index.php 9.2 KB

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