| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> 4 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> 5 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 * 21 * $Id: adherent_options.class.php,v 1.15 2004/10/19 18:58:50 opensides Exp $ 22 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/adherents/adherent_options.class.php,v $ 23 * 24 */ 25 26 /*! \file htdocs/adherents/adherent_options.class.php 27 \ingroup adherent 28 \brief Fichier de la classe de gestion de la table des champs optionels adhérents 29 \author Rodolphe Quiedville 30 \author Jean-Louis Bergamo 31 \author Sebastien Di Cintio 32 \author Benoit Mortier 33 \version $Revision: 1.15 $ 34 */ 35 36 /*! \class AdherentOptions 37 \brief Classe de gestion de la table des champs optionels adhérents 38 */ 39 40 class AdherentOptions 41 { 42 var $id; 43 var $db; 44 /* 45 * Tableau contenant le nom des champs en clef et la definition de 46 * ces champs 47 */ 48 var $attribute_name; 49 /* 50 * Tableau contenant le nom des champs en clef et le label de ces 51 * champs en value 52 */ 53 var $attribute_label; 54 55 var $errorstr; 56 /* 57 * Constructor 58 * 59 */ 60 61 /*! 62 \brief AdherentOptions 63 \param DB base de données 64 \param id id de l'adhérent 65 */ 66 67 function AdherentOptions($DB, $id='') 68 { 69 $this->db = $DB ; 70 $this->id = $id; 71 $this->errorstr = array(); 72 $this->attribute_name = array(); 73 $this->attribute_label = array(); 74 } 75 76 /*! 77 \brief fonction qui imprime un liste d'erreurs 78 */ 79 function print_error_list() 80 { 81 $num = sizeof($this->errorstr); 82 for ($i = 0 ; $i < $num ; $i++) 83 { 84 print "<li>" . $this->errorstr[$i]; 85 } 86 } 87 88 /*! 89 \brief fonction qui vérifie les données entrées 90 \param minimum 91 */ 92 function check($minimum=0) 93 { 94 $err = 0; 95 96 if (strlen(trim($this->societe)) == 0) 97 { 98 if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0) 99 { 100 $error_string[$err] = "Vous devez saisir vos nom et prénom ou le nom de votre société."; 101 $err++; 102 } 103 } 104 105 if (strlen(trim($this->adresse)) == 0) 106 { 107 $error_string[$err] = "L'adresse saisie est invalide"; 108 $err++; 109 } 110 111 /* 112 * Return errors 113 * 114 */ 115 116 if ($err) 117 { 118 $this->errorstr = $error_string; 119 return 0; 120 } 121 else 122 { 123 return 1; 124 } 125 126 } 127 128 /*! 129 \brief fonction qui crée un attribut optionnel 130 \param attrname nom de l'atribut 131 \param type type de l'attribut 132 \param length longuer de l'attribut 133 134 \remarks Ceci correspond a une modification de la table et pas a un rajout d'enregistrement 135 */ 136 137 function create($attrname,$type='varchar',$length=255) { 138 /* 139 * Insertion dans la base 140 */ 141 if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-]*$/",$attrname)){ 142 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."adherent_options "; 143 switch ($type){ 144 case 'varchar' : 145 case 'interger' : 146 $sql .= " ADD $attrname $type($length)"; 147 break; 148 case 'text' : 149 case 'date' : 150 case 'datetime' : 151 $sql .= " ADD $attrname $type"; 152 break; 153 default: 154 $sql .= " ADD $attrname $type"; 155 break; 156 } 157 158 if ($this->db->query($sql)) 159 { 160 return 1; 161 } 162 else 163 { 164 dolibarr_print_error($this->db); 165 return 0; 166 } 167 }else{ 168 return 0; 169 } 170 } 171 172 /*! 173 \brief fonction qui crée un label 174 \param attrname nom de l'atribut 175 \param label nom du label 176 */ 177 178 function create_label($attrname,$label='') { 179 /* 180 * Insertion dans la base 181 */ 182 if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-]*$/",$attrname)) { 183 $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label SET "; 184 $escaped_label=mysql_escape_string($label); 185 $sql .= " name='$attrname',label='$escaped_label' "; 186 187 if ($this->db->query($sql)) 188 { 189 return 1; 190 } 191 else 192 { 193 print dolibarr_print_error($this->db); 194 return 0; 195 } 196 } 197 } 198 199 /*! 200 \brief fonction qui supprime un attribut 201 \param attrname nom de l'atribut 202 */ 203 204 function delete($attrname) 205 { 206 if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-]*$/",$attrname)){ 207 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."adherent_options DROP COLUMN $attrname"; 208 209 if ( $this->db->query( $sql) ) 210 { 211 return $this->delete_label($attrname); 212 } 213 else 214 { 215 print dolibarr_print_error($this->db); 216 return 0; 217 } 218 }else{ 219 return 0; 220 } 221 222 } 223 224 /*! 225 \brief fonction qui supprime un label 226 \param attrname nom du label 227 */ 228 229 function delete_label($attrname) 230 { 231 if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-]*$/",$attrname)){ 232 $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label WHERE name='$attrname'"; 233 234 if ( $this->db->query( $sql) ) 235 { 236 return 1; 237 } 238 else 239 { 240 print dolibarr_print_error($this->db); 241 return 0; 242 } 243 }else{ 244 return 0; 245 } 246 247 } 248 249 /*! 250 \brief fonction qui modifie un attribut optionnel 251 \param attrname nom de l'atribut 252 \param type type de l'attribut 253 \param length longuer de l'attribut 254 */ 255 256 function update($attrname,$type='varchar',$length=255) 257 { 258 if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-]*$/",$attrname)){ 259 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."adherent_options "; 260 switch ($type){ 261 case 'varchar' : 262 case 'interger' : 263 $sql .= " MODIFY COLUMN $attrname $type($length)"; 264 break; 265 case 'text' : 266 case 'date' : 267 case 'datetime' : 268 $sql .= " MODIFY COLUMN $attrname $type"; 269 break; 270 default: 271 $sql .= " MODIFY COLUMN $attrname $type"; 272 break; 273 } 274 //$sql .= "MODIFY COLUMN $attrname $type($length)"; 275 276 if ( $this->db->query( $sql) ) 277 { 278 return 1; 279 } 280 else 281 { 282 print dolibarr_print_error($this->db); 283 return 0; 284 } 285 }else{ 286 return 0; 287 } 288 289 } 290 291 /*! 292 \brief fonction qui modifie un label 293 \param attrname nom de l'atribut 294 \param label nom du label 295 */ 296 297 function update_label($attrname,$label='') 298 { 299 if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-]*$/",$attrname)){ 300 $escaped_label=mysql_escape_string($label); 301 $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label WHERE name = 302 '$attrname';"; 303 $this->db->query($sql_del); 304 $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label (name,label) 305 VALUES ('$attrname','$escaped_label');"; 306 //$sql = "REPLACE INTO ".MAIN_DB_PREFIX."adherent_options_label SET name='$attrname',label='$escaped_label'"; 307 308 if ( $this->db->query( $sql) ) 309 { 310 return 1; 311 } 312 else 313 { 314 print dolibarr_print_error($this->db); 315 return 0; 316 } 317 }else{ 318 return 0; 319 } 320 321 } 322 323 324 /*! 325 \brief fonction qui modifie un label 326 */ 327 function fetch_optionals() 328 { 329 $this->fetch_name_optionals(); 330 $this->fetch_name_optionals_label(); 331 } 332 333 334 /*! 335 \brief fonction qui modifie un label 336 */ 337 function fetch_name_optionals() 338 { 339 $array_name_options=array(); 340 $sql = "SHOW COLUMNS FROM ".MAIN_DB_PREFIX."adherent_options"; 341 342 if ( $this->db->query( $sql) ) 343 { 344 if ($this->db->num_rows()) 345 { 346 while ($tab = $this->db->fetch_object()) 347 { 348 if ($tab->Field != 'optid' && $tab->Field != 'tms' && $tab->Field != 'adhid') 349 { 350 // we can add this attribute to adherent object 351 $array_name_options[]=$tab->Field; 352 $this->attribute_name[$tab->Field]=$tab->Type; 353 } 354 } 355 return $array_name_options; 356 }else{ 357 return array(); 358 } 359 }else{ 360 print $this->db->error(); 361 return array() ; 362 } 363 364 } 365 366 /*! 367 \brief fonction qui modifie un label 368 */ 369 function fetch_name_optionals_label() 370 { 371 $array_name_label=array(); 372 $sql = "SELECT name,label FROM ".MAIN_DB_PREFIX."adherent_options_label"; 373 374 if ( $this->db->query( $sql) ) 375 { 376 if ($this->db->num_rows()) 377 { 378 while ($tab = $this->db->fetch_object()) 379 { 380 // we can add this attribute to adherent object 381 $array_name_label[$tab->name]=stripslashes($tab->label); 382 $this->attribute_label[$tab->name]=stripslashes($tab->label); 383 } 384 return $array_name_label; 385 }else{ 386 return array(); 387 } 388 }else{ 389 print dolibarr_print_error($this->db); 390 return array() ; 391 } 392 393 } 394 } 395 ?>
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 |
|