NEW Can filter on container type, language and tags in the list of pages

of website module.
This commit is contained in:
Laurent Destailleur 2020-05-26 12:25:41 +02:00
parent b6308f6dfa
commit 2d30d33303
3 changed files with 87 additions and 25 deletions

View File

@ -248,7 +248,7 @@ print '</tr>';
// Default language // Default language
print '<tr class="oddeven"><td class="titlefield">'.$langs->trans("DefaultLanguage").'</td><td>'; print '<tr class="oddeven"><td class="titlefield">'.$langs->trans("DefaultLanguage").'</td><td>';
print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT, 'MAIN_LANG_DEFAULT', 1, 0, 0, 0, 0, 'minwidth300', 2); print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT, 'MAIN_LANG_DEFAULT', 1, null, '', 0, 0, 'minwidth300', 2);
print '<input class="button" type="submit" name="submit" value="'.$langs->trans("Save").'">'; print '<input class="button" type="submit" name="submit" value="'.$langs->trans("Save").'">';
print '</td>'; print '</td>';
print '<td width="20">&nbsp;</td>'; print '<td width="20">&nbsp;</td>';

View File

@ -768,9 +768,10 @@ function getSocialNetworkSharingLinks()
* @param string $sortfield Sort Fields * @param string $sortfield Sort Fields
* @param string $sortorder Sort order ('DESC' or 'ASC') * @param string $sortorder Sort order ('DESC' or 'ASC')
* @param string $langcode Language code ('' or 'en', 'fr', 'es', ...) * @param string $langcode Language code ('' or 'en', 'fr', 'es', ...)
* @param array $otherfilters Other filters
* @return string HTML content * @return string HTML content
*/ */
function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $sortfield = 'date_creation', $sortorder = 'DESC', $langcode = '') function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $sortfield = 'date_creation', $sortorder = 'DESC', $langcode = '', $otherfilters = 'null')
{ {
global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers. global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers.
@ -784,8 +785,7 @@ function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $so
$error++; $error++;
$arrayresult['code'] = 'KO'; $arrayresult['code'] = 'KO';
$arrayresult['message'] = $weblangs->trans("EmptySearchString"); $arrayresult['message'] = $weblangs->trans("EmptySearchString");
} elseif (dol_strlen($searchstring) < 2) } elseif (dol_strlen($searchstring) < 2) {
{
$weblangs->load("errors"); $weblangs->load("errors");
$error++; $error++;
$arrayresult['code'] = 'KO'; $arrayresult['code'] = 'KO';
@ -807,10 +807,13 @@ function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $so
if (!$error && (empty($max) || ($found < $max)) && (preg_match('/meta/', $algo) || preg_match('/content/', $algo))) if (!$error && (empty($max) || ($found < $max)) && (preg_match('/meta/', $algo) || preg_match('/content/', $algo)))
{ {
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'website_page'; $sql = 'SELECT wp.rowid FROM '.MAIN_DB_PREFIX.'website_page as wp';
$sql .= " WHERE fk_website = ".$website->id; if (is_array($otherfilters) && ! empty($otherfilters['category'])) {
$sql .= ', '.MAIN_DB_PREFIX.'categorie_website_page as cwp';
}
$sql .= " WHERE wp.fk_website = ".$website->id;
if ($langcode) { if ($langcode) {
$sql .= " AND lang ='".$db->escape($langcode)."'"; $sql .= " AND wp.lang ='".$db->escape($langcode)."'";
} }
if ($type) { if ($type) {
$tmparrayoftype = explode(',', $type); $tmparrayoftype = explode(',', $type);
@ -818,20 +821,23 @@ function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $so
foreach ($tmparrayoftype as $tmptype) { foreach ($tmparrayoftype as $tmptype) {
$typestring .= ($typestring ? ", " : "")."'".trim($tmptype)."'"; $typestring .= ($typestring ? ", " : "")."'".trim($tmptype)."'";
} }
$sql .= " AND type_container IN (".$typestring.")"; $sql .= " AND wp.type_container IN (".$typestring.")";
} }
$sql .= " AND ("; $sql .= " AND (";
$searchalgo = ''; $searchalgo = '';
if (preg_match('/meta/', $algo)) if (preg_match('/meta/', $algo))
{ {
$searchalgo .= ($searchalgo ? ' OR ' : '')."title LIKE '%".$db->escape($searchstring)."%' OR description LIKE '%".$db->escape($searchstring)."%'"; $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.title LIKE '%".$db->escape($searchstring)."%' OR wp.description LIKE '%".$db->escape($searchstring)."%'";
$searchalgo .= ($searchalgo ? ' OR ' : '')."keywords LIKE '".$db->escape($searchstring).",%' OR keywords LIKE '% ".$db->escape($searchstring)."%'"; // TODO Use a better way to scan keywords $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.keywords LIKE '".$db->escape($searchstring).",%' OR wp.keywords LIKE '% ".$db->escape($searchstring)."%'"; // TODO Use a better way to scan keywords
} }
if (preg_match('/content/', $algo)) if (preg_match('/content/', $algo))
{ {
$searchalgo .= ($searchalgo ? ' OR ' : '')."content LIKE '%".$db->escape($searchstring)."%'"; $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.content LIKE '%".$db->escape($searchstring)."%'";
} }
$sql .= $searchalgo; $sql .= $searchalgo;
if (is_array($otherfilters) && ! empty($otherfilters['category'])) {
$sql .= ' AND cwp.fk_website_page = wp.rowid AND cwp.fk_categorie = '.((int) $otherfilters['category']);
}
$sql .= ")"; $sql .= ")";
$sql .= $db->order($sortfield, $sortorder); $sql .= $db->order($sortfield, $sortorder);
$sql .= $db->plimit($max); $sql .= $db->plimit($max);

View File

@ -282,7 +282,14 @@ if (empty($sortfield)) {
$searchkey = GETPOST('searchstring', 'none'); $searchkey = GETPOST('searchstring', 'none');
if ($action == 'replacesiteconfirm') { if ($action == 'replacesiteconfirm') {
$listofpages = getPagesFromSearchCriterias('', $algo, $searchkey, 1000, $sortfield, $sortorder); $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
$langcode = GETPOST('optionlanguage', 'aZ09');
$otherfilters = array();
if (GETPOST('optioncategory', 'int') > 0) {
$otherfilters['category'] = GETPOST('optioncategory', 'int');
}
$listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
} }
@ -430,8 +437,15 @@ if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha'))
setEventMessages($langs->trans("ReplacementDoneInXPages", $nbreplacement), null, 'mesgs'); setEventMessages($langs->trans("ReplacementDoneInXPages", $nbreplacement), null, 'mesgs');
} }
$containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
$langcode = GETPOST('optionlanguage', 'aZ09');
$otherfilters = array();
if (GETPOST('optioncategory', 'int') > 0) {
$otherfilters['category'] = GETPOST('optioncategory', 'int');
}
// Now we reload list // Now we reload list
$listofpages = getPagesFromSearchCriterias('', $algo, $searchkey, 1000, $sortfield, $sortorder); $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
} }
} }
@ -3547,10 +3561,12 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
print load_fiche_titre($langs->trans("ReplaceWebsiteContent"), '', 'search'); print load_fiche_titre($langs->trans("ReplaceWebsiteContent"), '', 'search');
print '<div class="fichecenter"><div class="fichehalfleft">';
print '<div class="tagtable">'; print '<div class="tagtable">';
print '<div class="tagtr">'; print '<div class="tagtr">';
print '<div class="tagtd paddingrightonly">'; print '<div class="tagtd paddingrightonly opacitymedium">';
print $langs->trans("SearchReplaceInto"); print $langs->trans("SearchReplaceInto");
print '</div>'; print '</div>';
print '<div class="tagtd">'; print '<div class="tagtd">';
@ -3561,23 +3577,64 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
print '</div>'; print '</div>';
print '<div class="tagtr">'; print '<div class="tagtr">';
print '<div class="tagtd paddingrightonly">'; print '<div class="tagtd paddingrightonly opacitymedium" style="padding-right: 10px !important">';
print $langs->trans("SearchString"); print $langs->trans("SearchString");
print '</div>'; print '</div>';
print '<div class="tagtd">'; print '<div class="tagtd">';
print '<input type="text" name="searchstring" value="'.dol_escape_htmltag($searchkey, 0, 0, '', 1).'" autofocus>'; print '<input type="text" name="searchstring" value="'.dol_escape_htmltag($searchkey, 0, 0, '', 1).'" autofocus>';
print '</div>';
print '</div>';
print '</div>';
print '</div><div class="fichehalfleft">';
print '<div class="tagtable">';
print '<div class="tagtr">';
print '<div class="tagtd paddingrightonly opacitymedium" style="padding-right: 10px !important">';
print $langs->trans("WEBSITE_TYPE_CONTAINER");
print '</div>';
print '<div class="tagtd">';
print $formwebsite->selectTypeOfContainer('optioncontainertype', (GETPOST('optioncontainertype', 'alpha') ? GETPOST('optioncontainertype', 'alpha') : ''), 1);
print '</div>';
print '</div>';
print '<div class="tagtr">';
print '<div class="tagtd paddingrightonly opacitymedium" style="padding-right: 10px !important">';
print $langs->trans("Language");
print '</div>';
print '<div class="tagtd">';
print img_picto('', 'language', 'class="paddingrightonly"').' '.$formadmin->select_language(GETPOSTISSET('optionlanguage') ? GETPOST('optionlanguage') : '', 'optionlanguage', 0, null, '1', 0, 0, 'minwidth300', 2, 0, 0, null, 1);
print '</div>';
print '</div>';
// Categories
if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
{
print '<div class="tagtr">';
print '<div class="tagtd paddingrightonly marginrightonly opacitymedium" style="padding-right: 10px !important">';
print $langs->trans("Category");
print '</div>';
print '<div class="tagtd">';
print img_picto('', 'category', 'class="paddingrightonly"').' '.$form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, GETPOSTISSET('optioncategory') ? GETPOST('optioncategory') : '', 'optioncategory', null, null);
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
print ajax_combobox('optioncategory');
print '</div>';
print '</div>';
}
print '</div>';
print '<input type="submit" class="button" name="buttonreplacesitesearch" value="'.dol_escape_htmltag($langs->trans("Search")).'">'; print '<input type="submit" class="button" name="buttonreplacesitesearch" value="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '</div>'; print '</div></div>';
print '</div>';
print '</div>';
if ($action == 'replacesiteconfirm') if ($action == 'replacesiteconfirm')
{ {
print '<!-- List of search result -->'."\n";
print '<div class="rowsearchresult clearboth">';
print '<br>'; print '<br>';
print '<br>'; print '<br>';
@ -3606,9 +3663,6 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit, 1, 1, 1); print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit, 1, 1, 1);
print '<!-- List of search result -->'."\n";
print '<div class="rowsearchresult">';
$param = 'action=replacesiteconfirm&website='.urlencode($website->ref); $param = 'action=replacesiteconfirm&website='.urlencode($website->ref);
$param .= '&searchstring='.urlencode($searchkey); $param .= '&searchstring='.urlencode($searchkey);
if (GETPOST('optioncontent')) $param .= '&optioncontent=content'; if (GETPOST('optioncontent')) $param .= '&optioncontent=content';
@ -3727,12 +3781,14 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
} }
} }
print '</table>'; print '</table>';
print '</div></div>'; print '</div>';
print '<br>'; print '<br>';
} }
else { else {
print $listofpages['message']; print $listofpages['message'];
} }
print '</div>';
} }
print '</form>'; print '</form>';