From 3450bd93b1df0e3fbb53207892ef4df709350083 Mon Sep 17 00:00:00 2001 From: "alextselegidis@gmail.com" Date: Tue, 24 Sep 2013 16:05:40 +0000 Subject: [PATCH] * Split the backend_users.js into three different files. --- src/application/controllers/backend_api.php | 9 +- src/application/models/admins_model.php | 7 +- src/application/views/backend/users.php | 8 + src/assets/js/backend_users.js | 1458 +------------------ src/assets/js/backend_users_admins.js | 381 +++++ src/assets/js/backend_users_providers.js | 742 ++++++++++ src/assets/js/backend_users_secretaries.js | 356 +++++ 7 files changed, 1512 insertions(+), 1449 deletions(-) create mode 100644 src/assets/js/backend_users_admins.js create mode 100644 src/assets/js/backend_users_providers.js create mode 100644 src/assets/js/backend_users_secretaries.js diff --git a/src/application/controllers/backend_api.php b/src/application/controllers/backend_api.php index e7afd06d..fafe8bf3 100644 --- a/src/application/controllers/backend_api.php +++ b/src/application/controllers/backend_api.php @@ -850,8 +850,13 @@ class Backend_api extends CI_Controller { */ public function ajax_validate_username() { try { - // We will use the function in the admins_model because it is sufficient for - // the rest user types for now (providers, secretaries). + // $_POST['record_exists'] is treated like a string in this method and this + // is making the validation algorithm fail. So we need to convert the value + // into bool before validating the username. + $_POST['record_exists'] = ($_POST['record_exists'] == 'true') ? TRUE : FALSE; + + // We will only use the function in the admins_model because it is sufficient + // for the rest user types for now (providers, secretaries). $this->load->model('admins_model'); $is_valid = $this->admins_model->validate_username($_POST['username'], $_POST['record_exists']); echo json_encode($is_valid); diff --git a/src/application/models/admins_model.php b/src/application/models/admins_model.php index ced992f7..ca249818 100644 --- a/src/application/models/admins_model.php +++ b/src/application/models/admins_model.php @@ -357,10 +357,11 @@ class Admins_Model extends CI_Model { */ public function validate_username($username, $record_exists) { $num_rows = $this->db->get_where('ea_user_settings', array('username' => $username))->num_rows(); - if (($num_rows == 0 && $record_exists == FALSE) || ($num_rows == 1 && $record_exists == TRUE)) { - return TRUE; + if (($num_rows == 0 && $record_exists == FALSE) || ($num_rows == 1 && $record_exists == TRUE) + || ($num_rows == 0 && $record_exists == TRUE)) { + return TRUE; // valid } else { - return FALSE; + return FALSE; // not valid } } } diff --git a/src/application/views/backend/users.php b/src/application/views/backend/users.php index 886ef5a8..b3ef5f41 100644 --- a/src/application/views/backend/users.php +++ b/src/application/views/backend/users.php @@ -1,5 +1,13 @@ + + + + +