Created
February 6, 2019 19:35
-
-
Save mnemocron/3e85723b2f846fedec4b4c968e17f8cb to your computer and use it in GitHub Desktop.
Display time recordings from an app as .ics calendars with php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8' /> | |
<link href='assets/fullcalendar.min.css' rel='stylesheet' /> | |
<link href='assets/fullcalendar.print.min.css' rel='stylesheet' media='print' /> | |
<script src='assets/lib/moment.min.js'></script> | |
<script src='assets/lib/jquery.min.js'></script> | |
<script src='assets/fullcalendar.min.js'></script> | |
<script> | |
$(document).ready(function() { | |
<?php | |
$basedir = './calendars/'; | |
$file = substr($_GET['f'], 0,140); | |
$filepath = $basedir . $file; | |
$jsonString = file_get_contents ( $filepath ); | |
// echo 'var jsonString = \'' . $jsonString . '\';'; | |
?> | |
$('#calendar').fullCalendar({ | |
header: { | |
left: 'prev,next today', | |
center: 'title', | |
right: 'month,agendaWeek,agendaDay,listWeek' | |
}, | |
defaultDate: '2018-03-12', | |
navLinks: true, // can click day/week names to navigate views | |
editable: true, | |
eventLimit: true, // allow "more" link when too many events | |
events: './csv2json.php?f=<?php echo $file ;?>' | |
//events: './file2json.php?f=<?php echo $file ;?>' | |
}); | |
}); | |
</script> | |
<style> | |
body { | |
margin: 40px 10px; | |
padding: 0; | |
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif; | |
font-size: 14px; | |
} | |
#calendar { | |
max-width: 900px; | |
margin: 0 auto; | |
} | |
</style> | |
</head> | |
<body> | |
<div id='calendar'></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-type: application/json'); | |
$filename = $_GET['f']; | |
$csv_path = './calendars/' . $filename; | |
if (file_exists($csv_path) && strcmp(pathinfo($filename, PATHINFO_EXTENSION), 'csv') ==0 ) { | |
$handle = fopen($csv_path, 'r'); | |
if ($handle) { | |
$line = fgets($handle); // first line is the title | |
$i = 0; | |
while (($line = fgets($handle)) !== false) { | |
$title = explode(',', $line)[0]; | |
$title = str_replace('"', '', $title); | |
$start = explode(',', $line)[2]; | |
$start = str_replace(' ', 'T', $start); | |
$start = str_replace('"', '', $start); | |
if (strpos($start, 'T') !== false) { | |
$start = $start . ':00'; | |
} | |
$end = explode(',', $line)[3]; | |
$end = str_replace(' ', 'T', $end); | |
$end = str_replace('"', '', $end); | |
if (strpos($end, 'T') !== false) { | |
$end = $end . ':00'; | |
} | |
if (strpos($start, '-') !== false){ | |
$arr[$i]['title'] = $title; | |
$arr[$i]['start'] = $start; | |
$arr[$i]['end'] = $end; | |
} | |
$i += 1; | |
} | |
fclose($handle); | |
} else { | |
// error opening the file. | |
} | |
//$myfile = fopen($csv_path, 'r') or die('Unable to open file!'); | |
//$csvstr = fread($myfile, filesize($csv_path)); | |
//fclose($myfile); | |
//$arr = array_map('str_getcsv', file($csv_path)); | |
//echo $csvstr; | |
echo json_encode($arr); | |
} else { | |
echo json_encode(array('status' => 'error')); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"title": "All Day Event", | |
"start": "2018-03-01" | |
}, | |
{ | |
"title": "Long Event", | |
"start": "2018-03-07", | |
"end": "2018-03-10" | |
}, | |
{ | |
"id": 999, | |
"title": "Repeating Event", | |
"start": "2018-03-09T16:00:00" | |
}, | |
{ | |
"id": 999, | |
"title": "Repeating Event", | |
"start": "2018-03-16T16:00:00" | |
}, | |
{ | |
"title": "Conference", | |
"start": "2018-03-11", | |
"end": "2018-03-13" | |
}, | |
{ | |
"title": "Meeting", | |
"start": "2018-03-12T10:30:00", | |
"end": "2018-03-12T12:30:00" | |
}, | |
{ | |
"title": "Lunch", | |
"start": "2018-03-12T12:00:00" | |
}, | |
{ | |
"title": "Meeting", | |
"start": "2018-03-12T14:30:00" | |
}, | |
{ | |
"title": "Happy Hour", | |
"start": "2018-03-12T17:30:00" | |
}, | |
{ | |
"title": "Dinner", | |
"start": "2018-03-12T20:00:00" | |
}, | |
{ | |
"title": "Birthday Party", | |
"start": "2018-03-13T07:00:00" | |
}, | |
{ | |
"title": "Click for Google", | |
"url": "http://google.com/", | |
"start": "2018-03-28" | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-type: application/json'); | |
$filename = $_GET['f']; | |
$json_path = './calendars/' . $filename; | |
if (file_exists($json_path) && strcmp(pathinfo($filename, PATHINFO_EXTENSION), 'json') ==0 ) { | |
$myfile = fopen($json_path, 'r') or die('Unable to open file!'); | |
$jsonstr = fread($myfile, filesize($json_path)); | |
fclose($myfile); | |
echo $jsonstr; | |
} else { | |
echo json_encode(array('status' => 'error')); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<!-- | |
Editorial by HTML5 UP | |
html5up.net | @ajlkn | |
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license) | |
--> | |
<html> | |
<head> | |
<title>Calendar Viewver</title> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> | |
<link rel="stylesheet" href="assets/css/main.css" /> | |
</head> | |
<body class="is-preload"> | |
<!-- Wrapper --> | |
<div id="wrapper"> | |
<!-- Main --> | |
<div id="main"> | |
<div class="inner"> | |
<!-- Header --> | |
<header id="header"> | |
<a href="../" class="logo">FullCalendar by <strong>simonmartin.ch</strong></a> | |
</header> | |
<!-- Content --> | |
<section> | |
<header class="main"> | |
<h3>Calendar Viewer</h3> | |
</header> | |
<div class="row gtr-uniform"> | |
<div class="col-12-xsmall"> | |
<h4>Select Calendar File</h4> | |
<ul class="actions"> | |
<li> | |
<?php | |
$files = scandir("./calendars"); | |
echo '<select id="json-selector">'; | |
for ($i = 0; $i < sizeof($files); $i ++ ) { | |
if(strpos($files[$i], 'csv') !== false){ | |
echo '<option value="'. $files[$i] .'">' . $files[$i] . '</option>'; | |
} | |
} | |
echo '</select>'; | |
?></li> | |
<li><button type="button" id="myBtn">Load</button></li> | |
</ul> | |
</div> | |
</div> | |
<iframe id="iframe-loader" width="100%" height="1080" src="agenda-views.php"></iframe> | |
</section> | |
</div> | |
</div> | |
<!-- Sidebar --> | |
<div id="sidebar"> | |
<div class="inner"> | |
<!-- Section --> | |
<section> | |
<header class="major"> | |
<h2>Calendar Viewer</h2> | |
</header> | |
</section> | |
<!-- Footer --> | |
<footer id="footer"> | |
<p class="copyright">© Untitled. All rights reserved. Demo Images: <a href="https://unsplash.com">Unsplash</a>. Design: <a href="https://html5up.net">HTML5 UP</a>.</p> | |
</footer> | |
</div> | |
</div> | |
</div> | |
<script src="assets/js/jquery.min.js"></script> | |
<script src="assets/js/browser.min.js"></script> | |
<script src="assets/js/breakpoints.min.js"></script> | |
<script src="assets/js/util.js"></script> | |
<script src="assets/js/main.js"></script> | |
<script> | |
document.getElementById("myBtn").addEventListener("click", function(){ | |
var e = document.getElementById("json-selector"); | |
var strUser = e.options[e.selectedIndex].text; | |
var baseUrl = "agenda-views.php?f="; | |
document.getElementById('iframe-loader').src = baseUrl.concat(strUser); | |
//alert(string.concat(strUser, baseUrl)); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment