From 21aba5d4da605226f06418e2b1de101df5efbada Mon Sep 17 00:00:00 2001 From: "alextselegidis@gmail.com" Date: Sun, 24 Nov 2013 17:01:46 +0000 Subject: [PATCH] * Updated user models and settings view file. --- src/application/controllers/appointments.php | 3 ++ src/application/models/admins_model.php | 5 +++- src/application/models/customers_model.php | 29 +++++++++++--------- src/application/models/providers_model.php | 5 +++- src/application/models/secretaries_model.php | 5 +++- src/application/views/backend/settings.php | 2 ++ 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/application/controllers/appointments.php b/src/application/controllers/appointments.php index e59d6395..3ecb3d9c 100644 --- a/src/application/controllers/appointments.php +++ b/src/application/controllers/appointments.php @@ -88,6 +88,9 @@ class Appointments extends CI_Controller { $appointment = $post_data['appointment']; $customer = $post_data['customer']; + if ($this->customers_model->exists($customer)) + $customer['id'] = $this->customers_model->find_record_id($customer); + $customer_id = $this->customers_model->add($customer); $appointment['id_users_customer'] = $customer_id; diff --git a/src/application/models/admins_model.php b/src/application/models/admins_model.php index 7a14fe69..daa91b84 100644 --- a/src/application/models/admins_model.php +++ b/src/application/models/admins_model.php @@ -221,16 +221,19 @@ class Admins_Model extends CI_Model { } // When inserting a record the email address must be unique. + $admin_id = (isset($admin['id'])) ? $admin['id'] : ''; + $num_rows = $this->db ->select('*') ->from('ea_users') ->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner') ->where('ea_roles.slug', DB_SLUG_ADMIN) ->where('ea_users.email', $admin['email']) + ->where('ea_users.id <>', $admin_id) ->get() ->num_rows(); - if ($num_rows > 0 && !isset($admin['id'])) { + if ($num_rows > 0) { throw new Exception('Given email address belongs to another admin record. ' . 'Please use a different email.'); } diff --git a/src/application/models/customers_model.php b/src/application/models/customers_model.php index b5562717..2c272ace 100644 --- a/src/application/models/customers_model.php +++ b/src/application/models/customers_model.php @@ -182,19 +182,22 @@ class Customers_Model extends CI_Model { } // When inserting a record the email address must be unique. - //$num_rows = $this->db - // ->select('*') - // ->from('ea_users') - // ->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner') - // ->where('ea_roles.slug', DB_SLUG_CUSTOMER) - // ->where('ea_users.email', $customer['email']) - // ->get() - // ->num_rows(); - // - //if ($num_rows > 0 && !isset($customer['id'])) { - // throw new Exception('Given email address belongs to another customer record. ' - // . 'Please use a different email.'); - //} + $customer_id = (isset($customer['id'])) ? $customer['id'] : ''; + + $num_rows = $this->db + ->select('*') + ->from('ea_users') + ->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner') + ->where('ea_roles.slug', DB_SLUG_CUSTOMER) + ->where('ea_users.email', $customer['email']) + ->where('ea_users.id <>', $customer_id) + ->get() + ->num_rows(); + + if ($num_rows > 0) { + throw new Exception('Given email address belongs to another customer record. ' + . 'Please use a different email.'); + } return TRUE; } diff --git a/src/application/models/providers_model.php b/src/application/models/providers_model.php index 3de5314e..efa87ea3 100644 --- a/src/application/models/providers_model.php +++ b/src/application/models/providers_model.php @@ -251,16 +251,19 @@ class Providers_Model extends CI_Model { } // When inserting a record the email address must be unique. + $provider_id = (isset($provider['id'])) ? $provider['id'] : ''; + $num_rows = $this->db ->select('*') ->from('ea_users') ->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner') ->where('ea_roles.slug', DB_SLUG_PROVIDER) ->where('ea_users.email', $provider['email']) + ->where('ea_users.id <>', $provider_id) ->get() ->num_rows(); - if ($num_rows > 0 && !isset($provider['id'])) { + if ($num_rows > 0) { throw new Exception('Given email address belongs to another provider record. ' . 'Please use a different email.'); } diff --git a/src/application/models/secretaries_model.php b/src/application/models/secretaries_model.php index 7ab5470e..e95528e7 100644 --- a/src/application/models/secretaries_model.php +++ b/src/application/models/secretaries_model.php @@ -219,16 +219,19 @@ class Secretaries_Model extends CI_Model { } // When inserting a record the email address must be unique. + $secretary_id = (isset($secretary['id'])) ? $secretary['id'] : ''; + $num_rows = $this->db ->select('*') ->from('ea_users') ->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner') ->where('ea_roles.slug', DB_SLUG_SECRETARY) ->where('ea_users.email', $secretary['email']) + ->where('ea_users.id <>', $secretary_id) ->get() ->num_rows(); - if ($num_rows > 0 && !isset($secretary['id'])) { + if ($num_rows > 0) { throw new Exception('Given email address belongs to another secretary record. ' . 'Please use a different email.'); } diff --git a/src/application/views/backend/settings.php b/src/application/views/backend/settings.php index c2a164e3..9a0214f5 100644 --- a/src/application/views/backend/settings.php +++ b/src/application/views/backend/settings.php @@ -325,6 +325,8 @@ official Google Group for answers. You might also need to create a new issue on the Google Code page in order to help the development progress.

+ Official Website + | Google+ Community |