dolibarr 19.0.4
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
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32
36class Project extends CommonObject
37{
41 public $element = 'project';
42
46 public $table_element = 'projet';
47
51 public $table_element_line = 'projet_task';
52
56 public $table_element_date;
57
61 public $fk_element = 'fk_projet';
62
67 public $ismultientitymanaged = 1;
68
72 public $isextrafieldmanaged = 1;
73
77 public $picto = 'project';
78
82 protected $table_ref_field = 'ref';
83
87 public $fk_project;
88
92 public $description;
93
97 public $title;
98
104 public $dateo;
105
109 public $date_start;
110
116 public $datee;
117
121 public $date_end;
122
126 public $date_start_event;
127
131 public $date_end_event;
132
136 public $location;
137
141 public $date_close;
142
143 public $socid; // To store id of thirdparty
144 public $thirdparty_name; // To store name of thirdparty (defined only in some cases)
145
147
151 public $fk_user_close;
152
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 $labelStatusShort;
206 public $labelStatus;
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
227 public $monthWorkLoad;
228
232 public $monthWorkLoadPerTask;
233
239 public $datec;
240
244 public $date_c;
245
251 public $datem;
252
256 public $date_m;
257
261 public $ip;
262
266 public $lines;
267
292 // BEGIN MODULEBUILDER PROPERTIES
296 public $fields = array(
297 'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
298 'fk_project' =>array('type'=>'integer', 'label'=>'Parent', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'position'=>12),
299 'ref' =>array('type'=>'varchar(50)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'showoncombobox'=>1, 'position'=>15, 'searchall'=>1),
300 'title' =>array('type'=>'varchar(255)', 'label'=>'ProjectLabel', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>17, 'showoncombobox'=>2, 'searchall'=>1),
301 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>3, 'notnull'=>1, 'position'=>19),
302 'fk_soc' =>array('type'=>'integer', 'label'=>'Thirdparty', 'enabled'=>1, 'visible'=>0, 'position'=>20),
303 'dateo' =>array('type'=>'date', 'label'=>'DateStart', 'enabled'=>1, 'visible'=>1, 'position'=>30),
304 'datee' =>array('type'=>'date', 'label'=>'DateEnd', 'enabled'=>1, 'visible'=>1, 'position'=>35),
305 'description' =>array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>3, 'position'=>55, 'searchall'=>1),
306 'public' =>array('type'=>'integer', 'label'=>'Visibility', 'enabled'=>1, 'visible'=>1, 'position'=>65),
307 'fk_opp_status' =>array('type'=>'integer', 'label'=>'OpportunityStatusShort', 'enabled'=>'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")', 'visible'=>1, 'position'=>75),
308 'opp_percent' =>array('type'=>'double(5,2)', 'label'=>'OpportunityProbabilityShort', 'enabled'=>'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")', 'visible'=>1, 'position'=>80),
309 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>85, 'searchall'=>1),
310 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>90, 'searchall'=>1),
311 'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPdf', 'enabled'=>1, 'visible'=>0, 'position'=>95),
312 'date_close' =>array('type'=>'datetime', 'label'=>'DateClosing', 'enabled'=>1, 'visible'=>0, 'position'=>105),
313 'fk_user_close' =>array('type'=>'integer', 'label'=>'UserClosing', 'enabled'=>1, 'visible'=>0, 'position'=>110),
314 'opp_amount' =>array('type'=>'double(24,8)', 'label'=>'OpportunityAmountShort', 'enabled'=>1, 'visible'=>'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")', 'position'=>115),
315 'budget_amount' =>array('type'=>'double(24,8)', 'label'=>'Budget', 'enabled'=>1, 'visible'=>-1, 'position'=>119),
316 'usage_opportunity' =>array('type'=>'integer', 'label'=>'UsageOpportunity', 'enabled'=>1, 'visible'=>-1, 'position'=>130),
317 'usage_task' =>array('type'=>'integer', 'label'=>'UsageTasks', 'enabled'=>1, 'visible'=>-1, 'position'=>135),
318 'usage_bill_time' =>array('type'=>'integer', 'label'=>'UsageBillTimeShort', 'enabled'=>1, 'visible'=>-1, 'position'=>140),
319 'usage_organize_event' =>array('type'=>'integer', 'label'=>'UsageOrganizeEvent', 'enabled'=>1, 'visible'=>-1, 'position'=>145),
320 // Properties for event organization
321 'date_start_event' =>array('type'=>'date', 'label'=>'DateStartEvent', 'enabled'=>"isModEnabled('eventorganization')", 'visible'=>1, 'position'=>200),
322 'date_end_event' =>array('type'=>'date', 'label'=>'DateEndEvent', 'enabled'=>"isModEnabled('eventorganization')", 'visible'=>1, 'position'=>201),
323 'location' =>array('type'=>'text', 'label'=>'Location', 'enabled'=>1, 'visible'=>3, 'position'=>55, 'searchall'=>202),
324 'accept_conference_suggestions' =>array('type'=>'integer', 'label'=>'AllowUnknownPeopleSuggestConf', 'enabled'=>1, 'visible'=>-1, 'position'=>210),
325 'accept_booth_suggestions' =>array('type'=>'integer', 'label'=>'AllowUnknownPeopleSuggestBooth', 'enabled'=>1, 'visible'=>-1, 'position'=>211),
326 'price_registration' =>array('type'=>'double(24,8)', 'label'=>'PriceOfRegistration', 'enabled'=>1, 'visible'=>-1, 'position'=>212),
327 'price_booth' =>array('type'=>'double(24,8)', 'label'=>'PriceOfBooth', 'enabled'=>1, 'visible'=>-1, 'position'=>215),
328 'max_attendees' =>array('type'=>'integer', 'label'=>'MaxNbOfAttendees', 'enabled'=>1, 'visible'=>-1, 'position'=>215),
329 // Generic
330 'datec' =>array('type'=>'datetime', 'label'=>'DateCreationShort', 'enabled'=>1, 'visible'=>-2, 'position'=>400),
331 'tms' =>array('type'=>'timestamp', 'label'=>'DateModificationShort', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>405),
332 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserCreation', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>410),
333 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModification', 'enabled'=>1, 'visible'=>0, 'position'=>415),
334 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'position'=>420),
335 'email_msgid'=>array('type'=>'varchar(255)', 'label'=>'EmailMsgID', 'enabled'=>1, 'visible'=>-1, 'position'=>450, 'help'=>'EmailMsgIDWhenSourceisEmail', 'csslist'=>'tdoverflowmax125'),
336 'fk_statut' =>array('type'=>'smallint(6)', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>500),
337 );
338 // END MODULEBUILDER PROPERTIES
339
343 const STATUS_DRAFT = 0;
344
349
353 const STATUS_CLOSED = 2;
354
360 public function __construct($db)
361 {
362 global $conf;
363
364 $this->db = $db;
365
366 $this->labelStatusShort = array(0 => 'Draft', 1 => 'Opened', 2 => 'Closed');
367 $this->labelStatus = array(0 => 'Draft', 1 => 'Opened', 2 => 'Closed');
368
369 global $conf;
370
371 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
372 $this->fields['rowid']['visible'] = 0;
373 }
374
375 if (!getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
376 $this->fields['fk_opp_status']['enabled'] = 0;
377 $this->fields['opp_percent']['enabled'] = 0;
378 $this->fields['opp_amount']['enabled'] = 0;
379 $this->fields['usage_opportunity']['enabled'] = 0;
380 }
381
382 if (getDolGlobalString('PROJECT_HIDE_TASKS')) {
383 $this->fields['usage_bill_time']['visible'] = 0;
384 $this->fields['usage_task']['visible'] = 0;
385 }
386
387 if (empty($conf->eventorganization->enabled)) {
388 $this->fields['usage_organize_event']['visible'] = 0;
389 $this->fields['accept_conference_suggestions']['enabled'] = 0;
390 $this->fields['accept_booth_suggestions']['enabled'] = 0;
391 $this->fields['price_registration']['enabled'] = 0;
392 $this->fields['price_booth']['enabled'] = 0;
393 $this->fields['max_attendees']['enabled'] = 0;
394 }
395 }
396
404 public function create($user, $notrigger = 0)
405 {
406 global $conf, $langs;
407
408 $error = 0;
409 $ret = 0;
410
411 $now = dol_now();
412
413 // Clean parameters
414 $this->note_private = dol_substr($this->note_private, 0, 65535);
415 $this->note_public = dol_substr($this->note_public, 0, 65535);
416
417 // Check parameters
418 if (!trim($this->ref)) {
419 $this->error = 'ErrorFieldsRequired';
420 dol_syslog(get_class($this)."::create error -1 ref null", LOG_ERR);
421 return -1;
422 }
423 if (getDolGlobalString('PROJECT_THIRDPARTY_REQUIRED') && !($this->socid > 0)) {
424 $this->error = 'ErrorFieldsRequired';
425 dol_syslog(get_class($this)."::create error -1 thirdparty not defined and option PROJECT_THIRDPARTY_REQUIRED is set", LOG_ERR);
426 return -1;
427 }
428
429 // Create project
430 $this->db->begin();
431
432 $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (";
433 $sql .= "ref";
434 $sql .= ", fk_project";
435 $sql .= ", title";
436 $sql .= ", description";
437 $sql .= ", fk_soc";
438 $sql .= ", fk_user_creat";
439 $sql .= ", fk_statut";
440 $sql .= ", fk_opp_status";
441 $sql .= ", opp_percent";
442 $sql .= ", public";
443 $sql .= ", datec";
444 $sql .= ", dateo";
445 $sql .= ", datee";
446 $sql .= ", opp_amount";
447 $sql .= ", budget_amount";
448 $sql .= ", usage_opportunity";
449 $sql .= ", usage_task";
450 $sql .= ", usage_bill_time";
451 $sql .= ", usage_organize_event";
452 $sql .= ", accept_conference_suggestions";
453 $sql .= ", accept_booth_suggestions";
454 $sql .= ", price_registration";
455 $sql .= ", price_booth";
456 $sql .= ", max_attendees";
457 $sql .= ", date_start_event";
458 $sql .= ", date_end_event";
459 $sql .= ", location";
460 $sql .= ", email_msgid";
461 $sql .= ", note_private";
462 $sql .= ", note_public";
463 $sql .= ", entity";
464 $sql .= ", ip";
465 $sql .= ") VALUES (";
466 $sql .= "'".$this->db->escape($this->ref)."'";
467 $sql .= ", ".($this->fk_project ? ((int) $this->fk_project) : "null");
468 $sql .= ", '".$this->db->escape($this->title)."'";
469 $sql .= ", '".$this->db->escape($this->description)."'";
470 $sql .= ", ".($this->socid > 0 ? $this->socid : "null");
471 $sql .= ", ".((int) $user->id);
472 $sql .= ", ".(is_numeric($this->statut) ? ((int) $this->statut) : '0');
473 $sql .= ", ".((is_numeric($this->opp_status) && $this->opp_status > 0) ? ((int) $this->opp_status) : 'NULL');
474 $sql .= ", ".(is_numeric($this->opp_percent) ? ((int) $this->opp_percent) : 'NULL');
475 $sql .= ", ".($this->public ? 1 : 0);
476 $sql .= ", '".$this->db->idate($now)."'";
477 $sql .= ", ".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : 'null');
478 $sql .= ", ".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : 'null');
479 $sql .= ", ".(strcmp($this->opp_amount, '') ? price2num($this->opp_amount) : 'null');
480 $sql .= ", ".(strcmp($this->budget_amount, '') ? price2num($this->budget_amount) : 'null');
481 $sql .= ", ".($this->usage_opportunity ? 1 : 0);
482 $sql .= ", ".($this->usage_task ? 1 : 0);
483 $sql .= ", ".($this->usage_bill_time ? 1 : 0);
484 $sql .= ", ".($this->usage_organize_event ? 1 : 0);
485 $sql .= ", ".($this->accept_conference_suggestions ? 1 : 0);
486 $sql .= ", ".($this->accept_booth_suggestions ? 1 : 0);
487 $sql .= ", ".(strcmp($this->price_registration, '') ? price2num($this->price_registration) : 'null');
488 $sql .= ", ".(strcmp($this->price_booth, '') ? price2num($this->price_booth) : 'null');
489 $sql .= ", ".(strcmp($this->max_attendees, '') ? ((int) $this->max_attendees) : 'null');
490 $sql .= ", ".($this->date_start_event != '' ? "'".$this->db->idate($this->date_start_event)."'" : 'null');
491 $sql .= ", ".($this->date_end_event != '' ? "'".$this->db->idate($this->date_end_event)."'" : 'null');
492 $sql .= ", ".($this->location ? "'".$this->db->escape($this->location)."'" : 'null');
493 $sql .= ", ".($this->email_msgid ? "'".$this->db->escape($this->email_msgid)."'" : 'null');
494 $sql .= ", ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : 'null');
495 $sql .= ", ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : 'null');
496 $sql .= ", ".((int) $conf->entity);
497 $sql .= ", ".(!isset($this->ip) ? 'NULL' : "'".$this->db->escape($this->ip)."'");
498 $sql .= ")";
499
500 dol_syslog(get_class($this)."::create", LOG_DEBUG);
501 $resql = $this->db->query($sql);
502 if ($resql) {
503 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
504 $ret = $this->id;
505
506 if (!$notrigger) {
507 // Call trigger
508 $result = $this->call_trigger('PROJECT_CREATE', $user);
509 if ($result < 0) {
510 $error++;
511 }
512 // End call triggers
513 }
514 } else {
515 $this->error = $this->db->lasterror();
516 $error++;
517 }
518
519 // Update extrafield
520 if (!$error) {
521 $result = $this->insertExtraFields();
522 if ($result < 0) {
523 $error++;
524 }
525 }
526
527 if (!$error && (getDolGlobalString('MAIN_DISABLEDRAFTSTATUS') || getDolGlobalString('MAIN_DISABLEDRAFTSTATUS_PROJECT'))) {
528 $res = $this->setValid($user);
529 if ($res < 0) {
530 $error++;
531 }
532 }
533
534 if (!$error) {
535 $this->db->commit();
536 return $ret;
537 } else {
538 $this->db->rollback();
539 return -1;
540 }
541 }
542
550 public function update($user, $notrigger = 0)
551 {
552 global $langs, $conf;
553
554 $error = 0;
555
556 // Clean parameters
557 $this->title = trim($this->title);
558 $this->description = trim($this->description);
559 if ($this->opp_amount < 0) {
560 $this->opp_amount = '';
561 }
562 if ($this->opp_percent < 0) {
563 $this->opp_percent = '';
564 }
565 if ($this->date_end && $this->date_end < $this->date_start) {
566 $this->error = $langs->trans("ErrorDateEndLowerThanDateStart");
567 $this->errors[] = $this->error;
568 $this->db->rollback();
569 dol_syslog(get_class($this)."::update error -3 ".$this->error, LOG_ERR);
570 return -3;
571 }
572
573 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
574
575 if (dol_strlen(trim($this->ref)) > 0) {
576 $this->db->begin();
577
578 $sql = "UPDATE ".MAIN_DB_PREFIX."projet SET";
579 $sql .= " ref='".$this->db->escape($this->ref)."'";
580 $sql .= ", fk_project=".($this->fk_project ? ((int) $this->fk_project) : "null");
581 $sql .= ", title = '".$this->db->escape($this->title)."'";
582 $sql .= ", description = '".$this->db->escape($this->description)."'";
583 $sql .= ", fk_soc = ".($this->socid > 0 ? $this->socid : "null");
584 $sql .= ", fk_statut = ".((int) $this->statut);
585 $sql .= ", fk_opp_status = ".((is_numeric($this->opp_status) && $this->opp_status > 0) ? $this->opp_status : 'null');
586 $sql .= ", opp_percent = ".((is_numeric($this->opp_percent) && $this->opp_percent != '') ? $this->opp_percent : 'null');
587 $sql .= ", public = ".($this->public ? 1 : 0);
588 $sql .= ", datec = ".($this->date_c != '' ? "'".$this->db->idate($this->date_c)."'" : 'null');
589 $sql .= ", dateo = ".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : 'null');
590 $sql .= ", datee = ".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : 'null');
591 $sql .= ", date_close = ".($this->date_close != '' ? "'".$this->db->idate($this->date_close)."'" : 'null');
592 $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
593 $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
594 $sql .= ", fk_user_close = ".($this->fk_user_close > 0 ? $this->fk_user_close : "null");
595 $sql .= ", opp_amount = ".(strcmp($this->opp_amount, '') ? price2num($this->opp_amount) : "null");
596 $sql .= ", budget_amount = ".(strcmp($this->budget_amount, '') ? price2num($this->budget_amount) : "null");
597 $sql .= ", fk_user_modif = ".$user->id;
598 $sql .= ", usage_opportunity = ".($this->usage_opportunity ? 1 : 0);
599 $sql .= ", usage_task = ".($this->usage_task ? 1 : 0);
600 $sql .= ", usage_bill_time = ".($this->usage_bill_time ? 1 : 0);
601 $sql .= ", usage_organize_event = ".($this->usage_organize_event ? 1 : 0);
602 $sql .= ", accept_conference_suggestions = ".($this->accept_conference_suggestions ? 1 : 0);
603 $sql .= ", accept_booth_suggestions = ".($this->accept_booth_suggestions ? 1 : 0);
604 $sql .= ", price_registration = ".(strcmp($this->price_registration, '') ? price2num($this->price_registration) : "null");
605 $sql .= ", price_booth = ".(strcmp($this->price_booth, '') ? price2num($this->price_booth) : "null");
606 $sql .= ", max_attendees = ".(strcmp($this->max_attendees, '') ? price2num($this->max_attendees) : "null");
607 $sql .= ", date_start_event = ".($this->date_start_event != '' ? "'".$this->db->idate($this->date_start_event)."'" : 'null');
608 $sql .= ", date_end_event = ".($this->date_end_event != '' ? "'".$this->db->idate($this->date_end_event)."'" : 'null');
609 $sql .= ", location = '".$this->db->escape($this->location)."'";
610 $sql .= ", entity = ".((int) $this->entity);
611 $sql .= " WHERE rowid = ".((int) $this->id);
612
613 dol_syslog(get_class($this)."::update", LOG_DEBUG);
614 $resql = $this->db->query($sql);
615 if ($resql) {
616 // Update extrafield
617 if (!$error) {
618 $result = $this->insertExtraFields();
619 if ($result < 0) {
620 $error++;
621 }
622 }
623
624 if (!$error && !$notrigger) {
625 // Call trigger
626 $result = $this->call_trigger('PROJECT_MODIFY', $user);
627 if ($result < 0) {
628 $error++;
629 }
630 // End call triggers
631 }
632
633 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
634 // We remove directory
635 if ($conf->project->dir_output) {
636 $olddir = $conf->project->dir_output."/".dol_sanitizeFileName($this->oldcopy->ref);
637 $newdir = $conf->project->dir_output."/".dol_sanitizeFileName($this->ref);
638 if (file_exists($olddir)) {
639 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
640 $res = @rename($olddir, $newdir);
641 if (!$res) {
642 $langs->load("errors");
643 $this->error = $langs->trans('ErrorFailToRenameDir', $olddir, $newdir);
644 $error++;
645 }
646 }
647 }
648 }
649 if (!$error) {
650 $this->db->commit();
651 $result = 1;
652 } else {
653 $this->db->rollback();
654 $result = -1;
655 }
656 } else {
657 $this->error = $this->db->lasterror();
658 $this->errors[] = $this->error;
659 $this->db->rollback();
660 if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
661 $result = -4;
662 } else {
663 $result = -2;
664 }
665 dol_syslog(get_class($this)."::update error ".$result." ".$this->error, LOG_ERR);
666 }
667 } else {
668 dol_syslog(get_class($this)."::update ref null");
669 $result = -1;
670 }
671
672 return $result;
673 }
674
684 public function fetch($id, $ref = '', $ref_ext = '', $email_msgid = '')
685 {
686 if (empty($id) && empty($ref) && empty($ref_ext) && empty($email_msgid)) {
687 dol_syslog(get_class($this)."::fetch Bad parameters", LOG_WARNING);
688 return -1;
689 }
690
691 $sql = "SELECT rowid, entity, fk_project, ref, title, description, public, datec, opp_amount, budget_amount,";
692 $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,";
693 $sql .= " note_private, note_public, model_pdf, usage_opportunity, usage_task, usage_bill_time, usage_organize_event, email_msgid,";
694 $sql .= " accept_conference_suggestions, accept_booth_suggestions, price_registration, price_booth, max_attendees, date_start_event, date_end_event, location, extraparams";
695 $sql .= " FROM ".MAIN_DB_PREFIX."projet";
696 if (!empty($id)) {
697 $sql .= " WHERE rowid = ".((int) $id);
698 } else {
699 $sql .= " WHERE entity IN (".getEntity('project').")";
700 if (!empty($ref)) {
701 $sql .= " AND ref = '".$this->db->escape($ref)."'";
702 } elseif (!empty($ref_ext)) {
703 $sql .= " AND ref_ext = '".$this->db->escape($ref_ext)."'";
704 } else {
705 $sql .= " AND email_msgid = '".$this->db->escape($email_msgid)."'";
706 }
707 }
708
709 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
710 $resql = $this->db->query($sql);
711 if ($resql) {
712 $num_rows = $this->db->num_rows($resql);
713
714 if ($num_rows) {
715 $obj = $this->db->fetch_object($resql);
716
717 $this->id = $obj->rowid;
718 $this->entity = $obj->entity;
719 $this->ref = $obj->ref;
720 $this->fk_project = $obj->fk_project;
721 $this->title = $obj->title;
722 $this->description = $obj->description;
723 $this->date_c = $this->db->jdate($obj->datec);
724 $this->datec = $this->db->jdate($obj->datec); // TODO deprecated
725 $this->date_m = $this->db->jdate($obj->tms);
726 $this->datem = $this->db->jdate($obj->tms); // TODO deprecated
727 $this->date_start = $this->db->jdate($obj->date_start);
728 $this->date_end = $this->db->jdate($obj->date_end);
729 $this->date_close = $this->db->jdate($obj->date_close);
730 $this->note_private = $obj->note_private;
731 $this->note_public = $obj->note_public;
732 $this->socid = $obj->fk_soc;
733 $this->user_author_id = $obj->fk_user_creat;
734 $this->user_modification_id = $obj->fk_user_modif;
735 $this->user_closing_id = $obj->fk_user_close;
736 $this->public = $obj->public;
737 $this->statut = $obj->status; // deprecated
738 $this->status = $obj->status;
739 $this->opp_status = $obj->fk_opp_status;
740 $this->opp_amount = $obj->opp_amount;
741 $this->opp_percent = $obj->opp_percent;
742 $this->budget_amount = $obj->budget_amount;
743 $this->model_pdf = $obj->model_pdf;
744 $this->usage_opportunity = (int) $obj->usage_opportunity;
745 $this->usage_task = (int) $obj->usage_task;
746 $this->usage_bill_time = (int) $obj->usage_bill_time;
747 $this->usage_organize_event = (int) $obj->usage_organize_event;
748 $this->accept_conference_suggestions = (int) $obj->accept_conference_suggestions;
749 $this->accept_booth_suggestions = (int) $obj->accept_booth_suggestions;
750 $this->price_registration = $obj->price_registration;
751 $this->price_booth = $obj->price_booth;
752 $this->max_attendees = $obj->max_attendees;
753 $this->date_start_event = $this->db->jdate($obj->date_start_event);
754 $this->date_end_event = $this->db->jdate($obj->date_end_event);
755 $this->location = $obj->location;
756 $this->email_msgid = $obj->email_msgid;
757 $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams, true) : array();
758
759 $this->db->free($resql);
760
761 // Retrieve all extrafield
762 // fetch optionals attributes and labels
763 $this->fetch_optionals();
764
765 return 1;
766 }
767
768 $this->db->free($resql);
769
770 return 0;
771 } else {
772 $this->error = $this->db->lasterror();
773 $this->errors[] = $this->db->lasterror();
774 return -1;
775 }
776 }
777
786 public function fetchAndSetSubstitution($id, $key, $fetched = false)
787 {
788 $substitution = '';
789
790 if ($fetched === false) {
791 $res = $this->fetch($id);
792 if ($res > 0) {
793 $fetched = true;
794 }
795 }
796
797 if ($fetched === true) {
798 if ($key == '__PROJECT_ID__') {
799 $substitution = ($this->id > 0 ? $this->id : '');
800 } elseif ($key == '__PROJECT_REF__') {
801 $substitution = $this->ref;
802 } elseif ($key == '__PROJECT_NAME__') {
803 $substitution = $this->title;
804 }
805 }
806
807 return $substitution;
808 }
809
810 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
822 public function get_element_list($type, $tablename, $datefieldname = '', $date_start = '', $date_end = '', $projectkey = 'fk_projet')
823 {
824 // phpcs:enable
825
826 global $hookmanager;
827
828 $elements = array();
829
830 if ($this->id <= 0) {
831 return $elements;
832 }
833
834 $ids = $this->id;
835
836 if ($type == 'agenda') {
837 $sql = "SELECT id as rowid FROM ".MAIN_DB_PREFIX."actioncomm WHERE fk_project IN (".$this->db->sanitize($ids).") AND entity IN (".getEntity('agenda').")";
838 } elseif ($type == 'expensereport') {
839 $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).")";
840 } elseif ($type == 'project_task') {
841 $sql = "SELECT DISTINCT pt.rowid FROM ".MAIN_DB_PREFIX."projet_task as pt WHERE pt.fk_projet IN (".$this->db->sanitize($ids).")";
842 } elseif ($type == 'element_time') { // Case we want to duplicate line foreach user
843 $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).")";
844 } elseif ($type == 'stocktransfer_stocktransfer') {
845 $sql = "SELECT ms.rowid, ms.fk_user_author as fk_user FROM ".MAIN_DB_PREFIX."stocktransfer_stocktransfer 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";
846 } elseif ($type == 'loan') {
847 $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).")";
848 } else {
849 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$tablename." WHERE ".$projectkey." IN (".$this->db->sanitize($ids).") AND entity IN (".getEntity($type).")";
850 }
851
852 if ($date_start > 0 && $type == 'loan') {
853 $sql .= " AND (dateend > '".$this->db->idate($date_start)."' OR dateend IS NULL)";
854 } elseif ($date_start > 0 && ($type != 'project_task')) { // For table project_taks, we want the filter on date apply on project_time_spent table
855 if (empty($datefieldname) && !empty($this->table_element_date)) {
856 $datefieldname = $this->table_element_date;
857 }
858 if (empty($datefieldname)) {
859 return 'Error this object has no date field defined';
860 }
861 $sql .= " AND (".$datefieldname." >= '".$this->db->idate($date_start)."' OR ".$datefieldname." IS NULL)";
862 }
863
864 if ($date_end > 0 && $type == 'loan') {
865 $sql .= " AND (datestart < '".$this->db->idate($date_end)."' OR datestart IS NULL)";
866 } elseif ($date_end > 0 && ($type != 'project_task')) { // For table project_taks, we want the filter on date apply on project_time_spent table
867 if (empty($datefieldname) && !empty($this->table_element_date)) {
868 $datefieldname = $this->table_element_date;
869 }
870 if (empty($datefieldname)) {
871 return 'Error this object has no date field defined';
872 }
873 $sql .= " AND (".$datefieldname." <= '".$this->db->idate($date_end)."' OR ".$datefieldname." IS NULL)";
874 }
875
876 $parameters = array(
877 'sql'=>$sql,
878 'type' => $type,
879 'tablename' => $tablename,
880 'datefieldname' => $datefieldname,
881 'dates' => $date_start,
882 'datee' => $date_end,
883 'fk_projet' => $projectkey,
884 'ids' => $ids,
885 );
886 $reshook = $hookmanager->executeHooks('getElementList', $parameters);
887 if ($reshook > 0) {
888 $sql = $hookmanager->resPrint;
889 } else {
890 $sql .= $hookmanager->resPrint;
891 }
892
893 if (!$sql) {
894 return -1;
895 }
896
897 //print $sql;
898 dol_syslog(get_class($this)."::get_element_list", LOG_DEBUG);
899 $result = $this->db->query($sql);
900 if ($result) {
901 $nump = $this->db->num_rows($result);
902 if ($nump) {
903 $i = 0;
904 while ($i < $nump) {
905 $obj = $this->db->fetch_object($result);
906
907 $elements[$i] = $obj->rowid.(empty($obj->fk_user) ? '' : '_'.$obj->fk_user);
908
909 $i++;
910 }
911 $this->db->free($result);
912 }
913
914 /* Return array even if empty*/
915 return $elements;
916 } else {
917 dol_print_error($this->db);
918 }
919 }
920
928 public function delete($user, $notrigger = 0)
929 {
930 global $langs, $conf;
931 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
932
933 $error = 0;
934
935 $this->db->begin();
936
937 if (!$error) {
938 // Delete linked contacts
939 $res = $this->delete_linked_contact();
940 if ($res < 0) {
941 $this->error = 'ErrorFailToDeleteLinkedContact';
942 //$error++;
943 $this->db->rollback();
944 return 0;
945 }
946 }
947
948 // Set fk_projet into elements to null
949 $listoftables = array(
950 'propal' => 'fk_projet',
951 'commande' => 'fk_projet',
952 'facture' => 'fk_projet',
953 'supplier_proposal' => 'fk_projet',
954 'commande_fournisseur' => 'fk_projet',
955 'facture_fourn' => 'fk_projet',
956 'expensereport_det' => 'fk_projet',
957 'contrat' => 'fk_projet',
958 'fichinter' => 'fk_projet',
959 'don' => array('field' => 'fk_projet', 'module' => 'don'),
960 'actioncomm' => 'fk_project',
961 'mrp_mo' => array('field' => 'fk_project', 'module' => 'mrp'),
962 'entrepot' => 'fk_project',
963 );
964 foreach ($listoftables as $key => $value) {
965 if (is_array($value)) {
966 if (!isModEnabled($value['module'])) {
967 continue;
968 }
969 $fieldname = $value['field'];
970 } else {
971 $fieldname = $value;
972 }
973 $sql = "UPDATE ".MAIN_DB_PREFIX.$key." SET ".$fieldname." = NULL where ".$fieldname." = ".((int) $this->id);
974
975 $resql = $this->db->query($sql);
976 if (!$resql) {
977 $this->errors[] = $this->db->lasterror();
978 $error++;
979 break;
980 }
981 }
982
983 // Remove linked categories.
984 if (!$error) {
985 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_project";
986 $sql .= " WHERE fk_project = ".((int) $this->id);
987
988 $result = $this->db->query($sql);
989 if (!$result) {
990 $error++;
991 $this->errors[] = $this->db->lasterror();
992 }
993 }
994
995 // Fetch tasks
996 $this->getLinesArray($user, 0);
997
998 // Delete tasks
999 $ret = $this->deleteTasks($user);
1000 if ($ret < 0) {
1001 $error++;
1002 }
1003
1004
1005 // Delete all child tables
1006 if (!$error) {
1007 $elements = array('categorie_project'); // elements to delete. TODO Make goodway to delete
1008 foreach ($elements as $table) {
1009 if (!$error) {
1010 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
1011 $sql .= " WHERE fk_project = ".((int) $this->id);
1012
1013 $result = $this->db->query($sql);
1014 if (!$result) {
1015 $error++;
1016 $this->errors[] = $this->db->lasterror();
1017 }
1018 }
1019 }
1020 }
1021
1022 if (!$error) {
1023 $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_extrafields";
1024 $sql .= " WHERE fk_object = ".((int) $this->id);
1025
1026 $resql = $this->db->query($sql);
1027 if (!$resql) {
1028 $this->errors[] = $this->db->lasterror();
1029 $error++;
1030 }
1031 }
1032
1033 // Delete project
1034 if (!$error) {
1035 $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet";
1036 $sql .= " WHERE rowid=".((int) $this->id);
1037
1038 $resql = $this->db->query($sql);
1039 if (!$resql) {
1040 $this->errors[] = $langs->trans("CantRemoveProject", $langs->transnoentitiesnoconv("ProjectOverview"));
1041 $error++;
1042 }
1043 }
1044
1045
1046
1047 if (empty($error)) {
1048 // We remove directory
1049 $projectref = dol_sanitizeFileName($this->ref);
1050 if ($conf->project->dir_output) {
1051 $dir = $conf->project->dir_output."/".$projectref;
1052 if (file_exists($dir)) {
1053 $res = @dol_delete_dir_recursive($dir);
1054 if (!$res) {
1055 $this->errors[] = 'ErrorFailToDeleteDir';
1056 $error++;
1057 }
1058 }
1059 }
1060
1061 if (!$notrigger) {
1062 // Call trigger
1063 $result = $this->call_trigger('PROJECT_DELETE', $user);
1064
1065 if ($result < 0) {
1066 $error++;
1067 }
1068 // End call triggers
1069 }
1070 }
1071
1072 if (empty($error)) {
1073 $this->db->commit();
1074 return 1;
1075 } else {
1076 foreach ($this->errors as $errmsg) {
1077 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
1078 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1079 }
1080 dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
1081 $this->db->rollback();
1082 return -1;
1083 }
1084 }
1085
1094 public function getElementCount($type, $tablename, $projectkey = 'fk_projet')
1095 {
1096 if ($this->id <= 0) {
1097 return 0;
1098 }
1099
1100 if ($type == 'agenda') {
1101 $sql = "SELECT COUNT(id) as nb FROM ".MAIN_DB_PREFIX."actioncomm WHERE fk_project = ".((int) $this->id)." AND entity IN (".getEntity('agenda').")";
1102 } elseif ($type == 'expensereport') {
1103 $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);
1104 } elseif ($type == 'project_task') {
1105 $sql = "SELECT DISTINCT COUNT(pt.rowid) as nb FROM ".MAIN_DB_PREFIX."projet_task as pt WHERE pt.fk_projet = ".((int) $this->id);
1106 } elseif ($type == 'element_time') { // Case we want to duplicate line foreach user
1107 $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);
1108 } elseif ($type == 'stock_mouvement') {
1109 $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";
1110 } elseif ($type == 'loan') {
1111 $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);
1112 } else {
1113 $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.$tablename." WHERE ".$projectkey." = ".((int) $this->id)." AND entity IN (".getEntity($type).")";
1114 }
1115
1116 $result = $this->db->query($sql);
1117
1118 if (!$result) {
1119 return 0;
1120 }
1121
1122 $obj = $this->db->fetch_object($result);
1123
1124 $this->db->free($result);
1125
1126 return $obj->nb;
1127 }
1128
1135 public function deleteTasks($user)
1136 {
1137 $countTasks = count($this->lines);
1138 $deleted = false;
1139 if ($countTasks) {
1140 foreach ($this->lines as $task) {
1141 if ($task->hasChildren() <= 0) { // If there is no children (or error to detect them)
1142 $deleted = true;
1143 $ret = $task->delete($user);
1144 if ($ret <= 0) {
1145 $this->errors[] = $this->db->lasterror();
1146 return -1;
1147 }
1148 }
1149 }
1150 }
1151 $this->getLinesArray($user);
1152 if ($deleted && count($this->lines) < $countTasks) {
1153 if (count($this->lines)) {
1154 $this->deleteTasks($this->lines);
1155 }
1156 }
1157
1158 return 1;
1159 }
1160
1168 public function setValid($user, $notrigger = 0)
1169 {
1170 global $langs, $conf;
1171
1172 $error = 0;
1173
1174 // Protection
1175 if ($this->status == self::STATUS_VALIDATED) {
1176 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
1177 return 0;
1178 }
1179
1180 // Check parameters
1181 if (preg_match('/^'.preg_quote($langs->trans("CopyOf").' ').'/', $this->title)) {
1182 $this->error = $langs->trans("ErrorFieldFormat", $langs->transnoentities("Label")).'. '.$langs->trans('RemoveString', $langs->transnoentitiesnoconv("CopyOf"));
1183 return -1;
1184 }
1185
1186 $this->db->begin();
1187
1188 $sql = "UPDATE ".MAIN_DB_PREFIX."projet";
1189 $sql .= " SET fk_statut = ".self::STATUS_VALIDATED;
1190 $sql .= " WHERE rowid = ".((int) $this->id);
1191 //$sql .= " AND entity = ".((int) $conf->entity); // Disabled, when we use the ID for the where, we must not add any other search condition
1192
1193 dol_syslog(get_class($this)."::setValid", LOG_DEBUG);
1194 $resql = $this->db->query($sql);
1195 if ($resql) {
1196 // Call trigger
1197 if (empty($notrigger)) {
1198 $result = $this->call_trigger('PROJECT_VALIDATE', $user);
1199 if ($result < 0) {
1200 $error++;
1201 }
1202 // End call triggers
1203 }
1204
1205 if (!$error) {
1206 $this->statut = 1;
1207 $this->db->commit();
1208 return 1;
1209 } else {
1210 $this->db->rollback();
1211 $this->error = join(',', $this->errors);
1212 dol_syslog(get_class($this)."::setValid ".$this->error, LOG_ERR);
1213 return -1;
1214 }
1215 } else {
1216 $this->db->rollback();
1217 $this->error = $this->db->lasterror();
1218 return -1;
1219 }
1220 }
1221
1228 public function setClose($user)
1229 {
1230 global $langs, $conf;
1231
1232 $now = dol_now();
1233
1234 $error = 0;
1235
1236 if ($this->statut != self::STATUS_CLOSED) {
1237 $this->db->begin();
1238
1239 $sql = "UPDATE ".MAIN_DB_PREFIX."projet";
1240 $sql .= " SET fk_statut = ".self::STATUS_CLOSED.", fk_user_close = ".((int) $user->id).", date_close = '".$this->db->idate($now)."'";
1241 $sql .= " WHERE rowid = ".((int) $this->id);
1242 $sql .= " AND fk_statut = ".self::STATUS_VALIDATED;
1243
1244 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
1245 // TODO What to do if fk_opp_status is not code 'WON' or 'LOST'
1246 }
1247
1248 dol_syslog(get_class($this)."::setClose", LOG_DEBUG);
1249 $resql = $this->db->query($sql);
1250 if ($resql) {
1251 // Call trigger
1252 $result = $this->call_trigger('PROJECT_CLOSE', $user);
1253 if ($result < 0) {
1254 $error++;
1255 }
1256 // End call triggers
1257
1258 if (!$error) {
1259 $this->statut = 2;
1260 $this->db->commit();
1261 return 1;
1262 } else {
1263 $this->db->rollback();
1264 $this->error = join(',', $this->errors);
1265 dol_syslog(get_class($this)."::setClose ".$this->error, LOG_ERR);
1266 return -1;
1267 }
1268 } else {
1269 $this->db->rollback();
1270 $this->error = $this->db->lasterror();
1271 return -1;
1272 }
1273 }
1274
1275 return 0;
1276 }
1277
1284 public function getLibStatut($mode = 0)
1285 {
1286 return $this->LibStatut(isset($this->statut) ? $this->statut : $this->status, $mode);
1287 }
1288
1289 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1297 public function LibStatut($status, $mode = 0)
1298 {
1299 // phpcs:enable
1300 global $langs;
1301
1302 if (is_null($status)) {
1303 return '';
1304 }
1305
1306 $statustrans = array(
1307 0 => 'status0',
1308 1 => 'status4',
1309 2 => 'status6',
1310 );
1311
1312 $statusClass = 'status0';
1313 if (!empty($statustrans[$status])) {
1314 $statusClass = $statustrans[$status];
1315 }
1316
1317 return dolGetStatus($langs->transnoentitiesnoconv($this->labelStatus[$status]), $langs->transnoentitiesnoconv($this->labelStatusShort[$status]), '', $statusClass, $mode);
1318 }
1319
1327 public function getTooltipContentArray($params)
1328 {
1329 global $conf, $langs;
1330
1331 $langs->load('projects');
1332 $option = $params['option'] ?? '';
1333 $moreinpopup = $params['moreinpopup'] ?? '';
1334
1335 $datas = [];
1336 if ($option != 'nolink') {
1337 $datas['picto'] = img_picto('', $this->picto, 'class="pictofixedwidth"').' <u class="paddingrightonly">'.$langs->trans("Project").'</u>';
1338 }
1339 if (isset($this->status)) {
1340 $datas['picto'] .= ' '.$this->getLibStatut(5);
1341 }
1342 $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
1343 $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
1344 if (isset($this->public)) {
1345 $datas['visibility'] = '<br><b>'.$langs->trans("Visibility").":</b> ";
1346 $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"));
1347 }
1348 if (!empty($this->thirdparty_name)) {
1349 $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
1350 }
1351 if (!empty($this->date_start)) {
1352 $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
1353 }
1354 if (!empty($this->date_end)) {
1355 $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
1356 }
1357 if ($moreinpopup) {
1358 $datas['moreinpopup'] = '<br>'.$moreinpopup;
1359 }
1360
1361 return $datas;
1362 }
1363
1378 public function getNomUrl($withpicto = 0, $option = '', $addlabel = 0, $moreinpopup = '', $sep = ' - ', $notooltip = 0, $save_lastsearch_value = -1, $morecss = '', $save_pageforbacktolist = '')
1379 {
1380 global $conf, $langs, $user, $hookmanager;
1381
1382 if (!empty($conf->dol_no_mouse_hover)) {
1383 $notooltip = 1; // Force disable tooltips
1384 }
1385
1386 $result = '';
1387 if (getDolGlobalString('PROJECT_OPEN_ALWAYS_ON_TAB')) {
1388 $option = $conf->global->PROJECT_OPEN_ALWAYS_ON_TAB;
1389 }
1390 $params = [
1391 'id' => $this->id,
1392 'objecttype' => $this->element,
1393 'moreinpopup' => $moreinpopup,
1394 'option' => $option,
1395 ];
1396 $classfortooltip = 'classfortooltip';
1397 $dataparams = '';
1398 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1399 $classfortooltip = 'classforajaxtooltip';
1400 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1401 $label = '';
1402 } else {
1403 $label = implode($this->getTooltipContentArray($params));
1404 }
1405
1406 $url = '';
1407 if ($option != 'nolink') {
1408 if (preg_match('/\.php$/', $option)) {
1409 $url = dol_buildpath($option, 1).'?id='.$this->id;
1410 } elseif ($option == 'task') {
1411 $url = DOL_URL_ROOT.'/projet/tasks.php?id='.$this->id;
1412 } elseif ($option == 'preview') {
1413 $url = DOL_URL_ROOT.'/projet/element.php?id='.$this->id;
1414 } elseif ($option == 'eventorganization') {
1415 $url = DOL_URL_ROOT.'/eventorganization/conferenceorbooth_list.php?projectid='.$this->id;
1416 } else {
1417 $url = DOL_URL_ROOT.'/projet/card.php?id='.$this->id;
1418 }
1419 // Add param to save lastsearch_values or not
1420 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1421 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1422 $add_save_lastsearch_values = 1;
1423 }
1424 if ($add_save_lastsearch_values) {
1425 $url .= '&save_lastsearch_values=1';
1426 }
1427 $add_save_backpagefor = ($save_pageforbacktolist ? 1 : 0);
1428 if ($add_save_backpagefor) {
1429 $url .= "&save_pageforbacktolist=".urlencode($save_pageforbacktolist);
1430 }
1431 }
1432
1433 $linkclose = '';
1434 if (empty($notooltip) && $user->hasRight('projet', 'lire')) {
1435 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1436 $label = $langs->trans("ShowProject");
1437 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1438 }
1439 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
1440 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1441 } else {
1442 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1443 }
1444
1445 $picto = 'projectpub';
1446 if (!$this->public) {
1447 $picto = 'project';
1448 }
1449
1450 $linkstart = '<a href="'.$url.'"';
1451 $linkstart .= $linkclose.'>';
1452 $linkend = '</a>';
1453
1454 $result .= $linkstart;
1455 if ($withpicto) {
1456 $result .= img_object(($notooltip ? '' : $label), $picto, 'class="pictofixedwidth em088"', 0, 0, $notooltip ? 0 : 1);
1457 }
1458 if ($withpicto != 2) {
1459 $result .= $this->ref;
1460 }
1461 $result .= $linkend;
1462 if ($withpicto != 2) {
1463 $result .= (($addlabel && $this->title) ? '<span class="opacitymedium">'.$sep.dol_trunc($this->title, ($addlabel > 1 ? $addlabel : 0)).'</span>' : '');
1464 }
1465
1466 global $action;
1467 $hookmanager->initHooks(array('projectdao'));
1468 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1469 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1470 if ($reshook > 0) {
1471 $result = $hookmanager->resPrint;
1472 } else {
1473 $result .= $hookmanager->resPrint;
1474 }
1475
1476 return $result;
1477 }
1478
1486 public function initAsSpecimen()
1487 {
1488 global $user, $langs, $conf;
1489
1490 $now = dol_now();
1491
1492 // Initialise parameters
1493 $this->id = 0;
1494 $this->ref = 'SPECIMEN';
1495 $this->entity = $conf->entity;
1496 $this->specimen = 1;
1497 $this->socid = 1;
1498 $this->date_c = $now;
1499 $this->date_m = $now;
1500 $this->date_start = $now;
1501 $this->date_end = $now + (3600 * 24 * 365);
1502 $this->note_public = 'SPECIMEN';
1503 $this->fk_element = 20000;
1504 $this->opp_amount = 20000;
1505 $this->budget_amount = 10000;
1506
1507 $this->usage_opportunity = 1;
1508 $this->usage_task = 1;
1509 $this->usage_bill_time = 1;
1510 $this->usage_organize_event = 1;
1511
1512 /*
1513 $nbp = mt_rand(1, 9);
1514 $xnbp = 0;
1515 while ($xnbp < $nbp)
1516 {
1517 $line = new Task($this->db);
1518 $line->fk_project = 0;
1519 $line->label = $langs->trans("Label") . " " . $xnbp;
1520 $line->description = $langs->trans("Description") . " " . $xnbp;
1521
1522 $this->lines[]=$line;
1523 $xnbp++;
1524 }
1525 */
1526 }
1527
1535 public function restrictedProjectArea(User $user, $mode = 'read')
1536 {
1537 // To verify role of users
1538 $userAccess = 0;
1539 if (($mode == 'read' && $user->hasRight('projet', 'all', 'lire')) || ($mode == 'write' && $user->hasRight('projet', 'all', 'creer')) || ($mode == 'delete' && $user->hasRight('projet', 'all', 'supprimer'))) {
1540 $userAccess = 1;
1541 } elseif ($this->public && (($mode == 'read' && $user->hasRight('projet', 'lire')) || ($mode == 'write' && $user->hasRight('projet', 'creer')) || ($mode == 'delete' && $user->hasRight('projet', 'supprimer')))) {
1542 $userAccess = 1;
1543 } else { // No access due to permission to read all projects, so we check if we are a contact of project
1544 foreach (array('internal', 'external') as $source) {
1545 $userRole = $this->liste_contact(4, $source);
1546 $num = count($userRole);
1547
1548 $nblinks = 0;
1549 while ($nblinks < $num) {
1550 if ($source == 'internal' && $user->id == $userRole[$nblinks]['id']) { // $userRole[$nblinks]['id'] is id of user (llx_user) for internal contacts
1551 if ($mode == 'read' && $user->hasRight('projet', 'lire')) {
1552 $userAccess++;
1553 }
1554 if ($mode == 'write' && $user->hasRight('projet', 'creer')) {
1555 $userAccess++;
1556 }
1557 if ($mode == 'delete' && $user->hasRight('projet', 'supprimer')) {
1558 $userAccess++;
1559 }
1560 }
1561 if ($source == 'external' && $user->socid > 0 && $user->socid == $userRole[$nblinks]['socid']) { // $userRole[$nblinks]['id'] is id of contact (llx_socpeople) or external contacts
1562 if ($mode == 'read' && $user->hasRight('projet', 'lire')) {
1563 $userAccess++;
1564 }
1565 if ($mode == 'write' && $user->hasRight('projet', 'creer')) {
1566 $userAccess++;
1567 }
1568 if ($mode == 'delete' && $user->hasRight('projet', 'supprimer')) {
1569 $userAccess++;
1570 }
1571 }
1572 $nblinks++;
1573 }
1574 }
1575 //if (empty($nblinks)) // If nobody has permission, we grant creator
1576 //{
1577 // if ((!empty($this->user_author_id) && $this->user_author_id == $user->id))
1578 // {
1579 // $userAccess = 1;
1580 // }
1581 //}
1582 }
1583
1584 return ($userAccess ? $userAccess : -1);
1585 }
1586
1597 public function getProjectsAuthorizedForUser($user, $mode = 0, $list = 0, $socid = 0, $filter = '')
1598 {
1599 $projects = array();
1600 $temp = array();
1601
1602 $sql = "SELECT ".(($mode == 0 || $mode == 1) ? "DISTINCT " : "")."p.rowid, p.ref";
1603 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
1604 if ($mode == 0) {
1605 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact as ec ON ec.element_id = p.rowid";
1606 } elseif ($mode == 1) {
1607 $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
1608 } elseif ($mode == 2) {
1609 // No filter. Use this if user has permission to see all project
1610 }
1611 $sql .= " WHERE p.entity IN (".getEntity('project').")";
1612 // Internal users must see project he is contact to even if project linked to a third party he can't see.
1613 //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).")";
1614 if ($socid > 0) {
1615 $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
1616 }
1617
1618 // Get id of types of contacts for projects (This list never contains a lot of elements)
1619 $listofprojectcontacttype = array();
1620 $sql2 = "SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
1621 $sql2 .= " WHERE ctc.element = '".$this->db->escape($this->element)."'";
1622 $sql2 .= " AND ctc.source = 'internal'";
1623 $resql = $this->db->query($sql2);
1624 if ($resql) {
1625 while ($obj = $this->db->fetch_object($resql)) {
1626 $listofprojectcontacttype[$obj->rowid] = $obj->code;
1627 }
1628 } else {
1629 dol_print_error($this->db);
1630 }
1631 if (count($listofprojectcontacttype) == 0) {
1632 $listofprojectcontacttype[0] = '0'; // To avoid syntax error if not found
1633 }
1634
1635 if ($mode == 0) {
1636 $sql .= " AND ( p.public = 1";
1637 $sql .= " OR ( ec.fk_c_type_contact IN (".$this->db->sanitize(join(',', array_keys($listofprojectcontacttype))).")";
1638 $sql .= " AND ec.fk_socpeople = ".((int) $user->id).")";
1639 $sql .= " )";
1640 } elseif ($mode == 1) {
1641 $sql .= " AND ec.element_id = p.rowid";
1642 $sql .= " AND (";
1643 $sql .= " ( ec.fk_c_type_contact IN (".$this->db->sanitize(join(',', array_keys($listofprojectcontacttype))).")";
1644 $sql .= " AND ec.fk_socpeople = ".((int) $user->id).")";
1645 $sql .= " )";
1646 } elseif ($mode == 2) {
1647 // No filter. Use this if user has permission to see all project
1648 }
1649
1650 $sql .= $filter;
1651 //print $sql;
1652
1653 $resql = $this->db->query($sql);
1654 if ($resql) {
1655 $num = $this->db->num_rows($resql);
1656 $i = 0;
1657 while ($i < $num) {
1658 $row = $this->db->fetch_row($resql);
1659 $projects[$row[0]] = $row[1];
1660 $temp[] = $row[0];
1661 $i++;
1662 }
1663
1664 $this->db->free($resql);
1665
1666 if ($list) {
1667 if (empty($temp)) {
1668 return '0';
1669 }
1670 $result = implode(',', $temp);
1671 return $result;
1672 }
1673 } else {
1674 dol_print_error($this->db);
1675 }
1676
1677 return $projects;
1678 }
1679
1695 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)
1696 {
1697 global $langs, $conf;
1698
1699 $error = 0;
1700
1701 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);
1702
1703 $now = dol_mktime(0, 0, 0, idate('m', dol_now()), idate('d', dol_now()), idate('Y', dol_now()));
1704
1705 $clone_project = new Project($this->db);
1706
1707 $clone_project->context['createfromclone'] = 'createfromclone';
1708
1709 $this->db->begin();
1710
1711 // Load source object
1712 $clone_project->fetch($fromid);
1713 $clone_project->fetch_optionals();
1714 if ($newthirdpartyid > 0) {
1715 $clone_project->socid = $newthirdpartyid;
1716 }
1717 $clone_project->fetch_thirdparty();
1718
1719 $orign_dt_start = $clone_project->date_start;
1720 $orign_project_ref = $clone_project->ref;
1721
1722 $clone_project->id = 0;
1723 if ($move_date) {
1724 $clone_project->date_start = $now;
1725 if (!(empty($clone_project->date_end))) {
1726 $clone_project->date_end = $clone_project->date_end + ($now - $orign_dt_start);
1727 }
1728 }
1729
1730 $clone_project->date_c = $now;
1731
1732 if (!$clone_note) {
1733 $clone_project->note_private = '';
1734 $clone_project->note_public = '';
1735 }
1736
1737 //Generate next ref
1738 $defaultref = '';
1739 $obj = !getDolGlobalString('PROJECT_ADDON') ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;
1740 // Search template files
1741 $file = '';
1742 $classname = '';
1743 $filefound = 0;
1744 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1745 foreach ($dirmodels as $reldir) {
1746 $file = dol_buildpath($reldir."core/modules/project/".$obj.'.php', 0);
1747 if (file_exists($file)) {
1748 $filefound = 1;
1749 dol_include_once($reldir."core/modules/project/".$obj.'.php');
1750 $modProject = new $obj();
1751 $defaultref = $modProject->getNextValue(is_object($clone_project->thirdparty) ? $clone_project->thirdparty : null, $clone_project);
1752 break;
1753 }
1754 }
1755 if (is_numeric($defaultref) && $defaultref <= 0) {
1756 $defaultref = '';
1757 }
1758
1759 $clone_project->ref = $defaultref;
1760 $clone_project->title = $langs->trans("CopyOf").' '.$clone_project->title;
1761
1762 // Create clone
1763 $result = $clone_project->create($user, $notrigger);
1764
1765 // Other options
1766 if ($result < 0) {
1767 $this->error .= $clone_project->error;
1768 $error++;
1769 }
1770
1771 if (!$error) {
1772 //Get the new project id
1773 $clone_project_id = $clone_project->id;
1774
1775 //Note Update
1776 if (!$clone_note) {
1777 $clone_project->note_private = '';
1778 $clone_project->note_public = '';
1779 } else {
1780 $this->db->begin();
1781 $res = $clone_project->update_note(dol_html_entity_decode($clone_project->note_public, ENT_QUOTES | ENT_HTML5), '_public');
1782 if ($res < 0) {
1783 $this->error .= $clone_project->error;
1784 $error++;
1785 $this->db->rollback();
1786 } else {
1787 $this->db->commit();
1788 }
1789
1790 $this->db->begin();
1791 $res = $clone_project->update_note(dol_html_entity_decode($clone_project->note_private, ENT_QUOTES | ENT_HTML5), '_private');
1792 if ($res < 0) {
1793 $this->error .= $clone_project->error;
1794 $error++;
1795 $this->db->rollback();
1796 } else {
1797 $this->db->commit();
1798 }
1799 }
1800
1801 //Duplicate contact
1802 if ($clone_contact) {
1803 $origin_project = new Project($this->db);
1804 $origin_project->fetch($fromid);
1805
1806 foreach (array('internal', 'external') as $source) {
1807 $tab = $origin_project->liste_contact(-1, $source);
1808 if (is_array($tab) && count($tab)>0) {
1809 foreach ($tab as $contacttoadd) {
1810 $clone_project->add_contact($contacttoadd['id'], $contacttoadd['code'], $contacttoadd['source'], $notrigger);
1811 if ($clone_project->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1812 $langs->load("errors");
1813 $this->error .= $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
1814 $error++;
1815 } else {
1816 if ($clone_project->error != '') {
1817 $this->error .= $clone_project->error;
1818 $error++;
1819 }
1820 }
1821 }
1822 } elseif ($tab < 0) {
1823 $this->error .= $origin_project->error;
1824 $error++;
1825 }
1826 }
1827 }
1828
1829 //Duplicate file
1830 if ($clone_project_file) {
1831 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1832
1833 $clone_project_dir = $conf->project->dir_output."/".dol_sanitizeFileName($defaultref);
1834 $ori_project_dir = $conf->project->dir_output."/".dol_sanitizeFileName($orign_project_ref);
1835
1836 if (dol_mkdir($clone_project_dir) >= 0) {
1837 $filearray = dol_dir_list($ori_project_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', '', SORT_ASC, 1);
1838 foreach ($filearray as $key => $file) {
1839 $rescopy = dol_copy($ori_project_dir.'/'.$file['name'], $clone_project_dir.'/'.$file['name'], 0, 1);
1840 if (is_numeric($rescopy) && $rescopy < 0) {
1841 $this->error .= $langs->trans("ErrorFailToCopyFile", $ori_project_dir.'/'.$file['name'], $clone_project_dir.'/'.$file['name']);
1842 $error++;
1843 }
1844 }
1845 } else {
1846 $this->error .= $langs->trans('ErrorInternalErrorDetected').':dol_mkdir';
1847 $error++;
1848 }
1849 }
1850
1851 //Duplicate task
1852 if ($clone_task) {
1853 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
1854
1855 $taskstatic = new Task($this->db);
1856
1857 // Security check
1858 $socid = 0;
1859 if ($user->socid > 0) {
1860 $socid = $user->socid;
1861 }
1862
1863 $tasksarray = $taskstatic->getTasksArray(0, 0, $fromid, $socid, 0);
1864
1865 $tab_conv_child_parent = array();
1866
1867 // Loop on each task, to clone it
1868 foreach ($tasksarray as $tasktoclone) {
1869 $result_clone = $taskstatic->createFromClone($user, $tasktoclone->id, $clone_project_id, $tasktoclone->fk_task_parent, $move_date, true, false, $clone_task_file, true, false);
1870 if ($result_clone <= 0) {
1871 $this->error .= $taskstatic->error;
1872 $error++;
1873 } else {
1874 $new_task_id = $result_clone;
1875 $taskstatic->fetch($tasktoclone->id);
1876
1877 //manage new parent clone task id
1878 // if the current task has child we store the original task id and the equivalent clone task id
1879 if (($taskstatic->hasChildren()) && !array_key_exists($tasktoclone->id, $tab_conv_child_parent)) {
1880 $tab_conv_child_parent[$tasktoclone->id] = $new_task_id;
1881 }
1882 }
1883 }
1884
1885 //Parse all clone node to be sure to update new parent
1886 $tasksarray = $taskstatic->getTasksArray(0, 0, $clone_project_id, $socid, 0);
1887 foreach ($tasksarray as $task_cloned) {
1888 $taskstatic->fetch($task_cloned->id);
1889 if ($taskstatic->fk_task_parent != 0) {
1890 $taskstatic->fk_task_parent = $tab_conv_child_parent[$taskstatic->fk_task_parent];
1891 }
1892 $res = $taskstatic->update($user, $notrigger);
1893 if ($result_clone <= 0) {
1894 $this->error .= $taskstatic->error;
1895 $error++;
1896 }
1897 }
1898 }
1899 }
1900
1901 unset($clone_project->context['createfromclone']);
1902
1903 if (!$error) {
1904 $this->db->commit();
1905 return $clone_project_id;
1906 } else {
1907 $this->db->rollback();
1908 dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : ".$this->error, LOG_ERR);
1909 return -1;
1910 }
1911 }
1912
1913
1920 public function shiftTaskDate($old_project_dt_start)
1921 {
1922 global $user, $langs, $conf;
1923
1924 $error = 0;
1925 $result = 0;
1926
1927 $taskstatic = new Task($this->db);
1928
1929 // Security check
1930 $socid = 0;
1931 if ($user->socid > 0) {
1932 $socid = $user->socid;
1933 }
1934
1935 $tasksarray = $taskstatic->getTasksArray(0, 0, $this->id, $socid, 0);
1936
1937 foreach ($tasksarray as $tasktoshiftdate) {
1938 $to_update = false;
1939 // Fetch only if update of date will be made
1940 if ((!empty($tasktoshiftdate->date_start)) || (!empty($tasktoshiftdate->date_end))) {
1941 //dol_syslog(get_class($this)."::shiftTaskDate to_update", LOG_DEBUG);
1942 $to_update = true;
1943 $task = new Task($this->db);
1944 $result = $task->fetch($tasktoshiftdate->id);
1945 if (!$result) {
1946 $error++;
1947 $this->error .= $task->error;
1948 }
1949 }
1950 //print "$this->date_start + $tasktoshiftdate->date_start - $old_project_dt_start";exit;
1951
1952 //Calcultate new task start date with difference between old proj start date and origin task start date
1953 if (!empty($tasktoshiftdate->date_start)) {
1954 $task->date_start = $this->date_start + ($tasktoshiftdate->date_start - $old_project_dt_start);
1955 }
1956
1957 //Calcultate new task end date with difference between origin proj end date and origin task end date
1958 if (!empty($tasktoshiftdate->date_end)) {
1959 $task->date_end = $this->date_start + ($tasktoshiftdate->date_end - $old_project_dt_start);
1960 }
1961
1962 if ($to_update) {
1963 $result = $task->update($user);
1964 if (!$result) {
1965 $error++;
1966 $this->error .= $task->error;
1967 }
1968 }
1969 }
1970 if ($error != 0) {
1971 return -1;
1972 }
1973 return $result;
1974 }
1975
1976
1977 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1985 public function update_element($tableName, $elementSelectId)
1986 {
1987 // phpcs:enable
1988 $sql = "UPDATE ".MAIN_DB_PREFIX.$tableName;
1989
1990 if ($tableName == "actioncomm") {
1991 $sql .= " SET fk_project=".$this->id;
1992 $sql .= " WHERE id=".((int) $elementSelectId);
1993 } elseif (in_array($tableName, ["entrepot","mrp_mo","stocktransfer_stocktransfer"])) {
1994 $sql .= " SET fk_project=".$this->id;
1995 $sql .= " WHERE rowid=".((int) $elementSelectId);
1996 } else {
1997 $sql .= " SET fk_projet=".$this->id;
1998 $sql .= " WHERE rowid=".((int) $elementSelectId);
1999 }
2000
2001 dol_syslog(get_class($this)."::update_element", LOG_DEBUG);
2002 $resql = $this->db->query($sql);
2003 if (!$resql) {
2004 $this->error = $this->db->lasterror();
2005 return -1;
2006 } else {
2007 return 1;
2008 }
2009 }
2010
2011 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2021 public function remove_element($tableName, $elementSelectId, $projectfield = 'fk_projet')
2022 {
2023 // phpcs:enable
2024 $sql = "UPDATE ".MAIN_DB_PREFIX.$tableName;
2025
2026 if ($tableName == "actioncomm") {
2027 $sql .= " SET fk_project=NULL";
2028 $sql .= " WHERE id=".((int) $elementSelectId);
2029 } else {
2030 $sql .= " SET ".$projectfield."=NULL";
2031 $sql .= " WHERE rowid=".((int) $elementSelectId);
2032 }
2033
2034 dol_syslog(get_class($this)."::remove_element", LOG_DEBUG);
2035 $resql = $this->db->query($sql);
2036 if (!$resql) {
2037 $this->error = $this->db->lasterror();
2038 return -1;
2039 } else {
2040 return 1;
2041 }
2042 }
2043
2054 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2055 {
2056 global $conf, $langs;
2057
2058 $langs->load("projects");
2059
2060 if (!dol_strlen($modele)) {
2061 $modele = 'baleine';
2062
2063 if ($this->model_pdf) {
2064 $modele = $this->model_pdf;
2065 } elseif (getDolGlobalString('PROJECT_ADDON_PDF')) {
2066 $modele = $conf->global->PROJECT_ADDON_PDF;
2067 }
2068 }
2069
2070 $modelpath = "core/modules/project/doc/";
2071
2072 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2073 }
2074
2075
2085 public function loadTimeSpent($datestart, $taskid = 0, $userid = 0)
2086 {
2087 $error = 0;
2088
2089 $this->weekWorkLoad = array();
2090 $this->weekWorkLoadPerTask = array();
2091
2092 if (empty($datestart)) {
2093 dol_print_error('', 'Error datestart parameter is empty');
2094 }
2095
2096 $sql = "SELECT ptt.rowid as taskid, ptt.element_duration, ptt.element_date, ptt.element_datehour, ptt.fk_element";
2097 $sql .= " FROM ".MAIN_DB_PREFIX."element_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt";
2098 $sql .= " WHERE ptt.fk_element = pt.rowid";
2099 $sql .= " AND ptt.elementtype = 'task'";
2100 $sql .= " AND pt.fk_projet = ".((int) $this->id);
2101 $sql .= " AND (ptt.element_date >= '".$this->db->idate($datestart)."' ";
2102 $sql .= " AND ptt.element_date <= '".$this->db->idate(dol_time_plus_duree($datestart, 1, 'w') - 1)."')";
2103 if ($taskid) {
2104 $sql .= " AND ptt.fk_element=".((int) $taskid);
2105 }
2106 if (is_numeric($userid)) {
2107 $sql .= " AND ptt.fk_user=".((int) $userid);
2108 }
2109
2110 //print $sql;
2111 $resql = $this->db->query($sql);
2112 if ($resql) {
2113 $daylareadyfound = array();
2114
2115 $num = $this->db->num_rows($resql);
2116 $i = 0;
2117 // Loop on each record found, so each couple (project id, task id)
2118 while ($i < $num) {
2119 $obj = $this->db->fetch_object($resql);
2120 $day = $this->db->jdate($obj->element_date); // task_date is date without hours
2121 if (empty($daylareadyfound[$day])) {
2122 $this->weekWorkLoad[$day] = $obj->element_duration;
2123 $this->weekWorkLoadPerTask[$day][$obj->fk_element] = $obj->element_duration;
2124 } else {
2125 $this->weekWorkLoad[$day] += $obj->element_duration;
2126 $this->weekWorkLoadPerTask[$day][$obj->fk_element] += $obj->element_duration;
2127 }
2128 $daylareadyfound[$day] = 1;
2129 $i++;
2130 }
2131 $this->db->free($resql);
2132 return 1;
2133 } else {
2134 $this->error = "Error ".$this->db->lasterror();
2135 dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
2136 return -1;
2137 }
2138 }
2139
2149 public function loadTimeSpentMonth($datestart, $taskid = 0, $userid = 0)
2150 {
2151 $error = 0;
2152
2153 $this->monthWorkLoad = array();
2154 $this->monthWorkLoadPerTask = array();
2155
2156 if (empty($datestart)) {
2157 dol_print_error('', 'Error datestart parameter is empty');
2158 }
2159
2160 $sql = "SELECT ptt.rowid as taskid, ptt.element_duration, ptt.element_date, ptt.element_datehour, ptt.fk_element";
2161 $sql .= " FROM ".MAIN_DB_PREFIX."element_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt";
2162 $sql .= " WHERE ptt.fk_element = pt.rowid";
2163 $sql .= " AND ptt.elementtype = 'task'";
2164 $sql .= " AND pt.fk_projet = ".((int) $this->id);
2165 $sql .= " AND (ptt.element_date >= '".$this->db->idate($datestart)."' ";
2166 $sql .= " AND ptt.element_date <= '".$this->db->idate(dol_time_plus_duree($datestart, 1, 'm') - 1)."')";
2167 if ($taskid) {
2168 $sql .= " AND ptt.fk_element=".((int) $taskid);
2169 }
2170 if (is_numeric($userid)) {
2171 $sql .= " AND ptt.fk_user=".((int) $userid);
2172 }
2173
2174 //print $sql;
2175 $resql = $this->db->query($sql);
2176 if ($resql) {
2177 $weekalreadyfound = array();
2178
2179 $num = $this->db->num_rows($resql);
2180 $i = 0;
2181 // Loop on each record found, so each couple (project id, task id)
2182 while ($i < $num) {
2183 $obj = $this->db->fetch_object($resql);
2184 if (!empty($obj->element_date)) {
2185 $date = explode('-', $obj->element_date);
2186 $week_number = getWeekNumber($date[2], $date[1], $date[0]);
2187 }
2188 if (empty($weekalreadyfound[$week_number])) {
2189 $this->monthWorkLoad[$week_number] = $obj->element_duration;
2190 $this->monthWorkLoadPerTask[$week_number][$obj->fk_element] = $obj->element_duration;
2191 } else {
2192 $this->monthWorkLoad[$week_number] += $obj->element_duration;
2193 $this->monthWorkLoadPerTask[$week_number][$obj->fk_element] += $obj->element_duration;
2194 }
2195 $weekalreadyfound[$week_number] = 1;
2196 $i++;
2197 }
2198 $this->db->free($resql);
2199 return 1;
2200 } else {
2201 $this->error = "Error ".$this->db->lasterror();
2202 dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
2203 return -1;
2204 }
2205 }
2206
2207 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2214 public function load_board($user)
2215 {
2216 // phpcs:enable
2217 global $conf, $langs;
2218
2219 // For external user, no check is done on company because readability is managed by public status of project and assignement.
2220 //$socid=$user->socid;
2221
2222 $response = new WorkboardResponse();
2223 $response->warning_delay = $conf->project->warning_delay / 60 / 60 / 24;
2224 $response->label = $langs->trans("OpenedProjects");
2225 $response->labelShort = $langs->trans("Opened");
2226 $response->url = DOL_URL_ROOT.'/projet/list.php?search_project_user=-1&search_status=1&mainmenu=project';
2227 $response->img = img_object('', "projectpub");
2228 $response->nbtodo = 0;
2229 $response->nbtodolate = 0;
2230
2231 $sql = "SELECT p.rowid, p.fk_statut as status, p.fk_opp_status, p.datee as datee";
2232 $sql .= " FROM (".MAIN_DB_PREFIX."projet as p";
2233 $sql .= ")";
2234 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
2235 // For external user, no check is done on company permission because readability is managed by public status of project and assignement.
2236 //if (! $user->rights->societe->client->voir && ! $socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2237 $sql .= " WHERE p.fk_statut = 1";
2238 $sql .= " AND p.entity IN (".getEntity('project').')';
2239
2240
2241 $projectsListId = null;
2242 if (!$user->hasRight("projet", "all", "lire")) {
2243 $response->url = DOL_URL_ROOT.'/projet/list.php?search_status=1&mainmenu=project';
2244 $projectsListId = $this->getProjectsAuthorizedForUser($user, 0, 1);
2245 if (empty($projectsListId)) {
2246 return $response;
2247 }
2248
2249 $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
2250 }
2251
2252 // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
2253 //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).")";
2254 // For external user, no check is done on company permission because readability is managed by public status of project and assignement.
2255 //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))";
2256
2257 //print $sql;
2258 $resql = $this->db->query($sql);
2259 if ($resql) {
2260 $project_static = new Project($this->db);
2261
2262
2263 // This assignment in condition is not a bug. It allows walking the results.
2264 while ($obj = $this->db->fetch_object($resql)) {
2265 $response->nbtodo++;
2266
2267 $project_static->statut = $obj->status;
2268 $project_static->opp_status = $obj->fk_opp_status;
2269 $project_static->date_end = $this->db->jdate($obj->datee);
2270
2271 if ($project_static->hasDelay()) {
2272 $response->nbtodolate++;
2273 }
2274 }
2275
2276 return $response;
2277 }
2278
2279 $this->error = $this->db->error();
2280 return -1;
2281 }
2282
2291 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
2292 {
2293 $tables = array(
2294 'projet'
2295 );
2296
2297 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
2298 }
2299
2300
2301 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2307 public function load_state_board()
2308 {
2309 // phpcs:enable
2310 global $user;
2311
2312 $this->nb = array();
2313
2314 $sql = "SELECT count(p.rowid) as nb";
2315 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
2316 $sql .= " WHERE";
2317 $sql .= " p.entity IN (".getEntity('project').")";
2318 if (!$user->hasRight('projet', 'all', 'lire')) {
2319 $projectsListId = $this->getProjectsAuthorizedForUser($user, 0, 1);
2320 $sql .= "AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
2321 }
2322
2323 $resql = $this->db->query($sql);
2324 if ($resql) {
2325 while ($obj = $this->db->fetch_object($resql)) {
2326 $this->nb["projects"] = $obj->nb;
2327 }
2328 $this->db->free($resql);
2329 return 1;
2330 } else {
2331 dol_print_error($this->db);
2332 $this->error = $this->db->error();
2333 return -1;
2334 }
2335 }
2336
2337
2343 public function hasDelay()
2344 {
2345 global $conf;
2346
2347 if (!($this->statut == self::STATUS_VALIDATED)) {
2348 return false;
2349 }
2350 if (!$this->date_end) {
2351 return false;
2352 }
2353
2354 $now = dol_now();
2355
2356 return ($this->date_end) < ($now - $conf->project->warning_delay);
2357 }
2358
2359
2366 public function info($id)
2367 {
2368 $sql = 'SELECT c.rowid, datec as datec, tms as datem,';
2369 $sql .= ' date_close as datecloture,';
2370 $sql .= ' fk_user_creat as fk_user_author, fk_user_close as fk_user_cloture';
2371 $sql .= ' FROM '.MAIN_DB_PREFIX.'projet as c';
2372 $sql .= ' WHERE c.rowid = '.((int) $id);
2373 $result = $this->db->query($sql);
2374 if ($result) {
2375 if ($this->db->num_rows($result)) {
2376 $obj = $this->db->fetch_object($result);
2377
2378 $this->id = $obj->rowid;
2379
2380 $this->user_creation_id = $obj->fk_user_author;
2381 $this->user_closing_id = $obj->fk_user_cloture;
2382
2383 $this->date_creation = $this->db->jdate($obj->datec);
2384 $this->date_modification = $this->db->jdate($obj->datem);
2385 $this->date_cloture = $this->db->jdate($obj->datecloture);
2386 }
2387
2388 $this->db->free($result);
2389 } else {
2390 dol_print_error($this->db);
2391 }
2392 }
2393
2404 public function setCategories($categories)
2405 {
2406 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2407 return parent::setCategoriesCommon($categories, Categorie::TYPE_PROJECT);
2408 }
2409
2410
2418 public function getLinesArray($user, $loadRoleMode = 1)
2419 {
2420 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
2421 $taskstatic = new Task($this->db);
2422
2423 $this->lines = $taskstatic->getTasksArray(0, $user, $this->id, 0, 0, '', '-1', '', 0, 0, array(), 0, array(), 0, $loadRoleMode);
2424 return 1;
2425 }
2426
2444 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 = '')
2445 {
2446 global $conf, $langs;
2447 // TODO EMAIL
2448
2449 return 1;
2450 }
2458 public function getKanbanView($option = '', $arraydata = null)
2459 {
2460 global $langs;
2461
2462 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2463
2464 $return = '<div class="box-flex-item box-flex-grow-zero">';
2465 $return .= '<div class="info-box info-box-sm">';
2466 $return .= '<span class="info-box-icon bg-infobox-action">';
2467 $return .= img_picto('', $this->public ? 'projectpub' : $this->picto);
2468 //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
2469 $return .= '</span>';
2470 $return .= '<div class="info-box-content">';
2471 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref);
2472 if ($this->hasDelay()) {
2473 $return .= img_warning($langs->trans('Late'));
2474 }
2475 $return .= '</span>';
2476 if ($selected >= 0) {
2477 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2478 }
2479 // Date
2480 /*
2481 if (property_exists($this, 'date_start') && $this->date_start) {
2482 $return .= '<br><span class="info-box-label">'.dol_print_date($this->date_start, 'day').'</>';
2483 }
2484 if (property_exists($this, 'date_end') && $this->date_end) {
2485 if ($this->date_start) {
2486 $return .= ' - ';
2487 } else {
2488 $return .= '<br>';
2489 }
2490 $return .= '<span class="info-box-label">'.dol_print_date($this->date_end, 'day').'</span>';
2491 }*/
2492 if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) {
2493 $return .= '<br><div class="info-box-ref tdoverflowmax150 inline-block valignmiddle">'.$this->thirdparty->getNomUrl(1);
2494 $return .= '</div><div class="inline-block valignmiddle">';
2495 $return .= dol_print_phone($this->thirdparty->phone, $this->thirdparty->country_code, 0, $this->thirdparty->id, 'tel', 'hidenum', 'phone');
2496 $return .='</div>';
2497 }
2498 if (!empty($arraydata['assignedusers'])) {
2499 $return .= '<br>';
2500 if ($this->public) {
2501 $return .= img_picto($langs->trans('Visibility').': '.$langs->trans('SharedProject'), 'world', 'class="paddingrightonly valignmiddle"');
2502 //print $langs->trans('SharedProject');
2503 } else {
2504 $return .= img_picto($langs->trans('Visibility').': '.$langs->trans('PrivateProject'), 'private', 'class="paddingrightonly valignmiddle"');
2505 //print $langs->trans('PrivateProject');
2506 }
2507
2508 $return .= ' <span class="small valignmiddle">'.$arraydata['assignedusers'].'</span>';
2509 }
2510 /*if (property_exists($this, 'user_author_id')) {
2511 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Author").'</span>';
2512 $return .= '<span> : '.$user->getNomUrl(1).'</span>';
2513 }*/
2514 $return .= '<br><div>'; // start div line status
2515 if ($this->usage_opportunity && $this->opp_status_code) {
2516 //$return .= '<br><span class="info-bo-label opacitymedium">'.$langs->trans("OpportunityStatusShort").'</span>';
2517 //$return .= '<div class="small inline-block">'.dol_trunc($langs->trans("OppStatus".$this->opp_status_code), 5).'</div>';
2518 $return .= '<div class="opacitymedium small marginrightonly inline-block" title="'.dol_escape_htmltag($langs->trans("OppStatus".$this->opp_status_code)).'">'.round($this->opp_percent).'%</div>';
2519 $return .= ' <div class="amount small marginrightonly inline-block">'.price($this->opp_amount).'</div>';
2520 }
2521 if (method_exists($this, 'getLibStatut')) {
2522 $return .= '<div class="info-box-status small inline-block valignmiddle">'.$this->getLibStatut(3).'</div>';
2523 }
2524 $return .= '</div>'; // end div line status
2525
2526 $return .= '</div>';
2527 $return .= '</div>';
2528 $return .= '</div>';
2529
2530 return $return;
2531 }
2532
2538 public function getChildren()
2539 {
2540 $children = [];
2541 $sql = 'SELECT rowid,title';
2542 $sql .= ' FROM '.MAIN_DB_PREFIX.'projet';
2543 $sql .= ' WHERE fk_project = '.((int) $this->id);
2544 $sql .= ' ORDER BY title';
2545 $result = $this->db->query($sql);
2546 if ($result) {
2547 $n = $this->db->num_rows($result);
2548 while ($n) {
2549 $children[] = $this->db->fetch_object($result);
2550 $n--;
2551 }
2552 $this->db->free($result);
2553 } else {
2554 dol_print_error($this->db);
2555 }
2556
2557 return $children;
2558 }
2559}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
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.
liste_contact($statusoflink=-1, $source='external', $list=0, $code='', $status=-1, $arrayoftcids=array())
Get array of all contacts for an object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
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.
getNomUrl($withpicto=0, $option='', $addlabel=0, $moreinpopup='', $sep=' - ', $notooltip=0, $save_lastsearch_value=-1, $morecss='', $save_pageforbacktolist='')
Return clickable name (with picto eventually)
fetchAndSetSubstitution($id, $key, $fetched=false)
Fetch object and substitute key.
getChildren()
Return array of sub-projects of the current 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.
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.
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.
Class to manage Dolibarr users.
getWeekNumber($day, $month, $year)
Return week number.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after 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)
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
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).
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a 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)
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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.
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)
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
Definition invoice.php:1926