public static function addStatic(array $values) { $options = array(); foreach (self::$_properties as $k => $v) { if ($k != 'street' && $k != 'city' && $k != 'price_m') { if ($v['type'] == 'int') { $options[$k] = numStrToClearStr($values[$k]); } else { $options[$k] = isset($values[$k]) ? $values[$k] : ''; } } elseif ($k == 'street') { $v = clearTextData($values[$k]); $db_res = Street::getListLink('name="' . $v . '" AND city_id="' . $values['city_id'] . '"'); $row = $db_res->fetchRow(); if ($row) { $options['street_id'] = $row['id']; } else { $street_id = Street::createStatic(array('city_id' => $values['city_id'], 'name' => $v, 'status' => 0)); $options['street_id'] = $street_id; } } } $options['price_m'] = intval($options['price'] / $values['total_area']); $options['description'] = self::prepareDescription($values['description']); $options['contacts'] = self::prepareDescription($values['contacts']); $options['status'] = REALTY_STATUS_NEW; $id = parent::addStatic($options); return $id; }
public function add(array $values, $prefix = '') { $values[$prefix . 'price_m'] = intval(intval(numStrToClearStr($values[$prefix . 'price'])) / floatval(numStrToClearStr($values[$prefix . 'total_area']))); $values[$prefix . 'description'] = self::prepareDescription($values[$prefix . 'description']); if (isset($_POST['show_address'])) { $values[$prefix . 'show_address'] = intval($_POST['show_address']); } //print_r($values); parent::add($values, $prefix); }
public static function addStatic(array $values) { $options = array(); foreach (self::$_properties as $k => $v) { if ($v['type'] == 'int') { $options[$k] = numStrToClearStr($values[$k]); } else { $options[$k] = isset($values[$k]) ? $values[$k] : ''; } } $options['description'] = self::prepareDescription($values['description']); $id = parent::addStatic($options); return $id; }
public static function addStatic(array $values) { $options = array(); foreach (self::$_properties as $k => $v) { if ($k != 'city' && $k != 'price_h') { if ($v['type'] == 'int') { $options[$k] = numStrToClearStr($values[$k]); } else { $options[$k] = isset($values[$k]) ? $values[$k] : ''; } } } $options['price_h'] = intval($options['price'] / $values['area']); $options['description'] = self::prepareDescription($values['description']); $options['contacts'] = self::prepareDescription($values['contacts']); $options['status'] = REALTY_STATUS_NEW; $id = parent::addStatic($options); return $id; }
public static function addStatic(array $values) { $options = array(); foreach (self::$_properties as $k => $v) { if ($k != 'city' && $k != 'street' && $k != 'number' && $k != 'price_m') { if ($v['type'] == 'int') { $options[$k] = numStrToClearStr($values[$k]); } else { $options[$k] = isset($values[$k]) ? $values[$k] : ''; } } } $options['number'] = self::prepareDescription(strtolower($options['number'])); $options['price_m'] = intval($options['price'] / $values['total_area']); $options['address'] = self::prepareDescription($values['address']); $options['contacts'] = self::prepareDescription($values['contacts']); $options['description'] = self::prepareDescription($values['description']); $options['status'] = $values['type_deal'] == 1 ? REALTY_STATUS_NEW : REALTY_STATUS_RENT_NEW; $id = parent::addStatic($options); return $id; }
function edit($s) { $_SESSION['last_flat_id'] = (isset($_SESSION['last_flat_id'])) ? $_SESSION['last_flat_id'] : -1; if (empty($_POST)) { $id = intval($_REQUEST['id']); if (isset($_SESSION["admin"])) $_SESSION['last_flat_id'] = $id; if ($id!=$_SESSION['last_flat_id'] && !$_SESSION['user_id'] && !$_SESSION["admin"]) { header("Location: /index.html"); exit(); } $flat = new Flat(); $flat->getFull($id); if (isset($_SESSION['user_id']) && $flat->user_id != $_SESSION['user_id'] && !$_SESSION["admin"] && $id!=$_SESSION['last_flat_id']) { header("Location: /index.html"); exit(); } $block_html = Html::pageFlatEdit($flat); $s->assign("YANDEX_KEY",YANDEX_KEY); $s->assign("block_html",$block_html); $s->display("flat_edit.tpl"); } else { $flat = new Flat(); $id = intval($_REQUEST['id']); if ($id!=$_SESSION['last_flat_id'] && !$_SESSION['user_id'] && !$_SESSION["admin"]) { header("Location: /index.html"); exit(); } if (!isset($_SESSION['user_id'])) { $flat->getFull($id); } else { $flat->getFull($id,"f.user_id='{$_SESSION['user_id']}'"); if ($flat->user_id != $_SESSION['user_id'] && !$_SESSION["admin"] && $id!=$_SESSION['last_flat_id']) { header("Location: /index.html"); exit(); } else { //$_SESSION['last_flat_id'] = $flat->user_id; } } $_REQUEST['price'] = intval(numStrToClearStr($_REQUEST['price'])); if (in_array($flat->status,array(REALTY_STATUS_RENT,REALTY_STATUS_RENT_APPLY,REALTY_STATUS_RENT_NEW))) { Flat::$_properties['price']['min_val']=1000; } $errors = $flat->checkForm($_REQUEST); if (!isset($errors['is_error']) && $flat->id > 0) { $flat->update($_POST); $photo_flat_path = $flat->getPhotoPath(); if (!is_dir($photo_flat_path)) { mkdir($photo_flat_path,0777); chmod($photo_flat_path,0777); } //добавляем новые фото if (isset($_POST['photo_flat']) && is_array($_POST['photo_flat'])) { foreach ($_POST['photo_flat'] as $fname) { $fname = clearTextData($fname); if ($fname!='') $flat->addPhoto($fname,$_POST); } } //редактируем существующие фото if (isset($_POST['photo_flat_exist']) && is_array($_POST['photo_flat_exist'])) { foreach ($_POST['photo_flat_exist'] as $fname) { $fname = clearTextData($fname); if ($fname!='') $flat->editPhoto($fname,$_POST); } } header("Location: /flat.html?action=view&id=".$flat->id); exit(); } else { //echo "error"; //print_r($errors); $id = intval($_REQUEST['id']); $flat->getFull($id); $block_html = Html::pageFlatEdit($flat,$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("flat_add.tpl"); } } }
public function add(array $values, $prefix = '') { $options = array(); $called_class = get_called_class(); foreach ($called_class::$_properties as $k => $v) { if (isset($values[$prefix . $k]) && $values[$prefix . $k] !== '') { if (isset($v['type']) && $v['type'] == 'int') { $values[$prefix . $k] = numStrToClearStr($values[$prefix . $k]); } $options[$k] = $values[$prefix . $k]; } } //$options['status'] = $values['type_deal']==1 ? REALTY_STATUS_NEW : REALTY_STATUS_RENT_NEW; $options['created_on'] = date('Y-m-d H:i:s'); $options['updated_on'] = $options['created_on']; $contacts_owner = isset($options['contacts']) ? $options['contacts'] : ''; // сохраним оригинальное значение контактов для включения в письмо if (!User::isGuest()) { $options['user_id'] = $_SESSION['user_id']; } else { // если пользователь - Гость нужно проверить - не подается ли объявление через агенство... $agent = self::getUserWhenAddByAgency(); // откорректируем некоторые поля, если обнаружен пользователь, через агенство которого подается объявление self::correctFieldsWhenAddByAgency($options, $agent); } //print_r($options);exit; $this->_vals = $options; $id = $this->create($options); $this->_vals['id'] = $id; // если установлен пользователь, через которого подавалось объявление - отправим ему письмо с уведомлением if (isset($agent)) { self::sendEmailNotifyAddByAgency($agent, $id, $contacts_owner); } }