PageRenderTime 54ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/appl/models/promo_model.php

https://bitbucket.org/gan_kwok_wei/th-wcms-sandbox
PHP | 431 lines | 287 code | 59 blank | 85 comment | 48 complexity | 4ab2231b5091f6f3c4d95a3bd1c0546d MD5 | raw file
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * PHP 5
  4. *
  5. * GreenLabGroup Application System Environment (GreASE)
  6. * GreenLabGroup(tm) : Rapid Development Framework (http://www.greenlabgroup.com)
  7. * Copyright 2011-2012, P.T. Green Lab Group.
  8. *
  9. * Licensed under The MIT License
  10. * Redistributions of files must retain the above copyright notice.
  11. *
  12. * @filesource promo_model.php
  13. * @copyright Copyright 2011-2012, P.T. Green Lab Group.
  14. * @author nico
  15. * @package
  16. * @subpackage
  17. * @since Oct 9, 2012
  18. * @version
  19. * @modifiedby budi.lx
  20. * @lastmodified
  21. *
  22. *
  23. */
  24. class Promo_model extends GE_Model {
  25. /**
  26. * Enter description here ...
  27. */
  28. function __construct() {
  29. parent::__construct();
  30. // echo "<!--";
  31. // var_dump($_POST);
  32. // echo "-->";
  33. }
  34. /**
  35. * Enter description here ...
  36. * @return multitype:string
  37. */
  38. function get_promo_list($hotel_id = NULL) {
  39. if($hotel_id != NULL) {
  40. $this->db->where('hotel.hotel_id', $hotel_id);
  41. }
  42. $this->db->select('promo.*, city.city_name, hotel.hotel_name')
  43. ->from('promo')
  44. ->join('hotel', 'hotel.hotel_id = promo.hotel_id')
  45. ->join('city', 'city.city_id = hotel.city_id')
  46. ->order_by('hotel.sort');
  47. return $this->db->get();
  48. }
  49. /**
  50. * Enter description here ...
  51. * @return multitype:string
  52. */
  53. function get_promo($promo_id) {
  54. return $this->db->get_where('promo', array('promo_id' => $promo_id));
  55. }
  56. /**
  57. * Enter description here ...
  58. */
  59. function save_list_promo() {
  60. unset($_POST['btnSave']);
  61. foreach($_POST['sort'] as $id => $val) {
  62. $this->db->where('promo_id', $id);
  63. $this->db->update('promo', array('sort' => $val));
  64. }
  65. set_success_message(sprintf(lang('success_edit'), 'promo'));
  66. }
  67. /**
  68. * Enter description here ...
  69. */
  70. function save_promo() {
  71. unset($_POST['action']);
  72. unset($_POST['btnSave']);
  73. $this->load->library('form_validation');
  74. $this->form_validation->set_rules('promo_name', lang('label_promo'), 'trim|required|xss_clean');
  75. switch ($_POST['mode']) {
  76. case 'add':
  77. unset($_POST['mode']);
  78. if ($this->form_validation->run() != FALSE){// echo 'valid';
  79. $promo['promo_name'] = $_POST['promo_name'];
  80. // $promo['city_id'] = $_POST['city_id'];
  81. $promo['hotel_id'] = $_POST['hotel_id'];
  82. // $promo['display_pos'] = $_POST['display_pos'];
  83. // $promo['page_id'] = $_POST['page_id'];
  84. $promo['tags'] = $_POST['tags'];
  85. $promo['valid_from'] = $_POST['valid_from'];
  86. $promo['valid_to'] = $_POST['valid_to'];
  87. $promo['sort'] = $_POST['sort'];
  88. $promo['created_id'] = get_user_id();
  89. $this->db->insert('promo', $promo);
  90. $promo_id = $this->db->insert_id();
  91. foreach($_POST['language'] as $lang_k => $lang_v) {
  92. if($_POST['title'][$lang_k] != '') {
  93. $text = array();
  94. $text['content_text_type'] = 'promo';
  95. $text['parent_id'] = $promo_id;
  96. $text['title'] = $_POST['title'][$lang_k];
  97. // $text['icon'] = $_POST['icon'][$lang_k];
  98. // $text['image'] = $_POST['image'][$lang_k];
  99. $text['teaser'] = $_POST['teaser'][$lang_k];
  100. $text['content'] = $_POST['content'][$lang_k];
  101. $text['icon_1'] = $_POST['icon_1'][$lang_k];
  102. $text['image_1'] = $_POST['image_1'][$lang_k];
  103. // $text['teaser_1'] = $_POST['teaser_1'][$lang_k];
  104. // $text['content_1'] = $_POST['content_1'][$lang_k];
  105. $text['link'] = $_POST['link'][$lang_k];
  106. $text['language'] = $_POST['language'][$lang_k];
  107. if(!isset($_POST['country'][$lang_k])) {
  108. $_POST['country'][$lang_k] = $this->config->item('ge_def_country');
  109. }
  110. $text['country'] = implode('|', $_POST['country'][$lang_k]);
  111. $this->db->insert('content_text', $text);
  112. }
  113. }
  114. foreach($_POST['page_id'] as $display_k => $display_v) {
  115. if($display_v != '') {
  116. $display = array();
  117. $display['promo_id'] = $promo_id;
  118. $display['page_id'] = $_POST['page_id'][$display_k];
  119. $display['hotel_id'] = ($_POST['page_id'][$display_k] != 2) ? 0 : $_POST['hotel_row'][$display_k];
  120. // $display['display_pos'] = $_POST['display_pos'][$display_k];
  121. $this->db->insert('promo_display', $display);
  122. }
  123. }
  124. set_success_message(sprintf(lang('success_add'), 'promo'));
  125. redirect('system/promo');
  126. exit;
  127. }
  128. break;
  129. case 'edit':
  130. unset($_POST['mode']);
  131. if ($this->form_validation->run() != FALSE){// echo 'valid';
  132. if(!isset($_POST['hot'])) {
  133. $_POST['hot'] = 0;
  134. }
  135. if(!isset($_POST['status'])) {
  136. $_POST['status'] = 0;
  137. }
  138. $promo['promo_name'] = $_POST['promo_name'];
  139. $promo['hotel_id'] = $_POST['hotel_id'];
  140. // $promo['display_pos'] = $_POST['display_pos'];
  141. // $promo['page_id'] = $_POST['page_id'];
  142. $promo['tags'] = $_POST['tags'];
  143. $promo['valid_from'] = $_POST['valid_from'];
  144. $promo['valid_to'] = $_POST['valid_to'];
  145. $promo['hot'] = $_POST['hot'];
  146. $promo['status'] = $_POST['status'];
  147. $promo['sort'] = $_POST['sort'];
  148. $promo['modified_id'] = get_user_id();
  149. $promo['modified_time'] = date('Y-m-d H:i:s');
  150. $this->db->where('promo_id', $_POST['promo_id']);
  151. $this->db->update('promo', $promo);
  152. foreach($_POST['language'] as $lang_k => $lang_v) {
  153. if($_POST['title'][$lang_k] != '') {
  154. // $this->db->where(array('parent_id' => $_POST['promo_id'], 'content_text_type' => 'promo', 'language' => $_POST['language'][$lang_k]));
  155. $text = array();
  156. $text['title'] = $_POST['title'][$lang_k];
  157. // $text['icon'] = $_POST['icon'][$lang_k];
  158. // $text['image'] = $_POST['image'][$lang_k];
  159. $text['teaser'] = $_POST['teaser'][$lang_k];
  160. $text['content'] = $_POST['content'][$lang_k];
  161. $text['icon_1'] = $_POST['icon_1'][$lang_k];
  162. $text['image_1'] = $_POST['image_1'][$lang_k];
  163. // $text['teaser_1'] = $_POST['teaser_1'][$lang_k];
  164. // $text['content_1'] = $_POST['content_1'][$lang_k];
  165. $text['link'] = $_POST['link'][$lang_k];
  166. if(!isset($_POST['country'][$lang_k])) {
  167. $_POST['country'][$lang_k] = $this->config->item('ge_def_country');
  168. }
  169. $text['country'] = implode('|', $_POST['country'][$lang_k]);
  170. if($_POST['content_text_id'][$lang_k] != '0') {
  171. $this->db->where(array('content_text_id' => $_POST['content_text_id'][$lang_k]));
  172. $this->db->update('content_text', $text);
  173. } else {
  174. $text['parent_id'] = $_POST['promo_id'];
  175. $text['content_text_type'] = 'promo';
  176. $text['language'] = $_POST['language'][$lang_k];
  177. $this->db->insert('content_text', $text);
  178. }
  179. }
  180. }
  181. foreach($_POST['page_id'] as $display_k => $display_v) {
  182. if($display_v != '') {
  183. $display = array();
  184. $display['promo_id'] = $_POST['promo_id'];
  185. $display['page_id'] = $_POST['page_id'][$display_k];
  186. $display['hotel_id'] = ($_POST['page_id'][$display_k] != 2) ? 0 : $_POST['hotel_row'][$display_k];
  187. // $display['display_pos'] = $_POST['display_pos'][$display_k];
  188. if((isset($_POST['promo_display_id'])) && $_POST['promo_display_id'][$display_k] != '0') {
  189. $this->db->where(array('promo_display_id' => $_POST['promo_display_id'][$display_k]));
  190. $this->db->update('promo_display', $display);
  191. } else {
  192. $this->db->insert('promo_display', $display);
  193. }
  194. } else {
  195. $this->db->where(array('promo_display_id' => $_POST['promo_display_id'][$display_k]));
  196. $this->db->delete('promo_display');
  197. }
  198. }
  199. set_success_message(sprintf(lang('success_edit'), 'content'));
  200. redirect('system/promo/promo_edit/' . $_POST['promo_id']);
  201. exit;
  202. }
  203. break;
  204. case 'delete':
  205. break;
  206. }
  207. }
  208. function get_promo_display_list($promo_id) {
  209. return $this->db->get_where('promo_display', array('promo_id' => $promo_id));
  210. }
  211. /**
  212. * Enter description here ...
  213. * @return multitype:string
  214. */
  215. function get_campaign_list($parent_id = NULL) {
  216. if($parent_id != NULL) {
  217. return $this->db->get_where('campaign', array('parent_id' => $parent_id));
  218. } else {
  219. return $this->db->get('campaign');
  220. }
  221. }
  222. /**
  223. * Enter description here ...
  224. * @return multitype:string
  225. */
  226. function get_campaign($campaign_id) {
  227. return $this->db->get_where('campaign', array('campaign_id' => $campaign_id));
  228. }
  229. /**
  230. * Enter description here ...
  231. * @return multitype:string
  232. */
  233. function get_banner_list() {
  234. $this->db->select('banner.*, banner_category.title category_title')
  235. ->from('banner')
  236. ->join('banner_category', 'banner_category.banner_category_id = banner.banner_category_id')
  237. ->order_by('banner.banner_category_id, banner.sort');
  238. return $this->db->get();
  239. }
  240. /**
  241. * Enter description here ...
  242. * @return multitype:string
  243. */
  244. function get_campaign_banner_list($campaign_id) {
  245. $this->db->select('banner.*, banner_category.title category_title')
  246. ->from('banner')
  247. ->join('banner_category', 'banner_category.banner_category_id = banner.banner_category_id')
  248. ->where('campaign_id', $campaign_id)
  249. ->order_by('banner.banner_category_id, banner.sort');
  250. return $this->db->get();
  251. }
  252. /**
  253. * Enter description here ...
  254. * @return multitype:string
  255. */
  256. function get_campaign_promo_list($campaign_id) {
  257. $this->db->select('promo.*, hotel.hotel_name')
  258. ->from('promo')
  259. ->join('hotel', 'hotel.hotel_id = promo.hotel_id')
  260. ->where('promo.campaign_id', $campaign_id)
  261. ->order_by('hotel.sort');
  262. return $this->db->get();
  263. }
  264. /**
  265. * Enter description here ...
  266. */
  267. function save_campaign() {
  268. unset($_POST['action']);
  269. unset($_POST['btnSave']);
  270. $this->load->library('form_validation');
  271. $this->form_validation->set_rules('title', lang('label_title'), 'trim|required');
  272. if(!isset($_POST['campaign_name'])) {
  273. $campaign['campaign_name'] = underscore($_POST['title']);
  274. }
  275. switch ($_POST['mode']) {
  276. case 'add':
  277. unset($_POST['mode']);
  278. if ($this->form_validation->run() != FALSE){// echo 'valid';
  279. $campaign['title'] = $_POST['title'];
  280. $campaign['note'] = $_POST['note'];
  281. $campaign['valid_from'] = $_POST['valid_from'];
  282. $campaign['valid_to'] = $_POST['valid_to'];
  283. $campaign['status'] = 0;
  284. $campaign['created_id'] = get_user_id();
  285. if($this->db->insert('campaign', $campaign)) {
  286. $campaign_id = $this->db->insert_id();
  287. if(isset($_POST['banner_id'])){
  288. foreach($_POST['banner_id'] as $banner_id) {
  289. $banner = array();
  290. $banner['campaign_id'] = $campaign_id;
  291. $banner['publish_date_start'] = $_POST['valid_from'];
  292. $banner['publish_date_end'] = $_POST['valid_to'];
  293. $banner['status'] = 0;
  294. $this->db->where(array('banner_id' => $banner_id));
  295. $this->db->update('banner', $banner);
  296. }
  297. }
  298. if(isset($_POST['promo_id'])){
  299. foreach($_POST['promo_id'] as $promo_id) {
  300. $promo = array();
  301. $promo['campaign_id'] = $campaign_id;
  302. $promo['valid_from'] = $_POST['valid_from'];
  303. $promo['valid_to'] = $_POST['valid_to'];
  304. $promo['status'] = 0;
  305. $this->db->where(array('promo_id' => $promo_id));
  306. $this->db->update('promo', $promo);
  307. }
  308. }
  309. set_success_message(sprintf(lang('success_add'), 'campaign'));
  310. redirect('system/promo/campaign_edit/' . $campaign_id);
  311. exit;
  312. } else {
  313. set_error_message('Insert Failed!');
  314. }
  315. }
  316. break;
  317. case 'edit':
  318. unset($_POST['mode']);
  319. if ($this->form_validation->run() != FALSE){// echo 'valid';
  320. if(!isset($_POST['status'])) {
  321. $_POST['status'] = 0;
  322. }
  323. $campaign['title'] = $_POST['title'];
  324. $campaign['note'] = $_POST['note'];
  325. $campaign['valid_from'] = $_POST['valid_from'];
  326. $campaign['valid_to'] = $_POST['valid_to'];
  327. $campaign['status'] = $_POST['status'];
  328. $campaign['modified_id'] = get_user_id();
  329. $campaign['modified_time'] = date('Y-m-d H:i:s');
  330. $this->db->where('campaign_id', $_POST['campaign_id']);
  331. if($this->db->update('campaign', $campaign)) {
  332. $this->db->where(array('campaign_id' => $_POST['campaign_id']));
  333. $this->db->update('banner', array('campaign_id' => 0));
  334. if(isset($_POST['banner_id'])){
  335. foreach($_POST['banner_id'] as $banner_id) {
  336. $banner = array();
  337. $banner['campaign_id'] = $_POST['campaign_id'];
  338. $banner['publish_date_start'] = $_POST['valid_from'];
  339. $banner['publish_date_end'] = $_POST['valid_to'];
  340. $banner['status'] = $_POST['status'];
  341. $this->db->where(array('banner_id' => $banner_id));
  342. $this->db->update('banner', $banner);
  343. }
  344. }
  345. $this->db->where(array('campaign_id' => $_POST['campaign_id']));
  346. $this->db->update('promo', array('campaign_id' => 0));
  347. if(isset($_POST['promo_id'])){
  348. foreach($_POST['promo_id'] as $promo_id) {
  349. $promo = array();
  350. $promo['campaign_id'] = $_POST['campaign_id'];
  351. $promo['valid_from'] = $_POST['valid_from'];
  352. $promo['valid_to'] = $_POST['valid_to'];
  353. $promo['status'] = $_POST['status'];
  354. $this->db->where(array('promo_id' => $promo_id));
  355. $this->db->update('promo', $promo);
  356. }
  357. }
  358. set_success_message(sprintf(lang('success_edit'), 'campaign'));
  359. redirect('system/promo/campaign_edit/' . $_POST['campaign_id']);
  360. exit;
  361. } else {
  362. set_error_message('Update Failed!');
  363. }
  364. }
  365. break;
  366. }
  367. }
  368. }
  369. /**
  370. * End of file promo_model.php
  371. * Location: ./.../.../.../promo_model.php
  372. */