<?php require '../controller/session.php'; ?>
<?php include 'controller/admissionCode.php'; ?>
<?php require_once("inc/init.php"); ?>
<?php include 'csvAttend.php'; ?>
<div class="row">
	<div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
		<h1 class="page-title txt-color-blueDark">
			<i class="fa fa-table fa-fw "></i> 
				Report
			<span>> 
				All class_students
			</span>
		</h1>
	</div>

</div>
<div class="row">
			<div class="col-md-4"></div>
			<div class="col-md-4">
				
			<form enctype="multipart/form-data" id="import-csv" onsubmit="return false;" method="POST" action="index.php#ajax/set_remark.php">
				<div class="form-group">
					<input type="hidden" name="csv" value="ok">

					<input type="file" class="form-control" name="file" id="file">
<input type="submit" class="form-control btn btn-primary" id="import" value="Import Students Remarks">
				</div>
			</form>
			</div>
			<div class="col-md-4"></div>
			
		</div>
<!-- widget grid -->
<section id="widget-grid" class="">

	<!-- row -->
	<div class="row">
		<!-- <article class="col-xs-12 col-sm-12 col-md-12 col-lg-2"></article> -->
		<!-- NEW WIDGET START -->
		<article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

			<!-- Widget ID (each widget will need unique ID)-->
			<div class="jarviswidget jarviswidget-color-blueDark"  id="wid-id-3"  data-widget-editbutton="false" data-widget-deletebutton="false">
				<!-- widget options:
				usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

				data-widget-colorbutton="false"
				data-widget-editbutton="false"
				data-widget-togglebutton="false"
				data-widget-deletebutton="false"
				data-widget-fullscreenbutton="false"
				data-widget-custombutton="false"
				data-widget-collapsed="true"
				data-widget-sortable="false"

				-->
				<header>
					<span class="widget-icon"> <i class="fa fa-table"></i> </span>
					<h2>Export to PDF / Excel</h2>

				</header>

				<!-- widget div-->
				<div>

					<!-- widget edit box -->
					<div class="jarviswidget-editbox">
						<!-- This area used as dropdown edit box -->

					</div>
					<!-- end widget edit box -->

					<!-- widget content -->
					<div class="widget-body no-padding">

						<table id="datatable_tabletools" class="table table-striped table-bordered table-hover" width="100%">
							<thead>

								<tr>
									<th>S/N</th>
									<th data-hide="phone,tablet">Index No</th>
									<th data-class="expand"> Name</th>
									<th data-hide="phone,tablet"> Class</th>
									<th data-hide="phone,tablet"> Attitude</th>
									<th data-hide="phone,tablet"> Interest</th>
									<th> Conduct</th>
									<th> Attendance</th>
									<th data-hide="phone,tablet"> Action</th>
								</tr>
							</thead>
							
							<tbody>
									<?php 
								if ($form_students) {
									$i = 0;
									foreach ($form_students as $key) {
										$i++;
										$track = $admission->get_student_track($key['track']);
										   $attendance = $admission->get_attendance($key['student_id'],$std_form_id,$semester_id,$a_year_id);

									?>
									<tr>
									<td><?php echo $i; ?></td>
									<td><?php echo $key['student_id']; ?></td>
									<td><?php echo $key['student_name']; ?></td>
									<td><?php echo $key['class_name']; ?></td>
									<td id="showA<?php echo $key['student_id']?>"><?php echo $attendance[0]['attitude']; ?></td>
									<td id="showI<?php echo $key['student_id']?>"><?php echo $attendance[0]['interest']; ?></td>
									<td id="showC<?php echo $key['student_id']?>">
										<?php echo $attendance[0]['conduct']; ?>
									</td>
									<td id="show<?php echo $key['student_id']?>">
									<?php echo $attendance[0]['attendance']; ?>
                                                                        </td>
									<td><button class="btn btn-xs btn-success" data-toggle="modal" data-target="#<?php echo $key['student_id']; ?>">attendance</button></td>
								</tr>
								
								<div class="modal fade" id="<?php echo $key['student_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
									&times;
								</button>
								<h4 class="modal-title" id="myModalLabel"><?php echo $key['student_name']; ?> </h4>
							</div>
							<div class="modal-body">
				<style type="text/css">
	::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
    color: #fff;
    opacity: 1; /* Firefox */
}
</style>	
								<div class="row">
									<div class="col-md-12">
										<div class="well well-sm well-primary">
											<form class="form form-inline" action=""  onsubmit="//return false;" id="checkout-form<?php echo $key['student_id']; ?>" method="POST" role="form">
												

												<fieldset>
												<h5>Set Number of Days Present</h5>
													<div class="form-group">
													<input type="number" id="attendance<?php echo $key['student_id']; ?>" class="form-control" placeholder="Student's Attendance" name="">
													<input type="hidden" id="class<?php echo $key['student_id']; ?>" value="<?php echo $key['class'] ?>">

												</div>
												</fieldset>
												<fieldset>
												<h5>Conduct</h5>
													<div class="form-group">
													<input type="text" id="conduct<?php echo $key['student_id']; ?>" class="form-control" placeholder="Student's Conduct" name="">

												</div>
												</fieldset>
												<fieldset>
												<h5>Interest</h5>
													<div class="form-group">
													<input type="text" id="interest<?php echo $key['student_id']; ?>" class="form-control" placeholder="Student's Interest" name="">

												</div>
												</fieldset>
												<fieldset>
												<h5>Attitude</h5>
													<div class="form-group">
													<input type="text" id="attitude<?php echo $key['student_id']; ?>" class="form-control" placeholder="Student's Attitude" name="">

												</div>
												</fieldset>
												<div class="form-group">
													<input type="hidden" id="set<?php echo $key['student_id'] ?>" value="<?php echo $key['student_id'] ?>">
													<input type="submit" id="remark<?php echo $key['student_id'] ?>" class="btn btn-primary btn-sm" value="Save">
														
												</div>
											</form>
										</div>
									</div>
								</div>
				
							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">
									Cancel
								</button>
								
							</div>
						</div><!-- /.modal-content -->
					</div><!-- /.modal-dialog -->
				</div><!-- /.modal -->
				<script type="text/javascript">
				$("#remark<?php echo $key['student_id'] ?>").click(function(){
                                var attendance = $("#attendance<?php echo $key['student_id'] ?>").val();
                                var conduct = $("#conduct<?php echo $key['student_id'] ?>").val();
                                var attitude = $("#attitude<?php echo $key['student_id'] ?>").val();
                                var interest = $("#interest<?php echo $key['student_id'] ?>").val();
								var student_id = $("#set<?php echo $key['student_id'] ?>").val();
								var std_class = $("#class<?php echo $key['student_id'] ?>").val();
								var attendance_id = '<?php echo $attendance[0]['attendance_id']; ?>';

				var data = {
                                  student_id:student_id,
                                  attendance:attendance,
                                  std_class:std_class,
                                  interest:interest,
                                  conduct:conduct,
                                  attitude:attitude,
                                  attendance_id:attendance_id,
                                  set:''
                                  };
                                  $.post('ajax/set_remark.php',data,function(res){
                                  	
                                              $("#show<?php echo $key['student_id']?>").text(attendance);
                                               $("#showI<?php echo $key['student_id']?>").text(interest);
                                                $("#showA<?php echo $key['student_id']?>").text(attitude);
                                                 $("#showC<?php echo $key['student_id']?>").text(conduct);
                                    });
                                  });

				</script>
									<?php
									}
								}
								 ?>
								
							</tbody>
						</table>

					</div>
					<!-- end widget content -->

				</div>
				<!-- end widget div -->

			</div>
			<!-- end widget -->

		</article>
		<!-- WIDGET END -->
		<!-- <article class="col-xs-12 col-sm-12 col-md-12 col-lg-2"></article> -->
	</div>

	<!-- end row -->

	<!-- end row -->

