-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewScreenings.php
executable file
·170 lines (155 loc) · 7.47 KB
/
viewScreenings.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
<?php
/*
* Copyright 2013 by Jerrick Hoang, Ivy Xing, Sam Roberts, James Cook,
* Johnny Coster, Judy Yang, Jackson Moniaga, Oliver Radwan,
* Maxwell Palmer, Nolan McNair, Taylor Talmage, and Allen Tucker.
* This program is part of RMH Homebase, which is free software. It comes with
* absolutely no warranty. You can redistribute and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation
* (see <http://www.gnu.org/licenses/ for more information).
*
*/
/*
* Created on April 1, 2012
* @author Jackson Moniaga <[email protected]>
*/
session_start();
session_cache_expire(30);
include_once('database/dbApplicantScreenings.php');
include_once('domain/ApplicantScreening.php');
include_once('database/dbLog.php');
$type = $_GET["type"];
$screening = retrieve_dbApplicantScreenings($type);
if (!$screening) {
// nothing there for this type, so construct a new one with no steps
$screening = new ApplicantScreening("new", $_SESSION['_id'], "", "unpublished");
// and insert it into the database
insert_dbApplicantScreenings($screening);
}
?>
<html>
<head>
<title> Edit Applicant Screenings</title>
<!-- Choose a style sheet -->
<link rel="stylesheet" href="styles.css" type="text/css"/>
</head>
<body>
<div id="container">
<?php include("header.php"); ?>
<div id="content">
<?php
if ($_POST['_form_submit'] == 0) {
$action = "select";
echo('<p><b>Select a Screening: </b>');
include("viewScreenings.inc.php");
} else if ($_POST['s_type'] == "new") {
$action = $_POST['s_type'];
echo('<p><b>Create new Screening: </b>');
$new = true;
include('viewScreenings.inc.php');
} else if ($_POST['_form_submit'] == 1) {
$action = $_POST['s_type'];
echo('<p><b>Edit Screening: </b>' . $action);
include('viewScreenings.inc.php');
} else { // changes submitted, so process them and display the result
process_form($screening);
}
/**
* process_form gathers data and enters it into a database
*/
function process_form($oldScreening) {
//step one: gather data.
$oldType = $_POST['_old_type'];
if ($_POST['_form_type'] == "new")
$creator = $_SESSION['_id'];
else
$creator = $oldScreening->get_creator();
$steps = array();
// reset steps array
if (isset($_POST['steps']))
foreach ($_POST['steps'] as $step)
$steps[] = $step;
else
$steps = $oldScreening->get_steps();
$type = $_POST['new_type'];
foreach ($steps as $key => $value)
if (empty($value))
unset($steps[$key]);
$steps = implode(',', $steps);
// set published variable
if ($_POST['Status'] == "published")
$newstatus = "published";
else
$newstatus = "unpublished";
$status = $newstatus;
if (empty($type)) {
$type = $oldType;
// keeps "new" screening free from predefined steps and status
if ($type == "new") {
$steps = null;
$status = "unpublished";
}
}
//used to put together url for return to screenings link
$path = strrev(substr(strrev($_SERVER['SCRIPT_NAME']), strpos(strrev($_SERVER['SCRIPT_NAME']), '/')));
//step two: try to delete, add new, or replace
if ($_POST['deleteMe'] == "DELETE") {
$result = retrieve_dbApplicantScreenings($type);
if (!$result) {
echo('<p>Unable to delete. ' . $type . ' is not in the screenings database. To delete ' . $oldType . ',
try to delete again but do not rename screening type.');
} else {
$result = delete_dbApplicantScreenings($type);
echo("<p>You have successfully removed " . $type . " from the screnings database.</p>");
echo('<p><a href="' . $path . 'viewScreenings.php?type=' . $type . '"><b>click here</b> to
return to applicant screenings.</a><br><br></p>');
add_log_entry('ApplicantScreening type <a href=\"viewScreenings.php?type=' . $type . '\">' . $type . '</a>\'
has been deleted.');
}
} else if ($_POST['_form_type'] == "new") {
if ($_POST['$type_s'])
$dup = retrieve_dbApplicantScreenings($type);
if ($dup)
echo('<p class="error">Unable to add new screening type: ' . $type . ' to the screenings database. <br>
Another screening with the same type is already there.');
else {
$screening = new ApplicantScreening($type, $creator, $steps, $status);
$result = insert_dbApplicantScreenings($screening);
if (!$result)
echo ('<p class="error">Unable to add ' . $type . ' in the screenings database. <br>
Please report this error to the House Manager.');
else
echo("<p>You have successfully added '$type' to the screenings database.</p>");
echo('<p>click <a href="' . $path . 'viewScreenings.php?type=' . $type . '">here</a> to
return to applicant screenings.<br><br></p>');
add_log_entry('ApplicantScreening process <a href=\"viewScreenings.php?type=' . $type . '\">' . $type . '</a>\'
has been added.');
}
}
else {
$result = delete_dbApplicantScreenings($oldType);
if (!$result)
echo ('<p class="error">Unable to update ' . $oldType . ' as ' . $type);
else {
$newscreening = new ApplicantScreening($type, $creator, $steps, $status);
$result = insert_dbApplicantScreenings($newscreening);
if (!$result)
echo ('<p class="error">Unable to update ' . $type . ' in the screenings database. <br>
Please report this error to the House Manager.');
else
echo('<p>You have successfully edited "' . $type . '" in the screenings database.</p>');
echo('<p><a href="' . $path . 'viewScreenings.php?type=' . $type . '"><b>click here</b> to
return to applicant screenings.</a><br><br></p>');
add_log_entry('ApplicantScreening process <a href=\"viewScreenings.php?type=' . $type . '\">' . $type . '</a>\'
has been changed.');
}
}
//if (retrieve_dbApplicantScreenings("new")!= null)
// delete_dbApplicantScreenings("new");
}
?>
</div>
<?php include('footer.inc');?>
</div>
</body>
</html>