<script type="text/javascript">
    function validate()
    {
        if(trim(document.getElementById('var_name').value) == "")
        {
            alert("Please enter group name.");
            document.getElementById('var_name').focus();
            return false;
        }
       /* else if(trim(document.getElementById('int_displayorder').value) == "")
        {
            alert("Please enter display order.");
            document.getElementById('int_displayorder').focus();
            return false;
        }*/
        document.getElementById('h_save').value = 'T';

        return true;
    }
    function valButton(btn) {
        var cnt = -1;
        for (var i=btn.length-1; i > -1; i--) {
            if (btn[i].checked) {cnt = i; i = -1;}
        }
        if (cnt > -1) return btn[cnt].value;
        else return null;
    }
</script>
<script type="text/javascript">

    function selectallaction(checkid,ids)
    {
        var idArray;
        var lengthArray=0;
        var i=0;

        if(ids!="")
        {
            idArray=ids.split(",");

            lengthArray=idArray.length;

            if(document.getElementById(checkid).checked==true)
            {

                for(i=0;i<lengthArray;i++)
                {
                    $("#access-"+idArray[i]).attr("checked","checked");
                }
            }
            else
            {
                for(i=0;i<lengthArray;i++)
                {
                    $("#access-"+idArray[i]).attr("checked",false);
                }
                $("#selectall").attr("checked",false);
            }
        }
    }

    function unselectallaction(checkid,ids,unceckid)
    {
        var idArray;
        var lengthArray=0;
        var i=0;

        if(ids!="")
        {
            idArray=ids.split(",");

            lengthArray=idArray.length;

            if(document.getElementById(checkid).checked==false)
            {
                for(i=0;i<lengthArray;i++)
                {
                    $("#access-"+idArray[i]).attr("checked",false);
                }
                $("#selectall").attr("checked",false);
            }

            if(unceckid!="")
            {
                $("#"+unceckid).attr("checked",false);
            }
        }
    }

    function selectfirstaction(checkid,ids)
    {
        var idArray;
        var lengthArray=0;
        var i=0;

        if(ids!="")
        {
            idArray=ids.split(",");

            lengthArray=idArray.length;

            if(document.getElementById(checkid).checked==true)
            {
                for(i=0;i<lengthArray;i++)
                {
                    $("#access-"+idArray[i]).attr("checked","checked");
                }
            }
        }
    }

    function unselectall(checkid)
    {
        if(document.getElementById(checkid).checked==false)
        {
            $("input[name='access[]']").each(function() {
                this.checked = false;
            });
            $("input[name='chkmodule[]']").each(function() {
                this.checked = false;
            });
            $("input[name='chkaction[]']").each(function() {
                this.checked = false;
            });
        }
    }

    function selelectallchk()
    {
        if(document.getElementById('selectall').checked==true)
        {
            $("input[name='access[]']").each(function() {

                if(this.disabled==false)
                {
                    this.checked = true;
                }
            });
            $("input[name='chkmodule[]']").each(function() {
                this.checked = true;
            });
            $("input[name='chkaction[]']").each(function() {
                this.checked = true;
            });
        }
        else
        {
            $("input[name='access[]']").each(function() {
                this.checked = false;
            });
            $("input[name='chkmodule[]']").each(function() {
                this.checked = false;
            });
            $("input[name='chkaction[]']").each(function() {
                this.checked = false;
            });
        }
        $(".case").click(function(){

            if($(".case").length == $(".case:checked").length) {
                $("#selectall").attr("checked", "checked");
            } else {
                $("#selectall").removeAttr("checked");
            }
        });
    }
</script>

<?php if ($_REQUEST['action'] != '') $action = ucwords($_REQUEST['action']); ?>
<div class="breadcrumbs"><a href="index.php">Home </a>&nbsp;>&nbsp; <a href="index.php?module=accesscontrol&view=group">Manage Group Access</a>&nbsp; >&nbsp; <span class="current"><?= $action ?> Group Access</span>  </div>
<div id="dialog-modal" title="groups"></div>
<div class="add-new-user-title">
    <h2 ><img alt="add-new-listing" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>/add-new-user-icon.png"><?= $action ?> Group Access <?php
