<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#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.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id: listtags.php 2772 2006-05-17 02:25:27Z wishy $
$CMS_ADMIN_PAGE=1;
require_once("../include.php");
$userid = get_userid();
$access = check_permission($userid, "Modify Modules");
function display_error( $text )
{
echo "<div class=\"pageerrorcontainer\"><p class=\"pageerror\">$text</p></div>\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 "<div class=\"pagecontainer\">\n";
echo "<div class=\"pageoverflow\">\n";
echo $themeObject->ShowHeader('editeventhandler');
echo "</div>\n";
$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" ) );
}
$q = "SELECT handler_id FROM ".cms_db_prefix()."event_handlers WHERE handler_order = ?";
$dbresult = $db->Execute( $q, array($cur_order - 1) );
$row = $dbresult->FetchRow();
$prev_id = -1;
if( isset( $row['handler_id'] ) )
{
$prev_id = $row['handler_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" ) );
}
$q = "SELECT handler_id FROM ".cms_db_prefix()."event_handlers WHERE handler_order = ?";
$dbresult = $db->Execute( $q, array($cur_order + 1) );
$row = $dbresult->FetchRow();
$next_id = -1;
if( isset( $row['handler_id'] ) )
{
$next_id = $row['handler_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
global $gCms;
//$description = $gCms->modules[$module]['object']->GetEventDescription($event);
$description = '';
$modulename = '';
if ($module == 'Core') {
$description = Events::GetEventDescription($event);
$modulename = lang('core');
}
else if (isset($gCms->modules[$module])) {
$objinstance =& $gCms->modules[$module]['object'];
$description = $objinstance->GetEventDescription($event);
$modulename = $objinstance->GetFriendlyName();
}
// and now get the list of handlers for this event
$handlers = Events::ListEventHandlers( $module, $event );
//print_r( $handlers ); echo "<br/><br/>";
// and the list of all available handlers
$allhandlers = array();
// we get the list of user tags, and add them to the list
$usertags = UserTags::ListUserTags();
foreach( $usertags as $key => $value )
{
$allhandlers[$value] = $key;
}
// and the list of modules, and add them
foreach( $gCms->modules as $key => $value )
{
if( $key == $modulename )
{
continue;
}
if( $gCms->modules[$key]['object']->HandlesEvents() )
{
$allhandlers[$key] = 'm:'.$key;
}
}
echo "<div class=\"pageoverflow\">\n";
echo "<p class=\"pagetext\">".lang("module_name").":</p>\n";
echo "<p class=\"pageinput\">".$modulename.":</p>\n";
echo "</div>\n";
echo "<div class=\"pageoverflow\">\n";
echo "<p class=\"pagetext\">".lang("event_name").":</p>\n";
echo "<p class=\"pageinput\">".$event.":</p>\n";
echo "</div>\n";
echo "<div class=\"pageoverflow\">\n";
echo "<p class=\"pagetext\">".lang("event_description").":</p>\n";
echo "<p class=\"pageinput\">".$description.":</p>\n";
echo "</div>\n";
echo "<br/><table cellspacing=\"0\" class=\"pagetable\">\n";
echo "<thead>\n";
echo " <tr>\n";
echo " <th>".lang('order')."</th>\n";
echo " <th>".lang('user_tag')."</th>\n";
echo " <th>".lang('module')."</th>\n";
echo " <th class=\"pageicon\"> </th>\n";
echo " <th class=\"pageicon\"> </th>\n";
echo " <th class=\"pageicon\"> </th>\n";
echo " </tr>\n";
echo "</thead>\n";
$rowclass = "row1";
if( $handlers != false )
{
echo "<tbody>\n";
$idx = 0;
$url = "editevent.php?module=".$module."&event=".$event;
foreach( $handlers as $onehandler )
{
echo "<tr class=\"$rowclass\">\n";
echo " <td>".$onehandler['handler_order']."</td>\n";
echo " <td>".$onehandler['tag_name']."</td>\n";
echo " <td>".$onehandler['module_name']."</td>\n";
if( $idx != 0 )
{
echo " <td><a href=\"".$url."&action=up&order=".$onehandler['handler_order']."&handler=".$onehandler['handler_id']."\">$upImg</a></td>\n";
}
else
{
echo "<td> </td>";
}
if( $idx + 1 != count($handlers) )
{
echo " <td><a href=\"".$url."&action=down&order=".$onehandler['handler_order']."&handler=".$onehandler['handler_id']."\">$downImg</a></td>\n";
}
else
{
echo "<td> </td>";
}
if( $onehandler['removable'] == 1 )
{
echo " <td><a href=\"".$url."&action=delete&order=".$onehandler['handler_order']."&handler=".$onehandler['handler_id']."\">$deleteImg</a></td>\n";
}
else
{
echo " <td> </td>\n";
}
echo "</tr>\n";
$idx++;
}
echo "</tbody>\n";
}
echo "</table>\n";
echo "<br/><form action=\"editevent.php?action=create\" method=\"post\">\n";
echo "<select name=\"handler\">\n";
foreach( $allhandlers as $key => $value )
{
echo "<option value=\"$value\">$key</option>\n";
}
echo "</select>\n";
echo "<input type=\"hidden\" name=\"module\" value=\"$module\">\n";
echo "<input type=\"hidden\" name=\"event\" value=\"$event\">\n";
echo "<input type=\"submit\" name=\"add\" value=\"".lang('add')."\">";
echo "</form>\n";
echo "<p class=\"pageback\"><a class=\"pageback\" href=\"".$themeObject->BackUrl()."\">« ".lang('back')."</a></p>\n";
echo "</div>\n";
include_once("footer.php");
?>