示例#1
0
 public function Save()
 {
     //if installed goto dashboard
     if ($this->getSystemSetting(OpenSms::INSTALLATION_STATUS)) {
         OpenSms::redirectToAction('index', 'dashboard');
     }
     //var_dump($_POST);die();
     // CREATE
     $config = new SimpleXmlElement('<settings/>');
     $config->{OpenSms::VERSION} = $this->getSystemSetting(OpenSms::VERSION);
     $config->{OpenSms::SITE_NAME} = $this->getFormData(OpenSms::SITE_NAME);
     $config->{OpenSms::SITE_URL} = $this->getFormData(OpenSms::SITE_URL);
     $config->{OpenSms::DB_TYPE} = 'mysql';
     $config->{OpenSms::DB_HOST} = $this->getFormData(OpenSms::DB_HOST);
     $config->{OpenSms::DB_NAME} = $this->getFormData(OpenSms::DB_NAME);
     $config->{OpenSms::DB_TABLE_PREFIX} = $this->getFormData(OpenSms::DB_TABLE_PREFIX);
     $config->{OpenSms::DB_USERNAME} = $this->getFormData(OpenSms::DB_USERNAME);
     $config->{OpenSms::DB_PASSWORD} = $this->getFormData(OpenSms::DB_PASSWORD);
     $config->{OpenSms::DB_PASSWORD} = $this->getFormData(OpenSms::DB_PASSWORD);
     $config->{OpenSms::CURRENT_THEME_KEY} = $this->getFormData(OpenSms::CURRENT_THEME_KEY);
     $config->{OpenSms::OPEN_PRICE_PER_UNIT} = $this->getFormData(OpenSms::OPEN_PRICE_PER_UNIT);
     $config->{OpenSms::OPEN_UNITS_PER_SMS} = $this->getFormData(OpenSms::OPEN_UNITS_PER_SMS);
     $config->{OpenSms::INSTALLATION_STATUS} = false;
     //unlink(OpenSms::SETTINGS_FILE_PATH);
     $config->saveXML(OpenSms::SETTINGS_FILE_PATH);
     $this->setNotification('Settings saved', 'settings_save');
     OpenSms::redirectToAction('index');
 }
示例#2
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();
 }
示例#3
0
 public function save()
 {
     $this->data['user'] = $this->checkLogin(OpenSms::OPEN_ROLE_ADMIN);
     if (isset($_POST['key'])) {
         $cms = $this->loadModel("OpenSms_Model_Content", [0 => $_POST['key']]);
         if (!$cms->Id > 0) {
             $this->setError("No content found with the key '" . $_POST['key'] . "'", 'cms_save');
             OpenSms::redirectToAction('index');
         }
         $cms->Body = urldecode($_POST['body']);
         if ($cms->Save()) {
             if (isset($_POST['returnUrl'])) {
                 $this->redirect($_POST['returnUrl']);
             }
             OpenSms::redirectToAction('index');
         }
         $this->setError('Error in saving changes', 'cms_save');
         OpenSms::redirectToAction('index');
     }
 }
