diff --git a/application/config/config.php b/application/config/config.php index 1d098dd89..6225b1cc8 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -265,7 +265,7 @@ $config['sess_use_database'] = TRUE; $config['sess_table_name'] = 'ospos_sessions'; $config['sess_match_ip'] = FALSE; $config['sess_match_useragent'] = FAlSE; -$config['sess_time_to_update'] = 86400; +$config['sess_time_to_update'] = 0; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/employees.php b/application/controllers/employees.php index e719cb0cd..698d132d7 100644 --- a/application/controllers/employees.php +++ b/application/controllers/employees.php @@ -47,6 +47,7 @@ class Employees extends Person_controller { $data['person_info']=$this->Employee->get_info($employee_id); $data['all_modules']=$this->Module->get_all_modules(); + $data['all_subpermissions']=$this->Module->get_all_subpermissions(); $this->load->view("employees/form",$data); } @@ -68,7 +69,7 @@ class Employees extends Person_controller 'country'=>$this->input->post('country'), 'comments'=>$this->input->post('comments') ); - $permission_data = $this->input->post("permissions")!=false ? $this->input->post("permissions"):array(); + $grants_data = $this->input->post("grants")!=false ? $this->input->post("grants"):array(); //Password has been changed OR first time password set if($this->input->post('password')!='') @@ -83,7 +84,7 @@ class Employees extends Person_controller $employee_data=array('username'=>$this->input->post('username')); } - if($this->Employee->save($person_data,$employee_data,$permission_data,$employee_id)) + if($this->Employee->save($person_data,$employee_data,$grants_data,$employee_id)) { //New employee if($employee_id==-1) diff --git a/application/controllers/items.php b/application/controllers/items.php index b1e7211e5..be0c60aaa 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -21,7 +21,6 @@ class Items extends Secure_area implements iData_controller $stock_locations=$this->Stock_locations->get_allowed_locations(); $data['stock_location']=$stock_location; $data['stock_locations']=$stock_locations; - var_dump($stock_location); $data['controller_name']=strtolower(get_class()); $data['form_width']=$this->get_form_width(); $data['manage_table']=get_items_manage_table( $this->Item->get_all( $stock_location, $config['per_page'], $this->uri->segment( $config['uri_segment'] ) ), $this ); diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index 252726bd0..435f4a449 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -120,6 +120,7 @@ class Receivings extends Secure_area function delete_supplier() { + $this->receiving_lib->clear_invoice_number(); $this->receiving_lib->delete_supplier(); $this->_reload(); } @@ -246,7 +247,7 @@ class Receivings extends Secure_area $invoice_number=$this->receiving_lib->get_invoice_number(); if (empty($invoice_number)) - { + { $invoice_number=$this->config->config['recv_invoice_format']; } $invoice_count=$this->Receiving->get_invoice_count(); @@ -266,8 +267,10 @@ class Receivings extends Secure_area } $invoice_number=str_replace('$SI',$acronym,$invoice_number); } + $this->receiving_lib->set_invoice_number($invoice_number); $data['invoice_number']=$invoice_number; + $this->load->view("receivings/receiving",$data); $this->_remove_duplicate_cookies(); } diff --git a/application/controllers/reports.php b/application/controllers/reports.php index 54f91d465..d649f7dba 100644 --- a/application/controllers/reports.php +++ b/application/controllers/reports.php @@ -6,26 +6,18 @@ define("FORM_WIDTH", "400"); class Reports extends Secure_area { - + function __construct() { parent::__construct('reports'); - $method_name = $this->uri->segment(2); - $exploder = explode('_', $method_name); - $submodule_id = preg_match("/([^_.]*)(?:_graph)?$/", $method_name, $matches); - $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; - // check access to report submodule - /* if (sizeof($exploder) > 1 && !$this->Employee->has_permission('reports_'.$matches[1],$employee_id)) - { - redirect('no_access/'.$submodule_id); - } */ $this->load->helper('report'); } //Initial report listing screen function index() { - $this->load->view("reports/listing",array()); + $data['grants']=$this->Employee->get_employee_grants($this->session->userdata('person_id')); + $this->load->view("reports/listing",$data); } function _get_common_report_data() diff --git a/application/controllers/secure_area.php b/application/controllers/secure_area.php index dbdd750bc..77049d234 100644 --- a/application/controllers/secure_area.php +++ b/application/controllers/secure_area.php @@ -13,9 +13,9 @@ class Secure_area extends CI_Controller { redirect('login'); } - $submodule_id = empty($submodule_id) ? $module_id : $submodule_id; $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; - if(!$this->Employee->has_permission($module_id,$employee_id) || !$this->Employee->has_subpermission($submodule_id,$employee_id)) + if(!$this->Employee->has_module_permission($module_id,$employee_id) || + (isset($submodule_id) && !$this->Employee->has_module_permission($submodule_id,$employee_id))) { redirect('no_access/'.$module_id); } diff --git a/application/helpers/report_helper.php b/application/helpers/report_helper.php index 8367f2785..2617642b1 100644 --- a/application/helpers/report_helper.php +++ b/application/helpers/report_helper.php @@ -86,24 +86,18 @@ function random_color() return $c; } -function show_report_if_allowed($allowed_modules, $report_prefix, $report_name, $permission='') +function show_report_if_allowed($grant, $report_prefix, $report_name='') { $CI =& get_instance(); + $report_name = empty($report_name) ? $grant['permission_id'] : $report_name; $lang_line = 'reports_' .$report_name; $report_label = $CI->lang->line($lang_line); - $permission = empty($permission) ? $report_name : $permission; $report_prefix = empty($report_prefix) ? '' : $report_prefix . '_'; // no summary nor detailed reports for receivings if (!empty($report_label) && !(preg_match('/.*summary_?$/', $report_prefix) && $report_name === "receivings")) { - foreach($allowed_modules->result() as $module) - { - if ($module->module_id == 'reports_'. $permission) - { - ?> -
  • - +
  • + db->delete('permissions', array('person_id' => $employee_id)); + //First lets clear out any grants the employee currently has. + $success=$this->db->delete('grants', array('person_id' => $employee_id)); - //Now insert the new permissions + //Now insert the new grants if($success) { - foreach($permission_data as $allowed_module) + foreach($grants_data as $permission_id) { - $success = $this->db->insert('permissions', + $success = $this->db->insert('grants', array( - 'module_id'=>$allowed_module, + 'permission_id'=>$permission_id, 'person_id'=>$employee_id)); } } @@ -142,7 +142,7 @@ class Employee extends Person $this->db->trans_start(); //Delete permissions - if($this->db->delete('permissions', array('person_id' => $employee_id))) + if($this->db->delete('grants', array('person_id' => $employee_id))) { $this->db->where('person_id', $employee_id); $success = $this->db->update('employees', array('deleted' => 1)); @@ -167,7 +167,7 @@ class Employee extends Person $this->db->where_in('person_id',$employee_ids); //Delete permissions - if ($this->db->delete('permissions')) + if ($this->db->delete('grants')) { //delete from employee table $this->db->where_in('person_id',$employee_ids); @@ -306,37 +306,65 @@ class Employee extends Person /* * Determines whether the employee has access to at least one submodule */ - function has_subpermission($submodule_id,$person_id) + function has_module_permission($submodule_id,$person_id) { - $this->db->from('modules'); - $this->db->where('module_id like "' . $submodule_id . '_%"'); - // has no submodules + $this->db->from('grants'); + $this->db->where('permission_id like "' . $submodule_id . '%"'); + $this->db->where('person_id',$person_id); $result = $this->db->get(); - if ($result->num_rows() > 0) + $result_count = $result->num_rows(); + if ($result_count != 1) { - $this->db->from('permissions'); - $this->db->where('permissions.module_id like "' . $submodule_id . '_%"'); - $this->db->where("permissions.person_id",$person_id); - $result = $this->db->get(); - return $result->num_rows() > 0; + return $result_count != 0; } - return true; + return $this->has_submodules($submodule_id); + } + + function has_submodules($submodule_id) + { + $this->db->from('permissions'); + $this->db->where('permission_id like "' . $submodule_id . '_%"'); + $result = $this->db->get(); + return $result->num_rows() == 0; } /* - Determins whether the employee specified employee has access the specific module. + Determines whether the employee specified employee has access the specific module. */ - function has_permission($module_id,$person_id) + function has_permission($permission_id,$person_id) { //if no module_id is null, allow access - if($module_id==null) + if($permission_id==null) { return true; } - $query = $this->db->get_where('permissions', array('person_id' => $person_id,'module_id'=>$module_id), 1); + $query = $this->db->get_where('grants', array('person_id'=>$person_id,'permission_id'=>$permission_id), 1); return ($query->num_rows() == 1); } + + function get_employee_grants($person_id) + { + $this->db->from('grants'); + $this->db->where('person_id',$person_id); + $results = $this->db->get()->result_array(); + return $this->add_sales_categories($results, $person_id); + } + + function add_sales_categories($results, $person_id) + { + foreach($results as $result) + { + if ($result['permission_id'] == 'reports_sales') + { + foreach(array('categories', 'taxes', 'discounts', 'payments') as $sales_category) + { + $results[] = array('permission_id' => 'reports_'.$sales_category, 'person_id' => $person_id); + } + } + } + return $results; + } } ?> diff --git a/application/models/module.php b/application/models/module.php index 4f5ff99c8..32d5365d1 100644 --- a/application/models/module.php +++ b/application/models/module.php @@ -31,6 +31,21 @@ class Module extends CI_Model return $this->lang->line('error_unknown'); } + function get_all_permissions() + { + $this->db->from('permissions'); + return $this->db->get(); + } + + function get_all_subpermissions() + { + $this->db->from('permissions'); + $this->db->join('modules', 'modules.module_id=permissions.module_id'); + // can't quote the parameters correctly when using different operators.. + $this->db->where($this->db->dbprefix('modules').'.module_id!=', 'permission_id', FALSE); + return $this->db->get(); + } + function get_all_modules() { $this->db->from('modules'); @@ -41,8 +56,9 @@ class Module extends CI_Model function get_allowed_modules($person_id) { $this->db->from('modules'); - $this->db->join('permissions','permissions.module_id=modules.module_id'); - $this->db->where("permissions.person_id",$person_id); + $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->order_by("sort", "asc"); return $this->db->get(); } diff --git a/application/models/stock_locations.php b/application/models/stock_locations.php index 5ef5ca6ca..fa463a888 100644 --- a/application/models/stock_locations.php +++ b/application/models/stock_locations.php @@ -13,9 +13,6 @@ class Stock_locations extends CI_Model function get_all($limit=10000, $offset=0) { $this->db->from('stock_locations'); - $this->db->join('modules', 'modules.module_id=concat(\'items_stock\', location_id)'); - $this->db->join('permissions', 'permissions.module_id=modules.module_id'); - $this->db->where('person_id', $this->session->userdata('person_id')); $this->db->limit($limit); $this->db->offset($offset); return $this->db->get(); @@ -25,9 +22,6 @@ class Stock_locations extends CI_Model { $this->db->select('location_name'); $this->db->from('stock_locations'); - $this->db->join('modules', 'modules.module_id=concat(\'items_stock\', location_id)'); - $this->db->join('permissions', 'permissions.module_id=modules.module_id'); - $this->db->where('person_id', $this->session->userdata('person_id')); $this->db->where('deleted', 0); return $this->db->get(); } @@ -43,8 +37,8 @@ class Stock_locations extends CI_Model function get_undeleted_all() { $this->db->from('stock_locations'); - $this->db->join('modules', 'modules.module_id=concat(\'items_stock\', location_id)'); - $this->db->join('permissions', 'permissions.module_id=modules.module_id'); + $this->db->join('permissions','permissions.location_id=stock_locations.location_id'); + $this->db->join('grants','grants.permission_id=permissions.permission_id'); $this->db->where('person_id', $this->session->userdata('person_id')); $this->db->where('deleted',0); return $this->db->get(); @@ -64,9 +58,8 @@ class Stock_locations extends CI_Model function get_default_location_id() { $this->db->from('stock_locations'); - // TODO replace with extra join on ospos_grants - $this->db->join('modules', 'modules.module_id=concat(\'items_stock\', location_id)'); - $this->db->join('permissions', 'permissions.module_id=modules.module_id'); + $this->db->join('permissions','permissions.location_id=stock_locations.location_id'); + $this->db->join('grants','grants.permission_id=permissions.permission_id'); $this->db->where('person_id', $this->session->userdata('person_id')); $this->db->where('deleted',0); $this->db->limit(1); @@ -123,19 +116,21 @@ class Stock_locations extends CI_Model { $location_data = array('location_name'=>$location,'deleted'=>0); $this->db->insert('stock_locations',$location_data); - // insert new module for stock location $location_id = $this->db->insert_id(); - $module_id = 'items_stock'.$location_id; - $module_name = 'module_'.$module_id; - $module_data = array('name_lang_key' => $module_name, 'desc_lang_key' => $module_name.'_desc', 'module_id' => $module_id); - $this->db->insert('modules', $module_data); - // insert permissions for stock location + + // insert new permission for stock location + $permission_id = 'items_'.$location; + $permission_data = array('permission_id'=>$permission_id,'module_id'=>'items','location_id' => $location_id); + $this->db->insert('permissions', $permission_data); + + // insert grants for new permission $employees = $this->Employee->get_all(); foreach ($employees->result_array() as $employee) { - $permission_data = array('module_id' => $module_id, 'person_id' => $employee['person_id']); - $this->db->insert('permissions', $permission_data); + $grants_data = array('permission_id' => $permission_id, 'person_id' => $employee['person_id']); + $this->db->insert('grants', $grants_data); } + // insert quantities for existing items $items = $this->Item->get_all(); foreach ($items->result_array() as $item) diff --git a/application/views/employees/form.php b/application/views/employees/form.php index 03d928f69..465d46488 100644 --- a/application/views/employees/form.php +++ b/application/views/employees/form.php @@ -54,30 +54,27 @@ $password_label_attributes = $person_info->person_id == "" ? array('class'=>'req result() as $module) { - if (sizeof(explode('_', $module->module_id)) == 1) - { ?>
  • -module_id,$this->Employee->has_permission($module->module_id,$person_info->person_id)); ?> +module_id,$this->Employee->has_permission($module->module_id,$person_info->person_id)); ?> lang->line('module_'.$module->module_id);?>: lang->line('module_'.$module->module_id.'_desc');?> result() as $submodule) + foreach($all_subpermissions->result() as $permission) + { + $exploded_permission = explode('_', $permission->permission_id); + if ($permission->module_id == $module->module_id) { - $exploded_submodule_id = explode('_', $submodule->module_id); - if (sizeof($exploded_submodule_id) > 1 && $exploded_submodule_id[0] == $module->module_id) - { - $lang_line = $this->lang->line('reports_'.$exploded_submodule_id[1]); - $lang_line = empty($lang_line) ? $this->Stock_locations->get_location_name(substr($exploded_submodule_id[1], -1)) : $lang_line; - ?> - - lang->line('reports_'.$exploded_permission[1]); + $lang_line = empty($lang_line) ? $exploded_permission[1] : $lang_line; + ?> + + li > input[name='permissions[]']").each(function() + $("ul#permission_list > li > input[name='grants[]']").each(function() { var $this = $(this); $("ul > li > input", $this.parent()).each(function() @@ -164,7 +161,7 @@ $(document).ready(function() { equalTo: "#password" }, - email: "email", "permissions[]" : { + email: "email", "grants[]" : { required : function(element) { var checked = false; $("ul#permission_list > li > input:checkbox").each(function() @@ -216,7 +213,7 @@ $(document).ready(function() equalTo: "lang->line('employees_password_must_match'); ?>" }, email: "lang->line('common_email_invalid_format'); ?>", - "permissions[]": "fill in correctly!!" + "grants[]": "fill in correctly!!" } }); }); diff --git a/application/views/partial/header.php b/application/views/partial/header.php index 9b2514a18..3f65a343f 100644 --- a/application/views/partial/header.php +++ b/application/views/partial/header.php @@ -44,16 +44,13 @@ html { result() as $module) { - if (sizeof(explode('_', $module->module_id)) == 1) - { - ?> + ?> - diff --git a/application/views/reports/listing.php b/application/views/reports/listing.php index a3383c751..dc49fa9e8 100644 --- a/application/views/reports/listing.php +++ b/application/views/reports/listing.php @@ -1,18 +1,13 @@ - load->view("partial/header"); ?>
    lang->line('reports_reports'); ?>
    lang->line('reports_welcome_message'); ?>