<MyRusakov.ru />

Создание игр на Unreal Engine 5

Создание игр на Unreal Engine 5

Данный курс научит Вас созданию игр на Unreal Engine 5. Курс состоит из 12 модулей, в которых Вы с нуля освоите этот движок и сможете создавать самые разные игры.

В курсе Вы получите всю необходимую теоретическую часть, а также увидите массу практических примеров. Дополнительно, почти к каждому уроку идут упражнения для закрепления материала.

Помимо самого курса Вас ждёт ещё 8 бесплатных ценных Бонусов: «Chaos Destruction», «Разработка 2D-игры», «Динамическая смена дня и ночи», «Создание динамической погоды», «Создание искусственного интеллекта для NPC», «Создание игры под мобильные устройства», «Создание прототипа RPG с открытым миром» и и весь курс «Создание игр на Unreal Engine 4» (актуальный и в 5-й версии), включающий в себя ещё десятки часов видеоуроков.

Подробнее
Подписка

Подпишитесь на мой канал на YouTube, где я регулярно публикую новые видео.

YouTube Подписаться

Подписавшись по E-mail, Вы будете получать уведомления о новых статьях.

Подписка Подписаться

Добавляйтесь ко мне в друзья ВКонтакте! Отзывы о сайте и обо мне оставляйте в моей группе.

Мой аккаунт Мой аккаунт Моя группа
Опрос

Какая тема Вас интересует больше?

Форум сайта MyRusakov.ru

Ошибки Undefined variable в классе modules
08.03.2014 15:57:58 Ошибки Undefined variable в классе modules Сообщение #1
Nataly19910601

Nataly19910601

Новичок

Новичок

Дата регистрации:
08.03.2014 15:47:07

Сообщений: 2

Движок запускается, но в нем не выдаются никакие сообщения, не идет регистрация пользователей, включила отображения ошибок, выдал целый список. Пожалуйста помогите решить, уже неделю пытаюсь ничего не выходит

Notice: Undefined index: login in M:\home\test.local\www\lib\modules_class.php on line 43

Notice: Undefined index: password in M:\home\test.local\www\lib\modules_class.php on line 44

Notice: Undefined variable: field_out in M:\home\test.local\www\lib\database_class.php on line 88

Notice: Undefined variable: field_out in M:\home\test.local\www\lib\database_class.php on line 90

Notice: Undefined variable: text in M:\home\test.local\www\lib\modules_class.php on line 91

Notice: Undefined index: error_auth in M:\home\test.local\www\lib\modules_class.php on line 102

Notice: Undefined variable: text in M:\home\test.local\www\lib\modules_class.php on line 114

Notice: Undefined variable: db in M:\home\test.local\www\lib\modules_class.php on line 60

Notice: Undefined variable: field_in in M:\home\test.local\www\lib\database_class.php on line 102

Notice: Undefined variable: text in M:\home\test.local\www\lib\modules_class.php on line 72

Notice: Undefined variable: db in M:\home\test.local\www\lib\modules_class.php on line 61


modules_class.php
<?php
require_once "config_class.php";
require_once "article_class.php";
require_once "section_class.php";
require_once "user_class.php";
require_once "menu_class.php";
require_once "banner_class.php";
require_once "message_class.php";
require_once "poll_class.php";
require_once "pollvariant_class.php";

