. ***********************************************************************/ // // Template for simple table editors // class simple_crud { var $name; var $Mode; var $selected_id = ''; var $handlers; var $selector; // // function simple_crud($name, $options = array()) { $this->name = $name; $this->handlers = array( 'Edit' => '_edit', 'Delete' => '_delete', 'ADD' => '_add', 'UPDATE' => '_update', 'RESET' => '_cancel', 'CLONE' => '_cloning' ); // selector type: 'button' (default), or 'list' $this->selector = @$options['selector']; // TODO } function _check_mode($numeric_id = true) { global $Ajax; $sel_name = $this->name.'_id'; $this->Mode = 'Edit'; foreach (array('Edit', 'Delete') as $m) { foreach ($_POST as $p => $pvar) { if (strpos($p, $this->name.$m) === 0) { unset($_POST['_focus']); // focus on first form entry $this->selected_id = quoted_printable_decode(substr($p, strlen($this->name.$m))); $Ajax->activate($this->name.'_div'); $this->Mode = $m; return; } } } $default = ''; $this->selected_id = get_post($sel_name, $default); if ($this->selected_id === $default) { $this->Mode = ''; return; } foreach (array('ADD', 'UPDATE', 'RESET', 'CLONE') as $m) { if (isset($_POST[$this->name.$m])) { $Ajax->activate($this->name.'_div'); unset($_POST['_focus']); $this->Mode = $m; return; } } } // // Set record for edition // function _edit() { if ($this->selected_id !== '0') { $this->data = $this->db_read(); /* foreach($this->data as $name => $value) { if (!is_numeric($name)) { $_POST[$name] = $value; } } */ } } // // Update record after edition // function _update() { if ($this->insert_check()) { if ($this->db_update()) $this->selected_id = ''; } } // // Add new record // function _add() { if ($this->insert_check()) { $this->db_insert(); $this->selected_id = ''; } } // // Delete selected record // function _delete() { if ($this->delete_check()) $this->db_delete(); $this->selected_id = ''; } // // Return to listing view // function _cancel() { $this->selected_id = ''; } // // Clone record for new edition // function _cloning() { $this->selected_id = '0'; } /* Generate form controls */ function _bottom_controls() { $clone = $this->selected_id == '0'; $title=false; $async='both'; $base=$this->name; $cancel = $async; if ($async === 'both') { $async = 'default'; $cancel = 'cancel'; } else if ($async === 'default') $cancel = true; else if ($async === 'cancel') $async = true; echo "