egroupware/calendar/edit_entry.php

408 lines
14 KiB
PHP
Raw Normal View History

2000-08-18 05:24:22 +02:00
<?php
/**************************************************************************\
* phpGroupWare - Calendar *
* http://www.phpgroupware.org *
* Based on Webcalendar by Craig Knudsen <cknudsen@radix.net> *
* http://www.radix.net/~cknudsen *
2001-01-17 13:35:43 +01:00
* Modified by Mark Peters <skeeter@phpgroupware.org> *
2000-08-18 05:24:22 +02:00
* -------------------------------------------- *
* 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$ */
2001-02-18 23:33:10 +01:00
$phpgw_flags = Array(
2001-02-26 13:23:48 +01:00
'currentapp' => 'calendar',
'enable_nextmatchs_class' => True,
'enable_categories_class' => True,
2001-02-26 13:23:48 +01:00
'noheader' => True,
'nonavbar' => True,
'noappheader' => True,
'noappfooter' => True
2001-02-18 23:33:10 +01:00
);
$phpgw_info['flags'] = $phpgw_flags;
include('../header.inc.php');
$sb = CreateObject('phpgwapi.sbox');
$cal_info = CreateObject('calendar.calendar_item');
2001-05-15 06:13:20 +02:00
function display_item(&$p,$field,$data)
2001-02-18 23:33:10 +01:00
{
$p->set_var('field',$field);
$p->set_var('data',$data);
2001-05-15 06:13:20 +02:00
$p->parse('row','list',True);
2001-02-18 23:33:10 +01:00
}
if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12')
{
$hourformat = 'h';
}
else
{
$hourformat = 'H';
}
if ($id > 0)
{
$phpgw->calendar->open('INBOX',intval($owner),'');
$event = $phpgw->calendar->fetch_event(intval($id));
2001-02-18 23:33:10 +01:00
$can_edit = False;
if(($event->owner == $owner) && ($phpgw->calendar->check_perms(PHPGW_ACL_EDIT) == True))
2001-02-18 23:33:10 +01:00
{
if($event->public != True)
{
if($phpgw->calendar->check_perms(PHPGW_ACL_PRIVATE) == True)
{
$can_edit = True;
}
}
else
{
$can_edit = True;
}
2001-02-18 23:33:10 +01:00
}
if($can_edit == False)
{
header('Location: '.$phpgw->link('/calendar/view.php','id='.$id.'&owner='.$owner));
2001-02-18 23:33:10 +01:00
}
}
elseif(isset($readsess))
{
$event = unserialize(str_replace('O:8:"stdClass"','O:13:"calendar_time"',serialize($phpgw->session->appsession('entry','calendar'))));
2001-02-18 23:33:10 +01:00
if($event->owner == 0)
2001-02-18 23:33:10 +01:00
{
$phpgw->calendar->add_attribute('owner',$owner);
2001-02-18 23:33:10 +01:00
}
$can_edit = True;
}
else
{
if($phpgw->calendar->check_perms(PHPGW_ACL_ADD) == False)
{
header('Location: '.$phpgw->link('/calendar/view.php','id='.$id.'&owner='.$owner));
2001-02-18 23:33:10 +01:00
}
$phpgw->calendar->open('INBOX',intval($cal_info->owner),'');
$phpgw->calendar->event_init();
$phpgw->calendar->add_attribute('id',0);
2001-02-18 23:33:10 +01:00
$can_edit = True;
if (!isset($hour))
{
$thishour = 0;
}
else
{
$thishour = (int)$hour;
}
if (!isset($minute))
{
$thisminute = 00;
}
else
{
$thisminute = (int)$minute;
}
2001-07-01 16:03:03 +02:00
$phpgw->calendar->set_start($thisyear,$thismonth,$thisday,$thishour,$thisminute,0);
$phpgw->calendar->set_end($thisyear,$thismonth,$thisday,$thishour,$thisminute,0);
$phpgw->calendar->set_title('');
$phpgw->calendar->set_description('');
$phpgw->calendar->add_attribute('priority',2);
if($phpgw_info['user']['preferences']['calendar']['default_private'] == 'Y' || $phpgw_info['user']['preferences']['calendar']['default_private'] == True)
{
$phpgw->calendar->set_class(False);
}
else
{
$phpgw->calendar->set_class(True);
}
2001-02-18 23:33:10 +01:00
$phpgw->calendar->set_recur_none();
$event = $phpgw->calendar->event;
2001-02-18 23:33:10 +01:00
}
$start = mktime($event->start->hour,$event->start->min,$event->start->sec,$event->start->month,$event->start->mday,$event->start->year) - $phpgw->calendar->datetime->tz_offset;
$end = mktime($event->end->hour,$event->end->min,$event->end->sec,$event->end->month,$event->end->mday,$event->end->year) - $phpgw->calendar->datetime->tz_offset;
2001-02-18 23:33:10 +01:00
$phpgw->common->phpgw_header();
echo parse_navbar();
$p = CreateObject('phpgwapi.Template',$phpgw->calendar->template_dir);
2001-02-18 23:33:10 +01:00
$templates = Array(
2001-05-15 06:13:20 +02:00
'edit' => 'edit.tpl',
'form_button' => 'form_button_script.tpl'
2001-02-18 23:33:10 +01:00
);
$p->set_file($templates);
2001-05-15 06:13:20 +02:00
$p->set_block('edit','edit_entry','edit_entry');
$p->set_block('edit','list','list');
$p->set_block('edit','hr','hr');
2001-02-18 23:33:10 +01:00
if($id > 0)
{
$action = lang('Calendar - Edit');
}
else
{
$action = lang('Calendar - Add');
}
if($cd)
{
$errormsg = $phpgw->common->check_code($cd);
}
else
{
$errormsg = '';
}
$common_hidden = '<input type="hidden" name="id" value="'.$event->id.'">'."\n"
2001-02-18 23:33:10 +01:00
. '<input type="hidden" name="owner" value="'.$owner.'">'."\n";
$vars = Array(
2001-05-18 04:18:23 +02:00
'font' => $phpgw_info['theme']['font'],
2001-02-18 23:33:10 +01:00
'bg_color' => $phpgw_info['theme']['bg_text'],
'calendar_action' => $action,
'action_url' => $phpgw->link('/calendar/edit_entry_handler.php'),
'common_hidden' => $common_hidden,
'errormsg' => $errormsg
2001-02-18 23:33:10 +01:00
);
$p->set_var($vars);
2000-08-18 05:24:22 +02:00
2000-11-26 21:10:35 +01:00
// Brief Description
2001-05-15 06:13:20 +02:00
display_item($p,lang('Title'),'<input name="title" size="25" maxlength="80" value="'.$event->title.'">');
2000-11-26 21:10:35 +01:00
// Full Description
2001-05-15 06:13:20 +02:00
display_item($p,lang('Full Description'),'<textarea name="description" rows="5" cols="40" wrap="virtual" maxlength="2048">'.$event->description.'</textarea>');
2000-08-18 05:24:22 +02:00
// Display Categories
2001-05-15 06:13:20 +02:00
display_item($p,lang('Category'),'<select name="category"><option value="">'.lang('Choose the category').'</option>'.$phpgw->categories->formated_list('select','all',$event->category,True).'</select>');
2000-11-26 21:10:35 +01:00
// Date
$day_html = $sb->getDays('start[mday]',intval($phpgw->common->show_date($start,'d')));
$month_html = $sb->getMonthText('start[month]',intval($phpgw->common->show_date($start,'n')));
$year_html = $sb->getYears('start[year]',intval($phpgw->common->show_date($start,'Y')),intval($phpgw->common->show_date($start,'Y')));
2001-05-15 06:13:20 +02:00
display_item($p,lang('Start Date'),$phpgw->common->dateformatorder($year_html,$month_html,$day_html));
2000-08-18 05:24:22 +02:00
2000-11-26 21:10:35 +01:00
// Time
2001-02-18 23:33:10 +01:00
$amsel = ' checked'; $pmsel = '';
if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12')
{
if ($event->start->hour >= 12)
2001-02-18 23:33:10 +01:00
{
$amsel = ''; $pmsel = ' checked';
}
}
$str = '<input name="start[hour]" size="2" VALUE="'.$phpgw->common->show_date($start,$hourformat).'" maxlength="2">:<input name="start[min]" size="2" value="'.$phpgw->common->show_date($start,'i').'" maxlength="2">';
2001-02-18 23:33:10 +01:00
if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12')
{
$str .= '<input type="radio" name="start[ampm]" value="am"'.$amsel.'>am';
$str .= '<input type="radio" name="start[ampm]" value="pm"'.$pmsel.'>pm';
2001-02-18 23:33:10 +01:00
}
2001-05-15 06:13:20 +02:00
display_item($p,lang('Start Time'),$str);
2001-02-18 23:33:10 +01:00
// End Date
$day_html = $sb->getDays('end[mday]',intval($phpgw->common->show_date($end,'d')));
$month_html = $sb->getMonthText('end[month]',intval($phpgw->common->show_date($end,'n')));
$year_html = $sb->getYears('end[year]',intval($phpgw->common->show_date($end,'Y')),intval($phpgw->common->show_date($end,'Y')));
2001-05-15 06:13:20 +02:00
display_item($p,lang('End Date'),$phpgw->common->dateformatorder($year_html,$month_html,$day_html));
// End Time
2001-02-18 23:33:10 +01:00
$amsel = ' checked'; $pmsel = '';
if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12')
{
if ($event->end->hour >= 12)
2001-02-18 23:33:10 +01:00
{
$amsel = ''; $pmsel = ' checked';
}
}
$str = '<input name="end[hour]" size="2" VALUE="'.$phpgw->common->show_date($end,$hourformat).'" maxlength="2">:<input name="end[min]" size="2" value="'.$phpgw->common->show_date($end,'i').'" maxlength="2">';
2001-02-18 23:33:10 +01:00
if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12')
{
$str .= '<input type="radio" name="end[ampm]" value="am"'.$amsel.'>am';
$str .= '<input type="radio" name="end[ampm]" value="pm"'.$pmsel.'>pm';
2001-02-18 23:33:10 +01:00
}
2001-05-15 06:13:20 +02:00
display_item($p,lang("End Time"),$str);
2000-11-23 02:37:50 +01:00
2000-11-26 21:10:35 +01:00
// Priority
2001-05-15 06:13:20 +02:00
display_item($p,lang('Priority'),$sb->getPriority('priority',$event->priority));
2000-11-23 02:37:50 +01:00
2000-12-23 17:33:22 +01:00
// Access
$str = '<input type="checkbox" name="private" value="private"';
if($event->public != True)
2001-02-18 23:33:10 +01:00
{
$str .= ' checked';
}
$str .= '>';
2001-05-15 06:13:20 +02:00
display_item($p,lang('Private'),$str);
2000-11-23 02:37:50 +01:00
function build_part_list(&$users,$accounts,$owner)
2001-02-18 23:33:10 +01:00
{
global $phpgw;
if($accounts == False)
{
return;
}
while(list($index,$id) = each($accounts))
2001-02-18 23:33:10 +01:00
{
if(intval($id) == $owner)
2001-02-18 23:33:10 +01:00
{
continue;
}
if(!isset($users[intval($id)]))
{
$users[intval($id)] = $phpgw->common->grab_owner_name(intval($id));
if($phpgw->accounts->get_type(intval($id)) == 'g')
2001-02-18 23:33:10 +01:00
{
build_part_list($users,$phpgw->acl->get_ids_for_location(intval($id),1,'phpgw_group'),$owner);
2001-02-18 23:33:10 +01:00
}
}
}
}
// Participants
$accounts = $phpgw->acl->get_ids_for_location('run',1,'calendar');
$users = Array();
build_part_list($users,$accounts,$owner);
// unset($users[$owner]);
echo "Owner = ".$users[$owner]."<br>\n";
while(list($key,$status) = each($event->participants))
2001-02-18 23:33:10 +01:00
{
$parts[$key] = ' selected';
2001-02-18 23:33:10 +01:00
}
$str = "\n".' <select name="participants[]" multiple size="5">'."\n";
2001-02-18 23:33:10 +01:00
@asort($users);
@reset($users);
2001-03-16 02:54:22 +01:00
$user = Array();
while (list($id,$name) = each($users))
2001-02-18 23:33:10 +01:00
{
if(intval($id) == intval($owner))
2001-02-18 23:33:10 +01:00
{
continue;
}
elseif($phpgw->accounts->exists($id) == True)
{
$str .= ' <option value="' . $id . '"'.$parts[$id].'>('.$phpgw->accounts->get_type($id).') '.$name.'</option>'."\n";
2001-02-18 23:33:10 +01:00
}
}
$str .= ' </select>';
2001-05-15 06:13:20 +02:00
display_item($p,lang('Participants'),$str);
2000-11-23 02:37:50 +01:00
// I Participate
$str = '<input type="checkbox" name="participants[]" value="'.$owner.'"';
if((($id > 0) && isset($event->participants[$owner])) || !isset($id))
2001-02-18 23:33:10 +01:00
{
$str .= ' checked';
}
$str .= '>';
2001-05-15 06:13:20 +02:00
display_item($p,$phpgw->common->grab_owner_name($owner).' '.lang('Participates'),$str);
// Repeat Type
2001-02-18 23:33:10 +01:00
$p->set_var('hr_text','<hr>');
2001-05-15 06:13:20 +02:00
$p->parse('row','hr',True);
2001-02-18 23:33:10 +01:00
$p->set_var('hr_text','<center><b>'.lang('Repeating Event Information').'</b></center><br>');
2001-05-15 06:13:20 +02:00
$p->parse('row','hr',True);
$str = '<select name="recur_type">';
$rpt_type = Array(
MCAL_RECUR_NONE,
MCAL_RECUR_DAILY,
MCAL_RECUR_WEEKLY,
MCAL_RECUR_MONTHLY_WDAY,
MCAL_RECUR_MONTHLY_MDAY,
MCAL_RECUR_YEARLY
2001-02-18 23:33:10 +01:00
);
$rpt_type_out = Array(
MCAL_RECUR_NONE => 'None',
MCAL_RECUR_DAILY => 'Daily',
MCAL_RECUR_WEEKLY => 'Weekly',
MCAL_RECUR_MONTHLY_WDAY => 'Monthly (by day)',
MCAL_RECUR_MONTHLY_MDAY => 'Monthly (by date)',
MCAL_RECUR_YEARLY => 'Yearly'
2001-02-18 23:33:10 +01:00
);
for($l=0;$l<count($rpt_type);$l++)
2001-02-18 23:33:10 +01:00
{
$str .= '<option value="'.$rpt_type[$l].'"';
if($event->recur_type == $rpt_type[$l])
2001-02-18 23:33:10 +01:00
{
$str .= ' selected';
}
$str .= '>'.lang($rpt_type_out[$rpt_type[$l]]).'</option>';
2001-02-18 23:33:10 +01:00
}
$str .= '</select>';
2001-05-15 06:13:20 +02:00
display_item($p,lang('Repeat Type'),$str);
2001-02-18 23:33:10 +01:00
$str = '<input type="checkbox" name="rpt_use_end" value="y"';
if($event->recur_enddate->year != 0 && $event->recur_enddate->month != 0 && $event->recur_enddate->mday != 0)
2001-02-18 23:33:10 +01:00
{
$str .= ' checked';
$recur_end = mktime($event->recur_enddate->hour,$event->recur_enddate->min,$event->recur_enddate->sec,$event->recur_enddate->month,$event->recur_enddate->mday,$event->recur_enddate->year) - $tz_offset;
}
else
{
2001-03-22 19:30:35 +01:00
$recur_end = mktime($event->start->hour,$event->start->min,$event->start->sec,$event->start->month,$event->start->mday,$event->start->year) + 86400 - $tz_offset;
2001-02-18 23:33:10 +01:00
}
$str .= '>'.lang('Use End Date').' ';
$day_html = $sb->getDays('recur_enddate[mday]',intval($phpgw->common->show_date($recur_end,'d')));
$month_html = $sb->getMonthText('recur_enddate[month]',intval($phpgw->common->show_date($recur_end,'n')));
$year_html = $sb->getYears('recur_enddate[year]',intval($phpgw->common->show_date($recur_end,'Y')),intval($phpgw->common->show_date($recur_end,'Y')));
2001-02-18 23:33:10 +01:00
$str .= $phpgw->common->dateformatorder($year_html,$month_html,$day_html);
2001-05-15 06:13:20 +02:00
display_item($p,lang('Repeat End Date'),$str);
2001-02-18 23:33:10 +01:00
$str = '<input type="checkbox" name="cal[rpt_sun]" value="'.MCAL_SUNDAY.'"'.(($event->recur_data & MCAL_SUNDAY) ?' checked':'').'> '.lang('Sunday').' ';
$str .= '<input type="checkbox" name="cal[rpt_mon]" value="'.MCAL_MONDAY.'"'.(($event->recur_data & MCAL_MONDAY) ?' checked':'').'> '.lang('Monday').' ';
$str .= '<input type="checkbox" name="cal[rpt_tue]" value="'.MCAL_TUESDAY.'"'.(($event->recur_data & MCAL_TUESDAY) ?' checked':'').'> '.lang('Tuesday').' ';
$str .= '<input type="checkbox" name="cal[rpt_wed]" value="'.MCAL_WEDNESDAY.'"'.(($event->recur_data & MCAL_WEDNESDAY) ?' checked':'').'> '.lang('Wednesday').' <br>';
$str .= '<input type="checkbox" name="cal[rpt_thu]" value="'.MCAL_THURSDAY.'"'.(($event->recur_data & MCAL_THURSDAY) ?' checked':'').'> '.lang('Thursday').' ';
$str .= '<input type="checkbox" name="cal[rpt_fri]" value="'.MCAL_FRIDAY.'"'.(($event->recur_data & MCAL_FRIDAY) ?' checked':'').'> '.lang('Friday').' ';
$str .= '<input type="checkbox" name="cal[rpt_sat]" value="'.MCAL_SATURDAY.'"'.(($event->recur_data & MCAL_SATURDAY) ?' checked':'').'> '.lang('Saturday').' ';
2001-02-18 23:33:10 +01:00
2001-05-15 06:13:20 +02:00
display_item($p,lang('Repeat Day').'<br>'.lang('(for weekly)'),$str);
2001-02-18 23:33:10 +01:00
2001-05-15 06:13:20 +02:00
display_item($p,lang('Frequency'),'<input name="recur_interval" size="4" maxlength="4" value="'.$event->recur_interval.'">');
2001-02-18 23:33:10 +01:00
$p->set_var('submit_button',lang('Submit'));
if ($id > 0)
{
$action_url_button = $phpgw->link('/calendar/delete.php','id='.$id);
$action_text_button = lang('Delete');
$action_confirm_button = "onClick=\"return confirm('".lang("Are you sure\\nyou want to \\ndelete this entry?\\n\\nThis will delete\\nthis entry for all users.")."')\"";
$var = Array(
'action_url_button' => $action_url_button,
'action_text_button' => $action_text_button,
'action_confirm_button' => $action_confirm_button,
'action_extra_field' => ''
);
$p->set_var($var);
2001-02-18 23:33:10 +01:00
$p->parse('delete_button','form_button');
}
else
{
$p->set_var('delete_button','');
}
2001-05-15 06:13:20 +02:00
$p->pparse('out','edit_entry');
2001-02-18 23:33:10 +01:00
$phpgw->common->phpgw_footer();
2000-08-18 05:24:22 +02:00
?>