Source for file admin.modules.php
Documentation is available at admin.modules.php
* @copyright Refer to copyright.php
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @author Mambo Foundation Inc see README.php
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
// ensure user has access to this function
if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'modules', 'all' ) |
$acl->acl_check( 'administration', 'install', 'users', $my->usertype, 'modules', 'all' ))) {
mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') );
require_once( $mainframe->getPath( 'admin_html' ) );
$moduleid =
mosGetParam( $_REQUEST, 'moduleid', null );
if ($cid[0] ==
0 && isset
($moduleid) ) {
orderModule( $cid[0], ($task ==
'orderup' ? -
1 :
1), $option, $client );
* Compiles a list of installed or defined modules
global $database, $my, $mainframe, $mosConfig_list_limit, $mosConfig_absolute_path;
$filter_position =
$mainframe->getUserStateFromRequest( "filter_position{$option}{$client}", 'filter_position', 0 );
$filter_type =
$mainframe->getUserStateFromRequest( "filter_type{$option}{$client}", 'filter_type', 0 );
$limit =
$mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit );
$limitstart =
$mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 );
$search =
$mainframe->getUserStateFromRequest( "search{$option}{$client}", 'search', '' );
if ($client ==
'admin') {
$where[] =
"m.client_id = '1'";
$where[] =
"m.client_id = '0'";
if ( $filter_position ) {
$where[] =
"m.position = '$filter_position'";
$where[] =
"m.module = '$filter_type'";
$where[] =
"LOWER( m.title ) LIKE '%$search%'";
// get the total number of records
$query =
"SELECT COUNT(*) FROM #__modules AS m ".
( count( $where ) ?
"\n WHERE " .
implode( ' AND ', $where ) :
'' );
$database->setQuery( $query );
$total =
$database->loadResult();
require_once( $mosConfig_absolute_path .
'/administrator/includes/pageNavigation.php' );
$pageNav =
new mosPageNav( $total, $limitstart, $limit );
$database->setQuery( "SELECT m.*, u.name AS editor, g.name AS groupname, MIN(mm.menuid) AS pages"
.
"\n FROM #__modules AS m"
.
"\n LEFT JOIN #__users AS u ON u.id = m.checked_out"
.
"\n LEFT JOIN #__groups AS g ON g.id = m.access"
.
"\n LEFT JOIN #__modules_menu AS mm ON mm.moduleid=m.id"
.
( count( $where ) ?
"\n WHERE " .
implode( ' AND ', $where ) :
'' )
.
"\n ORDER BY position ASC, ordering ASC"
.
"\n LIMIT $pageNav->limitstart,$pageNav->limit"
$rows =
$database->loadObjectList();
if ($database->getErrorNum()) {
echo
$database->stderr();
// get list of Positions for dropdown filter
$query =
"SELECT t.position AS value, t.position AS text"
.
"\n FROM #__template_positions as t"
.
"\n LEFT JOIN #__modules AS m ON m.position = t.position"
.
"\n WHERE m.client_id = '$client_id'"
.
"\n GROUP BY t.position"
.
"\n ORDER BY t.position"
$database->setQuery( $query );
$positions =
array_merge( $positions, $database->loadObjectList() );
$lists['position'] =
mosHTML::selectList( $positions, 'filter_position', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', "$filter_position" );
// get list of Positions for dropdown filter
$query =
"SELECT module AS value, module AS text"
.
"\n WHERE client_id = '$client_id'"
$database->setQuery( $query );
$types =
array_merge( $types, $database->loadObjectList() );
$lists['type'] =
mosHTML::selectList( $types, 'filter_type', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', "$filter_type" );
HTML_modules::showModules( $rows, $my->id, $client, $pageNav, $option, $lists, $search );
* Compiles information to add or edit a module
* @param string The current GET/POST option
* @param integer The unique id of the record to edit
// load the row from the db table
$row->title =
'Copy of '.
$row->title;
echo
"<script> alert('".
$row->getError().
"'); window.history.go(-1); </script>\n";
echo
"<script> alert('".
$row->getError().
"'); window.history.go(-1); </script>\n";
if ($client ==
'admin') {
$where =
"client_id='1'";
$where =
"client_id='0'";
$row->updateOrder( "position='$row->position' AND ($where)" );
$database->setQuery( "SELECT menuid FROM #__modules_menu WHERE moduleid='$uid'" );
$rows =
$database->loadResultArray();
foreach($rows as $menuid) {
$database->setQuery( "INSERT INTO #__modules_menu"
.
"\nSET moduleid='$row->id', menuid='$menuid'"
$msg =
sprintf(T_('Module Copied [%s]'), $row->title);
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client, $msg );
* Saves the module after an edit form submit
foreach ($params as $k=>
$v) {
if (!$row->bind( $_POST, 'selections' )) {
echo
"<script> alert('".
$row->getError().
"'); window.history.go(-1); </script>\n";
$row->groups =
implode(',',$row->groups);
echo
"<script> alert('".
$row->getError().
"'); window.history.go(-1); </script>\n";
echo
"<script> alert('".
$row->getError().
"'); window.history.go(-1); </script>\n";
if ($client ==
'admin') {
$where =
"client_id='1'";
$where =
"client_id='0'";
$row->updateOrder( "position='$row->position' AND ($where)" );
$database->setQuery( "DELETE FROM #__modules_menu WHERE moduleid='$row->id'" );
foreach ($menus as $menuid){
// this check for the blank spaces in the select box that have been added for cosmetic reasons
if ( $menuid <>
"-999" &&
$menuid <>
"-998") {
$query =
"INSERT INTO #__modules_menu SET moduleid='$row->id', menuid='$menuid'";
$database->setQuery( $query );
$msg =
sprintf(T_('Successfully Saved changes to Module: %s'), $row->title) ;
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client .
'&task=editA&hidemainmenu=1&id='.
$row->id, $msg );
$msg =
sprintf(T_('Successfully Saved Module: %s'), $row->title);
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client, $msg );
* Compiles information to add or edit a module
* @param string The current GET/POST option
* @param integer The unique id of the record to edit
global $database, $my, $mainframe;
global $mosConfig_absolute_path;
// load the row from the db table
// fail if checked out not by 'me'
if ( $row->checked_out &&
$row->checked_out <>
$my->id ) {
echo
"<script>alert('".
sprintf(T_('The module %s is currently being edited by another administrator'), $row->title).
"'); document.location.href='index2.php?option=$option'</script>\n";
$row->checkout( $my->id );
// if a new record we must still prime the mosModule object with a default
// position and the order; also add an extra item to the order list to
// place the 'new' record in last position if desired
if ( $client ==
'admin' ) {
$where =
"client_id='1'";
$where =
"client_id='0'";
$query =
"SELECT position, ordering, showtitle, title"
$database->setQuery( $query );
if ( !($orders =
$database->loadObjectList()) ) {
echo
$database->stderr();
$query =
"SELECT position, description"
.
"\n FROM #__template_positions"
.
"\n WHERE position <> ''"
$database->setQuery( $query );
// hard code options for now
$positions =
$database->loadObjectList();
foreach ($positions as $position) {
$orders2[$position->position] =
array();
for ($i=
0, $n=
count( $orders ); $i <
$n; $i++
) {
// build the html select list
$pos_select =
'onchange="changeDynaList(\'ordering\',orders,document.adminForm.position.options[document.adminForm.position.selectedIndex].value, originalPos, originalOrder)"';
$active =
( $row->position ?
$row->position :
'left' );
$lists['position'] =
mosHTML::selectList( $pos, 'position', 'class="inputbox" size="1" '.
$pos_select, 'value', 'text', $active );
// get selected pages for $lists['selections']
$query =
'SELECT menuid AS value FROM #__modules_menu WHERE moduleid='.
$row->id;
$database->setQuery( $query );
$lookup =
$database->loadObjectList();
if ( $row->access ==
99 ||
$row->client_id ==
1 ||
$lists['client_id'] ) {
$lists['access'] =
T_('Administrator').
'<input type="hidden" name="access" value="99" />';
$lists['showtitle'] =
T_('N/A').
' <input type="hidden" name="showtitle" value="1" />';
$lists['selections'] =
T_('N/A');
if ( $client ==
'admin' ) {
$lists['access'] =
T_('N/A');
$lists['selections'] =
T_('N/A');
// build the html select list for published
$xmlfile =
$mainframe->getPath( $path, $row->module );
$row->description =
$xmlparser->getDescription('module');
// get params definitions
HTML_modules::editModule( $row, $orders2, $lists, $params, $option, $client );
* Deletes one or more modules
* Also deletes associated entries in the #__module_menu table.
* @param array An array of unique category id numbers
echo
"<script> alert('".
T_('Select a module to delete').
"'); window.history.go(-1);</script>\n";
$database->setQuery( "SELECT id, module, title, iscore, params FROM #__modules WHERE id IN ($cids)" );
if (!($rows =
$database->loadObjectList())) {
echo
"<script> alert('".
$database->getErrorMsg().
"'); window.history.go(-1); </script>\n";
foreach ($rows as $row) {
if ($row->module ==
'' ||
$row->iscore ==
0) {
// mod_mainmenu modules only deletable via Menu Manager
if ( $row->module ==
'mod_mainmenu' ) {
if ( strstr( $row->params, 'منوی اصلی' ) ) {
echo
"<script> alert('".
T_('You cannot delete mod_mainmenu module that displays the "mainmenu" as it is a core Menu').
"'); window.history.go(-1); </script>\n";
$database->setQuery( "DELETE FROM #__modules WHERE id IN ($cids)" );
if (!$database->query()) {
echo
"<script> alert('".
$database->getErrorMsg().
"'); window.history.go(-1); </script>\n";
$database->setQuery( "DELETE from #__modules_menu WHERE moduleid IN ($cids)" );
if (!$database->query()) {
echo
"<script> alert('".
$database->getErrorMsg().
"');</script>\n";
$mod->updateOrder( "position='left'" );
$mod->updateOrder( "position='right'" );
echo
"<script>alert('".
sprintf(T_('Module(s): "%s" cannot be deleted they can only be un-installed as they are Mambo modules.'), $cids).
"');</script>\n";
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client );
* Publishes or Unpublishes one or more modules
* @param array An array of unique record id numbers
* @param integer 0 if unpublishing, 1 if publishing
function publishModule( $cid=
null, $publish=
1, $option, $client ) {
$action =
$publish ?
T_('publish' ):
T_('unpublish');
echo
"<script> alert('".
sprintf(T_('Select a module to %s'), $action).
"'); window.history.go(-1);</script>\n";
$query =
"UPDATE #__modules SET published='$publish'"
.
"\n WHERE id IN ($cids)"
.
"\n AND (checked_out=0 OR (checked_out='$my->id'))"
$database->setQuery( $query );
if (!$database->query()) {
echo
"<script> alert('".
$database->getErrorMsg().
"'); window.history.go(-1); </script>\n";
if (count( $cid ) ==
1) {
$row->checkin( $cid[0] );
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client );
* Cancels an edit operation
$row->bind( $_POST, 'selections params' );
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client );
* Moves the order of a record
* @param integer The unique id of record
* @param integer The increment to reorder by
if ($client ==
'admin') {
$where =
"client_id='1'";
$where =
"client_id='0'";
$row->move( $inc, "position='$row->position' AND ($where)" );
$client =
'&client=admin' ;
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client );
* changes the access level of a record
* @param integer The increment to reorder by
function accessMenu( $uid, $access, $option, $client ) {
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client );
// update ordering values
foreach ($cid as $i=>
$ciditem) {
if ($row->ordering !=
$order[$i]) {
$row->ordering =
$order[$i];
echo
"<script> alert('".
$database->getErrorMsg().
"'); window.history.go(-1); </script>\n";
// remember to updateOrder this group
$positions[$row->position][$row->client_id] =
$row->id;
// execute updateOrder for each group
foreach ($positions as $position=>
$clients) {
foreach ($clients as $client=>
$rowid) {
$row->updateOrder("position = '$position' AND client_id = '$client'");
$msg =
T_('New ordering saved');
mosRedirect( 'index2.php?option=com_modules&client='.
$client, $msg );
Documentation generated on Mon, 05 May 2008 16:15:45 +0400 by phpDocumentor 1.4.0