</section>
<!-- end widget grid -->
	<!-- PAGE RELATED PLUGIN(S) -->
		
<script type="text/javascript">

	/* DO NOT REMOVE : GLOBAL FUNCTIONS!
	 *
	 * pageSetUp(); WILL CALL THE FOLLOWING FUNCTIONS
	 *
	 * // activate tooltips
	 * $("[rel=tooltip]").tooltip();
	 *
	 * // activate popovers
	 * $("[rel=popover]").popover();
	 *
	 * // activate popovers with hover states
	 * $("[rel=popover-hover]").popover({ trigger: "hover" });
	 *
	 * // activate inline charts
	 * runAllCharts();
	 *
	 * // setup widgets
	 * setup_widgets_desktop();
	 *
	 * // run form elements
	 * runAllForms();
	 *
	 ********************************
	 *
	 * pageSetUp() is needed whenever you load a page.
	 * It initializes and checks for all basic elements of the page
	 * and makes rendering easier.
	 *
	 */

	pageSetUp();
	
	/*
	 * ALL PAGE RELATED SCRIPTS CAN GO BELOW HERE
	 * eg alert("my home function");
	 * 
	 * var pagefunction = function() {
	 *   ...
	 * }
	 * loadScript("js/plugin/_PLUGIN_NAME_.js", pagefunction);
	 * 
	 */
	
	// PAGE RELATED SCRIPTS
	
	// pagefunction	
	var pagefunction = function() {
		//console.log("cleared");
		
		/* // DOM Position key index //
		
			l - Length changing (dropdown)
			f - Filtering input (search)
			t - The Table! (datatable)
			i - Information (records)
			p - Pagination (paging)
			r - pRocessing 
			< and > - div elements
			<"#id" and > - div with an id
			<"class" and > - div with a class
			<"#id.class" and > - div with an id and class
			
			Also see: http://legacy.datatables.net/usage/features
		*/	

		/* BASIC ;*/
			var responsiveHelper_dt_basic = undefined;
			var responsiveHelper_datatable_fixed_column = undefined;
			var responsiveHelper_datatable_col_reorder = undefined;
			var responsiveHelper_datatable_tabletools = undefined;
			
			var breakpointDefinition = {
				tablet : 1024,
				phone : 480
			};

			$('#dt_basic').dataTable({
				"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-12 hidden-xs'l>r>"+
					"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
				"autoWidth" : true,
				"preDrawCallback" : function() {
					// Initialize the responsive datatables helper once.
					if (!responsiveHelper_dt_basic) {
						responsiveHelper_dt_basic = new ResponsiveDatatablesHelper($('#dt_basic'), breakpointDefinition);
					}
				},
				"rowCallback" : function(nRow) {
					responsiveHelper_dt_basic.createExpandIcon(nRow);
				},
				"drawCallback" : function(oSettings) {
					responsiveHelper_dt_basic.respond();
				}
			});

		/* END BASIC */
		
		/* COLUMN FILTER  */
	    var otable = $('#datatable_fixed_column').DataTable({
	    	//"bFilter": false,
	    	//"bInfo": false,
	    	//"bLengthChange": false
	    	//"bAutoWidth": false,
	    	//"bPaginate": false,
	    	//"bStateSave": true // saves sort state using localStorage
			"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6 hidden-xs'f><'col-sm-6 col-xs-12 hidden-xs'<'toolbar'>>r>"+
					"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
			"autoWidth" : true,
			"preDrawCallback" : function() {
				// Initialize the responsive datatables helper once.
				if (!responsiveHelper_datatable_fixed_column) {
					responsiveHelper_datatable_fixed_column = new ResponsiveDatatablesHelper($('#datatable_fixed_column'), breakpointDefinition);
				}
			},
			"rowCallback" : function(nRow) {
				responsiveHelper_datatable_fixed_column.createExpandIcon(nRow);
			},
			"drawCallback" : function(oSettings) {
				responsiveHelper_datatable_fixed_column.respond();
			}		
		
	    });
	    
	    // custom toolbar
	    $("div.toolbar").html('<div class="text-right"><img src="img/logo.png" alt="OT SmartAdmin" style="width: 111px; margin-top: 3px; margin-right: 10px;"></div>');
	    	   
	    // Apply the filter
	    $("#datatable_fixed_column thead th input[type=text]").on( 'keyup change', function () {
	    	
	        otable
	            .column( $(this).parent().index()+':visible' )
	            .search( this.value )
	            .draw();
	            
	    } );
	    /* END COLUMN FILTER */   
    
		/* COLUMN SHOW - HIDE */
		$('#datatable_col_reorder').dataTable({
			"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-6 hidden-xs'C>r>"+
					"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-sm-6 col-xs-12'p>>",
			"autoWidth" : true,
			"preDrawCallback" : function() {
				// Initialize the responsive datatables helper once.
				if (!responsiveHelper_datatable_col_reorder) {
					responsiveHelper_datatable_col_reorder = new ResponsiveDatatablesHelper($('#datatable_col_reorder'), breakpointDefinition);
				}
			},
			"rowCallback" : function(nRow) {
				responsiveHelper_datatable_col_reorder.createExpandIcon(nRow);
			},
			"drawCallback" : function(oSettings) {
				responsiveHelper_datatable_col_reorder.respond();
			}			
		});
		
		/* END COLUMN SHOW - HIDE */

		/* TABLETOOLS */
		$('#datatable_tabletools').dataTable({
			
			// Tabletools options: 
			//   https://datatables.net/extensions/tabletools/button_options
			"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-6 hidden-xs'T>r>"+
					"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-sm-6 col-xs-12'p>>",
	        "oTableTools": {
	        	 "aButtons": [
	             "copy",
	             "csv",
	             "xls",
	                {
	                    "sExtends": "pdf",
	                    "sTitle": "Students List",
	                    "sPdfMessage": "OT SMS PDF Export",
	                    "sPdfSize": "letter"
	                },
	             	{
                    	"sExtends": "print",
                    	"sMessage": "OTSMS Report <i>(press Esc to close)</i>"
                	}
	             ],
	            "sSwfPath": "js/plugin/datatables/swf/copy_csv_xls_pdf.swf"
	        },
			"autoWidth" : true,
			"preDrawCallback" : function() {
				// Initialize the responsive datatables helper once.
				if (!responsiveHelper_datatable_tabletools) {
					responsiveHelper_datatable_tabletools = new ResponsiveDatatablesHelper($('#datatable_tabletools'), breakpointDefinition);
				}
			},
			"rowCallback" : function(nRow) {
				responsiveHelper_datatable_tabletools.createExpandIcon(nRow);
			},
			"drawCallback" : function(oSettings) {
				responsiveHelper_datatable_tabletools.respond();
			}
		});
		
		/* END TABLETOOLS */

	};

	// load related plugins
	
	loadScript("js/plugin/datatables/jquery.dataTables.min.js", function(){
		loadScript("js/plugin/datatables/dataTables.colVis.min.js", function(){
			loadScript("js/plugin/datatables/dataTables.tableTools.min.js", function(){
				loadScript("js/plugin/datatables/dataTables.bootstrap.min.js", function(){
					loadScript("js/plugin/datatable-responsive/datatables.responsive.min.js", pagefunction)
				});
			});
		});
	});

