modCategorie.class.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \defgroup category Module categories
  21. * \brief Module to manage categories
  22. * \file htdocs/core/modules/modCategorie.class.php
  23. * \ingroup category
  24. * \brief Fichier de description et activation du module Categorie
  25. */
  26. include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
  27. /**
  28. * Class to describe and enable module Categorie
  29. */
  30. class modCategorie extends DolibarrModules
  31. {
  32. /**
  33. * Constructor. Define names, constants, directories, boxes, permissions
  34. *
  35. * @param DoliDB $db Database handler
  36. */
  37. function __construct($db)
  38. {
  39. global $conf;
  40. $this->db = $db;
  41. $this->numero = 1780;
  42. $this->family = "technic";
  43. $this->module_position = '20';
  44. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  45. $this->name = preg_replace('/^mod/i','',get_class($this));
  46. $this->description = "Gestion des categories (produits, clients, fournisseurs...)";
  47. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  48. $this->version = 'dolibarr';
  49. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  50. $this->picto = 'category';
  51. // Data directories to create when module is enabled
  52. $this->dirs = array();
  53. // Dependencies
  54. $this->depends = array();
  55. // Config pages
  56. $this->config_page_url = array('categorie.php@categories');
  57. $this->langfiles = array("products","companies","categories","members");
  58. // Constants
  59. $this->const = array();
  60. $r=0;
  61. $this->const[$r][0] = "CATEGORIE_RECURSIV_ADD";
  62. $this->const[$r][1] = "yesno";
  63. $this->const[$r][2] = "0";
  64. $this->const[$r][3] = 'Affect parent categories';
  65. $this->const[$r][4] = 0;
  66. $r++;
  67. // Boxes
  68. $this->boxes = array();
  69. // Permissions
  70. $this->rights = array();
  71. $this->rights_class = 'categorie';
  72. $r=0;
  73. $this->rights[$r][0] = 241; // id de la permission
  74. $this->rights[$r][1] = 'Lire les categories'; // libelle de la permission
  75. $this->rights[$r][2] = 'r'; // type de la permission (deprecated)
  76. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  77. $this->rights[$r][4] = 'lire';
  78. $r++;
  79. $this->rights[$r][0] = 242; // id de la permission
  80. $this->rights[$r][1] = 'Creer/modifier les categories'; // libelle de la permission
  81. $this->rights[$r][2] = 'w'; // type de la permission (deprecated)
  82. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  83. $this->rights[$r][4] = 'creer';
  84. $r++;
  85. $this->rights[$r][0] = 243; // id de la permission
  86. $this->rights[$r][1] = 'Supprimer les categories'; // libelle de la permission
  87. $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
  88. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  89. $this->rights[$r][4] = 'supprimer';
  90. $r++;
  91. // Menus
  92. //-------
  93. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  94. // Exports
  95. //--------
  96. $r=0;
  97. $r++;
  98. $this->export_code[$r]='category_'.$r;
  99. $this->export_label[$r]='CatSupList';
  100. $this->export_icon[$r]='category';
  101. $this->export_enabled[$r]='$conf->fournisseur->enabled';
  102. $this->export_permission[$r]=array(array("categorie","lire"),array("fournisseur","lire"));
  103. $this->export_fields_array[$r]=array(
  104. 'u.rowid'=>"CategId",'u.label'=>"Label",'u.description'=>"Description",'s.rowid'=>'IdThirdParty','s.nom'=>'Name','s.prefix_comm'=>"Prefix",
  105. 's.client'=>"Customer",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",'s.code_client'=>"CustomerCode",'s.address'=>"Address",
  106. 's.zip'=>"Zip",'s.town'=>"Town",'c.label'=>"Country",'c.code'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",
  107. 's.siret'=>"ProfId1",'s.siren'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",
  108. 's.note_public'=>"NotePublic"
  109. );
  110. $this->export_TypeFields_array[$r]=array(
  111. 'u.label'=>"Text",'u.description'=>"Text",'s.rowid'=>'List:societe:nom','s.nom'=>'Text','s.prefix_comm'=>"Text",'s.client'=>"Text",'s.datec'=>"Date",
  112. 's.tms'=>"Date",'s.code_client'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",'s.town'=>"Text",'c.label'=>"List:c_country:label:label",'c.code'=>"Text",
  113. 's.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",'s.siret'=>"Text",'s.siren'=>"Text",'s.ape'=>"Text",'s.idprof4'=>"Text",
  114. 's.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note_public'=>"Text"
  115. );
  116. $this->export_entities_array[$r]=array(
  117. 's.rowid'=>'company','s.nom'=>'company','s.prefix_comm'=>"company",'s.client'=>"company",'s.datec'=>"company",'s.tms'=>"company",
  118. 's.code_client'=>"company",'s.address'=>"company",'s.zip'=>"company",'s.town'=>"company",'c.label'=>"company",'c.code'=>"company",
  119. 's.phone'=>"company",'s.fax'=>"company",'s.url'=>"company",'s.email'=>"company",'s.siret'=>"company",'s.siren'=>"company",'s.ape'=>"company",
  120. 's.idprof4'=>"company",'s.tva_intra'=>"company",'s.capital'=>"company",'s.note_public'=>"company"
  121. ); // We define here only fields that use another picto
  122. $this->export_sql_start[$r]='SELECT DISTINCT ';
  123. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'categorie as u, ';
  124. $this->export_sql_end[$r] .= MAIN_DB_PREFIX.'categorie_fournisseur as cf, ';
  125. $this->export_sql_end[$r] .= MAIN_DB_PREFIX.'societe as s LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
  126. $this->export_sql_end[$r] .=' WHERE u.rowid = cf.fk_categorie AND cf.fk_soc = s.rowid';
  127. $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category').')';
  128. $this->export_sql_end[$r] .=' AND u.type = 1'; // Supplier categories
  129. $r++;
  130. $this->export_code[$r]='category_'.$r;
  131. $this->export_label[$r]='CatCusList';
  132. $this->export_icon[$r]='category';
  133. $this->export_enabled[$r]='$conf->societe->enabled';
  134. $this->export_permission[$r]=array(array("categorie","lire"),array("societe","lire"));
  135. $this->export_fields_array[$r]=array(
  136. 'u.rowid'=>"CategId",'u.label'=>"Label",'u.description'=>"Description",'s.rowid'=>'IdThirdParty','s.nom'=>'Name','s.prefix_comm'=>"Prefix",
  137. 's.client'=>"Customer",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",'s.code_client'=>"CustomerCode",'s.address'=>"Address",
  138. 's.zip'=>"Zip",'s.town'=>"Town",'c.label'=>"Country",'c.code'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",
  139. 's.siret'=>"ProfId1",'s.siren'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",
  140. 's.note_public'=>"NotePublic",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus'
  141. );
  142. $this->export_TypeFields_array[$r]=array(
  143. 'u.label'=>"Text",'u.description'=>"Text",'s.rowid'=>'List:societe:nom','s.nom'=>'Text','s.prefix_comm'=>"Text",'s.client'=>"Text",
  144. 's.datec'=>"Date",'s.tms'=>"Date",'s.code_client'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",'s.town'=>"Text",'c.label'=>"List:c_country:label:label",
  145. 'c.code'=>"Text",'s.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",'s.siret'=>"Text",'s.siren'=>"Text",'s.ape'=>"Text",
  146. 's.idprof4'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note_public'=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code',
  147. 's.fk_stcomm'=>'List:c_stcomm:libelle:code'
  148. );
  149. $this->export_entities_array[$r]=array(
  150. 's.rowid'=>'company','s.nom'=>'company','s.prefix_comm'=>"company",'s.client'=>"company",'s.datec'=>"company",'s.tms'=>"company",
  151. 's.code_client'=>"company",'s.address'=>"company",'s.zip'=>"company",'s.town'=>"company",'c.label'=>"company",'c.code'=>"company",
  152. 's.phone'=>"company",'s.fax'=>"company",'s.url'=>"company",'s.email'=>"company",'s.siret'=>"company",'s.siren'=>"company",'s.ape'=>"company",
  153. 's.idprof4'=>"company",'s.tva_intra'=>"company",'s.capital'=>"company",'s.note_public'=>"company",'s.fk_prospectlevel'=>'company',
  154. 's.fk_stcomm'=>'company'
  155. ); // We define here only fields that use another picto
  156. $this->export_sql_start[$r]='SELECT DISTINCT ';
  157. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'categorie as u, ';
  158. $this->export_sql_end[$r] .= MAIN_DB_PREFIX.'categorie_societe as cf, ';
  159. $this->export_sql_end[$r] .= MAIN_DB_PREFIX.'societe as s LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object ';
  160. $this->export_sql_end[$r] .=' WHERE u.rowid = cf.fk_categorie AND cf.fk_soc = s.rowid';
  161. $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category').')';
  162. $this->export_sql_end[$r] .=' AND u.type = 2'; // Customer/Prospect categories
  163. // Add extra fields
  164. $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'societe'";
  165. $resql=$this->db->query($sql);
  166. if ($resql) // This can fail when class is used on old database (during migration for example)
  167. {
  168. while ($obj=$this->db->fetch_object($resql))
  169. {
  170. $fieldname='extra.'.$obj->name;
  171. $fieldlabel=ucfirst($obj->label);
  172. $typeFilter="Text";
  173. switch($obj->type)
  174. {
  175. case 'int':
  176. case 'double':
  177. case 'price':
  178. $typeFilter="Numeric";
  179. break;
  180. case 'date':
  181. case 'datetime':
  182. $typeFilter="Date";
  183. break;
  184. case 'boolean':
  185. $typeFilter="Boolean";
  186. break;
  187. case 'sellist':
  188. $typeFilter="List:".$obj->param;
  189. break;
  190. case 'select':
  191. $typeFilter="Select:".$obj->param;
  192. break;
  193. }
  194. $this->export_fields_array[$r][$fieldname]=$fieldlabel;
  195. $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
  196. $this->export_entities_array[$r][$fieldname]='company';
  197. }
  198. }
  199. // End add axtra fields
  200. $r++;
  201. $this->export_code[$r]='category_'.$r;
  202. $this->export_label[$r]='CatProdList';
  203. $this->export_icon[$r]='category';
  204. $this->export_enabled[$r]='$conf->produit->enabled';
  205. $this->export_permission[$r]=array(array("categorie","lire"),array("produit","lire"));
  206. $this->export_fields_array[$r]=array('u.rowid'=>"CategId",'u.label'=>"Label",'u.description'=>"Description",'p.rowid'=>'ProductId','p.ref'=>'Ref');
  207. $this->export_TypeFields_array[$r]=array('u.label'=>"Text",'u.description'=>"Text",'p.ref'=>'Text');
  208. $this->export_entities_array[$r]=array('p.rowid'=>'product','p.ref'=>'product'); // We define here only fields that use another picto
  209. $this->export_sql_start[$r]='SELECT DISTINCT ';
  210. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'categorie as u, '.MAIN_DB_PREFIX.'categorie_product as cp, '.MAIN_DB_PREFIX.'product as p';
  211. $this->export_sql_end[$r] .=' WHERE u.rowid = cp.fk_categorie AND cp.fk_product = p.rowid';
  212. $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category').')';
  213. $this->export_sql_end[$r] .=' AND u.type = 0'; // Supplier categories
  214. $r++;
  215. $this->export_code[$r]='category_'.$r;
  216. $this->export_label[$r]='CatMemberList';
  217. $this->export_icon[$r]='category';
  218. $this->export_enabled[$r]='$conf->adherent->enabled';
  219. $this->export_permission[$r]=array(array("categorie","lire"),array("adherent","lire"));
  220. $this->export_fields_array[$r]=array('u.rowid'=>"CategId",'u.label'=>"Label",'u.description'=>"Description",'p.rowid'=>'MemberId','p.lastname'=>'LastName','p.firstname'=>'Firstname');
  221. $this->export_TypeFields_array[$r]=array('u.label'=>"Text",'u.description'=>"Text",'p.lastname'=>'Text','p.firstname'=>'Text');
  222. $this->export_entities_array[$r]=array('p.rowid'=>'member','p.lastname'=>'member','p.firstname'=>'member'); // We define here only fields that use another picto
  223. $this->export_sql_start[$r]='SELECT DISTINCT ';
  224. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'categorie as u, '.MAIN_DB_PREFIX.'categorie_member as cp, '.MAIN_DB_PREFIX.'adherent as p';
  225. $this->export_sql_end[$r] .=' WHERE u.rowid = cp.fk_categorie AND cp.fk_member = p.rowid';
  226. $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category').')';
  227. $this->export_sql_end[$r] .=' AND u.type = 3'; // Member categories
  228. $r++;
  229. $this->export_code[$r]='category_'.$r;
  230. $this->export_label[$r]='CatContactList';
  231. $this->export_icon[$r]='category';
  232. $this->export_enabled[$r]='$conf->societe->enabled';
  233. $this->export_permission[$r]=array(array("categorie", "lire"), array ("societe", "lire"));
  234. $this->export_fields_array[$r]=array (
  235. 'u.rowid' => "CategId",
  236. 'u.label' => "Label",
  237. 'u.description' => "Description",
  238. 'p.rowid' => 'ContactId',
  239. 'p.civility' => 'UserTitle',
  240. 'p.lastname' => 'LastName',
  241. 'p.firstname' => 'Firstname',
  242. 'p.address' => 'Address',
  243. 'p.zip' => 'Zip',
  244. 'p.town' => 'Town',
  245. 'country.code' => 'CountryCode',
  246. 'country.label' => 'Country',
  247. 'p.birthday' => 'DateToBirth',
  248. 'p.poste' => 'PostOrFunction',
  249. 'p.phone' => 'Phone',
  250. 'p.phone_perso' => 'PhonePerso',
  251. 'p.phone_mobile' => 'PhoneMobile',
  252. 'p.fax' => 'Fax',
  253. 'p.email' => 'Email',
  254. 'p.note_private' => 'NotePrivate',
  255. 'p.note_public' => 'NotePublic',
  256. 's.nom'=>"Name",
  257. 's.client'=>"Customer",
  258. 's.fournisseur'=>"Supplier",
  259. 's.status'=>"Status",
  260. 's.address'=>"Address",
  261. 's.zip'=>"Zip",
  262. 's.town'=>"Town",
  263. 's.phone'=>"Phone",
  264. 's.fax'=>"Fax",
  265. 's.url'=>"Url",
  266. 's.email'=>"Email"
  267. );
  268. $this->export_TypeFields_array[$r] = array (
  269. 'u.label' => "Text",
  270. 'u.description' => "Text",
  271. 'p.lastname' => 'Text',
  272. 'p.firstname' => 'Text',
  273. 's.nom'=>"Text",
  274. 's.status'=>"Text",
  275. 's.address'=>"Text",
  276. 's.zip'=>"Text",
  277. 's.town'=>"Text",
  278. 's.phone'=>"Text",
  279. 's.fax'=>"Text",
  280. 's.url'=>"Text",
  281. 's.email'=>"Text"
  282. );
  283. $this->export_entities_array[$r] = array (
  284. 'u.rowid' => "category",
  285. 'u.label' => "category",
  286. 'u.description' => "category",
  287. 'p.rowid' => 'contact',
  288. 'p.civility' => 'contact',
  289. 'p.lastname' => 'contact',
  290. 'p.firstname' => 'contact',
  291. 'p.address' => 'contact',
  292. 'p.zip' => 'contact',
  293. 'p.town' => 'contact',
  294. 'country.code' => 'contact',
  295. 'country.label' => 'contact',
  296. 'p.birthday' => 'contact',
  297. 'p.poste' => 'contact',
  298. 'p.phone' => 'contact',
  299. 'p.phone_perso' => 'contact',
  300. 'p.phone_mobile' => 'contact',
  301. 'p.fax' => 'contact',
  302. 'p.email' => 'contact',
  303. 'p.note_private' => 'contact',
  304. 'p.note_public' => 'contact',
  305. 's.nom'=>"company",
  306. 's.client'=>"company",
  307. 's.fournisseur'=>"company",
  308. 's.status'=>"company",
  309. 's.address'=>"company",
  310. 's.zip'=>"company",
  311. 's.town'=>"company",
  312. 's.phone'=>"company",
  313. 's.fax'=>"company",
  314. 's.url'=>"company",
  315. 's.email'=>"company"
  316. ); // We define here only fields that use another picto
  317. // Add extra fields
  318. $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'socpeople'";
  319. $resql=$this->db->query($sql);
  320. if ($resql) // This can fail when class is used on old database (during migration for example)
  321. {
  322. while ($obj=$this->db->fetch_object($resql))
  323. {
  324. $fieldname='extra.'.$obj->name;
  325. $fieldlabel=ucfirst($obj->label);
  326. $typeFilter="Text";
  327. switch($obj->type)
  328. {
  329. case 'int':
  330. case 'double':
  331. case 'price':
  332. $typeFilter="Numeric";
  333. break;
  334. case 'date':
  335. case 'datetime':
  336. $typeFilter="Date";
  337. break;
  338. case 'boolean':
  339. $typeFilter="Boolean";
  340. break;
  341. case 'sellist':
  342. $typeFilter="List:".$obj->param;
  343. break;
  344. case 'select':
  345. $typeFilter="Select:".$obj->param;
  346. break;
  347. }
  348. $this->export_fields_array[$r][$fieldname]=$fieldlabel;
  349. $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
  350. $this->export_entities_array[$r][$fieldname]='contact';
  351. }
  352. }
  353. // End add axtra fields
  354. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  355. $this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'categorie as u, '.MAIN_DB_PREFIX . 'categorie_contact as cp, '.MAIN_DB_PREFIX . 'socpeople as p';
  356. $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as country ON p.fk_pays = country.rowid';
  357. $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe as s ON s.rowid = p.fk_soc';
  358. $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'socpeople_extrafields as extra ON extra.fk_object = p.rowid';
  359. $this->export_sql_end[$r] .= ' WHERE u.rowid = cp.fk_categorie AND cp.fk_socpeople = p.rowid AND u.entity IN ('.getEntity('category').')';
  360. $this->export_sql_end[$r] .= ' AND u.type = 4'; // contact categories
  361. // Imports
  362. //--------
  363. $r=0;
  364. $r++;
  365. $this->import_code[$r]=$this->rights_class.'_'.$r;
  366. $this->import_label[$r]="CatList"; // Translation key
  367. $this->import_icon[$r]=$this->picto;
  368. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  369. $this->import_tables_array[$r]=array('ca'=>MAIN_DB_PREFIX.'categorie');
  370. $this->import_fields_array[$r]=array('ca.label'=>"Label*",'ca.type'=>"Type*",'ca.description'=>"Description");
  371. $this->import_regex_array[$r]=array('ca.type'=>'^[0|1|2|3]');
  372. $typeexample="";
  373. if ($conf->product->enabled) { $typeexample.=($typeexample?"/":"")."0=Product"; }
  374. if ($conf->fournisseur->enabled) { $typeexample.=($typeexample?"/":"")."1=Supplier"; }
  375. if ($conf->societe->enabled) { $typeexample.=($typeexample?"/":"")."2=Customer-Prospect"; }
  376. if ($conf->adherent->enabled) { $typeexample.=($typeexample?"/":"")."3=Member"; }
  377. $this->import_examplevalues_array[$r]=array('ca.label'=>"Supplier Category",'ca.type'=>$typeexample,'ca.description'=>"Imported category");
  378. if (! empty($conf->product->enabled))
  379. {
  380. //Products
  381. $r++;
  382. $this->import_code[$r]=$this->rights_class.'_'.$r;
  383. $this->import_label[$r]="CatProdLinks"; // Translation key
  384. $this->import_icon[$r]=$this->picto;
  385. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  386. $this->import_tables_array[$r]=array('cp'=>MAIN_DB_PREFIX.'categorie_product');
  387. $this->import_fields_array[$r]=array('cp.fk_categorie'=>"Category*",'cp.fk_product'=>"Product*"
  388. );
  389. $this->import_convertvalue_array[$r]=array(
  390. 'cp.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'),
  391. 'cp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'product')
  392. );
  393. $this->import_examplevalues_array[$r]=array('cp.fk_categorie'=>"Imported category",'cp.fk_product'=>"PREF123456");
  394. }
  395. if (! empty($conf->societe->enabled))
  396. {
  397. //Customers
  398. $r++;
  399. $this->import_code[$r]=$this->rights_class.'_'.$r;
  400. $this->import_label[$r]="CatCusLinks"; // Translation key
  401. $this->import_icon[$r]=$this->picto;
  402. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  403. $this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_societe');
  404. $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"ThirdParty*"
  405. );
  406. $this->import_convertvalue_array[$r]=array(
  407. 'cs.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'),
  408. 'cs.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty')
  409. );
  410. $this->import_examplevalues_array[$r]=array('cs.fk_categorie'=>"Imported category",'cs.fk_soc'=>"MyBigCompany");
  411. }
  412. if (! empty($conf->fournisseur->enabled))
  413. {
  414. // Suppliers
  415. $r++;
  416. $this->import_code[$r]=$this->rights_class.'_'.$r;
  417. $this->import_label[$r]="CatSupLinks"; // Translation key
  418. $this->import_icon[$r]=$this->picto;
  419. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  420. $this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_fournisseur');
  421. $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"Supplier*"
  422. );
  423. $this->import_convertvalue_array[$r]=array(
  424. 'cs.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'),
  425. 'cs.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty')
  426. );
  427. $this->import_examplevalues_array[$r]=array('cs.fk_categorie'=>"Imported category",'cs.fk_soc'=>"MyBigCompany");
  428. }
  429. }
  430. /**
  431. * Function called when module is enabled.
  432. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  433. * It also creates data directories
  434. *
  435. * @param string $options Options when enabling module ('', 'noboxes')
  436. * @return int 1 if OK, 0 if KO
  437. */
  438. function init($options='')
  439. {
  440. // Permissions
  441. $this->remove($options);
  442. $sql = array();
  443. return $this->_init($sql,$options);
  444. }
  445. }