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