示例#1
0
 public function Index()
 {
     $this->data['user'] = $this->checkLogin();
     $this->data['transaction'] = $this->data['user']->GetLastTransaction();
     if ($this->data['transaction']->Status == OpenSms::OPEN_TRANSACTION_STATUS_COMPLETED) {
         $this->setError("No pending transaction found", "voucher_index");
         OpenSms::redirectToAction('Index', 'Recharge', 'Account');
     }
     if (isset($_POST['pin'])) {
         if (empty($_POST['pin']) || empty($_POST['serialNumber'])) {
             $this->setError('Both PIN and serial number are required', 'voucher_index');
         } else {
             $card = OpenSms::loadModel('OpenSms_Model_Card', [0 => $_POST['serialNumber'], 1 => $_POST['pin']]);
             if ($card->IsValid) {
                 $result = $card->Load($this->data['user']->LoginId);
                 if ($result['success'] != true) {
                     $this->setError($result['message'], 'voucher_index');
                 } else {
                     $this->data['transaction']->Status = OpenSms::OPEN_TRANSACTION_STATUS_COMPLETED;
                     $this->data['transaction']->Save();
                     $this->setNotification("Your account has been credited with {$card->Unit} units. Thanks for your patronage", 'voucher_index');
                     OpenSms::redirectToAction('index', 'dashboard', 'dashboard');
                 }
             } else {
                 $this->setError('Invalid card information. Please try again', 'voucher_index');
             }
         }
     }
     $this->data['pageTitle'] = "Load Voucher";
     $this->renderTemplate();
 }
示例#2
0
 public function Load($loginId)
 {
     $success = TRUE;
     $sql = "select * from " . OpenSms::getTableName('usedCards') . " where cardId = '" . StringMethods::MakeSave($this->Id) . "';";
     $result = OpenSms_Helper_Db::executeReader($sql);
     foreach ($result as $r) {
         $success = FALSE;
         if ($loginId == $r->loginId) {
             $message = 'This card has already been used by you';
         } else {
             $message = 'This card has already been used';
         }
     }
     if ($success) {
         $sql = 'insert into ' . OpenSms::getTableName('usedCards') . ' (loginId, cardId) value("' . $loginId . '", "' . $this->Id . '");';
         //die($sql);
         $inserted = OpenSms_Helper_Db::executeNonQuery($sql);
         if ($inserted) {
             $user = OpenSms::loadModel("OpenSms_Model_User", [0 => $loginId]);
             $user->Balance += $this->Unit;
             $user->Save();
             $message = 'Your account has been credited with ' . $this->Unit . ' SMS unit';
         }
     }
     return array('success' => $success, 'message' => $message);
 }
示例#3
0
 public function Commit()
 {
     if ($this->Committed) {
         return 'This transaction has already been committed';
     }
     if ($this->Status != OpenSms::OPEN_TRANSACTION_STATUS_COMPLETED) {
         return 'Cannot commit a transaction that is not completed.
                 Please change the status of the transaction to completed and try again';
     }
     $user = OpenSms::loadModel('OpenSms_Model_User', [0 => $this->LoginId]);
     if (empty($user->LoginId)) {
         return 'Invalid username';
     }
     switch ($this->Type) {
         case OpenSms::OPEN_TRANSACTION_TYPE_CREDIT:
             $user->Balance += $this->Unit;
             break;
         case OpenSms::OPEN_TRANSACTION_TYPE_DEBIT:
             if ($user->Balance < $this->Amount) {
                 return $user->Name . " does not have up to " . $this->Amount;
             }
             $user->Balance -= $this->Amount;
             break;
         default:
             return 'Invalid transaction type';
             break;
     }
     $this->Committed = true;
     $user->Save();
     return $this->Save();
 }
示例#4
0
 public function GetGroups()
 {
     $groups = array();
     $sql = "select * from `" . OpenSms::getTableName('group') . "` where loginId = '" . StringMethods::MakeSave($this->LoginId) . "' ORDER BY `id` DESC";
     $result = OpenSms_Helper_Db::executeReader($sql);
     foreach ($result as $r) {
         $g = OpenSms::loadModel("OpenSms_Model_Group");
         $g->Id = $r->id;
         $g->Name = $r->name;
         $g->LoginId = $r->loginId;
         $g->Description = $r->description;
         $g->GroupExits = !empty($r->id);
         $groups[] = $g;
     }
     return $groups;
 }
示例#5
0
 public function Delete($id)
 {
     $this->checkLogin();
     $returnUrl = isset($_REQUEST['returnUrl']) ? $_REQUEST['returnUrl'] : '';
     $tran = OpenSms::loadModel('OpenSms_Model_Transaction', [0 => $id]);
     if (!isset($tran->LoginId)) {
         return 'Invalid transaction Id';
     }
     $result = $tran->Delete();
     if (!$result) {
         $this->setError($result, 'delete_transaction');
     }
     if (empty($returnUrl)) {
         OpenSms::redirectToAction('Index');
     }
     OpenSms::redirect($returnUrl);
 }
示例#6
0
 public function loadModel($model_name, array $param = null)
 {
     return OpenSms::loadModel($model_name, $param);
 }
示例#7
0
 function GetMessages()
 {
     $sql = "select * from " . OpenSms::getTableName('sms') . " where bulkSMSId = '" . $this->Id . "';";
     $result = OpenSms_Helper_Db::executeReader($sql);
     $messages = array();
     foreach ($result as $r) {
         $message = OpenSms::loadModel('OpenSms_Model_Message');
         $message->Id = StringMethods::GetRaw($r->id);
         $message->BulkSMSId = StringMethods::GetRaw($r->bulkSMSId);
         $message->Number = StringMethods::GetRaw($r->number);
         $message->Message = StringMethods::GetRaw($r->message);
         $message->Sender = StringMethods::GetRaw($r->sender);
         $message->RefId = StringMethods::GetRaw($r->refId);
         $message->Status = StringMethods::GetRaw($r->status);
         $messages[] = $message;
     }
     return $messages;
 }