2004-10-20 23:06:45 +02:00
< ? php
2005-04-05 13:52:30 +02:00
/* Copyright ( C ) 2002 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2020-03-23 19:35:14 +01:00
* Copyright ( C ) 2005 - 2020 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2010 Regis Houssin < regis . houssin @ inodbox . com >
2013-03-25 19:31:17 +01:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2017-03-12 15:31:39 +01:00
* Copyright ( C ) 2014 - 2017 Marcos GarcÃa < marcosgdf @ gmail . com >
2017-03-03 12:57:52 +01:00
* Copyright ( C ) 2017 Ferran Marcet < fmarcet @ 2 byte . es >
2019-06-14 18:56:30 +02:00
* Copyright ( C ) 2019 Juanjo Menent < jmenent @ 2 byte . es >
2002-05-11 20:53:13 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2002-05-11 20:53:13 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2002-05-11 20:53:13 +02:00
*/
2005-08-14 03:38:12 +02:00
/**
2011-11-02 22:41:34 +01:00
* \file htdocs / projet / class / project . class . php
* \ingroup projet
2012-09-15 15:33:00 +02:00
* \brief File of class to manage projects
2009-01-15 00:36:51 +01:00
*/
2019-11-13 19:35:39 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
2007-05-28 13:30:44 +02:00
2005-08-14 03:38:12 +02:00
/**
2012-09-15 15:33:00 +02:00
* Class to manage projects
2009-01-15 00:36:51 +01:00
*/
2007-05-28 13:30:44 +02:00
class Project extends CommonObject
2006-06-23 21:40:28 +02:00
{
2011-11-02 22:41:34 +01:00
2020-05-19 22:06:17 +02:00
/**
2018-08-23 18:52:47 +02:00
* @ var string ID to identify managed object
*/
2018-08-29 15:37:35 +02:00
public $element = 'project' ;
2020-05-19 22:06:17 +02:00
/**
2018-08-22 19:56:24 +02:00
* @ var string Name of table without prefix where object is stored
*/
2018-08-29 15:37:35 +02:00
public $table_element = 'projet' ;
2020-05-19 22:06:17 +02:00
/**
2020-12-05 23:53:55 +01:00
* @ var string Name of subtable line
2018-09-02 11:08:41 +02:00
*/
public $table_element_line = 'projet_task' ;
2018-09-01 15:27:55 +02:00
2020-05-19 22:06:17 +02:00
/**
2020-12-05 23:53:55 +01:00
* @ var string Name of field date
2019-11-28 23:02:14 +01:00
*/
public $table_element_date ;
2020-05-19 22:06:17 +02:00
/**
2020-12-05 23:53:55 +01:00
* @ var string Field with ID of parent key if this field has a parent
2018-09-01 15:27:55 +02:00
*/
public $fk_element = 'fk_projet' ;
2018-10-06 12:18:03 +02:00
/**
* 0 = No test on entity , 1 = Test with field entity , 2 = Test with link by societe
* @ var int
*/
2020-05-19 22:06:17 +02:00
public $ismultientitymanaged = 1 ;
2018-10-06 12:18:03 +02:00
2020-05-19 22:06:17 +02:00
/**
* @ var string String with name of icon for myobject . Must be the part after the 'object_' into object_myobject . png
*/
2020-05-20 20:10:48 +02:00
public $picto = 'project' ;
2017-06-07 16:44:04 +02:00
2020-05-19 22:06:17 +02:00
/**
* { @ inheritdoc }
*/
protected $table_ref_field = 'ref' ;
2014-12-25 21:47:39 +01:00
2020-05-19 22:06:17 +02:00
/**
2018-08-31 19:26:08 +02:00
* @ var string description
*/
public $description ;
2015-04-23 23:21:06 +02:00
/**
* @ var string
*/
2020-05-19 22:06:17 +02:00
public $title ;
2019-07-19 13:22:54 +02:00
2020-05-19 22:06:17 +02:00
public $date_start ;
public $date_end ;
public $date_close ;
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
public $socid ; // To store id of thirdparty
public $thirdparty_name ; // To store name of thirdparty (defined only in some cases)
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
public $user_author_id ; //!< Id of project creator. Not defined if shared project.
2019-11-14 19:06:14 +01:00
2020-05-19 22:06:17 +02:00
/**
* @ var int user close id
*/
public $fk_user_close ;
2019-11-14 19:06:14 +01:00
2020-05-19 22:06:17 +02:00
/**
* @ var int user close id
*/
2018-09-02 11:08:41 +02:00
public $user_close_id ;
2020-05-19 22:06:17 +02:00
public $public ; //!< Tell if this is a public or private project
2021-03-23 21:04:38 +01:00
/**
* @ var float budget Amount
*/
2020-05-19 22:06:17 +02:00
public $budget_amount ;
2021-03-23 21:04:38 +01:00
/**
2021-04-02 21:49:21 +02:00
* @ var integer Can use projects to follow opportunities
*/
public $usage_opportunity ;
/**
* @ var integer Can follow tasks on project and enter time spent on it
*/
public $usage_task ;
/**
* @ var integer Use to bill task spend time
2021-03-23 21:04:38 +01:00
*/
2020-05-19 22:06:17 +02:00
public $usage_bill_time ; // Is the time spent on project must be invoiced or not
2015-02-16 10:40:09 +01:00
2021-03-23 21:04:38 +01:00
/**
2021-04-02 22:51:14 +02:00
* @ var integer Event organization : Use Event Organization
*/
2021-03-23 21:04:38 +01:00
public $usage_organize_event ;
/**
2021-04-02 21:49:21 +02:00
* @ var integer Event organization : Allow unknown people to suggest new conferences
2021-03-23 21:04:38 +01:00
*/
public $accept_conference_suggestions ;
/**
2021-04-02 21:49:21 +02:00
* @ var integer Event organization : Allow unknown people to suggest new booth
2021-03-23 21:04:38 +01:00
*/
public $accept_booth_suggestions ;
/**
* @ var float Event organization : registration price
*/
public $price_registration ;
/**
* @ var float Event organization : booth price
*/
public $price_booth ;
2022-05-04 01:53:45 +02:00
/**
* @ var float Max attendees
*/
public $max_attendees ;
2020-05-19 22:06:17 +02:00
public $statuts_short ;
public $statuts_long ;
2015-02-16 10:40:09 +01:00
2020-05-19 22:06:17 +02:00
public $statut ; // 0=draft, 1=opened, 2=closed
public $opp_status ; // opportunity status, into table llx_c_lead_status
2019-11-13 19:35:39 +01:00
public $opp_percent ; // opportunity probability
2015-06-29 16:57:32 +02:00
2020-08-21 01:11:22 +02:00
public $email_msgid ;
2020-05-19 22:06:17 +02:00
public $oldcopy ;
2013-07-07 13:14:32 +02:00
2020-05-19 22:06:17 +02:00
public $weekWorkLoad ; // Used to store workload details of a projet
public $weekWorkLoadPerTask ; // Used to store workload details of tasks of a projet
2015-03-18 11:04:50 +01:00
2015-04-23 23:21:06 +02:00
/**
* @ var int Creation date
* @ deprecated
2019-03-11 01:11:39 +01:00
* @ see $date_c
2015-04-23 23:21:06 +02:00
*/
public $datec ;
2018-09-02 11:08:41 +02:00
2015-04-23 23:21:06 +02:00
/**
* @ var int Creation date
*/
public $date_c ;
2018-09-02 11:08:41 +02:00
2015-04-23 23:21:06 +02:00
/**
* @ var int Modification date
* @ deprecated
2019-03-11 01:11:39 +01:00
* @ see $date_m
2015-04-23 23:21:06 +02:00
*/
public $datem ;
2018-09-02 11:08:41 +02:00
2015-04-23 23:21:06 +02:00
/**
* @ var int Modification date
*/
public $date_m ;
2016-11-19 16:08:27 +01:00
/**
* @ var Task []
*/
public $lines ;
2017-06-07 16:44:04 +02:00
2020-09-29 10:00:14 +02:00
/**
* 'type' if the field format ( 'integer' , 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]' , 'varchar(x)' , 'double(24,8)' , 'real' , 'price' , 'text' , 'html' , 'date' , 'datetime' , 'timestamp' , 'duration' , 'mail' , 'phone' , 'url' , 'password' )
* Note : Filter can be a string like " (t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL) "
* 'label' the translation key .
* 'enabled' is a condition when the field must be managed .
* 'position' is the sort order of field .
* 'notnull' is set to 1 if not null in database . Set to - 1 if we must set data to null if empty ( '' or 0 ) .
* 'visible' says if field is visible in list ( Examples : 0 = Not visible , 1 = Visible on list and create / update / view forms , 2 = Visible on list only , 3 = Visible on create / update / view form only ( not list ), 4 = Visible on list and update / view form only ( not create ) . 5 = Visible on list and view only ( not create / not update ) . Using a negative value means field is not shown by default on list but can be selected for viewing )
* 'noteditable' says if field is not editable ( 1 or 0 )
* 'default' is a default value for creation ( can still be overwrote by the Setup of Default Values if field is editable in creation form ) . Note : If default is set to '(PROV)' and field is 'ref' , the default value will be set to '(PROVid)' where id is rowid when a new record is created .
* 'index' if we want an index in database .
* 'foreignkey' => 'tablename.field' if the field is a foreign key ( it is recommanded to name the field fk_ ... ) .
* 'searchall' is 1 if we want to search in this field when making a search from the quick search button .
* 'isameasure' must be set to 1 if you want to have a total on list for this field . Field type must be summable like integer or double ( 24 , 8 ) .
* 'css' is the CSS style to use on field . For example : 'maxwidth200'
* 'help' is a string visible as a tooltip on field
* 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
* 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute . In most cases , this is never set into the definition of $fields into class , but is set dynamically by some part of code .
2021-04-29 12:10:55 +02:00
* 'arrayofkeyval' to set list of value if type is a list of predefined values . For example : array ( " 0 " => " Draft " , " 1 " => " Active " , " -1 " => " Cancel " )
2020-09-29 10:00:14 +02:00
* 'comment' is not used . You can store here any text of your choice . It is not used by application .
*
* Note : To have value dynamic , you can set value to 0 in definition and edit the value on the fly into the constructor .
*/
// BEGIN MODULEBUILDER PROPERTIES
/**
* @ var array Array with all fields and their property . Do not use it as a static var . It may be modified by constructor .
*/
2020-10-07 15:01:28 +02:00
public $fields = array (
2020-09-30 14:54:24 +02:00
'rowid' => array ( 'type' => 'integer' , 'label' => 'ID' , 'enabled' => 1 , 'visible' =>- 1 , 'notnull' => 1 , 'position' => 10 ),
2020-12-17 22:52:42 +01:00
'ref' => array ( 'type' => 'varchar(50)' , 'label' => 'Ref' , 'enabled' => 1 , 'visible' => 1 , 'showoncombobox' => 1 , 'position' => 15 , 'searchall' => 1 ),
2021-06-05 15:14:10 +02:00
'title' => array ( 'type' => 'varchar(255)' , 'label' => 'ProjectLabel' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'position' => 17 , 'showoncombobox' => 2 , 'searchall' => 1 ),
2020-12-17 22:52:42 +01:00
'entity' => array ( 'type' => 'integer' , 'label' => 'Entity' , 'default' => 1 , 'enabled' => 1 , 'visible' => 3 , 'notnull' => 1 , 'position' => 19 ),
'fk_soc' => array ( 'type' => 'integer' , 'label' => 'Thirdparty' , 'enabled' => 1 , 'visible' => 0 , 'position' => 20 ),
2020-09-29 10:00:14 +02:00
'dateo' => array ( 'type' => 'date' , 'label' => 'DateStart' , 'enabled' => 1 , 'visible' => 1 , 'position' => 30 ),
'datee' => array ( 'type' => 'date' , 'label' => 'DateEnd' , 'enabled' => 1 , 'visible' => 1 , 'position' => 35 ),
'description' => array ( 'type' => 'text' , 'label' => 'Description' , 'enabled' => 1 , 'visible' => 3 , 'position' => 55 , 'searchall' => 1 ),
'public' => array ( 'type' => 'integer' , 'label' => 'Visibility' , 'enabled' => 1 , 'visible' => 1 , 'position' => 65 ),
'fk_opp_status' => array ( 'type' => 'integer' , 'label' => 'OpportunityStatusShort' , 'enabled' => 1 , 'visible' => 1 , 'position' => 75 ),
'opp_percent' => array ( 'type' => 'double(5,2)' , 'label' => 'OpportunityProbabilityShort' , 'enabled' => 1 , 'visible' => 1 , 'position' => 80 ),
2020-12-17 22:52:42 +01:00
'note_private' => array ( 'type' => 'text' , 'label' => 'NotePrivate' , 'enabled' => 1 , 'visible' => 0 , 'position' => 85 , 'searchall' => 1 ),
'note_public' => array ( 'type' => 'text' , 'label' => 'NotePublic' , 'enabled' => 1 , 'visible' => 0 , 'position' => 90 , 'searchall' => 1 ),
'model_pdf' => array ( 'type' => 'varchar(255)' , 'label' => 'ModelPdf' , 'enabled' => 1 , 'visible' => 0 , 'position' => 95 ),
'date_close' => array ( 'type' => 'datetime' , 'label' => 'DateClosing' , 'enabled' => 1 , 'visible' => 0 , 'position' => 105 ),
'fk_user_close' => array ( 'type' => 'integer' , 'label' => 'UserClosing' , 'enabled' => 1 , 'visible' => 0 , 'position' => 110 ),
2020-09-29 10:00:14 +02:00
'opp_amount' => array ( 'type' => 'double(24,8)' , 'label' => 'OpportunityAmountShort' , 'enabled' => 1 , 'visible' => 1 , 'position' => 115 ),
2020-12-17 22:52:42 +01:00
'budget_amount' => array ( 'type' => 'double(24,8)' , 'label' => 'Budget' , 'enabled' => 1 , 'visible' => 1 , 'position' => 119 ),
'usage_bill_time' => array ( 'type' => 'integer' , 'label' => 'UsageBillTimeShort' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 130 ),
'usage_opportunity' => array ( 'type' => 'integer' , 'label' => 'UsageOpportunity' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 135 ),
'usage_task' => array ( 'type' => 'integer' , 'label' => 'UsageTasks' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 140 ),
2021-02-15 12:18:08 +01:00
'usage_organize_event' => array ( 'type' => 'integer' , 'label' => 'UsageOrganizeEvent' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 145 ),
2021-02-22 21:00:54 +01:00
'accept_conference_suggestions' => array ( 'type' => 'integer' , 'label' => 'AllowUnknownPeopleSuggestConf' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 146 ),
'accept_booth_suggestions' => array ( 'type' => 'integer' , 'label' => 'AllowUnknownPeopleSuggestBooth' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 147 ),
2021-02-21 12:32:16 +01:00
'price_registration' => array ( 'type' => 'double(24,8)' , 'label' => 'PriceOfRegistration' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 148 ),
'price_booth' => array ( 'type' => 'double(24,8)' , 'label' => 'PriceOfBooth' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 149 ),
2022-05-04 01:53:45 +02:00
'max_attendees' => array ( 'type' => 'integer' , 'label' => 'MaxNbOfAttendees' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 150 ),
2020-12-17 22:52:42 +01:00
'datec' => array ( 'type' => 'datetime' , 'label' => 'DateCreationShort' , 'enabled' => 1 , 'visible' =>- 2 , 'position' => 200 ),
'tms' => array ( 'type' => 'timestamp' , 'label' => 'DateModificationShort' , 'enabled' => 1 , 'visible' =>- 2 , 'notnull' => 1 , 'position' => 205 ),
'fk_user_creat' => array ( 'type' => 'integer' , 'label' => 'UserCreation' , 'enabled' => 1 , 'visible' => 0 , 'notnull' => 1 , 'position' => 210 ),
'fk_user_modif' => array ( 'type' => 'integer' , 'label' => 'UserModification' , 'enabled' => 1 , 'visible' => 0 , 'position' => 215 ),
'import_key' => array ( 'type' => 'varchar(14)' , 'label' => 'ImportId' , 'enabled' => 1 , 'visible' => 0 , 'position' => 220 ),
2021-06-14 19:58:12 +02:00
'email_msgid' => array ( 'type' => 'varchar(255)' , 'label' => 'EmailMsgID' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 250 , 'help' => 'EmailMsgIDWhenSourceisEmail' ),
2020-12-17 22:52:42 +01:00
'fk_statut' => array ( 'type' => 'smallint(6)' , 'label' => 'Status' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'position' => 500 )
2020-09-29 10:00:14 +02:00
);
// END MODULEBUILDER PROPERTIES
2017-06-08 12:21:41 +02:00
/**
* Draft status
*/
const STATUS_DRAFT = 0 ;
2018-09-02 11:08:41 +02:00
2017-06-08 12:21:41 +02:00
/**
* Open / Validated status
*/
const STATUS_VALIDATED = 1 ;
2018-09-02 11:08:41 +02:00
2017-06-08 12:21:41 +02:00
/**
* Closed status
*/
const STATUS_CLOSED = 2 ;
2020-05-19 22:06:17 +02:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
public function __construct ( $db )
{
2021-02-15 12:18:08 +01:00
global $conf ;
2020-05-19 22:06:17 +02:00
$this -> db = $db ;
$this -> statuts_short = array ( 0 => 'Draft' , 1 => 'Opened' , 2 => 'Closed' );
$this -> statuts_long = array ( 0 => 'Draft' , 1 => 'Opened' , 2 => 'Closed' );
2020-09-30 14:57:36 +02:00
2020-09-30 14:54:24 +02:00
global $conf ;
2021-02-26 18:49:22 +01:00
if ( empty ( $conf -> global -> MAIN_SHOW_TECHNICAL_ID )) {
$this -> fields [ 'rowid' ][ 'visible' ] = 0 ;
}
2020-09-30 14:54:24 +02:00
2021-02-12 15:45:49 +01:00
if ( empty ( $conf -> global -> PROJECT_USE_OPPORTUNITIES )) {
2020-09-30 14:54:24 +02:00
$this -> fields [ 'fk_opp_status' ][ 'enabled' ] = 0 ;
$this -> fields [ 'opp_percent' ][ 'enabled' ] = 0 ;
$this -> fields [ 'opp_amount' ][ 'enabled' ] = 0 ;
$this -> fields [ 'usage_opportunity' ][ 'enabled' ] = 0 ;
}
2021-02-15 12:18:08 +01:00
if ( ! empty ( $conf -> global -> PROJECT_HIDE_TASKS )) {
2020-09-30 14:54:24 +02:00
$this -> fields [ 'usage_bill_time' ][ 'visible' ] = 0 ;
$this -> fields [ 'usage_task' ][ 'visible' ] = 0 ;
}
2020-12-17 22:52:42 +01:00
2021-02-15 12:18:08 +01:00
if ( empty ( $conf -> eventorganization -> enabled )) {
2020-12-17 22:52:42 +01:00
$this -> fields [ 'usage_organize_event' ][ 'visible' ] = 0 ;
2021-02-22 21:00:54 +01:00
$this -> fields [ 'accept_conference_suggestions' ][ 'enabled' ] = 0 ;
$this -> fields [ 'accept_booth_suggestions' ][ 'enabled' ] = 0 ;
2021-02-21 12:32:16 +01:00
$this -> fields [ 'price_registration' ][ 'enabled' ] = 0 ;
$this -> fields [ 'price_booth' ][ 'enabled' ] = 0 ;
2020-12-17 22:52:42 +01:00
}
2020-05-19 22:06:17 +02:00
}
/**
* Create a project into database
*
* @ param User $user User making creation
* @ param int $notrigger Disable triggers
* @ return int < 0 if KO , id of created project if OK
*/
public function create ( $user , $notrigger = 0 )
{
global $conf , $langs ;
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
$error = 0 ;
$ret = 0 ;
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
$now = dol_now ();
2018-02-01 19:15:50 +01:00
2020-05-19 22:06:17 +02:00
// Clean parameters
$this -> note_private = dol_substr ( $this -> note_private , 0 , 65535 );
$this -> note_public = dol_substr ( $this -> note_public , 0 , 65535 );
// Check parameters
2021-02-26 18:49:22 +01:00
if ( ! trim ( $this -> ref )) {
2020-05-19 22:06:17 +02:00
$this -> error = 'ErrorFieldsRequired' ;
dol_syslog ( get_class ( $this ) . " ::create error -1 ref null " , LOG_ERR );
return - 1 ;
2015-02-16 10:40:09 +01:00
}
2021-02-26 18:49:22 +01:00
if ( ! empty ( $conf -> global -> PROJECT_THIRDPARTY_REQUIRED ) && ! ( $this -> socid > 0 )) {
2020-05-19 22:06:17 +02:00
$this -> error = 'ErrorFieldsRequired' ;
dol_syslog ( get_class ( $this ) . " ::create error -1 thirdparty not defined and option PROJECT_THIRDPARTY_REQUIRED is set " , LOG_ERR );
return - 1 ;
2017-01-29 13:36:33 +01:00
}
2015-06-03 21:01:50 +02:00
2020-05-19 22:06:17 +02:00
// Create project
$this -> db -> begin ();
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " projet ( " ;
$sql .= " ref " ;
$sql .= " , title " ;
$sql .= " , description " ;
$sql .= " , fk_soc " ;
$sql .= " , fk_user_creat " ;
$sql .= " , fk_statut " ;
$sql .= " , fk_opp_status " ;
$sql .= " , opp_percent " ;
$sql .= " , public " ;
$sql .= " , datec " ;
$sql .= " , dateo " ;
$sql .= " , datee " ;
$sql .= " , opp_amount " ;
$sql .= " , budget_amount " ;
$sql .= " , usage_opportunity " ;
$sql .= " , usage_task " ;
$sql .= " , usage_bill_time " ;
$sql .= " , usage_organize_event " ;
2021-02-22 21:00:54 +01:00
$sql .= " , accept_conference_suggestions " ;
$sql .= " , accept_booth_suggestions " ;
2021-02-21 12:32:16 +01:00
$sql .= " , price_registration " ;
$sql .= " , price_booth " ;
2022-05-04 01:53:45 +02:00
$sql .= " , max_attendees " ;
2020-08-21 01:11:22 +02:00
$sql .= " , email_msgid " ;
2020-05-19 22:06:17 +02:00
$sql .= " , note_private " ;
$sql .= " , note_public " ;
$sql .= " , entity " ;
$sql .= " ) VALUES ( " ;
$sql .= " ' " . $this -> db -> escape ( $this -> ref ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> title ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> description ) . " ' " ;
$sql .= " , " . ( $this -> socid > 0 ? $this -> socid : " null " );
2021-09-03 21:25:17 +02:00
$sql .= " , " . (( int ) $user -> id );
$sql .= " , " . ( is_numeric ( $this -> statut ) ? (( int ) $this -> statut ) : '0' );
$sql .= " , " . (( is_numeric ( $this -> opp_status ) && $this -> opp_status > 0 ) ? (( int ) $this -> opp_status ) : 'NULL' );
$sql .= " , " . ( is_numeric ( $this -> opp_percent ) ? (( int ) $this -> opp_percent ) : 'NULL' );
2020-05-19 22:06:17 +02:00
$sql .= " , " . ( $this -> public ? 1 : 0 );
$sql .= " , ' " . $this -> db -> idate ( $now ) . " ' " ;
$sql .= " , " . ( $this -> date_start != '' ? " ' " . $this -> db -> idate ( $this -> date_start ) . " ' " : 'null' );
$sql .= " , " . ( $this -> date_end != '' ? " ' " . $this -> db -> idate ( $this -> date_end ) . " ' " : 'null' );
$sql .= " , " . ( strcmp ( $this -> opp_amount , '' ) ? price2num ( $this -> opp_amount ) : 'null' );
$sql .= " , " . ( strcmp ( $this -> budget_amount , '' ) ? price2num ( $this -> budget_amount ) : 'null' );
$sql .= " , " . ( $this -> usage_opportunity ? 1 : 0 );
$sql .= " , " . ( $this -> usage_task ? 1 : 0 );
$sql .= " , " . ( $this -> usage_bill_time ? 1 : 0 );
$sql .= " , " . ( $this -> usage_organize_event ? 1 : 0 );
2021-02-22 21:00:54 +01:00
$sql .= " , " . ( $this -> accept_conference_suggestions ? 1 : 0 );
$sql .= " , " . ( $this -> accept_booth_suggestions ? 1 : 0 );
2021-02-21 12:32:16 +01:00
$sql .= " , " . ( strcmp ( $this -> price_registration , '' ) ? price2num ( $this -> price_registration ) : 'null' );
$sql .= " , " . ( strcmp ( $this -> price_booth , '' ) ? price2num ( $this -> price_booth ) : 'null' );
2022-05-04 01:53:45 +02:00
$sql .= " , " . ( strcmp ( $this -> max_attendees , '' ) ? (( int ) $this -> max_attendees ) : 'null' );
2020-08-21 01:11:22 +02:00
$sql .= " , " . ( $this -> email_msgid ? " ' " . $this -> db -> escape ( $this -> email_msgid ) . " ' " : 'null' );
2020-05-19 22:06:17 +02:00
$sql .= " , " . ( $this -> note_private ? " ' " . $this -> db -> escape ( $this -> note_private ) . " ' " : 'null' );
$sql .= " , " . ( $this -> note_public ? " ' " . $this -> db -> escape ( $this -> note_public ) . " ' " : 'null' );
2021-09-03 21:25:17 +02:00
$sql .= " , " . (( int ) $conf -> entity );
2020-05-19 22:06:17 +02:00
$sql .= " ) " ;
dol_syslog ( get_class ( $this ) . " ::create " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $resql ) {
2020-05-19 22:06:17 +02:00
$this -> id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " projet " );
$ret = $this -> id ;
2020-02-02 09:06:02 +01:00
2021-02-26 18:49:22 +01:00
if ( ! $notrigger ) {
2020-05-19 22:06:17 +02:00
// Call trigger
$result = $this -> call_trigger ( 'PROJECT_CREATE' , $user );
2021-02-26 18:49:22 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2020-05-19 22:06:17 +02:00
// End call triggers
}
2020-05-21 15:05:19 +02:00
} else {
2020-05-19 22:06:17 +02:00
$this -> error = $this -> db -> lasterror ();
$this -> errno = $this -> db -> lasterrno ();
$error ++ ;
2014-10-29 20:21:24 +01:00
}
2013-07-07 13:14:32 +02:00
2020-05-19 22:06:17 +02:00
// Update extrafield
2019-11-13 19:35:39 +01:00
if ( ! $error ) {
2020-05-20 20:10:48 +02:00
$result = $this -> insertExtraFields ();
2021-02-26 18:49:22 +01:00
if ( $result < 0 ) {
2020-05-20 20:10:48 +02:00
$error ++ ;
2019-06-14 18:56:30 +02:00
}
}
2021-02-26 18:49:22 +01:00
if ( ! $error && ! empty ( $conf -> global -> MAIN_DISABLEDRAFTSTATUS )) {
2020-05-19 22:06:17 +02:00
$res = $this -> setValid ( $user );
2021-02-26 18:49:22 +01:00
if ( $res < 0 ) {
$error ++ ;
}
2017-07-06 15:48:22 +02:00
}
2019-06-14 18:56:30 +02:00
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2020-05-19 22:06:17 +02:00
$this -> db -> commit ();
return $ret ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-19 22:06:17 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
/**
* Update a project
2019-02-24 23:32:09 +01:00
*
2020-05-19 22:06:17 +02:00
* @ param User $user User object of making update
* @ param int $notrigger 1 = Disable all triggers
* @ return int <= 0 if KO , > 0 if OK
2019-02-24 23:32:09 +01:00
*/
2020-05-19 22:06:17 +02:00
public function update ( $user , $notrigger = 0 )
{
2019-11-13 19:35:39 +01:00
global $langs , $conf ;
2012-04-27 11:03:01 +02:00
2019-11-13 19:35:39 +01:00
$error = 0 ;
2012-05-06 00:15:03 +02:00
2020-05-19 22:06:17 +02:00
// Clean parameters
$this -> title = trim ( $this -> title );
$this -> description = trim ( $this -> description );
2021-02-26 18:49:22 +01:00
if ( $this -> opp_amount < 0 ) {
$this -> opp_amount = '' ;
}
if ( $this -> opp_percent < 0 ) {
$this -> opp_percent = '' ;
}
if ( $this -> date_end && $this -> date_end < $this -> date_start ) {
2020-05-19 22:06:17 +02:00
$this -> error = $langs -> trans ( " ErrorDateEndLowerThanDateStart " );
$this -> errors [] = $this -> error ;
$this -> db -> rollback ();
dol_syslog ( get_class ( $this ) . " ::update error -3 " . $this -> error , LOG_ERR );
return - 3 ;
2012-04-27 11:03:01 +02:00
}
2022-03-25 11:53:27 +01:00
$this -> entity = (( isset ( $this -> entity ) && is_numeric ( $this -> entity )) ? $this -> entity : $conf -> entity );
2021-02-26 18:49:22 +01:00
if ( dol_strlen ( trim ( $this -> ref )) > 0 ) {
2020-05-19 22:06:17 +02:00
$this -> db -> begin ();
$sql = " UPDATE " . MAIN_DB_PREFIX . " projet SET " ;
$sql .= " ref=' " . $this -> db -> escape ( $this -> ref ) . " ' " ;
$sql .= " , title = ' " . $this -> db -> escape ( $this -> title ) . " ' " ;
$sql .= " , description = ' " . $this -> db -> escape ( $this -> description ) . " ' " ;
$sql .= " , fk_soc = " . ( $this -> socid > 0 ? $this -> socid : " null " );
2021-06-09 15:36:47 +02:00
$sql .= " , fk_statut = " . (( int ) $this -> statut );
2020-05-19 22:06:17 +02:00
$sql .= " , fk_opp_status = " . (( is_numeric ( $this -> opp_status ) && $this -> opp_status > 0 ) ? $this -> opp_status : 'null' );
$sql .= " , opp_percent = " . (( is_numeric ( $this -> opp_percent ) && $this -> opp_percent != '' ) ? $this -> opp_percent : 'null' );
$sql .= " , public = " . ( $this -> public ? 1 : 0 );
$sql .= " , datec= " . ( $this -> date_c != '' ? " ' " . $this -> db -> idate ( $this -> date_c ) . " ' " : 'null' );
$sql .= " , dateo= " . ( $this -> date_start != '' ? " ' " . $this -> db -> idate ( $this -> date_start ) . " ' " : 'null' );
$sql .= " , datee= " . ( $this -> date_end != '' ? " ' " . $this -> db -> idate ( $this -> date_end ) . " ' " : 'null' );
$sql .= " , date_close= " . ( $this -> date_close != '' ? " ' " . $this -> db -> idate ( $this -> date_close ) . " ' " : 'null' );
$sql .= " , fk_user_close= " . ( $this -> fk_user_close > 0 ? $this -> fk_user_close : " null " );
$sql .= " , opp_amount = " . ( strcmp ( $this -> opp_amount , '' ) ? price2num ( $this -> opp_amount ) : " null " );
$sql .= " , budget_amount = " . ( strcmp ( $this -> budget_amount , '' ) ? price2num ( $this -> budget_amount ) : " null " );
$sql .= " , fk_user_modif = " . $user -> id ;
$sql .= " , usage_opportunity = " . ( $this -> usage_opportunity ? 1 : 0 );
$sql .= " , usage_task = " . ( $this -> usage_task ? 1 : 0 );
$sql .= " , usage_bill_time = " . ( $this -> usage_bill_time ? 1 : 0 );
$sql .= " , usage_organize_event = " . ( $this -> usage_organize_event ? 1 : 0 );
2021-02-22 21:00:54 +01:00
$sql .= " , accept_conference_suggestions = " . ( $this -> accept_conference_suggestions ? 1 : 0 );
$sql .= " , accept_booth_suggestions = " . ( $this -> accept_booth_suggestions ? 1 : 0 );
2021-02-21 12:32:16 +01:00
$sql .= " , price_registration = " . ( strcmp ( $this -> price_registration , '' ) ? price2num ( $this -> price_registration ) : " null " );
$sql .= " , price_booth = " . ( strcmp ( $this -> price_booth , '' ) ? price2num ( $this -> price_booth ) : " null " );
2022-05-04 01:53:45 +02:00
$sql .= " , max_attendees = " . ( strcmp ( $this -> max_attendees , '' ) ? price2num ( $this -> max_attendees ) : " null " );
2022-03-25 11:53:27 +01:00
$sql .= " , entity = " . (( int ) $this -> entity );
2021-03-30 19:12:07 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2020-05-19 22:06:17 +02:00
dol_syslog ( get_class ( $this ) . " ::update " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $resql ) {
2020-05-19 22:06:17 +02:00
// Update extrafield
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2020-05-20 20:10:48 +02:00
$result = $this -> insertExtraFields ();
2021-02-26 18:49:22 +01:00
if ( $result < 0 ) {
2020-05-20 20:10:48 +02:00
$error ++ ;
2020-05-19 22:06:17 +02:00
}
2012-04-27 11:03:01 +02:00
}
2012-05-06 00:15:03 +02:00
2021-02-26 18:49:22 +01:00
if ( ! $error && ! $notrigger ) {
2020-05-19 22:06:17 +02:00
// Call trigger
$result = $this -> call_trigger ( 'PROJECT_MODIFY' , $user );
2021-02-26 18:49:22 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2020-05-19 22:06:17 +02:00
// End call triggers
2012-04-27 11:03:01 +02:00
}
2012-05-06 00:15:03 +02:00
2021-02-26 18:49:22 +01:00
if ( ! $error && ( is_object ( $this -> oldcopy ) && $this -> oldcopy -> ref !== $this -> ref )) {
2020-05-19 22:06:17 +02:00
// We remove directory
2021-02-26 18:49:22 +01:00
if ( $conf -> projet -> dir_output ) {
2020-05-19 22:06:17 +02:00
$olddir = $conf -> projet -> dir_output . " / " . dol_sanitizeFileName ( $this -> oldcopy -> ref );
$newdir = $conf -> projet -> dir_output . " / " . dol_sanitizeFileName ( $this -> ref );
2021-02-26 18:49:22 +01:00
if ( file_exists ( $olddir )) {
2020-05-19 22:06:17 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
$res = @ rename ( $olddir , $newdir );
2021-02-26 18:49:22 +01:00
if ( ! $res ) {
2020-05-19 22:06:17 +02:00
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( 'ErrorFailToRenameDir' , $olddir , $newdir );
2012-04-27 11:03:01 +02:00
$error ++ ;
}
}
}
}
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2020-05-19 22:06:17 +02:00
$this -> db -> commit ();
$result = 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-19 22:06:17 +02:00
$this -> db -> rollback ();
$result = - 1 ;
2012-04-27 11:03:01 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-05-19 22:06:17 +02:00
$this -> error = $this -> db -> lasterror ();
$this -> errors [] = $this -> error ;
$this -> db -> rollback ();
2021-02-26 18:49:22 +01:00
if ( $this -> db -> lasterrno () == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
2020-05-19 22:06:17 +02:00
$result = - 4 ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-19 22:06:17 +02:00
$result = - 2 ;
}
dol_syslog ( get_class ( $this ) . " ::update error " . $result . " " . $this -> error , LOG_ERR );
2012-04-27 11:03:01 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-05-19 22:06:17 +02:00
dol_syslog ( get_class ( $this ) . " ::update ref null " );
$result = - 1 ;
2012-04-27 11:03:01 +02:00
}
2012-05-06 00:15:03 +02:00
2020-05-19 22:06:17 +02:00
return $result ;
2012-05-06 00:15:03 +02:00
}
2013-07-07 13:14:32 +02:00
2018-09-03 19:00:37 +02:00
/**
2020-05-19 22:06:17 +02:00
* Get object from database
2018-09-03 19:00:37 +02:00
*
2020-08-23 18:04:52 +02:00
* @ param int $id Id of object to load
* @ param string $ref Ref of project
2020-08-27 18:50:08 +02:00
* @ param string $ref_ext Ref ext of project
2020-08-23 18:04:52 +02:00
* @ param string $email_msgid Email msgid
* @ return int > 0 if OK , 0 if not found , < 0 if KO
2020-05-19 22:06:17 +02:00
*/
2020-08-27 18:50:08 +02:00
public function fetch ( $id , $ref = '' , $ref_ext = '' , $email_msgid = '' )
2013-04-29 12:02:58 +02:00
{
2020-05-19 22:06:17 +02:00
global $conf ;
2013-07-07 13:14:32 +02:00
2021-06-14 20:06:52 +02:00
if ( empty ( $id ) && empty ( $ref ) && empty ( $ref_ext ) && empty ( $email_msgid )) {
2021-06-14 20:13:27 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch Bad parameters " , LOG_WARNING );
2021-02-26 18:49:22 +01:00
return - 1 ;
}
2013-07-07 13:14:32 +02:00
2020-08-21 01:11:22 +02:00
$sql = " SELECT rowid, entity, ref, title, description, public, datec, opp_amount, budget_amount, " ;
2020-05-20 20:10:48 +02:00
$sql .= " tms, dateo, datee, date_close, fk_soc, fk_user_creat, fk_user_modif, fk_user_close, fk_statut as status, fk_opp_status, opp_percent, " ;
2021-02-21 12:32:16 +01:00
$sql .= " note_private, note_public, model_pdf, usage_opportunity, usage_task, usage_bill_time, usage_organize_event, email_msgid, " ;
2022-05-04 01:53:45 +02:00
$sql .= " accept_conference_suggestions, accept_booth_suggestions, price_registration, price_booth, max_attendees " ;
2020-05-19 22:06:17 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet " ;
2021-02-26 18:49:22 +01:00
if ( ! empty ( $id )) {
2021-03-14 11:48:39 +01:00
$sql .= " WHERE rowid = " . (( int ) $id );
2020-08-23 18:04:52 +02:00
} else {
$sql .= " WHERE entity IN ( " . getEntity ( 'project' ) . " ) " ;
2020-09-07 10:18:17 +02:00
if ( ! empty ( $ref )) {
2020-08-23 18:04:52 +02:00
$sql .= " AND ref = ' " . $this -> db -> escape ( $ref ) . " ' " ;
2020-09-08 21:27:28 +02:00
} elseif ( ! empty ( $ref_ext )) {
2020-08-27 18:50:08 +02:00
$sql .= " AND ref_ext = ' " . $this -> db -> escape ( $ref_ext ) . " ' " ;
2020-08-23 18:04:52 +02:00
} else {
$sql .= " AND email_msgid = ' " . $this -> db -> escape ( $email_msgid ) . " ' " ;
}
2013-04-29 12:02:58 +02:00
}
2013-07-07 13:14:32 +02:00
2020-05-19 22:06:17 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch " , LOG_DEBUG );
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $resql ) {
2020-05-19 22:06:17 +02:00
$num_rows = $this -> db -> num_rows ( $resql );
2014-09-23 00:02:19 +02:00
2021-02-26 18:49:22 +01:00
if ( $num_rows ) {
2020-05-19 22:06:17 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2014-09-23 00:02:19 +02:00
2020-05-19 22:06:17 +02:00
$this -> id = $obj -> rowid ;
2020-08-21 01:11:22 +02:00
$this -> entity = $obj -> entity ;
2020-05-19 22:06:17 +02:00
$this -> ref = $obj -> ref ;
$this -> title = $obj -> title ;
$this -> description = $obj -> description ;
$this -> date_c = $this -> db -> jdate ( $obj -> datec );
$this -> datec = $this -> db -> jdate ( $obj -> datec ); // TODO deprecated
$this -> date_m = $this -> db -> jdate ( $obj -> tms );
$this -> datem = $this -> db -> jdate ( $obj -> tms ); // TODO deprecated
$this -> date_start = $this -> db -> jdate ( $obj -> dateo );
$this -> date_end = $this -> db -> jdate ( $obj -> datee );
$this -> date_close = $this -> db -> jdate ( $obj -> date_close );
$this -> note_private = $obj -> note_private ;
$this -> note_public = $obj -> note_public ;
$this -> socid = $obj -> fk_soc ;
$this -> user_author_id = $obj -> fk_user_creat ;
$this -> user_modification_id = $obj -> fk_user_modif ;
$this -> user_close_id = $obj -> fk_user_close ;
$this -> public = $obj -> public ;
2020-05-20 20:10:48 +02:00
$this -> statut = $obj -> status ; // deprecated
$this -> status = $obj -> status ;
2020-05-19 22:06:17 +02:00
$this -> opp_status = $obj -> fk_opp_status ;
$this -> opp_amount = $obj -> opp_amount ;
$this -> opp_percent = $obj -> opp_percent ;
$this -> budget_amount = $obj -> budget_amount ;
2020-08-18 14:48:38 +02:00
$this -> model_pdf = $obj -> model_pdf ;
2020-10-07 15:01:28 +02:00
$this -> modelpdf = $obj -> model_pdf ; // deprecated
2020-05-19 22:06:17 +02:00
$this -> usage_opportunity = ( int ) $obj -> usage_opportunity ;
$this -> usage_task = ( int ) $obj -> usage_task ;
$this -> usage_bill_time = ( int ) $obj -> usage_bill_time ;
$this -> usage_organize_event = ( int ) $obj -> usage_organize_event ;
2021-02-22 21:00:54 +01:00
$this -> accept_conference_suggestions = ( int ) $obj -> accept_conference_suggestions ;
$this -> accept_booth_suggestions = ( int ) $obj -> accept_booth_suggestions ;
2021-02-21 12:32:16 +01:00
$this -> price_registration = $obj -> price_registration ;
$this -> price_booth = $obj -> price_booth ;
2022-05-04 01:53:45 +02:00
$this -> max_attendees = $obj -> max_attendees ;
2020-08-21 01:11:22 +02:00
$this -> email_msgid = $obj -> email_msgid ;
2020-05-19 22:06:17 +02:00
$this -> db -> free ( $resql );
2020-10-23 20:08:35 +02:00
// Retrieve all extrafield
2020-05-19 22:06:17 +02:00
// fetch optionals attributes and labels
$this -> fetch_optionals ();
return 1 ;
}
2014-09-23 00:02:19 +02:00
2020-05-19 22:06:17 +02:00
$this -> db -> free ( $resql );
2014-09-23 00:02:19 +02:00
2020-05-19 22:06:17 +02:00
return 0 ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2021-03-11 19:09:42 +01:00
$this -> errors [] = $this -> db -> lasterror ();
2014-09-20 10:14:26 +02:00
return - 1 ;
}
2013-04-29 12:02:58 +02:00
}
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
2020-05-19 22:06:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
/**
2020-05-19 22:06:17 +02:00
* Return list of elements for type , linked to a project
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
*
2020-05-19 22:06:17 +02:00
* @ param string $type 'propal' , 'order' , 'invoice' , 'order_supplier' , 'invoice_supplier' , ...
* @ param string $tablename name of table associated of the type
* @ param string $datefieldname name of date field for filter
* @ param int $dates Start date
* @ param int $datee End date
* @ param string $projectkey Equivalent key to fk_projet for actual type
* @ return mixed Array list of object ids linked to project , < 0 or string if error
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
*/
2020-05-19 22:06:17 +02:00
public function get_element_list ( $type , $tablename , $datefieldname = '' , $dates = '' , $datee = '' , $projectkey = 'fk_projet' )
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
{
2020-05-19 22:06:17 +02:00
// phpcs:enable
2020-12-15 11:34:04 +01:00
global $hookmanager ;
2020-05-19 22:06:17 +02:00
$elements = array ();
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
2021-02-26 18:49:22 +01:00
if ( $this -> id <= 0 ) {
return $elements ;
}
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
2020-05-19 22:06:17 +02:00
$ids = $this -> id ;
2017-01-16 21:16:05 +01:00
2021-02-26 18:49:22 +01:00
if ( $type == 'agenda' ) {
2021-03-22 11:30:18 +01:00
$sql = " SELECT id as rowid FROM " . MAIN_DB_PREFIX . " actioncomm WHERE fk_project IN ( " . $this -> db -> sanitize ( $ids ) . " ) AND entity IN ( " . getEntity ( 'agenda' ) . " ) " ;
2021-02-26 18:49:22 +01:00
} elseif ( $type == 'expensereport' ) {
2021-03-22 11:30:18 +01:00
$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 ) . " ) " ;
2021-02-26 18:49:22 +01:00
} elseif ( $type == 'project_task' ) {
2021-03-22 11:30:18 +01:00
$sql = " SELECT DISTINCT pt.rowid FROM " . MAIN_DB_PREFIX . " projet_task as pt WHERE pt.fk_projet IN ( " . $this -> db -> sanitize ( $ids ) . " ) " ;
2021-02-26 18:49:22 +01:00
} elseif ( $type == 'project_task_time' ) { // Case we want to duplicate line foreach user
2021-03-22 11:30:18 +01:00
$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 ) . " ) " ;
2021-02-26 18:49:22 +01:00
} elseif ( $type == 'stock_mouvement' ) {
2021-09-30 15:59:47 +02:00
$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 " ;
2021-02-26 18:49:22 +01:00
} elseif ( $type == 'loan' ) {
2021-09-30 15:59:47 +02:00
$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 ) . " ) " ;
2020-05-21 15:05:19 +02:00
} else {
2021-03-22 11:30:18 +01:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . $tablename . " WHERE " . $projectkey . " IN ( " . $this -> db -> sanitize ( $ids ) . " ) AND entity IN ( " . getEntity ( $type ) . " ) " ;
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
}
2020-09-07 10:18:17 +02:00
if ( $dates > 0 && $type == 'loan' ) {
2020-05-19 22:06:17 +02:00
$sql .= " AND (dateend > ' " . $this -> db -> idate ( $dates ) . " ' OR dateend IS NULL) " ;
2021-02-26 18:49:22 +01:00
} elseif ( $dates > 0 && ( $type != 'project_task' )) { // For table project_taks, we want the filter on date apply on project_time_spent table
if ( empty ( $datefieldname ) && ! empty ( $this -> table_element_date )) {
$datefieldname = $this -> table_element_date ;
}
if ( empty ( $datefieldname )) {
return 'Error this object has no date field defined' ;
}
2020-05-19 22:06:17 +02:00
$sql .= " AND ( " . $datefieldname . " >= ' " . $this -> db -> idate ( $dates ) . " ' OR " . $datefieldname . " IS NULL) " ;
}
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
2020-09-07 10:18:17 +02:00
if ( $datee > 0 && $type == 'loan' ) {
2020-05-19 22:06:17 +02:00
$sql .= " AND (datestart < ' " . $this -> db -> idate ( $datee ) . " ' OR datestart IS NULL) " ;
2021-02-26 18:49:22 +01:00
} elseif ( $datee > 0 && ( $type != 'project_task' )) { // For table project_taks, we want the filter on date apply on project_time_spent table
if ( empty ( $datefieldname ) && ! empty ( $this -> table_element_date )) {
$datefieldname = $this -> table_element_date ;
}
if ( empty ( $datefieldname )) {
return 'Error this object has no date field defined' ;
}
2020-05-19 22:06:17 +02:00
$sql .= " AND ( " . $datefieldname . " <= ' " . $this -> db -> idate ( $datee ) . " ' OR " . $datefieldname . " IS NULL) " ;
}
2020-12-15 11:34:04 +01:00
$parameters = array (
'sql' => $sql ,
'type' => $type ,
'tablename' => $tablename ,
'datefieldname' => $datefieldname ,
'dates' => $dates ,
'datee' => $datee ,
2021-07-29 14:49:41 +02:00
'fk_projet' => $projectkey ,
'ids' => $ids ,
2020-12-15 11:34:04 +01:00
);
2021-12-28 19:47:58 +01:00
$reshook = $hookmanager -> executeHooks ( 'getElementList' , $parameters );
2021-02-26 18:49:22 +01:00
if ( $reshook > 0 ) {
$sql = $hookmanager -> resPrint ;
} else {
$sql .= $hookmanager -> resPrint ;
}
2020-12-15 11:34:04 +01:00
2021-02-26 18:49:22 +01:00
if ( ! $sql ) {
return - 1 ;
}
2020-05-19 22:06:17 +02:00
//print $sql;
dol_syslog ( get_class ( $this ) . " ::get_element_list " , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $result ) {
2020-05-19 22:06:17 +02:00
$nump = $this -> db -> num_rows ( $result );
2021-02-26 18:49:22 +01:00
if ( $nump ) {
2020-05-19 22:06:17 +02:00
$i = 0 ;
2021-02-26 18:49:22 +01:00
while ( $i < $nump ) {
2020-05-19 22:06:17 +02:00
$obj = $this -> db -> fetch_object ( $result );
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
2020-05-19 22:06:17 +02:00
$elements [ $i ] = $obj -> rowid . ( empty ( $obj -> fk_user ) ? '' : '_' . $obj -> fk_user );
2015-03-04 00:53:35 +01:00
2019-10-20 11:59:21 +02:00
$i ++ ;
2020-05-19 22:06:17 +02:00
}
$this -> db -> free ( $result );
2019-10-20 11:59:21 +02:00
}
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
2020-05-19 22:06:17 +02:00
/* Return array even if empty*/
return $elements ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-19 22:06:17 +02:00
dol_print_error ( $this -> db );
}
}
2015-03-04 00:53:35 +01:00
2019-11-21 17:05:06 +01:00
/**
2020-05-19 22:06:17 +02:00
* Delete a project from database
2019-11-21 17:05:06 +01:00
*
2020-05-19 22:06:17 +02:00
* @ param User $user User
* @ param int $notrigger Disable triggers
* @ return int < 0 if KO , 0 if not possible , > 0 if OK
2019-11-21 17:05:06 +01:00
*/
2020-05-19 22:06:17 +02:00
public function delete ( $user , $notrigger = 0 )
2019-11-21 17:05:06 +01:00
{
2020-05-19 22:06:17 +02:00
global $langs , $conf ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2019-11-21 17:05:06 +01:00
2020-05-19 22:06:17 +02:00
$error = 0 ;
2019-11-21 17:05:06 +01:00
2020-05-19 22:06:17 +02:00
$this -> db -> begin ();
2019-11-21 17:05:06 +01:00
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2020-05-19 22:06:17 +02:00
// Delete linked contacts
$res = $this -> delete_linked_contact ();
2021-02-26 18:49:22 +01:00
if ( $res < 0 ) {
2020-05-19 22:06:17 +02:00
$this -> error = 'ErrorFailToDeleteLinkedContact' ;
//$error++;
$this -> db -> rollback ();
return 0 ;
}
}
2019-11-21 17:05:06 +01:00
2020-05-19 22:06:17 +02:00
// Set fk_projet into elements to null
$listoftables = array (
'propal' => 'fk_projet' , 'commande' => 'fk_projet' , 'facture' => 'fk_projet' ,
'supplier_proposal' => 'fk_projet' , 'commande_fournisseur' => 'fk_projet' , 'facture_fourn' => 'fk_projet' ,
'expensereport_det' => 'fk_projet' , 'contrat' => 'fk_projet' , 'fichinter' => 'fk_projet' , 'don' => 'fk_projet' ,
2021-09-24 02:02:12 +02:00
'actioncomm' => 'fk_project' , 'mrp_mo' => 'fk_project' , 'entrepot' => 'fk_project'
2020-05-19 22:06:17 +02:00
);
2021-02-26 18:49:22 +01:00
foreach ( $listoftables as $key => $value ) {
2021-03-30 03:37:54 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . $key . " SET " . $value . " = NULL where " . $value . " = " . (( int ) $this -> id );
2020-05-19 22:06:17 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( ! $resql ) {
2020-05-19 22:06:17 +02:00
$this -> errors [] = $this -> db -> lasterror ();
$error ++ ;
break ;
}
}
// Remove linked categories.
if ( ! $error ) {
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " categorie_project " ;
2021-03-30 19:12:07 +02:00
$sql .= " WHERE fk_project = " . (( int ) $this -> id );
2020-05-19 22:06:17 +02:00
$result = $this -> db -> query ( $sql );
if ( ! $result ) {
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
}
}
// Fetch tasks
$this -> getLinesArray ( $user );
// Delete tasks
$ret = $this -> deleteTasks ( $user );
2021-02-26 18:49:22 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2019-11-21 17:05:06 +01:00
2020-05-19 22:06:17 +02:00
// Delete all child tables
if ( ! $error ) {
$elements = array ( 'categorie_project' ); // elements to delete. TODO Make goodway to delete
2021-02-26 18:49:22 +01:00
foreach ( $elements as $table ) {
2020-05-19 22:06:17 +02:00
if ( ! $error ) {
$sql = " DELETE FROM " . MAIN_DB_PREFIX . $table ;
2021-03-30 19:12:07 +02:00
$sql .= " WHERE fk_project = " . (( int ) $this -> id );
2020-05-19 22:06:17 +02:00
$result = $this -> db -> query ( $sql );
if ( ! $result ) {
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
}
2019-11-21 17:05:06 +01:00
}
2020-05-19 22:06:17 +02:00
}
}
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2020-06-29 14:01:48 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " projet_extrafields " ;
2021-08-27 18:18:50 +02:00
$sql .= " WHERE fk_object = " . (( int ) $this -> id );
2020-05-19 22:06:17 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( ! $resql ) {
2020-06-29 14:01:48 +02:00
$this -> errors [] = $this -> db -> lasterror ();
2020-05-19 22:06:17 +02:00
$error ++ ;
}
}
2020-06-29 14:01:48 +02:00
// Delete project
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2020-06-29 14:01:48 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " projet " ;
2021-03-14 12:20:23 +01:00
$sql .= " WHERE rowid= " . (( int ) $this -> id );
2020-05-19 22:06:17 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( ! $resql ) {
2020-06-29 14:01:48 +02:00
$this -> errors [] = $langs -> trans ( " CantRemoveProject " , $langs -> transnoentitiesnoconv ( " ProjectOverview " ));
2020-05-19 22:06:17 +02:00
$error ++ ;
}
}
2020-06-29 14:01:48 +02:00
2020-05-19 22:06:17 +02:00
if ( empty ( $error )) {
// We remove directory
$projectref = dol_sanitizeFileName ( $this -> ref );
if ( $conf -> projet -> dir_output ) {
$dir = $conf -> projet -> dir_output . " / " . $projectref ;
if ( file_exists ( $dir )) {
$res = @ dol_delete_dir_recursive ( $dir );
if ( ! $res ) {
$this -> errors [] = 'ErrorFailToDeleteDir' ;
$error ++ ;
}
2019-11-21 17:05:06 +01:00
}
2019-10-20 11:59:21 +02:00
}
2016-08-29 10:32:00 +02:00
2021-02-26 18:49:22 +01:00
if ( ! $notrigger ) {
2020-05-19 22:06:17 +02:00
// Call trigger
$result = $this -> call_trigger ( 'PROJECT_DELETE' , $user );
if ( $result < 0 ) {
$error ++ ;
2019-11-21 17:05:06 +01:00
}
2020-05-19 22:06:17 +02:00
// End call triggers
2019-11-21 17:05:06 +01:00
}
2020-05-19 22:06:17 +02:00
}
2021-02-26 18:49:22 +01:00
if ( empty ( $error )) {
2020-05-19 22:06:17 +02:00
$this -> db -> commit ();
2019-11-21 17:05:06 +01:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 18:49:22 +01:00
foreach ( $this -> errors as $errmsg ) {
2020-05-19 22:06:17 +02:00
dol_syslog ( get_class ( $this ) . " ::delete " . $errmsg , LOG_ERR );
$this -> error .= ( $this -> error ? ', ' . $errmsg : $errmsg );
}
dol_syslog ( get_class ( $this ) . " ::delete " . $this -> error , LOG_ERR );
$this -> db -> rollback ();
2019-11-21 17:05:06 +01:00
return - 1 ;
}
}
2015-03-04 00:53:35 +01:00
2020-10-06 12:56:28 +02:00
/**
* Return the count of a type of linked elements of this project
*
* @ param string $type The type of the linked elements ( e . g . 'propal' , 'order' , 'invoice' , 'order_supplier' , 'invoice_supplier' )
* @ param string $tablename The name of table associated of the type
* @ param string $projectkey ( optional ) Equivalent key to fk_projet for actual type
* @ return integer The count of the linked elements ( the count is zero on request error too )
*/
public function getElementCount ( $type , $tablename , $projectkey = 'fk_projet' )
{
2021-02-26 18:49:22 +01:00
if ( $this -> id <= 0 ) {
return 0 ;
}
2020-10-06 12:56:28 +02:00
if ( $type == 'agenda' ) {
2021-08-27 18:18:50 +02:00
$sql = " SELECT COUNT(id) as nb FROM " . MAIN_DB_PREFIX . " actioncomm WHERE fk_project = " . (( int ) $this -> id ) . " AND entity IN ( " . getEntity ( 'agenda' ) . " ) " ;
2020-10-06 12:56:28 +02:00
} elseif ( $type == 'expensereport' ) {
2021-03-30 19:12:07 +02:00
$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 );
2020-10-06 12:56:28 +02:00
} elseif ( $type == 'project_task' ) {
2021-08-23 18:56:46 +02:00
$sql = " SELECT DISTINCT COUNT(pt.rowid) as nb FROM " . MAIN_DB_PREFIX . " projet_task as pt WHERE pt.fk_projet = " . (( int ) $this -> id );
2020-10-06 12:56:28 +02:00
} elseif ( $type == 'project_task_time' ) { // Case we want to duplicate line foreach user
2021-03-30 19:12:07 +02:00
$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 );
2020-10-06 12:56:28 +02:00
} elseif ( $type == 'stock_mouvement' ) {
2021-09-30 15:59:47 +02:00
$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 " ;
2020-10-06 12:56:28 +02:00
} elseif ( $type == 'loan' ) {
2021-09-30 15:59:47 +02:00
$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 );
2020-10-06 12:56:28 +02:00
} else {
2021-03-30 19:12:07 +02:00
$sql = " SELECT COUNT(rowid) as nb FROM " . MAIN_DB_PREFIX . $tablename . " WHERE " . $projectkey . " = " . (( int ) $this -> id ) . " AND entity IN ( " . getEntity ( $type ) . " ) " ;
2020-10-06 12:56:28 +02:00
}
$result = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( ! $result ) {
return 0 ;
}
2020-10-06 12:56:28 +02:00
$obj = $this -> db -> fetch_object ( $result );
$this -> db -> free ( $result );
return $obj -> nb ;
}
2015-04-18 18:11:01 +02:00
/**
2020-05-19 22:06:17 +02:00
* Delete tasks with no children first , then task with children recursively
2015-04-18 18:11:01 +02:00
*
2020-05-19 22:06:17 +02:00
* @ param User $user User
* @ return int < 0 if KO , 1 if OK
2015-04-18 18:11:01 +02:00
*/
2020-05-19 22:06:17 +02:00
public function deleteTasks ( $user )
2015-04-18 18:11:01 +02:00
{
2020-05-19 22:06:17 +02:00
$countTasks = count ( $this -> lines );
$deleted = false ;
2021-02-26 18:49:22 +01:00
if ( $countTasks ) {
foreach ( $this -> lines as $task ) {
2020-05-19 22:06:17 +02:00
if ( $task -> hasChildren () <= 0 ) { // If there is no children (or error to detect them)
$deleted = true ;
$ret = $task -> delete ( $user );
2021-02-26 18:49:22 +01:00
if ( $ret <= 0 ) {
2020-05-19 22:06:17 +02:00
$this -> errors [] = $this -> db -> lasterror ();
return - 1 ;
}
}
}
}
$this -> getLinesArray ( $user );
2021-02-26 18:49:22 +01:00
if ( $deleted && count ( $this -> lines ) < $countTasks ) {
if ( count ( $this -> lines )) {
$this -> deleteTasks ( $this -> lines );
}
2020-05-19 22:06:17 +02:00
}
2015-04-18 18:11:01 +02:00
2020-05-19 22:06:17 +02:00
return 1 ;
2015-04-18 18:11:01 +02:00
}
2016-08-29 10:32:00 +02:00
2016-02-28 00:19:12 +01:00
/**
2020-05-19 22:06:17 +02:00
* Validate a project
2016-02-28 00:19:12 +01:00
*
2020-05-19 22:06:17 +02:00
* @ param User $user User that validate
* @ param int $notrigger 1 = Disable triggers
* @ return int < 0 if KO , > 0 if OK
2016-02-28 00:19:12 +01:00
*/
2020-05-19 22:06:17 +02:00
public function setValid ( $user , $notrigger = 0 )
2016-02-28 00:19:12 +01:00
{
2020-05-19 22:06:17 +02:00
global $langs , $conf ;
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
$error = 0 ;
2016-08-29 10:32:00 +02:00
2021-02-26 18:49:22 +01:00
if ( $this -> statut != 1 ) {
2020-05-19 22:06:17 +02:00
// Check parameters
2021-02-26 18:49:22 +01:00
if ( preg_match ( '/^' . preg_quote ( $langs -> trans ( " CopyOf " ) . ' ' ) . '/' , $this -> title )) {
2020-05-19 22:06:17 +02:00
$this -> error = $langs -> trans ( " ErrorFieldFormat " , $langs -> transnoentities ( " Label " )) . '. ' . $langs -> trans ( 'RemoveString' , $langs -> transnoentitiesnoconv ( " CopyOf " ));
return - 1 ;
}
$this -> db -> begin ();
$sql = " UPDATE " . MAIN_DB_PREFIX . " projet " ;
$sql .= " SET fk_statut = 1 " ;
2021-08-23 18:56:46 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
$sql .= " AND entity = " . (( int ) $conf -> entity );
2020-05-19 22:06:17 +02:00
dol_syslog ( get_class ( $this ) . " ::setValid " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $resql ) {
2020-05-19 22:06:17 +02:00
// Call trigger
2021-02-26 18:49:22 +01:00
if ( empty ( $notrigger )) {
2020-05-19 22:06:17 +02:00
$result = $this -> call_trigger ( 'PROJECT_VALIDATE' , $user );
2021-02-26 18:49:22 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2020-05-19 22:06:17 +02:00
// End call triggers
}
2016-08-29 10:32:00 +02:00
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2020-05-19 22:06:17 +02:00
$this -> statut = 1 ;
$this -> db -> commit ();
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-19 22:06:17 +02:00
$this -> db -> rollback ();
$this -> error = join ( ',' , $this -> errors );
dol_syslog ( get_class ( $this ) . " ::setValid " . $this -> error , LOG_ERR );
return - 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-05-19 22:06:17 +02:00
$this -> db -> rollback ();
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
}
}
2016-08-29 10:32:00 +02:00
2016-01-18 15:56:51 +01:00
/**
2020-05-19 22:06:17 +02:00
* Close a project
2016-01-18 15:56:51 +01:00
*
2020-05-19 22:06:17 +02:00
* @ param User $user User that close project
* @ return int < 0 if KO , 0 if already closed , > 0 if OK
2016-01-18 15:56:51 +01:00
*/
2020-05-19 22:06:17 +02:00
public function setClose ( $user )
2016-01-18 15:56:51 +01:00
{
2020-05-19 22:06:17 +02:00
global $langs , $conf ;
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
$now = dol_now ();
2016-01-18 15:56:51 +01:00
2020-05-19 22:06:17 +02:00
$error = 0 ;
2016-01-18 15:56:51 +01:00
2021-02-26 18:49:22 +01:00
if ( $this -> statut != self :: STATUS_CLOSED ) {
2020-05-19 22:06:17 +02:00
$this -> db -> begin ();
$sql = " UPDATE " . MAIN_DB_PREFIX . " projet " ;
2021-03-30 03:37:54 +02:00
$sql .= " SET fk_statut = " . self :: STATUS_CLOSED . " , fk_user_close = " . (( int ) $user -> id ) . " , date_close = ' " . $this -> db -> idate ( $now ) . " ' " ;
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2020-05-19 22:06:17 +02:00
$sql .= " AND fk_statut = " . self :: STATUS_VALIDATED ;
2021-02-26 18:49:22 +01:00
if ( ! empty ( $conf -> global -> PROJECT_USE_OPPORTUNITIES )) {
2020-05-19 22:06:17 +02:00
// TODO What to do if fk_opp_status is not code 'WON' or 'LOST'
}
dol_syslog ( get_class ( $this ) . " ::setClose " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $resql ) {
2020-05-19 22:06:17 +02:00
// Call trigger
$result = $this -> call_trigger ( 'PROJECT_CLOSE' , $user );
2021-02-26 18:49:22 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2020-05-19 22:06:17 +02:00
// End call triggers
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2020-05-19 22:06:17 +02:00
$this -> statut = 2 ;
$this -> db -> commit ();
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-19 22:06:17 +02:00
$this -> db -> rollback ();
$this -> error = join ( ',' , $this -> errors );
dol_syslog ( get_class ( $this ) . " ::setClose " . $this -> error , LOG_ERR );
return - 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-05-19 22:06:17 +02:00
$this -> db -> rollback ();
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
2017-03-12 15:31:39 +01:00
}
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
return 0 ;
2016-02-28 00:19:12 +01:00
}
2015-04-18 18:11:01 +02:00
2016-07-09 15:30:42 +02:00
/**
2020-05-19 22:06:17 +02:00
* Return status label of object
2016-07-09 15:30:42 +02:00
*
2020-05-19 22:06:17 +02:00
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto
* @ return string Label
2016-07-09 15:30:42 +02:00
*/
2020-05-19 22:06:17 +02:00
public function getLibStatut ( $mode = 0 )
2016-07-09 15:30:42 +02:00
{
2020-05-20 20:10:48 +02:00
return $this -> LibStatut ( isset ( $this -> statut ) ? $this -> statut : $this -> status , $mode );
2016-07-09 15:30:42 +02:00
}
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2016-08-29 10:32:00 +02:00
/**
2020-05-19 22:06:17 +02:00
* Renvoi status label for a status
2016-08-29 10:32:00 +02:00
*
2020-05-19 22:06:17 +02:00
* @ param int $status id status
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto , 6 = Long label + Picto
* @ return string Label
2016-08-29 10:32:00 +02:00
*/
2020-05-19 22:06:17 +02:00
public function LibStatut ( $status , $mode = 0 )
2016-08-29 10:32:00 +02:00
{
2020-05-19 22:06:17 +02:00
// phpcs:enable
global $langs ;
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
$statustrans = array (
0 => 'status0' ,
1 => 'status4' ,
2 => 'status6' ,
);
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
$statusClass = 'status0' ;
if ( ! empty ( $statustrans [ $status ])) {
$statusClass = $statustrans [ $status ];
2016-08-29 10:32:00 +02:00
}
2021-10-16 19:37:57 +02:00
return dolGetStatus ( $langs -> transnoentitiesnoconv ( $this -> statuts_long [ $status ]), $langs -> transnoentitiesnoconv ( $this -> statuts_short [ $status ]), '' , $statusClass , $mode );
2017-06-07 16:44:04 +02:00
}
2016-08-29 10:32:00 +02:00
2016-07-09 15:30:42 +02:00
/**
2020-05-20 23:58:32 +02:00
* Return clickable name ( with picto eventually )
2016-07-09 15:30:42 +02:00
*
2020-05-19 22:06:17 +02:00
* @ param int $withpicto 0 = No picto , 1 = Include picto into link , 2 = Only picto
2020-05-20 23:58:32 +02:00
* @ param string $option Variant where the link point to ( '' , 'nolink' )
2020-05-19 22:06:17 +02:00
* @ param int $addlabel 0 = Default , 1 = Add label into string , > 1 = Add first chars into string
* @ param string $moreinpopup Text to add into popup
* @ param string $sep Separator between ref and label if option addlabel is set
* @ param int $notooltip 1 = Disable tooltip
* @ param int $save_lastsearch_value - 1 = Auto , 0 = No save of lastsearch_values when clicking , 1 = Save lastsearch_values whenclicking
2020-05-20 23:58:32 +02:00
* @ param string $morecss More css on a link
2020-05-19 22:06:17 +02:00
* @ return string String with URL
2016-07-09 15:30:42 +02:00
*/
2020-05-20 20:10:48 +02:00
public function getNomUrl ( $withpicto = 0 , $option = '' , $addlabel = 0 , $moreinpopup = '' , $sep = ' - ' , $notooltip = 0 , $save_lastsearch_value = - 1 , $morecss = '' )
2016-07-09 15:30:42 +02:00
{
2020-05-19 22:06:17 +02:00
global $conf , $langs , $user , $hookmanager ;
2021-02-26 18:49:22 +01:00
if ( ! empty ( $conf -> dol_no_mouse_hover )) {
$notooltip = 1 ; // Force disable tooltips
}
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
$result = '' ;
2020-09-07 10:18:17 +02:00
if ( ! empty ( $conf -> global -> PROJECT_OPEN_ALWAYS_ON_TAB )) {
2020-05-20 20:10:48 +02:00
$option = $conf -> global -> PROJECT_OPEN_ALWAYS_ON_TAB ;
2016-08-29 10:32:00 +02:00
}
2020-05-19 22:06:17 +02:00
$label = '' ;
2021-02-26 18:49:22 +01:00
if ( $option != 'nolink' ) {
2021-10-30 17:19:46 +02:00
$label = img_picto ( '' , $this -> picto , 'class="pictofixedwidth"' ) . ' <u class="paddingrightonly">' . $langs -> trans ( " Project " ) . '</u>' ;
2021-02-26 18:49:22 +01:00
}
2020-11-02 11:41:07 +01:00
if ( isset ( $this -> status )) {
$label .= ' ' . $this -> getLibStatut ( 5 );
}
2020-05-19 22:06:17 +02:00
$label .= ( $label ? '<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
$label .= ( $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
2020-05-20 20:10:48 +02:00
if ( isset ( $this -> public )) {
$label .= '<br><b>' . $langs -> trans ( " Visibility " ) . " :</b> " . ( $this -> public ? $langs -> trans ( " SharedProject " ) : $langs -> trans ( " PrivateProject " ));
}
2020-05-20 23:25:10 +02:00
if ( ! empty ( $this -> thirdparty_name )) {
2020-05-19 22:06:17 +02:00
$label .= ( $label ? '<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
2020-05-20 23:25:10 +02:00
}
if ( ! empty ( $this -> dateo )) {
2020-05-20 20:10:48 +02:00
$label .= ( $label ? '<br>' : '' ) . '<b>' . $langs -> trans ( 'DateStart' ) . ': </b>' . dol_print_date ( $this -> dateo , 'day' ); // The space must be after the : to not being explode when showing the title in img_picto
2020-05-20 23:25:10 +02:00
}
if ( ! empty ( $this -> datee )) {
2020-05-20 20:10:48 +02:00
$label .= ( $label ? '<br>' : '' ) . '<b>' . $langs -> trans ( 'DateEnd' ) . ': </b>' . dol_print_date ( $this -> datee , 'day' ); // The space must be after the : to not being explode when showing the title in img_picto
2020-05-20 23:25:10 +02:00
}
2021-02-26 18:49:22 +01:00
if ( $moreinpopup ) {
$label .= '<br>' . $moreinpopup ;
}
2020-05-19 22:06:17 +02:00
2020-05-20 20:10:48 +02:00
$url = '' ;
2021-02-26 18:49:22 +01:00
if ( $option != 'nolink' ) {
2020-05-20 20:10:48 +02:00
if ( preg_match ( '/\.php$/' , $option )) {
$url = dol_buildpath ( $option , 1 ) . '?id=' . $this -> id ;
2021-02-26 18:49:22 +01:00
} elseif ( $option == 'task' ) {
2020-05-20 20:10:48 +02:00
$url = DOL_URL_ROOT . '/projet/tasks.php?id=' . $this -> id ;
2021-02-26 18:49:22 +01:00
} elseif ( $option == 'preview' ) {
2020-05-20 20:10:48 +02:00
$url = DOL_URL_ROOT . '/projet/element.php?id=' . $this -> id ;
2021-03-15 20:20:53 +01:00
} elseif ( $option == 'eventorganization' ) {
$url = DOL_URL_ROOT . '/eventorganization/conferenceorbooth_list.php?projectid=' . $this -> id ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 20:10:48 +02:00
$url = DOL_URL_ROOT . '/projet/card.php?id=' . $this -> id ;
2016-08-29 10:32:00 +02:00
}
2020-05-20 20:10:48 +02:00
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ( $save_lastsearch_value == 1 ? 1 : 0 );
2021-02-26 18:49:22 +01:00
if ( $save_lastsearch_value == - 1 && preg_match ( '/list\.php/' , $_SERVER [ " PHP_SELF " ])) {
$add_save_lastsearch_values = 1 ;
}
if ( $add_save_lastsearch_values ) {
$url .= '&save_lastsearch_values=1' ;
}
2016-08-29 10:32:00 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 20:10:48 +02:00
$linkclose = '' ;
2021-02-26 18:49:22 +01:00
if ( empty ( $notooltip ) && $user -> rights -> projet -> lire ) {
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
2020-05-20 20:10:48 +02:00
$label = $langs -> trans ( " ShowProject " );
$linkclose .= ' alt="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
2016-08-29 10:32:00 +02:00
}
2020-05-20 20:10:48 +02:00
$linkclose .= ' title="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
2020-06-18 02:50:46 +02:00
$linkclose .= ' class="classfortooltip' . ( $morecss ? ' ' . $morecss : '' ) . '"' ;
2021-02-26 18:49:22 +01:00
} else {
$linkclose = ( $morecss ? ' class="' . $morecss . '"' : '' );
2016-08-29 10:32:00 +02:00
}
2020-05-20 20:10:48 +02:00
$picto = 'projectpub' ;
2021-02-26 18:49:22 +01:00
if ( ! $this -> public ) {
$picto = 'project' ;
}
2020-05-19 22:06:17 +02:00
2020-05-20 20:10:48 +02:00
$linkstart = '<a href="' . $url . '"' ;
$linkstart .= $linkclose . '>' ;
$linkend = '</a>' ;
2020-05-19 22:06:17 +02:00
2020-05-20 20:10:48 +02:00
$result .= $linkstart ;
2021-02-26 18:49:22 +01:00
if ( $withpicto ) {
2021-10-30 17:19:46 +02:00
$result .= img_object (( $notooltip ? '' : $label ), $picto , ( $notooltip ? (( $withpicto != 2 ) ? 'class="paddingright"' : '' ) : 'class="' . (( $withpicto != 2 ) ? 'paddingright ' : '' ) . 'classfortooltip pictofixedwidth"' ), 0 , 0 , $notooltip ? 0 : 1 );
2021-02-26 18:49:22 +01:00
}
if ( $withpicto != 2 ) {
$result .= $this -> ref ;
}
2020-05-20 20:10:48 +02:00
$result .= $linkend ;
2021-02-26 18:49:22 +01:00
if ( $withpicto != 2 ) {
$result .= (( $addlabel && $this -> title ) ? $sep . dol_trunc ( $this -> title , ( $addlabel > 1 ? $addlabel : 0 )) : '' );
}
2020-05-19 22:06:17 +02:00
2020-05-20 20:10:48 +02:00
global $action ;
$hookmanager -> initHooks ( array ( 'projectdao' ));
2021-11-22 19:57:26 +01:00
$parameters = array ( 'id' => $this -> id , 'getnomurl' => & $result );
2020-05-20 20:10:48 +02:00
$reshook = $hookmanager -> executeHooks ( 'getNomUrl' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 18:49:22 +01:00
if ( $reshook > 0 ) {
$result = $hookmanager -> resPrint ;
} else {
$result .= $hookmanager -> resPrint ;
}
2020-05-19 22:06:17 +02:00
2020-05-20 20:10:48 +02:00
return $result ;
2016-08-29 10:32:00 +02:00
}
/**
2020-05-19 22:06:17 +02:00
* Initialise an instance with random values .
* Used to build previews or test instances .
* id must be 0 if object instance is a specimen .
2016-08-29 10:32:00 +02:00
*
2020-05-19 22:06:17 +02:00
* @ return void
2016-08-29 10:32:00 +02:00
*/
2020-05-19 22:06:17 +02:00
public function initAsSpecimen ()
2016-08-29 10:32:00 +02:00
{
2020-05-19 22:06:17 +02:00
global $user , $langs , $conf ;
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
$now = dol_now ();
// Initialise parameters
$this -> id = 0 ;
$this -> ref = 'SPECIMEN' ;
$this -> specimen = 1 ;
$this -> socid = 1 ;
$this -> date_c = $now ;
$this -> date_m = $now ;
$this -> date_start = $now ;
$this -> date_end = $now + ( 3600 * 24 * 365 );
$this -> note_public = 'SPECIMEN' ;
$this -> fk_ele = 20000 ;
$this -> opp_amount = 20000 ;
$this -> budget_amount = 10000 ;
$this -> usage_opportunity = 1 ;
$this -> usage_task = 1 ;
$this -> usage_bill_time = 1 ;
$this -> usage_organize_event = 1 ;
/*
$nbp = mt_rand ( 1 , 9 );
$xnbp = 0 ;
while ( $xnbp < $nbp )
{
$line = new Task ( $this -> db );
$line -> fk_project = 0 ;
$line -> label = $langs -> trans ( " Label " ) . " " . $xnbp ;
$line -> description = $langs -> trans ( " Description " ) . " " . $xnbp ;
$this -> lines [] = $line ;
$xnbp ++ ;
}
*/
}
2017-06-07 16:44:04 +02:00
2016-11-09 22:54:51 +01:00
/**
2020-05-19 22:06:17 +02:00
* Check if user has permission on current project
2017-06-07 16:44:04 +02:00
*
2020-05-19 22:06:17 +02:00
* @ param User $user Object user to evaluate
* @ param string $mode Type of permission we want to know : 'read' , 'write'
* @ return int > 0 if user has permission , < 0 if user has no permission
2016-11-09 22:54:51 +01:00
*/
2020-11-05 09:40:37 +01:00
public function restrictedProjectArea ( User $user , $mode = 'read' )
2016-11-09 22:54:51 +01:00
{
2020-05-19 22:06:17 +02:00
// To verify role of users
$userAccess = 0 ;
2021-02-26 18:49:22 +01:00
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 ))) {
2020-05-19 22:06:17 +02:00
$userAccess = 1 ;
2021-02-26 18:49:22 +01:00
} elseif ( $this -> public && (( $mode == 'read' && ! empty ( $user -> rights -> projet -> lire )) || ( $mode == 'write' && ! empty ( $user -> rights -> projet -> creer )) || ( $mode == 'delete' && ! empty ( $user -> rights -> projet -> supprimer )))) {
2020-05-19 22:06:17 +02:00
$userAccess = 1 ;
2020-11-05 09:40:37 +01:00
} else { // No access due to permission to read all projects, so we check if we are a contact of project
2021-02-26 18:49:22 +01:00
foreach ( array ( 'internal' , 'external' ) as $source ) {
2020-05-19 22:06:17 +02:00
$userRole = $this -> liste_contact ( 4 , $source );
$num = count ( $userRole );
2016-08-29 10:32:00 +02:00
2020-05-19 22:06:17 +02:00
$nblinks = 0 ;
2021-02-26 18:49:22 +01:00
while ( $nblinks < $num ) {
if ( $source == 'internal' && $user -> id == $userRole [ $nblinks ][ 'id' ]) { // $userRole[$nblinks]['id'] is id of user (llx_user) for internal contacts
if ( $mode == 'read' && $user -> rights -> projet -> lire ) {
$userAccess ++ ;
}
if ( $mode == 'write' && $user -> rights -> projet -> creer ) {
$userAccess ++ ;
}
if ( $mode == 'delete' && $user -> rights -> projet -> supprimer ) {
$userAccess ++ ;
}
2020-11-05 09:40:37 +01:00
}
2021-02-26 18:49:22 +01:00
if ( $source == 'external' && $user -> socid > 0 && $user -> socid == $userRole [ $nblinks ][ 'socid' ]) { // $userRole[$nblinks]['id'] is id of contact (llx_socpeople) or external contacts
if ( $mode == 'read' && $user -> rights -> projet -> lire ) {
$userAccess ++ ;
}
if ( $mode == 'write' && $user -> rights -> projet -> creer ) {
$userAccess ++ ;
}
if ( $mode == 'delete' && $user -> rights -> projet -> supprimer ) {
$userAccess ++ ;
}
2020-05-19 22:06:17 +02:00
}
$nblinks ++ ;
2016-08-29 10:32:00 +02:00
}
}
2020-05-19 22:06:17 +02:00
//if (empty($nblinks)) // If nobody has permission, we grant creator
//{
// if ((!empty($this->user_author_id) && $this->user_author_id == $user->id))
// {
// $userAccess = 1;
2020-05-20 20:10:48 +02:00
// }
//}
2016-08-29 10:32:00 +02:00
}
2016-11-09 22:54:51 +01:00
2020-05-20 23:56:06 +02:00
return ( $userAccess ? $userAccess : - 1 );
2020-05-20 20:10:48 +02:00
}
2016-08-29 10:32:00 +02:00
2020-05-20 23:56:06 +02:00
/**
* Return array of projects a user has permission on , is affected to , or all projects
*
* @ param User $user User object
* @ param int $mode 0 = All project I have permission on ( assigned to me or public ), 1 = Projects assigned to me only , 2 = Will return list of all projects with no test on contacts
* @ param int $list 0 = Return array , 1 = Return string list
* @ param int $socid 0 = No filter on third party , id of third party
* @ param string $filter additionnal filter on project ( statut , ref , ... )
* @ return array or string Array of projects id , or string with projects id separated with " , " if list is 1
*/
public function getProjectsAuthorizedForUser ( $user , $mode = 0 , $list = 0 , $socid = 0 , $filter = '' )
2020-05-20 20:10:48 +02:00
{
2020-05-20 23:56:06 +02:00
$projects = array ();
$temp = array ();
2017-06-07 16:44:04 +02:00
2020-05-20 23:56:06 +02:00
$sql = " SELECT " . (( $mode == 0 || $mode == 1 ) ? " DISTINCT " : " " ) . " p.rowid, p.ref " ;
2020-09-07 10:18:17 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet as p " ;
2021-02-26 18:49:22 +01:00
if ( $mode == 0 ) {
2020-09-07 10:18:17 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " element_contact as ec ON ec.element_id = p.rowid " ;
2021-02-26 18:49:22 +01:00
} elseif ( $mode == 1 ) {
2020-09-07 10:18:17 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " element_contact as ec " ;
2021-02-26 18:49:22 +01:00
} elseif ( $mode == 2 ) {
2020-05-20 23:56:06 +02:00
// No filter. Use this if user has permission to see all project
}
2020-09-07 10:18:17 +02:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'project' ) . " ) " ;
2020-05-20 23:56:06 +02:00
// Internal users must see project he is contact to even if project linked to a third party he can't see.
2021-08-23 17:41:11 +02:00
//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).")";
2021-02-26 18:49:22 +01:00
if ( $socid > 0 ) {
2021-08-23 17:41:11 +02:00
$sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . (( int ) $socid ) . " ) " ;
2021-02-26 18:49:22 +01:00
}
2020-05-20 23:56:06 +02:00
// Get id of types of contacts for projects (This list never contains a lot of elements)
2020-09-07 10:18:17 +02:00
$listofprojectcontacttype = array ();
2020-05-20 23:56:06 +02:00
$sql2 = " SELECT ctc.rowid, ctc.code FROM " . MAIN_DB_PREFIX . " c_type_contact as ctc " ;
2020-09-07 10:18:17 +02:00
$sql2 .= " WHERE ctc.element = ' " . $this -> db -> escape ( $this -> element ) . " ' " ;
$sql2 .= " AND ctc.source = 'internal' " ;
2020-05-20 23:56:06 +02:00
$resql = $this -> db -> query ( $sql2 );
2021-02-26 18:49:22 +01:00
if ( $resql ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2020-09-07 10:18:17 +02:00
$listofprojectcontacttype [ $obj -> rowid ] = $obj -> code ;
2020-05-19 22:06:17 +02:00
}
2021-02-26 18:49:22 +01:00
} else {
dol_print_error ( $this -> db );
}
if ( count ( $listofprojectcontacttype ) == 0 ) {
$listofprojectcontacttype [ 0 ] = '0' ; // To avoid syntax error if not found
}
2016-08-29 10:32:00 +02:00
2021-02-26 18:49:22 +01:00
if ( $mode == 0 ) {
2020-09-07 10:18:17 +02:00
$sql .= " AND ( p.public = 1 " ;
2021-03-22 11:30:18 +01:00
$sql .= " OR ( ec.fk_c_type_contact IN ( " . $this -> db -> sanitize ( join ( ',' , array_keys ( $listofprojectcontacttype ))) . " ) " ;
2021-08-23 18:56:46 +02:00
$sql .= " AND ec.fk_socpeople = " . (( int ) $user -> id ) . " ) " ;
2020-09-07 10:18:17 +02:00
$sql .= " ) " ;
2021-02-26 18:49:22 +01:00
} elseif ( $mode == 1 ) {
2020-09-07 10:18:17 +02:00
$sql .= " AND ec.element_id = p.rowid " ;
$sql .= " AND ( " ;
2021-03-22 11:30:18 +01:00
$sql .= " ( ec.fk_c_type_contact IN ( " . $this -> db -> sanitize ( join ( ',' , array_keys ( $listofprojectcontacttype ))) . " ) " ;
2021-08-23 18:56:46 +02:00
$sql .= " AND ec.fk_socpeople = " . (( int ) $user -> id ) . " ) " ;
2020-09-07 10:18:17 +02:00
$sql .= " ) " ;
2021-02-26 18:49:22 +01:00
} elseif ( $mode == 2 ) {
2020-05-20 23:56:06 +02:00
// No filter. Use this if user has permission to see all project
}
2020-05-20 20:10:48 +02:00
2020-09-07 10:18:17 +02:00
$sql .= $filter ;
2020-05-20 23:56:06 +02:00
//print $sql;
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $resql ) {
2020-05-20 23:56:06 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-26 18:49:22 +01:00
while ( $i < $num ) {
2020-05-20 23:56:06 +02:00
$row = $this -> db -> fetch_row ( $resql );
$projects [ $row [ 0 ]] = $row [ 1 ];
$temp [] = $row [ 0 ];
$i ++ ;
}
2016-08-29 10:32:00 +02:00
2020-05-20 23:56:06 +02:00
$this -> db -> free ( $resql );
2017-06-07 16:44:04 +02:00
2021-02-26 18:49:22 +01:00
if ( $list ) {
if ( empty ( $temp )) {
return '0' ;
}
2020-05-20 23:56:06 +02:00
$result = implode ( ',' , $temp );
return $result ;
2020-05-19 22:06:17 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
dol_print_error ( $this -> db );
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
return $projects ;
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
/**
* Load an object from its id and create a new one in database
*
* @ param User $user User making the clone
* @ param int $fromid Id of object to clone
* @ param bool $clone_contact Clone contact of project
* @ param bool $clone_task Clone task of project
* @ param bool $clone_project_file Clone file of project
* @ param bool $clone_task_file Clone file of task ( if task are copied )
* @ param bool $clone_note Clone note of project
* @ param bool $move_date Move task date on clone
* @ param integer $notrigger No trigger flag
* @ param int $newthirdpartyid New thirdparty id
* @ return int New id of clone
*/
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 )
2020-05-20 20:10:48 +02:00
{
2020-05-20 23:56:06 +02:00
global $langs , $conf ;
2016-11-09 22:54:51 +01:00
2020-05-20 23:56:06 +02:00
$error = 0 ;
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
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 );
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$now = dol_mktime ( 0 , 0 , 0 , idate ( 'm' , dol_now ()), idate ( 'd' , dol_now ()), idate ( 'Y' , dol_now ()));
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$clone_project = new Project ( $this -> db );
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$clone_project -> context [ 'createfromclone' ] = 'createfromclone' ;
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$this -> db -> begin ();
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
// Load source object
$clone_project -> fetch ( $fromid );
$clone_project -> fetch_optionals ();
2021-02-26 18:49:22 +01:00
if ( $newthirdpartyid > 0 ) {
$clone_project -> socid = $newthirdpartyid ;
}
2020-05-20 23:56:06 +02:00
$clone_project -> fetch_thirdparty ();
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$orign_dt_start = $clone_project -> date_start ;
$orign_project_ref = $clone_project -> ref ;
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$clone_project -> id = 0 ;
if ( $move_date ) {
$clone_project -> date_start = $now ;
2021-02-26 18:49:22 +01:00
if ( ! ( empty ( $clone_project -> date_end ))) {
2020-05-20 23:56:06 +02:00
$clone_project -> date_end = $clone_project -> date_end + ( $now - $orign_dt_start );
2020-05-19 22:06:17 +02:00
}
2020-05-20 23:56:06 +02:00
}
2020-05-19 22:06:17 +02:00
2021-09-10 11:44:58 +02:00
$clone_project -> date_c = $now ;
2020-05-19 22:06:17 +02:00
2021-02-26 18:49:22 +01:00
if ( ! $clone_note ) {
2020-05-20 23:56:06 +02:00
$clone_project -> note_private = '' ;
$clone_project -> note_public = '' ;
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
//Generate next ref
$defaultref = '' ;
$obj = empty ( $conf -> global -> PROJECT_ADDON ) ? 'mod_project_simple' : $conf -> global -> PROJECT_ADDON ;
// Search template files
$file = '' ; $classname = '' ; $filefound = 0 ;
$dirmodels = array_merge ( array ( '/' ), ( array ) $conf -> modules_parts [ 'models' ]);
2021-02-26 18:49:22 +01:00
foreach ( $dirmodels as $reldir ) {
2020-05-20 23:56:06 +02:00
$file = dol_buildpath ( $reldir . " core/modules/project/ " . $obj . '.php' , 0 );
2021-02-26 18:49:22 +01:00
if ( file_exists ( $file )) {
2020-05-20 23:56:06 +02:00
$filefound = 1 ;
dol_include_once ( $reldir . " core/modules/project/ " . $obj . '.php' );
$modProject = new $obj ;
$defaultref = $modProject -> getNextValue ( is_object ( $clone_project -> thirdparty ) ? $clone_project -> thirdparty : null , $clone_project );
break ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 20:10:48 +02:00
}
2021-02-26 18:49:22 +01:00
if ( is_numeric ( $defaultref ) && $defaultref <= 0 ) {
$defaultref = '' ;
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$clone_project -> ref = $defaultref ;
$clone_project -> title = $langs -> trans ( " CopyOf " ) . ' ' . $clone_project -> title ;
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
// Create clone
$result = $clone_project -> create ( $user , $notrigger );
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
// Other options
2021-02-26 18:49:22 +01:00
if ( $result < 0 ) {
2020-05-20 23:56:06 +02:00
$this -> error .= $clone_project -> error ;
$error ++ ;
2020-05-20 20:10:48 +02:00
}
2020-05-20 23:56:06 +02:00
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2020-05-20 23:56:06 +02:00
//Get the new project id
$clone_project_id = $clone_project -> id ;
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
//Note Update
2021-02-26 18:49:22 +01:00
if ( ! $clone_note ) {
2020-05-20 23:56:06 +02:00
$clone_project -> note_private = '' ;
$clone_project -> note_public = '' ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
$this -> db -> begin ();
2020-10-31 14:32:18 +01:00
$res = $clone_project -> update_note ( dol_html_entity_decode ( $clone_project -> note_public , ENT_QUOTES | ENT_HTML5 ), '_public' );
2021-02-26 18:49:22 +01:00
if ( $res < 0 ) {
2020-05-20 23:56:06 +02:00
$this -> error .= $clone_project -> error ;
$error ++ ;
$this -> db -> rollback ();
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
$this -> db -> commit ();
}
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
$this -> db -> begin ();
2020-10-31 14:32:18 +01:00
$res = $clone_project -> update_note ( dol_html_entity_decode ( $clone_project -> note_private , ENT_QUOTES | ENT_HTML5 ), '_private' );
2021-02-26 18:49:22 +01:00
if ( $res < 0 ) {
2020-05-20 23:56:06 +02:00
$this -> error .= $clone_project -> error ;
$error ++ ;
$this -> db -> rollback ();
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
$this -> db -> commit ();
2020-05-19 22:06:17 +02:00
}
2020-05-20 23:56:06 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
//Duplicate contact
2021-02-26 18:49:22 +01:00
if ( $clone_contact ) {
2020-05-20 23:56:06 +02:00
$origin_project = new Project ( $this -> db );
$origin_project -> fetch ( $fromid );
2020-05-19 22:06:17 +02:00
2021-02-26 18:49:22 +01:00
foreach ( array ( 'internal' , 'external' ) as $source ) {
2020-05-20 23:56:06 +02:00
$tab = $origin_project -> liste_contact ( - 1 , $source );
2021-10-21 19:00:48 +02:00
if ( is_array ( $tab ) && count ( $tab ) > 0 ) {
foreach ( $tab as $contacttoadd ) {
$clone_project -> add_contact ( $contacttoadd [ 'id' ], $contacttoadd [ 'code' ], $contacttoadd [ 'source' ], $notrigger );
if ( $clone_project -> error == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
$langs -> load ( " errors " );
$this -> error .= $langs -> trans ( " ErrorThisContactIsAlreadyDefinedAsThisType " );
2020-05-19 22:06:17 +02:00
$error ++ ;
2021-10-21 19:00:48 +02:00
} else {
if ( $clone_project -> error != '' ) {
$this -> error .= $clone_project -> error ;
$error ++ ;
}
2020-05-19 22:06:17 +02:00
}
}
2021-10-21 22:24:35 +02:00
} elseif ( $tab < 0 ) {
$this -> error .= $origin_project -> error ;
$error ++ ;
2020-05-19 22:06:17 +02:00
}
}
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
//Duplicate file
2021-02-26 18:49:22 +01:00
if ( $clone_project_file ) {
2020-05-20 23:56:06 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$clone_project_dir = $conf -> projet -> dir_output . " / " . dol_sanitizeFileName ( $defaultref );
$ori_project_dir = $conf -> projet -> dir_output . " / " . dol_sanitizeFileName ( $orign_project_ref );
2020-05-19 22:06:17 +02:00
2021-02-26 18:49:22 +01:00
if ( dol_mkdir ( $clone_project_dir ) >= 0 ) {
2020-05-20 23:56:06 +02:00
$filearray = dol_dir_list ( $ori_project_dir , " files " , 0 , '' , '(\.meta|_preview.*\.png)$' , '' , SORT_ASC , 1 );
2021-02-26 18:49:22 +01:00
foreach ( $filearray as $key => $file ) {
2020-05-20 23:56:06 +02:00
$rescopy = dol_copy ( $ori_project_dir . '/' . $file [ 'name' ], $clone_project_dir . '/' . $file [ 'name' ], 0 , 1 );
2021-02-26 18:49:22 +01:00
if ( is_numeric ( $rescopy ) && $rescopy < 0 ) {
2020-05-20 23:56:06 +02:00
$this -> error .= $langs -> trans ( " ErrorFailToCopyFile " , $ori_project_dir . '/' . $file [ 'name' ], $clone_project_dir . '/' . $file [ 'name' ]);
$error ++ ;
2020-05-19 22:06:17 +02:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
$this -> error .= $langs -> trans ( 'ErrorInternalErrorDetected' ) . ':dol_mkdir' ;
$error ++ ;
}
2020-05-19 22:06:17 +02:00
}
2020-05-20 23:56:06 +02:00
//Duplicate task
2021-02-26 18:49:22 +01:00
if ( $clone_task ) {
2020-09-07 10:18:17 +02:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php' ;
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$taskstatic = new Task ( $this -> db );
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
// Security check
2020-09-07 10:18:17 +02:00
$socid = 0 ;
2021-02-26 18:49:22 +01:00
if ( $user -> socid > 0 ) {
$socid = $user -> socid ;
}
2020-05-19 22:06:17 +02:00
2020-09-07 10:18:17 +02:00
$tasksarray = $taskstatic -> getTasksArray ( 0 , 0 , $fromid , $socid , 0 );
2020-05-19 22:06:17 +02:00
2020-09-07 10:18:17 +02:00
$tab_conv_child_parent = array ();
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
// Loop on each task, to clone it
2021-02-26 18:49:22 +01:00
foreach ( $tasksarray as $tasktoclone ) {
2020-05-20 23:56:06 +02:00
$result_clone = $taskstatic -> createFromClone ( $user , $tasktoclone -> id , $clone_project_id , $tasktoclone -> fk_parent , $move_date , true , false , $clone_task_file , true , false );
2021-02-26 18:49:22 +01:00
if ( $result_clone <= 0 ) {
2021-10-21 19:00:48 +02:00
$this -> error .= $taskstatic -> error ;
2020-05-20 23:56:06 +02:00
$error ++ ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
$new_task_id = $result_clone ;
$taskstatic -> fetch ( $tasktoclone -> id );
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
//manage new parent clone task id
// if the current task has child we store the original task id and the equivalent clone task id
2021-02-26 18:49:22 +01:00
if (( $taskstatic -> hasChildren ()) && ! array_key_exists ( $tasktoclone -> id , $tab_conv_child_parent )) {
2020-05-20 23:56:06 +02:00
$tab_conv_child_parent [ $tasktoclone -> id ] = $new_task_id ;
2020-05-19 22:06:17 +02:00
}
}
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
//Parse all clone node to be sure to update new parent
$tasksarray = $taskstatic -> getTasksArray ( 0 , 0 , $clone_project_id , $socid , 0 );
2021-02-26 18:49:22 +01:00
foreach ( $tasksarray as $task_cloned ) {
2020-05-20 23:56:06 +02:00
$taskstatic -> fetch ( $task_cloned -> id );
2021-02-26 18:49:22 +01:00
if ( $taskstatic -> fk_task_parent != 0 ) {
2020-05-20 23:56:06 +02:00
$taskstatic -> fk_task_parent = $tab_conv_child_parent [ $taskstatic -> fk_task_parent ];
}
$res = $taskstatic -> update ( $user , $notrigger );
2021-02-26 18:49:22 +01:00
if ( $result_clone <= 0 ) {
2020-05-20 23:56:06 +02:00
$this -> error .= $taskstatic -> error ;
$error ++ ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
}
}
2020-05-20 23:56:06 +02:00
unset ( $clone_project -> context [ 'createfromclone' ]);
2020-05-19 22:06:17 +02:00
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2020-05-20 23:56:06 +02:00
$this -> db -> commit ();
return $clone_project_id ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
$this -> db -> rollback ();
dol_syslog ( get_class ( $this ) . " ::createFromClone nbError: " . $error . " error : " . $this -> error , LOG_ERR );
return - 1 ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
/**
* Shift project task date from current date to delta
*
* @ param integer $old_project_dt_start Old project start date
* @ return int 1 if OK or < 0 if KO
*/
public function shiftTaskDate ( $old_project_dt_start )
{
global $user , $langs , $conf ;
2020-05-20 20:10:48 +02:00
2020-09-07 10:18:17 +02:00
$error = 0 ;
2021-10-21 19:00:48 +02:00
$result = 0 ;
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
$taskstatic = new Task ( $this -> db );
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
// Security check
2020-09-07 10:18:17 +02:00
$socid = 0 ;
2021-02-26 18:49:22 +01:00
if ( $user -> socid > 0 ) {
$socid = $user -> socid ;
}
2020-05-20 20:10:48 +02:00
2020-09-07 10:18:17 +02:00
$tasksarray = $taskstatic -> getTasksArray ( 0 , 0 , $this -> id , $socid , 0 );
2020-05-20 20:10:48 +02:00
2021-02-26 18:49:22 +01:00
foreach ( $tasksarray as $tasktoshiftdate ) {
2020-09-07 10:18:17 +02:00
$to_update = false ;
2020-05-20 23:56:06 +02:00
// Fetch only if update of date will be made
2021-02-26 18:49:22 +01:00
if (( ! empty ( $tasktoshiftdate -> date_start )) || ( ! empty ( $tasktoshiftdate -> date_end ))) {
2020-05-20 23:56:06 +02:00
//dol_syslog(get_class($this)."::shiftTaskDate to_update", LOG_DEBUG);
2020-09-07 10:18:17 +02:00
$to_update = true ;
2020-05-20 23:56:06 +02:00
$task = new Task ( $this -> db );
$result = $task -> fetch ( $tasktoshiftdate -> id );
2021-02-26 18:49:22 +01:00
if ( ! $result ) {
2020-05-20 23:56:06 +02:00
$error ++ ;
2020-09-07 10:18:17 +02:00
$this -> error .= $task -> error ;
2020-05-19 22:06:17 +02:00
}
}
2020-05-20 23:56:06 +02:00
//print "$this->date_start + $tasktoshiftdate->date_start - $old_project_dt_start";exit;
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
//Calcultate new task start date with difference between old proj start date and origin task start date
2021-02-26 18:49:22 +01:00
if ( ! empty ( $tasktoshiftdate -> date_start )) {
2020-05-20 23:56:06 +02:00
$task -> date_start = $this -> date_start + ( $tasktoshiftdate -> date_start - $old_project_dt_start );
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
//Calcultate new task end date with difference between origin proj end date and origin task end date
2021-02-26 18:49:22 +01:00
if ( ! empty ( $tasktoshiftdate -> date_end )) {
2020-05-20 23:56:06 +02:00
$task -> date_end = $this -> date_start + ( $tasktoshiftdate -> date_end - $old_project_dt_start );
}
2020-05-19 22:06:17 +02:00
2021-02-26 18:49:22 +01:00
if ( $to_update ) {
2020-05-20 23:56:06 +02:00
$result = $task -> update ( $user );
2021-02-26 18:49:22 +01:00
if ( ! $result ) {
2020-05-20 23:56:06 +02:00
$error ++ ;
$this -> error .= $task -> error ;
2020-05-19 22:06:17 +02:00
}
}
}
2021-02-26 18:49:22 +01:00
if ( $error != 0 ) {
2020-05-20 23:56:06 +02:00
return - 1 ;
}
return $result ;
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Associate element to a project
*
* @ param string $tableName Table of the element to update
* @ param int $elementSelectId Key - rowid of the line of the element to update
* @ return int 1 if OK or < 0 if KO
*/
public function update_element ( $tableName , $elementSelectId )
2020-05-20 20:10:48 +02:00
{
2020-05-20 23:56:06 +02:00
// phpcs:enable
$sql = " UPDATE " . MAIN_DB_PREFIX . $tableName ;
2020-05-19 22:06:17 +02:00
2021-02-26 18:49:22 +01:00
if ( $tableName == " actioncomm " ) {
2020-05-20 23:56:06 +02:00
$sql .= " SET fk_project= " . $this -> id ;
2021-06-09 15:36:47 +02:00
$sql .= " WHERE id= " . (( int ) $elementSelectId );
2021-04-15 09:59:08 +02:00
} elseif ( $tableName == " entrepot " ) {
$sql .= " SET fk_project= " . $this -> id ;
2021-06-09 15:36:47 +02:00
$sql .= " WHERE rowid= " . (( int ) $elementSelectId );
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
$sql .= " SET fk_projet= " . $this -> id ;
2021-06-09 15:36:47 +02:00
$sql .= " WHERE rowid= " . (( int ) $elementSelectId );
2020-05-20 23:56:06 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
dol_syslog ( get_class ( $this ) . " ::update_element " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( ! $resql ) {
$this -> error = $this -> db -> lasterror ();
return - 1 ;
} else {
return 1 ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 23:56:06 +02:00
}
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Associate element to a project
*
* @ param string $tableName Table of the element to update
* @ param int $elementSelectId Key - rowid of the line of the element to update
* @ param string $projectfield The column name that stores the link with the project
*
* @ return int 1 if OK or < 0 if KO
*/
public function remove_element ( $tableName , $elementSelectId , $projectfield = 'fk_projet' )
2020-05-20 20:10:48 +02:00
{
2020-05-20 23:56:06 +02:00
// phpcs:enable
$sql = " UPDATE " . MAIN_DB_PREFIX . $tableName ;
2020-05-20 20:10:48 +02:00
2021-02-26 18:49:22 +01:00
if ( $tableName == " actioncomm " ) {
2020-05-20 23:56:06 +02:00
$sql .= " SET fk_project=NULL " ;
2021-06-09 15:36:47 +02:00
$sql .= " WHERE id= " . (( int ) $elementSelectId );
2020-05-21 02:02:54 +02:00
} else {
2020-05-20 23:56:06 +02:00
$sql .= " SET " . $projectfield . " =NULL " ;
2021-06-09 15:36:47 +02:00
$sql .= " WHERE rowid= " . (( int ) $elementSelectId );
2020-05-20 23:56:06 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
dol_syslog ( get_class ( $this ) . " ::remove_element " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( ! $resql ) {
$this -> error = $this -> db -> lasterror ();
return - 1 ;
} else {
return 1 ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 20:10:48 +02:00
}
2020-05-20 23:56:06 +02:00
/**
* Create an intervention document on disk using template defined into PROJECT_ADDON_PDF
*
* @ param string $modele Force template to use ( '' by default )
* @ param Translate $outputlangs Objet lang to use for translation
* @ param int $hidedetails Hide details of lines
* @ param int $hidedesc Hide description
* @ param int $hideref Hide ref
* @ return int 0 if KO , 1 if OK
*/
public function generateDocument ( $modele , $outputlangs , $hidedetails = 0 , $hidedesc = 0 , $hideref = 0 )
{
2020-09-07 10:18:17 +02:00
global $conf , $langs ;
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
$langs -> load ( " projects " );
2020-05-20 20:10:48 +02:00
2020-09-07 10:18:17 +02:00
if ( ! dol_strlen ( $modele )) {
2020-05-20 23:56:06 +02:00
$modele = 'baleine' ;
2020-05-19 22:06:17 +02:00
2020-09-10 01:49:09 +02:00
if ( $this -> model_pdf ) {
$modele = $this -> model_pdf ;
2020-09-07 10:18:17 +02:00
} elseif ( ! empty ( $conf -> global -> PROJECT_ADDON_PDF )) {
2020-05-20 23:56:06 +02:00
$modele = $conf -> global -> PROJECT_ADDON_PDF ;
2020-05-19 22:06:17 +02:00
}
}
2020-05-20 23:56:06 +02:00
$modelpath = " core/modules/project/doc/ " ;
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
return $this -> commonGenerateDocument ( $modelpath , $modele , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
/**
* Load time spent into this -> weekWorkLoad and this -> weekWorkLoadPerTask for all day of a week of project .
* Note : array weekWorkLoad and weekWorkLoadPerTask are reset and filled at each call .
*
* @ param int $datestart First day of week ( use dol_get_first_day to find this date )
* @ param int $taskid Filter on a task id
* @ param int $userid Time spent by a particular user
* @ return int < 0 if OK , > 0 if KO
*/
public function loadTimeSpent ( $datestart , $taskid = 0 , $userid = 0 )
{
2020-09-07 10:18:17 +02:00
$error = 0 ;
2020-05-19 22:06:17 +02:00
2020-09-07 10:18:17 +02:00
$this -> weekWorkLoad = array ();
$this -> weekWorkLoadPerTask = array ();
2020-05-19 22:06:17 +02:00
2021-02-26 18:49:22 +01:00
if ( empty ( $datestart )) {
dol_print_error ( '' , 'Error datestart parameter is empty' );
}
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
$sql = " SELECT ptt.rowid as taskid, ptt.task_duration, ptt.task_date, ptt.task_datehour, ptt.fk_task " ;
2020-09-07 10:18:17 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet_task_time AS ptt, " . MAIN_DB_PREFIX . " projet_task as pt " ;
$sql .= " WHERE ptt.fk_task = pt.rowid " ;
2021-08-23 18:56:46 +02:00
$sql .= " AND pt.fk_projet = " . (( int ) $this -> id );
2020-09-07 10:18:17 +02:00
$sql .= " AND (ptt.task_date >= ' " . $this -> db -> idate ( $datestart ) . " ' " ;
$sql .= " AND ptt.task_date <= ' " . $this -> db -> idate ( dol_time_plus_duree ( $datestart , 1 , 'w' ) - 1 ) . " ') " ;
2021-02-26 18:49:22 +01:00
if ( $taskid ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND ptt.fk_task= " . (( int ) $taskid );
2021-02-26 18:49:22 +01:00
}
if ( is_numeric ( $userid )) {
2021-06-09 15:36:47 +02:00
$sql .= " AND ptt.fk_user= " . (( int ) $userid );
2021-02-26 18:49:22 +01:00
}
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
//print $sql;
2020-09-07 10:18:17 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $resql ) {
2020-09-07 10:18:17 +02:00
$daylareadyfound = array ();
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
// Loop on each record found, so each couple (project id, task id)
2021-02-26 18:49:22 +01:00
while ( $i < $num ) {
2020-09-07 10:18:17 +02:00
$obj = $this -> db -> fetch_object ( $resql );
$day = $this -> db -> jdate ( $obj -> task_date ); // task_date is date without hours
2021-02-26 18:49:22 +01:00
if ( empty ( $daylareadyfound [ $day ])) {
2020-05-20 23:56:06 +02:00
$this -> weekWorkLoad [ $day ] = $obj -> task_duration ;
$this -> weekWorkLoadPerTask [ $day ][ $obj -> fk_task ] = $obj -> task_duration ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
$this -> weekWorkLoad [ $day ] += $obj -> task_duration ;
$this -> weekWorkLoadPerTask [ $day ][ $obj -> fk_task ] += $obj -> task_duration ;
}
2020-09-07 10:18:17 +02:00
$daylareadyfound [ $day ] = 1 ;
2020-05-20 23:56:06 +02:00
$i ++ ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 23:56:06 +02:00
$this -> db -> free ( $resql );
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
$this -> error = " Error " . $this -> db -> lasterror ();
dol_syslog ( get_class ( $this ) . " ::fetch " . $this -> error , LOG_ERR );
return - 1 ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:58:32 +02:00
/**
* Load time spent into this -> weekWorkLoad and this -> weekWorkLoadPerTask for all day of a week of project .
* Note : array weekWorkLoad and weekWorkLoadPerTask are reset and filled at each call .
*
* @ param int $datestart First day of week ( use dol_get_first_day to find this date )
* @ param int $taskid Filter on a task id
* @ param int $userid Time spent by a particular user
* @ return int < 0 if OK , > 0 if KO
*/
public function loadTimeSpentMonth ( $datestart , $taskid = 0 , $userid = 0 )
{
$error = 0 ;
2020-05-19 22:06:17 +02:00
2020-05-20 23:58:32 +02:00
$this -> monthWorkLoad = array ();
$this -> monthWorkLoadPerTask = array ();
2020-05-19 22:06:17 +02:00
2021-02-26 18:49:22 +01:00
if ( empty ( $datestart )) {
dol_print_error ( '' , 'Error datestart parameter is empty' );
}
2020-05-20 23:27:45 +02:00
2020-05-20 23:58:32 +02:00
$sql = " SELECT ptt.rowid as taskid, ptt.task_duration, ptt.task_date, ptt.task_datehour, ptt.fk_task " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " projet_task_time AS ptt, " . MAIN_DB_PREFIX . " projet_task as pt " ;
$sql .= " WHERE ptt.fk_task = pt.rowid " ;
2021-08-23 18:56:46 +02:00
$sql .= " AND pt.fk_projet = " . (( int ) $this -> id );
2020-05-20 23:58:32 +02:00
$sql .= " AND (ptt.task_date >= ' " . $this -> db -> idate ( $datestart ) . " ' " ;
$sql .= " AND ptt.task_date <= ' " . $this -> db -> idate ( dol_time_plus_duree ( $datestart , 1 , 'm' ) - 1 ) . " ') " ;
2021-02-26 18:49:22 +01:00
if ( $task_id ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND ptt.fk_task= " . (( int ) $taskid );
2021-02-26 18:49:22 +01:00
}
if ( is_numeric ( $userid )) {
2021-06-09 15:36:47 +02:00
$sql .= " AND ptt.fk_user= " . (( int ) $userid );
2021-02-26 18:49:22 +01:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:58:32 +02:00
//print $sql;
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $resql ) {
2020-05-20 23:58:32 +02:00
$weekalreadyfound = array ();
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
// Loop on each record found, so each couple (project id, task id)
2021-02-26 18:49:22 +01:00
while ( $i < $num ) {
2020-05-20 23:58:32 +02:00
$obj = $this -> db -> fetch_object ( $resql );
if ( ! empty ( $obj -> task_date )) {
$date = explode ( '-' , $obj -> task_date );
$week_number = getWeekNumber ( $date [ 2 ], $date [ 1 ], $date [ 0 ]);
}
2021-02-26 18:49:22 +01:00
if ( empty ( $weekalreadyfound [ $week_number ])) {
2020-05-20 23:58:32 +02:00
$this -> monthWorkLoad [ $week_number ] = $obj -> task_duration ;
$this -> monthWorkLoadPerTask [ $week_number ][ $obj -> fk_task ] = $obj -> task_duration ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:58:32 +02:00
$this -> monthWorkLoad [ $week_number ] += $obj -> task_duration ;
$this -> monthWorkLoadPerTask [ $week_number ][ $obj -> fk_task ] += $obj -> task_duration ;
}
$weekalreadyfound [ $week_number ] = 1 ;
$i ++ ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 23:58:32 +02:00
$this -> db -> free ( $resql );
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:58:32 +02:00
$this -> error = " Error " . $this -> db -> lasterror ();
dol_syslog ( get_class ( $this ) . " ::fetch " . $this -> error , LOG_ERR );
return - 1 ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Load indicators for dashboard ( this -> nbtodo and this -> nbtodolate )
*
* @ param User $user Objet user
* @ return WorkboardResponse | int < 0 if KO , WorkboardResponse if OK
*/
public function load_board ( $user )
2020-05-20 20:10:48 +02:00
{
2020-05-20 23:56:06 +02:00
// phpcs:enable
global $conf , $langs ;
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
// For external user, no check is done on company because readability is managed by public status of project and assignement.
//$socid=$user->socid;
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
$projectsListId = null ;
2021-10-24 10:02:12 +02:00
if ( empty ( $user -> rights -> projet -> all -> lire )) {
2021-02-26 18:49:22 +01:00
$projectsListId = $this -> getProjectsAuthorizedForUser ( $user , 0 , 1 );
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$sql = " SELECT p.rowid, p.fk_statut as status, p.fk_opp_status, p.datee as datee " ;
$sql .= " FROM ( " . MAIN_DB_PREFIX . " projet as p " ;
$sql .= " ) " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s on p.fk_soc = s.rowid " ;
// For external user, no check is done on company permission because readability is managed by public status of project and assignement.
//if (! $user->rights->societe->client->voir && ! $socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
$sql .= " WHERE p.fk_statut = 1 " ;
$sql .= " AND p.entity IN ( " . getEntity ( 'project' ) . ')' ;
2021-02-26 18:49:22 +01:00
if ( ! empty ( $projectsListId )) {
2021-03-22 11:30:18 +01:00
$sql .= " AND p.rowid IN ( " . $this -> db -> sanitize ( $projectsListId ) . " ) " ;
2021-02-26 18:49:22 +01:00
}
2020-05-20 23:56:06 +02:00
// No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
2021-08-23 17:41:11 +02:00
//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).")";
2020-05-20 23:56:06 +02:00
// For external user, no check is done on company permission because readability is managed by public status of project and assignement.
2021-08-23 18:56:46 +02:00
//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))";
2020-05-20 23:56:06 +02:00
//print $sql;
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $resql ) {
2020-05-20 23:56:06 +02:00
$project_static = new Project ( $this -> db );
$response = new WorkboardResponse ();
$response -> warning_delay = $conf -> projet -> warning_delay / 60 / 60 / 24 ;
$response -> label = $langs -> trans ( " OpenedProjects " );
$response -> labelShort = $langs -> trans ( " Opened " );
2021-02-26 18:49:22 +01:00
if ( $user -> rights -> projet -> all -> lire ) {
$response -> url = DOL_URL_ROOT . '/projet/list.php?search_status=1&mainmenu=project' ;
} else {
$response -> url = DOL_URL_ROOT . '/projet/list.php?search_project_user=-1&search_status=1&mainmenu=project' ;
}
2020-05-20 23:56:06 +02:00
$response -> img = img_object ( '' , " projectpub " );
// This assignment in condition is not a bug. It allows walking the results.
2021-02-26 18:49:22 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2020-05-20 23:56:06 +02:00
$response -> nbtodo ++ ;
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$project_static -> statut = $obj -> status ;
2021-07-05 13:44:05 +02:00
$project_static -> opp_status = $obj -> fk_opp_status ;
2020-05-20 23:56:06 +02:00
$project_static -> datee = $this -> db -> jdate ( $obj -> datee );
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
if ( $project_static -> hasDelay ()) {
$response -> nbtodolate ++ ;
}
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
return $response ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
$this -> error = $this -> db -> error ();
return - 1 ;
}
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
/**
* Function used to replace a thirdparty id with another one .
*
* @ param DoliDB $db Database handler
* @ param int $origin_id Old thirdparty id
* @ param int $dest_id New thirdparty id
* @ return bool
*/
public static function replaceThirdparty ( DoliDB $db , $origin_id , $dest_id )
{
$tables = array (
'projet'
);
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
return CommonObject :: commonReplaceThirdparty ( $db , $origin_id , $dest_id , $tables );
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Charge indicateurs this -> nb pour le tableau de bord
*
* @ return int < 0 if KO , > 0 if OK
*/
public function load_state_board ()
{
// phpcs:enable
global $user ;
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$this -> nb = array ();
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$sql = " SELECT count(p.rowid) as nb " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " projet as p " ;
$sql .= " WHERE " ;
$sql .= " p.entity IN ( " . getEntity ( 'project' ) . " ) " ;
2021-10-24 10:02:12 +02:00
if ( empty ( $user -> rights -> projet -> all -> lire )) {
2020-05-20 23:56:06 +02:00
$projectsListId = $this -> getProjectsAuthorizedForUser ( $user , 0 , 1 );
2021-03-22 12:47:23 +01:00
$sql .= " AND p.rowid IN ( " . $this -> db -> sanitize ( $projectsListId ) . " ) " ;
2020-05-20 23:56:06 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $resql ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2020-05-20 23:56:06 +02:00
$this -> nb [ " projects " ] = $obj -> nb ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 23:56:06 +02:00
$this -> db -> free ( $resql );
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
dol_print_error ( $this -> db );
$this -> error = $this -> db -> error ();
return - 1 ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
/**
* Is the project delayed ?
*
* @ return bool
*/
public function hasDelay ()
{
global $conf ;
2020-05-19 22:06:17 +02:00
2021-02-26 18:49:22 +01:00
if ( ! ( $this -> statut == self :: STATUS_VALIDATED )) {
return false ;
}
if ( ! $this -> datee && ! $this -> date_end ) {
return false ;
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
$now = dol_now ();
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
return ( $this -> datee ? $this -> datee : $this -> date_end ) < ( $now - $conf -> projet -> warning_delay );
}
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
/**
* Charge les informations d 'ordre info dans l' objet commande
*
* @ param int $id Id of order
* @ return void
*/
public function info ( $id )
2020-05-20 20:10:48 +02:00
{
2020-05-20 23:56:06 +02:00
$sql = 'SELECT c.rowid, datec as datec, tms as datem,' ;
$sql .= ' date_close as datecloture,' ;
$sql .= ' fk_user_creat as fk_user_author, fk_user_close as fk_use_cloture' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'projet as c' ;
2021-03-14 11:48:39 +01:00
$sql .= ' WHERE c.rowid = ' . (( int ) $id );
2020-05-20 23:56:06 +02:00
$result = $this -> db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( $result ) {
if ( $this -> db -> num_rows ( $result )) {
2020-05-20 23:56:06 +02:00
$obj = $this -> db -> fetch_object ( $result );
$this -> id = $obj -> rowid ;
2021-02-26 18:49:22 +01:00
if ( $obj -> fk_user_author ) {
2020-05-20 23:56:06 +02:00
$cuser = new User ( $this -> db );
$cuser -> fetch ( $obj -> fk_user_author );
$this -> user_creation = $cuser ;
}
2020-05-20 20:10:48 +02:00
2021-02-26 18:49:22 +01:00
if ( $obj -> fk_user_cloture ) {
2020-05-20 23:56:06 +02:00
$cluser = new User ( $this -> db );
$cluser -> fetch ( $obj -> fk_user_cloture );
$this -> user_cloture = $cluser ;
2020-05-19 22:06:17 +02:00
}
2020-05-20 23:56:06 +02:00
$this -> date_creation = $this -> db -> jdate ( $obj -> datec );
$this -> date_modification = $this -> db -> jdate ( $obj -> datem );
$this -> date_cloture = $this -> db -> jdate ( $obj -> datecloture );
2020-05-19 22:06:17 +02:00
}
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
$this -> db -> free ( $result );
2020-05-21 15:05:19 +02:00
} else {
2020-05-20 23:56:06 +02:00
dol_print_error ( $this -> db );
2020-05-19 22:06:17 +02:00
}
2020-05-20 20:10:48 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
/**
* Sets object to supplied categories .
*
* Deletes object from existing categories not supplied .
* Adds it to non existing supplied categories .
* Existing categories are left untouch .
*
* @ param int [] | int $categories Category or categories IDs
* @ return void
*/
public function setCategories ( $categories )
2020-05-20 20:10:48 +02:00
{
2020-05-20 23:56:06 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2020-12-24 00:53:10 +01:00
return parent :: setCategoriesCommon ( $categories , Categorie :: TYPE_PROJECT );
2020-05-20 23:56:06 +02:00
}
2020-05-19 22:06:17 +02:00
2020-05-20 23:56:06 +02:00
/**
* Create an array of tasks of current project
*
* @ param User $user Object user we want project allowed to
* @ return int > 0 if OK , < 0 if KO
*/
public function getLinesArray ( $user )
{
require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php' ;
$taskstatic = new Task ( $this -> db );
2020-05-20 20:10:48 +02:00
2020-05-20 23:56:06 +02:00
$this -> lines = $taskstatic -> getTasksArray ( 0 , $user , $this -> id , 0 , 0 );
}
2002-05-11 20:53:13 +02:00
}