dolibarr  13.0.2
index.php
Go to the documentation of this file.
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 
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 
34 // Load translation files required by the page
35 $langs->load("categories");
36 
37 if (!$user->rights->categorie->lire) accessforbidden();
38 
39 $id = GETPOST('id', 'int');
40 $type = (GETPOST('type', 'aZ09') ? GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT);
41 $catname = GETPOST('catname', 'alpha');
42 $nosearch = GETPOST('nosearch', 'int');
43 
44 $categstatic = new Categorie($db);
45 if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
46 
47 
48 /*
49  * View
50  */
51 
52 $form = new Form($db);
53 
54 $moreparam = ($nosearch ? '&nosearch=1' : '');
55 
56 $typetext = $type;
57 if ($type == Categorie::TYPE_ACCOUNT) $title = $langs->trans('AccountsCategoriesArea');
58 elseif ($type == Categorie::TYPE_WAREHOUSE) $title = $langs->trans('StocksCategoriesArea');
59 elseif ($type == Categorie::TYPE_ACTIONCOMM) $title = $langs->trans('ActionCommCategoriesArea');
60 elseif ($type == Categorie::TYPE_WEBSITE_PAGE) $title = $langs->trans('WebsitePagesCategoriesArea');
61 else {
62  $title = $langs->trans(ucfirst($type).'sCategoriesArea');
63 }
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 
68 llxHeader('', $title, '', '', 0, 0, $arrayofjs, $arrayofcss);
69 
70 $newcardbutton = '';
71 if (!empty($user->rights->categorie->creer)) {
72  $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);
73 }
74 
75 print load_fiche_titre($title, $newcardbutton, 'object_category');
76 
77 // Search categories
78 if (empty($nosearch)) {
79  print '<div class="fichecenter"><div class="fichehalfleft">';
80 
81 
82  print '<form method="post" action="index.php?type='.$type.'">';
83  print '<input type="hidden" name="token" value="'.newToken().'">';
84  print '<input type="hidden" name="type" value="'.$type.'">';
85  print '<input type="hidden" name="nosearch" value="'.$nosearch.'">';
86 
87 
88  print '<table class="noborder nohover centpercent">';
89  print '<tr class="liste_titre">';
90  print '<td colspan="3">'.$langs->trans("Search").'</td>';
91  print '</tr>';
92  print '<tr class="oddeven nohover"><td>';
93  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>';
94  print '</table></form>';
95 
96 
97  print '</div><div class="fichehalfright">';
98 
99 
100  /*
101  * Categories found
102  */
103  if ($catname || $id > 0)
104  {
105  $cats = $categstatic->rechercher($id, $catname, $typetext);
106 
107  print '<table class="noborder centpercent">';
108  print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
109 
110  foreach ($cats as $cat)
111  {
112  $color = $categstatic->color ? ' style="background: #'.$categstatic->color.';"' : ' style="background: #bbb"';
113 
114  print "\t".'<tr class="oddeven">'."\n";
115  print "\t\t<td>";
116  $categstatic->id = $cat->id;
117  $categstatic->ref = $cat->label;
118  $categstatic->label = $cat->label;
119  $categstatic->type = $cat->type;
120  $categstatic->color = $cat->color;
121  print '<span class="noborderoncategories"'.$color.'>';
122  print $categstatic->getNomUrl(1, '');
123  print '</span>';
124  print "</td>\n";
125  print "\t\t<td>";
126  print dolGetFirstLineOfText($cat->description);
127  print "</td>\n";
128  print "\t</tr>\n";
129  }
130  print "</table>";
131  } else print '&nbsp;';
132 
133  print '</div></div>';
134 }
135 
136 print '<div class="fichecenter"><br>';
137 
138 
139 // Charge tableau des categories
140 $cate_arbo = $categstatic->get_full_arbo($typetext);
141 
142 // Define fulltree array
143 $fulltree = $cate_arbo;
144 
145 // Load possible missing includes
146 if ($conf->global->CATEGORY_SHOW_COUNTS)
147 {
148  if ($type == Categorie::TYPE_MEMBER) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
149  if ($type == Categorie::TYPE_ACCOUNT) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
150  if ($type == Categorie::TYPE_PROJECT) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
151  if ($type == Categorie::TYPE_USER) require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
152 }
153 
154 // Define data (format for treeview)
155 $data = array();
156 $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
157 foreach ($fulltree as $key => $val)
158 {
159  $categstatic->id = $val['id'];
160  $categstatic->ref = $val['label'];
161  $categstatic->color = $val['color'];
162  $categstatic->type = $type;
163  $li = $categstatic->getNomUrl(1, '', 60, $moreparam.'&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam));
164  $desc = dol_htmlcleanlastbr($val['description']);
165 
166  $counter = '';
167 
168  if ($conf->global->CATEGORY_SHOW_COUNTS)
169  {
170  // we need only a count of the elements, so it is enough to consume only the id's from the database
171  $elements = $categstatic->getObjectsInCateg($type, 1);
172  $counter = "<td class='left' width='40px;'>".(is_countable($elements) ? count($elements) : '0')."</td>";
173  }
174 
175  $color = $categstatic->color ? ' style="background: #'.sprintf("%06s", $categstatic->color).';"' : ' style="background: #bbb"';
176 
177  $data[] = array(
178  'rowid'=>$val['rowid'],
179  'fk_menu'=>$val['fk_parent'],
180  'entry'=>'<table class="nobordernopadding centpercent"><tr><td><span class="noborderoncategories"'.$color.'>'.$li.'</span></td>'.$counter.
181  '<td class="right" width="20px;"><a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$val['id'].'&type='.$type.$moreparam.'&backtolist='.urlencode($_SERVER["PHP_SELF"].'?type='.$type.$moreparam).'">'.img_view().'</a></td></tr></table>'
182  );
183 }
184 
185 
186 //print_barre_liste('', 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, 0, '', 0, $newcardbutton, '', 0, 1, 1);
187 
188 print '<table class="liste nohover" width="100%">';
189 print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td class="right">';
190 if (!empty($conf->use_javascript_ajax))
191 {
192  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>';
193 }
194 print '</td></tr>';
195 
196 $nbofentries = (count($data) - 1);
197 
198 if ($nbofentries > 0)
199 {
200  print '<tr class="pair"><td colspan="3">';
201  tree_recur($data, $data[0], 0);
202  print '</td></tr>';
203 } else {
204  print '<tr class="pair">';
205  print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
206  print '<td valign="middle">';
207  print $langs->trans("NoCategoryYet");
208  print '</td>';
209  print '<td>&nbsp;</td>';
210  print '</table></td>';
211  print '</tr>';
212 }
213 
214 print "</table>";
215 
216 print '</div>';
217 
218 // End of page
219 llxFooter();
220 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dolGetButtonTitle($label, $helpText= '', $iconClass= 'fa fa-file', $url= '', $id= '', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
Class to manage categories.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
dolGetFirstLineOfText($text, $nboflines=1, $charset= 'UTF-8')
Return first line of text.
print
Draft customers invoices.
Definition: index.php:89
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
img_view($titlealt= 'default', $float=0, $other= '')
Show logo view card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
tree_recur($tab, $pere, $rang, $iddivjstree= 'iddivjstree', $donoresetalreadyloaded=0, $showfk=0, $moreparam= '')
Recursive function to output a tree.