public function overwriteRead($return)
 {
     $return = parent::overwriteRead($return);
     $objs = $return['objs'];
     foreach ($objs as $obj) {
         if (isset($obj->testi_acc_id)) {
             $acc = new LL_Account();
             $acc->getByID($obj->testi_acc_id);
             $obj->testi_acc_id = $acc->macc_first_name . " " . $acc->macc_last_name;
         }
         if (isset($obj->testi_product_id)) {
             $acc = new LL_Article_WImage();
             $acc->getByID($obj->testi_product_id);
             $obj->testi_product_id = $acc->BaseArticleNameENG;
         }
         //
         if (isset($obj->testi_status)) {
             $obj->testi_status = $this->arrStatus[$obj->testi_status];
         }
     }
     return $return;
 }
 public function createDummyData()
 {
     //        die("tidak active");
     ?>
     <h1>Create Device Logger</h1>
     <?php 
     $dev = new DeviceLogger();
     //        $dev->getByID(1);
     //        $type = array("android","ios");
     for ($x = 0; $x < 100; $x++) {
         //random if ada account atau tidak
         $adaAcc = rand(0, 9);
         if ($adaAcc > 6) {
             $accID = 0;
         } else {
             $acc = new LL_Account();
             $r = rand(0, 113);
             $arrAcc = $acc->getOrderBy("macc_id ASC LIMIT {$r},1");
             $accku = $arrAcc[0];
             $accID = $accku->macc_id;
         }
         //random type
         $type = "ios";
         $rtype = rand(0, 9);
         if ($rtype > 2) {
             $type = "android";
         }
         $minusan = 12620550 - $x * 100;
         //            $minusan = 75000;
         //random date
         $int = mt_rand(time() - $minusan, time());
         $log = new DeviceLogger();
         $log->log_acc_id = $accID;
         $log->log_dev_id = "dev_" . $accID;
         $log->log_dev_type = $type;
         $log->log_date = date("Y-m-d H:i:s", $int);
         echo $log->save();
         if ($accID) {
             $accl = new LL_AccountLogger();
             $accl->log_acc_id = $accID;
             $accl->log_date = date("Y-m-d H:i:s", $int);
             echo $accl->save();
         }
     }
 }
    function test()
    {
        IMBAuth::checkOAuth();
        $id = addslashes($_GET['id']);
        //        echo $id;
        if ($id == "" || $id < 1) {
            die("No ID");
        }
        $ps = new PushNotCamp();
        $ps->getByID($id);
        $llacc = new LL_Account();
        $arrAcc = $llacc->getOrderBy("macc_first_name ASC");
        ?>
<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">
        <h4>Test Push Notification for</h4>
        <h1><?php 
        echo $ps->camp_name;
        ?>
</h1>
        Input Customer ID's <input class="form-control" type="text" id="ids" value="1576199,512260">
        <br><i>separated by commas</i><br><br>
        <button id="push" class="btn btn-danger">Push</button>
        <div id="testresults" style="background-color: #dedede; margin-top: 40px; padding: 20px;display: none;"></div>
    </div>

    <script>
        $("#push").click(function(){

            var ids = $("#ids").val();

            $.post("<?php 
        echo _SPPATH;
        ?>
PushNotResults/pusher?token=<?php 
        echo $_GET['token'];
        ?>
",{
                camp_id : <?php 
        echo $id;
        ?>
,
                ids : ids
            } ,function (data) {
//                alert(data);
                $("#testresults").show();
                $("#testresults").html(data);
            });

        });
    </script>
    <?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 
    }
    function demographic()
    {
        $bulan = addslashes($_GET['m']);
        if ($bulan == "") {
            $bulan = date("F Y");
            $days_ago = date('Y-m-01');
            // hard-coded '01' for first day
            $days_now = date('Y-m-t');
        } else {
            $bulan = urldecode($bulan);
            $days_ago = date('Y-m-01', strtotime($bulan));
            // hard-coded '01' for first day
            $days_now = date('Y-m-t', strtotime($bulan));
        }
        $numberDays = cal_days_in_month(CAL_GREGORIAN, date('n', strtotime($bulan)), date('Y', strtotime($bulan)));
        $days_ago = date('Y-m-01', strtotime($bulan));
        // hard-coded '01' for first day
        $days_now = date('Y-m-01', strtotime('+1 month', strtotime($bulan)));
        $t = time();
        //male female
        $ll = new LL_Account();
        global $db;
        $query3 = "Select (Select count(*) from {$ll->table_name} where macc_gender='Male' AND (macc_acquire_date BETWEEN '{$days_ago}' AND '{$days_now}')) AS Male,\n(Select count(*) from {$ll->table_name} where macc_gender='Female' AND (macc_acquire_date BETWEEN '{$days_ago}' AND '{$days_now}')) AS Female ";
        $gender = $db->query($query3, 1);
        //        pr($gender);
        //        macc_lyb_status
        $query4 = "Select (Select count(*) from {$ll->table_name} where macc_lyb_status='LYB Club' AND (macc_acquire_date BETWEEN '{$days_ago}' AND '{$days_now}')) AS Club,\n(Select count(*) from {$ll->table_name} where macc_lyb_status='The Body Shop Friend' AND (macc_acquire_date BETWEEN '{$days_ago}' AND '{$days_now}')) AS Stampcard,\n(Select count(*) from {$ll->table_name} where macc_lyb_status='LYB Fan' AND (macc_acquire_date BETWEEN '{$days_ago}' AND '{$days_now}')) AS Fan ";
        $lyb = $db->query($query4, 1);
        //        pr($lyb);
        //macc_address_city
        //        $query5="SELECT DISTINCT macc_address_city FROM {$ll->table_name} ";
        //
        //        $cities = $db->query($query5,2);
        ////        pr($cities);
        //
        //        foreach($cities as $number=>$city){
        //            if($city->macc_address_city!="") {
        //                $city->macc_address_city = str_replace(".","",$city->macc_address_city);
        //                $city->macc_address_city = str_replace(",","",$city->macc_address_city);
        //                $text[] = "(Select count(*) as count from {$ll->table_name} where macc_address_city='{$city->macc_address_city}' AND (macc_acquire_date BETWEEN '$days_ago' AND '$days_now')) AS " . str_replace("/", "", str_replace(" ", "", str_replace("-", "", $city->macc_address_city)));
        //            }
        ////            if($number>10)break;
        //        }
        ////        pr($text);
        //        $imp = "Select ". implode(",",$text)." ORDER BY count DESC";
        global $db;
        $q = "SELECT macc_address_city,COUNT(*) as count FROM {$ll->table_name} GROUP BY macc_address_city ORDER BY count DESC LIMIT 0,20";
        $arrSl = $db->query($q, 2);
        //        pr($arrSl);
        //        echo $imp;
        //        $nrcities = $db->query($imp,2);
        //        pr($nrcities);
        ?>
<div class="row">
    <div class="col-md-12">
        <h1>
            Demographic Dashboard
            <small><?php 
        echo $bulan;
        ?>
</small>
        </h1>
        <ol class="breadcrumb">
            <li>
                <?php 
        echo Lang::t('Select Timeframe');
        ?>
            </li>
            <li class="active">
                <?php 
        $start = new DateTime('11 months ago');
        // So you don't skip February if today is day the 29th, 30th, or 31st
        $start->modify('first day of this month');
        $end = new DateTime();
        $interval = new DateInterval('P1M');
        $period = new DatePeriod($start, $interval, $end);
        ?>
                <select id="apptimeselector_<?php 
        echo $t;
        ?>
">
                    <?php 
        foreach ($period as $dt) {
            ?>
                        <option value="<?php 
            echo urlencode($dt->format('F Y'));
            ?>
" <?php 
            if ($dt->format('F Y') == $bulan) {
                echo "selected";
            }
            ?>
>
                            <?php 
            echo $dt->format('F Y') . "<br>";
            ?>
                        </option>
                    <?php 
        }
        ?>

                </select>
                <script>
                    $("#apptimeselector_<?php 
        echo $t;
        ?>
").change(function(){
                        var slc = $("#apptimeselector_<?php 
        echo $t;
        ?>
").val();
                        openLw("Demographic","<?php 
        echo _SPPATH;
        ?>
BIWebDemographic/demographic?m="+slc,"fade");
                    });
                </script>
            </li>
        </ol>
    </div>
</div>

        <?php 
        $arrUserswPic = $ll->getWhere("macc_foto != '' AND (macc_acquire_date BETWEEN '{$days_ago}' AND '{$days_now}') ORDER BY macc_acquire_date DESC LIMIT 0,8");
        $arrUsers = $ll->getOrderBy(" macc_acquire_date DESC LIMIT 0,8");
        ?>
        <div class="row">
            <!--<div class="col-md-6">

                <div class="box box-danger">
                    <div class="box-header with-border">
                        <h3 class="box-title">Latest Members</h3>

                        <div class="box-tools pull-right">
                            <span class="label label-danger">8 New Members</span>
                            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                            </button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i>
                            </button>
                        </div>
                    </div>

                    <div class="box-body no-padding">
                        <ul class="users-list clearfix">
                            <?php 
        foreach ($arrUsers as $user) {
            if ($user->macc_foto == "") {
                $url = _SPPATH . "images/noimage.jpg";
            } else {
                $url = "http://43.231.128.129/" . $user->macc_foto;
            }
            ?>
                            <li>
                                <img src="<?php 
            echo $url;
            ?>
" alt="<?php 
            echo $user->macc_first_name . " " . $user->macc_last_name;
            ?>
">
                                <a class="users-list-name" href="#"><?php 
            echo $user->macc_first_name . " " . $user->macc_last_name;
            ?>
</a>
                                <span class="users-list-date"><?php 
            echo ago(strtotime($user->macc_acquire_date));
            ?>
</span>
                            </li>
                            <?php 
        }
        ?>

                        </ul>

                    </div>

                    <div class="box-footer text-center">
                        <a href="javascript::" class="uppercase">View All Users</a>
                    </div>

                </div>

            </div>
            -->
            <div class="col-md-6">
                <!-- USERS LIST -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">Latest Customers</h3>

                        <!--<div class="box-tools pull-right">
                            <span class="label label-danger">8 New Members</span>
                            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                            </button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i>
                            </button>
                        </div>-->
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body no-padding">
                        <ul class="users-list clearfix">
                            <?php 
        foreach ($arrUserswPic as $user) {
            ?>
                                <li style="height: 160px;">
                                    <img src="<?php 
            echo _LOKASI;
            echo $user->macc_foto;
            ?>
" alt="User Image">
                                    <span class="users-list-name" ><?php 
            echo $user->macc_first_name . " " . $user->macc_last_name;
            ?>
</span>
                                    <span class="users-list-date"><?php 
            echo ago(strtotime($user->macc_acquire_date));
            ?>
</span>
                                </li>
                            <?php 
        }
        ?>

                        </ul>
                        <!-- /.users-list -->
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer text-center">
                        <a href="javascript:openLw('LL_Account', '<?php 
        echo _SPPATH;
        ?>
LLAccWeb/LL_Account', 'fade'); activkanMenuKiri('LL_Account');" class="uppercase">View All Customers</a>
                    </div>
                    <!-- /.box-footer -->
                </div>
                <!--/.box -->
            </div>

            <?php 
        $arrColor = array("#00a65a", "#00c0ef");
        $c = new Charting();
        $c->color = array_pop($arrColor);
        $c->label = "Male";
        $c->value = $gender->Male;
        $arrData[] = $c;
        $c = new Charting();
        $c->color = array_pop($arrColor);
        $c->label = "Female";
        $c->value = $gender->Female;
        $arrData[] = $c;
        ?>
<div class="col-md-3"><?php 
        Charting::morrisDonut("287px", $arrData, 1, "Gender", "default");
        ?>

            </div>
            <?php 
        $arrColor = array("#4da65a", "#7bcd03", "#53ddde");
        $arrData = array();
        $c = new Charting();
        //            $c->color = array_pop($arrColor);
        $c->color = "#e90057";
        $c->label = "Fan";
        $c->value = $lyb->Fan;
        $arrData[] = $c;
        $c = new Charting();
        //            $c->color = array_pop($arrColor);
        $c->color = "#cd6949";
        $c->label = "Club";
        $c->value = $lyb->Club;
        $arrData[] = $c;
        $c = new Charting();
        //            $c->color = array_pop($arrColor);
        $c->color = "#f4bb1b";
        $c->label = "Stampcard";
        $c->value = $lyb->Stampcard;
        $arrData[] = $c;
        ?>
<div class="col-md-3"><?php 
        Charting::morrisDonut("287px", $arrData, 1, "Member Type", "default");
        ?>

            </div>

            <?php 
        $arrData = array();
        $arrlegend = array();
        foreach ($arrSl as $attr => $value) {
            if ($value->macc_address_city == "") {
                $value->macc_address_city = "Unknown";
            }
            $c = new Charting();
            $c->color = "#" . $this->random_color();
            $c->label = str_replace(" ", "_", $value->macc_address_city);
            $c->value = $value->count;
            $arrData[] = $c;
            //                $arrlegend[$attr] = $value;
        }
        //            asort($arrlegend);
        //pr($arrlegend);
        //            $arrlegend = array_reverse($arrlegend,1);
        //            $arrData = array();
        //            foreach($arrSl as $attr=>$value){
        //                $c = new Charting();
        //                $c->color = "#".$this->random_color();
        //
        //                $c->label = str_replace(" ","_",$value->macc_address_city);
        //                $c->value = $value->count;
        //
        ////                $c->label = ucwords(strtolower(str_replace("_"," ",$attr)));
        ////                $c->value = $value;
        //                $arrData[] = $c;
        //                $arrColors[$attr] = $c->color;
        ////                $arrlegend[$attr] = $value;
        //            }
        ?>
        </div>

        <div class="row">
            <div class="col-md-12">
                <div class="box box-default">
                    <div class="box-header with-border">
                        <h3 class="box-title">Locations</h3>

                        <div class="box-tools pull-right">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                            </button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                        </div>
                    </div>
                    <div class="box-body chart-responsive">

                <div class="col-md-6">
                <?php 
        Charting::morrisDonut("300px", $arrData, 0, "Locations", "default", 0);
        ?>
                </div>
                <div class="col-md-6">
                    <?php 
        ?>
                    <ul class="nav nav-pills nav-stacked">
                        <?php 
        foreach ($arrSl as $attr => $value) {
            if ($value->macc_address_city == "") {
                $value->macc_address_city = "Unknown";
            }
            ?>
                        <li style="line-height: 30px;">
                            <div style="margin-top:5px; float: left; width: 20px; height: 20px; background-color: <?php 
            echo $arrColors[$attr];
            ?>
;"></div>
                            &nbsp; <?php 
            echo ucwords(str_replace("_", " ", strtolower($value->macc_address_city)));
            ?>
                                <span class="pull-right "> <?php 
            echo $value->count;
            ?>
</span></li>

                        <?php 
        }
        ?>
                    </ul>
                </div>

                    </div>
                    <!-- /.box-body -->
                </div>
            </div>
        </div>


        <style>
            ul.legend li{
                list-style: none;
                line-height: 30px;
            }
            ul.legend li div{
                float: left;
                margin-top: 10px;
                margin-right: 15px;
            }
            .legend-item{
                float: left;
                margin: 10px;
                line-height: 30px;
                margin-right: 5px;
            }
            .legend-item div{
                float: left;
                margin-top: 10px;
                margin-right: 5px;
            }
            .breadcrumb {
                padding: 8px 15px;
                margin-bottom: 20px;
                list-style: none;
                background-color: #f5f5f5;
                border-radius: 4px;
            }
            .breadcrumb {
                float: right;
                background: transparent;
                margin-top: 0;
                margin-bottom: 0;
                font-size: 12px;
                padding: 7px 5px;
                position: absolute;
                top: 15px;
                right: 10px;
                border-radius: 2px;
            }
            .users-list-name{
                white-space: nowrap;
            }
        </style>
<?php 
    }
 public static function parseToLLAccount($VRO)
 {
     $ll = new LL_Account();
     $ll->macc_ll_customer_id = (string) $VRO->CustomerBody->CustomerID;
     $ll->macc_id = (string) $VRO->CustomerBody->CustomerID;
     if (!$ll->macc_id) {
         return 0;
     }
     /*
      * cek apa di database sudah ada
      */
     $ll->getByID($ll->macc_id);
     if ($ll->macc_id != "" || $ll->macc_id != 0) {
         $ll->load = 0;
     }
     /*
      * cek if ada fb_id atau foto
      */
     $macc_foto = addslashes($_POST['macc_foto']);
     $macc_fb_id = addslashes($_POST['macc_fb_id']);
     if ($macc_foto != "") {
         $ll->macc_foto = Crud::savePic($macc_foto);
     }
     if ($macc_fb_id != "") {
         $ll->macc_fb_id = $macc_fb_id;
     }
     //insert name
     $arrName = $VRO->CustomerBody->EntityInformation->Individual->Name;
     foreach ($arrName->Name as $obj) {
         $var = self::xml_attribute($obj, 'TypeCode');
         //pr($obj);
         //echo "var : ".$var;
         if ($var == "FamilyName") {
             $ll->macc_last_name = (string) $obj;
         }
         if ($var == "GivenName") {
             $ll->macc_first_name = (string) $obj;
         }
         if ($var == "PreferredName") {
             $ll->macc_prefered_name = (string) $obj;
         }
     }
     if ($_GET['test']) {
         echo "names : ";
         pr($ll);
     }
     //insert dob
     $arrTelp = $VRO->CustomerBody->EntityInformation->Individual->ContactInformation->Telephone;
     foreach ($arrTelp as $obj) {
         $var = self::xml_attribute($obj, 'TypeCode');
         if ($var == "Home") {
             $ll->macc_phone_home = (string) $obj->LocalNumber;
         }
         if ($var == "Mobile") {
             $ll->macc_phone = (string) $obj->LocalNumber;
         }
         if ($var == "Work") {
             $ll->macc_phone_work = (string) $obj->LocalNumber;
         }
     }
     if ($_GET['test']) {
         echo "telp : ";
         pr($ll);
     }
     //Address
     $arrAddress = $VRO->CustomerBody->EntityInformation->Individual->ContactInformation->Address;
     $ll->macc_address = (string) $arrAddress->AddressLine;
     $ll->macc_address_city = (string) $arrAddress->City;
     $ll->macc_address_territory = (string) $arrAddress->Territory;
     $ll->macc_address_postalcode = (string) $arrAddress->PostalCode;
     $ll->macc_address_country = (string) $arrAddress->Country;
     //email
     $arrEmail = $VRO->CustomerBody->EntityInformation->Individual->ContactInformation->EMail;
     foreach ($arrEmail as $obj) {
         $var = self::xml_attribute($obj, 'TypeCode');
         if ($var == "Home") {
             $ll->macc_email = (string) $obj->EMailAddress;
         }
     }
     if ($_GET['test']) {
         echo "email : ";
         pr($ll);
     }
     //PersonalSummary
     $personalSum = $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary;
     foreach ($personalSum->attributes() as $a => $b) {
         //echo $a,'="',$b,"\"";
         //echo "IN $a $b";
         //echo "haloo ".$arrName->Name[$b];
         if ($a == "GenderType") {
             $ll->macc_gender = (string) $b;
         }
     }
     if ($_GET['test']) {
         echo "gender : ";
         pr($ll);
     }
     //insert dob
     $dob = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->BirthDate;
     $exp = explode("+", $dob);
     $ll->macc_dob = date("Y-m-d", strtotime($exp[0]));
     $ll->macc_card_nr = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->LoyaltyTokenID;
     $ll->macc_card_barcode = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->LoyaltyTokenBarcode;
     $ll->macc_member_type = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->MemberType;
     $ll->macc_member_tier = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->MemberTier;
     //real tier n type
     $ll->macc_real_member_type = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->MemberType;
     $ll->macc_real_tier = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->MemberTier;
     $tkdate = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->TokenIssueDate;
     $ll->macc_token_issue_date = date("Y-m-d h:i:s", strtotime($tkdate));
     $ll->macc_token_status = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->TokenStatus;
     if ($_GET['test']) {
         echo "members : ";
         pr($ll);
     }
     $ll->macc_member_mismatch = 0;
     //mismatch calculator
     if ($ll->macc_real_member_type == "STC" && $ll->macc_real_tier != "Stamp Card Member") {
         $ll->macc_member_mismatch = 1;
     }
     if ($ll->macc_real_member_type == "133") {
         if ($ll->macc_real_tier != "Fan" && $ll->macc_real_tier != "LYB Member") {
             $ll->macc_member_mismatch = 1;
         }
     }
     if ($ll->macc_real_member_type == "LYB") {
         if ($ll->macc_real_tier != "Fan" && $ll->macc_real_tier != "LYB Member") {
             $ll->macc_member_mismatch = 1;
         }
     }
     //converter member type Stamp card
     if ($ll->macc_member_tier == "Fan" || $ll->macc_member_tier == "LYB Member") {
         $ll->macc_member_type == "LYB";
     }
     //        if($ll->macc_member_tier == "Stamp Card Member") {
     //            $ll->macc_member_type == "STC";
     //        }
     //converter member type Stamp card
     if ($ll->macc_member_type == "STC") {
         //            $ll->macc_member_type = "STC";
         $ll->macc_member_tier = "Stamp Card Member";
     }
     //points
     $arrPoints = $VRO->CustomerBody->CustomerAccount->LoyaltyAccount->Points;
     //pr($arrPoints);
     $sem = array();
     $pointsDetails = array();
     foreach ($arrPoints as $obj) {
         $var = self::xml_attribute($obj, 'Type');
         $sem[$var] = (string) $obj;
         foreach ($obj->attributes() as $a => $b) {
             $pointsDetails[$var][$a] = (string) $b;
         }
     }
     if ($_GET['test']) {
         echo "points : ";
         pr($ll);
     }
     //sementara pakai balance
     $ll->macc_points = $sem['Balance'];
     //sementara saja
     $ll->macc_point_details = serialize(array("points" => $sem, "details" => $pointsDetails));
     //$this->points_details = $pointsDetails;
     return $ll;
 }
 static function kerjakan($psn)
 {
     //cek apakah ada acc_id, kalau ada..forget filter
     $cols = "macc_id,macc_first_name,macc_last_name";
     $acc = $psn->camp_acc_id;
     if ($acc != "" || $psn->camp_account_file != "") {
         $arrAcc = array();
         if ($acc != "") {
             $exp = explode(",", $psn->camp_acc_id);
             foreach ($exp as $ac) {
                 $arrAcc[] = trim(rtrim($ac));
             }
             //from acc get device ID
             //                self::sendUsingAccountArray($arrAcc, $psn);
         }
         if ($psn->camp_account_file != "") {
             $row = 1;
             $if = new InputFileModel();
             //                $arrAcc = array();
             if (($handle = fopen($if->upload_location . $psn->camp_account_file, "r")) !== FALSE) {
                 $csv = fread($handle, filesize($if->upload_location . $psn->camp_account_file));
                 $arrsem = explode(",", $csv);
                 foreach ($arrsem as $acs) {
                     $arrAcc[] = trim(rtrim($acs));
                 }
                 //                    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                 //
                 //                        $arrAcc[] = trim(rtrim($data[0]));
                 //
                 //                    }
                 fclose($handle);
             }
             //                pr($arrAcc);
             //from acc get device ID
             //                self::sendUsingAccountArray($arrAcc, $psn);
             //                die();
         }
         self::sendUsingAccountArray($arrAcc, $psn);
     } else {
         //bukan acc, brati filter aktif
         //cek contradictives constraints
         $arrwhere = array();
         //gender check
         $query_gender = "";
         if ($psn->camp_filter_gender != '0') {
             if ($psn->camp_filter_gender == '1') {
                 $query_gender = "macc_gender = 'Female'";
             } else {
                 $query_gender = "macc_gender = 'Male'";
             }
             $arrwhere[] = $query_gender;
         }
         //tier check
         $query_tier = "";
         if ($psn->camp_filter_tier != '0') {
             if ($psn->camp_filter_tier == '1') {
                 //stampcard
                 $query_tier = "(macc_member_type = 'STC')";
             } elseif ($psn->camp_filter_tier == '2') {
                 //club
                 $query_tier = "macc_member_tier = 'LYB Member'";
             } elseif ($psn->camp_filter_tier == '3') {
                 //fan
                 $query_tier = "macc_member_tier = 'Fan'";
             } else {
                 //all lyb
                 //                    $query_tier = "(macc_member_tier = 'LYB Member' OR macc_member_tier = 'Fan')";
                 $query_tier = "(macc_member_tier = 'LYB Member' OR macc_member_tier = 'Fan')";
             }
             $arrwhere[] = $query_tier;
         }
         //city check
         $query_city = "";
         if ($psn->camp_filter_city != 'all') {
             $query_city = "macc_address_city = '{$psn->camp_filter_city}' ";
             $arrwhere[] = $query_city;
         }
         //birthday cek
         //camp_filter_bday
         $query_bday = "";
         if ($psn->camp_filter_bday != '0') {
             if ($psn->camp_filter_bday == '1') {
                 //has birthday today
                 $query_bday = "macc_dob = CURDATE()";
             } else {
                 //today not his/her bday
                 $query_bday = "macc_dob != CURDATE()";
             }
             $arrwhere[] = $query_bday;
         }
         //camp age cek
         //using inputfilter..
         $query_age = "";
         if ($psn->camp_filter_age != "") {
             $exp = explode("__", $psn->camp_filter_age);
             //                $cols = "macc_id,TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) AS age";
             if ($exp[0] == "=") {
                 $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) = " . $exp[1];
             }
             if ($exp[0] == "!=") {
                 $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) != " . $exp[1];
             }
             if ($exp[0] == "<") {
                 $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) < " . $exp[1];
             }
             if ($exp[0] == ">") {
                 $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) > " . $exp[1];
             }
             if ($exp[0] == "<=") {
                 $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) <= " . $exp[1];
             }
             if ($exp[0] == ">=") {
                 $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) >= " . $exp[1];
             }
             $arrwhere[] = $query_age;
         }
         //now calculate the query
         $acc = new LL_Account();
         $arrAcc = array();
         //            pr($arrwhere);
         //            echo $cols;
         if (count($arrwhere) > 0) {
             $where = implode(" AND ", $arrwhere);
             echo $where;
             $arrAcc = $acc->getWhere($where, $cols);
         } else {
             $arrAcc = $acc->getAll();
         }
         $arrSend = array();
         //masukan ke 1 array
         foreach ($arrAcc as $cc) {
             $arrSend[] = $cc->macc_id;
         }
         //from acc get device ID
         self::sendUsingAccountArray($arrSend, $psn);
     }
 }
    function testPush()
    {
        $acc = new LL_Account();
        $arrAcc = $acc->getAll();
        $inputID = "to";
        ?>
    <form method="post" action="<?php 
        echo _SPPATH;
        ?>
PushNotBE/send" id="sendPN">
        <div id="formgroup" class="form-group">
            <label for="<?php 
        echo $inputID;
        ?>
" class="col-sm-2 control-label"><?php 
        echo Lang::t($inputID);
        ?>
</label>

            <div class="col-sm-10">
                <select class="form-control" id="<?php 
        echo $inputID;
        ?>
" name="<?php 
        echo $inputID;
        ?>
">
                    <?php 
        foreach ($arrAcc as $acc) {
            ?>
                        <option value="<?php 
            echo $acc->macc_id;
            ?>
"><?php 
            echo $acc->macc_first_name;
            ?>
 <?php 
            echo $acc->macc_last_name;
            ?>
</option>
                    <?php 
        }
        ?>
                </select>
                <span class="help-block" id="warning_<?php 
        echo $inputID;
        ?>
"></span>
            </div>
<?php 
        $inputID = 'msg';
        ?>
            <label for="<?php 
        echo $inputID;
        ?>
" class="col-sm-2 control-label"><?php 
        echo Lang::t($inputID);
        ?>
</label>

            <div class="col-sm-10">
                <input class="form-control" type="text" id="<?php 
        echo $inputID;
        ?>
" name="<?php 
        echo $inputID;
        ?>
" placeholder="<?php 
        echo Lang::t($inputID);
        ?>
">
                <span class="help-block" id="warning_<?php 
        echo $inputID;
        ?>
"></span>
            </div>

            <?php 
        $inputID = 'action';
        ?>
            <div style="display: none;">
            <label for="<?php 
        echo $inputID;
        ?>
" class="col-sm-2 control-label"><?php 
        echo Lang::t($inputID);
        ?>
</label>

            <div class="col-sm-10" >
                <input class="form-control" type="url" id="<?php 
        echo $inputID;
        ?>
" name="<?php 
        echo $inputID;
        ?>
" placeholder="<?php 
        echo Lang::t($inputID);
        ?>
">
                <span class="help-block" id="warning_<?php 
        echo $inputID;
        ?>
"></span>
            </div>
            </div>
        </div>
        <button type="submit" class="btn btn-default btn-lg"><?php 
        echo Lang::t('Send');
        ?>
</button>

    </form>

        <script type="text/javascript">
            // console.log(array_rte);
            $("#sendPN").submit(function (event) {
                //alert( "Handler for .submit() called." );



                // Stop form from submitting normally
                event.preventDefault();

                // Get some values from elements on the page:
                var $form = $(this),
                    url = $form.attr("action");

                // Send the data using post
                var posting = $.post(url, $form.serialize(), function (data) {
//                    alert(data);
                    console.log( data ); // John
                    //console.log( data.bool ); // 2pm
                    if(data.bool){
                        alert('Success');
                    }else{
                        var obj = data.err;
//                        var tim = data.timeId;
                        //console.log( obj );
                        for (var property in obj) {
//                            alert(property);

                            if (obj.hasOwnProperty(property)) {

                                alert(obj[property]);

                            }
                        }
                    }
                },'json');


            });
        </script>
    <?php 
    }
    function main()
    {
        $mtrans = new MTranDetail();
        //        global $db;
        //        $q = "SELECT SUM(detail_price_total) as total, COUNT(*) AS num FROM {$mtrans->table_name}";
        //        $arr = $db->query($q,1);
        //        pr($arr);
        $arrOrder = $mtrans->getOrderBy(" detail_date DESC LIMIT 0,5");
        //        pr($arrOrder);
        ?>

        <h1 style="margin-top: 0;">Dashboard</h1>
        <div class="penjualan_container">
        <?php 
        BIPenjualan::graph();
        ?>
        </div>

        <div class="row">
            <div class="col-md-6" style="padding-top: 20px;">
                <div class="penjualan_container">

                    <h2 class="penjualan_money_h2">Lifetime Sales</h2>
                    <table class="table no-margin">
                        <thead>
                        <tr>
                            <th>Order ID</th>
                            <th>Item</th>
                            <th>Status</th>
                            <th>Popularity</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td><a href="pages/examples/invoice.html">OR9842</a></td>
                            <td>Call of Duty IV</td>
                            <td><span class="label label-success">Shipped</span></td>
                            <td>
                                <div class="sparkbar" data-color="#00a65a" data-height="20"><canvas width="34" height="20" style="display: inline-block; width: 34px; height: 20px; vertical-align: top;"></canvas></div>
                            </td>
                        </tr>
                        <tr>
                            <td><a href="pages/examples/invoice.html">OR1848</a></td>
                            <td>Samsung Smart TV</td>
                            <td><span class="label label-warning">Pending</span></td>
                            <td>
                                <div class="sparkbar" data-color="#f39c12" data-height="20"><canvas width="34" height="20" style="display: inline-block; width: 34px; height: 20px; vertical-align: top;"></canvas></div>
                            </td>
                        </tr>
                        <tr>
                            <td><a href="pages/examples/invoice.html">OR7429</a></td>
                            <td>iPhone 6 Plus</td>
                            <td><span class="label label-danger">Delivered</span></td>
                            <td>
                                <div class="sparkbar" data-color="#f56954" data-height="20"><canvas width="34" height="20" style="display: inline-block; width: 34px; height: 20px; vertical-align: top;"></canvas></div>
                            </td>
                        </tr>
                        <tr>
                            <td><a href="pages/examples/invoice.html">OR7429</a></td>
                            <td>Samsung Smart TV</td>
                            <td><span class="label label-info">Processing</span></td>
                            <td>
                                <div class="sparkbar" data-color="#00c0ef" data-height="20"><canvas width="34" height="20" style="display: inline-block; width: 34px; height: 20px; vertical-align: top;"></canvas></div>
                            </td>
                        </tr>
                        <tr>
                            <td><a href="pages/examples/invoice.html">OR1848</a></td>
                            <td>Samsung Smart TV</td>
                            <td><span class="label label-warning">Pending</span></td>
                            <td>
                                <div class="sparkbar" data-color="#f39c12" data-height="20"><canvas width="34" height="20" style="display: inline-block; width: 34px; height: 20px; vertical-align: top;"></canvas></div>
                            </td>
                        </tr>
                        <tr>
                            <td><a href="pages/examples/invoice.html">OR7429</a></td>
                            <td>iPhone 6 Plus</td>
                            <td><span class="label label-danger">Delivered</span></td>
                            <td>
                                <div class="sparkbar" data-color="#f56954" data-height="20"><canvas width="34" height="20" style="display: inline-block; width: 34px; height: 20px; vertical-align: top;"></canvas></div>
                            </td>
                        </tr>
                        <tr>
                            <td><a href="pages/examples/invoice.html">OR9842</a></td>
                            <td>Call of Duty IV</td>
                            <td><span class="label label-success">Shipped</span></td>
                            <td>
                                <div class="sparkbar" data-color="#00a65a" data-height="20"><canvas width="34" height="20" style="display: inline-block; width: 34px; height: 20px; vertical-align: top;"></canvas></div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <div class="row">
        <div class="col-md-3">
            <div class="penjualan_container">
            <div class="penjualan">
                <h2 class="penjualan_money_h2">Lifetime Sales</h2>
                <div class="penjualan_money" style="color: #e2007a;">IDR <?php 
        echo idr($arr->total);
        ?>
</div>
            </div>

            <div class="penjualan">
                <h2 class="penjualan_money_h2">Average Order</h2>
                <div class="penjualan_money">IDR <?php 
        echo idr($arr->total / $arr->num);
        ?>
</div>
            </div>
            <hr>

                <div class="penjualan">
                    <h2 class="penjualan_money_h2" style="margin-bottom: 10px;">Latest Transactions</h2>
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>Customer</th>
<!--                            <th>Qty</th>-->
                            <th>Total</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php 
        foreach ($arrOrder as $order) {
            ?>
                                <tr>
                                    <td><?php 
            if ($order->detail_macc_id > 0) {
                $llac = new LL_Account();
                $llac->getByID($order->detail_macc_id);
                echo $llac->macc_first_name;
            } else {
                echo "unknown";
            }
            ?>
</td>
<!--                                    <td>--><?php 
            //=$order->detail_qty;
            ?>
<!--</td>-->
                                    <td>IDR <?php 
            echo idr($order->detail_price_total);
            ?>
</td>
                                </tr>
                                <?php 
        }
        ?>
                        </tbody>
                    </table>
                </div>
                <hr>
                <div class="penjualan">
                    <h2 class="penjualan_money_h2" style="margin-bottom: 20px;">Last Search Terms</h2>
                    <?php 
        $sL = new MSearchLog();
        $arrSl = $sL->getOrderBy("slog_date DESC LIMIT 0,30");
        if (count($arrSl) > 0) {
            $slsudah = array();
            ?>
                        <table class="table table-striped"><?php 
            foreach ($arrSl as $sll) {
                if (!in_array($sll->slog_keyword, $slsudah)) {
                    $slsudah[] = $sll->slog_keyword;
                    ?>
                                <tr>
                                    <td>
                                        <div class="searchkeyword"><?php 
                    echo $sll->slog_keyword;
                    ?>
</div>
                                    </td>
                                </tr>

                            <?php 
                }
            }
            ?>
</table><?php 
        } else {
            ?>
                        <p>We couldn't find any records.</p>
                        <?php 
        }
        ?>
                </div>
                <hr>
                <div class="penjualan">
                    <h2 class="penjualan_money_h2" style="margin-bottom: 20px;">Top Search Terms</h2>
                    <?php 
        $sL = new MSearchLog();
        global $db;
        $q = "SELECT slog_keyword,COUNT(*) as count FROM {$sL->table_name} GROUP BY slog_keyword ORDER BY count DESC LIMIT 0,10";
        $arrSl = $db->query($q, 2);
        //                    pr($arrSl);
        //                    $arrSl = $sL->getOrderBy("slog_date DESC LIMIT 0,30");
        if (count($arrSl) > 0) {
            $slsudah = array();
            ?>
                        <table class="table table-striped"><?php 
            foreach ($arrSl as $sll) {
                if (!in_array($sll->slog_keyword, $slsudah)) {
                    $slsudah[] = $sll->slog_keyword;
                    ?>
                                <tr>
                                    <td>
                                        <div class="searchkeyword"><?php 
                    echo $sll->slog_keyword;
                    ?>
</div>
                                    </td>
                                    <td>
                                        <div class="searchkeyword"><?php 
                    echo $sll->count;
                    ?>
</div>
                                    </td>
                                </tr>

                            <?php 
                }
            }
            ?>
</table><?php 
        } else {
            ?>
                        <p>We couldn't find any records.</p>
                    <?php 
        }
        ?>
                </div>
            </div>
        </div>
        <style>
            .penjualan_container{
                border: 1px solid #dedede;
                background-color: white;
                padding: 20px;
            }
            .penjualan_money_h2{
                padding: 0;
                margin: 0;
                font-size: 20px;
                margin-bottom: 20px;
                color: #666666;
            }
            .penjualan_money{
                font-size: 25px;
            }
            .penjualan{
                margin-bottom: 20px;
            }
        </style>

            <div class="col-md-9">


                <div class="penjualan_container" style="margin-bottom: 20px;">


                    </div>
                <div class="penjualan_container">
                    <div>

                        <!-- Nav tabs -->
                        <ul class="nav nav-tabs" role="tablist">
                            <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
                            <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
                            <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
                            <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
                        </ul>

                        <!-- Tab panes -->
                        <div class="tab-content">
                            <div role="tabpanel" class="tab-pane active" id="home">ss...</div>
                            <div role="tabpanel" class="tab-pane" id="profile">.bb..</div>
                            <div role="tabpanel" class="tab-pane" id="messages">..cc.</div>
                            <div role="tabpanel" class="tab-pane" id="settings">..dd.</div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
        <div class="clearfix"></div>
        </div>
        <?php 
    }
 public static function setSession($data, $remember)
 {
     $_SESSION['member'] = $data;
     $_SESSION['member_token'] = self::generateRandomString(15);
     $_SESSION["member_session"] = 1;
     $acc = new LL_Account();
     $acc->macc_id = $data->macc_id;
     $acc->fill(toRow($data));
     $acc->macc_login_date = leap_mysqldate();
     $acc->macc_token = $_SESSION['member_token'];
     $acc->save(1);
     self::setCookie($data, $remember, $acc->macc_acquire_date);
     return array('id' => $data->macc_id, 'token' => $acc->macc_token, 'name' => $data->macc_first_name . " " . $data->macc_last_name);
 }
 public function getByFB()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $fb_id = addslashes($_POST['macc_fb_id']);
     $json = array();
     //$fb_id = addslashes($_POST['macc_fb_id']);
     if ($fb_id == "") {
         $json['status_code'] = 0;
         $json['status_message'] = "Invalid FB ID";
         echo json_encode($json);
         die;
     }
     //update di lokal saja
     $ll = new LL_Account();
     $arrLL = $ll->getWhere("macc_fb_id = '{$fb_id}' LIMIT 0,1");
     //kalau sudah terdaftar
     if (count($arrLL) > 0) {
         $ll = $arrLL[0];
         //ambil dari ll dengan macc_id ini untuk update status
         $VRO = VRCustModel::findByID($ll->macc_id);
         $json = VRCustMapper::kerjakan($VRO);
         echo json_encode($json);
         die;
     } else {
         $json['status_code'] = 0;
         $json['status_message'] = "User with this FB ID not Found";
     }
     echo json_encode($json);
     die;
 }
 public static function getAcquire($beginDate, $endDate)
 {
     //customer acquisition per day
     $ll = new LL_Account();
     $arrw = $ll->getWhere("(macc_acquire_date BETWEEN '{$beginDate}' AND '{$endDate}')", "macc_acquire_date");
     //        pr($arrw);
     //        echo count($arrw);
     $data = array();
     //for begin date sampai end date day by day
     $start = strtotime($beginDate);
     $finish = strtotime($endDate);
     while ($start <= $finish) {
         $label = date("d", $start);
         $start = strtotime('+1 day', $start);
         $xLabels[] = $label;
         $data[$label] = 0;
     }
     //        pr($xLabels);
     //manage data
     foreach ($arrw as $w) {
         $curdate = date("d", strtotime($w->macc_acquire_date));
         $data[$curdate]++;
     }
     //        pr($data);
     $arr = array_values($data);
     //        pr($arr);
     $c = new Charting();
     $c->label = "User Acquisition";
     $c->data = $arr;
     $c->color = "#AAAAAA";
     $arrData2[] = $c;
     Charting::chartJSLine("300px", $xLabels, $arrData2, "false", 0, 0, "User Acquisition", "info", 0);
     return $arrw;
 }
 public function findMy()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $id = isset($_GET['id']) ? addslashes($_GET['id']) : 0;
     if (!$id) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $acc = new LL_Account();
     $acc->getByID($id);
     $rew = new LL_RewardCatalog();
     //old masi pakai active
     // $arrReward = $rew->getWhere("rew_active = 1 ORDER BY rew_point DESC");
     $arrReward = $rew->getWhere("CURDATE() between rew_start and rew_end ORDER BY rew_point DESC");
     $arrStatus = $rew->arrStatus;
     $poin = (int) $acc->macc_points;
     $status = $acc->macc_lyb_status;
     //        print_r($status);
     //echo "pts ".$poin." ".$status;
     $my_status = 0;
     foreach ($arrStatus as $statid => $val) {
         if ($val == $status) {
             $my_status = $statid;
         }
     }
     //        pr($arrStatus);
     //pr($arrStatus);
     //echo "<br>mystatus ".$my_status;
     //expiry blom di consider krn nanti di cron job...
     $taruhbawah = array();
     $taruhatas = array();
     //urutkan sesuai yang bisa dan tidak bisa
     foreach ($arrReward as $rew) {
         if ($rew->rew_status > $my_status) {
             //kalau statusnya tidak cukup tinggi
             $taruhbawah[] = $rew;
             $rew->rew_problem = 3;
             //"gak_cukup_status";
         } else {
             if ($rew->rew_point > $poin) {
                 $rew->rew_problem = 2;
                 //"gak_cukup_poin";
                 $taruhbawah[] = $rew;
             } else {
                 $taruhatas[] = $rew;
                 $rew->rew_problem = 1;
                 //all clear
             }
         }
     }
     $json = array();
     //masukan ke satu array dan kirim
     $json['status_code'] = 1;
     foreach ($taruhatas as $rew) {
         $arrbaru = array();
         $arrbaru['id'] = $rew->rew_id;
         $arrbaru['pic'] = _PHOTOURL . $rew->rew_pic;
         $arrbaru['status'] = $rew->rew_problem;
         $arrbaru['point'] = $rew->rew_point;
         $arrbaru['member_type'] = $rew->rew_status;
         $arrbaru['aktif'] = $rew->rew_active;
         $arrbaru['rew_start'] = $rew->rew_start;
         $arrbaru['rew_end'] = $rew->rew_end;
         $json['results'][] = $arrbaru;
     }
     foreach ($taruhbawah as $rew) {
         $arrbaru = array();
         $arrbaru['id'] = $rew->rew_id;
         $arrbaru['pic'] = _PHOTOURL . $rew->rew_pic;
         $arrbaru['status'] = $rew->rew_problem;
         $arrbaru['point'] = $rew->rew_point;
         $arrbaru['member_type'] = $rew->rew_status;
         $arrbaru['aktif'] = $rew->rew_active;
         $arrbaru['rew_start'] = $rew->rew_start;
         $arrbaru['rew_end'] = $rew->rew_end;
         $json['results'][] = $arrbaru;
     }
     echo json_encode($json);
     die;
 }