Example #1
0
 public function actionCreate()
 {
     $model = new Training();
     if (isset($_POST['Training'])) {
         $model->setAttributes($_POST['Training']);
         if ($model->save()) {
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 Yii::app()->end();
             } else {
                 $this->redirect(array('admin'));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #2
0
 function trainings($employee_id = '')
 {
     $data['page_name'] = '<b>Personal Data Sheet</b>';
     $data['section_name'] = '<b>Personal Information</b>';
     $data['focus_field'] = 'tra_name';
     $data['msg'] = '';
     $e = new Employee_m();
     $data['employee'] = $e->get_by_id($employee_id);
     if (Input::get('op')) {
         // TRAINING PROGRAMS=========================
         $tra_name = Input::get('tra_name');
         $tra_date_from = Input::get('tra_date_from');
         $tra_date_to = Input::get('tra_date_to');
         $tra_hours = Input::get('tra_hours');
         $tra_conduct = Input::get('tra_conduct');
         $tra_location = Input::get('tra_location');
         $t = new Training();
         $t->get_by_employee_id($employee_id);
         $t->delete_all();
         $i = 0;
         foreach ($tra_name as $tra) {
             if ($tra != "") {
                 $t = new Training();
                 $t->employee_id = $employee_id;
                 $t->name = $tra_name[$i];
                 $t->date_from = $tra_date_from[$i];
                 $t->date_to = $tra_date_to[$i];
                 $t->number_hours = $tra_hours[$i];
                 $t->conducted_by = $tra_conduct[$i];
                 $t->location = $tra_location[$i];
                 $t->save();
             }
             $i++;
         }
         $data['msg'] = 'Trainings has been saved!';
     }
     // Training=========================================================
     $t = new Training();
     //STR_TO_DATE(date_from, '%M %Y') DESC
     $t->order_by('date_from', 'DESC');
     //$t->order_by('STR_TO_DATE(date_from, "%Y-%m-%d")', 'DESC');
     //$t->order_by("YEAR(date_from)", 'DESC');
     //var_dump($t);
     $data['trains'] = $t->get_by_employee_id($employee_id);
     $data['tra_location_options'] = array('local' => 'Local', 'regional' => 'Regional', 'national' => 'National', 'international' => 'International');
     if ($employee_id == '') {
         $data['trains'] = array();
     }
     $data['selected'] = $e->office_id;
     // Use for office listbox
     $data['options'] = $this->options->office_options();
     $data['employee_id'] = $employee_id;
     $data['main_content'] = 'trainings';
     return View::make('includes/template', $data);
 }
Example #3
0
 function employees($employee_id = '')
 {
     $data['page_name'] = '<b>Employee\'s Training Record</b>';
     $data['focus_field'] = 'tra_name';
     $data['msg'] = '';
     $employee_id = Input::get('employee_id');
     $e = new Employee_m();
     $data['employee'] = $e->get_by_id(Input::get('employee_id'));
     $data['pics'] = file_exists('pics/' . $e->pics) ? $e->pics : 'not_available.jpg';
     $image_properties = array('src' => base_url() . 'pics/' . $data['pics'], 'width' => '140', 'height' => '140');
     $data['pics'] = $image_properties;
     $em = new Employee_movement_m();
     $em->get_by_id($e->employee_movement_id);
     $data['employment_movement'] = $em->employee_movement;
     if (Input::get('op')) {
         // TRAINING PROGRAMS=========================
         $tra_name = Input::get('tra_name');
         $tra_date_from = Input::get('tra_date_from');
         $tra_date_to = Input::get('tra_date_to');
         $tra_hours = Input::get('tra_hours');
         $tra_conduct = Input::get('tra_conduct');
         $tra_location = Input::get('tra_location');
         $t = new Training();
         $t->get_by_employee_id($employee_id);
         $t->delete_all();
         $i = 0;
         foreach ($tra_name as $tra) {
             if ($tra != "") {
                 $t = new Training();
                 $t->employee_id = $employee_id;
                 $t->name = $tra_name[$i];
                 $t->date_from = $tra_date_from[$i];
                 $t->date_to = $tra_date_to[$i];
                 $t->number_hours = $tra_hours[$i];
                 $t->conducted_by = $tra_conduct[$i];
                 $t->location = $tra_location[$i];
                 $t->save();
             }
             $i++;
         }
         $data['msg'] = 'Trainings has been saved!';
     }
     // Recommended trainings
     if (Input::get('op2')) {
         $recommends = Input::get('recommend_id');
         $reco_year = Input::get('reco_year');
         $course_id = Input::get('course_id');
         $relevant = Input::get('relevant');
         $reco_remarks = Input::get('reco_remarks');
         $i = 0;
         foreach ($recommends as $r_id) {
             if ($reco_year[$i] != '') {
                 $t = new Training_recomended_m();
                 $t->where('course_id', $course_id[$i]);
                 $t->where('reco_year', $reco_year[$i]);
                 $t->where('employee_id', $employee_id);
                 $t->get();
                 $t->employee_id = $employee_id;
                 $t->reco_year = $reco_year[$i];
                 $t->course_id = $course_id[$i];
                 $t->relevant = $relevant[$i];
                 $t->reco_remarks = $reco_remarks[$i];
                 $t->save();
             }
             $i++;
         }
         // Remove checked
         if (Input::get('remove')) {
             foreach (Input::get('remove') as $recommended_id) {
                 $t = new Training_recomended_m();
                 $t->get_by_id($recommended_id);
                 $t->delete();
             }
         }
     }
     // Actual duties
     if (Input::get('op3')) {
         $duties_ids = Input::get('duties_id');
         $duty_from = Input::get('duty_from');
         $duty_to = Input::get('duty_to');
         $duty_desc = Input::get('duty_desc');
         $i = 0;
         foreach ($duties_ids as $r_id) {
             if ($duty_from[$i] != '') {
                 $ed = new Employee_duty_m();
                 $ed->get_by_id($r_id);
                 $ed->employee_id = $employee_id;
                 $ed->duty_from = $duty_from[$i];
                 $ed->duty_to = $duty_to[$i];
                 $ed->duty_desc = $duty_desc[$i];
                 $ed->save();
             }
             $i++;
         }
     }
     // Training===========================================================
     $t = new Training();
     $t->order_by('date_from', 'DESC');
     $data['trains'] = $t->get_by_employee_id($employee_id);
     $data['tra_location_options'] = array('local' => 'Local', 'regional' => 'Regional', 'national' => 'National', 'international' => 'International');
     if ($employee_id == '') {
         $data['trains'] = array();
     }
     // Recommended Trainings
     $t = new Training_recomended_m();
     $t->order_by('reco_year');
     $data['recommends'] = $t->get_by_employee_id($employee_id);
     // Actual Duties
     $ed = new Employee_duty_m();
     $ed->order_by('duty_from');
     $data['duties'] = $ed->get_by_employee_id($employee_id);
     $data['selected'] = $e->office_id;
     //Use for office listbox
     $data['options'] = $this->options->office_options();
     // Courses
     $t = new Training_course();
     $data['courses'] = $t->courses();
     $data['employee_id'] = $employee_id;
     $data['main_content'] = 'employees';
     return View::make('includes/template', $data);
 }
Example #4
0
 /**
  * [saveTraining description]
  * @param  string $train_id [description]
  * @return [type]           [description]
  */
 public function saveTraining($train_id = "")
 {
     Input::flash();
     $data = Input::all();
     $files = Input::file('training_upload');
     /*
             if( count($files) > 0)
             {
                 foreach($files as $key => $file)
                 {
                     $file->move($this->upload_path, $file->getClientOriginalName());
                     $fullpath = $this->upload_path.$file->getClientOriginalName();
                     $upload_media[] = array('typeid'=>'1', 'fullpath'=>$fullpath);
                 }
             }*/
     //UploadMedia::insert($upload_media);
     $rules = array('title' => array('required'), 'description' => array('required'), 'sdt' => array('required'), 'edt' => array('required'));
     // Build the custom messages array.
     $messages = array('title.required' => 'กรุณาระบุชื่อหลักสูตรอบรม', 'description.required' => 'กรุณาระบุรายละเอียดหลักสูตรอบรม', 'sdt.required' => 'กรุณาระบุวันเริ่มต้นที่สามารถเข้าร่วม', 'edt.required' => 'กรุณาระบุวันสุดท้ายที่สามารถเข้าร่วม');
     // Create a new validator instance.
     $validator = Validator::make($data, $rules, $messages);
     $title = trim($data['title']);
     if (isset($data['status'])) {
         $data['status'] == 'on' ? $status = true : ($status = false);
     } else {
         $status = false;
     }
     if ($validator->passes()) {
         if (!$train_id) {
             //from add page
             if (count($data['role_id'] > 0)) {
                 $role_str = implode(",", $data['role_id']);
             }
             $training = new Training();
             $rs_check = $training->checkTitle($title);
             if ($rs_check) {
                 $start_date = $data['sdt'] . ':00';
                 $end_date = $data['edt'] . ':00';
                 $training->title = $title;
                 $training->description = $data['description'];
                 $training->target = $role_str;
                 $training->status = $status;
                 $training->closed_date = $end_date;
                 $training->start_training_date = $start_date;
                 $training->save();
                 $lastInsertId = $training->id;
                 if (count($files) > 0) {
                     foreach ($files as $key => $file) {
                         $file->move($this->upload_path, $file->getClientOriginalName());
                         $fullpath = $this->upload_path . $file->getClientOriginalName();
                         $upload_media[] = array('typeid' => '1', 'fullpath' => $fullpath, 'training_id' => $lastInsertId);
                     }
                 }
                 UploadMedia::insert($upload_media);
                 //save to media upload
                 return Redirect::to('/training')->with('success', 'บันทึกสำเร็จ');
             } else {
                 return Redirect::to('/training/add')->with('warning', 'มีชื่อหลัักสูตรนี้ในระบบแล้ว');
             }
         } else {
             //from edit page
             if (count($data['role_id'] > 0)) {
                 $role_str = implode(",", $data['role_id']);
             }
             $training = new Training();
             // $rs_check = $training->checkTitle($title);
             // if($rs_check)
             // {
             $start_date = $data['sdt'] . ':00';
             $end_date = $data['edt'] . ':00';
             $training = Training::find($train_id);
             $training->title = $data['title'];
             $training->description = $data['description'];
             $training->target = $role_str;
             $training->status = $status;
             $training->closed_date = $end_date;
             $training->start_training_date = $start_date;
             $training->save();
             $lastInsertId = $training->id;
             if (count($files) > 0) {
                 foreach ($files as $key => $file) {
                     $file->move($this->upload_path, $file->getClientOriginalName());
                     $fullpath = $this->upload_path . $file->getClientOriginalName();
                     $upload_media[] = array('typeid' => '1', 'fullpath' => $fullpath, 'training_id' => $lastInsertId);
                 }
             }
             UploadMedia::insert($upload_media);
             //save to media upload
             return Redirect::to('/training')->with('success', 'แก้ไขสำเร็จ');
             // }else
             // {
             // 	return Redirect::to('/training/add')->with('warning','Existing title namle.');
             // }
         }
     } else {
         if (!$train_id) {
             //from add page
             return Redirect::to('/training/add')->withErrors($validator);
         } else {
             return Redirect::to('/training/edit/' . $train_id)->with('warning', 'กรุณากรอกข้อมูลตรงตามที่ระบบต้องการ');
         }
     }
 }