/new/PHPSource/newmanga.php
PHP | 235 lines | 220 code | 10 blank | 5 comment | 8 complexity | 54babb749eef7bfd0d59e8d06eefe358 MD5 | raw file
-
- <?php
- session_start();
- include('dbconfig.php');
- /*kiem tra cac thong so quyen han */
- if(!isset($_SESSION['userid']) || !isset($_SESSION["power"])){
- 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>
- </div>";
- }
- else{
- /* quyen han hop le,xuat ra form nhap manga moi */
-
-
- $name = $_POST['name'];
- $author = $_POST['author'];
- $type = $_POST['type'];
- $summary = $_REQUEST['summary'];
- $image= $_FILES['image'];
- $icon = $_FILES['icon'];
-
- $sql_type ="select * from category";
- $result_type = mysql_query($sql_type,$connection);
- echo "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"frmNewmanga\">";
- echo "<div class = \"headnewmanga\"><h3>Thęm manga m?i</h3><div class=\"khoangcach1\"></div></div>";
- echo "<div class=\"newmanga\">";
- echo "
- <table border=\"0\">
- <tr>
- <td>Tęn manga </td>
- <td><label>
- <input name=\"name\" type=\"text\" id=\"name\" size ='45' value =\"$name\" >
- </label></td>
- </tr>
- <tr>
- <td width=\"100\">Tác gi? </td>
- <td width=\"253\">
- <input name=\"author\" type=\"text\" id=\"author\" size ='45' value =\"$author\" >
- </td>
- </tr>
- <tr>
- <td>Th? lo?i </td>
- <td>
- <select name=\"type\">";
- while($row_type = mysql_fetch_array($result_type))
- {
- echo "<option value=\"$row_type[0]\" ";
- if($type==$row_type[0])
- echo "selected";
- echo ">$row_type[1]</option>";
- }
- echo " </select>
- </td>
- </tr>
- <tr>
- <td>Tóm t?t</td>
- <td>";
-
- /* <label>
- <textarea name=\"summary\" id=\"summary\" rows =\"5\" cols=\"40\"></textarea>
- </label> */
- echo "<script type=\"text/javascript\" src=\"js/editor.js\"></script>
- <span id=\"postArea\"><br><br><br><br> Loading...</span>
- <script type=\"text/javascript\">
- RTE=new Editor('RTE','postArea','',470, 350);
- RTE.removeButton('btnQuote','btnCode','btnUnformat','btnAlignJustify');
- RTE.display();
- </script>
- ";
- echo "
- <input name=\"summary\" type=\"hidden\" id=\"summary\">
- <br>
- </td>
- </tr>
- <tr>
- <td>?nh minh h?a</td>
- <td><label>
- <input name=\"image\" type=\"file\" id=\"image\" value=\"\" size ='45'>
- </label></td>
- </tr>
- <tr>
- <td>?nh icon</td>
- <td><label>
- <input name=\"icon\" type=\"file\" id=\"icon\" size ='45' >
- </label></td>
- </tr>
- </table></div>";
-
-
- echo "<center><p>
- <label>
- <input type=\"Submit\" name=\"Submit\" value=\"Thęm\" onclick=\"doSubmit();\">
- </label>
- <label>
- <input type=\"reset\" name=\"Submit2\" value=\"Reset\">
- </label>
- </p></center>
- </form> ";
- }
- ?>
- <?php
- function check_file($str)
- {
- if(strlen($str) <=0)
- return false;
- if(strpos($str,".")==false)
- return false;
- $post = strrpos($str,".");
- $type = substr($str,$post+1);
- if(strcmp($type,"jpg")!=0 && strcmp($type,"jpeg")!=0 &&strcmp($type,"gif")!=0 &&strcmp($type,"png")!=0 )
- {
-
- return false;
- }
- return $type;
-
- }
- if($_POST['Submit']==TRUE)
- {
-
- $name = $_POST['name'];
- $name = str_replace("'","\'",$name);
-
-
- $author = $_POST['author'];
- $author = str_replace("'","\'",$author);
- $type = $_POST['type'];
- $summary = $_REQUEST['summary'];
- $summary = str_replace("'","\'",$summary);
- $image= $_FILES['image'];
- $icon = $_FILES['icon'];
- $a = (string)" \ ";
- $a = trim($a);
-
- if( !isset($name) ||$name==NULL ||!isset($author) ||$author==NULL ||!isset($summary) ||$summary==NULL ||!isset($image) ||$image==NULL ||!isset($icon) ||$icon==NULL)
- {
- 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>";
- return -1;
- }
- $sql_check ="select * from manga where MangaName = '$name'";
- $result_check = mysql_query($sql_check,$connection);
- $num_rs_check = mysql_num_rows($result_check);
- if($num_rs_check >=1){
- $row_check = mysql_fetch_array($result_check);
- 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>";
- return -1;
- }else{
- $img_type = check_file($image["name"]);
- $ico_type = check_file($icon["name"]);
- if($ico_type==false && $img_type==false)
- {
- 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>";
- return -1;
- }
- $date=gmdate('Y-m-d', time()+(25200));
- $uid = $_SESSION['userid'];
- $passed = 0; //dang cho duyet
- $stt = 1; //dang update
- $strSQL = sprintf("Insert into manga
- (
- MangaName,DateAdded,Status,
- UID,Summary,Passed,Author
- )
- values
- (
- '%s','%s','%d',
- '%d','%s','%d','%s'
-
- )
- ", $name,$date, $stt, $uid, $summary,$passed,$author);
- mysql_query ($strSQL, $connection);
- if(mysql_errno() != 0)
- {
- 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>";
- return -1;
- }
- $mangaid1 = mysql_insert_id();
- // echo $mangaid1;
- /*
- $hotname = str_replace(" ","",$hotname);
- $hotname = str_replace("?","",$hotname);
- $hotname = str_replace("*","",$hotname);
- $hotname = str_replace("/","",$hotname);
- $hotname = str_replace("|","",$hotname);
- $hotname = str_replace(":","",$hotname);
- $hotname = str_replace(">","",$hotname);
- $hotname = str_replace("<","",$hotname);
- $hotname = str_replace('"',"",$hotname);
- $hotname = str_replace($a,"",$hotname); */
- $foder = "manga/".$mangaid1."/";
- // echo $foder;
-
- if(opendir($foder)!=FALSE){
- 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>";
- return -1;
- }
- else{
- if($ico_type!=false && $img_type!=false)
- {
- mkdir($foder);
- $img_name = "trangbia.".$img_type;
- $ico_name = "m.trangbia.".$ico_type;
- $path_img = $foder.$img_name;
- $path_ico = $foder.$ico_name;
- $strSQL = sprintf("Update manga set Image = '%s',Icon = '%s' where MID = '%d'", $path_img,$path_ico,$mangaid1);
- mysql_query ($strSQL, $connection);
- // echo $path_img.$path_ico;
- move_uploaded_file($image["tmp_name"],$path_img);
- move_uploaded_file($icon["tmp_name"],$path_ico);
- }
- else{
- 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>";
- return -1;
- }
-
- $sql2 = sprintf("select MID from manga where MangaName = '%s'",$name);
- $result2 = mysql_query ($sql2, $connection);
- $num2 = mysql_num_rows($result2);
- if($num2 >= 1)
- {
- $row= mysql_fetch_array($result2);
- $mangaid = $row[0];
- }
- $sql3 = "Insert into catagorylist(CategogyID,MID) values($type,$mangaid)";
- $result3 = mysql_query ($sql3, $connection);
- $num_view = 0;
- $sql_view = "Insert into view(ViewCount,MID) values($num_view,$mangaid)";
- $result_view = mysql_query ($sql_view, $connection);
- mysql_close($connection);
- $username = $_SESSION["username"];
- 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>";
- }
- }
- }
-
- ?>