GetDb();
$userid = get_userid();
$access = check_permission($userid, "Modify Events");
function display_error( $text )
{
echo "
\n";
echo "
\n";
echo $themeObject->ShowHeader('editeventhandler');
echo "
\n";
if ($access) {
$action = "";
$module = "";
$event = "";
$handler = "";
if( isset( $_POST['add'] ) ) {
// we're adding some funky event handler
if( isset( $_POST['module'] ) && $_POST['module'] != '' ) $module = trim(cleanValue($_POST['module']));
if( isset( $_POST['event'] ) && $_POST['event'] != '' ) $event = trim(cleanValue($_POST['event']));
if( isset( $_POST['handler'] ) ) $handler = trim(cleanValue($_POST['handler']));
if( $module && $event && $handler ) {
if( substr( $handler, 0, 2 ) == "m:" ) {
$handler = substr( $handler, 2 );
Events::AddEventHandler( $module, $event, false, $handler );
}
else {
Events::AddEventHandler( $module, $event, $handler );
}
}
}
else {
$cur_order = -1;
// we're processing an up/down or delete
if( isset( $_GET['action'] ) && $_GET['action'] != '' ) $action = trim(cleanValue($_GET['action']));
if( isset( $_GET['module'] ) && $_GET['module'] != '' ) $module = trim(cleanValue($_GET['module']));
if( isset( $_GET['event'] ) && $_GET['event'] != '' ) $event = trim(cleanValue($_GET['event']));
if( isset( $_GET['handler'] ) && $_GET['handler'] != '' ) $handler = (int)$_GET['handler'];
if( isset( $_GET['order'] ) && $_GET['order'] != '' ) $cur_order = (int)$_GET['order'];
if( $module == "" || $event == "" || $action == "" ) {
display_error( lang("missingparams" ) );
return;
}
switch( $action ) {
case 'up':
// move an item up (decrease the order)
// increases the previous order, and decreases the current handler id
if( !$handler || $cur_order < 1 ) {
display_error( lang("missingparams" ) );
return;
}
Events::OrderHandlerUp( $handler );
break;
case 'down':
// move an item down (increase the order)
// move an item up (decrease the order)
// increases the previous order, and decreases the current handler id
if( !$handler || $cur_order < 1 ) {
display_error( lang("missingparams" ) );
return;
}
Events::OrderHandlerDown( $handler );
break;
case 'delete':
if( !$handler ) {
display_error( lang("missingparams" ) );
return;
}
Events::RemoveEventHandlerById( $handler );
break;
default:
// unknown or unset action
break;
} // switch
} // else
// get the event description
$usertagops = $gCms->GetUserTagOperations();
$description = '';
$modulename = '';
if ($module == 'Core') {
$description = Events::GetEventDescription($event);
$modulename = lang('core');
}
else {
$objinstance = cms_utils::get_module($module);
$description = $objinstance->GetEventDescription($event);
$modulename = $objinstance->GetFriendlyName();
}
// and now get the list of handlers for this event
$handlers = Events::ListEventHandlers( $module, $event );
// and the list of all available handlers
$allhandlers = array();
// we get the list of user tags, and add them to the list
$usertags = $usertagops->ListUserTags();
foreach( $usertags as $key => $value ) {
$allhandlers[$value] = $value;
}
// and the list of modules, and add them
$allmodules = ModuleOperations::get_instance()->GetInstalledModules();
foreach( $allmodules as $key ) {
if( $key == $modulename ) continue;
$modobj = ModuleOperations::get_instance()->get_module_instance($key);
if( $modobj && $modobj->HandlesEvents() ) {
$allhandlers[$key] = 'm:'.$key;
}
}
echo "
\n";
echo "
".lang("module_name").":
\n";
echo "
".$modulename."
\n";
echo "
\n";
echo "
\n";
echo "
".lang("event_name").":
\n";
echo "
".$event."
\n";
echo "
\n";
echo "
\n";
echo "
".lang("event_description").":
\n";
echo "
".$description."
\n";
echo "
\n";
echo "
\n";
echo "\n";
echo " \n";
echo " ".lang('order')." | \n";
echo " ".lang('user_tag')." | \n";
echo " ".lang('module')." | \n";
echo " | \n";
echo " | \n";
echo " | \n";
echo "
\n";
echo "\n";
$rowclass = "row1";
if( $handlers != false ) {
echo "\n";
$idx = 0;
$url = "editevent.php".$urlext."&module=".$module."&event=".$event;
foreach( $handlers as $onehandler ) {
echo "\n";
echo " ".$onehandler['handler_order']." | \n";
echo " ".$onehandler['tag_name']." | \n";
echo " ".$onehandler['module_name']." | \n";
if( $idx != 0 ) {
echo " $upImg | \n";
}
else {
echo " | ";
}
if( $idx + 1 != count($handlers) ) {
echo " $downImg | \n";
}
else {
echo " | ";
}
if( $onehandler['removable'] == 1 ) {
echo " $deleteImg | \n";
}
else {
echo " | \n";
}
echo "
\n";
$idx++;
}
}
else{
echo "\n";
echo "\n";
echo " | ";
echo "
\n";
}
echo "\n";
echo "
\n";
echo "
\n";
echo "
\n";
}
else {
display_error(lang('noaccessto', array(lang('editeventhandler'))));
}
include_once("footer.php");