dolibarr  19.0.0-dev
project.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2014-2017 Marcos GarcĂ­a <marcosgdf@gmail.com>
7  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
8  * Copyright (C) 2019 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
10  * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
31 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32 
36 class Project extends CommonObject
37 {
38 
42  public $element = 'project';
43 
47  public $table_element = 'projet';
48 
52  public $table_element_line = 'projet_task';
53 
57  public $table_element_date;
58 
62  public $fk_element = 'fk_projet';
63 
68  public $ismultientitymanaged = 1;
69 
73  public $isextrafieldmanaged = 1;
74 
78  public $picto = 'project';
79 
83  protected $table_ref_field = 'ref';
84 
88  public $description;
89 
93  public $title;
94 
100  public $dateo;
101 
105  public $date_start;
106 
112  public $datee;
113 
117  public $date_end;
118 
122  public $date_start_event;
123 
127  public $date_end_event;
128 
132  public $location;
133 
137  public $date_close;
138 
139  public $socid; // To store id of thirdparty
140  public $thirdparty_name; // To store name of thirdparty (defined only in some cases)
141 
143 
147  public $fk_user_close;
148 
152  public $user_close_id;
153  public $public;
154 
158  public $budget_amount;
159 
163  public $usage_opportunity;
164 
168  public $usage_task;
169 
173  public $usage_bill_time; // Is the time spent on project must be invoiced or not
174 
178  public $usage_organize_event;
179 
183  public $accept_conference_suggestions;
184 
188  public $accept_booth_suggestions;
189 
193  public $price_registration;
194 
198  public $price_booth;
199 
203  public $max_attendees;
204 
205  public $statuts_short;
206  public $statuts_long;
207 
208  public $statut; // 0=draft, 1=opened, 2=closed
209 
210  public $opp_status; // opportunity status, into table llx_c_lead_status
211  public $opp_status_code;
212  public $fk_opp_status; // opportunity status, into table llx_c_lead_status
213  public $opp_amount; // opportunity amount
214  public $opp_percent; // opportunity probability
215  public $opp_weighted_amount; // opportunity weighted amount
216 
217  public $email_msgid;
218 
219  public $oldcopy;
220 
221  public $weekWorkLoad; // Used to store workload details of a projet
222  public $weekWorkLoadPerTask; // Used to store workload details of tasks of a projet
223 
229  public $datec;
230 
234  public $date_c;
235 
241  public $datem;
242 
246  public $date_m;
247 
251  public $lines;
252 
277  // BEGIN MODULEBUILDER PROPERTIES
281  public $fields = array(
282  'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
283  'ref' =>array('type'=>'varchar(50)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'showoncombobox'=>1, 'position'=>15, 'searchall'=>1),
284  'title' =>array('type'=>'varchar(255)', 'label'=>'ProjectLabel', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>17, 'showoncombobox'=>2, 'searchall'=>1),
285  'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>3, 'notnull'=>1, 'position'=>19),
286  'fk_soc' =>array('type'=>'integer', 'label'=>'Thirdparty', 'enabled'=>1, 'visible'=>0, 'position'=>20),
287  'dateo' =>array('type'=>'date', 'label'=>'DateStart', 'enabled'=>1, 'visible'=>1, 'position'=>30),
288  'datee' =>array('type'=>'date', 'label'=>'DateEnd', 'enabled'=>1, 'visible'=>1, 'position'=>35),
289  'description' =>array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>3, 'position'=>55, 'searchall'=>1),
290  'public' =>array('type'=>'integer', 'label'=>'Visibility', 'enabled'=>1, 'visible'=>1, 'position'=>65),
291  'fk_opp_status' =>array('type'=>'integer', 'label'=>'OpportunityStatusShort', 'enabled'=>'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")', 'visible'=>1, 'position'=>75),
292  'opp_percent' =>array('type'=>'double(5,2)', 'label'=>'OpportunityProbabilityShort', 'enabled'=>'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")', 'visible'=>1, 'position'=>80),
293  'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>85, 'searchall'=>1),
294  'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>90, 'searchall'=>1),
295  'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPdf', 'enabled'=>1, 'visible'=>0, 'position'=>95),
296  'date_close' =>array('type'=>'datetime', 'label'=>'DateClosing', 'enabled'=>1, 'visible'=>0, 'position'=>105),
297  'fk_user_close' =>array('type'=>'integer', 'label'=>'UserClosing', 'enabled'=>1, 'visible'=>0, 'position'=>110),
298  'opp_amount' =>array('type'=>'double(24,8)', 'label'=>'OpportunityAmountShort', 'enabled'=>1, 'visible'=>'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")', 'position'=>115),
299  'budget_amount' =>array('type'=>'double(24,8)', 'label'=>'Budget', 'enabled'=>1, 'visible'=>-1, 'position'=>119),
300  'usage_opportunity' =>array('type'=>'integer', 'label'=>'UsageOpportunity', 'enabled'=>1, 'visible'=>-1, 'position'=>130),
301  'usage_task' =>array('type'=>'integer', 'label'=>'UsageTasks', 'enabled'=>1, 'visible'=>-1, 'position'=>135),
302  'usage_bill_time' =>array('type'=>'integer', 'label'=>'UsageBillTimeShort', 'enabled'=>1, 'visible'=>-1, 'position'=>140),
303  'usage_organize_event' =>array('type'=>'integer', 'label'=>'UsageOrganizeEvent', 'enabled'=>1, 'visible'=>-1, 'position'=>145),
304  // Properties for event organization
305  'date_start_event' =>array('type'=>'date', 'label'=>'DateStartEvent', 'enabled'=>"isModEnabled('eventorganization')", 'visible'=>1, 'position'=>200),
306  'date_end_event' =>array('type'=>'date', 'label'=>'DateEndEvent', 'enabled'=>"isModEnabled('eventorganization')", 'visible'=>1, 'position'=>201),
307  'location' =>array('type'=>'text', 'label'=>'Location', 'enabled'=>1, 'visible'=>3, 'position'=>55, 'searchall'=>202),
308  'accept_conference_suggestions' =>array('type'=>'integer', 'label'=>'AllowUnknownPeopleSuggestConf', 'enabled'=>1, 'visible'=>-1, 'position'=>210),
309  'accept_booth_suggestions' =>array('type'=>'integer', 'label'=>'AllowUnknownPeopleSuggestBooth', 'enabled'=>1, 'visible'=>-1, 'position'=>211),
310  'price_registration' =>array('type'=>'double(24,8)', 'label'=>'PriceOfRegistration', 'enabled'=>1, 'visible'=>-1, 'position'=>212),
311  'price_booth' =>array('type'=>'double(24,8)', 'label'=>'PriceOfBooth', 'enabled'=>1, 'visible'=>-1, 'position'=>215),
312  'max_attendees' =>array('type'=>'integer', 'label'=>'MaxNbOfAttendees', 'enabled'=>1, 'visible'=>-1, 'position'=>215),
313  // Generic
314  'datec' =>array('type'=>'datetime', 'label'=>'DateCreationShort', 'enabled'=>1, 'visible'=>-2, 'position'=>400),
315  'tms' =>array('type'=>'timestamp', 'label'=>'DateModificationShort', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>405),
316  'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserCreation', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>410),
317  'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModification', 'enabled'=>1, 'visible'=>0, 'position'=>415),
318  'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'position'=>420),
319  'email_msgid'=>array('type'=>'varchar(255)', 'label'=>'EmailMsgID', 'enabled'=>1, 'visible'=>-1, 'position'=>450, 'help'=>'EmailMsgIDWhenSourceisEmail', 'csslist'=>'tdoverflowmax125'),
320  'fk_statut' =>array('type'=>'smallint(6)', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>500),
321  );
322  // END MODULEBUILDER PROPERTIES
323 
327  const STATUS_DRAFT = 0;
328 
332  const STATUS_VALIDATED = 1;
333 
337  const STATUS_CLOSED = 2;
338 
344  public function __construct($db)
345  {
346  global $conf;
347 
348  $this->db = $db;
349 
350  $this->statuts_short = array(0 => 'Draft', 1 => 'Opened', 2 => 'Closed');
351  $this->statuts_long = array(0 => 'Draft', 1 => 'Opened', 2 => 'Closed');
352 
353  global $conf;
354 
355  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
356  $this->fields['rowid']['visible'] = 0;
357  }
358 
359  if (empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
360  $this->fields['fk_opp_status']['enabled'] = 0;
361  $this->fields['opp_percent']['enabled'] = 0;
362  $this->fields['opp_amount']['enabled'] = 0;
363  $this->fields['usage_opportunity']['enabled'] = 0;
364  }
365 
366  if (!empty($conf->global->PROJECT_HIDE_TASKS)) {
367  $this->fields['usage_bill_time']['visible'] = 0;
368  $this->fields['usage_task']['visible'] = 0;
369  }
370 
371  if (empty($conf->eventorganization->enabled)) {
372  $this->fields['usage_organize_event']['visible'] = 0;
373  $this->fields['accept_conference_suggestions']['enabled'] = 0;
374  $this->fields['accept_booth_suggestions']['enabled'] = 0;
375  $this->fields['price_registration']['enabled'] = 0;
376  $this->fields['price_booth']['enabled'] = 0;
377  $this->fields['max_attendees']['enabled'] = 0;
378  }
379  }
380 
388  public function create($user, $notrigger = 0)
389  {
390  global $conf, $langs;
391 
392  $error = 0;
393  $ret = 0;
394 
395  $now = dol_now();
396 
397  // Clean parameters
398  $this->note_private = dol_substr($this->note_private, 0, 65535);
399  $this->note_public = dol_substr($this->note_public, 0, 65535);
400 
401  // Check parameters
402  if (!trim($this->ref)) {
403  $this->error = 'ErrorFieldsRequired';
404  dol_syslog(get_class($this)."::create error -1 ref null", LOG_ERR);
405  return -1;
406  }
407  if (!empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) && !($this->socid > 0)) {
408  $this->error = 'ErrorFieldsRequired';
409  dol_syslog(get_class($this)."::create error -1 thirdparty not defined and option PROJECT_THIRDPARTY_REQUIRED is set", LOG_ERR);
410  return -1;
411  }
412 
413  // Create project
414  $this->db->begin();
415 
416  $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (";
417  $sql .= "ref";
418  $sql .= ", title";
419  $sql .= ", description";
420  $sql .= ", fk_soc";
421  $sql .= ", fk_user_creat";
422  $sql .= ", fk_statut";
423  $sql .= ", fk_opp_status";
424  $sql .= ", opp_percent";
425  $sql .= ", public";
426  $sql .= ", datec";
427  $sql .= ", dateo";
428  $sql .= ", datee";
429  $sql .= ", opp_amount";
430  $sql .= ", budget_amount";
431  $sql .= ", usage_opportunity";
432  $sql .= ", usage_task";
433  $sql .= ", usage_bill_time";
434  $sql .= ", usage_organize_event";
435  $sql .= ", accept_conference_suggestions";
436  $sql .= ", accept_booth_suggestions";
437  $sql .= ", price_registration";
438  $sql .= ", price_booth";
439  $sql .= ", max_attendees";
440  $sql .= ", date_start_event";
441  $sql .= ", date_end_event";
442  $sql .= ", location";
443  $sql .= ", email_msgid";
444  $sql .= ", note_private";
445  $sql .= ", note_public";
446  $sql .= ", entity";
447  $sql .= ", ip";
448  $sql .= ") VALUES (";
449  $sql .= "'".$this->db->escape($this->ref)."'";
450  $sql .= ", '".$this->db->escape($this->title)."'";
451  $sql .= ", '".$this->db->escape($this->description)."'";
452  $sql .= ", ".($this->socid > 0 ? $this->socid : "null");
453  $sql .= ", ".((int) $user->id);
454  $sql .= ", ".(is_numeric($this->statut) ? ((int) $this->statut) : '0');
455  $sql .= ", ".((is_numeric($this->opp_status) && $this->opp_status > 0) ? ((int) $this->opp_status) : 'NULL');
456  $sql .= ", ".(is_numeric($this->opp_percent) ? ((int) $this->opp_percent) : 'NULL');
457  $sql .= ", ".($this->public ? 1 : 0);
458  $sql .= ", '".$this->db->idate($now)."'";
459  $sql .= ", ".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : 'null');
460  $sql .= ", ".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : 'null');
461  $sql .= ", ".(strcmp($this->opp_amount, '') ? price2num($this->opp_amount) : 'null');
462  $sql .= ", ".(strcmp($this->budget_amount, '') ? price2num($this->budget_amount) : 'null');
463  $sql .= ", ".($this->usage_opportunity ? 1 : 0);
464  $sql .= ", ".($this->usage_task ? 1 : 0);
465  $sql .= ", ".($this->usage_bill_time ? 1 : 0);
466  $sql .= ", ".($this->usage_organize_event ? 1 : 0);
467  $sql .= ", ".($this->accept_conference_suggestions ? 1 : 0);
468  $sql .= ", ".($this->accept_booth_suggestions ? 1 : 0);
469  $sql .= ", ".(strcmp($this->price_registration, '') ? price2num($this->price_registration) : 'null');
470  $sql .= ", ".(strcmp($this->price_booth, '') ? price2num($this->price_booth) : 'null');
471  $sql .= ", ".(strcmp($this->max_attendees, '') ? ((int) $this->max_attendees) : 'null');
472  $sql .= ", ".($this->date_start_event != '' ? "'".$this->db->idate($this->date_start_event)."'" : 'null');
473  $sql .= ", ".($this->date_end_event != '' ? "'".$this->db->idate($this->date_end_event)."'" : 'null');
474  $sql .= ", ".($this->location ? "'".$this->db->escape($this->location)."'" : 'null');
475  $sql .= ", ".($this->email_msgid ? "'".$this->db->escape($this->email_msgid)."'" : 'null');
476  $sql .= ", ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : 'null');
477  $sql .= ", ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : 'null');
478  $sql .= ", ".((int) $conf->entity);
479  $sql .= ", ".(!isset($this->ip) ? 'NULL' : "'".$this->db->escape($this->ip)."'");
480  $sql .= ")";
481 
482  dol_syslog(get_class($this)."::create", LOG_DEBUG);
483  $resql = $this->db->query($sql);
484  if ($resql) {
485  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
486  $ret = $this->id;
487 
488  if (!$notrigger) {
489  // Call trigger
490  $result = $this->call_trigger('PROJECT_CREATE', $user);
491  if ($result < 0) {
492  $error++;
493  }
494  // End call triggers
495  }
496  } else {
497  $this->error = $this->db->lasterror();
498  $this->errno = $this->db->lasterrno();
499  $error++;
500  }
501 
502  // Update extrafield
503  if (!$error) {
504  $result = $this->insertExtraFields();
505  if ($result < 0) {
506  $error++;
507  }
508  }
509 
510  if (!$error && (getDolGlobalString('MAIN_DISABLEDRAFTSTATUS') || getDolGlobalString('MAIN_DISABLEDRAFTSTATUS_PROJECT'))) {
511  $res = $this->setValid($user);
512  if ($res < 0) {
513  $error++;
514  }
515  }
516 
517  if (!$error) {
518  $this->db->commit();
519  return $ret;
520  } else {
521  $this->db->rollback();
522  return -1;
523  }
524  }
525 
533  public function update($user, $notrigger = 0)
534  {
535  global $langs, $conf;
536 
537  $error = 0;
538 
539  // Clean parameters
540  $this->title = trim($this->title);
541  $this->description = trim($this->description);
542  if ($this->opp_amount < 0) {
543  $this->opp_amount = '';
544  }
545  if ($this->opp_percent < 0) {
546  $this->opp_percent = '';
547  }
548  if ($this->date_end && $this->date_end < $this->date_start) {
549  $this->error = $langs->trans("ErrorDateEndLowerThanDateStart");
550  $this->errors[] = $this->error;
551  $this->db->rollback();
552  dol_syslog(get_class($this)."::update error -3 ".$this->error, LOG_ERR);
553  return -3;
554  }
555 
556  $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
557 
558  if (dol_strlen(trim($this->ref)) > 0) {
559  $this->db->begin();
560 
561  $sql = "UPDATE ".MAIN_DB_PREFIX."projet SET";
562  $sql .= " ref='".$this->db->escape($this->ref)."'";
563  $sql .= ", title = '".$this->db->escape($this->title)."'";
564  $sql .= ", description = '".$this->db->escape($this->description)."'";
565  $sql .= ", fk_soc = ".($this->socid > 0 ? $this->socid : "null");
566  $sql .= ", fk_statut = ".((int) $this->statut);
567  $sql .= ", fk_opp_status = ".((is_numeric($this->opp_status) && $this->opp_status > 0) ? $this->opp_status : 'null');
568  $sql .= ", opp_percent = ".((is_numeric($this->opp_percent) && $this->opp_percent != '') ? $this->opp_percent : 'null');
569  $sql .= ", public = ".($this->public ? 1 : 0);
570  $sql .= ", datec = ".($this->date_c != '' ? "'".$this->db->idate($this->date_c)."'" : 'null');
571  $sql .= ", dateo = ".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : 'null');
572  $sql .= ", datee = ".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : 'null');
573  $sql .= ", date_close = ".($this->date_close != '' ? "'".$this->db->idate($this->date_close)."'" : 'null');
574  $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
575  $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
576  $sql .= ", fk_user_close = ".($this->fk_user_close > 0 ? $this->fk_user_close : "null");
577  $sql .= ", opp_amount = ".(strcmp($this->opp_amount, '') ? price2num($this->opp_amount) : "null");
578  $sql .= ", budget_amount = ".(strcmp($this->budget_amount, '') ? price2num($this->budget_amount) : "null");
579  $sql .= ", fk_user_modif = ".$user->id;
580  $sql .= ", usage_opportunity = ".($this->usage_opportunity ? 1 : 0);
581  $sql .= ", usage_task = ".($this->usage_task ? 1 : 0);
582  $sql .= ", usage_bill_time = ".($this->usage_bill_time ? 1 : 0);
583  $sql .= ", usage_organize_event = ".($this->usage_organize_event ? 1 : 0);
584  $sql .= ", accept_conference_suggestions = ".($this->accept_conference_suggestions ? 1 : 0);
585  $sql .= ", accept_booth_suggestions = ".($this->accept_booth_suggestions ? 1 : 0);
586  $sql .= ", price_registration = ".(strcmp($this->price_registration, '') ? price2num($this->price_registration) : "null");
587  $sql .= ", price_booth = ".(strcmp($this->price_booth, '') ? price2num($this->price_booth) : "null");
588  $sql .= ", max_attendees = ".(strcmp($this->max_attendees, '') ? price2num($this->max_attendees) : "null");
589  $sql .= ", date_start_event = ".($this->date_start_event != '' ? "'".$this->db->idate($this->date_start_event)."'" : 'null');
590  $sql .= ", date_end_event = ".($this->date_end_event != '' ? "'".$this->db->idate($this->date_end_event)."'" : 'null');
591  $sql .= ", location = '".$this->db->escape($this->location)."'";
592  $sql .= ", entity = ".((int) $this->entity);
593  $sql .= " WHERE rowid = ".((int) $this->id);
594 
595  dol_syslog(get_class($this)."::update", LOG_DEBUG);
596  $resql = $this->db->query($sql);
597  if ($resql) {
598  // Update extrafield
599  if (!$error) {
600  $result = $this->insertExtraFields();
601  if ($result < 0) {
602  $error++;
603  }
604  }
605 
606  if (!$error && !$notrigger) {
607  // Call trigger
608  $result = $this->call_trigger('PROJECT_MODIFY', $user);
609  if ($result < 0) {
610  $error++;
611  }
612  // End call triggers
613  }
614 
615  if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
616  // We remove directory
617  if ($conf->project->dir_output) {
618  $olddir = $conf->project->dir_output."/".dol_sanitizeFileName($this->oldcopy->ref);
619  $newdir = $conf->project->dir_output."/".dol_sanitizeFileName($this->ref);
620  if (file_exists($olddir)) {
621  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
622  $res = @rename($olddir, $newdir);
623  if (!$res) {
624  $langs->load("errors");
625  $this->error = $langs->trans('ErrorFailToRenameDir', $olddir, $newdir);
626  $error++;
627  }
628  }
629  }
630  }
631  if (!$error) {
632  $this->db->commit();
633  $result = 1;
634  } else {
635  $this->db->rollback();
636  $result = -1;
637  }
638  } else {
639  $this->error = $this->db->lasterror();
640  $this->errors[] = $this->error;
641  $this->db->rollback();
642  if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
643  $result = -4;
644  } else {
645  $result = -2;
646  }
647  dol_syslog(get_class($this)."::update error ".$result." ".$this->error, LOG_ERR);
648  }
649  } else {
650  dol_syslog(get_class($this)."::update ref null");
651  $result = -1;
652  }
653 
654  return $result;
655  }
656 
666  public function fetch($id, $ref = '', $ref_ext = '', $email_msgid = '')
667  {
668  if (empty($id) && empty($ref) && empty($ref_ext) && empty($email_msgid)) {
669  dol_syslog(get_class($this)."::fetch Bad parameters", LOG_WARNING);
670  return -1;
671  }
672 
673  $sql = "SELECT rowid, entity, ref, title, description, public, datec, opp_amount, budget_amount,";
674  $sql .= " tms, dateo as date_start, datee as date_end, date_close, fk_soc, fk_user_creat, fk_user_modif, fk_user_close, fk_statut as status, fk_opp_status, opp_percent,";
675  $sql .= " note_private, note_public, model_pdf, usage_opportunity, usage_task, usage_bill_time, usage_organize_event, email_msgid,";
676  $sql .= " accept_conference_suggestions, accept_booth_suggestions, price_registration, price_booth, max_attendees, date_start_event, date_end_event, location, extraparams";
677  $sql .= " FROM ".MAIN_DB_PREFIX."projet";
678  if (!empty($id)) {
679  $sql .= " WHERE rowid = ".((int) $id);
680  } else {
681  $sql .= " WHERE entity IN (".getEntity('project').")";
682  if (!empty($ref)) {
683  $sql .= " AND ref = '".$this->db->escape($ref)."'";
684  } elseif (!empty($ref_ext)) {
685  $sql .= " AND ref_ext = '".$this->db->escape($ref_ext)."'";
686  } else {
687  $sql .= " AND email_msgid = '".$this->db->escape($email_msgid)."'";
688  }
689  }
690 
691  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
692  $resql = $this->db->query($sql);
693  if ($resql) {
694  $num_rows = $this->db->num_rows($resql);
695 
696  if ($num_rows) {
697  $obj = $this->db->fetch_object($resql);
698 
699  $this->id = $obj->rowid;
700  $this->entity = $obj->entity;
701  $this->ref = $obj->ref;
702  $this->title = $obj->title;
703  $this->description = $obj->description;
704  $this->date_c = $this->db->jdate($obj->datec);
705  $this->datec = $this->db->jdate($obj->datec); // TODO deprecated
706  $this->date_m = $this->db->jdate($obj->tms);
707  $this->datem = $this->db->jdate($obj->tms); // TODO deprecated
708  $this->date_start = $this->db->jdate($obj->date_start);
709  $this->date_end = $this->db->jdate($obj->date_end);
710  $this->date_close = $this->db->jdate($obj->date_close);
711  $this->note_private = $obj->note_private;
712  $this->note_public = $obj->note_public;
713  $this->socid = $obj->fk_soc;
714  $this->user_author_id = $obj->fk_user_creat;
715  $this->user_modification_id = $obj->fk_user_modif;
716  $this->user_close_id = $obj->fk_user_close;
717  $this->public = $obj->public;
718  $this->statut = $obj->status; // deprecated
719  $this->status = $obj->status;
720  $this->opp_status = $obj->fk_opp_status;
721  $this->opp_amount = $obj->opp_amount;
722  $this->opp_percent = $obj->opp_percent;
723  $this->budget_amount = $obj->budget_amount;
724  $this->model_pdf = $obj->model_pdf;
725  $this->modelpdf = $obj->model_pdf; // deprecated
726  $this->usage_opportunity = (int) $obj->usage_opportunity;
727  $this->usage_task = (int) $obj->usage_task;
728  $this->usage_bill_time = (int) $obj->usage_bill_time;
729  $this->usage_organize_event = (int) $obj->usage_organize_event;
730  $this->accept_conference_suggestions = (int) $obj->accept_conference_suggestions;
731  $this->accept_booth_suggestions = (int) $obj->accept_booth_suggestions;
732  $this->price_registration = $obj->price_registration;
733  $this->price_booth = $obj->price_booth;
734  $this->max_attendees = $obj->max_attendees;
735  $this->date_start_event = $this->db->jdate($obj->date_start_event);
736  $this->date_end_event = $this->db->jdate($obj->date_end_event);
737  $this->location = $obj->location;
738  $this->email_msgid = $obj->email_msgid;
739  $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams, true) : array();
740 
741  $this->db->free($resql);
742 
743  // Retrieve all extrafield
744  // fetch optionals attributes and labels
745  $this->fetch_optionals();
746 
747  return 1;
748  }
749 
750  $this->db->free($resql);
751 
752  return 0;
753  } else {
754  $this->error = $this->db->lasterror();
755  $this->errors[] = $this->db->lasterror();
756  return -1;
757  }
758  }
759 
760  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
772  public function get_element_list($type, $tablename, $datefieldname = '', $date_start = '', $date_end = '', $projectkey = 'fk_projet')
773  {
774  // phpcs:enable
775 
776  global $hookmanager;
777 
778  $elements = array();
779 
780  if ($this->id <= 0) {
781  return $elements;
782  }
783 
784  $ids = $this->id;
785 
786  if ($type == 'agenda') {
787  $sql = "SELECT id as rowid FROM ".MAIN_DB_PREFIX."actioncomm WHERE fk_project IN (".$this->db->sanitize($ids).") AND entity IN (".getEntity('agenda').")";
788  } elseif ($type == 'expensereport') {
789  $sql = "SELECT ed.rowid FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."expensereport_det as ed WHERE e.rowid = ed.fk_expensereport AND e.entity IN (".getEntity('expensereport').") AND ed.fk_projet IN (".$this->db->sanitize($ids).")";
790  } elseif ($type == 'project_task') {
791  $sql = "SELECT DISTINCT pt.rowid FROM ".MAIN_DB_PREFIX."projet_task as pt WHERE pt.fk_projet IN (".$this->db->sanitize($ids).")";
792  } elseif ($type == 'element_time') { // Case we want to duplicate line foreach user
793  $sql = "SELECT DISTINCT pt.rowid, ptt.fk_user FROM ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."element_time as ptt WHERE pt.rowid = ptt.fk_element AND ptt.elementtype = 'task' AND pt.fk_projet IN (".$this->db->sanitize($ids).")";
794  } elseif ($type == 'stock_mouvement') {
795  $sql = "SELECT ms.rowid, ms.fk_user_author as fk_user FROM ".MAIN_DB_PREFIX."stock_mouvement as ms, ".MAIN_DB_PREFIX."entrepot as e WHERE e.rowid = ms.fk_entrepot AND e.entity IN (".getEntity('stock').") AND ms.origintype = 'project' AND ms.fk_origin IN (".$this->db->sanitize($ids).") AND ms.type_mouvement = 1";
796  } elseif ($type == 'loan') {
797  $sql = "SELECT l.rowid, l.fk_user_author as fk_user FROM ".MAIN_DB_PREFIX."loan as l WHERE l.entity IN (".getEntity('loan').") AND l.fk_projet IN (".$this->db->sanitize($ids).")";
798  } else {
799  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$tablename." WHERE ".$projectkey." IN (".$this->db->sanitize($ids).") AND entity IN (".getEntity($type).")";
800  }
801 
802  if ($date_start > 0 && $type == 'loan') {
803  $sql .= " AND (dateend > '".$this->db->idate($date_start)."' OR dateend IS NULL)";
804  } elseif ($date_start > 0 && ($type != 'project_task')) { // For table project_taks, we want the filter on date apply on project_time_spent table
805  if (empty($datefieldname) && !empty($this->table_element_date)) {
806  $datefieldname = $this->table_element_date;
807  }
808  if (empty($datefieldname)) {
809  return 'Error this object has no date field defined';
810  }
811  $sql .= " AND (".$datefieldname." >= '".$this->db->idate($date_start)."' OR ".$datefieldname." IS NULL)";
812  }
813 
814  if ($date_end > 0 && $type == 'loan') {
815  $sql .= " AND (datestart < '".$this->db->idate($date_end)."' OR datestart IS NULL)";
816  } elseif ($date_end > 0 && ($type != 'project_task')) { // For table project_taks, we want the filter on date apply on project_time_spent table
817  if (empty($datefieldname) && !empty($this->table_element_date)) {
818  $datefieldname = $this->table_element_date;
819  }
820  if (empty($datefieldname)) {
821  return 'Error this object has no date field defined';
822  }
823  $sql .= " AND (".$datefieldname." <= '".$this->db->idate($date_end)."' OR ".$datefieldname." IS NULL)";
824  }
825 
826  $parameters = array(
827  'sql'=>$sql,
828  'type' => $type,
829  'tablename' => $tablename,
830  'datefieldname' => $datefieldname,
831  'dates' => $date_start,
832  'datee' => $date_end,
833  'fk_projet' => $projectkey,
834  'ids' => $ids,
835  );
836  $reshook = $hookmanager->executeHooks('getElementList', $parameters);
837  if ($reshook > 0) {
838  $sql = $hookmanager->resPrint;
839  } else {
840  $sql .= $hookmanager->resPrint;
841  }
842 
843  if (!$sql) {
844  return -1;
845  }
846 
847  //print $sql;
848  dol_syslog(get_class($this)."::get_element_list", LOG_DEBUG);
849  $result = $this->db->query($sql);
850  if ($result) {
851  $nump = $this->db->num_rows($result);
852  if ($nump) {
853  $i = 0;
854  while ($i < $nump) {
855  $obj = $this->db->fetch_object($result);
856 
857  $elements[$i] = $obj->rowid.(empty($obj->fk_user) ? '' : '_'.$obj->fk_user);
858 
859  $i++;
860  }
861  $this->db->free($result);
862  }
863 
864  /* Return array even if empty*/
865  return $elements;
866  } else {
867  dol_print_error($this->db);
868  }
869  }
870 
878  public function delete($user, $notrigger = 0)
879  {
880  global $langs, $conf;
881  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
882 
883  $error = 0;
884 
885  $this->db->begin();
886 
887  if (!$error) {
888  // Delete linked contacts
889  $res = $this->delete_linked_contact();
890  if ($res < 0) {
891  $this->error = 'ErrorFailToDeleteLinkedContact';
892  //$error++;
893  $this->db->rollback();
894  return 0;
895  }
896  }
897 
898  // Set fk_projet into elements to null
899  $listoftables = array(
900  'propal'=>'fk_projet', 'commande'=>'fk_projet', 'facture'=>'fk_projet',
901  'supplier_proposal'=>'fk_projet', 'commande_fournisseur'=>'fk_projet', 'facture_fourn'=>'fk_projet',
902  'expensereport_det'=>'fk_projet', 'contrat'=>'fk_projet',
903  'fichinter'=>'fk_projet',
904  'don'=>array('field'=>'fk_projet', 'module'=>'don'),
905  'actioncomm'=>'fk_project',
906  'mrp_mo'=>'fk_project',
907  'entrepot'=>'fk_project'
908  );
909  foreach ($listoftables as $key => $value) {
910  if (is_array($value)) {
911  if (!isModEnabled($value['module'])) {
912  continue;
913  }
914  $fieldname = $value['field'];
915  } else {
916  $fieldname = $value;
917  }
918  $sql = "UPDATE ".MAIN_DB_PREFIX.$key." SET ".$fieldname." = NULL where ".$fieldname." = ".((int) $this->id);
919 
920  $resql = $this->db->query($sql);
921  if (!$resql) {
922  $this->errors[] = $this->db->lasterror();
923  $error++;
924  break;
925  }
926  }
927 
928  // Remove linked categories.
929  if (!$error) {
930  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_project";
931  $sql .= " WHERE fk_project = ".((int) $this->id);
932 
933  $result = $this->db->query($sql);
934  if (!$result) {
935  $error++;
936  $this->errors[] = $this->db->lasterror();
937  }
938  }
939 
940  // Fetch tasks
941  $this->getLinesArray($user, 0);
942 
943  // Delete tasks
944  $ret = $this->deleteTasks($user);
945  if ($ret < 0) {
946  $error++;
947  }
948 
949 
950  // Delete all child tables
951  if (!$error) {
952  $elements = array('categorie_project'); // elements to delete. TODO Make goodway to delete
953  foreach ($elements as $table) {
954  if (!$error) {
955  $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
956  $sql .= " WHERE fk_project = ".((int) $this->id);
957 
958  $result = $this->db->query($sql);
959  if (!$result) {
960  $error++;
961  $this->errors[] = $this->db->lasterror();
962  }
963  }
964  }
965  }
966 
967  if (!$error) {
968  $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_extrafields";
969  $sql .= " WHERE fk_object = ".((int) $this->id);
970 
971  $resql = $this->db->query($sql);
972  if (!$resql) {
973  $this->errors[] = $this->db->lasterror();
974  $error++;
975  }
976  }
977 
978  // Delete project
979  if (!$error) {
980  $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet";
981  $sql .= " WHERE rowid=".((int) $this->id);
982 
983  $resql = $this->db->query($sql);
984  if (!$resql) {
985  $this->errors[] = $langs->trans("CantRemoveProject", $langs->transnoentitiesnoconv("ProjectOverview"));
986  $error++;
987  }
988  }
989 
990 
991 
992  if (empty($error)) {
993  // We remove directory
994  $projectref = dol_sanitizeFileName($this->ref);
995  if ($conf->project->dir_output) {
996  $dir = $conf->project->dir_output."/".$projectref;
997  if (file_exists($dir)) {
998  $res = @dol_delete_dir_recursive($dir);
999  if (!$res) {
1000  $this->errors[] = 'ErrorFailToDeleteDir';
1001  $error++;
1002  }
1003  }
1004  }
1005 
1006  if (!$notrigger) {
1007  // Call trigger
1008  $result = $this->call_trigger('PROJECT_DELETE', $user);
1009 
1010  if ($result < 0) {
1011  $error++;
1012  }
1013  // End call triggers
1014  }
1015  }
1016 
1017  if (empty($error)) {
1018  $this->db->commit();
1019  return 1;
1020  } else {
1021  foreach ($this->errors as $errmsg) {
1022  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
1023  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1024  }
1025  dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
1026  $this->db->rollback();
1027  return -1;
1028  }
1029  }
1030 
1039  public function getElementCount($type, $tablename, $projectkey = 'fk_projet')
1040  {
1041  if ($this->id <= 0) {
1042  return 0;
1043  }
1044 
1045  if ($type == 'agenda') {
1046  $sql = "SELECT COUNT(id) as nb FROM ".MAIN_DB_PREFIX."actioncomm WHERE fk_project = ".((int) $this->id)." AND entity IN (".getEntity('agenda').")";
1047  } elseif ($type == 'expensereport') {
1048  $sql = "SELECT COUNT(ed.rowid) as nb FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."expensereport_det as ed WHERE e.rowid = ed.fk_expensereport AND e.entity IN (".getEntity('expensereport').") AND ed.fk_projet = ".((int) $this->id);
1049  } elseif ($type == 'project_task') {
1050  $sql = "SELECT DISTINCT COUNT(pt.rowid) as nb FROM ".MAIN_DB_PREFIX."projet_task as pt WHERE pt.fk_projet = ".((int) $this->id);
1051  } elseif ($type == 'element_time') { // Case we want to duplicate line foreach user
1052  $sql = "SELECT DISTINCT COUNT(pt.rowid) as nb FROM ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."element_time as ptt WHERE pt.rowid = ptt.fk_element AND ptt.elementtype = 'task' AND pt.fk_projet = ".((int) $this->id);
1053  } elseif ($type == 'stock_mouvement') {
1054  $sql = "SELECT COUNT(ms.rowid) as nb FROM ".MAIN_DB_PREFIX."stock_mouvement as ms, ".MAIN_DB_PREFIX."entrepot as e WHERE e.rowid = ms.fk_entrepot AND e.entity IN (".getEntity('stock').") AND ms.origintype = 'project' AND ms.fk_origin = ".((int) $this->id)." AND ms.type_mouvement = 1";
1055  } elseif ($type == 'loan') {
1056  $sql = "SELECT COUNT(l.rowid) as nb FROM ".MAIN_DB_PREFIX."loan as l WHERE l.entity IN (".getEntity('loan').") AND l.fk_projet = ".((int) $this->id);
1057  } else {
1058  $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.$tablename." WHERE ".$projectkey." = ".((int) $this->id)." AND entity IN (".getEntity($type).")";
1059  }
1060 
1061  $result = $this->db->query($sql);
1062 
1063  if (!$result) {
1064  return 0;
1065  }
1066 
1067  $obj = $this->db->fetch_object($result);
1068 
1069  $this->db->free($result);
1070 
1071  return $obj->nb;
1072  }
1073 
1080  public function deleteTasks($user)
1081  {
1082  $countTasks = count($this->lines);
1083  $deleted = false;
1084  if ($countTasks) {
1085  foreach ($this->lines as $task) {
1086  if ($task->hasChildren() <= 0) { // If there is no children (or error to detect them)
1087  $deleted = true;
1088  $ret = $task->delete($user);
1089  if ($ret <= 0) {
1090  $this->errors[] = $this->db->lasterror();
1091  return -1;
1092  }
1093  }
1094  }
1095  }
1096  $this->getLinesArray($user);
1097  if ($deleted && count($this->lines) < $countTasks) {
1098  if (count($this->lines)) {
1099  $this->deleteTasks($this->lines);
1100  }
1101  }
1102 
1103  return 1;
1104  }
1105 
1113  public function setValid($user, $notrigger = 0)
1114  {
1115  global $langs, $conf;
1116 
1117  $error = 0;
1118 
1119  // Protection
1120  if ($this->status == self::STATUS_VALIDATED) {
1121  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
1122  return 0;
1123  }
1124 
1125  // Check parameters
1126  if (preg_match('/^'.preg_quote($langs->trans("CopyOf").' ').'/', $this->title)) {
1127  $this->error = $langs->trans("ErrorFieldFormat", $langs->transnoentities("Label")).'. '.$langs->trans('RemoveString', $langs->transnoentitiesnoconv("CopyOf"));
1128  return -1;
1129  }
1130 
1131  $this->db->begin();
1132 
1133  $sql = "UPDATE ".MAIN_DB_PREFIX."projet";
1134  $sql .= " SET fk_statut = ".self::STATUS_VALIDATED;
1135  $sql .= " WHERE rowid = ".((int) $this->id);
1136  //$sql .= " AND entity = ".((int) $conf->entity); // Disabled, when we use the ID for the where, we must not add any other search condition
1137 
1138  dol_syslog(get_class($this)."::setValid", LOG_DEBUG);
1139  $resql = $this->db->query($sql);
1140  if ($resql) {
1141  // Call trigger
1142  if (empty($notrigger)) {
1143  $result = $this->call_trigger('PROJECT_VALIDATE', $user);
1144  if ($result < 0) {
1145  $error++;
1146  }
1147  // End call triggers
1148  }
1149 
1150  if (!$error) {
1151  $this->statut = 1;
1152  $this->db->commit();
1153  return 1;
1154  } else {
1155  $this->db->rollback();
1156  $this->error = join(',', $this->errors);
1157  dol_syslog(get_class($this)."::setValid ".$this->error, LOG_ERR);
1158  return -1;
1159  }
1160  } else {
1161  $this->db->rollback();
1162  $this->error = $this->db->lasterror();
1163  return -1;
1164  }
1165  }
1166 
1173  public function setClose($user)
1174  {
1175  global $langs, $conf;
1176 
1177  $now = dol_now();
1178 
1179  $error = 0;
1180 
1181  if ($this->statut != self::STATUS_CLOSED) {
1182  $this->db->begin();
1183 
1184  $sql = "UPDATE ".MAIN_DB_PREFIX."projet";
1185  $sql .= " SET fk_statut = ".self::STATUS_CLOSED.", fk_user_close = ".((int) $user->id).", date_close = '".$this->db->idate($now)."'";
1186  $sql .= " WHERE rowid = ".((int) $this->id);
1187  $sql .= " AND fk_statut = ".self::STATUS_VALIDATED;
1188 
1189  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
1190  // TODO What to do if fk_opp_status is not code 'WON' or 'LOST'
1191  }
1192 
1193  dol_syslog(get_class($this)."::setClose", LOG_DEBUG);
1194  $resql = $this->db->query($sql);
1195  if ($resql) {
1196  // Call trigger
1197  $result = $this->call_trigger('PROJECT_CLOSE', $user);
1198  if ($result < 0) {
1199  $error++;
1200  }
1201  // End call triggers
1202 
1203  if (!$error) {
1204  $this->statut = 2;
1205  $this->db->commit();
1206  return 1;
1207  } else {
1208  $this->db->rollback();
1209  $this->error = join(',', $this->errors);
1210  dol_syslog(get_class($this)."::setClose ".$this->error, LOG_ERR);
1211  return -1;
1212  }
1213  } else {
1214  $this->db->rollback();
1215  $this->error = $this->db->lasterror();
1216  return -1;
1217  }
1218  }
1219 
1220  return 0;
1221  }
1222 
1229  public function getLibStatut($mode = 0)
1230  {
1231  return $this->LibStatut(isset($this->statut) ? $this->statut : $this->status, $mode);
1232  }
1233 
1234  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1242  public function LibStatut($status, $mode = 0)
1243  {
1244  // phpcs:enable
1245  global $langs;
1246 
1247  $statustrans = array(
1248  0 => 'status0',
1249  1 => 'status4',
1250  2 => 'status6',
1251  );
1252 
1253  $statusClass = 'status0';
1254  if (!empty($statustrans[$status])) {
1255  $statusClass = $statustrans[$status];
1256  }
1257 
1258  return dolGetStatus($langs->transnoentitiesnoconv($this->statuts_long[$status]), $langs->transnoentitiesnoconv($this->statuts_short[$status]), '', $statusClass, $mode);
1259  }
1260 
1268  public function getTooltipContentArray($params)
1269  {
1270  global $conf, $langs;
1271 
1272  $langs->load('projects');
1273  $option = $params['option'] ?? '';
1274  $moreinpopup = $params['morinpopup'] ?? '';
1275 
1276  $datas = [];
1277  if ($option != 'nolink') {
1278  $datas['picto'] = img_picto('', $this->picto, 'class="pictofixedwidth"').' <u class="paddingrightonly">'.$langs->trans("Project").'</u>';
1279  }
1280  if (isset($this->status)) {
1281  $datas['picto'] .= ' '.$this->getLibStatut(5);
1282  }
1283  $datas['ref'] = (isset($datas['picto']) ? '<br>' : '').'<b>'.$langs->trans('Ref').': </b>'.$this->ref; // The space must be after the : to not being explode when showing the title in img_picto
1284  $datas['label'] = '<br><b>'.$langs->trans('Label').': </b>'.$this->title; // The space must be after the : to not being explode when showing the title in img_picto
1285  if (isset($this->public)) {
1286  $datas['visibility'] = '<br><b>'.$langs->trans("Visibility").":</b> ";
1287  $datas['visibility'] .= ($this->public ? img_picto($langs->trans('SharedProject'), 'world', 'class="pictofixedwidth"').$langs->trans("SharedProject") : img_picto($langs->trans('PrivateProject'), 'private', 'class="pictofixedwidth"').$langs->trans("PrivateProject"));
1288  }
1289  if (!empty($this->thirdparty_name)) {
1290  $datas['thirdparty'] = '<br><b>'.$langs->trans('ThirdParty').': </b>'.$this->thirdparty_name; // The space must be after the : to not being explode when showing the title in img_picto
1291  }
1292  if (!empty($this->date_start)) {
1293  $datas['datestart'] = '<br><b>'.$langs->trans('DateStart').': </b>'.dol_print_date($this->date_start, 'day'); // The space must be after the : to not being explode when showing the title in img_picto
1294  }
1295  if (!empty($this->date_end)) {
1296  $datas['dateend'] = '<br><b>'.$langs->trans('DateEnd').': </b>'.dol_print_date($this->date_end, 'day'); // The space must be after the : to not being explode when showing the title in img_picto
1297  }
1298  if ($moreinpopup) {
1299  $datas['moreinpopup'] = '<br>'.$moreinpopup;
1300  }
1301 
1302  return $datas;
1303  }
1304 
1318  public function getNomUrl($withpicto = 0, $option = '', $addlabel = 0, $moreinpopup = '', $sep = ' - ', $notooltip = 0, $save_lastsearch_value = -1, $morecss = '')
1319  {
1320  global $conf, $langs, $user, $hookmanager;
1321 
1322  if (!empty($conf->dol_no_mouse_hover)) {
1323  $notooltip = 1; // Force disable tooltips
1324  }
1325 
1326  $result = '';
1327  if (!empty($conf->global->PROJECT_OPEN_ALWAYS_ON_TAB)) {
1328  $option = $conf->global->PROJECT_OPEN_ALWAYS_ON_TAB;
1329  }
1330  $params = [
1331  'id' => $this->id,
1332  'objecttype' => $this->element,
1333  'moreinpopup' => $moreinpopup,
1334  'option' => $option,
1335  ];
1336  $classfortooltip = 'classfortooltip';
1337  $dataparams = '';
1338  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1339  $classfortooltip = 'classforajaxtooltip';
1340  $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1341  $label = '';
1342  } else {
1343  $label = implode($this->getTooltipContentArray($params));
1344  }
1345 
1346  $url = '';
1347  if ($option != 'nolink') {
1348  if (preg_match('/\.php$/', $option)) {
1349  $url = dol_buildpath($option, 1).'?id='.$this->id;
1350  } elseif ($option == 'task') {
1351  $url = DOL_URL_ROOT.'/projet/tasks.php?id='.$this->id;
1352  } elseif ($option == 'preview') {
1353  $url = DOL_URL_ROOT.'/projet/element.php?id='.$this->id;
1354  } elseif ($option == 'eventorganization') {
1355  $url = DOL_URL_ROOT.'/eventorganization/conferenceorbooth_list.php?projectid='.$this->id;
1356  } else {
1357  $url = DOL_URL_ROOT.'/projet/card.php?id='.$this->id;
1358  }
1359  // Add param to save lastsearch_values or not
1360  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1361  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1362  $add_save_lastsearch_values = 1;
1363  }
1364  if ($add_save_lastsearch_values) {
1365  $url .= '&save_lastsearch_values=1';
1366  }
1367  }
1368 
1369  $linkclose = '';
1370  if (empty($notooltip) && $user->hasRight('projet', 'lire')) {
1371  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1372  $label = $langs->trans("ShowProject");
1373  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1374  }
1375  $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
1376  $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1377  } else {
1378  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1379  }
1380 
1381  $picto = 'projectpub';
1382  if (!$this->public) {
1383  $picto = 'project';
1384  }
1385 
1386  $linkstart = '<a href="'.$url.'"';
1387  $linkstart .= $linkclose.'>';
1388  $linkend = '</a>';
1389 
1390  $result .= $linkstart;
1391  if ($withpicto) {
1392  $result .= img_object(($notooltip ? '' : $label), $picto, 'class="pictofixedwidth em088"', 0, 0, $notooltip ? 0 : 1);
1393  }
1394  if ($withpicto != 2) {
1395  $result .= $this->ref;
1396  }
1397  $result .= $linkend;
1398  if ($withpicto != 2) {
1399  $result .= (($addlabel && $this->title) ? '<span class="opacitymedium">'.$sep.dol_trunc($this->title, ($addlabel > 1 ? $addlabel : 0)).'</span>' : '');
1400  }
1401 
1402  global $action;
1403  $hookmanager->initHooks(array('projectdao'));
1404  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1405  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1406  if ($reshook > 0) {
1407  $result = $hookmanager->resPrint;
1408  } else {
1409  $result .= $hookmanager->resPrint;
1410  }
1411 
1412  return $result;
1413  }
1414 
1422  public function initAsSpecimen()
1423  {
1424  global $user, $langs, $conf;
1425 
1426  $now = dol_now();
1427 
1428  // Initialise parameters
1429  $this->id = 0;
1430  $this->ref = 'SPECIMEN';
1431  $this->entity = $conf->entity;
1432  $this->specimen = 1;
1433  $this->socid = 1;
1434  $this->date_c = $now;
1435  $this->date_m = $now;
1436  $this->date_start = $now;
1437  $this->date_end = $now + (3600 * 24 * 365);
1438  $this->note_public = 'SPECIMEN';
1439  $this->fk_ele = 20000;
1440  $this->opp_amount = 20000;
1441  $this->budget_amount = 10000;
1442 
1443  $this->usage_opportunity = 1;
1444  $this->usage_task = 1;
1445  $this->usage_bill_time = 1;
1446  $this->usage_organize_event = 1;
1447 
1448  /*
1449  $nbp = mt_rand(1, 9);
1450  $xnbp = 0;
1451  while ($xnbp < $nbp)
1452  {
1453  $line = new Task($this->db);
1454  $line->fk_project = 0;
1455  $line->label = $langs->trans("Label") . " " . $xnbp;
1456  $line->description = $langs->trans("Description") . " " . $xnbp;
1457 
1458  $this->lines[]=$line;
1459  $xnbp++;
1460  }
1461  */
1462  }
1463 
1471  public function restrictedProjectArea(User $user, $mode = 'read')
1472  {
1473  // To verify role of users
1474  $userAccess = 0;
1475  if (($mode == 'read' && !empty($user->rights->projet->all->lire)) || ($mode == 'write' && !empty($user->rights->projet->all->creer)) || ($mode == 'delete' && !empty($user->rights->projet->all->supprimer))) {
1476  $userAccess = 1;
1477  } elseif ($this->public && (($mode == 'read' && !empty($user->rights->projet->lire)) || ($mode == 'write' && !empty($user->rights->projet->creer)) || ($mode == 'delete' && !empty($user->rights->projet->supprimer)))) {
1478  $userAccess = 1;
1479  } else { // No access due to permission to read all projects, so we check if we are a contact of project
1480  foreach (array('internal', 'external') as $source) {
1481  $userRole = $this->liste_contact(4, $source);
1482  $num = count($userRole);
1483 
1484  $nblinks = 0;
1485  while ($nblinks < $num) {
1486  if ($source == 'internal' && $user->id == $userRole[$nblinks]['id']) { // $userRole[$nblinks]['id'] is id of user (llx_user) for internal contacts
1487  if ($mode == 'read' && $user->rights->projet->lire) {
1488  $userAccess++;
1489  }
1490  if ($mode == 'write' && $user->rights->projet->creer) {
1491  $userAccess++;
1492  }
1493  if ($mode == 'delete' && $user->rights->projet->supprimer) {
1494  $userAccess++;
1495  }
1496  }
1497  if ($source == 'external' && $user->socid > 0 && $user->socid == $userRole[$nblinks]['socid']) { // $userRole[$nblinks]['id'] is id of contact (llx_socpeople) or external contacts
1498  if ($mode == 'read' && $user->rights->projet->lire) {
1499  $userAccess++;
1500  }
1501  if ($mode == 'write' && $user->rights->projet->creer) {
1502  $userAccess++;
1503  }
1504  if ($mode == 'delete' && $user->rights->projet->supprimer) {
1505  $userAccess++;
1506  }
1507  }
1508  $nblinks++;
1509  }
1510  }
1511  //if (empty($nblinks)) // If nobody has permission, we grant creator
1512  //{
1513  // if ((!empty($this->user_author_id) && $this->user_author_id == $user->id))
1514  // {
1515  // $userAccess = 1;
1516  // }
1517  //}
1518  }
1519 
1520  return ($userAccess ? $userAccess : -1);
1521  }
1522 
1533  public function getProjectsAuthorizedForUser($user, $mode = 0, $list = 0, $socid = 0, $filter = '')
1534  {
1535  $projects = array();
1536  $temp = array();
1537 
1538  $sql = "SELECT ".(($mode == 0 || $mode == 1) ? "DISTINCT " : "")."p.rowid, p.ref";
1539  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
1540  if ($mode == 0) {
1541  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact as ec ON ec.element_id = p.rowid";
1542  } elseif ($mode == 1) {
1543  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
1544  } elseif ($mode == 2) {
1545  // No filter. Use this if user has permission to see all project
1546  }
1547  $sql .= " WHERE p.entity IN (".getEntity('project').")";
1548  // Internal users must see project he is contact to even if project linked to a third party he can't see.
1549  //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
1550  if ($socid > 0) {
1551  $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
1552  }
1553 
1554  // Get id of types of contacts for projects (This list never contains a lot of elements)
1555  $listofprojectcontacttype = array();
1556  $sql2 = "SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
1557  $sql2 .= " WHERE ctc.element = '".$this->db->escape($this->element)."'";
1558  $sql2 .= " AND ctc.source = 'internal'";
1559  $resql = $this->db->query($sql2);
1560  if ($resql) {
1561  while ($obj = $this->db->fetch_object($resql)) {
1562  $listofprojectcontacttype[$obj->rowid] = $obj->code;
1563  }
1564  } else {
1565  dol_print_error($this->db);
1566  }
1567  if (count($listofprojectcontacttype) == 0) {
1568  $listofprojectcontacttype[0] = '0'; // To avoid syntax error if not found
1569  }
1570 
1571  if ($mode == 0) {
1572  $sql .= " AND ( p.public = 1";
1573  $sql .= " OR ( ec.fk_c_type_contact IN (".$this->db->sanitize(join(',', array_keys($listofprojectcontacttype))).")";
1574  $sql .= " AND ec.fk_socpeople = ".((int) $user->id).")";
1575  $sql .= " )";
1576  } elseif ($mode == 1) {
1577  $sql .= " AND ec.element_id = p.rowid";
1578  $sql .= " AND (";
1579  $sql .= " ( ec.fk_c_type_contact IN (".$this->db->sanitize(join(',', array_keys($listofprojectcontacttype))).")";
1580  $sql .= " AND ec.fk_socpeople = ".((int) $user->id).")";
1581  $sql .= " )";
1582  } elseif ($mode == 2) {
1583  // No filter. Use this if user has permission to see all project
1584  }
1585 
1586  $sql .= $filter;
1587  //print $sql;
1588 
1589  $resql = $this->db->query($sql);
1590  if ($resql) {
1591  $num = $this->db->num_rows($resql);
1592  $i = 0;
1593  while ($i < $num) {
1594  $row = $this->db->fetch_row($resql);
1595  $projects[$row[0]] = $row[1];
1596  $temp[] = $row[0];
1597  $i++;
1598  }
1599 
1600  $this->db->free($resql);
1601 
1602  if ($list) {
1603  if (empty($temp)) {
1604  return '0';
1605  }
1606  $result = implode(',', $temp);
1607  return $result;
1608  }
1609  } else {
1610  dol_print_error($this->db);
1611  }
1612 
1613  return $projects;
1614  }
1615 
1631  public function createFromClone(User $user, $fromid, $clone_contact = false, $clone_task = true, $clone_project_file = false, $clone_task_file = false, $clone_note = true, $move_date = true, $notrigger = 0, $newthirdpartyid = 0)
1632  {
1633  global $langs, $conf;
1634 
1635  $error = 0;
1636 
1637  dol_syslog("createFromClone clone_contact=".$clone_contact." clone_task=".$clone_task." clone_project_file=".$clone_project_file." clone_note=".$clone_note." move_date=".$move_date, LOG_DEBUG);
1638 
1639  $now = dol_mktime(0, 0, 0, idate('m', dol_now()), idate('d', dol_now()), idate('Y', dol_now()));
1640 
1641  $clone_project = new Project($this->db);
1642 
1643  $clone_project->context['createfromclone'] = 'createfromclone';
1644 
1645  $this->db->begin();
1646 
1647  // Load source object
1648  $clone_project->fetch($fromid);
1649  $clone_project->fetch_optionals();
1650  if ($newthirdpartyid > 0) {
1651  $clone_project->socid = $newthirdpartyid;
1652  }
1653  $clone_project->fetch_thirdparty();
1654 
1655  $orign_dt_start = $clone_project->date_start;
1656  $orign_project_ref = $clone_project->ref;
1657 
1658  $clone_project->id = 0;
1659  if ($move_date) {
1660  $clone_project->date_start = $now;
1661  if (!(empty($clone_project->date_end))) {
1662  $clone_project->date_end = $clone_project->date_end + ($now - $orign_dt_start);
1663  }
1664  }
1665 
1666  $clone_project->date_c = $now;
1667 
1668  if (!$clone_note) {
1669  $clone_project->note_private = '';
1670  $clone_project->note_public = '';
1671  }
1672 
1673  //Generate next ref
1674  $defaultref = '';
1675  $obj = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;
1676  // Search template files
1677  $file = ''; $classname = ''; $filefound = 0;
1678  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1679  foreach ($dirmodels as $reldir) {
1680  $file = dol_buildpath($reldir."core/modules/project/".$obj.'.php', 0);
1681  if (file_exists($file)) {
1682  $filefound = 1;
1683  dol_include_once($reldir."core/modules/project/".$obj.'.php');
1684  $modProject = new $obj;
1685  $defaultref = $modProject->getNextValue(is_object($clone_project->thirdparty) ? $clone_project->thirdparty : null, $clone_project);
1686  break;
1687  }
1688  }
1689  if (is_numeric($defaultref) && $defaultref <= 0) {
1690  $defaultref = '';
1691  }
1692 
1693  $clone_project->ref = $defaultref;
1694  $clone_project->title = $langs->trans("CopyOf").' '.$clone_project->title;
1695 
1696  // Create clone
1697  $result = $clone_project->create($user, $notrigger);
1698 
1699  // Other options
1700  if ($result < 0) {
1701  $this->error .= $clone_project->error;
1702  $error++;
1703  }
1704 
1705  if (!$error) {
1706  //Get the new project id
1707  $clone_project_id = $clone_project->id;
1708 
1709  //Note Update
1710  if (!$clone_note) {
1711  $clone_project->note_private = '';
1712  $clone_project->note_public = '';
1713  } else {
1714  $this->db->begin();
1715  $res = $clone_project->update_note(dol_html_entity_decode($clone_project->note_public, ENT_QUOTES | ENT_HTML5), '_public');
1716  if ($res < 0) {
1717  $this->error .= $clone_project->error;
1718  $error++;
1719  $this->db->rollback();
1720  } else {
1721  $this->db->commit();
1722  }
1723 
1724  $this->db->begin();
1725  $res = $clone_project->update_note(dol_html_entity_decode($clone_project->note_private, ENT_QUOTES | ENT_HTML5), '_private');
1726  if ($res < 0) {
1727  $this->error .= $clone_project->error;
1728  $error++;
1729  $this->db->rollback();
1730  } else {
1731  $this->db->commit();
1732  }
1733  }
1734 
1735  //Duplicate contact
1736  if ($clone_contact) {
1737  $origin_project = new Project($this->db);
1738  $origin_project->fetch($fromid);
1739 
1740  foreach (array('internal', 'external') as $source) {
1741  $tab = $origin_project->liste_contact(-1, $source);
1742  if (is_array($tab) && count($tab)>0) {
1743  foreach ($tab as $contacttoadd) {
1744  $clone_project->add_contact($contacttoadd['id'], $contacttoadd['code'], $contacttoadd['source'], $notrigger);
1745  if ($clone_project->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1746  $langs->load("errors");
1747  $this->error .= $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
1748  $error++;
1749  } else {
1750  if ($clone_project->error != '') {
1751  $this->error .= $clone_project->error;
1752  $error++;
1753  }
1754  }
1755  }
1756  } elseif ($tab < 0) {
1757  $this->error .= $origin_project->error;
1758  $error++;
1759  }
1760  }
1761  }
1762 
1763  //Duplicate file
1764  if ($clone_project_file) {
1765  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1766 
1767  $clone_project_dir = $conf->project->dir_output."/".dol_sanitizeFileName($defaultref);
1768  $ori_project_dir = $conf->project->dir_output."/".dol_sanitizeFileName($orign_project_ref);
1769 
1770  if (dol_mkdir($clone_project_dir) >= 0) {
1771  $filearray = dol_dir_list($ori_project_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', '', SORT_ASC, 1);
1772  foreach ($filearray as $key => $file) {
1773  $rescopy = dol_copy($ori_project_dir.'/'.$file['name'], $clone_project_dir.'/'.$file['name'], 0, 1);
1774  if (is_numeric($rescopy) && $rescopy < 0) {
1775  $this->error .= $langs->trans("ErrorFailToCopyFile", $ori_project_dir.'/'.$file['name'], $clone_project_dir.'/'.$file['name']);
1776  $error++;
1777  }
1778  }
1779  } else {
1780  $this->error .= $langs->trans('ErrorInternalErrorDetected').':dol_mkdir';
1781  $error++;
1782  }
1783  }
1784 
1785  //Duplicate task
1786  if ($clone_task) {
1787  require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
1788 
1789  $taskstatic = new Task($this->db);
1790 
1791  // Security check
1792  $socid = 0;
1793  if ($user->socid > 0) {
1794  $socid = $user->socid;
1795  }
1796 
1797  $tasksarray = $taskstatic->getTasksArray(0, 0, $fromid, $socid, 0);
1798 
1799  $tab_conv_child_parent = array();
1800 
1801  // Loop on each task, to clone it
1802  foreach ($tasksarray as $tasktoclone) {
1803  $result_clone = $taskstatic->createFromClone($user, $tasktoclone->id, $clone_project_id, $tasktoclone->fk_task_parent, $move_date, true, false, $clone_task_file, true, false);
1804  if ($result_clone <= 0) {
1805  $this->error .= $taskstatic->error;
1806  $error++;
1807  } else {
1808  $new_task_id = $result_clone;
1809  $taskstatic->fetch($tasktoclone->id);
1810 
1811  //manage new parent clone task id
1812  // if the current task has child we store the original task id and the equivalent clone task id
1813  if (($taskstatic->hasChildren()) && !array_key_exists($tasktoclone->id, $tab_conv_child_parent)) {
1814  $tab_conv_child_parent[$tasktoclone->id] = $new_task_id;
1815  }
1816  }
1817  }
1818 
1819  //Parse all clone node to be sure to update new parent
1820  $tasksarray = $taskstatic->getTasksArray(0, 0, $clone_project_id, $socid, 0);
1821  foreach ($tasksarray as $task_cloned) {
1822  $taskstatic->fetch($task_cloned->id);
1823  if ($taskstatic->fk_task_parent != 0) {
1824  $taskstatic->fk_task_parent = $tab_conv_child_parent[$taskstatic->fk_task_parent];
1825  }
1826  $res = $taskstatic->update($user, $notrigger);
1827  if ($result_clone <= 0) {
1828  $this->error .= $taskstatic->error;
1829  $error++;
1830  }
1831  }
1832  }
1833  }
1834 
1835  unset($clone_project->context['createfromclone']);
1836 
1837  if (!$error) {
1838  $this->db->commit();
1839  return $clone_project_id;
1840  } else {
1841  $this->db->rollback();
1842  dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : ".$this->error, LOG_ERR);
1843  return -1;
1844  }
1845  }
1846 
1847 
1854  public function shiftTaskDate($old_project_dt_start)
1855  {
1856  global $user, $langs, $conf;
1857 
1858  $error = 0;
1859  $result = 0;
1860 
1861  $taskstatic = new Task($this->db);
1862 
1863  // Security check
1864  $socid = 0;
1865  if ($user->socid > 0) {
1866  $socid = $user->socid;
1867  }
1868 
1869  $tasksarray = $taskstatic->getTasksArray(0, 0, $this->id, $socid, 0);
1870 
1871  foreach ($tasksarray as $tasktoshiftdate) {
1872  $to_update = false;
1873  // Fetch only if update of date will be made
1874  if ((!empty($tasktoshiftdate->date_start)) || (!empty($tasktoshiftdate->date_end))) {
1875  //dol_syslog(get_class($this)."::shiftTaskDate to_update", LOG_DEBUG);
1876  $to_update = true;
1877  $task = new Task($this->db);
1878  $result = $task->fetch($tasktoshiftdate->id);
1879  if (!$result) {
1880  $error++;
1881  $this->error .= $task->error;
1882  }
1883  }
1884  //print "$this->date_start + $tasktoshiftdate->date_start - $old_project_dt_start";exit;
1885 
1886  //Calcultate new task start date with difference between old proj start date and origin task start date
1887  if (!empty($tasktoshiftdate->date_start)) {
1888  $task->date_start = $this->date_start + ($tasktoshiftdate->date_start - $old_project_dt_start);
1889  }
1890 
1891  //Calcultate new task end date with difference between origin proj end date and origin task end date
1892  if (!empty($tasktoshiftdate->date_end)) {
1893  $task->date_end = $this->date_start + ($tasktoshiftdate->date_end - $old_project_dt_start);
1894  }
1895 
1896  if ($to_update) {
1897  $result = $task->update($user);
1898  if (!$result) {
1899  $error++;
1900  $this->error .= $task->error;
1901  }
1902  }
1903  }
1904  if ($error != 0) {
1905  return -1;
1906  }
1907  return $result;
1908  }
1909 
1910 
1911  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1919  public function update_element($tableName, $elementSelectId)
1920  {
1921  // phpcs:enable
1922  $sql = "UPDATE ".MAIN_DB_PREFIX.$tableName;
1923 
1924  if ($tableName == "actioncomm") {
1925  $sql .= " SET fk_project=".$this->id;
1926  $sql .= " WHERE id=".((int) $elementSelectId);
1927  } elseif (in_array($tableName, ["entrepot","mrp_mo"])) {
1928  $sql .= " SET fk_project=".$this->id;
1929  $sql .= " WHERE rowid=".((int) $elementSelectId);
1930  } else {
1931  $sql .= " SET fk_projet=".$this->id;
1932  $sql .= " WHERE rowid=".((int) $elementSelectId);
1933  }
1934 
1935  dol_syslog(get_class($this)."::update_element", LOG_DEBUG);
1936  $resql = $this->db->query($sql);
1937  if (!$resql) {
1938  $this->error = $this->db->lasterror();
1939  return -1;
1940  } else {
1941  return 1;
1942  }
1943  }
1944 
1945  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1955  public function remove_element($tableName, $elementSelectId, $projectfield = 'fk_projet')
1956  {
1957  // phpcs:enable
1958  $sql = "UPDATE ".MAIN_DB_PREFIX.$tableName;
1959 
1960  if ($tableName == "actioncomm") {
1961  $sql .= " SET fk_project=NULL";
1962  $sql .= " WHERE id=".((int) $elementSelectId);
1963  } else {
1964  $sql .= " SET ".$projectfield."=NULL";
1965  $sql .= " WHERE rowid=".((int) $elementSelectId);
1966  }
1967 
1968  dol_syslog(get_class($this)."::remove_element", LOG_DEBUG);
1969  $resql = $this->db->query($sql);
1970  if (!$resql) {
1971  $this->error = $this->db->lasterror();
1972  return -1;
1973  } else {
1974  return 1;
1975  }
1976  }
1977 
1988  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1989  {
1990  global $conf, $langs;
1991 
1992  $langs->load("projects");
1993 
1994  if (!dol_strlen($modele)) {
1995  $modele = 'baleine';
1996 
1997  if ($this->model_pdf) {
1998  $modele = $this->model_pdf;
1999  } elseif (!empty($conf->global->PROJECT_ADDON_PDF)) {
2000  $modele = $conf->global->PROJECT_ADDON_PDF;
2001  }
2002  }
2003 
2004  $modelpath = "core/modules/project/doc/";
2005 
2006  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2007  }
2008 
2009 
2019  public function loadTimeSpent($datestart, $taskid = 0, $userid = 0)
2020  {
2021  $error = 0;
2022 
2023  $this->weekWorkLoad = array();
2024  $this->weekWorkLoadPerTask = array();
2025 
2026  if (empty($datestart)) {
2027  dol_print_error('', 'Error datestart parameter is empty');
2028  }
2029 
2030  $sql = "SELECT ptt.rowid as taskid, ptt.element_duration, ptt.element_date, ptt.element_datehour, ptt.fk_element";
2031  $sql .= " FROM ".MAIN_DB_PREFIX."element_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt";
2032  $sql .= " WHERE ptt.fk_element = pt.rowid";
2033  $sql .= " AND ptt.elementtype = 'task'";
2034  $sql .= " AND pt.fk_projet = ".((int) $this->id);
2035  $sql .= " AND (ptt.element_date >= '".$this->db->idate($datestart)."' ";
2036  $sql .= " AND ptt.element_date <= '".$this->db->idate(dol_time_plus_duree($datestart, 1, 'w') - 1)."')";
2037  if ($taskid) {
2038  $sql .= " AND ptt.fk_element=".((int) $taskid);
2039  }
2040  if (is_numeric($userid)) {
2041  $sql .= " AND ptt.fk_user=".((int) $userid);
2042  }
2043 
2044  //print $sql;
2045  $resql = $this->db->query($sql);
2046  if ($resql) {
2047  $daylareadyfound = array();
2048 
2049  $num = $this->db->num_rows($resql);
2050  $i = 0;
2051  // Loop on each record found, so each couple (project id, task id)
2052  while ($i < $num) {
2053  $obj = $this->db->fetch_object($resql);
2054  $day = $this->db->jdate($obj->element_date); // task_date is date without hours
2055  if (empty($daylareadyfound[$day])) {
2056  $this->weekWorkLoad[$day] = $obj->element_duration;
2057  $this->weekWorkLoadPerTask[$day][$obj->fk_element] = $obj->element_duration;
2058  } else {
2059  $this->weekWorkLoad[$day] += $obj->element_duration;
2060  $this->weekWorkLoadPerTask[$day][$obj->fk_element] += $obj->element_duration;
2061  }
2062  $daylareadyfound[$day] = 1;
2063  $i++;
2064  }
2065  $this->db->free($resql);
2066  return 1;
2067  } else {
2068  $this->error = "Error ".$this->db->lasterror();
2069  dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
2070  return -1;
2071  }
2072  }
2073 
2083  public function loadTimeSpentMonth($datestart, $taskid = 0, $userid = 0)
2084  {
2085  $error = 0;
2086 
2087  $this->monthWorkLoad = array();
2088  $this->monthWorkLoadPerTask = array();
2089 
2090  if (empty($datestart)) {
2091  dol_print_error('', 'Error datestart parameter is empty');
2092  }
2093 
2094  $sql = "SELECT ptt.rowid as taskid, ptt.element_duration, ptt.element_date, ptt.element_datehour, ptt.fk_element";
2095  $sql .= " FROM ".MAIN_DB_PREFIX."element_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt";
2096  $sql .= " WHERE ptt.fk_element = pt.rowid";
2097  $sql .= " AND ptt.elementtype = 'task'";
2098  $sql .= " AND pt.fk_projet = ".((int) $this->id);
2099  $sql .= " AND (ptt.element_date >= '".$this->db->idate($datestart)."' ";
2100  $sql .= " AND ptt.element_date <= '".$this->db->idate(dol_time_plus_duree($datestart, 1, 'm') - 1)."')";
2101  if ($taskid) {
2102  $sql .= " AND ptt.fk_element=".((int) $taskid);
2103  }
2104  if (is_numeric($userid)) {
2105  $sql .= " AND ptt.fk_user=".((int) $userid);
2106  }
2107 
2108  //print $sql;
2109  $resql = $this->db->query($sql);
2110  if ($resql) {
2111  $weekalreadyfound = array();
2112 
2113  $num = $this->db->num_rows($resql);
2114  $i = 0;
2115  // Loop on each record found, so each couple (project id, task id)
2116  while ($i < $num) {
2117  $obj = $this->db->fetch_object($resql);
2118  if (!empty($obj->element_date)) {
2119  $date = explode('-', $obj->element_date);
2120  $week_number = getWeekNumber($date[2], $date[1], $date[0]);
2121  }
2122  if (empty($weekalreadyfound[$week_number])) {
2123  $this->monthWorkLoad[$week_number] = $obj->element_duration;
2124  $this->monthWorkLoadPerTask[$week_number][$obj->fk_element] = $obj->element_duration;
2125  } else {
2126  $this->monthWorkLoad[$week_number] += $obj->element_duration;
2127  $this->monthWorkLoadPerTask[$week_number][$obj->fk_element] += $obj->element_duration;
2128  }
2129  $weekalreadyfound[$week_number] = 1;
2130  $i++;
2131  }
2132  $this->db->free($resql);
2133  return 1;
2134  } else {
2135  $this->error = "Error ".$this->db->lasterror();
2136  dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
2137  return -1;
2138  }
2139  }
2140 
2141  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2148  public function load_board($user)
2149  {
2150  // phpcs:enable
2151  global $conf, $langs;
2152 
2153  // For external user, no check is done on company because readability is managed by public status of project and assignement.
2154  //$socid=$user->socid;
2155 
2156  $response = new WorkboardResponse();
2157  $response->warning_delay = $conf->project->warning_delay / 60 / 60 / 24;
2158  $response->label = $langs->trans("OpenedProjects");
2159  $response->labelShort = $langs->trans("Opened");
2160  $response->url = DOL_URL_ROOT.'/projet/list.php?search_project_user=-1&search_status=1&mainmenu=project';
2161  $response->img = img_object('', "projectpub");
2162  $response->nbtodo = 0;
2163  $response->nbtodolate = 0;
2164 
2165  $sql = "SELECT p.rowid, p.fk_statut as status, p.fk_opp_status, p.datee as datee";
2166  $sql .= " FROM (".MAIN_DB_PREFIX."projet as p";
2167  $sql .= ")";
2168  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
2169  // For external user, no check is done on company permission because readability is managed by public status of project and assignement.
2170  //if (! $user->rights->societe->client->voir && ! $socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2171  $sql .= " WHERE p.fk_statut = 1";
2172  $sql .= " AND p.entity IN (".getEntity('project').')';
2173 
2174 
2175  $projectsListId = null;
2176  if (!$user->hasRight("projet", "all", "lire")) {
2177  $response->url = DOL_URL_ROOT.'/projet/list.php?search_status=1&mainmenu=project';
2178  $projectsListId = $this->getProjectsAuthorizedForUser($user, 0, 1);
2179  if (empty($projectsListId)) {
2180  return $response;
2181  }
2182 
2183  $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
2184  }
2185 
2186  // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
2187  //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
2188  // For external user, no check is done on company permission because readability is managed by public status of project and assignement.
2189  //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).") OR (s.rowid IS NULL))";
2190 
2191  //print $sql;
2192  $resql = $this->db->query($sql);
2193  if ($resql) {
2194  $project_static = new Project($this->db);
2195 
2196 
2197  // This assignment in condition is not a bug. It allows walking the results.
2198  while ($obj = $this->db->fetch_object($resql)) {
2199  $response->nbtodo++;
2200 
2201  $project_static->statut = $obj->status;
2202  $project_static->opp_status = $obj->fk_opp_status;
2203  $project_static->date_end = $this->db->jdate($obj->datee);
2204 
2205  if ($project_static->hasDelay()) {
2206  $response->nbtodolate++;
2207  }
2208  }
2209 
2210  return $response;
2211  }
2212 
2213  $this->error = $this->db->error();
2214  return -1;
2215  }
2216 
2225  public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
2226  {
2227  $tables = array(
2228  'projet'
2229  );
2230 
2231  return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
2232  }
2233 
2234 
2235  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2241  public function load_state_board()
2242  {
2243  // phpcs:enable
2244  global $user;
2245 
2246  $this->nb = array();
2247 
2248  $sql = "SELECT count(p.rowid) as nb";
2249  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
2250  $sql .= " WHERE";
2251  $sql .= " p.entity IN (".getEntity('project').")";
2252  if (empty($user->rights->projet->all->lire)) {
2253  $projectsListId = $this->getProjectsAuthorizedForUser($user, 0, 1);
2254  $sql .= "AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
2255  }
2256 
2257  $resql = $this->db->query($sql);
2258  if ($resql) {
2259  while ($obj = $this->db->fetch_object($resql)) {
2260  $this->nb["projects"] = $obj->nb;
2261  }
2262  $this->db->free($resql);
2263  return 1;
2264  } else {
2265  dol_print_error($this->db);
2266  $this->error = $this->db->error();
2267  return -1;
2268  }
2269  }
2270 
2271 
2277  public function hasDelay()
2278  {
2279  global $conf;
2280 
2281  if (!($this->statut == self::STATUS_VALIDATED)) {
2282  return false;
2283  }
2284  if (!$this->date_end) {
2285  return false;
2286  }
2287 
2288  $now = dol_now();
2289 
2290  return ($this->date_end) < ($now - $conf->project->warning_delay);
2291  }
2292 
2293 
2300  public function info($id)
2301  {
2302  $sql = 'SELECT c.rowid, datec as datec, tms as datem,';
2303  $sql .= ' date_close as datecloture,';
2304  $sql .= ' fk_user_creat as fk_user_author, fk_user_close as fk_use_cloture';
2305  $sql .= ' FROM '.MAIN_DB_PREFIX.'projet as c';
2306  $sql .= ' WHERE c.rowid = '.((int) $id);
2307  $result = $this->db->query($sql);
2308  if ($result) {
2309  if ($this->db->num_rows($result)) {
2310  $obj = $this->db->fetch_object($result);
2311  $this->id = $obj->rowid;
2312  if ($obj->fk_user_author) {
2313  $cuser = new User($this->db);
2314  $cuser->fetch($obj->fk_user_author);
2315  $this->user_creation = $cuser;
2316  }
2317 
2318  if (!empty($obj->fk_user_cloture)) {
2319  $cluser = new User($this->db);
2320  $cluser->fetch($obj->fk_user_cloture);
2321  $this->user_cloture = $cluser;
2322  }
2323 
2324  $this->date_creation = $this->db->jdate($obj->datec);
2325  $this->date_modification = $this->db->jdate($obj->datem);
2326  $this->date_cloture = $this->db->jdate($obj->datecloture);
2327  }
2328 
2329  $this->db->free($result);
2330  } else {
2331  dol_print_error($this->db);
2332  }
2333  }
2334 
2345  public function setCategories($categories)
2346  {
2347  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2348  return parent::setCategoriesCommon($categories, Categorie::TYPE_PROJECT);
2349  }
2350 
2351 
2359  public function getLinesArray($user, $loadRoleMode = 1)
2360  {
2361  require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
2362  $taskstatic = new Task($this->db);
2363 
2364  $this->lines = $taskstatic->getTasksArray(0, $user, $this->id, 0, 0, '', '-1', '', 0, 0, array(), 0, array(), 0, $loadRoleMode);
2365  return 1;
2366  }
2367 
2385  public function sendEmail($text, $subject, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = -1, $errors_to = '', $moreinheader = '')
2386  {
2387  global $conf, $langs;
2388  // TODO EMAIL
2389 
2390  return 1;
2391  }
2399  public function getKanbanView($option = '', $arraydata = null)
2400  {
2401  global $langs;
2402 
2403  $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2404 
2405  $return = '<div class="box-flex-item box-flex-grow-zero">';
2406  $return .= '<div class="info-box info-box-sm">';
2407  $return .= '<span class="info-box-icon bg-infobox-action">';
2408  $return .= img_picto('', $this->public ? 'projectpub' : $this->picto);
2409  //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
2410  $return .= '</span>';
2411  $return .= '<div class="info-box-content">';
2412  $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref);
2413  if ($this->hasDelay()) {
2414  $return .= img_warning($langs->trans('Late'));
2415  }
2416  $return .= '</span>';
2417  $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2418  // Date
2419  /*
2420  if (property_exists($this, 'date_start') && $this->date_start) {
2421  $return .= '<br><span class="info-box-label">'.dol_print_date($this->date_start, 'day').'</>';
2422  }
2423  if (property_exists($this, 'date_end') && $this->date_end) {
2424  if ($this->date_start) {
2425  $return .= ' - ';
2426  } else {
2427  $return .= '<br>';
2428  }
2429  $return .= '<span class="info-box-label">'.dol_print_date($this->date_end, 'day').'</span>';
2430  }*/
2431  if (!empty($arraydata['assignedusers'])) {
2432  $return .= '<br>';
2433  if ($this->public) {
2434  $return .= img_picto($langs->trans('Visibility').': '.$langs->trans('SharedProject'), 'world', 'class="paddingrightonly valignmiddle"');
2435  //print $langs->trans('SharedProject');
2436  } else {
2437  $return .= img_picto($langs->trans('Visibility').': '.$langs->trans('PrivateProject'), 'private', 'class="paddingrightonly valignmiddle"');
2438  //print $langs->trans('PrivateProject');
2439  }
2440 
2441  $return .= ' <span class="small valignmiddle">'.$arraydata['assignedusers'].'</span>';
2442  }
2443  /*if (property_exists($this, 'user_author_id')) {
2444  $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Author").'</span>';
2445  $return .= '<span> : '.$user->getNomUrl(1).'</span>';
2446  }*/
2447  if ($this->usage_opportunity && $this->opp_status_code) {
2448  //$return .= '<br><span class="info-bo-label opacitymedium">'.$langs->trans("OpportunityStatusShort").'</span>';
2449  $return .= '<br><span class="info-box-label small">'.$langs->trans("OppStatus".$this->opp_status_code).'</span>';
2450  $return .= ' <span class="opacitymedium small">('.round($this->opp_percent).'%)</span>';
2451  $return .= '<br><span class="amount small">'.price($this->opp_amount).'</span>';
2452  }
2453  if (method_exists($this, 'getLibStatut')) {
2454  $return .= '<br><div class="info-box-status small">'.$this->getLibStatut(3).'</div>';
2455  }
2456  $return .= '</div>';
2457  $return .= '</div>';
2458  $return .= '</div>';
2459  return $return;
2460  }
2461 }
$object ref
Definition: info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
liste_contact($statusoflink=-1, $source='external', $list=0, $code='', $status=-1, $arrayoftcids=array())
Get array of all contacts for an object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage projects.
$user_author_id
Id of project creator. Not defined if shared project.
LibStatut($status, $mode=0)
Renvoi status label for a status.
getLibStatut($mode=0)
Return status label of object.
getElementCount($type, $tablename, $projectkey='fk_projet')
Return the count of a type of linked elements of this project.
setValid($user, $notrigger=0)
Validate a project.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
const STATUS_VALIDATED
Open/Validated status.
$public
Tell if this is a public or private project.
getProjectsAuthorizedForUser($user, $mode=0, $list=0, $socid=0, $filter='')
Return array of projects a user has permission on, is affected to, or all projects.
create($user, $notrigger=0)
Create a project into database.
load_state_board()
Charge indicateurs this->nb pour le tableau de bord.
const STATUS_CLOSED
Closed status.
const STATUS_DRAFT
Draft status.
loadTimeSpentMonth($datestart, $taskid=0, $userid=0)
Load time spent into this->weekWorkLoad and this->weekWorkLoadPerTask for all day of a week of projec...
__construct($db)
Constructor.
get_element_list($type, $tablename, $datefieldname='', $date_start='', $date_end='', $projectkey='fk_projet')
Return list of elements for type, linked to a project.
fetch($id, $ref='', $ref_ext='', $email_msgid='')
Get object from database.
shiftTaskDate($old_project_dt_start)
Shift project task date from current date to delta.
$table_ref_field
{}
hasDelay()
Is the project delayed?
remove_element($tableName, $elementSelectId, $projectfield='fk_projet')
Associate element to a project.
setCategories($categories)
Sets object to supplied categories.
update_element($tableName, $elementSelectId)
Associate element to a project.
createFromClone(User $user, $fromid, $clone_contact=false, $clone_task=true, $clone_project_file=false, $clone_task_file=false, $clone_note=true, $move_date=true, $notrigger=0, $newthirdpartyid=0)
Load an object from its id and create a new one in database.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
getLinesArray($user, $loadRoleMode=1)
Create an array of tasks of current project.
info($id)
Charge les informations d'ordre info dans l'objet commande.
getTooltipContentArray($params)
getTooltipContentArray
sendEmail($text, $subject, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=-1, $errors_to='', $moreinheader='')
Function sending an email to the current member with the text supplied in parameter.
initAsSpecimen()
Initialise an instance with random values.
setClose($user)
Close a project.
loadTimeSpent($datestart, $taskid=0, $userid=0)
Load time spent into this->weekWorkLoad and this->weekWorkLoadPerTask for all day of a week of projec...
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create an intervention document on disk using template defined into PROJECT_ADDON_PDF.
getNomUrl($withpicto=0, $option='', $addlabel=0, $moreinpopup='', $sep=' - ', $notooltip=0, $save_lastsearch_value=-1, $morecss='')
Return clickable name (with picto eventually)
restrictedProjectArea(User $user, $mode='read')
Check if user has permission on current project.
deleteTasks($user)
Delete tasks with no children first, then task with children recursively.
update($user, $notrigger=0)
Update a project.
Class to manage tasks.
Definition: task.class.php:40
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
getWeekNumber($day, $month, $year)
Return week number.
Definition: date.lib.php:1167
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:122
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
Definition: files.lib.php:1485
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
Definition: files.lib.php:717
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:62
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)