if ($_REQUEST['action'] == 'edit') {
    echo '-' . ' ' . $row['var_name'];
}
?></h2>
</div>

<?= $messagebox ?>
<form  name="frmcontact"  id="frmcontact" action="<?= $frmaction ?>" method="post" onSubmit="return validate();" enctype="multipart/form-data" >
    <input type="hidden" name="h_save" id="h_save" value="T">
    <input type="hidden" name="fk_modules" id="fk_modules" value="<?php echo $fk_modules ?>">
    <input type="hidden" name="old_displayorder" id="old_displayorder" value="<?= $row['int_displayorder'] ?>">
    <?php
    if ($row['int_displayorder'] != '') {
        $int_disporder = $row['int_displayorder'];
    } else {
        $int_disporder = '1';
    }

    if ($row['chr_publish'] != '') {
        $hidden_chr_publish = $row['chr_publish'];
    } else {
        $hidden_chr_publish = 'Y';
    }
    ?>
    <div class="web-booking-main">
        <div class="grid-list-subtitle-bg" style="margin-top:10px; cursor:pointer" onClick="javascript:expandcollapsepanel('asignbanner');" >
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td align="left" valign="top" class="grid-td-left">Groups Informations</td>
                </tr>
            </table>
        </div>
        <div class="information-white-bg" id="asignbanner" >
            <div class="clear"></div>
            <div class="grid-list-inner-table-text">
                <table width="100%" border="0" cellspacing="3" cellpadding="3">
                    <tr>
                        <td width="15%" align="left" valign="top" class="add-new-user-text"> Group Name : <span>(required)</span> </td>
                        <td width="27%" align="left" valign="top">
                            <input name="var_name" type="text"  class="add-new-user-textarea" style="width:300px" id="var_name" value="<?= $row['var_name']; ?>" maxlength="100" /></td>
                        <td width="30%"></td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="clear"></div>
        <!-- new access -->
        <div class="grid-list-subtitle-bg" style="margin-top:10px; cursor:pointer" onClick="javascript:expandcollapsepanel('assignAccess');" >
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td align="left" valign="top" class="grid-td-left">Access Information</td>
                </tr>
            </table>
        </div>
        <div class="information-white-bg" id="assignAccess" >
            <div class="grid-list-subtitle-bg" style="margin-top:10px;">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="4%" align="center" valign="middle" class="grid-td-left"><input class="checkallcheckbox" name="selectall" id="selectall" type="checkbox" onclick="selelectallchk();"/></td>
                        <td width="20%" align="left" valign="middle" class="grid-td-top">Module Name</td>
                        <?php
                        foreach ($allAction as $Action) {
                            if ($Action['actionId'] == 1) {
                                $onclick = "selectallaction('chkaction-" . $Action[actionId] . "',$('#hidactions-" . $Action[actionId] . "').val());unselectall('chkaction-" . $Action[actionId] . "');";
                            } else {
                                $onclick = "selectallaction('chkaction-" . $Action[actionId] . "',$('#hidactions-" . $Action[actionId] . "').val());selectfirstaction('chkaction-" . $Action[actionId] . "',$('#hidactions-1').val());";
                            }
                            ?>
                        <td width="10%" align="center" valign="middle" class="grid-td-top">
                        <input class="checkallcheckbox" name="chkaction[]" id="chkaction-<?php echo $Action['actionId'] ?>" type="checkbox" onclick="<?php echo $onclick; ?>"  />&nbsp;<?php echo $Action['actionName'] ?></td>
                <?php } ?>
                    </tr>
                </table>
            </div>
            <div class="information-white-bg" id="dvpersonalinformation" >
                <div class="grid-list-inner-table-text">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" >
                      <?php  $i=0; 
                        foreach ($allModule as $Module) { ?>
                           
                            <tr id="gtr-<?= $row['int_glcode'] ?>"  style="background-color: transparent;"  class="<?= $clsname ?>" onmouseover="this.style.backgroundColor='#f6f6f6'" onmouseout="this.style.backgroundColor='transparent'" >
                                <td width="4%" align="center" valign="middle" class="grid-td-left"><input name="chkmodule[]" id="chkmodule-<?php echo $Module['moduleId'] ;  ?>" type="checkbox" value="<?php echo $row['int_glcode'] ?>" onclick="selectallaction('chkmodule-<?php echo $Module['moduleId'] ;?>',$('#hidmodules-<?php echo $Module['moduleId'] ; ?>').val())"/></td>
                                <td width="20%" align="left" valign="middle" class="grid-td-top">
                                <?php echo $Module['chr_pro_modulename'] ?>
                                </td>
                                <?php
                                foreach ($allAction as $Action) {
                                    if ($Action['actionId'] == 1) {
                                        $onclick = "unselectallaction('access-" . $Module[moduleId] . "-" . $Action[actionId] . "',$('#hidmodules-" . $Module[moduleId] . "').val(),'chkmodule-" . $Module['moduleId'] . "-')";
                                    } else {
                                        $onclick = "javascript:$('#access-" . $Module['moduleId'] . "-1').attr('checked',true);";
                                    }

                                    if ($accesscontrolObj->actionassign[$Module['moduleId']][$Action['actionId']] == 'Y') {
                                        $checked = "checked";
                                    } else {
                                        $checked = "";
                                    }
                                    if ($accesscontrolObj->actiondisable[$Module['moduleId']][$Action['actionId']] != 'N') {
                                        $Disable = ' disabled="disabled"';
                                        $checked = "";
                                    } else {
                                        $Disable = "";
                                        $modulewiseids .= $Module['moduleId'] . '-' . $Action['actionId'] . ',';
                                        $actionwiseids[$Action['actionName']] .= $Module['moduleId'] . '-' . $Action['actionId'] . ',';
                                    }
                                    ?>
                                    <td width="10%" align="center" valign="middle" class="grid-td-top"><?php //echo $actionmodule[$Module['moduleId']][$Action['actionId']][$Module['chrcustom']].'-----'.$Module['moduleId'].'-'.$Action['actionId'].'-'.$Module['chrcustom']; ?>
                                        <input <?php echo $checked ?> class="checkallcheckbox"  name="access[]" id="access-<?php echo $Module['moduleId'] . '-' . $Action['actionId'] ; ?>" <?php echo $Disable ?> type="checkbox" value="<?php echo $actionmodule[$Module['moduleId']][$Action['actionId']]; ?>" onclick="<?php echo $onclick; ?>"/>&nbsp;
                                    </td>

                                    <?php
                                }
                                ?> 
                                <input type="hidden" name="hidmodules[]" id="hidmodules-<?php echo $Module['moduleId'] ; ?>" value="<?php echo $modulewiseids; ?>">    </tr>
                                <?php
                                $modulewiseids = "";
                            }
                            foreach ($allAction as $Action) { ?>
                            <input type="hidden" name="hidactions[]" id="hidactions-<?php echo $Action['actionId']; ?>" value="<?php echo $actionwiseids[$Action['actionName']]; ?>">
                        <?php } ?>
                        <input type="hidden" name="ptrecords" id="ptrecords" value="<?= $rowcount ?>">
                    </table>
                </div>
            </div>
            <div class="clear"></div>
        </div>
        <div class="clear"></div>
        <?php
        if ($row['int_displayorder'] != '')
            $int_disporder = $row['int_displayorder'];
        else
            $int_disporder = '1';
        ?>
        <input name="chr_publish" id="chr_publish" type="hidden"  class="add-new-user-textarea"  value="Y"  />
        <br />
<?=$BottomSubmitButtons ?>
        <div class="clear">
        </div><br><br>
        <div class="add-new-user-button"></div>
    </div>
</form>