public function overwriteForm($return, $returnfull)
 {
     $return['admin_ip'] = new Leap\View\InputText("hidden", "admin_ip", "admin_ip", $this->admin_ip);
     $return['admin_inbox'] = new Leap\View\InputText("hidden", "admin_inbox", "admin_inbox", $this->admin_inbox);
     $return['admin_nama_depan'] = new Leap\View\InputText("text", "admin_nama_depan", "admin_nama_depan", $this->admin_nama_depan);
     $return['admin_nama_belakang'] = new Leap\View\InputText("hidden", "admin_nama_belakang", "admin_nama_belakang", $this->admin_nama_belakang);
     $return['admin_lastupdate'] = new Leap\View\InputText("hidden", "admin_lastupdate", "admin_lastupdate", $this->admin_lastupdate);
     $return['admin_email'] = new Leap\View\InputText("email", "admin_email", "admin_email", $this->admin_email);
     $return['admin_aktiv'] = new Leap\View\InputSelect($this->arrayYesNO, "admin_aktiv", "admin_aktiv", $this->admin_aktiv);
     $return['admin_foto'] = new Leap\View\InputText("hidden", "admin_foto", "admin_foto", $this->admin_foto);
     $return['admin_inbox'] = new Leap\View\InputText("hidden", "admin_inbox", "admin_inbox", $this->admin_inbox);
     $role = new Role();
     $arrroles = $role->getWhere("role_active =1");
     foreach ($arrroles as $rr) {
         $arrRole[$rr->role_id] = Lang::t($rr->role_id);
     }
     $return['admin_role'] = new Leap\View\InputSelect($arrRole, "admin_role", "admin_role", $this->admin_role);
     $return['admin_inbox_update'] = new Leap\View\InputText("hidden", "admin_inbox_update", "admin_inbox_update", $this->admin_inbox_update);
     $return['admin_inbox_timestamp'] = new Leap\View\InputText("hidden", "admin_inbox_timestamp", "admin_inbox_timestamp", $this->admin_inbox_timestamp);
     $arrType = ['admin', 'user', 'store'];
     $return['admin_type'] = new Leap\View\InputSelect($arrType, "admin_type", "admin_type", $this->admin_type);
     return $return;
 }
    public function ShowRole2RoleLevel()
    {
        //create the model object
        $cal = new Role2Role();
        $arr = $cal->findLevels();
        $t = time();
        //pr($arr);
        $rr = new Role();
        $arrRoles = $rr->getWhere("role_active = 1");
        ?>
<script>
    var arrayOfRoles = [];
</script>            
         <?php 
        foreach ($arrRoles as $role) {
            ?>
<script>
    var r = {id:'<?php 
            echo $role->role_id;
            ?>
',level:0};
    arrayOfRoles.push(r);
</script>
            <?php 
            foreach ($arr as $lvl => $arrRole) {
                foreach ($arrRole as $role2) {
                    if ($role->role_id == $role2) {
                        $arrSudahAda[$role2] = $role2;
                    }
                }
            }
        }
        //pr($arrSudahAda);
        foreach ($arrRoles as $role) {
            if (!in_array($role->role_id, $arrSudahAda)) {
                $arrBlmAda[$role->role_id] = $role->role_id;
            }
        }
        //pr($arrBlmAda);
        foreach ($arr as $lvl => $x) {
            $arrSorts[] = "#sortable_{$lvl}";
        }
        $str = implode(",", $arrSorts);
        ?>
<style>
    .droptrue li{
        list-style-type: none;
        margin:5px;
        background-color: #dedede;
        padding:5px;
        border-radius: 5px;
    }
</style>
<script>
  $(function() {
    $( "ul.droptrue" ).sortable({
      connectWith: "ul",
      receive: function(event, ui) {
          var sem = this.id;
          var exp = sem.split("_");
          for(var key in arrayOfRoles){
                if(arrayOfRoles[key].id == ui.item.html()){
                    arrayOfRoles[key].level = parseInt(exp[1]);
                }
            }
            console.log("[" + this.id + "] received [" + ui.item.html() + "] from [" + ui.sender.attr("id") + "]");
            console.log(arrayOfRoles);
        }
    });
    console.log(arrayOfRoles);
    /*$( "ul.dropfalse" ).sortable({
      connectWith: "ul",
      dropOnEmpty: false
    });*/
 
    $( "<?php 
        echo $str;
        ?>
" ).disableSelection();
  });
  </script>
  <style>
      .droptrue{
          width: 150px;  
          border:1px solid #888;
          padding: 10px;
           
      }
      .lvlcon{
          float: left;
          width: 150px; 
          margin-right: 10px;
          background-color: #efefef; 
      }
      .lvlcon h3{
          text-align: center;
      }
  </style>
  <h1><?php 
        echo Lang::t('Role Adjuster');
        ?>
</h1>
  <button id="addsub_<?php 
        echo $t;
        ?>
" class="btn btn-default"><?php 
        echo Lang::t('Add Sub Level');
        ?>
</button>
  <button id="addsuper_<?php 
        echo $t;
        ?>
" class="btn btn-default"><?php 
        echo Lang::t('Add Super Level');
        ?>
</button>
  <div class="clearfix" style="padding:10px;"></div>
  <?php 
        $lvl = -1;
        ?>
  <div id="treecontainer_<?php 
        echo $t;
        ?>
">
  <div class="lvlcon">
      <h3><?php 
        if ($lvl < 0) {
            echo 'Deactivate';
        } else {
            echo $lvl;
        }
        ?>
</h3>
      <ul id="sortable_<?php 
        echo $lvl;
        ?>
" class="droptrue">                    
        <?php 
        foreach ($arrBlmAda as $role) {
            ?>
          <li id="<?php 
            echo $role;
            ?>
" class="ui-state-highlight"><?php 
            echo $role;
            ?>
</li>
          <script>
              for(var key in arrayOfRoles){
                  if(arrayOfRoles[key].id == '<?php 
            echo $role;
            ?>
'){
                      arrayOfRoles[key].level = <?php 
            echo $lvl;
            ?>
;
                  }
              }
          </script>
        <?php 
        }
        ?>
    </ul>
  </div>
 <?php 
        foreach ($arr as $lvl => $arrRole) {
            ?>
  <div class="lvlcon">
                <h3 ><?php 
            echo $lvl;
            ?>
</h3>
                <ul id="sortable_<?php 
            echo $lvl;
            ?>
" class="droptrue">
                    
                    <?php 
            foreach ($arrRole as $role) {
                ?>
                        <li id="<?php 
                echo $role;
                ?>
" class="ui-state-highlight"><?php 
                echo $role;
                ?>
</li>
                        <script>
                        for(var key in arrayOfRoles){
                            if(arrayOfRoles[key].id == '<?php 
                echo $role;
                ?>
'){
                                arrayOfRoles[key].level = <?php 
                echo $lvl;
                ?>
;
                            }
                        }
                    </script>
                    <?php 
            }
            ?>
                </ul>
  </div>
            <?php 
        }
        ?>
  </div>
  <div class="clearfix" style="margin-top:20px;"></div>
  <p id="printer<?php 
        echo $t;
        ?>
" style="margin: 20px;">
  
  </p>
  <script>
  var lvlmin = -1;
  var lvlmax = <?php 
        echo $lvl;
        ?>
;
  $("#addsub_<?php 
        echo $t;
        ?>
").click(function(){
      lvlmin--;
      $("#treecontainer_<?php 
        echo $t;
        ?>
").prepend('<div class="lvlcon"><h3>'+lvlmin+'</h3><ul id="sortable_'+lvlmin+'" class="droptrue"> </ul></div>');
      $( "ul.droptrue" ).sortable({
      connectWith: "ul",
      receive: function(event, ui) {
        var sem = this.id;
          var exp = sem.split("_");
          for(var key in arrayOfRoles){
                if(arrayOfRoles[key].id == ui.item.html()){
                    arrayOfRoles[key].level  = parseInt(exp[1]);
                }
            }
            console.log("[" + this.id + "] received [" + ui.item.html() + "] from [" + ui.sender.attr("id") + "]");
            console.log(arrayOfRoles);
        }
        });
  });
  $("#addsuper_<?php 
        echo $t;
        ?>
").click(function(){
      lvlmax++;
      $("#treecontainer_<?php 
        echo $t;
        ?>
").append('<div class="lvlcon"><h3>'+lvlmax+'</h3><ul id="sortable_'+lvlmax+'" class="droptrue"> </ul></div>');
      $( "ul.droptrue" ).sortable({
      connectWith: "ul",
      receive: function(event, ui) {
        var sem = this.id;
          var exp = sem.split("_");
          for(var key in arrayOfRoles){
                if(arrayOfRoles[key].id == ui.item.html()){
                    arrayOfRoles[key].level  = parseInt(exp[1]);
                }
            }
            console.log("[" + this.id + "] received [" + ui.item.html() + "] from [" + ui.sender.attr("id") + "]");
            console.log(arrayOfRoles);
        }
        });
  });
  </script>
 
   <button id="saveTree_<?php 
        echo $t;
        ?>
" class="btn btn-default"><?php 
        echo Lang::t('Save Role Connections');
        ?>
</button> 
   <script>
   $("#saveTree_<?php 
        echo $t;
        ?>
").click(function(){
       console.log(arrayOfRoles);
       var myJsonString = JSON.stringify(arrayOfRoles);
       $.post("<?php 
        echo _SPPATH;
        ?>
AccountLoginWeb/saveTree",{tree:myJsonString},function(data){
           console.log(data);
           $("#printer<?php 
        echo $t;
        ?>
").html(data);
       });
   });    
   </script>
        <?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 
    }
    public function Role2Menu()
    {
        $t = time();
        //create matrix to adjust menu
        $arrMenu = Registor::getAllAdminMenuFromSession();
        ?>
<div class="table-responsive">
    <table class="table table-bordered table-striped table-hover">
        <thead>
            <tr>
                <td><?php 
        echo Lang::t('Menu');
        ?>
</td>
                <td><?php 
        echo Lang::t('Min-Role');
        ?>
</td>
            </tr>
        </thead>
        <tbody>
            <?php 
        $r = new Role();
        $existingRoles = $r->getWhere("role_active = 1 ORDER BY role_id ASC");
        foreach ($arrMenu as $menu) {
            $role = Role2Menu::getRoleForMenu($menu);
            ?>
            <tr>
                <td><?php 
            echo $menu;
            ?>
</td>
                <td>
                    <select id="role_select_<?php 
            echo $menu;
            ?>
_<?php 
            echo $t;
            ?>
">
                <?php 
            foreach ($existingRoles as $ro) {
                ?>
                
                        <option value="<?php 
                echo $ro->role_id;
                ?>
" <?php 
                if ($ro->role_id == $role) {
                    echo "selected";
                }
                ?>
><?php 
                echo $ro->role_id;
                ?>
</option>
                <?php 
            }
            ?>
                    </select>
                    <script>
                    $("#role_select_<?php 
            echo $menu;
            ?>
_<?php 
            echo $t;
            ?>
").change(function(){
                        var slc = $("#role_select_<?php 
            echo $menu;
            ?>
_<?php 
            echo $t;
            ?>
").val();
                       $.get("<?php 
            echo _SPPATH;
            ?>
RoleWeb/ins?menu=<?php 
            echo base64_encode($menu);
            ?>
&role_id="+slc); 
                    });    
                    </script>
                </td>
            </tr>
            <?php 
        }
        ?>
        </tbody>
       
    </table>
</div>    
        <?php 
    }