diff --git a/Release Notes.txt b/Release Notes.txt index abadfc41..0e76cd5a 100644 --- a/Release Notes.txt +++ b/Release Notes.txt @@ -1,12 +1,11 @@ -VERSION 0.5 +VERSION 0.6 =========== -[Feature] Admin users management. -[Feature] Service provider users management. -[Feature] Customer users management. -[Feature] Secretary users management. -[Feature] Custom error 404 page. -[Enhancement] Display selected service description and price at the appointment book wizard. -[Enhancement] Group services by categories at the appointment book wizard. +[Feature] System and user settings page. +[Feature] Login process included. +[Feature] Applied user privileges through all the system depending their role type. +[Feature] Select existing customer from backend/calendar when trying to add a new appointment. +[Fix] Fix backend/calendar service and provider functionality. + Official Easy!Appointments Website: http://easyappointments.org diff --git a/src/application/config/config.php b/src/application/config/config.php index 641d7f3e..cf4496bc 100644 --- a/src/application/config/config.php +++ b/src/application/config/config.php @@ -1,5 +1,8 @@ load->model('settings_model'); + $this->load->model('user_model'); + + $this->load->library('session'); + + // @task Apply data for testing this page (this must be done during the login process). + $this->session->set_userdata('user_id', 18); + $this->session->set_userdata('user_slug', DB_SLUG_ADMIN); + + $user_id = $this->session->userdata('user_id'); $view['base_url'] = $this->config->item('base_url'); $view['company_name'] = $this->settings_model->get_setting('company_name'); + $view['user_slug'] = $this->session->userdata('user_slug'); + $view['system_settings'] = $this->settings_model->get_settings(); + $view['user_settings'] = $this->user_model->get_settings($user_id); $this->load->view('backend/header', $view); $this->load->view('backend/settings', $view); diff --git a/src/application/controllers/backend_api.php b/src/application/controllers/backend_api.php index 7c154ec8..674441bb 100644 --- a/src/application/controllers/backend_api.php +++ b/src/application/controllers/backend_api.php @@ -793,6 +793,33 @@ class Backend_api extends CI_Controller { )); } } + + /** + * [AJAX] Save a setting or multiple settings in the database. + * + * This method is used to store settings in the database. It can be either system + * or user settings, one or many. Use the $_POST variables accordingly. + * + * @param array $_POST['settings'] Contains an array with settings. + * @param bool $_POST['type'] Determines the settings type, can be either SETTINGS_SYSTEM + * or SETTINGS_USER. + */ + public function ajax_save_settings() { + try { + if ($_POST['type'] == SETTINGS_SYSTEM) { + // @task Implement save settings. + } else if ($_POST['type'] == SETTINGS_USER) { + $this->load->library('session'); + $this->load->model('user_model'); + $user_id = $this->session->userdata('user_id'); + $this->user_model->save_settings($_POST['settings'], $user_id); + } + } catch(Exception $exc) { + echo json_encode(array( + 'exceptions' => array(exceptionToJavaScript($exc)) + )); + } + } } /* End of file backend_api.php */ diff --git a/src/application/models/settings_model.php b/src/application/models/settings_model.php index 2ceefe18..98b3acd3 100644 --- a/src/application/models/settings_model.php +++ b/src/application/models/settings_model.php @@ -90,6 +90,40 @@ class Settings_Model extends CI_Model { return $this->db->delete('ea_settings', array('name' => $name)); } + + /** + * Saves all the system settings into the database. + * + * This method is usefull when trying to save all the system settings at once instead of + * saving them one by one. + * + * @param array $settings Contains all the system settings. + * @return bool Returns the save operation result. + * + * @throws Exception When the update operation won't work for a specific setting. + */ + public function save_settings($settings) { + if (!is_array($settings)) { + throw new Exception('$settings argument is invalid: '. print_r($settings, TRUE)); + } + + foreach($settings as $name=>$value) { + if (!$this->db->update('ea_settings', array('value' => $value), array('name' => $name))) { + throw new Exception('Could not save setting (' . $name . ' - ' . $value . ')'); + } + } + + return TRUE; + } + + /** + * Returns all the system settings at once. + * + * @return array Array of all the system settings stored in the 'ea_settings' table. + */ + public function get_settings() { + return $this->db->get('ea_settings')->result_array(); + } } /* End of file settings_model.php */ diff --git a/src/application/models/user_model.php b/src/application/models/user_model.php new file mode 100644 index 00000000..fbacc999 --- /dev/null +++ b/src/application/models/user_model.php @@ -0,0 +1,41 @@ +db->get_where('ea_user_settings', array('id_users' => $user_id))->row_array(); + unset($settings['id_users']); + return $settings; + } + + /** + * This method saves the user settings into the database. + * + * @param array $settings Contains the current users settings. + * @param numeric $user_id User record id of the settings. + * @return bool Returns the operation result. + */ + public function save_settings($settings, $user_id) { + $settings['id_users'] = $user_id; + $this->db->where('id_users', $user_id); + return $this->db->update('ea_user_settings', $settings); + } +} + +/* End of file user_model.php */ +/* Location: ./application/models/user_model.php */ \ No newline at end of file diff --git a/src/application/views/backend/settings.php b/src/application/views/backend/settings.php index fb95cac4..1ad43951 100644 --- a/src/application/views/backend/settings.php +++ b/src/application/views/backend/settings.php @@ -1,11 +1,248 @@ -
- It will be included in the next release of Easy!Appointments (v0.6).
-
- Check the Google+
- Community for development updates or visit the
- Support Group for help.
+
+
+
-