-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup.php
More file actions
157 lines (121 loc) · 3.94 KB
/
group.php
File metadata and controls
157 lines (121 loc) · 3.94 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
session_start();
if (isset($_SESSION['userId'])) {
$userId = $_SESSION['userId'];
} else {
header("Location: http://sorubank.ege.edu.tr/~b051164/dersler/lwp/proje/login.php");
die();
}
include "baglan.php";
if($_POST['action'] == "createGroup") {
$isUpdate = false;
} else if($_POST['action'] == "updateGroup") {
$isUpdate = true;
$groupId = $_POST['groupId'];
$group_query = mysql_query("SELECT GroupId, Name, PictureURL, AdminId
FROM GROUPINFO
WHERE GroupId = $groupId");
$group_info = mysql_fetch_array($group_query);
$groupName = $group_info['Name'];
} else {
@include_once "koruma.php";
if ((isset($_POST)) && (isset($_POST['submit']))) {
$submit = secure_var($_POST["submit"]);
} else {
$submit = false;
}
if ($submit) {
$error = array();
$groupName = test_input($_POST["groupName"]);
$isUpdate = $_POST["isUpdate"];
$groupId = $_POST['groupId'];
if (empty($groupName)) {
$error['groupName'] = "Please enter your name";
}
if ($_FILES["file"]["name"] != "") {
$allowedExts = array("jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 1000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
$error['pictureURL'] = "Invalid file";
}
else
{
if (file_exists("img/group/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
$new_filename = $userId . "_" . date("Ymd") . "_" . date("hisa");
$full_local_path = 'img/group/' . $new_filename . "." . $extension ;
$pictureURL = "http://sorubank.ege.edu.tr/~b051164/dersler/lwp/proje/" . $full_local_path;
move_uploaded_file($_FILES["file"]["tmp_name"], $full_local_path);
}
}
}
else
{
$error['pictureURL'] = "Invalid file";
}
}
if (count($error) == 0) {
if ($isUpdate) {
mysql_query("UPDATE GROUPINFO SET Name = '$groupName', PictureURL = '$pictureURL'
WHERE GroupId = $groupId ");
echo mysql_error();
} else {
mysql_query("INSERT INTO GROUPINFO (Name, AdminId, PictureURL)
VALUES ('$groupName', $userId, '$pictureURL')");
$groupId_query = mysql_query("SELECT GroupId FROM GROUPINFO
ORDER BY GroupId DESC LIMIT 1");
$groupId = mysql_fetch_array($groupId_query);
mysql_query("INSERT INTO USERGROUP (UserId, GroupId)
VALUES ($userId, " . $groupId['GroupId'] . ")");
}
mysql_close();
header("Location: http://sorubank.ege.edu.tr/~b051164/dersler/lwp/proje/main.php");
die();
}
}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<form class="form" id="group_form" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" enctype="multipart/form-data">
Group Name:
<input type="text" name="groupName" value="<?php echo $groupName; ?>">
<span class="error">* <?php echo $error['groupName'];?> </span>
<br>
<span class="error"><?php echo $error['pictureURL'];?> </span><br>
<label for="file">Set group picture:</label>
<input type="file" name="file" id="file"><br>
<input type="hidden" name="pictureURL" value="<?php echo $picture; ?>">
<input type="hidden" name="isUpdate" value="<?php echo $isUpdate; ?>">
<input type="hidden" name="groupId" value="<?php echo $groupId; ?>">
<input class="submit" type="submit" name="submit" value="Save Changes">
</form>
</body>
</html>