static function savelog($camp_id, $device_id, $acc_id, $status, $log_text, $log_multicast_id)
 {
     $nl = new PushLogger();
     $nl->log_camp_id = $camp_id;
     $nl->log_device_id = $device_id;
     $nl->log_macc_id = $acc_id;
     $nl->log_status = $status;
     $nl->log_text = $log_text;
     $nl->log_multicast_id = $log_multicast_id;
     $nl->log_date = leap_mysqldate();
     return $nl->save();
 }
    function detail()
    {
        $id = addslashes($_GET['id']);
        //        echo "in".$id;
        $nn = new PushLogger();
        $arrLogs = $nn->getWhere("log_multicast_id = '{$id}' ORDER BY log_id ASC");
        //        pr($arrLogs);
        foreach ($arrLogs as $log) {
            $acc = new LL_Account();
            $acc->getByID($log->log_macc_id);
            ?>
            <div class="hasil">
                ID : <?php 
            echo $acc->macc_id;
            ?>
 <?php 
            echo $acc->macc_first_name;
            ?>
 <?php 
            echo $acc->macc_last_name;
            ?>
<br>
                Status : <?php 
            echo $this->arrStatus[$log->log_status];
            ?>
<br>
                Message : <?php 
            echo $log->log_text;
            ?>
            </div>
            <?php 
        }
    }
