index.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  32. // Load translation files required by the page
  33. $langs->load("categories");
  34. $id = GETPOST('id', 'int');
  35. $type = (GETPOST('type', 'aZ09') ? GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT);
  36. $catname = GETPOST('catname', 'alpha');
  37. $nosearch = GETPOST('nosearch', 'int');
  38. $categstatic = new Categorie($db);
  39. if (is_numeric($type)) {
  40. $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
  41. }
  42. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
  43. $hookmanager->initHooks(array('categoryindex'));
  44. if (!$user->rights->categorie->lire) {
  45. accessforbidden();
  46. }
  47. /*
  48. * View
  49. */
  50. $form = new Form($db);
  51. $moreparam = ($nosearch ? '&nosearch=1' : '');
  52. $typetext = $type;
  53. if ($type == Categorie::TYPE_ACCOUNT) {
  54. $title = $langs->trans('AccountsCategoriesArea');
  55. } elseif ($type == Categorie::TYPE_WAREHOUSE) {
  56. $title = $langs->trans('StocksCategoriesArea');
  57. } elseif ($type == Categorie::TYPE_ACTIONCOMM) {
  58. $title = $langs->trans('ActionCommCategoriesArea');
  59. } elseif ($type == Categorie::TYPE_WEBSITE_PAGE) {
  60. $title = $langs->trans('WebsitePagesCategoriesArea');
  61. } else {
  62. $title = $langs->trans(ucfirst($type).'sCategoriesArea');
  63. }
  64. $arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
  65. $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
  66. llxHeader('', $title, '', '', 0, 0, $arrayofjs, $arrayofcss);
  67. $newcardbutton = '';
  68. if (!empty($user->rights->categorie->creer)) {
  69. $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);
  70. }
  71. print load_fiche_titre($title, $newcardbutton, 'object_category');
  72. // Search categories
  73. if (empty($nosearch)) {
  74. print '<div class="fichecenter"><div class="fichehalfleft">';
  75. print '<form method="post" action="index.php?type='.$type.'">';
  76. print '<input type="hidden" name="token" value="'.newToken().'">';
  77. print '<input type="hidden" name="type" value="'.$type.'">';
  78. print '<input type="hidden" name="nosearch" value="'.$nosearch.'">';
  79. print '<table class="noborder nohover centpercent">';
  80. print '<tr class="liste_titre">';
  81. print '<td colspan="3">'.$langs->trans("Search").'</td>';
  82. print '</tr>';
  83. print '<tr class="oddeven nohover"><td>';
  84. print $langs->trans("Name").':</td><td><input class="flat inputsearch" type="text" name="catname" value="'.dol_escape_htmltag($catname).'"></td>';
  85. print '<td><input type="submit" class="button small" value="'.$langs->trans("Search").'"></td></tr>';
  86. print '</table></form>';
  87. print '</div><div class="fichehalfright">';
  88. /*
  89. * Categories found
  90. */
  91. if ($catname || $id > 0) {
  92. $cats = $categstatic->rechercher($id, $catname, $typetext);
  93. print '<table class="noborder centpercent">';
  94. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
  95. foreach ($cats as $cat) {
  96. $categstatic->id = $cat->id;
  97. $categstatic->ref = $cat->label;
  98. $categstatic->label = $cat->label;
  99. $categstatic->type = $cat->type;
  100. $categstatic->color = $cat->color;
  101. $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
  102. print "\t".'<tr class="oddeven">'."\n";
  103. print "\t\t<td>";
  104. print '<span class="noborderoncategories"'.$color.'>';
  105. print $categstatic->getNomUrl(1, '');
  106. print '</span>';
  107. print "</td>\n";
  108. print "\t\t<td>";
  109. $text = dolGetFirstLineOfText(dol_string_nohtmltag($cat->description, 1));
  110. $trunclength = 48;
  111. print $form->textwithtooltip(dol_trunc($text, $trunclength), $cat->description);
  112. print "</td>\n";
  113. print "\t</tr>\n";
  114. }
  115. print "</table>";
  116. } else {
  117. print '&nbsp;';
  118. }
  119. print '</div></div>';
  120. }
  121. print '<div class="fichecenter"><br>';
  122. // Charge tableau des categories
  123. $cate_arbo = $categstatic->get_full_arbo($typetext);
  124. // Define fulltree array
  125. $fulltree = $cate_arbo;
  126. // Load possible missing includes
  127. if (!empty($conf->global->CATEGORY_SHOW_COUNTS)) {
  128. if ($type == Categorie::TYPE_MEMBER) {
  129. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  130. }
  131. if ($type == Categorie::TYPE_ACCOUNT) {
  132. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  133. }
  134. if ($type == Categorie::TYPE_PROJECT) {
  135. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  136. }
  137. if ($type == Categorie::TYPE_USER) {
  138. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  139. }
  140. }
  141. // Define data (format for treeview)
  142. $data = array();
  143. $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
  144. foreach ($fulltree as $key => $val) {
  145. $categstatic->id = $val['id'];
  146. $categstatic->ref = $val['label'];
  147. $categstatic->color = $val['color'];
  148. $categstatic->type = $type;
  149. $desc = dol_htmlcleanlastbr($val['description']);
  150. $counter = '';
  151. if (!empty($conf->global->CATEGORY_SHOW_COUNTS)) {
  152. // we need only a count of the elements, so it is enough to consume only the id's from the database
  153. $elements = $type == Categorie::TYPE_ACCOUNT
  154. ? $categstatic->getObjectsInCateg("account", 1) // Categorie::TYPE_ACCOUNT is "bank_account" instead of "account"
  155. : $categstatic->getObjectsInCateg($type, 1);
  156. $counter = "<td class='left' width='40px;'>".(is_array($elements) ? count($elements) : '0')."</td>";
  157. }
  158. $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
  159. $li = $categstatic->getNomUrl(1, '', 60, '&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam));
  160. $entry = '<table class="nobordernopadding centpercent">';
  161. $entry .= '<tr>';
  162. $entry .= '<td>';
  163. $entry .= '<span class="noborderoncategories" '.$color.'>'.$li.'</span>';
  164. $entry .= '</td>';
  165. $entry .= $counter;
  166. $entry .= '<td class="right" width="20px;">';
  167. $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>';
  168. $entry .= '</td>';
  169. $entry .= '<td class="right" width="20px;">';
  170. if ($user->rights->categorie->creer) {
  171. $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>';
  172. }
  173. $entry .= '</td>';
  174. $entry .= '<td class="right" width="20px;">';
  175. if ($user->rights->categorie->supprimer) {
  176. $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>';
  177. }
  178. $entry .= '</td>';
  179. $entry .= '</tr>';
  180. $entry .= '</table>';
  181. $data[] = array('rowid' => $val['rowid'], 'fk_menu' => $val['fk_parent'], 'entry' => $entry);
  182. }
  183. $nbofentries = (count($data) - 1);
  184. $morethan1level = 0;
  185. foreach ($data as $record) {
  186. if (!empty($record['fk_menu']) && $record['fk_menu'] > 0) {
  187. $morethan1level = 1;
  188. }
  189. }
  190. print '<table class="liste nohover centpercent">';
  191. print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td class="right">';
  192. if ($morethan1level && !empty($conf->use_javascript_ajax)) {
  193. print '<div id="iddivjstreecontrol">';
  194. print '<a class="notasortlink" href="#">'.img_picto('', 'folder', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("UndoExpandAll").'</span></a>';
  195. print ' | ';
  196. print '<a class="notasortlink" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("ExpandAll").'</span></a>';
  197. print '</div>';
  198. }
  199. print '</td></tr>';
  200. if ($nbofentries > 0) {
  201. print '<tr class="pair"><td colspan="3">';
  202. tree_recur($data, $data[0], 0);
  203. print '</td></tr>';
  204. } else {
  205. print '<tr class="pair">';
  206. print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
  207. print '<td valign="middle">';
  208. print $langs->trans("NoCategoryYet");
  209. print '</td>';
  210. print '<td>&nbsp;</td>';
  211. print '</table></td>';
  212. print '</tr>';
  213. }
  214. print "</table>";
  215. print '</div>';
  216. // End of page
  217. llxFooter();
  218. $db->close();