load->database(); } //$data=date("Y-m-d"); function get_pages($lang=false,$nOffset = false, $nRowsCount = false ) { $this->db->select('*'); $this->db->from('pages_description,pages'); $this->db->where('pages_description.id = pages.id'); if($lang) $this->db->where('language_id',$lang); $this->db->orderby("sort_order", "asc"); if ($nRowsCount) $this->db->limit($nRowsCount,$nOffset); $query = $this->db->get(); return $query ->result_array(); } function get_pages_admin($lang=false,$nOffset = false, $nRowsCount = false ) { $this->db->select('*'); $this->db->from('pages_description,pages'); $this->db->where('pages_description.id = pages.id'); if($lang) $this->db->where('language_id',$lang); if(isset($_SESSION['search_pages']) && !empty($_SESSION['search_pages'])) $this->db->like('pages_description.pages_title',$_SESSION['search_pages']); $this->db->orderby("sort_order", "asc"); if ($nRowsCount) $this->db->limit($nRowsCount,$nOffset); $query = $this->db->get(); return $query ->result_array(); } function get_last_pages() { $this->db->select('*'); $this->db->from('pages_description,pages'); $this->db->where('pages_description.id = pages.id'); $this->db->orderby("sort_order", "DESC"); $this->db->limit(1,0); $query = $this->db->get(); return $query ->result_array(); } function get_pages_by_id($id,$lang_id=false) { $this->db->select('*'); $this->db->from('pages_description'); $this->db->join('pages','pages_description.id = pages.id'); $this->db->where('pages_description.id',$id); if($lang_id) $this->db->where('pages_description.language_id',$lang_id); $query = $this->db->get(); return $query ->result_array(); } function get_pages_by_url_key($lang_id,$url_key) { $this->db->select('*'); $this->db->from('pages_description'); $this->db->join('pages','pages_description.id = pages.id'); $this->db->where('pages_description.url_key',$url_key); if($lang_id) $this->db->where('pages_description.language_id',$lang_id); $query = $this->db->get(); return $query ->result_array();} function get_url_key($id) { $this->db->select('url_key'); $this->db->from('pages_description'); $this->db->where('language_id',$lang_id); $this->db->where('id',$id); $query = $this->db->get(); return $query ->result_array(); } function get_pages_id_by_url_key($url_key) { $this->db->select('id'); $this->db->from('pages_description'); //$this->db->where('language_id',$lang_id); $this->db->where('url_key',$url_key); $query = $this->db->get(); return $query ->result_array(); } function insert_pages_id() { $max="SELECT MAX(sort_order) AS max FROM `pages`"; $q = $this -> db -> query($max); $t = $q->result_array(); $max=$t[0]['max']; if($max=='') $max=0; else $max=$max+1; $this->db->set('sort_order', $max); $this->db->insert('pages'); return $this->db->insert_id(); } function insert_pages($addfile,$edit) { if ($edit=='edit') { $t=$this->get_pages_by_id($addfile['id'],$addfile['language_id']); if(isset($t[0]['language_id'])) $this->db->update('pages_description',$addfile,array('id'=>$addfile['id'],'language_id'=>$addfile['language_id'])); else $this->db->insert('pages_description',$addfile); } else if ($edit=='new') { $this->db->insert('pages_description',$addfile); } } function get_sort_order($id) { $this->db->select('sort_order'); $this->db->from('pages'); $this->db->where('id',$id); $query = $this->db->get(); $query = $query ->result_array(); return $query[0]['sort_order']; } function get_target_sort_order($direction,$sort_order) { $this->db->select('sort_order'); $this->db->from('pages'); if($direction=="up") { $this->db->where('sort_order < ', $sort_order); $this->db->orderby("sort_order", "desc"); } elseif($direction=="down") { $this->db->where('sort_order > ', $sort_order); $this->db->orderby("sort_order", "asc"); } $query = $this->db->get(); $query = $query ->result_array(); if($query==NULL) $tt=''; else $tt=$query[0]['sort_order']; return $tt; } function move($sort_order,$target) { $t=-10; $this->db->update('pages', array('sort_order' => $t), array('sort_order' => $sort_order)); $this->db->update('pages', array('sort_order' => $sort_order), array('sort_order' => $target)); $this->db->update('pages', array('sort_order' => $target), array('sort_order' => $t)); } function delete_pages($id) { $pages=$this->pages_model->get_pages_by_id($id); foreach ($pages as $item): $pages_1[$item['language_id']]=$item; endforeach; if($pages_1[2]['file_name']!='') { @unlink(document_root().'/uploads/pages/'.$this->add_sufix->add_thumb($pages_1[2]['file_name'])); @unlink(document_root().'/uploads/pages/'.$pages_1[2]['file_name']); } $this->db->delete('pages', array('id' => $id)); $this->db->delete('pages_description', array('id' => $id)); } function get_bulk_images($id) { $sql = 'SELECT * FROM pages_images WHERE id = ' . $id.' ORDER BY sort_order ASC'; $query= $this->db->query($sql); $images=$query->result_array(); return $images; } function get_bulk_images_next_sort_order($id) { $max="SELECT MAX(sort_order) AS max FROM `pages_images` WHERE id = ".$id; $q = $this -> db -> query($max); $t = $q->result_array(); $max=$t[0]['max']; if($max=='') $max=0; else $max=$max+1; return $max; } function get_sort_order_bulk_img($image_id) { $this->db->select('sort_order'); $this->db->from('pages_images'); $this->db->where('image_id',$image_id); $query = $this->db->get(); $query = $query ->result_array(); return $query[0]['sort_order']; } function get_target_sort_order_bulk_img($direction,$sort_order,$id) { $this->db->select('sort_order'); $this->db->from('pages_images'); $this->db->where('id', $id); if($direction=="up") { $this->db->where('sort_order < ', $sort_order); $this->db->orderby("sort_order", "desc"); } elseif($direction=="down") { $this->db->where('sort_order > ', $sort_order); $this->db->orderby("sort_order", "asc"); } $query = $this->db->get(); $query = $query ->result_array(); if($query==NULL) $tt=''; else $tt=$query[0]['sort_order']; return $tt; } function move_bulk_img($sort_order,$target,$id) { $t=-10; $this->db->update('pages_images', array('sort_order' => $t), array('sort_order' => $sort_order, 'id' => $id)); $this->db->update('pages_images', array('sort_order' => $sort_order), array('sort_order' => $target, 'id' => $id)); $this->db->update('pages_images', array('sort_order' => $target), array('sort_order' => $t, 'id' => $id)); } }