NEW Add mass action to set category on a list of website pages.
This commit is contained in:
parent
48137f8cad
commit
da8bd7507e
@ -655,10 +655,10 @@ class Categorie extends CommonObject
|
|||||||
* Link an object to the category
|
* Link an object to the category
|
||||||
*
|
*
|
||||||
* @param CommonObject $obj Object to link to category
|
* @param CommonObject $obj Object to link to category
|
||||||
* @param string $type Type of category ('product', ...)
|
* @param string $type Type of category ('product', ...). Use '' to take $obj->element.
|
||||||
* @return int 1 : OK, -1 : erreur SQL, -2 : id not defined, -3 : Already linked
|
* @return int 1 : OK, -1 : erreur SQL, -2 : id not defined, -3 : Already linked
|
||||||
*/
|
*/
|
||||||
public function add_type($obj, $type)
|
public function add_type($obj, $type = '')
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
global $user, $langs, $conf;
|
global $user, $langs, $conf;
|
||||||
@ -667,6 +667,8 @@ class Categorie extends CommonObject
|
|||||||
|
|
||||||
if ($this->id == -1) return -2;
|
if ($this->id == -1) return -2;
|
||||||
|
|
||||||
|
if (empty($type)) $type = $obj->element;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
|
||||||
|
|||||||
@ -647,7 +647,7 @@ class Form
|
|||||||
|
|
||||||
$disabled = 0;
|
$disabled = 0;
|
||||||
$ret = '<div class="centpercent center">';
|
$ret = '<div class="centpercent center">';
|
||||||
$ret .= '<select class="flat'.(empty($conf->use_javascript_ajax) ? '' : ' hideobject').' ' . $name . ' ' . $name . 'select valignmiddle" name="' . $name . '"'.($disabled ? ' disabled="disabled"' : '').'>';
|
$ret .= '<select class="flat'.(empty($conf->use_javascript_ajax) ? '' : ' hideobject').' ' . $name . ' ' . $name . 'select valignmiddle alignstart" name="' . $name . '"'.($disabled ? ' disabled="disabled"' : '').'>';
|
||||||
|
|
||||||
// Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['currentcontext'] completed by executeHooks.
|
// Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['currentcontext'] completed by executeHooks.
|
||||||
$parameters = array();
|
$parameters = array();
|
||||||
@ -713,17 +713,18 @@ class Form
|
|||||||
urlform = urlform + "#show_files";
|
urlform = urlform + "#show_files";
|
||||||
}
|
}
|
||||||
$( this ).closest("form").attr("action", urlform);
|
$( this ).closest("form").attr("action", urlform);
|
||||||
console.log("we select a mass action "+massaction+" - "+urlform);
|
console.log("we select a mass action name='.$name.' massaction="+massaction+" - "+urlform);
|
||||||
/* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
|
/* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
|
||||||
if ($(this).val() != \'0\')
|
if ($(this).val() != \'0\')
|
||||||
{
|
{
|
||||||
jQuery(".' . $name . 'confirmed").prop(\'disabled\', false);
|
jQuery(".' . $name . 'confirmed").prop(\'disabled\', false);
|
||||||
jQuery(".' . $name . 'other").show();
|
jQuery(".' . $name . 'other").hide(); /* To disable if another div was open */
|
||||||
|
jQuery(".' . $name . '"+massaction).show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jQuery(".' . $name . 'confirmed").prop(\'disabled\', true);
|
jQuery(".' . $name . 'confirmed").prop(\'disabled\', true);
|
||||||
jQuery(".' . $name . 'other").hide();
|
jQuery(".' . $name . 'other").hide(); /* To disable any div open */
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1239,7 +1239,7 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr
|
|||||||
if (GETPOSTISSET('dol_optimize_smallscreen')) { $themeparam .= '&dol_optimize_smallscreen='.GETPOST('dol_optimize_smallscreen', 'int'); }
|
if (GETPOSTISSET('dol_optimize_smallscreen')) { $themeparam .= '&dol_optimize_smallscreen='.GETPOST('dol_optimize_smallscreen', 'int'); }
|
||||||
if (GETPOSTISSET('dol_no_mouse_hover')) { $themeparam .= '&dol_no_mouse_hover='.GETPOST('dol_no_mouse_hover', 'int'); }
|
if (GETPOSTISSET('dol_no_mouse_hover')) { $themeparam .= '&dol_no_mouse_hover='.GETPOST('dol_no_mouse_hover', 'int'); }
|
||||||
if (GETPOSTISSET('dol_use_jmobile')) { $themeparam .= '&dol_use_jmobile='.GETPOST('dol_use_jmobile', 'int'); $conf->dol_use_jmobile = GETPOST('dol_use_jmobile', 'int'); }
|
if (GETPOSTISSET('dol_use_jmobile')) { $themeparam .= '&dol_use_jmobile='.GETPOST('dol_use_jmobile', 'int'); $conf->dol_use_jmobile = GETPOST('dol_use_jmobile', 'int'); }
|
||||||
if (GETPOSTISSET('THEME_AGRESSIVENESS_RATIO')) { $themeparam .= '&THEME_AGRESSIVENESS_RATIO='.GETPOST('THEME_AGRESSIVENESS_RATIO', 'int'); }
|
if (GETPOSTISSET('THEME_SATURATE_RATIO')) { $themeparam .= '&THEME_SATURATE_RATIO='.GETPOST('THEME_SATURATE_RATIO', 'int'); }
|
||||||
|
|
||||||
if (!defined('DISABLE_JQUERY') && !$disablejs && $conf->use_javascript_ajax)
|
if (!defined('DISABLE_JQUERY') && !$disablejs && $conf->use_javascript_ajax)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -552,6 +552,9 @@ textarea.centpercent {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
margin: 0px auto;
|
margin: 0px auto;
|
||||||
}
|
}
|
||||||
|
.alignstart {
|
||||||
|
text-align: start;
|
||||||
|
}
|
||||||
.left {
|
.left {
|
||||||
text-align: <?php print $left; ?>;
|
text-align: <?php print $left; ?>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -292,6 +292,8 @@ if ($action == 'replacesiteconfirm') {
|
|||||||
$listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
|
$listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$usercanedit = $user->rights->website->write;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -380,6 +382,46 @@ if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && !$searc
|
|||||||
$massaction = '';
|
$massaction = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set categoery
|
||||||
|
if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit)
|
||||||
|
{
|
||||||
|
$error = 0;
|
||||||
|
|
||||||
|
$db->begin();
|
||||||
|
|
||||||
|
$categoryid = GETPOST('setcategory', 'none');
|
||||||
|
if ($categoryid > 0) {
|
||||||
|
$nbupdate = 0;
|
||||||
|
$tmpwebsitepage = new WebsitePage($db);
|
||||||
|
$category = new Categorie($db);
|
||||||
|
$category->fetch($categoryid);
|
||||||
|
|
||||||
|
foreach($toselect as $tmpid) {
|
||||||
|
$tmpwebsitepage->id = $tmpid;
|
||||||
|
$result = $category->add_type($tmpwebsitepage, 'website_page');
|
||||||
|
if ($result < 0 && $result != -3) {
|
||||||
|
$error++;
|
||||||
|
setEventMessages($category->error, $category->errors, 'errors');
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
$nbupdate++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
|
$db->rollback();
|
||||||
|
} else {
|
||||||
|
if ($nbupdate) {
|
||||||
|
setEventMessages($langs->trans("RecordsModified", $nbupdate), null, 'mesgs');
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->commit();
|
||||||
|
}
|
||||||
|
// Now we reload list
|
||||||
|
$listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
|
||||||
|
}
|
||||||
|
|
||||||
// Replacement of string into pages
|
// Replacement of string into pages
|
||||||
if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha'))
|
if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha'))
|
||||||
{
|
{
|
||||||
@ -3558,7 +3600,7 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
|
|||||||
print '<input type="hidden" name="website" value="'.$website->ref.'">';
|
print '<input type="hidden" name="website" value="'.$website->ref.'">';
|
||||||
|
|
||||||
|
|
||||||
print '<!-- Replace string -->'."\n";
|
print '<!-- Search page and replace string -->'."\n";
|
||||||
print '<div class="fiche"><br>';
|
print '<div class="fiche"><br>';
|
||||||
|
|
||||||
print load_fiche_titre($langs->trans("ReplaceWebsiteContent"), '', 'search');
|
print load_fiche_titre($langs->trans("ReplaceWebsiteContent"), '', 'search');
|
||||||
@ -3652,20 +3694,27 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
|
|||||||
// List of mass actions available
|
// List of mass actions available
|
||||||
$arrayofmassactions = array();
|
$arrayofmassactions = array();
|
||||||
if ($user->rights->website->writephp && $searchkey) $arrayofmassactions['replace'] = $langs->trans("Replace");
|
if ($user->rights->website->writephp && $searchkey) $arrayofmassactions['replace'] = $langs->trans("Replace");
|
||||||
|
if ($user->rights->website->write) $arrayofmassactions['setcategory'] = $langs->trans("ClassifyInCategory");
|
||||||
if ($permissiontodelete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
|
if ($permissiontodelete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
|
||||||
if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
|
if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
|
||||||
|
|
||||||
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
|
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
|
||||||
$massactionbutton .= '<div class="massactionother hidden">';
|
$massactionbutton .= '<div class="massactionother massactionreplace hidden">';
|
||||||
$massactionbutton .= $langs->trans("ReplaceString");
|
$massactionbutton .= $langs->trans("ReplaceString");
|
||||||
$massactionbutton .= '<input type="text" name="replacestring" value="'.dol_escape_htmltag(GETPOST('replacestring', 'none')).'">';
|
$massactionbutton .= ' <input type="text" name="replacestring" value="'.dol_escape_htmltag(GETPOST('replacestring', 'none')).'">';
|
||||||
|
$massactionbutton .= '</div>';
|
||||||
|
$massactionbutton .= '<div class="massactionother massactionsetcategory hidden">';
|
||||||
|
$massactionbutton .= $langs->trans("Category");
|
||||||
|
$massactionbutton .= ' '.$form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, GETPOSTISSET('setcategory') ? GETPOST('setcategory') : '', 'setcategory', 64, 0, 0, 0, 'minwidth300 alignstart');
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
|
||||||
|
$massactionbutton .= ajax_combobox('setcategory');
|
||||||
$massactionbutton .= '</div>';
|
$massactionbutton .= '</div>';
|
||||||
|
|
||||||
$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
|
$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
|
||||||
//$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
|
//$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
|
||||||
$selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
|
$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_barre_liste($langs->trans("Results"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit, 1, 1, 1);
|
||||||
|
|
||||||
$param = 'action=replacesiteconfirm&website='.urlencode($website->ref);
|
$param = 'action=replacesiteconfirm&website='.urlencode($website->ref);
|
||||||
$param .= '&searchstring='.urlencode($searchkey);
|
$param .= '&searchstring='.urlencode($searchkey);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user