not longer needed

This commit is contained in:
Ralf Becker 2003-03-20 16:41:57 +00:00
parent 0b53b03eae
commit 686537ac7a
5 changed files with 0 additions and 7120 deletions

View File

@ -1,408 +0,0 @@
<?php
/**************************************************************************\
* phpGroupWare - Calendar: CSV - Import *
* http://www.phpgroupware.org *
* Written by Ralf Becker <RalfBecker@outdoor-training.de> *
* -------------------------------------------- *
* 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. *
\**************************************************************************/
/* $Id$ */
$GLOBALS['phpgw_info']['flags'] = Array(
'currentapp' => 'calendar',
'noappheader' => True,
'noappfooter' => True
);
include('../header.inc.php');
$GLOBALS['phpgw']->contacts = createobject('phpgwapi.contacts');
$t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); // $t->unknows = 'keep'; $t->debug = 1;
$t->set_file(array('import' => 'csv_import.tpl'));
$t->set_block('import','filename','filenamehandle');
$t->set_block('import','fheader','fheaderhandle');
$t->set_block('import','fields','fieldshandle');
$t->set_block('import','ffooter','ffooterhandle');
$t->set_block('import','imported','importedhandle');
// $t->set_var("navbar_bg",$phpgw_info["theme"]["navbar_bg"]);
// $t->set_var("navbar_text",$phpgw_info["theme"]["navbar_next"]);
if ($action == 'download' && (!$fieldsep || !$csvfile || !($fp=fopen($csvfile,'r'))))
{
$action = '';
}
$t->set_var('action_url',$GLOBALS['phpgw']->link('/calendar/csv_import.php'));
$t->set_var('lang_cal_action',lang('Import CSV-File into Calendar'));
$PSep = '||'; // Pattern-Separator, separats the pattern-replacement-pairs in trans
$ASep = '|>'; // Assignment-Separator, separats pattern and replacesment
$VPre = '|#'; // Value-Prefix, is expanded to \ for ereg_replace
$CPre = '|['; $CPreReg = '\|\['; // |{csv-fieldname} is expanded to the value of the csv-field
$CPos = ']'; $CPosReg = '\]'; // if used together with @ (replacement is eval-ed) value gets autom. quoted
function dump_array( $arr )
{
while (list($key,$val) = each($arr))
{
$ret .= ($ret ? ',' : '(') . "'$key' => '$val'\n";
}
return $ret.')';
}
function index( $value,$arr )
{
while (list ($key,$val) = each($arr))
{
if ($value == $val)
{
return $key;
}
}
return False;
}
// find in Addressbook, at least n_family AND (n_given OR org_name) have to match
function addr_id( $n_family,$n_given,$org_name )
{
$addrs = $GLOBALS['phpgw']->contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given,org_name=$org_name" );
if (!count($addrs))
{
$addrs = $GLOBALS['phpgw']->contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given" );
}
if (!count($addrs))
{
$addrs = $GLOBALS['phpgw']->contacts->read( 0,0,array('id'),'',"n_family=$n_family,org_name=$org_name" );
}
if (count($addrs))
{
return $addrs[0]['id'];
}
return False;
}
$cat2id = array( );
function cat_id($cats)
{
if (!$cats)
{
return '';
}
$cats = split('[,;]',$cats);
while (list($k,$cat) = each($cats))
{
if (isset($cat2id[$cat]))
{
$ids[$cat] = $cat2id[$cat]; // cat is in cache
}
else
{
if (!is_object($GLOBALS['phpgw']->categories))
{
$GLOBALS['phpgw']->categories = createobject('phpgwapi.categories');
}
if ($id = $GLOBALS['phpgw']->categories->name2id( addslashes($cat) ))
{ // cat exists
$cat2id[$cat] = $ids[$cat] = $id;
}
else
{ // create new cat
$GLOBALS['phpgw']->categories->add(array('name' => $cat,'descr' => $cat));
$cat2id[$cat] = $ids[$cat] = $GLOBALS['phpgw']->categories->name2id( addslashes($cat) );
}
}
}
$id_str = implode( ',',$ids );
if (count($ids) > 1)
{
$id_str = ','.$id_str.',';
}
return $id_str;
}
switch ($action)
{
case '': // Start, ask Filename
$t->set_var('lang_csvfile',lang('CSV-Filename'));
$t->set_var('lang_fieldsep',lang('Fieldseparator'));
$t->set_var('fieldsep',$fieldsep ? $fieldsep : ',');
$t->set_var('submit',lang('Download'));
$t->set_var('csvfile',$csvfile);
$t->set_var('enctype','ENCTYPE="multipart/form-data"');
$hiddenvars .= '<input type="hidden" name="action" value="download">'."\n";
$t->parse('filenamehandle','filename');
break;
case 'download':
$GLOBALS['phpgw']->preferences->read_repository();
$defaults = $GLOBALS['phpgw_info']['user']['preferences']['calendar']['csv_import'];
if (!is_array($defaults))
{
$defaults = array();
}
$t->set_var('lang_csv_fieldname',lang('CSV-Fieldname'));
$t->set_var('lang_cal_fieldname',lang('Calendar-Fieldname'));
$t->set_var('lang_translation',lang("Translation").' <a href="#help">'.lang('help').'</a>');
$t->set_var('submit',lang('Import'));
$t->set_var('lang_debug',lang('Test Import (show importable records <u>only</u> in browser)'));
$t->parse('fheaderhandle','fheader');
$hiddenvars .= '<input type="hidden" name="action" value="import">'."\n"
. '<input type="hidden" name="fieldsep" value="'.$fieldsep."\">\n";
$mktime_lotus = "${PSep}0?([0-9]+)[ .:-]+0?([0-9]*)[ .:-]+0?([0-9]*)[ .:-]+0?([0-9]*)[ .:-]+0?([0-9]*)[ .:-]+0?([0-9]*).*$ASep@mktime(${VPre}4,${VPre}5,${VPre}6,${VPre}2,${VPre}3,${VPre}1)";
$defaults = array (
'VERTRAULICH' => "is_public${PSep}0${ASep}1${PSep}0",
'VONDATUM' => 'datetime'.$mktime_lotus,
'BISDATUM' => 'edatetime'.$mktime_lotus,
'SCHLUSSELID' => "category$PSep@cat_id(${CPre}SCHLUSSELID$CPos)",
'NOTIZEN' => 'title',
);
$cal_names = array(
'owner' => 'Owner of the calendar-entry',
'category' => 'Category: @cat_id(CatName)',
'groups' => 'Groups (dont know what this field is for)',
'datetime' => 'Startdate: @mktime( )',
'mdatetime' => 'Modification date',
'edatetime' => 'Enddate of the entry',
'priority' => 'Priority: 1=Low, 2=Normal, 3=High',
'cal_type' => 'cal_type: single_event=E else M',
'is_public' => 'Access: 1=public, 0=private',
'title' => 'Title varchar(80)',
'description' => 'Description text'
);
$cal_name_options = "<option value=\"\">none\n";
reset($cal_names);
while (list($field,$name) = each($cal_names))
{
$cal_name_options .= "<option value=\"$field\">".$GLOBALS['phpgw']->strip_html($name)."\n";
}
$csv_fields = fgetcsv($fp,8000,$fieldsep);
$csv_fields[] = 'no CSV 1'; // eg. for static assignments
$csv_fields[] = 'no CSV 2';
$csv_fields[] = 'no CSV 3';
while (list($csv_idx,$csv_field) = each($csv_fields))
{
$t->set_var('csv_field',$csv_field);
$t->set_var('csv_idx',$csv_idx);
if ($def = $defaults[$csv_field])
{
list( $cal,$trans ) = explode($PSep,$def,2);
$t->set_var('trans',$trans);
$t->set_var('cal_fields',str_replace('="'.$cal.'">','="'.$cal.'" selected>',$cal_name_options));
}
else
{
$t->set_var('trans','');
$t->set_var('cal_fields',$cal_name_options);
}
$t->parse('fieldshandle','fields',True);
}
$t->set_var('lang_start',lang('Startrecord'));
$t->set_var('start',$start);
$t->set_var('lang_max',lang('Number of records to read (<=200)'));
$t->set_var('max',200);
$t->parse('ffooterhandle','ffooter');
fclose($fp);
$old = $csvfile; $csvfile = $phpgw_info['server']['temp_dir'].'/cal_import_'.basename($csvfile);
rename($old,$csvfile);
$hiddenvars .= '<input type="hidden" name="csvfile" value="'.$csvfile.'">';
$help_on_trans = "<a name='help'><b>How to use Translation's</b><p>".
"Translations enable you to change / adapt the content of each CSV field for your needs. <br>".
"General syntax is: <b>pattern1 ${ASep} replacement1 ${PSep} ... ${PSep} patternN ${ASep} replacementN</b><br>".
"If the pattern-part of a pair is ommited it will match everything ('^.*$'), which is only ".
"usefull for the last pair, as they are worked from left to right.<p>".
"First example: <b>1${ASep}private${PSep}public</b><br>".
"This will translate a '1' in the CSV field to 'privat' and everything else to 'public'.<p>".
"Patterns as well as the replacement can be regular expressions (the replacement is done via ereg_replace). ".
"If, after all replacements, the value starts with an '@' the whole value is eval()'ed, so you ".
"may use all php, phpgw plus your own functions. This is quiet powerfull, but <u>circumvents all ACL</u>.<p>".
"Example using regular expressions and '@'-eval(): <br><b>$mktime_lotus</b><br>".
"It will read a date of the form '2001-05-20 08:00:00.00000000000000000' (and many more, see the regular expr.). ".
"The&nbsp;[&nbsp;.:-]-separated fields are read and assigned in different order to @mktime(). Please note to use ".
"${VPre} insted of a backslash (I couldn't get backslash through all the involved templates and forms.) ".
"plus the field-number of the pattern.<p>".
"In addintion to the fields assign by the pattern of the reg.exp. you can use all other CSV-fields, with the ".
"syntax <b>${CPre}CSV-FIELDNAME$CPos</b>. Here is an example: <br>".
"<b>.+$ASep${CPre}Company$CPos: ${CPre}NFamily$CPos, ${CPre}NGiven$CPos$PSep${CPre}NFamily$CPos, ${CPre}NGiven$CPos</b><br>".
"It is used on the CSV-field 'Company' and constructs a something like <i>Company: FamilyName, GivenName</i> or ".
"<i>FamilyName, GivenName</i> if 'Company' is empty.<p>".
"You can use the 'No CSV #'-fields to assign csv-values to more than on field, the following example uses the ".
"csv-field 'Note' (which gots already assingned to the description) and construct a short subject: ".
"<b>@substr(${CPre}Note$CPos,0,60).' ...'</b><p>".
"Their is one important user-function for the Info Log:<br>".
"<b>@addr_id(${CPre}NFamily$CPos,${CPre}NGiven$CPos,${CPre}Company$CPos)</b> ".
"searches the addressbook for an address and returns the id if it founds an exact match of at least ".
"<i>NFamily</i> AND (<i>NGiven</i> OR <i>Company</i>). This is necessary to link your imported InfoLog-entrys ".
"with the addressbook.<br>".
"<b>@cat_id(Cat1,...,CatN)</b> returns a (','-separated) list with the cat_id's. If a category isn't found, it ".
"will be automaticaly added.<p>".
"I hope that helped to understand the features, if not <a href='mailto:RalfBecker@outdoor-training.de'>ask</a>.";
$t->set_var('help_on_trans',lang($help_on_trans)); // I don't think anyone will translate this
break;
case 'import':
// echo "<p>cal_fields=array(".dump_array($cal_fields).")</p>\n";
$fp=fopen($csvfile,"r");
$csv_fields = fgetcsv($fp,8000,$fieldsep);
$csv_fields[] = 'no CSV 1';
$csv_fields[] = 'no CSV 2';
$csv_fields[] = 'no CSV 3';
$cal_fields = array_diff($cal_fields,array( '' )); // throw away empty / not assigned entrys
$defaults = array();
while (list($csv_idx,$addr) = each($cal_fields))
{ // convert $trans[$csv_idx] into array of pattern => value
$defaults[$csv_fields[$csv_idx]] = $cal;
if ($trans[$csv_idx])
{
$defaults[$csv_fields[$csv_idx]] .= $PSep.$trans[$csv_idx];
}
}
$GLOBALS['phpgw']->preferences->read_repository();
$GLOBALS['phpgw']->preferences->add('calendar','csv_import',$defaults);
$GLOBALS['phpgw']->preferences->save_repository(True);
$log = "<table border=1>\n\t<tr><td>#</td>\n";
reset($cal_fields);
while (list($csv_idx,$cal) = each($cal_fields))
{ // convert $trans[$csv_idx] into array of pattern => value
// if (!$debug) echo "<p>$csv_idx: ".$csv_fields[$csv_idx].": $cal".($trans[$csv_idx] ? ': '.$trans[$csv_idx] : '')."</p>";
$pat_reps = explode($PSep,stripslashes($trans[$csv_idx]));
$replaces = ''; $values = '';
if ($pat_reps[0] != '')
{
while (list($k,$pat_rep) = each($pat_reps))
{
list($pattern,$replace) = explode($ASep,$pat_rep,2);
if ($replace == '')
{
$replace = $pattern; $pattern = '^.*$';
}
$values[$pattern] = $replace; // replace two with only one, added by the form
$replaces .= ($replaces != '' ? $PSep : '') . $pattern . $ASep . $replace;
}
$trans[$csv_idx] = $values;
}
else
{
unset( $trans[$csv_idx] );
}
$log .= "\t\t<td><b>$cal</b></td>\n";
}
$user = $phpgw_info['user']['account_id'];
$calendar = $GLOBALS['phpgw']->calendar;
$calendar->open('INBOX',$user,'');
if ($start < 1) $start = 1;
for ($i = 1; $i < $start && fgetcsv($fp,8000,$fieldsep); ++$i); // overread lines before our start-record
for ($anz = 0; $anz < $max && ($fields = fgetcsv($fp,8000,$fieldsep)); ++$anz)
{
$log .= "\t</tr><tr><td>".($start+$anz)."</td>\n";
reset($cal_fields); $values = array();
while (list($csv_idx,$cal) = each($cal_fields))
{
// echo "<p>$csv_idx: $cal".($trans[$csv] ? ': '.$trans[$csv] : '')."</p>";
$val = $fields[$csv_idx];
if (isset($trans[$csv_idx]))
{
$trans_csv = $trans[$csv_idx];
while (list($pattern,$replace) = each($trans_csv))
{
if (ereg((string) $pattern,$val))
{
// echo "<p>csv_idx='$csv_idx',info='$cal',trans_csv=".dump_array($trans_csv).",ereg_replace('$pattern','$replace','$val') = ";
$val = ereg_replace((string) $pattern,str_replace($VPre,'\\',$replace),(string) $val);
// echo "'$val'</p>";
$quote = $val[0] == '@' ? "'" : '';
$reg = $CPreReg.'([a-zA-Z_0-9]+)'.$CPosReg;
while (ereg($reg,$val,$vars))
{ // expand all CSV fields
$val = str_replace($CPre.$vars[1].$CPos,$val[0]=='@'?"'".addslashes($fields[index($vars[1],$csv_fields)])."'":
$fields[index($vars[1],$csv_fields)],$val);
}
if ($val[0] == '@')
{
// removing the $ to close security hole of showing vars, which contain eg. passwords
$val = 'return '.substr(str_replace('$','',$val),1).';';
// echo "<p>eval('$val')=";
$val = eval($val);
// echo "'$val'</p>";
}
if ($pattern[0] != '@' || $val)
{
break;
}
}
}
}
$values[$cal] = $val;
$log .= "\t\t<td>$val</td>\n";
}
// if (!isset($values['datecreated'])) $values['datecreated'] = $values['startdate'];
if (!$debug)
{
// echo "<p>adding: ".dump_array($values)."</p>\n";
$calendar->event_init(); // set some reasonable defaults
$calendar->set_recur_none();
$calendar->event->owner = $user;
$calendar->event->priority = 2;
$calendar->event->title = $calendar->event->description = '';
$calendar->event->participants = array ( $user => 'A' );
while (list($cal,$val) = each($values)) {
switch ($cal) {
case 'is_public':
$calendar->event->public = $val;
break;
case 'datetime': case 'edatetime':
$date = $calendar->datetime->localdates($val);
$func = $cal == 'datetime' ? 'set_start' : 'set_end';
$calendar->$func($date['year'],$date['month'],$date['day'],
$date['hour'],$date['minute'],$date['second']);
break;
default:
$calendar->event->$cal = $val;
break;
}
}
$calendar->save_event( $calendar->event );
}
}
$log .= "\t</tr>\n</table>\n";
$t->set_var('anz_imported',$debug ? lang( '%1 records read (not yet imported, you may go back and uncheck Test Import)',
$anz,'<a href="javascript:history.back()">','</a>' ) :
lang( '%1 records imported',$anz ));
$t->set_var('log',$log);
$t->parse('importedhandle','imported');
break;
}
$t->set_var('hiddenvars',$hiddenvars);
$t->pfp('out','import',True);
$GLOBALS['phpgw']->common->phpgw_footer();
?>

