function get_record($table_name, $var_name, $reqd_admin_level = 0, $must_be_logged_id = false) { global $registry; // start fresh $this->data = array(); $this->data['status'] = AJAX_NO_ERROR; $this->data['message'] = ''; if (isset($this->record) == true) { unset($this->record); } $mgr = new v6_manager(); $mgr->UserIsLoggedIn(false); if (isset($must_be_logged_id) && $must_be_logged_id == true && $mgr->IsLoggedIn == false) { $this->data['status'] = AJAX_ACCESS_DENIED; $this->data['message'] = 'Access Denied (AGR-1)'; return $this->data['status']; } if ($reqd_admin_level == 2 && $mgr->is_almighty == false) { $this->data['status'] = AJAX_ACCESS_DENIED; $this->data['message'] = 'Access Denied (AGR-2)'; return $this->data['status']; } if ($reqd_admin_level == 1 && ($mgr->is_almighty == false && $mgr->is_admin == false)) { $this->data['status'] = AJAX_ACCESS_DENIED; $this->data['message'] = 'Access Denied (AGR-3)'; return $this->data['status']; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->data['status'] = AJAX_ACCESS_DENIED; $this->data['message'] = 'Access Denied (AGR-4)'; return $this->data['status']; } $registry->helper->load('v6_validator'); $validator = new v6_validator($_GET); // make sure the querystring is a valid number... $validator->CheckNumber($var_name, 'Id', 0, 999999); $message = $validator->message; if (empty($message) == false) { $this->data['status'] = AJAX_VALIDATION_FAILURE; $this->data['message'] = $message; return $this->data['status']; } $this->record = new v6_table($table_name); $this->record->load_by_id($_GET[$var_name]); $this->data['status'] = AJAX_RECORD_DATA; $this->data['message'] = 'Record Data'; return $this->data['status']; }
/** * perform the actual read from the database and populate this instance of the list. select statement MUST have a * field called "id" as a column name in the result set! * @param $sql select statement to grab rows from the database */ function read_from_db($sql) { global $registry; $this->the_list = array(); // start fresh with an empty list try { foreach ($registry->db->query($sql) as $row) { $tbl = new v6_table($this->table_name); $tbl->load_by_id($row['id']); $this->the_list[] = $tbl; } } catch (PDOException $e) { /** * @todo clean up error catch exposure */ echo $e->getMessage() . '<br>' . $sql . '<br><hr>'; } }