/
userWorkingExampleManagement.php
216 lines (171 loc) · 6.99 KB
/
userWorkingExampleManagement.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
require("includes/mysql_database_connection.php");
require("includes/projects_management_function.php");
require("includes/profile_management_function.php");
require("includes/session.php");
require("includes/util.php");
redirectToHTTPS();
if (isset($_SESSION['username'])) {
$username = $_SESSION['username'];
$userProfilePicturePath = getProfilePicturePathByUsername($username);
$projectArray = getProjectsListByUsername($username);
$isUserAdminValue = isUserAdmin($username);
if (isset($_POST['projectUploadSubmit'])) {
$projectTitle = ($_POST['projectTitle']);
$description = ($_POST['projectDescription']);
if(getProjectDetailsByUsernameAndTitle($username,$projectTitle) == null){
$uploadedFileName = $_FILES["projectFile"]["name"];
$fileExt = end(explode(".", $uploadedFileName));
if ( isset($fileExt) && ( $fileExt == "rar" || $fileExt == "zip" ) ) {
if ($_FILES["projectFile"]["error"] > 0) {
$error = "Return Code: " . $_FILES["projectFile"]["error"] . "<br />";
} else {
$fileName = $projectTitle.".". $fileExt;
$directoryPath = "user_projects/" .$username ;
$finalFilePath = $directoryPath."/". $fileName;
if(! file_exists($directoryPath)){
mkdir($directoryPath, 0777 , true);
}
move_uploaded_file($_FILES["projectFile"]["tmp_name"], $finalFilePath);
manageProject($username, $finalFilePath, $description ,$projectTitle);
$projectArray = getProjectsListByUsername($username);
}
} else {
$error = "Only .rar and .zip file types are allowed";
}
}else {
$error = "A file with the same project title already exists. Try different project title";
}
} else {
$description = "";
}
if(isset($_GET['filePathToDelete'])){
$filePathToDelete = $_GET['filePathToDelete'];
unlink($filePathToDelete);
deleteProject($filePathToDelete);
redirect_to("../userProject");
}
} else {
redirect_to("home");
}
?>
<script type="text/javascript" language="javascript" src="js/userProject.js"></script>
<script type="text/javascript" language="javascript">
function resetAdminArea(){
<?php
if (isset($_SESSION['selectedUsername'])) {
unset($_SESSION['selectedUsername']);
}
?>
}
</script>
<head>
<title>Be Linked! User project management</title>
<link rel="stylesheet" href="css/layout.css" type="text/css">
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body >
<table width="100%" >
<tr>
<td width="100%" >
<div class="headerImage"><?php require_once("headerImage.php"); ?> </div>
</td>
</tr>
<tr>
<td width="100%" >
<div class="siteMenu"><?php require_once("siteMenu.php"); ?> </div>
</td>
</tr>
<tr>
<td width="100%" >
<div class="myAccount">
<table id="myAccountNavigationTable" border="0" cellpadding="3" class="fontOnly">
<tr>
<td><img width="120" height="120" src="<?php echo $userProfilePicturePath ?>" /></td>
</tr>
<tr>
<td><a href="userProfile" class="search"><u>Manage Profile</u></a><br></td>
</tr>
<tr>
<td><a href="userCV" class="search"><u>Manage CV</u></a> </td>
</tr>
<tr>
<td><a href="userProject" class="search"><u>Manage Project</u></a></td>
</tr>
<tr>
<td><?php if ($isUserAdminValue) { ?>
<a href="adminPanel" class="search"><u>Admin Panel</u></a> <br>
<?php } ?></td>
</tr>
</table>
<table id="formTable" border="0" class="fontOnly">
<tr>
<td>
</td>
<td>
<form name="projectUploadForm" id="projectUploadForm" action="userProject" method="post" onsubmit="return validateForm()" enctype="multipart/form-data">
<table border="0" cellpadding="5" class="fontOnly">
<tr>
<td><label for="projectTitle">Project Title </label>
<input type="text" name="projectTitle" id="projectTitle" maxlength="100" value="<?php if(isset($projectTitle)){echo htmlentities($projectTitle);} ?>" onChange="this.value=this.value.trim()" onKeyUp="clearMsg()" onBlur="isProjectTitleValid(this.value)" size="52"/>
</td>
<td><div id="projectTitleMsg" ></div></td>
</tr>
<tr>
<td><label for="projectDescription">Description </label><br><textarea rows="3" cols="50" name="projectDescription" maxlength="250" id="projectDescription" onChange="this.value=this.value.trim()" onKeyUp="clearMsg()" onBlur="isProjectDescriptionValid(this.value)" ><?php echo $description ?></textarea></td>
<td><div id="projectDescriptionMsg"></div></td>
</tr>
<tr>
<td><label for="projectFile">File name </label><input type="file" name="projectFile" id="projectFile" size="30" /></td>
</tr>
<tr>
<td><input type="submit" value="Upload Project" name="projectUploadSubmit" ></td>
</tr>
</table>
<?php if (isset($_POST['projectUploadSubmit']) && isset($error)) { ?>
<div id="projectUploadMsg"><font color=red><?php echo $error ?></font></div>
<?php } ?><br/>
<table id="projectsTable" border="1" class="fontOnly" style='table-layout:fixed' width="100%" >
<col width=25%>
<col width=35%>
<col width=20%>
<col width=20%>
<?php
if(count($projectArray) > 0){
foreach($projectArray as $project){ ?>
<tr>
<td>
<b><?php echo $project["project_file_title"]; ?></b>
</td>
<td width="35%" >
<div style="overflow:scroll"> <?php echo htmlentities($project["project_description"]); ?> </div>
</td>
<td>
<a href="<?php echo $project["project_file_path"] ?>" class="search" target="_blank"><u>Download Project</u></a>
</td>
<td>
<a href="userProjects-<?php echo $project["project_file_path"] ; ?>" class="search" onclick="return ConfirmDelete();" ><u>Remove Project</u></a>
</td>
</tr>
<?php } ?>
<?php }else{ ?>
No projects have been uploaded yet.
<?php } ?>
</table>
</form></br>
</td>
</tr>
<tr>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>
<?php
if(isset($connection)){
mysql_close($connection);
}
?>