forked from jwigal/churchinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptionManager.php
400 lines (345 loc) · 10.6 KB
/
OptionManager.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<?php
/*******************************************************************************
*
* filename : OptionsManager.php
* last change : 2003-04-16
* website : http://www.infocentral.org
* copyright : Copyright 2003 Chris Gebhardt
*
* OptionName : Interface for editing simple selection options such as those
* : used for Family Roles, Classifications, and Group Types
*
* InfoCentral is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
******************************************************************************/
//Include the function library
require "Include/Config.php";
require "Include/Functions.php";
$mode = trim($_GET["mode"]);
// Check security for the mode selected.
switch ($mode) {
case famroles:
case classes:
if (!$_SESSION['bMenuOptions'])
{
Redirect("Menu.php");
exit;
}
break;
case grptypes:
case grproles:
case groupcustom:
if (!$_SESSION['bManageGroups'])
{
Redirect("Menu.php");
exit;
}
break;
case custom:
case famcustom:
case securitygrp:
if (!$_SESSION['bAdmin'])
{
Redirect("Menu.php");
exit;
}
break;
default:
Redirect("Menu.php");
break;
}
// Select the proper settings for the editor mode
switch ($mode) {
case famroles:
$adj = gettext("Family");
$noun = gettext("Role");
$listID = 2;
$embedded = false;
break;
case classes:
$adj = gettext("Person");
$noun = gettext("Classification");
$listID = 1;
$embedded = false;
break;
case grptypes:
$adj = gettext("Group");
$noun = gettext("Type");
$listID = 3;
$embedded = false;
break;
case securitygrp:
$adj = gettext("Security");
$noun = gettext("Group");
$listID = 5;
$embedded = false;
break;
case grproles:
$adj = gettext("Group Member");
$noun = gettext("Role");
$listID = FilterInput($_GET["ListID"],'int');
$embedded = true;
$sSQL = "SELECT grp_DefaultRole FROM group_grp WHERE grp_RoleListID = " . $listID;
$rsTemp = RunQuery($sSQL);
// Validate that this list ID is really for a group roles list. (for security)
if (mysql_num_rows($rsTemp) == 0) {
Redirect("Menu.php");
break;
}
$aTemp = mysql_fetch_array($rsTemp);
$iDefaultRole = $aTemp[0];
break;
case custom:
$adj = gettext("Person Custom List");
$noun = gettext("Option");
$listID = FilterInput($_GET["ListID"],'int');
$embedded = true;
$sSQL = "SELECT '' FROM person_custom_master WHERE type_ID = 12 AND custom_Special = " . $listID;
$rsTemp = RunQuery($sSQL);
// Validate that this is a valid person-custom field custom list
if (mysql_num_rows($rsTemp) == 0) {
Redirect("Menu.php");
break;
}
break;
case groupcustom:
$adj = gettext("Custom List");
$noun = gettext("Option");
$listID = FilterInput($_GET["ListID"],'int');
$embedded = true;
$sSQL = "SELECT '' FROM groupprop_master WHERE type_ID = 12 AND prop_Special = " . $listID;
$rsTemp = RunQuery($sSQL);
// Validate that this is a valid group-specific-property field custom list
if (mysql_num_rows($rsTemp) == 0) {
Redirect("Menu.php");
break;
}
break;
case famcustom:
$adj = gettext("Family Custom List");
$noun = gettext("Option");
$listID = FilterInput($_GET["ListID"],'int');
$embedded = true;
$sSQL = "SELECT '' FROM family_custom_master WHERE type_ID = 12 AND fam_custom_Special = " . $listID;
$rsTemp = RunQuery($sSQL);
// Validate that this is a valid family_custom field custom list
if (mysql_num_rows($rsTemp) == 0) {
Redirect("Menu.php");
break;
}
break;
default:
Redirect("Menu.php");
break;
}
// Check if we're adding a field
if (isset($_POST["AddField"]))
{
$newFieldName = FilterInput($_POST["newFieldName"]);
if (strlen($newFieldName) == 0)
{
$bNewNameError = 1;
}
else
{
// Check for a duplicate option name
$sSQL = "SELECT '' FROM list_lst WHERE lst_ID = $listID AND lst_OptionName = '" . $newFieldName . "'";
$rsCount = RunQuery($sSQL);
if (mysql_num_rows($rsCount) > 0)
{
$bNewNameError = 2;
}
else
{
// Get count of the options
$sSQL = "SELECT '' FROM list_lst WHERE lst_ID = $listID";
$rsTemp = RunQuery($sSQL);
$numRows = mysql_num_rows($rsTemp);
$newOptionSequence = $numRows + 1;
// Get the new OptionID
$sSQL = "SELECT MAX(lst_OptionID) FROM list_lst WHERE lst_ID = $listID";
$rsTemp = RunQuery($sSQL);
$aTemp = mysql_fetch_array($rsTemp);
$newOptionID = $aTemp[0] + 1;
// Insert into the appropriate options table
$sSQL = "INSERT INTO list_lst (lst_ID, lst_OptionID, lst_OptionName, lst_OptionSequence)
VALUES (" . $listID . "," . $newOptionID . ",'" . $newFieldName . "'," . $newOptionSequence . ")";
RunQuery($sSQL);
$bNewNameError = 0;
}
}
}
if (isset($_POST["SaveChanges"]))
{
$bErrorFlag = false;
$bDuplicateFound = false;
// Get the original list of options..
$sSQL = "SELECT lst_OptionName, lst_OptionID FROM list_lst WHERE lst_ID=$listID ORDER BY lst_OptionSequence";
$rsList = RunQuery($sSQL);
$numRows = mysql_num_rows($rsList);
for ($row = 1; $row <= $numRows; $row++)
{
$aRow = mysql_fetch_array($rsList, MYSQL_BOTH);
$aOldNameFields[$row] = $aRow["lst_OptionName"];
$aIDs[$row] = $aRow["lst_OptionID"];
$aNameFields[$row] = FilterInput($_POST[$row . "name"]);
}
for ($row = 1; $row <= $numRows; $row++)
{
if ( strlen($aNameFields[$row]) == 0 )
{
$aNameErrors[$row] = 1;
$bErrorFlag = true;
}
elseif ($row < $numRows)
{
$aNameErrors[$row] = 0;
for ($rowcmp = $row + 1; $rowcmp <= $numRows; $rowcmp++)
{
if ($aNameFields[$row] == $aNameFields[$rowcmp])
{
$bErrorFlag = true;
$bDuplicateFound = true;
$aNameErrors[$row] = 2;
break;
}
}
}
else
{
$aNameErrors[$row] = 0;
}
}
// If no errors, then update.
if (!$bErrorFlag)
{
for( $row=1; $row <= $numRows; $row++ )
{
// Update the type's name if it has changed from what was previously stored
if ($aOldNameFields[$row] != $aNameFields[$row])
{
$sSQL = "UPDATE list_lst SET `lst_OptionName` = '" . $aNameFields[$row] . "' WHERE `lst_ID` = '$listID' AND `lst_OptionSequence` = '" . $row . "'";
RunQuery($sSQL);
}
}
}
}
// Get data for the form as it now exists..
$sSQL = "SELECT lst_OptionName, lst_OptionID FROM list_lst WHERE lst_ID = $listID ORDER BY lst_OptionSequence";
$rsRows = RunQuery($sSQL);
$numRows = mysql_num_rows($rsRows);
// Create arrays of the option names and IDs
for ($row = 1; $row <= $numRows; $row++)
{
$aRow = mysql_fetch_array($rsRows, MYSQL_BOTH);
if (!$bErrorFlag)
$aNameFields[$row] = $aRow["lst_OptionName"];
$aIDs[$row] = $aRow["lst_OptionID"];
}
//Set the starting row color
$sRowClass = "RowColorA";
// Use a minimal page header if this form is going to be used within a frame
if ($embedded)
include "Include/Header-Minimal.php";
else
{
$sPageTitle = $adj . ' ' . $noun . "s Editor:";
include "Include/Header.php";
}
?>
<form method="post" action="OptionManager.php?<?php echo "mode=$mode&ListID=$listID" ?>" name="OptionManager">
<center><b><?php echo gettext("Warning: Removing will reset all assignments for all persons with the assignment!"); ?></b><br><br>
<?php
if ( $bErrorFlag )
{
echo "<span class=\"MediumLargeText\" style=\"color: red;\">";
if ($bDuplicateFound) echo "<br>" . gettext("Error: Duplicate") . " " . $adj . " " . $noun . gettext("s are not allowed.");
echo "<br>" . gettext("Invalid fields or selections. Changes not saved! Please correct and try again!") . "</span><br><br>";
}
?>
<input type="submit" class="icButton" <?php echo 'value="' . gettext("Save Changes") . '"'; ?> Name="SaveChanges">
<?php if ($mode == 'groupcustom' || $mode == 'custom' || $mode == 'famcustom') { ?>
<input type="button" class="icButton" <?php echo 'value="' . gettext("Exit") . '"'; ?> Name="Exit" onclick="javascript:window.close();">
<?php } elseif ($mode != "grproles") { ?>
<input type="button" class="icButton" <?php echo 'value="' . gettext("Exit") . '"'; ?> Name="Exit" onclick="javascript:document.location='<?php
if (strlen($sPreviousURL) > 0)
echo $sPreviousURL;
else
echo "Menu.php";
?>';">
<?php } ?>
</center>
<br>
<table cellpadding="3" width="30%" align="center">
<?php
for ($row=1; $row <= $numRows; $row++)
{
?>
<tr align="center">
<td class="LabelColumn">
<b>
<?php
if ($mode == "grproles" && $aIDs[$row] == $iDefaultRole)
echo gettext("Default") . " ";
echo $row;
?>
</b>
</td>
<td class="TextColumn" nowrap>
<?php
if ($row != 1)
echo "<a href=\"OptionManagerRowOps.php?mode=$mode&Order=$row&ListID=$listID&ID=" . $aIDs[$row] . "&Action=up\"><img src=\"Images/uparrow.gif\" border=\"0\"></a>";
if ($row < $numRows)
echo "<a href=\"OptionManagerRowOps.php?mode=$mode&Order=$row&ListID=$listID&ID=" . $aIDs[$row] . "&Action=down\"><img src=\"Images/downarrow.gif\" border=\"0\"></a>";
if ($numRows > 1)
echo "<a href=\"OptionManagerRowOps.php?mode=$mode&Order=$row&ListID=$listID&ID=" . $aIDs[$row] . "&Action=delete\"><img src=\"Images/x.gif\" border=\"0\"></a>";
?>
</td>
<td class="TextColumn">
<span class="SmallText">
<input type="text" name="<?php echo $row . "name"; ?>" value="<?php echo htmlentities(stripslashes($aNameFields[$row]),ENT_NOQUOTES, "UTF-8"); ?>" size="30" maxlength="40">
</span>
<?php
if ( $aNameErrors[$row] == 1 )
echo "<span style=\"color: red;\"><BR>" . gettext("You must enter a name.") . " </span>";
elseif ( $aNameErrors[$row] == 2 )
echo "<span style=\"color: red;\"><BR>" . gettext("Duplicate name found.") . " </span>";
?>
</td>
<?php
if ($mode == "grproles")
echo "<td class=\"TextColumn\"><input type=\"button\" class=\"icTinyButton\" value=\"" . gettext("Make Default") . "\" Name=\"default\" onclick=\"javascript:document.location='OptionManagerRowOps.php?mode=" . $mode . "&ListID=" . $listID . "&ID=" . $aIDs[$row] . "&Action=makedefault';\" ></td>";
?>
</tr>
<?php } ?>
</table>
<br>
<center>
New <?php echo $noun . " " . gettext("Name:"); ?>
<span class="SmallText">
<input type="text" name="newFieldName" size="30" maxlength="40">
</span>
<input type="submit" class="icTinyButton" <?php echo 'value="' . gettext("Add New") . ' ' . $adj . ' ' . $noun . '"'?> Name="AddField">
<?php
if ($bNewNameError > 0)
{
echo "<div><span style=\"color: red;\"><BR>";
if ( $bNewNameError == 1 )
echo gettext("Error: You must enter a name.");
else
echo gettext("Error: A ") . $noun . gettext(" by that name already exists.");
echo "</span></div>";
}
?>
</center>
</form>
<?php
if ($embedded)
echo "</body></html>";
else
include "Include/Footer.php";
?>