Jump to content

Recommended Posts

Datalayer(this is where the functions are)

<?php

// START of tblJOBS_COUNTRIES

/**
 * Save to the tblJOBS_COUNTRIES table
 * @param $jobs_country_id int
 * @param $jobs_country_name varchar(100)
 * @param $jobs_country_slug varchar(100)
 * @param $jobs_country_count int
 */
function Jobs_Save_Country(
        $jobs_country_id=0,
        $jobs_country_name=null,
        $jobs_country_slug=null,
        $jobs_country_count=null)
{
        $tableName = "tblJOBS_COUNTRIES";
        $keyName = "jobs_country_id";
        $keyValue = $jobs_country_id;
        
        $FV = array();
        $types = array();
        
        if ($jobs_country_name !== null) { $FV['jobs_country_name'] = $jobs_country_name; $types[] = "text"; }
        if ($jobs_country_slug !== null) { $FV['jobs_country_slug'] = $jobs_country_slug; $types[] = "text"; }
        if ($jobs_country_count !== null) { $FV['jobs_country_count'] = $jobs_country_count; $types[] = "int"; }
        
        return Save($tableName, $keyName, $keyValue, $FV, $types);
}

/**
 * 
 * Load from the tblJOBS_COUNTRIES table
 * @param int $total_rows (out)
 * @param int $jobs_country_id=0
 * @param string $jobs_country_name=null
 * @param string $jobs_country_slug=null
 * @param string $order_by=null
 * @param int $limit_start=0
 * @param int $limit_rows=0
 * 
 * return array Countries
 */
function Jobs_Load_Countries(
        &$total_rows, 
        $jobs_country_id=0, $jobs_country_name=null, $jobs_country_slug=null, 
        $order_by = null, $limit_start = 0, $limit_rows = 0)
{
        $total_rows = 0;
        
        $sql = "SELECT tblJOBS_COUNTRIES.* FROM tblJOBS_COUNTRIES WHERE 1=1";
        
        if ($jobs_country_id !== 0)
        {
                $sql .= sprintf(" AND jobs_country_id = %s", GetSQLValueString($jobs_country_id, "int"));
        }
        if ($jobs_country_name !== null)
        {
                $sql .= sprintf(" AND jobs_country_name LIKE %s", GetSQLValueString($jobs_country_name, "like"));
        }
        if ($jobs_country_slug !== null)
        {
                $sql .= sprintf(" AND jobs_country_slug = %s", GetSQLValueString($jobs_country_slug, "text"));
        }
        
        //DebugOut($sql);
        
        return Load($total_rows, $sql, $order_by, $limit_start, $limit_rows);
}

// END of tblJOBS_COUNTRIES

// START of tblJOBS_REGIONS

// Default regions are:
// Scotland, North East, North West, Yorkshire and Humberside, West Midlands, East Midlands, Wales, 
// ... Northern Ireland, East Anglia, South East, London, South West

/**
 * Save to the tblJOBS_REGIONS table
 * @param $jobs_region_id int
 * @param $jobs_country_id int
 * @param $jobs_region_name varchar(100)
 * @param $jobs_region_slug varchar(100)
 * @param $jobs_region_count int
 */
function Jobs_Save_Region(
        $jobs_region_id=0,
        $jobs_country_id=null,
        $jobs_region_name=null,
        $jobs_region_slug=null,
        $jobs_region_count=null,
        $jobs_region_order=null)
{
        $tableName = "tblJOBS_REGIONS";
        $keyName = "jobs_region_id";
        $keyValue = $jobs_region_id;
        
        $FV = array();
        $types = array();
        
        if ($jobs_country_id !== null) { $FV['jobs_country_id'] = $jobs_country_id; $types[] = "int"; }
        if ($jobs_region_name !== null) { $FV['jobs_region_name'] = $jobs_region_name; $types[] = "text"; }
        if ($jobs_region_slug !== null) { $FV['jobs_region_slug'] = $jobs_region_slug; $types[] = "text"; }
        if ($jobs_region_count !== null) { $FV['jobs_region_count'] = $jobs_region_count; $types[] = "int"; }
        if ($jobs_region_order !== null) { $FV['jobs_region_order'] = $jobs_region_order; $types[] = "int"; }

        return Save($tableName, $keyName, $keyValue, $FV, $types);
}

/**
 * 
 * Load from the tblJOBS_REGIONS table
 * @param int $total_rows (out)
 * @param int $jobs_region_id=0
 * @param int $jobs_country_id=null
 * @param string $jobs_region_name=null
 * @param string $jobs_region_slug=null
 * @param string $order_by=null
 * @param int $limit_start=0
 * @param int $limit_rows=0
 * 
 * return array Regions
 */
function Jobs_Load_Regions(
        &$total_rows, 
        $jobs_region_id=0, $jobs_country_id=null, $jobs_region_name=null, $jobs_region_slug=null, 
        $order_by = null, $limit_start = 0, $limit_rows = 0)
{
        $total_rows = 0;
        
        $sql = "SELECT tblJOBS_REGIONS.* FROM tblJOBS_REGIONS WHERE 1=1";
        
        if ($jobs_region_id !== 0)
        {
                $sql .= sprintf(" AND jobs_region_id = %s", GetSQLValueString($jobs_region_id, "int"));
        }
        if ($jobs_country_id !== null)
        {
                $sql .= sprintf(" AND jobs_country_id = %s", GetSQLValueString($jobs_country_id, "int"));
        }
        if ($jobs_region_name !== null)
        {
                $sql .= sprintf(" AND jobs_region_name LIKE %s", GetSQLValueString($jobs_region_name, "like"));
        }
        if ($jobs_region_slug !== null)
        {
                $sql .= sprintf(" AND jobs_region_slug = %s", GetSQLValueString($jobs_region_slug, "text"));
        }
        
        //DebugOut($sql);
        
        return Load($total_rows, $sql, $order_by, $limit_start, $limit_rows);
}

// END of tblJOBS_REGIONS

// START of tblJOBS_SUBREGIONS

/**
 * Save to the tblJOBS_SUBREGIONS table
 * @param $jobs_subregion_id int
 * @param $jobs_region_id int
 * @param $jobs_country_id int
 * @param $jobs_city_name varchar(100)
 * @param $jobs_city_slug varchar(100)
 * @param $jobs_city_count int
 */
function Jobs_Save_SubRegion(
        $jobs_subregion_id=0,
        $jobs_region_id=null,
        $jobs_country_id=null,
        $jobs_subregion_name=null,
        $jobs_subregion_slug=null,
        $jobs_subregion_count=null,
        $jobs_subregion_order=null)
{
        $tableName = "tblJOBS_SUBREGIONS";
        $keyName = "jobs_subregion_id";
        $keyValue = $jobs_subregion_id;
        
        $FV = array();
        $types = array();
        
        if ($jobs_region_id !== null) { $FV['jobs_region_id'] = $jobs_region_id; $types[] = "int"; }
        if ($jobs_country_id !== null) { $FV['jobs_country_id'] = $jobs_country_id; $types[] = "int"; }
        if ($jobs_subregion_name !== null) { $FV['jobs_subregion_name'] = $jobs_subregion_name; $types[] = "text"; }
        if ($jobs_subregion_slug !== null) { $FV['jobs_subregion_slug'] = $jobs_subregion_slug; $types[] = "text"; }
        if ($jobs_subregion_count !== null) { $FV['jobs_subregion_count'] = $jobs_subregion_count; $types[] = "int"; }
        if ($jobs_subregion_order !== null) { $FV['jobs_subregion_order'] = $jobs_subregion_order; $types[] = "int"; }

        return Save($tableName, $keyName, $keyValue, $FV, $types);
}

/**
 * 
 * Load from the tblJOBS_SUBREGIONS table
 * @param int $total_rows (out)
 * @param int $jobs_subregion_id=0
 * @param int $jobs_region_id=null
 * @param int $jobs_country_id=null
 * @param string $jobs_city_name=null
 * @param string $jobs_city_slug=null
 * @param string $order_by=null
 * @param int $limit_start=0
 * @param int $limit_rows=0
 */
function Jobs_Load_SubRegions(
        &$total_rows, 
        $jobs_subregion_id=0, $jobs_region_id=null, $jobs_country_id=null, 
        $jobs_subregion_name=null, $jobs_subregion_slug=null, 
        $order_by = null, $limit_start = 0, $limit_rows = 0)
{
        $total_rows = 0;
        
        $sql = "SELECT tblJOBS_SUBREGIONS.* FROM tblJOBS_SUBREGIONS WHERE 1=1";
        
        if ($jobs_subregion_id !== 0)
        {
                $sql .= sprintf(" AND jobs_subregion_id = %s", GetSQLValueString($jobs_subregion_id, "int"));
        }
        if ($jobs_region_id !== null)
        {
                $sql .= sprintf(" AND jobs_region_id = %s", GetSQLValueString($jobs_region_id, "int"));
        }
        if ($jobs_country_id !== null)
        {
                $sql .= sprintf(" AND jobs_country_id = %s", GetSQLValueString($jobs_country_id, "int"));
        }
        if ($jobs_subregion_name !== null)
        {
                $sql .= sprintf(" AND jobs_subregion_name LIKE %s", GetSQLValueString($jobs_subregion_name, "like"));
        }
        if ($jobs_subregion_slug !== null)
        {
                $sql .= sprintf(" AND jobs_subregion_slug = %s", GetSQLValueString($jobs_subregion_slug, "text"));
        }
        
        //DebugOut($sql);
        
        return Load($total_rows, $sql, $order_by, $limit_start, $limit_rows);
}

