<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Adposition
{
	function Adposition()
	{
		//$GLOBALS['WebSe'] -> isOnLine();

		//$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/login/actlogin");
	}
	
	function infolist(  )
	{
		$pageSize = 20 ;		$pageNumval 	= $GLOBALS['Reque'] -> reqval["pageNum"];
		
		if( $pageNumval > 1 )
		{
			$pageNum  = $pageNumval;
			$LIMITnum = ceil( ( $pageNumval -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}
		//序号 	广告位置 	宽度 	高度 	说明
		$sqlQuery = " SELECT adp_id, adp_name, adp_width, 	adp_height, adp_desc   FROM  ".SQL_PREFIX."adposition  WHERE 1 GROUP BY adp_id ORDER BY `adp_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."adposition  WHERE 1  ORDER BY `adp_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=adposition&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] );
		

		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('adposition_tpl.html');
		
	}
	
	function add(  )
	{
		$GLOBALS['Templ'] -> caching = true;
		$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24

		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=adposition&act=addinfo");
		$GLOBALS['Templ']->display('adpositionadd_tpl.html');
	}
	
	function addinfo()
	{
		$adp_nameval 		= $GLOBALS['Reque'] -> funpost("adp_name");
		$adp_widthval 		= $GLOBALS['Reque'] -> funpost("adp_width");
		$adp_heightval		= $GLOBALS['Reque'] -> funpost("adp_height");
		$adp_descval 		= $GLOBALS['Reque'] -> funpost("adp_desc");
		$adp_styleval	 	= $GLOBALS['Reque'] -> funpost("adp_style");

		if($adp_nameval !='' and $adp_widthval !='' and $adp_heightval !='' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."adposition  WHERE adp_name = '".$adp_nameval."' ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{				
				$insertip ="INSERT INTO `".SQL_PREFIX."adposition` (`adp_name` , `adp_width` , `adp_height` , `adp_desc` , `adp_style` ) VALUES (  '$adp_nameval', '$adp_widthval', '$adp_heightval', '$adp_descval', '$adp_styleval')";
				
				$GLOBALS['MySql'] -> querySql($insertip);
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_addsusse'] );
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=adposition&act=infolist");
				$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
			}else{
				
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_isrealyerror']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=adposition&act=add");
				$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
			}
			
		}else{
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_losssusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=adposition&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$deletesql ="DELETE FROM `".SQL_PREFIX."adposition` WHERE `adp_id` in ( $infoid ) ";
		$GLOBALS['MySql'] -> querySql($deletesql);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_delsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=adposition&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."adposition  WHERE adp_id = '".$infoid."' ORDER BY `adp_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=adposition&act=editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('adpositionedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
		$adp_idval 		= $GLOBALS['Reque'] -> funpost("adp_id");
		$adp_nameval 	= $GLOBALS['Reque'] -> funpost("adp_name");
		$adp_widthval 	= $GLOBALS['Reque'] -> funpost("adp_width");
		$adp_heightval	= $GLOBALS['Reque'] -> funpost("adp_height");
		$adp_descval 	= $GLOBALS['Reque'] -> funpost("adp_desc");
		$adp_styleval	= $GLOBALS['Reque'] -> funpost("adp_style");
		
		if($adp_idval !='' and $adp_nameval !='' )
		{

			$updatesql = "UPDATE `".SQL_PREFIX."adposition` SET  adp_name = '".$adp_nameval."' , adp_width = '".$adp_widthval."'  , adp_height = '".$adp_heightval."' , adp_desc = '".$adp_descval."' , adp_style = '".$adp_styleval."'   WHERE  adp_id = '".$adp_idval."' ";
			
			$GLOBALS['MySql'] -> querySql( $updatesql );
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=adposition&act=infolist");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');
				
		}else{
		
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_losssusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=adposition&act=info&id=".$admin_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
		
}

//nmon_x86_rhel4


$Adposition = new Adposition();

?>