public function __construct()
 {
     $this->tree_multi_user_constraint = array("cat_app_id" => AppAccount::getAppID());
 }
 public function constraints_old()
 {
     //err id => err msg
     $err = array();
     if (!isset($this->prod_pic)) {
         $err['prod_pic'] = Lang::t('Picture must be provided');
     } else {
         //            $src = _PHOTOPATH.$this->camp_pic;
         //            list($iWidth,$iHeight,$type)    = getimagesize($src);
         //            if(round($iWidth/$iHeight,1) != round($this->ratio_weight/$this->ratio_height,1)){
         //                $err['camp_pic'] = Lang::t('Proportion is not right, please crop using our tool');
         //            }
     }
     if (!isset($this->prod_name)) {
         $err['prod_name'] = Lang::t('Please provide Name');
     }
     if (!isset($this->prod_des)) {
         $err['prod_des'] = Lang::t('Description cannot be empty');
     }
     if (!isset($this->prod_price)) {
         $err['prod_price'] = Lang::t('Price cannot be empty');
     }
     if (!isset($this->prod_cat_id)) {
         $err['prod_cat_id'] = Lang::t('Category cannot be empty');
     }
     if (!isset($this->prod_stock)) {
         $err['prod_stock'] = Lang::t('Stock cannot be empty');
     }
     if (!isset($this->prod_attribute_array)) {
         $err['prod_attribute_array'] = Lang::t('Attribute cannot be empty');
     }
     $this->prod_app_id = AppAccount::getAppID();
     //cek apakah paket sesuai dengan yg diperbolehkan
     $app = AppAccount::getActiveAppObject();
     //carousel 1_5
     $carousel_id = $app->app_paket_id . "_8";
     $mm = new PaketMatrix();
     $mm->getByID($carousel_id);
     $limit = $mm->ps_isi;
     //get all campaign dengan app_id dan type yg diperbolehkan
     $nr = $this->getJumlah("prod_app_id = '{$this->prod_app_id}' AND prod_active = 1");
     if ($this->prod_active) {
         if ($nr >= $limit) {
             $err['prod_active'] = Lang::t('Too many products active!! Please deactivate the others. Limit is ' . $limit);
         }
     }
     //        $err['prod_active'] = Lang::t($nr.' Too many products active!! Please deactivate the others. Limit is '.$limit);
     //        $this->camp_updatedate = leap_mysqldate();
     return $err;
 }
    function getMatrix()
    {
        $cid = addslashes($_GET['cid']);
        //get campaign for owner verification
        $camms = new MCampaignModel();
        $camms->getByID($cid);
        if ($camms->camp_app_id != AppAccount::getAppID()) {
            die("Not Allowed");
        }
        $as = new MCampaignMatrix();
        $arr = $as->getWhere("cm_camp_id = '{$cid}'");
        $arrProd = $_SESSION['arrProd'];
        foreach ($arrProd as $pp) {
            $arrProds[$pp->prod_id] = $pp;
        }
        //pr($arrProds);
        //pr($arr);
        $t = time();
        ?>
        <div class="col-md-6">
            <?php 
        foreach ($arr as $g) {
            $prod = $arrProds[$g->cm_prod_id];
            $sudahAda[] = $g->cm_prod_id;
            ?>
                <div class="productcamp">

                    <div class="productcamp_title">

                        <div style="float:right;width: 20px;">
                            <i id="cm_<?php 
            echo $g->cm_id;
            ?>
" class="glyphicon glyphicon-arrow-right" style="cursor:pointer;"></i>
                        </div>
                        <?php 
            echo $prod->prod_name;
            ?>
                    </div>
                </div>
                <script>
                    $("#cm_<?php 
            echo $g->cm_id;
            ?>
").click(function(){
                        $.get("<?php 
            echo _SPPATH;
            ?>
MCampApp/delMatrix?cmid=<?php 
            echo $g->cm_id;
            ?>
",function(data){
                            console.log(data);
                            if(data.bool){
                                $("#camp_matrix").load("<?php 
            echo _SPPATH;
            ?>
MCampApp/getMatrix?cid=<?php 
            echo $cid;
            ?>
");
                            }else{
                                alert('<?php 
            echo Lang::t('Delete Error');
            ?>
');
                            }
                        },'json');
                    });
                </script>
            <?php 
        }
        ?>
        </div>
        <div class="col-md-6" >
            <div style="background-color: #AAA; margin: 5px; padding: 10px; ">
                <div class="input-group">
                    <span class="input-group-addon" id="basic-addon1">Select Product To Insert to Campaign</span>

                </div>
                <div class="input-group">
            <span class="input-group-btn">
                <button id="add_to_camp_<?php 
        echo $t;
        ?>
" class="btn btn-default" type="button"><i class="glyphicon glyphicon-arrow-left"></i></button>
            </span>
                    <select id="sel_to_camp_<?php 
        echo $t;
        ?>
" class="form-control">
                        <?php 
        foreach ($arrProds as $key => $prod) {
            if (in_array($key, $sudahAda)) {
                continue;
            }
            ?>
                            <option value="<?php 
            echo $prod->prod_id;
            ?>
"><?php 
            echo $prod->prod_name;
            ?>
</option>
                        <?php 
        }
        ?>
                    </select>
                </div><!-- /input-group -->
            </div>
        </div>
        <script>
            $("#add_to_camp_<?php 
        echo $t;
        ?>
").click(function(){
                var slc = $("#sel_to_camp_<?php 
        echo $t;
        ?>
").val();
                $.get("<?php 
        echo _SPPATH;
        ?>
MCampApp/insProd?cid=<?php 
        echo $cid;
        ?>
&pid="+slc,function(data){
                    console.log(data);
                    if(data.bool){
                        $("#camp_matrix").load("<?php 
        echo _SPPATH;
        ?>
MCampApp/getMatrix?cid=<?php 
        echo $cid;
        ?>
");
                    }else{
                        alert('<?php 
        echo Lang::t('Insert Error');
        ?>
');
                    }
                },'json');
            });

        </script>
        <?php 
        exit;
    }
 public function constraints()
 {
     //err id => err msg
     $err = array();
     if (!isset($this->camp_pic)) {
         $err['camp_pic'] = Lang::t('Picture must be provided');
     } else {
         $src = _PHOTOPATH . $this->camp_pic;
         list($iWidth, $iHeight, $type) = getimagesize($src);
         if (round($iWidth / $iHeight, 1) != round($this->ratio_weight / $this->ratio_height, 1)) {
             $err['camp_pic'] = Lang::t('Proportion is not right, please crop using our tool');
         }
     }
     if (!isset($this->camp_name)) {
         $err['camp_name'] = Lang::t('Please provide carousel photo');
     }
     if (!isset($this->camp_descr)) {
         $err['camp_descr'] = Lang::t('Description cannot be empty');
     }
     if (!isset($this->camp_begin)) {
         $err['camp_begin'] = Lang::t('Validity cannot be empty');
     }
     if (!isset($this->camp_end)) {
         $err['camp_end'] = Lang::t('Validity cannot be empty');
     }
     $this->camp_app_id = AppAccount::getAppID();
     return $err;
 }
 public function constraints()
 {
     //err id => err msg
     $err = array();
     if (!isset($this->camp_pic)) {
         $err['camp_pic'] = Lang::t('Picture must be provided');
     } else {
         $src = _PHOTOPATH . $this->camp_pic;
         list($iWidth, $iHeight, $type) = getimagesize($src);
         if (round($iWidth / $iHeight, 1) != round($this->ratio_weight / $this->ratio_height, 1)) {
             $err['camp_pic'] = Lang::t('Proportion is not right, please crop using our tool');
         }
     }
     if (!isset($this->camp_name)) {
         $err['camp_name'] = Lang::t('Please provide carousel photo');
     }
     if (!isset($this->camp_descr)) {
         $err['camp_descr'] = Lang::t('Description cannot be empty');
     }
     if (!isset($this->camp_begin)) {
         $err['camp_begin'] = Lang::t('Validity cannot be empty');
     }
     if (!isset($this->camp_end)) {
         $err['camp_end'] = Lang::t('Validity cannot be empty');
     }
     $this->camp_app_id = AppAccount::getAppID();
     $this->camp_updatedate = leap_mysqldate();
     //cek apakah paket sesuai dengan yg diperbolehkan
     $app = AppAccount::getActiveAppObject();
     //basic
     $type = $this->arrtype[$this->camp_type];
     //carousel 1_5
     $carousel_id = $app->app_paket_id . "_5";
     $banner_id = $app->app_paket_id . "_6";
     $mm = new PaketMatrix();
     if ($type == "Carousel") {
         $mm->getByID($carousel_id);
     }
     if ($type == "Campaign") {
         $mm->getByID($banner_id);
     }
     $limit = $mm->ps_isi;
     //get all campaign dengan app_id dan type yg diperbolehkan
     $nr = $this->getJumlah("camp_app_id = '{$this->camp_app_id}' AND camp_active = 1 AND camp_type = '{$this->camp_type}'");
     if ($this->camp_active) {
         if ($nr >= $limit) {
             $err['camp_active'] = Lang::t('Too many campaign active for ' . $type . ', please deactivate the others. Limit is ' . $limit);
         }
     }
     return $err;
 }
 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;
 }