dolibarr/htdocs/project.class.php

324 lines
6.1 KiB
PHP
Raw Normal View History

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>
2005-01-23 03:14:56 +01:00
* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
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.
*
2002-12-22 21:04:24 +01:00
* $Id$
* $Source$
*
2002-05-11 20:53:13 +02:00
*/
2005-04-05 13:52:30 +02:00
/*!
\file htdocs/project.class.php
\ingroup projet
\brief Fichier de la classe de gestion des projets
\version $Revision$
2005-01-23 03:14:56 +01:00
*/
2005-04-05 13:52:30 +02:00
/*!
\class Project
\brief Classe permettant la gestion des projets
2005-01-23 03:14:56 +01:00
*/
2002-05-11 20:53:13 +02:00
class Project {
var $id;
var $db;
var $ref;
var $title;
var $socidp;
2005-01-23 03:14:56 +01:00
/**
* \brief Constructeur de la classe
* \param DB handler acc<EFBFBD>s base de donn<EFBFBD>es
*/
2005-04-05 13:52:30 +02:00
function Project($DB)
{
2002-05-11 20:53:13 +02:00
$this->db = $DB;
2005-04-05 14:01:08 +02:00
$this->societe = new Societe($DB);
2002-05-11 20:53:13 +02:00
}
2005-04-05 13:52:30 +02:00
2002-05-11 20:53:13 +02:00
/*
2005-01-23 03:14:56 +01:00
* \brief Cr<EFBFBD>e un projet en base
2005-04-05 13:52:30 +02:00
* \param user id utilisateur qui cr<EFBFBD>e
2002-05-11 20:53:13 +02:00
*/
2005-04-05 13:52:30 +02:00
function create($user)
{
2005-07-30 22:23:00 +02:00
if (strlen(trim($this->ref)) > 0)
2005-04-05 14:01:08 +02:00
{
2005-07-30 22:23:00 +02:00
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, dateo) ";
$sql .= " VALUES ('$this->ref', '$this->title', $this->socidp, ".$user->id.",now()) ;";
if ($this->db->query($sql) )
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
$result = 0;
}
else
{
dolibarr_syslog($this->db->error());
$result = -2;
}
2005-04-05 14:01:08 +02:00
}
else
2002-05-11 20:53:13 +02:00
{
2005-07-30 22:23:00 +02:00
dolibarr_syslog("Project::Create 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;
2005-04-05 13:52:30 +02:00
}
2005-04-05 14:01:08 +02:00
2005-07-30 22:23:00 +02:00
return $result;
}
2002-05-11 20:53:13 +02:00
/*
2005-01-23 03:14:56 +01:00
* \brief Charge objet projet depuis la base
* \param rowid id du projet <EFBFBD> charger
2002-05-11 20:53:13 +02:00
*/
2005-04-05 13:52:30 +02:00
function fetch($rowid)
{
2005-04-05 14:01:08 +02:00
$sql = "SELECT title, ref, fk_soc FROM ".MAIN_DB_PREFIX."projet";
2005-04-05 13:52:30 +02:00
$sql .= " WHERE rowid=".$rowid;
2002-05-11 20:53:13 +02:00
2005-04-05 13:52:30 +02:00
$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;
2005-04-05 14:01:08 +02:00
$this->titre = $obj->title;
$this->societe->id = $obj->fk_soc;
2005-04-05 13:52:30 +02:00
$this->db->free($resql);
}
}
else
{
print $this->db->error();
2002-05-11 20:53:13 +02:00
}
}
2004-10-20 23:06:45 +02:00
2002-05-11 20:53:13 +02:00
/*
*
*
*
*/
2004-10-20 23:06:45 +02:00
function get_propal_list()
2002-12-22 21:04:24 +01:00
{
$propales = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE fk_projet=$this->id;";
2002-12-22 21:04:24 +01:00
if ($this->db->query($sql) )
{
$nump = $this->db->num_rows();
if ($nump)
{
$i = 0;
while ($i < $nump)
{
$obj = $this->db->fetch_object();
2002-12-22 21:04:24 +01:00
$propales[$i] = $obj->rowid;
2002-05-11 20:53:13 +02:00
2002-12-22 21:04:24 +01:00
$i++;
}
$this->db->free();
/*
* Retourne un tableau contenant la liste des propales associees
*/
return $propales;
}
2002-05-11 20:53:13 +02:00
}
2002-12-22 21:04:24 +01:00
else
{
print $this->db->error() . '<br>' .$sql;
}
2002-05-11 20:53:13 +02:00
}
2005-01-23 03:14:56 +01:00
2004-10-20 23:06:45 +02:00
2002-12-22 21:04:24 +01:00
/*
*
*
*
*/
function liste_array($id_societe='')
2002-12-22 21:04:24 +01:00
{
$projets = array();
2002-05-11 20:53:13 +02:00
$sql = "SELECT rowid, title FROM ".MAIN_DB_PREFIX."projet";
2002-05-11 20:53:13 +02:00
2002-12-22 21:04:24 +01:00
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();
2002-12-22 21:04:24 +01:00
$projets[$obj->rowid] = $obj->title;
$i++;
}
}
return $projets;
}
else
{
print $this->db->error();
}
}
2005-04-05 14:01:08 +02:00
/*
*
*
*
*/
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<EFBFBD>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);
}
}
2005-07-30 22:23:00 +02:00
/*
* \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;
}
}
2002-05-11 20:53:13 +02:00
}
?>