modCategorie.class.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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. /**
  21. * \defgroup category Module categories
  22. * \brief Module to manage categories
  23. * \file htdocs/core/modules/modCategorie.class.php
  24. * \ingroup category
  25. * \brief Description and activation file for the module Category
  26. */
  27. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  28. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  29. /**
  30. * Class to describe and enable module Categorie
  31. */
  32. class modCategorie extends DolibarrModules
  33. {
  34. /**
  35. * Constructor. Define names, constants, directories, boxes, permissions
  36. *
  37. * @param DoliDB $db Database handler
  38. */
  39. public function __construct($db)
  40. {
  41. global $conf;
  42. $this->db = $db;
  43. $this->numero = 1780;
  44. $this->family = "technic";
  45. $this->module_position = '20';
  46. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  47. $this->name = preg_replace('/^mod/i', '', get_class($this));
  48. $this->description = "Gestion des categories (produits, clients, fournisseurs...)";
  49. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  50. $this->version = 'dolibarr';
  51. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  52. $this->picto = 'category';
  53. // Data directories to create when module is enabled
  54. $this->dirs = array();
  55. // Dependencies
  56. $this->depends = array();
  57. // Config pages
  58. $this->config_page_url = array('categorie.php@categories');
  59. $this->langfiles = array("products", "companies", "categories", "members", "stocks", "website");
  60. // Constants
  61. $this->const = array();
  62. $r = 0;
  63. $this->const[$r][0] = "CATEGORIE_RECURSIV_ADD";
  64. $this->const[$r][1] = "yesno";
  65. $this->const[$r][2] = "0";
  66. $this->const[$r][3] = 'Affect parent categories';
  67. $this->const[$r][4] = 0;
  68. $r++;
  69. // Boxes
  70. $this->boxes = array();
  71. // Permissions
  72. $this->rights = array();
  73. $this->rights_class = 'categorie';
  74. $r = 0;
  75. $this->rights[$r][0] = 241; // id de la permission
  76. $this->rights[$r][1] = 'Lire les categories'; // libelle de la permission
  77. $this->rights[$r][2] = 'r'; // type de la permission (deprecated)
  78. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  79. $this->rights[$r][4] = 'lire';
  80. $r++;
  81. $this->rights[$r][0] = 242; // id de la permission
  82. $this->rights[$r][1] = 'Creer/modifier les categories'; // libelle de la permission
  83. $this->rights[$r][2] = 'w'; // type de la permission (deprecated)
  84. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  85. $this->rights[$r][4] = 'creer';
  86. $r++;
  87. $this->rights[$r][0] = 243; // id de la permission
  88. $this->rights[$r][1] = 'Supprimer les categories'; // libelle de la permission
  89. $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
  90. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  91. $this->rights[$r][4] = 'supprimer';
  92. $r++;
  93. // Menus
  94. //-------
  95. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  96. // Exports
  97. //--------
  98. $r = 0;
  99. // All Categories List
  100. $r++;
  101. $this->export_code[$r] = $this->rights_class.'_list';
  102. $this->export_label[$r] = 'CatListAll';
  103. $this->export_icon[$r] = $this->picto;
  104. $this->export_enabled[$r] = 'true';
  105. $this->export_permission[$r] = array(array("categorie", "lire"));
  106. $typeexample = "";
  107. if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
  108. $typeexample .= ($typeexample ? " / " : "")."0=Product-Service";
  109. }
  110. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
  111. $typeexample .= ($typeexample ? "/" : "")."1=Supplier";
  112. }
  113. if (!empty($conf->societe->enabled)) {
  114. $typeexample .= ($typeexample ? " / " : "")."2=Customer-Prospect";
  115. }
  116. if (!empty($conf->adherent->enabled)) {
  117. $typeexample .= ($typeexample ? " / " : "")."3=Member";
  118. }
  119. if (!empty($conf->societe->enabled)) {
  120. $typeexample .= ($typeexample ? " / " : "")."4=Contact";
  121. }
  122. if (!empty($conf->bank->enabled)) {
  123. $typeexample .= ($typeexample ? " / " : "")."5=Bank account";
  124. }
  125. if (!empty($conf->projet->enabled)) {
  126. $typeexample .= ($typeexample ? " / " : "")."6=Project";
  127. }
  128. if (!empty($conf->user->enabled)) {
  129. $typeexample .= ($typeexample ? " / " : "")."7=User";
  130. }
  131. if (!empty($conf->bank->enabled)) {
  132. $typeexample .= ($typeexample ? " / " : "")."8=Bank line";
  133. }
  134. if (!empty($conf->stock->enabled)) {
  135. $typeexample .= ($typeexample ? " / " : "")."9=Warehouse";
  136. }
  137. if (!empty($conf->agenda->enabled)) {
  138. $typeexample .= ($typeexample ? " / " : "")."10=Agenda event";
  139. }
  140. if (!empty($conf->website->enabled)) {
  141. $typeexample .= ($typeexample ? " / " : "")."11=Website page";
  142. }
  143. $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.type'=>"Type", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory", 'pcat.label'=>"ParentCategoryLabel");
  144. $this->export_TypeFields_array[$r] = array('cat.label'=>"Text", 'cat.type'=>"Numeric", 'cat.description'=>"Text", 'cat.fk_parent'=>'List:categorie:label:rowid', 'pcat.label'=>'Text');
  145. $this->export_entities_array[$r] = array(); // We define here only fields that use another picto
  146. $this->export_help_array[$r] = array('cat.type'=>$typeexample);
  147. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  148. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
  149. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as pcat ON pcat.rowid = cat.fk_parent';
  150. $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
  151. // 0 Products
  152. $r++;
  153. $this->export_code[$r] = $this->rights_class.'_0_'.Categorie::$MAP_ID_TO_CODE[0];
  154. $this->export_label[$r] = 'CatProdList';
  155. $this->export_icon[$r] = $this->picto;
  156. $this->export_enabled[$r] = '!empty($conf->product->enabled) || !empty($conf->service->abled)';
  157. $this->export_permission[$r] = array(array("categorie", "lire"), array("produit", "export"));
  158. $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory", 'p.rowid'=>'ProductId', 'p.ref'=>'Ref', 'p.label'=>'Label');
  159. $this->export_TypeFields_array[$r] = array('cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'List:categorie:label:rowid', 'p.ref'=>'Text', 'p.label'=>'Text');
  160. $this->export_entities_array[$r] = array('p.rowid'=>'product', 'p.ref'=>'product', 'p.label'=>'product'); // We define here only fields that use another picto
  161. $keyforselect = 'product';
  162. $keyforelement = 'product';
  163. $keyforaliasextra = 'extra';
  164. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  165. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  166. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
  167. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_categorie = cat.rowid';
  168. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'product as p ON p.rowid = cp.fk_product';
  169. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON extra.fk_object = p.rowid';
  170. $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
  171. $this->export_sql_end[$r] .= ' AND cat.type = 0';
  172. // 1 Suppliers
  173. $r++;
  174. $this->export_code[$r] = $this->rights_class.'_1_'.Categorie::$MAP_ID_TO_CODE[1];
  175. $this->export_label[$r] = 'CatSupList';
  176. $this->export_icon[$r] = $this->picto;
  177. $this->export_enabled[$r] = '!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)';
  178. $this->export_permission[$r] = array(array("categorie", "lire"), array("fournisseur", "lire"));
  179. $this->export_fields_array[$r] = array(
  180. 'cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory",
  181. 's.rowid'=>'IdThirdParty', 's.nom'=>'Name', 's.prefix_comm'=>"Prefix", 's.fournisseur'=>"Supplier", 's.datec'=>"DateCreation", 's.tms'=>"DateLastModification", 's.code_fournisseur'=>"SupplierCode",
  182. 's.address'=>"Address", 's.zip'=>"Zip", 's.town'=>"Town", 'c.label'=>"Country", 'c.code'=>"CountryCode",
  183. 's.phone'=>"Phone", 's.fax'=>"Fax", 's.url'=>"Url", 's.email'=>"Email",
  184. 's.siret'=>"ProfId1", 's.siren'=>"ProfId2", 's.ape'=>"ProfId3", 's.idprof4'=>"ProfId4", 's.tva_intra'=>"VATIntraShort", 's.capital'=>"Capital", 's.note_public'=>"NotePublic",
  185. 't.libelle'=>'ThirdPartyType'
  186. );
  187. $this->export_TypeFields_array[$r] = array(
  188. 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'List:categorie:label:rowid',
  189. '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",
  190. 's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text", 'c.label'=>"List:c_country:label:label", 'c.code'=>"Text",
  191. 's.phone'=>"Text", 's.fax'=>"Text", 's.url'=>"Text", 's.email'=>"Text",
  192. 's.siret'=>"Text", 's.siren'=>"Text", 's.ape'=>"Text", 's.idprof4'=>"Text", 's.tva_intra'=>"Text", 's.capital'=>"Numeric", 's.note_public'=>"Text",
  193. 't.libelle'=>'List:c_typent:libelle:code'
  194. );
  195. $this->export_entities_array[$r] = array(
  196. 's.rowid'=>'company', 's.nom'=>'company', 's.prefix_comm'=>"company", 's.fournisseur'=>"company", 's.datec'=>"company", 's.tms'=>"company", 's.code_fournisseur'=>"company",
  197. 's.address'=>"company", 's.zip'=>"company", 's.town'=>"company", 'c.label'=>"company", 'c.code'=>"company",
  198. 's.phone'=>"company", 's.fax'=>"company", 's.url'=>"company", 's.email'=>"company",
  199. 's.siret'=>"company", 's.siren'=>"company", 's.ape'=>"company", 's.idprof4'=>"company", 's.tva_intra'=>"company", 's.capital'=>"company", 's.note_public'=>"company",
  200. 't.libelle'=>'company'
  201. ); // We define here only fields that use another picto
  202. $keyforselect = 'societe';
  203. $keyforelement = 'company';
  204. $keyforaliasextra = 'extra';
  205. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  206. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  207. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
  208. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_fournisseur as cf ON cf.fk_categorie = cat.rowid';
  209. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = cf.fk_soc';
  210. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
  211. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
  212. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
  213. $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
  214. $this->export_sql_end[$r] .= ' AND cat.type = 1';
  215. // 2 Customers/Prospects
  216. $r++;
  217. $this->export_code[$r] = $this->rights_class.'_2_'.Categorie::$MAP_ID_TO_CODE[2];
  218. $this->export_label[$r] = 'CatCusList';
  219. $this->export_icon[$r] = $this->picto;
  220. $this->export_enabled[$r] = '!empty($conf->societe->enabled)';
  221. $this->export_permission[$r] = array(array("categorie", "lire"), array("societe", "export"));
  222. $this->export_fields_array[$r] = array(
  223. 'cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory",
  224. 's.rowid'=>'IdThirdParty', 's.nom'=>'Name', 's.prefix_comm'=>"Prefix", 's.client'=>"Customer", 's.datec'=>"DateCreation", 's.tms'=>"DateLastModification", 's.code_client'=>"CustomerCode",
  225. 's.address'=>"Address", 's.zip'=>"Zip", 's.town'=>"Town", 'c.label'=>"Country", 'c.code'=>"CountryCode",
  226. 's.phone'=>"Phone", 's.fax'=>"Fax", 's.url'=>"Url", 's.email'=>"Email",
  227. 's.siret'=>"ProfId1", 's.siren'=>"ProfId2", 's.ape'=>"ProfId3", 's.idprof4'=>"ProfId4", 's.tva_intra'=>"VATIntraShort", 's.capital'=>"Capital", 's.note_public'=>"NotePublic",
  228. 't.libelle'=>'ThirdPartyType', 'pl.code'=>'ProspectLevel', 'st.code'=>'ProspectStatus'
  229. );
  230. $this->export_TypeFields_array[$r] = array(
  231. 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'List:categorie:label:rowid',
  232. '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",
  233. 's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text", 'c.label'=>"List:c_country:label:label", 'c.code'=>"Text",
  234. 's.phone'=>"Text", 's.fax'=>"Text", 's.url'=>"Text", 's.email'=>"Text",
  235. 's.siret'=>"Text", 's.siren'=>"Text", 's.ape'=>"Text", 's.idprof4'=>"Text", 's.tva_intra'=>"Text", 's.capital'=>"Numeric", 's.note_public'=>"Text",
  236. 't.libelle'=>'List:c_typent:libelle:code', 'pl.code'=>'List:c_prospectlevel:label:code', 'st.code'=>'List:c_stcomm:libelle:code'
  237. );
  238. $this->export_entities_array[$r] = array(
  239. 's.rowid'=>'company', 's.nom'=>'company', 's.prefix_comm'=>"company", 's.client'=>"company", 's.datec'=>"company", 's.tms'=>"company", 's.code_client'=>"company",
  240. 's.address'=>"company", 's.zip'=>"company", 's.town'=>"company", 'c.label'=>"company", 'c.code'=>"company",
  241. 's.phone'=>"company", 's.fax'=>"company", 's.url'=>"company", 's.email'=>"company",
  242. 's.siret'=>"company", 's.siren'=>"company", 's.ape'=>"company", 's.idprof4'=>"company", 's.tva_intra'=>"company", 's.capital'=>"company", 's.note_public'=>"company",
  243. 't.libelle'=>'company', 'pl.code'=>'company', 'st.code'=>'company'
  244. ); // We define here only fields that use another picto
  245. $keyforselect = 'societe';
  246. $keyforelement = 'company';
  247. $keyforaliasextra = 'extra';
  248. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  249. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  250. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
  251. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_societe as cs ON cs.fk_categorie = cat.rowid';
  252. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = cs.fk_soc';
  253. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
  254. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
  255. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
  256. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_prospectlevel as pl ON s.fk_prospectlevel = pl.code';
  257. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
  258. $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
  259. $this->export_sql_end[$r] .= ' AND cat.type = 2';
  260. // 3 Members
  261. $r++;
  262. $this->export_code[$r] = $this->rights_class.'_3_'.Categorie::$MAP_ID_TO_CODE[3];
  263. $this->export_label[$r] = 'CatMemberList';
  264. $this->export_icon[$r] = $this->picto;
  265. $this->export_enabled[$r] = '!empty($conf->adherent->enabled)';
  266. $this->export_permission[$r] = array(array("categorie", "lire"), array("adherent", "export"));
  267. $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory", 'p.rowid'=>'MemberId', 'p.lastname'=>'LastName', 'p.firstname'=>'Firstname');
  268. $this->export_TypeFields_array[$r] = array('cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'List:categorie:label:rowid', 'p.lastname'=>'Text', 'p.firstname'=>'Text');
  269. $this->export_entities_array[$r] = array('p.rowid'=>'member', 'p.lastname'=>'member', 'p.firstname'=>'member'); // We define here only fields that use another picto
  270. $keyforselect = 'adherent';
  271. $keyforelement = 'member';
  272. $keyforaliasextra = 'extra';
  273. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  274. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  275. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
  276. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_member as cm ON cm.fk_categorie = cat.rowid';
  277. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'adherent as p ON p.rowid = cm.fk_member';
  278. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_extrafields as extra ON cat.rowid = extra.fk_object ';
  279. $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
  280. $this->export_sql_end[$r] .= ' AND cat.type = 3';
  281. // 4 Contacts
  282. $r++;
  283. $this->export_code[$r] = $this->rights_class.'_4_'.Categorie::$MAP_ID_TO_CODE[4];
  284. $this->export_label[$r] = 'CatContactList';
  285. $this->export_icon[$r] = $this->picto;
  286. $this->export_enabled[$r] = '!empty($conf->societe->enabled)';
  287. $this->export_permission[$r] = array(array("categorie", "lire"), array("societe", "contact", "export"));
  288. $this->export_fields_array[$r] = array(
  289. 'cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory",
  290. 'p.rowid' => 'ContactId', 'civ.label' => 'UserTitle', 'p.lastname' => 'LastName', 'p.firstname' => 'Firstname',
  291. 'p.address' => 'Address', 'p.zip' => 'Zip', 'p.town' => 'Town', 'c.code' => 'CountryCode', 'c.label' => 'Country',
  292. 'p.birthday' => 'DateOfBirth', 'p.poste' => 'PostOrFunction',
  293. 'p.phone' => 'Phone', 'p.phone_perso' => 'PhonePerso', 'p.phone_mobile' => 'PhoneMobile', 'p.fax' => 'Fax', 'p.email' => 'Email',
  294. 'p.note_private' => 'NotePrivate', 'p.note_public' => 'NotePublic', 'p.statut' => 'Status',
  295. 's.nom'=>"Name", 's.client'=>"Customer", 's.fournisseur'=>"Supplier", 's.status'=>"Status",
  296. 's.address'=>"Address", 's.zip'=>"Zip", 's.town'=>"Town",
  297. 's.phone'=>"Phone", 's.fax'=>"Fax", 's.url'=>"Url", 's.email'=>"Email"
  298. );
  299. $this->export_TypeFields_array[$r] = array(
  300. 'cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'List:categorie:label:rowid',
  301. 'civ.label' => 'List:c_civility:label:label', 'p.lastname' => 'Text', 'p.firstname' => 'Text',
  302. 'p.address' => 'Text', 'p.zip' => 'Text', 'p.town' => 'Text', 'c.code' => 'Text', 'c.label' => 'List:c_country:label:label',
  303. 'p.birthday' => 'Date', 'p.poste' => 'Text',
  304. 'p.phone' => 'Text', 'p.phone_perso' => 'Text', 'p.phone_mobile' => 'Text', 'p.fax' => 'Text', 'p.email' => 'Text',
  305. 'p.note_private' => 'Text', 'p.note_public' => 'Text', 'p.statut' => 'Boolean',
  306. 's.nom'=>"Text", 's.client'=>"Boolean", 's.fournisseur'=>"Boolean", 's.status'=>"Boolean",
  307. 's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text",
  308. 's.phone'=>"Text", 's.fax'=>"Text", 's.url'=>"Text", 's.email'=>"Text"
  309. );
  310. $this->export_entities_array[$r] = array(
  311. 'p.rowid' => 'contact', 'civ.label' => 'contact', 'p.lastname' => 'contact', 'p.firstname' => 'contact',
  312. 'p.address' => 'contact', 'p.zip' => 'contact', 'p.town' => 'contact', 'c.code' => 'contact', 'c.label' => 'contact',
  313. 'p.birthday' => 'contact', 'p.poste' => 'contact',
  314. 'p.phone' => 'contact', 'p.phone_perso' => 'contact', 'p.phone_mobile' => 'contact', 'p.fax' => 'contact', 'p.email' => 'contact',
  315. 'p.note_private' => 'contact', 'p.note_public' => 'contact', 'p.statut' => 'contact',
  316. 's.nom'=>"company", 's.client'=>"company", 's.fournisseur'=>"company", 's.status'=>"company",
  317. 's.address'=>"company", 's.zip'=>"company", 's.town'=>"company",
  318. 's.phone'=>"company", 's.fax'=>"company", 's.url'=>"company", 's.email'=>"company"
  319. ); // We define here only fields that use another picto
  320. $keyforselect = 'socpeople';
  321. $keyforelement = 'contact';
  322. $keyforaliasextra = 'extra';
  323. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  324. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  325. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
  326. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_contact as cc ON cc.fk_categorie = cat.rowid';
  327. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'socpeople as p ON p.rowid = cc.fk_socpeople';
  328. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = p.rowid';
  329. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_civility as civ ON civ.code = p.civility';
  330. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON c.rowid = p.fk_pays';
  331. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
  332. $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
  333. $this->export_sql_end[$r] .= ' AND cat.type = 4';
  334. // 5 Bank accounts, TODO ?
  335. // 6 Projects
  336. $r++;
  337. $this->export_code[$r] = $this->rights_class.'_6_'.Categorie::$MAP_ID_TO_CODE[6];
  338. $this->export_label[$r] = 'CatProjectsList';
  339. $this->export_icon[$r] = $this->picto;
  340. $this->export_enabled[$r] = '!empty($conf->projet->enabled)';
  341. $this->export_permission[$r] = array(array("categorie", "lire"), array("projet", "export"));
  342. $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory", 'p.rowid'=>'ProjectId', 'p.ref'=>'Ref', 's.rowid'=>"IdThirdParty", 's.nom'=>"Name");
  343. $this->export_TypeFields_array[$r] = array('cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'List:categorie:label:rowid', 'p.ref'=>'Text', 's.rowid'=>"Numeric", 's.nom'=>"Text");
  344. $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
  345. $keyforselect = 'projet';
  346. $keyforelement = 'project';
  347. $keyforaliasextra = 'extra';
  348. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  349. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  350. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
  351. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_project as cp ON cp.fk_categorie = cat.rowid';
  352. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'projet as p ON p.rowid = cp.fk_project';
  353. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet_extrafields as extra ON extra.fk_object = p.rowid';
  354. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
  355. $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
  356. $this->export_sql_end[$r] .= ' AND cat.type = 6';
  357. // 7 Users
  358. $r++;
  359. $this->export_code[$r] = $this->rights_class.'_7_'.Categorie::$MAP_ID_TO_CODE[7];
  360. $this->export_label[$r] = 'CatUsersList';
  361. $this->export_icon[$r] = $this->picto;
  362. $this->export_enabled[$r] = '!empty($conf->user->enabled)';
  363. $this->export_permission[$r] = array(array("categorie", "lire"), array("user", "export"));
  364. $this->export_fields_array[$r] = array('cat.rowid'=>"CategId", 'cat.label'=>"Label", 'cat.description'=>"Description", 'cat.fk_parent'=>"ParentCategory", 'p.rowid'=>'TechnicalID', 'p.login'=>'Login', 'p.lastname'=>'Lastname', 'p.firstname'=>'Firstname');
  365. $this->export_TypeFields_array[$r] = array('cat.label'=>"Text", 'cat.description'=>"Text", 'cat.fk_parent'=>'List:categorie:label:rowid', 'p.login'=>'Text', 'p.lastname'=>'Text', 'p.firstname'=>'Text');
  366. $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
  367. $keyforselect = 'user';
  368. $keyforelement = 'user';
  369. $keyforaliasextra = 'extra';
  370. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  371. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  372. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'categorie as cat';
  373. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'categorie_user as cu ON cu.fk_categorie = cat.rowid';
  374. $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'user as p ON p.rowid = cu.fk_user';
  375. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user_extrafields as extra ON extra.fk_object = p.rowid';
  376. $this->export_sql_end[$r] .= ' WHERE cat.entity IN ('.getEntity('category').')';
  377. $this->export_sql_end[$r] .= ' AND cat.type = 7';
  378. // 8 Bank Lines, TODO ?
  379. // 9 Warehouses, TODO ?
  380. // 10 Agenda Events, TODO ?
  381. // 11 Website Pages, TODO ?
  382. // Imports
  383. //--------
  384. $r = 0;
  385. // Categories
  386. $r++;
  387. $this->import_code[$r] = $this->rights_class.'_list';
  388. $this->import_label[$r] = "CatList"; // Translation key
  389. $this->import_icon[$r] = $this->picto;
  390. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  391. $this->import_tables_array[$r] = array('ca'=>MAIN_DB_PREFIX.'categorie');
  392. $this->import_fields_array[$r] = array(
  393. 'ca.label'=>"Label*", 'ca.type'=>"Type*", 'ca.description'=>"Description",
  394. 'ca.fk_parent' => 'ParentCategory'
  395. );
  396. $this->import_regex_array[$r] = array('ca.type'=>'^(0|1|2|3|4|5|6|7|8|9|10|11)$');
  397. $this->import_convertvalue_array[$r] = array(
  398. 'ca.fk_parent' => array(
  399. 'rule' => 'fetchidfromcodeandlabel',
  400. 'classfile' => '/categories/class/categorie.class.php',
  401. 'class' => 'Categorie',
  402. 'method' => 'fetch',
  403. 'element' => 'category',
  404. 'codefromfield' => 'ca.type'
  405. )
  406. );
  407. $this->import_examplevalues_array[$r] = array(
  408. 'ca.label'=>"My Category Label", 'ca.type'=>$typeexample, 'ca.description'=>"My Category description", // $typeexample built above in exports
  409. 'ca.fk_parent' => 'rowid or label'
  410. );
  411. $this->import_updatekeys_array[$r] = array('ca.label'=>'Label');
  412. // 0 Products
  413. if (!empty($conf->product->enabled)) {
  414. $r++;
  415. $this->import_code[$r] = $this->rights_class.'_0_'.Categorie::$MAP_ID_TO_CODE[0];
  416. $this->import_label[$r] = "CatProdLinks"; // Translation key
  417. $this->import_icon[$r] = $this->picto;
  418. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  419. $this->import_tables_array[$r] = array('cp'=>MAIN_DB_PREFIX.'categorie_product');
  420. $this->import_fields_array[$r] = array('cp.fk_categorie'=>"Category*", 'cp.fk_product'=>"Product*");
  421. $this->import_regex_array[$r] = array('cp.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=0');
  422. $this->import_convertvalue_array[$r] = array(
  423. 'cp.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
  424. 'cp.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
  425. );
  426. $this->import_examplevalues_array[$r] = array('cp.fk_categorie'=>"rowid or label", 'cp.fk_product'=>"rowid or ref");
  427. }
  428. // 1 Suppliers
  429. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
  430. $r++;
  431. $this->import_code[$r] = $this->rights_class.'_1_'.Categorie::$MAP_ID_TO_CODE[1];
  432. $this->import_label[$r] = "CatSupLinks"; // Translation key
  433. $this->import_icon[$r] = $this->picto;
  434. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  435. $this->import_tables_array[$r] = array('cs'=>MAIN_DB_PREFIX.'categorie_fournisseur');
  436. $this->import_fields_array[$r] = array('cs.fk_categorie'=>"Category*", 'cs.fk_soc'=>"Supplier*");
  437. $this->import_regex_array[$r] = array(
  438. 'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=1',
  439. 'cs.fk_soc'=>'rowid@'.MAIN_DB_PREFIX.'societe:fournisseur>0'
  440. );
  441. $this->import_convertvalue_array[$r] = array(
  442. 'cs.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
  443. 'cs.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty')
  444. );
  445. $this->import_examplevalues_array[$r] = array('cs.fk_categorie'=>"rowid or label", 'cs.fk_soc'=>"rowid or name");
  446. }
  447. // 2 Customers
  448. if (!empty($conf->societe->enabled)) {
  449. $r++;
  450. $this->import_code[$r] = $this->rights_class.'_2_'.Categorie::$MAP_ID_TO_CODE[2];
  451. $this->import_label[$r] = "CatCusLinks"; // Translation key
  452. $this->import_icon[$r] = $this->picto;
  453. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  454. $this->import_tables_array[$r] = array('cs'=>MAIN_DB_PREFIX.'categorie_societe');
  455. $this->import_fields_array[$r] = array('cs.fk_categorie'=>"Category*", 'cs.fk_soc'=>"Customer*");
  456. $this->import_regex_array[$r] = array(
  457. 'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=2',
  458. 'cs.fk_soc'=>'rowid@'.MAIN_DB_PREFIX.'societe:client>0'
  459. );
  460. $this->import_convertvalue_array[$r] = array(
  461. 'cs.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
  462. 'cs.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty')
  463. );
  464. $this->import_examplevalues_array[$r] = array('cs.fk_categorie'=>"rowid or label", 'cs.fk_soc'=>"rowid or name");
  465. }
  466. // 3 Members
  467. if (!empty($conf->adherent->enabled)) {
  468. $r++;
  469. $this->import_code[$r] = $this->rights_class.'_3_'.Categorie::$MAP_ID_TO_CODE[3];
  470. $this->import_label[$r] = "CatMembersLinks"; // Translation key
  471. $this->import_icon[$r] = $this->picto;
  472. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  473. $this->import_tables_array[$r] = array('cm'=>MAIN_DB_PREFIX.'categorie_contact');
  474. $this->import_fields_array[$r] = array('cm.fk_categorie'=>"Category*", 'cm.fk_member'=>"Member*");
  475. $this->import_regex_array[$r] = array('cm.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=3');
  476. $this->import_convertvalue_array[$r] = array(
  477. 'cs.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
  478. 'cs.fk_member'=>array('rule'=>'fetchidfromref', 'classfile'=>'/adherents/class/adherent.class.php', 'class'=>'Adherent', 'method'=>'fetch', 'element'=>'Member')
  479. );
  480. $this->import_examplevalues_array[$r] = array('cs.fk_categorie'=>"rowid or label", 'cs.fk_member'=>"rowid or ref");
  481. }
  482. // 4 Contacts/Addresses
  483. if (!empty($conf->societe->enabled)) {
  484. $r++;
  485. $this->import_code[$r] = $this->rights_class.'_4_'.Categorie::$MAP_ID_TO_CODE[4];
  486. $this->import_label[$r] = "CatContactsLinks"; // Translation key
  487. $this->import_icon[$r] = $this->picto;
  488. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  489. $this->import_tables_array[$r] = array('cc'=>MAIN_DB_PREFIX.'categorie_contact');
  490. $this->import_fields_array[$r] = array('cc.fk_categorie'=>"Category*", 'cc.fk_socpeople'=>"IdContact*");
  491. $this->import_regex_array[$r] = array(
  492. 'cc.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=4'
  493. //'cc.fk_socpeople'=>'rowid@'.MAIN_DB_PREFIX.'socpeople'
  494. );
  495. $this->import_convertvalue_array[$r] = array(
  496. 'cc.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
  497. //'cc.fk_socpeople'=>array('rule'=>'fetchidfromref','classfile'=>'/contact/class/contact.class.php','class'=>'Contact','method'=>'fetch','element'=>'Contact')
  498. );
  499. $this->import_examplevalues_array[$r] = array('cc.fk_categorie'=>"rowid or label", 'cc.fk_socpeople'=>"rowid");
  500. }
  501. // 5 Bank accounts, TODO ?
  502. // 6 Projects
  503. if (!empty($conf->projet->enabled)) {
  504. $r++;
  505. $this->import_code[$r] = $this->rights_class.'_6_'.Categorie::$MAP_ID_TO_CODE[6];
  506. $this->import_label[$r] = "CatProjectsLinks"; // Translation key
  507. $this->import_icon[$r] = $this->picto;
  508. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  509. $this->import_tables_array[$r] = array('cp'=>MAIN_DB_PREFIX.'categorie_project');
  510. $this->import_fields_array[$r] = array('cp.fk_categorie'=>"Category*", 'cp.fk_project'=>"Project*");
  511. $this->import_regex_array[$r] = array('cp.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=6');
  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_project'=>array('rule'=>'fetchidfromref', 'classfile'=>'/projet/class/project.class.php', 'class'=>'Project', 'method'=>'fetch', 'element'=>'Project')
  515. );
  516. $this->import_examplevalues_array[$r] = array('cp.fk_categorie'=>"rowid or label", 'cp.fk_project'=>"rowid or ref");
  517. }
  518. // 7 Users
  519. if (!empty($conf->user->enabled)) {
  520. $r++;
  521. $this->import_code[$r] = $this->rights_class.'_7_'.Categorie::$MAP_ID_TO_CODE[7];
  522. $this->import_label[$r] = "CatUsersLinks"; // Translation key
  523. $this->import_icon[$r] = $this->picto;
  524. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  525. $this->import_tables_array[$r] = array('cu'=>MAIN_DB_PREFIX.'categorie_user');
  526. $this->import_fields_array[$r] = array('cu.fk_categorie'=>"Category*", 'cu.fk_user'=>"User*");
  527. $this->import_regex_array[$r] = array('cu.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=7');
  528. $this->import_convertvalue_array[$r] = array(
  529. 'cu.fk_categorie'=>array('rule'=>'fetchidfromref', 'classfile'=>'/categories/class/categorie.class.php', 'class'=>'Categorie', 'method'=>'fetch', 'element'=>'category'),
  530. 'cu.fk_user'=>array('rule'=>'fetchidfromref', 'classfile'=>'/user/class/user.class.php', 'class'=>'User', 'method'=>'fetch', 'element'=>'User')
  531. );
  532. $this->import_examplevalues_array[$r] = array('cu.fk_categorie'=>"rowid or label", 'cu.fk_user'=>"rowid or login");
  533. }
  534. // 8 Bank Lines, TODO ?
  535. // 9 Warehouses, TODO ?
  536. // 10 Agenda Events, TODO ?
  537. // 11 Website Pages, TODO ?
  538. }
  539. /**
  540. * Function called when module is enabled.
  541. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  542. * It also creates data directories
  543. *
  544. * @param string $options Options when enabling module ('', 'noboxes')
  545. * @return int 1 if OK, 0 if KO
  546. */
  547. public function init($options = '')
  548. {
  549. // Permissions
  550. $this->remove($options);
  551. $sql = array();
  552. return $this->_init($sql, $options);
  553. }
  554. }