<?php
defined('PHP168_PATH') or die();

/**
* 添加模型内容入口文件
**/

$this_controller->check_action($ACTION) or message('no_privilege');
//强制登录
$UID or message('not_login', $core->U_controller.'?forward='.$this_url,2);

if(REQUEST_METHOD == 'GET' || defined('P8_GENERATE_HTML')){
	$SEO_KEYWORDS = $SEO_DESCRIPTION = '';
	$TITLE = '我要写信_'. $core->CONFIG['site_name'];
	
	$data['department'] = isset($_GET['department'])? intval($_GET['department']):'';
	$cates = $this_module->get_category();
	$type = '';
	foreach($URL_PARAMS as $k => $v){
		switch($v){		
			case 'type':
				$type = isset($URL_PARAMS[$k +1]) ? intval($URL_PARAMS[$k +1]) : '';
			break;		
		}
	}
	$data['visual'] = 1;
	$data['type'] = !empty($type) ? intval($type):'';
	if(!empty($this_module->CONFIG['redepartment'])){
		unset($cates['department'][$this_module->CONFIG['redepartment']]);
	}
	$id_type = $this_module->id_type();
	$attachment_hash = unique_id(16);
	
	$letterconfig = $core->get_config('core', 'letter');
	$tatistics = $this_module->getstatistics2();
	
	include template($this_module, 'edit');

}else if(REQUEST_METHOD == 'POST'){
	
	//如果魔法引号开启strip掉
	$_POST = p8_stripslashes2($_POST);
	if(isset($_POST['checkcaptcha'])){
		$st = !captcha(isset($_POST['captcha']) ? $_POST['captcha'] : '',true)?'false':'true';
		exit($st);
	}
	$id = $_POST['id'];
	$status = $this_controller->add($_POST) or message('fail');
	unset($_POST);
	$message = p8lang($P8LANG['post_success'], $status['number'],$status['code']);
	$reurl = $this_url;
	include template($this_module, 'message');	
}
