-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateform.php
217 lines (207 loc) · 6.83 KB
/
createform.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
217
<?php
###############################################################################
# $Id$
# UI to create.php
###############################################################################
require_once dirname(__FILE__).'/common.php';
$isUpdate = isset($_GET["staffid"]);
if ($isUpdate) {
$fields = array("first", "middle", "last", "display_name", "year", "gender",
"email", "dept", "position", "begin_date", "end_date", "athena_username",
"birthday", "phone", "gchat");
$sql = "SELECT " . join(", ", $fields) . " FROM staff WHERE staffid = ";
$sql .= $mdb2->quote($_GET["staffid"]) . " AND active = 'yes'";
$mdb2->setLimit(1);
$res =& $mdb2->query($sql);
if(PEAR::isError($res)) {
error_log($res->getDebugInfo());
fatal("Could not get information for $email: ".$res->getMessage());
}
foreach ($fields as $field) {
$res->bindColumn($field, $$field);
}
$row = $res->fetchRow();
$phone = formatPhone($phone);
if($birthday == '0000-00-00') { $birthday = ''; }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php if ($isUpdate) { ?>
<title>The Tech Staff Modification Page</title>
<?php } else { ?>
<title>The Tech Staff Addition Page</title>
<?php } ?>
<style type="text/css">
td { padding:2px;text-align:center }
</style>
</head>
<body style='margin:15px auto;padding:5px 20px;width:860px;'>
<h1 align="center">The Tech</h1>
<?php if ($isUpdate) { ?>
<h2 align="center">Staff Modification Page</h2>
<?php } else { ?>
<h2 align="center">Staff Addition Page</h2>
<?php } ?>
<form method="post" action="./create.php">
<table width="50%" border="0" align="center">
<tr>
<td>
<input onkeyup="updateDisplayName()" type="text" size="15" maxlength="20" name="first" value="<?=$first?>">
</td>
<td>
<input onkeyup="updateDisplayName()" type="text" size="15" maxlength="20" name="middle" value="<?=$middle?>">
</td>
<td>
<input onkeyup="updateDisplayName()" type="text" size="15" maxlength="30" name="last" value="<?=$last?>">
</td>
</tr>
<tr>
<td>First Name</td>
<td>Middle Name</td>
<td>Last Name</td>
</tr>
<tr>
<td colspan="1">Display Name</td>
<td colspan="2">
<input onchange="flagDisplayNameChanged()" type="text" size="30" maxlength="50" name="display_name" value="<?=$display_name?>">
</td>
</tr>
<tr>
<td>
<input onkeyup="updateAthenaUsername()" type="text" size="15" maxlength="50" name="email" value="<?=$email?>">
</td>
<td>
<input type="text" size="15" maxlength="30" name="gchat" value="<?=$gchat?>">
</td>
<td>
<input type="text" size="4" maxlength="4" name="year" value="<?=$year?>">
</td>
<td>
Male <input type="radio" value="Male" name="gender"<?=$gender=="male"?" checked":""?>><br/>
Female <input type="radio" value="Female" name="gender"<?=$gender=="female"?" checked":""?>><br />
Other <input type="radio" value="Other" name="gender" <?=$gender=="other"?" checked":""?>>
</td>
</tr>
<tr>
<td>E-Mail Address</td>
<td>gchat</td>
<td>Class Year (YYYY)
<font size="1"><br />0 for Grad
<br />9998 for CME
<br />9999 for no year</font></td>
<td></td>
</tr>
<tr>
<td>
<select onchange="updateTitles()" name="dept">
<option<?=isset($dept)?"":" selected "?>></option>
<?php foreach (getDepartments() as $department) { ?>
<option value="<?=$department?>"<?=($dept==$department)?" selected":""?>><?=$department?></option>
<?php } ?>
</select>
</td>
<td>
<select name="position">
<?php if(isset($dept)) { foreach (getDepartmentTitles($dept) as $title) { ?>
<option value="<?=$title?>"<?=($position==$title)?" selected":""?>><?=$title?></option>
<?php } } else { ?>
<!-- This will be filled in with JavaScript -->
<option></option>
<?php } ?>
</select>
</td>
<td>
<input type="text" name="begin_date" size="10" maxlength="10" value="<?=date("Y-m-d")?>">
</td>
</tr>
<tr>
<td>Department</td>
<td>Job Title </td>
<td>Effective Date<br><font size=1>(YYYY-MM-DD)</font></td>
</tr>
<tr>
<td>
<input type="text" name="birthday" size="10" maxlength="10" value="<?=$birthday?>">
</td>
<td>
<input type="text" size="15" maxlength="20" name="phone" value="<?=$phone?>">
</td>
<td>
<input onchange="flagAthenaUserChanged()" type="text" size="15" maxlength="20" name="athena_username" value="<?=$athena_username?>">
</td>
</tr>
<tr>
<td> Birthday<br><font size=1>(YYYY-MM-DD)</font></td>
<td> Phone Number<br><font size=1>(XXX-XXX-XXXX)</font></td>
<td> Athena Username</td>
</tr>
</table>
<?php if ($isUpdate) { ?>
<input type="hidden" name="staffid" value="<?=$_GET["staffid"]?>">
<?php } ?>
<p align="center">
<input style="margin-right:10%" type="reset" value="Reset">
<input type="submit" value="Submit" name="submit">
<input style="margin-left:10%" type="submit" value="Deactive me!" name="delete">
</p>
<br>
</form>
<form method="get" action="./">
<input style="width:50%;margin-left:25%;margin-right:25%" type="submit" value="Cancel">
</form>
</body>
<script type="text/javascript" language="javascript">
var displayNameModified = false;
var athenaUserModified = false;
function updateDisplayName() {
if(!displayNameModified) {
var first = document.getElementsByName("first")[0].value;
var middle= document.getElementsByName("middle")[0].value;
var last = document.getElementsByName("last")[0].value;
var name = first + " ";
if(middle.length != 0) {
name += middle.charAt(0) + ". ";
}
name += last;
document.getElementsByName("display_name")[0].value = name;
}
return true;
}
function flagDisplayNameChanged() {
displayNameModified = true;
}
function updateAthenaUsername() {
if(!athenaUserModified) {
var email = document.getElementsByName("email")[0].value;
var i = email.indexOf("@mit.edu",1);
if(i != 0) {
document.getElementsByName("athena_username")[0].value = email.substring(0,i);
}
}
return true;
}
function flagAthenaUserChanged() {
athenaUserModified = true;
}
function updateTitles() {
var url = "./json.php?0=getDepartmentTitles&1=";
url += document.getElementsByName("dept")[0].value;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else { // IE6 and IE 5
alert("Get rid of your stanky old shit. http://www.getfirefox.com/");
return false;
}
xmlhttp.open("GET",url,false);
xmlhttp.send(null);
var titles = JSON.parse(xmlhttp.responseText);
var html = "";
for (t in titles) {
html += "<option value='" + titles[t] + "'>" + titles[t] + "</option>\n";
}
document.getElementsByName("position")[0].innerHTML = html;
}
</script>
</html>