<?php
if(!defined('IN_GATEWEI')) {	exit('Access Denied');}
include ('./clientdata/cache/cache_navigation.php');
    if($ipost=="order"){
	
	$temp=$nav[$get_id];
	krsort($nav);
    foreach($nav as $k => $v)
	{
	  if($k<$get_id)
		  {
	      $nav[$k+1]=$nav[$k];
	      }
	}
	$nav[0]=$temp;
	ksort($nav);
	w2navigation($nav,'update');
}

if($ipost=="delete"){
	array_splice($nav,$get_id,1);
	ksort($nav);
	w2navigation($nav,'update');
	gadminmessage("删除成功","siteadmin.php?iframe=navigation",1);
}

if($ipost=="save")
{
	foreach($naviname as $key =>$val){
		if(!empty($val)){
			if(substr($naviurl[$key],0,7)!="http://"){
				$naviurl[$key]="http://".$naviurl[$key];
			}
			$navigation[]=$val.';'.$naviurl[$key].';other;0';
		}	
	}
    w2navigation($navigation);
	gadminmessage("设置成功","siteadmin.php?iframe=navigation",1);
}

if($ipost=="add")
{
	foreach($nav as $val){
	$navi[]=$val['title'].';'.$val['url'].';'.$val['type'].';'.$val['id'];
	}

	foreach($navigation as $val){
	$navi[]=$val;
	}
	foreach($naviname as $key =>$val){
		if(!empty($val)){
			if(substr($naviurl[$key],0,7)!="http://"){
				$naviurl[$key]="http://".$naviurl[$key];
			}
			$navi[]=$val.';'.$naviurl[$key].';other;0';
		}	
	}
    w2navigation($navi);
	writelog($message=array("用户ID:\t".$userid."\t修改导航设置成功\t".$currentip."\t".gmdate("Y-n-j H:i" , $timestamp + 8*3600)));
	gadminmessage("设置成功","siteadmin.php?iframe=navigation",1);
}

function ordernav()
{ 
	global $nav;
ksort($nav);
$i=0;
foreach ($nav as $key => $val)
	{	
?>
<div class="navitem"><a id="nav_<?php echo $i?>" href="javascript:void(0)" onmouseover="showMenu(this.id,0,2)"><?php echo $val['title']?></a></div>

<div class="popupmenu_popup" id="nav_<?php echo $i?>_menu" style="display:none">
<a href="siteadmin.php?iframe=navigation&ipost=delete&get_id=<?php echo $key?>">删除</a>
<a href="siteadmin.php?iframe=navigation&ipost=order&get_id=<?php echo $key?>">优先</a>
</div>
<?php
		if($i>9){
		  break;
		}
		$i++;
	} 
}
?>

<table>
<caption>网站导航设置</caption>
		  <tr>
    <th colspan="2"><span>网站导航菜单</span></th>
  </tr>
	  <tr>
    <td colspan="2"><?php echo ordernav() ?></td>
  </tr>

  <tr>
          <td colspan="2">
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
	      </td>
   </tr>
    </table>

<form id="navigationform" method="post">
<div id="navigationlist">
<table >
  <tr>
    <th class="boundary"><span>站内信息分类</span></th>
	<th class="boundary">设为导航</th>
  </tr>
<tbody>
   <tr>
    <td class="boundary"><span><img src="images/common/arrow_01.gif" class="absmiddle"> 网站首页</span></td>
    <td class="boundary"><input type="checkbox" name="navigation[]" value="网站首页;index.php;index;0"></td>
    </tr>
</tbody>
<tbody>
	 <tr>
    <td class="boundary"><span><img src="images/common/arrow_01.gif" class="absmiddle"> <?php echo $surveyname?></span></td>
	<td class="boundary">
	<INPUT TYPE="checkbox" name="navigation[]" value="<?php echo $surveyname?>;surveydisplay.php;survey;0" ></td>
    </tr>
