<?php 
/*include_once "../ichat/admin/route.php";
require_once 'database.php';
if(isset($_SESSION[$elhash]) && $_SESSION[$elhash] != "") { 
    $random_hash = $_SESSION[$elhash];
} else {
    $random_hash = uniqid();
    $_SESSION[$elhash] = $random_hash;
}*/


session_start();
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';?>
<div class="ordes-content">
    <div class="container midle-order">
        <div class="row">
        	<?php include 'menu.php';?>
            <div class="col-md-9">
                <div class="order-wraper">
                	<div class="col-md-12">
                    	<h1>Edit Tracking</h1>
						<?php if($msg !=''){echo '<span class="alert alert-danger pull-left">'.$msg.'</span>';}?>
                    </div>
                    <div class="clearfix"></div>
                    <div class="col-sm-12">
                    	<div class="order-contact edit-track-con">
                        	<h2>ORDER: #<?php echo htmlspecialchars($od['id']);?></h2>
                            <div class="row">
							
                            	<div class="col-md-6">
                                <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" >
                                    	<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="track-btn">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 class="clearfix"></div>
                <div class="order-wraper extra-info">
                	<div class="col-md-12">
                    	<h1>Comments</h1>
                    </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>
            </div>
        </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';?>