예제 #1
0
function add($s) {
	if (empty($_POST)) {		
		if (isset($_COOKIE['contacts'])) {			
			$errors['val']['contacts'] = $_COOKIE['contacts'];
		}
		else {
			$errors = NULL;	
		}							
		$block_html = Html::pageCommercialAdd($errors);
		$s->assign("block_html",$block_html);
		$s->assign("YANDEX_KEY",YANDEX_KEY);
		$s->assign("LAT_CENTER_REGION",LAT_CENTER_REGION);
		$s->assign("LON_CENTER_REGION",LON_CENTER_REGION);				
		$s->display("commercial_add.tpl");
	}
	else {		
		$errors = Commercial::checkForm($_REQUEST,'');				
		require_once './libs/securimage/securimage.php';
		$securimage = new Securimage();
		if ($securimage->check($_POST['captcha_code']) == false) {
			$errors['captcha']['is_error'] = 1;
		}		
		if (!isset($errors['is_error'])&&!isset($errors['captcha']['is_error'])) {

			//Дом уже есть в бд
			if (isset($_POST['tenement_id']) && $_POST['tenement_id']>0) {				
				$tenement_id = intval($_POST['tenement_id']);
				$tenement = new Tenement();
				$tenement->find($tenement_id);
				if (!$tenement->id) {
					echo "Дом не найден";
					exit();
				}
			}			
			$commercial_id = Commercial::addStatic($_POST);			
			setcookie('contacts',stripslashes($_POST['contacts']));
			$_SESSION['last_commercial_id'] = $commercial_id;			
			if ($commercial_id > 0) header("Location: /commercial.html?action=view&id=".$commercial_id);			
			exit();
		}
		else {
			//echo "Error:".print_r($errors);
			$block_html = Html::pageCommercialAdd($errors);
			$s->assign("YANDEX_KEY",YANDEX_KEY);
			if (isset($_SESSION['admin'])) $s->assign("is_admin",$_SESSION['admin']);
			$s->assign("block_html",$block_html);
			$s->display("commercial_add.tpl");
		}
	}	
}