Пример #3
0
 static function processGCM($arrhasil, $app_id, $psn, $array_ids, $app, $isTest = 0)
 {
     $json['status_code'] = 1;
     $json['status_message'] = "Success";
     $json['result'] = $arrhasil;
     foreach ($arrhasil as $numw => $hasil) {
         //simpan hasil
         $gcm = new GCMResult();
         $gcm->multicast_id = $hasil->multicast_id;
         $gcm->success = $hasil->success;
         $gcm->failure = $hasil->failure;
         $gcm->results = serialize($hasil->results);
         $gcm->canonical_ids = $hasil->canonical_ids;
         $gcm->camp_id = $psn->camp_id;
         $gcm->gcm_date = leap_mysqldate();
         $gcm->gcm_test = $isTest;
         $gcm->app_id = $app_id;
         $gcm->client_camp_id = $psn->camp_client_id;
         $gcm->client_id = $app->app_client_id;
         $gcm->save();
         if (!$isTest) {
             //kurangin pulsa ...
             $old = $app->app_pulsa;
             $app->app_pulsa = $app->app_pulsa - $hasil->success;
             $app->load = 1;
             $app->save();
             //save transactions
             $tt = new AppPulsa();
             $tt->pulsa_acc_id = Account::getMyID();
             $tt->pulsa_action = "debit";
             $tt->pulsa_app_id = $app_id;
             $tt->pulsa_date = leap_mysqldate();
             $tt->pulsa_jumlah = $hasil->success;
             $tt->pulsa_new = $app->app_pulsa;
             $tt->pulsa_old = $old;
             $tt->pulsa_camp_id = $psn->camp_id;
             $tt->save();
             //
         }
         //            echo "ID : ".$hasil->multicast_id."<br>";
         //            echo "Success : ".$hasil->success."<br>";
         //            echo "Failure : ".$hasil->failure."<br>";
         //            echo "<a target='_blank' href='"._SPPATH."PushNotResults/res?id={$psn->camp_id}&token=".IMBAuth::createOAuth()."' class='btn btn primary'>Complete Results</a><br><br>";
         $page = 999 * $numw;
         foreach ($hasil->results as $num => $res) {
             if (isset($res->error)) {
                 //error
                 $status = 0;
                 $log_text = $res->error;
                 //delete device_id from table
                 $dv = new DeviceModel();
                 global $db;
                 //repaired using update
                 $q = "UPDATE  {$dv->table_name} SET dev_not_send = 1 WHERE device_id = '" . $array_ids[$page + $num] . "'";
                 if ($_GET['test']) {
                     echo "<br>query : " . $q . "<br>";
                     echo "delete succ :" . $db->query($q, 0);
                     echo "<br>";
                 }
             } else {
                 //success
                 $status = 1;
                 $log_text = $res->message_id;
             }
             // repaired macc id cannot get
             PushLogger::savelog($psn->camp_id, $array_ids[$num], $app->app_client_id, $status, $log_text, $hasil->multicast_id, $app_id, $psn->camp_client_id);
         }
     }
     $psn->camp_status = 1;
     $psn->camp_send_date = leap_mysqldate();
     $psn->load = 1;
     $psn->save();
     return $json;
 }
 function deleteByLogID()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $macc_id = addslashes($_POST['macc_id']);
     $lid = addslashes($_POST['lid']);
     $psl = new PushLogger();
     $psl->getByID($lid);
     $json['status_code'] = 0;
     if ($psl->log_macc_id = $macc_id) {
         //tidak active lagi
         $psl->log_active = 0;
         $psl->load = 1;
         if ($psl->save()) {
             $json['status_code'] = 1;
         }
     }
     echo json_encode($json);
     die;
 }
 static function sendUsingAccountArray($arrAcc, $psn, $isTest = 0)
 {
     if ($_GET['test']) {
         pr($arrAcc);
     }
     if ($_GET['test']) {
         echo "<h1>Push Complete Results</h1>";
     }
     foreach ($arrAcc as $to) {
         $dev = new DeviceModel();
         //            $arrD = $dev->getWhere("acc_id = '$to' AND device_type = 'android' ORDER BY logindate DESC");
         //kalau dijaddin ga aktif 16 dec 2015
         //            $arrD = $dev->getWhere("acc_id = '$to' ORDER BY logindate DESC");
         $arrD = $dev->getWhere("acc_id = '{$to}' AND dev_active = 1  ORDER BY logindate DESC");
         //            $json['arrD'] = $arrD;
         //            foreach ($arrD as $d) {
         //                $json['dev'] = $d->device_id;
         ////                if($d->device_id == "")continue;
         //                $hasil = self::push($d->device_id, $msg, $website);
         //                $json['hasil'] = $hasil;
         //                if ($hasil->success > 0) {
         //                    $json['bool'] = 1;
         ////                    $json['hasil'] = $hasil;
         //                }
         //            }
         if (count($arrD) > 0) {
             foreach ($arrD as $ddd) {
                 $devices[] = $ddd;
             }
         } else {
             if ($_GET['test']) {
                 echo "no device id : " . $to . " <br>";
             }
         }
     }
     $action = self::getAction($psn);
     if ($_GET['test']) {
         echo "action = " . $action . "<br>";
     }
     $array_id = array();
     if ($_GET['test']) {
         echo "<h3>Devices</h3>";
     }
     foreach ($devices as $dev) {
         if ($_GET['test']) {
             echo " acc_id : " . $dev->acc_id;
             echo "<br> dev_id : " . $dev->device_id;
             echo "<br> type : " . $dev->device_type;
             echo "<br>";
         }
         $array_id[] = $dev->device_id;
     }
     $url2push = Efiwebsetting::getData('PUBLIC_IP') . "WebViewer/messages/" . $psn->camp_id;
     //penambahan atas permintaan tbs 10 sept 2015, bisa push url
     if ($psn->camp_url != "") {
         $url2push = $psn->camp_url;
     }
     /*
      *
      *  PILIHAN antara server luar dan dalam
      *  27 Nov 2015
      *
      */
     $pss = new Pusher();
     if ($pss->pakai_server_luar == '1') {
         $app_id = 1;
         $app_key = "1qay2wsx";
         $push_api_url = "http://push.indomegabyte.com/PushAPI/doPushByDevID";
         $devs = implode(",", $array_id);
         $fields = array('devs' => $devs, 'app_id' => $app_id, 'key' => $app_key, 'camp_id' => $psn->camp_id, 'camp_name' => $psn->camp_name, 'camp_title' => $psn->camp_title, 'camp_url' => $url2push, 'isTest' => $isTest);
         $headers = array('Content-Type: application/json');
         //            pr($fields);
         //"postvar1=value1&postvar2=value2&postvar3=value3"
         foreach ($fields as $k => $val) {
             $jadi[] = $k . "=" . $val;
         }
         $imp = implode("&", $jadi);
         //            echo http_build_query($fields);
         //            $ch = curl_init();
         //            curl_setopt($ch, CURLOPT_URL, $push_api_url);
         //            curl_setopt($ch, CURLOPT_POST, true);
         //            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         //            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         //            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         //            curl_setopt($ch, CURLOPT_POSTFIELDS, $imp);
         //            $result = json_decode(curl_exec($ch));
         //            curl_close($ch);
         //
         //            pr($result);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $push_api_url);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
         // in real life you should use something like:
         // curl_setopt($ch, CURLOPT_POSTFIELDS,
         //          http_build_query(array('postvar1' => 'value1')));
         // receive server response ...
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $server_output = curl_exec($ch);
         curl_close($ch);
         //            pr($server_output);
         $ress = json_decode($server_output);
         if (!isset($_POST['no_echo'])) {
             echo "<h1>" . $ress->status_message . " Status Code [" . $ress->status_code . "]</h1>";
         }
         $arrhasil = $ress->result;
         //            pr($arrhasil);
     } elseif ($pss->pakai_server_luar == '2') {
         //create temporary files to read from
         $myfile = fopen(_PHOTOPATH . "campaign.txt", "w") or die("Unable to create file!");
         $txt = implode(",", $array_id);
         if (fwrite($myfile, $txt)) {
             fclose($myfile);
             $app_id = 1;
             $app_key = "1qay2wsx";
             $push_api_url = "http://push.indomegabyte.com/PushAPI/doPushByDevIDwithFile";
             //                $push_api_url = "http://localhost:8888/push/PushAPI/doPushByDevIDwithFile";
             $devs = Efiwebsetting::getData('PUBLIC_IP') . "uploads/campaign.txt";
             //                pr($devs);
             //                pr($push_api_url);
             $fields = array('devs' => $devs, 'app_id' => $app_id, 'key' => $app_key, 'camp_id' => $psn->camp_id, 'camp_name' => $psn->camp_name, 'camp_title' => $psn->camp_title, 'camp_url' => $url2push, 'isTest' => $isTest);
             $headers = array('Content-Type: application/json');
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $push_api_url);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             $server_output = curl_exec($ch);
             curl_close($ch);
             $ress = json_decode($server_output);
             if (!isset($_POST['no_echo'])) {
                 echo "<h1>" . $ress->status_message . " Status Code [" . $ress->status_code . "]</h1>";
             }
             $arrhasil = $ress->result;
             //                pr($fields);
             //                pr($arrhasil);
             //                pr($server_output);
         } else {
             die("Unable to write");
         }
     } else {
         //after we collected the device ids in an array, kita push
         $arrhasil = self::push($array_id, $psn->camp_title, $url2push, $action);
     }
     if ($_GET['test']) {
         pr($arrhasil);
     }
     if (!isset($_POST['no_echo'])) {
         echo "<h1>Results</h1>";
     }
     foreach ($arrhasil as $numw => $hasil) {
         //simpan hasil
         $gcm = new GCMResult();
         $gcm->multicast_id = $hasil->multicast_id;
         $gcm->success = $hasil->success;
         $gcm->failure = $hasil->failure;
         $gcm->results = serialize($hasil->results);
         $gcm->canonical_ids = $hasil->canonical_ids;
         $gcm->camp_id = $psn->camp_id;
         $gcm->gcm_date = leap_mysqldate();
         $gcm->gcm_test = $isTest;
         $gcm->save();
         if (!isset($_POST['no_echo'])) {
             echo "ID : " . $hasil->multicast_id . "<br>";
             echo "Success : " . $hasil->success . "<br>";
             echo "Failure : " . $hasil->failure . "<br>";
             echo "<a target='_blank' href='" . _SPPATH . "PushNotResults/res?id={$psn->camp_id}&token=" . IMBAuth::createOAuth() . "' class='btn btn primary'>Complete Results</a><br><br>";
         }
         $page = 999 * $numw;
         foreach ($hasil->results as $num => $res) {
             if (isset($res->error)) {
                 //error
                 $status = 0;
                 $log_text = $res->error;
                 //delete device_id from table
                 $dv = new DeviceModel();
                 global $db;
                 $q = "DELETE FROM {$dv->table_name} WHERE device_id = '" . $array_id[$page + $num] . "'";
                 $q = "UPDATE {$dv->table_name} SET dev_active = 0 WHERE device_id = '" . $array_id[$page + $num] . "'";
                 //coba test..
                 //                        echo $q;
                 $del = $db->query($q, 0);
                 if ($_GET['test']) {
                     echo "<br>query : " . $q . "<br>";
                     echo "delete succ :" . $del;
                     echo "<br>";
                 }
             } else {
                 //success
                 $status = 1;
                 $log_text = $res->message_id;
             }
             PushLogger::savelog($psn->camp_id, $array_id[$num], $devices[$num]->acc_id, $status, $log_text, $hasil->multicast_id);
             //disini save camp_id ke device_id dan date
             //pakai PushLogger Bisa !!! 11 January 2016
         }
     }
     //        foreach($hasil->results as $
     //        foreach($devices as $dev) {
     //            PushLogger::savelog($psn->camp_id,)
     //        }
     //        echo json_encode($json);
     //        die();
 }
