public static function instance() { if (self::$instance === NULL) { self::$instance = new AdStorage(); } return self::$instance; }
$id = !empty($_POST['id']) ? $_POST['id'] : null; if ($_POST['type'] === 'private') { $ad = new AdPrivate($_POST); } else { $ad = new AdCompany($_POST); } $resultFromSaveAd = $ad->save($db); $row = AdStorage::instance()->getAdFromDb($db, $id)->writeOut($smarty); $resultFromSaveAd['row'] = $row; echo json_encode($resultFromSaveAd); die; } $citys = HtmlOption::getCitys($db); $categories = HtmlOption::getCategories($db); $smarty->assign('category', $categories); $smarty->assign('city', $citys); $smarty->assign('ads_radios', array('private' => 'Частное объявление', 'company' => 'Объявление Компании')); if (!empty($_GET['action']) && $_GET['action'] === 'edit') { $adForEdit = AdStorage::instance()->getAdFromDb($db, $_GET['id'])->getAdFromStorage($_GET['id']); $adForEditArray = $adForEdit->objectToArray(); $adForEditArray['main_form_submit'] = 'Сохранить'; echo json_encode($adForEditArray); die; } $rows = AdStorage::instance()->getAllAdsFromDb($db)->writeOut($smarty); $smarty->assign('ads_rows', $rows); $smarty->assign('ads_single', new AdPrivate()); $smarty->display('index.tpl'); ?>