/[dolibarr]/dolibarr/htdocs/html.form.class.php
ViewVC logotype

Diff of /dolibarr/htdocs/html.form.class.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.101 by eldy, Thu Sep 1 18:02:12 2005 UTC revision 1.102 by eldy, Fri Sep 2 20:17:22 2005 UTC
# Line 37  Line 37 
37    
38  class Form  class Form
39  {  {
40    var $db;      var $db;
41    var $errorstr;      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          \brief     Constructeur
51          \param     DB      handler d'accès base de donnée          \param     DB      handler d'accès base de donnée
52    */      */
           
   function Form($DB)  
   {  
     $this->db = $DB;  
53            
54      return 1;      function Form($DB)
55    }      {
56            $this->db = $DB;
57            
58            return 1;
59        }
60        
61    /**      /**
62     *    \brief      Retourne la liste déroulante des départements/province/cantons tout pays confondu ou pour un pays donné.       *    \brief      Retourne la liste déroulante des départements/province/cantons tout pays confondu ou pour un pays donné.
63     *    \remarks    Dans le cas d'une liste tout pays confondus, l'affichage fait une rupture sur le pays.       *    \remarks    Dans le cas d'une liste tout pays confondus, l'affichage fait une rupture sur le pays.
64     *    \remarks    La cle de la liste est le code (il peut y avoir plusieurs entrée pour       *    \remarks    La cle de la liste est le code (il peut y avoir plusieurs entrée pour
65     *                un code donnée mais dans ce cas, le champ pays diffère).       *                un code donnée mais dans ce cas, le champ pays diffère).
66     *                Ainsi les liens avec les départements se font sur un département indépendemment de nom som.       *                Ainsi les liens avec les départements se font sur un département indépendemment de nom som.
67     *    \param      selected        code forme juridique a présélectionné       *    \param      selected        code forme juridique a présélectionné
68     *    \param      pays_code       0=liste tous pays confondus, sinon code du pays à afficher       *    \param      pays_code       0=liste tous pays confondus, sinon code du pays à afficher
69     */       */
70        function select_departement($selected='',$pays_code=0)
71    function select_departement($selected='',$pays_code=0)      {
   {  
72      global $conf,$langs;      global $conf,$langs;
73      $langs->load("dict");      $langs->load("dict");
74            
# Line 445  class Form Line 450  class Form
450     *    \param      filtretype      Pour filtre sur type de produit     *    \param      filtretype      Pour filtre sur type de produit
451     *    \param      limit           Limite sur le nombre de lignes retourné     *    \param      limit           Limite sur le nombre de lignes retourné
452     */     */
453    function select_produits($selected='',$htmlname='productid',$filtretype='',$limit=20)      function select_produits($selected='',$htmlname='productid',$filtretype='',$limit=20)
454    {      {
455      global $langs,$conf;          global $langs,$conf;
456            
457      $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration";          $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration";
458      $sql.= " FROM ".MAIN_DB_PREFIX."product as p ";          $sql.= " FROM ".MAIN_DB_PREFIX."product as p ";
459      $sql.= " WHERE p.envente = 1";          $sql.= " WHERE p.envente = 1";
460      if ($filtretype && $filtretype != '') $sql.=" AND p.fk_product_type=".$filtretype;          if ($filtretype && $filtretype != '') $sql.=" AND p.fk_product_type=".$filtretype;
461      $sql.= " ORDER BY p.nbvente DESC";          $sql.= " ORDER BY p.nbvente DESC";
462      if ($limit) $sql.= " LIMIT $limit";          if ($limit) $sql.= " LIMIT $limit";
463            
464      $result=$this->db->query($sql);          $result=$this->db->query($sql);
465      if ($result)          if ($result)
466      {          {
467          print '<select class="flat" name="'.$htmlname.'">';              print '<select class="flat" name="'.$htmlname.'">';
468          print "<option value=\"0\" selected=\"true\">&nbsp;</option>";              print "<option value=\"0\" selected=\"true\">&nbsp;</option>";
469        
470          $num = $this->db->num_rows($result);              $num = $this->db->num_rows($result);
471          $i = 0;              $i = 0;
472          while ($i < $num)              while ($i < $num)
473                {
474                    $objp = $this->db->fetch_object($result);
475                    $opt = "<option value=\"$objp->rowid\">[$objp->ref] $objp->label - $objp->price ".$langs->trans("Currency".$conf->monnaie);
476                    if ($objp->duration) $opt .= " - ".$objp->duration;
477                    $opt .= "</option>\n";
478                    print $opt;
479                    $i++;
480                }
481                print '</select>';
482        
483                $this->db->free($result);
484            }
485            else
486          {          {
487              $objp = $this->db->fetch_object($result);              dolibarr_print_error($db);
             $opt = "<option value=\"$objp->rowid\">[$objp->ref] $objp->label - $objp->price ".$langs->trans("Currency".$conf->monnaie);  
             if ($objp->duration) $opt .= " - ".$objp->duration;  
             $opt .= "</option>\n";  
             print $opt;  
             $i++;  
488          }          }
         print '</select>';  
           
         $this->db->free($result);  
489      }      }
490      else    
491    
492        /**
493         *    \brief      Charge dans cache la liste des conditions de paiements possibles
494         *    \param      selected        Condition de paiement présélectionnée
495         *    \param      htmlname        Nom de la zone select
496         *    \param      filtretype      Pour filtre
497         */
498        function load_cache_conditions_paiements()
499      {      {
500          dolibarr_print_error($db);          global $langs;
501    
502            dolibarr_syslog('html.form.class.php::load_cache_conditions_paiements');
503            $sql = "SELECT rowid, libelle";
504            $sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement";
505            $sql.= " WHERE actif=1";
506            $sql.= " ORDER BY sortorder";
507            $resql = $this->db->query($sql);
508            if ($resql)
509            {
510                $num = $this->db->num_rows($result);
511                $i = 0;
512                while ($i < $num)
513                {
514                    $obj = $this->db->fetch_object($resql);
515    
516                    // Si traduction existe, on l'utilise, sinon on prend le libellé par défaut
517                    $libelle=($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->libelle!='-'?$obj->libelle:''));
518                    $this->cache_conditions_paiements_code[$obj->rowid]=$obj->code;
519                    $this->cache_conditions_paiements_libelle[$obj->rowid]=$libelle;
520                    $i++;
521                }
522                return 1;
523            }
524            else {
525                dolibarr_print_error($this->db);
526                return -1;
527            }
528      }      }
529    }  
530          /**
531           *    \brief      Charge dans cache la liste des types de paiements possibles
532    /**       *    \param      selected        Type de praiement présélectionné
533     *    \brief      Retourne la liste des types de paiements possibles       *    \param      htmlname        Nom de la zone select
534     *    \param      selected        Type de praiement présélectionné       *    \param      filtretype      Pour filtre
535     *    \param      htmlname        Nom de la zone select       */
536     *    \param      filtretype      Pour filtre      function load_cache_types_paiements()
    */  
     function select_types_paiements($selected='',$htmlname='paiementtype',$filtertype=-1)  
537      {      {
538          global $langs;          global $langs;
539            
540          $sql = "SELECT id, code, libelle";          dolibarr_syslog('html.form.class.php::load_cache_types_paiements');
541            $sql = "SELECT id, code, libelle, type";
542          $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement";          $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement";
543          $sql.= " WHERE active > 0";          $sql.= " WHERE active > 0";
         if ($filtertype >= 0) $sql.=" AND type = $filtertype";  
544          $sql.= " ORDER BY id";          $sql.= " ORDER BY id";
545          $result = $this->db->query($sql);          $resql = $this->db->query($sql);
546          if ($result)          if ($resql)
547          {          {
             print '<select class="flat" name="'.$htmlname.'">';  
548              $num = $this->db->num_rows($result);              $num = $this->db->num_rows($result);
549              $i = 0;              $i = 0;
550              while ($i < $num)              while ($i < $num)
551              {              {
552                  $obj = $this->db->fetch_object($result);                  $obj = $this->db->fetch_object($resql);
553                  if ($selected == $obj->code)  
                 {  
                     print '<option value="'.$obj->id.'" selected="true">';  
                 }  
                 else  
                 {  
                     print '<option value="'.$obj->id.'">';  
                 }  
554                  // Si traduction existe, on l'utilise, sinon on prend le libellé par défaut                  // Si traduction existe, on l'utilise, sinon on prend le libellé par défaut
555                  print ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->libelle!='-'?$obj->libelle:''));                  $libelle=($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->libelle!='-'?$obj->libelle:''));
556                  print '</option>';                  $this->cache_types_paiements_code[$obj->id]=$obj->code;
557                    $this->cache_types_paiements_libelle[$obj->id]=$libelle;
558                    $this->cache_types_paiements_type[$obj->id]=$obj->type;
559                  $i++;                  $i++;
560              }              }
561              print "</select>";              return 1;
562          }          }
563          else {          else {
564              dolibarr_print_error($this->db);              dolibarr_print_error($this->db);
565                return -1;
566            }
567        }
568    
569    
570    
571         /**
572         *    \brief      Retourne la liste des types de paiements possibles
573         *    \param      selected        Type de praiement présélectionné
574         *    \param      htmlname        Nom de la zone select
575         *    \param      filtretype      Pour filtre
576         */
577        function select_conditions_paiements($selected='',$htmlname='condid',$filtertype=-1)
578        {
579            global $langs;
580            
581            // Charge le cache si premier appel
582            if (! sizeof($this->cache_conditions_paiements_code))
583            {
584                $this->load_cache_conditions_paiements();
585            }
586    
587            print '<select class="flat" name="'.$htmlname.'">';
588            foreach($this->cache_conditions_paiements_code as $id => $code)
589            {
590                if ($selected == $code)
591                {
592                    print '<option value="'.$id.'" selected="true">';
593                }
594                else
595                {
596                    print '<option value="'.$id.'">';
597                }
598                print $this->cache_conditions_paiements_libelle[$id];
599                print '</option>';
600            }
601            print '</select>';
602        }
603    
604    
605        
606    
607        /**
608         *      \brief      Retourne la liste des types de paiements possibles
609         *      \param      selected        Type de praiement présélectionné
610         *      \param      htmlname        Nom de la zone select
611         *      \param      filtretype      Pour filtre
612         *      \param      format          0=id+libelle, 1=code+code
613         */
614        function select_types_paiements($selected='',$htmlname='paiementtype',$filtertype='',$format=0)
615        {
616            global $langs;
617    
618            $filterarray=array();
619            if ($filtertype && $filtertype != '-1') $filterarray=split(',',$filtertype);
620            
621            // Charge le cache si premier appel
622            if (! sizeof($this->cache_types_paiements_code))
623            {
624                $this->load_cache_types_paiements();
625            }
626    
627            //dolibarr_syslog('html.form.class.php::select_types_paiements use cache');
628            print '<select class="flat" name="'.$htmlname.'">';
629            foreach($this->cache_types_paiements_code as $id => $code)
630            {
631                // On passe si on a demandé de filtrer sur des modes de paiments particulièrs
632                if (sizeof($filterarray) && ! in_array($this->cache_types_paiements_type[$id],$filterarray)) continue;
633    
634                if ($format == 0) print '<option value="'.$id.'"';
635                if ($format == 1) print '<option value="'.$code.'"';
636                if ($selected == $code)
637                {
638                    print ' selected="true"';
639                }
640                print '>';
641                if ($format == 0) print $this->cache_types_paiements_libelle[$id];
642                if ($format == 1) print $code;
643                print '</option>';
644          }          }
645            print '</select>';
646      }      }
647    
648    

Legend:
Removed from v.1.101  
changed lines
  Added in v.1.102

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26