Пример #6
0
 static function simpanHasilGCM($arrhasil, $psn, $array_id, $arrDevs, $app, $isTest = 0)
 {
     if ($_GET['test']) {
         pr($arrhasil);
     }
     if ($_GET['test']) {
         echo "<h1>Results</h1>";
     }
     foreach ($arrhasil as $numw => $hasil) {
         //simpan hasil
         $gcm = new GCMResultCaps();
         $gcm->multicast_id = $hasil->multicast_id;
         $gcm->success = $hasil->success;
         $gcm->failure = $hasil->failure;
         $gcm->results = serialize($hasil->results);
         $gcm->canonical_ids = $hasil->canonical_ids;
         $gcm->camp_id = $psn->camp_id;
         $gcm->gcm_date = leap_mysqldate();
         $gcm->gcm_test = $isTest;
         $gcm->save();
         if ($_GET['test']) {
             echo "ID : " . $hasil->multicast_id . "<br>";
             echo "Success : " . $hasil->success . "<br>";
             echo "Failure : " . $hasil->failure . "<br>";
             echo "<a target='_blank' href='" . _SPPATH . "PushNotResults/res?id={$psn->camp_id}&token=" . IMBAuth::createOAuth() . "' class='btn btn primary'>Complete Results</a><br><br>";
         }
         $page = 999 * $numw;
         foreach ($hasil->results as $num => $res) {
             if (isset($res->error)) {
                 //error
                 $status = 0;
                 $log_text = $res->error;
                 //delete device_id from table
                 $dv = new DeviceModel();
                 global $db;
                 //                    $q = "DELETE FROM {$dv->table_name} WHERE device_id = '".$array_id[$page+$num]."'";
                 $q = "UPDATE {$dv->table_name} SET dev_not_send = 1 WHERE device_id = '" . $array_id[$page + $num] . "'";
                 if ($_GET['test']) {
                     echo "<br>query : " . $q . "<br>";
                     echo "delete succ :" . $db->query($q, 0);
                     echo "<br>";
                 }
             } else {
                 //success
                 $status = 1;
                 $log_text = $res->message_id;
             }
             PushLogger::savelog($psn->camp_id, $array_id[$page + $num], $arrDevs[$page + $num]->acc_id, $status, $log_text, $hasil->multicast_id, $app->app_id, $app->app_client_id);
             //                PushLogger::savelog($psn->camp_id,$array_id[$page+$num],$arrDevs[$page+$num]->acc_id,$status,$log_text,$hasil->multicast_id);
         }
     }
 }
