* Copyright (C) 2005 Eric Seigne * Copyright (C) 2006-2016 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2021 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/categories/index.php * \ingroup category * \brief Home page of category area */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; // Load translation files required by the page $langs->load("categories"); $id = GETPOSTINT('id'); $type = (GETPOST('type', 'aZ09') ? GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT); $catname = GETPOST('catname', 'alpha'); $nosearch = GETPOSTINT('nosearch'); $categstatic = new Categorie($db); if (is_numeric($type)) { $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility } // Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('categoryindex')); if (!$user->hasRight('categorie', 'lire')) { accessforbidden(); } /* * View */ $form = new Form($db); $moreparam = ($nosearch ? '&nosearch=1' : ''); $typetext = $type; if ($type == Categorie::TYPE_ACCOUNT) { $title = $langs->trans('AccountsCategoriesArea'); } elseif ($type == Categorie::TYPE_WAREHOUSE) { $title = $langs->trans('StocksCategoriesArea'); } 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'); } $arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js'); $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css'); llxHeader('', $title, '', '', 0, 0, $arrayofjs, $arrayofcss); $newcardbutton = ''; if ($user->hasRight('categorie', 'creer')) { $newcardbutton .= dolGetButtonTitle($langs->trans('NewCategory'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/categories/card.php?action=create&type='.$type.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam).$moreparam); } print load_fiche_titre($title, $newcardbutton, 'object_category'); // Search categories if (empty($nosearch)) { print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Search").'
'; print $langs->trans("Name").':
'; print '
'; /* * Categories found */ if ($catname || $id > 0) { $cats = $categstatic->rechercher($id, $catname, $typetext); print ''; print ''; foreach ($cats as $cat) { $categstatic->id = $cat->id; $categstatic->ref = $cat->label; $categstatic->label = $cat->label; $categstatic->type = $cat->type; $categstatic->color = $cat->color; $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"'; print "\t".''."\n"; print "\t\t\n"; print "\t\t\n"; print "\t\n"; } print "
'.$langs->trans("FoundCats").'
"; print ''; print $categstatic->getNomUrl(1, ''); print ''; print ""; $text = dolGetFirstLineOfText(dol_string_nohtmltag($cat->description, 1)); $trunclength = 48; print $form->textwithtooltip(dol_trunc($text, $trunclength), $cat->description); print "
"; } else { print ' '; } print '
'; } print '

'; // Charge tableau des categories $cate_arbo = $categstatic->get_full_arbo($typetext); // Define fulltree array $fulltree = $cate_arbo; // Load possible missing includes if (getDolGlobalString('CATEGORY_SHOW_COUNTS')) { if ($type == Categorie::TYPE_MEMBER) { 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_USER) { require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; } } // Define data (format for treeview) $data = array(); $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>''); foreach ($fulltree as $key => $val) { $categstatic->id = $val['id']; $categstatic->ref = $val['label']; $categstatic->color = $val['color']; $categstatic->type = $type; $desc = dol_htmlcleanlastbr($val['description']); $counter = ''; if (getDolGlobalString('CATEGORY_SHOW_COUNTS')) { // 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 ? $categstatic->getObjectsInCateg("account", 1) // Categorie::TYPE_ACCOUNT is "bank_account" instead of "account" : $categstatic->getObjectsInCateg($type, 1); $counter = "".(is_array($elements) ? count($elements) : '0').""; } $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"'; $li = $categstatic->getNomUrl(1, '', 60, '&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam)); $entry = ''; $entry .= ''; $entry .= ''; // Add column counter $entry .= $counter; $entry .= ''; $entry .= ''; $entry .= ''; $entry .= ''; $entry .= '
'; $entry .= ''.$li.''; $entry .= ''; $entry .= ''.img_view().''; $entry .= ''; if ($user->hasRight('categorie', 'creer')) { $entry .= '' . img_edit() . ''; } $entry .= ''; if ($user->hasRight('categorie', 'supprimer')) { $entry .= '' . img_delete() . ''; } $entry .= '
'; $data[] = array('rowid' => $val['rowid'], 'fk_menu' => $val['fk_parent'], 'entry' => $entry); } $nbofentries = (count($data) - 1); $morethan1level = 0; foreach ($data as $record) { if (!empty($record['fk_menu']) && $record['fk_menu'] > 0) { $morethan1level = 1; } } print ''; print ''; if ($nbofentries > 0) { print ''; } else { print ''; print ''; print ''; } print "
'.$langs->trans("Categories").''; if ($morethan1level && !empty($conf->use_javascript_ajax)) { print ''; } print '
'; tree_recur($data, $data[0], 0); print '
'; print ''; print ''; print '
'.img_picto_common('', 'treemenu/branchbottom.gif').''; print $langs->trans("NoCategoryYet"); print ' 
"; print '
'; // End of page llxFooter(); $db->close();