<commit_before><?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Edit_user extends CI_Capstone_Controller
{

        function __construct()
        {
                parent::__construct();
                /**
                 * just to make sure
                 */
                if ( ! $this->ion_auth->is_admin())
                {
                        show_error(lang('access_denied_of_current_user_group'));
                }
                $this->load->library('form_validation');
                $this->form_validation->set_error_delimiters('<span class="help-inline">', '</span> ');
                $this->breadcrumbs->unshift(2, lang('administrators_label'), '#');
                $this->breadcrumbs->unshift(3, lang('index_heading'), 'users');
        }

        private function set_hook($user_id)
        {
                /**
                 * set hook for add data in update_at, after success updating data
                 */
                $this->ion_auth->set_hook(
                        'post_update_user_successful', 'update_at', $this/* $this because the class already extended */, 'add_update_at_data_user_column', array($this->ion_auth_model->tables['users'], $user_id)
                );
        }

        public function index()
        {

                if ( ! ($user_id = $this->input->get('user-id')))
                {
                        show_error('Invalid request.');
                }

                $this->data['title'] = $this->lang->line('edit_user_heading');



                $user = $this->ion_auth->user($user_id)->row();

                $this->set_hook($user->id);
                if ( ! $user)
                {
                        show_error('Invalid request.');
                }

                $this->breadcrumbs->unshift(3, 'Edit User [ ' . $user->last_name . ', ' . $user->first_name . ' ]', 'edit-user?user-id=' . $user->id);

                $groups        = $this->ion_auth->groups()->result_array();
                $currentGroups = $this->ion_auth->get_users_groups($user->id)->result();

                //just 
                // validate form input
                $this->form_validation->set_rules('first_name', $this->lang->line('edit_user_validation_fname_label'), 'trim|required|human_name');
                $this->form_validation->set_rules('last_name', $this->lang->line('edit_user_validation_lname_label'), 'trim|required|human_name');
                $this->form_validation->set_rules('phone', $this->lang->line('edit_user_validation_phone_label'), 'trim');
                $this->form_validation->set_rules('company', $this->lang->line('edit_user_validation_company_label'), 'trim');

                if ($this->form_validation->run())
                {


                        // update the password if it was posted
                        if ($this->input->post('password', TRUE))
                        {
                                $this->form_validation->set_rules('password', $this->lang->line('edit_user_validation_password_label'), 'trim|required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]|no_space|password_level[3]');
                                $this->form_validation->set_rules('password_confirm', $this->lang->line('edit_user_validation_password_confirm_label'), 'trim|required');
                        }

                        if ($this->form_validation->run() === TRUE)
                        {
                                $data = array(
                                    'first_name' => $this->input->post('first_name', TRUE),
                                    'last_name'  => $this->input->post('last_name', TRUE),
                                    'company'    => $this->input->post('company', TRUE),
                                    'phone'      => $this->input->post('phone', TRUE),
                                );

                                // update the password if it was posted
                                if ($this->input->post('password', TRUE))
                                {
                                        $data['password'] = $this->input->post('password', TRUE);
                                }



                                // Only allow updating groups if user is admin
                                if ($this->ion_auth->is_admin())
                                {
                                        //Update the groups user belongs to
                                        $groupData = $this->input->post('groups', TRUE);

                                        if (isset($groupData) && ! empty($groupData))
                                        {

                                                $this->ion_auth->remove_from_group('', $user_id);

                                                foreach ($groupData as $grp)
                                                {
                                                        $this->ion_auth->add_to_group($grp, $user_id);
                                                }
                                        }
                                }

                                // check to see if we are updating the user
                                if ($this->ion_auth->update($user->id, $data))
                                {
                                        /**
                                         * delete all query cache 
                                         */
                                        $this->load->model('User_model');
                                        $this->User_model->delete_cache();
                                        /**
                                         * refresh session data
                                         * if edit from current user
                                         */
                                        $user_obj = $this->ion_auth->user()->row();
                                        if ($user_obj->id == $user->id)
                                        {
                                                $this->session->set_userdata(array(
                                                    'user_first_name' => $user_obj->first_name,
                                                    'user_last_name'  => $user_obj->last_name
                                                ));
                                        }
                                        // redirect them back to the admin page if admin, or to the base url if non admin
                                        $this->session->set_flashdata('message', $this->ion_auth->messages());
                                        if ($this->ion_auth->is_admin())
                                        {
                                                redirect(site_url('users'), 'refresh');
                                        }
                                        else
                                        {
                                                redirect('/', 'refresh');
                                        }<commit_msg>dis allowed remove current user from admin,then fix refresh session of current user edit<commit_after><?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Edit_user extends CI_Capstone_Controller
{

        function __construct()
        {
                parent::__construct();
                /**
                 * just to make sure
                 */
                if ( ! $this->ion_auth->is_admin())
                {
                        show_error(lang('access_denied_of_current_user_group'));
                }
                $this->load->library('form_validation');
                $this->form_validation->set_error_delimiters('<span class="help-inline">', '</span> ');
                $this->breadcrumbs->unshift(2, lang('administrators_label'), '#');
                $this->breadcrumbs->unshift(3, lang('index_heading'), 'users');
        }

        private function set_hook($user_id)
        {
                /**
                 * set hook for add data in update_at, after success updating data
                 */
                $this->ion_auth->set_hook(
                        'post_update_user_successful', 'update_at', $this/* $this because the class already extended */, 'add_update_at_data_user_column', array($this->ion_auth_model->tables['users'], $user_id)
                );
        }

        public function index()
        {

                if ( ! ($user_id = $this->input->get('user-id')))
                {
                        show_error('Invalid request.');
                }

                $this->data['title'] = $this->lang->line('edit_user_heading');



                $user = $this->ion_auth->user($user_id)->row();

                $this->set_hook($user->id);
                if ( ! $user)
                {
                        show_error('Invalid request.');
                }

                $this->breadcrumbs->unshift(3, 'Edit User [ ' . $user->last_name . ', ' . $user->first_name . ' ]', 'edit-user?user-id=' . $user->id);

                $groups        = $this->ion_auth->groups()->result_array();
                $currentGroups = $this->ion_auth->get_users_groups($user->id)->result();

                //just 
                // validate form input
                $this->form_validation->set_rules('first_name', $this->lang->line('edit_user_validation_fname_label'), 'trim|required|human_name');
                $this->form_validation->set_rules('last_name', $this->lang->line('edit_user_validation_lname_label'), 'trim|required|human_name');
                $this->form_validation->set_rules('phone', $this->lang->line('edit_user_validation_phone_label'), 'trim');
                $this->form_validation->set_rules('company', $this->lang->line('edit_user_validation_company_label'), 'trim');

                if ($this->form_validation->run())
                {


                        // update the password if it was posted
                        if ($this->input->post('password', TRUE))
                        {
                                $this->form_validation->set_rules('password', $this->lang->line('edit_user_validation_password_label'), 'trim|required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]|no_space|password_level[3]');
                                $this->form_validation->set_rules('password_confirm', $this->lang->line('edit_user_validation_password_confirm_label'), 'trim|required');
                        }

                        if ($this->form_validation->run() === TRUE)
                        {
                                $data = array(
                                    'first_name' => $this->input->post('first_name', TRUE),
                                    'last_name'  => $this->input->post('last_name', TRUE),
                                    'company'    => $this->input->post('company', TRUE),
                                    'phone'      => $this->input->post('phone', TRUE),
                                );

                                // update the password if it was posted
                                if ($this->input->post('password', TRUE))
                                {
                                        $data['password'] = $this-><PASSWORD>->post('password', TRUE);
                                }



                                // Only allow updating groups if user is admin
                                if ($this->ion_auth->is_admin())
                                {
                                        //Update the groups user belongs to
                                        $group_ids = $this->input->post('groups', TRUE);

                                        /**
                                         * if current user has admin group,then remove in edit,
                                         * show error for do not remove admin if current user is admin
                                         */
                                        if ( ! $group_ids)
                                        {
                                                /**
                                                 * make sure atleast one selected 
                                                 */
                                                show_error('empty user_group not allowed.');
                                        }

                                        /**
                                         * if current user
                                         */
                                        if ($this->session->userdata('user_id') == $user->id)
                                        {
                                                //get id of admin from db
                                                $this->load->model('Group_model');
                                                $admin_id = $this->Group_model->where(array('name' => $this->config->item('admin_group', 'ion_auth')))->get()->id;
                                                /**
                                                 * check admin_id if has in post
                                                 */
                                                if ( ! in_array($admin_id, $group_ids))
                                                {
                                                        show_error('cannot remove from admin a current user');
                                                }
                                        }

                                        if (isset($group_ids) && ! empty($group_ids))
                                        {

                                                $this->ion_auth->remove_from_group('', $user_id);

                                                foreach ($group_ids as $grp)
                                                {
                                                        $this->ion_auth->add_to_group($grp, $user_id);
                                                }
                                        }
                                }

                                // check to see if we are updating the user
                                if ($this->ion_auth->update($user->id, $data))
                                {
                                        /**
                                         * delete all query cache 
                                         */
                                        $this->load->model('User_model');
                                        $this->User_model->delete_cache();
                                        /**
                                         * refresh session data
                                         * if edit from current user
                                         */
                                        if ($this->session->userdata('user_id') == $user->id)
                                        {
                                                /**
                                                 * refreshing session data of current user
                                                 */
                                                $this->set_session_data_session(); //from my_controlerr
                                        }
                                        // redirect them back to the admin page if admin, or to the base url if non admin
                                        $this->session->set_flashdata('message', $this->ion_auth->messages());
                                        if ($this->ion_auth->is_admin())
                                        {
                                                redirect(site_url('users'), 'refresh');
                                        }
                                        else
                                        {
                                                redirect('/', 'refresh');
                                        }
{'fraction_non_alphanumeric': 0.11262421788737578, 'fraction_numerical': 0.000490737332842596, 'mean_word_length': 0.8843042071197411, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 249, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 177, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2121815', 'n_tokens_mistral': 3312, 'n_tokens_neox': 3146, 'n_words': 576}