This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
newproject.php
187 lines (177 loc) · 8.89 KB
/
newproject.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
<?php
if (!isset($_SESSION)) session_start();
include_once '_class/IdeaAbstractionManager.class.php';
// include '_pages/header.php';
?>
<head>
<title>New Project</title>
<style>
body{width:610px;}
.main-wrapper {border: 1px solid #a8d4b1;background-color: #c6f7d0;margin: 2px 0px;padding:40px;border-radius:4px;}
#users{float:left;list-style:none;margin-top:-3px;padding:0;width:190px;position: absolute;}
#users li{padding: 10px; background: #f0f0f0; border-bottom: #bbb9b9 1px solid;}
#users li:hover{background:#ece3d2;cursor: pointer;}
.textfield {padding: 10px;border: #a8d4b1 1px solid;border-radius:4px;}
</style>
<script src="_scripts/jquery-3.3.1.min.js"></script>
<script>
// AJAX call for autocomplete
$(document).ready(function(){
$("#topics").keyup(function(){
$.ajax({
type: "POST",
url: "_scripts/readtopics.php",
data:'keyword='+$(this).val(),
beforeSend: function(){
$("#topics").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
},
success: function(data){
$("#topic_suggestion_box").show();
$("#topic_suggestion_box").html(data);
$("#topics").css("background","#FFF");
}
});
});
$("#coauthors").keyup(function(){
$.ajax({
type: "POST",
url: "_scripts/readusers.php",
data:'keyword='+$(this).val(),
beforeSend: function(){
$("#coauthors").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
},
success: function(data){
$("#user_suggestion_box").show();
$("#user_suggestion_box").html(data);
$("#coauthors").css("background","#FFF");
}
});
});
});
//To select username
function selectTopic(val){
var user = $("#topics").val();
var n = user.lastIndexOf(';');
var t = user.substr(0, n);
if(val=='nouser') t ? $("#topics").val(t + ';') : $("#topics").val('');
else t ? $("#topics").val(t + ';' +val + ';') : $("#topics").val(val + ';');
$("#topic_suggestion_box").hide();
$("#topics").focus();
}
function selectUser(val){
var user = $("#coauthors").val();
var n = user.lastIndexOf(';');
var t = user.substr(0, n);
if(val=='nouser') t ? $("#coauthors").val(t + ';') : $("#coauthors").val('');
else t ? $("#coauthors").val(t + ';' +val + ';') : $("#coauthors").val(val + ';');
$("#user_suggestion_box").hide();
$("#coauthors").focus();
}
</script>
</head>
<?php
if(isset($_SESSION['repsyst_session_username'])){
//handling login error messages
if(isset($_GET['new'])){
$new = $_GET['new'];
switch ($new) {
case 'filesupload':
echo '<label class="success_message">Project added. ';
echo '<label class="error_message">Some files failed to upload</label><br/>';
break;
case 'projectadded':
echo '<label class="success_message">Project added successfully here. ';
echo '<a href="project.php?uid='.$_GET['id'].'>See project</a><br/>';
break;
}
unset($_GET);
}
if(isset($_POST['submit_addproject'])){
$title = ucfirst($_POST['title']);
$description = ucfirst($_POST['description']);
$postedby = $_SESSION['repsyst_session_username'];
$coauthors = $_POST['coauthors'];
$keywords = $_POST['keywords'];
$type = $_POST['type'];
$docs = ''; $uid = '';
$links = $_POST['links'];
$database = new PDO('mysql:host=localhost;dbname=srproj', 'root', '');
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
# Generating unique identifier
do $uid = strtoupper(substr(sha1($type.$title.uniqid()), -12));
while (IdeaAbstractionManager::uidExists($uid, $database));
# Check files upload
# TODO:(8) (Javascript) file uploading process
$success = true;
for($i = 0, $size = count($_FILES['uploads']['name']); $i < $size; $i++){
if($_FILES['uploads']['error'][$i] > 0) $success = false;
else{
$file_name = $_FILES['uploads']['name'][$i];
$file_temp_name = $_FILES['uploads']['tmp_name'][$i];
$file_extension = explode('.', $file_name);
$file_extension = strtolower(end($file_extension));
$allowed_file_extensions = array('pdf', 'doc', 'odt', 'odp', 'docx', 'ppt', 'pptx', 'ppsx', 'pps');
if(in_array($file_extension, $allowed_file_extensions)){
if($_FILES['uploads']['size'][$i] < 20971520) { //less than 20MB
$new_filename = '_uploads/_documents/'.$uid.'.'.$file_extension;
move_uploaded_file($file_temp_name, $new_filename);
$docs = $docs.';'.$new_filename;
}
else $success = false;
}
else $success = false;
}
}
#Building array to pass to constructor
$t_project = array('uid'=>$uid,
'title'=>$title,
'type'=>$type,
'description'=>$description,
'coauthors'=>$coauthors,
'postedby'=>$postedby,
'docs'=>$docs,
'links'=>$links,
'keywords'=>$keywords);
#Check type
$Constructor = str_replace(' ', '', $type);
$my_idea = new $Constructor($t_project);
$idea_manager = new IdeaAbstractionManager($database);
$idea_manager->add($my_idea);
#Returns error message if files could not be uploaded fully
if($success) header("Location: newproject.php?new=projectadded&uid=".$uid);
else header("Location: newproject.php?new=filesupload");
}
else{?>
<h1>Add new</h1>
<section class="main-container">
<div class="main-wrapper">
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data">
<table>
<tr><td>Title:</td><td><input type="text" name="title" placeholder="Title" class="textfield" required></td></tr>
<tr><td>Description:</td><td><textarea name="description" cols="30" rows="10" class="textfield" required></textarea></td></tr>
<!-- TODO: select tag to be empty onload -->
<tr><td>Type:</td><td><select name="type" placeholder="-Select Type-" class="textfield" required>
<!-- <option disabled selected hidden>-Select Type-</option> -->
<option value="Idea">Idea</option>
<option value="Project">Project</option>
<option value="Senior Project">Senior Project</option>
<option value="Research">Research</option>
</select></td></tr>
<!-- COMPLETED (AJAX - jQuery) function to shortlist authors usernames as you type -->
<tr><td>Co-Authors:</td><td><input type="text" name="coauthors" id="coauthors" class="textfield"placeholder="author1; author2; author3;...">
<div id="user_suggestion_box"></div></td></tr>
<tr><td>Links:</td><td><input type="text" class="textfield" name="links" placeholder="link1; link2; link3;..."></td></tr>
<!-- COMPLETED (AJAX - jQuery) function to shortlist topics as you type in -->
<tr><td>Topics:</td><td><input type="text" class="textfield" name="topics" id="topics" placeholder="keyword1; keyword2; keyword3;..." required>
<div id="topic_suggestion_box"></div></td></tr>
<!-- TODO:(8) (AJAX-Javascript) process files upload status -->
<tr><td>Files:</td><td><input name="uploads[]" type="file" multiple="multiple" accept=".odp, .pdf, .odt, .doc, .docx, .ppt, .pptx, .ppsx, .pps"/></td></tr>
<tr><td></td><td><button type="submit" name="submit_addproject">Add ></button></td></tr>
</table>
</form>
</div>
</section><?php
}
}
else header("Location: login.php");
?>