-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroupEditor.php
353 lines (303 loc) · 10.8 KB
/
GroupEditor.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
<?php
/*******************************************************************************
*
* filename : GroupEditor.php
* last change : 2003-04-15
* website : http://www.infocentral.org
* copyright : Copyright 2001, 2002, 2003 Deane Barker, Chris Gebhardt
*
* 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";
// Security: User must have Manage Groups permission
if (!$_SESSION['bManageGroups'])
{
Redirect("Menu.php");
exit;
}
//Set the page title
$sPageTitle = gettext("Group Editor");
//Get the GroupID from the querystring
$iGroupID = FilterInput($_GET["GroupID"],'int');
$bEmptyCart = ($_GET["EmptyCart"] == "yes") && count($_SESSION['aPeopleCart']) > 0;
//Is this the second pass?
if (isset($_POST["GroupSubmit"]))
{
//Assign everything locally
$sName = FilterInput($_POST["Name"]);
$iGroupType = FilterInput($_POST["GroupType"],'int');
$iDefaultRole = FilterInput($_POST["DefaultRole"],'int');
$sDescription = FilterInput($_POST["Description"]);
$bUseGroupProps = $_POST["UseGroupProps"];
$cloneGroupRole = FilterInput($_POST["cloneGroupRole"],'int');
$seedGroupID = FilterInput($_POST["seedGroupID"],'int');
//Did they enter a Name?
if (strlen($sName) < 1)
{
$bNameError = True;
$bErrorFlag = True;
}
// If no errors, then let's update...
if (!$bErrorFlag)
{
// Are we creating a new group?
if (strlen($iGroupID) < 1)
{
//Get a new Role List ID
$sSQL = "SELECT MAX(lst_ID) FROM list_lst";
$aTemp = mysql_fetch_array(RunQuery($sSQL));
if ($aTemp[0] > 9)
$newListID = $aTemp[0] + 1;
else
$newListID = 10;
if ($bUseGroupProps)
$sUseProps = 'true';
else
$sUseProps = 'false';
$sSQL = "INSERT INTO group_grp (grp_Name, grp_Type, grp_Description, grp_hasSpecialProps, grp_DefaultRole, grp_RoleListID) VALUES ('" . $sName . "', " . $iGroupType . ", '" . $sDescription . "', '" . $sUseProps . "', '1', " . $newListID . ")";
$bGetKeyBack = True;
$bCreateGroupProps = $bUseGroupProps;
}
else
{
$sSQLtest = "SELECT grp_hasSpecialProps FROM group_grp WHERE grp_ID = " . $iGroupID;
$rstest = RunQuery($sSQLtest);
$aRow = mysql_fetch_array($rstest);
$bCreateGroupProps = ($aRow[0] == 'false') && $bUseGroupProps;
$bDeleteGroupProps = ($aRow[0] == 'true') && !$bUseGroupProps;
$sSQL = "UPDATE group_grp SET grp_Name='" . $sName . "', grp_Type='" . $iGroupType . "', grp_Description='" . $sDescription . "'";
if ($bCreateGroupProps)
$sSQL .= ", grp_hasSpecialProps = 'true'";
if ($bDeleteGroupProps)
{
$sSQL .= ", grp_hasSpecialProps = 'false'";
$sSQLp = "DROP TABLE groupprop_" . $iGroupID;
RunQuery($sSQLp);
// need to delete the master index stuff
$sSQLp = "DELETE FROM groupprop_master WHERE grp_ID = " . $iGroupID;
RunQuery($sSQLp);
}
$sSQL .= " WHERE grp_ID = " . $iGroupID;
$bGetKeyBack = False;
}
// execute the SQL
RunQuery($sSQL);
//If the user added a new record, we need to key back to the route to the GroupView page
if ($bGetKeyBack)
{
//Get the key back
$iGroupID = mysql_insert_id($cnInfoCentral);
if (($cloneGroupRole) && ($seedGroupID>0)) {
$sSQL = "SELECT list_lst.* FROM list_lst, group_grp WHERE group_grp.grp_RoleListID = list_lst.lst_ID AND group_grp.grp_id = $seedGroupID ORDER BY list_lst.lst_OptionID";
$rsRoleSeed = RunQuery($sSQL);
while ($aRow = mysql_fetch_array($rsRoleSeed))
{
extract ($aRow);
$sSQL = "INSERT INTO list_lst VALUES ($newListID, $lst_OptionID, $lst_OptionSequence, '$lst_OptionName')";
RunQuery($sSQL);
}
} else
{
$sSQL = "INSERT INTO list_lst VALUES ($newListID, 1, 1,'Member')";
RunQuery($sSQL);
}
}
// Create a table for group-specific properties
if ( $bCreateGroupProps )
{
$sSQLp = "CREATE TABLE groupprop_" . $iGroupID . " (
per_ID mediumint(8) unsigned NOT NULL default '0',
PRIMARY KEY (per_ID),
UNIQUE KEY per_ID (per_ID)
) TYPE=MyISAM;";
RunQuery($sSQLp);
// If this is an existing group, add rows in this table for each member
if ( !$bGetKeyBack )
{
$sSQL = "SELECT per_ID FROM person_per INNER JOIN person2group2role_p2g2r ON per_ID = p2g2r_per_ID WHERE p2g2r_grp_ID = " . $iGroupID . " ORDER BY per_ID";
$rsGroupMembers = RunQuery($sSQL);
while ($aRow = mysql_fetch_array($rsGroupMembers))
{
$sSQLr = "INSERT INTO groupprop_" . $iGroupID . " ( `per_ID` ) VALUES ( '" . $aRow[0] . "' );";
RunQuery($sSQLr);
}
}
}
if ($_POST["EmptyCart"] && count($_SESSION['aPeopleCart']) > 0)
{
while ($element = each($_SESSION['aPeopleCart'])) {
AddToGroup($_SESSION['aPeopleCart'][$element[key]],$iGroupID,$iDefaultRole);
}
$sGlobalMessage = $iCount . " records(s) successfully added to selected Group.";
Redirect("GroupEditor.php?GroupID=" . $iGroupID . "&Action=EmptyCart");
}
else
{
Redirect("GroupEditor.php?GroupID=$iGroupID");
}
}
}
else
{
//FirstPass
//Are we editing or adding?
if (strlen($iGroupID) > 0)
{
//Editing....
//Get the information on this familyAge Groups for the drop down
$sSQL = "SELECT * FROM group_grp WHERE grp_ID = " . $iGroupID;
$rsGroup = RunQuery($sSQL);
$aRow = mysql_fetch_array($rsGroup);
$iGroupID = $aRow["grp_ID"];
$iGroupType = $aRow["grp_Type"];
$iDefaultRole = $aRow["grp_DefaultRole"];
$iRoleListID = $aRow["grp_RoleListID"];
$sName = $aRow["grp_Name"];
$sDescription = $aRow["grp_Description"];
$bHasSpecialProps = ($aRow["grp_hasSpecialProps"] == 'true');
}
}
// Get Group Types for the drop-down
$sSQL = "SELECT * FROM list_lst WHERE lst_ID = 3 ORDER BY lst_OptionSequence";
$rsGroupTypes = RunQuery($sSQL);
//Group Group Role List
$sSQL = "SELECT * FROM group_grp WHERE grp_RoleListID > 0 ORDER BY grp_Name";
$rsGroupRoleSeed = RunQuery($sSQL);
require "Include/Header.php";
?>
<script language="javascript">
bStatus = false;
function confirmDelete() {
if (!bStatus) {
bStatus = confirm(<?php echo "'" . gettext("Are you sure you want to remove the group-specific person properties? All group member properties data will be lost!") . "'"; ?>);
document.GroupEdit.UseGroupProps.checked = !bStatus;
}
else
bStatus = false;
}
function confirmAdd() {
if (!bStatus) {
bStatus = confirm(<?php echo "'" . gettext("This will create a group-specific properties table for this group. You should then add needed properties with the Group-Specific Properties Form Editor.") . "'"; ?>);
document.GroupEdit.UseGroupProps.checked = bStatus;
}
else
bStatus = false;
}
</script>
<table border="0" width="100%">
<tr>
<td width="40%" valign="top" align="center">
<form name="GroupEdit" method="post" action="GroupEditor.php?GroupID=<?php echo $iGroupID ?>">
<table cellpadding="3">
<tr>
<td class="LabelColumn"><b><?php echo gettext("Name:"); ?></b></td>
<td class="TextColumn"><input type="text" Name="Name" value="<?php echo htmlentities(stripslashes($sName),ENT_NOQUOTES, "UTF-8"); ?>" size="40" maxlength="50">
<?php if ($bNameError) echo "<br><font color=\"red\">" . gettext("You must enter a name.") . "</font>"; ?>
</td>
</tr>
<tr>
<td class="LabelColumn"><b><?php echo gettext("Description:"); ?></b></td>
<td class="TextColumnWithBottomBorder"><textarea name="Description" cols="40" rows="5"><?php echo htmlentities(stripslashes($sDescription),ENT_NOQUOTES, "UTF-8"); ?></textarea></td>
</tr>
<tr>
<td class="LabelColumn"><b><?php echo gettext("Type of Group:"); ?></b></td>
<td class="TextColumnWithBottomBorder">
<select name="GroupType">
<option value="0"><?php echo gettext("Unassigned"); ?></option>
<option value="0">-----------------------</option>
<?php
while ($aRow = mysql_fetch_array($rsGroupTypes))
{
extract($aRow);
echo "<option value=\"" . $lst_OptionID . "\"";
if ($iGroupType == $lst_OptionID)
echo " selected";
echo ">" . $lst_OptionName . "</option>";
}
?>
</select>
</td>
</tr>
<?php
// Show Role Clone fields only when adding new group
if (strlen($iGroupID) < 1) { ?>
<tr>
<td class="LabelColumn"><b><?php echo gettext("Group Member Roles:"); ?></b></td>
<td class="TextColumnWithBottomBorder">
<?php echo gettext("Clone roles:"); ?>
<input type="checkbox" name="cloneGroupRole" value="1"><br>
<?php echo gettext("from group:"); ?>
<select name="seedGroupID">
<option value="0"><?php gettext("Select a group"); ?></option>
<?php
while ($aRow = mysql_fetch_array($rsGroupRoleSeed))
{
extract($aRow);
echo "<option value=\"" . $grp_ID . "\">" . $grp_Name . "</option>";
}
echo "</select>";
?>
</td>
</tr>
<?php } ?>
<tr>
<td class="LabelColumn"><b><?php echo gettext("Group-Specific<br>Properties:"); ?></b></td>
<td class="TextColumnWithBottomBorder">
<?php echo gettext("Use group-specific properties?"); ?>
<?php
if ($bHasSpecialProps)
{
echo "<input type=\"checkbox\" name=\"UseGroupProps\" value=\"1\" onChange=\"confirmDelete();\" checked><br><br>";
echo "<a class=\"SmallText\" href=\"GroupPropsFormEditor.php?GroupID=$iGroupID\">" . gettext("Edit Group-Specific Properties Form") . "</a>";
}
else
echo "<input type=\"checkbox\" name=\"UseGroupProps\" value=\"1\" onChange=\"confirmAdd();\">";
?>
</td>
</tr>
<tr>
<td class="SmallShadedBox" colspan="2" align="center"><input type="checkbox" name="EmptyCart" value="1" <?php if ($bEmptyCart) { echo " checked"; } ?>> <b><?php echo gettext("Empty Cart to this Group?"); ?></b></td>
</tr>
<tr><td><br></td></tr>
<tr>
<td colspan="2" align="center">
<input type="submit" class="icButton" <?php echo 'value="' . gettext("Save") . '"'; ?> Name="GroupSubmit">
<input type="button" class="icButton" <?php echo 'value="' . gettext("Exit") . '"'; ?> Name="GroupCancel" onclick="javascript:document.location='<?php
if (strlen($iGroupID) > 0)
echo "GroupView.php?GroupID=$iGroupID';\">";
else
echo "GroupList.php';\">";
?>
</td>
</tr>
</table>
</form>
</td>
<td align="center">
<?php
if (strlen($iGroupID) > 0)
{
?>
<b class="MediumLargeText"><?php echo gettext("Group Roles:"); ?></b><br><br>
<iframe width="100%" height="400px" frameborder="0" align="left" marginheight="0" marginwidth="0"
src="OptionManager.php?mode=grproles&ListID=<?php echo $iRoleListID; ?>"></iframe>
<?php
}
else
{
?><b class="MediumLargeText"><?php echo gettext("Initial Group Creation: Group roles can be edited after the first save."); ?></b><br><br><?php
}
?>
</td>
</tr>
</table>
<?php
require "Include/Footer.php";
?>