<?php require '../controller/session.php'; ?>
<?php include 'controller/profileCode.php'; ?>
<?php require_once("inc/init.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> 
				View
			<span>> 
				Class
			</span>
		</h1>
	</div>

</div>
<style type="text/css">
	input{
		color:#000;
	}

</style>
<!-- widget grid -->
<section id="widget-grid" class="">

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

			<!-- 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-wrench"></i> </span>
					<h2>Assign Class(es) to Teachers</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">
						<div class="widget-body-toolbar">
							
							<div class="row">
								
								<div class="col-sm-6">
									<button id="enable" class="btn btn btn-default">
										enable / disable 
									</button>
								</div>
								<div class="col-sm-6 text-right">
									
									<div class="onoffswitch-container">
										<span class="onoffswitch-title">Auto Open Next</span> 
										<span class="onoffswitch">
											<input type="checkbox" class="onoffswitch-checkbox" id="autoopen">
											<label class="onoffswitch-label" for="autoopen"> 
												<span class="onoffswitch-inner" data-swchon-text="ON" data-swchoff-text="OFF"></span> 
												<span class="onoffswitch-switch"></span>
											</label> 
										</span> 
										
										
									</div>
									
								<!-- 	<div class="onoffswitch-container">
										<span class="onoffswitch-title">Open Inline</span> 
										<span class="onoffswitch">
											<input type="checkbox" class="onoffswitch-checkbox" id="inline">
											<label class="onoffswitch-label" for="inline"> 
												<span class="onoffswitch-inner" data-swchon-text="ON" data-swchoff-text="OFF"></span> 
												<span class="onoffswitch-switch"></span>
											</label> 
										</span>
									</div> -->	
									
								</div>
								
							</div>
								

						</div>

						<table id="datatable_tabletools" class="table table-striped table-bordered table-hover" width="100%">
							<tbody>
								<tr>
									<td>STAFF ID</td>
									<td>STAFF NAME</td>
									<td>FORM MASTER For</td>
								</tr>
								<?php 
								if ($all_staff) {
									foreach ($all_staff as $staffs) {
										// $classes = $staffs['class'];
										// $classesArray = "";
										// $countClasses = 0;
										// $classesArray6 = "";
										// $classesRow = $classes;
										// if($classesRow  != "" )  {
										// $classesArray = explode(",",$classesRow);
										// $countClasses = count($classesArray);
										// $classesArray18 = array_slice($classesArray, 0,18);

										// }
										$staff_classes = $profile->get_classes($staffs['staff_id']);
										// print_r($staff_classes);
										$countClasses = "";
										if ($countClasses) {
											$countClasses = count($staff_classes);
										}
								?>

								
								<tr>
									<td><?php echo $staffs['staff_id']; ?></td>
									<td><?php echo $staffs['last_name'].' '.$staffs['first_name']; ?></td>
									<td>
									<?php 
									$is_form_master_for = $profile->get_staff_forms($staffs['staff_id']);

									 ?>
										<input type="text" id="form_id<?php echo $staffs['staff_id']; ?>" value="<?php echo $is_form_master_for[0]['is_form_master'] ?>" class=""><button data-loading-text="&lt;i class='fa fa-refresh fa-spin'&gt;&lt;/i&gt; &nbsp; Saving..." class="btn btn-primary btn-xs pull-right" type="submit" id="save<?php echo $staffs['staff_id']; ?>" name="">
		Save <i class="fa fa-save fa-lg"></i>
										<a href=""></a>
									</td>
								</tr>

								<script type="text/javascript">
									$('#save<?php echo $staffs['staff_id']; ?>').click(function(){
										var form_id = $('#form_id<?php echo $staffs['staff_id']; ?>').val();
										var staff_id = '<?php echo $staffs['staff_id']; ?>';
										var data = {
											form_id:form_id,
											staff_id:staff_id,
											update_form:''
										};
										//console.log(data);
										$.post('ajax/form_master.php',data,function(res){
											var trimstr = res.trim();
								       			if (trimstr.charAt(0) == 0) {
								       				$.smallBox({
													title : "Class Master Assigned successfully",
													content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
													color : "#000000",
													iconSmall : "fa fa-check bounce animated",
													timeout : 4000
												});
								       			}
										});
									});
								</script>
								<?php
							
								}	
							}
								 ?>
					
							</tbody>
						</table>
						
						<input type="hidden" id="houses" value="<?php 
						if($houses){
							$no = count($houses);
							$i=0;
							
							foreach($houses as $house){
								$i++;
								if($i<$no){
									echo $house['house_id'].",";
								}else{
									echo $house['house_id'];
								}
							}
						}
						 ?>">
						

					</div>					</div>

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


		</article>
		<!-- WIDGET END -->
		<article class="col-xs-4 col-sm-4 col-md-4 col-lg-4" >
			<!-- 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" style="position: relative;">
			
				<header>
					<span class="widget-icon"> <i class="fa fa-info"></i> </span>
					<h2>Class Details</h2>

				</header>

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

					<!-- end widget edit box -->

					<!-- widget content -->
				<div class="widget-body">
						<div class="widget-body-toolbar">
							
							<div class="row">
								
								<div class="col-sm-6">
									
								</div>
								<div class="col-sm-6 text-right">
									
									<div class="onoffswitch-container">
									
										
										
									</div>
									
								<!-- 	<div class="onoffswitch-container">
										<span class="onoffswitch-title">Open Inline</span> 
										<span class="onoffswitch">
											<input type="checkbox" class="onoffswitch-checkbox" id="inline">
											<label class="onoffswitch-label" for="inline"> 
												<span class="onoffswitch-inner" data-swchon-text="ON" data-swchoff-text="OFF"></span> 
												<span class="onoffswitch-switch"></span>
											</label> 
										</span>
									</div> -->	
									
								</div>
								
							</div>
								

						</div>

						<table id="user" class="table table-bordered table-striped" style="clear: both">
							<tbody>
								<tr>
									<td>S/N</td>
									<td>Class Id</td>
									<td>House Name</td>
								</tr>
								<?php 
								$classes = $profile->get_class_list();
								if ($classes) {
									$i = 0;
									foreach($classes as $class){
										$i++;
										?>
										<tr>
											<td><?php echo $i; ?></td>
											<td><?php echo $class['class_id'] ?></td>
											<td><?php echo $class['class_name'] ?></td>
										</tr>
										<?php
									}
								}

								 ?>
				
					
							</tbody>
						</table>
						
						
						

					</div>					</div>

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

				
		</article>
	</div>
				
	
	<!-- end row -->

	<!-- end row -->

</section>
<!-- end widget grid -->

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


</script>
