diff --git a/htdocs/lib/project.lib.php b/htdocs/lib/project.lib.php
new file mode 100644
index 00000000000..147cd191481
--- /dev/null
+++ b/htdocs/lib/project.lib.php
@@ -0,0 +1,78 @@
+
+ *
+ * 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.
+ * or see http://www.gnu.org/
+ *
+ * $Id$
+ * $Source$
+ */
+
+/**
+ \file htdocs/lib/project.lib.php
+ \brief Ensemble de fonctions de base pour le module projet
+ \ingroup societe
+ \version $Revision$
+
+ Ensemble de fonctions de base de dolibarr sous forme d'include
+*/
+
+function project_prepare_head($objsoc)
+{
+ global $langs, $conf, $user;
+ $h = 0;
+ $head = array();
+
+ $head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$objsoc->id;
+ $head[$h][1] = $langs->trans("Project");
+ $head[$h][2] = 'project';
+ $h++;
+
+ $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$objsoc->id;
+ $head[$h][1] = $langs->trans("Tasks");
+ $head[$h][2] = 'tasks';
+ $h++;
+
+ if ($conf->propal->enabled)
+ {
+ $langs->load("propal");
+ $head[$h][0] = DOL_URL_ROOT.'/projet/propal.php?id='.$objsoc->id;
+ $head[$h][1] = $langs->trans("Proposals");
+ $head[$h][2] = 'propal';
+ $h++;
+ }
+
+ if ($conf->commande->enabled)
+ {
+ $langs->load("orders");
+ $head[$h][0] = DOL_URL_ROOT.'/projet/commandes.php?id='.$objsoc->id;
+ $head[$h][1] = $langs->trans("Orders");
+ $head[$h][2] = 'order';
+ $h++;
+ }
+
+ if ($conf->facture->enabled)
+ {
+ $langs->load("bills");
+ $head[$h][0] = DOL_URL_ROOT.'/projet/facture.php?id='.$objsoc->id;
+ $head[$h][1] = $langs->trans("Invoices");
+ $head[$h][2] = 'invoice';
+ $h++;
+ }
+
+ return $head;
+}
+
+?>
\ No newline at end of file
diff --git a/htdocs/project.class.php b/htdocs/project.class.php
index e1348a35fbe..3886d0152ad 100644
--- a/htdocs/project.class.php
+++ b/htdocs/project.class.php
@@ -21,10 +21,10 @@
*/
/**
- \file htdocs/project.class.php
- \ingroup projet
- \brief Fichier de la classe de gestion des projets
- \version $Revision$
+ \file htdocs/project.class.php
+ \ingroup projet
+ \brief Fichier de la classe de gestion des projets
+ \version $Revision$
*/
/**
@@ -33,405 +33,469 @@
*/
class Project
{
- var $id;
- var $db;
- var $ref;
- var $title;
- var $socid;
-
- /**
- * \brief Constructeur de la classe
- * \param DB handler accès base de données
- */
- function Project($DB)
- {
- $this->db = $DB;
- $this->societe = new Societe($DB);
- }
-
- /*
- * \brief Crée un projet en base
- * \param user Id utilisateur qui crée
- * \return int <0 si ko, id du projet crée si ok
- */
- function create($user)
- {
- if (trim($this->ref))
- {
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, dateo) ";
- $sql .= " VALUES ('".addslashes($this->ref)."', '".addslashes($this->title)."', $this->socid, ".$user->id.",now()) ;";
-
- if ($this->db->query($sql) )
- {
- $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
- $result = $this->id;
- }
- else
- {
- dolibarr_syslog("Project::Create error -2");
- $this->error=$this->db->error();
- $result = -2;
- }
- }
- else
- {
- dolibarr_syslog("Project::Create error -1 ref null");
- $result = -1;
- }
-
- return $result;
- }
+ var $id;
+ var $db;
+ var $ref;
+ var $title;
+ var $socid;
-
- function update($user)
- {
- if (strlen(trim($this->ref)) > 0)
- {
- $sql = "UPDATE ".MAIN_DB_PREFIX."projet";
- $sql .= " SET ref='$this->ref'";
- $sql .= " , title = '$this->title'";
- $sql .= " WHERE rowid = ".$this->id;
-
- 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;
- }
-
-
- /*
- * \brief Charge objet projet depuis la base
- * \param rowid id du projet à charger
- */
-
- function fetch($rowid)
- {
-
- $sql = "SELECT title, ref, fk_soc FROM ".MAIN_DB_PREFIX."projet";
- $sql .= " WHERE rowid=".$rowid;
-
- $resql = $this->db->query($sql);
- if ($resql)
- {
- if ($this->db->num_rows($resql))
- {
- $obj = $this->db->fetch_object($resql);
-
- $this->id = $rowid;
- $this->ref = $obj->ref;
- $this->title = $obj->title;
- $this->titre = $obj->title;
- $this->societe->id = $obj->fk_soc;
-
- $this->db->free($resql);
-
- return 0;
- }
- else
- {
- return -1;
- }
- }
- else
- {
- print $this->db->error();
- return -2;
- }
- }
-
-
- /*
- *
- *
- *
- */
-
- function get_propal_list()
- {
- $propales = array();
- $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE fk_projet=$this->id;";
-
- if ($this->db->query($sql) )
+ /**
+ * \brief Constructeur de la classe
+ * \param DB handler accès base de données
+ */
+ function Project($DB)
{
- $nump = $this->db->num_rows();
- if ($nump)
- {
- $i = 0;
- while ($i < $nump)
- {
- $obj = $this->db->fetch_object();
-
- $propales[$i] = $obj->rowid;
-
- $i++;
- }
- $this->db->free();
- /*
- * Retourne un tableau contenant la liste des propales associees
- */
- return $propales;
- }
+ $this->db = $DB;
+ $this->societe = new Societe($DB);
}
- else
- {
- print $this->db->error() . '
' .$sql;
- }
- }
+ /*
+ * \brief Crée un projet en base
+ * \param user Id utilisateur qui crée
+ * \return int <0 si ko, id du projet crée si ok
+ */
+ function create($user)
+ {
+ if (trim($this->ref))
+ {
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, dateo) ";
+ $sql .= " VALUES ('".addslashes($this->ref)."', '".addslashes($this->title)."', $this->socid, ".$user->id.",now()) ;";
+
+ if ($this->db->query($sql) )
+ {
+ $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
+ $result = $this->id;
+ }
+ else
+ {
+ dolibarr_syslog("Project::Create error -2");
+ $this->error=$this->db->error();
+ $result = -2;
+ }
+ }
+ else
+ {
+ dolibarr_syslog("Project::Create error -1 ref null");
+ $result = -1;
+ }
+
+ return $result;
+ }
+
+
+ function update($user)
+ {
+ if (strlen(trim($this->ref)) > 0)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."projet";
+ $sql .= " SET ref='$this->ref'";
+ $sql .= " , title = '$this->title'";
+ $sql .= " WHERE rowid = ".$this->id;
+
+ 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;
+ }
+
+
+ /*
+ * \brief Charge objet projet depuis la base
+ * \param rowid id du projet à charger
+ */
+ function fetch($rowid)
+ {
+
+ $sql = "SELECT title, ref, fk_soc FROM ".MAIN_DB_PREFIX."projet";
+ $sql .= " WHERE rowid=".$rowid;
+
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ if ($this->db->num_rows($resql))
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ $this->id = $rowid;
+ $this->ref = $obj->ref;
+ $this->title = $obj->title;
+ $this->titre = $obj->title;
+ $this->societe->id = $obj->fk_soc;
+
+ $this->db->free($resql);
+
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ else
+ {
+ print $this->db->error();
+ return -2;
+ }
+ }
+
+
+ /*
+ *
+ *
+ *
+ */
+ function get_propal_list()
+ {
+ $propales = array();
+ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE fk_projet=$this->id;";
+
+ if ($this->db->query($sql) )
+ {
+ $nump = $this->db->num_rows();
+ if ($nump)
+ {
+ $i = 0;
+ while ($i < $nump)
+ {
+ $obj = $this->db->fetch_object();
+
+ $propales[$i] = $obj->rowid;
+
+ $i++;
+ }
+ $this->db->free();
+ /*
+ * Retourne un tableau contenant la liste des propales associees
+ */
+ return $propales;
+ }
+ }
+ else
+ {
+ print $this->db->error() . '
' .$sql;
+ }
+ }
+
+
+ /*
+ *
+ *
+ *
+ */
+ function liste_array($id_societe='')
+ {
+ $projets = array();
+
+ $sql = "SELECT rowid, title FROM ".MAIN_DB_PREFIX."projet";
+
+ if (isset($id_societe))
+ {
+ $sql .= " WHERE fk_soc = $id_societe";
+ }
+
+ if ($this->db->query($sql) )
+ {
+ $nump = $this->db->num_rows();
+
+ if ($nump)
+ {
+ $i = 0;
+ while ($i < $nump)
+ {
+ $obj = $this->db->fetch_object();
+
+ $projets[$obj->rowid] = $obj->title;
+ $i++;
+ }
+ }
+ return $projets;
+ }
+ else
+ {
+ print $this->db->error();
+ }
+
+ }
+ /*
+ *
+ *
+ *
+ */
+ function get_facture_list()
+ {
+ $factures = array();
+ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE fk_projet=$this->id;";
+
+ $result=$this->db->query($sql);
+ if ($result)
+ {
+ $nump = $this->db->num_rows($result);
+ if ($nump)
+ {
+ $i = 0;
+ while ($i < $nump)
+ {
+ $obj = $this->db->fetch_object($result);
+
+ $factures[$i] = $obj->rowid;
+
+ $i++;
+ }
+ $this->db->free($result);
+ /*
+ * Retourne un tableau contenant la liste des factures associees
+ */
+ return $factures;
+ }
+ }
+ else
+ {
+ dolibarr_print_error($this->db);
+ }
+ }
+ /**
+ * Renvoie la liste des commande associées au projet
+ *
+ *
+ */
+ function get_commande_list()
+ {
+ $commandes = array();
+ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande WHERE fk_projet=$this->id;";
+
+ $result=$this->db->query($sql);
+ if ($result)
+ {
+ $nump = $this->db->num_rows($result);
+ if ($nump)
+ {
+ $i = 0;
+ while ($i < $nump)
+ {
+ $obj = $this->db->fetch_object($result);
+
+ $commandes[$i] = $obj->rowid;
+
+ $i++;
+ }
+ $this->db->free($result);
+ /*
+ * Retourne un tableau contenant la liste des commandes associees
+ */
+ return $commandes;
+ }
+ }
+ else
+ {
+ dolibarr_print_error($this->db);
+ }
+ }
+
+ /*
+ * \brief Supprime l'projet dans la base
+ * \param Utilisateur
+ */
+
+ function delete($user)
+ {
+
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet";
+ $sql .= " WHERE rowid=".$this->id;
+
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+ /*
+ * \brief Crée une tache dans le projet
+ * \param user Id utilisateur qui crée
+ * \param title titre de la tâche
+ * \param parent tache parente
+ */
+ function CreateTask($user, $title, $parent = 0)
+ {
+ $result = 0;
+ if (trim($title))
+ {
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task (fk_projet, title, fk_user_creat, fk_task_parent) ";
+ $sql .= " VALUES (".$this->id.",'$title', ".$user->id.",".$parent.") ;";
+
+ if ($this->db->query($sql) )
+ {
+ $task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
+ $result = 0;
+ }
+ else
+ {
+ dolibarr_syslog("Project::CreateTask error -2",LOG_ERR);
+ dolibarr_syslog($this->db->error(),LOG_ERR);
+ $this->error=$this->db->error();
+ $result = -2;
+ }
+
+ if ($result ==0)
+ {
+
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_actors (fk_projet_task, fk_user) ";
+ $sql .= " VALUES (".$task_id.",".$user->id.") ;";
+
+ if ($this->db->query($sql) )
+ {
+ $result = 0;
+ }
+ else
+ {
+ dolibarr_syslog("Project::CreateTask error -3",LOG_ERR);
+ $this->error=$this->db->error();
+ $result = -2;
+ }
+ }
+
+
+ }
+ else
+ {
+ dolibarr_syslog("Project::CreateTask error -1 ref null");
+ $result = -1;
+ }
+
+ return $result;
+ }
+
+
+ /*
+ * \brief Crée une tache dans le projet
+ * \param user Id utilisateur qui crée
+ * \param title titre de la tâche
+ * \param parent tache parente
+ */
+ function TaskAddTime($user, $task, $time, $date)
+ {
+ $result = 0;
+
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (fk_task, task_date, task_duration, fk_user)";
+ $sql .= " VALUES (".$task.",'".$this->db->idate($date)."',".$time.", ".$user->id.") ;";
+
+ 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;
+ }
+
+ if ($result ==0)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
+ $sql .= " SET duration_effective = duration_effective + '".ereg_replace(",",".",$time)."'";
+ $sql .= " WHERE rowid = '".$task."';";
+
+ 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;
+ }
+
+
+ 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;
+ }
+
+
+ function getTasksArray()
+ {
+ $tasks = array();
+
+ /* Liste des tâches dans $tasks */
+
+ $sql = "SELECT t.rowid, t.title, t.fk_task_parent, t.duration_effective";
+ $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as t";
+ $sql .= " WHERE t.fk_projet =".$this->id;
+ $sql .= " ORDER BY t.fk_task_parent";
+
+ $var=true;
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $tasks[$i]->id = $obj->rowid;
+ $tasks[$i]->title = $obj->title;
+ $tasks[$i]->fk_parent = $obj->fk_task_parent;
+ $tasks[$i]->duration = $obj->duration_effective;
+ $i++;
+ }
+ $this->db->free();
+ }
+ else
+ {
+ dolibarr_print_error($this->db);
+ }
- /*
- *
- *
- *
- */
- function liste_array($id_societe='')
- {
- $projets = array();
-
- $sql = "SELECT rowid, title FROM ".MAIN_DB_PREFIX."projet";
-
- if (isset($id_societe))
- {
- $sql .= " WHERE fk_soc = $id_societe";
+ return $tasks;
}
-
- if ($this->db->query($sql) )
- {
- $nump = $this->db->num_rows();
- if ($nump)
- {
- $i = 0;
- while ($i < $nump)
- {
- $obj = $this->db->fetch_object();
-
- $projets[$obj->rowid] = $obj->title;
- $i++;
- }
- }
- return $projets;
- }
- else
- {
- print $this->db->error();
- }
-
- }
- /*
- *
- *
- *
- */
- function get_facture_list()
- {
- $factures = array();
- $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE fk_projet=$this->id;";
-
- $result=$this->db->query($sql);
- if ($result)
- {
- $nump = $this->db->num_rows($result);
- if ($nump)
- {
- $i = 0;
- while ($i < $nump)
- {
- $obj = $this->db->fetch_object($result);
-
- $factures[$i] = $obj->rowid;
-
- $i++;
- }
- $this->db->free($result);
- /*
- * Retourne un tableau contenant la liste des factures associees
- */
- return $factures;
- }
- }
- else
- {
- dolibarr_print_error($this->db);
- }
- }
- /**
- * Renvoie la liste des commande associées au projet
- *
- *
- */
- function get_commande_list()
- {
- $commandes = array();
- $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande WHERE fk_projet=$this->id;";
-
- $result=$this->db->query($sql);
- if ($result)
- {
- $nump = $this->db->num_rows($result);
- if ($nump)
- {
- $i = 0;
- while ($i < $nump)
- {
- $obj = $this->db->fetch_object($result);
-
- $commandes[$i] = $obj->rowid;
-
- $i++;
- }
- $this->db->free($result);
- /*
- * Retourne un tableau contenant la liste des commandes associees
- */
- return $commandes;
- }
- }
- else
- {
- dolibarr_print_error($this->db);
- }
- }
-
- /*
- * \brief Supprime l'projet dans la base
- * \param Utilisateur
- */
-
- function delete($user)
- {
-
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet";
- $sql .= " WHERE rowid=".$this->id;
-
- $resql = $this->db->query($sql);
- if ($resql)
- {
- return 0;
- }
- else
- {
- return -1;
- }
- }
-
- /*
- * \brief Crée une tache dans le projet
- * \param user Id utilisateur qui crée
- * \param title titre de la tâche
- * \param parent tache parente
- */
- function CreateTask($user, $title, $parent = 0)
- {
- $result = 0;
- if (trim($title))
- {
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task (fk_projet, title, fk_user_creat, fk_task_parent) ";
- $sql .= " VALUES (".$this->id.",'$title', ".$user->id.",".$parent.") ;";
-
- if ($this->db->query($sql) )
- {
- $task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
- $result = 0;
- }
- else
- {
- dolibarr_syslog("Project::CreateTask error -2",LOG_ERR);
- dolibarr_syslog($this->db->error(),LOG_ERR);
- $this->error=$this->db->error();
- $result = -2;
- }
-
- if ($result ==0)
- {
-
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_actors (fk_projet_task, fk_user) ";
- $sql .= " VALUES (".$task_id.",".$user->id.") ;";
-
- if ($this->db->query($sql) )
- {
- $result = 0;
- }
- else
- {
- dolibarr_syslog("Project::CreateTask error -3",LOG_ERR);
- $this->error=$this->db->error();
- $result = -2;
- }
- }
-
-
- }
- else
- {
- dolibarr_syslog("Project::CreateTask error -1 ref null");
- $result = -1;
- }
-
- return $result;
- }
- /*
- * \brief Crée une tache dans le projet
- * \param user Id utilisateur qui crée
- * \param title titre de la tâche
- * \param parent tache parente
- */
- function TaskAddTime($user, $task, $time, $date)
- {
- $result = 0;
-
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (fk_task, task_date, task_duration, fk_user)";
- $sql .= " VALUES (".$task.",'".$this->db->idate($date)."',".$time.", ".$user->id.") ;";
-
- 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;
- }
-
- if ($result ==0)
- {
-
- $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
- $sql .= " SET duration_effective = duration_effective + '".ereg_replace(",",".",$time)."'";
- $sql .= " WHERE rowid = '".$task."';";
-
- 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;
- }
}
?>
diff --git a/htdocs/projet/commandes.php b/htdocs/projet/commandes.php
index a3fd01c8060..eae79bc9efc 100644
--- a/htdocs/projet/commandes.php
+++ b/htdocs/projet/commandes.php
@@ -31,6 +31,7 @@ require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
if ($conf->projet->enabled) $langs->load("projects");
$langs->load("companies");
@@ -72,43 +73,13 @@ llxHeader("","../");
$projet = new Project($db);
$projet->fetch($_GET["id"]);
-
-$h=0;
-$head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$projet->id;
-$head[$h][1] = $langs->trans("Project");
-$h++;
-
-$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$projet->id;
-$head[$h][1] = $langs->trans("Tasks");
-$h++;
-
-if ($conf->propal->enabled) {
- $langs->load("propal");
- $head[$h][0] = DOL_URL_ROOT.'/projet/propal.php?id='.$projet->id;
- $head[$h][1] = $langs->trans("Proposals");
- $h++;
-}
-
-if ($conf->commande->enabled) {
- $langs->load("orders");
- $head[$h][0] = DOL_URL_ROOT.'/projet/commandes.php?id='.$projet->id;
- $head[$h][1] = $langs->trans("Orders");
- $hselected=$h;
- $h++;
-}
-
-if ($conf->facture->enabled) {
- $langs->load("bills");
- $head[$h][0] = DOL_URL_ROOT.'/projet/facture.php?id='.$projet->id;
- $head[$h][1] = $langs->trans("Bills");
- $h++;
-}
-
-dolibarr_fiche_head($head, $hselected, $langs->trans("Project").": ".$projet->ref);
-
-
$projet->societe->fetch($projet->societe->id);
+$head=project_prepare_head($projet);
+dolibarr_fiche_head($head, 'order', $langs->trans("Project"));
+
+
+
print '
';
print '| '.$langs->trans("Ref").' | '.$projet->ref.' |
';
diff --git a/htdocs/projet/facture.php b/htdocs/projet/facture.php
index 31efd1d76e9..1079f54eff4 100644
--- a/htdocs/projet/facture.php
+++ b/htdocs/projet/facture.php
@@ -31,6 +31,7 @@ require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
$langs->load("projects");
$langs->load("companies");
@@ -73,43 +74,12 @@ llxHeader("","../");
$projet = new Project($db);
$projet->fetch($_GET["id"]);
-
-$h=0;
-$head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$projet->id;
-$head[$h][1] = $langs->trans("Project");
-$h++;
-
-$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$projet->id;
-$head[$h][1] = $langs->trans("Tasks");
-$h++;
-
-if ($conf->propal->enabled) {
- $langs->load("propal");
- $head[$h][0] = DOL_URL_ROOT.'/projet/propal.php?id='.$projet->id;
- $head[$h][1] = $langs->trans("Proposals");
- $h++;
-}
-
-if ($conf->commande->enabled) {
- $langs->load("orders");
- $head[$h][0] = DOL_URL_ROOT.'/projet/commandes.php?id='.$projet->id;
- $head[$h][1] = $langs->trans("Orders");
- $h++;
-}
-
-if ($conf->facture->enabled) {
- $langs->load("bills");
- $head[$h][0] = DOL_URL_ROOT.'/projet/facture.php?id='.$projet->id;
- $head[$h][1] = $langs->trans("Bills");
- $hselected=$h;
- $h++;
-}
-
-dolibarr_fiche_head($head, $hselected, $langs->trans("Project").": ".$projet->ref);
-
-
$projet->societe->fetch($projet->societe->id);
+$head=project_prepare_head($projet);
+dolibarr_fiche_head($head, 'invoice', $langs->trans("Project"));
+
+
print '';
print '| '.$langs->trans("Ref").' | '.$projet->ref.' |
';
diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php
index a0fcf64707c..9e5aa0af001 100644
--- a/htdocs/projet/fiche.php
+++ b/htdocs/projet/fiche.php
@@ -31,6 +31,7 @@ require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
if (!$user->rights->projet->lire) accessforbidden();
@@ -44,7 +45,7 @@ if ($projetid == '' && ($_GET['action'] != "create" && $_POST['action'] != "add"
if ($user->societe_id > 0)
{
- $socid = $user->societe_id;
+ $socid = $user->societe_id;
}
// Protection restriction commercial
@@ -56,7 +57,7 @@ if ($projetid && !$user->rights->commercial->client->voir)
$sql.= " WHERE p.rowid = ".$projetid;
if (!$user->rights->commercial->client->voir) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND p.fk_soc = ".$socid;
-
+
if ( $db->query($sql) )
{
if ( $db->num_rows() == 0) accessforbidden();
@@ -66,61 +67,63 @@ if ($projetid && !$user->rights->commercial->client->voir)
if ($_POST["action"] == 'add' && $user->rights->projet->creer)
{
- $pro = new Project($db);
- $pro->socid = $_GET["socid"];
- $pro->ref = $_POST["ref"];
- $pro->title = $_POST["title"];
- $result = $pro->create($user);
-
- if ($result > 0)
- {
- Header("Location:fiche.php?id=".$pro->id);
- exit;
- }
- else
- {
- $mesg=''.$pro->error.'
';
- $_GET["action"] = 'create';
- }
+ $pro = new Project($db);
+ $pro->socid = $_GET["socid"];
+ $pro->ref = $_POST["ref"];
+ $pro->title = $_POST["title"];
+ $result = $pro->create($user);
+
+ if ($result > 0)
+ {
+ Header("Location:fiche.php?id=".$pro->id);
+ exit;
+ }
+ else
+ {
+ $mesg=''.$pro->error.'
';
+ $_GET["action"] = 'create';
+ }
}
if ($_POST["action"] == 'update' && $user->rights->projet->creer)
{
- if (! $_POST["cancel"])
- {
- if (!(empty($_POST["id"]) || empty($_POST["ref"]) || empty($_POST["title"])))
+ if (! $_POST["cancel"])
{
- $projet = new Project($db);
- $projet->id = $_POST["id"];
- $projet->ref = $_POST["ref"];
- $projet->title = $_POST["title"];
- $projet->update($user);
-
- $_GET["id"]=$projet->id; // On retourne sur la fiche projet
+ if (!(empty($_POST["id"]) || empty($_POST["ref"]) || empty($_POST["title"])))
+ {
+ $projet = new Project($db);
+ $projet->id = $_POST["id"];
+ $projet->ref = $_POST["ref"];
+ $projet->title = $_POST["title"];
+ $projet->update($user);
+
+ $_GET["id"]=$projet->id; // On retourne sur la fiche projet
+ }
+ else
+ {
+ $_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
+ }
}
- else
+ else
{
- $_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
+ $_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
}
- }
- else
- {
- $_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
- }
}
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->projet->supprimer)
{
- $projet = new Project($db);
- $projet->id = $_GET["id"];
- if ($projet->delete($user) == 0)
- {
- Header("Location: index.php");
- }
- else
- {
- Header("Location: fiche.php?id=".$projet->id);
- }
+ $projet = new Project($db);
+ $projet->id = $_GET["id"];
+ if ($projet->delete($user) == 0)
+ {
+ Header("Location: index.php");
+ exit;
+ }
+ else
+ {
+ Header("Location: fiche.php?id=".$projet->id);
+ exit;
+ }
}
@@ -158,109 +161,76 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer)
} else {
- /*
- * Fiche projet en mode visu
- *
- */
+ /*
+ * Fiche projet en mode visu
+ *
+ */
- $projet = new Project($db);
- $projet->fetch($_GET["id"]);
- $projet->societe->fetch($projet->societe->id);
-
- $h=0;
- $head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$projet->id;
- $head[$h][1] = $langs->trans("Project");
- $hselected=$h;
- $h++;
-
- $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$projet->id;
- $head[$h][1] = $langs->trans("Tasks");
- $h++;
+ $projet = new Project($db);
+ $projet->fetch($_GET["id"]);
+ $projet->societe->fetch($projet->societe->id);
- if ($conf->propal->enabled)
- {
- $langs->load("propal");
- $head[$h][0] = DOL_URL_ROOT.'/projet/propal.php?id='.$projet->id;
- $head[$h][1] = $langs->trans("Proposals");
- $h++;
- }
-
- if ($conf->commande->enabled)
- {
- $langs->load("orders");
- $head[$h][0] = DOL_URL_ROOT.'/projet/commandes.php?id='.$projet->id;
- $head[$h][1] = $langs->trans("Orders");
- $h++;
- }
-
- if ($conf->facture->enabled)
- {
- $langs->load("bills");
- $head[$h][0] = DOL_URL_ROOT.'/projet/facture.php?id='.$projet->id;
- $head[$h][1] = $langs->trans("Bills");
- $h++;
- }
-
- dolibarr_fiche_head($head, $hselected, $langs->trans("Project").": ".$projet->ref);
+ $head=project_prepare_head($projet);
+ dolibarr_fiche_head($head, 'project', $langs->trans("Project"));
- if ($_GET["action"] == 'delete')
- {
- $htmls = new Form($db);
- $htmls->form_confirm("fiche.php?id=".$_GET["id"],$langs->trans("DeleteAProject"),$langs->trans("ConfirmDeleteAProject"),"confirm_delete");
- print "
";
- }
+ if ($_GET["action"] == 'delete')
+ {
+ $htmls = new Form($db);
+ $htmls->form_confirm("fiche.php?id=".$_GET["id"],$langs->trans("DeleteAProject"),$langs->trans("ConfirmDeleteAProject"),"confirm_delete");
+ print "
";
+ }
- if ($_GET["action"] == 'edit')
- {
- print '