// END of tblJOBS_SUBREGIONS

// START of tblJOBS_CITIES

/**
 * Save to the tblJOBS_CITIES table
 * @param $jobs_city_id int
 * @param $jobs_subregion_id int
 * @param $jobs_region_id int
 * @param $jobs_country_id int
 * @param $jobs_city_name varchar(100)
 * @param $jobs_city_slug varchar(100)
 * @param $jobs_city_count int
 */
function Jobs_Save_City(
        $jobs_city_id=0,
        $jobs_subregion_id=null,
        $jobs_region_id=null,
        $jobs_country_id=null,
        $jobs_city_name=null,
        $jobs_city_slug=null,
        $jobs_city_count=null,
        $jobs_city_order=null)
{
        $tableName = "tblJOBS_CITIES";
        $keyName = "jobs_city_id";
        $keyValue = $jobs_city_id;
        
        $FV = array();
        $types = array();
        
        if ($jobs_subregion_id !== null) { $FV['jobs_subregion_id'] = $jobs_subregion_id; $types[] = "int"; }
        if ($jobs_region_id !== null) { $FV['jobs_region_id'] = $jobs_region_id; $types[] = "int"; }
        if ($jobs_country_id !== null) { $FV['jobs_country_id'] = $jobs_country_id; $types[] = "int"; }
        if ($jobs_city_name !== null) { $FV['jobs_city_name'] = $jobs_city_name; $types[] = "text"; }
        if ($jobs_city_slug !== null) { $FV['jobs_city_slug'] = $jobs_city_slug; $types[] = "text"; }
        if ($jobs_city_count !== null) { $FV['jobs_city_count'] = $jobs_city_count; $types[] = "int"; }
        if ($jobs_city_order !== null) { $FV['jobs_city_order'] = $jobs_city_order; $types[] = "int"; }

        return Save($tableName, $keyName, $keyValue, $FV, $types);
}

/**
 * 
 * Load from the tblJOBS_CITIES table
 * @param int $total_rows (out)
 * @param int $jobs_city_id=0
 * @param int $jobs_subregion_id=null
 * @param int $jobs_region_id=null
 * @param int $jobs_country_id=null
 * @param string $jobs_city_name=null
 * @param string $jobs_city_slug=null
 * @param string $order_by=null
 * @param int $limit_start=0
 * @param int $limit_rows=0
 */
function Jobs_Load_Cities(
        &$total_rows, 
        $jobs_city_id=0, $jobs_subregion_id=null, $jobs_region_id=null, $jobs_country_id=null, 
        $jobs_city_name=null, $jobs_city_slug=null, 
        $order_by = null, $limit_start = 0, $limit_rows = 0)
{
        $total_rows = 0;
        
        $sql = "SELECT tblJOBS_CITIES.* FROM tblJOBS_CITIES WHERE 1=1";
        
        if ($jobs_city_id !== 0)
        {
                $sql .= sprintf(" AND jobs_city_id = %s", GetSQLValueString($jobs_city_id, "int"));
        }
        if ($jobs_subregion_id !== null)
        {
                $sql .= sprintf(" AND jobs_subregion_id = %s", GetSQLValueString($jobs_subregion_id, "int"));
        }
        if ($jobs_region_id !== null)
        {
                $sql .= sprintf(" AND jobs_region_id = %s", GetSQLValueString($jobs_region_id, "int"));
        }
        if ($jobs_country_id !== null)
        {
                $sql .= sprintf(" AND jobs_country_id = %s", GetSQLValueString($jobs_country_id, "int"));
        }
        if ($jobs_city_name !== null)
        {
                $sql .= sprintf(" AND jobs_city_name LIKE %s", GetSQLValueString($jobs_city_name, "like"));
        }
        if ($jobs_city_slug !== null)
        {
                $sql .= sprintf(" AND jobs_city_slug = %s", GetSQLValueString($jobs_city_slug, "text"));
        }
        
        //DebugOut($sql);
        
        return Load($total_rows, $sql, $order_by, $limit_start, $limit_rows);
}

// END of tblJOBS_CITIES



// START of JOBS_HIERARCHY

// JOBS_HIERARCHY stores the information for agencies, branches and consultants

/**
 * 
 * Save to the tblJOBS_HIERARCHY table
 * @param $jobs_hierarchy_id int
 * @param $jobs_hierarchy_type int
 * @param $jobs_hierarchy_parent_id int
 * @param $jobs_hierarchy_name varchar(100)
 * @param $jobs_hierarchy_info text
 */
function Jobs_Save_Hierarchy(
        $jobs_hierarchy_id=0,
        $jobs_hierarchy_type=null,
        $jobs_hierarchy_parent_id=null,
        $jobs_hierarchy_name=null,
        $jobs_hierarchy_info=null
        )
{
        $tableName = "tblJOBS_HIERARCHY";
        $keyName = "jobs_hierarchy_id";
        $keyValue = $jobs_hierarchy_id;
        
        $FV = array();
        $types = array();
        
        if ($jobs_hierarchy_type !== null) { $FV['jobs_hierarchy_type'] = $jobs_hierarchy_type; $types[] = "int"; }
        if ($jobs_hierarchy_parent_id !== null) { $FV['jobs_hierarchy_parent_id'] = $jobs_hierarchy_parent_id; $types[] = "int"; }
        if ($jobs_hierarchy_name !== null) { $FV['jobs_hierarchy_name'] = $jobs_hierarchy_name; $types[] = "text"; }
        if ($jobs_hierarchy_info !== null) { $FV['jobs_hierarchy_info'] = $jobs_hierarchy_info; $types[] = "text"; }
        
        return Save($tableName, $keyName, $keyValue, $FV, $types);
}

/**
 * 
 * Load from the tblJOBS_HIERARCHY table
 * @param int $total_rows
 * @param int $jobs_hierarchy_id
 * @param int $jobs_hierarchy_type
 * @param int $jobs_hierarchy_parent_id
 * @param string $jobs_hierarchy_name
 * @param string $order_by
 * @param int $limit_start
 * @param int $limit_rows
 */
function Jobs_Load_Hierarchy(
        &$total_rows, 
        $jobs_hierarchy_id=0, $jobs_hierarchy_type=null, $jobs_hierarchy_parent_id=null, 
        $jobs_hierarchy_name=null,  
        $order_by = null, $limit_start = 0, $limit_rows = 0)
{
        $total_rows = 0;
        
        $sql = "SELECT tblJOBS_HIERARCHY.* FROM tblJOBS_HIERARCHY WHERE 1=1";
        
        if ($jobs_hierarchy_id !== 0)
        {
                $sql .= sprintf(" AND jobs_hierarchy_id = %s", GetSQLValueString($jobs_hierarchy_id, "int"));
        }
        if ($jobs_hierarchy_type !== 0)
        {
                $sql .= sprintf(" AND jobs_hierarchy_type = %s", GetSQLValueString($jobs_hierarchy_type, "int"));
        }
        if ($jobs_hierarchy_parent_id !== 0)
        {
                $sql .= sprintf(" AND jobs_hierarchy_parent_id = %s", GetSQLValueString($jobs_hierarchy_parent_id, "int"));
        }
        if ($jobs_hierarchy_name !== null)
        {
                $sql .= sprintf(" AND jobs_hierarchy_name LIKE %s", GetSQLValueString($jobs_hierarchy_name, "like"));
        }
        
        DebugOut($sql);
        
        return Load($total_rows, $sql, $order_by, $limit_start, $limit_rows);
}

// END of JOBS_HIERARCHY



// START of tblJOBS_CLIENTS

function Jobs_Load_FeaturedClients(
        &$total_rows, $order_by = null, $limit_start = 0, $limit_rows = 0)
{
        $total_rows = 0;
        
        $meta_group_id = GetMetaGroup('Jobs: Clients');
        
//      $metaFields = array();
//      $metaFields[0] = array(
//              'type'=>'value', 
//              'meta_key'=>'Featured', 
//              'field_name'=>'featured', 
//              'req'=>true, 
//              'min'=>0, 
//              'max'=>1, 
//              'meta_content'=>null, 
//              'meta_value'=>0);
        
        $sql = "
SELECT *
FROM
(
        SELECT t1.*, t2.*, 
        CASE
                WHEN @id != t1.client_id THEN @rownum := 1
            ELSE @rownum := @rownum + 1
        END AS rank,
        @id := t1.client_id
    FROM tblJOBS_CLIENTS t1
    JOIN tblMEDIA t2 ON (t1.client_id = t2.owner_id)
    JOIN ( SELECT @id := NULL, @rownum := 0) t3
    WHERE t2.owner_type = 1
    ORDER BY media_id DESC
) t3
WHERE rank = 1
";
        
        $metaMatches = array();
        $metaMatches[] = array(
                'meta_key'=>'Featured', 'value'=>1, 'field_name'=>'meta_value', 
                'comparison_operator'=>'=', 'comparison_type'=>'int');
        
        $sql .= returnMetaMatchSQL($metaMatches, $meta_group_id, 't3.client_id');
        
        //DebugOut($sql);
        
        return Load($total_rows, $sql, $order_by, $limit_start, $limit_rows);
}

