public static function instance() { if (self::$instance == NULL) { self::$instance = new AdsStore(); } return self::$instance; }
header("Content-Type: text/html; charset=utf-8"); $project_root = $_SERVER['DOCUMENT_ROOT']; $smarty_dir = $project_root . '/Smarty/'; require_once "connect_to_db.php"; //подключаемся к самой БД require_once "bd_script.php"; //подключаем файл со скриптами для БД // подключаем smarty $smarty_dir = 'Smarty/'; require $smarty_dir . 'libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->compile_check = TRUE; $smarty->debugging = 0; $smarty->template_dir = $smarty_dir . 'templates/'; $smarty->compile_dir = $smarty_dir . 'templates_c/'; $smarty->cache_dir = $smarty_dir . 'cache/'; $smarty->config_dir = $smarty_dir . 'configs/'; //Подключаем классы spl_autoload_register(function ($class) { $class_path = 'lib/' . $class . '.class.php'; if (file_exists($class_path)) { require_once $class_path; } }); $adsStore = AdsStore::instance(); $adsStore->getAllAdsFromDb(); $errors = new errors(array('title', 'description', 'price', 'seller_name', 'phone')); //передаем 'имя переменной' и 'значение' $smarty->assign('title', 'Наше объявление'); $smarty->assign('city', $adsStore->getlocationid()); $smarty->assign('category', $adsStore->getCategories());
public static function getInstance() { // Создаем экземпляр AdsStore if (self::$instance == NULL) { self::$instance = new AdsStore(); } return self::$instance; }
<?php require_once "prepare.php"; AdsStore::instance()->getAllAdsFromDb()->prepareForOut()->display();
$firePHP->log($tube_stations, '$tube_stations'); $category_id = ''; $result = $db->select('select * from categories order by id ASC'); $firePHP->log($result, 'categories $result'); foreach ($result as $value) { $result2 = $db->select('select * from subcategories where category=' . $value['id'] . ' order by subcategory'); $firePHP->log($result2, 'subcategories $result2'); foreach ($result2 as $value2) { $subcategory[$value2['subcategory']] = $value2['id']; } $categories[$value['category']] = $subcategory; $subcategory = array(); } $firePHP->log($categories, '$categories'); // если гет заполнен, значит запросили изменение (в ходе просмотра) и удаление $main = AdsStore::instance(); $main->getAllAdsFromDb(); $main->writeOutAll(); if ($_POST['form'] == "Сохранить объявление") { // сохранить элемент // записать изменение в базу //$temp_array = $Ads1->change_ad($db, $_POST, $_GET["id"]); //$firePHP->log($temp_array, 'ads $temp_array'); $main->change_Ad($_GET['id']); $_POST = null; header('Location:' . $site_dir . '/' . $current_php_script . '.php'); } if ($_POST['form'] == "Назад") { $_POST = null; unset($_GET); header('Location:' . $site_dir . '/' . $current_php_script . '.php');
ob_start(); $smarty_root = __DIR__ . "/smarty/"; $project_root = __DIR__; require $smarty_root . 'libs/Smarty.class.php'; require_once $project_root . "/dbsimple/config.php"; require_once $project_root . "/dbsimple/DbSimple/Generic.php"; $smarty = new Smarty(); $smarty->compile_check = true; $smarty->debugging = false; $smarty->template_dir = $smarty_root . '/templates/'; $smarty->compile_dir = $smarty_root . '/templates_c/'; $db = DbSimple_Generic::connect('mysqli://*****:*****@127.0.0.1/ads'); $db->setErrorHandler('databaseErrorHandler'); $db->query("SET NAMES UTF8"); function databaseErrorHandler($message, $info) { if (!error_reporting()) { return; } echo "SQL Error: {$message}<br><pre>"; print_r($info); echo "</pre>"; exit; } $show = new AdsStore(); $city_array = $show->option('city', 'cities'); $category_array = $show->option('category', 'categories'); $type_array = $show->option('type', 'types'); $smarty->assign('city_array', $city_array); $smarty->assign('category_array', $category_array); $smarty->assign('type_array', $type_array);
<?php header("Content-type: text/html; Charset=utf-8"); require_once 'config.php'; require_once $project_root . '/lib/connection.php'; // Подключаем БД require $project_root . '/lib/ads_class.php'; // Подключаем файл с функциями // Создаем либо редактируем объявление if (isset($_POST['seller_name']) && isset($_POST['description'])) { // если была нажата кнопка $post_ad = Ads::trimPOST($_POST); $ad = new Ads($post_ad); $ad->saveAd(); header("Location: index.php"); exit; } // Удаление объявления if (isset($_GET['delete'])) { $del_id = (int) $_GET['delete']; Ads::delAdFromDb($del_id); } $instance = AdsStore::getInstance(); $instance->getAllAdsFromDb(); // Показ конкретного объявления if (isset($_GET['show'])) { $edit_id = (int) $_GET['show']; $instance->prepareForOutSingleAd($edit_id); } $instance->prepareForOutDataForm()->prepareForOutTableRow()->display();
<?php require_once "prepare.php"; if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete' && isset($_REQUEST['id'])) { // Кнопка "удалить" нажата? AdsStore::instance()->deleteAds($_REQUEST['id']); echo 'Объявление успешно удалено'; }
<?php require_once "prepare.php"; $adStore = AdsStore::instance()->getAllAdsFromDb(); if (isset($_POST['seller_name']) and isset($_POST['price'])) { // Кнопка 'Отправить' нажата? if ($_POST['private']) { $ad = new AdsCompany($_POST); } else { $ad = new AdsPrivatePerson($_POST); } $CheckResult = AdChecker::check($ad); if ($CheckResult) { // Проверка на заполнение полей $adStore->prepareForOut($ad, $CheckResult); // Если не пройдена - на корректировку } else { $ad->save(); // Иначе - сохранение $adStore->getAllAdsFromDb()->prepareForOut(); } } elseif (isset($_GET['id'])) { // Ссылка на объявление нажата? $adStore->prepareForOut($_GET['id']); } else { // Ничего не нажато - значит новое объявление $adStore->prepareForOut(); } $adStore->display();