public static function userHasRole($user) { $user_obj = $user->getObject(); $app = $user->getApp(); $flag = false; $mhr_user = $user->getUserOnInstitution(); if ($mhr_user && $user_obj) { if ($app->isHome() || $mhr_user->getObject()->staff == 1) { $home = GcrInstitutionTable::getHome(); $home_user_obj = $home->selectFromMhrTable('usr', 'username', $user_obj->username, true); if ($home_user_obj) { $home_user = new GcrMhrUser($home_user_obj, $home); $mhr_usr_institution = $home_user->getMhrUsrInstitutionRecords($home->getMhrInstitution()); if ($mhr_usr_institution) { $flag = $mhr_usr_institution->staff == 1; } } } } return $flag; }
// 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);