board_proc.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. session_start();
  3. include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
  4. include $_SERVER['DOCUMENT_ROOT'].ADMIN_PATH.'common/auth_chk.php';
  5. $upBaseDir = $_SERVER['DOCUMENT_ROOT'].UPLOAD_PATH."board";
  6. //게시판 글쓰기
  7. $cd_seq = trim(avoid_crack($_POST["cd_seq"]));
  8. $cd_board = trim(avoid_crack($_POST["cd_board"]));
  9. $cd_user = trim(avoid_crack($_POST["cd_user"]));
  10. $cd_userid = trim(avoid_crack($_POST["cd_userid"]));
  11. $nm_title = trim(avoid_crack($_POST["nm_title"]));
  12. $nm_content =$_POST["nm_content"];
  13. $nm_reply =$_POST["nm_reply"];
  14. $ds_open = trim(avoid_crack($_POST["ds_open"]));
  15. $ds_kind = trim(avoid_crack($_POST["ds_kind"]));
  16. $ds_top = trim(avoid_crack($_POST["ds_top"]));
  17. $ds_main = trim(avoid_crack($_POST["ds_main"]));
  18. $nm_name = trim(avoid_crack($_POST["nm_name"]));
  19. $nm_etc1 = trim(avoid_crack($_POST["nm_etc1"]));
  20. $nm_etc2 = trim(avoid_crack($_POST["nm_etc2"]));
  21. $nm_etc3 = trim(avoid_crack($_POST["nm_etc3"]));
  22. $nm_etc4 = trim(avoid_crack($_POST["nm_etc4"]));
  23. $nm_etc5 = trim(avoid_crack($_POST["nm_etc5"]));
  24. $nm_title = trim(avoid_crack($_POST["nm_title"]));
  25. $no_pcd_seq = trim(avoid_crack($_POST["no_pcd_seq"]));
  26. $org_upload_file_name = trim(avoid_crack($_POST["org_upload_file_name"]));
  27. switch($mode) {
  28. case "Add" :
  29. $RES = array('CODE'=>'9999', 'MSG'=>'');
  30. try {
  31. $check_id=@mysql_result(mysql_query("select count(*) from admin_info where cd_userid='$cd_userid'"),0,0);
  32. if($check_id==0) {
  33. throw new Exception("등록 실패 하였습니다.", "9990");
  34. }
  35. $nm_content = addslashes($nm_content);
  36. $upload_file_name = "";
  37. $upload_path = $upBaseDir."/board_".$cd_board;
  38. if (is_uploaded_file($_FILES['nm_file']['tmp_name'])) {
  39. if($_FILES['nm_file']['size'] > 0 ){
  40. $upload_file_name = upload($_FILES['nm_file'],$upload_path, 50, array('gif', 'jpeg', 'jpg','png','bmp','hwp','doc','docx','xls','xlsx','ppt','docx','pptx' ,'pdf', 'txt' ));
  41. if($upload_file_name==false){
  42. throw new Exception("첨부파일 업로드 실패 하였습니다.", "9990");
  43. // AlertBack("첨부파일 업로드 실패 하였습니다.");
  44. die();
  45. }
  46. }
  47. }
  48. //계층형 관련 데이터 설정
  49. $no_famally=@mysql_result(mysql_query("SELECT (IFNULL(MIN(no_famally),0)) -(1) FROM board_master"),0,0);
  50. $no_order = 0;
  51. $no_step = 0;
  52. //파일 저장
  53. $sql="insert into board_master
  54. (cd_board, cd_userid, nm_name, nm_title, no_hit , ds_open, nm_content, nm_file, nm_updir, no_famally, no_order, no_step, nm_reply, dt_insert,nm_insert, dt_update, nm_update,ds_delind, ds_top, ds_main, ds_kind, nm_etc1, nm_etc2, nm_etc3,nm_etc4,nm_etc5 )
  55. values
  56. ('$cd_board','$cd_userid','$nm_name','$nm_title',0,'$ds_open','$nm_content','$upload_file_name','$upload_path',$no_famally, $no_order, $no_step, '$nm_reply', now(),'$cd_userid',now(),'$cd_userid','N','$ds_top','$ds_main','A','$nm_etc1','$nm_etc2','$nm_etc3','$nm_etc4','$nm_etc5')
  57. ";
  58. //echo $sql;
  59. //exit;
  60. $result = mysql_query($sql,$connect);
  61. if (!$result) {
  62. throw new Exception("등록 실패 하였습니다..", "9990");
  63. }
  64. // Redirect(ADMIN_PATH."board/bbs_list.php?cd_board=".$cd_board."");
  65. // }else{
  66. // AlertBack("등록 실패 하였습니다.");
  67. // }
  68. $RES['CODE'] = "0000";
  69. $RES['MSG'] = "정상.";
  70. }catch(Exception $e){
  71. $RES['CODE'] = $e->getCode();
  72. $RES['MSG'] = $e->getMessage();
  73. }
  74. @mysql_close($connect);
  75. echo json_encode($RES);
  76. exit;
  77. break;
  78. case "Reply" :
  79. $check_id=@mysql_result(mysql_query("select count(*) from admin_info where cd_userid='$cd_userid'"),0,0);
  80. if($check_id==0) {
  81. AlertBack("등록자 정보가 잘못되었습니다.");
  82. }
  83. $nm_content = addslashes($nm_content);
  84. $upload_file_name = "";
  85. $upload_path = $upBaseDir."/board_".$cd_board;
  86. if (is_uploaded_file($_FILES['nm_file']['tmp_name'])) {
  87. if($_FILES['nm_file']['size'] > 0 ){
  88. $upload_file_name = upload($_FILES['nm_file'],$upload_path, 50, array('gif', 'jpeg', 'jpg','png','bmp','hwp','doc','docx','xls','xlsx','ppt','docx','pptx' ,'ppt' ,'pdf', 'txt' ));
  89. if($upload_file_name==false){
  90. AlertBack("첨부파일 업로드 실패 하였습니다.");
  91. die();
  92. }
  93. }
  94. }
  95. //부모글 관련 정보 가져온다.
  96. $sqlParent = "SELECT no_famally, no_order, no_step FROM board_master WHERE cd_seq = $no_pcd_seq";
  97. $col=mysql_fetch_array(mysql_query($sqlParent));
  98. if (!empty($col[no_famally])){
  99. $no_famally = $col[no_famally];
  100. $no_order = $col[no_order];
  101. $no_step = $col[no_step];
  102. //ORDER 재정렬
  103. $sqlOrder = "UPDATE board_master SET no_order=no_order+1 WHERE no_famally=$no_famally and no_order>$no_order";
  104. mysql_query($sqlOrder,$connect);
  105. }else{
  106. AlertBack("등록 실패 하였습니다.");
  107. die();
  108. }
  109. //DB저장
  110. $sql="insert into board_master
  111. (cd_board, cd_userid, nm_name, nm_title, no_hit , ds_open, nm_content, nm_file, nm_updir, no_famally, no_order, no_step, dt_insert,nm_insert, dt_update, nm_update,ds_delind, ds_top, ds_main, ds_kind )
  112. values
  113. ('$cd_board','$cd_userid','$nm_name' ,'$nm_title',0,'$ds_open','$nm_content','$upload_file_name','$upload_path',$no_famally, ($no_order+1), ($no_step+1), now(),'$cd_userid',now(),'$cd_userid','N','$ds_top','$ds_main','A')
  114. ";
  115. $result = mysql_query($sql,$connect);
  116. if ($result) {
  117. Redirect(ADMIN_PATH."board/bbs_list.php?cd_board=".$cd_board."");
  118. }else{
  119. AlertBack("등록 실패 하였습니다.");
  120. }
  121. break;
  122. //reply inquiry
  123. case "ReplyInquiry":
  124. $sql="update board_master
  125. set
  126. nm_reply = '$nm_reply'
  127. ,dt_reply = now()
  128. ,dt_update = now()
  129. ,nm_update = '$cd_userid'
  130. WHERE cd_seq =$cd_seq";
  131. $result = mysql_query($sql,$connect);
  132. if ($result) {
  133. Redirect(ADMIN_PATH."board/bbs_list.php?cd_board=".$cd_board."");
  134. }else{
  135. AlertBack("수정 실패 하였습니다.");
  136. }
  137. break;
  138. //reply inquiry
  139. case "ReplyInquiryAjax":
  140. //파일 저장
  141. $sql="update board_master
  142. set
  143. nm_reply = '$nm_reply'
  144. ,dt_reply = now()
  145. ,dt_update = now()
  146. ,nm_update = '$cd_userid'
  147. WHERE cd_seq =$cd_seq";
  148. $result = mysql_query($sql,$connect);
  149. if ($result) {
  150. echo("Y");
  151. exit;
  152. } else {
  153. echo("N");
  154. exit;
  155. }
  156. break;
  157. //글수정
  158. case "Update":
  159. $RES = array('CODE'=>'9999', 'MSG'=>'');
  160. try {
  161. $upload_file_name = "";
  162. $upload_path = $upBaseDir."/board_".$cd_board;
  163. if (is_uploaded_file($_FILES['nm_file']['tmp_name'])) {
  164. if($_FILES['nm_file']['size'] > 0 ){
  165. $upload_file_name = upload($_FILES['nm_file'],$upload_path, 50, array('gif', 'jpeg', 'jpg','png','bmp','hwp','doc','docx','xls','xlsx','ppt','docx','pptx' ,'ppt' ,'pdf', 'txt' ));
  166. if($upload_file_name==false){
  167. throw new Exception("첨부파일 업로드 실패 하였습니다.", "9990");
  168. // AlertBack("첨부파일 업로드 실패 하였습니다.");
  169. die();
  170. }
  171. }else{
  172. $upload_file_name = $org_upload_file_name;
  173. }
  174. }
  175. if($upload_file_name=="" || $upload_file_name == null || $upload_file_name == false){
  176. $upload_file_name = $org_upload_file_name;
  177. }
  178. //파일 저장
  179. $sql="update board_master
  180. set
  181. cd_board = '$cd_board'
  182. ,nm_title = '$nm_title'
  183. ,nm_name = '$nm_name'
  184. ,ds_open = '$ds_open'
  185. ,nm_content = '$nm_content'
  186. ,nm_reply = '$nm_reply'
  187. ,nm_file = '$upload_file_name'
  188. ,nm_updir = '$upload_path'
  189. ,dt_update = now()
  190. ,nm_update = '$cd_userid'
  191. ,ds_top = '$ds_top'
  192. ,ds_main = '$ds_main'
  193. ,ds_kind ='$ds_kind'
  194. ,nm_etc1 ='$nm_etc1'
  195. ,nm_etc2 ='$nm_etc2'
  196. ,nm_etc3 ='$nm_etc3'
  197. ,nm_etc4 ='$nm_etc4'
  198. ,nm_etc5 ='$nm_etc5'
  199. WHERE cd_seq =$cd_seq";
  200. $result = mysql_query($sql,$connect);
  201. if (!$result) {
  202. throw new Exception("수정 실패 하였습니다..", "9990");
  203. }
  204. //
  205. // if ($result) {
  206. // Redirect(ADMIN_PATH."board/bbs_list.php?cd_board=".$cd_board."");
  207. // }else{
  208. // AlertBack("수정 실패 하였습니다.");
  209. // }
  210. $RES['CODE'] = "0000";
  211. $RES['MSG'] = "정상.";
  212. }catch(Exception $e){
  213. $RES['CODE'] = $e->getCode();
  214. $RES['MSG'] = $e->getMessage();
  215. }
  216. @mysql_close($connect);
  217. echo json_encode($RES);
  218. exit;
  219. break;
  220. //글삭제 처리
  221. case "Delete" :
  222. $RES = array('CODE'=>'9999', 'MSG'=>'');
  223. try {
  224. $cd_seq = trim(avoid_crack($_POST["cd_seq"]));
  225. $cd_userid = trim(avoid_crack($_POST["cd_userid"]));
  226. $cd_board = trim(avoid_crack($_POST["cd_board"]));
  227. $PageNo = trim(avoid_crack($_POST["PageNo"]));
  228. $sql = "update board_master set ds_delind='Y' , nm_update = '$cd_userid' , dt_update = now() where cd_seq='$cd_seq'";
  229. $result = mysql_query($sql,$connect);
  230. if (!$result) {
  231. throw new Exception("삭제 실패 하였습니다.", "9990");
  232. }
  233. // }
  234. //
  235. // if ($result) {
  236. // Redirect(ADMIN_PATH."board/bbs_list.php?cd_board=".$cd_board."");
  237. // }else{
  238. // AlertRedirect("삭제 실패하였습니다.",ADMIN_PATH."board/bbs_list.php?cd_board=".$cd_board."");
  239. // }
  240. //
  241. //
  242. //
  243. // if ($result) {
  244. // Redirect(ADMIN_PATH."board/bbs_list.php?cd_board=".$cd_board."");
  245. // }else{
  246. // AlertBack("수정 실패 하였습니다.");
  247. // }
  248. $RES['CODE'] = "0000";
  249. $RES['MSG'] = "정상.";
  250. }catch(Exception $e){
  251. $RES['CODE'] = $e->getCode();
  252. $RES['MSG'] = $e->getMessage();
  253. }
  254. @mysql_close($connect);
  255. echo json_encode($RES);
  256. exit;
  257. // echo 'a';
  258. // exit;
  259. break;
  260. default :
  261. AlertRedirect("지정되지않은 요청입니다",ADMIN_PATH."index.php");
  262. break;
  263. }
  264. mysql_close($connect);
  265. ?>