1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
//------------------------------------------------------------------------------ |
4
|
|
|
// |
5
|
|
|
// eTraxis - Records tracking web-based system |
6
|
|
|
// Copyright (C) 2010 Artem Rodygin |
7
|
|
|
// |
8
|
|
|
// This program is free software: you can redistribute it and/or modify |
9
|
|
|
// it under the terms of the GNU General Public License as published by |
10
|
|
|
// the Free Software Foundation, either version 3 of the License, or |
11
|
|
|
// (at your option) any later version. |
12
|
|
|
// |
13
|
|
|
// This program is distributed in the hope that it will be useful, |
14
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
// GNU General Public License for more details. |
17
|
|
|
// |
18
|
|
|
// You should have received a copy of the GNU General Public License |
19
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
// |
21
|
|
|
//------------------------------------------------------------------------------ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @package eTraxis |
25
|
|
|
* @ignore |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/**#@+ |
29
|
|
|
* Dependency. |
30
|
|
|
*/ |
31
|
|
|
require_once('../engine/engine.php'); |
32
|
|
|
require_once('../dbo/accounts.php'); |
33
|
|
|
require_once('../dbo/groups.php'); |
34
|
|
|
/**#@-*/ |
35
|
|
|
|
36
|
|
|
init_page(LOAD_TAB); |
37
|
|
|
|
38
|
|
|
if (get_user_level() != USER_LEVEL_ADMIN) |
39
|
|
|
{ |
40
|
|
|
debug_write_log(DEBUG_NOTICE, 'User must have admin rights to be allowed.'); |
41
|
|
|
exit; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// check that requested account exists |
45
|
|
|
|
46
|
|
|
$id = ustr2int(try_request('id')); |
47
|
|
|
$account = account_find($id); |
48
|
|
|
|
49
|
|
|
if (!$account) |
50
|
|
|
{ |
51
|
|
|
debug_write_log(DEBUG_NOTICE, 'Account cannot be found.'); |
52
|
|
|
exit; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// add to/remove from selected groups |
56
|
|
|
|
57
|
|
View Code Duplication |
if (try_request('submitted') == 'othersform') |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
debug_write_log(DEBUG_NOTICE, 'Data are submitted (adding to new groups).'); |
60
|
|
|
|
61
|
|
|
if (isset($_REQUEST['groups'])) |
62
|
|
|
{ |
63
|
|
|
foreach ($_REQUEST['groups'] as $group) |
64
|
|
|
{ |
65
|
|
|
group_membership_add($group, $id); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
else |
69
|
|
|
{ |
70
|
|
|
debug_write_log(DEBUG_NOTICE, 'No groups are selected.'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
exit; |
74
|
|
|
} |
75
|
|
|
elseif (try_request('submitted') == 'groupsform') |
76
|
|
|
{ |
77
|
|
|
debug_write_log(DEBUG_NOTICE, 'Data are submitted (removing from selected groups).'); |
78
|
|
|
|
79
|
|
|
if (isset($_REQUEST['groups'])) |
80
|
|
|
{ |
81
|
|
|
foreach ($_REQUEST['groups'] as $group) |
82
|
|
|
{ |
83
|
|
|
group_membership_remove($group, $id); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
else |
87
|
|
|
{ |
88
|
|
|
debug_write_log(DEBUG_NOTICE, 'No groups are selected.'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
exit; |
92
|
|
|
} |
93
|
|
|
else |
94
|
|
|
{ |
95
|
|
|
debug_write_log(DEBUG_NOTICE, 'Data are being requested.'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
// generate left side |
99
|
|
|
|
100
|
|
|
$xml = '<dual>' |
101
|
|
|
. '<dualleft>' |
102
|
|
|
. '<form name="othersform" action="groups.php?id=' . $id . '" success="reloadTab">' |
103
|
|
|
. '<group title="' . get_html_resource(RES_OTHERS_ID) . '">' |
104
|
|
|
. '<control name="groups[]">' |
105
|
|
|
. '<listbox size="10">'; |
106
|
|
|
|
107
|
|
|
$rs = dal_query('accounts/glist2.sql', $id); |
108
|
|
|
|
109
|
|
|
while (($row = $rs->fetch())) |
110
|
|
|
{ |
111
|
|
|
$xml .= '<listitem value="' . $row['group_id'] . '">' |
112
|
|
|
. ustr2html($row['group_name']) |
113
|
|
|
. '</listitem>'; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$xml .= '</listbox>' |
117
|
|
|
. '</control>' |
118
|
|
|
. '</group>' |
119
|
|
|
. '</form>' |
120
|
|
|
. '</dualleft>'; |
121
|
|
|
|
122
|
|
|
// generate right side |
123
|
|
|
|
124
|
|
|
$xml .= '<dualright>' |
125
|
|
|
. '<form name="groupsform" action="groups.php?id=' . $id . '" success="reloadTab">' |
126
|
|
|
. '<group title="' . get_html_resource(RES_GLOBAL_GROUPS_ID) . '">' |
127
|
|
|
. '<control name="groups[]">' |
128
|
|
|
. '<listbox size="10">'; |
129
|
|
|
|
130
|
|
|
$rs = dal_query('accounts/glist.sql', $id); |
131
|
|
|
|
132
|
|
|
while (($row = $rs->fetch())) |
133
|
|
|
{ |
134
|
|
|
$xml .= '<listitem value="' . $row['group_id'] . '">' |
135
|
|
|
. ustr2html($row['group_name']) |
136
|
|
|
. '</listitem>'; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$xml .= '</listbox>' |
140
|
|
|
. '</control>' |
141
|
|
|
. '</group>' |
142
|
|
|
. '</form>' |
143
|
|
|
. '</dualright>'; |
144
|
|
|
|
145
|
|
|
// generate buttons |
146
|
|
|
|
147
|
|
|
$xml .= '<button action="$(\'#othersform\').submit()">%gt;%gt;</button>' |
148
|
|
|
. '<button action="$(\'#groupsform\').submit()">%lt;%lt;</button>' |
149
|
|
|
. '</dual>'; |
150
|
|
|
|
151
|
|
|
echo(xml2html($xml)); |
152
|
|
|
|
153
|
|
|
?> |
154
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.