get('/jobs/new', function ( $request, $response) { if( !$login = $this->get(Session::class)->get('login') ){ // $response = $response->withHeader('Location', "/login")->withStatus(302); $response = $response->withHeader('Location', '/login') ->withStatus(302); // 302 表示臨時重定向 return $response; } $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); $job_type_mapper = new JobTypeMapper($this->get(PDO::class)); $job_types = $job_type_mapper->getJobType(); $experience_mapper = new ExperienceMapper($this->get(PDO::class)); $experiences = $experience_mapper->getExperience(); $uri = $request->getUri(); $baseUrl = $uri->getScheme() . '://' . $uri->getHost(); $this->get(Session::class)->set('last_url', '/jobs/new'); $response = $this->get(View::class)->render($response, "jobsnew.phtml", ["categorys" => $categorys,"base_url"=>$baseUrl, "job_types"=>$job_types, "experiences"=>$experiences ,"path_url"=>$request->getUri()]); return $response; }); $app->post('/jobs/new', function ( $request, $response) { $session_user_id = $_SESSION['user_id']+0; if(!$session_user_id){ # avoid `jobs`.`owener_id` is zero. die('

您的登入資訊已過期(失效)了,請依照下列指示發佈您的徵才訊息:

Step1: 請重新登入(將另開分頁)後,

Step2: 再至上一頁重新送出您的徵才資訊,

謝謝。

'); } $data = $request->getParsedBody(); $this->get(Session::class)->set('last_url', '/jobs/new'); $jobs_data = []; $jobs_data['job_title'] = $data['job_title']; $jobs_data['job_description'] = $data['job_description']; $jobs_data['place'] = $data['place']; $jobs_data['company'] = $data['company']; $jobs_data['website'] = $data['website']; $jobs_data['salary_text'] = $data['salary_text']; $jobs_data['salary_mon_min'] = (int)$data['salary_mon_min']; $jobs_data['salary_mon_max'] = (int)$data['salary_mon_max']; // $jobs_data['salary_year_max'] = (int)$data['salary_year_max']; $jobs_data['job_type'] = (int)$data['job_type_id']; $jobs_data['experience'] = (int)$data['experience_id']; $jobs_data['category'] = (int)$data['category_id']; $jobs_data['owener_id'] = $session_user_id; $jobs_data['date_expired'] = $data['date_expired']; $jobs_data['date_post'] = date('Y-m-d H:i:s'); $jobs_data['logo_url'] = $data['logo_url']; // print_r($jobs_data);exit; $jobs_data['logo_path'] = ''; $jobs_data['company_depart'] = $data['company_depart']; // if(IS_OPEN_MORE_EMAIL_NOTIFY){ $ary_more_notify_emails = array(); foreach(array(1,2,3)as$v){ $tmp_email = trim($data['more_notify_email'.$v]); if($tmp_email and filter_var($tmp_email,FILTER_VALIDATE_EMAIL)){ $ary_more_notify_emails[] = $tmp_email; } } $jobs_data['more_notify_emails'] = $ary_more_notify_emails ? implode(',', $ary_more_notify_emails) : ''; // } // TODO check file size $files = $request->getUploadedFiles(); // print_r($files); if (!empty($files['logo_path'])) { $newfile = $files['logo_path']; if ( $newfile->getError() === UPLOAD_ERR_OK) { // $uploadFileType = $newfile->getClientMediaType(); // // print($uploadFileType); // switch ($uploadFileType) { // case 'image/png': // break; // case 'image/jpeg': // break; // case 'image/gif': // break; // default: // return false; // } $uploadFileName = $newfile->getClientFilename(); if(1===preg_match('/ /', $uploadFileName)){ die('The image filename of company logo cannot contain "space". Go back'); } $target_path = generateRandomString().'_'.$uploadFileName; $uploaded_image_path = "./job_logo/". $target_path; $newfile->moveTo($uploaded_image_path); $thumbnail_image_path = preg_replace('{\\.[^\\.]+$}', '.jpg', $target_path); $result = square_thumbnail_with_proportion($uploaded_image_path, "./job_logo_crop/". $thumbnail_image_path,600); $jobs_data['logo_path'] = $thumbnail_image_path; } } $is_admin_login = is_admin_login($this->get(Session::class), $this->get(PDO::class)); $jobs_data['verify'] = $is_admin_login ? JOB_VERIFY_OPEN : JOB_VERIFY_CLOSE; $jobs_data['visible'] = $is_admin_login ? JOB_VISIBLE_SHOW : JOB_VISIBLE_HIDE; // print_r($jobs_data); exit; $jobs = new JobsEntity($jobs_data); $jobs_mapper = new JobsMapper($this->get(PDO::class)); $insert_id = $jobs_mapper->save($jobs); function_when_job_add_or_update('_ADD_', $this, $this->get(PDO::class), $this->get(Session::class), array('insert_id'=>$insert_id)); // $response = $response->withHeader('Location', "/")->withStatus(302); // $response = $response->withHeader('Location', OWNER_DASHBOARD_URL)->withStatus(302); $response = $response->withHeader('Location', OWNER_DASHBOARD_URL) ->withStatus(302); // 302 表示臨時重定向 return $response; }); # AJAX POSTing $app->post('/jobs/apply', function ( $request, $response) { $data = $request->getParsedBody(); check_captcha(isset($data['captcha']) ? $data['captcha'] : '', true); $this->get(Session::class)->set('last_url', '/jobs/apply'); // print_r($data); if( (isset($data['resume_delete']) && ($data['resume_delete']=='on')) && $data['cv_path'] ){ $data['cv_path'] = ''; } // TODO check file size $files = $request->getUploadedFiles(); if (!empty($files['newfile'])) { $newfile = $files['newfile']; if ($newfile->getError() === UPLOAD_ERR_OK) { $uploadFileName = $newfile->getClientFilename(); $target_path = generateRandomString().'_'.$uploadFileName; $newfile->moveTo("./application/". $target_path ); $data['cv_path'] = $target_path; } } $data['send_time'] = date("Y-m-d H:i:s"); $applications = new ApplicationEntity($data); $application_mapper = new ApplicationMapper($this->get(PDO::class)); $application_mapper->save($applications); $job_id = $data['job_id']; $jobs_mapper = new JobsMapper($this->get(PDO::class)); $owner = $jobs_mapper->getOwnerbyJobId($job_id); $jobs_mapper->updateSubmitCount($job_id); // print_r($owner); $job = __get_job(array('id'=>$data['job_id']), $this->get(PDO::class),true); // $english_mapper = new EnglishMapper($this->get(PDO::class)); $english = $english_mapper->getEnglishById($data['english_ability_id']); $data['english_ability_id'] = $english['english']; $education_mapper = new EducationMapper($this->get(PDO::class)); $education = $education_mapper->getEducationById($data['highest_education_id']); $data['highest_education_id'] = $education['highest_education']; // print_r($data); $englishs = $english_mapper->getEnglish(); $english_opt = '('; foreach($englishs as $english): $english_opt .= $english->getEnglish().'/'; endforeach; $english_opt = substr($english_opt,0,-1) . ')'; $educations = $education_mapper->getEducation(); $educations_opt = '('; foreach($educations as $education): $educations_opt .= $education->getEducation().'/'; endforeach; $educations_opt = substr($educations_opt,0,-1) . ')'; $skill_mapper = new SkillMapper($this->get(PDO::class)); $official_skills = array(); foreach($skill_mapper->getOfficialSkill()as$v){ $official_skills[$v->getId()] = $v->getSkillName(); } $jobhistory_mapper = new JobHistoryMapper($this->get(PDO::class)); send_apply_to_job_owner($jobhistory_mapper, $data,$owner,$english_opt,$educations_opt,$job,$official_skills); $response = $response->withHeader('Location', "/")->withStatus(302); // $response = $response->withHeader('Location', "/jobs/dashboard")->withStatus(302); return $response; }); $app->get(OWNER_DASHBOARD_URL,function( $request, $response){ // TODO check admin if( !$login = $this->get(Session::class)->get('login') ){ $response = $response->withHeader('Location', "/login")->withStatus(302); return $response; } $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); if( $user_id = $this->get(Session::class)->get('user_id') ){ $jobs_mapper = new JobsMapper($this->get(PDO::class)); $jobs = $jobs_mapper->getJobsbyOwner($user_id); $uri = $request->getUri(); $baseUrl = $uri->getScheme() . '://' . $uri->getHost(); $response = $this->get(View::class)->render($response, "dashboard.phtml", ["jobs_mapper"=>$jobs_mapper, "categorys" => $categorys, "result"=>count($jobs),"jobs"=>$jobs, "url"=>$request->getUri()->getQuery(),"base_url"=>$baseUrl,"path_url"=>$request->getUri() ]); }else{ $response = $response->withHeader('Location', "/login")->withStatus(302); return $response; } return $response; }); $app->get(sprintf(ADMIN_JOB_EDIT_URL,'{id}'), function ($request, $response, $args) { // start.... $job = null; $is_verify_hash_correct=false; $urlquery = $request->getQueryParams(); $job_id = $args['id']+0; if(isset($urlquery[URLQUERY_HASH4VERIFY_KEY])){ $job = __get_job($args, $this->get(PDO::class)); $is_verify_hash_correct = is_correct_job_hash( $job_id, $job[0]->get_owener_email(), $urlquery[URLQUERY_HASH4VERIFY_KEY] ); } // TODO check admin if( !$login = $this->get(Session::class)->get('login') and !$is_verify_hash_correct ){ $response = $response->withHeader('Location', "/login")->withStatus(302); return $response; } $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); if(!$job){ $job = __get_job($args, $this->get(PDO::class)); } $job_type_mapper = new JobTypeMapper($this->get(PDO::class)); $job_types = $job_type_mapper->getJobType(); $job_diff_notification_mapper = new JobDiffNotificationMapper($this->get(PDO::class)); $ary_history_table = $job_diff_notification_mapper->findAllByJobId($job_id); $experience_mapper = new ExperienceMapper($this->get(PDO::class)); $experiences = $experience_mapper->getExperience(); $this->get(Session::class)->set('last_url', '/jobs/admin/edit'); $response = $this->get(View::class)->render($response, "jobedit_admin.phtml", [ 'flash_messages'=>$this->get(Flash::class)->getMessages(), 'ary_history_table'=>$ary_history_table, "categorys" => $categorys, "job_types"=>$job_types, "experiences"=>$experiences, "base_url"=>$request->getUri()->getScheme() . '://' .$request->getUri()->getHost(),"job" => $job[0],"path_url"=>$request->getUri()]); return $response; }); function get_is_valid_key1($job_id, $owner_user_id){ $is_valid_key1 = false; $key4changing_expired_day = isset($_GET['key1']) ? $_GET['key1'] : ''; $valid_key1 = get_key4changing_expired_day($job_id, $owner_user_id); if($key4changing_expired_day and $valid_key1===$key4changing_expired_day){ $is_valid_key1 = true; } return $is_valid_key1; } $app->get('/jobs/edit/{id}', function ($request, $response, $args) { $job_id = (int)$args['id']; $jobs_mapper = new JobsMapper($this->get(PDO::class)); $job = $jobs_mapper->getJobById($job_id); $owner_user_id = $job[0]->get_owener_id(); $is_valid_key1 = get_is_valid_key1($job_id, $owner_user_id); if( !$login = $this->get(Session::class)->get('login') and !$is_valid_key1){ $response = $response->withHeader('Location', "/login")->withStatus(302); return $response; } $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); if(!$is_valid_key1){ if(!is_admin_login_simple() and $job[0]->get_owener_id()!=$_SESSION['user_id']){ $response = $response->withHeader('Location', OWNER_DASHBOARD_URL.'?cannot_edit_others_job')->withStatus(302); return $response; } } $job_type_mapper = new JobTypeMapper($this->get(PDO::class)); $job_types = $job_type_mapper->getJobType(); $experience_mapper = new ExperienceMapper($this->get(PDO::class)); $experiences = $experience_mapper->getExperience(); $this->get(Session::class)->set('last_url', '/jobs/edit'); $ary_view_data = ["categorys" => $categorys, "job_types"=>$job_types, "experiences"=>$experiences, "base_url"=>$request->getUri()->getScheme() . '://' .$request->getUri()->getHost(),"job" => $job[0],"path_url"=>$request->getUri()]; # $ary_apply_application = $jobs_mapper->getAllApplyApplicationByJobId($job_id); $eng_mapper = new EnglishMapper($this->get(PDO::class)); $ary_eng = array(); foreach($ary_apply_application as$k=>$v){ if(!isset($ary_eng[$v['english_ability_id']])){ $ary_eng[$v['english_ability_id']] = $eng_mapper->getEnglishById($v['english_ability_id'])['english']; } $ary_apply_application[$k]['english_ability_id'] = $ary_eng[$v['english_ability_id']]; } $ary_view_data['ary_apply_application'] = $ary_apply_application;$jobs_mapper->getAllApplyApplicationByJobId($job_id); $ary_view_data['int_apply_count'] = count( $ary_view_data['ary_apply_application'] ); $response = $this->get(View::class)->render($response, "jobedit.phtml", $ary_view_data); return $response; }); $app->post('/jobs/status/edit', function ($request, $response, $args) { $data = $request->getParsedBody(); $this->get(Session::class)->set('last_url', '/jobs/admin/edit'); $jobs_data = []; $jobs_data['id'] = $data['id']; $jobs_data['visible'] = $data['visible']; $jobs = new JobsEntity($jobs_data); $jobs_mapper = new JobsMapper($this->get(PDO::class)); $re = $jobs_mapper->update_status($jobs); $jobhistory_mapper = new JobHistoryMapper($this->get(PDO::class)); $do_what_id = $data['visible']==1 ? OWNER_VISIBLE_JOB : OWNER_INVISIBLE_JOB; $jobhistory_mapper->save($jobs_data['id'], $this->get(Session::class)->get('user_id'), $do_what_id); // $response = $response->withHeader('Location', "/jobs/admin/edit/".$jobs_data['id'])->withStatus(302); // $response = $response->withHeader('Location', "/jobs/dashboard")->withStatus(302); $response->getBody()->write(json_encode($re, JSON_UNESCAPED_UNICODE)); return $response->withHeader('Content-Type', 'application/json'); // return $response->withJson($re); }); $app->post('/jobs/edit', function ($request, $response, $args) { $data = $request->getParsedBody(); $job_id = $data['id']; $jobs_mapper = new JobsMapper($this->get(PDO::class)); $job = $jobs_mapper->getJobById($job_id); $owner_user_id = $job[0]->get_owener_id(); $is_valid_key1 = get_is_valid_key1($job_id, $owner_user_id); if( !$login = $this->get(Session::class)->get('login') and !$is_valid_key1){ $response = $response->withHeader('Location', "/login")->withStatus(302); return $response; } // $this->get(Session::class)->set('last_url', '/jobs/edit'); $jobs_data = []; $jobs_data['id'] = $job_id; $jobs_data['job_title'] = $data['job_title']; $jobs_data['job_description'] = $data['job_description']; $jobs_data['place'] = $data['place']; $jobs_data['company'] = $data['company']; $jobs_data['website'] = $data['website']; $jobs_data['salary_text'] = $data['salary_text']; $jobs_data['salary_mon_min'] = (int)$data['salary_mon_min']; $jobs_data['salary_mon_max'] = (int)$data['salary_mon_max']; $jobs_data['job_type'] = (int)$data['job_type_id']; $jobs_data['experience'] = (int)$data['experience_id']; $jobs_data['category'] = (int)$data['category_id']; $is_not_admin_login = !is_admin_login($this->get(Session::class), $this->get(PDO::class)); // print_r($data);exit(); if(IS_OPEN_STILL_VISIBLE_AFTER_OWNER_EDIT_JOB_FEATURE){ $jobs_data['visible'] = $data['visible']==JOB_VISIBLE_SHOW ? JOB_VISIBLE_SHOW : JOB_VISIBLE_HIDE; }else{ if($is_not_admin_login){ $jobs_data['visible'] = JOB_VISIBLE_HIDE; }else{ $jobs_data['visible'] = $data['visible']==JOB_VISIBLE_SHOW ? JOB_VISIBLE_SHOW : JOB_VISIBLE_HIDE; } } // print_r($jobs_data); print_r($data);exit(); if(IS_OPEN_STILL_VISIBLE_AFTER_OWNER_EDIT_JOB_FEATURE){ $jobs_mapper = new JobsMapper($this->get(PDO::class)); # keep original value $jobs_data['verify'] = $jobs_mapper->getSingleJobById($job_id)->getVerify(); }else{ $jobs_data['verify'] = !$is_not_admin_login ? JOB_VERIFY_OPEN : JOB_VERIFY_CLOSE; } $jobs_data['date_expired'] = $data['date_expired']; $jobs_data['company_depart'] = $data['company_depart']; // if(IS_OPEN_MORE_EMAIL_NOTIFY){ $ary_more_notify_emails = array(); foreach(array(1,2,3)as$v){ $tmp_email = trim($data['more_notify_email'.$v]); if($tmp_email and filter_var($tmp_email,FILTER_VALIDATE_EMAIL)){ $ary_more_notify_emails[] = $tmp_email; } } $jobs_data['more_notify_emails'] = $ary_more_notify_emails ? implode(',', $ary_more_notify_emails) : ''; // } $jobs_data['logo_path_tmp'] = $data['logo_path']; $jobs_data['logo_path'] = ''; $jobs_data['logo_url'] = $data['logo_url']; // print_r($jobs_data);exit(); $files = $request->getUploadedFiles(); // print_r($files);/ // TODO check file size if (!empty($files['newfile'])) { $newfile = $files['newfile']; // print_r($newfile); if ($newfile->getError() === UPLOAD_ERR_OK) { $uploadFileName = $newfile->getClientFilename(); $target_path = generateRandomString().'_'.$uploadFileName; $uploaded_image_path = "./job_logo/". $target_path; $newfile->moveTo($uploaded_image_path); $thumbnail_image_path = preg_replace('{\\.[^\\.]+$}', '.jpg', $target_path); $result = square_thumbnail_with_proportion($uploaded_image_path, "./job_logo_crop/". $thumbnail_image_path,600); $jobs_data['logo_path'] = $thumbnail_image_path; } } if( (isset($data['logo_delete']) && ($data['logo_delete']=='on')) || $jobs_data['logo_path'] ){ $file_path = $_SERVER['DOCUMENT_ROOT'] .'/job_logo_crop/'.$jobs_data['logo_path_tmp']; // print($file_path); if(is_file($file_path)){ unlink($file_path); } }else{ $jobs_data['logo_path'] = $jobs_data['logo_path_tmp']; } // print_r($jobs_data);exit(); $jobs = new JobsEntity($jobs_data); $jobs_mapper = new JobsMapper($this->get(PDO::class)); $jobs_mapper->update($jobs, $this->get(Session::class)); $querystring = array(); foreach($_GET as$k=>$v){ $querystring[] = $k.'='.$v; } $querystring = $querystring ? '?'.implode('&',$querystring) : ''; $response = $response->withHeader('Location', "/jobs/edit/".$jobs_data['id'].$querystring)->withStatus(302); return $response; }); #/jobs/dashboard/admin $app->get(ADMIN_DASHBOARD_URL,function( $request, $response){ // TODO check admin if( !$login = $this->get(Session::class)->get('login') ){ $response = $response->withHeader('Location', "/login")->withStatus(302); return $response; } $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); $params = $request->getQueryParams(); $param_keyword = isset($params['keyword'])? $params['keyword']:''; $job_query = "SELECT j.id , j.job_title , j.logo_path , j.submit_count , j.company , j.place , t.job_type , j.visible , j.verify ,j.date_mod ,j.date_post ,j.date_expired , u.name, u.email from jobs j join job_type t on (t.id = j.job_type_id) join users u on (u.id = j.owener_id)"; if( $param_keyword != ''){ $job_query .= " and (j.job_title LIKE '%$param_keyword%' OR j.company LIKE '%$param_keyword%' OR j.place LIKE '%$param_keyword%' OR t.job_type LIKE '%$param_keyword%' OR u.name LIKE '%$param_keyword%' OR u.email LIKE '%$param_keyword%')"; } $job_query .= ' WHERE j.is_trash=0'; $job_query .= ' ORDER BY `visible` DESC, j.date_mod DESC'; // print($job_query); $Paginator = new Paginator($this->get(PDO::class), $job_query); $limit = ( isset( $params['limit'] ) ) ? $params['limit'] : 10; $page = ( isset( $params['page'] ) ) ? $params['page'] : 1; $links = ( isset( $params['links'] ) ) ? $params['links'] : 7; $results = $Paginator->getData( $limit, $page, $links, "JobsEntity" ); $jobs = $results->data; $jobs_mapper = new JobsMapper($this->get(PDO::class)); // $job = $jobs_mapper->getJobById($job_id); $response = $this->get(View::class)->render($response, "dashboard_admin.phtml", ["categorys" => $categorys, "result"=>$results,"job_mapper"=>$jobs_mapper,"jobs"=>$jobs, "Paginator"=> $Paginator, "path"=>$request->getUri()->getPath(),"url"=>$request->getUri()->getQuery(),"base_url"=>$request->getUri()->getScheme() . '://' .$request->getUri()->getHost(),"path_url"=>$request->getUri() ]); return $response; }); $app->get('/jobs/{id}', function ($request, $response, $args) { // TODO check if !exist => not found $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); $job_id = (int)$args['id']; $jobs_mapper = new JobsMapper($this->get(PDO::class)); $job = $jobs_mapper->getJobByIdLimitVisible($job_id); // print_r($job); if( isset($job['error'])){ // print($job['error']); return $response = $this->get(View::class)->render($response, "404.phtml", ["categorys" => $categorys,"path"=>$request->getUri()->getPath() ,"url"=>$request->getUri()->getQuery() ,"base_url"=>$request->getUri()->getScheme() . '://' .$request->getUri()->getHost() ,"error_msg"=>$job['error' ] ,"path_url"=>$request->getUri()] ); } $english_mapper = new EnglishMapper($this->get(PDO::class)); $englishs = $english_mapper->getEnglish(); $education_mapper = new EducationMapper($this->get(PDO::class)); $educations = $education_mapper->getEducation(); $apply_id = 0; $apply = []; #default, Array if( isset($_SESSION['user_id']) and $_SESSION['user_id'] ){ $user_id = (int)$_SESSION['user_id']; $user_mapper = new UserMapper($this->get(PDO::class)); $user = $user_mapper->getUserById($user_id); $apply_id = $user->getApplyId(); if( $apply_id != 0 ){ $apply_mapper = new UserApplyTmpMapper($this->get(PDO::class)); $apply = $apply_mapper->getApplyById($apply_id); #not default, Object } } $viewdata = ["apply_id"=> $apply_id, "apply"=>$apply, "categorys" => $categorys,"englishs" => $englishs,"educations" => $educations, "base_url"=>$request->getUri()->getScheme() . '://' .$request->getUri()->getHost(),"job_detail" => $job[0],"path_url"=>$request->getUri()]; if(IS_OPEN_SKILL_FEATURE){ $skill_mapper = new SkillMapper($this->get(PDO::class)); $skills = $skill_mapper->getOfficialSkill(); $viewdata['skills'] = $skills; # $nonofficial_skills = $skill_mapper->getNonOfficialSkill(); $ary_nonofficial_skills = array(); foreach($nonofficial_skills as$_){ $ary_nonofficial_skills[$_->getId()] = $_->getSkillName(); } $viewdata['ary_nonofficial_skills'] = $ary_nonofficial_skills; } //////////// $knowhow_mapper = new KnowhowMapper($this->get(PDO::class)); $knowhows = $knowhow_mapper->getOfficialKnowhow(); $viewdata['knowhows'] = $knowhows; # $nonofficial_knowhows = $knowhow_mapper->getNonOfficialKnowhow(); $ary_nonofficial_knowhows = array(); foreach($nonofficial_knowhows as$_){ $ary_nonofficial_knowhows[$_->getId()] = $_->getKnowhowName(); } $viewdata['ary_nonofficial_knowhows'] = $ary_nonofficial_knowhows; # $response = $this->get(View::class)->render($response, "jobdetail.phtml", $viewdata); return $response; });