public static function get_employee_custom($employee_id)
 {
     $custom = DB::select('*')->from('employees_customs')->where('employee_id', "=", $employee_id)->execute()->as_array();
     if (count($custom)) {
         return Model_EmployeeCustom::find($custom[0]['id']);
     } else {
         return null;
     }
 }
Esempio n. 2
0
 public static function get_employee($id)
 {
     $query = DB::select('employees.*', 'users.username', 'users.last_login', 'users.fb_login')->from('employees')->join('users', 'inner')->on('employees.user_id', '=', 'users.id')->where('employees.id', '=', $id)->execute()->as_array();
     if (count($query)) {
         $result = $query[0];
         $result['custom'] = Model_EmployeeCustom::get_employee_custom($id);
         $result['expect'] = Model_Expect::get_expects($id);
         $result['experience'] = Model_Experience::get_experience($id);
         $result['school'] = Model_School::get_schools($id);
         $result['comp_skills'] = Model_Skill::get_computer_skills($id);
         $result['lang_skills'] = Model_Skill::get_language_skills($id);
         $result['other_skills'] = Model_Skill::get_other_skills($id);
         return $result;
     } else {
         return null;
     }
 }
Esempio n. 3
0
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('employee');
     $employee = Model_Employee::find($id);
     if (!$employee) {
         Session::set_flash('error', 'Could not find employee #' . $id);
         Response::redirect('employee');
     }
     if ($employee->user_id) {
         $user = Model_User::find($employee->user_id);
         $custom = Model_EmployeeCustom::get_employee_custom($employee->id);
     } else {
         $user = null;
         $custom = null;
     }
     if (Input::method() == 'POST') {
         $val = Model_Employee::validate('edit');
         if ($user && strlen(Input::post('password'))) {
             $val->add_field('password', 'Password', 'required|min_length[8]|max_length[20]');
             $val->add_field('password_re', 'Re-type Password', 'required|min_length[8]|max_length[20]');
         }
         $file = Input::file('employee_photo_file');
         $error = false;
         if ($val->run()) {
             $employee_photo = "";
             if ($file['size'] > 0) {
                 $allowList = array(".jpg", ".png");
                 $ext = substr($file['name'], strrpos($file['name'], "."));
                 if (!in_array($ext, $allowList)) {
                     Session::set_flash('error', 'ชนิดของไฟล์ภาพไม่ถูกต้อง');
                     $error = true;
                 }
                 $path = realpath(DOCROOT . "/../../uploads/profile_photo/employee/") . DS;
                 $filename = md5($file['name']);
                 if (@copy($file['tmp_name'], $path . $filename . "-o" . $ext)) {
                     $employee_photo = $filename . $ext;
                     /* cropped, default, and retina images */
                     if ($ext === ".jpg") {
                         $image = imagecreatefromjpeg($path . $filename . "-o" . $ext);
                     } else {
                         if ($ext === ".png") {
                             $image = imagecreatefrompng($path . $filename . "-o" . $ext);
                         }
                     }
                     $width = imagesx($image);
                     $height = imagesy($image);
                     $photo_width = Input::post('photo_width') ? Input::post('photo_width') : $width;
                     $photo_height = Input::post('photo_height') ? Input::post('photo_height') : $height;
                     $default_image = imagecreatetruecolor(360, 360);
                     $black = imagecolorallocate($default_image, 0, 0, 0);
                     imagecolortransparent($default_image, $black);
                     imagecopyresized($default_image, $image, 0, 0, 0, 0, 360, 360, $photo_width, $photo_height);
                     if ($ext === ".jpg") {
                         imagejpeg($default_image, $path . $filename . $ext);
                     } else {
                         if ($ext === ".png") {
                             imagepng($default_image, $path . $filename . $ext);
                         }
                     }
                     $retina_image = imagecreatetruecolor(720, 720);
                     $black = imagecolorallocate($retina_image, 0, 0, 0);
                     imagecolortransparent($retina_image, $black);
                     imagecopyresized($retina_image, $image, 0, 0, 0, 0, 720, 720, $photo_width, $photo_height);
                     if ($ext === ".jpg") {
                         imagejpeg($retina_image, $path . $filename . "@2x" . $ext);
                     } else {
                         if ($ext === ".png") {
                             imagepng($retina_image, $path . $filename . "@2x" . $ext);
                         }
                     }
                 }
             }
             if (strlen(Input::post('password')) && Input::post('password') != Input::post('password_re')) {
                 Session::set_flash('error', 'กรุณากรอก Password ทั้งสองช่องให้ตรงกัน');
                 $error = true;
             }
             if (!$error) {
                 if ($user) {
                     if (strlen(Input::post('password'))) {
                         $user->password = Auth::instance()->hash_password(Input::post('password'));
                     }
                     $user->save();
                 }
                 $employee->employee_firstname = Input::post('employee_firstname');
                 $employee->employee_lastname = Input::post('employee_lastname');
                 $employee->employee_nickname = Input::post('employee_nickname');
                 $employee->employee_display_name = Input::post('employee_display_name');
                 $employee->employee_display_position = Input::post('employee_display_position');
                 $employee->employee_gender = Input::post('employee_gender');
                 $employee->employee_bdate = Input::post('employee_bdate');
                 $employee->employee_addr = Input::post('employee_addr');
                 $employee->province_id = Input::post('province_id');
                 $employee->employee_phone = Input::post('employee_phone');
                 $employee->employee_email = Input::post('employee_email');
                 $employee->employee_website = Input::post('employee_website');
                 $employee->employee_facebook = Input::post('employee_facebook');
                 $employee->employee_twitter = Input::post('employee_twitter');
                 $employee->employee_gplus = Input::post('employee_gplus');
                 $employee->employee_weight = Input::post('employee_weight');
                 $employee->employee_height = Input::post('employee_height');
                 $employee->employee_prefer = Input::post('employee_prefer');
                 $employee->employee_about = Input::post('employee_about');
                 if (strlen($employee_photo)) {
                     $employee->employee_photo = $employee_photo;
                 }
                 $employee->employee_is_active = Input::post('employee_is_active');
                 if ($employee->save()) {
                     $custom->working_status = Input::post('working_status');
                     $custom->resume_published = Input::post('resume_published');
                     $custom->portfolio_published = Input::post('portfolio_published');
                     $custom->save();
                     Session::set_flash('success', 'Updated employee #' . $id);
                     Response::redirect('employee');
                 } else {
                     Session::set_flash('error', 'Could not update employee #' . $id);
                 }
             }
         } else {
             $employee->employee_firstname = Input::post('employee_firstname');
             $employee->employee_lastname = Input::post('employee_lastname');
             $employee->employee_nickname = Input::post('employee_nickname');
             $employee->employee_display_name = Input::post('employee_display_name');
             $employee->employee_display_position = Input::post('employee_display_position');
             $employee->employee_gender = Input::post('employee_gender');
             $employee->employee_bdate = Input::post('employee_bdate');
             $employee->employee_addr = Input::post('employee_addr');
             $employee->province_id = Input::post('province_id');
             $employee->employee_phone = Input::post('employee_phone');
             $employee->employee_email = Input::post('employee_email');
             $employee->employee_website = Input::post('employee_website');
             $employee->employee_facebook = Input::post('employee_facebook');
             $employee->employee_twitter = Input::post('employee_twitter');
             $employee->employee_gplus = Input::post('employee_gplus');
             $employee->employee_weight = Input::post('employee_weight');
             $employee->employee_height = Input::post('employee_height');
             $employee->employee_prefer = Input::post('employee_prefer');
             $employee->employee_about = Input::post('employee_about');
             $employee->employee_is_active = Input::post('employee_is_active');
             $msg = '<ul>';
             foreach ($val->error() as $field => $error) {
                 $msg .= '<li>' . $error->get_message() . '</li>';
             }
             $msg .= '</ul>';
             Session::set_flash('error', $msg);
         }
     }
     $this->theme->set_template('edit');
     $this->theme->get_template()->set_global('employee', $employee, false);
     $this->theme->get_template()->set_global('user', $user, false);
     $this->theme->get_template()->set_global('custom', $custom, false);
     $this->theme->get_template()->set('current_menu', "Employees");
     $this->theme->get_template()->set('current_menu_desc', "จัดการผู้ใช้งานที่เป็นผู้หางานทั้งหมดในระบบ");
     $this->theme->get_template()->set('breadcrumb', array(array('title' => "Home", 'icon' => "fa-home", 'link' => Uri::create('home'), 'active' => false), array('title' => "Employees", 'icon' => "fa-users", 'link' => Uri::create('employee/index'), 'active' => false), array('title' => "Edit", 'icon' => "", 'link' => "", 'active' => true)));
     $this->theme->get_template()->set_global('menu', "edit", false);
     $this->theme->set_partial('sidebar', 'common/sidebar');
     $this->theme->set_partial('left', 'employee/edit');
     $this->theme->get_template()->set_global('provinces', Model_Province::get_provinces("th"), false);
 }