Go to the documentation of this file.
108 $this->
table=$p_table;
113 $this->a_label_displaid[
$value]=$key;
117 $this->a_select[
$value]=
null;
118 $this->a_col_option[
$value]=
"";
119 $this->a_header_option[
$value]=
"";
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"));
130 $this->icon_mod=
"right";
131 $this->icon_del=
"right";
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";
144 $this->cssclass=$p_class;
155 $this->
title=$p_title;
186 header(
'Content-type:text/xml;charset="UTF-8"');
205 $this->dialogbox_style = $db_style;
244 $this->a_info[$p_key]=$p_comment;
254 $this->col_sort=$p_num;
271 $this->
table=$p_noalyss_sql;
280 throw new Exception(
"set_order, parameter is not an array");
291 $this->aerror[$p_col]=$p_message;
298 return count($this->aerror);
308 if (isset($this->aerror[$p_col]))
309 return $this->aerror[$p_col];
362 if (!isset($this->a_type[$p_key]))
363 throw new Exception(
"invalid key $p_key");
365 return $this->a_col_option[$p_col];
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;
395 if (!isset($this->a_type[$p_key]))
396 throw new Exception(
"invalid key $p_key");
398 return $this->a_header_option[$p_col];
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;
427 if (!isset($this->a_type[$p_key]))
428 throw new Exception(
"invalid key $p_key");
430 if (!in_array($p_value,
431 array(
"text",
"numeric",
"date",
"select",
"timestamp",
"custom")))
432 throw new Exception(
"invalid type $p_value");
434 $this->a_type[$p_key]=$p_value;
436 if ( $p_value ==
"numeric" && $this->a_col_option[$p_key]==
"") {
437 $this->a_col_option[$p_key]=
' class="num" ';
449 if (!isset($this->a_type[$p_key]))
450 throw new Exception(
"invalid key");
452 return $this->a_type[$p_key];
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);
500 $this->json_parameter=$p_json;
509 $this->callback=$p_file;
518 $style=json_encode($this->dialogbox_style);
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}\";
535 if (
$error ==
"") {
return "";}
545 $this->object_name=$p_object_name;
555 if (! isset($this->a_prop[$p_key]))
556 throw new Exception(__FILE__.
":".__LINE__.
"$p_key invalid index");
561 elseif ($p_value==True)
564 throw new Exception(
"set_property_updatable [ $p_value ] incorrect");
582 if ($pString !=
"right" && $pString !=
"left" && $pString!=
"first")
583 throw new Exception(
'set_icon_mod invalide '.$pString);
584 $this->icon_mod=$pString;
592 if ($pString !=
"right" && $pString !=
"left" )
593 throw new Exception(
'set_icon_del invalide '.$pString);
594 $this->icon_del=$pString;
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;
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;
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;
653 if (
$val==self::UPDATABLE)
665 if (!isset ($this->a_prop[$p_key]) )
666 throw new Exception(__FILE__.
":".__LINE__.
"$p_key invalid index");
672 elseif ($p_value==True)
675 throw new Exception(
"set_property_updatable [ $p_value ] incorrect");
685 if (
$val===self::VISIBLE)
698 $this->a_label_displaid[$p_key]=$p_display;
707 $nb_order=count($this->a_order);
708 for (
$i=0;
$i<$nb_order;
$i++)
709 if ($this->a_order[
$i]==$p_key)
711 throw new Exception(
"COL INVAL ".$p_key);
729 if ($cur_pos==$p_idx)
734 $nb_order=count($this->a_order);
735 for (
$i=0;
$i<$nb_order;
$i++)
738 if ($this->a_order[
$i]!=$p_key)
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;
750 $nb_order=count($this->a_order)-1;
751 for (
$i=$nb_order;
$i>0;
$i--)
754 if ($this->a_order[
$i]!=$p_key)
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;
786 $p_order=
"order by {$this->table->primary_key}";
802 if ($this->
can_append_row()==TRUE && $this->button_add_top ==
true)
805 sprintf(
"%s.input('-1','%s')",
807 $this->object_name),
"xx",
"smallbutton",
BUTTONADD);
809 $nb_order=count($this->a_order);
813 for (
$e=0;
$e<$nb_order;
$e++)
828 if ( $this->sort_column ==
"")
830 printf(
'<table class="result" id="tb%s">', $this->object_name);
832 printf(
'<table class="result sortable" id="tb%s">', $this->object_name);
846 sprintf(
"%s.input('-1','%s')",
848 $this->object_name),
"xx",
"smallbutton",
BUTTONADD);
850 printf(
'<script> alternate_row_color("tb%s");</script>',
860 $nb=count($this->a_order);
866 echo
th(
" ",
'style="width:40px" class="sorttable_nosort"');
870 echo
th(
" ",
'style="width:40px" class="sorttable_nosort"');
875 $key=$this->a_order[
$i];
877 if ( $key == $this->sort_column) {
878 $sorted=
' class="sorttable_sorted"';
881 $style=$this->a_header_option[$key];
883 echo
th(
"", $sorted.$style, $this->a_label_displaid[$key]);
888 echo
th(
" ",
'style="width:40px" class="sorttable_nosort"');
892 echo
th(
" ",
'style="width:40px" class="sorttable_nosort" ');
902 $this->sort_column=$p_col;
918 $this->
table->load();
928 $nb=count($this->a_order);
933 $key=$this->a_order[
$i];
937 $v=
$http->request($this->a_order[
$i],
"string",
"");
938 $this->
table->$key=strip_tags($v);
948 $js=sprintf(
"%s.input('%s','%s');", $this->object_name,
949 $p_row[$this->
table->primary_key], $this->object_name
961 $js=sprintf(
"%s.remove('%s','%s');", $this->object_name,
962 $p_row[$this->
table->primary_key], $this->object_name
981 $pk_id=$p_row[$this->
table->primary_key];
982 printf(
'<tr id="%s_%s">', $this->object_name,
986 if ($this->icon_mod==
"left")
988 if ($this->icon_del==
"left")
991 $nb_order=count($this->a_order);
992 for (
$i=0;
$i<$nb_order;
$i++)
994 $this->current_row=$p_row;
995 $v=$this->a_order[
$i];
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>';
1008 echo
td($p_row[$v],sprintf(
' sorttable_customkey="X%s" ',$p_row[$v]));
1010 echo
td($p_row[$v],$this->a_col_option[$v],$p_row[$v]);
1015 echo
td($p_row[$v],sprintf(
' sorttable_customkey="X%s" ',$p_row[$v]),$this->a_col_option[$v]);
1033 $array_to_search=$this->a_select[$v];
1036 $nb_search=(is_array($array_to_search))?count($array_to_search):0;
1038 for (
$e=0;
$e<$nb_search;
$e++)
1040 if (isset($array_to_search[
$e][
'value'])&&$array_to_search[
$e][
'value']==
$value)
1043 echo
td($array_to_search[
$e][
'label'],$this->a_col_option[$v]);
1056 echo
td($p_row[$v], $this->a_col_option[$v]);
1060 if ($this->icon_mod==
"right")
1062 if ($this->icon_del==
"right")
1102 return td($p_value);
1119 $nb_order=count($this->a_order);
1121 for (
$i=0;
$i<$nb_order;
$i++)
1124 $key=$this->a_order[
$i];
1125 $label=$this->a_label_displaid[$key];
1133 if ( isset($this->a_info[$key])) {
1137 echo
"<td> {$label} {$info} {$error}</td>";
1142 if ($this->a_type[$key]==
"select")
1145 $select->value=$this->a_select[$key];
1149 elseif ($this->a_type[$key]==
"text")
1154 $text->size=$min_size;
1155 echo
$text->input();
1157 elseif ($this->a_type[$key]==
"numeric")
1162 $text->size=$min_size;
1163 echo
$text->input();
1165 elseif ($this->a_type[$key]==
"numeric4")
1171 $text->size=$min_size;
1172 echo
$text->input();
1174 elseif ($this->a_type[$key]==
"numeric6")
1180 $text->size=$min_size;
1181 echo
$text->input();
1183 elseif ($this->a_type[$key]==
"date")
1188 $text->size=$min_size;
1189 echo
$text->input();
1190 } elseif ($this->a_type[$key]==
"custom")
1198 printf(
'<td>%s %s</td>',
h(
$value),
1226 throw new Exception(__FILE__.
":".__LINE__.
"-"._(
"non implémenté"));
1238 $xml=
new DOMDocument(
'1.0',
"UTF-8");
1246 if ($this->
check()==
false)
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);
1262 $this->
table->load();
1265 $html=ob_get_contents();
1267 $s3=
$xml->createElement(
"html");
1269 $s3->appendChild($t1);
1273 $root->appendChild($s1);
1274 $root->appendChild($s2);
1275 $root->appendChild($s3);
1276 $root->appendChild($s4);
1279 catch (Exception
$ex)
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());
1287 $root->appendChild($s1);
1288 $root->appendChild($s2);
1289 $root->appendChild($s3);
1290 $root->appendChild($s4);
1310 $xml=
new DOMDocument(
"1.0",
"UTF-8");
1311 $xml->createElement(
"status", $p_status);
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;
1329 $close=sprintf(
"\$('%s').remove()", $this->dialog_box);
1332 echo
'<ul class="aligned-block">';
1334 if ( $can_update ) {
1346 $html=ob_get_contents();
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");
1355 $s3->appendChild($t1);
1358 $root->appendChild($s1);
1359 $root->appendChild($s2);
1360 $root->appendChild($s3);
1361 $root->appendChild($s4);
1363 catch (Exception
$ex)
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());
1372 $root->appendChild($s1);
1373 $root->appendChild($s2);
1374 $root->appendChild($s3);
1375 $root->appendChild($s4);
1387 $this->
table->delete();
1399 $xml=
new DOMDocument(
'1.0',
"UTF-8");
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);
1411 $root->appendChild($s1);
1412 $root->appendChild($s2);
1413 $root->appendChild($s3);
1414 $root->appendChild($s4);
1416 catch (Exception
$ex)
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);
1425 $root->appendChild($s1);
1426 $root->appendChild($s2);
1427 $root->appendChild($s3);
1428 $root->appendChild($s4);
1441 if ($this->
table->exist()==0)
1443 $this->
table->insert();
1447 $this->
table->update();
1458 $this->
table->insert();
1468 $this->
table->update();
1478 $this->
table->set($p_key, $p_value);
1488 $nb_order=count($this->a_order);
1489 if (count($this->aerror)==0)
1491 echo
"<span class=\"notice\">Liste erreurs :</span>";
1492 for (
$i=0;
$i<$nb_order;
$i++)
1494 $key=$this->a_order[
$i];
1495 $label=$this->a_label_displaid[$key];
1497 $error=(
$error==
"")?
"":
"<span class=\"notice\" style=\"font-weight:normal;font-style:normal;display:block\">".
h(
$label).
" : ".
h($this->
get_error($key)).
"</span>";
$a_type
Type of the column : date , select ... Only in input.
h( $row[ 'oa_description'])
save()
save the Data_SQL Object The noalyss_SQL is not empty
create_js_script()
we must create first the javascript if we want to update, insert or delete rows.
can_delete_row()
return false if the delete of the row is forbidden
This class handles only the numeric input, the input will call a javascript to change comma to period...
display_row($p_row)
display a data row in the table, with the order defined in a_order and depending of the visibility of...
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...
__construct(Data_SQL $p_table)
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
get_header_option($p_key)
add extra to column Header, normally class , javascript or style
count_error()
returns the nb of errors found
get_dialogbox_style()
return the db_style
setTitle($p_title)
Set the title of the diabox , default is Donnée.
set_dialogbox_style($db_style)
Dialog box style , by default {position: "fixed", top: '15', width: "auto", "margin-left": "20%"}.
get_property_visible($p_key)
return True if the column is visible otherwise false
$search_table
boolean , by default true ,it is possible to search in the table,
set_icon_del($pString)
Set the icon to delete at the right or left of the row.
$row_delete
Flag to indicate if rows can be deleted.
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
$row_append
Flag to indicate if rows can be added.
set_update_row($p_value)
Enable or disable the updating of rows.
set_property_updatable($p_key, $p_value)
set a column of the data row updatable or not
$current_row
CSS class for the dialog box.
$aerror
Array containing the error of the input data.
set_object_name($p_object_name)
Set the object_name.
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 ,...
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
set_value($p_key, $p_value)
$sort_column
javascript sort on this column , if empty there is no js sort
$icon_del
place of right or left the icon update or mod, default right, accepted value=left,...
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_sort_column($p_col)
set the column to sort by default
param_set($p_json)
Set the parameter of the object (gDossier, ac, plugin_code...) @detail By default ,...
set_search_table($search_table)
Set the table searchable or not.
ajax_input($p_status="OK")
send an xml with input of the object, create an xml answer.
display_table($p_order="", $p_array=NULL)
display the data of the table
$object_name
Object_name is used for the javascript , it is the row id to update or delete.
insert()
insert a new value
set_pk($p_id)
set the id value of a data row and load from the db
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
add_json_param($p_attribute, $p_value)
Add json parameter to the current one.
$col_sort
when inserting, it is the column to sort,-1 to disable it and append only
get_sort_column()
return the column to sort
set_error($p_col, $p_message)
set the error message for a wrong input
set_json($p_json)
Set the parameter of the object (gDossier, ac, plugin_code...) @detail By default ,...
set_delete_row($p_value)
Enable or disable the deletion of rows.
$cssclass
< give the title of the diabox , default is Data
$dialog_box
ID of the dialog box which display the result of the ajax calls.
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 ...
get_error($p_col)
retrieve the error message
set_append_row($p_value)
Enable or disable the appending of rows.
$icon_mod
place of right or left the icon update or mod, default right, accepted value=left,...
move($p_key, $p_idx)
if we change a column order , the order of the other columns is impacted.
static num_row($ret)
wrapper for the function pg_NumRows
$dialogbox_style
style of the dialog box
if(headers_sent() &&DEBUGNOALYSS > 0) $html
get_col_option($p_key)
add extra to column, normally class , javascript or style
set_table(Data_SQL $p_noalyss_sql)
static modify($p_id, $p_javascript)
Display the icon to modify a idem.
set_current_row($current_row)
set the current row printed in display_row
get_current_row()
Return the current row printed in display_row.
set_col_option($p_key, $p_value)
add extra to column, normally class or style
set_button_add_top($button_add_top)
set_dialog_box($dialog_box)
execute_query($p_order="", $p_array=NULL)
execute the query (Data_SQL.seek), called by display_table
set_col_label($p_key, $p_display)
set the name to display for a column
static id()
return the $_REQUEST['gDossier'] after a check
$a_col_option
in display_row and display_custom_row, it is the current row which is used
$a_prop
property for each col.
get_search_table()
Get if we can search in the table.
set_icon_mod($pString)
Set the icon to modify at the right ,the first col or left of the row.
$a_header_option
Extra to add to the column Header : CSS Style , CSS class, javascript ,...
get_col_type($p_key)
return the type of a column
can_update_row()
return false if the update of the row is forbidden
display_error()
Display a list of the error collected.
$button_add_top
place of the button add on the top, by default true
get_js_variable()
Get the object name.
th($p_string, $p_extra='', $raw='')
display_table_header()
display the column header excepted the not visible one and in the order defined with $this->a_order
td($p_string='', $p_extra='')
surround the string with td
input()
display into a dialog box the datarow in order to be appended or modified.
$a_info
Array with the infotip.
from_request()
get the data from http request strip the not update or not visible data to their initial value.
get_col_sort()
When adding an element , it is column we checked to insert before,.
set_header_option($p_key, $p_value)
add extra to column Header, normally class or style
$json_parameter
Default parameter to add (gDossier...), sent to the ajax callback.
input_custom($p_key, $p_value)
this function let you create your own input , for example for a ITEXT , a IRADIO ,...
$a_label_displaid
Label of the col. of the datarow.
$row_update
Flag to indicate if rows can be updated.
$a_select
Possible value if a_type is a SELECT.
send_header()
send the XML headers for the ajax call
this an abstract class , all the SQL class, like noalyss_sql (table), Acc_Plan_SQL (based on a SQL no...
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
can_append_row()
return false if the append of the row is forbidden
get_property_updatable($p_key)
return True if the column is updatable otherwise false
ajax_delete()
Delete a record and return an XML answer for ajax.
set_col_tips($p_key, $p_comment)
Set the info for a column, use Icon_Action::infobulle the message are in message_javascript....
set_callback($p_file)
set the callback function that is passed to javascript
get_current_pos($p_key)
get the position of a column