function getRoleInput($input_name, $user_id)
 {
     $ci =& get_instance();
     $user_roles = Security_helper::getUserRoles($user_id);
     $value_groups = array();
     foreach ($user_roles as $role) {
         $value_groups[] = $role->role_id;
     }
     $html = '<select size="8" name="' . $input_name . '">';
     $optgroup = '';
     $roles = Security_helper::getRoles();
     foreach ($roles as $row) {
         if (true === empty($row->role_id)) {
             if ($optgroup != $row->name) {
                 if (true === empty($optgroup)) {
                     $html .= '</optgroup>';
                 }
                 $html .= '<optgroup label="' . $row->name . '">';
                 $optgroup = $row->name;
             }
         } else {
             $html .= '<option value="' . $row->role_id . '"' . (true == in_array($row->role_id, $value_groups) ? ' selected="selected"' : '') . '>' . $row->name . '&nbsp;&nbsp;&nbsp;</option>';
         }
     }
     $html .= '</optgroup></select>';
     return $html;
 }
Exemple #2
0
 public function loginUser($name, $password, &$usersession)
 {
     $ci =& get_instance();
     $query = 'SELECT * FROM ' . $ci->db->protect_identifiers('users') . ' WHERE username = ?';
     $rs = $ci->db->query($query, array($name));
     if (0 < $rs->num_rows()) {
         $row = $rs->row();
         $pwd_arr = explode(':', $row->password);
         if (1 < sizeof($pwd_arr)) {
             $password = $password . $pwd_arr[1];
         }
         if (md5($password) == $pwd_arr[0]) {
             $usersession->id = $row->id;
             $usersession->name = $row->username;
             $usersession->roles = array();
             $roles = Security_helper::getUserRoles($usersession->id);
             foreach ($roles as $role) {
                 $usersession->roles[] = $role->name;
             }
             return true;
         }
     }
     return false;
 }