function w3($args)
 {
     list($id, $name) = $args;
     $obj = ProductCategoryService::getCategory();
     $num = 0;
     foreach ($obj->layer as $key => $val) {
         //key semua ke anak2nya
         foreach ($val as $key2 => $val2) {
             foreach ($val2 as $val3) {
                 if ($id == $val3) {
                     //                            $keys[] = $val3;
                     $parents = $key;
                     $parents2 = $key2;
                 }
             }
         }
     }
     $cats = $obj;
     //create parents and children link
     //1 parents
     //no children
     $namepar = $obj->detail->{$parents};
     $name1 = "<a title='{$namepar}' href='" . _SPPATH . "pr/w1/" . $parents . "/" . urlencode($namepar) . "'>";
     $name1 .= ucwords(strtolower($obj->detail->{$parents}));
     $name1 .= "</a>";
     $namepar2 = $obj->detail->{$parents2};
     $name2 = "<a title='{$namepar2}' href='" . _SPPATH . "pr/w2/" . $parents2 . "/" . urlencode($namepar2) . "'>";
     $name2 .= ucwords(strtolower($obj->detail->{$parents2}));
     $name2 .= "</a>";
     $breadcrumbs = $name1 . " > " . $name2 . " > <span>" . ucwords(strtolower($name)) . "</span>";
     $token = IMBAuth::createOAuth();
     $url = "http://localhost:8888/tbsecom/LLProdWeb/getItemsUsing3rdTag?id=" . $id . "&token=" . $token;
     $url = "http://www.hulx.net/hulx/LLProdWeb/getItemsUsing3rdTag?id=" . $id . "&token=" . $token;
     $contents = file_get_contents($url);
     $obj = json_decode($contents);
     ProductAtCategory::printer($obj, $id, $name, $breadcrumbs, $cats, 3);
 }
    public static function printCategoryFilterAll()
    {
        $cats = ProductCategoryService::getCategory();
        foreach ($cats->layer as $key => $val) {
            //key semua ke anak2nya
            ?>
                <div onclick="$('.<?php 
            echo $key;
            ?>
').toggle();" class="key" style="font-weight: bold; cursor: pointer; padding-top: 5px; padding-bottom: 5px;" ><span ><?php 
            echo strform($cats->detail->{$key});
            ?>
</span></div>
                <?php 
            foreach ($val as $key2 => $val2) {
                //diprint
                ?>
                        <div class="key2 <?php 
                echo $key;
                ?>
" style="cursor: pointer; display: none;" >&nbsp; <span onclick="$('.<?php 
                echo $key2;
                ?>
').toggle();"><?php 
                echo strform($cats->detail->{$key2});
                ?>
</span></div>
                        <?php 
                foreach ($val2 as $val3) {
                    //diprint
                    ?>
                            <div class="key3 <?php 
                    echo $key2;
                    ?>
" style="display: none;"> &nbsp; &nbsp; <input class="category_check" id="check_<?php 
                    echo $val3;
                    ?>
" type="checkbox" > &nbsp; <?php 
                    echo strform($cats->detail->{$val3});
                    ?>
</div>
                            <script>
                                $("#check_<?php 
                    echo $val3;
                    ?>
").change(function() {
                                    var key = '<?php 
                    echo $val3;
                    ?>
';
                                    if(this.checked) {
                                        //Do stuff

                                        catKey.push(key);
                                    }
                                    else{
                                        //remove element from array
                                        removeA(catKey, key);
                                    }
                                    page = 1;
                                    printProduct({});
                                });
                            </script>
                        <?php 
                }
            }
        }
    }
 static function convertToTree()
 {
     $obj = ProductCategoryService::getCategory();
     $m = new MProdCat();
     if ($_POST['radio'] == "truncate") {
         $m->truncate();
     }
     //
     //        pr($obj);
     $num = 0;
     $gagal = 0;
     $gagalArr = array();
     foreach ($obj->layer as $key => $val) {
         $name = trim(rtrim($obj->detail->{$key}));
         $urutan = $obj->urutan->{$key};
         $mp = new MProdCat();
         $mp->cat_name = $name;
         $mp->cat_id = $key;
         $mp->cat_parent_id = 0;
         $mp->cat_urutan = $urutan;
         if ($mp->save(1)) {
             $num++;
         } else {
             $gagal++;
             $gagalArr[] = $key;
         }
         //key semua ke anak2nya
         foreach ($val as $key2 => $val2) {
             $name2 = trim(rtrim($obj->detail->{$key2}));
             $urutan2 = $obj->urutan->{$key2};
             $mp2 = new MProdCat();
             $mp2->cat_id = $key2;
             $mp2->cat_name = $name2;
             $mp2->cat_parent_id = $key;
             $mp2->cat_urutan = $urutan2;
             if ($mp2->save(1)) {
                 $num++;
             } else {
                 $gagal++;
                 $gagalArr[] = $key2;
             }
             foreach ($val2 as $val3) {
                 $name3 = trim(rtrim($obj->detail->{$val3}));
                 $urutan3 = $obj->urutan->{$val3};
                 $mp3 = new MProdCat();
                 $mp3->cat_id = $val3;
                 $mp3->cat_name = $name3;
                 $mp3->cat_parent_id = $key2;
                 $mp3->cat_urutan = $urutan3;
                 if ($mp3->save(1)) {
                     $num++;
                 } else {
                     $gagal++;
                     $gagalArr[] = $val3;
                 }
             }
         }
         $json['success'] = $num;
         $json['failed'] = $gagal;
         $json['failed_arr'] = $gagalArr;
         echo json_encode($json);
         die;
     }
 }