| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?PHP 2 /* Copyright (c) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 4 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> 5 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> 6 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 * 22 * $Id: html.form.class.php,v 1.131.2.3 2005/12/25 01:39:31 eldy Exp $ 23 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/html.form.class.php,v $ 24 */ 25 26 /** 27 \file htdocs/html.form.class.php 28 \brief Fichier de la classe des fonctions prédéfinie de composants html 29 \version $Revision: 1.131.2.3 $ 30 */ 31 32 33 /** 34 \class Form 35 \brief Classe permettant la génération de composants html 36 */ 37 38 class Form 39 { 40 var $db; 41 var $errorstr; 42 43 var $cache_types_paiements_code=array(); 44 var $cache_types_paiements_libelle=array(); 45 var $cache_conditions_paiements_code=array(); 46 var $cache_conditions_paiements_libelle=array(); 47 48 49 /** 50 \brief Constructeur 51 \param DB handler d'accès base de donnée 52 */ 53 function Form($DB) 54 { 55 $this->db = $DB; 56 57 return 1; 58 } 59 60 /** 61 \brief Retourne propriétés pour affichae d'un tooltip 62 \param htmltooltip Contenu html du tooltip 63 \return string Chaine des propriétés de declenchement du tooltip 64 */ 65 function tooltip_properties($htmltooltip='Text for tooltip') 66 { 67 global $conf; 68 $s =''; 69 if ($conf->use_javascript) 70 { 71 $s.=' onmouseover="showtip(\''.$htmltooltip.'\')"'; 72 $s.=' onMouseout="hidetip()"'; 73 } 74 return $s; 75 } 76 77 /** 78 \brief Efface champ alt et title pour permettre utiliser dans un tooltip 79 \param string Chaine a nettoyer 80 \return string Chaine nettoyé 81 */ 82 function tooltip_sanitize($string) 83 { 84 global $conf; 85 if ($conf->use_javascript) 86 { 87 // Supprime alt et title de text pour eviter conflit avec tooltip 88 $string=eregi_replace('alt="[^"]+"','',$string); 89 $string=eregi_replace('title="[^"]+"','',$string); 90 } 91 return $string; 92 } 93 94 /** 95 * \brief Retourne la liste déroulante des départements/province/cantons tout pays confondu ou pour un pays donné. 96 * \remarks Dans le cas d'une liste tout pays confondus, l'affichage fait une rupture sur le pays. 97 * \remarks La cle de la liste est le code (il peut y avoir plusieurs entrée pour 98 * un code donnée mais dans ce cas, le champ pays diffère). 99 * Ainsi les liens avec les départements se font sur un département indépendemment de nom som. 100 * \param selected code forme juridique a présélectionné 101 * \param pays_code 0=liste tous pays confondus, sinon code du pays à afficher 102 */ 103 function select_departement($selected='',$pays_code=0) 104 { 105 global $conf,$langs; 106 $langs->load("dict"); 107 108 $htmlname='departement_id'; 109 110 // On recherche les départements/cantons/province active d'une region et pays actif 111 $sql = "SELECT d.rowid, d.code_departement as code , d.nom, d.active, p.libelle as libelle_pays, p.code as code_pays FROM"; 112 $sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_pays as p"; 113 $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=p.rowid"; 114 $sql .= " AND d.active = 1 AND r.active = 1 AND p.active = 1"; 115 if ($pays_code) $sql .= " AND p.code = '".$pays_code."'"; 116 $sql .= " ORDER BY p.code, d.code_departement"; 117 118 $result=$this->db->query($sql); 119 if ($result) 120 { 121 print '<select class="flat" name="'.$htmlname.'">'; 122 if ($pays_code) print '<option value="0"> </option>'; 123 $num = $this->db->num_rows($result); 124 $i = 0; 125 if ($num) 126 { 127 $pays=''; 128 while ($i < $num) 129 { 130 $obj = $this->db->fetch_object($result); 131 if ($obj->code == 0) { 132 print '<option value="0"> </option>'; 133 } 134 else { 135 if (! $pays || $pays != $obj->libelle_pays) { 136 // Affiche la rupture si on est en mode liste multipays 137 if (! $pays_code && $obj->code_pays) { 138 print '<option value="-1">----- '.$obj->libelle_pays." -----</option>\n"; 139 $pays=$obj->libelle_pays; 140 } 141 } 142 143 if ($selected > 0 && $selected == $obj->rowid) 144 { 145 print '<option value="'.$obj->rowid.'" selected="true">'; 146 } 147 else 148 { 149 print '<option value="'.$obj->rowid.'">'; 150 } 151 // Si traduction existe, on l'utilise, sinon on prend le libellé par défaut 152 print $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->nom!='-'?$obj->nom:'')); 153 print '</option>'; 154 } 155 $i++; 156 } 157 } 158 print '</select>'; 159 } 160 else { 161 dolibarr_print_error($this->db); 162 } 163 } 164 165 166 /** 167 * \brief Retourne la liste déroulante des regions actives dont le pays est actif 168 * \remarks La cle de la liste est le code (il peut y avoir plusieurs entrée pour 169 * un code donnée mais dans ce cas, le champ pays et lang diffère). 170 * Ainsi les liens avec les regions se font sur une region independemment 171 * de nom som. 172 */ 173 174 function select_region($selected='',$htmlname='region_id') 175 { 176 global $conf,$langs; 177 $langs->load("dict"); 178 179 $sql = "SELECT r.rowid, r.code_region as code, r.nom as libelle, r.active, p.libelle as libelle_pays FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_pays as p"; 180 $sql .= " WHERE r.fk_pays=p.rowid AND r.active = 1 and p.active = 1 ORDER BY libelle_pays, libelle ASC"; 181 182 if ($this->db->query($sql)) 183 { 184 print '<select class="flat" name="'.$htmlname.'">'; 185 $num = $this->db->num_rows(); 186 $i = 0; 187 if ($num) 188 { 189 $pays=''; 190 while ($i < $num) 191 { 192 $obj = $this->db->fetch_object(); 193 if ($obj->code == 0) { 194 print '<option value="0"> </option>'; 195 } 196 else { 197 if ($pays == '' || $pays != $obj->libelle_pays) { 198 // Affiche la rupture 199 print '<option value="-1">----- '.$obj->libelle_pays." -----</option>\n"; 200 $pays=$obj->libelle_pays; 201 } 202 203 if ($selected > 0 && $selected == $obj->code) 204 { 205 print '<option value="'.$obj->code.'" selected="true">'.$obj->libelle.'</option>'; 206 } 207 else 208 { 209 print '<option value="'.$obj->code.'">'.$obj->libelle.'</option>'; 210 } 211 } 212 $i++; 213 } 214 } 215 print '</select>'; 216 } 217 else { 218 dolibarr_print_error($this->db); 219 } 220 } 221 222 /** 223 * \brief Retourne la liste déroulante des pays actifs, dans la langue de l'utilisateur 224 * \param selected Code pays pré-sélectionné 225 * \param htmlname Nom de la liste deroulante 226 * \param htmloption Options html sur le select 227 * \todo trier liste sur noms après traduction plutot que avant 228 */ 229 230 function select_pays($selected='',$htmlname='pays_id',$htmloption='') 231 { 232 global $conf,$langs; 233 $langs->load("dict"); 234 235 $sql = "SELECT rowid, libelle, code, active FROM ".MAIN_DB_PREFIX."c_pays"; 236 $sql .= " WHERE active = 1"; 237 $sql .= " ORDER BY code ASC;"; 238 239 if ($this->db->query($sql)) 240 { 241 print '<select class="flat" name="'.$htmlname.'" '.$htmloption.'>'; 242 $num = $this->db->num_rows(); 243 $i = 0; 244 if ($num) 245 { 246 $foundselected=false; 247 while ($i < $num) 248 { 249 $obj = $this->db->fetch_object(); 250 if ($selected > 0 && $selected == $obj->rowid) 251 { 252 $foundselected=true; 253 print '<option value="'.$obj->rowid.'" selected="true">'; 254 } 255 else 256 { 257 print '<option value="'.$obj->rowid.'">'; 258 } 259 // Si traduction existe, on l'utilise, sinon on prend le libellé par défaut 260 if ($obj->code) { print $obj->code . ' - '; } 261 print ($obj->code && $langs->trans("Country".$obj->code)!="Country".$obj->code?$langs->trans("Country".$obj->code):($obj->libelle!='-'?$obj->libelle:' ')); 262 print '</option>'; 263 $i++; 264 } 265 } 266 print '</select>'; 267 return 0; 268 } 269 else { 270 dolibarr_print_error($this->db); 271 return 1; 272 } 273 } 274 275 276 /** 277 * \brief Retourne la liste déroulante des langues disponibles 278 * \param selected Langue présélectionnée 279 * \param htmlname Nom de la zone select 280 * \param showauto Affiche choix auto 281 */ 282 function select_lang($selected='',$htmlname='lang_id',$showauto=0) 283 { 284 global $langs; 285 286 $langs_available=$langs->get_available_languages(); 287 288 print '<select class="flat" name="'.$htmlname.'">'; 289 if ($showauto) 290 { 291 print '<option value="auto"'; 292 if ($selected == 'auto') print ' selected="true"'; 293 print '>'.$langs->trans("AutoDetectLang").'</option>'; 294 } 295 $num = count($langs_available); 296 $i = 0; 297 if ($num) 298 { 299 while ($i < $num) 300 { 301 if ($selected == $langs_available[$i]) 302 { 303 print '<option value="'.$langs_available[$i].'" selected="true">'.$langs_available[$i].'</option>'; 304 } 305 else 306 { 307 print '<option value="'.$langs_available[$i].'">'.$langs_available[$i].'</option>'; 308 } 309 $i++; 310 } 311 } 312 print '</select>'; 313 } 314 315 316 /** 317 * \brief Retourne la liste déroulante des menus disponibles 318 * \param selected Menu pré-sélectionnée 319 * \param htmlname Nom de la zone select 320 * \param dirmenu Repértoire à scanner 321 */ 322 function select_menu($selected='',$htmlname,$dirmenu) 323 { 324 global $langs; 325 326 if ($selected == 'eldy.php') $selected='eldy_backoffice.php'; // Pour compatibilité 327 328 print '<select class="flat" name="'.$htmlname.'">'; 329 $handle=opendir($dirmenu); 330 while (($file = readdir($handle))!==false) 331 { 332 if (is_file($dirmenu."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') 333 { 334 $filelib=eregi_replace('\.php$','',$file); 335 if ($file == $selected) 336 { 337 print '<option value="'.$file.'" selected="true">'.$filelib.'</option>'; 338 } 339 else 340 { 341 print '<option value="'.$file.'">'.$filelib.'</option>'; 342 } 343 } 344 } 345 print '</select>'; 346 } 347 348 /** 349 * \brief Retourne la liste des types de comptes financiers 350 * \param selected Type pré-sélectionné 351 * \param htmlname Nom champ formulaire 352 */ 353 354 function select_type_comptes_financiers($selected=1,$htmlname='type') 355 { 356 global $langs; 357 $langs->load("banks"); 358 359 $type_available=array(0,1,2); 360 361 print '<select class="flat" name="'.$htmlname.'">'; 362 $num = count($type_available); 363 $i = 0; 364 if ($num) 365 { 366 while ($i < $num) 367 { 368 if ($selected == $type_available[$i]) 369 { 370 print '<option value="'.$type_available[$i].'" selected="true">'.$langs->trans("BankType".$type_available[$i]).'</option>'; 371 } 372 else 373 { 374 print '<option value="'.$type_available[$i].'">'.$langs->trans("BankType".$type_available[$i]).'</option>'; 375 } 376 $i++; 377 } 378 } 379 print '</select>'; 380 } 381 382 383 /** 384 * \brief Retourne la liste déroulante des sociétés 385 * \param selected Societe présélectionnée 386 * \param htmlname Nom champ formulaire 387 * \param filter Criteres optionnels de filtre 388 */ 389 function select_societes($selected='',$htmlname='soc_id',$filter='') 390 { 391 // On recherche les societes 392 $sql = "SELECT s.idp, s.nom FROM"; 393 $sql.= " ".MAIN_DB_PREFIX ."societe as s"; 394 if ($filter) $sql.= " WHERE $filter"; 395 $sql.= " ORDER BY nom ASC"; 396 397 $resql=$this->db->query($sql); 398 if ($resql) 399 { 400 print '<select class="flat" name="'.$htmlname.'">'; 401 $num = $this->db->num_rows($resql); 402 $i = 0; 403 if ($num) 404 { 405 while ($i < $num) 406 { 407 $obj = $this->db->fetch_object($resql); 408 if ($selected > 0 && $selected == $obj->idp) 409 { 410 print '<option value="'.$obj->idp.'" selected="true">'.$obj->nom.'</option>'; 411 } 412 else 413 { 414 print '<option value="'.$obj->idp.'">'.$obj->nom.'</option>'; 415 } 416 $i++; 417 } 418 } 419 print '</select>'; 420 } 421 else { 422 dolibarr_print_error($this->db); 423 } 424 } 425 426 427 /** 428 * \brief Retourne la liste déroulante des contacts d'une société donnée 429 * \param socid Id de la société 430 * \param selected Id contact pré-sélectionn 431 * \param htmlname Nom champ formulaire 432 */ 433 function select_contacts($socid,$selected='',$htmlname='contactid') 434 { 435 // On recherche les societes 436 $sql = "SELECT s.idp, s.name, s.firstname FROM "; 437 $sql .= MAIN_DB_PREFIX ."socpeople as s"; 438 $sql .= " WHERE fk_soc=".$socid; 439 $sql .= " ORDER BY s.name ASC"; 440 441 if ($this->db->query($sql)) 442 { 443 print '<select class="flat" name="'.$htmlname.'">'; 444 $num = $this->db->num_rows(); 445 $i = 0; 446 if ($num) 447 { 448 while ($i < $num) 449 { 450 $obj = $this->db->fetch_object(); 451 452 if ($selected && $selected == $obj->idp) 453 { 454 print '<option value="'.$obj->idp.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>'; 455 } 456 else 457 { 458 print '<option value="'.$obj->idp.'">'.$obj->name.' '.$obj->firstname.'</option>'; 459 } 460 $i++; 461 } 462 } 463 print '</select>'; 464 } 465 else 466 { 467 dolibarr_print_error($this->db); 468 } 469 } 470 471 472 /** 473 * \brief Retourne la liste déroulante des utilisateurs 474 * \param selected Id contact pré-sélectionn 475 * \param htmlname Nom champ formulaire 476 */ 477 function select_users($selected='',$htmlname='userid') 478 { 479 // On recherche les societes 480 $sql = "SELECT u.rowid, u.name, u.firstname FROM "; 481 $sql .= MAIN_DB_PREFIX ."user as u"; 482 $sql .= " ORDER BY u.name ASC"; 483 484 if ($this->db->query($sql)) 485 { 486 print '<select class="flat" name="'.$htmlname.'">'; 487 $num = $this->db->num_rows(); 488 $i = 0; 489 if ($num) 490 { 491 while ($i < $num) 492 { 493 $obj = $this->db->fetch_object(); 494 495 if ($selected && $selected == $obj->rowid) 496 { 497 print '<option value="'.$obj->rowid.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>'; 498 } 499 else 500 { 501 print '<option value="'.$obj->rowid.'">'.$obj->name.' '.$obj->firstname.'</option>'; 502 } 503 $i++; 504 } 505 } 506 print '</select>'; 507 } 508 else 509 { 510 dolibarr_print_error($this->db); 511 } 512 } 513 514 515 /** 516 * \brief Affiche la liste déroulante des projets d'une société donnée 517 * \param socid Id société 518 * \param selected Id projet présélectionné 519 * \param htmlname Nom de la zone html 520 * \return int Nbre de projet si ok, <0 si ko 521 */ 522 function select_projects($socid='', $selected='', $htmlname='projectid') 523 { 524 // On recherche les projets 525 $sql = 'SELECT p.rowid, p.title FROM '; 526 $sql.= MAIN_DB_PREFIX .'projet as p'; 527 $sql.= " WHERE fk_soc='".$socid."'"; 528 $sql.= " ORDER BY p.title ASC"; 529 530 $result=$this->db->query($sql); 531 if ($result) 532 { 533 print '<select class="flat" name="'.$htmlname.'">'; 534 print '<option value="0"> </option>'; 535 $num = $this->db->num_rows($result); 536 $i = 0; 537 if ($num) 538 { 539 while ($i < $num) 540 { 541 $obj = $this->db->fetch_object(); 542 if (!empty($selected) && $selected == $obj->rowid) 543 { 544 print '<option value="'.$obj->rowid.'" selected="true">'.$obj->title.'</option>'; 545 } 546 else 547 { 548 print '<option value="'.$obj->rowid.'">'.$obj->title.'</option>'; 549 } 550 $i++; 551 } 552 } 553 print '</select>'; 554 return $num; 555 } 556 else 557 { 558 dolibarr_print_error($this->db); 559 return -1; 560 } 561 } 562 563 /** 564 * \brief Retourne la liste des produits 565 * \param selected Produit présélectionné 566 * \param htmlname Nom de la zone select 567 * \param filtretype Pour filtre sur type de produit 568 * \param limit Limite sur le nombre de lignes retournées 569 */ 570 function select_produits($selected='',$htmlname='productid',$filtretype='',$limit=20) 571 { 572 global $langs,$conf; 573 574 $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration"; 575 $sql.= " FROM ".MAIN_DB_PREFIX."product as p "; 576 $sql.= " WHERE p.envente = 1"; 577 if ($filtretype && $filtretype != '') $sql.=" AND p.fk_product_type=".$filtretype; 578 $sql.= " ORDER BY p.nbvente DESC"; 579 if ($limit) $sql.= " LIMIT $limit"; 580 581 $result=$this->db->query($sql); 582 if ($result) 583 { 584 print '<select class="flat" name="'.$htmlname.'">'; 585 print "<option value=\"0\" selected=\"true\"> </option>"; 586 587 $num = $this->db->num_rows($result); 588 $i = 0; 589 while ($i < $num) 590 { 591 $objp = $this->db->fetch_object($result); 592 $opt = '<option value="'.$objp->rowid.'">['.$objp->ref.'] '; 593 $opt.= dolibarr_trunc($objp->label,40).' - '; 594 $opt.= $objp->price.' '.$langs->trans("Currency".$conf->monnaie); 595 if ($objp->duration) $opt.= ' - '.$objp->duration; 596 $opt.= "</option>\n"; 597 print $opt; 598 $i++; 599 } 600 print '</select>'; 601 602 $this->db->free($result); 603 } 604 else 605 { 606 dolibarr_print_error($db); 607 } 608 } 609 610 611 /** 612 * \brief Retourne la liste des produits fournisseurs 613 * \param selected Produit présélectionné 614 * \param htmlname Nom de la zone select 615 * \param filtretype Pour filtre sur type de produit 616 * \param limit Limite sur le nombre de lignes retournées 617 * \param filtre Pour filtre 618 */ 619 function select_produits_fournisseurs($socid,$selected='',$htmlname='productid',$filtretype='',$filtre='') 620 { 621 global $langs,$conf; 622 623 $sql = "SELECT p.rowid, p.label, p.ref, p.price as price, pf.price as fprice, pf.quantity, p.duration"; 624 $sql.= " FROM ".MAIN_DB_PREFIX."product as p "; 625 $sql .= " , ".MAIN_DB_PREFIX."product_fournisseur_price as pf "; 626 $sql.= " WHERE p.rowid = pf.fk_product AND pf.fk_soc = ".$socid; 627 if ($filtretype && $filtretype != '') $sql.=" AND p.fk_product_type=".$filtretype; 628 if ($filtre) $sql.="$filtre"; 629 $sql.= " ORDER BY p.ref DESC"; 630 631 $result=$this->db->query($sql); 632 if ($result) 633 { 634 print '<select class="flat" name="'.$htmlname.'">'; 635 print "<option value=\"0\" selected=\"true\"> </option>"; 636 637 $num = $this->db->num_rows($result); 638 $i = 0; 639 while ($i < $num) 640 { 641 $objp = $this->db->fetch_object($result); 642 $opt = '<option value="'.$objp->rowid.'">['.$objp->ref.'] '; 643 $opt.= dolibarr_trunc($objp->label,40).' - '; 644 $opt.= $objp->fprice." ".$langs->trans("Currency".$conf->monnaie)." / ".$objp->quantity." ".$langs->trans("Units"); 645 if ($objp->quantity > 1) 646 { 647 $opt.=" - "; 648 $opt.= round($objp->fprice/$objp->quantity,4)." ".$langs->trans("Currency".$conf->monnaie)." / ".$langs->trans("Unit"); 649 } 650 if ($objp->duration) $opt .= " - ".$objp->duration; 651 $opt .= "</option>\n"; 652 print $opt; 653 $i++; 654 } 655 print '</select>'; 656 657 $this->db->free($result); 658 } 659 else 660 { 661 dolibarr_print_error($db); 662 } 663 } 664 665 666 /** 667 * \brief Charge dans cache la liste des conditions de paiements possibles 668 * \return int Nb lignes chargées, 0 si déjà chargées, <0 si ko 669 */ 670 function load_cache_conditions_paiements() 671 { 672 global $langs; 673 674 if (sizeof($this->cache_conditions_paiements_code)) return 0; // Cache déja chargé 675 676 dolibarr_syslog('html.form.class.php::load_cache_conditions_paiements'); 677 $sql = "SELECT rowid, libelle"; 678 $sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement"; 679 $sql.= " WHERE active=1"; 680 $sql.= " ORDER BY sortorder"; 681 $resql = $this->db->query($sql); 682 if ($resql) 683 { 684 $num = $this->db->num_rows($result); 685 $i = 0; 686 while ($i < $num) 687 { 688 $obj = $this->db->fetch_object($resql); 689 690 // Si traduction existe, on l'utilise, sinon on prend le libellé par défaut 691 $libelle=($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->libelle!='-'?$obj->libelle:'')); 692 $this->cache_conditions_paiements_code[$obj->rowid]=$obj->code; 693 $this->cache_conditions_paiements_libelle[$obj->rowid]=$libelle; 694 $i++; 695 } 696 return 1; 697 } 698 else { 699 dolibarr_print_error($this->db); 700 return -1; 701 } 702 } 703 704 /** 705 * \brief Charge dans cache la liste des types de paiements possibles 706 * \return int Nb lignes chargées, 0 si déjà chargées, <0 si ko 707 */ 708 function load_cache_types_paiements() 709 { 710 global $langs; 711 712 if (sizeof($this->cache_types_paiements_code)) return 0; // Cache déja chargé 713 714 dolibarr_syslog('html.form.class.php::load_cache_types_paiements'); 715 $sql = "SELECT id, code, libelle, type"; 716 $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement"; 717 $sql.= " WHERE active > 0"; 718 $sql.= " ORDER BY id"; 719 $resql = $this->db->query($sql); 720 if ($resql) 721 { 722 $num = $this->db->num_rows($result); 723 $i = 0; 724 while ($i < $num) 725 { 726 $obj = $this->db->fetch_object($resql); 727 728 // Si traduction existe, on l'utilise, sinon on prend le libellé par défaut 729 $libelle=($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->libelle!='-'?$obj->libelle:'')); 730 $this->cache_types_paiements_code[$obj->id]=$obj->code; 731 $this->cache_types_paiements_libelle[$obj->id]=$libelle; 732 $this->cache_types_paiements_type[$obj->id]=$obj->type; 733 $i++; 734 } 735 return $num; 736 } 737 else { 738 dolibarr_print_error($this->db); 739 return -1; 740 } 741 } 742 743 744 745 /** 746 * \brief Retourne la liste des types de paiements possibles 747 * \param selected Id du type de paiement présélectionné 748 * \param htmlname Nom de la zone select 749 * \param filtertype Pour filtre 750 */ 751 function select_conditions_paiements($selected='',$htmlname='condid',$filtertype=-1) 752 { 753 global $langs; 754 755 $this->load_cache_conditions_paiements(); 756 757 print '<select class="flat" name="'.$htmlname.'">'; 758 foreach($this->cache_conditions_paiements_code as $id => $code) 759 { 760 if ($selected == $id) 761 { 762 print '<option value="'.$id.'" selected="true">'; 763 } 764 else 765 { 766 print '<option value="'.$id.'">'; 767 } 768 print $this->cache_conditions_paiements_libelle[$id]; 769 print '</option>'; 770 } 771 print '</select>'; 772 } 773 774 775 776 777 /** 778 * \brief Retourne la liste des modes de paiements possibles 779 * \param selected Id du mode de paiement présélectionné 780 * \param htmlname Nom de la zone select 781 * \param filtertype Pour filtre 782 * \param format 0=id+libelle, 1=code+code, 2=code+libelle 783 */ 784 function select_types_paiements($selected='',$htmlname='paiementtype',$filtertype='',$format=0) 785 { 786 global $langs; 787 788 $filterarray=array(); 789 if ($filtertype && $filtertype != '-1') $filterarray=split(',',$filtertype); 790 791 $this->load_cache_types_paiements(); 792 793 print '<select class="flat" name="'.$htmlname.'">'; 794 foreach($this->cache_types_paiements_code as $id => $code) 795 { 796 // On passe si on a demandé de filtrer sur des modes de paiments particulièrs 797 if (sizeof($filterarray) && ! in_array($this->cache_types_paiements_type[$id],$filterarray)) continue; 798 799 if ($format == 0) print '<option value="'.$id.'"'; 800 if ($format == 1) print '<option value="'.$code.'"'; 801 if ($format == 2) print '<option value="'.$code.'"'; 802 // Si selected est text, on compare avec code, sinon avec id 803 if (eregi('[a-z]', $selected) && $selected == $code) print ' selected="true"'; 804 elseif ($selected == $id) print ' selected="true"'; 805 print '>'; 806 if ($format == 0) print $this->cache_types_paiements_libelle[$id]; 807 if ($format == 1) print $code; 808 if ($format == 2) print $this->cache_types_paiements_libelle[$id]; 809 print '</option>'; 810 } 811 print '</select>'; 812 } 813 814 815 /** 816 * \brief Retourne la liste des comptes 817 * \param selected Id compte présélectionné 818 * \param htmlname Nom de la zone select 819 * \param statut Statut des comptes recherchés 820 * \param filtre Pour filtre sur la liste 821 * \param useempty Affiche valeur vide dans liste 822 */ 823 function select_comptes($selected='',$htmlname='accountid',$statut=0,$filtre='',$useempty=0) 824 { 825 global $langs; 826 827 $sql = "SELECT rowid, label, bank"; 828 $sql.= " FROM ".MAIN_DB_PREFIX."bank_account"; 829 $sql.= " WHERE clos = '".$statut."'"; 830 if ($filtre) $sql.=" AND ".$filtre; 831 $sql.= " ORDER BY rowid"; 832 $result = $this->db->query($sql); 833 if ($result) 834 { 835 print '<select class="flat" name="'.$htmlname.'">'; 836 if ($useempty) 837 { 838 print '<option value="'.$obj->rowid.'"> </option>'; 839 } 840 841 $num = $this->db->num_rows($result); 842 $i = 0; 843 while ($i < $num) 844 { 845 $obj = $this->db->fetch_object($result); 846 if ($selected == $obj->rowid) 847 { 848 print '<option value="'.$obj->rowid.'" selected="true">'; 849 } 850 else 851 { 852 print '<option value="'.$obj->rowid.'">'; 853 } 854 print $obj->label; 855 print '</option>'; 856 $i++; 857 } 858 print "</select>"; 859 } 860 else { 861 dolibarr_print_error($this->db); 862 } 863 } 864 865 866 /** 867 * \brief Retourne la liste déroulante des civilite actives 868 * \param selected civilite pré-sélectionnée 869 */ 870 function select_civilite($selected='') 871 { 872 global $conf,$langs; 873 $langs->load("dict"); 874 875 $sql = "SELECT rowid, code, civilite, active FROM ".MAIN_DB_PREFIX."c_civilite"; 876 $sql .= " WHERE active = 1"; 877 878 if ($this->db->query($sql)) 879 { 880 print '<select class="flat" name="civilite_id">'; 881 print '<option value=""> </option>'; 882 $num = $this->db->num_rows(); 883 $i = 0; 884 if ($num) 885 { 886 while ($i < $num) 887 { 888 $obj = $this->db->fetch_object(); 889 if ($selected == $obj->code) 890 { 891 print '<option value="'.$obj->code.'" selected="true">'; 892 } 893 else 894 { 895 print '<option value="'.$obj->code.'">'; 896 } 897 // Si traduction existe, on l'utilise, sinon on prend le libellé par défaut 898 print ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->civilite!='-'?$obj->civilite:'')); 899 print '</option>'; 900 $i++; 901 } 902 } 903 print '</select>'; 904 } 905 else 906 { 907 dolibarr_print_error($this->db); 908 } 909 } 910 911 912 /** 913 * \brief Retourne le nom traduit de la civilité 914 * \param code Code de la civilité 915 * \return string Nom traduit de la civilité 916 */ 917 function civilite_name($code) 918 { 919 global $langs; 920 $langs->load("dict"); 921 return $langs->trans("Civility".$code)!="Civility".$code ? $langs->trans("Civility".$code) : $code; 922 } 923 924 925 /** 926 * \brief Retourne la liste déroulante des formes juridiques tous pays confondus ou pour un pays donné. 927 * \remarks Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays 928 * \param selected Code forme juridique a présélectionn 929 * \param pays_code 0=liste tous pays confondus, sinon code du pays à afficher 930 */ 931 function select_forme_juridique($selected='',$pays_code=0) 932 { 933 global $conf,$langs; 934 $langs->load("dict"); 935 936 // On recherche les formes juridiques actives des pays actifs 937 $sql = "SELECT f.rowid, f.code as code , f.libelle as nom, f.active, p.libelle as libelle_pays, p.code as code_pays"; 938 $sql .= " FROM llx_c_forme_juridique as f, llx_c_pays as p"; 939 $sql .= " WHERE f.fk_pays=p.rowid"; 940 $sql .= " AND f.active = 1 AND p.active = 1"; 941 if ($pays_code) $sql .= " AND p.code = '".$pays_code."'"; 942 $sql .= " ORDER BY p.code, f.code"; 943 944 $result=$this->db->query($sql); 945 if ($result) 946 { 947 print '<select class="flat" name="forme_juridique_code">'; 948 if ($pays_code) print '<option value="0"> </option>'; 949 $num = $this->db->num_rows($result); 950 $i = 0; 951 if ($num) 952 { 953 $pays=''; 954 while ($i < $num) 955 { 956 $obj = $this->db->fetch_object($result); 957 if ($obj->code == 0) { 958 print '<option value="0"> </option>'; 959 } 960 else { 961 if (! $pays || $pays != $obj->libelle_pays) { 962 // Affiche la rupture si on est en mode liste multipays 963 if (! $pays_code && $obj->code_pays) { 964 print '<option value="0">----- '.$obj->libelle_pays." -----</option>\n"; 965 $pays=$obj->libelle_pays; 966 } 967 } 968 969 if ($selected > 0 && $selected == $obj->code) 970 { 971 print '<option value="'.$obj->code.'" selected="true">'; 972 } 973 else 974 { 975 print '<option value="'.$obj->code.'">'; 976 } 977 // Si traduction existe, on l'utilise, sinon on prend le libellé par défaut 978 print $obj->code . ' - ' .($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->nom!='-'?$obj->nom:'')); 979 print '</option>'; 980 } 981 $i++; 982 } 983 } 984 print '</select>'; 985 } 986 else 987 { 988 dolibarr_print_error($this->db); 989 } 990 } 991 992 993 /** 994 * \brief Retourne le nom traduit de la forme juridique 995 * \param code Code de la forme juridique 996 * \return string Nom traduit du pays 997 */ 998 function forme_juridique_name($code) 999 { 1000 global $langs; 1001 1002 if (! $code) return ''; 1003 1004 $sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."c_forme_juridique"; 1005 $sql.= " WHERE code='$code';"; 1006 1007 if ($this->db->query($sql)) 1008 { 1009 $num = $this->db->num_rows(); 1010 1011 if ($num) 1012 { 1013 $obj = $this->db->fetch_object(); 1014 $label=($obj->libelle!='-' ? $obj->libelle : ''); 1015 return $label; 1016 } 1017 else 1018 { 1019 return $langs->trans("NotDefined"); 1020 } 1021 1022 } 1023 } 1024 1025 1026 /** 1027 * \brief Retourne le formulaire de saisie d'un identifiant professionnel (siren, siret, etc...) 1028 * \param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) 1029 * \param soc Objet societe 1030 * \param htmlname Nom de la zone input 1031 */ 1032 function id_prof($idprof,$soc,$htmlname,$selected='') 1033 { 1034 global $langs; 1035 $formlength=16; 1036 if ($idprof==1 && $soc->pays_code == 'FR') $formlength=9; 1037 if ($idprof==2 && $soc->pays_code == 'FR') $formlength=14; 1038 if ($idprof==3 && $soc->pays_code == 'FR') $formlength=4; 1039 if ($idprof==4 && $soc->pays_code == 'FR') $formlength=4; 1040 print '<input type="text" name="'.$htmlname.'" size="'.($formlength+1).'" maxlength="'.$formlength.'" value="'.$selected.'">'; 1041 } 1042 1043 1044 /** 1045 * \brief Retourne le nom traduit ou code+nom d'un pays 1046 * \param id id du pays 1047 * \param withcode 1=affiche code + nom 1048 * \return string Nom traduit du pays 1049 */ 1050 function pays_name($id,$withcode=0) 1051 { 1052 global $langs; 1053 1054 $sql = "SELECT rowid, code, libelle FROM ".MAIN_DB_PREFIX."c_pays"; 1055 $sql.= " WHERE rowid=$id;"; 1056 1057 if ($this->db->query($sql)) 1058 { 1059 $num = $this->db->num_rows(); 1060 1061 if ($num) 1062 { 1063 $obj = $this->db->fetch_object(); 1064 $label=$obj->code && $langs->trans("Country".$obj->code)!="Country".$obj->code?$langs->trans("Country".$obj->code):($obj->libelle!='-'?$obj->libelle:''); 1065 if ($withcode) return $label==$obj->code?"$obj->code":"$obj->code - $label"; 1066 else return $label; 1067 } 1068 else 1069 { 1070 return $langs->trans("NotDefined"); 1071 } 1072 1073 } 1074 } 1075 1076 1077 /** 1078 * \brief Retourne le nom traduit ou code+nom d'une devise 1079 * \param code_iso Code iso de la devise 1080 * \param withcode 1=affiche code + nom 1081 * \return string Nom traduit de la devise 1082 */ 1083 function currency_name($code_iso,$withcode=0) 1084 { 1085 global $langs; 1086 1087 // Si il existe une traduction, on peut renvoyer de suite le libellé 1088 if ($langs->trans("Currency".$code_iso)!="Currency".$code_iso) 1089 { 1090 return $langs->trans("Currency".$code_iso); 1091 } 1092 1093 // Si pas de traduction, on consulte libellé par défaut en table 1094 $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies"; 1095 $sql.= " WHERE code_iso='$code_iso';"; 1096 1097 if ($this->db->query($sql)) 1098 { 1099 $num = $this->db->num_rows(); 1100 1101 if ($num) 1102 { 1103 $obj = $this->db->fetch_object(); 1104 $label=($obj->label!='-'?$obj->label:''); 1105 if ($withcode) return $label==$code_iso?"$code_iso":"$code_iso - $label"; 1106 else return $label; 1107 } 1108 else 1109 { 1110 return $code_iso; 1111 } 1112 1113 } 1114 } 1115 1116 1117 /** 1118 * \brief Affiche formulaire de demande de confirmation 1119 * \param page page 1120 * \param title title 1121 * \param question question 1122 * \param action action 1123 */ 1124 1125 function form_confirm($page, $title, $question, $action) 1126 { 1127 global $langs; 1128 1129 print '<form method="post" action="'.$page.'">'; 1130 print '<input type="hidden" name="action" value="'.$action.'">'; 1131 print '<table class="border" width="100%">'; 1132 // Ligne titre 1133 print '<tr><td class="validtitle" colspan="3">'.$title.'</td></tr>'; 1134 // Ligne message 1135 print '<tr><td class="valid">'.$question.'</td><td class="valid">'; 1136 $this->selectyesno("confirm","no"); 1137 print "</td>\n"; 1138 print '<td class="valid" align="center"><input class="button" type="submit" value="'.$langs->trans("Confirm").'"</td></tr>'; 1139 1140 print '</table>'; 1141 print "</form>\n"; 1142 } 1143 1144 1145 /** 1146 * \brief Affiche formulaire de selection de projet 1147 * \param page Page 1148 * \param socid Id societe 1149 * \param selected Id projet présélectionné 1150 * \param htmlname Nom du formulaire select 1151 */ 1152 function form_project($page, $socid, $selected='', $htmlname='projectid') 1153 { 1154 global $langs; 1155 $langs->load("project"); 1156 if ($htmlname != "none") 1157 { 1158 print '<form method="post" action="'.$page.'">'; 1159 print '<input type="hidden" name="action" value="classin">'; 1160 print '<table class="noborder" cellpadding="0" cellspacing="0">'; 1161 print '<tr><td>'; 1162 $this->select_projects($socid,$selected,$htmlname); 1163 print '</td>'; 1164 print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>'; 1165 print '</tr></table></form>'; 1166 } 1167 else 1168 { 1169 if ($selected) { 1170 $projet = New Project($this->db); 1171 $projet->fetch($selected); 1172 print '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$selected.'">'.$projet->title.'</a>'; 1173 } else { 1174 print " "; 1175 } 1176 } 1177 } 1178 1179 /** 1180 * \brief Affiche formulaire de selection de conditions de paiement 1181 * \param page Page 1182 * \param selected Id condition présélectionnée 1183 * \param htmlname Nom du formulaire select 1184 */ 1185 function form_conditions_reglement($page, $selected='', $htmlname='cond_reglement_id') 1186 { 1187 global $langs; 1188 if ($htmlname != "none") 1189 { 1190 print '<form method="post" action="'.$page.'">'; 1191 print '<input type="hidden" name="action" value="setconditions">'; 1192 print '<table class="noborder" cellpadding="0" cellspacing="0">'; 1193 print '<tr><td>'; 1194 $this->select_conditions_paiements($selected,$htmlname); 1195 print '</td>'; 1196 print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>'; 1197 print '</tr></table></form>'; 1198 } 1199 else 1200 { 1201 if ($selected) 1202 { 1203 $this->load_cache_conditions_paiements(); 1204 print $this->cache_conditions_paiements_libelle[$selected]; 1205 } else { 1206 print " "; 1207 } 1208 } 1209 } 1210 1211 1212 /** 1213 * \brief Affiche formulaire de selection des modes de reglement 1214 * \param page Page 1215 * \param selected Id mode présélectionné 1216 * \param htmlname Nom du formulaire select 1217 */ 1218 function form_modes_reglement($page, $selected='', $htmlname='mode_reglement_id') 1219 { 1220 global $langs; 1221 if ($htmlname != "none") 1222 { 1223 print '<form method="post" action="'.$page.'">'; 1224 print '<input type="hidden" name="action" value="setmode">'; 1225 print '<table class="noborder" cellpadding="0" cellspacing="0">'; 1226 print '<tr><td>'; 1227 $this->select_types_paiements($selected,$htmlname); 1228 print '</td>'; 1229 print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>'; 1230 print '</tr></table></form>'; 1231 } 1232 else 1233 { 1234 if ($selected) 1235 { 1236 $this->load_cache_types_paiements(); 1237 print $this->cache_types_paiements_libelle[$selected]; 1238 } else { 1239 print " "; 1240 } 1241 } 1242 } 1243 1244 1245 /** 1246 * \brief Retourne la liste des devises, dans la langue de l'utilisateur 1247 * \param selected code devise pré-sélectionnée 1248 * \param htmlname nom de la liste deroulante 1249 * \todo trier liste sur noms après traduction plutot que avant 1250 */ 1251 function select_currency($selected='',$htmlname='currency_id') 1252 { 1253 global $conf,$langs; 1254 $langs->load("dict"); 1255 1256 if ($selected=='euro' || $selected=='euros') $selected='EUR'; // Pour compatibilité 1257 1258 $sql = "SELECT code_iso, label, active FROM ".MAIN_DB_PREFIX."c_currencies"; 1259 $sql .= " WHERE active = 1"; 1260 $sql .= " ORDER BY code_iso ASC;"; 1261 1262 if ($this->db->query($sql)) 1263 { 1264 print '<select class="flat" name="'.$htmlname.'">'; 1265 $num = $this->db->num_rows(); 1266 $i = 0; 1267 if ($num) 1268 { 1269 $foundselected=false; 1270 while ($i < $num) 1271 { 1272 $obj = $this->db->fetch_object(); 1273 if ($selected && $selected == $obj->code_iso) 1274 { 1275 $foundselected=true; 1276 print '<option value="'.$obj->code_iso.'" selected="true">'; 1277 } 1278 else 1279 { 1280 print '<option value="'.$obj->code_iso.'">'; 1281 } 1282 // Si traduction existe, on l'utilise, sinon on prend le libellé par défaut 1283 if ($obj->code_iso) { print $obj->code_iso . ' - '; } 1284 print ($obj->code_iso && $langs->trans("Currency".$obj->code_iso)!="Currency".$obj->code_iso?$langs->trans("Currency".$obj->code_iso):($obj->label!='-'?$obj->label:'')); 1285 print '</option>'; 1286 $i++; 1287 } 1288 } 1289 print '</select>'; 1290 return 0; 1291 } 1292 else { 1293 dolibarr_print_error($this->db); 1294 return 1; 1295 } 1296 } 1297 1298 1299 /** 1300 * \brief Selection du taux de tva 1301 * \param name Nom champ html 1302 * \param defaulttx Taux tva présélectionné (deprecated) 1303 * \param societe_vendeuse Objet société vendeuse 1304 * \param societe_acheteuse Objet société acheteuse 1305 * \param taux_produit Taux par defaut du produit vendu 1306 * \remarks Si vendeur non assujeti à TVA, TVA par défaut=0. Fin de règle. 1307 * Si le (pays vendeur = pays acheteur) alors la TVA par défaut=TVA du produit vendu. Fin de règle. 1308 * Si vendeur et acheteur dans Communauté européenne et bien vendu = moyen de transports neuf (auto, bateau, avion), TVA par défaut=0 (La TVA doit être payé par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de règle. 1309 * Si vendeur et acheteur dans Communauté européenne et bien vendu autre que transport neuf alors la TVA par défaut=TVA du produit vendu. Fin de règle. 1310 * Sinon la TVA proposée par défaut=0. Fin de règle. 1311 */ 1312 function select_tva($name='tauxtva', $defaulttx='', $societe_vendeuse='', $societe_acheteuse='', $taux_produit='') 1313 { 1314 global $langs,$conf; 1315 1316 // \todo Si pays vendeur non défini 1317 if (1 == 2) 1318 { 1319 // \todo si pays vendeur = soi-même 1320 if (1 == 1) 1321 { 1322 print '<font class="error">'.$langs->trans("ErrorYourCountryIsNotDefined").'</div>'; 1323 } 1324 else 1325 { 1326 print '<font class="error">'.$langs->trans("ErrorSupplierCountryIsNotDefined").'</div>'; 1327 } 1328 return; 1329 } 1330 1331 // \todo Ecraser defaulttx par valeur en fonction de la règle de gestion TVA 1332 //$defaulttx=get_default_tva($societe_vendeuse,$societe_acheteuse,$taux_produit); 1333 1334 // \todo Initialiser code_pays avec code_pays société vendeuse 1335 $code_pays=$conf->global->MAIN_INFO_SOCIETE_PAYS; 1336 $sql = "SELECT t.taux,t.recuperableonly"; 1337 $sql .= " FROM ".MAIN_DB_PREFIX."c_tva AS t"; 1338 $sql .= " WHERE t.fk_pays = '".$code_pays."'"; 1339 $sql .= " AND t.active = 1"; 1340 $sql .= " ORDER BY t.taux ASC, t.recuperableonly ASC"; 1341 1342 if ($this->db->query($sql)) 1343 { 1344 $num = $this->db->num_rows(); 1345 for ($i = 0; $i < $num; $i++) 1346 { 1347 $obj = $this->db->fetch_object(); 1348 $txtva[ $i ] = $obj->taux; 1349 $libtva[ $i ] = $obj->taux.'%'.($obj->recuperableonly ? ' *':''); 1350 } 1351 } 1352 1353 // Si taux par defaut n'a pu etre trouvé, on prend dernier. 1354 // Comme ils sont triés par ordre croissant, dernier = plus élevé = taux courant 1355 if ($defaulttx == '') $defaulttx = $txtva[sizeof($txtva)-1]; 1356 1357 $taille = sizeof($txtva); 1358 1359 print '<select class="flat" name="'.$name.'">'; 1360 if ($default) print '<option value="0">'.$langs->trans("Default").'</option>'; 1361 1362 for ($i = 0 ; $i < $taille ; $i++) 1363 { 1364 print '<option value="'.$txtva[$i].'"'; 1365 if ($txtva[$i] == $defaulttx) 1366 { 1367 print ' selected="true"'; 1368 } 1369 print '>'.$libtva[$i].'</option>'; 1370 } 1371 print '</select>'; 1372 } 1373 1374 1375 /** 1376 * \brief Affiche zone de selection de date 1377 * Liste deroulante pour les jours, mois, annee et eventuellement heurs et minutes 1378 * Les champs sont présélectionnées avec: 1379 * - La date set_time (timestamps ou date au format YYYY-MM-DD ou YYYY-MM-DD HH:MM) 1380 * - La date du jour si set_time vaut '' 1381 * - Aucune date (champs vides) si set_time vaut -1 1382 */ 1383 function select_date($set_time='', $prefix='re', $h = 0, $m = 0, $empty=0) 1384 { 1385 global $conf,$langs; 1386 1387 if (! $set_time && $empty == 0) $set_time = time(); 1388 1389 $strmonth[1] = $langs->trans("January"); 1390 $strmonth[2] = $langs->trans("February"); 1391 $strmonth[3] = $langs->trans("March"); 1392 $strmonth[4] = $langs->trans("April"); 1393 $strmonth[5] = $langs->trans("May"); 1394 $strmonth[6] = $langs->trans("June"); 1395 $strmonth[7] = $langs->trans("July"); 1396 $strmonth[8] = $langs->trans("August"); 1397 $strmonth[9] = $langs->trans("September"); 1398 $strmonth[10] = $langs->trans("October"); 1399 $strmonth[11] = $langs->trans("November"); 1400 $strmonth[12] = $langs->trans("December"); 1401 1402 // Analyse de la date de préselection 1403 if (eregi('^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?',$set_time,$reg)) { 1404 // Date au format 'YYYY-MM-DD' ou 'YYYY-MM-DD HH:MM:SS' 1405 $syear = $reg[1]; 1406 $smonth = $reg[2]; 1407 $sday = $reg[3]; 1408 $shour = $reg[4]; 1409 $smin = $reg[5]; 1410 } 1411 elseif ($set_time) { 1412 // Date est un timestamps 1413 $syear = date("Y", $set_time); 1414 $smonth = date("n", $set_time); 1415 $sday = date("d", $set_time); 1416 $shour = date("H", $set_time); 1417 $smin = date("i", $set_time); 1418 } 1419 else { 1420 // Date est vide 1421 $syear = ''; 1422 $smonth = ''; 1423 $sday = ''; 1424 $shour = ''; 1425 $smin = ''; 1426 } 1427 1428 $conf->use_popup_date=0; // Mettre 1 pour avoir date en popup (experimental) 1429 1430 /* 1431 * Affiche date en popup 1432 */ 1433 if ($conf->use_javascript && $conf->use_popup_date) 1434 { 1435 $timearray=getDate($set_time); 1436 $formated_date=dolibarr_print_date($set_time,$conf->format_date_short); 1437 print '<input id="'.$prefix.'" name="'.$prefix.'" type="text" size="11" maxlength="11" value="'.$formated_date.'"> <button id="'.$prefix.'Button" type="button" class="dpInvisibleButtons" onClick="showDP(\''.DOL_URL_ROOT.'/theme/'.$conf->theme.'/\',\''.$prefix.'\',\''.$conf->format_date_short.'\');">'.img_object($langs->trans("SelectDate"),'calendar').'</button>'; 1438 print '<input type="hidden" name="'.$prefix.'day" value="'.$timearray['mday'].'">'."\n"; 1439 print '<input type="hidden" name="'.$prefix.'month" value="'.$timearray['mon'].'">'."\n"; 1440 print '<input type="hidden" name="'.$prefix.'year" value="'.$timearray['year'].'">'."\n"; 1441 } 1442 1443 /* 1444 * Affiche date en select 1445 */ 1446 if (! $conf->use_javascript || ! $conf->use_popup_date) 1447 { 1448 1449 // Jour 1450 print '<select class="flat" name="'.$prefix.'day">'; 1451 1452 if ($empty || $set_time == -1) 1453 { 1454 $sday = 0; 1455 $smonth = 0; 1456 $syear = 0; 1457 $shour = 0; 1458 $smin = 0; 1459 1460 print '<option value="0" selected="true"> </option>'; 1461 } 1462 1463 for ($day = 1 ; $day <= 31; $day++) 1464 { 1465 if ($day == $sday) 1466 { 1467 print "<option value=\"$day\" selected=\"true\">$day"; 1468 } 1469 else 1470 { 1471 print "<option value=\"$day\">$day"; 1472 } 1473 print "</option>"; 1474 } 1475 1476 print "</select>"; 1477 1478 print '<select class="flat" name="'.$prefix.'month">'; 1479 if ($empty || $set_time == -1) 1480 { 1481 print '<option value="0" selected="true"> </option>'; 1482 } 1483 1484 // Mois 1485 for ($month = 1 ; $month <= 12 ; $month++) 1486 { 1487 if ($month == $smonth) 1488 { 1489 print "<option value=\"$month\" selected=\"true\">" . $strmonth[$month]; 1490 } 1491 else 1492 { 1493 print "<option value=\"$month\">" . $strmonth[$month]; 1494 } 1495 print "</option>"; 1496 } 1497 print "</select>"; 1498 1499 // Année 1500 if ($empty || $set_time == -1) 1501 { 1502 print '<input class="flat" type="text" size="3" maxlength="4" name="'.$prefix.'year">'; 1503 } 1504 else 1505 { 1506 print '<select class="flat" name="'.$prefix.'year">'; 1507 1508 for ($year = $syear - 5; $year < $syear + 10 ; $year++) 1509 { 1510 if ($year == $syear) 1511 { 1512 print "<option value=\"$year\" selected=\"true\">$year"; 1513 } 1514 else 1515 { 1516 print "<option value=\"$year\">$year"; 1517 } 1518 print "</option>"; 1519 } 1520 print "</select>\n"; 1521 } 1522 } 1523 1524 /* 1525 * Affiche heure en select 1526 */ 1527 if ($h) 1528 { 1529 print '<select class="flat" name="'.$prefix.'hour">'; 1530 1531 for ($hour = 0; $hour < 24 ; $hour++) 1532 { 1533 if (strlen($hour) < 2) 1534 { 1535 $hour = "0" . $hour; 1536 } 1537 if ($hour == $shour) 1538 { 1539 print "<option value=\"$hour\" selected=\"true\">$hour"; 1540 } 1541 else 1542 { 1543 print "<option value=\"$hour\">$hour"; 1544 } 1545 print "</option>"; 1546 } 1547 print "</select>H\n"; 1548 1549 if ($m) 1550 { 1551 print '<select class="flat" name="'.$prefix.'min">'; 1552 1553 for ($min = 0; $min < 60 ; $min++) 1554 { 1555 if (strlen($min) < 2) 1556 { 1557 $min = "0" . $min; 1558 } 1559 if ($min == $smin) 1560 { 1561 print "<option value=\"$min\" selected=\"true\">$min"; 1562 } 1563 else 1564 { 1565 print "<option value=\"$min\">$min"; 1566 } 1567 print "</option>"; 1568 } 1569 print "</select>M\n"; 1570 } 1571 1572 } 1573 1574 } 1575 1576 /** 1577 * \brief Affiche liste déroulante depuis requete SQL 1578 * \param name Nom de la zone select 1579 * \param sql Requete sql 1580 * \param id Id présélectionné 1581 */ 1582 function select($name, $sql, $id='') 1583 { 1584 $resql = $this->db->query($sql); 1585 if ($resql) 1586 { 1587 print '<select class="flat" name="'.$name.'">'; 1588 $num = $this->db->num_rows($resql); 1589 $i = 0; 1590 while ($i < $num) 1591 { 1592 $row = $this->db->fetch_row($resql); 1593 print '<option value="'.$row[0].'"'; 1594 if ($id != '' && $id == $row[0]) 1595 { 1596 print ' selected="true"'; 1597 } 1598 print '>'.$row[1].'</option>'; 1599 $i++; 1600 } 1601 print "</select>\n"; 1602 } 1603 else 1604 { 1605 dolibarr_print_error($this->db); 1606 } 1607 } 1608 1609 /** 1610 \brief Affiche un select à partir d'un tableau 1611 \param name nom de la zone select 1612 \param array tableau de key+valeur 1613 \param id key présélectionnée 1614 \param empty 1 si il faut un valeur " " dans la liste, 0 sinon 1615 \param key_libelle 1 pour afficher la key dans la valeur "[key] value" 1616 */ 1617 1618 function select_array($name, $array, $id='', $empty=0, $key_libelle=0) 1619 { 1620 print '<select class="flat" name="'.$name.'">'; 1621 1622 $i = 0; 1623 1624 if (strlen($id)) { 1625 if ($empty == 1) 1626 { 1627 $array[0] = " "; 1628 } 1629 reset($array); 1630 } 1631 1632 while (list($key, $value) = each ($array)) 1633 { 1634 print "<option value=\"$key\" "; 1635 1636 // Si il faut présélectionner une valeur 1637 if ($id && $id == $key) 1638 { 1639 print 'selected="true"'; 1640 } 1641 1642 if ($key_libelle) 1643 { 1644 print ">[$key] $value</option>\n"; 1645 } 1646 else 1647 { 1648 if ($value=="-") { $value=" "; } 1649 print ">$value</option>\n"; 1650 } 1651 } 1652 1653 print "</select>"; 1654 } 1655 1656 /** 1657 * \brief Renvoie la chaîne de caractère décrivant l'erreur 1658 * 1659 */ 1660 1661 function error() 1662 { 1663 return $this->errorstr; 1664 } 1665 1666 1667 /** 1668 * \brief Selection de oui/non en chaine (renvoie yes/no) 1669 * \param name Nom du select 1670 * \param value Valeur présélectionnée 1671 * \param option 0 retourne yes/no, 1 retourne 1/0 1672 */ 1673 function selectyesno($name,$value='',$option=0) 1674 { 1675 global $langs; 1676 1677 $yes="yes"; $no="no"; 1678 1679 if ($option) 1680 { 1681 $yes="1"; 1682 $no="0"; 1683 } 1684 1685 print '<select class="flat" name="'.$name.'">'."\n"; 1686 if (("$value" == 'yes') || ($value == 1)) 1687 { 1688 print '<option value="'.$yes.'" selected="true">'.$langs->trans("yes").'</option>'."\n"; 1689 print '<option value="'.$no.'">'.$langs->trans("no").'</option>'."\n"; 1690 } 1691 else 1692 { 1693 print '<option value="'.$yes.'">'.$langs->trans("yes").'</option>'."\n"; 1694 print '<option value="'.$no.'" selected="true">'.$langs->trans("no").'</option>'."\n"; 1695 } 1696 print '</select>'."\n"; 1697 } 1698 1699 /** 1700 * \brief Selection de oui/non en chiffre (renvoie 1/0) 1701 * \param name Nom du select 1702 * \param value Valeur présélectionnée 1703 */ 1704 function selectyesnonum($name,$value='') 1705 { 1706 $this->selectyesno($name,$value,1); 1707 } 1708 1709 /** 1710 * \brief Checkbox 1711 * 1712 */ 1713 function checkbox($name,$checked=0,$value=1) 1714 { 1715 if ($checked==1){ 1716 print "<input type=\"checkbox\" name=\"$name\" value=\"$value\" checked />\n"; 1717 }else{ 1718 print "<input type=\"checkbox\" name=\"$name\" value=\"$value\" />\n"; 1719 } 1720 } 1721 1722 1723 /** 1724 * \brief Affiche la cartouche générique d'un rapport 1725 * \param nom Valeur pour nom du rapport 1726 * \param variante Lien optionnel de variante du rapport 1727 * \param period Periode du reporting 1728 * \param periodlink Lien pour changer de période 1729 * \param description Description 1730 * \param builddate Date génération 1731 * \param exportlink Lien pour export 1732 */ 1733 function report_header($nom,$variante='',$period,$periodlink,$description,$builddate,$exportlink) 1734 { 1735 global $langs; 1736 1737 print "\n\n<!-- debut cartouche rapport -->\n"; 1738 1739 $h=0; 1740 $head[$h][0] = $_SERVER["PHP_SELF"]; 1741 $head[$h][1] = $langs->trans("Report"); 1742 dolibarr_fiche_head($head, $hselected, $societe->nom); 1743 1744 print '<table width="100%" class="border">'; 1745 1746 // Ligne de titre 1747 print '<tr>'; 1748 print '<td valign="top" width="110px">'.$langs->trans("ReportName").'</td>'; 1749 if (! $variante) print '<td colspan="3">'; 1750 else print '<td>'; 1751 print $nom; 1752 if ($variante) print '</td><td colspan="2">'.$variante; 1753 print '</td>'; 1754 print '</tr>'; 1755 1756 // Ligne de la periode d'analyse du rapport 1757 print '<tr>'; 1758 print '<td>'.$langs->trans("ReportPeriod").'</td>'; 1759 if (! $periodlink) print '<td colspan="3">'; 1760 else print '<td>'; 1761 print $period; 1762 if ($periodlink) print '</td><td colspan="2">'.$periodlink; 1763 print '</td>'; 1764 print '</tr>'; 1765 1766 // Ligne de description 1767 print '<tr>'; 1768 print '<td valign="top">'.$langs->trans("ReportDescription").'</td>'; 1769 print '<td colspan="3">'.$description.'</td>'; 1770 print '</tr>'; 1771 1772 // Ligne d'export 1773 print '<tr>'; 1774 print '<td>'.$langs->trans("GeneratedOn").'</td>'; 1775 if (! $exportlink) print '<td colspan="3">'; 1776 else print '<td>'; 1777 print dolibarr_print_date($builddate); 1778 if ($exportlink) print '</td><td>'.$langs->trans("Export").'</td><td>'.$exportlink; 1779 print '</td></tr>'; 1780 1781 print '</table>'; 1782 print '</div>'; 1783 print "\n<!-- fin cartouche rapport -->\n\n"; 1784 } 1785 1786 /** 1787 * \brief Affiche la cartouche de la liste des documents d'une propale, facture... 1788 * \param modulepart propal=propal, facture=facture, ... 1789 * \param filename Nom fichier sans extension 1790 * \param filedir Repertoire à scanner 1791 * \param urlsource Url page origine 1792 * \param genallowed Génération autorisée 1793 * \param delallowed Suppression autorisée 1794 * \param modelselected Modele à présélectionner par défaut 1795 * \remarks Le fichier de facture détaillée est de la forme 1796 * REFFACTURE-XXXXXX-detail.pdf ou XXXXX est une forme diverse 1797 */ 1798 function show_documents($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='') 1799 { 1800 // filedir = conf->...dir_ouput."/".get_exdir(id) 1801 1802 global $langs,$bc; 1803 $var=true; 1804 1805 $filename = sanitize_string($filename); 1806 // Par defaut 1807 $extension = 'pdf'; $relativepath = "$filename}/$filename}.$extension}"; 1808 // Autre cas 1809 if ($modulepart == 'expedition') { $extension='pdf'; $relativepath = get_exdir("$filename}")."$filename}.pdf"; } 1810 if ($modulepart == 'don') { $extension='html'; $relativepath = get_exdir("$filename}")."$filename}.html"; } 1811 1812 $i=0; 1813 if (is_dir($filedir)) 1814 { 1815 $handle=opendir($filedir); 1816 while (($file = readdir($handle))!==false) 1817 { 1818 // Si fichier non lisible ou non .pdf, on passe au suivant 1819 if (! is_readable($filedir."/".$file) || ! eregi('\.'.$extension.'$',$file)) continue; 1820 1821 if ($i==0) 1822 { 1823 // Affiche en-tete tableau 1824 if ($genallowed) 1825 { 1826 print '<form action="'.$urlsource.'" method="post">'; 1827 print '<input type="hidden" name="action" value="setpdfmodel">'; 1828 } 1829 1830 print_titre($langs->trans("Documents")); 1831 print '<table class="border" width="100%">'; 1832 1833 if ($genallowed) 1834 { 1835 $liste=array(); 1836 if ($modulepart == 'propal') 1837 { 1838 include_once (DOL_DOCUMENT_ROOT.'/includes/modules/propale/modules_propale.php'); 1839 $model=new ModelePDFPropales(); 1840 $liste=$model->liste_modeles($this->db); 1841 } 1842 elseif ($modulepart == 'facture') 1843 { 1844 include_once (DOL_DOCUMENT_ROOT.'/includes/modules/facture/modules_facture.php'); 1845 $model=new ModelePDFFactures(); 1846 $liste=$model->liste_modeles($this->db); 1847 } 1848 else 1849 { 1850 dolibarr_print_error($this->db,'Bad value for modulepart'); 1851 } 1852 print '<tr '.$bc[$var].'><td>'.$langs->trans('Model').'</td><td align="center">'; 1853 $this->select_array('modelpdf',$liste,$modelselected); 1854 $texte=$langs->trans('Generate'); 1855 print '</td><td align="center" colspan="2"><input class="button" type="submit" value="'.$texte.'">'; 1856 print '</td></tr>'; 1857 } 1858 } 1859 1860 print "<tr $bc[$var]>"; 1861 $mimetype=strtoupper($extension); 1862 if ($extension == 'pdf') $mimetype='PDF'; 1863 if ($extension == 'html') $mimetype='HTML'; 1864 if (eregi('\-detail\.pdf',$file)) $mimetype='PDF Détaillé'; 1865 print '<td nowrap>'.$mimetype.'</td>'; 1866 print '<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&file='.urlencode($relativepath).'">'.$file.'</a></td>'; 1867 print '<td align="right">'.filesize($filedir."/".$file). ' bytes</td>'; 1868 print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($filedir."/".$file)).'</td>'; 1869 print '</tr>'; 1870 1871 $i++; 1872 } 1873 } 1874 1875 if ($i > 0) 1876 { 1877 // Affiche pied du tableau 1878 print "</table>\n"; 1879 if ($genallowed) 1880 { 1881 print '</form>'; 1882 } 1883 } 1884 1885 } 1886 1887 } 1888 1889 ?>
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 |
|