<?php  include('techsyn_header.php'); ?>    
<!-- Main Content Container for side bar and body-->
<div class="main-container ace-save-state" id="main-container">
		<script type="text/javascript">
			try{ace.settings.loadState('main-container')}catch(e){}
		</script>
<?php  include('techsyn_sidebar.php'); ?>
<?php  

$id = $_POST['flex_opd_id'];
$query = "select * from employee where id = '".$id."' ";
if (!$result = @mysqli_query($conn,$query)) {
            die(mysqli_error($conn));
    	
} else{
		$row=@mysqli_fetch_array($result);
		@extract($row);
}
 ?>
<!--breadcrumb-->
<div class="main-content">
    <div class="main-content-inner">
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="#">Home</a>
                </li>
                <li class="#">Patient Visit</li><li class="active">History</li><li class="success"><label class="blue"><?php  echo $fname?> <?php  echo $lname?>(<?php  echo $emp_code?>)</label>
            </ul>
			<div class="nav-search" id="nav-search" style="width:170px;">
				<form id="flex_form_opd">
						<input type="hidden" name="opd_id"id="flex_opd_id">
						<select class="chosen-select form-control" id="emp_list"name="emp_list" data-placeholder="Goto Employee.." onchange="history(this.value)">
							<option></option>
							<?php 
							$sql_emp="SELECT id, CONCAT(fname, ' ', lname, '-', emp_code) AS emp_details FROM employee order by fname";
							generate_options($sql_emp,'','id','emp_details','id',$id);
							?>
						</select>
				</form>
			</div>
        </div>
        <!-- End of breadcrumb -->
		
             	<div class="row">
				<div class="col-xs-12">
					<div class="widget-box">
						
						<div class="widget-body">
							<div class="widget-main">
								<div class="row">
								<div style="margin:5px;">
									<div class="tabbable">
										<ul class="nav nav-tabs" id="myTab">
											
											<li class="active">
												<a data-toggle="tab" href="#history" aria-expanded="false" class="tab-pane fade in active" >
													History
													<span class="badge badge-danger">4</span>
												</a>
											</li>
										</ul>
									
										<div class="tab-content">
											
											<div id="history" class="tab-pane fade in active ">
												<button style="position:relative; left:1100px; bottom:60px;"><a style="all: unset" href="injury_pdf.php" target="_blank">PDF</a></button>
<button style="position:relative; left:1010px; bottom:60px;"><a style="all: unset" href="excel_opd.php" target="_blank">EXCEL</a></button>
<?php 
$sql_history="select * from employee_appointment where emp_id='".$_REQUEST['opd_id']."' order by appointment_date desc";
$result_history = mysqli_query($conn,$sql_history);	
$num_rows=@mysqli_num_rows($result_history);
?>
<script>$(".badge-danger").html(<?php  echo $num_rows?>)</script>
									
