[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> 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 * or see http://www.gnu.org/ 18 * 19 * $Id: mod_codeclient_zebre.php,v 1.7 2005/02/17 11:46:41 rodolphe Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/includes/modules/societe/mod_codeclient_zebre.php,v $ 21 * 22 */ 23 24 class mod_codeclient_zebre 25 { 26 27 function mod_codeclient_zebre() 28 { 29 $this->nom = "Zèbre"; 30 31 $this->code_modifiable = 0; // code modifiable 32 33 $this->code_modifiable_invalide = 0; // code modifiable si il est invalide 34 35 $this->code_modifiable_null = 1; // code modifiable si il est null 36 37 $this->code_null = 0; // Saisi vide interdite 38 39 } 40 /*! \brief Renvoi la description du module 41 * \return string Texte descripif 42 */ 43 function info() 44 { 45 return "Vérifie si le code client est de la forme ABCD5600. Les quatres premières lettres étant une représentation mnémotechnique, suivi du code postal en 2 chiffres et un numéro d'ordre pour la prise en compte des doublons."; 46 } 47 48 /** 49 * Vérifie la validité du code 50 * 51 * 52 */ 53 54 function verif($db, &$code, $socid=0) 55 { 56 $code = strtoupper(trim($code)); 57 58 if ($this->verif_syntax($code) == 0) 59 { 60 $i = 1; 61 62 $is_dispo = $this->verif_dispo($db, $code, $socid); 63 64 while ( $is_dispo <> 0 && $i < 99) 65 { 66 $arr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 67 68 $code = substr($code,0,6) . substr("00".$i, -2); 69 70 $is_dispo = $this->verif_dispo($db, $code); 71 72 $i++; 73 } 74 75 if ($is_dispo <> 0) 76 { 77 return -3; 78 } 79 } 80 else 81 { 82 if (strlen(trim($code)) == 0) 83 { 84 return -2; 85 } 86 else 87 { 88 return -1; 89 } 90 } 91 } 92 93 function get_correct($db, &$code) 94 { 95 $code = strtoupper(trim($code)); 96 97 if ($this->verif_syntax($code) == 0) 98 { 99 $i = 1; 100 101 $is_dispo = $this->verif_dispo($db, $code); 102 103 while ( $is_dispo <> 0 && $i < 99) 104 { 105 $arr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 106 107 $code = substr($code,0,6) . substr("00".$i, -2); 108 109 $is_dispo = $this->verif_dispo($db, $code); 110 111 $i++; 112 } 113 114 return $is_dispo; 115 116 } 117 else 118 { 119 return -1; 120 } 121 122 } 123 124 function verif_dispo($db, $code) 125 { 126 $code = strtoupper(trim($code)); 127 128 $sql = "SELECT code_client FROM ".MAIN_DB_PREFIX."societe"; 129 $sql .= " WHERE code_client = '".$code."'"; 130 131 if ($db->query($sql)) 132 { 133 if ($db->num_rows() == 0) 134 { 135 return 0; 136 } 137 else 138 { 139 return -1; 140 } 141 } 142 else 143 { 144 return -2; 145 } 146 147 } 148 149 150 function verif_syntax(&$code) 151 { 152 $res = 0; 153 154 $code = strtoupper(trim($code)); 155 156 if (strlen($code) <> 8) 157 { 158 $res = -1; 159 } 160 else 161 { 162 if ($this->is_alpha(substr($code,0,4)) == 0 && $this->is_num(substr($code,4,4)) == 0 ) 163 { 164 $res = 0; 165 } 166 else 167 { 168 $res = -2; 169 } 170 171 } 172 return $res; 173 } 174 175 176 function is_alpha($str) 177 { 178 $ok = 0; 179 // Je n'ai pas trouvé de fonction pour tester une chaine alpha sans les caractère accentués 180 // dommage 181 $alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 182 183 for ($i = 0 ; $i < 4 ; $i++) 184 { 185 if (strpos($alpha, substr($str,$i, 1)) === false) 186 { 187 $ok++; 188 } 189 } 190 191 return $ok; 192 } 193 194 function is_num($str) 195 { 196 $ok = 0; 197 198 $alpha = '0123456789'; 199 200 for ($i = 0 ; $i < 4 ; $i++) 201 { 202 if (strpos($alpha, substr($str,$i, 1)) === false) 203 { 204 $ok++; 205 } 206 } 207 208 return $ok; 209 } 210 211 } 212 213 ?>
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 |
![]() |