forked from csc325/GCal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
categoryAdmin2.php
217 lines (190 loc) · 8.27 KB
/
categoryAdmin2.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
require_once 'global.php';
require_once 'header.php';
/*
* categoryAdmin2.php: Current version of category/location management
* PHP version 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category Administrator Functions
* @author CSC-325 Database and Web Application Fall 2010 Class
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version 3.0
*/
/*Require html header, global variables and all functions*/
require_once 'global.php';
require_once 'header.php';
?>
<!-- Permanent Categories/Locations Table -->
<div class="body" >
<div class="col large">
<?php
$admintype = $_GET['admintype'];
if(($admintype == 1) || (!isset($admintype))){
$name = "Category";
$table = "categories";
$field1 = "categories.categoryID";
$field2 = "categories.categoryName";
$field3 = "events.categoryID";
$permanent = "categories.permanent";
$nm1 = "categoryID";
$nm2 = "categoryName";
}
if($admintype == 2) {
$name = "Location";
$table = "locations";
$field1 = "locations.locationID";
$field2 = "locations.locationName";
$field3 = "events.locationID";
$permanent = "locations.permanent";
$nm1 = "locationID";
$nm2 = "locationName";
}
echo "<form name='downgrade' action='updowngrade.php?admintype=$admintype' method='post'>
<table>
<tr>
<th class='catcol'>";
echo $name;
echo "</th>
<th>Requests</th>
<th>Downgrade</th>
<th>Rename</th>
</tr>";
$queryPerm = "SELECT $field1, $field2,
COUNT(*) 'requestCount'
FROM $table, events
WHERE $permanent = 1
AND $field1 = $field3
GROUP BY $field1
ORDER BY requestCount DESC;";
$resultPerm = mysql_query($queryPerm);
$queryTemp = "SELECT $field1, $field2,
COUNT(*) 'requestCount'
FROM $table, events
WHERE $permanent = 0
AND $field1 = $field3
GROUP BY $field1
ORDER BY requestCount DESC;";
$resultTemp = mysql_query($queryTemp);
$categoryNames = array();
$categoryRequests = array();
while ($row = mysql_fetch_assoc($resultPerm)) {
$categoryNames[$row[$nm1]] =
$row[$nm2];
$categoryRequests[$row[$nm1]] =
$row['requestCount'];
}
foreach($categoryNames as $id => $name) :
echo "<tr>
<td> $name </td>
<td align='center'>
$categoryRequests[$id] </td>
<td align='center'><input type='checkbox'
name='$id'
value='downgrade'
class='updowngrade_box'></td>
<td align='center'><input type='checkbox'
id='$id'
value='rename'></td>
</tr>";
endforeach;
echo "</table>
</form>";
//Temporary Categories Table
echo "<form name='upgrade' action='updowngrade.php' method='post'>
<table>
<tr>
<th class='catcol'>";
if($_GET['admintype'] == 1) echo "Category";
if($_GET['admintype'] == 2) echo "Location";
echo "</th><th>Requests</th>
<th>Upgrade</th>
<th>Rename</th>
</tr>";
while ($row = mysql_fetch_assoc($resultTemp)) {
$tempCategoryNames[$row[$nm1]] =
$row[$nm2];
$tempCategoryRequests[$row[$nm1]] =
$row['requestCount'];
}
foreach($tempCategoryNames as $id => $name) :
echo "<tr>
<td> $name </td>
<td align='center'>
{$tempCategoryRequests[$id]} </td>
<td align='center'><input type='checkbox'
name='$id'
value='upgrade'
class='updowngrade_box'></td>
<td align='center'><input type='checkbox'
id='$id'
value='rename'></td>
</tr>";
endforeach; ?>
</table>
</form>
<button type='button' id='update'>Update</button>
<script type="text/javascript">
//function that adds input field if input for location/category
drop down menu is other
$(document).ready(function(){
$("input[value='rename']").change ( function () {
var catID = $(this).attr('id');
if( this.checked ) {
$(this).parent().parent().append('<td id = "rename_' +
catID + '" > <input type="text" name="' + catID + '"
class="rename_field"></td>\n');
} else {
$('#rename_' + catID).remove();
}
});
$("#update").click ( function() {
var updowngrades_str = '';
$('input.updowngrade_box').each ( function () {
if ( this.checked ) {
var catID = $(this).attr('name');
var value = $(this).val();
updowngrades_str = updowngrades_str + catID + '=' +
value + '&';
}
});
var renames_str = '';
$('input.rename_field').each ( function () {
var catID = $(this).attr('name');
var value = $(this).val();
renames_str = renames_str + catID + '=' + value + '&';
});
var success = 0;
$.ajax({
type:"post",
url:"updowngrade.php",
data: updowngrades_str,
success: function (r) {
if (r == 1) {
window.location = window.location.href;
}
}
});
$.ajax({
type:"post",
url:"rename.php?admintype=<?php $_GET['admintype']; ?>",
data: renames_str,
success: function (r) {
if (r == 1) {
window.location = window.location.href;
}
}
});
});
});
-->
</script>
</div>
<?php include 'sidebar.php'; ?>
</div>
<?php include 'footer.php'; ?>