143 $this->
table=$p_table;
148 $this->a_label_displaid[
$value]=$key;
152 $this->a_select[
$value]=
null;
153 $this->a_col_option[
$value]=
"";
154 $this->a_header_option[
$value]=
"";
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"));
165 $this->icon_mod=
"right";
166 $this->icon_del=
"right";
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";
179 $this->cssclass=$p_class;
190 $this->
title=$p_title;
221 header(
'Content-type:text/xml;charset="UTF-8"');
240 $this->dialogbox_style = $db_style;
279 $this->a_info[$p_key]=$p_comment;
289 $this->col_sort=$p_num;
306 $this->
table=$p_noalyss_sql;
315 throw new Exception(
"set_order, parameter is not an array");
326 $this->aerror[
$p_col]=$p_message;
333 return count($this->aerror);
343 if (isset($this->aerror[
$p_col]))
344 return $this->aerror[
$p_col];
397 if (!isset($this->a_type[$p_key]))
398 throw new Exception(
"invalid key $p_key");
400 return $this->a_col_option[
$p_col];
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;
430 if (!isset($this->a_type[$p_key]))
431 throw new Exception(
"invalid key $p_key");
433 return $this->a_header_option[
$p_col];
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;
462 if (!isset($this->a_type[$p_key]))
463 throw new Exception(
"invalid key $p_key");
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");
469 $this->a_type[$p_key]=$p_value;
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" ';
484 if (!isset($this->a_type[$p_key]))
485 throw new Exception(
"invalid key");
487 return $this->a_type[$p_key];
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);
535 $this->json_parameter=$p_json;
544 $this->callback=$p_file;
553 $style=json_encode($this->dialogbox_style);
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}\";
570 if (
$error ==
"") {
return "";}
580 $this->object_name=$p_object_name;
590 if (! isset($this->a_prop[$p_key]))
591 throw new Exception(__FILE__.
":".__LINE__.
"$p_key invalid index");
599 throw new Exception(
"set_property_updatable [ $p_value ] incorrect");
618 if (! in_array( $pString ,[
'right',
'left',
'custom',
'first'] ) )
619 throw new Exception(
'set_icon_mod invalide '.$pString);
620 $this->icon_mod=$pString;
628 if ($pString !=
"right" && $pString !=
"left" )
629 throw new Exception(
'set_icon_del invalide '.$pString);
630 $this->icon_del=$pString;
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;
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;
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;
689 if (
$val==self::UPDATABLE)
701 if (!isset ($this->a_prop[$p_key]) )
702 throw new Exception(__FILE__.
":".__LINE__.
"$p_key invalid index");
711 throw new Exception(
"set_property_updatable [ $p_value ] incorrect");
721 if (
$val===self::VISIBLE)
734 $this->a_label_displaid[$p_key]=$p_display;
743 $nb_order=count($this->a_order);
744 for (
$i=0;
$i<$nb_order;
$i++)
745 if ($this->a_order[
$i]==$p_key)
747 throw new Exception(
"COL INVAL ".$p_key);
765 if ($cur_pos==$p_idx)
770 $nb_order=count($this->a_order);
771 for (
$i=0;
$i<$nb_order;
$i++)
774 if ($this->a_order[
$i]!=$p_key)
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;
786 $nb_order=count($this->a_order)-1;
787 for (
$i=$nb_order;
$i>0;
$i--)
790 if ($this->a_order[
$i]!=$p_key)
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;
822 $p_order=
"order by {$this->table->primary_key}";
838 if ($this->
can_append_row()==TRUE && $this->button_add_top ==
true)
841 sprintf(
"%s.input('-1','%s')",
843 $this->object_name),
"xx",
"smallbutton",
BUTTONADD);
845 $nb_order=count($this->a_order);
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++)
866 if ( $this->sort_column ==
"")
868 printf(
'<table class="result" id="tb%s">', $this->object_name);
870 printf(
'<table class="result sortable" id="tb%s">', $this->object_name);
884 sprintf(
"%s.input('-1','%s')",
886 $this->object_name),
"xx",
"smallbutton",
BUTTONADD);
888 printf(
'<script> alternate_row_color("tb%s");</script>',
898 $nb=count($this->a_order);
904 echo
th(
" ",
'style="width:40px" class="sorttable_nosort"');
908 echo
th(
" ",
'style="width:40px" class="sorttable_nosort"');
913 $key=$this->a_order[
$i];
915 if ( $key == $this->sort_column) {
916 $sorted=
' class="sorttable_sorted"';
919 $style=$this->a_header_option[$key];
921 echo
th(
"", $sorted.$style, $this->a_label_displaid[$key]);
926 echo
th(
" ",
'style="width:40px" class="sorttable_nosort"');
930 echo
th(
" ",
'style="width:40px" class="sorttable_nosort" ');
940 $this->sort_column=
$p_col;
956 $this->
table->load();
966 $nb=count($this->a_order);
971 $key=$this->a_order[
$i];
975 $v=
$http->request($this->a_order[
$i],
"string",
"");
976 $this->
table->$key=strip_tags($v);
986 $js=sprintf(
"%s.input('%s','%s');", $this->object_name,
987 $p_row[$this->
table->primary_key], $this->object_name
999 $js=sprintf(
"%s.remove('%s','%s');", $this->object_name,
1000 $p_row[$this->
table->primary_key], $this->object_name
1021 $pk_id=$p_row[$this->
table->primary_key];
1022 printf(
'<tr id="%s_%s" ctl_pk_id="%s">', $this->object_name,
1026 if ($this->icon_mod==
"left")
1028 if ($this->icon_del==
"left")
1030 if ( $this->icon_mod ==
"custom")
1033 $nb_order=count($this->a_order);
1034 for (
$i=0;
$i<$nb_order;
$i++)
1036 $this->current_row=$p_row;
1037 $v=$this->a_order[
$i];
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>';
1050 echo
td($p_row[$v],sprintf(
' sorttable_customkey="X%s" ',$p_row[$v]));
1052 echo
td($p_row[$v],$this->a_col_option[$v]);
1054 echo
td(
nbm($p_row[$v],2),$this->a_col_option[$v]);
1056 echo
td(
nbm($p_row[$v],4),$this->a_col_option[$v]);
1058 echo
td(
nbm($p_row[$v],6),$this->a_col_option[$v]);
1063 echo
td($p_row[$v],sprintf(
' sorttable_customkey="X%s" ',$p_row[$v]),$this->a_col_option[$v]);
1081 $array_to_search=$this->a_select[$v];
1084 $nb_search=(is_array($array_to_search))?count($array_to_search):0;
1086 for (
$e=0;
$e<$nb_search;
$e++)
1088 if (isset($array_to_search[
$e][
'value'])&&$array_to_search[
$e][
'value']==
$value)
1091 echo
td($array_to_search[
$e][
'label'],$this->a_col_option[$v]);
1103 echo
td($p_row[$v],$this->a_col_option[$v]);
1105 echo
td(
nbm($p_row[$v],2),$this->a_col_option[$v]);
1107 echo
td(
nbm($p_row[$v],4),$this->a_col_option[$v]);
1109 echo
td(
nbm($p_row[$v],6),$this->a_col_option[$v]);
1112 echo
td($p_row[$v], $this->a_col_option[$v]);
1116 if ($this->icon_mod==
"right")
1118 if ($this->icon_del==
"right")
1158 return td($p_value);
1175 $nb_order=count($this->a_order);
1177 for (
$i=0;
$i<$nb_order;
$i++)
1180 $key=$this->a_order[
$i];
1181 $label=$this->a_label_displaid[$key];
1189 if ( isset($this->a_info[$key])) {
1193 echo
"<td> {$label} {$info} {$error}</td>";
1198 if ($this->a_type[$key]==
"select")
1201 $select->value=$this->a_select[$key];
1205 elseif ($this->a_type[$key]==
"text")
1210 $text->size=$min_size;
1211 echo
$text->input();
1213 elseif ($this->a_type[$key]==
"numeric")
1218 $text->size=$min_size;
1219 echo
$text->input();
1221 elseif ($this->a_type[$key]==
"numeric2")
1227 $text->size=$min_size;
1228 echo
$text->input();
1230 elseif ($this->a_type[$key]==
"numeric4")
1236 $text->size=$min_size;
1237 echo
$text->input();
1239 elseif ($this->a_type[$key]==
"numeric6")
1245 $text->size=$min_size;
1246 echo
$text->input();
1248 elseif ($this->a_type[$key]==
"date")
1253 $text->size=$min_size;
1254 echo
$text->input();
1255 }
elseif ($this->a_type[$key]==
"custom")
1263 printf(
'<td>%s %s</td>',
h(
$value),
1291 throw new Exception(__FILE__.
":".__LINE__.
"- input_custom "._(
"non implémenté"));
1303 $xml=
new DOMDocument(
'1.0',
"UTF-8");
1311 if ($this->
check()==
false)
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());
1328 $this->
table->load();
1331 $html=ob_get_contents();
1333 $s3=
$xml->createElement(
"html");
1335 $s3->appendChild($t1);
1339 $root->appendChild($s1);
1340 $root->appendChild($s2);
1341 $root->appendChild($s3);
1342 $root->appendChild($s4);
1343 $root->appendChild($s5);
1346 catch (Exception
$ex)
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());
1354 $root->appendChild($s1);
1355 $root->appendChild($s2);
1356 $root->appendChild($s3);
1357 $root->appendChild($s4);
1358 $root->appendChild($s5);
1378 $xml=
new DOMDocument(
"1.0",
"UTF-8");
1379 $xml->createElement(
"status", $p_status);
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;
1397 $close=sprintf(
"\$('%s').remove()", $this->dialog_box);
1400 echo
'<ul class="aligned-block">';
1402 if ( $can_update ) {
1414 $html=ob_get_contents();
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());
1424 $s3->appendChild($t1);
1427 $root->appendChild($s1);
1428 $root->appendChild($s2);
1429 $root->appendChild($s3);
1430 $root->appendChild($s4);
1431 $root->appendChild($s5);
1434 catch (Exception
$ex)
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());
1443 $root->appendChild($s1);
1444 $root->appendChild($s2);
1445 $root->appendChild($s3);
1446 $root->appendChild($s4);
1447 $root->appendChild($s5);
1461 $this->
table->delete();
1473 $xml=
new DOMDocument(
'1.0',
"UTF-8");
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);
1485 $root->appendChild($s1);
1486 $root->appendChild($s2);
1487 $root->appendChild($s3);
1488 $root->appendChild($s4);
1490 catch (Exception
$ex)
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);
1499 $root->appendChild($s1);
1500 $root->appendChild($s2);
1501 $root->appendChild($s3);
1502 $root->appendChild($s4);
1515 if ($this->
table->exist()==0)
1517 $this->
table->insert();
1521 $this->
table->update();
1532 $this->
table->insert();
1542 $this->
table->update();
1552 $this->
table->set($p_key, $p_value);
1562 $nb_order=count($this->a_order);
1563 if (count($this->aerror)==0)
1565 echo
"<span class=\"notice\">Liste erreurs :</span>";
1566 for (
$i=0;
$i<$nb_order;
$i++)
1568 $key=$this->a_order[
$i];
1569 $label=$this->a_label_displaid[$key];
1571 $error=(
$error==
"")?
"":
"<span class=\"notice\" style=\"font-weight:normal;font-style:normal;display:block\">".
h(
$label).
" : ".
h($this->
get_error($key)).
"</span>";
1585 echo
'<td>'.
'<a href="#">';
noalyss_strlen($p_string)
th($p_string, $p_extra='', $raw='')
td($p_string='', $p_extra='')
surround the string with td
nbm($p_number, $p_dec=2)
format the number with a sep.
if(headers_sent() &&DEBUGNOALYSS > 0) $html
h( $row[ 'oa_description'])
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
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
This class handles only the numeric input, the input will call a javascript to change comma to period...
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
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.
set_dialog_box($dialog_box)
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.
if( $delta< 0) elseif( $delta==0)