<?php
/**
 * 金戈企业建站系统：基本设置管理页面
 *
 *
 * @name 
 * @author 烟鬼 QQ:460874 Email:460874@qq.com
 * @version 0.1  $id  cener.php
 * @copyright Copyright (c) 2007 - 2008 烟鬼
 */
session_start();
require('../config.php');
require('rootfun/roothtml.php');
require('rootfun/rootfun.php');

//判断是否是管理员，该函数在myfun.php 中定义
if(!check_root())
	{
		echo '<meta http-equiv="Refresh" content="0; url=../error.php?error=nono" >';
		exit;
	}

//插入页头
rootheader();
?>
<div id="rootmain">

<?php

//获取在left.php通过URL传递过来的变量action 根据其值判断该进入哪一个模块
$action = $_GET['action'];
if($action == '')
{
	echo '<img src="img/logos.gif" />';
}
//基本设置
if ($action == 'jiben') 
{
	$row = root_all(web);
	if ($row) 
	{
	     $row = setassoc($row);
	     display_shezhi_form($row);
	}
	else 
	{
		display_shezhi_form();
	}
	
}

//如果更新基本设置将执行以下内容
if ($action == 'up') 
{
	//判断表单填写是否完整
     if (!filled_out($_POST)) 
     {
          echo '请完整填写表单--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
          exit;
     }
     
     //获取表单变量同时对变量进行格式化，使其能够存入数据库my_yz()函数在myapi/myfun.php中定义
     //其实该函数就是封装了一些常用的字符串格式化的函数。这样使用方便。
     $title = my_yz($_POST['title']);
     $cop = my_yz($_POST['cop']);
     $qq = my_yz($_POST['qq']);
     $icp = my_yz($_POST['icp']);
     $icpurl = my_yz($_POST['icpurl']);
     $mail = my_yz($_POST['mail']);
     $keywords = my_yz($_POST['keywords']);
     $description = my_yz($_POST['description']);
     $yb = my_yz($_POST['yb']);
     $tel = my_yz($_POST['tel']);
     $cstel = my_yz($_POST['cstel']);
     $dz = my_yz($_POST['dz']);
     $news = my_yz($_POST['news']);
     $chanpin = my_yz($_POST['chanpin']);
     $lyb = my_yz($_POST['lyb']);
     $fc = my_yz($_POST['fc']);
     $job = my_yz($_POST['job']);
     $ry = my_yz($_POST['ry']);
     
     if (!is_numeric($qq) || !is_numeric($yb) || !is_numeric($news) || !is_numeric($chanpin) ||
     		!is_numeric($lyb) || !is_numeric($fc) || !is_numeric($job) || !is_numeric($ry)) 
     {
          echo '请按要求填写表单--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
          exit;
     }
     //对一些字符串进行长度判断
     if (strlen($qq)>15 || strlen($tel)>15 || strlen($news)>5 || strlen($chanpin)>5 || 
     	strlen($lyb)>5 || strlen($fc)>5 || strlen($ry) > 5) 
     {
          echo '字符串请勿超出长度--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
          exit;
     }
     //update_shezhi()函数在rootfun.php中定义
     if (update_shezhi($title,$cop,$qq,$icp,$icpurl,$mail,$keywords,$description,$yb,$tel,$cstel,
     					$dz,$news,$chanpin,$lyb,$fc,$job,$ry)) 
     {
          echo '更新成功--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
     }
     else 
     {
     	 echo '更新失败--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
     }
}

//栏目管理
if ($action == 'lanmu') 
{
     echo '<div class="rnav">';
     //取出nav表的内容
     $conn = db_connect();
     $result=$conn->query("set names 'gb2312'");
     $result = $conn->query('SELECT * FROM nav');
     echo '<form id="form1" name="form1" method="post" action="center.php?action=uplanmu">';
     	for ($i=1;$i<9;$i++)
     	{
     		$row = $result->fetch_assoc();
     		$value = $row['nav_kz'];
     		$nav_id = $row['nav_id'];
     		echo $row['nav_name'];
     		echo "<input name='nav_kz$i' type='text' value='$value' size='5' />　如果不需要该栏目可设置为“0”，该栏目会被关闭<br />";
     		echo "<input type='hidden' name='nav_id$i' value='$nav_id' />";
     	}
     	echo '<input type="submit" name="Submit" value="提交" />';
    	echo '</form>';
     
}

