<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	$action=empty($action)?'manage':trim($action);
	require_once(DIRCMS_ROOT.'include/list.class.php');
	$l=new dircmslist();

	$c=new cache();
	$action=empty($action)?'manage':trim($action);
	switch($action)
	{
		case 'flink':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['link']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if(isset($do_submit)) 
			{
				foreach($id as $val)
				{
					$db->update(DB_PRE.'link',array('orderby'=>$orderby[$val],'name'=>$name[$val],'url'=>$url[$val]),'id='.intval($val));
				}
				$c->cache_link();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=flink');
			}
			$where=1;
			$ispassed=isset($ispassed)?$ispassed:1;
			$where.=" AND `ispassed`=".intval($ispassed);
			$orderby="orderby ASC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'link',$where,$orderby,$page,15);	
			$pages=$l->pages;
			include admin_tlp('other_flink');			
			break;
		case 'flink_add':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['link']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if(isset($do_submit)) 
			{
				if(!$newlink['name'] || !$newlink['url'])showmsg('友链名称和地址不能为空!');
				$newlink['addtime']=TIME;
				$newlink['hits']=0;
				if(is_uploaded_file($_FILES['linklogo']['tmp_name']))
				{
					$filename=md5($newlink['name'].$newlink['url']).'.'.get_fileext($_FILES['linklogo']['name']);
					@move_uploaded_file($_FILES['linklogo']['tmp_name'],DIRCMS_ROOT.'images/logo/'.$filename);
					$newlink['logo']='images/logo/'.$filename;
				}
				else
				{
					$newlink['logo']='';
				}
				$db->insert(DB_PRE."link",$newlink);
				$c->cache_link();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=flink');
			}
			include admin_tlp('other_flink_add');
			break;
		case 'flink_lock':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['link']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if($db->query("UPDATE ".DB_PRE."link SET ".DB_PRE."link.ispassed=".intval($ispassed)." WHERE ".DB_PRE."link.id=".intval($id),true))
			{
				$c->cache_link();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=flink');
			}
			else 
			{
				showmsg($LANG['MANAGE_ERROR'],ADMIN_FILE.'?file=other&action=flink');
			}
			break;
		case 'flink_isindex':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['link']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if($db->query("UPDATE ".DB_PRE."link SET ".DB_PRE."link.isindex=".intval($isindex)." WHERE ".DB_PRE."link.id=".intval($id),true))
			{
				$c->cache_link();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=flink');
			}
			else 
			{
				showmsg($LANG['MANAGE_ERROR'],ADMIN_FILE.'?file=other&action=flink');
			}
			break;
		case 'flink_edit':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['link']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if(isset($do_submit))
			{
				if(!$link['name'] || !$link['url'])showmsg('友链名称和地址不能为空!');
				if(is_uploaded_file($_FILES['linklogo']['tmp_name']))
				{
					$filename=md5($link['name'].$link['url']).'.'.get_fileext($_FILES['linklogo']['name']);
					@move_uploaded_file($_FILES['linklogo']['tmp_name'],DIRCMS_ROOT.'images/logo/'.$filename);
					$link['logo']='images/logo/'.$filename;
				}

				$db->update(DB_PRE."link",$link,'id='.$id);
				$c->cache_link();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=flink');
			}
			$r=$db->fetch_one("SELECT * FROM ".DB_PRE."link WHERE id=$id");
			include admin_tlp('other_flink_edit');
			break;
		case 'flink_delete':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['link']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			$db->mysql_delete(DB_PRE.'link',intval($id));
			$c->cache_link();
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=flink');
			break;
		case 'ads':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['ads']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if(isset($do_submit)) 
			{
				foreach($id as $val)
				{
					$db->update(DB_PRE.'ads',array('fromdate'=>strtotime($fromdate[$val]),'name'=>$name[$val],'todate'=>strtotime($todate[$val])),'id='.intval($val));
				}
				$c->cache_adspos();
				$c->cache_adsfile();
				showmsg('操作成功',ADMIN_FILE.'?file=other&action=ads');
			}
			$where=1;
			$ispassed=isset($ispassed)?$ispassed:1;
			$where.=" AND `ispassed`=".intval($ispassed);
			$orderby="id DESC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'ads',$where,$orderby,$page,15);	
			$pages=$l->pages;
			if($result)foreach($result as $key => $v)
			{
				$r=cache_read("adspos".$v['adsposid'].".cache.php",DIRCMS_ROOT.'data/cache/');
				$result[$key]['adspos']=$r['name'];
			}
			
			include admin_tlp('other_ads');
			break;
		case 'ads_add':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['ads']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if(isset($do_submit)) 
			{
				if(!$info['name'])showmsg('广告名称不能为空!');
				$t=$info['code'];
				$info=array_map('htmlspecialchars',$info);
				$info['code']=$t;
				if($info['type']==1 && is_uploaded_file($_FILES['imageurl']['tmp_name']))
				{
					if(!in_array(get_fileext($_FILES['imageurl']['name']),array('gif','bmp','jpg','jpeg','png')))showmsg('图片格式不正确!应为gif,bmp,jpg,jpeg,png格式。');
					$filename=date('Ymd').mt_rand(1000,9999).'.'.get_fileext($_FILES['imageurl']['name']);
					@move_uploaded_file($_FILES['imageurl']['tmp_name'],DIRCMS_ROOT.'images/ads/'.$filename);
					$info['imageurl']='images/ads/'.$filename;
				}
				else
				{
					$info['imageurl']='';
				}

				if($info['type']==2 && is_uploaded_file($_FILES['flashurl']['tmp_name']))
				{
					if(!in_array(get_fileext($_FILES['flashurl']['name']),array('swf','SWF')))showmsg('Flash格式不正确!应为swf格式。');
					$filename=date('Ymd').mt_rand(1000,9999).'.'.get_fileext($_FILES['flashurl']['name']);
					@move_uploaded_file($_FILES['flashurl']['tmp_name'],DIRCMS_ROOT.'images/ads/'.$filename);
					$info['flashurl']='images/ads/'.$filename;
				}
				else
				{
					$info['flashurl']='';
				}

				if($info['type']==5)
				{
					$info['code']=base64_encode($info['code']);
				}

				$info['fromdate']=$info['addtime']=strtotime($info['addtime']);
				$info['todate']=strtotime($info['todate']);
				$db->insert(DB_PRE."ads",$info);
				$db->query("UPDATE `".DB_PRE."adspos` SET `".DB_PRE."adspos`.`number`=`".DB_PRE."adspos`.`number`+1 WHERE `".DB_PRE."adspos`.`id`=".intval($info['adsposid']),true);
				$c->cache_adspos();
				$c->cache_adsfile();
				showmsg('操作成功',ADMIN_FILE.'?file=other&action=ads');
			}
			$r=cache_read('adspos.cache.php',DIRCMS_ROOT.'data/cache/');
			$adsposid_select='<select name="info[adsposid]">';
			if($r)foreach($r as $__r)
			{
				$isselected=$posid==$__r['id']?' selected="selected"':'';
				$adsposid_select.='<option value="'.$__r['id'].'"'.$isselected.'>'.$__r['name'].'</option>';
			}
			$adsposid_select.='</select>';
			include admin_tlp('other_ads_add');
			break;
		case 'ads_edit':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['ads']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			if(isset($do_submit)) 
			{
				$info=array_map('htmlspecialchars',$info);
				if($info['type']==1 && is_uploaded_file($_FILES['imageurl']['tmp_name']))
				{
					if(!in_array(get_fileext($_FILES['imageurl']['name']),array('gif','bmp','jpg','jpeg','png')))showmsg('图片格式不正确!应为gif,bmp,jpg,jpeg,png格式。');
					$filename=date('Ymd').mt_rand(1000,9999).'.'.get_fileext($_FILES['imageurl']['name']);
					@move_uploaded_file($_FILES['imageurl']['tmp_name'],DIRCMS_ROOT.'images/ads/'.$filename);
					$info['imageurl']='images/ads/'.$filename;
				}
				else
				{
					unset($info['imageurl']);
				}

				if($info['type']==2 && is_uploaded_file($_FILES['flashurl']['tmp_name']))
				{
					if(!in_array(get_fileext($_FILES['flashurl']['name']),array('swf')))showmsg('Flash格式不正确!应为swf格式。');
					$filename=date('Ymd').mt_rand(1000,9999).'.'.get_fileext($_FILES['flashurl']['name']);
					@move_uploaded_file($_FILES['flashurl']['tmp_name'],DIRCMS_ROOT.'images/ads/'.$filename);
					$info['flashurl']='images/ads/'.$filename;
				}
				else
				{
					unset($info['flashurl']);
				}
				$info['addtime']=strtotime($info['addtime']);
				$info['todate']=strtotime($info['todate']);
				$db->update(DB_PRE."ads",$info,'id='.intval($id));
				$c->cache_adspos();
				$c->cache_adsfile();
				showmsg('操作成功',ADMIN_FILE.'?file=other&action=ads');
			}
			$result=$db->fetch_one("SELECT * FROM `".DB_PRE."ads` WHERE `".DB_PRE."ads`.`id`=".intval($id));
			$r=cache_read('adspos.cache.php',DIRCMS_ROOT.'data/cache/');
			$adsposid_select='<select name="info[adsposid]">';
			if($r)foreach($r as $__r)
			{
				$isselected=$result['adsposid']==$__r['id']?' selected="selected"':'';
				$adsposid_select.='<option value="'.$__r['id'].'"'.$isselected.'>'.$__r['name'].'</option>';
			}
			$adsposid_select.='</select>';
			include admin_tlp('other_ads_edit');
			break;
		case 'ads_delete':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['ads']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			$db->mysql_delete(DB_PRE.'ads',intval($id));
			$db->query("UPDATE `".DB_PRE."adspos` SET `".DB_PRE."adspos`.`number`=`".DB_PRE."adspos`.`number`-1 WHERE `".DB_PRE."adspos`.`id`=".intval($adspos),true);
			$c->cache_adspos();
			$c->cache_adsfile();
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=ads');
			break;
		case 'ads_lock':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['ads']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if($db->query("UPDATE ".DB_PRE."ads SET ".DB_PRE."ads.ispassed=".intval($ispassed)." WHERE ".DB_PRE."ads.id=".intval($id),true))
			{
				$c->cache_adspos();
				$c->cache_adsfile();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=ads&ispassed='.intval($ispassed));
			}
			else 
			{
				showmsg($LANG['MANAGE_ERROR']);
			}
			break;
		case 'createhtml':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['ads']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			$DIRCMS['t']='Dircms';
			$r=cache_read("adspos.cache.php",DIRCMS_ROOT.'data/cache/');
			if($r)foreach($r as $_r)
			{
				unset($contents);
				$__r=cache_read("ads_pos".$_r['id'].".cache.php",DIRCMS_ROOT.'data/cache/');
				$___r=cache_read("adspos".$_r['id'].".cache.php",DIRCMS_ROOT.'data/cache/');

				if($___r['option'])
				{
					foreach($__r as $_v)
					{
						if($_v['type']==1)
						{
							$contents[]='<a href="'.$DIRCMS['site_url'].'ads.php?id='.$_v['id'].'" title="'.$_v['alt'].'" target="_blank"><img src="'.$DIRCMS['site_url'].$_v['imageurl'].'" width="'.$___r['width'].'" height="'.$___r['height'].'" alt="'.$_v['alt'].'"/></a>';
						}
						if($_v['type']==2)
						{
							$contents[]='<OBJECT width="'.$___r['width'].'" height="'.$___r['height'].'">
	<PARAM NAME=movie value="'.$DIRCMS['site_url'].$_v['flashurl'].'">
	<PARAM NAME=quality value=high>
	<PARAM NAME=wmode value='.$_v['wmode'].'>
	<EMBED width="'.$___r['width'].'" height="'.$___r['height'].'" src="'.$DIRCMS['site_url'].$_v['flashurl'].'" quality=high wmode=transparent TYPE="application/x-shockwave-flash"></EMBED>
	</OBJECT>';
						}
						if($_v['type']==3)
						{
							$contents[]=$_v['text'];
						}
						if($_v['type']==4)
						{
							$contents[]='<a href="'.$DIRCMS['site_url'].'ads.php?id='.$_v['id'].'" title="'.$_v['code'].'" target="_blank">'.$_v['code'].'</a>';
						}
						if($_v['type']==5)
						{
							$contents[]=stripslashes(stripslashes(base64_decode($_v['code'])));
						}
					}	
				}
				else
				{
					$rand=get_rand_array_value($__r);
					if($rand['type']==1)
					{
						$contents[]='<a href="'.$DIRCMS['site_url'].'ads.php?id='.$rand['id'].'" title="'.$rand['alt'].'" target="_blank"><img src="'.$DIRCMS['site_url'].$rand['imageurl'].'" width="'.$___r['width'].'" height="'.$___r['height'].'"  alt="'.$rand['alt'].'"/></a>';
					}
					if($rand['type']==2)
					{
						$contents[]='<OBJECT width="'.$___r['width'].'" height="'.$___r['height'].'">
<PARAM NAME=movie value="'.$DIRCMS['site_url'].$rand['flashurl'].'">
<PARAM NAME=quality value=high>
<PARAM NAME=wmode value='.$rand['wmode'].'>
<EMBED width="'.$___r['width'].'" height="'.$___r['height'].'" src="'.$DIRCMS['site_url'].$rand['flashurl'].'" quality=high wmode=transparent TYPE="application/x-shockwave-flash"></EMBED>
</OBJECT>';
					}
					if($rand['type']==3)
					{
						$contents[]=$rand['text'];
					}
					if($rand['type']==4)
					{
						$contents[]='<a href="'.$DIRCMS['site_url'].'ads.php?id='.$rand['id'].'" title="'.$rand['code'].'" target="_blank">'.$rand['code'].'</a>';
					}
					if($rand['type']==5)
					{
						$contents[]=stripslashes(stripslashes(base64_decode($rand['code'])));
					}
				}

				ob_start();
				include template($___r['template']);
				create_html(DIRCMS_ROOT.'data/ads/'.$_r['id'].'.html');
			}
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=adspos');
			break;
		case 'adspos':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['ads']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			
			if(isset($do_submit)) 
			{
				foreach($id as $val)
				{
					$db->update(DB_PRE.'adspos',array('name'=>$name[$val],'price'=>$price[$val]),'id='.intval($val));
				}
				$c->cache_adspos();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=adspos');
			}
			$where=1;
			$orderby="id DESC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'adspos',$where,$orderby,$page,15);	
			$pages=$l->pages;
			include admin_tlp('other_adspos');
			break;
		case 'adspos_add':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['ads']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			
			if(isset($do_submit)) 
			{
				if(!$info['name'])showmsg('广告名称不能为空!',ADMIN_FILE.'?file=other&action=adspos');
				$db->insert(DB_PRE."adspos",$info);
				$c->cache_adspos();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=adspos');
			}
			$r=cache_read('template.cache.php',TPL_ROOT.TPL_NAME.'/');
			$tlpname_select='<select name="info[template]" id="template">';
			if($r)foreach($r as $__r)
			{
				if(strtolower(substr($__r['template'],0,4))=='ads_')
				$tlpname_select.='<option value='.$__r['template'].'>'.$__r['name'].'('.$__r['template'].'.html)</option>';
			}
			$tlpname_select.='</select>';
			include admin_tlp('other_adspos_add');
			break;		
		case 'adspos_edit':
			if(isset($do_submit)) 
			{			
				$db->update(DB_PRE."adspos",$info,DB_PRE."adspos.id=".intval($id));
				$c->cache_adspos();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=adspos');
			}
			$result=$db->fetch_one("SELECT * FROM ".DB_PRE."adspos WHERE ".DB_PRE."adspos.id=".intval($id));
			$r=cache_read('template.cache.php',TPL_ROOT.TPL_NAME.'/');
			$tlpname_select='<select name="info[template]" id="template">';
			if($r)foreach($r as $__r)
			{
				$isselected=$result['template']==$__r['template']?' selected="selected"':'';
				if(strtolower(substr($__r['template'],0,4))=='ads_')
				$tlpname_select.='<option value="'.$__r['template'].'"'.$isselected.'>'.$__r['name'].'('.$__r['template'].'.html)</option>';
			}
			$tlpname_select.='</select>';
			include admin_tlp('other_adspos_edit');
			break;
		case 'adspos_delete':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['ads']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			$db->mysql_delete(DB_PRE.'adspos',intval($id));
			$c->cache_adspos();
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=adspos');
			break;
		case 'adspos_lock':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['ads']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if($db->query("UPDATE ".DB_PRE."adspos SET ".DB_PRE."adspos.ispassed=".intval($ispassed)." WHERE ".DB_PRE."adspos.id=".intval($id),true))
			{
				$c->cache_adspos();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=adspos');
			}
			else 
			{
				showmsg($LANG['MANAGE_ERROR']);
			}
			break;
		case 'install_plus':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['plus']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if($do_submit)
			{
				if(!preg_match('/^[a-z0-9_]{1,50}$/i',$info['link']))showmsg('插件包文件夹由1-50个a-z，0-9_组成!');
				$db->insert(DB_PRE."plus",$info);
				$c->cache_plus();
				showmsg('插件安装成功!<script language="javascript">self.top.document.frames("leftFrame").location.reload();</script>');
			}
			include admin_tlp('install_plus');
			break;
		case 'notice':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['notice']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if(isset($do_submit)) 
			{
				foreach($id as $val)
				{
					$db->update(DB_PRE.'notice',array('title'=>$title[$val],'orderby'=>$orderby[$val]),'id='.intval($val));
				}
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=notice');
			}
			
			$result=$db->fetch_all("SELECT * FROM ".DB_PRE."notice ORDER BY ".DB_PRE."notice.orderby ASC,id DESC");
			include admin_tlp('notice_manage');			
			break;
		case 'notice_add':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['notice']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if(isset($do_submit)) 
			{	
				if(!$info['title'])showmsg('公告标题不能为空!');
				$info['time']=TIME;
				$db->insert(DB_PRE.'notice',$info,true);
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=notice');
			}
			require_once(DIRCMS_ROOT.'include/form.class.php');	
			$form=new form();
			include admin_tlp('notice_add');
			break;
		case 'notice_edit':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['notice']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if(isset($do_submit)) 
			{
				$db->update(DB_PRE.'notice',$info,'id='.intval($id));
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=notice');
			}
			require_once(DIRCMS_ROOT.'include/form.class.php');	
			$form=new form();
			$r=$db->fetch_one("SELECT * FROM ".DB_PRE."notice WHERE id=$id");
			include admin_tlp('notice_edit');			
			break;
		case 'notice_delete':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['notice']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			$db->mysql_delete(DB_PRE.'notice',intval($id));
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=notice');
			break;
		case 'vote':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['plus']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if(isset($do_submit)) 
			{
				foreach($id as $val)
				{
					$db->update(DB_PRE.'vote',array('votename'=>$votename[$val],'totalcount'=>intval($totalcount[$val]),'starttime'=>strtotime($starttime[$val]),'endtime'=>strtotime($endtime[$val])),'id='.intval($val));
				}
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=vote');
			}
			$r=$db->fetch_all("SELECT * FROM `".DB_PRE."vote` ORDER BY `".DB_PRE."vote`.`id` DESC");
			include admin_tlp('other_vote');	
			break;
		case 'vote_add':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['plus']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
			if(isset($do_submit)) 
			{
				if(!$info['votename'])showmsg('投票名称不能为空!');
				$info['starttime']=strtotime($info['starttime']);
				$info['endtime']=strtotime($info['endtime']);
				if($info['endtime']<$info['starttime'])showmsg('结束时间不能小于开始时间!');
				foreach($votenote as $k => $v)
				{
					$info['votenote'].='<vote id="'.$k.'" count="0">'.$v.'</vote>'."\n";
				}
				$db->insert(DB_PRE.'vote',$info,true);
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=vote');
			}
			include admin_tlp('other_vote_add');
			break;
		case 'vote_edit':
			$id=intval($id);
			if(!$id)
			{
				showmsg('转向投票列表页...',ADMIN_FILE.'?file=other&action=vote');
			}
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['plus']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			if(isset($do_submit)) 
			{
				if(!$info['votename'])showmsg('投票名称不能为空!');
				$info['starttime']=strtotime($info['starttime']);
				$info['endtime']=strtotime($info['endtime']);
				$info['delay']=$info['delay']*3600;
				if($info['endtime']<$info['starttime'])showmsg('结束时间不能小于开始时间!');
				$db->update(DB_PRE.'vote',$info,'id='.intval($id));
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=vote');
			}
			$r=$db->fetch_one("SELECT * FROM `".DB_PRE."vote` WHERE `".DB_PRE."vote`.`id`={$id}");
			include admin_tlp('other_vote_edit');	
			break;
		case 'vote_delete':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['plus']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			$db->mysql_delete(DB_PRE.'vote',intval($id));
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=other&action=vote');
			break;
		case 'vote_view':
			$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
			$r=$r['plus']['roleid']; 
			if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');

			$id=intval($id);
			$itemstr='';
			$r=$db->fetch_one("SELECT * FROM `".DB_PRE."vote` WHERE `".DB_PRE."vote`.`id`={$id}");
			
			if(!$r)showmsg('无此投票!');
			$item=explode("\n",$r['votenote']);
			$totalitem=$r['totalcount']?$r['totalcount']:sizeof($item);
			if($item)foreach($item as $_item)
			{
				$len=preg_match('/<vote id="([0-9]+)" count="([0-9]+)">(.+?)<\/vote>/i',$_item,$lenreg);
				$len=$lenreg[2];
				$len=min(100,round($len/$totalitem,2)*100);
				$itemstr.=preg_replace('/<vote id="([0-9]+)" count="([0-9]+)">(.+?)<\/vote>/i',"<tr height='30'><td style='border-bottom:1px solid'>\\1、\\3</td><td style='border-bottom:1px solid'>
					
					<table border='0' cellspacing='0' cellpadding='2' title='$len%' width='$len%'><tr><td height='16' style='background-color:#BAD5F1;border:1px solid #666666;font-size:9pt;line-height:110%'>\\2</td></tr></table>
					</td></tr>",$_item);
			}
			$votestr="<table width='98%' border='0' cellspacing='1' cellpadding='1'>
		<tr><td height=22><strong>".$r['votename']."</strong> </td><td align='right'>投票开始时间：".date('Y-m-d',$r['starttime'])."　 投票结束时间：".date('Y-m-d',$r['endtime'])." 投票人数：".$r['totalcount']."</td></tr>
		<tr height='8'><td width='30%'></td><td></td></tr>".$itemstr."
		<tr><td></td><td></td></tr>
		</table>";
			include admin_tlp('other_vote_view');
			break;
		case 'sign':
			$where=1;
			$where=$contentid?$where." AND contentid=".$contentid:$where;
			$k=trim($k);
			$where=!empty($k)?$where." AND	title like '%{$k}%'":$where;
			$orderby="id DESC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'sign',$where,$orderby,$page,15);
			$pages=$l->pages;
			include admin_tlp('other_sign_manage');
			break;
	}
?>