modCategorie.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 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->special = 0;
  51. $this->picto = 'category';
  52. // Data directories to create when module is enabled
  53. $this->dirs = array();
  54. // Dependencies
  55. $this->depends = array();
  56. // Config pages
  57. $this->config_page_url = array('categorie.php@categories');
  58. $this->langfiles = array("products","companies","categories");
  59. // Constants
  60. $this->const = array();
  61. $r=0;
  62. $this->const[$r][0] = "CATEGORIE_RECURSIV_ADD";
  63. $this->const[$r][1] = "yesno";
  64. $this->const[$r][2] = "0";
  65. $this->const[$r][3] = 'Affect parent categories';
  66. $this->const[$r][4] = 0;
  67. $r++;
  68. // Boxes
  69. $this->boxes = array();
  70. // Permissions
  71. $this->rights = array();
  72. $this->rights_class = 'categorie';
  73. $r=0;
  74. $this->rights[$r][0] = 241; // id de la permission
  75. $this->rights[$r][1] = 'Lire les categories'; // libelle de la permission
  76. $this->rights[$r][2] = 'r'; // type de la permission (deprecated)
  77. $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
  78. $this->rights[$r][4] = 'lire';
  79. $r++;
  80. $this->rights[$r][0] = 242; // id de la permission
  81. $this->rights[$r][1] = 'Creer/modifier les categories'; // libelle de la permission
  82. $this->rights[$r][2] = 'w'; // type de la permission (deprecated)
  83. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  84. $this->rights[$r][4] = 'creer';
  85. $r++;
  86. $this->rights[$r][0] = 243; // id de la permission
  87. $this->rights[$r][1] = 'Supprimer les categories'; // libelle de la permission
  88. $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
  89. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  90. $this->rights[$r][4] = 'supprimer';
  91. $r++;
  92. // Exports
  93. //--------
  94. $r=0;
  95. $r++;
  96. $this->export_code[$r]='category_'.$r;
  97. $this->export_label[$r]='CatSupList';
  98. $this->export_icon[$r]='category';
  99. $this->export_enabled[$r]='$conf->fournisseur->enabled';
  100. $this->export_permission[$r]=array(array("categorie","lire"),array("fournisseur","lire"));
  101. $this->export_fields_array[$r]=array('u.rowid'=>"CategId",'u.label'=>"Label",'u.description'=>"Description",'s.rowid'=>'IdThirdParty','s.nom'=>'Name','s.prefix_comm'=>"Prefix",'s.client'=>"Customer",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",'s.code_client'=>"CustomerCode",'s.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",'c.label'=>"Country",'c.code'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"ProfId1",'s.siren'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note_public'=>"NotePublic");
  102. $this->export_TypeFields_array[$r]=array('u.label'=>"Text",'u.description'=>"Text",'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",'s.address'=>"Text",'s.zip'=>"Text",'s.town'=>"Text",'c.label'=>"List:c_country:label:label",'c.code'=>"Text",'s.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",'s.siret'=>"Text",'s.siren'=>"Text",'s.ape'=>"Text",'s.idprof4'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note_public'=>"Text");
  103. $this->export_entities_array[$r]=array('s.rowid'=>'company','s.nom'=>'company','s.prefix_comm'=>"company",'s.client'=>"company",'s.datec'=>"company",'s.tms'=>"company",'s.code_client'=>"company",'s.address'=>"company",'s.zip'=>"company",'s.town'=>"company",'c.label'=>"company",'c.code'=>"company",'s.phone'=>"company",'s.fax'=>"company",'s.url'=>"company",'s.email'=>"company",'s.siret'=>"company",'s.siren'=>"company",'s.ape'=>"company",'s.idprof4'=>"company",'s.tva_intra'=>"company",'s.capital'=>"company",'s.note_public'=>"company"); // We define here only fields that use another picto
  104. $this->export_sql_start[$r]='SELECT DISTINCT ';
  105. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'categorie as u, '.MAIN_DB_PREFIX.'categorie_fournisseur as cf, '.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';
  106. $this->export_sql_end[$r] .=' WHERE u.rowid = cf.fk_categorie AND cf.fk_soc = s.rowid';
  107. $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category',1).')';
  108. $this->export_sql_end[$r] .=' AND u.type = 1'; // Supplier categories
  109. $r++;
  110. $this->export_code[$r]='category_'.$r;
  111. $this->export_label[$r]='CatCusList';
  112. $this->export_icon[$r]='category';
  113. $this->export_enabled[$r]='$conf->societe->enabled';
  114. $this->export_permission[$r]=array(array("categorie","lire"),array("societe","lire"));
  115. $this->export_fields_array[$r]=array('u.rowid'=>"CategId",'u.label'=>"Label",'u.description'=>"Description",'s.rowid'=>'IdThirdParty','s.nom'=>'Name','s.prefix_comm'=>"Prefix",'s.client'=>"Customer",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",'s.code_client'=>"CustomerCode",'s.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",'c.label'=>"Country",'c.code'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"ProfId1",'s.siren'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note_public'=>"NotePublic",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus');
  116. $this->export_TypeFields_array[$r]=array('u.label'=>"Text",'u.description'=>"Text",'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",'s.address'=>"Text",'s.zip'=>"Text",'s.town'=>"Text",'c.label'=>"List:c_country:label:label",'c.code'=>"Text",'s.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",'s.siret'=>"Text",'s.siren'=>"Text",'s.ape'=>"Text",'s.idprof4'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note_public'=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code','s.fk_stcomm'=>'List:c_stcomm:libelle:code');
  117. $this->export_entities_array[$r]=array('s.rowid'=>'company','s.nom'=>'company','s.prefix_comm'=>"company",'s.client'=>"company",'s.datec'=>"company",'s.tms'=>"company",'s.code_client'=>"company",'s.address'=>"company",'s.zip'=>"company",'s.town'=>"company",'c.label'=>"company",'c.code'=>"company",'s.phone'=>"company",'s.fax'=>"company",'s.url'=>"company",'s.email'=>"company",'s.siret'=>"company",'s.siren'=>"company",'s.ape'=>"company",'s.idprof4'=>"company",'s.tva_intra'=>"company",'s.capital'=>"company",'s.note_public'=>"company",'s.fk_prospectlevel'=>'company','s.fk_stcomm'=>'company'); // We define here only fields that use another picto
  118. $this->export_sql_start[$r]='SELECT DISTINCT ';
  119. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'categorie as u, '.MAIN_DB_PREFIX.'categorie_societe as cf, '.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';
  120. $this->export_sql_end[$r] .=' WHERE u.rowid = cf.fk_categorie AND cf.fk_soc = s.rowid';
  121. $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category',1).')';
  122. $this->export_sql_end[$r] .=' AND u.type = 2'; // Customer/Prospect categories
  123. $r++;
  124. $this->export_code[$r]='category_'.$r;
  125. $this->export_label[$r]='CatProdList';
  126. $this->export_icon[$r]='category';
  127. $this->export_enabled[$r]='$conf->produit->enabled';
  128. $this->export_permission[$r]=array(array("categorie","lire"),array("produit","lire"));
  129. $this->export_fields_array[$r]=array('u.rowid'=>"CategId",'u.label'=>"Label",'u.description'=>"Description",'p.rowid'=>'ProductId','p.ref'=>'Ref');
  130. $this->export_TypeFields_array[$r]=array('u.label'=>"Text",'u.description'=>"Text",'p.ref'=>'Text');
  131. $this->export_entities_array[$r]=array('p.rowid'=>'product','p.ref'=>'product'); // We define here only fields that use another picto
  132. $this->export_sql_start[$r]='SELECT DISTINCT ';
  133. $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';
  134. $this->export_sql_end[$r] .=' WHERE u.rowid = cp.fk_categorie AND cp.fk_product = p.rowid';
  135. $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category',1).')';
  136. $this->export_sql_end[$r] .=' AND u.type = 0'; // Supplier categories
  137. $r++;
  138. $this->export_code[$r]='category_'.$r;
  139. $this->export_label[$r]='CatMemberList';
  140. $this->export_icon[$r]='category';
  141. $this->export_enabled[$r]='$conf->adherent->enabled';
  142. $this->export_permission[$r]=array(array("categorie","lire"),array("adherent","lire"));
  143. $this->export_fields_array[$r]=array('u.rowid'=>"CategId",'u.label'=>"Label",'u.description'=>"Description",'p.rowid'=>'MemberId','p.lastname'=>'LastName','p.firstname'=>'Firstname');
  144. $this->export_TypeFields_array[$r]=array('u.label'=>"Text",'u.description'=>"Text",'p.lastname'=>'Text','p.firstname'=>'Text');
  145. $this->export_entities_array[$r]=array('p.rowid'=>'member','p.lastname'=>'member','p.firstname'=>'member'); // We define here only fields that use another picto
  146. $this->export_sql_start[$r]='SELECT DISTINCT ';
  147. $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';
  148. $this->export_sql_end[$r] .=' WHERE u.rowid = cp.fk_categorie AND cp.fk_member = p.rowid';
  149. $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category',1).')';
  150. $this->export_sql_end[$r] .=' AND u.type = 3'; // Member categories
  151. $r++;
  152. $this->export_code[$r]='category_'.$r;
  153. $this->export_label[$r]='CatContactList';
  154. $this->export_icon[$r]='category';
  155. $this->export_enabled[$r]='$conf->societe->enabled';
  156. $this->export_permission[$r]=array(array("categorie", "lire"), array ("societe", "lire"));
  157. $this->export_fields_array[$r]=array (
  158. 'u.rowid' => "CategId",
  159. 'u.label' => "Label",
  160. 'u.description' => "Description",
  161. 'p.rowid' => 'ContactId',
  162. 'p.civility' => 'Civility',
  163. 'p.lastname' => 'LastName',
  164. 'p.firstname' => 'Firstname',
  165. 'p.address' => 'Address',
  166. 'p.zip' => 'Zip',
  167. 'p.town' => 'Town',
  168. 'country.code' => 'CountryCode',
  169. 'country.label' => 'Country',
  170. 'p.birthday' => 'DateToBirth',
  171. 'p.poste' => 'PostOrFunction',
  172. 'p.phone' => 'Phone',
  173. 'p.phone_perso' => 'PhonePerso',
  174. 'p.phone_mobile' => 'PhoneMobile',
  175. 'p.fax' => 'Fax',
  176. 'p.email' => 'Email',
  177. 'p.note_private' => 'NotePrivate',
  178. 'p.note_public' => 'NotePublic',
  179. 's.nom'=>"Name",
  180. 's.client'=>"Customer",
  181. 's.fournisseur'=>"Supplier",
  182. 's.status'=>"Status",
  183. 's.address'=>"Address",
  184. 's.zip'=>"Zip",
  185. 's.town'=>"Town",
  186. 's.phone'=>"Phone",
  187. 's.fax'=>"Fax",
  188. 's.url'=>"Url",
  189. 's.email'=>"Email"
  190. );
  191. $this->export_TypeFields_array[$r] = array (
  192. 'u.label' => "Text",
  193. 'u.description' => "Text",
  194. 'p.lastname' => 'Text',
  195. 'p.firstname' => 'Text',
  196. 's.nom'=>"Text",
  197. 's.status'=>"Text",
  198. 's.address'=>"Text",
  199. 's.zip'=>"Text",
  200. 's.town'=>"Text",
  201. 's.phone'=>"Text",
  202. 's.fax'=>"Text",
  203. 's.url'=>"Text",
  204. 's.email'=>"Text"
  205. );
  206. $this->export_entities_array[$r] = array (
  207. 'u.rowid' => "category",
  208. 'u.label' => "category",
  209. 'u.description' => "category",
  210. 'p.rowid' => 'contact',
  211. 'p.civility' => 'contact',
  212. 'p.lastname' => 'contact',
  213. 'p.firstname' => 'contact',
  214. 'p.address' => 'contact',
  215. 'p.zip' => 'contact',
  216. 'p.town' => 'contact',
  217. 'country.code' => 'contact',
  218. 'country.label' => 'contact',
  219. 'p.birthday' => 'contact',
  220. 'p.poste' => 'contact',
  221. 'p.phone' => 'contact',
  222. 'p.phone_perso' => 'contact',
  223. 'p.phone_mobile' => 'contact',
  224. 'p.fax' => 'contact',
  225. 'p.email' => 'contact',
  226. 'p.note_private' => 'contact',
  227. 'p.note_public' => 'contact',
  228. 's.nom'=>"company",
  229. 's.client'=>"company",
  230. 's.fournisseur'=>"company",
  231. 's.status'=>"company",
  232. 's.address'=>"company",
  233. 's.zip'=>"company",
  234. 's.town'=>"company",
  235. 's.phone'=>"company",
  236. 's.fax'=>"company",
  237. 's.url'=>"company",
  238. 's.email'=>"company"
  239. ); // We define here only fields that use another picto
  240. // Add extra fields
  241. $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'socpeople'";
  242. $resql=$this->db->query($sql);
  243. if ($resql) // This can fail when class is used on old database (during migration for example)
  244. {
  245. while ($obj=$this->db->fetch_object($resql))
  246. {
  247. $fieldname='extra.'.$obj->name;
  248. $fieldlabel=ucfirst($obj->label);
  249. $typeFilter="Text";
  250. switch($obj->type)
  251. {
  252. case 'int':
  253. case 'double':
  254. case 'price':
  255. $typeFilter="Numeric";
  256. break;
  257. case 'date':
  258. case 'datetime':
  259. $typeFilter="Date";
  260. break;
  261. case 'boolean':
  262. $typeFilter="Boolean";
  263. break;
  264. case 'sellist':
  265. $typeFilter="List:".$obj->param;
  266. break;
  267. case 'select':
  268. $typeFilter="Select:".$obj->param;
  269. break;
  270. }
  271. $this->export_fields_array[$r][$fieldname]=$fieldlabel;
  272. $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
  273. $this->export_entities_array[$r][$fieldname]='contact';
  274. }
  275. }
  276. // End add axtra fields
  277. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  278. $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';
  279. $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as country ON p.fk_pays = country.rowid';
  280. $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe as s ON s.rowid = p.fk_soc';
  281. $this->export_sql_end[$r] .= ' WHERE u.rowid = cp.fk_categorie AND cp.fk_socpeople = p.rowid AND u.entity IN ('.getEntity('category',1).')';
  282. $this->export_sql_end[$r] .= ' AND u.type = 4'; // contact categories
  283. // Imports
  284. //--------
  285. $r=0;
  286. $r++;
  287. $this->import_code[$r]=$this->rights_class.'_'.$r;
  288. $this->import_label[$r]="CatList"; // Translation key
  289. $this->import_icon[$r]=$this->picto;
  290. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  291. $this->import_tables_array[$r]=array('ca'=>MAIN_DB_PREFIX.'categorie');
  292. $this->import_fields_array[$r]=array('ca.label'=>"Label*",'ca.type'=>"Type*",'ca.description'=>"Description");
  293. $this->import_regex_array[$r]=array('ca.type'=>'^[0|1|2|3]');
  294. $typeexample="";
  295. if ($conf->product->enabled) { $typeexample.=($typeexample?"/":"")."0=Product"; }
  296. if ($conf->fournisseur->enabled) { $typeexample.=($typeexample?"/":"")."1=Supplier"; }
  297. if ($conf->societe->enabled) { $typeexample.=($typeexample?"/":"")."2=Customer-Prospect"; }
  298. if ($conf->adherent->enabled) { $typeexample.=($typeexample?"/":"")."3=Member"; }
  299. $this->import_examplevalues_array[$r]=array('ca.label'=>"Supplier Category",'ca.type'=>$typeexample,'ca.description'=>"Imported category");
  300. if (! empty($conf->product->enabled))
  301. {
  302. //Products
  303. $r++;
  304. $this->import_code[$r]=$this->rights_class.'_'.$r;
  305. $this->import_label[$r]="CatProdLinks"; // Translation key
  306. $this->import_icon[$r]=$this->picto;
  307. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  308. $this->import_tables_array[$r]=array('cp'=>MAIN_DB_PREFIX.'categorie_product');
  309. $this->import_fields_array[$r]=array('cp.fk_categorie'=>"Category*",'cp.fk_product'=>"Product*"
  310. );
  311. $this->import_convertvalue_array[$r]=array(
  312. 'cp.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'),
  313. 'cp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'product')
  314. );
  315. $this->import_examplevalues_array[$r]=array('cp.fk_categorie'=>"Imported category",'cp.fk_product'=>"PREF123456");
  316. }
  317. if (! empty($conf->societe->enabled))
  318. {
  319. //Customers
  320. $r++;
  321. $this->import_code[$r]=$this->rights_class.'_'.$r;
  322. $this->import_label[$r]="CatCusLinks"; // Translation key
  323. $this->import_icon[$r]=$this->picto;
  324. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  325. $this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_societe');
  326. $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"ThirdParty*"
  327. );
  328. $this->import_convertvalue_array[$r]=array(
  329. 'cs.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'),
  330. 'cs.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty')
  331. );
  332. $this->import_examplevalues_array[$r]=array('cs.fk_categorie'=>"Imported category",'cs.fk_soc'=>"MyBigCompany");
  333. }
  334. if (! empty($conf->fournisseur->enabled))
  335. {
  336. // Suppliers
  337. $r++;
  338. $this->import_code[$r]=$this->rights_class.'_'.$r;
  339. $this->import_label[$r]="CatSupLinks"; // Translation key
  340. $this->import_icon[$r]=$this->picto;
  341. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  342. $this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_fournisseur');
  343. $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_soc'=>"Supplier*"
  344. );
  345. $this->import_convertvalue_array[$r]=array(
  346. 'cs.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'),
  347. 'cs.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty')
  348. );
  349. $this->import_examplevalues_array[$r]=array('cs.fk_categorie'=>"Imported category",'cs.fk_soc'=>"MyBigCompany");
  350. }
  351. }
  352. /**
  353. * Function called when module is enabled.
  354. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  355. * It also creates data directories
  356. *
  357. * @param string $options Options when enabling module ('', 'noboxes')
  358. * @return int 1 if OK, 0 if KO
  359. */
  360. function init($options='')
  361. {
  362. // Permissions
  363. $this->remove($options);
  364. $sql = array();
  365. return $this->_init($sql,$options);
  366. }
  367. }