</tbody>
    <tr>
    <td class="boundary"><span><img src="images/common/arrow_01.gif" class="absmiddle"> <?php echo $articlename?></span></td>
	<td class="boundary">&nbsp;</td>
    </tr>
	<?php
			$q=$db->query("SELECT * FROM g_articlecategory WHERE pid = 0 ORDER BY ord");
			while($categorys=$db->fetch_array($q))
				{
	?>
  <tr>
    <td class="boundary"><span class="navisub"><img src="images/common/arrow_01.gif" class="absmiddle"> <?php echo $categorys['categorytitle']?></font></span></td>
    <td class="boundary"><INPUT TYPE="checkbox" NAME="navigation[]" value="<?php echo $categorys['categorytitle']?>;articledisplay.php?pid=0&categoryid=<?php echo $categorys['acid']?>;article;<?php echo $categorys['acid']?>"></td>
  </tr>
				<?php
				$subq=$db->query("SELECT * FROM g_articlecategory WHERE pid = {$categorys['acid']} ORDER BY ord");
				while($subcategorys=$db->fetch_array($subq)){
				?>
	<tr>
    <td class="boundary"><span class="navisubsub"><img src="images/common/arrow_01.gif" class="absmiddle"> <?php echo $subcategorys['categorytitle']?></span></td>
    <td class="boundary"><INPUT TYPE="checkbox" NAME="navigation[]" value="<?php echo $subcategorys['categorytitle']?>;articledisplay.php?pid=<?php echo $subcategorys['pid']?>&categoryid=<?php echo $subcategorys['acid']?>;article;<?php echo $subcategorys['acid']?>"></td>
  </tr>

			  <?php
							}	  
				}	  
  ?>
   <tr>
    <td class="boundary"><span><img src="images/common/arrow_01.gif" class="absmiddle"> <?php echo $productname?></span></td>
	<td class="boundary">
	<INPUT TYPE="checkbox" name="navigation[]" value="<?php echo $productname?>;product.php;product;0" ></td>
    </tr>

		<?php
			$q=$db->query("SELECT * FROM g_productcategory WHERE pid = 0 ORDER BY ord");
			while($categorys=$db->fetch_array($q))
				{
	?>
  <tr>
    <td class="boundary"><span class="navisub"><img src="images/common/arrow_01.gif" class="absmiddle"> <?php echo $categorys['categorytitle']?></span></td>
    <td class="boundary"><INPUT TYPE="checkbox" NAME="navigation[]" value="<?php echo $categorys['categorytitle']?>;productdisplay.php?pid=0&categoryid=<?php echo $categorys['pcid']?>;product;<?php echo $categorys['pcid']?>"></td>
  </tr>
				<?php
				$subq=$db->query("SELECT * FROM g_productcategory WHERE pid = {$categorys['pcid']} ORDER BY ord");
				while($subcategorys=$db->fetch_array($subq)){
				?>
	<tr>
    <td class="boundary"><span class="navisubsub"><img src="images/common/arrow_01.gif" class="absmiddle"> <?php echo $subcategorys['categorytitle']?></span></td>
    <td class="boundary"><INPUT TYPE="checkbox" NAME="navigation[]" value="<?php echo $subcategorys['categorytitle']?>;productdisplay.php?pid=<?php echo $subcategorys['pid']?>&categoryid=<?php echo $subcategorys['pcid']?>;product;<?php echo $subcategorys['pcid']?>"></td>
  </tr>
			  <?php
							}	  
				}	  
  ?>

     <tr>
    <td class="boundary"><span><img src="images/common/arrow_01.gif" class="absmiddle"> <?php echo $forumname?></span></td>
	<td class="boundary"><INPUT TYPE="checkbox" NAME="navigation[]" value="<?php echo $forumname?>;forums.php;forum;0" ></td>
    </tr>

	<?php
			$q=$db->query("SELECT * FROM g_forumcategory WHERE pid = 0 ORDER BY ord");
			while($categorys=$db->fetch_array($q))
				{
	?>
  <tr>
    <td class="boundary"><span class="navisub"><img src="images/common/arrow_01.gif" class="absmiddle"> <?php echo $categorys['forumtitle']?></span></td>
    <td class="boundary"></td>
  </tr>
				<?php
				$subq=$db->query("SELECT * FROM g_forumcategory WHERE pid = {$categorys['forid']} ORDER BY ord");
				while($subcategorys=$db->fetch_array($subq)){
				?>
	<tr>
    <td class="boundary"><span class="navisubsub"><img src="images/common/arrow_01.gif" class="absmiddle"> <?php echo $subcategorys['forumtitle']?></span></td>
    <td class="boundary"><INPUT TYPE="checkbox" NAME="navigation[]" value="<?php echo $subcategorys['forumtitle']?>;forumdisplay.php?forid=<?php echo $subcategorys['forid']?>;thread;<?php echo $subcategorys['forid']?>"></td>
  </tr>
			  <?php
							}	  
				}	  
  ?>

       <tr>
          <td colspan="2">&nbsp;
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
	      </td>
   </tr>
  <tr>
    <th  colspan="3"><span>添加自定义导航</span></td>
  </tr>
    <tr>
    <td class="boundary"><span>频道名称</span></td>
	<td class="boundary"><span>频道URL地址(必须以http://开头)<span></td>
  </tr>
  <tr>
    <td class="boundary"><input name="naviname[]" type="text" class="formtext" maxlength="6" value=""></td>
	<td class="boundary"><input name="naviurl[]" type="text" class="formtext" value="http://"></td>
  </tr>
    <tr>
    <td class="boundary"><input name="naviname[]" type="text" class="formtext" maxlength="6" value=""></td>
	<td class="boundary"><input name="naviurl[]" type="text" class="formtext" value="http://"></td>
  </tr>
    <tr>
    <td class="boundary"><input name="naviname[]" type="text" class="formtext" maxlength="6" value=""></td>
	<td class="boundary"><input name="naviurl[]" type="text" class="formtext" value="http://"></td>
  </tr>
    <tr>
    <td class="boundary"><input name="naviname[]" type="text" class="formtext" maxlength="6" value=""></td>
	<td class="boundary"><input name="naviurl[]" type="text" class="formtext" value="http://"></td>
  </tr>
    <tr>
    <td class="boundary"><input name="naviname[]" type="text" class="formtext" maxlength="6" value=""></td>
	<td class="boundary"><input name="naviurl[]" type="text" class="formtext" value="http://"></td>
  </tr>
   <tr>
          <td colspan="2">&nbsp;
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
	      </td>
   </tr>

</table>

</div>


</form>
 <div id="submitdiv"><input name="g_navigation_submit" type="button" value="提&nbsp;&nbsp;交" onclick="submitnavigation()"> <input name="g_navigation_add" type="button" value="增&nbsp;&nbsp;加" onclick="addnavigation()"></div>
<SCRIPT LANGUAGE="JavaScript">
 function submitnavigation(){
	$('navigationform').action="siteadmin.php?iframe=navigation&ipost=save";
	$('navigationform').submit();
}
 function addnavigation(){
	$('navigationform').action="siteadmin.php?iframe=navigation&ipost=add";
	$('navigationform').submit();
}
</SCRIPT>

