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