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.

471 lines
20 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Board extends WB_Controller
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. $this->theme = 'admin';
  9. $this->load->library('boardlib');
  10. }
  11. /******************************************************************************************************
  12. * 게시판 목록
  13. ******************************************************************************************************/
  14. public function lists()
  15. {
  16. // 메타태그 설정
  17. $this->site->meta_title = "게시판 관리";
  18. // 레이아웃 & 뷰파일 설정
  19. $this->view = $this->active = "board/lists";
  20. }
  21. /**
  22. * 게시판 등록/수정
  23. * @param string $brd_key
  24. */
  25. public function form($brd_key="")
  26. {
  27. $this->load->model('board_model');
  28. $this->load->library('form_validation');
  29. $this->form_validation->set_rules('brd_key','게시판 고유 키',"required|trim|min_length[3]|max_length[20]". (empty($brd_key)?"|callback_brd_key_check":""));
  30. if( $this->form_validation->run() != FALSE )
  31. {
  32. $data['brd_key'] = $this->input->post('brd_key', TRUE);
  33. $data['brd_title'] = $this->input->post('brd_title', TRUE,'');
  34. $data['brd_keywords'] = $this->input->post('brd_keywords', TRUE);
  35. $data['brd_description'] = $this->input->post('brd_description', TRUE);
  36. $data['brd_skin_l'] = $this->input->post('brd_skin_l', TRUE);
  37. $data['brd_skin_l_m'] = $this->input->post('brd_skin_l_m', TRUE);
  38. $data['brd_skin_w'] = $this->input->post('brd_skin_w', TRUE);
  39. $data['brd_skin_w_m'] = $this->input->post('brd_skin_w_m', TRUE);
  40. $data['brd_skin_v'] = $this->input->post('brd_skin_v', TRUE);
  41. $data['brd_skin_v_m'] = $this->input->post('brd_skin_v_m', TRUE);
  42. $data['brd_skin_c'] = $this->input->post('brd_skin_c', TRUE);
  43. $data['brd_skin_c_m'] = $this->input->post('brd_skin_c_m', TRUE);
  44. $data['brd_use_category'] = $this->input->post('brd_use_category', TRUE, "N");
  45. $data['brd_category'] = rtrim(trim($this->input->post('brd_category', TRUE, '')), ';');
  46. $data['brd_lv_list'] = $this->input->post('brd_lv_list', TRUE);
  47. $data['brd_lv_read'] = $this->input->post('brd_lv_read', TRUE);
  48. $data['brd_lv_write'] = $this->input->post('brd_lv_write', TRUE);
  49. $data['brd_lv_reply'] = $this->input->post('brd_lv_reply', TRUE);
  50. $data['brd_lv_comment'] = $this->input->post('brd_lv_comment', TRUE);
  51. $data['brd_lv_download'] = $this->input->post('brd_lv_download', TRUE);
  52. $data['brd_page_limit'] = $this->input->post('brd_page_limit', TRUE);
  53. $data['brd_page_rows'] = $this->input->post('brd_page_rows', TRUE);
  54. $data['brd_page_rows_m'] = $this->input->post('brd_page_rows_m', TRUE);
  55. $data['brd_fixed_num'] = $this->input->post('brd_fixed_num', TRUE);
  56. $data['brd_fixed_num_m'] = $this->input->post('brd_fixed_num_m', TRUE);
  57. $data['brd_display_time'] = $this->input->post('brd_display_time', TRUE);
  58. $data['brd_use_anonymous'] = $this->input->post('brd_use_anonymous', TRUE);
  59. $data['brd_use_secret'] = $this->input->post('brd_use_secret', TRUE);
  60. $data['brd_use_reply'] = $this->input->post('brd_use_reply', TRUE);
  61. $data['brd_use_comment'] = $this->input->post('brd_use_comment', TRUE);
  62. $data['brd_point_read'] = $this->input->post('brd_point_read', TRUE, 0);
  63. $data['brd_point_write'] = $this->input->post('brd_point_write', TRUE, 0);
  64. $data['brd_point_comment'] = $this->input->post('brd_point_comment', TRUE, 0);
  65. $data['brd_point_download'] = $this->input->post('brd_point_download', TRUE, 0);
  66. $data['brd_point_reply'] = $this->input->post('brd_point_reply', TRUE, 0);
  67. $data['brd_point_read_flag'] = $this->input->post('brd_point_read_flag', TRUE, -1);
  68. $data['brd_point_write_flag'] = $this->input->post('brd_point_write_flag', TRUE, 1);
  69. $data['brd_point_comment_flag'] = $this->input->post('brd_point_comment_flag', TRUE, 1);
  70. $data['brd_point_download_flag'] = $this->input->post('brd_point_download_flag', TRUE, -1);
  71. $data['brd_point_reply_flag'] = $this->input->post('brd_point_reply_flag', TRUE, 1);
  72. $data['upd_user'] = $this->member->is_login();
  73. $data['upd_datetime'] = date('Y-m-d H:i:s');
  74. if(empty($brd_key))
  75. {
  76. $data['reg_user'] = $data['upd_user'];
  77. $data['reg_datetime'] = $data['upd_datetime'];
  78. $data['brd_count_post'] = 0;
  79. if( $this->db->insert('board', $data) )
  80. {
  81. alert_modal_close('게시판 생성이 완료되었습니다.');
  82. exit;
  83. }
  84. }
  85. else
  86. {
  87. $this->db->where('brd_key', $brd_key);
  88. if( $this->db->update('board', $data) ) {
  89. $this->boardlib->delete_cache($brd_key);
  90. alert_modal_close('게시판 정보 수정이 완료되었습니다.');
  91. exit;
  92. }
  93. }
  94. alert('DB입력도중 오류가 발생하였습니다.');
  95. exit;
  96. }
  97. else
  98. {
  99. $this->data['view'] = (empty($brd_key)) ? array() : $this->boardlib->get($brd_key, TRUE);
  100. $this->data['brd_key'] = $brd_key;
  101. $this->data['skin_list_l'] = get_skin_list('board/list');
  102. $this->data['skin_list_w'] = get_skin_list('board/write');
  103. $this->data['skin_list_v'] = get_skin_list('board/view');
  104. $this->data['skin_list_c'] = get_skin_list('board/comment');
  105. // 메타태그 설정
  106. $this->site->meta_title = "게시판 관리";
  107. // 레이아웃 & 뷰파일 설정
  108. $this->view = "board/form";
  109. $this->theme_file = 'iframe';
  110. }
  111. }
  112. /**
  113. * 게시판 삭제
  114. */
  115. public function remove($brd_key)
  116. {
  117. if(empty($brd_key))
  118. {
  119. alert('잘못된 접근입니다.');
  120. exit;
  121. }
  122. $this->db->where('brd_key', $brd_key)->delete('board');
  123. alert('게시판이 삭제되었습니다.');
  124. exit;
  125. }
  126. /**
  127. * 게시판 복사
  128. */
  129. public function board_copy($brd_key)
  130. {
  131. $this->load->model('board_model');
  132. $this->load->library('form_validation');
  133. $this->form_validation->set_rules('original', "원본 게시판", "required|trim");
  134. $this->form_validation->set_rules('brd_key','게시판 고유 키',"required|trim|min_length[3]|max_length[20]|callback_brd_key_check");
  135. if( $this->form_validation->run() != FALSE )
  136. {
  137. $data = $this->boardlib->get( $this->input->post('original', TRUE) , TRUE);
  138. if(! $data || !isset($data['brd_key']) || !$data['brd_key'])
  139. {
  140. alert_modal_close('원본 게시판 설정을 찾을수 없습니다.');
  141. exit;
  142. }
  143. $data['brd_key'] = $this->input->post('brd_key', TRUE);
  144. $data['brd_title'] = $this->input->post('brd_title', TRUE);
  145. $data['brd_count_post'] = 0;
  146. $data['upd_user'] = $data['reg_user'] = $this->member->is_login();
  147. $data['upd_datetime'] = $data['reg_datetime'] = date('Y-m-d H:i:s');
  148. $this->db->insert('board', $data);
  149. alert_modal_close('게시판 복사가 완료되었습니다.');
  150. exit;
  151. }
  152. else
  153. {
  154. $this->data['view'] = $this->boardlib->get($brd_key, TRUE);
  155. if(! $this->data['view'] || !isset($this->data['view']['brd_key']) || ! $this->data['view']['brd_key'])
  156. {
  157. alert_modal_close('원본 게시판 설정을 찾을수 없습니다.');
  158. exit;
  159. }
  160. $this->data['brd_key'] = $brd_key;
  161. $this->data['skin_list'] = get_skin_list('board');
  162. $this->theme = "admin";
  163. $this->theme_file = "iframe";
  164. $this->view = "board/board_copy";
  165. }
  166. }
  167. /**
  168. * 게시판 중복여부 확인
  169. */
  170. function brd_key_check($str)
  171. {
  172. $this->load->model('board_model');
  173. if(! preg_match("/^[a-z][a-z0-9_]{2,19}$/", $str))
  174. {
  175. $this->form_validation->set_message('brd_key_check', "게시판 고유키는 영어 소문자로 시작하는 3~20 글자로 영어와 숫자만 사용가능합니다. : {$str}");
  176. return FALSE;
  177. }
  178. if( $board = $this->boardlib->get($str, TRUE) ) {
  179. $this->form_validation->set_message('brd_key_check', "이미 사용중인 {field} 입니다 : {$str}");
  180. return FALSE;
  181. }
  182. return TRUE;
  183. }
  184. /**
  185. * 게시판 목록
  186. */
  187. function posts($brd_key)
  188. {
  189. $this->boardlib->common_data($brd_key);
  190. $this->data['list'] = $this->boardlib->post_list($this->data['board'], $this->param);
  191. $paging['page'] = $this->param['page'];
  192. $paging['page_rows'] = 20;
  193. $paging['total_rows'] = $this->data['list']['total_count'];
  194. $this->load->library('paging', $paging);
  195. $this->data['pagination'] = $this->paging->create();
  196. $this->active = "board/" . $brd_key;
  197. $this->theme = "admin";
  198. $this->view = "board/posts";
  199. }
  200. function read($brd_key, $post_idx="")
  201. {
  202. $this->boardlib->common_data($brd_key);
  203. $this->data['view'] = $this->boardlib->get_post($brd_key, $post_idx, FALSE);
  204. $this->active = "board/" . $brd_key;
  205. $this->theme = "admin";
  206. $this->view = "board/read";
  207. }
  208. function write($brd_key, $post_idx="")
  209. {
  210. $this->load->library('form_validation');
  211. $this->boardlib->common_data($brd_key);
  212. $this->form_validation->set_rules('post_title', langs('게시판/form/post_title') ,'required|trim');
  213. $this->form_validation->set_rules('post_content', langs('게시판/form/post_content'),'required|trim');
  214. if( $this->form_validation->run() != FALSE)
  215. {
  216. $this->load->library('upload');
  217. // 받아온 값을 정리한다.
  218. $data['post_title'] = $this->input->post('post_title', TRUE);
  219. $data['post_category'] = $this->input->post('post_category', TRUE, '');
  220. $data['post_parent'] = $this->input->post('post_parent', TRUE, 0);
  221. $data['post_secret'] = $this->input->post('post_secret', TRUE, 'N') == 'Y' ? "Y":'N';
  222. $data['post_content'] = $this->input->post('post_content', FALSE);
  223. $data['brd_key'] = $brd_key;
  224. $data['upd_datetime'] = date('Y-m-d H:i:s');
  225. $data['upd_user'] = $this->member->is_login();
  226. $data['post_notice'] = $this->input->post('post_notice', TRUE) == 'Y' ? 'Y' : 'N';
  227. $data['post_ip'] = ip2long( $this->input->ip_address() );
  228. $data['post_mobile'] = $this->site->viewmode == DEVICE_MOBILE ? 'Y' : 'N';
  229. $data['post_keywords'] = $this->input->post('post_keywords', TRUE);
  230. for($i=1; $i<=9; $i++)
  231. {
  232. $data['post_ext'.$i] = $this->input->post('post_ext'.$i, TRUE,'');
  233. }
  234. $parent = array();
  235. if(! empty( $data['post_parent'] ) )
  236. {
  237. $parent = $this->board_model->get_post($brd_key, $data['post_parent'], FALSE);
  238. }
  239. // 게시판 설정을 이용해서 값 정리
  240. if( $this->data['board']['brd_use_secret'] == 'N' ) $data['post_secret'] = 'N';
  241. else if ( $this->data['board']['brd_use_secret'] == 'A' ) $data['post_secret'] = 'Y';
  242. // 답글인경우 원글이 비밀글이면 답글도 비밀글
  243. else if ( ! empty($data['post_parent']) && $parent['post_secret'] == 'Y' ) $data['post_secret'] = 'Y';
  244. // 파일 업로드가 있다면
  245. if( isset($_FILES) && isset($_FILES['userfile']) && count($_FILES['userfile']) > 0 )
  246. {
  247. $dir_path = DIR_UPLOAD . "/board/{$brd_key}/".date('Y')."/".date('m');
  248. make_dir($dir_path,FALSE);
  249. $upload_config['upload_path'] = "./".$dir_path;
  250. $upload_config['file_ext_tolower'] = TRUE;
  251. $upload_config['allowed_types'] = FILE_UPLOAD_ALLOW;
  252. $upload_config['encrypt_name'] = TRUE;
  253. $this->load->library("upload", $upload_config);
  254. $this->data['upload_array'] = array();
  255. // FOR문으로 업로드하기 위해 돌리기
  256. $files = NULL;
  257. foreach ($_FILES['userfile'] as $key => $value) {
  258. foreach ($value as $noKey => $noValue) {
  259. $files[$noKey][$key] = $noValue;
  260. }
  261. }
  262. unset($_FILES);
  263. // FOR 문 돌면서 정리
  264. foreach ($files as $file) {
  265. $_FILES['userfile'] = $file;
  266. $this->upload->initialize($upload_config);
  267. if( ! isset($_FILES['userfile']['tmp_name']) OR ! $_FILES['userfile']['tmp_name']) continue;
  268. if (! $this->upload->do_upload('userfile') )
  269. {
  270. alert('파일 업로드에 실패하였습니다.\\n'.$this->upload->display_errors(' ',' '));
  271. exit;
  272. }
  273. else
  274. {
  275. $filedata = $this->upload->data();
  276. $this->data['upload_array'][] = array(
  277. "att_target_type" => 'BOARD',
  278. "att_origin" => $filedata['orig_name'],
  279. "att_filepath" => $dir_path . "/" . $filedata['file_name'],
  280. "att_downloads" => 0,
  281. "att_filesize" => $filedata['file_size'] * 1024,
  282. "att_width" => $filedata['image_width'] ? $filedata['image_width'] : 0,
  283. "att_height" => $filedata['image_height'] ? $filedata['image_height'] : 0,
  284. "att_ext" => $filedata['file_ext'],
  285. "att_is_image" => ($filedata['is_image'] == 1) ? 'Y' : 'N',
  286. "reg_user" => $this->member->is_login(),
  287. "reg_datetime" => date('Y-m-d H:i:s')
  288. );
  289. }
  290. }
  291. }
  292. // 첨부파일 삭제가 있다면 삭제한다.
  293. $del_file = $this->input->post("del_file", TRUE);
  294. if( $del_file && count($del_file) > 0 )
  295. {
  296. foreach($del_file as $att_idx) {
  297. $this->board_model->attach_remove($att_idx);
  298. }
  299. }
  300. // 수정이냐 신규냐에 따라 값 설정
  301. if( empty($post_idx) )
  302. {
  303. $data['mem_userid'] = $this->member->info('userid');
  304. $data['mem_nickname'] = $this->member->info('nickname');
  305. $data['mem_password'] = $this->member->info('password');
  306. $data['post_regtime'] = date('Y-m-d H:i:s');
  307. $data['post_status'] = 'Y';
  308. $data['post_count_comment'] = 0;
  309. $data['post_hit'] = 0;
  310. // 답글인경우
  311. if(! empty($data['post_parent']))
  312. {
  313. if( strlen($parent['post_reply']) >= 10 )
  314. {
  315. alert('더 이상 답변하실 수 없습니다.\\n답변은 10단계 까지만 가능합니다.');
  316. exit;
  317. }
  318. $reply_len = strlen($parent['post_reply']) + 1;
  319. $begin_reply_char = 'A';
  320. $end_reply_char = 'Z';
  321. $reply_number = +1;
  322. $reply_char = "";
  323. $this->db->select("MAX(SUBSTRING(post_reply, {$reply_len}, 1)) AS reply")->from('board_post')->where('post_num', $parent['post_num'])->where('brd_key', $brd_key)->where("SUBSTRING(post_reply, {$reply_len}, 1) <>", '');
  324. if($parent['post_reply']) $this->db->like('post_reply', $parent['post_reply'],'after');
  325. $row = $this->db->get()->row_array();
  326. if(! $row['reply']) {
  327. $reply_char = $begin_reply_char;
  328. }
  329. else if ($row['reply'] == $end_reply_char) {
  330. alert("더 이상 답변하실 수 없습니다.\\n답변은 26개 까지만 가능합니다.");
  331. exit;
  332. }
  333. else {
  334. $reply_char = chr(ord($row['reply']) + $reply_number);
  335. }
  336. $data['post_reply'] = $parent['post_reply'] . $reply_char;
  337. // 답변의 원글이 비밀글이라면, 비밀번호는 원글과 동일하게 넣는다.
  338. if( $parent['post_secret'] == 'Y' ) {
  339. $data['mem_password'] = $parent['mem_password'];
  340. }
  341. $data['post_num'] = $parent['post_num'];
  342. }
  343. else {
  344. $tmp = (int)$this->db->select_max('post_num','max')->from('board_post')->where('brd_key',$brd_key)->get()->row(0)->max;
  345. $data['post_reply'] = "";
  346. $data['post_num'] = $tmp+1;
  347. }
  348. if(! $this->db->insert('board_post', $data) )
  349. {
  350. alert(langs('게시판/msg/write_failed'));
  351. exit;
  352. }
  353. $post_idx = $this->db->insert_id();
  354. }
  355. else {
  356. $this->db->where('brd_key', $brd_key);
  357. $this->db->where('post_idx', $post_idx);
  358. if(! $this->db->update('board_post', $data))
  359. {
  360. alert(langs('게시판/msg/write_failed'));
  361. exit;
  362. }
  363. }
  364. // 업로드된 데이타가 있을경우에 DB에 기록
  365. if(isset($this->data['upload_array']) && count($this->data['upload_array']) >0 )
  366. {
  367. foreach($this->data['upload_array'] as &$arr) {
  368. $arr['att_target'] = $post_idx;
  369. }
  370. $this->db->insert_batch("attach", $this->data['upload_array']);
  371. }
  372. alert(langs('게시판/msg/write_success'), base_url("admin/board/read/{$brd_key}/{$post_idx}"));
  373. exit;
  374. }
  375. else {
  376. // 수정일경우를 대비해서 글 고유 pk 넘김
  377. $this->data['post_idx'] = (int)$post_idx;
  378. $this->data['post_parent'] = $this->input->get('post_parent', TRUE);
  379. $this->data['view'] = empty($post_idx) ? array() : $this->boardlib->get_post($brd_key, $post_idx, FALSE);
  380. $this->data['parent'] = empty($this->data['post_parent']) ? array() : $this->boardlib->get_post($brd_key, $this->data['post_parent'], FALSE);
  381. if( $this->data['post_idx'] && (! $this->data['view'] OR ! isset($this->data['view']['post_idx']) OR !$this->data['view']['post_idx'] ) )
  382. {
  383. alert('잘못된 접근입니다.');
  384. exit;
  385. }
  386. $hidden = array();
  387. // 답글작성일경우 부모 번호 넘겨주기
  388. if($this->data['post_parent']) {
  389. $hidden['post_parent'] = $this->data['post_parent'];
  390. $this->data['view']['post_title'] = "RE : ". $this->data['parent']['post_title'];
  391. }
  392. $write_url = base_url("admin/board/write/{$brd_key}" . ($post_idx ? '/'.$post_idx : ''), SSL_VERFIY ? "https":'http');
  393. $this->data['form_open'] = form_open_multipart($write_url, array("autocomplete"=>"off"), $hidden);
  394. $this->data['form_close'] = form_close();
  395. // 레이아웃 & 뷰파일 설정
  396. $this->active = "board/".$brd_key;
  397. $this->theme = "admin";
  398. $this->view = "board/write";
  399. }
  400. }
  401. }