Пример #1
0
 static function createLog($num, $log_data, $category = null)
 {
     if (is_null($category)) {
         $category = self::SMS_LOG_CATEGORY_FAILURE;
     }
     // if
     if (!self::isValidCategory($category)) {
         throw new Error("'{$category}' is not valid sms log category");
     }
     // if
     $log = new SmsLog();
     try {
         DB::beginWork();
         $log->setNumber($num);
         $log->setLogData($log_data);
         $log->setCategory($category);
         $log->save();
         DB::commit();
     } catch (Exception $e) {
         DB::rollback();
     }
     return $log;
 }
Пример #2
0
 public function executeResend()
 {
     $param = $this->getAllRequestParameter();
     $sendsCrit = new Criteria();
     $sendsCrit->add(SmsLogRecipientPeer::ID, $param['id'], Criteria::IN);
     $sends = SmsLogRecipientPeer::doSelect($sendsCrit);
     $logs = array();
     foreach ($sends as $send) {
         if (!array_key_exists($send->getSmsLog()->getId(), $logs)) {
             $log = new SmsLog();
             $log->setCreatorUserId($send->getSmsLog()->getCreatorUserId());
             $log->setCreatorType($send->getSmsLog()->getCreatorType());
             $log->setSubject('Resend : ' . $send->getSmsLog()->getSubject());
             $recipients = array(array('type' => $send->getRecipientType(), 'value' => $send->getRecipientId()));
             $log->setRecipient($this->jsonwrapper->json_encode($recipients));
             $log->setMessage($send->getSmsLog()->getMessage());
             $log->setCreated(date('Y-m-d H:i:s'));
             $log->setSenderId($send->getSmsLog()->getSenderId());
             $sendAt = date('Y-m-d H:i:s');
             $log->setSendAt($sendAt);
             $log->setSmsLong($send->getSmsLog()->getSmsLong());
             $log->setSmsCount(1);
             $log->save();
             $logs[$send->getSmsLog()->getId()]['object'] = $log;
             $logs[$send->getSmsLog()->getId()]['sms_count'] = 1;
         } else {
             $log = $logs[$send->getSmsLog()->getId()]['object'];
             $logs[$send->getSmsLog()->getId()]['sms_count']++;
             $recipients = $this->jsonwrapper->json_decode($log->getRecipient);
             $recipients[] = array(array('type' => $send->getRecipientType(), 'value' => $send->getRecipientId()));
             $log->setRecipient($this->jsonwrapper->json_encode($recipients));
             $log->setSmsCount($logs[$send->getSmsLog()->getId()]['sms_count']);
             $log->save();
         }
         $rec = new SmsLogRecipient();
         $rec->setLogId($log->getId());
         $rec->setRecipientId($send->getRecipientId());
         $rec->setRecipientType($send->getRecipientType());
         $rec->setRecipientNumber($send->getRecipientNumber());
         $rec->setStatus('pending');
         $rec->setLog(0);
         $rec->save();
         /* Saving to gammu Database */
         $save = $this->sms->send($rec->getId(), 1, 2, 3, $rec->getRecipientNumber(), $log->getMessage(), $log->getCreated(), $log->getSendAt());
         /* log send status to resend */
         $send->setStatus('resend');
         $send->save();
     }
     $this->jsonwrapper->print_json(array('success' => 1, 'message' => 'success'));
 }
Пример #3
0
 public function sendSmsSppPayment($student, $month, $year)
 {
     $months = array(1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April', 5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Desember');
     $message = 'Pembayaran SPP bulan ' . $months[$month] . ' ' . $year . ' telah kami terima. Terima kasih telah berpartisipasi dalam program kami.';
     $recipients = array(array('type' => 'student', 'value' => $student->getId()));
     $departmentId = $student->getClassGroup()->getDepartmentId();
     $senderId = $this->getSenderID($departmentId);
     $message = $senderId->getText() . ' ' . $message;
     $log = new SmsLog();
     //$log->setCreatorUserId($employeeId);
     $log->setCreatorType('system');
     $log->setSubject('Konfirmasi pembayaran SPP');
     $log->setRecipient($this->jsonwrapper->json_encode($recipients));
     $log->setMessage($message);
     $log->setSenderId($senderId->getId());
     $log->setCreated(date('Y-m-d H:i:s'));
     $sendAt = date('Y-m-d H:i:s');
     $log->setSendAt('now');
     $log->save();
     $recNumber = $student->getStudentDetail()->getCellphone();
     $rec = new SmsLogRecipient();
     $rec->setLogId($log->getId());
     $rec->setRecipientId($student->getId());
     $rec->setRecipientType('student');
     $rec->setRecipientNumber($recNumber);
     $rec->setStatus('pending');
     $rec->setLog(0);
     $rec->save();
     /* Saving to gammu Database */
     $save = $this->smsConn->send($rec->getId(), 1, 2, 3, $recNumber, $log->getMessage(), $log->getCreated(), $log->getSendAt());
 }
