[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2000,2001 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * 4 * $Id: functions.lib.php,v 1.4 2004/10/23 17:01:20 eldy Exp $ 5 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/bank/functions.lib.php,v $ 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 * or see http://www.gnu.org/ 21 */ 22 23 function gljDbConnect() { 24 return pg_Connect($GLOBALS["DB_HOST"], 25 $GLOBALS["DB_PORT"], 26 $GLOBALS["DB_OPTIONS"], 27 $GLOBALS["DB_TTY"], 28 $GLOBALS["DB_NAME"]); 29 } 30 31 function gljPrintSelect($db, $refid) { 32 $num = $db->num_rows(); 33 $i = 0; 34 while ($i < $num) { 35 $obj = $db->fetch_object(); 36 print "<OPTION VALUE=$obj->id"; 37 if ($refid==$obj->id) { 38 print " SELECTED"; 39 } 40 print ">$obj->libelle</OPTION>\n"; 41 $i++; 42 } 43 } 44 /* 45 * Copy company def from one base to another 46 */ 47 48 function gljCopy_Soc($idsoc, $dbfrom, $dbto) { 49 global $dbhost, $dbport, $dboptions, $dbtty, $DB_LOGIN_NAME, $dbname, $DB_NAME; 50 51 // Add login info into login table 52 53 $connfrom = pg_Connect($dbhost, $dbport, $dboptions, $dbtty, $DB_NAME["$dbfrom"]); 54 $connto = pg_Connect($dbhost, $dbport, $dboptions, $dbtty, $DB_NAME["$dbto"]); 55 $connlogin = pg_Connect($DB_LOGIN_HOST, $DB_LOGIN_PORT , $dboptions, $dbtty ,$DB_LOGIN_NAME); 56 57 $madate = time(); 58 59 if ($connfrom) { 60 if ($connto) { 61 if ($connlogin) { 62 $sql = "SELECT nom, fk_effectif FROM societe WHERE id = '$idsoc'"; 63 $result = pg_Exec($connfrom, $sql); 64 if ( $result ) { 65 if (pg_NumRows($result) ) { 66 $obj = pg_Fetch_Object($result); 67 68 $sql = "INSERT INTO societe (id, nom, datec, fk_effectif) "; 69 $sql .= "VALUES ('$idsoc', '$obj->nom', $madate, $obj->fk_effectif)"; 70 71 $result = pg_Exec($connto, $sql); 72 if ( $result ) { 73 $sql = "UPDATE login SET pays = pays || ':$dbto' WHERE id = '$idsoc'"; 74 $result = pg_Exec($connlogin, $sql); 75 if ( $result ) { 76 // ALL success 77 return 0; 78 } 79 } 80 } else { 81 // this login exists 82 return 2; 83 } 84 } 85 pg_close($connlogin); 86 } 87 pg_close($connto); 88 } 89 pg_close($connfrom); 90 } 91 } 92 /* 93 * Envoie le login lors de la premiere connexion au compte 94 */ 95 function gljMailLogin ($db, $address, $id, $dbname) { 96 97 $sql = "SELECT login, clearpass FROM login where id='$id' "; 98 99 if ($db->query($sql)) { 100 if ($db->num_rows() > 0) { 101 $obj = $db->fetch_object(); 102 $db->free(); 103 104 $subject = "Confirmation"; 105 $mess = "Vous venez de déposer votre CV sur http://".$GLOBALS["GLJ_NORMAL_HOST"]."\n"; 106 $mess .= "\n\n"; 107 $mess .= "login : $obj->login\n"; 108 $mess .= "pass : $obj->clearpass\n"; 109 $mess .= "\n-----------------------------\n"; 110 $mess .= "contact : " . $GLOBALS["WEBMASTER"]; 111 $mess .= "\n-----------------------------\n"; 112 113 $return = mail("$address","$subject","$mess","From: " . $GLOBALS["WEBMASTER"]); 114 } 115 } 116 } 117 // 118 // 119 // 120 function gljFooter_Cursor ($file, $page, $limit, $i, $parm="") { 121 $page_prev = $page - 1; 122 $page_next = $page + 1; 123 124 print "<TABLE width=\"100%\" border=\"0\" cellspacing=\"2\"><TR><TD>"; 125 126 if ( $page ) { 127 print "<A href=\"$file?page=$page_prev$parm\" class=\"T3\">" . $GLOBALS["_PAGE_PREV"] . "</A>"; 128 } 129 130 print "</TD><TD align=\"right\">"; 131 132 if ( $i > ( $limit - 1 ) ) { 133 print "<A href=\"$file?page=$page_next$parm\" class=\"T3\">" . $GLOBALS["_PAGE_NEXT"] . "</A>"; 134 } 135 136 print "</TD></TR></TABLE>\n"; 137 } 138 // 139 // 140 // 141 142 /* 143 * 144 * Verif info 145 * 146 */ 147 function gljVerif_NewLogin($login, $pass, $pass2) { 148 if (! strlen($login) ) { 149 return 3; 150 exit; 151 } 152 if ( $pass <> $pass2 ) { 153 return 1; 154 exit; 155 } 156 if (! strlen($pass) ) { 157 return 5; 158 exit; 159 } 160 return 0; 161 } 162 // 163 // Create new candidat login 164 // 165 function gljCreate_Login_Cand($db, $login, $pass, $pass2) { 166 global $dbhost, $dbport, $dboptions, $dbtty, $DB_LOGIN_NAME, $dbname; 167 168 // Check validity 169 $return = gljVerif_NewLogin($login, $pass, $pass2); 170 if ( $return ) { 171 return $return; 172 exit; 173 } 174 // Add login info into login table 175 176 $madate = $db->idate(time()); 177 $passmd5 = md5($pass); 178 $token = uniqid("CAN"); 179 180 $sql = "SELECT login FROM login WHERE login = '$login'"; 181 182 if ( $db->query($sql) ) { 183 if (! $db->num_rows() ) { 184 $sql = "INSERT INTO login VALUES ('$token','$login', '$passmd5','$pass', $madate, 'c','" . $GLOBALS["PREFIX"] . "')"; 185 if ( $db->query($sql) ) { 186 // 187 // Create data base in candidat 188 // 189 190 $sql = "INSERT INTO candidat (id, datec,datel, sent, fk_anexpe, reminder, intern, cjn) VALUES ('$token',$madate,$madate, -1, 0, 1, 1, 1)"; 191 if ( $db->query($sql) ) { 192 return 0; 193 } 194 } 195 } else { 196 // this login exists 197 return 2; 198 } 199 } 200 } 201 /* 202 * 203 * 204 * Create new company login 205 * 206 * 207 */ 208 function gljCreateCompany($db, $company_name, $address, $cp, $ville, $fkpays, $phone, $fax, $url, 209 $fksecteur, $fkeffectif, $fktypent, $c_nom, $c_prenom, $c_phone, $c_mail, $siren, 210 $parentidp=0, $setid=0, &$numerror) { 211 /* 212 * Create a new company 213 * - insert data in table societe 214 * - return company's idp 215 */ 216 217 // Check validity 218 $return = gljVerifCompany($company_name, $address, $cp, $ville, $fkpays, $phone, $fax, $url, 219 $fksecteur,$fkeffectif, $c_nom, $c_prenom, $c_phone, $c_mail, $numerror); 220 if ( $return ) { 221 $sql = "INSERT INTO societe (datec,nom,address,cp,ville,tel,fax,url,fk_secteur,fk_effectif,fk_typent"; 222 $sql .= ",c_nom,c_prenom,c_tel,c_mail,karma,view_res_coord,siren,parent"; 223 if ($setid > 0 ) { 224 $sql .= ",id"; 225 } 226 $sql .= ")"; 227 228 $sql .= "VALUES (now(),'$company_name',$address,$cp,$ville,$phone,$fax,$url,$fksecteur,$fkeffectif,$fktypent"; 229 $sql .= ",$c_nom,$c_prenom,$c_phone,'$c_mail', 0, 0,'$siren',$parentidp"; 230 231 if ($setid > 0 ) { 232 if ($setid == 2 ) { 233 $token = uniqid("-OC"); 234 } else { 235 $token = uniqid("SOC"); 236 } 237 $sql .= ",'$token'"; 238 } 239 $sql .= ");"; 240 241 if ( $db->query($sql) ) { 242 $sql = "SELECT idp FROM societe WHERE id= '$token';"; 243 if ( $db->query($sql) ) { 244 if ( $db->num_rows() ) { 245 $obj = $db->fetch_object(); 246 return $obj->idp; 247 $db->free(); 248 249 $sql = "INSERT INTO socpeople (datec, name, firstname, fk_soc, phone, fax, email)"; 250 $sql .= "VALUES (now(),'$c_nom','$c_prenom', $obj->idp, $phone, $fax,$url, '$c_mail')"; 251 if ( $db->query($sql) ) { 252 253 } 254 } 255 } else { 256 print $db->error(); 257 } 258 } else { 259 print $db->error(); 260 return 0; 261 } 262 return 1; 263 } else { 264 /* 265 * Verification Failed 266 */ 267 return 0; 268 } 269 } 270 /* 271 * 272 * 273 */ 274 function gljVerifCompany(&$company_name, &$address, &$cp, &$ville, &$fkpays, &$phone, &$fax, &$url, &$fksecteur,&$fkeffectif, &$c_nom, &$c_prenom, &$c_phone, &$c_mail, &$numerror) { 275 $numerror = 0; 276 277 if (!strlen(trim($company_name))) { $numerror = 4; } 278 if (!gljValidEmail($c_mail)) { $numerror = 8; } 279 if (!strlen(trim($c_mail))) { $numerror = 7; } 280 281 if (strlen(trim($address))) { $address = "'$address'"; } else { $address = "NULL"; } 282 if (strlen(trim($cp))) { $cp = "'".trim($cp) ."'"; } else { $cp = "NULL"; } 283 if (strlen(trim($ville))) { $ville = "'".trim($ville)."'"; } else { $ville = "NULL"; } 284 if (strlen(trim($phone))) { $phone = "'".trim($phone)."'"; } else { $phone = "NULL"; } 285 if (strlen(trim($fax))) { $fax = "'".trim($fax) ."'"; } else { $fax = "NULL"; } 286 if (strlen(trim($url))) { $url = "'".trim($url) ."'"; } else { $url = "NULL"; } 287 if (strlen(trim($c_nom))) { $c_nom = "'".trim($c_nom)."'"; } else { $c_nom = "NULL"; } 288 if (strlen(trim($c_prenom))) { $c_prenom = "'$c_prenom'"; } else { $c_prenom = "NULL"; } 289 if (strlen(trim($c_phone))) { $c_phone = "'$c_phone'"; } else { $c_phone = "NULL"; } 290 291 if ($numerror) { 292 return 0; 293 } else { 294 return 1; 295 } 296 } 297 function gljCreateCompanyMail($to, $subject, $message) { 298 $return = mail($to, $subject, $message, "From: " . $GLOBALS["WEBMASTER"]); 299 } 300 // 301 // 302 function gljValidEmail($email) { 303 if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2}[mtgvu]?$", $email) ) { 304 return 1; 305 } else { 306 return 0; 307 } 308 } 309 // 310 // Create new company login REPLACE by function gljCreate_Company 311 // 312 function gljCreate_Login_Soc($login, $pass, $pass2, $company_name) { 313 global $dbhost, $dbport, $dboptions, $dbtty, $DB_LOGIN_NAME, $dbname; 314 315 // Check validity 316 $return = gljVerif_NewLogin($login, $pass, $pass2); 317 if ( $return ) { 318 return $return; 319 exit; 320 } 321 if (! strlen(trim($company_name))) { 322 return 4; 323 exit; 324 } 325 // Add login info into login table 326 $dbconn = pg_Connect("$dbhost","$dbport","$dboptions","$dbtty",$DB_LOGIN_NAME); 327 $dbconn2 = gljDbConnect(); 328 329 $madate = time(); 330 $passmd5 = md5($pass); 331 $token = uniqid(""); 332 333 if ($dbconn) { 334 if ($dbconn2) { 335 $sql = "SELECT login FROM login WHERE login = '$login'"; 336 337 $result = pg_Exec($dbconn, $sql); 338 if ( $result ) { 339 if (! pg_NumRows($result) ) { 340 $sql = "SELECT nom FROM societe WHERE nom = '$company_name'"; 341 342 $result = pg_Exec($dbconn2, $sql); 343 if ( $result ) { 344 if (! pg_NumRows($result) ) { 345 346 $sql = "INSERT INTO login VALUES ('$token','$login', '$passmd5','$pass', $madate, 's','" . $GLOBALS["PREFIX"] . "')"; 347 $result = pg_Exec($dbconn, $sql); 348 if( $result ) { 349 $sql2 = "INSERT INTO societe (id, datec, nom, fk_effectif, tchoozeid, viewed, cjn, intern) VALUES ('$token', $madate, '$company_name',0,0,0, 1, 1)"; 350 351 $result = pg_Exec($dbconn2, $sql2); 352 return 0; 353 } 354 } else { 355 return 6; 356 } 357 } 358 } else { 359 // this login exists 360 return 2; 361 } 362 } 363 } 364 } 365 } 366 // 367 // Ajoute un outil 368 // 369 function ins_outil ($db, $idp, $outil, $contrib, $niveau, $table, $champ, $fkanexpe=0) { 370 371 $sql = "DELETE FROM $table WHERE $champ=$idp AND fk_outil=$outil;"; 372 if ( $db->query( $sql ) ) { 373 $sql = "INSERT INTO $table ($champ, fk_outil, fk_contrib, fk_niveau, fk_anexpe)"; 374 $sql .= " VALUES ($idp, $outil, $contrib, $niveau, $fkanexpe)" ; 375 376 $result = $db->query( $sql ); 377 if (!$result) { 378 print "Erreur INSERT\n<BR>$sql"; 379 } 380 } 381 } 382 // 383 // 384 // 385 function ins_lang ($db, $idp, $lang, $niveau, $table='lang', $champ='fk_cand') { 386 387 $sql = "DELETE FROM $table WHERE $champ=$idp AND fk_lang=$lang;"; 388 if ( $db->query( $sql ) ) { 389 $sql = "INSERT INTO $table ($champ, fk_lang, fk_niv) VALUES ($idp, $lang, $niveau)" ; 390 391 $result = $db->query($sql); 392 if (!$result) { 393 echo "Erreur INSERT\n$sql"; 394 } 395 } 396 } 397 // 398 // 399 // 400 function get_ofid_by_idp ($db, $ofidp) { 401 $sql = "SELECT id from OFFRE where idp = $ofidp"; 402 403 $result = $db->query( $sql ); 404 405 if (!$result) { 406 return 0; 407 } else { 408 if ($db->num_rows() > 0) { 409 $row = 0; 410 while($data = $db->fetch_object($result)) { 411 $id = $data->id ; 412 } 413 return $id; 414 } 415 } 416 } 417 ?>
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 |
![]() |