public function index($offset = 0) { $columns = array('latitude' => 'string', 'longitude' => 'string'); $configs = array('admin', 'proposes', '%s'); $conditions = conditions($columns, $configs, 'Propose', $this->input_gets()); $conditions = array(implode(' AND ', array_merge($conditions, array('id_enabled = 1')))); $limit = 25; $total = Propose::count(array('conditions' => $conditions)); $offset = $offset < $total ? $offset : 0; $this->load->library('pagination'); $configs = array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs); $this->pagination->initialize($configs); $pagination = $this->pagination->create_links(); $proposes = Propose::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'conditions' => $conditions)); $message = identity()->get_session('_flash_message', true); $this->add_css(base_url('resource', 'css', 'fancyBox_v2.1.5', 'jquery.fancybox.css'))->add_css(base_url('resource', 'css', 'fancyBox_v2.1.5', 'jquery.fancybox-buttons.css'))->add_css(base_url('resource', 'css', 'fancyBox_v2.1.5', 'jquery.fancybox-thumbs.css'))->add_css(base_url('resource', 'css', 'fancyBox_v2.1.5', 'my.css'))->add_js(base_url('resource', 'javascript', 'fancyBox_v2.1.5', 'jquery.fancybox.js'))->add_js(base_url('resource', 'javascript', 'fancyBox_v2.1.5', 'jquery.fancybox-buttons.js'))->add_js(base_url('resource', 'javascript', 'fancyBox_v2.1.5', 'jquery.fancybox-thumbs.js'))->add_js(base_url('resource', 'javascript', 'fancyBox_v2.1.5', 'jquery.fancybox-media.js'))->load_view(array('message' => $message, 'pagination' => $pagination, 'proposes' => $proposes, 'columns' => $columns)); }
public function create() { if (!$this->has_post()) { return redirect(array('proposes')); } $title = trim($this->input_post('title')); $latitude = trim($this->input_post('latitude')); $longitude = trim($this->input_post('longitude')); if (time() - identity()->get_session('post_time') < 30) { return identity()->set_session('_flash_message', '別急!一分鐘後再推薦新地點吧!', true)->set_session('title', $title, true)->set_session('latitude', $latitude, true)->set_session('longitude', $longitude, true) && redirect(array('proposes'), 'refresh'); } if (!($title && $latitude && $longitude)) { return identity()->set_session('_flash_message', '填寫資訊有少!', true)->set_session('title', $title, true)->set_session('latitude', $latitude, true)->set_session('longitude', $longitude, true) && redirect(array('proposes'), 'refresh'); } $params = array('title' => $title, 'ip' => $this->input->ip_address(), 'latitude' => $latitude, 'longitude' => $longitude, 'id_enabled' => 1); if (!verifyCreateOrm($propose = Propose::create($params))) { return identity()->set_session('_flash_message', '新增失敗!', true)->set_session('title', $title, true)->set_session('latitude', $latitude, true)->set_session('longitude', $longitude, true) && redirect(array('proposes'), 'refresh'); } identity()->set_session('post_time', time()); return identity()->set_session('_flash_message', '新增成功,等待管理員審核通過!', true) && redirect(array('proposes'), 'refresh'); }