modProjet.class.php 20 KB

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