Last active
August 29, 2015 14:24
-
-
Save phanngoc/90cbedd995ae6842274a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @extends ('layouts.master') | |
| @section ('head.title') | |
| Add Candidate | |
| @stop | |
| @section ('body.content') | |
| <link href="{{Asset('bootstrap/css/select2.min.css')}}" rel="stylesheet" type="text/css" /> | |
| <script src="{{Asset('bootstrap/js/select2.min.js')}}" type="text/javascript"></script> | |
| <script src="{{ Asset('bootstrap-datepicker/bootstrap-datepicker.js') }}"></script> | |
| <link rel="stylesheet" href="{{ Asset('bootstrap-datepicker/bootstrap-datepicker.css') }}" type="text/css" /> | |
| <div class="content-wrapper"> | |
| <!-- Content Header (Page header) --> | |
| <section class="content-header"> | |
| <h1> | |
| Candidate Management | |
| </h1> | |
| <ol class="breadcrumb"> | |
| <li><a href="{{ route('index') }}"><i class="fa fa-dashboard"></i> {{trans('messages.dashboard')}}</a></li> | |
| <li><a href="{{ route('users.index') }}">Human Resources</a></li> | |
| <li class="active">Add Candidate</li> | |
| </ol> | |
| </section> | |
| <!-- Main content --> | |
| <section class="content"> | |
| <div class="row"> | |
| <!-- left column --> | |
| <div class="col-md-8 col-md-offset-2"> | |
| <!-- general form elements --> | |
| <div class="box box-primary"> | |
| <div class="box-header"> | |
| <h3 class="box-title">Add Candidate</h3> | |
| <a class="btn btn-primary pull-right" href="{!!route('candidates.index') !!}">List Candidates</i></a> | |
| </div> | |
| @if (count($errors) > 0) | |
| <div class="alert alert-danger"> | |
| <strong>{{trans('messages.whoop')}}</strong> {{trans('messages.problem')}}<br><br> | |
| <ul> | |
| @foreach ($errors->all() as $error) | |
| <li>{{ $error }}</li> | |
| @endforeach | |
| </ul> | |
| </div> | |
| @endif | |
| <!-- form start --> | |
| {!! Form::open([ | |
| 'route'=>['candidates.store'], | |
| 'method'=>'POST', | |
| 'id'=>'add', | |
| 'enctype'=>'multipart/form-data' | |
| ]) !!} | |
| <div class="box-body"> | |
| <div class="form-group"> | |
| {!! HTML::decode(Form::label('firstname', 'First Name'.'<span id="label">*</span>')) !!} | |
| {!! Form::text('firstname',null,['id'=>'firstname','class'=>'form-control','placeholder'=>'First Name']) !!} | |
| </div> | |
| <div class="form-group"> | |
| {!! HTML::decode(Form::label('lastname', 'Last Name'.'<span id="label">*</span>')) !!} | |
| {!! Form::text('lastname',null,['id'=>'lastname','class'=>'form-control','placeholder'=>'Last Name']) !!} | |
| </div> | |
| <div class="form-group"> | |
| <label for="dateofbirth">Date of Birth<span id="label">*</span></label> | |
| {!! Form::text('dateofbirth',null,['id'=>'dateofbirth','class'=>'form-control','placeholder'=>'Date of Birth']) !!} | |
| </div> | |
| <div class="form-group"> | |
| {!! HTML::decode(Form::label('phone', 'Phone'.'<span id="label">*</span>')) !!} | |
| {!! Form::text('phone',null,['id'=>'phone','class'=>'form-control','placeholder'=>'Phone']) !!} | |
| </div> | |
| <div class="form-group"> | |
| {!! HTML::decode(Form::label('email', 'Email'.'<span id="label">*</span>')) !!} | |
| {!! Form::email('email',null,['id'=>'email','class'=>'form-control','placeholder'=>'Email']) !!} | |
| </div> | |
| <div class="form-group"> | |
| {!! HTML::decode(Form::label('position', 'Position'.'<span id="label">*</span>')) !!} | |
| {!! Form::select('position[]', $positions,null, ['class'=>'js-example-basic-multiple form-control','multiple'=>true]) !!} | |
| </div> | |
| <div class="form-group"> | |
| <label for="datesubmit">Date for receipt<span id="label">*</span></label> | |
| {!! Form::text('datesubmit',null,['id'=>'datesubmit','class'=>'form-control','placeholder'=>'Date for receipt']) !!} | |
| </div> | |
| <div class="form-group"> | |
| {!! HTML::decode(Form::label('comment', 'Comment')) !!} | |
| {!! Form::text('comment', null,['id'=>'comment','class'=>'form-control']) !!} | |
| </div> | |
| <div class="form-group"> | |
| <label for="file">Files</label> | |
| <input name="files[]" id="file" type="file" multiple="" /> | |
| </div> | |
| <div class="box-footer center"> | |
| <div class="row"> | |
| <div class="col-sm-4 col-sm-offset-4 text-center"> | |
| <input type="submit" class="btn btn-primary" value="Save"></input> | |
| <input type='reset' name='reset' id='reset' class="btn btn-primary" value="{{trans('messages.reset')}}"> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| {!! Form::close() !!} | |
| </div> | |
| </div> | |
| </div> | |
| </section> | |
| <script type="text/javascript"> | |
| $(function() { | |
| var formdata = false; | |
| if (window.FormData) { | |
| formdata = new FormData(); | |
| } | |
| $("input").change(function (){ | |
| var filedata = document.getElementsByName("fileattach"); | |
| console.log(filedata); | |
| var i = 0, len = filedata[0].files.length, img, reader, file; | |
| for (; i < len; i++) { | |
| file = filedata[0].files[i]; | |
| console.log(file); | |
| $("#area-show-file").append("<div class='namefile'>"+file.name+"</div>"); | |
| // if (window.FileReader) { | |
| // reader = new FileReader(); | |
| // reader.onloadend = function(e) { | |
| // showUploadedItem(e.target.result, file.fileName); | |
| // }; | |
| // reader.readAsDataURL(file); | |
| // } | |
| if (formdata) { | |
| formdata.append("file"+i, file); | |
| } | |
| } | |
| console.log(formdata); | |
| if (formdata) { | |
| $.ajax({ | |
| url: "server.php", | |
| type: "POST", | |
| data: formdata, | |
| processData: false, | |
| contentType: false, | |
| success: function(res) { | |
| console.log(res); | |
| }, | |
| error: function(res) { | |
| } | |
| }); | |
| } | |
| }); | |
| }); | |
| </script> | |
| <script type="text/javascript"> | |
| $(document).ready(function(){ | |
| $( "#dateofbirth" ).datepicker({format: 'dd/mm/yyyy'}); | |
| $( "#datesubmit" ).datepicker({format: 'dd/mm/yyyy'}); | |
| $.validator.addMethod("phone",function(value,element){ | |
| return this.optional(element) || /(^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$)/.test(value); | |
| },""); | |
| }); | |
| </script> | |
| <script type="text/javascript"> | |
| $(".js-example-basic-multiple").select2({ | |
| placeholder: "{{trans('messages.sl_groups')}}" | |
| }); | |
| </script> | |
| <script> | |
| $("#add").validate({ | |
| rules: { | |
| firstname: { | |
| required: true, | |
| minlength: 2 | |
| }, | |
| lastname: { | |
| required: true, | |
| minlength: 2 | |
| }, | |
| dateofbirth: { | |
| required: true | |
| }, | |
| phone: { | |
| required: true, | |
| phone: true | |
| }, | |
| email: { | |
| required: true | |
| }, | |
| datesubmit: { | |
| required: true | |
| } | |
| }, | |
| messages: { | |
| firstname: { | |
| required: "You can't leave this empty", | |
| minlength: "Please enter more than 2 characters" | |
| }, | |
| lastname: { | |
| required: "You can't leave this empty", | |
| minlength: "Please enter more than 2 characters" | |
| }, | |
| dateofbirth: { | |
| required: "You can't leave this empty" | |
| }, | |
| phone: { | |
| required: "You can't leave this empty", | |
| phone: "Please enter a valid value" | |
| }, | |
| email: { | |
| required: "You can't leave this empty" | |
| }, | |
| datesubmit: { | |
| required: "You can't leave this empty", | |
| } | |
| } | |
| }); | |
| </script> | |
| </div> | |
| @stop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php namespace App\Http\Controllers; | |
| use App\Http\Requests; | |
| use App\Http\Controllers\Controller; | |
| use App\Candidate; | |
| use App\Http\Requests\AddCandidateRequest; | |
| use Input; | |
| use App\File; | |
| use App\Http\Requests\EditCandidateRequest; | |
| use Illuminate\Http\Request; | |
| use App\StatusRecord; | |
| use App\Position; | |
| use Zipper; | |
| class CandidateController extends AdminController { | |
| /** | |
| * Display listing candidate | |
| * | |
| * @return Response | |
| */ | |
| public function index() | |
| { | |
| $candidates = Candidate::whereIn('status_record_id', [1, 2,3, 4 ,5])->get(); | |
| return view('candidates.listcandidate', compact('statusrecord','candidates')); | |
| } | |
| public function zipfile($id) | |
| { | |
| $file_path = public_path() . '/files/'.$id.'/All.zip'; | |
| if (!file_exists($file_path)) { | |
| $files = glob(public_path().'/files/'.$id.'/*'); | |
| $zipper = Zipper::make(public_path().'/files/'.$id.'/All.zip')->add($files); | |
| } | |
| } | |
| /** | |
| * Show the form for creating a new resource. | |
| * | |
| * @return Response | |
| */ | |
| public function create() | |
| { | |
| $status_records = StatusRecord::lists('name', 'id'); | |
| $positions = Position::lists('name','id'); | |
| return view('candidates.addcandidate',compact('positions','status_records')); | |
| } | |
| public function convert_datetimesql_to_datepicker($date) { | |
| $year = substr($date, 0, 4); | |
| $month = substr($date, 5, 2); | |
| $day = substr($date, 8, 2); | |
| $res = $day . "/" . $month . "/" . $year; | |
| return $res; | |
| } | |
| public function convert_datepicker_to_datetimesql($date) { | |
| $day = substr($date, 0, 2); | |
| $month = substr($date, 3, 2); | |
| $year = substr($date, 6, 4); | |
| $mysqltime = date("Y-m-d H:i:s", strtotime($year . "-" . $month . "-" . $day)); | |
| return $mysqltime; | |
| } | |
| /** | |
| * Store a newly created resource in storage. | |
| * | |
| * @return Response | |
| */ | |
| public function store(AddCandidateRequest $request) | |
| { | |
| $candidates = new Candidate(); | |
| $files = new File(); | |
| $requestdata = $request->all(); | |
| $requestdata['date_of_birth'] = $this->convert_datepicker_to_datetimesql($request->get('dateofbirth')); | |
| $requestdata['date_submit'] = $this->convert_datepicker_to_datetimesql($request->get('datesubmit')); | |
| $candidates->first_name = $request->get('firstname'); | |
| $candidates->last_name = $request->get('lastname'); | |
| $candidates->date_of_birth = $requestdata['date_of_birth']; | |
| $candidates->phone = $request->get('phone'); | |
| $candidates->email = $request->get('email'); | |
| $candidates->date_submit = $requestdata['date_submit']; | |
| $candidates->comment = $requestdata['comment']; | |
| $candidates->status_record_id = 1; | |
| $candidates->save(); | |
| $candidates->attachPosition($request['position']); | |
| $destinationPath = public_path().'/files/'.$candidates->id; | |
| /*Files*/ | |
| if (Input::hasFile('files')) { | |
| $file = Input::file('files'); | |
| foreach ($file as $f) { | |
| $filename = $f->getClientOriginalName(); | |
| $uploadSuccess = $f->move($destinationPath, $filename); | |
| $files->create([ | |
| 'candidate_id' => $candidates->id, | |
| 'name' => $filename, | |
| ]); | |
| } | |
| } | |
| return redirect()->route('candidates.index')->with('messageOk', 'Add candidate successfully!');; | |
| } | |
| /** | |
| * Display the specified resource. | |
| * | |
| * @param int $id | |
| * @return Response | |
| */ | |
| public function show($id) | |
| { | |
| $candidate = Candidate::find($id); | |
| $candidate->date_of_birth = $this->convert_datetimesql_to_datepicker($candidate->date_of_birth); | |
| $candidate->date_submit = $this->convert_datetimesql_to_datepicker($candidate->date_submit); | |
| $f1 = File::lists('id'); | |
| $f2 = $candidate->files->lists('name', 'id'); | |
| //$status_records = StatusRecord::lists('name', 'id'); | |
| $status_records = StatusRecord::whereIn('id', array(1, 3, 4))->get(); | |
| $res_status = array(); | |
| foreach ($status_records as $k_sta => $v_sta) { | |
| $res_status += array($v_sta->id => $v_sta->name); | |
| } | |
| $status_records = $res_status; | |
| $positions = Position::lists('name','id'); | |
| return view('candidates.editcandidate', compact('positions','status_records','candidate', 'f1', 'f2')); | |
| } | |
| /** | |
| * Show the form for editing the specified resource. | |
| * | |
| * @param int $id | |
| * @return Response | |
| */ | |
| public function edit($id) | |
| { | |
| // | |
| } | |
| /** | |
| * Update the specified resource in storage. | |
| * | |
| * @param int $id | |
| * @return Response | |
| */ | |
| public function update($id, EditCandidateRequest $request) | |
| { | |
| $candidate = Candidate::find($id); | |
| $fff = new File(); | |
| $destinationPath = public_path().'/files/'.$candidate->id.'/'; | |
| //dd($destinationPath); | |
| $requestdata = $request->all(); | |
| $requestdata['date_of_birth'] = $this->convert_datepicker_to_datetimesql($request->get('dateofbirth')); | |
| $requestdata['date_submit'] = $this->convert_datepicker_to_datetimesql($request->get('datesubmit')); | |
| $candidate->update([ | |
| 'first_name' => $request->get('firstname'), | |
| 'last_name' => $request->get('lastname'), | |
| 'date_of_birth' => $requestdata['date_of_birth'], | |
| 'phone' => $request->get('phone'), | |
| 'email' => $request->get('email'), | |
| 'date_submit' => $requestdata['date_submit'], | |
| 'status_record_id' => $requestdata['status_record_id'], | |
| 'comment' => $requestdata['comment'], | |
| ]); | |
| $candidate->attachPosition($request['position']); | |
| /*Xoa file trong select*/ | |
| foreach($candidate->files as $value){ | |
| $check = in_array($value->id, $request['delete_files']); | |
| if(!$check){ | |
| if(file_exists($destinationPath.$value->name)){ | |
| unlink($destinationPath.$value->name); | |
| } | |
| $f1 = File::where('id', '=', $value->id)->delete(); | |
| } | |
| } | |
| /*UP load len file moi*/ | |
| if (Input::hasFile('files')) { | |
| $file = Input::file('files'); | |
| foreach ($file as $f) { | |
| $filename = $f->getClientOriginalName(); | |
| $uploadSuccess = $f->move($destinationPath, $filename); | |
| $fff->create([ | |
| 'candidate_id' => $candidate->id, | |
| 'name' => $filename, | |
| ]); | |
| } | |
| } | |
| // if($requestdata['status_record_id'] == 3) | |
| // { | |
| // $interview = InterviewSchedule::where('candidate_id','=',$id)->first(); | |
| // if($interview == null) | |
| // { | |
| // InterviewSchedule::create(['candidate_id' => $id, 'employee_id' => 0]); | |
| // } | |
| // // dd($interview); | |
| // } | |
| return redirect()->route('candidates.index')->with('messageOk', 'Update candidate successfully'); | |
| } | |
| /** | |
| * Remove the specified resource from storage. | |
| * | |
| * @param int $id | |
| * @return Response | |
| */ | |
| public function destroy($id) | |
| { | |
| $candidate = Candidate::find($id); | |
| $files = File::where('candidate_id', '=', $candidate->id)->delete(); | |
| $candidate->delete(); | |
| return redirect()->route('candidates.index')->with('messageDelete', 'Delete candidate successfully!'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment