| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
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: webcal.class.php,v 1.18 2005/09/11 16:30:01 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/lib/webcal.class.php,v $ 21 */ 22 23 /** 24 \file htdocs/lib/webcal.class.php 25 \ingroup webcalendar 26 \brief Ensemble des fonctions permettant d'acceder a la database webcalendar. 27 \author Rodolphe Quiedeville. 28 \author Laurent Destailleur. 29 \version $Revision: 1.18 $ 30 */ 31 32 33 /** 34 \class Webcal 35 \brief Classe permettant d'acceder a la database webcalendar 36 */ 37 38 class Webcal { 39 40 var $localdb; 41 42 var $date; 43 var $duree = 0; // Secondes 44 var $texte; 45 var $desc; 46 47 var $error; 48 49 50 /** 51 \brief Constructeur de la classe d'interface à Webcalendar 52 */ 53 function Webcal() 54 { 55 global $conf; 56 global $dolibarr_main_db_type,$dolibarr_main_db_host,$dolibarr_main_db_user; 57 global $dolibarr_main_db_pass,$dolibarr_main_db_name; 58 59 // Défini parametres webcal (avec substitution eventuelle) 60 $webcaltype=eregi_replace('__dolibarr_main_db_type__',$dolibarr_main_db_type,$conf->webcal->db->type); 61 $webcalhost=eregi_replace('__dolibarr_main_db_host__',$dolibarr_main_db_host,$conf->webcal->db->host); 62 $webcaluser=eregi_replace('__dolibarr_main_db_user__',$dolibarr_main_db_user,$conf->webcal->db->user); 63 $webcalpass=eregi_replace('__dolibarr_main_db_pass__',$dolibarr_main_db_pass,$conf->webcal->db->pass); 64 $webcalname=eregi_replace('__dolibarr_main_db_name__',$dolibarr_main_db_name,$conf->webcal->db->name); 65 66 // On initie la connexion à la base Webcalendar 67 require_once (DOL_DOCUMENT_ROOT ."/lib/".$webcaltype.".lib.php"); 68 $this->localdb = new DoliDb($webcaltype,$webcalhost,$webcaluser,$webcalpass,$webcalname); 69 } 70 71 72 /** 73 \brief Ajoute objet en tant qu'entree dans le calendrier de l'utilisateur 74 \param[in] user Le login de l'utilisateur 75 \return int 1 en cas de succès, -1,-2,-3 en cas d'erreur, -4 si login webcal non défini 76 */ 77 function add($user) 78 { 79 global $langs; 80 81 dolibarr_syslog("Webcal::add user=$user"); 82 83 // Test si login webcal défini pour le user 84 if (! $user->webcal_login) { 85 $this->error=$langs->trans("ErrorWebcalLoginNotDefined","<a href=\"".DOL_URL_ROOT."/user/fiche.php?id=".$user->id."\">".$user->login."</a>"); 86 return -4; 87 } 88 89 $this->localdb->begin(); 90 91 // Recupère l'id max+1 dans la base webcalendar 92 $id = $this->get_next_id(); 93 94 if ($id > 0) 95 { 96 $cal_id = $id; 97 $cal_create_by = $user->webcal_login; 98 $cal_date = strftime('%Y%m%d', $this->date); 99 $cal_time = strftime('%H%M%S', $this->date); 100 $cal_mod_date = strftime('%Y%m%d', time()); 101 $cal_mod_time = strftime('%H%M%S', time()); 102 $cal_duration = round($this->duree / 60); 103 $cal_priority = 2; 104 $cal_type = "E"; 105 $cal_access = "P"; 106 $cal_name = $this->texte; 107 $cal_description = $this->desc; 108 109 $sql = "INSERT INTO webcal_entry (cal_id, cal_create_by,cal_date,cal_time,cal_mod_date, cal_mod_time,cal_duration,cal_priority,cal_type, cal_access, cal_name,cal_description)"; 110 $sql.= " VALUES ($cal_id, '$cal_create_by', '$cal_date', '$cal_time', '$cal_mod_date', '$cal_mod_time', $cal_duration, $cal_priority, '$cal_type', '$cal_access', '$cal_name','$cal_description')"; 111 112 if ($this->localdb->query($sql)) 113 { 114 $sql = "INSERT INTO webcal_entry_user (cal_id, cal_login, cal_status)"; 115 $sql .= " VALUES ($cal_id, '$cal_create_by', 'A')"; 116 117 if ( $this->localdb->query($sql) ) 118 { 119 // OK 120 $this->localdb->commit(); 121 return 1; 122 } 123 else 124 { 125 $this->localdb->rollback(); 126 $this->error = $this->localdb->error() . '<br>' .$sql; 127 return -1; 128 } 129 } 130 else 131 { 132 $this->localdb->rollback(); 133 $this->error = $this->localdb->error() . '<br>' .$sql; 134 return -2; 135 } 136 } 137 else 138 { 139 $this->localdb->rollback(); 140 $this->error = $this->localdb->error() . '<br>' .$sql; 141 return -3; 142 } 143 } 144 145 146 /** 147 \brief Obtient l'id suivant dans le webcalendar 148 \return int Retourne l'id suivant dans webcalendar, <0 si ko 149 */ 150 function get_next_id() 151 { 152 $sql = "SELECT max(cal_id) as id FROM webcal_entry"; 153 154 $resql=$this->localdb->query($sql); 155 if ($resql) 156 { 157 $obj=$this->localdb->fetch_object($resql); 158 return ($obj->id + 1); 159 } 160 else 161 { 162 $this->error=$this->localdb->error(); 163 return -1; 164 } 165 } 166 167 } 168 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
|