Commit a465348a authored by Ehsan Fakhraie's avatar Ehsan Fakhraie

Upload Completed

parent 6267e053
...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
<project version="4"> <project version="4">
<component name="SqlDialectMappings"> <component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/components/database/db.php" dialect="GenericSQL" /> <file url="file://$PROJECT_DIR$/components/database/db.php" dialect="GenericSQL" />
<file url="file://$PROJECT_DIR$/pages/login.php" dialect="GenericSQL" />
</component> </component>
</project> </project>
\ No newline at end of file
This diff is collapsed.
...@@ -26,6 +26,15 @@ class ValidationCode ...@@ -26,6 +26,15 @@ class ValidationCode
public $date; public $date;
public $code; public $code;
} }
class Movie{
public $id;
public $name;
public $description;
public $creator;
public $tags;
public $credits;
public $file;
}
$conn = new mysqli($servername, $username, $password, $dbname); $conn = new mysqli($servername, $username, $password, $dbname);
...@@ -51,6 +60,20 @@ function getAllUsers() ...@@ -51,6 +60,20 @@ function getAllUsers()
} }
function getAllMovies()
{
global $conn;
$sql = "SELECT * From movies";
$result = $conn->query($sql);
$movieArray = new ArrayObject(array());
while ($row = $result->fetch_assoc()) {
$movieArray->append(sqlDataToMovie($row));
}
return $movieArray;
}
function getUser($id) function getUser($id)
{ {
global $conn; global $conn;
...@@ -64,6 +87,21 @@ function getUser($id) ...@@ -64,6 +87,21 @@ function getUser($id)
} }
return $user; return $user;
} }
function getMovie($id)
{
global $conn;
$sql = "SELECT * From movies where id=" . $id;
$result = $conn->query($sql);
$movie = new User();
while ($row = $result->fetch_assoc()) {
$movie = sqlDataToMovie($row);
}
return $movie;
}
function getUserByPhone($phone) function getUserByPhone($phone)
{ {
global $conn; global $conn;
...@@ -149,9 +187,35 @@ function insertUser(User $user) ...@@ -149,9 +187,35 @@ function insertUser(User $user)
return "Error: " . $sql . "<br>" . $conn->error; return "Error: " . $sql . "<br>" . $conn->error;
} }
} }
}
function insertMovie(Movie $movie)
{
global $conn;
if(empty($movie->id)){
$sql = "INSERT INTO `movies` (`name`, `description`, `creator`, `tags`, `credits`, `file`) VALUES ('" . $movie->name . "',
'" . $movie->description . "', '" . $movie->creator . "', '" . $movie->tags . "', '" . $movie->credits . "', '" . $movie->file . "')";
if ($conn->query($sql) === TRUE) {
return $conn->insert_id;
} else {
return 0;
}
}else{
$sql ="UPDATE `movies` SET
`name` = '$movie->name', `description` = '$movie->description',
`creator` = '$movie->creator', `tags` = '$movie->tags',
`credits` = '$movie->credits', `file` = '$movie->file'
WHERE `movies`.`id` = $movie->id";
if ($conn->query($sql) === TRUE) {
return $conn->insert_id;
} else {
return 0;
}
}
} }
function sqlDataToUser($d) function sqlDataToUser($d)
{ {
$user = new User(); $user = new User();
...@@ -159,7 +223,7 @@ function sqlDataToUser($d) ...@@ -159,7 +223,7 @@ function sqlDataToUser($d)
$user->name = $d["full_name"]; $user->name = $d["full_name"];
$user->email = $d["email"]; $user->email = $d["email"];
$user->phone = $d["phone"]; $user->phone = $d["phone"];
$user->password = ""; $user->password = $d["password"];
$user->nationalCode = $d["national_code"]; $user->nationalCode = $d["national_code"];
$user->address = $d["address"]; $user->address = $d["address"];
$user->movies = $d["movies"]; $user->movies = $d["movies"];
...@@ -168,6 +232,19 @@ function sqlDataToUser($d) ...@@ -168,6 +232,19 @@ function sqlDataToUser($d)
return $user; return $user;
} }
function sqlDataToMovie($d){
$movie = new Movie();
$movie->id = $d["registered"];
$movie->name = $d["name"];
$movie->description = $d["description"];
$movie->creator = $d["creator"];
$movie->credits = $d["credits"];
$movie->tags = $d["tags"];
$movie->tags = $d["tags"];
$movie->file = $d["file"];
return $movie;
}
function insertUsersByJson($file) function insertUsersByJson($file)
{ {
$studentjsondata = file_get_contents($file); $studentjsondata = file_get_contents($file);
......
...@@ -33,7 +33,8 @@ if(isset($_SESSION["id"])){ ...@@ -33,7 +33,8 @@ if(isset($_SESSION["id"])){
if(!$error){ if(!$error){
if(insertUser($user)){ if(insertUser($user)){
header("location:login.php"); $_SESSION["loggedIn"]=1;
header("location:welcome.php");
} }
} }
......
<?php <?php
include "../components/functions.php"; include "../components/functions.php";
include "../components/database/db.php";
session_start();
if (isset($_SESSION["loggedIn"]) && $_SESSION["loggedIn"] === true) {
header("location: welcome.php");
exit;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$password_err = $phone_err = $phone = $password = "";
if (empty(trim($_POST["phone"]))) {
$phone_err = "لطفا شماره تلفن خود را وارد کنید.";
} else {
$phone = trim($_POST["phone"]);
}
// Check if password is empty
if (empty(trim($_POST["password"]))) {
$password_err = "لطفا پسورد خود را وارد کنید.";
} else {
$password = trim($_POST["password"]);
}
if (empty($email_err) && empty($password_err)) {
$user=getUserByPhone($phone);
if($user){
echo $password;
echo $user->password;
if (password_verify($password, $user->password)) {
session_start();
$_SESSION['id']=$user->id;
$_SESSION["loggedIn"]=1;
header("location:welcome.php");
}else{
$password_err = "پسورد غلط است.";
}
}else{
$phone_err="کاربر با شماره وارد شده یافت نشد.";
}
}
}
?> ?>
...@@ -8,7 +56,6 @@ include "../components/functions.php"; ...@@ -8,7 +56,6 @@ include "../components/functions.php";
<head> <head>
<?php <?php
echo css_include(); echo css_include();
echo script_include(); echo script_include();
?> ?>
...@@ -17,22 +64,31 @@ include "../components/functions.php"; ...@@ -17,22 +64,31 @@ include "../components/functions.php";
<body> <body>
<div class="container" id="login_container"> <div class="container" id="login_container">
<div class="flex-container"> <div class="flex-container">
<form class="border" id="form_border"> <form class="border" id="form_border" method="post" action="login.php">
<div class="form-group py-4"> <div class="form-group py-4">
<span class="login_title py-3" style="font-family:'B Titr'">ورود</span> <span class="login_title py-3" style="font-family:'B Titr'">ورود</span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="mobile">تلفن همراه</label> <label for="mobile">تلفن همراه</label>
<input type="text" class="form-control rounded-pill" id="mobile" aria-describedby="mobileErr" <input type="text" class="form-control rounded-pill" id="mobile" name="phone" aria-describedby="mobileErr"
placeholder="۰۹۱۲-------" maxlength="11"> placeholder="۰۹۱۲۳۴۵۶۷۸" maxlength="11">
<small id="mobileErr" style="color: red"></small> <small id="mobileErr" style="color: red">
<?php
if(!empty($phone_err))
echo $phone_err;
?>
</small>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="exampleInputPassword1">رمز عبور</label> <label for="exampleInputPassword1">رمز عبور</label>
<input type="password" class="form-control rounded-pill" id="exampleInputPassword1" <input type="password" class="form-control rounded-pill" id="password" name="password"
aria-describedby="passErr"> aria-describedby="passErr">
<small id="passErr" style="color:red"></small> <small id="passErr" style="color:red">
<?php
if(!empty($password_err))
echo $password_err;
?>
</small>
</div> </div>
<div class="form-group"> <div class="form-group">
<a href="#">رمز عبورم را فراموش کرده‌ام</a> <a href="#">رمز عبورم را فراموش کرده‌ام</a>
...@@ -59,12 +115,12 @@ include "../components/functions.php"; ...@@ -59,12 +115,12 @@ include "../components/functions.php";
var v = document.getElementById("mobile").value; var v = document.getElementById("mobile").value;
{ {
if (v.length != 0) { if (v.length != 0) {
var flag=0; var flag = 0;
if(v.length!=11){ if (v.length != 11) {
flag=1; flag = 1;
} }
if(v[0]!="0"){ if (v[0] != "0") {
flag=1; flag = 1;
} }
if (flag) { if (flag) {
document.getElementById('mobileErr').innerHTML = 'شماره موبایل فاقد اعتبار است'; document.getElementById('mobileErr').innerHTML = 'شماره موبایل فاقد اعتبار است';
......
var isFormValid=0;
var isUploadValid=0;
function _(el) { function _(el) {
return document.getElementById(el); return document.getElementById(el);
} }
...@@ -42,7 +44,7 @@ function uploadFile() { ...@@ -42,7 +44,7 @@ function uploadFile() {
ajax.addEventListener("load", completeHandler, false); ajax.addEventListener("load", completeHandler, false);
ajax.addEventListener("error", errorHandler, false); ajax.addEventListener("error", errorHandler, false);
ajax.addEventListener("abort", abortHandler, false); ajax.addEventListener("abort", abortHandler, false);
ajax.open("POST", "../videoTest/upload.php"); // http://www.developphp.com/video/JavaScript/File-Upload-Progress-Bar-Meter-Tutorial-Ajax-PHP ajax.open("POST", "upload.php"); // http://www.developphp.com/video/JavaScript/File-Upload-Progress-Bar-Meter-Tutorial-Ajax-PHP
//use file_upload_parser.php from above url //use file_upload_parser.php from above url
ajax.send(formdata); ajax.send(formdata);
} }
...@@ -68,6 +70,12 @@ function completeHandler(event) { ...@@ -68,6 +70,12 @@ function completeHandler(event) {
_("status").style.color="green"; _("status").style.color="green";
_("status").innerHTML = event.target.responseText; _("status").innerHTML = event.target.responseText;
// _("dynamic").style.display="none"; // _("dynamic").style.display="none";
_("status").innerHTML="<video width=\"400\" controls>\n" +
" <source src=\""+event.target.responseText+"\" type=\"video/mp4\">\n" +
"</video>";
_("status").innerHTML+="<br/>";
_("status").innerHTML+="فایل با موفقیت آپلود شد.";
isUploadValid=1;
} }
...@@ -92,3 +100,46 @@ String.prototype.toPersianDigit = function() { ...@@ -92,3 +100,46 @@ String.prototype.toPersianDigit = function() {
return ret; return ret;
}); });
}; };
function sendData() {
var nc=_("nationalCode").value;
var fixedNumber=_("fixedNumber").value;
var address=_("address").value;
var postalCode=_("postalCode").value;
_("mcErr").innerHTML="";
_("ftErr").innerHTML="";
_("addressErr").innerHTML="";
_("zipErr").innerHTML="";
var error=0;
if(nc.length===0){
_("mcErr").innerHTML="کد ملی را وارد کنید.";
error=1;
}
if(fixedNumber.length===0){
_("ftErr").innerHTML="تلفن ثابت را وارد کنید.";
error=1;
}
if(address.length===0){
_("addressErr").innerHTML="آدرس را وارد کنید.";
error=1;
}
if(postalCode.length===0){
_("zipErr").innerHTML="کد پستی را وارد کنید.";
error=1;
}
if(!isUploadValid){
_("status").innerHTML="لطفا فایل را آپلود کنید.";
error=1;
}
if(!error){
document.getElementById("form_border").submit();
}
}
*{
direction: rtl;
}
video {
width: 100%;
height: auto;
}
#form_border{ #form_border{
padding: 50px; padding: 50px;
......
<?php <?php
include "../components/functions.php"; include "../components/functions.php";
include "../components/database/db.php";
session_start();
$user=getUser($_SESSION["id"]);
if(!$_SESSION["loggedIn"]){
header("location:login.php");
}else if(isset($_POST["postalCode"])){
$user->nationalCode=$_POST["nationalCode"];
$user->address=$_POST["address"];
if(isset($_SESSION["uploadedVideo"])){
$movie= new Movie();
$movie->file=$_SESSION["uploadedVideo"];
$movie->creator=$user->id;
$id=insertMovie($movie);
if($id!=0){
$user->movies=$id;
insertUser($user);
header("location:uploadSuccessful.php");
}else{
echo "error";
exit();
}
}else{
echo "error";
exit();
}
echo "s";
}else if(isset($_FILES['myfile'])){
// form submit
$files = $_FILES['myfile'];
$fn = $files['name'];
move_uploaded_file(
$files['tmp_name'],
'../uploads/' . $fn
);
echo "../uploads/$fn";
//echo "<p>فایل با موفقیت آپلود شد.</p>";
$_SESSION["uploadedVideo"]=$fn;
exit();
}
?> ?>
<!DOCTYPE> <!DOCTYPE>
<html> <html>
...@@ -18,7 +59,7 @@ include "../components/functions.php"; ...@@ -18,7 +59,7 @@ include "../components/functions.php";
<div class="container " id="register_container"> <div class="container " id="register_container">
<form class="border" id="form_border"> <form class="border" id="form_border" method="post" action="upload.php">
<div class="form-group py-4"> <div class="form-group py-4">
<span class="login_title py-3" style="font-family:'B Titr'">آپلود ویدیو</span> <span class="login_title py-3" style="font-family:'B Titr'">آپلود ویدیو</span>
</div> </div>
...@@ -29,7 +70,7 @@ include "../components/functions.php"; ...@@ -29,7 +70,7 @@ include "../components/functions.php";
<label for="file1" class="custom-file-upload" id="upload-btn"> <label for="file1" class="custom-file-upload" id="upload-btn">
آپلود فیلم آپلود فیلم
</label> </label>
<input id="file1" type="file" onchange="uploadFile()"/> <input id="file1" type="file" onchange="uploadFile()"/>
</div> </div>
...@@ -43,58 +84,65 @@ include "../components/functions.php"; ...@@ -43,58 +84,65 @@ include "../components/functions.php";
<br> <br>
</div> </div>
</div> </div>
<div id="status" style="color:red"></div>
<div class="row" id="status" style="color:red"></div>
<hr id="sp-line"> <hr id="sp-line">
<div class="form-group"> <div class="form-group">
<p style="text-align: center;font-size: 30px" >اطلاعات شخصی</p> <p style="text-align: center;font-size: 30px" >اطلاعات شخصی</p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="fullName">نام و نام خانوادگی</label> <label for="fullName">نام و نام خانوادگی</label>
<input type="text" class="form-control rounded-pill" id="fullName" aria-describedby="mcErr" disabled> <input type="text" class="form-control rounded-pill" id="fullName" aria-describedby="mcErr" disabled STYLE="text-align: right;" value="<?php
<small id="mcErr" style="color:red"></small> if(isset($user->name))
echo $user->name;
?>">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="phone">شماره موبایل</label> <label for="phone">شماره موبایل</label>
<input type="text" class="form-control rounded-pill" id="phone" aria-describedby="mcErr" disabled> <input type="text" class="form-control rounded-pill" id="phone" aria-describedby="mcErr" disabled value="<?php
<small id="mcErr" style="color:red"></small> if(isset($user->phone))
</div> echo $user->phone;
?>">
<div class="form-group">
<label for="mc">کدملی</label>
<input type="text" class="form-control rounded-pill" id="mc" aria-describedby="mcErr" placeholder="0021234567">
<small id="mcErr" style="color:red"></small>
</div>
<div class="form-group">
<label for="fixedNumber">تلفن ثابت</label>
<input type="text" class="form-control rounded-pill" id="fixedNumber" aria-describedby="ftErr" placeholder="02122334455">
<small id="ftErr" style="color:red"></small>
</div>
<div class="form-group">
<label for="address">آدرس</label>
<textarea class="form-control" id="address" rows="3"></textarea>
<small id="addressErr" style="color:red"></small>
</div>
<div class="form-group">
<label for="zip">کدپستی</label>
<input type="text" class="form-control rounded-pill" id="zip" aria-describedby="zipErr">
<small id="zipErr" style="color:red"></small>
</div> </div>
<hr id="sp-line"> <div class="form-group">
<div class="form-group"> <label for="mc">کدملی</label>
<p style="text-align: center;font-size: 30px" >اطلاعات فیلم</p> <input type="text" class="form-control rounded-pill" id="nationalCode" name="nationalCode" aria-describedby="mcErr" placeholder="0021234567">
</div> <small id="mcErr" style="color:red"></small>
<div class="form-group"> </div>
<label for="groupMembers">نام اعضای گروه</label> <div class="form-group">
<input type="text" class="form-control rounded-pill" id="groupMembers" aria-describedby="gpmErr" style="text-align: right"> <label for="fixedNumber">تلفن ثابت</label>
<small id="gpmErr" style="color:red"></small> <input type="text" class="form-control rounded-pill" id="fixedNumber" name="fixedNumber" aria-describedby="ftErr" placeholder="02122334455">
</div> <small id="ftErr" style="color:red"></small>
<div class="form-group"> </div>
<label for="movieName">نام فیلم</label> <div class="form-group">
<input type="text" class="form-control rounded-pill" id="movieName" aria-describedby="mnErr" style="text-align: right"> <label for="address">آدرس</label>
<small id="mnErr" style="color:red"></small> <textarea class="form-control" id="address" name="address" rows="3"></textarea>
</div> <small id="addressErr" style="color:red"></small>
<button type="submit" class="btn btn-primary rounded-pill pb-2" style="background-color: green;border-color: green;width: 100%">ارسال</button> </div>
<div class="form-group">
<label for="zip">کدپستی</label>
<input type="text" class="form-control rounded-pill" id="postalCode" name="postalCode" aria-describedby="zipErr">
<small id="zipErr" style="color:red"></small>
</div>
<hr id="sp-line">
<div class="form-group">
<p style="text-align: center;font-size: 30px" >اطلاعات فیلم</p>
</div>
<div class="form-group">
<label for="groupMembers">نام اعضای گروه</label>
<input type="text" class="form-control rounded-pill" id="groupMembers" aria-describedby="gpmErr" style="text-align: right">
<small id="gpmErr" style="color:red"></small>
</div>
<div class="form-group">
<label for="movieName">نام فیلم</label>
<input type="text" class="form-control rounded-pill" id="movieName" aria-describedby="mnErr" style="text-align: right">
<small id="mnErr" style="color:red"></small>
</div>
<button type="button" ID="submitBtn" class="btn btn-primary rounded-pill pb-2" style="background-color: green;border-color: green;width: 100%" onclick="sendData()">ارسال</button>
</form> </form>
...@@ -104,7 +152,6 @@ include "../components/functions.php"; ...@@ -104,7 +152,6 @@ include "../components/functions.php";
</div> </div>
</div> </div>
<script src="script/uploadVideo.js"></script> <script src="script/uploadVideo.js"></script>
</body> </body>
</html> </html>
<?php
include "../components/functions.php";
session_start();
if(!$_SESSION["loggedIn"]){
header("location:login.php");
}
?>
<!DOCTYPE>
<html>
<head>
<?php
echo css_include();
echo script_include();
?>
</head>
<body>
<div class="container" id="login_container">
<div class="flex-container">
<form class="border" id="form_border">
<div class="form-group py-4">
<span class="login_title py-3" style="font-family:'B Titr',serif">ارسال اثر</span>
</div>
<div class="row">
اثر شما با موفقیت ارسال شد.
</div>
<br>
<div class="row">
<div class="col-3"></div>
<button type="button"
class="btn btn-primary rounded-pill pb-2 col-6 default_btn" id="submitButton">بازگشت به سایت
</button>
<div class="col-3"></div>
</div>
</form>
</div>
</div>
</body>
</html>
<?php
include "../components/functions.php";
session_start();
if(!$_SESSION["loggedIn"]){
header("location:login.php");
}
?>
<!DOCTYPE> <!DOCTYPE>
<html> <html>
<head> <head>
<link rel="stylesheet" media="screen" href="https://fontlibrary.org/face/iranian-sans" type="text/css"/> <?php
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> echo css_include();
<link rel="stylesheet" href="style/style.css"> echo script_include();
<meta charset="utf-8"> ?>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head> </head>
<style>
</style> <body>
<body >
<div class="container" id="login_container"> <div class="container" id="login_container">
<div class="flex-container"> <div class="flex-container">
<form class="border" id="form_border"> <form class="border" id="form_border">
<div class="form-group py-4"> <div class="form-group py-4">
<span class="login_title py-3" style="font-family:'B Titr'">ثبت نام شما با موفقیت صورت گرفت</span> <span class="login_title py-3" style="font-family:'B Titr',serif">خوش آمدید</span>
</div>
<div class="row">
کاربر گرامی به ششمین جشنواره فیلم مدرسه خوش آمدید، در صورت تمایل برای ارسال اثر ادامه دهید.
</div> </div>
<br> <br>
<div class="row"> <div class="row">
<button type="submit" <button type="button"
class="btn btn-primary rounded-pill pb-2 col-5 default_btn" id="submitButton">بازگشت به سایت</button> class="btn btn-primary rounded-pill pb-2 col-5 default_btn" id="submitButton">بازگشت به سایت
</button>
<div class="col-2"></div> <div class="col-2"></div>
<button onclick="location.href='#';" <button onclick="location.href='upload.php';"
type="button" class="btn btn-primary rounded-pill col-5 default_btn" id="button" >ارسال فیلم</button> type="button" class="btn btn-primary rounded-pill col-5 default_btn" id="button">ارسال فیلم
</button>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
</body> </body>
</html> </html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
<?php
///*
//Server-side PHP file upload code for HTML5 File Drag & Drop demonstration
//Featured on SitePoint.com
//Developed by Craig Buckler (@craigbuckler) of OptimalWorks.net
//*/
$fn = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);
if ($fn) {
// AJAX call
file_put_contents(
'uploads/' . $fn,
file_get_contents('php://input')
);
echo "$fn uploaded";
exit();
}
else {
// form submit
$files = $_FILES['myfile'];
$fn = $files['name'];
move_uploaded_file(
$files['tmp_name'],
'uploads/' . $fn
);
echo "<p>File $fn uploaded.</p>";
}
//
//$xhr = $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
//if (!$xhr)
// echo '<textarea>';
//?>
<!---->
<!--// main content of response here-->
<!---->
<?php
//if (!$xhr)
// echo '</textarea>';
//?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment