<?php
require_once(dirname(__FILE__) . "/../classes/Paginator.php");

$webpage_title_en = "Find Employees In Cyprus";
$meta['description'] = "Check out the latest resume postings in Cyprus. Filter through Limassol resumes, Nicosia resumes, Larnaca resumes, Paphos resumes or Famagusta resumes.";
$meta['keywords'] = "Cyprus resumes, Limassol resumes, Nicosia resumes, Larnaca resumes, Paphos resumes, Famagusta resumes";

$canonical_link = $protocol . $ultra_domainname . "/resumes/";

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

$optres['css'][] = $module_css_path . "amodules/jobsresumes/css/paginator.css";
$optres['css'][] = $module_css_path . "amodules/jobs_ext/css/resumes.css";
$optres['js'][] = $path . "amodules/jobs_ext/js/resumes.js";

$have_filters = true;

$search = array(
    'job_cat_id' => "",
    'JobLocation' => "",
    'CountryOfOrigin' => "",
    'posted' => "all",
    'display' => "yes",
    'i_from' => 0,
    'i_limit' => 20
);



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


if(isset($_POST['resumes']) && isset($_POST['resumes']['display']) && $_POST['resumes']['display'] == "yes") {
    $have_filters = true;
    $resumes = $_POST['resumes'];
    $cv = $_POST['cv'];
    $search = array_merge($search, $cv);
    //echo '<pre>$search = ', var_export($search, true), '</pre>';
}

if(isset($_REQUEST['filter'])) {
    $filter = (trim($_REQUEST['filter']) != "") ? base64_decode($_REQUEST['filter']) : "";
    //echo '<pre>$filter = ', var_export($filter, true), '</pre>';
    if($filter != "") {
        $qs = array();
        parse_str($filter, $qs);
        //echo '<pre>$qs = ', var_export($qs, true), '</pre>';
        //var_dump($qs);
        $search = array_merge($search, $qs);
    }
}


