<?php
/**
 *      [Dzz!] (C)2010-2011 dzz.cc
 *      This is NOT a freeware, use is subject to license terms
 *
 * ============================================================================
 * 版权所有 2010-2011 Dzz!Desktop，并保留所有权利。
 * 网站地址: http://dzz.cc；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式、任何目的的再发布。
 * ============================================================================
 */
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}
$refer=dreferer();
dzz_cpheader();
	require_once libfile('function/post');

//	$dzz_announce = DB::result_first("SELECT svalue FROM ".DB::table('common_setting')." WHERE skey='dzz_announce'");
	$dzz_announce = dstripslashes(unserialize(stripslashes($_G['setting']['dzz_announce'])));
	
	if(!$operation) {
		if(submitcheck('announcesubmit')) {
			$newfocus = array();
			
			$newfocus['data'] = array();
			if(isset($dzz_announce['data']) && is_array($dzz_announce['data'])) foreach($dzz_announce['data'] as $k => $v) {
				if(is_array($_GET['delete']) && in_array($k, $_GET['delete'])) {
					unset($dzz_announce['data'][$k]);
				} else {
					$v['available'] = $_GET['available'][$k] ? 1 : 0;
					$newfocus['data'][$k] = $v;
				}
			}
			$newfocus['cookie'] = $dzz_announce['cookie'];
			DB::insert('common_setting', array(
				'skey' => 'dzz_announce',
				'svalue' => addslashes(serialize(dstripslashes($newfocus))),
			), false, true);
			updatecache(array('setting', 'dzz_announce'));

			cpmsg($lang['announce_manage_update_succeed'], 'action=announce', 'succeed');

		}

	} elseif($operation == 'add') {

		if(count($focus['data']) >= 10) {
			cpmsg($lang['announce_add_num_limit'], 'action=announce', 'error');
		}

		if(submitcheck('addsubmit')) {
			if($_GET['announce_subject'] && $_GET['announce_summary']) {
				
				$dzz_announce['data'][] = array(
					'available' => '1',
					'subject' => cutstr($_GET['announce_subject'], 80),
					'summary' => $_GET['announce_summary'],
				);
				DB::insert('common_setting', array(
					'skey' => 'dzz_announce',
					'svalue' => addslashes(serialize(dstripslashes($dzz_announce))),
				), false, true);
				updatecache(array('setting', 'dzz_announce'));
			} else {
				cpmsg($lang['extended_announce_addrequired'], '', 'error');
			}

			cpmsg($lang['extended_announce_add_succeed'], 'action=announce', 'succeed');

		}

	} elseif($operation == 'edit') {
		$id = intval($_GET['id']);
		if(!$item = $dzz_announce['data'][$id]) {
			cpmsg($lang['extended_announce_noexists'], 'action=announce', 'error');
		}
		if(submitcheck('editsubmit')) {

			if($_GET['announce_subject'] && $_GET['announce_summary']) {
				
				$item = array(
					'available' => '1',
					'subject' => cutstr($_GET['announce_subject'], 50),
					'summary' => $_GET['announce_summary'],
					
				);
				$dzz_announce['data'][$id] = $item;
				DB::insert('common_setting', array(
					'skey' => 'dzz_announce',
					'svalue' => addslashes(serialize(dstripslashes($dzz_announce)))
				), false, true);
				updatecache(array('setting', 'dzz_announce'));
			}

			cpmsg($lang['extended_announce_edit_succeed'], 'action=announce', 'succeed');

		}
	} elseif($operation == 'config') {
		if(submitcheck('confsubmit')) {
			$dzz_announce['cookie'] = trim(intval($_GET['announce_cookie']));
			$dzz_announce['cookie'] = empty($dzz_announce['cookie']) ? 0 : $dzz_announce['cookie'];
			DB::insert('common_setting', array(
				'skey' => 'dzz_announce',
				'svalue' => addslashes(serialize(dstripslashes($dzz_announce)))
			), false, true);
			updatecache(array('setting', 'dzz_announce'));
			cpmsg($lang['extended_announce_conf_succeed'], 'action=announce&operation=config', 'succeed');
		}

	}
include dzztemplate('admin/dzz_announce');
dzzfooter();
?>