), remove_allnonalphanumeric_chars($this->input->post('organization_name')))); if ($query_insert) { $this->updateChildLocations($id); //now update the Sphinx Index by SphinxQL $this->sphinxQLAddUpdate('locations', $id); return $id; } else { return false; } } function additionalInfoLocationExistingResource_old($id) { $location_apb = remove_nonalphanumeric_chars($this->input->post('location_apb')); $location_apb2 = remove_nonalphanumeric_chars($this->input->post('location_apb2')); $sql_insert = "UPDATE lostandfound.locations "; $sql_insert .= " SET location_name=?, location_address=?, location_address2=?, location_state=?, location_city=?, location_zipcode=?, location_phone=?, location_fax=?, location_link=?, location_location_id=?, location_send_email=?, location_apb=?, location_apb2=?, location_pic=?, location_description=?, location_date=?, location_autourl=? "; $sql_insert .= " WHERE location_id='{$id}' "; $query_insert = $this->db->query($sql_insert, array($this->input->post('organization_name'), $this->input->post('address1'), $this->input->post('address2'), $this->input->post('state'), $this->input->post('city'), $this->input->post('zipcode'), $this->input->post('phone'), $this->input->post('fax'), $this->input->post('link'), $this->input->post('loc_type'), $this->input->post('radio_sendmail'), $location_apb, $location_apb2, $this->input->post('avatarpic'), $this->input->post('description'), date('Y-m-d'), remove_allnonalphanumeric_chars($this->input->post('organization_name')))); if ($query_insert) { return true; } else { return false; } } function editLocationURL($location_id) { $location_apb = remove_nonalphanumeric_chars($this->input->post('location_apb')); $location_apb2 = remove_nonalphanumeric_chars($this->input->post('location_apb2')); $sql_edit = "UPDATE lostandfound.locations SET "; $sql_edit .= " location_apb = " . $this->db->escape($location_apb) . " , location_apb2 = " . $this->db->escape($location_apb2); $sql_edit .= " WHERE location_id = ?"; $query_edit = $this->db->query($sql_edit, $location_id); if ($query_edit) return true; else return false; } function editLocation($location_id, $needs_admin_approval = false) { $loc_loc_ids = explode(',', $this->input->post('addn_type')); $sql_edit = "UPDATE lostandfound.locations SET "; $sql_edit .= "location_name = " . $this->db->escape($this->input->post('organization_name')) . ", "; $sql_edit .= "location_autourl = " . $this->db->escape(remove_allnonalphanumeric_chars($this->input->post('organization_name'))) . ", "; $sql_edit .= "location_address = " . $this->db->escape($this->input->post('address1')) . ", "; $sql_edit .= "location_address2 = " . $this->db->escape($this->input->post('address2')) . ", "; $sql_edit .= "location_city = " . $this->db->escape($this->input->post('city')) . ", "; $sql_edit .= "location_state = " . $this->db->escape($this->input->post('state')) . ", "; $sql_edit .= "location_zipcode = " . $this->db->escape($this->input->post('zipcode')) . ", "; $sql_edit .= "location_phone = " . $this->db->escape($this->input->post('phone')) . ", "; $sql_edit .= "location_fax = " . $this->db->escape($this->input->post('fax')) . ", "; $sql_edit .= "location_email = " . $this->db->escape($this->input->post('email')) . ", "; if ($this->input->post('hn_latitude') && $this->input->post('hn_longitude')) { $sql_edit .= "latitude = " . $this->db->escape($this->input->post('hn_latitude')) . ", "; $sql_edit .= "longitude = " . $this->db->escape($this->input->post('hn_longitude')) . ", "; } if ($this->input->post('location_location_sub_id')) { $sql_edit .= "location_location_sub_id = " . $this->db->escape($this->input->post('location_location_sub_id')) . ", "; } if ($this->input->post('location_location_sub_radius')) { $sql_edit .= "location_location_sub_radius = " . $this->db->escape($this->input->post('location_location_sub_radius')) . ", "; } if ($this->input->post('type')) { $sql_edit .= "location_location_id = " . $this->db->escape($this->input->post('type')) . ", "; } if ($this->input->post('venue_transit_system')) { $location_transit_system = $this->db->escape_str($this->input->post('venue_transit_system')); $location_transit_system = !strstr($location_transit_system, 'none') ? $location_transit_system : ''; $sql_edit .= "location_transit_system = '$location_transit_system', "; } if ($this->input->post('venue_transit_line')) { $sql_edit .= "location_transit_line = " . $this->db->escape($this->input->post('venue_transit_line')) . ", "; } if ($this->input->post('location_salesperson')) { $sql_edit .= "location_salesperson = " . $this->db->escape($this->input->post('location_salesperson')) . ", "; } $sql_edit .= "location_apb = " . $this->db->escape($this->input->post('location_apb')) . ", "; $sql_edit .= "location_apb2 = " . $this->db->escape($this->input->post('location_apb2')) . ", "; $sql_edit .= "location_link = " . $this->db->escape($this->input->post('link')) . ", "; $sql_edit .= "location_major = " . $this->db->escape($this->input->post('radio_major')) . ", "; $sql_edit .= "location_venue_id = " . $this->db->escape($this->input->post('venue_id')) . ", "; $sql_edit .= "location_pass = " . $this->db->escape($this->input->post('password')) . ", "; $sql_edit .= "location_send_email = " . $this->db->escape($this->input->post('radio_sendmail')) . ", "; $sql_edit .= "location_description = " . $this->db->escape($this->input->post('description')); if ($needs_admin_approval) { $sql_edit .= ", location_status = 'F', location_edited = '1' "; } $sql_edit .= " WHERE location_id = '$location_id'"; $query_edit = $this->db->query($sql_edit); if ($query_edit) { $loc_children = $this->getChildLocationsTypes($location_id); $loc_children_del = array_diff($loc_children, $loc_loc_ids); $loc_children_add = array_diff($loc_loc_ids, $loc_children); foreach ($loc_children_add as $val_lli) { $insert_vars_child = array($this->input->post('organization_name'), $this->input->post('address1'), $this->input->post('address2'), $this->input->post('city'), $this->input->post('state'), $this->input->post('zipcode'), $listing_country, $this->input->post('phone'), $this->input->post('fax'), $this->input->post('email'), $val_lli, $this->input->post('link'), $loc_description, $this->input->post('transit_name'), $this->input->post('radio_sendmail'), $this->input->post('hn_latitude'), $this->input->post('hn_longitude'), $loc_status, $this->input->post('location_location_sub_id'), $this->input->post('location_salesperson'), $location_id, remove_allnonalphanumeric_chars($this->input->post('organization_name'))); $sql_insert_child = "INSERT INTO lostandfound.locations "; $sql_insert_child .= " (location_name, location_address, location_address2, location_city, location_state, location_zipcode, location_country, location_phone, location_fax, location_email, location_location_id, location_link, location_description, location_transit_system, location_send_email, latitude, longitude, location_status, location_location_sub_id, location_salesperson, location_parent, location_autourl)"; $sql_insert_child .= " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $query_insert_child = $this->db->query($sql_insert_child, $insert_vars_child); } foreach ($loc_children_del as $val_lli) { $this->deleteChildLocation($location_id, $val_lli); } $this->updateChildLocations($location_id); //now update the Sphinx Index by SphinxQL $this->sphinxQLAddUpdate('locations', $location_id); return true; } else { return false; } } function unlinkLocation($locationid, $userid) { $sql = "DELETE FROM lostandfound.accounts_locations "; $sql .= " WHERE account_location_location_id=? AND account_location_account_id=?"; $query = $this->db->query($sql, array($locationid, $userid)); $sql = "DELETE FROM lostandfound.accounts_locations_subadmins "; $sql .= " WHERE account_location_location_id=?"; $query = $this->db->query($sql, array($locationid)); if ($query) { //now update the Sphinx Index by SphinxQL $this->sphinxQLAddUpdate('locations', $locationid); return true; } else { return false; } } function getLocationStatesByLocationType($location_type, $country = '') { $country = $this->clocale->getCountry(); $sql = "SELECT DISTINCT (location_state) as location_state, location_state as location_state_name FROM lostandfound.locations "; $sql .= " WHERE location_country = " . $this->db->escape($country); $sql .= " AND location_state != '' AND location_state IS NOT NULL "; $sql .= " AND location_location_id = " . $this->db->escape($location_type); $sql .= " ORDER BY location_state"; $query = $this->db->query($sql); if ($query->num_rows > 0) { return $query->result(); } else { return false; } } function getLocationsByTypeAndState($state, $location_type, $country = '') { $country = $this->clocale->getCountry(); $sql = "SELECT * FROM lostandfound.locations WHERE location_parent=0 AND location_status = 'T' AND location_country='{$country}' "; $sql .= " AND location_state='{$state}' AND location_location_id='$location_type' "; $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $sql .= " ORDER BY location_major DESC, location_city, location_name "; $query = $this->db->query($sql); if ($query->num_rows > 0) { $result = $query->result(); for ($i = 0; $i < count($result); $i++) { foreach ($result[$i] as $key_r => $val_r) { $result[$i]->$key_r = remove_nonascii_chars($result[$i]->$key_r); $result[$i]->$key_r = nl2br(str_ireplace('\n', '', $result[$i]->$key_r)); $result[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $result[$i]->$key_r)); $result[$i]->$key_r = $this->filter_bad_words($result[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $result[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $result[$i]->$key_r = $valkey_r; } } } return $result; } else { return false; } } function getLocationsByTypeAndZipcode($location_type = '', $location_zipcode = '', $radius = 25, $country = '') { $return = false; $country = $this->clocale->getCountry(); $country_code = $this->clocale->getCountryCode(); if ($location_type == '21') { $radius = 40; } elseif ($location_type == '2') { $radius = 5; } elseif ($location_type == '16') { $radius = 15; } elseif ($location_type == '45') { $radius = 100; } elseif ($location_type == '11') { $radius = 100; } $zipcodes = $this->MdlMisc->getZipCodesRadiusSearch($location_zipcode, $radius, true); $sql_zipcode = ""; $sql_zipcode_radius = ""; $sql = "SELECT * FROM lostandfound.locations "; $sql .= " JOIN lostandfound.locations_type ON location_type_id = location_location_id "; $sql .= " WHERE location_status = 'T' AND location_country='{$country}' "; //show only unclaimed venues //$sql .= " AND location_email_temp='' "; if (!empty($location_zipcode)) { $sql_zipcode = " AND location_zipcode='{$location_zipcode}' "; } if (!empty($location_type)) { $sql .= " AND ( "; $sql .= " location_location_id='$location_type' "; if ($location_type == '23') { $sql .= " OR location_location_id='34' "; } $sql .= " ) "; } else { $sql .= " AND location_parent = '0' "; } if (is_array($zipcodes) && count($zipcodes) > 0) { //$sql_zipcode_radius .= " OR location_zipcode='{$location_zipcode}' "; foreach ($zipcodes as $val_zc) { if (stristr($country_code, 'gb') || stristr($country_code, 'ca')) { $sql_zipcode_radius .= " OR location_zipcode LIKE '{$val_zc}%' "; } else { $sql_zipcode_radius .= " OR location_zipcode='{$val_zc}' "; } } $sql_zipcode_radius = substr($sql_zipcode_radius, 3); $sql_zipcode_radius = " AND ({$sql_zipcode_radius}) "; $sql_zipcode_radius = " AND location_zipcode!='{$location_zipcode}' {$sql_zipcode_radius} "; } //if(!empty($sql_zipcode_radius)) $sql_zipcode = $sql_zipcode_radius; $sql_order = " ORDER BY location_name "; $query = $this->db->query($sql . $sql_zipcode . $sql_order); $query_radius = (is_array($zipcodes) && count($zipcodes) > 0) ? $this->db->query($sql . $sql_zipcode_radius . $sql_order) : false; if ($query && $query->num_rows > 0) { $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } $return = $query_res; } if ($query_radius && $query_radius->num_rows > 0) { if (!$return) { $return = array(); } $query_radius_res = $query_radius->result(); for ($i = 0; $i < count($query_radius_res); $i++) { foreach ($query_radius_res[$i] as $key_r => $val_r) { $query_radius_res[$i]->$key_r = remove_nonascii_chars($query_radius_res[$i]->$key_r); $query_radius_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_radius_res[$i]->$key_r)); $query_radius_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_radius_res[$i]->$key_r)); $query_radius_res[$i]->$key_r = $this->filter_bad_words($query_radius_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_radius_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_radius_res[$i]->$key_r = $valkey_r; } } array_push($return, $query_radius_res[$i]); } } return $return; } function getLocationsByTypeAndZipcodeAndIdAndName($location_type = '', $location_zipcode = '', $location_id = '', $location_name = '', $radius = 25, $country = '') { $return = false; $country = $this->clocale->getCountry(); $country_code = $this->clocale->getCountryCode(); if ($location_type == '21') { $radius = 40; } elseif ($location_type == '2') { $radius = 5; } elseif ($location_type == '16') { $radius = 15; } elseif ($location_type == '45') { $radius = 100; } elseif ($location_type == '11') { $radius = 100; } $zipcodes = $this->MdlMisc->getZipCodesRadiusSearch($location_zipcode, $radius, true); $sql_zipcode = ""; $sql_zipcode_radius = ""; $sql = "SELECT * "; $sql .= " FROM lostandfound.locations "; $sql .= " JOIN lostandfound.locations_type ON location_type_id = location_location_id "; $sql .= " JOIN lostandfound.accounts_locations ON location_id = account_location_location_id "; // show only managed venues $sql .= " WHERE location_status = 'T' AND location_parent = 0 AND location_country='{$country}' "; if (!empty($location_id)) { $sql_zipcode = " AND location_id='" . $this->db->escape_str($location_id) . "' "; } else { if (!empty($location_name)) { $sql_zipcode = " AND location_name LIKE '%" . $this->db->escape_like_str($location_name) . "%' "; } if (!empty($location_zipcode)) { $sql_zipcode = " AND location_zipcode='" . $this->db->escape_str($location_zipcode) . "' "; } if (!empty($location_type)) { $sql .= " AND location_location_id='" . $this->db->escape_str($location_type) . "' "; } else { $sql .= " AND location_parent = '0' "; } if (is_array($zipcodes) && count($zipcodes) > 0) { foreach ($zipcodes as $val_zc) { if (stristr($country_code, 'gb') || stristr($country_code, 'ca')) { $sql_zipcode_radius .= " OR location_zipcode LIKE '{$val_zc}%' "; } else { $sql_zipcode_radius .= " OR location_zipcode='{$val_zc}' "; } } $sql_zipcode_radius = substr($sql_zipcode_radius, 3); $sql_zipcode_radius = " AND ({$sql_zipcode_radius}) "; $sql_zipcode_radius = " AND location_zipcode!='{$location_zipcode}' {$sql_zipcode_radius} "; } } $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $sql_order = " ORDER BY location_name "; $query = $this->db->query($sql . $sql_zipcode . $sql_order); $query_radius = (is_array($zipcodes) && count($zipcodes) > 0) ? $this->db->query($sql . $sql_zipcode_radius . $sql_order) : false; if ($query && $query->num_rows > 0) { $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } $return = $query_res; } if ($query_radius && $query_radius->num_rows > 0) { if (!$return) { $return = array(); } $query_radius_res = $query_radius->result(); for ($i = 0; $i < count($query_radius_res); $i++) { foreach ($query_radius_res[$i] as $key_r => $val_r) { $query_radius_res[$i]->$key_r = remove_nonascii_chars($query_radius_res[$i]->$key_r); $query_radius_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_radius_res[$i]->$key_r)); $query_radius_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_radius_res[$i]->$key_r)); $query_radius_res[$i]->$key_r = $this->filter_bad_words($query_radius_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_radius_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_radius_res[$i]->$key_r = $valkey_r; } } array_push($return, $query_radius_res[$i]); } } return $return; } function getTransitNames($transit_type = '', $country = '') { $return = array(); $country = $this->clocale->getCountry(); $sql = "SELECT * FROM lostandfound.locations "; $sql .= " WHERE location_parent=0 AND location_status = 'T' AND location_transit_system != '' AND location_transit_system IS NOT NULL AND location_country='{$country}' "; if ($transit_type == 'train') { $sql .= " AND location_transit_type = 'Train'"; } elseif ($transit_type == 'bus') { $sql .= " AND location_transit_type = 'Bus/BusStation'"; } $sql .= " GROUP BY location_transit_system ORDER BY location_transit_system "; $query = $this->db->query($sql); if ($query && $query->num_rows > 0) { $query_res = $query->result(); foreach ($query_res as $val_qr) { if (!empty($val_qr->location_transit_system)) { array_push($return, $val_qr->location_transit_system); } } } return $return; } function getTransitLocationsByTypeAndZipcode($location_type = '', $location_zipcode = '', $transit_type = 'train', $radius = 25, $country = '') { $return = false; $country = $this->clocale->getCountry(); $country_code = $this->clocale->getCountryCode(); if ($location_type == '21') { $radius = 40; } elseif ($location_type == '2') { $radius = 5; } elseif ($location_type == '16') { $radius = 15; } elseif ($location_type == '45') { $radius = 100; } elseif ($location_type == '11') { $radius = 100; } $zipcodes = $this->MdlMisc->getZipCodesRadiusSearch($location_zipcode, $radius, true); $sql_zipcode = ""; $sql_zipcode_radius = ""; $sql = "SELECT * FROM lostandfound.locations "; $sql .= " JOIN lostandfound.locations_type ON location_type_id = location_location_id "; $sql .= " WHERE location_status = 'T' AND location_transit_system != '' AND location_transit_system IS NOT NULL AND location_country='{$country}' "; if ($transit_type == 'train') { $sql .= " AND location_transit_type = 'Train'"; } elseif ($transit_type == 'bus') { $sql .= " AND location_transit_type = 'Bus/BusStation'"; } elseif ($transit_type == 'train_bus') { $sql .= " AND ( location_transit_type = 'Train' OR location_transit_type = 'Bus/BusStation' )"; } if (!empty($location_zipcode)) { $sql_zipcode = " AND location_zipcode='{$location_zipcode}' "; } if (!empty($location_type)) { $location_type = explode('+', $location_type); $sql .= " AND ( "; $sql .= " location_location_id='{$location_type[0]}' "; for ($i = 1; $i < count($location_type); $i++) { $sql .= " OR location_location_id='{$location_type[$i]}' "; } $sql .= " ) "; } else { $sql .= " AND location_parent = '0' "; } if (is_array($zipcodes) && count($zipcodes) > 0) { foreach ($zipcodes as $val_zc) { if (stristr($country_code, 'gb') || stristr($country_code, 'ca')) { $sql_zipcode_radius .= " OR location_zipcode LIKE '{$val_zc}%' "; } else { $sql_zipcode_radius .= " OR location_zipcode='{$val_zc}' "; } } $sql_zipcode_radius = substr($sql_zipcode_radius, 3); $sql_zipcode_radius = " AND ({$sql_zipcode_radius}) "; $sql_zipcode_radius = " AND location_zipcode!='{$location_zipcode}' {$sql_zipcode_radius} "; } $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $sql_order = " GROUP BY location_transit_system "; $query = $this->db->query($sql . $sql_zipcode . $sql_order); $query_radius = (is_array($zipcodes) && count($zipcodes) > 0) ? $this->db->query($sql . $sql_zipcode_radius . $sql_order) : false; if ($query && $query->num_rows > 0) { $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } $return = $query_res; } if ($query_radius && $query_radius->num_rows > 0) { if (!$return) { $return = array(); } $query_radius_res = $query_radius->result(); for ($i = 0; $i < count($query_radius_res); $i++) { foreach ($query_radius_res[$i] as $key_r => $val_r) { $query_radius_res[$i]->$key_r = remove_nonascii_chars($query_radius_res[$i]->$key_r); $query_radius_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_radius_res[$i]->$key_r)); $query_radius_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_radius_res[$i]->$key_r)); $query_radius_res[$i]->$key_r = $this->filter_bad_words($query_radius_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_radius_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_radius_res[$i]->$key_r = $valkey_r; } } array_push($return, $query_radius_res[$i]); } } return $return; } function getTransitLocationsByTransitName($transit_name, $zipcode = '') { $country = $this->clocale->getCountry(); $transit_name = str_ireplace('*', ' ', $transit_name); $transit_name = remove_nonascii_chars($transit_name); if (!empty($zipcode)) { $city = $this->MdlMisc->getCityByZipcode($zipcode); } else { $city = ''; } $sql = "SELECT * FROM lostandfound.locations "; $sql .= " JOIN lostandfound.locations_type ON location_type_id = location_location_id "; $sql .= " WHERE location_status = 'T' AND location_location_id='34' AND location_transit_system = '{$transit_name}' AND location_country='{$country}' "; if (!empty($city)) { $sql .= " AND location_city = '{$city}' "; } $sql .= " AND location_parent = '0' "; $sql .= " ORDER BY location_name "; $query = $this->db->query($sql); if ($query && $query->num_rows > 0) { $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } return($query_res); } else { return false; } } function getCarRentalLocationsByTypeAndStateAndCity($city, $state, $agency, $country = '') { $country = $this->clocale->getCountry(); $sql = "SELECT * FROM lostandfound.locations WHERE location_status = 'T' AND location_country='{$country}' AND location_car_rental_agency != '' "; if ($state && !empty($state)) $sql .= " AND location_state='{$state}' "; $sql .= " AND location_car_rental_agency='$agency' "; $sql .= " AND location_city = '{$city}' "; $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $sql .= " ORDER BY location_major DESC, location_name "; $query = $this->db->query($sql); if ($query->num_rows > 0) { $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } return $query_res; } else { return false; } } function getLocationsByTypeAndStateAndCity($state, $location_type, $city, $country = '') { $country = $this->clocale->getCountry(); $sql = "SELECT * FROM lostandfound.locations WHERE location_parent=0 AND location_status = 'T' AND location_country='{$country}' "; if ($state && !empty($state)) $sql .= " AND location_state='{$state}' "; $sql .= " AND location_location_id='$location_type' "; $sql .= " AND location_city = '{$city}' "; $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $sql .= " ORDER BY location_major DESC, location_name "; $query = $this->db->query($sql); if ($query->num_rows > 0) { $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } return $query_res; } else { return false; } } function getLocationCities($state, $location_type, $country = '') { $country = $this->clocale->getCountry(); $sql = "SELECT DISTINCT(location_city) as city_name FROM lostandfound.locations WHERE location_status = 'T' AND location_country='{$country}' "; if ($state && !empty($state)) $sql .= " AND location_state='{$state}' "; $sql .= " AND location_location_id='$location_type' "; $sql .= " ORDER BY city_name "; $query = $this->db->query($sql); if ($query->num_rows > 0) { return $query->result(); } else { return false; } } function getUserLocations($userid = 0, $getSubAdmins = 1) { if (empty($userid)) { $userid = $this->auth->uid; } $sql = "SELECT * FROM lostandfound.accounts_locations "; $sql .= " JOIN lostandfound.locations ON account_location_location_id = location_id "; $sql .= " WHERE 1 AND account_location_account_id='{$userid}' "; $sql .= " AND location_parent = '0' "; $sql .= " ORDER BY account_location_id DESC LIMIT 1"; $query = $this->db->query($sql); if ($query->num_rows > 0) { return $query->result(); } else { if ($getSubAdmins) { //now see if the user is there as a subadmin? $sql = "SELECT * FROM lostandfound.accounts_locations_subadmins "; $sql .= " JOIN lostandfound.locations ON account_location_location_id = location_id "; $sql .= " WHERE 1 AND account_location_account_id='{$userid}' AND account_location_subadmin_approved='1' "; $sql .= " AND location_parent = '0' "; $sql .= " ORDER BY account_location_id DESC LIMIT 1"; $query = $this->db->query($sql); if ($query->num_rows > 0) { return $query->result(); } else { return false; } } else { return false; } } } function getLocationSubAdmins($locationid, $approved = 1) { if (empty($locationid)) { return false; } $sql = "SELECT * FROM lostandfound.accounts_locations_subadmins "; $sql .= " JOIN lostandfound.accounts ON account_location_account_id = account_id "; $sql .= " WHERE 1 AND account_location_location_id='{$locationid}' AND account_location_subadmin_approved='{$approved}' "; $sql .= " ORDER BY account_email"; $query = $this->db->query($sql); if ($query->num_rows > 0) { return $query->result(); } else { return false; } } function deleteLocationSubAdmin($accountid, $locationid) { if (empty($accountid) || empty($locationid)) { return false; } $sql = "DELETE FROM lostandfound.accounts_locations_subadmins "; $sql .= " WHERE account_location_account_id='{$accountid}' AND account_location_location_id='{$locationid}' "; $query = $this->db->query($sql); if ($query) { return true; } else { return false; } } function actvateLocationSubAdmin($account, $location) { $accountid = $account->account_id; $locationid = $location->location_id; if (empty($accountid) || empty($locationid)) { return false; } $venue_owner_email = $this->getUserFromLocations($locationid); $sql = "UPDATE lostandfound.accounts_locations_subadmins "; $sql .= " SET account_location_subadmin_approved = '1' "; $sql .= " WHERE account_location_account_id='{$accountid}' AND account_location_location_id='{$locationid}' "; $query = $this->db->query($sql); if ($query) { $subAdminForVenue = array($venue_owner_email->account_email, $location->location_name); $email_to = $account->account_email; $email_login_url = site_url('login'); $email_subject = 'LostAndFound.com Venue Sub-Admin approval : The Internet Lost and Found, Inc.'; $email_body = <<< EOTM You have been approved by {$subAdminForVenue[0]} to be the Sub Admin for {$subAdminForVenue[1]}. Click here to log in to your LostAndFound.com account. Go the MY ACCOUNTS section in the top right corner, {$subAdminForVenue[1]} venue information will be there for you to commence to create and delete listings for {$subAdminForVenue[1]} venue. Thank you. EOTM; $this->load->library('Email'); $this->email->sendmail($email_to, $email_subject, $email_body); return true; } else { return false; } } function newLocationSubAdmin($account, $location, $approved = 1) { $accountid = $account->account_id; $locationid = $location->location_id; $location_owner_account = $this->getUserFromLocations($locationid); if (empty($accountid) || empty($locationid)) { return false; } $unlimited = $this->input->post('accesslevel') ? $this->input->post('accesslevel') : 0; $sql = "INSERT INTO lostandfound.accounts_locations_subadmins "; $sql .= " (account_location_account_id, account_location_location_id, account_location_subadmin_approved, account_location_subadmin_unlimited) "; $sql .= " VALUES ('{$accountid}', '{$locationid}' , '{$approved}' , '{$unlimited}') "; $query = $this->db->query($sql); if ($query) { $this->load->library('Email'); if ($approved) { $subAdminForVenue = array($account->account_email, $location->location_name); $email_unlimited = $unlimited ? 'Unlimited' : 'Limited'; $email_to = $subAdminForVenue[0]; $email_login_url = site_url('login'); $email_subject = 'LostAndFound.com Venue Sub-Admin approval : The Internet Lost and Found, Inc.'; $email_body = <<< EOTM You have been requested to be a Sub Admin by {$location_owner_account->account_email} of {$subAdminForVenue[1]} venue. You are now able to log in under your current username and password and under MY VENUE section have {$email_unlimited} access to add and delete lost and found listings you create for {$subAdminForVenue[1]} venue. If you have received this email in error please contact the venue admin who requested you be added, or cs@LostAndFound.com. Thank you. EOTM; $this->email->sendmail($email_to, $email_subject, $email_body); //now send the venue owner an email $subAdminForVenue = array($location_owner_account->account_email, $location->location_name); $email_unlimited = $unlimited ? 'Unlimited' : 'Limited'; $email_to = $subAdminForVenue[0]; $email_login_url = site_url('login'); $email_subject = 'LostAndFound.com Venue Sub-Admin approval : The Internet Lost and Found, Inc.'; $email_body = <<< EOTM You have requested {$account->account_email} to be the Sub Admin for your venue. Sub Admin will be able to log in under their current username and password and have {$email_unlimited} access to add and delete lost and found listings for {$subAdminForVenue[1]} venue. Thank you. EOTM; $this->email->sendmail($email_to, $email_subject, $email_body); } else { $subAdminForVenue = array($account->account_email, $location->location_name); $email_unlimited = $unlimited ? 'Unlimited' : 'Limited'; $email_to = $subAdminForVenue[0]; $email_login_url = site_url('login'); $email_subject = 'LostAndFound.com Venue Sub-Admin approval : The Internet Lost and Found, Inc.'; $email_body = <<< EOTM You have requested to be a Sub Admin for {$subAdminForVenue[1]} venue. Once you have been approved by Venue Admin, you will receive an email with instructions on how to access your Sub Admin Venue Account. If you have received this email in error please contact cs@LostAndFound.com. Thank you. EOTM; $this->email->sendmail($email_to, $email_subject, $email_body); //now send the venue owner an email $location_owner_account = $this->getUserFromLocations($locationid); $subAdminForVenue = array($location_owner_account->account_email, $location->location_name); $email_unlimited = $unlimited ? 'Unlimited' : 'Limited'; $email_to = $subAdminForVenue[0]; $email_login_url = site_url('account/manage_venue'); $email_subject = 'LostAndFound.com Venue Sub-Admin approval : The Internet Lost and Found, Inc.'; $email_body = <<< EOTM {$account->account_email} has requested to be a Sub Admin for {$subAdminForVenue[1]} venue. You can allow Sub Admin to have Limited or Unlimited access to the listings that are associated with {$subAdminForVenue[1]} venue. Click here to approve or deny and select permission of Sub Admin. Thank you. EOTM; $this->email->sendmail($email_to, $email_subject, $email_body); } return true; } else { return false; } } function getUserFromLocations($locid = 0) { if (empty($locid)) { return false; } $sql = "SELECT * FROM lostandfound.accounts_locations "; $sql .= " JOIN lostandfound.accounts ON account_location_account_id = account_id "; $sql .= " WHERE 1 AND account_location_location_id='{$locid}' "; $query = $this->db->query($sql); if ($query->num_rows > 0) { return $query->row(); } else { return false; } } function locationBelongsToUser($locationid, $userid = 0) { if (empty($userid)) { $userid = $this->auth->uid; } $sql = "SELECT * FROM lostandfound.accounts_locations "; $sql .= " JOIN lostandfound.locations ON account_location_location_id = location_id "; $sql .= " WHERE 1 AND account_location_account_id='{$userid}' "; $sql .= " AND account_location_location_id='{$locationid}' "; $query = $this->db->query($sql); if ($query->num_rows > 0) { return true; } else { return false; } } function getAllLocations($page_num = 1, $country = '') { $page_num = max(1, intval($page_num)); $country = !empty($country) ? $country : $this->clocale->getCountry(); $limit = (($page_num - 1) * $this->config->item('listings_per_page')) . ', ' . $this->config->item('listings_per_page'); $sql_select = "SELECT * "; $sql_select_count = "SELECT COUNT(*) as count "; $sql = " FROM lostandfound.locations WHERE location_status = 'T' AND location_country LIKE '{$country}' "; $sql .= " AND location_parent = '0' "; if ($this->uri->segment(5) && $this->uri->segment(6)) { $sql .= " ORDER BY " . $this->uri->segment(5) . " " . $this->uri->segment(6); } else { $sql .= " ORDER BY location_date DESC, location_name "; } //separate the limit query in a diff var (so we can calc the total rows by executing limit-less query $sql_limit = " LIMIT {$limit}"; $query = $this->db->query($sql_select . $sql . $sql_limit); if ($query->num_rows > 0) { //get total number of rows $query_rows = $this->db->query($sql_select_count . $sql); $total_rows_num = ($query_rows->num_rows > 0) ? $query_rows->row()->count : 0; $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } return array('search_results_num' => $total_rows_num, 'search_results' => $query_res); } else { return false; } } function getLocationsLinkedToAccounts() { $sql = "SELECT * FROM lostandfound.accounts_locations "; $sql .= " JOIN lostandfound.locations ON lostandfound.accounts_locations.account_location_location_id = lostandfound.locations.location_id "; $sql .= " JOIN lostandfound.accounts ON lostandfound.accounts_locations.account_location_account_id = lostandfound.accounts.account_id "; $sql .= " WHERE location_status = 'T' "; $sql .= " AND location_parent = '0' "; $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $query = $this->db->query($sql); if ($query->num_rows > 0) { return $query->result(); } else { return false; } } function getLocationsBySalesPerson($salesperson_name, $status = 'T', $claimed = false) { $salesperson_name = $this->db->escape_str($salesperson_name); $sql = "SELECT * FROM lostandfound.locations "; $sql .= " WHERE 1 "; $sql .= " AND location_parent = '0' "; $sql .= " AND location_salesperson = '{$salesperson_name}' "; if ($claimed) { $sql .= " AND location_email_temp != '' AND location_email_temp IS NOT NULL "; } else { $sql .= " AND location_status = '{$status}' "; } $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $sql .= " ORDER BY location_id DESC"; $query = $this->db->query($sql); if ($query->num_rows > 0) { $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } return $query_res; } else { return false; } } function getAccountLocations($account_aid, $country = '') { $page_num = 1; $country = !empty($country) ? $country : $this->clocale->getCountry(); $account_id = $this->MdlUsers->getAccountDetailsByAID($account_aid)->account_id; $account_locations = $this->getUserLocations($account_id); $limit = "0, 50000"; $sql_select = "SELECT * "; $sql_select_count = "SELECT COUNT(*) as count "; $sql = " FROM lostandfound.locations WHERE 1 AND location_country LIKE '{$country}' "; $sql .= " AND location_parent = '0' "; if ($account_id) { $sql .= " AND ( "; foreach ($account_locations as $val_al) { $sql .= " location_id = '{$val_al->account_location_location_id}' OR "; } $sql = substr($sql, 0, strlen($sql) - 3); $sql .= " ) "; } else { return false; } $sql .= " ORDER BY location_date DESC, location_name "; //separate the limit query in a diff var (so we can calc the total rows by executing limit-less query $sql_limit = " LIMIT {$limit}"; $query = $this->db->query($sql_select . $sql . $sql_limit); if ($query->num_rows > 0) { //get total number of rows $query_rows = $this->db->query($sql_select_count . $sql); $total_rows_num = ($query_rows->num_rows > 0) ? $query_rows->row()->count : 0; $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } return array('search_results_num' => $total_rows_num, 'search_results' => $query_res); } else { return false; } } function getPendingLocations($page_num = 1, $country = '') { $page_num = max(1, intval($page_num)); $country = !empty($country) ? $country : $this->clocale->getCountry(); $limit = (($page_num - 1) * $this->config->item('listings_per_page')) . ', ' . $this->config->item('listings_per_page'); $sql_select = "SELECT * "; $sql_select_count = "SELECT COUNT(*) as count "; $sql = " FROM lostandfound.locations WHERE location_status != 'T' "; $sql .= " AND location_country LIKE '{$country}' "; $sql .= " AND location_parent = '0' "; if ($this->uri->segment(5) && $this->uri->segment(6)) { $sql .= " ORDER BY " . $this->uri->segment(5) . " " . $this->uri->segment(6); } else { $sql .= " ORDER BY location_date DESC, location_name "; } //separate the limit query in a diff var (so we can calc the total rows by executing limit-less query $sql_limit = " LIMIT {$limit}"; $query = $this->db->query($sql_select . $sql . $sql_limit); if ($query->num_rows > 0) { //get total number of rows $query_rows = $this->db->query($sql_select_count . $sql); $total_rows_num = ($query_rows->num_rows > 0) ? $query_rows->row()->count : 0; $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } return array('search_results_num' => $total_rows_num, 'search_results' => $query_res); } else { return false; } } function getClaimedLocations($page_num = 1, $country = '') { $page_num = max(1, intval($page_num)); $country = !empty($country) ? $country : $this->clocale->getCountry(); $limit = (($page_num - 1) * $this->config->item('listings_per_page')) . ', ' . $this->config->item('listings_per_page'); $sql_select = "SELECT * "; $sql_select_count = "SELECT COUNT(*) as count "; $sql = " FROM lostandfound.locations WHERE location_email_temp != '' AND location_email_temp IS NOT NULL "; $sql .= " AND location_country LIKE '{$country}' "; $sql .= " AND location_parent = '0' "; if ($this->uri->segment(5) && $this->uri->segment(6)) { $sql .= " ORDER BY " . $this->uri->segment(5) . " " . $this->uri->segment(6); } else { $sql .= " ORDER BY location_date DESC, location_name "; } //separate the limit query in a diff var (so we can calc the total rows by executing limit-less query $sql_limit = " LIMIT {$limit}"; $query = $this->db->query($sql_select . $sql . $sql_limit); if ($query->num_rows > 0) { //get total number of rows $query_rows = $this->db->query($sql_select_count . $sql); $total_rows_num = ($query_rows->num_rows > 0) ? $query_rows->row()->count : 0; $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } return array('search_results_num' => $total_rows_num, 'search_results' => $query_res); } else { return false; } } function getUnverifiedLocations($page_num = 1, $country = '') { $page_num = max(1, intval($page_num)); $country = !empty($country) ? $country : $this->clocale->getCountry(); $limit = (($page_num - 1) * $this->config->item('listings_per_page')) . ', ' . $this->config->item('listings_per_page'); $sql_select = "SELECT * "; $sql_select_count = "SELECT COUNT(*) as count "; $sql = " FROM lostandfound.locations WHERE location_edited = '1' AND location_status = 'F' "; $sql .= " AND location_country LIKE '{$country}' "; $sql .= " AND location_parent = '0' "; $sql .= " ORDER BY location_date DESC, location_name "; //separate the limit query in a diff var (so we can calc the total rows by executing limit-less query $sql_limit = " LIMIT {$limit}"; $query = $this->db->query($sql_select . $sql . $sql_limit); if ($query->num_rows > 0) { //get total number of rows $query_rows = $this->db->query($sql_select_count . $sql); $total_rows_num = ($query_rows->num_rows > 0) ? $query_rows->row()->count : 0; $query_res = $query->result(); for ($i = 0; $i < count($query_res); $i++) { foreach ($query_res[$i] as $key_r => $val_r) { $query_res[$i]->$key_r = remove_nonascii_chars($query_res[$i]->$key_r); $query_res[$i]->$key_r = nl2br(str_ireplace('\n', '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $query_res[$i]->$key_r)); $query_res[$i]->$key_r = $this->filter_bad_words($query_res[$i]->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $query_res[$i]->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $query_res[$i]->$key_r = $valkey_r; } } } return array('search_results_num' => $total_rows_num, 'search_results' => $query_res); } else { return false; } } function getGetVenueAutoApprove() { $sql = " SELECT * FROM lostandfound.settings "; $sql .= " WHERE name='venue_auto_approve' "; $query = $this->db->query($sql); if ($query->num_rows > 0) { $row = $query->row(); $row = $row->value; if (intval($row) > 0) { return true; } else { return false; } } else { return false; } } function toggleVenueAutoApprove() { $sql = " UPDATE lostandfound.settings set value = !value "; $sql .= " WHERE name='venue_auto_approve' "; $query = $this->db->query($sql); return true; } function changeLocationStatus($location_id, $status = 'F', $send_mail = true) { $location_details = $this->getLocationDetails($location_id); $user_details = $this->MdlMisc->getUserDetailsFromLocation($location_id); $sql = "UPDATE lostandfound.locations SET location_status = ? WHERE location_id = ?"; $query = $this->db->query($sql, array($status, $location_id)); //if the location is being deactivated, restore the original data from locations_saved if ($status == 'F') { $saved_location_details = $this->getSavedLocationDetails($location_id); if ($saved_location_details) { $sql_update_at = "UPDATE lostandfound.locations SET "; foreach ($saved_location_details as $val_ld_key => $val_ld_val) { if ($val_ld_key == 'location_id') continue; $sql_update_at .= $val_ld_key . ' = ' . $this->db->escape($val_ld_val) . ','; } $sql_update_at = substr($sql_update_at, 0, strlen($sql_update_at) - 1); $sql_update_at .= ' WHERE location_id = ' . $this->db->escape($location_id); $this->db->query($sql_update_at); } //make sure deactivated loctions dont have the location_email_temp set $this->db->query("UPDATE lostandfound.locations SET location_email_temp = '' WHERE location_id = " . $this->db->escape($location_id)); //delete the info in locations_saved $this->db->query("DELETE FROM locations_saved WHERE location_id = " . $this->db->escape($location_id)); //delete any account-location linking $this->db->query("DELETE FROM accounts_locations WHERE account_location_location_id = " . $this->db->escape($location_id)); //delete any venue relationships $this->db->query("DELETE FROM venue_relationships WHERE venue_relationship_parent = " . $this->db->escape($location_id) . " OR venue_relationship_child = " . $this->db->escape($location_id)); //now update the Sphinx Index by SphinxQL $this->sphinxQLAddUpdate('locations', $location_id); } $this->updateChildLocations($location_id); //send the location status changed email if ($query) { $email_to = $user_details->account_email; $email_subject = 'Your Venue Status has been changed : The Internet Lost and Found, Inc.'; $email_login_url = site_url('login'); //$email_location_url = site_url('venues/myilf/' . $location_id); $email_location_url = site_url(!empty($location_details->location_apb) ? $location_details->location_apb : $location_details->location_id); $email_location_status = $status == 'F' ? 'Deactivated.' : 'Activated.'; if ($status == 'T') { $email_location_venuepagelink = <<< EOTM It is very important to attach the following link on your website. It is the website linking code that will take your patrons DIRECTLY to your Venue Page - the page where YOUR content (lost and found info) is displayed. Please add this hyperlink to the appropriate place on your website. EOTM; } $email_body = <<< EOTM The status of your Venue registered at LostAndFound.com has been changed. Below mentioned are the details: Venue Number: {$location_details->location_id} Please keep this for your records. You are able to link your venue to other establishments on Lost and Found using your venue number. Location Name: {$location_details->location_name} Location Status: {$email_location_status} Your Login URL : {$email_login_url} Your MyILF URL : {$email_location_url} {$email_location_venuepagelink} Thank you. EOTM; $this->load->library('Email'); if ($send_mail) $this->email->sendmail($email_to, $email_subject, $email_body); return true; } else { return false; } } function totalLocationsNum($country = '%') { $sql = "SELECT COUNT(*) as count FROM lostandfound.locations WHERE location_country LIKE '{$country}' AND location_status = 'T' "; $sql .= " AND location_parent = '0' "; $sql .= " ORDER BY location_date DESC"; $query = $this->db->query($sql); if ($query->num_rows > 0) return $query->row()->count; else return false; } function managedLocationsNum($country = '%') { $res = $this->searchLocations($page_num, $country, truettr_location_state', array(floatval(sprintf("%u", abs(crc32(strtolower($var['search_state']))))))); } } if ($this->input->post('search_location_type') != '36') { if ($country != '%') { $cl->SetFilter('attr_location_country', array(floatval(sprintf("%u", abs(crc32(strtolower($country))))))); } } /* $geo_coords = $this->getZipCodeCoords($var['search_zipcode']); $geo_latitude = deg2rad($geo_coords->zip_code_latitude); $geo_longitude = deg2rad($geo_coords->zip_code_longitude); if(!empty($geo_latitude) && !empty($geo_longitude)){ $geo_radius = 50000 * 1.67; //in meters $cl->SetFilterFloatRange('@geodist', 0.0, $geo_radius); $cl->SetGeoAnchor('attr_latitude', 'attr_longitude', $geo_latitude, $geo_longitude); $cl->SetSortMode(SPH_SORT_EXTENDED, "attr_location_account_linked DESC, @geodist ASC, @relevance DESC, attr_location_date DESC"); }else{ if (!empty($var['search_zipcode']) && $var['search_zipcode'] != 'Enter Post Code') { $cl->SetFilter('attr_location_zipcode', array(floatval(sprintf("%u", crc32(strtolower($var['search_zipcode'])))))); } $cl->SetSortMode(SPH_SORT_EXTENDED, "attr_location_account_linked DESC,@relevance DESC, attr_location_date DESC"); } */ $attr_location_zipcode = array(); if (!empty($var['search_zipcode']) && $var['search_zipcode'] != 'Enter Post Code') { array_push($attr_location_zipcode, floatval(sprintf("%u", crc32(strtolower($var['search_zipcode']))))); } $geo_zipcodes_in_radius = $this->MdlMisc->getZipCodesRadiusSearch($var['search_zipcode'], $radius, true); if (is_array($geo_zipcodes_in_radius) && !empty($geo_zipcodes_in_radius)) { foreach ($geo_zipcodes_in_radius as $val_gzir) { array_push($attr_location_zipcode, floatval(sprintf("%u", crc32(strtolower($val_gzir))))); } } if (is_array($attr_location_zipcode) && !empty($attr_location_zipcode)) { $cl->SetFilter('attr_location_zipcode', $attr_location_zipcode); $cl->SetSortMode(SPH_SORT_EXTENDED, "attr_location_account_linked DESC,@relevance DESC, attr_location_date DESC"); } else { $cl->SetSortMode(SPH_SORT_EXTENDED, "attr_location_account_linked DESC,@relevance DESC, attr_location_date DESC"); } $curl_res = $cl->Query($search_keyword, $index); if (is_array($curl_res) && count($curl_res) > 1 && (is_array($curl_res['matches']) && count($curl_res['matches']) >= 1)) { foreach ($curl_res['matches'] as $val_crm) { array_push($search_locations_ids, $val_crm['id']); } } if (!empty($var['search_location_type_id']) && $var['search_location_type_id'] != 25) { $return_res = $this->getResultSetFromLocationIds($search_locations_ids, ($var['search_location_type_id'] == 47 || $var['search_location_type_id'] == 38) ? true : false); } else { $return_res = $this->getResultSetFromLocationIdsForAJAX($search_locations_ids, ($var['search_location_type_id'] == 47 || $var['search_location_type_id'] == 38) ? true : false); } $return_res = $return_res['search_results']; return $return_res; } function searchLocationsForAJAXNonSphinx($var = array(), $page_num = 1, $country = '') { $country = !empty($country) ? $country : $this->clocale->getCountry(); $sql = "SELECT location_id, location_name, location_address, location_city, location_transit_line, location_transit_system, location_car_rental_agency, location_location_id , location_venue_id, location_major FROM lostandfound.locations WHERE 1 "; $sql .= " AND location_status = 'T' "; if (!empty($var['search_keyword'])) { $sql .= " AND location_name LIKE '%{$var['search_keyword']}%' "; } if (!empty($var['search_location_type'])) { $sql .= " AND location_location_id = '{$var['search_location_type']}' "; } if (!empty($var['search_city'])) { $sql .= " AND location_city = '{$var['search_city']}' "; } elseif (!empty($var['search_state'])) { $sql .= " AND location_state = '{$var['search_state']}' "; } if ($country != '%') { $sql .= " AND location_country = '{$country}' "; } $sql .= " ORDER BY location_date DESC "; $query = $this->db->query($sql); if ($query->num_rows > 0) { $return_res = $query->result(); } else { $return_res = array(); } return($return_res); } function quickSearchLocations($page_num = 1, $country = '') { $page_num = max(1, intval($page_num)); $country = !empty($country) ? $country : $this->clocale->getCountry(); $limit = (($page_num - 1) * $this->config->item('listings_per_page')) . ', ' . $this->config->item('listings_per_page'); $sql_select = "SELECT * "; $sql_select_count = "SELECT COUNT(*) as count "; $sql = " FROM lostandfound.locations JOIN lostandfound.locations_type ON location_type_id=location_location_id WHERE 1 "; if ($this->input->post('search_location_id')) { $sql .= " AND location_id = " . $this->db->escape($this->input->post('search_location_id')) . " "; } else { $sql .= " AND location_parent = '0' "; } if ($this->input->post('search_location_email')) { $sql .= " AND LOWER(location_email) LIKE '%" . $this->db->escape_like_str(strtolower($this->input->post('search_location_email'))) . "%' "; } if ($this->input->post('search_location_phone')) { $sql .= " AND location_phone LIKE '%" . $this->db->escape_like_str($this->input->post('search_location_phone')) . "%' "; } if ($this->input->post('search_city')) { $sql .= " AND LOWER(location_city) LIKE '%" . strtolower($this->db->escape_str($this->input->post('search_city'))) . "%'"; } if ($this->input->post('search_state')) { $sql .= " AND LOWER(location_state) LIKE '%" . strtolower($this->db->escape_str($this->input->post('search_state'))) . "%'"; } if ($this->input->post('search_zipcode') && $this->input->post('search_zipcode') != 'Enter Post Code') { $sql .= " AND location_zipcode=" . $this->db->escape($this->input->post('search_zipcode')); } if ($this->input->post('search_location_status')) { $sql .= " AND location_status = " . $this->db->escape($this->input->post('search_location_status')); } $sql .= " AND location_country LIKE '{$country}' "; $sql .= " ORDER BY location_major DESC, location_date DESC "; //separate the limit query in a diff var (so we can calc the total rows by executing limit-less query $sql_limit = " LIMIT {$limit}"; $query = $this->db->query($sql_select . $sql . $sql_limit); if ($query->num_rows > 0) { //get total number of rows $query_rows = $this->db->query($sql_select_count . $sql); $total_rows_num = ($query_rows->num_rows > 0) ? $query_rows->row()->count : 0; return array('search_results_num' => $total_rows_num, 'search_results' => $query->result()); } else { return false; } } function searchLocations_old($page_num = 1, $country = '') { $page_num = max(1, intval($page_num)); $country = $this->clocale->getCountry(); $limit = (($page_num - 1) * $this->config->item('listings_per_page')) . ', ' . $this->config->item('listings_per_page'); $sql_select = "SELECT * "; $sql_select_match = ""; $sql_select_count = "SELECT COUNT(*) as count "; $sql = " FROM lostandfound.locations JOIN lostandfound.locations_type ON location_type_id=location_location_id WHERE 1 "; //if the keyword is only three letter and there exists an airport for that, let's search for only the airport $search_keyword = $this->input->post('search_keyword'); if (!empty($search_keyword) && strlen($search_keyword) == 3) { $query_airport_exists = $this->db->query("SELECT location_id FROM lostandfound.locations WHERE location_venue_id=" . $this->db->escape($this->input->post('search_keyword')) . " AND location_location_id=21"); if ($query_airport_exists->num_rows > 0) { $sql .= " AND location_venue_id = " . $this->db->escape($this->input->post('search_keyword')) . " AND location_location_id=21 "; } } elseif (!empty($search_keyword) && strlen($search_keyword) != 3) { /* $keyword = "'%" . $this->db->escape_str($this->input->post('search_keyword')) . "%'"; $sql .= " AND ( "; $sql .= " location_name LIKE {$keyword}"; $sql .= " OR location_venue_id LIKE {$keyword}"; //$sql .= " OR location_address LIKE {$keyword}"; $sql .= " OR location_city LIKE {$keyword}"; $sql .= " OR location_state LIKE {$keyword}"; //$sql .= " OR location_link LIKE {$keyword}"; //$sql .= " OR location_description LIKE {$keyword}"; $sql .= " )"; */ $keyword = $this->db->escape_str($this->input->post('search_keyword')); $sql .= " AND {$this->match_location_sql} AGAINST ('>{$keyword}')"; $sql_select_match .= " ,({$this->match_location_sql} AGAINST ('{$keyword}')) as match_rel "; } if ($this->input->post('search_location_name')) $sql .= " AND LOWER(location_name) LIKE '%" . $this->db->escape_like_str(strtolower($this->input->post('search_location_name'))) . "%' "; if ($this->input->post('search_location_phone')) $sql .= " AND location_phone LIKE '%" . $this->db->escape_like_str($this->input->post('search_location_phone')) . "%' "; if ($this->input->post('search_location_address')) $sql .= " AND LOWER(location_address) LIKE '%" . $this->db->escape_like_str(strtolower($this->input->post('search_location_address'))) . "%' "; if ($this->input->post('search_location_type')) $sql .= " AND location_location_id=" . $this->db->escape($this->input->post('search_location_type')); if ($this->input->post('search_city')) $sql .= " AND LOWER(location_city) LIKE '%" . strtolower($this->db->escape_str($this->input->post('search_city'))) . "%'"; if ($this->input->post('search_state')) $sql .= " AND LOWER(location_state) LIKE '%" . strtolower($this->db->escape_str($this->input->post('search_state'))) . "%'"; if ($this->input->post('search_zipcode') && $this->input->post('search_zipcode') != 'Enter Post Code') $sql .= " AND location_zipcode=" . $this->db->escape($this->input->post('search_zipcode')); if ($this->input->post('local_results_only') && $this->input->post('local_results_only') == 'local_results_only') { $search_local_zipcode = $this->clocale->getZipCode(); if (!empty($search_local_zipcode)) { $search_local_radius_zipcodes = $this->MdlMisc->getZipCodesRadiusSearch($search_local_zipcode, 50); $sql .= " AND (location_zipcode='{$search_local_zipcode}' "; foreach ($search_local_radius_zipcodes as $val_rz) { $sql .= " OR location_zipcode='{$val_rz}' "; } $sql .= " ) "; } } if ($this->input->post('search_location_status')) { $sql .= " AND location_status = " . $this->db->escape($this->input->post('search_location_status')); } $sql .= " AND location_country='{$country}' "; $sql .= " ORDER BY location_major DESC, match_rel DESC "; //$sql .= " ORDER BY location_name, location_city, location_state DESC "; if (empty($sql_select_match)) { $sql_select_match .= " , location_date as match_rel "; } //separate the limit query in a diff var (so we can calc the total rows by executing limit-less query $sql_limit = " LIMIT {$limit}"; $query = $this->db->query($sql_select . $sql_select_match . $sql . $sql_limit); if ($query->num_rows > 0) { //get total number of rows $query_rows = $this->db->query($sql_select_count . $sql_select_match . $sql); $total_rows_num = ($query_rows->num_rows > 0) ? $query_rows->row()->count : 0; return array('search_results_num' => $total_rows_num, 'search_results' => $query->result()); } else { return false; } } function getPendingListings($page_num = 1) { $page_num = max(1, intval($page_num)); $limit = (($page_num - 1) * $this->config->item('listings_per_page')) . ', ' . $this->config->item('listings_per_page'); $sql_select = "SELECT * "; $sql_select_count = "SELECT COUNT(*) as count "; $sql = " FROM lostandfound.listings JOIN lostandfound.categories ON category_id=listing_category WHERE 1 AND listing_parent=0 AND listing_status='F' "; $sql .= " ORDER BY listing_date DESC "; //separate the limit query in a diff var (so we can calc the total rows by executing limit-less query $sql_limit = " LIMIT {$limit}"; $query = $this->db->query($sql_select . $sql . $sql_limit); if ($query->num_rows > 0) { //get total number of rows $query_rows = $this->db->query($sql_select_count . $sql); $total_rows_num = ($query_rows->num_rows > 0) ? $query_rows->row()->count : 0; $result = $query->result(); for ($res_i = 0; $res_i < count($result); $res_i++) { foreach ($result[$res_i] as $key_r => $val_r) { $result[$res_i]->$key_r = remove_nonascii_chars($result[$res_i]->$key_r); $result[$res_i]->$key_r = $this->filter_bad_words($result[$res_i]->$key_r); } } return array('search_results_num' => $total_rows_num, 'search_results' => $result); } else { return false; } } function getListingDetails($id) { $sql = " SELECT * FROM lostandfound.listings LEFT JOIN lostandfound.categories ON category_id=listing_category WHERE listing_id = ? "; $query = $this->db->query($sql, $id); if ($query->num_rows > 0) { $result = $query->row(); if(strtolower($result->listing_brand) == 'unknown brand'){ $result->listing_brand = ''; } foreach ($result as $key_r => $val_r) { $result->$key_r = remove_nonascii_chars($result->$key_r); $result->$key_r = nl2br(str_ireplace('\n', '
', $result->$key_r)); $result->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $result->$key_r)); $result->$key_r = $this->filter_bad_words($result->$key_r); } return $result; } else { return false; } } function getLocationDetails($id, $dojoin = true) { if (empty($id)) return false; $sql = " SELECT * FROM lostandfound.locations "; $sql .= ($dojoin ? 'JOIN locations_type ON location_location_id = location_type_id' : ''); $sql .= " WHERE location_id = ? "; $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $query = $this->db->query($sql, $id); if ($query->num_rows > 0) { $result = $query->row(); foreach ($result as $key_r => $val_r) { $result->$key_r = remove_nonascii_chars($result->$key_r); $result->$key_r = nl2br(str_ireplace('\n', '', $result->$key_r)); $result->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $result->$key_r)); $result->$key_r = $this->filter_bad_words($result->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $result->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $result->$key_r = $valkey_r; } } return $result; } else { return false; } } function getLocationAreas($lid){ $sql = "SELECT * FROM lostandfound.locations_areas WHERE location_area_location_id = $lid"; $query = $this->db->query($sql); if ($query->num_rows > 0) { $result = $query->result(); return $result; } else { return false; } } function getLocationArea($lid){ $sql = "SELECT * FROM lostandfound.locations_areas WHERE location_area_id = $lid"; $query = $this->db->query($sql); if ($query->num_rows > 0) { $result = $query->row(); return $result; } else { return false; } } function addLocationArea($lid, $title, $info){ $sql = "INSERT INTO lostandfound.locations_areas (location_area_location_id, location_area_title, location_area_information)"; $sql .= " VALUES (?, ?, ?)"; $query = $this->db->query($sql, array($lid, $title, $info)); if ($query) { return true; } else { return false; } } function deleteLocationArea($lid){ $sql = "DELETE FROM lostandfound.locations_areas WHERE location_area_id = $lid"; $query = $this->db->query($sql); if ($query) { return true; } else { return false; } } function defaultLocationArea($lid){ $l_area_details = $this->getLocationArea($lid); if(isset($l_area_details->location_area_location_id) AND !empty($l_area_details->location_area_location_id)){ $this->db->query("UPDATE lostandfound.locations_areas SET location_area_default = 0 WHERE location_area_location_id = {$l_area_details->location_area_location_id}"); } $sql = "UPDATE lostandfound.locations_areas SET location_area_default = 1 WHERE location_area_id = $lid"; $query = $this->db->query($sql); if ($query) { return true; } else { return false; } } function getVenueSalesPersons() { $sales_persons = array(); $sql = " SELECT DISTINCT(location_salesperson) as location_salesperson FROM lostandfound.locations WHERE 1 "; $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $sql .= " ORDER BY location_salesperson"; $query = $this->db->query($sql, $id); if ($query->num_rows > 0) { $result = $query->result(); foreach ($result as $val) { if (empty($val->location_salesperson)) { continue; } array_push($sales_persons, $val->location_salesperson); } return $sales_persons; } else { return false; } } function searchVenueSalesPersons($name) { $sales_persons = array(); $name = $this->db->escape_like_str($name); $sql = " SELECT DISTINCT(location_salesperson) as location_salesperson FROM lostandfound.locations "; $sql .= " WHERE location_salesperson LIKE '%{$name}%' "; $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $sql .= " ORDER BY location_salesperson"; $query = $this->db->query($sql, $id); if ($query->num_rows > 0) { $result = $query->result(); foreach ($result as $val) { if (empty($val->location_salesperson)) { continue; } array_push($sales_persons, $val->location_salesperson); } return $sales_persons; } else { return false; } } function getSavedLocationDetails($id) { if (empty($id)) return false; $sql = " SELECT * FROM lostandfound.locations_saved WHERE location_id = ? "; $query = $this->db->query($sql, $id); if ($query->num_rows > 0) { $result = $query->row(); foreach ($result as $key_r => $val_r) { $result->$key_r = remove_nonascii_chars($result->$key_r); $result->$key_r = nl2br(str_ireplace('\n', '', $result->$key_r)); $result->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $result->$key_r)); $result->$key_r = $this->filter_bad_words($result->$key_r); } return $result; } else { return false; } } function getLocationDetailsByName($name) { if (empty($name)) return false; $sql = " SELECT * FROM lostandfound.locations WHERE location_name LIKE ? AND location_parent = '0' "; $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $query = $this->db->query($sql, $name); if ($query->num_rows > 0) { $result = $query->row(); foreach ($result as $key_r => $val_r) { $result->$key_r = remove_nonascii_chars($result->$key_r); $result->$key_r = nl2br(str_ireplace('\n', '', $result->$key_r)); $result->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $result->$key_r)); $result->$key_r = $this->filter_bad_words($result->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $result->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $result->$key_r = $valkey_r; } } return $result; } else { return false; } } function getLocationURL($id, $dontshowparent = true) { if (empty($id)) { return false; } $id = $this->db->escape_str($id); $sql = "SELECT * FROM lostandfound.locations WHERE ( "; if (preg_match("/[a-zA-Z]/", $id)) { $sql .= " location_apb LIKE '{$id}' OR location_apb2 LIKE '{$id}' OR location_autourl LIKE '{$id}' "; } else { $sql .= " location_id = '{$id}' "; } if ($field != 'location_id' && strlen($id) == 3) { $sql .= " OR location_venue_id LIKE '{$id}' "; } $sql .= " ) "; if ($dontshowparent) { $sql .= " AND location_parent = '0' "; } $sql .= " AND location_country LIKE " . $this->db->escape($this->clocale->getCountry()); $query = $this->db->query($sql); if ($query->num_rows > 0) { $result = $query->row(); foreach ($result as $key_r => $val_r) { $result->$key_r = remove_nonascii_chars($result->$key_r); $result->$key_r = nl2br(str_ireplace('\n', '', $result->$key_r)); $result->$key_r = nl2br(str_ireplace(array('\\', '"', '\''), '', $result->$key_r)); $result->$key_r = $this->filter_bad_words($result->$key_r); if ($key_r == 'location_zipcode' && stristr($result->location_country, 'united states')) { $result->$key_r = str_pad($result->$key_r, 5, '0', STR_PAD_LEFT); } if ($key_r == 'location_name' || $key_r == 'location_city') { $valkey_r = explode('-', $result->$key_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('-', $valkey_r); $valkey_r = explode('/', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('/', $valkey_r); $valkey_r = explode('(', $valkey_r); for ($j = 0; $j < count($valkey_r); $j++) { $valkey_r[$j] = ucwords($valkey_r[$j]); } $valkey_r = implode('(', $valkey_r); $result->$key_r = $valkey_r; } } return $result; } else { return false; } } function locationHasOwner($loc_id) { $loc_details = $this->getLocationDetails($loc_id); if (!empty($loc_details->location_parent)) $loc_id = $loc_details->location_parent; $sql = "SELECT * FROM lostandfound.accounts_locations JOIN lostandfound.locations ON account_location_location_id = location_id WHERE location_id = " . $this->db->escape($loc_id); $query = $this->db->query($sql); if ($query->num_rows > 0) return $query->row(); else return false; } function getLocationTypeDetails($id) { if (empty($id)) return false; $sql = " SELECT * FROM lostandfound.locations_type WHERE location_type_id = ? AND location_type_show = 1"; $query = $this->db->query($sql, $id); if ($query->num_rows > 0) return $query->row(); else return false; } function getAccountListingContactAttempts($listing_id, $account_id = '') { if (empty($account_id)) { $account_id = $this->auth->uid; } $sql = "SELECT * FROM accounts_contact_attempts "; $sql .= " WHERE 1 "; $sql .= " AND accounts_contact_attempt_account_id = '$account_id' "; $sql .= " AND accounts_contact_attempt_listing_id = '$listing_id' "; $query = $this->db->query($sql); if ($query->num_rows > 0) return true; else return false; } function newLostListing($authed) { $listing_country = $this->input->post('hn_country') ? $this->input->post('hn_country') : $this->clocale->getCountry(); if (!$authed) { //create the user is not $authed $account_id = $this->MdlUsers->createNewUser(array($this->input->post('contactEmailAddress'), $this->input->post('password'), $this->input->post('contactPhoneNumber'))); } else { if ($this->input->post('contactEmailAddressProxy')) { $account_id = $this->MdlUsers->createNewUser(array($this->input->post('contactEmailAddressProxy'), rand(99999, 999999), $this->input->post('contactPhoneProxy'))); $account_proxy_venue = $this->input->post('locationVenueID') ? $this->input->post('locationVenueID') : ''; if (!empty($account_proxy_venue)) { $account_proxy_venue_details = $this->getLocationDetails($account_proxy_venue); $account_proxy_email_msg = "location_id)) . "\">" . (ucwords($account_proxy_venue_details->location_name)) . " created a listing on your behalf."; } } else { $account_id = $this->auth->uid; } } //fetch the account_details $account_details = $this->MdlUsers->getAccountDetails($account_id); $account_aid = $account_details->account_aid; $account_email = $account_details->account_email; if ($this->input->post('rf_date')) { $date_lost_form = strtotime($this->input->post('rf_date')); } else { $date_lost_form = ($this->input->post('lostDateYear') && $this->input->post('lostDateMonth') && $this->input->post('lostDateDay')) ? mktime(0, 0, 0, $this->input->post('lostDateMonth'), $this->input->post('lostDateDay'), $this->input->post('lostDateYear')) : time(); } if ($date_lost_form > time()) { $date = date('Y-m-d H:i:s'); } else { $date = date('Y-m-d H:i:s', $date_lost_form); } $date_now = date('Y-m-d 00:00:00'); $zipcodeinfo = $this->MdlMisc->getZipCodeInfoByZipcode($this->input->post('zipcode')); //create the arrays $array_fields = array( 'listing_sku' => $account_aid . '_' . intval(microtime(true)), 'listing_acct_id' => $account_aid, 'listing_kind' => 'Lost', 'listing_category' => $this->input->post('search_subcategory') ? $this->db->escape_str($this->input->post('search_subcategory')) : $this->db->escape_str($this->input->post('category')), 'listing_venue_id' => $this->input->post('locationVenueID') ? $this->db->escape_str($this->input->post('locationVenueID')) : '', 'listing_title' => $this->db->escape_str($this->input->post('title')), 'listing_description' => $this->db->escape_str($this->input->post('description') . ($this->input->post('listingDescription') ? "\n\n" . $this->db->escape_str($this->input->post('listingDescription')) : '')), 'listing_gender' => $this->db->escape_str((($this->input->post('gender') ? $this->input->post('gender') : 'Unknown'))), 'listing_date' => $date, 'listing_date_created' => $date_now, 'listing_location' => $this->db->escape_str($this->input->post('locationDescription') . ($this->input->post('locationDetails') ? "\n\n" . $this->db->escape_str($this->input->post('locationDetails')) : '')), 'listing_location_type' => $this->db->escape_str($this->input->post('locationType')), 'listing_city' => $this->db->escape_str(!empty($zipcodeinfo->zip_code_city) ? $zipcodeinfo->zip_code_city : $this->input->post('city')), 'listing_state' => $this->db->escape_str(!empty($zipcodeinfo->zip_code_state) ? $zipcodeinfo->zip_code_state : $this->input->post('state')), 'listing_country' => $listing_country, 'listing_zipcode' => $this->db->escape_str(!empty($zipcodeinfo->zip_code_zipcode) ? $zipcodeinfo->zip_code_zipcode : $this->input->post('zipcode')), 'listing_departure_id' => '', 'listing_departure_name' => '', 'listing_departure_number' => '', 'listing_departure_country' => '', 'listing_departure_state' => '', 'listing_departure_city' => '', 'listing_departure_zipcode' => '', 'listing_departure_location_type' => '', 'listing_layover_id' => '', 'listing_layover_name' => '', 'listing_layover_number' => '', 'listing_layover_country' => '', 'listing_layover_state' => '', 'listing_layover_city' => '', 'listing_layover_zipcode' => '', 'listing_layover_location_type' => '', 'listing_arrival_id' => '', 'listing_arrival_name' => '', 'listing_arrival_number' => '', 'listing_arrival_country' => '', 'listing_arrival_state' => '', 'listing_arrival_city' => '', 'listing_arrival_zipcode' => '', 'listing_arrival_location_type' => '', 'listing_departure_airport' => '', 'listing_layover_airport' => '', 'listing_arrival_airport' => '', 'listing_status' => 'T', 'listing_latitude' => $this->input->post('hn_latitude'), 'listing_longitude' => $this->input->post('hn_longitude') ); //airport module if ($this->input->post('TC2_departureAirport')) { $array_fields['listing_location_type'] = $this->MdlMisc->getLocationTypeIdByName('Airport'); $dapt_departure = $this->MdlMisc->getLocation($this->input->post('TC2_departureAirport')); $dapt_layover = $this->MdlMisc->getLocation($this->input->post('TC2_layoverAirport')); $dapt_arrival = $this->MdlMisc->getLocation($this->input->post('TC2_arrivalAirport')); $array_fields['listing_city'] = $dapt_departure->location_city; $array_fields['listing_state'] = $dapt_departure->location_state; $array_fields['listing_zipcode'] = $dapt_departure->location_zipcode; $array_fields['listing_country'] = $dapt_departure->location_country; $array_fields['listing_location_type'] = $dapt_departure->location_location_id; $array_fields['listing_departure_id'] = $dapt_departure->location_id; $array_fields['listing_departure_name'] = $dapt_departure->location_name; $array_fields['listing_departure_country'] = $dapt_departure->location_country; $array_fields['listing_departure_state'] = $dapt_departure->location_state; $array_fields['listing_departure_city'] = $dapt_departure->location_city; $array_fields['listing_departure_zipcode'] = $dapt_departure->location_zipcode; $array_fields['listing_departure_location_type'] = $dapt_departure->location_location_id; $array_fields['listing_departure_number'] = $this->input->post('TC2_airline1_flightnum'); $array_fields['listing_departure_airport'] = $this->input->post('TC2_airline1'); $array_fields['listing_layover_id'] = $dapt_layover->location_id; $array_fields['listing_layover_name'] = $dapt_layover->location_name; $array_fields['listing_layover_country'] = $dapt_layover->location_country; $array_fields['listing_layover_state'] = $dapt_layover->location_state; $array_fields['listing_layover_city'] = $dapt_layover->location_city; $array_fields['listing_layover_zipcode'] = $dapt_layover->location_zipcode; $array_fields['listing_layover_location_type'] = $dapt_layover->location_location_id; $array_fields['listing_layover_number'] = $this->input->post('TC2_airline2_flightnum'); $array_fields['listing_layover_airport'] = $this->input->post('TC2_airline2'); $array_fields['listing_arrival_id'] = $dapt_arrival->location_id; $array_fields['listing_arrival_name'] = $dapt_arrival->location_name; $array_fields['listing_arrival_country'] = $dapt_arrival->location_country; $array_fields['listing_arrival_state'] = $dapt_arrival->location_state; $array_fields['listing_arrival_city'] = $dapt_arrival->location_city; $array_fields['listing_arrival_zipcode'] = $dapt_arrival->location_zipcode; $array_fields['listing_arrival_location_type'] = $dapt_arrival->location_location_id; } //car rental module elseif ($this->input->post('TC2_carrental')) { $array_fields['listing_location_type'] = 47; $dapt_departure = $this->MdlMisc->getLocation($this->input->post('TC2_departureCRID')); $dapt_layover = $this->MdlMisc->getLocation($this->input->post('TC2_layoverCRID')); $dapt_arrival = $this->MdlMisc->getLocation($this->input->post('TC2_arrivalCRID')); $array_fields['listing_city'] = $dapt_departure->location_city; $array_fields['listing_state'] = $dapt_departure->location_state; $array_fields['listing_zipcode'] = $dapt_departure->location_zipcode; $array_fields['listing_country'] = $dapt_departure->location_country; $array_fields['listing_location_type'] = $dapt_departure->location_location_id; $array_fields['listing_departure_id'] = $dapt_departure->location_id; $array_fields['listing_departure_name'] = $dapt_departure->location_name; $array_fields['listing_departure_country'] = $dapt_departure->location_country; $array_fields['listing_departure_state'] = $dapt_departure->location_state; $array_fields['listing_departure_city'] = $dapt_departure->location_city; $array_fields['listing_departure_zipcode'] = $dapt_departure->location_zipcode; $array_fields['listing_departure_location_type'] = $dapt_departure->location_location_id; $array_fields['listing_layover_id'] = $dapt_layover->location_id; $array_fields['listing_layover_name'] = $dapt_layover->location_name; $array_fields['listing_layover_country'] = $dapt_layover->location_country; $array_fields['listing_layover_state'] = $dapt_layover->location_state; $array_fields['listing_layover_city'] = $dapt_layover->location_city; $array_fields['listing_layover_zipcode'] = $dapt_layover->location_zipcode; $array_fields['listing_layover_location_type'] = $dapt_layover->location_location_id; $array_fields['listing_arrival_id'] = $dapt_arrival->location_id; $array_fields['listing_arrival_name'] = $dapt_arrival->location_name; $array_fields['listing_arrival_country'] = $dapt_arrival->location_country; $array_fields['listing_arrival_state'] = $dapt_arrival->location_state; $array_fields['listing_arrival_city'] = $dapt_arrival->location_city; $array_fields['listing_arrival_zipcode'] = $dapt_arrival->location_zipcode; $array_fields['listing_arrival_location_type'] = $dapt_arrival->location_location_id; } //amtrak module elseif ($this->input->post('TC2_bus_amtrak')) { $array_fields['listing_location_type'] = $this->MdlMisc->getLocationTypeIdByName('Train'); $dapt_departure = $this->MdlMisc->getLocation($this->input->post('TC2_departureStation')); $dapt_layover = $this->MdlMisc->getLocation($this->input->post('TC2_layoverStation')); $dapt_arrival = $this->MdlMisc->getLocation($this->input->post('TC2_arrivalStation')); $array_fields['listing_city'] = $dapt_departure->location_city; $array_fields['listing_state'] = $dapt_departure->location_state; $array_fields['listing_zipcode'] = $dapt_departure->location_zipcode; $array_fields['listing_country'] = $dapt_departure->location_country; $array_fields['listing_location_type'] = $dapt_departure->location_location_id; $array_fields['listing_departure_id'] = $dapt_departure->location_id; $array_fields['listing_departure_name'] = $dapt_departure->location_name; $array_fields['listing_departure_country'] = $dapt_departure->location_country; $array_fields['listing_departure_state'] = $dapt_departure->location_state; $array_fields['listing_departure_city'] = $dapt_departure->location_city; $array_fields['listing_departure_zipcode'] = $dapt_departure->location_zipcode; $array_fields['listing_departure_location_type'] = $dapt_departure->location_location_id; $array_fields['listing_departure_number'] = $this->input->post('TC2_servicenum1'); $array_fields['listing_layover_id'] = $dapt_layover->location_id; $array_fields['listing_layover_name'] = $dapt_layover->location_name; $array_fields['listing_layover_country'] = $dapt_layover->location_country; $array_fields['listing_layover_state'] = $dapt_layover->location_state; $array_fields['listing_layover_city'] = $dapt_layover->location_city; $array_fields['listing_layover_zipcode'] = $dapt_layover->location_zipcode; $array_fields['listing_layover_location_type'] = $dapt_layover->location_location_id; $array_fields['listing_layover_number'] = $this->input->post('TC2_servicenum2'); $array_fields['listing_arrival_id'] = $dapt_arrival->location_id; $array_fields['listing_arrival_name'] = $dapt_arrival->location_name; $array_fields['listing_arrival_country'] = $dapt_arrival->location_country; $array_fields['listing_arrival_state'] = $dapt_arrival->location_state; $array_fields['listing_arrival_city'] = $dapt_arrival->location_city; $array_fields['listing_arrival_zipcode'] = $dapt_arrival->location_zipcode; $array_fields['listing_arrival_location_type'] = $dapt_arrival->location_location_id; } //greyhound_trailways module elseif ($this->input->post('TC2_bus_greyhound')) { $array_fields['listing_location_type'] = $this->MdlMisc->getLocationTypeIdByName('Bus'); $dapt_departure = $this->MdlMisc->getLocation($this->input->post('TC2_departureStation')); $dapt_layover = $this->MdlMisc->getLocation($this->input->post('TC2_layoverStation')); $dapt_arrival = $this->MdlMisc->getLocation($this->input->post('TC2_arrivalStation')); $array_fields['listing_city'] = $dapt_departure->location_city; $array_fields['listing_state'] = $dapt_departure->location_state; $array_fields['listing_zipcode'] = $dapt_departure->location_zipcode; $array_fields['listing_country'] = $dapt_departure->location_country; $array_fields['listing_location_type'] = $dapt_departure->location_location_id; $array_fields['listing_departure_id'] = $dapt_departure->location_id; $array_fields['listing_departure_name'] = $dapt_departure->location_name; $array_fields['listing_departure_country'] = $dapt_departure->location_country; $array_fields['listing_departure_state'] = $dapt_departure->location_state; $array_fields['listing_departure_city'] = $dapt_departure->location_city; $array_fields['listing_departure_zipcode'] = $dapt_departure->location_zipcode; $array_fields['listing_departure_location_type'] = $dapt_departure->location_location_id; $array_fields['listing_departure_number'] = $this->db->escape_str($this->input->post('TC2_busroute1')); $array_fields['listing_layover_id'] = $dapt_layover->location_id; $array_fields['listing_layover_name'] = $dapt_layover->location_name; $array_fields['listing_layover_country'] = $dapt_layover->location_country; $array_fields['listing_layover_state'] = $dapt_layover->location_state; $array_fields['listing_layover_city'] = $dapt_layover->location_city; $array_fields['listing_layover_zipcode'] = $dapt_layover->location_zipcode; $array_fields['listing_layover_location_type'] = $dapt_layover->location_location_id; $array_fields['listing_layover_number'] = $this->db->escape_str($this->input->post('TC2_busroute2')); $array_fields['listing_arrival_id'] = $dapt_arrival->location_id; $array_fields['listing_arrival_name'] = $dapt_arrival->location_name; $array_fields['listing_arrival_country'] = $dapt_arrival->location_country; $array_fields['listing_arrival_state'] = $dapt_arrival->location_state; $array_fields['listing_arrival_city'] = $dapt_arrival->location_city; $array_fields['listing_arrival_zipcode'] = $dapt_arrival->location_zipcode; $array_fields['listing_arrival_location_type'] = $dapt_arrival->location_location_id; } //automobile module elseif ($this->input->post('TC2_automobile')) { $array_fields['listing_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_country'] = $listing_country; $array_fields['listing_location_type'] = $this->db->escape_str($this->input->post('TC2_departureLocationType')); $array_fields['listing_departure_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_departure_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_departure_country'] = $listing_country; $array_fields['listing_departure_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_departure_location_type'] = $this->db->escape_str($this->input->post('TC2_departureLocationType')); $array_fields['listing_layover_city'] = $this->db->escape_str($this->input->post('TC2_layoverCity')); $array_fields['listing_layover_state'] = $this->db->escape_str($this->input->post('TC2_layoverState')); $array_fields['listing_layover_country'] = $listing_country; $array_fields['listing_layover_zipcode'] = $this->db->escape_str($this->input->post('TC2_layoverPostalCode')); $array_fields['listing_layover_location_type'] = $this->db->escape_str($this->input->post('TC2_layoverLocationType')); $array_fields['listing_arrival_city'] = $this->db->escape_str($this->input->post('TC2_arrivalCity')); $array_fields['listing_arrival_state'] = $this->db->escape_str($this->input->post('TC2_arrivalState')); $array_fields['listing_arrival_country'] = $listing_country; $array_fields['listing_arrival_zipcode'] = $this->db->escape_str($this->input->post('TC2_arrivalPostalCode')); $array_fields['listing_arrival_location_type'] = $this->db->escape_str($this->input->post('TC2_arrivalLocationType')); } //bus_commuter module elseif ($this->input->post('TC2_bus_commuter')) { $array_fields['listing_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_country'] = $listing_country; $array_fields['listing_location_type'] = $this->MdlMisc->getLocationTypeIdByName('Bus'); $array_fields['listing_departure_name'] = $this->db->escape_str($this->input->post('TC2_departureBusName')); $array_fields['listing_departure_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_departure_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_departure_country'] = $listing_country; $array_fields['listing_departure_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_departure_number'] = $this->db->escape_str($this->input->post('TC2_departureBusRoute')); $array_fields['listing_departure_location_type'] = $this->MdlMisc->getLocationTypeIdByName('Bus'); $array_fields['listing_layover_name'] = $this->db->escape_str($this->input->post('TC2_layoverBusName')); $array_fields['listing_layover_city'] = $this->db->escape_str($this->input->post('TC2_layoverCity')); $array_fields['listing_layover_state'] = $this->db->escape_str($this->input->post('TC2_layoverState')); $array_fields['listing_layover_country'] = $listing_country; $array_fields['listing_layover_zipcode'] = $this->db->escape_str($this->input->post('TC2_layoverPostalCode')); $array_fields['listing_layover_number'] = $this->db->escape_str($this->input->post('TC2_layoverBusRoute')); $array_fields['listing_layover_location_type'] = $this->MdlMisc->getLocationTypeIdByName('Bus'); $array_fields['listing_arrival_city'] = $this->db->escape_str($this->input->post('TC2_arrivalCity')); $array_fields['listing_arrival_state'] = $this->db->escape_str($this->input->post('TC2_arrivalState')); $array_fields['listing_arrival_country'] = $listing_country; $array_fields['listing_arrival_zipcode'] = $this->db->escape_str($this->input->post('TC2_arrivalPostalCode')); $array_fields['listing_arrival_location_type'] = $this->MdlMisc->getLocationTypeIdByName('Bus'); } //school bus module elseif ($this->input->post('TC2_bus_school')) { $array_fields['listing_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_country'] = $listing_country; $array_fields['listing_location_type'] = $this->db->escape_str($this->input->post('TC2_departureLocationType')); $array_fields['listing_departure_id'] = $this->db->escape_str($this->input->post('TC2_departureSchoolID')); $array_fields['listing_departure_name'] = $this->db->escape_str($this->input->post('TC2_departureBusName')); $array_fields['listing_departure_number'] = $this->db->escape_str($this->input->post('TC2_departureBusNumber')); $array_fields['listing_departure_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_departure_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_departure_country'] = $listing_country; $array_fields['listing_departure_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_departure_location_type'] = $this->db->escape_str($this->input->post('TC2_departureLocationType')); $array_fields['listing_layover_id'] = $this->db->escape_str($this->input->post('TC2_layoverSchoolID')); $array_fields['listing_layover_name'] = $this->db->escape_str($this->input->post('TC2_layoverBusName')); $array_fields['listing_layover_number'] = $this->db->escape_str($this->input->post('TC2_layoverBusNumber')); $array_fields['listing_layover_city'] = $this->db->escape_str($this->input->post('TC2_layoverCity')); $array_fields['listing_layover_state'] = $this->db->escape_str($this->input->post('TC2_layoverState')); $array_fields['listing_layover_country'] = $listing_country; $array_fields['listing_layover_zipcode'] = $this->db->escape_str($this->input->post('TC2_layoverPostalCode')); $array_fields['listing_layover_location_type'] = $this->db->escape_str($this->input->post('TC2_layoverLocationType')); $array_fields['listing_arrival_id'] = $this->db->escape_str($this->input->post('TC2_arrivalSchoolID')); $array_fields['listing_arrival_city'] = $this->db->escape_str($this->input->post('TC2_arrivalCity')); $array_fields['listing_arrival_state'] = $this->db->escape_str($this->input->post('TC2_arrivalState')); $array_fields['listing_arrival_country'] = $listing_country; $array_fields['listing_arrival_zipcode'] = $this->db->escape_str($this->input->post('TC2_arrivalPostalCode')); $array_fields['listing_arrival_location_type'] = $this->db->escape_str($this->input->post('TC2_layoverLocationType')); } //taxi_limo module elseif ($this->input->post('TC2_taxi')) { $array_fields['listing_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_country'] = $listing_country; $array_fields['listing_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_location_type'] = $this->db->escape_str($this->input->post('TC2_departureLocationType')); $array_fields['listing_departure_name'] = $this->db->escape_str($this->input->post('TC2_departureTaxiName')); $array_fields['listing_departure_number'] = $this->db->escape_str($this->input->post('TC2_departureTaxiNumber')); $array_fields['listing_departure_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_departure_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_departure_country'] = $listing_country; $array_fields['listing_departure_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_departure_location_type'] = $this->db->escape_str($this->input->post('TC2_departureLocationType')); $array_fields['listing_arrival_city'] = $this->db->escape_str($this->input->post('TC2_arrivalCity')); $array_fields['listing_arrival_state'] = $this->db->escape_str($this->input->post('TC2_arrivalState')); $array_fields['listing_arrival_country'] = $listing_country; $array_fields['listing_arrival_zipcode'] = $this->db->escape_str($this->input->post('TC2_arrivalPostalCode')); $array_fields['listing_arrival_location_type'] = $this->db->escape_str($this->input->post('TC2_layoverLocationType')); } //ship_ferry module elseif ($this->input->post('TC2_ship')) { $dapt_departure = $this->MdlMisc->getLocation($this->input->post('TC2_departureShipName')); $dapt_layover = $this->MdlMisc->getLocation($this->input->post('TC2_layoverShipName')); $dapt_arrival = $this->MdlMisc->getLocation($this->input->post('TC2_arrivalShipName')); $array_fields['listing_city'] = $dapt_departure->location_city; $array_fields['listing_state'] = $dapt_departure->location_state; $array_fields['listing_zipcode'] = $dapt_departure->location_zipcode; $array_fields['listing_country'] = $dapt_departure->location_country; $array_fields['listing_location_type'] = $dapt_departure->location_location_id; $array_fields['listing_departure_id'] = $dapt_departure->location_id; $array_fields['listing_departure_name'] = $dapt_departure->location_name; $array_fields['listing_departure_country'] = $dapt_departure->location_country; $array_fields['listing_departure_state'] = $dapt_departure->location_state; $array_fields['listing_departure_city'] = $dapt_departure->location_city; $array_fields['listing_departure_zipcode'] = $dapt_departure->location_zipcode; $array_fields['listing_departure_location_type'] = $dapt_departure->location_location_id; $array_fields['listing_departure_number'] = $this->input->post('TC2_departureShipNumber'); $array_fields['listing_layover_id'] = $dapt_layover->location_id; $array_fields['listing_layover_name'] = $dapt_layover->location_name; $array_fields['listing_layover_country'] = $dapt_layover->location_country; $array_fields['listing_layover_state'] = $dapt_layover->location_state; $array_fields['listing_layover_city'] = $dapt_layover->location_city; $array_fields['listing_layover_zipcode'] = $dapt_layover->location_zipcode; $array_fields['listing_layover_location_type'] = $dapt_layover->location_location_id; $array_fields['listing_layover_number'] = $this->input->post('TC2_layoverShipNumber'); $array_fields['listing_arrival_id'] = $dapt_arrival->location_id; $array_fields['listing_arrival_name'] = $dapt_arrival->location_name; $array_fields['listing_arrival_country'] = $dapt_arrival->location_country; $array_fields['listing_arrival_state'] = $dapt_arrival->location_state; $array_fields['listing_arrival_city'] = $dapt_arrival->location_city; $array_fields['listing_arrival_zipcode'] = $dapt_arrival->location_zipcode; $array_fields['listing_arrival_location_type'] = $dapt_arrival->location_location_id; $array_fields['listing_arrival_number'] = $this->input->post('TC2_arrivalShipNumber'); /* $array_fields['listing_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_country'] = $listing_country; $array_fields['listing_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_location_type'] = $this->MdlMisc->getLocationTypeIdByName('Ferry'); $array_fields['listing_departure_name'] = $this->db->escape_str($this->input->post('TC2_departureShipName')); $array_fields['listing_departure_number'] = $this->db->escape_str($this->input->post('TC2_departureShipNumber')); $array_fields['listing_departure_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_departure_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_departure_country'] = $listing_country; $array_fields['listing_departure_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_departure_location_type'] = $this->MdlMisc->getLocationTypeIdByName('Ferry'); $array_fields['listing_layover_name'] = $this->db->escape_str($this->input->post('TC2_layoverShipName')); $array_fields['listing_layover_number'] = $this->db->escape_str($this->input->post('TC2_layoverShipNumber')); $array_fields['listing_layover_city'] = $this->db->escape_str($this->input->post('TC2_layoverCity')); $array_fields['listing_layover_state'] = $this->db->escape_str($this->input->post('TC2_layoverState')); $array_fields['listing_layover_country'] = $listing_country; $array_fields['listing_layover_zipcode'] = $this->db->escape_str($this->input->post('TC2_layoverPostalCode')); $array_fields['listing_layover_location_type'] = $this->MdlMisc->getLocationTypeIdByName('Ferry'); $array_fields['listing_arrival_name'] = $this->db->escape_str($this->input->post('TC2_arrivalShipName')); $array_fields['listing_arrival_number'] = $this->db->escape_str($this->input->post('TC2_arrivalShipNumber')); $array_fields['listing_arrival_city'] = $this->db->escape_str($this->input->post('TC2_arrivalCity')); $array_fields['listing_arrival_state'] = $this->db->escape_str($this->input->post('TC2_arrivalState')); $array_fields['listing_arrival_country'] = $listing_country; $array_fields['listing_arrival_zipcode'] = $this->db->escape_str($this->input->post('TC2_arrivalPostalCode')); $array_fields['listing_arrival_location_type'] = $this->MdlMisc->getLocationTypeIdByName('Ferry'); */ } //train_local module elseif ($this->input->post('TC2_train')) { $array_fields['listing_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_country'] = $listing_country; $array_fields['listing_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_location_type'] = $this->db->escape_str($this->input->post('TC2_departureLocationType')); $array_fields['listing_departure_name'] = $this->db->escape_str($this->input->post('TC2_departureTrainName')); $array_fields['listing_departure_number'] = $this->db->escape_str($this->input->post('TC2_departureTrainNumber')); $array_fields['listing_departure_city'] = $this->db->escape_str($this->input->post('TC2_departureCity')); $array_fields['listing_departure_state'] = $this->db->escape_str($this->input->post('TC2_departureState')); $array_fields['listing_departure_country'] = $listing_country; $array_fields['listing_departure_zipcode'] = $this->db->escape_str($this->input->post('TC2_departurePostalCode')); $array_fields['listing_departure_location_type'] = $this->db->escape_str($this->input->post('TC2_departureLocationType')); $array_fields['listing_layover_name'] = $this->db->escape_str($this->input->post('TC2_layoverTrainName')); $array_fields['listing_layover_number'] = $this->db->escape_str($this->input->post('TC2_layoverTrainNumber')); $array_fields['listing_layover_city'] = $this->db->escape_str($this->input->post('TC2_layoverCity')); $array_fields['listing_layover_state'] = $this->db->escape_str($this->input->post('TC2_layoverState')); $array_fields['listing_layover_country'] = $listing_country; $array_fields['listing_layover_zipcode'] = $this->db->escape_str($this->input->post('TC2_layoverPostalCode')); $array_fields['listing_layover_location_type'] = $this->db->escape_str($this->input->post('TC2_layoverLocationType')); $array_fields['listing_arrival_city'] = $this->db->escape_str($this->input->post('TC2_arrivalCity')); $array_fields['listing_arrival_state'] = $this->db->escape_str($this->input->post('TC2_arrivalState')); $array_fields['listing_arrival_country'] = $listing_country; $array_fields['listing_arrival_zipcode'] = $this->db->escape_str($this->input->post('TC2_arrivalPostalCode')); $array_fields['listing_arrival_location_type'] = $this->db->escape_str($this->input->post('TC2_layoverLocationType')); } //if it is a paid category, set the listing status to 'F' false $category_details = $this->MdlMisc->getCategoryDetails($array_fields['listing_category']); if ($category_details->category_free != 1) $array_fields['listing_status'] = 'F'; //remove any '?'s from any fields foreach ($array_fields as $key => $val) { $array_fields[$key] = str_ireplace('?', '', $val); } $array_fields_columns = array_keys($array_fields); $array_fields_values = array_values($array_fields); $sql = " INSERT INTO lostandfound.listings "; $sql .= " ( "; foreach ($array_fields as $key_af => $val_af) { $sql .= $this->db->escape_str($key_af) . ","; } $sql = substr($sql, 0, strlen($sql) - 1); $sql .= " ) "; //$sql .= " ( " . implode(',', $array_fields_columns) . " ) "; //$sql .= " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "; $sql .= " VALUES ("; foreach ($array_fields as $key_af => $val_af) { $sql .= " '" . $this->db->escape_str($val_af) . "',"; } $sql = substr($sql, 0, strlen($sql) - 1); $sql .= "); "; $query = $this->db->query($sql, $array_fields_values); if ($query) { $listing_id = $this->db->insert_id(); //add the free contact attemp credits (max upto 6, 3 for each new listing) $contact_attempts = intval($this->MdlUsers->getAccountContactEmails()); if ($contact_attempts < 6) { $contact_attempts_set = 6 - $contact_attempts; $contact_attempts_set = $contact_attempts + min(3, $contact_attempts_set); //LAF#412 - emily has asked for only 3 contact_attempts when the user is created //$this->db->query("UPDATE lostandfound.accounts SET account_email_contacts = '{$contact_attempts_set}', account_email_contacts_expiry = '" . date('Y-m-d 00:00:00', strtotime('+1 month')) . "' WHERE account_id='{$this->auth->uid}' "); } $this->newChildListingsLost($listing_id); $listing_email_date = date('m-d-Y', $date_lost_form); $listing_email_title = $this->input->post('title'); $listing_email_description = nl2br($this->input->post('description') . ($this->input->post('listingDescription') ? "\n" . $this->input->post('listingDescription') : '')); //$listing_email_category = $this->input->post('search_subcategory') ? $this->MdlMisc->getSubCategory($this->input->post('search_subcategory'))->category_name : $this->MdlMisc->getSubCategory($this->input->post('category'))->category_name; $url_listing_details = site_url('search/detail/' . $listing_id); $url_listing_poster = site_url('search/poster/' . $listing_id); $url_listing_upgrade = site_url('account/upgradelisting/' . $listing_id); $email_to = $account_email; $account_proxy_email_msg = isset($account_proxy_email_msg) && !empty($account_proxy_email_msg) ? $account_proxy_email_msg : ''; $account_proxy_email_error_msg = isset($account_proxy_email_msg) && !empty($account_proxy_email_msg) ? "\nIf this message is in error please contact cs@lostandfound.com com with the ILF listing number.\n" : ''; $email_subject = "Welcome to LostAndFound : Listing ID # ILF{$listing_id}"; $listing_email_title = $this->filter_bad_words(nl2br(str_ireplace(array('\n', '\\', '"', '\''), array(' ', '', '', ''), remove_nonascii_chars($listing_email_title)))); $listing_email_description = $this->filter_bad_words(nl2br(str_ireplace(array('\n', '\\', '"', '\''), array(' ', '', '', ''), remove_nonascii_chars($listing_email_description)))); $listing_email_description = str_ireplace(array('
', '
', '
'), array(' ', ' ', ' '), $listing_email_description); //get the amazon link $amazonEcsResult = ''; if (0 && ($this->input->post('brandText') || $this->input->post('brand') || !empty($category_details->category_name))) { try { if ($this->input->post('brand')) { $query_text = $this->input->post('brand'); } elseif ($this->input->post('brandText')) { $query_text = $this->input->post('brandText'); } else { $query_text = $category_details->category_name; } $this->load->library('amazonecs'); $amazonEcs = new AmazonECS(0, 0, 'com', 0); $amazonEcs->associateTag($this->AWS_ASSOCIATE_TAG); $amazonEcsResponse = $amazonEcs->category('All')->responseGroup('Large')->search($query_text); if ($amazonEcsResponse->Items->TotalResults > 0) { $amazonEcsResult = $amazonEcsResponse->Items->Item; } else { $amazonEcsResult = ''; } } catch (Exception $e) { $amazonEcsResult = ''; } } if (!empty($amazonEcsResult) && is_array($amazonEcsResult)) { $amazonEcsLink = "\nPlease click the link below to see related products for purchase\n"; $amazonEcsLink .= ''; $amazonEcsLink .= ''; for ($i = 0; $i < 5; $i++) { $amazonEcsLink .= ''; } $amazonEcsLink .= ''; $amazonEcsLink .= '
'; $amazonEcsLink = ''; $amazonEcsLink .= "DetailPageURL}\">{$amazonEcsResult[$i]->ItemAttributes->Title}"; $amazonEcsLink .= '
'; $amazonEcsLink .= "\n\n"; } $email_body = <<{$url_listing_details} Your Listing Poster: {$url_listing_poster} {$account_proxy_email_error_msg} Upgrade Your Listing! Purchasing an upgrade will result in greater visibility for your listing. To purchase an upgrade click here! Thank you, LostandFound.com The Internet Lost and Found, Inc. {$amazonEcsLink} For any questions or concerns, please contact customer service at cs@lostandfound.com ----------------------------------------------------------------------- THIS IS A SYSTEM GENERATED RESPONSE. PLEASE DO NOT REPLY TO THIS EMAIL EOTM; $this->load->library('Email'); //send this email after the premium listings page after the users reports the lost item $this->email->sendmail($email_to, $email_subject, $email_body, true, false); //send the email notification to the venue if (!empty($array_fields['listing_venue_id'])) { $loc_details = $this->getLocationDetails($array_fields['listing_venue_id']); $email_to = $this->getUserFromLocations($loc_details->location_id)->account_email; $email_subject = "New LOST Listing Posted at your Venue: Listing ID # ILF{$listing_id}"; $email_body_venue = <<{$url_listing_details} Your Listing Poster: {$url_listing_poster} Thank you, LostAndFound.com EOTM; if ($loc_details->location_send_email == 'T') { $userlocn = $this->getUserLocations($account_details->account_id, 0); if ($array_fields['listing_venue_id'] != $userlocn[0]->location_id) { $this->email->sendmail($email_to, $email_subject, $email_body_venue); } } } //update the listing id for the temp id we used for uploading the photo if ($this->input->post('hn_lost_pic_id')) { $sql = "UPDATE lostandfound.listings_pictures SET listing_picture_listing_id = '{$listing_id}' WHERE listing_picture_listing_id = '" . $this->input->post('hn_lost_pic_id') . "'"; $query = $this->db->query($sql); } //put in the additional listing info $sql = " UPDATE lostandfound.listings SET "; $sql .= " listing_brand=?, listing_model=?, listing_departure_location=?, listing_layover_location=?, listing_arrival_location=?, listing_color1=?, listing_color2=?, listing_serial=?, listing_photo=? "; $sql .= " WHERE listing_id = ? "; $post_listing_vars = array($this->input->post('brandText') ? $this->input->post('brandText') : $this->input->post('brand'), $this->input->post('model'), $this->input->post('listing_departure_location'), $this->input->post('listing_layover_location'), $this->input->post('listing_arrival_location'), $this->input->post('primary_color'), $this->input->post('secondaryColor'), $this->input->post('serial_claim'), $photo, $listing_id); $query = $this->db->query($sql, $post_listing_vars); if ($query) { $this->additionalInfoChildListingsLost($listing_id); } //now update the Sphinx Index by SphinxQL $this->sphinxQLAddUpdate('listings', $listing_id); //additional info entered, return the listing id return $listing_id; } else { return false; } } function newChildListingsLost($listing_id) { $listing_details = $this->getListingDetails($listing_id); $array_fields = array('listing_sku' => $listing_details->listing_sku . '_' . intval(microtime(true)), 'listing_acct_id' => $listing_details->listing_acct_id, 'listing_kind' => $listing_details->listing_kind, 'listing_category' => $listing_details->listing_category, 'listing_title' => $listing_details->listing_title, 'listing_description' => $listing_details->listing_description, 'listing_gender' => $listing_details->listing_gender, 'listing_date' => $listing_details->listing_date, 'listing_date_created' => $listing_details->listing_date_created, 'listing_venue_id' => $listing_details->listing_arrival_location, 'listing_location' => $listing_details->listing_location, 'listing_status' => $listing_details->listing_status, 'listing_brand' => $listing_details->listing_brand, 'listing_model' => $listing_details->listing_model, 'listing_color1' => $listing_details->listing_color1, 'listing_color2' => $listing_details->listing_color2, 'listing_serial' => $listing_details->listing_serial, 'listing_number' => '', 'listing_photo' => $listing_details->listing_photo, 'listing_parent' => $listing_details->listing_id, 'listing_travel_type' => '', 'listing_venue_id' => '', 'listing_location_type' => '', 'listing_city' => '', 'listing_state' => '', 'listing_country' => '', 'listing_zipcode' => '', 'listing_departure_id' => '', 'listing_departure_name' => '', 'listing_departure_number' => '', 'listing_departure_country' => '', 'listing_departure_state' => '', 'listing_departure_city' => '', 'listing_departure_zipcode' => '', 'listing_departure_location_type' => '', 'listing_layover_id' => '', 'listing_layover_name' => '', 'listing_layover_number' => '', 'listing_layover_country' => '', 'listing_layover_state' => '', 'listing_layover_city' => '', 'listing_layover_zipcode' => '', 'listing_layover_location_type' => '', 'listing_arrival_id' => '', 'listing_arrival_name' => '', 'listing_arrival_number' => '', 'listing_arrival_country' => '', 'listing_arrival_state' => '', 'listing_arrival_city' => '', 'listing_arrival_zipcode' => '', 'listing_arrival_location_type' => '', 'listing_latitude' => '', 'listing_longitude' => ''); if (!empty($listing_details->listing_arrival_country)) { $arrival_array_fields = $array_fields; $arrival_array_fields['listing_travel_type'] = 'arrival'; $arrival_array_fields['listing_venue_id'] = $listing_details->listing_arrival_id; $arrival_array_fields['listing_location_type'] = $listing_details->listing_arrival_location_type; $arrival_array_fields['listing_city'] = $listing_details->listing_arrival_city; $arrival_array_fields['listing_state'] = $listing_details->listing_arrival_state; $arrival_array_fields['listing_country'] = $listing_details->listing_arrival_country; $arrival_array_fields['listing_zipcode'] = $listing_details->listing_arrival_zipcode; $arrival_array_fields['listing_number'] = $listing_details->listing_arrival_number; if ($this->input->post('hn_arrival_latitude')) { $arrival_array_fields['listing_latitude'] = $t