| Total Complexity | 38 |
| Total Lines | 367 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | class GroupsController extends BaseController |
||
| 15 | { |
||
| 16 | public $controller_name = 'GroupsController'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Default method to render the controller according to the action parameter. |
||
| 20 | */ |
||
| 21 | public function render() |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Show default list of groups in the database. |
||
| 90 | * |
||
| 91 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 92 | */ |
||
| 93 | public function doDefault($msg = '') |
||
| 94 | { |
||
| 95 | $lang = $this->lang; |
||
| 96 | $data = $this->misc->getDatabaseAccessor(); |
||
| 97 | |||
| 98 | $this->printTrail('server'); |
||
| 99 | $this->printTabs('server', 'groups'); |
||
| 100 | $this->printMsg($msg); |
||
| 101 | |||
| 102 | $groups = $data->getGroups(); |
||
| 103 | |||
| 104 | $columns = [ |
||
| 105 | 'group' => [ |
||
| 106 | 'title' => $lang['strgroup'], |
||
| 107 | 'field' => Decorator::field('groname'), |
||
| 108 | 'url' => "groups.php?action=properties&{$this->misc->href}&", |
||
| 109 | 'vars' => ['group' => 'groname'], |
||
| 110 | ], |
||
| 111 | 'actions' => [ |
||
| 112 | 'title' => $lang['stractions'], |
||
| 113 | ], |
||
| 114 | ]; |
||
| 115 | |||
| 116 | $actions = [ |
||
| 117 | 'drop' => [ |
||
| 118 | 'content' => $lang['strdrop'], |
||
| 119 | 'attr' => [ |
||
| 120 | 'href' => [ |
||
| 121 | 'url' => 'groups.php', |
||
| 122 | 'urlvars' => [ |
||
| 123 | 'action' => 'confirm_drop', |
||
| 124 | 'group' => Decorator::field('groname'), |
||
| 125 | ], |
||
| 126 | ], |
||
| 127 | ], |
||
| 128 | ], |
||
| 129 | ]; |
||
| 130 | |||
| 131 | echo $this->printTable($groups, $columns, $actions, 'groups-properties', $lang['strnogroups']); |
||
| 132 | |||
| 133 | $this->printNavLinks(['create' => [ |
||
|
1 ignored issue
–
show
|
|||
| 134 | 'attr' => [ |
||
| 135 | 'href' => [ |
||
| 136 | 'url' => 'groups.php', |
||
| 137 | 'urlvars' => [ |
||
| 138 | 'action' => 'create', |
||
| 139 | 'server' => $_REQUEST['server'], |
||
| 140 | ], |
||
| 141 | ], |
||
| 142 | ], |
||
| 143 | 'content' => $lang['strcreategroup'], |
||
| 144 | ]], 'groups-groups', get_defined_vars()); |
||
|
1 ignored issue
–
show
|
|||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Add user to a group. |
||
| 149 | */ |
||
| 150 | public function doAddMember() |
||
| 151 | { |
||
| 152 | $lang = $this->lang; |
||
| 153 | $data = $this->misc->getDatabaseAccessor(); |
||
| 154 | |||
| 155 | $status = $data->addGroupMember($_REQUEST['group'], $_REQUEST['user']); |
||
| 156 | if (0 == $status) { |
||
| 157 | $this->doProperties($lang['strmemberadded']); |
||
| 158 | } else { |
||
| 159 | $this->doProperties($lang['strmemberaddedbad']); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Show confirmation of drop user from group and perform actual drop. |
||
| 165 | * |
||
| 166 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 167 | */ |
||
| 168 | public function doDropMember($confirm) |
||
| 169 | { |
||
| 170 | $lang = $this->lang; |
||
| 171 | $data = $this->misc->getDatabaseAccessor(); |
||
| 172 | |||
| 173 | if ($confirm) { |
||
| 174 | $this->printTrail('group'); |
||
| 175 | $this->printTitle($lang['strdropmember'], 'pg.group.alter'); |
||
| 176 | |||
| 177 | echo '<p>', sprintf($lang['strconfdropmember'], $this->misc->printVal($_REQUEST['user']), $this->misc->printVal($_REQUEST['group'])), "</p>\n"; |
||
| 178 | |||
| 179 | echo '<form action="' . \SUBFOLDER . "/src/views/groups.php\" method=\"post\">\n"; |
||
| 180 | echo $this->misc->form; |
||
| 181 | echo "<input type=\"hidden\" name=\"action\" value=\"drop_member\" />\n"; |
||
| 182 | echo '<input type="hidden" name="group" value="', htmlspecialchars($_REQUEST['group']), "\" />\n"; |
||
| 183 | echo '<input type="hidden" name="user" value="', htmlspecialchars($_REQUEST['user']), "\" />\n"; |
||
| 184 | echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
||
| 185 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; |
||
| 186 | echo "</form>\n"; |
||
| 187 | } else { |
||
| 188 | $status = $data->dropGroupMember($_REQUEST['group'], $_REQUEST['user']); |
||
| 189 | if (0 == $status) { |
||
| 190 | $this->doProperties($lang['strmemberdropped']); |
||
| 191 | } else { |
||
| 192 | $this->doDropMember(true, $lang['strmemberdroppedbad']); |
||
| 193 | } |
||
| 194 | } |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Show read only properties for a group. |
||
| 199 | * |
||
| 200 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 201 | */ |
||
| 202 | public function doProperties($msg = '') |
||
| 203 | { |
||
| 204 | $lang = $this->lang; |
||
| 205 | $data = $this->misc->getDatabaseAccessor(); |
||
| 206 | |||
| 207 | if (!isset($_POST['user'])) { |
||
| 208 | $_POST['user'] = ''; |
||
| 209 | } |
||
| 210 | |||
| 211 | $this->printTrail('group'); |
||
| 212 | $this->printTitle($lang['strproperties'], 'pg.group'); |
||
| 213 | $this->printMsg($msg); |
||
| 214 | |||
| 215 | $groupdata = $data->getGroup($_REQUEST['group']); |
||
| 216 | $users = $data->getUsers(); |
||
| 217 | |||
| 218 | if ($groupdata->recordCount() > 0) { |
||
| 219 | $columns = [ |
||
| 220 | 'members' => [ |
||
| 221 | 'title' => $lang['strmembers'], |
||
| 222 | 'field' => Decorator::field('usename'), |
||
| 223 | ], |
||
| 224 | 'actions' => [ |
||
| 225 | 'title' => $lang['stractions'], |
||
| 226 | ], |
||
| 227 | ]; |
||
| 228 | |||
| 229 | $actions = [ |
||
| 230 | 'drop' => [ |
||
| 231 | 'content' => $lang['strdrop'], |
||
| 232 | 'attr' => [ |
||
| 233 | 'href' => [ |
||
| 234 | 'url' => 'groups.php', |
||
| 235 | 'urlvars' => [ |
||
| 236 | 'action' => 'confirm_drop_member', |
||
| 237 | 'group' => $_REQUEST['group'], |
||
| 238 | 'user' => Decorator::field('usename'), |
||
| 239 | ], |
||
| 240 | ], |
||
| 241 | ], |
||
| 242 | ], |
||
| 243 | ]; |
||
| 244 | |||
| 245 | echo $this->printTable($groupdata, $columns, $actions, 'groups-members', $lang['strnousers']); |
||
| 246 | } |
||
| 247 | |||
| 248 | // Display form for adding a user to the group |
||
| 249 | echo '<form action="' . \SUBFOLDER . "/src/views/groups.php\" method=\"post\">\n"; |
||
| 250 | echo '<select name="user">'; |
||
| 251 | while (!$users->EOF) { |
||
| 252 | $uname = $this->misc->printVal($users->fields['usename']); |
||
| 253 | echo "<option value=\"{$uname}\"", |
||
| 254 | ($uname == $_POST['user']) ? ' selected="selected"' : '', ">{$uname}</option>\n"; |
||
| 255 | $users->moveNext(); |
||
| 256 | } |
||
| 257 | echo "</select>\n"; |
||
| 258 | echo "<input type=\"submit\" value=\"{$lang['straddmember']}\" />\n"; |
||
| 259 | echo $this->misc->form; |
||
| 260 | echo '<input type="hidden" name="group" value="', htmlspecialchars($_REQUEST['group']), "\" />\n"; |
||
| 261 | echo "<input type=\"hidden\" name=\"action\" value=\"add_member\" />\n"; |
||
| 262 | echo "</form>\n"; |
||
| 263 | |||
| 264 | $this->printNavLinks(['showall' => [ |
||
|
1 ignored issue
–
show
|
|||
| 265 | 'attr' => [ |
||
| 266 | 'href' => [ |
||
| 267 | 'url' => 'groups.php', |
||
| 268 | 'urlvars' => [ |
||
| 269 | 'server' => $_REQUEST['server'], |
||
| 270 | ], |
||
| 271 | ], |
||
| 272 | ], |
||
| 273 | 'content' => $lang['strshowallgroups'], |
||
| 274 | ]], 'groups-properties', get_defined_vars()); |
||
|
1 ignored issue
–
show
|
|||
| 275 | } |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Show confirmation of drop and perform actual drop. |
||
| 279 | * |
||
| 280 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 281 | */ |
||
| 282 | public function doDrop($confirm) |
||
| 306 | } |
||
| 307 | } |
||
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Displays a screen where they can enter a new group. |
||
| 312 | * |
||
| 313 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 314 | */ |
||
| 315 | public function doCreate($msg = '') |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Actually creates the new group in the database. |
||
| 362 | */ |
||
| 363 | public function doSaveCreate() |
||
| 381 | } |
||
| 382 | } |
||
| 383 | } |
||
| 385 |