noalyss Version-9
manage_table_sql.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// Copyright Author Dany De Bontridder danydb@aevalys.eu
21/*!\file
22 * \brief Definition Manage_Table_SQL
23 *
24 */
25
26/*!\brief Purpose is to propose a librairy to display a table content
27 * and allow to update and delete row , handle also the ajax call
28 * thanks the script managetable.js
29 *
30 * Code for ajax , here we see the ajax_input for creating a dg box
31 \code
32 $objet->set_pk($p_id);
33 // It is very important to set the name of the javascript variable
34 // Contained in the http_input variable "ctl" , without this the list cannot be updated
35 $objet->set_object_name($objet_name);
36
37 // Set the ajax to call
38 $objet->set_callback("ajax.php");
39
40 // Build the json object for JS
41 $http=new HttpInput();
42 $plugin_code=$http->request("plugin_code");
43 $ac=$http->request("ac");
44 $sa=$http->request("sa");
45 $aJson=array("gDossier"=>Dossier::id(),
46 "ac"=>$ac,
47 "plugin_code"=>$plugin_code,
48 "sa"=>$sa,
49 "sb"=>$sb
50 );
51 $json=json_encode($aJson);
52 $objet->param_set($json);
53
54
55 // Display the box
56 header('Content-type: text/xml; charset=UTF-8');
57 $xml=$objet->ajax_input();
58 echo $xml->save_XML();
59 @endcode
60 * @see ManageTable.js
61 * @see ajax_accounting.php
62 * @see sorttable.js
63 *
64 * If you need to add extra XML fields to manage them in the afterSaveFct then you can do like this
65 * in your php code answering the ajax call
66 *
67 * @code
68 header('Content-type: text/xml; charset=UTF-8');
69 $xml=$manage_table->ajax_save();
70 $s1=$xml->createElement("previous_id",$previous);
71 $data=$xml->getElementsByTagName("data");
72 $data[0]->append($s1);
73 echo $xml->saveXML();
74
75
76 * @endcode
77 *
78 * The afterSaveFct is the function called after saving, the param is the HTML Element
79 @code PHP
80// to redirect : we take the pk_id and redirect to another location
81
82 $obj=$this->get_object_name();
83 $url=DRIVINGSCHOOL_URL;
84 $script=<<<EOF
85(function(){
86{$obj}.afterSaveFct=function(p_param) {
87 let student=p_param.attributes["ctl_pk_id"].value;
88 window.location="{$url}/do.php?do=student&student_id="+student+"&act=detail";
89 }})();
90EOF;
91
92echo create_script($script);
93 {$obj}.afterSaveFct=function(p_param) {
94 let student=p_param.attributes["ctl_pk_id"].value;
95 window.location="{$url}/do.php?do=student&student_id="+student+"&act=detail";
96 }})();
97@endcode
98 */
99
101{
102
103 protected $table; //!< Object Data_SQL
104 protected $a_label_displaid; //!< Label of the col. of the datarow
105 protected $a_order; //!< order of the col
106 protected $a_prop; //!< property for each col.
107 protected $a_type; //!< Type of the column : date , select ... Only in input
108 protected $a_select; //!< Possible value if a_type is a SELECT
109 protected $object_name; //!< Object_name is used for the javascript , it is the row id to update or delete
110 protected $row_delete; //!< Flag to indicate if rows can be deleted
111 protected $row_update; //!< Flag to indicate if rows can be updated
112 protected $row_append; //!< Flag to indicate if rows can be added
113 protected $json_parameter; //!< Default parameter to add (gDossier...), sent to the ajax callback
114 protected $aerror; //!< Array containing the error of the input data
115 protected $col_sort; //!< when inserting, it is the column to sort,-1 to disable it and append only
116 protected $a_info; //!< Array with the infotip
117 protected $sort_column; //!< javascript sort on this column , if empty there is no js sort
118 protected $dialog_box; //!< ID of the dialog box which display the result of the ajax calls
119 protected $search_table; //!< boolean , by default true ,it is possible to search in the table,
120 const UPDATABLE=1;
121 const VISIBLE=2;
122
123 protected $icon_mod; //!< place of right or left the icon update or mod, default right, accepted value=left,right,first,custom column for mod
124 protected $icon_del; //!< place of right or left the icon update or mod, default right, accepted value=left,right
125 protected $dialogbox_style; //!< style of the dialog box
126 protected $button_add_top; //!< place of the button add on the top, by default true
127 protected $title; //! < give the title of the diabox , default is Data
128 protected $cssclass; //! CSS class for the dialog box
129 protected $current_row; //! in display_row and display_custom_row, it is the current row which is used
130 protected $a_col_option; //!< Extra to add to the column : CSS Style , CSS class, javascript ,...
131 protected $a_header_option; //!< Extra to add to the column Header : CSS Style , CSS class, javascript ,...
132 protected $callback; //!< Callback function
133 /**
134 * @brief Constructor : set the label to the column name,
135 * the order of the column , set the properties and the
136 * permission for updating or deleting row
137 * @example test_manage_table_sql.php
138 * @example ajax_manage_table_sql.php
139 */
140
141 function __construct(Data_SQL $p_table)
142 {
143 $this->table=$p_table;
144 $order=0;
145 foreach ($this->table->name as $key=> $value)
146 {
147
148 $this->a_label_displaid[$value]=$key;
149 $this->a_order[$order]=$value;
150 $this->a_prop[$value]=self::UPDATABLE|self::VISIBLE;
151 $this->a_type[$value]=$this->table->type[$value];
152 $this->a_select[$value]=null;
153 $this->a_col_option[$value]="";
154 $this->a_header_option[$value]="";
155 $order++;
156 }
157 $this->object_name=uniqid("tbl");
158 $this->row_delete=TRUE;
159 $this->row_update=TRUE;
160 $this->row_append=TRUE;
161 $this->callback="ajax.php";
162 $this->json_parameter=json_encode(array("gDossier"=>Dossier::id(),
163 "op"=>"managetable"));
164 $this->aerror=[];
165 $this->icon_mod="right";
166 $this->icon_del="right";
167 $this->col_sort=0;
168 // By default no js sort
169 $this->sort_column="";
170 $this->dialog_box="dtr";
171 $this->dialogbox_style=array();
172 $this->search_table=true;
173 $this->button_add_top=true;
174 $this->title=_("Donnée");
175 $this->cssclass="inner_box";
176
177 }
178 function setCssClass($p_class) {
179 $this->cssclass=$p_class;
180 }
181 function getCssClass() {
182 return $this->cssclass;
183 }
184 /**
185 *@brief Set the title of the diabox , default is Donnée
186 * @param type $p_title
187 */
188 function setTitle($p_title)
189 {
190 $this->title=$p_title;
191 }
192 function getTitle()
193 {
194 return $this->title;
195 }
196 /**
197 * @brief Get if we can search in the table
198 * @return boolean
199 */
200 public function get_search_table()
201 {
202 return $this->search_table;
203 }
204
205 /**
206 * @brief Set the table searchable or not
207 * @param boolean : true we can search
208 * @return $this
209 */
211 {
212 $this->search_table=$search_table;
213 return $this;
214 }
215
216 /**
217 *@brief send the XML headers for the ajax call
218 */
219 function send_header()
220 {
221 header('Content-type:text/xml;charset="UTF-8"');
222 }
223
224 /**
225 * @brief return the db_style
226 * @return array
227 */
228 public function get_dialogbox_style()
229 {
231 }
232
233 /**
234 * @brief Dialog box style , by default {position: "fixed", top: '15%', width: "auto", "margin-left": "20%"}
235 *
236 * @param array $db_style , will be transformed into a json object
237 */
238 public function set_dialogbox_style($db_style)
239 {
240 $this->dialogbox_style = $db_style;
241 return $this;
242 }
243
244 /**
245 * @return mixed
246 */
247 public function get_dialog_box()
248 {
249 return $this->dialog_box;
250 return $this;
251 }
252
253 /**
254 * @param mixed $dialog_box
255 */
257 {
258 $this->dialog_box = $dialog_box;
259 return $this;
260 }
261
262 /**
263 * @brief When adding an element , it is column we checked to insert before,
264 * @return none
265 */
266 function get_col_sort() {
267 return $this->col_sort;
268 }
269 /**
270 * @brief Set the info for a column, use Icon_Action::infobulle
271 * the message are in message_javascript.php
272 * @param string $p_key Column name
273 * @param integer $p_comment comment idx
274 *
275 * @see message_javascript.php
276 * @see Icon_Action::infobulle()
277 */
278 function set_col_tips($p_key,$p_comment) {
279 $this->a_info[$p_key]=$p_comment;
280 }
281 /**
282 * @brief When adding an element ,we place it thanks the DOM Attribute sort_value
283 * set it to -1 if you want one to append
284 * @param numeric $pn_num
285 * @note you must be aware that the icon_mod or icon_del is in the first col,
286 * this column is skipped
287 */
288 function set_col_sort($p_num) {
289 $this->col_sort=$p_num;
290 }
291 function get_icon_mod()
292 {
293 return $this->icon_mod;
294 }
295 function get_icon_del()
296 {
297 return $this->icon_del;
298 }
299 function get_table()
300 {
301 return $this->table;
302 }
303
304 function set_table(Data_SQL $p_noalyss_sql)
305 {
306 $this->table=$p_noalyss_sql;
307 }
308 function get_order()
309 {
310 return $this->a_order;
311 }
313 {
314 if (! is_array($p_order) )
315 throw new Exception("set_order, parameter is not an array");
316 $this->a_order=$p_order;
317 }
318 /**
319 * @brief set the error message for a wrong input
320 * @param $p_col the column name
321 * @param $p_message the error message
322 * @see check
323 */
324 function set_error($p_col, $p_message)
325 {
326 $this->aerror[$p_col]=$p_message;
327 }
328 /**
329 * @brief returns the nb of errors found
330 */
331 function count_error()
332 {
333 return count($this->aerror);
334 }
335 /**
336 * @brief retrieve the error message
337 * @param $p_col column name
338 * @return string with message or empty if no error
339 * @see input
340 */
342 {
343 if (isset($this->aerror[$p_col]))
344 return $this->aerror[$p_col];
345 return "";
346 }
347
348 /**
349 * @brief This function can be overrided to check the data before
350 * inserting , updating or removing, above an example of an overidden check.
351 *
352 * Usually , you get the row of the table (get_table) , you check the conditions
353 * if an condition is not met then you set the error with $this->set_error
354 *
355 * if there are error (returns false otherwise true
356 *
357 * @see set_error get_error count_error
358 * @return boolean
359 *
360@code
361function check()
362 {
363 global $cn;
364 $table=$this->get_table();
365 $is_error=0;
366 $insert=false;
367 // sect_codename must be unique
368 if ( $table->exist() > 0) {
369 $insert=1;
370 }
371 $count=$cn->get_value(" select count(*) from syndicat.treasurer where tr_login=$1 and sect_id=$2 and tr_id<>$3",
372 array(
373 $table->tr_login,
374 $table->section_full_name,
375 $table->tr_id
376 ));
377 if ($count > 0 ) {
378 $this->set_error("section_full_name",_("Ce trésorier a déjà accès à cette section"));
379 $is_error++;
380 }
381 if ( $is_error > 0 ) return false;
382 return true;
383 }
384@endcode
385 */
386 function check()
387 {
388 return true;
389 }
390 /**
391 * @brief add extra to column, normally class , javascript or style
392 * @param string $p_key column name
393 * @see set_col_option
394 */
395 public function get_col_option($p_key)
396 {
397 if (!isset($this->a_type[$p_key]))
398 throw new Exception("invalid key $p_key");
399
400 return $this->a_col_option[$p_col];
401 }
402 /**
403 * @brief add extra to column, normally class or style
404 *
405 * @param string $p_key column name
406 * @param string $p_value extra info for this column (CSS, js, ...)
407 *
408 @code{.php}
409 $manage_table->set_col_option("pcm_lib",'style="color:red;text-align:center"');
410
411 $manage_table->set_col_option("pcm_val", "onclick=\"alert('toto')\" style=\"text-decoration:underline\" onmouseover=\"this.style.cursor='pointer'\"");
412 @endcode
413 *
414 */
415 public function set_col_option($p_key,$p_value)
416 {
417
418 if (!isset($this->a_type[$p_key]))
419 throw new Exception("invalid key $p_key");
420 $this->a_col_option[$p_key]=$p_value;
421 return $this;
422 }
423 /**
424 * @brief add extra to column Header, normally class , javascript or style
425 * @param string $p_key column name
426 * @see set_col_option
427 */
428 public function get_header_option($p_key)
429 {
430 if (!isset($this->a_type[$p_key]))
431 throw new Exception("invalid key $p_key");
432
433 return $this->a_header_option[$p_col];
434 }
435 /**
436 * @brief add extra to column Header, normally class or style
437 * @param string $p_key column name
438 * @param string $p_value extra info for this column (CSS, js, ...)
439 * @see set_col_option
440 */
441 public function set_header_option($p_key,$p_value)
442 {
443 if (!isset($this->a_type[$p_key]))
444 throw new Exception("invalid key $p_key");
445 $this->a_header_option[$p_key]=$p_value;
446 return $this;
447 }
448
449 /**
450 * @brief set the type of a column , it will change in the input db box , the
451 * select must supply an array of possible values [val=> , label=>] with
452 * the variable $this->key_name->a_value
453 * @param $p_key col name
454 * @param $p_type is "text", "numeric", "date", "select", "timestamp","custom"
455 * @param $p_array if type is SELECT an array is expected
456 * @note if $p_type is custom then a function named input_custom($p_key,$p_value) must be implemented
457 * in the class
458 * @see Manage_Table_SQL:input_custom
459 */
460 function set_col_type($p_key, $p_value, $p_array=NULL)
461 {
462 if (!isset($this->a_type[$p_key]))
463 throw new Exception("invalid key $p_key");
464
465 if (!in_array($p_value,
466 array("text", "numeric","numeric2", "numeric4","numeric6","date", "select", "timestamp","custom")))
467 throw new Exception("invalid type $p_value");
468
469 $this->a_type[$p_key]=$p_value;
470 $this->a_select[$p_key]=$p_array;
471 if ( in_array($p_value ,array("numeric","numeric2","numeric4","numeric6")) && $this->a_col_option[$p_key]=="") {
472 $this->a_col_option[$p_key]=' class="num" ';
473 }
474
475 }
476
477 /**
478 * @brief return the type of a column
479 * @param $p_key col name
480 * @see set_col_type
481 */
482 function get_col_type($p_key)
483 {
484 if (!isset($this->a_type[$p_key]))
485 throw new Exception("invalid key");
486
487 return $this->a_type[$p_key];
488 }
489
490 /**
491 * @brief Get the object name
492 * @details : return the object name , it is useful it
493 * the javascript will return coded without the create_js_script function
494 * @see create_js_script
495 */
497 {
498 return $this->object_name;
499 }
500 /**
501 * @brief Add json parameter to the current one
502 */
503 function add_json_param($p_attribute,$p_value) {
504 $x=json_decode($this->json_parameter,TRUE);
505 $x[$p_attribute]=$p_value;
506 $this->json_parameter=json_encode($x, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
507 }
508 function get_json()
509 {
511 }
512 function get_object_name() {
513 return $this->object_name;
514 }
515 /**
516 * @brief Set the parameter of the object (gDossier, ac, plugin_code...)
517 * @detail By default , only gDossier will be set . The default value
518 * is given in the constructor
519 * @param string with json format $p_json
520 * @deprecated since version 692
521 * @see set_json
522 */
523 function param_set($p_json)
524 {
525 $this->set_json($p_json);
526 }
527 /**
528 * @brief Set the parameter of the object (gDossier, ac, plugin_code...)
529 * @detail By default , only gDossier will be set . The default value
530 * is given in the constructor
531 * @param string with json format $p_json
532 */
533 function set_json($p_json)
534 {
535 $this->json_parameter=$p_json;
536
537 }
538 /**
539 * @brief set the callback function that is passed to javascript
540 * @param $p_file : callback file by default ajax.php
541 */
542 function set_callback($p_file)
543 {
544 $this->callback=$p_file;
545 }
546
547 /**
548 * @brief we must create first the javascript if we want to update, insert
549 * or delete rows. It is the default script .
550 */
552 {
553 $style=json_encode($this->dialogbox_style);
554 echo "
555 <script>
556 var {$this->object_name}=new ManageTable(\"{$this->table->table}\");
557 {$this->object_name}.set_callback(\"{$this->callback}\");
558 {$this->object_name}.param_add({$this->json_parameter});
559 {$this->object_name}.set_sort({$this->get_col_sort()});
560 {$this->object_name}.set_control(\"{$this->get_dialog_box()}\");
561 {$this->object_name}.set_style($style);
562 {$this->object_name}.cssclass=\"{$this->cssclass}\";
563 </script>
564
565 ";
566 }
568 {
569 $error=$this->get_error($p_col);
570 if ($error == "") { return "";}
572 }
573 /**
574 * @brief Set the object_name
575 * @param string $p_object_name name of the JS var, used in ajax response,id
576 * of the part of the id DOMElement to modify
577 */
578 function set_object_name($p_object_name)
579 {
580 $this->object_name=$p_object_name;
581 }
582
583 /**
584 * @brief set a column of the data row updatable or not
585 * @param string $p_key data column
586 * @param bool $p_value Boolean False or True
587 */
588 function set_property_updatable($p_key, $p_value)
589 {
590 if (! isset($this->a_prop[$p_key]))
591 throw new Exception(__FILE__.":".__LINE__."$p_key invalid index");
592 // if already done returns
593 if ( $this->get_property_updatable($p_key) == $p_value)return;
594 if ($p_value==False)
595 $this->a_prop[$p_key]=$this->a_prop[$p_key]-self::UPDATABLE;
596 elseif ($p_value==True)
597 $this->a_prop[$p_key]=$this->a_prop[$p_key]|self::UPDATABLE;
598 else
599 throw new Exception("set_property_updatable [ $p_value ] incorrect");
600 }
601
602 /**
603 * @brief return false if the update of the row is forbidden
604 */
605 function can_update_row()
606 {
607
608 return $this->row_update;
609 }
610 /**
611 * @brief Set the icon to modify at the right ,the first col or left of the row, if the mod if custom ,
612 * you have to override the function display_icon_custom
613 * @see Manage_Table_SQL::display_icon_custom($p_row)
614 * @param string $pString default right, accepted value=left,right,first,custom column for mod
615 * @throws Exception if invalide choice
616 */
617 function set_icon_mod($pString) {
618 if (! in_array( $pString ,[ 'right','left','custom','first'] ) )
619 throw new Exception('set_icon_mod invalide '.$pString);
620 $this->icon_mod=$pString;
621 }
622 /**
623 * @brief Set the icon to delete at the right or left of the row
624 * @param type $pString
625 * @throws Exception
626 */
627 function set_icon_del($pString) {
628 if ($pString != "right" && $pString != "left" )
629 throw new Exception('set_icon_del invalide '.$pString);
630 $this->icon_del=$pString;
631 }
632 /**
633 * @brief return false if the append of the row is forbidden
634 */
635 function can_append_row()
636 {
637
638 return $this->row_append;
639 }
640
641 /**
642 * @brief Enable or disable the deletion of rows
643 * @param $p_value Boolean : true enable the row to be deleted
644 */
645 function set_delete_row($p_value)
646 {
647 if ($p_value!==True&&$p_value!==False)
648 throw new Exception("Valeur invalide set_delete_row [$p_value]");
649 $this->row_delete=$p_value;
650 }
651
652 /**
653 * @brief Enable or disable the appending of rows
654 * @param $p_value Boolean : true enable the row to be appended
655 */
656 function set_append_row($p_value)
657 {
658 if ($p_value!==True&&$p_value!==False)
659 throw new Exception("Valeur invalide set_append_row [$p_value]");
660 $this->row_append=$p_value;
661 }
662
663 /**
664 * @brief Enable or disable the updating of rows
665 * @param $p_value Boolean : true enable the row to be updated
666 */
667 function set_update_row($p_value)
668 {
669 if ($p_value!==True&&$p_value!==False)
670 throw new Exception("Valeur invalide set_update_row [$p_value]");
671 $this->row_update=$p_value;
672 }
673
674 /**
675 * @brief return false if the delete of the row is forbidden
676 */
677 function can_delete_row()
678 {
679 return $this->row_delete;
680 }
681
682 /**
683 * @brief return True if the column is updatable otherwise false
684 * @param $p_key data column
685 */
686 function get_property_updatable($p_key)
687 {
688 $val=$this->a_prop[$p_key]&self::UPDATABLE;
689 if ($val==self::UPDATABLE)
690 return true;
691 return false;
692 }
693
694 /**
695 * @brief set a column of the data row visible or not
696 * @param string $p_key data column
697 * @param bool $p_value Boolean False or True
698 */
699 function set_property_visible($p_key, $p_value)
700 {
701 if (!isset ($this->a_prop[$p_key]) )
702 throw new Exception(__FILE__.":".__LINE__."$p_key invalid index");
703 // if already done return
704 if ( $this->get_property_visible($p_key) == $p_value)return;
705
706 if ($p_value==False)
707 $this->a_prop[$p_key]=$this->a_prop[$p_key]-self::VISIBLE;
708 elseif ($p_value==True)
709 $this->a_prop[$p_key]=$this->a_prop[$p_key]|self::VISIBLE;
710 else
711 throw new Exception("set_property_updatable [ $p_value ] incorrect");
712 }
713
714 /**
715 * @brief return True if the column is visible otherwise false
716 * @param $p_key data column
717 */
718 function get_property_visible($p_key)
719 {
720 $val=$this->a_prop[$p_key]&self::VISIBLE;
721 if ($val===self::VISIBLE)
722 return true;
723 return false;
724 }
725
726 /**
727 * @brief set the name to display for a column
728 * @param string $p_key data column
729 * @param string $p_display Label to display
730 *
731 */
732 function set_col_label($p_key, $p_display)
733 {
734 $this->a_label_displaid[$p_key]=$p_display;
735 }
736
737 /**
738 * @brief get the position of a column
739 * @param $p_key data column
740 */
741 function get_current_pos($p_key)
742 {
743 $nb_order=count($this->a_order);
744 for ($i=0; $i<$nb_order; $i++)
745 if ($this->a_order[$i]==$p_key)
746 return $i;
747 throw new Exception("COL INVAL ".$p_key);
748 }
749
750 /**
751 * @brief if we change a column order , the order
752 * of the other columns is impacted.
753 *
754 * With a_order[0,1,2,3]=[x,y,z,a]
755 * if we move the column x (idx=0) to 2
756 * we must obtain [y,z,x,a]
757 * @param string $p_key data column
758 * @param integer $p_idx new location
759 */
760 function move($p_key, $p_idx)
761 {
762 // get current position of p_key
763 $cur_pos=$this->get_current_pos($p_key);
764
765 if ($cur_pos==$p_idx)
766 return;
767
768 if ($cur_pos<$p_idx)
769 {
770 $nb_order=count($this->a_order);
771 for ($i=0; $i<$nb_order; $i++)
772 {
773 // if col_name is not the searched one we continue
774 if ($this->a_order[$i]!=$p_key)
775 continue;
776 if ($p_idx==$i)
777 continue;
778 // otherwise we swap with i+1
779 $old=$this->a_order[$i+1];
780 $this->a_order[$i]=$this->a_order[$i+1];
781 $this->a_order[$i+1]=$p_key;
782 }
783 } else
784 {
785
786 $nb_order=count($this->a_order)-1;
787 for ($i=$nb_order; $i>0; $i--)
788 {
789 // if col_name is not the searched one we continue
790 if ($this->a_order[$i]!=$p_key)
791 continue;
792 if ($p_idx==$i)
793 continue;
794 // otherwise we swap with i+1
795 $old=$this->a_order[$i-1];
796 $this->a_order[$i]=$this->a_order[$i-1];
797 $this->a_order[$i-1]=$p_key;
798 }
799 }
800 }
801 public function get_button_add_top()
802 {
804 }
805
807 {
808 $this->button_add_top=$button_add_top;
809 return $this;
810 }
811 /**
812 * @brief execute the query (Data_SQL.seek), called by display_table
813 * @param string (default empty) $p_order SQL string added to DatabaseCore::seek
814 * @param array (default null) $p_array Array for the SQL string
815 * @see Data_SQL.seek
816 * @return pgsql resource
817 */
819 {
820 if ($p_order=="")
821 {
822 $p_order="order by {$this->table->primary_key}";
823 }
824 $ret=$this->table->seek($p_order, $p_array);
825 return $ret;
826 }
827 /**
828 * @brief display the data of the table
829 * @param $p_order is the cond or order of the rows,
830 * if empty the primary key will be used
831 * @param $p_array array of the bind variables
832 * @note the function create_js_script MUST be called before this function
833 */
834 function display_table($p_order="", $p_array=NULL)
835 {
838 if ($this->can_append_row()==TRUE && $this->button_add_top == true)
839 {
840 echo HtmlInput::button_action(" "._("Ajout"),
841 sprintf("%s.input('-1','%s')",
842 $this->object_name,
843 $this->object_name), "xx", "smallbutton", BUTTONADD);
844 }
845 $nb_order=count($this->a_order);
846 $virg=""; $result="";
847
848 // filter only on visible column
849 $visible=($this->icon_mod=='left')?1:0;
850 $visible=$visible+( ($this->icon_del=='left')?1:0);
851 for ($e=0; $e<$nb_order; $e++)
852 {
853 if ($this->get_property_visible($this->a_order[$e])==TRUE)
854 {
855 $result.=$virg."$visible";
856 $virg=",";
857 $visible++;
858 }
859 }
860 if ( $this->get_search_table() )
861 {
862 echo _('Cherche')." ".HtmlInput::filter_table("tb".$this->object_name, $result, 1);
863 }
864
865 // Set a sort on a column if sort_column is not empty
866 if ( $this->sort_column =="")
867 {
868 printf('<table class="result" id="tb%s">', $this->object_name);
869 } else {
870 printf('<table class="result sortable" id="tb%s">', $this->object_name);
871 }
872 $this->display_table_header();
873 echo '<tbody>';
874 for ($i=0; $i<$nb; $i++)
875 {
877 $this->display_row($row);
878 }
879 echo '</tbody>';
880 echo "</table>";
881 if ($this->can_append_row()==TRUE)
882 {
883 echo HtmlInput::button_action(" "._("Ajout"),
884 sprintf("%s.input('-1','%s')",
885 $this->object_name,
886 $this->object_name), "xx", "smallbutton", BUTTONADD);
887 }
888 printf('<script> alternate_row_color("tb%s");</script>',
889 $this->object_name);
890 }
891
892 /**
893 * @brief display the column header excepted the not visible one
894 * and in the order defined with $this->a_order
895 */
897 {
898 $nb=count($this->a_order);
899 echo '<thead>';
900 echo "<tr>";
901
902 if ($this->can_update_row() && $this->icon_mod=="left")
903 {
904 echo th(" ", 'style="width:40px" class="sorttable_nosort"');
905 }
906 if ($this->can_delete_row() && $this->icon_del=="left")
907 {
908 echo th(" ", 'style="width:40px" class="sorttable_nosort"');
909 }
910 for ($i=0; $i<$nb; $i++)
911 {
912
913 $key=$this->a_order[$i];
914 $sorted="";
915 if ( $key == $this->sort_column) {
916 $sorted=' class="sorttable_sorted"';
917 }
918
919 $style=$this->a_header_option[$key];
920 if ($this->get_property_visible($key)==true ) {
921 echo th("", $sorted.$style, $this->a_label_displaid[$key]);
922 }
923 }
924 if ($this->can_update_row() && $this->icon_mod=="right")
925 {
926 echo th(" ", 'style="width:40px" class="sorttable_nosort"');
927 }
928 if ($this->can_delete_row() && $this->icon_del=="right")
929 {
930 echo th(" ", 'style="width:40px" class="sorttable_nosort" ');
931 }
932 echo "</tr>";
933 echo '</thead>';
934 }
935 /**
936 * @brief set the column to sort by default
937 */
939 {
940 $this->sort_column=$p_col;
941 }
942 /**
943 * @brief return the column to sort
944 */
946 {
947 return $this->sort_column;
948 }
949
950 /**
951 * @brief set the id value of a data row and load from the db
952 */
953 function set_pk($p_id)
954 {
955 $this->table->set_pk_value($p_id);
956 $this->table->load();
957 }
958
959 /**
960 * @brief get the data from http request strip the not update or not visible data to their
961 * initial value. Before saving , it is important to set the pk and load from db
962 * @see set_pk
963 */
964 function from_request()
965 {
966 $nb=count($this->a_order);
967 $http=new HttpInput();
968 for ($i=0; $i<$nb; $i++)
969 {
970
971 $key=$this->a_order[$i];
972 if ($this->get_property_visible($key)==TRUE&&$this->get_property_updatable($key)
973 ==TRUE)
974 {
975 $v=$http->request($this->a_order[$i],"string","");
976 $this->table->$key=strip_tags($v);
977 }
978 }
979 }
980
981 function display_icon_mod($p_row)
982 {
983 if ($this->can_update_row())
984 {
985 echo "<td>";
986 $js=sprintf("%s.input('%s','%s');", $this->object_name,
987 $p_row[$this->table->primary_key], $this->object_name
988 );
989 echo Icon_Action::modify(uniqid(), $js);
990 echo "</td>";
991 }
992 }
993
994 function display_icon_del($p_row)
995 {
996 if ($this->can_delete_row())
997 {
998 echo "<td>";
999 $js=sprintf("%s.remove('%s','%s');", $this->object_name,
1000 $p_row[$this->table->primary_key], $this->object_name
1001 );
1002 echo Icon_Action::trash(uniqid(), $js);
1003 echo "</td>";
1004 }
1005 }
1006
1007 /**
1008 * @brief display a data row in the table, with the order defined
1009 * in a_order and depending of the visibility of the column, all the rows contains the attribute ctl_pk_id , to retrieve
1010 * in javascript , ie with the function afterSaveFct (see managetable.js)
1011 * @param array $p_row contains a row from the database
1012 * @see set_col_type
1013 * @see input_custom
1014 * @see display_table
1015 * @see display_row_custom
1016 * @see managetable.js
1017 */
1018 function display_row($p_row)
1019 {
1020
1021 $pk_id=$p_row[$this->table->primary_key];
1022 printf('<tr id="%s_%s" ctl_pk_id="%s">', $this->object_name,
1023 $pk_id,$pk_id)
1024 ;
1025
1026 if ($this->icon_mod=="left")
1027 $this->display_icon_mod($p_row);
1028 if ($this->icon_del=="left")
1029 $this->display_icon_del($p_row);
1030 if ( $this->icon_mod == "custom")
1031 $this->display_icon_custom($p_row);
1032
1033 $nb_order=count($this->a_order);
1034 for ($i=0; $i<$nb_order; $i++)
1035 {
1036 $this->current_row=$p_row;
1037 $v=$this->a_order[$i];
1038
1039 if ($i==0&&$this->icon_mod=="first"&&$this->can_update_row())
1040 {
1041 $js=sprintf("onclick=\"%s.input('%s','%s');\"", $this->object_name,
1042 $pk_id, $this->object_name);
1043 $td=($i == $this->col_sort ) ? sprintf('<td sorttable_customkey="X%s" class="%s">',
1044 $p_row[$v],$this->a_col_option[$v]):"<td>";
1045 echo $td.HtmlInput::anchor($p_row[$v], "", $js).'</td>';
1046 }
1047 elseif ( $i == $this->col_sort && $this->get_property_visible($v) )
1048 {
1049 if ( $this->get_col_type($v) == 'text') {
1050 echo td($p_row[$v],sprintf(' sorttable_customkey="X%s" ',$p_row[$v]));
1051 } elseif ( $this->get_col_type($v) == 'numeric') {
1052 echo td($p_row[$v],$this->a_col_option[$v]);
1053 } elseif ( $this->get_col_type($v) == 'numeric2') {
1054 echo td(nbm($p_row[$v],2),$this->a_col_option[$v]);
1055 } elseif ( $this->get_col_type($v) == 'numeric4') {
1056 echo td(nbm($p_row[$v],4),$this->a_col_option[$v]);
1057 } elseif ( $this->get_col_type($v) == 'numeric6') {
1058 echo td(nbm($p_row[$v],6),$this->a_col_option[$v]);
1059 } elseif ($this->get_col_type($v)=="custom") {
1060 // For custom col
1061 echo $this->display_row_custom($v,$p_row[$v],$pk_id);
1062 }else {
1063 echo td($p_row[$v],sprintf(' sorttable_customkey="X%s" ',$p_row[$v]),$this->a_col_option[$v]);
1064
1065 }
1066 }
1067 elseif ( ! $this->get_property_visible($v)) {
1068 continue;
1069 }
1070 else
1071 {
1072 if ($this->get_col_type($v)=="select")
1073 {
1074 /**
1075 * From database
1076 */
1077 $idx=$p_row[$v];
1078 /*
1079 * Check if index exists
1080 */
1081 $array_to_search=$this->a_select[$v];
1082 $value=$p_row[$v];
1083
1084 $nb_search=(is_array($array_to_search))?count($array_to_search):0;
1085 $found=FALSE;
1086 for ($e=0; $e<$nb_search; $e++)
1087 {
1088 if (isset($array_to_search[$e]['value'])&&$array_to_search[$e]['value']==$value)
1089 {
1090 $found=TRUE;
1091 echo td($array_to_search[$e]['label'],$this->a_col_option[$v]);
1092 }
1093 }
1094
1095 if (!$found)
1096 {
1097 echo td("--");
1098 }
1099 } elseif ($this->get_col_type($v)=="custom") {
1100 // For custom col
1101 echo $this->display_row_custom($v,$p_row[$v],$pk_id);
1102 } elseif ( $this->get_col_type($v) == 'numeric') {
1103 echo td($p_row[$v],$this->a_col_option[$v]);
1104 } elseif ( $this->get_col_type($v) == 'numeric2') {
1105 echo td(nbm($p_row[$v],2),$this->a_col_option[$v]);
1106 }elseif ( $this->get_col_type($v) == 'numeric4') {
1107 echo td(nbm($p_row[$v],4),$this->a_col_option[$v]);
1108 }elseif ( $this->get_col_type($v) == 'numeric6') {
1109 echo td(nbm($p_row[$v],6),$this->a_col_option[$v]);
1110 }
1111 else {
1112 echo td($p_row[$v], $this->a_col_option[$v]);
1113 }
1114 }
1115 }
1116 if ($this->icon_mod=="right")
1117 $this->display_icon_mod($p_row);
1118 if ($this->icon_del=="right")
1119 $this->display_icon_del($p_row);
1120
1121
1122
1123 echo '</tr>';
1124 }
1125 /**
1126 * Return the current row printed in display_row
1127 * @return array
1128 */
1129 public function get_current_row()
1130 {
1131 return $this->current_row;
1132 }
1133 /**
1134 * set the current row printed in display_row
1135 * @param type $current_row
1136 * @return this;
1137 */
1139 {
1140 $this->current_row=$current_row;
1141 return $this;
1142 }
1143
1144 /**
1145 * @brief When displaying a row, if a column has the type "custom" , we can call this function to display properly the value
1146 * including the tag "<td>".
1147 * You can get the full array from display_row via get_current_row() or reload from db thanks $p_id
1148 *
1149 * @param $p_key string key name
1150 * @param $p_value string value
1151 * @param int $p_id id of the row , usually the pk of Data_SQL (optional default 0)
1152 * @see input_custom
1153 * @see set_type
1154 * @note must return a string which will be in surrounded by td in the function display_row
1155 * @return string
1156 */
1157 function display_row_custom($p_key,$p_value,$p_id=0) {
1158 return td($p_value);
1159 }
1160 /**
1161 * @brief display into a dialog box the datarow in order
1162 * to be appended or modified. Can be override if you need
1163 * a more complex form or add elements with "set_order" before
1164 * calling this function.
1165 * This function does not add the form , only the table.
1166 *
1167 * It returns true , if it is not readyonly and the form will have a "save" button, if it returns nothing or false
1168 * then there is no save button, nor form, the content is then readonly
1169 *
1170 *@see get_error , set_error
1171 *
1172 */
1173 function input()
1174 {
1175 $nb_order=count($this->a_order);
1176 echo "<table>";
1177 for ($i=0; $i<$nb_order; $i++)
1178 {
1179 echo "<tr>";
1180 $key=$this->a_order[$i];
1181 $label=$this->a_label_displaid[$key];
1182 $value=$this->table->get($key);
1183 $error=$this->get_error($key);
1185 if ($this->get_property_visible($key)===TRUE)
1186 {
1187 // Label
1188 $info="";
1189 if ( isset($this->a_info[$key])) {
1190 $info=Icon_Action::infobulle($this->a_info[$key]);
1191 }
1192 // Label
1193 echo "<td> {$label} {$info} {$error}</td>";
1194
1195 if ($this->get_property_updatable($key)==TRUE)
1196 {
1197 echo "<td>";
1198 if ($this->a_type[$key]=="select")
1199 {
1200 $select=new ISelect($key);
1201 $select->value=$this->a_select[$key];
1202 $select->selected=$value;
1203 echo $select->input();
1204 }
1205 elseif ($this->a_type[$key]=="text")
1206 {
1207 $text=new IText($key);
1208 $text->value=$value;
1209 $min_size=(noalyss_strlen($value)<30)?30:strlen($value)+5;
1210 $text->size=$min_size;
1211 echo $text->input();
1212 }
1213 elseif ($this->a_type[$key]=="numeric") // number from db
1214 {
1215 $text=new INum($key);
1216 $text->value=$value;
1217 $min_size=(noalyss_strlen($value)<10)?10:strlen($value)+1;
1218 $text->size=$min_size;
1219 echo $text->input();
1220 }
1221 elseif ($this->a_type[$key]=="numeric2") // number from db
1222 {
1223 $text=new INum($key);
1224 $this->prec=2;
1225 $text->value=round($value??"0",2);
1226 $min_size=(noalyss_strlen($value)<10)?10:strlen($value)+1;
1227 $text->size=$min_size;
1228 echo $text->input();
1229 }
1230 elseif ($this->a_type[$key]=="numeric4") // number 4 decimale
1231 {
1232 $text=new INum($key);
1233 $text->prec=4;
1234 $text->value=round($value??"0",4);;
1235 $min_size=(noalyss_strlen($value)<10)?10:strlen($value)+1;
1236 $text->size=$min_size;
1237 echo $text->input();
1238 }
1239 elseif ($this->a_type[$key]=="numeric6") // number 6 decimale
1240 {
1241 $text=new INum($key);
1242 $text->prec=6;
1243 $text->value=round($value??"0",6);
1244 $min_size=(noalyss_strlen($value)<10)?10:strlen($value)+1;
1245 $text->size=$min_size;
1246 echo $text->input();
1247 }
1248 elseif ($this->a_type[$key]=="date")
1249 {
1250 $text=new IDate($key);
1251 $text->value=$value;
1252 $min_size=10;
1253 $text->size=$min_size;
1254 echo $text->input();
1255 } elseif ($this->a_type[$key]=="custom")
1256 {
1257 $this->input_custom($key,$value);
1258 }
1259 echo "</td>";
1260 }
1261 else
1262 {
1263 printf('<td>%s %s</td>', h($value),
1265 );
1266 }
1267 }
1268 echo "</tr>";
1269 }
1270 echo "</table>";
1271 return true;
1272 }
1273 /**
1274 * @brief this function let you create your own input , for example for a ITEXT , a IRADIO , ...
1275 * it must be override , there is not default
1276 * @code
1277 * function input_custom($p_key,$p_value) {
1278 * switch ($p_key) {
1279 * case 'name':
1280 * $w=new ICard($p_key,$p_value);
1281 * $w->input();
1282 * break;
1283 * }
1284 * }
1285 * @endcode
1286 * @param string $p_key name of the column
1287 * @param string $p_value current value
1288 * @return nothing
1289 */
1290 function input_custom($p_key,$p_value) {
1291 throw new Exception(__FILE__.":".__LINE__."- input_custom "._("non implémenté"));
1292 }
1293 /**
1294 * @brief Save the record from Request into the DB and returns an XML
1295 * to update the Html Element. The function check() will be called before saving
1296 * @see check
1297 * @return \DOMDocument
1298 */
1299 function ajax_save()
1300 {
1301
1302 $status="NOK";
1303 $xml=new DOMDocument('1.0', "UTF-8");
1304 try
1305 {
1306 // fill up object with $_REQUEST
1307 $this->from_request();
1308 // Check if the data are valid , if not then display the
1309 // input values with the error message
1310 //
1311 if ($this->check()==false)
1312 {
1313 $xml=$this->ajax_input("NOK");
1314 return $xml;
1315 }
1316 else
1317 {
1318 // Data are valid so we can save them
1319 $this->save();
1320 // compose the answer
1321 $status="OK";
1322 $s1=$xml->createElement("status", $status);
1323 $ctl=$this->object_name."_".$this->table->get_pk_value();
1324 $s2=$xml->createElement("ctl_row", $ctl);
1325 $s4=$xml->createElement("ctl", $this->object_name);
1326 $s5=$xml->createElement("ctl_pk_id", $this->table->get_pk_value());
1327 ob_start();
1328 $this->table->load();
1329 $array=$this->table->to_array();
1330 $this->display_row($array);
1331 $html=ob_get_contents();
1332 ob_end_clean();
1333 $s3=$xml->createElement("html");
1334 $t1=$xml->createTextNode($html);
1335 $s3->appendChild($t1);
1336 }
1337
1338 $root=$xml->createElement("data");
1339 $root->appendChild($s1);
1340 $root->appendChild($s2);
1341 $root->appendChild($s3);
1342 $root->appendChild($s4);
1343 $root->appendChild($s5);
1344 $xml->appendChild($root);
1345 }
1346 catch (Exception $ex)
1347 {
1348 $s1=$xml->createElement("status", "NOK");
1349 $s2=$xml->createElement("ctl_row",
1350 $this->object_name."_".$this->table->get_pk_value());
1351 $s4=$xml->createElement("ctl", $this->object_name);
1352 $s3=$xml->createElement("html", $ex->getTraceAsString());
1353 $root=$xml->createElement("data");
1354 $root->appendChild($s1);
1355 $root->appendChild($s2);
1356 $root->appendChild($s3);
1357 $root->appendChild($s4);
1358 $root->appendChild($s5);
1359 $xml->appendChild($root);
1360 }
1361 return $xml;
1362 }
1363
1364 /**
1365 * @brief send an xml with input of the object, create an xml answer. It will call Manage_Table_SQL.input to
1366 * display the input , but if that function returns false, the "save" button will disappear but the form can be
1367 * submitted with enter.
1368 *
1369 * @see input
1370 * XML tag
1371 * - status : OK , NOK
1372 * - ctl : Dom id to update
1373 * - content : Html answer
1374 * @return DomDocument
1375 */
1376 function ajax_input($p_status="OK")
1377 {
1378 $xml=new DOMDocument("1.0", "UTF-8");
1379 $xml->createElement("status", $p_status);
1380 try
1381 {
1382 $status=$p_status;
1383
1384 ob_start();
1385
1386 echo HtmlInput::title_box($this->getTitle(), $this->dialog_box,"close","","y","y");
1387 printf('<form id="frm%s_%s" method="POST" onsubmit="%s.save(\'frm%s_%s\');return false;">',
1388 $this->object_name, $this->table->get_pk_value(),
1389 $this->object_name, $this->object_name,
1390 $this->table->get_pk_value());
1391 $can_update=$this->input();
1392 $can_update =( $can_update===false) ? false:true;
1393 // JSON param to hidden
1394 echo HtmlInput::json_to_hidden($this->json_parameter);
1395 echo HtmlInput::hidden("p_id", $this->table->get_pk_value());
1396 // button Submit and cancel
1397 $close=sprintf("\$('%s').remove()", $this->dialog_box);
1398 // display error if any
1399 $this->display_error();
1400 echo '<ul class="aligned-block">';
1401 // form readonly
1402 if ( $can_update ) {
1403 echo '<li>',
1404 HtmlInput::submit('update', _("Sauver")),
1405 '</li>';
1406 }
1407 echo '<li>',
1408 HtmlInput::button_action(_("Annuler"), $close, "", "smallbutton"),
1409 '</li>',
1410 '</ul>';
1411 echo "</form>";
1412
1413
1414 $html=ob_get_contents();
1415 ob_end_clean();
1416
1417 $s1=$xml->createElement("status", $status);
1418 $ctl=$this->object_name."_".$this->table->get_pk_value();
1419 $s2=$xml->createElement("ctl_row", $ctl);
1420 $s4=$xml->createElement("ctl", $this->object_name);
1421 $s3=$xml->createElement("html");
1422 $s5=$xml->createElement("ctl_pk_id", $this->table->get_pk_value());
1423 $t1=$xml->createTextNode($html);
1424 $s3->appendChild($t1);
1425
1426 $root=$xml->createElement("data");
1427 $root->appendChild($s1);
1428 $root->appendChild($s2);
1429 $root->appendChild($s3);
1430 $root->appendChild($s4);
1431 $root->appendChild($s5);
1432
1433 }
1434 catch (Exception $ex)
1435 {
1436 $s1=$xml->createElement("status", "NOK");
1437 $s3=$xml->createElement("ctl", $this->object_name);
1438 $s2=$xml->createElement("ctl_row",
1439 $this->object_name."_".$this->table->get_pk_value());
1440 $s4=$xml->createElement("html", $ex->getTraceAsString());
1441 $s5=$xml->createElement("ctl_pk_id", $this->table->get_pk_value());
1442 $root=$xml->createElement("data");
1443 $root->appendChild($s1);
1444 $root->appendChild($s2);
1445 $root->appendChild($s3);
1446 $root->appendChild($s4);
1447 $root->appendChild($s5);
1448
1449
1450 }
1451 $xml->appendChild($root);
1452 return $xml;
1453 }
1454
1455 /**
1456 * @brief delete a datarow , the id must be have set before
1457 * @see from_request
1458 */
1459 function delete()
1460 {
1461 $this->table->delete();
1462 }
1463
1464 /**
1465 * Delete a record and return an XML answer for ajax. If a check is needed before
1466 * deleting you can override this->delete and throw an exception if the deleting
1467 * is not allowed
1468 * @return \DOMDocument
1469 */
1470 function ajax_delete()
1471 {
1472 $status="NOK";
1473 $xml=new DOMDocument('1.0', "UTF-8");
1474 try
1475 {
1476 $this->delete();
1477 $status="OK";
1478 $s1=$xml->createElement("status", $status);
1479 $ctl=$this->object_name."_".$this->table->get_pk_value();
1480 $s2=$xml->createElement("ctl_row", $ctl);
1481 $s3=$xml->createElement("html", _("Effacé"));
1482 $s4=$xml->createElement("ctl", $this->object_name);
1483
1484 $root=$xml->createElement("data");
1485 $root->appendChild($s1);
1486 $root->appendChild($s2);
1487 $root->appendChild($s3);
1488 $root->appendChild($s4);
1489 }
1490 catch (Exception $ex)
1491 {
1492 $s1=$xml->createElement("status", "NOK");
1493 $s2=$xml->createElement("ctl",
1494 $this->object_name."_".$this->table->get_pk_value());
1495 $s3=$xml->createElement("html", $ex->getMessage());
1496 $s4=$xml->createElement("ctl", $this->object_name);
1497
1498 $root=$xml->createElement("data");
1499 $root->appendChild($s1);
1500 $root->appendChild($s2);
1501 $root->appendChild($s3);
1502 $root->appendChild($s4);
1503 }
1504 $xml->appendChild($root);
1505 return $xml;
1506 }
1507
1508 /**
1509 * @brief save the Data_SQL Object
1510 * The noalyss_SQL is not empty
1511 * @see from_request
1512 */
1513 function save()
1514 {
1515 if ($this->table->exist()==0)
1516 {
1517 $this->table->insert();
1518 }
1519 else
1520 {
1521 $this->table->update();
1522 }
1523 }
1524
1525 /**
1526 * @brief insert a new value
1527 * @see set_pk_value
1528 * @see from_request
1529 */
1530 function insert()
1531 {
1532 $this->table->insert();
1533 }
1534
1535 /**
1536 * @brief
1537 * @see set_pk_value
1538 * @see from_request
1539 */
1540 function update()
1541 {
1542 $this->table->update();
1543 }
1544
1545 /**
1546 * @brief
1547 * @see set_pk_value
1548 * @see from_request
1549 */
1550 function set_value($p_key, $p_value)
1551 {
1552 $this->table->set($p_key, $p_value);
1553 }
1554
1555 /**
1556 * Display a list of the error collected
1557 * @see get_error set_error
1558 *
1559 */
1560 function display_error()
1561 {
1562 $nb_order=count($this->a_order);
1563 if (count($this->aerror)==0)
1564 return;
1565 echo "<span class=\"notice\">Liste erreurs :</span>";
1566 for ($i=0; $i<$nb_order; $i++)
1567 {
1568 $key=$this->a_order[$i];
1569 $label=$this->a_label_displaid[$key];
1570 $error=$this->get_error($key);
1571 $error=($error=="")?"":"<span class=\"notice\" style=\"font-weight:normal;font-style:normal;display:block\">".h($label)." : ".h($this->get_error($key))."</span>";
1572
1573 echo $error;
1574 }
1575 echo "</ul>";
1576 }
1577
1578 /**
1579 * @brief usually contain a link and calls another page, it must be overriden
1580 * @param array $p_row is the current database row
1581 * @return void
1582 */
1583 function display_icon_custom($p_row)
1584 {
1585 echo '<td>'.'<a href="#">';
1586 print_r($p_row);
1587 echo '</a></td>';
1588 }
1589}
noalyss_strlen($p_string)
Definition: ac_common.php:1541
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
if(headers_sent() &&DEBUGNOALYSS > 0) $html
h( $row[ 'oa_description'])
$idx
switch($op2) $xml
Definition: ajax_card.php:806
$ex
Definition: balance.inc.php:45
this an abstract class , all the SQL class, like noalyss_sql (table), Acc_Plan_SQL (based on a SQL no...
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
static id()
return the 'gDossier' value after a check
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_action($action, $javascript, $id=NULL, $p_class="button", $p_symbole="")
button Html with javascript
static hidden($p_name, $p_value, $p_id="")
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 errorbulle($p_comment)
static json_to_hidden($p_json)
transform a json to hidden
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
manage the http input (get , post, request) and extract from an array
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: idate.class.php:34
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:42
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input.
Definition: itext.class.php:30
static modify($p_id, $p_javascript)
Display the icon to modify a idem.
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
static trash($p_id, $p_javascript)
Display the icon of a trashbin.
Purpose is to propose a librairy to display a table content and allow to update and delete row ,...
$dialogbox_style
style of the dialog box
display_row($p_row)
display a data row in the table, with the order defined in a_order and depending of the visibility of...
move($p_key, $p_idx)
if we change a column order , the order of the other columns is impacted.
set_icon_mod($pString)
Set the icon to modify at the right ,the first col or left of the row, if the mod if custom ,...
ajax_input($p_status="OK")
send an xml with input of the object, create an xml answer.
insert()
insert a new value
$row_delete
Flag to indicate if rows can be deleted.
count_error()
returns the nb of errors found
display_icon_custom($p_row)
usually contain a link and calls another page, it must be overriden
get_col_sort()
When adding an element , it is column we checked to insert before,.
set_delete_row($p_value)
Enable or disable the deletion of rows.
$a_type
Type of the column : date , select ... Only in input.
$json_parameter
Default parameter to add (gDossier...), sent to the ajax callback.
$a_prop
property for each col.
set_append_row($p_value)
Enable or disable the appending of rows.
$cssclass
< give the title of the diabox , default is Data
get_property_updatable($p_key)
return True if the column is updatable otherwise false
$a_info
Array with the infotip.
$col_sort
when inserting, it is the column to sort,-1 to disable it and append only
can_delete_row()
return false if the delete of the row is forbidden
get_current_pos($p_key)
get the position of a column
input_custom($p_key, $p_value)
this function let you create your own input , for example for a ITEXT , a IRADIO ,...
set_col_sort($p_num)
When adding an element ,we place it thanks the DOM Attribute sort_value set it to -1 if you want one ...
$icon_mod
place of right or left the icon update or mod, default right, accepted value=left,...
$dialog_box
ID of the dialog box which display the result of the ajax calls.
ajax_delete()
Delete a record and return an XML answer for ajax.
set_value($p_key, $p_value)
$aerror
Array containing the error of the input data.
$a_label_displaid
Label of the col. of the datarow.
set_property_updatable($p_key, $p_value)
set a column of the data row updatable or not
$a_select
Possible value if a_type is a SELECT.
param_set($p_json)
Set the parameter of the object (gDossier, ac, plugin_code...) @detail By default ,...
can_append_row()
return false if the append of the row is forbidden
$object_name
Object_name is used for the javascript , it is the row id to update or delete.
set_json($p_json)
Set the parameter of the object (gDossier, ac, plugin_code...) @detail By default ,...
set_col_tips($p_key, $p_comment)
Set the info for a column, use Icon_Action::infobulle the message are in message_javascript....
$current_row
CSS class for the dialog box.
set_col_type($p_key, $p_value, $p_array=NULL)
set the type of a column , it will change in the input db box , the select must supply an array of po...
set_table(Data_SQL $p_noalyss_sql)
set_header_option($p_key, $p_value)
add extra to column Header, normally class or style
set_object_name($p_object_name)
Set the object_name.
get_property_visible($p_key)
return True if the column is visible otherwise false
create_js_script()
we must create first the javascript if we want to update, insert or delete rows.
set_pk($p_id)
set the id value of a data row and load from the db
$search_table
boolean , by default true ,it is possible to search in the table,
set_col_option($p_key, $p_value)
add extra to column, normally class or style
$row_update
Flag to indicate if rows can be updated.
execute_query($p_order="", $p_array=NULL)
execute the query (Data_SQL.seek), called by display_table
$icon_del
place of right or left the icon update or mod, default right, accepted value=left,...
get_error($p_col)
retrieve the error message
get_current_row()
Return the current row printed in display_row.
get_search_table()
Get if we can search in the table.
set_dialogbox_style($db_style)
Dialog box style , by default {position: "fixed", top: '15', width: "auto", "margin-left": "20%"}.
$row_append
Flag to indicate if rows can be added.
$a_header_option
Extra to add to the column Header : CSS Style , CSS class, javascript ,...
get_dialogbox_style()
return the db_style
can_update_row()
return false if the update of the row is forbidden
save()
save the Data_SQL Object The noalyss_SQL is not empty
set_search_table($search_table)
Set the table searchable or not.
get_col_option($p_key)
add extra to column, normally class , javascript or style
display_table_header()
display the column header excepted the not visible one and in the order defined with $this->a_order
setTitle($p_title)
Set the title of the diabox , default is Donnée.
set_update_row($p_value)
Enable or disable the updating of rows.
$sort_column
javascript sort on this column , if empty there is no js sort
display_table($p_order="", $p_array=NULL)
display the data of the table
from_request()
get the data from http request strip the not update or not visible data to their initial value.
$button_add_top
place of the button add on the top, by default true
set_sort_column($p_col)
set the column to sort by default
display_row_custom($p_key, $p_value, $p_id=0)
When displaying a row, if a column has the type "custom" , we can call this function to display prope...
set_current_row($current_row)
set the current row printed in display_row
$callback
Callback function.
add_json_param($p_attribute, $p_value)
Add json parameter to the current one.
display_error()
Display a list of the error collected.
__construct(Data_SQL $p_table)
set_callback($p_file)
set the callback function that is passed to javascript
ajax_save()
Save the record from Request into the DB and returns an XML to update the Html Element.
set_property_visible($p_key, $p_value)
set a column of the data row visible or not
get_header_option($p_key)
add extra to column Header, normally class , javascript or style
input()
display into a dialog box the datarow in order to be appended or modified.
set_error($p_col, $p_message)
set the error message for a wrong input
get_col_type($p_key)
return the type of a column
$a_col_option
in display_row and display_custom_row, it is the current row which is used
set_col_label($p_key, $p_display)
set the name to display for a column
get_sort_column()
return the column to sort
set_icon_del($pString)
Set the icon to delete at the right or left of the row.
send_header()
send the XML headers for the ajax call
set_button_add_top($button_add_top)
get_js_variable()
Get the object name.
$all table
$anc_filter title
const BUTTONADD
Definition: constant.php:102
$max_email_input prec
if( $delta< 0) elseif( $delta==0)