Код переписан для большего удобства.
Отдельно вынесены header и footer. Убран ненужный путь admin. Управление пользователями убрано, так как нужен лишь админ.
This commit is contained in:
parent
43d5576f61
commit
44f3a586d7
|
@ -22,7 +22,7 @@ else
|
|||
* @see http://kohanaframework.org/guide/using.configuration
|
||||
* @see http://php.net/timezones
|
||||
*/
|
||||
date_default_timezone_set('Asia/Krasnoyarsk');
|
||||
date_default_timezone_set('Asia/Novosibirsk');
|
||||
|
||||
/**
|
||||
* Set the default locale.
|
||||
|
@ -114,11 +114,6 @@ Kohana::modules(array(
|
|||
* defaults for the URI.
|
||||
*/
|
||||
|
||||
Route::set('admin', 'admin/<controller>(/<action>(/<id>))')->defaults(array(
|
||||
'directory' => 'admin',
|
||||
'controller' => 'pages',
|
||||
'action' => 'view'
|
||||
));
|
||||
Route::set('default', '(<controller>(/<action>(/<id>)))')
|
||||
->defaults(array(
|
||||
'controller' => 'page',
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Controller_Admin extends Controller_Admin_Pages {
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Controller_Admin_Users extends Controller_Template {
|
||||
public $template = 'admin/users/view';
|
||||
protected $auth;
|
||||
protected $user;
|
||||
public function before() {
|
||||
parent::before();
|
||||
$this->auth = Auth::instance();
|
||||
$this->user = $this->auth->get_user();
|
||||
$this->session= Session::instance();
|
||||
if ($this->auth->logged_in()){
|
||||
if ($this->auth->logged_in(array('admin')) === FALSE) $this->template->error = "Недостаточно прав для внесения изменений.";
|
||||
}
|
||||
else{
|
||||
$this->template->error = "Вы не зашли в систему.";
|
||||
if ($this->request->action() != 'login') $this->request->redirect('admin/users/login');
|
||||
}
|
||||
}
|
||||
|
||||
public function action_view(){
|
||||
$this->template->users = ORM::factory('user')->find_all()->as_array('id');
|
||||
}
|
||||
public function action_login() {
|
||||
$this->template = new View('admin/users/login');
|
||||
|
||||
if($this->auth->logged_in()) return $this->request->redirect('admin/pages/view');
|
||||
if ($_POST){
|
||||
$user = ORM::factory('user');
|
||||
$status = $this->auth->login($_POST['login'], $_POST['password']);
|
||||
if ($status) $this->request->redirect('admin/pages/view');
|
||||
else $this->template->error = "Неверный логин или пароль.";
|
||||
}
|
||||
}
|
||||
public function action_logout() {
|
||||
if ($this->auth->logout()) return $this->request->redirect('admin/users/login');
|
||||
else $this->template->error = "Ошибка выхода пользователя.";
|
||||
}
|
||||
public function action_register() {
|
||||
$this->template = new View('admin/users/register');
|
||||
if ($_POST){
|
||||
$model = ORM::factory('user');
|
||||
$model->values(array(
|
||||
'username' => $_POST['login'],
|
||||
'email' => $_POST['email'],
|
||||
'password' => $_POST['password'],
|
||||
'password_confirm' => $_POST['password_confirm'],
|
||||
));
|
||||
try {
|
||||
$model->save();
|
||||
$model->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
|
||||
$this->request->redirect('admin/users');
|
||||
}
|
||||
catch (ORM_Validation_Exception $e){
|
||||
$this->template->error = "Ошибка проверки данных.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
10
application/classes/controller/footer.php
Normal file
10
application/classes/controller/footer.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Controller_Footer extends Controller_Template {
|
||||
public $template = 'footer';
|
||||
public function action_standard() {
|
||||
$this->template->years = Kohana::config('common.this_year');
|
||||
if (date('Y') > Kohana::config('common.this_year')) $this->template->years = Kohana::config('common.this_year') . date('-Y');
|
||||
}
|
||||
public function action_view(){$this->request->redirect('');}
|
||||
}
|
27
application/classes/controller/header.php
Normal file
27
application/classes/controller/header.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Controller_Header extends Controller_Template {
|
||||
public $template = 'header';
|
||||
public function action_standard() {
|
||||
$this->template->title = $this->request->post('title');
|
||||
$styles = $this->request->post('styles');
|
||||
$scripts = $this->request->post('scripts');
|
||||
$temp = "";
|
||||
if (is_array($styles)){
|
||||
foreach($styles as $style=>$media):
|
||||
if ($media != 'screen' and $media != 'print'){
|
||||
$style=$media;
|
||||
$media="screen";
|
||||
}
|
||||
$temp .= '<link rel="stylesheet" type="text/css" media="'. $media .'" href="'.URL::site('assets/css/'.$style).'">'."\n";
|
||||
endforeach;
|
||||
$this->template->styles = $temp;
|
||||
}
|
||||
else $this->template->styles = '<link rel="stylesheet" type="text/css" media="screen" href="'.URL::site('assets/css/'.$styles)."\">\n";
|
||||
if (is_array($scripts)) foreach($scripts as $script):
|
||||
$temp .= '<script type="text/javascript" charset="utf-8" src="'.URL::site('assets/javascript/'.$script).'"></script>'."\n";
|
||||
endforeach;
|
||||
$this->template->scripts = $temp;
|
||||
}
|
||||
public function action_view(){$this->request->redirect('');}
|
||||
}
|
20
application/classes/controller/login.php
Normal file
20
application/classes/controller/login.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Controller_Login extends Controller_Template {
|
||||
public $template = 'login';
|
||||
public function action_view() {
|
||||
if(Auth::instance()->logged_in()){
|
||||
if (Auth::instance()->logged_in(array('admin')) === FALSE) return $this->request->redirect('pages/view');
|
||||
return $this->request->redirect('');
|
||||
}
|
||||
if ($_POST){
|
||||
$user = ORM::factory('user');
|
||||
$status = Auth::instance()->login($_POST['login'], $_POST['password']);
|
||||
if ($status){
|
||||
if (Auth::instance()->logged_in(array('admin')) === FALSE) return $this->request->redirect('pages/view');
|
||||
return $this->request->redirect('');
|
||||
}
|
||||
else $this->template->error = "Неверный логин или пароль.";
|
||||
}
|
||||
}
|
||||
}
|
8
application/classes/controller/logout.php
Normal file
8
application/classes/controller/logout.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Controller_Logout extends Controller {
|
||||
public function action_view() {
|
||||
if (Auth::instance()->logout()) return $this->request->redirect('login');
|
||||
else $this->template->error = "Ошибка выхода пользователя.";
|
||||
}
|
||||
}
|
|
@ -1,10 +1,17 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Controller_Navigation extends Controller_Template {
|
||||
public $template = 'navigation';
|
||||
public function action_standard() {
|
||||
$page = new Model_Page();
|
||||
$this->template->pages = ORM::factory('page')->where('id','>','1')->order_by('order','ASC')->find_all()->as_array('id');
|
||||
public $template = 'navigation/actions';
|
||||
public function action_actions() {
|
||||
$this->template = new View('navigation/actions');
|
||||
$this->template->login_or_logout = HTML::anchor('login', 'Вход');
|
||||
if (Auth::instance()->logged_in()){
|
||||
$this->template->login_or_logout = HTML::anchor('logout', 'Выход');
|
||||
}
|
||||
if (Auth::instance()->logged_in('admin')){
|
||||
$this->template->admin_actions = View::factory('navigation/admin')->render();
|
||||
}
|
||||
$this->template->pages = ORM::factory('page')->where('id','>',1)->find_all();
|
||||
}
|
||||
public function action_view(){$this->request->redirect('');}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Controller_Admin_Pages extends Controller_Template {
|
||||
public $template = 'admin/pages/view';
|
||||
class Controller_Pages extends Controller_Template {
|
||||
public $template = 'pages/view';
|
||||
protected $auth;
|
||||
protected $user;
|
||||
public function before() {
|
||||
|
@ -14,14 +14,14 @@ class Controller_Admin_Pages extends Controller_Template {
|
|||
}
|
||||
else{
|
||||
$this->template->error = "Вы не зашли в систему.";
|
||||
$this->request->redirect('admin/users/login');
|
||||
$this->request->redirect('login');
|
||||
}
|
||||
}
|
||||
public function action_view(){
|
||||
$this->template->pages = ORM::factory('page')->find_all()->as_array('id');
|
||||
}
|
||||
public function action_add() {
|
||||
$this->template = new View('admin/pages/add');
|
||||
$this->template = new View('pages/add');
|
||||
$page = new Model_Page;
|
||||
$message = "";
|
||||
$error = "";
|
||||
|
@ -58,7 +58,7 @@ class Controller_Admin_Pages extends Controller_Template {
|
|||
};
|
||||
}
|
||||
public function action_edit() {
|
||||
$this->template = new View('admin/pages/edit');
|
||||
$this->template = new View('pages/edit');
|
||||
$page = new Model_Page($this->request->param('id'));
|
||||
if($_POST){
|
||||
$page->name = Arr::get($_POST, 'name', '');
|
||||
|
@ -67,7 +67,7 @@ class Controller_Admin_Pages extends Controller_Template {
|
|||
try{
|
||||
$page->save();
|
||||
$this->template->message = 'Страница сохранена.';
|
||||
$this->request->redirect('admin/pages');
|
||||
$this->request->redirect('pages');
|
||||
}
|
||||
catch(ORM_Validation_Exception $e){
|
||||
$error = "Ошибка проверки данных.";
|
||||
|
@ -84,7 +84,7 @@ class Controller_Admin_Pages extends Controller_Template {
|
|||
$this->template->message = $message;
|
||||
}
|
||||
public function action_delete() {
|
||||
$this->template = new View('admin/pages/delete');
|
||||
$this->template = new View('pages/delete');
|
||||
$page = new Model_Page($this->request->param('id'));
|
||||
$this->template->name = $page->name;
|
||||
$this->template->content = $page->content;
|
6
application/config/common.php
Normal file
6
application/config/common.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
|
||||
return array(
|
||||
'this_year' => "2011",
|
||||
'title' => ""
|
||||
);
|
|
@ -1,20 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Аутентификация пользователя</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="/assets/css/admin.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="error"><?php if(!empty($error)) echo $error;?></div>
|
||||
<div id="message"><?php if(!empty($message)) echo $message;?></div>
|
||||
<p id="greeting">Введите логин и пароль для получения доступа к разделу.</p>
|
||||
<div id="login_form">
|
||||
<?php echo form::open('admin/users/login') ?>
|
||||
<p><?php echo form::label('login','Логин: '); echo form::input('login','') ?></p>
|
||||
<p><?php echo form::label('password','Пароль: '); echo form::password('password','') ?></p>
|
||||
<p><?php echo form::submit('submit','Отправить') ?></p>
|
||||
<?php echo form::close() ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,20 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Регистрация пользователя</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="/assets/css/admin.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="error"><?php if(!empty($error)) echo $error;?></div>
|
||||
<div id="message"><?php if(!empty($message)) echo $message;?></div>
|
||||
<?php echo form::open('admin/users/register') ?>
|
||||
<p><?php echo form::label('login','Логин: '); echo form::input('login','') ?></p>
|
||||
<p><?php echo form::label('password','Пароль: '); echo form::password('password','') ?></p>
|
||||
<p><?php echo form::label('password_confirm','Подтверждение пароля: '); echo form::password('password_confirm','') ?></p>
|
||||
<p><?php echo form::label('email','E-mail: '); echo form::input('email','') ?></p>
|
||||
<p><?php echo form::submit('submit','Отправить') ?>
|
||||
</p>
|
||||
<?php echo form::close() ?>
|
||||
</body>
|
||||
</html>
|
|
@ -1,27 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Обзор пользователей</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="/assets/css/admin.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="error"><?php if(!empty($error)) echo $error;?></div>
|
||||
<div id="message"><?php if(!empty($message)) echo $message;?></div>
|
||||
|
||||
<table border="1" width="100%">
|
||||
<thead><tr><td>ID</td><td>Логин</td></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach($users as $id=>$user):?>
|
||||
<tr>
|
||||
<td><?php echo $user->id;?></td><td><?php echo $user->username;?></td>
|
||||
</tr>
|
||||
<?php endforeach;?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p><a href="/admin/users/register">Зарегистрировать пользователя</a></p>
|
||||
<p><a href="/admin/users/logout">Разлогиниться</a></p>
|
||||
<img id="image">
|
||||
</body>
|
||||
</html>
|
4
application/views/error.php
Normal file
4
application/views/error.php
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?php echo Request::factory('header/standard')->post('title',$title)->post('styles','main.css')->execute() ?>
|
||||
<h1><?php echo $title?></h1>
|
||||
<p><?php echo $description?></p>
|
||||
<?php echo Request::factory('footer/standard')->execute() ?>
|
5
application/views/footer.php
Normal file
5
application/views/footer.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
</div>
|
||||
<div id="footer">© Студия Гид <?php echo $years ?></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
19
application/views/header.php
Normal file
19
application/views/header.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title><?php echo $title ?></title>
|
||||
<meta charset="utf-8">
|
||||
<?php echo $styles ?>
|
||||
<?php echo $scripts ?>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main_container">
|
||||
<?php if (Kohana::config('common.title') != '') { ?>
|
||||
<div id="header">
|
||||
<h1><?php echo Kohana::config('common.title')?></h1>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div id="menu">
|
||||
<?php echo Request::factory('navigation/actions')->execute() ?>
|
||||
</div>
|
||||
<div id="column_text">
|
12
application/views/login.php
Normal file
12
application/views/login.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php echo Request::factory('header/standard')->post('title',"Вход в систему")->post('styles','page.css')->execute() ?>
|
||||
|
||||
<div id="error"><?php if(!empty($error)) echo $error;?></div>
|
||||
<div id="message"><?php if(!empty($message)) echo $message;?></div>
|
||||
<p>Введите логин и пароль для получения доступа к разделу.</p>
|
||||
<?php echo form::open('login') ?>
|
||||
<p><?php echo form::label('login','Логин: '); echo form::input('login','') ?></p>
|
||||
<p><?php echo form::label('password','Пароль: '); echo form::password('password','') ?></p>
|
||||
<p><?php echo form::submit('submit','Отправить') ?>
|
||||
</p>
|
||||
<?php echo form::close() ?>
|
||||
<?php echo Request::factory('footer/standard')->execute() ?>
|
|
@ -1,5 +0,0 @@
|
|||
<ul>
|
||||
<?php foreach($pages as $id=>$page):?>
|
||||
<li><a href="/page/view/<?php echo $id;?>"><?php echo $page->name;?></a></li>
|
||||
<?php endforeach;?>
|
||||
</ul>
|
9
application/views/navigation/actions.php
Normal file
9
application/views/navigation/actions.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<ul>
|
||||
<?php foreach ($pages as $page){ ?>
|
||||
<li><?php echo $page->name ?></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<ul>
|
||||
<?php if (isset($admin_actions)) echo $admin_actions;?>
|
||||
<li><?php echo $login_or_logout; ?></li>
|
||||
</ul>
|
1
application/views/navigation/admin.php
Normal file
1
application/views/navigation/admin.php
Normal file
|
@ -0,0 +1 @@
|
|||
<li><?php echo HTML::anchor('pages', 'Страницы'); ?></li>
|
|
@ -1,25 +1,3 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<link href='http://fonts.googleapis.com/css?family=PT+Sans:regular,bold&subset=cyrillic,latin' rel='stylesheet' type='text/css'>
|
||||
<title><?php echo $title; ?></title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="/assets/css/page.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="main_container">
|
||||
<div id="logo_big"></div>
|
||||
<div id="menu">
|
||||
<?php echo Request::factory('navigation/standard')->execute() ?>
|
||||
</div>
|
||||
<div id="column_text">
|
||||
<?php echo Request::factory('header/standard')->post('title',$title)->post('styles','page.css')->execute() ?>
|
||||
<?php echo $content; ?>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div id="copyright">© <?php echo $years ?></div>
|
||||
<div id="logo_small"></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php echo Request::factory('footer/standard')->execute() ?>
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
body{
|
||||
background-color: #9ab4ca;
|
||||
background-image: url('/assets/images/admin.svg');
|
||||
background-size: 100%;
|
||||
color: blue;
|
||||
font-size: large;
|
||||
margin: 1em;
|
||||
}
|
||||
#login_form{
|
||||
top: 1em;
|
||||
right: 1em;
|
||||
left: 1em;
|
||||
position: absolute;
|
||||
text-align: center;
|
||||
}
|
||||
#login_form p{
|
||||
display: inline;
|
||||
}
|
||||
#greeting{
|
||||
bottom: 1em;
|
||||
margin-top: 70%;
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
text-align: center;
|
||||
}
|
||||
#error{
|
||||
color: #a60000;
|
||||
background: #ffd4d4;
|
||||
margin: 1em;
|
||||
font-weight: bold;
|
||||
padding-left: 1em;
|
||||
height: auto;
|
||||
}
|
||||
table{
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
text-align: center;
|
||||
width: 70%;
|
||||
background: #tf70d8;
|
||||
}
|
||||
thead{
|
||||
background: #4188d2;
|
||||
}
|
||||
a, a:visited{
|
||||
color: #edfd3f;
|
||||
}
|
||||
input, textarea{
|
||||
width: 15em;
|
||||
background: #04376c;
|
||||
color: #e5fb00;
|
||||
border: none;
|
||||
margin-left: 1em;
|
||||
padding: 1em;
|
||||
}
|
||||
input[type="submit"]{
|
||||
margin: 1em auto;
|
||||
width: 10em;
|
||||
}
|
||||
#image{
|
||||
position: absolute;
|
||||
bottom: 1em;
|
||||
right: 1em;
|
||||
width: 256px;
|
||||
height: 256px;
|
||||
background-image: url('/assets/images/gift14.png');
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
#image_edit{
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: url('/assets/images/pencil3.png');
|
||||
background-size: 100%;
|
||||
}
|
||||
#image_delete{
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: url('/assets/images/deletered.png');
|
||||
background-size: 100%;
|
||||
}
|
|
@ -3,48 +3,36 @@ body{
|
|||
color: #ffffff;
|
||||
font-family: 'PT Sans', arial, serif;
|
||||
}
|
||||
#main_container{
|
||||
min-height: 100%;
|
||||
}
|
||||
#menu{
|
||||
right: 0;
|
||||
position: absolute;
|
||||
width: 20%;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
#header h1{
|
||||
text-align: center;
|
||||
}
|
||||
#menu a{
|
||||
text-decoration: none;
|
||||
}
|
||||
#column_text{
|
||||
right: 20%;
|
||||
left: 20%;
|
||||
position: absolute;
|
||||
text-align: justify;
|
||||
width: 60%;
|
||||
margin: 1em 1%;
|
||||
padding: 0;
|
||||
}
|
||||
#copyright{
|
||||
right: 2em;
|
||||
bottom: 1em;
|
||||
position: absolute;
|
||||
}
|
||||
#cite{
|
||||
float: right;
|
||||
width: 40%;
|
||||
}
|
||||
a, a:visited{
|
||||
color: #ffffff;
|
||||
}
|
||||
#logo_big{
|
||||
top:0px;
|
||||
left:0px;
|
||||
position: absolute;
|
||||
width: 20%;
|
||||
#main_container{
|
||||
clear:left;
|
||||
margin: 1em 5%;
|
||||
}
|
||||
#header{
|
||||
text-align: center;
|
||||
border-bottom: 1px solid #fff;
|
||||
}
|
||||
#menu{
|
||||
float: right;
|
||||
width: 160px;
|
||||
margin-right: 10px;
|
||||
padding-top: 1em;
|
||||
}
|
||||
#column_text{
|
||||
padding-top: 1em;
|
||||
margin: 0 200px 0 2em;
|
||||
}
|
||||
#footer{
|
||||
height: 150px;
|
||||
clear: both;
|
||||
width: 100%;
|
||||
clear: both;
|
||||
margin-top: 1em;
|
||||
text-align: right;
|
||||
border-top: 1px solid #fff;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue