Perf: Little optimization
This commit is contained in:
parent
ee92964ef7
commit
253a21eb33
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
|
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
|
||||||
@ -22,7 +23,7 @@
|
|||||||
* \ingroup projet
|
* \ingroup projet
|
||||||
* \brief Fichier de la classe de gestion des projets
|
* \brief Fichier de la classe de gestion des projets
|
||||||
*/
|
*/
|
||||||
require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
|
require_once(DOL_DOCUMENT_ROOT . "/core/class/commonobject.class.php");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class Project
|
* \class Project
|
||||||
@ -30,9 +31,9 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
|
|||||||
*/
|
*/
|
||||||
class Project extends CommonObject
|
class Project extends CommonObject
|
||||||
{
|
{
|
||||||
public $element='project'; //!< Id that identify managed objects
|
|
||||||
public $table_element='projet'; //!< Name of table without prefix where object is stored
|
|
||||||
|
|
||||||
|
public $element = 'project'; //!< Id that identify managed objects
|
||||||
|
public $table_element = 'projet'; //!< Name of table without prefix where object is stored
|
||||||
var $id;
|
var $id;
|
||||||
var $ref;
|
var $ref;
|
||||||
var $description;
|
var $description;
|
||||||
@ -47,7 +48,6 @@ class Project extends CommonObject
|
|||||||
var $public; //!< Tell if this is a public or private project
|
var $public; //!< Tell if this is a public or private project
|
||||||
var $note_private;
|
var $note_private;
|
||||||
var $note_public;
|
var $note_public;
|
||||||
|
|
||||||
var $statuts_short;
|
var $statuts_short;
|
||||||
var $statuts;
|
var $statuts;
|
||||||
|
|
||||||
@ -61,8 +61,8 @@ class Project extends CommonObject
|
|||||||
$this->db = $DB;
|
$this->db = $DB;
|
||||||
$this->societe = new Societe($DB);
|
$this->societe = new Societe($DB);
|
||||||
|
|
||||||
$this->statuts_short=array(0=>'Draft',1=>'Validated',2=>'Closed');
|
$this->statuts_short = array(0 => 'Draft', 1 => 'Validated', 2 => 'Closed');
|
||||||
$this->statuts=array(0=>'Draft',1=>'Validated',2=>'Closed');
|
$this->statuts = array(0 => 'Draft', 1 => 'Validated', 2 => 'Closed');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,20 +76,20 @@ class Project extends CommonObject
|
|||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$error=0;
|
$error = 0;
|
||||||
$ret=0;
|
$ret = 0;
|
||||||
|
|
||||||
// Check parameters
|
// Check parameters
|
||||||
if (! trim($this->ref))
|
if (!trim($this->ref))
|
||||||
{
|
{
|
||||||
$this->error='ErrorFieldsRequired';
|
$this->error = 'ErrorFieldsRequired';
|
||||||
dol_syslog("Project::Create error -1 ref null", LOG_ERR);
|
dol_syslog("Project::Create error -1 ref null", LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (";
|
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "projet (";
|
||||||
$sql.= "ref";
|
$sql.= "ref";
|
||||||
$sql.= ", title";
|
$sql.= ", title";
|
||||||
$sql.= ", description";
|
$sql.= ", description";
|
||||||
@ -101,50 +101,54 @@ class Project extends CommonObject
|
|||||||
$sql.= ", dateo";
|
$sql.= ", dateo";
|
||||||
$sql.= ", datee";
|
$sql.= ", datee";
|
||||||
$sql.= ") VALUES (";
|
$sql.= ") VALUES (";
|
||||||
$sql.= "'".$this->db->escape($this->ref)."'";
|
$sql.= "'" . $this->db->escape($this->ref) . "'";
|
||||||
$sql.= ", '".$this->db->escape($this->title)."'";
|
$sql.= ", '" . $this->db->escape($this->title) . "'";
|
||||||
$sql.= ", '".$this->db->escape($this->description)."'";
|
$sql.= ", '" . $this->db->escape($this->description) . "'";
|
||||||
$sql.= ", ".($this->socid > 0?$this->socid:"null");
|
$sql.= ", " . ($this->socid > 0 ? $this->socid : "null");
|
||||||
$sql.= ", ".$user->id;
|
$sql.= ", " . $user->id;
|
||||||
$sql.= ", 0";
|
$sql.= ", 0";
|
||||||
$sql.= ", ".($this->public?1:0);
|
$sql.= ", " . ($this->public ? 1 : 0);
|
||||||
$sql.= ", ".($this->datec!=''?$this->db->idate($this->datec):'null');
|
$sql.= ", " . ($this->datec != '' ? $this->db->idate($this->datec) : 'null');
|
||||||
$sql.= ", ".($this->dateo!=''?$this->db->idate($this->dateo):'null');
|
$sql.= ", " . ($this->dateo != '' ? $this->db->idate($this->dateo) : 'null');
|
||||||
$sql.= ", ".($this->datee!=''?$this->db->idate($this->datee):'null');
|
$sql.= ", " . ($this->datee != '' ? $this->db->idate($this->datee) : 'null');
|
||||||
$sql.= ")";
|
$sql.= ")";
|
||||||
|
|
||||||
dol_syslog("Project::create sql=".$sql,LOG_DEBUG);
|
dol_syslog("Project::create sql=" . $sql, LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "projet");
|
||||||
$ret = $this->id;
|
$ret = $this->id;
|
||||||
|
|
||||||
if (! $notrigger)
|
if (!$notrigger)
|
||||||
{
|
{
|
||||||
// Call triggers
|
// Call triggers
|
||||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||||
$interface=new Interfaces($this->db);
|
$interface = new Interfaces($this->db);
|
||||||
$result=$interface->run_triggers('PROJECT_CREATE',$this,$user,$langs,$conf);
|
$result = $interface->run_triggers('PROJECT_CREATE', $this, $user, $langs, $conf);
|
||||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
if ($result < 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
$this->errors = $interface->errors;
|
||||||
|
}
|
||||||
// End call triggers
|
// End call triggers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
$this->errno=$this->db->lasterrno();
|
$this->errno = $this->db->lasterrno();
|
||||||
dol_syslog("Project::Create error -2 ".$this->error, LOG_ERR);
|
dol_syslog("Project::Create error -2 " . $this->error, LOG_ERR);
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error && ! empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
|
if (!$error && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
|
||||||
{
|
{
|
||||||
$res=$this->setValid($user);
|
$res = $this->setValid($user);
|
||||||
if ($res < 0) $error++;
|
if ($res < 0) $error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (!$error)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $ret;
|
return $ret;
|
||||||
@ -156,7 +160,6 @@ class Project extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a project
|
* Update a project
|
||||||
*
|
*
|
||||||
@ -166,7 +169,7 @@ class Project extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function update($user, $notrigger=0)
|
function update($user, $notrigger=0)
|
||||||
{
|
{
|
||||||
global $langs,$conf;
|
global $langs, $conf;
|
||||||
|
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
$this->title = trim($this->title);
|
$this->title = trim($this->title);
|
||||||
@ -174,28 +177,32 @@ class Project extends CommonObject
|
|||||||
|
|
||||||
if (dol_strlen(trim($this->ref)) > 0)
|
if (dol_strlen(trim($this->ref)) > 0)
|
||||||
{
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."projet SET";
|
$sql = "UPDATE " . MAIN_DB_PREFIX . "projet SET";
|
||||||
$sql.= " ref='".$this->ref."'";
|
$sql.= " ref='" . $this->ref . "'";
|
||||||
$sql.= ", title = '".$this->db->escape($this->title)."'";
|
$sql.= ", title = '" . $this->db->escape($this->title) . "'";
|
||||||
$sql.= ", description = '".$this->db->escape($this->description)."'";
|
$sql.= ", description = '" . $this->db->escape($this->description) . "'";
|
||||||
$sql.= ", fk_soc = ".($this->socid > 0?$this->socid:"null");
|
$sql.= ", fk_soc = " . ($this->socid > 0 ? $this->socid : "null");
|
||||||
$sql.= ", fk_statut = ".$this->statut;
|
$sql.= ", fk_statut = " . $this->statut;
|
||||||
$sql.= ", public = ".($this->public?1:0);
|
$sql.= ", public = " . ($this->public ? 1 : 0);
|
||||||
$sql.= ", datec=".($this->date_c!=''?$this->db->idate($this->date_c):'null');
|
$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.= ", dateo=" . ($this->date_start != '' ? $this->db->idate($this->date_start) : 'null');
|
||||||
$sql.= ", datee=".($this->date_end!=''?$this->db->idate($this->date_end):'null');
|
$sql.= ", datee=" . ($this->date_end != '' ? $this->db->idate($this->date_end) : 'null');
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = " . $this->id;
|
||||||
|
|
||||||
dol_syslog("Project::Update sql=".$sql,LOG_DEBUG);
|
dol_syslog("Project::Update sql=" . $sql, LOG_DEBUG);
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql))
|
||||||
{
|
{
|
||||||
if (! $notrigger)
|
if (!$notrigger)
|
||||||
{
|
{
|
||||||
// Call triggers
|
// Call triggers
|
||||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||||
$interface=new Interfaces($this->db);
|
$interface = new Interfaces($this->db);
|
||||||
$result=$interface->run_triggers('PROJECT_MODIFY',$this,$user,$langs,$conf);
|
$result = $interface->run_triggers('PROJECT_MODIFY', $this, $user, $langs, $conf);
|
||||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
if ($result < 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
$this->errors = $interface->errors;
|
||||||
|
}
|
||||||
// End call triggers
|
// End call triggers
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,8 +210,8 @@ class Project extends CommonObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
dol_syslog("Project::Update error -2 ".$this->error, LOG_ERR);
|
dol_syslog("Project::Update error -2 " . $this->error, LOG_ERR);
|
||||||
$result = -2;
|
$result = -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,7 +224,6 @@ class Project extends CommonObject
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get object and lines from database
|
* Get object and lines from database
|
||||||
*
|
*
|
||||||
@ -225,17 +231,17 @@ class Project extends CommonObject
|
|||||||
* @param string $ref Ref of project
|
* @param string $ref Ref of project
|
||||||
* @return int >0 if OK, 0 if not found, <0 if KO
|
* @return int >0 if OK, 0 if not found, <0 if KO
|
||||||
*/
|
*/
|
||||||
function fetch($id,$ref='')
|
function fetch($id, $ref='')
|
||||||
{
|
{
|
||||||
if (empty($id) && empty($ref)) return -1;
|
if (empty($id) && empty($ref)) return -1;
|
||||||
|
|
||||||
$sql = "SELECT rowid, ref, title, description, public, datec";
|
$sql = "SELECT rowid, ref, title, description, public, datec";
|
||||||
$sql.= ", tms, dateo, datee, fk_soc, fk_user_creat, fk_statut, note_private, note_public";
|
$sql.= ", tms, dateo, datee, fk_soc, fk_user_creat, fk_statut, note_private, note_public";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."projet";
|
$sql.= " FROM " . MAIN_DB_PREFIX . "projet";
|
||||||
if ($ref) $sql.= " WHERE ref='".$ref."'";
|
if ($ref) $sql.= " WHERE ref='" . $ref . "'";
|
||||||
else $sql.= " WHERE rowid=".$id;
|
else $sql.= " WHERE rowid=" . $id;
|
||||||
|
|
||||||
dol_syslog("Project::fetch sql=".$sql, LOG_DEBUG);
|
dol_syslog("Project::fetch sql=" . $sql, LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
@ -273,8 +279,8 @@ class Project extends CommonObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
dol_syslog("Project::fetch ".$this->error, LOG_ERR);
|
dol_syslog("Project::fetch " . $this->error, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,11 +298,11 @@ class Project extends CommonObject
|
|||||||
$projects = array();
|
$projects = array();
|
||||||
|
|
||||||
$sql = "SELECT rowid, title";
|
$sql = "SELECT rowid, title";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."projet";
|
$sql.= " FROM " . MAIN_DB_PREFIX . "projet";
|
||||||
$sql.= " WHERE entity = ".$conf->entity;
|
$sql.= " WHERE entity = " . $conf->entity;
|
||||||
if (! empty($socid)) $sql.= " AND fk_soc = ".$socid;
|
if (! empty($socid)) $sql.= " AND fk_soc = " . $socid;
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$nump = $this->db->num_rows($resql);
|
$nump = $this->db->num_rows($resql);
|
||||||
@ -318,7 +324,6 @@ class Project extends CommonObject
|
|||||||
{
|
{
|
||||||
print $this->db->lasterror();
|
print $this->db->lasterror();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -331,22 +336,32 @@ class Project extends CommonObject
|
|||||||
{
|
{
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
$sql='';
|
$sql = '';
|
||||||
if ($type == 'propal') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE fk_projet=".$this->id;
|
if ($type == 'propal')
|
||||||
if ($type == 'order') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande WHERE fk_projet=".$this->id;
|
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "propal WHERE fk_projet=" . $this->id;
|
||||||
if ($type == 'invoice') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE fk_projet=".$this->id;
|
if ($type == 'order')
|
||||||
if ($type == 'invoice_predefined') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture_rec WHERE fk_projet=".$this->id;
|
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "commande WHERE fk_projet=" . $this->id;
|
||||||
if ($type == 'order_supplier') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE fk_projet=".$this->id;
|
if ($type == 'invoice')
|
||||||
if ($type == 'invoice_supplier') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture_fourn WHERE fk_projet=".$this->id;
|
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture WHERE fk_projet=" . $this->id;
|
||||||
if ($type == 'contract') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."contrat WHERE fk_projet=".$this->id;
|
if ($type == 'invoice_predefined')
|
||||||
if ($type == 'intervention') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."fichinter WHERE fk_projet=".$this->id;
|
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture_rec WHERE fk_projet=" . $this->id;
|
||||||
if ($type == 'trip') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."deplacement WHERE fk_projet=".$this->id;
|
if ($type == 'order_supplier')
|
||||||
if ($type == 'agenda') $sql = "SELECT id as rowid FROM ".MAIN_DB_PREFIX."actioncomm WHERE fk_project=".$this->id;
|
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "commande_fournisseur WHERE fk_projet=" . $this->id;
|
||||||
|
if ($type == 'invoice_supplier')
|
||||||
|
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture_fourn WHERE fk_projet=" . $this->id;
|
||||||
|
if ($type == 'contract')
|
||||||
|
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "contrat WHERE fk_projet=" . $this->id;
|
||||||
|
if ($type == 'intervention')
|
||||||
|
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "fichinter WHERE fk_projet=" . $this->id;
|
||||||
|
if ($type == 'trip')
|
||||||
|
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "deplacement WHERE fk_projet=" . $this->id;
|
||||||
|
if ($type == 'agenda')
|
||||||
|
$sql = "SELECT id as rowid FROM " . MAIN_DB_PREFIX . "actioncomm WHERE fk_project=" . $this->id;
|
||||||
if (! $sql) return -1;
|
if (! $sql) return -1;
|
||||||
|
|
||||||
//print $sql;
|
//print $sql;
|
||||||
dol_syslog("Project::get_element_list sql=".$sql);
|
dol_syslog("Project::get_element_list sql=" . $sql);
|
||||||
$result=$this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$nump = $this->db->num_rows($result);
|
$nump = $this->db->num_rows($result);
|
||||||
@ -382,36 +397,36 @@ class Project extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function delete($user, $notrigger=0)
|
function delete($user, $notrigger=0)
|
||||||
{
|
{
|
||||||
global $langs,$conf;
|
global $langs, $conf;
|
||||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
require_once(DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php");
|
||||||
|
|
||||||
$error=0;
|
$error = 0;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
if (! $error)
|
if (!$error)
|
||||||
{
|
{
|
||||||
// Delete linked contacts
|
// Delete linked contacts
|
||||||
$res = $this->delete_linked_contact();
|
$res = $this->delete_linked_contact();
|
||||||
if ($res < 0)
|
if ($res < 0)
|
||||||
{
|
{
|
||||||
$this->error='ErrorFailToDeleteLinkedContact';
|
$this->error = 'ErrorFailToDeleteLinkedContact';
|
||||||
//$error++;
|
//$error++;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task";
|
$sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_task";
|
||||||
$sql.= " WHERE fk_projet=".$this->id;
|
$sql.= " WHERE fk_projet=" . $this->id;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
|
dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."projet";
|
$sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet";
|
||||||
$sql.= " WHERE rowid=".$this->id;
|
$sql.= " WHERE rowid=" . $this->id;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
|
dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
@ -419,7 +434,7 @@ class Project extends CommonObject
|
|||||||
$projectref = dol_sanitizeFileName($this->ref);
|
$projectref = dol_sanitizeFileName($this->ref);
|
||||||
if ($conf->projet->dir_output)
|
if ($conf->projet->dir_output)
|
||||||
{
|
{
|
||||||
$dir = $conf->projet->dir_output . "/" . $projectref ;
|
$dir = $conf->projet->dir_output . "/" . $projectref;
|
||||||
$file = $conf->projet->dir_output . "/" . $projectref . "/" . $projectref . ".pdf";
|
$file = $conf->projet->dir_output . "/" . $projectref . "/" . $projectref . ".pdf";
|
||||||
if (file_exists($file))
|
if (file_exists($file))
|
||||||
{
|
{
|
||||||
@ -427,41 +442,45 @@ class Project extends CommonObject
|
|||||||
|
|
||||||
if (!dol_delete_file($file))
|
if (!dol_delete_file($file))
|
||||||
{
|
{
|
||||||
$this->error='ErrorFailToDeleteFile';
|
$this->error = 'ErrorFailToDeleteFile';
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file_exists($dir))
|
if (file_exists($dir))
|
||||||
{
|
{
|
||||||
$res=@dol_delete_dir($dir);
|
$res = @dol_delete_dir($dir);
|
||||||
if (! $res)
|
if (!$res)
|
||||||
{
|
{
|
||||||
$this->error='ErrorFailToDeleteDir';
|
$this->error = 'ErrorFailToDeleteDir';
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $notrigger)
|
if (!$notrigger)
|
||||||
{
|
{
|
||||||
// Call triggers
|
// Call triggers
|
||||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||||
$interface=new Interfaces($this->db);
|
$interface = new Interfaces($this->db);
|
||||||
$result=$interface->run_triggers('PROJECT_DELETE',$this,$user,$langs,$conf);
|
$result = $interface->run_triggers('PROJECT_DELETE', $this, $user, $langs, $conf);
|
||||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
if ($result < 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
$this->errors = $interface->errors;
|
||||||
|
}
|
||||||
// End call triggers
|
// End call triggers
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_syslog("Project::delete sql=".$sql, LOG_DEBUG);
|
dol_syslog("Project::delete sql=" . $sql, LOG_DEBUG);
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
dol_syslog("Project::delete ".$this->error, LOG_ERR);
|
dol_syslog("Project::delete " . $this->error, LOG_ERR);
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -481,23 +500,27 @@ class Project extends CommonObject
|
|||||||
{
|
{
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."projet";
|
$sql = "UPDATE " . MAIN_DB_PREFIX . "projet";
|
||||||
$sql.= " SET fk_statut = 1";
|
$sql.= " SET fk_statut = 1";
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = " . $this->id;
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
$sql.= " AND entity = " . $conf->entity;
|
||||||
|
|
||||||
dol_syslog("Project::setValid sql=".$sql);
|
dol_syslog("Project::setValid sql=" . $sql);
|
||||||
$resql=$this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
// Appel des triggers
|
// Appel des triggers
|
||||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||||
$interface=new Interfaces($this->db);
|
$interface = new Interfaces($this->db);
|
||||||
$result=$interface->run_triggers('PROJECT_VALIDATE',$this,$user,$langs,$conf);
|
$result = $interface->run_triggers('PROJECT_VALIDATE', $this, $user, $langs, $conf);
|
||||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
if ($result < 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
$this->errors = $interface->errors;
|
||||||
|
}
|
||||||
// Fin appel triggers
|
// Fin appel triggers
|
||||||
|
|
||||||
if (! $error)
|
if (!$error)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
@ -505,16 +528,16 @@ class Project extends CommonObject
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
$this->error=join(',',$this->errors);
|
$this->error = join(',', $this->errors);
|
||||||
dol_syslog("Project::setValid ".$this->error,LOG_ERR);
|
dol_syslog("Project::setValid " . $this->error, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
$this->error=$this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
dol_syslog("Project::setValid ".$this->error,LOG_ERR);
|
dol_syslog("Project::setValid " . $this->error, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -534,24 +557,28 @@ class Project extends CommonObject
|
|||||||
{
|
{
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."projet";
|
$sql = "UPDATE " . MAIN_DB_PREFIX . "projet";
|
||||||
$sql.= " SET fk_statut = 2";
|
$sql.= " SET fk_statut = 2";
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = " . $this->id;
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
$sql.= " AND entity = " . $conf->entity;
|
||||||
$sql.= " AND fk_statut = 1";
|
$sql.= " AND fk_statut = 1";
|
||||||
|
|
||||||
dol_syslog("Project::setClose sql=".$sql);
|
dol_syslog("Project::setClose sql=" . $sql);
|
||||||
$resql=$this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
// Appel des triggers
|
// Appel des triggers
|
||||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||||
$interface=new Interfaces($this->db);
|
$interface = new Interfaces($this->db);
|
||||||
$result=$interface->run_triggers('PROJECT_CLOSE',$this,$user,$langs,$conf);
|
$result = $interface->run_triggers('PROJECT_CLOSE', $this, $user, $langs, $conf);
|
||||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
if ($result < 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
$this->errors = $interface->errors;
|
||||||
|
}
|
||||||
// Fin appel triggers
|
// Fin appel triggers
|
||||||
|
|
||||||
if (! $error)
|
if (!$error)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
@ -559,16 +586,16 @@ class Project extends CommonObject
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
$this->error=join(',',$this->errors);
|
$this->error = join(',', $this->errors);
|
||||||
dol_syslog("Project::setClose ".$this->error,LOG_ERR);
|
dol_syslog("Project::setClose " . $this->error, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
$this->error=$this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
dol_syslog("Project::setClose ".$this->error,LOG_ERR);
|
dol_syslog("Project::setClose " . $this->error, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -582,7 +609,7 @@ class Project extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function getLibStatut($mode=0)
|
function getLibStatut($mode=0)
|
||||||
{
|
{
|
||||||
return $this->LibStatut($this->statut,$mode);
|
return $this->LibStatut($this->statut, $mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -592,7 +619,7 @@ class Project extends CommonObject
|
|||||||
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
|
* @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
|
* @return string Label
|
||||||
*/
|
*/
|
||||||
function LibStatut($statut,$mode=0)
|
function LibStatut($statut, $mode=0)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
@ -606,27 +633,39 @@ class Project extends CommonObject
|
|||||||
}
|
}
|
||||||
if ($mode == 2)
|
if ($mode == 2)
|
||||||
{
|
{
|
||||||
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]);
|
if ($statut == 0)
|
||||||
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]);
|
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut0') . ' ' . $langs->trans($this->statuts_short[$statut]);
|
||||||
if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]);
|
if ($statut == 1)
|
||||||
|
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4') . ' ' . $langs->trans($this->statuts_short[$statut]);
|
||||||
|
if ($statut == 2)
|
||||||
|
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut6') . ' ' . $langs->trans($this->statuts_short[$statut]);
|
||||||
}
|
}
|
||||||
if ($mode == 3)
|
if ($mode == 3)
|
||||||
{
|
{
|
||||||
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0');
|
if ($statut == 0)
|
||||||
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
|
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut0');
|
||||||
if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
|
if ($statut == 1)
|
||||||
|
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4');
|
||||||
|
if ($statut == 2)
|
||||||
|
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut6');
|
||||||
}
|
}
|
||||||
if ($mode == 4)
|
if ($mode == 4)
|
||||||
{
|
{
|
||||||
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]);
|
if ($statut == 0)
|
||||||
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]);
|
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut0') . ' ' . $langs->trans($this->statuts_short[$statut]);
|
||||||
if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]);
|
if ($statut == 1)
|
||||||
|
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4') . ' ' . $langs->trans($this->statuts_short[$statut]);
|
||||||
|
if ($statut == 2)
|
||||||
|
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut6') . ' ' . $langs->trans($this->statuts_short[$statut]);
|
||||||
}
|
}
|
||||||
if ($mode == 5)
|
if ($mode == 5)
|
||||||
{
|
{
|
||||||
if ($statut==0) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut0');
|
if ($statut == 0)
|
||||||
if ($statut==1) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut1');
|
return $langs->trans($this->statuts_short[$statut]) . ' ' . img_picto($langs->trans($this->statuts_short[$statut]), 'statut0');
|
||||||
if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]);
|
if ($statut == 1)
|
||||||
|
return $langs->trans($this->statuts_short[$statut]) . ' ' . img_picto($langs->trans($this->statuts_short[$statut]), 'statut1');
|
||||||
|
if ($statut == 2)
|
||||||
|
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut6') . ' ' . $langs->trans($this->statuts_short[$statut]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,28 +677,28 @@ class Project extends CommonObject
|
|||||||
* @param int $addlabel 0=Default, 1=Add label into string
|
* @param int $addlabel 0=Default, 1=Add label into string
|
||||||
* @return string Chaine avec URL
|
* @return string Chaine avec URL
|
||||||
*/
|
*/
|
||||||
function getNomUrl($withpicto=0,$option='',$addlabel=0)
|
function getNomUrl($withpicto=0, $option='', $addlabel=0)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
$result='';
|
$result = '';
|
||||||
$lien='';
|
$lien = '';
|
||||||
$lienfin='';
|
$lienfin = '';
|
||||||
|
|
||||||
if ($option != 'nolink')
|
if ($option != 'nolink')
|
||||||
{
|
{
|
||||||
$lien = '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$this->id.'">';
|
$lien = '<a href="' . DOL_URL_ROOT . '/projet/fiche.php?id=' . $this->id . '">';
|
||||||
$lienfin='</a>';
|
$lienfin = '</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$picto='projectpub';
|
$picto = 'projectpub';
|
||||||
if (! $this->public) $picto='project';
|
if (!$this->public) $picto = 'project';
|
||||||
|
|
||||||
$label=$langs->trans("ShowProject").': '.$this->ref.($this->title?' - '.$this->title:'');
|
$label = $langs->trans("ShowProject") . ': ' . $this->ref . ($this->title ? ' - ' . $this->title : '');
|
||||||
|
|
||||||
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
|
if ($withpicto) $result.=($lien . img_object($label, $picto) . $lienfin);
|
||||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||||
if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin.(($addlabel && $this->title)?' - '.$this->title:'');
|
if ($withpicto != 2) $result.=$lien . $this->ref . $lienfin . (($addlabel && $this->title) ? ' - ' . $this->title : '');
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -672,17 +711,17 @@ class Project extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function initAsSpecimen()
|
function initAsSpecimen()
|
||||||
{
|
{
|
||||||
global $user,$langs,$conf;
|
global $user, $langs, $conf;
|
||||||
|
|
||||||
$now=mktime();
|
$now = mktime();
|
||||||
|
|
||||||
// Charge tableau des id de societe socids
|
// Charge tableau des id de societe socids
|
||||||
$socids = array();
|
$socids = array();
|
||||||
|
|
||||||
$sql = "SELECT rowid";
|
$sql = "SELECT rowid";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe";
|
$sql.= " FROM " . MAIN_DB_PREFIX . "societe";
|
||||||
$sql.= " WHERE client IN (1, 3)";
|
$sql.= " WHERE client IN (1, 3)";
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
$sql.= " AND entity = " . $conf->entity;
|
||||||
$sql.= " LIMIT 10";
|
$sql.= " LIMIT 10";
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
@ -703,9 +742,9 @@ class Project extends CommonObject
|
|||||||
$prodids = array();
|
$prodids = array();
|
||||||
|
|
||||||
$sql = "SELECT rowid";
|
$sql = "SELECT rowid";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product";
|
$sql.= " FROM " . MAIN_DB_PREFIX . "product";
|
||||||
$sql.= " WHERE tosell = 1";
|
$sql.= " WHERE tosell = 1";
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
$sql.= " AND entity = " . $conf->entity;
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
@ -721,24 +760,24 @@ class Project extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialise parametres
|
// Initialise parametres
|
||||||
$this->id=0;
|
$this->id = 0;
|
||||||
$this->ref = 'SPECIMEN';
|
$this->ref = 'SPECIMEN';
|
||||||
$this->specimen=1;
|
$this->specimen = 1;
|
||||||
$socid = rand(1, $num_socs);
|
$socid = rand(1, $num_socs);
|
||||||
$this->socid = $socids[$socid];
|
$this->socid = $socids[$socid];
|
||||||
$this->date_c = $now;
|
$this->date_c = $now;
|
||||||
$this->date_m = $now;
|
$this->date_m = $now;
|
||||||
$this->date_start = $now;
|
$this->date_start = $now;
|
||||||
$this->note_public='SPECIMEN';
|
$this->note_public = 'SPECIMEN';
|
||||||
$nbp = rand(1, 9);
|
$nbp = rand(1, 9);
|
||||||
$xnbp = 0;
|
$xnbp = 0;
|
||||||
while ($xnbp < $nbp)
|
while ($xnbp < $nbp)
|
||||||
{
|
{
|
||||||
$line=new Task($this->db);
|
$line = new Task($this->db);
|
||||||
$line->desc=$langs->trans("Description")." ".$xnbp;
|
$line->desc = $langs->trans("Description") . " " . $xnbp;
|
||||||
$line->qty=1;
|
$line->qty = 1;
|
||||||
$prodid = rand(1, $num_prods);
|
$prodid = rand(1, $num_prods);
|
||||||
$line->fk_product=$prodids[$prodid];
|
$line->fk_product = $prodids[$prodid];
|
||||||
$xnbp++;
|
$xnbp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -750,7 +789,7 @@ class Project extends CommonObject
|
|||||||
* @param int $noprint 0=Print forbidden message if no permission, 1=Return -1 if no permission
|
* @param int $noprint 0=Print forbidden message if no permission, 1=Return -1 if no permission
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function restrictedProjectArea($user,$noprint=0)
|
function restrictedProjectArea($user, $noprint=0)
|
||||||
{
|
{
|
||||||
// To verify role of users
|
// To verify role of users
|
||||||
$userAccess = 0;
|
$userAccess = 0;
|
||||||
@ -764,15 +803,15 @@ class Project extends CommonObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach(array('internal','external') as $source)
|
foreach (array('internal', 'external') as $source)
|
||||||
{
|
{
|
||||||
$userRole = $this->liste_contact(4,$source);
|
$userRole = $this->liste_contact(4, $source);
|
||||||
$num=count($userRole);
|
$num = count($userRole);
|
||||||
|
|
||||||
$nblinks = 0;
|
$nblinks = 0;
|
||||||
while ($nblinks < $num)
|
while ($nblinks < $num)
|
||||||
{
|
{
|
||||||
if (preg_match('/PROJECT/',$userRole[$nblinks]['code']) && $user->id == $userRole[$nblinks]['id'])
|
if (preg_match('/PROJECT/', $userRole[$nblinks]['code']) && $user->id == $userRole[$nblinks]['id'])
|
||||||
{
|
{
|
||||||
$userAccess++;
|
$userAccess++;
|
||||||
}
|
}
|
||||||
@ -788,17 +827,16 @@ class Project extends CommonObject
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $userAccess)
|
if (!$userAccess)
|
||||||
{
|
{
|
||||||
if (!$noprint)
|
if (!$noprint)
|
||||||
{
|
{
|
||||||
accessforbidden('',0);
|
accessforbidden('', 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $userAccess;
|
return $userAccess;
|
||||||
@ -813,7 +851,7 @@ class Project extends CommonObject
|
|||||||
* @param int $socid 0=No filter on third party, id of third party
|
* @param int $socid 0=No filter on third party, id of third party
|
||||||
* @return array Array of projects
|
* @return array Array of projects
|
||||||
*/
|
*/
|
||||||
function getProjectsAuthorizedForUser($user,$mode=0,$list=0,$socid=0)
|
function getProjectsAuthorizedForUser($user, $mode=0, $list=0, $socid=0)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
@ -821,32 +859,33 @@ class Project extends CommonObject
|
|||||||
$temp = array();
|
$temp = array();
|
||||||
|
|
||||||
$sql = "SELECT DISTINCT p.rowid, p.ref";
|
$sql = "SELECT DISTINCT p.rowid, p.ref";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
|
$sql.= " FROM " . MAIN_DB_PREFIX . "projet as p";
|
||||||
if ($mode == 0 || $mode == 1)
|
if ($mode == 0 || $mode == 1)
|
||||||
{
|
{
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
|
$sql.= ", " . MAIN_DB_PREFIX . "element_contact as ec";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
|
$sql.= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc";
|
||||||
}
|
}
|
||||||
$sql.= " WHERE p.entity = ".$conf->entity;
|
$sql.= " WHERE p.entity = " . $conf->entity;
|
||||||
|
|
||||||
// Internal users must see project he is contact to even if project linked to a third party he can't see.
|
// Internal users must see project he is contact to even if project linked to a third party he can't see.
|
||||||
//if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
|
//if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
|
||||||
if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
|
if ($socid)
|
||||||
|
$sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")";
|
||||||
|
|
||||||
if ($mode == 0)
|
if ($mode == 0)
|
||||||
{
|
{
|
||||||
$sql.= " AND ( p.public = 1";
|
$sql.= " AND ec.element_id = p.rowid AND ( p.public = 1";
|
||||||
//$sql.= " OR p.fk_user_creat = ".$user->id;
|
//$sql.= " OR p.fk_user_creat = ".$user->id;
|
||||||
$sql.= " OR ( ec.element_id = p.rowid";
|
$sql.= " OR ( ctc.rowid = ec.fk_c_type_contact";
|
||||||
$sql.= " AND ctc.rowid = ec.fk_c_type_contact";
|
$sql.= " AND ctc.element = '" . $this->element . "'";
|
||||||
$sql.= " AND ctc.element = '".$this->element."'";
|
$sql.= " AND ec.fk_socpeople = " . $user->id . " ) )";
|
||||||
$sql.= " AND ec.fk_socpeople = ".$user->id." ) )";
|
|
||||||
}
|
}
|
||||||
if ($mode == 1)
|
if ($mode == 1)
|
||||||
{
|
{
|
||||||
$sql.= " AND ec.element_id = p.rowid";
|
$sql.= " AND ec.element_id = p.rowid";
|
||||||
$sql.= " AND ctc.rowid = ec.fk_c_type_contact";
|
$sql.= " AND ctc.rowid = ec.fk_c_type_contact";
|
||||||
$sql.= " AND ctc.element = '".$this->element."'";
|
$sql.= " AND ctc.element = '" . $this->element . "'";
|
||||||
$sql.= " AND ec.fk_socpeople = ".$user->id;
|
$sql.= " AND ec.fk_socpeople = " . $user->id;
|
||||||
}
|
}
|
||||||
if ($mode == 2)
|
if ($mode == 2)
|
||||||
{
|
{
|
||||||
@ -872,7 +911,7 @@ class Project extends CommonObject
|
|||||||
if ($list)
|
if ($list)
|
||||||
{
|
{
|
||||||
if (empty($temp)) return 0;
|
if (empty($temp)) return 0;
|
||||||
$result = implode(',',$temp);
|
$result = implode(',', $temp);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -885,4 +924,5 @@ class Project extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user