<?php 
include('includes/function_lib2.php');
$obj1=new role_edit();
$rec=$obj1->getrole_parent_data($_REQUEST['Id']);
$child_rec=$obj1->getrole_child_data($_REQUEST['Id']);
//echo "<pre>";
//print_r($child_rec);
if(isset($_REQUEST['save']))
{
 $obj1->save_edit_data($_REQUEST);
}
?>
<link rel="stylesheet" href="css/new_mxerp_role.css">
<style type="text/css">


/* Hide footnote and breadcrumb stuff for screen. See print.css for the code that displays these. */
#ku_breadcrumbs, sup.footnote_tag, #footnote_wrapper {
	display: none;
}



/***** Tabbox ****/

/**
 * Tabbed widget
 */
.tabbox > .nav {
    list-style-type: none;
    margin: 0 0 -1px 0;
    padding-left: 0;
}

.tabbox > .nav li {
    background-color: #ebebeb;
    border: 1px solid #ccc;
    display:inline-block;
    height: 30px;
    line-height: 30px;
    margin: 0;
    margin-left: -6px;
    padding-bottom: 0;
    padding-left: 0;
    padding-top: 0;
    text-indent: 0;
}

.tabbox.tabbox-rounded > .nav li {
    border-radius: 10px 10px 0 0;
}

.tabbox > .nav li.active {
    border-bottom: 1px solid #fff;
    background-color: #ffffff;
}

.tabbox > .nav li:first-child {
    margin-left: 0;
}

.tabbox > .nav li a {
    display: block;
    height: 100%;
    padding: 0 10px;
    text-decoration: none;
	font-size:13px;
	padding-top:5px;
}

.tabbox.tabbox-rounded > .nav li a {
    border-radius: 10px 10px 0 0;
}

.tabbox > .nav li.active a {
    background-color: #fff;
    color: #e8000d;
}

.tabbox > .content {
    background: #fff;
    border: 1px solid #ccc;
    padding: 10px;
}

.tabbox > .content > .tab {
    height: 0;
    visibility: hidden;
    width: 0;
    display: none;
}

.tabbox > .content > .active {
    display: block;
}

.tabbox > .content > .tab.active {
    height: auto;
    visibility: visible;
    width: auto;
}

#region-sidebar-first .tabbox > .nav li {
    background: #fff;
    border: 1px solid #fff;
    border-width: 1px 1px 0 1px;
    margin-left: -5px;
}

#region-sidebar-first .tabbox > .nav li:first-child {
    margin-left: 5px;
}

#region-sidebar-first .tabbox > .nav li.active {
    border: 1px solid #ccc;
    border-bottom: 1px solid #fff;
}

#region-sidebar-first .tabbox > .content {
    border: 0;
    border-top: 1px solid #ccc;
}

/***** Accordions ****/
.accordion {
    cursor: pointer;
    font-family: Georgia, Times, "Times New Roman", serif;
    margin: 10px 0;
    font-size: 14px;
    font-weight: bold;
    padding-left: 12px;
    background: transparent url(../images/accordion-closed.gif) no-repeat center left;
    color: #0022B4;
}

.active_accordion {
    background: transparent url(../images/accordion-open.gif) no-repeat center left;
}

.accordion_content {
    padding: 0 0 10px 32px;
}


/*--For Tree Structure--*/
.treeview, .treeview ul { 
	padding: 0;
	margin: 0;
	list-style: none;
}

.treeview ul {
	background-color: white;
	margin-top: 4px;
}

.treeview .hitarea {
	background: url(images/treeview-default.gif) -64px -25px no-repeat;
	height: 16px;
	width: 16px;
	margin-left: -16px;
	float: left;
	cursor: pointer;
}
/* fix for IE6 */
* html .hitarea {
	display: inline;
	float:none;
}

.treeview li { 
	margin: 0;
	padding: 3px 0pt 3px 16px;
}

