diff --git a/application/controllers/Config.php b/application/controllers/Config.php index 6684f52ed..fce888253 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -206,6 +206,7 @@ class Config extends Secure_Controller $data['register_mode_options'] = $this->sale_lib->get_register_mode_options(); $data['rounding_options'] = Rounding_mode::get_rounding_options(); $data['tax_codes'] = $this->get_tax_code_options(); + $data['show_office_group'] = $this->Module->get_show_office_group(); $data = $this->xss_clean($data); @@ -308,6 +309,8 @@ class Config extends Secure_Controller 'custom10_name' => $this->input->post('custom10_name') ); + $this->Module->set_show_office_group($this->input->post('show_office_group') != NULL); + $result = $this->Appconfig->batch_save($batch_save_data); $success = $result ? TRUE : FALSE; diff --git a/application/controllers/Employees.php b/application/controllers/Employees.php index 533f334b2..18960ad4a 100644 --- a/application/controllers/Employees.php +++ b/application/controllers/Employees.php @@ -61,6 +61,7 @@ class Employees extends Persons { $module->module_id = $this->xss_clean($module->module_id); $module->grant = $this->xss_clean($this->Employee->has_grant($module->module_id, $person_info->person_id)); + $module->menu_group = $this->xss_clean($this->Employee->get_menu_group($module->module_id, $person_info->person_id)); $modules[] = $module; } @@ -134,6 +135,16 @@ class Employees extends Persons 'comments' => $this->input->post('comments'), ); $grants_data = $this->input->post('grants') != NULL ? $this->input->post('grants') : array(); + $menu_groups = $this->input->post('menu_groups') != NULL ? $this->input->post('menu_groups') : array(); + + $grants_array = array(); + foreach ($grants_data as $key => $value) + { + $grants = array(); + $grants['permission_id'] = $value; + $grants['menu_group'] = $menu_groups[$key]; + $grants_array[] = $grants; + } //Password has been changed OR first time password set if($this->input->post('password') != '') @@ -149,7 +160,7 @@ class Employees extends Persons $employee_data = array('username' => $this->input->post('username')); } - if($this->Employee->save_employee($person_data, $employee_data, $grants_data, $employee_id)) + if($this->Employee->save_employee($person_data, $employee_data, $grants_array, $employee_id)) { // New employee if($employee_id == -1) diff --git a/application/controllers/Home.php b/application/controllers/Home.php index 87c1df243..c4c4a5820 100644 --- a/application/controllers/Home.php +++ b/application/controllers/Home.php @@ -4,6 +4,11 @@ require_once("Secure_Controller.php"); class Home extends Secure_Controller { + function __construct() + { + parent::__construct(NULL,NULL,'home'); + } + public function index() { $this->load->view('home'); diff --git a/application/controllers/Office.php b/application/controllers/Office.php new file mode 100644 index 000000000..d9339a4d0 --- /dev/null +++ b/application/controllers/Office.php @@ -0,0 +1,24 @@ +load->view('office'); + } + + public function logout() + { + $this->track_page('logout', 'logout'); + + $this->Employee->logout(); + } +} +?> diff --git a/application/controllers/Secure_Controller.php b/application/controllers/Secure_Controller.php index ad7f18e20..3125ae518 100644 --- a/application/controllers/Secure_Controller.php +++ b/application/controllers/Secure_Controller.php @@ -6,7 +6,7 @@ class Secure_Controller extends CI_Controller * Controllers that are considered secure extend Secure_Controller, optionally a $module_id can * be set to also check if a user can access a particular module in the system. */ - public function __construct($module_id = NULL, $submodule_id = NULL) + public function __construct($module_id = NULL, $submodule_id = NULL, $menu_group = NULL) { parent::__construct(); @@ -28,7 +28,24 @@ class Secure_Controller extends CI_Controller } // load up global data visible to all the loaded views - $data['allowed_modules'] = $this->Module->get_allowed_modules($logged_in_employee_info->person_id); + + $this->load->library('session'); + if($menu_group == NULL) + { + $menu_group = $this->session->userdata('menu_group'); + } + else + { + $this->session->set_userdata('menu_group', $menu_group); + } + if($menu_group == 'home') + { + $data['allowed_modules'] = $this->Module->get_allowed_home_modules($logged_in_employee_info->person_id); + } + else + { + $data['allowed_modules'] = $this->Module->get_allowed_office_modules($logged_in_employee_info->person_id); + } $data['user_info'] = $logged_in_employee_info; $data['controller_name'] = $module_id; diff --git a/application/language/en-US/config_lang.php b/application/language/en-US/config_lang.php index f106569f9..3b028986c 100644 --- a/application/language/en-US/config_lang.php +++ b/application/language/en-US/config_lang.php @@ -225,6 +225,7 @@ $lang["config_sales_invoice_format"] = "Sales Invoice Format"; $lang["config_sales_quote_format"] = "Sales Quote Format"; $lang["config_saved_successfully"] = "Configuration save successful."; $lang["config_saved_unsuccessfully"] = "Configuration save failed."; +$lang["config_show_office_group"] = "Show office icon"; $lang["config_statistics"] = "Send Statistics"; $lang["config_statistics_tooltip"] = "Send statistics for development and feature improvement purposes."; $lang["config_stock_location"] = "Stock location"; diff --git a/application/language/en-US/module_lang.php b/application/language/en-US/module_lang.php index e447a17a6..55bc997a4 100644 --- a/application/language/en-US/module_lang.php +++ b/application/language/en-US/module_lang.php @@ -1,5 +1,6 @@ db->insert('grants', array('permission_id' => $permission_id, 'person_id' => $employee_id)); + $success = $this->db->insert('grants', array('permission_id' => $grant['permission_id'], 'person_id' => $employee_id, 'menu_group' => $grant['menu_group'])); + $count = $count+ 1; } } } @@ -390,9 +392,9 @@ class Employee extends Person return ($this->db->get()->num_rows() == 0); } - /* - Determines whether the employee specified employee has access the specific module. - */ + /** + * Determines whether the employee specified employee has access the specific module. + */ public function has_grant($permission_id, $person_id) { //if no module_id is null, allow access @@ -406,9 +408,32 @@ class Employee extends Person return ($query->num_rows() == 1); } - /* - Gets employee permission grants - */ + /** + * Returns the menu group designation that this module is to appear in + */ + public function get_menu_group($permission_id, $person_id) + { + $this->db->select('menu_group'); + $this->db->from('grants'); + $this->db->where('permission_id', $permission_id); + $this->db->where('person_id', $person_id); + + $row = $this->db->get()->row(); + + // If no grants are assigned yet then set the default to 'home' + if ($row == null) + { + return "home"; + } + else + { + return $row->menu_group; + } + } + + /* + Gets employee permission grants + */ public function get_employee_grants($person_id) { $this->db->from('grants'); diff --git a/application/models/Module.php b/application/models/Module.php index 09edd4d6a..1b95375c7 100644 --- a/application/models/Module.php +++ b/application/models/Module.php @@ -6,6 +6,11 @@ class Module extends CI_Model { + function __construct() + { + parent::__construct(); + } + public function get_module_name($module_id) { $query = $this->db->get_where('modules', array('module_id' => $module_id), 1); @@ -55,19 +60,69 @@ class Module extends CI_Model { $this->db->from('modules'); $this->db->order_by('sort', 'asc'); - return $this->db->get(); } - public function get_allowed_modules($person_id) + public function get_allowed_home_modules($person_id) { + $menus = array('home', 'both'); $this->db->from('modules'); $this->db->join('permissions', 'permissions.permission_id = modules.module_id'); $this->db->join('grants', 'permissions.permission_id = grants.permission_id'); $this->db->where('person_id', $person_id); + $this->db->where_in('menu_group', $menus); + $this->db->where('sort !=', 0); $this->db->order_by('sort', 'asc'); - return $this->db->get(); } + + public function get_allowed_office_modules($person_id) + { + $menus = array('office', 'both'); + $this->db->from('modules'); + $this->db->join('permissions', 'permissions.permission_id = modules.module_id'); + $this->db->join('grants', 'permissions.permission_id = grants.permission_id'); + $this->db->where('person_id', $person_id); + $this->db->where_in('menu_group', $menus); + $this->db->where('sort !=', 0); + $this->db->order_by('sort', 'asc'); + return $this->db->get(); + } + + /** + * This method is used to set the show the office navigation icon on the home page + * which happens when the sort value is greater than zero + */ + public function set_show_office_group($show_office_group) + { + if($show_office_group) + { + $sort = 1; + } + else + { + $sort = 0; + } + + $modules_data = array( + 'sort' => $sort + ); + $this->db->where('module_id', 'office'); + $this->db->update('modules', $modules_data); + } + + /** + * This method is used to show the office navigation icon on the home page + * which happens when the sort value is greater than zero + */ + public function get_show_office_group() + { + $this->db->select('sort'); + $this->db->from('grants'); + $this->db->where('module_id', 'office'); + $this->db->from('modules'); + return $this->db->get()->row()->sort; + } + } ?> diff --git a/application/views/configs/general_config.php b/application/views/configs/general_config.php index 1b179cf5c..86bc5a8c0 100644 --- a/application/views/configs/general_config.php +++ b/application/views/configs/general_config.php @@ -94,7 +94,7 @@