<?php
/**
 * 金戈企业建站系统：后台管理相关的函数定义文件
 *
 *
 * @name 
 * @author 烟鬼 QQ:460874 Email:460874@qq.com
 * @version 0.1  $id  rootfun.php
 * @copyright Copyright (c) 2007 - 2008 烟鬼
 */

//更新基本设置函数
function update_shezhi($title,$cop,$qq,$icp,$icpurl,$mail,$keywords,$description,$yb,$tel,$cstel,
     					$dz,$news,$chanpin,$lyb,$fc,$job,$ry)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE web SET 
							w_tel='$tel',
							w_cstel='$cstel',
							w_title= '$title',
							w_keywords= '$keywords',
							w_description= '$description',
							w_cop= '$cop',
							w_qq= '$qq',
							w_mail= '$mail',
							w_icp= '$icp',
							w_icpurl= '$icpurl',
							w_news= '$news',
							w_chanpin= '$chanpin',
							w_lyb= '$lyb',
							w_job='$job',
							w_fc= '$fc',
							w_yb= '$yb',
							w_dz= '$dz',
							w_ry= '$ry'");
	if (!$result)
     return false;
   else
     return true;
}

//添加基本设置函数
function insert_shezhi($tel,$cstel,$title,$keywords,$description,$cop,$qq,$mail,
						$icp,$icpurl,$news,$chanpin,$lyb,$fc,$job,$yb,$dz,$ry)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("INSERT INTO web VALUES 
							(NULL,'$tel','$cstel','$title','$keywords','$description','$cop',
							'$qq','$mail','$icp','$icpurl','$news','$chanpin','$lyb','$fc','$job',
							'$yb','$dz','$ry')");
	if (!$result)
     return false;
   else
     return true;
}

//更新栏目管理函数
function update_nav($a,$id)
{
	$conn = db_connect();
	$result = $conn->query("UPDATE nav SET nav_kz='$a' where nav_id='$id'");
	if (!$result)
     return false;
   else
     return true;
}

//首页管理
function index()
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT * FROM danye where d_id = 1');
	if(!$result || $result->num_rows < 0)
		return false;
	$results = $result->fetch_assoc();
		return $results;
}

//添加折叠管理内容
function insert_index($jingli,$wenhua,$mubiao)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("INSERT INTO danye VALUES (NULL,'$jingli','$wenhua','$mubiao')");
	if (!$result) 
	     return false;
	else 
		return true;
}

//更新首页管理内容
function update_index($jingli,$wenhua,$mubiao)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE danye SET d_jingli='$jingli',d_wenhua='$wenhua',
							d_mubiao='$mubiao'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//编辑新闻分类
function upncl($cid)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT * FROM new_class where n_c_id = '.$cid);
	if(!$result || $result->num_rows < 0)
		return false;
	$results = $result->fetch_assoc();
		return $results;
}

//更新新闻分类
function upncup($id,$name)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE new_class SET n_c_name='$name' where n_c_id='$id'");
	if (!$result)
     return false;
   else
     return true;
}

