This repository has been archived by the owner on Oct 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·217 lines (184 loc) · 6.8 KB
/
index.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
$pageTitle = 'Home';
require_once('head_pre_output.php');
require_once('head_output.php');
require_once('classes/eq_group.class.php');
if ($IS_AUTHENTICATED) {
// SECTION: authenticated
?>
<script type="text/javascript">
$(document).ready(function () {
// default conditions
// ***************************
// Listeners
// ***************************
// Show ajax form
$("#btnDisplayAddEqGroup").click(function () {
$("#btnDisplayAddEqGroup").addClass('hide');
$("#eqGroupFields").removeClass('hide');
});
// custom form cleanup
$("#btnCancelAddEqGroup").click(function () {
cleanUpForm("frmAddGroup");
});
// ***************************
// Form validation
// ***************************
var validateAddGroup = $('#frmAddGroup').validate({
rules: {
groupName: {
minlength: 2,
required: true
},
groupDescription: {
minlength: 2,
required: false
},
groupReference: {
minlength: 2,
required: false
}
},
highlight: function (element) {
$(element).closest('.control-group').removeClass('success').addClass('error');
},
success: function (element) {
element
.text('OK!').addClass('valid')
.closest('.control-group').removeClass('error').addClass('success');
},
submitHandler: function (form) {
// show loading text (button)
$("#btnSubmitAddEqGroup").button('loading');
var formName = $("#frmAddGroup").attr('name'); // get name from the form element
var action = $('#' + formName + ' #ajaxGroupAction').val();
var group_name = $('#' + formName + ' #groupName').val();
var group_description = $('#' + formName + ' #groupDescription').val();
var group_reference = $('#' + formName + ' #groupReference').val();
// alert('formName=' + formName + '\n' + 'group_name=' + group_name + '\n' + 'group_description=' + group_description);
$.ajax({
type: 'GET',
url: $("#frmAddGroup").attr('action'),
data: {
ajaxVal_Action: action,
ajaxVal_Name: group_name,
ajaxVal_Description: group_description,
ajaxVal_Reference: group_reference
},
dataType: 'json',
success: function (data) {
// reset form
cleanUpForm("frmAddGroup");
if (data.status == 'success') {
// remove error messages
$('DIV.alert-error').remove();
// update the element with new data from the ajax call
$("UL#displayEqGroups").append(data.html_output);
}
else {
// show error message
$("UL#displayEqGroups").after('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button><h4>Failed: No action taken</h4> A record with that same name already exists in database.</div>');
}
}
});
}
});
// ***************************
// Custom functions
// ***************************
function cleanUpForm(formName) {
// reset form
$("#" + formName).trigger("reset");
validateAddGroup.resetForm();
// hide form, show button to activate form
$("#eqGroupFields").addClass('hide');
$("#btnDisplayAddEqGroup").removeClass('hide');
// manually remove input highlights
$(".control-group").removeClass('success').removeClass('error');
// reset button
$("#btnSubmitAddEqGroup").button('reset');
}
})
</script>
<?php
echo "<hr />";
echo "<h3>Your Equipment Groups</h3>";
echo "<ul class=\"unstyled\" id=\"displayEqGroups\">";
# is system admin?
if ($USER->flag_is_system_admin) {
# get groups for this ordinary user
$UserEqGroups = EqGroup::getAllEqGroupsForAdminUser($USER);
if (count($UserEqGroups) > 0) {
foreach ($UserEqGroups as $ueg) {
echo "<li><a href=\"equipment_group.php?eid=" . $ueg->eq_group_id . "\" title=\"\">" . $ueg->name . "</a></li>";
}
}
else {
echo "<li>You do not belong to any equipment groups.</li>";
}
echo "</ul>";
# system admin may add new eq_groups
?>
<form action="ajax_actions/ajax_eq_group.php" id="frmAddGroup" class="form-horizontal" name="frmAddGroup" method="post">
<button type="button" id="btnDisplayAddEqGroup" class="btn btn-primary" name="btnDisplayAddEqGroup">Add a new equipment group
</button>
<div id="eqGroupFields" class="hide">
<legend>Add a new equipment group</legend>
<div class="control-group">
<label class="control-label" for="groupName">Name</label>
<div class="controls">
<input type="hidden" id="ajaxGroupAction" name="ajaxGroupAction" value="add-group" />
<input type="text" id="groupName" class="input-large" name="groupName" value="" placeholder="Name of group" maxlength="200" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="groupDescription">Description</label>
<div class="controls">
<input type="text" id="groupDescription" class="input-xlarge" name="groupDescription" value="" placeholder="Description of group" maxlength="200" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="groupReference">Reference Link</label>
<div class="controls">
<input type="url" id="groupReference" class="input-xlarge" name="groupReference" value="" placeholder="Reference Link" maxlength="200" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="btnSubmitAddEqGroup"></label>
<div class="controls">
<button type="submit" id="btnSubmitAddEqGroup" class="btn btn-success" data-loading-text="Saving...">Add Group</button>
<button type="reset" id="btnCancelAddEqGroup" class="btn btn-link btn-cancel">Cancel</button>
</div>
</div>
</div>
</form>
<?php
}
else {
# get groups for this ordinary user
$UserEqGroups = EqGroup::getAllEqGroupsForNonAdminUser($USER);
if (count($UserEqGroups) > 0) {
foreach ($UserEqGroups as $ueg) {
echo $ueg->toListItemLinkedNoDesc();
}
}
else {
echo "<li>You do not have access to any equipment groups.</li>";
}
echo "</ul>";
}
}
else {
// SECTION: not yet authenticated, wants to log in
?>
<div class="hero-unit">
<h2><?php echo LANG_INSTITUTION_NAME; ?></h2>
<h1><?php echo LANG_APP_NAME; ?></h1>
<br />
<p>This is our system for scheduling equipment reservations.</p>
<p>To sign in, please use your <?php echo LANG_INSTITUTION_NAME; ?> username and password.</p>
</div>
<?php
}
require_once('foot.php');
?>