<div class="row">
	<div class="col-xs-12">
		<table id="simple-table" class="table  table-bordered table-hover">
			

			<tbody>
			<?php if($num_rows>0){
				?>
				<thead>
					<tr>
						
					
						<th><i class="ace-icon fa fa-clock-o bigger-110 hidden-480"></i>Date</th>
						<th>Complaints/Injury Details</th>
						<th class="hidden-480">Examination Findings</th>
						<th class="hidden-480">Diagnosis/Injury Type</th>
						<th class="hidden-480">Treatments</th>
						
						<th>Referral</th>
						<th class="hidden-480">Follow-up</th>
						<th class="hidden-480">Remarks</th>
						<th></th>
					</tr>
				</thead>
				<?php 
				while($row_history=@mysqli_fetch_array($result_history))
				{
					extract($row_history);
					$appointmentType = $row_history['appointment_type'];
					
					
					
								
				?>

				<tr <?php if($appointmentType=='O'){?>class='warning'<?php }else if($appointmentType=='I'){?>class='danger'<?php }?>>
					

					
					


					<td>
						<?php  echo date_format(date_create($row_history['appointment_date']),"d-M-Y ")?>
					</td>
					<td><?php  echo $row_history['complaints']?></td>
					<td><?php  echo $row_history['examination_remarks']?></td>
					<td><?php  echo ($appointmentType=='O')?getCommaSeperatedValuesForInClause("select ailment_name from ailment ","ailment_id",$row_history['ailment_ids']):getCommaSeperatedValuesForInClause("select injury_type_name from injury_type ","injury_type_id",$row_history['injury_types'])?></td>
					<td><?php  echo $row_history['referral']?></td>

					
					<td></td>
					
					<td><?php  echo $row_history['followup']?></td>
					<td><?php  echo $row_history['remarks']?></td>
					<td>
														<div class="hidden-sm hidden-xs btn-group">
															<button class="btn btn-xs btn-success" onclick="validate_update('opd_form<?php  echo $row_history['appointment_id']?>','<?php  echo $row_history['appointment_id']?>');">
																<i class="ace-icon fa fa-check bigger-120"></i>
															</button>

															<button class="btn btn-xs btn-info">
																<i class="ace-icon fa fa-pencil bigger-120"></i>
															</button>

															<button class="btn btn-xs btn-danger" onclick="delete_appointment('<?php $row_history['appointment_id']?>')">
																<i class="ace-icon fa fa-trash-o bigger-120"></i>
															</button>

														
														</div>

														<div class="hidden-md hidden-lg">
															<div class="inline pos-rel">
																<button class="btn btn-minier btn-primary dropdown-toggle" data-toggle="dropdown" data-position="auto">
																	<i class="ace-icon fa fa-cog icon-only bigger-110"></i>
																</button>

																<ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
																	<li>
																		<a href="#" class="tooltip-info" data-rel="tooltip" title="" data-original-title="View">
																			<span class="blue">
																				<i class="ace-icon fa fa-search-plus bigger-120"></i>
																			</span>
																		</a>
																	</li>

																	<li>
																		<a href="#" class="tooltip-success" data-rel="tooltip" title="" data-original-title="Edit">
																			<span class="green">
																				<i class="ace-icon fa fa-pencil-square-o bigger-120"></i>
																			</span>
																		</a>
																	</li>

																	<li>
																		<a href="#" class="tooltip-error" data-rel="tooltip" title="" data-original-title="Delete">
																			<span class="red">
																				<i class="ace-icon fa fa-trash-o bigger-120"></i>
																			</span>
																		</a>
																	</li>
																</ul>
															</div>
														</div>
													</td>
				</tr>

				<tr class="detail-row">
					<td colspan="10">
						<div class="table-detail">
							<div class="row">
								<?php 
								if($row_history['appointment_type']=='O'){
									include('opd_entry_embed.php'); 
								}else if($row_history['appointment_type']=='I'){
									include('injury_entry_embed.php'); 
								}?>
							</div>
						</div>
					</td>
				</tr>
			<?php }}else{?>
			<tr>
			
			<td>No Past History found for the employee</td>
			</tr>
			
			<?php }?>
				
			</tbody>
		</table>
	</div><!-- /.span -->
	</div>
<script>
function validate_update(formId, appointment_id){
	var appointment_date = $('#appointment_date'+appointment_id).val();
	if(appointment_date == ''){
		BootstrapDialog.alert('Please Enter Appointment Name.!!!');
		return false;
	}
	var complaints = $('#complaints'+appointment_id).val();
	if(complaints == ''){
		BootstrapDialog.alert('Please Enter Complaints.!!!');
		return false;
	}
	update_appointment(formId, appointment_id);
}
function update_appointment(formId, appointment_id){
	$.ajax({
				url : 'save_opd.php',
				type : "POST",
				data : $("#"+formId).serialize(),
				success : function(data) {
					var data = $.parseJSON(data);
					//alert(data);
					if(data.appointment_id!=null){
						$("#appointment_id"+appointment_id).val(data.appointment_id);
					}
					
					BootstrapDialog.alert('Injury Details Updated Successfully.');
					//location.reload();
					return;
				},
				error : function(data) {
					BootstrapDialog.alert('Error Updating Injury Details');
					return;
				}
		});
}
/*
function validate(){
	var appointment_date = $('#appointment_date').val();
	if(appointment_date == ''){
		BootstrapDialog.alert('Please Enter Appointment Name.!!!');
		return false;
	}
	var complaints = $('#complaints').val();
	if(complaints == ''){
		BootstrapDialog.alert('Please Enter Complaints.!!!');
		return false;
	}
	save_appointment();
}*/
function save_appointment(){
	$.ajax({
				url : 'save_opd.php',
				type : "POST",
				data : $("#opd_form").serialize(),
				success : function(data) {
					var data = $.parseJSON(data);
					//alert(data);
					if(data.appointment_id!=null){
						$("#appointment_id").val(data.appointment_id);
					}
					
					BootstrapDialog.alert('Injury Details Saved Successfully.');
					//location.reload();
					return;
				},
				error : function(data) {
					BootstrapDialog.alert('Error Saving Injury Details');
					return;
				}
		});
}
</script>	
 
											</div>

											
										</div>
									</div><!--end tab table-->
										

								</div><!--end of inner row-->
								
							</div><!--end of widget-main -->
						</div><!--end of inner widgetbody-->
					</div><!--end of inner widgetbox-->
				</div><!--end of xs-->
			</div><!--end of inner widgetbody-->
				</div> 
