From Mambo Manual
This is where the other half of the serious work happens (actually it happens first). As for the presentation layer, event handler also builds up as we develop additional functionality. In fact, there are usually many more events handled than there are requirements to display them.
We've already created the code to display the user list and let's build the event handler for this first.
Create a file called admin.mrx_inout.php in the /administrator/components/com_mrx_inout directory. Copy the following code into it and then we'll dissect what's happening.
1: <?php /* $Id $ */
2:
3: /**
4: * In/Out Board Main Handler
5: * @package MOS−ROX
7: * @license http://www.gnu.org/copyleft/gpl.html. GNU Public License
8: * @version 4.5.1
10: */
11:
12: // ensure this file is being included by a parent file
13: defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
14:
15: require_once( $mainframe−>getPath( 'admin_html' ) );
16: require_once( $mainframe−>getPath( 'class' ) );
17:
18: $cid = mosGetParam( $_REQUEST, 'cid', array() );
19:
20: switch ($task) {
48:
49: default:
50: listUsers( $option );
51: break;
52: }
53:
54: /**
55: * List users
56: * @param string The current GET/POST option
57: */
58: function listUsers( $option ) {
59: global $database;
60:
61: $catid = intval( mosGetParam( $_REQUEST, 'catid', 0 ) );
62: $limit = intval( mosGetParam( $_REQUEST, 'limit', 10 ) );
63: $limitstart = intval( mosGetParam( $_REQUEST, 'limitstart', 0 ) );
64:
65: // get the total number of records
66: $database−>setQuery( "SELECT count(*) FROM #__mrx_inout"
67: . ($catid ? "\nWHERE catid='$catid'" : "")
68: );
69: $total = $database−>loadResult();
70: echo $database−>getErrorMsg();
71:72: if ($limit > $total) {
73: $limitstart = 0;
74: }
75:
76: // get the subset (based on limits) of required records
77: $database−>setQuery( "SELECT a.*, u.name, c.name AS catname"
78: . "\nFROM #__mrx_inout AS a"
79: . "\nINNER JOIN #__categories AS c ON c.id = a.catid"
80: . "\nINNER JOIN #__users AS u ON u.id = a.user_id"
81: . ($catid ? "\nWHERE a.catid='$catid'" : "")
82: . "\nORDER BY a.catid, a.ordering"
83: . "\nLIMIT $limitstart,$limit"
84: );
85:
86: $rows = $database−>loadObjectList();
87: if ($database−>getErrorNum()) {
88: echo $database−>stderr();
89: return false;
90: }
91: $lists = array();
92: // get list of categories
93: $categories[] = mosHTML::makeOption( '0', 'Select Category' );
94: $categories[] = mosHTML::makeOption( '0', '− All Categories' );
95: $database−>setQuery( "SELECT id AS value, title AS text FROM#__categories"
96: . "\nWHERE section='$option' ORDER BY ordering" );
97: $categories = array_merge( $categories, $database−>loadObjectList() );
98:
99: $lists['catid'] = mosHTML::selectList( $categories, 'catid',
'class="inputbox" size="1" onchange="document.adminForm.submit();"',
100: 'value', 'text', $catid );
101: unset( $categories );
102:
103: require_once("includes/pageNavigation.php");
104: $pageNav = new mosPageNav( $total, $limitstart, $limit );
105:
106: HTML_mrx_inout::listUsers( $rows, $lists, $pageNav, $option );
107: }
Yikes, that looks complicated at first glance! Well, let's try and make it a bit easier to follow:
Line 13:
Remember this from the toolbar. This is an essential part of MOS's security system. Don't forget to put this in all of your files.