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;
 }
 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;
 }
 function saveTree($object, $webClass)
 {
     $tree = $_POST['tags'];
     $arr = json_decode($tree);
     $json = array();
     //get active knoten
     $nrActive = $this->hitungAnakActive($arr[0][1]);
     //        echo "<h1>".$nrActive."</h1>";
     //        pr($arr);
     //cek apakah paket sesuai dengan yg diperbolehkan
     $app = AppAccount::getActiveAppObject();
     //category 1_7
     $cat_id = $app->app_paket_id . "_7";
     //
     $mm = new PaketMatrix();
     $mm->getByID($cat_id);
     //
     $limit = (int) $mm->ps_isi;
     //
     //        //get all campaign dengan app_id dan type yg diperbolehkan
     //        $nr = $object->getJumlah("cat_parent_id != '-1' AND cat_app_id = '".$app->app_id."'");
     //
     //
     //        echo "nr = ".$nr." limit : ".$limit;
     if ($nrActive > $limit) {
         $json['bool'] = 0;
         $json['err'] = "<h1>Too Many Categories!! Limit is {$limit} </h1>";
         echo json_encode($json);
         die;
     }
     //pr($arr);
     foreach ($arr as $n => $obj) {
         //cek apakah array
         if (is_array($obj)) {
             //if yes
             //get the first col as name and the res as children
             $id = $obj[0];
             //echo "adalah array dengan element pertama adalah $id <br>";
             //pr($obj);
             $this->saveTreeRecursive($obj[1], $id, $object, $webClass);
         } else {
             $id = $obj;
             //di skip aja krn tidak disave juga
         }
     }
     $json['bool'] = 1;
     $json['err'] = "<h1>Success</h1>";
     echo json_encode($json);
     die;
     //        exit();
 }
    function getBalance()
    {
        $app_id = AppAccount::getAppID();
        $app = AppAccount::getActiveAppObject();
        $limit = addslashes($_GET['lmt']);
        if ($limit < 30 || $limit == "") {
            $limit = 30;
        }
        ?>

        <div class="row">
            <div class="col-md-12 ">
                <div class="bg-green" style="padding: 10px; text-align: center;">
                <h1>Current Balance : <b><?php 
        echo $app->app_pulsa;
        ?>
</b> <i class="fa fa-mail-forward"></i> </h1>
                </div>
            </div>
        </div>
        <?php 
        //get transactions
        $apptrans = new AppPulsa();
        $arrB = $apptrans->getWhere("pulsa_app_id = '{$app_id}' ORDER BY pulsa_date DESC LIMIT 0,{$limit} ");
        $arrB = array_reverse($arrB);
        //        pr($arrB);
        ?>
        <div class="row">
        <div class="col-md-12" style="margin-top: 30px;">
        <h1><i class="fa fa-mail-forward"></i> Balance Statement <small>Last <?php 
        echo $limit;
        ?>
 Transactions</small></h1>
            <ol class="breadcrumb">
                <li>
                    <?php 
        echo Lang::t('Select Nr. of Transactions');
        ?>
                </li>
                <li class="active">

                    <select id="nrtransaction">
                        <option  value="30">30</option>
                        <option <?php 
        if ($limit == 60) {
            echo "selected";
        }
        ?>
 value="60">60</option>
                        <option <?php 
        if ($limit == 100) {
            echo "selected";
        }
        ?>
 value="100">100</option>
                        <option <?php 
        if ($limit == 500) {
            echo "selected";
        }
        ?>
 value="500">500</option>
                        <option <?php 
        if ($limit == 1000) {
            echo "selected";
        }
        ?>
 value="1000">1000</option>
                    </select>

                </li>
            </ol>
    <script>
        $('#nrtransaction').change(function(){
           var slc =  $('#nrtransaction').val();
            openLw('Balance','<?php 
        echo _SPPATH;
        ?>
AppBalance/getBalance?lmt='+slc,'fade');
        });
    </script>
        <div class="table-responsive" >
            <table class="table table-bordered" style="background-color: white;">
                <thead>
                <tr>
                    <th>
                        Date
                    </th>
                    <th>
                        Description
                    </th>
                    <th>
                        Debit
                    </th>
                    <th>
                        Credit
                    </th>
                    <th>
                        Balance
                    </th>

                </tr>

                </thead>
                <tbody>
                <?php 
        foreach ($arrB as $bb) {
            ?>
                <tr>
                    <td><?php 
            echo indonesian_date($bb->pulsa_date);
            ?>
</td>
                    <td>
                        <?php 
            if ($bb->pulsa_action == "debit") {
                ?>
                            Used in campaign. <a style="cursor: pointer;" id="camp_id_<?php 
                echo $bb->pulsa_camp_id;
                ?>
" >view campaign</a>
                            <script>
                                $('#camp_id_<?php 
                echo $bb->pulsa_camp_id;
                ?>
').click(function(){
//                                    var slc =  $('#nrtransaction').val();
                                    openLw('campView','<?php 
                echo _SPPATH;
                ?>
AppBalance/campView?camp_id=<?php 
                echo $bb->pulsa_camp_id;
                ?>
','fade');
                                });
                            </script>
                        <?php 
            } else {
                ?>
                                Topped-up
                            <?php 
            }
            ?>
                    </td>
                    <td class="duit">
                        <?php 
            if ($bb->pulsa_action == "debit") {
                echo $bb->pulsa_jumlah;
            }
            ?>
                    </td>
                    <td class="duit">
                        <?php 
            if ($bb->pulsa_action == "credit") {
                echo $bb->pulsa_jumlah;
            }
            ?>
                    </td>
                    <td class="duit">
                        <b><?php 
            echo $bb->pulsa_new;
            ?>
</b>
                    </td>

                </tr>
                    <?php 
        }
        ?>
                </tbody>
            </table>
        </div>
        </div>
        </div>
        <style>
            table.table td.duit{
                text-align: right;
            }
            .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;
            }
        </style>
        <?php 
    }