diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 0c310b92dd6..965bca72824 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -722,6 +722,7 @@ class Form else { jQuery(".massaction").hide(); + jQuery(".massactionother").hide(); } } @@ -743,10 +744,12 @@ class Form if ($(this).val() != \'0\') { jQuery(".massactionconfirmed").prop(\'disabled\', false); + jQuery(".massactionother").show(); } else { jQuery(".massactionconfirmed").prop(\'disabled\', true); + jQuery(".massactionother").hide(); } }); }); diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index af8840b33ae..770bc3fda88 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -793,7 +793,7 @@ function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $so { $tmpwebsitepage = new WebsitePage($db); $tmpwebsitepage->fetch($obj->rowid); - if ($tmpwebsitepage->id > 0) $arrayresult['list'][] = $tmpwebsitepage; + if ($tmpwebsitepage->id > 0) $arrayresult['list'][$obj->rowid] = $tmpwebsitepage; $found++; } $i++; diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 222eeb6df0d..c3e9870266f 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -126,4 +126,5 @@ MainLanguage=Main language OtherLanguages=Other languages UseManifest=Provide a manifest.json file PublicAuthorAlias=Public author alias -AvailableLanguagesAreDefinedIntoWebsiteProperties=Available languages are defined into website properties \ No newline at end of file +AvailableLanguagesAreDefinedIntoWebsiteProperties=Available languages are defined into website properties +ReplacementDoneInXPages=Replacement done in %s pages or containers \ No newline at end of file diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 9f823935bcb..a34cfce2206 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -52,9 +52,12 @@ $websitekey = GETPOST('website', 'alpha'); $page = GETPOST('page', 'alpha'); $pageid = GETPOST('pageid', 'int'); $pageref = GETPOST('pageref', 'alphanohtml'); + $action = GETPOST('action', 'aZ09'); +$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); +$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bomlist'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') @@ -260,6 +263,23 @@ $manifestjsoncontentdefault .= '{ }] }'; +$listofpages = array(); + +$algo = ''; +if (GETPOST('optionmeta')) $algo .= 'meta'; +if (GETPOST('optioncontent')) $algo .= 'content'; +if (GETPOST('optionsitefiles')) $algo .= 'sitefiles'; + +if (empty($sortfield)) { + $sortfield = 'pageurl'; $sortorder = 'ASC'; +} + +$searchkey = GETPOST('searchstring', 'none'); + +if ($action == 'replacesiteconfirm') { + $listofpages = getPagesFromSearchCriterias('', $algo, $searchkey, 1000, $sortfield, $sortorder); +} + /* @@ -340,11 +360,67 @@ if ($action == 'unsetshowsubcontainers') exit; } -if (($action == 'replacesite' || $action == 'replacesiteconfirm') && empty(GETPOST('searchstring'))) +if (($action == 'replacesite' || $action == 'replacesiteconfirm') && ! $searchkey) { $action = 'replacesite'; } +// Replacement of string into pages +if ($massaction == 'replace') +{ + $replacestring = GETPOST('replacestring', 'alphanohtml'); + if (! $replacestring) { + setEventMessages("ErrorReplaceStringEmpty", null, 'errors'); + } + else { + $nbreplacement = 0; + + foreach($toselect as $keyselected) { + $objectpage = $listofpages['list'][$keyselected]; + if ($objectpage->pageurl) { + dol_syslog("Replace string into page ".$objectpage->pageurl); + + if (GETPOST('optioncontent', 'aZ09')) { + $objectpage->content = str_replace($searchkey, $replacestring, $objectpage->content); + } + if (GETPOST('optionmeta', 'aZ09')) { + $objectpage->title = str_replace($searchkey, $replacestring, $objectpage->title); + $objectpage->description = str_replace($searchkey, $replacestring, $objectpage->description); + $objectpage->keywords = str_replace($searchkey, $replacestring, $objectpage->keywords); + } + + if (!empty($objectpage->content)) + { + $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php'; + $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php'; + + // Save page alias + $result = dolSavePageAlias($filealias, $object, $objectpage); + if (!$result) + { + setEventMessages('Failed to write file '.basename($filealias), null, 'errors'); + } + + // Save page of content + $result = dolSavePageContent($filetpl, $object, $objectpage); + if ($result) + { + $nbreplacement++; + } else { + $error++; + setEventMessages('Failed to write file '.$filetpl, null, 'errors'); + $action = 'createcontainer'; + break; + } + } + } + } + if (! $error) { + setEventMessages($langs->trans("ReplacementDoneInXPages", $nbreplacement), null, 'mesgs'); + } + } +} + // Add directory /* @@ -3397,10 +3473,8 @@ print "\n"; print "\n"; -if ($action == 'replacesite' || $action == 'replacesiteconfirm') +if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction == 'replace') { - $searchkey = GETPOST('searchstring', 'none'); - print '
'; print ''; print ''; @@ -3431,37 +3505,53 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm') print ''; print '
'; print ''; - print '
'; - print ''; - - print ''; - - print '
'; print ''; + print ''; + print ''; + + print ''; + + if ($action == 'replacesiteconfirm') { - $algo = ''; - if (GETPOST('optionmeta')) $algo .= 'meta'; - if (GETPOST('optioncontent')) $algo .= 'content'; - if (GETPOST('optionsitefiles')) $algo .= 'sitefiles'; - - if (empty($sortfield)) { - $sortfield = 'pageurl'; $sortorder = 'ASC'; - } - - $listofpages = getPagesFromSearchCriterias('', $algo, $searchkey, 1000, $sortfield, $sortorder); - print '
'; print '
'; if ($listofpages['code'] == 'OK') { + $arrayofselected = is_array($toselect) ? $toselect : array(); + $param = ''; + $nbtotalofrecords = count($listofpages['list']); + $num = $nbtotalofrecords = $limit; + $permissiontodelete = 0; + + // List of mass actions available + $arrayofmassactions = array( + //'validate'=>$langs->trans("Validate"), + //'generate_doc'=>$langs->trans("ReGeneratePDF"), + //'builddoc'=>$langs->trans("PDFMerge"), + 'replace'=>$langs->trans("Replace"), + ); + if ($permissiontodelete) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); + if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); + $massactionbutton = $form->selectMassAction('', $arrayofmassactions); + $massactionbutton .= ''; + + $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; + //$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); + + print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit, 1, 1, 1); + print ''."\n"; print '
'; - if ($action == 'replacesiteconfirm' && $conf->global->MAIN_FEATURES_LEVEL >= 2) + /*if ($action == 'replacesiteconfirm') { print '
'; print '
'; @@ -3469,11 +3559,11 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm') print '
'; print '
'; print ''; - print ''; + print ''; print '
'; print '
'; print '
'; - } + }*/ $param = 'action=replacesiteconfirm&website='.urlencode($website->ref); $param .= '&searchstring='.urlencode($searchkey); @@ -3488,6 +3578,7 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm') print getTitleFieldOfList("Page", 0, $_SERVER['PHP_SELF'], 'pageurl', '', $param, '', $sortfield, $sortorder, '')."\n"; //print getTitleFieldOfList("Description", 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '')."\n"; print getTitleFieldOfList("", 0 , $_SERVER['PHP_SELF']); + print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; print ''; foreach ($listofpages['list'] as $answerrecord) @@ -3521,6 +3612,17 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm') } print ''.img_picto($langs->trans("EditHTMLSource"), 'edit').''; print ''; + + // Action column + print ''; + if ($massactionbutton || $massaction) + { + $selected = 0; + if (in_array($answerrecord->id, $arrayofselected)) $selected = 1; + print ''; + } + print ''; + print ''; } else @@ -3550,11 +3652,17 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm') print ''; print ''; print ''; + + // Action column + print ''; + print ''; + print ''; } } print ''; print '
'; + print '
'; } else {