<?php
/**
* eventCreator
* ver 2.0
*
* The iCal file event php-HTML form editor
*
* copyright (c) 2006 Kjell-Inge Gustafsson kigkonsult
* www.kigkonsult.se/iCalcreator/eventCreator/index.php
* hide@address.com
* updated 20070117
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* This script manages logging and all file creating and output
*
**/
/** Set flag that this is a parent file */
define( '_VALID_KIG', 1 );
/** setup */
require_once 'eventCreator.config.php';
/** grab command */
$task = isset( $_REQUEST['v']['task'] ) ? $_REQUEST['v']['task'] : null;
/** remove old files */
if( '' < @ECOUTPUTDIR ) {
$timeout = ( 0 < @ECOUTPUTDIRTIMEOUT ) ? ECOUTPUTDIRTIMEOUT : ECTIMEOUT;
ecremFiles( ECOUTPUTDIR, $timeout );
}
/** execute command ? */
switch( $task ) {
case 'xCal':
if( ECXCALOUTPUT ) {
ecreturnCalendar( 'xCal' );
exit;
}
break;
case 'iCal':
if( ECICALOUTPUT ) {
ecreturnCalendar();
exit;
}
break;
case 'rss2Cal':
if( ECRSS2CALOUTPUT ) {
ecrsscalCalendar( '2.0' );
exit;
}
break;
case 'rssCal':
if( ECRSSCALOUTPUT ) {
ecrsscalCalendar();
exit;
}
break;
default:
break;
}
function ectxt2log( $type, $text ) {
if( !defined( 'ECLOG' ))
return FALSE;
if( !file_exists( ECLOG ) && !touch( ECLOG, '0700' ))
return FALSE;
clearstatcache();
if( !is_writeable( ECLOG ))
return FALSE;
clearstatcache();
if ( FALSE !== ( $fp = @fopen ( ECLOG, "a" ))) {
if( is_array( $type ))
$type = implode( ' ', $type );
if( is_array( $text ))
$text = implode( ' ', $text );
$tab = "\t";
$address = $_SERVER['REMOTE_ADDR'];
$host = gethostbyaddr ( $address );
$output = date( 'Y-m-d H:i:s' ).$tab.$type.$tab.$text.$tab.$address.$tab.$host."\n";
@fwrite( $fp, $output );
@fclose( $fp );
}
}
function ecrsscalCalendar( $version=null ) {
require_once ECRSSCAL_DIR.DIRECTORY_SEPARATOR.'rsscalCreator.class.php'; // rssCalreator incl. path
$v = isset( $_REQUEST['v'] ) ? $_REQUEST['v'] : null; // grab data
$feed = new rsscalCreator( $v['SUMMARY'] // create new rsscal feed
, $v['URL'] // with required elements
, $v['DESCRIPTION']
);
if( $version )
$feed->setVersion( $version );
$feed->setChannelElement( 'dc:date', date( 'Y:m:d H:i:s' ));
// create rsscal item
$item = new rsscalItem( $v['SUMMARY'], $v['URL'], $v['DESCRIPTION'] );
// add item elements
$item->addElement( 'ev:type', $v['CLASS'] );
$item->addElement( 'ev:organizer', $v['ORGANIZER'] );
$item->addElement( 'ev:location', $v['LOCATION'] );
$v['DTSTART']['hour'] = (isset( $v['DTSTART']['Hour'])) ? $v['DTSTART']['Hour'] : 0;
$v['DTSTART']['min'] = (isset( $v['DTSTART']['Minute'])) ? $v['DTSTART']['Minute'] : 0;
$item->addElement( 'ev:startdate', date( 'Ymd\THis', mktime ( $v['DTSTART']['hour'], $v['DTSTART']['min'], 0, $v['DTSTART']['Month'], $v['DTSTART']['Day'], $v['DTSTART']['Year'])));
if( !isset( $v['DTEND']['Year'] ) || !empty( $v['chkb'] ))
$v['DTEND'] = $v['DTSTART'];
$v['DTEND']['hour'] = (isset( $v['DTEND']['Hour'])) ? $v['DTEND']['Hour'] : 0;
$v['DTEND']['min'] = (isset( $v['DTEND']['Minute'])) ? $v['DTEND']['Minute'] : 0;
$item->addElement( 'ev:enddate',date( 'Ymd\THis', mktime ( $v['DTEND']['hour'], $v['DTEND']['min'], 0, $v['DTEND']['Month'], $v['DTEND']['Day'], $v['DTEND']['Year'])));
$feed->addItem( $item ); // add item to feed
$directory = ( '' < @ECOUTPUTDIR ) ? ECOUTPUTDIR : ECCACHE;
$filename = ( '' < @ECOUTPUTFIXFILENAME )
? ECOUTPUTFIXFILENAME.'.xml' : date(ECOUTPUTFILENAMETMPL).'.xml';
$feed->setFilename( $directory, $filename );
if( defined( 'ECLOG' )) { // alt 1: log file info before redirect
/** create feed, save file and return file info */
$fileinfo = $feed->saveRSS();
/** log file creation to log file */
ectxt2log( array( 'eventCreator', 'RSS'.$version ), $fileinfo );
/** send file to browser */
$feed->useCachedRSS( $fileinfo[0], $fileinfo[1] );
}
else { // alt 2: create and redirect RSS feed to browser
$feed->returnRSS();
}
exit;
}
function ecreturnCalendar( $format=FALSE ) {
$v = isset( $_REQUEST['v'] ) ? $_REQUEST['v'] : null; // grab data
$calendar = & ecloadFile( $v ); // load old file
$v['directory'] = ( '' < @ECOUTPUTDIR ) ? ECOUTPUTDIR : ECCACHE;
$ext = ( $format ) ? 'xml' : 'ics';
$v['filename'] = ( '' < @ECOUTPUTFIXFILENAME )
? ECOUTPUTFIXFILENAME.".$ext" : date(ECOUTPUTFILENAMETMPL).".$ext";
if( TRUE === @ECSINGLEEVENT )
$calendar = & ecsaveEvent( $v ); // create new file and save single event
else
$calendar = & ecsaveEvent( $v, $calendar ); // create new file and update event
if( $format )
$calendar->setConfig( 'format', $format );
if( defined( 'ECLOG' )) { // alt 1: log file info before redirect
/** get file info */
$fileinfo = $calendar->getConfig( 'fileinfo' );
/** log file creation to log file */
$type = ( $format ) ? 'xCal' : 'iCal';
ectxt2log( array( 'eventCreator', $type ), $fileinfo );
/** send file to browser */
$calendar->useCachedCalendar( $fileinfo[0], $fileinfo[1] );
}
else { // alt 2: return direct
$calendar->returnCalendar();
}
exit;
}
?>