abstract class Modules {

protected $config;
protected $article;
protected $section;
protected $user;
protected $menu;
protected $banner;
protected $message;
protected $data;
protected $user_info;
protected $poll;
protected $poll_variant;

public function __construct($db) {
session_start();
$this->config = new Config();
$this->article = new Article($db);
$this->section = new Section($db);
$this->user = new User($db);
$this->menu = new Menu($db);
$this->banner = new Banner($db);
$this->message = new Message();
$this->data = $this->secureData($_GET);
$this->user_info = $this->getUser();
$this->poll = new Poll($db);
$this->poll_variant = new PollVariant($db);
}

private function getUser() {
$login = '';
$login = $_SESSION["login"];
$password = $_SESSION["password"];
$password = '';
if ($this->user->checkUser($login, $password)) return $this->user->getUserOnLogin($login);
else return false;
}

public function getContent() {
$sr["title"] = $this->getTitle();
$sr["meta_desc"] = $this->getDescription();
$sr["meta_key"] = $this->getKeyWords();
$sr["menu"] = $this->getMenu();
$sr["auth_user"] = $this->getAuthUser();
$sr["banners"] = $this->getBanners();
$sr["top"] = $this->getTop();
$sr["middle"] = $this->getMiddle();
$sr["bottom"] = $this->getBottom();
$sr["poll"] = $this->getPoll($db);
$sr["image"] = $this->getImage($db);
return $this->getReplaceTemplate($sr, "main";
}
private function getPoll() {
$poll = $this->poll->getRandomElement(1);
$poll = $poll[0];
$variants = $this->poll_variant->getAllOnPollID($poll["id"]);
$sr["title"] = $poll["title"];
for($i = 0; $i < count($variants); $i++) {
$new_sr["title"] = $variants[$i]["title"];
$new_sr["id"] = $variants[$i]["id"];
$text .= $this->getReplaceTemplate($new_sr, "poll_variant";
}

$sr["variants"] = $text;
return $this->getReplaceTemplate($sr, "poll";
}

abstract protected function getTitle();
abstract protected function getDescription();
abstract protected function getKeyWords();
abstract protected function getMiddle();
abstract protected function getImage();

protected function getMenu() {
$menu = $this->menu->getAll();
for ($i = 0; $i < count($menu); $i++) {
$sr["title"] = $menu[$i]["title"];
$sr["link"] = $menu[$i]["link"];
$sr["image"] = $menu[$i]["image"];
$text .= $this->getReplaceTemplate($sr, "menu_item";
}
return $text;
}

protected function getAuthUser() {

if ($this->user_info) {
$sr["username"] = $this->user_info["login"];
return $this->getReplaceTemplate($sr, "user_panel";
}
if ($_SESSION["error_auth"] ==1) {
$sr["message_auth"] = $this->getMessage("ERROR_AUTH";
unset($_SESSION["error_auth"]);
}
else $sr["message_auth"] = "";
return $this->getReplaceTemplate($sr, "form_auth";
}

protected function getBanners() {
$banners = $this->banner->getAll();
for ($i=0; $i < count($banners); $i++) {
$sr["code"] = $banners[$i]["code"];
$text .=$this->getReplaceTemplate($sr, "banner";
}
return $text;
}

protected function getTop() {
return "";
}

protected function getBottom() {
return "";
}

private function secureData($data) {
foreach($data as $key => $value) {
if (is_array($value)) $this->secureData($value);
else $data[$key] = htmlspecialchars($value);
}
return $data;
}

protected function getBlogArticles($articles, $page) {
$start = ($page - 1) * $this->config->count_blog;
$end = (count($articles) > $start + $this->config->count_blog)? $start + $this->config->count_blog: count($articles);
for ($i = $start; $i < $end; $i++) {
$sr["title"] = $articles[$i]["title"];
$sr["image"] = $articles[$i]["image"];
$sr["intro_text"] = $articles[$i]["intro_text"];
$sr["date"] = $this->formDate($articles[$i]["date"]);
$sr["link_article"] = $this->config->address."?view=article&amp;id=".$articles[$i]["id"];
$text .= $this->getReplaceTempLate($sr, "article_intro";
}
return $text;
}

protected function formDate($time) {
return date("Y-m-d H:i:s", $time);
}

protected function getMessage($message = "" {
$message = '';
if ($message = "" {
$message = $_SESSION["message"];
unset($_SESSION["message"]);
}
$sr["message"] = $this->message->getText($message);
return $this->getReplaceTemplate($sr, "message_string";
}

protected function getPagination($count, $count_on_page, $link) {
$count_pages = ceil($count / $count_on_page);
$sr["number"] = 1;
$sr["link"] = $link;
$pages = $this->getReplaceTempLate($sr, "number_page";
$sym = (strpos($link, "?" !== false)? "&amp;": "?";
for ($i = 2; $i <= $count_pages; $i++) {
$sr["number"] = $i;
$sr["link"] = $link.$sym."page=$i";
$pages .= $this->getReplaceTempLate($sr, "number_page";
}

$els["number_pages"] = $pages;
return $this->getReplaceTempLate($els, "pagination";
}

protected function getTemplate($name) {
$text = file_get_contents($this->config->dir_tmpl.$name.".tpl";
return str_replace("%address%", $this->config->address, $text);
}

protected function getReplaceTemplate($sr, $template) {
return $this->getReplaceContent($sr, $this->getTemplate($template));
}

private function getReplaceContent($sr, $content) {
$search = array();
$replace = array();
$i=0;
foreach ($sr as $key => $value) {
$search[$i] = "%$key%";
$replace[$i] = $value;
$i++;
}
return str_replace($search, $replace, $content);
}

protected function redirect($link) {
header("Location: $link";
exit;
}

protected function notFound() {
$this->redirect($this->config->address."?view=notfound";
}
}
?>


index.php
<?php
ini_set('display_errors','On');
error_reporting(E_ALL | E_STRICT);

mb_internal_encoding("UTF-8";
require_once "lib/database_class.php";
require_once "lib/frontpagecontent_class.php";
require_once "lib/sectioncontent_class.php";
require_once "lib/articlecontent_class.php";
require_once "lib/regcontent_class.php";
require_once "lib/messagecontent_class.php";
require_once "lib/searchcontent_class.php";
require_once "lib/notfoundcontent_class.php";
require_once "lib/pollcontent_class.php";

$db = new DataBase();
$view = $_GET["view"];
switch ($view) {
case "":
$content = new FrontPageContent($db);
break;
case "section":
$content = new SectionContent($db);
break;
case "article":
$content = new ArticleContent($db);
break;
case "reg":
$content = new RegContent($db);
break;
case "message":
$content = new MessageContent($db);
break;
case "search":
$content = new SearchContent($db);
break;
case "poll":
$content = new PollContent($db);
break;
default: $content = new NotFoundContent($db);
}

echo $content->getContent();
?>


database_class.php
<?php
require_once "config_class.php";
require_once "checkvalid_class.php";

class DataBase {

private $config;
private $mysqli;
private $valid;

public function __construct() {
$this->config = new Config();
$this->valid = new CheckValid();
$this->mysqli = new mysqli($this->config->host, $this->config->user, $this->config->password, $this->config->db);
$this->mysqli->query("SET NAMES 'utf8'";
}

private function query($query) {
return $this->mysqli->query($query);
}

private function select($table_name, $fields, $where= "", $order = "", $up = true, $limit = "" {
for ($i = 0; $i< count($fields); $i++) {
if ((strpos($fields[$i], "(" === false) && ($fields[$i] != "*") $fields[$i] = "`". $fields[$i] ."`";
}
$fields = implode(",", $fields);
$table_name = $this->config->db_prefix.$table_name;
if (!$order) $order = "ORDER BY `id`";
else {
if ($order != "RAND()" {
$order = "ORDER BY `$order`";
if (!$up) $order .= " DESC";
}
else $order = "ORDER BY $order";
}
if ($limit) $limit = "LIMIT $limit";
if ($where) $query = "SELECT $fields FROM $table_name WHERE $where $order $limit";
else $query = "SELECT $fields FROM $table_name $order $limit";
$result_set = $this->query($query);
if (!$result_set) return false;
$i = 0;
while ($row = $result_set->fetch_assoc()) {
$data[$i] = $row;
$i++;
}
$result_set->close();
return $data;
}

public function insert($table_name, $new_values) {
$table_name = $this->config->db_prefix.$table_name;
$query = "INSERT INTO $table_name (";
foreach ($new_values as $field => $value) $query.= "`".$field."`,";
$query = substr($query, 0, -1);
$query .= " VALUES (";
foreach ($new_values as $value) $query .= "'".addslashes($value)."'";
$query = substr($query, 0, -1);
$query .="";
return $this->query($query);
}
private function update($table_name, $upd_fields, $where) {
$table_name = $this->config->db_prefix.$table_name;
$query = "UPDATE $table_name SET";
foreach ($upd_fields as $field=> $value) $query .="`$field` = '".addslashes($value)."'";
$query = substr($query, 0, -1);
if ($where) {
$query .= "WHERE $where";
return $this->query($query);
}
else return false;
}

public function delete($table_name, $where = "" {
$table_name = $this->config->db_prefix.$table_name;
if(where) {
$query = "DELETE FROM $table_name WHERE $where";
return $this->query($query);
}
else return false;
}
public function deleteAll($table_name) {
$table_name = $this->config->db_prefix.$table_name;
$query = "TRUNCATE TABLE `$table_name`";
return $this->query($query);
}

public function getField($table_name, $filed_out, $field_in, $value_in) {
$data = $this->select($table_name, array($field_out), "`$field_in`='".addslashes($value_in)."'";
if (count($data) != 1) return false;
return $data[0][$field_out];
}
public function getFieldOnID($table_name, $id, $filed_out) {
if (!$this->existsID($table_name, $id)) return false;
return $this->getField($table_name, $field_out, "id", $id);
}

public function getAll($table_name, $order, $up) {
return $this->select($table_name, array("*", "", $order, $up);
}

public function getAllOnField($table_name, $field, $value, $order, $up) {
return $this->select($table_name, array("*", "`$field_in`='".addslashes($value)."'", $order, $up);
}

public function getLastID($table_name) {
$data = $this->select($table_name, array("MAX(`id`)");
return $data[0]["MAX(`id`)"];
}

public function deleteOnID($table_name, $id) {
if (!$this->existsID($table_name, $id)) return false;
return $this->delete($table_name, "`id` = '$id'";
}

public function setField ($table_name, $field, $value, $field_in, $value_in) {
return $this->update($table_name, array($field => $value), "`$field_in` = '".addslashes($value_in)."'";
}

public function setFieldOnID($table_name, $id, $field, $value) {
if (!$this->existsID($table_name, $id)) return false;
return $this->setField($table_name, $field, $value, "id", $id);
}

public function getElementOnID($table_name, $id) {
if (!$this->existsID($table_name, $id)) return false;
$arr = $this->select($table_name, array("*", "`id` = '$id'";
return $arr[0];
}

public function getRandomElements($table_name, $count) {
return $this->select($table_name, array("*", "", "RAND()", true, $count);
}

public function getCount($table_name) {
$data = $this->select($table_name, array("COUNT(`id`)");
return $data[0]["COUNT(`id`)"];
}

public function isExists($table_name, $field, $value) {
$data = $this->select($table_name, array("id", "`$field` = '".addslashes($value)."'";
if(count($data) === 0) return false;
return true;
}

private function existsID($table_name, $id) {
if (!$this->valid->validID($id)) return false;
$data = $this->select($table_name, array("id", "`id` = '".addslashes($id)."'";
if(count($data) === 0) return false;
return true;
}

public function search ($table_name, $words, $fields) {
$words = mb_strtolower($words);
$words = trim($words);
$words = quotemeta($words);
if ($words == "" return false;
$where = "";
$arraywords = explode(" ", $words);
$logic = "OR";

foreach ($arraywords as $key => $value) {
if (isset ($arraywords[$key - 1])) $where .= $logic;
for ($i = 0; $i<count($fields); $i++) {
$where .="`".$fields[$i]."` LIKE'%".addslashes($value)."%'";
if (($i+1) != count($fields)) $where .= "OR";
}
}
$results = $this->select($table_name, array("*", $where);
if (!$results) return false;
$k = 0;
$data = array();
for ($i = 0; $i <count($results); $i++) {
for ($j = 0; $j <count($fields); $j++) {
$results[$i][$fields[$j]] = mb_strtolower(strip_tags($results[$i][$fields[$j]]));
}
$data[$k] = $results[$i];
$data[$k]["relevant"] = $this->getRelevantForSearch($results[$i], $fields, $words);
$k++;
}
$data = $this->orderResultSearch($data, "relevant";
return $data;
}

private function getRelevantForSearch($result, $fields, $words) {
$relevant = 0;
$arraywords = explode(" ", $words);
for ($i = 0; $i < count($fields); $i++) {
for ($j = 0; $j < count($arraywords); $j++) {
$relevant += substr_count($results[$fields[$i]], $arraywords[$j]);
}
}
return $relevant;
}

private function orderResultSearch($data, $order) {
for ($i = 0; $i <count($data) - 1; $i++) {
$k = $i;
for ($j = $i +1;$j<count($data); $j++) {
if($data[$j][$order] > $data[$k][$order]) $k = $j;
}
$temp = $data[$k];
$data[$k] = $data[$i];
$data[$i] = $temp;
}
return $data;
}

public function __destruct() {
if ($this->mysqli) $this->mysqli->close();
}
}
?>


manage_class.php
<?php
require_once "config_class.php";
require_once "user_class.php";
require_once "poll_class.php";
require_once "pollvariant_class.php";

class Manage {

private $config;
private $user;
private $data;
public function __construct($db) {
session_start();
$this->config = new Config();
$this->user = new User($db);
$this->poll = new Poll($db);
$this->poll_variant = new PollVariant($db);
$this->data = $this->secureData(array_merge($_POST,$_GET));
}

private function secureData($data) {
foreach($data as $key => $value) {
if (is_array($value)) $this->secureData($value);
else $data[$key] = htmlspecialchars($value);
}
return $data;
}

public function redirect($link) {
header("Location: $link";
exit;
}

public function regUser() {
$link_reg = $this->config->address."?view=reg";
$captcha = $this->data["captcha"];
if (($_SESSION["rand"] != $captcha) && ($_SESSION["rand"] != "") {
return $this->returnMessage("ERROR_CAPTCHA", $link_reg);
}
$login = $this->data["login"];
if($this->user->isExistsLogin($login)) return $this->returnMessage("EXISTS_LOGIN", $link_reg);
$password = $this->data["password"];
if ($password == "" return $this->unknownError($link_reg);
$password = $this->hashPassword($password);
$result = $this->user->addUser($login, $password, time());
if ($result) return $this->returnPageMessage("SUCCESS_REG", $this->config->address."?view=message";
else return $this->unknownERROR($link_reg);
}

public function login() {
$login = $this->data["login"];
$password = $this->data["password"];
$password = $this->hashPassword($password);
$r = $_SERVER["HTTP_REFERER"];
if ($this->user->checkUser($login, $password)) {
$_SESSION["login"] = $login;
$_SESSION["password"] = $password;
return $r;
}
else {
$_SESSION["error_auth"] = 1;
return $r;
}
}

public function logout() {
unset($_SESSION["login"]);
unset($_SESSION["password"]);
return $_SERVER["HTTP_REFERER"];
}

public function poll() {
$id = $this->data["variant"];
$variant = $this->poll_variant->get($id);
$poll_id = $variant["poll_id"];
$this->poll_variant->setVotes($id, $variant["votes"] + 1);
return $this->config->address."?view=poll&id=$poll_id";
}

private function hashPassword($password) {
return md5($password.$this->config->secret);
}



private function unknownError($r) {
return $this->returnMessage("UNKNOWN_ERROR", $r);
}

private function returnMessage($message, $r) {
$_SESSION["message"] = $message;
return $r;
}

private function returnPageMessage($message, $r) {
$_SESSION["page_message"] = $message;
return $r;
}
}
?>
Профиль
10.03.2014 14:30:09 Ошибки Undefined variable в классе modules Сообщение #2
Avery

Avery

Освоившийся

Освоившийся

Дата регистрации:
05.05.2013 15:48:09

Сообщений: 37

Идем по порядку:
1.
Notice: Undefined index: login in M:\home\test.local\www\lib\modules_class.php on line 43.

Он не может найти переменные в сессии.
Код исправен, сессия пустая.
2.
Notice: Undefined index: password in M:\home\test.local\www\lib\modules_class.php on line 44.

Тоже самое.
3.
Notice: Undefined variable: field_out in M:\home\test.local\www\lib\database_class.php on line 88

Косяк в объявлении аргумента функции.
Вместо $field_out написано $filed_out.
Фикс: заменить код функции GetFiled на строке 88 на этот:
public function getField($table_name, $field_out, $field_in, $value_in) {
$data = $this->select($table_name, array($field_out), "`$field_in`='".addslashes($value_in)."'";
if (count($data) != 1) return false;
return $data[0][$field_out];
}

4.
Notice: Undefined variable: field_out in M:\home\test.local\www\lib\database_class.php on line 90

Тот же косяк, фикс тот же
5, 7, 10 .
Notice: Undefined variable: text in M:\home\test.local\www\lib\modules_class.php on line 91; Notice: Undefined variable: text in M:\home\test.local\www\lib\modules_class.php on line 114 ; Notice: Undefined variable: text in M:\home\test.local\www\lib\modules_class.php on line 72

Переменная $text необъявлена. Дописать в начало функций getMenu, getBanners, getPoll переменную $text;
6.
Notice: Undefined index: error_auth in M:\home\test.local\www\lib\modules_class.php on line 102
Пустая сессия
8, 11 переменной db нету.
9.Переменной $field_in просто нету.
Переустановите движок с офф. сайта и учитесь искать ошибки!!!!!!!!!
Профиль
10.03.2014 23:41:38 Ошибки Undefined variable в классе modules Сообщение #3
LLIMATKO

LLIMATKO

Эксперт

Эксперт

Дата регистрации:
12.02.2013 15:31:03

Сообщений: 129

не поленился же человек и посмотрел ваш код))
лично я даже не читаю столько кода, кажется человек не пробовал через известные методы найти свою ошибку - ну поюзайте echo и print_r .... офигенный метод
Профиль
11.03.2014 13:16:21 Ошибки Undefined variable в классе modules Сообщение #4
Nataly19910601

Nataly19910601

Новичок

Новичок

Дата регистрации:
08.03.2014 15:47:07

Сообщений: 2

Спасибо за советы, я новичок и поэтому не все ошибки могу сама решить.
Denwer и так был с официального сайта, но я переустановила, решила часть ошибок,но не знаю почему сессии пустые(

Notice: Undefined index: view in M:\home\test.local\www\index.php on line 18
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at M:\home\test.local\www\index.php:18) in M:\home\test.local\www\lib\modules_class.php on line 28

Notice: Undefined index: login in M:\home\test.local\www\lib\modules_class.php on line 43

Notice: Undefined index: password in M:\home\test.local\www\lib\modules_class.php on line 44

Notice: Undefined variable: data in M:\home\test.local\www\lib\database_class.php on line 50

Notice: Undefined index: error_auth in M:\home\test.local\www\lib\modules_class.php on line 103

index.php
<?php
ini_set('display_errors','On');
error_reporting(E_ALL | E_STRICT);

mb_internal_encoding("UTF-8";
require_once "lib/database_class.php";
require_once "lib/frontpagecontent_class.php";
require_once "lib/sectioncontent_class.php";
require_once "lib/articlecontent_class.php";
require_once "lib/regcontent_class.php";
require_once "lib/messagecontent_class.php";
require_once "lib/searchcontent_class.php";
require_once "lib/notfoundcontent_class.php";
require_once "lib/pollcontent_class.php";


$db = new DataBase();
$view = $_GET["view"];
switch ($view) {
case "":
$content = new FrontPageContent($db);
break;
case "section":
$content = new SectionContent($db);
break;
case "article":
$content = new ArticleContent($db);
break;
case "reg":
$content = new RegContent($db);
break;
case "message":
$content = new MessageContent($db);
break;
case "search":
$content = new SearchContent($db);
break;
case "poll":
$content = new PollContent($db);
break;
default: $content = new NotFoundContent($db);
}

echo $content->getContent();
?>


modules_class.php
<?php
require_once "config_class.php";
require_once "article_class.php";
require_once "section_class.php";
require_once "user_class.php";
require_once "menu_class.php";
require_once "banner_class.php";
require_once "message_class.php";
require_once "poll_class.php";
require_once "pollvariant_class.php";

abstract class Modules {

protected $config;
protected $article;
protected $section;
protected $user;
protected $menu;
protected $banner;
protected $message;
protected $data;
protected $user_info;
protected $poll;
protected $poll_variant;


public function __construct($db) {
session_start();
$this->config = new Config();
$this->article = new Article($db);
$this->section = new Section($db);
$this->user = new User($db);
$this->menu = new Menu($db);
$this->banner = new Banner($db);
$this->message = new Message();
$this->data = $this->secureData($_GET);
$this->user_info = $this->getUser();
$this->poll = new Poll($db);
$this->poll_variant = new PollVariant($db);
}

private function getUser() {
$login = $_SESSION["login"];
$password = $_SESSION["password"];
if ($this->user->checkUser($login, $password)) return $this->user->getUserOnLogin($login);
else return false;
}

public function getContent() {
$sr["title"] = $this->getTitle();
$sr["meta_desc"] = $this->getDescription();
$sr["meta_key"] = $this->getKeyWords();
$sr["menu"] = $this->getMenu();
$sr["auth_user"] = $this->getAuthUser();
$sr["banners"] = $this->getBanners();
$sr["top"] = $this->getTop();
$sr["middle"] = $this->getMiddle();
$sr["bottom"] = $this->getBottom();
$sr["poll"] = $this->getPoll();
$sr["image"] = $this->getImage();
return $this->getReplaceTemplate($sr, "main";
}
private function getPoll() {
$text = "";
$poll = $this->poll->getRandomElement(1);
$poll = $poll[0];
$variants = $this->poll_variant->getAllOnPollID($poll["id"]);
$sr["title"] = $poll["title"];
for($i = 0; $i < count($variants); $i++) {
$new_sr["title"] = $variants[$i]["title"];
$new_sr["id"] = $variants[$i]["id"];
$text .= $this->getReplaceTemplate($new_sr, "poll_variant";
}

$sr["variants"] = $text;
return $this->getReplaceTemplate($sr, "poll";
}

abstract protected function getTitle();
abstract protected function getDescription();
abstract protected function getKeyWords();
abstract protected function getMiddle();
abstract protected function getImage();

protected function getMenu() {
$text = "";
$menu = $this->menu->getAll();
for ($i = 0; $i < count($menu); $i++) {
$sr["title"] = $menu[$i]["title"];
$sr["link"] = $menu[$i]["link"];
$sr["image"] = $menu[$i]["image"];
$text .= $this->getReplaceTemplate($sr, "menu_item";
}
return $text;
}

protected function getAuthUser() {

if ($this->user_info) {
$sr["username"] = $this->user_info["login"];
return $this->getReplaceTemplate($sr, "user_panel";
}
if ($_SESSION["error_auth"] ==1) {
$sr["message_auth"] = $this->getMessage("ERROR_AUTH";
unset($_SESSION["error_auth"]);
}
else $sr["message_auth"] = "";
return $this->getReplaceTemplate($sr, "form_auth";
}

protected function getBanners() {
$text = "";
$banners = $this->banner->getAll();
for ($i=0; $i < count($banners); $i++) {
$sr["code"] = $banners[$i]["code"];
$text .=$this->getReplaceTemplate($sr, "banner";
}
return $text;
}

protected function getTop() {
return "";
}

protected function getBottom() {
return "";
}

private function secureData($data) {
foreach($data as $key => $value) {
if (is_array($value)) $this->secureData($value);
else $data[$key] = htmlspecialchars($value);
}
return $data;
}

protected function getBlogArticles($articles, $page) {
$text="";
$start = ($page - 1) * $this->config->count_blog;
$end = (count($articles) > $start + $this->config->count_blog)? $start + $this->config->count_blog: count($articles);
for ($i = $start; $i < $end; $i++) {
$sr["title"] = $articles[$i]["title"];
$sr["image"] = $articles[$i]["image"];
$sr["intro_text"] = $articles[$i]["intro_text"];
$sr["date"] = $this->formDate($articles[$i]["date"]);
$sr["link_article"] = $this->config->address."?view=article&amp;id=".$articles[$i]["id"];
$text .= $this->getReplaceTempLate($sr, "article_intro";
}
return $text;
}

protected function formDate($time) {
return date("Y-m-d H:i:s", $time);
}

protected function getMessage($message = "" {
$message = "";
if ($message = "" {
$message = $_SESSION["message"];
unset($_SESSION["message"]);
}
$sr["message"] = $this->message->getText($message);
return $this->getReplaceTemplate($sr, "message_string";
}

protected function getPagination($count, $count_on_page, $link) {
$count_pages = ceil($count / $count_on_page);
$sr["number"] = 1;
$sr["link"] = $link;
$pages = $this->getReplaceTempLate($sr, "number_page";
$sym = (strpos($link, "?" !== false)? "&amp;": "?";
for ($i = 2; $i <= $count_pages; $i++) {
$sr["number"] = $i;
$sr["link"] = $link.$sym."page=$i";
$pages .= $this->getReplaceTempLate($sr, "number_page";
}

$els["number_pages"] = $pages;
return $this->getReplaceTempLate($els, "pagination";
}

protected function getTemplate($name) {
$text = file_get_contents($this->config->dir_tmpl.$name.".tpl";
return str_replace("%address%", $this->config->address, $text);
}

protected function getReplaceTemplate($sr, $template) {
return $this->getReplaceContent($sr, $this->getTemplate($template));
}

private function getReplaceContent($sr, $content) {
$search = array();
$replace = array();
$i=0;
foreach ($sr as $key => $value) {
$search[$i] = "%$key%";
$replace[$i] = $value;
$i++;
}
return str_replace($search, $replace, $content);
}

protected function redirect($link) {
header("Location: $link";
exit;
}

protected function notFound() {
$this->redirect($this->config->address."?view=notfound";
}
}
?>


database_class.php
<?php
require_once "config_class.php";
require_once "checkvalid_class.php";

class DataBase {

private $config;
private $mysqli;
private $valid;



public function __construct() {
$this->config = new Config();
$this->valid = new CheckValid();
$this->mysqli = new mysqli($this->config->host, $this->config->user, $this->config->password, $this->config->db);
$this->mysqli->query("SET NAMES 'utf8'";
}


private function query($query) {
return $this->mysqli->query($query);
}

private function select($table_name, $fields, $where= "", $order = "", $up = true, $limit = "" {
for ($i = 0; $i< count($fields); $i++) {
if ((strpos($fields[$i], "(" === false) && ($fields[$i] != "*") $fields[$i] = "`". $fields[$i] ."`";
}
$fields = implode(",", $fields);
$table_name = $this->config->db_prefix.$table_name;
if (!$order) $order = "ORDER BY `id`";
else {
if ($order != "RAND()" {
$order = "ORDER BY `$order`";
if (!$up) $order .= " DESC";
}
else $order = "ORDER BY $order";
}
if ($limit) $limit = "LIMIT $limit";
if ($where) $query = "SELECT $fields FROM $table_name WHERE $where $order $limit";
else $query = "SELECT $fields FROM $table_name $order $limit";
$result_set = $this->query($query);
if (!$result_set) return false;
$i = 0;
while ($row = $result_set->fetch_assoc()) {
$data[$i] = $row;
$i++;
}
$result_set->close();
return $data;
}

public function insert($table_name, $new_values) {
$table_name = $this->config->db_prefix.$table_name;
$query = "INSERT INTO $table_name (";
foreach ($new_values as $field => $value) $query.= "`".$field."`,";
$query = substr($query, 0, -1);
$query .= " VALUES (";
foreach ($new_values as $value) $query .= "'".addslashes($value)."'";
$query = substr($query, 0, -1);
$query .="";
return $this->query($query);
}
private function update($table_name, $upd_fields, $where) {
$table_name = $this->config->db_prefix.$table_name;
$query = "UPDATE $table_name SET";
foreach ($upd_fields as $field=> $value) $query .="`$field` = '".addslashes($value)."'";
$query = substr($query, 0, -1);
if ($where) {
$query .= "WHERE $where";
return $this->query($query);
}
else return false;
}

public function delete($table_name, $where = "" {
$table_name = $this->config->db_prefix.$table_name;
if(where) {
$query = "DELETE FROM $table_name WHERE $where";
return $this->query($query);
}
else return false;
}
public function deleteAll($table_name) {
$table_name = $this->config->db_prefix.$table_name;
$query = "TRUNCATE TABLE `$table_name`";
return $this->query($query);
}

public function getField($table_name, $field_out, $field_in, $value_in) {
$data = $this->select($table_name, array($field_out), "`$field_in`='".addslashes($value_in)."'";
if (count($data) != 1) return false;
return $data[0][$field_out];
}
public function getFieldOnID($table_name, $id, $field_out) {
if (!$this->existsID($table_name, $id)) return false;
return $this->getField($table_name, $field_out, "id", $id);
}

public function getAll($table_name, $order, $up) {
return $this->select($table_name, array("*", "", $order, $up);
}

public function getAllOnField($table_name, $field_in, $value, $order, $up) {
return $this->select($table_name, array("*", "`$field_in`='".addslashes($value)."'", $order, $up);
}

public function getLastID($table_name) {
$data = $this->select($table_name, array("MAX(`id`)");
return $data[0]["MAX(`id`)"];
}

public function deleteOnID($table_name, $id) {
if (!$this->existsID($table_name, $id)) return false;
return $this->delete($table_name, "`id` = '$id'";
}

public function setField ($table_name, $field, $value, $field_in, $value_in) {
return $this->update($table_name, array($field => $value), "`$field_in` = '".addslashes($value_in)."'";
}

public function setFieldOnID($table_name, $id, $field, $value) {
if (!$this->existsID($table_name, $id)) return false;
return $this->setField($table_name, $field, $value, "id", $id);
}

public function getElementOnID($table_name, $id) {
if (!$this->existsID($table_name, $id)) return false;
$arr = $this->select($table_name, array("*", "`id` = '$id'";
return $arr[0];
}

public function getRandomElements($table_name, $count) {
return $this->select($table_name, array("*", "", "RAND()", true, $count);
}

public function getCount($table_name) {
$data = $this->select($table_name, array("COUNT(`id`)");
return $data[0]["COUNT(`id`)"];
}

public function isExists($table_name, $field, $value) {
$data = $this->select($table_name, array("id", "`$field` = '".addslashes($value)."'";
if(count($data) === 0) return false;
return true;
}

private function existsID($table_name, $id) {
if (!$this->valid->validID($id)) return false;
$data = $this->select($table_name, array("id", "`id` = '".addslashes($id)."'";
if(count($data) === 0) return false;
return true;
}

public function search ($table_name, $words, $fields) {
$words = mb_strtolower($words);
$words = trim($words);
$words = quotemeta($words);
if ($words == "" return false;
$where = "";
$arraywords = explode(" ", $words);
$logic = "OR";

foreach ($arraywords as $key => $value) {
if (isset ($arraywords[$key - 1])) $where .= $logic;
for ($i = 0; $i<count($fields); $i++) {
$where .="`".$fields[$i]."` LIKE'%".addslashes($value)."%'";
if (($i+1) != count($fields)) $where .= "OR";
}
}
$results = $this->select($table_name, array("*", $where);
if (!$results) return false;
$k = 0;
$data = array();
for ($i = 0; $i <count($results); $i++) {
for ($j = 0; $j <count($fields); $j++) {
$results[$i][$fields[$j]] = mb_strtolower(strip_tags($results[$i][$fields[$j]]));
}
$data[$k] = $results[$i];
$data[$k]["relevant"] = $this->getRelevantForSearch($results[$i], $fields, $words);
$k++;
}
$data = $this->orderResultSearch($data, "relevant";
return $data;
}

private function getRelevantForSearch($result, $fields, $words) {
$relevant = 0;
$arraywords = explode(" ", $words);
for ($i = 0; $i < count($fields); $i++) {
for ($j = 0; $j < count($arraywords); $j++) {
$relevant += substr_count($results[$fields[$i]], $arraywords[$j]);
}
}
return $relevant;
}

private function orderResultSearch($data, $order) {
for ($i = 0; $i <count($data) - 1; $i++) {
$k = $i;
for ($j = $i +1;$j<count($data); $j++) {
if($data[$j][$order] > $data[$k][$order]) $k = $j;
}
$temp = $data[$k];
$data[$k] = $data[$i];
$data[$i] = $temp;
}
return $data;
}

public function __destruct() {
if ($this->mysqli) $this->mysqli->close();
}
}
?>
Профиль
11.03.2014 17:15:40 Ошибки Undefined variable в классе modules Сообщение #5
Avery

Avery

Освоившийся

Освоившийся

Дата регистрации:
05.05.2013 15:48:09

Сообщений: 37

Я имел ввиду не denwer, а скрипты которые вы выложили, видно что это скачано. Если они ваши, вы должны сначала в сессию эти значения занести, а потом уж получать. Так же при получении значений из GET/POST/Cokkie/Сессий нужно проверять существуют они или нет с помощью функции isset(var).
P.S.
Notice: Undefined variable: data in M:\home\test.local\www\lib\database_class.php on line 50

Тут обращение к несуществующей переменной login на строке 50.
Профиль