<?php
session_start();
if (!isset($_SESSION['loggedin'])) {
	header('Location: index.html');
	exit;
}
?>
<!DOCTYPE html>
<html>
<head>
	<title>BJH On-line foglalási rendszer</title>

	<meta charset="utf-8">

			<link href="style.css" rel="stylesheet" type="text/css">
			<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">



</head>

<body>

	<body class="loggedin">
			<nav class="navtop">
				<div>
					<h1>BJH gyógytorna on-line foglalási rendszer</h1>
					<a href="javascript:openWindow()"><i class="fas fa-solid fa-clock"></i>Órarend</a>
					<a href="logout.php"><i class="fas fa-sign-out-alt"></i>Kilépés</a>
				</div>
			</nav>
			
			
			





	<link href=
	"https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.css"
	rel="stylesheet">
	<link href=
	"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.css"
	rel="stylesheet">
	<link href="./jquery-ui.css" rel="stylesheet">
	<script src=
	"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js">
	</script>
	<script src=
	"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js">
	</script>
	<script src=
	"https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.min.js">
	</script>
	<script src="./jquery-ui.min.js">
	</script>
	<script src="./hu.min.js">
	</script>
	<link href=
	"//cdn.jsdelivr.net/npm/@sweetalert2/theme-bootstrap-4/bootstrap-4.css" rel=
	"stylesheet">
	<script src="//cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js">
	</script>
	<link href="https://fonts.googleapis.com/css2?family=Staatliches&display=swap"
	rel="stylesheet">
	<style>
	    h1 {font-family: "Staatliches", cursive;
	          font-size: 60px;
	          text-align: center;}
	</style>
	<style>
	       body {
	          background-image: url("images/bg.jpg");
	          background-size: cover;

	            }
	</style>
	
	
	<script type="text/javascript">
    function openWindow() {
        var win = window.open('schedule.html','New Window','width=800,height=566,top=70,left=70,resizable=no');
        win.focus();
    }
    </script>
	
	
	<script>

	    $(document).ready(function() {
	     var calendar = $('#calendar').fullCalendar({
	      editable:true,
	      theme:true,

	      header:{
	       left:'prev,next today',
	       center:'title',
	       right:'month,agendaWeek,agendaDay,listWeek'
	      },

	      navLinks: true,
	      weekNumbers: true,
	      weekNumbersWithinDays: true,
	      weekNumberCalculation: 'ISO',
	      editable: true,
	      eventLimit: true,
	      events: 'load.php',
	      selectable:true,
	      selectHelper:true,

	      select: async function(start, end, allDay)
        {
        var view = $('#calendar').fullCalendar('getView');
        var clickDate = $('#calendar').fullCalendar('dayClick');

        if (view.name == 'month')
        {
          $('#calendar').fullCalendar( 'changeView', 'agendaDay', start );
        }
        else {

         var inputString = await Swal.fire({
            title: 'A résztvevő adatai:',
            input: 'text',
            inputAttributes: {autocapitalize: 'off'},
            showCancelButton: true,
            confirmButtonText: 'Hozzáadás',
            cancelButtonText: 'Vissza',
            showLoaderOnConfirm: true

          })

         var title = inputString.value;


	    if (title)
      {
	        var start = $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss");
	        var end = $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss");

	        $.ajax({
	         url:"insert.php",
	         type:"POST",
	         data:{title:title, start:start, end:end},
	         success:function()
	         {
            calendar.fullCalendar('refetchEvents');
            calendar.fullCalendar('refetchEvents');

            }
	        })
        }
        }
	      },
	      editable:true,
	      eventResize:function(event)
	      {
	       var start = $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss");
	       var end = $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss");
	       var title = event.title;
	       var id = event.id;
	       $.ajax({
	        url:"update.php",
	        type:"POST",
	        data:{title:title, start:start, end:end, id:id},
	        success:function(){
	        calendar.fullCalendar('refetchEvents');
	        }
	       })
	      },

	      eventDrop:function(event)
	      {
	       var start = $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss");
	       var end = $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss");
	       var title = event.title;
	       var id = event.id;
	       $.ajax({
	        url:"update.php",
	        type:"POST",
	        data:{title:title, start:start, end:end, id:id},
	        success:function()
	        {
	         calendar.fullCalendar('refetchEvents');
	        }
	       });
	      },

	      eventClick:function(event)
        {
	         Swal.fire({
	            title: 'Biztosan törli?',
	            text: 'A törlés nem visszavonható!',
	            icon: 'warning',
	            showCancelButton: true,
	            confirmButtonColor: '#3085d6',
	            cancelButtonColor: '#d33',
	            confirmButtonText: 'Igen',
	            cancelButtonText: 'Vissza'}).then((result) =>
                 { if (result.isConfirmed)
                   {
                   var id = event.id;
                   $.ajax(
                     {
                     url:"delete.php",
                     type:"POST",
                     data:{id:id},
                     success:function()
                       {
                          calendar.fullCalendar('refetchEvents');
                          Swal.fire({
                              title:'',
                              text: 'Résztvevő törölve',
                              icon: 'error',
                              confirmButtonText: 'Rendben'})
	                     }
	                   });
	                 }
	               })
        }
	     })
	     });


	</script><br>
	
	
	
	<br>
	<div class="container">
	<div id="calendar">
	</div>
	</div>
</body>
</html>
