2004-10-20 23:06:45 +02:00
|
|
|
|
<?php
|
2005-04-05 13:52:30 +02:00
|
|
|
|
/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2008-03-02 23:20:44 +01:00
|
|
|
|
* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
2007-11-01 21:39:36 +01:00
|
|
|
|
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
|
2002-05-11 20:53:13 +02:00
|
|
|
|
*
|
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2005-08-14 03:38:12 +02:00
|
|
|
|
/**
|
2006-09-23 02:27:47 +02:00
|
|
|
|
\file htdocs/project.class.php
|
|
|
|
|
|
\ingroup projet
|
|
|
|
|
|
\brief Fichier de la classe de gestion des projets
|
2008-03-02 23:20:44 +01:00
|
|
|
|
\version $Id$
|
2005-01-23 03:14:56 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2007-05-28 13:30:44 +02:00
|
|
|
|
require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php");
|
|
|
|
|
|
|
2005-08-14 03:38:12 +02:00
|
|
|
|
/**
|
2006-06-23 21:40:28 +02:00
|
|
|
|
\class Project
|
|
|
|
|
|
\brief Classe permettant la gestion des projets
|
2005-01-23 03:14:56 +01:00
|
|
|
|
*/
|
2007-05-28 13:30:44 +02:00
|
|
|
|
class Project extends CommonObject
|
2006-06-23 21:40:28 +02:00
|
|
|
|
{
|
2006-09-23 02:27:47 +02:00
|
|
|
|
var $id;
|
|
|
|
|
|
var $db;
|
|
|
|
|
|
var $ref;
|
|
|
|
|
|
var $title;
|
|
|
|
|
|
var $socid;
|
2007-05-28 13:30:44 +02:00
|
|
|
|
var $user_resp_id;
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Constructeur de la classe
|
2008-03-17 05:10:35 +01:00
|
|
|
|
* \param DB handler acc<EFBFBD>s base de donn<EFBFBD>es
|
2006-09-23 02:27:47 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function Project($DB)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->db = $DB;
|
|
|
|
|
|
$this->societe = new Societe($DB);
|
|
|
|
|
|
}
|
2005-06-27 23:47:44 +02:00
|
|
|
|
|
2006-09-23 02:27:47 +02:00
|
|
|
|
/*
|
2008-03-17 05:10:35 +01:00
|
|
|
|
* \brief Cree un projet en base
|
|
|
|
|
|
* \param user Id utilisateur qui cree
|
|
|
|
|
|
* \return int <0 si ko, id du projet cree si ok
|
2006-09-23 02:27:47 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function create($user)
|
2002-12-22 21:04:24 +01:00
|
|
|
|
{
|
2008-03-17 05:10:35 +01:00
|
|
|
|
// Check parameters
|
|
|
|
|
|
if (! trim($this->ref))
|
2002-12-22 21:04:24 +01:00
|
|
|
|
{
|
2008-03-17 05:10:35 +01:00
|
|
|
|
$this->error='ErrorFieldsRequired';
|
|
|
|
|
|
dolibarr_syslog("Project::Create error -1 ref null");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2002-05-11 20:53:13 +02:00
|
|
|
|
|
2008-03-31 07:01:39 +02:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, fk_user_resp, dateo, fk_statut)";
|
2008-03-17 05:10:35 +01:00
|
|
|
|
$sql.= " VALUES ('".addslashes($this->ref)."', '".addslashes($this->title)."',";
|
|
|
|
|
|
$sql.= " ".($this->socid > 0?$this->socid:"null").",";
|
|
|
|
|
|
$sql.= " ".$user->id.",";
|
2008-08-27 20:53:27 +02:00
|
|
|
|
$sql.= " ".$this->user_resp_id.", ".$this->db->idate(mktime()).", 0)";
|
2008-03-17 05:10:35 +01:00
|
|
|
|
|
2008-09-10 11:43:48 +02:00
|
|
|
|
dolibarr_syslog("Project::create sql=".$sql,LOG_DEBUG);
|
2008-03-17 05:10:35 +01:00
|
|
|
|
$resql=$this->db->query($sql);
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
|
|
|
|
|
|
$result = $this->id;
|
2006-09-23 02:27:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2008-03-17 05:10:35 +01:00
|
|
|
|
dolibarr_syslog("Project::Create error -2");
|
|
|
|
|
|
$this->error=$this->db->error();
|
|
|
|
|
|
$result = -2;
|
2002-12-22 21:04:24 +01:00
|
|
|
|
}
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
|
|
|
|
|
return $result;
|
2002-05-11 20:53:13 +02:00
|
|
|
|
}
|
2005-01-23 03:14:56 +01:00
|
|
|
|
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
|
|
|
|
|
function update($user)
|
2002-12-22 21:04:24 +01:00
|
|
|
|
{
|
2006-09-23 02:27:47 +02:00
|
|
|
|
if (strlen(trim($this->ref)) > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."projet";
|
2007-05-28 13:30:44 +02:00
|
|
|
|
$sql.= " SET ref='".$this->ref."'";
|
|
|
|
|
|
$sql.= ", title = '".$this->title."'";
|
2008-09-10 11:43:48 +02:00
|
|
|
|
$sql.= ", fk_soc = ".($this->socid > 0?$this->socid:"null");
|
2007-05-28 13:30:44 +02:00
|
|
|
|
$sql.= ", fk_user_resp = ".$this->user_resp_id;
|
|
|
|
|
|
$sql.= " WHERE rowid = ".$this->id;
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
2008-09-10 11:43:48 +02:00
|
|
|
|
dolibarr_syslog("Project::update sql=".$sql,LOG_DEBUG);
|
2006-09-23 02:27:47 +02:00
|
|
|
|
if ($this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$result = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog($this->db->error());
|
|
|
|
|
|
$result = -2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog("Project::Update ref null");
|
|
|
|
|
|
$result = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $result;
|
2002-12-22 21:04:24 +01:00
|
|
|
|
}
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* \brief Charge objet projet depuis la base
|
2008-04-19 19:26:41 +02:00
|
|
|
|
* \param rowid id du projet a charger
|
2006-09-23 02:27:47 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function fetch($rowid)
|
2002-12-22 21:04:24 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
2007-05-28 13:30:44 +02:00
|
|
|
|
$sql = "SELECT title, ref, fk_soc, fk_user_creat, fk_user_resp, fk_statut, note";
|
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."projet";
|
|
|
|
|
|
$sql.= " WHERE rowid=".$rowid;
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
|
|
|
if ($resql)
|
2002-12-22 21:04:24 +01:00
|
|
|
|
{
|
2006-09-23 02:27:47 +02:00
|
|
|
|
if ($this->db->num_rows($resql))
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
|
|
|
|
2007-05-28 13:30:44 +02:00
|
|
|
|
$this->id = $rowid;
|
|
|
|
|
|
$this->ref = $obj->ref;
|
|
|
|
|
|
$this->title = $obj->title;
|
|
|
|
|
|
$this->titre = $obj->title;
|
|
|
|
|
|
$this->note = $obj->note;
|
2008-09-10 11:43:48 +02:00
|
|
|
|
$this->socid = $obj->fk_soc;
|
|
|
|
|
|
$this->societe->id = $obj->fk_soc; // For backward compatibility
|
2007-05-28 13:30:44 +02:00
|
|
|
|
$this->user_author_id = $obj->fk_user_creat;
|
|
|
|
|
|
$this->user_resp_id = $obj->fk_user_resp;
|
|
|
|
|
|
$this->statut = $obj->fk_statut;
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
|
|
|
|
|
$this->db->free($resql);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
return -2;
|
2002-12-22 21:04:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
2008-09-10 22:49:21 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Return list of projects
|
|
|
|
|
|
* \param id_societe To filter on a particular third party
|
|
|
|
|
|
* \return array Liste of projects
|
2006-09-23 02:27:47 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function liste_array($id_societe='')
|
2005-04-05 14:01:08 +02:00
|
|
|
|
{
|
2006-09-23 02:27:47 +02:00
|
|
|
|
$projets = array();
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT rowid, title FROM ".MAIN_DB_PREFIX."projet";
|
2008-09-10 22:49:21 +02:00
|
|
|
|
if (! empty($id_societe))
|
2006-09-23 02:27:47 +02:00
|
|
|
|
{
|
2008-09-10 22:49:21 +02:00
|
|
|
|
$sql .= " WHERE fk_soc = ".$id_societe;
|
2006-09-23 02:27:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2008-09-10 22:49:21 +02:00
|
|
|
|
$resql=$this->db->query($sql);
|
|
|
|
|
|
if ($resql)
|
2006-09-23 02:27:47 +02:00
|
|
|
|
{
|
2008-09-10 22:49:21 +02:00
|
|
|
|
$nump = $this->db->num_rows($resql);
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
|
|
|
|
|
if ($nump)
|
|
|
|
|
|
{
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $nump)
|
|
|
|
|
|
{
|
2008-09-10 22:49:21 +02:00
|
|
|
|
$obj = $this->db->fetch_object($resql);
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
|
|
|
|
|
$projets[$obj->rowid] = $obj->title;
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return $projets;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2005-04-05 14:01:08 +02:00
|
|
|
|
{
|
2006-09-23 02:27:47 +02:00
|
|
|
|
print $this->db->error();
|
2005-04-05 14:01:08 +02:00
|
|
|
|
}
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
2005-04-05 14:01:08 +02:00
|
|
|
|
}
|
2008-04-19 19:26:41 +02:00
|
|
|
|
|
2006-09-23 02:27:47 +02:00
|
|
|
|
/**
|
2008-04-19 19:26:41 +02:00
|
|
|
|
* \brief Return list of elements for type linked to project
|
|
|
|
|
|
* \param type 'propal','order','invoice','order_supplier','invoice_supplier'
|
|
|
|
|
|
* \return array List of orders linked to project, <0 if error
|
2006-09-23 02:27:47 +02:00
|
|
|
|
*/
|
2008-04-19 19:26:41 +02:00
|
|
|
|
function get_element_list($type)
|
2005-04-05 14:01:08 +02:00
|
|
|
|
{
|
2008-04-19 19:26:41 +02:00
|
|
|
|
$elements = array();
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
2008-04-19 19:26:41 +02:00
|
|
|
|
$sql='';
|
|
|
|
|
|
if ($type == 'propal') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE fk_projet=".$this->id;
|
|
|
|
|
|
if ($type == 'order') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande WHERE fk_projet=".$this->id;
|
|
|
|
|
|
if ($type == 'invoice') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture 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_supplier') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture_fourn WHERE fk_projet=".$this->id;
|
2008-12-31 16:10:21 +01:00
|
|
|
|
if ($type == 'contract') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."contrat WHERE fk_projet=".$this->id;
|
2008-04-19 19:26:41 +02:00
|
|
|
|
if (! $sql) return -1;
|
|
|
|
|
|
|
|
|
|
|
|
dolibarr_syslog("Project::get_element_list sql=".$sql);
|
2006-09-23 02:27:47 +02:00
|
|
|
|
$result=$this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
2005-04-05 14:01:08 +02:00
|
|
|
|
{
|
2006-09-23 02:27:47 +02:00
|
|
|
|
$nump = $this->db->num_rows($result);
|
|
|
|
|
|
if ($nump)
|
|
|
|
|
|
{
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $nump)
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
|
|
|
|
2008-04-19 19:26:41 +02:00
|
|
|
|
$elements[$i] = $obj->rowid;
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->db->free($result);
|
2008-04-19 19:26:41 +02:00
|
|
|
|
|
|
|
|
|
|
/* Return array */
|
|
|
|
|
|
return $elements;
|
2006-09-23 02:27:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
2005-04-05 14:01:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
2008-04-19 19:26:41 +02:00
|
|
|
|
/**
|
2007-08-28 09:44:17 +02:00
|
|
|
|
* \brief Supprime le projet dans la base
|
2006-09-23 02:27:47 +02:00
|
|
|
|
* \param Utilisateur
|
|
|
|
|
|
*/
|
|
|
|
|
|
function delete($user)
|
2005-04-05 14:01:08 +02:00
|
|
|
|
{
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."projet";
|
|
|
|
|
|
$sql .= " WHERE rowid=".$this->id;
|
|
|
|
|
|
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2005-04-05 14:01:08 +02:00
|
|
|
|
}
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
2008-04-19 19:26:41 +02:00
|
|
|
|
/**
|
2008-09-10 22:49:21 +02:00
|
|
|
|
* \brief Create a task into project
|
|
|
|
|
|
* \param user Id user that create
|
|
|
|
|
|
* \param title Title of task
|
|
|
|
|
|
* \param parent Id task parent
|
2006-09-23 02:27:47 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function CreateTask($user, $title, $parent = 0)
|
|
|
|
|
|
{
|
2005-08-20 09:25:50 +02:00
|
|
|
|
$result = 0;
|
2006-09-23 02:27:47 +02:00
|
|
|
|
if (trim($title))
|
|
|
|
|
|
{
|
2008-08-26 00:14:58 +02:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task (fk_projet, title, fk_user_creat, fk_task_parent, duration_effective)";
|
|
|
|
|
|
$sql.= " VALUES (".$this->id.",'$title', ".$user->id.",".$parent.", 0)";
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
2008-08-26 00:14:58 +02:00
|
|
|
|
dolibarr_syslog("Project::CreateTask sql=".$sql,LOG_DEBUG);
|
2006-09-23 02:27:47 +02:00
|
|
|
|
if ($this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
|
|
|
|
|
|
$result = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$this->db->error();
|
2008-08-26 00:14:58 +02:00
|
|
|
|
dolibarr_syslog("Project::CreateTask error -2 ".$this->error,LOG_ERR);
|
2006-09-23 02:27:47 +02:00
|
|
|
|
$result = -2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2007-08-28 09:44:17 +02:00
|
|
|
|
if ($result == 0)
|
2006-09-23 02:27:47 +02:00
|
|
|
|
{
|
2008-08-26 00:14:58 +02:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_actors (fk_projet_task, fk_user)";
|
|
|
|
|
|
$sql.= " VALUES (".$task_id.",".$user->id.")";
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
2008-08-26 00:14:58 +02:00
|
|
|
|
dolibarr_syslog("Project::CreateTask sql=".$sql,LOG_DEBUG);
|
2006-09-23 02:27:47 +02:00
|
|
|
|
if ($this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$result = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$this->db->error();
|
2008-08-26 00:14:58 +02:00
|
|
|
|
dolibarr_syslog("Project::CreateTask error -3 ".$this->error,LOG_ERR);
|
2006-09-23 02:27:47 +02:00
|
|
|
|
$result = -2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog("Project::CreateTask error -1 ref null");
|
|
|
|
|
|
$result = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-19 19:26:41 +02:00
|
|
|
|
/**
|
2008-09-10 22:49:21 +02:00
|
|
|
|
* \brief Cree une tache dans le projet
|
|
|
|
|
|
* \param user Id utilisateur qui cree
|
|
|
|
|
|
* \param title titre de la tache
|
|
|
|
|
|
* \param parent tache parente
|
2006-09-23 02:27:47 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function TaskAddTime($user, $task, $time, $date)
|
|
|
|
|
|
{
|
2005-08-20 09:25:50 +02:00
|
|
|
|
$result = 0;
|
|
|
|
|
|
|
2006-09-23 02:27:47 +02:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (fk_task, task_date, task_duration, fk_user)";
|
2008-09-10 22:49:21 +02:00
|
|
|
|
$sql .= " VALUES (".$task.",'".$this->db->idate($date)."',".$time.", ".$user->id.")";
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
2008-09-10 22:49:21 +02:00
|
|
|
|
dolibarr_syslog("Project::TaskAddTime sql=".$sql, LOG_DEBUG);
|
2006-09-23 02:27:47 +02:00
|
|
|
|
if ($this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
|
|
|
|
|
|
$result = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog("Project::TaskAddTime error -2",LOG_ERR);
|
|
|
|
|
|
$this->error=$this->db->error();
|
|
|
|
|
|
$result = -2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-09-10 22:49:21 +02:00
|
|
|
|
if ($result == 0)
|
2006-09-23 02:27:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
|
2008-09-10 22:49:21 +02:00
|
|
|
|
$sql .= " SET duration_effective = duration_effective + '".price2num($time)."'";
|
2006-09-23 02:27:47 +02:00
|
|
|
|
$sql .= " WHERE rowid = '".$task."';";
|
|
|
|
|
|
|
2008-09-10 22:49:21 +02:00
|
|
|
|
dolibarr_syslog("Project::TaskAddTime sql=".$sql, LOG_DEBUG);
|
2006-09-23 02:27:47 +02:00
|
|
|
|
if ($this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$result = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog("Project::TaskAddTime error -3",LOG_ERR);
|
|
|
|
|
|
$this->error=$this->db->error();
|
|
|
|
|
|
$result = -2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-09-10 22:49:21 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* Enter description here...
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param unknown_type $user
|
|
|
|
|
|
* @return unknown
|
|
|
|
|
|
*/
|
2006-09-23 02:27:47 +02:00
|
|
|
|
function getTasksRoleForUser($user)
|
|
|
|
|
|
{
|
|
|
|
|
|
$tasksrole = array();
|
|
|
|
|
|
|
|
|
|
|
|
/* Liste des taches et role sur la tache du user courant dans $tasksrole */
|
|
|
|
|
|
$sql = "SELECT a.fk_projet_task, a.role";
|
|
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_actors as a";
|
|
|
|
|
|
$sql .= " WHERE a.fk_user = ".$user->id;
|
|
|
|
|
|
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows($resql);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$row = $this->db->fetch_row($resql);
|
|
|
|
|
|
$tasksrole[$row[0]] = $row[1];
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $tasksrole;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-09-10 22:49:21 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* Return list of project - tasks
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return unknown
|
|
|
|
|
|
*/
|
2006-09-23 02:27:47 +02:00
|
|
|
|
function getTasksArray()
|
|
|
|
|
|
{
|
|
|
|
|
|
$tasks = array();
|
2005-08-20 09:25:50 +02:00
|
|
|
|
|
2008-09-10 22:49:21 +02:00
|
|
|
|
/* List of tasks */
|
2006-09-23 02:27:47 +02:00
|
|
|
|
|
2008-09-10 22:49:21 +02:00
|
|
|
|
$sql = "SELECT p.rowid as projectid, p.ref, p.title,";
|
|
|
|
|
|
$sql.= " t.rowid, t.title, t.fk_task_parent, t.duration_effective";
|
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
|
|
|
|
|
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t on t.fk_projet = p.rowid";
|
|
|
|
|
|
if ($this->id) $sql .= " WHERE t.fk_projet =".$this->id;
|
|
|
|
|
|
$sql.= " ORDER BY p.ref, t.fk_task_parent";
|
|
|
|
|
|
|
|
|
|
|
|
dolibarr_syslog("Project::getTasksArray sql=".$sql);
|
2006-09-23 02:27:47 +02:00
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows($resql);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object($resql);
|
2008-09-10 22:49:21 +02:00
|
|
|
|
$tasks[$i]->projectid = $obj->projectid;
|
|
|
|
|
|
$tasks[$i]->projectref = $obj->ref;
|
|
|
|
|
|
$tasks[$i]->projectlabel = $obj->title;
|
|
|
|
|
|
$tasks[$i]->id = $obj->rowid;
|
|
|
|
|
|
$tasks[$i]->title = $obj->title;
|
|
|
|
|
|
$tasks[$i]->fk_parent = $obj->fk_task_parent;
|
|
|
|
|
|
$tasks[$i]->duration = $obj->duration_effective;
|
2006-09-23 02:27:47 +02:00
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $tasks;
|
|
|
|
|
|
}
|
2005-08-20 09:25:50 +02:00
|
|
|
|
|
2008-09-10 22:49:21 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Renvoie nom clicable (avec eventuellement le picto)
|
|
|
|
|
|
* \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
|
|
|
|
|
|
* \param option Sur quoi pointe le lien
|
|
|
|
|
|
* \return string Chaine avec URL
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getNomUrl($withpicto=0,$option='')
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
|
|
|
|
|
|
$result='';
|
|
|
|
|
|
|
|
|
|
|
|
$lien = '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$this->id.'">';
|
|
|
|
|
|
$lienfin='</a>';
|
|
|
|
|
|
|
|
|
|
|
|
$picto='project';
|
|
|
|
|
|
|
|
|
|
|
|
$label=$langs->trans("ShowProject").': '.$this->ref;
|
|
|
|
|
|
|
|
|
|
|
|
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
|
|
|
|
|
|
if ($withpicto && $withpicto != 2) $result.=' ';
|
|
|
|
|
|
if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin;
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
2002-05-11 20:53:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
?>
|