//取回所有的新闻，并做分页处理等一系列处理
function senews()
{
	$page=isset($_GET['page'])?intval($_GET['page']):1;
	//每页显示多少条
	$num = 20; 
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT n_n_id FROM new_news');
	$total=$result->num_rows; 
	$pagenum=ceil($total/$num);
	if ($page > $pagenum || $page == 0) 
	{
		echo '没有新闻...';
		exit;
	}
	$offset=($page-1)*$num;
	$result = $conn->query('SELECT new_news.n_n_id,new_news.n_n_title,
							new_class.n_c_name FROM new_news LEFT JOIN new_class
							ON new_news.n_n_cid = new_class.n_c_id
							order by new_news.n_n_id desc
							limit '.$offset.','.$num);
	if (!$result || $result->num_rows < 0) 
	{
		echo '没有新闻..';
	 	exit;
	}
	else 
		$result = setarray($result);
	echo '<form id="form1" name="form1" method="post" action="rootnews.php?action=delnews">';
          foreach ($result as $row)
          {
          	echo '['.$row['n_c_name'].']-'.$row['n_n_title'].
          		'    <a href=rootnews.php?action=endnews&nid='.$row['n_n_id'].'>  编辑</a>'.
          		'<input type=checkbox name="del_me[]"value='.$row['n_n_id'].'>'.
          		'<br />';
          }
	echo '<br />';
	echo '<input type="submit" name="Submit" value="删除选择新闻" />';
	echo '</form>';
	
	echo '共'.$pagenum.'页';
    for($i=1;$i<=$pagenum;$i++)
	{
    $show=($i!=$page)?"<a href='rootnews.php?action=rootnews&page=".$i."'>$i</a>":"<b>$i</b>";
    echo '['.$show.']';
    }
}
//通过指定的ID删除新闻的函数
function delnews($nid)
{
	$conn = db_connect();
	$result = $conn->query("DELETE FROM new_news WHERE n_n_id = '$nid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//更新新闻
function upnews($title,$cop,$cid,$wztxt,$nid)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE new_news SET n_n_title='$title',n_n_newly='$cop',
							n_n_cid='$cid',n_n_news='$wztxt' WHERE n_n_id='$nid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//添加新闻
function innews($cid,$title,$time,$cop,$wztxt)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("INSERT INTO new_news VALUES (NULL,'$cid','$title','$time',
														'$cop','$wztxt')");
	if (!$result) 
	     return false;
	else 
		return true;
}

//添加企业简介
function inqyjj($infile,$qyjj)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("INSERT INTO qyjj VALUES (NULL,'$infile','$qyjj')");
	if (!$result) 
	     return false;
	else 
		return true;
}

//更新企业简介(如果有图片)
function upqyjj($upfile,$qyjj,$nid)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE qyjj SET jj_img='$upfile',jj_nr='$qyjj' WHERE jj_id='$nid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//更新企业简介(只修改了文字内容)
function upqyjj_nr($qyjj,$nid)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE qyjj SET jj_nr='$qyjj' WHERE jj_id='$nid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//取回所有企业荣誉，并做一系列处理等
function seqyry()
{
	$page=isset($_GET['page'])?intval($_GET['page']):1;
	//每页显示多少条
	$num = 20; 
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT ry_id FROM qyry');
	$total=$result->num_rows; 
	$pagenum=ceil($total/$num);
	if ($page > $pagenum || $page == 0) 
	{
		echo '没有内容...';
		exit;
	}
	$offset=($page-1)*$num;
	$result = $conn->query('SELECT * FROM qyry ORDER BY ry_id DESC limit '.$offset.','.$num);
	if (!$result || $result->num_rows < 0) 
	{
		echo '没有内容...';
	 	exit;
	}
	else 
		$result = setarray($result);
	echo '<form id="form1" name="form1" method="post" action="rootry.php?action=delry">';
          foreach ($result as $row)
          {
          	echo $row['ry_title'].
          		'    <a href=rootry.php?action=endry&ryid='.$row['ry_id'].'>  编辑</a>'.
          		'<input type=checkbox name="del_me[]"value='.$row['ry_id'].'>'.
          		'<input type="hidden" name="img[]" value="'.$row['ry_img'].'" />'.
          		'<br />';
          }
	echo '<br />';
	echo '<input type="submit" name="Submit" value="删除选择新闻" />';
	echo '</form>';
	
	echo '共'.$pagenum.'页';
    for($i=1;$i<=$pagenum;$i++)
	{
    $show=($i!=$page)?"<a href='rootry.php?action=qyry&page=".$i."'>$i</a>":"<b>$i</b>";
    echo '['.$show.']';
    }
}

//删除企业荣誉
function delqyry($ryid)
{
	$conn = db_connect();
	$result = $conn->query("DELETE FROM qyry WHERE ry_id = '$ryid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//更新企业荣誉(如果有图片)
function upqyry($upfile,$qyry,$title,$ryid)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE qyry SET ry_img='$upfile',ry_title='$title',ry_js='$qyry' WHERE ry_id='$ryid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//更新企业荣誉(只修改了文字内容)
function upqyry_nr($qyry,$title,$ryid)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE qyry SET ry_title='$title',ry_js='$qyry' WHERE ry_id='$ryid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//添加企业荣誉
function inqyry($upfile,$title,$js)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("INSERT INTO qyry VALUES(NULL,'$upfile','$title','$js')");
	if (!$result) 
	     return false;
	else 
		return true;
}

//取回所有企业风采，并做一系列处理等
function seqyfc()
{
	$page=isset($_GET['page'])?intval($_GET['page']):1;
	//每页显示多少条
	$num = 20; 
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT fc_id FROM qyfc');
	$total=$result->num_rows; 
	$pagenum=ceil($total/$num);
	if ($page > $pagenum || $page == 0) 
	{
		echo '没有内容...';
		exit;
	}
	$offset=($page-1)*$num;
	$result = $conn->query('SELECT * FROM qyfc ORDER BY fc_id DESC limit '.$offset.','.$num);
	if (!$result || $result->num_rows < 0) 
	{
		echo '没有内容...';
	 	exit;
	}
	else 
		$result = setarray($result);
	echo '<form id="form1" name="form1" method="post" action="rootfc.php?action=delfc">';
          foreach ($result as $row)
          {
          	echo $row['fc_title'].
          		'    <a href=rootfc.php?action=endfc&fcid='.$row['fc_id'].'>  编辑</a>'.
          		'<input type=checkbox name="del_me[]"value='.$row['fc_id'].'>'.
          		'<input type="hidden" name="img[]" value="'.$row['fc_img'].'" />'.
          		'<br />';
          }
	echo '<br />';
	echo '<input type="submit" name="Submit" value="删除选择新闻" />';
	echo '</form>';
	
	echo '共'.$pagenum.'页';
    for($i=1;$i<=$pagenum;$i++)
	{
    $show=($i!=$page)?"<a href='rootfc.php?action=qyfc&page=".$i."'>$i</a>":"<b>$i</b>";
    echo '['.$show.']';
    }
}

//删除企业荣誉
function delqyfc($fcid)
{
	$conn = db_connect();
	$result = $conn->query("DELETE FROM qyfc WHERE fc_id = '$fcid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//更新企业风采(如果有图片)
function upqyfc($upfile,$sm,$title,$fcid)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE qyfc SET fc_img='$upfile',fc_title='$title',fc_sm='$sm' WHERE fc_id='$fcid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//更新企业风采(只修改了文字内容)
function upqyfc_nr($title,$sm,$fcid)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE qyfc SET fc_title='$title',fc_sm='$sm' WHERE fc_id='$fcid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//添加企业荣誉
function inqyfc($upfile,$title,$sm)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("INSERT INTO qyfc VALUES(NULL,'$upfile','$title','$sm')");
	if (!$result) 
	     return false;
	else 
		return true;
}

//编辑产品分类
function endcpclass($cid)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT * FROM cp_class where cp_c_id = '.$cid);
	if(!$result || $result->num_rows < 0)
		return false;
	$results = $result->fetch_assoc();
		return $results;
}

//更新产品分类
function upcpclass($cid,$cname)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE cp_class SET cp_c_name='$cname' WHERE cp_c_id='$cid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//添加产品分类
function incpclass($cname)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("INSERT INTO cp_class VALUES (NULL,'$cname')");
	if (!$result) 
	     return false;
	else 
		return true;
}

//取回所有产品，并做一系列处理等
function sechanpin()
{
	$page=isset($_GET['page'])?intval($_GET['page']):1;
	//每页显示多少条
	$num = 20; 
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT cp_id FROM cp_cp');
	$total=$result->num_rows; 
	$pagenum=ceil($total/$num);
	if ($page > $pagenum || $page == 0) 
	{
		echo '没有产品...';
		exit;
	}
	$offset=($page-1)*$num;
	$result = $conn->query('SELECT cp_cp.cp_id,cp_cp.cp_name,cp_class.cp_c_name,cp_cp.cp_kz,cp_cp.cp_img
							FROM cp_cp LEFT JOIN cp_class
							ON cp_cp.cp_c_id = cp_class.cp_c_id
							ORDER BY cp_id DESC 
							LIMIT '.$offset.','.$num);
	if (!$result || $result->num_rows < 0) 
	{
		echo '没有内容...';
	 	exit;
	}
	else 
		$result = setarray($result);
	echo '<form id="form1" name="form1" method="post" action="rootcp.php?action=delcp">';
          foreach ($result as $row)
          {
          	if ($row['cp_kz'] == 1) 
          	{
          	     $tj = '已推荐';
          	}
          	else 
          	{
          		$tj = '未推荐';
          	}
          	echo '['.$tj.']'.'['.$row['cp_c_name'].']--'.$row['cp_name'].
          		'    <a href=rootcp.php?action=endcp&cpid='.$row['cp_id'].'>  编辑</a>'.
          		'<input type=checkbox name="del_me[]"value='.$row['cp_id'].'>'.
          		'<input type="hidden" name="img[]" value="'.$row['cp_img'].'" />'.
          		'<br />';
          }
	echo '<br />';
	echo '<input type="submit" name="Submit" value="删除选择产品" />';
	echo '</form>';
	
	echo '共'.$pagenum.'页';
    for($i=1;$i<=$pagenum;$i++)
	{
    $show=($i!=$page)?"<a href='rootcp.php?action=chanpin&page=".$i."'>$i</a>":"<b>$i</b>";
    echo '['.$show.']';
    }
}

//更新产品信息(包括产品图片)
function upchanpin($upfile,$cpname,$cpxh,$cid,$sm,$cpkz,$cpid)
{
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE cp_cp SET cp_name='$cpname',cp_c_id='$cid',cp_kz='$cpkz',
							cp_xh='$cpxh',cp_img='$upfile',cp_sm='$sm' WHERE cp_id='$cpid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//更新产品信息(不包括产品图片)
function upchanpin_nr($cpname,$cpxh,$cid,$sm,$cpkz,$cpid)
{
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE cp_cp SET cp_name='$cpname',cp_c_id='$cid',cp_kz='$cpkz',
							cp_xh='$cpxh',cp_sm='$sm' WHERE cp_id='$cpid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//通过指定的ID删除产品的函数
function delchanpin($nid)
{
	$conn = db_connect();
	$result = $conn->query("DELETE FROM cp_cp WHERE cp_id = '$nid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//添加产品函数
function inchanpin($cid,$cpkz,$cpname,$cpxh,$sm,$upfile)
{
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query("INSERT INTO cp_cp VALUES (NULL,'$cid','$cpkz','$cpname','$cpxh',
							'$sm','$upfile')");
	if (!$result) 
	     return false;
	else 
		return true;
}

//验证首页推荐产品条书
function indexcprows()
{
	$conn = db_connect();
	$result = $conn->query('SELECT cp_id FROM cp_cp WHERE cp_kz=1');
	if ($result->num_rows > 2) 
	{
	     return false;
	}
	else 
	{
		return true;
	}
}

//取回所有已回复留言，并做一系列处理等
function sehb()
{
	$page=isset($_GET['page'])?intval($_GET['page']):1;
	//每页显示多少条
	$num = 20; 
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT book.l_id
							FROM book,hbook
							WHERE hbook.l_id = book.l_id');
	$total=$result->num_rows; 
	$pagenum=ceil($total/$num);
	if ($page > $pagenum || $page == 0) 
	{
		echo '没有已回复留言...';
		exit;
	}
	$offset=($page-1)*$num;
	$result = $conn->query('SELECT book.l_id,book.l_title
							FROM book ,hbook
							WHERE hbook.l_id = book.l_id
							ORDER BY book.l_id DESC 
							limit '.$offset.','.$num);
	if (!$result || $result->num_rows < 0) 
	{
		echo '没有已回复留言...';
	 	exit;
	}
	else 
		$result = setarray($result);
	echo '<form id="form1" name="form1" method="post" action="rootbook.php?action=delbook">';
          foreach ($result as $row)
          {
          	echo $row['l_title'].
          		'    <a href=rootbook.php?action=sehb&reid='.$row['l_id'].'>  修改回复</a>'.
          		'<input type=checkbox name="del_me[]"value='.$row['l_id'].'>'.
          		'<br />';
          }
	echo '<br />';
	echo '<input type="submit" name="Submit" value="删除选择留言" />';
	echo '</form>';
	
	echo '共'.$pagenum.'页';
    for($i=1;$i<=$pagenum;$i++)
	{
    $show=($i!=$page)?"<a href='rootbook.php?action=hb&page=".$i."'>$i</a>":"<b>$i</b>";
    echo '['.$show.']';
    }
}

//取回所有未回复留言，并做一系列处理等
function sewb()
{
	$page=isset($_GET['page'])?intval($_GET['page']):1;
	//每页显示多少条
	$num = 20; 
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT book.l_id,hbook.hf_nr
							FROM book left join hbook
							using(l_id)
							WHERE hbook.hf_nr is null
							and book.l_ckroot = 1');
	$total=$result->num_rows; 
	$pagenum=ceil($total/$num);
	if ($page > $pagenum || $page == 0) 
	{
		echo '没有未回复留言...';
		exit;
	}
	$offset=($page-1)*$num;
	$result = $conn->query('SELECT book.l_id,book.l_title,hbook.hf_nr 
							FROM book left join hbook
							using(l_id)
							WHERE hbook.hf_nr is null
							and book.l_ckroot = 1
							ORDER BY book.l_id DESC 
							limit '.$offset.','.$num);
	if (!$result || $result->num_rows < 0) 
	{
		echo '没有未回复留言...';
	 	exit;
	}
	else 
		$result = setarray($result);
	echo '<form id="form1" name="form1" method="post" action="rootbook.php?action=delbook">';
          foreach ($result as $row)
          {
          	echo $row['l_title'].
          		'    <a href=rootbook.php?action=sewb&lid='.$row['l_id'].'>  回复</a>'.
          		'<input type=checkbox name="del_me[]"value='.$row['l_id'].'>'.
          		'<br />';
          }
	echo '<br />';
	echo '<input type="submit" name="Submit" value="删除选择留言" />';
	echo '</form>';
	
	echo '共'.$pagenum.'页';
    for($i=1;$i<=$pagenum;$i++)
	{
    $show=($i!=$page)?"<a href='rootbook.php?action=wb&page=".$i."'>$i</a>":"<b>$i</b>";
    echo '['.$show.']';
    }
}

//取回所有管理员可见的留言，并做一系列处理等
function semst()
{
	$page=isset($_GET['page'])?intval($_GET['page']):1;
	//每页显示多少条
	$num = 20; 
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT book.l_id
							FROM book
							WHERE book.l_ckroot != 1');
	$total=$result->num_rows; 
	$pagenum=ceil($total/$num);
	if ($page > $pagenum || $page == 0) 
	{
		echo '没有给管理员的留言...';
		exit;
	}
	$offset=($page-1)*$num;
	$result = $conn->query('SELECT *
							FROM book
							WHERE book.l_ckroot != 1
							ORDER BY book.l_id DESC 
							limit '.$offset.','.$num);
	if (!$result || $result->num_rows < 0) 
	{
		echo '没有给管理员的留言...';
	 	exit;
	}
	else 
		$result = setarray($result);
	echo '<form id="form1" name="form1" method="post" action="rootbook.php?action=delbook">';
          foreach ($result as $row)
          {
			mstbook($row['l_title'],$row['l_time'],$row['l_name'],$row['l_ip'],$row['l_mail'],
					$row['l_lynr'],$row['l_id']);
          }
	echo '<br />';
	echo '<input type="submit" name="Submit" value="删除选择留言" />';
	echo '</form>';
	
	echo '共'.$pagenum.'页';
    for($i=1;$i<=$pagenum;$i++)
	{
    $show=($i!=$page)?"<a href='rootbook.php?action=mst&page=".$i."'>$i</a>":"<b>$i</b>";
    echo '['.$show.']';
    }
}

//通过指定的ID删除留言的函数
function delbook($nid)
{
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query("DELETE FROM book WHERE l_id = '$nid'");
	$results = $conn->query('SELECT * FROM hbook WHERE l_id = '.$nid);
	if ($results->num_rows > 0) 
	{
	     $row = setassoc($results);
	     $reid = $row['hf_id'];
	     $result = $conn->query("DELETE FROM hbook WHERE hf_id = '$reid'");
	}
	if (!$result) 
	     return false;
	else 
		return true;
}

//取回回复
function hb($lid)
{
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT * FROM hbook WHERE l_id = '.$lid);
	if (!$result) 
	     return false;
	else 
		return $result;
}

//更新回复
function uphf($hfnr,$id)
{
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE hbook SET hf_nr='$hfnr' WHERE hf_id='$id'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//添加回复
function inhf($hfnr,$l_id)
{
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query("INSERT INTO hbook VALUES (NULL,'$l_id','$hfnr')");
	if (!$result) 
	     return false;
	else 
		return true;
}

//取回所有企业招聘信息，并做一系列处理等
function sejob()
{
	$page=isset($_GET['page'])?intval($_GET['page']):1;
	//每页显示多少条
	$num = 20; 
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT j_id FROM job');
	$total=$result->num_rows; 
	$pagenum=ceil($total/$num);
	if ($page > $pagenum || $page == 0) 
	{
		echo '没有招聘信息...';
		exit;
	}
	$offset=($page-1)*$num;
	$result = $conn->query('SELECT * FROM job ORDER BY j_id DESC limit '.$offset.','.$num);
	if (!$result || $result->num_rows < 0) 
	{
		echo '没有招聘信息...';
	 	exit;
	}
	else 
		$result = setarray($result);
	echo '<form id="form1" name="form1" method="post" action="rootzp.php?action=deljob">';
          foreach ($result as $row)
          {
          	echo $row['j_title'].
          		'    <a href=rootzp.php?action=endjob&jid='.$row['j_id'].'>  编辑</a>'.
          		'<input type=checkbox name="del_me[]"value='.$row['j_id'].'>'.
          		'<br />';
          }
	echo '<br />';
	echo '<input type="submit" name="Submit" value="删除选择招聘信息" />';
	echo '</form>';
	
	echo '共'.$pagenum.'页';
    for($i=1;$i<=$pagenum;$i++)
	{
    $show=($i!=$page)?"<a href='rootzp.php?action=rootzp&page=".$i."'>$i</a>":"<b>$i</b>";
    echo '['.$show.']';
    }
}

//取回招聘信息
function endjob($id)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT * FROM job where j_id = '.$id);
	if(!$result || $result->num_rows < 0)
		return false;
	$results = $result->fetch_assoc();
		return $results;
}

//删除指定的招聘信息
function deljob($id)
{
	$conn = db_connect();
	$result = $conn->query("DELETE FROM job WHERE j_id = '$id'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//更新指定的招聘信息
function upjob($title,$xueli,$didian,$gztime,$jobren,$waiyu,$lianxi,$miaosu,$jid)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("UPDATE job SET 
							j_title='$title',
							j_xueli='$xueli',
							j_didian='$didian',
							j_gztime='$gztime',
							j_jobren='$jobren',
							j_waiyu='$waiyu',
							j_lianxi='$lianxi',
							j_miaosu='$miaosu' 
							WHERE j_id='$jid'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//添加招聘信息
function injob($title,$xueli,$didian,$gztime,$jobren,$waiyu,$lianxi,$miaosu)
{
	$conn = db_connect();
	$result = $conn->query("set names 'gb2312'");
	$result = $conn->query("INSERT INTO job VALUES (NULL,'$title','$xueli','$didian','$gztime',
													'$jobren','$waiyu','$lianxi','$miaosu')");
	if (!$result) 
	     return false;
	else 
		return true;
}

//更新管理员密码的函数
function change_rootpass($username, $old_password, $new_password)
{
	// 为了安全利用了root_login函数验证用户是否是真正的管理员
	root_login($username,$old_password);
	$conn = db_connect();
	$result = $conn->query("UPDATE root SET root_pass = sha1('$new_password')
							WHERE root_name = '$username'");
	if (!$result) 
	     return false;
	else 
		return true;
}

//添加管理员函数
function reroot($username,$password)
{
  $conn = db_connect();
  // 检查数据库中是否有相同的用户名 
  $result = $conn->query("SELECT * FROM root WHERE root_name='$username'"); 
  if (!$result)
    throw new Exception('数据库查询失败');
  if ($result->num_rows>0) 
    throw new Exception($username.'已经被存在.');

  // 如果没问题就将注册信息插入数据库
  $result = $conn->query("INSERT INTO root VALUES
                         (NULL,'$username', sha1('$password'))");
  if (!$result)
    throw new Exception('添加失败.');

  return true;
}

//取回所有管理员信息
function root_a()
{
	$conn = db_connect();
	$result=$conn->query("set names 'gb2312'");
	$result = $conn->query('SELECT * FROM root');
	if(!$result || $result->num_rows <= 0)
			return false;
	else 
			return $result;
}

//删除管理员函数
function delroot($id)
{
	$conn = db_connect();
	$result = $conn->query("DELETE FROM root WHERE root_id = '$id'");
	if (!$result) 
	     return false;
	else 
		return true;
}
?>