dolibarr  9.0.0
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 <http://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 
43 if (is_numeric($type)) $type=Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
44 
45 
46 /*
47  * View
48  */
49 
50 $categstatic = new Categorie($db);
51 $form = new Form($db);
52 
53 if ($type == Categorie::TYPE_PRODUCT) { $title=$langs->trans("ProductsCategoriesArea"); $typetext='product'; }
54 elseif ($type == Categorie::TYPE_SUPPLIER) { $title=$langs->trans("SuppliersCategoriesArea"); $typetext='supplier'; }
55 elseif ($type == Categorie::TYPE_CUSTOMER) { $title=$langs->trans("CustomersCategoriesArea"); $typetext='customer'; }
56 elseif ($type == Categorie::TYPE_MEMBER) { $title=$langs->trans("MembersCategoriesArea"); $typetext='member'; }
57 elseif ($type == Categorie::TYPE_CONTACT) { $title=$langs->trans("ContactsCategoriesArea"); $typetext='contact'; }
58 elseif ($type == Categorie::TYPE_ACCOUNT) { $title=$langs->trans("AccountsCategoriesArea"); $typetext='bank_account'; }
59 elseif ($type == Categorie::TYPE_PROJECT) { $title=$langs->trans("ProjectsCategoriesArea"); $typetext='project'; }
60 elseif ($type == Categorie::TYPE_USER) { $title=$langs->trans("UsersCategoriesArea"); $typetext='user'; }
61 else { $title=$langs->trans("CategoriesArea"); $typetext='unknown'; }
62 
63 $arrayofjs=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
64 $arrayofcss=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
65 
66 llxHeader('',$title,'','',0,0,$arrayofjs,$arrayofcss);
67 
68 $newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/categories/card.php?action=create&type='.$type.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?type='.$type).'"><span class="valignmiddle">'.$langs->trans("NewCategory").'</span>';
69 $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
70 $newcardbutton.= '</a>';
71 
72 print load_fiche_titre($title, $newcardbutton);
73 
74 //print '<table border="0" width="100%" class="notopnoleftnoright">';
75 //print '<tr><td valign="top" width="30%" class="notopnoleft">';
76 print '<div class="fichecenter"><div class="fichethirdleft">';
77 
78 
79 /*
80  * Zone recherche produit/service
81  */
82 print '<form method="post" action="index.php?type='.$type.'">';
83 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
84 print '<input type="hidden" name="type" value="'.$type.'">';
85 
86 
87 print '<table class="noborder nohover" width="100%">';
88 print '<tr class="liste_titre">';
89 print '<td colspan="3">'.$langs->trans("Search").'</td>';
90 print '</tr>';
91 print '<tr class="oddeven"><td>';
92 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>';
93 /*
94 // faire une rech dans une sous categorie uniquement
95 print '<tr '.$bc[0].'><td>';
96 print $langs->trans("SubCatOf").':</td><td>';
97 
98 print $form->select_all_categories('','subcatof');
99 print '</td>';
100 print '<td><input type="submit" class="button" value="'.$langs->trans ("Search").'"></td></tr>';
101 */
102 
103 print '</table></form>';
104 
105 
106 //print '</td><td valign="top" width="70%">';
107 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
108 
109 
110 /*
111  * Categories found
112  */
113 if ($catname || $id > 0)
114 {
115  $cats = $categstatic->rechercher($id, $catname, $typetext);
116 
117  print '<table class="noborder" width="100%">';
118  print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
119 
120  foreach ($cats as $cat)
121  {
122  print "\t".'<tr class="oddeven">'."\n";
123  print "\t\t<td>";
124  $categstatic->id=$cat->id;
125  $categstatic->ref=$cat->label;
126  $categstatic->label=$cat->label;
127  $categstatic->type=$cat->type;
128  $categstatic->color=$cat->color;
129  print '<span class="noborderoncategories" '.($categstatic->color?' style="background: #'.$categstatic->color.';"':' style="background: #aaa"').'>';
130  print $categstatic->getNomUrl(1,'');
131  print '</span>';
132  print "</td>\n";
133  print "\t\t<td>";
134  print dolGetFirstLineOfText($cat->description);
135  print "</td>\n";
136  print "\t</tr>\n";
137  }
138  print "</table>";
139 }
140 else print '&nbsp;';
141 
142 
143 //print '</td></tr></table>';
144 print '</div></div></div>';
145 
146 print '<div class="fichecenter"><br>';
147 
148 
149 // Charge tableau des categories
150 $cate_arbo = $categstatic->get_full_arbo($typetext);
151 
152 // Define fulltree array
153 $fulltree=$cate_arbo;
154 
155 // Define data (format for treeview)
156 $data=array();
157 $data[] = array('rowid'=>0,'fk_menu'=>-1,'title'=>"racine",'mainmenu'=>'','leftmenu'=>'','fk_mainmenu'=>'','fk_leftmenu'=>'');
158 foreach($fulltree as $key => $val)
159 {
160  $categstatic->id=$val['id'];
161  $categstatic->ref=$val['label'];
162  $categstatic->color=$val['color'];
163  $categstatic->type=$type;
164  $li=$categstatic->getNomUrl(1,'',60);
165  $desc=dol_htmlcleanlastbr($val['description']);
166 
167  $data[] = array(
168  'rowid'=>$val['rowid'],
169  'fk_menu'=>$val['fk_parent'],
170  'entry'=>'<table class="nobordernopadding centpercent"><tr><td><span class="noborderoncategories" '.($categstatic->color?' style="background: #'.$categstatic->color.';"':' style="background: #aaa"').'>'.$li.'</span></td>'.
171  //'<td width="50%">'.dolGetFirstLineOfText($desc).'</td>'.
172  '<td align="right" width="20px;"><a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$val['id'].'&type='.$type.'">'.img_view().'</a></td>'.
173  '</tr></table>'
174  );
175 }
176 
177 
178 //print_barre_liste('', 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, 0, '', 0, $newcardbutton, '', 0, 1, 1);
179 
180 print '<table class="liste nohover" width="100%">';
181 print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td align="right">';
182 if (! empty($conf->use_javascript_ajax))
183 {
184  print '<div id="iddivjstreecontrol"><a class="notasortlink" href="#">'.img_picto('','object_category').' '.$langs->trans("UndoExpandAll").'</a> | <a class="notasortlink" href="#">'.img_picto('','object_category-expanded').' '.$langs->trans("ExpandAll").'</a></div>';
185 }
186 print '</td></tr>';
187 
188 $nbofentries=(count($data) - 1);
189 
190 if ($nbofentries > 0)
191 {
192  print '<tr class="pair"><td colspan="3">';
193  tree_recur($data,$data[0],0);
194  print '</td></tr>';
195 }
196 else
197 {
198  print '<tr class="pair">';
199  print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('','treemenu/branchbottom.gif').'</td>';
200  print '<td valign="middle">';
201  print $langs->trans("NoCategoryYet");
202  print '</td>';
203  print '<td>&nbsp;</td>';
204  print '</table></td>';
205  print '</tr>';
206 }
207 
208 print "</table>";
209 
210 print '</div>';
211 
212 // End of page
213 llxFooter();
214 $db->close();
llxFooter()
Footer empty.
Definition: index.php:44
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
img_view($titlealt='default', $float=0, $other='')
Show logo view card.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0)
Recursive function to output a tree.
Class to manage generation of HTML components Only common components must be here.
llxHeader()
Header empty.
Definition: index.php:36
Class to manage categories.
dolGetFirstLineOfText($text, $nboflines=1)
Return first line of text.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)