noalyss Version-9
icard.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21// Copyright Author Dany De Bontridder danydb@aevalys.eu
22
23/**\file
24 * \brief Input HTML for the card show buttons
25 *
26 */
27
28/**
29 * \brief Input HTML for the card show buttons, in the file, you have to add card.js
30 * How to use :
31 * - label is the label in the button
32 * - extra contents the type (all, deb or cred, a list of FD_ID between parent. or a SQL clause
33 * - attribute are the attribute to set (via ajax). The ledger is either a attribute (jrn) or a
34 * hidden field in the document, if none are set, there is no filter on the ledger
35 * \note you must in a hidden field gDossier (dossier::hidden)
36 * \see ajaxFid
37 * \see card.js
38 * \see fid.php
39 * \see fid_card.php
40 * \see ajax_card.php
41 *
42 * Set the hidden field or input field to be set by javascript with the function set_attribute
43 * call the input method. After selecting a value the update_value function is called. If you need
44 * to modify the queryString before the request is sent, you'll use the set_callback; the first
45 * parameter is the INPUT field and the second the queryString, the function must returns a
46 * queryString
47 * \code
48 // insert all the javascript files
49 echo js_include('prototype.js');
50 echo js_include('scriptaculous.js');
51 echo js_include('effects.js');
52 echo js_include('controls.js');
53
54 //
55 $W1=new ICard();
56 $W1->label="Client ".Icon_Action::infobulle(0) ;
57 $W1->name="e_client";
58 $W1->tabindex=3;
59 $W1->value=$e_client;
60 $W1->table=0;
61 // If double click call the javascript fill_ipopcard
62 $W1->set_dblclick("fill_ipopcard(this);");
63
64 // Type of card : deb, cred or all
65 $W1->set_attribute('typecard','deb');
66
67 $W1->extra='deb';
68
69 // Add the callback function to filter the card on the jrn
70 $W1->set_callback('filter_card');
71
72 // when value selected in the autcomplete
73 $W1->set_function('fill_data');
74
75 // when the data change
76 $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
77 $W1->name);
78
79 // name of the field to update with the name of the card
80 $W1->set_attribute('label','e_client_label');
81 $client_label=new ISpan();
82 $client_label->table=0;
83 $f_client=$client_label->input("e_client_label",$e_client_label);
84
85 $f_client_qcode=$W1->input();
86
87 // Search button for card
88 $f_client_bt=$W1->search();
89 * \endcode
90 For searching a card, you need a popup, the script card.js and set
91 the values for card, popup filter_card callback
92 @code
93 $card=new ICard('acc');
94 $card->name="acc";
95 $card->extra="all";
96 $card->set_attribute('typecard','all');
97 $card->set_callback('filter_card');
98
99 echo $card->input();
100 echo $card->search();
101 // example 2
102 $w=new ICard("av_text".$attr->ad_id);
103 // filter on frd_id
104 $sql=' select fd_id from fiche_def where frd_id in ('.FICHE_TYPE_CLIENT.','.FICHE_TYPE_FOURNISSEUR.','.FICHE_TYPE_ADM_TAX.')';
105 $filter=$this->cn->make_list($sql);
106 $w->set_attribute('ipopup','ipopcard');
107 $w->set_attribute('typecard',$filter);
108 $w->set_attribute('inp',"av_text".$attr->ad_id);
109 $w->set_attribute('label',"av_text".$attr->ad_id."_label");
110
111 $w->extra=$filter;
112 $w->extra2=0;
113 $label=new ISpan();
114 $label->name="av_text".$attr->ad_id."_label";
115 $msg.=td($w->search().$label->input());
116 @endcode
117 */
118require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
119
120class ICard extends HtmlInput
121{
122 //!< $fct ,by default it is update_value called BEFORE the querystring is send
123 var $fct;
124
125 //!< $dblclick action if double click
127
128 //!< $callback ,
130
131 //!< $choice
133
134 //!< $indicator, text displaid when searching
136
137 //!< $choice_create 1 , display a (+) button , default 1
139
140 //!< $autocomplete : 1 enable - 0 disable
142
143 //!< $style supplemental CSS
144 var $style=' ';
145
146 //!< $accvis account_visible =1 otherwise 0, default 1
148
149 //!< $limit Max of row show
151
152 //!< $amount_from_type : accountancy , sell or purchase price
154
155 //!< $typecard : type of card
157
158 //!< $autocomplete_file , ajax file used for autocompletion (see Ajax.Autocompleter)
160
161 function __construct($name="", $value="", $p_id="")
162 {
163 parent::__construct($name, $value);
164 $this->fct='update_value';
165 $this->dblclick='';
166 $this->callback='null';
167 $this->javascript='';
168 $this->id=($p_id!="")?$p_id:$name;
169 $this->choice=null;
170 $this->indicator=null;
171 $this->choice_create=1;
172 $this->autocomplete=1;
173 $this->style=' ';
174 $this->accvis=1; //!< account_visible =1 otherwise 0
175 $this->limit=12; //!< Max of row show
176 $this->amount_from_type=''; //!< in the follow up ,when a card is selected you take Prix Vente or Prix Achat
177 $this->typecard='all';
178 $this->autocomplete_file="fid_card.php";
179 }
180 /**
181 * Function javascript by default it is update_value called BEFORE the querystring is send in ajax
182 * @return type
183 */
184 public function get_fct()
185 {
186 return $this->fct;
187 }
188 /**
189 * @brief id_of_div_to_populate with the output of the autocomplete_file, it is
190 * the autocomplete div presenting a list of possible choices. Default {this->id}_choices
191 *
192 * @return html string (
193 */
194 public function get_choice()
195 {
196 if ( $this->choice==null) {
197 return sprintf("%s_choices", $this->id);
198 }
199 return $this->choice;
200 }
201 /**
202 * Id of the element to show that it is seaching
203 * @return type
204 */
205 public function get_indicator()
206 {
207 return $this->indicator;
208 }
209 /**
210 * @brief 1 if you want to create automatically the autocomplete DIV to fill with the the output of
211 * "autocomplete_file" or 0 if this DIV is created explicitly
212 *
213 * @return this
214 */
215 public function get_choice_create()
216 {
218 }
219 /**
220 * @brief 1 autocomplete enable ; 0 autocomplete disable
221 * @return type
222 */
223 public function get_autocomplete()
224 {
225 return $this->autocomplete;
226 }
227 /**
228 * CSS Style of the INPUT TEXT element
229 * @return type
230 */
231 public function get_style()
232 {
233 return $this->style;
234 }
235 /***
236 * @brief $accvis account_visible =1 otherwise 0, default 1
237 */
238 public function get_accvis()
239 {
240 return $this->accvis;
241 }
242
243 public function get_limit()
244 {
245 return $this->limit;
246 }
247 /**
248 * @brief amount_from_type : accountancy , sell or purchase price
249 *
250 */
251 public function get_amount_from_type()
252 {
254 }
255
256 public function get_typecard()
257 {
258 return $this->typecard;
259 }
260 /**
261 * @brief php file to call to complete info from the card
262 * @param string $autocomplete_file
263 * @see fid_card.php
264 * @return $this
265 */
266 public function get_autocomplete_file()
267 {
269 }
270 /***
271 * @brief Function javascript by default it is update_value called BEFORE the querystring is send in ajax
272 *@see afterUpdateElement
273 */
274 public function set_fct($fct)
275 {
276 $this->fct=$fct;
277 return $this;
278 }
279 /**
280 * @brief id_of_div_to_populate with the output of the autocomplete_file, it is
281 * the autocomplete div presenting a list of possible choices. Default {this->id}_choices
282 *
283 * @return html string (
284 */
285 public function set_choice($choice)
286 {
287 $this->choice=$choice;
288 return $this;
289 }
290 /**
291 * @brief Id of the element to show that it is seaching
292 */
293 public function set_indicator($indicator)
294 {
295 $this->indicator=$indicator;
296 return $this;
297 }
298 /**
299 * @brief 1 if you want to create automatically the autocomplete DIV to fill with the the output of
300 * "autocomplete_file" or 0 if this DIV is created explicitly
301 *
302 * @return this
303 */
305 {
306 $this->choice_create=$choice_create;
307 return $this;
308 }
309 /**
310 * @brief 1 autocomplet enable ; 0 autocomplete disable
311 * @return type
312 */
314 {
315 $this->autocomplete=$autocomplete;
316 return $this;
317 }
318 /**
319 * CSS Style of the INPUT TEXT element
320 * @return type
321 */
322 public function set_style($style)
323 {
324 $this->style=$style;
325 return $this;
326 }
327 /***
328 * @brief $accvis account_visible =1 otherwise 0, default 1
329 */
330 public function set_accvis($accvis)
331 {
332 $this->accvis=$accvis;
333 return $this;
334 }
335
336 public function set_limit($limit)
337 {
338 $this->limit=$limit;
339 return $this;
340 }
341 /**
342 * @brief amount_from_type : accountancy , sell or purchase price
343 * @parameter $amount_from_type ACH VEN or GL
344 *
345 */
347 {
348 if ( ! in_array($amount_from_type,array("ACH","VEN","GL"))) {
349 throw new Exception('icard.305 '.sprintf("[%s]",$amount_from_type));
350 }
352 return $this;
353 }
354 /**
355 * argument "e" passed to autocomplete_file ,
356 * @see fid_card.php
357 * @param type $typecard
358 * @return $this
359 */
360 public function set_typecard($typecard)
361 {
362 $this->typecard=$typecard;
363 return $this;
364 }
365 /**
366 * @brief php file to call to complete info from the card
367 * @param string $autocomplete_file
368 * @see fid_card.php
369 * @return $this
370 */
372 {
373 $this->autocomplete_file=$autocomplete_file;
374 return $this;
375 }
376
377 /**
378 * @brief in the search box, the accounting will be shown it is the default
379 */
380 function show_accounting() {
381 $this->accvis=1;
382 }
383
384 /**
385 * @brief in the search box, the accounting will be hidden
386 */
388 {
389 $this->accvis=0;
390 }
391
392
393 /**
394 * \brief set the javascript callback function
395 * by default it is update_value called BEFORE the querystring is send
396 *
397 * \param $p_name callback function name
398 */
399
400 function set_callback($p_name)
401 {
402 $this->callback=$p_name;
403 }
404
405 /**\brief set the javascript callback function
406 * by default it is update_value called AFTER an item has been selected
407 * \param $p_name callback function name
408 */
409
410 function set_function($p_name)
411 {
412 $this->fct=$p_name;
413 }
414
415 /**
416 * \brief return the html string for creating the ipopup, this ipopup
417 * can be used for adding, modifying or display a card
418 * @note ipopup is obsolete, the popin is created by javascript
419 * \param $p_name name of the ipopup, must be set after with set_attribute
420 \code
421 $f_add_button=new IButton('add_card');
422 $f_add_button->label='Créer une nouvelle fiche';
423 $f_add_button->set_attribute('ipopup','ipop_newcard');
424 $f_add_button->set_attribute('filter',$this->get_all_fiche_def ());
425 $f_add_button->javascript=" select_card_type(this);";
426 $str_add_button=$f_add_button->input();
427
428 \endcode
429 * \return html string
430 * \note must be one of first instruction on a new page, to avoid problem
431 * of position with IE
432 */
433
434 static function ipopup($p_name)
435 {
436 $ip_card=new IPopup($p_name);
437 $ip_card->drag=true;
438 $ip_card->set_width('45%');
439 $ip_card->title='Fiche ';
440 $ip_card->value='';
441
442 return $ip_card->input();
443 }
444
445 /**\brief set the extra javascript property for a double click on
446 * INPUT field
447 * \param $p_action action when a double click happens
448 * \note the $p_action cannot contain a double quote
449 */
450
452 {
453 $this->dblclick=$p_action;
454 }
455
456 /**\brief show the html input of the widget */
457
458 public function input($p_name=null, $p_value=null)
459 {
460 if ($p_name==null&&$this->name=="")
461 throw (new Exception(_('Le nom d une icard doit être donne')));
462 $this->value=($p_value==null)?$this->value:$p_value;
463 if ($this->readOnly==true)
464 return $this->display();
465
466 $this->id=($this->id=="")?$this->name:$this->id;
467 $this->choice=($this->choice==null)?sprintf("%s_choices", $this->id):$this->choice;
468 $this->indicator=($this->indicator==null)?sprintf("%s_ind", $this->id):$this->indicator;
469 $attr=$this->get_js_attr();
470
471 $label='';
472 if ($this->dblclick!='')
473 {
474 $e=sprintf(' ondblclick="%s" ', $this->dblclick);
475 $this->dblclick=$e;
476 }
477
478 $input='<div class="d-none d-lg-inline">'.
479 Icon_Action::clean_zone(uniqid("remove"),"$('{$this->id}').value=''").
480 "</div>";
481
482 $input.=sprintf('
483 <INPUT TYPE="Text" class="input_text icard"
484 NAME="%s" ID="%s" VALUE="%s" %s %s %s>',
485 $this->name, $this->id, $this->value,
486 $this->dblclick, $this->javascript, $this->style
487 );
488 if ($this->autocomplete==1)
489 {
490 // --- indicator
491 $this->indicator="ind_".$this->id;
492 $ind=sprintf('<span id="%s" class="autocomplete" style="position:absolute;display:none;margin-left:-20px"><img src="image/ajax-loader.gif" alt="Chargement..."/></span>',
493 $this->indicator);
494 // $this->indicator="null";
495
496 $div=($this->choice_create==1)?sprintf('<div id="%s" class="autocomplete"></div>',
497 $this->choice):"";
498
499 $query=http_build_query([ 'gDossier'=>Dossier::id(),'e'=>$this->typecard,'limit'=>$this->limit]);
500
501 $javascript=sprintf('try { new Ajax.Autocompleter("%s","%s","%s?%s",'.
502 '{paramName:"FID",minChars:1,indicator:%s, '.
503 'callback:%s, '.
504 'limit:%s,'.
505 ' afterUpdateElement:%s});} catch (e){alert(e.message);};',
506 $this->id, $this->choice, $this->autocomplete_file,$query, $this->indicator,
507 $this->callback, $this->limit, $this->fct);
508
509 $javascript=create_script($javascript.$this->dblclick);
510
511 $r=$label.$input.$attr.$ind.$div.$javascript;
512 }
513 else
514 {
515 $r=$label.$input;
516 }
517 if ($this->table==1)
518 $r=td($r);
519 return $r;
520 }
521
522 /**
523 \brief print in html the readonly value of the widget */
524
525 public function display()
526 {
527 $r=sprintf(' <INPUT TYPE="hidden" NAME="%s" id="%s" VALUE="%s" SIZE="8">',
528 $this->name, $this->name, $this->value
529 );
530 $r.='<span>'.$this->value.'</span>';
531 return $r;
532 }
533
534 /**
535 * @brief return a string containing the button for displaying
536 * a search form. When clicking on the result, update the input text file
537 * the common used attribute as
538 * - jrn the ledger
539 * - label the field to update
540 * - name name of the input text
541 * - price amount
542 * - tvaid
543 * - typecard (deb, cred, filter or list of value)
544 * will be set
545 * if ICard is in readOnly, the button disappears, so the return string is empty
546 \code
547 // search ipopup
548 $search_card=new IPopup('ipop_card');
549 $search_card->title=_('Recherche de fiche');
550 $search_card->value='';
551 echo $search_card->input();
552
553 $a=new ICard('test');
554 $a->search();
555
556 \endcode
557 * \see ajax_card.php
558 * \note the ipopup id is hard coded : ipop_card
559 * @return HTML string with the button
560 */
561 function search()
562 {
563 if ($this->readOnly==true)
564 return '';
565 if (!isset($this->id))
566 $this->id=$this->name;
567 $a="";
568 foreach (array('typecard', 'jrn', 'label', 'price', 'tvaid', 'accvis','amount_from_type') as
569 $att)
570 {
571 if (isset($this->$att))
572 $a.="this.".$att."='".$this->$att."';";
573 }
574 if (isset($this->id)&&$this->id!="")
575 $a.="this.inp='".$this->id."';";
576 else
577 $a.="this.inp='".$this->name."';";
578 $a.="this.popup='ipop_card';";
579 $javascript=$a.' search_card(this);return false;';
580
581
583 return $button;
584 }
585
586 static public function test_me()
587 {
588 $_SESSION[SESSION_KEY.'isValid']=1;
589 $a=new ICard('testme');
590 $a->extra="all";
591 $a->set_attribute('label', 'ctl_label');
592 $a->set_attribute('tvaid', 'ctl_tvaid');
593 $a->set_attribute('price', 'ctl_price');
594 $a->set_attribute('purchase', 'ctl_purchase');
595 $a->set_attribute('type', 'all');
596 echo <<<EOF
597 <div id="debug" style="border:solid 1px black;overflow:auto"></div>
598 <script type="text/javascript" language="javascript" src="js/prototype.js">
599 </script>
600 <script type="text/javascript" language="javascript" src="js/scriptaculous.js">
601 </script>
602 <script type="text/javascript" language="javascript" src="js/effects.js">
603 </script>
604 <script type="text/javascript" language="javascript" src="js/controls.js">
605 </script>
606 <script type="text/javascript" language="javascript" src="js/ajax_fid.js">
607 </script>
608 <script type="text/javascript" language="javascript" >
609 function test_value(text,li)
610 {
611 alert("premier"+li.id);
612
613 str="";
614 str=text.id+'<hr>';
615 if ( text.js_attr1)
616 {
617 str+=text.js_attr1;
618 str+='<hr>';
619 }
620 if ( text.js_attr2)
621 {
622 str+=text.js_attr2;
623 str+='<hr>';
624 }
625 if ( text.js_attr3)
626 {
627 str+=text.js_attr3;
628 str+='<hr>';
629 }
630 for (var i in text)
631 {
632 str+=i+'<br>';
633 }
634
635 // $('debug').innerHTML=str;
636 ajaxFid(text);
637 }
638 </script>
639
640EOF;
641 echo "<form>";
642 $l=new IText('ctl_label');
643 $t=new IText('ctl_tvaid');
644 $p=new IText('ctl_price');
645 $b=new IText('ctl_purchase');
646
647 echo "Label ".$l->input().'<br>';
648 echo "Tva id ".$t->input().'<br>';
649 echo "Price ".$p->input().'<br>';
650 echo "Purchase ".$b->input().'<br>';
651
652 if (isset($_REQUEST['test_select']))
653 echo HtmlInput::hidden('test_select', $_REQUEST['test_select']);
654 $a->set_function('test_value');
655 $a->javascript=' onchange="alert(\'onchange\');" onblur="alert(\'onblur\');" ';
656 echo $a->input();
657 echo dossier::hidden();
658 echo HtmlInput::submit('Entree', 'entree');
659 echo '</form>';
660 echo <<<EOF
661EOF;
662 }
663
664}
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
alert($p_msg, $buffer=false)
alert in javascript
Definition: ac_common.php:738
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$input
$ret javascript
$div
$opd_description style
$_REQUEST['ac']
$p
Definition: array.php:34
$from_poste name
$input_from type
Definition: balance.inc.php:65
for($i=0;$i<=6;$i++) $ind
Definition: calendar.php:34
if(! isset($_GET['submit_query'])) $p_action
static id()
return the 'gDossier' value after a check
class widget This class is used to create all the HTML INPUT TYPE and some specials which works with ...
static hidden($p_name, $p_value, $p_id="")
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
get_js_attr()
you can add attribute to this in javascript this function is a wrapper and create a script (in js) to...
Input HTML for the card show buttons, in the file, you have to add card.js How to use :
get_accvis()
display()
print in html the readonly value of the widget
$fct
< $fct ,by default it is update_value called BEFORE the querystring is send
$callback
$choice
set_fct($fct)
__construct($name="", $value="", $p_id="")
get_amount_from_type()
amount_from_type : accountancy , sell or purchase price
$choice
$indicator, text displaid when searching
$style
$accvis account_visible =1 otherwise 0, default 1
get_style()
CSS Style of the INPUT TEXT element.
set_choice_create($choice_create)
1 if you want to create automatically the autocomplete DIV to fill with the the output of "autocomple...
set_amount_from_type($amount_from_type)
amount_from_type : accountancy , sell or purchase price @parameter $amount_from_type ACH VEN or GL
hide_accounting()
in the search box, the accounting will be hidden
input($p_name=null, $p_value=null)
show the html input of the widget
set_dblclick($p_action)
set the extra javascript property for a double click on INPUT field
get_fct()
Function javascript by default it is update_value called BEFORE the querystring is send in ajax.
set_style($style)
CSS Style of the INPUT TEXT element.
get_autocomplete()
1 autocomplete enable ; 0 autocomplete disable
$amount_from_type
$typecard : type of card
get_autocomplete_file()
php file to call to complete info from the card
$autocomplete_file
set_autocomplete_file($autocomplete_file)
php file to call to complete info from the card
set_choice($choice)
id_of_div_to_populate with the output of the autocomplete_file, it is the autocomplete div presenting...
set_typecard($typecard)
argument "e" passed to autocomplete_file ,
static test_me()
$autocomplete
$style supplemental CSS
search()
return a string containing the button for displaying a search form.
set_callback($p_name)
set the javascript callback function by default it is update_value called BEFORE the querystring is s...
get_typecard()
get_choice_create()
1 if you want to create automatically the autocomplete DIV to fill with the the output of "autocomple...
set_indicator($indicator)
Id of the element to show that it is seaching.
show_accounting()
in the search box, the accounting will be shown it is the default
$dblclick
$callback ,
$typecard
$autocomplete_file , ajax file used for autocompletion (see Ajax.Autocompleter)
get_choice()
id_of_div_to_populate with the output of the autocomplete_file, it is the autocomplete div presenting...
set_autocomplete($autocomplete)
1 autocomplet enable ; 0 autocomplete disable
get_limit()
set_accvis($accvis)
$choice_create
$autocomplete : 1 enable - 0 disable
$limit
$amount_from_type : accountancy , sell or purchase price
set_function($p_name)
set the javascript callback function by default it is update_value called AFTER an item has been sele...
get_indicator()
Id of the element to show that it is seaching.
$accvis
$limit Max of row show
set_limit($limit)
static ipopup($p_name)
return the html string for creating the ipopup, this ipopup can be used for adding,...
$indicator
$choice_create 1 , display a (+) button , default 1
create a popup in html above the current layer the html inside the popup cannot contain any floating ...
Html Input.
Definition: itext.class.php:30
static clean_zone($id, $p_javascript, $p_style="")
static button_magnifier($id, $p_javascript, $p_style="")
Display a icon with a magnify glass.
$all table
$icard readOnly
$icard amount_from_type
create_script($p_string)
create the HTML for adding the script tags around of the script