.treeview a.selected {
	background-color: #eee;
}

#treecontrol { margin: 1em 0; display: none; }

.treeview .hover { color: red; cursor: pointer; }

.treeview li { background: url(images/treeview-default-line.gif) 0 0 no-repeat; }
.treeview li.collapsable, .treeview li.expandable { background-position: 0 -176px; }

.treeview .expandable-hitarea { background-position: -80px -3px; }

.treeview li.last { background-position: 0 -1766px }
.treeview li.lastCollapsable, .treeview li.lastExpandable { background-image: url(images/treeview-default.gif); }  
.treeview li.lastCollapsable { background-position: 0 -111px }
.treeview li.lastExpandable { background-position: -32px -67px }

.treeview div.lastCollapsable-hitarea, .treeview div.lastExpandable-hitarea { background-position: 0; }

.treeview-red li { background-image: url(images/treeview-red-line.gif); }
.treeview-red .hitarea, .treeview-red li.lastCollapsable, .treeview-red li.lastExpandable { background-image:url(images/login/treeview-red.gif); } 

.treeview-black li { background-image: url(images/treeview-black-line.gif); }
.treeview-black .hitarea, .treeview-black li.lastCollapsable, .treeview-black li.lastExpandable { background-image: url(images/treeview-black.gif); }  

.treeview-gray li { background-image: url(images/treeview-gray-line.gif); }
.treeview-gray .hitarea, .treeview-gray li.lastCollapsable, .treeview-gray li.lastExpandable { background-image: url(images/treeview-gray.gif); } 

.treeview-famfamfam li { background-image: url(images/treeview-famfamfam-line.gif); }
.treeview-famfamfam .hitarea, .treeview-famfamfam li.lastCollapsable, .treeview-famfamfam li.lastExpandable { background-image: url(images/treeview-famfamfam.gif); } 


.filetree li { padding: 3px 0 2px 16px; }
.filetree span.folder, .filetree span.file { padding: 1px 0 1px 16px; display: block; }
.filetree span.folder { background: url(images/folder.gif) 0 0 no-repeat; }
.filetree li.expandable span.folder { background: url(images/folder-closed.gif) 0 0 no-repeat; }
.filetree span.file { background: url(images/file.gif) 0 0 no-repeat; }

.f13{font-family:Arial, Helvetica, sans-serif; font-size:12px; font-weight:bold;}
.f12{font-family:Arial, Helvetica, sans-serif; font-size:12px;}
</style>
<script type="text/javascript" src="js/jquery_005.js"></script>
<script type="text/javascript" src="js/ku_common.js"></script>

<script type="text/javascript" src="js/tree/jquery_002.js"></script>
<script src="js/tree/jquery.js" type="text/javascript"></script>
<script src="js/tree/jquery_003.js" type="text/javascript"></script>
<script type="text/javascript" src="js/tree/demo.js"></script>



<form method="post" action="" onsubmit="javascript:return validate()">
<div class="tabbox">
    <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
    		<tbody><tr>
    			<td>
    				<fieldset>
	<table align="center" border="0" cellpadding="5" cellspacing="2" width="100%">
	<tbody><tr>
		<td class="paddfeild"><font color="red">Role</font></td>
		<td>
		<input name="rolename" id="rolename" style="width:200px;background-color:#FFFFFF;" value="<?php echo $rec['secrolename'] ?>" type="text">				</td>				
		<td class="paddfeild"><font color="red">Status</font></td>
                <td><input name="rolestatus" type="radio" <?php if($rec['rolestatus']=="Y") { echo 'checked="true"'; } ?>   value="Y"  id="rolestatus1"/>
		  Active
            <input name="rolestatus" type="radio" value="N" <?php if($rec['rolestatus']=="N") { echo 'checked="true"'; } ?>   id="rolestatus"/>
