Esempio n. 1
0
 public function processAdminUI()
 {
     $db = AbstractDb::getObject();
     $currentUser = self::getCurrentUser();
     if (Security::hasPermission(Permission::P('NETWORK_PERM_EDIT_ANY_USER'), $this->getNetwork())) {
         /* Account status */
         $name = "user_" . $this->getId() . "_accountstatus";
         $status = FormSelectGenerator::getResult($name, null);
         $this->setAccountStatus($status);
     }
     if ($this == $currentUser || Security::requirePermission(Permission::P('NETWORK_PERM_EDIT_ANY_USER'), $this->getNetwork())) {
         /* Username */
         $name = "user_" . $this->getId() . "_username";
         $this->setUsername($_REQUEST[$name]);
         /* Change password */
         $nameOldpassword = "******" . $this->getId() . "_oldpassword";
         $nameNewpassword = "******" . $this->getId() . "_newpassword";
         $nameNewpasswordAgain = "user_" . $this->getId() . "_newpassword_again";
         if ($_REQUEST[$nameNewpassword] != null) {
             if ($this == $currentUser && $this->getPasswordHash() != User::passwordHash($_REQUEST[$nameOldpassword])) {
                 throw new Exception(_("Wrong password."));
             }
             if ($_REQUEST[$nameNewpassword] != $_REQUEST[$nameNewpasswordAgain]) {
                 throw new Exception(_("Passwords do not match."));
             }
             $this->setPassword($_REQUEST[$nameNewpassword]);
         }
         // Pretend there is only one
         $profiles = $this->getAllProfiles();
         if (!empty($profiles)) {
             $current_profile = $profiles[0];
             if ($current_profile != null) {
                 $current_profile->processAdminUI();
                 $name = "user_" . $this->getId() . "_delete_profile_" . $current_profile->getId();
                 if (!empty($_REQUEST[$name])) {
                     $errmsg = null;
                     $current_profile->delete($errmsg);
                 }
             }
         } else {
             $name = "user_" . $this->getId() . "_add_profile";
             if (!empty($_REQUEST[$name])) {
                 // Get the list of profile templates for the users' network
                 $profile_templates = ProfileTemplate::getAllProfileTemplates($this->getNetwork());
                 if (!empty($profile_templates)) {
                     // Create a blank profile and link it to the user
                     $current_profile = Profile::createNewObject(null, $profile_templates[0]);
                     $this->addProfile($current_profile);
                 }
             }
         }
     }
 }