public static function authorizeChainedPayment($course)
 {
     global $CFG;
     $flag = false;
     $current_user = $CFG->current_app->getCurrentUser();
     $course_institution = $course->getApp()->getInstitution();
     if ($course_institution->getAccountManager()->usesChainedPayments()) {
         $flag = true;
     } else {
         if ($seller = $course->getSeller()) {
             if ($seller->getAccountManager()->usesChainedPayments()) {
                 $flag = true;
             }
         }
     }
     if ($current_user->isRemoteUser()) {
         $user_institution = $current_user->getInstitution();
         if ($user_institution->getAccountManager()->usesChainedPayments()) {
             $commission = GcrCommissionTable::getCommission($user_institution, $course->getApp());
             if ($commission) {
                 $rate = $commission->getCommissionRate();
                 if ($rate > 0 && $rate <= 100) {
                     $flag = true;
                 }
             }
         }
     }
     return $flag;
 }
 public static function getCommissionFee($institution, $eschool)
 {
     $commission_fee = 0;
     $eschool_institution = $eschool->getInstitution();
     if ($institution->getId() != $eschool_institution->getid()) {
         $commission = GcrCommissionTable::getCommission($institution, $eschool);
         if ($commission) {
             $commission_rate = $commission->getCommissionRate();
             if ($commission_rate > 0 && $commission_rate <= 100) {
                 $commission_fee = $commission_rate;
             }
         }
     }
     return $commission_fee;
 }
 public function deleteEschoolFromSystemEntirely()
 {
     // remove all mnet connections with any maharas
     if ($this->isCreated()) {
         foreach ($this->getMnetInstitutions() as $institution) {
             $institution->removeMnetConnection($this);
         }
     }
     GcrDatabaseAccessPostgres::deleteSchemaFromSystem($this);
     // delete moodledata directory for eschool
     exec(escapeshellcmd('rm -R ' . gcr::moodledataDir . $this->short_name . '/'));
     // delete global eschool row for this eschool and related address and person table rows
     GcrCommissionTable::getInstance()->createQuery('c')->delete()->where('c.eschool_id = ?', $this->short_name)->execute();
     GcrEclassroomTable::getInstance()->createQuery('e')->delete()->where('e.eschool_id = ?', $this->short_name)->execute();
     // delete password salt history for this eschool
     $q = Doctrine_Query::create()->delete('GcrEschoolSaltHistory')->where('eschoolid = ?', $this->id);
     $q->execute();
     if ($address = $this->getAddressObject()) {
         $address->delete();
     }
     if ($contact1 = $this->getPersonObject()) {
         $contact1->delete();
     }
     if ($contact2 = $this->getPerson2Object()) {
         $contact2->delete();
     }
     $this->delete();
 }
 public function executeCreateCommission(sfWebRequest $request)
 {
     $this->authorizeUser();
     $form = $request->getPostParameters();
     if ($form['commission_rate'] > 0 && $form['commission_rate'] <= 100) {
         $institution = GcrInstitutionTable::getInstitution($form['institution']);
         $eschool = GcrEschoolTable::getEschool($form['eschool']);
         $existing_commission = GcrCommissionTable::getCommission($institution, $eschool);
         if ($existing_commission) {
             $existing_commission->setCommissionRate($form['commission_rate']);
             $existing_commission->save();
         } else {
             GcrCommissionTable::createCommission($institution, $eschool, $form['commission_rate']);
         }
     }
     $this->redirect(GcrEschoolTable::getHome()->getUrl() . '/homeadmin/commission');
 }
 public function deleteInstitutionFromSystemEntirely()
 {
     // delete each moodle instance owned by this institution
     foreach ($this->getEschools() as $eschool) {
         $eschool->deleteEschoolFromSystemEntirely();
     }
     // delete this institution's database schema
     GcrDatabaseAccessPostgres::deleteSchemaFromSystem($this);
     // delete moodledata directory for institution
     exec(escapeshellcmd('rm -R ' . gcr::moodledataDir . $this->short_name . '/'));
     // delete password salt history for this institution
     Doctrine_Query::create()->delete('GcrInstitutionSaltHistory')->where('institutionid = ?', $this->id)->execute();
     Doctrine_Query::create()->delete('GcrTrial t')->where('t.organization_id = ?', $this->id)->execute();
     GcrChainedPaymentTable::getInstance()->createQuery('c')->delete()->where('c.user_institution_id = ?', $this->short_name)->execute();
     GcrChatSessionTable::getInstance()->createQuery('c')->delete()->where('c.eschool_id = ?', $this->short_name)->execute();
     GcrChatSessionUsersTable::getInstance()->createQuery('c')->delete()->where('c.user_eschool_id = ?', $this->short_name)->execute();
     GcrChatSessionInviteTable::getInstance()->createQuery('c')->delete()->where('c.user_eschool_id = ?', $this->short_name)->orWhere('c.from_user_eschool_id = ?', $this->short_name)->execute();
     GcrCommissionTable::getInstance()->createQuery('c')->delete()->where('c.institution_id = ?', $this->short_name)->execute();
     GcrEclassroomTable::getInstance()->createQuery('e')->delete()->where('e.user_institution_id = ?', $this->short_name)->execute();
     GcrEschoolMonthlyDataTable::getInstance()->createQuery('e')->delete()->where('e.eschool_id = ?', $this->short_name)->execute();
     GcrUserMonthlyDataTable::getInstance()->createQuery('u')->delete()->where('u.user_institution_id = ?', $this->short_name)->execute();
     GcrPayoffTable::getInstance()->createQuery('p')->delete()->where('p.user_eschool_id = ?', $this->short_name)->execute();
     GcrPurchaseTable::deleteInstitutionRecords($this);
     GcrUserStorageS3Table::deleteBucket($this);
     if ($address = $this->getAddressObject()) {
         $address->delete();
     }
     if ($contact1 = $this->getPersonObject()) {
         $contact1->delete();
     }
     if ($contact2 = $this->getPerson2Object()) {
         $contact2->delete();
     }
     $this->delete();
 }