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)); }