noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_icard.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 Input HTML for the card show buttons
24  *
25  */
26 
27 /*!
28  * \brief Input HTML for the card show buttons, in the file, you have to add card.js
29  * How to use :
30  * - label is the label in the button
31  * - extra contents the type (all, deb or cred, a list of FD_ID between parent. or a SQL clause
32  * - attribute are the attribute to set (via ajax). The ledger is either a attribute (jrn) or a
33  * hidden field in the document, if none are set, there is no filter on the ledger
34  *\note you must in a hidden field gDossier (dossier::hidden)
35  *\see ajaxFid
36  *\see card.js
37  *\see fid.php
38  *\see fid_card.php
39  *\see ajax_card.php
40  *
41  * Set the hidden field or input field to be set by javascript with the function set_attribute
42  * call the input method. After selecting a value the update_value function is called. If you need
43  * to modify the queryString before the request is sent, you'll use the set_callback; the first
44  * parameter is the INPUT field and the second the queryString, the function must returns a
45  * queryString
46  *\code
47 // insert all the javascript files
48  echo js_include('prototype.js');
49  echo js_include('scriptaculous.js');
50  echo js_include('effects.js');
51  echo js_include('controls.js');
52 
53 //
54  $W1=new ICard();
55  $W1->label="Client ".HtmlInput::infobulle(0) ;
56  $W1->name="e_client";
57  $W1->tabindex=3;
58  $W1->value=$e_client;
59  $W1->table=0;
60 // If double click call the javascript fill_ipopcard
61  $W1->set_dblclick("fill_ipopcard(this);");
62 
63  // Type of card : deb, cred or all
64  $W1->set_attribute('typecard','deb');
65 
66  $W1->extra='deb';
67 
68 // Add the callback function to filter the card on the jrn
69  $W1->set_callback('filter_card');
70 
71 // when value selected in the autcomplete
72  $W1->set_function('fill_data');
73 
74 // when the data change
75  $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
76  $W1->name);
77 
78  // name of the field to update with the name of the card
79  $W1->set_attribute('label','e_client_label');
80  $client_label=new ISpan();
81  $client_label->table=0;
82  $f_client=$client_label->input("e_client_label",$e_client_label);
83 
84  $f_client_qcode=$W1->input();
85 
86 // Search button for card
87  $f_client_bt=$W1->search();
88 * \endcode
89 For searching a card, you need a popup, the script card.js and set
90 the values for card, popup filter_card callback
91 @code
92 $card=new ICard('acc');
93 $card->name="acc";
94 $card->extra="all";
95 $card->set_attribute('typecard','all');
96 $card->set_callback('filter_card');
97 
98 echo $card->input();
99 echo $card->search();
100 // example 2
101 $w=new ICard("av_text".$attr->ad_id);
102 // filter on frd_id
103 $sql=' select fd_id from fiche_def where frd_id in ('.FICHE_TYPE_CLIENT.','.FICHE_TYPE_FOURNISSEUR.','.FICHE_TYPE_ADM_TAX.')';
104 $filter=$this->cn->make_list($sql);
105 $w->set_attribute('ipopup','ipopcard');
106 $w->set_attribute('typecard',$filter);
107 $w->set_attribute('inp',"av_text".$attr->ad_id);
108 $w->set_attribute('label',"av_text".$attr->ad_id."_label");
109 
110 $w->extra=$filter;
111 $w->extra2=0;
112 $label=new ISpan();
113 $label->name="av_text".$attr->ad_id."_label";
114 $msg.=td($w->search().$label->input());
115 @endcode
116 */
117 require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
118 require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
119 
120 class ICard extends HtmlInput
121 {
122  function __construct($name="",$value="",$p_id="")
123  {
124  parent::__construct($name,$value);
125  $this->fct='update_value';
126  $this->dblclick='';
127  $this->callback='null';
128  $this->javascript='';
129  $this->id=($p_id != "")?$p_id:$name;
130  $this->choice=null;
131  $this->indicator=null;
132  $this->choice_create=1;
133  $this->autocomplete=1;
134  $this->style=' style="vertical-align:50%"';
135  }
136  /*!\brief set the javascript callback function
137  * by default it is update_value called BEFORE the querystring is send
138  *
139  *\param $p_name callback function name
140  */
141  function set_callback($p_name)
142  {
143  $this->callback=$p_name;
144  }
145 
146  /*!\brief set the javascript callback function
147  * by default it is update_value called AFTER an item has been selected
148  *\param $p_name callback function name
149  */
150  function set_function($p_name)
151  {
152  $this->fct=$p_name;
153  }
154  /*!\brief return the html string for creating the ipopup, this ipopup
155  * can be used for adding, modifying or display a card
156  *@note ipopup is obsolete, the popin is created by javascript
157  *\param $p_name name of the ipopup, must be set after with set_attribute
158  \code
159  $f_add_button=new IButton('add_card');
160  $f_add_button->label='Créer une nouvelle fiche';
161  $f_add_button->set_attribute('ipopup','ipop_newcard');
162  $f_add_button->set_attribute('filter',$this->get_all_fiche_def ());
163  $f_add_button->javascript=" select_card_type(this);";
164  $str_add_button=$f_add_button->input();
165 
166  \endcode
167  *\return html string
168  *\note must be one of first instruction on a new page, to avoid problem
169  * of position with IE
170  */
171  static function ipopup($p_name)
172  {
173  $ip_card=new IPopup ($p_name);
174  $ip_card->drag=true;
175  $ip_card->set_width('45%');
176  $ip_card->title='Fiche ';
177  $ip_card->value='';
178 
179  return $ip_card->input();
180  }
181  /*!\brief set the extra javascript property for a double click on
182  * INPUT field
183  *\param $p_action action when a double click happens
184  *\note the $p_action cannot contain a double quote
185  */
187  {
188  $this->dblclick=$p_action;
189  }
190  /*!\brief show the html input of the widget*/
191  public function input($p_name=null,$p_value=null)
192  {
193  if ( $p_name == null && $this->name == "")
194  throw (new Exception('Le nom d une icard doit être donne'));
195 
196  $this->value=($p_value==null)?$this->value:$p_value;
197  if ( $this->readOnly==true) return $this->display();
198 
199  $this->id=($this->id=="")?$this->name:$this->id;
200  $this->choice=($this->choice==null)?sprintf("%s_choices",$this->id):$this->choice;
201  $this->indicator=($this->indicator==null)?sprintf("%s_ind",$this->id):$this->indicator;
202  $attr=$this->get_js_attr();
203 
204  $label='';
205  if ( $this->dblclick != '')
206  {
207  $e=sprintf(' ondblclick="%s" ',
208  $this->dblclick);
209  $this->dblclick=$e;
210  }
211  $input=sprintf('<INPUT TYPE="Text" class="input_text" '.
212  ' NAME="%s" ID="%s" VALUE="%s" SIZE="%d" %s %s %s>',
213  $this->name,
214  $this->id,
215  $this->value,
216  $this->size,
217  $this->dblclick,
218  $this->javascript,
219  $this->style
220  );
221  if ( $this->autocomplete == 1)
222  {
223  $this->indicator="ind_".$this->id;
224  $ind=sprintf('<span id="%s" class="autocomplete" style="position:absolute;display:none">Un instant... <img src="image/loading.gif" alt="Chargement..."/>'.
225  '</span>',
226  $this->indicator);
227  $this->indicator="null";
228  $div=($this->choice_create == 1) ? sprintf('<div id="%s" class="autocomplete"></div>',$this->choice):"";
229 
230  $query=dossier::get().'&e='.urlencode($this->typecard);
231 
232  $javascript=sprintf('try { new Ajax.Autocompleter("%s","%s","fid_card.php?%s",'.
233  '{paramName:"FID",minChars:1,indicator:%s, '.
234  'callback:%s, '.
235  ' afterUpdateElement:%s});} catch (e){alert(e.message);};',
236  $this->id,
237  $this->choice,
238  $query,
239  $this->indicator,
240  $this->callback,
241  $this->fct);
242 
243  $javascript=create_script($javascript.$this->dblclick);
244 
245  $r=$label.$input.$attr.$ind.$div.$javascript;
246  }
247  else
248  {
249  $r=$label.$input;
250  }
251  if ( $this->table == 1 )
252  $r=td($r);
253  return $r;
254 
255  }
256  /*!\brief print in html the readonly value of the widget*/
257  public function display()
258  {
259  $r=sprintf(' <INPUT TYPE="hidden" NAME="%s" id="%s" VALUE="%s" SIZE="8">',
260  $this->name,
261  $this->name,
262  $this->value
263  );
264  $r.='<span>'.$this->value.'</span>';
265  return $r;
266 
267  }
268  /**
269  *@brief return a string containing the button for displaying
270  * a search form. When clicking on the result, update the input text file
271  * the common used attribute as
272  * - jrn the ledger
273  * - label the field to update
274  * - name name of the input text
275  * - price amount
276  * - tvaid
277  * - typecard (deb, cred, filter or list of value)
278  * will be set
279  * if ICard is in readOnly, the button disappears, so the return string is empty
280  \code
281  // search ipopup
282  $search_card=new IPopup('ipop_card');
283  $search_card->title=_('Recherche de fiche');
284  $search_card->value='';
285  echo $search_card->input();
286 
287  $a=new ICard('test');
288  $a->search();
289 
290  \endcode
291  *\see ajax_card.php
292  *\note the ipopup id is hard coded : ipop_card
293  *@return HTML string with the button
294  */
295  function search()
296  {
297  if ( $this->readOnly==true) return '';
298  if ( ! isset($this->id )) $this->id=$this->name;
299  $a="";
300  foreach (array('typecard','jrn','label','price','tvaid') as $att)
301  {
302  if (isset($this->$att) )
303  $a.="this.".$att."='".$this->$att."';";
304  }
305  if (isset($this->id) && $this->id != "")
306  $a.="this.inp='".$this->id."';";
307  else
308  $a.="this.inp='".$this->name."';";
309  $a.="this.popup='ipop_card';";
310  $javascript=$a.' search_card(this);return false;';
311 
312  $button=HtmlInput::button_image($javascript,$this->name."_bt", 'alt="'._('Recherche').'" class="image_search"',"image/magnifier13.png");
313  return $button;
314  }
315 
316  static public function test_me()
317  {
318  require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
319  $_SESSION['isValid']=1;
320  $a=new ICard('testme');
321  $a->extra="all";
322  $a->set_attribute('label','ctl_label');
323  $a->set_attribute('tvaid','ctl_tvaid');
324  $a->set_attribute('price','ctl_price');
325  $a->set_attribute('purchase','ctl_purchase');
326  $a->set_attribute('type','all');
327  echo <<<EOF
328  <div id="debug" style="border:solid 1px black;overflow:auto"></div>
329  <script type="text/javascript" language="javascript" src="js/prototype.js">
330  </script>
331  <script type="text/javascript" language="javascript" src="js/scriptaculous.js">
332  </script>
333  <script type="text/javascript" language="javascript" src="js/effects.js">
334  </script>
335  <script type="text/javascript" language="javascript" src="js/controls.js">
336  </script>
337  <script type="text/javascript" language="javascript" src="js/ajax_fid.js">
338  </script>
339  <script type="text/javascript" language="javascript" >
340  function test_value(text,li)
341  {
342  alert("premier"+li.id);
343 
344  str="";
345  str=text.id+'<hr>';
346  if ( text.js_attr1)
347  {
348  str+=text.js_attr1;
349  str+='<hr>';
350  }
351  if ( text.js_attr2)
352  {
353  str+=text.js_attr2;
354  str+='<hr>';
355  }
356  if ( text.js_attr3)
357  {
358  str+=text.js_attr3;
359  str+='<hr>';
360  }
361  for (var i in text)
362  {
363  str+=i+'<br>';
364  }
365 
366  // $('debug').innerHTML=str;
367  ajaxFid(text);
368  }
369  </script>
370 
371 EOF;
372  echo "<form>";
373  $l=new IText('ctl_label');
374  $t=new IText('ctl_tvaid');
375  $p=new IText('ctl_price');
376  $b=new IText('ctl_purchase');
377 
378  echo "Label ".$l->input().'<br>';
379  echo "Tva id ".$t->input().'<br>';
380  echo "Price ".$p->input().'<br>';
381  echo "Purchase ".$b->input().'<br>';
382 
383  if ( isset($_REQUEST['test_select']) )
384  echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
385  $a->set_function('test_value');
386  $a->javascript=' onchange="alert(\'onchange\');" onblur="alert(\'onblur\');" ';
387  echo $a->input();
388  echo dossier::hidden();
389  echo HtmlInput::submit('Entree','entree');
390  echo '</form>';
391  echo <<<EOF
392 EOF;
393  }
394 }
alert($p_msg, $buffer=false)
alert in javascript
Definition: ac_common.php:666
$opd_description style
set_function($p_name)
set the javascript callback function by default it is update_value called AFTER an item has been sele...
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
display()
print in html the readonly value 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...
function ajaxFid(p_ctl)
this function fills the data from fid.php,
Definition: ajax_fiche.js:67
$ret javascript
search()
return a string containing the button for displaying a search form.
for($e=0;$e< count($array);$e++) $desc readOnly
set_callback($p_name)
set the javascript callback function by default it is update_value called BEFORE the querystring is s...
$div
$name size
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
static ipopup($p_name)
return the html string for creating the ipopup, this ipopup can be used for adding, modifying or display a card
$from_poste name
$_REQUEST['ac']
$input_from type
Definition: balance.inc.php:70
set_dblclick($p_action)
set the extra javascript property for a double click on INPUT field
static test_me()
for($i=0;$i<=6;$i++) $ind
Definition: calendar.php:29
Input HTML for the card show buttons, in the file, you have to add card.js How to use : ...
class widget This class is used to create all the HTML INPUT TYPE and some specials which works with ...
input($p_name=null, $p_value=null)
show the html input of the widget
static button_image($javascript, $id="xx", $p_class='class="button"', $p_image="")
button Html image
if(!isset($_GET['submit_query'])) $p_action
$select_type table
static hidden($p_name, $p_value, $p_id="")
$p
Definition: array.php:34
create_script($p_string)
create the HTML for adding the script tags around of the script
__construct($name="", $value="", $p_id="")