<?php

require_once "../initialise_files.php";
include_once "sessioninc.php";
$smarty->assign('action', $_GET['action']);
$smarty->assign('id', (int) $_GET['id']);
if (isset($_GET['action']) && $_GET['action'] == "edit" && isset($_GET['id'])) {
    $id = (int) $_GET['id'];
    $jt_name = JobStatus::find_by_id($id);
    $jt_name2 = $jt_name->status_name;
    $smarty->assign('jt_name2', $jt_name2);
    $smarty->assign('is_active', $jt_name->is_active);
    if (isset($_GET['bt_update'])) {
        $job_status = new JobStatus();
        $job_status->id = (int) $_GET['id'];
        $job_status->status_name = $_GET['txt_name'];
        $job_status->is_active = $_GET['txt_active'];
        $job_status->var_name = $jt_name->mod_write_check($_GET['txt_name'], $jt_name->var_name);
        if ($job_status->save()) {
            $session->message("Job Status updated ");
            redirect_to($_SERVER['PHP_SELF'] . "?#" . $_GET['id']);
            die;
        } else {
            $message = join("<br />", $job_status->errors);
        }
    }
}
if (isset($_GET['action']) && $_GET['action'] == "delete" && isset($_GET['id'])) {
    $job_status = new JobStatus();
    $job_status->id = (int) $_GET['id'];
    if ($job_status->delete()) {
//what are you looking for
$ljt = $cv_details->look_job_title;
$smarty->assign('ljt', $ljt);
$ljt2 = $cv_details->look_job_title2;
$smarty->assign('ljt2', $ljt2);
$sql = " SELECT * FROM " . TBL_CV_CAT . " WHERE cv_id=" . $id;
$cv_cat = $db->query($sql);
$cv_cat_array = array();
while ($row = $db->fetch_object($cv_cat)) {
    $categories = Category::find_by_id($row->category_id);
    $cv_cat_array[] = $categories->cat_name;
}
$smarty->assign('li', join("<br />", $cv_cat_array));
//job states
$js = empty($cv_details->look_job_status) ? 0 : $cv_details->look_job_status;
$job_status = JobStatus::find_by_id($js);
$ljs = $job_status ? $job_status->status_name : format_lang('none');
$smarty->assign('ljs', $ljs);
//job type
$job_t = empty($cv_details->look_job_type) ? 0 : $cv_details->look_job_type;
$job_type_arr = JobType::find_by_id($job_t);
//print_r( $job_type_arr);
$job_types = $job_type_arr ? $job_type_arr->type_name : format_lang('none');
$smarty->assign('job_type', $job_types);
//where do you wont to work
//country
$country_arry = Country::find_by_code($cv_details->country);
$country_var_name = $country_arry->var_name;
$country_name = $country_arry->name;
$smarty->assign('country', $country_name);
//states
$sql = $select . $from . $where . $group_by . $order . $limit;
//echo $sql;
$result = $db->query($sql);
$num_rows = $db->num_rows($result);
if ($num_rows > 0) {
    $manage_list = array();
    $i = 1;
    while ($rows = $db->fetch_object($result)) {
        $employee = Employee::find_by_id($rows->fk_employee_id);
        $manage_list[$i]['id'] = $rows->id;
        $manage_list[$i]['employee_name'] = $employee->full_name();
        $manage_list[$i]['employee_id'] = $rows->fk_employee_id;
        $manage_list[$i]['cv_title'] = $rows->cv_title;
        $manage_list[$i]['look_job_title'] = $rows->look_job_title;
        $manage_list[$i]['look_job_title2'] = $rows->look_job_title2;
        $status = JobStatus::find_by_id($rows->look_job_status);
        $status_name = $status->status_name;
        $manage_list[$i]['look_job_status'] = $status_name;
        $manage_list[$i]['recent_job_title'] = $rows->recent_job_title;
        //$manage_list[$i]['city']=  $rows->city;
        $manage_list[$i]['modified_at'] = strftime(DATE_FORMAT, strtotime($rows->modified_at));
        //locations
        //country
        $country_arry = Country::find_by_code($rows->country);
        $country_var_name = $country_arry->var_name;
        $country_name = $country_arry->name;
        //states
        $state = StateProvince::find_by_code($rows->country, $rows->state_province);
        $state_name = empty($state) ? $rows->state_province : $state->name;
        //county
        $county = County::find_by_code($rows->country, $rows->state_province, $rows->county);