noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_itva_popup.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This file is part of NOALYSS.
4  *
5  * NOALYSS is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * NOALYSS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with NOALYSS; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 // Copyright Author Dany De Bontridder danydb@aevalys.eu
21 
22 /*!\file
23  * \brief Html Input
24  */
25 require_once NOALYSS_INCLUDE.'/lib/class_ipopup.php';
26 require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
27 require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
28 /**
29  *@brief let you choose a TVA in a popup
30  *@code
31  $a=new IPopup('popup_tva');
32  $a->set_title('Choix de la tva');
33  echo $a->input();
34  $tva=new ITva_Popup("tva1");
35  $tva->with_button(true);
36  // You must add the attributes gDossier, popup
37  $tva->set_attribute('popup','popup_tva');
38  $tva->set_attribute('gDossier',dossier::id());
39 
40  // We can add a label for the code
41  $tva->add_label('code');
42  $tva->js='onchange="set_tva_label(this);"';
43  echo $tva->input();
44 @endcode
45 */
46 class ITva_Popup extends HtmlInput
47 {
48  /**
49  *@brief by default, the p_name is the name/id of the input type
50  * the this->button is false (control if a button is visible) and
51  * this->in_table=false (return the widget inside a table)
52  * this->code is a span widget to display the code (in this case, you will
53  * to set this->cn as database connexion)
54  * to have its own javascript for the button you can use this->but_javascript)
55  * by default it is 'popup_select_tva(this)';
56  */
57  public function __construct($p_name=null,$p_value="",$p_id="")
58  {
59  $this->name=$p_name;
60  $this->button=true;
61  $this->in_table=false;
62  $this->value=$p_value;
63  $this->id=$p_id;
64  }
65  function with_button($p)
66  {
67  if ($p == true )
68  $this->button=true;
69  else
70  $this->button=false;
71  }
72  /*!\brief show the html input of the widget*/
73  public function input($p_name=null,$p_value=null)
74  {
75  $this->name=($p_name==null)?$this->name:$p_name;
76  $this->value=($p_value==null)?$this->value:$p_value;
77  $this->js=(isset($this->js))?$this->js:'onchange="format_number(this);"';
78  $this->id=($this->id=="")?$this->name:$this->id;
79 
80  if ( $this->readOnly==true) return $this->display();
81 
82  $str='<input type="TEXT" class="input_text" name="%s" value="%s" id="%s" size="3" %s>';
83  $r=sprintf($str,$this->name,$this->value,$this->id,$this->js);
84 
85  if ($this->in_table)
86  $table='<table>'.'<tr>'.td($r);
87 
88  if ( $this->button==true && ! $this->in_table)
89  $r.=$this->dbutton();
90 
91  if ( $this->button==true && $this->in_table)
92  $r=$table.td($this->dbutton()).'</tr></table>';
93 
94  if ( isset($this->code))
95  {
96  if ( $this->cn != NULL)
97  {
98  /* check if tva_id == integer */
99  if (trim($this->value)!='' && isNumber($this->value)==1 && strpos($this->value,',') === false)
100  $this->code->value=$this->cn->get_value('select tva_label from tva_rate where tva_id=$1',
101  array($this->value));
102  ;
103  }
104  $r.=$this->code->input();
105  if ($this->table==1) $r=td($r);
106  $this->set_attribute('jcode',$this->code->name);
107  $this->set_attribute('gDossier',dossier::id());
108  $this->set_attribute('ctl',$this->name);
109  $r.=$this->get_js_attr();
110 
111  }
112 
113  return $r;
114 
115  }
116  /**
117  *@brief show a button, if it is pushed show a popup to select the need vat
118  *@note
119  * - a ipopup must be created before with the name popup_tva
120  * - the javascript scripts.js must be loaded
121  *@return string with html code
122  */
123  function dbutton()
124  {
125  if( trim($this->name)=='') throw new Exception (_('Le nom ne peut ĂȘtre vide'));
126  $this->id=($this->id=="")?$this->name:$this->id;
127 
128  // button
129  $bt=new ISmallButton('bt_'.$this->id);
130  $bt->tabindex="-1";
131  $bt->label=_(' TVA ');
132  $bt->set_attribute('gDossier',dossier::id());
133  $bt->set_attribute('ctl',$this->id);
134  $bt->set_attribute('popup','popup_tva');
135  if ( isset($this->code))
136  $bt->set_attribute('jcode',$this->code->name);
137  if ( isset($this->compute))
138  $bt->set_attribute('compute',$this->compute);
139  $bt->javascript=(isset($this->but_javascript))?$this->but_javascript:'popup_select_tva(this)';
140  $r=$bt->input();
141  return $r;
142  }
143 
144  /*!\brief print in html the readonly value of the widget*/
145  public function display()
146  {
148  $tva=new Acc_Tva($cn, $this->value);
149 
150  $comment=($tva->load() != "-1")? $tva->tva_label:"";
151  $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);
152  return $res;
153  }
154  /**
155  *@brief add a field to show the selected tva's label
156  *@param $p_code is the name of the label where you can see the label of VAT
157  *@param $p_cn is a database connection if NULL it doesn't seek in the database
158  */
159  public function add_label($p_code,$p_cn=null)
160  {
161  $this->cn=$p_cn;
162  $this->code=new ISpan($p_code);
163  }
164  static public function test_me()
165  {
166  $a=new IPopup('popup_tva');
167  $a->set_title('Choix de la tva');
168  echo $a->input();
169  $tva=new ITva_Popup("tva1");
170  $tva->with_button(true);
171  // We can add a label for the code
172  $tva->add_label('code');
173  $tva->js='onchange="set_tva_label(this);"';
174  echo $tva->input();
175  echo $tva->dbutton();
176  }
177 }
$str
Definition: fiche.inc.php:97
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
add_label($p_code, $p_cn=null)
add a field to show the selected tva's label
static test_me()
input($p_name=null, $p_value=null)
show the html input of the widget
get_js_attr()
you can add attribute to this in javascript this function is a wrapper and create a script (in js) to...
set_attribute($p_name, $p_value)
set the extra javascript property for the INPUT field
let you choose a TVA in a popup
isNumber(&$p_int)
Definition: ac_common.php:202
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
for($e=0;$e< count($array);$e++) $desc readOnly
Acc_Tva is used for to map the table tva_rate parameter are.
$from_poste name
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
$input_from cn
Definition: balance.inc.php:71
if(!isset($_REQUEST['p_jrn'])) else $Ledger id
display()
print in html the readonly value of the widget
static connect()
dbutton()
show a button, if it is pushed show a popup to select the need vat
class widget This class is used to create all the HTML INPUT TYPE and some specials which works with ...
$select_type table
__construct($p_name=null, $p_value="", $p_id="")
by default, the p_name is the name/id of the input type the this->button is false (control if a button...
$p
Definition: array.php:34