<?php
/**
 * hao123导航站
*/

/****以下代码非专业人员不建议修改***************/
define('EmpireCMSAdmin','1');
define('EmpireCMSAPage','login');

require("../class/connect.php");
require("../class/db_sql.php");
require("../class/functions.php");
require LoadLang("pub/fun.php");
require("../class/delpath.php");
require("../class/copypath.php");
require("../class/t_functions.php");
require("../data/dbcache/class.php");
require("../data/dbcache/MemberLevel.php");

/*
$_POST[title]='tt';
$_POST[cjid]='11';
$_POST[cjsource]='tt';
$_POST[playurl]='playurl';
$_POST[volumeid]='22';
$_POST[volumename]='volumename';
$_POST[enews]='AddNews';
$_POST[username]='admin';
$_POST[classid]='7';
*/
if(empty($_POST))
{
	//这里刷新列表
	echo "<select name='list'>";
	echo maketree($cates,0,'');
	echo '</select>';
	exit();
}
$link=db_connect();
$empire=new mysqlquery();

/**
 * 检查验证码
*/

ecmsCheckShowKey('checkplkey',$_POST['key'],1);

$incftp=0;
if($public_r['phpmode'])
{
	include("../class/ftp.php");
	$incftp=1;
}
require("../class/hinfofun.php");
$navtheid=(int)$_POST['filepass'];

//=====================================判断标题重复
$title=$_POST['title'];

$tr=$empire->fetch1("select id from {$dbtbpre}ecms_links where `title`='$title'");

//if($tr) 
if($tr)
{
    printerror("Duplicate","history.go(-1)",1);
}
else
{
	$sqlflag   =   $empire->query(" INSERT INTO {$dbtbpre}ecms_links_check (title,titleurl,smalltext,pv,createTime,user,phone,qq,isLinked,newstime,classid,isurl,newspath) VALUES ('{$_POST['title']}','{$_POST['titleurl']}','{$_POST['smalltext']}','{$_POST['pv']}','{$_POST['createTime']}','{$_POST['user']}','{$_POST['phone']}','{$_POST['qq']}','{$_POST['isLinked']}','".time()."','22','1','".date("Y-m-d",time())."') ");
	$id    =   $empire->lastid();
    $sqlflag   =  $sqlflag&&$empire->query(" INSERT INTO {$dbtbpre}ecms_links_index (id,classid,checked) VALUES ('{$id}','22','0') ");
    $sqlflag   =  $sqlflag&&$empire->query(" INSERT INTO {$dbtbpre}ecms_links_check_data (id,classid) VALUES ('{$id}','22') ");
    $sqlflag   =  $sqlflag&&$empire->query(" UPDATE {$dbtbpre}enewsclass SET allinfos = allinfos + 1 WHERE classid = '22' ");
    $sqlflag   =  $sqlflag&&$empire->query(" UPDATE {$dbtbpre}ecms_links_check SET filename  = '{$id}' WHERE id = '{$id}' ");
    if( $sqlflag ){
        printerror("AddQinfoSuccess","/",1);
    }
}
db_close();
$empire=null;

/***生成目录的一个遍历算法***/
function maketree($ar,$id,$pre)
{
	$ids='';
	foreach($ar as $k=>$v){
		$pid=$v['pid'];
		$cname=$v['cname'];
		$cid=$v['cid'];
		if($pid==$id)
		{
			$ids.="<option value='$cid'>{$pre}{$cname}</option>";
			foreach($ar as $kk=>$vv)
			{
				$pp=$vv['pid'];
				if($pp==$cid)
				{ 
					$ids.=maketree($ar,$cid,$pre);
					break;
				}
			}
		}
	}
	return $ids;
}
?>