PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/category/controllers/admin.php

https://github.com/coderlabs/Kaimonokago
PHP | 292 lines | 170 code | 42 blank | 80 comment | 14 complexity | 5f53f2a5a37eac41d6f760a82a42e66a 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('Category');
  8. $this->load->model('MCats');
  9. $this->module=basename(dirname(dirname(__FILE__)));
  10. //$this->module='category';
  11. // Set breadcrumb
  12. $this->bep_site->set_crumb($this->lang->line('backendpro_category'),$this->module.'/admin');
  13. mb_internal_encoding('UTF-8');
  14. }
  15. function index(){
  16. $data['title'] = $this->lang->line('kago_category');
  17. $fields = array('id', 'name','parentid','status','table_id','lang_id');
  18. $orderby = array('lang_id','parentid','table_id');
  19. //$data['categories'] = $this->MCats->getAllCategories();
  20. $data['categories'] = $this->MKaimonokago->getAll($this->module,$fields, $orderby);
  21. $data['header'] = $this->lang->line('backendpro_access_control');
  22. $data['page'] = $this->config->item('backendpro_template_admin') . "admin_cat_home";
  23. $data['module'] = $this->module;
  24. $this->load->view($this->_container,$data);
  25. function create(){
  26. $this->bep_assets->load_asset_group('TINYMCE');
  27. if ($this->input->post('name')){
  28. $data = array(
  29. 'name' => db_clean($_POST['name']),
  30. 'shortdesc' => db_clean($_POST['shortdesc']),
  31. 'longdesc' => db_clean($_POST['longdesc'],5000),
  32. 'status' => db_clean($_POST['status'],8),
  33. 'parentid' => id_clean($_POST['parentid']),
  34. 'lang_id' => id_clean($_POST['lang_id']),
  35. 'table_id' => id_clean($_POST['table_id'])
  36. );
  37. //$this->MCats->addCategory();
  38. $this->MKaimonokago->addItem($this->module, $data);
  39. $string = $this->input->post('name');
  40. // createdirname function is from plugin mytools.php
  41. $folder = createdirname($string);
  42. $folder = 'assets/images/'.$folder;
  43. create_path($folder);
  44. // we used to use like this. $this->session->set_flashdata('message','Category created');
  45. // now we are using Bep's flashMsg function to show messages.
  46. flashMsg('success',$this->lang->line('userlib_category_created'));
  47. //redirect($this->module.'/admin/index','refresh');
  48. }else{
  49. $data['title'] = "Create Category";
  50. $data['categories'] = $this->MCats->getTopCategories();
  51. //$data['right'] = 'admin/category_right';
  52. // Set breadcrumb
  53. $this->bep_site->set_crumb($this->lang->line('userlib_create')." category",'category/admin/create');
  54. $data['header'] = $this->lang->line('backendpro_access_control');
  55. // This is how BackendPro do
  56. $data['page'] = $this->config->item('backendpro_template_admin') . "admin_cat_create";
  57. $data['module'] = $this->module;
  58. $this->load->view($this->_container,$data);
  59. }
  60. }
  61. function edit($id=0){
  62. $this->bep_assets->load_asset_group('TINYMCE');
  63. if ($this->input->post('name')){
  64. $this->MCats->updateCategory();
  65. flashMsg('success',$this->lang->line('userlib_category_updated'));
  66. redirect('category/admin/index','refresh');
  67. }else{
  68. // similar to menus
  69. $data['title'] = $this->lang->line('kago_edit')." ".$this->lang->line('kago_category');
  70. // get all the languages
  71. $data['languages'] =$this->MLangs->getLangDropDownWithId();
  72. // get translated languages
  73. // For other languages segment 4 is omc_categroy.table_id, table_id is id of english(original), omc_category.id
  74. // for english is omc_category.id
  75. // $table_id is used to find translated languages and it is used to get info of english menu
  76. $table_id = $this->uri->segment(4);
  77. // segment 5 is not used in category
  78. // segment 5 is omc_category.page_uri_id. page_uri_id is omc_pages.id which the menu is using for a page
  79. // page_uri_id is sent to a view. This is used to add page_uri_id in omc_menus.
  80. //$page_uri_id = $this->uri->segment(5);
  81. //$data['page_uri_id']= $page_uri_id;
  82. // translanguages shows translated languages by checking the same page_uri_id
  83. $data['translanguages'] =$this->MLangs->getTransLang($this->module,$table_id);
  84. $data['page'] = $this->config->item('backendpro_template_admin') . "admin_cat_edit";
  85. $category = $this->MCats->getCategory($id);
  86. $data['category'] = $category;
  87. $data['module']=$this->module;
  88. //$data['categories'] = $this->MCats->getTopCategories();
  89. $lang_id = $category['lang_id'];
  90. $data['categories'] = $this->MCats->getTopCategories($lang_id);
  91. $data['right'] = 'admin/category_right';
  92. if (!count($data['category'])){
  93. redirect('admin/category/index','refresh');
  94. }
  95. // Set breadcrumb
  96. $this->bep_site->set_crumb($this->lang->line('kago_edit'),'category/admin/edit');
  97. $data['header'] = $this->lang->line('backendpro_access_control');
  98. $data['module'] = $this->module;
  99. $this->load->view($this->_container,$data);
  100. }
  101. }
  102. function delete($id){
  103. // delete button is hidden in the page, but
  104. // check if parentid is not 0
  105. $cate = $this->MCats->getCategory($id);
  106. $parentid = $cate['parentid'];
  107. if(!$parentid==0){
  108. $cat = $this->MCats->getCategory($id);
  109. $string = $cat['name'];
  110. $catname = createdirname($string);
  111. $catname = 'assets/images/'.$catname;
  112. recursive_remove_directory($catname, $empty=FALSE);
  113. $orphans = $this->MCats->checkOrphans($id);
  114. if (count($orphans)){
  115. $this->session->set_userdata('orphans',$orphans);
  116. redirect('category/admin/reassign/'.$id,'refresh');
  117. }else{
  118. $this->MCats->deleteCategory($id);
  119. flashMsg('success',$this->lang->line('userlib_category_deleted'));
  120. redirect('category/admin/index','refresh');
  121. }
  122. } else {
  123. $this->MCats->deleteCategory($id);
  124. flashMsg('success',$this->lang->line('userlib_category_deleted'));
  125. redirect('category/admin/index','refresh');
  126. }
  127. }
  128. function export(){
  129. $this->load->helper('download');
  130. $csv = $this->MCats->exportCsv();
  131. $name = "category_export.csv";
  132. force_download($name,$csv);
  133. }
  134. function reassign($id=0){
  135. if ($_POST){
  136. $this->load->module_model('products','MProducts');
  137. $this->MProducts->reassignProducts();
  138. $id = $this->input->post('id');
  139. $this->MCats->deleteCategory($id); // this is not working at the moment.
  140. flashMsg('success',$this->lang->line('userlib_category_reassigned'));
  141. redirect('category/admin/index','refresh');
  142. }else{
  143. //$id = $this->uri->segment(4);
  144. $data['category'] = $this->MCats->getCategory($id);
  145. $data['title'] = "Reassign Products";
  146. $data['header'] = $this->lang->line('backendpro_access_control');
  147. $data['categories'] = $this->MCats->getCategoriesDropDown();
  148. // Set breadcrumb
  149. $this->bep_site->set_crumb($this->lang->line('userlib_category_reassign'),'category/admin/reassign');
  150. $data['page'] = $this->config->item('backendpro_template_admin') . "admin_cat_reassign";
  151. $data['module'] = $this->module;
  152. $this->load->view($this->_container,$data);
  153. }
  154. }
  155. function changeCatStatus($id){
  156. //$id = $this->uri->segment(4);
  157. $this->MCats->changeCatStatus($id);
  158. flashMsg('success',$this->lang->line('userlib_category_status'));
  159. redirect('category/admin/index','refresh');
  160. }
  161. function _remove_path($folder){
  162. $files = glob( $folder . DIRECTORY_SEPARATOR . '*');
  163. foreach( $files as $file ){
  164. if($file == '.' || $file == '..'){continue;}
  165. if(is_dir($file)){
  166. $this->_remove_path( $file );
  167. }else{
  168. unlink( $file );
  169. }
  170. }
  171. rmdir( $folder );
  172. }
  173. function langcreate(){
  174. $this->bep_assets->load_asset_group('TINYMCE');
  175. if ($this->input->post('name')){
  176. // info is filled out, so the followings
  177. $this->MCats->addCategory();
  178. // This is CI way to show flashdata
  179. // $this->session->set_flashdata('message','Page updated');
  180. // But here we use Bep way to display flash msg
  181. flashMsg('success',$this->lang->line('kago_translation_added'));
  182. redirect('category/admin/index','refresh');
  183. }else{
  184. // segment 4 is table_id
  185. $table_id = $this->uri->segment(4);
  186. // need to send it to a view for table_id
  187. $data['table_id']=$table_id;
  188. // page_uri_id is in segment 5
  189. //$page_uri_id = $this->uri->segment(5);
  190. //$data['page_uri_id']= $page_uri_id;
  191. // language id is in segment 5
  192. $lang_id = $this->uri->segment(5);
  193. $data['lang_id']=$lang_id;
  194. // no need for menu path
  195. //$path = $this->uri->segment(6);
  196. // check if there is no translation with this lang
  197. // this can use a model as well
  198. //$checktrans = $this->MKaimonokago->checktrans($this->module, $id, $lang_id);
  199. //if (count($checktrans)){
  200. // there is translation of this language
  201. //redirect with warning
  202. //flashMsg('warning',$this->lang->line('kago_translation_exists'));
  203. //redirect('menus/admin/index','refresh');
  204. //}
  205. // do normal thing
  206. // get all the languages
  207. $data['languages'] =$this->MLangs->getLangDropDownWithId();
  208. // get all the translated languages
  209. //$id =
  210. //$data['translanguages'] =$this->MLangs->getTransLang($this->module,$id);
  211. $data['translanguages'] =$this->MLangs->getTransLang($this->module,$table_id);
  212. //$data['translanguages'] =$this->MLangs->getTransLang($this->module,$page_uri_id);
  213. // get language info, langname. This will be used in Title
  214. $table ='languages';
  215. $selected_lang = $this->MKaimonokago->getinfo($table,$lang_id);
  216. $data['selected_lang']= $selected_lang;
  217. // this must pull only pages where the segment 6 which is lang id
  218. // then use dropdown to select page
  219. // then use dropdown to select page
  220. //$data['pages'] = $this->MPages->getIdwithnone();
  221. /*
  222. $data['pages'] = $this->MPages->getIdwithnoneLang($lang_id);
  223. $lang_id = $this->uri->segment(6);
  224. $data['menus'] = $this->MMenus->getAllMenusDisplayByLang($lang_id);
  225. */ $data['category'] = $this->MCats->getCategory($table_id);
  226. // get category by lang
  227. //$data['categories'] = $this->MCats->getCategoriesbyLang($lang_id);
  228. $data['categories'] = $this->MCats->getTopCategories($lang_id);
  229. // set variables here
  230. $data['title'] = $this->lang->line('kago_add_translation').ucwords($selected_lang['langname']);
  231. $data['page'] = $this->config->item('backendpro_template_admin') . "admin_lang_create";
  232. // send the parent(English) field data to use it for other languages
  233. //$data['menu'] = $this->MMenus->getMenu($id);
  234. //if (!count($data['menu'])){
  235. // if page is not specified redirect to index
  236. // flashMsg('warning',$this->lang->line('kago_no_exists'));
  237. // redirect('menus/admin/index','refresh');
  238. //}
  239. $selected_lang=ucfirst($selected_lang['langname']);// using this in bread crumb
  240. //$data['menus'] = $this->MMenus->getAllMenusDisplay();
  241. // Set breadcrumb
  242. $this->bep_site->set_crumb($this->lang->line('kago_edit_home'),'menus/admin/edit/');
  243. //$this->bep_site->set_crumb($this->lang->line('kago_add_translation').$selected_lang,'menus/admin/edit/'.$id."/".$lang_id);
  244. $data['header'] = $this->lang->line('backendpro_access_control');
  245. $data['module'] = $this->module;
  246. $this->load->view($this->_container,$data);
  247. }
  248. }
  249. }//end class
  250. ?>