You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
6.3 KiB

  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. require APPPATH . '/libraries/REST_Controller.php';
  4. class Management extends REST_Controller
  5. {
  6. /****************************************************************************
  7. * 공용 순서변경
  8. ***************************************************************************/
  9. function sort_post()
  10. {
  11. $key = $this->input->post('key', TRUE);
  12. $sort_idx = $this->input->post("sort_order", TRUE);
  13. $table = $this->input->post('table', TRUE);
  14. $sort_col = $this->input->post('sort', TRUE);
  15. if(empty($key) OR empty($table) or empty($sort_col))
  16. $this->response(array('message'=>'잘못된 접근입니다.'));
  17. $update_array = array();
  18. for($i=1; $i<=count($sort_idx); $i++)
  19. {
  20. $update_array[] = array(
  21. $key => $sort_idx[$i-1],
  22. $sort_col => $i
  23. );
  24. }
  25. $this->db->update_batch($table, $update_array, $key);
  26. }
  27. /**
  28. * 팝업 목록
  29. */
  30. function popups_get() {
  31. $page_rows = $this->input->get('take', TRUE, 15);
  32. $start = $this->input->get('skip', TRUE);
  33. $this->db
  34. ->select('SQL_CALC_FOUND_ROWS P.*, M.mem_nickname AS upd_username', FALSE)
  35. ->from('popup AS P')
  36. ->join('member AS M','M.mem_idx=P.upd_user','inner')
  37. ->where('pop_status', 'Y')
  38. ->order_by('pop_idx DESC')
  39. ->limit($page_rows, $start);
  40. $result = $this->db->get();
  41. $return['lists'] = $result->result_array();
  42. $return['totalCount'] = (int)$this->db->query("SELECT FOUND_ROWS() AS cnt")->row(0)->cnt;
  43. foreach($return['lists'] as $i=>&$row)
  44. {
  45. $row['nums'] = $return['totalCount'] - $i - $start;
  46. $row['pop_state'] = (strtotime($row['pop_start']) <= time() && strtotime($row['pop_end']) >= time())?'표시중':'미표시중';
  47. }
  48. $this->response($return, 200);
  49. }
  50. /**
  51. * 팝업 삭제
  52. */
  53. function popups_delete()
  54. {
  55. $pop_idx = $this->delete('pop_idx', TRUE);
  56. $mem_idx = $this->member->is_login();
  57. if(empty($pop_idx)) $this->response('잘못된 접근입니다.', 400);
  58. $data['upd_datetime'] = date('Y-m-d H:i:s');
  59. $data['upd_user'] = $mem_idx;
  60. $data['pop_status'] = 'N';
  61. $this->db->where('pop_idx', $pop_idx);
  62. $this->db->update('popup', $data);
  63. }
  64. /**
  65. * 사이트맵 목록
  66. */
  67. function sitemaps_get()
  68. {
  69. $page_rows = $this->input->get('take', TRUE, 15);
  70. $start = $this->input->get('skip', TRUE);
  71. $this->db
  72. ->select('SQL_CALC_FOUND_ROWS S.*, M.mem_nickname AS upd_username', FALSE)
  73. ->from('sitemap AS S')
  74. ->join('member AS M','M.mem_idx=S.upd_user','inner')
  75. ->order_by('sit_idx DESC')
  76. ->limit($page_rows, $start);
  77. $result = $this->db->get();
  78. $return['lists'] = $result->result_array();
  79. $return['totalCount'] = (int)$this->db->query("SELECT FOUND_ROWS() AS cnt")->row(0)->cnt;
  80. $this->response($return, 200);
  81. }
  82. function sitemaps_delete()
  83. {
  84. $sit_idx = $this->delete('sit_idx', TRUE);
  85. if(empty($sit_idx)) $this->response(array('message'=>'잘못된 접근입니다.'), 400);
  86. $this->db->where('sit_idx', $sit_idx)->delete('sitemap');
  87. }
  88. // Q&A 분류 삭제
  89. function qna_category_delete()
  90. {
  91. $qnc_idx = $this->delete('qnc_idx', TRUE);
  92. if(empty($qnc_idx)) $this->response(array('message'=>'잘못된 접근입니다.'), 400);
  93. $data['upd_user'] = $this->member->is_login();
  94. $data['upd_datetime'] = date('Y-m-d H:i:s');
  95. $data['qnc_status'] = 'N';
  96. $this->db->where('qnc_idx', $qnc_idx)->update('qna_category', $data);
  97. }
  98. function qna_delete()
  99. {
  100. $qna_idx= $this->delete('qna_idx', TRUE);
  101. if(empty($qna_idx)) $this->response(array('message'=>'잘못된 접근입니다.'), 400);
  102. $data['upd_user'] = $this->member->is_login();
  103. $data['upd_datetime'] = date('Y-m-d H:i:s');
  104. $data['qna_status'] = 'N';
  105. $this->db->where('qna_idx', $qna_idx)->update('qna', $data);
  106. }
  107. function qna_get()
  108. {
  109. $startdate = $this->get('startdate', TRUE);
  110. $enddate = $this->get('enddate', TRUE);
  111. $qna_ans_status = $this->get('qna_ans_status', TRUE);
  112. $st = $this->get('st', TRUE);
  113. $sc = $this->get('sc', TRUE);
  114. $page_rows = $this->get('take', TRUE);
  115. $start = $this->get('skip', TRUE);
  116. if(! empty($page_rows)) $this->db->limit($page_rows, $start);
  117. if(! empty($startdate)) $this->db->where('reg_datetime >=', $startdate.' 00:00:00');
  118. if(! empty($enddate)) $this->db->where('reg_datetime <=', $enddate.' 23:59:59');
  119. if(! empty($qna_ans_status)) $this->db->where('qna_ans_status', $qna_ans_status);
  120. if(! empty($st) && ! empty($sc)) $this->db->like($sc, $st);
  121. $this->db->select("SQL_CALC_FOUND_ROWS Q.*, QC.qnc_title, M.mem_nickname AS qna_ans_upd_username",FALSE);
  122. $this->db->order_by('qna_idx DESC');
  123. $this->db->from('qna AS Q');
  124. $this->db->join('qna_category AS QC','QC.qnc_idx=Q.qnc_idx','left');
  125. $this->db->join('member AS M','M.mem_idx=Q.qna_ans_user','left');
  126. $this->db->where('qna_status','Y');
  127. $result = $this->db->get();
  128. $return['lists'] = $result->result_array();
  129. $return['totalCount'] = (int)$this->db->query("SELECT FOUND_ROWS() AS cnt")->row(0)->cnt;
  130. foreach($return['lists'] as $i=>&$row)
  131. {
  132. $row['nums'] = $return['totalCount'] - $i - $start;
  133. }
  134. $this->response($return, 200);
  135. }
  136. /**
  137. * 공용 에디트
  138. */
  139. function updates_post()
  140. {
  141. $table = $this->post('table', TRUE);
  142. $key_column = $this->post('key_column', TRUE);
  143. $key = $this->post('key', TRUE);
  144. $values = $this->post('values', TRUE);
  145. if(empty($table) OR empty($key_column) OR empty($key)) $this->response(array('message'=>'잘못된 접근입니다.'), 400);
  146. $values['upd_datetime'] = date('Y-m-d H:i:s');
  147. $values['upd_user'] = $this->member->is_login();
  148. $this->db->where($key_column, $key);
  149. $this->db->update($table, $values);
  150. }
  151. }