Fix edit of tag of website

This commit is contained in:
Laurent Destailleur 2020-06-30 02:50:58 +02:00
parent 146c521efd
commit 88cf904ced
3 changed files with 83 additions and 18 deletions

View File

@ -8270,6 +8270,27 @@ abstract class CommonObject
/* Part for categories/tags */ /* Part for categories/tags */
/**
* Sets object to given categories.
*
* Deletes object from existing categories not supplied.
* Adds it to non existing supplied categories.
* Existing categories are left untouch.
*
* @param string $type_categ Category type ('customer', 'supplier', 'website_page', ...)
* @return int Array of category objects or < 0 if KO
*/
public function getCategoriesCommon($type_categ)
{
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
// Get current categories
$c = new Categorie($this->db);
$existing = $c->containing($this->id, $type_categ, 'id');
return $existing;
}
/** /**
* Sets object to given categories. * Sets object to given categories.
* *

View File

@ -312,6 +312,11 @@ a.buttonticket {
/* height: 40px; */ /* height: 40px; */
} }
/* Used by categories */
span.categorysquarre {
padding: 0 4px 0 4px;
}
/* Used by timesheets */ /* Used by timesheets */
span.timesheetalreadyrecorded input { span.timesheetalreadyrecorded input {
border: none; border: none;

View File

@ -987,7 +987,20 @@ if ($action == 'addcontainer')
setEventMessages($objectpage->error, $objectpage->errors, 'errors'); setEventMessages($objectpage->error, $objectpage->errors, 'errors');
$action = 'createcontainer'; $action = 'createcontainer';
} }
else { }
if (!$error) {
// Website categories association
$categoriesarray = GETPOST('categories', 'array');
$result = $objectpage->setCategories($categoriesarray);
if ($result < 0)
{
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}
}
if (!$error) {
// If there is no home page yet, this new page will be set as the home page // If there is no home page yet, this new page will be set as the home page
if (empty($object->fk_default_home)) { if (empty($object->fk_default_home)) {
$object->fk_default_home = $pageid; $object->fk_default_home = $pageid;
@ -1006,7 +1019,6 @@ if ($action == 'addcontainer')
} }
} }
} }
}
if (!$error) if (!$error)
{ {
@ -1670,7 +1682,7 @@ if ($action == 'updatemeta')
} }
if (!$error) { if (!$error) {
// Supplier categories association // Website categories association
$categoriesarray = GETPOST('categories', 'array'); $categoriesarray = GETPOST('categories', 'array');
$result = $objectpage->setCategories($categoriesarray); $result = $objectpage->setCategories($categoriesarray);
if ($result < 0) if ($result < 0)
@ -3814,22 +3826,28 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print getTitleFieldOfList("Type", 0, $_SERVER['PHP_SELF'], 'type_container', '', $param, '', $sortfield, $sortorder, '')."\n"; print getTitleFieldOfList("Type", 0, $_SERVER['PHP_SELF'], 'type_container', '', $param, '', $sortfield, $sortorder, '')."\n";
print getTitleFieldOfList("Page", 0, $_SERVER['PHP_SELF'], 'pageurl', '', $param, '', $sortfield, $sortorder, '')."\n"; print getTitleFieldOfList("Page", 0, $_SERVER['PHP_SELF'], 'pageurl', '', $param, '', $sortfield, $sortorder, '')."\n";
print getTitleFieldOfList("Categories", 0, $_SERVER['PHP_SELF']);
//print getTitleFieldOfList("Description", 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '')."\n"; //print getTitleFieldOfList("Description", 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '')."\n";
print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']); print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']);
print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']); print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']);
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
print '</tr>'; print '</tr>';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$c = new Categorie($db);
foreach ($listofpages['list'] as $answerrecord) foreach ($listofpages['list'] as $answerrecord)
{ {
if (get_class($answerrecord) == 'WebsitePage') if (get_class($answerrecord) == 'WebsitePage')
{ {
print '<tr>'; print '<tr>';
// Type of container
print '<td class="nowraponall">'.$langs->trans("Container").' - '; print '<td class="nowraponall">'.$langs->trans("Container").' - ';
print $langs->trans($answerrecord->type_container); // TODO Use label of container print $langs->trans($answerrecord->type_container); // TODO Use label of container
print '</td>'; print '</td>';
// Container url and label
print '<td>'; print '<td>';
print $answerrecord->getNomUrl(1); print $answerrecord->getNomUrl(1);
print ' <span class="opacitymedium">('.($answerrecord->title ? $answerrecord->title : $langs->trans("NoTitle")).')</span>'; print ' <span class="opacitymedium">('.($answerrecord->title ? $answerrecord->title : $langs->trans("NoTitle")).')</span>';
@ -3839,6 +3857,23 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
print '<span class="opacitymedium">'.$answerrecord->description.'</span>'; print '<span class="opacitymedium">'.$answerrecord->description.'</span>';
print '</td>'; print '</td>';
// Categories
print '<td>';
if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
{
// Get current categories
$existing = $c->containing($answerrecord->id, Categorie::TYPE_WEBSITE_PAGE, 'object');
if (is_array($existing)) {
foreach ($existing as $tmpcategory) {
//var_dump($tmpcategory);
print '<span class="categorysquarre marginrightonly" style="background-color: #'.($tmpcategory->color != '' ? $tmpcategory->color : '888').'" title="'.dol_escape_htmltag($langs->trans("Category").' '.$tmpcategory->label).'"></span>';
}
}
}
//var_dump($existing);
print '</td>';
$param = '?action=replacesiteconfirm'; $param = '?action=replacesiteconfirm';
$param .= '&websiteid='.$website->id; $param .= '&websiteid='.$website->id;
$param .= '&optioncontent='.GETPOST('optioncontent', 'aZ09'); $param .= '&optioncontent='.GETPOST('optioncontent', 'aZ09');
@ -3882,10 +3917,10 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
} } else {
else {
print '<tr>'; print '<tr>';
// Type of container
print '<td>'; print '<td>';
$translateofrecordtype = array( $translateofrecordtype = array(
'website_csscontent'=>'WEBSITE_CSS_INLINE', 'website_csscontent'=>'WEBSITE_CSS_INLINE',
@ -3913,11 +3948,15 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction =
$param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09'); $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
$param .= '&searchstring='.urlencode($searchkey); $param .= '&searchstring='.urlencode($searchkey);
// Container url and label
print '<td>'; print '<td>';
$backtopageurl = $_SERVER["PHP_SELF"].$param; $backtopageurl = $_SERVER["PHP_SELF"].$param;
print '<a href="'.$_SERVER["PHP_SELF"].'?action=editcss&website='.$website->ref.'&backtopage='.urlencode($backtopageurl).'">'.$langs->trans("EditCss").'</a>'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=editcss&website='.$website->ref.'&backtopage='.urlencode($backtopageurl).'">'.$langs->trans("EditCss").'</a>';
print '</td>'; print '</td>';
print '<td>';
print '</td>';
print '<td class="tdoverflow100">'; print '<td class="tdoverflow100">';
print '</td>'; print '</td>';