'; for ($xoff=-24.0; $xoff<=24.0; $xoff+=0.5) { $selstuff=str_replace("", "", $selstuff); } $zones = timezone_identifiers_list(); foreach ($zones as $zone) { $origzone=$zone; //$ourtz=new DateTimeZone($zone); $zone = explode('/', $zone); // 0 => Continent, 1 => City // Only use "friendly" continent names if ($zone[0] == 'Africa' || $zone[0] == 'America' || $zone[0] == 'Antarctica' || $zone[0] == 'Arctic' || $zone[0] == 'Asia' || $zone[0] == 'Atlantic' || $zone[0] == 'Australia' || $zone[0] == 'Europe' || $zone[0] == 'Indian' || $zone[0] == 'Pacific') { if (isset($zone[1]) != '') { //$locations[$zone[0]][$zone[0]. '/' . $zone[1]] = str_replace('_', ' ', $zone[1]); // Creates array(DateTimeZone => 'Friendly name') //$ourtz=new DateTimeZone(str_replace('_', ' ', $zone[0]. '/' . $zone[1])); //$selstuff=str_replace("", "", $selstuff); $selstuff=str_replace("", "", $selstuff); //$selstuff=str_replace("", "", $selstuff); } } } return $selstuff; } function dateselcombo($parid, $defstr) { $mths=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; $yyyystr=""; $mmstr=""; $ddstr=""; $hhstr=""; $mistr=""; $ssstr=""; return $yyyystr . $mmstr . $ddstr . ":" . $hhstr . $mistr . $ssstr; } if (isset($_GET['msg'])) { $dhuh=urldecode($_GET['msg']) . ' '; //exit; if (strcmp(substr($dhuh,0,1),"0") >= 0 && strcmp(substr($dhuh,0,1),"9") <= 0) { $pcont=@file_get_contents("ics_attachment.php"); $pbits=explode("/" . "/ " . $_GET['msg'] . " ", explode('?' . '>', $pcont)[0]); if (sizeof($pbits) > 1) { $postpbits=explode("/" . "/ ", explode("/" . "/ " . (1 + $_GET['msg']) . " ", $pbits[-1 + sizeof($pbits)])[0]); $msg=""; $okay=true; for ($i=0; $i Calendar *.ics file creation - RJM Programming - November, 2016

" . $msg . "

