public function edit($pkey, $method = "echo") { _has_user_access_permission(TRUE, array('admin', 'management_company')); $output = array('message' => "", 'status' => ""); $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array(); $company_id = $this->current_user->group_id == GROUP_ADMIN ? 0 : $this->current_user->company_id; $user_id = isset($params[SYS_USER_ID]) && gtzero_integer($params[SYS_USER_ID]) ? to_int($params[SYS_USER_ID]) : 0; $redirect_url = $this->_post_args('redirect_url', ARGS_TYPE_STRING, $this->agent->referrer()); $user_info = $this->user_m->details($user_id); if (!$user_info || _has_company_group_access($this->current_user->group_id) && $user_info->company_id != $this->current_user->company_id || $this->current_user->user_id == $user_id) { $this->show_permission_denied_error($method); } $group_id = $this->_post_args("group_id", ARGS_TYPE_INT, $user_info->group_id); $company_id = $this->current_user->group_id == GROUP_ADMIN ? $this->_post_args('company_id', ARGS_TYPE_INT, $user_info->company_id) : $this->current_user->company_id; $this->form_validation->set_rules('group_id', 'Group', 'required|callback__check_user_group'); if ($this->current_user->group_id == GROUP_ADMIN) { $this->form_validation->set_rules('company_id', 'Agency', 'callback__check_user_company'); } $this->form_validation->set_rules('client_ids', 'Client', 'callback__check_user_company_clients'); if ($this->current_user->group_id == GROUP_ADMIN) { $this->form_validation->set_rules('email', 'Email Address', 'required|valid_email|is_unique[users.email.id.' . $user_id . ']'); } $this->form_validation->set_rules('first_name', 'First Name', 'required|xss_clean'); $this->form_validation->set_rules('last_name', 'Last Name', 'trim|xss_clean'); $this->form_validation->set_rules('phone', 'Phone Number', 'required|xss_clean|min_length[3]'); //$this->form_validation->set_rules('postcode', 'Postcode', 'trim|xss_clean'); //$this->form_validation->set_rules('workhours', 'Working Hours', 'trim|xss_clean'); if ($this->input->post('password')) { $this->form_validation->set_rules('password', 'Password', 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]'); $this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required'); } if ($this->form_validation->run() == TRUE) { $company_id = $this->current_user->group_id == GROUP_ADMIN ? $this->_post_args('company_id', ARGS_TYPE_INT) : $this->current_user->company_id; //$company_info = $this->company_m->company_detail($company_id); //$company_settings = $this->company_m->company_settings($company_id); //$gmt_offset = ( _check_company_user_access($group_id) && $company_id > 0) ? $company_settings->gmt_offset : ( ( $this->current_user->group_id == GROUP_ADMIN ) ? $this->current_user->gmt_offset : $this->current_user->company_settings->gmt_offset); $input_data = array('email' => $this->current_user->group_id == GROUP_ADMIN ? $this->_post_args('email', ARGS_TYPE_STRING) : $user_info->email, 'first_name' => $this->_post_args('first_name', ARGS_TYPE_STRING), 'last_name' => $this->_post_args('last_name', ARGS_TYPE_STRING), 'phone' => $this->_post_args('phone', ARGS_TYPE_STRING), 'gmt_offset' => $this->_post_args('gmt_offset', ARGS_TYPE_STRING, $this->cfg->gmt_offset, array('override' => TRUE))); if ($this->_post_args('password', ARGS_TYPE_STRING)) { $input_data['password'] = $this->_post_args('password', ARGS_TYPE_STRING); } /*$user_avatar = $this->_post_args('user_avatar_img', ARGS_TYPE_STRING); if( array_key_exists('user_avatar_img', $_POST) && !empty($user_avatar) ){ $additional_data['avatar'] = $user_avatar; } elseif( ($user_avatar = $this->upload_avatar()) && empty($user_avatar['error']) && !empty($user_avatar['file_name']) ) { $additional_data['avatar'] = $user_avatar['file_name']; }*/ $is_record_updated = $this->ion_auth->update($user_id, $input_data); $group = array($group_id); $this->user_m->update_user_group($user_id, $group_id); if (_has_company_resources($group_id)) { if (gtzero_integer($user_info->company_id) && $user_info->company_id != $company_id) { $this->user_m->delete_user_company($user_id); } $this->user_m->update_user_company($user_id, $company_id, $group_id); $this->user_m->delete_user_clients($user_id); } elseif (_has_company_non_resources($group_id)) { $this->user_m->delete_user_company($user_id); $client_ids = $this->_post_args('client_ids', ARGS_TYPE_ARRAY); $this->user_m->update_user_clients($user_id, $client_ids, $company_id); } elseif ($group_id == GROUP_ADMIN) { $this->user_m->delete_user_clients($user_id); $this->user_m->delete_user_company($user_id); } if ($is_record_updated) { $output['message'] = sprintf('The user "%s" was updated.', $user_info->first_name . ' ' . $user_info->last_name); $output['status'] = SUCCESS_MESSAGE; $output['user_id'] = $user_id; $this->user_m->clear_user_profile_cache(array('user_id' => $user_id, 'company_id' => $company_id, 'old_company_id' => $user_info->company_id)); //trigger_trip("user_updated", $company_id, array('user_id' => $user_id, 'updated_by' => $this->current_user->user_id)); } else { $output['message'] = sprintf('Unable to Update Account Information for user "%s". Please report the issue to %s', $user_info->first_name . ' ' . $user_info->last_name, $this->cfg->contact_email); $output['status'] = ERROR_MESSAGE; } $this->_output_request($output, $redirect_url); } else { if (validation_errors()) { $output['message'] = validation_errors(); $output['status'] = ERROR_MESSAGE; } } $company_settings = $this->company_m->company_settings($company_id); $doc_key = $this->_post_args('doc_key', ARGS_TYPE_STRING) ? $this->_post_args('doc_key', ARGS_TYPE_STRING) : keygen(); $csrf = _get_csrf_nonce(); $gmt_offset = _check_company_user_access($group_id) && $company_id > 0 ? $company_settings->gmt_offset : ($this->current_user->group_id == GROUP_ADMIN ? $this->current_user->gmt_offset : $this->current_user->company_settings->gmt_offset); $data = array("user_id" => $user_id, 'form_action_type' => FORM_ACTION_EDIT, 'form_action' => site_url('users/edit/' . $pkey), 'cancel_url' => $redirect_url, 'page' => 'user/form', 'title' => 'User Detail', 'submit_btn_text' => 'Save Changes', 'first_name' => $this->_post_args('first_name', ARGS_TYPE_STRING, $user_info->first_name), 'last_name' => $this->_post_args('last_name', ARGS_TYPE_STRING, $user_info->last_name), 'email' => $this->_post_args('email', ARGS_TYPE_STRING, $user_info->email), 'phone' => $this->_post_args('phone', ARGS_TYPE_STRING, $user_info->phone), 'password' => '', 'password_confirm' => '', 'company_id' => $company_id, 'client_ids' => $this->_post_args('client_ids', ARGS_TYPE_ARRAY, isset($user_info->client_ids) ? $user_info->client_ids : array()), 'group_id' => $this->_post_args('group_id', ARGS_TYPE_INT, $user_info->group_id), 'gmt_offset' => $this->_post_args('gmt_offset', ARGS_TYPE_STRING, !empty($user_info->gmt_offset) ? $user_info->gmt_offset : $gmt_offset), 'scripts' => array('user/form.js'), 'hiddenvars' => array_merge($csrf, array('redirect_url' => $redirect_url)), 'doc_key' => $doc_key); if ($this->input->is_ajax_request()) { $html = $this->template->raw_view('pages/user/form_modal', $data, TRUE); if ($method == "ajax") { $output['html'] = $html; $this->_output_request($output, $redirect_url); } else { echo $html; } } else { if (!empty($output['status'])) { set_flash_data($output['status'], $output['message'], FALSE); } $this->template->load('default', $data); } }
" class="btn btn-primary btn-xs" data-ajax="wdpajax" data-options='{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Agency Detail", "modal" : {"buttons" : true, "modal_success_callback" : "gl.user.form._init_companies(response);", "override" : true}, "params" : "echo"}'> <i class="fa fa-level-up"></i> </a> </div> </div> <?php echo form_error('company_id', '<label class="error">', '</label>'); ?> </div> </div> <?php } ?> <div class="form-group client_option" <?php echo _has_company_non_resources($group_id) && gtzero_integer($company_id) ? '' : 'style="display:none;"'; ?> > <label class="col-sm-4 control-label no-padding-right" for="client_ids">Client:</label> <div class="col-sm-8"> <div class="row"> <div class="col-sm-10"> <?php echo form_dropdown('client_ids[]', clients_dropdown('return', array('company_id' => $company_id, 'first_row' => TRUE)), $client_ids, 'id="client_ids" class="form-control input-sm" data-placeholder="Select a Client" multiple="multiple"'); ?> </div> <div class="col-sm-2"> <a href="<?php echo site_url('clients/create/' . serialize_object()); ?> " class="btn btn-primary btn-xs" data-ajax="wdpajax" data-options='{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Client detail", "modal" : {"buttons" : true, "modal_success_callback" : "gl.user.form._init_clients(response);", "override" : true}, "params" : "echo"}'>
public function update_user_company($user_id, $company_id, $group_id) { if (_has_company_non_resources($group_id)) { return FALSE; } if ($this->check_if_company_exists($user_id)) { $this->db->where('user_id', to_int($user_id)); $return = $this->db->update('user_company', array("company_id" => to_int($company_id))); } else { $return = $this->db->insert('user_company', array("company_id" => to_int($company_id), "user_id" => to_int($user_id))); } return $return; }