-
Notifications
You must be signed in to change notification settings - Fork 32
/
group.php
244 lines (205 loc) · 8.29 KB
/
group.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
<?php
include ("include/dbconnect.php");
include ("include/format.inc.php");
echo "<title>Groups | Address Book</title>";
include ("include/header.inc.php");
echo "<h1>".ucfmsg('GROUPS')."</h1>";
if($read_only) {
echo "<br /><div class='msgbox'>Editing is disabled.<br /><i>return to the <a href='group$page_ext'>group page</a></i></div>";
} else {
if($submit) {
$sql = "INSERT INTO $table_groups (domain_id, group_name, group_header, group_footer, group_parent_id)
VALUES ('$domain_id', '$group_name','$group_header','$group_footer','$group_parent_id')";
$result = mysql_query($sql);
echo "<br /><div class='msgbox'>A new group has been entered into the address book.<br /><i>return to the <a href='group$page_ext'>group page</a></i></div>";
// -- Add people to a group
} else if($new) {
?>
<form accept-charset="utf-8" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<label>Group name:</label>
<input type="text" name="group_name" size="35" /><br />
<label><?php echo ucfmsg('GROUP_PARENT'); ?></label>
<select name="group_parent_id">
<option value="0">[none]</option>
<?php
$sql="SELECT group_name, group_id
FROM $groups_from_where
ORDER BY lower(group_name) ASC;";
$result_groups = mysql_query($sql);
$result_gropup_snumber = mysql_numrows($result_groups);
// has parent row in list been found?
$parent_found = false;
while ($myrow2 = mysql_fetch_array($result_groups))
{
echo "<option value=\"".$myrow2['group_id']."\">".$myrow2["group_name"]."</option>\n";
}
?>
</select><br /><br />
<label>Group header (Logo):</label>
<textarea name="group_header" rows="10" cols="40"></textarea><br />
<label>Group footer (Comment):</label>
<textarea name="group_footer" rows="10" cols="40"></textarea><br /><br />
<input type="submit" name="submit" value="Enter information" />
</form>
<?php
} else if($delete) {
// Remove the groups
foreach($selected as $group_id)
{
// Delete links between addresses and groups
$sql = "delete from $table_grp_adr where domain_id = $domain_id AND group_id = $group_id";
$result = mysql_query($sql);
// Delete groups
$sql = "delete from $groups_from_where AND group_id = $group_id";
$result = mysql_query($sql);
}
echo "<div class='msgbox'>Group has been removed.<br /><i>return to the <a href='group$page_ext'>group page</a></i></div>";
}
else if($add)
{
// Lookup for the group_id
$sql = "select * from $groups_from_where AND group_name = '$to_group'";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$group_id = $myrow["group_id"];
$group_name = $myrow["group_name"];
// Add people to the group, who are not alread in the group!
if(isset($selected)){
foreach($selected as $user_id)
{
$sql = "insert into $table_grp_adr (domain_id, id, group_id, created, modified)
values ($domain_id, $user_id, $group_id, now(), now())";
$result = mysql_query($sql);
}
echo "<div class='msgbox'>Users added.<br /><i>Go to <a href='./?group=$group_name'>group page \"$group_name\"</a>.</i></div>";
} else {
echo "<div class='msgbox'><i>No users selected.<br />Please use the checkbox to select a user.</i></div>";
}
}
// -- Remove people from a group
else if($remove)
{
// Lookup for the group_id
$sql = "select * from $table_groups where group_name = '$group'";
$result = mysql_query($sql);
// $resultsnumber = mysql_numrows($result);
$myrow = mysql_fetch_array($result);
$group_id = $myrow["group_id"];
$group_name = $myrow["group_name"];
// Remove people from the group, who are not alread in the group!
foreach($selected as $user_id)
{
$sql = "delete from $table_grp_adr where id = $user_id AND group_id = $group_id";
$result = mysql_query($sql);
}
echo "<div class='msgbox'>Users removed. <br /><i>return to <a href='./?group=$group_name'>group page \"$group_name\"</a>.</i></div>";
}
else if($update)
{
$sql="SELECT * FROM $table_groups WHERE group_id=$id";
$result = mysql_query($sql);
$resultsnumber = mysql_numrows($result);
if($resultsnumber > 0)
{
if (!is_numeric($group_parent_id))
$gpid='null';
else
$gpid=$group_parent_id;
$sql = "UPDATE $table_groups SET group_name='$group_name'".
", group_header='$group_header'".
", group_footer='$group_footer'".
", group_parent_id=$gpid".
" WHERE group_id=$id";
$result = mysql_query($sql);
// header("Location: view?id=$id");
echo "<br /><div class='msgbox'>Group record has been updated.<br /><i>return to the <a href='group$page_ext'>group page</a></i></div>";
} else {
echo "<br /><div class='msgbox'>Invalid ID.<br /><i>return to the <a href='group$page_ext'>group page</a></i></div>";
}
}
// Open for Editing
else if($edit || $id)
{
if($edit)
$id = $selected[0];
$result = mysql_query("$select_groups AND groups.group_id=$id",$db);
$myrow = mysql_fetch_array($result);
?>
<form accept-charset="utf-8" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type="hidden" name="id" value="<?php echo $myrow['group_id']?>" />
<label><?php echo ucfmsg('GROUP_NAME'); ?></label>
<input type="text" name="group_name" size="35" value="<?php echo $myrow['group_name'];?>" />
<br /><br />
<label><?php echo ucfmsg('GROUP_PARENT'); ?></label>
<select name="group_parent_id">
<?php
$sql="SELECT group_name, group_id
FROM $table_groups
WHERE group_id != $id
ORDER BY lower(group_name) ASC;";
$result_groups = mysql_query($sql);
$result_gropup_snumber = mysql_numrows($result_groups);
// has parent row in list been found?
$parent_found = false;
while ($myrow2 = mysql_fetch_array($result_groups))
{
// look for selected parent
if ($myrow['group_parent_id'] == $myrow2['group_id']) {
$selected_text = ' selected';
$parent_found = true;
} else {
// not found, reset selected text
$selected_text = '';
}
// parent option
echo "<option value=\"".$myrow2['group_id']."\"$selected_text>".$myrow2["group_name"]."</option>\n";
}
// if no matching parent found, default to none
if (!$parent_found)
$selected_text = ' selected';
else
$selected_text = '';
// none option
echo "<option value=\"none\"$selected_text>[none]</option>\n";
?>
</select>
<br /><br class="clear" />
<label><?php echo ucfmsg('GROUP_HEADER'); ?>:</label>
<textarea name="group_header" rows="10" cols="40"><?php echo $myrow["group_header"]?></textarea><br />
<label><?php echo ucfmsg('GROUP_FOOTER'); ?>:</label>
<textarea name="group_footer" rows="10" cols="40"><?php echo $myrow["group_footer"]?></textarea><br /><br />
<input type="submit" name="update" value="<?php echo ucfmsg('UPDATE'); ?>" />
</form>
<br />
<?php
}
else
{
$result = mysql_query($select_groups." ORDER BY groups.group_name");
$resultsnumber = mysql_numrows($result);
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type="submit" name="new" value="<?php echo ucfmsg('NEW_GROUP'); ?>" />
<input type="submit" name="delete" value="<?php echo ucfmsg('DELETE_GROUPS'); ?>" />
<input type="submit" name="edit" value="<?php echo ucfmsg('EDIT_GROUP'); ?>" />
<hr />
<?php
while ($myrow = mysql_fetch_array($result)) {
echo "<input type='checkbox' name='selected[]' value='".$myrow['group_id']."' title='Select (".$myrow['group_name'].")'/>";
if($myrow['parent_name'] != "") {
echo $myrow['group_name']." <i>(".$myrow['parent_name'].")</i><br />";
} else {
echo $myrow['group_name']."<br />";
}
}
?>
<br />
<input type="submit" name="new" value="<?php echo ucfmsg('NEW_GROUP'); ?>" />
<input type="submit" name="delete" value="<?php echo ucfmsg('DELETE_GROUPS'); ?>" />
<input type="submit" name="edit" value="<?php echo ucfmsg('EDIT_GROUP'); ?>" />
</form>
<?php
}
}
include ("include/footer.inc.php");
?>