<?php
!defined("MONKEYMAO") && die("Accessed Defined!");
@include lang('themes','themes/admin');
if(cpchecksubmit('updatelist')){
	if(is_array($linksitenew)){
		foreach($linksitenew AS $key => $value) {
			$ordermodenew[$key] = $ordermodenew[$key] ? $ordermodenew[$key] : 0;
			$db -> query("UPDATE {$tablepre}links SET linksite='$linksitenew[$key]', linkurl='$linkurlnew[$key]', linknote='$linknotenew[$key]', logo='$logonew[$key]', ordermode ='$ordermodenew[$key]' WHERE  lid='$key'");
		}
	}

	if($newlinksite) {
		$db -> query("INSERT INTO {$tablepre}links (type,linksite, linkurl, linknote, logo, ordermode, postime) VALUES ('1','$newlinksite', '$newlinkurl', '$newlinknote', '$newlogo', '$newordermode', '$time')");
	}
	cpmsg('succeeded','index.php?action=link&menu='.$menu);
}elseif($del){
	$db -> query("DELETE FROM {$tablepre}links WHERE  lid='$del'");
	cpmsg('succeeded','index.php?action=link&menu='.$menu);
}elseif($allow){
	$db -> query("UPDATE {$tablepre}links SET type='1' WHERE  lid='$allow'");
	cpmsg('succeeded','index.php?action=link&menu='.$menu);
}else{
	if($menu == 'request') {
		$theme = 'link_request';
		$sql = "WHERE type='0'";
	}else{
		$theme = 'link';
		$sql = "WHERE type='1'";
	}

	$links=array();
	$page = ispage($page) ? $page : 1;
	$pagenum = 20;
	$start_limit = ($page-1) * $pagenum;	
	$pics = array();
	$query = $db -> query("SELECT COUNT(*) FROM {$tablepre}links $sql");
	$lines = $db -> result($query, 0);
	$paging = paging($lines, $pagenum, $page, 'index.php?action=link&menu='.$menu);
	$query = $db -> query("SELECT * FROM {$tablepre}links $sql ORDER BY ordermode LIMIT $start_limit, $pagenum");	
	while($link = $db -> fetch_array($query)){
		$link['postime'] = gmdate("$dateformat $timeformat", $link['postime'] + ($timeoffset * 3600));
		$links[$link['lid']] = $link;
	}

	include theme($theme, 'themes/admin','admin');
}
?>