-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewSource.php
106 lines (101 loc) · 3.39 KB
/
viewSource.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
require "template/pdo.php";
if(isset($_POST["name"])){
$id=$_POST["id"];
$name=$_POST["name"];
$data=$_POST["data"];
$status=$_POST["status"];
$cur_date = date("Y-m-d");
$files=$_POST["fn"];
if(isset($_FILES["files"]["tmp_name"])){//เชคว่ามาการส่งไฟล์หรือไม่
$f=1;
unlink("source/".$id.".zip");
$zip = new ZipArchive();
$zip->open('source/'.$id.'.zip', ZipArchive::CREATE);
$zip->addFile($_FILES["files"]["tmp_name"],$_FILES["files"]["name"]);
$zip->close();
}
$data=htmlentities($data);
$sql = "update source set name=:name,data= :data,status= :status,cur_date= :cur_date,files= :files where id='$id'";
$sth = $pdo->prepare($sql);
$sth->execute(array(
':name' => $name,
':data'=> $data,
':status' => $status,
':cur_date' => $cur_date,
':files' => $files
));
header("location:viewSource.php?id=$id");
}
?>
<!DOCTYPE html>
<?php include "template/pdo.php";
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/bootstrap.min.css" type="text/css" rel="stylesheet" >
<link href="css/bootstrap-theme.min.css" type="text/css" rel="stylesheet" >
<link href="css/style.css" type="text/css"rel="stylesheet" >
<title>CodeSpace</title>
</head>
<body class="col-lg-12">
<div>
<div class="container"> <?php require "template/menu.php";
$id=$_GET["id"];
$temp=$pdo->query("select * from source where id ='$id'");
$data=$temp->fetch();
?><!--I'm Menu Bar-->
<div class="ct"><!--This is Container -->
<br><br>
<form enctype="multipart/form-data" action="viewSource.php" method="post">
<fieldset>
<label for="name">Name:</label>
<input class="form-control" type="text" name="name" value="<?php echo $data["name"]; ?>" autofocus required>
<label for="data">Code:</label>
<textarea name="data" class="form-control" rows="20"><?php echo $data["data"]; ?></textarea>
<div><!--ไฟล์ -->
<?php
if($data["files"]==1){
$zip = new ZipArchive;
$location="source/".$id.".zip";
if ($zip->open($location) === TRUE) {
echo "Files:";
for ($i = 0; $i < $zip->numFiles; $i++) {
echo $zip->getNameIndex($i) . "<br />";
}
echo "<a href='$location'>Download Now!</a>";
}
}if(isset($_SESSION["username"])){//check session
if($_SESSION["username"]=="Administrator"||$_SESSION["username"]==$data["own"]){//check Own
?>
<br>
<input type="file" name="files">
<input type="text" name="fn" value="<?php echo $data["files"]; ?> " hidden="on">
<label for="status">Status:</label>
<select name="status" class="form-control">
<?php if($data["status"]=="public"){ ?>
<option value="public" selected>Public</option>
<option value="private">Private</option>
<?php }else{ ?>
<option value="public">Public</option>
<option value="private" selected>Private</option>
<?php } ?>
</select>
<input name="id" type="text" value="<?php echo $id;?>" hidden="on">
<input type="submit" value="Edit" class="form-control">
<?php }
}// end if
?>
</fieldset>
</form>
</div>
</div>
</div>
</div>
<hr>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</html>