/**
 * 
 * Enter description here ...
 * @param $total_rows
 * @param $args array [item] = array('field_name'=>,'comparison_operator'=>,'value'=>,'data_type'=>)
 * @param $order_by
 * @param $limit_start
 * @param $limit_rows
 */
function Jobs_Load_Clients(
        &$total_rows, $args, 
        $meta_fields=null,
        $meta_matches=null,
        $order_by = null, $limit_start = 0, $limit_rows = 0)
{
        $total_rows = 0;
        
        $sql = "SELECT tblJOBS_CLIENTS.* ";
        
        $meta_group_id = GetMetaGroup('Jobs: Clients');
        $sql .= returnMetaFieldListSQL($meta_fields, $meta_group_id, 'tblJOBS_CLIENTS.client_id');
        
        $sql .= " FROM tblJOBS_CLIENTS";
        
        if ($args !== null && is_array($args) && count($args) > 0)
        {
                $tSql = trim(GetArgsAsSQL($args));
                $sql .= " WHERE " . (startsWithA($tSql, array("AND", "OR", "NOT")) ? "1=1 " : "") . $tSql;
        }
        
        $sql .= returnMetaMatchSQL($meta_matches, $meta_group_id, 'tblJOBS_CLIENTS.client_id');
        
        //DebugOut($sql);
        
        return Load($total_rows, $sql, $order_by, $limit_start, $limit_rows);
}

function Jobs_Save_Client(
        $client_id=0,
        $client_internal_ref=null,
        $client_name=null,
        $client_logo_id=null,
        $client_url=null
        )
{
        $tableName = "tblJOBS_CLIENTS";
        $keyName = "client_id";
        $keyValue = $client_id;
        
        $FV = array();
        $types = array();
        
        if ($client_internal_ref !== null) { $FV['client_internal_ref'] = $client_internal_ref; $types[] = "text"; }
        if ($client_name !== null) { $FV['client_name'] = $client_name; $types[] = "text"; }
        if ($client_logo_id !== null) { $FV['client_logo_id'] = $client_logo_id; $types[] = "int"; }
        if ($client_url !== null) { $FV['client_url'] = $client_url; $types[] = "text"; }
        
        return Save($tableName, $keyName, $keyValue, $FV, $types);
}

// END of tblJOBS_CLIENTS


// START of tblJOBS_VACANCIES

/**
 * 
 * Load Vacancies...
 * @param $total_rows int
 * @param $args array = (param=>mixed)  
 * @param $order_by string
 * @param $limit_start int
 * @param $limit_rows int
 *
 */
