2001-09-07 18:34:49 +02:00
< ? 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$ */
class uialarm
{
var $template ;
var $template_dir ;
var $bo ;
2001-10-26 01:54:21 +02:00
var $event ;
2001-09-07 18:34:49 +02:00
var $debug = False ;
// var $debug = True;
var $tz_offset ;
var $theme ;
var $public_functions = array (
'manager' => True
);
function uialarm ()
{
$GLOBALS [ 'phpgw' ] -> nextmatchs = CreateObject ( 'phpgwapi.nextmatchs' );
$GLOBALS [ 'phpgw' ] -> browser = CreateObject ( 'phpgwapi.browser' );
$this -> theme = $GLOBALS [ 'phpgw_info' ][ 'theme' ];
$this -> bo = CreateObject ( 'calendar.boalarm' );
$this -> tz_offset = $this -> bo -> tz_offset ;
if ( $this -> debug )
{
echo " BO Owner : " . $this -> bo -> owner . " <br> \n " ;
}
$this -> template_dir = $GLOBALS [ 'phpgw' ] -> common -> get_tpl_dir ( 'calendar' );
2003-08-28 16:31:11 +02:00
$this -> html = CreateObject ( 'calendar.html' );
2001-09-07 18:34:49 +02:00
}
function prep_page ()
{
2001-12-28 16:53:33 +01:00
$this -> event = $this -> bo -> read_entry ( $this -> bo -> cal_id );
2003-08-28 16:31:11 +02:00
/*
$can_edit = $this -> bo -> bo -> check_perms ( PHPGW_ACL_EDIT , $this -> event );
2002-11-23 15:19:56 +01:00
2001-09-07 18:34:49 +02:00
if ( ! $can_edit )
{
2003-08-28 16:31:11 +02:00
$GLOBALS [ 'phpgw' ] -> redirect_link ( '/index.php' , Array (
'menuaction' => 'calendar.uicalendar.view' ,
'cal_id' => $this -> bo -> cal_id
));
2001-09-07 18:34:49 +02:00
}
2003-08-28 16:31:11 +02:00
*/
2003-04-21 13:00:53 +02:00
unset ( $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'noheader' ]);
unset ( $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'nonavbar' ]);
$GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'app_header' ] = $GLOBALS [ 'phpgw_info' ][ 'apps' ][ 'calendar' ][ 'title' ] . ' - ' . lang ( 'Alarm Management' );
$GLOBALS [ 'phpgw' ] -> common -> phpgw_header ();
2001-10-26 01:54:21 +02:00
$this -> template = CreateObject ( 'phpgwapi.Template' , $this -> template_dir );
2003-08-28 16:31:11 +02:00
$this -> template -> set_unknowns ( 'remove' );
2001-10-26 01:54:21 +02:00
$this -> template -> set_file (
Array (
2003-04-21 13:00:53 +02:00
'alarm' => 'alarm.tpl'
)
2001-10-26 01:54:21 +02:00
);
$this -> template -> set_block ( 'alarm' , 'alarm_management' , 'alarm_management' );
$this -> template -> set_block ( 'alarm' , 'alarm_headers' , 'alarm_headers' );
$this -> template -> set_block ( 'alarm' , 'list' , 'list' );
$this -> template -> set_block ( 'alarm' , 'hr' , 'hr' );
2003-08-28 16:31:11 +02:00
$this -> template -> set_block ( 'alarm' , 'buttons' , 'buttons' );
2001-10-26 01:54:21 +02:00
}
function output_template_array ( $row , $list , $var )
{
2003-08-28 16:31:11 +02:00
if ( ! isset ( $var [ 'tr_color' ]))
{
$var [ 'tr_color' ] = $GLOBALS [ 'phpgw' ] -> nextmatchs -> alternate_row_color ();
}
2001-10-26 01:54:21 +02:00
$this -> template -> set_var ( $var );
$this -> template -> parse ( $row , $list , True );
2001-09-07 18:34:49 +02:00
}
/* Public functions */
function manager ()
{
2003-08-28 16:31:11 +02:00
if ( $_POST [ 'delete' ] && count ( $_POST [ 'alarm' ]))
{
if ( $this -> bo -> delete ( $_POST [ 'alarm' ]) < 0 )
{
echo '<center>' . lang ( 'You do not have permission to delete this alarm !!!' ) . '</center>' ;
$GLOBALS [ 'phpgw' ] -> common -> phpgw_exit ( True );
}
}
if (( $_POST [ 'enable' ] || $_POST [ 'disable' ]) && count ( $_POST [ 'alarm' ]))
{
if ( $this -> bo -> enable ( $_POST [ 'alarm' ], $_POST [ 'enable' ]) < 0 )
{
echo '<center>' . lang ( 'You do not have permission to enable/disable this alarm !!!' ) . '</center>' ;
$GLOBALS [ 'phpgw' ] -> common -> phpgw_exit ( True );
}
}
2001-09-07 18:34:49 +02:00
$this -> prep_page ();
2003-08-28 16:31:11 +02:00
if ( $_POST [ 'add' ])
{
$time = intval ( $_POST [ 'time' ][ 'days' ]) * 24 * 3600 +
intval ( $_POST [ 'time' ][ 'hours' ]) * 3600 +
intval ( $_POST [ 'time' ][ 'mins' ]) * 60 ;
if ( $time > 0 && ! $this -> bo -> add ( $this -> event , $time , $_POST [ 'owner' ]))
{
echo '<center>' . lang ( 'You do not have permission to add alarms to this event !!!' ) . '</center>' ;
$GLOBALS [ 'phpgw' ] -> common -> phpgw_exit ( True );
}
}
if ( ! ExecMethod ( 'calendar.uicalendar.view_event' , $this -> event ))
{
echo '<center>' . lang ( 'You do not have permission to read this record!' ) . '</center>' ;
$GLOBALS [ 'phpgw' ] -> common -> phpgw_exit ( True );
}
2003-04-21 13:00:53 +02:00
echo " <br> \n " ;
2003-08-28 16:31:11 +02:00
$GLOBALS [ 'phpgw' ] -> template -> set_var ( 'th_bg' , $this -> theme [ 'th_bg' ]);
$GLOBALS [ 'phpgw' ] -> template -> set_var ( 'hr_text' , lang ( 'Alarms' ) . ':' );
2003-04-21 13:00:53 +02:00
$GLOBALS [ 'phpgw' ] -> template -> fp ( 'row' , 'hr' , True );
2003-08-28 16:31:11 +02:00
$GLOBALS [ 'phpgw' ] -> template -> pfp ( 'phpgw_body' , 'view_event' );
2001-10-26 01:54:21 +02:00
$var = Array (
2003-08-28 16:31:11 +02:00
'tr_color' => $this -> theme [ 'th_bg' ],
'action_url' => $GLOBALS [ 'phpgw' ] -> link ( '/index.php' , Array ( 'menuaction' => 'calendar.uialarm.manager' )),
'hidden_vars' => $this -> html -> input_hidden ( 'cal_id' , $this -> bo -> cal_id ),
'lang_select' => lang ( 'Select' ),
'lang_time' => lang ( 'Time' ),
'lang_text' => lang ( 'Text' ),
'lang_owner' => lang ( 'Owner' ),
'lang_enabled' => lang ( 'enabled' ),
'lang_disabled' => lang ( 'disabled' ),
'lang_enabled' => lang ( 'enabled' ),
'lang_disabled' => lang ( 'disabled' )
2001-10-26 01:54:21 +02:00
);
2001-11-04 05:08:57 +01:00
if ( $this -> event [ 'alarm' ])
2001-10-26 01:54:21 +02:00
{
2003-08-28 16:31:11 +02:00
$this -> output_template_array ( 'rows' , 'alarm_headers' , $var );
foreach ( $this -> event [ 'alarm' ] as $key => $alarm )
2001-11-04 05:08:57 +01:00
{
2003-08-28 16:31:11 +02:00
if ( ! $this -> bo -> check_perms ( PHPGW_ACL_READALARM , $alarm [ 'owner' ]))
{
continue ;
}
2001-11-04 05:08:57 +01:00
$var = Array (
2003-08-28 16:31:11 +02:00
'field' => $GLOBALS [ 'phpgw' ] -> common -> show_date ( $alarm [ 'time' ]),
//'data' => $alarm['text'],
'data' => 'Email Notification' ,
'owner' => $GLOBALS [ 'phpgw' ] -> common -> grab_owner_name ( $alarm [ 'owner' ]),
'enabled' => ( $alarm [ 'enabled' ] ? '<img src="' . $GLOBALS [ 'phpgw' ] -> common -> image ( 'calendar' , 'enabled.gif' ) . '" width="13" height="13" title="' . lang ( 'enabled' ) . '">' :
'<img src="' . $GLOBALS [ 'phpgw' ] -> common -> image ( 'calendar' , 'disabled.gif' ) . '" width="13" height="13" title="' . lang ( 'disabled' ) . '">' ),
'select' => '<input type="checkbox" name="alarm[' . $alarm [ 'id' ] . ']">'
2001-11-04 05:08:57 +01:00
);
2003-08-28 16:31:11 +02:00
if ( $this -> bo -> check_perms ( PHPGW_ACL_DELETEALARM , $alarm [ 'owner' ]))
{
++ $to_delete ;
}
$this -> output_template_array ( 'rows' , 'list' , $var );
2001-11-04 05:08:57 +01:00
}
2003-08-28 16:31:11 +02:00
$this -> template -> set_var ( 'enable_button' , $this -> html -> submit_button ( 'enable' , 'Enable' ));
$this -> template -> set_var ( 'disable_button' , $this -> html -> submit_button ( 'disable' , 'Disable' ));
if ( $to_delete )
{
$this -> template -> set_var ( 'delete_button' , $this -> html -> submit_button ( 'delete' , 'Delete' , " return confirm(' " . lang ( " Are you sure \\ nyou want to \\ ndelete these alarms? " ) . " ') " ));
}
$this -> template -> parse ( 'rows' , 'buttons' , True );
2001-10-26 01:54:21 +02:00
}
2003-08-28 16:31:11 +02:00
if ( isset ( $this -> event [ 'participants' ][ intval ( $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ])]))
{
$this -> template -> set_var ( Array (
'input_text' => lang ( 'Email reminder' ),
'input_days' => $this -> html -> select ( 'time[days]' , $_POST [ 'time' ][ 'days' ], range ( 0 , 31 ), True ) . ' ' . lang ( 'days' ),
'input_hours' => $this -> html -> select ( 'time[hours]' , $_POST [ 'time' ][ 'hours' ], range ( 0 , 24 ), True ) . ' ' . lang ( 'hours' ),
'input_minutes' => $this -> html -> select ( 'time[mins]' , $_POST [ 'time' ][ 'mins' ], range ( 0 , 60 ), True ) . ' ' . lang ( 'minutes' ) . ' ' . lang ( 'before the event' ),
'input_owner' => $this -> html -> select ( 'owner' , $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ], $this -> bo -> participants ( $this -> event , True ), True ),
'input_add' => $this -> html -> submit_button ( 'add' , 'Add Alarm' )
));
}
//echo "<p>alarm_management='".htmlspecialchars($this->template->get_var('alarm_management'))."'</p>\n";
$this -> template -> pfp ( 'out' , 'alarm_management' );
2001-09-07 18:34:49 +02:00
}
}
2003-08-28 16:31:11 +02:00
?>