/en/application/controllers/admin/homepage2.php

https://gitlab.com/anurat/earththailand · PHP · 404 lines · 224 code · 70 blank · 110 comment · 14 complexity · af29942958898af9fdd139df906d81da MD5 · raw file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. include_once APPPATH .'controllers/admin/admin_ci.php';
  3. class Homepage2 extends Admin_CI {
  4. public function __construct() {
  5. parent::__construct();
  6. }
  7. /**
  8. * Show header image page
  9. *
  10. */
  11. public function header_image() {
  12. $this->data['content'] = 'admin/homepage/header_image';
  13. $this->data['title'] = $this->lang->line( 'menu_header_image', $this->data['language'] );
  14. $this->load->view( 'admin_template', $this->data );
  15. }
  16. /**
  17. * Show link page
  18. *
  19. */
  20. public function link() {
  21. $cms_homepage = $this->cms_model->get_cms_homepage();
  22. $this->data['thai_link_list'] = $cms_homepage->get_homepages( 'thai_link' );
  23. $this->data['regional_link_list'] = $cms_homepage->get_homepages( 'regional_link' );
  24. $this->data['global_link_list'] = $cms_homepage->get_homepages( 'global_link' );
  25. $this->data['content'] = 'admin/homepage/link';
  26. $this->data['title'] = $this->lang->line( 'menu_link', $this->data['language'] );
  27. $this->lang->load( 'link', $this->data['language'] );
  28. $this->load->view( 'admin_template', $this->data );
  29. }
  30. /**
  31. * Add link
  32. *
  33. * @param string $type
  34. */
  35. public function add_link( $type ) {
  36. $this->link_page( $type );
  37. $link_name = $this->input->post( 'link_name' );
  38. if( !empty( $link_name ) ) {
  39. redirect( "admin/homepage/link" );
  40. }
  41. }
  42. /**
  43. * Update link
  44. *
  45. * @param string $type
  46. * @param int $homepage_id
  47. *
  48. */
  49. public function update_link( $type, $homepage_id ) {
  50. $this->link_page( $type, $homepage_id );
  51. $link_name = $this->input->post( 'link_name' );
  52. if( !empty( $link_name ) ) {
  53. redirect( "admin/homepage/link" );
  54. }
  55. }
  56. /**
  57. * Remove link
  58. *
  59. * @param int $homepage_id
  60. */
  61. public function remove_link( $homepage_id ) {
  62. $cms_homepage = $this->cms_model->get_cms_homepage();
  63. $cms_homepage->delete_homepage( $homepage_id );
  64. redirect( "admin/homepage/link" );
  65. }
  66. /**
  67. * Show slideshow page
  68. *
  69. */
  70. public function slideshow() {
  71. $this->data['content'] = 'admin/homepage/slideshow';
  72. $this->data['title'] = $this->lang->line( 'menu_slideshow', $this->data['language'] );
  73. $this->load->view( 'admin_template', $this->data );
  74. }
  75. /**
  76. * Show news slideshow page
  77. *
  78. */
  79. public function news_slideshow() {
  80. $cms_homepage = $this->cms_model->get_cms_homepage();
  81. $this->data['homepage_list'] = $cms_homepage->get_homepages( 'news_slideshow' );
  82. $this->data['content'] = 'admin/homepage/news_slideshow';
  83. $this->data['title'] = $this->lang->line( 'menu_news_slideshow', $this->data['language'] );
  84. $this->lang->load( 'news_slideshow', $this->data['language'] );
  85. $this->load->view( 'admin_template', $this->data );
  86. }
  87. /**
  88. * Add news slideshow
  89. *
  90. *
  91. */
  92. public function add_news_slideshow() {
  93. $cms_category = $this->cms_model->get_cms_category();
  94. $cms_homepage = $this->cms_model->get_cms_homepage();
  95. $content_type = $this->input->post('content_type');
  96. if( !empty( $content_type ) ) {
  97. $content_title = $this->input->post('content_title');
  98. $table = '';
  99. $table_id = 0;
  100. $obj = null;
  101. switch( $content_type ) {
  102. case Cms_category::MULTIMEDIA_CAT:
  103. $table = 'multimedia';
  104. $cms_multimedia = $this->cms_model->get_cms_multimedia();
  105. $obj = $cms_multimedia->get_multimedia_by_title( $content_title );
  106. $table_id = $obj->get_multimedia_id();
  107. break;
  108. case Cms_category::GALLERY_CAT:
  109. $table = 'gallery';
  110. $cms_gallery = $this->cms_model->get_cms_gallery();
  111. $obj = $cms_gallery->get_gallery_by_title( $content_title );
  112. $table_id = $obj->get_gallery_id();
  113. break;
  114. case Cms_category::DOCUMENT_CAT:
  115. $table = 'document';
  116. $cms_document = $this->cms_model->get_cms_document();
  117. $obj = $cms_document->get_document_by_title( $content_title );
  118. $table_id = $obj->get_document_id();
  119. break;
  120. case Cms_category::ARTICLE_CAT:
  121. $table = 'article';
  122. $cms_article = $this->cms_model->get_cms_article();
  123. $obj = $cms_article->get_article_by_title( $content_title );
  124. $table_id = $obj->get_article_id();
  125. break;
  126. }
  127. if( !empty( $obj ) ) {
  128. $cms_homepage->add_homepage( 'news_slideshow', $table_id,
  129. $obj->get_list_title(), $obj->get_list_desc(), $obj->get_list_img(),
  130. $table, "/{$table}/{$table_id}" );
  131. redirect( "admin/homepage/news_slideshow" );
  132. }
  133. else {
  134. $this->data['error'] = 'Unable to find content.';
  135. }
  136. }
  137. $this->data['cat_list'] = $cms_category->get_main_categories();
  138. $this->data['content'] = 'admin/homepage/add_news_slideshow';
  139. $this->data['title'] = $this->lang->line( 'menu_add_news_slideshow', $this->data['language'] );
  140. $this->lang->load( 'news_slideshow', $this->data['language'] );
  141. $this->load->view( 'admin_template', $this->data );
  142. }
  143. /**
  144. * Update news slideshow
  145. *
  146. * @param int $homepage_id
  147. *
  148. */
  149. public function update_news_slideshow( $homepage_id ) {
  150. $cms_category = $this->cms_model->get_cms_category();
  151. $cms_homepage = $this->cms_model->get_cms_homepage();
  152. $title = $this->input->post('title');
  153. if( !empty( $title ) ) {
  154. $description = $this->input->post( 'editor1' );
  155. $image = $this->input->post( 'news_slideshow_img' );
  156. $ns = $cms_homepage->get_homepage( $homepage_id );
  157. $cms_homepage->update_homepage( $homepage_id, $ns->get_table(), $ns->get_table_id(),
  158. $title, $description, $image, $ns->get_link_name(), $ns->get_link_url() );
  159. redirect( "admin/homepage/news_slideshow" );
  160. }
  161. $this->data['cat_list'] = $cms_category->get_main_categories();
  162. $this->data['news_slideshow'] = $cms_homepage->get_homepage( $homepage_id );
  163. $this->data['content'] = 'admin/homepage/update_news_slideshow';
  164. $this->data['title'] = $this->lang->line( 'menu_update_news_slideshow', $this->data['language'] )
  165. .'-' .$this->data['news_slideshow']->get_title();
  166. $this->lang->load( 'article', $this->data['language'] );
  167. $this->load->view( 'admin_template', $this->data );
  168. }
  169. /**
  170. * Remove news slideshow
  171. *
  172. * @param int $homepage_id
  173. */
  174. public function remove_news_slideshow( $homepage_id ) {
  175. $cms_homepage = $this->cms_model->get_cms_homepage();
  176. $cms_homepage->delete_homepage( $homepage_id );
  177. redirect( "admin/homepage/news_slideshow" );
  178. }
  179. /**
  180. * Show documents page
  181. *
  182. */
  183. public function documents() {
  184. $cms_homepage = $this->cms_model->get_cms_homepage();
  185. $this->data['homepage_list'] = $cms_homepage->get_homepages( 'document' );
  186. $this->data['content'] = 'admin/homepage/documents';
  187. $this->data['title'] = $this->lang->line( 'menu_documents', $this->data['language'] );
  188. $this->lang->load( 'document', $this->data['language'] );
  189. $this->load->view( 'admin_template', $this->data );
  190. }
  191. /**
  192. * Update a document item in homepage
  193. *
  194. * @param int $document_id
  195. *
  196. */
  197. public function update_document( $document_id ) {
  198. $this->update_homepage( 'document', $document_id );
  199. $title = $this->input->post( 'title' );
  200. if( !empty( $title ) ) {
  201. redirect( 'admin/homepage/documents' );
  202. }
  203. }
  204. /**
  205. * Remove a document from homepage
  206. *
  207. * @param int $homepage_id
  208. *
  209. */
  210. public function remove_document( $homepage_id ) {
  211. $cms_homepage = $this->cms_model->get_cms_homepage();
  212. $cms_homepage->delete_homepage( $homepage_id );
  213. redirect( "admin/homepage/documents" );
  214. }
  215. /**
  216. * Show articles page
  217. *
  218. */
  219. public function articles() {
  220. $cms_homepage = $this->cms_model->get_cms_homepage();
  221. $this->data['homepage_list'] = $cms_homepage->get_homepages( 'article' );
  222. $this->data['content'] = 'admin/homepage/articles';
  223. $this->data['title'] = $this->lang->line( 'menu_articles', $this->data['language'] );
  224. $this->lang->load( 'article', $this->data['language'] );
  225. $this->load->view( 'admin_template', $this->data );
  226. }
  227. /**
  228. * Update an article item in homepage
  229. *
  230. * @param int $article_id
  231. *
  232. */
  233. public function update_article( $article_id ) {
  234. $this->update_homepage( 'article', $article_id );
  235. $title = $this->input->post( 'title' );
  236. if( !empty( $title ) ) {
  237. redirect( 'admin/homepage/articles' );
  238. }
  239. }
  240. /**
  241. * Remove an article from homepage
  242. *
  243. * @param int $homepage_id
  244. *
  245. */
  246. public function remove_article( $homepage_id ) {
  247. $cms_homepage = $this->cms_model->get_cms_homepage();
  248. $cms_homepage->delete_homepage( $homepage_id );
  249. redirect( "admin/homepage/articles" );
  250. }
  251. /**
  252. * Show tags page
  253. *
  254. * @param string $query
  255. */
  256. public function tags( $query=null ) {
  257. $search = urldecode( $query );
  258. $cms_tag = $this->cms_model->get_cms_tag();
  259. if( !empty( $query ) ) {
  260. $tags = $cms_tag->search( $search );
  261. }
  262. else {
  263. $tags = $cms_tag->get_tag_list();
  264. }
  265. $this->data['search'] = $search;
  266. $this->data['tags'] = $tags;
  267. $this->data['content'] = 'admin/homepage/tags';
  268. $this->data['title'] = $this->lang->line( 'menu_tags', $this->data['language'] );
  269. $this->lang->load( 'tag', $this->data['language'] );
  270. $this->load->view( 'admin_template', $this->data );
  271. }
  272. /**
  273. * Show tag detail
  274. *
  275. * @param int $tag_id
  276. *
  277. */
  278. public function tag( $tag_id ) {
  279. $cms_tag = $this->cms_model->get_cms_tag();
  280. $this->data['tag'] = $cms_tag->get_tag( $tag_id );
  281. $this->data['tag_links'] = $cms_tag->get_tag_links( $tag_id );
  282. $this->data['content'] = 'admin/homepage/tag';
  283. $this->data['title'] = $this->lang->line( 'menu_tag_detail', $this->data['language'] )
  284. .'-' .$this->data['tag']->get_name();
  285. $this->lang->load( 'tag', $this->data['language'] );
  286. $this->load->view( 'admin_template', $this->data );
  287. }
  288. /**
  289. * Remove tag
  290. *
  291. * @param int $tag_id
  292. *
  293. */
  294. public function remove_tag( $tag_id ) {
  295. $cms_tag = $this->cms_model->get_cms_tag();
  296. $cms_tag->delete_tag( $tag_id );
  297. redirect( "/admin/homepage/tags" );
  298. }
  299. /**
  300. * Remove tag link
  301. *
  302. * @param int $tag_link_id
  303. *
  304. */
  305. public function remove_tag_link( $tag_link_id ) {
  306. $cms_tag = $this->cms_model->get_cms_tag();
  307. $tag_id = $cms_tag->get_tag_link( $tag_link_id )->get_tag_id();
  308. $cms_tag->delete_tag_link( $tag_link_id );
  309. redirect( "/admin/homepage/tag/" .$tag_id );
  310. }
  311. /**
  312. * Show footer page
  313. *
  314. */
  315. public function footer() {
  316. $filepath = APPPATH .'views/footer.php';
  317. $editor1 = $this->input->post( 'editor1' );
  318. if( !empty( $editor1 ) ) {
  319. $no = file_put_contents( $filepath, $editor1 );
  320. if( $no ) {
  321. $this->data['result'] = 'Save file successfully.';
  322. }
  323. else {
  324. $this->data['result'] = 'Error saving file.';
  325. }
  326. }
  327. $this->data['footer'] = file_get_contents( $filepath );
  328. $this->data['content'] = 'admin/homepage/footer';
  329. $this->data['title'] = $this->lang->line( 'menu_footer', $this->data['language'] );
  330. $this->load->view( 'admin_template', $this->data );
  331. }
  332. }
  333. /* End of file homepage.php */
  334. /* Location: ./application/controllers/admin/homepage.php */