function getTenementInfo($param) { if (isset($param['tenement_id'])) { $tenement_id = intval($param['tenement_id']); $row = Tenement::getFullStatic($tenement_id); if ($row) { $vals = Tenement::getPropertiesValStatic($row); $vals['id'] = $row['id']; $vals['city_id'] = $row['city_id']; $vals['street_id'] = $row['street_id']; $vals['lat'] = $row['lat']; $vals['lon'] = $row['lon']; $vals['address'] = $row['street'] . ', ' . $row['number']; echo json_encode($vals); } else { echo ''; } } else { $city_id = intval($param['city_id']); $number = clearTextData($param['number']); $street = clearTextData($param['street']); $sql = "city_id={$city_id} AND name='{$street}'"; $res = Street::getListLink($sql); $num_rows = $res->numRows(); if ($num_rows < 1) { /* * Добавлять без проверки на человека не будем чтобы не было дыры */ //$street_id = $streetObj->add(array('city_id'=>$city_id, 'name'=>$street)); echo ''; } else { $row = $res->fetchRow(); $street_id = $row['id']; $res = Tenement::getBy("city_id={$city_id} AND street_id={$street_id} AND number LIKE '{$number}'"); if ($res) { $row = $res->fetchRow(); } if ($row) { $vals = Tenement::getPropertiesValStatic($row); $vals['id'] = $row['id']; $vals['city_id'] = $row['city_id']; $vals['street_id'] = $row['street_id']; $vals['lat'] = $row['lat']; $vals['lon'] = $row['lon']; $vals['address'] = $street . ', ' . $row['number']; echo json_encode($vals); } else { echo ''; } } } }
public static function getAdminTenementList($action, $per_page = 10, $current_page = 1) { if ($action == 'listActive') { $where = "t.status='" . REALTY_STATUS_APPLY . "'"; } else { if ($action == 'listNew') { $where = "t.status='" . REALTY_STATUS_NEW . "'"; } } $start_pos = ($current_page - 1) * $per_page; $limit = " LIMIT {$start_pos},{$per_page}"; $amount = Tenement::getAmountInList($where); $order = " ORDER BY id DESC"; $db_res = Tenement::getFullListLink($where . $order . $limit); $paginator = self::paginator("tenement.php?action={$action}", $amount, $per_page, $current_page); $html = "\n\t\t<div>{$paginator}</div>\n\t\t<div><a href='tenement.html?action=activateAll'>Активировать все</a></div>\t\t\n\t\t<table class='base_text'>\n\t\t<thead>\n\t\t<tr>\n\t\t <th>Адрес</th>\t\t \n\t\t <th>Тип дома</th>\n\t\t <th>Этажность</th>\n\t\t <th>Карта</th>\t\t \n\t\t <th></th>\n\t\t <th></th>\n\t\t <th></th>\n\t\t <th></th>\n\t\t</tr>\n\t\t</thead>\n\t\t<tbody>\n\t\t"; while ($row = $db_res->fetchRow()) { $type = Tenement::$TYPE[$row['type_id']]; $city = $row['city_id'] == 0 ? '' : $row['city'] . ','; $addr = "{$city} {$row['street']}, {$row['number']}"; $map = $row['lat'] && $row['lon'] ? 'Да' : '<b>Нет</b>'; $html .= "<tr>\n\t\t\t<td>{$addr}</td>\t\t\t\n\t\t\t<td>{$type}</td>\n\t\t\t<td>{$row['storeys']}</td>\n\t\t\t<td>{$map}</td>\n\t\t\t<td><a href='/tenement.html?action=edit&id={$row['id']}' target='_blank'>Редактировать</a></td>\t\t\t\n\t\t\t<td><a href='/tenement.html?action=view&id={$row['id']}' target='_blank'>Смотреть</a></td>\n\t\t\t<td><a href='javascript:delTenement({$row['id']})'>Удалить</a></td>\n\t\t\t<td><a href='/tenement.html?action=approve&id={$row['id']}' target='_blank'>Активировать</a></td>\n\t\t\t</tr>"; } $html .= "</tbody></table>\n\t\t<script>\t\t\n\t\tdelTenement = function(id) {\n\t\t\tif (confirm('Вы уверены удалить этот дом?')) {\n\t\t\t\tlocation.href = '/tenement.html?action=delete&id='+id;\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\t\t\t\t\n\t\t</script>"; return $html; }
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"); } } }
function delete() { if (!isset($_SESSION['admin'])) { echo "Not admin"; //header("Location: /index.html"); exit(); } $id = intval($_REQUEST['id']); Tenement::delete($id); header("Location: ".$_SERVER['HTTP_REFERER']); }
function import($s) { if (!isset($_SESSION['user_id'])) { header("Location: index.html"); exit(); } $amount=-1; $num_updated_all = 0; if (isset($_FILES["userfile"])) { if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { $filename = $_FILES['userfile']['tmp_name']; $rows = file($filename); unset($rows[0]); $amount=0; foreach ($rows as $row) { $row = iconv("windows-1251", "utf-8", $row); $el = explode('|',$row); $date = $el[33];//дата объявления //if ($date<date('d.m.Y')) $type_deal = $el[0];//1 - продажа, 2 - аренда $status = ($el[0]==1) ? REALTY_STATUS_IMPORT_SALE : REALTY_STATUS_IMPORT_RENT; $is_city = $el[1];//1-город 2-республика if ($is_city != 1) continue; $rooms = $el[2];//11-комната 22-дом 27-участок 28-уч. под застройку 41-гараж if ($rooms>11) continue; $phone = $el[6]; $an_name = $el[7]; $phone2 = $el[8]; $name2 = $el[9]; $street = $el[10]; //echo "\n$street _\n"; if(!preg_match("/[0-9]+[а-яА-Я]*$/", $street)) { //нет номера дома //continue; } //echo "\n$street\n"; preg_match("/[0-9]+[а-яА-Я]*$/", $street,$nums_tenement); $num = mb_strtolower($nums_tenement[0],'UTF-8');//strtolower($nums_tenement[0]); $street_name = str_replace($num,'',$street); $street_name = trim(str_replace(' ',' ',$street_name)); $street_clear2 = str_replace('ул','',$street_name); $street_clear2 = str_replace('.','',$street_clear2); $street_arr = explode(' ',$street_clear2); //находим самую длинную строку в названии улицы $i = 0; $max_len = ''; $last_len = 0; if(count($street_arr)) { foreach ($street_arr as $c) { if (strlen($c)>$last_len) { $max_len = $c; $last_len = strlen($c); } $i++; } } if ($max_len=='') continue; //echo "\nmax_len=$max_len"; $row = Street::findBy("name LIKE '%$max_len%'"); if (!$row) { $street_id = Street::createStatic(array('name'=>$street_name,'city_id'=>0, 'status'=>0)); } else { $street_id = $row['id']; $street_name = $row['name']; } $storey = $el[12]; $stores = $el[13]; $tenement_type = $el[15]; if ($tenement_type=='КИРП') $type_id=0; elseif ($tenement_type=='ПАН') $type_id=1; elseif ($tenement_type=='БЛОК') $type_id=3; elseif ($tenement_type=='ДЕР') $type_id=4; else $type_id=2; $total_area = str_replace(',','.',$el[16]); //if ($total_area=='') continue; $living_area = str_replace(',','.',$el[17]); $kitchen_area = str_replace(',','.',$el[18]); if (!$kitchen_area) $kitchen_area=9; $description = $el[26]; $price = str_replace(',','.',$el[27]); //if (!($price>0)) continue; $price_k = $el[28];//1-тыс. 2-млн. 5-руб/м 6-у.е./м if ($price_k==1) $price *= 1000; elseif ($price_k==2) $price *= 1000000; elseif ($price_k==5) $price *= $total_area; $haggle = $el[29];//торг/чистая продажа $date_end = $el[31];//срок сдачи дома $row = Tenement::findBy("street_id='$street_id' AND number='$num'"); if ($row) { $tenement_id=$row['id']; } else { $num = clearTextData($num); $options = array( 'city_id'=>0, 'street_id'=>$street_id, 'number'=>$num, 'type_id'=>clearTextData($type_id), 'storeys'=>clearTextData($stores), 'hot_water'=>1, 'type_energy'=>0, 'type_heating'=>0, 'user_id'=>$_SESSION['user_id'], 'status'=>REALTY_STATUS_NEW ); $address = urlencode('Йошкар-Ола, '.$street_name.', д.'.$num); $geo_url = 'http://psearch-maps.yandex.ru/1.x/?text='.$address.'&key='.YANDEX_KEY.'&format=json'; $json = file_get_contents($geo_url); $d = json_decode($json); if (isset($d->{'response'}->{'GeoObjectCollection'}->{'featureMember'}[0]->{'GeoObject'}->{'Point'}->{'pos'})) { $coords = explode(' ',$d->{'response'}->{'GeoObjectCollection'}->{'featureMember'}[0]->{'GeoObject'}->{'Point'}->{'pos'}); $options['lon'] = $coords[0]; $options['lat'] = $coords[1]; } $tenement_id = Tenement::addStatic($options); } if (!$tenement_id) continue; $num_updated = Flat::updateByCondition("tenement_id='$tenement_id' AND rooms='$rooms' AND storey='$storey' AND price='$price' AND user_id='{$_SESSION['user_id']}'",array('updated_on'=>date('Y-m-d H:i:s'))); $num_updated_all += $num_updated; if ($num_updated>0) continue; $contacts = ($phone2!='') ? $phone2.' '.$name2 : $phone.' '.$an_name; $options = array( 'tenement_id'=>$tenement_id, 'price'=>clearTextData($price), 'rooms'=>clearTextData($rooms), 'storey'=>clearTextData($storey), 'total_area'=>clearTextData($total_area), 'kitchen_area'=>clearTextData($kitchen_area), 'living_area'=>clearTextData($living_area), 'description'=>clearTextData($description,1000), 'contacts'=>clearTextData($contacts), 'user_id'=>$_SESSION['user_id'], 'status'=>$status ); Flat::addStatic($options); $amount++; } $dest = IMPORT_PATH.$_SESSION['user_id'].'_'.date('d').'_'.date('m').'_'.date('H').'_'.date('i').'_'.date('s').'.txt'; move_uploaded_file($filename,$dest); } } $s->assign("amount",$amount); $s->assign("num_updated_all",$num_updated_all); $s->display("import.tpl"); }
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"; } }