示例#4
0
 public function save()
 {
     if (!isset($_POST[OpenSms::DB_HOST])) {
         OpenSms::redirectToAction('index');
     }
     //if installed goto dashboard
     if ($this->getSystemSetting(OpenSms::INSTALLATION_STATUS)) {
         OpenSms::redirectToAction('index', 'dashboard');
     }
     //var_dump($_POST);die();
     // CREATE
     $config = new SimpleXmlElement('<settings/>');
     $config->{OpenSms::VERSION} = $this->getSystemSetting(OpenSms::VERSION);
     $config->{OpenSms::SITE_NAME} = $this->getFormData(OpenSms::SITE_NAME);
     $config->{OpenSms::SITE_URL} = $this->getFormData(OpenSms::SITE_URL);
     $config->{OpenSms::DB_TYPE} = 'mysql';
     $config->{OpenSms::DB_HOST} = $this->getFormData(OpenSms::DB_HOST);
     $config->{OpenSms::DB_NAME} = $this->getFormData(OpenSms::DB_NAME);
     $config->{OpenSms::DB_TABLE_PREFIX} = $this->getFormData(OpenSms::DB_TABLE_PREFIX);
     $config->{OpenSms::DB_USERNAME} = $this->getFormData(OpenSms::DB_USERNAME);
     $config->{OpenSms::DB_PASSWORD} = $this->getFormData(OpenSms::DB_PASSWORD);
     $config->{OpenSms::DB_PASSWORD} = $this->getFormData(OpenSms::DB_PASSWORD);
     $config->{OpenSms::CURRENT_THEME_KEY} = 'default';
     $config->{OpenSms::OPEN_PRICE_PER_UNIT} = $this->getFormData(OpenSms::OPEN_PRICE_PER_UNIT);
     $config->{OpenSms::OPEN_UNITS_PER_SMS} = $this->getFormData(OpenSms::OPEN_UNITS_PER_SMS);
     $config->{OpenSms::INSTALLATION_STATUS} = 'installed';
     //unlink(OpenSms::SETTINGS_FILE_PATH);
     $config->saveXML(OpenSms::SETTINGS_FILE_PATH);
     $this->loadSystemSettings();
     //create tables
     OpenSms_Helper_Db::executeNonQuery($this->getDbScript());
     //create admin account
     $user = $this->loadModel('OpenSms_Model_User');
     $user->LoginId = $this->getFormData('admin_username');
     $user->Password = $this->getFormData('admin_password');
     $user->Role = OpenSms_Model_User::ADMIN;
     $saved = $user->save();
     OpenSms::redirectToAction('complete', 'install', 'admin', [0 => $saved == true ? 1 : 0]);
 }
示例#5
0
 public function Logout()
 {
     unset($_SESSION['loginId']);
     unset($_SESSION['role']);
     OpenSms::redirectToAction('login');
 }
