/** * @param string $myzip * @param int $miles * @return array v6_databaselist->the_list */ function ZipsWithinMiles($myzip, $miles) { // first find out my lat/lon $this->my_zip_record->load_by_secondary_key('zip_code', $myzip); $ziplist = new v6_database_list($this->zip_radius_table_name); $where = sprintf("(SQRT((69.172*(%f-zip_radius_table_name.latitude))*(69.172*(%f-zip_radius_table_name.latitude))+(53.0*(%f-zip_radius_table_name.longitude))*(53.0*(%f-zip_radius_table_name.longitude)))<=%f)", $this->my_zip_record->latitude, $this->my_zip_record->latitude, $this->my_zip_record->longitude, $this->my_zip_record->longitude, $miles); $where = str_replace('zip_radius_table_name', $this->zip_radius_table_name, $where); $ziplist->load_by_custom_where($where); return $ziplist->the_list; }
/** * 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>'; } }
function delete_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 (ADR-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 (ADR-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 (ADR-3)'; return $this->data['status']; } if ($_SERVER['REQUEST_METHOD'] == 'GET') { $this->data['status'] = AJAX_ACCESS_DENIED; $this->data['message'] = 'Access Denied (ADR-4)'; return $this->data['status']; } $registry->helper->load('v6_validator'); $validator = new v6_validator($_POST); // 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->delete_by_id($_POST[$var_name]); $this->data['status'] = AJAX_RECORD_DELETED; $this->data['message'] = 'Record Deleted'; return $this->data['status']; }
public function SetGroupPermission($group_id, $privilege_id_descrip, $allow_deny) { $privilege_id = $this->PrivilegeId($privilege_id_descrip); $group_permission = new v6_table('group_permissions'); $group_permission->load_by_custom_where(sprintf('group_id=%d and privilege_id=%d', $group_id, $privilege_id)); if (strlen(trim($allow_deny)) == 0) { $id = $group_permission->field['id']; if ($id != 0) { // only delete it if we found it $group_permission->delete_by_id($id); } } else { $group_permission->group_id = $group_id; $group_permission->privilege_id = $privilege_id; $group_permission->allow_deny = $allow_deny; $group_permission->save(); } }