modProjet.class.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <?php
  2. /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  5. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  8. * Copyright (C) 2014 Charles-Fr BENKE <charles.fr@benke.fr>
  9. * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \defgroup projet Module project
  26. * \brief Module to create projects/tasks/gantt diagram. Projects can them be affected to tasks.
  27. * \file htdocs/core/modules/modProjet.class.php
  28. * \ingroup projet
  29. * \brief Description and activation file for the module project
  30. */
  31. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  32. /**
  33. * Class to describe and enable module Projet
  34. */
  35. class modProjet extends DolibarrModules
  36. {
  37. /**
  38. * Constructor. Define names, constants, directories, boxes, permissions
  39. *
  40. * @param DoliDB $db Database handler
  41. */
  42. public function __construct($db)
  43. {
  44. global $conf;
  45. $this->db = $db;
  46. $this->numero = 400;
  47. $this->family = "projects";
  48. $this->module_position = '14';
  49. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  50. $this->name = preg_replace('/^mod/i', '', get_class($this));
  51. $this->description = "Gestion des projets";
  52. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  53. $this->version = 'dolibarr';
  54. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  55. $this->config_page_url = array("project.php@projet");
  56. $this->picto = 'project';
  57. // Data directories to create when module is enabled
  58. $this->dirs = array("/projet/temp");
  59. // Dependencies
  60. $this->hidden = false; // A condition to hide module
  61. $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
  62. $this->requiredby = array('modEventOrganization'); // List of module ids to disable if this one is disabled
  63. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  64. $this->phpmin = array(7, 0); // Minimum version of PHP required by module
  65. $this->langfiles = array('projects');
  66. // Constants
  67. $this->const = array();
  68. $r = 0;
  69. $this->const[$r][0] = "PROJECT_ADDON_PDF";
  70. $this->const[$r][1] = "chaine";
  71. $this->const[$r][2] = "baleine";
  72. $this->const[$r][3] = 'Name of PDF/ODT project manager class';
  73. $this->const[$r][4] = 0;
  74. $r++;
  75. $this->const[$r][0] = "PROJECT_ADDON";
  76. $this->const[$r][1] = "chaine";
  77. $this->const[$r][2] = "mod_project_simple";
  78. $this->const[$r][3] = 'Name of Numbering Rule project manager class';
  79. $this->const[$r][4] = 0;
  80. $r++;
  81. $this->const[$r][0] = "PROJECT_ADDON_PDF_ODT_PATH";
  82. $this->const[$r][1] = "chaine";
  83. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/projects";
  84. $this->const[$r][3] = "";
  85. $this->const[$r][4] = 0;
  86. $r++;
  87. $this->const[$r][0] = "PROJECT_TASK_ADDON_PDF";
  88. $this->const[$r][1] = "chaine";
  89. $this->const[$r][2] = "";
  90. $this->const[$r][3] = 'Name of PDF/ODT tasks manager class';
  91. $this->const[$r][4] = 0;
  92. $r++;
  93. $this->const[$r][0] = "PROJECT_TASK_ADDON";
  94. $this->const[$r][1] = "chaine";
  95. $this->const[$r][2] = "mod_task_simple";
  96. $this->const[$r][3] = 'Name of Numbering Rule task manager class';
  97. $this->const[$r][4] = 0;
  98. $r++;
  99. $this->const[$r][0] = "PROJECT_TASK_ADDON_PDF_ODT_PATH";
  100. $this->const[$r][1] = "chaine";
  101. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/tasks";
  102. $this->const[$r][3] = "";
  103. $this->const[$r][4] = 0;
  104. $r++;
  105. $this->const[$r][0] = "PROJECT_USE_OPPORTUNITIES";
  106. $this->const[$r][1] = "chaine";
  107. $this->const[$r][2] = "1";
  108. $this->const[$r][3] = "";
  109. $this->const[$r][4] = 0;
  110. $r++;
  111. // Boxes
  112. $this->boxes = array(
  113. 0=>array('file'=>'box_project.php', 'enabledbydefaulton'=>'Home'), // open projects
  114. 1=>array('file'=>'box_project_opportunities.php', 'enabledbydefaulton'=>'Home'), // open opportunities
  115. 2=>array('file'=>'box_task.php', 'enabledbydefaulton'=>'Home'),
  116. 3=>array('file'=>'box_validated_projects.php', 'enabledbydefaulton'=>'Home'), // task without timespent
  117. 4=>array('file'=>'box_funnel_of_prospection.php', 'enabledbydefaulton'=>'Home'),
  118. );
  119. // Permissions
  120. $this->rights = array();
  121. $this->rights_class = 'projet';
  122. $r = 0;
  123. $r++;
  124. $this->rights[$r][0] = 41; // id de la permission
  125. $this->rights[$r][1] = "Read projects and tasks (shared projects or projects I am contact for)"; // libelle de la permission
  126. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  127. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  128. $this->rights[$r][4] = 'lire';
  129. $r++;
  130. $this->rights[$r][0] = 42; // id de la permission
  131. $this->rights[$r][1] = "Create/modify projects and tasks (shared projects or projects I am contact for)"; // libelle de la permission
  132. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  133. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  134. $this->rights[$r][4] = 'creer';
  135. $r++;
  136. $this->rights[$r][0] = 44; // id de la permission
  137. $this->rights[$r][1] = "Delete project and tasks (shared projects or projects I am contact for)"; // libelle de la permission
  138. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  139. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  140. $this->rights[$r][4] = 'supprimer';
  141. $r++;
  142. $this->rights[$r][0] = 45; // id de la permission
  143. $this->rights[$r][1] = "Export projects"; // libelle de la permission
  144. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  145. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  146. $this->rights[$r][4] = 'export';
  147. $r++;
  148. $this->rights[$r][0] = 141; // id de la permission
  149. $this->rights[$r][1] = "Read all projects and tasks (also private projects I am not contact for)"; // libelle de la permission
  150. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  151. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  152. $this->rights[$r][4] = 'all';
  153. $this->rights[$r][5] = 'lire';
  154. $r++;
  155. $this->rights[$r][0] = 142; // id de la permission
  156. $this->rights[$r][1] = "Create/modify all projects and tasks (also private projects I am not contact for)"; // libelle de la permission
  157. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  158. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  159. $this->rights[$r][4] = 'all';
  160. $this->rights[$r][5] = 'creer';
  161. $r++;
  162. $this->rights[$r][0] = 144; // id de la permission
  163. $this->rights[$r][1] = "Delete all projects and tasks (also private projects I am not contact for)"; // libelle de la permission
  164. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  165. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  166. $this->rights[$r][4] = 'all';
  167. $this->rights[$r][5] = 'supprimer';
  168. $r++;
  169. $this->rights[$r][0] = 145; // id de la permission
  170. $this->rights[$r][1] = "Can enter time consumed on assigned tasks (timesheet)"; // libelle de la permission
  171. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  172. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  173. $this->rights[$r][4] = 'time';
  174. // Menus
  175. //-------
  176. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  177. // Exports
  178. //--------
  179. $r = 1;
  180. $this->export_code[$r] = $this->rights_class.'_'.$r;
  181. $this->export_label[$r] = 'ProjectsAndTasksLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
  182. $this->export_permission[$r] = array(array("projet", "export"));
  183. $this->export_dependencies_array[$r] = array('projecttask'=>'pt.rowid', 'task_time'=>'ptt.rowid');
  184. $this->export_TypeFields_array[$r] = array(
  185. 's.rowid'=>"Numeric", 's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 's.fk_pays'=>'List:c_country:label',
  186. 's.phone'=>'Text', 's.email'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text',
  187. 'p.rowid'=>"Numeric", 'p.ref'=>"Text", 'p.title'=>"Text",
  188. 'p.usage_opportunity'=>'Boolean', 'p.usage_task'=>'Boolean', 'p.usage_bill_time'=>'Boolean',
  189. 'p.datec'=>"Date", 'p.dateo'=>"Date", 'p.datee'=>"Date", 'p.fk_statut'=>'Status', 'cls.code'=>"Text", 'p.opp_percent'=>'Numeric', 'p.opp_amount'=>'Numeric', 'p.description'=>"Text", 'p.entity'=>'Numeric', 'p.budget_amount'=>'Numeric',
  190. 'pt.rowid'=>'Numeric', 'pt.ref'=>'Text', 'pt.label'=>'Text', 'pt.dateo'=>"Date", 'pt.datee'=>"Date", 'pt.duration_effective'=>"Duree", 'pt.planned_workload'=>"Numeric", 'pt.progress'=>"Numeric", 'pt.description'=>"Text",
  191. 'ptt.rowid'=>'Numeric', 'ptt.element_date'=>'Date', 'ptt.element_duration'=>"Duree", 'ptt.fk_user'=>"FormSelect:select_dolusers", 'ptt.note'=>"Text"
  192. );
  193. $this->export_entities_array[$r] = array(
  194. 's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 's.fk_pays'=>'company',
  195. 's.phone'=>'company', 's.email'=>'company', 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company'
  196. );
  197. $this->export_fields_array[$r] = array(
  198. 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 's.fk_pays'=>'Country',
  199. 's.phone'=>'Phone', 's.email'=>'Email', 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode',
  200. 'p.rowid'=>"ProjectId", 'p.ref'=>"RefProject", 'p.title'=>'ProjectLabel',
  201. 'p.usage_opportunity'=>'ProjectFollowOpportunity', 'p.usage_task'=>'ProjectFollowTasks', 'p.usage_bill_time'=>'BillTime',
  202. 'p.datec'=>"DateCreation", 'p.dateo'=>"DateStart", 'p.datee'=>"DateEnd", 'p.fk_statut'=>'ProjectStatus', 'cls.code'=>'OpportunityStatus', 'p.opp_percent'=>'OpportunityProbability', 'p.opp_amount'=>'OpportunityAmount', 'p.budget_amount'=>'Budget', 'p.description'=>"Description"
  203. );
  204. // Add multicompany field
  205. if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
  206. $nbofallowedentities = count(explode(',', getEntity('project'))); // If project are shared, nb will be > 1
  207. if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
  208. $this->export_fields_array[$r] += array('p.entity'=>'Entity');
  209. }
  210. }
  211. if (!getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  212. unset($this->export_fields_array[$r]['p.opp_percent']);
  213. unset($this->export_fields_array[$r]['p.opp_amount']);
  214. unset($this->export_fields_array[$r]['cls.code']);
  215. }
  216. // Add fields for project
  217. $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array());
  218. // Add extra fields for project
  219. $keyforselect = 'projet';
  220. $keyforelement = 'project';
  221. $keyforaliasextra = 'extra';
  222. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  223. // Add fields for tasks
  224. $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('pt.rowid'=>'TaskId', 'pt.ref'=>'RefTask', 'pt.label'=>'LabelTask', 'pt.dateo'=>"TaskDateStart", 'pt.datee'=>"TaskDateEnd", 'pt.duration_effective'=>"DurationEffective", 'pt.planned_workload'=>"PlannedWorkload", 'pt.progress'=>"Progress", 'pt.description'=>"TaskDescription"));
  225. $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('pt.rowid'=>'projecttask', 'pt.ref'=>'projecttask', 'pt.label'=>'projecttask', 'pt.dateo'=>"projecttask", 'pt.datee'=>"projecttask", 'pt.duration_effective'=>"projecttask", 'pt.planned_workload'=>"projecttask", 'pt.progress'=>"projecttask", 'pt.description'=>"projecttask"));
  226. // Add extra fields for task
  227. $keyforselect = 'projet_task';
  228. $keyforelement = 'projecttask';
  229. $keyforaliasextra = 'extra2';
  230. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  231. // End add extra fields
  232. $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('ptt.rowid'=>'IdTaskTime', 'ptt.element_date'=>'TaskTimeDate', 'ptt.element_duration'=>"TimeSpent", 'ptt.fk_user'=>"TaskTimeUser", 'ptt.note'=>"TaskTimeNote"));
  233. $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('ptt.rowid'=>'task_time', 'ptt.element_date'=>'task_time', 'ptt.element_duration'=>"task_time", 'ptt.fk_user'=>"task_time", 'ptt.note'=>"task_time"));
  234. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  235. $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('f.ref'=>"Billed"));
  236. $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('f.ref'=>"task_time"));
  237. }
  238. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  239. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'projet as p';
  240. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet_extrafields as extra ON p.rowid = extra.fk_object';
  241. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_lead_status as cls ON p.fk_opp_status = cls.rowid';
  242. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX."projet_task as pt ON p.rowid = pt.fk_projet";
  243. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet_task_extrafields as extra2 ON pt.rowid = extra2.fk_object';
  244. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX."element_time as ptt ON (pt.rowid = ptt.fk_element AND ptt.elementtype = 'task')";
  245. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON p.fk_soc = s.rowid';
  246. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  247. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture as f ON ptt.invoice_id = f.rowid';
  248. }
  249. $this->export_sql_end[$r] .= " WHERE p.entity IN (".getEntity('project').")";
  250. // Import project/opportunities
  251. $r++;
  252. $this->import_code[$r] = 'projects';
  253. $this->import_label[$r] = 'ImportDatasetProjects';
  254. $this->import_icon[$r] = 'project';
  255. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  256. $this->import_tables_array[$r] = array('t'=>MAIN_DB_PREFIX.'projet', 'extra'=>MAIN_DB_PREFIX.'projet_extrafields'); // List of tables to insert into (insert done in same order)
  257. $this->import_fields_array[$r] = array('t.ref'=>'ProjectRef*', 't.title'=>'Label*', 't.description'=>"Description", 't.fk_soc' => 'ThirdPartyName', 't.public'=>"Public", 't.fk_statut'=>"Status");
  258. $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('t.fk_opp_status'=>"OpportunityStatus", 't.opp_percent'=>"OpportunityProbability", 't.opp_amount'=>"OpportunityAmount", 't.note_public'=>"NotePublic", 't.note_private'=>"NotePrivate", 't.budget_amount'=>"Budget", 't.dateo'=>"DateStart", 't.datee'=>"DateEnd"));
  259. // Add extra fields
  260. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'projet' AND entity IN (0,".$conf->entity.")";
  261. $resql = $this->db->query($sql);
  262. if ($resql) { // This can fail when class is used on old database (during migration for example)
  263. while ($obj = $this->db->fetch_object($resql)) {
  264. $fieldname = 'extra.'.$obj->name;
  265. $fieldlabel = ucfirst($obj->label);
  266. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  267. }
  268. }
  269. // End add extra fields
  270. $this->import_fieldshidden_array[$r] = array('t.fk_user_creat'=>'user->id', 'extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'projet'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
  271. $this->import_convertvalue_array[$r] = array(
  272. 't.ref'=>array('rule'=>'getrefifauto', 'class'=>(!getDolGlobalString('PROJECT_ADDON') ? 'mod_project_simple' : $conf->global->PROJECT_ADDON), 'path'=>"/core/modules/project/".(!getDolGlobalString('PROJECT_ADDON') ? 'mod_project_simple' : $conf->global->PROJECT_ADDON).'.php'),
  273. 't.fk_soc' => array(
  274. 'rule' => 'fetchidfromref',
  275. 'file' => '/societe/class/societe.class.php',
  276. 'class' => 'Societe',
  277. 'method' => 'fetch',
  278. 'element' => 'ThirdParty'
  279. ),
  280. );
  281. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  282. $this->import_regex_array[$r] = array('t.dateo'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$', 't.datee'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$', 't.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$');
  283. $this->import_examplevalues_array[$r] = array('t.fk_soc'=>'ThirdParty', 't.ref'=>"auto or PJ2010-1234", 't.title'=>"My project", 't.fk_statut'=>'0,1 or 2', 't.datec'=>'1972-10-10', 't.note_private'=>"My private note", 't.note_public'=>"My public note");
  284. // Import list of tasks
  285. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  286. $r++;
  287. $this->import_code[$r] = 'tasksofprojects';
  288. $this->import_label[$r] = 'ImportDatasetTasks';
  289. $this->import_icon[$r] = 'task';
  290. $this->import_entities_array[$r] = array('t.fk_projet'=>'project'); // We define here only fields that use another icon that the one defined into import_icon
  291. $this->import_tables_array[$r] = array('t'=>MAIN_DB_PREFIX.'projet_task', 'extra'=>MAIN_DB_PREFIX.'projet_task_extrafields'); // List of tables to insert into (insert done in same order)
  292. $this->import_fields_array[$r] = array('t.fk_projet'=>'ProjectRef*', 't.ref'=>'RefTask*', 't.label'=>'LabelTask*', 't.dateo'=>"DateStart", 't.datee'=>"DateEnd", 't.planned_workload'=>"PlannedWorkload", 't.progress'=>"Progress", 't.note_private'=>"NotePrivate", 't.note_public'=>"NotePublic", 't.datec'=>"DateCreation");
  293. // Add extra fields
  294. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'projet_task' AND entity IN (0,".$conf->entity.")";
  295. $resql = $this->db->query($sql);
  296. if ($resql) { // This can fail when class is used on old database (during migration for example)
  297. while ($obj = $this->db->fetch_object($resql)) {
  298. $fieldname = 'extra.'.$obj->name;
  299. $fieldlabel = ucfirst($obj->label);
  300. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  301. }
  302. }
  303. // End add extra fields
  304. $this->import_fieldshidden_array[$r] = array('t.fk_user_creat'=>'user->id', 'extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'projet_task'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
  305. $this->import_convertvalue_array[$r] = array(
  306. 't.fk_projet'=>array('rule'=>'fetchidfromref', 'classfile'=>'/projet/class/project.class.php', 'class'=>'Project', 'method'=>'fetch', 'element'=>'Project'),
  307. 't.ref'=>array('rule'=>'getrefifauto', 'class'=>(!getDolGlobalString('PROJECT_TASK_ADDON') ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON), 'path'=>"/core/modules/project/task/".(!getDolGlobalString('PROJECT_TASK_ADDON') ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON).'.php')
  308. );
  309. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  310. $this->import_regex_array[$r] = array('t.dateo'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$', 't.datee'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$', 't.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$');
  311. $this->import_examplevalues_array[$r] = array('t.fk_projet'=>'MyProjectRef', 't.ref'=>"auto or TK2010-1234", 't.label'=>"My task", 't.progress'=>"0 (not started) to 100 (finished)", 't.datec'=>'1972-10-10', 't.note_private'=>"My private note", 't.note_public'=>"My public note");
  312. }
  313. }
  314. /**
  315. * Function called when module is enabled.
  316. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  317. * It also creates data directories
  318. *
  319. * @param string $options Options when enabling module ('', 'noboxes')
  320. * @return int 1 if OK, 0 if KO
  321. */
  322. public function init($options = '')
  323. {
  324. global $conf, $langs;
  325. // Permissions
  326. $this->remove($options);
  327. //ODT template for project
  328. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/projects/template_project.odt';
  329. $dirodt = DOL_DATA_ROOT.'/doctemplates/projects';
  330. $dest = $dirodt.'/template_project.odt';
  331. if (file_exists($src) && !file_exists($dest)) {
  332. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  333. dol_mkdir($dirodt);
  334. $result = dol_copy($src, $dest, 0, 0);
  335. if ($result < 0) {
  336. $langs->load("errors");
  337. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  338. return 0;
  339. }
  340. }
  341. //ODT template for tasks
  342. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/tasks/template_task_summary.odt';
  343. $dirodt = DOL_DATA_ROOT.'/doctemplates/tasks';
  344. $dest = $dirodt.'/template_task_summary.odt';
  345. if (file_exists($src) && !file_exists($dest)) {
  346. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  347. dol_mkdir($dirodt);
  348. $result = dol_copy($src, $dest, 0, 0);
  349. if ($result < 0) {
  350. $langs->load("errors");
  351. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  352. return 0;
  353. }
  354. }
  355. $sql = array();
  356. $sql[] = "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[3][2])."' AND type = 'task' AND entity = ".((int) $conf->entity);
  357. $sql[] = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[3][2])."','task',".((int) $conf->entity).")";
  358. $sql[] = "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'beluga' AND type = 'project' AND entity = ".((int) $conf->entity);
  359. $sql[] = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('beluga','project',".((int) $conf->entity).")";
  360. $sql[] = "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'baleine' AND type = 'project' AND entity = ".((int) $conf->entity);
  361. $sql[] = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('baleine','project',".((int) $conf->entity).")";
  362. return $this->_init($sql, $options);
  363. }
  364. }