<?php
function format_phone($phone)
{
    $phone = preg_replace("/[^0-9]/", "", $phone);

    if(strlen($phone) == 8)
        return preg_replace("/([0-9]{2})([0-9]{3})([0-9]{3})/", "$1-$2-$3", $phone);
    elseif(strlen($phone) == 11)
        return preg_replace("/([0-9]{3})([0-9]{2})([0-9]{3})([0-9]{3})/", "(+$1) $2-$3-$4", $phone);
    elseif(strlen($phone) == 13 && substr($phone, 0, 2) == "00")
        return preg_replace("/([0-9]{2})([0-9]{3})([0-9]{2})([0-9]{3})([0-9]{3})/", "(+$2) $3-$4-$5", $phone);
    else
        return $phone;
}

$optres['css'][] = $module_css_path . "amodules/jobs_ext/css/resume_details.css";
$job_cv_id = isset($rid) ? intval($rid) : 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_cv_id) && intval($job_cv_id) > 0) {
    $query_resume = "SELECT * FROM job_cvs WHERE job_cv_id='$job_cv_id' AND active='yes' AND resume_status='1' ";
    if($rdl > 0) {
        $daystolive = date("Y-m-d 00:00:00", strtotime("-$rdl days", time()));
        $query_resume .= " AND updated_at>='$daystolive' ";
    }
    $result_resume = mysql_query($query_resume) or die(mysql_error());
    if ($result_resume && mysql_num_rows($result_resume) > 0) {



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

        }*/



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

        $canonical_link = $protocol . $ultra_domainname . "/resumes/resume/$job_cv_id/" . url_slug(stripslashes($line_resumes["FirstName"] . ' ' . $line_resumes["LastName"]));

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

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

        $webpage_title_en = stripslashes($line_resumes["FirstName"] . ' ' . $line_resumes["LastName"]) . ' Resume - ' . $webpage_title_en;

        $j_category = ($job_categories[$line_resumes['job_cat_id']] != "Other") ? $job_categories[$line_resumes['job_cat_id']] : '';



        $meta['description'] = stripslashes($line_resumes["FirstName"] . ' ' . $line_resumes["LastName"]) . ' is looking for a ' . $job_categories[$line_resumes['job_cat_id']] . ' job in ' . $line_resumes['JobLocation'] . ', Cyprus.';
        $meta['keywords'] = stripslashes($line_resumes["FirstName"] . ' ' . $line_resumes["LastName"]) . ', ' . $job_categories[$line_resumes['job_cat_id']] . ', job, ' . $line_resumes['JobLocation'] . ', Cyprus jobs';
        ?>

        <article class="article cyprus">
            <header>
                <h1><?php echo stripslashes($line_resumes["FirstName"] . ' ' . $line_resumes["LastName"]) . ' Resume'; ?></h1>
                <!--[/SocialShareButtons/]-->
            </header>
            <div class="article-body cyprus">


                <div align="container-fluid">
                    <?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 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="alert alert-info">
                        <p>
                            <?php
                            echo '<strong>' . stripslashes($line_resumes["FirstName"] . ' ' . $line_resumes["LastName"]) . '</strong> is looking for a <strong>' . $job_categories[$line_resumes['job_cat_id']] . '</strong> job in <strong>' . $line_resumes['JobLocation'] . '</strong>, Cyprus.';
                            ?>
                        </p>
                    </div>
                    <div class="job-details" itemscope itemtype="http://schema.org/Person">

                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <b>Candidate Info</b>
                            </div>
                            <div class="panel-body no-padding">
                                <div class="container-fluid">

                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Name</div>
                                        <div class="col-sm-7">
                                            <span itemprop="title" class="text-bold text-primary"><?= stripslashes($line_resumes["FirstName"] . ' ' . $line_resumes['LastName']); ?></span>
                                        </div>
                                    </div>

                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Gender</div>
                                        <div class="col-sm-7">
                                            <span itemprop="industry" class=""><?php echo $line_resumes['Genre'] == "m" ? "Male" : "Female";?></span>
                                        </div>
                                    </div>

                                    <?php
                                    if($line_resumes['dob'] != "") {
                                        ?>
                                        <div class="row detail-row">
                                            <div class="col-sm-3 text-bold">Age:</div>
                                            <div class="col-sm-7">
                                            <span class="">
                                                <?php
                                                echo "<b>" . date_diff(date_create(date('Y-m-d', strtotime($line_resumes['dob']))), date_create('today'))->y, "</b> years old";
                                                ?>
                                            </span>
                                            </div>
                                        </div>
                                        <?php
                                    }
                                    ?>

                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Marital Status:</div>
                                        <div class="col-sm-7">
                                            <span class="">
                                                <?php
                                                echo $line_resumes['MaritalStatus'];
                                                ?>
                                            </span>
                                        </div>
                                    </div>
                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Children:</div>
                                        <div class="col-sm-7">
                                            <span class="">
                                                <?php
                                                echo intval($line_resumes['Children']) > 0 ? $line_resumes['Children'] : 'No children';
                                                ?>
                                            </span>
                                        </div>
                                    </div>

                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Country Of Origin:</div>
                                        <div class="col-sm-7">
                                            <span class="">
                                                <?php
                                                echo $line_resumes['CountryOfOrigin'];
                                                ?>
                                            </span>
                                        </div>
                                    </div>

                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Last Updated:</div>
                                        <div class="col-sm-7">
                                            <meta itemprop="datePosted" content="<?php echo date("c", strtotime($line_resumes['updated_at'])); ?>"/>
                                            <span class=""><?php echo date("d/m/Y", strtotime($line_resumes['updated_at'])); ?></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <b>Residence / 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">Address</div>
                                        <div class="col-sm-7">
                                            <span><?= nl2br(stripslashes(trim($line_resumes['ResAddress']))); ?></span>,
                                            <span class="text-bold"><?= stripslashes(trim($line_resumes['ResTown'])); ?></span>,
                                            <span class="text-bold"><?= $line_resumes['ResCountry']; ?></span>
                                        </div>
                                    </div>
                                    <?php
                                    $phones = array();

                                    if(strlen(trim($line_resumes['ResPhone'])) >= 8) {
                                        $phn = preg_replace('/[^0-9+]/', '', trim($line_resumes['ResPhone']));
                                        if(strlen($phn) >= 8) {
                                            $phones [] = '<i class="fa fa-phone"></i> <a href="tel:'.$phn.'">' . format_phone(trim($line_resumes['ResPhone'])) . '</a>';
                                        }
                                    }

                                    if(strlen(trim($line_resumes['Mobile'])) >= 8) {
                                        $phn = preg_replace('/[^0-9+]/', '', trim($line_resumes['Mobile']));
                                        if(strlen($phn) >= 8) {
                                            $phones [] = '<i class="fa fa-mobile-phone"></i> <a href="tel:'.$phn.'">' . format_phone(trim($line_resumes['Mobile'])) . '</a>';
                                        }
                                    }

                                    if(count($phones) > 0) {
                                        ?>
                                        <div class="row detail-row">
                                            <div class="col-sm-3 text-bold">Phones</div>
                                            <div class="col-sm-7">
                                                <span><?= implode(', ', $phones); ?></span>
                                            </div>
                                        </div>
                                        <?php
                                    }
                                    ?>
                                    <div class="row detail-row">
                                        <div class="col-sm-3 text-bold">Email</div>
                                        <div class="col-sm-7">
                                            <span><i class="fa fa-envelope"></i> <a href="mailto:<?= $line_resumes['Email']; ?>"><?= $line_resumes['Email']; ?></a></span>
                                        </div>
                                    </div>



                                </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);
                        }
                        ?>

                        <?php
                        if (trim(strip_tags($line_resumes["ProfessionalExperience"])) != "") {
                            ?>
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <b>Professional Experience</b>
                                </div>
                                <div class="panel-body">
                                    <?php
                                    if ($line_resumes['jversion'] == 0) {
                                        echo nl2br(stripslashes($line_resumes["ProfessionalExperience"]));
                                    } else {
                                        echo stripslashes($line_resumes["ProfessionalExperience"]);
                                    }
                                    ?>
                                </div>
                            </div>
                            <?php
                        }

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

                        if (trim(strip_tags($line_resumes["SpecialSkills"])) != "") {
                            ?>
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <b>Skills</b>
                                </div>
                                <div class="panel-body">
                                    <?php
                                    if ($line_resumes['jversion'] == 0) {
                                        echo nl2br(stripslashes($line_resumes["SpecialSkills"]));
                                    } else {
                                        echo stripslashes($line_resumes["SpecialSkills"]);
                                    }
                                    ?>
                                </div>
                            </div>
                            <?php
                        }

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

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

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

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

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

                        if (trim(strip_tags($line_resumes["ReferencesOther"])) != "") {
                            ?>
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <b>References</b>
                                </div>
                                <div class="panel-body">
                                    <?php
                                    if ($line_resumes['jversion'] == 0) {
                                        echo nl2br(stripslashes($line_resumes["ReferencesOther"]));
                                    } else {
                                        echo stripslashes($line_resumes["ReferencesOther"]);
                                    }
                                    ?>
                                </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 resume is no longer available.</b>
            </p>
        </div>
        <?php
        require_once(dirname(__FILE__) . "/../404/404.php");
    }
}
else{
    echo 'Please select a Resume first!!';
}
?>
