index.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
  3. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  4. * Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  8. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/categories/index.php
  25. * \ingroup category
  26. * \brief Home page of category area
  27. */
  28. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  33. // Load translation files required by the page
  34. $langs->load("categories");
  35. $id = GETPOST('id', 'int');
  36. $type = (GETPOST('type', 'aZ09') ? GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT);
  37. $catname = GETPOST('catname', 'alpha');
  38. $nosearch = GETPOST('nosearch', 'int');
  39. $categstatic = new Categorie($db);
  40. if (is_numeric($type)) {
  41. $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
  42. }
  43. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
  44. $hookmanager->initHooks(array('categoryindex'));
  45. if (!$user->hasRight('categorie', 'lire')) {
  46. accessforbidden();
  47. }
  48. /*
  49. * View
  50. */
  51. $form = new Form($db);
  52. $moreparam = ($nosearch ? '&nosearch=1' : '');
  53. $typetext = $type;
  54. if ($type == Categorie::TYPE_ACCOUNT) {
  55. $title = $langs->trans('AccountsCategoriesArea');
  56. } elseif ($type == Categorie::TYPE_WAREHOUSE) {
  57. $title = $langs->trans('StocksCategoriesArea');
  58. } elseif ($type == Categorie::TYPE_ACTIONCOMM) {
  59. $title = $langs->trans('ActionCommCategoriesArea');
  60. } elseif ($type == Categorie::TYPE_WEBSITE_PAGE) {
  61. $title = $langs->trans('WebsitePagesCategoriesArea');
  62. } else {
  63. $title = $langs->trans(ucfirst($type).'sCategoriesArea');
  64. }
  65. $arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
  66. $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
  67. llxHeader('', $title, '', '', 0, 0, $arrayofjs, $arrayofcss);
  68. $newcardbutton = '';
  69. if ($user->hasRight('categorie', 'creer')) {
  70. $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);
  71. }
  72. print load_fiche_titre($title, $newcardbutton, 'object_category');
  73. // Search categories
  74. if (empty($nosearch)) {
  75. print '<div class="fichecenter"><div class="fichehalfleft">';
  76. print '<form method="post" action="index.php?type='.$type.'">';
  77. print '<input type="hidden" name="token" value="'.newToken().'">';
  78. print '<input type="hidden" name="type" value="'.$type.'">';
  79. print '<input type="hidden" name="nosearch" value="'.$nosearch.'">';
  80. print '<table class="noborder nohover centpercent">';
  81. print '<tr class="liste_titre">';
  82. print '<td colspan="3">'.$langs->trans("Search").'</td>';
  83. print '</tr>';
  84. print '<tr class="oddeven nohover"><td>';
  85. print $langs->trans("Name").':</td><td><input class="flat inputsearch" type="text" name="catname" value="'.dol_escape_htmltag($catname).'"></td>';
  86. print '<td><input type="submit" class="button small" value="'.$langs->trans("Search").'"></td></tr>';
  87. print '</table></form>';
  88. print '</div><div class="fichehalfright">';
  89. /*
  90. * Categories found
  91. */
  92. if ($catname || $id > 0) {
  93. $cats = $categstatic->rechercher($id, $catname, $typetext);
  94. print '<table class="noborder centpercent">';
  95. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
  96. foreach ($cats as $cat) {
  97. $categstatic->id = $cat->id;
  98. $categstatic->ref = $cat->label;
  99. $categstatic->label = $cat->label;
  100. $categstatic->type = $cat->type;
  101. $categstatic->color = $cat->color;
  102. $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
  103. print "\t".'<tr class="oddeven">'."\n";
  104. print "\t\t<td>";
  105. print '<span class="noborderoncategories"'.$color.'>';
  106. print $categstatic->getNomUrl(1, '');
  107. print '</span>';
  108. print "</td>\n";
  109. print "\t\t<td>";
  110. $text = dolGetFirstLineOfText(dol_string_nohtmltag($cat->description, 1));
  111. $trunclength = 48;
  112. print $form->textwithtooltip(dol_trunc($text, $trunclength), $cat->description);
  113. print "</td>\n";
  114. print "\t</tr>\n";
  115. }
  116. print "</table>";
  117. } else {
  118. print '&nbsp;';
  119. }
  120. print '</div></div>';
  121. }
  122. print '<div class="fichecenter"><br>';
  123. // Charge tableau des categories
  124. $cate_arbo = $categstatic->get_full_arbo($typetext);
  125. // Define fulltree array
  126. $fulltree = $cate_arbo;
  127. // Load possible missing includes
  128. if (!empty($conf->global->CATEGORY_SHOW_COUNTS)) {
  129. if ($type == Categorie::TYPE_MEMBER) {
  130. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  131. }
  132. if ($type == Categorie::TYPE_ACCOUNT) {
  133. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  134. }
  135. if ($type == Categorie::TYPE_PROJECT) {
  136. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  137. }
  138. if ($type == Categorie::TYPE_USER) {
  139. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  140. }
  141. }
  142. // Define data (format for treeview)
  143. $data = array();
  144. $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
  145. foreach ($fulltree as $key => $val) {
  146. $categstatic->id = $val['id'];
  147. $categstatic->ref = $val['label'];
  148. $categstatic->color = $val['color'];
  149. $categstatic->type = $type;
  150. $desc = dol_htmlcleanlastbr($val['description']);
  151. $counter = '';
  152. if (!empty($conf->global->CATEGORY_SHOW_COUNTS)) {
  153. // we need only a count of the elements, so it is enough to consume only the id's from the database
  154. $elements = $type == Categorie::TYPE_ACCOUNT
  155. ? $categstatic->getObjectsInCateg("account", 1) // Categorie::TYPE_ACCOUNT is "bank_account" instead of "account"
  156. : $categstatic->getObjectsInCateg($type, 1);
  157. $counter = "<td class='left' width='40px;'>".(is_array($elements) ? count($elements) : '0')."</td>";
  158. }
  159. $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
  160. $li = $categstatic->getNomUrl(1, '', 60, '&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam));
  161. $entry = '<table class="nobordernopadding centpercent">';
  162. $entry .= '<tr>';
  163. $entry .= '<td>';
  164. $entry .= '<span class="noborderoncategories" '.$color.'>'.$li.'</span>';
  165. $entry .= '</td>';
  166. $entry .= $counter;
  167. $entry .= '<td class="right" width="20px;">';
  168. $entry .= '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$val['id'].'&type='.$type.$moreparam.'&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type).'">'.img_view().'</a>';
  169. $entry .= '</td>';
  170. $entry .= '<td class="right" width="20px;">';
  171. if ($user->hasRight('categorie', 'creer')) {
  172. $entry .= '<a class="editfielda" href="' . DOL_URL_ROOT . '/categories/edit.php?id=' . $val['id'] . '&type=' . $type . $moreparam . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?type=' . $type) . '">' . img_edit() . '</a>';
  173. }
  174. $entry .= '</td>';
  175. $entry .= '<td class="right" width="20px;">';
  176. if ($user->hasRight('categorie', 'supprimer')) {
  177. $entry .= '<a class="deletefilelink" href="' . DOL_URL_ROOT . '/categories/viewcat.php?action=delete&token=' . newToken() . '&id=' . $val['id'] . '&type=' . $type . $moreparam . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?type=' . $type . $moreparam) . '&backtolist=' . urlencode($_SERVER["PHP_SELF"] . '?type=' . $type . $moreparam) . '">' . img_delete() . '</a>';
  178. }
  179. $entry .= '</td>';
  180. $entry .= '</tr>';
  181. $entry .= '</table>';
  182. $data[] = array('rowid' => $val['rowid'], 'fk_menu' => $val['fk_parent'], 'entry' => $entry);
  183. }
  184. $nbofentries = (count($data) - 1);
  185. $morethan1level = 0;
  186. foreach ($data as $record) {
  187. if (!empty($record['fk_menu']) && $record['fk_menu'] > 0) {
  188. $morethan1level = 1;
  189. }
  190. }
  191. print '<table class="liste nohover centpercent">';
  192. print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td class="right">';
  193. if ($morethan1level && !empty($conf->use_javascript_ajax)) {
  194. print '<div id="iddivjstreecontrol">';
  195. print '<a class="notasortlink" href="#">'.img_picto('', 'folder', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("UndoExpandAll").'</span></a>';
  196. print ' | ';
  197. print '<a class="notasortlink" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("ExpandAll").'</span></a>';
  198. print '</div>';
  199. }
  200. print '</td></tr>';
  201. if ($nbofentries > 0) {
  202. print '<tr class="oddeven"><td colspan="3">';
  203. tree_recur($data, $data[0], 0);
  204. print '</td></tr>';
  205. } else {
  206. print '<tr class="oddeven">';
  207. print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
  208. print '<td class="valignmiddle">';
  209. print $langs->trans("NoCategoryYet");
  210. print '</td>';
  211. print '<td>&nbsp;</td>';
  212. print '</table></td>';
  213. print '</tr>';
  214. }
  215. print "</table>";
  216. print '</div>';
  217. // End of page
  218. llxFooter();
  219. $db->close();