示例#6
0
 public function Send()
 {
     $user = $this->checkLogin();
     //var_dump($_POST); die();
     if (isset($_POST['sendmessage'])) {
         $hasErro = FALSE;
         if ($_POST['sender'] == '' || $_POST['message'] == '') {
             $notification = 'Sender and message cannot be empty';
             $hasErro = TRUE;
         } else {
             //sending message
             $recepients = '';
             //getting recipiet from the txtbox
             if (isset($_POST['recipient'])) {
                 $contactInput = preg_split('/(\\r?\\n)+/', trim($_POST['recipient']));
                 foreach ($contactInput as $ci) {
                     $recepients .= $ci . ',';
                 }
             }
             //getting recipient from the uploaded file
             if (!empty($_FILES['to_file']['name'])) {
                 //chicking file type
                 $allowedTxt = array('txt', 'TXT');
                 $allowedXls = array('xls', 'XLS');
                 $filename = $_FILES['to_file']['name'];
                 $ext = pathinfo($filename, PATHINFO_EXTENSION);
                 if (in_array($ext, $allowedTxt)) {
                     $fp = fopen($_FILES['to_file']['tmp_name'], 'rb');
                     while (($line = fgets($fp)) !== false) {
                         if (strlen(trim($line)) > 4) {
                             $f = substr($line, 0, 1);
                             if ($f != '0' && $f != '2') {
                                 $line = '0' . $line;
                             }
                             $recepients .= $line . ',';
                         }
                     }
                 } elseif (in_array($ext, $allowedXls)) {
                     //excel sheet
                     require_once 'app/code/opensms/helper/excel_reader2.php';
                     $data = new Spreadsheet_Excel_Reader($_FILES['to_file']['tmp_name']);
                     for ($i = 0; $i < count($data->sheets); $i++) {
                         if (count($data->sheets[$i]['cells']) > 0) {
                             for ($j = 1; $j <= count($data->sheets[$i]['cells']); $j++) {
                                 $num = $data->sheets[$i]['cells'][$j][1];
                                 if (strlen(trim($num)) > 4) {
                                     $f = substr($num, 0, 1);
                                     if ($f != '0' && $f != '2') {
                                         $num = '0' . $num;
                                     }
                                     $recepients .= $num . ',';
                                 }
                             }
                         }
                     }
                 } else {
                     $notification = 'Error! Please upload a text or an excel(xls) file';
                     $hasErro = TRUE;
                 }
             }
             //getting recipient from group
             if (isset($_POST['groupid']) && trim($_POST['groupid']) != '-1') {
                 $g = $this->loadModel('OpenSms_Model_Group', [0 => $_POST['groupid']]);
                 $recepients .= $g->SerializeContacts();
             }
             //senitizing number
             $recepients = str_replace(' ', '', trim($recepients));
             //take out spcae
             $recepients = str_replace(PHP_EOL, '', trim($recepients));
             //take out new lines
             $recepients = str_replace('+', '', $recepients);
             if (substr($recepients, 0, 1) == '0') {
                 $recepients = '234' . substr($recepients, 1);
             }
             $recepients = str_replace(',0', ',234', $recepients);
             //take away the 1st and last comma
             if (substr($recepients, 0, 1) == ',') {
                 $recepients = '' . substr($recepients, 1);
             }
             if (substr($recepients, strlen($recepients) - 1, 1) == ',') {
                 $recepients = '' . substr($recepients, 0, strlen($recepients) - 1);
             }
             //balanc check
             $len = strlen($_POST['message']);
             $lenPerSMS = $len < 160 ? 160 : 153;
             $msgNo = $len < $lenPerSMS ? 1 : ($len - $len % $lenPerSMS) / $lenPerSMS;
             $msgNo = $len > $lenPerSMS && $len % $lenPerSMS != 0 ? $msgNo + 1 : $msgNo;
             //dskljfsaddlkl mk
             $notification = '';
             $hasErro = FALSE;
             $count = ceil(count(explode(',', $recepients)) * $msgNo);
             $avu = $user->Balance * 1;
             $uneeded = $count * OpenSms::getSystemSetting(OpenSms::OPEN_UNITS_PER_SMS);
             if ($avu < $uneeded) {
                 $notification = 'Insufficient SMS unit!';
                 $hasErro = TRUE;
             } else {
                 if ($count > 0 && !$hasErro) {
                     /*
                     $url = API_URL.'api/SAPI/sendMessage?returnDetails=1&loginId='.API_USERNAME.'&password='******'&senderId='.
                         urlencode($_POST["sender"]).'&message='.urlencode($_POST['message']).
                         '&Recipients='.trim($recepients).'&sendOnDate=2/2/2';
                     */
                     $url = OpenSms::getField('Sms_Send_Api')->value;
                     //replace username, password, senderId, message, recipients, sendOnDate
                     $url = str_replace('@username@', OpenSms::getField('Sms_Api_Username')->value, $url);
                     $url = str_replace('@password@', OpenSms::getField('Sms_Api_Password')->value, $url);
                     $url = str_replace('@senderId@', urlencode($_POST["sender"]), $url);
                     $url = str_replace('@message@', urlencode($_POST["message"]), $url);
                     $url = str_replace('@recipients@', trim($recepients), $url);
                     //die($url);
                     //messge scheduling &sendondate=13-04-2014T12:03:20
                     if (isset($_POST['send_later']) && $_POST['send_later'] == 1) {
                         $y = $_POST['schedule_year'];
                         $mnt = $_POST['schedule_month'];
                         $d = $_POST['schedule_day'];
                         $h = $_POST['schedule_hour'];
                         $m = $_POST['schedule_munite'];
                         $now = new DateTime();
                         $selectedDateStr = $d . '-' . $mnt . '-' . $y . 'T' . $h . ':' . $m . ':00';
                         $sendDate = '&sendondate=' . urlencode($selectedDateStr);
                         $url .= $sendDate;
                         $url = str_replace('@sendOnDate@', $sendDate, $url);
                     } else {
                         $url = str_replace('@sendOnDate@', '2/2/2', $url);
                     }
                     //die($url);
                     $xml = file_get_contents($url);
                     //var_dump($xml);die();
                     //<result>True</result>
                     //1701
                     //check if message sent and deduct
                     //strpos(strtolower($xml), strtolower(OpenSms::getField('Sms_Api_Success_Keyword'))
                     if (strpos(strtolower($xml), strtolower(OpenSms::getField('Sms_Api_Success_Keyword')->value))) {
                         $user->Balance -= $count * OpenSms::getSystemSetting(OpenSms::OPEN_UNITS_PER_SMS);
                         $user->Save();
                         $notification = "Message sent";
                         $bulksSMS = $this->loadModel('OpenSms_Model_BulkSms');
                         $bulksSMS->LoginId = $user->LoginId;
                         $bulksSMS->Message = $_POST['message'];
                         $bulksSMS->Sender = $_POST['sender'];
                         $bulksSMS->Status = 1701;
                         $bulksSMS->Count = $count;
                         $bulksSMS->Save();
                         $messages = array();
                         $nos = explode(',', $recepients);
                         foreach ($nos as $no) {
                             if (empty($no)) {
                                 continue;
                             }
                             $message = $this->loadModel('OpenSms_Model_Message');
                             $message->BulkSMSId = $bulksSMS->Id;
                             $message->Number = $no;
                             $message->Message = $_POST['message'];
                             $message->Sender = $_POST['sender'];
                             $message->RefId = -1;
                             $message->Status = 1701;
                             $messages[] = $message;
                         }
                         $bulksSMS->SaveMessages($messages);
                     } else {
                         $notification = "Error! Message not sent";
                     }
                 } else {
                     if (!$hasErro) {
                         $notification = 'Please enter at least one number';
                     }
                 }
             }
         }
     } else {
         $notification = 'Invalid request param';
         $hasErro = TRUE;
     }
     if ($hasErro) {
         $this->setError($notification, 'compose_send');
     } else {
         $this->setNotification($notification, 'compose_send');
     }
     OpenSms::redirectToAction('Index');
 }