File diff suppressed because it is too large Load Diff

View File

@ -1,616 +0,0 @@
<?php
/**************************************************************************\
* phpGroupWare - Calendar *
* http://www.phpgroupware.org *
* Based on Webcalendar by Craig Knudsen <cknudsen@radix.net> *
* http://www.radix.net/~cknudsen *
* Modified by Mark Peters <skeeter@phpgroupware.org> *
* -------------------------------------------- *
* 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. *
\**************************************************************************/
/* $Id$ */
if (@$GLOBALS['phpgw_info']['flags']['included_classes']['socalendar_'])
{
return;
}
$GLOBALS['phpgw_info']['flags']['included_classes']['socalendar_'] = True;
class socalendar_ extends socalendar__
{
var $deleted_events = Array();
var $cal_event;
var $today = Array('raw','day','month','year','full','dow','dm','bd');
function socalendar_()
{
$this->socalendar__();
}
function open($calendar='',$user='',$passwd='',$options='')
{
if($user=='')
{
// settype($user,'integer');
$this->user = $GLOBALS['phpgw_info']['user']['account_id'];
}
elseif(is_int($user))
{
$this->user = $user;
}
elseif(is_string($user))
{
$this->user = $GLOBALS['phpgw']->accounts->name2id($user);
}
$this->stream = $GLOBALS['phpgw']->db;
return $this->stream;
}
function popen($calendar='',$user='',$passwd='',$options='')
{
return $this->open($calendar,$user,$passwd,$options);
}
function reopen($calendar,$options='')
{
return $this->stream;
}
function close($options='')
{
return True;
}
function create_calendar($calendar='')
{
return $calendar;
}
function rename_calendar($old_name='',$new_name='')
{
return $new_name;
}
function delete_calendar($calendar='')
{
$this->stream->query('SELECT cal_id FROM phpgw_cal WHERE owner='.intval($calendar),__LINE__,__FILE__);
if($this->stream->num_rows())
{
while($this->stream->next_record())
{
$this->delete_event(intval($this->stream->f('cal_id')));
}
$this->expunge();
}
$this->stream->lock(array('phpgw_cal_user'));
$this->stream->query('DELETE FROM phpgw_cal_user WHERE cal_login='.intval($calendar),__LINE__,__FILE__);
$this->stream->unlock();
return $calendar;
}
function fetch_event($event_id,$options='')
{
if(!isset($this->stream))
{
return False;
}
$this->stream->lock(array('phpgw_cal','phpgw_cal_user','phpgw_cal_repeats','phpgw_cal_alarm'));
$this->stream->query('SELECT * FROM phpgw_cal WHERE cal_id='.$event_id,__LINE__,__FILE__);
if($this->stream->num_rows() > 0)
{
$this->event_init();
$this->stream->next_record();
// Load the calendar event data from the db into $event structure
// Use http://www.php.net/manual/en/function.mcal-fetch-event.php as the reference
$this->add_attribute('owner',intval($this->stream->f('owner')));
$this->add_attribute('id',intval($this->stream->f('cal_id')));
$this->set_class(intval($this->stream->f('is_public')));
$this->set_category($this->stream->f('category'));
$this->set_title($GLOBALS['phpgw']->strip_html($this->stream->f('title')));
$this->set_description($GLOBALS['phpgw']->strip_html($this->stream->f('description')));
$this->add_attribute('uid',$GLOBALS['phpgw']->strip_html($this->stream->f('uid')));
$this->add_attribute('location',$GLOBALS['phpgw']->strip_html($this->stream->f('location')));
$this->add_attribute('reference',intval($this->stream->f('reference')));
// This is the preferred method once everything is normalized...
//$this->event->alarm = intval($this->stream->f('alarm'));
// But until then, do it this way...
//Legacy Support (New)
$datetime = $GLOBALS['phpgw']->datetime->localdates($this->stream->f('datetime'));
$this->set_start($datetime['year'],$datetime['month'],$datetime['day'],$datetime['hour'],$datetime['minute'],$datetime['second']);
$datetime = $GLOBALS['phpgw']->datetime->localdates($this->stream->f('mdatetime'));
$this->set_date('modtime',$datetime['year'],$datetime['month'],$datetime['day'],$datetime['hour'],$datetime['minute'],$datetime['second']);
$datetime = $GLOBALS['phpgw']->datetime->localdates($this->stream->f('edatetime'));
$this->set_end($datetime['year'],$datetime['month'],$datetime['day'],$datetime['hour'],$datetime['minute'],$datetime['second']);
//Legacy Support
$this->add_attribute('priority',intval($this->stream->f('priority')));
if($this->stream->f('cal_group') || $this->stream->f('groups') != 'NULL')
{
$groups = explode(',',$this->stream->f('groups'));
for($j=1;$j<count($groups) - 1;$j++)
{
$this->add_attribute('groups',$groups[$j],$j-1);
}
}
$this->stream->query('SELECT * FROM phpgw_cal_repeats WHERE cal_id='.$event_id,__LINE__,__FILE__);
if($this->stream->num_rows())
{
$this->stream->next_record();
$this->add_attribute('recur_type',intval($this->stream->f('recur_type')));
$this->add_attribute('recur_interval',intval($this->stream->f('recur_interval')));
$enddate = $this->stream->f('recur_enddate');
if($enddate != 0 && $enddate != Null)
{
$datetime = $GLOBALS['phpgw']->datetime->localdates($enddate);
$this->add_attribute('recur_enddate',$datetime['year'],'year');
$this->add_attribute('recur_enddate',$datetime['month'],'month');
$this->add_attribute('recur_enddate',$datetime['day'],'mday');
$this->add_attribute('recur_enddate',$datetime['hour'],'hour');
$this->add_attribute('recur_enddate',$datetime['minute'],'min');
$this->add_attribute('recur_enddate',$datetime['second'],'sec');
}
else
{
$this->add_attribute('recur_enddate',0,'year');
$this->add_attribute('recur_enddate',0,'month');
$this->add_attribute('recur_enddate',0,'mday');
$this->add_attribute('recur_enddate',0,'hour');
$this->add_attribute('recur_enddate',0,'min');
$this->add_attribute('recur_enddate',0,'sec');
}
$this->add_attribute('recur_enddate',0,'alarm');
if($this->debug)
{
echo 'Event ID#'.$this->event['id'].' : Enddate = '.$enddate."<br>\n";
}
$this->add_attribute('recur_data',$this->stream->f('recur_data'));
$exception_list = $this->stream->f('recur_exception');
$exceptions = Array();
if(strpos(' '.$exception_list,','))
{
$exceptions = explode(',',$exception_list);
}
elseif($exception_list != '')
{
$exceptions[]= $exception_list;
}
$this->add_attribute('recur_exception',$exceptions);
}
//Legacy Support
$this->stream->query('SELECT * FROM phpgw_cal_user WHERE cal_id='.$event_id,__LINE__,__FILE__);
if($this->stream->num_rows())
{
while($this->stream->next_record())
{
if(intval($this->stream->f('cal_login')) == intval($this->user))
{
$this->add_attribute('users_status',$this->stream->f('cal_status'));
}
$this->add_attribute('participants',$this->stream->f('cal_status'),intval($this->stream->f('cal_login')));
}
}
if($this->event['reference'])
{
$alarm_cal_id = $event_id.','.$this->event['reference'];
}
else
{
$alarm_cal_id = $event_id;
}
$this->stream->query('SELECT * FROM phpgw_cal_alarm WHERE cal_id in ('.$alarm_cal_id.') AND cal_owner='.$this->user,__LINE__,__FILE__);
if($this->stream->num_rows())
{
while($this->stream->next_record())
{
$this->event['alarm'][] = Array(
'id' => intval($this->stream->f('alarm_id')),
'time' => intval($this->stream->f('cal_time')),
'text' => $this->stream->f('cal_text'),
'enabled' => intval($this->stream->f('alarm_enabled'))
);
}
}
}
else
{
$this->event = False;
}
$this->stream->unlock();
return $this->event;
}
function list_events($startYear,$startMonth,$startDay,$endYear=0,$endMonth=0,$endDay=0,$extra='',$tz_offset=0,$owner_id=0)
{
if(!isset($this->stream))
{
return False;
}
$datetime = mktime(0,0,0,$startMonth,$startDay,$startYear) - $tz_offset;
$user_where = ' AND (phpgw_cal_user.cal_login in (';
if($owner_id)
{
$user_where .= implode(',',$owner_id);
}
else
{
$user_where .= $this->user;
}
$member_groups = $GLOBALS['phpgw']->accounts->membership($this->user);
@reset($member_groups);
while($member_groups != False && list($key,$group_info) = each($member_groups))
{
$member[] = $group_info['account_id'];
}
@reset($member);
// $user_where .= ','.implode(',',$member);
$user_where .= ')) ';
if($this->debug)
{
echo '<!-- '.$user_where.' -->'."\n";
}
$startDate = 'AND ( ( (phpgw_cal.datetime >= '.$datetime.') ';
$enddate = '';
if($endYear != 0 && $endMonth != 0 && $endDay != 0)
{
$edatetime = mktime(23,59,59,intval($endMonth),intval($endDay),intval($endYear)) - $tz_offset;
$endDate .= 'AND (phpgw_cal.edatetime <= '.$edatetime.') ) '
. 'OR ( (phpgw_cal.datetime <= '.$datetime.') '
. 'AND (phpgw_cal.edatetime >= '.$edatetime.') ) '
. 'OR ( (phpgw_cal.datetime >= '.$datetime.') '
. 'AND (phpgw_cal.datetime <= '.$edatetime.') '
. 'AND (phpgw_cal.edatetime >= '.$edatetime.') ) '
. 'OR ( (phpgw_cal.datetime <= '.$datetime.') '
. 'AND (phpgw_cal.edatetime >= '.$datetime.') '
. 'AND (phpgw_cal.edatetime <= '.$edatetime.') ';
}
$endDate .= ') ) ';
$order_by = 'ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC, phpgw_cal.priority ASC';
if($this->debug)
{
echo "SQL : ".$user_where.$startDate.$endDate.$extra."<br>\n";
}
return $this->get_event_ids(False,$user_where.$startDate.$endDate.$extra.$order_by);
}
function append_event()
{
$this->save_event($this->event);
$this->send_update(MSG_ADDED,$this->event->participants,'',$this->event);
return $this->event['id'];
}
function store_event()
{
return $this->save_event(&$this->event);
}
function delete_event($event_id)
{
$this->deleted_events[] = $event_id;
}
function snooze($event_id)
{
//Turn off an alarm for an event
//Returns true.
}
function list_alarms($begin_year='',$begin_month='',$begin_day='',$end_year='',$end_month='',$end_day='')
{
//Return a list of events that has an alarm triggered at the given datetime
//Returns an array of event ID's
}
// The function definition doesn't look correct...
// Need more information for this function
function next_recurrence($weekstart,$next)
{
// return next_recurrence (int stream, int weekstart, array next);
}
function expunge()
{
reset($this->deleted_events);
if(count($this->deleted_events) <= 0)
{
return 1;
}
$this_event = $this->event;
$locks = Array(
'phpgw_cal',
'phpgw_cal_user',
'phpgw_cal_repeats',
'phpgw_cal_alarm'
);
$this->stream->lock($locks);
for($i=0;$i<count($this->deleted_events);$i++)
{
for($k=0;$k<count($locks);$k++)
{
$this->stream->query('DELETE FROM '.$locks[$k].' WHERE cal_id='.$this->deleted_events[$i],__LINE__,__FILE__);
}
}
$this->stream->unlock();
$this->event = $this_event;
return 1;
}
/***************** Local functions for SQL based Calendar *****************/
function get_event_ids($search_repeats=False,$extra='')
{
if($search_repeats == True)
{
$repeats_from = ', phpgw_cal_repeats ';
$repeats_where = 'AND (phpgw_cal_repeats.cal_id = phpgw_cal.cal_id) ';
}
else
{
$repeats_from = ' ';
$repeats_where = '';
}
$sql = 'SELECT DISTINCT phpgw_cal.cal_id,'
. 'phpgw_cal.datetime,phpgw_cal.edatetime,'
. 'phpgw_cal.priority '
. 'FROM phpgw_cal, phpgw_cal_user'
. $repeats_from
. 'WHERE (phpgw_cal_user.cal_id = phpgw_cal.cal_id) '
. $repeats_where . $extra;
if($this->debug)
{
echo "FULL SQL : ".$sql."<br>\n";
}
$this->stream->query($sql,__LINE__,__FILE__);
$retval = Array();
if($this->stream->num_rows() == 0)
{
if($this->debug)
{
echo "No records found!<br>\n";
}
return $retval;
}
while($this->stream->next_record())
{
$retval[] = intval($this->stream->f('cal_id'));
}
if($this->debug)
{
echo "Records found!<br>\n";
}
return $retval;
}
function save_event(&$event)
{
$locks = Array(
'phpgw_cal',
'phpgw_cal_user',
'phpgw_cal_repeats'
);
$this->stream->lock($locks);
if($event['id'] == 0)
{
if(!$event['uid'])
{
if ($GLOBALS['phpgw_info']['server']['hostname'] != '')
{
$id_suffix = $GLOBALS['phpgw_info']['server']['hostname'];
}
else
{
$id_suffix = $GLOBALS['phpgw']->common->randomstring(3).'local';
}
$parts = Array(
0 => 'title',
1 => 'description'
);
@reset($parts);
while(list($key,$field) = each($parts))
{
$part[$key] = substr($GLOBALS['phpgw']->crypto->encrypt($event[$field]),0,20);
if(!$GLOBALS['phpgw']->crypto->enabled)
{
$part[$key] = bin2hex(unserialize($part[$key]));
}
}
$event['uid'] = $part[0].'-'.$part[1].'@'.$id_suffix;
}
$temp_name = tempnam($GLOBALS['phpgw_info']['server']['temp_dir'],'cal');
$this->stream->query('INSERT INTO phpgw_cal(uid,title,owner,priority,is_public,category) '
. "values('".$event['uid']."','".$temp_name."',".$event['owner'].','.$event['priority'].','.$event['public'].",'".$event['category']."')");
$this->stream->query("SELECT cal_id FROM phpgw_cal WHERE title='".$temp_name."'");
$this->stream->next_record();
$event['id'] = $this->stream->f('cal_id');
}
$date = $this->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
$enddate = $this->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
$today = time() - $GLOBALS['phpgw']->datetime->tz_offset;
if($event['recur_type'] != MCAL_RECUR_NONE)
{
$type = 'M';
}
else
{
$type = 'E';
}
$sql = 'UPDATE phpgw_cal SET '
. 'owner='.$event['owner'].', '
. 'datetime='.$date.', '
. 'mdatetime='.$today.', '
. 'edatetime='.$enddate.', '
. 'priority='.$event['priority'].', '
. "category='".$event['category']."', "
. "cal_type='".$type."', "
. 'is_public='.$event['public'].', '
. "title='".$this->stream->db_addslashes($event['title'])."', "
. "description='".$this->stream->db_addslashes($event['description'])."', "
. "location='".$event['location']."', "
. ($event['groups']?"groups='".(count($event['groups'])>1?implode(',',$event['groups']):','.$event['groups'][0].',')."', ":'')
. 'reference='.$event['reference'].' '
. 'WHERE cal_id='.$event['id'];
$this->stream->query($sql,__LINE__,__FILE__);
$this->stream->query('DELETE FROM phpgw_cal_user WHERE cal_id='.$event['id'],__LINE__,__FILE__);
@reset($event['participants']);
while (list($key,$value) = @each($event['participants']))
{
if(intval($key) == $event['owner']/*RB intval($this->user)*/)
{
$value = 'A';
}
$this->stream->query('INSERT INTO phpgw_cal_user(cal_id,cal_login,cal_status) '
. 'VALUES('.$event['id'].','.intval($key).",'".$value."')",__LINE__,__FILE__);
}
if($event['recur_type'] != MCAL_RECUR_NONE)
{
if($event['recur_enddate']['month'] != 0 && $event['recur_enddate']['mday'] != 0 && $event['recur_enddate']['year'] != 0)
{
$end = $this->maketime($event['recur_enddate']) - $GLOBALS['phpgw']->datetime->tz_offset;
}
else
{
$end = 0;
}
$this->stream->query('SELECT count(cal_id) FROM phpgw_cal_repeats WHERE cal_id='.$event['id'],__LINE__,__FILE__);
$this->stream->next_record();
$num_rows = $this->stream->f(0);
if($num_rows == 0)
{
$this->stream->query('INSERT INTO phpgw_cal_repeats(cal_id,recur_type,recur_enddate,recur_data,recur_interval) '
.'VALUES('.$event['id'].','.$event['recur_type'].','.$end.','.$event['recur_data'].','.$event['recur_interval'].')',__LINE__,__FILE__);
}
else
{
$this->stream->query('UPDATE phpgw_cal_repeats '
. 'SET recur_type='.$event['recur_type'].', '
. 'recur_enddate='.$end.', '
. 'recur_data='.$event['recur_data'].', '
. 'recur_interval='.$event['recur_interval'].', '
. "recur_exception='".(count($event['recur_exception'])>1?implode(',',$event['recur_exception']):(count($event['recur_exception'])==1?$event['recur_exception'][0]:''))."' "
. 'WHERE cal_id='.$event['id'],__LINE__,__FILE__);
}
}
else
{
$this->stream->query('DELETE FROM phpgw_cal_repeats WHERE cal_id='.$event['id'],__LINE__,__FILE__);
}
if($this->debug)
{
echo '<!-- Event ID #'.$event['id'].' saved! -->'."\n";
}
$this->stream->unlock();
return True;
}
function get_alarm($id)
{
$this->stream->query('SELECT cal_time, cal_text FROM phpgw_cal_alarm WHERE cal_id='.$id.' AND cal_owner='.$this->user,__LINE__,__FILE__);
if($this->stream->num_rows())
{
while($this->stream->next_record())
{
$alarm[$this->stream->f('cal_time')] = $this->stream->f('cal_text');
}
@reset($alarm);
return $alarm;
}
else
{
return False;
}
}
function set_status($id,$owner,$status)
{
$status_code_short = Array(
REJECTED => 'R',
NO_RESPONSE => 'U',
TENTATIVE => 'T',
ACCEPTED => 'A'
);
$this->stream->query("UPDATE phpgw_cal_user SET cal_status='".$status_code_short[$status]."' WHERE cal_id=".$id." AND cal_login=".$owner,__LINE__,__FILE__);
return True;
}
// End of ICal style support.......
function group_search($owner=0)
{
$owner = ($owner==$GLOBALS['phpgw_info']['user']['account_id']?0:$owner);
$groups = substr($GLOBALS['phpgw']->common->sql_search('phpgw_cal.groups',intval($owner)),4);
if (!$groups)
{
return '';
}
else
{
return "(phpgw_cal.is_public=2 AND (". $groups .')) ';
}
}
function splittime_($time)
{
$temp = array('hour','minute','second','ampm');
$time = strrev($time);
$second = (int)strrev(substr($time,0,2));
$minute = (int)strrev(substr($time,2,2));
$hour = (int)strrev(substr($time,4));
$temp['second'] = (int)$second;
$temp['minute'] = (int)$minute;
$temp['hour'] = (int)$hour;
$temp['ampm'] = ' ';
return $temp;
}
function date_to_epoch($d)
{
return $this->localdates(mktime(0,0,0,intval(substr($d,4,2)),intval(substr($d,6,2)),intval(substr($d,0,4))));
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +0,0 @@
infolog/calendar contains some special versions / adaptations of files from the calendar.
They differ, because:
- the planner is working fully
- infolog is integrated in uicalendar.view
- modifications / corrections on the ACL (still in progress)
I use it to keep track of my changes and be able to sumbit the changes in small patches to skeeter.
If you want to use this version of calendar, simply symlink the files to the coresponding calendar directory.