<?php require_once("inc/init.php"); ?>
<?php include'controller/globalCode.php'; ?>

<div class="alert alert-block alert-success">
	<a class="close" data-dismiss="alert" href="#">×</a>
	<h4 class="alert-heading"><i class="fa fa-check-square-o"></i> Dashboard</h4>
	<p class="output">
	</p>
</div>

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

	<!-- row -->
	<div class="row">
		<article class="col-sm-12">
		

		</article>
	</div>

	<!-- end row -->

	<!-- row -->

	<div class="row">

		<article class="col-sm-12 col-md-12 col-lg-6">
			<div class="jarviswidget" id="wid-id-2" data-widget-colorbutton="false" data-widget-editbutton="false">
				<header>
					<span class="widget-icon"> <i class="fa fa-gears"></i> </span>
					<h2>Update Password</h2>
					
				</header>
				<!-- widget div-->
				<div>
					<!-- widget edit box -->
					<div class="jarviswidget-editbox">
						<div>
							<label>Title:</label>
							<input type="text" />
						</div>
					</div>
					<!-- end widget edit box -->
					<div class="widget-body no-padding">
					
					
					 <div class="row">
							<form onsubmit="return false;"  class="smart-form" novalidate="novalidate">
							<fieldset>
							<section class="col col-12">
								<label class="input">
								<input type="password" id="password" value="" placeholder="Password">
								<i></i> </label>
							</section><br><br><br>
							<footer>
							<input type="submit" id="update_credentials" class="btn btn-primary" value="Update Password">
							<input type="hidden" id="staff_id" value="<?php echo $_SESSION['staff_id'] ?>">
							</footer>
							</form>
						</div>
					
					
					</fieldset>
					</div>

				</div>
	
			</div>
		

		</article>

			 <?php if ($_SESSION['isAdmin']=='ADMIN'): ?>

			 	<article class="col-sm-12 col-md-12 col-lg-6">
			<div class="jarviswidget" id="wid-id-2" data-widget-colorbutton="false" data-widget-editbutton="false">
				<header>
					<span class="widget-icon"> <i class="fa fa-gears"></i> </span>
					<h2>Promote Students</h2>
					
				</header>
				<!-- widget div-->
				<div>
					<!-- widget edit box -->
					<div class="jarviswidget-editbox">
						<div>
							<label>Title:</label>
							<input type="text" />
						</div>
					</div>
					<!-- end widget edit box -->
					<div class="widget-body no-padding">
					
					<center><h5 style="color: red">Click this button once at the end of every academic year</h5></center>
					<center><input type="radio" id="activate"></center>
					<a href="http://localhost/otmain/index.php#ajax/dashboard.php?p@=''" id="this_button" style="padding: 5px" class="btn btn-primary pull-right hidden">Promote Students</a>
					
					
					</fieldset>
					</div>

				</div>
	
			</div>
		

		</article>


			 	<article class="col-sm-12 col-md-12 col-lg-6">
			<div class="jarviswidget" id="wid-id-2" data-widget-colorbutton="false" data-widget-editbutton="false">
				<header>
					<span class="widget-icon"> <i class="fa fa-gears"></i> </span>
					<h2>Send SMS to Parents (PTA)</h2>
					
				</header>
				<!-- widget div-->
				<div>
					<!-- widget edit box -->
					<div class="jarviswidget-editbox">
						<div>
							<label>Title:</label>
							<input type="text" />
						</div>
					</div>
					<!-- end widget edit box -->
					<div class="widget-body no-padding">
					
					
					 <div class="row">
							<form action="ajax/msg/pta.php" method="POST"  class="smart-form" novalidate="novalidate">
							<fieldset>
								<section class="col col-12">
										<label class="select">
											<select name="form" id="set_track" required="required" style="width:200px">
												<option value="" selected="" disabled=""> * Set Form</option>
												<option value="1">Form 1</option>
												<option value="2">Form 2</option>
												<option value="3">Form 3</option>
											</select> <i></i> </label>
											<!-- <input type="hidden" id="set_track" name="set_track" value="" > -->
									</section>
							</fieldset>
							<fieldset>
							<section class="col col-12">
							
								<label class="textarea"  class="form-control" >
								<textarea style="color: #fff;" style="width: 100%" cols="100" rows="10" name="msg" id="parent_msg"></textarea>
								<i></i> </label>
							</section><br><br><br>
							
							<input type="hidden" name="pta_sms">

							<input type="submit" id="" style="padding: 5px" class="btn btn-primary pull-right" value="Send SMS">
							
							</form>
						</div>
					</fieldset>
					
					
					</div>

				</div>
	
			</div>
		

		</article>

		<article class="col-sm-12 col-md-12 col-lg-6">
			<div class="jarviswidget" id="wid-id-2" data-widget-colorbutton="false" data-widget-editbutton="false">
				<header>
					<span class="widget-icon"> <i class="fa fa-gears"></i> </span>
					<h2>Send SMS to Teachers (PTA) </h2>
					
				</header>
				<!-- widget div-->
				<div>
					<!-- widget edit box -->
					<div class="jarviswidget-editbox">
						<div>
							<label>Title:</label>
							<input type="text" />
						</div>
					</div>
					<!-- end widget edit box -->
					<div class="widget-body no-padding">
					
					
					 <div class="row">
					
							<form action="ajax/msg/pta_tea.php" method="POST"  class="smart-form" novalidate="novalidate">
							 <fieldset>
							<section class="col col-12">
								<label class="textarea"  class="form-control" >Enter Message
								<textarea style="color: #fff;" style="width: 100%" name="msg" cols="100" rows="10" id="parent_msg"></textarea>
								<i></i> </label>
							</section><br><br><br>
							
							<input type="hidden" name="pta_tea_sms">
							<input type="submit" style="padding: 5px" id="" class="btn btn-primary pull-right" value="Send SMS">
							
							</form>
							
						</div>
					
					</fieldset>
					
					</div>

				</div>
	
			</div>
		

		</article>

		<article class="col-sm-12 col-md-12 col-lg-6">

			<!-- new widget -->
			<div class="jarviswidget" id="wid-id-2" data-widget-colorbutton="false" data-widget-editbutton="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-gears"></i> </span>
					<h2>Set Globals</h2>
					
				</header>

				<!-- widget div-->
				<div>
					<!-- widget edit box -->
					<div class="jarviswidget-editbox">
						<div>
							<label>Title:</label>
							<input type="text" />
						</div>
					</div>
					<!-- end widget edit box -->

					<div class="widget-body no-padding">
							<form  id="checkout-form3" onsubmit="return false;"  class="smart-form" novalidate="novalidate" enctype="multipart/form-data">

							<fieldset>
							
								    <div class="row">
										<section class="col col-6">
										<label class="select">
											<select name="set_a_year" id="set_a_year" required="required" >
												<option value="" selected="" disabled=""> * Set Academic Year</option>
												<?php 
												if ($a_years) {
													foreach($a_years as $key){
														?>
													<option value="<?php echo $key['a_year_id'] ?>" ><?php echo $key['a_year'] ?></option>	
														<?php
													}
												}
												 ?>
											</select> <i></i> </label>
											<!-- <input type="hidden" id="set_a_year" name="set_a_year" value="" > -->
									</section>
										<section class="col col-6">
										<label class="select">
											<select name="set_semester" id="set_semester" required="required" >
												<option value="" selected="" disabled=""> * Set Semester</option>
												
												<?php 
												if ($semesters) {
													foreach($semesters as $key){
														?>
													<option value="<?php echo $key['sem_id'] ?>" ><?php echo $key['sem_name'] ?></option>	
														<?php
													}
												}
												 ?>
											</select> <i></i> </label>
											<!-- <input type="hidden" id="set_semester" name="set_semester" value=""> -->
									</section>
										<section class="col col-6">
										<label class="select">
											<select name="set_track" id="set_track" required="required" >
												<option value="" selected="" disabled=""> * Set Track</option>
											<?php 
												if ($tracks) {
													foreach($tracks as $key){
														?>
													<option value="<?php echo $key['track_id'] ?>" ><?php echo $key['track_name'] ?></option>	
														<?php
													}
												}
												 ?>		
												
											</select> <i></i> </label>
											<!-- <input type="hidden" id="set_track" name="set_track" value="" > -->
									</section>
									<section class="col col-6">
										<label class="input">
											<input type="number" name="no_of_days" placeholder="No of Days"> <i></i> </label>
											<!-- <input type="hidden" id="set_track" name="set_track" value="" > -->
									</section>
									
								
								</div>
								
							</fieldset>


							

							<footer>
								<input type="hidden" name="set_global">
							<input type="submit" id="set_global" class="btn btn-primary" value="Set Globals">

							</footer>
							<hr>
							<br>
						</form>
						<?php 
						$vacation = $global->get_vacation();
						 ?>
						<form onsubmit="return false;"  class="smart-form" novalidate="novalidate">
							
								<section class="col col-6">
										<label class="input">Vacation Date
											<input type="text" id="end" value="<?php echo $vacation[0]['end'] ?>" placeholder="Enter Vacation Date">
										</label>
											<!-- <input type="hidden" id="set_track" name="set_track" value="" > -->
									</section>

									<section class="col col-6">
										<label class="input">Resuming Date
											<input type="text" id="next" value="<?php echo $vacation[0]['next'] ?>" placeholder="Enter Resuming Date">
										</label>
											<!-- <input type="hidden" id="set_track" name="set_track" value="" > -->
									</section>
							<footer>
									<input type="submit" id="setVacation" class="btn btn-primary" value="Save">
							</footer>
						</form>
						<?php $promoteAll = $global->get_promotion_status(); ?>
						<form onsubmit="return false;"  class="smart-form hidden" novalidate="novalidate">
							
								<section class="col col-6">
										<label class="select">Promote All
											<select name="promoteAll" id="promoteAll" required="required" >
												
											<?php 
												if ($promoteAll) {

													foreach($promoteAll as $key){
														$name = '';
													if ($key['promote_all']==1) {
														$name = 'Yes';
														?>
														<option value="<?php echo $key['promote_all'] ?>" ><?php echo $name ?></option>
														<option value="0" >No</option>
														<?php
													}elseif($key['promote_all']==0){
														$name = 'No';
														?>
														<option value="<?php echo $key['promote_all'] ?>" ><?php echo $name ?></option>
														<option value="1" >Yes</option>
														<?php
													}

													?>
																
														
													
													<?php
												}
											}else{
												?>
												<option value="" selected="" disabled=""> * Set Select Choice</option>	
												<?php
											}
												 ?>		
												
											</select>
										</label>
											<!-- <input type="hidden" id="set_track" name="set_track" value="" > -->
									</section>
							<footer>
									<input type="submit" id="setPromotionCondition" class="btn btn-primary" value="Save">
							</footer>
						</form>

					</div>

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

			

		</article>

			 <?php endif ?>
	</div>

	<!-- 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.
	 *
	 */

	 var flot_updating_chart, flot_statsChart, flot_multigraph, calendar;

	pageSetUp();
	
	/*
	 * PAGE RELATED SCRIPTS
	 */

	// pagefunction
	
	var pagefunction = function() {
			
		$(".js-status-update a").click(function () {
		    var selText = $(this).text();
		    var $this = $(this);
		    $this.parents('.btn-group').find('.dropdown-toggle').html(selText + ' <span class="caret"></span>');
		    $this.parents('.dropdown-menu').find('li').removeClass('active');
		    $this.parent().addClass('active');
		});
		
		/*
		 * TODO: add a way to add more todo's to list
		 */
		
		// initialize sortable
		
	    $("#sortable1, #sortable2").sortable({
	        handle: '.handle',
	        connectWith: ".todo",
	        update: countTasks
	    }).disableSelection();
		
		
		// check and uncheck
		$('.todo .checkbox > input[type="checkbox"]').click(function () {
		    var $this = $(this).parent().parent().parent();
		
		    if ($(this).prop('checked')) {
		        $this.addClass("complete");
		
		        // remove this if you want to undo a check list once checked
		        //$(this).attr("disabled", true);
		        $(this).parent().hide();
		
		        // once clicked - add class, copy to memory then remove and add to sortable3
		        $this.slideUp(500, function () {
		            $this.clone().prependTo("#sortable3").effect("highlight", {}, 800);
		            $this.remove();
		            countTasks();
		        });
		    } else {
		        // insert undo code here...
		    }
		
		})
		// count tasks
		function countTasks() {
		
		    $('.todo-group-title').each(function () {
		        var $this = $(this);
		        $this.find(".num-of-tasks").text($this.next().find("li").size());
		    });
		
		}
		
		/*
		 * RUN PAGE GRAPHS
		 */

		// load all flot plugins
		loadScript("js/plugin/flot/jquery.flot.cust.min.js", function(){
			loadScript("js/plugin/flot/jquery.flot.resize.min.js", function(){
				loadScript("js/plugin/flot/jquery.flot.time.min.js", function(){
					loadScript("js/plugin/flot/jquery.flot.tooltip.min.js", generatePageGraphs);
				});
			});
		});

		
		function generatePageGraphs() {
		
		    /* TAB 1: UPDATING CHART */
		    // For the demo we use generated data, but normally it would be coming from the server
		
		    var data = [],
		        totalPoints = 200,
		        $UpdatingChartColors = $("#updating-chart").css('color');
		
		    function getRandomData() {
		        if (data.length > 0)
		            data = data.slice(1);
		
		        // do a random walk
		        while (data.length < totalPoints) {
		            var prev = data.length > 0 ? data[data.length - 1] : 50;
		            var y = prev + Math.random() * 10 - 5;
		            if (y < 0)
		                y = 0;
		            if (y > 100)
		                y = 100;
		            data.push(y);
		        }
		
		        // zip the generated y values with the x values
		        var res = [];
		        for (var i = 0; i < data.length; ++i)
		            res.push([i, data[i]])
		        return res;
		    }
		
		    // setup control widget
		    var updateInterval = 1500;
		    $("#updating-chart").val(updateInterval).change(function () {
		
		        var v = $(this).val();
		        if (v && !isNaN(+v)) {
		            updateInterval = +v;
		            $(this).val("" + updateInterval);
		        }
		
		    });
		
		    // setup plot
		    var options = {
		        yaxis: {
		            min: 0,
		            max: 100
		        },
		        xaxis: {
		            min: 0,
		            max: 100
		        },
		        colors: [$UpdatingChartColors],
		        series: {
		            lines: {
		                lineWidth: 1,
		                fill: true,
		                fillColor: {
		                    colors: [{
		                        opacity: 0.4
		                    }, {
		                        opacity: 0
		                    }]
		                },
		                steps: false
		
		            }
		        }
		    };
		
		    flot_updating_chart = $.plot($("#updating-chart"), [getRandomData()], options);
		
		    /* live switch */
		    $('input[type="checkbox"]#start_interval').click(function () {
		        if ($(this).prop('checked')) {
		            $on = true;
		            updateInterval = 1500;
		            update();
		        } else {
		            clearInterval(updateInterval);
		            $on = false;
		        }
		    });
		
		    function update() {

				try {
			        if ($on == true) {
			            flot_updating_chart.setData([getRandomData()]);
			            flot_updating_chart.draw();
			            setTimeout(update, updateInterval);
			
			        } else {
			            clearInterval(updateInterval)
			        }
				}
				catch(err) {
				    clearInterval(updateInterval);
				}
		
		    }
		
		    var $on = false;
		
		    /*end updating chart*/
		
		    /* TAB 2: Social Network  */
		
		    $(function () {
		        // jQuery Flot Chart
		        var twitter = [
		            [1, 27],
		            [2, 34],
		            [3, 51],
		            [4, 48],
		            [5, 55],
		            [6, 65],
		            [7, 61],
		            [8, 70],
		            [9, 65],
		            [10, 75],
		            [11, 57],
		            [12, 59],
		            [13, 62]
		        ],
		            facebook = [
		                [1, 25],
		                [2, 31],
		                [3, 45],
		                [4, 37],
		                [5, 38],
		                [6, 40],
		                [7, 47],
		                [8, 55],
		                [9, 43],
		                [10, 50],
		                [11, 47],
		                [12, 39],
		                [13, 47]
		            ],
		            data = [{
		                label: "Twitter",
		                data: twitter,
		                lines: {
		                    show: true,
		                    lineWidth: 1,
		                    fill: true,
		                    fillColor: {
		                        colors: [{
		                            opacity: 0.1
		                        }, {
		                            opacity: 0.13
		                        }]
		                    }
		                },
		                points: {
		                    show: true
		                }
		            }, {
		                label: "Facebook",
		                data: facebook,
		                lines: {
		                    show: true,
		                    lineWidth: 1,
		                    fill: true,
		                    fillColor: {
		                        colors: [{
		                            opacity: 0.1
		                        }, {
		                            opacity: 0.13
		                        }]
		                    }
		                },
		                points: {
		                    show: true
		                }
		            }];
		
		        var options = {
		            grid: {
		                hoverable: true
		            },
		            colors: ["#568A89", "#3276B1"],
		            tooltip: true,
		            tooltipOpts: {
		                //content : "Value <b>$x</b> Value <span>$y</span>",
		                defaultTheme: false
		            },
		            xaxis: {
		                ticks: [
		                    [1, "JAN"],
		                    [2, "FEB"],
		                    [3, "MAR"],
		                    [4, "APR"],
		                    [5, "MAY"],
		                    [6, "JUN"],
		                    [7, "JUL"],
		                    [8, "AUG"],
		                    [9, "SEP"],
		                    [10, "OCT"],
		                    [11, "NOV"],
		                    [12, "DEC"],
		                    [13, "JAN+1"]
		                ]
		            },
		            yaxes: {
		
		            }
		        };
		
		        flot_statsChart = $.plot($("#statsChart"), data, options);
		    });
		
		    // END TAB 2
		
		    // TAB THREE GRAPH //
		    /* TAB 3: Revenew  */
		
		    $(function () {
		
		        var trgt = [
		            [1354586000000, 153],
		            [1364587000000, 658],
		            [1374588000000, 198],
		            [1384589000000, 663],
		            [1394590000000, 801],
		            [1404591000000, 1080],
		            [1414592000000, 353],
		            [1424593000000, 749],
		            [1434594000000, 523],
		            [1444595000000, 258],
		            [1454596000000, 688],
		            [1464597000000, 364]
		        ],
		            prft = [
		                [1354586000000, 53],
		                [1364587000000, 65],
		                [1374588000000, 98],
		                [1384589000000, 83],
		                [1394590000000, 980],
		                [1404591000000, 808],
		                [1414592000000, 720],
		                [1424593000000, 674],
		                [1434594000000, 23],
		                [1444595000000, 79],
		                [1454596000000, 88],
		                [1464597000000, 36]
		            ],
		            sgnups = [
		                [1354586000000, 647],
		                [1364587000000, 435],
		                [1374588000000, 784],
		                [1384589000000, 346],
		                [1394590000000, 487],
		                [1404591000000, 463],
		                [1414592000000, 479],
		                [1424593000000, 236],
		                [1434594000000, 843],
		                [1444595000000, 657],
		                [1454596000000, 241],
		                [1464597000000, 341]
		            ],
		            toggles = $("#rev-toggles"),
		            target = $("#flotcontainer");
		
		        var data = [{
		            label: "Target Profit",
		            data: trgt,
		            bars: {
		                show: true,
		                align: "center",
		                barWidth: 30 * 30 * 60 * 1000 * 80
		            }
		        }, {
		            label: "Actual Profit",
		            data: prft,
		            color: '#3276B1',
		            lines: {
		                show: true,
		                lineWidth: 3
		            },
		            points: {
		                show: true
		            }
		        }, {
		            label: "Actual Signups",
		            data: sgnups,
		            color: '#71843F',
		            lines: {
		                show: true,
		                lineWidth: 1
		            },
		            points: {
		                show: true
		            }
		        }]
		
		        var options = {
		            grid: {
		                hoverable: true
		            },
		            tooltip: true,
		            tooltipOpts: {
		                //content: '%x - %y',
		                //dateFormat: '%b %y',
		                defaultTheme: false
		            },
		            xaxis: {
		                mode: "time"
		            },
		            yaxes: {
		                tickFormatter: function (val, axis) {
		                    return "$" + val;
		                },
		                max: 1200
		            }
		
		        };
		
		        flot_multigraph = null;
		
		        function plotNow() {
		            var d = [];
		            toggles.find(':checkbox').each(function () {
		                if ($(this).is(':checked')) {
		                    d.push(data[$(this).attr("name").substr(4, 1)]);
		                }
		            });
		            if (d.length > 0) {
		                if (flot_multigraph) {
		                    flot_multigraph.setData(d);
		                    flot_multigraph.draw();
		                } else {
		                    flot_multigraph = $.plot(target, d, options);
		                }
		            }
		
		        };
		
		        toggles.find(':checkbox').on('change', function () {
		            plotNow();
		        });

		        plotNow()
		
		    });
		
		}
		
		/*
		 * VECTOR MAP
		 */
		
		data_array = {
		    "US": 4977,
		    "AU": 4873,
		    "IN": 3671,
		    "BR": 2476,
		    "TR": 1476,
		    "CN": 146,
		    "CA": 134,
		    "BD": 100
		};
		
		// Load Map dependency 1 then call for dependency 2 and then run renderVectorMap function
		loadScript("js/plugin/vectormap/jquery-jvectormap-1.2.2.min.js", function(){
			loadScript("js/plugin/vectormap/jquery-jvectormap-world-mill-en.js", renderVectorMap);
		});
		

		function renderVectorMap() {
		    $('#vector-map').vectorMap({
		        map: 'world_mill_en',
		        backgroundColor: '#fff',
		        regionStyle: {
		            initial: {
		                fill: '#c4c4c4'
		            },
		            hover: {
		                "fill-opacity": 1
		            }
		        },
		        series: {
		            regions: [{
		                values: data_array,
		                scale: ['#85a8b6', '#4d7686'],
		                normalizeFunction: 'polynomial'
		            }]
		        },
		        onRegionLabelShow: function (e, el, code) {
		            if (typeof data_array[code] == 'undefined') {
		                e.preventDefault();
		            } else {
		                var countrylbl = data_array[code];
		                el.html(el.html() + ': ' + countrylbl + ' visits');
		            }
		        }
		    });
		}
		
		/*
		 * FULL CALENDAR JS
		 */
		
		// Load Calendar dependency then setup calendar
		
		loadScript("js/plugin/moment/moment.min.js", function(){
			loadScript("js/plugin/fullcalendar/jquery.fullcalendar.min.js", setupCalendar);
		});
		
		function setupCalendar() {
		
		    if ($("#calendar").length) {
		        var date = new Date();
		        var d = date.getDate();
		        var m = date.getMonth();
		        var y = date.getFullYear();
		
		        calendar = $('#calendar').fullCalendar({
		
		            editable: true,
		            draggable: true,
		            selectable: false,
		            selectHelper: true,
		            unselectAuto: false,
		            disableResizing: false,
		
		            header: {
		                left: 'title', //,today
		                center: 'prev, next, today',
		                right: 'month, agendaWeek, agenDay' //month, agendaDay,
		            },
		
		            select: function (start, end, allDay) {
		                var title = prompt('Event Title:');
		                if (title) {
		                    calendar.fullCalendar('renderEvent', {
		                            title: title,
		                            start: start,
		                            end: end,
		                            allDay: allDay
		                        }, true // make the event "stick"
		                    );
		                }
		                calendar.fullCalendar('unselect');
		            },
		
		            events: [{
		                title: 'All Day Event',
		                start: new Date(y, m, 1),
		                description: 'long description',
		                className: ["event", "bg-color-greenLight"],
		                icon: 'fa-check'
		            }, {
		                title: 'Long Event',
		                start: new Date(y, m, d - 5),
		                end: new Date(y, m, d - 2),
		                className: ["event", "bg-color-red"],
		                icon: 'fa-lock'
		            }, {
		                id: 999,
		                title: 'Repeating Event',
		                start: new Date(y, m, d - 3, 16, 0),
		                allDay: false,
		                className: ["event", "bg-color-blue"],
		                icon: 'fa-clock-o'
		            }, {
		                id: 999,
		                title: 'Repeating Event',
		                start: new Date(y, m, d + 4, 16, 0),
		                allDay: false,
		                className: ["event", "bg-color-blue"],
		                icon: 'fa-clock-o'
		            }, {
		                title: 'Meeting',
		                start: new Date(y, m, d, 10, 30),
		                allDay: false,
		                className: ["event", "bg-color-darken"]
		            }, {
		                title: 'Lunch',
		                start: new Date(y, m, d, 12, 0),
		                end: new Date(y, m, d, 14, 0),
		                allDay: false,
		                className: ["event", "bg-color-darken"]
		            }, {
		                title: 'Birthday Party',
		                start: new Date(y, m, d + 1, 19, 0),
		                end: new Date(y, m, d + 1, 22, 30),
		                allDay: false,
		                className: ["event", "bg-color-darken"]
		            }, {
		                title: 'Smartadmin Open Day',
		                start: new Date(y, m, 28),
		                end: new Date(y, m, 29),
		                className: ["event", "bg-color-darken"]
		            }],
		
		            eventRender: function (event, element, icon) {
		                if (!event.description == "") {
		                    element.find('.fc-event-title').append("<br/><span class='ultra-light'>" + event.description +
		                        "</span>");
		                }
		                if (!event.icon == "") {
		                    element.find('.fc-event-title').append("<i class='air air-top-right fa " + event.icon +
		                        " '></i>");
		                }
		            }
		        });
		
		    };
		
		    /* hide default buttons */
		    $('.fc-header-right, .fc-header-center').hide();
		
		}
		
		// calendar prev
		$('#calendar-buttons #btn-prev').click(function () {
		    $('.fc-button-prev').click();
		    return false;
		});
		
		// calendar next
		$('#calendar-buttons #btn-next').click(function () {
		    $('.fc-button-next').click();
		    return false;
		});
		
		// calendar today
		$('#calendar-buttons #btn-today').click(function () {
		    $('.fc-button-today').click();
		    return false;
		});
		
		// calendar month
		$('#mt').click(function () {
		    $('#calendar').fullCalendar('changeView', 'month');
		});
		
		// calendar agenda week
		$('#ag').click(function () {
		    $('#calendar').fullCalendar('changeView', 'agendaWeek');
		});
		
		// calendar agenda day
		$('#td').click(function () {
		    $('#calendar').fullCalendar('changeView', 'agendaDay');
		});
		
		/*
		 * CHAT
		 */
		
		// var filter_input = $('#filter-chat-list'),
		// 	chat_users_container = $('#chat-container > .chat-list-body'),
		// 	chat_users = $('#chat-users'),
		// 	chat_list_btn = $('#chat-container > .chat-list-open-close'),
		// 	chat_body = $('#chat-body');
		
		/*
		 * LIST FILTER (CHAT)
		 */
		
		// custom css expression for a case-insensitive contains()
		// jQuery.expr[':'].Contains = function (a, i, m) {
		//     return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
		// };
		
		// function listFilter(list) { 
		// 	// header is any element, list is an unordered list
		//     // create and add the filter form to the header
		
		//     filter_input.change(function () {
		//         var filter = $(this).val();
		//         if (filter) {
		//             // this finds all links in a list that contain the input,
		//             // and hide the ones not containing the input while showing the ones that do
		//             chat_users.find("a:not(:Contains(" + filter + "))").parent().slideUp();
		//             chat_users.find("a:Contains(" + filter + ")").parent().slideDown();
		//         } else {
		//             chat_users.find("li").slideDown();
		//         }
		//         return false;
		//     }).keyup(function () {
		//         // fire the above change event after every letter
		//         $(this).change();
		
		//     });
		
		// }
		
		// on dom ready
		// listFilter(chat_users);
		
		// // open chat list
		// chat_list_btn.click(function () {
		//     $(this).parent('#chat-container').toggleClass('open');
		// })
		
		// chat_body.animate({
		//     scrollTop: chat_body[0].scrollHeight
		// }, 500);
	
	};
	
	// end pagefunction

	// destroy generated instances 
	// pagedestroy is called automatically before loading a new page
	// only usable in AJAX version!

	var pagedestroy = function(){
		
		// destroy calendar
		calendar.fullCalendar('destroy');
		calendar = null;

		//destroy flots
		flot_updating_chart.shutdown();  
		flot_updating_chart=null;
		flot_statsChart.shutdown(); 
		flot_statsChart = null;

		flot_multigraph.shutdown(); 
		flot_multigraph = null;

		// destroy vector map objects
		$('#vector-map').find('*').addBack().off().remove();

		// destroy todo
		$("#sortable1, #sortable2").sortable("destroy");
		$('.todo .checkbox > input[type="checkbox"]').off();

		// destroy misc events
		$("#rev-toggles").find(':checkbox').off();
		$('#chat-container').find('*').addBack().off().remove();

		// debug msg
		if (debugState){
			root.console.log("✔ Calendar, Flot Charts, Vector map, misc events destroyed");
		} 

	}


	$(document).ready(function(){
		// $('#track_main').change(function(){
		// 	var track = $('#track_main').val();
		// 	$('#track').val(track);
		// });
		// $('#class_main').change(function(){
		// 	var class_val = $('#class_main').val();
		// 	$('#class').val(class_val);
		// });
		async function getGlobal(){
			 $.get('ajax/controller/setupCode.php?get_global=',(res)=>{
				const data =  JSON.parse(res);
				let output = '';
				data.forEach((global,index)=>{
					output = `<span id="academic_year_title">${global.a_year} / </span>
							  <span id="semester_title">${global.sem_name}</span>`;
				});
				$('.output').html(output);
			});
		}

		getGlobal();

		async function setGlobal(){
			var form = new FormData($("#checkout-form3")[0]);
			// var data = new FormData(form); 
			$.ajax({
						type: "POST",
						enctype: 'multipart/form-data',
						url: "ajax/dashboard.php",
						data: form,
						processData: false,
						contentType: false,
						cache: false,
						timeout: 600000,
			beforeSend: function(response){

				},
				complete: function(response){
				
			},
			success: function(response){
				if (response.charAt(0) == 0) {
					$.smallBox({
							title : "Globals set Successfully",
							content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
							color : "#000000",
							iconSmall : "fa fa-check bounce animated",
							timeout : 4000
						});
					$('#checkout-form3').find("input[type=text], textarea,input[type=email],input[type=phone],select").val("");
				}else if(response.charAt(0) == 2){
					$.smallBox({
							title : "Globals Updated Successfully",
							content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
							color : "#000000",
							iconSmall : "fa fa-check bounce animated",
							timeout : 4000
						});
					$('#checkout-form3').find("input[type=text], textarea,input[type=email],input[type=phone],select").val("");
				}else{
					$.smallBox({
							title : "Globals not Set!",
							content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
							color : "#C46A69",
							iconSmall : "fa fa-check bounce animated",
							timeout : 4000
						});
				}

			}
			});
		   }

		$('#checkout-form3').on('submit',function(){
			//Invoked immediately without call
			(async function init(){
				await setGlobal();
				getGlobal();
			})();
		return false;
		});

		$('#setVacation').click(function(){
			var end = $('#end').val();
			var next = $('#next').val();

			var data = {
				end:end,
				next:next,
				setVacation:''
			};
			$.post('ajax/dashboard.php',data,function(res){
				$.smallBox({
					title : "Vacation date set Successfully",
					content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
					color : "#000000",
					iconSmall : "fa fa-check bounce animated",
					timeout : 4000
				});
			});
		});

		$('#setPromotionCondition').click(function(){
			var promote_all = $('#promoteAll').val();
			var data = {
				promote_all:promote_all,
				setPromotionCondition:''
			};
			$.post('ajax/dashboard.php',data,function(res){
				alert('Saved');
			});
		});

		$('#update_credentials').click(function(){
			var password = $('#password').val();
			var staff_id = $('#staff_id').val();
			var data = {
				password:password,
				staff_id:staff_id,
				update_credentials:''
			};
			$.post('ajax/dashboard.php',data,function(res){
				$.smallBox({
					title : "Password Updated Successfully",
					content : "<i class='fa fa-clock-o'></i> <i>just now...</i>",
					color : "#000000",
					iconSmall : "fa fa-check bounce animated",
					timeout : 4000
				});
			});
		});

		$('#send_parents_sms').click(function(){
			var sms = $('#parent_msg').val();
			var data = {
				msg:sms,
				pta_sms:''
			};
			$.post('ajax/msg/pta.php',data,function(res){
				console.log(res);
			});
		});
		$('#activate').click(function(){

			$('#this_button').removeClass('hidden');
		});

	});

	// end destroy
	
	// run pagefunction on load
	pagefunction();
	
	
</script>
