/new/PHPSource/newpost.php
PHP | 337 lines | 278 code | 52 blank | 7 comment | 47 complexity | 70d1a54c0a37fbf3411f823cd918926e 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{
- echo "<div class = \"headnewmanga\"><h3>Thęm chapter m?i</h3></div>";
- echo "<form id=\"frmNewpost\" name=\"frmNewpost\" method=\"post\" action=\"\" enctype=\"multipart/form-data\">
- <div class=\"newmanga\">
-
- <table width=\"533\" border=\"0\">
- <tr>
- <td>Chọn manga </td>
- <td><select name=\"MangaId\" id=\"MangaId\">";
-
-
- $sql_manga = "select MID,MangaName from manga where Passed = 2 order by MangaName";
- $result_manga = mysql_query($sql_manga,$connection);
- $num_manga = mysql_num_rows($result_manga);
- if($num_manga > 0){
-
- while($row_manga= mysql_fetch_array($result_manga)){
- echo "<option value = \"$row_manga[0]\"";
- if($_POST['MangaId'] == $row_manga[0])
- echo "selected";
- echo ">$row_manga[1]</option>";
- }
- }
-
- $txt_name = $_POST['txtName'];
- $txt_no = $_POST['txtNo'];
- echo "
- </select></td>
- </tr>
- <tr>
- <td width=\"100\">Tên chap </td>
- <td width=\"423\"><input name=\"txtName\" type=\"text\" id=\"txtName\" size=\"35\" value = \"$txt_name\" ";
-
- echo "/></td>
- </tr>
- <tr>
- <td>Số thứ tự </td>
- <td><input name=\"txtNo\" type=\"text\" id=\"txtNo\" value = \"$txt_no\"/><div id =\"check_no\"></div></td>
- </tr>
- <tr><td>Cách upload ?nh</td>
- <td><select name=\"uptype\" id=\"select_uptype\" >
- <option value=\"1\"";
- if($_POST['uptype']=="1")
- echo "selected";
- echo ">Důng ?nh ?ă ???c upload tr??c</option>
- <option value=\"2\"";
- if($_POST['uptype']=="2")
- {
- //echo "selected";
- }
- echo ">Upload ?nh t? máy cá nhân</option>
- </select></td></tr>
- </table> </div>
-
- <div class=\"newmanga\">
- <div id = \"ajax_here\">
- <table width=\"533\" border=\"0\">
-
- <tr>
- <td width=\"100\">Hình ảnh </td>
- <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
- <textarea name=\"txtImg\" rows=\"5\" id=\"txtImg\" cols=\"50\"></textarea>
- </label>
- </td>
- </tr>
- </div>
- </table></div> </div>
- <p align=\"center\">
- <label>
- <input type=\"submit\" name=\"Submit\" value=\"Thêm\">
- </label>
- <label>
- <input type=\"reset\" name=\"Submit2\" value=\"Xóa trắng\">
- </label>
- </p>
-
-
- </form>";
-
- function get_path($mid)
- {
- include('dbconfig.php');
- $sql = "select Image from manga where MID = $mid";
- $result = mysql_query($sql,$connection);
- $num = mysql_num_rows($result);
- if($num >=1){
- $row = mysql_fetch_array($result);
- $img = $row[0];
- }
- $pos = strrpos($img,"/");
- if($pos === false)
- return NULL;
- else
- $path = substr($img,0,$pos);
- return $path;
- mysql_close($connection);
-
- }
- function cat_url($str){
- if($str != "" && $str != NULL &&$str != " "){
- /* dua chuoi ve dinh dang chuan */
- $str = str_replace("HTTP://","http://",$str);
-
- $str = str_replace("HtTP://","http://",$str);
- $str = str_replace("HTtP://","http://",$str);
- $str = str_replace("HTTp://","http://",$str);
- $str = str_replace("hTTP://","http://",$str);
-
- $str = str_replace("htTP://","http://",$str);
- $str = str_replace("hTtP://","http://",$str);
- $str = str_replace("hTTp://","http://",$str);
-
- $str = str_replace("HttP://","http://",$str);
- $str = str_replace("HtTp://","http://",$str);
-
- $str = str_replace("HTtp://","http://",$str);
-
- $str = str_replace("httP://","http://",$str);
- $str = str_replace("Http://","http://",$str);
- $str = str_replace("hTtp://","http://",$str);
- $str = str_replace("htTp://","http://",$str);
-
-
- /* ket thuc chuan hoa chuoi */
-
- $pos = strpos($str,"http://");
- if($pos === false)
- return NULL;
- $pos = strpos($str,".");
- if($pos === false)
- return NULL;
- $arr = explode("http://",$str);
- $new_arr = array(count($arr)-1);
- for($i = 1;$i < count($arr);$i++)
- {
- $arr[$i] = "http://".$arr[$i];
- $new_arr[$i-1] = $arr[$i];
- }
- return $new_arr;
- }
- else
- return NULL;
- }
- if($_POST['Submit']==true)
- {
- $up_type = $_POST['uptype'];
- $up_type = (int)$up_type;
- if($up_type==1)
- {
-
- $fileup= NULL;
- $pic = $_POST['txtImg'];
- $name = $_POST['txtName'];
- $mangaid = $_POST['MangaId'];
- $uid = $_SESSION['userid'];
- $stt = 0;
- $post_date=gmdate('Y-m-d', time()+(25200)); //GMT +7
-
-
-
- if(is_numeric($_POST['txtNo']) == false || $_POST['txtNo'] < 0)
- {
- 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>";
-
- return -1;
- }
- $no = $_POST['txtNo'];
- $no = (int)$no;
-
- if( !isset($name) ||$name==NULL || !isset($pic) ||$pic==NULL || !isset($no) ||$no==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;
-
- }
- $sttok = 1;
- $sql_checkno =sprintf("select PID from posting where MID = '%s' and ChapNo='%d' and Status ='%d'",$mangaid,$no,$sttok);
- $result_checkno = mysql_query ($sql_checkno, $connection);
- $num_checkno = mysql_num_rows($result_checkno);
- if($num_checkno>0)
- {
- $row_checkno= mysql_fetch_array($result_checkno);
- 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>";
- return -1;
- }
-
- $arr_pic = cat_url($pic);
- if(count($arr_pic)<1 || $arr_pic == NULL){
- 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>";
- return -1;
-
- }
-
- $strSQL = sprintf("Insert into posting
- (
- UID,DateAdded,LastUpdate,
- Status,MID,ChapName,
- ChapNo
- )
- values
- (
- '%d','%s','%s',
- '%d','%d','%s',
- '%d'
-
- )
- ", $uid,$post_date,$post_date,$stt, $mangaid,$name,$no);
- mysql_query ($strSQL, $connection);
- $postid = mysql_insert_id();
- $chapid = 0;
- for($i = 1;$i <= count($arr_pic);$i++)
- {
- $sql = sprintf("Insert into
- imagepath(PID,ImageNo,ImagePath)
- values
- (
- '%d','%d','%s'
- )",$postid,$i,$arr_pic[$i-1]);
-
- mysql_query ($sql, $connection);
- // echo $sql;
- }
- 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>";
- }
- if($up_type==2)//chon upload tu may ca nhan
- {
- $fileup= $_FILES['fileuploaded'];
- $pic = NULL;
- $name = $_POST['txtName'];
- $mangaid = $_POST['MangaId'];
- $uid = $_SESSION['userid'];
- $stt = 0;
- $post_date=gmdate('Y-m-d', time()+(25200)); //GMT +7
-
-
- if(is_numeric($_POST['txtNo']) == false || $_POST['txtNo'] < 0)//kiem tra thu tu cua chap hop le
- {
- 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>";
- return -1;
- }
- $no = $_POST['txtNo'];
- $no = (int)$no;
- //kiem tra tat ca thong tin duoc nhap day du
- if( !isset($name) ||$name==NULL || !isset($fileup) ||$fileup==NULL || !isset($no) ||$no==NULL ||
- (count($fileup['size']) ==1 && ($fileup['size'][0] == 0 ) ))
- {
- 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;
-
- }
- //kiem tra xem chap nay da duoc post truoc hay chua
- $sttok = 1;
- $sql_checkno =sprintf("select PID from posting where MID = '%s' and ChapNo='%d' and Status ='%d'",$mangaid,$no,$sttok);
- $result_checkno = mysql_query ($sql_checkno, $connection);
- $num_checkno = mysql_num_rows($result_checkno);
- if($num_checkno>0)
- {
- $row_checkno= mysql_fetch_array($result_checkno);
- 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>";
- return -1;//chap da dc post truoc,xuat thong bao loi
- }
- $path = get_path($mangaid);
- if($no<10)
- $chapnum = "00".$no;
- else if($no >9 && $no<100)
- $chapnum = "0".$no;
- else
- $chapnum = "".$no;
- $real_path = $path."/".$chapnum."/";
- if(opendir($real_path)!=FALSE)//foder nay da ton tai
- {
- 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.
- B?n c?ng có th? s? d?ng ?nh ?ă upload ?? tránh l?i nŕy<img src=\"images/37.gif\"></div></div>";
-
- }else{
- mkdir($real_path);//tao foder
- $strSQL = sprintf("Insert into posting
- (
- UID,DateAdded,LastUpdate,
- Status,MID,ChapName,
- ChapNo
- )
- values
- (
- '%d','%s','%s',
- '%d','%d','%s',
- '%d'
-
- )
- ", $uid,$post_date,$post_date,$stt, $mangaid,$name,$no);
- mysql_query ($strSQL, $connection);//them thong tin ve posting vao trong csdl
- $postid = mysql_insert_id();
- $total_pic = count($fileup['name']);
- for($i = 0;$i<$total_pic;$i++)
- {
- $imgs_path = $real_path.$fileup["name"][$i];
- move_uploaded_file($fileup["tmp_name"][$i],$imgs_path);//di chuyen hinh anh vao thu muc moi tao
- $sql = sprintf("Insert into
- imagepath(PID,ImageNo,ImagePath)
- values
- (
- '%d','%d','%s'
- )",$postid,$i+1,$imgs_path);
-
- mysql_query ($sql, $connection);//chen link anh vao csdl
- }
- $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 chapter:$name.<img src=\"images/26.gif\"></div></div>";
-
- }
-
- }
-
-
-
-
-
-
-
-
- }
- }
- ?>