| 452 | | static function processSelectUserUI($user_prefix, &$errMsg) { |
| 453 | | /*$object = null; |
| 454 | | try { |
| 455 | | $network = Network :: processSelectUI($user_prefix); |
| 456 | | $name = "select_user_{$user_prefix}_username"; |
| 457 | | if (!empty ($_REQUEST[$name])) { |
| 458 | | $username = $_REQUEST[$name]; |
| 459 | | return self :: getUserByUsernameOrEmail($username, $errMsg); |
| 460 | | } else |
| 461 | | return null; |
| 462 | | } catch (Exception $e) { |
| 463 | | return null; |
| 464 | | }*/ |
| 465 | | } |
| 466 | | |
| 467 | | // TODO: implement this |
| | 490 | public static function getTemplatesForNetworkUI($user_prefix, $network) { |
| | 491 | |
| | 492 | $db = AbstractDb :: getObject(); |
| | 493 | |
| | 494 | $networktemplates = self::getTemplatesForNetwork($network); |
| | 495 | $object_id = $db->escapeString($network->getId()); |
| | 496 | |
| | 497 | // Get the list of all contexts to see which are taken |
| | 498 | $contexts = self::getContexts(); |
| | 499 | $html = "<table class='token_template_management'>\n"; |
| | 500 | $html .= "<th>" . _('Context') . '</th><th>' . _('Actions') . '</th>' . "\n"; |
| | 501 | |
| | 502 | |
| | 503 | foreach ($networktemplates as $template) { |
| | 504 | |
| | 505 | $html .= "<tr class='token_template'>\n"; |
| | 506 | /* Display page */ |
| | 507 | $html .= "<td>" . $contexts[$template->getContext()] . "</td>\n"; |
| | 508 | $html .= "<td>"; |
| | 509 | $name = $object_id . "_tt_" . $template->getId() . "_" . $template->getContext() . "_edit"; |
| | 510 | $html .= "<input type='button' class='submit' name='$name' value='" . _("Edit") . "' onClick='window.open(\"" . GENERIC_OBJECT_ADMIN_ABS_HREF . "?object_class=TokenTemplate&action=edit&object_id=" . $template->getId() . "\");'>\n"; |
| | 511 | $html .= "</td>\n"; |
| | 512 | $html .= "</tr>\n"; |
| | 513 | unset($contexts[$template->getContext()]); |
| | 514 | } |
| | 515 | |
| | 516 | // Add new token for remaining context |
| | 517 | if (!empty($contexts)) { |
| | 518 | $choices = array(); |
| | 519 | $i = 0; |
| | 520 | foreach ($contexts as $key => $value) { |
| | 521 | $choices[$i][0] = $key; |
| | 522 | $choices[$i][1] = $value; |
| | 523 | $i++; |
| | 524 | } |
| | 525 | $html .= "<tr>"; |
| | 526 | $html .= "<td>" . FormSelectGenerator::generateFromArray($choices, null, $user_prefix, 'tt_add', false) . "</td>\n"; |
| | 527 | $name = $object_id . "_tt_add"; |
| | 528 | $html .= "<td><input type='submit' class='submit' name='$name' value='" . _("Add") . "'></td>\n"; |
| | 529 | $html .= "</tr>\n"; |
| | 530 | |
| | 531 | } |
| | 532 | $html .= "</table>\n"; |
| | 533 | |
| | 534 | return $html; |
| | 535 | } |
| | 536 | |
| | 537 | /** |
| | 538 | * processes the interface to add / edit token templates |
| | 539 | * |
| | 540 | * @param string $user_prefix A identifier provided by the |
| | 541 | * programmer to recognise it's |
| | 542 | * generated HTML form |
| | 543 | * @param Network $network The network to get the ui for |
| | 544 | * @return string HTML markup |
| | 545 | |
| | 546 | */ |
| | 547 | public static function processTemplatesForNetworkUI($user_prefix, $network) { |
| | 548 | |
| | 549 | $db = AbstractDb :: getObject(); |
| | 550 | |
| | 551 | $networktemplates = self::getTemplatesForNetwork($network); |
| | 552 | $object_id = $db->escapeString($network->getId()); |
| | 553 | |
| | 554 | // Get the list of all contexts to see which are taken |
| | 555 | $contexts = self::getContexts(); |
| | 556 | |
| | 557 | $name = $object_id . "_tt_add"; |
| | 558 | if (!empty($_REQUEST[$name])) { |
| | 559 | $context = FormSelectGenerator::getResult($user_prefix, 'tt_add'); |
| | 560 | self::createNewObject(null, $network, $context); |
| | 561 | } |
| | 562 | |
| | 563 | } |
| | 564 | |
| 470 | | $db = AbstractDb::getObject(); |
| 471 | | $currentUser = self :: getCurrentUser(); |
| 472 | | $userPreferencesItems = array(); |
| 473 | | $finalHtml = ''; |
| 474 | | if(Security::hasPermission(Permission::P('NETWORK_PERM_VIEW_STATISTICS'), $this->getNetwork())) { |
| 475 | | // Statistics |
| 476 | | $content = "<a href='".BASE_SSL_PATH."admin/stats.php?Statistics=".$this->getNetwork()->getId()."&distinguish_users_by=user_id&stats_selected_users=".$this->getUsername()."&UserReport=on&user_id=".$this->getId()."&action=generate'>"._("Get user statistics")."</a>\n"; |
| 477 | | $administrationItems[] = InterfaceElements::genSectionItem($content); |
| 478 | | |
| 479 | | // Account status |
| 480 | | $title = _("Account Status"); |
| 481 | | $help = _("Note that Error is for internal use only"); |
| 482 | | $name = "user_" . $this->getId() . "_accountstatus"; |
| 483 | | global $account_status_to_text; |
| 484 | | $content = FormSelectGenerator::generateFromKeyLabelArray($account_status_to_text, $this->getAccountStatus(), $name, null, false); |
| 485 | | $administrationItems[] = InterfaceElements::genSectionItem($content, $title, $help); |
| 486 | | |
| 487 | | $finalHtml .= InterfaceElements::genSection($administrationItems, _("Administrative options")); |
| 488 | | } |
| 489 | | |
| 490 | | if (($this == $currentUser && !$this->isSplashOnlyUser() )|| Security::hasPermission(Permission::P('NETWORK_PERM_EDIT_ANY_USER'), $this->getNetwork())) { |
| 491 | | // Username |
| 492 | | $title = _("Username"); |
| 493 | | $name = "user_" . $this->getId() . "_username"; |
| 494 | | $content = "<input type='text' name='$name' value='" . htmlentities($this->getUsername()) . "' size=30><br/>\n"; |
| 495 | | $content .= _("Be careful when changing this: it's the username you use to log in!"); |
| 496 | | $userPreferencesItems[] = InterfaceElements::genSectionItem($content, $title); |
| 497 | | |
| 498 | | |
| 499 | | // Email |
| 500 | | $title = _("Email"); |
| 501 | | $name = "email_" . $this->getId() . "_email"; |
| 502 | | $content = "<input type='text' name='$name' disabled='disabled' value='" . htmlentities($this->getEmail()) . "' size=30><br/>\n"; |
| 503 | | $content .= _("If you wish to change this address, please Email Support!"); |
| 504 | | $userPreferencesItems[] = InterfaceElements::genSectionItem($content, $title); |
| 505 | | |
| 506 | | |
| 507 | | |
| 508 | | // Change password |
| 509 | | $changePasswordItems=array(); |
| 510 | | if($this == $currentUser) {//Don't enter the old password if changing password for another user |
| 511 | | $title = _("Your current password"); |
| 512 | | $name = "user_" . $this->getId() . "_oldpassword"; |
| 513 | | $content = "<input type='password' name='$name' size='20'>\n"; |
| 514 | | $changePasswordItems[] = InterfaceElements::genSectionItem($content, $title); |
| 515 | | } |
| 516 | | |
| 517 | | $title = _("Your new password"); |
| 518 | | $name = "user_" . $this->getId() . "_newpassword"; |
| 519 | | $content = "<input type='password' name='$name' size='20'>\n"; |
| 520 | | $changePasswordItems[] = InterfaceElements::genSectionItem($content, $title); |
| 521 | | |
| 522 | | $title = _("Your new password (again)"); |
| 523 | | $name = "user_" . $this->getId() . "_newpassword_again"; |
| 524 | | $content = "<input type='password' name='$name' size='20'>\n"; |
| 525 | | $changePasswordItems[] = InterfaceElements::genSectionItem($content, $title); |
| 526 | | |
| 527 | | $userPreferencesItems[] = InterfaceElements::genSection($changePasswordItems, _("Change my password")); |
| 528 | | |
| 529 | | $finalHtml .= InterfaceElements::genSection($userPreferencesItems, _("User preferences"), false, false, get_class($this)); |
| 530 | | |
| 531 | | //N.B: For now, let pretend we have only one profile per use... |
| 532 | | $profiles = $this->getAllProfiles(); |
| 533 | | $current_profile = null; |
| 534 | | if(!empty($profiles)) { |
| 535 | | $current_profile = $profiles[0]; |
| 536 | | } |
| 537 | | |
| 538 | | if($current_profile != null) { |
| 539 | | $finalHtml .= $current_profile->getAdminUI(); |
| 540 | | $name = "user_" . $this->getId() . "_delete_profile_".$current_profile->getId(); |
| 541 | | $value = _("Completely delete my public profile"); |
| 542 | | $finalHtml .= "<div class='admin_element_tools'>"; |
| 543 | | $finalHtml .= '<input type="submit" class="submit" name="' . $name . '" value="' . $value . '">'; |
| 544 | | $finalHtml .= "</div>"; |
| 545 | | } |
| 546 | | else { // Get the list of profile templates for the users' network |
| 547 | | $profile_templates = ProfileTemplate::getAllProfileTemplates($this->getNetwork()); |
| 548 | | if(!empty($profile_templates)) { |
| 549 | | $name = "user_" . $this->getId() . "_add_profile"; |
| 550 | | $value = _("Create my public profile"); |
| 551 | | $finalHtml .= "<div class='admin_element_tools'>"; |
| 552 | | $finalHtml .= '<input type="submit" class="submit" name="' . $name . '" value="' . $value . '">'; |
| 553 | | $finalHtml .= "</div>"; |
| 554 | | } |
| 555 | | } |
| 556 | | } |
| 557 | | |
| 558 | | return $finalHtml;*/ |
| 559 | | } |
| 560 | | |
| 561 | | // TODO Implement this |
| | 572 | * Verify if an error message was registered before outputting the form |
| | 573 | */ |
| | 574 | if (isset($this->errorMsg)) { |
| | 575 | $html .= "<div class='errormsg'>" . $this->errorMsg . "</div>"; |
| | 576 | } |
| | 577 | $tt_id = $this->getId(); |
| | 578 | |
| | 579 | /* |
| | 580 | * Begin with admin interface |
| | 581 | */ |
| | 582 | $html .= "<fieldset class='admin_container ".get_class($this)."'>\n"; |
| | 583 | $html .= "<legend>"._("Token template")."</legend>\n"; |
| | 584 | $html .= "<ul class='admin_element_list'>\n"; |
| | 585 | |
| | 586 | /* |
| | 587 | * Template information |
| | 588 | */ |
| | 589 | $html_tt_information = array(); |
| | 590 | |
| | 591 | // template id |
| | 592 | $title = _("Token Template Id"); |
| | 593 | $data = htmlspecialchars($tt_id, ENT_QUOTES); |
| | 594 | $html_tt_information[] = InterfaceElements::generateAdminSectionContainer("tt_id", $title, $data); |
| | 595 | |
| | 596 | // template context |
| | 597 | $title = _("Token Template Context"); |
| | 598 | $contexts = self::getContexts(); |
| | 599 | $data = htmlspecialchars(_($contexts[$this->getContext()]), ENT_QUOTES); |
| | 600 | $html_tt_information[] = InterfaceElements::generateAdminSectionContainer("tt_context", $title, $data); |
| | 601 | |
| | 602 | // template description |
| | 603 | $_title = _("Description"); |
| | 604 | $name = "tt_" . $tt_id . "_description"; |
| | 605 | $data = "<textarea name='$name' cols=80 rows=5 id='tt_description_textarea'>\n".$this->getDescription()."\n</textarea>\n"; |
| | 606 | $html_tt_information[] = InterfaceElements::generateAdminSectionContainer("tt_description", $_title, $data); |
| | 607 | |
| | 608 | // is reusable |
| | 609 | $title = _("Template reusable"); |
| | 610 | $help = _("Are tokens generated from this template reusable?"); |
| | 611 | $data = InterfaceElements::generateInputCheckbox("tt_" . $tt_id . "_reusable", "", _("Yes"), $this->getIsReusable(), "tt_reusable_radio"); |
| | 612 | $html_tt_information[] = InterfaceElements::generateAdminSectionContainer("tt_reusable", $title, $data, $help); |
| | 613 | |
| | 614 | // Build section |
| | 615 | $html .= InterfaceElements::generateAdminSectionContainer("tt_information", _("Information about the token template"), implode(null, $html_tt_information)); |
| | 616 | |
| | 617 | |
| | 618 | /* |
| | 619 | * TT's data information |
| | 620 | */ |
| | 621 | $html_tt_data_properties = array(); |
| | 622 | |
| | 623 | // max incoming data |
| | 624 | $title = _("Max incoming data"); |
| | 625 | $help = _("The maximum number of bytes of data this token can receive"); |
| | 626 | $data = InterfaceElements::generateInputText("tt_" . $tt_id . "_max_incoming", $this->getMaxIncomingData(), "tt_max_incoming_input"); |
| | 627 | $html_tt_data_properties[] = InterfaceElements::generateAdminSectionContainer("tt_max_incoming", $title, $data, $help); |
| | 628 | |
| | 629 | // max outoing data |
| | 630 | $title = _("Max outgoing data"); |
| | 631 | $help = _("The maximum number of bytes of data this token can send"); |
| | 632 | $data = InterfaceElements::generateInputText("tt_" . $tt_id . "_max_outgoing", $this->getMaxOutgoingData(), "tt_max_outgoing_input"); |
| | 633 | $html_tt_data_properties[] = InterfaceElements::generateAdminSectionContainer("tt_max_outgoing", $title, $data, $help); |
| | 634 | |
| | 635 | // max total data |
| | 636 | $title = _("Max total data"); |
| | 637 | $help = _("The maximum total number of bytes this token can send and receive"); |
| | 638 | $data = InterfaceElements::generateInputText("tt_" . $tt_id . "_max_total_data", $this->getMaxTotalData(), "tt_max_total_data_input"); |
| | 639 | $html_tt_data_properties[] = InterfaceElements::generateAdminSectionContainer("tt_max_data", $title, $data, $help); |
| | 640 | |
| | 641 | // Build section |
| | 642 | $html .= InterfaceElements::generateAdminSectionContainer("tt_data", _("Data limits"), implode(null, $html_tt_data_properties)); |
| | 643 | |
| | 644 | |
| | 645 | /* |
| | 646 | * TT's data information |
| | 647 | */ |
| | 648 | $html_tt_duration_properties = array(); |
| | 649 | |
| | 650 | // max incoming data |
| | 651 | $title = _("Max connection duration"); |
| | 652 | $help = _("The length of a single connection."); |
| | 653 | $data = InterfaceElements::generateInputText("tt_" . $tt_id . "_max_conn_duration", $this->getMaxConnectionDuration(), "tt_max_conn_duration_input"); |
| | 654 | $html_tt_duration_properties[] = InterfaceElements::generateAdminSectionContainer("tt_max_conn_duration", $title, $data, $help); |
| | 655 | |
| | 656 | // max outoing data |
| | 657 | $title = _("Max usage"); |
| | 658 | $help = _("The maximum time a user can be online (counting only when used). Allows access by the hour."); |
| | 659 | $data = InterfaceElements::generateInputText("tt_" . $tt_id . "_max_usage", $this->getMaxUsageDuration(), "tt_max_usage_input"); |
| | 660 | $html_tt_duration_properties[] = InterfaceElements::generateAdminSectionContainer("tt_max_usage", $title, $data, $help); |
| | 661 | |
| | 662 | // max total data |
| | 663 | $title = _("Max wall clock duration"); |
| | 664 | $help = _("The maximum amount of time a token can be used, starting count when first used. Allows weekly, daily tokens."); |
| | 665 | $data = InterfaceElements::generateInputText("tt_" . $tt_id . "_max_wc_duration", $this->getMaxWallClockDuration(), "tt_max_wc_duration_input"); |
| | 666 | $html_tt_duration_properties[] = InterfaceElements::generateAdminSectionContainer("tt_max_wc_duration", $title, $data, $help); |
| | 667 | |
| | 668 | // max total data |
| | 669 | $title = _("Max age"); |
| | 670 | $help = _("The maximum age before a token expires, starting count when issued."); |
| | 671 | $data = InterfaceElements::generateInputText("tt_" . $tt_id . "_max_age", $this->getMaxAge(), "tt_max_age_input"); |
| | 672 | $html_tt_duration_properties[] = InterfaceElements::generateAdminSectionContainer("tt_max_age", $title, $data, $help); |
| | 673 | |
| | 674 | // Build section |
| | 675 | $html .= InterfaceElements::generateAdminSectionContainer("tt_duration", _("Duration limits"), implode(null, $html_tt_duration_properties), |
| | 676 | _("For these values, any postgresql interval is acceptable, for example '1 day', '1 month', '3 week'")); |
| | 677 | |
| | 678 | return $html; |
| | 679 | } |
| | 680 | |
| 563 | | /* $db = AbstractDb::getObject(); |
| 564 | | $currentUser = self :: getCurrentUser(); |
| 565 | | if (Security::hasPermission(Permission::P('NETWORK_PERM_EDIT_ANY_USER'), $this->getNetwork())) { |
| 566 | | // Account status |
| 567 | | $name = "user_" . $this->getId() . "_accountstatus"; |
| 568 | | $status = FormSelectGenerator::getResult($name, null); |
| 569 | | $this->setAccountStatus($status); |
| 570 | | } |
| 571 | | |
| 572 | | if ($this == $currentUser || Security::requirePermission(Permission::P('NETWORK_PERM_EDIT_ANY_USER'), $this->getNetwork())) { |
| 573 | | // Username |
| 574 | | $name = "user_" . $this->getId() . "_username"; |
| 575 | | $this->setUsername($_REQUEST[$name]); |
| 576 | | |
| 577 | | // Change password |
| 578 | | $nameOldpassword = "user_" . $this->getId() . "_oldpassword"; |
| 579 | | $nameNewpassword = "user_" . $this->getId() . "_newpassword"; |
| 580 | | $nameNewpasswordAgain = "user_" . $this->getId() . "_newpassword_again"; |
| 581 | | if($_REQUEST[$nameNewpassword]!=null){ |
| 582 | | if ($this == $currentUser && $this->getPasswordHash() != User::passwordHash($_REQUEST[$nameOldpassword])) { |
| 583 | | throw new Exception(_("Wrong password.")); |
| 584 | | } |
| 585 | | if ($_REQUEST[$nameNewpassword] != $_REQUEST[$nameNewpasswordAgain]){ |
| 586 | | throw new Exception(_("Passwords do not match.")); |
| 587 | | } |
| 588 | | $this->setPassword($_REQUEST[$nameNewpassword]); |
| 589 | | } |
| 590 | | |
| 591 | | // Pretend there is only one |
| 592 | | $profiles = $this->getAllProfiles(); |
| 593 | | if(!empty($profiles)) { |
| 594 | | $current_profile = $profiles[0]; |
| 595 | | if($current_profile != null) { |
| 596 | | $current_profile->processAdminUI(); |
| 597 | | $name = "user_" . $this->getId() . "_delete_profile_".$current_profile->getId(); |
| 598 | | if(!empty($_REQUEST[$name])) { |
| 599 | | $errmsg=null; |
| 600 | | $current_profile->delete($errmsg); |
| 601 | | } |
| 602 | | } |
| 603 | | } |
| 604 | | else { |
| 605 | | $name = "user_" . $this->getId() . "_add_profile"; |
| 606 | | if(!empty($_REQUEST[$name])) { |
| 607 | | // Get the list of profile templates for the users' network |
| 608 | | $profile_templates = ProfileTemplate::getAllProfileTemplates($this->getNetwork()); |
| 609 | | if(!empty($profile_templates)) { |
| 610 | | // Create a blank profile and link it to the user |
| 611 | | $current_profile = Profile::createNewObject(null, $profile_templates[0]); |
| 612 | | $this->addProfile($current_profile); |
| 613 | | } |
| 614 | | } |
| 615 | | |
| 616 | | } |
| 617 | | |
| 618 | | }*/ |
| | 682 | Security::requirePermission(Permission::P('NETWORK_PERM_EDIT_NETWORK_CONFIG'), $this->getNetwork()); |
| | 683 | $tt_id = $this->getId(); |
| | 684 | |
| | 685 | // template description |
| | 686 | $name = "tt_" . $tt_id . "_description"; |
| | 687 | $this->setDescription($_REQUEST[$name]); |
| | 688 | |
| | 689 | // is reusable |
| | 690 | $name = "tt_" . $tt_id . "_reusable"; |
| | 691 | $this->setIsReusable(empty ($_REQUEST[$name]) ? false : true); |
| | 692 | |
| | 693 | // max incoming data |
| | 694 | $name = "tt_" . $tt_id . "_max_incoming"; |
| | 695 | $this->setMaxIncomingData($_REQUEST[$name]); |
| | 696 | |
| | 697 | // max outoing data |
| | 698 | $name = "tt_" . $tt_id . "_max_outgoing"; |
| | 699 | $this->setMaxOutgoingData($_REQUEST[$name]); |
| | 700 | |
| | 701 | // max total data |
| | 702 | $name = "tt_" . $tt_id . "_max_total_data"; |
| | 703 | $this->setMaxTotalData($_REQUEST[$name]); |
| | 704 | |
| | 705 | // max incoming data |
| | 706 | $name = "tt_" . $tt_id . "_max_conn_duration"; |
| | 707 | $this->setMaxConnectionDuration($_REQUEST[$name]); |
| | 708 | |
| | 709 | // max outoing data |
| | 710 | $name = "tt_" . $tt_id . "_max_usage"; |
| | 711 | $this->setMaxUsageDuration($_REQUEST[$name]); |
| | 712 | |
| | 713 | // max total data |
| | 714 | $name = "tt_" . $tt_id . "_max_wc_duration"; |
| | 715 | $this->setMaxWallClockDuration($_REQUEST[$name]); |
| | 716 | |
| | 717 | // max total data |
| | 718 | $name = "tt_" . $tt_id . "_max_age"; |
| | 719 | $this->setMaxAge($_REQUEST[$name]); |
| | 720 | |