Пример #4
0
 public function actionCreateMultiple()
 {
     $model = new SmsLog();
     $smsBerhasil = count(SmsLog::model()->findALlByAttributes(array('STATUS' => 1)));
     $smsGagal = count(SmsLog::model()->findALlByAttributes(array('STATUS' => 0)));
     $smsTotal = $smsBerhasil + $smsGagal;
     $smsKuota = Sms::model()->findByPk(1);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['SmsLog'])) {
         Yii::import('ext.nasrulsms.SMSreguler');
         if ($_POST['SmsLog']['TUJUAN'] != "" && $_POST['SmsLog']['PESAN'] != "") {
             ob_start();
             $smsusername = "******";
             $smspassword = "******";
             $apikey = "4b15b9bb700fef70f11e143d09a3f3c9";
             $banyak = 0;
             $berhasil = 0;
             $gagal = 0;
             // cek curl aktif atau tidak
             if (!function_exists('curl_version')) {
                 Yii::app()->user->setFlash('info', "<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'></button>Curl tidak aktif! aktifkan dulu mas bero! -_-</div>");
                 $this->redirect(array('createMultiple'));
             }
             // inisialisasi
             $nohp = $_POST['SmsLog']['TUJUAN'];
             $pesan = $_POST['SmsLog']['PESAN'];
             // filter karakter
             $replace = str_replace(" ", "", $nohp);
             $replace = str_replace("-", "", $replace);
             $replace = str_replace("(", "", $replace);
             $replace = str_replace(")", "", $replace);
             $replace = str_replace("+62", "0", $replace);
             // looping sesuai jumlah nomor yg diinput
             $pisahkoma = count($nohp);
             if (count($pisahkoma) < $smsKuota->SISA_KUOTA) {
                 if ($smsKuota->STATUS != 0 && $smsKuota->MASA_BERLAKU > date("Y-m-d H:i:s")) {
                     foreach ($nohp as $value) {
                         $pelanggan = Pasien::model()->findByPk($value);
                         if (count($pelanggan) > 0) {
                             // kirim sms
                             $sms = new SMSreguler();
                             $sms->setUsername($smsusername);
                             $sms->setPassword($smspassword);
                             $sms->setApi($apikey);
                             $sms->setTo($pelanggan->NO_TELP);
                             $sms->setText($pesan);
                             $sts = $sms->smssend();
                             $idreport = explode('|', $sts);
                             if (substr($sts, 0, 1) == '0') {
                                 $status = 1;
                                 $berhasil += 1;
                             } else {
                                 $status = 0;
                                 $gagal += 1;
                             }
                             // simpan sms ke db
                             $smsLog = new SmsLog();
                             $smsLog->ID_USER = Yii::app()->user->getState('nama');
                             $smsLog->ID_PASIEN = $pelanggan->ID_PASIEN;
                             $smsLog->PESAN = $pesan;
                             $smsLog->TUJUAN = $pelanggan->NO_TELP;
                             $smsLog->TANGGAL_KIRIM = date("Y-m-d H:i:s");
                             $smsLog->STATUS = $status;
                             $smsLog->save();
                             // catat record
                             $banyak += 1;
                         }
                     }
                     $error = false;
                 } else {
                     Yii::app()->user->setFlash('info', "<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'></button><strong>GAGAL!</strong> Status SMS Broadcast Tidak Aktif, silahkan hubungi <strong>Admin Website</strong>.</div>");
                     // reset STATUS
                     $smsMaster = Sms::model()->findByPk(1);
                     $smsMaster->STATUS = 0;
                     $smsMaster->save();
                     $this->redirect(array('createMultiple'));
                 }
             } else {
                 $model->addError('TUJUAN', 'Jumlah Nomor Tujuan SMS melebihi sisa kuota.');
                 $model->PESAN = $pesan;
                 $error = true;
             }
             $smsMaster = Sms::model()->findByPk(1);
             $smsMaster->SISA_KUOTA = $smsMaster->SISA_KUOTA - $banyak;
             $smsMaster->save();
             if (!$error) {
                 $notifikasi = "Total SMS Terkirim adalah <strong>" . $banyak . " SMS</strong>, terdiri dari <strong>" . $berhasil . " Berhasil</strong> dan <strong>" . $gagal . " Gagal</strong>.";
                 Yii::app()->user->setFlash('info', "<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'></button>" . $notifikasi . "</div>");
                 $this->redirect(array('createMultiple'));
             }
         }
     }
     $this->render('create_multiple', array('model' => $model, 'smsBerhasil' => $smsBerhasil, 'smsGagal' => $smsGagal, 'smsTotal' => $smsTotal, 'smsKuota' => $smsKuota->SISA_KUOTA));
 }