| Conditions | 36 | 
| Paths | > 20000 | 
| Total Lines | 239 | 
| Code Lines | 199 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 9 | ||
| Bugs | 0 | Features | 2 | 
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 | ||
| 280 | function displayDeploymentPropertyWidget(&$deploymentObject) { | ||
| 281 | // RADIUS status icons | ||
| 282 | $radiusMessages = [ | ||
| 283 |         \core\AbstractDeployment::RADIUS_OK => ['icon' => '../resources/images/icons/Tabler/square-rounded-check-filled-green.svg', 'text' => _("Successfully set profile")], | ||
| 284 |         \core\AbstractDeployment::RADIUS_FAILURE => ['icon' => '../resources/images/icons/Tabler/square-rounded-x-filled-red.svg', 'text' => _("Some problem occurred during profile update")], | ||
| 285 | ]; | ||
| 286 | |||
| 287 | $radius_status = array(); | ||
| 288 | $radius_status[0] = $deploymentObject->radius_status_1; | ||
| 289 | $radius_status[1] = $deploymentObject->radius_status_2; | ||
| 290 | $retry = $deploymentObject->checkRADIUSHostandConfigDaemon(); | ||
| 291 |     if (is_array($retry)) { | ||
| 292 |         foreach ($retry as $id => $stat) { | ||
| 293 |             if ($stat) { | ||
| 294 | $response = $deploymentObject->setRADIUSconfig($id, 1); | ||
| 295 | } | ||
| 296 | } | ||
| 297 | } | ||
| 298 | ?> | ||
| 299 | <div style='display: table-row_id;'> | ||
| 300 | <div class='profilebox' style='display: table-cell;'> | ||
| 301 | <h2><?php | ||
| 302 |                 switch ($deploymentObject->consortium) { | ||
| 303 | case "eduroam": | ||
| 304 | $displayname = config\ConfAssistant::CONSORTIUM['name'] . " " . core\DeploymentManaged::PRODUCTNAME; | ||
| 305 | break; | ||
| 306 | case "OpenRoaming": | ||
| 307 | $displayname = "OpenRoaming ANP"; | ||
| 308 | break; | ||
| 309 | default: | ||
| 310 |                         throw new Exception("We are supposed to operate on a roaming consortium we don't know."); | ||
| 311 | } | ||
| 312 |                 echo $displayname . " (<span style='color:" . ( $deploymentObject->status == \core\AbstractDeployment::INACTIVE ? "red;'>" . _("inactive") : "green;'>" . _("active") ) . "</span>)"; | ||
| 313 | ?></h2> | ||
| 314 | <table> | ||
| 315 |                 <caption><?php echo _("Deployment Details"); ?></caption> | ||
| 316 | <tr> | ||
| 317 |                     <th class='wai-invisible' scope='col'><?php echo("Server IP addresses"); ?></th> | ||
| 318 |                     <th class='wai-invisible' scope='col'><?php echo("Server Port label"); ?></th> | ||
| 319 |                     <th class='wai-invisible' scope='col'><?php echo("Server Port value"); ?></th> | ||
| 320 |                     <th class='wai-invisible' scope='col'><?php echo("Deployment Status"); ?></th> | ||
| 321 | </tr> | ||
| 322 | <tr> | ||
| 323 |                     <td><strong><?php echo _("Your primary RADIUS server") ?></strong><br/> | ||
| 324 | <?php | ||
| 325 |                         if ($deploymentObject->host1_v4 !== NULL) { | ||
| 326 |                             echo _("IPv4") . ": " . $deploymentObject->host1_v4; | ||
| 327 | } | ||
| 328 |                         if ($deploymentObject->host1_v4 !== NULL && $deploymentObject->host1_v6 !== NULL) { | ||
| 329 | echo "<br/>"; | ||
| 330 | } | ||
| 331 |                         if ($deploymentObject->host1_v6 !== NULL) { | ||
| 332 |                             echo _("IPv6") . ": " . $deploymentObject->host1_v6; | ||
| 333 | } | ||
| 334 | ?> | ||
| 335 | </td> | ||
| 336 |                     <td><?php echo _("RADIUS port number: ") ?></td> | ||
| 337 | <td><?php echo $deploymentObject->port1; ?></td> | ||
| 338 | <td> | ||
| 339 | <?php | ||
| 340 | echo "<img src='" . $radiusMessages[$deploymentObject->radius_status_1]['icon'] . | ||
| 341 | "' alt='" . $radiusMessages[$deploymentObject->radius_status_1]['text'] . | ||
| 342 | "' title='" . $radiusMessages[$deploymentObject->radius_status_1]['text'] . "' class='cat-icon'>"; | ||
| 343 | ?> | ||
| 344 | </td> | ||
| 345 | </tr> | ||
| 346 | <tr> | ||
| 347 |                     <td><strong><?php echo _("Your backup RADIUS server") ?><br/></strong> | ||
| 348 | <?php | ||
| 349 |                         if ($deploymentObject->host2_v4 !== NULL) { | ||
| 350 |                             echo _("IPv4") . ": " . $deploymentObject->host2_v4; | ||
| 351 | } | ||
| 352 |                         if ($deploymentObject->host2_v4 !== NULL && $deploymentObject->host2_v6 !== NULL) { | ||
| 353 | echo "<br/>"; | ||
| 354 | } | ||
| 355 |                         if ($deploymentObject->host2_v6 !== NULL) { | ||
| 356 |                             echo _("IPv6") . ": " . $deploymentObject->host2_v6; | ||
| 357 | } | ||
| 358 | ?></td> | ||
| 359 |                     <td><?php echo _("RADIUS port number: ") ?></td> | ||
| 360 | <td><?php echo $deploymentObject->port2; ?></td> | ||
| 361 | <td> | ||
| 362 | <?php | ||
| 363 | echo "<img src='" . $radiusMessages[$deploymentObject->radius_status_2]['icon'] . | ||
| 364 | "' alt='" . $radiusMessages[$deploymentObject->radius_status_2]['text'] . | ||
| 365 | "' title='" . $radiusMessages[$deploymentObject->radius_status_2]['text'] . "' class='cat-icon'>"; | ||
| 366 | ?> | ||
| 367 | </td> | ||
| 368 | </tr> | ||
| 369 | |||
| 370 | <tr> | ||
| 371 |                     <td><strong><?php echo _("RADIUS shared secret"); ?></strong></td> | ||
| 372 | <td><?php echo $deploymentObject->secret; ?></td> | ||
| 373 | </tr> | ||
| 374 | <tr><td colspan="4"><hr></td></tr> | ||
| 375 |                 <?php if ($opname = $deploymentObject->getAttributes("managedsp:operatorname")[0]['value'] ?? NULL) { ?> | ||
| 376 | <tr> | ||
| 377 |                         <td><strong><?php echo _("Custom Operator-Name"); ?></strong></td> | ||
| 378 | <td><?php echo $opname; ?></td> | ||
| 379 | </tr> | ||
| 380 | <?php | ||
| 381 | } | ||
| 382 |                 if ($vlan = $deploymentObject->getAttributes("managedsp:vlan")[0]['value'] ?? NULL) { | ||
| 383 | ?> | ||
| 384 | <tr> | ||
| 385 |                         <td><strong><?php echo _("VLAN tag for own users"); ?></strong></td> | ||
| 386 | <td><?php echo $vlan; ?></td> | ||
| 387 | </tr> | ||
| 388 | <?php } ?> | ||
| 389 | <?php | ||
| 390 |                 $allRealms = array_values(array_unique(array_column($deploymentObject->getAttributes("managedsp:realmforvlan"), "value"))); | ||
| 391 |                 if (!empty($allRealms)) { | ||
| 392 | ?> | ||
| 393 | <tr> | ||
| 394 |                         <td><strong><?php echo _("Realm to be considered own users"); ?></strong></td> | ||
| 395 |                         <td><?php echo implode(', ', $allRealms); ?></td> | ||
| 396 | </tr> | ||
| 397 | <?php | ||
| 398 | } | ||
| 399 | ?> | ||
| 400 | </table> | ||
| 401 | <div class='buttongroupprofilebox' style='clear:both;'> | ||
| 402 | <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'> | ||
| 403 | <br/> | ||
| 404 |                     <button type='submit' name='profile_action' style='cursor:pointer;' value='edit'><?php echo _("Advanced Configuration"); ?></button> | ||
| 405 | </form> | ||
| 406 |                 <?php if ($deploymentObject->status == \core\AbstractDeployment::ACTIVE) { ?> | ||
| 407 | <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'> | ||
| 408 |                         <button class='delete' type='submit' style='cursor:pointer;' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_DELETE; ?>' onclick="return confirm('<?php printf(_("Do you really want to deactivate the %s deployment?"), core\DeploymentManaged::PRODUCTNAME); ?>')"> | ||
| 409 |                             <?php echo _("Deactivate"); ?> | ||
| 410 | </button> | ||
| 411 | <?php | ||
| 412 |                         if (isset($_GET['res']) && is_array($_GET['res'])) { | ||
| 413 | $res = array_count_values($_GET['res']); | ||
| 414 |                             if (array_key_exists('FAILURE', $res) && $res['FAILURE'] > 0) { | ||
| 415 | echo '<br>'; | ||
| 416 |                                 if ($res['FAILURE'] == 2) { | ||
| 417 |                                     echo ' <span style="color: red;">' . _("Activation failure.") . '</span>'; | ||
| 418 |                                 } else { | ||
| 419 |                                     if (isset($_GET['res'][1]) && $_GET['res']['1'] == 'FAILURE') { | ||
| 420 |                                         echo ' <span style="color: red;">' . _("Activation failure for your primary RADIUS server.") . '</span>'; | ||
| 421 |                                     } else { | ||
| 422 |                                         echo ' <span style="color: red;">' . _("Activation failure for your backup RADIUS server.") . '</span>'; | ||
| 423 | } | ||
| 424 | } | ||
| 425 | } | ||
| 426 | } | ||
| 427 | ?> | ||
| 428 | </form> | ||
| 429 | <?php | ||
| 430 |                 } elseif (count($deploymentObject->getAttributes("hiddenmanagedsp:tou_accepted")) == 0) { | ||
| 431 | ?> | ||
| 432 | <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'> | ||
| 433 | <button class='delete' style='background-color: yellow; color: black;' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_TERMSOFUSE_NEEDACCEPTANCE; ?>'> | ||
| 434 |                             <?php echo _("Accept Terms of Use"); ?> | ||
| 435 | </button> | ||
| 436 | </form> | ||
| 437 | <div align="right"> | ||
| 438 | <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'> | ||
| 439 |                             <button class='delete' style='background-color: yellow; color: black' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_REMOVESP; ?>' onclick="return confirm('<?php printf(_("Do you really want to remove this %s deployment?"), core\DeploymentManaged::PRODUCTNAME); ?>')"> | ||
| 440 |                                 <?php echo _("Remove deployment"); ?> | ||
| 441 | </button> | ||
| 442 | </form> | ||
| 443 | </div> | ||
| 444 | <?php | ||
| 445 |                     } else { | ||
| 446 | ?> | ||
| 447 | <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'> | ||
| 448 | <button class='delete' style='background-color: green;' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_ACTIVATE; ?>'> | ||
| 449 |                                 <?php echo _("Activate"); ?> | ||
| 450 | </button> | ||
| 451 | <?php | ||
| 452 |                             if (isset($_GET['res']) && is_array($_GET['res'])) { | ||
| 453 | $res = array_count_values($_GET['res']); | ||
| 454 |                                 if ($res['FAILURE'] > 0) { | ||
| 455 | echo '<br>'; | ||
| 456 |                                     if ($res['FAILURE'] == 2) { | ||
| 457 |                                         echo ' <span style="color: red;">' . _("Failure during deactivation, your request is queued for handling") . '</span>'; | ||
| 458 |                                     } else { | ||
| 459 |                                         if (isset($_GET['res'][1]) && $_GET['res']['1'] == 'FAILURE') { | ||
| 460 |                                             echo ' <span style="color: red;">' . _("Deactivation failure for your primary RADIUS server, your request is queued.") . '</span>'; | ||
| 461 |                                         } else { | ||
| 462 |                                             echo ' <span style="color: red;">' . _("Deactivation failure for your backup RADIUS server, your request is queued.") . '</span>'; | ||
| 463 | } | ||
| 464 | } | ||
| 465 | } | ||
| 466 | } | ||
| 467 | ?> | ||
| 468 | </form> | ||
| 469 | <div align="right"> | ||
| 470 | <form action='edit_hotspot.php?inst_id=<?php echo $deploymentObject->institution; ?>&deployment_id=<?php echo $deploymentObject->identifier; ?>' method='post' accept-charset='UTF-8'> | ||
| 471 |                             <button class='delete' style='background-color: yellow; color: black' type='submit' name='submitbutton' value='<?php echo web\lib\common\FormElements::BUTTON_REMOVESP; ?>' onclick="return confirm('<?php printf(_("Do you really want to remove this %s deployment?"), core\DeploymentManaged::PRODUCTNAME); ?>')"> | ||
| 472 |                                 <?php echo _("Remove deployment"); ?> | ||
| 473 | </button> | ||
| 474 | </form> | ||
| 475 | </div> | ||
| 476 | <?php | ||
| 477 | } | ||
| 478 | ?> | ||
| 479 | </div> | ||
| 480 | </div> | ||
| 481 | <div style='width:20px;'></div> <!-- QR code space, reserved --> | ||
| 482 | <div style='display: table-cell; min-width:200px;'> | ||
| 483 |             <?php $tablecaption = _("Hotspot Usage Statistics");?> | ||
| 484 | <h1><?php echo $tablecaption; ?></h1> | ||
| 485 |             <h2><?php echo _("5 most recent authentications");?></h2> | ||
| 486 |             <p><?php echo _("(AP Identifier is a /-separated tuple of NAS-Identifier/NAS-IP-Address/NAS-IPv6-Address/Called-Station-Id)");?></p> | ||
| 487 | <table class='authrecord'> | ||
| 488 | <caption><?php echo $tablecaption;?></caption> | ||
| 489 | <tr style='text-align: left;'> | ||
| 490 |         <th scope="col"><strong><?php echo _("Timestamp (UTC)");?></strong></th> | ||
| 491 |         <th scope="col"><strong><?php echo _("Realm");?></strong></th> | ||
| 492 |         <th scope="col"><strong><?php echo _("MAC Address");?></strong></th> | ||
| 493 |         <th scope="col"><strong><?php echo _("Chargeable-User-Identity");?></strong></th> | ||
| 494 |         <th scope="col"><strong><?php echo _("Result");?></strong></th> | ||
| 495 |         <th scope="col"><strong><?php echo _("AP Identifier");?></strong></th> | ||
| 496 | </tr> | ||
| 497 | <?php | ||
| 498 | $userAuthData = $deploymentObject->retrieveStatistics(0,5); | ||
| 499 |     foreach ($userAuthData as $oneRecord) { | ||
| 500 | echo "<tr class='".($oneRecord['result'] == "OK" ? "auth-success" : "auth-fail" )."'>" | ||
| 501 | . "<td>".$oneRecord['activity_time']."</td>" | ||
| 502 | . "<td>".$oneRecord['realm']."</td>" | ||
| 503 | . "<td>".$oneRecord['mac']."</td>" | ||
| 504 | . "<td>".$oneRecord['cui']."</td>" | ||
| 505 |                 . "<td>".($oneRecord['result'] == "OK" ? _("Success") : _("Failure"))."</td>" | ||
| 506 | . "<td>".$oneRecord['ap_id']."</td>" | ||
| 507 | . "</tr>"; | ||
| 508 | } | ||
| 509 | ?> | ||
| 510 | </table> | ||
| 511 | <div style='display: ruby;'><form action="inc/deploymentStats.inc.php?inst_id=<?php echo $deploymentObject->institution; ?>&deployment_id=<?php echo $deploymentObject->identifier; ?>" onsubmit='popupRedirectWindow(this); return false;' accept-charset='UTF-8' method='post'> | ||
| 512 |                 <button type='submit' id='stats-hour' name='stats' value='HOUR'><?php echo _("Last hour"); ?></button> | ||
| 513 | </form> | ||
| 514 | <form action="inc/deploymentStats.inc.php?inst_id=<?php echo $deploymentObject->institution; ?>&deployment_id=<?php echo $deploymentObject->identifier; ?>" onsubmit='popupRedirectWindow(this); return false;' accept-charset='UTF-8' method='post'> | ||
| 515 |                 <button type='submit' id='stats-month' name='stats' value='MONTH'><?php echo _("Last 30 days"); ?></button> | ||
| 516 | </form> | ||
| 517 | <form action="inc/deploymentStats.inc.php?inst_id=<?php echo $deploymentObject->institution; ?>&deployment_id=<?php echo $deploymentObject->identifier; ?>" onsubmit='popupRedirectWindow(this); return false;' accept-charset='UTF-8' method='post'> | ||
| 518 |                 <button type='submit' id='stats-full' name='stats' value='FULL'><?php echo _("Last 6 months"); ?></button> | ||
| 519 | </form> | ||
| 788 |