Joomla模块学习之后台mod

    技术2022-05-20  55

    Joomla模块学习之后台mod_logged模块

    在线用户模块

    后台管理模块效果图

     

     

     

    原理:

    后台mod_logged模块通过在后台配置相应的信息. 返回在线用户列表

     

     

    配置界面:

     

     

     

     

    mod_feed模块结构图:

     

     

     

    关键代码

    (mod_logged.php代码) jimport('joomla.html.pagination'); $db =& JFactory::getDBO(); $user =& JFactory::getUser(); // TODO - pagination needs to be completed in module $limit = $mainframe->getUserStateFromRequest('limit', 'limit', $mainframe->getCfg('list_limit'), 'int'); $limitstart = $mainframe->getUserStateFromRequest('mod_logged.limitstart', 'limitstart', 0, 'int'); // hides Administrator or Super Administrator from list depending on usertype // 根据用户类型隐藏管理员和超级管理员 $and = ''; // administrator check // 如果用户属于管理员组,隐藏超级管理员组用户在线信息 if ( $user->get('gid') == 24 ) { $and = ' AND gid != "25"'; } // manager check // 如果用户属于经理组,隐藏管理员组和超级管理员组用户在线信息 if ( $user->get('gid') == 23 ) { $and = ' AND gid != "25"'; $and .= ' AND gid != "24"'; } // get the total number of records $query = 'SELECT COUNT(*)' . ' FROM #__session' . ' WHERE userid != 0' . $and . ' ORDER BY usertype, username' ; $db->setQuery( $query ); $total = $db->loadResult(); // page navigation $pageNav = new JPagination( $total, $limitstart, $limit ); $query = 'SELECT username, time, userid, usertype, client_id' . ' FROM #__session' . ' WHERE userid != 0' . $and . ' ORDER BY usertype, username' ; $db->setQuery( $query ); $rows = $db->loadObjectList(); require( dirname( __FILE__ ).DS.'tmpl'.DS.'default.php' );

    (mod_logged default.php代码) <?php $i = 0; $now = time(); foreach ($rows as $row) : $auth = $user->authorize( 'com_users', 'manage' ); if ($auth) : $link = 'index.php?option=com_users&task=edit&cid[]='. $row->userid; $name = '<a href="'. $link .'" mce_href="'. $link .'" title="'. JText::_( 'Edit User' ) .'">'. $row->username .'</a>'; else : $name = $row->username; endif; //判断用户登录位置(前台or后台) $clientInfo =& JApplicationHelper::getClientInfo($row->client_id); ?> <tr> <td width="5%"> <?php echo $pageNav->getRowOffset( $i ); ?> </td> <td> <?php echo $name;?> </td> <td> <?php echo $row->usertype;?> </td> <td> <?php echo $clientInfo->name;?> </td> <td> <?php echo JText::sprintf( 'activity hours', ($now - $row->time)/3600.0 );?> </td> <td> <?php if ($auth && $user->get('gid') > 24 && $row->userid != $user->get('id')) : ?> <input type="image" src="images/publish_x.png" mce_src="images/publish_x.png" οnclick="f=this.form; f.task.value='flogout'; f.client.value=<?php echo (int) $row->client_id; ?>; f.cid_value.value=<?php echo (int) $row->userid ?>" /> <?php endif; ?> </td> </tr> <?php $i++; endforeach; ?>

     


    最新回复(0)