Пример #1
0
 /**
  * index page for this controller
  */
 public function index()
 {
     $id = id_auth_user();
     if (!$id) {
         redirect();
     }
     $this->data['page_title'] = 'Profile';
     $this->load->model('Admin_model');
     $this->data['form_action'] = site_url($this->class_path_name);
     $this->data['changepass_form'] = site_url($this->class_path_name . '/change_pass');
     $detail = $this->Admin_model->getAdmin($id);
     $post = $detail;
     if ($this->input->post()) {
         if ($this->validateForm()) {
             $post = $this->input->post();
             $now = date('Y-m-d H:i:s');
             $data_post = array('name' => $post['name'], 'email' => strtolower($post['email']), 'phone' => $post['phone'], 'alamat' => $post['alamat'], 'modify_date' => $now);
             // update data
             $this->Admin_model->UpdateRecord($id, $data_post);
             $post_image = $_FILES;
             if ($post_image['image']['tmp_name']) {
                 if ($detail['image'] != '' && file_exists(IMG_UPLOAD_DIR . 'admin/' . $detail['image'])) {
                     unlink(IMG_UPLOAD_DIR . 'admin/' . $detail['image']);
                     unlink(IMG_UPLOAD_DIR . 'admin/tmb_' . $detail['image']);
                     unlink(IMG_UPLOAD_DIR . 'admin/sml_' . $detail['image']);
                 }
                 $filename = 'adm_' . url_title($post['name'], '_', true) . md5plus($id);
                 $picture_db = file_copy_to_folder($post_image['image'], IMG_UPLOAD_DIR . 'admin/', $filename);
                 copy_image_resize_to_folder(IMG_UPLOAD_DIR . 'admin/' . $picture_db, IMG_UPLOAD_DIR . 'admin/', 'tmb_' . $filename, IMG_THUMB_WIDTH, IMG_THUMB_HEIGHT);
                 copy_image_resize_to_folder(IMG_UPLOAD_DIR . 'admin/' . $picture_db, IMG_UPLOAD_DIR . 'admin/', 'sml_' . $filename, IMG_SMALL_WIDTH, IMG_SMALL_HEIGHT);
                 $this->Admin_model->UpdateRecord($id, array('image' => $picture_db));
             }
             $user_session = array($_SESSION['ADM_SESS']);
             $user_sess = array();
             foreach ($user_session as $key => $val) {
                 $user_session[$key]['admin_name'] = $post['name'];
                 $user_session[$key]['admin_email'] = strtolower($post['email']);
             }
             foreach ($user_session as $key => $val) {
                 $user_sess[$val] = $key[$val];
             }
             $new_session = $val;
             // insert to log
             $data_log = array('id_user' => id_auth_user(), 'id_group' => id_auth_group(), 'action' => 'Profile', 'desc' => 'Edit Profile; ID: ' . $id . '; Data: ' . json_encode($post));
             insert_to_log($data_log);
             // end insert to log
             $this->session->set_userdata('ADM_SESS', $new_session);
             $this->session->set_flashdata('form_message', alert_box('Your Profile has been updated.', 'success'));
             redirect($this->class_path_name);
         }
     }
     $this->data['post'] = $post;
     if ($this->error) {
         $this->data['form_message'] = $this->error;
     }
     if ($this->session->flashdata('form_message')) {
         $this->data['form_message'] = $this->session->flashdata('form_message');
     }
 }