示例#7
0
 public function deleteContact($groupId, $contactId)
 {
     $this->checkLogin();
     $c2d = $this->loadModel('OpenSms_Model_Contact', [0 => $contactId]);
     $notification = $c2d->Delete();
     $error_code = $notification == 'One number deleted' ? 0 : 1;
     $this->setNotification($notification, 'delete_contact');
     OpenSms::redirectToAction('detail', '*', 'group', ['parameter1' => $groupId]);
 }
示例#8
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);
 }
示例#9
0
 public function Update()
 {
     $this->checkLogin(OpenSms::OPEN_ROLE_ADMIN);
     if (isset($_POST['key'])) {
         $theme = new OpenSms_Model_System_Theme($_POST['key']);
         if (!$theme->exists) {
             $this->setError('Invalid theme name', 'themes_update');
             OpenSms::redirectToAction('index');
         }
         if (isset($_POST['Activate'])) {
             $config = simplexml_load_file(OpenSms::SETTINGS_FILE_PATH);
             $config->{OpenSms::CURRENT_THEME_KEY} = $this->getFormData('key');
             $config->saveXML(OpenSms::SETTINGS_FILE_PATH);
         } elseif (isset($_POST['Save'])) {
             $theme_xml = simplexml_load_file($theme->getSettingsFile());
             foreach ($theme_xml->fields->field as $field) {
                 $field->value = $_POST[(string) $field->key]['value'];
             }
             $theme_xml->saveXML($theme->getSettingsFile());
         }
         $this->setNotification('Save changes succeeded', 'themes_update');
         OpenSms::redirectToAction('Detail', 'Themes', 'Admin', [0 => $theme->key]);
     } else {
         $this->setError('Invalid request param', 'themes_update');
         OpenSms::redirectToAction('Index', 'Themes', 'Admin');
     }
 }
