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.

166 lines
6.5 KiB

7 years ago
7 years ago
7 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * Q&A 페이지
  5. */
  6. class Qna extends WB_Controller
  7. {
  8. function index($qna_idx="")
  9. {
  10. $page = (int)$this->input->get('page', TRUE, 1) > 1 ? (int)$this->input->get('page', TRUE, 1) : 1;
  11. $page_rows = (int)$this->input->get('page_rows', TRUE, 15);
  12. $start = ($page - 1) * $page_rows;
  13. $sc = $this->input->get('sc', TRUE);
  14. $st = $this->input->get('st', TRUE);
  15. if(! empty($sc) && !empty($st)) {
  16. $st = explode(" ", $st);
  17. if(count($st) > 0) {
  18. foreach($st as $stxt) {
  19. $this->db->like("qna_".$sc, $stxt);
  20. }
  21. }
  22. }
  23. // Q&A 목록 가져오기
  24. $this->db
  25. ->select("SQL_CALC_FOUND_ROWS Q.*, QC.qnc_title", FALSE)
  26. ->from('qna AS Q')
  27. ->join('qna_category AS QC','QC.qnc_idx=Q.qnc_idx','left')
  28. ->where('qna_status', 'Y')
  29. ->limit($page_rows, $start);
  30. $result = $this->db->get();
  31. $this->data['lists'] = $result->result_array();
  32. $this->data['total_count'] = (int)$this->db->query("SELECT FOUND_ROWS() AS cnt")->row(0)->cnt;
  33. foreach($this->data['lists'] as $i=>&$row)
  34. {
  35. $row['nums'] = $this->data['total_count'] - $i - $start;
  36. $row['is_answered'] = $row['qna_ans_status'] == 'Y';
  37. }
  38. // 페이지네이션 세팅
  39. $paging['page'] = $page;
  40. $paging['page_rows'] = $page_rows;
  41. $paging['total_rows'] = $this->data['total_count'];
  42. $this->load->library('paging', $paging);
  43. $this->data['pagination'] = $this->paging->create();
  44. $this->theme = $this->site->get_layout();
  45. $this->view = "customer/qna";
  46. }
  47. function write()
  48. {
  49. $this->load->library('form_validation');
  50. $this->form_validation->set_rules('qna_title', '제목', 'required|trim');
  51. if( $this->form_validation->run() != FALSE )
  52. {
  53. $data['qnc_idx'] = $this->input->post('qnc_idx', TRUE, 0);
  54. $data['qna_title'] = trim($this->input->post('qna_title', TRUE,''));
  55. if( $this->member->is_login() )
  56. {
  57. $data['qna_name'] = $this->member->info('nickname');
  58. $data['qna_password'] = $this->member->info('password');
  59. }
  60. else {
  61. $data['qna_name'] = trim($this->input->post('qna_name', TRUE,''));
  62. $data['qna_password'] = get_password_hash($data['qna_password']);
  63. }
  64. $data['qna_phone'] = trim($this->input->post('qna_phone', TRUE,''));
  65. $data['qna_email'] = trim($this->input->post('qna_email', TRUE,''));
  66. $data['qna_content'] = trim($this->input->post('qna_content', TRUE,''));
  67. $data['upd_user'] = $data['reg_user'] = $this->member->is_login();
  68. $data['upd_datetime'] = $data['reg_datetime'] = date('Y-m-d H:i:s');
  69. $data['qna_ans_status'] = 'N';
  70. $data['qna_ans_user'] = 0;
  71. $data['qna_ans_datetime'] = '0000-00-00 00:00:00';
  72. $data['qna_ans_upd_user'] = 0;
  73. $data['qna_ans_upd_datetime'] ='0000-00-00 00:00:00';
  74. $data['qna_ans_content'] = '';
  75. $upload_array = array();
  76. if( isset($_FILES) && isset($_FILES['userfile']) && count($_FILES['userfile']) > 0 )
  77. {
  78. $dir_path = DIR_UPLOAD . "/qna/".date('Y')."/".date('m');
  79. make_dir($dir_path,FALSE);
  80. $upload_config['upload_path'] = "./".$dir_path;
  81. $upload_config['file_ext_tolower'] = TRUE;
  82. $upload_config['allowed_types'] = FILE_UPLOAD_ALLOW;
  83. $upload_config['encrypt_name'] = TRUE;
  84. $this->load->library("upload", $upload_config);
  85. // FOR문으로 업로드하기 위해 돌리기
  86. $files = NULL;
  87. foreach ($_FILES['userfile'] as $key => $value) {
  88. foreach ($value as $noKey => $noValue) {
  89. $files[$noKey][$key] = $noValue;
  90. }
  91. }
  92. unset($_FILES);
  93. // FOR 문 돌면서 정리
  94. foreach ($files as $file) {
  95. $_FILES['userfile'] = $file;
  96. $this->upload->initialize($upload_config);
  97. if( ! isset($_FILES['userfile']['tmp_name']) OR ! $_FILES['userfile']['tmp_name']) continue;
  98. if (! $this->upload->do_upload('userfile') )
  99. {
  100. alert('파일 업로드에 실패하였습니다.\\n'.$this->upload->display_errors(' ',' '));
  101. exit;
  102. }
  103. else
  104. {
  105. $filedata = $this->upload->data();
  106. $upload_array[] = array(
  107. "att_target_type" => 'QNA',
  108. "att_origin" => $filedata['orig_name'],
  109. "att_filepath" => $dir_path . "/" . $filedata['file_name'],
  110. "att_downloads" => 0,
  111. "att_filesize" => $filedata['file_size'] * 1024,
  112. "att_width" => $filedata['image_width'] ? $filedata['image_width'] : 0,
  113. "att_height" => $filedata['image_height'] ? $filedata['image_height'] : 0,
  114. "att_ext" => $filedata['file_ext'],
  115. "att_is_image" => ($filedata['is_image'] == 1) ? 'Y' : 'N',
  116. "reg_user" => $this->member->is_login(),
  117. "reg_datetime" => date('Y-m-d H:i:s')
  118. );
  119. }
  120. }
  121. }
  122. $this->db->insert('qna', $data);
  123. $qna_idx = $this->db->insert_id();
  124. if( count($upload_array) > 0 )
  125. {
  126. foreach($upload_array as &$arr) {
  127. $arr['att_target'] = $qna_idx;
  128. }
  129. $this->db->insert_batch('attach', $upload_array);
  130. }
  131. alert('등록이 완료되었습니다.', base_url('customer/qna'));
  132. }
  133. else
  134. {
  135. $this->data['qna_category'] = $this->db->where('qnc_status','Y')->order_by('sort')->get('qna_category')->result_array();
  136. $this->theme = $this->site->get_layout();
  137. $this->view = "customer/qna";
  138. }
  139. }
  140. function view($qna_idx) {
  141. }
  142. }