[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 109/151: Add a class to manage the Param tabl
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 109/151: Add a class to manage the Param table (CRUD) |
Date: |
Sat, 4 Feb 2017 17:14:32 +0000 (UTC) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit c323df8f849ecc8523b886a0c72b8fac18535639
Author: Rachel <address@hidden>
Date: Tue Jan 10 16:25:51 2017 +0100
Add a class to manage the Param table (CRUD)
Signed-off-by: Dany De Bontridder <address@hidden>
---
include/database/class_manage_table_sql.php | 201 +++++++++++++++++++++++++++
1 file changed, 201 insertions(+)
diff --git a/include/database/class_manage_table_sql.php
b/include/database/class_manage_table_sql.php
new file mode 100644
index 0000000..7d21089
--- /dev/null
+++ b/include/database/class_manage_table_sql.php
@@ -0,0 +1,201 @@
+<script>
+var ManageTable={
+ add:function(p_table) {
+ // display the form to enter data
+ },
+ save:function(form_id) {
+
+ },
+ delete:function (p_table,p_id) {
+
+ },
+ input:function (p_table,p_id) {
+ }
+
+
+}
+</script>
+
+<?php
+class Manage_Table_SQL
+{
+ private $table ;
+ private $a_label_displaid;
+ function __construct(Noalyss_SQL $p_table)
+ {
+ $this->table=$p_table;
+ $order=0;
+ foreach ($this->table->name as $key=> $value)
+ {
+
+ $this->a_label_displaid[$value]=$value;
+ $this->a_order[$order]=$value;
+ $order++;
+ }
+
+ }
+ function set_col_label($p_col_name,$p_display)
+ {
+ $this->a_label_displaid[$p_col_name]=$p_display;
+ }
+ function get_current_pos($p_col_name)
+ {
+ $nb_order=count($this->a_order);
+ for ($i=0;$i<$nb_order;$i++)
+ if ( $this->a_order[$i]==$p_col_name) return $i;
+ throw new Exception ("COL INVAL ".$p_col_name);
+
+ }
+ /**
+ address@hidden if we change a column order , the order
+ * of the other columns is impacted.
+ *
+ * With a_order[0,1,2,3]=[x,y,z,a]
+ * if we move the column x (idx=0) to 2
+ * we must obtain [y,z,x,a]
+ */
+ function move($p_col_name,$p_idx)
+ {
+ // get current position of p_col_name
+ $cur_pos=$this->get_current_pos($p_col_name);
+
+ if ( $cur_pos == $p_idx ) return ;
+
+ if ( $cur_pos < $p_idx )
+ {
+ $nb_order=count($this->a_order);
+ for ($i=0;$i<$nb_order;$i++) {
+ // if col_name is not the searched one we
continue
+ if ( $this->a_order[$i] != $p_col_name )
continue;
+ if ( $p_idx == $i ) continue;
+ // otherwise we swap with i+1
+ $old=$this->a_order[$i+1];
+ $this->a_order[$i]=$this->a_order[$i+1];
+ $this->a_order[$i+1]=$p_col_name;
+ }
+ } else {
+
+ $nb_order=count($this->a_order)-1;
+ for ($i=$nb_order;$i>0;$i--) {
+ // if col_name is not the searched one we
continue
+ if ( $this->a_order[$i] != $p_col_name )
continue;
+ if ( $p_idx == $i ) continue;
+ // otherwise we swap with i+1
+ $old=$this->a_order[$i-1];
+ $this->a_order[$i]=$this->a_order[$i-1];
+ $this->a_order[$i-1]=$p_col_name;
+ }
+
+ }
+
+ }
+
+ function display_table()
+ {
+ $ret=$this->table->seek();
+ $nb=Database::num_count($ret);
+ for ($i=0;$i< $nb ; $i++ )
+ {
+ if ( $i == 0 ) {
+ $this->display_table_header();
+ }
+ $row=Database::fetch_array($ret,$i);
+ $this->display_row($row);
+ }
+ }
+
+ function display_table_header()
+ {
+ $nb=count($this->a_order);
+ echo "<tr>";
+
+ for ($i=0;$i < $nb ; $i++ ) {
+
+ $key=$this->a_order[$i];
+ echo th($this->a_label_displaid[$key]);
+ }
+ echo "</tr>";
+
+ }
+ function set_pk($p_id)
+ {
+ $this->table->set_pk_value($p_id);
+ }
+ function from_request()
+ {
+ $nb=count($this->a_order);
+ for ($i=0;$i < $nb ; $i++ ) {
+
$v=HtmlInput::default_value_request($this->a_order[$i],"");
+ $key=$this->a_order[$i];
+ $this->table->$key=$v;
+ }
+
+ }
+ private function display_row($p_row)
+ {
+
+ printf ('<tr id="%s_%s">',
+ $this->table->table,
+ $p_row[$this->table->primary_key])
+ ;
+
+ $nb_order=count($this->a_order);
+ for ($i=0;$i < $nb_order ; $i++)
+ {
+ $v=$this->a_order($i);
+ echo td($p_row[$v]);
+ }
+ $js=printf ("ManageTable.input('%s','%s');",
+ $this->table->table,
+ $p_row[$this->table->primary_key]
+ );
+ $js=printf ("ManageTable.delete('%s','%s');",
+ $this->table->table,
+ $p_row[$this->table->primary_key]
+ );
+
+ echo "<td>";
+ echo '</tr>';
+ }
+ function input()
+ {
+ $nb_order=count($this->a_order);
+ echo "<table>";
+ echo "<tr>";
+ for ( $i=0; $i <$nb_order ; $i++ )
+ {
+ $key=$this->a_order[$i];
+ $label=$this->a_label_displaid[$key];
+ $value=$this->table->get($key);
+
+ // Label
+ echo "<td> {$label} </td>";
+ printf('<input type="text" label="%s" value="%s"
name="%s" id="%s">',
+ $label,
+ $value,
+ $key,
+ $key
+ );
+ }
+ echo "</tr>";
+ echo "</table>";
+ }
+ function delete() {
+ $this->table->delete();
+ }
+ function save() {
+ $this->table->save();
+ }
+ function insert() {
+ $this->table->insert();
+ }
+ function update() {
+ $this->table->update();
+ }
+ function set_value($p_col_name,$p_value)
+ {
+ $this->table->set($p_col_name,$p_value);
+ }
+
+}
+
- [Noalyss-commit] [noalyss] 134/151: Fix Bug : Predefined operation in Sales , impossible to add new items, (continued)
- [Noalyss-commit] [noalyss] 134/151: Fix Bug : Predefined operation in Sales , impossible to add new items, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 139/151: ManageTable correct color of HighLigthed row, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 140/151: ManageTable use icon, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 136/151: Esthetic for duplicate operation & Correct esthetic, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 72/151: Documentation Task #2 - Documentation nouveau code, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 76/151: Ajout options Task #9 - PDF_Operation : ajout des options, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 83/151: Performance : improve VERIF, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 74/151: Export en PDF d'operation : PDF_Operation::print_section Task #10 - PDF_Operation : ajout titre Analytique, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 84/151: Performance : improve VERIF , change query pour fiche utilisé avec 2 postes, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 115/151: Correct doxygen, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 109/151: Add a class to manage the Param table (CRUD),
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 113/151: Correct doxygen doc, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 131/151: Doxygen, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 120/151: Add managetable.js to the script to load, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 128/151: Security : add security, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 130/151: #1380 : change the name of the function Acc_Ledger::button_copy_operation, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 132/151: Correct Doxygen documentation, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 96/151: Documentation and clean code, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 112/151: Improve Doxygen doc, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 73/151: Export en PDF d'operation, Dany De Bontridder, 2017/02/04
- [Noalyss-commit] [noalyss] 143/151: Fix : when exporting files for creating a PDF in ANC , the filename can be a problem if he contains some char., Dany De Bontridder, 2017/02/04