<?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");
    $page = $_GET['page'];
    $limit = $_GET['limit'];
    if (!($limit)) {
        $limit = 25;
    } // Default results per-page.
    if (!($page)) {
        $page = 0;
    } // Default page value.
    $numresults = $db->query("select * from u_users "); // the query.
    $numrows = mysql_num_rows($numresults); // Number of rows returned from above query.


    $pages = intval($numrows / $limit); // Number of results pages.

    // $pages now contains int of pages, unless there is a remainder from division.

    if ($numrows % $limit) {
        $pages++;
    } // has remainder so add one page

    $current = ($page / $limit) + 1; // Current page number.

    if (($pages < 1) || ($pages == 0)) {
        $total = 1;
    } // If $pages is less than one or equal to 0, total pages is 1.

    else {
        $total = $pages;
    } // Else total pages is $pages value.

    $first = $page + 1; // The first result.

    if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
        $last = $page + $limit;
    } //If not last results page, last result equals $page plus $limit.

    else {
        $last = $numrows;
    } // If last results page, last result equals total number of results.
    //escape from PHP mode.
   function get_groups_list($name, $selected = false)
    {
        $db = con();
        $sql = $db->query("select * from u_groups");
        $output = '<select name="' . $name . '">';
        $output .= '<option value=""> 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>';
        return $output;
    }
   
    function get_admin_groups_list($name, $selected = false)
    {
        $db = con();
        $sql = $db->query("select * from u_admin_groups order by groupsID");

        $output .= '<select name="' . $name . '">';
        $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;
    }
     function get_admin_groups_list2($name, $selected = false)
    {
        $db = con();
        $sql = $db->query("select * from u_admin_groups order by groupsID");

        $output .= '<select name="' . $name . '"  onchange="admin_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> سیستم جامع مدیریت W200 </title>
<?php include("maintemplate/mainheader.php");?>
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script>
function admin_file(id){ 
			$.ajax({
   type: "POST",
   url: "send_ajax_chitasoft.php?act=admin_file",
   data: "id="+id,
   success: function(msg){
document.getElementById("result").innerHTML=msg;
   }
			
 });
}	
</script>			
		
</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($_GET['do'])) {
        $action = $_GET['do'];
    }
    switch ($action) {

        case 'Create_file_admin':
?>
        <form action="groups.php?do=insert_Create_file" method="post">
  	 <table  class="table_insert" cellpadding="3" cellspacing="3" width="90%" align="center" >
        <tr>
            <td class="td_d">نام فايل: </td><td class="td_d"><input type="text" name="filename"  /></td>
        </tr>
        <tr>
            <td class="td_d">توضیحات: </td><td class="td_d"><input type="text" name="fileDescription" size="50"  /></td>
        </tr>
         <tr>
            <td colspan="2" align="center">  <input type="submit" name="insert" value="Insert" /></td>
        </tr>
        </table>        
        </form>	
<?php
            $sql = $db->query("select * from u_admin_files");
            echo '<table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0"  class="table1" >';
            echo '<tr><th class="td_header"> نام فايل </th><th class="td_header"> توضیحات </th><th class="td_header" align="center"> امکانات </th></tr>';
            while ($res = $db->fetchNextArray($sql)) {
                echo '<tr><td  align=center class="tablebattom1"> ' . $res['fileName'] . ' </td>
			<td  align=center class="tablebattom1"> ' . $res['description'] .
                    ' </td><td  align=center class="tablebattom1"> <a href="groups.php?do=delete_admin_file&GID=' .
                    $res['id'] . '"> <img border="0" src="images/dell.gif"> </a> </td></tr>';
            }
            echo '</table>';
            break;
            //-------------------------------------------------------------------------------------
        case 'delete_admin_file':
            if (isset($_GET['GID']) && ($_GET['GID'] != '')) {
                $db->execute("delete from u_admin_files where id = '" . (int)$_GET['GID'] . "'");
                echo ' فايل مورد نظرر با موفقيت حذف شد.<br><a href="groups.php?do=Create_file_admin"> بازگشت </a>';
            }
            break;
            //-------------------------------------------------------------------------------
        case 'insert_Create_file':

            if (isset($_POST['insert'])) {
                $db->execute("insert into u_admin_files set fileName='" . $db->safe_string($_POST['filename']) .
                    "', description='" . $db->safe_string($_POST['fileDescription']) . "'");
                $GID = $db->lastInsertedId();
                echo ' فايل جديد تعريف شد.<br><a href="groups.php?do=Create_file_admin">بازگشت</a>';
            }
            break;


            //=======================================================================================
        case 'Create_file_user':
?>
        <form action="groups.php?do=insert_Create_file_user" method="post">
  	 <table  class="table_insert" cellpadding="3" cellspacing="3" width="90%" align="center" >
        <tr>
            <td class="td_d">نام فايل: </td><td class="td_d"><input type="text" name="filename"  /></td>
        </tr>
        <tr>
            <td class="td_d">توضیحات: </td><td class="td_d"><input type="text" name="fileDescription" size="50"  /></td>
        </tr>
         <tr>
            <td colspan="2" align="center">  <input type="submit" name="insert" value="Insert" /></td>
        </tr>
        </table>
        </form>	
<?php


            $sql = $db->query("select * from u_files");
            echo '<table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0"  class="table1" >';
            echo '<tr><th class="td_header"> نام فايل </th><th class="td_header"> توضیحات </th><th class="td_header"> امکانات </th></tr>';
            while ($res = $db->fetchNextArray($sql)) {
                echo '<tr><td align=center class="tablebattom1"> ' . $res['fileName'] . ' </td>
			<td align=center class="tablebattom1"> ' . $res['description'] .
                    ' </td><td align=center class="tablebattom1"> <a href="groups.php?do=delete_user_file&GID=' .
                    $res['id'] . '"> <img border="0" src="images/dell.gif"> </a> </td></tr>';
            }
            echo '</table>';
            break;
            //-------------------------------------------------------------------------------------
        case 'delete_user_file':
            if (isset($_GET['GID']) && ($_GET['GID'] != '')) {
                $db->execute("delete from u_files where id = '" . (int)$_GET['GID'] . "'");
                echo 'File Deleted Successfully!<br><a href="groups.php?do=Create_file_user"> Back </a>';
            }
            break;
            //=======================================================================================

        case 'new_group':

            if (isset($_POST['insert'])) {
                $db->execute("insert into u_groups set groupName = '" . $db->safe_string($_POST['groupName']) .
                    "', groupDescription = '" . $db->safe_string($_POST['groupDescription']) . "'");
                $GID = $db->lastInsertedId();

                echo 'New Group is Defined.<br><a href="groups.php?do=new_group">Back</a> OR <a href="groups.php?do=set_access_user&GID=' .
                    $GID . '">Set Access Permissions</a> ';
                echo debug_message('گروه با موفقیت وارد شد ...', '2', '');
                echo '<form action="groups.php?do=new_group" method="POST">
		<p align="center"><input type="submit" id="button" value="OK"></p>
		</form>';
            } elseif (isset($_POST['edite'])) {
                $db->execute("update u_groups set groupName = '" . $db->safe_string($_POST['groupName']) .
                    "' , groupDescription = '" . $db->safe_string($_POST['groupDescription']) .
                    "' where groupsID = '" . (int)$_POST['groupsID'] . "'");

                echo debug_message('گروه با موفقیت ویرایش شد ...', '2', '');
                echo '<form action="groups.php?do=groups_list" method="POST">
		<p align="center"><input type="submit" id="button" value="OK"></p>
		</form>';
            } else {
                $sql = $db->query("select * from u_groups where groupsID='" . $_GET['GID'] . "'");
                $res = $db->fetchNextArray($sql);
                $num = $db->numRows($sql)

?>
<form action="groups.php?do=new_group" method="post">
<table border="0" width="90%" class="table_insert" >
<tr>
	<td class="td_d">نام گروه: </td><td class="td_d"><input type="text" name="groupName" value="<?php echo
$res['groupName']; ?>"  /></td>
</tr>
<tr>
	<td class="td_d">توضیحات: </td><td class="td_d"><input type="text" name="groupDescription" size="50" value="<?php echo
$res['groupDescription']; ?>" /></td>
</tr>
<tr>
	<td class="td_d"> </td><td class="td_d">
    
<?PHP if ($num) {
                    echo '<input type="submit" name="edite" value="Edite" /><input type="hidden" name="groupsID" value=' .
                        $res['groupsID'] . ' />';
                } else {
                    echo '<input type="submit" name="insert" value="Insert" />';
                }

?>    
    </td>
</tr>

</table>

</form>
<?php
            }
            break;

        case 'new_admin_group':

            if (isset($_POST['insert'])) {
                $db->execute("insert into u_admin_groups set groupName = '" . $db->safe_string($_POST['groupName']) .
                    "', groupDescription = '" . $db->safe_string($_POST['groupDescription']) . "'");
                $GID = $db->lastInsertedId();
                echo ' گروه جديد با موفقيت ابجاد شد.<br><a href="groups.php?do=new_admin_group">بازگشت </a> OR <a href="groups.php?do=set_access_admin&GID=' .
                    $GID . '"> تعريف سطح دسترسي.</a> ';
            } elseif (isset($_POST['edite'])) {
                $db->execute("update u_admin_groups set groupName = '" . $db->safe_string($_POST['groupName']) .
                    "' , groupDescription = '" . $db->safe_string($_POST['groupDescription']) .
                    "' where groupsID = '" . (int)$_POST['groupsID'] . "'");
                echo debug_message('گروه با موفقیت ویرایش شد ...', '2', '');

                echo '<form action="groups.php?do=admin_groups_list" method="POST">
		<p align="center"><input type="submit" id="button" value="OK"></p>
		</form>';
            } else {
                $sql = $db->query("select * from u_admin_groups where groupsID='" . $_GET['GID'] .
                    "'");
                $res = $db->fetchNextArray($sql);
                $num = $db->numRows($sql)
?>
<form action="groups.php?do=new_admin_group" method="post">
<table class="table_insert" cellpadding="3" cellspacing="3" width="90%" >
<tr>
	<td class="td_d">نام گروه: </td><td class="td_d"><input type="text" name="groupName" value="<?php echo
$res['groupName']; ?>"  /></td>
</tr>
<tr>
	<td class="td_d">توضیحات: </td><td class="td_d"><input type="text" name="groupDescription" size="50" value="<?php echo
$res['groupDescription']; ?>" /></td>
</tr>


<tr>
	<td class="td_d"> </td><td class="td_d">
<?PHP if ($num) {
                    echo '<input type="submit" name="edite" value="Edite" /><input type="hidden" name="groupsID" value=' .
                        $res['groupsID'] . ' />';
                } else {
                    echo '<input type="submit" name="insert" value="Insert" />';
                }

?>    
    </td>
</tr>
</table>

</form>
<?php
            }
            break;


        case 'admin_groups_list':
            $sql = $db->query("select * from u_admin_groups");
            echo '<table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0"  class="table1" >';
            echo '<tr><th class="td_header"> نام گروه </th><th class="td_header"> توضیحات </th><th class="td_header"> امکانات </th></tr>';
            while ($res = $db->fetchNextArray($sql)) {
                echo '<tr><td align=center class="tablebattom1"> ' . $res['groupName'] . ' </td>
			<td align=center class="tablebattom1"> ' . $res['groupDescription'] . ' </td>
			<td align=center class="tablebattom1">
			<a href="groups.php?do=Create_admin_user&GID=' . $res['groupsID'] .
                    '"> <img src="images/add.gif" border="0" title="add ">  </a> 
			<a href="groups.php?do=new_admin_group&GID=' . $res['groupsID'] .
                    '"><img src="images/edit.gif" border="0" title="edit "> </a>
            <a href="groups.php?do=delete_admin_group&GID=' . $res['groupsID'] .
                    '"> <img src="images/dell.gif" border="0" title="delete ">  </a>
            <a href="groups.php?do=set_access_admin&GID=' . $res['groupsID'] .
                    '"> <img src="images/info.gif" border="0" title="تعيين سطح دسترسی">  </a>
          </td></tr>';
            }
            echo '</table>';
            break;

        case 'delete_admin_group':
            if (isset($_GET['GID']) && ($_GET['GID'] != '')) {
                $db->execute("delete from u_admin_groups where groupsID = '" . (int)$_GET['GID'] .
                    "'");
                $db->execute("delete from u_admin_file_to_groups where groupID = '" . (int)$_GET['GID'] .
                    "'");
                echo 'Group Deleted Successfully!<br><a href="groups.php?do=admin_groups_list"> Back </a>';
            }
            break;


        case 'groups_list':
            $sql = $db->query("select * from u_groups");
            echo '<table width="600" border="1" cellpadinf="3" cellspacing="0" dir="rtl">';
            echo '<tr><th class="td_header"> نام گروه </th><th class="td_header"> توضیحات </th><th class="td_header"> امکانات </th></tr>';
            while ($res = $db->fetchNextArray($sql)) {
                echo '<tr><td align=center class="tablebattom1"> ' . $res['groupName'] . ' </td>
			<td align=center class="tablebattom1"> ' . $res['groupDescription'] . ' </td>
			<td align=center class="tablebattom1">  
			<a href="groups.php?do=Create_user&GID=' . $res['groupsID'] .
                    '"> <img src="images/add.gif" border="0">  </a>
			<a href="groups.php?do=new_group&GID=' . $res['groupsID'] .
                    '"><img src="images/edit.gif" border="0">  </a>
			
            <a href="groups.php?do=delete_user_group&GID=' . $res['groupsID'] .
                    '"> <img border="0" src="images/dell.gif"> </a> 			
			</td></tr>';
            }
            echo '</table>';
            break;

        case 'delete_user_group':
            if (isset($_GET['GID']) && ($_GET['GID'] != '')) {
                $db->execute("delete from u_groups where groupsID = '" . (int)$_GET['GID'] . "'");
                $db->execute("delete from u_file_to_groups where groupID = '" . (int)$_GET['GID'] .
                    "'");                    
                echo debug_message('گروه با موفقیت حذف شد ...', '2', '');
                echo '<form action="groups.php?do=groups_list" method="POST">
		<p align="center"><input type="submit" id="button" value="OK"></p>
		</form>';

            }
            break;


        case 'Create_user':

            if (isset($_GET['insert'])) {
                $db->execute("insert into u_users set userName = '" . $db->safe_string($_POST['userName']) .
                    "', userPass = '" . md5($_POST['Password']) . "', userGroup = '" . (int)$_POST['groupID'] .
                    "'");

                echo debug_message('گروه با موفقیت وارد شد ...', '2', '');

                echo '<form action="groups.php?do=users_list" method="POST">
		<p align="center"><input type="submit" id="button" value="OK"></p>
		</form>';

            } elseif (isset($_GET['update'])) {
                $db->execute("update u_users set userName = '" . $db->safe_string($_POST['userName']) .
                    "', userPass = '" . md5($_POST['Password']) . "', userGroup = '" . (int)$_POST['groupID'] .
                    "' where ID = '" . (int)$_GET['AID'] . "'");


                echo debug_message('کاربر با موفقیت وارد شد ...', '2', '');

                echo '<form action="groups.php?do=users_list" method="POST">
		<p align="center"><input type="submit" id="button" value="OK"></p>
		</form>';

            } else {
                $form_action = 'insert';
                if (isset($_GET['AID'])) {
                    $sql = $db->query("select * from u_users where ID = '" . (int)$_GET['AID'] . "'");
                    $res = $db->fetchNextArray($sql);
                    $_GET['GID'] = $res['userGroup'];
                    $form_action = 'update&AID=' . $_GET['AID'];
                }
?>
<form action="groups.php?do=Create_user&<?php echo $form_action; ?>" method="post">
<table border="0" width="90%" class="table_insert">
<tr>
	<td class="td_d">نام کاربری: </td><td class="td_d"><input type="text" name="userName" value="<?php echo
$res['userName']; ?>" /></td>
</tr>
<tr>
	<td class="td_d">رمز عبور: </td><td class="td_d"><?php if (isset($_GET['AID'])) {
                    echo 'Password Can\'t be displayed.<br>';
                } ?>
    <input type="text" name="Password" /></td>
</tr>
<tr>
	<td class="td_d"> گروه: </td><td class="td_d"><?php echo get_groups_list('groupID',
$_GET['GID']); ?></td>
</tr>

<tr>
	<td class="td_d"> </td><td class="td_d"><input type="submit" name="process" value="Insert" />
</td>
</tr>
</table>

</form>
<?php
            }
            break;

        case 'Create_admin_user':
            if (isset($_GET['insert'])) {
                $db->execute("insert into u_admin_users set 
														userName = '" . $db->safe_string($_POST['userName']) . "',
														userPass = '" . md5($_POST['Password']) . "',
														userGroup = '" . (int)$_POST['groupID'] . "',
														isAdmin = '1',
														first_lastName='" . $_POST['first_lastName'] . "' ");
				 $userID = $db->lastInsertedId();
				 $db->execute("insert into adminavilable set userID = '" .$userID."' ");
                echo debug_message('کاربر با موفقیت وارد شد ...', '2', '');

                echo '<form action="groups.php?do=admin_groups_list" method="POST">
		<p align="center"><input type="submit" id="button" value="OK"></p>
		</form>';

            } elseif (isset($_GET['update'])) {
                $db->execute("update u_admin_users set userName = '" . $db->safe_string($_POST['userName']) .
                    "', userPass = '" . md5($_POST['Password']) . "', userGroup = '" . (int)$_POST['groupID'] .
                    "', isAdmin = '1' where ID = '" . (int)$_GET['AID'] . "'");

                echo 'User is Updated.<br><a href="groups.php?do=admin_groups_list"> Back </a>';
            } else {
                $form_action = 'insert';
                if (isset($_GET['AID'])) {
                    $sql = $db->query("select * from u_admin_users where ID = '" . (int)$_GET['AID'] .
                        "'");
                    $res = $db->fetchNextArray($sql);
                    $_GET['GID'] = $res['userGroup'];
                    $form_action = 'update&AID=' . $_GET['AID'];
                }
?>
<form action="groups.php?do=Create_admin_user&<?php echo $form_action; ?>" method="post">
<table class="table_insert" cellpadding="3" cellspacing="3" width="90%" >
<tr>
	<td class="td_d">نام کاربری: </td><td class="td_d"><input type="text" name="userName" value="<?php echo
$res['userName']; ?>" /></td>
</tr>
<tr>
	<td class="td_d">نام و نام خانوادگی: </td><td class="td_d"><input type="text" name="first_lastName" value="<?php echo
$res['first_lastName']; ?>" /></td>
</tr>
<tr>
	<td class="td_d">رمز عبور: </td><td class="td_d"><?php if (isset($_GET['AID'])) {
                    echo 'Password Can\'t be displayed.<br>';
                } ?>
    <input type="text" name="Password" /></td>
</tr>
<tr>
	<td class="td_d"> گروه: </td><td class="td_d"><?php echo get_admin_groups_list('groupID',
$_GET['GID']); ?></td>
</tr>
<tr>
	<td class="td_d"></td><td class="td_d"><input type="submit" name="process" value="Insert" /></td>

</tr>
</table>

</form>
<?php
            }
            break;


        case 'admin_users_list':
            $sql = $db->query("select * from u_admin_users");
            echo '<table width="600" border="0" cellpadinf="3" cellspacing="0" dir="rtl">';
            echo '<tr><th class="td_header"> نام کاربری </th><th class="td_header"> نام گروه </th><th class="td_header"> امکانات </th></tr>';
            while ($res = $db->fetchNextArray($sql)) {
                $sql1 = $db->query("select groupName from u_admin_groups where groupsID = '" . $res['userGroup'] .
                    "'");
                $res1 = $db->fetchNextArray($sql1);
                echo '<tr><td align=center class="tablebattom1"> ' . $res['userName'] . ' </td>
			<td align=center class="tablebattom1"> ' . $res1['groupName'] . ' </td>
			<td align=center class="tablebattom1"> <a href="groups.php?do=delete_admin_user&AID=' .
                    $res['ID'] . '"> <img border="0" src="images/dell.gif"> </a> 
			<a href="groups.php?do=Create_admin_user&AID=' . $res['ID'] .
                    '"> <img src="images/edit.gif" border="0" title="edit "></a> </td></tr>';
            }
            echo '</table>';

            break;


        case 'delete_admin_user':
            if (isset($_GET['AID']) && ($_GET['AID'] != '')) {
                $db->execute("delete from u_admin_users where ID = '" . (int)$_GET['AID'] . "'");
                echo debug_message('ادمین با موفقیت حذف شد ...', '2', '');

                echo '<form action="groups.php?do=users_list" method="POST">
		<p align="center"><input type="submit" id="button" value="OK"></p>
		</form>';
            }
            break;


        case 'users_list':
?>
	<p align="center">صفحه <?= $current ?></b> از <?= $total ?></p>
    <?Php
            $sql = $db->query("select * from u_users  ORDER BY userName  LIMIT $page, $limit");
            echo '<table width="90%" border="0" cellpadinf="3" cellspacing="0" dir="rtl" class="table1" align="center">';
            echo '<tr><th class="td_header"> نام کاربری </th><th class="td_header"> نام گروه </th><th class="td_header"> امکانات </th></tr>';
            while ($res = $db->fetchNextArray($sql)) {
                $sql1 = $db->query("select groupName from u_groups where groupsID = '" . $res['userGroup'] .
                    "'");
                $res1 = $db->fetchNextArray($sql1);
                echo '<tr><td align=center class="tablebattom1"> ' . $res['userName'] . ' </td>
			<td align=center class="tablebattom1"> ' . $res1['groupName'] . ' </td>
			<td align=center class="tablebattom1"> <a href="groups.php?do=delete_user&AID=' .
                    $res['ID'] . '"> <img border="0" src="images/dell.gif"> </a> 
			<a href="groups.php?do=Create_user&AID=' . $res['ID'] .
                    '"> <img src="images/edit.gif" border="0" title="edit "></a> 
			
			<a href="groups.php?do=info_user&AID=' . $res['ID'] .
                    '"> <img src="images/info.gif" border="0" title="info"></a> 			
			</td></tr>';
            }
            echo '</table>';

            echo '<p align="center" style="margin-top:20px;" dir="rtl">';

            if ($page != 0) { // Don't show back link if current page is first page.
                $back_page = $page - $limit;
                echo ("<a style=\"text-decoration:none;color:#000\"   href=\"$PHP_SELF?do=users_list&query=$query&page=$back_page&limit=$limit\" class=\"pages\">back</a>    \n");
            }

            for ($i = 1; $i <= $pages; $i++) // loop through each page and give link to it.
                {
                $ppage = $limit * ($i - 1);
                if ($ppage == $page) {
                    echo ("<b style=\"text-decoration:none;color:#000\"  class=\"pages_on\">" .
                        Convertnumber2farsi($i) . "</b> \n");
                } // If current page don't give link, just text.
                else {
                    echo ("<a style=\"text-decoration:none;color:#000\"  href=\"$PHP_SELF?do=users_list&query=$query&page=$ppage&limit=$limit\" class=\"pages\">" .
                        Convertnumber2farsi($i) . "</a> \n");
                }
            }

            if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
                $next_page = $page + $limit;
                echo ("<a  style=\"text-decoration:none;color:#000\"  href=\"$PHP_SELF?do=users_list&query=$query&page=$next_page&limit=$limit\" class=\"pages\">next</a>\n");
            }
            echo '</p>';

            break;
            //=======================================================================================
        case 'info_user':


            $sql = $db->query("select * from u_users  where ID='" . $_GET['AID'] . "'");
            echo '<table width="90%" border="0" cellpading="3" cellspacing="0" dir="rtl" class="table1" align="center">';

            $row = $db->fetchNextArray($sql);
            echo '<tr><td align="right" class="tablebattom1">';

            echo ' <br />نام و نام خانوادگی : ' . $row['name_lastname'];
            echo ' <br />تاریخ تولد  : ' . $row['tavalod'];
            echo ' <br />آخرین مدرک تحصیلی  : ' . $row['madrak'];
            echo ' <br />آدرس پست الکترونیک : ' . $row['email'];
            echo ' <br />تلفن تماس  : ' . $row['tell'];
            echo ' <br />آدرس  : ' . $row['address'];
            echo '</td>
            </tr>
		    </table>';

            echo '<form action="groups.php?do=users_list" method="POST">
		<p align="center"><input type="submit" id="button" value="باز گشت"></p>
		</form>';

            break;

        case 'delete_user':
            if (isset($_GET['AID']) && ($_GET['AID'] != '')) {
                $db->execute("delete from u_users where ID = '" . (int)$_GET['AID'] . "'");

                echo debug_message('کاربر با موفقیت حذف شد ...', '2', '');

                echo '<form action="groups.php?do=users_list" method="POST">
		<p align="center"><input type="submit" id="button" value="OK"></p>
		</form>';

            }
            break;
    //====================================================================================

        case 'set_access_admin':
            if (isset($_POST['process'])) {
                $num = (int)$_POST['num'];
                $groupID = (int)$_POST['groupID'];                
                //حذف همه دست رسی ها  یک گروه
                $sql3 = $db->query("select * from u_admin_files");            
                while ($res3 = $db->fetchNextArray($sql3)) {
                      $sql2 = $db->query("DELETE FROM  u_admin_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_admin_file_to_groups set fileName = '" . $_POST['file' .
                            $i] . "',groupID = '" . $groupID . "'");
                    }
                }
                header("location: groups.php?do=set_access_admin");


            } else {
?>
<form action="groups.php?do=set_access_admin&insert" method="post">
<table border="0" width="100%">

	<td class="td_d"> گروه: </td><td colspan="3" class="td_d" ><?php echo get_admin_groups_list2('groupID', $_GET['GID']); ?></td>

</table>
<dir id="result"></dir>
<input type="submit" name="process" value="Process" />
</form>
<?php
            }
         break;

            //===================================================


        case 'set_access_user':
            if (isset($_POST['process'])) {
                $num = (int)$_POST['num'];
                $groupID = (int)$_POST['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 . "'");
                    }
                }
                echo 'Access Permissions Are Set.<br><a href="groups.php?do=set_access_user">Back</a>';


            } else {
?>
<form action="groups.php?do=set_access_user&insert" method="post">
 <table  class="table_insert" cellpadding="3" cellspacing="3" width="90%" >
<tr>
	<td class="td_d">نام فایل: </td><td class="td_d"><input type="text" name="fileName" /></td>
</tr>
<tr>
	<td class="td_d">توضیحات : </td><td class="td_d"><input type="text" name="descrption" /></td>
</tr>
</table>
<input type="submit" name="process" value="Process" />
</form>

<?php
            }
            break;

            //===============================================================================================

        case 'Create_file':
            if (isset($_POST['process'])) {
                $num = (int)$_POST['num'];
                $groupID = (int)$_POST['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 . "'");
                    }
                }
                echo 'Access Permissions Are Set.<br><a href="groups.php?do=set_access_user">Back</a>';
            } else {

?>

<form action="groups.php?do=Create_file&insert" method="post">
<table border="0" width="600">
<tr><td class="td_d"> گروه: </td>
	<td colspan="3" class="td_d"><?php echo get_admin_groups_list('groupID', $_GET['GID']); ?></td>
</tr>
<tr>
<?php
                $sql = $db->query("select * from u_files");
                $i = 1;
                while ($res = $db->fetchNextArray($sql)) {
                    echo '<td width="150" height="40" align="right">' . $res['description'] .
                        '<input type="checkbox" name="file' . $i . '" value="' . $res['fileName'] .
                        '" /></td>';
                    if (($i % 3) == 0)
                        echo '</tr><tr>';
                    $i++;
                }
                echo '<input type="hidden" name="num" value="' . ($i - 1) . '" />';

?>
</tr>
</table>
<input type="submit" name="process" value="Process" />
</form>
<?php }

            break;
    }
?>
                              </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 } ?>