public function service()
 {
     if (isset($_REQUEST['number'])) {
         $number = $this->secure($_REQUEST['number']);
         $sentSmsManager = SentSmsManager::getInstance($this->config, $this->args);
         $number = SentSmsManager::getValidArmenianNumber($number);
         if ($number == null) {
             $jsonArr = array('status' => "err", "errText" => "Invalid cell phone number!", 'number_valid' => "false");
             echo json_encode($jsonArr);
             return false;
         }
         $company = $this->getCustomer();
         $lastSmsValidationCode = substr(uniqid(rand(), true), 0, 6);
         $companyManager = CompanyManager::getInstance($this->config, $this->args);
         $companyManager->setLastSmsValidationCode($company->getId(), $lastSmsValidationCode);
         $sentSmsManager->sendSmsToArmenia($number, $lastSmsValidationCode);
         $jsonArr = array('status' => "ok", 'number_valid' => "true");
         echo json_encode($jsonArr);
         return true;
     } elseif (isset($_REQUEST['code'])) {
         $code = $this->secure($_REQUEST['code']);
         $company = $this->getCustomer();
         $c = $company->getLastSmsValidationCode();
         if ($code == $c) {
             $jsonArr = array('status' => "ok", 'code_valid' => "true");
             echo json_encode($jsonArr);
             return true;
         } else {
             $jsonArr = array('status' => "err", "errText" => "Invalid sms code!", 'code_valid' => "false");
             echo json_encode($jsonArr);
             return false;
         }
     }
 }
 public function load()
 {
     $this->addParam('pcstore_contact_number', $this->getCmsVar('pcstore_sales_phone_number'));
     $customer = $this->getCustomer();
     $sms_sent = false;
     if (isset($_REQUEST['co_code'])) {
         $code = $this->secure($_REQUEST['co_code']);
         $this->addParam('co_code', $code);
         if ($customer->getLastSmsValidationCode() === $code) {
             $this->addParam('order_confirmed', true);
         } else {
             $this->addParam('errorMessage', 223);
         }
         $this->addParam('sms_sent', true);
         return true;
     }
     $cell_phone_editable = $this->secure($_REQUEST['cho_do_shipping']) != 1;
     if ($cell_phone_editable) {
         $this->addParam('infoMessage', 362);
     }
     $cell_phone_number = $this->getPhoneNumberToSendSMS();
     $validNumber = null;
     if ($cell_phone_number != null) {
         $validNumber = SentSmsManager::getValidArmenianNumber($cell_phone_number);
     }
     if ($validNumber != null) {
         $lastSmsValidationCode = substr(uniqid(rand(), true), 0, 6);
         if ($this->getUserLevel() == UserGroups::$USER) {
             $userManager = UserManager::getInstance($this->config, $this->args);
             $userManager->setLastSmsValidationCode($customer->getId(), $lastSmsValidationCode);
         } elseif ($this->getUserLevel() == UserGroups::$COMPANY) {
             $companyManager = CompanyManager::getInstance($this->config, $this->args);
             $companyManager->setLastSmsValidationCode($customer->getId(), $lastSmsValidationCode);
         }
         $sentSmsManager = SentSmsManager::getInstance($this->config, $this->args);
         $sentSmsManager->sendSmsToArmenia($validNumber, $lastSmsValidationCode);
         $this->addParam('infoMessage', "`319` ({$validNumber})");
         $this->addParam('validNumber', "(" . $validNumber . ")");
         $this->addParam('sms_sent', true);
     } else {
         if (!empty($cell_phone_number)) {
             $this->addParam('errorMessage', 318);
         }
         $this->addParam('cell_phone_number', $cell_phone_number);
         if (!$cell_phone_editable) {
             $this->addParam('infoMessage', 387);
         }
     }
     $this->addParam('cell_phone_editable', $cell_phone_editable);
 }