function Jobs_Load_Vacancies(&$total_rows, $args=null, $order_by = null, $limit_start = 0, $limit_rows = 0)
{
        $total_rows = 0;
        
        $sql_join = array();
        $sql_where = array();

        
        // Vacancy ID
        $vacancy_id = (array_key_exists('vacancy_id', $args)) ? $args['vacancy_id'] : null;
        if ($vacancy_id !== null)
        {
                $sql_where[] = sprintf(" tblJOBS_VACANCIES.vacancy_id = %s ", GetSQLValueString($vacancy_id, "int"));
        }
        
        // Client ID
        $cl = (array_key_exists('cl', $args)) ? $args['cl'] : null;
        if ($cl !== null)
        {
                $sql_where[] = sprintf(" tblJOBS_VACANCIES.client_id = %s ", GetSQLValueString($cl, "int"));
        }
        
        // Author ID
        $ag = (array_key_exists('ag', $args)) ? $args['ag'] : null;
        if ($ag !== null)
        {
                $sql_where[] = sprintf(" author_id = %s ", GetSQLValueString($ag, "int"));
        }
        
        // Client Job Ref
        $cl_ref = (array_key_exists('cl_ref', $args)) ? $args['cl_ref'] : null;
        if ($cl_ref !== null)
        {
                $sql_where[] = sprintf(" client_job_ref LIKE %s ", GetSQLValueString($cl_ref, "like"));
        }
        
        // Internal Job Ref
        $ag_ref = (array_key_exists('ag_ref', $args)) ? $args['ag_ref'] : null;
        if ($ag_ref !== null)
        {
                $sql_where[] = sprintf(" internal_job_ref LIKE %s ", GetSQLValueString($ag_ref, "like"));
        }

        // Location
        $loc = (array_key_exists('loc', $args)) ? $args['loc'] : null;
        if ($loc !== null)
        {
                $loc_keys = array('country_id'=>-1, 'region_id'=>-1, 'subregion_id'=>-1, 'city_id'=>-1);
                $country_id = 1;
                
                if (!is_array($loc))
                        $loc = array($loc);
                
                if (count($loc) > 0)
                {
                        //$sql_join[]= " LEFT JOIN tblJOBS_JOBLOCATIONLINK ON tblJOBS_VACANCIES.vacancy_id = tblJOBS_JOBLOCATIONLINK.vacancy_id ";
                        $sql_group = array();

                        foreach ($loc as $loc_item)
                        {
                                $type = substr($loc_item, 0, 1);
                                $sql_subgroup = null;
                                $skip = false;
                                
                                switch ($type)
                                {
                                        case "r":
                                                // Region
                                                $lkeys = $loc_keys;
                                                $lkeys['country_id'] = $country_id;
                                                $lkeys['region_id'] = substr($loc_item, 1);
                                                unset($lkeys['subregion_id']);
                                                unset($lkeys['city_id']);
                                                break;
                                        case "s":
                                                // Sub-Region
                                                $lkeys = $loc_keys;
                                                $lkeys['country_id'] = $country_id;
                                                unset($lkeys['region_id']);
                                                $lkeys['subregion_id'] = substr($loc_item, 1);
                                                unset($lkeys['city_id']);
                                                break;
                                        case "c":
                                                // City
                                                $lkeys = $loc_keys;
                                                $lkeys['country_id'] = $country_id;
                                                unset($lkeys['region_id']);
                                                unset($lkeys['subregion_id']);
                                                $lkeys['city_id'] = substr($loc_item, 1);
                                                break;
                                        default:
                                                $skip = true;
                                                break;
                                }
                                
                                if ($skip) 
                                        continue;
                                        
                                // Search for a match and if not available, create one - in case delete failed
                                $sql_args = array();
                                foreach ($lkeys as $thisk=>$thisv)
                                        $sql_args[] = "tblJOBS_JOBLOCATIONLINK.$thisk = $thisv";
                                
                                $sql_group[] = " EXISTS ( SELECT vacancy_id AS vc FROM tblJOBS_JOBLOCATIONLINK " . 
                                        "WHERE vacancy_id = tblJOBS_VACANCIES.vacancy_id AND " . implode(' AND ', $sql_args) . " ) ";
                        }
                        
                        $sql_where[] = " ( " . implode(" OR ", $sql_group) . " ) ";
                }
        }
        
        // Area of Law
        $aol = (array_key_exists('aol', $args)) ? $args['aol'] : null;
        if ($aol !== null)
        {
                if (!is_array($aol))
                        $aol = array($aol);
                
                if (count($aol) > 0)
                {
                        //$sql_join[]= " LEFT JOIN tblJOBS_JOBDISCIPLINELINK ON tblJOBS_VACANCIES.vacancy_id = tblJOBS_JOBDISCIPLINELINK.vacancy_id ";
                        $sql_group = array();
                        foreach ($aol as $aol_item)
                                $sql_group[] = " tblJOBS_JOBDISCIPLINELINK.discipline_id = $aol_item ";
                                
                        $sql_where[] = " EXISTS ( SELECT vacancy_id AS vc FROM tblJOBS_JOBDISCIPLINELINK " . 
                                "WHERE vacancy_id = tblJOBS_VACANCIES.vacancy_id AND " . 
                                "( " . implode(" OR ", $sql_group) . " ) ) ";
                }
        }
        

        // rent
        $s_sf = (array_key_exists('s_sf', $args)) ? $args['s_sf'] : null;
        $s_sf2 = (array_key_exists('s_sf2', $args)) ? $args['s_sf2'] : null;
        $sf = (array_key_exists('sf', $args)) ? $args['sf'] : null;
        if ($sf !== null)
        {
                if (!is_array($sf))
                        $sf = array($sf);
                        
                if (count($sf) > 0)
                {
                        //$sql_join[]= " LEFT JOIN tblJOBS_JOBDISCIPLINELINK ON tblJOBS_VACANCIES.vacancy_id = tblJOBS_JOBDISCIPLINELINK.vacancy_id ";
                        $sql_group = array();
                        foreach ($sf as $sf_item)
                                $sql_group[] = " tblJOBS_JOBRENTLINK.job_level_val = $sf_item ";
                                
                        $sql_where[] = " EXISTS ( SELECT vacancy_id AS vc FROM tblJOBS_JOBRENTLINK " . 
                                "WHERE vacancy_id = tblJOBS_VACANCIES.vacancy_id 
                                 AND " . 
                                "( " . implode(" OR ", $sql_group) . " ) ) ";
                        
                }
                        
        }
        
        // Job Level
        $jl = (array_key_exists('jl', $args)) ? $args['jl'] : null;
        if ($jl !== null)
        {
                if (!is_array($jl))
                        $jl = array($jl);
                
                if (count($jl) > 0)
                {
                        //$sql_join[]= " LEFT JOIN tblJOBS_JOBDISCIPLINELINK ON tblJOBS_VACANCIES.vacancy_id = tblJOBS_JOBDISCIPLINELINK.vacancy_id ";
                        $sql_group = array();
                        foreach ($jl as $jl_item)
                                $sql_group[] = " tblJOBS_JOBLEVELLINK.job_level_val = $jl_item ";
                                
                        $sql_where[] = " EXISTS ( SELECT vacancy_id AS vc FROM tblJOBS_JOBLEVELLINK " . 
                                "WHERE vacancy_id = tblJOBS_VACANCIES.vacancy_id AND " . 
                                "( " . implode(" OR ", $sql_group) . " ) ) ";
                }
        }
        
        
//      // Job Level
//      $jl = (array_key_exists('jl', $args)) ? $args['jl'] : null;
//      if ($jl !== null)
//      {
//              if (!is_array($jl))
//                      $jl = array($jl);
//              
//              if (count($jl) > 0)
//              {
//                      $sql_group = array();
//                      foreach ($jl as $jl_item)
//                              $sql_group[] = " job_level_val = $jl_item ";
//                              
//                      $sql_where[] = " ( " . implode(" OR ", $sql_group) . " ) ";
//              }
//      }
        
        // JSBEDS
        $js = (array_key_exists('js', $args)) ? $args['js'] : null;
        if ($js !== null)
        {
                if (!is_array($js))
                        $js = array($js);
                
                if (count($js) > 0)
                {
                        //$sql_join[]= " LEFT JOIN tblJOBS_JOBDISCIPLINELINK ON tblJOBS_VACANCIES.vacancy_id = tblJOBS_JOBDISCIPLINELINK.vacancy_id ";
                        $sql_group = array();
                        foreach ($js as $js_item)
                                $sql_group[] = " tblJOBS_JOBBEDLINK.job_level_val = $js_item ";
                                
                        $sql_where[] = " EXISTS ( SELECT vacancy_id AS vc FROM tblJOBS_JOBBEDLINK " . 
                                "WHERE vacancy_id = tblJOBS_VACANCIES.vacancy_id AND " . 
                                "( " . implode(" OR ", $sql_group) . " ) ) ";
                }
        }
        
        // Job Sector
//      $js = (array_key_exists('js', $args)) ? $args['js'] : null;
//      if ($js !== null)
//      {
//              if (!is_array($js))
//                      $js = array($js);
//              
//              if (count($js) > 0)
//              {
//                      $sql_group = array();
//                      foreach ($js as $js_item)
//                              $sql_group[] = " job_sector_val = $js_item ";
//                              
//                      $sql_where[] = " ( " . implode(" OR ", $sql_group) . " ) ";
//              }
//      }
        
        // Job Type
        $jt = (array_key_exists('jt', $args)) ? $args['jt'] : null;
        if ($jt !== null)
        {
                if (!is_array($jt))
                        $jt = array($jt);
                
                if (count($jt) > 0)
                {
                        $sql_group = array();
                        foreach ($jt as $jt_item)
                                $sql_group[] = " job_type_val = $jt_item ";
                                
                        $sql_where[] = " ( " . implode(" OR ", $sql_group) . " ) ";
                }
        }
        
        // Keywords : Job Title - need to be split before they get here
        $jtl = (array_key_exists('jtl', $args)) ? $args['jtl'] : null;
        if ($jtl !== null)
        {
                if (!is_array($jtl))
                        $jtl = array($jtl);
                
                if (count($jtl) > 0)
                {
                        $sql_group = array();
                        foreach ($jtl as $jtl_item)
                                $sql_group[] = sprintf(" job_title LIKE %s ", 
                                        GetSQLValueString($jtl_item, "like"));
                                
                        $sql_where[] = " ( " . implode(" OR ", $sql_group) . " ) ";
                }
        }
        
        // Keywords : Job Description - need to be split before they get here
        $jd = (array_key_exists('jd', $args)) ? $args['jd'] : null;
        if ($jd !== null)
        {
                if (!is_array($jd))
                        $jd = array($jd);
                
                if (count($jd) > 0)
                {
                        $sql_group = array();
                        foreach ($jd as $jd_item)
                                $sql_group[] = sprintf(" job_description LIKE %s ", 
                                        GetSQLValueString($jd_item, "like"));
                                
                        $sql_where[] = " ( " . implode(" OR ", $sql_group) . " ) ";
                }
        }
        
        // Expiry Date
        $expired = (array_key_exists('expired', $args)) ? $args['expired'] : null;
        if ($expired !== null)
        {
                if ($expired)
                {
                        $sql_where[] = sprintf(" expiry_date <= %s ", time());
                }
                else
                {
                        $sql_where[] = sprintf(" expiry_date > %s ", time());
                }
        }
        
        // Enabled
        $enabled = (array_key_exists('enabled', $args)) ? $args['enabled'] : null;
        if ($enabled !== null)
        {
                $sql_where[] = sprintf(" enabled = %s ", ($enabled ? 1 : 0));
        }
        
        //// Salary
//      $sf = (array_key_exists('sf', $args)) ? $args['sf'] : null;     // Min
        //$st = (array_key_exists('st', $args)) ? $args['st'] : null;   // Max
//      $sql_group = array();
//      if ($sf !== null && $st !== null)
//      {
//              $sql_group[] = sprintf("(salary_from_pa > %s AND salary_from_pa < %s)", 
//                      GetSQLValueString($sf, "decimal"), GetSQLValueString($st, "decimal"));
//              $sql_group[] = sprintf("(salary_to_pa > %s AND salary_to_pa < %s AND salary_to_pa != 0)", 
//                      GetSQLValueString($sf, "decimal"), GetSQLValueString($st, "decimal"));
//              $sql_group[] = sprintf("(salary_from_pa > %s AND salary_to_pa < %s AND salary_to_pa != 0)", 
//                      GetSQLValueString($sf, "decimal"), GetSQLValueString($st, "decimal"));
//              $sql_group[] = sprintf("(salary_from_pa < %s AND salary_to_pa < %s AND salary_to_pa != 0)", 
//                      GetSQLValueString($sf, "decimal"), GetSQLValueString($st, "decimal"));
//                      
//              $sql_where[] = " ( " . implode(" OR ", $sql_group) . " ) ";
//      }
//      elseif ($sf !== null)
//      {
//              $sql_group[] = sprintf("(salary_to_pa > %s AND salary_to_pa != 0)", 
//                      GetSQLValueString($sf, "decimal"));
//              $sql_group[] = sprintf("(salary_from_pa > %s)", 
//                      GetSQLValueString($sf, "decimal"));
//                      
//              $sql_where[] = " ( " . implode(" OR ", $sql_group) . " ) ";
//      }
//      elseif ($st !== null)
//      {
//              $sql_group[] = sprintf("(salary_from_pa < %s)", 
//                      GetSQLValueString($st, "decimal"));
//                      
//              $sql_where[] = " ( " . implode(" OR ", $sql_group) . " ) ";
//      }
//      
//      // Salary: Min
//      $sf = (array_key_exists('sf', $args)) ? $args['sf'] : null;
//      if ($sf !== null)
//      {
//              $sql_where[] = " salary_to_pa > $sf ";
//      }
//      
//      // Salary: Max
//      $st = (array_key_exists('st', $args)) ? $args['st'] : null;
//      if ($st !== null)
//      {
//              $sql_where[] = " salary_from_pa < $st ";
//      }
        
        // Get Client Info
        $sql_join[]= " LEFT JOIN tblJOBS_CLIENTS ON tblJOBS_VACANCIES.client_id = tblJOBS_CLIENTS.client_id ";
        $sql_join[]= " LEFT JOIN tblUSERS ON tblJOBS_VACANCIES.author_id = tblUSERS.user_id ";
        
        // Build SQL
        $sql_from = " tblJOBS_VACANCIES ";
        if (count($sql_join) > 0)
        {
                foreach ($sql_join as $sql_join_item)
                        $sql_from = " ( $sql_from $sql_join_item ) ";
        }
        
        $sql_pre = "SELECT tblJOBS_VACANCIES.*, tblJOBS_CLIENTS.*, tblUSERS.email_address ";
        
        // User Info
        $metaFields = array();
        $metaFields[0] = array('type'=>'content', 'meta_key'=>'First Name', 'field_name'=>'first_name', 'req'=>true, 'min'=>1, 'max'=>100, 'meta_content'=>null, 'meta_value'=>null);
        $metaFields[1] = array('type'=>'content', 'meta_key'=>'Last Name', 'field_name'=>'last_name', 'req'=>true, 'min'=>1, 'max'=>100, 'meta_content'=>null, 'meta_value'=>null);
        $meta_group_id = GetMetaGroup('Users');
        $sql_pre .= returnMetaFieldListSQL($metaFields, $meta_group_id, 'tblJOBS_VACANCIES.author_id');
        
        $sql = "$sql_pre FROM $sql_from ";
        
        if (count($sql_where) > 0)
        {
                $sql .= " WHERE " . implode(" AND ", $sql_where);
        }
        
        //echo "<!-- \r\n$sql\r\n//-->";
        //exit();
        
        return Load($total_rows, $sql, $order_by, $limit_start, $limit_rows);   
}

