<?php
session_start();
error_reporting(1);
ini_set('display_errors', 1);
require_once "../config.php";
include_once "../ichat/admin/route.php";
if ($session->is_logged_in() != true ) {
        redirect_to(WEB_LINK.'/login');
} else {
    $current_user = User::get_specific_id($session->admin_id);
    $current_user->set_online();
    $group = $current_user->prvlg_group;
}


require_once("../ichat/admin/assets/includes/Library/SessManager.php");
require_once("../ichat/admin/assets/includes/Library/User.php");
$session = new  SessManager();

//require_once "check_admin.php";
require_once 'database.php';
	class edit_tracking extends database
	{
		
		public function getdata($id)
		{
			$where['id']=$id;
			return $this->fetchRow('orders',$where);
		}
		
		
	}
$add = new edit_tracking();
$msg="";
if(!isset($_GET['id']))
{
	  header('Location:orders.php');
}
$id=$_GET['id'];
$od = $add->getdata($id);
include 'header.php';
?>
            <!-- MAIN CONTENT-->
            <div class="main-content">
                <div class="section__content section__content--p30">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="overview-wrap">
                                    <h2 class="title-1">Edit Tracking</h2>
                                    
                                </div>
								<?php if($msg !=''){echo '<span class="col-md-6 alert alert-danger pull-left">'.$msg.'</span>';}?>
                            </div>
                        </div>
                        
                        <div class="row m-t-25 m-row">
					
                            <div class="col-lg-12">
                                <div class="card">
                                   
									<div class="card-header">
                                        <span class="pull-right">ORDER: #<?php echo $od['id'];?></span>
                                        
                                    </div>
                                        
                                    
                                    <div class="card-body card-block">
									
									<div class="row">
							
											<div class="col-md-6 m-t-25">
											<div class="error_message_stage"></div>
												<label>Phone Number : <?php echo htmlspecialchars($od['phone']);?></label>
													<div class="error-message pull-left"></div>
												<input type="hidden" id="order_id" value="<?php echo $id;?>"/>
												<select id="stage" class="form-control">
													<option value="">--Stages--</option>
													<option value="1">Pasūtījums ģenerēts</option>
													<option value="2">Tiek remontēts|</option>
													<option value="3">Ierīce salabota</option>
													<option value="4">Nodota Kurjieram</option>
												</select>
												<button type="button" id="complete" class="btn btn-warning">Complete</button>
											</div>
											<?php if($od['stage1'] != '1'){echo '';}else{echo 'check-box';}	?>
										
									</div>
									<div class="row">
									<div class="col-md-12">
										<div class="timeline-vertcal">
											<ul>
											  <li class="vert-sel">
												<div class="dot-box <?php if($od['stage'] >= '1'){echo 'check-box';} ?>">
												  <?php if($od['stage'] >= '1'){ ?>
												  <span class="fa fa-check"></span>

												<?php } ?>
												</div>
												<span class="iner-box">
													Pasūtījums ģenerēts
												 </span> 
												 <div class="timeline-dropdown">
												<!--	Lorem ipsum dolor sit amet, consectetur adipiscing elit.
													Lorem ipsum dolor sit amet, consectetur adipiscing elit.
													Lorem ipsum dolor sit amet, -->
													
												 </div>
											  </li>
											  <li class="<?php if($od['stage'] >= '2'){echo 'vert-sel'; }?>">
												<div class="dot-box <?php if($od['stage'] >= '2'){echo 'check-box';} ?>">
												  <?php if($od['stage'] >= '2'){ ?>
												  <span class="fa fa-check"></span>
												<?php } ?>
												</div>
												<span class="iner-box">
													Tiek remontēts|
												 </span>
												 <div class="timeline-dropdown">
													<!--Lorem ipsum dolor sit amet, consectetur adipiscing elit.
													Lorem ipsum dolor sit amet, consectetur adipiscing elit.
													Lorem ipsum dolor sit amet,-->
													
												 </div>
											  </li>
											  <li class="<?php if($od['stage'] >= '3'){echo 'vert-sel'; }?>">
												<div class="dot-box <?php if($od['stage'] >= '3'){echo 'check-box';} ?>">
												   <?php if($od['stage'] >= '3'){ ?><span class="fa fa-check"></span><?php } ?></div>
												<span class="iner-box">
													Ierīce salabota
												 </span> 
												 <div class="timeline-dropdown">
													<!--Lorem ipsum dolor sit amet, consectetur adipiscing elit.
													Lorem ipsum dolor sit amet, consectetur adipiscing elit.
													Lorem ipsum dolor sit amet, -->
													
												 </div> 
											  </li>
											  <li class="<?php if($od['stage'] >= '4'){echo 'vert-sel'; }?>">
												<div class="dot-box <?php if($od['stage'] >= '4'){echo 'check-box';} ?>">
												   <?php if($od['stage'] >= '4'){ ?>
													<span class="fa fa-check"></span>
												 
												 <?php
											   }
											   ?>
											   </div>
												<span class="iner-box">
												  Nodota Kurjieram
												 </span>
												 <div class="timeline-dropdown">
													<!--Lorem ipsum dolor sit amet, consectetur adipiscing elit.
													Lorem ipsum dolor sit amet, consectetur adipiscing elit.
													Lorem ipsum dolor sit amet,-->
													
												 </div>
											  </li>
											  
											</ul>
										  </div>
									  </div>
									</div>
									
                                    </div>
                                </div>
                            </div>
                          
                        </div>
                        
                         <div class="clearfix"></div>
                <div class="order-wraper extra-info">
                	<div class="col-md-12">
                    	 <h2 class="title-1">Comments</h2>
                    </div>
                    <div class="clearfix"></div>
                    <div class="col-sm-12">
					<div class="error-message1"></div>
                    	<div class="edit-track-box">
                        	<div class="row">
                            	<div class="col-md-12">
                                	<textarea id="comment"></textarea>
                                </div>
                        	</div>                            
                        </div>
                        <div class="edit-track-btn">
                        	<button type="button" id="submit" class="track-btn">SUBMIT</button>
                        </div>
				
                    </div>
                </div>
                       
