<?php
$optres['css'][] = $module_css_path . "/amodules/jobs_ext/css/jobs_ext.css";
$optres['js'][] = $path . "/amodules/jobs_ext/js/jobs_main.js";

$jobs = array(
    'job_cat_id' => "",
    'Location' => $def_location,
    'Conditions' => "",
    'posted' => "all",
    'i_limit' => "20",
    'display' => "no"
);

$cv = array(
    'job_cat_id' => "",
    'JobLocation' => $def_location,
    'posted' => "all",
    'i_limit' => "20",
    'display' => "no"
);

if(isset($_REQUEST['jobs'])) {
	foreach($_REQUEST['jobs'] as $f=>$v) {
        if(isset($jobs[$f])) $jobs[$f] = $v;
    }
}

if(isset($_REQUEST['cv'])) {
    foreach($_REQUEST['cv'] as $f=>$v) {
        if(isset($cv[$f])) $cv[$f] = $v;
    }
}

$locations = array("Nicosia", "Limassol", "Larnaca", "Paphos", "Famagusta");

?>
<div class="row">
    <div class="col-sm-5">
        <section class="jsrch_container box box-primary box-solid">
            <div class="box-header with-border"><h1 class="text-white"><i class="fa fa-search"></i> Job Seekers <small>search jobs.</small></h1></div>
            <div class="box-body">

                <form method="post" action="jobs/" name="jobs_search_frm" id="jobs_search_frm" class="form-horizontal" role="form">
                    <div class="container-fluid">
                        <div class="form-group">
                            <label class="control-label"><?php echo 'Job Category';?></label>
                            <select name="jobs[job_cat_id]" class="form-control input-sm">
                                <option value=""><?php echo 'Select Category';?></option>
                                <?php
                                $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)){
                                        $selected = '';
                                        if($jobs['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 class="form-group">
                            <label class="control-label"><?php echo 'Job Location';?></label>
                            <select name="jobs[Location]" class="form-control input-sm">
                                <option value=""><?php echo 'Any'?></option>
                                <?php
                                foreach ($locations as $loc) {
                                    $selected = '';
                                    if($jobs['Location'] == $loc) $selected = 'selected="selected"';
                                    echo '<option value="',$loc,'" ',$selected,'>', $loc, '</option>';
                                }
                                ?>
                            </select>
                        </div>


                        <div class="form-group">
                            <label class="control-label"><?php echo 'Job Type';?></label>
                            <?php
                            $all_commitment = array(
                                "full-time" 	=> "Full Time",
                                "part-time"		=> "Part Time",
                                "contract"		=> "Contract",
                                "temp"			=> "Temporary",
                                "internship"	=> "Internship",
                                "other"			=> "Other"
                            );
                            ?>
                            <select name="jobs[Conditions]" class="form-control input-sm">
                                <option value=""><?php echo 'Any';?></option>
                                <?php
                                foreach ($all_commitment as $ctype=>$ctype_title) {
                                    $selected = '';
                                    if($jobs['Conditions'] == $ctype) $selected = 'selected="selected"';
                                    echo '<option value="',$ctype,'" ',$selected,'>', $ctype_title, '</option>';
                                }
                                ?>
                            </select>
                        </div>


                        <div class="form-group">
                            <label class="control-label"><?php echo 'Posted';?></label>
                            <select name="jobs[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(isset($jobs['posted']) && $jobs['posted'] != "all" && $jobs['posted'] == $pv) $selected = 'selected="selected"';
                                    echo '<option value="',$pv,'" ',$selected,'>', $pv_title, '</option>';
                                }
                                ?>
                            </select>
                        </div>

                        <div class="form-inline">
                            <div class="form-group">
                                    <?php
                                    echo 'Show', ' ';
                                    echo '<select name="jobs[i_limit]" style="width: 50px;" class="">';
                                    $limit_ar = array('10', '15', '20', '25', '30', '50');
                                    foreach ($limit_ar as $lt) {
                                        $selected = '';
                                        if(intval($jobs['i_limit']) == intval($lt)) $selected = 'selected="selected"';
                                        echo '<option value="',$lt,'" ',$selected,'>',$lt,'</option>';
                                    }
                                    echo '</select> ', 'results per page';
                                    ?>
                            </div>
                        </div>
                        <div class="text-center" style="margin-top: 15px; ">
                            <button type="submit" class="load-disabled btn btn-success btn-sm" disabled="disabled"><i class="fa fa-search fa-lg fa-spin"></i> Search Jobs</button>

                        </div>
                    </div>

                    <input type="hidden" name="jobs[i_from]" value="0">
                    <input type="hidden" name="module_page" value="jobs_ext">
                    <input type="hidden" name="jobs_url" value="jobs"/>
                    <input type="hidden" name="jobs[display]" value="yes"/>
                </form>


            </div>
            <div class="box-footer bg-gray">
                <div class="jfoot">
                    <p class="title"><?php echo 'Be discovered!';?></p>
                    <p>
                        <?php
                        if(!isset($_SESSION['member_id'])) {
                            echo 'Log In or ', '<a href="account/add_member.html">', 'Sign Up', '</a> ', ' to post your Resume.';

                        }
                        else {
                            echo '<a href="account/resumes/resume.html">', 'Post Resume!', '</a> ';
                        }
                        ?>
                        <span class="slogan"><?php echo "It's easy and <b class='text-danger'>FREE</b>!";?></span>
                    </p>
                </div>
            </div>
        </section>
    </div>
    <div class="col-sm-5">
        <section  class="jsrch_container box box-info box-solid">

            <div class="box-header with-border"><h1 class="text-white"><i class="fa fa-search"></i> Employers <small>search resumes.</small></h1></div>
            <div class="box-body">

                <form method="post" action="resumes/" name="resumes_search_frm" id="resumes_search_frm" class="form-horizontal" role="form">
                    <div class="container-fluid">
                        <div class="form-group">
                            <label for="cv_job_cat_id" class="control-label"><?php echo 'Job Category';?></label>
                            <select name="cv[job_cat_id]" id="cv_job_cat_id" class="form-control input-sm">
                                <option value=""><?php echo 'Select Category';?></option>
                                <?php
                                $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)){
                                        $selected = '';
                                        if($cv['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 class="form-group">
                            <label for="cv_JobLocation" class="control-label"><?php echo 'Location';?></label>
                            <select name="cv[JobLocation]" id="cv_JobLocation" class="form-control input-sm">
                                <option value=""><?php echo 'Any'?></option>
                                <?php
                                foreach ($locations as $loc) {
                                    $selected = '';
                                    if($cv['JobLocation'] == $loc) $selected = 'selected="selected"';
                                    echo '<option value="',$loc,'" ',$selected,'>', $loc, '</option>';
                                }
                                ?>
                            </select>
                        </div>

                        <div class="form-group">
                            <label for="cv_posted" class="control-label"><?php echo 'Posted';?></label>
                            <select name="cv[posted]" id="cv_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($cv['posted'] != "all" && $cv['posted'] == $pv) $selected = 'selected="selected"';
                                    echo '<option value="',$pv,'" ',$selected,'>', $pv_title, '</option>';
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group" style="height: 56px;"></div>

                        <div class="form-inline">
                            <div class="form-group">
                                <?php
                                echo 'Show', ' ';
                                echo '<select name="cv[i_limit]" style="vertical-align:middle;">';
                                $limit_ar = array('10', '15', '20', '25', '30', '50');
                                foreach ($limit_ar as $lt) {
                                    $selected = '';
                                    if(intval($cv['i_limit']) == intval($lt)) $selected = 'selected="selected"';
                                    echo '<option value="',$lt,'" ',$selected,'>',$lt,'</option>';
                                }
                                echo '</select> ', 'results per page';
                                ?>
                            </div>
                        </div>
                        <div class="text-center" style="margin-top: 15px; ">
                            <button type="submit" class="load-disabled btn btn-success btn-sm" disabled="disabled"><i class="fa fa-search fa-lg fa-spin"></i> Search Resumes</button>
                        </div>
                    </div>

                    <input type="hidden" name="cv[i_from]" value="0">
                    <input type="hidden" name="module_page" value="jobs_ext">
                    <input type="hidden" name="jobs_url" value=""/>
                    <input type="hidden" name="cv[display]" value="yes"/>
                </form>

            </div>
            <div class="box-footer bg-gray">
                <div class="jfoot">
                    <p class="title"><?php echo 'Have job openings?';?></p>
                    <p>
                        <?php
                        if(!isset($_SESSION['member_id'])) {
                            echo 'Log In or ', '<a href="account/add_member.html">', 'Sign Up', '</a> ', ' to post your jobs.';

                        }
                        else {
                            echo '<a href="account/jobs/job.html">', 'Post Resume!', '</a> ';
                        }
                        ?>
                        <span class="slogan"><?php echo "It's easy and <b class='text-danger'>FREE</b>!";?></span>
                    </p>
                </div>
            </div>

        </section>
    </div>

</div>

<?php
if($gads_show) {
    if ($def_ads == "yes" && $def_ad_id != "") {
        include(dirname(__FILE__) . "/../gads_content/gads_content_default.php");
    }
}


if($def_category_list == "yes") {
// Get the category jobs
    $categs = array();
    $q = "SELECT j.job_cat_id, COUNT(j.job_cat_id) AS num_jobs, c.title_en FROM job_jobs j LEFT JOIN job_cat c ON j.job_cat_id=c.job_cat_id WHERE j.active='yes' AND j.job_status='1' ";
    if ($jdl > 0) {
        $daystolive = date("Y-m-d 00:00:00", strtotime("-$jdl days", time()));
        $q .= " AND j.updated_at>='$daystolive' ";
    }

    if(isset($def_location) && $def_location != "") {
        $q .= " AND j.Location like '%$def_location%' ";
    }

    $q .= " GROUP BY j.job_cat_id ORDER BY c.title_en ASC;";

    $r = @mysql_query($q);
    if ($r && mysql_num_rows($r) > 0) {
        while ($row = mysql_fetch_assoc($r)) {
            $num_jobs = intval($row['num_jobs']);
            $job_cat_id = intval($row['job_cat_id']);
            $title_en = stripslashes($row['title_en']);

            $categs [] = array(
                "title" => $title_en . ' (' . $num_jobs . ')',
                "link" => "jobs/category/" . $job_cat_id . "/" . url_slug($title_en)
            );
        }
    }

    $def_title_location = (isset($def_location) && $def_location != "") ? $def_location : "Cyprus";

    if (count($categs) > 0) {
        ?>
        <div class="box box-default box-solid category-jobs">
            <div class="box-header with-border">
                <h2><?=$def_title_location;?> Jobs By Category</h2>
            </div>
            <div class="box-body">
                <div class="container-fluid">
                    <div class="row">
                        <?php
                        foreach ($categs as $cat) {
                            ?>
                            <div class="col-sm-5 jcateg">
                                <a href="<?= $cat['link']; ?>"><?= $cat['title']; ?></a>
                            </div>
                            <?php
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>
        <?php
    }

}