示例#10
0
 public static function checkLogin($role = '')
 {
     if (isset($_SESSION['loginId'])) {
         $user = self::loadModel('OpenSms_Model_User', array(0 => $_SESSION['loginId']));
     } elseif (isset($_REQUEST['callback'])) {
         $user = self::loadModel('OpenSms_Model_User', array(0 => $_REQUEST['LoginId'], 1 => $_REQUEST['Password']));
         if (!$user->IsValidated) {
             echo jsonp(array('error' => TRUE, 'message' => 'Invalid Credential'));
             exit;
         }
     } else {
         $token = self::loadModel('OpenSms_Model_Login');
         if ($token->Validated()) {
             $user = self::loadModel('OpenSms_Model_User', array(0 => $token->LoginId));
         }
     }
     if (isset($user)) {
         $_SESSION['loginId'] = $user->LoginId;
         $_SESSION['role'] = $user->Role;
     } else {
         self::setError('Please login to continue', 'checkLogin_OpenSms');
         OpenSms::redirectToAction('login', 'account', 'account');
     }
     if (!empty($role)) {
         if ($user->Role != $role) {
             self::setError('Access denied. You must be an admin to perform that operation', 'checkLogin_OpenSms');
             OpenSms::redirectToAction('login', 'account', 'admin');
         }
     }
     return $user;
 }
示例#11
0
 public function update($_loginId)
 {
     $this->data['user'] = $this->checkLogin(OpenSms::OPEN_ROLE_ADMIN);
     //editing
     if (isset($_POST['resetPassword'])) {
         $errorMsg = '';
         //validation
         if (trim($_POST['Password']) == '') {
             $this->setError('Password cannot be empty and password must match', 'users_update');
             $error_code = 1;
         } else {
             $user = $this->loadModel('OpenSms_Model_User', [0 => $_loginId]);
             $user->Password = $_POST['Password'];
             $user->Save();
             $this->setNotification('Password Changed', 'users_update');
             $error_code = 0;
         }
     } else {
         $this->setError('Invalid request param', 'users_update');
     }
     OpenSms::redirectToAction('manage', 'users', 'admin', [0 => $_loginId], $error_code);
     //header('Location: '.URL.'users?notification='.$errorMsg.'&error_code='.$error_code);
     //exit();
 }
示例#12
0
 public function Update()
 {
     $this->checkLogin(OpenSms::OPEN_ROLE_ADMIN);
     if (isset($_POST['name'])) {
         $module = new OpenSms_Model_System_Module($_POST['name']);
         if (!$module->exists) {
             $this->setError('Invalid module name', 'modules_update');
             OpenSms::redirectToAction('index');
         }
         $module_xml = simplexml_load_file($module->fileName);
         if (isset($_POST['Disable'])) {
             if (OpenSms::OPEN_OPTION_YES == $module->enabled && strtolower($module->name) == 'admin') {
                 $this->setError("You can't disable the admin module", "modules_update");
                 OpenSms::redirectToAction('Detail', 'Modules', 'Admin', [0 => $module->name]);
             }
             $module_xml->enabled = (string) $module_xml->enabled == OpenSms::OPEN_OPTION_YES ? OpenSms::OPEN_OPTION_NO : OpenSms::OPEN_OPTION_YES;
         } elseif (isset($_POST['Save'])) {
             foreach ($module_xml->payments->payment as $payment) {
                 $payment->enable = $_POST[(string) $payment->key]['enabled'];
                 $payment->sort_order = $_POST[(string) $payment->key]['sort_order'];
                 $payment->order_status = $_POST[(string) $payment->key]['order_status'];
             }
             foreach ($module_xml->fields->field as $field) {
                 $field->value = $_POST[(string) $field->key]['value'];
                 $field->sort_order = $_POST[(string) $field->key]['sort_order'];
             }
         }
         $module_xml->saveXML($module->fileName);
         $this->setNotification('Save changes succeeded', 'modules_update');
         OpenSms::redirectToAction('Detail', 'Modules', 'Admin', [0 => $module->name]);
     } else {
         $this->setError('Invalid request param', 'modules_update');
         OpenSms::redirectToAction('Index', 'Modules', 'Admin');
     }
 }
示例#13
0
 public function Pay()
 {
     OpenSms::redirectToAction('index', 'fbn', 'payment');
 }
示例#14
0
 protected function redirectToAction($action, $controller = '', $module = '', array $routeParam = null)
 {
     OpenSms::redirectToAction($action, $controller, $module, $routeParam);
 }
示例#15
0
 public function Pay(OpenSms_Model_Transaction $transaction)
 {
     OpenSms::redirectToAction('Finish', 'UBA', 'Admin');
 }