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

/new/PHPSource/newpost.php

http://clover-mana.googlecode.com/
PHP | 337 lines | 278 code | 52 blank | 7 comment | 47 complexity | 70d1a54c0a37fbf3411f823cd918926e MD5 | raw file
  1. <?php
  2. session_start();
  3. include('dbconfig.php');
  4. /*kiem tra cac thong so quyen han */
  5. if(!isset($_SESSION['userid']) || !isset($_SESSION["power"])){
  6. echo "<div class = \"alert\"><div class= 'h10'><img src=\"images/x15.png\" title = \"\">B?n không ?? quy?n ?? lŕm vi?c nŕy,vui lňng ??ng nh?p ho?c <a href=\"index.php?mode=register\">??ng ký</a></div>
  7. </div>";
  8. }
  9. else{
  10. echo "<div class = \"headnewmanga\"><h3>Thęm chapter m?i</h3></div>";
  11. echo "<form id=\"frmNewpost\" name=\"frmNewpost\" method=\"post\" action=\"\" enctype=\"multipart/form-data\">
  12. <div class=\"newmanga\">
  13. <table width=\"533\" border=\"0\">
  14. <tr>
  15. <td>Ch&#7885;n manga </td>
  16. <td><select name=\"MangaId\" id=\"MangaId\">";
  17. $sql_manga = "select MID,MangaName from manga where Passed = 2 order by MangaName";
  18. $result_manga = mysql_query($sql_manga,$connection);
  19. $num_manga = mysql_num_rows($result_manga);
  20. if($num_manga > 0){
  21. while($row_manga= mysql_fetch_array($result_manga)){
  22. echo "<option value = \"$row_manga[0]\"";
  23. if($_POST['MangaId'] == $row_manga[0])
  24. echo "selected";
  25. echo ">$row_manga[1]</option>";
  26. }
  27. }
  28. $txt_name = $_POST['txtName'];
  29. $txt_no = $_POST['txtNo'];
  30. echo "
  31. </select></td>
  32. </tr>
  33. <tr>
  34. <td width=\"100\">T&ecirc;n chap </td>
  35. <td width=\"423\"><input name=\"txtName\" type=\"text\" id=\"txtName\" size=\"35\" value = \"$txt_name\" ";
  36. echo "/></td>
  37. </tr>
  38. <tr>
  39. <td>S&#7889; th&#7913; t&#7921; </td>
  40. <td><input name=\"txtNo\" type=\"text\" id=\"txtNo\" value = \"$txt_no\"/><div id =\"check_no\"></div></td>
  41. </tr>
  42. <tr><td>Cách upload ?nh</td>
  43. <td><select name=\"uptype\" id=\"select_uptype\" >
  44. <option value=\"1\"";
  45. if($_POST['uptype']=="1")
  46. echo "selected";
  47. echo ">Důng ?nh ?ă ???c upload tr??c</option>
  48. <option value=\"2\"";
  49. if($_POST['uptype']=="2")
  50. {
  51. //echo "selected";
  52. }
  53. echo ">Upload ?nh t? máy cá nhân</option>
  54. </select></td></tr>
  55. </table> </div>
  56. <div class=\"newmanga\">
  57. <div id = \"ajax_here\">
  58. <table width=\"533\" border=\"0\">
  59. <tr>
  60. <td width=\"100\">H&igrave;nh &#7843;nh </td>
  61. <td width=\"423\"><div id =\"img_post\"><label>Vui lňng copy ???ng d?n cho t?t c? hěnh ?nh,h? th?ng s? t? ??ng c?p nh?p s? ?nh
  62. <textarea name=\"txtImg\" rows=\"5\" id=\"txtImg\" cols=\"50\"></textarea>
  63. </label>
  64. </td>
  65. </tr>
  66. </div>
  67. </table></div> </div>
  68. <p align=\"center\">
  69. <label>
  70. <input type=\"submit\" name=\"Submit\" value=\"Th&ecirc;m\">
  71. </label>
  72. <label>
  73. <input type=\"reset\" name=\"Submit2\" value=\"X&oacute;a tr&#7855;ng\">
  74. </label>
  75. </p>
  76. </form>";
  77. function get_path($mid)
  78. {
  79. include('dbconfig.php');
  80. $sql = "select Image from manga where MID = $mid";
  81. $result = mysql_query($sql,$connection);
  82. $num = mysql_num_rows($result);
  83. if($num >=1){
  84. $row = mysql_fetch_array($result);
  85. $img = $row[0];
  86. }
  87. $pos = strrpos($img,"/");
  88. if($pos === false)
  89. return NULL;
  90. else
  91. $path = substr($img,0,$pos);
  92. return $path;
  93. mysql_close($connection);
  94. }
  95. function cat_url($str){
  96. if($str != "" && $str != NULL &&$str != " "){
  97. /* dua chuoi ve dinh dang chuan */
  98. $str = str_replace("HTTP://","http://",$str);
  99. $str = str_replace("HtTP://","http://",$str);
  100. $str = str_replace("HTtP://","http://",$str);
  101. $str = str_replace("HTTp://","http://",$str);
  102. $str = str_replace("hTTP://","http://",$str);
  103. $str = str_replace("htTP://","http://",$str);
  104. $str = str_replace("hTtP://","http://",$str);
  105. $str = str_replace("hTTp://","http://",$str);
  106. $str = str_replace("HttP://","http://",$str);
  107. $str = str_replace("HtTp://","http://",$str);
  108. $str = str_replace("HTtp://","http://",$str);
  109. $str = str_replace("httP://","http://",$str);
  110. $str = str_replace("Http://","http://",$str);
  111. $str = str_replace("hTtp://","http://",$str);
  112. $str = str_replace("htTp://","http://",$str);
  113. /* ket thuc chuan hoa chuoi */
  114. $pos = strpos($str,"http://");
  115. if($pos === false)
  116. return NULL;
  117. $pos = strpos($str,".");
  118. if($pos === false)
  119. return NULL;
  120. $arr = explode("http://",$str);
  121. $new_arr = array(count($arr)-1);
  122. for($i = 1;$i < count($arr);$i++)
  123. {
  124. $arr[$i] = "http://".$arr[$i];
  125. $new_arr[$i-1] = $arr[$i];
  126. }
  127. return $new_arr;
  128. }
  129. else
  130. return NULL;
  131. }
  132. if($_POST['Submit']==true)
  133. {
  134. $up_type = $_POST['uptype'];
  135. $up_type = (int)$up_type;
  136. if($up_type==1)
  137. {
  138. $fileup= NULL;
  139. $pic = $_POST['txtImg'];
  140. $name = $_POST['txtName'];
  141. $mangaid = $_POST['MangaId'];
  142. $uid = $_SESSION['userid'];
  143. $stt = 0;
  144. $post_date=gmdate('Y-m-d', time()+(25200)); //GMT +7
  145. if(is_numeric($_POST['txtNo']) == false || $_POST['txtNo'] < 0)
  146. {
  147. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/52.gif\" title = \"Bó tay!\">Th? t? c?a chap ph?i lŕ s? nguyęn d??ng<img src=\"images/69.gif\"></div></div>";
  148. return -1;
  149. }
  150. $no = $_POST['txtNo'];
  151. $no = (int)$no;
  152. if( !isset($name) ||$name==NULL || !isset($pic) ||$pic==NULL || !isset($no) ||$no==NULL )
  153. {
  154. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/52.gif\" title = \"Bó tay!\">Vui lňng nh?p ??y ?? thông tin<img src=\"images/69.gif\"></div></div>";
  155. return -1;
  156. }
  157. $sttok = 1;
  158. $sql_checkno =sprintf("select PID from posting where MID = '%s' and ChapNo='%d' and Status ='%d'",$mangaid,$no,$sttok);
  159. $result_checkno = mysql_query ($sql_checkno, $connection);
  160. $num_checkno = mysql_num_rows($result_checkno);
  161. if($num_checkno>0)
  162. {
  163. $row_checkno= mysql_fetch_array($result_checkno);
  164. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/botay.gif\" title = \"Bó tay!\">Chapter nŕy ?ă ???c post tr??c ?ây.Xem chi ti?t<a href = \"index.php?mode=chaper_info&pid=$row_checkno[0]\"> t?i ?ây</a>.<img src=\"images/69.gif\"></div></div>";
  165. return -1;
  166. }
  167. $arr_pic = cat_url($pic);
  168. if(count($arr_pic)<1 || $arr_pic == NULL){
  169. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/botay.gif\" title = \"Bó tay!\">H? th?ng không těm th?y ???ng d?n ?nh h?p l?.<img src=\"images/69.gif\"></div></div>";
  170. return -1;
  171. }
  172. $strSQL = sprintf("Insert into posting
  173. (
  174. UID,DateAdded,LastUpdate,
  175. Status,MID,ChapName,
  176. ChapNo
  177. )
  178. values
  179. (
  180. '%d','%s','%s',
  181. '%d','%d','%s',
  182. '%d'
  183. )
  184. ", $uid,$post_date,$post_date,$stt, $mangaid,$name,$no);
  185. mysql_query ($strSQL, $connection);
  186. $postid = mysql_insert_id();
  187. $chapid = 0;
  188. for($i = 1;$i <= count($arr_pic);$i++)
  189. {
  190. $sql = sprintf("Insert into
  191. imagepath(PID,ImageNo,ImagePath)
  192. values
  193. (
  194. '%d','%d','%s'
  195. )",$postid,$i,$arr_pic[$i-1]);
  196. mysql_query ($sql, $connection);
  197. // echo $sql;
  198. }
  199. mysql_close($connection);
  200. $username = $_SESSION["username"];
  201. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/25.gif\" title = \"Chúc m?ng!\">Ch?c m?ng $username.B?n ?ă post thŕnh công manga:$name.<img src=\"images/26.gif\"></div></div>";
  202. }
  203. if($up_type==2)//chon upload tu may ca nhan
  204. {
  205. $fileup= $_FILES['fileuploaded'];
  206. $pic = NULL;
  207. $name = $_POST['txtName'];
  208. $mangaid = $_POST['MangaId'];
  209. $uid = $_SESSION['userid'];
  210. $stt = 0;
  211. $post_date=gmdate('Y-m-d', time()+(25200)); //GMT +7
  212. if(is_numeric($_POST['txtNo']) == false || $_POST['txtNo'] < 0)//kiem tra thu tu cua chap hop le
  213. {
  214. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/52.gif\" title = \"Bó tay!\">Th? t? c?a chap ph?i lŕ s? nguyęn d??ng<img src=\"images/69.gif\"></div></div>";
  215. return -1;
  216. }
  217. $no = $_POST['txtNo'];
  218. $no = (int)$no;
  219. //kiem tra tat ca thong tin duoc nhap day du
  220. if( !isset($name) ||$name==NULL || !isset($fileup) ||$fileup==NULL || !isset($no) ||$no==NULL ||
  221. (count($fileup['size']) ==1 && ($fileup['size'][0] == 0 ) ))
  222. {
  223. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/52.gif\" title = \"Bó tay!\">Vui lňng nh?p ??y ?? thông tin<img src=\"images/69.gif\"></div></div>";
  224. return -1;
  225. }
  226. //kiem tra xem chap nay da duoc post truoc hay chua
  227. $sttok = 1;
  228. $sql_checkno =sprintf("select PID from posting where MID = '%s' and ChapNo='%d' and Status ='%d'",$mangaid,$no,$sttok);
  229. $result_checkno = mysql_query ($sql_checkno, $connection);
  230. $num_checkno = mysql_num_rows($result_checkno);
  231. if($num_checkno>0)
  232. {
  233. $row_checkno= mysql_fetch_array($result_checkno);
  234. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/botay.gif\" title = \"Bó tay!\">Chapter nŕy ?ă ???c post tr??c ?ây.Xem chi ti?t<a href = \"index.php?mode=chaper_info&pid=$row_checkno[0]\"> t?i ?ây</a>.<img src=\"images/69.gif\"></div></div>";
  235. return -1;//chap da dc post truoc,xuat thong bao loi
  236. }
  237. $path = get_path($mangaid);
  238. if($no<10)
  239. $chapnum = "00".$no;
  240. else if($no >9 && $no<100)
  241. $chapnum = "0".$no;
  242. else
  243. $chapnum = "".$no;
  244. $real_path = $path."/".$chapnum."/";
  245. if(opendir($real_path)!=FALSE)//foder nay da ton tai
  246. {
  247. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/27.gif\" title = \"R?t ti?c!\">Có s? c? trong vi?c upload.Có th? chapter b?n v?a post ?ă t?n t?i.Lięn h? qu?n tr? ?? bi?t thęm chi ti?t.
  248. B?n c?ng th? s? d?ng ?nh ?ă upload ?? tránh l?i nŕy<img src=\"images/37.gif\"></div></div>";
  249. }else{
  250. mkdir($real_path);//tao foder
  251. $strSQL = sprintf("Insert into posting
  252. (
  253. UID,DateAdded,LastUpdate,
  254. Status,MID,ChapName,
  255. ChapNo
  256. )
  257. values
  258. (
  259. '%d','%s','%s',
  260. '%d','%d','%s',
  261. '%d'
  262. )
  263. ", $uid,$post_date,$post_date,$stt, $mangaid,$name,$no);
  264. mysql_query ($strSQL, $connection);//them thong tin ve posting vao trong csdl
  265. $postid = mysql_insert_id();
  266. $total_pic = count($fileup['name']);
  267. for($i = 0;$i<$total_pic;$i++)
  268. {
  269. $imgs_path = $real_path.$fileup["name"][$i];
  270. move_uploaded_file($fileup["tmp_name"][$i],$imgs_path);//di chuyen hinh anh vao thu muc moi tao
  271. $sql = sprintf("Insert into
  272. imagepath(PID,ImageNo,ImagePath)
  273. values
  274. (
  275. '%d','%d','%s'
  276. )",$postid,$i+1,$imgs_path);
  277. mysql_query ($sql, $connection);//chen link anh vao csdl
  278. }
  279. $username = $_SESSION["username"];
  280. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/25.gif\" title = \"Chúc m?ng!\">Ch?c m?ng $username.B?n ?ă post thŕnh công chapter:$name.<img src=\"images/26.gif\"></div></div>";
  281. }
  282. }
  283. }
  284. }
  285. ?>