protected function createBucket(GcrUserStorageS3Account $account)
 {
     $app = $this->app->getInstitution();
     $this->bucket = $app->getShortName() . '-' . strtolower(GcrEschoolTable::generateRandomString(25));
     $create_bucket_response = $this->api->create_bucket($this->bucket, AmazonS3::REGION_US_E1);
     // Provided that the bucket was created successfully...
     if ($create_bucket_response->isOK()) {
         /* Since AWS follows an "eventual consistency" model, sleep and poll
            until the bucket is available. */
         $exists = $this->api->if_bucket_exists($this->bucket);
         $counter = 0;
         while (!$exists) {
             // Not yet? Sleep for 1 second, then check again
             sleep(1);
             $exists = $this->api->if_bucket_exists($this->bucket);
             if ($counter++ > 15) {
                 $this->app->gcError('Bucket Creation Timed Out', 'gcdatabaseerror');
             }
         }
         $user_storage_s3 = new GcrUserStorageS3();
         $user_storage_s3->setAppId($app->getShortName());
         $user_storage_s3->setBucketName($this->bucket);
         $user_storage_s3->setAccountId($account->getId());
         $user_storage_s3->save();
     } else {
         $this->app->gcError('AWS Bucket Creation Failed', 'gcdatabaseerror');
     }
 }
 protected function generateSignatureWithoutParameters()
 {
     if (!($app_key = $this->app->getConfigVar(self::SIGN_CONFIG_VAR))) {
         $app_key = GcrEschoolTable::generateRandomString(15);
         $this->app->setConfigVar(self::SIGN_CONFIG_VAR, $app_key);
     }
     $plain_text_string = $app_key . self::SIGNED_REQUEST_SALT;
     return md5($plain_text_string);
 }
 public function logout()
 {
     global $USER;
     if (isset($_COOKIE['gc_eschools'])) {
         $short_names = explode(';', $_COOKIE['gc_eschools']);
         foreach ($short_names as $short_name) {
             if ($short_name == '') {
                 continue;
             }
             if ($eschool = Doctrine::getTable('GcrEschool')->findOneByShortName($short_name)) {
                 if ($mdl_user = $this->getUserOnEschool($eschool)) {
                     $sql = 'select id, timecreated from ' . $eschool->getShortName() . '.mdl_sessions where userid = ? order by timecreated DESC';
                     $mdl_session = $eschool->gcQuery($sql, array($mdl_user->getObject()->id), true);
                     if ($mdl_session) {
                         $eschool->updateMdlTable('sessions', array('sid' => time() . 'logout' . GcrEschoolTable::generateRandomString(15)), array('id' => $mdl_session->id));
                     }
                 }
             }
         }
         setcookie('gc_eschools', '', time() - 65536, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly'));
     }
     $USER->logout();
 }
 public function executeCreate(sfWebRequest $request)
 {
     global $CFG;
     $CFG->current_app->requireMahara();
     $current_user = $CFG->current_app->getCurrentUser();
     if (!$current_user->getRoleManager()->HasPrivilege('GCUser')) {
         $CFG->current_app->gcError("Unauthorized attempt to access eschool/create.", 'gcpageaccessdenied');
     }
     $this->formErrors = array();
     $this->eschoolForm = new GcrEschoolForm();
     $form = $request->getPostParameters();
     // validate form values
     $this->validateShortName($form['short_name']);
     if (!GcrEschoolTypeTable::validateEschoolType($form['eschool_type'])) {
         $this->formErrors['eschool_type'] = 'eSchool type is invalid.';
     }
     // make an address object to insert in to the address table for the address submitted
     $addressObject = new GcrAddress();
     $addressObject->setStreet1($form['street1']);
     $addressObject->setStreet2($form['street2']);
     $addressObject->setCity($form['city']);
     $addressObject->setState($form['state']);
     $addressObject->setCountry($form['country']);
     $addressObject->setZipcode($form['zipcode']);
     // Try to add the eschool's address to the address table
     $addressObject->save();
     // make a person object to insert in to the person table for contact 1
     $personObject = new GcrPerson();
     $personObject->setFirstName($form['first_name']);
     $personObject->setLastName($form['last_name']);
     $personObject->setAddress($addressObject->getId());
     $personObject->setPhone1($form['phone1']);
     $personObject->setPhone2($form['phone2']);
     $personObject->setEmail($form['email']);
     // Try to add the contact 1 to the person table
     $personObject->save();
     // make a person object to insert in to the person table for contact 2
     $person2Object = new GcrPerson();
     $person2Object->setFirstName($form['first_name_2']);
     $person2Object->setLastName($form['last_name_2']);
     $person2Object->setAddress($addressObject->getId());
     $person2Object->setPhone1($form['phone1_2']);
     $person2Object->setPhone2($form['phone2_2']);
     $person2Object->setEmail($form['email_2']);
     // try to add the contact 2 to the person table
     $person2Object->save();
     // make an array of values to validate as the eschool form
     $eschoolFields = array('id' => '', 'full_name' => $form['full_name'], 'short_name' => strtolower($form['short_name']), 'external_url' => $form['external_url'], 'logo' => $CFG->current_app->getLogo(), 'suspended' => '', 'can_sell' => '', 'contact1' => $personObject->getId(), 'contact2' => $person2Object->getId(), 'address' => $addressObject->getId(), 'eschool_type' => $form['eschool_type'], 'eschool_creator' => $CFG->current_app->getId(), 'admin_password' => GcrEschoolTable::generateAdminPassword(), 'password_salt' => GcrEschoolTable::generateRandomString(), 'creation_date' => time(), 'organization_id' => $CFG->current_app->getId(), 'visible' => '1', 'street1' => $form['street1'], 'street2' => $form['street2'], 'city' => $form['city'], 'state' => $form['state'], 'country' => $form['country'], 'zipcode' => $form['zipcode'], 'first_name' => $form['first_name'], 'last_name' => $form['last_name'], 'phone1' => $form['phone1'], 'phone2' => $form['phone2'], 'email' => $form['email'], 'first_name_2' => $form['first_name_2'], 'last_name_2' => $form['last_name_2'], 'phone1_2' => $form['phone1_2'], 'phone2_2' => $form['phone2_2'], 'email_2' => $form['email_2'], '_csrf_token' => $form['_csrf_token']);
     // try to add the eschool data to the eschool table
     if (!($eschoolRecord = $this->processForm($eschoolFields, $this->eschoolForm, $request->getFiles()))) {
         $this->formErrors['eschoolRecord'] = 'Some Field(s) Have Missing or Incorrect Data';
     }
     // If the eschool record was saved, we need to also add a trial record for it
     if (count($this->formErrors) == 0) {
         // create the eschool if everything is valid
         $eschoolRecord->create();
         $this->emailNewEschoolGC($eschoolRecord, $personObject, $person2Object);
         // send user to the newly created eschool
         $this->redirect($eschoolRecord->getUrl());
     } else {
         $addressObject->delete();
         $personObject->delete();
         $person2Object->delete();
         $this->getResponse()->setTitle('Create a Trial eSchool');
         $this->setTemplate('new');
     }
 }
print number_format($item1->getAmount(), 2);
?>
 fee)<br />
        <input type="radio" name="purchase_item" id="credits2" value="<?php 
print $item2->getShortName();
?>
" />
                2 Credit Course ($<?php 
print number_format($item2->getAmount(), 2);
?>
 fee)<br />
        <input type="radio" name="purchase_item" id="credits3" value="<?php 
print $item3->getShortName();
?>
" />
                3 Credit Course ($<?php 
print number_format($item3->getAmount(), 2);
?>
 fee)<br /><br />
        <input type="hidden" name="token" id="token" value="<?php 
print GcrEschoolTable::generateRandomString();
?>
" />
        NOTE: Selecting the wrong number of credits could result in a delay of the issuing of your transcript.<br/><br/>
        Contact <?php 
print mail_to("*****@*****.**", "*****@*****.**", array('encode' => 'true', 'class' => 'email_link'));
?>
        with any questions.<br/><br/>
        <input type="submit" class="button" value="Continue" />
    </form>
</div>
 public static function generateToken()
 {
     return GcrEschoolTable::generateRandomString() . GcrEschoolTable::generateRandomString();
 }
 public function executeProcess(sfWebRequest $request)
 {
     global $CFG;
     $this->formErrors = array();
     $this->institutionForm = new GcrTrialApplicationForm();
     $form = $request->getPostParameters();
     // make an address object to insert in to the address table for the address submitted
     $addressObject = new GcrAddress();
     $addressObject->setStreet1($form['street1']);
     $addressObject->setStreet2($form['street2']);
     $addressObject->setCity($form['city']);
     $addressObject->setState($form['state']);
     $addressObject->setCountry($form['country']);
     $addressObject->setZipcode($form['zipcode']);
     // Try to add the eschool's address to the address table
     $addressObject->save();
     // make a person object to insert in to the person table for contact 1
     $personObject = new GcrPerson();
     $personObject->setFirstName($form['first_name']);
     $personObject->setLastName($form['last_name']);
     $personObject->setAddress($addressObject->getId());
     $personObject->setPhone1($form['phone1']);
     $personObject->setPhone2($form['phone2']);
     $personObject->setEmail($form['email']);
     // Try to add the contact 1 to the person table
     $personObject->save();
     $verify = GcrEschoolTable::generateRandomString();
     // make an array of values to validate as the institution form
     $institutionFields = array('id' => '', 'contact' => $personObject->getId(), 'address' => $addressObject->getId(), 'verify_hash' => $verify, 'street1' => $form['street1'], 'street2' => $form['street2'], 'city' => $form['city'], 'state' => $form['state'], 'country' => $form['country'], 'zipcode' => $form['zipcode'], 'first_name' => $form['first_name'], 'last_name' => $form['last_name'], 'phone1' => $form['phone1'], 'phone2' => $form['phone2'], 'email' => $form['email'], '_csrf_token' => $form['_csrf_token']);
     // try to add the eschool data to the eschool table
     if (!($trial_application_record = $this->processForm($institutionFields, $this->institutionForm, $request->getFiles()))) {
         $this->formErrors['institutionRecord'] = 'Some Field(s) Have Missing or Incorrect Data';
     }
     // If the institution record was saved, we send an email to verify the user before creating the new institution
     if (count($this->formErrors) == 0) {
         //create Constant Contact entry for user of newly created eschool
         $this->ccCreateContact($form);
         if ($CFG->current_app->hasPrivilege('GCUser')) {
             // skip email verification is this is a gc admin
             $this->redirect($CFG->current_app->getUrl() . '/institution/verify?aid=' . $trial_application_record->getId());
         }
         $this->redirect($CFG->current_app->getUrl() . '/institution/sendVerificationEmail?id=' . $trial_application_record->getId());
     } else {
         $addressObject->delete();
         $personObject->delete();
         $this->getResponse()->setTitle('Create a Trial Platform');
         $this->setTemplate('new');
     }
 }
if ($app->isMoodle()) {
    $institution = $app->getInstitution();
} else {
    $institution = $app;
}
$current_user_obj = $current_user->getObject();
$mhr_user_obj = $institution->getMhrUserByUsername($current_user_obj->username);
// if the user's account doesn't exist on the institution (check for email address)
if (!$mhr_user_obj) {
    $admin = 0;
    if ($role_manager->hasPrivilege('GCUser')) {
        // 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) {
<?php

require_once dirname(__FILE__) . '/../config/ProjectConfiguration.class.php';
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
sfContext::createInstance($configuration);
$databaseManager = new sfDatabaseManager($configuration);
$databaseManager->loadConfiguration();
if (!($conn = Doctrine_Manager::getInstance()->getCurrentConnection())) {
    echo "Could not connect to Database.";
    die;
}
foreach (GcrInstitutionTable::getInstitutions() as $institution) {
    $password_salt = $institution->getPasswordSalt();
    if ($password_salt == '') {
        $salt = GcrEschoolTable::generateRandomString();
        $institution->setPasswordSalt($salt);
        $institution->save();
        print "\n" . $institution->getShortName() . ': salt created';
    }
}
 public function executeMembershipPurchase(sfWebRequest $request)
 {
     global $CFG;
     $this->authorizePurchaseOnInstitution();
     $form = $request->getPostParameters();
     if (!$request->isMethod(sfRequest::POST)) {
         $this->redirect($CFG->current_app->getUrl());
     }
     $form = $request->getPostParameters();
     if ($form['bill_cycle'] && $CFG->current_app->isMembershipAllowed($form['bill_cycle'])) {
         $this->form = new GcrPurchaseForm();
         $this->form->setDefaults(array('purchase_type' => 'membership', 'purchase_type_id' => $CFG->current_app->getShortName(), 'purchase_type_eschool_id' => $CFG->current_app->getShortName(), 'bill_cycle' => $form['bill_cycle'], 'purchase_token' => GcrEschoolTable::generateRandomString()));
         // set up object which hold info about the purchase item to display on form
         $this->purchaseObject = new StdClass();
         $this->hydratePurchaseObject($this->purchaseObject, 'membership', $CFG->current_app->getShortName(), $CFG->current_app->getShortName(), $form['bill_cycle']);
         $this->getResponse()->setTitle('eClassroom Purchase');
     } else {
         $this->redirect($CFG->current_app->getUrl());
     }
 }
 public function create()
 {
     if (!($institution = $this->getInstitution())) {
         global $CFG;
         $CFG->current_app->gcError('Creator institution for new eSchool ' . $this->short_name . ' not found', 'gcdatabaseerror');
     } else {
         if (!($mhr_owner = $this->getInstitution()->getOwnerUser())) {
             global $CFG;
             $CFG->current_app->gcError('Institution owner of ' . $institution->getShortName() . ' not found', 'gcdatabaseerror');
         }
     }
     GcrDatabaseAccessPostgres::createSchema($this);
     $eschool = $this->getAppType()->getTemplateObject();
     // add the template's salt to the list of historical salts for the new eschool
     $salt_history = new GcrEschoolSaltHistory();
     $salt_history->setEschoolid($this->id);
     $salt_history->setSalt($eschool->password_salt);
     $salt_history->save();
     // transfer all old salts from template to new eschool
     if ($old_salts = Doctrine::getTable('GcrEschoolSaltHistory')->findByEschoolid($eschool->id)) {
         foreach ($old_salts as $salt_record) {
             $salt_history = new GcrEschoolSaltHistory();
             $salt_history->setEschoolid($this->id);
             $salt_history->setSalt($salt_record->salt);
             $salt_history->save();
         }
     }
     // change the title name of the eschool from Eschool Template to whatever its called
     $this->updateMdlTable('course', array('fullname' => $this->full_name, 'shortname' => $this->short_name), array('id' => 1));
     // change the self-reference entry in mdl_mnet_host to the new eschool's info
     $this->updateMdlTable('mnet_host', array('name' => $this->full_name), array('wwwroot' => $this->getAppUrl()));
     // change the gcadmin username and password to the generated one.
     $password = md5($this->admin_password);
     $this->updateMdlTable('user', array('password' => $password), array('username' => "gc4{$this->short_name}admin"));
     // Change the web services token for gc4<schema>admin to a new uniue value.
     $this->updateMdlTable('external_tokens', array('token' => md5(uniqid(rand(), 1))), array('userid' => $this->getGCAdminUser()->getObject()->id));
     $this->setMnetConnection();
     // Remove mnet connection to template's institution (if it exists)
     $template_institution = $eschool->getInstitution();
     if ($template_institution) {
         $this->removeMnetConnection($template_institution);
     }
     $this->setUser($mhr_owner, array('eschooladmin'));
     // set unique mdl_config vars
     $this->setConfigVar('calendar_exportsalt', GcrEschoolTable::generateRandomString(60));
     $this->setConfigVar('alternateloginurl', $this->getUrl() . '/eschool/login');
     $this->setConfigVar('resource_secretphrase', GcrEschoolTable::generateRandomString(60));
     $this->setConfigVar('calendar_exportsalt', GcrEschoolTable::generateRandomString(20));
     $this->setConfigVar('siteidentifier', GcrEschoolTable::generateRandomString(32) . $this->getDomain());
     $this->setConfigVar('cronremotepassword', GcrEschoolTable::generateRandomString(20));
     $this->setConfigVar('noreplyaddress', $this->getDomain());
     $this->setConfigVar('registerauth', 'email');
     $this->setMdlCacheSettings();
     $institution->createMnetConnection($this);
 }
 public function executeCreatePaymentInfo(sfWebRequest $request)
 {
     global $CFG;
     $CFG->current_app->requireLogin();
     $this->current_user = $CFG->current_app->getCurrentUser();
     $role_manager = $this->current_user->getRoleManager();
     $form = $request->getPostParameters();
     if ($form['id'] != '') {
         if (!$role_manager->hasPrivilege('GCUser')) {
             $CFG->current_app->gcError('Non-privileged attempted access to edit ' . $form['user_eschool_id'] . ' createPaymentInfo with user ID ' . $form['user_id'], 'gcpageaccessdenied');
         }
         if (!($credentials = Doctrine::getTable('GcrPayoffCredentials')->find($form['id']))) {
             $CFG->current_app->gcError('Credentials with ID ' . $form['id'] . ' does not exist.', 'gcdatabaseerror');
         }
         $this->payoff_credentials_form = new GcrPayoffCredentialsForm($credentials);
     } else {
         $this->payoff_credentials_form = new GcrPayoffCredentialsForm();
     }
     $institution = GcrInstitutionTable::getInstitution($form['user_eschool_id']);
     if (!($user = $institution->getUserById($form['user_id']))) {
         $CFG->current_app->gcError('Local User with ID ' . $form['user_id'] . ' on eschool ' . $institution->getShortName() . ' does not exist', 'gcdatabaseerror');
     }
     $account_manager = $user->getAccountManager();
     // If this isn't a gc admin, we need to check that they aren't trying to change someone else's credentials
     if (!$role_manager->hasPrivilege('GCUser')) {
         if (!$this->current_user->isSameUser($user)) {
             $CFG->current_app->gcError('Non-privileged attempted access to ' . $form['user_eschool_id'] . ' createPaymentInfo with user ID ' . $form['user_id'], 'gcpageaccessdenied');
         }
         if ($account_manager->usesChainedPayments()) {
             $CFG->current_app->gcError('User cannot change payoff credentials with chained payments enabled.', 'gcchainedpaymentcredentials');
         }
         $form['verify_status'] = 'unverified';
     } else {
         $form['verify_status'] = 'verified';
     }
     $form['verify_hash'] = GcrEschoolTable::generateRandomString();
     $this->payoff_credentials_form->bind($form);
     if ($this->payoff_credentials_form->isValid()) {
         $old_credentials = $account_manager->getPayoffCredentials();
         $payoff_credentials = $this->payoff_credentials_form->save();
         if ($old_credentials && $form['id'] == '') {
             $old_credentials->setVerifyStatus('expired');
             $old_credentials->save();
         }
         if ($form['verify_status'] == 'unverified') {
             $subject = 'Verification of Global Classroom Payment Information';
             $params = array('institution' => $institution, 'credentials' => $payoff_credentials);
             $email = new GcrUserEmailer('verify_payoff_credentials', $user, $subject, $params);
             $email->sendHtmlEmail();
         }
         $this->redirect($CFG->current_app->getUrl() . '/account/newPaymentInfo?id=' . $payoff_credentials->getId());
     }
     $this->setTemplate('paymentInfo');
 }
 public function mnetReplacement()
 {
     $this->start_time = time();
     $this->operation_description = 'MNET Connection Replacement';
     $this->max_failures_allowed = 10;
     $home = GcrEschoolTable::getHome();
     $token = GcrEschoolTable::generateRandomString();
     $home->setConfigVar('gc_replace_mnet_token' . $token, $token);
     foreach ($this->app_array as $institution) {
         if ($this->kill_operation) {
             exit;
         }
         $this->replaceMnetInstitution($institution, $token);
     }
     $home->deleteFromMdlTable('config', 'name', 'gc_replace_mnet_token' . $token);
     $this->close();
 }
 /**
  * executes paypal subscription form
  *
  * @param sfWebRequest $request_object
  * @param returns paypal form.
  * gets values from get method
  */
 public function executeSubscriptionPurchase(sfWebRequest $request)
 {
     global $CFG;
     $bill_cycle = "Month";
     $this->params = $request->getGetParameters();
     $this->form = new GcrPurchaseForm();
     // sets institution, product short names and product type
     $this->form->setDefaults(array('purchase_type' => 'subscription', 'purchase_type_id' => $this->params["institution"] . "~" . $this->params["type"], 'purchase_type_eschool_id' => $CFG->current_app->getShortName(), 'bill_cycle' => $bill_cycle, 'purchase_token' => GcrEschoolTable::generateRandomString()));
     // set up object which hold info about the purchase item to display on form
     $this->purchaseObject = new StdClass();
     $this->hydratePurchaseObject($this->purchaseObject, 'subscription', $this->params["institution"] . "~" . $this->params["type"], $CFG->current_app->getShortName(), $bill_cycle);
     $this->getResponse()->setTitle('Subscription Purchase');
 }
 public function createMnetConnection($eschool)
 {
     // we need this check to avoid duplicate mnet connections
     foreach ($this->getMnetEschools() as $mnet_eschool) {
         if ($eschool->getShortName() == $mnet_eschool->getShortName()) {
             return false;
         }
     }
     $mdl_mnet_host = $eschool->getSelfMdlMnetHostRecord();
     $temp_name = GcrEschoolTable::generateRandomString(50);
     $params = array('id' => gcr::autoNumber, 'instancename' => $temp_name, 'priority' => 1, 'institution' => gcr::maharaInstitutionName, 'authname' => 'xmlrpc');
     $this->insertIntoMhrTable('auth_instance', $params);
     $mhr_auth_instance = $this->selectFromMhrTable('auth_instance', 'instancename', $temp_name, true);
     $this->insertIntoMhrTable('auth_instance_config', array('instance' => $mhr_auth_instance->id, 'field' => 'theyautocreateusers', 'value' => 1));
     $this->insertIntoMhrTable('auth_instance_config', array('instance' => $mhr_auth_instance->id, 'field' => 'wessoout', 'value' => 1));
     $this->insertIntoMhrTable('auth_instance_config', array('instance' => $mhr_auth_instance->id, 'field' => 'wwwroot', 'value' => $mdl_mnet_host->wwwroot));
     $params = array('wwwroot' => $mdl_mnet_host->wwwroot, 'name' => $eschool->getFullName(), 'institution' => gcr::maharaInstitutionName, 'ipaddress' => $mdl_mnet_host->ip_address, 'publickey' => $mdl_mnet_host->public_key, 'publickeyexpires' => $mdl_mnet_host->public_key_expires, 'appname' => 'moodle');
     $this->insertIntoMhrTable('host', $params);
     $this->updateMhrTable('auth_instance', array('instancename' => $eschool->getFullName()), array('instancename' => $temp_name));
 }