Commit ca1cdefa by Tobin

daily commit

parent ea631040
......@@ -109,7 +109,16 @@ class Mechanic extends CI_Controller {
}else if($err == 0 && (!isset($_POST['address']) || empty($_POST['address']))){
$err = 1;
$errMsg = 'Provide an address';
}else if($err == 0 && (!isset($_POST['location']) || empty($_POST['location']))){
$err = 1;
$errMsg = 'Provide a Functional Area';
}
$fnLocation = getLocationLatLng($_POST['location']);
if(empty($fnLocation)){
$err = 1;
$errMsg = 'Provide a Valid Functional Area';
}
if($err == 0){
$config = set_upload_service("assets/uploads/services");
$this->load->library('upload');
......@@ -139,6 +148,8 @@ class Mechanic extends CI_Controller {
redirect(base_url('Mechanic/addMechanic'));
}
$_POST['password'] = md5($_POST['password']);
$_POST['location_lat'] = $fnLocation['lat'];
$_POST['location_lng'] = $fnLocation['lng'];
$status = $this->Mechanic_model->addMechanic($_POST);
if($status == 1){
......@@ -214,7 +225,16 @@ class Mechanic extends CI_Controller {
}else if($err == 0 && (!isset($_POST['address']) || empty($_POST['address']))){
$err = 1;
$errMsg = 'Provide your address';
}else if($err == 0 && (!isset($_POST['location']) || empty($_POST['location']))){
$err = 1;
$errMsg = 'Provide a Functional Area';
}
$fnLocation = getLocationLatLng($_POST['location']);
if(empty($fnLocation)){
$err = 1;
$errMsg = 'Provide a Valid Functional Area';
}
if($err == 0){
$config = set_upload_service("assets/uploads/services");
$this->load->library('upload');
......@@ -239,7 +259,9 @@ class Mechanic extends CI_Controller {
$this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Mechanic/addMechanic'));
}
$_POST['location_lat'] = $fnLocation['lat'];
$_POST['location_lng'] = $fnLocation['lng'];
$status = $this->Mechanic_model->updateMechanic(decode_param($mechanic_id),$_POST);
if($status == 1){
$flashMsg =array('message'=>'Successfully Updated User Details..!','class'=>'success');
......
......@@ -4,199 +4,219 @@ header('Content-Type: text/html; charset=utf-8');
// Allow from any origin
if(isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
class Webservices extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('Webservice_model');
$this->load->library('form_validation');
$auth = '';
$class = $this->router->fetch_class();
$method = $this->router->fetch_method();
if($this->input->server('REQUEST_METHOD') == 'GET')
$postdata = json_encode($_GET);
else if ($this->input->server('REQUEST_METHOD') == 'POST')
$postdata = file_get_contents("php://input");
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
}
// $this->last_id = set_log($class, $method, $postdata, $auth);
}
// customer_login
public function customer_login(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Customer_model');
$respArr = array('status'=>'0','message'=>'Required Fields are empty.');
if(!isset($postData['email']) || empty($postData['email']) ||
!isset($postData['password']) || empty($postData['password'])){
echo json_encode($respArr);exit;
}
$custResp = $this->Customer_model->checkCustomerLogin($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
$respArr['data'] = $custResp['data'];
$respArr['status'] = '1';
$respArr['message'] = 'Success';
echo json_encode($respArr);exit;
}
if($custResp['status'] == '2'){
$respArr['status'] = '2';
$respArr['message'] = 'Invalid Email Address';
echo json_encode($respArr);exit;
}
if($custResp['status'] == '3'){
$respArr['status'] = '3';
$respArr['message'] = 'Invalid Password';
echo json_encode($respArr);exit;
}
echo json_encode($respArr); exit;
}
// customer_forgot_password
public function customer_forgot_password(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Customer_model');
$respArr = array('status'=>'0','message'=>'Required Fields are empty.');
if(empty($postData) || !isset($postData['email']) || empty($postData['email'])){
echo json_encode($respArr);exit;
}
$custResp = $this->Customer_model->genCustForgotPassLink($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit;
}
if($custResp['status'] == '2'){
$respArr['status'] = '2';
$respArr['message'] = 'Invalid Email Address';
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
/*
MAIL SENT CONFIGARATION -- TODO
*/
$respArr['status'] = '1';
$respArr['message'] = 'Password Reset Email has been sent';
}
echo json_encode($respArr); exit;
}
// customer_registration
public function customer_registration(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Customer_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
if(empty($postData)){
echo json_encode($respArr);exit;
}
$err = 0;
$msg = '';
if(!isset($postData['email']) || empty($postData['email'])){
$err = 1;
$msg = 'Provide a valid Email ID';
}
else if(!isset($postData['password']) || empty($postData['password'])){
$err = 1;
$msg = 'Provide a Password';
}
else if(!isset($postData['first_name']) || empty($postData['first_name'])){
$err = 1;
$msg = 'Provide valid Name';
}
else if(!isset($postData['last_name']) || empty($postData['last_name'])){
$err = 1;
$msg = 'Provide valid Name';
}
if($err == 1){
$respArr['message'] = $msg;
echo json_encode($respArr);exit;
}
if(isset($postData['phone']) && empty($postData['phone'])){
unset($postData['phone']);
}
unset($postData['promocode']);
$custResp = $this->Customer_model->customer_registration($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit;
}
if($custResp['status'] == '2'){
$respArr['status'] = '2';
$respArr['message'] = 'Email Address already in use';
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
$custResp = $this->Customer_model->checkCustomerLogin($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
$respArr['data'] = $custResp['data'];
$respArr['status'] = '1';
$respArr['message'] = 'Success';
echo json_encode($respArr);exit;
}
}
echo json_encode($respArr); exit;
}
// customer_registration
public function getGeneralIssues(){
header('Content-type: application/json');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
$this->load->model('Issue_model');
$issue_data = $this->Issue_model->getGeneralIssues();
if(!empty($issue_data)){
$respArr['status'] = '1';
$respArr['message'] = 'Success';
$respArr['issue_data'] = $issue_data;
}
echo json_encode($respArr); exit;
}
public function __construct() {
parent::__construct();
$this->load->model('Webservice_model');
$this->load->library('form_validation');
$auth = '';
$class = $this->router->fetch_class();
$method = $this->router->fetch_method();
if($this->input->server('REQUEST_METHOD') == 'GET')
$postdata = json_encode($_GET);
else if ($this->input->server('REQUEST_METHOD') == 'POST')
$postdata = file_get_contents("php://input");
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
}
// $this->last_id = set_log($class, $method, $postdata, $auth);
}
// customer_login
public function customer_login(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Customer_model');
$respArr = array('status'=>'0','message'=>'Required Fields are empty.');
if(!isset($postData['email']) || empty($postData['email']) ||
!isset($postData['password']) || empty($postData['password'])){
echo json_encode($respArr);exit;
}
$custResp = $this->Customer_model->checkCustomerLogin($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
$respArr['data'] = $custResp['data'];
$respArr['status'] = '1';
$respArr['message'] = 'Success';
echo json_encode($respArr);exit;
}
if($custResp['status'] == '2'){
$respArr['status'] = '2';
$respArr['message'] = 'Invalid Email Address';
echo json_encode($respArr);exit;
}
if($custResp['status'] == '3'){
$respArr['status'] = '3';
$respArr['message'] = 'Invalid Password';
echo json_encode($respArr);exit;
}
echo json_encode($respArr); exit;
}
// customer_forgot_password
public function customer_forgot_password(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Customer_model');
$respArr = array('status'=>'0','message'=>'Required Fields are empty.');
if(empty($postData) || !isset($postData['email']) || empty($postData['email'])){
echo json_encode($respArr);exit;
}
$custResp = $this->Customer_model->genCustForgotPassLink($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit;
}
if($custResp['status'] == '2'){
$respArr['status'] = '2';
$respArr['message'] = 'Invalid Email Address';
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
/*
MAIL SENT CONFIGARATION -- TODO
*/
$respArr['status'] = '1';
$respArr['message'] = 'Password Reset Email has been sent';
}
echo json_encode($respArr); exit;
}
// customer_registration
public function customer_registration(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Customer_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
if(empty($postData)){
echo json_encode($respArr);exit;
}
$err = 0;
$msg = '';
if(!isset($postData['email']) || empty($postData['email'])){
$err = 1;
$msg = 'Provide a valid Email ID';
}
else if(!isset($postData['password']) || empty($postData['password'])){
$err = 1;
$msg = 'Provide a Password';
}
else if(!isset($postData['first_name']) || empty($postData['first_name'])){
$err = 1;
$msg = 'Provide valid Name';
}
else if(!isset($postData['last_name']) || empty($postData['last_name'])){
$err = 1;
$msg = 'Provide valid Name';
}
if($err == 1){
$respArr['message'] = $msg;
echo json_encode($respArr);exit;
}
if(isset($postData['phone']) && empty($postData['phone'])){
unset($postData['phone']);
}
unset($postData['promocode']);
$custResp = $this->Customer_model->customer_registration($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit;
}
if($custResp['status'] == '2'){
$respArr['status'] = '2';
$respArr['message'] = 'Email Address already in use';
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
$custResp = $this->Customer_model->checkCustomerLogin($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
$respArr['data'] = $custResp['data'];
$respArr['status'] = '1';
$respArr['message'] = 'Success';
echo json_encode($respArr);exit;
}
}
echo json_encode($respArr); exit;
}
// getGeneralIssues
public function getGeneralIssues(){
header('Content-type: application/json');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
$this->load->model('Issue_model');
$issue_data = $this->Issue_model->getGeneralIssues();
if(!empty($issue_data)){
$respArr['status'] = '1';
$respArr['message'] = 'Success';
$respArr['issue_data'] = $issue_data;
}
echo json_encode($respArr); exit;
}
// getNearByMechanics
public function getNearByMechanics(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Mechanic_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
$mechanic_data = $this->Mechanic_model->getNearByMechanics($postData);
if(!empty($issue_data)){
$respArr['status'] = '1';
$respArr['message'] = 'Success';
$respArr['mechanic_data'] = $mechanic_data;
}
echo json_encode($respArr); exit;
}
}
?>
......@@ -44,9 +44,12 @@ class Mechanic_model extends CI_Model {
'shop_id'=>$mechanic_data['shop_id'],
'address'=>$mechanic_data['address'],
'licence'=>$mechanic_data['licence'],
'location'=>$mechanic_data['location'],
'email_id'=>$mechanic_data['email_id'],
'last_name'=>$mechanic_data['last_name'],
'first_name'=>$mechanic_data['first_name'],
'location_lat'=>$mechanic_data['location_lat'],
'location_lng'=>$mechanic_data['location_lng'],
'licence_number'=>$mechanic_data['licence_number'],
'licence_exp_date'=>$mechanic_data['licence_exp_date']));
return $status;
......@@ -105,6 +108,9 @@ class Mechanic_model extends CI_Model {
'state'=>$mechanic_data['state'],'shop_id'=>$mechanic_data['shop_id'],
'address'=>$mechanic_data['address'],'email_id'=>$mechanic_data['email_id'],
'last_name'=>$mechanic_data['last_name'],'phone'=>$mechanic_data['phone'],
'location'=>$mechanic_data['location'],
'location_lat'=>$mechanic_data['location_lat'],
'location_lng'=>$mechanic_data['location_lng'],
'licence_number'=>$mechanic_data['licence_number'],
'licence_exp_date'=>$mechanic_data['licence_exp_date']);
......@@ -122,5 +128,27 @@ class Mechanic_model extends CI_Model {
$status = $this->db->update('admin_users',array('status'=>$status),array('id'=>$mechanic_id));
return $status;
}
function getNearByMechanics($pickLocData = array()){
if(empty($pickLocData)){
return 0;
}
$current_lat = $pickLocData['pickup_lat'];
$current_lng = $pickLocData['pickup_lng'];
$sql = "SELECT ME.*, MS.*,
3956 * 2 * ASIN(SQRT(POWER(SIN(($current_lat-ME.location_lat)*pi()/180/2),2)+
COS($current_lat*pi()/180 )*COS(ME.location_lat*pi()/180)*
POWER(SIN(($current_lng-ME.location_lng)*pi()/180/2),2) )) as distance
FROM mechanic AS ME
INNER JOIN admin_users AS AU ON (AU.id=ME.mechanic_id)
LEFT JOIN mechanic_shop AS MS ON (MS.shop_id=ME.shop_id AND MS.status='1')
WHERE AU.status = '1'
HAVING distance<10";
pr($this->db->query($sql));
}
}
?>
\ No newline at end of file
......@@ -112,6 +112,12 @@
required="" name="state" placeholder="Enter email ID" value="<?= (isset($user_data->state))?$user_data->state:'' ?>">
<span class="glyphicon form-control-feedback"></span>
</div>
<div class="form-group">
<label>Functional Area</label>
<input type="text" class="form-control" data-parsley-trigger="change"
id="loc_search_1" name="location" placeholder="Choose Functional Area" value="<?= (isset($user_data->location))?$user_data->location:'' ?>">
<span class="glyphicon form-control-feedback"></span>
</div>
<?php if(!empty($shop_data)){ ?>
<div class="form-group">
<label>Workshop</label>
......
......@@ -201,6 +201,11 @@ jQuery('[id="viewMechanic"]').on('click',function() {
'<div class="col-md-1">:</div>'+
'<div class="col-md-6"><label>'+mechanic_data['state']+'</label></div> '+
'</div> '+
'<div class="row"> '+
'<div class="col-md-4">Location</div>'+
'<div class="col-md-1">:</div>'+
'<div class="col-md-6"><label>'+mechanic_data['location']+'</label></div> '+
'</div> '+
shopHtml+
'</div> '+
'<div class="col-md-5"> '+
......
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