static function simpanHasilGCM($arrhasil, $psn, $array_id, $arrDevs, $isTest = 0)
 {
     if ($_GET['test']) {
         pr($arrhasil);
     }
     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();
         echo "ID : " . $hasil->multicast_id . "<br>";
         echo "Success : " . $hasil->success . "<br>";
         echo "Failure : " . $hasil->failure . "<br>";
         echo "<a target='_blank' href='" . _SPPATH . "PushNotResultsCaps/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 DeviceModelCapsule();
                 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;
             }
             PushLoggerCaps::savelog($psn->camp_id, $array_id[$page + $num], $arrDevs[$page + $num]->acc_id, $status, $log_text, $hasil->multicast_id);
             //                PushLogger::savelog($psn->camp_id,$array_id[$page+$num],$arrDevs[$page+$num]->acc_id,$status,$log_text,$hasil->multicast_id);
         }
     }
 }
    function res()
    {
        //        echo IMBAuth::createOAuth();
        //        echo "<br>";
        //        echo $_GET['token'];
        IMBAuth::checkOAuth();
        $id = addslashes($_GET['id']);
        //        echo $id;
        if ($id == "" || $id < 1) {
            die("No ID");
        }
        $ps = new PushNotCampCaps();
        $ps->getByID($id);
        //        pr($ps);
        $pss = new GCMResultCaps();
        $arrs = $pss->getWhere("camp_id = '{$id}' ORDER BY gcm_date DESC");
        ?>
    <html>
    <head>
        <link href="<?php 
        echo _SPPATH;
        ?>
themes/adminlte/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
        <link rel="stylesheet" href="<?php 
        echo _SPPATH;
        ?>
themes/adminlte/css/jqueryui.css">
        <script src="<?php 
        echo _SPPATH;
        ?>
themes/adminlte/js/jquery-1.11.1.min.js"></script>
        <script src="<?php 
        echo _SPPATH;
        ?>
js/jqueryui.js"></script>
        <script src="<?php 
        echo _SPPATH;
        ?>
themes/adminlte/js/bootstrap.min.js" type="text/javascript"></script>
    </head>
    <body>
    <div id="wait" style="display: none; position: absolute;  width: 100%; line-height: 30px; text-align: center; font-weight: bold;">
        <span style="background-color: red; color:white; padding: 10px; margin-top: 20px;">Loading....</span></div>
    <div class="container">
    <h1><?php 
        echo $ps->camp_name;
        ?>
</h1>

    <table class="table table-bordered">
        <thead>
            <tr>
                <th>No.</th>
                <th>Date</th>
                <th>Is Test?</th>
                <th>Success</th>
                <th>Failure</th>
                <th>Summary</th>
                <th>Results</th>
            </tr>
            <?php 
        $cnt = 0;
        foreach ($arrs as $cc) {
            $cnt++;
            ?>
            <tr>
                <td>
                    <?php 
            echo $cnt;
            ?>
                </td>
                <td>
                    <?php 
            echo indonesian_date($cc->gcm_date);
            ?>
                </td>
                <td>
                    <?php 
            if ($cc->gcm_test) {
                echo "Yes";
            } else {
                echo "No";
            }
            ?>
                </td>
                <td>
                    <?php 
            echo $cc->success;
            ?>
                </td>
                <td>
                    <?php 
            echo $cc->failure;
            ?>
                </td>
                <td>
                    <?php 
            echo round($cc->success / ($cc->failure + $cc->success) * 100, 3);
            echo " %";
            ?>
                </td>
                <td>
                    <button class="btn btn-primary" id="detail_<?php 
            echo $cc->multicast_id;
            ?>
">Details</button>
                    <div id="multicast_<?php 
            echo $cc->multicast_id;
            ?>
" style="padding: 10px; display: none;"></div>
                    <script>
                        $("#detail_<?php 
            echo $cc->multicast_id;
            ?>
").click(function(){

                            var isHidden = $( "#multicast_<?php 
            echo $cc->multicast_id;
            ?>
" ).is( ":hidden" );
                            if(isHidden) {
                                $.get("<?php 
            echo _SPPATH;
            ?>
PushNotResultsCaps/detail?id=<?php 
            echo $cc->multicast_id;
            ?>
", function (data) {
                                    $("#multicast_<?php 
            echo $cc->multicast_id;
            ?>
").html(data);
                                    $("#multicast_<?php 
            echo $cc->multicast_id;
            ?>
").show();
                                });
                            }
                            else{
                                $("#multicast_<?php 
            echo $cc->multicast_id;
            ?>
").hide();
                            }
                        });
                    </script>
                    <?php 
            //                    $ress = unserialize($cc->results);  pr($ress);
            ?>
                </td>
            </tr>
                <?php 
        }
        ?>
        </thead>

    </table>
    </div>

    <?php 
        //    pr($arrs);
        ?>
    <script>
        $(document).ajaxStart(function(){
            $("#wait").css("display", "block");
        });

        $(document).ajaxComplete(function(){
            $("#wait").css("display", "none");
        });
    </script>
    <style>
        .hasil{
            border: 1px dashed #cccccc;
            margin: 5px;
            padding: 5px;
        }
        .red{
            color:red;
        }
        .green{
            color :darkgreen;
        }
    </style>
    </body>

    </html>

    <?php 
    }