$(document).ready(function(){
	$('#import').click(function(){
		 // var form = new FormData($("#import-csv")[0]);
		  var myFormData = new FormData();
myFormData.append('file', $('#file').prop('files')[0]);
var cid = ['<?php echo $std_class_id ?>'];

myFormData.append('cid',cid);
// var data = new FormData(form); 
   $.ajax({
            type: "POST",
            enctype: 'multipart/form-data',
            url: "ajax/set_remark.php",
            data: myFormData,
            processData: false,
            contentType: false,
            cache: false,
            timeout: 600000,
beforeSend: function(response){

    },
    complete: function(response){
       
    },
    success: function(response){
    	console.log(response);
    	if (response.charAt(0)==0) {
    		$.smallBox({
					title : "Students Attendance Imported successfully",
					content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
					color : "#000000",
					iconSmall : "fa fa-check bounce animated",
					timeout : 4000
				});
    	}else if (response.charAt(0)==1) {
    		$.smallBox({
					title : "Action Failed!",
					content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
					color : "#C46A69",
					iconSmall : "fa fa-check bounce animated",
					timeout : 4000
				});
    	}else if (response.charAt(0)==3) {
    		$.smallBox({
					title : "Internal Error!",
					content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
					color : "#C46A69",
					iconSmall : "fa fa-check bounce animated",
					timeout : 4000
				});
    	}
	}
    });
	});
});
</script>