<?php

/*
 * Copyright (C) xgcms.com
 */

!defined('FRAMEWORK_PATH') && exit('FRAMEWORK_PATH not defined.');

include POST_PATH.'admin/control/admin_control.class.php';

class extend_control extends admin_control {
	
	function __construct(&$conf) {
		parent::__construct($conf);
		$this->_checked = array('bbs'=>' class="checked"');
		$this->check_admin_group();
	}
	public function on_ads(){
		$this->_title[] = '广告管理';
		$this->_nav[] = '<a href="./">广告管理</a>';
		
		$error = array();
		if($this->form_submit()) {
			
			// 修改
			$adsidarr = core::gpc('adsid', 'P');
			$namearr = core::gpc('adsname', 'P');
			$contentarr = core::gpc('adscontent', 'P');
			// hook admin_forum_list_gpc_after.php
			
			if(!empty($adsidarr)) {
				foreach($adsidarr as $aid) {
					$aid = intval($aid);
					$ad = $this->ads->get($aid);
					
					if(empty($namearr[$aid])){
						$this->ads->_delete($aid);
						continue;
					}
					
					$ad['adsname'] = $namearr[$aid];
					$ad['adscontent'] = $contentarr[$aid];
					$this->ads->update($ad);

				}
			}
			
			// 新增
			$ads_name_sub=core::gpc('ads_name_sub','P');
			$ads_content_sub=core::gpc('ads_content_sub','P');
			if(!empty($ads_name_sub)&&!empty($ads_content_sub)) {
				$data=array();
				$data['adsname'] = trim($ads_name_sub);
			    $data['adscontent'] = stripslashes(trim($ads_content_sub));
				$newad = $this->ads->create($data);
			}
			$this->ads->clear_cache();
			
		}
		$list = $this->ads->get_ads_all();
		$this->view->assign('error', $error);
		$this->view->assign('list', $list);
		$this->view->display('extend_ads.html');
		
	}
	
	private function t2js($l1, $l2=1){
       $I1 = str_replace(array("\r", "\n"), array('', '\n'), addslashes($l1));
       return $l2 ? "document.write(\"$I1\");" : $I1;
   }
	
}

?>