Vasse
Новичок
Дата регистрации:
07.03.2016 22:08:34
Сообщений: 7
Ошибка заключается в том, что почему-то данные не отправляются в таблицу и не каких ошибок не появляется, хотя я всё с точностью и внимательно списывал. Страница просто обновляется.
И вторая ошибка вот такая, тоже долго с ней мучаюсь:
user_class.php
<?php
require_once "global_class.php";
class User extends GlobalClass {
public function __construct($db) {
parent::__construct("users", $db);
}
public function addUser($login, $password, $regdate) {
if (!$this->checkValid($login, $password, $regdate)) return false;
return $this->add(array("login" => $login, "password" => $password, "regdate" => $regdate));
}
public function editUser($id, $login, $password, $regdate) {
if (!$this->checkValid($login, $password, $regdate)) return false;
return $this->edit($id, array("login" => $login, "password" => $password, "regdate" => $regdate));
}
public function isExistsUser($login) { //onko login olemassa jo
return $this->isExists("login", $login);
}
public function checkUser($login, $password) {
$user = $this->getUserOnLogin($login);
if (!$user) return false;
return $user["password"] === $password;
}
public function getUserOnLogin($login) {
$id = $this->getField("id", "login", $login);
return $this->get($id);
}
private function checkValid($login, $password, $regdate) { //proverka na korrektnost
if (!$this->valid->validLogin($login)) return false;
if (!$this->valid->validHash($password)) return false;
if (!$this->valid->validTimeStamp($regdate)) return false;
return true;
}
}
?>
manage_class.php<?php
require_once "config_class.php";
require_once "user_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->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";
$login = $this->data["login"];
if ($this->user->isExistsUser($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"];
}
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;
}
}
?>
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 .= "`$shield` = '".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, $value, $order, $up) {
return $this->select($table_name, array("*", "`$field`='".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) { // Onko login olemassa
$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 __destruct () {
if ($this->mysqli) $this->mysqli->close();
}
}
?>
regcontent_class.php<?php
require_once "modules_class.php";
class RegContent extends Modules {
public function __construct($db) {
parent::__construct($db);
}
protected function getTitle() {
return "";
}
protected function getDescription() {
return "";
}
protected function getKeyWords() {
return "";
}
protected function getMiddle() {
$sr["message"] = $this->getMessage();
$sr["login"] = $_SESSION["login"];
return $this->getReplaceTemplate($sr, "form_reg"
}
}
?>
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 "email_class.php";
abstract class Modules {
protected $config;
protected $article;
protected $section;
protected $user;
protected $menu;
protected $banner;
protected $message;
protected $email;
protected $data;
protected $user_info;
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->email = new Email();
$this->data = $this->secureData($_GET);
$this->user_info = $this->getUser();
}
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();
return $this->getReplaceTemplate($sr, "main"
}
abstract protected function getTitle();
abstract protected function getDescription();
abstract protected function getKeyWords();
abstract protected function getMiddle();
protected function getMenu() {
$menu = $this->menu->getAll();
for ($i = 0; $i < count($menu); $i++) {
$sr["title"] = $menu[$i]["title"];
$sr["link"] = $menu[$i]["link"];
$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["intro_text"] = $articles[$i]["intro_text"];
$sr["date"] = $this->formatDate($articles[$i]["date"]);
$sr["link_article"] = $this->config->address."?view=article&id=".$articles[$i]["id"];
$text .=$this->getReplaceTemplate($sr, "article_intro"
}
return $text;
}
protected function formatDate($time) {
return date("Y-m-d H:i:s", $time);
}
protected function getMessage($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)? "&": "?";
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);
}
}
?>
Заранее всем огромное спасибо за помощь и ваше потраченное время.