<?php  include('techsyn_footer.php'); ?>    
	<script type="text/javascript">
		function history(id){
			//alert(id);
			if(id!=null && id!=''){
				$("#flex_opd_id").val(id);
				$("#flex_form_opd").attr('method', 'POST');
				$("#flex_form_opd").attr('action', 'history.php');
				$("#flex_form_opd").submit();
			}

		}
			jQuery(function($) {
				//initiate dataTables plugin
				var myTable = 
				$('#dynamic-table')
				//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
				.DataTable( {
					bAutoWidth: false,
					"aoColumns": [
					  { "bSortable": false },
					  null, null,null, null, null,
					  { "bSortable": false }
					],
					"aaSorting": [],
					
					
					//"bProcessing": true,
			        //"bServerSide": true,
			        //"sAjaxSource": "http://127.0.0.1/table.php"	,
			
					//,
					//"sScrollY": "200px",
					//"bPaginate": false,
			
					//"sScrollX": "100%",
					//"sScrollXInner": "120%",
					//"bScrollCollapse": true,
					//Note: if you are applying horizontal scrolling (sScrollX) on a ".table-bordered"
					//you may want to wrap the table inside a "div.dataTables_borderWrap" element
			
					//"iDisplayLength": 50
			
			
					select: {
						style: 'multi'
					}
			    } );
			
				
				/*
				$.fn.dataTable.Buttons.defaults.dom.container.className = 'dt-buttons btn-overlap btn-group btn-overlap';
				
				new $.fn.dataTable.Buttons( myTable, {
					buttons: [
					  {
						"extend": "colvis",
						"text": "<i class='fa fa-search bigger-110 blue'></i> <span class='hidden'>Show/hide columns</span>",
						"className": "btn btn-white btn-primary btn-bold",
						columns: ':not(:first):not(:last)'
					  },
					  {
						"extend": "copy",
						"text": "<i class='fa fa-copy bigger-110 pink'></i> <span class='hidden'>Copy to clipboard</span>",
						"className": "btn btn-white btn-primary btn-bold"
					  },
					  {
						"extend": "csv",
						"text": "<i class='fa fa-database bigger-110 orange'></i> <span class='hidden'>Export to CSV</span>",
						"className": "btn btn-white btn-primary btn-bold"
					  },
					  {
						"extend": "excel",
						"text": "<i class='fa fa-file-excel-o bigger-110 green'></i> <span class='hidden'>Export to Excel</span>",
						"className": "btn btn-white btn-primary btn-bold"
					  },
					  {
						"extend": "pdf",
						"text": "<i class='fa fa-file-pdf-o bigger-110 red'></i> <span class='hidden'>Export to PDF</span>",
						"className": "btn btn-white btn-primary btn-bold"
					  },
					  {
						"extend": "print",
						"text": "<i class='fa fa-print bigger-110 grey'></i> <span class='hidden'>Print</span>",
						"className": "btn btn-white btn-primary btn-bold",
						autoPrint: false,
						message: 'This print was produced using the Print button for DataTables'
					  }		  
					]
				} );
				myTable.buttons().container().appendTo( $('.tableTools-container') );
				*/
				//style the message box
				var defaultCopyAction = myTable.button(1).action();
				myTable.button(1).action(function (e, dt, button, config) {
					defaultCopyAction(e, dt, button, config);
					$('.dt-button-info').addClass('gritter-item-wrapper gritter-info gritter-center white');
				});
				
				
				var defaultColvisAction = myTable.button(0).action();
				myTable.button(0).action(function (e, dt, button, config) {
					
					defaultColvisAction(e, dt, button, config);
					
					
					if($('.dt-button-collection > .dropdown-menu').length == 0) {
						$('.dt-button-collection')
						.wrapInner('<ul class="dropdown-menu dropdown-light dropdown-caret dropdown-caret" />')
						.find('a').attr('href', '#').wrap("<li />")
					}
					$('.dt-button-collection').appendTo('.tableTools-container .dt-buttons')
				});
			
				////
			
				setTimeout(function() {
					$($('.tableTools-container')).find('a.dt-button').each(function() {
						var div = $(this).find(' > div').first();
						if(div.length == 1) div.tooltip({container: 'body', title: div.parent().text()});
						else $(this).tooltip({container: 'body', title: $(this).text()});
					});
				}, 500);
				
				
				
				
				
				myTable.on( 'select', function ( e, dt, type, index ) {
					if ( type === 'row' ) {
						$( myTable.row( index ).node() ).find('input:checkbox').prop('checked', true);
					}
				} );
				myTable.on( 'deselect', function ( e, dt, type, index ) {
					if ( type === 'row' ) {
						$( myTable.row( index ).node() ).find('input:checkbox').prop('checked', false);
					}
				} );
			
			
			
			
				/////////////////////////////////
				//table checkboxes
				$('th input[type=checkbox], td input[type=checkbox]').prop('checked', false);
				
				//select/deselect all rows according to table header checkbox
				$('#dynamic-table > thead > tr > th input[type=checkbox], #dynamic-table_wrapper input[type=checkbox]').eq(0).on('click', function(){
					var th_checked = this.checked;//checkbox inside "TH" table header
					
					$('#dynamic-table').find('tbody > tr').each(function(){
						var row = this;
						if(th_checked) myTable.row(row).select();
						else  myTable.row(row).deselect();
					});
				});
				
				//select/deselect a row when the checkbox is checked/unchecked
				$('#dynamic-table').on('click', 'td input[type=checkbox]' , function(){
					var row = $(this).closest('tr').get(0);
					if(this.checked) myTable.row(row).deselect();
					else myTable.row(row).select();
				});
			
			
			
				$(document).on('click', '#dynamic-table .dropdown-toggle', function(e) {
					e.stopImmediatePropagation();
					e.stopPropagation();
					e.preventDefault();
				});
				
				
				
				//And for the first simple table, which doesn't have TableTools or dataTables
				//select/deselect all rows according to table header checkbox
				var active_class = 'active';
				$('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
					var th_checked = this.checked;//checkbox inside "TH" table header
					
					$(this).closest('table').find('tbody > tr').each(function(){
						var row = this;
						if(th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
						else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
					});
				});
				
				//select/deselect a row when the checkbox is checked/unchecked
				$('#simple-table').on('click', 'td input[type=checkbox]' , function(){
					var $row = $(this).closest('tr');
					if($row.is('.detail-row ')) return;
					if(this.checked) $row.addClass(active_class);
					else $row.removeClass(active_class);
				});
			
				
			
				/********************************/
				//add tooltip for small view action buttons in dropdown menu
				$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
				
				//tooltip placement on right or left
				function tooltip_placement(context, source) {
					var $source = $(source);
					var $parent = $source.closest('table')
					var off1 = $parent.offset();
					var w1 = $parent.width();
			
					var off2 = $source.offset();
					//var w2 = $source.width();
			
					if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
					return 'left';
				}
				
				
				
				
				/***************/
				$('.show-details-btn').on('click', function(e) {
					e.preventDefault();
					$(this).closest('tr').next().toggleClass('open');
					$(this).find(ace.vars['.icon']).toggleClass('fa-angle-double-down').toggleClass('fa-angle-double-up');
				});
				/***************/
				
				
				
				
				
				/**
				//add horizontal scrollbars to a simple table
				$('#simple-table').css({'width':'2000px', 'max-width': 'none'}).wrap('<div style="width: 1000px;" />').parent().ace_scroll(
				  {
					horizontal: true,
					styleClass: 'scroll-top scroll-dark scroll-visible',//show the scrollbars on top(default is bottom)
					size: 2000,
					mouseWheelLock: true
				  }
				).css('padding-top', '12px');
				*/
			
			
			})
		</script>