<?php

/*

	[UCenter Home] (C) 2007-2008 Comsenz Inc.

	$Id: admincp_site.php 8390 2008-08-06 05:50:42Z liguode $

*/



if(!defined('IN_UCHOME') || !defined('IN_ADMINCP')) {

	exit('Access Denied');

}



//权限

if(!$allowmanage=checkperm('manageprofield')) {

	cpmessage('no_authority_management_operation');

}

$page = empty($_GET['page'])?1:intval($_GET['page']);

if ( isset( $_GET['action'] ) && $_GET['action'] == 'edit' )

{

	if(submitcheck('sitesubmit')) 

	{

		include_once(S_ROOT.'./source/adminupload.php');

		$iconmsg		=	shtmlspecialchars(trim($_POST['icon']));

		if ( isset( $_FILES['ficon']['name'] ) && $_FILES['ficon']['name'] != '' ){

			$FILE 		= 	$_FILES['ficon'];

			$iconmsg 	= 	custom_upload($FILE);

		}

		$setarr = array(

			'title' => shtmlspecialchars(trim($_POST['title'])),

			'url' => shtmlspecialchars(trim($_POST['url'])),

			'icon' => $iconmsg,

			'color' => shtmlspecialchars(trim($_POST['color'])),

			'titlecolor' => shtmlspecialchars(trim($_POST['titlecolor'])),

			'hot' => intval(trim($_POST['hot'])),

			'type' => shtmlspecialchars(trim($_POST['type'])),

			'visible' => intval(trim($_POST['visible']))

		);

		updatetable('site', $setarr, array('id'=>intval($_GET['id'])));

		cpmessage('do_success', "admincp.php?ac=site&page=$page");

	}

	else

	{

		$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site')." WHERE id=".intval($_GET['id']));

		while ($value = $_SGLOBAL['db']->fetch_array($query)) {

			$list[] = $value;

		}

	}

}

else

{

	if(submitcheck('deletesubmit')) {

		if($_POST['ids']){

			$_SGLOBAL['db']->query("DELETE FROM ".tname('site')." WHERE id IN (".implode(',',$_POST['ids']).")");

			cpmessage('do_success', "admincp.php?ac=site&page=$page");

		}

	}



	$mpurl = 'admincp.php?ac=site';



	//处理搜索

	$intkeys = array('uid');

	$strkeys = array('title');

	$randkeys = array();

	$likekeys = array('title');

	$results = getwheres($intkeys, $strkeys, $randkeys, $likekeys);

	$wherearr = $results['wherearr'];

	$wheresql = empty($wherearr)?'1':implode(' AND ', $wherearr);

	$mpurl .= '&'.implode('&', $results['urls']);



	$perpage = empty($_GET['perpage'])?0:intval($_GET['perpage']);

	if(!in_array($perpage, array(20,50,100,1000))) $perpage = 20;



	

	if($page<1) $page = 1;

	$start = ($page-1)*$perpage;

	//检查开始数

	ckstart($start, $perpage);

	if($perpage > 100) {

		$count = 1;

		$selectsql = 'id';

	} else {

		$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('site')." WHERE $wheresql"), 0);

		$selectsql = '*';

	}

	$mpurl .= '&perpage='.$perpage;

	$perpages = array($perpage => ' selected');



	$list = array();

	$multi = '';



	if($count) {

		$query = $_SGLOBAL['db']->query("SELECT $selectsql FROM ".tname('site')." WHERE $wheresql LIMIT $start,$perpage");

		while ($value = $_SGLOBAL['db']->fetch_array($query)) {

			$list[] = $value;

		}

		$multi = multi($count, $perpage, $page, $mpurl);

	}



	if($perpage > 100) {

		$count = count($list);

	}

}



?>