[ 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/fichinter/ -> fichinter.class.php (source)

   1  <?php
   2  /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2004-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: fichinter.class.php,v 1.17 2005/11/23 21:02:16 tipaul Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/fichinter/fichinter.class.php,v $
  21   *
  22   */
  23  
  24  /**        \file       htdocs/fichinter/fichinter.class.php
  25          \ingroup    fucheinter
  26          \brief      Fichier de la classe des gestion des fiches interventions
  27          \version    $Revision: 1.17 $
  28  */
  29  
  30  require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
  31  
  32  
  33  /**        \class      Ficheinter
  34          \brief      Classe des gestion des fiches interventions
  35  */
  36  class Fichinter
  37  {
  38      var $id;
  39      var $db;
  40      var $socidp;
  41      var $author;
  42      var $ref;
  43      var $date;
  44      var $duree;
  45      var $note;
  46      var $projet_id;
  47  
  48      /**
  49       *    \brief      Constructeur de la classe
  50       *    \param      DB            Handler accès base de données
  51       *    \param      soc_idp       Id societe
  52       */
  53      function Fichinter($DB, $soc_idp="")
  54      {
  55          global $langs;
  56  
  57          $this->db = $DB ;
  58          $this->socidp = $soc_idp;
  59          $this->products = array();
  60          $this->projet_id = 0;
  61  
  62          // Statut 0=brouillon, 1=validé
  63          $this->statuts[0]=$langs->trans("Draft");
  64          $this->statuts[1]=$langs->trans("Validated");
  65      }
  66  
  67  
  68      function add_product($idproduct)
  69      {
  70          if ($idproduct > 0)
  71          {
  72              $i = sizeof($this->products);
  73              $this->products[$i] = $idproduct;
  74          }
  75      }
  76  
  77  
  78      /*
  79       *    \brief      Crée une fiche intervention en base
  80       *
  81       */
  82      function create()
  83      {
  84          if (!strlen($this->duree)) { $this->duree = 0; }
  85  
  86          $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter (fk_soc, datei, datec, ref, fk_user_author, note, duree";
  87          if ($this->projet_id) {
  88              $sql .=  ",fk_projet";
  89          }
  90          $sql .= ") ";
  91          $sql .= " VALUES ($this->socidp, $this->date, now(), '$this->ref', $this->author, '".addslashes($this->note)."', $this->duree";
  92          if ($this->projet_id) {
  93              $sql .= ", $this->projet_id";
  94          }
  95          $sql .= ")";
  96          $sqlok = 0;
  97  
  98          $result=$this->db->query($sql);
  99          if ($result)
 100          {
 101              return $this->db->last_insert_id(MAIN_DB_PREFIX."fichinter");
 102          }
 103          else
 104          {
 105              return -1;
 106          }
 107  
 108      }
 109  
 110      /*
 111       *
 112       *
 113       */
 114      function update($id)
 115      {
 116          if (! strlen($this->projet_id))
 117          {
 118              $this->projet_id = 0;
 119          }
 120  
 121          /*
 122           *  Insertion dans la base
 123           */
 124          $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET ";
 125          $sql .= " datei = $this->date";
 126          $sql .= ", note  = '".addslashes($this->note)."'";
 127          $sql .= ", duree = $this->duree";
 128          $sql .= ", fk_projet = $this->projet_id";
 129          $sql .= " WHERE rowid = $id";
 130  
 131          if (! $this->db->query($sql) )
 132          {
 133  
 134              print $this->db->error() . '<b><br>'.$sql;
 135          }
 136          return 1;
 137      }
 138  
 139      /*
 140       *
 141       *
 142       */
 143      function get_new_num($prefix_comm)
 144      {
 145  
 146          $sql = "SELECT max(ref) FROM ".MAIN_DB_PREFIX."fichinter WHERE ref like 'FI-".$prefix_comm."-%'";
 147  
 148          if ($this->db->query($sql) )
 149          {
 150              if ($this->db->num_rows())
 151              {
 152                  $row = $this->db->fetch_row(0);
 153                  $num = $row[0];
 154                  /*
 155                  *$num = substr($num, strlen($num) - 4, 4);
 156                  *$num = $num + 1;
 157                  *$num = '0000' . $num;
 158                  *$num = 'FI-' . $prefix_comm . '-' . substr($num, strlen($num) - 4, 4);
 159                  */
 160                  $num = substr($num, 3);
 161                  $num = substr(strstr($num, "-"),1);
 162  
 163                  $num = $num + 1;
 164                  //$num = '0000' . $num;
 165                  //$num = 'FI-' . $prefix_comm . '-' . substr($num, strlen($num) - 4, 4);
 166                  $num = 'FI-' . $prefix_comm . '-' . $num;
 167                  return $num;
 168              }
 169          }
 170          else
 171          {
 172              print $this->db->error();
 173          }
 174      }
 175  
 176      /*
 177       *
 178       *
 179       */
 180      function fetch($rowid)
 181      {
 182  
 183          $sql = "SELECT ref,note,fk_soc,fk_statut,duree,".$this->db->pdate(datei)."as di, fk_projet FROM ".MAIN_DB_PREFIX."fichinter WHERE rowid=$rowid;";
 184  
 185          if ($this->db->query($sql) )
 186          {
 187              if ($this->db->num_rows())
 188              {
 189                  $obj = $this->db->fetch_object();
 190  
 191                  $this->id         = $rowid;
 192                  $this->date       = $obj->di;
 193                  $this->duree      = $obj->duree;
 194                  $this->ref        = $obj->ref;
 195                  $this->note       = stripslashes($obj->note);
 196                  $this->societe_id = $obj->fk_soc;
 197                  $this->projet_id  = $obj->fk_projet;
 198                  $this->statut     = $obj->fk_statut;
 199  
 200                  $this->db->free();
 201                  return 1;
 202              }
 203          }
 204          else
 205          {
 206              print $this->db->error();
 207              return 0;
 208          }
 209      }
 210  
 211      /*
 212       *
 213       *
 214       */
 215      function valid($userid, $outputdir)
 216      {
 217          $action_notify = 1; // ne pas modifier cette valeur
 218  
 219          $this->fetch($this->id);
 220  
 221          $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid";
 222          $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
 223  
 224          if ($this->db->query($sql) )
 225          {
 226              /*
 227               * Set generates files readonly
 228               */
 229              umask(0);
 230              $file = $outputdir . "/$this->ref/$this->ref.tex";
 231              if (is_writeable($file))
 232              {
 233                  chmod($file, 0444);
 234              }
 235              $file = $outputdir . "/$this->ref/$this->ref.ps";
 236              if (is_writeable($file))
 237              {
 238                  chmod($file, 0444);
 239              }
 240              $filepdf = $conf->fichinter->dir_output . "/$this->ref/$this->ref.pdf";
 241              if (is_writeable($filepdf))
 242              {
 243                  chmod($filepdf, 0444);
 244              }
 245  
 246              /*
 247               * Notify
 248               */
 249              $mesg = "La fiche d'intervention ".$this->ref." a été validée.\n";
 250  
 251              $notify = New Notify($this->db);
 252              $notify->send($action_notify, $this->societe_id, $mesg, "ficheinter", $this->id, $filepdf);
 253  
 254              return 1;
 255          }
 256          else
 257          {
 258              print $this->db->error() . ' in ' . $sql;
 259              return -1;
 260          }
 261  
 262      }
 263  
 264      /*
 265       *    \brief      Charge la liste des clients depuis la base
 266       */
 267      function fetch_client()
 268      {
 269          $client = new Societe($this->db);
 270          $client->fetch($this->societe_id);
 271          $this->client = $client;
 272      }
 273  
 274      /*
 275       *    \brief      Charge les infos du projet depuis la base
 276       *
 277       */
 278      function fetch_projet()
 279      {
 280          $projet = new Project($this->db);
 281          $projet->fetch($this->projet_id);
 282          $this->projet = $projet->title;
 283      }
 284  
 285  
 286      /**
 287       *    \brief      Retourne le libellé du statut de l'intervantion
 288       *    \return     string      Libellé
 289       */
 290      function getLibStatut()
 291      {
 292          return $this->LibStatut($this->statut);
 293      }
 294  
 295      /**
 296       *    \brief      Renvoi le libellé d'un statut donné
 297       *    \param      statut      id statut
 298       *    \return     string      Libellé
 299       */
 300      function LibStatut($statut)
 301      {
 302          return $this->statuts[$statut];
 303      }
 304  }  
 305  ?>
 306      


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