<script>
	$(document).on('click','#complete', function(){
	
	var data = new Object();
	data['stage'] = $('#stage').val().trim();
	data['order_id']=$('#order_id').val().trim();
	$('.error_message_stage').html('<div class="alert alert-warning">Completing Stage.....</div>').show();
	$('#complete').attr('disabled', 'disabled');
	$.post('complete', {data:data}, function(){
		$('#complete').removeAttr('disabled');
		$('.error_message_stage').html('<div class="alert alert-success">Stage Completed Successfully</div>');
	 location.reload();

	},'json').fail(function(xhr) {
		$('#complete').removeAttr('disabled');
		
        var html = '';
        var res = xhr.responseJSON;
        $(res).each(function(i, value){
                html+= '<p>' + value + '</p>';
        });
        $('.error_message_stage').html('<div class="alert alert-danger">' + html + ' </div>').show();
        window.location.href = '#body';
    },'json');
});
</script>
<script>
	$(document).on('click','#submit', function(){
	
	var data = new Object();
	data['comment'] = $('#comment').val().trim();
data['order_id']=$('#order_id').val().trim();
	$('.error-message1').html('<div class="alert alert-warning">Processing.....</div>').show();
	$('#submit').attr('disabled', 'disabled');
	$.post('comment', {data:data}, function(){
		$('#submit').removeAttr('disabled');
		$('.error-message1').html('<div class="alert alert-success">Comment Updated</div>');
	

	},'json').fail(function(xhr) {
		$('#submit').removeAttr('disabled');
		
        var html = '';
        var res = xhr.responseJSON;
        $(res).each(function(i, value){
                html+= '<p>' + value + '</p>';
        });
        $('.error-message1').html('<div class="alert alert-danger">' + html + ' </div>').show();
        window.location.href = '#body';
    },'json');
});
</script>
  <?php
  include 'footer.php';
  ?>