public function overwriteForm($return, $returnfull)
 {
     $t = time();
     $return = parent::overwriteForm($return, $returnfull);
     $return['prod_attribute_array'] = new Leap\View\InputAttribute("prod_stock_" . $t, "prod_attribute_array", "prod_attribute_array", $this->prod_attribute_array);
     $return['prod_pic'] = new Leap\View\InputGallery("prod_pic", "prod_pic", $this->prod_pic);
     $return['prod_active'] = new Leap\View\InputSelect($this->arrayYesNO, "prod_active", "prod_active", $this->prod_active);
     // $return['news_text'] = new Leap\View\InputTextArea("news_text", "news_text", $this->news_text);
     $return['prod_des'] = new Leap\View\InputTextArea("prod_des", "prod_des", $this->prod_des);
     $return['prod_stock'] = new Leap\View\InputText("hidden", "prod_stock_" . $t, "prod_stock", $this->prod_stock);
     $return['prod_app_id'] = new Leap\View\InputText("hidden", "prod_app_id" . $t, "prod_app_id", $this->prod_app_id);
     $return['prod_price'] = new Leap\View\InputPrice("prod_price", "prod_price", $this->prod_price);
     $return['prod_price_diskon'] = new Leap\View\InputPrice("prod_price_diskon", "prod_price_diskon", $this->prod_price_diskon);
     $p = new MProdCat();
     if (count($p->tree_multi_user_constraint) > 0) {
         $where = array();
         foreach ($p->tree_multi_user_constraint as $attr => $val) {
             $where[] = $attr . " = '" . $val . "'";
         }
         $impWhere = implode(" AND ", $where);
         $arrPage = $p->getWhere($impWhere);
     } else {
         $arrPage = $p->getAll();
     }
     //        $arrPage = $p->getAll();
     //category harus sesuai tree structurenya.....
     $arrNe = array();
     foreach ($arrPage as $pp) {
         $arrNe[$pp->cat_id] = $pp->cat_name;
     }
     $return['prod_cat_id'] = new Leap\View\InputSelect($arrNe, "prod_cat_id", "prod_cat_id", $this->prod_cat_id);
     return $return;
 }
 static function getHome()
 {
     /*
     * Carousel, ratio 16:10
     Campaigns, ratio 16:10
     Categories
     category id, name, image
     Drawer
     Login, Wishlist, Payment, Transactions, Logout - Static
     About Us, Contact Us - Dynamic
     Nembak ke URL
     Additional pages dynamic, semua masuk ke sebelum logout
     Application Settings
     Actionbar Color - Hex code “#dedede"
     Actionbar Icon Color - Black / White
     Search Product
     */
     //check ada POST ga ?
     $app_id = addslashes($_POST['app_id']);
     //ambil main banner
     $camp = new MCampaignModel();
     //TODO masih harus dilimit sesuai paket yg dibeli
     $arrCarousel = $camp->getWhere("camp_app_id = '{$app_id}' AND camp_active = 1 AND camp_type = 'carousel' AND camp_begin <= CURDATE() AND camp_end >= CURDATE() ORDER BY camp_begin DESC ");
     //TODO masih harus dilimit sesuai paket yg dibeli
     $arrBanner = $camp->getWhere("camp_app_id = '{$app_id}' AND camp_active = 1 AND camp_type = 'campaign' AND camp_begin <= CURDATE() AND camp_end >= CURDATE() ORDER BY camp_begin DESC ");
     $cat = new MProdCat();
     $arrCat = $cat->getWhere("cat_app_id = '{$app_id}' AND cat_parent_id = 0 ORDER BY cat_name ASC");
     $json['status_code'] = 1;
     $json['status_message'] = "OK";
     $json['results']['carousel'] = APIFilter::filter($arrCarousel);
     $json['results']['campaign'] = APIFilter::filter($arrBanner);
     $json['results']['maincategories'] = APIFilter::filter($arrCat);
     $json['results']['drawer'] = array();
     $json['results']['setting'] = array();
     echo json_encode($json);
     die;
 }
    public function p()
    {
        $t = time() . rand(1, 100);
        $id = $this->id . "attrib_" . $t;
        //        echo $id;
        $exp = explode(",", $this->value);
        $llimit = count($exp);
        if ($llimit < 1) {
            $llimit = 0;
        }
        ?>

        <input type="text" name="<?php 
        echo $this->name;
        ?>
" id="<?php 
        echo $this->id;
        ?>
_<?php 
        echo $t;
        ?>
" class="<?php 
        echo $this->id;
        ?>
" value="<?php 
        echo $this->value;
        ?>
">
        <div class="attribute_adder">
            <div id="submitter_<?php 
        echo $id;
        ?>
" style="padding: 10px; text-align: right; float: right;">
                <!--                <button id="butsave_--><?php 
        //=$id;
        ?>
<!--" type="button" class="btn btn-default">Save Attributes</button>-->
                <button id="but_<?php 
        echo $id;
        ?>
" type="button" class="btn btn-default">Add Attribute </button>
            </div>

            <div id="attbox_<?php 
        echo $id;
        ?>
">
            </div>

        </div>
        <div id="allprod" style="display: none; background-color: #FFFFFF; padding: 10px;">
            <div style="float: right; width: 10px; height: 10px;" onclick="$('#allprod').hide();">x</div>
            <?php 
        $n = new \MProdModel();
        $arrN = $n->getOrderBy("VariantID ASC");
        self::printer($arrN);
        ?>
        </div>
        <script>
            var featSudah = [];
            var opt_<?php 
        echo $id;
        ?>
 = [
                '<option value="all">all</option>',
//                '<option value="price">Price</option>',
                '<option value="variantID">VariantID</option>',
                '<option value="baseID">BaseID</option>',
                '<option value="category">Category</option>'
            ];

            var optcommand_<?php 
        echo $id;
        ?>
 = [
                'variantID',
                'baseID',
                'category'
            ];

            var opt2a_<?php 
        echo $id;
        ?>
 = [
                '<option value=""></option>',
                '<option value="=">=</option>',
                '<option value="&gt;">&gt;</option>',
                '<option value="&gt;=<">&gt;=</option>',
                '<option value="=&lt;">=&lt;</option>',
                '<option value="&lt;">&lt;</option>'
            ];

            var opt2b_<?php 
        echo $id;
        ?>
 = [
                '<option value=""></option>',
                '<option value="is">is one of</option>',
                '<option value="is_not">is not one of</option>'
            ];

            var opt3a_<?php 
        echo $id;
        ?>
 = '<input type="number" id="span3">';

            var attr_<?php 
        echo $id;
        ?>
 = [];
            var attrnr_<?php 
        echo $id;
        ?>
 = <?php 
        echo $llimit;
        ?>
;
            <?php 
        if ($llimit > 0) {
            ?>
            //create attributes
            <?php 
            foreach ($exp as $num => $ee) {
                $exp2 = explode(";", $ee);
                $option1 = $exp2[0];
                $option2 = $exp2[1];
                $option3 = $exp2[1];
                ?>
            createAttr<?php 
                echo $id;
                ?>
('<?php 
                echo $num;
                ?>
','<?php 
                echo $option1;
                ?>
','<?php 
                echo $option2;
                ?>
','<?php 
                echo $option3;
                ?>
');
            <?php 
            }
            //foreach
            ?>

            function createAttr<?php 
            echo $id;
            ?>
(lokalid,option1,option2,option3){

                var selecttext = '';
                for(var x=0;x<opt_<?php 
            echo $id;
            ?>
.length;x++){
                    selecttext += opt_<?php 
            echo $id;
            ?>
[x];
                }
                var text2 = "<div class='condition form-inline'><select class='form-control' id='select1_"+lokalid+"' onchange='updateSpan2(\""+lokalid+"\");'>"+selecttext+"</select><span id='span2_"+lokalid+"'></span><span id='span3_"+lokalid+"'></span></div>";
                $("#attbox_<?php 
            echo $id;
            ?>
").append(text2);
                $("#submitter_<?php 
            echo $id;
            ?>
").show();
            }
            <?php 
        }
        ?>

            function updateSpan2(lokalid){
                var slc = $('#select1_'+lokalid).val();

                activeLokalID = lokalid;


                var selecttext = '';
                if(slc == "all"){
                    $('#span2_'+lokalid).html('');
                    $('#span3_'+lokalid).html('');
                    return "";
                }
                else if(slc == "price"){
                    for(var x=0;x<opt2a_<?php 
        echo $id;
        ?>
.length;x++){
                        selecttext += opt2a_<?php 
        echo $id;
        ?>
[x];
                    }
                    featSudah.push(slc);
                }else{
                    for(var x=0;x<opt2b_<?php 
        echo $id;
        ?>
.length;x++){
                        selecttext += opt2b_<?php 
        echo $id;
        ?>
[x];
                    }
                    featSudah.push(slc);
                }
                $('#span3_'+lokalid).html('');
                $('#span2_'+lokalid).html("<select class='form-control' id='select2_"+lokalid+"' onchange='updateSpan3(\""+lokalid+"\");'>"+selecttext+"</select>");
            }

            var activeLokalID = 0;

            function updateSpan3(lokalid){
                var slc2 = $('#select1_'+lokalid).val();

                var slc = $('#select2_'+lokalid).val();

                activeLokalID = lokalid;
//                $('#span3_'+lokalid).html(slc);

                var selecttext = '';
                if(slc2 == "price"){

                    $('#span3_'+lokalid).html('<input onchange="updateHiddenCondition();" class="form-control" type="number" id="isi_span3_'+lokalid+'">');

                }else{
                    /// load from database....
                    if(slc2 == "variantID"){
                        //uncheck all checkbox
                        $('.variant_check').prop("checked",false);
                        checkedVariant = [];
                        $('#allprod').show();
                        html = "<input type='text' class='form-control' id='isi_span3_"+lokalid+"'>";

                    }
                    if(slc2 == "baseID"){
                        <?php 
        $n = new \MProdModel();
        $arrN = $n->getWhere("ArticleType = 'Base' ORDER BY BaseArticleID ASC");
        $cc = '';
        foreach ($arrN as $num => $nn) {
            $cc .= "<input type='checkbox'>" . $num . ". " . $nn->BaseArticleID . " " . $nn->BaseArticleNameENG . "<br>";
        }
        ?>
                        var html = "<?php 
        echo $cc;
        ?>
";
                    }
                    if(slc2 == "category"){
                        <?php 
        $n = new \MProdCat();
        $arrN = $n->getWhere("cat_parent_id != '-1' ORDER BY cat_name ASC");
        $cc = '';
        foreach ($arrN as $num => $nn) {
            $cc .= "<input type='checkbox'>" . $num . ". " . $nn->cat_id . " " . $nn->cat_name . "<br>";
        }
        ?>
                        var html = "<?php 
        echo $cc;
        ?>
";
                    }
                    $('#span3_'+lokalid).html(html);

                }


            }


            $("#but_<?php 
        echo $id;
        ?>
").click(function(){
                var lokalid = attrnr_<?php 
        echo $id;
        ?>
;
//                var text = "<div class='attr_box'>Attr Name : <input id='attrtext_<?php 
        //=$id;
        ?>
//_"+lokalid+"' type='text'> Stok : <input id='attrstok_<?php 
        //=$id;
        ?>
//_"+lokalid+"' type='number'></div>";


                var selecttext = '';
                for(var x=0;x<opt_<?php 
        echo $id;
        ?>
.length;x++){

                    if(jQuery.inArray( optcommand_<?php 
        echo $id;
        ?>
[x], featSudah ) !== -1){
                        continue;
                    }


                    selecttext += opt_<?php 
        echo $id;
        ?>
[x];
                }
                var text2 = "<div class='condition form-inline'><select class='form-control' id='select1_"+lokalid+"' onchange='updateSpan2(\""+lokalid+"\");'>"+selecttext+"</select><span id='span2_"+lokalid+"'></span><span id='span3_"+lokalid+"'></span></div>";
                $("#attbox_<?php 
        echo $id;
        ?>
").append(text2);

                $("#submitter_<?php 
        echo $id;
        ?>
").show();
                attrnr_<?php 
        echo $id;
        ?>
++;
            });

//            $("#butsave_<?php 
        //=$id;
        ?>
//").click(function(){
//
//                updateHiddenCondition();
////                alert(energy);
//
////                $("#<?php 
        ////=$this->totalstock_id;
        ?>
////").val(totalstok);
//            });

            function updateHiddenCondition(){
                var gab = [];
                var totalstok = 0;
//                alert(attrnr_<?php 
        //=$id;
        ?>
//);
                //parsing all the inputs
                for(var x = 0;x<attrnr_<?php 
        echo $id;
        ?>
;x++){

//                    alert(x);

                    var isi3 = $("#isi_span3_"+x).val();
                    var isi2 = $("#select2_"+x).val();
                    var isi1 = $("#select1_"+x).val();

                    if(isi1=="" || isi2 =="" || isi3 == ""){
                        //error1
                        alert("Missing Attributes ");
                    }
                    else {
                        gab.push(isi1+";"+isi2+";"+isi3);
                    }

                }

                var energy = gab.join("|");

                $("#<?php 
        echo $this->id;
        ?>
_<?php 
        echo $t;
        ?>
").val(energy);
            }
        </script>
        <style>
            .condition{
                padding: 5px;
            }
        </style>
    <?php 
    }