?>
    <section class="article cyprus">
        <header>
            <h1>Find Resumes In Cyprus</h1>
            <!--[/SocialShareButtons/]-->
        </header>
        <div class="article-body ">


            <?php

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

            <form method="post" action="resumes/" id="search_form" class="form-horizontal" role="form">
                <div id="jsearch" class="box no-border">
                    <div class="box-body bg-gray">
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-5">
                                    <div class="form-group">
                                        <label class="control-label">Job Category</label>
                                        <select name="resumes[job_cat_id]" class="form-control input-sm">
                                            <option value=""><?php echo 'Select Category';?></option>
                                            <?php
                                            $categs = array();
                                            $qexl = "select * from job_cat where active='yes' order by order_seq asc;";
                                            $rexl = @mysql_query($qexl);
                                            if($rexl && mysql_num_rows($rexl) > 0) {
                                                while ($rowexl = mysql_fetch_assoc($rexl)){
                                                    $categs[$rowexl['job_cat_id']] = stripslashes($rowexl['title_en']);
                                                    $selected = '';
                                                    if($search['job_cat_id'] == $rowexl['job_cat_id']) $selected = ' selected="selected"';
                                                    echo '<option value="',trim($rowexl['job_cat_id']),'" ',$selected,'>', stripslashes($rowexl['title_en']), '</option>';
                                                }
                                            }
                                            ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-sm-5">
                                    <div class="form-group npl">
                                        <label class="control-label">Posted</label>
                                        <select name="resumes[posted]" class="form-control input-sm">
                                            <option value="all" selected="selected">Any Time</option>
                                            <?php
                                            $posted_vals = array(
                                                '0' => 'Today',
                                                '1' => 'Yesterday',
                                                '7'	=> 'Last 7 Days',
                                                '30'=> 'Last 30 Days'

                                            );
                                            foreach ($posted_vals as $pv=>$pv_title) {
                                                $selected = '';
                                                if($search['posted'] != "all" && $search['posted'] == $pv) $selected = 'selected="selected"';
                                                echo '<option value="',strval($pv),'" ',$selected,'>', $pv_title, '</option>';
                                            }
                                            ?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-5">
                                    <div class="form-group">
                                        <label class="control-label">Location</label>
                                        <select name="resumes[JobLocation]" class="form-control input-sm">
                                            <option value=""><?php echo 'Any'?></option>
                                            <?php
                                            $locations = array("Nicosia", "Limassol", "Larnaca", "Paphos", "Famagusta");
                                            foreach ($locations as $loc) {
                                                $selected = '';
                                                if($search['JobLocation'] == $loc) $selected = 'selected="selected"';
                                                echo '<option value="',$loc,'" ',$selected,'>', $loc, '</option>';
                                            }
                                            ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-sm-5">
                                    <div class="form-group npl">
                                        <label class="control-label">Origin Country</label>

                                        <select name="resumes[CountryOfOrigin]" class="form-control input-sm">
                                            <option value="" <?php echo ($search['CountryOfOrigin'] == "") ? 'selected="selected"' : '';?>>Any</option>

                                            <?php
                                            $countries = array();
                                            $qexl = "SELECT DISTINCT CountryOfOrigin FROM job_cvs WHERE active='yes' AND resume_status='1' ";
                                            if($rdl > 0) {
                                                $daystolive = date("Y-m-d 00:00:00", strtotime("-$rdl days", time()));
                                                $qexl .= " AND updated_at>='$daystolive' ";
                                            }
                                            $qexl .= " ORDER BY CountryOfOrigin ASC;";
                                            $rexl = @mysql_query($qexl);
                                            if($rexl && mysql_num_rows($rexl) > 0) {
                                                while ($rowexl = mysql_fetch_assoc($rexl)){
                                                    $countries[] = stripslashes($rowexl['CountryOfOrigin']);
                                                    $selected = '';
                                                    if( strcmp($search['CountryOfOrigin'], $rowexl['CountryOfOrigin']) === 0) $selected = ' selected="selected"';
                                                    echo '<option value="',trim($rowexl['CountryOfOrigin']),'" ',$selected,'>', stripslashes($rowexl['CountryOfOrigin']), '</option>';
                                                }
                                            }
                                            ?>


                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-5">
                                    <div class="form-group form-inline">
                                        <?php
                                        echo '<span>';
                                        echo '<select name="resumes[i_limit]" class="input-custom input-sm" style="width: 70px; margin-top: 10px;">';
                                        $limit_ar = array('10', '15', '20', '25', '30', '50');
                                        foreach ($limit_ar as $lt) {
                                            $selected = '';
                                            if(intval($search['i_limit']) == intval($lt) ) $selected = 'selected="selected"';
                                            echo '<option value="',$lt,'" ',$selected,'>',$lt,'</option>';
                                        }
                                        echo '</select> ', 'results per page' . '</span>';
                                        ?>
                                    </div>

                                </div>
                                <div class="col-sm-5">
                                    <div class="form-group jfoot">
                                        <button type="submit" name="search_resumes" class="btn btn-sm bg-black"><i class="fa fa-search"></i> Search</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <input type="hidden" name="resumes[i_from]" id="from" value="0">
                <input type="hidden" name="module_page" value="jobs_ext">
                <input type="hidden" name="module_type" value="resumes">
                <input type="hidden" name="jobs_url" value=""/>
                <input type="hidden" name="resumes[display]" value="yes"/>
            </form>



            <?php

            if($have_filters) {

                foreach($search as $k=>$v) {
                    ${$k} = mysql_real_escape_string($v);
                }


                $q = "SELECT * FROM job_cvs WHERE active='yes' AND resume_status='1'";

                if($job_cat_id >0) {
                    $q .= " AND job_cat_id='$job_cat_id' ";
                }

                if($JobLocation != "") {
                    $q .= " AND JobLocation like '%$JobLocation%' ";
                }

                if($CountryOfOrigin != "") {
                    $q .= " AND CountryOfOrigin='$CountryOfOrigin' ";
                }

                switch (strval($posted)) {
                    case "all":
                        if($rdl > 0) {
                            $daystolive = date("Y-m-d 00:00:00", strtotime("-$rdl days", time()));
                            $q .= " AND updated_at>='$daystolive' ";
                        }
                        break;
                    case "0":
                        $today = date("Y-m-d 00:00:00");
                        $q .= " AND updated_at='$today' ";
                        break;
                    case "1":
                        $q .= " AND DATE(updated_at)=DATE_SUB(CURDATE(),INTERVAL 1 DAY) ";
                        break;
                    case "7":
                        $q .= " AND DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= DATE(updated_at) ";
                        break;
                    case "30":
                        $q .= " AND DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= DATE(updated_at) ";
                        break;
                }

                $q .= " ORDER BY updated_at DESC ";

                //echo $q;
                $total_records = 0;
                $r = @mysql_query($q);
                if($r && mysql_num_rows($r)>0){
                    $total_records = mysql_num_rows($r);
                }

                $q .= "	LIMIT $i_from, $i_limit;";

                //echo "<br/>".$q;

                if($total_records > 0) {

                    $paginator = new Paginator(array(
                        "base_url"  => "resumes/?",
                        "request_parameter_name" => "filter",
                        "records_per_page" => 20,
                        "show_all" => 0
                    ));

                    $search = array_map('stripslashes', $search);

                    //echo '<pre>$search = ', var_export($search, true), '</pre>';
                    $pagination = $paginator->paginate($total_records, $search);
                    echo $pagination;

                    $r = mysql_query($q) or die("<strong>$q</strong>".mysql_error());
                    if($r && mysql_num_rows($r)>0) {
                        ?>

                        <div class="container-fluid">

                            <?php
                            $cnt = 1 + $i_from;
                            while ($row = mysql_fetch_assoc($r)) {
                                //$name = (($row['Genre'] == "m") ? "Mr." : "Ms.") . " " . stripslashes(trim($row['FirstName'])) . " " . stripslashes(trim($row['LastName']));
                                $emp_name = trim(stripslashes($row['FirstName']) . ' ' . stripslashes($row['LastName']));
                                $country = stripslashes($row['CountryOfOrigin']);
                                $locations = str_replace(";", ", ", trim($row['JobLocation']));
                                $job_cv_id = intval($row['job_cv_id']);
                                $job_cat_id = intval($row['job_cat_id']);
                                $added_on = date("m/d/Y", strtotime($row['added_on']));
                                $updated_at = date("d/m/Y", strtotime($row['updated_at']));
                                ?>
                                <div class="row job-line">
                                    <div class="jdata col-xs-10 job-title">
                                        <span class="job-num badge"><?=$cnt;?></span>
                                        <!--<a href="jobs/job-details.html?jid=<?/*=$job_cv_id;*/?>" target="_self" class=""><?/*=$job_title;*/?></a>-->
                                        <a href="resumes/resume/<?=$job_cv_id;?>/<?=url_slug($emp_name);?>" target="_self" class=""><?=$emp_name;?></a>
                                    </div>
                                    <div class="jdata col-xs-10">
                                        <div class="row">
                                            <div class="col-sm-5">
                                                <span class="job-company">Country: <strong><?=$country;?></strong></span>
                                            </div>
                                            <div class="col-sm-5">
                                                <span class="job-location">Location: <strong><?=$locations;?></strong></span>
                                            </div>
                                        </div>

                                    </div>

                                    <div class="jdata col-xs-10">
                                        <div class="row">
                                            <div class="col-sm-5">
                                                <span class="job-company">Category: <strong><?=$categs[$job_cat_id];?></strong></span>
                                            </div>
                                            <div class="col-sm-5">

                                            </div>
                                        </div>
                                    </div>


                                    <div class="jdata col-xs-10 date-line">
                                        <div class="row">
                                            <div class="col-xs-10">
                                                <span class="job-updated">Last Updated: <?=$updated_at;?></span>

                                                <span class="job-updated pull-right">ID: <strong><?=$job_cv_id;?></strong></span>
                                            </div>
                                        </div>

                                    </div>
                                </div>

                                <?php

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

                                $cnt++;
                            }
                            ?>

                        </div>

                        <?php
                    }

                    echo $pagination;
                }
                else {
                    echo '<br><div class="alert alert-danger"><p class="text-white"><b><i class="fa fa-warning"></i> Sorry!</b></span><br/>There are no records matching your criteria.</p></div>';
                }
            }
            ?>


        </div>

    </section>
<?php
?>