refactor code to new code igniter. Remove all models because of useless

parent 34572266
configuration.php
/nbproject
gi
\ No newline at end of file
......@@ -132,4 +132,4 @@ $autoload['language'] = array();
|
| $autoload['model'] = array('first_model' => 'first');
*/
$autoload['model'] = array('mdl_views', 'mdl_post', 'mdl_query', 'mdl_search', 'mdl_session', 'mdl_authorized', 'mdl_menu');
$autoload['model'] = array();
......@@ -23,7 +23,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = 'http://typos.server.ambulance.sandbox.eterhost.ru/cp/';
$config['base_url'] = 'http://ambulance.sandbox.eterhost.ru/typos.server/new_cp/';
/*
|--------------------------------------------------------------------------
......@@ -35,7 +35,7 @@ $config['base_url'] = 'http://typos.server.ambulance.sandbox.eterhost.ru/cp/';
| variable so that it is blank.
|
*/
$config['index_page'] = 'index.php';
$config['index_page'] = '';
/*
|--------------------------------------------------------------------------
......@@ -114,7 +114,7 @@ $config['enable_hooks'] = true;
| https://codeigniter.com/user_guide/general/creating_libraries.html
|
*/
$config['subclass_prefix'] = 'MY_';
$config['subclass_prefix'] = 'Typos_';
/*
|--------------------------------------------------------------------------
......
......@@ -73,13 +73,14 @@ defined('BASEPATH') OR exit('No direct script access allowed');
$active_group = 'default';
$query_builder = TRUE;
// Default group can be loaded by $this->load->database()
$db['default'] = array(
'dsn' => '',
'dsn' => 'mysql:host=localhost; dbname=barbass_typos_new; charset=utf8;',
'hostname' => 'localhost',
'username' => 'ambulance',
'password' => 'ambulanceetersoft',
'database' => 'barbass_typos_new',
'dbdriver' => 'mysql',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
......
......@@ -49,6 +49,4 @@ defined('BASEPATH') OR exit('No direct script access allowed');
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['default_controller'] = 'authorization';
\ No newline at end of file
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Authorization extends CI_Controller {
/**
* Contains common data
* @var type array
*/
private $data;
/**
* View name for this controller
* @var type string
*/
private $view_name;
function __construct() {
parent::__construct();
$this->data['auth_url'] = $this->config->base_url()."authorization/check";
$this->view_name = 'authorization/index';
$this->load->model('user');
}
function index() {
$this->load->view($this->view_name, $this->data);
}
function check() {
if (!$this->check_login_error()) {
$this->data['error_message'] = "Вы превысили число попыток";
$this->load->view($this->view_name, $this->data);
return;
}
$username = $this->input->post('username');
$password = $this->input->post('password');
if ($username == "" || $password == "") {
$this->data['error_message'] = "Логин/пароль пустой";
$this->load->view($this->view_name, $this->data);
return;
}
/* Look for admin account information in config/typos_config*/
if ($this->config->item('typos_admin_login') &&
$this->config->item('typos_admin_password') &&
$this->config->item('typos_admin_email')) {
if ($username == $this->config->item('typos_admin_login') &&
$password == $this->config->item('typos_admin_password')) {
$this->session->login = $username;
$this->session->usertype = 'admin';
$this->session->email = $this->config->item('typos_admin_email');
$this->session->login_id = -1;
redirect('admins/sites/');
}
}
$user_info = $this->user->getUser($username);
$password = $this->user->hashPassword($password);
echo var_dump($user_info);
if (!$user_info) {
$this->error_login();
$this->data['error_message'] = "Пароль/логин не верен";
$this->load->view($this->view_name, $this->data);
return;
} else {
if ($password == $user_info->password) {
if (intval($user_info->activity) == 1) {
$loginData = array(
'login' => $username,
'usertype' => $user_info->type,
'email' => $user_info->email,
'login_id' => $user_info->id,
'firstname' => $user_info->firstname,
'lastname' => $user_info->lastname,
'middlename' => $user_info->middlename,
);
$this->session->set_userdata($loginData);
/*Перенаправлям в зависимости от типа пользователя*/
if ($user_info->type == 'admin') {
redirect('admins/sites/');
} else if ($user_info->type == 'user') {
redirect('users/typos/');
}
}
} else {
$this->error_login();
$this->data['error_message'] = "Пароль/логин не верен";
$this->load->view($this->view_name, $this->data);
return;
}
}
}
function logout() {
$this->session->sess_destroy();
unset($_SESSION);
redirect ("authorized");
}
/*Устанавливаем счетчики ошибок входа*/
function error_login() {
$this->session->set_userdata('error_login', intval($this->session->error_login_count) + 1);
$this->session->set_userdata('error_login_time', time());
}
function check_login_error() {
if (!$this->session->error_login) {
return true;
} else {
$count_error = intval($this->session->userdata('error_login'));
$config_count = $this->config->item('error_login_count');
if (!$config_count) {
$config_count = 3;
}
$config_time = $this->config->item('error_login_time');
if (!$config_time) {
$config_time = 10000;
}
$time_error = time() - intval($this->session->error_login_time);
/*Если время бана прошло, обнуляем*/
if ($time_error > $config_time) {
$this->session->error_login_count = null;
return true;
}
if ($time_error <= $config_time && $count_error >= $config_count) {
return false;
} else {
return true;
}
}
}
}
/**/
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->view('welcome_message');
}
}
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*Работа с сайтами - администратор*/
class Sites extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('admins/mdl_sites');
$this->login_id = $this->mdl_session->get_data('login_id');
$this->usertype = $this->mdl_session->get_data('usertype');
if ($this->usertype != 'admin') {
redirect('users/typos');
}
}
/*Создаем шаблон*/
function index() {
$views['body']['url'] = "admins/sites";
$views['menu']['url'] = "menu";
$views['menu']['data']['items'] = $this->mdl_menu->admin();
$this->mdl_views->view($views);
return true;
}
function typos() {
$this->index();
return;
}
/*Получить сайты*/
function get_list_sites() {
$data['page'] = $this->mdl_post->int('page');
$data['limit'] = $this->mdl_post->int('rows', 1);
$data['sord'] = $this->mdl_post->string('sord');
$data['sidx'] = $this->mdl_post->string('sidx');
$data['search'] = $this->mdl_post->string('_search');
$data['searchField'] = $this->mdl_post->string('searchField');
$data['searchOper'] = $this->mdl_post->string('searchOper');
$data['searchString'] = $this->mdl_post->string('searchString');
$data['login_id'] = $this->login_id;
echo json_encode($this->mdl_sites->get_list_sites($data));
}
/*Получить пользователей по сайту*/
function get_list_users() {
$data['id_site'] = $this->mdl_post->int("id");
$data['page'] = $this->mdl_post->int('page');
$data['limit'] = $this->mdl_post->int('rows', 1);
$data['sord'] = $this->mdl_post->string('sord');
$data['sidx'] = $this->mdl_post->string('sidx');
$data['search'] = $this->mdl_post->string('_search');
$data['searchField'] = $this->mdl_post->string('searchField');
$data['searchOper'] = $this->mdl_post->string('searchOper');
$data['searchString'] = $this->mdl_post->string('searchString');
$data['login_id'] = $this->login_id;
echo json_encode($this->mdl_sites->get_list_users($data));
}
/*Управление сайтами*/
function panel_sites() {
$oper = $this->mdl_post->string('oper');
if ($oper == 'add') {
$data['site'] = $this->mdl_post->string('site');
if ($data['site'] == '') {
echo json_encode(array('message' => 'Название сайта некорректно'));
} else {
$return = $this->mdl_sites->add_site($data);
if ($return) {
echo json_encode($return);
}
}
return true;
} else if ($oper == 'edit') {
$data['id_site'] = $this->mdl_post->int('id');
$data['site'] = $this->mdl_post->string('site');
if ($data['site'] == '') {
echo json_encode(array('message' => 'Название сайта некорректно'));
} else {
$return = $this->mdl_sites->edit_site($data);
if ($return) {
echo json_encode($return);
}
}
return true;
} else if ($oper == 'del') {
$data['id_site'] = $this->mdl_post->int('id');
if (!$this->mdl_sites->delete_site($data)) {
echo json_encode(array('message' => 'Сайт нельзя удалить. Количество пользователей не равно 0'));
}
return true;
}
}
function panel_users() {
$oper = $this->mdl_post->string('oper');
if ($oper == 'del') {
$this->load->model('admins/mdl_users');
$data['id_user'] = $this->mdl_post->int('id');
$data['id_site'] = $this->mdl_post->int('id_site');
$this->mdl_users->delete_responsible($data);
}
}
}
/**/
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*Работа с пользователями - администратор*/
class Users extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('admins/mdl_users');
$this->login_id = $this->mdl_session->get_data('login_id');
$this->usertype = $this->mdl_session->get_data('usertype');
if ($this->usertype != 'admin') {
redirect('users/typos');
}
}
/*Создаем шаблон*/
function index() {
$views['body']['url'] = "admins/users";
$views['menu']['url'] = "menu";
$views['menu']['data']['items'] = $this->mdl_menu->admin();
$this->mdl_views->view($views);
return true;
}
function users() {
$this->index();
return;
}
/*Получить пользователей*/
function get_list_users() {
$data['page'] = $this->mdl_post->int('page');
$data['limit'] = $this->mdl_post->int('rows', 1);
$data['sord'] = $this->mdl_post->string('sord');
$data['sidx'] = $this->mdl_post->string('sidx');
$data['search'] = $this->mdl_post->string('_search');
$data['searchField'] = $this->mdl_post->string('searchField');
$data['searchOper'] = $this->mdl_post->string('searchOper');
$data['searchString'] = $this->mdl_post->string('searchString');
echo json_encode($this->mdl_users->get_list_users($data));
}
/*Получить сайты пользователя*/
function get_user_sites() {
$data['page'] = $this->mdl_post->int('page');
$data['limit'] = $this->mdl_post->int('rows', 1);
$data['sord'] = $this->mdl_post->string('sord');
$data['sidx'] = $this->mdl_post->string('sidx');
$data['search'] = $this->mdl_post->string('_search');
$data['searchField'] = $this->mdl_post->string('searchField');
$data['searchOper'] = $this->mdl_post->string('searchOper');
$data['searchString'] = $this->mdl_post->string('searchString');
$data['id_user'] = $this->mdl_post->int('id');
echo json_encode($this->mdl_users->get_user_sites($data));
}
/*Управление пользователями*/
function panel_users() {
$oper = $this->mdl_post->string('oper');
$data = array();
if ($oper == 'add') {
$data['login'] = $this->mdl_post->string('login');
if (strlen($data['login']) < 3) {
echo json_encode(array('message' => 'Логин не корректен'));
return;
}
$data['type'] = $this->mdl_post->string('type');
if ($data['type'] != 'user' && $data['type'] != 'admin') {
$data['type'] = 'user';
}
$data['email'] = $this->mdl_post->string('email');
if (!filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
echo json_encode(array('message' => 'Email не корректен'));
return;
}
$data['firstname'] = $this->mdl_post->string('firstname');
if (strlen($data['firstname']) < 2) {
echo json_encode(array('message' => 'Имя не корректна'));
return;
}
$data['middlename'] = $this->mdl_post->string('middlename');
$data['lastname'] = $this->mdl_post->string('lastname');
if (strlen($data['lastname']) < 2) {
echo json_encode(array('message' => 'Фамилия не корректна'));
return;
}
$data['password'] = $this->mdl_post->string('password');
if (strlen($data['password']) < 4) {
echo json_encode(array('message' => 'Пароль не корректен'));
return;
}
$data['status'] = $this->mdl_post->int('status');
if ($data['status'] != 1 && $data['status'] != 0) {
$data['status'] = 0;
}
$data['activity'] = $this->mdl_post->int('activity');
if ($data['activity'] != 0 && $data['activity'] != 1) {
$data['activity'] = 'user';
}
$return = $this->mdl_users->add_user($data);
if ($return) {
echo json_encode($return);
}
return;
} else if ($oper == 'del') {
$data['id_user'] = $this->mdl_post->int('id');
$this->mdl_users->delete_user($data);
return;
} else if ($oper == 'edit') {
$data['id_user'] = $this->mdl_post->int('id');
$data['login'] = $this->mdl_post->string('login');
if (strlen($data['login']) < 3) {
echo json_encode(array('message' => 'Логин не корректен'));
return;
}
$data['type'] = $this->mdl_post->string('type');
if ($data['type'] != 'user' && $data['type'] != 'admin') {
$data['type'] = 'user';
}
$data['email'] = $this->mdl_post->string('email');
if (!preg_match("/^([a-z0-9_-]+\.)*[a-z0-9_-]+@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]{2,4}$/", $data['email'])) {
echo json_encode(array('message' => 'Email не корректен'));
return;
}
$data['firstname'] = $this->mdl_post->string('firstname');
if (strlen($data['firstname']) < 2) {
echo json_encode(array('message' => 'Имя не корректна'));
return;
}
$data['middlename'] = $this->mdl_post->string('middlename');
$data['lastname'] = $this->mdl_post->string('lastname');
if (strlen($data['lastname']) < 2) {
echo json_encode(array('message' => 'Фамилия не корректна'));
return;
}
$data['password'] = $this->mdl_post->string('password');
if (strlen($data['password']) < 2) {
echo json_encode(array('message' => 'Пароль не корректен'));
return;
}
$data['status'] = $this->mdl_post->int('status');
if ($data['status'] != 1 && $data['status'] != 0) {
$data['status'] = 0;
}
$data['activity'] = $this->mdl_post->int('activity');
if ($data['activity'] != 0 && $data['activity'] != 1) {
$data['activity'] = 'user';
}
$return = $this->mdl_users->edit_user($data);
if ($return) {
echo json_encode($return);
}
return;
}
}
/*Получаем сайты для пользователя, кроме уже принадлежащих*/
//Возвращать должен html-список
function get_sites() {
$id_user = $this->mdl_post->int('id_user');
$sites = $this->mdl_users->get_sites($id_user);
$select = "<select>";
if (!$sites) {
$select .= "<option disabled selected value='-1'>Сайтов нет</option>";
} else {
for ($i=0; $i<count($sites); $i++) {
$select .= "<option value='".$sites[$i]['id']."'>".$sites[$i]['site']."</option>";
}
}
$select .= "</select>";
echo $select;
return;
}
/*Управление сайтами пользователя*/
function panel_users_site() {
$oper = $this->mdl_post->string('oper');
if ($oper == 'add') {
$data['id_user'] = $this->mdl_post->int('id_user');
$data['id_site'] = $this->mdl_post->int('site');
$data['status'] = $this->mdl_post->int('status');
if ($data['status'] != 1 && $data['status'] != 0) {
$data['status'] = 0;
}
$return = $this->mdl_users->add_responsible($data);
if ($return) {
echo json_encode($return);
}
} else if ($oper == 'edit') {
$data['id_user'] = $this->mdl_post->int('id_user');
$data['id_site'] = $this->mdl_post->int('id');
$data['status'] = $this->mdl_post->int('status');
$data['status'] = $this->mdl_post->int('status');
if ($data['status'] != 1 && $data['status'] != 0) {
$data['status'] = 0;
}
$this->mdl_users->edit_responsible($data);
} else if ($oper == 'del') {
$data['id_user'] = $this->mdl_post->int('id_user');
$data['id_site'] = $this->mdl_post->int('id');
$this->mdl_users->delete_responsible($data);
}
}
}
/**/
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*Работа с опечатками - пользователь*/
class Typos extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('users/mdl_typos');
$this->load->model('mdl_session');
$this->login_id = $this->mdl_session->get_data('login_id');
}
/*Создаем шаблон*/
function index() {
if ($this->mdl_session->get_data('usertype') == 'admin') {$views['menu']['data']['items'] = $this->mdl_menu->admin();}
if ($this->mdl_session->get_data('usertype') == 'user') {$views['menu']['data']['items'] = $this->mdl_menu->user();}
$views['body']['url'] = "users/sites";
$views['menu']['url'] = "menu";
$this->mdl_views->view($views);
return true;
}
function typos() {
$this->index();
return;
}
/*Получить список сайтов для пользователя*/
function get_list_sites() {
$data['page'] = $this->mdl_post->int('page');
$data['limit'] = $this->mdl_post->int('rows', 1);
$data['sord'] = $this->mdl_post->string('sord');
$data['sidx'] = $this->mdl_post->string('sidx');
$data['search'] = $this->mdl_post->string('_search');
$data['searchField'] = $this->mdl_post->string('searchField');
$data['searchOper'] = $this->mdl_post->string('searchOper');
$data['searchString'] = $this->mdl_post->string('searchString');
$data['login_id'] = $this->login_id;
echo json_encode($this->mdl_typos->get_list_sites($data));
}
/*Получить список сообщений об опечатках для пользователя*/
function get_list_messages() {
$data['id_site'] = $this->mdl_post->int("id");
$data['page'] = $this->mdl_post->int('page');
$data['limit'] = $this->mdl_post->int('rows', 1);
$data['sord'] = $this->mdl_post->string('sord');
$data['sidx'] = $this->mdl_post->string('sidx');
$data['search'] = $this->mdl_post->string('_search');
$data['searchField'] = $this->mdl_post->string('searchField');
$data['searchOper'] = $this->mdl_post->string('searchOper');
$data['searchString'] = $this->mdl_post->string('searchString');
$data['login_id'] = $this->login_id;
echo json_encode($this->mdl_typos->get_list_messages($data));
}
/*Управление сайтами*/
function panel_sites() {
$id_site = $this->mdl_post->int("id");
$oper = $this->mdl_post->string("oper");
$status = $this->mdl_post->int("status");
$login_id = $this->login_id;
if ($oper == 'edit') {
if ($status != 0 && $status != 1) {
$status = 1;
}
$data['id_site'] = $id_site;
$data['status'] = $status;
$data['login_id'] = $login_id;
$this->mdl_typos->update_status($data);
}
}
/*Управление сообщениями*/
function panel_messages() {
$oper = $this->mdl_post->string('oper');
$data = array();
if ($oper == 'add') {
$data['id_site'] = $this->mdl_post->int('id_site');
$data['link'] = $this->mdl_post->string('link');
$data['error_text'] = $this->mdl_post->string('error_text');
$data['comment'] = $this->mdl_post->string('comment');
$data['status'] = $this->mdl_post->int('status');
if ($data['status'] != 0 && $data['status'] != 1) {
$data['status'] = 1;
}
$data['login_id'] = $this->login_id;
$this->mdl_typos->add_message($data);
} else if ($oper == 'del') {
$data['id_message'] = $this->mdl_post->int('id');
$data['id_site'] = $this->mdl_post->int('id_site');
$data['login_id'] = $this->login_id;
$this->mdl_typos->delete_message($data);
} else if ($oper == 'edit') {
$data['id_message'] = $this->mdl_post->int('id');
$data['id_site'] = $this->mdl_post->int('id_site');
$data['status'] = $this->mdl_post->int('status');
$data['login_id'] = $this->login_id;
if ($data['status'] != 0 && $data['status'] != 1) {
$data['status'] = 0;
}
$this->mdl_typos->edit_message($data);
}
}
}
/**/
\ No newline at end of file
<?php if (isset($error_message)) {
?>
<div class="warning"><?php echo $error_message;?></div>
<?php
}
?>
<form action="<?php echo $auth_url;?>" method="POST">
<table>
<tr>
<td>Логин:</td>
<td><input name="username" type="text" required/></td>
</tr>
<tr>
<td>Пароль:</td>
<td><input name="password" type="password" required/></td>
</tr>
<tr>
<td><input type="submit" value="Войти"/></td>
</tr>
</table>
</form>
\ No newline at end of file
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>
<style type="text/css">
::selection { background-color: #E13300; color: white; }
::-moz-selection { background-color: #E13300; color: white; }
body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px 0;
padding: 14px 15px 10px 15px;
}
code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
#body {
margin: 0 15px 0 15px;
}
p.footer {
text-align: right;
font-size: 11px;
border-top: 1px solid #D0D0D0;
line-height: 32px;
padding: 0 10px 0 10px;
margin: 20px 0 0 0;
}
#container {
margin: 10px;
border: 1px solid #D0D0D0;
box-shadow: 0 0 8px #D0D0D0;
}
</style>
</head>
<body>
<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>
<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/Welcome.php</code>
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
</div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment