| Conditions | 17 |
| Paths | 128 |
| Total Lines | 92 |
| Code Lines | 66 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 286 | public function formAlter($mode, $msg = '') |
||
| 287 | { |
||
| 288 | $data = $this->misc->getDatabaseAccessor(); |
||
| 289 | |||
| 290 | $this->coalesceArr($_REQUEST, 'username', []); |
||
| 291 | |||
| 292 | $this->coalesceArr($_REQUEST, 'groupname', []); |
||
| 293 | |||
| 294 | $this->coalesceArr($_REQUEST, 'privilege', []); |
||
| 295 | |||
| 296 | // Get users from the database |
||
| 297 | $users = $data->getUsers(); |
||
| 298 | // Get groups from the database |
||
| 299 | $groups = $data->getGroups(); |
||
| 300 | |||
| 301 | $this->printTrail($_REQUEST['subject']); |
||
| 302 | |||
| 303 | $this->printTitle($this->lang['str'.$mode], 'pg.privilege.'.$mode); |
||
| 304 | |||
| 305 | $this->printMsg($msg); |
||
| 306 | |||
| 307 | echo '<form action="'.\SUBFOLDER.'/src/views/privileges" method="post">'.PHP_EOL; |
||
| 308 | echo '<table>'.PHP_EOL; |
||
| 309 | echo "<tr><th class=\"data left\">{$this->lang['strusers']}</th>".PHP_EOL; |
||
| 310 | echo '<td class="data1"><select name="username[]" multiple="multiple" size="', min(6, $users->recordCount()), '">'.PHP_EOL; |
||
| 311 | while (!$users->EOF) { |
||
| 312 | $uname = htmlspecialchars($users->fields['usename']); |
||
| 313 | echo "<option value=\"{$uname}\"", |
||
| 314 | in_array($users->fields['usename'], $_REQUEST['username'], true) ? ' selected="selected"' : '', ">{$uname}</option>".PHP_EOL; |
||
| 315 | $users->moveNext(); |
||
| 316 | } |
||
| 317 | echo '</select></td></tr>'.PHP_EOL; |
||
| 318 | echo "<tr><th class=\"data left\">{$this->lang['strgroups']}</th>".PHP_EOL; |
||
| 319 | echo '<td class="data1">'.PHP_EOL; |
||
| 320 | echo '<input type="checkbox" id="public" name="public"', (isset($_REQUEST['public']) ? ' checked="checked"' : ''), ' /><label for="public">PUBLIC</label>'.PHP_EOL; |
||
| 321 | // Only show groups if there are groups! |
||
| 322 | if ($groups->recordCount() > 0) { |
||
| 323 | echo '<br /><select name="groupname[]" multiple="multiple" size="', min(6, $groups->recordCount()), '">'.PHP_EOL; |
||
| 324 | while (!$groups->EOF) { |
||
| 325 | $gname = htmlspecialchars($groups->fields['groname']); |
||
| 326 | echo "<option value=\"{$gname}\"", |
||
| 327 | in_array($groups->fields['groname'], $_REQUEST['groupname'], true) ? ' selected="selected"' : '', ">{$gname}</option>".PHP_EOL; |
||
| 328 | $groups->moveNext(); |
||
| 329 | } |
||
| 330 | echo '</select>'.PHP_EOL; |
||
| 331 | } |
||
| 332 | echo '</td></tr>'.PHP_EOL; |
||
| 333 | echo "<tr><th class=\"data left required\">{$this->lang['strprivileges']}</th>".PHP_EOL; |
||
| 334 | echo '<td class="data1">'.PHP_EOL; |
||
| 335 | foreach ($data->privlist[$_REQUEST['subject']] as $v) { |
||
| 336 | $v = htmlspecialchars($v); |
||
| 337 | echo "<input type=\"checkbox\" id=\"privilege[${v}]\" name=\"privilege[${v}]\"", |
||
| 338 | isset($_REQUEST['privilege'][$v]) ? ' checked="checked"' : '', " /><label for=\"privilege[${v}]\">{$v}</label><br />".PHP_EOL; |
||
| 339 | } |
||
| 340 | echo '</td></tr>'.PHP_EOL; |
||
| 341 | // Grant option |
||
| 342 | if ($data->hasGrantOption()) { |
||
| 343 | echo "<tr><th class=\"data left\">{$this->lang['stroptions']}</th>".PHP_EOL; |
||
| 344 | echo '<td class="data1">'.PHP_EOL; |
||
| 345 | if ('grant' == $mode) { |
||
| 346 | echo '<input type="checkbox" id="grantoption" name="grantoption"', |
||
| 347 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', ' /><label for="grantoption">GRANT OPTION</label>'.PHP_EOL; |
||
| 348 | } elseif ('revoke' == $mode) { |
||
| 349 | echo '<input type="checkbox" id="grantoption" name="grantoption"', |
||
| 350 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', ' /><label for="grantoption">GRANT OPTION FOR</label><br />'.PHP_EOL; |
||
| 351 | echo '<input type="checkbox" id="cascade" name="cascade"', |
||
| 352 | isset($_REQUEST['cascade']) ? ' checked="checked"' : '', ' /><label for="cascade">CASCADE</label><br />'.PHP_EOL; |
||
| 353 | } |
||
| 354 | echo '</td></tr>'.PHP_EOL; |
||
| 355 | } |
||
| 356 | echo '</table>'.PHP_EOL; |
||
| 357 | |||
| 358 | echo '<p><input type="hidden" name="action" value="save" />'.PHP_EOL; |
||
| 359 | echo '<input type="hidden" name="mode" value="', htmlspecialchars($mode), '" />'.PHP_EOL; |
||
| 360 | echo '<input type="hidden" name="subject" value="', htmlspecialchars($_REQUEST['subject']), '" />'.PHP_EOL; |
||
| 361 | if (isset($_REQUEST[$_REQUEST['subject'].'_oid'])) { |
||
| 362 | echo '<input type="hidden" name="', htmlspecialchars($_REQUEST['subject'].'_oid'), |
||
| 363 | '" value="', htmlspecialchars($_REQUEST[$_REQUEST['subject'].'_oid']), '" />'.PHP_EOL; |
||
| 364 | } |
||
| 365 | |||
| 366 | echo '<input type="hidden" name="', htmlspecialchars($_REQUEST['subject']), |
||
| 367 | '" value="', htmlspecialchars($_REQUEST[$_REQUEST['subject']]), '" />'.PHP_EOL; |
||
| 368 | if ('column' == $_REQUEST['subject']) { |
||
| 369 | echo '<input type="hidden" name="table" value="', |
||
| 370 | htmlspecialchars($_REQUEST['table']), '" />'.PHP_EOL; |
||
| 371 | } |
||
| 372 | |||
| 373 | echo $this->misc->form; |
||
| 374 | echo sprintf('<input type="submit" name="%s" value="%s" />%s', $mode, $this->lang['str'.$mode], PHP_EOL); |
||
| 375 | |||
| 376 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>"; |
||
| 377 | echo '</form>'.PHP_EOL; |
||
| 378 | } |
||
| 430 |