public static function portalIndex()
    {
        //global $template;
        //$template->addTextToHead("<script src='"._SPPATH."app/BPlugin/Twitter/js/jquery-1.11.1.js'></script>");
        //pr($template);
        /*
         * print breadcrumbs
         */
        $t = time();
        $getID = TextP::getP("id");
        ?>
        
        <style>
            .webapps{
                padding: 10px;
                cursor: pointer;
                border-bottom: 1px solid #dedede;
            }
            .borderless{
                border-bottom: 0px;
            }
            .fullscreen {
                width: 100%;
                height: 100%;
                position: absolute;
                z-index: 10000;
                top:0;
                left: 0;
             }
             .iframeasli{
                 width: 100%;
                 height: 650px;
             }
        </style>
        <script>
            function getwidth(){
                return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0;
             }
             function getheight(){
                return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0;
             }
             function callfullscreen() {
                 var heit = $(window).height();
                 var wit = $(window).width(); 
                $('.fullscreen').css({
                        width: getwidth(),
                        height: getheight()
                    });
                   // alert('resize');
             }
            /*$(document).ready(function(){
                callfullscreen();
            });*/
            function kerjakanFullScreen(){
                $('#wepapps_menu').fadeToggle();
                $('#webapps_iframe').toggleClass('col-md-9');
                $('#iframeholder').toggleClass('fullscreen').toggleClass('iframeasli');
            }
            //$('#wepapps_menu').fadeToggle();$('#webapps_iframe').toggleClass('fullscreen').toggleClass('col-md-9');
        </script>
        <?php 
        ?>
        <div onclick="kerjakanFullScreen();" style="position: fixed; padding: 10px; bottom: 0; right: 0; color:white; background-color: rgba(0,0,0,0.3); z-index: 10001;"><i class="glyphicon glyphicon-fullscreen"></i></div>
        <div class="col-md-3" id="wepapps_menu">
            <div style="padding: 10px; background-color: #efefef; border-radius: 5px; margin-right: 10px;">
                <?php 
        $wb = new WebAppsPortal();
        $chan = Account::getMyChannels();
        $all = $wb->getByMyChannels($chan, " AND webapps_tech = 'web' ORDER BY webapps_name ASC");
        //$all = $wb->get
        //pr($chan);
        //pr($all);
        foreach ($all as $num => $wp) {
            $num++;
            ?>
                    <div id="webapps_<?php 
            echo $wp->webapps_id;
            ?>
_<?php 
            echo $t;
            ?>
" class="webapps <?php 
            if ($num >= count($all)) {
                ?>
borderless<?php 
            }
            ?>
"><?php 
            echo $wp->webapps_name;
            ?>
</div>
                    <script>
                        $('#webapps_<?php 
            echo $wp->webapps_id;
            ?>
_<?php 
            echo $t;
            ?>
').click(function(){
                            <?php 
            //if webmail
            if ($wp->webapps_id == 1) {
                ?>
                                    var url = '<?php 
                echo $wp->webapps_url;
                ?>
';
                                    var win = window.open(url, '_blank');
                                    win.focus();
                            <?php 
            } else {
                ?>
                            $("#webapps_iframe").empty().html('<iframe id="iframeholder" class="iframeasli" src="<?php 
                echo $wp->webapps_url;
                ?>
"></iframe> ');
                            <?php 
            }
            ?>
                        });
                    <?php 
            if ($getID == $wp->webapps_id) {
                ?>
   
                    $(document).ready(function(){
                        $("#webapps_iframe").empty().html('<iframe id="iframeholder" class="iframeasli" src="<?php 
                echo $wp->webapps_url;
                ?>
"></iframe> ');                  
                    });
                    <?php 
            }
            ?>
                    </script>
                     <?php 
        }
        ?>
            </div> 
        </div>
        <div class="col-md-9" id="webapps_iframe">
            
            <?php 
        //pr($_SESSION);
        ?>
        </div> 
         <?php 
    }
    public function AccountManagement()
    {
        /*
         * process search 
         */
        $s = TextP::getP("word");
        $page = TextP::getP("page", 1);
        $new = TextP::getP("new", 0);
        if ($new) {
            $invert_new = 0;
        } else {
            $invert_new = 1;
        }
        $searchText = '';
        if ($s != "") {
            $searchText = "\r\n                WHERE\r\n    admin_username LIKE '%{$s}%' OR admin_nama_depan LIKE '%{$s}%'";
            if ($new) {
                $searchText = " AND (admin_username LIKE '%{$s}%' OR admin_nama_depan LIKE '%{$s}%') ";
            }
        }
        /*
         * sort
         */
        $sort = TextP::getP("sort", "admin_nama_depan");
        $ord = TextP::getP("order", "ASC");
        $orderText = " {$sort} {$ord}";
        /*define order and sort*/
        $order = $_SESSION['account_man_order'];
        if ($order == "") {
            $order = "ASC";
        } elseif ($order == "ASC") {
            $order = "DESC";
        } else {
            $order = "ASC";
        }
        $_SESSION['account_man_order'] = $order;
        /*
         * Pagination
         */
        $limit = 20;
        $begin = ($page - 1) * $limit;
        global $db;
        $acc = new Account();
        $rl = new RoleLevel();
        $ro = new RoleOrganization();
        $am = new AccountMeta();
        if ($new) {
            $q = "SELECT * FROM `core__admin_account` WHERE NOT EXISTS (SELECT * FROM core__admin_account__metadata WHERE core__admin_account.admin_id = core__admin_account__metadata.account_id) {$searchText} ORDER BY\r\n    {$orderText} LIMIT {$begin},{$limit}";
            $qjumlah = "SELECT count(*) as nr FROM `core__admin_account` WHERE NOT EXISTS (SELECT * FROM core__admin_account__metadata WHERE core__admin_account.admin_id = core__admin_account__metadata.account_id) ";
            $nr = $db->query($qjumlah, 1);
            $jml = $nr->nr;
        } else {
            //normal query
            $q = "\r\nSELECT\r\n    admin_id,admin_username,admin_nama_depan,admin_role,admin_email,\r\n    org.meta_value as org,\r\n    level.meta_value as level\r\nFROM {$acc->table_name}\r\n    LEFT JOIN {$am->table_name} AS org ON org.account_id = admin_id\r\n        AND org.meta_key='RoleOrganization'\r\n    LEFT JOIN {$am->table_name} AS level ON level.account_id = admin_id\r\n        AND level.meta_key='RoleLevel'\r\n    {$searchText} \r\nORDER BY\r\n    {$orderText} LIMIT {$begin},{$limit}";
            $jml = $acc->getJumlah($searchText);
        }
        //echo $q;
        $arrCal = $db->query($q, 2);
        //pr($arr);
        /*
         * get All Active Department
         */
        $dp = new RoleOrganization();
        $arrOrg = $dp->getWhere("organization_active = 1 AND organization_parent_id != 0");
        //simpan ke array yang mudah
        $arrOrg2 = array();
        foreach ($arrOrg as $or) {
            $arrOrg2[$or->organization_id] = $or;
        }
        //pr($arrOrg2);
        /*
         * get All Active Level
         */
        $dp = new RoleLevel();
        $arrOrg = $dp->getWhere("level_active = 1");
        //simpan ke array yang mudah
        $arrLevel = array();
        foreach ($arrOrg as $or) {
            $arrLevel[$or->level_id] = $or;
        }
        /*
         * get All Active Role
         */
        $dp = new Role();
        $arrOrg = $dp->getWhere("role_active = 1");
        //simpan ke array yang mudah
        $arrRoles = array();
        foreach ($arrOrg as $or) {
            $arrRoles[$or->role_id] = $or;
        }
        $t = time();
        ?>
<style>
    .clickable{
        cursor: pointer;
    }
</style>
<h1><?php 
        echo Lang::t('Account Management');
        ?>
</h1>
<div class="row hidden-print" style="margin-bottom: 10px;">
<div class="col-md-6 col-xs-12">

<div class="input-group">
<input type="text" class="form-control" value="<?php 
        echo $s;
        ?>
" id="Account2Deptsearchpat<?php 
        echo $t;
        ?>
" placeholder="<?php 
        echo Lang::t('Username');
        ?>
,<?php 
        echo Lang::t('Name');
        ?>
">
<span class="input-group-btn">
<button class="btn btn-default" id="Account2Deptsearchpat2_<?php 
        echo $t;
        ?>
" type="button"><?php 
        echo Lang::t('Search');
        ?>
</button>
</span>
<span class="input-group-btn">
<button class="btn btn-default <?php 
        if ($new) {
            ?>
 btn-warning<?php 
        }
        ?>
" id="Account2Deptsearchpat2b_<?php 
        echo $t;
        ?>
" type="button"><?php 
        echo Lang::t('w/o Departments and Level');
        ?>
</button>
</span>
</div>
<!-- /input-group -->
<script type="text/javascript">
    $("#Account2Deptsearchpat2_<?php 
        echo $t;
        ?>
").click(function () {
        var slc = encodeURI($('#Account2Deptsearchpat<?php 
        echo $t;
        ?>
').val());
        openLw(window.selected_page, '<?php 
        echo _SPPATH;
        ?>
PortalAdminWeb/AccountManagement?page=1&new=<?php 
        echo $new;
        ?>
&word=' + slc, 'fade');
    });
    $("#Account2Deptsearchpat<?php 
        echo $t;
        ?>
").keyup(function (event) {
        if (event.keyCode == 13) { //on enter
            var slc = encodeURI($('#Account2Deptsearchpat<?php 
        echo $t;
        ?>
').val());
            openLw(selected_page, '<?php 
        echo _SPPATH;
        ?>
PortalAdminWeb/AccountManagement?page=1&new=<?php 
        echo $new;
        ?>
&word=' + slc, 'fade');
        }
    });
    $('#Account2Deptsearchpat2b_<?php 
        echo $t;
        ?>
').click(function(){
        var slc = encodeURI($('#Account2Deptsearchpat<?php 
        echo $t;
        ?>
').val());
         openLw(window.selected_page, '<?php 
        echo _SPPATH;
        ?>
PortalAdminWeb/AccountManagement?page=1&new=<?php 
        echo $invert_new;
        ?>
&word=' + slc, 'fade');
    });
</script>
</div>
</div>
<table class="table table-bordered table-striped table-hover" style="background-color: white;">    
    <thead>
        <tr>
            <th class="clickable" onclick="openLw(selected_page, '<?php 
        echo _SPPATH;
        ?>
PortalAdminWeb/AccountManagement?page=<?php 
        echo $page;
        ?>
&word=<?php 
        echo $s;
        ?>
&sort=admin_id&order=<?php 
        echo $order;
        ?>
', 'fade');"><?php 
        echo Lang::t('ID');
        ?>
</th>
            <th class="clickable" onclick="openLw(selected_page, '<?php 
        echo _SPPATH;
        ?>
PortalAdminWeb/AccountManagement?page=<?php 
        echo $page;
        ?>
&word=<?php 
        echo $s;
        ?>
&sort=admin_username&order=<?php 
        echo $order;
        ?>
', 'fade');"><?php 
        echo Lang::t('Email');
        ?>
</th>
            <th class="clickable" onclick="openLw(selected_page, '<?php 
        echo _SPPATH;
        ?>
PortalAdminWeb/AccountManagement?page=<?php 
        echo $page;
        ?>
&word=<?php 
        echo $s;
        ?>
&sort=admin_nama_depan&order=<?php 
        echo $order;
        ?>
', 'fade');"><?php 
        echo Lang::t('Name');
        ?>
</th>
            <th class="clickable" onclick="openLw(selected_page, '<?php 
        echo _SPPATH;
        ?>
PortalAdminWeb/AccountManagement?page=<?php 
        echo $page;
        ?>
&word=<?php 
        echo $s;
        ?>
&sort=admin_role&order=<?php 
        echo $order;
        ?>
', 'fade');"><?php 
        echo Lang::t('Role');
        ?>
</th>
            <th class="clickable" onclick="openLw(selected_page, '<?php 
        echo _SPPATH;
        ?>
PortalAdminWeb/AccountManagement?page=<?php 
        echo $page;
        ?>
&word=<?php 
        echo $s;
        ?>
&sort=org.meta_value&order=<?php 
        echo $order;
        ?>
', 'fade');"><?php 
        echo Lang::t('Department');
        ?>
</th>
            <th class="clickable" onclick="openLw(selected_page, '<?php 
        echo _SPPATH;
        ?>
PortalAdminWeb/AccountManagement?page=<?php 
        echo $page;
        ?>
&word=<?php 
        echo $s;
        ?>
&sort=level.meta_value&order=<?php 
        echo $order;
        ?>
', 'fade');"><?php 
        echo Lang::t('Level');
        ?>
</th>
            <th><?php 
        echo Lang::t('Action');
        ?>
</th>
        </tr>
    </thead>
    <tbody>
        <?php 
        foreach ($arrCal as $acc) {
            ?>
        <tr>
            <td><?php 
            echo $acc->admin_id;
            ?>
</td>
            <td><?php 
            echo $acc->admin_email;
            ?>
</td>
            <td><input id="name_<?php 
            echo $acc->admin_id;
            ?>
_<?php 
            echo $t;
            ?>
" type="text" value="<?php 
            echo $acc->admin_nama_depan;
            ?>
" class="form-control"></td>
            <td>
                <select id="role_<?php 
            echo $acc->admin_id;
            ?>
_<?php 
            echo $t;
            ?>
" class="form-control">
                <?php 
            foreach ($arrRoles as $id => $org) {
                ?>
    <option <?php 
                if ($id == $acc->admin_role) {
                    echo "selected";
                }
                ?>
 value="<?php 
                echo $id;
                ?>
"><?php 
                echo $org->role_name;
                ?>
</option>   
                 <?php 
            }
            ?>
                </select>
            </td>

            <td>
                <select id="org_<?php 
            echo $acc->admin_id;
            ?>
_<?php 
            echo $t;
            ?>
" class="form-control">
                <?php 
            foreach ($arrOrg2 as $id => $org) {
                ?>
    <option <?php 
                if ($id == $acc->org) {
                    echo "selected";
                }
                ?>
 value="<?php 
                echo $id;
                ?>
"><?php 
                echo $org->organization_name;
                ?>
</option>   
                 <?php 
            }
            ?>
                </select>
                </td>
                <td>
                <select id="level_<?php 
            echo $acc->admin_id;
            ?>
_<?php 
            echo $t;
            ?>
" class="form-control">
                <?php 
            foreach ($arrLevel as $id => $org) {
                ?>
    <option <?php 
                if ($id == $acc->level) {
                    echo "selected";
                }
                ?>
 value="<?php 
                echo $id;
                ?>
"><?php 
                echo $org->level_name;
                ?>
</option>   
                 <?php 
            }
            ?>
                </select>
                </td>
                <td><button id="updater_<?php 
            echo $acc->admin_id;
            ?>
_<?php 
            echo $t;
            ?>
" class="btn btn-default"><?php 
            echo Lang::t('update');
            ?>
</button></td>
    <script>
        $("#updater_<?php 
            echo $acc->admin_id;
            ?>
_<?php 
            echo $t;
            ?>
").click(function(){
            var name = encodeURI($("#name_<?php 
            echo $acc->admin_id;
            ?>
_<?php 
            echo $t;
            ?>
").val());
            var role = encodeURI($("#role_<?php 
            echo $acc->admin_id;
            ?>
_<?php 
            echo $t;
            ?>
").val());
            var lvl = encodeURI($("#level_<?php 
            echo $acc->admin_id;
            ?>
_<?php 
            echo $t;
            ?>
").val());
            var org = encodeURI($("#org_<?php 
            echo $acc->admin_id;
            ?>
_<?php 
            echo $t;
            ?>
").val());
            
            $.post("<?php 
            echo _LANGPATH;
            ?>
PortalAdminWeb/updater",{
                id : '<?php 
            echo $acc->admin_id;
            ?>
',
                name :name,
                lvl : lvl,
                org : org,
                role : role
            },function(data){
                console.log(data.post);
                console.log(data.isi);
                if(data.bool)alert('<?php 
            echo Lang::t('Update Succesful');
            ?>
');
                else alert(data.err);
            },'json');
        });
    </script>
        </tr>
          
           <?php 
        }
        ?>
    </tbody>
</table>
<?php 
        $halaman = $page;
        $jmlpage = ceil($jml / $limit);
        ?>
<nav>
  <ul class="pagination">
      <?php 
        if ($halaman > 1) {
            ?>
    <li><a class="clickable" onclick="openLw(selected_page,'<?php 
            echo _LANGPATH;
            ?>
PortalAdminWeb/AccountManagement?page=<?php 
            echo $page - 1;
            ?>
&word=<?php 
            echo $s;
            ?>
&sort=<?php 
            echo $sort;
            ?>
&order=<?php 
            echo $order;
            ?>
&new=<?php 
            echo $new;
            ?>
','fade');"><span aria-hidden="true">&laquo;</span><span class="sr-only">Previous</span></a></li>
    <?php 
        }
        ?>
    <?php 
        //ambil 3 bh terdekat //
        $mulai = $halaman - 2;
        $akhir = $halaman + 2;
        //echo $mulai.$akhir;
        $min = max($mulai, 1);
        $max = min($akhir, $jmlpage);
        //echo "<br> max :".$max;
        //echo "<br> min :".$min;
        for ($x = $min; $x <= $max; $x++) {
            ?>
    
    <li <?php 
            if ($x == $halaman) {
                ?>
class="active"<?php 
            }
            ?>
><a onclick="openLw(selected_page,'<?php 
            echo _LANGPATH;
            ?>
PortalAdminWeb/AccountManagement?page=<?php 
            echo $x;
            ?>
&word=<?php 
            echo $s;
            ?>
&sort=<?php 
            echo $sort;
            ?>
&order=<?php 
            echo $order;
            ?>
&new=<?php 
            echo $new;
            ?>
','fade');"><?php 
            echo $x;
            ?>
</a></li>
    <?php 
        }
        ?>
    
    <?php 
        if ($jml > $begin + $limit) {
            ?>
    <li><a class="clickable" onclick="openLw(selected_page,'<?php 
            echo _LANGPATH;
            ?>
PortalAdminWeb/AccountManagement?page=<?php 
            echo $page + 1;
            ?>
&word=<?php 
            echo $s;
            ?>
&sort=<?php 
            echo $sort;
            ?>
&order=<?php 
            echo $order;
            ?>
&new=<?php 
            echo $new;
            ?>
','fade');"><span aria-hidden="true">&raquo;</span><span class="sr-only">Next</span></a></li>
    <?php 
        }
        ?>
  </ul>
</nav>
        <h4><?php 
        echo $jml;
        ?>
 <?php 
        echo Lang::t('results in');
        ?>
 <?php 
        echo $jmlpage;
        ?>
 <?php 
        echo Lang::t('pages');
        ?>
</h4>  
        <?php 
    }