<?php
/*
ساخت منو برای یک گرو مدیریتی
*/
include ("include/config.php");
include ("include/protect.class.php");
include ("include/functions.php");
include ("include/jdf.php");
$prot = new protect();
if ($prot->showPage) {
    $db = new DB($globalConfig['dbase'], $globalConfig['dbhost'], $globalConfig['dbuser'],
        $globalConfig['dbpass']);
    mysql_query("SET NAMES utf8");
    if (isset($_GET['do'])) {
        $action = $_GET['do'];
    }

    switch ($action) {
            //-------------------------------------------------------------------------------------
        case 'pdelete':
            if (isset($_GET['confirm'])) {
                $db->execute("delete from m_u_admin_menu where id = '" . (int)$_GET['id'] . "'");
            }
            header("location: m_make_menu.php");
            break;
            //-------------------------------------------------------------------------------
        case 'pinsert':

            if (isset($_POST['Insert'])) {
               echo $_POST['adgroup'];
                $res = $db->execute("insert into m_u_admin_menu set 
													link ='" . $db->safe_string($_POST['mlink']) . "',
													title ='" . $db->safe_string($_POST['mtitle']) . "',
													parent ='" . $db->safe_string($_POST['pmenu']) . "',
													admingroup ='" . $db->safe_string($_POST['adgroup']) . "'");
            }
            header("location: m_make_menu.php");
            break;

    }

?>

<!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>
<?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 ($_GET['act'] == 'delete') {
        if (!isset($_GET['confirm'])) {
            echo 'آيا شما مطمئنيد؟ <br /> <a href="m_make_menu.php?do=pdelete&id=' . (int)$_GET['GID'] .
                '&confirm"> بلــــه </a> | <a href="m_make_menu.php"> خيـــــر </a> ';
        }
    }

    switch ($action) {
            //-------------------------------------------------------------------------------------
        default:

            $sql2 = $db->query("select * from m_u_admin_menu where id='" . $_GET['id'] . "'");
            $res2 = $db->fetchNextArray($sql2);
            $num = $db->numRows($sql2);
            if ($num) {               
            } else {
                ////////////////////////اضافه کردن منو برای یک گروه خواص////////////////////////////////////////////
                $act = 'do=pinsert';
?>
             <form action="m_make_menu.php?<?= $act ?>" 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="mtitle" value=""  /></td> 
                       </tr>
                      <tr>
                         <td class="td_d">LINK :</td><td class="td_d"><input type="text" name="mlink" value=""  /></td>            
                       </tr>
         <tr>
            <td class="td_d">گروه مدیریت :</td>
            <td class="td_d">
            	<?php
                printCombobox("adgroup", "adgroup", "u_admin_groups", "groupsID", "groupName");
?>
            </td> 
        </tr>     
        <tr>
            <td class="td_d">منو والد :</td>
            <td class="td_d">
            <?php getadminsmenu("pmenu","pmenu","m_u_admin_menu","id","title","منو اصلی")?>
            </td> 
        </tr>         
         <tr>
            <td colspan="2" align="center">
            <?php
                echo '<input type="submit" name="Insert" value="ذخیره" />';                
?>
              </td>
        </tr>
        </table>        
        </form>	
            <?php
            }
?>       
<?php
            $sql = $db->query("select * from m_u_admin_menu  ORDER BY admingroup ,parent ASC ");
            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>
                            <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"> ' . admin_group_name($res['admingroup']) .
                    ' </td>
                <td  align=center class="tablebattom1"> ' . get_parent_menu_admin($res['parent']) .
                    ' </td>
                <td  align=center class="tablebattom1"> ' . $res['title'] .
                    ' </td>
                <td  align=center class="tablebattom1"> ' . $res['link'] .
                    ' </td>
			 		<td  align=center class="tablebattom1">
                     <a href="m_make_menu.php?act=delete&GID=' . $res['id'] .
                    '"><img border="0" src="images/dp.png"></a></td></tr>';
            }
            echo '</table>';
            echo '<p align="center" style="margin-top:20px;">';

            if ($page != 0) { // Don't show back link if current page is first page.
                $back_page = $page - $limit;
                echo ("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\" class=\"pages\">قبلی</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 class=\"pages_on\">" . $i . "</b> \n");
                } // If current page don't give link, just text.
                else {
                    echo ("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\" class=\"pages\">" .
                        $i . "</a> \n");
                }
            }

            if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
                $next_page = $page + $limit;
                echo ("<a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\" class=\"pages\">بعدی</a>\n");
            }
            echo '</p>';
            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 } ?>