table=$p_table; $order=0; foreach ($this->table->name as $key=> $value) { $this->a_label_displaid[$value]=$value; $this->a_order[$order]=$value; $this->a_prop[$value]=self::UPDATABLE|self::VISIBLE; $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); } /** *@brief 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 "
| {$label} | "; printf('', $label, $value, $key, $key ); } echo "