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

   1  <?php
   2  /* Copyright (C) 2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   3   *
   4   * This program is free software; you can redistribute it and/or modify
   5   * it under the terms of the GNU General Public License as published by
   6   * the Free Software Foundation; either version 2 of the License, or
   7   * (at your option) any later version.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   *
  18   * $Id: interface_webcal.class.php,v 1.6 2005/10/30 17:45:23 eldy Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/includes/triggers/interface_webcal.class.php,v $
  20   */
  21  
  22  /**
  23          \file       htdocs/includes/triggers/interface_webcal.class.php
  24          \ingroup    webcalendar
  25          \brief      Fichier de demo de personalisation des actions du workflow
  26          \remarks    Son propre fichier d'actions peut etre créé par recopie de celui-ci:
  27                      - Le nom du fichier doit etre interface_xxx.class.php
  28                      - Le fichier doit rester stocké dans includes/triggers
  29                      - Le nom de la classe doit etre InterfaceXxx
  30  */
  31  
  32  include_once(DOL_DOCUMENT_ROOT.'/lib/webcal.class.php');
  33  
  34  
  35  /**
  36          \class      InterfaceWebCal
  37          \brief      Classe des fonctions triggers des actions webcalendar
  38  */
  39  
  40  class InterfaceWebCal
  41  {
  42      var $db;
  43      var $error;
  44      
  45      var $date;
  46      var $duree;
  47      var $texte;
  48      var $desc;
  49      
  50      /**
  51       *   \brief      Constructeur.
  52       *   \param      DB      Handler d'accès base
  53       */
  54      function InterfaceWebCal($DB)
  55      {
  56          $this->db = $DB ;
  57      
  58          $this->name = "WebCal";
  59          $this->family = "webcal";
  60          $this->description = "Les triggers de ce composant permettent d'insérer un évênement dans le calendrier webcalendar pour chaque grand évênement Dolibarr.";
  61          $this->version = 'dolibarr';                        // 'experimental' or 'dolibarr' or version
  62      }
  63      
  64      /**
  65       *   \brief      Renvoi nom du lot de triggers
  66       *   \return     string      Nom du lot de triggers
  67       */
  68      function getName()
  69      {
  70          return $this->name;
  71      }
  72      
  73      /**
  74       *   \brief      Renvoi descriptif du lot de triggers
  75       *   \return     string      Descriptif du lot de triggers
  76       */
  77      function getDesc()
  78      {
  79          return $this->description;
  80      }
  81  
  82      /**
  83       *   \brief      Renvoi version du lot de triggers
  84       *   \return     string      Version du lot de triggers
  85       */
  86      function getVersion()
  87      {
  88          global $langs;
  89          $langs->load("admin");
  90  
  91          if ($this->version == 'experimental') return $langs->trans("Experimental");
  92          elseif ($this->version == 'dolibarr') return DOL_VERSION;
  93          elseif ($this->version) return $this->version;
  94          else return $langs->trans("Unknown");
  95      }
  96  
  97      /**
  98       *      \brief      Fonction appelée lors du déclenchement d'un évènement Dolibarr.
  99       *                  D'autres fonctions run_trigger peuvent etre présentes dans includes/triggers
 100       *      \param      action      Code de l'evenement
 101       *      \param      object      Objet concerné
 102       *      \param      user        Objet user
 103       *      \param      lang        Objet lang
 104       *      \param      conf        Objet conf
 105       *      \return     int         <0 si ko, 0 si aucune action faite, >0 si ok
 106       */
 107      function run_trigger($action,$object,$user,$langs,$conf)
 108      {
 109          // Mettre ici le code à exécuter en réaction de l'action
 110          // Les données de l'action sont stockées dans $object
 111  
 112          if (! $conf->webcal->enabled) return 0;     // Module non actif
 113          if (! $object->use_webcal) return 0;        // Option syncro webcal non active
 114  
 115          // Actions
 116          if ($action == 'ACTION_CREATE')
 117          {
 118              dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
 119              $langs->load("other");
 120  
 121              // Initialisation donnees (date,duree,texte,desc)
 122              if ($object->type_id == 5 && $object->contact->fullname)
 123              {
 124                  $libellecal =$langs->trans("TaskRDVWith",$object->contact->fullname)."\n";
 125                  $libellecal.=$object->note;
 126              }
 127              else
 128              {
 129                  $libellecal="";
 130                  if ($langs->trans("Action".$object->type_code) != "Action".$object->type_code)
 131                  {
 132                      $libellecal.=$langs->trans("Action".$object->type_code)."\n";
 133                  }
 134                  $libellecal.=($object->label!=$libellecal?$object->label."\n":"");
 135                  $libellecal.=($object->note?$object->note:"");
 136              }
 137  
 138              $this->date=$object->date;
 139              $this->duree=$object->duree;
 140              $this->texte=$object->societe->nom;
 141              $this->desc=$libellecal;
 142          }
 143  
 144          if ($action == 'COMPANY_CREATE')
 145          {
 146              dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
 147              $langs->load("other");
 148              
 149              // Initialisation donnees (date,duree,texte,desc)
 150              $this->date=time();
 151              $this->duree=0;
 152              $this->texte=$langs->trans("NewCompanyToDolibarr",$object->nom);
 153              $this->desc=$langs->trans("NewCompanyToDolibarr",$object->nom);
 154              $this->desc.="\n".$langs->trans("Prefix").': '.$object->prefix;
 155              //$this->desc.="\n".$langs->trans("Customer").': '.yn($object->client);
 156              //$this->desc.="\n".$langs->trans("Supplier").': '.yn($object->fournisseur);
 157              $this->desc.="\n".$langs->trans("Author").': '.$user->code;
 158          }
 159  
 160          if ($action == 'CONTRACT_VALIDATE')
 161          {
 162              dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
 163              $langs->load("other");
 164  
 165              // Initialisation donnees (date,duree,texte,desc)
 166              $this->date=time();
 167              $this->duree=0;
 168              $this->texte=$langs->trans("ContractValidatedInDolibarr",$object->ref);
 169              $this->desc=$langs->trans("ContractValidatedInDolibarr",$object->ref);
 170              $this->desc.="\n".$langs->trans("Author").': '.$user->code;
 171          }
 172          if ($action == 'CONTRACT_CANCEL')
 173          {
 174              dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
 175              $langs->load("other");
 176  
 177              $this->date=time();
 178              $this->duree=0;
 179              $this->texte=$langs->trans("ContractCanceledInDolibarr",$object->ref);
 180              $this->desc=$langs->trans("ContractCanceledInDolibarr",$object->ref);
 181              $this->desc.="\n".$langs->trans("Author").': '.$user->code;
 182          }
 183          if ($action == 'CONTRACT_CLOSE')
 184          {
 185              dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
 186              $langs->load("other");
 187  
 188              $this->date=time();
 189              $this->duree=0;
 190              $this->texte=$langs->trans("ContractClosedInDolibarr",$object->ref);
 191              $this->desc=$langs->trans("ContractClosedInDolibarr",$object->ref);
 192              $this->desc.="\n".$langs->trans("Author").': '.$user->code;
 193          }
 194  
 195          if ($action == 'BILL_VALIDATE')
 196          {
 197              dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
 198              $langs->load("other");
 199  
 200              $this->date=time();
 201              $this->duree=0;
 202              $this->texte=$langs->trans("InvoiceValidatedInDolibarr",$object->ref);
 203              $this->desc=$langs->trans("InvoiceValidatedInDolibarr",$object->ref);
 204              $this->desc.="\n".$langs->trans("Author").': '.$user->code;
 205          }
 206          if ($action == 'BILL_PAYED')
 207          {
 208              dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
 209              $langs->load("other");
 210  
 211              $this->date=time();
 212              $this->duree=0;
 213              $this->texte=$langs->trans("InvoicePayedInDolibarr",$object->ref);
 214              $this->desc=$langs->trans("InvoicePayedInDolibarr",$object->ref);
 215              $this->desc.="\n".$langs->trans("Author").': '.$user->code;
 216          }
 217          if ($action == 'BILL_CANCELED')
 218          {
 219              dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
 220              $langs->load("other");
 221  
 222              $this->date=time();
 223              $this->duree=0;
 224              $this->texte=$langs->trans("InvoiceCanceledInDolibarr",$object->ref);
 225              $this->desc=$langs->trans("InvoiceCanceledInDolibarr",$object->ref);
 226              $this->desc.="\n".$langs->trans("Author").': '.$user->code;
 227          }
 228  
 229          // Ajoute entrée dans webcal
 230          if ($this->date)
 231          {
 232  
 233              // Crée objet webcal et connexion avec params $conf->webcal->db->xxx
 234              $webcal = new Webcal();
 235              if (! $webcal->localdb->ok)
 236              {
 237                  // Si la creation de l'objet n'as pu se connecter
 238                  $error ="Dolibarr n'a pu se connecter à la base Webcalendar avec les identifiants définis (host=".$conf->webcal->db->host." dbname=".$conf->webcal->db->name." user=".$conf->webcal->db->user.").";
 239                  $error.=" L'option de mise a jour Webcalendar a été ignorée.";
 240                  $this->error=$error;
 241      
 242                  dolibarr_syslog("interface_webcal.class.php: ".$this->error);
 243                  return -1;
 244              }
 245  
 246              $webcal->date=$this->date;
 247              $webcal->duree=$this->duree;
 248              $webcal->texte=$this->texte;
 249              $webcal->desc=$this->desc;
 250  
 251              $result=$webcal->add($user);
 252              if ($result > 0)
 253              {
 254                  return 1;
 255              }
 256              else
 257              {
 258                  $this->error="Echec insertion dans webcal: ".$webcal->error;
 259                  return -1;
 260              }
 261          }
 262          
 263          return 0;
 264      }
 265  
 266  }
 267  ?>


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