2001-09-07 18:34:49 +02:00
< ? php
/************************************************************************** \
2004-01-27 01:31:58 +01:00
* eGroupWare - Calendar *
* http :// www . egroupware . org *
2001-09-07 18:34:49 +02:00
* 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' );
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
2003-09-14 14:51:31 +02:00
if ( ! is_object ( $GLOBALS [ 'phpgw' ] -> html ))
{
$GLOBALS [ 'phpgw' ] -> html = CreateObject ( 'phpgwapi.html' );
}
$this -> html = & $GLOBALS [ 'phpgw' ] -> html ;
2001-09-07 18:34:49 +02:00
}
function prep_page ()
{
2003-09-11 14:01:16 +02:00
if ( $this -> bo -> cal_id <= 0 ||
2004-01-04 01:47:37 +01:00
! $this -> event = $this -> bo -> read_entry ( $this -> bo -> cal_id ))
2001-09-07 18:34:49 +02:00
{
2003-08-28 16:31:11 +02:00
$GLOBALS [ 'phpgw' ] -> redirect_link ( '/index.php' , Array (
2003-09-11 14:01:16 +02:00
'menuaction' => 'calendar.uicalendar.index'
2003-08-28 16:31:11 +02:00
));
2001-09-07 18:34:49 +02:00
}
2003-09-11 14:01:16 +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-09-14 14:51:31 +02:00
if ( $_POST [ 'cancel' ])
{
$GLOBALS [ 'phpgw' ] -> redirect_link ( '/index.php' , 'menuaction=' . ( $_POST [ 'return_to' ] ? $_POST [ 'return_to' ] : 'calendar.uicalendar.index' ));
}
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' ])
{
2004-01-04 01:47:37 +01:00
$time = ( int )( $_POST [ 'time' ][ 'days' ]) * 24 * 3600 +
( int )( $_POST [ 'time' ][ 'hours' ]) * 3600 +
( int )( $_POST [ 'time' ][ 'mins' ]) * 60 ;
2003-08-28 16:31:11 +02:00
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' ],
'lang_select' => lang ( 'Select' ),
'lang_time' => lang ( 'Time' ),
'lang_text' => lang ( 'Text' ),
'lang_owner' => lang ( 'Owner' ),
'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 (
2004-02-22 21:23:52 +01:00
'field' => $GLOBALS [ 'phpgw' ] -> common -> show_date ( $alarm [ 'time' ]),
2003-08-28 16:31:11 +02:00
//'data' => $alarm['text'],
2003-09-11 14:01:16 +02:00
'data' => lang ( 'Email Notification' ),
2003-08-28 16:31:11 +02:00
'owner' => $GLOBALS [ 'phpgw' ] -> common -> grab_owner_name ( $alarm [ 'owner' ]),
2003-09-14 14:51:31 +02:00
'enabled' => $this -> html -> image ( 'calendar' , $alarm [ 'enabled' ] ? 'enabled' : 'disabled' , $alarm [ 'enabled' ] ? 'enabled' : 'disabled' , 'width="13" height="13"' ),
'select' => $this -> html -> checkbox ( " 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
}
2004-01-04 01:47:37 +01:00
if ( isset ( $this -> event [ 'participants' ][( int ) $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ]]))
2003-08-28 16:31:11 +02:00
{
$this -> template -> set_var ( Array (
'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 ),
2003-09-11 14:01:16 +02:00
'input_add' => $this -> html -> submit_button ( 'add' , 'Add Alarm' ),
2003-08-28 16:31:11 +02:00
));
}
2003-09-11 14:01:16 +02:00
$this -> template -> set_var ( Array (
'action_url' => $GLOBALS [ 'phpgw' ] -> link ( '/index.php' , Array ( 'menuaction' => 'calendar.uialarm.manager' )),
2003-09-14 14:51:31 +02:00
'hidden_vars' => $this -> html -> input_hidden ( array (
'cal_id' => $this -> bo -> cal_id ,
'return_to' => $_POST [ 'return_to' ]
)),
2003-09-11 14:01:16 +02:00
'lang_enable' => lang ( 'Enable' ),
2003-09-14 14:51:31 +02:00
'lang_disable' => lang ( 'Disable' ),
'input_cancel' => $this -> html -> submit_button ( 'cancel' , 'Cancel' )
2003-09-11 14:01:16 +02:00
));
2003-08-28 16:31:11 +02:00
//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
?>