function Jobs_Save_Vacancy($vacancy_id=0, $args=null)
{
        $tableName = "tblJOBS_VACANCIES";
        $keyName = "vacancy_id";
        $keyValue = $vacancy_id;
        
        $FV = array();
        $types = array();
        
        if (is_array($args))
        {
                foreach ($args as $thisField)
                {
                        if ($thisField['type'] == "text")
                        {
                                $FV[$thisField['name']] = $thisField['value']; $types[] = $thisField['type'];
                        }
                        elseif ($thisField['value'] !== null && $thisField['value'] != "")
                        {
                                $FV[$thisField['name']] = $thisField['value']; $types[] = $thisField['type'];
                        }
                }
        }
        
        return Save($tableName, $keyName, $keyValue, $FV, $types);
}
// END of tblJOBS_VACANCIES


function GetArgsAsSQL($args, $innerOperator = 'AND')
{
        $sql = "";
        if ($args !== null && is_array($args))
        {
                $sql_parts = array();
                foreach ($args as $argItem)
                {
                        if (array_key_exists('group', $argItem))
                        {
                                $sql .= sprintf(" %s (%s)",
                                        $argItem['outer_operator'],
                                        GetArgsAsSQL($argItem['group'], $argItem['inner_operator']));
                        }
                        else
                        {
                                $sql_parts[] = sprintf(" %s %s %s ", 
                                        $argItem['field_name'], 
                                        $argItem['comparison_operator'], 
                                        GetSQLValueString($argItem['value'], $argItem['data_type']));
                        }
                }
                
                if (count($sql_parts) > 0)
                {
                        $sql .= implode($innerOperator, $sql_parts);
                }
        }
        return $sql;
}

// START of JOBS_SECTORS


// END of JOBS_SECTORS


// START of JOBS_SUB_SECTORS


// END of JOBS_SUB_SECTORS


// START of tblJOBS_JOBLOCATIONLINK

function Jobs_Load_JobLocationLinks($vacancy_id, $country_id=1)
{
        $result = array();
        $tableName = "tblJOBS_JOBLOCATIONLINK";
        
        $sql = "SELECT * FROM $tableName WHERE vacancy_id=$vacancy_id";
        
        $totalRows_rs = 0;
        $locations = Load($totalRows_rs, $sql);
        
        if ($totalRows_rs > 0)
        {
                foreach ($locations as $thisLoc)
                {
                        if ($thisLoc['city_id'] != -1)
                        {
                                $result["c".$thisLoc['city_id']] = $thisLoc['location_text'];
                        }
                        elseif ($thisLoc['subregion_id'] != -1)
                        {
                                $result["s".$thisLoc['subregion_id']] = $thisLoc['location_text'];
                        }
                        elseif ($thisLoc['region_id'] != -1)
                        {
                                $result["r".$thisLoc['region_id']] = $thisLoc['location_text'];
                        }
                }
        }
        
        return $result;
}

function Jobs_Save_JobLocationLinks($vacancy_id, $locations_array, $country_id=1)
{
        $tableName = "tblJOBS_JOBLOCATIONLINK";
        $keys = array('vacancy_id'=>-1, 'country_id'=>-1, 'region_id'=>-1, 'subregion_id'=>-1, 'city_id'=>-1);
        
        $removeSQL = "DELETE FROM $tableName WHERE vacancy_id=%s";
        $findSQL = "SELECT COUNT(*) as record_count FROM $tableName WHERE ";
        $createSQL = "INSERT INTO $tableName (%s) VALUES (%s)";
        
        // Clear old link records
        $lSql = sprintf($removeSQL, $vacancy_id);
        ActionSQL($lSql);
        
        if (is_array($locations_array))
        {
                foreach ($locations_array as $k=>$name)
                {
                        $type = substr($k, 0, 1);
                        switch ($type)
                        {
                                case "r":
                                        // Region
                                        $lkeys = $keys;
                                        $lkeys['vacancy_id'] = $vacancy_id;
                                        $lkeys['country_id'] = $country_id;
                                        $lkeys['region_id'] = substr($k, 1);
                                        unset($lkeys['subregion_id']);
                                        unset($lkeys['city_id']);
                                        if (startsWith($name, "All "))
                                                $name = substr($name, 4);
                                        break;
                                case "s":
                                        // Sub-Region - need to store Region_ID too
                                        $sub_region_id = substr($k, 1);
                                        $region_id = -1;
                                        $totalRows_SubRegions = 0;
                                        $SubRegions = Jobs_Load_SubRegions($totalRows_SubRegions, $sub_region_id);
                                        if (count($SubRegions) == 1)
                                                $region_id = $SubRegions[0]['jobs_region_id'];

                                        $lkeys = $keys;
                                        $lkeys['vacancy_id'] = $vacancy_id;
                                        $lkeys['country_id'] = $country_id;
                                        $lkeys['region_id'] = $region_id;
                                        $lkeys['subregion_id'] = $sub_region_id;
                                        unset($lkeys['city_id']);
                                        break;
                                case "c":
                                        // City - need to store Region_ID and Sub-Region_ID too
                                        $city_id = substr($k, 1);
                                        $sub_region_id = -1;
                                        $region_id = -1;
                                        $totalRows_Cities = 0;
                                        $Cities = Jobs_Load_Cities($totalRows_Cities, $city_id);
                                        if (count($Cities) == 1)
                                        {
                                                $region_id = $Cities[0]['jobs_region_id'];
                                                $sub_region_id = $Cities[0]['jobs_subregion_id'];
                                        }
                                                
                                        $lkeys = $keys;
                                        $lkeys['vacancy_id'] = $vacancy_id;
                                        $lkeys['country_id'] = $country_id;
                                        $lkeys['region_id'] = $region_id;
                                        $lkeys['subregion_id'] = $sub_region_id;
                                        $lkeys['city_id'] = $city_id;
                                        break;                                  
                        }
                        
                        // Search for a match and if not available, create one - in case delete failed
                        $sql_args = array();
                        foreach ($lkeys as $thisk=>$thisv)
                                $sql_args[] = "$thisk = $thisv";
                                
                        $lSql = $findSQL . implode(' AND ', $sql_args);
                        
                        if (GetValue($lSql, "record_count") == 0)
                        {
                                // Create
                                $lSql = sprintf($createSQL,
                                        implode(",", array_keys($lkeys)) . ", location_text",
                                        implode(",", array_values($lkeys)) . ", " . GetSQLValueString($name, "text"));
                                ActionSQL($lSql);
                                //DebugOut($lSql);
                        }
                }
                //exit();
        }
}

// END of tblJOBS_JOBLOCATIONLINK



// START of tblJOBS_JOBLEVELLINK

function Jobs_Load_JobLevelLinks($vacancy_id)
{
        $result = array();
        $tableName = "tblJOBS_JOBLEVELLINK";
        
        $sql = "SELECT * FROM $tableName WHERE vacancy_id=$vacancy_id";
        
        $totalRows_rs = 0;
        $jls = Load($totalRows_rs, $sql);
        
        if ($totalRows_rs > 0)
        {
                foreach ($jls as $thisJl)
                        $result[] = $thisJl['job_level_val'];
        }
        return $result;
}

function Jobs_Save_JobLevelLinks($vacancy_id, $jl_array)
{
        $tableName = "tblJOBS_JOBLEVELLINK";
        
        $removeSQL = "DELETE FROM $tableName WHERE vacancy_id=%s";
        $findSQL = "SELECT COUNT(*) as record_count FROM $tableName WHERE ";
        $createSQL = "INSERT INTO $tableName (vacancy_id, job_level_val) VALUES ($vacancy_id, %s)";
        
        // Clear old link records
        $lSql = sprintf($removeSQL, $vacancy_id);
        ActionSQL($lSql);
        
        if (is_array($jl_array))
        {
                foreach ($jl_array as $item)
                {
                        $lSql = sprintf($createSQL, $item);
                        ActionSQL($lSql);                       
                }
        }
}




