Merge pull request #16408 from frederic34/categ_codesyntax

code syntax categorie collab directory
This commit is contained in:
Laurent Destailleur 2021-02-26 10:22:15 +01:00 committed by GitHub
commit 563a9bd7ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 505 additions and 469 deletions

View File

@ -27,8 +27,9 @@ require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
if (!$user->admin) if (!$user->admin) {
accessforbidden(); accessforbidden();
}
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("categories", "admin")); $langs->loadLangs(array("categories", "admin"));
@ -40,11 +41,9 @@ $action = GETPOST('action', 'aZ09');
*/ */
$reg = array(); $reg = array();
if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
{
$code = $reg[1]; $code = $reg[1];
if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
{
header("Location: ".$_SERVER["PHP_SELF"]); header("Location: ".$_SERVER["PHP_SELF"]);
exit; exit;
} else { } else {
@ -52,11 +51,9 @@ if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg))
} }
} }
if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
{
$code = $reg[1]; $code = $reg[1];
if (dolibarr_del_const($db, $code, $conf->entity) > 0) if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
{
header("Location: ".$_SERVER["PHP_SELF"]); header("Location: ".$_SERVER["PHP_SELF"]);
exit; exit;
} else { } else {
@ -100,12 +97,10 @@ print '<td>'.$langs->trans("CategorieRecursiv").'</td>';
print '<td align="center" width="20">'.$form->textwithpicto('', $langs->trans("CategorieRecursivHelp"), 1, 'help').'</td>'; print '<td align="center" width="20">'.$form->textwithpicto('', $langs->trans("CategorieRecursivHelp"), 1, 'help').'</td>';
print '<td align="center" width="100">'; print '<td align="center" width="100">';
if ($conf->use_javascript_ajax) if ($conf->use_javascript_ajax) {
{
print ajax_constantonoff('CATEGORIE_RECURSIV_ADD'); print ajax_constantonoff('CATEGORIE_RECURSIV_ADD');
} else { } else {
if (empty($conf->global->CATEGORIE_RECURSIV_ADD)) if (empty($conf->global->CATEGORIE_RECURSIV_ADD)) {
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_CATEGORIE_RECURSIV_ADD">'.img_picto($langs->trans("Disabled"), 'off').'</a>'; print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_CATEGORIE_RECURSIV_ADD">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
} else { } else {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_CATEGORIE_RECURSIV_ADD">'.img_picto($langs->trans("Enabled"), 'on').'</a>'; print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_CATEGORIE_RECURSIV_ADD">'.img_picto($langs->trans("Enabled"), 'on').'</a>';

View File

@ -37,13 +37,17 @@ $form = new Form($db);
// List of supported format // List of supported format
$tmptype2label = ExtraFields::$type2label; $tmptype2label = ExtraFields::$type2label;
$type2label = array(''); $type2label = array('');
foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); foreach ($tmptype2label as $key => $val) {
$type2label[$key] = $langs->transnoentitiesnoconv($val);
}
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha'); $attrname = GETPOST('attrname', 'alpha');
$elementtype = 'categorie'; //Must be the $element of the class that manage extrafield $elementtype = 'categorie'; //Must be the $element of the class that manage extrafield
if (!$user->admin) accessforbidden(); if (!$user->admin) {
accessforbidden();
}
/* /*
@ -76,8 +80,7 @@ print dol_get_fiche_end();
// Buttons // Buttons
if ($action != 'create' && $action != 'edit') if ($action != 'create' && $action != 'edit') {
{
print '<div class="tabsAction">'; print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create#newattrib\">".$langs->trans("NewAttribute")."</a>"; print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create#newattrib\">".$langs->trans("NewAttribute")."</a>";
print "</div>"; print "</div>";
@ -90,8 +93,7 @@ if ($action != 'create' && $action != 'edit')
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
if ($action == 'create') if ($action == 'create') {
{
print '<br><div id="newattrib"></div>'; print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute')); print load_fiche_titre($langs->trans('NewAttribute'));
@ -103,8 +105,7 @@ if ($action == 'create')
/* Edition of an optional field */ /* Edition of an optional field */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
if ($action == 'edit' && !empty($attrname)) if ($action == 'edit' && !empty($attrname)) {
{
print "<br>"; print "<br>";
print load_fiche_titre($langs->trans("FieldEdition", $attrname)); print load_fiche_titre($langs->trans("FieldEdition", $attrname));

View File

@ -37,14 +37,16 @@ $langs->load("categories");
// Security check // Security check
$socid = (int) GETPOST('socid', 'int'); $socid = (int) GETPOST('socid', 'int');
if (!$user->rights->categorie->lire) accessforbidden(); if (!$user->rights->categorie->lire) {
accessforbidden();
}
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$cancel = GETPOST('cancel', 'alpha'); $cancel = GETPOST('cancel', 'alpha');
$origin = GETPOST('origin', 'alpha'); $origin = GETPOST('origin', 'alpha');
$catorigin = (int) GETPOST('catorigin', 'int'); $catorigin = (int) GETPOST('catorigin', 'int');
$type = GETPOST('type', 'aZ09'); $type = GETPOST('type', 'aZ09');
$urlfrom = GETPOST('urlfrom', 'alpha'); $urlfrom = GETPOST('urlfrom', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha');
$label = (string) GETPOST('label', 'alphanohtml'); $label = (string) GETPOST('label', 'alphanohtml');
@ -54,15 +56,29 @@ $visible = (int) GETPOST('visible', 'int');
$parent = (int) GETPOST('parent', 'int'); $parent = (int) GETPOST('parent', 'int');
if ($origin) { if ($origin) {
if ($type == Categorie::TYPE_PRODUCT) $idProdOrigin = $origin; if ($type == Categorie::TYPE_PRODUCT) {
if ($type == Categorie::TYPE_SUPPLIER) $idSupplierOrigin = $origin; $idProdOrigin = $origin;
if ($type == Categorie::TYPE_CUSTOMER) $idCompanyOrigin = $origin; }
if ($type == Categorie::TYPE_MEMBER) $idMemberOrigin = $origin; if ($type == Categorie::TYPE_SUPPLIER) {
if ($type == Categorie::TYPE_CONTACT) $idContactOrigin = $origin; $idSupplierOrigin = $origin;
if ($type == Categorie::TYPE_PROJECT) $idProjectOrigin = $origin; }
if ($type == Categorie::TYPE_CUSTOMER) {
$idCompanyOrigin = $origin;
}
if ($type == Categorie::TYPE_MEMBER) {
$idMemberOrigin = $origin;
}
if ($type == Categorie::TYPE_CONTACT) {
$idContactOrigin = $origin;
}
if ($type == Categorie::TYPE_PROJECT) {
$idProjectOrigin = $origin;
}
} }
if ($catorigin && $type == Categorie::TYPE_PRODUCT) $idCatOrigin = $catorigin; if ($catorigin && $type == Categorie::TYPE_PRODUCT) {
$idCatOrigin = $catorigin;
}
$object = new Categorie($db); $object = new Categorie($db);
@ -80,13 +96,10 @@ $error = 0;
*/ */
// Add action // Add action
if ($action == 'add' && $user->rights->categorie->creer) if ($action == 'add' && $user->rights->categorie->creer) {
{
// Action ajout d'une categorie // Action ajout d'une categorie
if ($cancel) if ($cancel) {
{ if ($urlfrom) {
if ($urlfrom)
{
header("Location: ".$urlfrom); header("Location: ".$urlfrom);
exit; exit;
} elseif ($backtopage) { } elseif ($backtopage) {
@ -125,24 +138,25 @@ if ($action == 'add' && $user->rights->categorie->creer)
$object->visible = $visible; $object->visible = $visible;
$object->type = $type; $object->type = $type;
if ($parent != "-1") $object->fk_parent = $parent; if ($parent != "-1") {
$object->fk_parent = $parent;
}
$ret = $extrafields->setOptionalsFromPost(null, $object); $ret = $extrafields->setOptionalsFromPost(null, $object);
if ($ret < 0) $error++; if ($ret < 0) {
$error++;
}
if (!$object->label) if (!$object->label) {
{
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
$action = 'create'; $action = 'create';
} }
// Create category in database // Create category in database
if (!$error) if (!$error) {
{
$result = $object->create($user); $result = $object->create($user);
if ($result > 0) if ($result > 0) {
{
$action = 'confirmed'; $action = 'confirmed';
$_POST["addcat"] = ''; $_POST["addcat"] = '';
} else { } else {
@ -152,41 +166,31 @@ if ($action == 'add' && $user->rights->categorie->creer)
} }
// Confirm action // Confirm action
if (($action == 'add' || $action == 'confirmed') && $user->rights->categorie->creer) if (($action == 'add' || $action == 'confirmed') && $user->rights->categorie->creer) {
{
// Action confirmation de creation categorie // Action confirmation de creation categorie
if ($action == 'confirmed') if ($action == 'confirmed') {
{ if ($urlfrom) {
if ($urlfrom)
{
header("Location: ".$urlfrom); header("Location: ".$urlfrom);
exit; exit;
} elseif ($backtopage) } elseif ($backtopage) {
{
header("Location: ".$backtopage); header("Location: ".$backtopage);
exit; exit;
} elseif ($idProdOrigin) } elseif ($idProdOrigin) {
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated"))); header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit; exit;
} elseif ($idCompanyOrigin) } elseif ($idCompanyOrigin) {
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated"))); header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit; exit;
} elseif ($idSupplierOrigin) } elseif ($idSupplierOrigin) {
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated"))); header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit; exit;
} elseif ($idMemberOrigin) } elseif ($idMemberOrigin) {
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated"))); header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit; exit;
} elseif ($idContactOrigin) } elseif ($idContactOrigin) {
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated"))); header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit; exit;
} elseif ($idProjectOrigin) } elseif ($idProjectOrigin) {
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated"))); header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit; exit;
} }
@ -207,11 +211,9 @@ $formother = new FormOther($db);
$helpurl = ''; $helpurl = '';
llxHeader("", $langs->trans("Categories"), $helpurl); llxHeader("", $langs->trans("Categories"), $helpurl);
if ($user->rights->categorie->creer) if ($user->rights->categorie->creer) {
{
// Create or add // Create or add
if ($action == 'create' || GETPOST("addcat") == 'addcat') if ($action == 'create' || GETPOST("addcat") == 'addcat') {
{
dol_set_focus('#label'); dol_set_focus('#label');
print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$type.'" method="POST">'; print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$type.'" method="POST">';
@ -222,8 +224,12 @@ if ($user->rights->categorie->creer)
print '<input type="hidden" name="id" value="'.GETPOST('origin', 'alpha').'">'; print '<input type="hidden" name="id" value="'.GETPOST('origin', 'alpha').'">';
print '<input type="hidden" name="type" value="'.$type.'">'; print '<input type="hidden" name="type" value="'.$type.'">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
if ($origin) print '<input type="hidden" name="origin" value="'.$origin.'">'; if ($origin) {
if ($catorigin) print '<input type="hidden" name="catorigin" value="'.$catorigin.'">'; print '<input type="hidden" name="origin" value="'.$origin.'">';
}
if ($catorigin) {
print '<input type="hidden" name="catorigin" value="'.$catorigin.'">';
}
print load_fiche_titre($langs->trans("CreateCat")); print load_fiche_titre($langs->trans("CreateCat"));
@ -257,8 +263,7 @@ if ($user->rights->categorie->creer)
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
if (empty($reshook)) if (empty($reshook)) {
{
print $object->showOptionals($extrafields, 'edit', $parameters); print $object->showOptionals($extrafields, 'edit', $parameters);
} }

View File

@ -140,15 +140,12 @@ class Categories extends DolibarrApi
$sql = "SELECT t.rowid"; $sql = "SELECT t.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."categorie as t"; $sql .= " FROM ".MAIN_DB_PREFIX."categorie as t";
$sql .= ' WHERE t.entity IN ('.getEntity('category').')'; $sql .= ' WHERE t.entity IN ('.getEntity('category').')';
if (!empty($type)) if (!empty($type)) {
{
$sql .= ' AND t.type='.array_search($type, Categories::$TYPES); $sql .= ' AND t.type='.array_search($type, Categories::$TYPES);
} }
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -157,8 +154,7 @@ class Categories extends DolibarrApi
$sql .= $this->db->order($sortfield, $sortorder); $sql .= $this->db->order($sortfield, $sortorder);
if ($limit) { if ($limit) {
if ($page < 0) if ($page < 0) {
{
$page = 0; $page = 0;
} }
$offset = $limit * $page; $offset = $limit * $page;
@ -167,13 +163,11 @@ class Categories extends DolibarrApi
} }
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
$i = 0; $i = 0;
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit)); $min = min($num, ($limit <= 0 ? $num : $limit));
while ($i < $min) while ($i < $min) {
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$category_static = new Categorie($this->db); $category_static = new Categorie($this->db);
if ($category_static->fetch($obj->rowid)) { if ($category_static->fetch($obj->rowid)) {
@ -181,8 +175,7 @@ class Categories extends DolibarrApi
} }
$i++; $i++;
} }
} } else {
else {
throw new RestException(503, 'Error when retrieve category list : '.$this->db->lasterror()); throw new RestException(503, 'Error when retrieve category list : '.$this->db->lasterror());
} }
if (!count($obj_ret)) { if (!count($obj_ret)) {
@ -238,7 +231,9 @@ class Categories extends DolibarrApi
} }
foreach ($request_data as $field => $value) { foreach ($request_data as $field => $value) {
if ($field == 'id') continue; if ($field == 'id') {
continue;
}
$this->category->$field = $value; $this->category->$field = $value;
} }
@ -721,8 +716,9 @@ class Categories extends DolibarrApi
{ {
$category = array(); $category = array();
foreach (Categories::$FIELDS as $field) { foreach (Categories::$FIELDS as $field) {
if (!isset($data[$field])) if (!isset($data[$field])) {
throw new RestException(400, "$field field missing"); throw new RestException(400, "$field field missing");
}
$category[$field] = $data[$field]; $category[$field] = $data[$field];
} }
return $category; return $category;
@ -747,8 +743,7 @@ class Categories extends DolibarrApi
throw new RestException(401); throw new RestException(401);
} }
if (empty($type)) if (empty($type)) {
{
throw new RestException(500, 'The "type" parameter is required.'); throw new RestException(500, 'The "type" parameter is required.');
} }

View File

@ -98,7 +98,7 @@ class Categorie extends CommonObject
8 => 'bank_line', 8 => 'bank_line',
9 => 'warehouse', 9 => 'warehouse',
10 => 'actioncomm', 10 => 'actioncomm',
11 => 'website_page' 11 => 'website_page'
); );
/** /**
@ -197,7 +197,7 @@ class Categorie extends CommonObject
/** /**
* @var string Category label * @var string Category label
*/ */
public $label; public $label;
/** /**
* @var string description * @var string description
@ -231,9 +231,9 @@ class Categorie extends CommonObject
* @see Categorie::TYPE_PROJECT * @see Categorie::TYPE_PROJECT
* @see Categorie::TYPE_ACCOUNT * @see Categorie::TYPE_ACCOUNT
* @see Categorie::TYPE_BANK_LINE * @see Categorie::TYPE_BANK_LINE
* @see Categorie::TYPE_WAREHOUSE * @see Categorie::TYPE_WAREHOUSE
* @see Categorie::TYPE_ACTIONCOMM * @see Categorie::TYPE_ACTIONCOMM
* @see Categorie::TYPE_WEBSITE_PAGE * @see Categorie::TYPE_WEBSITE_PAGE
*/ */
public $type; public $type;
@ -266,9 +266,9 @@ class Categorie extends CommonObject
$mapList = $hookmanager->resArray; $mapList = $hookmanager->resArray;
$mapId = $mapList['id']; $mapId = $mapList['id'];
$mapCode = $mapList['code']; $mapCode = $mapList['code'];
self::$MAP_ID_TO_CODE[$mapId] = $mapCode; self::$MAP_ID_TO_CODE[$mapId] = $mapCode;
$this->MAP_ID[$mapCode] = $mapId; $this->MAP_ID[$mapCode] = $mapId;
$this->MAP_CAT_FK[$mapCode] = $mapList['cat_fk']; $this->MAP_CAT_FK[$mapCode] = $mapList['cat_fk'];
$this->MAP_CAT_TABLE[$mapCode] = $mapList['cat_table']; $this->MAP_CAT_TABLE[$mapCode] = $mapList['cat_table'];
$this->MAP_OBJ_CLASS[$mapCode] = $mapList['obj_class']; $this->MAP_OBJ_CLASS[$mapCode] = $mapList['obj_class'];
$this->MAP_OBJ_TABLE[$mapCode] = $mapList['obj_table']; $this->MAP_OBJ_TABLE[$mapCode] = $mapList['obj_table'];
@ -313,8 +313,12 @@ class Categorie extends CommonObject
global $conf; global $conf;
// Check parameters // Check parameters
if (empty($id) && empty($label) && empty($ref_ext)) return -1; if (empty($id) && empty($label) && empty($ref_ext)) {
if (!is_null($type) && !is_numeric($type)) $type = $this->MAP_ID[$type]; return -1;
}
if (!is_null($type) && !is_numeric($type)) {
$type = $this->MAP_ID[$type];
}
$sql = "SELECT rowid, fk_parent, entity, label, description, color, fk_soc, visible, type, ref_ext"; $sql = "SELECT rowid, fk_parent, entity, label, description, color, fk_soc, visible, type, ref_ext";
$sql .= ", date_creation, tms, fk_user_creat, fk_user_modif"; $sql .= ", date_creation, tms, fk_user_creat, fk_user_modif";
@ -325,7 +329,9 @@ class Categorie extends CommonObject
$sql .= " WHERE ref_ext LIKE '".$this->db->escape($ref_ext)."'"; $sql .= " WHERE ref_ext LIKE '".$this->db->escape($ref_ext)."'";
} else { } else {
$sql .= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category').")"; $sql .= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category').")";
if (!is_null($type)) $sql .= " AND type = ".((int) $type); if (!is_null($type)) {
$sql .= " AND type = ".((int) $type);
}
} }
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
@ -357,7 +363,9 @@ class Categorie extends CommonObject
$this->db->free($resql); $this->db->free($resql);
// multilangs // multilangs
if (!empty($conf->global->MAIN_MULTILANGS)) $this->getMultiLangs(); if (!empty($conf->global->MAIN_MULTILANGS)) {
$this->getMultiLangs();
}
return 1; return 1;
} else { } else {
@ -387,7 +395,9 @@ class Categorie extends CommonObject
$type = $this->type; $type = $this->type;
if (!is_numeric($type)) $type = $this->MAP_ID[$type]; if (!is_numeric($type)) {
$type = $this->MAP_ID[$type];
}
$error = 0; $error = 0;
@ -399,7 +409,9 @@ class Categorie extends CommonObject
$this->color = trim($this->color); $this->color = trim($this->color);
$this->import_key = trim($this->import_key); $this->import_key = trim($this->import_key);
$this->ref_ext = trim($this->ref_ext); $this->ref_ext = trim($this->ref_ext);
if (empty($this->visible)) $this->visible = 0; if (empty($this->visible)) {
$this->visible = 0;
}
$this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0); $this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0);
if ($this->already_exists()) { if ($this->already_exists()) {
@ -463,7 +475,9 @@ class Categorie extends CommonObject
if (!$error) { if (!$error) {
// Call trigger // Call trigger
$result = $this->call_trigger('CATEGORY_CREATE', $user); $result = $this->call_trigger('CATEGORY_CREATE', $user);
if ($result < 0) { $error++; } if ($result < 0) {
$error++;
}
// End call triggers // End call triggers
} }
@ -542,7 +556,9 @@ class Categorie extends CommonObject
if (!$error) { if (!$error) {
// Call trigger // Call trigger
$result = $this->call_trigger('CATEGORY_MODIFY', $user); $result = $this->call_trigger('CATEGORY_MODIFY', $user);
if ($result < 0) { $error++; $this->db->rollback(); return -1; } if ($result < 0) {
$error++; $this->db->rollback(); return -1;
}
// End call triggers // End call triggers
} }
@ -579,7 +595,9 @@ class Categorie extends CommonObject
if (!$error && !$notrigger) { if (!$error && !$notrigger) {
// Call trigger // Call trigger
$result = $this->call_trigger('CATEGORY_DELETE', $user); $result = $this->call_trigger('CATEGORY_DELETE', $user);
if ($result < 0) $error++; if ($result < 0) {
$error++;
}
// End call triggers // End call triggers
} }
@ -649,9 +667,13 @@ class Categorie extends CommonObject
$error = 0; $error = 0;
if ($this->id == -1) return -2; if ($this->id == -1) {
return -2;
}
if (empty($type)) $type = $obj->element; if (empty($type)) {
$type = $obj->element;
}
$this->db->begin(); $this->db->begin();
@ -699,7 +721,9 @@ class Categorie extends CommonObject
// Call trigger // Call trigger
$this->context = array('linkto'=>$obj); // Save object we want to link category to into category instance to provide information to trigger $this->context = array('linkto'=>$obj); // Save object we want to link category to into category instance to provide information to trigger
$result = $this->call_trigger('CATEGORY_LINK', $user); $result = $this->call_trigger('CATEGORY_LINK', $user);
if ($result < 0) { $error++; } if ($result < 0) {
$error++;
}
// End call triggers // End call triggers
if (!$error) { if (!$error) {
@ -757,7 +781,9 @@ class Categorie extends CommonObject
// Call trigger // Call trigger
$this->context = array('unlinkoff'=>$obj); // Save object we want to link category to into category instance to provide information to trigger $this->context = array('unlinkoff'=>$obj); // Save object we want to link category to into category instance to provide information to trigger
$result = $this->call_trigger('CATEGORY_UNLINK', $user); $result = $this->call_trigger('CATEGORY_UNLINK', $user);
if ($result < 0) { $error++; } if ($result < 0) {
$error++;
}
// End call triggers // End call triggers
if (!$error) { if (!$error) {
@ -805,7 +831,9 @@ class Categorie extends CommonObject
if (($type == 'customer' || $type == 'supplier') && $user->socid > 0) { if (($type == 'customer' || $type == 'supplier') && $user->socid > 0) {
$sql .= " AND o.rowid = ".$user->socid; $sql .= " AND o.rowid = ".$user->socid;
} }
if ($limit > 0 || $offset > 0) $sql .= $this->db->plimit($limit + 1, $offset); if ($limit > 0 || $offset > 0) {
$sql .= $this->db->plimit($limit + 1, $offset);
}
$sql .= $this->db->order($sortfield, $sortorder); $sql .= $this->db->order($sortfield, $sortorder);
dol_syslog(get_class($this)."::getObjectsInCateg", LOG_DEBUG); dol_syslog(get_class($this)."::getObjectsInCateg", LOG_DEBUG);
@ -1037,7 +1065,9 @@ class Categorie extends CommonObject
// phpcs:enable // phpcs:enable
global $conf, $langs; global $conf, $langs;
if (!is_numeric($type)) $type = $this->MAP_ID[$type]; if (!is_numeric($type)) {
$type = $this->MAP_ID[$type];
}
if (is_null($type)) { if (is_null($type)) {
$this->error = 'BadValueForParameterType'; $this->error = 'BadValueForParameterType';
return -1; return -1;
@ -1063,9 +1093,13 @@ class Categorie extends CommonObject
// Init $this->cats array // Init $this->cats array
$sql = "SELECT DISTINCT c.rowid, c.label, c.ref_ext, c.description, c.color, c.fk_parent, c.visible"; // Distinct reduce pb with old tables with duplicates $sql = "SELECT DISTINCT c.rowid, c.label, c.ref_ext, c.description, c.color, c.fk_parent, c.visible"; // Distinct reduce pb with old tables with duplicates
if (!empty($conf->global->MAIN_MULTILANGS)) $sql .= ", t.label as label_trans, t.description as description_trans"; if (!empty($conf->global->MAIN_MULTILANGS)) {
$sql .= ", t.label as label_trans, t.description as description_trans";
}
$sql .= " FROM ".MAIN_DB_PREFIX."categorie as c"; $sql .= " FROM ".MAIN_DB_PREFIX."categorie as c";
if (!empty($conf->global->MAIN_MULTILANGS)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_lang as t ON t.fk_category=c.rowid AND t.lang='".$this->db->escape($current_lang)."'"; if (!empty($conf->global->MAIN_MULTILANGS)) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_lang as t ON t.fk_category=c.rowid AND t.lang='".$this->db->escape($current_lang)."'";
}
$sql .= " WHERE c.entity IN (".getEntity('category').")"; $sql .= " WHERE c.entity IN (".getEntity('category').")";
$sql .= " AND c.type = ".(int) $type; $sql .= " AND c.type = ".(int) $type;
@ -1204,14 +1238,18 @@ class Categorie extends CommonObject
public function get_all_categories($type = null, $parent = false) public function get_all_categories($type = null, $parent = false)
{ {
// phpcs:enable // phpcs:enable
if (!is_numeric($type)) $type = $this->MAP_ID[$type]; if (!is_numeric($type)) {
$type = $this->MAP_ID[$type];
}
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie"; $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie";
$sql .= " WHERE entity IN (".getEntity('category').")"; $sql .= " WHERE entity IN (".getEntity('category').")";
if (!is_null($type)) if (!is_null($type)) {
$sql .= " AND type = ".(int) $type; $sql .= " AND type = ".(int) $type;
if ($parent) }
if ($parent) {
$sql .= " AND fk_parent = 0"; $sql .= " AND fk_parent = 0";
}
$res = $this->db->query($sql); $res = $this->db->query($sql);
if ($res) { if ($res) {
@ -1252,7 +1290,9 @@ class Categorie extends CommonObject
// phpcs:enable // phpcs:enable
$type = $this->type; $type = $this->type;
if (!is_numeric($type)) $type = $this->MAP_ID[$type]; if (!is_numeric($type)) {
$type = $this->MAP_ID[$type];
}
/* We have to select any rowid from llx_categorie which category's mother and label /* We have to select any rowid from llx_categorie which category's mother and label
* are equals to those of the calling category * are equals to those of the calling category
@ -1318,7 +1358,9 @@ class Categorie extends CommonObject
// Check contrast with background and correct text color // Check contrast with background and correct text color
$forced_color = 'categtextwhite'; $forced_color = 'categtextwhite';
if ($cat->color) { if ($cat->color) {
if (colorIsLight($cat->color)) $forced_color = 'categtextblack'; if (colorIsLight($cat->color)) {
$forced_color = 'categtextblack';
}
} }
} }
} }
@ -1399,8 +1441,9 @@ class Categorie extends CommonObject
} }
} }
if (count($ways) == 0) if (count($ways) == 0) {
$ways[0][0] = $this; $ways[0][0] = $this;
}
return $ways; return $ways;
} }
@ -1419,7 +1462,9 @@ class Categorie extends CommonObject
{ {
$cats = array(); $cats = array();
if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type];
}
if ($type === Categorie::TYPE_BANK_LINE) { // TODO Remove this with standard category code after migration of llx_bank_categ into llx_categorie if ($type === Categorie::TYPE_BANK_LINE) { // TODO Remove this with standard category code after migration of llx_bank_categ into llx_categorie
// Load bank categories // Load bank categories
@ -1509,11 +1554,14 @@ class Categorie extends CommonObject
$sql .= " WHERE type = ".$this->MAP_ID[$type]; $sql .= " WHERE type = ".$this->MAP_ID[$type];
$sql .= " AND entity IN (".getEntity('category').")"; $sql .= " AND entity IN (".getEntity('category').")";
if ($nom) { if ($nom) {
if (!$exact) if (!$exact) {
$nom = '%'.str_replace('*', '%', $nom).'%'; $nom = '%'.str_replace('*', '%', $nom).'%';
if (!$case) }
if (!$case) {
$sql .= " AND label LIKE '".$this->db->escape($nom)."'"; $sql .= " AND label LIKE '".$this->db->escape($nom)."'";
else $sql .= " AND label LIKE BINARY '".$this->db->escape($nom)."'"; } else {
$sql .= " AND label LIKE BINARY '".$this->db->escape($nom)."'";
}
} }
if ($id) { if ($id) {
$sql .= " AND rowid = '".$id."'"; $sql .= " AND rowid = '".$id."'";
@ -1554,7 +1602,9 @@ class Categorie extends CommonObject
// Check contrast with background and correct text color // Check contrast with background and correct text color
$forced_color = 'categtextwhite'; $forced_color = 'categtextwhite';
if ($this->color) { if ($this->color) {
if (colorIsLight($this->color)) $forced_color = 'categtextblack'; if (colorIsLight($this->color)) {
$forced_color = 'categtextblack';
}
} }
$link = '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$this->id.'&type='.$this->type.$moreparam.'&backtopage='.urlencode($_SERVER['PHP_SELF'].($moreparam ? '?'.$moreparam : '')).'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip '.$forced_color.'">'; $link = '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$this->id.'&type='.$this->type.$moreparam.'&backtopage='.urlencode($_SERVER['PHP_SELF'].($moreparam ? '?'.$moreparam : '')).'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip '.$forced_color.'">';
@ -1563,9 +1613,15 @@ class Categorie extends CommonObject
$picto = 'category'; $picto = 'category';
if ($withpicto) $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); if ($withpicto) {
if ($withpicto && $withpicto != 2) $result .= ' '; $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
if ($withpicto != 2) $result .= $link.dol_trunc(($this->ref ? $this->ref : $this->label), $maxlength).$linkend; }
if ($withpicto && $withpicto != 2) {
$result .= ' ';
}
if ($withpicto != 2) {
$result .= $link.dol_trunc(($this->ref ? $this->ref : $this->label), $maxlength).$linkend;
}
return $result; return $result;
} }
@ -1653,13 +1709,18 @@ class Categorie extends CommonObject
// Objet // Objet
$obj = array(); $obj = array();
$obj['photo'] = $photo; $obj['photo'] = $photo;
if ($photo_vignette && is_file($dirthumb.$photo_vignette)) $obj['photo_vignette'] = 'thumbs/'.$photo_vignette; if ($photo_vignette && is_file($dirthumb.$photo_vignette)) {
else $obj['photo_vignette'] = ""; $obj['photo_vignette'] = 'thumbs/'.$photo_vignette;
} else {
$obj['photo_vignette'] = "";
}
$tabobj[$nbphoto - 1] = $obj; $tabobj[$nbphoto - 1] = $obj;
// On continue ou on arrete de boucler // On continue ou on arrete de boucler
if ($nbmax && $nbphoto >= $nbmax) break; if ($nbmax && $nbphoto >= $nbmax) {
break;
}
} }
} }
@ -1764,8 +1825,9 @@ class Categorie extends CommonObject
} }
// on ne sauvegarde pas des champs vides // on ne sauvegarde pas des champs vides
if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"] || $this->multilangs["$key"]["note"]) if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"] || $this->multilangs["$key"]["note"]) {
dol_syslog(get_class($this).'::setMultiLangs', LOG_DEBUG); dol_syslog(get_class($this).'::setMultiLangs', LOG_DEBUG);
}
if (!$this->db->query($sql2)) { if (!$this->db->query($sql2)) {
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
return -1; return -1;
@ -1876,7 +1938,9 @@ class Categorie extends CommonObject
*/ */
public static function getFilterJoinQuery($type, $rowIdName) public static function getFilterJoinQuery($type, $rowIdName)
{ {
if ($type == 'bank_account') $type = 'account'; if ($type == 'bank_account') {
$type = 'account';
}
return " LEFT JOIN ".MAIN_DB_PREFIX."categorie_".$type." as cp ON ".$rowIdName." = cp.fk_".$type; return " LEFT JOIN ".MAIN_DB_PREFIX."categorie_".$type." as cp ON ".$rowIdName." = cp.fk_".$type;
} }
@ -1891,7 +1955,9 @@ class Categorie extends CommonObject
*/ */
public static function getFilterSelectQuery($type, $rowIdName, $searchList) public static function getFilterSelectQuery($type, $rowIdName, $searchList)
{ {
if ($type == 'bank_account') $type = 'account'; if ($type == 'bank_account') {
$type = 'account';
}
if (empty($searchList) && !is_array($searchList)) { if (empty($searchList) && !is_array($searchList)) {
return ""; return "";

View File

@ -62,7 +62,9 @@ if ($result <= 0) {
} }
$type = $object->type; $type = $object->type;
if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
}
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label($object->table_element); $extrafields->fetch_name_optionals_label($object->table_element);
@ -90,7 +92,7 @@ if ($cancel) {
// Action mise a jour d'une categorie // Action mise a jour d'une categorie
if ($action == 'update' && $user->rights->categorie->creer) { if ($action == 'update' && $user->rights->categorie->creer) {
$object->oldcopy = dol_clone($object); $object->oldcopy = dol_clone($object);
$object->label = $label; $object->label = $label;
$object->description = dol_htmlcleanlastbr($description); $object->description = dol_htmlcleanlastbr($description);
$object->color = $color; $object->color = $color;
$object->socid = ($socid > 0 ? $socid : 0); $object->socid = ($socid > 0 ? $socid : 0);
@ -105,10 +107,11 @@ if ($action == 'update' && $user->rights->categorie->creer) {
} }
if (!$error && empty($object->error)) { if (!$error && empty($object->error)) {
$ret = $extrafields->setOptionalsFromPost(null, $object); $ret = $extrafields->setOptionalsFromPost(null, $object);
if ($ret < 0) $error++; if ($ret < 0) {
$error++;
}
if (!$error && $object->update($user) > 0) if (!$error && $object->update($user) > 0) {
{
if ($backtopage) { if ($backtopage) {
header("Location: ".$backtopage); header("Location: ".$backtopage);
exit; exit;

View File

@ -34,7 +34,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
// Load translation files required by the page // Load translation files required by the page
$langs->load("categories"); $langs->load("categories");
if (!$user->rights->categorie->lire) accessforbidden(); if (!$user->rights->categorie->lire) {
accessforbidden();
}
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$type = (GETPOST('type', 'aZ09') ? GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT); $type = (GETPOST('type', 'aZ09') ? GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT);
@ -42,7 +44,9 @@ $catname = GETPOST('catname', 'alpha');
$nosearch = GETPOST('nosearch', 'int'); $nosearch = GETPOST('nosearch', 'int');
$categstatic = new Categorie($db); $categstatic = new Categorie($db);
if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
}
/* /*
@ -54,11 +58,15 @@ $form = new Form($db);
$moreparam = ($nosearch ? '&nosearch=1' : ''); $moreparam = ($nosearch ? '&nosearch=1' : '');
$typetext = $type; $typetext = $type;
if ($type == Categorie::TYPE_ACCOUNT) $title = $langs->trans('AccountsCategoriesArea'); if ($type == Categorie::TYPE_ACCOUNT) {
elseif ($type == Categorie::TYPE_WAREHOUSE) $title = $langs->trans('StocksCategoriesArea'); $title = $langs->trans('AccountsCategoriesArea');
elseif ($type == Categorie::TYPE_ACTIONCOMM) $title = $langs->trans('ActionCommCategoriesArea'); } elseif ($type == Categorie::TYPE_WAREHOUSE) {
elseif ($type == Categorie::TYPE_WEBSITE_PAGE) $title = $langs->trans('WebsitePagesCategoriesArea'); $title = $langs->trans('StocksCategoriesArea');
else { } elseif ($type == Categorie::TYPE_ACTIONCOMM) {
$title = $langs->trans('ActionCommCategoriesArea');
} elseif ($type == Categorie::TYPE_WEBSITE_PAGE) {
$title = $langs->trans('WebsitePagesCategoriesArea');
} else {
$title = $langs->trans(ucfirst($type).'sCategoriesArea'); $title = $langs->trans(ucfirst($type).'sCategoriesArea');
} }
@ -100,15 +108,13 @@ if (empty($nosearch)) {
/* /*
* Categories found * Categories found
*/ */
if ($catname || $id > 0) if ($catname || $id > 0) {
{
$cats = $categstatic->rechercher($id, $catname, $typetext); $cats = $categstatic->rechercher($id, $catname, $typetext);
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>'; print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
foreach ($cats as $cat) foreach ($cats as $cat) {
{
$color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"'; $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
print "\t".'<tr class="oddeven">'."\n"; print "\t".'<tr class="oddeven">'."\n";
@ -128,7 +134,9 @@ if (empty($nosearch)) {
print "\t</tr>\n"; print "\t</tr>\n";
} }
print "</table>"; print "</table>";
} else print '&nbsp;'; } else {
print '&nbsp;';
}
print '</div></div>'; print '</div></div>';
} }
@ -143,19 +151,25 @@ $cate_arbo = $categstatic->get_full_arbo($typetext);
$fulltree = $cate_arbo; $fulltree = $cate_arbo;
// Load possible missing includes // Load possible missing includes
if ($conf->global->CATEGORY_SHOW_COUNTS) if ($conf->global->CATEGORY_SHOW_COUNTS) {
{ if ($type == Categorie::TYPE_MEMBER) {
if ($type == Categorie::TYPE_MEMBER) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
if ($type == Categorie::TYPE_ACCOUNT) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; }
if ($type == Categorie::TYPE_PROJECT) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; if ($type == Categorie::TYPE_ACCOUNT) {
if ($type == Categorie::TYPE_USER) require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
if ($type == Categorie::TYPE_PROJECT) {
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
}
if ($type == Categorie::TYPE_USER) {
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
}
} }
// Define data (format for treeview) // Define data (format for treeview)
$data = array(); $data = array();
$data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>''); $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
foreach ($fulltree as $key => $val) foreach ($fulltree as $key => $val) {
{
$categstatic->id = $val['id']; $categstatic->id = $val['id'];
$categstatic->ref = $val['label']; $categstatic->ref = $val['label'];
$categstatic->color = $val['color']; $categstatic->color = $val['color'];
@ -163,8 +177,7 @@ foreach ($fulltree as $key => $val)
$desc = dol_htmlcleanlastbr($val['description']); $desc = dol_htmlcleanlastbr($val['description']);
$counter = ''; $counter = '';
if ($conf->global->CATEGORY_SHOW_COUNTS) if ($conf->global->CATEGORY_SHOW_COUNTS) {
{
// we need only a count of the elements, so it is enough to consume only the id's from the database // we need only a count of the elements, so it is enough to consume only the id's from the database
$elements = $type == Categorie::TYPE_ACCOUNT $elements = $type == Categorie::TYPE_ACCOUNT
? $categstatic->getObjectsInCateg("account", 1) // Categorie::TYPE_ACCOUNT is "bank_account" instead of "account" ? $categstatic->getObjectsInCateg("account", 1) // Categorie::TYPE_ACCOUNT is "bank_account" instead of "account"
@ -206,15 +219,13 @@ foreach ($fulltree as $key => $val)
print '<table class="liste nohover" width="100%">'; print '<table class="liste nohover" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td class="right">'; print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td class="right">';
if (!empty($conf->use_javascript_ajax)) if (!empty($conf->use_javascript_ajax)) {
{
print '<div id="iddivjstreecontrol"><a class="notasortlink" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a> | <a class="notasortlink" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a></div>'; print '<div id="iddivjstreecontrol"><a class="notasortlink" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a> | <a class="notasortlink" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a></div>';
} }
print '</td></tr>'; print '</td></tr>';
$nbofentries = (count($data) - 1); $nbofentries = (count($data) - 1);
if ($nbofentries > 0) if ($nbofentries > 0) {
{
print '<tr class="pair"><td colspan="3">'; print '<tr class="pair"><td colspan="3">';
tree_recur($data, $data[0], 0); tree_recur($data, $data[0], 0);
print '</td></tr>'; print '</td></tr>';

View File

@ -20,7 +20,7 @@
/** /**
* \file htdocs/categories/info.php * \file htdocs/categories/info.php
* \ingroup categories * \ingroup categories
* \brief Category info page * \brief Category info page
*/ */
require '../main.inc.php'; require '../main.inc.php';
@ -40,7 +40,9 @@ $id = GETPOST('id', 'int');
$label = GETPOST('label', 'alpha'); $label = GETPOST('label', 'alpha');
// Security check // Security check
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'categorie', $id, '&category'); $result = restrictedArea($user, 'categorie', $id, '&category');
$object = new Categorie($db); $object = new Categorie($db);
@ -50,7 +52,9 @@ if ($result <= 0) {
} }
$type = $object->type; $type = $object->type;
if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
}
/* /*
* View * View

View File

@ -38,11 +38,10 @@ $langs->loadlangs(array('categories', 'bills'));
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$label = GETPOST('label', 'alpha'); $label = GETPOST('label', 'alpha');
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm'); $confirm = GETPOST('confirm');
if ($id == '' && $label == '') if ($id == '' && $label == '') {
{
dol_print_error('', 'Missing parameter id'); dol_print_error('', 'Missing parameter id');
exit(); exit();
} }
@ -57,7 +56,9 @@ if ($result <= 0) {
} }
$type = $object->type; $type = $object->type;
if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
}
$upload_dir = $conf->categorie->multidir_output[$object->entity]; $upload_dir = $conf->categorie->multidir_output[$object->entity];
@ -65,16 +66,12 @@ $upload_dir = $conf->categorie->multidir_output[$object->entity];
* Actions * Actions
*/ */
if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && $_POST["sendit"] && !empty($conf->global->MAIN_UPLOAD_DOC)) if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && $_POST["sendit"] && !empty($conf->global->MAIN_UPLOAD_DOC)) {
{
if ($object->id) { if ($object->id) {
$file = $_FILES['userfile']; $file = $_FILES['userfile'];
if (is_array($file['name']) && count($file['name']) > 0) if (is_array($file['name']) && count($file['name']) > 0) {
{ foreach ($file['name'] as $i => $name) {
foreach ($file['name'] as $i => $name) if (empty($file['tmp_name'][$i]) || intval($conf->global->MAIN_UPLOAD_DOC) * 1000 <= filesize($file['tmp_name'][$i])) {
{
if (empty($file['tmp_name'][$i]) || intval($conf->global->MAIN_UPLOAD_DOC) * 1000 <= filesize($file['tmp_name'][$i]))
{
setEventMessage($file['name'][$i].' : '.$langs->trans(empty($file['tmp_name'][$i]) ? 'ErrorFailedToSaveFile' : 'MaxSizeForUploadedFiles')); setEventMessage($file['name'][$i].' : '.$langs->trans(empty($file['tmp_name'][$i]) ? 'ErrorFailedToSaveFile' : 'MaxSizeForUploadedFiles'));
unset($file['name'][$i], $file['type'][$i], $file['tmp_name'][$i], $file['error'][$i], $file['size'][$i]); unset($file['name'][$i], $file['type'][$i], $file['tmp_name'][$i], $file['error'][$i], $file['size'][$i]);
} }
@ -87,13 +84,11 @@ if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && $_POST["sen
} }
} }
if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer) if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer) {
{
$object->delete_photo($upload_dir."/".$_GET["file"]); $object->delete_photo($upload_dir."/".$_GET["file"]);
} }
if ($action == 'addthumb' && $_GET["file"]) if ($action == 'addthumb' && $_GET["file"]) {
{
$object->addThumbs($upload_dir."/".$_GET["file"]); $object->addThumbs($upload_dir."/".$_GET["file"]);
} }
@ -107,8 +102,7 @@ llxHeader("", "", $langs->trans("Categories"));
$form = new Form($db); $form = new Form($db);
$formother = new FormOther($db); $formother = new FormOther($db);
if ($object->id) if ($object->id) {
{
$title = Categorie::$MAP_TYPE_TITLE_AREA[$type]; $title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
$head = categories_prepare_head($object, $type); $head = categories_prepare_head($object, $type);
@ -119,8 +113,7 @@ if ($object->id)
$object->ref = $object->label; $object->ref = $object->label;
$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> '; $morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
$ways = $object->print_all_ways(" &gt;&gt; ", '', 1); $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
foreach ($ways as $way) foreach ($ways as $way) {
{
$morehtmlref .= $way."<br>\n"; $morehtmlref .= $way."<br>\n";
} }
$morehtmlref .= '</div>'; $morehtmlref .= '</div>';
@ -130,8 +123,7 @@ if ($object->id)
/* /*
* Confirmation de la suppression de photo * Confirmation de la suppression de photo
*/ */
if ($action == 'delete') if ($action == 'delete') {
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1); print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
} }
@ -168,10 +160,8 @@ if ($object->id)
print '<div class="tabsAction">'."\n"; print '<div class="tabsAction">'."\n";
if ($action != 'ajout_photo' && $user->rights->categorie->creer) if ($action != 'ajout_photo' && $user->rights->categorie->creer) {
{ if (!empty($conf->global->MAIN_UPLOAD_DOC)) {
if (!empty($conf->global->MAIN_UPLOAD_DOC))
{
print '<a class="butAction hideonsmartphone" href="'.$_SERVER['PHP_SELF'].'?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">'; print '<a class="butAction hideonsmartphone" href="'.$_SERVER['PHP_SELF'].'?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">';
print $langs->trans("AddPhoto").'</a>'; print $langs->trans("AddPhoto").'</a>';
} else { } else {
@ -185,16 +175,14 @@ if ($object->id)
/* /*
* Ajouter une photo * Ajouter une photo
*/ */
if ($action == 'ajout_photo' && $user->rights->categorie->creer && !empty($conf->global->MAIN_UPLOAD_DOC)) if ($action == 'ajout_photo' && $user->rights->categorie->creer && !empty($conf->global->MAIN_UPLOAD_DOC)) {
{
// Affiche formulaire upload // Affiche formulaire upload
$formfile = new FormFile($db); $formfile = new FormFile($db);
$formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;type='.$type, $langs->trans("AddPhoto"), 1, '', $user->rights->categorie->creer, 50, $object, '', false, '', 0); $formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;type='.$type, $langs->trans("AddPhoto"), 1, '', $user->rights->categorie->creer, 50, $object, '', false, '', 0);
} }
// Affiche photos // Affiche photos
if ($action != 'ajout_photo') if ($action != 'ajout_photo') {
{
$nbphoto = 0; $nbphoto = 0;
$nbbyrow = 5; $nbbyrow = 5;
@ -206,23 +194,24 @@ if ($object->id)
$listofphoto = $object->liste_photos($dir); $listofphoto = $object->liste_photos($dir);
if (is_array($listofphoto) && count($listofphoto)) if (is_array($listofphoto) && count($listofphoto)) {
{
print '<br>'; print '<br>';
print '<table width="100%" valign="top" align="center">'; print '<table width="100%" valign="top" align="center">';
foreach ($listofphoto as $key => $obj) foreach ($listofphoto as $key => $obj) {
{
$nbphoto++; $nbphoto++;
if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print '<tr align=center valign=middle border=1>'; if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) {
if ($nbbyrow) print '<td width="'.ceil(100 / $nbbyrow).'%" class="photo">'; print '<tr align=center valign=middle border=1>';
}
if ($nbbyrow) {
print '<td width="'.ceil(100 / $nbbyrow).'%" class="photo">';
}
print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">'; print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">';
// Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
if ($obj['photo_vignette']) if ($obj['photo_vignette']) {
{
$filename = $obj['photo_vignette']; $filename = $obj['photo_vignette'];
} else { } else {
$filename = $obj['photo']; $filename = $obj['photo'];
@ -243,22 +232,23 @@ if ($object->id)
print '<br>'; print '<br>';
// On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i', $obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i', $obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) {
{
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addthumb&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'), 'refresh').'&nbsp;&nbsp;</a>'; print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addthumb&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'), 'refresh').'&nbsp;&nbsp;</a>';
} }
if ($user->rights->categorie->creer) if ($user->rights->categorie->creer) {
{
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">';
print img_delete().'</a>'; print img_delete().'</a>';
} }
if ($nbbyrow) print '</td>'; if ($nbbyrow) {
if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print '</tr>'; print '</td>';
}
if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) {
print '</tr>';
}
} }
// Ferme tableau // Ferme tableau
while ($nbphoto % $nbbyrow) while ($nbphoto % $nbbyrow) {
{
print '<td width="'.ceil(100 / $nbbyrow).'%">&nbsp;</td>'; print '<td width="'.ceil(100 / $nbbyrow).'%">&nbsp;</td>';
$nbphoto++; $nbphoto++;
} }
@ -266,8 +256,7 @@ if ($object->id)
print '</table>'; print '</table>';
} }
if ($nbphoto < 1) if ($nbphoto < 1) {
{
print '<div class="opacitymedium">'.$langs->trans("NoPhotoYet")."</div>"; print '<div class="opacitymedium">'.$langs->trans("NoPhotoYet")."</div>";
} }
} }

View File

@ -35,13 +35,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array('categories', 'languages')); $langs->loadLangs(array('categories', 'languages'));
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$label = GETPOST('label', 'alpha'); $label = GETPOST('label', 'alpha');
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
$cancel = GETPOST('cancel', 'alpha'); $cancel = GETPOST('cancel', 'alpha');
if ($id == '' && $label == '') if ($id == '' && $label == '') {
{
dol_print_error('', 'Missing parameter id'); dol_print_error('', 'Missing parameter id');
exit(); exit();
} }
@ -56,7 +55,9 @@ if ($result <= 0) {
} }
$type = $object->type; $type = $object->type;
if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
}
/* /*
* Actions * Actions
@ -64,8 +65,7 @@ if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backwar
$error = 0; $error = 0;
// retour a l'affichage des traduction si annulation // retour a l'affichage des traduction si annulation
if ($cancel == $langs->trans("Cancel")) if ($cancel == $langs->trans("Cancel")) {
{
$action = ''; $action = '';
} }
@ -73,8 +73,7 @@ if ($cancel == $langs->trans("Cancel"))
// Validation de l'ajout // Validation de l'ajout
if ($action == 'vadd' && if ($action == 'vadd' &&
$cancel != $langs->trans("Cancel") && $cancel != $langs->trans("Cancel") &&
($user->rights->categorie->creer)) ($user->rights->categorie->creer)) {
{
$object->fetch($id); $object->fetch($id);
$current_lang = $langs->getDefaultLang(); $current_lang = $langs->getDefaultLang();
@ -106,7 +105,9 @@ $cancel != $langs->trans("Cancel") &&
// sauvegarde en base // sauvegarde en base
$res = $object->setMultiLangs($user); $res = $object->setMultiLangs($user);
if ($res < 0) $error++; if ($res < 0) {
$error++;
}
} }
} }
@ -121,13 +122,11 @@ $cancel != $langs->trans("Cancel") &&
// Validation de l'edition // Validation de l'edition
if ($action == 'vedit' && if ($action == 'vedit' &&
$cancel != $langs->trans("Cancel") && $cancel != $langs->trans("Cancel") &&
($user->rights->categorie->creer)) ($user->rights->categorie->creer)) {
{
$object->fetch($id); $object->fetch($id);
$current_lang = $langs->getDefaultLang(); $current_lang = $langs->getDefaultLang();
foreach ($object->multilangs as $key => $value) // enregistrement des nouvelles valeurs dans l'objet foreach ($object->multilangs as $key => $value) { // enregistrement des nouvelles valeurs dans l'objet
{
$libelle = GETPOST('libelle-'.$key, 'alpha'); $libelle = GETPOST('libelle-'.$key, 'alpha');
$desc = GETPOST('desc-'.$key); $desc = GETPOST('desc-'.$key);
@ -147,7 +146,9 @@ $cancel != $langs->trans("Cancel") &&
if (!$error) { if (!$error) {
$res = $object->setMultiLangs($user); $res = $object->setMultiLangs($user);
if ($res < 0) $error++; if ($res < 0) {
$error++;
}
} }
if ($error) { if ($error) {
@ -175,10 +176,8 @@ $head = categories_prepare_head($object, $type);
// Calculate $cnt_trans // Calculate $cnt_trans
$cnt_trans = 0; $cnt_trans = 0;
if (!empty($object->multilangs)) if (!empty($object->multilangs)) {
{ foreach ($object->multilangs as $key => $value) {
foreach ($object->multilangs as $key => $value)
{
$cnt_trans++; $cnt_trans++;
} }
} }
@ -232,12 +231,12 @@ print dol_get_fiche_end();
print "\n<div class=\"tabsAction\">\n"; print "\n<div class=\"tabsAction\">\n";
if ($action == '') if ($action == '') {
{ if ($user->rights->produit->creer || $user->rights->service->creer) {
if ($user->rights->produit->creer || $user->rights->service->creer)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&id='.$object->id.'&type='.$type.'">'.$langs->trans('Add').'</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=add&id='.$object->id.'&type='.$type.'">'.$langs->trans('Add').'</a>';
if ($cnt_trans > 0) print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&id='.$object->id.'&type='.$type.'">'.$langs->trans('Update').'</a>'; if ($cnt_trans > 0) {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&id='.$object->id.'&type='.$type.'">'.$langs->trans('Update').'</a>';
}
} }
} }
@ -245,8 +244,7 @@ print "\n</div>\n";
if ($action == 'edit') if ($action == 'edit') {
{
//WYSIWYG Editor //WYSIWYG Editor
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
@ -256,10 +254,8 @@ if ($action == 'edit')
print '<input type="hidden" name="id" value="'.$object->id.'">'; print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="type" value="'.$type.'">'; print '<input type="hidden" name="type" value="'.$type.'">';
if (!empty($object->multilangs)) if (!empty($object->multilangs)) {
{ foreach ($object->multilangs as $key => $value) {
foreach ($object->multilangs as $key => $value)
{
print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>"; print "<br><b><u>".$langs->trans('Language_'.$key)." :</u></b><br>";
print '<table class="border centpercent">'; print '<table class="border centpercent">';
@ -287,27 +283,27 @@ if ($action == 'edit')
print '</div>'; print '</div>';
print '</form>'; print '</form>';
} elseif ($action != 'add') } elseif ($action != 'add') {
{ if ($cnt_trans) {
if ($cnt_trans) print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
}
if (!empty($object->multilangs)) if (!empty($object->multilangs)) {
{ foreach ($object->multilangs as $key => $value) {
foreach ($object->multilangs as $key => $value)
{
$s = picto_from_langcode($key); $s = picto_from_langcode($key);
print '<table class="border centpercent">'; print '<table class="border centpercent">';
print '<tr class="liste_titre"><td colspan="2">'.($s ? $s.' ' : '')." <b>".$langs->trans('Language_'.$key).":</b> ".'<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'&type='.$type.'">'.img_delete('', '').'</a></td></tr>'; print '<tr class="liste_titre"><td colspan="2">'.($s ? $s.' ' : '')." <b>".$langs->trans('Language_'.$key).":</b> ".'<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&langtodelete='.$key.'&type='.$type.'">'.img_delete('', '').'</a></td></tr>';
print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>'; print '<tr><td class="titlefield">'.$langs->trans('Label').'</td><td>'.$object->multilangs[$key]["label"].'</td></tr>';
print '<tr><td>'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>'; print '<tr><td>'.$langs->trans('Description').'</td><td>'.$object->multilangs[$key]["description"].'</td></tr>';
if (!empty($conf->global->CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION)) if (!empty($conf->global->CATEGORY_USE_OTHER_FIELD_IN_TRANSLATION)) {
{
print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>'; print '<tr><td>'.$langs->trans('Other').' ('.$langs->trans("NotUsed").')</td><td>'.$object->multilangs[$key]["other"].'</td></tr>';
} }
print '</table>'; print '</table>';
} }
} }
if (!$cnt_trans && $action != 'add') print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>'; if (!$cnt_trans && $action != 'add') {
print '<div class="opacitymedium">'.$langs->trans('NoTranslation').'</div>';
}
} }
@ -315,8 +311,7 @@ if ($action == 'edit')
* Form to add a new translation * Form to add a new translation
*/ */
if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer)) if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer)) {
{
//WYSIWYG Editor //WYSIWYG Editor
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';

View File

@ -49,7 +49,7 @@ $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'categorylist'; // To manage different context of search $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'categorylist'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
// Load variable for pagination // Load variable for pagination
@ -57,13 +57,14 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma'); $sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
$page = 0;
} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if ($id == "" && $label == "") if ($id == "" && $label == "") {
{
dol_print_error('', 'Missing parameter id'); dol_print_error('', 'Missing parameter id');
exit(); exit();
} }
@ -78,7 +79,9 @@ if ($result <= 0) {
} }
$type = $object->type; $type = $object->type;
if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
}
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label($object->table_element); $extrafields->fetch_name_optionals_label($object->table_element);
@ -90,8 +93,7 @@ $hookmanager->initHooks(array('categorycard', 'globalcard'));
* Actions * Actions
*/ */
if ($confirm == 'no') if ($confirm == 'no') {
{
if ($backtopage) { if ($backtopage) {
header("Location: ".$backtopage); header("Location: ".$backtopage);
exit; exit;
@ -101,26 +103,21 @@ if ($confirm == 'no')
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
// Remove element from category // Remove element from category
if ($id > 0 && $removeelem > 0) if ($id > 0 && $removeelem > 0) {
{ if ($type == Categorie::TYPE_PRODUCT && ($user->rights->produit->creer || $user->rights->service->creer)) {
if ($type == Categorie::TYPE_PRODUCT && ($user->rights->produit->creer || $user->rights->service->creer))
{
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
$tmpobject = new Product($db); $tmpobject = new Product($db);
$result = $tmpobject->fetch($removeelem); $result = $tmpobject->fetch($removeelem);
$elementtype = 'product'; $elementtype = 'product';
} elseif ($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer) } elseif ($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer) {
{
$tmpobject = new Societe($db); $tmpobject = new Societe($db);
$result = $tmpobject->fetch($removeelem); $result = $tmpobject->fetch($removeelem);
$elementtype = 'supplier'; $elementtype = 'supplier';
} elseif ($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer) } elseif ($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer) {
{
$tmpobject = new Societe($db); $tmpobject = new Societe($db);
$result = $tmpobject->fetch($removeelem); $result = $tmpobject->fetch($removeelem);
$elementtype = 'customer'; $elementtype = 'customer';
} elseif ($type == Categorie::TYPE_MEMBER && $user->rights->adherent->creer) } elseif ($type == Categorie::TYPE_MEMBER && $user->rights->adherent->creer) {
{
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
$tmpobject = new Adherent($db); $tmpobject = new Adherent($db);
$result = $tmpobject->fetch($removeelem); $result = $tmpobject->fetch($removeelem);
@ -130,20 +127,17 @@ if ($id > 0 && $removeelem > 0)
$tmpobject = new Contact($db); $tmpobject = new Contact($db);
$result = $tmpobject->fetch($removeelem); $result = $tmpobject->fetch($removeelem);
$elementtype = 'contact'; $elementtype = 'contact';
} elseif ($type == Categorie::TYPE_ACCOUNT && $user->rights->banque->configurer) } elseif ($type == Categorie::TYPE_ACCOUNT && $user->rights->banque->configurer) {
{
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$tmpobject = new Account($db); $tmpobject = new Account($db);
$result = $tmpobject->fetch($removeelem); $result = $tmpobject->fetch($removeelem);
$elementtype = 'account'; $elementtype = 'account';
} elseif ($type == Categorie::TYPE_PROJECT && $user->rights->projet->creer) } elseif ($type == Categorie::TYPE_PROJECT && $user->rights->projet->creer) {
{
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
$tmpobject = new Project($db); $tmpobject = new Project($db);
$result = $tmpobject->fetch($removeelem); $result = $tmpobject->fetch($removeelem);
$elementtype = 'project'; $elementtype = 'project';
} elseif ($type == Categorie::TYPE_USER && $user->rights->user->user->creer) } elseif ($type == Categorie::TYPE_USER && $user->rights->user->user->creer) {
{
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$tmpobject = new User($db); $tmpobject = new User($db);
$result = $tmpobject->fetch($removeelem); $result = $tmpobject->fetch($removeelem);
@ -151,13 +145,13 @@ if ($id > 0 && $removeelem > 0)
} }
$result = $object->del_type($tmpobject, $elementtype); $result = $object->del_type($tmpobject, $elementtype);
if ($result < 0) dol_print_error('', $object->error); if ($result < 0) {
dol_print_error('', $object->error);
}
} }
if ($user->rights->categorie->supprimer && $action == 'confirm_delete' && $confirm == 'yes') if ($user->rights->categorie->supprimer && $action == 'confirm_delete' && $confirm == 'yes') {
{ if ($object->delete($user) >= 0) {
if ($object->delete($user) >= 0)
{
if ($backtopage) { if ($backtopage) {
header("Location: ".$backtopage); header("Location: ".$backtopage);
exit; exit;
@ -174,20 +168,16 @@ if ($elemid && $action == 'addintocategory' &&
(($type == Categorie::TYPE_PRODUCT && ($user->rights->produit->creer || $user->rights->service->creer)) || (($type == Categorie::TYPE_PRODUCT && ($user->rights->produit->creer || $user->rights->service->creer)) ||
($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer) || ($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer) ||
($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer) ($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer)
)) )) {
{ if ($type == Categorie::TYPE_PRODUCT) {
if ($type == Categorie::TYPE_PRODUCT)
{
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
$newobject = new Product($db); $newobject = new Product($db);
$elementtype = 'product'; $elementtype = 'product';
} elseif ($type == Categorie::TYPE_CUSTOMER) } elseif ($type == Categorie::TYPE_CUSTOMER) {
{
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
$newobject = new Societe($db); $newobject = new Societe($db);
$elementtype = 'customer'; $elementtype = 'customer';
} elseif ($type == Categorie::TYPE_SUPPLIER) } elseif ($type == Categorie::TYPE_SUPPLIER) {
{
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
$newobject = new Societe($db); $newobject = new Societe($db);
$elementtype = 'supplier'; $elementtype = 'supplier';
@ -196,12 +186,10 @@ if ($elemid && $action == 'addintocategory' &&
// TODO Add into categ // TODO Add into categ
$result = $object->add_type($newobject, $elementtype); $result = $object->add_type($newobject, $elementtype);
if ($result >= 0) if ($result >= 0) {
{
setEventMessages($langs->trans("WasAddedSuccessfully", $newobject->ref), null, 'mesgs'); setEventMessages($langs->trans("WasAddedSuccessfully", $newobject->ref), null, 'mesgs');
} else { } else {
if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
{
setEventMessages($langs->trans("ObjectAlreadyLinkedToCategory"), null, 'warnings'); setEventMessages($langs->trans("ObjectAlreadyLinkedToCategory"), null, 'warnings');
} else { } else {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
@ -233,8 +221,7 @@ $object->next_prev_filter = ' type = '.$object->type;
$object->ref = $object->label; $object->ref = $object->label;
$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> '; $morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
$ways = $object->print_all_ways(" &gt;&gt; ", '', 1); $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
foreach ($ways as $way) foreach ($ways as $way) {
{
$morehtmlref .= $way."<br>\n"; $morehtmlref .= $way."<br>\n";
} }
$morehtmlref .= '</div>'; $morehtmlref .= '</div>';
@ -246,8 +233,7 @@ dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'la
* Confirmation suppression * Confirmation suppression
*/ */
if ($action == 'delete') if ($action == 'delete') {
{
if ($backtopage) { if ($backtopage) {
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&backtopage='.urlencode($backtopage), $langs->trans('DeleteCategory'), $langs->trans('ConfirmDeleteCategory'), 'confirm_delete', '', '', 2); print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&backtopage='.urlencode($backtopage), $langs->trans('DeleteCategory'), $langs->trans('ConfirmDeleteCategory'), 'confirm_delete', '', '', 2);
} else { } else {
@ -288,16 +274,16 @@ print dol_get_fiche_end();
print "<div class='tabsAction'>\n"; print "<div class='tabsAction'>\n";
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) { if (empty($reshook)) {
if ($user->rights->categorie->creer) if ($user->rights->categorie->creer) {
{
$socid = ($object->socid ? "&socid=".$object->socid : ""); $socid = ($object->socid ? "&socid=".$object->socid : "");
print '<a class="butAction" href="edit.php?id='.$object->id.$socid.'&type='.$type.'">'.$langs->trans("Modify").'</a>'; print '<a class="butAction" href="edit.php?id='.$object->id.$socid.'&type='.$type.'">'.$langs->trans("Modify").'</a>';
} }
if ($user->rights->categorie->supprimer) if ($user->rights->categorie->supprimer) {
{
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id.'&type='.$type.'&backtolist='.urlencode($backtolist).'">'.$langs->trans("Delete").'</a>'; print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id.'&type='.$type.'&backtolist='.urlencode($backtolist).'">'.$langs->trans("Delete").'</a>';
} }
} }
@ -305,8 +291,7 @@ if (empty($reshook)) {
print "</div>"; print "</div>";
$newcardbutton = ''; $newcardbutton = '';
if (!empty($user->rights->categorie->creer)) if (!empty($user->rights->categorie->creer)) {
{
$link = DOL_URL_ROOT.'/categories/card.php'; $link = DOL_URL_ROOT.'/categories/card.php';
$link .= '?action=create'; $link .= '?action=create';
$link .= '&type='.$type; $link .= '&type='.$type;
@ -335,8 +320,7 @@ print '<td>'.$langs->trans("SubCats").'</td>';
print '<td></td>'; print '<td></td>';
print '<td class="right">'; print '<td class="right">';
if (!empty($conf->use_javascript_ajax)) if (!empty($conf->use_javascript_ajax)) {
{
print '<div id="iddivjstreecontrol">'; print '<div id="iddivjstreecontrol">';
print '<a class="notasortlink" href="#">'.img_picto('', 'folder').' '.$langs->trans("UndoExpandAll").'</a>'; print '<a class="notasortlink" href="#">'.img_picto('', 'folder').' '.$langs->trans("UndoExpandAll").'</a>';
print " | "; print " | ";
@ -348,11 +332,9 @@ print '</td>';
print '</tr>'; print '</tr>';
$cats = $object->get_filles(); $cats = $object->get_filles();
if ($cats < 0) if ($cats < 0) {
{
dol_print_error($db, $object->error, $object->errors); dol_print_error($db, $object->error, $object->errors);
} elseif (count($cats) < 1) } elseif (count($cats) < 1) {
{
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td colspan="3" class="opacitymedium">'.$langs->trans("NoSubCat").'</td>'; print '<td colspan="3" class="opacitymedium">'.$langs->trans("NoSubCat").'</td>';
print '</tr>'; print '</tr>';
@ -362,19 +344,25 @@ if ($cats < 0)
$fulltree = $categstatic->get_full_arbo($type, $object->id, 1); $fulltree = $categstatic->get_full_arbo($type, $object->id, 1);
// Load possible missing includes // Load possible missing includes
if ($conf->global->CATEGORY_SHOW_COUNTS) if ($conf->global->CATEGORY_SHOW_COUNTS) {
{ if ($type == Categorie::TYPE_MEMBER) {
if ($type == Categorie::TYPE_MEMBER) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
if ($type == Categorie::TYPE_ACCOUNT) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; }
if ($type == Categorie::TYPE_PROJECT) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; if ($type == Categorie::TYPE_ACCOUNT) {
if ($type == Categorie::TYPE_USER) require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
if ($type == Categorie::TYPE_PROJECT) {
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
}
if ($type == Categorie::TYPE_USER) {
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
}
} }
// Define data (format for treeview) // Define data (format for treeview)
$data = array(); $data = array();
$data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>''); $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
foreach ($fulltree as $key => $val) foreach ($fulltree as $key => $val) {
{
$categstatic->id = $val['id']; $categstatic->id = $val['id'];
$categstatic->ref = $val['label']; $categstatic->ref = $val['label'];
$categstatic->color = $val['color']; $categstatic->color = $val['color'];
@ -382,8 +370,7 @@ if ($cats < 0)
$desc = dol_htmlcleanlastbr($val['description']); $desc = dol_htmlcleanlastbr($val['description']);
$counter = ''; $counter = '';
if ($conf->global->CATEGORY_SHOW_COUNTS) if ($conf->global->CATEGORY_SHOW_COUNTS) {
{
// we need only a count of the elements, so it is enough to consume only the id's from the database // we need only a count of the elements, so it is enough to consume only the id's from the database
$elements = $type == Categorie::TYPE_ACCOUNT $elements = $type == Categorie::TYPE_ACCOUNT
? $categstatic->getObjectsInCateg("account", 1) // Categorie::TYPE_ACCOUNT is "bank_account" instead of "account" ? $categstatic->getObjectsInCateg("account", 1) // Categorie::TYPE_ACCOUNT is "bank_account" instead of "account"
@ -421,8 +408,7 @@ if ($cats < 0)
} }
$nbofentries = (count($data) - 1); $nbofentries = (count($data) - 1);
if ($nbofentries > 0) if ($nbofentries > 0) {
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
print '<tr class="pair">'; print '<tr class="pair">';
print '<td colspan="3">'; print '<td colspan="3">';
@ -465,19 +451,16 @@ $typeid = $type;
// List of products or services (type is type of category) // List of products or services (type is type of category)
if ($type == Categorie::TYPE_PRODUCT) if ($type == Categorie::TYPE_PRODUCT) {
{
$permission = ($user->rights->produit->creer || $user->rights->service->creer); $permission = ($user->rights->produit->creer || $user->rights->service->creer);
$prods = $object->getObjectsInCateg($type, 0, $limit, $offset); $prods = $object->getObjectsInCateg($type, 0, $limit, $offset);
if ($prods < 0) if ($prods < 0) {
{
dol_print_error($db, $object->error, $object->errors); dol_print_error($db, $object->error, $object->errors);
} else { } else {
// Form to add record into a category // Form to add record into a category
$showclassifyform = 1; $showclassifyform = 1;
if ($showclassifyform) if ($showclassifyform) {
{
print '<br>'; print '<br>';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
@ -510,13 +493,13 @@ if ($type == Categorie::TYPE_PRODUCT)
print '<table class="noborder centpercent">'."\n"; print '<table class="noborder centpercent">'."\n";
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Ref").'</td></tr>'."\n"; print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Ref").'</td></tr>'."\n";
if (count($prods) > 0) if (count($prods) > 0) {
{
$i = 0; $i = 0;
foreach ($prods as $prod) foreach ($prods as $prod) {
{
$i++; $i++;
if ($i > $limit) break; if ($i > $limit) {
break;
}
print "\t".'<tr class="oddeven">'."\n"; print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">'; print '<td class="nowrap" valign="top">';
@ -525,8 +508,7 @@ if ($type == Categorie::TYPE_PRODUCT)
print '<td class="tdtop">'.$prod->label."</td>\n"; print '<td class="tdtop">'.$prod->label."</td>\n";
// Link to delete from category // Link to delete from category
print '<td class="right">'; print '<td class="right">';
if ($permission) if ($permission) {
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$prod->id."'>"; print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$prod->id."'>";
print $langs->trans("DeleteFromCat"); print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
@ -544,19 +526,16 @@ if ($type == Categorie::TYPE_PRODUCT)
} }
} }
if ($type == Categorie::TYPE_CUSTOMER) if ($type == Categorie::TYPE_CUSTOMER) {
{
$permission = $user->rights->societe->creer; $permission = $user->rights->societe->creer;
$socs = $object->getObjectsInCateg($type, 0, $limit, $offset); $socs = $object->getObjectsInCateg($type, 0, $limit, $offset);
if ($socs < 0) if ($socs < 0) {
{
dol_print_error($db, $object->error, $object->errors); dol_print_error($db, $object->error, $object->errors);
} else { } else {
// Form to add record into a category // Form to add record into a category
$showclassifyform = 1; $showclassifyform = 1;
if ($showclassifyform) if ($showclassifyform) {
{
print '<br>'; print '<br>';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
@ -588,13 +567,13 @@ if ($type == Categorie::TYPE_CUSTOMER)
print '<table class="noborder centpercent">'."\n"; print '<table class="noborder centpercent">'."\n";
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Name").'</td></tr>'."\n"; print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Name").'</td></tr>'."\n";
if (count($socs) > 0) if (count($socs) > 0) {
{
$i = 0; $i = 0;
foreach ($socs as $key => $soc) foreach ($socs as $key => $soc) {
{
$i++; $i++;
if ($i > $limit) break; if ($i > $limit) {
break;
}
print "\t".'<tr class="oddeven">'."\n"; print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">'; print '<td class="nowrap" valign="top">';
@ -602,8 +581,7 @@ if ($type == Categorie::TYPE_CUSTOMER)
print "</td>\n"; print "</td>\n";
// Link to delete from category // Link to delete from category
print '<td class="right">'; print '<td class="right">';
if ($permission) if ($permission) {
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$soc->id."'>"; print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$soc->id."'>";
print $langs->trans("DeleteFromCat"); print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
@ -622,19 +600,16 @@ if ($type == Categorie::TYPE_CUSTOMER)
} }
if ($type == Categorie::TYPE_SUPPLIER) if ($type == Categorie::TYPE_SUPPLIER) {
{
$permission = $user->rights->societe->creer; $permission = $user->rights->societe->creer;
$socs = $object->getObjectsInCateg($type, 0, $limit, $offset); $socs = $object->getObjectsInCateg($type, 0, $limit, $offset);
if ($socs < 0) if ($socs < 0) {
{
dol_print_error($db, $object->error, $object->errors); dol_print_error($db, $object->error, $object->errors);
} else { } else {
// Form to add record into a category // Form to add record into a category
$showclassifyform = 1; $showclassifyform = 1;
if ($showclassifyform) if ($showclassifyform) {
{
print '<br>'; print '<br>';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
@ -666,13 +641,13 @@ if ($type == Categorie::TYPE_SUPPLIER)
print '<table class="noborder centpercent">'."\n"; print '<table class="noborder centpercent">'."\n";
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Name")."</td></tr>\n"; print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Name")."</td></tr>\n";
if (count($socs) > 0) if (count($socs) > 0) {
{
$i = 0; $i = 0;
foreach ($socs as $soc) foreach ($socs as $soc) {
{
$i++; $i++;
if ($i > $limit) break; if ($i > $limit) {
break;
}
print "\t".'<tr class="oddeven">'."\n"; print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">'; print '<td class="nowrap" valign="top">';
@ -680,8 +655,7 @@ if ($type == Categorie::TYPE_SUPPLIER)
print "</td>\n"; print "</td>\n";
// Link to delete from category // Link to delete from category
print '<td class="right">'; print '<td class="right">';
if ($permission) if ($permission) {
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$soc->id."'>"; print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$soc->id."'>";
print $langs->trans("DeleteFromCat"); print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
@ -701,15 +675,13 @@ if ($type == Categorie::TYPE_SUPPLIER)
} }
// List of members // List of members
if ($type == Categorie::TYPE_MEMBER) if ($type == Categorie::TYPE_MEMBER) {
{
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
$permission = $user->rights->adherent->creer; $permission = $user->rights->adherent->creer;
$prods = $object->getObjectsInCateg($type, 0, $limit, $offset); $prods = $object->getObjectsInCateg($type, 0, $limit, $offset);
if ($prods < 0) if ($prods < 0) {
{
dol_print_error($db, $object->error, $object->errors); dol_print_error($db, $object->error, $object->errors);
} else { } else {
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
@ -726,13 +698,13 @@ if ($type == Categorie::TYPE_MEMBER)
print "<table class='noborder' width='100%'>\n"; print "<table class='noborder' width='100%'>\n";
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Name").'</td></tr>'."\n"; print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Name").'</td></tr>'."\n";
if (count($prods) > 0) if (count($prods) > 0) {
{
$i = 0; $i = 0;
foreach ($prods as $key => $member) foreach ($prods as $key => $member) {
{
$i++; $i++;
if ($i > $limit) break; if ($i > $limit) {
break;
}
print "\t".'<tr class="oddeven">'."\n"; print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">'; print '<td class="nowrap" valign="top">';
@ -743,8 +715,7 @@ if ($type == Categorie::TYPE_MEMBER)
print '<td class="tdtop">'.$member->firstname."</td>\n"; print '<td class="tdtop">'.$member->firstname."</td>\n";
// Link to delete from category // Link to delete from category
print '<td class="right">'; print '<td class="right">';
if ($permission) if ($permission) {
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$member->id."'>"; print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$member->id."'>";
print $langs->trans("DeleteFromCat"); print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
@ -762,13 +733,11 @@ if ($type == Categorie::TYPE_MEMBER)
} }
// Categorie contact // Categorie contact
if ($type == Categorie::TYPE_CONTACT) if ($type == Categorie::TYPE_CONTACT) {
{
$permission = $user->rights->societe->creer; $permission = $user->rights->societe->creer;
$contacts = $object->getObjectsInCateg($type, 0, $limit, $offset); $contacts = $object->getObjectsInCateg($type, 0, $limit, $offset);
if ($contacts < 0) if ($contacts < 0) {
{
dol_print_error($db, $object->error, $object->errors); dol_print_error($db, $object->error, $object->errors);
} else { } else {
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
@ -788,13 +757,13 @@ if ($type == Categorie::TYPE_CONTACT)
print '<table class="noborder centpercent">'."\n"; print '<table class="noborder centpercent">'."\n";
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Ref").'</td></tr>'."\n"; print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Ref").'</td></tr>'."\n";
if (count($contacts) > 0) if (count($contacts) > 0) {
{
$i = 0; $i = 0;
foreach ($contacts as $key => $contact) foreach ($contacts as $key => $contact) {
{
$i++; $i++;
if ($i > $limit) break; if ($i > $limit) {
break;
}
print "\t".'<tr class="oddeven">'."\n"; print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">'; print '<td class="nowrap" valign="top">';
@ -802,8 +771,7 @@ if ($type == Categorie::TYPE_CONTACT)
print "</td>\n"; print "</td>\n";
// Link to delete from category // Link to delete from category
print '<td class="right">'; print '<td class="right">';
if ($permission) if ($permission) {
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$contact->id."'>"; print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$contact->id."'>";
print $langs->trans("DeleteFromCat"); print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
@ -822,15 +790,13 @@ if ($type == Categorie::TYPE_CONTACT)
} }
// List of bank accounts // List of bank accounts
if ($type == Categorie::TYPE_ACCOUNT) if ($type == Categorie::TYPE_ACCOUNT) {
{
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$permission = $user->rights->banque->creer; $permission = $user->rights->banque->creer;
$accounts = $object->getObjectsInCateg($type, 0, $limit, $offset); $accounts = $object->getObjectsInCateg($type, 0, $limit, $offset);
if ($accounts < 0) if ($accounts < 0) {
{
dol_print_error($db, $object->error, $object->errors); dol_print_error($db, $object->error, $object->errors);
} else { } else {
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
@ -847,13 +813,13 @@ if ($type == Categorie::TYPE_ACCOUNT)
print "<table class='noborder' width='100%'>\n"; print "<table class='noborder' width='100%'>\n";
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n"; print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n";
if (count($accounts) > 0) if (count($accounts) > 0) {
{
$i = 0; $i = 0;
foreach ($accounts as $key => $account) foreach ($accounts as $key => $account) {
{
$i++; $i++;
if ($i > $limit) break; if ($i > $limit) {
break;
}
print "\t".'<tr class="oddeven">'."\n"; print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">'; print '<td class="nowrap" valign="top">';
@ -863,8 +829,7 @@ if ($type == Categorie::TYPE_ACCOUNT)
print '<td class="tdtop">'.$account->number."</td>\n"; print '<td class="tdtop">'.$account->number."</td>\n";
// Link to delete from category // Link to delete from category
print '<td class="right">'; print '<td class="right">';
if ($permission) if ($permission) {
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$account->id."'>"; print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$account->id."'>";
print $langs->trans("DeleteFromCat"); print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
@ -882,15 +847,13 @@ if ($type == Categorie::TYPE_ACCOUNT)
} }
// List of Project // List of Project
if ($type == Categorie::TYPE_PROJECT) if ($type == Categorie::TYPE_PROJECT) {
{
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
$permission = $user->rights->projet->creer; $permission = $user->rights->projet->creer;
$objects = $object->getObjectsInCateg($type, 0, $limit, $offset); $objects = $object->getObjectsInCateg($type, 0, $limit, $offset);
if ($objects < 0) if ($objects < 0) {
{
dol_print_error($db, $object->error, $object->errors); dol_print_error($db, $object->error, $object->errors);
} else { } else {
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
@ -908,13 +871,13 @@ if ($type == Categorie::TYPE_PROJECT)
print "<table class='noborder' width='100%'>\n"; print "<table class='noborder' width='100%'>\n";
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n"; print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n";
if (count($objects) > 0) if (count($objects) > 0) {
{
$i = 0; $i = 0;
foreach ($objects as $key => $project) foreach ($objects as $key => $project) {
{
$i++; $i++;
if ($i > $limit) break; if ($i > $limit) {
break;
}
print "\t".'<tr class="oddeven">'."\n"; print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">'; print '<td class="nowrap" valign="top">';
@ -924,8 +887,7 @@ if ($type == Categorie::TYPE_PROJECT)
print '<td class="tdtop">'.$project->title."</td>\n"; print '<td class="tdtop">'.$project->title."</td>\n";
// Link to delete from category // Link to delete from category
print '<td class="right">'; print '<td class="right">';
if ($permission) if ($permission) {
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$project->id."'>"; print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$project->id."'>";
print $langs->trans("DeleteFromCat"); print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
@ -943,13 +905,11 @@ if ($type == Categorie::TYPE_PROJECT)
} }
// List of users // List of users
if ($type == Categorie::TYPE_USER) if ($type == Categorie::TYPE_USER) {
{
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$users = $object->getObjectsInCateg($type); $users = $object->getObjectsInCateg($type);
if ($users < 0) if ($users < 0) {
{
dol_print_error($db, $object->error, $object->errors); dol_print_error($db, $object->error, $object->errors);
} else { } else {
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
@ -969,11 +929,9 @@ if ($type == Categorie::TYPE_USER)
print "<table class='noborder' width='100%'>\n"; print "<table class='noborder' width='100%'>\n";
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Users").' <span class="badge">'.$num.'</span></td></tr>'."\n"; print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Users").' <span class="badge">'.$num.'</span></td></tr>'."\n";
if (count($users) > 0) if (count($users) > 0) {
{
// Use "$userentry" here, because "$user" is the current user // Use "$userentry" here, because "$user" is the current user
foreach ($users as $key => $userentry) foreach ($users as $key => $userentry) {
{
print "\t".'<tr class="oddeven">'."\n"; print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">'; print '<td class="nowrap" valign="top">';
print $userentry->getNomUrl(1); print $userentry->getNomUrl(1);
@ -982,8 +940,7 @@ if ($type == Categorie::TYPE_USER)
// Link to delete from category // Link to delete from category
print '<td class="right">'; print '<td class="right">';
if ($user->rights->user->user->creer) if ($user->rights->user->user->creer) {
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$type."&amp;removeelem=".$userentry->id."'>"; print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$type."&amp;removeelem=".$userentry->id."'>";
print $langs->trans("DeleteFromCat"); print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
@ -1002,15 +959,13 @@ if ($type == Categorie::TYPE_USER)
// List of warehouses // List of warehouses
if ($type == Categorie::TYPE_WAREHOUSE) if ($type == Categorie::TYPE_WAREHOUSE) {
{
$permission = $user->rights->stock->creer; $permission = $user->rights->stock->creer;
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
$objects = $object->getObjectsInCateg($type, 0, $limit, $offset); $objects = $object->getObjectsInCateg($type, 0, $limit, $offset);
if ($objects < 0) if ($objects < 0) {
{
dol_print_error($db, $object->error, $object->errors); dol_print_error($db, $object->error, $object->errors);
} else { } else {
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
@ -1028,13 +983,13 @@ if ($type == Categorie::TYPE_WAREHOUSE)
print "<table class='noborder' width='100%'>\n"; print "<table class='noborder' width='100%'>\n";
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n"; print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n";
if (count($objects) > 0) if (count($objects) > 0) {
{
$i = 0; $i = 0;
foreach ($objects as $key => $project) foreach ($objects as $key => $project) {
{
$i++; $i++;
if ($i > $limit) break; if ($i > $limit) {
break;
}
print "\t".'<tr class="oddeven">'."\n"; print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">'; print '<td class="nowrap" valign="top">';
@ -1044,8 +999,7 @@ if ($type == Categorie::TYPE_WAREHOUSE)
print '<td class="tdtop">'.$project->title."</td>\n"; print '<td class="tdtop">'.$project->title."</td>\n";
// Link to delete from category // Link to delete from category
print '<td class="right">'; print '<td class="right">';
if ($permission) if ($permission) {
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$project->id."'>"; print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$project->id."'>";
print $langs->trans("DeleteFromCat"); print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');

View File

@ -31,7 +31,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("admin", "other", "website")); $langs->loadLangs(array("admin", "other", "website"));
if (!$user->admin) accessforbidden(); if (!$user->admin) {
accessforbidden();
}
$conf->dol_hide_leftmenu = 1; // Force hide of left menu. $conf->dol_hide_leftmenu = 1; // Force hide of left menu.
@ -41,17 +43,37 @@ $page = GETPOST('page', 'alpha');
$pageid = GETPOST('pageid', 'int'); $pageid = GETPOST('pageid', 'int');
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
if (GETPOST('delete')) { $action = 'delete'; } if (GETPOST('delete')) {
if (GETPOST('preview')) $action = 'preview'; $action = 'delete';
if (GETPOST('create')) { $action = 'create'; } }
if (GETPOST('editmedia')) { $action = 'editmedia'; } if (GETPOST('preview')) {
if (GETPOST('editcss')) { $action = 'editcss'; } $action = 'preview';
if (GETPOST('editmenu')) { $action = 'editmenu'; } }
if (GETPOST('setashome')) { $action = 'setashome'; } if (GETPOST('create')) {
if (GETPOST('editmeta')) { $action = 'editmeta'; } $action = 'create';
if (GETPOST('editcontent')) { $action = 'editcontent'; } }
if (GETPOST('editmedia')) {
$action = 'editmedia';
}
if (GETPOST('editcss')) {
$action = 'editcss';
}
if (GETPOST('editmenu')) {
$action = 'editmenu';
}
if (GETPOST('setashome')) {
$action = 'setashome';
}
if (GETPOST('editmeta')) {
$action = 'editmeta';
}
if (GETPOST('editcontent')) {
$action = 'editcontent';
}
if (empty($action)) $action = 'preview'; if (empty($action)) {
$action = 'preview';
}
@ -60,13 +82,16 @@ if (empty($action)) $action = 'preview';
* Actions * Actions
*/ */
if (GETPOST('refreshsite')) $pageid = 0; // If we change the site, we reset the pageid. if (GETPOST('refreshsite')) {
if (GETPOST('refreshpage')) $action = 'preview'; $pageid = 0; // If we change the site, we reset the pageid.
}
if (GETPOST('refreshpage')) {
$action = 'preview';
}
// Add a collab page // Add a collab page
if ($action == 'add') if ($action == 'add') {
{
$db->begin(); $db->begin();
$objectpage->title = GETPOST('WEBSITE_TITLE'); $objectpage->title = GETPOST('WEBSITE_TITLE');
@ -74,23 +99,19 @@ if ($action == 'add')
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); $objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
$objectpage->keywords = GETPOST('WEBSITE_KEYWORD'); $objectpage->keywords = GETPOST('WEBSITE_KEYWORD');
if (empty($objectpage->title)) if (empty($objectpage->title)) {
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
$error++; $error++;
} }
if (!$error) if (!$error) {
{
$res = $objectpage->create($user); $res = $objectpage->create($user);
if ($res <= 0) if ($res <= 0) {
{
$error++; $error++;
setEventMessages($objectpage->error, $objectpage->errors, 'errors'); setEventMessages($objectpage->error, $objectpage->errors, 'errors');
} }
} }
if (!$error) if (!$error) {
{
$db->commit(); $db->commit();
setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs'); setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
$action = ''; $action = '';
@ -103,25 +124,21 @@ if ($action == 'add')
} }
// Update page // Update page
if ($action == 'delete') if ($action == 'delete') {
{
$db->begin(); $db->begin();
$res = $object->fetch(0, $website); $res = $object->fetch(0, $website);
$res = $objectpage->fetch($pageid, $object->fk_website); $res = $objectpage->fetch($pageid, $object->fk_website);
if ($res > 0) if ($res > 0) {
{
$res = $objectpage->delete($user); $res = $objectpage->delete($user);
if (!($res > 0)) if (!($res > 0)) {
{
$error++; $error++;
setEventMessages($objectpage->error, $objectpage->errors, 'errors'); setEventMessages($objectpage->error, $objectpage->errors, 'errors');
} }
if (!$error) if (!$error) {
{
$db->commit(); $db->commit();
setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs'); setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs');
@ -149,15 +166,16 @@ llxHeader('', $langs->trans("WebsiteSetup"), $help_url, '', 0, '', '', '', '', '
print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST"><div>'; print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST"><div>';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
if ($action == 'create') if ($action == 'create') {
{
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
} }
// Add a margin under toolbar ? // Add a margin under toolbar ?
$style = ''; $style = '';
if ($action != 'preview' && $action != 'editcontent') $style = ' margin-bottom: 5px;'; if ($action != 'preview' && $action != 'editcontent') {
$style = ' margin-bottom: 5px;';
}
//var_dump($objectpage);exit; //var_dump($objectpage);exit;
print '<div class="centpercent websitebar">'; print '<div class="centpercent websitebar">';