dolibarr  19.0.0-dev
modCategorie.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
3  * Copyright (C) 2005-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012-2016 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2020 Stéphane Lesage <stephane.lesage@ateis.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
28 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
30 
31 
36 {
42  public function __construct($db)
43  {
44  global $conf;
45 
46  $this->db = $db;
47  $this->numero = 1780;
48 
49  $this->family = "technic";
50  $this->module_position = '25';
51  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
52  $this->name = preg_replace('/^mod/i', '', get_class($this));
53  $this->description = "Gestion des categories (produits, clients, fournisseurs...)";
54 
55  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
56  $this->version = 'dolibarr';
57 
58  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
59  $this->picto = 'category';
60 
61  // Data directories to create when module is enabled
62  $this->dirs = array();
63 
64  // Dependencies
65  $this->depends = array();
66 
67  // Config pages
68  $this->config_page_url = array('categorie.php@categories');
69  $this->langfiles = array("products", "companies", "categories", "members", "stocks", "website");
70 
71  // Constants
72  $this->const = array();
73  $r = 0;
74  $this->const[$r][0] = "CATEGORIE_RECURSIV_ADD";
75  $this->const[$r][1] = "yesno";
76  $this->const[$r][2] = "0";
77  $this->const[$r][3] = 'Affect parent categories';
78  $this->const[$r][4] = 0;
79  $r++;
80 
81  // Boxes
82  $this->boxes = array();
83 
84  // Permissions
85  $this->rights = array();
86  $this->rights_class = 'categorie';
87 
88  $r = 0;
89 
90  $this->rights[$r][0] = 241; // id de la permission
91  $this->rights[$r][1] = 'Lire les categories'; // libelle de la permission
92  $this->rights[$r][2] = 'r'; // type de la permission (deprecated)
93  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
94  $this->rights[$r][4] = 'lire';
95  $r++;
96 
97  $this->rights[$r][0] = 242; // id de la permission
98  $this->rights[$r][1] = 'Creer/modifier les categories'; // libelle de la permission
99  $this->rights[$r][2] = 'w'; // type de la permission (deprecated)
100  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
101  $this->rights[$r][4] = 'creer';
102  $r++;
103 
104  $this->rights[$r][0] = 243; // id de la permission
105  $this->rights[$r][1] = 'Supprimer les categories'; // libelle de la permission
106  $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
107  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
108  $this->rights[$r][4] = 'supprimer';
109  $r++;
110 
111 
112  // Menus
113  //-------
114  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
115 
116 
117  // Exports
118  //--------
119  $r = 0;
120 
121  // All Categories List
122  $r++;
123  $this->export_code[$r] = $this->rights_class.'_list';
124  $this->export_label[$r] = 'CatListAll';
125  $this->export_icon[$r] = $this->picto;
126  $this->export_enabled[$r] = 'true';
127  $this->export_permission[$r] = array(array("categorie", "lire"));
128 
129  $typeexample = "";
130  if (isModEnabled("product") || isModEnabled("service")) {
131  $typeexample .= ($typeexample ? " / " : "")."0=Product-Service";
132  }
133  if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
134  $typeexample .= ($typeexample ? "/" : "")."1=Supplier";
135  }
136  if (isModEnabled("societe")) {
137  $typeexample .= ($typeexample ? " / " : "")."2=Customer-Prospect";
138  }
139  if (isModEnabled('adherent')) {
140  $typeexample .= ($typeexample ? " / " : "")."3=Member";
141  }
142  if (isModEnabled("societe")) {
143  $typeexample .= ($typeexample ? " / " : "")."4=Contact";
144  }
145  if (isModEnabled('bank')) {
146  $typeexample .= ($typeexample ? " / " : "")."5=Bank account";
147  }
148  if (isModEnabled('project')) {
149  $typeexample .= ($typeexample ? " / " : "")."6=Project";
150  }
151  if (isModEnabled('user')) {
152  $typeexample .= ($typeexample ? " / " : "")."7=User";
153  }
154  if (isModEnabled('bank')) {
155  $typeexample .= ($typeexample ? " / " : "")."8=Bank line";
156  }
157  if (isModEnabled('stock')) {
158  $typeexample .= ($typeexample ? " / " : "")."9=Warehouse";
159  }
160  if (isModEnabled('agenda')) {
161  $typeexample .= ($typeexample ? " / " : "")."10=Agenda event";
162  }
163  if (isModEnabled('website')) {
164  $typeexample .= ($typeexample ? " / " : "")."11=Website page";
165  }
166 
167  // Definition of vars
168  $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.type'=>"Type", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategoryID", 'pcat.label'=>"ParentCategoryLabel");
169  $this->export_TypeFields_array[$r] = array('cat.rowid'=>'Numeric', 'cat.label'=>"Text", 'cat.type'=>"Numeric", 'cat.description'=>"Text", 'cat.fk_parent'=>'Numeric', 'pcat.label'=>'Text');
170  $this->export_entities_array[$r] = array(); // We define here only fields that use another picto
171  $this->export_help_array[$r] = array('cat.type'=>$typeexample);
172 
173  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
174  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
175  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
176  $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
177 
178  // 0 Products
179  $r++;
180  $this->export_code[$r] = $this->rights_class.'_0_'.Categorie::$MAP_ID_TO_CODE[0];
181  $this->export_label[$r] = 'CatProdList';
182  $this->export_icon[$r] = $this->picto;
183  $this->export_enabled[$r] = 'isModEnabled("product") || isModEnabled("service")';
184  $this->export_permission[$r] = array(array("categorie", "lire"), array("produit", "export"));
185  $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategoryID", 'pcat.label'=>"ParentCategoryLabel", 'p.rowid'=>'ProductId', 'p.ref'=>'Ref', 'p.label'=>'Label');
186  $this->export_TypeFields_array[$r] = array('cat.rowid'=>'Numeric', 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'Numeric', 'pcat.label'=>'Text', 'p.rowid'=>'Numeric', 'p.ref'=>'Text', 'p.label'=>'Text');
187  $this->export_entities_array[$r] = array('p.rowid'=>'product', 'p.ref'=>'product', 'p.label'=>'product'); // We define here only fields that use another picto
188 
189  $keyforselect = 'product';
190  $keyforelement = 'product';
191  $keyforaliasextra = 'extra';
192  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
193 
194  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
195  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
196  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
197  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_categorie = cat.rowid';
198  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'product as p ON p.rowid = cp.fk_product';
199  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON extra.fk_object = p.rowid';
200  $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
201  $this->export_sql_end[$r] .= ' AND cat.type = 0';
202 
203  // 1 Suppliers
204  $r++;
205  $this->export_code[$r] = $this->rights_class.'_1_'.Categorie::$MAP_ID_TO_CODE[1];
206  $this->export_label[$r] = 'CatSupList';
207  $this->export_icon[$r] = $this->picto;
208  $this->export_enabled[$r] = 'isModEnabled("supplier_order") || isModEnabled("supplier_invoice")';
209  $this->export_permission[$r] = array(array("categorie", "lire"), array("fournisseur", "lire"));
210  $this->export_fields_array[$r] = array(
211  'cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategoryID", 'pcat.label'=>"ParentCategoryLabel",
212  's.rowid'=>'IdThirdParty', 's.nom'=>'Name', 's.prefix_comm'=>"Prefix", 's.fournisseur'=>"Supplier", 's.datec'=>"DateCreation", 's.tms'=>"DateLastModification", 's.code_fournisseur'=>"SupplierCode",
213  's.address'=>"Address", 's.zip'=>"Zip", 's.town'=>"Town", 'c.label'=>"Country", 'c.code'=>"CountryCode",
214  's.phone'=>"Phone", 's.fax'=>"Fax", 's.url'=>"Url", 's.email'=>"Email",
215  's.siret'=>"ProfId1", 's.siren'=>"ProfId2", 's.ape'=>"ProfId3", 's.idprof4'=>"ProfId4", 's.tva_intra'=>"VATIntraShort", 's.capital'=>"Capital", 's.note_public'=>"NotePublic",
216  't.libelle'=>'ThirdPartyType'
217  );
218  $this->export_TypeFields_array[$r] = array(
219  'cat.rowid'=>'Numeric', 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'Numeric', 'pcat.label'=>'Text',
220  's.rowid'=>'List:societe:nom', 's.nom'=>'Text', 's.prefix_comm'=>"Text", 's.fournisseur'=>"Text", 's.datec'=>"Date", 's.tms'=>"Date", 's.code_fournisseur'=>"Text",
221  's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text", 'c.label'=>"List:c_country:label:label", 'c.code'=>"Text",
222  's.phone'=>"Text", 's.fax'=>"Text", 's.url'=>"Text", 's.email'=>"Text",
223  's.siret'=>"Text", 's.siren'=>"Text", 's.ape'=>"Text", 's.idprof4'=>"Text", 's.tva_intra'=>"Text", 's.capital'=>"Numeric", 's.note_public'=>"Text",
224  't.libelle'=>'List:c_typent:libelle:code'
225  );
226  $this->export_entities_array[$r] = array(
227  's.rowid'=>'company', 's.nom'=>'company', 's.prefix_comm'=>"company", 's.fournisseur'=>"company", 's.datec'=>"company", 's.tms'=>"company", 's.code_fournisseur'=>"company",
228  's.address'=>"company", 's.zip'=>"company", 's.town'=>"company", 'c.label'=>"company", 'c.code'=>"company",
229  's.phone'=>"company", 's.fax'=>"company", 's.url'=>"company", 's.email'=>"company",
230  's.siret'=>"company", 's.siren'=>"company", 's.ape'=>"company", 's.idprof4'=>"company", 's.tva_intra'=>"company", 's.capital'=>"company", 's.note_public'=>"company",
231  't.libelle'=>'company'
232  ); // We define here only fields that use another picto
233 
234  $keyforselect = 'societe';
235  $keyforelement = 'company';
236  $keyforaliasextra = 'extra';
237  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
238 
239  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
240  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
241  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
242  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_fournisseur as cf ON cf.fk_categorie = cat.rowid';
243  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = cf.fk_soc';
244  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
245  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
246  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
247  $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
248  $this->export_sql_end[$r] .= ' AND cat.type = 1';
249 
250  // 2 Customers/Prospects
251  $r++;
252  $this->export_code[$r] = $this->rights_class.'_2_'.Categorie::$MAP_ID_TO_CODE[2];
253  $this->export_label[$r] = 'CatCusList';
254  $this->export_icon[$r] = $this->picto;
255  $this->export_enabled[$r] = 'isModEnabled("societe")';
256  $this->export_permission[$r] = array(array("categorie", "lire"), array("societe", "export"));
257  $this->export_fields_array[$r] = array(
258  'cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategoryID", 'pcat.label'=>"ParentCategoryLabel",
259  's.rowid'=>'IdThirdParty', 's.nom'=>'Name', 's.prefix_comm'=>"Prefix", 's.client'=>"Customer", 's.datec'=>"DateCreation", 's.tms'=>"DateLastModification", 's.code_client'=>"CustomerCode",
260  's.address'=>"Address", 's.zip'=>"Zip", 's.town'=>"Town", 'c.label'=>"Country", 'c.code'=>"CountryCode",
261  's.phone'=>"Phone", 's.fax'=>"Fax", 's.url'=>"Url", 's.email'=>"Email",
262  's.siret'=>"ProfId1", 's.siren'=>"ProfId2", 's.ape'=>"ProfId3", 's.idprof4'=>"ProfId4", 's.tva_intra'=>"VATIntraShort", 's.capital'=>"Capital", 's.note_public'=>"NotePublic",
263  't.libelle'=>'ThirdPartyType', 'pl.code'=>'ProspectLevel', 'st.code'=>'ProspectStatus'
264  );
265  $this->export_TypeFields_array[$r] = array(
266  'cat.rowid'=>'Numeric', 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'Numeric', 'pcat.label'=>'Text',
267  's.rowid'=>'List:societe:nom', 's.nom'=>'Text', 's.prefix_comm'=>"Text", 's.client'=>"Text", 's.datec'=>"Date", 's.tms'=>"Date", 's.code_client'=>"Text",
268  's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text", 'c.label'=>"List:c_country:label:label", 'c.code'=>"Text",
269  's.phone'=>"Text", 's.fax'=>"Text", 's.url'=>"Text", 's.email'=>"Text",
270  's.siret'=>"Text", 's.siren'=>"Text", 's.ape'=>"Text", 's.idprof4'=>"Text", 's.tva_intra'=>"Text", 's.capital'=>"Numeric", 's.note_public'=>"Text",
271  't.libelle'=>'List:c_typent:libelle:code', 'pl.code'=>'List:c_prospectlevel:label:code', 'st.code'=>'List:c_stcomm:libelle:code'
272  );
273  $this->export_entities_array[$r] = array(
274  's.rowid'=>'company', 's.nom'=>'company', 's.prefix_comm'=>"company", 's.client'=>"company", 's.datec'=>"company", 's.tms'=>"company", 's.code_client'=>"company",
275  's.address'=>"company", 's.zip'=>"company", 's.town'=>"company", 'c.label'=>"company", 'c.code'=>"company",
276  's.phone'=>"company", 's.fax'=>"company", 's.url'=>"company", 's.email'=>"company",
277  's.siret'=>"company", 's.siren'=>"company", 's.ape'=>"company", 's.idprof4'=>"company", 's.tva_intra'=>"company", 's.capital'=>"company", 's.note_public'=>"company",
278  't.libelle'=>'company', 'pl.code'=>'company', 'st.code'=>'company'
279  ); // We define here only fields that use another picto
280 
281  $keyforselect = 'societe';
282  $keyforelement = 'company';
283  $keyforaliasextra = 'extra';
284  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
285 
286  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
287  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
288  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
289  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_societe as cs ON cs.fk_categorie = cat.rowid';
290  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = cs.fk_soc';
291  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
292  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
293  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
294  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_prospectlevel as pl ON s.fk_prospectlevel = pl.code';
295  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
296  $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
297  $this->export_sql_end[$r] .= ' AND cat.type = 2';
298 
299  // 3 Members
300  $r++;
301  $this->export_code[$r] = $this->rights_class.'_3_'.Categorie::$MAP_ID_TO_CODE[3];
302  $this->export_label[$r] = 'CatMemberList';
303  $this->export_icon[$r] = $this->picto;
304  $this->export_enabled[$r] = 'isModEnabled("adherent")';
305  $this->export_permission[$r] = array(array("categorie", "lire"), array("adherent", "export"));
306  $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategoryID", 'pcat.label'=>"ParentCategoryLabel", 'p.rowid'=>'MemberId', 'p.lastname'=>'LastName', 'p.firstname'=>'Firstname');
307  $this->export_TypeFields_array[$r] = array('cat.rowid'=>"Numeric", 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'Numeric', 'pcat.label'=>'Text', 'p.lastname'=>'Text', 'p.firstname'=>'Text');
308  $this->export_entities_array[$r] = array('p.rowid'=>'member', 'p.lastname'=>'member', 'p.firstname'=>'member'); // We define here only fields that use another picto
309 
310  $keyforselect = 'adherent';
311  $keyforelement = 'member';
312  $keyforaliasextra = 'extra';
313  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
314 
315  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
316  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
317  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
318  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_member as cm ON cm.fk_categorie = cat.rowid';
319  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'adherent as p ON p.rowid = cm.fk_member';
320  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_extrafields as extra ON cat.rowid = extra.fk_object ';
321  $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
322  $this->export_sql_end[$r] .= ' AND cat.type = 3';
323 
324  // 4 Contacts
325  $r++;
326  $this->export_code[$r] = $this->rights_class.'_4_'.Categorie::$MAP_ID_TO_CODE[4];
327  $this->export_label[$r] = 'CatContactList';
328  $this->export_icon[$r] = $this->picto;
329  $this->export_enabled[$r] = 'isModEnabled("societe")';
330  $this->export_permission[$r] = array(array("categorie", "lire"), array("societe", "contact", "export"));
331  $this->export_fields_array[$r] = array(
332  'cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategoryID", 'pcat.label'=>"ParentCategoryLabel",
333  'p.rowid' => 'ContactId', 'civ.label' => 'UserTitle', 'p.lastname' => 'LastName', 'p.firstname' => 'Firstname',
334  'p.address' => 'Address', 'p.zip' => 'Zip', 'p.town' => 'Town', 'c.code' => 'CountryCode', 'c.label' => 'Country',
335  'p.birthday' => 'DateOfBirth', 'p.poste' => 'PostOrFunction',
336  'p.phone' => 'Phone', 'p.phone_perso' => 'PhonePerso', 'p.phone_mobile' => 'PhoneMobile', 'p.fax' => 'Fax', 'p.email' => 'Email',
337  'p.note_private' => 'NotePrivate', 'p.note_public' => 'NotePublic', 'p.statut' => 'Status',
338  's.nom'=>"Name", 's.client'=>"Customer", 's.fournisseur'=>"Supplier", 's.status'=>"Status",
339  's.address'=>"Address", 's.zip'=>"Zip", 's.town'=>"Town",
340  's.phone'=>"Phone", 's.fax'=>"Fax", 's.url'=>"Url", 's.email'=>"Email"
341  );
342  $this->export_TypeFields_array[$r] = array(
343  'cat.rowid'=>'Numeric', 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'Numeric', 'pcat.label'=>'Text',
344  'civ.label' => 'List:c_civility:label:label', 'p.rowid'=>'Numeric', 'p.lastname' => 'Text', 'p.firstname' => 'Text',
345  'p.address' => 'Text', 'p.zip' => 'Text', 'p.town' => 'Text', 'c.code' => 'Text', 'c.label' => 'List:c_country:label:label',
346  'p.birthday' => 'Date', 'p.poste' => 'Text',
347  'p.phone' => 'Text', 'p.phone_perso' => 'Text', 'p.phone_mobile' => 'Text', 'p.fax' => 'Text', 'p.email' => 'Text',
348  'p.note_private' => 'Text', 'p.note_public' => 'Text', 'p.statut' => 'Boolean',
349  's.nom'=>"Text", 's.client'=>"Boolean", 's.fournisseur'=>"Boolean", 's.status'=>"Boolean",
350  's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text",
351  's.phone'=>"Text", 's.fax'=>"Text", 's.url'=>"Text", 's.email'=>"Text"
352  );
353  $this->export_entities_array[$r] = array(
354  'p.rowid' => 'contact', 'civ.label' => 'contact', 'p.lastname' => 'contact', 'p.firstname' => 'contact',
355  'p.address' => 'contact', 'p.zip' => 'contact', 'p.town' => 'contact', 'c.code' => 'contact', 'c.label' => 'contact',
356  'p.birthday' => 'contact', 'p.poste' => 'contact',
357  'p.phone' => 'contact', 'p.phone_perso' => 'contact', 'p.phone_mobile' => 'contact', 'p.fax' => 'contact', 'p.email' => 'contact',
358  'p.note_private' => 'contact', 'p.note_public' => 'contact', 'p.statut' => 'contact',
359  's.nom'=>"company", 's.client'=>"company", 's.fournisseur'=>"company", 's.status'=>"company",
360  's.address'=>"company", 's.zip'=>"company", 's.town'=>"company",
361  's.phone'=>"company", 's.fax'=>"company", 's.url'=>"company", 's.email'=>"company"
362  ); // We define here only fields that use another picto
363 
364  $keyforselect = 'socpeople';
365  $keyforelement = 'contact';
366  $keyforaliasextra = 'extra';
367  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
368 
369  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
370  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
371  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
372  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_contact as cc ON cc.fk_categorie = cat.rowid';
373  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'socpeople as p ON p.rowid = cc.fk_socpeople';
374  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = p.rowid';
375  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_civility as civ ON civ.code = p.civility';
376  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON c.rowid = p.fk_pays';
377  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
378  $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
379  $this->export_sql_end[$r] .= ' AND cat.type = 4';
380 
381  // 5 Bank accounts, TODO ?
382 
383  // 6 Projects
384  $r++;
385  $this->export_code[$r] = $this->rights_class.'_6_'.Categorie::$MAP_ID_TO_CODE[6];
386  $this->export_label[$r] = 'CatProjectsList';
387  $this->export_icon[$r] = $this->picto;
388  $this->export_enabled[$r] = "isModEnabled('project')";
389  $this->export_permission[$r] = array(array("categorie", "lire"), array("projet", "export"));
390  $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory", 'pcat.label'=>"ParentCategoryLabel", 'p.rowid'=>'ProjectId', 'p.ref'=>'Ref', 's.rowid'=>"IdThirdParty", 's.nom'=>"Name");
391  $this->export_TypeFields_array[$r] = array('cat.rowid'=>'Numeric', 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'Numeric', 'pcat.label'=>'Text', 'p.rowid'=>'Numeric', 'p.ref'=>'Text', 's.rowid'=>"Numeric", 's.nom'=>"Text");
392  $this->export_entities_array[$r] = array('p.rowid'=>'project', 'p.ref'=>'project', 's.rowid'=>"company", 's.nom'=>"company"); // We define here only fields that use another picto
393 
394  $keyforselect = 'projet';
395  $keyforelement = 'project';
396  $keyforaliasextra = 'extra';
397  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
398 
399  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
400  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
401  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
402  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_project as cp ON cp.fk_categorie = cat.rowid';
403  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'projet as p ON p.rowid = cp.fk_project';
404  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet_extrafields as extra ON extra.fk_object = p.rowid';
405  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
406  $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
407  $this->export_sql_end[$r] .= ' AND cat.type = 6';
408 
409  // 7 Users
410  $r++;
411  $this->export_code[$r] = $this->rights_class.'_7_'.Categorie::$MAP_ID_TO_CODE[7];
412  $this->export_label[$r] = 'CatUsersList';
413  $this->export_icon[$r] = $this->picto;
414  $this->export_enabled[$r] = 'isModEnabled("user")';
415  $this->export_permission[$r] = array(array("categorie", "lire"), array("user", "export"));
416  $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory", 'pcat.label'=>"ParentCategoryLabel", 'p.rowid'=>'UserID', 'p.login'=>'Login', 'p.lastname'=>'Lastname', 'p.firstname'=>'Firstname');
417  $this->export_TypeFields_array[$r] = array('cat.rowid'=>"Numeric", 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'Numeric', 'pcat.label'=>'Text', 'p.rowid'=>'Numeric', 'p.login'=>'Text', 'p.lastname'=>'Text', 'p.firstname'=>'Text');
418  $this->export_entities_array[$r] = array('p.rowid'=>'user', 'p.login'=>'user', 'p.lastname'=>'user', 'p.firstname'=>'user'); // We define here only fields that use another picto
419 
420  $keyforselect = 'user';
421  $keyforelement = 'user';
422  $keyforaliasextra = 'extra';
423  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
424 
425  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
426  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
427  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
428  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_user as cu ON cu.fk_categorie = cat.rowid';
429  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'user as p ON p.rowid = cu.fk_user';
430  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user_extrafields as extra ON extra.fk_object = p.rowid';
431  $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
432  $this->export_sql_end[$r] .= ' AND cat.type = 7';
433 
434  // 8 Bank Lines, TODO ?
435 
436  // 9 Warehouses, TODO ?
437 
438  // 10 Agenda Events, TODO ?
439 
440  // 11 Website Pages, TODO ?
441 
442  // Imports
443  //--------
444 
445  $r = 0;
446 
447  // Categories
448  $r++;
449  $this->import_code[$r] = $this->rights_class.'_list';
450  $this->import_label[$r] = "CatList"; // Translation key
451  $this->import_icon[$r] = $this->picto;
452  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
453  $this->import_tables_array[$r] = array('ca'=>MAIN_DB_PREFIX.'categorie');
454  $this->import_fields_array[$r] = array(
455  'ca.label'=>"Label*", 'ca.type'=>"Type*", 'ca.description'=>"Description",
456  'ca.fk_parent' => 'ParentCategory'
457  );
458  $this->import_regex_array[$r] = array('ca.type'=>'^(0|1|2|3|4|5|6|7|8|9|10|11)$');
459  $this->import_convertvalue_array[$r] = array(
460  'ca.fk_parent' => array(
461  'rule' => 'fetchidfromcodeandlabel',
462  'classfile' => '/categories/class/categorie.class.php',
463  'class' => 'Categorie',
464  'method' => 'fetch',
465  'element' => 'category',
466  'codefromfield' => 'ca.type'
467  )
468  );
469 
470  $this->import_examplevalues_array[$r] = array(
471  'ca.label'=>"My Category Label", 'ca.type'=>$typeexample, 'ca.description'=>"My Category description", // $typeexample built above in exports
472  'ca.fk_parent' => 'rowid or label'
473  );
474  $this->import_updatekeys_array[$r] = array('ca.label'=>'Label');
475 
476  // 0 Products
477  if (isModEnabled("product")) {
478  $r++;
479  $this->import_code[$r] = $this->rights_class.'_0_'.Categorie::$MAP_ID_TO_CODE[0];
480  $this->import_label[$r] = "CatProdLinks"; // Translation key
481  $this->import_icon[$r] = $this->picto;
482  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
483  $this->import_tables_array[$r] = array('cp'=>MAIN_DB_PREFIX.'categorie_product');
484  $this->import_fields_array[$r] = array('cp.fk_categorie'=>"Category*", 'cp.fk_product'=>"Product*");
485  $this->import_regex_array[$r] = array('cp.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=0');
486 
487  $this->import_convertvalue_array[$r] = array(
488  'cp.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
489  'cp.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
490  );
491  $this->import_examplevalues_array[$r] = array('cp.fk_categorie'=>"rowid or label", 'cp.fk_product'=>"rowid or ref");
492  $this->import_updatekeys_array[$r] = array('cp.fk_categorie' => 'Category', 'cp.fk_product' => 'ProductRef');
493  }
494 
495  // 1 Suppliers
496  if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
497  $r++;
498  $this->import_code[$r] = $this->rights_class.'_1_'.Categorie::$MAP_ID_TO_CODE[1];
499  $this->import_label[$r] = "CatSupLinks"; // Translation key
500  $this->import_icon[$r] = $this->picto;
501  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
502  $this->import_tables_array[$r] = array('cs'=>MAIN_DB_PREFIX.'categorie_fournisseur');
503  $this->import_fields_array[$r] = array('cs.fk_categorie'=>"Category*", 'cs.fk_soc'=>"Supplier*");
504  $this->import_regex_array[$r] = array(
505  'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=1',
506  'cs.fk_soc'=>'rowid@'.MAIN_DB_PREFIX.'societe:fournisseur>0'
507  );
508 
509  $this->import_convertvalue_array[$r] = array(
510  'cs.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
511  'cs.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty')
512  );
513  $this->import_examplevalues_array[$r] = array('cs.fk_categorie'=>"rowid or label", 'cs.fk_soc'=>"rowid or name");
514  }
515 
516  // 2 Customers
517  if (isModEnabled("societe")) {
518  $r++;
519  $this->import_code[$r] = $this->rights_class.'_2_'.Categorie::$MAP_ID_TO_CODE[2];
520  $this->import_label[$r] = "CatCusLinks"; // Translation key
521  $this->import_icon[$r] = $this->picto;
522  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
523  $this->import_tables_array[$r] = array('cs'=>MAIN_DB_PREFIX.'categorie_societe');
524  $this->import_fields_array[$r] = array('cs.fk_categorie'=>"Category*", 'cs.fk_soc'=>"Customer*");
525  $this->import_regex_array[$r] = array(
526  'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=2',
527  'cs.fk_soc'=>'rowid@'.MAIN_DB_PREFIX.'societe:client>0'
528  );
529 
530  $this->import_convertvalue_array[$r] = array(
531  'cs.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
532  'cs.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty')
533  );
534  $this->import_examplevalues_array[$r] = array('cs.fk_categorie'=>"rowid or label", 'cs.fk_soc'=>"rowid or name");
535  }
536 
537  // 3 Members
538  if (isModEnabled('adherent')) {
539  $r++;
540  $this->import_code[$r] = $this->rights_class.'_3_'.Categorie::$MAP_ID_TO_CODE[3];
541  $this->import_label[$r] = "CatMembersLinks"; // Translation key
542  $this->import_icon[$r] = $this->picto;
543  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
544  $this->import_tables_array[$r] = array('cm'=>MAIN_DB_PREFIX.'categorie_contact');
545  $this->import_fields_array[$r] = array('cm.fk_categorie'=>"Category*", 'cm.fk_member'=>"Member*");
546  $this->import_regex_array[$r] = array('cm.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=3');
547 
548  $this->import_convertvalue_array[$r] = array(
549  'cs.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
550  'cs.fk_member'=>array('rule'=>'fetchidfromref', 'classfile'=>'/adherents/class/adherent.class.php', 'class'=>'Adherent', 'method'=>'fetch', 'element'=>'Member')
551  );
552  $this->import_examplevalues_array[$r] = array('cs.fk_categorie'=>"rowid or label", 'cs.fk_member'=>"rowid or ref");
553  }
554 
555  // 4 Contacts/Addresses
556  if (isModEnabled("societe")) {
557  $r++;
558  $this->import_code[$r] = $this->rights_class.'_4_'.Categorie::$MAP_ID_TO_CODE[4];
559  $this->import_label[$r] = "CatContactsLinks"; // Translation key
560  $this->import_icon[$r] = $this->picto;
561  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
562  $this->import_tables_array[$r] = array('cc'=>MAIN_DB_PREFIX.'categorie_contact');
563  $this->import_fields_array[$r] = array('cc.fk_categorie'=>"Category*", 'cc.fk_socpeople'=>"IdContact*");
564  $this->import_regex_array[$r] = array(
565  'cc.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=4'
566  //'cc.fk_socpeople'=>'rowid@'.MAIN_DB_PREFIX.'socpeople'
567  );
568 
569  $this->import_convertvalue_array[$r] = array(
570  'cc.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
571  //'cc.fk_socpeople'=>array('rule'=>'fetchidfromref','classfile'=>'/contact/class/contact.class.php','class'=>'Contact','method'=>'fetch','element'=>'Contact')
572  );
573  $this->import_examplevalues_array[$r] = array('cc.fk_categorie'=>"rowid or label", 'cc.fk_socpeople'=>"rowid");
574  }
575 
576  // 5 Bank accounts, TODO ?
577 
578  // 6 Projects
579  if (isModEnabled('project')) {
580  $r++;
581  $this->import_code[$r] = $this->rights_class.'_6_'.Categorie::$MAP_ID_TO_CODE[6];
582  $this->import_label[$r] = "CatProjectsLinks"; // Translation key
583  $this->import_icon[$r] = $this->picto;
584  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
585  $this->import_tables_array[$r] = array('cp'=>MAIN_DB_PREFIX.'categorie_project');
586  $this->import_fields_array[$r] = array('cp.fk_categorie'=>"Category*", 'cp.fk_project'=>"Project*");
587  $this->import_regex_array[$r] = array('cp.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=6');
588 
589  $this->import_convertvalue_array[$r] = array(
590  'cs.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
591  'cs.fk_project'=>array('rule'=>'fetchidfromref', 'classfile'=>'/projet/class/project.class.php', 'class'=>'Project', 'method'=>'fetch', 'element'=>'Project')
592  );
593  $this->import_examplevalues_array[$r] = array('cp.fk_categorie'=>"rowid or label", 'cp.fk_project'=>"rowid or ref");
594  }
595 
596  // 7 Users
597  if (isModEnabled('user')) {
598  $r++;
599  $this->import_code[$r] = $this->rights_class.'_7_'.Categorie::$MAP_ID_TO_CODE[7];
600  $this->import_label[$r] = "CatUsersLinks"; // Translation key
601  $this->import_icon[$r] = $this->picto;
602  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
603  $this->import_tables_array[$r] = array('cu'=>MAIN_DB_PREFIX.'categorie_user');
604  $this->import_fields_array[$r] = array('cu.fk_categorie'=>"Category*", 'cu.fk_user'=>"User*");
605  $this->import_regex_array[$r] = array('cu.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=7');
606 
607  $this->import_convertvalue_array[$r] = array(
608  'cu.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
609  'cu.fk_user'=>array('rule'=>'fetchidfromref', 'classfile'=>'/user/class/user.class.php', 'class'=>'User', 'method'=>'fetch', 'element'=>'User')
610  );
611  $this->import_examplevalues_array[$r] = array('cu.fk_categorie'=>"rowid or label", 'cu.fk_user'=>"rowid or login");
612  }
613 
614  // 8 Bank Lines, TODO ?
615 
616  // 9 Warehouses, TODO ?
617 
618  // 10 Agenda Events, TODO ?
619 
620  // 11 Website Pages, TODO ?
621  }
622 
623 
632  public function init($options = '')
633  {
634  // Permissions
635  $this->remove($options);
636 
637  $sql = array();
638 
639  return $this->_init($sql, $options);
640  }
641 }
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Class to describe and enable module Categorie.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
isModEnabled($module)
Is Dolibarr module enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123