<?php
define('IN_OUN', true);
include_once( "includes/command.php");

if(!empty($Aconf['priveMessage']))
{
   echo showMessage($Aconf['priveMessage']);
   exit;
}
/* 导航系统内容 */
if($Aconf["rewrite"] > 0 ){
	$Anavesys = array(
		'0'                =>   '选择模块',
		'index.html'        =>   '首页', 
		'articles.html'     =>   '文章列表',
		'products.html'     =>   '产品列表',  
		'pic.html'       =>   '图库', 
		'pravail.html'       =>   '商家列表', 
		'votes.html'        =>   '网上调查', 
		'links.html'      =>   '友情连接',
		'about.html'        =>   '关于我们',
		'support.html'      =>   '客户留言',
		'webreg.html'      =>   '网站申请注册',
	);
}else{
	$Anavesys = array(
		'0'                =>   '选择模块',
		'index.php'        =>   '首页', 
		'articles.php'     =>   '文章列表',
		'products.php'     =>   '产品列表',  
		'pic.php'       =>   '图库', 
		'pravail.php'       =>   '商家列表', 
		'votes.php'        =>   '网上调查', 
		'links.php'      =>   '友情连接',
		'about.php'        =>   '关于我们',
		'support.php'      =>   '客户留言',
		'webreg.php'      =>   '网站申请注册',
	);
}

 

$optNavesys = '<SELECT NAME="navesys" id="navesys_id" onchange="nave_sys(this.options[this.options.selectedIndex].value,this.options[this.options.selectedIndex].text)">';
while( @list( $k, $v ) = @each( $Anavesys) ) {
    $optNavesys .= '<OPTION VALUE="'.$k.'"  >'.$v. '</OPTION>';
}
$optNavesys .= '</SELECT>';

$db_table = $pre."nav";
//post
if(!empty($_POST["action"])){
	if(!isset($name)) $name=false; 
	if(!isset($vieworder)) $vieworder=false; 
	if(!isset($opennew)) $opennew=false; 
	if(!isset($url)) $url=false;  
	if( $_POST["action"] == 'add'  ) {
		if (trim($name) == '') {
		   $strMessage =  "导航名不能为空！";
		} else {
			$Afields=array('name'=>trim($name),'vieworder'=>$vieworder,'opennew'=>$opennew,'url'=>$url,'domain_id'=>$_SESSION[$un_domain_id]);
			$oPub->install($db_table,$Afields);
			$strMessage =  "添加成功!";
		}
		unset($_GET);
	}

	if( $_POST["action"] == 'edit'){
		$id = $id +0; 
		$Afields=array('name'=>trim($name),'vieworder'=>$vieworder,'opennew'=>$opennew,'url'=>$url,'domain_id'=>$_SESSION[$un_domain_id]);
		$condition = 'domain_id = '.$_SESSION[$un_domain_id].' and id = '.$id;
		$oPub->update($db_table,$Afields,$condition);
		$strMessage = "成功修改！";
		unset($_GET);
	}
}

//get
if(!isset($_GET["action"])) $_GET["action"]=false; 
if($_GET["action"] == 'edit'){
	$sql = "SELECT * FROM ".$db_table." 
	       WHERE id = ".$id.
		   " AND domain_id=".$_SESSION[$un_domain_id];
	$Anav = $oPub->selectrow($sql);
}

if($_GET["action"] == 'del'){
    $condition = 'id='.$id;
    $oPub->delete($db_table,$condition);
	
}

//page
$strWhere = " WHERE domain_id=".$_SESSION[$un_domain_id];
$sql = "SELECT count( * ) AS count FROM ".$db_table.$strWhere;
$row = $oPub->selectrow($sql);
$count = $row['count'];
unset($row);
$page = new ShowPage;
$page->PageSize =20;
$page->Total = $count;
$pagenew = $page->PageNum();
$page->LinkAry = array(); 
$page->PHP_SELF = $PHP_SELF;
$strOffSet = $page->OffSet();

$sql = "SELECT * FROM ".$db_table.$strWhere." ORDER BY vieworder,id asc limit ".$strOffSet;
$AnavAll = $oPub->select($sql);

