PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/new/PHPSource/newmanga.php

http://clover-mana.googlecode.com/
PHP | 235 lines | 220 code | 10 blank | 5 comment | 8 complexity | 54babb749eef7bfd0d59e8d06eefe358 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. /* quyen han hop le,xuat ra form nhap manga moi */
  11. $name = $_POST['name'];
  12. $author = $_POST['author'];
  13. $type = $_POST['type'];
  14. $summary = $_REQUEST['summary'];
  15. $image= $_FILES['image'];
  16. $icon = $_FILES['icon'];
  17. $sql_type ="select * from category";
  18. $result_type = mysql_query($sql_type,$connection);
  19. echo "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"frmNewmanga\">";
  20. echo "<div class = \"headnewmanga\"><h3>Thęm manga m?i</h3><div class=\"khoangcach1\"></div></div>";
  21. echo "<div class=\"newmanga\">";
  22. echo "
  23. <table border=\"0\">
  24. <tr>
  25. <td>Tęn manga </td>
  26. <td><label>
  27. <input name=\"name\" type=\"text\" id=\"name\" size ='45' value =\"$name\" >
  28. </label></td>
  29. </tr>
  30. <tr>
  31. <td width=\"100\">Tác gi? </td>
  32. <td width=\"253\">
  33. <input name=\"author\" type=\"text\" id=\"author\" size ='45' value =\"$author\" >
  34. </td>
  35. </tr>
  36. <tr>
  37. <td>Th? lo?i </td>
  38. <td>
  39. <select name=\"type\">";
  40. while($row_type = mysql_fetch_array($result_type))
  41. {
  42. echo "<option value=\"$row_type[0]\" ";
  43. if($type==$row_type[0])
  44. echo "selected";
  45. echo ">$row_type[1]</option>";
  46. }
  47. echo " </select>
  48. </td>
  49. </tr>
  50. <tr>
  51. <td>Tóm t?t</td>
  52. <td>";
  53. /* <label>
  54. <textarea name=\"summary\" id=\"summary\" rows =\"5\" cols=\"40\"></textarea>
  55. </label> */
  56. echo "<script type=\"text/javascript\" src=\"js/editor.js\"></script>
  57. <span id=\"postArea\"><br><br><br><br>&nbsp; Loading...</span>
  58. <script type=\"text/javascript\">
  59. RTE=new Editor('RTE','postArea','',470, 350);
  60. RTE.removeButton('btnQuote','btnCode','btnUnformat','btnAlignJustify');
  61. RTE.display();
  62. </script>
  63. ";
  64. echo "
  65. <input name=\"summary\" type=\"hidden\" id=\"summary\">
  66. <br>
  67. </td>
  68. </tr>
  69. <tr>
  70. <td>?nh minh h?a</td>
  71. <td><label>
  72. <input name=\"image\" type=\"file\" id=\"image\" value=\"\" size ='45'>
  73. </label></td>
  74. </tr>
  75. <tr>
  76. <td>?nh icon</td>
  77. <td><label>
  78. <input name=\"icon\" type=\"file\" id=\"icon\" size ='45' >
  79. </label></td>
  80. </tr>
  81. </table></div>";
  82. echo "<center><p>
  83. <label>
  84. <input type=\"Submit\" name=\"Submit\" value=\"Thęm\" onclick=\"doSubmit();\">
  85. </label>
  86. <label>
  87. <input type=\"reset\" name=\"Submit2\" value=\"Reset\">
  88. </label>
  89. </p></center>
  90. </form> ";
  91. }
  92. ?>
  93. <?php
  94. function check_file($str)
  95. {
  96. if(strlen($str) <=0)
  97. return false;
  98. if(strpos($str,".")==false)
  99. return false;
  100. $post = strrpos($str,".");
  101. $type = substr($str,$post+1);
  102. if(strcmp($type,"jpg")!=0 && strcmp($type,"jpeg")!=0 &&strcmp($type,"gif")!=0 &&strcmp($type,"png")!=0 )
  103. {
  104. return false;
  105. }
  106. return $type;
  107. }
  108. if($_POST['Submit']==TRUE)
  109. {
  110. $name = $_POST['name'];
  111. $name = str_replace("'","\'",$name);
  112. $author = $_POST['author'];
  113. $author = str_replace("'","\'",$author);
  114. $type = $_POST['type'];
  115. $summary = $_REQUEST['summary'];
  116. $summary = str_replace("'","\'",$summary);
  117. $image= $_FILES['image'];
  118. $icon = $_FILES['icon'];
  119. $a = (string)" \ ";
  120. $a = trim($a);
  121. if( !isset($name) ||$name==NULL ||!isset($author) ||$author==NULL ||!isset($summary) ||$summary==NULL ||!isset($image) ||$image==NULL ||!isset($icon) ||$icon==NULL)
  122. {
  123. 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>";
  124. return -1;
  125. }
  126. $sql_check ="select * from manga where MangaName = '$name'";
  127. $result_check = mysql_query($sql_check,$connection);
  128. $num_rs_check = mysql_num_rows($result_check);
  129. if($num_rs_check >=1){
  130. $row_check = mysql_fetch_array($result_check);
  131. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/87.gif\" title = \"Bó tay!\">Manga nŕy có th? ?ă ???c upload b?i thŕnh vięn khác.Xem chi ti?t <a href= \"index.php?mode=chitietmanga&id=$row_check[0]\">t?i ?ây</a><img src=\"images/28.gif\"></div></div>";
  132. return -1;
  133. }else{
  134. $img_type = check_file($image["name"]);
  135. $ico_type = check_file($icon["name"]);
  136. if($ico_type==false && $img_type==false)
  137. {
  138. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/botay.gif\" title = \"Bó tay!\">Vui lňng upload file có 1 trong 4 ??nh d?ng sau : jpg,jpeg,gif,png<img src=\"images/69.gif\"></div></div>";
  139. return -1;
  140. }
  141. $date=gmdate('Y-m-d', time()+(25200));
  142. $uid = $_SESSION['userid'];
  143. $passed = 0; //dang cho duyet
  144. $stt = 1; //dang update
  145. $strSQL = sprintf("Insert into manga
  146. (
  147. MangaName,DateAdded,Status,
  148. UID,Summary,Passed,Author
  149. )
  150. values
  151. (
  152. '%s','%s','%d',
  153. '%d','%s','%d','%s'
  154. )
  155. ", $name,$date, $stt, $uid, $summary,$passed,$author);
  156. mysql_query ($strSQL, $connection);
  157. if(mysql_errno() != 0)
  158. {
  159. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/87.gif\" title = \"Bó tay!\">L?i trong quá trěnh thęm d? li?u<img src=\"images/28.gif\"></div></div>";
  160. return -1;
  161. }
  162. $mangaid1 = mysql_insert_id();
  163. // echo $mangaid1;
  164. /*
  165. $hotname = str_replace(" ","",$hotname);
  166. $hotname = str_replace("?","",$hotname);
  167. $hotname = str_replace("*","",$hotname);
  168. $hotname = str_replace("/","",$hotname);
  169. $hotname = str_replace("|","",$hotname);
  170. $hotname = str_replace(":","",$hotname);
  171. $hotname = str_replace(">","",$hotname);
  172. $hotname = str_replace("<","",$hotname);
  173. $hotname = str_replace('"',"",$hotname);
  174. $hotname = str_replace($a,"",$hotname); */
  175. $foder = "manga/".$mangaid1."/";
  176. // echo $foder;
  177. if(opendir($foder)!=FALSE){
  178. 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? manga b?n v?a post ?ă t?n t?i.Lięn h? qu?n tr? ?? bi?t thęm chi ti?t.<img src=\"images/37.gif\"></div></div>";
  179. return -1;
  180. }
  181. else{
  182. if($ico_type!=false && $img_type!=false)
  183. {
  184. mkdir($foder);
  185. $img_name = "trangbia.".$img_type;
  186. $ico_name = "m.trangbia.".$ico_type;
  187. $path_img = $foder.$img_name;
  188. $path_ico = $foder.$ico_name;
  189. $strSQL = sprintf("Update manga set Image = '%s',Icon = '%s' where MID = '%d'", $path_img,$path_ico,$mangaid1);
  190. mysql_query ($strSQL, $connection);
  191. // echo $path_img.$path_ico;
  192. move_uploaded_file($image["tmp_name"],$path_img);
  193. move_uploaded_file($icon["tmp_name"],$path_ico);
  194. }
  195. else{
  196. echo "?<div class = \"alert\"><div class= 'h10'><img src=\"images/botay.gif\" title = \"Bó tay!\">Vui lňng upload file có 1 trong 4 ??nh d?ng sau : jpg,jpeg,gif,png<img src=\"images/69.gif\"></div></div>";
  197. return -1;
  198. }
  199. $sql2 = sprintf("select MID from manga where MangaName = '%s'",$name);
  200. $result2 = mysql_query ($sql2, $connection);
  201. $num2 = mysql_num_rows($result2);
  202. if($num2 >= 1)
  203. {
  204. $row= mysql_fetch_array($result2);
  205. $mangaid = $row[0];
  206. }
  207. $sql3 = "Insert into catagorylist(CategogyID,MID) values($type,$mangaid)";
  208. $result3 = mysql_query ($sql3, $connection);
  209. $num_view = 0;
  210. $sql_view = "Insert into view(ViewCount,MID) values($num_view,$mangaid)";
  211. $result_view = mysql_query ($sql_view, $connection);
  212. mysql_close($connection);
  213. $username = $_SESSION["username"];
  214. 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>";
  215. }
  216. }
  217. }
  218. ?>