[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/ -> project.class.php (source)

   1  <?php
   2  /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2005      Laurent Destailleur  <eldy@users.sourceforge.net>
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License
  16   * along with this program; if not, write to the Free Software
  17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18   *
  19   * $Id: project.class.php,v 1.15 2005/08/20 21:45:40 rodolphe Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/project.class.php,v $
  21   *
  22   */
  23  
  24  /**
  25          \file       htdocs/project.class.php
  26          \ingroup    projet
  27          \brief      Fichier de la classe de gestion des projets
  28          \version    $Revision: 1.15 $
  29  */
  30  
  31  /**
  32    \class      Project
  33    \brief      Classe permettant la gestion des projets
  34  */
  35  
  36  class Project {
  37      var $id;
  38      var $db;
  39      var $ref;
  40      var $title;
  41      var $socidp;
  42      
  43      /**
  44       *    \brief  Constructeur de la classe
  45       *    \param  DB          handler accès base de données
  46       */
  47      function Project($DB)
  48      {
  49          $this->db = $DB;
  50          $this->societe = new Societe($DB);
  51      }
  52    
  53      /*
  54       *    \brief      Crée un projet en base
  55       *    \param      user        Id utilisateur qui crée
  56       *    \return     int         <0 si ko, id du projet crée si ok
  57       */
  58      function create($user)
  59      {
  60          if (trim($this->ref))
  61          {
  62              $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, dateo) ";
  63              $sql .= " VALUES ('$this->ref', '$this->title', $this->socidp, ".$user->id.",now()) ;";
  64      
  65              if ($this->db->query($sql) )
  66              {
  67                  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
  68                  $result = $this->id;
  69              }
  70              else
  71              {
  72                  dolibarr_syslog("Project::Create error -2");
  73                  $this->error=$this->db->error();
  74                  $result = -2;
  75              }
  76          }
  77          else
  78          {
  79              dolibarr_syslog("Project::Create error -1 ref null");
  80              $result = -1;
  81          }
  82      
  83          return $result;
  84      }
  85  
  86  
  87    function update($user)
  88    {
  89      if (strlen(trim($this->ref)) > 0)
  90        {
  91      $sql = "UPDATE ".MAIN_DB_PREFIX."projet";
  92      $sql .= " SET ref='$this->ref'";
  93      $sql .= " , title = '$this->title'";
  94      $sql .= " WHERE rowid = ".$this->id;
  95      
  96      if ($this->db->query($sql) ) 
  97        {
  98          $result = 0;
  99        }
 100      else
 101        {
 102          dolibarr_syslog($this->db->error());
 103          $result = -2;
 104        }    
 105        }
 106      else
 107        {
 108      dolibarr_syslog("Project::Update ref null");
 109      $result = -1;
 110        }    
 111    
 112      return $result;
 113    }  
 114  
 115  
 116    /*
 117     *    \brief      Charge objet projet depuis la base
 118     *    \param      rowid       id du projet à charger
 119     */
 120  
 121    function fetch($rowid)
 122    {
 123      
 124      $sql = "SELECT title, ref, fk_soc FROM ".MAIN_DB_PREFIX."projet";
 125      $sql .= " WHERE rowid=".$rowid;
 126  
 127      $resql = $this->db->query($sql);
 128      if ($resql)
 129        {
 130      if ($this->db->num_rows($resql))
 131        {
 132          $obj = $this->db->fetch_object($resql);
 133          
 134          $this->id = $rowid;
 135          $this->ref = $obj->ref;
 136          $this->title = $obj->title;
 137          $this->titre = $obj->title;
 138          $this->societe->id = $obj->fk_soc;
 139          
 140          $this->db->free($resql);
 141  
 142          return 0;
 143        }
 144      else
 145        {
 146          return -1;
 147        }
 148        }
 149      else
 150        {
 151      print $this->db->error();
 152      return -2;
 153        }
 154    }
 155      
 156  
 157    /*
 158     *
 159     *
 160     *
 161     */
 162       
 163    function get_propal_list()
 164      {
 165        $propales = array();
 166        $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE fk_projet=$this->id;";
 167        
 168        if ($this->db->query($sql) )
 169      {
 170        $nump = $this->db->num_rows();
 171        if ($nump)
 172          {
 173            $i = 0;
 174            while ($i < $nump)
 175          {
 176            $obj = $this->db->fetch_object();
 177            
 178            $propales[$i] = $obj->rowid;
 179  
 180            $i++;
 181          }
 182            $this->db->free();
 183            /*
 184             *  Retourne un tableau contenant la liste des propales associees
 185             */
 186            return $propales;
 187          }
 188      }
 189        else
 190      {
 191        print $this->db->error() . '<br>' .$sql;
 192      }      
 193      }
 194  
 195          
 196    /*
 197     *
 198     *
 199     *
 200     */
 201    function liste_array($id_societe='')
 202      {
 203        $projets = array();
 204  
 205        $sql = "SELECT rowid, title FROM ".MAIN_DB_PREFIX."projet";
 206  
 207        if (isset($id_societe))
 208      {
 209        $sql .= " WHERE fk_soc = $id_societe";
 210      }
 211        
 212        if ($this->db->query($sql) )
 213      {
 214        $nump = $this->db->num_rows();
 215  
 216        if ($nump)
 217          {
 218            $i = 0;
 219            while ($i < $nump)
 220          {
 221            $obj = $this->db->fetch_object();
 222            
 223            $projets[$obj->rowid] = $obj->title;
 224            $i++;
 225          }
 226          }
 227        return $projets;
 228      }
 229        else
 230      {
 231        print $this->db->error();
 232      }
 233        
 234      }
 235    /*
 236     *
 237     *
 238     *
 239     */
 240    function get_facture_list()
 241      {
 242        $factures = array();
 243        $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE fk_projet=$this->id;";
 244        
 245        $result=$this->db->query($sql);
 246        if ($result)
 247      {
 248        $nump = $this->db->num_rows($result);
 249        if ($nump)
 250          {
 251            $i = 0;
 252            while ($i < $nump)
 253          {
 254            $obj = $this->db->fetch_object($result);
 255            
 256            $factures[$i] = $obj->rowid;
 257            
 258            $i++;
 259          }
 260            $this->db->free($result);
 261            /*
 262             *  Retourne un tableau contenant la liste des factures associees
 263             */
 264            return $factures;
 265          }
 266      }
 267        else
 268      {
 269        dolibarr_print_error($this->db);
 270      }
 271      }
 272    /**
 273     * Renvoie la liste des commande associées au projet
 274     *
 275     *
 276     */
 277    function get_commande_list()
 278      {
 279        $commandes = array();
 280        $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande WHERE fk_projet=$this->id;";
 281        
 282        $result=$this->db->query($sql);
 283        if ($result)
 284      {
 285        $nump = $this->db->num_rows($result);
 286        if ($nump)
 287          {
 288            $i = 0;
 289            while ($i < $nump)
 290          {
 291            $obj = $this->db->fetch_object($result);
 292            
 293            $commandes[$i] = $obj->rowid;
 294            
 295            $i++;
 296          }
 297            $this->db->free($result);
 298            /*
 299             *  Retourne un tableau contenant la liste des commandes associees
 300             */
 301            return $commandes;
 302          }
 303      }
 304        else
 305      {
 306        dolibarr_print_error($this->db);
 307      }
 308      }
 309  
 310    /*
 311     *    \brief    Supprime l'projet dans la base
 312     *    \param    Utilisateur
 313     */
 314  
 315    function delete($user)
 316    {
 317      
 318      $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet";
 319      $sql .= " WHERE rowid=".$this->id;
 320  
 321      $resql = $this->db->query($sql);
 322      if ($resql)
 323        {
 324      return 0;
 325        }
 326      else
 327        {
 328      return -1;
 329        }
 330    }
 331  
 332    /*
 333     *    \brief      Crée une tache dans le projet
 334     *    \param      user        Id utilisateur qui crée
 335     *    \param     title      titre de la tâche
 336     *    \param      parent   tache parente
 337     */
 338    function CreateTask($user, $title, $parent = 0)
 339    {
 340      $result = 0;
 341      if (trim($title))
 342        {
 343      $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task (fk_projet, title, fk_user_creat, fk_task_parent) ";
 344      $sql .= " VALUES (".$this->id.",'$title', ".$user->id.",".$parent.") ;";
 345      
 346      if ($this->db->query($sql) )
 347        {
 348          $task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
 349          $result = 0;
 350        }
 351      else
 352        {
 353          dolibarr_syslog("Project::CreateTask error -2",LOG_ERR);
 354          dolibarr_syslog($this->db->error(),LOG_ERR);
 355          $this->error=$this->db->error();
 356          $result = -2;
 357        }
 358  
 359      if ($result ==0)
 360        {
 361  
 362          $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_actors (fk_projet_task, fk_user) ";
 363          $sql .= " VALUES (".$task_id.",".$user->id.") ;";
 364      
 365          if ($this->db->query($sql) )
 366            {
 367          $result = 0;
 368            }
 369          else
 370            {
 371          dolibarr_syslog("Project::CreateTask error -3",LOG_ERR);
 372          $this->error=$this->db->error();
 373          $result = -2;
 374            }
 375        }
 376  
 377  
 378          }
 379      else
 380        {
 381      dolibarr_syslog("Project::CreateTask error -1 ref null");
 382      $result = -1;
 383        }
 384      
 385      return $result;
 386    }
 387    /*
 388     *    \brief      Crée une tache dans le projet
 389     *    \param      user        Id utilisateur qui crée
 390     *    \param     title      titre de la tâche
 391     *    \param      parent   tache parente
 392     */
 393    function TaskAddTime($user, $task, $time, $date)
 394    {
 395      $result = 0;
 396  
 397      $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (fk_task, task_date, task_duration, fk_user)";
 398      $sql .= " VALUES (".$task.",'".$this->db->idate($date)."',".$time.", ".$user->id.") ;";
 399  
 400      if ($this->db->query($sql) )
 401        {
 402          $task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
 403          $result = 0;
 404        }
 405      else
 406        {
 407          dolibarr_syslog("Project::TaskAddTime error -2",LOG_ERR);
 408          $this->error=$this->db->error();
 409          $result = -2;
 410        }
 411  
 412      if ($result ==0)
 413        {
 414  
 415          $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
 416          $sql .= " SET duration_effective = duration_effective + '".ereg_replace(",",".",$time)."'";
 417          $sql .= " WHERE rowid = '".$task."';";
 418      
 419          if ($this->db->query($sql) )
 420            {
 421          $result = 0;
 422            }
 423          else
 424            {
 425          dolibarr_syslog("Project::TaskAddTime error -3",LOG_ERR);
 426          $this->error=$this->db->error();
 427          $result = -2;
 428            }
 429        }
 430      
 431  
 432  
 433  
 434      
 435      return $result;
 436    }
 437  }
 438  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics