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');
     }
 }
 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');
     }
 }
 public function executeDoManualPayoff(sfWebRequest $request)
 {
     global $CFG;
     $CFG->current_app->requireLogin();
     $this->current_user = $CFG->current_app->getCurrentUser();
     if (!$this->current_user->getRoleManager()->hasPrivilege('GCUser')) {
         $CFG->current_app->gcError('Non-privileged attempted access to ' . $form['user_eschool_id'] . ' createWithdrawal with user ID ' . $form['user_id'], 'gcpageaccessdenied');
     }
     $form = $request->getPostParameters();
     if ($form['payoff_id'] != '') {
         if (!($this->payoff = Doctrine::getTable('GcrPayoff')->find($form['payoff_id']))) {
             $CFG->current_app->gcError('Payoff ID: ' . $form['id'] . ' does not exist', 'gcdatabaseerror');
         }
         if (!$this->payoff->isManual()) {
             $CFG->current_app->gcError('Payoff ID ' . $this->payoff->getId() . ' is not of type manual', 'gcdatabaseerror');
         }
         $this->institution = GcrInstitutionTable::getInstitution($this->payoff->getEschoolId());
         $user_institution = GcrInstitutionTable::getInstitution($this->payoff->getUserEschoolId());
         if (!($this->user = $user_institution->getUserById($this->payoff->getUserId()))) {
             $CFG->current_app->gcError('Local User with ID ' . $this->payoff->getUserId() . ' on eschool ' . $user_institution->getShortName() . ' does not exist', 'gcdatabaseerror');
         }
         if (!($this->credentials = $this->payoff->getCredentials())) {
             $CFG->current_app - gcError('Payoff ID ' . $this->payoff->getId() . ' has no credentials', 'gcdatabaserror');
         }
         if (!($purchase = $this->payoff->getPurchase())) {
             $CFG->current_app->gcError('Payoff ID ' . $this->payoff->getId() . ' purchase ID ' . $this->payoff->getPurchaseId() . ' does not exist.', 'gcdatabaseerror');
         }
     } else {
         $this->institution = GcrInstitutionTable::getInstitution($form['eschool_id']);
         $user_institution = GcrInstitutionTable::getInstitution($form['user_eschool_id']);
         if (!($this->user = $user_institution->getUserById($form['user_id']))) {
             $CFG->current_app->gcError('Local User with ID ' . $form['user_id'] . ' on eschool ' . $user_institution->getShortName() . ' does not exist', 'gcdatabaseerror');
         }
         if (!($this->credentials = $this->user->getAccountManager()->getPayoffCredentials())) {
             $CFG->current_app->gcError('No payoff credentials found for ' . $form['user_eschool_id'] . ' createWithdrawal with user ID ' . $form['user_id'], 'gcpageaccessdenied');
         }
         $this->payoff = new GcrPayoff();
         $this->payoff->setUserId($this->user->getObject()->id);
         $this->payoff->setUserEschoolId($form['user_eschool_id']);
         $this->payoff->setEschoolId($form['eschool_id']);
         $this->payoff->setPayoffStatus('completed');
         $this->payoff->setCredentialsId($this->credentials->getId());
     }
     unset($form['payoff_id']);
     $manual_payoff_form = new GcrPayoffManualForm();
     $manual_payoff_form->bind($form);
     if ($manual_payoff_form->isValid()) {
         $this->payoff->setAmount($form['amount']);
         $form['transtime'] = GcrPurchaseTable::convertDatetoTimestamp($form['transtime']);
         $this->payoff->setTransTime($form['transtime']);
         $this->payoff->setPayoffType($this->user->getAccountManager()->getPayoffType() . '_manual');
         $url = GcrEschoolTable::getHome()->getUrl() . '/account/view?eschool=' . $this->institution->getShortName() . '&user='******'type'] == 'check') {
             if ($this->payoff->isManualCheckPayment()) {
                 if (!($address = $this->payoff->getAddressObject())) {
                     $CFG->current_app->gcError('Payoff ID ' . $this->payoff->getId() . ' has non-existant address value');
                 }
             } else {
                 $address = new GcrAddress();
             }
             $address->setStreet1($form['street1']);
             $address->setStreet2($form['street2']);
             $address->setCity($form['city']);
             $address->setZipcode($form['zipcode']);
             $address->setState($form['state']);
             $address->setCountry($form['country']);
             $address->save();
             $this->payoff->setAddress($address->getId());
         }
         if ($form['description'] == '') {
             $description = 'Manual Account Withdrawal';
         } else {
             $description = $form['description'];
         }
         if ($purchase) {
             $purchase->setPurchaseTypeDescription($description);
             $purchase->setAmount($this->payoff->getAmount());
             $purchase->setTransTime($form['transtime']);
             $purchase->setProfileId($form['reference_id']);
             $purchase->save();
         } else {
             $purchase = $this->payoff->createPurchaseRecord($description, $form['transtime'], $form['reference_id']);
         }
         $this->payoff->save();
         $purchase->updateRelatedAccounting();
         $this->redirect($url);
     }
     $this->payoff_id = $this->payoff->getId();
     $this->payoff_form = $manual_payoff_form;
     $this->setTemplate('manualPayoff');
 }