Inactive</td>
                <td class="paddfeild"><font color="red">Company</font></td>
                <td><select name="company[]" multiple="multiple" id="mul_company"  >
            <?php $com_sql=DB_query("select * from companies",$db); while($com_res=DB_fetch_assoc($com_sql)){
                $com_saved=explode(',',$rec['companyid']);
                if(in_array($com_res['CompanyId'],$com_saved))
                        $p="selected";
                else
                    $p="";
                echo  '<option value="'.$com_res['CompanyId'].'" '.$p.'>'.$com_res['CompanyName'].'</option>';                
            }?>
           
            
          </select></td>
	</tr>
	</tbody></table>
    				</fieldset>
                          
                                
                            </fieldset>
    			</td>
    		</tr>
    	</tbody></table>
<ul class="nav" style="text-align:left;">
    <?php  
    $nn=0;$query=DB_query("select * from modules where status='Y'",$db);
                     while($row=DB_fetch_array($query))
                     { ?>
    <li class="<?php if($nn==0){?>active<?php } ?>"><a href="#"><?php echo $row['modulename'] ?></a></li>

                     <?php $nn++;} ?>
</ul>
  
<div class="content">   
    

 <?php  
 $mm=0;
 $m=0;
 
 $query=DB_query("select * from modules Where status='Y'",$db);
                     while($row=DB_fetch_array($query))
                     {   
                    // if($mm==0) { ?>
    
                     <?php // } ?>
<div style="display: block; text-align:left;" class="tab <?php if($mm==0){?>active<?php } ?>">
<div align="center" style="margin-bottom:20px; width:500px; margin-left:230px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="50" align="left" valign="bottom" class="f12">
      <input type="checkbox" id="alladd_<?php echo $row['id'] ?>" checked="true" class="all_add" />Add</td>
    <td width="50" align="left" valign="bottom"> 
      <input type="checkbox" id="alledit_<?php echo $row['id'] ?>" checked="true" class="all_edit" />Edit</td>
    <td width="55" align="left" valign="bottom"> 
      <input type="checkbox" id="alldelete_<?php echo $row['id'] ?>" checked="true" class="all_delete" />Delete</td>
    <td width="50" align="left" valign="bottom"> 
      <input type="checkbox" id="allview_<?php echo $row['id'] ?>" checked="true" class="all_view" />View</td>
    <td width="70" align="left" valign="bottom"> 
      <input type="checkbox" id="allapproval_<?php echo $row['id'] ?>" checked="true" class="all_approve" />Approval</td>
    <td align="left" valign="bottom"> 
      <input type="checkbox" id="allcancel_<?php echo $row['id'] ?>" checked="true" class="all_cancel" />Cancel</td>
  </tr>
</table>
</div>
    <div><input type="checkbox" class="full_module"><span style="font-weight: bold;font-style: italic;color: red">Full Module</span></div>
<ul id="red" class="treeview-red treeview">
<?php 
$mod_cat=DB_query("select * from module_form_categories where module_id=".$row['id']." and status='Y'",$db); 
while($mod_cat_res=DB_fetch_assoc($mod_cat)){ 
?>

	<li class="expandable"><div class="hitarea expandable-hitarea"></div><span class="f13"><?php echo $mod_cat_res['cat_desc'] ?></span>
            
           <ul style="display: block;">
                 <li class="last"><span class="f12" style="font-style: italic;color: #0a0;font-weight: bold"><input type="checkbox"  class="module_cat_checked" >All</span></li>
               <?php 
$form_sql=DB_query("select * from modules_form where module_form_category_id=".$mod_cat_res['id']." and status='Y' ",$db); 
while($form_res=DB_fetch_assoc($form_sql))
{
     if(array_key_exists($form_res['id'],$child_rec))
     {   $form_check="checked";
            $form_primary_key=$child_rec[$form_res['id']]['id'];
          if($child_rec[$form_res['id']]['PerAdd']=="1")
               $PerAdd="checked";
          else
               $PerAdd="";
           if($child_rec[$form_res['id']]['PerEdit']=="1")
               $PerEdit="checked";
          else
               $PerEdit="";
           if($child_rec[$form_res['id']]['PerDelete']=="1")
               $PerDelete="checked";
          else
               $PerDelete="";
           if($child_rec[$form_res['id']]['PerView']=="1")
               $PerView="checked";
          else
               $PerView="";
           if($child_rec[$form_res['id']]['PerApprove']=="1")
               $PerApprove="checked";
          else
               $PerApprove="";
           if($child_rec[$form_res['id']]['PerCancel']=="1")
               $PerCancel="checked";
          else
               $PerCancel="";
     }     
     else
     {  $form_check="";
     $PerCancel=""; $PerApprove="";$PerView="";$PerDelete="";$PerEdit="";$PerAdd="";
     $form_primary_key=0;
     }
         
?>
            <li class="last">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="200"><span class="f12"><input type="checkbox"  <?php echo $form_check; ?>  value="<?php echo $form_res['id'] ?>" name="role_form[]" id="role_form_<?php echo $form_res['id'] ?>" ><?php echo $form_res['frm_name'] ?><input type="hidden" name="moduleid[<?php echo $form_res['id'] ?>]" value="<?php echo $row['id']; ?>"><input type="hidden" name="form_pkid[<?php echo $form_res['id'] ?>]" value="<?php echo $form_primary_key; ?>"></span></td>
                        <td width="50" align="left"><input type="checkbox" <?php echo $PerAdd; ?> class="add_permission_<?php echo $row['id'] ?>" id="add_permission_<?php echo $form_res['id'] ?>" name="add[<?php echo $form_res['id'] ?>]" value="1" /></td>
                        <td width="50" align="left"><input type="checkbox" <?php echo $PerEdit; ?> id="edit_permission_<?php echo $form_res['id'] ?>" class="edit_permission_<?php echo $row['id'] ?>" name="edit[<?php echo $form_res['id'] ?>]" value="1" /></td>
                        <td width="55" align="left"><input type="checkbox" id="delete_permission_<?php echo $form_res['id'] ?>" <?php echo $PerDelete; ?> class="delete_permission_<?php echo $row['id'] ?>" name="delete[<?php echo $form_res['id'] ?>]" value="1" /></td>
                        <td width="50" align="left"><input type="checkbox" <?php echo $PerView; ?> class="view_permission_<?php echo $row['id'] ?>" name="view[<?php echo $form_res['id'] ?>]" id="view_permission_<?php echo $form_res['id'] ?>" value="1" /></td>
                        <td width="70" align="left"><input type="checkbox" <?php echo $PerApprove; ?> class="approval_permission_<?php echo $row['id'] ?>" id="approval_permission_<?php echo $form_res['id'] ?>" name="approval[<?php echo $form_res['id'] ?>]" value="1" /></td>
                        <td align="left"><input type="checkbox" <?php echo $PerCancel; ?> class="cancel_permission_<?php echo $row['id'] ?>" id="cancel_permission_<?php echo $form_res['id'] ?>" name="cancel[<?php echo $form_res['id'] ?>]" value="1" /></td>
                    </tr>
                </table>
            </li>
<?php $m++;} ?>
	</ul>
	</li>
	
	<?php } ?>
        </ul>
</div>
<?php $mm++;} ?>
</div>
</div>
    <input type="submit" value="Save" name="save">&nbsp; <input type="button" value="Cancel" name="">
