/
index.php
100 lines (70 loc) · 3.37 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
ini_set('display_errors', 1);
header('Content-type: text/html; charset=utf-8');
// проводим настройки смарти
$project_root = $_SERVER['DOCUMENT_ROOT'];
$smarty_dir = $project_root . '/smarty/';
// put full path to Smarty.class.php
require('smarty/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->compile_check = true; //true;
$smarty->debugging = FALSE; //FALSE;
$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';
// определение функций
include 'functions.php';
// загрузка данных из фала server_name,user_name, password, database
$filename = './User.txt';
if (file_exists($filename)) {
$temp_str = file_get_contents('./User.txt');
if (isset($temp_str)) {
$User = unserialize(file_get_contents('./User.txt')); // действие в случае удачи
} else {
?><a href="instal.php">Проверьте введенные данные</a><?php
exit('Ошибка чтения файла'); // или другое действие при неудачном чтении файла
//header("Location: instal.php");
}
}
//подключение к серверу SQL
$bd = @mysqli_connect($User['server_name'], $User['user_name'], $User['password'], $User['database']) or die('<a href="instal.php">проверьте введеные данные</a> - Сервер недоступен');
mysqli_query($bd, 'SET NAMES utf8');
$Location = basename($_SERVER['PHP_SELF']);
//добавленых объявления в массив
if (isset($_POST['main_form_submit'])) {
$post_date = $_POST;
if (isset($_GET['id'])) { //изменение объявления ID в БД
$id = $_GET['id'];
sql_UPDATE($bd, $id, $post_date);
} else { //иначе запись нового объявления в БД
sql_INSERT($bd, $post_date);
}
header("Location: $Location");
exit;
}
if ($_GET == TRUE) { //варианты действий при получении данных в GET
if (isset($_GET['id_del'])) { //удаление объявления id из БД с ID = $id_del
$id_del = $_GET['id_del'];
sql_DELETE($bd, $id_del);
header("Location: $Location");
exit;
}
if (isset($_GET['id'])) { // передача переменных в шаблон
$id_key = $_GET['id'];
$smarty->assign('id_key', $id_key);
$smarty->assign('save', 'Сохранить изменения');
$Announcements = translation_table_form_in_array_Announcements($bd);
}
}
//подключение таблиц городов и категорий
$location = translation_table_sity_in_array_location($bd);
$category = translation_table_category_in_array_category($bd);
$Announcements = translation_table_form_in_array_Announcements($bd); //подключение таблицы заполненных форм
//передача массивов в шаблон
$smarty->assign('Location', basename($_SERVER['PHP_SELF']));
$smarty->assign('location', $location);
$smarty->assign('category', $category);
$smarty->assign('Announcements', $Announcements);
$smarty->display('index.tpl');