Пример #2
0
 /**
  * detail page
  * @param int $id
  */
 public function edit($id = 0)
 {
     if (!$id) {
         redirect($this->class_path_name);
     }
     $record = $this->Quiz_model->GetQuiz($id);
     if (!$record) {
         redirect($this->class_path_name);
     }
     $this->data['page_title'] = 'Edit';
     $this->data['form_action'] = site_url($this->class_path_name . '/edit/' . $id);
     $this->data['delete_picture_url'] = site_url($this->class_path_name . '/delete_picture/' . $id);
     $this->data['cancel_url'] = site_url($this->class_path_name);
     if ($this->input->post()) {
         $post = $this->input->post();
         if ($this->validateForm($id)) {
             $post['modify_date'] = date('Y-m-d H:i:s');
             $post['status'] = isset($post['status']) ? 1 : 0;
             $post['is_superadmin'] = isset($post['is_superadmin']) ? 1 : 0;
             $post['email'] = strtolower($post['email']);
             if ($post['password'] != '') {
                 $post['userpass'] = password_hash($post['password'], PASSWORD_DEFAULT);
             }
             unset($post['password']);
             unset($post['conf_password']);
             // update data
             $this->Quiz_model->UpdateRecord($id, $post);
             unset($post['userpass']);
             // now change session if user is edit themselve
             if (id_auth_user() == $id) {
                 $user_session = array($_SESSION['ADM_SESS']);
                 $user_sess = array();
                 foreach ($user_session as $key => $val) {
                     $user_session[$key]['admin_name'] = $post['name'];
                     $user_session[$key]['admin_id_auth_group'] = $post['id_auth_group'];
                     $user_session[$key]['admin_email'] = strtolower($post['email']);
                 }
                 foreach ($user_session as $key => $val) {
                     $user_sess[$val] = $key[$val];
                 }
                 $new_session = $val;
                 $this->session->set_userdata('ADM_SESS', $new_session);
             }
             $post_image = $_FILES;
             if ($post_image['image']['tmp_name']) {
                 if ($record['image'] != '' && file_exists(UPLOAD_DIR . 'admin/' . $record['image'])) {
                     unlink(UPLOAD_DIR . 'admin/' . $record['image']);
                     @unlink(UPLOAD_DIR . 'admin/tmb_' . $record['image']);
                     @unlink(UPLOAD_DIR . 'admin/sml_' . $record['image']);
                 }
                 $filename = 'adm_' . url_title($post['name'], '_', true) . md5plus($id);
                 $picture_db = file_copy_to_folder($post_image['image'], UPLOAD_DIR . 'admin/', $filename);
                 copy_image_resize_to_folder(UPLOAD_DIR . 'admin/' . $picture_db, UPLOAD_DIR . 'admin/', 'tmb_' . $filename, IMG_THUMB_WIDTH, IMG_THUMB_HEIGHT);
                 copy_image_resize_to_folder(UPLOAD_DIR . 'admin/' . $picture_db, UPLOAD_DIR . 'admin/', 'sml_' . $filename, IMG_SMALL_WIDTH, IMG_SMALL_HEIGHT);
                 $this->Quiz_model->UpdateRecord($id, array('image' => $picture_db));
             }
             // insert to log
             $data_log = array('id_user' => id_auth_user(), 'id_group' => id_auth_group(), 'action' => 'User Quiz', 'desc' => 'Edit User Quiz; ID: ' . $id . '; Data: ' . json_encode($post));
             insert_to_log($data_log);
             // end insert to log
             $this->session->set_flashdata('flash_message', alert_box('Success.', 'success'));
             redirect($this->class_path_name);
         }
     }
     $this->data['template'] = $this->class_path_name . '/form';
     $this->data['post'] = $record;
     if (isset($this->error)) {
         $this->data['form_message'] = $this->error;
     }
 }
Пример #3
0
 /**
  * detail page
  * @param int $id
  */
 public function detail($id = 0)
 {
     if (!$id) {
         redirect($this->class_path_name);
     }
     $record = $this->Site_model->GetSite($id);
     if (!$record) {
         redirect($this->class_path_name);
     }
     $this->data['page_title'] = 'Detail: ' . $record['site_name'];
     $this->data['form_action'] = site_url($this->class_path_name . '/detail/' . $id);
     $this->data['cancel_url'] = site_url($this->class_path_name);
     if ($this->input->post()) {
         $post = $this->input->post();
         if ($this->validateForm($id)) {
             $post['modify_date'] = date('Y-m-d H:i:s');
             $post['is_default'] = isset($post['is_default']) ? 1 : 0;
             // update data
             $post_setting = $post['setting'];
             unset($post['setting']);
             $this->Site_model->UpdateRecord($id, $post);
             // update setting
             $this->Site_model->UpdateSettingData($id, $post_setting);
             $post_image = $_FILES;
             if ($post_image['site_logo']['tmp_name']) {
                 if ($record['site_logo'] != '' && file_exists(UPLOAD_DIR . 'site/' . $record['site_logo'])) {
                     unlink(UPLOAD_DIR . 'site/' . $record['site_logo']);
                     @unlink(UPLOAD_DIR . 'site/tmb_' . $record['site_logo']);
                     @unlink(UPLOAD_DIR . 'site/sml_' . $record['site_logo']);
                 }
                 $filename = url_title($post['site_name'] . '-logo');
                 $picture_db = file_copy_to_folder($post_image['site_logo'], UPLOAD_DIR . 'site/', $filename);
                 copy_image_resize_to_folder(UPLOAD_DIR . 'site/' . $picture_db, UPLOAD_DIR . 'site/', 'tmb_' . $filename, IMG_THUMB_WIDTH, IMG_THUMB_HEIGHT);
                 copy_image_resize_to_folder(UPLOAD_DIR . 'site/' . $picture_db, UPLOAD_DIR . 'site/', 'sml_' . $filename, IMG_SMALL_WIDTH, IMG_SMALL_HEIGHT);
                 $this->Site_model->UpdateRecord($id, array('site_logo' => $picture_db));
             }
             // insert to log
             $data_log = array('id_user' => id_auth_user(), 'id_group' => id_auth_group(), 'action' => 'Site Setting', 'desc' => 'Edit Site Setting; ID: ' . $id . '; Data: ' . json_encode($post));
             insert_to_log($data_log);
             // end insert to log
             $this->session->set_flashdata('flash_message', alert_box('Success.', 'success'));
             redirect($this->class_path_name);
         }
     }
     $this->data['template'] = $this->class_path_name . '/form';
     $this->data['post'] = $record;
     if (isset($this->error)) {
         $this->data['form_message'] = $this->error;
     }
 }