// START of tblJOBS_JOBDISCIPLINELINK

function Jobs_Load_JobDisciplineLinks($vacancy_id)
{
        $result = array();
        $tableName = "tblJOBS_JOBDISCIPLINELINK";
        
        $sql = "SELECT * FROM $tableName WHERE vacancy_id=$vacancy_id";
        
        $totalRows_rs = 0;
        $aols = Load($totalRows_rs, $sql);
        
        if ($totalRows_rs > 0)
        {
                foreach ($aols as $thisAol)
                        $result[] = $thisAol['discipline_id'];
        }
        return $result;
}


function Jobs_Save_JobDisciplineLinks($vacancy_id, $aol_array)
{
        $tableName = "tblJOBS_JOBDISCIPLINELINK";
        //$keys = array('vacancy_id'=>-1, 'country_id'=>-1, 'region_id'=>-1, 'subregion_id'=>-1, 'city_id'=>-1);
        
        $removeSQL = "DELETE FROM $tableName WHERE vacancy_id=%s";
        $findSQL = "SELECT COUNT(*) as record_count FROM $tableName WHERE ";
        $createSQL = "INSERT INTO $tableName (vacancy_id, discipline_id) VALUES ($vacancy_id, %s)";
        
        // Clear old link records
        $lSql = sprintf($removeSQL, $vacancy_id);
        ActionSQL($lSql);
        
        if (is_array($aol_array))
        {
                foreach ($aol_array as $item)
                {
                        $lSql = sprintf($createSQL, $item);
                        ActionSQL($lSql);                       
                }
        }
}

// END of tblJOBS_JOBDISCIPLINELINK
// START of tblJOBS_JOBRENTLINK

function Jobs_Load_JobrentLinks($vacancy_id)
{
        $result = array();
        $tableName = "tblJOBS_JOBRENTLINK";
        
        $sql = "SELECT * FROM $tableName WHERE vacancy_id=$vacancy_id";
        
        $totalRows_rs = 0;
        $sfs = Load($totalRows_rs, $sql);
        
        if ($totalRows_rs > 0)
        {
                foreach ($sfs as $thisSF)
                        $result[] = $thisSF['job_level_val'];
        }
        return $result;
}


function Jobs_Save_JobrentLinks($vacancy_id, $SF_array)
{
        $tableName = "tblJOBS_JOBRENTLINK";
        //$keys = array('vacancy_id'=>-1, 'country_id'=>-1, 'region_id'=>-1, 'subregion_id'=>-1, 'city_id'=>-1);
        
        $removeSQL = "DELETE FROM $tableName WHERE vacancy_id=%s";
        $findSQL = "SELECT COUNT(*) as record_count FROM $tableName WHERE ";
        $createSQL = "INSERT INTO $tableName (vacancy_id, job_level_val) VALUES ($vacancy_id, %s)";
        
        // Clear old link records
        $lSql = sprintf($removeSQL, $vacancy_id);
        ActionSQL($lSql);
        
        if (is_array($SF_array))
        {
                foreach ($SF_array as $item)
                {
                        $lSql = sprintf($createSQL, $item);
                        ActionSQL($lSql);                       
                }
        }
}

// END of tblJOBS_JOBRENTLINK
// START of tblJOBS_JOBBEDLINK

function Jobs_Load_JobbedLinks($vacancy_id)
{
        $result = array();
        $tableName = "tblJOBS_JOBBEDLINK";
        
        $sql = "SELECT * FROM $tableName WHERE vacancy_id=$vacancy_id";
        
        $totalRows_rs = 0;
        $jss = Load($totalRows_rs, $sql);
        
        if ($totalRows_rs > 0)
        {
                foreach ($jss as $thisJS)
                        $result[] = $thisJS['job_level_val'];
        }
        return $result;
}


function Jobs_Save_JobbedLinks($vacancy_id, $js_array)
{
        $tableName = "tblJOBS_JOBBEDLINK";
        //$keys = array('vacancy_id'=>-1, 'country_id'=>-1, 'region_id'=>-1, 'subregion_id'=>-1, 'city_id'=>-1);
        
        $removeSQL = "DELETE FROM $tableName WHERE vacancy_id=%s";
        $findSQL = "SELECT COUNT(*) as record_count FROM $tableName WHERE ";
        $createSQL = "INSERT INTO $tableName (vacancy_id, job_level_val) VALUES ($vacancy_id, %s)";
        
        // Clear old link records
        $lSql = sprintf($removeSQL, $vacancy_id);
        ActionSQL($lSql);
        
        if (is_array($js_array))
        {
                foreach ($js_array as $item)
                {
                        $lSql = sprintf($createSQL, $item);
                        ActionSQL($lSql);                       
                }
        }
}

// END of tblJOBS_JOBDISCIPLINELINK

// Parts for applications will come later

// Also need to restrict use based upon user's permissions

/**
 * town/postcode/outcode etc is entered
 * validate as postcode/outcode
 * - if postcode/outcode, get lat/lng for this value (pos from a lookup cache)
 * - if NOT valid, treat as a town and look-up via Google for the lat/lng as above
 *
 * when we create a new job (and we can do this to add the same job INFO for multiple locations)
 * we take the [country], [region], [town/postcode]
 * 
 */
?>

search.php this is what shows the search form

<?php 

//$s_aol = null;        // Areas of Law
//$s_loc = null;        // Locations
$s_js = null;   // 1
$s_jl = null;   // 2
$s_sf = null;   // 2
$s_sf2 = null;  // 2
//$aol = null;  // Areas of Law
//$loc = null;  // Locations
$js = null;     // Areas of Law
$jl = null;     // Locations
$sf = null;     // Locations

//$s_aol = array_key_exists('s_aol', $_GET) ? $_GET['s_aol'] : $s_aol;
//$s_loc = array_key_exists('s_loc', $_GET) ? $_GET['s_loc'] : $s_loc;
$s_sf2 = array_key_exists('s_sf2', $_GET) ? $_GET['s_sf2'] : $s_sf2;
$s_sf = array_key_exists('s_sf', $_GET) ? $_GET['s_sf'] : $s_sf;
$s_js = array_key_exists('s_js', $_GET) ? $_GET['s_js'] : $s_js;
$s_jl = array_key_exists('s_jl', $_GET) ? $_GET['s_jl'] : $s_jl;

//$aol = array_key_exists('aol', $_GET) ? $_GET['aol'] : $aol;
//$loc = array_key_exists('loc', $_GET) ? $_GET['loc'] : $loc;

// Load Values for Selects
if (!isset($o_LDC3))
{
        $totalRows_LD3 = 0;
        $ot_LD3 = getOptionTypeId('Beds');
        $o_LD3 = Load_Options($totalRows_LD3, 0, $ot_LD3, null, null, null, 'option_title ASC');
        $o_JSC = CondenseOptions($o_LD3);
}

// load value 2
if (!isset($o_LAfSC))
{
        $totalRows_LD2 = 0;
        $ot_LD2 = getOptionTypeId('Furnishing');
        $o_LD2 = Load_Options($totalRows_LD2, 0, $ot_LD2, null, null, null, 'option_title ASC');
        $o_LAfSC = CondenseOptions($o_LD2);
}
// load value 3
if (!isset($o_SFSC))
{
        $totalRows_LD4 = 0;
        $ot_LD4 = getOptionTypeId('Rent');
        $o_LD4 = Load_Options($totalRows_LD4, 0, $ot_LD4, null, null, null, 'option_title ASC');
        $o_SFSC = CondenseOptions($o_LD4);
}

?>
        <!-- Search //-->
        <div class="searchmargin"><div id="search">
    <div>
        <div class="float_left search_width">
                <img src="../../../../adamson/images/properitysearchtext.png" alt="Job Search" />
            
            <form id="frmAdvancedSearch" style="margin:0;padding:0;" method="get" action="<?php echo $cms_applicationUrl . "prop-search-results.html"; ?>">
                        <div style="display: none;"><input name="search_submit_h" type="hidden" value="Y" /></div>
        
            <table class="search_table" cellspacing="2" cellpadding="0">
             
              <tr>
                <br>
                        <select name="s_js" class="search_dropdown">
                        <option value="0">How Many Beds?</option>
                        <?php
                        echo GetHtmlOptions_FromArray($o_JSC, $s_js);
                        ?>
                    </select>
                    <br>
                
                <br>
               
                        <select name="s_jl" class="search_dropdown">
                        <option value="0">Furnishing ?</option>
                        <?php
                        echo GetHtmlOptions_FromArray($o_LAfSC, $s_jl);
                        ?>
                    </select>
                    <br>
                     <br>
               
                        <select name="s_sf" class="search_dropdown">
                        <option value="0">Min Rent ?</option>
                        <?php
                        echo GetHtmlOptions_FromArray($o_SFSC, $s_sf);
                        ?>
                    </select>
                    <br>
                 <br>
               
                        <select name="s_sf2" class="search_dropdown">
                        <option value="0">Max Rent ?</option>
                        <?php
                        echo GetHtmlOptions_FromArray($o_SFSC, $s_sf2);
                        ?>
                    </select>
                    <br>
                
                
                <br>
                <input name="search_btn" type="image" value="Search" 
                        class="search_btn" src="images/x.gif"/>
              </tr>
              <br>
             
            </table>
            
            </form>
            
          </div> 
        
       
        
        
    </div>
    </div>
    </div>
    <div class="agentlogos"><img src="../../../../adamson/images/safeagent-panel.png" width="75" height="50" alt=""/><img src="../../../../adamson/images/nals-panel.png" width="75" height="50" alt=""/><img src="../../../../adamson/images/property-ombudsman-logo.jpg" width="120" height="50" alt=""/></div>
    <!-- End Search //-->

