get('/', function ($request, $response) { // return $response; $_SESSION['last_url'] = '/'; // $this->get(Session::class)->set('last_url', '/'); $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); $params = $request->getQueryParams(); $param_keyword = isset($params['keyword']) ? $params['keyword'] : ''; $param_category = isset($params['category']) ? $params['category'] : ''; $param_company = isset($params['company']) ? $params['company'] : ''; $IS_COMPANY_LIST_PAGE = is_company_list_page($params); $job_query = get_job_sql_query(); if (!empty($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 e.experience LIKE '%$param_keyword%' OR c.category LIKE '%$param_keyword%' OR j.salary_mon_min LIKE '%$param_keyword%' OR j.salary_mon_max LIKE '%$param_keyword%' )"; } if (!empty($param_category)) { $job_query .= " AND c.id = $param_category"; } if (!empty($param_company)) { $job_query .= " AND j.company='{$param_company}' "; } $job_query .= ' ORDER BY j.date_mod DESC'; if ($IS_COMPANY_LIST_PAGE) { $job_query = "SELECT MAX(id) AS id , COUNT(id) AS jobnum_in_company , MAX(submit_count) AS submit_count , MAX(logo_url) AS logo_url , MAX(logo_path) AS logo_path , MAX(job_title) AS job_title , MAX(company_depart) AS company_depart , MAX(company) AS company , MAX(place) AS place , MAX(job_type) AS job_type , MAX(category) AS category , MAX(salary_text) AS salary_text , MAX(salary_mon_min) AS salary_mon_min , MAX(salary_mon_max) AS salary_mon_max , MAX(owener_id) AS owener_id , MAX(`name`) AS `name` , MAX(school_no) AS school_no , MAX(experience) AS experience FROM ({$job_query}) tbl GROUP BY tbl.company"; } // print($job_query); $Paginator = new Paginator($this->get(PDO::class), $job_query); $limit = (isset($params['limit'])) ? $params['limit'] + 0 : DEFAULT_JOB_PAGESIZE_AT_HOME; $page = (isset($params['page'])) ? $params['page'] + 0 : 1; if ($page < 1) { $page = 1; } $links = (isset($params['links'])) ? $params['links'] + 0 : 7; $results = $Paginator->getData($limit, $page, $links, "JobsEntity"); $jobs = $results->data; #cannot output.... if(isset($_GET['xx'])){ print_r($jobs); } $at = $IS_COMPANY_LIST_PAGE ? 'INDEX_GROUPBY_COMPANY' : 'INDEX'; $response = $this->get(View::class)->render($response, "index.phtml", [ "categorys" => $categorys, "result" => $results, "jobs" => $jobs, "Paginator" => $Paginator, "hidden_category" => $param_category, "url" => $request->getUri()->getQuery(), "base_url" => $request->getUri()->getScheme() . '://' . $request->getUri()->getHost() . ($request->getUri()->getPort() && !in_array($request->getUri()->getPort(), [80, 443]) ? ':' . $request->getUri()->getPort() : ''), "path_url" => $request->getUri(), "at" => $at, "IS_COMPANY_LIST_PAGE" => $IS_COMPANY_LIST_PAGE ]); return $response; })->setName('homepage'); $app->post(AJAX_JOBSHOW_URL, function ($request, $response) { _ajax_response_of_job_which_is_changed_with_one_field( $request, $this->get(PDO::class), 'VISIBLE', $this->get(Session::class) ); }); $app->post(AJAX_JOBVERIFY_URL, function ($request, $response) { _ajax_response_of_job_which_is_changed_with_one_field( $request, $this->get(PDO::class), 'VERIFY', $this->get(Session::class) ); }); $app->post(AJAX_MOVE2TRASH_URL, function ($request, $response) { _ajax_response_of_job_which_is_changed_with_one_field( $request, $this->get(PDO::class), 'TRASH', $this->get(Session::class) ); }); require_once __DIR__ . '/routes-jobs.php'; $app->post(ADMIN_JOB_EDIT_POSTING_URL, function ($request, $response, $args) { $data = $request->getParsedBody(); $job_id = isset($data['id']) ? $data['id'] + 0 : 0; $is_verify_hash_correct = false; if (isset($data[INPUT_NAME_HASH4VERIFY])) { $job = __get_job(array('id' => $job_id), $this->get(PDO::class))[0]; $is_verify_hash_correct = is_correct_job_hash( $job_id, $job->get_owener_email(), $data[INPUT_NAME_HASH4VERIFY] ); } $is_admin_login = is_admin_login_simple(); if (!$is_admin_login and !$is_verify_hash_correct) { if (IS_DEVELOPER) { var_dump($is_admin_login); echo '
'; var_dump($is_verify_hash_correct); } die('Not allow'); } $url_posting_from = $is_verify_hash_correct ? sprintf(ADMIN_JOB_EDIT_URL_WITH_VERIFY_HASH, $job_id, $data[INPUT_NAME_HASH4VERIFY]) : sprintf(ADMIN_JOB_EDIT_URL, $job_id); $this->get(Session::class)->set('last_url', '/jobs/admin/edit'); # TODO: change all last_url to /jobs/admin/edit/{job_id} like this. $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['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['verify'] = (int)$data['verify_id']; $jobs_data['visible'] = (int)$data['visible_id']; $jobs_data['date_expired'] = $data['date_expired']; $jobs_data['company_depart'] = $data['company_depart']; $jobs_data['logo_path_tmp'] = $data['logo_path']; $jobs_data['logo_path'] = ''; $jobs_data['logo_url'] = $data['logo_url']; // TODO check file size $files = $request->getUploadedFiles(); // print_r($files);/ if (!empty($files['newfile'])) { $newfile = $files['newfile']; // print_r($newfile); if ($newfile->getError() === UPLOAD_ERR_OK) { // $uploadFileName = $newfile->getClientFilename(); // $target_path = generateRandomString().'_'.$uploadFileName; // print("./job_logo/". $target_path); // $newfile->moveTo("./job_logo/". $target_path ); // $jobs_data['logo_path'] = $target_path; $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, 200); $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']; } $jobs = new JobsEntity($jobs_data); $jobs_mapper = new JobsMapper($this->get(PDO::class)); // echo __FILE__.':'.__LINE__; $jobs_mapper->update($jobs, $this->get(Session::class), true); $this->get(Flash::class)->addMessage( 'success', '已更新職缺 (於' . date('Y-m-d H:i:s') . ')' ); $response = $response->withHeader('Location', $url_posting_from)->withStatus(302); // $response = $response->withHeader('Location', "/jobs/dashboard")->withStatus(302); return $response; }); $app->get('/intro', function ($request, $response, $args) { $uri = $request->getUri(); $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); $baseUrl = $uri->getScheme() . '://' . $uri->getHost(); $response = $this->get(View::class)->render($response, "posts/intro.phtml", [ 'path' => $request->getUri()->getPath(), 'url' => $request->getUri()->getQuery(), 'base_url' => $baseUrl, 'categorys' => $categorys ]); return $response; }); require_once __DIR__ . '/routes-tools.php'; $app->get("/login", function ($request, $response, $args) { if ($this->get(Session::class)->get('last_url') != '/login') { $this->get(Session::class)->set('error_msg', null); } $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); $this->get(Session::class)->set('last_url', '/login'); $response = $this->get(View::class)->render($response, "login.phtml", ["categorys" => $categorys, "base_url" => $request->getUri()->getScheme() . '://' .$request->getUri()->getHost()]); return $response; }); $app->post("/login", function ($request, $response, $args) use($app) { $data = $request->getParsedBody(); // print_r($data);exit(); check_captcha(isset($data['captcha']) ? $data['captcha'] : ''); $this->get(Session::class)->set('last_url', '/login'); $user_data = []; $user_data['email'] = $data['email']; $user_data['pwd'] = md5($data['pwd']); // print_r($user_data); $user = new UserEntity($user_data); $user_mapper = new UserMapper($this->get(PDO::class)); $usersloginnum_mapper = new UsersLoginNumMapper($this->get(PDO::class)); $result = $user_mapper->checkMember($user); // print_r($result); if (isset($result['error'])) { $this->get(Session::class)->set('error_msg', $result); // $response = $response->withHeader('Location', "/login")->withStatus(302); $response = $response ->withHeader('Location', '/login') ->withStatus(302); } else { $user_id = $result['user']['id']; $last_login_time = date('Y-m-d H:i:s'); setup_user_session( $this->get(Session::class), $result['user']['name'], $user_data['email'], $user_data['pwd'], $result['user']['authority'], $user_id ); // insert users_login_num row data $usersloginnum_mapper->save($user_id); // update users.login_total_num $login_total_num = $usersloginnum_mapper->countUsersLoginNum($user_id); $user_mapper->updateLoginTotalNum($user_id, $login_total_num); if (isset($data['remeber_me']) and $data['remeber_me']) { $result = $user_mapper->updateLastLoginData($user_id); if ($result and isset($result['success']) and isset($result['last_login_token']) and $result['last_login_token']) { setcookie( LOGIN_TOKEN_COOKIE_KEY, $result['last_login_token'], time() + REMEBER_LOGIN_TIME ); // echo $result['last_login_token']; print_r($_COOKIE);exit(); } } $response = $response ->withHeader('Location', '/') ->withStatus(302); } return $response; }); $app->get("/logout", function ($request, $response) { $user_id = $this->get(Session::class)->get('user_id'); // var_dump($user_id); $user_mapper = new UserMapper($this->get(PDO::class)); $user_mapper->updateLastLoginData($user_id, true); remove_cookie(LOGIN_TOKEN_COOKIE_KEY); $this->get(Session::class)->destroy(); $response = $response->withHeader('Location', "/login")->withStatus(302); return $response; }); $app->get("/user/new", function ($request, $response, $args) { if ($this->get(Session::class)->get('last_url') != '/user/new') { $this->get(Session::class)->set('error_msg', null); $this->get(Session::class)->set('user', null); } $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); $this->get(Session::class)->set('last_url', '/user/new'); $response = $this->get(View::class)->render($response, "usernew.phtml", ["categorys" => $categorys, "base_url" => $request->getUri()->getScheme() . '://' .$request->getUri()->getHost()]); return $response; }); $app->post("/user/new", function ($request, $response, $args) { $this->get(Session::class)->set('last_url', '/user/new'); $data = $request->getParsedBody(); check_captcha(isset($data['captcha']) ? $data['captcha'] : ''); $user_data = []; $user_data['email'] = $data['email']; $user_data['pwd'] = md5($data['pwd']); $user_data['name'] = $data['name']; $user_data['school_no'] = $data['school_no']; $user_data['phone'] = $data['phone']; $user_data['people_email'] = ($data['people'] == 'on') ? 1 : 0; $user_data['job_email'] = ($data['job'] == 'on') ? 1 : 0; $user_data['token'] = generateRandomString(15); $this->get(Session::class)->set('user', $data); $user = new UserEntity($user_data); $user_mapper = new UserMapper($this->get(PDO::class)); $result = $user_mapper->createUser($user); // print_r( $result['error'] ); if (isset($result['error'])) { $this->get(Session::class)->set('error_msg', $result['error']); // print_r( $_SESSION ); $response = $response->withHeader('Location', "/user/new")->withStatus(302); } else { $send_result = send_mail($user_data); $this->get(Session::class)->set('mail_msg', $send_result['msg']); // $this->get(Session::class)->set('login', $user_data); // $this->get(Session::class)->set('verify', 0); // $this->get(Session::class)->set('user_id', $result['user_id']); // $this->get(Session::class)->set('test',$result); $response = $response->withHeader('Location', "/")->withStatus(302); } return $response; }); $app->get("/confirmation/new", function ($request, $response, $args) { if ($this->get(Session::class)->get('last_url') != '/confirmation/new') { $this->get(Session::class)->set('error_msg', null); } $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); $this->get(Session::class)->set('last_url', '/confirmation/new'); $response = $this->get(View::class)->render($response, "confirmation.phtml", ["categorys" => $categorys, "base_url" => $request->getUri()->getScheme() . '://' .$request->getUri()->getHost()]); return $response; }); $app->post("/confirmation/new", function ($request, $response, $args) { $this->get(Session::class)->set('last_url', '/confirmation/new'); $data = $request->getParsedBody(); check_captcha(isset($data['captcha']) ? $data['captcha'] : ''); $user_data = []; $user_data['email'] = $data['email']; $user = new UserEntity($user_data); $user_mapper = new UserMapper($this->get(PDO::class)); $result = $user_mapper->checkStatus($user); // print_r($result); if (isset($result['error'])) { $this->get(Session::class)->set('error_msg', $result); $response = $response->withHeader('Location', "/confirmation/new")->withStatus(302); } else { $this->get(Session::class)->set('mail_msg', $result['msg']); $response = $response->withHeader('Location', "/confirmation/new")->withStatus(302); } return $response; }); $app->get("/password/edit", function ($request, $response, $args) { if ($this->get(Session::class)->get('last_url') != '/password/edit') { $this->get(Session::class)->set('error_msg', null); } $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); $this->get(Session::class)->set('last_url', 'password/edit'); $params = $request->getQueryParams(); $response = $this->get(View::class)->render($response, "pwd_edit.phtml", ["token" => $params['token'], "categorys" => $categorys, "base_url" => $request->getUri()->getScheme() . '://' .$request->getUri()->getHost()]); return $response; }); $app->post("/password/edit", function ($request, $response, $args) { $this->get(Session::class)->set('last_url', '/password/edit'); $data = $request->getParsedBody(); // print($data); $user_data = []; if ($data['token'] == '') { $this->get(Session::class)->set('error_msg', '此密碼重置無效,請重新申請。'); $response = $response->withHeader('Location', "/password/edit?token=" . $data['token'] . "&email=" . $data['email'])->withStatus(302); return $response; } $user_data['email'] = $data['email']; $user_data['pwd_token'] = $data['token']; $user_data['pwd'] = md5($data['new_pwd']); if ($data['new_pwd'] != $data['re_pwd']) { $this->get(Session::class)->set('error_msg', '兩次密碼輸入不同 請檢查'); $response = $response->withHeader('Location', "/password/edit?token=" . $data['token'] . "&email=" . $data['email'])->withStatus(302); return $response; } else { $user_data['pwd'] = md5($data['new_pwd']); } $user = new UserEntity($user_data); $user_mapper = new UserMapper($this->get(PDO::class)); $result = $user_mapper->updatePWD($user); // print_r($user_data); if (isset($result['error'])) { $this->get(Session::class)->set('error_msg', $result['error']); $response = $response->withHeader('Location', "/password/edit?token=" . $data['token'] . "&email=" . $data['email'])->withStatus(302); } else { $user = new UserEntity($user_data); $user_mapper = new UserMapper($this->get(PDO::class)); $result_user = $user_mapper->checkMember($user); // print_r($result); if (isset($result_user['error'])) { $this->get(Session::class)->set('error_msg', $result_user['error']); $response = $response->withHeader('Location', "/login")->withStatus(302); } else { $this->get(Session::class)->set('mail_msg', $result['success']); $this->get(Session::class)->set('login', $user_data); $this->get(Session::class)->set('verify', $result_user['user']['authority']); $this->get(Session::class)->set('user_id', $result_user['user']['id']); $response = $response->withHeader('Location', "/")->withStatus(302); } } return $response; }); $app->get("/password/new", function ($request, $response, $args) { if ($this->get(Session::class)->get('last_url') != '/password/new') { $this->get(Session::class)->set('error_msg', null); } $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); $this->get(Session::class)->set('last_url', '/password/new'); $response = $this->get(View::class)->render($response, "pwd_new.phtml", ["categorys" => $categorys, "base_url" => $request->getUri()->getScheme() . '://' .$request->getUri()->getHost()]); return $response; }); $app->post("/password/new", function ($request, $response, $args) { $this->get(Session::class)->set('last_url', '/password/new'); $data = $request->getParsedBody(); check_captcha(isset($data['captcha']) ? $data['captcha'] : ''); $user_data = []; $user_data['email'] = $data['email']; $user = new UserEntity($user_data); $user_mapper = new UserMapper($this->get(PDO::class)); $result = $user_mapper->pwd_apply($user); // print_r($result); if (isset($result['error'])) { $this->get(Session::class)->set('error_msg', $result); $response = $response->withHeader('Location', "/password/new")->withStatus(302); } else { $this->get(Session::class)->set('mail_msg', $result['msg']); $response = $response->withHeader('Location', "/password/new")->withStatus(302); } return $response; }); $app->get("/user/update", function ($request, $response, $args) { if (!$login = $this->get(Session::class)->get('login')) { $response = $response->withHeader('Location', "/login")->withStatus(302); return $response; } $post_msg = ''; if ($_SESSION['last_url'] != '/user/update') { $this->get(Session::class)->set('error_msg', null); } else { if (isset($_SESSION['post_msg'])) { $post_msg = '會員資料修改成功'; unset($_SESSION['post_msg']); } } $categorys_mapper = new CategoryMapper($this->get(PDO::class)); $categorys = $categorys_mapper->getCategory(); $user_id = (int)$_SESSION['user_id']; $mapper = new UserMapper($this->get(PDO::class)); $user = $mapper->getUserById($user_id); $user_data = []; $user_data['email'] = $user->getEmail(); $user_data['name'] = $user->getName(); $user_data['school_no'] = $user->getSchoolNo(); $user_data['phone'] = $user->getPhone(); $user_data['pwd'] = $user->getMd5Pwd(); $user_data['people'] = $user->getPeopleEmail(); $user_data['job'] = $user->getJobEmail(); $this->get(Session::class)->set('login', $user_data); $this->get(Session::class)->set('last_url', '/user/update'); $response = $this->get(View::class)->render($response, "userupdate.phtml", ["post_msg" => $post_msg, "user" => $user, "categorys" => $categorys, "base_url" => $request->getUri()->getScheme() . '://' .$request->getUri()->getHost()]); return $response; }); $app->post("/user/update", function ($request, $response) { $this->get(Session::class)->set('error_msg', null); $this->get(Session::class)->set('last_url', '/user/update'); $data = $request->getParsedBody(); if (md5($data['pwd']) == $_SESSION['login']['pwd']) { $user_data = []; $user_data['email'] = $data['email']; $user_data['name'] = $data['name']; $user_data['phone'] = $data['phone']; $user_data['school_no'] = $data['school_no']; $user_data['pwd'] = md5($data['pwd']); $user_data['id'] = $_SESSION['user_id']; $user_data['people_email'] = ($data['people'] == 'on') ? 1 : 0; $user_data['job_email'] = ($data['job'] == 'on') ? 1 : 0; if ($data['new_pwd'] != '') { if ($data['new_pwd'] != $data['re_pwd']) { $this->get(Session::class)->set('error_msg', array('error' => '兩次密碼輸入不同 請檢查', 'field' => 're_pwd')); $response = $response->withHeader('Location', "/user/update")->withStatus(302); return $response; } else { $user_data['pwd'] = md5($data['new_pwd']); } } $user = new UserEntity($user_data); $user_mapper = new UserMapper($this->get(PDO::class)); $result = $user_mapper->updateUser($user); if (isset($result['error'])) { $this->get(Session::class)->set('error_msg', $result); } else { $this->get(Session::class)->set('post_msg', 'success'); $this->get(Session::class)->set('login', $user_data); } $response = $response->withHeader('Location', "/user/update")->withStatus(302); return $response; } else { $this->get(Session::class)->set('error_msg', array('error' => '密碼錯誤 請檢查', 'field' => 'pwd')); $response = $response->withHeader('Location', "/user/update")->withStatus(302); return $response; } }); # AJAX POSTing $app->get("/user/apply/update", function ($request, $response, $args) { 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(); $english_mapper = new EnglishMapper($this->get(PDO::class)); $englishs = $english_mapper->getEnglish(); $education_mapper = new EducationMapper($this->get(PDO::class)); $educations = $education_mapper->getEducation(); $user_id = (int)$_SESSION['user_id']; $mapper = new UserMapper($this->get(PDO::class)); $user = $mapper->getUserById($user_id); // print_r($user); $apply_id = $user->getApplyId(); $apply = []; if ($apply_id != 0) { $apply_mapper = new UserApplyTmpMapper($this->get(PDO::class)); $apply = $apply_mapper->getApplyById($apply_id); } else { // $apply_data = new UserApplyTmpEntity($user_data); $apply_mapper = new UserApplyTmpMapper($this->get(PDO::class)); $apply_result = $apply_mapper->new_apply($user); $apply_id = $apply_result['id']; // print('new_apply_id:'.$apply_id); $user_mapper = new UserMapper($this->get(PDO::class)); $user_mapper->updateUserApplyId($user_id, $apply_id); $apply = $apply_mapper->getApplyById($apply_id); // print_r($apply); } $viewdata = ["apply_id" => $apply_id, "apply" => $apply, "categorys" => $categorys, "englishs" => $englishs, "educations" => $educations, "base_url" => $request->getUri()->getScheme() . '://' .$request->getUri()->getHost()]; 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; $this->get(Session::class)->set('last_url', '/user/apply/update'); $response = $this->get(View::class)->render($response, "applyupdate.phtml", $viewdata); return $response; }); $app->post("/user/apply/update", function ($request, $response) { $data = $request->getParsedBody(); $this->get(Session::class)->set('last_url', '/user/apply/update'); // print_r($data); $data['cv_path_tmp'] = $data['cv_path']; $data['cv_path'] = ''; if (IS_OPEN_SKILL_FEATURE) { if (!isset($data['skill'])) { $data['skill'] = array(); #default } $other_skill = $data['other_skill']; $ary_skill_names = preg_split("/(\r\n|\n|\r)/", $other_skill); $skill_mapper = new SkillMapper($this->get(PDO::class)); foreach ($ary_skill_names as $skill_name) { $skill = $skill_mapper->getSkillByName($skill_name); if ($skill) { $skill_id = $skill->getId(); } else { $skill_id = $skill_mapper->save($skill_name); } $data['skill'][] = $skill_id; } $data['skill'] = ary2dbstr($data['skill']); } # if (!isset($data['knowhow'])) { $data['knowhow'] = array(); #default } $other_knowhow = $data['other_knowhow']; $ary_knowhow_names = preg_split("/(\r\n|\n|\r)/", $other_knowhow); $knowhow_mapper = new KnowhowMapper($this->get(PDO::class)); foreach ($ary_knowhow_names as $knowhow_name) { $knowhow = $knowhow_mapper->getKnowhowByName($knowhow_name); if ($knowhow) { $knowhow_id = $knowhow->getId(); } else { $knowhow_id = $knowhow_mapper->save($knowhow_name); } $data['knowhow'][] = $knowhow_id; } $data['knowhow'] = ary2dbstr($data['knowhow']); // TODO check file size $files = $request->getUploadedFiles(); if (!empty($files['newfile'])) { $newfile = $files['newfile']; // print_r($newfile); if ($newfile->getError() === UPLOAD_ERR_OK) { $uploadFileName = $newfile->getClientFilename(); $target_path = generateRandomString() . '_' . $uploadFileName; $newfile->moveTo("./application/" . $target_path); $data['cv_path'] = $target_path; } } if ((isset($data['resume_delete']) && $data['resume_delete'] == 'on') || $data['cv_path']) { $file_path = RESUME_FOLDER_ABS_PATH . $data['cv_path_tmp']; // print($file_path); if (is_file($file_path)) { // unlink($file_path); $tmp = explode('.', $file_path); $file_extname = '.' . $tmp[count($tmp) - 1]; rename($file_path, $file_path . RESUME_FILE_SUFFIX_DIVIDER . date('YmdHis') . $file_extname); } } else { $data['cv_path'] = $data['cv_path_tmp']; } $user_id = (int)$_SESSION['user_id']; $user_mapper = new UserMapper($this->get(PDO::class)); $user = $user_mapper->getUserById($user_id); $apply_id = $user->getApplyId(); $apply_mapper = new UserApplyTmpMapper($this->get(PDO::class)); if ($apply_id == 0) { $apply = new UserApplyTmpEntity($data); $apply_result = $apply_mapper->save($apply); $user_apply_id = $apply_result['id']; $user_mapper->updateUserApplyId($user_id, $user_apply_id); } else { $data['id'] = $apply_id; $apply = new UserApplyTmpEntity($data); $apply_mapper->update($apply); } $response = $response->withHeader('Location', "/user/apply/update")->withStatus(302); return $response; }); $app->get('/users/admin', function ($request, $response) { 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'] : ''; $users_query = "SELECT u.id, u.name, u.school_no, u.phone, u.email, u.authority, u.status, u.login_total_num, u.last_login_time from users u"; if ($param_keyword != '') { $users_query .= " where (u.name LIKE '%$param_keyword%' OR u.email LIKE '%$param_keyword%' OR u.phone LIKE '%$param_keyword%')"; } $users_query .= " ORDER BY authority DESC, u.last_login_time DESC "; #2018.11.7 // print($users_query); $Paginator = new Paginator($this->get(PDO::class), $users_query); $limit = (isset($params['limit'])) ? $params['limit'] : 12; $page = (isset($params['page'])) ? $params['page'] : 1; $links = (isset($params['links'])) ? $params['links'] : 7; $results = $Paginator->getData($limit, $page, $links, "UserEntity"); $users = $results->data; $response = $this->get(View::class)->render($response, "users_admin.phtml", ["categorys" => $categorys, "result" => $results, "users" => $users, "Paginator" => $Paginator, "path" => $request->getUri()->getPath(), "url" => $request->getUri()->getQuery(), "base_url" => $request->getUri()->getScheme() . '://' .$request->getUri()->getHost()]); return $response; }); $app->get('/user/apply/history', function ($request, $response) { 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(); $english_mapper = new EnglishMapper($this->get(PDO::class)); $education_mapper = new EducationMapper($this->get(PDO::class)); $applications = []; if ($user_id = $this->get(Session::class)->get('user_id')) { $application_mapper = new ApplicationMapper($this->get(PDO::class)); $applications = $application_mapper->getApplicationByUser($user_id); } $response = $this->get(View::class)->render($response, "my_application.phtml", ["english_mapper" => $english_mapper, "education_mapper" => $education_mapper, "applications" => $applications, "categorys" => $categorys, "path" => $request->getUri()->getPath(), "url" => $request->getUri()->getQuery(), "base_url" => $request->getUri()->getScheme() . '://' .$request->getUri()->getHost()]); return $response; }); $app->get('/confirmation', function ($request, $response) { $params = $request->getQueryParams(); // print_r($data); $user = new UserEntity($params); $user_mapper = new UserMapper($this->get(PDO::class)); $re = $user_mapper->confirm($user); $this->get(Session::class)->set('mail_msg', $re['msg']); return $response->withHeader('Location', "/")->withStatus(302); }); $app->post('/user/status/update', function ($request, $response, $args) { $data = $request->getParsedBody(); // print( $data['id'] ); $user_data = []; $user_data['id'] = $data['id']; $user_data['status'] = $data['status']; // $user_data['authority'] = $data['authority']; $user = new UserEntity($user_data); $user_mapper = new UserMapper($this->get(PDO::class)); $re = $user_mapper->update_status($user); $response->getBody()->write(json_encode($re, JSON_UNESCAPED_UNICODE)); return $response->withHeader('Content-Type', 'application/json'); // return $response->withJson($re); }); $app->post('/user/authority/update', function ($request, $response, $args) { $data = $request->getParsedBody(); // print( $data['id'] ); $user_data = []; $user_data['id'] = $data['id']; $user_data['authority'] = $data['authority']; // $user_data['authority'] = $data['authority']; $user = new UserEntity($user_data); $user_mapper = new UserMapper($this->get(PDO::class)); $re = $user_mapper->update_authority($user); $response->getBody()->write(json_encode($re, JSON_UNESCAPED_UNICODE)); return $response->withHeader('Content-Type', 'application/json'); // return $response->withJson($re); }); $app->get('/resume_file/{job_id}/{apply_user_id}', function ($request, $response, $args) { $job_id = $args['job_id']; $apply_user_id = $args['apply_user_id']; $application_mapper = new ApplicationMapper($this->get(PDO::class)); $application = $application_mapper->getApplicationByJobIdAndUser( $job_id, $apply_user_id ); // print_r($application);exit; # debug $cv_path = $application->getCVpath(); $email = $application->getEmail(); if (!$cv_path) { die('' . '履歷檔案已不存在,請聯絡 jobs@aiacademy.tw 或 求職者 ' . $application->getName() . ' ' . $email . '' . ', 謝謝!'); } else { $cv_abs_path = RESUME_FOLDER_ABS_PATH . $cv_path; if (is_file($cv_abs_path)) { header('location: ' . RESUME_URI_PREFIX . $cv_path); exit(); } else { // 20181202: try to search original backup file if existed $a = glob($cv_abs_path . '*'); if (is_file($a[0])) { $tmp = explode(DIRECTORY_SEPARATOR, $a[0]); $cv_backup_file_name = $tmp[count($tmp) - 1]; header('location: ' . RESUME_URI_PREFIX . $cv_backup_file_name); exit(); } else { // 20181202: if not existed, use newest cv file.contact user. //$email = $application->getEmail(); //$tmp2 = explode(DIRECTORY_SEPARATOR, $cv_abs_path); die('' . '履歷檔案已不存在,請聯絡 jobs@aiacademy.tw 或 求職者 ' . $application->getName() . ' ' . $email . '' . ', 謝謝!'); } } } // end of if($cv_path) }); // $app->post('/apply/check', function ($request, $response, $args) { // // if ($_SERVER['REMOTE_ADDR'] == '61.60.216.21'){ // // return $response->withJson(array('success' => '未申請過此工作')); // // } // $data = $request->getParsedBody(); // $sql = "SELECT * FROM `application` WHERE `job_id`=" . $data['job_id'] . " and `apply_user_id`=" . $data['apply_user_id']; // $stmt = $this->get(PDO::class)->query($sql); // if ($stmt->rowCount() == 0) { // return $response->withJson(array('success' => '未申請過此工作')); // } else { // return $response->withJson(array('error' => '您有申請過該工作,請問確定再次寄出職缺申請嗎?')); // } // }); $app->post('/apply/check', function ( $request, $response, $args) { $data = $request->getParsedBody(); // 建立 SQL 查詢(⚠ 建議日後用 prepared statement 防止 SQL injection) $sql = "SELECT * FROM `application` WHERE `job_id`=" . intval($data['job_id']) . " AND `apply_user_id`=" . intval($data['apply_user_id']); $stmt = $this->get(PDO::class)->query($sql); $payload = []; if ($stmt->rowCount() == 0) { $payload = ['success' => '未申請過此工作']; } else { $payload = ['error' => '您有申請過該工作,請問確定再次寄出職缺申請嗎?']; } $response->getBody()->write(json_encode($payload, JSON_UNESCAPED_UNICODE)); return $response->withHeader('Content-Type', 'application/json'); }); $app->post('/mail', function ($request, $response, $args) { $data = $request->getParsedBody(); send_mail($data); // return $request->withJson($data); // send_mail($data); $response->getBody()->write(json_encode($data, JSON_UNESCAPED_UNICODE)); return $response->withHeader('Content-Type', 'application/json'); }); function access_internal_page_validation() { $ip = $_SERVER['REMOTE_ADDR']; if ( $ip != '127.0.0.1' #and $ip!='198.13.46.35' /*web server self IP*/ and $ip != '192.168.112.1' /*web server self IP*/ #MUST delete because just use login... and $ip!='118.163.102.67' # Taipei Wifi #MUST delete because just use login... and $ip!='104.156.239.111' # VPN ) { die('You are not in allowed IP(' . $ip . ').'); } } /* no need $app->get('/resend_resume2job_manually/{jobid}/{id}', function(){ access_internal_page_validation(); $id = (int)$args['id']; $jobid = (int)$args['jobid']; #$sql = "SELECT * FROM application WHERE send_time>'2017-11-18 00:00:00'"; $sql = "SELECT * FROM application WHERE id=".$id; $stmt = $this->get(PDO::class)->query($sql); $apply_data = $stmt->fetch(); $job = __get_job(array('id'=>$jobid), $this->get(PDO::class),true); print_r($apply_data); print_r($job); $application_mapper = new ApplicationMapper($this->get(PDO::class)); $application_mapper->save($applications); $jobs_mapper = new JobsMapper($this->get(PDO::class)); $owner = $jobs_mapper->getOwnerbyJobId($jobid); print_r($owner); #send_apply_to_job_owner($apply_data, $owner, '(不懂/普通/中等/精通','(博士/碩士/學士/專科/中等/初等)', $job); }); */ $app->get(JOBS_WITHOUT_OWNERID_URL, function () { access_internal_page_validation(); $sql = "SELECT * FROM `jobs` WHERE `owener_id`=0 OR owener_id IS NULL"; $stmt = $this->get(PDO::class)->query($sql); echo '

Jobs without Owner_ID:

'; while ($row = $stmt->fetch()) { echo 'job_id=' . $row['id'] . ' ' . $row['job_title'] . ' --- 職缺截止於 ' . $row['date_expired'] . ''; echo '
'; } }); /* $app->get(RESEND_JOB_NOTIFY_EMAIL, function(){ if(!IS_DEVELOPER){die('x');} $job_id = isset($_GET['job_id']) ? ($_GET['job_id']+0) : ''; if(!$job_id){die('y');} send_job_added_or_edited_mail('_ADD_', $job_id, array(), $this->get(PDO::class)); }); */ require_once __DIR__ . '/routes-stats.php'; $app->get(WAIT4VERIFY_URL, function ($request, $response, $args){ $user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] + 0 : 0; $user = NULL; if ($user_id) { $user_mapper = new UserMapper($this->get(PDO::class)); $user = $user_mapper->getUserById($user_id); } if ($user and $user->getAuthority() == 1) { // nothing } else { access_internal_page_validation(); } $jobs_mapper = new JobsMapper($this->get(PDO::class)); $a = $jobs_mapper->getWait4VerifyJobs(true); $html_css = ''; $email_content = ''; $WAIT4VERIFY_COUNT = count($a); $email_content .= '

近日 ' . $WAIT4VERIFY_COUNT . ' 個等待上架 Jobs:

'; $tb = ''; $tb .= ''; $job_diff_notification_mapper = new JobDiffNotificationMapper($this->get(PDO::class)); foreach ($a as $v) { $last_modify = $job_diff_notification_mapper->getLastModifyDateTime($v['job_id']); $more = $v['job_description'] ? '另開分頁
' . $v['job_description'] . '
' : ' (無描述)另開分頁'; $tb .= ''; $tb .= ''; $tb .= ''; $tb .= ''; $tb .= ''; $tb .= ''; $tb .= ''; $tb .= ''; $tb .= ''; $tb .= ''; $tb .= ''; $tb .= ''; } $tb = $tb . '
' . implode('', array( 'ID', '新增', '修改', '截止', '分類', '類型', '職缺', '公司', '部門', '發佈者', )) . '
' . $v['job_id'] . '' . $v['date_post'] . '' . ($last_modify ? $last_modify : '未曾修改') . '' . $v['date_expired'] . '' . $v['category'] . '' . $v['job_type'] . '' . $v['job_title'] . '' . $more . '' . $v['company'] . '' . $v['company_depart'] . '' . ($v['name'] ? $v['name'] : 'No user??') . '
' . $v['email'] . '
' . ($v['phone'] ? 'phone: ' . $v['phone'] : '') . '
'; $html_js = ''; $html_js2 = << $('.toggle_detail').click(function(){ $(this).siblings('.detail').toggle(); }); var ifr=$('#ifr'); $('.link_open_ifr').click(function(){ var v = $(this); ifr.height(550).attr('src', v.attr('href')).css('margin-bottom',20); return false; }); EOF; if (isset($_GET['emailnotify']) and $WAIT4VERIFY_COUNT > 0) { send_mail_base( array('wei@sted.tw', 'dh@sted.tw'), '[JOBS.AIA] ' . date('Y-m-d') . ' 有 ' . $WAIT4VERIFY_COUNT . ' 個等待上架 Jobs', $email_content . $tb ); echo 'Sent email done'; } else { echo $html_css . $email_content . '' #. '

經驗1: 若貼文者不是原公司(如:獵人頭公司、非@公司信箱),可考慮審核不通過。

' . $tb . $html_js . $html_js2; } return $response; }); $app->get('/test_varchar_length', function () { $stmt = $this->get(PDO::class)->query('SELECT LENGTH("物件追蹤演算法 高級工程師 (Object Tracking Algorithm Sr. Developer)") AS len'); $r = $stmt->fetch(); print_r($r); $stmt = $this->get(PDO::class)->query("SHOW FIELDS FROM jobs where Field ='job_title'"); $r = $stmt->fetch(); print_r($r); $max_field_varchar_length = str_replace(array('varchar(', ')'), '', $r['Type']); echo $max_field_varchar_length; }); #$app->get('/test_key4changing_expired_day', function(){ #echo get_key4changing_expired_day(29,38); #}); $app->get('/test_logo_base64', function () { $jobs_mapper = new JobsMapper($this->get(PDO::class)); $job = $jobs_mapper->getJobById(116); $logo_abs_path = CORP_LOGO_ABS_PATH . $job[0]->getLogoPath(); echo '
'; echo get_img_base64($logo_abs_path); }); $app->get('/test_session', function () { #print_r($_SESSION); }); $app->get('/test_usersloginnum', function () { die('--'); $usersloginnum_mapper = new UsersLoginNumMapper($this->get(PDO::class)); $user_id = 163; $usersloginnum_mapper->save($user_id); echo $login_total_num = $usersloginnum_mapper->countUsersLoginNum($user_id); $user_mapper = new UserMapper($this->get(PDO::class)); $user_mapper->updateLoginTotalNum($user_id, $login_total_num); die('done'); }); $app->get('/test_jobhistory', function () { $jobhistory_mapper = new JobHistoryMapper($this->get(PDO::class)); $last_id = $jobhistory_mapper->save(15, 38, ADMIN_VERIFY_JOB); $jobhistory = $jobhistory_mapper->getJobHistoryById($last_id); echo '
'; print_r($jobhistory); }); $app->get('/test_var', function () { echo $_SERVER['SERVER_NAME'] . '##' . date('Y-m-d'); echo '---'; print_r($this->get(Session::class)->get('login')); echo '---'; echo ($this->get(Session::class)->get('login')['email']); echo '###' . ($this->get(Session::class)->get('user_id')); echo '---'; echo $this->get(Session::class)->get('verify'); }); $app->get('/test_resume_links_in_gmail', function () { $e = isset($_GET['e']) ? $_GET['e'] : ''; if (!$e) { die('err'); } $b = filter_var($e, FILTER_VALIDATE_EMAIL); if (!$b) { die('error'); } if (strpos($e, 'v') !== 0 and strpos($e, 'swchen11') !== 0) { die('error.'); } $n = 0; $s = ''; foreach (glob(__DIR__ . '/../public/application/*') as $v) { $fn = explode('/', $v); $fn = $fn[count($fn) - 1]; $fn = rawurlencode($fn); #echo$fn.'
'; $lnk = 'https://' . $_SERVER['SERVER_NAME'] . '/application/' . $fn; $s .= '' . $lnk . '
'; $n++; } echo '

' . $n . ' mail links already sent to ' . $e . ' , please check your email inbox.

'; send_mail_base($e, 'test resume links in gmail', $s); echo $s; }); $app->get('/test_1', function () { if (!IS_DEVELOPER) { die('x'); } $jobs_mapper = new JobsMapper($this->get(PDO::class)); $job = $jobs_mapper->getJobById(41)[0]; $TEST = $_GET['test']; echo '
';
        switch ($TEST) {
            case '1a': # pure update
                print_r($jobs_mapper->set_visible($job, true, false));
                print_r($jobs_mapper->set_verify($job, true, false));
                break;
            case '1b': # pure update
                print_r($jobs_mapper->set_visible($job, !true, false));
                print_r($jobs_mapper->set_verify($job, !true, false));
                break;
            case 2: # verify depends on trash
                print_r($jobs_mapper->set_trash($job));
                // var_dump($job);
                print_r($jobs_mapper->set_verify($job, false, true));
                break;
            case 3: # visible depends on verify
                print_r($jobs_mapper->set_verify($job, false, false));
                // var_dump($job);
                print_r($jobs_mapper->set_visible($job, false, true));
                break;
        }
    });
    $app->get('/test_setcookie', function ($request, $response, $args) {
        if (isset($_GET['step1'])) {
            echo '

set done

'; $after_30days = 30 * 24 * 60 * 60; setcookie('test2', 'test2value', time() + $after_30days); // $this->cookie->set( // 'test1' // , array('value' => 'test1value', // 'domain' => null, // 'hostonly' => null, // 'path' => null, // 'expires' => date('Y-m-d H:i:s', time() + 36000), // 'secure' => false, // 'httponly' => true) // ,'30 days' // ,'/' // ,$_SERVER['SERVER_NAME'] // ,false // ,true //); // var_dump($this->cookie->toHeaders()); } elseif (isset($_GET['step2'])) { echo '

get done

'; print_r($_COOKIE); var_dump($_COOKIE['test1']); // echo $app->getCookie('test1'); } else { echo '

do nothing

'; } }); $app->get('/test_logintoken', function () { if (!IS_DEVELOPER) { die('xx'); } echo get_logintoken(13, 123); }); $app->get('/test_recaptcha', function () { var_dump(IS_DEVELOPER); if (!IS_DEVELOPER) { die('xx'); } echo date('Y-m-d H:i:s'); echo '
CAPTCHA Image'; echo << [ Different Image ] EOF; }); $app->post('/test_recaptcha', function () { if (!IS_DEVELOPER) { die('xx'); } include_once __DIR__ . '/../lib/securimage/securimage.php'; $securimage = new Securimage(); if (!$securimage->check($_POST['captcha_code'])) { echo 'fail'; } else { echo 'yes'; } }); $app->get('/test_skill', function () { die(''); $mapper = new SkillMapper($this->get(PDO::class)); $test_skill_name = 'testskill'; $n = $mapper->save($test_skill_name); var_dump($n); echo '
'; $skill = $mapper->getSkillByName($test_skill_name); echo $skill->getId() . '--' . $skill->getSkillName() . '
'; try { var_dump($mapper->getSkillById(9999)); } catch (Exception $e) { echo 'not exists 9999
'; } try { var_dump($mapper->getSkillByName('s99999999')); } catch (Exception $e) { echo 'not exists s99999999
'; } }); $app->get('/test_job_apply', function () { die(''); $job_id = 35; $apply_data = array('job_id' => $job_id); $owner_data = array(); $english_opt = 'yyy'; $educations_opt = 'xxx'; $job = __get_job(array('id' => $job_id), $this->get(PDO::class), true); $jobhistory_mapper = new JobHistoryMapper($this->get(PDO::class)); send_apply_to_job_owner($jobhistory_mapper, $apply_data, $owner_data, $english_opt, $educations_opt, $job); }); $app->get('/test_sendmail', function () { echo $ip = $_SERVER['REMOTE_ADDR']; if (!in_array($ip, array('127.0.0.1', '140.109.16.164', '140.109.22.127'))) { die('xx'); } var_dump(IS_DEV); echo date('Y-m-d H:i:s'); echo $_SERVER['SERVER_NAME'] . '
'; echo __DIR__ . '
'; $email_to = isset($_GET['m']) ? $_GET['m'] : ''; if (!$email_to) { die('
yy'); } $email_to2 = isset($_GET['m2']) ? $_GET['m2'] : ''; $email_subject = '測試主旨'; $email_content = '內容
內容粗體'; $result = send_mail_base( array($email_to . '@gmail.com', $email_to2 . '@gmail.com') #$email_to.'@gmail.com' , $email_subject, $email_content ); echo '
'; var_dump($result); }); $app->get('/test_sendmail_by_proxy', function () { $ip = $_SERVER['REMOTE_ADDR']; # if($ip!='127.0.0.1' && $ip!='180.217.138.9'){die('xx');} # Our new data # Create a connection if (1) { $url = 'http://smartdonor.tw/send_email_proxy/send_it.php'; $data = array( 'key' => 'asdewioTxzvlk', 'subject' => '[主旨]中文', 'content' => 'i中文xxxeee', 'email_from' => 'jobs@aiacademy.tw', 'email_from_name' => '台灣DataJobs', 'email_to' => 'vansind.ata@gmail.com`van.sindata@gmail.com', ); } else { $url = 'http://smartdonor.tw/send_email_proxy/test_post_it.php'; $data = array('election' => 1, 'name' => 'Test'); } $ch = curl_init($url); # Form data string $postString = http_build_query($data, '', '&'); # Setting our options curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postString); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # Get the response $response = curl_exec($ch); curl_close($ch); var_dump($response); }); $app->post('/research_sinica_system_notify', function () { $ip = $_SERVER['REMOTE_ADDR']; # expect 140.109.8.77 http://research.sinica.edu.tw/cront if ($ip !== '140.109.8.77') { die('xx'); } send_mail_base($_POST['gmail_account_prefix'] . 'data@gmail.com', 'research 硬碟快滿了', $_POST['content']); echo 'Done!'; print_r($_POST); }); function generateRandomString($length = 5) { return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length); } function encoding($msg) { return mb_encode_mimeheader($msg, 'UTF-8', 'B', "\r\n", strlen('Subject: ')); } function send_pwd_mail($email, $pwd_token) { $email_content = '
您好,' . $email . '!
欲變更密碼請點擊下方連結:

我要變更密碼
若您未曾申請變更密碼,請直接捨棄此封郵件。
在您點擊上方[我要變更密碼]連結以前,
您的密碼都不會更改,敬請安心。
******************

本徵才服務由台灣人工智慧學校人才媒合平台提供。如有任何問題或建議,歡迎隨時來信與我們聯絡: jobs@aiacademy.tw
'; $bool = send_mail_base($email, '[台灣人工智慧學校人才媒合平台] 重設密碼', $email_content, 'jobs@aiacademy.tw', '台灣人工智慧學校人才媒合平台', array()); if (!$bool) { return array('status' => 'error', 'msg' => 'send email wrong 2.' /*$mail->ErrorInfo*/); } else { return array('status' => 'success', 'msg' => '您將在幾分鐘後收到一封電子郵件,內有重新設定密碼的步驟說明。'); } /* mb_internal_encoding('UTF-8'); $mail = new PHPMailer; $mail->CharSet = 'utf-8'; ini_set('default_charset', 'UTF-8'); $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'mail.iis.sinica.edu.tw'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'joanne3634'; // SMTP username $mail->Password = '@Lulu@0525@20171110@'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted $mail->IsHTML(true); // $mail->addReplyTo( $user_data['email'], $user_data['name'] ); $mail->From = 'no-reply@datasci.tw'; $mail->FromName = '資料科學人才媒合平台'; $mail->addAddress($email); // Add a recipient $mail->addBCC('b00902007@ntu.edu.tw', encoding('CC信箱')); // Add a recipient $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->isHTML(true); // Set email format to HTML $mail->Subject = encoding('[資料科學人才媒合平台] 重設密碼'); $mail->Body = '
您好,'.$email.'!
欲變更密碼請點擊下方連結:

我要變更密碼
若您未曾申請變更密碼,請直接捨棄此封郵件。
在您點擊上方[我要變更密碼]連結以前,
您的密碼都不會更改,敬請安心。
******************

本徵才服務由台灣資料科學協會提供。如有任何問題或建議,歡迎隨時來信與我們聯絡: secretary@datasci.tw
'; if(!$mail->send()) { return array('status'=>'error','msg'=> $mail->ErrorInfo) ; // return false; } else { return array('status'=>'success','msg'=> '您將在幾分鐘後收到一封電子郵件,內有重新設定密碼的步驟說明。'); // return true; } */ } function send_mail($user_data) { $email_content = '
您好,' . $user_data['name'] . '!
歡迎您登錄「台灣人工智慧學校人才媒合平台」。

您使用 ' . $user_data['email'] . ' 註冊,
若確認無誤請點擊下方連結進行會員認證。

我要認證
******************

本徵才服務由台灣人工智慧學校人才媒合平台提供。如有任何問題或建議,歡迎隨時來信與我們聯絡: jobs@aiacademy.tw
'; $bool = send_mail_base($user_data['email'], '[台灣人工智慧學校人才媒合平台] 請確認您的電子郵件帳號', $email_content, 'no-reply@aiacademy.tw', '台灣人工智慧學校人才媒合平台', array()); if (!$bool) { return array('status' => 'error', 'msg' => 'send email wrong' /*$mail->ErrorInfo*/); } else { return array('status' => 'success', 'msg' => '確認信件將在幾分鐘後送至您的 Email 信箱'); } /* mb_internal_encoding('UTF-8'); $mail = new PHPMailer; $mail->CharSet = 'utf-8'; ini_set('default_charset', 'UTF-8'); $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'mail.iis.sinica.edu.tw'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'joanne3634'; // SMTP username $mail->Password = '@Lulu@0525@20171110@'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted $mail->IsHTML(true); // $mail->addReplyTo( $user_data['email'], $user_data['name'] ); $mail->From = 'no-reply@datasci.tw'; $mail->FromName = '資料科學人才媒合平台'; $mail->addAddress($user_data['email'], $user_data['name']); // Add a recipient $mail->addBCC('b00902007@ntu.edu.tw', encoding('CC信箱')); // Add a recipient $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->isHTML(true); // Set email format to HTML $mail->Subject = encoding('[資料科學人才媒合平台] 請確認您的電子郵件帳號'); $mail->Body = '
您好,'.$user_data['name'].'!
歡迎您登錄「資料科學人才媒合平台」。

您使用 '.$user_data['email'].' 註冊,
若確認無誤請點擊下方連結進行會員認證。

我要認證
******************

本徵才服務由台灣資料科學協會提供。如有任何問題或建議,歡迎隨時來信與我們聯絡: secretary@datasci.tw
'; if(!$mail->send()) { return array('status'=>'error','msg'=> $mail->ErrorInfo) ; // return false; } else { return array('status'=>'success','msg'=> '確認信件將在幾分鐘後送至您的 Email 信箱'); // return true; } */ } function send_apply_to_job_owner($jobhistory_mapper, $apply_data, $owner_data, $english_opt, $educations_opt, $job, $official_skills = null) { $job_id = $apply_data['job_id']; $apply_user_id = $apply_data['apply_user_id']; $subject = '[台灣人工智慧學校人才媒合平台] 投遞履歷 至 ' . $job->getCompany() . ' / ' . $job->getJobTitle(); //$file_link = RESUME_URI_PREFIX.rawurlencode($apply_data['cv_path']); //if($job_id==112 and $apply_user_id==163){ $file_link = 'https://' . $_SERVER['SERVER_NAME'] . '/resume_file/' . $job_id . '/' . $apply_user_id; //} $file_link = '' . $file_link . ''; # $str_skills = ''; $ary_other_skills = preg_split("/(\r\n|\n|\r)/", $apply_data['other_skill']); foreach ($ary_other_skills as $k => $v) { if (!trim($v)) { unset($ary_other_skills[$k]); } } if ($official_skills) { foreach ($apply_data['skill'] as $idx => $skill_id) { $str_skills .= $official_skills[$skill_id]; if ($idx < count($apply_data['skill']) - 1) { $str_skills .= ', '; } } } if ($ary_other_skills) { $str_skills .= ', ' . implode(', ', $ary_other_skills); } if ($apply_data['cv_path']) { $cv_file_and_data_wording = '履歷檔案與資料'; $cv_file_text = '履歷檔案: ' . $file_link . '

'; } else { $cv_file_and_data_wording = '資料'; $cv_file_text = ''; } $email_content = '
您好,' . $apply_data['name'] . ' 透過 台灣人工智慧學校人才媒合平台 向' . $job->getCompany() . ' / ' . $job->getJobTitle() . '投遞履歷,以下是他/她的' . $cv_file_and_data_wording . '。

' . $cv_file_text . ' 姓名:' . $apply_data['name'] . '
性別:' . display_text('GENDER', $apply_data['gender']) . '
信箱:' . $apply_data['email'] . '
第2信箱:' . $apply_data['second_email'] . '
手機:' . $apply_data['second_phone'] . '
電話:' . $apply_data['phone'] . '
出生年份:' . $apply_data['age_year'] . '
最高學歷:' . $apply_data['highest_education_id'] . ' ' . $educations_opt . '
畢業年份:' . $apply_data['graduate_year'] . '
畢業學校:' . $apply_data['gradute_school'] . '
畢業科系:' . $apply_data['gradute_master'] . '
目前或最後一間公司名稱:' . $apply_data['latest_company'] . '
目前或最後一份工作職稱:' . $apply_data['latest_job_title'] . '
英文能力:' . $apply_data['english_ability_id'] . ' ' . $english_opt . '
專業技能:' . $str_skills . '
處理資料的相關能力經驗:
' . $apply_data['experience'] . '
其他能力、經驗:
' . $apply_data['other'] . '
******************

本徵才服務由台灣人工智慧學校人才媒合平台提供。如有任何問題或建議,歡迎隨時來信與我們聯絡: jobs@aiacademy.tw
'; $ary_emails = array($owner_data['email']); $more_notify_emails = $job->getMoreNotifyEmails(); if ($more_notify_emails) { $a = explode(',', $more_notify_emails); if ($a) { $ary_emails = array_merge($ary_emails, $a); } } $bool = send_mail_base($ary_emails, $subject, $email_content, 'no-reply@aiacademy.tw', '台灣人工智慧學校人才媒合平台', array()); $meta = array('sendmail_result' => $bool, 'ary_emails' => $ary_emails); if (!$bool) { $meta = array_merge($meta, array('sendmail_type' => 'FAIL')); $jobhistory_mapper->save( $job->getId(), $apply_user_id, USER_APPLY_JOB, $meta ); return array('status' => 'error', 'msg' => 'send mail wrong 777' /*$mail->ErrorInfo*/); } else { $meta = array_merge($meta, array('sendmail_type' => 'SUCC')); $jobhistory_mapper->save( $job->getId(), $apply_user_id, USER_APPLY_JOB, $meta ); return array('status' => 'success', 'msg' => '確認信件將在幾分鐘後送至您的 Email 信箱'); } } function square_thumbnail_with_proportion($src_file, $destination_file, $square_dimensions, $jpeg_quality = 90) { // Step one: Rezise with proportion the src_file *** I found this in many places. $src_img = imagecreatefromstring(file_get_contents($src_file)); $image = imagecreatetruecolor(imagesx($src_img), imagesy($src_img)); $white = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $white); imagecopy($image, $src_img, 0, 0, 0, 0, imagesx($image), imagesy($image)); // $src_img=imagecreatefromjpeg($src_file); $old_x = imageSX($image); $old_y = imageSY($image); $ratio1 = $old_x / $square_dimensions; $ratio2 = $old_y / $square_dimensions; if ($ratio1 > $ratio2) { $thumb_w = $square_dimensions; $thumb_h = $old_y / $ratio1; } else { $thumb_h = $square_dimensions; $thumb_w = $old_x / $ratio2; } // we create a new image with the new dimmensions $smaller_image_with_proportions = ImageCreateTrueColor($thumb_w, $thumb_h); // resize the big image to the new created one imagecopyresampled($smaller_image_with_proportions, $image, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); // *** End of Step one *** // Step Two (this is new): "Copy and Paste" the $smaller_image_with_proportions in the center of a white image of the desired square dimensions // Create image of $square_dimensions x $square_dimensions in white color (white background) $final_image = imagecreatetruecolor($square_dimensions, $square_dimensions); $bg = imagecolorallocate($final_image, 255, 255, 255); // imagefilledrectangle($final_image,0,0,$square_dimensions,$square_dimensions,$bg); imagefill($final_image, 0, 0, $bg); // need to center the small image in the squared new white image if ($thumb_w > $thumb_h) { // more width than height we have to center height $dst_x = 0; $dst_y = ($square_dimensions - $thumb_h) / 2; } elseif ($thumb_h > $thumb_w) { // more height than width we have to center width $dst_x = ($square_dimensions - $thumb_w) / 2; $dst_y = 0; } else { $dst_x = 0; $dst_y = 0; } $src_x = 0; // we copy the src image complete $src_y = 0; // we copy the src image complete $src_w = $thumb_w; // we copy the src image complete $src_h = $thumb_h; // we copy the src image complete $pct = 100; // 100% over the white color ... here you can use transparency. 100 is no transparency. imagecopymerge($final_image, $smaller_image_with_proportions, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct); imagejpeg($final_image, $destination_file, $jpeg_quality); // destroy aux images (free memory) imagedestroy($image); imagedestroy($smaller_image_with_proportions); imagedestroy($final_image); } require_once __DIR__ . '/routes-internalapi.php'; require_once __DIR__ . '/routes-other.php'; $app->map(['GET', 'POST', 'PUT', 'DELETE'], '/{routes:.+}', function ($request, $response) { return $response ->withHeader('Location', "/") ->withStatus(301); }); } ?>