-
Notifications
You must be signed in to change notification settings - Fork 2
/
insertProjectDetails.php
156 lines (138 loc) · 6.23 KB
/
insertProjectDetails.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
<script src = 'http://code.jquery.com/jquery-1.11.0.min.js';></script>
<?php
session_start(); //starts the session
if ($_SESSION['email']) { //checks if name is logged in
} else {
header("location:index.php"); // redirects if name is not logged in
}
$email = $_SESSION['email'];
require 'dbconn.php';
require 'navbar.php';
if (isset($_POST['project_title']) and
isset($_POST['description']) and
isset($_POST['start_date']) and
isset($_POST['planned_completion_date']) and
isset($_POST['campaign_start_date']) and
isset($_POST['campaign_end_date']) and
isset($_POST['min_fund_req']) and
isset($_POST['max_fund_req'])
) {
$project_title = $_POST['project_title'];
$description = $_POST['description'];
$start_date = $_POST['start_date'];
$planned_completion_date = $_POST['planned_completion_date'];
if(trim($_FILES['photo']['tmp_name'])!=''){
if (getimagesize($_FILES['photo']['tmp_name']) == TRUE) {
$photo = addslashes($_FILES['photo']['tmp_name']);
$photo = file_get_contents($photo);
$photo = base64_encode($photo);
echo $photo;
}
}else{
$photo = '';
}
$video_name= $_FILES['video']['name'];
$video_tmp_name= $_FILES['video']['tmp_name'];
$position= strpos($video_name, ".");
$file_extension= substr($video_name, $position + 1);
$file_extension= strtolower($file_extension);
$success= -1;
if (isset($video_name)) {
$path= 'videos/';
if (!empty($video_name)){
if (($file_extension !== "mp4") and ($file_extension !== "ogg") and ($file_extension !== "webm"))
{
$success=0;
?>
<script>
alert("The video should be mp4, ogg, or webm format");
</script>
<?php
}else if (($file_extension == "mp4") or ($file_extension == "ogg") or ($file_extension == "webm")) {
if (move_uploaded_file($video_tmp_name, $path.$video_name)) {
$success=1;
}
}
}
}
$campaign_start_date = $_POST['campaign_start_date'];
$campaign_end_date = $_POST['campaign_end_date'];
$min_fund_req = $_POST['min_fund_req'];
$max_fund_req = $_POST['max_fund_req'];
if(trim($photo)!=''){
if(trim($video_name)!=''){
$sql_insert_project = "insert into PROJECT(PROJECT_TITLE, DESCRIPTION, DATE_TIME_CREATED, START_DATE, PLANNED_COMPLETION_DATE, PHOTO, VIDEO)
values('$project_title','$description',NOW(),'$start_date','$planned_completion_date','$photo','$video_name')";
}else{
$sql_insert_project = "insert into PROJECT(PROJECT_TITLE, DESCRIPTION, DATE_TIME_CREATED, START_DATE, PLANNED_COMPLETION_DATE, PHOTO, VIDEO)
values('$project_title','$description',NOW(),'$start_date','$planned_completion_date','$photo',NULL)";
}
}else{
if(trim($video_name)!=''){
$sql_insert_project = "insert into PROJECT(PROJECT_TITLE, DESCRIPTION, DATE_TIME_CREATED, START_DATE, PLANNED_COMPLETION_DATE, PHOTO, VIDEO)
values('$project_title','$description',NOW(),'$start_date','$planned_completion_date',NULL,'$video_name')";
}else{
$sql_insert_project = "insert into PROJECT(PROJECT_TITLE, DESCRIPTION, DATE_TIME_CREATED, START_DATE, PLANNED_COMPLETION_DATE, PHOTO, VIDEO)
values('$project_title','$description',NOW(),'$start_date','$planned_completion_date',NULL,NULL)";
}
}
echo $sql_insert_project;
if( ($min_fund_req < $max_fund_req) and ($campaign_start_date < $campaign_end_date) and ($campaign_end_date <= $start_date) and ($start_date < $planned_completion_date)){
if ($conn->query($sql_insert_project)=== TRUE){
$sql_rid = "select max(PROJECT_ID) as Project_id from PROJECT;";
$res = $conn->query($sql_rid);
$res = $res->fetch_assoc();
$new_project_id = $res['Project_id'];
$_SESSION['project_id'] = $new_project_id;
$sql_insert_project_campaign = "insert into PROJECT_CAMPAIGN(PROJECT_ID, FUND_START_DATE, FUND_END_DATE, MIN_FUND_GOAL, MAX_FUND_GOAL)
VALUES ('$new_project_id','$campaign_start_date','$campaign_end_date','$min_fund_req','$max_fund_req')";
echo $sql_insert_project_campaign;
if ($conn->query($sql_insert_project_campaign)=== TRUE){
$sql_insert_project_owner = "insert into project_ownership VALUES ('$new_project_id','$email')";
if($conn -> query($sql_insert_project_owner)){
?>
<script>
alert("Project Created!");
window.location.href = 'viewProject.php?project_id=<?php echo $new_project_id ?>';
</script>
<?php
}else{
$sql_delete_project_campaign = "delete from project_campaign where project_id = $new_project_id";
$conn->query($sql_delete_project_campaign);
$sql_delete_project = "delete from project where project_id = $new_project_id";
$conn->query($sql_delete_project);
?>
<script>
alert("There was some problem!");
window.location.href = 'createProject.php';
</script>
<?php
}
}else{
$sql_delete_project = "delete from project where project_id = $new_project_id";
$conn->query($sql_delete_project);
?>
<script>
alert("There was some problem!");
window.location.href = 'createProject.php';
</script>
<?php
}
}else{
?>
<script>
alert("There was some problem!");
window.location.href = 'createProject.php';
</script>
<?php
}
}else{
?>
<script>
alert("There was some problem!");
window.location.href = 'createProject.php';
</script>
<?php
}
}
?>