30 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 public $element =
'project';
46 public $table_element =
'projet';
51 public $table_element_line =
'projet_task';
56 public $table_element_date;
61 public $fk_element =
'fk_projet';
67 public $ismultientitymanaged = 1;
72 public $picto =
'project';
116 public $date_start_event;
121 public $date_end_event;
134 public $thirdparty_name;
141 public $fk_user_close;
146 public $user_close_id;
152 public $budget_amount;
157 public $usage_opportunity;
167 public $usage_bill_time;
172 public $usage_organize_event;
177 public $accept_conference_suggestions;
182 public $accept_booth_suggestions;
187 public $price_registration;
197 public $max_attendees;
199 public $statuts_short;
200 public $statuts_long;
205 public $fk_opp_status;
212 public $weekWorkLoad;
213 public $weekWorkLoadPerTask;
272 public $fields = array(
273 'rowid' =>array(
'type'=>
'integer',
'label'=>
'ID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
274 'ref' =>array(
'type'=>
'varchar(50)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>1,
'showoncombobox'=>1,
'position'=>15,
'searchall'=>1),
275 'title' =>array(
'type'=>
'varchar(255)',
'label'=>
'ProjectLabel',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'position'=>17,
'showoncombobox'=>2,
'searchall'=>1),
276 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>3,
'notnull'=>1,
'position'=>19),
277 'fk_soc' =>array(
'type'=>
'integer',
'label'=>
'Thirdparty',
'enabled'=>1,
'visible'=>0,
'position'=>20),
278 'dateo' =>array(
'type'=>
'date',
'label'=>
'DateStart',
'enabled'=>1,
'visible'=>1,
'position'=>30),
279 'datee' =>array(
'type'=>
'date',
'label'=>
'DateEnd',
'enabled'=>1,
'visible'=>1,
'position'=>35),
280 'description' =>array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>3,
'position'=>55,
'searchall'=>1),
281 'public' =>array(
'type'=>
'integer',
'label'=>
'Visibility',
'enabled'=>1,
'visible'=>1,
'position'=>65),
282 'fk_opp_status' =>array(
'type'=>
'integer',
'label'=>
'OpportunityStatusShort',
'enabled'=>
'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")',
'visible'=>1,
'position'=>75),
283 'opp_percent' =>array(
'type'=>
'double(5,2)',
'label'=>
'OpportunityProbabilityShort',
'enabled'=>
'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")',
'visible'=>1,
'position'=>80),
284 'note_private' =>array(
'type'=>
'text',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>85,
'searchall'=>1),
285 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>90,
'searchall'=>1),
286 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'ModelPdf',
'enabled'=>1,
'visible'=>0,
'position'=>95),
287 'date_close' =>array(
'type'=>
'datetime',
'label'=>
'DateClosing',
'enabled'=>1,
'visible'=>0,
'position'=>105),
288 'fk_user_close' =>array(
'type'=>
'integer',
'label'=>
'UserClosing',
'enabled'=>1,
'visible'=>0,
'position'=>110),
289 'opp_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'OpportunityAmountShort',
'enabled'=>1,
'visible'=>
'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")',
'position'=>115),
290 'budget_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Budget',
'enabled'=>1,
'visible'=>-1,
'position'=>119),
291 'usage_bill_time' =>array(
'type'=>
'integer',
'label'=>
'UsageBillTimeShort',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
292 'usage_opportunity' =>array(
'type'=>
'integer',
'label'=>
'UsageOpportunity',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
293 'usage_task' =>array(
'type'=>
'integer',
'label'=>
'UsageTasks',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
294 'usage_organize_event' =>array(
'type'=>
'integer',
'label'=>
'UsageOrganizeEvent',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
296 'date_start_event' =>array(
'type'=>
'date',
'label'=>
'DateStartEvent',
'enabled'=>
"isModEnabled('eventorganization')",
'visible'=>1,
'position'=>200),
297 'date_end_event' =>array(
'type'=>
'date',
'label'=>
'DateEndEvent',
'enabled'=>
"isModEnabled('eventorganization')",
'visible'=>1,
'position'=>201),
298 'location' =>array(
'type'=>
'text',
'label'=>
'Location',
'enabled'=>1,
'visible'=>3,
'position'=>55,
'searchall'=>202),
299 'accept_conference_suggestions' =>array(
'type'=>
'integer',
'label'=>
'AllowUnknownPeopleSuggestConf',
'enabled'=>1,
'visible'=>-1,
'position'=>210),
300 'accept_booth_suggestions' =>array(
'type'=>
'integer',
'label'=>
'AllowUnknownPeopleSuggestBooth',
'enabled'=>1,
'visible'=>-1,
'position'=>211),
301 'price_registration' =>array(
'type'=>
'double(24,8)',
'label'=>
'PriceOfRegistration',
'enabled'=>1,
'visible'=>-1,
'position'=>212),
302 'price_booth' =>array(
'type'=>
'double(24,8)',
'label'=>
'PriceOfBooth',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
303 'max_attendees' =>array(
'type'=>
'integer',
'label'=>
'MaxNbOfAttendees',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
305 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreationShort',
'enabled'=>1,
'visible'=>-2,
'position'=>400),
306 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModificationShort',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>405),
307 'fk_user_creat' =>array(
'type'=>
'integer',
'label'=>
'UserCreation',
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>410),
308 'fk_user_modif' =>array(
'type'=>
'integer',
'label'=>
'UserModification',
'enabled'=>1,
'visible'=>0,
'position'=>415),
309 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-1,
'position'=>420),
310 'email_msgid'=>array(
'type'=>
'varchar(255)',
'label'=>
'EmailMsgID',
'enabled'=>1,
'visible'=>-1,
'position'=>450,
'help'=>
'EmailMsgIDWhenSourceisEmail',
'csslist'=>
'tdoverflowmax125'),
311 'fk_statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'position'=>500),
341 $this->statuts_short = array(0 =>
'Draft', 1 =>
'Opened', 2 =>
'Closed');
342 $this->statuts_long = array(0 =>
'Draft', 1 =>
'Opened', 2 =>
'Closed');
346 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
347 $this->fields[
'rowid'][
'visible'] = 0;
350 if (empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
351 $this->fields[
'fk_opp_status'][
'enabled'] = 0;
352 $this->fields[
'opp_percent'][
'enabled'] = 0;
353 $this->fields[
'opp_amount'][
'enabled'] = 0;
354 $this->fields[
'usage_opportunity'][
'enabled'] = 0;
357 if (!empty($conf->global->PROJECT_HIDE_TASKS)) {
358 $this->fields[
'usage_bill_time'][
'visible'] = 0;
359 $this->fields[
'usage_task'][
'visible'] = 0;
362 if (empty($conf->eventorganization->enabled)) {
363 $this->fields[
'usage_organize_event'][
'visible'] = 0;
364 $this->fields[
'accept_conference_suggestions'][
'enabled'] = 0;
365 $this->fields[
'accept_booth_suggestions'][
'enabled'] = 0;
366 $this->fields[
'price_registration'][
'enabled'] = 0;
367 $this->fields[
'price_booth'][
'enabled'] = 0;
368 $this->fields[
'max_attendees'][
'enabled'] = 0;
379 public function create($user, $notrigger = 0)
381 global $conf, $langs;
389 $this->note_private =
dol_substr($this->note_private, 0, 65535);
390 $this->note_public =
dol_substr($this->note_public, 0, 65535);
393 if (!trim($this->
ref)) {
394 $this->error =
'ErrorFieldsRequired';
395 dol_syslog(get_class($this).
"::create error -1 ref null", LOG_ERR);
398 if (!empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) && !($this->socid > 0)) {
399 $this->error =
'ErrorFieldsRequired';
400 dol_syslog(get_class($this).
"::create error -1 thirdparty not defined and option PROJECT_THIRDPARTY_REQUIRED is set", LOG_ERR);
407 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet (";
410 $sql .=
", description";
412 $sql .=
", fk_user_creat";
413 $sql .=
", fk_statut";
414 $sql .=
", fk_opp_status";
415 $sql .=
", opp_percent";
420 $sql .=
", opp_amount";
421 $sql .=
", budget_amount";
422 $sql .=
", usage_opportunity";
423 $sql .=
", usage_task";
424 $sql .=
", usage_bill_time";
425 $sql .=
", usage_organize_event";
426 $sql .=
", accept_conference_suggestions";
427 $sql .=
", accept_booth_suggestions";
428 $sql .=
", price_registration";
429 $sql .=
", price_booth";
430 $sql .=
", max_attendees";
431 $sql .=
", date_start_event";
432 $sql .=
", date_end_event";
433 $sql .=
", location";
434 $sql .=
", email_msgid";
435 $sql .=
", note_private";
436 $sql .=
", note_public";
439 $sql .=
") VALUES (";
440 $sql .=
"'".$this->db->escape($this->
ref).
"'";
441 $sql .=
", '".$this->db->escape($this->title).
"'";
442 $sql .=
", '".$this->db->escape($this->
description).
"'";
443 $sql .=
", ".($this->socid > 0 ? $this->socid :
"null");
444 $sql .=
", ".((int) $user->id);
445 $sql .=
", ".(is_numeric($this->statut) ? ((int) $this->statut) :
'0');
446 $sql .=
", ".((is_numeric($this->opp_status) && $this->opp_status > 0) ? ((
int) $this->opp_status) :
'NULL');
447 $sql .=
", ".(is_numeric($this->opp_percent) ? ((int) $this->opp_percent) :
'NULL');
448 $sql .=
", ".($this->public ? 1 : 0);
449 $sql .=
", '".$this->db->idate($now).
"'";
450 $sql .=
", ".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
'null');
451 $sql .=
", ".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
'null');
452 $sql .=
", ".(strcmp($this->opp_amount,
'') ?
price2num($this->opp_amount) :
'null');
453 $sql .=
", ".(strcmp($this->budget_amount,
'') ?
price2num($this->budget_amount) :
'null');
454 $sql .=
", ".($this->usage_opportunity ? 1 : 0);
455 $sql .=
", ".($this->usage_task ? 1 : 0);
456 $sql .=
", ".($this->usage_bill_time ? 1 : 0);
457 $sql .=
", ".($this->usage_organize_event ? 1 : 0);
458 $sql .=
", ".($this->accept_conference_suggestions ? 1 : 0);
459 $sql .=
", ".($this->accept_booth_suggestions ? 1 : 0);
460 $sql .=
", ".(strcmp($this->price_registration,
'') ?
price2num($this->price_registration) :
'null');
461 $sql .=
", ".(strcmp($this->price_booth,
'') ?
price2num($this->price_booth) :
'null');
462 $sql .=
", ".(strcmp($this->max_attendees,
'') ? ((int) $this->max_attendees) :
'null');
463 $sql .=
", ".($this->date_start_event !=
'' ?
"'".$this->db->idate($this->date_start_event).
"'" :
'null');
464 $sql .=
", ".($this->date_end_event !=
'' ?
"'".$this->db->idate($this->date_end_event).
"'" :
'null');
465 $sql .=
", ".($this->location ?
"'".$this->db->escape($this->location).
"'" :
'null');
466 $sql .=
", ".($this->email_msgid ?
"'".$this->db->escape($this->email_msgid).
"'" :
'null');
467 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
'null');
468 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
'null');
469 $sql .=
", ".((int) $conf->entity);
470 $sql .=
", ".(!isset($this->ip) ?
'NULL' :
"'".$this->db->escape($this->ip).
"'");
473 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
476 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"projet");
488 $this->error = $this->
db->lasterror();
489 $this->errno = $this->
db->lasterrno();
512 $this->
db->rollback();
524 public function update($user, $notrigger = 0)
526 global $langs, $conf;
531 $this->title = trim($this->title);
533 if ($this->opp_amount < 0) {
534 $this->opp_amount =
'';
536 if ($this->opp_percent < 0) {
537 $this->opp_percent =
'';
539 if ($this->date_end && $this->date_end < $this->date_start) {
540 $this->error = $langs->trans(
"ErrorDateEndLowerThanDateStart");
541 $this->errors[] = $this->error;
542 $this->
db->rollback();
543 dol_syslog(get_class($this).
"::update error -3 ".$this->error, LOG_ERR);
547 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
552 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet SET";
553 $sql .=
" ref='".$this->db->escape($this->
ref).
"'";
554 $sql .=
", title = '".$this->db->escape($this->title).
"'";
555 $sql .=
", description = '".$this->db->escape($this->
description).
"'";
556 $sql .=
", fk_soc = ".($this->socid > 0 ? $this->socid :
"null");
557 $sql .=
", fk_statut = ".((int) $this->statut);
558 $sql .=
", fk_opp_status = ".((is_numeric($this->opp_status) && $this->opp_status > 0) ? $this->opp_status :
'null');
559 $sql .=
", opp_percent = ".((is_numeric($this->opp_percent) && $this->opp_percent !=
'') ? $this->opp_percent :
'null');
560 $sql .=
", public = ".($this->public ? 1 : 0);
561 $sql .=
", datec = ".($this->date_c !=
'' ?
"'".$this->db->idate($this->date_c).
"'" :
'null');
562 $sql .=
", dateo = ".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
'null');
563 $sql .=
", datee = ".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
'null');
564 $sql .=
", date_close = ".($this->date_close !=
'' ?
"'".$this->db->idate($this->date_close).
"'" :
'null');
565 $sql .=
", fk_user_close = ".($this->fk_user_close > 0 ? $this->fk_user_close :
"null");
566 $sql .=
", opp_amount = ".(strcmp($this->opp_amount,
'') ?
price2num($this->opp_amount) :
"null");
567 $sql .=
", budget_amount = ".(strcmp($this->budget_amount,
'') ?
price2num($this->budget_amount) :
"null");
568 $sql .=
", fk_user_modif = ".$user->id;
569 $sql .=
", usage_opportunity = ".($this->usage_opportunity ? 1 : 0);
570 $sql .=
", usage_task = ".($this->usage_task ? 1 : 0);
571 $sql .=
", usage_bill_time = ".($this->usage_bill_time ? 1 : 0);
572 $sql .=
", usage_organize_event = ".($this->usage_organize_event ? 1 : 0);
573 $sql .=
", accept_conference_suggestions = ".($this->accept_conference_suggestions ? 1 : 0);
574 $sql .=
", accept_booth_suggestions = ".($this->accept_booth_suggestions ? 1 : 0);
575 $sql .=
", price_registration = ".(strcmp($this->price_registration,
'') ?
price2num($this->price_registration) :
"null");
576 $sql .=
", price_booth = ".(strcmp($this->price_booth,
'') ?
price2num($this->price_booth) :
"null");
577 $sql .=
", max_attendees = ".(strcmp($this->max_attendees,
'') ?
price2num($this->max_attendees) :
"null");
578 $sql .=
", date_start_event = ".($this->date_start_event !=
'' ?
"'".$this->db->idate($this->date_start_event).
"'" :
'null');
579 $sql .=
", date_end_event = ".($this->date_end_event !=
'' ?
"'".$this->db->idate($this->date_end_event).
"'" :
'null');
580 $sql .=
", location = '".$this->db->escape($this->location).
"'";
581 $sql .=
", entity = ".((int) $this->entity);
582 $sql .=
" WHERE rowid = ".((int) $this->
id);
584 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
595 if (!$error && !$notrigger) {
604 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
606 if ($conf->project->dir_output) {
609 if (file_exists($olddir)) {
610 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
611 $res = @rename($olddir, $newdir);
613 $langs->load(
"errors");
614 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
624 $this->
db->rollback();
628 $this->error = $this->
db->lasterror();
629 $this->errors[] = $this->error;
630 $this->
db->rollback();
631 if ($this->
db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
636 dol_syslog(get_class($this).
"::update error ".$result.
" ".$this->error, LOG_ERR);
639 dol_syslog(get_class($this).
"::update ref null");
655 public function fetch($id, $ref =
'', $ref_ext =
'', $email_msgid =
'')
659 if (empty($id) && empty($ref) && empty($ref_ext) && empty($email_msgid)) {
660 dol_syslog(get_class($this).
"::fetch Bad parameters", LOG_WARNING);
664 $sql =
"SELECT rowid, entity, ref, title, description, public, datec, opp_amount, budget_amount,";
665 $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,";
666 $sql .=
" note_private, note_public, model_pdf, usage_opportunity, usage_task, usage_bill_time, usage_organize_event, email_msgid,";
667 $sql .=
" accept_conference_suggestions, accept_booth_suggestions, price_registration, price_booth, max_attendees, date_start_event, date_end_event, location";
668 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet";
670 $sql .=
" WHERE rowid = ".((int) $id);
672 $sql .=
" WHERE entity IN (".getEntity(
'project').
")";
674 $sql .=
" AND ref = '".$this->db->escape($ref).
"'";
675 } elseif (!empty($ref_ext)) {
676 $sql .=
" AND ref_ext = '".$this->db->escape($ref_ext).
"'";
678 $sql .=
" AND email_msgid = '".$this->db->escape($email_msgid).
"'";
682 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
685 $num_rows = $this->
db->num_rows(
$resql);
688 $obj = $this->
db->fetch_object(
$resql);
690 $this->
id = $obj->rowid;
691 $this->entity = $obj->entity;
692 $this->
ref = $obj->ref;
693 $this->title = $obj->title;
695 $this->date_c = $this->
db->jdate($obj->datec);
696 $this->datec = $this->
db->jdate($obj->datec);
697 $this->date_m = $this->
db->jdate($obj->tms);
698 $this->datem = $this->
db->jdate($obj->tms);
699 $this->date_start = $this->
db->jdate($obj->date_start);
700 $this->date_end = $this->
db->jdate($obj->date_end);
701 $this->date_close = $this->
db->jdate($obj->date_close);
702 $this->note_private = $obj->note_private;
703 $this->note_public = $obj->note_public;
704 $this->socid = $obj->fk_soc;
705 $this->user_author_id = $obj->fk_user_creat;
706 $this->user_modification_id = $obj->fk_user_modif;
707 $this->user_close_id = $obj->fk_user_close;
708 $this->
public = $obj->public;
709 $this->statut = $obj->status;
710 $this->status = $obj->status;
711 $this->opp_status = $obj->fk_opp_status;
712 $this->opp_amount = $obj->opp_amount;
713 $this->opp_percent = $obj->opp_percent;
714 $this->budget_amount = $obj->budget_amount;
715 $this->model_pdf = $obj->model_pdf;
716 $this->modelpdf = $obj->model_pdf;
717 $this->usage_opportunity = (int) $obj->usage_opportunity;
718 $this->usage_task = (
int) $obj->usage_task;
719 $this->usage_bill_time = (int) $obj->usage_bill_time;
720 $this->usage_organize_event = (
int) $obj->usage_organize_event;
721 $this->accept_conference_suggestions = (int) $obj->accept_conference_suggestions;
722 $this->accept_booth_suggestions = (
int) $obj->accept_booth_suggestions;
723 $this->price_registration = $obj->price_registration;
724 $this->price_booth = $obj->price_booth;
725 $this->max_attendees = $obj->max_attendees;
726 $this->date_start_event = $this->
db->jdate($obj->date_start_event);
727 $this->date_end_event = $this->
db->jdate($obj->date_end_event);
728 $this->location = $obj->location;
729 $this->email_msgid = $obj->email_msgid;
744 $this->error = $this->
db->lasterror();
745 $this->errors[] = $this->
db->lasterror();
762 public function get_element_list($type, $tablename, $datefieldname =
'', $date_start =
'', $date_end =
'', $projectkey =
'fk_projet')
770 if ($this->
id <= 0) {
776 if ($type ==
'agenda') {
777 $sql =
"SELECT id as rowid FROM ".MAIN_DB_PREFIX.
"actioncomm WHERE fk_project IN (".$this->
db->sanitize($ids).
") AND entity IN (".
getEntity(
'agenda').
")";
778 } elseif ($type ==
'expensereport') {
779 $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).
")";
780 } elseif ($type ==
'project_task') {
781 $sql =
"SELECT DISTINCT pt.rowid FROM ".MAIN_DB_PREFIX.
"projet_task as pt WHERE pt.fk_projet IN (".$this->
db->sanitize($ids).
")";
782 } elseif ($type ==
'project_task_time') {
783 $sql =
"SELECT DISTINCT pt.rowid, ptt.fk_user FROM ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet_task_time as ptt WHERE pt.rowid = ptt.fk_task AND pt.fk_projet IN (".$this->
db->sanitize($ids).
")";
784 } elseif ($type ==
'stock_mouvement') {
785 $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";
786 } elseif ($type ==
'loan') {
787 $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).
")";
789 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.$tablename.
" WHERE ".$projectkey.
" IN (".$this->
db->sanitize($ids).
") AND entity IN (".
getEntity($type).
")";
792 if ($date_start > 0 && $type ==
'loan') {
793 $sql .=
" AND (dateend > '".$this->db->idate($date_start).
"' OR dateend IS NULL)";
794 } elseif ($date_start > 0 && ($type !=
'project_task')) {
795 if (empty($datefieldname) && !empty($this->table_element_date)) {
796 $datefieldname = $this->table_element_date;
798 if (empty($datefieldname)) {
799 return 'Error this object has no date field defined';
801 $sql .=
" AND (".$datefieldname.
" >= '".$this->
db->idate($date_start).
"' OR ".$datefieldname.
" IS NULL)";
804 if ($date_end > 0 && $type ==
'loan') {
805 $sql .=
" AND (datestart < '".$this->db->idate($date_end).
"' OR datestart IS NULL)";
806 } elseif ($date_end > 0 && ($type !=
'project_task')) {
807 if (empty($datefieldname) && !empty($this->table_element_date)) {
808 $datefieldname = $this->table_element_date;
810 if (empty($datefieldname)) {
811 return 'Error this object has no date field defined';
813 $sql .=
" AND (".$datefieldname.
" <= '".$this->
db->idate($date_end).
"' OR ".$datefieldname.
" IS NULL)";
819 'tablename' => $tablename,
820 'datefieldname' => $datefieldname,
821 'dates' => $date_start,
822 'datee' => $date_end,
823 'fk_projet' => $projectkey,
826 $reshook = $hookmanager->executeHooks(
'getElementList', $parameters);
828 $sql = $hookmanager->resPrint;
830 $sql .= $hookmanager->resPrint;
838 dol_syslog(get_class($this).
"::get_element_list", LOG_DEBUG);
839 $result = $this->
db->query($sql);
841 $nump = $this->
db->num_rows($result);
845 $obj = $this->
db->fetch_object($result);
847 $elements[$i] = $obj->rowid.(empty($obj->fk_user) ?
'' :
'_'.$obj->fk_user);
851 $this->
db->free($result);
868 public function delete($user, $notrigger = 0)
870 global $langs, $conf;
871 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
881 $this->error =
'ErrorFailToDeleteLinkedContact';
883 $this->
db->rollback();
889 $listoftables = array(
890 'propal'=>
'fk_projet',
'commande'=>
'fk_projet',
'facture'=>
'fk_projet',
891 'supplier_proposal'=>
'fk_projet',
'commande_fournisseur'=>
'fk_projet',
'facture_fourn'=>
'fk_projet',
892 'expensereport_det'=>
'fk_projet',
'contrat'=>
'fk_projet',
893 'fichinter'=>
'fk_projet',
894 'don'=>array(
'field'=>
'fk_projet',
'module'=>
'don'),
895 'actioncomm'=>
'fk_project',
896 'mrp_mo'=>
'fk_project',
897 'entrepot'=>
'fk_project'
899 foreach ($listoftables as $key => $value) {
900 if (is_array($value)) {
904 $fieldname = $value[
'field'];
908 $sql =
"UPDATE ".MAIN_DB_PREFIX.$key.
" SET ".$fieldname.
" = NULL where ".$fieldname.
" = ".((int) $this->
id);
912 $this->errors[] = $this->
db->lasterror();
920 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_project";
921 $sql .=
" WHERE fk_project = ".((int) $this->
id);
923 $result = $this->
db->query($sql);
926 $this->errors[] = $this->
db->lasterror();
942 $elements = array(
'categorie_project');
943 foreach ($elements as $table) {
945 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$table;
946 $sql .=
" WHERE fk_project = ".((int) $this->
id);
948 $result = $this->
db->query($sql);
951 $this->errors[] = $this->
db->lasterror();
958 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_extrafields";
959 $sql .=
" WHERE fk_object = ".((int) $this->
id);
963 $this->errors[] = $this->
db->lasterror();
970 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet";
971 $sql .=
" WHERE rowid=".((int) $this->
id);
975 $this->errors[] = $langs->trans(
"CantRemoveProject", $langs->transnoentitiesnoconv(
"ProjectOverview"));
985 if ($conf->project->dir_output) {
986 $dir = $conf->project->dir_output.
"/".$projectref;
987 if (file_exists($dir)) {
990 $this->errors[] =
'ErrorFailToDeleteDir';
1007 if (empty($error)) {
1008 $this->
db->commit();
1011 foreach ($this->errors as $errmsg) {
1012 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1013 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1015 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
1016 $this->
db->rollback();
1031 if ($this->
id <= 0) {
1035 if ($type ==
'agenda') {
1036 $sql =
"SELECT COUNT(id) as nb FROM ".MAIN_DB_PREFIX.
"actioncomm WHERE fk_project = ".((int) $this->
id).
" AND entity IN (".
getEntity(
'agenda').
")";
1037 } elseif ($type ==
'expensereport') {
1038 $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);
1039 } elseif ($type ==
'project_task') {
1040 $sql =
"SELECT DISTINCT COUNT(pt.rowid) as nb FROM ".MAIN_DB_PREFIX.
"projet_task as pt WHERE pt.fk_projet = ".((int) $this->
id);
1041 } elseif ($type ==
'project_task_time') {
1042 $sql =
"SELECT DISTINCT COUNT(pt.rowid) as nb FROM ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet_task_time as ptt WHERE pt.rowid = ptt.fk_task AND pt.fk_projet = ".((int) $this->
id);
1043 } elseif ($type ==
'stock_mouvement') {
1044 $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";
1045 } elseif ($type ==
'loan') {
1046 $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);
1048 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.$tablename.
" WHERE ".$projectkey.
" = ".((int) $this->
id).
" AND entity IN (".
getEntity($type).
")";
1051 $result = $this->
db->query($sql);
1057 $obj = $this->
db->fetch_object($result);
1059 $this->
db->free($result);
1072 $countTasks = count($this->lines);
1075 foreach ($this->lines as $task) {
1076 if ($task->hasChildren() <= 0) {
1078 $ret = $task->delete($user);
1080 $this->errors[] = $this->
db->lasterror();
1087 if ($deleted && count($this->lines) < $countTasks) {
1088 if (count($this->lines)) {
1105 global $langs, $conf;
1110 if ($this->status == self::STATUS_VALIDATED) {
1111 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
1116 if (preg_match(
'/^'.preg_quote($langs->trans(
"CopyOf").
' ').
'/', $this->title)) {
1117 $this->error = $langs->trans(
"ErrorFieldFormat", $langs->transnoentities(
"Label")).
'. '.$langs->trans(
'RemoveString', $langs->transnoentitiesnoconv(
"CopyOf"));
1123 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet";
1124 $sql .=
" SET fk_statut = ".self::STATUS_VALIDATED;
1125 $sql .=
" WHERE rowid = ".((int) $this->
id);
1128 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
1132 if (empty($notrigger)) {
1133 $result = $this->
call_trigger(
'PROJECT_VALIDATE', $user);
1142 $this->
db->commit();
1145 $this->
db->rollback();
1146 $this->error = join(
',', $this->errors);
1147 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
1151 $this->
db->rollback();
1152 $this->error = $this->
db->lasterror();
1165 global $langs, $conf;
1171 if ($this->statut != self::STATUS_CLOSED) {
1174 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet";
1175 $sql .=
" SET fk_statut = ".self::STATUS_CLOSED.
", fk_user_close = ".((int) $user->id).
", date_close = '".$this->
db->idate($now).
"'";
1176 $sql .=
" WHERE rowid = ".((int) $this->
id);
1177 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1179 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
1183 dol_syslog(get_class($this).
"::setClose", LOG_DEBUG);
1195 $this->
db->commit();
1198 $this->
db->rollback();
1199 $this->error = join(
',', $this->errors);
1200 dol_syslog(get_class($this).
"::setClose ".$this->error, LOG_ERR);
1204 $this->
db->rollback();
1205 $this->error = $this->
db->lasterror();
1221 return $this->
LibStatut(isset($this->statut) ? $this->statut : $this->status, $mode);
1237 $statustrans = array(
1243 $statusClass =
'status0';
1244 if (!empty($statustrans[$status])) {
1245 $statusClass = $statustrans[$status];
1248 return dolGetStatus($langs->transnoentitiesnoconv($this->statuts_long[$status]), $langs->transnoentitiesnoconv($this->statuts_short[$status]),
'', $statusClass, $mode);
1264 public function getNomUrl($withpicto = 0, $option =
'', $addlabel = 0, $moreinpopup =
'', $sep =
' - ', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
1266 global $conf, $langs, $user, $hookmanager;
1268 if (!empty($conf->dol_no_mouse_hover)) {
1273 if (!empty($conf->global->PROJECT_OPEN_ALWAYS_ON_TAB)) {
1274 $option = $conf->global->PROJECT_OPEN_ALWAYS_ON_TAB;
1278 if ($option !=
'nolink') {
1279 $label =
img_picto(
'', $this->picto,
'class="pictofixedwidth"').
' <u class="paddingrightonly">'.$langs->trans(
"Project").
'</u>';
1281 if (isset($this->status)) {
1282 $label .=
' '.$this->getLibStatut(5);
1284 $label .= ($label ?
'<br>' :
'').
'<b>'.$langs->trans(
'Ref').
': </b>'.$this->ref;
1285 $label .= ($label ?
'<br>' :
'').
'<b>'.$langs->trans(
'Label').
': </b>'.$this->title;
1286 if (isset($this->
public)) {
1287 $label .=
'<br><b>'.$langs->trans(
"Visibility").
":</b> ";
1288 $label .= ($this->
public ?
img_picto($langs->trans(
'SharedProject'),
'world',
'class="pictofixedwidth"').$langs->trans(
"SharedProject") :
img_picto($langs->trans(
'PrivateProject'),
'private',
'class="pictofixedwidth"').$langs->trans(
"PrivateProject"));
1290 if (!empty($this->thirdparty_name)) {
1291 $label .= ($label ?
'<br>' :
'').
'<b>'.$langs->trans(
'ThirdParty').
': </b>'.$this->thirdparty_name;
1293 if (!empty($this->date_start)) {
1294 $label .= ($label ?
'<br>' :
'').
'<b>'.$langs->trans(
'DateStart').
': </b>'.
dol_print_date($this->date_start,
'day');
1296 if (!empty($this->date_end)) {
1297 $label .= ($label ?
'<br>' :
'').
'<b>'.$langs->trans(
'DateEnd').
': </b>'.
dol_print_date($this->date_end,
'day');
1300 $label .=
'<br>'.$moreinpopup;
1304 if ($option !=
'nolink') {
1305 if (preg_match(
'/\.php$/', $option)) {
1307 } elseif ($option ==
'task') {
1308 $url = DOL_URL_ROOT.
'/projet/tasks.php?id='.$this->id;
1309 } elseif ($option ==
'preview') {
1310 $url = DOL_URL_ROOT.
'/projet/element.php?id='.$this->id;
1311 } elseif ($option ==
'eventorganization') {
1312 $url = DOL_URL_ROOT.
'/eventorganization/conferenceorbooth_list.php?projectid='.$this->id;
1314 $url = DOL_URL_ROOT.
'/projet/card.php?id='.$this->id;
1317 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1318 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1319 $add_save_lastsearch_values = 1;
1321 if ($add_save_lastsearch_values) {
1322 $url .=
'&save_lastsearch_values=1';
1327 if (empty($notooltip) && $user->hasRight(
'projet',
'lire')) {
1328 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1329 $label = $langs->trans(
"ShowProject");
1330 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1332 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1333 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1335 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1338 $picto =
'projectpub';
1339 if (!$this->
public) {
1343 $linkstart =
'<a href="'.$url.
'"';
1344 $linkstart .= $linkclose.
'>';
1347 $result .= $linkstart;
1349 $result .=
img_object(($notooltip ?
'' : $label), $picto, ($notooltip ? (($withpicto != 2) ?
'class="pictofixedwidth"' :
'') :
'class="'.(($withpicto != 2) ?
'pictofixedwidth ' :
'').
'classfortooltip pictofixedwidth em088"'), 0, 0, $notooltip ? 0 : 1);
1351 if ($withpicto != 2) {
1352 $result .= $this->ref;
1354 $result .= $linkend;
1355 if ($withpicto != 2) {
1356 $result .= (($addlabel && $this->title) ?
'<span class="opacitymedium">'.$sep.dol_trunc($this->title, ($addlabel > 1 ? $addlabel : 0)).
'</span>' :
'');
1360 $hookmanager->initHooks(array(
'projectdao'));
1361 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1362 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1364 $result = $hookmanager->resPrint;
1366 $result .= $hookmanager->resPrint;
1381 global $user, $langs, $conf;
1387 $this->
ref =
'SPECIMEN';
1388 $this->entity = $conf->entity;
1389 $this->specimen = 1;
1391 $this->date_c = $now;
1392 $this->date_m = $now;
1393 $this->date_start = $now;
1394 $this->date_end = $now + (3600 * 24 * 365);
1395 $this->note_public =
'SPECIMEN';
1396 $this->fk_ele = 20000;
1397 $this->opp_amount = 20000;
1398 $this->budget_amount = 10000;
1400 $this->usage_opportunity = 1;
1401 $this->usage_task = 1;
1402 $this->usage_bill_time = 1;
1403 $this->usage_organize_event = 1;
1432 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))) {
1434 } elseif ($this->
public && (($mode ==
'read' && !empty($user->rights->projet->lire)) || ($mode ==
'write' && !empty($user->rights->projet->creer)) || ($mode ==
'delete' && !empty($user->rights->projet->supprimer)))) {
1437 foreach (array(
'internal',
'external') as $source) {
1439 $num = count($userRole);
1442 while ($nblinks < $num) {
1443 if ($source ==
'internal' && $user->id == $userRole[$nblinks][
'id']) {
1444 if ($mode ==
'read' && $user->rights->projet->lire) {
1447 if ($mode ==
'write' && $user->rights->projet->creer) {
1450 if ($mode ==
'delete' && $user->rights->projet->supprimer) {
1454 if ($source ==
'external' && $user->socid > 0 && $user->socid == $userRole[$nblinks][
'socid']) {
1455 if ($mode ==
'read' && $user->rights->projet->lire) {
1458 if ($mode ==
'write' && $user->rights->projet->creer) {
1461 if ($mode ==
'delete' && $user->rights->projet->supprimer) {
1477 return ($userAccess ? $userAccess : -1);
1492 $projects = array();
1495 $sql =
"SELECT ".(($mode == 0 || $mode == 1) ?
"DISTINCT " :
"").
"p.rowid, p.ref";
1496 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
1498 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_contact as ec ON ec.element_id = p.rowid";
1499 } elseif ($mode == 1) {
1500 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1501 } elseif ($mode == 2) {
1504 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
1508 $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).
")";
1512 $listofprojectcontacttype = array();
1513 $sql2 =
"SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1514 $sql2 .=
" WHERE ctc.element = '".$this->db->escape($this->element).
"'";
1515 $sql2 .=
" AND ctc.source = 'internal'";
1518 while ($obj = $this->
db->fetch_object(
$resql)) {
1519 $listofprojectcontacttype[$obj->rowid] = $obj->code;
1524 if (count($listofprojectcontacttype) == 0) {
1525 $listofprojectcontacttype[0] =
'0';
1529 $sql .=
" AND ( p.public = 1";
1530 $sql .=
" OR ( ec.fk_c_type_contact IN (".$this->db->sanitize(join(
',', array_keys($listofprojectcontacttype))).
")";
1531 $sql .=
" AND ec.fk_socpeople = ".((int) $user->id).
")";
1533 } elseif ($mode == 1) {
1534 $sql .=
" AND ec.element_id = p.rowid";
1536 $sql .=
" ( ec.fk_c_type_contact IN (".$this->db->sanitize(join(
',', array_keys($listofprojectcontacttype))).
")";
1537 $sql .=
" AND ec.fk_socpeople = ".((int) $user->id).
")";
1539 } elseif ($mode == 2) {
1548 $num = $this->
db->num_rows(
$resql);
1551 $row = $this->
db->fetch_row(
$resql);
1552 $projects[$row[0]] = $row[1];
1563 $result = implode(
',', $temp);
1588 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)
1590 global $langs, $conf;
1594 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);
1598 $clone_project =
new Project($this->
db);
1600 $clone_project->context[
'createfromclone'] =
'createfromclone';
1605 $clone_project->fetch($fromid);
1606 $clone_project->fetch_optionals();
1607 if ($newthirdpartyid > 0) {
1608 $clone_project->socid = $newthirdpartyid;
1610 $clone_project->fetch_thirdparty();
1612 $orign_dt_start = $clone_project->date_start;
1613 $orign_project_ref = $clone_project->ref;
1615 $clone_project->id = 0;
1617 $clone_project->date_start = $now;
1618 if (!(empty($clone_project->date_end))) {
1619 $clone_project->date_end = $clone_project->date_end + ($now - $orign_dt_start);
1623 $clone_project->date_c = $now;
1626 $clone_project->note_private =
'';
1627 $clone_project->note_public =
'';
1632 $obj = empty($conf->global->PROJECT_ADDON) ?
'mod_project_simple' : $conf->global->PROJECT_ADDON;
1634 $file =
''; $classname =
''; $filefound = 0;
1635 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1636 foreach ($dirmodels as $reldir) {
1637 $file =
dol_buildpath($reldir.
"core/modules/project/".$obj.
'.php', 0);
1638 if (file_exists($file)) {
1641 $modProject =
new $obj;
1642 $defaultref = $modProject->getNextValue(is_object($clone_project->thirdparty) ? $clone_project->thirdparty :
null, $clone_project);
1646 if (is_numeric($defaultref) && $defaultref <= 0) {
1650 $clone_project->ref = $defaultref;
1651 $clone_project->title = $langs->trans(
"CopyOf").
' '.$clone_project->title;
1654 $result = $clone_project->create($user, $notrigger);
1658 $this->error .= $clone_project->error;
1664 $clone_project_id = $clone_project->id;
1668 $clone_project->note_private =
'';
1669 $clone_project->note_public =
'';
1672 $res = $clone_project->update_note(
dol_html_entity_decode($clone_project->note_public, ENT_QUOTES | ENT_HTML5),
'_public');
1674 $this->error .= $clone_project->error;
1676 $this->
db->rollback();
1678 $this->
db->commit();
1682 $res = $clone_project->update_note(
dol_html_entity_decode($clone_project->note_private, ENT_QUOTES | ENT_HTML5),
'_private');
1684 $this->error .= $clone_project->error;
1686 $this->
db->rollback();
1688 $this->
db->commit();
1693 if ($clone_contact) {
1694 $origin_project =
new Project($this->
db);
1695 $origin_project->fetch($fromid);
1697 foreach (array(
'internal',
'external') as $source) {
1698 $tab = $origin_project->liste_contact(-1, $source);
1699 if (is_array($tab) && count($tab)>0) {
1700 foreach ($tab as $contacttoadd) {
1701 $clone_project->add_contact($contacttoadd[
'id'], $contacttoadd[
'code'], $contacttoadd[
'source'], $notrigger);
1702 if ($clone_project->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1703 $langs->load(
"errors");
1704 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
1707 if ($clone_project->error !=
'') {
1708 $this->error .= $clone_project->error;
1713 } elseif ($tab < 0) {
1714 $this->error .= $origin_project->error;
1721 if ($clone_project_file) {
1722 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1727 if (
dol_mkdir($clone_project_dir) >= 0) {
1728 $filearray =
dol_dir_list($ori_project_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'', SORT_ASC, 1);
1729 foreach ($filearray as $key => $file) {
1730 $rescopy =
dol_copy($ori_project_dir.
'/'.$file[
'name'], $clone_project_dir.
'/'.$file[
'name'], 0, 1);
1731 if (is_numeric($rescopy) && $rescopy < 0) {
1732 $this->error .= $langs->trans(
"ErrorFailToCopyFile", $ori_project_dir.
'/'.$file[
'name'], $clone_project_dir.
'/'.$file[
'name']);
1737 $this->error .= $langs->trans(
'ErrorInternalErrorDetected').
':dol_mkdir';
1744 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
1746 $taskstatic =
new Task($this->
db);
1750 if ($user->socid > 0) {
1751 $socid = $user->socid;
1754 $tasksarray = $taskstatic->getTasksArray(0, 0, $fromid, $socid, 0);
1756 $tab_conv_child_parent = array();
1759 foreach ($tasksarray as $tasktoclone) {
1760 $result_clone = $taskstatic->createFromClone($user, $tasktoclone->id, $clone_project_id, $tasktoclone->fk_parent, $move_date,
true,
false, $clone_task_file,
true,
false);
1761 if ($result_clone <= 0) {
1762 $this->error .= $taskstatic->error;
1765 $new_task_id = $result_clone;
1766 $taskstatic->fetch($tasktoclone->id);
1770 if (($taskstatic->hasChildren()) && !array_key_exists($tasktoclone->id, $tab_conv_child_parent)) {
1771 $tab_conv_child_parent[$tasktoclone->id] = $new_task_id;
1777 $tasksarray = $taskstatic->getTasksArray(0, 0, $clone_project_id, $socid, 0);
1778 foreach ($tasksarray as $task_cloned) {
1779 $taskstatic->fetch($task_cloned->id);
1780 if ($taskstatic->fk_task_parent != 0) {
1781 $taskstatic->fk_task_parent = $tab_conv_child_parent[$taskstatic->fk_task_parent];
1783 $res = $taskstatic->update($user, $notrigger);
1784 if ($result_clone <= 0) {
1785 $this->error .= $taskstatic->error;
1792 unset($clone_project->context[
'createfromclone']);
1795 $this->
db->commit();
1796 return $clone_project_id;
1798 $this->
db->rollback();
1799 dol_syslog(get_class($this).
"::createFromClone nbError: ".$error.
" error : ".$this->error, LOG_ERR);
1813 global $user, $langs, $conf;
1818 $taskstatic =
new Task($this->
db);
1822 if ($user->socid > 0) {
1823 $socid = $user->socid;
1826 $tasksarray = $taskstatic->getTasksArray(0, 0, $this->
id, $socid, 0);
1828 foreach ($tasksarray as $tasktoshiftdate) {
1831 if ((!empty($tasktoshiftdate->date_start)) || (!empty($tasktoshiftdate->date_end))) {
1834 $task =
new Task($this->
db);
1835 $result = $task->fetch($tasktoshiftdate->id);
1838 $this->error .= $task->error;
1844 if (!empty($tasktoshiftdate->date_start)) {
1845 $task->date_start = $this->date_start + ($tasktoshiftdate->date_start - $old_project_dt_start);
1849 if (!empty($tasktoshiftdate->date_end)) {
1850 $task->date_end = $this->date_start + ($tasktoshiftdate->date_end - $old_project_dt_start);
1854 $result = $task->update($user);
1857 $this->error .= $task->error;
1879 $sql =
"UPDATE ".MAIN_DB_PREFIX.$tableName;
1881 if ($tableName ==
"actioncomm") {
1882 $sql .=
" SET fk_project=".$this->id;
1883 $sql .=
" WHERE id=".((int) $elementSelectId);
1884 } elseif ($tableName ==
"entrepot") {
1885 $sql .=
" SET fk_project=".$this->id;
1886 $sql .=
" WHERE rowid=".((int) $elementSelectId);
1888 $sql .=
" SET fk_projet=".$this->id;
1889 $sql .=
" WHERE rowid=".((int) $elementSelectId);
1892 dol_syslog(get_class($this).
"::update_element", LOG_DEBUG);
1895 $this->error = $this->
db->lasterror();
1912 public function remove_element($tableName, $elementSelectId, $projectfield =
'fk_projet')
1915 $sql =
"UPDATE ".MAIN_DB_PREFIX.$tableName;
1917 if ($tableName ==
"actioncomm") {
1918 $sql .=
" SET fk_project=NULL";
1919 $sql .=
" WHERE id=".((int) $elementSelectId);
1921 $sql .=
" SET ".$projectfield.
"=NULL";
1922 $sql .=
" WHERE rowid=".((int) $elementSelectId);
1925 dol_syslog(get_class($this).
"::remove_element", LOG_DEBUG);
1928 $this->error = $this->
db->lasterror();
1945 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1947 global $conf, $langs;
1949 $langs->load(
"projects");
1952 $modele =
'baleine';
1954 if ($this->model_pdf) {
1955 $modele = $this->model_pdf;
1956 } elseif (!empty($conf->global->PROJECT_ADDON_PDF)) {
1957 $modele = $conf->global->PROJECT_ADDON_PDF;
1961 $modelpath =
"core/modules/project/doc/";
1963 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1980 $this->weekWorkLoad = array();
1981 $this->weekWorkLoadPerTask = array();
1983 if (empty($datestart)) {
1987 $sql =
"SELECT ptt.rowid as taskid, ptt.task_duration, ptt.task_date, ptt.task_datehour, ptt.fk_task";
1988 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time AS ptt, ".MAIN_DB_PREFIX.
"projet_task as pt";
1989 $sql .=
" WHERE ptt.fk_task = pt.rowid";
1990 $sql .=
" AND pt.fk_projet = ".((int) $this->
id);
1991 $sql .=
" AND (ptt.task_date >= '".$this->db->idate($datestart).
"' ";
1992 $sql .=
" AND ptt.task_date <= '".$this->db->idate(
dol_time_plus_duree($datestart, 1,
'w') - 1).
"')";
1994 $sql .=
" AND ptt.fk_task=".((int) $taskid);
1996 if (is_numeric($userid)) {
1997 $sql .=
" AND ptt.fk_user=".((int) $userid);
2003 $daylareadyfound = array();
2005 $num = $this->
db->num_rows(
$resql);
2009 $obj = $this->
db->fetch_object(
$resql);
2010 $day = $this->
db->jdate($obj->task_date);
2011 if (empty($daylareadyfound[$day])) {
2012 $this->weekWorkLoad[$day] = $obj->task_duration;
2013 $this->weekWorkLoadPerTask[$day][$obj->fk_task] = $obj->task_duration;
2015 $this->weekWorkLoad[$day] += $obj->task_duration;
2016 $this->weekWorkLoadPerTask[$day][$obj->fk_task] += $obj->task_duration;
2018 $daylareadyfound[$day] = 1;
2024 $this->error =
"Error ".$this->db->lasterror();
2025 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
2043 $this->monthWorkLoad = array();
2044 $this->monthWorkLoadPerTask = array();
2046 if (empty($datestart)) {
2050 $sql =
"SELECT ptt.rowid as taskid, ptt.task_duration, ptt.task_date, ptt.task_datehour, ptt.fk_task";
2051 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time AS ptt, ".MAIN_DB_PREFIX.
"projet_task as pt";
2052 $sql .=
" WHERE ptt.fk_task = pt.rowid";
2053 $sql .=
" AND pt.fk_projet = ".((int) $this->
id);
2054 $sql .=
" AND (ptt.task_date >= '".$this->db->idate($datestart).
"' ";
2055 $sql .=
" AND ptt.task_date <= '".$this->db->idate(
dol_time_plus_duree($datestart, 1,
'm') - 1).
"')";
2057 $sql .=
" AND ptt.fk_task=".((int) $taskid);
2059 if (is_numeric($userid)) {
2060 $sql .=
" AND ptt.fk_user=".((int) $userid);
2066 $weekalreadyfound = array();
2068 $num = $this->
db->num_rows(
$resql);
2072 $obj = $this->
db->fetch_object(
$resql);
2073 if (!empty($obj->task_date)) {
2074 $date = explode(
'-', $obj->task_date);
2077 if (empty($weekalreadyfound[$week_number])) {
2078 $this->monthWorkLoad[$week_number] = $obj->task_duration;
2079 $this->monthWorkLoadPerTask[$week_number][$obj->fk_task] = $obj->task_duration;
2081 $this->monthWorkLoad[$week_number] += $obj->task_duration;
2082 $this->monthWorkLoadPerTask[$week_number][$obj->fk_task] += $obj->task_duration;
2084 $weekalreadyfound[$week_number] = 1;
2090 $this->error =
"Error ".$this->db->lasterror();
2091 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
2106 global $conf, $langs;
2112 $response->warning_delay = $conf->project->warning_delay / 60 / 60 / 24;
2113 $response->label = $langs->trans(
"OpenedProjects");
2114 $response->labelShort = $langs->trans(
"Opened");
2115 $response->url = DOL_URL_ROOT.
'/projet/list.php?search_project_user=-1&search_status=1&mainmenu=project';
2116 $response->img =
img_object(
'',
"projectpub");
2117 $response->nbtodo = 0;
2118 $response->nbtodolate = 0;
2120 $sql =
"SELECT p.rowid, p.fk_statut as status, p.fk_opp_status, p.datee as datee";
2121 $sql .=
" FROM (".MAIN_DB_PREFIX.
"projet as p";
2123 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
2126 $sql .=
" WHERE p.fk_statut = 1";
2127 $sql .=
" AND p.entity IN (".getEntity(
'project').
')';
2130 $projectsListId =
null;
2131 if (!$user->hasRight(
"projet",
"all",
"lire")) {
2132 $response->url = DOL_URL_ROOT.
'/projet/list.php?search_status=1&mainmenu=project';
2134 if (empty($projectsListId)) {
2138 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2149 $project_static =
new Project($this->
db);
2153 while ($obj = $this->
db->fetch_object(
$resql)) {
2154 $response->nbtodo++;
2156 $project_static->statut = $obj->status;
2157 $project_static->opp_status = $obj->fk_opp_status;
2158 $project_static->date_end = $this->
db->jdate($obj->datee);
2160 if ($project_static->hasDelay()) {
2161 $response->nbtodolate++;
2168 $this->error = $this->
db->error();
2201 $this->nb = array();
2203 $sql =
"SELECT count(p.rowid) as nb";
2204 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2206 $sql .=
" p.entity IN (".getEntity(
'project').
")";
2207 if (empty($user->rights->projet->all->lire)) {
2209 $sql .=
"AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2214 while ($obj = $this->
db->fetch_object(
$resql)) {
2215 $this->nb[
"projects"] = $obj->nb;
2221 $this->error = $this->
db->error();
2236 if (!($this->statut == self::STATUS_VALIDATED)) {
2239 if (!$this->date_end) {
2245 return ($this->date_end) < ($now - $conf->project->warning_delay);
2257 $sql =
'SELECT c.rowid, datec as datec, tms as datem,';
2258 $sql .=
' date_close as datecloture,';
2259 $sql .=
' fk_user_creat as fk_user_author, fk_user_close as fk_use_cloture';
2260 $sql .=
' FROM '.MAIN_DB_PREFIX.
'projet as c';
2261 $sql .=
' WHERE c.rowid = '.((int) $id);
2262 $result = $this->
db->query($sql);
2264 if ($this->
db->num_rows($result)) {
2265 $obj = $this->
db->fetch_object($result);
2266 $this->
id = $obj->rowid;
2267 if ($obj->fk_user_author) {
2268 $cuser =
new User($this->
db);
2269 $cuser->fetch($obj->fk_user_author);
2270 $this->user_creation = $cuser;
2273 if (!empty($obj->fk_user_cloture)) {
2274 $cluser =
new User($this->
db);
2275 $cluser->fetch($obj->fk_user_cloture);
2276 $this->user_cloture = $cluser;
2279 $this->date_creation = $this->
db->jdate($obj->datec);
2280 $this->date_modification = $this->
db->jdate($obj->datem);
2281 $this->date_cloture = $this->
db->jdate($obj->datecloture);
2284 $this->
db->free($result);
2302 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2303 return parent::setCategoriesCommon($categories, Categorie::TYPE_PROJECT);
2316 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
2317 $taskstatic =
new Task($this->
db);
2319 $this->lines = $taskstatic->getTasksArray(0, $user, $this->
id, 0, 0,
'',
'-1',
'', 0, 0, array(), 0, array(), 0, $loadRoleMode);