Пример #7
0
 static function sendUsingAccountArray($arrAcc, $psn, $isTest = 0)
 {
     if ($_GET['test']) {
         pr($arrAcc);
     }
     if ($_GET['test']) {
         echo "<h1>Push Complete Results</h1>";
     }
     foreach ($arrAcc as $to) {
         $dev = new DeviceModel();
         //            $arrD = $dev->getWhere("acc_id = '$to' AND device_type = 'android' ORDER BY logindate DESC");
         $arrD = $dev->getWhere("acc_id = '{$to}' ORDER BY logindate DESC");
         //            $json['arrD'] = $arrD;
         //            foreach ($arrD as $d) {
         //                $json['dev'] = $d->device_id;
         ////                if($d->device_id == "")continue;
         //                $hasil = self::push($d->device_id, $msg, $website);
         //                $json['hasil'] = $hasil;
         //                if ($hasil->success > 0) {
         //                    $json['bool'] = 1;
         ////                    $json['hasil'] = $hasil;
         //                }
         //            }
         if (count($arrD) > 0) {
             foreach ($arrD as $ddd) {
                 $devices[] = $ddd;
             }
         } else {
             if ($_GET['test']) {
                 echo "no device id : " . $to . " <br>";
             }
         }
     }
     $action = self::getAction($psn);
     if ($_GET['test']) {
         echo "action = " . $action . "<br>";
     }
     $array_id = array();
     if ($_GET['test']) {
         echo "<h3>Devices</h3>";
     }
     foreach ($devices as $dev) {
         if ($_GET['test']) {
             echo " acc_id : " . $dev->acc_id;
             echo "<br> dev_id : " . $dev->device_id;
             echo "<br> type : " . $dev->device_type;
             echo "<br>";
         }
         $array_id[] = $dev->device_id;
     }
     $url2push = Efiwebsetting::getData('PUBLIC_IP') . "WebViewer/messages/" . $psn->camp_id;
     //penambahan atas permintaan tbs 10 sept 2015, bisa push url
     if ($psn->camp_url != "") {
         $url2push = $psn->camp_url;
     }
     //after we collected the device ids in an array, kita push
     $arrhasil = self::push($array_id, $psn->camp_title, $url2push, $action);
     if ($_GET['test']) {
         pr($arrhasil);
     }
     echo "<h1>Results</h1>";
     foreach ($arrhasil as $numw => $hasil) {
         //simpan hasil
         $gcm = new GCMResult();
         $gcm->multicast_id = $hasil->multicast_id;
         $gcm->success = $hasil->success;
         $gcm->failure = $hasil->failure;
         $gcm->results = serialize($hasil->results);
         $gcm->canonical_ids = $hasil->canonical_ids;
         $gcm->camp_id = $psn->camp_id;
         $gcm->gcm_date = leap_mysqldate();
         $gcm->gcm_test = $isTest;
         $gcm->save();
         echo "ID : " . $hasil->multicast_id . "<br>";
         echo "Success : " . $hasil->success . "<br>";
         echo "Failure : " . $hasil->failure . "<br>";
         echo "<a target='_blank' href='" . _SPPATH . "PushNotResults/res?id={$psn->camp_id}&token=" . IMBAuth::createOAuth() . "' class='btn btn primary'>Complete Results</a><br><br>";
         $page = 999 * $numw;
         foreach ($hasil->results as $num => $res) {
             if (isset($res->error)) {
                 //error
                 $status = 0;
                 $log_text = $res->error;
                 //delete device_id from table
                 $dv = new DeviceModel();
                 global $db;
                 $q = "DELETE FROM {$dv->table_name} WHERE device_id = '" . $array_id[$page + $num] . "'";
                 if ($_GET['test']) {
                     echo "<br>query : " . $q . "<br>";
                     echo "delete succ :" . $db->query($q, 0);
                     echo "<br>";
                 }
             } else {
                 //success
                 $status = 1;
                 $log_text = $res->message_id;
             }
             PushLogger::savelog($psn->camp_id, $array_id[$num], $devices[$num]->acc_id, $status, $log_text, $hasil->multicast_id);
         }
     }
     //        foreach($hasil->results as $
     //        foreach($devices as $dev) {
     //            PushLogger::savelog($psn->camp_id,)
     //        }
     //        echo json_encode($json);
     //        die();
 }
 public function exportIt($return)
 {
     $id = addslashes($_GET['cid']);
     //        echo $id;
     if ($id == "" || $id < 1) {
         die("no id");
     }
     $camp = new PushNotCamp();
     $camp->getByID($id);
     $arrStatus = array("0" => "Not Pushed", "1" => "Pushed");
     if ($camp->camp_app_id != AppAccount::getAppID()) {
         die("camp mismatched");
     }
     //        pr($camp);
     $onDate = "";
     if ($camp->camp_status == 1) {
         $onDate = " on " . indonesian_date($camp->camp_send_date);
     }
     //hitung openrate dll
     $targetedDev = count(explode(",", $camp->camp_dev_ids));
     $gcm = new GCMResult();
     $arrGCM = $gcm->getWhere("camp_id = '{$id}' ORDER BY gcm_date DESC");
     $succ = 0;
     $fail = 0;
     $seen_by = 0;
     foreach ($arrGCM as $cc) {
         $succ += $cc->success;
         $fail += $cc->failure;
         $seen_by += $cc->seen_by;
     }
     $openrate = round($seen_by / $succ * 100, 3);
     $del = round($succ / ($succ + $fail) * 100, 3);
     $filename = urlencode(str_replace(" ", "_", $camp->camp_name)) . "_" . date('Ymd') . ".xls";
     header("Content-Disposition: attachment; filename=\"{$filename}\"");
     header("Content-Type: application/vnd.ms-excel");
     $flag = false;
     print "Campaign Name : \t" . $camp->camp_title;
     //judul
     print "\n";
     print "Status : \t" . $arrStatus[$camp->camp_status] . $onDate;
     //status and delieverd date
     print "\n";
     print "Content : \t" . $camp->camp_title;
     print "\n";
     print "Open Rate : \t" . $openrate;
     print "\n";
     print "Seen By : \t" . $seen_by;
     print "\n";
     print "Deliverable Percentage : \t" . $del;
     print "\n";
     print "Targeted Devices : \t" . $targetedDev;
     print "\n";
     print "Success : \t" . $succ;
     print "\n";
     print "Failed : \t" . $fail;
     print "\n";
     print "\n";
     $logs = new PushLogger();
     $objs = $logs->getWhere("log_camp_id = '{$id}'");
     $filter = explode(",", $logs->exportList);
     foreach ($objs as $key => $obj) {
         foreach ($obj as $name => $value) {
             if (in_array($name, $filter)) {
                 echo Lang::t($name) . "\t";
             }
         }
         break;
     }
     print "\n";
     foreach ($objs as $key => $obj) {
         foreach ($obj as $name => $value) {
             if (in_array($name, $filter)) {
                 echo $value . "\t";
             }
         }
         print "\n";
     }
     exit;
 }