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 .= '| ' . implode(' | ', array(
'ID',
'新增',
'修改',
'截止',
'分類',
'類型',
'職缺',
'公司',
'部門',
'發佈者',
)) . ' |
';
$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 .= '| ' . $v['job_id'] . ' | ';
$tb .= '' . $v['date_post'] . ' | ';
$tb .= '' . ($last_modify ? $last_modify : '未曾修改') . ' | ';
$tb .= '' . $v['date_expired'] . ' | ';
$tb .= '' . $v['category'] . ' | ';
$tb .= '' . $v['job_type'] . ' | ';
$tb .= '' . $v['job_title'] . '' . $more . ' | ';
$tb .= '' . $v['company'] . ' | ';
$tb .= '' . $v['company_depart'] . ' | ';
$tb .= '' . ($v['name'] ? $v['name'] : 'No user??') . ' ' . $v['email'] . ' '
. ($v['phone']
? 'phone: ' . $v['phone'] : '')
. ' | ';
$tb .= '
';
}
$tb = $tb . '
';
$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 '