public function handle_table_action($action, $options) { $options = $this->process_table_options($options); if (isset($options['error'])) { return array('success' => FALSE, 'msg' => $options['error']); } if ($action == 'data') { $page = isset($_POST['page']) ? (int) $_POST['page'] : 1; $rp = isset($_POST['rp']) ? (int) $_POST['rp'] : 10; $sortname = isset($_POST['sortname']) && $_POST['sortname'] != 'undefined' ? $_POST['sortname'] : FALSE; $sortorder = isset($_POST['sortorder']) ? $_POST['sortorder'] == 'asc' ? 'ASC' : 'DESC' : 'DESC'; $search_string = isset($_POST['query']) ? $_POST['query'] != '' ? $_POST['query'] : false : false; $search_field = isset($_POST['qtype']) ? $_POST['qtype'] != '' ? $_POST['qtype'] : false : false; $this->fetch_opts = array('offset' => $page, 'amount' => $rp, 'sortfield' => $sortname, 'sortorder' => $sortorder, 'search_field' => $search_field, 'search_string' => $search_string); $result = $this->get_records(); // Records can be processed before being sent to the client side. if (isset($this->model_value_processors['client'][$this->model_name]) && is_callable($this->model_value_processors['client'][$this->model_name])) { call_user_func($this->model_value_processors['client'][$this->model_name], array('instances' => &$result['records'])); } $jsonData = array('page' => $page, 'total' => 0, 'rows' => array()); $jsonData['total'] = $result['total']; $jsonData['rows'] = $result['records']; return $jsonData; } if ($action == 'create' || $action == 'update' || $action == 'delete' || ($action = 'view')) { // Is this action allowed? if (isset($options['controller_order']) && count($options['controller_order']) > 0) { if (!in_array($action, $options['controller_order'])) { return array('success' => FALSE, 'msg' => "The action '{$action}' is not allowed"); } } else { if (isset($options[$action]) && $options[$action] == FALSE) { return array('success' => FALSE, 'msg' => "The action '{$action}' is not allowed"); } } // A primary key value is required for any action other than 'create' $id = isset($_POST['pk']) ? $_POST['pk'] !== '' ? $_POST['pk'] : NULL : NULL; if ($action != 'create' && $id === NULL) { return array('success' => FALSE, 'msg' => "A record id value is required for this action ('{$action}')"); } // First apply table options such as order and column options. $form_options = array('model' => $this->model_def, 'model_name' => $this->model_name, 'fields' => $this->column_options, 'order' => $options['order'], 'record_id' => $id); if (isset($options['form_options'])) { // Then apply default form options if they exist. if (isset($options['form_options']['default'])) { $form_options = $this->merge_assoc_arrays($form_options, $options['form_options']['default']); } // Finally apply specific form options if they exist. if ($action == 'create' && isset($options['form_options']['create'])) { $form_options = $this->merge_assoc_arrays($form_options, $options['form_options']['create']); } if ($action == 'update' && isset($options['form_options']['update'])) { $form_options = $this->merge_assoc_arrays($form_options, $options['form_options']['update']); } if ($action == 'delete' && isset($options['form_options']['delete'])) { $form_options = $this->merge_assoc_arrays($form_options, $options['form_options']['delete']); } } $form_options['type'] = $action; $Form = new Form(); $Form->model_value_processors = $this->model_value_processors; if (!isset($_POST['instance'])) { $result = $Form->initialise($form_options); return $result; } $result = $Form->handle_form_action($action, $form_options); if (!$result['success']) { return $result; } return array('success' => TRUE); // $result = $this->handle_form_action($form_options); // if(!$result['success']) // return $result; // // On success return a new list of instances that the table should display. // $instances = $this->get_records(); // if(isset($this->model_value_processors['client'][$this->model_name]) && is_callable($this->model_value_processors['client'][$this->model_name])) // { // call_user_func($this->model_value_processors['client'][$this->model_name], array('instances' => &$instances)); // } // $result['instances'] = $instances; // return $result; } //else if($action == 'search' || $ac }