public static function deleteUser(GcrMhrUser $mhr_user_deleted)
 {
     global $CFG;
     $mhr_user_obj = $mhr_user_deleted->getObject();
     $username_array = explode('.', $mhr_user_obj->username);
     $mhr_user_obj->username = $username_array[0];
     $mhr_user = new GcrMhrUser($mhr_user_obj, $mhr_user_deleted->getApp());
     foreach ($CFG->current_app->getMnetEschools() as $eschool) {
         $mdl_user = $mhr_user->getUserOnEschool($eschool);
         if ($mdl_user) {
             $params = array($mdl_user->getObject()->id);
             $result = self::executeWebServiceRequest($eschool, 'moodle_user_delete_users', $params);
         }
     }
 }
        // we only give site admin privilege to those on home who are
        // institution admins, while everyone gets the eschool admin role
        $admin = 1;
    }
    $temp_password = GcrEschoolTable::generateRandomString(12);
    $new_user_credentials = $institution->buildUserCredentials($current_user_obj->username, $temp_password);
    $params = array('id' => gcr::autoNumber, 'password' => $new_user_credentials->password, 'salt' => $new_user_credentials->salt, 'active' => 1, 'admin' => $admin, 'firstname' => $current_user_obj->firstname, 'lastname' => $current_user_obj->lastname, 'email' => $current_user_obj->email, 'quota' => 52428800, 'passwordchange' => 1, 'username' => $current_user_obj->username);
    $mhr_user = $institution->createUser($params);
    if ($mhr_user) {
        $mhr_user_obj = $mhr_user->getObject();
        $url = $institution->setupAutoLogin($current_user_obj->username, $temp_password, 60);
    }
} else {
    $mhr_user = new GcrMhrUser($mhr_user_obj, $institution);
}
// Add user to home mhr_institution as an admin
if ($current_user_obj->email == $mhr_user_obj->email) {
    $user_app = $mhr_user->getApp();
    $mhr_usr_institution = $mhr_user->getMhrUsrInstitutionRecords($user_app->getMhrInstitution());
    if (!$mhr_usr_institution) {
        $mhr_user->addMhrInstitutionMembership();
        $user_app->updateMhrTable('usr_institution', array('admin' => '1'), array('usr' => $mhr_user_obj->id, 'institution' => gcr::maharaInstitutionName));
    }
}
if (!$url) {
    $url = $app->getAppUrl();
    if ($app->isMoodle()) {
        $url .= '?transfer=' . $institution->getShortName();
    }
}
redirect($url);