finish with user and site panels

parent 68874b55
...@@ -113,7 +113,7 @@ class Sites extends CI_Controller { ...@@ -113,7 +113,7 @@ class Sites extends CI_Controller {
$oper = $this->input->post('oper'); $oper = $this->input->post('oper');
if ($oper == 'del') { if ($oper == 'del') {
$this->load->model('admins/user'); $this->load->model('admins/user');
$data['id_user'] = $this->input->get('id'); $data['id_user'] = $this->input->post('id');
$data['id_site'] = $this->input->get('id_site'); $data['id_site'] = $this->input->get('id_site');
$this->user->deleteResponsible($data); $this->user->deleteResponsible($data);
} }
......
...@@ -44,6 +44,8 @@ class Users extends CI_Controller { ...@@ -44,6 +44,8 @@ class Users extends CI_Controller {
/*Получить пользователей*/ /*Получить пользователей*/
function get_list_users() { function get_list_users() {
error_log("get_list_users");
$data['page'] = $this->input->get('page'); $data['page'] = $this->input->get('page');
$data['limit'] = $this->input->get('rows', 1); $data['limit'] = $this->input->get('rows', 1);
$data['sord'] = $this->input->get('sord'); $data['sord'] = $this->input->get('sord');
...@@ -58,6 +60,8 @@ class Users extends CI_Controller { ...@@ -58,6 +60,8 @@ class Users extends CI_Controller {
/*Получить сайты пользователя*/ /*Получить сайты пользователя*/
function get_user_sites() { function get_user_sites() {
log_message('error', 'get_user_states');
$data['page'] = $this->input->get('page'); $data['page'] = $this->input->get('page');
$data['limit'] = $this->input->get('rows', 1); $data['limit'] = $this->input->get('rows', 1);
$data['sord'] = $this->input->get('sord'); $data['sord'] = $this->input->get('sord');
...@@ -76,6 +80,8 @@ class Users extends CI_Controller { ...@@ -76,6 +80,8 @@ class Users extends CI_Controller {
$oper = $this->input->post('oper'); $oper = $this->input->post('oper');
$data = array(); $data = array();
log_message('error', 'panel_users');
log_message('error', "Oper = $oper");
if ($oper == 'add') { if ($oper == 'add') {
$data['login'] = $this->input->post('login'); $data['login'] = $this->input->post('login');
if (strlen($data['login']) < 3) { if (strlen($data['login']) < 3) {
...@@ -129,6 +135,7 @@ class Users extends CI_Controller { ...@@ -129,6 +135,7 @@ class Users extends CI_Controller {
return; return;
} else if ($oper == 'del') { } else if ($oper == 'del') {
$data['id_user'] = $this->input->post('id'); $data['id_user'] = $this->input->post('id');
log_message('error', "DELETE USSER!!!!!");
$this->user->deleteUser($data); $this->user->deleteUser($data);
return; return;
} else if ($oper == 'edit') { } else if ($oper == 'edit') {
...@@ -192,16 +199,14 @@ class Users extends CI_Controller { ...@@ -192,16 +199,14 @@ class Users extends CI_Controller {
//Возвращать должен html-список //Возвращать должен html-список
function get_sites() { function get_sites() {
$id_user = $this->input->get('id_user'); $id_user = $this->input->get('id_user');
$sites = $this->user->getUserSites($id_user); $sites = $this->user->getAvailableSites($id_user);
log_message("error", "result!!!");
$select = "<select>"; $select = "<select>";
if (!$sites) { if ($sites->num_rows() == 0) {
$select .= "<option disabled selected value='-1'>Сайтов нет</option>"; $select .= "<option disabled selected value='-1'>Сайтов нет</option>";
} else { } else {
for ($i=0; $i<count($sites); $i++) { foreach ($sites->result() as $site) {
$select .= "<option value='".$sites[$i]['id']."'>".$sites[$i]['site']."</option>"; $select .= "<option value='".$site->id."'>".$site->site."</option>";
} }
} }
$select .= "</select>"; $select .= "</select>";
...@@ -213,28 +218,33 @@ class Users extends CI_Controller { ...@@ -213,28 +218,33 @@ class Users extends CI_Controller {
/*Управление сайтами пользователя*/ /*Управление сайтами пользователя*/
function panel_users_site() { function panel_users_site() {
$oper = $this->input->post('oper'); $oper = $this->input->post('oper');
if ($oper == 'add') { if ($oper == 'add') {
$data['id_user'] = $this->input->post('id_user'); $data['id_user'] = $this->input->get('id_user');
$data['id_site'] = $this->input->post('site'); $data['id_site'] = $this->input->post('site');
$data['status'] = $this->input->post('status'); $data['status'] = $this->input->post('status');
if ($data['status'] != 1 && $data['status'] != 0) { if ($data['status'] != 1 && $data['status'] != 0) {
$data['status'] = 0; $data['status'] = 0;
} }
$return = $this->user->addResponsible($data); $return = $this->user->addResponsible($data);
if ($return) { if ($return) {
echo json_encode($return); echo json_encode($return);
} }
} else if ($oper == 'edit') { } else if ($oper == 'edit') {
$data['id_user'] = $this->input->post('id_user'); $data['id_user'] = $this->input->get('id_user');
$data['id_site'] = $this->input->post('id'); $data['id_site'] = $this->input->post('id');
$data['status'] = $this->input->post('status'); $data['status'] = $this->input->post('status');
$data['status'] = $this->input->post('status');
if ($data['status'] != 1 && $data['status'] != 0) { if ($data['status'] != 1 && $data['status'] != 0) {
$data['status'] = 0; $data['status'] = 0;
} }
$this->user->editResponsible($data); $this->user->editResponsible($data);
} else if ($oper == 'del') { } else if ($oper == 'del') {
$data['id_user'] = $this->input->post('id_user'); $data['id_user'] = $this->input->get('id_user');
$data['id_site'] = $this->input->post('id'); $data['id_site'] = $this->input->post('id');
$this->user->deleteResponsible($data); $this->user->deleteResponsible($data);
} }
......
...@@ -23,17 +23,19 @@ class User extends CI_Model { ...@@ -23,17 +23,19 @@ class User extends CI_Model {
} }
private function filterResults($table, $data) { private function filterResults($table, $data) {
log_message('error', "data = " . print_r($data, true));
$this->load->helper("search"); $this->load->helper("search");
log_message('error', "data = " . print_r($data, true));
$id_user = isset($data['id_user']) ? $data['id_user'] : 0; $id_user = isset($data['id_user']) ? $data['id_user'] : 0;
$page = $data['page']; $page = isset($data['page']) ? $data['page'] : 0;
$limit = $data['limit']; $limit = isset($data['limit']) ? $data['limit'] : 0;
$sord = isset($data['sord']) ? $data['sord'] : 0; $sord = isset($data['sord']) ? $data['sord'] : 0;
$sidx = isset($data['sidx']) ? $data['sidx'] : 0; $sidx = isset($data['sidx']) ? $data['sidx'] : 0;
$search = $data['search']; $search = isset($data['search']) ? $data['search'] : "false";
$searchstring = ""; $searchstring = "";
$search_string = ""; $search_string = "";
if ($search == "true") { if ($search == "true") {
$searchField = $data['searchField']; $searchField = $data['searchField'];
$searchOper = $data['searchOper']; $searchOper = $data['searchOper'];
...@@ -80,7 +82,6 @@ class User extends CI_Model { ...@@ -80,7 +82,6 @@ class User extends CI_Model {
$this->db->select('*'); $this->db->select('*');
if ( $table == 'users' ) { if ( $table == 'users' ) {
$this->db->from('users as u'); $this->db->from('users as u');
} else { } else {
$this->db->from('responsible as r'); $this->db->from('responsible as r');
...@@ -101,6 +102,8 @@ class User extends CI_Model { ...@@ -101,6 +102,8 @@ class User extends CI_Model {
$results = $this->db->get(); $results = $this->db->get();
log_message('error', $this->db->last_query());
if ( $table == 'users') { if ( $table == 'users') {
foreach( $results->result() as $id => $row ) { foreach( $results->result() as $id => $row ) {
$data['rows'][$id]['id'] = $row->id; $data['rows'][$id]['id'] = $row->id;
...@@ -128,6 +131,23 @@ class User extends CI_Model { ...@@ -128,6 +131,23 @@ class User extends CI_Model {
return $data; return $data;
} }
/**
* Возвращает список сайтов, доступных для добавления
* к пользователю.
*
* @param type $user_id Идентификатор пользователя
*/
function getAvailableSites($user_id) {
$this->db->select("s.id,s.site");
$this->db->from("sites as s");
$this->db->where('s.id NOT IN ('
. 'SELECT s.id FROM sites as s '
. 'JOIN responsible as r ON r.id_site = s.id '
. 'WHERE r.id_user = '.$user_id.')');
return $this->db->get();
}
/*Добавляем пользователя*/ /*Добавляем пользователя*/
function addUser($data) { function addUser($data) {
if (!$this->checkEmail($data['email'])) { if (!$this->checkEmail($data['email'])) {
...@@ -184,15 +204,21 @@ class User extends CI_Model { ...@@ -184,15 +204,21 @@ class User extends CI_Model {
/*Удаляем пользователя*/ /*Удаляем пользователя*/
function deleteUser($data) { function deleteUser($data) {
log_message('error', print_r($data, true));
$this->db->where('id', $data['id_user']); $this->db->where('id', $data['id_user']);
$this->db->delete('users'); $this->db->delete('users');
log_message('error', $this->db->last_query());
$this->db->where('id', $data['id_user']); $this->db->where('id', $data['id_user']);
$this->db->delete('responsible'); $this->db->delete('responsible');
} }
/*Снимаем ответсвенного*/ /*Снимаем ответсвенного*/
function deleteResponsible($data) { function deleteResponsible($data) {
log_message('error', 'deleteResponsible with data = ');
log_message('error', print_r($data, true));
$this->db->where('id_site', $data['id_site']); $this->db->where('id_site', $data['id_site']);
$this->db->where('id_user', $data['id_user']); $this->db->where('id_user', $data['id_user']);
...@@ -201,10 +227,14 @@ class User extends CI_Model { ...@@ -201,10 +227,14 @@ class User extends CI_Model {
/*Обновляем статус*/ /*Обновляем статус*/
function editResponsible($data) { function editResponsible($data) {
$this->db->set('status', $data['status']);
$this->db->where('id_site', $data['id_site']); $this->db->where('id_site', $data['id_site']);
$this->db->where('id_user', $data['id_user']); $this->db->where('id_user', $data['id_user']);
$this->db->update('responsible', array( 'status' => $data['status']));
$this->db->update('responsible');
log_message('error', $this->db->last_query());
} }
/*Проверяем логин на уникальность*/ /*Проверяем логин на уникальность*/
...@@ -276,18 +306,21 @@ class User extends CI_Model { ...@@ -276,18 +306,21 @@ class User extends CI_Model {
return array('message' => "Сайт не существует"); return array('message' => "Сайт не существует");
} }
$data2[0] = 'NULL'; $data2 = [
$data2[1] = $data['id_site']; 'id' => NULL,
$data2[2] = $data['id_user']; 'id_site' => $data['id_site'],
$data2[3] = $data['status']; 'id_user' => $data['id_user'],
$data2[4] = date('Y-m-d H:i:s', time()); 'status' => $data['status'],
'date' => date('Y-m-d H:i:s', time())
];
$this->db->insert('responsible', $data2); $this->db->insert('responsible', $data2);
} }
/*Проверяем - есть ли у пользователя такой сайт*/ /*Проверяем - есть ли у пользователя такой сайт*/
function checkResponsible($data) { function checkResponsible($data) {
$this->db->where("user_id", $data['id_user']); $this->db->where("id_user", $data['id_user']);
$this->db->where("site_id", $data['id_site']); $this->db->where("id_site", $data['id_site']);
$this->db->from("responsible"); $this->db->from("responsible");
$count = $this->db->count_all_results(); $count = $this->db->count_all_results();
...@@ -305,9 +338,9 @@ class User extends CI_Model { ...@@ -305,9 +338,9 @@ class User extends CI_Model {
$count = $this->db->count_all_results(); $count = $this->db->count_all_results();
if ($count == 0) { if ($count == 0) {
return true;
} else {
return false; return false;
} else {
return true;
} }
} }
......
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