-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
127 lines (86 loc) · 3 KB
/
Copy pathindex.php
File metadata and controls
127 lines (86 loc) · 3 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
<?php
include "setup/db.php";
$action = isset($_GET['action']) ? $_GET['action'] : "";
switch($action) {
case 'setup':
setup();
break;
case 'add':
addProject();
break;
case 'edit':
editProject();
break;
case 'delete':
deleteProject();
break;
default:
listProjects();
}
function indexHome() {
if (PP_SETUP == false) {
header("Location: index.php?action=setup");
}
$pageTitle = "Home";
require_once "library/home.php";
}
function listProjects() {
$pageTitle = "Home";
require_once "library/home.php";
}
function addProject() {
$pageTitle = "Add New Project";
if (isset($_POST['operation'])) {
try {
$db_conn = db_connect();
$query = "ALTER TABLE projects AUTO_INCREMENT = 1;";
$result = $db_conn->query($query);
$stmt = $db_conn->prepare('INSERT INTO projects (project_name) VALUES (:project_name)');
$stmt->bindValue(":project_name", $_POST['project_name']);
$stmt->execute();
$alert = "alert-success";
$message = "New project successfully added!";
$pageTitle = "Projects";
require_once "library/home.php";
} catch (PDOException $e) {
$alert = "";
$message = "Project couldn't be added, please try again.";
$pageTitle = "Add New Project";
require_once "library/add.php";
}
} else {
require_once "library/add.php";
}
}
function editProject() {
$pageTitle = "Edit Existing Project";
$pid = isset($_GET['pid']) ? $_GET['pid'] : "";
if (isset($_POST['operation'])) {
try {
$db_conn = db_connect();
$stmt = $db_conn->prepare('UPDATE projects SET project_name = :project_name WHERE project_ID = :project_ID');
$stmt->bindValue(":project_name", $_POST['project_name']);
$stmt->bindParam(":project_ID", $pid);
$stmt->execute();
$alert = "alert-success";
$message = "Project successfully edited.";
$pageTitle = "Projects";
require_once "library/home.php";
} catch (PDOException $e) {
$alert = "";
$message = "Project couldn't be edited, please try again.";
require_once "library/edit.php";
}
} else {
require_once "library/edit.php";
}
}
function deleteProject() {
$pageTitle = "Delete Existing Project";
$alert = "Project deleted.";
}
function setup() {
$pageTitle = "Database Setup";
require_once "setup/index.php";
}
?>