"; } else { echo ""; } } else { $ourtz=new DateTimeZone(urldecode($_GET['msg'])); $ztz=$ourtz->getLocation()[latitude] . "," . $ourtz->getLocation()[longitude] . ",~" . urlencode(str_replace('_', ' ', explode('/', urldecode($_GET['msg']))[1])) . "~"; echo " Calendar *.ics file creation - RJM Programming - November, 2016 function domap(withthis) { var mapurl=\"http://www.rjmprogramming.com.au/PHP/Map/map.php?title=Places&onclick=y&label=['Lat',&value='Lon','Name']&data=,[0.0000,0.0000,~Timbuktu~]\"; var maphuh='0.0000,0.0000,~Timbuktu~'; if (withthis != '') { if (parent.document.getElementById('myplaceiframe')) { //mapurl=parent.document.getElementById('divmap').innerHTML.replace(']','],[' + withthis + ']'); parent.document.getElementById('myplaceiframe').src+=',[' + withthis + ']'; mapurl=\"http://www.rjmprogramming.com.au/PHP/Map/map.php?title=Places&onclick=y&label=['Lat',&value='Lon','Name']&data=,[0.0000,0.0000,~Timbuktu~]\"; } else if (mapurl.indexOf(maphuh) != -1) { mapurl=mapurl.replace(maphuh,withthis); if (parent.document.getElementById('divmap').innerHTML == '') { parent.document.getElementById('divmap').innerHTML=''; } else { parent.document.getElementById('myplaceiframe').src=mapurl; } } else { mapurl=mapurl.replace(']','],[' + withthis + ']'); parent.document.getElementById('myplaceiframe').src=mapurl; mapurl=\"http://www.rjmprogramming.com.au/PHP/Map/map.php?title=Places&onclick=y&label=['Lat',&value='Lon','Name']&data=,[0.0000,0.0000,~Timbuktu~]\"; } } } "; } } else if (!isset($_POST['id']) && !isset($_GET['id'])) { date_default_timezone_set('Australia/Perth'); $qbits=@file_get_contents("ics_attachment.php"); $msgno=1; while (strpos($qbits, "/" . "/ " . $msgno . " ") !== false) { $msgno++; } echo " Calendar *.ics file creation - RJM Programming - November, 2016

Create Calendar iCal File

RJM Programming

November, 2016

Thanks to https://gist.github.com/vtedesco/5671155

Title:

Subtitle:

Description:

:

Start Date (YYYYmmdd:HH24MISS)
" . ourtimezonelist('datestart') . " Time: or " . dateselcombo("datestart",date("Ymd:His")) . "

End Date (YYYYmmdd:HH24MISS)
" . ourtimezonelist('dateend') . " Time: or " . dateselcombo("dateend",date("Ymd:His")) . "

Event
Recall
Text:

"; } else { // filled in form if ((isset($_POST['eventwords']) && isset($_POST['id']) ) || (isset($_GET['eventwords']) && isset($_GET['id']) )) { if (isset($_GET['eventwords']) && isset($_GET['id'])) { $ptmsg=explode(" ", "/" . "/ " . $_GET['id'] . " " . urldecode($_GET['eventwords'])); } else { $ptmsg=explode(" ", "/" . "/ " . $_POST['id'] . " " . urldecode($_POST['eventwords'])); } //echo sizeof($ptmsg); if (sizeof($ptmsg) > 3) { if ($ptmsg[2] != "") { //echo "here"; //exit; if (isset($_GET['eventwords']) && isset($_GET['id'])) { file_put_contents("ics_attachment.php", explode('?' . '>', file_get_contents("ics_attachment.php"))[0] . "\n/" . "/ " . $_GET['id'] . " " . str_replace("\n", "\n/" . "/ ", str_replace('?' . '>', '', urldecode($_GET['eventwords']))) . "\n" . "?" . ">"); } else { file_put_contents("ics_attachment.php", explode('?' . '>', file_get_contents("ics_attachment.php"))[0] . "\n/" . "/ " . $_POST['id'] . " " . str_replace("\n", "\n/" . "/ ", str_replace('?' . '>', '', urldecode($_POST['eventwords']))) . "\n" . "?" . ">"); } } else { $x=""; } } else { $x=""; } } // Fetch vars if (isset($_GET['id'])) { if (isset($_GET['emode'])) { if (strpos(urldecode($_GET['emode']), "To") !== false) { //echo "99huh"; if (urldecode($_GET['emode']) == "To") $interactive = false; if (strpos(urldecode($_GET['address']), "@") !== false && strpos(urldecode($_GET['address']), " ") === false) { $emailto = urldecode($_GET['address']); } } } $event = array( 'id' => $_GET['id'], 'title' => urldecode($_GET['title']), 'address' => urldecode($_GET['address']), 'description' => urldecode($_GET['description']), 'datestart' => $_GET['datestart'], 'dateend' => $_GET['dateend'], 'address' => urldecode($_GET['stage']) ); } else { if (isset($_POST['emode'])) { if (strpos(urldecode($_POST['emode']), "To") !== false) { //echo "979huh"; if (urldecode($_POST['emode']) == "To") $interactive = false; if (strpos(urldecode($_POST['address']), "@") !== false && strpos(urldecode($_POST['address']), " ") === false) { $emailto = urldecode($_POST['address']); } } } $event = array( 'id' => $_POST['id'], 'title' => urldecode($_POST['title']), 'address' => urldecode($_POST['address']), 'description' => urldecode($_POST['description']), 'datestart' => $_POST['datestart'], 'dateend' => $_POST['dateend'], 'address' => urldecode($_POST['stage']) ); } // iCal date format: yyyymmddThhiissZ // PHP equiv format: Ymd\This // The Function function dateToCal($time) { date_default_timezone_set('GMT'); //echo "\n" . date('Ymd\This', $time) . 'Z'; return date('Ymd\This', $time) . 'Z'; } function tzbit($ts,$ofw) { global $start_end_offsets, $posttz; $thisi=0; $outts=$ts; if (isset($_POST['tz']) || isset($_GET['tz'])) { if ((isset($_POST['tz']) && $_POST['tz'] != "") || (isset($_GET['tz']) && $_GET['tz'] != "")) { date_default_timezone_set('Europe/London'); //echo urldecode($_POST['tz']) . ' ... ' . $ofw . ' ... '; if (isset($_GET['tz'])) { $posttz=urldecode($_GET['tz']); } else { $posttz=urldecode($_POST['tz']); } if (strpos(($posttz), ",") !== false) { $ourtzs=explode(",", ($posttz)); if (strpos($ofw, "end") !== false) { $thisi=1; } if (strpos($ourtzs[$thisi], "/") !== false) { $r_dtz = new DateTimeZone($ourtzs[$thisi]); date_default_timezone_set('Europe/London'); $dateTimeGMT = new DateTime("now"); $start_end_offsets[$thisi] = (0.0 - ($r_dtz->getOffset($dateTimeGMT) / (60.0 * 60.0))); //echo $ourtzs[$thisi] . " offset is " . (0.0 - ($r_dtz->getOffset($dateTimeGMT) / (60.0 * 60.0))); //exit; } else { //if (strpos($ofw, "end") !== false) { // echo ' +++ ' . $ourtzs[$thisi] . ' --- '; //} $start_end_offsets[$thisi] = floatval(str_replace('+','',$ourtzs[$thisi])); } } else if (strpos(urldecode($posttz), "/") === false) { $start_end_offsets[0] = floatval(str_replace('+','',urldecode($posttz))); } else { $r_dtz = new DateTimeZone($ourtzs[$thisi]); $dateTimeGMT = new DateTime("now"); $start_end_offsets[$thisi] = (0.0 - ($r_dtz->getOffset($dateTimeGMT) / (60.0 * 60.0))); //echo $ourtzs[$thisi] . " offset Is " . (0.0 - ($r_dtz->getOffset($dateTimeGMT) / (60.0 * 60.0))); //exit; } $di="PT" . str_replace("-","",("" . $start_end_offsets[$thisi])) . "H"; $parsed_date = DateTime::createFromFormat('Ymd:His', $ts); if (strpos(("" . $start_end_offsets[$thisi]), "-") !== false) { //if (strpos($ofw, "end") !== false) { // echo "sub" . $di; //} if (strpos($di, ".25") !== false) { $parsed_date->sub(new DateInterval(explode(".",$di)[0] . "H")); $parsed_date->sub(new DateInterval("PT15M")); } else if (strpos($di, ".75") !== false) { $parsed_date->sub(new DateInterval(explode(".",$di)[0] . "H")); $parsed_date->sub(new DateInterval("PT45M")); } else if (strpos($di, ".") !== false) { $parsed_date->sub(new DateInterval(explode(".",$di)[0] . "H")); $parsed_date->sub(new DateInterval("PT30M")); } else { // if (strpos($_GET['tz'], "Perth") !== false) { // echo $event['datestart'] . " " . $ts . " " . $_GET['tz'] . " " . $thisi . " " . $start_end_offsets[$thisi] . " " . $di; // exit; // } $parsed_date->sub(new DateInterval($di)); } } else { //if (strpos($ofw, "end") !== false) { // echo "add" . $di . " " . urldecode($_POST['tz']) . " start_end_offsets[0] = " . $start_end_offsets[0] . " and start_end_offsets[1] = " . $start_end_offsets[1] . " "; //} if (strpos($di, ".25") !== false) { $parsed_date->add(new DateInterval(explode(".",$di)[0] . "H")); $parsed_date->add(new DateInterval("PT15M")); } else if (strpos($di, ".75") !== false) { $parsed_date->add(new DateInterval(explode(".",$di)[0] . "H")); $parsed_date->add(new DateInterval("PT45M")); } else if (strpos($di, ".") !== false) { $parsed_date->add(new DateInterval(explode(".",$di)[0] . "H")); $parsed_date->add(new DateInterval("PT30M")); } else { $parsed_date->add(new DateInterval($di)); } } $outts = $parsed_date->format('Ymd:His'); //if (strpos($ofw, "end") !== false) { // echo " " . $outts . " "; //} //echo $outts . " " . $di . " "; date_default_timezone_set('Australia/Perth'); } } return $outts; } $proposed_url='http://www.rjmprogramming.com.au/PHP/ics_attachment.php?msg=' . $event['id']; if (isset($_POST['url'])) { if (strpos(urldecode($_POST['url']), "http") !== false) $proposed_url=urldecode($_POST['url']); } else if (isset($_GET['url'])) { if (strpos(urldecode($_GET['url']), "http") !== false) $proposed_url=urldecode($_GET['url']); } // Build the ics file $ical = 'BEGIN:VCALENDAR VERSION:2.0 PRODID:-//hacksw/handcal//NONSGML v1.0//EN CALSCALE:GREGORIAN BEGIN:VEVENT DTEND:' . str_replace(':','T',tzbit($event['dateend'],'dateend')) . 'Z UID:' . md5($event['title']) . ' DTSTAMP:' . time() . ' LOCATION:' . addslashes($event['address']) . ' DESCRIPTION:' . addslashes($event['description']) . ' URL;VALUE=URI:' . $proposed_url . ' SUMMARY:' . addslashes($event['title']) . ' DTSTART:' . str_replace(':','T',tzbit($event['datestart'],'datestart')) . 'Z END:VEVENT END:VCALENDAR'; //echo $ical; //exit; //set correct content-type-header if ($event['id'] >= 0) { if ($emailto != "") { $eol = PHP_EOL; $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol; $headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol; $filename="rjmprogramming-event.ics"; if (strpos($posttz,",") === false) $posttz='' . $start_end_offsets[1] . ',' . $posttz; $subject = $event['title'] . ' ... ' . $event['address'] . ' ... Calendar Start: ' . $event['datestart'] . ' ' . str_replace('() ',' ','(' . explode(',',($posttz . ','))[0] . ') ') . ' End: ' . $event['dateend'] . ' ' . str_replace('()','','(' . explode(',',($posttz . ','))[1] . ')'); $content = chunk_split(base64_encode($ical)); //$uid = md5(uniqid(time())); // a random hash will be necessary to send mixed content $separator = md5(time()); $headers .= "MIME-Version: 1.0" . $eol; $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol . $eol; $headers .= "Content-Transfer-Encoding: 7bit" . $eol; $headers .= "This is a MIME encoded message." . $eol . $eol; // message $headers .= "--" . $separator . $eol; $headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol; $headers .= "Content-Transfer-Encoding: 8bit" . $eol . $eol; $headers .= "Please see attachment below:" . $eol . $eol; //ourpremail($tem, $mysubject, "", $headers . "--" . $separator . "--"); // attachment $headers .= "--" . $separator . $eol; //$headers .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol; $headers .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol; $headers .= "Content-Transfer-Encoding: base64" . $eol; $headers .= "Content-Disposition: attachment;filename=\"" . $filename . "\"" . $eol; $headers .= $content . $eol . $eol; $headers .= "--" . $separator . "--"; mail($emailto, $subject, "", $headers); } if ($interactive) { header('Content-type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename=rjmprogramming-event.ics'); echo $ical; } else if ($emailto == "") { // for debugging purposes header('Content-type: text/html; charset=utf-8'); header('Content-Disposition: attachment; filename=rjmprogramming-event.html'); echo " Calendar *.ics file creation - RJM Programming - November, 2016

" . $ical . "

"; } } else { // If $id isn't set, then kick the user back to home. Do not pass go, and do not collect $200. header('Location: /'); } } // -1 No message // 999999999 No message ?>