示例#3
0
 public function service()
 {
     $sentSmsManager = SentSmsManager::getInstance($this->config, $this->args);
     $smsGatewaysManager = SmsGatewaysManager::getInstance($this->config, $this->args);
     $phoneNumber = $this->secure($_REQUEST['phone_number']);
     $gatewayId = $this->secure($_REQUEST['gateway']);
     $gateway = $smsGatewaysManager->selectByPK($gatewayId);
     if (!isset($gateway)) {
         $this->error(array('message' => 'Wrong gateway!'));
     }
     $message = $_REQUEST['message'];
     if (empty($message)) {
         $this->error(array('message' => 'Message can not be empty!'));
     }
     $validNumber = SentSmsManager::getValidArmenianNumber($phoneNumber);
     if (!isset($validNumber)) {
         $this->error(array('message' => 'Invalid phone number!'));
     }
     $sentSmsManager->sendSmsToArmenia($phoneNumber, $message, $gateway->getName());
     $this->ok();
 }
示例#4
0
 public static function getValidArmenianNumber($number, $internationalCodePrefix = '+')
 {
     $manager = SentSmsManager::getInstance(null, null);
     if (!isset($number)) {
         return null;
     }
     $number = strval($number);
     $number = preg_replace("/[^0-9]/", "", $number);
     if (strlen($number) >= 8) {
         $number = substr($number, -8, 8);
         if (in_array(substr($number, 0, 2), $manager->validArmenianPrefix)) {
             return $internationalCodePrefix . $manager->armeniaTelCode . $number;
         }
     }
     return null;
 }
 public function sendSmsToAdminIfUploaderIsNotItself($companyName)
 {
     $adminManager = AdminManager::getInstance($this->config, $this->args);
     $adminsToReceiveSms = $adminManager->getSmsEnabledAdmins();
     $sentSmsManager = SentSmsManager::getInstance($this->config, $this->args);
     foreach ($adminsToReceiveSms as $key => $admin) {
         if ($this->getUserLevel() === UserGroups::$ADMIN && $this->getUserId() == $admin->getId()) {
             continue;
         }
         $numberToReceiveSmsOnPriceUpload = $admin->getNumberToReceiveSmsOnPriceUpload();
         if (!empty($numberToReceiveSmsOnPriceUpload)) {
             $sentSmsManager->sendSmsToArmenia($numberToReceiveSmsOnPriceUpload, "'" . $companyName . "' just uploaded price on PcStore!    Best Regards www.pcstore.am");
         }
     }
 }
 public function sendSmsToSmsInterestedCompanies($companyId, $companyName)
 {
     $companyManager = CompanyManager::getInstance($this->config, $this->args);
     $companiesToReceiveSMS = $companyManager->getCompanyPriceInterestedForSmsCompanies($companyId);
     $sentSmsManager = SentSmsManager::getInstance($this->config, $this->args);
     foreach ($companiesToReceiveSMS as $key => $company) {
         $numberToReceiveSmsOnPriceUpload = $company->getPriceUploadSmsPhoneNumber();
         if (empty($numberToReceiveSmsOnPriceUpload)) {
             continue;
         }
         $weekdays = $company->getSmsReceiveWeekdays();
         $dayofweek = date('N');
         if ($weekdays[$dayofweek - 1] != '1') {
             continue;
         }
         $duration = $company->getSmsToDurationMinutes();
         if ($duration > 0) {
             $smsReceiveTimeStart = $company->getSmsReceiveTimeStart();
             $smsReceiveStartDateTime = strtotime(date('Y-m-d') . ' ' . $smsReceiveTimeStart);
             $smsReceiveEndDateTime = strtotime("+{$duration} minutes", $smsReceiveStartDateTime);
             $now = time();
             if ($now < $smsReceiveStartDateTime || $now > $smsReceiveEndDateTime) {
                 continue;
             }
         }
         $sentSmsManager->sendSmsToArmenia($numberToReceiveSmsOnPriceUpload, "'" . $companyName . "' just uploaded price on PcStore!    Best Regards www.pcstore.am");
     }
 }