PageRenderTime 25ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/pages/controllers/admin.php

https://github.com/coderlabs/Kaimonokago
PHP | 252 lines | 130 code | 27 blank | 95 comment | 8 complexity | edb2ee18c533deb5b7f919f2ac75c113 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Admin extends Shop_Admin_Controller {
  3. private $module;
  4. function Admin(){
  5. parent::Shop_Admin_Controller();
  6. // Check for access permission
  7. check('Pages');
  8. // $this->module='pages';
  9. $this->module=basename(dirname(dirname(__FILE__)));
  10. // Load modules/menus/models/MMenus
  11. $this->load->module_model('menus','MMenus');
  12. // Load pages model
  13. $this->load->model('MPages');
  14. // Set breadcrumb
  15. $this->bep_site->set_crumb($this->lang->line('backendpro_pages'),$this->module.'/admin');
  16. }
  17. function index(){
  18. // we use the following variables in the view
  19. $data['title'] = $this->lang->line('kago_manage_page');
  20. // sort pages depends on languages
  21. // get all the languages
  22. // $data['languages'] =$this->MLangs->getLangDropDownWithId();
  23. //$data['pages'] = $this->MPages->getAllPages();
  24. /*
  25. * 'omc_pages.id, omc_pages.name,omc_pages.path,omc_pages.status,omc_pages.lang_id
  26. ,omc_languages.langname'
  27. */
  28. $fields = array('id', 'name','path','status','lang_id');
  29. $orderby = array('path');
  30. $data['pages'] = $this->MKaimonokago->getAll($this->module,$fields, $orderby);
  31. //$data['pages'] = $this->MPages->getAllPagesbyName();
  32. // show pages only english which has lang_id 0
  33. // $lang_id=0;
  34. //$data['pages'] = $this->MPages->getAllPagesbyLang($lang_id);
  35. $data['header'] = $this->lang->line('backendpro_access_control');
  36. // This how Bep load views
  37. $data['page'] = $this->config->item('backendpro_template_admin') . "admin_pages_home";
  38. $data['module'] = $this->module;
  39. $this->load->view($this->_container,$data);
  40. }
  41. function _fields(){
  42. $data = array(
  43. 'name' => db_clean($_POST['name']),
  44. 'keywords' => db_clean($_POST['keywords']),
  45. 'description' => db_clean($_POST['description']),
  46. 'path' => db_clean($_POST['path']),
  47. 'content' => $_POST['content'],
  48. 'status' => db_clean($_POST['status'],8),
  49. 'lang_id' =>$this->input->post('lang_id'),
  50. );
  51. return $data;
  52. }
  53. function create(){
  54. // We need TinyMCE, so load it
  55. $this->bep_assets->load_asset_group('TINYMCE');
  56. if ($this->input->post('name')){
  57. // if info is filled in then do this
  58. $data = $this->_fields();
  59. $this->MKaimonokago->addItem($this->module,$data);
  60. //$this->MPages->addPage();
  61. // This is CI way to show flashdata
  62. // $this->session->set_flashdata('message','Page created');
  63. // But here we use Bep way to display flash msg
  64. flashMsg('success',$this->lang->line('kago_page_created'));
  65. // and redirect to this index page
  66. redirect( $this->module.'/admin/index','refresh');
  67. }else{
  68. // this must be first visit to the creat page
  69. $data['title'] = $this->lang->line('kago_create_page');
  70. $data['menus'] = $this->MMenus->getAllMenusDisplay();
  71. // Set breadcrumb
  72. $this->bep_site->set_crumb($this->lang->line('kago_create'),'pages/admin/create');
  73. $data['header'] = $this->lang->line('backendpro_access_control');
  74. // Setting up page and telling which module
  75. $data['page'] = $this->config->item('backendpro_template_admin') . "admin_pages_create";
  76. $data['module'] = $this->module;
  77. $this->load->view($this->_container,$data);
  78. }
  79. }
  80. function edit($id=0){
  81. // we are using TinyMCE here, so load it.
  82. $this->bep_assets->load_asset_group('TINYMCE');
  83. if ($this->input->post('name')){
  84. // info is filled out, so the followings
  85. $data = $this->_fields();
  86. $this->MKaimonokago->updateItem($this->module,$data);
  87. //$this->MPages->updatePage();
  88. // This is CI way to show flashdata
  89. // $this->session->set_flashdata('message','Page updated');
  90. // But here we use Bep way to display flash msg
  91. flashMsg('success',$this->lang->line('kago_page_updated'));
  92. redirect($this->module.'/admin/index','refresh');
  93. }else{
  94. $content_id = $this->uri->segment(4);
  95. // path
  96. $path = $this->uri->segment(5);
  97. // get all the languages
  98. $data['languages'] =$this->MLangs->getLangDropDownWithId();
  99. // get translated languages
  100. $data['translanguages'] =$this->MLangs->getTransLang($this->module,$path);
  101. // set variables here
  102. $data['title'] = $this->lang->line('kago_edit_page');
  103. $data['page'] = $this->config->item('backendpro_template_admin') . "admin_pages_edit";
  104. $pagecontent = $this->MPages->getPage($content_id);
  105. $data['pagecontent'] = $pagecontent;
  106. if (!count($data['page'])){
  107. // if page is not specified redirect to index
  108. flashMsg('success',$this->lang->line('kago_no_exist'));
  109. redirect('pages/admin/index','refresh');
  110. }
  111. //$data['menus'] = $this->MMenus->getAllMenusDisplay();
  112. // Set breadcrumb
  113. $this->bep_site->set_crumb($this->lang->line('kago_edit'),'pages/admin/');
  114. // if lang_id is not 0 then they are translation
  115. /*
  116. $lang_id = $pagecontent['lang_id'];
  117. if($lang_id>0){
  118. $this->bep_site->set_crumb($this->lang->line('kago_edit_translation'),'pages/admin/edit/'.$content_id);
  119. }
  120. *
  121. */
  122. $data['header'] = $this->lang->line('backendpro_access_control');
  123. $data['module'] = $this->module;
  124. $this->load->view($this->_container,$data);
  125. }
  126. }
  127. /**
  128. *
  129. * Before delete is it should check it is used in menu, if it is so warn to change the menu
  130. * first. otherwise refuse to delete
  131. * @param <type> $id
  132. */
  133. function delete($id){
  134. $id = $this->uri->segment(5);
  135. // check if is used in menu
  136. // check omc_menus.page_uri_id is the same as omc_pages.id of the page
  137. $moduleToCheck='menus';
  138. $fieldToCheck = 'page_uri_id';
  139. $checkmenu = $this->MKaimonokago->checkItem($moduleToCheck,$fieldToCheck,$id);
  140. if(!empty($checkmenu)){
  141. //warn
  142. $data['checkmenu']=$checkmenu;
  143. flashMsg('warn',"Menu name: ".$checkmenu['name'].". ".$this->lang->line('kago_menu_exist'));
  144. // redirect to menu admin
  145. redirect('menus/admin/index','refresh');
  146. }else{
  147. // delete it
  148. $table = 'omc_'. $this->module;
  149. $this->MKaimonokago->deleteitem($table,$id);
  150. flashMsg('success',$this->lang->line('kago_page_deleted'));
  151. redirect('pages/admin/index','refresh');
  152. }
  153. }
  154. /*
  155. * moved to kaimonokago common function
  156. function changePageStatus($id){
  157. $this->MPages->changePageStatus($id);
  158. // CI way
  159. // $this->session->set_flashdata('message','Page status changed');
  160. flashMsg('success','Page status changed');
  161. redirect('pages/admin/index','refresh');
  162. }
  163. */
  164. function langcreate(){
  165. // we are using TinyMCE here, so load it.
  166. $this->bep_assets->load_asset_group('TINYMCE');
  167. if ($this->input->post('name')){
  168. // info is filled out, so the followings
  169. $data = $this->_fields();
  170. $this->MKaimonokago->addItem($this->module,$data);
  171. //$this->MPages->addPage();
  172. // This is CI way to show flashdata
  173. // $this->session->set_flashdata('message','Page updated');
  174. // But here we use Bep way to display flash msg
  175. flashMsg('success',$this->lang->line('kago_translation_added'));
  176. redirect('pages/admin/index','refresh');
  177. }else{
  178. // id of content is segment 4
  179. $id = $this->uri->segment(4);
  180. // need to send it to a view for content id
  181. $data['content_id']=$id;
  182. // path
  183. $path = $this->uri->segment(5);
  184. // language id is segment 5
  185. $lang_id = $this->uri->segment(6);
  186. $data['lang_id']=$lang_id;
  187. // check if there is no translation with this lang
  188. // this can use a model as well
  189. $checktrans =$this->MKaimonokago->checktrans($this->module,$path, $lang_id);
  190. if (count($checktrans)){
  191. //redirect with warning
  192. // flashMsg('warning',$this->lang->line('kago_translation_exists'));
  193. redirect('pages/admin/index','refresh');
  194. }
  195. // do normal thing
  196. // get all the languages
  197. $data['languages'] =$this->MLangs->getLangDropDownWithId();
  198. $data['translanguages'] =$this->MLangs->getTransLang($this->module,$path);
  199. // get language info, langname. This will be used in Title
  200. $table ='languages';
  201. $selected_lang = $this->MKaimonokago->getinfo($table,$lang_id);
  202. $data['selected_lang']= $selected_lang;
  203. // set variables here
  204. $data['title'] = $this->lang->line('kago_add_translation').ucwords($selected_lang['langname']);
  205. $data['page'] = $this->config->item('backendpro_template_admin') . "admin_lang_create";
  206. $data['pagecontent'] = $this->MPages->getPage($id);
  207. if (!count($data['page'])){
  208. // if page is not specified redirect to index
  209. flashMsg('warning',$this->lang->line('kago_no_exist'));
  210. redirect('pages/admin/index','refresh');
  211. }
  212. $selected_lang=ucfirst($selected_lang['langname']);// using this in bread crumb
  213. //$data['menus'] = $this->MMenus->getAllMenusDisplay();
  214. // Set breadcrumb
  215. $this->bep_site->set_crumb($this->lang->line('kago_edit'),'pages/admin/edit/'.$id);
  216. //$this->bep_site->set_crumb($this->lang->line('kago_add_translation').$selected_lang,'pages/admin/edit/'.$id."/".$lang_id);
  217. $data['header'] = $this->lang->line('backendpro_access_control');
  218. $data['module'] = $this->module;
  219. $this->load->view($this->_container,$data);
  220. }
  221. }
  222. }//end class
  223. ?>