noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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';
68O
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 protected $after_clean; //!< javascript to call after cleaning the INPUT TEXT
162 function __construct($name="", $value="", $p_id="")
163 {
164 parent::__construct($name, $value);
165 $this->fct='update_value';
166 $this->dblclick='';
167 $this->callback='null';
168 $this->javascript='';
169 $this->id=($p_id!="")?$p_id:$name;
170 $this->choice=null;
171 $this->indicator=null;
172 $this->choice_create=1;
173 $this->autocomplete=1;
174 $this->style=' ';
175 $this->accvis=1; //!< account_visible =1 otherwise 0
176 $this->limit=12; //!< Max of row show
177 $this->amount_from_type=''; //!< in the follow up ,when a card is selected you take Prix Vente or Prix Achat
178 $this->typecard='all';
179 $this->autocomplete_file="fid_card.php";
180 $this->after_clean="";
181 }
182 public function getAfter_clean()
183 {
184 return $this->after_clean;
185 }
186
188 {
189 $this->after_clean = $after_clean;
190 return $this;
191 }
192
193 /**
194 * Function javascript by default it is update_value called BEFORE the querystring is send in ajax
195 * @return type
196 */
197 public function get_fct()
198 {
199 return $this->fct;
200 }
201 /**
202 * @brief id_of_div_to_populate with the output of the autocomplete_file, it is
203 * the autocomplete div presenting a list of possible choices. Default {this->id}_choices
204 *
205 * @return html string (
206 */
207 public function get_choice()
208 {
209 if ( $this->choice==null) {
210 return sprintf("%s_choices", $this->id);
211 }
212 return $this->choice;
213 }
214 /**
215 * Id of the element to show that it is seaching
216 * @return type
217 */
218 public function get_indicator()
219 {
220 return $this->indicator;
221 }
222 /**
223 * @brief 1 if you want to create automatically the autocomplete DIV to fill with the the output of
224 * "autocomplete_file" or 0 if this DIV is created explicitly
225 *
226 * @return this
227 */
228 public function get_choice_create()
229 {
231 }
232 /**
233 * @brief 1 autocomplete enable ; 0 autocomplete disable
234 * @return type
235 */
236 public function get_autocomplete()
237 {
238 return $this->autocomplete;
239 }
240 /**
241 * CSS Style of the INPUT TEXT element
242 * @return type
243 */
244 public function get_style()
245 {
246 return $this->style;
247 }
248 /***
249 * @brief $accvis account_visible =1 otherwise 0, default 1
250 */
251 public function get_accvis()
252 {
253 return $this->accvis;
254 }
255
256 public function get_limit()
257 {
258 return $this->limit;
259 }
260 /**
261 * @brief amount_from_type : accountancy , sell or purchase price
262 *
263 */
264 public function get_amount_from_type()
265 {
267 }
268
269 public function get_typecard()
270 {
271 return $this->typecard;
272 }
273 /**
274 * @brief php file to call to complete info from the card
275 * @param string $autocomplete_file
276 * @see fid_card.php
277 * @return $this
278 */
279 public function get_autocomplete_file()
280 {
282 }
283 /***
284 * @brief Function javascript by default it is update_value called BEFORE the querystring is send in ajax
285 *@see afterUpdateElement
286 */
287 public function set_fct($fct)
288 {
289 $this->fct=$fct;
290 return $this;
291 }
292 /**
293 * @brief id_of_div_to_populate with the output of the autocomplete_file, it is
294 * the autocomplete div presenting a list of possible choices. Default {this->id}_choices
295 *
296 * @return html string (
297 */
298 public function set_choice($choice)
299 {
300 $this->choice=$choice;
301 return $this;
302 }
303 /**
304 * @brief Id of the element to show that it is seaching
305 */
306 public function set_indicator($indicator)
307 {
308 $this->indicator=$indicator;
309 return $this;
310 }
311 /**
312 * @brief 1 if you want to create automatically the autocomplete DIV to fill with the the output of
313 * "autocomplete_file" or 0 if this DIV is created explicitly
314 *
315 * @return this
316 */
318 {
319 $this->choice_create=$choice_create;
320 return $this;
321 }
322 /**
323 * @brief 1 autocomplet enable ; 0 autocomplete disable
324 * @return type
325 */
327 {
328 $this->autocomplete=$autocomplete;
329 return $this;
330 }
331 /**
332 * CSS Style of the INPUT TEXT element
333 * @return type
334 */
335 public function set_style($style)
336 {
337 $this->style=$style;
338 return $this;
339 }
340 /***
341 * @brief $accvis account_visible =1 otherwise 0, default 1
342 */
343 public function set_accvis($accvis)
344 {
345 $this->accvis=$accvis;
346 return $this;
347 }
348
349 public function set_limit($limit)
350 {
351 $this->limit=$limit;
352 return $this;
353 }
354 /**
355 * @brief amount_from_type : accountancy , sell or purchase price
356 * @parameter $amount_from_type ACH VEN or GL
357 *
358 */
360 {
361 if ( ! in_array($amount_from_type,array("ACH","VEN","GL"))) {
362 throw new Exception('icard.305 '.sprintf("[%s]",$amount_from_type));
363 }
365 return $this;
366 }
367 /**
368 * argument "e" passed to autocomplete_file ,
369 * @see fid_card.php
370 * @param type $typecard
371 * @return $this
372 */
373 public function set_typecard($typecard)
374 {
375 $this->typecard=$typecard;
376 return $this;
377 }
378 /**
379 * @brief php file to call to complete info from the card
380 * @param string $autocomplete_file
381 * @see fid_card.php
382 * @return $this
383 */
385 {
386 $this->autocomplete_file=$autocomplete_file;
387 return $this;
388 }
389
390 /**
391 * @brief in the search box, the accounting will be shown it is the default
392 */
393 function show_accounting() {
394 $this->accvis=1;
395 }
396
397 /**
398 * @brief in the search box, the accounting will be hidden
399 */
401 {
402 $this->accvis=0;
403 }
404
405
406 /**
407 * \brief set the javascript callback function
408 * by default it is update_value called BEFORE the querystring is send
409 *
410 * \param $p_name callback function name
411 */
412
413 function set_callback($p_name)
414 {
415 $this->callback=$p_name;
416 }
417
418 /**\brief set the javascript callback function
419 * by default it is update_value called AFTER an item has been selected
420 * \param $p_name callback function name
421 */
422
423 function set_function($p_name)
424 {
425 $this->fct=$p_name;
426 }
427
428 /**
429 * \brief return the html string for creating the ipopup, this ipopup
430 * can be used for adding, modifying or display a card
431 * @note ipopup is obsolete, the popin is created by javascript
432 * \param $p_name name of the ipopup, must be set after with set_attribute
433 \code
434 $f_add_button=new IButton('add_card');
435 $f_add_button->label='Créer une nouvelle fiche';
436 $f_add_button->set_attribute('ipopup','ipop_newcard');
437 $f_add_button->set_attribute('filter',$this->get_all_fiche_def ());
438 $f_add_button->javascript=" select_card_type(this);";
439 $str_add_button=$f_add_button->input();
440
441 \endcode
442 * \return html string
443 * \note must be one of first instruction on a new page, to avoid problem
444 * of position with IE
445 */
446
447 static function ipopup($p_name)
448 {
449 $ip_card=new IPopup($p_name);
450 $ip_card->drag=true;
451 $ip_card->set_width('45%');
452 $ip_card->title='Fiche ';
453 $ip_card->value='';
454
455 return $ip_card->input();
456 }
457
458 /**\brief set the extra javascript property for a double click on
459 * INPUT field
460 * \param $p_action action when a double click happens
461 * \note the $p_action cannot contain a double quote
462 */
463
465 {
466 $this->dblclick=$p_action;
467 }
468
469 /**\brief show the html input of the widget */
470
471 public function input($p_name=null, $p_value=null)
472 {
473 if ($p_name==null&&$this->name=="")
474 throw (new Exception(_('Le nom d une icard doit être donne')));
475 $this->value=($p_value==null)?$this->value:$p_value;
476 if ($this->readOnly==true)
477 return $this->display();
478
479 $this->id=($this->id=="")?$this->name:$this->id;
480 $this->choice=($this->choice==null)?sprintf("%s_choices", $this->id):$this->choice;
481 $this->indicator=($this->indicator==null)?sprintf("%s_ind", $this->id):$this->indicator;
482 $attr=$this->get_js_attr();
483
484 $label='';
485 if ($this->dblclick!='')
486 {
487 $e=sprintf(' ondblclick="%s" ', $this->dblclick);
488 $this->dblclick=$e;
489 }
490
491 $input='<div class="d-none d-lg-inline">'.
492 Icon_Action::clean_zone(uniqid("remove"),"clean_Fid('{$this->id}');{$this->after_clean}").
493 "</div>";
494
495 $input.=sprintf('
496 <INPUT TYPE="Text" class="input_text icard"
497 NAME="%s" ID="%s" VALUE="%s" %s %s %s>',
498 $this->name, $this->id, $this->value,
499 $this->dblclick, $this->javascript, $this->style
500 );
501 if ($this->autocomplete==1)
502 {
503 // --- indicator
504 $this->indicator="ind_".$this->id;
505 $ind=sprintf('<span id="%s" class="autocomplete" style="position:absolute;display:none;margin-left:-20px"><img src="image/ajax-loader.gif" alt="Chargement..."/></span>',
506 $this->indicator);
507 // $this->indicator="null";
508
509 $div=($this->choice_create==1)?sprintf('<div id="%s" class="autocomplete"></div>',
510 $this->choice):"";
511
512 $query=http_build_query([ 'gDossier'=>Dossier::id(),'e'=>$this->typecard,'limit'=>$this->limit]);
513
514 $javascript=sprintf('try { new Ajax.Autocompleter("%s","%s","%s?%s",'.
515 '{paramName:"FID",minChars:1,indicator:%s, '.
516 'callback:%s, '.
517 'limit:%s,'.
518 ' afterUpdateElement:%s});} catch (e){alert(e.message);};',
519 $this->id, $this->choice, $this->autocomplete_file,$query, $this->indicator,
520 $this->callback, $this->limit, $this->fct);
521
522 $javascript=create_script($javascript.$this->dblclick);
523
524 $r=$label.$input.$attr.$ind.$div.$javascript;
525 }
526 else
527 {
528 $r=$label.$input;
529 }
530 if ($this->table==1)
531 $r=td($r);
532 return $r;
533 }
534
535 /**
536 \brief print in html the readonly value of the widget */
537
538 public function display()
539 {
540 $r=sprintf(' <INPUT TYPE="hidden" NAME="%s" id="%s" VALUE="%s" SIZE="8">',
541 $this->name, $this->name, $this->value
542 );
543 $r.='<span>'.$this->value.'</span>';
544 return $r;
545 }
546
547 /**
548 * @brief return a string containing the button for displaying
549 * a search form. When clicking on the result, update the input text file
550 * the common used attribute as
551 * - jrn the ledger
552 * - label the field to update
553 * - name name of the input text
554 * - price amount
555 * - tvaid
556 * - typecard (deb, cred, filter or list of value)
557 * will be set
558 * if ICard is in readOnly, the button disappears, so the return string is empty
559 \code
560 // search ipopup
561 $search_card=new IPopup('ipop_card');
562 $search_card->title=_('Recherche de fiche');
563 $search_card->value='';
564 echo $search_card->input();
565
566 $a=new ICard('test');
567 $a->search();
568
569 \endcode
570 * \see ajax_card.php
571 * \note the ipopup id is hard coded : ipop_card
572 * @return HTML string with the button
573 */
574 function search()
575 {
576 if ($this->readOnly==true)
577 return '';
578 if (!isset($this->id))
579 $this->id=$this->name;
580 $a="";
581 foreach (array('typecard', 'jrn', 'label', 'price', 'tvaid', 'accvis','amount_from_type') as
582 $att)
583 {
584 if (isset($this->$att))
585 $a.="this.".$att."='".$this->$att."';";
586 }
587 if (isset($this->id)&&$this->id!="")
588 $a.="this.inp='".$this->id."';";
589 else
590 $a.="this.inp='".$this->name."';";
591 $a.="this.popup='ipop_card';";
592 $javascript=$a.' search_card(this);return false;';
593
594
596 return $button;
597 }
598
599 static public function test_me()
600 {
601 $_SESSION[SESSION_KEY.'isValid']=1;
602 $a=new ICard('testme');
603 $a->extra="all";
604 $a->set_attribute('label', 'ctl_label');
605 $a->set_attribute('tvaid', 'ctl_tvaid');
606 $a->set_attribute('price', 'ctl_price');
607 $a->set_attribute('purchase', 'ctl_purchase');
608 $a->set_attribute('type', 'all');
609 echo <<<EOF
610 <div id="debug" style="border:solid 1px black;overflow:auto"></div>
611 <script type="text/javascript" language="javascript" src="js/prototype.js">
612 </script>
613 <script type="text/javascript" language="javascript" src="js/scriptaculous.js">
614 </script>
615 <script type="text/javascript" language="javascript" src="js/effects.js">
616 </script>
617 <script type="text/javascript" language="javascript" src="js/controls.js">
618 </script>
619 <script type="text/javascript" language="javascript" src="js/ajax_fid.js">
620 </script>
621 <script type="text/javascript" language="javascript" >
622 function test_value(text,li)
623 {
624 alert("premier"+li.id);
625
626 str="";
627 str=text.id+'<hr>';
628 if ( text.js_attr1)
629 {
630 str+=text.js_attr1;
631 str+='<hr>';
632 }
633 if ( text.js_attr2)
634 {
635 str+=text.js_attr2;
636 str+='<hr>';
637 }
638 if ( text.js_attr3)
639 {
640 str+=text.js_attr3;
641 str+='<hr>';
642 }
643 for (var i in text)
644 {
645 str+=i+'<br>';
646 }
647
648 // $('debug').innerHTML=str;
649 ajaxFid(text);
650 }
651 </script>
652
653EOF;
654 echo "<form>";
655 $l=new IText('ctl_label');
656 $t=new IText('ctl_tvaid');
657 $p=new IText('ctl_price');
658 $b=new IText('ctl_purchase');
659
660 echo "Label ".$l->input().'<br>';
661 echo "Tva id ".$t->input().'<br>';
662 echo "Price ".$p->input().'<br>';
663 echo "Purchase ".$b->input().'<br>';
664
665 if (isset($_REQUEST['test_select']))
666 echo HtmlInput::hidden('test_select', $_REQUEST['test_select']);
667 $a->set_function('test_value');
668 $a->javascript=' onchange="alert(\'onchange\');" onblur="alert(\'onblur\');" ';
669 echo $a->input();
670 echo dossier::hidden();
671 echo HtmlInput::submit('Entree', 'entree');
672 echo '</form>';
673 echo <<<EOF
674EOF;
675 }
676
677}
td($p_string='', $p_extra='')
surround the string with td
Definition ac_common.php:83
alert($p_msg, $buffer=false)
alert in javascript
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$ret javascript
$opd_description style
$_REQUEST['ac']
$from_poste name
_("actif, passif,charge,...")
$input_from type
for($i=0;$i<=6;$i++) $ind
Definition calendar.php:55
$p
Definition calendar.php:9
if(! isset($_GET['submit_query'])) $p_action
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 :
$after_clean
javascript to call after cleaning the INPUT TEXT
get_accvis()
$accvis account_visible =1 otherwise 0, default 1
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)
Function javascript by default it is update_value called BEFORE the querystring is send in ajax.
__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
setAfter_clean($after_clean)
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 ,
getAfter_clean()
$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
set_accvis($accvis)
$accvis account_visible =1 otherwise 0, default 1
$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 Text member :
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
$t
Definition compute.php:46
$icard readOnly
$icard amount_from_type
create_script($p_string)
create the HTML for adding the script tags around of the script