PHP File Manager
Editing File: Locations.php
<?php class Locations extends CI_Model { function get($location_id = null) { $sql = "SELECT loc.* " . "FROM location AS loc " . "WHERE loc.deleted IS NULL "; if ($location_id) { $sql .= sprintf('AND location_id = %s ', $this->db->escape($location_id)); } $query = $this->db->query($sql); $result = $query->result(); if ($location_id && $result) { return reset($result); } return $result; } function save($data) { foreach ($data['loc'] as $location_id => $location) { $save_data = array( 'name' => $location['name'], 'deleted' => (isset($location['deleted']) && $location['deleted'] ? date('Y-m-d H:i:s') : null), ); $this->db->query($this->db->update_string('location', $save_data, "location_id = {$this->db->escape($location_id)}")); } if ($new_name = trim($data['new']['name'])) { $save_data = array('name' => $new_name); $this->db->query($this->db->insert_string('location', $save_data)); } } function getDropdownData(array $locations) { $ret = array('' => ' --- '); foreach ($locations as $location) { $ret[$location->location_id] = $location->name; } return $ret; } }
Cancel