dolibarr  7.0.0-beta
modProjet.class.php
Go to the documentation of this file.
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@capnetworks.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 <http://www.gnu.org/licenses/>.
22  */
23 
31 include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
32 
33 
38 {
39 
45  function __construct($db)
46  {
47  global $conf;
48 
49  $this->db = $db;
50  $this->numero = 400;
51 
52  $this->family = "projects";
53  $this->module_position = 10;
54  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
55  $this->name = preg_replace('/^mod/i','',get_class($this));
56  $this->description = "Gestion des projets";
57  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
58  $this->version = 'dolibarr';
59 
60  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
61  $this->special = 0;
62  $this->config_page_url = array("project.php@projet");
63  $this->picto='project';
64 
65  // Data directories to create when module is enabled
66  $this->dirs = array("/projet/temp");
67 
68  // Dependancies
69  $this->depends = array();
70  $this->requiredby = array();
71  $this->conflictwith = array();
72  $this->langfiles = array('projects');
73 
74  // Constants
75  $this->const = array();
76  $r=0;
77 
78  $this->const[$r][0] = "PROJECT_ADDON_PDF";
79  $this->const[$r][1] = "chaine";
80  $this->const[$r][2] = "baleine";
81  $this->const[$r][3] = 'Name of PDF/ODT project manager class';
82  $this->const[$r][4] = 0;
83  $r++;
84 
85  $this->const[$r][0] = "PROJECT_ADDON";
86  $this->const[$r][1] = "chaine";
87  $this->const[$r][2] = "mod_project_simple";
88  $this->const[$r][3] = 'Name of Numbering Rule project manager class';
89  $this->const[$r][4] = 0;
90  $r++;
91 
92  $this->const[$r][0] = "PROJECT_ADDON_PDF_ODT_PATH";
93  $this->const[$r][1] = "chaine";
94  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/projects";
95  $this->const[$r][3] = "";
96  $this->const[$r][4] = 0;
97  $r++;
98 
99  $this->const[$r][0] = "PROJECT_TASK_ADDON_PDF";
100  $this->const[$r][1] = "chaine";
101  $this->const[$r][2] = "";
102  $this->const[$r][3] = 'Name of PDF/ODT tasks manager class';
103  $this->const[$r][4] = 0;
104  $r++;
105 
106  $this->const[$r][0] = "PROJECT_TASK_ADDON";
107  $this->const[$r][1] = "chaine";
108  $this->const[$r][2] = "mod_task_simple";
109  $this->const[$r][3] = 'Name of Numbering Rule task manager class';
110  $this->const[$r][4] = 0;
111  $r++;
112 
113  $this->const[$r][0] = "PROJECT_TASK_ADDON_PDF_ODT_PATH";
114  $this->const[$r][1] = "chaine";
115  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/tasks";
116  $this->const[$r][3] = "";
117  $this->const[$r][4] = 0;
118  $r++;
119 
120  $this->const[$r][0] = "PROJECT_USE_OPPORTUNITIES";
121  $this->const[$r][1] = "chaine";
122  $this->const[$r][2] = "1";
123  $this->const[$r][3] = "";
124  $this->const[$r][4] = 0;
125  $r++;
126 
127  $this->const[$r][0] = "MAIN_DELAY_PROJECT_TO_CLOSE";
128  $this->const[$r][1] = "chaine";
129  $this->const[$r][2] = "7";
130  $this->const[$r][3] = "";
131  $this->const[$r][4] = 0;
132  $r++;
133  $this->const[$r][0] = "MAIN_DELAY_TASKS_TODO";
134  $this->const[$r][1] = "chaine";
135  $this->const[$r][2] = "7";
136  $this->const[$r][3] = "";
137  $this->const[$r][4] = 0;
138  $r++;
139 
140  // Boxes
141  $this->boxes = array();
142  $r=0;
143  $this->boxes[$r][1] = "box_project.php";
144  $r++;
145  $this->boxes[$r][1] = "box_task.php";
146  $r++;
147 
148  // Permissions
149  $this->rights = array();
150  $this->rights_class = 'projet';
151  $r=0;
152 
153  $r++;
154  $this->rights[$r][0] = 41; // id de la permission
155  $this->rights[$r][1] = "Read projects and tasks (shared projects or projects I am contact for). Can also enter time consumed on assigned tasks (timesheet)"; // libelle de la permission
156  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
157  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
158  $this->rights[$r][4] = 'lire';
159 
160  $r++;
161  $this->rights[$r][0] = 42; // id de la permission
162  $this->rights[$r][1] = "Create/modify projects and tasks (shared projects or projects I am contact for)"; // libelle de la permission
163  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
164  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
165  $this->rights[$r][4] = 'creer';
166 
167  $r++;
168  $this->rights[$r][0] = 44; // id de la permission
169  $this->rights[$r][1] = "Delete project and tasks (shared projects or projects I am contact for)"; // libelle de la permission
170  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
171  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
172  $this->rights[$r][4] = 'supprimer';
173 
174  $r++;
175  $this->rights[$r][0] = 45; // id de la permission
176  $this->rights[$r][1] = "Export projects"; // libelle de la permission
177  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
178  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
179  $this->rights[$r][4] = 'export';
180 
181  $r++;
182  $this->rights[$r][0] = 141; // id de la permission
183  $this->rights[$r][1] = "Read all projects and tasks (also private projects I am not contact for)"; // libelle de la permission
184  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
185  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
186  $this->rights[$r][4] = 'all';
187  $this->rights[$r][5] = 'lire';
188 
189  $r++;
190  $this->rights[$r][0] = 142; // id de la permission
191  $this->rights[$r][1] = "Create/modify all projects and tasks (also private projects I am not contact for). Can also enter time consumed on assigned tasks (timesheet)"; // libelle de la permission
192  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
193  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
194  $this->rights[$r][4] = 'all';
195  $this->rights[$r][5] = 'creer';
196 
197  $r++;
198  $this->rights[$r][0] = 144; // id de la permission
199  $this->rights[$r][1] = "Delete all projects and tasks (also private projects I am not contact for)"; // libelle de la permission
200  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
201  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
202  $this->rights[$r][4] = 'all';
203  $this->rights[$r][5] = 'supprimer';
204 
205 
206  // Menus
207  //-------
208  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
209 
210 
211  //Exports
212  //--------
213  $r=1;
214 
215  $this->export_code[$r]=$this->rights_class.'_'.$r;
216  $this->export_label[$r]='ProjectsAndTasksLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
217  $this->export_permission[$r]=array(array("projet","export"));
218  $this->export_dependencies_array[$r]=array('projecttask'=>'pt.rowid', 'task_time'=>'ptt.rowid');
219 
220  $this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','s.fk_pays'=>'List:c_country:label',
221  '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',
222  'p.rowid'=>"List:projet:ref",'p.ref'=>"Text",'p.title'=>"Text",'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',
223  'pt.rowid'=>'Text','pt.label'=>'Text','pt.dateo'=>"Date",'pt.datee'=>"Date",'pt.duration_effective'=>"Duree",'pt.planned_workload'=>"Numeric",'pt.progress'=>"Numeric",'pt.description'=>"Text",
224  'ptt.rowid'=>'Numeric','ptt.task_date'=>'Date','ptt.task_duration'=>"Duree",'ptt.fk_user'=>"List:user:CONCAT(lastname,' ',firstname)",'ptt.note'=>"Text");
225  $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company',
226  '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');
227 
228  $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country',
229  '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',
230  'p.rowid'=>"ProjectId",'p.ref'=>"RefProject",'p.title'=>'ProjectLabel', '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.description'=>"Description");
231  // Add multicompany field
232  if (! empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED))
233  {
234  $nbofallowedentities=count(explode(',',getEntity('project'))); // If project are shared, nb will be > 1
235  if (! empty($conf->multicompany->enabled) && $nbofallowedentities > 1) $this->export_fields_array[$r]+=array('p.entity'=>'Entity');
236  }
237  if (empty($conf->global->PROJECT_USE_OPPORTUNITIES))
238  {
239  unset($this->export_fields_array[$r]['p.opp_percent']);
240  unset($this->export_fields_array[$r]['p.opp_amount']);
241  unset($this->export_fields_array[$r]['cls.code']);
242  }
243 
244  // Add fields for project
245  $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array());
246  // Add extra fields for project
247  $keyforselect='projet'; $keyforelement='project'; $keyforaliasextra='extra';
248  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
249  // Add fields for tasks
250  $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('pt.rowid'=>'RefTask','pt.label'=>'LabelTask','pt.dateo'=>"TaskDateStart",'pt.datee'=>"TaskDateEnd",'pt.duration_effective'=>"DurationEffective",'pt.planned_workload'=>"PlannedWorkload",'pt.progress'=>"Progress",'pt.description'=>"TaskDescription"));
251  $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r], array('pt.rowid'=>'projecttask','pt.label'=>'projecttask','pt.dateo'=>"projecttask",'pt.datee'=>"projecttask",'pt.duration_effective'=>"projecttask",'pt.planned_workload'=>"projecttask",'pt.progress'=>"projecttask",'pt.description'=>"projecttask"));
252  // Add extra fields for task
253  $keyforselect='projet_task'; $keyforelement='projecttask'; $keyforaliasextra='extra2';
254  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
255  // End add extra fields
256  $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"));
257  $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"));
258 
259  $this->export_sql_start[$r]='SELECT DISTINCT ';
260  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'projet as p';
261  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet_extrafields as extra ON p.rowid = extra.fk_object';
262  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_lead_status as cls ON p.fk_opp_status = cls.rowid';
263  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task as pt ON p.rowid = pt.fk_projet";
264  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet_task_extrafields as extra2 ON pt.rowid = extra2.fk_object';
265  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task_time as ptt ON pt.rowid = ptt.fk_task";
266  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON p.fk_soc = s.rowid';
267  $this->export_sql_end[$r] .=' WHERE p.entity = '.$conf->entity;
268 
269 
270  // Import list of tasks
271  if (empty($conf->global->PROJECT_HIDE_TASKS))
272  {
273  $r++;
274  $this->import_code[$r]='tasksofprojects';
275  $this->import_label[$r]='ImportDatasetTasks';
276  $this->import_icon[$r]='task';
277  $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
278  $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)
279  $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");
280  // Add extra fields
281  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'projet_task' AND entity = ".$conf->entity;
282  $resql=$this->db->query($sql);
283  if ($resql) // This can fail when class is used on old database (during migration for example)
284  {
285  while ($obj=$this->db->fetch_object($resql))
286  {
287  $fieldname='extra.'.$obj->name;
288  $fieldlabel=ucfirst($obj->label);
289  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
290  }
291  }
292  // End add extra fields
293  $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)
294  $this->import_convertvalue_array[$r]=array(
295  't.fk_projet'=>array('rule'=>'fetchidfromref','classfile'=>'/projet/class/project.class.php','class'=>'Project','method'=>'fetch','element'=>'Project'),
296  't.ref'=>array('rule'=>'getrefifauto')
297  );
298  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
299  $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])?$');
300  $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");
301  }
302  }
303 
304 
313  function init($options='')
314  {
315  global $conf,$langs;
316 
317  // Permissions
318  $this->remove($options);
319 
320  //ODT template for project
321  $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/projects/template_project.odt';
322  $dirodt=DOL_DATA_ROOT.'/doctemplates/projects';
323  $dest=$dirodt.'/template_project.odt';
324 
325  if (file_exists($src) && ! file_exists($dest))
326  {
327  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
328  dol_mkdir($dirodt);
329  $result=dol_copy($src,$dest,0,0);
330  if ($result < 0)
331  {
332  $langs->load("errors");
333  $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
334  return 0;
335  }
336  }
337 
338  //ODT template for tasks
339  $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/tasks/template_task_summary.odt';
340  $dirodt=DOL_DATA_ROOT.'/doctemplates/tasks';
341  $dest=$dirodt.'/template_task_summary.odt';
342 
343  if (file_exists($src) && ! file_exists($dest))
344  {
345  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
346  dol_mkdir($dirodt);
347  $result=dol_copy($src,$dest,0,0);
348  if ($result < 0)
349  {
350  $langs->load("errors");
351  $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
352  return 0;
353  }
354  }
355 
356  $sql = array(
357  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'project' AND entity = ".$conf->entity,
358  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','project',".$conf->entity.")",
359  );
360 
361  $sql = array(
362  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[3][2])."' AND type = 'task' AND entity = ".$conf->entity,
363  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[3][2])."','task',".$conf->entity.")"
364  );
365 
366  return $this->_init($sql,$options);
367  }
368 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:631
Class DolibarrModules.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
init($options='')
Function called when module is enabled.
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
_init($array_sql, $options='')
Enables a module.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
__construct($db)
Constructor.
Class to describe and enable module Projet.