search results (this is what shows the search results)

<?php
$default_noResultsContent = 
<<<NRC

<ul>
<li>We currently have no properties for this search</li> 

</ul>

NRC;


$_SESSION['latest_search'] = $cms_originalRequestAndQS;

$pageNum_rs = array_key_exists('pageNum_rs', $_GET) ? $_GET['pageNum_rs'] : 1;
$maxRows_rs = 5;
$startRow_rs = ($pageNum_rs - 1) * $maxRows_rs;
$totalRows_rs = array_key_exists('totalRows_rs', $_GET) ? $_GET['totalRows_rs'] : 0;


$js = null;     // Beds!!!!!!!!!!
$s_js = null;   // 1

$jl = null;     // 2
$s_jl = null;   // 2

$sf = null;     // Rent
$s_sf = null;   // 2

$sf = null;     // Locations
$s_sf2 = null;  // 2

$s_aol = null;  // Areas of Law
$s_loc = null;  // Locations
$aol = null;    // Areas of Law
$loc = null;    // Locations
$jt = null;     // 1
$ms = null;     // 4
$mms = null;    // Max Salary
$jk = null;     // Job Keywords
$img = null;    // Job Keywords

// To Allow refine or search by link
//$s_aol = array_key_exists('s_aol', $_GET) ? $_GET['s_aol'] : $s_aol;
//$s_loc = array_key_exists('s_loc', $_GET) ? $_GET['s_loc'] : $s_loc;
$aol = array_key_exists('aol', $_GET) ? $_GET['aol'] : $aol;
$loc = array_key_exists('loc', $_GET) ? $_GET['loc'] : $loc;
$jt = array_key_exists('jt', $_GET) ? $_GET['jt'] : $jt;
$jl = array_key_exists('jl', $_GET) ? $_GET['jl'] : $jl;
$js = array_key_exists('js', $_GET) ? $_GET['js'] : $js;
$sf = array_key_exists('sf', $_GET) ? $_GET['sf'] : $sf;
$mms = array_key_exists('mms', $_GET) ? $_GET['mms'] : $mms;
$jk = array_key_exists('jk', $_GET) ? $_GET['jk'] : $jk;
$img = array_key_exists('img', $_GET) ? $_GET['img'] : $img;
$s_js = array_key_exists('s_js', $_GET) ? $_GET['s_js'] : $s_js;
$s_jl = array_key_exists('s_jl', $_GET) ? $_GET['s_jl'] : $s_jl;
$s_sf = array_key_exists('s_sf', $_GET) ? $_GET['s_sf'] : $s_sf;
$s_sf2 = array_key_exists('s_sf2', $_GET) ? $_GET['s_sf2'] : $s_sf2;
//if ($s_aol != null && is_numeric($s_aol) && $s_aol > 0)
//      $aol = array($s_aol);
//if ($s_loc != null && $s_loc != "0")
//      $loc = array(0=>$s_loc);

if ($s_js != null && is_numeric($s_js) && $s_js > 0)
        $js = array($s_js);
        
if ($s_jl != null && $s_jl != "0")
        $jl = array(0=>$s_jl);
        
        if ($s_sf != null && $s_sf != "0")
        $sf = array(0=>$s_sf);
        
//if ($s_sf != null && is_numeric($s_sf) && $s_sf > 0)
        //$sf = array($sf=>$s_sf );
        
//if ($s_sf2 != null && is_numeric($s_sf2) && $s_sf2 > 0)
        //$sf = array($sf=>$s_sf2 );    
        
        //$sf >= ($s_sf) AND $sf <= ($s_sf2);

$order_by = "creation_date DESC";
if (array_key_exists('order_by', $_GET))
{
        switch ($_GET['order_by'])
        {
                case "creation_date ASC":
                case "creation_date DESC":
                case "job_title ASC":
                case "job_title DESC":
                case "salary_from_pa ASC":
                case "salary_from_pa DESC":
                        $order_by = $_GET['order_by'];
                        break;
                default:
                        $order_by = "creation_date ASC";
                        break;
        }
}

// Search
//$sf = 0;
$ms = 0;
$st = 0;
//$jl = 0;
//$js = 0;
//$ms = 0;
// search = 0
//$ms = rent
if ($st != null)
        if ($ms != null)
        if ($s_sf != null)
        if ($s_sf2 !=null)
        //$s_sf >= (min) AND $s_sf2 <= (max);



$args = array
        (
                //"expired"=>false,
                "enabled"=>true
        );

//if ($sf > 0) $args['sf'] = $sf;
//if ($js != null) $args['js'] = $js;

//if ($jt != null) $args['jt'] = $jt;
//if ($jl != null) $args['jl'] = $jl;


if ($jk != null)
{
        $jk = str_replace(",", " ", $jk);
        $jk_parts = explode(" ", $jk);
        $jk_parts_cleaned = array();
        foreach ($jk_parts as $item)
        {
                if (trim($item) != "")
                        $jk_parts_cleaned[] = trim($item);
        }
        $jk = implode(" ", $jk_parts_cleaned);
        
        if ($jk != "")
        {
                $args['jtl'] = $jk_parts_cleaned;
                $args['jd'] = $jk_parts_cleaned;
                $args['jsn'] = $jk_parts_cleaned;
        }
}




// $jl
$args['jl'] = $jl;
        
$totalRows_rs = 0;
$Vacancies = Jobs_Load_Vacancies($totalRows_rs, $args, $order_by, $startRow_rs, $maxRows_rs);
$totalPages_rs = ceil($totalRows_rs/$maxRows_rs);
$queryString_gen = GetPagedQueryStringn($totalRows_rs);


// $js
$args['js'] = $js;
        
$totalRows_rs = 0;
$Vacancies = Jobs_Load_Vacancies($totalRows_rs, $args, $order_by, $startRow_rs, $maxRows_rs);
$totalPages_rs = ceil($totalRows_rs/$maxRows_rs);
$queryString_gen = GetPagedQueryStringn($totalRows_rs);


// $sf
$args['sf'] = $sf;
        
$totalRows_sf = 0;
$Vacancies = Jobs_Load_Vacancies($totalRows_rs, $args, $order_by, $startRow_rs, $maxRows_rs);
$totalPages_rs = ceil($totalRows_rs/$maxRows_rs);
$queryString_gen = GetPagedQueryStringn($totalRows_rs);

//print_r($Vacancies);


if (!isset($o_SFC))
{
        $totalRows_sf = 0;
        $ot_sf = getOptionTypeId('Rent');
        $o_sf = Load_Options($totalRows_sf, 0, $ot_sf, null, null, null, 'option_title ASC');
        $o_SFC = CondenseOptions($o_sf);
}

