<?php
 /*
 * 74cms 企业用户相关
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once(dirname(__FILE__).'/../data/config.php');
require_once(dirname(__FILE__).'/include/admin_common.inc.php');
require_once(ADMIN_ROOT_PATH.'include/admin_list_fun.php');
require_once(ADMIN_ROOT_PATH.'include/upload.php');
$act = !empty($_GET['act']) ? trim($_GET['act']) : 'list';
if($act == 'list')
{
	check_permissions($_SESSION['admin_purview'],"list_show");
	$_GET['audit']<>""? $wheresqlarr['l.audit']=intval($_GET['audit']):'';
	$_GET['mobile']<>""? $wheresqlarr['l.mobile']=intval($_GET['mobile']):'';
	$_GET['email']<>""? $wheresqlarr['l.email']=intval($_GET['email']):'';
	$_GET['utype']<>""? $wheresqlarr['l.utype']=intval($_GET['utype']):'';
	if (is_array($wheresqlarr)) $wheresql=wheresql($wheresqlarr);
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$orderbysql=" order BY l.id DESC ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('list')." AS l".$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$list = get_list($offset,$perpage,$wheresql.$orderbysql);
	$smarty->assign('pageheader',"list列表");
	$smarty->assign('list',$list);
	$smarty->assign('page',$page->show(3));
	$smarty->display('list/admin_list.htm');
}
elseif($act == 'list_perform')
{
	check_token();
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:adminmsg("你没有选择list通讯录！",1);
	if (!empty($_REQUEST['delete']))
	{
		check_permissions($_SESSION['admin_purview'],"del_list");
		$num=del_list($yid);
		if ($num>0)
		{
		adminmsg("删除成功！共删除".$num."行",2);
		}
		else
		{
		adminmsg("删除失败！",0);
		}
	}
	elseif (!empty($_POST['set_audit']))
	{
		check_permissions($_SESSION['admin_purview'],"audit_list");
		$audit=intval($_POST['audit']);
		if ($n=edit_list_audit($yid,$audit))
		{
		adminmsg("审核成功！响应行数 {$n}",2);			
		}
		else
		{
		adminmsg("审核成功！响应行数 0",1);
		}
	}
}
elseif($act == 'edit_list')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"edit_list");
	$id =!empty($_REQUEST['id'])?intval($_REQUEST['id']):adminmsg("你没有list通讯录！",1);
	$smarty->assign('pageheader',"list管理");
	$list=get_list_one($id);
	$smarty->assign('url',$_SERVER["HTTP_REFERER"]);
	$smarty->assign('list',$list);
	$smarty->display('list/admin_list_edit.htm');
}
elseif ($act=='editlist_save')
{
	global $_CFG;
	check_token();
	check_permissions($_SESSION['admin_purview'],"edit_list");
	$id=intval($_POST['id']);
	$setsqlarr['title']=!empty($_POST['title'])?trim($_POST['title']):adminmsg('您没有填写通讯录标题！',1);
	$setsqlarr['trade']=!empty($_POST['trade'])?trim($_POST['trade']):adminmsg('您没有选择行业！',1);
	$setsqlarr['trade_cn']=trim($_POST['trade_cn']);
	$setsqlarr['audit']=intval($_POST['audit']);
	$setsqlarr['mobile']=!empty($_POST['mobile'])?trim($_POST['mobile']):adminmsg('您没有选择手机情况！',1);
	$setsqlarr['mobile_cn']=trim($_POST['mobile_cn']);
	$setsqlarr['email']=!empty($_POST['email'])?trim($_POST['email']):adminmsg('您没有选择邮箱情况！',1);
	$setsqlarr['email_cn']=trim($_POST['email_cn']);
	$setsqlarr['list_time']=!empty($_POST['list_time'])?strtotime(trim($_POST['list_time']).'-01-01'):adminmsg('您没有选择年份！',1);
	$setsqlarr['price']=!empty($_POST['price'])?trim($_POST['price']):adminmsg('您没有填写下载定价！',1);
	$setsqlarr['contents']=trim($_POST['contents']);
	//更新文件
	if (!empty($_FILES['file']['name']))
	{
		if(intval($_FILES['file']['size']) > (intval($_CFG['upload_list_file_size_max'])*1024))
		{
			adminmsg('文件大小超过设置上限！',1);
		}
		else
		{
			$setsqlarr['file_size']=intval($_FILES['file']['size']);
		}
		require_once(ADMIN_ROOT_PATH.'include/upload.php');
		$entrust_updir="../data/list/";
		$entrust_dir="data/list/";
		$entrust_updir=$entrust_updir.date("Y/m/");
		make_dir($entrust_updir);
		$setsqlarr['file']=_asUpFiles($entrust_updir,"file",$_CFG['upload_list_file_size_max'],'docx/doc/zip/xls',true);
		if (empty($setsqlarr['file']))
		{
			adminmsg('更新文件失败！',1);
		}
		//$setsqlarr['file']=$entrust_dir.date("Y/m/").$setsqlarr['file'];
		$setsqlarr['file']=date("Y/m/").$setsqlarr['file'];
		//将旧文件删掉
		$list_info = $db->getone("select  * from ".table('list')." where id =".$id." limit 1");
		$path = QISHI_ROOT_PATH."data/list/".$list_info['file'];
		if(!unlink($path))
		{
			adminmsg('删除文件失败！',1);
		}
	}
	if (!updatetable(table('list'),$setsqlarr," id = ".$id)) adminmsg("保存失败！",0);
	$link[0]['text'] = "返回list列表";
	$link[0]['href'] = $_POST['url'];
	adminmsg("修改成功！",2,$link);

}
//查看明细
elseif($act == 'check_detail')
{
	$id =!empty($_GET['id'])?intval($_GET['id']):adminmsg("id丢失！",1);
	$list_info=get_list_one($id);
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$orderbysql=" order BY l.id DESC ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('list')." AS l".$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$down_info=get_down_info($offset,$perpage,$id);
	$smarty->assign('pageheader',"下载明细");
	$smarty->assign('url',$_SERVER["HTTP_REFERER"]);
	$smarty->assign('down_info',$down_info);
	$smarty->assign('list_info',$list_info);
	$smarty->assign('page',$page->show(3));
	$smarty->display('list/admin_list_down_detail.htm');
}
elseif($act == 'management')
{	
	$id=intval($_GET['id']);
	$u=get_user($id);
	if (!empty($u))
	{
		unset($_SESSION['uid']);
		unset($_SESSION['parentuid']);
		unset($_SESSION['username']);
		unset($_SESSION['utype']);
		unset($_SESSION['uqqid']);
		setcookie("QS[uid]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
		setcookie("QS[parentuid]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
		setcookie("QS[username]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
		setcookie("QS[password]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
		setcookie("QS[utype]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
		unset($_SESSION['activate_username']);
		unset($_SESSION['activate_email']);
		
		$_SESSION['uid']=$u['uid'];
		$_SESSION['parentuid']=$u['parentuid'];
		$_SESSION['username']=$u['username'];
		$_SESSION['utype']=$u['utype'];
		$_SESSION['uqqid']="1";
		setcookie('QS[uid]',$u['uid'],0,$QS_cookiepath,$QS_cookiedomain);
		setcookie('QS[parentuid]',$u['parentuid'],0,$QS_cookiepath,$QS_cookiedomain);
		setcookie('QS[username]',$u['username'],0,$QS_cookiepath,$QS_cookiedomain);
		setcookie('QS[password]',$u['password'],0,$QS_cookiepath,$QS_cookiedomain);
		setcookie('QS[utype]',$u['utype'], 0,$QS_cookiepath,$QS_cookiedomain);
		header("Location:".get_member_url($u['utype']));
	}	
} 

?>