<?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  
error_reporting(E_ERROR | E_PARSE);
$id = $_REQUEST['flex_opd_id'];
$query = "select * from patient_master where id = '".$id."' ";
//echo $query;

if (!$result = @mysqli_query($conn,$query)) {
            die(mysqli_error($conn));
    	
} else{
		$row=@mysqli_fetch_array($result);
		@extract($row);
}
$page = $_REQUEST['page'];
 ?>
    <!--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">Injury</li>
                </ul>

            </div>

            <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 id="appoint" class="active">
                                                    <a data-toggle="tab" href="#appointment" aria-expanded="false">
                                                        New Injury
                                                        <span class="badge badge-success">+</span>
                                                    </a>
                                                </li>

                                                <!-- <li class="">
														<a data-toggle="tab" href="#home" aria-expanded="false">
															<i class="green ace-icon fa fa-user bigger-120"></i>
															<?php  echo $patient_name?>'s Profile
														</a>
													</li> -->


                                                <?php 
													 $flex_opd_id=$_REQUEST['flex_opd_id'];
													 
													$sql="select * from employee_appointment where emp_id='".$flex_opd_id."' ";
	                                                   $result = mysqli_query($conn,$sql);	
	                                                   $row1=mysqli_fetch_array($result);
	                                                   $num_rows=@mysqli_num_rows($result);
													    if($num_rows=="" || $num_rows==null)
															 $num_rows=0;
													   ?>



                                                <li id="histo" class="">
                                                    <a data-toggle="tab" href="#history" aria-expanded="false">
                                                        History
                                                        <span class="badge badge-danger"
                                                            id="history_record"><?php  echo $num_rows?></span>
                                                    </a>
                                                </li>

                                            </ul>

                                            <div class="tab-content">
                                                <div id="appointment" class="tab-pane fade in active ">
                                                    <?php 

                                                      $Rolecodes= explode(',',$_SESSION ['RoleCode']) ;
														
                                                      $_REQUEST['appointmentId'] = $app_id = $_REQUEST['followup_to_opd'] != '' ? $_REQUEST['followup_to_opd'] : $_REQUEST['appointmentId'];

                                                      error_log('xxx -'. $app_id);
  
                                                      if (isset( $app_id)) {
                                                          if(($_REQUEST['followup_to_opd'] != '' && $_REQUEST['followup_to_opd'] != null)){
                                                              $docAttended = getFieldFromTable("doctor_attended_flag", "followup_details", "followup_id", $_REQUEST['followup_id']); 
                                                             }else{
                                                              $docAttended = getFieldFromTable("doctor_attended_flag", "employee_appointment", "appointment_id", $_REQUEST['appointmentId']);
                                                             }
                                                          
                                                      }
                                                      error_log('xxx -'.$docAttended);
														
														if (('DIS' == $_SESSION ['RoleCode'] || in_array('DIS', $Rolecodes)) && $docAttended == "Y") {
															include('dispensary_view_injury.php');  
														}else{
														include('employee_injury_form_noprice.php');
														} ?>

                                                </div>
                                                <!-- <div id="home" class="tab-pane fade">
														 
													</div> -->
                                                <div id="history" class="tab-pane fade">
                                                    <?php  include('appointment_history.php'); ?>
                                                </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>



        </div>
        <!--end of outer col-xs-12">-->
    </div>
    <!--end of outer row-->
</div>



<?php  include('techsyn_footer.php'); ?>
<script type="text/javascript">
$(document).ready(function() {
    /*var page = <?php  echo $page?>;
    if(page=="employee_injury"){
    	 $( '#appoint' ).removeClass( 'active' );
    	 $( '#histo' ).addClass( 'active' );
    	 $( '#appointment' ).removeClass( 'in active' );
                $( '#history' ).addClass( 'in active' );
    			      
    			//alert('hello');
    }*/
});

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'
            }
        });



    //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>