// Load Values for Selects
if (!isset($o_LDC))
{
        $totalRows_LD = 0;
        $ot_LD = getOptionTypeId('Law Disciplines');
        $o_LD = Load_Options($totalRows_LD, 0, $ot_LD, null, null, null, 'option_title ASC');
        $o_LDC = CondenseOptions($o_LD);
}
//if (!isset($o_LAfSC))
//{
//      $o_LAfSC = GetLocationsArray_ForSearch();
//}
if (!isset($o_JTC))
{
        $totalRows_JT = 0;
        $ot_JT = getOptionTypeId('Job Type');
        $o_JT = Load_Options($totalRows_JT, 0, $ot_JT, null, null, null, 'option_title ASC');
        $o_JTC = CondenseOptions($o_JT);
}
if (!isset($o_JLC))
{
        $totalRows_JL = 0;
        $ot_JL = getOptionTypeId('Furnishing');
        $o_JL = Load_Options($totalRows_JL, 0, $ot_JL, null, null, null, 'option_title ASC');
        $o_JLC = CondenseOptions($o_JL);
}
if (!isset($o_JSC))
{
        $totalRows_JS = 0;
        $ot_JS = getOptionTypeId('Beds');
        $o_JS = Load_Options($totalRows_JS, 0, $ot_JS, null, null, null, 'option_title ASC');
        $o_JSC = CondenseOptions($o_JS);
}
if (!isset($o_MSC))
{
        $totalRows_MS = 0;
        $ot_MS = getOptionTypeId('Rent');
        $o_MS = Load_Options($totalRows_MS, 0, $ot_MS, null, null, null, 'option_title ASC');
        $o_MSC = CondenseOptions($o_MS);
        //$o_MSC = array(0 => 'Not Set');
}
////################################results########################
$result_template = <<<RESULTTEMPLATE

        <!-- Search Result //-->
        <div class="listing_holderresults">
                
                <div class="greydientsearch">
                        <div class="listing_div">
                        <div class="propimages">--IMAGE-- "></div>
                                <div class="float_left listing_leftsearch">
                                <div class="proptitle">--JOB_TITLE--<br /></div>
                                        <b>Rent:</b> --SF--<br />
                                        <b>Beds:</b> --JS--</br>
                                        --JOB_DESCRIPTION--
                                        </br> </div>
                                        <div class="bottomrightimages">
                                        <div class="listing_read_more float_left">
                        <a href="--JOB_LINK--"></a>
                    </div>
                 
                    <div class="listing_apply_now float_left">
                        <a href="--APPLY_FOR_JOB_LINK--"></a>
                   
                                        </div>
                    <div class="clear"></div>
                                </div>
                                <div class="clear"></div> 
                        </div>          
                </div>
        </div>
        <!-- End Search Result //-->

RESULTTEMPLATE;

?>
<a name="searchtop"></a>
<div class="content_padding">
        <h1 class="propertiesh1">Properties</h1>
        <span class="results_count"><?php echo $totalRows_rs; ?> Properties found</span>
</div>


<!-- Latest Vacancies //-->
<?php
if (count($Vacancies) > 0)
{
        foreach ($Vacancies as $thisItem)
        {
                $vacancy_id = $thisItem['vacancy_id'];
                $temp = $result_template;
                
                $job_title = (strlen($thisItem['job_title']) > 50) 
                        ? (substr($thisItem['job_title'], 0, 50) . "...")
                        : $thisItem['job_title'];
                $temp = str_replace("--JOB_TITLE--", $job_title, $temp);
        
        $img = (strlen($thisItem['image']) > 100) 
                        ? (substr($thisItem['image'], 0, 100) . "...")
                        : $thisItem['image'];
                $temp = str_replace("--IMAGE--", $img, $temp);
        
                
                $job_description = strip_tags($thisItem['job_description'], "<br /><br>");
                $job_description = (strlen($job_description) > 350)
                        ? (substr($job_description, 0, 350) . "...")
                        : $job_description;
                
                $job_snippet = strip_tags($thisItem['job_snippet']);
                $job_snippet = str_replace(array('\r\n', '\n'), "<br />", $job_snippet);
                
                if ($job_snippet != '')
                        $job_description = $job_snippet;
                
                $temp = str_replace("--JOB_DESCRIPTION--", $job_description, $temp);
                
                $job_link = $cms_applicationUrl . "JobsById/$vacancy_id/" . GetSlug($job_title);
                $temp = str_replace("--JOB_LINK--", $job_link, $temp);
                        
                $email_job_link = BuildUrl($cms_applicationUrl, "email-job.html", 
                        array
                        (
                                'vacancy_id'=>$vacancy_id, 
                                'redirect'=>urlencode($cms_originalRequestAndQS)
                                ));
                $temp = str_replace("--EMAIL_JOB_LINK--", $email_job_link, $temp);
                
                $email_friend_job_link = BuildUrl($cms_applicationUrl, "email-to-a-friend.html", 
                        array
                        (
                                'vacancy_id'=>$vacancy_id, 
                                'redirect'=>urlencode($cms_originalRequestAndQS)
                                ));
                $temp = str_replace("--EMAIL_FRIEND_JOB_LINK--", $email_friend_job_link, $temp);
                                
                $apply_for_job_link = BuildUrl($cms_applicationUrl, "prop-application.html",
                        array
                        (
                                'vacancy_id'=>$vacancy_id, 
                                'redirect'=>urlencode($cms_originalRequestAndQS)
                        ));
                $temp = str_replace("--APPLY_FOR_JOB_LINK--", $apply_for_job_link, $temp);
                
                $salary = "£" . number_format($thisItem['salary_from_pa'], 0);
                $salary_to = number_format($thisItem['salary_to_pa'], 0);
                if ($salary_to > 0)
                {
                        $salary .= " - £$salary_to";
                }
                $temp = str_replace("--SALARY--", $salary, $temp);
                
                $internal_job_ref = $thisItem['internal_job_ref'];
                $temp = str_replace("--INTERNAL_JOB_REF--", $internal_job_ref, $temp);
                
                // Load Areas of Law
                $aolIn = Jobs_Load_JobDisciplineLinks($vacancy_id);
                $aolMatches = array();
                foreach ($aolIn as $aolItem)
                {
                        if (array_key_exists($aolItem, $o_LDC))
                                $aolMatches[] = $o_LDC[$aolItem];
                }
                $temp = str_replace("--AOL--", implode(", ", $aolMatches), $temp);
                
                // Load Locations
                $locIn = Jobs_Load_JobLocationLinks($vacancy_id);
                $temp = str_replace("--LOCATION--", implode(", ", $locIn), $temp);
                
                // Load Job Levels
                $jlIn = Jobs_Load_JobLevelLinks($vacancy_id);
                $jlMatches = array();
                foreach ($jlIn as $jlItem)
                {
                        if (array_key_exists($jlItem, $o_JLC))
                                $jlMatches[] = $o_JLC[$jlItem];
                }
                $temp = str_replace("--JOB_LEVEL--", implode(", ", $jlMatches), $temp);
                
                $temp = str_replace("--JOB_TYPE--", 
                        (array_key_exists($thisItem['job_type_val'], $o_JTC)
                        ? $o_JTC[$thisItem['job_type_val']]
                        : "U/K"
                        ), $temp);
                        
//              $temp = str_replace("--JOB_LEVEL--", 
//                      (array_key_exists($thisItem['job_level_val'], $o_JLC)
//                      ? $o_JLC[$thisItem['job_level_val']]
//                      : "U/K"
//                      ), $temp);
                        
                        // Load Beds
                $jsIn = Jobs_Load_JobbedLinks($vacancy_id);
                $jsMatches = array();
                foreach ($jsIn as $jsItem)
                {
                        if (array_key_exists($jsItem, $o_JSC))
                                $jsMatches[] = $o_JSC[$jsItem];
                }
                $temp = str_replace("--JS--", implode(", ", $jsMatches), $temp);
                
                // Load Rent
                $sfIn = Jobs_Load_JobrentLinks($vacancy_id);
                $sfMatches = array();
                foreach ($sfIn as $sfItem)
                {
                        if (array_key_exists($sfItem, $o_SFC))
                                $sfMatches[] = $o_SFC[$sfItem];
                }
                $temp = str_replace("--SF--", implode(", ", $sfMatches), $temp);
                
                //$temp = str_replace("--JOB_SECTOR--", 
//                      (array_key_exists($thisItem['job_sector_val'], $o_JSC)
//                      ? $o_JSC[$thisItem['job_sector_val']]
//                      : "U/K"
//                      ), $temp);
                
                echo $temp;
        }
}
else
{
        $noResultsContent = "";
        if (array_key_exists('INC: NO RESULTS CONTENT', $cms_pageIncContent))
        {
                $noResultsContent = $cms_pageIncContent['INC: NO RESULTS CONTENT'];
        }
        else $noResultsContent = $default_noResultsContent;
        
        echo $noResultsContent;
}

include($cms_applicationLocalPath . "cms/includes/custom_paging.php"); 
$Vacancies = null;
?>

Unfortunately this code isn't very clean but is workable
now what i am trying to do is get the results of min and max rent, currently it is working on beds, furnishing.
on min rent it just gets that specific amount of money say £200 and only them properties.
how can i get this to show the the properties between min and maximum.
feel free to ask any questions and ill answer as best i can.
if you need to see the site let me know.
Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/291642-searchminmax/
Share on other sites

What IS ALL THIS CODE?  Do you really expect us to read thru pages of code to answer your question?  How about showing us the pertinent code?  From you description it would seem to be a simple query but looking at this mess of a post I have to wonder how you are trying to do it.

Link to comment
https://forums.phpfreaks.com/topic/291642-searchminmax/#findComment-1493636
Share on other sites

you will need to narrow down the problem and post just the relevant code.

 

when you do post just the relevant code you need help with, YOU will need to FULLY document what each variable means and what data is in it. the code you have is using non-descriptive variable names, like $js, $o_MSC, $ot_MS... for anyone here to be able to help you, you will need to provide a comment on each variable telling us what it means and provide a sample (var_dump()) of what the data in them is.

 

you will also need to describe or post any error or incorrect output you are getting from that relevant code along with a sample of what the correct output should be.

Link to comment
https://forums.phpfreaks.com/topic/291642-searchminmax/#findComment-1493906
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.