function get_all_user_groups_name($user_id) { $user_groups_name = array(); $ci =& get_instance(); $user_groups = get_all_user_groups($user_id); $ci->db->select('name'); $ci->db->from('user_groups'); $ci->db->where_in('id', $user_groups); $result = $ci->db->get()->result_array(); foreach ($result as $r) { $user_groups_name[] = $r['name']; } return $user_groups_name; }
public function saveUser($data) { $now_date = strtotime("now"); $this->db->insert('users', array('usercode' => $data['code'], 'user_group_id' => $data['user_type'], 'username' => $data['user_name'], 'password' => md5($data['new_password']), 'email' => $data['user_email'], 'contact_no' => $data['user_contact'], 'last_login' => date('Y-m-d H:i:s'), 'created' => $now_date, 'updated' => $now_date, 'active' => 'Yes', 'approve' => 1)); /** To get last insert ID **/ $user_id = $this->db->insert_id(); $user_meta_fields = array('user_type' => 'agent_type', 'bus_name' => 'bus_name', 'user_contact' => 'contact_no', 'user_area' => 'area', 'user_city' => 'city', 'user_state' => 'state', 'user_country' => 'country', 'alt_contact' => 'alt_contact_no'); if (in_array($data['user_type'], get_all_user_groups($user_id))) { $this->db->update('user_groups_mapping', array('updated' => $now_date)); } else { $this->db->insert('user_groups_mapping', array('user_id' => $user_id, 'user_group_id' => $data['user_type'], 'created' => $now_date, 'updated' => $now_date)); } foreach ($user_meta_fields as $k => $v) { $this->db->insert('user_meta', array('user_id' => $user_id, 'meta_key' => $v, 'meta_value' => $data[$k])); } return true; }
public function login() { $username = $this->input->post('username'); $password = $this->input->post('password'); $result = $this->db->get_where('users', array('username' => $username, 'password' => md5($password), 'status' => '1')); if ($result->num_rows() > 0) { $first_row = $result->first_row(); $user = (array) $first_row; //echo '<pre>'; print_r($user); exit; $user['user_group_id'] = get_all_user_groups($first_row->id); $this->session->set_userdata($user); //echo '<pre>'; print_r($first_row->id); exit; $now_date = strtotime("now"); $this->db->update('users', array('last_login' => $now_date), array('id' => $first_row->id)); return true; } else { return false; } }
</TD> </TR> </TABLE> <? ?> </fieldset> <br/> <br/> <fieldset> <legend>Rights</legend> <p> Group Selection </p> <TABLE class="menu"> <? $totalGroups = get_all_user_groups(); ?> <TR class="menu"><TH class="menu">Available Groups</TH><TH class="menu"></TH><TH class="menu">Current Groups</TH></TR> <TR class="menu"> <TD class="menu"> <SELECT class="paramlist" name = "list1" size = "5" onDblClick="moveSelectedOptions(this.form['list1'],this.form['list2'])"> <? foreach ($totalGroups as $value) { $valueTmp = str_replace("___", "\M", $value); $valueArray = explode ("\M", $valueTmp); $groupId = $valueArray[0]; $groupName = $valueArray[1]; echo "<option value =\"$groupName\">$groupName"; } ?>
public function save_user() { $this->load->model('case_model'); $this->load->helper('global_helper'); $id = 0; $data['user_group_id'] = $this->input->post('user_type'); $data['username'] = $this->input->post('user_name'); $data['password'] = md5($this->input->post('new_password')); $data['email'] = $this->input->post('user_email'); $data['contact_no'] = $this->input->post('user_contact'); $data['city_id'] = $this->input->post('user_city'); $data['state_id'] = $this->input->post('user_state'); $data['country_id'] = $this->input->post('user_country'); if ($data['user_group_id'] == 4 || $data['user_group_id'] == 5) { $data['first_name'] = $this->input->post('bus_name'); } else { $data['first_name'] = $this->input->post('first_name'); $data['last_name'] = $this->input->post('last_name'); } $data['address'] = $this->input->post('user_area'); $data['created'] = strtotime("now"); $data['updated'] = strtotime("now"); $data['last_login'] = strtotime("now"); if ($id == 0) { $max = $this->case_model->maxUserVal($data['user_group_id']); $max = $max == 0 ? '001' : (strlen($max) == 1 ? '00' . ($max + 1) : '0' . ($max + 1)); if ($data['user_group_id'] == 4) { $code = 'A' . $max; } else { if ($data['user_group_id'] == 5) { $code = 'C' . $max; } else { if ($data['user_group_id'] == 2) { $code = 'U' . $max; } else { $code = 'W' . $max; } } } $data['usercode'] = $code; } if (isset($id) && $id > 0) { if (strlen($password) > 0) { $this->db->update('users', array('rid' => $role, 'username' => $username, 'password' => md5($password), 'temp_pwd' => $password), array('uid' => $uid)); } else { $this->db->update('users', array('rid' => $role, 'username' => $username), array('uid' => $uid)); } } else { $this->db->insert('users', $data); } if ($id == 0) { $id = $this->db->insert_id(); } if (in_array($data['user_group_id'], get_all_user_groups($id))) { $this->db->update('user_groups_mapping', array('updated' => $data['updated'])); } else { $this->db->insert('user_groups_mapping', array('user_id' => $id, 'user_group_id' => $data['user_group_id'], 'created' => $data['updated'], 'updated' => $data['updated'])); } return true; }