Commit 2557a8f3 by Tobin

daily commit

parent 8cce08d9
......@@ -6,7 +6,7 @@ class Vehicle extends CI_Controller {
public function __construct() {
parent::__construct();
date_default_timezone_set("Asia/Kolkata");
// $this->load->model('Vechicle_model');
$this->load->model('Vehicle_model');
if(!$this->session->userdata('logged_in')) {
redirect(base_url());
......@@ -15,11 +15,13 @@ class Vehicle extends CI_Controller {
public function vehicleSearch(){
$return_arr = array('status'=>'0');
if(!isset($_POST) || empty($_POST) || !isset($_POST['searchType']) || empty($_POST['searchType'])){
if(!isset($_POST) || empty($_POST) || !isset($_POST['searchType']) || empty($_POST['searchType']) ||
!isset($_POST['vehLocation']) || empty($vehLocation = $_POST['vehLocation'])){
echo json_encode($return_arr);exit;
}
$param = "";
$searchType = $_POST['searchType'];
$vehicle_data = array('car_location'=>$vehLocation);
$this->load->model('Settings_model');
$settings = $this->Settings_model->settings_viewing();
......@@ -28,12 +30,17 @@ class Vehicle extends CI_Controller {
isset($_POST['vehYear']) && !empty($_POST['vehYear']) &&
isset($_POST['vehModel']) && !empty($_POST['vehModel']) &&
isset($_POST['vehMaker']) && !empty($_POST['vehMaker'])){
$vehicle_data['car_maker'] = $_POST['vehMaker'];
$vehicle_data['car_model'] = $_POST['vehModel'];
$vehicle_data['car_model_year'] = $_POST['vehYear'];
$param = "?format=json&key=".urlencode($settings['vin_audit_api'])."&year=".
urlencode($_POST['vehYear'])."&make=".urlencode($_POST['vehMaker'])."&model=".
urlencode($_POST['vehModel']);
}
else if($searchType == 2 && isset($_POST['vehVin']) && !empty($_POST['vehVin'])){
$vehicle_data['car_vin'] = $_POST['vehVin'];
$param = "?format=json&key=".urlencode($settings['vin_audit_api']).
"&vin=".urlencode($_POST['vehVin']);
}
......@@ -46,10 +53,35 @@ class Vehicle extends CI_Controller {
$return_arr['status'] = 2;
echo json_encode($return_arr);exit;
}
$return_arr['status'] = '1';
$return_arr['veh_data'] = $vehData;
$lat_lng = getLocationLatLng($vehLocation);
if(empty($lat_lng)){
$return_arr['status'] = 3;
echo json_encode($return_arr);exit;
}
$vehicle_data['car_name'] = $vehData['vehicle'];
$vehicle_data['car_loc_lat'] = $lat_lng['lat'];
$vehicle_data['car_loc_lng'] = $lat_lng['lng'];
$vehicle_data['vehicle_data'] = json_encode($vehData);
$car_id = $this->Vehicle_model->addVehicle($vehicle_data);
if(!empty($car_id)){
$return_arr['status'] = '1';
$return_arr['car_id'] = $car_id;
$return_arr['veh_data'] = $vehData;
}
}
echo json_encode($return_arr);exit;
}
function updateUserCarStatus(){
$return_arr = array('status'=>'0');
if(!isset($_POST) || empty($_POST) ||
!isset($_POST['car_id']) || empty($car_id = $_POST['car_id']) ||
!isset($_POST['action']) || empty($action = $_POST['action'])){
echo json_encode($return_arr); exit;
}
$return_arr['status'] = $this->Vehicle_model->changeStatus($car_id,$action);
echo json_encode($return_arr); exit;
}
}
?>
\ No newline at end of file
......@@ -66,4 +66,28 @@
$decode = trim(base64_decode(urldecode($decode)),'{*}');
return $decode;
}
function getLocationLatLng($location = ''){
$settings = getSettings();
if(empty($location) || empty($settings) || !isset($settings['google_api_key']) ||
empty($gKey = $settings['google_api_key'])){
return 0;
}
$thisObj = & get_instance();
$locData = file_get_contents("https://maps.google.com/maps/api/geocode/json?address=".
urlencode($location)."&sensor=false&key=".$gKey);
if(empty($locData))
return 0;
$loc_data = json_decode($locData);
if(empty($loc_data) || !isset($loc_data->status) || $loc_data->status != 'OK')
return 0;
$locArr['lat'] = $loc_data->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$locArr['lng'] = $loc_data->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
if(empty($locArr['lat']) || empty($locArr['lng']))
return 0;
return $locArr;
}
?>
\ No newline at end of file
<?php
class Vehicle_model extends CI_Model {
public function _consruct(){
parent::_construct();
}
function addVehicle($vehicle_data = array()){
if(empty($vehicle_data)){
return 0;
}
$status = $this->db->insert('customer_vehicle',$vehicle_data);
return ($status)?$this->db->insert_id():'0';
}
function changeStatus($vehicle_id = '', $action = '0'){
if(empty($vehicle_id)){
return 0;
}
if($action == 3){
$status = $this->db->delete('customer_vehicle',array('customer_veh_id'=>$vehicle_id));
} else {
$status = $this->db->update('customer_vehicle',array('status'=>$action),
array('customer_veh_id'=>$vehicle_id));
}
return $status;
}
}
?>
\ No newline at end of file
......@@ -95,7 +95,102 @@
</div>
</div>
</div>
<div class="col-md-12 padBottom20">
<div class="col-md-12 padBottom20" id="savedVehiclesCntr">
</div>
</div>
</form>
<div class="box-header with-border">
<h3 class="box-title">Add New Vehicles</h3>
</div>
<br>
<!-- Vehicle Details START -->
<form id="CarSearchForm">
<div class="col-md-12">
<div class="col-md-3">
<label>
<input id="search_key_type" type="radio" name="search_key_type" value='1' checked>
<span class="padAll-20">Vechile Details</span>
</label>
</div>
<div class="col-md-9">
<label>
<input id="search_key_type" type="radio" name="search_key_type" value='2'>
<span class="padAll-20">VIN Number</span>
</label>
</div>
</div>
<!-- Search Box START -->
<div class="col-md-12 padAll-20">
<div class="col-md-8">
<!-- Vehicle Details Search START -->
<div id="searchTyp_1">
<div class="col-md-12">
<div class="col-md-6">
<label>Vehicle Model</label>
<input type="text" class="form-control required" name="vehModel" input="search_params"
placeholder="Enter Vehicle Model" required="">
</div>
<div class="col-md-6">
<label>Vehicle Maker</label>
<input type="text" class="form-control required" name="vehMaker" input="search_params"
placeholder="Enter Vehicle Maker" required>
</div>
</div>
<div class="col-md-12 padTop10">
<div class="col-md-6">
<label>Vehicle Model Year</label>
<select name="vehYear" class="form-control required" input="search_params"
data-parsley-trigger="change" required="">
<option selected disabled value="">Choose Vehicle Model Year</option>
<?php
for($year=date('Y'); $year>=1950; $year--){
$cond = (isset($vehicle_data) && isset($vehicle_data->model) &&
!empty($vehicle_data->model) &&
$vehicle_data->model == $year)?'selected':'';
echo '<option '.$cond.' value="'.$year.'">'.$year.'</option>';
}
?>
</select>
</div>
<div class="col-md-6">
<label>Vehicle Location</label>
<input type="text" class="form-control required" name="vehLocation"
id="loc_search_1" input="search_params" placeholder="Enter Vehicle Location" required>
</div>
</div>
</div>
<!-- Vehicle Details Search END -->
<!-- Vehicle Vin Search START -->
<div id="searchTyp_2" class="hide">
<div class="col-md-12">
<div class="col-md-12">
<label>Vehicle VIN Number</label>
<input type="text" class="form-control" name="vehVin" input="search_params"
placeholder="Enter Vehicle VIN Number">
</div>
<div class="col-md-12 padTop10">
<label>Vehicle Location</label>
<input type="text" class="form-control" name="vehLocation"
id="loc_search_2" input="search_params" placeholder="Enter Vehicle Location">
</div>
</div>
</div>
<!-- Vehicle Vin Search END -->
</div>
<!-- Search Box END -->
<div class="col-md-4">
<button id="vehSearch" type="button" class="btn btn-info" style="margin-top:18%;">Search</button>
</div>
</div>
<!-- Vehicle Details END -->
</form>
<!-- View Car DEtails START -->
<div class="col-md-12 padBottom20 hide" id="carSearchResult"></div>
<!-- View Car DEtails END -->
<div class="col-md-12">
<div class="box-footer">
<div style="text-align: center;">
......@@ -108,4 +203,4 @@
</div>
</div>
</section>
</div>
</div>
\ No newline at end of file
......@@ -89,83 +89,4 @@
</div>
</div>
</section>
</div>
<div class="hide" id="vechileAddHtml">
<!-- Vehicle Details START -->
<form name="vechile_search_form" id="CarSearchForm">
<div class="col-md-12">
<div class="col-md-3">
<label>
<input id="search_key_type" type="radio" name="search_key_type" value='1' checked>
<span class="padAll-20">Vechile Details</span>
</label>
</div>
<div class="col-md-9">
<label>
<input id="search_key_type" type="radio" name="search_key_type" value='2'>
<span class="padAll-20">VIN Number</span>
</label>
</div>
</div>
<!-- Search Box START -->
<div class="col-md-12 padAll-20">
<div class="col-md-8">
<!-- Vehicle Details Search START -->
<div id="searchTyp_1">
<div class="col-md-12">
<div class="col-md-12">
<label>Vehicle Model</label>
<input type="text" class="form-control required" name="vehModel" input="search_params"
placeholder="Enter Vehicle Model" required="">
</div>
</div>
<div class="col-md-12 padTop10">
<div class="col-md-6">
<label>Vehicle Maker</label>
<input type="text" class="form-control required" name="vehMaker" input="search_params"
placeholder="Enter Vehicle Maker" required>
</div>
<div class="col-md-6">
<label>Year of Manufactured</label>
<select name="vehYear" class="form-control required" input="search_params"
data-parsley-trigger="change" required="">
<option selected disabled value="">Choose Vehicle Purchase Year</option>
<?php
for($year=date('Y'); $year>=1950; $year--){
$cond = (isset($vehicle_data) && isset($vehicle_data->model) &&
!empty($vehicle_data->model) &&
$vehicle_data->model == $year)?'selected':'';
echo '<option '.$cond.' value="'.$year.'">'.$year.'</option>';
}
?>
</select>
</div>
</div>
</div>
<!-- Vehicle Details Search END -->
<!-- Vehicle Vin Search START -->
<div id="searchTyp_2" class="hide">
<div class="col-md-12">
<div class="col-md-12">
<label>Vehicle VIN Number</label>
<input type="text" class="form-control" name="vehVin" input="search_params"
placeholder="Enter Vehicle VIN Number">
</div>
</div>
</div>
<!-- Vehicle Vin Search END -->
</div>
<!-- Search Box END -->
<div class="col-md-4">
<button type="submit" class="btn btn-info" style="margin-top:22px;">Search</button>
</div>
</div>
<!-- Vehicle Details END -->
</form>
<!-- View Car DEtails START -->
<div class="col-md-12 hide" id="CarSearchResult"></div>
<!-- View Car DEtails END -->
</div>
\ No newline at end of file
......@@ -312,6 +312,10 @@
padding-top:20px !important;
}
.padBottom20 {
padding-bottom:20px !important;
}
.padTop10 {
padding-top:10px !important;
}
......@@ -340,7 +344,7 @@
text-align:center;
}
.padAll-20 {
.padAll-10 {
padding: 10px;
}
......@@ -365,4 +369,16 @@
.disp-block {
display:block !important;
}
.margin-all {
margin: 5px;
}
.marginBottom-5 {
margin-bottom: 5px;
}
.marginBottom-10 {
margin-bottom: 10px;
}
\ No newline at end of file
......@@ -73,6 +73,25 @@ function viewImageModal(title,img_src){
modalTrigger(title,body_html);
}
function initLocSearch_1() {
var input = document.getElementById('loc_search_1');
var options = {componentRestrictions: {country: country_flag}};
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window,'load',initLocSearch_1);
function initLocSearch_2() {
var input = document.getElementById('loc_search_2');
var options = {componentRestrictions: {country: country_flag}};
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window,'load',initLocSearch_2);
function initLocSearch_3() {
var input = document.getElementById('loc_search_3');
var options = {componentRestrictions: {country: country_flag}};
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window,'load',initLocSearch_3);
jQuery('[id="viewMechanic"]').on('click',function() {
var mechanic_id = jQuery(this).attr('mechanic_id');
......@@ -401,9 +420,11 @@ jQuery('[id="createCustomerSubmit"]').on('click',function() {
jQuery('[id="createCustomerForm"]').submit();
});
jQuery('[name="vechile_search_form"]').on('submit',function(event) {
jQuery('[id="vehSearch"]').on('click',function(event) {
event.preventDefault();
if(!jQuery('[id="CarSearchForm"]').parsley().validate()){
return false;
}
var searchTypId = jQuery('input[name=search_key_type]:checked').val(),
passArr = {'searchType':'','vehModel':'','vehMaker':'','vehYear':'','vehVin':''};
if(searchTypId == '' || searchTypId == null || searchTypId == 'null' || searchTypId == undefined || searchTypId == 'undefined'){
......@@ -414,7 +435,9 @@ jQuery('[name="vechile_search_form"]').on('submit',function(event) {
vehYear = jQuery('[name="vehYear"]').val(),
vehModel = jQuery('[name="vehModel"]').val(),
vehMaker = jQuery('[name="vehMaker"]').val();
if((searchTypId == 1 &&
vehLocation = jQuery('[name="vehLocation"]').val();
if((vehLocation == '' || vehLocation == null || vehLocation == 'null' || vehLocation == undefined || vehLocation == 'undefined') ||
(searchTypId == 1 &&
(vehYear == '' || vehYear == null || vehYear == 'null' || vehYear == undefined || vehYear == 'undefined' ||
vehModel == '' || vehModel == null || vehModel == 'null' || vehModel == undefined || vehModel == 'undefined' ||
vehMaker == '' || vehMaker == null || vehMaker == 'null' || vehMaker == undefined || vehMaker == 'undefined')
......@@ -431,6 +454,7 @@ jQuery('[name="vechile_search_form"]').on('submit',function(event) {
passArr.vehModel = vehModel;
passArr.vehMaker = vehMaker;
passArr.searchType = searchTypId;
passArr.vehLocation = vehLocation;
jQuery.ajax({
url : base_url+"Vehicle/vehicleSearch",
......@@ -443,16 +467,21 @@ jQuery('[name="vechile_search_form"]').on('submit',function(event) {
return false;
}
var resp_data = jQuery.parseJSON(resp);
if(resp_data['status'] != '1' || (resp_data['status'] == 1 && resp_data['veh_data'] == '' || resp_data['veh_data'] == null || resp_data['veh_data'] == undefined || resp_data['veh_data'] == 'null' || resp_data['veh_data'] == 'undefined')){
if(resp_data['status'] != '1' || (resp_data['status'] == 1 && resp_data['veh_data'] == '' || resp_data['veh_data'] == null || resp_data['veh_data'] == undefined || resp_data['veh_data'] == 'null' || resp_data['veh_data'] == 'undefined' || resp_data['car_id'] == '' || resp_data['car_id'] == null || resp_data['car_id'] == undefined || resp_data['car_id'] == 'null' || resp_data['car_id'] == 'undefined')){
remFullScreenLoader();
var msg = (resp_data['status'] == '2')?'No Data Found, Try again with proper search parameters':'Something went wrong, please try again later...!';
var msg = 'Something went wrong, please try again later...!';
if(resp_data['status'] == '2')
msg = 'No Data Found, Try again with proper search parameters..!';
if(resp_data['status'] == '3')
msg = 'Provide a valid Location..!';
jQuery('[id="modal_content"]').html(msg);
return false;
}
var vehHtmlBody = '', vehicleData = resp_data['veh_data'];
vehHtmlBody = '<span class="vechile-body disp-block">'
var vehHtmlBody = '', car_id = resp_data['car_id'], vehicleData = resp_data['veh_data'];
vehHtmlBody = '<span class="vechile-body disp-block marginBottom-10">'
+vehicleData['vehicle']+
'<div id="closeVehSearch" class="float-right">'+
'<div onclick="searchAction('+car_id+',3,0,\''+vehicleData['vehicle']+'\');" class="float-right">'+
'<i class="fa fa-fw fa-close cpoint"></i>'+
'</div>'+
'</span>';
......@@ -465,10 +494,15 @@ jQuery('[name="vechile_search_form"]').on('submit',function(event) {
'<div class="col-xs-6"><span class="info-box-text">'+value+'</span></div>'+
'</div>';
});
vehHtmlBody += '<div class="col-md-12">'+
'<button onclick="searchAction('+car_id+',3,0,\''+vehicleData['vehicle']+'\');" type="button" class="btn btn-danger float-right margin-all">Remove</button>'+
'<button onclick="searchAction('+car_id+',2,0,\''+vehicleData['vehicle']+'\');" type="button" class="btn btn-primary float-right margin-all">Add</button>'+
'</div>';
jQuery('[id="CarSearchResult"]').append('<div class="box-body border marginTop10">'+vehHtmlBody+'</div>');
jQuery('[id="CarSearchResult"]').removeClass('hide');
jQuery('[id="carSearchResult"]').html('<div id="search_result_'+car_id+'" class="box-body border marginTop10">'+vehHtmlBody+'</div>');
jQuery('[id="carSearchResult"]').removeClass('hide');
remFullScreenLoader();
slideTo('carSearchResult');
},
fail: function(xhr, textStatus, errorThrown){
remFullScreenLoader();
......@@ -481,13 +515,32 @@ jQuery('[name="vechile_search_form"]').on('submit',function(event) {
});
});
jQuery("div").on("click","div#closeVehSearch", function(){
jQuery('[name="vechile_search_form"]').trigger("reset");
jQuery('[id="CarSearchResult"]').html('');
jQuery('[id="CarSearchResult"]').addClass('hide');
});
jQuery('[id="addCars"]').on('click',function() {
modalTrigger('Add New Cars',jQuery('[id="vechileAddHtml"]').html());
});
function searchAction(car_id, action, saved, name){
if(car_id == '' || car_id == null || car_id == 'null' || car_id == undefined || car_id == 'undefined' || action == '' || action == null || action == 'null' || action == undefined || action == 'undefined'){
return false;
}
var html = '';
if(action == 0 || action == 1 || action == 3){
if(saved == 1){
jQuery('[id="saved_vehicle_'+car_id+'"]').remove();
}
slideTo('CarSearchForm');
jQuery.ajax({
url : base_url+"Vehicle/updateUserCarStatus",
type : 'POST',
data : {'car_id':car_id,'action':action}
});
}
if(action == 2){
html = '<span id="saved_vehicle_'+car_id+'" class="vechile-body disp-block marginBottom-5">'
+name+
'<div onclick="searchAction('+car_id+',3,1,\'\');" class="float-right">'+
'<i class="fa fa-fw fa-close cpoint"></i>'+
'</div>'+
'<input type="hidden" name="saved_vehicles[]" >'+
'</span>';
jQuery('[id="savedVehiclesCntr"]').append(html);
slideTo('savedVehiclesCntr');
}
jQuery('[id="search_result_'+car_id+'"]').remove();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment