Exemple #1
0
function add($s) {
	if (empty($_POST)) {		
		$tenement = new Tenement();					
		$block_html = Html::pageTenementAdd($tenement);
		$s->assign("block_html",$block_html);
		$s->assign("YANDEX_KEY",YANDEX_KEY);
		$s->assign("is_admin",$_SESSION['admin']);
		$s->display("tenement_add.tpl");
	}
	else {
		$tenement = new Tenement();
		$errors_tenement = (!isset($_REQUEST['id'])||!$_REQUEST['id']) ? $tenement->checkForm($_REQUEST) : array();							
		$errors = array(TENEMENT=>$errors_tenement);		
		if (!isset($errors[TENEMENT]['is_error'])) {
			//Дом уже есть в бд
			if (isset($_POST['id']) && $_POST['id']>0) {				
				$tenement_id = intval($_POST['id']);
				$tenement->find($tenement_id);
				if (!$tenement->id) {
					echo "Дом не найден";
					exit();
				}
			}
			//Добавляем дом в бд
			else {				
				$tenement->add($_POST);
			}			
			$photo_tenement_path = $tenement->getPhotoPath();
			if (!is_dir($photo_tenement_path)) {
				mkdir($photo_tenement_path,0777,true);				
			}
			if (isset($_POST['photo_tenement']) && is_array($_POST['photo_tenement'])) {
				foreach ($_POST['photo_tenement'] as $fname) {
					$fname = clearTextData($fname);
					$tenement->addPhoto($fname,$_POST);
				}
			}
			if ($tenement->id > 0) header("Location: /tenement.html?action=view&id=".$tenement->id);						
			exit();
		}
		else {
			echo "Error:".print_r($errors);
			$block_html = Html::pageTenementAdd($tenement,$errors);
			$s->assign("block_html",$block_html);
			$s->assign("YANDEX_KEY",YANDEX_KEY);
			$s->assign("is_admin",$_SESSION['admin']);
			$s->display("tenement_add.tpl");
		}
	}
}
Exemple #2
0
function add($s) {	
	if (empty($_POST)) {		
		$tenement = new Tenement();			 						
		$flat = new Flat();
		if (isset($_COOKIE['contacts'])) {			
			$errors[FLAT]['val']['contacts'] = $_COOKIE['contacts'];
		}
		else {
			$errors = NULL;	
		}							
		$block_html = Html::pageFlatAdd($tenement,$flat,$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("flat_add.tpl");
	}
	else {
		$tenement = new Tenement();		
		if ($_REQUEST['city_id']>1) {
			Tenement::$_properties['street']['required']=null;
			Tenement::$_properties['street_id']['required']=null;	
			Tenement::$_properties['number']['required']=null;
		}		
		$errors_tenement = (!isset($_REQUEST['id'])||!$_REQUEST['id']) ? Tenement::checkForm($_REQUEST) : array();		
		$flat = new Flat();
		//Продажа
		$_POST['flat__price'] = intval(numStrToClearStr($_POST['flat__price']));
		if ($_POST['type_deal']==SALE && $_POST['flat__price']<20000) {
			$_POST['flat__price'] *= 1000;
			$_REQUEST['flat__price'] = $_POST['flat__price']; 
		}
		if ($_POST['type_deal']==RENT && $_POST['flat__price']>=100000) {
			$_POST['type_deal']= SALE;
		}
		
		if ($_POST['type_deal']==RENT) {
			Flat::$_properties['price']['min_val']=1000;
		}
		$errors_flat = Flat::checkForm($_REQUEST,'flat__');						
		$errors = array(TENEMENT=>$errors_tenement,FLAT=>$errors_flat);		
		require_once './libs/securimage/securimage.php';
		$securimage = new Securimage();
		if ($securimage->check($_POST['captcha_code']) == false) {
			$errors['captcha']['is_error'] = 1;
		}		
		if (!isset($errors[TENEMENT]['is_error'])&&!isset($errors[FLAT]['is_error'])&&!isset($errors['captcha']['is_error'])) {
			//Дом уже есть в бд
			if (isset($_POST['id']) && $_POST['id']>0) {				
				$tenement_id = intval($_POST['id']);
				$tenement->find($tenement_id);
				if (!$tenement->id) {
					echo "Дом не найден";
					exit();
				}
			}
			//Добавляем дом в бд
			else {				
				$tenement->add($_POST);
			}			
			//Квартира уже есть в бд
			if (isset($_POST['flat_id'])) {
				echo "exist:".$flat_id = intval($_POST['flat_id']);
				$flat->getFull($flat_id);
				$flat_id = $flat->id;				
			}
			//Добавляем кв в бд
			else {
				$data = $_POST;
				$data['flat__tenement_id'] = $tenement->id;
				$data['flat__status'] = $data['type_deal']==SALE ? REALTY_STATUS_NEW : REALTY_STATUS_RENT_NEW;
				if ($tenement_id>0 && isset($_SESSION['user_id'])) {
					if ($data['flat__status']==REALTY_STATUS_NEW) {
						$data['flat__status'] = REALTY_STATUS_SALE;
					}
					else {
						$data['flat__status'] = REALTY_STATUS_RENT;
					}					
				}
				$data['flat__description'] = clearTextData($data['flat__description'],10000);
				$data['flat__contacts'] = clearTextData($data['flat__contacts'],1000); 
				$flat->add($data,'flat__');
			}
			setcookie('contacts',stripslashes($_POST['flat__contacts']));
			$_SESSION['last_flat_id'] = $flat->id;					
			$photo_tenement_path = $tenement->getPhotoPath();
			if (!is_dir($photo_tenement_path)) {
				mkdir($photo_tenement_path,0777,true);				
			}
			if (isset($_POST['photo_tenement']) && is_array($_POST['photo_tenement'])) {
				foreach ($_POST['photo_tenement'] as $fname) {
					$fname = clearTextData($fname);
					$tenement->addPhoto($fname,$_POST);
				}
			}
			$photo_flat_path = $flat->getPhotoPath();
			if (!is_dir($photo_flat_path)) {			
				mkdir($photo_flat_path,0777);						
			}
			if (isset($_POST['photo_flat']) && is_array($_POST['photo_flat'])) {
				foreach ($_POST['photo_flat'] as $fname) {
					$fname = clearTextData($fname);
					$flat->addPhoto($fname,$_POST);
				}
			}
			if ($flat->id > 0) header("Location: /flat.html?action=view&id=".$flat->id);			
			exit();
		}
		else {
			//echo "Error:".print_r($errors);
			$block_html = Html::pageFlatAdd($tenement,$flat,$errors);			
			$s->assign("YANDEX_KEY",YANDEX_KEY);
			if (isset($_SESSION['admin'])) $s->assign("is_admin",$_SESSION['admin']);
			if (isset($_REQUEST['id'])) $s->assign("tenement_id",intval($_REQUEST['id']));			
			$s->assign("city_id",intval($_REQUEST['city_id']));
			$s->assign("street_id",intval($_REQUEST['street_id']));
			$s->assign("lon",clearTextData($_REQUEST['lon']));
			$s->assign("lat",clearTextData($_REQUEST['lat']));
			$s->assign("is_error",1);
			$s->assign("block_html",$block_html);
			$s->display("flat_add.tpl");
		}
	}	
}
Exemple #3
0
function edit($s) {	
	$_SESSION['last_commercial_id'] = (isset($_SESSION['last_commercial_id'])) ? $_SESSION['last_commercial_id'] : -1;
	$id = intval($_REQUEST['id']);
	$commercial = new Commercial();
	$commercial->getFull($id);
	if ($commercial->tenement_id > 0)
		$commercial->number = $commercial->tnum;  
	//загрузка дома	
	if (empty($_POST) && $commercial->id>0) {		
		if (isset($_SESSION["admin"])) $_SESSION['last_commercial_id'] = $id; 	
		if ($id!=$_SESSION['last_commercial_id'] && !$_SESSION['user_id'] && !$_SESSION["admin"]) {
			header("Location: /index.html");
			exit();
		}		
		if (isset($_SESSION['user_id']) && $commercial->user_id != $_SESSION['user_id'] && !$_SESSION["admin"] 
			&& $id!=$_SESSION['last_commercial_id']) {
			header("Location: /index.html");
			exit();
		}		
		$block_html = Html::pageCommercialEdit($commercial);
		$s->assign("YANDEX_KEY",YANDEX_KEY);
		
		$s->assign("city_id",$commercial->city_id);
		$s->assign("city",$commercial->city);
		$s->assign("street_id",$commercial->street_id);
		if (!$commercial->tenement_id) $commercial->street = $commercial->street_name;		
		$s->assign("street",$commercial->street);
		if (isset($_SESSION['admin'])) $s->assign("is_admin",$_SESSION['admin']);		
		$s->assign("block_html",$block_html);
		$s->display("commercial_add.tpl");
	}
	//обновление
	elseif (isset($_POST) && $_REQUEST['id']>0) {
		$commercial = new Commercial();		
		$errors = $commercial->checkForm($_REQUEST);
		$id = intval($_REQUEST['id']);
		if ($id!=$_SESSION['last_commercial_id'] && !$_SESSION['user_id'] && !$_SESSION["admin"]) {
			header("Location: /index.html");
			exit();
		}
		//Дом уже есть в бд
		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();
			}
		}			
	
		if (!isset($_SESSION['user_id'])) {
			$commercial->getFull($id);
		}
		else {
			$commercial->getFull($id,"h.user_id='{$_SESSION['user_id']}'");
			if ($commercial->user_id != $_SESSION['user_id'] && !$_SESSION["admin"] && $id!=$_SESSION['last_commercial_id']) {
				header("Location: /index.html");
				exit();
			}
		}				
		if (!isset($errors['is_error']) && $commercial->id > 0) {						
			$commercial->update($_POST);					
			//добавляем новые фото
			if (isset($_POST['photo_commercial']) && is_array($_POST['photo_commercial'])) {
				$photo_commercial_path = $commercial->getPhotoPath();
				if (!is_dir($photo_commercial_path)) {			
					mkdir($photo_commercial_path,0777);
					chmod($photo_commercial_path,0777);						
				}				
				foreach ($_POST['photo_commercial'] as $fname) {					
					$fname = clearTextData($fname);
					if ($fname!='') $commercial->addPhoto($fname,$_POST);
				}
			}
			//редактируем существующие фото
			if (isset($_POST['photo_'.COMMERCIAL.'_exist']) && is_array($_POST['photo_'.COMMERCIAL.'_exist'])) {
				$photo_commercial_path = $commercial->getPhotoPath();
				if (!is_dir($photo_commercial_path)) {			
					mkdir($photo_commercial_path,0777);
					chmod($photo_commercial_path,0777);						
				}
				foreach ($_POST['photo_'.COMMERCIAL.'_exist'] as $fname) {
					$fname = clearTextData($fname);
					if ($fname!='') $commercial->editPhoto($fname,$_POST);
				}
			}			
			header("Location: /commercial.html?action=view&id=".$commercial->id);
			exit();
		}
		else {
			echo "error";
			$id = intval($_REQUEST['id']);			
			$commercial->getFull($id);				
			$block_html = Html::pageCommercialEdit($commercial,$errors);
			$s->assign("YANDEX_KEY",YANDEX_KEY);
			$s->assign("is_admin",$_SESSION['admin']);			
			$s->assign("block_html",$block_html);
			$s->display("commercial_edit.tpl");
		}
	}
	else {
		echo "error";
	}
}