noalyss Version-9
html_input.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 This class is used to create all the HTML INPUT TYPE
25 */
26
27/*!
28 * \brief class widget This class is used to create all the HTML INPUT TYPE
29 * and some specials which works with javascript like
30 * js_search.
31 *
32 * special value
33 * js_search and js_search_only :you need to add a span widget the name
34 * of the js_* widget + '_label' , the member extra contains cred,deb to
35 * filter the search of cred of deb of a jrn or contains a string with
36 * a list of frd_id.
37 * Possible type
38 * $type
39 * - TEXT
40 * - HIDDEN
41 * - BUTTON in this->js you have the javascript code
42 * - SELECT the options are passed via this->value, this array is
43 * build thanks the make_array function, each array (of the
44 * array) aka row must contains a field value and a field label
45 * - PASSWORD
46 * - CHECKBOX
47 * - RADIO
48 * - TEXTAREA
49 * - RICHTEXT
50 * - FILE
51 * - SPAN
52 */
53#[AllowDynamicProperties]
55{
56
57 var $type; /*!< $type type of the widget */
58 var $name; /*!< $name field NAME of the INPUT */
59 var $value; /*!< $value what the INPUT contains */
60 var $readOnly; /*!< $readonly true : we cannot change value */
61 var $size; /*!< $size size of the input */
62 var $selected; /*!< $selected for SELECT RADIO and CHECKBOX the selected value */
63 var $table; /*!< $table =1 add the table tag */
64 var $label; /*!< $label the question before the input */
65 var $disabled; /*!< $disabled poss. value == true or nothing, to disable INPUT */
66 var $extra; /*!< $extra different usage, it depends of the $type */
67 var $extra2; /*!< $extra2 different usage,
68 it depends of the $type */
69 var $javascript; /*!< $javascript is the javascript to add to the widget */
70 var $ctrl; /*!<$ctrl is the control to update (see js_search_card_control) */
73 var $width;
74 var $heigh;
76 var $id;
77 var $style;
79
80 function __construct($p_name="", $p_value="", $p_id="")
81 {
82 $this->name=$p_name;
83 $this->readOnly=false;
84 $this->size=20;
85 $this->width=50;
86 $this->heigh=20;
87 $this->value=$p_value;
88 $this->selected="";
89 $this->table=0;
90 $this->disabled=false;
91 $this->javascript="";
92 $this->extra="";
93 $this->extra2="all";
94 $this->attribute=array();
95 $this->id=$p_id;
96 $this->require=false;
97 }
98
99 function setReadOnly($p_read)
100 {
101 $this->readOnly=$p_read;
102 }
103
104 /*!
105 * \brief set the extra javascript property for the INPUT field
106 * \param $p_name name of the parameter
107 * \param $p_value default value of this parameter
108 */
109
110 public function set_attribute($p_name, $p_value)
111 {
112 $this->attribute[]=array($p_name, $p_value);
113 $this->$p_name=$p_value;
114 }
115
116 /**
117 * @brief Set the value of input (IText, INum,...)
118 * @param string $p_string
119 */
120 function set_value($p_string)
121 {
122 $this->value=$p_string;
123 }
124
125 /**
126 * @brief Return the value of input (IText, INum,...)
127 */
128 function get_value()
129 {
130 return $this->value;
131 }
132
133 /**
134 * @brief you can add attribute to this in javascript
135 * this function is a wrapper and create a script (in js) to modify
136 * "this" (in javascript) with the value of obj->attribute from PHP.
137 * @see build_javascript_attribute() include the string in the DOM Element instead of in a piece of code
138 * @return string : return string with the javascript code
139 */
140 public function get_js_attr()
141 {
142 require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
143 $attr="";
144 if (count($this->attribute)==0)
145 return "";
146
147 /* Add properties at the widget */
148 for ($i=0; $i<count($this->attribute); $i++)
149 {
150 list($name, $value)=$this->attribute[$i];
151 $tmp1=sprintf("$('%s').%s='%s';", $this->id, $name, $value);
152 $attr.=$tmp1;
153 }
155 return $attr;
156 }
157
158 /**
159 *@brief Make a JSON object, this method create a javascript object
160 * with the attribute set, it returns a javascript string with the object
161 * @param $p_name : name of the object, can be null. If the name is not null, return
162 * $p_name={} otherwise only the object {}
163 * @return javascript string with the object
164 * @note: there is not check on the key->value, so you could need to escape
165 * special char as quote, single-quote...
166 * @deprecated
167 * @code
168 $a=new IButton()
169 $a->set_attribute('prop','1');
170 $a->set_attribute('prop','2');
171 $a->set_attribute('prop','3');
172 $string = $a->make_object('property');
173 echo $string => property={'prop':'1','prop2':'2','prop3':'3'};
174 $string = $a->make_object(null);
175 echo $string => {'prop':'1','prop2':'2','prop3':'3'};
176 @endcode
177 */
178 public function make_object_deprecated($p_name=null)
179 {
180 $name=($p_name!=null)?$p_name.'=':'';
181 if (count($this->attribute)==0)
182 return $name."{}";
183 $ret=$name."{";
184 $and='';
185
186 for ($i=0; $i<count($this->attribute); $i++)
187 {
188 list($name, $value)=$this->attribute[$i];
189 $tmp1=sprintf($and."'%s':'%s'", $name, $value);
190 $ret.=$tmp1;
191 $and=',';
192 }
193
194 $ret.='}';
195 return $ret;
196 }
197
198 //#####################################################################
199 /* Debug
200 */
201 function __toString()
202 {
203 $r= "Type ".$this->type."<br>";
204 $r.= "name ".$this->name."<br>";
205 $r.= "value".$this->value."<br>";
206 $readonly=(isset($this->readOnly) && $this->readOnly==false)?"false":"true";
207 $r.= "read only".$readonly."<br>";
208 return $r;
209 }
210
211 static function submit($p_name, $p_value, $p_javascript="",
212 $p_class="smallbutton")
213 {
214
215 return '<INPUT TYPE="SUBMIT" class="'.$p_class.'" NAME="'.$p_name.'" ID="'.$p_name.'_submit_id" VALUE="'.$p_value.'" '.$p_javascript.'>';
216 }
217
218 static function button($p_name, $p_value, $p_javascript="",
219 $p_class="smallbutton")
220 {
221
222 return '<INPUT TYPE="button" class="'.$p_class.'" NAME="'.$p_name.'" ID="'.$p_name.'" VALUE="'.$p_value.'" '.$p_javascript.'>';
223 }
224
225 static function reset($p_value)
226 {
227 return '<INPUT TYPE="RESET" class="smallbutton" VALUE="'.$p_value.'">';
228 }
229
230 static function hidden($p_name, $p_value, $p_id="")
231 {
232 if ($p_id=="")
233 $p_id=$p_name;
234 if ( DEBUGNOALYSS > 2) {
235 return '<span style="font-size:80%;color:blue;background-color:lightgoldenrodyellow">'.
236 $p_id .
237 '= <INPUT TYPE="text" id="'.strip_tags($p_id).'" NAME="'.$p_name.'" VALUE="'.strip_tags($p_value??"").'" style="color:blue;font-size:80%">'.
238 '</span>';
239 }else
240 return '<INPUT TYPE="hidden" id="'.strip_tags($p_id).'" NAME="'.$p_name.'" VALUE="'.strip_tags($p_value??"").'">';
241 }
242
243 static function extension()
244 {
245 return self::hidden('plugin_code', $_REQUEST['plugin_code']);
246 }
247
248 /*!\brief create a button with a ref
249 * \param $p_label the text
250 * \param $p_value the location of the window,
251 * \param $p_name the id of the span
252 * \param $p_javascript javascript for this button
253 * \return string with htmlcode
254 */
255
256 static function button_anchor($p_label, $p_value, $p_name="",
257 $p_javascript="", $p_class="smallbutton")
258 {
259 $href="";
260 if ($p_value!="")
261 $href=sprintf(' href ="%s" ', $p_value);
262 $r=sprintf('<span id="%s" > <A class="'.$p_class.'" style="display:inline-block;" %s %s >%s</A></span>',
263 $p_name, $href, $p_javascript, $p_label);
264 return $r;
265 }
266 /**
267 * @deprecated since version 7.0
268 * @see Icon_Action::warnbulle
269 * @param type $p_comment
270 * @return string
271 */
272 static function warnbulle($p_comment)
273 {
274 throw new Exception("DEPRECATED");
275 }
276
277 static function errorbulle($p_comment)
278 {
279 global $g_failed;
280 if ( $p_comment == "") return "";
281 $r=sprintf('<A HREF="#" tabindex="-1" style="display:inline;color:red;background-color:transparent;padding-left:4px;padding-right:4px;text-decoration:none;" onmouseover="displayBulle(\'%s\')" onclick="displayBulle(\'%s\')" onmouseout="hideBulle(0)"> %s </A>',
282 $p_comment, $p_comment, $g_failed);
283 return $r;
284 }
285
286 /**
287 * @brief return a string containing the html code for calling the modifyOperation
288 */
289 static function detail_op($p_jr_id, $p_mesg)
290 {
291 return sprintf('<A class="detail" style="text-decoration:underline;display:inline" HREF="javascript:modifyOperation(%d,%d)">%s</A>',
292 $p_jr_id, dossier::id(), $p_mesg);
293 }
294
295 /**
296 * @brief return an anchor to view the detail of an action
297 * @param $ag_id
298 * @param $p_mesg
299 * @param $p_modify let you modify an operation
300 *
301 */
302 static function detail_action($ag_id, $p_mesg, $p_modify=1)
303 {
304 return sprintf('<A class="detail" style="text-decoration:underline;display:inline" HREF="javascript:view_action(%d,%d,%d)">%s</A>',
305 $ag_id, dossier::id(), $p_modify, $p_mesg);
306 }
307
308 /**
309 * @brief return a string containing the html code for calling the modifyModeleDocument
310 */
312 {
313 return sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:modifyModeleDocument(%d,%d)">%s</A>',
315 }
316
317 /**
318 *@brief return a string containing the html code for calling the removeStock
319 */
320 static function remove_stock($p_id, $p_mesg)
321 {
322 return sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:removeStock(%d,%d)">%s</A>',
324 }
325
326 /**
327 *@brief display a div with the history of the card
328 */
329 static function history_card($f_id, $p_mesg, $p_style="",$p_exercice="")
330 {
331 global $g_user;
332 if ( $p_exercice=="") {
333 $p_exercice=$g_user->get_exercice();
334 }
335 $view_history=sprintf('<A class="detail" style="text-decoration:underline;%s" HREF="javascript:view_history_card(\'%s\',\'%s\',\'%s\')" >%s</A>',
336 $p_style, $f_id, dossier::id(),$p_exercice, $p_mesg);
337 return $view_history;
338 }
339
340 /**
341 *@brief display a div with the history of the card
342 * @param int $f_id fiche.f_id
343 * @param string $p_mesg string to display
344 * @param int $p_exercice exercice of the history
345 */
347 {
348 static $e=0;
349 $e++;
350 global $g_user;
351 if ( $p_exercice=="") {
352 $p_exercice=$g_user->get_exercice();
353 }
354 $js=sprintf('onclick="view_history_card(\'%s\',\'%s\',\'%s\')"', $f_id,
356 $view_history=HtmlInput::button("hcb".$e, $p_mesg, $js);
357 return $view_history;
358 }
359 /**
360 *@brief display a div with the history of the card
361 * @param int $f_id fiche.f_id
362 * @param string $p_mesg string to display
363 * @param int $p_exercice exercice of the history
364 */
366 {
367 global $g_user;
368 $js=sprintf('onclick="view_followup_card(\'%s\',\'%s\')"', $f_id,
369 dossier::id());
370 $view_followup=HtmlInput::button(uniqid("fu"), $p_mesg, $js);
371 return $view_followup;
372 }
373
374
375
376 /**
377 * @brief display a div with the history of the account
378 * @param string $p_account accounting
379 * @param string $p_mesg string to display
380 * @param string $p_style extra code for HTML
381 * @param int $p_exercice exercice of the history
382 */
383 static function history_account($p_account, $p_mesg, $p_style="",$p_exercice="")
384 {
385 global $g_user;
386 if ( $p_exercice=="") {
387 $p_exercice=$g_user->get_exercice();
388 }
389 $view_history=sprintf('<A class="detail" style="text-decoration:underline;%s" HREF="javascript:view_history_account(\'%s\',\'%s\',\'%s\')" >%s</A>',
390 $p_style, $p_account, dossier::id(),$p_exercice, $p_mesg);
391 return $view_history;
392 }
393 /**
394 * @brief display a div with the history of the analytic account
395 * @param int $p_account po_id
396 * @param string $p_mesg string to display
397 * @param string $p_style extra code for HTML
398 * @param int $p_exercice exercice of the history
399 */
400 static function history_anc_account($p_account, $p_mesg, $p_style="",$p_exercice="")
401 {
402 global $g_user;
403 if ( $p_exercice=="") {
404 $p_exercice=$g_user->get_exercice();
405 }
406 $view_history=sprintf('<A class="detail" style="text-decoration:underline;%s" HREF="javascript:view_history_anc_account(\'%s\',\'%s\',\'%s\')" >%s</A>',
407 $p_style, $p_account, dossier::id(),$p_exercice, $p_mesg);
408 return $view_history;
409 }
410
411 /**
412 * @brief create a hidden plus button to select the cat of ledger
413 * @note the selected value is stored in the array p_cat
414 */
415 static function select_cat($array_cat)
416 {
417 ob_start();
418 $ledger=new ISmallButton('l');
419 $ledger->label=_("Catégorie");
420 $ledger->javascript=" show_cat_choice()";
421 echo $ledger->input();
422
423 /* create a hidden div for the ledger */
424 echo '<div id="div_cat">';
425 echo '<h2 class="info">'._('Choix des categories').'</h2>';
426 $selected=(isset($_GET['r_cat']))?$_GET['r_cat']:null;
427
428 echo '<ul>';
429 for ($e=0; $e<count($array_cat); $e++)
430 {
432 $re=new ICheckBox('r_cat['.$e.']', $row['cat']);
433
434 if ($selected!=null&&isset($selected[$e]))
435 {
436 $re->selected=true;
437 }
438 echo '<li style="list-style-type: none;">'.$re->input().$row['name'].'('.$row['cat'].')</li>';
439 }
440 echo '</ul>';
441 $hide=new IButton('l2');
442 $hide->label=_("Valider");
443 $hide->javascript=" hide_cat_choice() ";
444 echo $hide->input();
445
446 echo '</div>';
447 $r=ob_get_contents();
448 ob_end_clean();
449 return $r;
450 }
451
452 static function display_periode($p_id)
453 {
454 $r=sprintf('<a href="javascript:void(0)" onclick="display_periode(%d,%d)">Modifier</a>',
455 dossier::id(), $p_id);
456 return $r;
457 }
458
459 /**
460 * @brief close button for the HTML popup
461 * @see add_div modify_operation
462 * @param $div_name is the name of the div to remove
463 */
464 static function button_close($div_name,$class='smallbutton')
465 {
466 $a=new IButton('Fermer');
467 $a->label=_("Fermer");
468 $a->class=$class;
469 $a->javascript="removeDiv('".$div_name."')";
470 $html=$a->input();
471
472 return $html;
473 }
474
475 /**
476 * @brief Hide the HTML popup
477 * @param type $div_name
478 * @return type
479 */
480 static function button_hide($div_name)
481 {
482 $a=new IButton('Fermer');
483 $a->label=_("Fermer");
484 $a->javascript="$('".$div_name."').hide()";
485 $html=$a->input();
486
487 return $html;
488 }
489
490 /**
491 * @brief Return a html string with an anchor which close the inside popup. (top-right corner)
492 * @param name of the DIV to close
493 * @deprecated
494 * @see Icon_Action::close
495 */
496 static function anchor_close($div, $p_js="")
497 {
498 throw new Exception("DEPRECATED");
499 }
500
501 /**
502 * @brief Anchor Html with javascript
503 * @param $action action action to perform (message) without onclick
504 * @param $javascript javascript to execute
505 * @param $id is the DOM element id
506 * @param $p_class CSS class of the button
507 * @param $p_symbole raw symbole to add to the action message
508 */
509 static function anchor_action($action, $javascript, $id=NULL,
510 $p_class="button", $p_symbole="")
511 {
512 if ($id==NULL)
513 {
514 $id=uniqid("xx");
515 }
516 $r="";
517 $r.='<a id="'.$id.'" href="javascript:void(0)" class="'.$p_class.'" onclick="'.$javascript.'">'.$p_symbole.h($action).'</a>';
518 return $r;
519 }
520
521 /**
522 * @brief button Html with javascript
523 * @param $action action action to perform (message) without onclick
524 * @param $javascript javascript to execute
525 * @param $id is the DOM element id
526 * @param $p_class CSS class of the button
527 * @param $p_symbole raw symbole to add to the action message
528 */
529 static function button_action($action, $javascript, $id=NULL,
530 $p_class="button", $p_symbole="")
531 {
532 if ($id==NULL)
533 {
534 $id=uniqid("xx");
535 }
536 $r="";
537 $r.='<input type="button" id="'.$id.'" class="'.$p_class.'" onclick="'.$javascript.'" value="'.$p_symbole.h($action).'">';
538 return $r;
539 }
540
541 /**
542 * @brief Image to click ,
543 * @param string $p_image filename of the image under image/
544 * @param string $p_js javascript when the image is clicked
545 * @param string $p_message Message
546 */
547 static function image_click($p_image, $p_js, $p_message, $p_class="")
548 {
549 $ret=sprintf('<a class="nav %s" style="display:inline" title="%s"><img src="image/%s" onclick="%s"></a>',
550 $p_class, $p_message, $p_image, $p_js);
551 return $ret;
552 }
553
554 /**
555 * @brief button Html image
556 * @param $javascript javascript to execute
557 * @param $id id of the button
558 * @param $class class of the button
559 * @param $p_image image
560 */
561 static function button_image($javascript, $id="xx",
562 $p_class='class="button"', $p_image="")
563 {
564 if ($id=="xx")
565 {
566 $id=uniqid("xx");
567 }
568 $r="";
569 $r.='<image id="'.$id.'" '.$p_class.' onclick="'.$javascript.'" src="'.$p_image.'" />';
570 return $r;
571 }
572
573 /**
574 * @brief Return a html string with an anchor to hide a div, put it in the right corner
575 * @param $action action action to perform (message)
576 * @param $javascript javascript
577 * @note not protected against html
578 * @see Icon_Action::hide
579 * @deprecated
580 *
581 */
583 {
584 throw new Exception("DEPRECATED");
585 }
586
587 /**
588 * Javascript to print the current window
589 */
590 static function print_window()
591 {
592 $r='';
593 $r.=HtmlInput::button('print', _('Imprimer'), 'onclick="window.print();"');
594 return $r;
595 }
596
597 /**
598 * @brief show the detail of a card
599 */
600 static function card_detail($p_qcode, $pname='', $p_style="",
601 $p_nohistory=false,$nofollowup=false)
602 {
603 if ($pname !=='') {$pname='<span class="v-large">('.$pname.')</span>';}
604 $r="";
605 $histo=($p_nohistory==true)?' ,nohistory:1':"";
606 $followup=($nofollowup==true)?' ,nofollowup:1':"";
607 $r.=sprintf('<a href="javascript:void(0)" %s class="detail" onclick="fill_ipopcard({qcode:\'%s\' %s %s})">%s %s</a>',
608 $p_style, $p_qcode, $histo,$followup,$p_qcode,$pname);
609 return $r;
610 }
611
612 /**
613 * @brief transform request data to hidden
614 * @param $array is an of indices
615 * @param $request name of the superglobal $_POST $_GET $_REQUEST(default)
616 * @return html string with the hidden data
617 */
618 static function array_to_hidden($array, $global_array)
619 {
620
621 $r="";
622
623 if (count($global_array)==0)
624 return '';
625 foreach ($array as $a)
626 {
627 if (isset($global_array [$a]))
628 if (is_array($global_array[$a])==false)
629 {
630 $r.=HtmlInput::hidden($a, $global_array [$a]);
631 }
632 else
633 {
634 if (count($global_array[$a])>0)
635 {
636 foreach ($global_array[$a] as $value)
637 {
639 }
640 }
641 }
642 }
643
644 return $r;
645 }
646 /**
647 * @brief Transform a double array as a HTML string with hidden html value
648 * array has the formarray ["name"]="x",array['value']="y") the key name will be the hidden input name;
649 * @param double $array
650 */
652 {
653 if (empty ($array)) return "";
654 $r="";
655 foreach ( $array as $key=>$value) {
657 }
658 return $r;
659 }
660 /**
661 * @brief transform a json to hidden
662 * @param json $p_json
663 */
664 static function json_to_hidden($p_json)
665 {
666 $aJson=json_decode($p_json);
667 foreach ($aJson as $key=> $value)
668 {
669 echo HtmlInput::hidden($key, $value);
670 }
671 }
672
673 /**
674 * @brief transform $_GET data to hidden
675 * @param $array is an of indices
676 * @see HtmlInput::request_to_hidden
677 * @return html string with the hidden data
678 */
679 static function get_to_hidden($array)
680 {
682 return $r;
683 }
684
685 /**
686 * transform $_POST data to hidden
687 * @param $array is an of indices
688 * @see HtmlInput::request_to_hidden
689 * @return html string with the hidden data
690 */
691 static function post_to_hidden($array)
692 {
694 return $r;
695 }
696
697 /**
698 * transform $_REQUEST data to hidden
699 * @param $array is an of indices
700 * @see HtmlInput::request_to_hidden
701 * @return html string with the hidden data
702 */
703 static function request_to_hidden(array $array)
704 {
706 return $r;
707 }
708
709 /**
710 * transform request data to string
711 * @param $array is an of indices
712 * @param $request name of the superglobal $_POST $_GET $_REQUEST(default)
713 * @return html string with the string data
714 */
715 static function array_to_string($array, $global_array, $start="?")
716 {
717
718 $r="";
719
720 if (count($global_array)==0)
721 return '';
722 $and="";
723 foreach ($array as $a)
724 {
725 if (isset($global_array [$a]))
726 {
727 if (is_array($global_array[$a])==false)
728 {
729 $r.=$and."$a=".$global_array [$a];
730 }
731 else
732 {
733 for ($i=0; $i<count($global_array[$a]); $i++)
734 {
735 $r.=$and."$a"."[]=".$global_array[$a][$i];
736 $and="&amp;";
737 }
738 }
739 }
740 $and="&amp;";
741 }
742 if (trim ($r) != "") $r=$start.$r;
743 return $r;
744 }
745
746 /**
747 * transform $_GET data to string
748 * @param $array is an of indices
749 * @see HtmlInput::request_to_string
750 * @return html string with the string data
751 */
752 static function get_to_string($array, $start="?")
753 {
755 return $r;
756 }
757
758 /**
759 * transform $_POST data to string
760 * @param $array is an of indices
761 * @see HtmlInput::request_to_string
762 * @return html string with the string data
763 */
764 static function post_to_string($array)
765 {
767 return $r;
768 }
769
770 /**
771 * transform $_REQUEST data to string
772 * @param $array is an of indices
773 * @see HtmlInput::request_to_string
774 * @return html string with the string data
775 */
776 static function request_to_string($array, $start="?")
777 {
779 return $r;
780 }
781
782 /**
783 * generate an unique id for a widget,
784 * @param $p_prefix prefix
785 * @see HtmlInput::IDate
786 * @return string with a unique id
787 */
788 static function generate_id($p_prefix)
789 {
790 $r=sprintf('%s_%d', $p_prefix, mt_rand(0, 999999));
791 return $r;
792 }
793
794 /**
795 * return default if the value if the value doesn't exist in the array
796 * @param $ind string the index to check
797 * @param $default string the value to return
798 * @param $array array the array
799 */
800 static function default_value($ind, $default, $array)
801 {
802 if (!isset($array[$ind]))
803 {
804 return $default;
805 }
806 return $array[$ind];
807 }
808
809 /**
810 * return default if the value if the value doesn't exist in $_GET
811 * use HttpInput instead
812 * @see HttpInput
813 * @deprecated
814 * @param $ind name of the variable
815 * @param type $default
816 * @return type
817 */
818 static function default_value_get($ind, $default)
819 {
820 if (!isset($_GET[$ind]))
821 {
822 return $default;
823 }
824 return $_GET[$ind];
825 }
826
827 /**
828 * return default if the value if the value doesn't exist in $_POST
829 * use HttpInput instead
830 * @see HttpInput
831 * @deprecated
832 * @param $ind name of the variable
833 * @param type $default
834 * @return type
835 */
836 static function default_value_post($ind, $default)
837 {
838 if (!isset($_POST[$ind]))
839 {
840 return $default;
841 }
842 return $_POST[$ind];
843 }
844
845 /**
846 * return default if the value if the value doesn't exist in $_REQUEST
847 * use HttpInput instead
848 * @see HttpInput
849 * @deprecated
850 * @param $ind name of the variable
851 * @param type $default
852 * @return type
853 */
854 static function default_value_request($ind, $default)
855 {
856 if (!isset($_REQUEST[$ind]))
857 {
858 return $default;
859 }
860 return $_REQUEST[$ind];
861 }
862
863 /**
864 * Title for boxes, you can customize the symbol thanks symbol with
865 * the mode "custom"
866 * @param string $p_name Title
867 * @param string $div element id, except for mode none or custom
868 * @param string $p_mod hide , close , zoom , custom or none, with
869 * custom , the $name contains all the code
870 * @param string $p_js contains the javascript if mod = "custom" or "zoom" contains button + code
871 * @param char $p_draggable , y = yes n = no ,if set to yes the box will be draggable
872 * @return type
873 */
874 static function title_box($p_name, $p_div, $p_mod="close", $p_js="",
875 $p_draggable="n",$p_enlarge='n')
876 {
877 $p_div=strip_tags($p_div);
878 $r='<div class="bxbutton">';
879
880 // If draggable : display a icon to unpin and move the dialog box
881 if ($p_draggable=="y")
882 {
883 $r.=Icon_Action::draggable($p_div);
884 }
885 if ( $p_enlarge=='y') {
886 $r.=Icon_Action::full_size($p_div);
887 }
888 if ($p_mod=='close')
889 {
890 $r.=Icon_Action::close($p_div, $p_js);
891 }
892 elseif ($p_mod=='zoom')
893 {
894 $r.=Icon_Action::zoom($p_div,$p_js);
895 }
896 elseif ($p_mod=='hide')
897 {
898 $r.=Icon_Action::hide("&#xe816;", "$('$p_div').hide();$p_js");
899 }
900 elseif ($p_mod=='custom')
901 {
902 $r.='<span id="span_'.$p_div.'" style="float:right;margin-right:5px">'.$p_js."</span>";
903 }
904 elseif ($p_mod=='none')
905 {
906 $r.="";
907 }
908 else
909 {
910 throw new Exception(__FILE__.":".__LINE__._("Paramètre invalide p_mod = '$p_mod'"));
911 }
912
913
914 $r.='</div>';
915 $r.=h2($p_name, ' class="title" ');
916
917 return $r;
918 }
919
920 /**
921 * @brief let you create only a link and set an id on it.
922 * After create a javascript for getting the event
923 * onclick = function() {...}
924 * @param type $p_text Text to display
925 * @param type $p_id id of the link
926 * @param type $type title of the link
927 * @code
928 * echo HtmlInput::anchor_empty('go','go_id');
929 * <script>$("go_id").onclick=function (e) { ...}</script>
930 * @endcode
931 */
932 static function anchor_empty($p_text, $p_id, $p_title="")
933 {
934 $p_url="javascript:void(0)";
935 $str=sprintf('<a id="%s" href="javascript:void(0)" class="line" title="%s">%s</a>',
936 $p_id, $p_title, $p_text);
937 return $str;
938 }
939
940 /**
941 * Return a simple anchor with a url or a javascript
942 * if $p_js is not null then p_url will be javascript:void(0)
943 * we don't add the event onclick. You must give p_url OR p_js
944 * default CSS class=line
945 * @param string $p_text text of the anchor
946 * @param string $p_url url
947 * @param string $p_js javascript
948 * @param string $p_style is the visuable effect (class, style...)
949 * @param string $p_title Title
950 * @param array $p_attribute javascript attribute to add to the anchor, CAUTION special chars will be translated(see htmlspecialchars function)
951 * @see h()
952 */
953 static function anchor($p_text, $p_url="", $p_js="",
954 $p_style=' class="line" ', $p_title="click", array $p_attribute=[])
955 {
956 if ($p_js!="")
957 {
958 $p_url='href="javascript:void(0)"';
959 } else {
960 $p_url=sprintf('href="%s"',$p_url);
961 }
962 $str_javascript_attr=build_javascript_attribute($p_attribute);
963 $str=sprintf('<a %s %s %s %s title="%s">%s</a>', $str_javascript_attr,$p_style, $p_url, $p_js, $p_title,$p_text);
964 return $str;
965 }
966
967 /**
968 * Create an ISelect object containing the available repository for reading
969 * or writing
970 * @remark $g_user global.
971 *
972 * @param $p_cn db object
973 * @param $p_name name of the select
974 * @param $p_mode is 'R' for reading, 'W' for writinh
975 * @return ISelect
976 * @throws Exception if p_mode is wrong
977 */
978 static function select_stock($p_cn, $p_name, $p_mode)
979 {
980 global $g_user;
981 if (!in_array($p_mode, array('R', 'W')))
982 {
983 throw new Exception(__FILE__.":".__LINE__." $p_mode invalide");
984 }
985 $profile=$g_user->get_profile();
986 $sel=new ISelect($p_name);
987
988 if ($p_mode=='W')
989 {
990 $sel->value=$p_cn->make_array("
991 select r_id,r_name
992 from stock_repository join profile_sec_repository using (r_id)
993 where
994 ur_right='W' and p_id=".sql_string($profile).
995 " order by 2");
996 return $sel;
997 }
998 if ($p_mode=='R')
999 {
1000 $sel->value=$p_cn->make_array("
1001 select r_id,r_name
1002 from stock_repository join profile_sec_repository using (r_id)
1003 where
1004 p_id=".sql_string($profile).
1005 " order by 2");
1006 return $sel;
1007 }
1008 }
1009 /**
1010 *
1011 * * filter the rows in a table and keep the colored row in alternance
1012 * @param dom_id $p_table_id table
1013 * @param string $p_col , column to search example 0,1,2
1014 * @param int $start_row row to always keep (header)
1015 * @param string $p_name name of the input field
1016 * @param string $p_old_value search value sent by $_GET (or $_REQUEST)
1017 * @return string HTML
1018 */
1019 static function filter_table_form($p_table_id, $p_col, $start_row, $p_name,
1020 $p_old_value)
1021 {
1022 $r="
1023 <span>
1024 <span class=\"icon\" >&#xf50d;</span>
1025 <input id=\"lk_".$p_table_id."\" name=\"$p_name\" value=\"$p_old_value\"autocomplete=\"off\" class=\"input_text\" name=\"filter\" onkeyup=\"filter_table(this, '$p_table_id','$p_col',$start_row )\" type=\"text\" placeholder=\""._("Recherche")."\">
1026 <input type=\"button\" class=\"smallbutton\" onclick=\"$('lk_".$p_table_id."').value='';filter_table($('lk_".$p_table_id."'), '$p_table_id','$p_col',$start_row );\" value=\"X\">
1027 </span>
1028 ";
1029 $r.=' <span class="notice" id="info_'.$p_table_id.'"></span>';
1030 return $r;
1031 }
1032 /**
1033 * filter the rows in a table and keep the colored row in alternance
1034 * @param dom_id $p_table_id table
1035 * @param string $p_col , column to search example 0,1,2
1036 * @param int $start_row row to always keep (header)
1037 * @return string HTML
1038 */
1039 static function filter_table($p_table_id, $p_col, $start_row)
1040 {
1041 $r="
1042 <span>
1043 <span class=\"icon\" >&#xf50d;</span>
1044
1045 <input id=\"lk_".$p_table_id."\" autocomplete=\"off\" class=\"input_text\" name=\"filter\" onkeyup=\"filter_table(this, '$p_table_id','$p_col',$start_row )\" type=\"text\" placeholder=\""._("Recherche")."\">
1046 <input type=\"button\" class=\"smallbutton\" onclick=\"$('lk_".$p_table_id."').value='';filter_table($('lk_".$p_table_id."'), '$p_table_id','$p_col',$start_row );\" value=\"X\">
1047 </span>
1048 ";
1049 $r.=' <span class="notice" id="info_'.$p_table_id.'"></span>';
1050 return $r;
1051 }
1052 /**
1053 * @brief Display a field for searching an element in a list, the searchable text must be in an element with the className search-content
1054 * @param string $p_list_id DOM ID of the list (ul or ol)
1055 * @code
1056
1057 <ul id="xx">
1058 <li><span class="search-content"> Content used for searching</span> Content not used for search </li>
1059 <li><span class="search-content"> Content used for searching</span> <a href="">Content not used for search</a> </li>
1060 <li><span class="search-content"> Content used for searching</span> Content not used for search </li>
1061 <li><a href=""><span class="search-content"> Content used for searching</span> </a></li>
1062 <ul>
1063 *
1064 * @endcode
1065 * @return string
1066 */
1067 static function filter_list($p_list_id)
1068 {
1069 $r="<span>";
1070 $r.='<span class=" icon">&#xf50d;</span>';
1071 $r.=sprintf('<input id="search_%s" type="TEXT" class="input_text" name="filter_list%s" placeholder="%s" onkeyup="filter_list(this,\'%s\')">',
1072 $p_list_id,$p_list_id,_("Recherche"),$p_list_id);
1073
1074 $r.=sprintf('<input type="button" class="smallbutton" onclick="$(\'search_%s\').value=\'\';filter_list(\'search_%s\',\'%s\')" value="x">',$p_list_id,$p_list_id,$p_list_id);
1075 $r.='</span>';
1076 return $r;
1077 }
1078
1079 static function show_reconcile($p_div, $let, $span="")
1080 {
1081 $r='<A style="color:red;text-decoration:underline" href="javascript:void(0)" onclick="show_reconcile(\''.$p_div.'\',\''.$let.'\')">'.$let.$span.'</A>';
1082 return $r;
1083 }
1084
1085 /**
1086 * Zoom the calendar
1087 * @param type $obj objet json for the javascript
1088 * @see calendar_zoom in noalyss_script.js
1089 */
1090 static function calendar_zoom($obj)
1091 {
1092 $button=new ISmallButton("calendar", _("Calendrier"));
1093 $button->javascript="calendar_zoom($obj)";
1094 return $button->input();
1095 }
1096
1097 /**
1098 *
1099 * @param type $p_array indice
1100 * - div div name
1101 * - type ALL, VEN, ACH or ODS
1102 * - all_type 1 yes 0 no
1103 *
1104 */
1105 static function button_choice_ledger($p_array)
1106 {
1107 extract($p_array, EXTR_SKIP);
1108 $bledger_param=json_encode(array(
1109 'dossier'=>$_REQUEST['gDossier'],
1110 'type'=>$type,
1111 'all_type'=>$all_type,
1112 'div'=>$div,
1113 'class'=>'inner_box'
1114 ));
1115
1116 $bledger_param=noalyss_str_replace('"', "'", $bledger_param);
1117 $bledger=new ISmallButton('l');
1118 $bledger->label=_("choix des journaux");
1119 $bledger->javascript=" show_ledger_choice($bledger_param)";
1120 $f_ledger=$bledger->input();
1121 $hid_jrn="";
1122 if (isset($_REQUEST[$div.'nb_jrn']))
1123 {
1124 for ($i=0; $i<$_REQUEST[$div.'nb_jrn']; $i++)
1125 {
1126 if (isset($_REQUEST[$div."r_jrn"][$i]))
1127 $hid_jrn.=HtmlInput::hidden($div.'r_jrn['.$i.']',
1128 $_REQUEST[$div."r_jrn"][$i]);
1129 }
1130 $hid_jrn.=HtmlInput::hidden($div.'nb_jrn',
1131 $_REQUEST[$div.'nb_jrn']);
1132 } else
1133 {
1134 $hid_jrn=HtmlInput::hidden($div.'nb_jrn', 0);
1135 }
1136 echo $f_ledger;
1137 echo '<span id="ledger_id'.$div.'">';
1138 echo $hid_jrn;
1139 echo '</span>';
1140 }
1141
1142 /**
1143 * @brief Returns HTML code for displaying a icon with a link to a receipt document from
1144 * the ledger
1145 * @param $p_jr_id jrn.jr_id
1146 * @param $p_name name in the link , if the name is empty then we show the icon
1147 * @return nothing or HTML Code for a link to the document
1148 */
1149 static function show_receipt_document($p_jr_id, $p_name="")
1150 {
1151 global $cn;
1152 $image=$p_name;
1153
1154 // Check the jr_id has a receipt document
1155 $array=$cn->get_array('select jr_def_id,jr_pj_name,jr_grpt_id from jrn where jr_id=$1',
1156 array($p_jr_id));
1157 if (count($array)==0)
1158 return "";
1159 if ($array[0]['jr_pj_name']=="")
1160 return "";
1161 $str_dossier=Dossier::get();
1162
1163 // Name is empty then use an image
1164 if ($p_name=="")
1165 {
1166 $image='<IMG style="width:24px;height:24px;border:0px" SRC="image/documents.png" title="'.h($array[0]['jr_pj_name']).'" >';
1167 }
1168
1169 // Build the url
1170 $href=http_build_query(array('gDossier'=>Dossier::id(), 'jr_id'=>$p_jr_id,
1171 'act'=>'RAW:receipt'));
1172
1173 $r=sprintf('<A class="mtitle line" HREF="export.php?%s">%s</A>', $href,
1174 $image);
1175 return $r;
1176 }
1177
1178 /**
1179 *
1180 * @param type $p_operation_jr_id action_gestion_operation.ago_id
1181 */
1182 static function button_action_remove_operation($p_operation)
1183 {
1184 $rmOperation=sprintf("confirm_box(null,'"._('Voulez-vous effacer cette relation ')."',function () {remove_operation('%s','%s');});",
1185 dossier::id(), $p_operation);
1186 $js=Icon_Action::trash("acop".$p_operation, $rmOperation);
1187 return $js;
1188 }
1189
1190
1191
1192 static function button_action_add()
1193 {
1194 $dossier=Dossier::id();
1195 $js=HtmlInput::button_action(_('Nouvel événement'),
1196 'action_add('.$dossier.')', 'xx', 'smallbutton');
1197 return $js;
1198 }
1199
1200 /**
1201 * @brief Insert attribute inside a INPUT TYPE, these attribute can be retrieved
1202 * in javascript with element.getAttribute or changed with element.setAttribute
1203 * example insert my_attribute into a checkbox <input type="checkbox" "my_attribute"="XX">
1204 * @return string to insert into the HTML node
1205 *
1206 */
1207 function get_node_attribute()
1208 {
1209 $r="";
1210 $nb_attribute=count($this->attribute);
1211 for ($i=0; $i<$nb_attribute; $i++)
1212 {
1213 $r.=sprintf(' %s="%s" ', $this->attribute[$i][0],
1214 $this->attribute[$i][1]);
1215 }
1216 return $r;
1217 }
1218
1219}
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:511
global $g_user
if no group available , then stop
$ag_id
Definition: action.inc.php:54
$href
Definition: adm.inc.php:31
$action
if(headers_sent() &&DEBUGNOALYSS > 0) $html
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$select selected
for( $i=0; $i< $nb_row; $i++)
if(!headers_sent())
– pour utiliser unoconv démarrer un server libreoffice commande libreoffice –headless –accept="socket...
$ret javascript
$div
$name size
$_REQUEST['ac']
$array_cat
$from_poste name
$input_from id
Definition: balance.inc.php:63
for($i=0;$i<=6;$i++) $ind
Definition: calendar.php:34
$_GET['qcode']
$class
class widget This class is used to create all the HTML INPUT TYPE and some specials which works with ...
static followup_card_button($f_id, $p_mesg)
display a div with the history of the card
static get_to_string($array, $start="?")
transform $_GET data to string
static detail_action($ag_id, $p_mesg, $p_modify=1)
return an anchor to view the detail of an action
static history_account($p_account, $p_mesg, $p_style="", $p_exercice="")
display a div with the history of the account
static detail_modele_document($p_id, $p_mesg)
return a string containing the html code for calling the modifyModeleDocument
static button_hide($div_name)
Hide the HTML popup.
static history_card_button($f_id, $p_mesg, $p_exercice="")
display a div with the history of the card
static default_value_request($ind, $default)
return default if the value if the value doesn't exist in $_REQUEST use HttpInput instead
static button_image($javascript, $id="xx", $p_class='class="button"', $p_image="")
button Html image
static button_close($div_name, $class='smallbutton')
close button for the HTML popup
set_attribute($p_name, $p_value)
set the extra javascript property for the INPUT field
static default_value_get($ind, $default)
return default if the value if the value doesn't exist in $_GET use HttpInput instead
static detail_op($p_jr_id, $p_mesg)
return a string containing the html code for calling the modifyOperation
static select_stock($p_cn, $p_name, $p_mode)
Create an ISelect object containing the available repository for reading or writing.
static request_to_hidden(array $array)
transform $_REQUEST data to hidden
__construct($p_name="", $p_value="", $p_id="")
static remove_stock($p_id, $p_mesg)
return a string containing the html code for calling the removeStock
static filter_table($p_table_id, $p_col, $start_row)
filter the rows in a table and keep the colored row in alternance
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
set_value($p_string)
Set the value of input (IText, INum,...)
static generate_id($p_prefix)
generate an unique id for a widget,
static extension()
static request_to_string($array, $start="?")
transform $_REQUEST data to string
setReadOnly($p_read)
static default_value($ind, $default, $array)
return default if the value if the value doesn't exist in the array
static reset($p_value)
static print_window()
Javascript to print the current window.
make_object_deprecated($p_name=null)
Make a JSON object, this method create a javascript object with the attribute set,...
static card_detail($p_qcode, $pname='', $p_style="", $p_nohistory=false, $nofollowup=false)
show the detail of a card
static anchor($p_text, $p_url="", $p_js="", $p_style=' class="line" ', $p_title="click", array $p_attribute=[])
Return a simple anchor with a url or a javascript if $p_js is not null then p_url will be javascript:...
static button_action($action, $javascript, $id=NULL, $p_class="button", $p_symbole="")
button Html with javascript
static warnbulle($p_comment)
static anchor_close($div, $p_js="")
Return a html string with an anchor which close the inside popup.
get_value()
Return the value of input (IText, INum,...)
static hidden($p_name, $p_value, $p_id="")
static history_anc_account($p_account, $p_mesg, $p_style="", $p_exercice="")
display a div with the history of the analytic account
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n')
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
static button_anchor($p_label, $p_value, $p_name="", $p_javascript="", $p_class="smallbutton")
create a button with a ref
static calendar_zoom($obj)
Zoom the calendar.
static array_to_string($array, $global_array, $start="?")
transform request data to string
static errorbulle($p_comment)
static simple_array_to_hidden($array)
Transform a double array as a HTML string with hidden html value array has the formarray ["name"]="x"...
static post_to_string($array)
transform $_POST data to string
static history_card($f_id, $p_mesg, $p_style="", $p_exercice="")
display a div with the history of the card
static array_to_hidden($array, $global_array)
transform request data to hidden
static show_reconcile($p_div, $let, $span="")
static get_to_hidden($array)
transform $_GET data to hidden
static anchor_hide($action, $javascript)
Return a html string with an anchor to hide a div, put it in the right corner.
static image_click($p_image, $p_js, $p_message, $p_class="")
Image to click ,.
static display_periode($p_id)
static select_cat($array_cat)
create a hidden plus button to select the cat of ledger
static json_to_hidden($p_json)
transform a json to hidden
static filter_list($p_list_id)
Display a field for searching an element in a list, the searchable text must be in an element with th...
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
static post_to_hidden($array)
transform $_POST data to hidden
get_js_attr()
you can add attribute to this in javascript this function is a wrapper and create a script (in js) to...
static anchor_action($action, $javascript, $id=NULL, $p_class="button", $p_symbole="")
Anchor Html with javascript.
static filter_table_form($p_table_id, $p_col, $start_row, $p_name, $p_old_value)
static anchor_empty($p_text, $p_id, $p_title="")
let you create only a link and set an id on it.
static default_value_post($ind, $default)
return default if the value if the value doesn't exist in $_POST use HttpInput instead
Html Input.
Html Input.
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
static close($p_div)
Return a html string with an anchor which close the inside popup.
static draggable($p_div)
Display a icon for fix or move a div.
static zoom($p_div, $p_javascript)
Display a icon for zooming.
static hide($action, $javascript)
Return a html string with an anchor to hide a div, put it in the right corner.
static full_size($p_div)
$all table
global $g_failed
$_POST['ac']
Definition: do.php:310
$str
Definition: fiche.inc.php:91
$icard readOnly
build_javascript_attribute($pa_attribute)
build a string with the attribute that javascript can use , that string must be included in a DOM ele...
create_script($p_string)
create the HTML for adding the script tags around of the script
$all disabled
if( $delta< 0) elseif( $delta==0)
$poste extra
$p_mesg
Definition: opening.inc.php:34
$p_exercice
$desc heigh
$desc width
$p_url