GetDb(); $userid = get_userid(); $access = check_permission($userid, "Modify Events"); function display_error( $text ) { echo "

$text

\n"; } check_login(); include_once("header.php"); $downImg = $themeObject->DisplayImage('icons/system/arrow-d.gif', lang('down'),'','','systemicon'); $upImg = $themeObject->DisplayImage('icons/system/arrow-u.gif', lang('up'),'','','systemicon'); $deleteImg = $themeObject->DisplayImage('icons/system/delete.gif', lang('delete'),'','','systemicon'); 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 = $_POST['module']; } if( isset( $_POST['event'] ) && $_POST['event'] != '' ) { $event = $_POST['event']; } if( isset( $_POST['handler'] ) ) { // handler is set, we just have to try to set it $handler = $_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 = $_GET['action']; } if( isset( $_GET['module'] ) && $_GET['module'] != '' ) { $module = $_GET['module']; } if( isset( $_GET['event'] ) && $_GET['event'] != '' ) { $event = $_GET['event']; } if( isset( $_GET['handler'] ) && $_GET['handler'] != '' ) { $handler = $_GET['handler']; } if( isset( $_GET['order'] ) && $_GET['order'] != '' ) { $cur_order = $_GET['order']; } switch( $action ) { case 'up': // move an item up (decrease the order) // increases the previous order, and decreases the current handler id if( $handler == "" || $module == "" || $event == "" || $action == "" || ($cur_order == "" && $action != "delete") ) { display_error( lang("missingparams" ) ); } // Get the event id $q = "SELECT event_id FROM ".cms_db_prefix().'event_handlers WHERE handler_id = ?'; $event_id = $db->GetOne($q,array($handler)); // Get the previous handler id $q = 'SELECT handler_id FROM '.cms_db_prefix().'event_handlers WHERE handler_order = ? AND event_id = ?'; $prev_id = $db->GetOne($q,array($cur_order -1,$event_id)); if( $prev_id ) { $q = "UPDATE ".cms_db_prefix()."event_handlers SET handler_order = (handler_order - 1) where handler_id = ?"; $db->Execute( $q, array( $handler ) ); $q = "UPDATE ".cms_db_prefix()."event_handlers SET handler_order = (handler_order + 1) where handler_id = ?"; $db->Execute( $q, array( $prev_id ) ); } 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 == "" || $module == "" || $event == "" || $action == "" || ($cur_order == "" && $action != "delete") ) { display_error( lang("missingparams" ) ); } // Get the event id $q = "SELECT event_id FROM ".cms_db_prefix().'event_handlers WHERE handler_id = ?'; $event_id = $db->GetOne($q,array($handler)); // Get the next handler id $q = 'SELECT handler_id FROM '.cms_db_prefix().'event_handlers WHERE handler_order = ? AND event_id = ?'; $next_id = $db->GetOne($q,array($cur_order + 1,$event_id)); if( $next_id ) { $q = "UPDATE ".cms_db_prefix()."event_handlers SET handler_order = (handler_order + 1) where handler_id = ?"; $db->Execute( $q, array( $handler ) ); $q = "UPDATE ".cms_db_prefix()."event_handlers SET handler_order = (handler_order - 1) where handler_id = ?"; $db->Execute( $q, array( $next_id ) ); } break; case 'delete': { if( $handler == "" || $module == "" || $event == "" || $action == "" || ($cur_order == "" && $action != "delete") ) { display_error( lang("missingparams" ) ); } // get the details about the handler $q = "SELECT * FROM ".cms_db_prefix()."event_handlers WHERE handler_id = ?"; $dbresult = $db->Execute( $q, array( $handler ) ); if( $dbresult && $dbresult->RecordCount() ) { $row = $dbresult->FetchRow(); $event_id = $row['event_id']; // delete a handler $q = "DELETE FROM ".cms_db_prefix()."event_handlers WHERE handler_id = ?"; $dbresult = $db->Execute( $q, array( $handler ) ); // re-order the events $q = "UPDATE ".cms_db_prefix()."event_handlers SET handler_order = (handler_order - 1) WHERE handler_order > ? AND event_id = ?"; $dbresult = $db->Execute( $q, array( $cur_order, $event_id ) ); } } break; default: // unknown or unset action break; } // switch } // 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 " \n"; echo " \n"; echo " \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 " \n"; echo " \n"; echo " \n"; if( $idx != 0 ) { echo " \n"; } else { echo ""; } if( $idx + 1 != count($handlers) ) { echo " \n"; } else { echo ""; } if( $onehandler['removable'] == 1 ) { echo " \n"; } else { echo " \n"; } echo "\n"; $idx++; } } else{ echo "\n"; echo "\n"; echo ""; echo "\n"; } echo "\n"; echo "
".lang('order')."".lang('user_tag')."".lang('module')."   
".$onehandler['handler_order']."".$onehandler['tag_name']."".$onehandler['module_name']."$upImg $downImg $deleteImg 
 
\n"; echo "
\n"; echo "
\n"; echo ''."\n"; echo ''."\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "
\n"; echo "

BackUrl()."\">« ".lang('back')."

\n"; echo "
\n"; } else { display_error(lang('noaccessto', array(lang('editeventhandler')))); } include_once("footer.php"); ?>