//更新栏目管理
if ($action == 'uplanmu') 
{
	//去除空格
	$posts = $_POST;
	foreach ($posts as $key=>$values)
	{
		$posts[$key] = trim($values);
	}
	
	//获得表单内容，放入一个数组中。
	$nav_kz[] = $_POST['nav_kz1'];
	$nav_kz[] = $_POST['nav_kz2'];
	$nav_kz[] = $_POST['nav_kz3'];
	$nav_kz[] = $_POST['nav_kz4'];
	$nav_kz[] = $_POST['nav_kz5'];
	$nav_kz[] = $_POST['nav_kz6'];
	$nav_kz[] = $_POST['nav_kz7'];
	$nav_kz[] = $_POST['nav_kz8'];
	
	$nav[] = $_POST['nav_id1'];
	$nav[] = $_POST['nav_id2'];
	$nav[] = $_POST['nav_id3'];
	$nav[] = $_POST['nav_id4'];
	$nav[] = $_POST['nav_id5'];
	$nav[] = $_POST['nav_id6'];
	$nav[] = $_POST['nav_id7'];
	$nav[] = $_POST['nav_id8'];
	
	//判断长度是否合法
	if (strlen($nav_kz[0])>1 || strlen($nav_kz[1])>1 || strlen($nav_kz[2])>1 || strlen($nav_kz[3])>1 || 
		strlen($nav_kz[4])>1 || strlen($nav_kz[5])>1 || strlen($nav_kz[6])>1 || strlen($nav_kz[7])>1 ) 
	{
	     echo '请使用0或1--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
	     exit;
	}

	if (true) 
	{
		for ($i=1;$i<9;$i++)
		{
			// 更新数据库内容 update_nav()函数在rootfun.php定义
			update_nav($nav_kz[$i],$nav[$i]);
		}
		echo '更新成功--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
	}
	else 
	{
		echo '更新失败--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
	}
}

//如果添加基本设置将执行以下内容
if ($action == 'in') 
{
	//判断表单填写是否完整
     if (!filled_out($_POST)) 
     {
          echo '请完整填写表单--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
          exit;
     }
     
     //获取表单变量同时对变量进行格式化，使其能够存入数据库my_yz()函数在myapi/myfun.php中定义
     //其实该函数就是封装了一些常用的字符串格式化的函数。这样使用方便。
     $title = my_yz($_POST['title']);
     $cop = my_yz($_POST['cop']);
     $qq = my_yz($_POST['qq']);
     $icp = my_yz($_POST['icp']);
     $icpurl = my_yz($_POST['icpurl']);
     $mail = my_yz($_POST['mail']);
     $keywords = my_yz($_POST['keywords']);
     $description = my_yz($_POST['description']);
     $yb = my_yz($_POST['yb']);
     $tel = my_yz($_POST['tel']);
     $cstel = my_yz($_POST['cstel']);
     $dz = my_yz($_POST['dz']);
     $news = my_yz($_POST['news']);
     $chanpin = my_yz($_POST['chanpin']);
     $lyb = my_yz($_POST['lyb']);
     $fc = my_yz($_POST['fc']);
     $job = my_yz($_POST['job']);
     $ry = my_yz($_POST['ry']);
     
     //对一些字符串进行长度判断
     if (strlen($qq)>15 || strlen($tel)>15 || strlen($news)>5 || strlen($chanpin)>5 || 
     	strlen($lyb)>5 || strlen($fc)>5 || strlen($yb) > 6 || strlen($ry) > 5) 
     {
          echo '字符串请勿超出长度--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
          exit;
     }
     
     if (!is_numeric($qq) || !is_numeric($yb) || !is_numeric($news) || !is_numeric($chanpin) ||
     		!is_numeric($lyb) || !is_numeric($fc) || !is_numeric($job) || !is_numeric($ry)) 
     {
          echo '请按要求填写表单--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
          exit;
     }
     // insert_shezhi()函数在rootfun.php中定义
     if (insert_shezhi($tel,$cstel,$title,$keywords,$description,$cop,$qq,$mail,
						$icp,$icpurl,$news,$chanpin,$lyb,$fc,$job,$yb,$dz,$ry)) 
     {
          echo '添加成功--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
     }
     else 
     {
     	 echo '添加失败--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
     }
}

//折叠管理
if ($action == 'index') 
{
	//index()函数在rootfun.php定义
	$index = index();
	danye($index);
}

//添加折叠管理
if ($action == 'iin') 
{
	//验证表单填写是否完整
    if (!filled_out($_POST)) 
    {
         echo '请完整填写表单--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
         exit;
    }
	
	//获取表单变量,并格式化字符串
	$jingli = my_yz($_POST['jingli']);
	$wenhua = my_yz($_POST['wenhua']);
	$mubiao = my_yz($_POST['mubiao']);
	if (strlen($jingli)>160 || strlen($wenhua)>160 || strlen($mubiao)>160) 
	{
	     echo '请将字符限定在80字以内--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
	     exit;
	}
	if (insert_index($jingli,$wenhua,$mubiao)) 
	{
	     echo '添加成功--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
	}
	else 
	{
		echo '添加失败--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
	}
}

//更新折叠管理
if ($action == 'iup') 
{
     //验证表单填写是否完整
    if (!filled_out($_POST)) 
    {
         echo '请完整填写表单--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
         exit;
    }
	
	//获取表单变量,并格式化字符串
	$jingli = my_yz($_POST['jingli']);
	$wenhua = my_yz($_POST['wenhua']);
	$mubiao = my_yz($_POST['mubiao']);
	
	if (strlen($jingli)>160 || strlen($wenhua)>160 || strlen($mubiao)>160) 
	{
	     echo '请将字符限定在80字以内--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
	     exit;
	}
	
	if (update_index($jingli,$wenhua,$mubiao)) 
	{
	     echo '更新成功--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
	}
	else 
	{
		echo '更新失败--<a href='.$_SERVER['HTTP_REFERER'].'>返 回</a>';
	}
}
?></div> 
<!-- rootmain-end -->
<?php
//插入页脚
rootfooter();
?>
