2004-10-20 23:06:45 +02:00
< ? php
2004-02-13 15:05:00 +01:00
/* Copyright ( C ) 2002 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2011-09-22 01:41:42 +02:00
* Copyright ( C ) 2004 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2017-10-20 12:57:32 +02:00
* Copyright ( C ) 2011 - 2017 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
2011-12-07 00:16:19 +01:00
*
2011-11-03 11:49:22 +01: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
2011-11-03 11:49:22 +01:00
* ( at your option ) any later version .
2011-12-07 00:16:19 +01:00
*
2011-11-03 11:49:22 +01:00
* 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 .
2011-12-07 00:16:19 +01:00
*
2011-11-03 11:49:22 +01:00
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
2002-05-11 20:53:13 +02:00
2004-12-28 16:36:40 +01:00
/**
2010-06-05 17:32:18 +02:00
* \file htdocs / comm / action / class / actioncomm . class . php
2012-10-03 00:39:34 +02:00
* \ingroup agenda
2010-10-28 00:41:40 +02:00
* \brief File of class to manage agenda events ( actions )
2008-11-11 20:32:48 +01:00
*/
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/comm/action/class/cactioncomm.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
2007-05-11 02:13:43 +02:00
2004-09-30 21:28:40 +02:00
2012-10-03 00:39:34 +02:00
/**
* Class to manage agenda events ( actions )
2008-11-11 20:32:48 +01:00
*/
2010-06-09 20:25:20 +02:00
class ActionComm extends CommonObject
2003-05-15 21:30:01 +02:00
{
2011-11-01 13:22:39 +01:00
public $element = 'action' ;
public $table_element = 'actioncomm' ;
public $table_rowid = 'id' ;
2016-09-19 10:43:30 +02:00
public $picto = 'action' ;
2017-12-18 15:39:40 +01:00
/**
* 0 = No test on entity , 1 = Test with field entity , 2 = Test with link by societe
* @ var int
*/
public $ismultientitymanaged = 1 ;
/**
* 0 = Default , 1 = View may be restricted to sales representative only if no permission to see all or to company of external user if external user , 2 = Same than 1 but accept record if fksoc is empty
* @ var integer
*/
public $restrictiononfksoc = 2 ;
2017-07-04 10:29:38 +02:00
2015-02-10 11:38:13 +01:00
/**
* Id of the event
* @ var int
*/
2011-11-01 13:22:39 +01:00
var $id ;
2013-03-09 20:34:38 +01:00
2015-02-10 11:38:13 +01:00
/**
* Id of the event . Use $id as possible
* @ var int
*/
public $ref ;
2014-09-29 13:21:03 +02:00
var $type_id ; // Id into parent table llx_c_actioncomm (used only if option to use type is set)
var $type_code ; // Code into parent table llx_c_actioncomm (used only if option to use type is set). With default setup, should be AC_OTH_AUTO or AC_OTH.
var $type ; // Label into parent table llx_c_actioncomm (used only if option to use type is set)
var $type_color ; // Color into parent table llx_c_actioncomm (used only if option to use type is set)
2013-07-10 14:46:16 +02:00
var $code ; // Free code to identify action. Ie: Agenda trigger add here AC_TRIGGERNAME ('AC_COMPANY_CREATE', 'AC_PROPAL_VALIDATE', ...)
2015-02-10 11:38:13 +01:00
2005-09-09 23:24:13 +02:00
var $label ;
2008-02-11 16:51:03 +01:00
2015-02-10 11:38:13 +01:00
/**
* @ var string
* @ deprecated Use $label
2015-04-23 23:21:06 +02:00
* @ see label
2015-02-10 11:38:13 +01:00
*/
public $libelle ;
2008-07-26 13:40:24 +02:00
var $datec ; // Date creation record (datec)
var $datem ; // Date modification record (tms)
2015-02-10 11:38:13 +01:00
/**
* Object user that create action
* @ var User
* @ deprecated
2015-04-23 23:21:06 +02:00
* @ see authorid
2015-02-10 11:38:13 +01:00
*/
var $author ;
/**
* Object user that modified action
* @ var User
* @ deprecated
2015-04-23 23:21:06 +02:00
* @ see usermodid
2015-02-10 11:38:13 +01:00
*/
var $usermod ;
2014-09-26 12:27:18 +02:00
var $authorid ; // Id user that create action
var $usermodid ; // Id user that modified action
2008-02-11 16:51:03 +01:00
2008-07-26 13:40:24 +02:00
var $datep ; // Date action start (datep)
var $datef ; // Date action end (datep2)
2015-02-10 11:38:13 +01:00
/**
* @ var int - 1 = Unkown duration
* @ deprecated
*/
var $durationp = - 1 ;
2011-11-01 13:22:39 +01:00
var $fulldayevent = 0 ; // 1=Event on full day
2015-02-10 11:38:13 +01:00
/**
* Milestone
* @ var int
* @ deprecated Milestone is already event with end date = start date
*/
var $punctual = 1 ;
2011-11-01 13:22:39 +01:00
var $percentage ; // Percentage
var $location ; // Location
2014-09-20 00:57:29 +02:00
2013-04-06 17:39:31 +02:00
var $transparency ; // Transparency (ical standard). Used to say if people assigned to event are busy or not by event. 0=available, 1=busy, 2=busy (refused events)
2014-02-06 17:09:41 +01:00
var $priority ; // Small int (0 By default)
2009-05-04 22:39:17 +02:00
2014-09-23 16:15:15 +02:00
var $userassigned = array (); // Array of user ids
2015-07-21 11:04:01 +02:00
var $userownerid ; // Id of user owner = fk_user_action into table
var $userdoneid ; // Id of user done (deprecated)
2015-02-10 11:38:13 +01:00
2017-11-22 14:42:47 +01:00
var $socpeopleassigned = array (); // Array of contact ids
var $otherassigned = array (); // Array of other contact emails (not user, not contact)
/**
2015-02-10 11:38:13 +01:00
* Object user of owner
* @ var User
* @ deprecated
2015-04-23 23:21:06 +02:00
* @ see userownerid
2015-02-10 11:38:13 +01:00
*/
var $usertodo ;
/**
* Object user that did action
* @ var User
* @ deprecated
2015-04-23 23:21:06 +02:00
* @ see userdoneid
2015-02-10 11:38:13 +01:00
*/
var $userdone ;
2009-05-04 22:39:17 +02:00
2014-09-23 17:54:03 +02:00
var $socid ;
var $contactid ;
2015-02-10 11:38:13 +01:00
/**
* Company linked to action ( optional )
* @ var Societe | null
2015-04-23 23:21:06 +02:00
* @ deprecated
* @ see socid
2015-02-10 11:38:13 +01:00
*/
var $societe ;
/**
* Contact linked to action ( optional )
* @ var Contact | null
2015-04-23 23:21:06 +02:00
* @ deprecated
* @ see contactid
2015-02-10 11:38:13 +01:00
*/
var $contact ;
2011-06-06 13:37:59 +02:00
// Properties for links to other objects
var $fk_element ; // Id of record
2018-03-13 10:28:44 +01:00
var $elementid ; // Id of record alternative for API
2011-06-06 13:37:59 +02:00
var $elementtype ; // Type of record. This if property ->element of object linked to.
// Ical
2011-06-02 18:52:37 +02:00
var $icalname ;
var $icalcolor ;
2011-06-30 09:49:26 +02:00
2011-06-19 17:10:32 +02:00
var $actions = array ();
2010-09-12 22:27:40 +02:00
2016-01-08 13:05:56 +01:00
// Fields for emails
var $email_msgid ;
var $email_from ;
var $email_sender ;
var $email_to ;
var $email_tocc ;
var $email_tobcc ;
var $email_subject ;
var $errors_to ;
2017-07-04 10:29:38 +02:00
2005-09-09 23:24:13 +02:00
/**
2011-06-06 13:37:59 +02:00
* Constructor
2011-11-01 04:58:47 +01:00
*
* @ param DoliDB $db Database handler
2005-09-09 23:24:13 +02:00
*/
2016-04-16 21:41:06 +02:00
public function __construct ( DoliDB $db )
2003-05-15 21:30:01 +02:00
{
2005-09-09 23:24:13 +02:00
$this -> db = $db ;
2012-07-08 23:22:22 +02:00
2014-10-03 15:58:08 +02:00
$this -> societe = new stdClass (); // deprecated
$this -> contact = new stdClass (); // deprecated
2003-08-03 14:49:38 +02:00
}
2004-10-30 00:31:33 +02:00
2005-09-09 23:24:13 +02:00
/**
2014-10-05 04:51:34 +02:00
* Add an action / event into database .
* $this -> type_id OR $this -> type_code must be set .
2011-10-25 02:08:42 +02:00
*
2011-09-22 01:28:01 +02:00
* @ param User $user Object user making action
2011-11-01 13:22:39 +01:00
* @ param int $notrigger 1 = disable triggers , 0 = enable triggers
2011-09-22 01:28:01 +02:00
* @ return int Id of created event , < 0 if KO
2005-09-09 23:24:13 +02:00
*/
2016-04-16 21:41:06 +02:00
public function create ( User $user , $notrigger = 0 )
2003-05-15 21:31:07 +02:00
{
2013-01-25 19:12:54 +01:00
global $langs , $conf , $hookmanager ;
2013-03-09 20:34:38 +01:00
2011-11-01 13:22:39 +01:00
$error = 0 ;
$now = dol_now ();
2010-01-19 11:47:26 +01:00
2015-01-18 12:29:55 +01:00
// Check parameters
2018-03-04 19:39:46 +01:00
if ( ! isset ( $this -> userownerid ) || $this -> userownerid === '' ) // $this->userownerid may be 0 (anonymous event) of > 0
2015-01-18 12:29:55 +01:00
{
2015-11-12 14:36:35 +01:00
dol_syslog ( " You tried to create an event but mandatory property ownerid was not defined " , LOG_WARNING );
2015-01-18 12:29:55 +01:00
$this -> errors [] = 'ErrorPropertyUserowneridNotDefined' ;
return - 1 ;
}
2015-02-25 15:01:25 +01:00
2011-11-01 13:22:39 +01:00
// Clean parameters
$this -> label = dol_trunc ( trim ( $this -> label ), 128 );
$this -> location = dol_trunc ( trim ( $this -> location ), 128 );
$this -> note = dol_htmlcleanlastbr ( trim ( $this -> note ));
2010-11-18 23:17:44 +01:00
if ( empty ( $this -> percentage )) $this -> percentage = 0 ;
2014-02-06 17:09:41 +01:00
if ( empty ( $this -> priority ) || ! is_numeric ( $this -> priority )) $this -> priority = 0 ;
2012-12-13 17:33:53 +01:00
if ( empty ( $this -> fulldayevent )) $this -> fulldayevent = 0 ;
2010-11-18 23:17:44 +01:00
if ( empty ( $this -> punctual )) $this -> punctual = 0 ;
2013-04-06 17:39:31 +02:00
if ( empty ( $this -> transparency )) $this -> transparency = 0 ;
2008-03-02 19:47:42 +01:00
if ( $this -> percentage > 100 ) $this -> percentage = 100 ;
2013-06-24 16:41:31 +02:00
//if ($this->percentage == 100 && ! $this->dateend) $this->dateend = $this->date;
2014-09-18 01:43:50 +02:00
if ( ! empty ( $this -> datep ) && ! empty ( $this -> datef )) $this -> durationp = ( $this -> datef - $this -> datep ); // deprecated
2013-06-24 16:41:31 +02:00
//if (! empty($this->date) && ! empty($this->dateend)) $this->durationa=($this->dateend - $this->date);
2012-09-02 22:12:56 +02:00
if ( ! empty ( $this -> datep ) && ! empty ( $this -> datef ) && $this -> datep > $this -> datef ) $this -> datef = $this -> datep ;
2013-06-24 16:41:31 +02:00
//if (! empty($this->date) && ! empty($this->dateend) && $this->date > $this->dateend) $this->dateend=$this->date;
2012-09-02 22:12:56 +02:00
if ( ! isset ( $this -> fk_project ) || $this -> fk_project < 0 ) $this -> fk_project = 0 ;
2011-06-06 13:37:59 +02:00
if ( $this -> elementtype == 'facture' ) $this -> elementtype = 'invoice' ;
if ( $this -> elementtype == 'commande' ) $this -> elementtype = 'order' ;
if ( $this -> elementtype == 'contrat' ) $this -> elementtype = 'contract' ;
2008-03-02 19:47:42 +01:00
2017-11-13 02:44:02 +01:00
if ( ! is_array ( $this -> userassigned ) && ! empty ( $this -> userassigned )) // For backward compatibility when userassigned was an int instead fo array
2015-01-18 11:48:52 +01:00
{
$tmpid = $this -> userassigned ;
$this -> userassigned = array ();
2017-11-13 02:44:02 +01:00
$this -> userassigned [ $tmpid ] = array ( 'id' => $tmpid , 'transparency' => $this -> transparency );
2015-01-18 11:48:52 +01:00
}
2015-10-07 17:17:32 +02:00
if ( is_object ( $this -> contact ) && isset ( $this -> contact -> id ) && $this -> contact -> id > 0 && ! ( $this -> contactid > 0 )) $this -> contactid = $this -> contact -> id ; // For backward compatibility. Using this->contact->xx is deprecated
2015-04-24 21:29:02 +02:00
2015-04-26 16:30:33 +02:00
2014-10-11 15:04:42 +02:00
$userownerid = $this -> userownerid ;
$userdoneid = $this -> userdoneid ;
2014-09-26 12:27:18 +02:00
2015-01-18 12:29:55 +01:00
// Be sure assigned user is defined as an array of array('id'=>,'mandatory'=>,...).
2015-02-25 15:01:25 +01:00
if ( empty ( $this -> userassigned ) || count ( $this -> userassigned ) == 0 || ! is_array ( $this -> userassigned ))
2017-11-13 02:44:02 +01:00
$this -> userassigned = array ( $userownerid => array ( 'id' => $userownerid , 'transparency' => $this -> transparency ));
2015-01-15 02:06:04 +01:00
2014-10-05 04:51:34 +02:00
if ( ! $this -> type_id || ! $this -> type_code )
2011-11-01 13:22:39 +01:00
{
2014-10-05 04:51:34 +02:00
$key = empty ( $this -> type_id ) ? $this -> type_code : $this -> type_id ;
2011-11-01 13:22:39 +01:00
// Get id from code
$cactioncomm = new CActionComm ( $this -> db );
2014-10-05 04:51:34 +02:00
$result = $cactioncomm -> fetch ( $key );
2011-11-01 13:22:39 +01:00
if ( $result > 0 )
{
$this -> type_id = $cactioncomm -> id ;
2014-10-05 04:51:34 +02:00
$this -> type_code = $cactioncomm -> code ;
2011-11-01 13:22:39 +01:00
}
else if ( $result == 0 )
{
2014-10-05 04:51:34 +02:00
$this -> error = 'Failed to get record with id ' . $this -> type_id . ' code ' . $this -> type_code . ' from dictionary "type of events"' ;
2011-11-01 13:22:39 +01:00
return - 1 ;
}
else
2014-10-05 04:51:34 +02:00
{
2011-11-01 13:22:39 +01:00
$this -> error = $cactioncomm -> error ;
return - 1 ;
}
}
2018-05-16 20:52:45 +02:00
$code = empty ( $this -> code ) ? $this -> type_code : $this -> code ;
2011-11-01 13:22:39 +01:00
// Check parameters
if ( ! $this -> type_id )
{
$this -> error = " ErrorWrongParameters " ;
return - 1 ;
}
$this -> db -> begin ();
2008-02-29 17:26:38 +01:00
2005-06-25 15:02:39 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " actioncomm " ;
2006-02-25 01:38:31 +01:00
$sql .= " (datec, " ;
2008-02-29 17:26:38 +01:00
$sql .= " datep, " ;
$sql .= " datep2, " ;
2014-09-18 01:43:50 +02:00
$sql .= " durationp, " ; // deprecated
2008-11-11 20:32:48 +01:00
$sql .= " fk_action, " ;
2013-03-08 12:04:01 +01:00
$sql .= " code, " ;
2008-11-11 20:32:48 +01:00
$sql .= " fk_soc, " ;
2010-01-05 00:33:23 +01:00
$sql .= " fk_project, " ;
2008-11-11 20:32:48 +01:00
$sql .= " note, " ;
2011-11-01 13:22:39 +01:00
$sql .= " fk_contact, " ;
$sql .= " fk_user_author, " ;
$sql .= " fk_user_action, " ;
$sql .= " fk_user_done, " ;
$sql .= " label,percent,priority,fulldayevent,location,punctual, " ;
2013-04-06 17:39:31 +02:00
$sql .= " transparency, " ;
2011-06-04 15:12:44 +02:00
$sql .= " fk_element, " ;
$sql .= " elementtype, " ;
2018-06-07 12:53:06 +02:00
$sql .= " entity, " ;
$sql .= " extraparams " ;
2011-04-06 15:11:03 +02:00
$sql .= " ) VALUES ( " ;
2017-09-15 15:41:07 +02:00
$sql .= " ' " . $this -> db -> idate ( $now ) . " ', " ;
$sql .= ( strval ( $this -> datep ) != '' ? " ' " . $this -> db -> idate ( $this -> datep ) . " ' " : " null " ) . " , " ;
$sql .= ( strval ( $this -> datef ) != '' ? " ' " . $this -> db -> idate ( $this -> datef ) . " ' " : " null " ) . " , " ;
$sql .= (( isset ( $this -> durationp ) && $this -> durationp >= 0 && $this -> durationp != '' ) ? " ' " . $this -> db -> escape ( $this -> durationp ) . " ' " : " null " ) . " , " ; // deprecated
2013-05-19 18:47:14 +02:00
$sql .= ( isset ( $this -> type_id ) ? $this -> type_id : " null " ) . " , " ;
2018-05-16 20:52:45 +02:00
$sql .= ( $code ? ( " ' " . $code . " ' " ) : " null " ) . " , " ;
2017-09-15 15:41:07 +02:00
$sql .= (( isset ( $this -> socid ) && $this -> socid > 0 ) ? $this -> socid : " null " ) . " , " ;
$sql .= (( isset ( $this -> fk_project ) && $this -> fk_project > 0 ) ? $this -> fk_project : " null " ) . " , " ;
$sql .= " ' " . $this -> db -> escape ( $this -> note ) . " ', " ;
$sql .= (( isset ( $this -> contactid ) && $this -> contactid > 0 ) ? $this -> contactid : " null " ) . " , " ;
$sql .= ( isset ( $user -> id ) && $user -> id > 0 ? $user -> id : " null " ) . " , " ;
$sql .= ( $userownerid > 0 ? $userownerid : " null " ) . " , " ;
$sql .= ( $userdoneid > 0 ? $userdoneid : " null " ) . " , " ;
$sql .= " ' " . $this -> db -> escape ( $this -> label ) . " ',' " . $this -> db -> escape ( $this -> percentage ) . " ',' " . $this -> db -> escape ( $this -> priority ) . " ',' " . $this -> db -> escape ( $this -> fulldayevent ) . " ',' " . $this -> db -> escape ( $this -> location ) . " ',' " . $this -> db -> escape ( $this -> punctual ) . " ', " ;
$sql .= " ' " . $this -> db -> escape ( $this -> transparency ) . " ', " ;
$sql .= ( ! empty ( $this -> fk_element ) ? $this -> fk_element : " null " ) . " , " ;
$sql .= ( ! empty ( $this -> elementtype ) ? " ' " . $this -> db -> escape ( $this -> elementtype ) . " ' " : " null " ) . " , " ;
2018-06-07 12:53:06 +02:00
$sql .= $conf -> entity . " , " ;
$sql .= ( ! empty ( $this -> extraparams ) ? " ' " . $this -> db -> escape ( $this -> extraparams ) . " ' " : " null " );
2007-04-01 04:59:44 +02:00
$sql .= " ) " ;
2009-05-04 22:39:17 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::add " , LOG_DEBUG );
2007-04-01 04:59:44 +02:00
$resql = $this -> db -> query ( $sql );
2011-11-01 13:22:39 +01:00
if ( $resql )
2005-06-25 15:02:39 +02:00
{
2009-10-28 18:37:40 +01:00
$this -> id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " actioncomm " , " id " );
2009-05-04 22:39:17 +02:00
2014-09-23 12:18:42 +02:00
// Now insert assignedusers
if ( ! $error )
{
foreach ( $this -> userassigned as $key => $val )
{
2015-01-18 12:29:55 +01:00
if ( ! is_array ( $val )) // For backward compatibility when val=id
{
$val = array ( 'id' => $val );
}
2015-02-25 15:01:25 +01:00
2014-09-23 12:18:42 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status) " ;
2015-02-25 15:01:25 +01:00
$sql .= " VALUES( " . $this -> id . " , 'user', " . $val [ 'id' ] . " , " . ( empty ( $val [ 'mandatory' ]) ? '0' : $val [ 'mandatory' ]) . " , " . ( empty ( $val [ 'transparency' ]) ? '0' : $val [ 'transparency' ]) . " , " . ( empty ( $val [ 'answer_status' ]) ? '0' : $val [ 'answer_status' ]) . " ) " ;
2014-09-23 12:18:42 +02:00
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
{
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
}
//var_dump($sql);exit;
}
}
2017-06-06 17:43:22 +02:00
if ( ! $error )
{
2017-11-18 12:36:03 +01:00
if ( ! empty ( $this -> socpeopleassigned ))
2017-06-06 17:43:22 +02:00
{
2017-11-18 12:36:03 +01:00
foreach ( $this -> socpeopleassigned as $id => $Tab )
2017-06-06 17:43:22 +02:00
{
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status) " ;
$sql .= " VALUES( " . $this -> id . " , 'socpeople', " . $id . " , 0, 0, 0) " ;
2017-11-22 14:42:47 +01:00
2017-06-06 17:43:22 +02:00
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
{
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
}
2017-11-22 14:42:47 +01:00
2017-06-06 17:43:22 +02:00
}
}
}
2017-11-22 14:42:47 +01:00
2014-09-23 12:18:42 +02:00
if ( ! $error )
2012-12-08 12:49:20 +01:00
{
2014-11-15 19:04:21 +01:00
$action = 'create' ;
2018-04-10 12:03:01 +02:00
// Actions on extra fields
if ( empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLED )) // For avoid conflicts if trigger used
{
$result = $this -> insertExtraFields ();
if ( $result < 0 )
{
$error ++ ;
}
2014-09-23 12:18:42 +02:00
}
2012-12-08 12:49:20 +01:00
}
2012-12-10 19:06:59 +01:00
2012-12-30 13:49:37 +01:00
if ( ! $error && ! $notrigger )
2007-07-25 19:46:47 +02:00
{
2014-07-03 15:39:40 +02:00
// Call trigger
$result = $this -> call_trigger ( 'ACTION_CREATE' , $user );
2014-07-08 01:02:30 +02:00
if ( $result < 0 ) { $error ++ ; }
2014-07-03 15:39:40 +02:00
// End call triggers
2011-11-01 13:22:39 +01:00
}
2012-12-30 13:49:37 +01:00
if ( ! $error )
{
$this -> db -> commit ();
return $this -> id ;
}
else
{
2013-01-10 08:27:12 +01:00
$this -> db -> rollback ();
return - 1 ;
2012-12-30 13:49:37 +01:00
}
2004-10-30 14:17:49 +02:00
}
2005-06-25 15:02:39 +02:00
else
{
2011-11-01 13:22:39 +01:00
$this -> db -> rollback ();
$this -> error = $this -> db -> lasterror ();
2005-06-25 15:02:39 +02:00
return - 1 ;
}
2009-05-04 22:39:17 +02:00
2002-05-11 20:53:13 +02:00
}
2004-10-30 00:31:33 +02:00
2016-04-16 21:41:06 +02:00
/**
* Add an action / event into database .
* $this -> type_id OR $this -> type_code must be set .
*
* @ param User $user Object user making action
* @ param int $notrigger 1 = disable triggers , 0 = enable triggers
* @ return int Id of created event , < 0 if KO
* @ deprecated Use create instead
*/
public function add ( User $user , $notrigger = 0 )
{
2016-06-29 16:30:47 +02:00
return $this -> create ( $user , $notrigger );
2016-04-16 21:41:06 +02:00
}
2011-11-01 13:22:39 +01:00
/**
2015-06-08 12:39:25 +02:00
* Load an object from its id and create a new one in database
*
2015-06-19 11:27:15 +02:00
* @ param user $fuser Object user making action
2015-06-19 06:19:10 +02:00
* @ param int $socid Id of thirdparty
2015-06-08 12:39:25 +02:00
* @ return int New id of clone
*/
2015-06-19 11:27:15 +02:00
function createFromClone ( $fuser , $socid )
2015-06-08 12:39:25 +02:00
{
2015-06-19 11:27:15 +02:00
global $db , $user , $langs , $conf , $hookmanager ;
2015-06-19 11:21:36 +02:00
2015-06-08 12:39:25 +02:00
$this -> context [ 'createfromclone' ] = 'createfromclone' ;
$error = 0 ;
$now = dol_now ();
$this -> db -> begin ();
2015-09-24 16:32:48 +02:00
// Load source object
$objFrom = clone $this ;
2015-06-19 11:21:36 +02:00
2018-02-20 19:38:18 +01:00
// Retreive all extrafield
// fetch optionals attributes and labels
2015-06-08 15:06:43 +02:00
$this -> fetch_optionals ();
2018-02-20 19:38:18 +01:00
2017-06-06 17:43:22 +02:00
// $this->fetch_userassigned();
$this -> fetchResources ();
2015-06-19 11:21:36 +02:00
2015-06-08 12:39:25 +02:00
$this -> id = 0 ;
2016-01-13 14:41:32 +01:00
if ( ! is_object ( $fuser ))
{
if ( $fuser > 0 )
{
$u = new User ( $db );
$u -> fetch ( $fuser );
$fuser = $u ;
}
2017-07-04 10:29:38 +02:00
else
2016-01-13 14:41:32 +01:00
{
$fuser = $user ;
}
}
2015-06-08 12:39:25 +02:00
// Create clone
2016-04-16 21:41:06 +02:00
$result = $this -> create ( $fuser );
2015-06-08 12:39:25 +02:00
if ( $result < 0 ) $error ++ ;
if ( ! $error )
{
// Hook of thirdparty module
if ( is_object ( $hookmanager ))
{
$parameters = array ( 'objFrom' => $objFrom );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'createFrom' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) $error ++ ;
}
// Call trigger
2015-06-19 11:27:15 +02:00
$result = $this -> call_trigger ( 'ACTION_CLONE' , $fuser );
2015-06-08 12:39:25 +02:00
if ( $result < 0 ) { $error ++ ; }
// End call triggers
}
unset ( $this -> context [ 'createfromclone' ]);
// End
if ( ! $error )
{
$this -> db -> commit ();
return $this -> id ;
}
else
{
$this -> db -> rollback ();
return - 1 ;
}
}
2011-11-01 13:22:39 +01:00
/**
* Load object from database
*
2015-07-20 17:19:44 +02:00
* @ param int $id Id of action to get
* @ param string $ref Ref of action to get
* @ param string $ref_ext Ref ext to get
* @ return int < 0 if KO , > 0 if OK
2011-11-01 13:22:39 +01:00
*/
2015-07-20 17:19:44 +02:00
function fetch ( $id , $ref = '' , $ref_ext = '' )
2011-11-01 13:22:39 +01:00
{
global $langs ;
$sql = " SELECT a.id, " ;
2011-11-01 15:05:42 +01:00
$sql .= " a.id as ref, " ;
$sql .= " a.ref_ext, " ;
2011-11-01 13:22:39 +01:00
$sql .= " a.datep, " ;
$sql .= " a.datep2, " ;
2014-09-18 01:43:50 +02:00
$sql .= " a.durationp, " ; // deprecated
2011-11-01 13:22:39 +01:00
$sql .= " a.datec, " ;
$sql .= " a.tms as datem, " ;
2013-03-08 12:04:01 +01:00
$sql .= " a.code, a.label, a.note, " ;
2011-11-01 13:22:39 +01:00
$sql .= " a.fk_soc, " ;
$sql .= " a.fk_project, " ;
$sql .= " a.fk_user_author, a.fk_user_mod, " ;
$sql .= " a.fk_user_action, a.fk_user_done, " ;
$sql .= " a.fk_contact, a.percent as percentage, " ;
2018-03-13 10:28:44 +01:00
$sql .= " a.fk_element as elementid, a.elementtype, " ;
2014-09-28 14:18:04 +02:00
$sql .= " a.priority, a.fulldayevent, a.location, a.punctual, a.transparency, " ;
2016-10-30 12:39:51 +01:00
$sql .= " c.id as type_id, c.code as type_code, c.libelle as type_label, c.color as type_color, c.picto as type_picto, " ;
2011-11-01 13:22:39 +01:00
$sql .= " s.nom as socname, " ;
2013-02-23 12:30:01 +01:00
$sql .= " u.firstname, u.lastname as lastname " ;
2015-02-10 16:03:31 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " actioncomm as a " ;
2015-07-20 17:19:44 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_actioncomm as c ON a.fk_action=c.id " ;
2009-07-02 01:56:47 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " user as u on u.rowid = a.fk_user_author " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s on s.rowid = a.fk_soc " ;
2015-02-11 14:39:32 +01:00
$sql .= " WHERE " ;
2015-07-20 17:19:44 +02:00
if ( $ref ) $sql .= " a.id= " . $ref ; // No field ref, we use id
elseif ( $ref_ext ) $sql .= " a.ref_ext=' " . $this -> db -> escape ( $ref_ext ) . " ' " ;
2015-02-11 14:39:32 +01:00
else $sql .= " a.id= " . $id ;
2011-11-01 13:22:39 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch " , LOG_DEBUG );
2011-11-01 13:22:39 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2015-03-26 16:55:13 +01:00
$num = $this -> db -> num_rows ( $resql );
if ( $num )
2011-11-01 13:22:39 +01:00
{
$obj = $this -> db -> fetch_object ( $resql );
2016-10-30 12:39:51 +01:00
$this -> id = $obj -> id ;
$this -> ref = $obj -> ref ;
$this -> ref_ext = $obj -> ref_ext ;
2011-11-01 13:22:39 +01:00
2016-10-30 12:39:51 +01:00
// Properties of parent table llx_c_actioncomm
$this -> type_id = $obj -> type_id ;
$this -> type_code = $obj -> type_code ;
2016-08-28 07:59:47 +02:00
$this -> type_color = $obj -> type_color ;
2016-10-30 12:39:51 +01:00
$this -> type_picto = $obj -> type_picto ;
2011-11-01 13:22:39 +01:00
$transcode = $langs -> trans ( " Action " . $obj -> type_code );
2017-11-24 20:02:46 +01:00
$this -> type = (( $transcode != " Action " . $obj -> type_code ) ? $transcode : $obj -> type_label );
$transcode = $langs -> trans ( " Action " . $obj -> type_code . 'Short' );
$this -> type_short = (( $transcode != " Action " . $obj -> type_code . 'Short' ) ? $transcode : '' );
2013-03-09 20:34:38 +01:00
2013-03-08 12:04:01 +01:00
$this -> code = $obj -> code ;
2011-11-01 13:22:39 +01:00
$this -> label = $obj -> label ;
$this -> datep = $this -> db -> jdate ( $obj -> datep );
$this -> datef = $this -> db -> jdate ( $obj -> datep2 );
$this -> datec = $this -> db -> jdate ( $obj -> datec );
$this -> datem = $this -> db -> jdate ( $obj -> datem );
$this -> note = $obj -> note ;
$this -> percentage = $obj -> percentage ;
2014-09-29 13:21:03 +02:00
$this -> authorid = $obj -> fk_user_author ;
$this -> usermodid = $obj -> fk_user_mod ;
2014-10-10 16:53:21 +02:00
2017-11-24 20:02:46 +01:00
if ( ! is_object ( $this -> author )) $this -> author = new stdClass (); // To avoid warning
2014-09-29 13:21:03 +02:00
$this -> author -> id = $obj -> fk_user_author ; // deprecated
$this -> author -> firstname = $obj -> firstname ; // deprecated
$this -> author -> lastname = $obj -> lastname ; // deprecated
2017-11-24 20:02:46 +01:00
if ( ! is_object ( $this -> usermod )) $this -> usermod = new stdClass (); // To avoid warning
2014-09-29 13:21:03 +02:00
$this -> usermod -> id = $obj -> fk_user_mod ; // deprecated
2011-11-01 13:22:39 +01:00
2014-09-26 12:27:18 +02:00
$this -> userownerid = $obj -> fk_user_action ;
2014-09-29 13:21:03 +02:00
$this -> userdoneid = $obj -> fk_user_done ;
2011-11-01 13:22:39 +01:00
$this -> priority = $obj -> priority ;
2011-06-19 17:10:32 +02:00
$this -> fulldayevent = $obj -> fulldayevent ;
2011-11-01 13:22:39 +01:00
$this -> location = $obj -> location ;
2013-06-05 16:24:32 +02:00
$this -> transparency = $obj -> transparency ;
2015-04-23 23:21:06 +02:00
$this -> punctual = $obj -> punctual ; // deprecated
2011-11-01 13:22:39 +01:00
2014-09-24 01:35:29 +02:00
$this -> socid = $obj -> fk_soc ; // To have fetch_thirdparty method working
2014-09-29 13:21:03 +02:00
$this -> contactid = $obj -> fk_contact ; // To have fetch_contact method working
2014-09-24 01:35:29 +02:00
$this -> fk_project = $obj -> fk_project ; // To have fetch_project method working
2014-09-29 13:21:03 +02:00
$this -> societe -> id = $obj -> fk_soc ; // deprecated
$this -> contact -> id = $obj -> fk_contact ; // deprecated
2011-11-01 13:22:39 +01:00
2018-03-13 10:28:44 +01:00
$this -> fk_element = $obj -> elementid ;
2018-08-15 14:42:03 +02:00
$this -> elementid = $obj -> elementid ;
2011-11-01 13:22:39 +01:00
$this -> elementtype = $obj -> elementtype ;
2017-11-22 14:42:47 +01:00
2017-06-06 17:43:22 +02:00
$this -> fetchResources ();
2011-11-01 13:22:39 +01:00
}
$this -> db -> free ( $resql );
}
else
{
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
2015-04-01 16:07:22 +02:00
2015-03-26 16:55:13 +01:00
return $num ;
2015-04-01 16:07:22 +02:00
2011-11-01 13:22:39 +01:00
}
2017-06-06 17:43:22 +02:00
/**
* Initialize $this -> userassigned & this -> socpeopleassigned array with list of id of user and contact assigned to event
*
* @ return int < 0 if KO , > 0 if OK
*/
function fetchResources ()
{
$sql = 'SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'actioncomm_resources' ;
$sql .= ' WHERE fk_actioncomm = ' . $this -> id ;
2017-11-02 10:45:27 +01:00
$sql .= " AND element_type IN ('user', 'socpeople') " ;
2017-06-06 17:43:22 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$this -> userassigned = array ();
$this -> socpeopleassigned = array ();
// If owner is known, we must but id first into list
if ( $this -> userownerid > 0 ) $this -> userassigned [ $this -> userownerid ] = array ( 'id' => $this -> userownerid ); // Set first so will be first into list.
while ( $obj = $this -> db -> fetch_object ( $resql ))
{
if ( $obj -> fk_element > 0 )
{
switch ( $obj -> element_type ) {
case 'user' :
$this -> userassigned [ $obj -> fk_element ] = array ( 'id' => $obj -> fk_element , 'mandatory' => $obj -> mandatory , 'answer_status' => $obj -> answer_status , 'transparency' => $obj -> transparency );
if ( empty ( $this -> userownerid )) $this -> userownerid = $obj -> fk_element ; // If not defined (should not happened, we fix this)
break ;
case 'socpeople' :
$this -> socpeopleassigned [ $obj -> fk_element ] = array ( 'id' => $obj -> fk_element , 'mandatory' => $obj -> mandatory , 'answer_status' => $obj -> answer_status , 'transparency' => $obj -> transparency );
break ;
}
}
}
return 1 ;
}
else
{
dol_print_error ( $this -> db );
return - 1 ;
}
}
2014-09-23 16:15:15 +02:00
/**
2014-09-26 12:27:18 +02:00
* Initialize this -> userassigned array with list of id of user assigned to event
2014-09-23 16:15:15 +02:00
*
* @ return int < 0 if KO , > 0 if OK
*/
function fetch_userassigned ()
{
2015-02-10 11:38:13 +01:00
$sql = " SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency " ;
2014-09-23 16:15:15 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " actioncomm_resources " ;
$sql .= " WHERE element_type = 'user' AND fk_actioncomm = " . $this -> id ;
$resql2 = $this -> db -> query ( $sql );
if ( $resql2 )
{
2014-09-26 12:27:18 +02:00
$this -> userassigned = array ();
// If owner is known, we must but id first into list
if ( $this -> userownerid > 0 ) $this -> userassigned [ $this -> userownerid ] = array ( 'id' => $this -> userownerid ); // Set first so will be first into list.
2014-09-23 16:15:15 +02:00
while ( $obj = $this -> db -> fetch_object ( $resql2 ))
{
2014-10-09 17:05:57 +02:00
if ( $obj -> fk_element > 0 ) $this -> userassigned [ $obj -> fk_element ] = array ( 'id' => $obj -> fk_element , 'mandatory' => $obj -> mandatory , 'answer_status' => $obj -> answer_status , 'transparency' => $obj -> transparency );
2014-10-03 18:25:38 +02:00
if ( empty ( $this -> userownerid )) $this -> userownerid = $obj -> fk_element ; // If not defined (should not happened, we fix this)
2014-09-23 16:15:15 +02:00
}
2014-10-03 18:25:38 +02:00
2014-09-23 16:15:15 +02:00
return 1 ;
}
else
{
dol_print_error ( $this -> db );
return - 1 ;
}
}
2011-11-01 13:22:39 +01:00
/**
* Delete event from database
*
* @ param int $notrigger 1 = disable triggers , 0 = enable triggers
* @ return int < 0 if KO , > 0 if OK
*/
function delete ( $notrigger = 0 )
2009-05-04 22:39:17 +02:00
{
2011-11-01 13:22:39 +01:00
global $user , $langs , $conf ;
$error = 0 ;
$this -> db -> begin ();
2006-10-22 04:52:57 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " actioncomm " ;
$sql .= " WHERE id= " . $this -> id ;
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::delete " , LOG_DEBUG );
2012-12-08 12:49:20 +01:00
$res = $this -> db -> query ( $sql );
if ( $res < 0 ) {
$this -> error = $this -> db -> lasterror ();
$error ++ ;
}
2017-07-04 10:29:38 +02:00
2015-09-29 09:45:04 +02:00
if ( ! $error ) {
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " actioncomm_resources " ;
$sql .= " WHERE fk_actioncomm= " . $this -> id ;
2017-07-04 10:29:38 +02:00
2015-09-29 09:45:04 +02:00
dol_syslog ( get_class ( $this ) . " ::delete " , LOG_DEBUG );
$res = $this -> db -> query ( $sql );
if ( $res < 0 ) {
$this -> error = $this -> db -> lasterror ();
$error ++ ;
}
2012-12-08 12:49:20 +01:00
}
2017-07-04 10:29:38 +02:00
2012-12-08 12:49:20 +01:00
// Removed extrafields
if ( ! $error ) {
2012-12-10 19:06:59 +01:00
$result = $this -> deleteExtraFields ();
if ( $result < 0 )
{
$error ++ ;
dol_syslog ( get_class ( $this ) . " ::delete error -3 " . $this -> error , LOG_ERR );
}
2012-12-08 12:49:20 +01:00
}
2012-12-10 19:06:59 +01:00
2012-12-08 12:49:20 +01:00
if ( ! $error )
2004-10-30 00:31:33 +02:00
{
2011-11-01 13:22:39 +01:00
if ( ! $notrigger )
{
2014-07-03 15:39:40 +02:00
// Call trigger
$result = $this -> call_trigger ( 'ACTION_DELETE' , $user );
2014-07-08 01:02:30 +02:00
if ( $result < 0 ) { $error ++ ; }
2014-07-03 15:39:40 +02:00
// End call triggers
2011-11-01 13:22:39 +01:00
}
if ( ! $error )
{
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> db -> rollback ();
return - 2 ;
}
2004-10-30 00:31:33 +02:00
}
2006-10-22 04:52:57 +02:00
else
{
2011-11-01 13:22:39 +01:00
$this -> db -> rollback ();
$this -> error = $this -> db -> lasterror ();
return - 1 ;
2006-10-22 04:52:57 +02:00
}
2002-05-11 20:53:13 +02:00
}
2004-10-30 00:31:33 +02:00
2011-11-01 13:22:39 +01:00
/**
* Update action into database
* If percentage = 100 , on met a jour date 100 %
*
* @ param User $user Object user making change
* @ param int $notrigger 1 = disable triggers , 0 = enable triggers
* @ return int < 0 if KO , > 0 if OK
*/
function update ( $user , $notrigger = 0 )
2003-08-03 18:53:46 +02:00
{
2013-01-25 19:12:54 +01:00
global $langs , $conf , $hookmanager ;
2011-11-01 13:22:39 +01:00
$error = 0 ;
2008-02-26 19:34:53 +01:00
// Clean parameters
2011-11-01 13:22:39 +01:00
$this -> label = trim ( $this -> label );
2006-05-13 16:28:31 +02:00
$this -> note = trim ( $this -> note );
2011-11-01 13:22:39 +01:00
if ( empty ( $this -> percentage )) $this -> percentage = 0 ;
2014-02-06 17:09:41 +01:00
if ( empty ( $this -> priority ) || ! is_numeric ( $this -> priority )) $this -> priority = 0 ;
2013-04-06 17:39:31 +02:00
if ( empty ( $this -> transparency )) $this -> transparency = 0 ;
2010-11-18 23:17:44 +01:00
if ( empty ( $this -> fulldayevent )) $this -> fulldayevent = 0 ;
2007-09-02 12:20:07 +02:00
if ( $this -> percentage > 100 ) $this -> percentage = 100 ;
2013-06-24 16:41:31 +02:00
//if ($this->percentage == 100 && ! $this->dateend) $this->dateend = $this->date;
2014-09-18 01:43:50 +02:00
if ( $this -> datep && $this -> datef ) $this -> durationp = ( $this -> datef - $this -> datep ); // deprecated
2013-06-24 16:41:31 +02:00
//if ($this->date && $this->dateend) $this->durationa=($this->dateend - $this->date);
2011-11-01 13:22:39 +01:00
if ( $this -> datep && $this -> datef && $this -> datep > $this -> datef ) $this -> datef = $this -> datep ;
2013-06-24 16:41:31 +02:00
//if ($this->date && $this->dateend && $this->date > $this->dateend) $this->dateend=$this->date;
2010-01-05 00:33:23 +01:00
if ( $this -> fk_project < 0 ) $this -> fk_project = 0 ;
2009-05-04 22:39:17 +02:00
2011-11-01 13:22:39 +01:00
// Check parameters
2014-10-11 15:04:42 +02:00
if ( $this -> percentage == 0 && $this -> userdoneid > 0 )
2011-11-01 13:22:39 +01:00
{
$this -> error = " ErrorCantSaveADoneUserWithZeroPercentage " ;
return - 1 ;
}
2014-10-03 15:58:08 +02:00
$socid = ( $this -> socid ? $this -> socid : (( isset ( $this -> societe -> id ) && $this -> societe -> id > 0 ) ? $this -> societe -> id : 0 ));
$contactid = ( $this -> contactid ? $this -> contactid : (( isset ( $this -> contact -> id ) && $this -> contact -> id > 0 ) ? $this -> contact -> id : 0 ));
2014-10-11 15:04:42 +02:00
$userownerid = ( $this -> userownerid ? $this -> userownerid : 0 );
$userdoneid = ( $this -> userdoneid ? $this -> userdoneid : 0 );
2014-10-03 15:58:08 +02:00
2011-11-01 13:22:39 +01:00
$this -> db -> begin ();
2009-05-04 22:39:17 +02:00
2011-11-01 13:22:39 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " actioncomm " ;
2017-05-12 16:55:11 +02:00
$sql .= " SET percent = ' " . $this -> db -> escape ( $this -> percentage ) . " ' " ;
2017-09-19 17:26:18 +02:00
if ( $this -> type_id > 0 ) $sql .= " , fk_action = ' " . $this -> db -> escape ( $this -> type_id ) . " ' " ;
2011-02-24 19:11:12 +01:00
$sql .= " , label = " . ( $this -> label ? " ' " . $this -> db -> escape ( $this -> label ) . " ' " : " null " );
2008-07-28 23:20:23 +02:00
$sql .= " , datep = " . ( strval ( $this -> datep ) != '' ? " ' " . $this -> db -> idate ( $this -> datep ) . " ' " : 'null' );
$sql .= " , datep2 = " . ( strval ( $this -> datef ) != '' ? " ' " . $this -> db -> idate ( $this -> datef ) . " ' " : 'null' );
2017-09-15 15:41:07 +02:00
$sql .= " , durationp = " . ( isset ( $this -> durationp ) && $this -> durationp >= 0 && $this -> durationp != '' ? " ' " . $this -> db -> escape ( $this -> durationp ) . " ' " : " null " ); // deprecated
2011-02-24 19:11:12 +01:00
$sql .= " , note = " . ( $this -> note ? " ' " . $this -> db -> escape ( $this -> note ) . " ' " : " null " );
2017-09-15 15:41:07 +02:00
$sql .= " , fk_project = " . ( $this -> fk_project > 0 ? $this -> fk_project : " null " );
$sql .= " , fk_soc = " . ( $socid > 0 ? $socid : " null " );
$sql .= " , fk_contact = " . ( $contactid > 0 ? $contactid : " null " );
2017-05-12 16:55:11 +02:00
$sql .= " , priority = ' " . $this -> db -> escape ( $this -> priority ) . " ' " ;
$sql .= " , fulldayevent = ' " . $this -> db -> escape ( $this -> fulldayevent ) . " ' " ;
2011-02-24 19:11:12 +01:00
$sql .= " , location = " . ( $this -> location ? " ' " . $this -> db -> escape ( $this -> location ) . " ' " : " null " );
2017-05-12 16:55:11 +02:00
$sql .= " , transparency = ' " . $this -> db -> escape ( $this -> transparency ) . " ' " ;
$sql .= " , fk_user_mod = " . $user -> id ;
2014-10-03 18:25:38 +02:00
$sql .= " , fk_user_action= " . ( $userownerid > 0 ? " ' " . $userownerid . " ' " : " null " );
$sql .= " , fk_user_done= " . ( $userdoneid > 0 ? " ' " . $userdoneid . " ' " : " null " );
2017-09-15 15:41:07 +02:00
if ( ! empty ( $this -> fk_element )) $sql .= " , fk_element= " . ( $this -> fk_element ? $this -> db -> escape ( $this -> fk_element ) : " null " );
if ( ! empty ( $this -> elementtype )) $sql .= " , elementtype= " . ( $this -> elementtype ? " ' " . $this -> db -> escape ( $this -> elementtype ) . " ' " : " null " );
2006-05-23 23:15:33 +02:00
$sql .= " WHERE id= " . $this -> id ;
2009-05-04 22:39:17 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::update " , LOG_DEBUG );
2006-02-25 01:38:31 +01:00
if ( $this -> db -> query ( $sql ))
2005-07-10 04:05:09 +02:00
{
2014-11-15 19:04:21 +01:00
$action = 'update' ;
2012-12-10 19:06:59 +01:00
2018-04-10 12:03:01 +02:00
// Actions on extra fields
if ( empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLED )) // For avoid conflicts if trigger used
{
$result = $this -> insertExtraFields ();
if ( $result < 0 )
{
$error ++ ;
}
2012-12-08 12:49:20 +01:00
}
2012-12-10 19:06:59 +01:00
2014-09-23 16:15:15 +02:00
// Now insert assignedusers
if ( ! $error )
{
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " actioncomm_resources where fk_actioncomm = " . $this -> id . " AND element_type = 'user' " ;
$resql = $this -> db -> query ( $sql );
foreach ( $this -> userassigned as $key => $val )
{
2015-05-19 15:54:08 +02:00
if ( ! is_array ( $val )) // For backward compatibility when val=id
{
$val = array ( 'id' => $val );
}
2014-09-23 16:15:15 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status) " ;
2018-08-23 14:34:27 +02:00
$sql .= " VALUES( " . $this -> id . " , 'user', " . $val [ 'id' ] . " , " . ( empty ( $val [ 'mandatory' ]) ? '0' : $val [ 'mandatory' ]) . " , " . ( empty ( $val [ 'transparency' ]) ? '0' : $val [ 'transparency' ]) . " , " . ( empty ( $val [ 'answer_status' ]) ? '0' : $val [ 'answer_status' ]) . " ) " ;
2014-09-23 16:15:15 +02:00
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
{
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
}
//var_dump($sql);exit;
}
}
2017-11-22 14:42:47 +01:00
2017-06-06 17:43:22 +02:00
if ( ! $error )
{
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " actioncomm_resources where fk_actioncomm = " . $this -> id . " AND element_type = 'socpeople' " ;
$resql = $this -> db -> query ( $sql );
2017-11-22 14:42:47 +01:00
2017-11-18 12:36:03 +01:00
if ( ! empty ( $this -> socpeopleassigned ))
2017-06-06 17:43:22 +02:00
{
2017-11-18 12:36:03 +01:00
foreach ( array_keys ( $this -> socpeopleassigned ) as $id )
2017-06-06 17:43:22 +02:00
{
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status) " ;
$sql .= " VALUES( " . $this -> id . " , 'socpeople', " . $id . " , 0, 0, 0) " ;
2017-11-22 14:42:47 +01:00
2017-06-06 17:43:22 +02:00
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
{
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
}
2017-11-22 14:42:47 +01:00
2017-06-06 17:43:22 +02:00
}
}
}
2014-09-23 16:15:15 +02:00
if ( ! $error && ! $notrigger )
2011-11-01 13:22:39 +01:00
{
2014-07-03 15:39:40 +02:00
// Call trigger
$result = $this -> call_trigger ( 'ACTION_MODIFY' , $user );
2014-07-08 01:02:30 +02:00
if ( $result < 0 ) { $error ++ ; }
2014-07-03 15:39:40 +02:00
// End call triggers
2011-11-01 13:22:39 +01:00
}
if ( ! $error )
{
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> db -> rollback ();
dol_syslog ( get_class ( $this ) . " ::update " . join ( ',' , $this -> errors ), LOG_ERR );
return - 2 ;
}
2005-07-10 04:05:09 +02:00
}
2006-02-25 01:38:31 +01:00
else
{
2011-11-01 13:22:39 +01:00
$this -> db -> rollback ();
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
2003-08-03 18:53:46 +02:00
}
2009-05-04 22:39:17 +02:00
2011-11-01 13:22:39 +01:00
/**
2017-09-17 17:29:00 +02:00
* Load all objects with filters .
* WARNING : This make a fetch on all records instead of making one request with a join .
2012-01-08 00:15:36 +01:00
*
2012-12-19 20:59:08 +01:00
* @ param DoliDb $db Database handler
2012-01-08 00:52:07 +01:00
* @ param int $socid Filter by thirdparty
* @ param int $fk_element Id of element action is linked to
* @ param string $elementtype Type of element action is linked to
* @ param string $filter Other filter
2014-09-22 20:16:58 +02:00
* @ param string $sortfield Sort on this field
* @ param string $sortorder ASC or DESC
2017-09-13 15:12:54 +02:00
* @ param string $limit Limit number of answers
2013-01-07 23:20:00 +01:00
* @ return array or string Error string if KO , array with actions if OK
2011-11-01 13:22:39 +01:00
*/
2017-09-16 10:12:44 +02:00
static function getActions ( $db , $socid = 0 , $fk_element = 0 , $elementtype = '' , $filter = '' , $sortfield = 'a.datep' , $sortorder = 'DESC' , $limit = 0 )
2011-11-01 13:22:39 +01:00
{
global $conf , $langs ;
2012-12-01 15:45:05 +01:00
$resarray = array ();
2011-11-01 13:22:39 +01:00
$sql = " SELECT a.id " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " actioncomm as a " ;
2017-05-30 18:50:54 +02:00
$sql .= " WHERE a.entity IN ( " . getEntity ( 'agenda' ) . " ) " ;
2011-11-01 13:22:39 +01:00
if ( ! empty ( $socid )) $sql .= " AND a.fk_soc = " . $socid ;
if ( ! empty ( $elementtype ))
{
if ( $elementtype == 'project' ) $sql .= ' AND a.fk_project = ' . $fk_element ;
2015-12-24 14:27:12 +01:00
else $sql .= " AND a.fk_element = " . ( int ) $fk_element . " AND a.elementtype = ' " . $elementtype . " ' " ;
2011-11-01 13:22:39 +01:00
}
if ( ! empty ( $filter )) $sql .= $filter ;
2014-09-22 20:16:58 +02:00
if ( $sortorder && $sortfield ) $sql .= $db -> order ( $sortfield , $sortorder );
2017-09-16 13:14:46 +02:00
$sql .= $db -> plimit ( $limit , 0 );
2011-11-01 13:22:39 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class () . " ::getActions " , LOG_DEBUG );
2012-12-01 15:45:05 +01:00
$resql = $db -> query ( $sql );
2011-11-01 13:22:39 +01:00
if ( $resql )
{
2012-12-01 15:45:05 +01:00
$num = $db -> num_rows ( $resql );
2011-11-01 13:22:39 +01:00
if ( $num )
{
for ( $i = 0 ; $i < $num ; $i ++ )
2011-06-19 17:10:32 +02:00
{
2012-12-01 15:45:05 +01:00
$obj = $db -> fetch_object ( $resql );
$actioncommstatic = new ActionComm ( $db );
2011-11-01 13:22:39 +01:00
$actioncommstatic -> fetch ( $obj -> id );
2012-12-01 15:45:05 +01:00
$resarray [ $i ] = $actioncommstatic ;
2011-06-19 17:10:32 +02:00
}
2011-11-01 13:22:39 +01:00
}
2012-12-01 15:45:05 +01:00
$db -> free ( $resql );
return $resarray ;
2011-11-01 13:22:39 +01:00
}
else
2013-01-07 23:20:00 +01:00
{
return $db -> lasterror ();
2011-11-01 13:22:39 +01:00
}
}
2017-10-17 10:44:18 +02:00
2005-07-15 00:29:49 +02:00
/**
2015-02-15 15:01:28 +01:00
* Load indicators for dashboard ( this -> nbtodo and this -> nbtodolate )
2012-01-08 00:15:36 +01:00
*
2017-09-27 10:09:21 +02:00
* @ param User $user Objet user
* @ param int $load_state_board Charge indicateurs this -> nb de tableau de bord
2015-02-16 23:49:07 +01:00
* @ return WorkboardResponse | int < 0 if KO , WorkboardResponse if OK
2005-07-15 00:29:49 +02:00
*/
2017-09-27 10:09:21 +02:00
function load_board ( $user , $load_state_board = 0 )
2005-07-15 00:29:49 +02:00
{
2017-09-26 12:32:58 +02:00
global $conf , $langs ;
2017-10-17 10:44:18 +02:00
2017-09-27 10:09:21 +02:00
if ( empty ( $load_state_board )) $sql = " SELECT a.id, a.datep as dp " ;
else {
$this -> nb = array ();
$sql = " SELECT count(a.id) as nb " ;
}
2017-09-26 12:32:58 +02:00
$sql .= " FROM ( " . MAIN_DB_PREFIX . " actioncomm as a " ;
$sql .= " ) " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe_commerciaux as sc ON a.fk_soc = sc.fk_soc " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON a.fk_soc = s.rowid " ;
2017-10-26 18:35:32 +02:00
$sql .= " WHERE 1 = 1 " ;
2017-09-27 10:09:21 +02:00
if ( empty ( $load_state_board )) $sql .= " AND a.percent >= 0 AND a.percent < 100 " ;
2017-09-26 12:32:58 +02:00
$sql .= " AND a.entity IN ( " . getEntity ( 'agenda' ) . " ) " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $user -> societe_id ) $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = " . $user -> id . " ) " ;
if ( $user -> societe_id ) $sql .= " AND a.fk_soc = " . $user -> societe_id ;
if ( ! $user -> rights -> agenda -> allactions -> read ) $sql .= " AND (a.fk_user_author = " . $user -> id . " OR a.fk_user_action = " . $user -> id . " OR a.fk_user_done = " . $user -> id . " ) " ;
2017-10-17 10:44:18 +02:00
2017-09-26 12:32:58 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2017-09-27 10:09:21 +02:00
if ( empty ( $load_state_board )) {
$agenda_static = new ActionComm ( $this -> db );
$response = new WorkboardResponse ();
$response -> warning_delay = $conf -> agenda -> warning_delay / 60 / 60 / 24 ;
$response -> label = $langs -> trans ( " ActionsToDo " );
2018-02-05 23:05:37 +01:00
$response -> url = DOL_URL_ROOT . '/comm/action/list.php?actioncode=0&status=todo&mainmenu=agenda' ;
2017-09-27 10:09:21 +02:00
if ( $user -> rights -> agenda -> allactions -> read ) $response -> url .= '&filtert=-1' ;
$response -> img = img_object ( '' , " action " , 'class="inline-block valigntextmiddle"' );
2017-09-26 12:32:58 +02:00
}
2017-09-27 10:09:21 +02:00
// This assignment in condition is not a bug. It allows walking the results.
2017-09-26 12:32:58 +02:00
while ( $obj = $this -> db -> fetch_object ( $resql ))
{
2017-09-27 10:09:21 +02:00
if ( empty ( $load_state_board )) {
$response -> nbtodo ++ ;
$agenda_static -> datep = $this -> db -> jdate ( $obj -> dp );
if ( $agenda_static -> hasDelay ()) $response -> nbtodolate ++ ;
} else $this -> nb [ " actionscomm " ] = $obj -> nb ;
2017-09-26 12:32:58 +02:00
}
2017-10-17 10:44:18 +02:00
2017-09-26 12:32:58 +02:00
$this -> db -> free ( $resql );
2017-09-27 10:09:21 +02:00
if ( empty ( $load_state_board )) return $response ;
else return 1 ;
2017-09-26 12:32:58 +02:00
}
else
{
dol_print_error ( $this -> db );
$this -> error = $this -> db -> error ();
return - 1 ;
}
2005-07-15 00:29:49 +02:00
}
2006-03-19 00:20:21 +01:00
2011-11-01 13:22:39 +01:00
/**
* Charge les informations d 'ordre info dans l' objet facture
*
* @ param int $id Id de la facture a charger
* @ return void
*/
function info ( $id )
{
$sql = 'SELECT ' ;
$sql .= ' a.id,' ;
$sql .= ' datec,' ;
$sql .= ' tms as datem,' ;
$sql .= ' fk_user_author,' ;
$sql .= ' fk_user_mod' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'actioncomm as a' ;
$sql .= ' WHERE a.id = ' . $id ;
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::info " , LOG_DEBUG );
2011-11-01 13:22:39 +01:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
if ( $this -> db -> num_rows ( $result ))
{
$obj = $this -> db -> fetch_object ( $result );
$this -> id = $obj -> id ;
if ( $obj -> fk_user_author )
{
$cuser = new User ( $this -> db );
$cuser -> fetch ( $obj -> fk_user_author );
$this -> user_creation = $cuser ;
}
if ( $obj -> fk_user_mod )
{
$muser = new User ( $this -> db );
$muser -> fetch ( $obj -> fk_user_mod );
$this -> user_modification = $muser ;
}
$this -> date_creation = $this -> db -> jdate ( $obj -> datec );
2016-07-27 07:24:36 +02:00
if ( ! empty ( $obj -> fk_user_mod )) $this -> date_modification = $this -> db -> jdate ( $obj -> datem );
2011-11-01 13:22:39 +01:00
}
$this -> db -> free ( $result );
}
else
{
dol_print_error ( $this -> db );
}
}
/**
* Return label of status
*
2012-01-08 00:15:36 +01:00
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ param int $hidenastatus 1 = Show nothing if status is " Not applicable "
* @ return string String with status
2011-11-01 13:22:39 +01:00
*/
function getLibStatut ( $mode , $hidenastatus = 0 )
{
2016-10-30 12:39:51 +01:00
return $this -> LibStatut ( $this -> percentage , $mode , $hidenastatus , $this -> datep );
2011-11-01 13:22:39 +01:00
}
/**
* Return label of action status
*
2012-01-08 00:15:36 +01:00
* @ param int $percent Percent
2016-09-19 10:43:30 +02:00
* @ param int $mode 0 = Long label , 1 = Short label , 2 = Picto + Short label , 3 = Picto , 4 = Picto + Short label , 5 = Short label + Picto , 6 = Picto + Long label , 7 = Very short label + Picto
2012-01-08 00:15:36 +01:00
* @ param int $hidenastatus 1 = Show nothing if status is " Not applicable "
2016-10-30 12:39:51 +01:00
* @ param int $datestart Date start of event
2012-01-08 00:15:36 +01:00
* @ return string Label
2011-11-01 13:22:39 +01:00
*/
2016-10-30 12:39:51 +01:00
function LibStatut ( $percent , $mode , $hidenastatus = 0 , $datestart = '' )
2011-11-01 13:22:39 +01:00
{
global $langs ;
2009-05-04 22:39:17 +02:00
2006-05-20 14:16:18 +02:00
if ( $mode == 0 )
{
2011-11-03 11:49:22 +01:00
if ( $percent ==- 1 && ! $hidenastatus ) return $langs -> trans ( 'StatusNotApplicable' );
else if ( $percent == 0 ) return $langs -> trans ( 'StatusActionToDo' ) . ' (0%)' ;
else if ( $percent > 0 && $percent < 100 ) return $langs -> trans ( 'StatusActionInProcess' ) . ' (' . $percent . '%)' ;
else if ( $percent >= 100 ) return $langs -> trans ( 'StatusActionDone' ) . ' (100%)' ;
2011-11-01 13:22:39 +01:00
}
2011-11-03 11:49:22 +01:00
else if ( $mode == 1 )
2006-05-20 14:16:18 +02:00
{
2011-11-03 11:49:22 +01:00
if ( $percent ==- 1 && ! $hidenastatus ) return $langs -> trans ( 'StatusNotApplicable' );
else if ( $percent == 0 ) return $langs -> trans ( 'StatusActionToDo' );
else if ( $percent > 0 && $percent < 100 ) return $percent . '%' ;
else if ( $percent >= 100 ) return $langs -> trans ( 'StatusActionDone' );
2006-05-20 14:16:18 +02:00
}
2011-11-03 11:49:22 +01:00
else if ( $mode == 2 )
2006-05-20 14:16:18 +02:00
{
2011-11-03 11:49:22 +01:00
if ( $percent ==- 1 && ! $hidenastatus ) return img_picto ( $langs -> trans ( 'StatusNotApplicable' ), 'statut9' ) . ' ' . $langs -> trans ( 'StatusNotApplicable' );
else if ( $percent == 0 ) return img_picto ( $langs -> trans ( 'StatusActionToDo' ), 'statut1' ) . ' ' . $langs -> trans ( 'StatusActionToDo' );
else if ( $percent > 0 && $percent < 100 ) return img_picto ( $langs -> trans ( 'StatusActionInProcess' ), 'statut3' ) . ' ' . $percent . '%' ;
else if ( $percent >= 100 ) return img_picto ( $langs -> trans ( 'StatusActionDone' ), 'statut6' ) . ' ' . $langs -> trans ( 'StatusActionDone' );
2006-05-20 14:16:18 +02:00
}
2011-11-03 11:49:22 +01:00
else if ( $mode == 3 )
2006-05-20 14:16:18 +02:00
{
2011-11-03 11:49:22 +01:00
if ( $percent ==- 1 && ! $hidenastatus ) return img_picto ( $langs -> trans ( " Status " ) . ': ' . $langs -> trans ( 'StatusNotApplicable' ), 'statut9' );
else if ( $percent == 0 ) return img_picto ( $langs -> trans ( " Status " ) . ': ' . $langs -> trans ( 'StatusActionToDo' ) . ' (0%)' , 'statut1' );
else if ( $percent > 0 && $percent < 100 ) return img_picto ( $langs -> trans ( " Status " ) . ': ' . $langs -> trans ( 'StatusActionInProcess' ) . ' (' . $percent . '%)' , 'statut3' );
else if ( $percent >= 100 ) return img_picto ( $langs -> trans ( " Status " ) . ': ' . $langs -> trans ( 'StatusActionDone' ) . ' (100%)' , 'statut6' );
2006-05-20 14:16:18 +02:00
}
2011-11-03 11:49:22 +01:00
else if ( $mode == 4 )
2006-05-20 14:16:18 +02:00
{
2011-11-03 11:49:22 +01:00
if ( $percent ==- 1 && ! $hidenastatus ) return img_picto ( $langs -> trans ( 'StatusNotApplicable' ), 'statut9' ) . ' ' . $langs -> trans ( 'StatusNotApplicable' );
else if ( $percent == 0 ) return img_picto ( $langs -> trans ( 'StatusActionToDo' ), 'statut1' ) . ' ' . $langs -> trans ( 'StatusActionToDo' ) . ' (0%)' ;
else if ( $percent > 0 && $percent < 100 ) return img_picto ( $langs -> trans ( 'StatusActionInProcess' ), 'statut3' ) . ' ' . $langs -> trans ( 'StatusActionInProcess' ) . ' (' . $percent . '%)' ;
else if ( $percent >= 100 ) return img_picto ( $langs -> trans ( 'StatusActionDone' ), 'statut6' ) . ' ' . $langs -> trans ( 'StatusActionDone' ) . ' (100%)' ;
2006-05-20 14:16:18 +02:00
}
2011-11-03 11:49:22 +01:00
else if ( $mode == 5 )
2006-05-20 14:16:18 +02:00
{
2011-11-03 11:49:22 +01:00
if ( $percent ==- 1 && ! $hidenastatus ) return img_picto ( $langs -> trans ( 'StatusNotApplicable' ), 'statut9' );
else if ( $percent == 0 ) return '0% ' . img_picto ( $langs -> trans ( 'StatusActionToDo' ), 'statut1' );
else if ( $percent > 0 && $percent < 100 ) return $percent . '% ' . img_picto ( $langs -> trans ( 'StatusActionInProcess' ) . ' - ' . $percent . '%' , 'statut3' );
else if ( $percent >= 100 ) return $langs -> trans ( 'StatusActionDone' ) . ' ' . img_picto ( $langs -> trans ( 'StatusActionDone' ), 'statut6' );
2006-05-20 14:16:18 +02:00
}
2011-11-03 11:49:22 +01:00
else if ( $mode == 6 )
2011-06-01 10:24:26 +02:00
{
2016-09-19 10:43:30 +02:00
if ( $percent ==- 1 && ! $hidenastatus ) return $langs -> trans ( 'StatusNotApplicable' ) . ' ' . img_picto ( $langs -> trans ( 'StatusNotApplicable' ), 'statut9' );
2016-10-17 17:52:58 +02:00
else if ( $percent == 0 ) return $langs -> trans ( 'StatusActionToDo' ) . ' (0%) ' . img_picto ( $langs -> trans ( 'StatusActionToDo' ), 'statut1' );
2016-09-19 10:43:30 +02:00
else if ( $percent > 0 && $percent < 100 ) return $langs -> trans ( 'StatusActionInProcess' ) . ' (' . $percent . '%) ' . img_picto ( $langs -> trans ( 'StatusActionInProcess' ) . ' - ' . $percent . '%' , 'statut3' );
else if ( $percent >= 100 ) return $langs -> trans ( 'StatusActionDone' ) . ' (100%) ' . img_picto ( $langs -> trans ( 'StatusActionDone' ), 'statut6' );
}
else if ( $mode == 7 )
{
if ( $percent ==- 1 && ! $hidenastatus ) return img_picto ( $langs -> trans ( 'StatusNotApplicable' ), 'statut9' );
else if ( $percent == 0 ) return '0% ' . img_picto ( $langs -> trans ( 'StatusActionToDo' ), 'statut1' );
else if ( $percent > 0 && $percent < 100 ) return $percent . '% ' . img_picto ( $langs -> trans ( 'StatusActionInProcess' ) . ' - ' . $percent . '%' , 'statut3' );
else if ( $percent >= 100 ) return img_picto ( $langs -> trans ( 'StatusActionDone' ), 'statut6' );
2011-06-01 10:24:26 +02:00
}
2017-07-04 10:29:38 +02:00
2011-03-20 15:38:54 +01:00
return '' ;
2011-11-01 13:22:39 +01:00
}
/**
2014-10-20 13:07:54 +02:00
* Return URL of event
2014-10-20 13:14:33 +02:00
* Use $this -> id , $this -> type_code , $this -> label and $this -> type_label
2011-11-01 13:22:39 +01:00
*
2018-05-16 20:59:45 +02:00
* @ param int $withpicto 0 = No picto , 1 = Include picto into link , 2 = Only picto
* @ param int $maxlength Max number of charaters into label . If negative , use the ref as label .
* @ param string $classname Force style class on a link
* @ param string $option '' = Link to action , 'birthday' = Link to contact
* @ param int $overwritepicto 1 = Overwrite picto
* @ 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
* @ return string Chaine avec URL
2011-11-01 13:22:39 +01:00
*/
2018-05-16 20:59:45 +02:00
function getNomUrl ( $withpicto = 0 , $maxlength = 0 , $classname = '' , $option = '' , $overwritepicto = 0 , $notooltip = 0 , $save_lastsearch_value =- 1 )
2011-11-01 13:22:39 +01:00
{
2017-11-29 16:25:12 +01:00
global $conf , $langs , $user , $hookmanager , $action ;
2016-07-18 15:07:35 +02:00
2016-10-25 10:53:25 +02:00
if ( ! empty ( $conf -> dol_no_mouse_hover )) $notooltip = 1 ; // Force disable tooltips
2017-07-04 10:29:38 +02:00
2016-11-08 12:58:07 +01:00
$label = $this -> label ;
if ( empty ( $label )) $label = $this -> libelle ; // For backward compatibility
2016-07-18 15:07:35 +02:00
$result = '' ;
2017-07-04 10:29:38 +02:00
2018-03-07 11:53:30 +01:00
// Set label of type
$labeltype = '' ;
if ( $this -> type_code )
{
$labeltype = ( $langs -> transnoentities ( " Action " . $this -> type_code ) != " Action " . $this -> type_code ) ? $langs -> transnoentities ( " Action " . $this -> type_code ) : $this -> type_label ;
}
2016-11-08 12:58:07 +01:00
if ( empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE ))
{
if ( $this -> type_code != 'AC_OTH_AUTO' ) $labeltype = $langs -> trans ( 'ActionAC_MANUAL' );
}
2017-07-04 10:29:38 +02:00
2017-11-29 16:25:12 +01:00
$tooltip = '<u>' . $langs -> trans ( 'ShowAction' ) . '</u>' ;
2016-07-18 15:07:35 +02:00
if ( ! empty ( $this -> ref ))
$tooltip .= '<br><b>' . $langs -> trans ( 'Ref' ) . ':</b> ' . $this -> ref ;
if ( ! empty ( $label ))
$tooltip .= '<br><b>' . $langs -> trans ( 'Title' ) . ':</b> ' . $label ;
2016-11-08 12:58:07 +01:00
if ( ! empty ( $labeltype ))
$tooltip .= '<br><b>' . $langs -> trans ( 'Type' ) . ':</b> ' . $labeltype ;
2016-07-18 15:07:35 +02:00
if ( ! empty ( $this -> location ))
$tooltip .= '<br><b>' . $langs -> trans ( 'Location' ) . ':</b> ' . $this -> location ;
2016-10-25 10:53:25 +02:00
$linkclose = '' ;
2017-07-04 10:29:38 +02:00
if ( ! empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE ) && $this -> type_color )
2016-10-25 10:53:25 +02:00
$linkclose = ' style="background-color:#' . $this -> type_color . '"' ;
2016-08-25 12:22:17 +02:00
2016-11-08 12:58:07 +01:00
if ( empty ( $notooltip ))
2016-07-18 15:07:35 +02:00
{
2016-10-25 10:53:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ))
{
2016-11-08 12:58:07 +01:00
$label = $langs -> trans ( " ShowAction " );
2016-10-25 10:53:25 +02:00
$linkclose .= ' alt="' . dol_escape_htmltag ( $tooltip , 1 ) . '"' ;
}
$linkclose .= ' title="' . dol_escape_htmltag ( $tooltip , 1 ) . '"' ;
$linkclose .= ' class="' . $classname . ' classfortooltip"' ;
2017-07-04 10:29:38 +02:00
2018-06-04 12:55:55 +02:00
/*
2016-10-25 10:53:25 +02:00
$hookmanager -> initHooks ( array ( 'actiondao' ));
$parameters = array ( 'id' => $this -> id );
$reshook = $hookmanager -> executeHooks ( 'getnomurltooltip' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
$linkclose = ( $hookmanager -> resPrint ? $hookmanager -> resPrint : $linkclose );
2018-03-15 20:46:55 +01:00
*/
2016-07-18 15:07:35 +02:00
}
2016-10-25 10:53:25 +02:00
else $linkclose .= ' class="' . $classname . '"' ;
2017-07-04 10:29:38 +02:00
2016-10-25 10:53:25 +02:00
$url = '' ;
2017-07-04 10:29:38 +02:00
if ( $option == 'birthday' )
2016-10-25 10:53:25 +02:00
$url = DOL_URL_ROOT . '/contact/perso.php?id=' . $this -> id ;
2017-07-04 10:29:38 +02:00
else
2016-10-25 10:53:25 +02:00
$url = DOL_URL_ROOT . '/comm/action/card.php?id=' . $this -> id ;
2018-05-16 20:59:45 +02:00
if ( $option !== 'nolink' )
{
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ( $save_lastsearch_value == 1 ? 1 : 0 );
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' ;
}
2017-07-04 10:29:38 +02:00
2016-10-25 10:53:25 +02:00
$linkstart = '<a href="' . $url . '"' ;
$linkstart .= $linkclose . '>' ;
2016-07-18 15:07:35 +02:00
$linkend = '</a>' ;
2017-07-04 10:29:38 +02:00
2018-03-07 11:53:30 +01:00
//print 'rrr'.$this->libelle.'rrr'.$this->label.'rrr'.$withpicto;
2012-12-01 15:45:05 +01:00
2011-02-02 15:41:31 +01:00
if ( $withpicto == 2 )
{
2012-12-01 15:45:05 +01:00
$libelle = $label ;
2016-11-08 12:58:07 +01:00
if ( ! empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE )) $libelle = $labeltype ;
2011-02-02 15:41:31 +01:00
$libelleshort = '' ;
}
2006-12-12 20:25:30 +01:00
else
2015-01-25 01:20:58 +01:00
{
2015-01-08 10:01:02 +01:00
$libelle = ( empty ( $this -> libelle ) ? $label : $this -> libelle . (( $label && $label != $this -> libelle ) ? ' ' . $label : '' ));
2016-11-08 12:58:07 +01:00
if ( ! empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE ) && empty ( $libelle )) $libelle = $labeltype ;
2015-08-14 20:07:11 +02:00
if ( $maxlength < 0 ) $libelleshort = $this -> ref ;
else $libelleshort = dol_trunc ( $libelle , $maxlength );
2006-12-12 20:25:30 +01:00
}
2009-05-04 22:39:17 +02:00
2011-11-01 13:22:39 +01:00
if ( $withpicto )
{
2015-01-08 10:01:02 +01:00
if ( ! empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE )) // Add code into ()
{
2018-03-07 11:53:30 +01:00
if ( $labeltype )
{
$libelle .= ( preg_match ( '/' . preg_quote ( $labeltype , '/' ) . '/' , $libelle ) ? '' : ' (' . $langs -> transnoentities ( " Action " . $this -> type_code ) . ')' );
}
2015-01-08 10:01:02 +01:00
}
2011-11-01 13:22:39 +01:00
}
2017-11-02 15:03:09 +01:00
$result .= $linkstart ;
if ( $withpicto ) $result .= img_object (( $notooltip ? '' : $langs -> trans ( " ShowAction " ) . ': ' . $libelle ), ( $overwritepicto ? $overwritepicto : 'action' ), ( $notooltip ? 'class="' . (( $withpicto != 2 ) ? 'paddingright ' : '' ) . 'valigntextbottom"' : 'class="' . (( $withpicto != 2 ) ? 'paddingright ' : '' ) . 'classfortooltip valigntextbottom"' ), 0 , 0 , $notooltip ? 0 : 1 );
$result .= $libelleshort ;
$result .= $linkend ;
2018-03-15 20:46:55 +01:00
global $action ;
$hookmanager -> initHooks ( array ( 'actiondao' ));
$parameters = array ( 'id' => $this -> id , 'getnomurl' => $result );
$reshook = $hookmanager -> executeHooks ( 'getNomUrl' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook > 0 ) $result = $hookmanager -> resPrint ;
else $result .= $hookmanager -> resPrint ;
2011-11-01 13:22:39 +01:00
return $result ;
}
2006-10-24 01:07:46 +02:00
2009-05-04 22:39:17 +02:00
2008-04-08 00:11:22 +02:00
/**
2010-11-20 00:50:27 +01:00
* Export events from database into a cal file .
2011-09-22 01:41:42 +02:00
*
2012-01-08 00:15:36 +01:00
* @ param string $format 'vcal' , 'ical/ics' , 'rss'
* @ param string $type 'event' or 'journal'
* @ param int $cachedelay Do not rebuild file if date older than cachedelay seconds
* @ param string $filename Force filename
2018-02-28 20:06:28 +01:00
* @ param array $filters Array of filters . Exemple array ( 'notolderthan' => 99 , 'year' =>... , 'idfrom' =>... , 'notactiontype' => 'systemauto' , 'project' => 123 , ... )
2012-01-08 00:15:36 +01:00
* @ return int < 0 if error , nb of events in new file if ok
2008-10-31 03:03:26 +01:00
*/
2011-11-01 13:22:39 +01:00
function build_exportfile ( $format , $type , $cachedelay , $filename , $filters )
{
global $conf , $langs , $dolibarr_main_url_root , $mysoc ;
2008-10-31 03:03:26 +01:00
2011-11-01 13:22:39 +01:00
require_once ( DOL_DOCUMENT_ROOT . " /core/lib/xcal.lib.php " );
require_once ( DOL_DOCUMENT_ROOT . " /core/lib/date.lib.php " );
2013-11-28 12:58:02 +01:00
require_once ( DOL_DOCUMENT_ROOT . " /core/lib/files.lib.php " );
2014-02-10 01:30:48 +01:00
2011-11-01 13:22:39 +01:00
dol_syslog ( get_class ( $this ) . " ::build_exportfile Build export file format= " . $format . " , type= " . $type . " , cachedelay= " . $cachedelay . " , filename= " . $filename . " , filters size= " . count ( $filters ), LOG_DEBUG );
2008-04-08 00:11:22 +02:00
2011-11-01 13:22:39 +01:00
// Check parameters
if ( empty ( $format )) return - 1 ;
2008-04-08 00:11:22 +02:00
2011-11-01 13:22:39 +01:00
// Clean parameters
if ( ! $filename )
{
$extension = 'vcs' ;
if ( $format == 'ical' ) $extension = 'ics' ;
$filename = $format . '.' . $extension ;
}
2010-01-17 21:39:32 +01:00
2011-11-01 13:22:39 +01:00
// Create dir and define output file (definitive and temporary)
$result = dol_mkdir ( $conf -> agenda -> dir_temp );
$outputfile = $conf -> agenda -> dir_temp . '/' . $filename ;
2010-01-17 21:39:32 +01:00
2011-11-01 13:22:39 +01:00
$result = 0 ;
2008-04-08 03:09:10 +02:00
2011-11-01 13:22:39 +01:00
$buildfile = true ;
$login = '' ; $logina = '' ; $logind = '' ; $logint = '' ;
2009-05-04 22:39:17 +02:00
2011-11-01 13:22:39 +01:00
$now = dol_now ();
2010-05-22 11:50:32 +02:00
2011-11-01 13:22:39 +01:00
if ( $cachedelay )
{
$nowgmt = dol_now ();
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2011-11-01 13:22:39 +01:00
if ( dol_filemtime ( $outputfile ) > ( $nowgmt - $cachedelay ))
{
dol_syslog ( get_class ( $this ) . " ::build_exportfile file " . $outputfile . " is not older than now - cachedelay ( " . $nowgmt . " - " . $cachedelay . " ). Build is canceled " );
$buildfile = false ;
}
}
if ( $buildfile )
{
2011-06-30 09:49:26 +02:00
// Build event array
2011-11-01 13:22:39 +01:00
$eventarray = array ();
$sql = " SELECT a.id, " ;
$sql .= " a.datep, " ; // Start
$sql .= " a.datep2, " ; // End
2014-09-18 01:43:50 +02:00
$sql .= " a.durationp, " ; // deprecated
2011-11-01 13:22:39 +01:00
$sql .= " a.datec, a.tms as datem, " ;
2013-03-08 12:04:01 +01:00
$sql .= " a.label, a.code, a.note, a.fk_action as type_id, " ;
2011-11-01 13:22:39 +01:00
$sql .= " a.fk_soc, " ;
$sql .= " a.fk_user_author, a.fk_user_mod, " ;
2015-01-15 02:32:15 +01:00
$sql .= " a.fk_user_action, " ;
2011-11-01 13:22:39 +01:00
$sql .= " a.fk_contact, a.percent as percentage, " ;
$sql .= " a.fk_element, a.elementtype, " ;
2014-09-28 14:18:04 +02:00
$sql .= " a.priority, a.fulldayevent, a.location, a.punctual, a.transparency, " ;
2013-02-23 17:40:28 +01:00
$sql .= " u.firstname, u.lastname, " ;
2011-11-01 13:22:39 +01:00
$sql .= " s.nom as socname, " ;
$sql .= " c.id as type_id, c.code as type_code, c.libelle " ;
$sql .= " FROM ( " . MAIN_DB_PREFIX . " c_actioncomm as c, " . MAIN_DB_PREFIX . " actioncomm as a) " ;
2015-01-15 02:32:15 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " user as u on u.rowid = a.fk_user_author " ; // Link to get author of event for export
2012-02-01 11:32:55 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s on s.rowid = a.fk_soc " ;
2015-01-15 02:32:15 +01:00
// We must filter on assignement table
2017-07-04 10:29:38 +02:00
if ( $filters [ 'logint' ]) $sql .= " , " . MAIN_DB_PREFIX . " actioncomm_resources as ar " ;
2015-01-15 02:32:15 +01:00
$sql .= " WHERE a.fk_action=c.id " ;
2017-05-30 18:50:54 +02:00
$sql .= " AND a.entity IN ( " . getEntity ( 'agenda' ) . " ) " ;
2011-11-01 13:22:39 +01:00
foreach ( $filters as $key => $value )
{
2013-11-23 19:28:41 +01:00
if ( $key == 'notolderthan' && $value != '' ) $sql .= " AND a.datep >= ' " . $this -> db -> idate ( $now - ( $value * 24 * 60 * 60 )) . " ' " ;
2011-11-01 13:22:39 +01:00
if ( $key == 'year' ) $sql .= " AND a.datep BETWEEN ' " . $this -> db -> idate ( dol_get_first_day ( $value , 1 )) . " ' AND ' " . $this -> db -> idate ( dol_get_last_day ( $value , 12 )) . " ' " ;
if ( $key == 'id' ) $sql .= " AND a.id= " . ( is_numeric ( $value ) ? $value : 0 );
2010-08-19 21:30:17 +02:00
if ( $key == 'idfrom' ) $sql .= " AND a.id >= " . ( is_numeric ( $value ) ? $value : 0 );
if ( $key == 'idto' ) $sql .= " AND a.id <= " . ( is_numeric ( $value ) ? $value : 0 );
2014-02-07 18:08:25 +01:00
if ( $key == 'project' ) $sql .= " AND a.fk_project= " . ( is_numeric ( $value ) ? $value : 0 );
2018-02-28 20:06:28 +01:00
if ( $key == 'actiontype' ) $sql .= " AND c.type = ' " . $this -> db -> escape ( $value ) . " ' " ;
if ( $key == 'notactiontype' ) $sql .= " AND c.type <> ' " . $this -> db -> escape ( $value ) . " ' " ;
// We must filter on assignement table
2017-07-04 10:29:38 +02:00
if ( $key == 'logint' ) $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user' " ;
2011-11-01 13:22:39 +01:00
if ( $key == 'logina' )
{
$logina = $value ;
2017-07-04 10:29:38 +02:00
$condition = '=' ;
if ( preg_match ( '/^!/' , $logina ))
{
$logina = preg_replace ( '/^!/' , '' , $logina );
$condition = '<>' ;
}
2011-11-01 13:22:39 +01:00
$userforfilter = new User ( $this -> db );
2017-07-04 10:29:38 +02:00
$result = $userforfilter -> fetch ( '' , $logina );
if ( $result > 0 ) $sql .= " AND a.fk_user_author " . $condition . " " . $userforfilter -> id ;
elseif ( $result < 0 || $condition == '=' ) $sql .= " AND a.fk_user_author = 0 " ;
2011-11-01 13:22:39 +01:00
}
2017-07-04 10:29:38 +02:00
if ( $key == 'logint' )
2011-11-01 13:22:39 +01:00
{
$logint = $value ;
2017-07-04 10:29:38 +02:00
$condition = '=' ;
if ( preg_match ( '/^!/' , $logint ))
{
$logint = preg_replace ( '/^!/' , '' , $logint );
$condition = '<>' ;
}
2011-11-01 13:22:39 +01:00
$userforfilter = new User ( $this -> db );
2017-07-04 10:29:38 +02:00
$result = $userforfilter -> fetch ( '' , $logint );
if ( $result > 0 ) $sql .= " AND ar.fk_element = " . $userforfilter -> id ;
elseif ( $result < 0 || $condition == '=' ) $sql .= " AND ar.fk_element = 0 " ;
2011-11-01 13:22:39 +01:00
}
}
$sql .= " AND a.datep IS NOT NULL " ; // To exclude corrupted events and avoid errors in lightning/sunbird import
$sql .= " ORDER by datep " ;
//print $sql;exit;
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::build_exportfile select events " , LOG_DEBUG );
2011-11-01 13:22:39 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
// Note: Output of sql request is encoded in $conf->file->character_set_client
2013-11-07 20:51:30 +01:00
// This assignment in condition is not a bug. It allows walking the results.
2017-10-20 12:57:32 +02:00
$diff = 0 ;
2011-11-01 13:22:39 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql ))
{
$qualified = true ;
// 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
$event = array ();
$event [ 'uid' ] = 'dolibarragenda-' . $this -> db -> database_name . '-' . $obj -> id . " @ " . $_SERVER [ " SERVER_NAME " ];
$event [ 'type' ] = $type ;
2013-11-28 12:58:02 +01:00
$datestart = $this -> db -> jdate ( $obj -> datep ) - ( empty ( $conf -> global -> AGENDA_EXPORT_FIX_TZ ) ? 0 : ( $conf -> global -> AGENDA_EXPORT_FIX_TZ * 3600 ));
$dateend = $this -> db -> jdate ( $obj -> datep2 ) - ( empty ( $conf -> global -> AGENDA_EXPORT_FIX_TZ ) ? 0 : ( $conf -> global -> AGENDA_EXPORT_FIX_TZ * 3600 ));
2014-09-18 01:43:50 +02:00
$duration = ( $datestart && $dateend ) ? ( $dateend - $datestart ) : 0 ;
2011-12-07 18:10:24 +01:00
$event [ 'summary' ] = $obj -> label . ( $obj -> socname ? " ( " . $obj -> socname . " ) " : " " );
$event [ 'desc' ] = $obj -> note ;
2011-11-01 13:22:39 +01:00
$event [ 'startdate' ] = $datestart ;
$event [ 'enddate' ] = $dateend ; // Not required with type 'journal'
2014-09-18 01:43:50 +02:00
$event [ 'duration' ] = $duration ; // Not required with type 'journal'
2013-03-11 15:54:01 +01:00
$event [ 'author' ] = dolGetFirstLastname ( $obj -> firstname , $obj -> lastname );
2011-11-01 13:22:39 +01:00
$event [ 'priority' ] = $obj -> priority ;
2010-11-20 00:50:27 +01:00
$event [ 'fulldayevent' ] = $obj -> fulldayevent ;
2011-12-07 18:10:24 +01:00
$event [ 'location' ] = $obj -> location ;
2013-04-06 17:39:31 +02:00
$event [ 'transparency' ] = (( $obj -> transparency > 0 ) ? 'OPAQUE' : 'TRANSPARENT' ); // OPAQUE (busy) or TRANSPARENT (not busy)
2014-09-29 13:21:03 +02:00
$event [ 'punctual' ] = $obj -> punctual ;
2011-12-07 18:10:24 +01:00
$event [ 'category' ] = $obj -> libelle ; // libelle type action
2012-12-12 14:46:13 +01:00
// Define $urlwithroot
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2014-09-18 21:18:25 +02:00
$url = $urlwithroot . '/comm/action/card.php?id=' . $obj -> id ;
2011-11-01 13:22:39 +01:00
$event [ 'url' ] = $url ;
2013-11-28 12:58:02 +01:00
$event [ 'created' ] = $this -> db -> jdate ( $obj -> datec ) - ( empty ( $conf -> global -> AGENDA_EXPORT_FIX_TZ ) ? 0 : ( $conf -> global -> AGENDA_EXPORT_FIX_TZ * 3600 ));
$event [ 'modified' ] = $this -> db -> jdate ( $obj -> datem ) - ( empty ( $conf -> global -> AGENDA_EXPORT_FIX_TZ ) ? 0 : ( $conf -> global -> AGENDA_EXPORT_FIX_TZ * 3600 ));
2009-05-04 22:39:17 +02:00
2011-11-01 13:22:39 +01:00
if ( $qualified && $datestart )
{
2017-10-22 03:22:31 +02:00
$eventarray [] = $event ;
2011-11-01 13:22:39 +01:00
}
2017-10-20 12:57:32 +02:00
$diff ++ ;
2011-11-01 13:22:39 +01:00
}
}
else
{
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
$langs -> load ( " agenda " );
// Define title and desc
$more = '' ;
2011-12-07 18:10:24 +01:00
if ( $login ) $more = $langs -> transnoentities ( " User " ) . ' ' . $login ;
if ( $logina ) $more = $langs -> transnoentities ( " ActionsAskedBy " ) . ' ' . $logina ;
if ( $logint ) $more = $langs -> transnoentities ( " ActionsToDoBy " ) . ' ' . $logint ;
if ( $logind ) $more = $langs -> transnoentities ( " ActionsDoneBy " ) . ' ' . $logind ;
2011-11-01 13:22:39 +01:00
if ( $more )
{
2011-12-07 18:10:24 +01:00
$title = 'Dolibarr actions ' . $mysoc -> name . ' - ' . $more ;
2011-11-01 13:22:39 +01:00
$desc = $more ;
2011-12-07 18:10:24 +01:00
$desc .= ' (' . $mysoc -> name . ' - built by Dolibarr)' ;
2011-11-01 13:22:39 +01:00
}
else
{
2011-12-07 18:10:24 +01:00
$title = 'Dolibarr actions ' . $mysoc -> name ;
2011-11-01 13:22:39 +01:00
$desc = $langs -> transnoentities ( 'ListOfActions' );
2011-12-07 18:10:24 +01:00
$desc .= ' (' . $mysoc -> name . ' - built by Dolibarr)' ;
2011-11-01 13:22:39 +01:00
}
// Create temp file
2011-06-30 09:49:26 +02:00
$outputfiletmp = tempnam ( $conf -> agenda -> dir_temp , 'tmp' ); // Temporary file (allow call of function by different threads
@ chmod ( $outputfiletmp , octdec ( $conf -> global -> MAIN_UMASK ));
// Write file
2010-11-20 19:41:09 +01:00
if ( $format == 'vcal' ) $result = build_calfile ( $format , $title , $desc , $eventarray , $outputfiletmp );
2011-11-01 13:22:39 +01:00
if ( $format == 'ical' ) $result = build_calfile ( $format , $title , $desc , $eventarray , $outputfiletmp );
if ( $format == 'rss' ) $result = build_rssfile ( $format , $title , $desc , $eventarray , $outputfiletmp );
if ( $result >= 0 )
{
2013-11-28 12:58:02 +01:00
if ( dol_move ( $outputfiletmp , $outputfile , 0 , 1 )) $result = 1 ;
2011-11-01 13:22:39 +01:00
else
{
2013-11-28 12:58:02 +01:00
$this -> error = 'Failed to rename ' . $outputfiletmp . ' into ' . $outputfile ;
dol_syslog ( get_class ( $this ) . " ::build_exportfile " . $this -> error , LOG_ERR );
2011-06-30 09:49:26 +02:00
dol_delete_file ( $outputfiletmp , 0 , 1 );
2011-11-01 13:22:39 +01:00
$result =- 1 ;
}
}
else
{
2011-09-22 01:41:42 +02:00
dol_syslog ( get_class ( $this ) . " ::build_exportfile build_xxxfile function fails to for format= " . $format . " outputfiletmp= " . $outputfile , LOG_ERR );
2011-11-01 13:22:39 +01:00
dol_delete_file ( $outputfiletmp , 0 , 1 );
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( " ErrorFailToCreateFile " , $outputfile );
}
}
return $result ;
}
/**
* Initialise an instance with random values .
* Used to build previews or test instances .
* id must be 0 if object instance is a specimen .
*
* @ return void
*/
function initAsSpecimen ()
{
2015-02-10 11:38:13 +01:00
global $user ;
2011-11-01 13:22:39 +01:00
$now = dol_now ();
// Initialise parametres
$this -> id = 0 ;
$this -> specimen = 1 ;
$this -> type_code = 'AC_OTH' ;
2013-03-08 12:04:01 +01:00
$this -> code = 'AC_SPECIMEN_CODE' ;
2011-11-01 13:22:39 +01:00
$this -> label = 'Label of event Specimen' ;
$this -> datec = $now ;
$this -> datem = $now ;
$this -> datep = $now ;
$this -> datef = $now ;
$this -> author = $user ;
$this -> usermod = $user ;
2015-01-31 16:52:34 +01:00
$this -> usertodo = $user ;
2011-11-01 13:22:39 +01:00
$this -> fulldayevent = 0 ;
$this -> punctual = 0 ;
$this -> percentage = 0 ;
$this -> location = 'Location' ;
2014-09-29 13:21:03 +02:00
$this -> transparency = 1 ; // 1 means opaque
2014-02-06 17:09:41 +01:00
$this -> priority = 1 ;
2011-11-01 13:22:39 +01:00
$this -> note = 'Note' ;
2014-12-07 21:22:43 +01:00
$this -> userownerid = $user -> id ;
$this -> userassigned [ $user -> id ] = array ( 'id' => $user -> id , 'transparency' => 1 );
2011-11-01 13:22:39 +01:00
}
2011-11-01 04:58:47 +01:00
2015-04-18 18:11:01 +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 (
'actioncomm'
);
return CommonObject :: commonReplaceThirdparty ( $db , $origin_id , $dest_id , $tables );
}
2015-09-06 18:26:48 +02:00
/**
* Is the action delayed ?
*
* @ return bool
*/
public function hasDelay ()
{
global $conf ;
$now = dol_now ();
2015-12-14 09:14:34 +01:00
return $this -> datep && ( $this -> datep < ( $now - $conf -> agenda -> warning_delay ));
2015-09-06 18:26:48 +02:00
}
2017-08-03 11:42:22 +02:00
/**
* Send reminders by emails
* CAN BE A CRON TASK
*
* @ return int 0 if OK , <> 0 if KO ( this function is used also by cron so only 0 is OK )
*/
public function sendEmailsReminder ()
{
global $conf , $langs ;
2018-03-24 18:28:06 +01:00
$error = 0 ;
$this -> output = '' ;
2017-08-21 13:11:29 +02:00
$this -> error = '' ;
if ( empty ( $conf -> global -> AGENDA_REMINDER_EMAIL ))
{
2018-02-04 11:44:39 +01:00
$langs -> load ( " agenda " );
2017-08-21 13:11:29 +02:00
$this -> output = $langs -> trans ( 'EventRemindersByEmailNotEnabled' , $langs -> transnoentitiesnoconv ( " Agenda " ));
return 0 ;
}
2017-10-31 23:10:29 +01:00
$now = dol_now ();
2017-08-03 11:42:22 +02:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2018-03-24 18:28:06 +01:00
$this -> db -> begin ();
2017-10-31 23:10:29 +01:00
// TODO Scan events of type 'email' into table llx_actioncomm_reminder with status todo, send email, then set status to done
2017-08-03 11:42:22 +02:00
2017-10-31 23:10:29 +01:00
// Delete also very old past events (we do not keep more than 1 month record in past)
2017-11-03 17:24:14 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " actioncomm_reminder WHERE dateremind < ' " . $this -> db -> jdate ( $now - ( 3600 * 24 * 32 )) . " ' " ;
2017-10-31 23:10:29 +01:00
$this -> db -> query ( $sql );
2017-08-21 13:11:29 +02:00
2018-03-24 18:28:06 +01:00
$this -> db -> commit ();
return $error ;
2017-08-03 11:42:22 +02:00
}
2006-10-24 01:07:46 +02:00
}