function edit_user($id = null) { $this->data['title'] = "Edit User"; if (!$this->ion_auth->logged_in()) { redirect('auth', 'refresh'); } if (is_admin()) { $id = $id; } else { $id = $this->session->userdata('user_id'); } $nik = get_nik($id); $user_bu = get_user_buid($nik); $user = getAll('users', array('id' => 'where/' . $id))->row(); if ($this->ion_auth->is_admin_by_id($id)) { $groups = $this->ion_auth->groups()->result_array(); } else { $groups = $this->ion_auth->where("(`bu` = '{$user_bu}' or `admin_type_id` = '1')", null, false)->groups()->result_array(); } $currentGroups = $this->ion_auth->get_users_groups($id)->result(); //validate form input $this->form_validation->set_rules('first_name', $this->lang->line('edit_user_validation_fname_label'), 'xss_clean'); $this->form_validation->set_rules('last_name', $this->lang->line('edit_user_validation_lname_label'), 'xss_clean'); $this->form_validation->set_rules('bod', $this->lang->line('edit_user_validation_bod_label'), 'xss_clean'); $this->form_validation->set_rules('marital_id', $this->lang->line('edit_user_validation_marital_label'), 'xss_clean'); $this->form_validation->set_rules('groups', $this->lang->line('edit_user_validation_groups_label'), 'xss_clean'); $this->form_validation->set_rules('photo', $this->lang->line('edit_user_validation_photo_label'), 'xss_clean'); if (isset($_POST) && !empty($_POST)) { $first_name = getValue('first_name', 'users', array('id' => 'where/' . $id)); $last_name = getValue('last_name', 'users', array('id' => 'where/' . $id)); $bod = getValue('bod', 'users', array('id' => 'where/' . $id)); $marital_id = getValue('marital_id', 'users', array('id' => 'where/' . $id)); $phone = getValue('phone', 'users', array('id' => 'where/' . $id)); $previous_email = getValue('previous_email', 'users', array('id' => 'where/' . $id)); $bb_pin = getValue('bb_pin', 'users', array('id' => 'where/' . $id)); $first_name_n = $this->input->post('first_name'); $last_name_n = $this->input->post('last_name'); $bod_n = date('Y-m-d', strtotime($this->input->post('bod'))); $marital_id_n = $this->input->post('marital_id'); $phone_n = $this->input->post('phone'); $previous_email_n = $this->input->post('previous_email'); $bb_pin_n = $this->input->post('bb_pin'); if ($first_name !== $first_name_n || $last_name !== $last_name_n || $bod_n !== $bod_n || $marital_id_n !== $marital_id || $phone_n !== $phone || $previous_email !== $previous_email_n || $bb_pin !== $bb_pin_n) { $data_n = array('user_id' => $id, 'first_name_new' => !empty($first_name_n) ? $first_name_n : $first_name, 'last_name_new' => !empty($last_name_n) ? $last_name_n : $last_name, 'bod_new' => !empty($bod_n) ? $bod_n : $bod, 'marital_id_new' => !empty($marital_id_n) ? $marital_id_n : $marital_id, 'phone_new' => !empty($phone_n) ? $phone_n : $phone, 'previous_email_new' => !empty($previous_email_n) ? $previous_email_n : $previous_email, 'bb_pin_new' => !empty($bb_pin_n) ? $bb_pin_n : $bb_pin, 'is_app' => 0, 'note' => ''); $num_rows = getAll('users_edit_approval', array('user_id' => 'where/' . $id))->num_rows(); if ($num_rows > 0) { $this->db->where('user_id', $id); $this->db->update('users_edit_approval', $data_n); $edit_id = getValue('id', 'users_edit_approval', array('user_id' => 'where/' . $id)); } else { $this->db->insert('users_edit_approval', $data_n); $edit_id = $this->db->insert_id(); } $this->approval->edit_user($edit_id); $this->session->set_flashdata('message', '<div class="alert alert-info" role="alert">' . 'Pengajuan perubahan data pribadi anda sudah terkirim ke administrator untuk disetujui' . '</div>'); } //if() // do we have a valid request? /*if ($this->_valid_csrf_nonce() === FALSE || $id != $this->input->post('id')) { show_error($this->lang->line('error_csrf')); }*/ // Config for image upload $user_folder = $user->id . $user->first_name; if (!is_dir('./' . 'uploads')) { mkdir('./' . 'uploads', 0777); } if (!is_dir('./uploads/' . $user_folder)) { mkdir('./uploads/' . $user_folder, 0777); } $this->load->library('image_lib'); $config['upload_path'] = './uploads/' . $user_folder; $config['overwrite'] = TRUE; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = '3000'; //$config['encrypt_name'] = TRUE; $this->load->library('upload', $config); if (!$this->upload->do_upload('photo')) { $this->data['error'] = array('error' => $this->upload->display_errors('<div class="alert alert-danger">', '</div>')); //error } else { $upload_data = $this->upload->data(); //resize: $resize1 = '80x80'; if (!is_dir('./uploads/' . $user_folder . '/' . $resize1)) { mkdir('./uploads/' . $user_folder . '/' . $resize1, 0777); } $config = array('source_image' => $upload_data['full_path'], 'new_image' => './uploads/' . $user_folder . '/' . $resize1, 'maintain_ratio' => TRUE, 'width' => 80, 'height' => 80); $this->image_lib->initialize($config); $this->image_lib->resize(); $resize2 = '100x100'; if (!is_dir('./uploads/' . $user_folder . '/' . $resize2)) { mkdir('./uploads/' . $user_folder . '/' . $resize2, 0777); } $config = array('source_image' => $upload_data['full_path'], 'new_image' => './uploads/' . $user_folder . '/' . $resize2, 'maintain_ratio' => TRUE, 'width' => 100, 'height' => 100); $this->image_lib->initialize($config); $this->image_lib->resize(); $resize3 = '225x225'; if (!is_dir('./uploads/' . $user_folder . '/' . $resize3)) { mkdir('./uploads/' . $user_folder . '/' . $resize3, 0777); } $config = array('source_image' => $upload_data['full_path'], 'new_image' => './uploads/' . $user_folder . '/' . $resize3, 'maintain_ratio' => TRUE, 'width' => 225, 'height' => 225); $this->image_lib->initialize($config); $this->image_lib->resize(); } if (!$this->upload->do_upload('photo')) { $data = array('superior_id' => $this->input->post('superior_id')); } else { $image_name = $upload_data['file_name']; $data = array('photo' => $image_name, 'superior_id' => $this->input->post('superior_id')); } // 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'); if (isset($groupData) && !empty($groupData)) { $this->ion_auth->remove_from_group('', $id); foreach ($groupData as $grp) { $this->ion_auth->add_to_group($grp, $id); } } } //update the password if it was posted if ($this->input->post('password')) { $this->form_validation->set_rules('password', $this->lang->line('edit_user_validation_password_label'), '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', $this->lang->line('edit_user_validation_password_confirm_label'), 'required'); $data['password'] = $this->input->post('password'); } if ($this->form_validation->run() === TRUE) { $this->ion_auth->update($user->id, $data); //check to see if we are creating the user //redirect them back to the admin page if ($this->ion_auth->is_admin()) { $this->session->set_flashdata('message', "Perubahan Tersimpan"); redirect('auth', 'refresh'); } else { $this->session->set_flashdata('message', "Perubahan Tersimpan"); redirect('person/detail/' . $id, 'refresh'); } } } //display the edit user form $this->data['csrf'] = $this->_get_csrf_nonce(); //set the flash data error message if there is one $this->data['message'] = validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')); //pass the user to the view $this->data['user'] = $user; $this->data['groups'] = $groups; $this->data['currentGroups'] = $currentGroups; $this->data['photo'] = array('name' => 'photo', 'id' => 'photo', 'class' => 'input-file-control', 'value' => $this->form_validation->set_value('photo', $user->photo)); $this->data['kk'] = array('name' => 'kk', 'id' => 'kk', 'class' => 'input-file-control', 'value' => $this->form_validation->set_value('kk', $user->scan_kk)); $this->data['akta'] = array('name' => 'akta', 'id' => 'akta', 'class' => 'input-file-control', 'value' => $this->form_validation->set_value('akta', $user->scan_akta)); $this->data['nik'] = array('name' => 'nik', 'id' => 'nik', 'type' => 'text', 'disabled' => 'disabled', 'value' => $this->form_validation->set_value('nik', $user->nik)); $this->data['bod'] = array('name' => 'bod', 'id' => 'bod', 'type' => 'text', 'value' => $this->form_validation->set_value('bod', $user->bod)); $this->data['first_name'] = array('name' => 'first_name', 'id' => 'first_name', 'type' => 'text', 'value' => $this->form_validation->set_value('first_name', $user->first_name)); $this->data['last_name'] = array('name' => 'last_name', 'id' => 'last_name', 'type' => 'text', 'value' => $this->form_validation->set_value('last_name', $user->last_name)); $this->data['company'] = array('name' => 'company', 'id' => 'company', 'type' => 'text', 'value' => $this->form_validation->set_value('company', $user->company)); $this->data['phone'] = array('name' => 'phone', 'id' => 'phone', 'type' => 'text', 'value' => $this->form_validation->set_value('phone', $user->phone)); $this->data['email'] = array('name' => 'email', 'id' => 'email', 'type' => 'text', 'disabled' => 'disabled', 'value' => $this->form_validation->set_value('email', $user->email)); $this->data['previous_email'] = array('name' => 'previous_email', 'id' => 'previous_email', 'type' => 'text', 'value' => $this->form_validation->set_value('previous_email', $user->previous_email)); $this->data['bb_pin'] = array('name' => 'bb_pin', 'id' => 'bb_pin', 'type' => 'text', 'value' => $this->form_validation->set_value('bb_pin', $user->bb_pin)); $this->data['password'] = array('name' => 'password', 'id' => 'password', 'type' => 'text', 'onfocus' => "this.select();this.setAttribute('type','password')"); $this->data['password_confirm'] = array('name' => 'password_confirm', 'id' => 'password_confirm', 'type' => 'password'); $this->get_superior($id); $this->data['selected_superior'] = $this->db->where('id', $id)->get('users')->row('superior_id'); $this->data['marital_id'] = $this->form_validation->set_value('email', $user->marital_id); $this->data['s_photo'] = $this->form_validation->set_value('photo', $user->photo); $this->data['s_kk'] = $this->form_validation->set_value('kk', $user->scan_kk); $this->data['s_akta'] = $this->form_validation->set_value('akta', $user->scan_akta); $user_folder = $user->id . $user->first_name; $this->data['u_folder'] = $user_folder; $f_marital = array("is_deleted" => 0); $q_marital = GetAll('marital', $f_marital); $r = $this->data['marital'] = $q_marital->num_rows() > 0 ? $q_marital : array(); $this->_render_page('auth/edit_user', $this->data); }
function insert_leave_request($user_id, $data = array(), $leave_request_id) { $user_id = get_nik($user_id); $leaveid = substr($leave_request_id[0]['IDLEAVEREQUEST'], 2) + 1; $leaveid = sprintf('%06d', $leaveid); $IDLEAVEREQUEST = 'CT' . $leaveid; $RECVERSION = $leave_request_id[0]['RECVERSION'] + 1; $RECID = $leave_request_id[0]['RECID'] + 1; $remarks = str_replace(' ', '-', $data['remarks']); $alamat_cuti = str_replace(' ', '-', $data['alamat_cuti']); $phone = str_replace(' ', '-', $data['contact']); $method = 'post'; $params = array(); $uri = get_api_key() . 'users/leave_request/' . 'EMPLID/' . $user_id . '/HRSLEAVETYPEID/' . $data['alasan_cuti_id'] . '/REMARKS/' . $remarks . '/CONTACTPHONE/' . $phone . '/TOTALLEAVEDAYS/' . $data['jumlah_hari'] . '/LEAVEDATETO/' . $data['date_selesai_cuti'] . '/LEAVEDATEFROM/' . $data['date_mulai_cuti'] . '/REQUESTDATE/' . $data['created_on'] . '/IDLEAVEREQUEST/' . $IDLEAVEREQUEST . '/STATUSFLAG/' . '3' . '/IDPERSONSUBSTITUTE/' . $data['user_pengganti'] . '/TRAVELLINGLOCATION/' . $alamat_cuti . '/MODIFIEDDATETIME/' . $data['created_on'] . '/MODIFIEDBY/' . $data['created_by'] . '/CREATEDDATETIME/' . $data['created_on'] . '/CREATEDBY/' . $data['created_by'] . '/DATAAREAID/' . get_user_dataareaid($user_id) . '/RECVERSION/' . $RECVERSION . '/RECID/' . $RECID . '/BRANCHID/' . get_user_branchid($user_id) . '/DIMENSION/' . get_user_buid($user_id) . '/DIMENSION2_/' . get_user_dimension2_($user_id) . '/HRSLOCATIONID/' . get_user_locationid($user_id) . '/HRSEMPLGROUPID/' . get_user_emplgroupid($user_id); $this->rest->format('application/json'); $result = $this->rest->{$method}($uri, $params); if (isset($result->status) && $result->status == 'success') { return true; } else { return false; } }
function detail($id) { if (!$this->ion_auth->logged_in()) { $this->session->set_userdata('last_link', $this->uri->uri_string()); redirect('auth/login', 'refresh'); } else { $user_id = getValue('user_id', 'users_exit', array('id' => 'where/' . $id)); $form_exit = $this->data['form_exit'] = $this->form_exit_model->form_exit($id, $user_id); $user_id = getValue('user_id', 'users_exit', array('id' => 'where/' . $id)); $user_nik = get_nik($user_id); $user_nik = $this->data['user_nik'] = get_nik($user_id); //print_mz(get_user_buid($user_nik)); $this->data['sess_id'] = $sess_id = $this->session->userdata('user_id'); $sess_nik = $this->data['sess_nik'] = get_nik($sess_id); $this->data['is_admin_it'] = is_admin_it() && get_user_buid($sess_nik) == get_user_buid($user_nik) ? TRUE : FALSE; $this->data['is_admin_logistik'] = is_admin_logistik() && get_user_buid($sess_nik) == get_user_buid($user_nik) ? TRUE : FALSE; $this->data['is_admin_hrd'] = is_admin_hrd() && get_user_buid($sess_nik) == get_user_buid($user_nik) ? TRUE : FALSE; $this->data['is_admin_koperasi'] = is_admin_koperasi() && get_user_buid($sess_nik) == get_user_buid($user_nik) ? TRUE : FALSE; $this->data['is_admin_perpus'] = is_admin_perpus() && get_user_buid($sess_nik) == get_user_buid($user_nik) ? TRUE : FALSE; $this->data['is_admin_keuangan'] = is_admin_keuangan() && get_user_buid($sess_nik) == get_user_buid($user_nik) ? TRUE : FALSE; $i = $this->db->select('*')->from('users_inventory')->join('inventory', 'users_inventory.inventory_id = inventory.id', 'left')->where('users_inventory.user_id', $user_id)->get(); $this->data['users_inventory'] = $i; $this->data['rekomendasi'] = getAll('users_exit_rekomendasi', array('user_exit_id' => 'where/' . $id))->row(); $this->data['approval_status'] = GetAll('approval_status', array('is_deleted' => 'where/0')); $this->_render_page('form_exit/detail', $this->data); } }