<?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");
if(isset($_GET['do'])){
	$action = $_GET['do'];
}

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

		if(isset($_POST['Insert'])){
			$db->execute("insert into m_valide_ip set ip ='".$db->safe_string($_POST['userip'])."'");
	        header("location: m_list_ip.php");
		}
	break;
	
	case 'edit_ip':
		$db->execute("update  m_valide_ip set ip ='".$db->safe_string($_POST['userip'])."' where id ='".$_POST['id']."'");
		header("location: m_list_ip.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>سیستم جامع مدیریت W200 </title>

<?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>ها ip مدیریت </h2>
                <div id="dashboard-widgets-wrap">
                    <div id="dashboard-widgets" class="metabox-holder">
                        <div class="postbox-container" style="width:49%;">
                            <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>ها ip مدیریت  </span></h3>


<?php

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

}

switch($action){
	
	
    //-------------------------------------------------------------------------------------	
    	default :
		$sql2=$db->query("select * from m_valide_ip where id='".$_GET['id']."'");
		$res2=$db->fetchNextArray($sql2);
		$num=$db->numRows($sql2);
		if($num){
			$act='do=edit_ip';
		}else{
			$act='do=insert_ip';
		}
	?>
        <form action="m_list_ip.php?<?=$act?>" method="post">
  	 <table  class="table_insert" cellpadding="3" cellspacing="3" width="90%" align="center" >
        <tr>
            <td class="td_d">IP :</td><td class="td_d"><input type="text" name="userip" value="<?=$res2['ip']?>"  /></td>
        </tr>
         <tr>
            <td colspan="2" align="center">
            <?php
			if(!$num){
              echo '<input type="submit" name="Insert" value="ذخیره" />';
			}else{
				 echo '<input type="submit" name="edit" value="ویرایش" /><input type="hidden" name="id" value="'.$res2['id'].'">';
			}
			?>
              </td>
        </tr>
        </table>
        
        </form>	
<?php


		$sql = $db->query("select * from m_valide_ip ORDER BY id ");
		echo '<table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0"  class="table1" >';
		echo '<tr><th class="td_header">IP</th><th class="td_header" align="center"> امکانات </th></tr>';
		while($res = $db->fetchNextArray($sql)){
			echo '<tr><td  align=center class="tablebattom1"> '.$res['ip'].' </td>
			 		<td  align=center class="tablebattom1"> <a href="m_list_ip.php?act=delete&GID='.$res['id'].'"><img border="0" src="images/dp.png"></a><a href="m_list_ip.php?id='.$res['id'].'"><img border="0" src="images/ep.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 } ?>