PageRenderTime 66ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/application/modules/kaizen/controllers/Pages.php

https://bitbucket.org/rightshore/saskatoon-landscape-store
PHP | 292 lines | 249 code | 27 blank | 16 comment | 20 complexity | 39a17c071ec270f3894e4958f8eb3793 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Pages extends MY_Controller
  3. {
  4. private $limit = 20;
  5. var $offset = 0;
  6. function __construct()
  7. {
  8. parent::__construct();
  9. if( ! $this->session->userdata('web_admin_logged_in')) {
  10. redirect('kaizen/welcome','refresh');
  11. }
  12. $this->load->vars( array(
  13. 'global' => 'Available to all views',
  14. 'header' => 'common/header',
  15. 'left' => 'common/left',
  16. 'footer' => 'common/footer',
  17. 'right' => 'common/right'
  18. ));
  19. $this->load->model('modelpages');
  20. }
  21. public function index()
  22. {
  23. $this->dolist();
  24. }
  25. public function dolist(){
  26. $data = array();
  27. $parent_id = $this->input->get("parent_id");
  28. if(!empty($parent_id)){
  29. $where = array('parent_id' => $parent_id);
  30. }else{
  31. $where = array();
  32. }
  33. $order_by = array('title' => 'asc');
  34. $data_row = $this->modelpages->select_row('cms_pages',$where,$order_by);
  35. $rest_arr = $data_row;
  36. #echo $this->db->last_query();
  37. if(!empty($parent_id)){
  38. $where_ar = array('id' => $parent_id);
  39. $parebt_rec = $this->modelpages->select_row('cms_pages',$where_ar);
  40. if(!empty($data_row)){
  41. foreach($data_row as $data_ind){
  42. $where = array('parent_id' => $data_ind->id);
  43. $order_by = array('title' => 'asc');
  44. $data_row_sub = $this->modelpages->select_row('cms_pages',$where,$order_by);
  45. if(!empty($data_row_sub)){
  46. $rest_arr = array_merge($rest_arr,$data_row_sub);
  47. foreach($data_row_sub as $data_sub_sub){
  48. $where = array('parent_id' => $data_sub_sub->id);
  49. $order_by = array('title' => 'asc');
  50. $data_row_sub_sub = $this->modelpages->select_row('cms_pages',$where,$order_by);
  51. if(!empty($data_row_sub_sub)){
  52. $rest_arr = array_merge($rest_arr,$data_row_sub_sub);
  53. foreach($data_row_sub_sub as $data_sub_sub_sub){
  54. $where = array('parent_id' => $data_sub_sub_sub->id);
  55. $order_by = array('title' => 'asc');
  56. $data_row_sub_sub_sub = $this->modelpages->select_row('cms_pages',$where,$order_by);
  57. if(!empty($data_row_sub_sub_sub)){
  58. $rest_arr = array_merge($rest_arr,$data_row_sub_sub_sub);
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. }
  66. $data_row = array_merge($rest_arr,$parebt_rec);
  67. }
  68. // pre($data_row);
  69. // if(!empty($parebt_rec)){
  70. // $data_row = array_merge($data_row,$parebt_rec);
  71. // }
  72. // pre($data_row);
  73. $data['records']= $data_row;
  74. $wherepg = array();
  75. $order_bypg = array('title' =>'asc');
  76. $data['page_list']= $this->modelpages->select_row('cms_pages',$wherepg,$order_bypg);
  77. //pre($data['page_list']);
  78. $data['selected'] = $parent_id;
  79. // print_r($data);
  80. $this->load->view('pages/pages_list',$data);
  81. }
  82. public function doadd(){
  83. $data = array();
  84. $data['details']= new stdClass;
  85. $pages_id=$this->uri->segment(4);
  86. $data['details']->is_active = 1;
  87. $data['details']->id = $pages_id;
  88. $wherepg = array( 'is_active' =>1);
  89. $order_bypg = array('title' => 'asc');
  90. $data['page_list']= $this->modelpages->select_row('cms_pages',$wherepg,$order_bypg);
  91. $this->load->view('pages/edit_pages',$data);
  92. }
  93. public function popup()
  94. {
  95. $count = $this->uri->segment(4);
  96. $pos = $this->uri->segment(5);
  97. $this->data['folder_name'] = $count;
  98. $this->data['pos'] = $pos;
  99. $this->data['imgwidth'] = '1140';
  100. $this->data['imgheight'] = '698';
  101. $this->data['session'] = $this->uri->segment(5);
  102. $this->load->view('upload_product_crop',$this->data);
  103. }
  104. public function addedit()
  105. {
  106. $this->load->library('form_validation');
  107. $this->form_validation->set_rules('pages_title', 'Title', 'trim|required|xss_clean');
  108. $this->form_validation->set_error_delimiters('<span class="validation_msg">', '</span>');
  109. $id=$this->input->post('pages_id','');
  110. $pages_title ='';
  111. if($this->form_validation->run() == TRUE) // IF MENDATORY FIELDS VALIDATION TRUE(SERVER SIDE)
  112. {
  113. $where = array('id' => $id);
  114. $pages_detls = $this->modelpages->select_row('cms_pages',$where);
  115. if(!empty($pages_detls))
  116. {
  117. $this->pages_title =$this->input->post('pages_title',TRUE);
  118. $this->htmlfile1 =$this->input->post('htmlfile1',TRUE);
  119. $this->htmlfile8 =$this->input->post('htmlfile8',TRUE);
  120. $this->htmlfile9 =$this->input->post('htmlfile9',TRUE);
  121. $this->parent_id =$this->input->post('parent_id',TRUE);
  122. $this->meta_title =$this->input->post('meta_title',TRUE);
  123. $this->shown_in_banner =$this->input->post('shown_in_banner',TRUE);
  124. $this->external_link =$this->input->post('external_link',TRUE);
  125. $this->shown_in_top =$this->input->post('shown_in_top',TRUE);
  126. $this->shown_in_footer =$this->input->post('shown_in_footer',TRUE);
  127. $this->shown_in_side =$this->input->post('shown_in_side',TRUE);
  128. $this->htmlfile5 =$this->input->post('htmlfile5',TRUE);
  129. $this->display_order =$this->input->post('display_order',TRUE);
  130. $this->meta_keyword =$this->input->post('meta_keyword','');
  131. $this->meta_description =$this->input->post('meta_desc','');
  132. $this->content =$this->input->post('content');
  133. $this->content2 =$this->input->post('content2');
  134. $this->content3 =$this->input->post('content3');
  135. $this->content4 =$this->input->post('content4');
  136. $this->is_active =$this->input->post('is_active',TRUE);
  137. if($this->is_active===false){
  138. $this->is_active='1';
  139. }
  140. $update_data = array(
  141. 'title' => $this->pages_title,
  142. 'banner_photo' => $this->htmlfile1,
  143. 'about_us_photo' => $this->htmlfile8,
  144. 'about_us_photo2' => $this->htmlfile9,
  145. 'parent_id' => $this->parent_id,
  146. 'content' => $this->content,
  147. 'content2' => $this->content2,
  148. 'content3' => $this->content3,
  149. 'content4' => $this->content4,
  150. 'external_link' => $this->external_link,
  151. 'shown_in_top' => $this->shown_in_top,
  152. 'shown_in_footer' => $this->shown_in_footer,
  153. /*'shown_in_banner' => $this->shown_in_banner,
  154. 'shown_in_top' => $this->shown_in_top,
  155. 'shown_in_footer' => $this->shown_in_footer,
  156. 'shown_in_side' => $this->shown_in_side, */
  157. 'display_order' => $this->display_order,
  158. 'com_cat_img' => $this->htmlfile5,
  159. 'meta_title' => $this->meta_title ,
  160. 'meta_keyword' => $this->meta_keyword,
  161. 'meta_description' => $this->meta_description,
  162. 'is_active' => $this->is_active
  163. );
  164. $update_where = array('id' => $id);
  165. if($this->modelpages->update_row('cms_pages',$update_data,$update_where)) // IF UPDATE PROCEDURE EXECUTE SUCCESSFULLY
  166. {
  167. $session_data = array("SUCC_MSG" => "Pages Updated Successfully.");
  168. $this->session->set_userdata($session_data);
  169. }
  170. else // IF UPDATE PROCEDURE NOT EXECUTE SUCCESSFULLY
  171. {
  172. $session_data = array("ERROR_MSG" => "Pages Not Updated.");
  173. $this->session->set_userdata($session_data);
  174. }
  175. }
  176. else
  177. {
  178. $this->pages_title =$this->input->post('pages_title',TRUE);
  179. $this->htmlfile1 =$this->input->post('htmlfile1',TRUE);
  180. $this->htmlfile8 =$this->input->post('htmlfile8',TRUE);
  181. $this->parent_id =$this->input->post('parent_id',TRUE);
  182. $this->meta_title =$this->input->post('meta_title',TRUE);
  183. $this->shown_in_banner =$this->input->post('shown_in_banner',TRUE);
  184. $this->external_link =$this->input->post('external_link',TRUE);
  185. $this->shown_in_top =$this->input->post('shown_in_top',TRUE);
  186. $this->htmlfile5 =$this->input->post('htmlfile5',TRUE);
  187. $this->shown_in_footer =$this->input->post('shown_in_footer',TRUE);
  188. $this->shown_in_side =$this->input->post('shown_in_side',TRUE);
  189. $this->display_order =$this->input->post('display_order',TRUE);
  190. $this->meta_keyword =$this->input->post('meta_keyword','');
  191. $this->meta_description =$this->input->post('meta_desc','');
  192. $this->content =$this->input->post('content');
  193. $this->content2 =$this->input->post('content2');
  194. $this->content3 =$this->input->post('content3');
  195. $this->content4 =$this->input->post('content4');
  196. $this->is_active =$this->input->post('is_active',TRUE);
  197. if($this->is_active===false){
  198. $this->is_active='1';
  199. }
  200. $add_data = array(
  201. 'title' => $this->pages_title,
  202. 'banner_photo' => $this->htmlfile1,
  203. 'about_us_photo' => $this->htmlfile8,
  204. 'parent_id' => $this->parent_id,
  205. 'content' => $this->content,
  206. 'content2' => $this->content2,
  207. 'content3' => $this->content3,
  208. 'content4' => $this->content4,
  209. 'external_link' => $this->external_link,
  210. 'shown_in_top' => $this->shown_in_top,
  211. 'shown_in_footer' => $this->shown_in_footer,
  212. /*'shown_in_top' => $this->shown_in_top,
  213. 'shown_in_footer' => $this->shown_in_footer,
  214. 'shown_in_banner' => $this->shown_in_banner,
  215. 'shown_in_side' => $this->shown_in_side, */
  216. 'display_order' => $this->display_order,
  217. 'meta_title' => $this->meta_title ,
  218. 'com_cat_img' => $this->htmlfile5,
  219. 'meta_keyword' => $this->meta_keyword,
  220. 'meta_description' => $this->meta_description,
  221. 'page_link' => name_replaceCat('cms_pages',$this->pages_title),
  222. 'is_active' => $this->is_active
  223. );
  224. $id = $this->modelpages->insert_row('cms_pages',$add_data);
  225. if($id)
  226. {
  227. $session_data = array("SUCC_MSG" => "Pages Inserted Successfully.");
  228. $this->session->set_userdata($session_data);
  229. }
  230. else
  231. {
  232. $session_data = array("ERROR_MSG" => "Pages Not Inserted.");
  233. $this->session->set_userdata($session_data);
  234. }
  235. }
  236. redirect("kaizen/pages/doedit/".$id,'refresh');
  237. }
  238. else{
  239. if(!empty($id)){
  240. $this->doedit();
  241. }
  242. else{
  243. $this->doadd();
  244. }
  245. }
  246. }
  247. public function doedit($id)
  248. {
  249. $data = array();
  250. $pages_id=$this->uri->segment(4);
  251. $where = array( 'id' => $pages_id);
  252. $pages_detls = $this->modelpages->select_row('cms_pages',$where);
  253. if($pages_detls){
  254. $data['details'] = $pages_detls[0];
  255. }
  256. else{
  257. $data['details']->is_active = 1;
  258. $data['details']->id = 0;
  259. }
  260. $wherepg = array( 'is_active' =>1);
  261. $order_bypg = array('title' => 'asc');
  262. $data['page_list']= $this->modelpages->select_row('cms_pages',$wherepg,$order_bypg);
  263. $this->load->view('pages/edit_pages',$data);
  264. }
  265. }