</form>

<script>
    $(document).ready(function() {
        $('.all_add').click(function(){
            var id=this.id.split("_");
         if($("#alladd_"+id[1]).attr('checked')==true)
             { 
              $('.add_permission_'+id[1]).attr('checked',true);
             }
            else if($("#alladd_"+id[1]).attr('checked')==false)
             {
                $('.add_permission_'+id[1]).removeAttr('checked');
             }
        });
        
        $('.all_edit').click(function(){
            var id1=this.id.split("_");
         if($("#alledit_"+id1[1]).attr('checked')==true)
             { 
              $('.edit_permission_'+id1[1]).attr('checked',true);
             }
            else if($("#alledit_"+id1[1]).attr('checked')==false)
             {
                $('.edit_permission_'+id1[1]).removeAttr('checked');
             }
        });
        
         $('.all_delete').click(function(){
            var id2=this.id.split("_");
         if($("#alldelete_"+id2[1]).attr('checked')==true)
             { 
              $('.delete_permission_'+id2[1]).attr('checked',true);
             }
            else if($("#alldelete_"+id2[1]).attr('checked')==false)
             {
                $('.delete_permission_'+id2[1]).removeAttr('checked');
             }
        });
      
      
       $('.all_view').click(function(){
            var id3=this.id.split("_");
         if($("#allview_"+id3[1]).attr('checked')==true)
             { 
              $('.view_permission_'+id3[1]).attr('checked',true);
             }
            else if($("#allview_"+id3[1]).attr('checked')==false)
             {
                $('.view_permission_'+id3[1]).removeAttr('checked');
             }
        });
        
        $('.all_approve').click(function(){
            var id4=this.id.split("_");
            
         if($("#allapproval_"+id4[1]).attr('checked')==true)
             { 
              $('.approval_permission_'+id4[1]).attr('checked',true);
             }
            else if($("#allapproval_"+id4[1]).attr('checked')==false)
             {
                $('.approval_permission_'+id4[1]).removeAttr('checked');
             }
        });
        
        
        $('.all_cancel').click(function(){
            var id4=this.id.split("_");
         if($("#allcancel_"+id4[1]).attr('checked')==true)
             { 
              $('.cancel_permission_'+id4[1]).attr('checked',true);
             }
            else if($("#allcancel_"+id4[1]).attr('checked')==false)
             {
                $('.cancel_permission_'+id4[1]).removeAttr('checked');
             }
        });
        
          $('input[name="role_form[]"]').click(function(){
          var frm_id=this.id.split("_");
          if($('#'+this.id).attr('checked')==true)
              {
                   $('#add_permission_'+frm_id[2]).attr('checked',true);
                   $('#edit_permission_'+frm_id[2]).attr('checked',true);
                   $('#delete_permission_'+frm_id[2]).attr('checked',true);
                   $('#view_permission_'+frm_id[2]).attr('checked',true);
                   $('#approval_permission_'+frm_id[2]).attr('checked',true);
                   $('#cancel_permission_'+frm_id[2]).attr('checked',true);
              }
              else
                  {
                   $('#add_permission_'+frm_id[2]).removeAttr('checked');
                   $('#edit_permission_'+frm_id[2]).removeAttr('checked');
                   $('#delete_permission_'+frm_id[2]).removeAttr('checked');
                   $('#view_permission_'+frm_id[2]).removeAttr('checked');
                   $('#approval_permission_'+frm_id[2]).removeAttr('checked');
                   $('#cancel_permission_'+frm_id[2]).removeAttr('checked');
                  }
      });
       $('.module_cat_checked').click(function(){
        $(this).parent().parent().siblings('li').find("input[type='checkbox']").attr('checked', this.checked);
        });
      $('.full_module').click(function(){
         $(this).parent().siblings('ul').find("input[type='checkbox']").attr('checked', this.checked);
      });
   });
   
function validate()
{
   
    if(document.getElementById("rolename").value=='')
    {
            alert('Please enter name of the role');
            document.getElementById("rolename").focus();
            return false;
    }
    if(document.getElementById("rolestatus1").checked==false && document.getElementById("rolestatus").checked==false)
    {
            alert('Please choose status of the role');
            //document.getElementById("rolestatus1").focus();
            return false;
    }
   
 if($('#mul_company').val()==null)
        {
             alert('Please select Company');
               // $('#mul_company').focus();
            return false;
        }
        
       
}

</script>    
