noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_itva_popup.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief Html Input
00024  */
00025 require_once ('class_ipopup.php');
00026 require_once('class_ibutton.php');
00027 require_once('class_ispan.php');
00028 /**
00029  *@brief let you choose a TVA in a popup
00030  *@code
00031     $a=new IPopup('popup_tva');
00032     $a->set_title('Choix de la tva');
00033     echo $a->input();
00034     $tva=new ITva_Popup("tva1");
00035     $tva->with_button(true);
00036     // You must add the attributes gDossier, popup
00037     $tva->set_attribute('popup','popup_tva');
00038     $tva->set_attribute('gDossier',dossier::id());
00039 
00040     // We can add a label for the code
00041     $tva->add_label('code');
00042     $tva->js='onchange="set_tva_label(this);"';
00043     echo $tva->input();
00044 @endcode
00045 */
00046 class ITva_Popup extends HtmlInput
00047 {
00048     /**
00049      *@brief by default, the p_name is the name/id of the input type
00050      * the this->button is false (control if a button is visible) and
00051      * this->in_table=false (return the widget inside a table)
00052      * this->code is a span widget to display the code (in this case, you will
00053      * to set this->cn as database connexion)
00054      * to have its own javascript for the button you can use this->but_javascript)
00055      * by default it is 'popup_select_tva(this)';
00056      */
00057     public function __construct($p_name=null,$p_value="",$p_id="")
00058     {
00059         $this->name=$p_name;
00060         $this->button=true;
00061         $this->in_table=false;
00062                 $this->value=$p_value;
00063                 $this->id=$p_id;
00064     }
00065     function with_button($p)
00066     {
00067         if ($p == true )
00068             $this->button=true;
00069         else
00070             $this->button=false;
00071     }
00072     /*!\brief show the html  input of the widget*/
00073     public function input($p_name=null,$p_value=null)
00074     {
00075         $this->name=($p_name==null)?$this->name:$p_name;
00076         $this->value=($p_value==null)?$this->value:$p_value;
00077         $this->js=(isset($this->js))?$this->js:'onchange="format_number(this);"';
00078                 $this->id=($this->id=="")?$this->name:$this->id;
00079 
00080         if ( $this->readOnly==true) return $this->display();
00081 
00082         $str='<input type="TEXT"  class="input_text" name="%s" value="%s" id="%s" size="3" %s>';
00083         $r=sprintf($str,$this->name,$this->value,$this->id,$this->js);
00084 
00085         if ($this->in_table)
00086             $table='<table>'.'<tr>'.td($r);
00087 
00088         if ( $this->button==true && ! $this->in_table)
00089             $r.=$this->dbutton();
00090 
00091         if ( $this->button==true &&  $this->in_table)
00092             $r=$table.td($this->dbutton()).'</tr></table>';
00093 
00094         if ( isset($this->code))
00095         {
00096             if ( $this->cn != NULL)
00097             {
00098                 /* check if tva_id == integer */
00099                 if (trim($this->value)!='' &&  isNumber($this->value)==1 && strpos($this->value,',') === false)
00100                     $this->code->value=$this->cn->get_value('select tva_label from tva_rate where tva_id=$1',
00101                                                             array($this->value));
00102                 ;
00103             }
00104             $r.=$this->code->input();
00105             if ($this->table==1) $r=td($r);
00106             $this->set_attribute('jcode',$this->code->name);
00107             $this->set_attribute('gDossier',dossier::id());
00108             $this->set_attribute('ctl',$this->name);
00109             $r.=$this->get_js_attr();
00110 
00111         }
00112 
00113         return $r;
00114 
00115     }
00116     /**
00117      *@brief show a button, if it is pushed show a popup to select the need vat
00118      *@note
00119      * - a ipopup must be created before with the name popup_tva
00120      * - the javascript scripts.js must be loaded
00121      *@return string with html code
00122      */
00123     function dbutton()
00124     {
00125         if( trim($this->name)=='') throw new Exception (_('Le nom ne peut ĂȘtre vide'));
00126                 $this->id=($this->id=="")?$this->name:$this->id;
00127 
00128         // button
00129         $bt=new ISmallButton('bt_'.$this->id);
00130                 $bt->tabindex="-1";
00131         $bt->label=_(' TVA ');
00132         $bt->set_attribute('gDossier',dossier::id());
00133         $bt->set_attribute('ctl',$this->id);
00134         $bt->set_attribute('popup','popup_tva');
00135         if ( isset($this->code))
00136             $bt->set_attribute('jcode',$this->code->name);
00137         if ( isset($this->compute))
00138             $bt->set_attribute('compute',$this->compute);
00139         $bt->javascript=(isset($this->but_javascript))?$this->but_javascript:'popup_select_tva(this)';
00140         $r=$bt->input();
00141         return $r;
00142     }
00143 
00144     /*!\brief print in html the readonly value of the widget*/
00145     public function display()
00146     {
00147         $cn=  new Database(Dossier::id());
00148         $tva=new Acc_Tva($cn, $this->value);
00149         
00150         $comment=($tva->load()  != "-1")? $tva->tva_label:"";
00151         $res=sprintf('<input type="text" name="%s" size="6" class="input_text_ro" value="%s" id="%s" readonly="">%s',$this->name,$this->value,$this->name,$comment);
00152         return $res;
00153     }
00154     /**
00155      *@brief add a field to show the selected tva's label
00156      *@param $p_code is the name of the label where you can see the label of VAT
00157      *@param $p_cn is a database connection if NULL it doesn't seek in the database
00158      */
00159     public function add_label($p_code,$p_cn=null)
00160     {
00161         $this->cn=$p_cn;
00162         $this->code=new ISpan($p_code);
00163     }
00164     static public function test_me()
00165     {
00166         $a=new IPopup('popup_tva');
00167         $a->set_title('Choix de la tva');
00168         echo $a->input();
00169         $tva=new ITva_Popup("tva1");
00170         $tva->with_button(true);
00171         // We can add a label for the code
00172         $tva->add_label('code');
00173         $tva->js='onchange="set_tva_label(this);"';
00174         echo $tva->input();
00175         echo $tva->dbutton();
00176     }
00177 }
 All Data Structures Namespaces Files Functions Variables Enumerations