db->where('md5(id)',$id); $this->db->update($table,$action); return; } //is logged in public function is_logged_in() { //check if user logged in if ($this->session->userdata('logged_in') == TRUE && !empty($this->get_user($this->session->userdata('id')))) { return true; } else { return false; } } //function get user public function get_logged_user() { if ($this->is_logged_in()) { $this->db->select('u.*'); $this->db->from('users as u'); // $this->db->join('country as c', 'c.id = u.country', 'LEFT'); $this->db->where('u.id', $this->session->userdata('id')); $query = $this->db->get(); return $query->row(); } } public function get_logged_business( $id) { $this->db->select('B.*'); $this->db->from('business as B'); $this->db->where('B.uid', $id); $query = $this->db->get(); return $query->row(); } public function get_logged_employee() { if ($this->is_logged_in()) { $this->db->select('u.*, e.*'); $this->db->from('users as u'); $this->db->join('employees as e', 'e.user_id = u.id', 'LEFT'); $this->db->where('u.id', $this->session->userdata('id')); $query = $this->db->get(); return $query->row(); } } public function modules() { $this->db->select('module_id'); $this->db->from('permit_modules'); $this->db->where('uid', $this->session->userdata('business_id')); $this->db->where('is_active', 1); $query = $this->db->get(); return $query->result(); } public function group_membership() { $this->db->select('group_permisssion.group_id, group_permisssion.module_id'); $this->db->from('group_permisssion'); $this->db->join('group_membership', 'group_membership.group_id = group_permisssion.group_id'); $this->db->where('group_membership.emp_id', $this->session->userdata('id')); $this->db->where('group_membership.business_id', $this->session->userdata('business_id')); $this->db->where('group_permisssion.is_active', '1'); $query = $this->db->get(); return $query->result(); } public function Employee_group($myArray) { //$this->db->select('group_permisssion.group_id, group_permisssion.module_id'); $this->db->from('group_permisssion'); $this->db->join('group_membership', 'group_membership.group_id = group_permisssion.group_id'); $this->db->where('group_membership.group_id', $myArray[0]); $this->db->where('group_membership.emp_id', $this->session->userdata('id')); $this->db->where('group_permisssion.module_id', $myArray[1]); $this->db->where('group_permisssion.is_active', '1'); $query = $this->db->get(); return true; } //get user by id public function get_user($id) { $this->db->where('id', $id); $query = $this->db->get('users'); return $query->row(); } //is super admin public function is_superadmin() { // get_header_info(); //check logged in if (!$this->is_logged_in()) { return false; } //check role if (user()->role == 'sadmin') { return true; } else { return false; } } //is admin public function is_admin() { // get_header_info(); //check logged in if (!$this->is_logged_in()) { return false; } //check role if (user()->role == 'admin') { return true; } else { return false; } } //is user public function is_user() { // get_header_info(); //check logged in if (!$this->is_logged_in()) { return false; } //check role if (user()->role == 'user') { return true; } else { return false; } } //is pro user public function is_pro_user() { //check logged in if (!$this->is_logged_in()) { return false; } //check role if (user()->role == 'user' && user()->account_type == 'pro') { return true; } else { return false; } } //logout public function logout() { //unset user data $this->session->unset_userdata('logged_in'); $this->session->unset_userdata('admin_logged_in'); $this->session->unset_userdata('app_key'); $this->session->sess_destroy(); } // check valid user function validate_user() { $this->db->select('*'); $this->db->from('users'); $this->db->where('email', $this->input->post('user_name')); $this->db->or_where('user_name', $this->input->post('user_name')); // $this->db->where('is_active', 1); $this->db->limit(1); $query = $this->db->get(); if($query->num_rows() == 1){ return $query->row(); }else{ return false; } } // check valid user function validateUserForOtp($data, $where) { $this->db->select('*'); $this->db->from('users'); $this->db->where($where, $data); $this->db->limit(1); $query = $this->db->get(); if($query->num_rows() == 1){ return $query->row(); }else{ return false; } } // check valid Business function validateBusiness($business_id) { $this->db->select('*'); $this->db->from('business'); $this->db->where('is_active', 1); $this->db->where('uid', $business_id); $this->db->limit(1); $query = $this->db->get(); if($query->num_rows() == 1){ return $query->row(); }else{ return false; } } // check valid staff function validate_role() { $this->db->select('*'); $this->db->from('users_role'); $this->db->where('email', $this->input->post('user_name')); $this->db->limit(1); $query = $this->db->get(); if($query->num_rows() > 0) { return $query->row(); } else{ return FALSE; } } public function send_email($to, $subject, $message) { $this->load->library('email'); $settings = get_settings(); if ($settings->mail_protocol == "mail") { $config = Array( 'protocol' => 'mail', 'smtp_host' => $settings->mail_host, 'smtp_port' => $settings->mail_port, 'smtp_user' => $settings->mail_username, 'smtp_pass' => $settings->mail_password, 'smtp_timeout' => 100, 'mailtype' => 'html', 'charset' => 'utf-8', 'wordwrap' => TRUE ); } else { $config = Array( 'protocol' => 'smtp', 'smtp_host' => $settings->mail_host, 'smtp_port' => $settings->mail_port, 'smtp_user' => $settings->mail_username, 'smtp_pass' => $settings->mail_password, 'smtp_timeout' => 100, 'mailtype' => 'html', 'charset' => 'utf-8', 'wordwrap' => TRUE ); } //initialize $this->email->initialize($config); //send email $this->email->from($settings->mail_username, $settings->application_name); $this->email->to($to); $this->email->subject($subject); $this->email->message($message); $this->email->set_newline("\r\n"); return $this->email->send(); } }