<?php
include ("include/config.php");
include ("include/protect.class.php");
include ("include/functions.php");
$prot = new protect();
if ($prot->showPage) {
    $db = new DB($globalConfig['dbase'], $globalConfig['dbhost'], $globalConfig['dbuser'],
        $globalConfig['dbpass']);
    mysql_query("SET NAMES utf8");
  
  
     function get_user_groups_list2($name, $selected = false)
    {
        $db = con();
        $sql = $db->query("select * from u_groups order by groupsID");

        $output .= '<select name="' . $name . '"  onchange="user_file(this.value)">';
        $output .= '<option value="' . $res['groupsID'] . '"> Please Select </option>';
        while ($res = $db->fetchNextArray($sql)){
            $output .= '<option value="' . $res['groupsID'] . '"';
            if ($selected == $res['groupsID']) {
                $output .= ' selected="selected"';  }
            $output .= '>' . $res['groupName'] . '</option>';
        }
        $output .= '</select>';
        $output .= '</form>';
        return $output;
    }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>مدیریت دسترسی گروه های کاربری</title>

<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script>
function user_file(id){ 
			$.ajax({
   type: "POST",
   url: "send_ajax_chitasoft.php?act=user_file",
   data: "id="+id,
   success: function(msg){
document.getElementById("result").innerHTML=msg;
   }
 });
}	
</script>			
	<?php include("maintemplate/mainheader.php");?>	
</head>
<body>
<div id="wpwrap">
<div id="wpcontent">
	<?php include("include/menutop.php");?> 
<div id="wpbody">
	<?php include("include/header.php");?>
    <div style="overflow:hidden;" id="wpbody-content">
        <div id="screen-meta">
            <div class="wrap">
                <div id="icon-index" class="icon32"><br></div>
                <h2>مدیریت دسترسی گروه های کاربری</h2>
                <div id="dashboard-widgets-wrap">
                    <div id="dashboard-widgets" class="metabox-holder">
                        <div class="postbox-container" style="width:100%;">
                            <div id="normal-sortables" class="meta-box-sortables ui-sortable"><div id="dashboard_recent_comments" class="postbox ">
                   <div class="handlediv" title="برای جانشینی کلیک کنید"><br></div><h3 class="hndle"><span>مدیریت دسترسی گروه های کاربری  </span></h3>

      
<?php
            if (isset($_POST['process'])) {
                $num = (int)$_POST['num'];
                $groupID = (int)$_POST['groupID'];                
                //حذف همه دست رسی ها  یک گروه
                $sql3 = $db->query("select * from  u_user_files");            
                while ($res3 = $db->fetchNextArray($sql3)) {
                      $sql2 = $db->query("DELETE FROM  u_file_to_groups WHERE  fileName ='".$res3['fileName']."' AND groupID ='".$groupID."'");
                } 
                for ($i = 1; $i <= $num; $i++) {                     
                    if ($_POST['file' . $i] != '') {
                        $db->execute("insert into u_file_to_groups set fileName = '" . $_POST['file'.
                            $i] . "',groupID = '" . $groupID . "'");
                    }
                }
                header("location: m_set_access_users.php");
            } else {
?>
<form action="m_set_access_users.php" method="post">
<table border="0" width="600">
<td class="td_d"> گروه: </td>
	<td colspan="3" class="td_d"><?php echo $_GET['GID']; echo get_user_groups_list2('groupID'); ?></td>
</table>
<dir id="result"></dir>
<input type="submit" name="process" value="Process" />
</form>
<?php
            }       
    
?>
                            </div>
                            </div>
                        </div>                        
                    </div>
                    <div class="clear"></div>
                </div><!-- dashboard-widgets-wrap -->
            </div><!-- wrap -->
			<div class="clear"></div></div><!-- wpbody-content -->
			<div class="clear"></div></div><!-- wpbody -->
			<div class="clear"></div></div><!-- wpcontent -->
        </div>
    </div><!-- wpcontent -->
</div><!-- wpwrap -->
<?php include("include/footer.php");?>
</div>
</div>
</body>
</html><?php } ?>