$StrtypeAll = '';
$n = 0;
while( @list( $key, $value ) = @each( $AnavAll) ) {
	   $tmpstr = ($n % 2 == 0)?"even":"odd";
	   $n ++ ;
       $StrtypeAll .= '<TR class='.$tmpstr.'>';
       $StrtypeAll .= '<TD align=left>'.$value["name"].'</TD>';
       $StrtypeAll .= '<TD align=left>'.$value["url"].'</TD>';
	   $StrtypeAll .= '<TD align=left>'.$value["vieworder"].'</TD>';
    
	   $StrtypeAll .= '<TD align=left>';
	   $StrtypeAll .= ($value["opennew"])?'是':'否';
	   $StrtypeAll .= '</TD>';
       $StrtypeAll .= '<TD align=left><a href="'.$PHP_SELF.'?id='.$value["id"].'&action=edit&page='.$pagenew.'"><IMG SRC="images/b_edit.png" WIDTH="16" HEIGHT="16" BORDER="0" ALT="[编辑]"></a> _ ';
	   $StrtypeAll .= '<a href="'.$PHP_SELF.'?id='.$value["id"].'&action=del&page='.$pagenew.'"><IMG SRC="images/b_drop.png" WIDTH="16" HEIGHT="16" BORDER="0" ALT="[删除]"></a></TD>';
       $StrtypeAll .= '</TR>';    
}
?>
<?php
include_once( "header.php");
if (!empty($strMessage)) {
	 echo  '<SCRIPT language="javascript"> alert( "'.$strMessage.'");</script>';
}
?>

<DIV class=content>
<TABLE width="100%" border=0>
  <TR>
  <form name="form1" method="post" action="" > 
    <TD width="13%" align="left" colspan="6">
        <span style="font-weight:bold">系统内容:</span>
		<?php echo $optNavesys;?>
        <span style="font-weight:bold">名称:</span>
   		<input name="name" id="name_id" type="text" size="12" value="<?php echo !empty($Anav['id'])?$Anav['name']:''?>" />
		<br/>
        <span style="font-weight:bold">地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址:</span>
		<input name="url" id="url_id" type="text" size="50" value="<?php echo !empty($Anav['id'])?$Anav['url']:''?>" /><br/> 
		如果是本站的网址，可缩写为与根目录相对地址，如index.php；
        其他情况都应该输入完整的网址，如http://www.xy58.com/；<br/>查阅更多本站地址请访问 <a href="../map/" target="_blank">本网导航>></a>
        <br/>
		<span style="font-weight:bold">显示顺序:</span>
		<input name="vieworder" type="text" size="2" value="<?php echo !empty($Anav['id'])?$Anav['vieworder']:''?>" /> 
 
		<span style="font-weight:bold">在新窗口打开:</span>
		<SELECT NAME="opennew">
			<OPTION VALUE="0" <?php echo !empty($Anav['opennew'])?'':'SELECTED';?>>否</OPTION>
			<OPTION VALUE="1" <?php echo !empty($Anav['opennew'])?'SELECTED':'';?>>是</OPTION>
		</SELECT>         
		<input type="submit" name="Submit" value="<?php echo !empty($Anav['id'])?'编辑':'增加'?>" style="background-color: #FFCC66"/>

        <input type="hidden" name="action" value="<?php echo !empty($Anav['id'])?'edit':'add'?>" />        
		<input type="hidden" name="id" value="<?php echo !empty($Anav['id'])?$Anav['id']:''?>" />  
		<br/>
    </TD>
    </form>
  </TR>	
  <TR class=bg5>
    <TD width="20%" align=left>名称</TD>
    <TD width="50%" align=left>地址</TD>
	<TD width="10%" align=left>顺序</TD> 
	<TD width="10%" align=left>新窗口打开</TD>
	<TD width="10%" align=left>编辑/删除</TD>
  </TR>
  <?php echo $StrtypeAll?>
  <TR class=bg5>
    <TD colspan="6" align=right><?php echo $showpage = $page->ShowLink();?></TD>
  </TR>
</TABLE>
 
</DIV>
<script type="text/javascript" language="JavaScript">
function nave_sys(a,b)
{
	document.getElementById("name_id").value = b;
	document.getElementById("url_id").value  = a;
}
</script>
  
<?php
include_once( "footer.php");
?>