. \css\stylesheetadmin. CSS. \aplication\classes\adminverification. PHP. \aplication\classes\childrenbefore. PHP. \aplication\classes\exception404. PHP
.. \css\stylesheetadmin. css @charset " UTF-8"; body { margin: 0px; padding: 0px; min-height: 800px; min-width: 1024px; background-attachment: scroll; background-image: url(.. /img/background.jpg); background-repeat: repeat-x; background-position: left top; } #content_container { position: relative; margin: 0 auto; width: 900px; min-height: 550px; background-attachment: scroll; background-image: none; background-repeat: no-repeat; background-position: right center; } #logo_container { height: 90px; width: 900px; margin: 0 auto; min-width: 900px; } #main_container { height: 70px; width: 900px; margin: 0 auto; } #logo_image { width: 255px; height: 75px; margin-left: 10px; margin-top: 15px; float: left; background-image: url(.. /img/logo.png); } #top_bar_black { width: 100%; height: 90px; background-color: #000000; } #bottom_bar_black { width: 100%; height: 80px; background-color: #000000; } #nav_block { width: 500px; height: 90px; float: right; } . nav_button { color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; font-style: italic; font-size: 12px; margin-left: 15px; margin-top: 35px; text-align: center; float: left; } a: hover{ font-style: normal; font-weight: bold; color: #fff; } a { text-decoration: none; font-style: italic; font-weight: normal; color: #fff; font-family: Verdana, Arial, Helvetica, sans-serif; font-style: italic; font-size: 12px; } #header { width: 500px; margin-top: 50px; margin-bottom: 250px; float: left; } . header_content_mainline { font-size: 35px; color: #000000; width: 500px; font-style: italic; } #header_content_boxline { font-size: 35px; color: #000000; width: 400px; font-style: italic; } #header_content_lowerline { font-size: 35px; color: #FFFFFF; width: 400px; font-style: italic; } #header_content_boxcontent { font-size: 12px; color: #333333; width: 400px; font-style: italic; } #header_content_lowerboxcontent { font-size: 12px; color: #CCCCCC; width: 400px; } #header_content_tagline { font-size: 12px; color: #333333; width: 500px; } #header_lower { width: 400px; float: left; margin-right: 40px; margin-bottom: 50px; } #copywriteblock { margin: 10px auto; width: 900px; color: #333333; font-size: 10px; font-family: verdana; text-align: right; text-decoration: none; } #copywriteblock a{ color: #222; } #copywriteblock a: hover{ color: #555; } #clear{clear: both; } input{ padding: 0 10px; margin: 5px; } .. \aplication\classes\adminverification. php <? php defined('SYSPATH') or die('No direct script access. '); class Adminverification extends Controller_Template { public function before() { $session = Session:: instance(); $session-> set('auth_redirect', $_SERVER['REQUEST_URI']);
$auth=Auth:: instance(); if($auth-> logged_in() == 0 ) Request:: initial()-> redirect('authformer'); if($auth-> logged_in('admin') == 0 ) Request:: initial()-> redirect('netprav'); return parent:: before(); } } .. \aplication\classes\childrenbefore. php <? php defined('SYSPATH') or die('No direct script access. '); class Childrenbefore extends Controller_Template { public function before() { $session = Session:: instance(); // Создание эземпляра класса Session на основе метода Instance $session-> set('auth_redirect', $_SERVER['REQUEST_URI']); // запись в переменную session методом set страницы которую хотел посетить пользователь $auth=Auth:: instance(); // объявление экземпляра класса авторизации if($auth-> logged_in() == 0) Request:: initial()-> redirect('authformer'); // если пользователь не авторизован переадресовать его на страницу авторизации return parent:: before(); } } .. \aplication\classes\exception404. php <? php defined('SYSPATH') or die('No direct script access. '); class Exception404 { public static function handle(Exception $e) // На вход приходит ошибка { switch (get_class($e)) { case 'HTTP_Exception_404': // сравнивается с 404 $response = new Response; $response-> status(404); // в статус сервера 404 $view = new View('404view'); // использовать вид view404 $view-> message = $e-> getMessage(); // записать в переменную $message сообщение из контроллера materials -- throw new HTTP_Exception_404('Страница не найдена! '); echo $response-> body($view)-> send_headers()-> body(); // генерация отображения return TRUE; break; default: // если не 404 обрабатывать стандартными методами Kohana return Kohana_Exception:: handler($e); break; }
} } .. \aplication\classes\loginverification. php <? php defined('SYSPATH') or die('No direct script access. '); class Loginverification extends Controller_Template { public function before() { $session = Session:: instance(); $session-> set('auth_redirect', $_SERVER['REQUEST_URI']); $auth=Auth:: instance(); if($auth-> logged_in() == 0 ) Request:: initial()-> redirect('authformer'); return parent:: before(); } } .. \aplication\classes\nstree. php (готовый модуль для работы категорий) <? php defined('SYSPATH') or die('No direct script access. '); /* CREATE TABLE `tree` ( `id` INT(10) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `left_key` INT(10) NOT NULL, `right_key` INT(10) NOT NULL, `level` INT(10) NOT NULL, PRIMARY KEY (`id`), INDEX `key` (`left_key`, `right_key`, `level`) ) COLLATE='utf8_general_ci' ENGINE=InnoDB */ class NSTree { protected $table = NULL; public function __construct($tablename) { $this-> table = $tablename; } // Модифицирует ключи protected function modifyNodes($key, $delta) { $query = 'UPDATE '. Database:: instance()-> quote_table($this-> table). ' SET right_key = right_key + '. (int)$delta. ' WHERE right_key > = '. (int)$key; DB:: query(Database:: UPDATE, $query)-> execute(); $query = 'UPDATE '. Database:: instance()-> quote_table($this-> table). ' SET left_key = left_key + '. (int)$delta. ' WHERE left_key > = '. (int)$key; DB:: query(Database:: UPDATE, $query)-> execute(); } public function getNode($id) { $result = DB:: select() -> from($this-> table) -> where('id', '=', $id) -> execute(); if (count($result) == 0) throw new Exception('Node id='. $id. ' does not exist. '); return $result-> current(); } public function clear($extrafields=array()) { if (! is_array($extrafields)) throw new Exception('$extrafields must be array. '); DB:: query(NULL, 'TRUNCATE '. Database:: instance()-> quote_table($this-> table))-> execute(); DB:: delete($this-> table)-> execute(); $data = array( 'id' => 1, 'name' => '< root> ', 'left_key' => 1, 'right_key' => 2, 'level' => 0
); $data = $data + $extrafields; list($insert_id, $tmp) = DB:: insert($this-> table, array_keys($data))-> values(array_values($data))-> execute(); return $insert_id; } public function getTree($id=NULL) { $id = (int) $id; $QTblName = Database:: instance()-> quote_table($this-> table); if ($id! = 0) { $node = $this-> getNode($id); $query = 'SELECT * FROM '. $QTblName. ' WHERE left_key > = '. (int)$node['left_key']. ' AND right_key < = '. (int)$node['right_key']. ' ORDER BY left_key'; } else { $query = 'SELECT * FROM '. $QTblName. ' ORDER BY left_key'; } $result = DB:: query(Database:: SELECT, $query)-> execute(); return $result; } public function getPath($id) { $node = $this-> getNode($id); $query = 'SELECT * FROM '. Database:: instance()-> quote_table($this-> table). ' WHERE right_key > '. (int)$node['left_key']. ' AND left_key < '. (int)$node['right_key']. ' ORDER BY left_key'; $result = DB:: query(Database:: SELECT, $query)-> execute(); return $result; } public function insert($id, $extrafields=array()) { if (! is_array($extrafields)) throw new Exception('$extrafields must be array. '); // Находим родителя $parent = $this-> getNode($id); DB:: query(NULL, 'START TRANSACTION')-> execute(); // Обновляем ключи существующего дерева, узлы стоящие за родительским узлом $this-> modifyNodes((int)$parent['right_key'], 2); // Добавляем новый узел
$node = array( 'id' => NULL, 'left_key' => $parent['right_key'], 'right_key' => $parent['right_key'] + 1, 'level' => $parent['level'] + 1 ); $node = $node + $extrafields; list($insert_id, $tmp) = DB:: insert($this-> table, array_keys($node))-> values(array_values($node))-> execute(); DB:: query(NULL, 'COMMIT')-> execute(); return $insert_id; } public function delete($id) { $node = $this-> getNode($id); DB:: query(NULL, 'START TRANSACTION')-> execute(); // Удаляем узел (вместе с веткой) $query = 'DELETE FROM '. Database:: instance()-> quote_table($this-> table). ' WHERE left_key > = '. (int)$node['left_key']. ' AND right_key < = '. (int)$node['right_key']; DB:: query(Database:: DELETE, $query)-> execute(); $width = $node['right_key'] - $node['left_key'] + 1; // Обновление последующих узлов $this-> modifyNodes((int)$node['right_key'], -$width); DB:: query(NULL, 'COMMIT')-> execute(); } // Метод перемещает ноду $id в родительскую ноду $parentId public function move($id, $parentId) { $node = $this-> getNode($id); DB:: query(NULL, 'START TRANSACTION')-> execute(); // Удаляем узел (вместе с веткой) $query = 'DELETE FROM '. Database:: instance()-> quote_table($this-> table). ' WHERE left_key > = '. (int)$node['left_key']. ' AND right_key < = '. (int)$node['right_key']; DB:: query(Database:: DELETE, $query)-> execute();
$width = $node['right_key'] - $node['left_key'] + 1; // Обновление последующих узлов $this-> modifyNodes((int)$node['right_key'], -$width);
// DB:: query(NULL, 'COMMIT')-> execute(); } public function check($thorough=FALSE) { $QTblName = Database:: instance()-> quote_table($this-> table); // Тест 1 $query = 'SELECT id FROM '. $QTblName. ' WHERE MOD(right_key - left_key, 2) = 0'; $result = DB:: query(Database:: SELECT, $query)-> execute(); if (count($result)! = 0) throw new Exception('Test 1 integrity check failed. '); // Тест 2 $query = 'SELECT id FROM '. $QTblName. ' WHERE MOD(left_key - level + 2, 2) = 0'; $result = DB:: query(Database:: SELECT, $query)-> execute(); if (count($result)! = 0)
throw new Exception('Test 2 integrity check failed. '); // Тест 3 if ($thorough) { $query = 'SELECT t1. id, COUNT(t1. id) AS rep, MAX(t3. right_key) AS max_right FROM '. $QTblName. ' AS t1, '. $QTblName. ' AS t2, '. $QTblName. ' AS t3 WHERE t1. left_key < > t2. left_key AND t1. left_key < > t2. right_key AND t1. right_key < > t2. left_key AND t1. right_key < > t2. right_key GROUP BY t1. id HAVING max_right < > SQRT( 4 * rep + 1 ) + 1';
$result = DB:: query(Database:: SELECT, $query)-> execute();
if (count($result)! = 0) throw new Exception('Test 3 integrity check failed. '); } // Тест 4, проверка level $query = 'SELECT node. id as id, node. level as level FROM '. $QTblName. ' AS node, '. $QTblName. ' AS parent WHERE node. left_key BETWEEN parent. left_key AND parent. right_key GROUP BY node. id HAVING COUNT(parent. name) - 1! = level ORDER BY node. left_key'; $result = DB:: query(Database:: SELECT, $query)-> execute(); if (count($result)! = 0) throw new Exception('Test 4 integrity check failed. '); } }
Воспользуйтесь поиском по сайту: ©2015 - 2025 megalektsii.ru Все авторские права принадлежат авторам лекционных материалов. Обратная связь с нами...
|