dolibarr 19.0.3
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
28include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29include_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", 'cat.color'=>"Color", 'cat.date_creation'=>"DateCreation", 'cat.tms'=>"DateLastModification");
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", 'cat.color'=>"Color", 'cat.date_creation'=>"DateCreation", 'cat.tms'=>"DateLastModification", '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 'cat.color'=>"Color", 'cat.date_creation'=>"DateCreation", 'cat.tms'=>"DateLastModification",
213 's.rowid'=>'IdThirdParty', 's.nom'=>'Name', 's.prefix_comm'=>"Prefix", 's.fournisseur'=>"Supplier", 's.datec'=>"DateCreation", 's.tms'=>"DateLastModification", 's.code_fournisseur'=>"SupplierCode",
214 's.address'=>"Address", 's.zip'=>"Zip", 's.town'=>"Town", 'c.label'=>"Country", 'c.code'=>"CountryCode",
215 's.phone'=>"Phone", 's.fax'=>"Fax", 's.url'=>"Url", 's.email'=>"Email",
216 's.siret'=>"ProfId1", 's.siren'=>"ProfId2", 's.ape'=>"ProfId3", 's.idprof4'=>"ProfId4", 's.tva_intra'=>"VATIntraShort", 's.capital'=>"Capital", 's.note_public'=>"NotePublic",
217 't.libelle'=>'ThirdPartyType'
218 );
219 $this->export_TypeFields_array[$r] = array(
220 'cat.rowid'=>'Numeric', 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'Numeric', 'pcat.label'=>'Text',
221 '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",
222 's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text", 'c.label'=>"List:c_country:label:label", 'c.code'=>"Text",
223 's.phone'=>"Text", 's.fax'=>"Text", 's.url'=>"Text", 's.email'=>"Text",
224 's.siret'=>"Text", 's.siren'=>"Text", 's.ape'=>"Text", 's.idprof4'=>"Text", 's.tva_intra'=>"Text", 's.capital'=>"Numeric", 's.note_public'=>"Text",
225 't.libelle'=>'List:c_typent:libelle:code'
226 );
227 $this->export_entities_array[$r] = array(
228 's.rowid'=>'company', 's.nom'=>'company', 's.prefix_comm'=>"company", 's.fournisseur'=>"company", 's.datec'=>"company", 's.tms'=>"company", 's.code_fournisseur'=>"company",
229 's.address'=>"company", 's.zip'=>"company", 's.town'=>"company", 'c.label'=>"company", 'c.code'=>"company",
230 's.phone'=>"company", 's.fax'=>"company", 's.url'=>"company", 's.email'=>"company",
231 's.siret'=>"company", 's.siren'=>"company", 's.ape'=>"company", 's.idprof4'=>"company", 's.tva_intra'=>"company", 's.capital'=>"company", 's.note_public'=>"company",
232 't.libelle'=>'company'
233 ); // We define here only fields that use another picto
234
235 $keyforselect = 'societe';
236 $keyforelement = 'company';
237 $keyforaliasextra = 'extra';
238 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
239
240 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
241 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
242 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
243 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_fournisseur as cf ON cf.fk_categorie = cat.rowid';
244 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = cf.fk_soc';
245 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
246 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
247 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
248 $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
249 $this->export_sql_end[$r] .= ' AND cat.type = 1';
250
251 // 2 Customers/Prospects
252 $r++;
253 $this->export_code[$r] = $this->rights_class.'_2_'.Categorie::$MAP_ID_TO_CODE[2];
254 $this->export_label[$r] = 'CatCusList';
255 $this->export_icon[$r] = $this->picto;
256 $this->export_enabled[$r] = 'isModEnabled("societe")';
257 $this->export_permission[$r] = array(array("categorie", "lire"), array("societe", "export"));
258 $this->export_fields_array[$r] = array(
259 'cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategoryID", 'pcat.label'=>"ParentCategoryLabel",
260 'cat.color'=>"Color", 'cat.date_creation'=>"DateCreation", 'cat.tms'=>"DateLastModification",
261 's.rowid'=>'IdThirdParty', 's.nom'=>'Name', 's.prefix_comm'=>"Prefix", 's.client'=>"Customer", 's.datec'=>"DateCreation", 's.tms'=>"DateLastModification", 's.code_client'=>"CustomerCode",
262 's.address'=>"Address", 's.zip'=>"Zip", 's.town'=>"Town", 'c.label'=>"Country", 'c.code'=>"CountryCode",
263 's.phone'=>"Phone", 's.fax'=>"Fax", 's.url'=>"Url", 's.email'=>"Email",
264 's.siret'=>"ProfId1", 's.siren'=>"ProfId2", 's.ape'=>"ProfId3", 's.idprof4'=>"ProfId4", 's.tva_intra'=>"VATIntraShort", 's.capital'=>"Capital", 's.note_public'=>"NotePublic",
265 't.libelle'=>'ThirdPartyType', 'pl.code'=>'ProspectLevel', 'st.code'=>'ProspectStatus'
266 );
267 $this->export_TypeFields_array[$r] = array(
268 'cat.rowid'=>'Numeric', 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'Numeric', 'pcat.label'=>'Text',
269 '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",
270 's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text", 'c.label'=>"List:c_country:label:label", 'c.code'=>"Text",
271 's.phone'=>"Text", 's.fax'=>"Text", 's.url'=>"Text", 's.email'=>"Text",
272 's.siret'=>"Text", 's.siren'=>"Text", 's.ape'=>"Text", 's.idprof4'=>"Text", 's.tva_intra'=>"Text", 's.capital'=>"Numeric", 's.note_public'=>"Text",
273 't.libelle'=>'List:c_typent:libelle:code', 'pl.code'=>'List:c_prospectlevel:label:code', 'st.code'=>'List:c_stcomm:libelle:code'
274 );
275 $this->export_entities_array[$r] = array(
276 's.rowid'=>'company', 's.nom'=>'company', 's.prefix_comm'=>"company", 's.client'=>"company", 's.datec'=>"company", 's.tms'=>"company", 's.code_client'=>"company",
277 's.address'=>"company", 's.zip'=>"company", 's.town'=>"company", 'c.label'=>"company", 'c.code'=>"company",
278 's.phone'=>"company", 's.fax'=>"company", 's.url'=>"company", 's.email'=>"company",
279 's.siret'=>"company", 's.siren'=>"company", 's.ape'=>"company", 's.idprof4'=>"company", 's.tva_intra'=>"company", 's.capital'=>"company", 's.note_public'=>"company",
280 't.libelle'=>'company', 'pl.code'=>'company', 'st.code'=>'company'
281 ); // We define here only fields that use another picto
282
283 $keyforselect = 'societe';
284 $keyforelement = 'company';
285 $keyforaliasextra = 'extra';
286 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
287
288 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
289 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
290 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
291 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_societe as cs ON cs.fk_categorie = cat.rowid';
292 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = cs.fk_soc';
293 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
294 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
295 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
296 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_prospectlevel as pl ON s.fk_prospectlevel = pl.code';
297 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
298 $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
299 $this->export_sql_end[$r] .= ' AND cat.type = 2';
300
301 // 3 Members
302 $r++;
303 $this->export_code[$r] = $this->rights_class.'_3_'.Categorie::$MAP_ID_TO_CODE[3];
304 $this->export_label[$r] = 'CatMemberList';
305 $this->export_icon[$r] = $this->picto;
306 $this->export_enabled[$r] = 'isModEnabled("adherent")';
307 $this->export_permission[$r] = array(array("categorie", "lire"), array("adherent", "export"));
308 $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');
309 $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');
310 $this->export_entities_array[$r] = array('p.rowid'=>'member', 'p.lastname'=>'member', 'p.firstname'=>'member'); // We define here only fields that use another picto
311
312 $keyforselect = 'adherent';
313 $keyforelement = 'member';
314 $keyforaliasextra = 'extra';
315 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
316
317 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
318 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
319 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
320 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_member as cm ON cm.fk_categorie = cat.rowid';
321 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'adherent as p ON p.rowid = cm.fk_member';
322 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_extrafields as extra ON cat.rowid = extra.fk_object ';
323 $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
324 $this->export_sql_end[$r] .= ' AND cat.type = 3';
325
326 // 4 Contacts
327 $r++;
328 $this->export_code[$r] = $this->rights_class.'_4_'.Categorie::$MAP_ID_TO_CODE[4];
329 $this->export_label[$r] = 'CatContactList';
330 $this->export_icon[$r] = $this->picto;
331 $this->export_enabled[$r] = 'isModEnabled("societe")';
332 $this->export_permission[$r] = array(array("categorie", "lire"), array("societe", "contact", "export"));
333 $this->export_fields_array[$r] = array(
334 'cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategoryID", 'pcat.label'=>"ParentCategoryLabel",
335 'cat.color'=>"Color", 'cat.date_creation'=>"DateCreation", 'cat.tms'=>"DateLastModification",
336 'p.rowid' => 'ContactId', 'civ.label' => 'UserTitle', 'p.lastname' => 'LastName', 'p.firstname' => 'Firstname',
337 'p.address' => 'Address', 'p.zip' => 'Zip', 'p.town' => 'Town', 'c.code' => 'CountryCode', 'c.label' => 'Country',
338 'p.birthday' => 'DateOfBirth', 'p.poste' => 'PostOrFunction',
339 'p.phone' => 'Phone', 'p.phone_perso' => 'PhonePerso', 'p.phone_mobile' => 'PhoneMobile', 'p.fax' => 'Fax', 'p.email' => 'Email',
340 'p.note_private' => 'NotePrivate', 'p.note_public' => 'NotePublic', 'p.statut' => 'Status',
341 's.nom'=>"Name", 's.client'=>"Customer", 's.fournisseur'=>"Supplier", 's.status'=>"Status",
342 's.address'=>"Address", 's.zip'=>"Zip", 's.town'=>"Town",
343 's.phone'=>"Phone", 's.fax'=>"Fax", 's.url'=>"Url", 's.email'=>"Email"
344 );
345 $this->export_TypeFields_array[$r] = array(
346 'cat.rowid'=>'Numeric', 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'Numeric', 'pcat.label'=>'Text',
347 'civ.label' => 'List:c_civility:label:label', 'p.rowid'=>'Numeric', 'p.lastname' => 'Text', 'p.firstname' => 'Text',
348 'p.address' => 'Text', 'p.zip' => 'Text', 'p.town' => 'Text', 'c.code' => 'Text', 'c.label' => 'List:c_country:label:label',
349 'p.birthday' => 'Date', 'p.poste' => 'Text',
350 'p.phone' => 'Text', 'p.phone_perso' => 'Text', 'p.phone_mobile' => 'Text', 'p.fax' => 'Text', 'p.email' => 'Text',
351 'p.note_private' => 'Text', 'p.note_public' => 'Text', 'p.statut' => 'Boolean',
352 's.nom'=>"Text", 's.client'=>"Boolean", 's.fournisseur'=>"Boolean", 's.status'=>"Boolean",
353 's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text",
354 's.phone'=>"Text", 's.fax'=>"Text", 's.url'=>"Text", 's.email'=>"Text"
355 );
356 $this->export_entities_array[$r] = array(
357 'p.rowid' => 'contact', 'civ.label' => 'contact', 'p.lastname' => 'contact', 'p.firstname' => 'contact',
358 'p.address' => 'contact', 'p.zip' => 'contact', 'p.town' => 'contact', 'c.code' => 'contact', 'c.label' => 'contact',
359 'p.birthday' => 'contact', 'p.poste' => 'contact',
360 'p.phone' => 'contact', 'p.phone_perso' => 'contact', 'p.phone_mobile' => 'contact', 'p.fax' => 'contact', 'p.email' => 'contact',
361 'p.note_private' => 'contact', 'p.note_public' => 'contact', 'p.statut' => 'contact',
362 's.nom'=>"company", 's.client'=>"company", 's.fournisseur'=>"company", 's.status'=>"company",
363 's.address'=>"company", 's.zip'=>"company", 's.town'=>"company",
364 's.phone'=>"company", 's.fax'=>"company", 's.url'=>"company", 's.email'=>"company"
365 ); // We define here only fields that use another picto
366
367 $keyforselect = 'socpeople';
368 $keyforelement = 'contact';
369 $keyforaliasextra = 'extra';
370 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
371
372 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
373 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
374 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
375 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_contact as cc ON cc.fk_categorie = cat.rowid';
376 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'socpeople as p ON p.rowid = cc.fk_socpeople';
377 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = p.rowid';
378 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_civility as civ ON civ.code = p.civility';
379 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON c.rowid = p.fk_pays';
380 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
381 $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
382 $this->export_sql_end[$r] .= ' AND cat.type = 4';
383
384 // 5 Bank accounts, TODO ?
385
386 // 6 Projects
387 $r++;
388 $this->export_code[$r] = $this->rights_class.'_6_'.Categorie::$MAP_ID_TO_CODE[6];
389 $this->export_label[$r] = 'CatProjectsList';
390 $this->export_icon[$r] = $this->picto;
391 $this->export_enabled[$r] = "isModEnabled('project')";
392 $this->export_permission[$r] = array(array("categorie", "lire"), array("projet", "export"));
393 $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory", 'pcat.label'=>"ParentCategoryLabel", 'cat.color'=>"Color", 'cat.date_creation'=>"DateCreation", 'cat.tms'=>"DateLastModification", 'p.rowid'=>'ProjectId', 'p.ref'=>'Ref', 's.rowid'=>"IdThirdParty", 's.nom'=>"Name");
394 $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");
395 $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
396
397 $keyforselect = 'projet';
398 $keyforelement = 'project';
399 $keyforaliasextra = 'extra';
400 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
401
402 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
403 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
404 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
405 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_project as cp ON cp.fk_categorie = cat.rowid';
406 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'projet as p ON p.rowid = cp.fk_project';
407 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet_extrafields as extra ON extra.fk_object = p.rowid';
408 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
409 $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
410 $this->export_sql_end[$r] .= ' AND cat.type = 6';
411
412 // 7 Users
413 $r++;
414 $this->export_code[$r] = $this->rights_class.'_7_'.Categorie::$MAP_ID_TO_CODE[7];
415 $this->export_label[$r] = 'CatUsersList';
416 $this->export_icon[$r] = $this->picto;
417 $this->export_enabled[$r] = 'isModEnabled("user")';
418 $this->export_permission[$r] = array(array("categorie", "lire"), array("user", "export"));
419 $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory", 'pcat.label'=>"ParentCategoryLabel", 'cat.color'=>"Color", 'cat.date_creation'=>"DateCreation", 'cat.tms'=>"DateLastModification", 'p.rowid'=>'UserID', 'p.login'=>'Login', 'p.lastname'=>'Lastname', 'p.firstname'=>'Firstname');
420 $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');
421 $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
422
423 $keyforselect = 'user';
424 $keyforelement = 'user';
425 $keyforaliasextra = 'extra';
426 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
427
428 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
429 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
430 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
431 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_user as cu ON cu.fk_categorie = cat.rowid';
432 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'user as p ON p.rowid = cu.fk_user';
433 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user_extrafields as extra ON extra.fk_object = p.rowid';
434 $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
435 $this->export_sql_end[$r] .= ' AND cat.type = 7';
436
437 // 8 Bank Lines, TODO ?
438
439 // 9 Warehouses, TODO ?
440
441 // 10 Agenda Events, TODO ?
442
443 // 11 Website Pages, TODO ?
444
445 // Imports
446 //--------
447
448 $r = 0;
449
450 // Categories
451 $r++;
452 $this->import_code[$r] = $this->rights_class.'_list';
453 $this->import_label[$r] = "CatList"; // Translation key
454 $this->import_icon[$r] = $this->picto;
455 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
456 $this->import_tables_array[$r] = array('ca'=>MAIN_DB_PREFIX.'categorie');
457 $this->import_fields_array[$r] = array(
458 'ca.label'=>"Label*", 'ca.type'=>"Type*", 'ca.description'=>"Description",
459 'ca.fk_parent' => 'ParentCategory'
460 );
461 $this->import_regex_array[$r] = array('ca.type'=>'^(0|1|2|3|4|5|6|7|8|9|10|11)$');
462 $this->import_convertvalue_array[$r] = array(
463 'ca.fk_parent' => array(
464 'rule' => 'fetchidfromcodeandlabel',
465 'classfile' => '/categories/class/categorie.class.php',
466 'class' => 'Categorie',
467 'method' => 'fetch',
468 'element' => 'category',
469 'codefromfield' => 'ca.type'
470 )
471 );
472
473 $this->import_examplevalues_array[$r] = array(
474 'ca.label'=>"My Category Label", 'ca.type'=>$typeexample, 'ca.description'=>"My Category description", // $typeexample built above in exports
475 'ca.fk_parent' => 'rowid or label'
476 );
477 $this->import_updatekeys_array[$r] = array('ca.label'=>'Label', 'ca.type' => 'Type');
478
479 // 0 Products
480 if (isModEnabled("product")) {
481 $r++;
482 $this->import_code[$r] = $this->rights_class.'_0_'.Categorie::$MAP_ID_TO_CODE[0];
483 $this->import_label[$r] = "CatProdLinks"; // Translation key
484 $this->import_icon[$r] = $this->picto;
485 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
486 $this->import_tables_array[$r] = array('cp'=>MAIN_DB_PREFIX.'categorie_product');
487 $this->import_fields_array[$r] = array('cp.fk_categorie'=>"Category*", 'cp.fk_product'=>"Product*");
488 $this->import_regex_array[$r] = array('cp.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=0');
489
490 $this->import_convertvalue_array[$r] = array(
491 'cp.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
492 'cp.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
493 );
494 $this->import_examplevalues_array[$r] = array('cp.fk_categorie'=>"rowid or label", 'cp.fk_product'=>"rowid or ref");
495 $this->import_updatekeys_array[$r] = array('cp.fk_categorie' => 'Category', 'cp.fk_product' => 'ProductRef');
496 }
497
498 // 1 Suppliers
499 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
500 $r++;
501 $this->import_code[$r] = $this->rights_class.'_1_'.Categorie::$MAP_ID_TO_CODE[1];
502 $this->import_label[$r] = "CatSupLinks"; // Translation key
503 $this->import_icon[$r] = $this->picto;
504 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
505 $this->import_tables_array[$r] = array('cs'=>MAIN_DB_PREFIX.'categorie_fournisseur');
506 $this->import_fields_array[$r] = array('cs.fk_categorie'=>"Category*", 'cs.fk_soc'=>"Supplier*");
507 $this->import_regex_array[$r] = array(
508 'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=1',
509 'cs.fk_soc'=>'rowid@'.MAIN_DB_PREFIX.'societe:fournisseur>0'
510 );
511
512 $this->import_convertvalue_array[$r] = array(
513 'cs.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
514 'cs.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty')
515 );
516 $this->import_examplevalues_array[$r] = array('cs.fk_categorie'=>"rowid or label", 'cs.fk_soc'=>"rowid or name");
517 }
518
519 // 2 Customers
520 if (isModEnabled("societe")) {
521 $r++;
522 $this->import_code[$r] = $this->rights_class.'_2_'.Categorie::$MAP_ID_TO_CODE[2];
523 $this->import_label[$r] = "CatCusLinks"; // Translation key
524 $this->import_icon[$r] = $this->picto;
525 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
526 $this->import_tables_array[$r] = array('cs'=>MAIN_DB_PREFIX.'categorie_societe');
527 $this->import_fields_array[$r] = array('cs.fk_categorie'=>"Category*", 'cs.fk_soc'=>"Customer*");
528 $this->import_regex_array[$r] = array(
529 'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=2',
530 'cs.fk_soc'=>'rowid@'.MAIN_DB_PREFIX.'societe:client>0'
531 );
532
533 $this->import_convertvalue_array[$r] = array(
534 'cs.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
535 'cs.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty')
536 );
537 $this->import_examplevalues_array[$r] = array('cs.fk_categorie'=>"rowid or label", 'cs.fk_soc'=>"rowid or name");
538 }
539
540 // 3 Members
541 if (isModEnabled('adherent')) {
542 $r++;
543 $this->import_code[$r] = $this->rights_class.'_3_'.Categorie::$MAP_ID_TO_CODE[3];
544 $this->import_label[$r] = "CatMembersLinks"; // Translation key
545 $this->import_icon[$r] = $this->picto;
546 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
547 $this->import_tables_array[$r] = array('cm'=>MAIN_DB_PREFIX.'categorie_contact');
548 $this->import_fields_array[$r] = array('cm.fk_categorie'=>"Category*", 'cm.fk_member'=>"Member*");
549 $this->import_regex_array[$r] = array('cm.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=3');
550
551 $this->import_convertvalue_array[$r] = array(
552 'cs.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
553 'cs.fk_member'=>array('rule'=>'fetchidfromref', 'classfile'=>'/adherents/class/adherent.class.php', 'class'=>'Adherent', 'method'=>'fetch', 'element'=>'Member')
554 );
555 $this->import_examplevalues_array[$r] = array('cs.fk_categorie'=>"rowid or label", 'cs.fk_member'=>"rowid or ref");
556 }
557
558 // 4 Contacts/Addresses
559 if (isModEnabled("societe")) {
560 $r++;
561 $this->import_code[$r] = $this->rights_class.'_4_'.Categorie::$MAP_ID_TO_CODE[4];
562 $this->import_label[$r] = "CatContactsLinks"; // Translation key
563 $this->import_icon[$r] = $this->picto;
564 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
565 $this->import_tables_array[$r] = array('cc'=>MAIN_DB_PREFIX.'categorie_contact');
566 $this->import_fields_array[$r] = array('cc.fk_categorie'=>"Category*", 'cc.fk_socpeople'=>"IdContact*");
567 $this->import_regex_array[$r] = array(
568 'cc.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=4'
569 //'cc.fk_socpeople'=>'rowid@'.MAIN_DB_PREFIX.'socpeople'
570 );
571
572 $this->import_convertvalue_array[$r] = array(
573 'cc.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
574 //'cc.fk_socpeople'=>array('rule'=>'fetchidfromref','classfile'=>'/contact/class/contact.class.php','class'=>'Contact','method'=>'fetch','element'=>'Contact')
575 );
576 $this->import_examplevalues_array[$r] = array('cc.fk_categorie'=>"rowid or label", 'cc.fk_socpeople'=>"rowid");
577 }
578
579 // 5 Bank accounts, TODO ?
580
581 // 6 Projects
582 if (isModEnabled('project')) {
583 $r++;
584 $this->import_code[$r] = $this->rights_class.'_6_'.Categorie::$MAP_ID_TO_CODE[6];
585 $this->import_label[$r] = "CatProjectsLinks"; // Translation key
586 $this->import_icon[$r] = $this->picto;
587 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
588 $this->import_tables_array[$r] = array('cp'=>MAIN_DB_PREFIX.'categorie_project');
589 $this->import_fields_array[$r] = array('cp.fk_categorie'=>"Category*", 'cp.fk_project'=>"Project*");
590 $this->import_regex_array[$r] = array('cp.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=6');
591
592 $this->import_convertvalue_array[$r] = array(
593 'cs.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
594 'cs.fk_project'=>array('rule'=>'fetchidfromref', 'classfile'=>'/projet/class/project.class.php', 'class'=>'Project', 'method'=>'fetch', 'element'=>'Project')
595 );
596 $this->import_examplevalues_array[$r] = array('cp.fk_categorie'=>"rowid or label", 'cp.fk_project'=>"rowid or ref");
597 }
598
599 // 7 Users
600 if (isModEnabled('user')) {
601 $r++;
602 $this->import_code[$r] = $this->rights_class.'_7_'.Categorie::$MAP_ID_TO_CODE[7];
603 $this->import_label[$r] = "CatUsersLinks"; // Translation key
604 $this->import_icon[$r] = $this->picto;
605 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
606 $this->import_tables_array[$r] = array('cu'=>MAIN_DB_PREFIX.'categorie_user');
607 $this->import_fields_array[$r] = array('cu.fk_categorie'=>"Category*", 'cu.fk_user'=>"User*");
608 $this->import_regex_array[$r] = array('cu.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=7');
609
610 $this->import_convertvalue_array[$r] = array(
611 'cu.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
612 'cu.fk_user'=>array('rule'=>'fetchidfromref', 'classfile'=>'/user/class/user.class.php', 'class'=>'User', 'method'=>'fetch', 'element'=>'User')
613 );
614 $this->import_examplevalues_array[$r] = array('cu.fk_categorie'=>"rowid or label", 'cu.fk_user'=>"rowid or login");
615 }
616
617 // 8 Bank Lines, TODO ?
618
619 // 9 Warehouses, TODO ?
620
621 // 10 Agenda Events, TODO ?
622
623 // 11 Website Pages, TODO ?
624 }
625
626
635 public function init($options = '')
636 {
637 // Permissions
638 $this->remove($options);
639
640 $sql = array();
641
642 return $this->_init($sql, $options);
643 }
644}
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.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124