<?php
$optres['css'][] = $module_css_path . "amodules/jobs_ext/css/job_details.css";
$job_jobs_id = isset($jid) ? intval($jid) : 0;

$all_commitment = array(
    "full-time" 	=> "Full Time",
    "part-time"		=> "Part Time",
    "contract"		=> "Contract",
    "temp"			=> "Temporary",
    "internship"	=> "Internship",
    "other"			=> "Other"
);

$job_categories = array();
$queryjob_cat = "SELECT * FROM  job_cat WHERE active='yes'";
$resultjob_cat = @mysql_query ($queryjob_cat);
if($resultjob_cat && mysql_num_rows($resultjob_cat) > 0) {
    while ($row = mysql_fetch_assoc($resultjob_cat)) {
        $job_categories[$row['job_cat_id']] = stripslashes($row['title_en']);
    }
}

if(isset($job_jobs_id) && intval($job_jobs_id) > 0) {
    $query_job_job = "SELECT * FROM job_jobs WHERE job_jobs_id='$job_jobs_id' AND active='yes' AND job_status='1' ";
    if($jdl > 0) {
        $daystolive = date("Y-m-d 00:00:00", strtotime("-$jdl days", time()));
        $query_job_job .= " AND updated_at>='$daystolive' ";
    }
    $result_job_job = mysql_query($query_job_job) or die(mysql_error());
    if ($result_job_job && mysql_num_rows($result_job_job) > 0) {



        @mysql_query("UPDATE job_jobs SET clicks=clicks+1 WHERE job_jobs_id='$job_jobs_id';");// or die(mysql_error());
        $line_job_jobs = mysql_fetch_assoc($result_job_job);
        /*for ($i = 0; $i < mysql_num_fields($result_job_job); $i++) {
            if (trim($line_job_jobs [mysql_field_name($result_job_job, $i)]) == "") {
                $line_job_jobs [mysql_field_name($result_job_job, $i)] = "N/A";
            }

        }*/




        foreach ($line_job_jobs as $fld => $val) {
            $line_job_jobs[$fld] = trim(stripslashes($line_job_jobs[$fld]));
        }

        $company = urlencode($line_job_jobs['CompanyName']);
        $rss_feed_url = 'https://' . $_SERVER['HTTP_HOST'] . '/rss/feed/jobs?company=' . $company . '&count=20';
        $link_alternate[] = '<link rel="alternate" type="application/atom+xml" title="Latest Jobs From '.(str_replace('+', ' ', $company)).'" href="'.$rss_feed_url.'" />';


        $canonical_link = $protocol . $ultra_domainname . "/jobs/job/$job_jobs_id/" . url_slug(stripslashes($line_job_jobs["JobTitle"]));

        // Set breadcrumbs
        $breadcrumbs [] = array(
            'link' => 'jobs/',
            'title' => "Find Cyprus Jobs"
        );

        $breadcrumbs [] = array(
            'link' => '',
            'title' => "ID:$job_jobs_id"
        );

        $webpage_title_en = stripslashes($line_job_jobs["JobTitle"]) . ' - ' . $webpage_title_en;

        $j_conditions = ($line_job_jobs['Conditions'] != "other") ? $all_commitment[$line_job_jobs['Conditions']] : '';
        $j_categories = [];

        $job_categs = [];
        $qc = "SELECT * FROM job_categs WHERE job_id='$job_jobs_id' ORDER BY id ASC;";
        $rc = @mysql_query($qc);
        if($rc && mysql_num_rows($rc) > 0) {
            while($rowrc = mysql_fetch_assoc($rc)) {
                if ($line_job_jobs['job_cat_id'] > 0 && $line_job_jobs['job_cat_id'] == intval($rowrc['categ_id'])) {

                    array_unshift($job_categs, [
                        'title' => $job_categories[intval($rowrc['categ_id'])],
                        'categ_id' => intval($rowrc['categ_id'])
                    ]);
                }
                else {
                    $job_categs [] = [
                        'title' => $job_categories[intval($rowrc['categ_id'])],
                        'categ_id' => intval($rowrc['categ_id'])
                    ];
                }
            }
        }

        //echo '<pre>', var_export($job_categs, true), '</pre>';

        //($job_categories[$line_job_jobs['job_cat_id']] != "Other") ? $job_categories[$line_job_jobs['job_cat_id']] : '';

        if ($line_job_jobs['Conditions'] != "other") {
            $job_meta_desc = $all_commitment[$line_job_jobs['Conditions']] . ' ' . $job_categories[$line_job_jobs['job_cat_id']] . ' job in ' . str_replace(';', ', ', $line_job_jobs['Location']) . ' posted on ' . date("F d, Y", strtotime($line_job_jobs['added_on'])) . '. ' . $line_job_jobs['CompanyName'] . ' is looking for ' . $line_job_jobs['JobTitle'];
        } else {
            $job_meta_desc = $job_categories[$line_job_jobs['job_cat_id']] . ' job in ' . str_replace(';', ', ', $line_job_jobs['Location']) . ' posted on ' . date("F d, Y", strtotime($line_job_jobs['added_on'])) . '. ' . $line_job_jobs['CompanyName'] . ' is looking for ' . $line_job_jobs['JobTitle'];
        }

        $meta['description'] = $job_meta_desc;
        ?>

        <article class="article cyprus">
            <header>
                <h1><?php echo stripslashes(trim($line_job_jobs["JobTitle"])); ?></h1>
                <!--[/SocialShareButtons/]-->
            </header>
            <div class="article-body cyprus">
                <?php
                if(isset($_REQUEST['adsense_debug'])) {
                    echo '$def_ad_id = ' . var_export($def_ad_id, true);
                    echo '$gads_show = ' . var_export($gads_show, true);
                    echo '<pre>$gads = ' . var_export($gads, true), '</pre>';
                }
                // Show Adsense
                if($gads_show && $def_ads == "yes" && $def_ad_id != "") {
                    $adsense_container_class = "no-margin";
                    echo '<div style="margin-top: 9px;margin-bottom: 15px;">';
                    include(dirname(__FILE__) . "/../gads_content/gads_content_default.php");
                    echo '</div>';
                    unset($adsense_container_class);
                }
                ?>
                <div class="container-fluid">

                    <div class="job-details" itemscope itemtype="http://schema.org/JobPosting">

                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <b class="text-danger">Warning</b>
                            </div>
                            <div class="panel-body">
                                <p><span  class="text-danger">CyprusNet is not responsible or liable for any scams, frauds, misleading job offerings or false resume information within Cyprus Jobs free service. We strongly recommend that users never reveal private information such as credit cards, bank accounts, insurance numbers, passports, ID numbers or give away any money and so forth.</span></p>
                                <p>
                                    <span  class="text-danger">If you've been targeted by a job scam, report to:</span>
                                    <a href="http://www.police.gov.cy/police/police.nsf/f5d3aa79835d246ec22578b0003515a8/5ef7a1c0a814eb74c22578a900271b1c?OpenDocument" rel="nofollow" target="_blank">Cyprus Crime Combating Department</a>
                                </p>
                            </div>
                        </div>

                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <b>Position Details</b>
                            </div>
                            <div class="panel-body no-padding">
                                <div class="container-fluid">
                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Reference No.</div>
                                        <div class="col-sm-7">
                                            <span
                                                class="text-bold"><?php echo $line_job_jobs["job_jobs_id"]; ?></span>
                                        </div>
                                    </div>
                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Title</div>
                                        <div class="col-sm-7">
                                            <span itemprop="title" class="text-bold text-primary"><?= stripslashes($line_job_jobs["JobTitle"]); ?></span>
                                        </div>
                                    </div>

                                    <?php
                                    $range = false;
                                    $base_salary = 0;
                                    $upto = false;
                                    $salary_min = intval($line_job_jobs['salary_min']);
                                    $salary_max = intval($line_job_jobs['salary_max']);

                                    if($salary_min > 0 && $salary_max > 0) $range = true;

                                    if(!$range) {
                                        $base_salary = $salary_max > $salary_min ? $salary_max : $salary_min;
                                        if($salary_min == 0) $upto = true;
                                    }

                                    if(!$range && $base_salary > 0) {
                                        ?>
                                        <div class="row detail-row">
                                            <div class="col-sm-3 text-bold">Salary</div>
                                            <div class="col-sm-7">
                                                <span class="text-bold text-primary"><?php if($upto) echo '<small class="text-muted">Up to</small> '; ?><meta itemprop="salaryCurrency" content="EUR"/> &euro; <span itemprop="baseSalary"><?= $base_salary; ?></span></span>
                                            </div>
                                        </div>
                                        <?php
                                    }

                                    if($range) {
                                        ?>
                                        <div class="row detail-row">
                                            <div class="col-sm-3 text-bold">Salary</div>
                                            <div class="col-sm-7">
                                                <span class="text-bold text-primary">
                                                    <span itemprop="baseSalary" itemscope="" itemtype="http://schema.org/PriceSpecification">
                                                        <meta itemprop="priceCurrency" content="EUR"/>
                                                        &euro; <span itemprop="minPrice"><?= ($salary_min); ?></span> -
                                                        &euro; <span itemprop="maxPrice"><?= ($salary_max); ?></span>
                                                    </span>
                                                </span>
                                            </div>
                                        </div>
                                        <?php
                                    }

                                    ?>


                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Category</div>
                                        <div class="col-sm-7">
                                            <div itemprop="industry" class="">
                                                <?php
                                                foreach($job_categs as $categ_data) {
                                                    $jcateg_url = "jobs/category/{$categ_data['categ_id']}/" . url_slug($categ_data['title']);
                                                    ?>
                                                    <a href="<?=$jcateg_url?>"><?= $categ_data['title']; ?></a><br>
                                                    <?php
                                                }
                                                ?>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Employment Type</div>
                                        <div class="col-sm-7">
                                            <span itemprop="employmentType"
                                                  class=""><?php echo $all_commitment[$line_job_jobs["Conditions"]]; ?></span>
                                        </div>
                                    </div>
                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Available Positions</div>
                                        <div class="col-sm-7">
                                            <span
                                                class=""><?php echo intval($line_job_jobs["NumberOfPersons"]) > 0 ? intval($line_job_jobs["NumberOfPersons"]) : 1 ; ?></span>
                                        </div>
                                    </div>
                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Location(s):</div>
                                        <div class="col-sm-7">
                                            <span
                                                class=""><?php echo preg_replace("/;/", ", ", $line_job_jobs["Location"]); ?></span>
                                        </div>
                                    </div>
                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Posted On:</div>
                                        <div class="col-sm-7">
                                            <meta itemprop="datePosted" content="<?php echo date("c", strtotime($line_job_jobs['updated_at'])); ?>"/>
                                            <span class=""><?php echo date("d/m/Y", strtotime($line_job_jobs['updated_at'])); ?></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <b>Contact Details</b>
                            </div>
                            <div class="panel-body no-padding">
                                <div class="container-fluid">
                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Company</div>
                                        <div class="col-sm-7" itemprop="hiringOrganization" itemscope itemtype="http://schema.org/Organization">
                                            <span itemprop="name"><?= $line_job_jobs['CompanyName']; ?></span>
                                        </div>
                                    </div>
                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Contact Person</div>
                                        <div class="col-sm-7">
                                            <span><?= $line_job_jobs['ContactPerson']; ?></span>
                                        </div>
                                    </div>


                                    <div class="row detail-row" itemprop="jobLocation" itemscope
                                         itemtype="http://schema.org/Place">
                                        <div class="col-sm-3 text-bold">Address</div>
                                        <div class="col-sm-7" itemprop="address" itemscope
                                             itemtype="http://schema.org/PostalAddress">
                                            <span><?= nl2br($line_job_jobs['Address']); ?></span>
                                            <br><span itemprop="addressLocality">
                                                <?php
                                                switch ($line_job_jobs['Town']) {
                                                    case "other":
                                                        echo $line_job_jobs['OtherTown'];
                                                        break;
                                                    default:
                                                        echo $line_job_jobs['Town'];
                                                        break;
                                                }
                                                ?>
                                            </span>
                                        </div>
                                    </div>
                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Phones</div>
                                        <div class="col-sm-7">
                                            <?php
                                            $phones = array();
                                            if (strlen(trim($line_job_jobs["Phone"])) >= 8) {
                                                $phones [] = '<i class="fa fa-phone"></i> ' . trim($line_job_jobs["Phone"]);
                                            }
                                            if (strlen(trim($line_job_jobs["Mobile"])) >= 8) {
                                                $phones [] = '<i class="fa fa-phone"></i> ' . trim($line_job_jobs["Mobile"]);
                                            }
                                            ?>
                                            <span><?= implode(", ", $phones); ?></span>
                                        </div>
                                    </div>

                                    <?php
                                    if (strlen(trim($line_job_jobs["Fax"])) >= 8) {
                                        ?>
                                        <div class="row detail-row">
                                            <div class="col-sm-3 text-bold">Fax</div>
                                            <div class="col-sm-7">
                                                <span><?= trim($line_job_jobs["Fax"]); ?></span>
                                            </div>
                                        </div>
                                        <?php
                                    }

                                    if (strlen(trim($line_job_jobs["EmailAdd"])) > 3) {
                                        ?>
                                        <div class="row detail-row">
                                            <div class="col-sm-3 text-bold">Email</div>
                                            <div class="col-sm-7">
                                                <span><?= trim($line_job_jobs["EmailAdd"]); ?></span>
                                            </div>
                                        </div>
                                        <?php
                                    }
                                    ?>
                                </div>
                            </div>
                        </div>

                        <?php
                        // Show Adsense
                        if($gads_show && $def_ads == "yes" && $def_ad_id != "") {
                            $adsense_container_class = "no-margin";
                            echo '<div style="margin-top: 9px;margin-bottom: 15px;">';
                            include(dirname(__FILE__) . "/../gads_content/gads_content_default.php");
                            echo '</div>';
                            unset($adsense_container_class);
                        }
                        ?>


                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <b>Job Description</b>
                            </div>
                            <div class="panel-body" itemprop="description">
                                <?php
                                if ($line_job_jobs['jversion'] == 0) {
                                    echo nl2br(stripslashes($line_job_jobs["JobDescription"]));
                                } else {
                                    echo stripslashes($line_job_jobs["JobDescription"]);
                                }

                                ?>
                            </div>
                        </div>

                        <?php
                        if (trim($line_job_jobs["Qualifications"]) != "") {
                            ?>
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <b>Required Qualifications</b>
                                </div>
                                <div class="panel-body" itemprop="experienceRequirements">
                                    <?php
                                    if ($line_job_jobs['jversion'] == 0) {
                                        echo nl2br(stripslashes($line_job_jobs["Qualifications"]));
                                    } else {
                                        echo stripslashes($line_job_jobs["Qualifications"]);
                                    }
                                    ?>
                                </div>
                            </div>
                            <?php
                        }

                        if (trim($line_job_jobs["Other"]) != "") {
                            ?>
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <b>Other Requirements</b>
                                </div>
                                <div class="panel-body" itemprop="qualifications">
                                    <?php

                                    if ($line_job_jobs['jversion'] == 0) {
                                        echo nl2br(stripslashes($line_job_jobs["Other"]));
                                    } else {
                                        echo stripslashes($line_job_jobs["Other"]);
                                    }
                                    ?>

                                </div>
                            </div>
                            <?php
                        }
                        ?>
                    </div>
                </div>
            </div>
        </article>
        <?php
    }
    else {
        $send404 = true;

        ?>
        <div class="alert alert-danger">
            <p class="text-white">
                <b><i class="fa fa-warning"></i> This job is no longer available.</b>
            </p>
        </div>
        <?php
        require_once(dirname(__FILE__) . "/../404/404.php");
    }
}
else{
    echo 'Please select a Job first!!';
}
?>
