2009-11-01 10:57:00 +00:00
< ? php
2006-02-17 17:28:47 +00:00
// Allows the admin to manage activity modules
2003-05-09 17:24:17 +00:00
2006-03-06 14:25:26 +00:00
require_once ( '../config.php' );
2007-02-21 17:09:58 +00:00
require_once ( '../course/lib.php' );
2006-09-02 13:14:57 +00:00
require_once ( $CFG -> libdir . '/adminlib.php' );
2007-02-21 17:09:58 +00:00
require_once ( $CFG -> libdir . '/tablelib.php' );
// defines
define ( 'MODULE_TABLE' , 'module_administration_table' );
2007-04-30 17:08:34 +00:00
admin_externalpage_setup ( 'managemodules' );
2003-05-09 17:24:17 +00:00
2011-09-24 15:07:27 +02:00
$show = optional_param ( 'show' , '' , PARAM_PLUGIN );
$hide = optional_param ( 'hide' , '' , PARAM_PLUGIN );
2003-05-09 17:24:17 +00:00
/// Print headings
2006-09-03 14:45:57 +00:00
$stractivities = get_string ( " activities " );
2013-06-26 13:56:24 +02:00
$struninstall = get_string ( 'uninstallplugin' , 'core_admin' );
2003-11-03 03:22:52 +00:00
$strversion = get_string ( " version " );
2003-05-09 17:24:17 +00:00
$strhide = get_string ( " hide " );
$strshow = get_string ( " show " );
2003-07-24 12:09:32 +00:00
$strsettings = get_string ( " settings " );
2004-03-13 10:40:01 +00:00
$stractivities = get_string ( " activities " );
2003-05-09 17:24:17 +00:00
$stractivitymodule = get_string ( " activitymodule " );
2007-02-21 11:42:48 +00:00
$strshowmodulecourse = get_string ( 'showmodulecourse' );
2003-05-09 17:24:17 +00:00
/// If data submitted, then process and store.
2004-10-03 15:09:31 +00:00
if ( ! empty ( $hide ) and confirm_sesskey ()) {
2008-05-31 10:43:51 +00:00
if ( ! $module = $DB -> get_record ( " modules " , array ( " name " => $hide ))) {
2008-04-10 02:56:25 +00:00
print_error ( 'moduledoesnotexist' , 'error' );
2003-05-09 17:24:17 +00:00
}
2008-05-31 10:43:51 +00:00
$DB -> set_field ( " modules " , " visible " , " 0 " , array ( " id " => $module -> id )); // Hide main module
2007-09-12 02:56:50 +00:00
// Remember the visibility status in visibleold
// and hide...
2008-05-31 10:43:51 +00:00
$sql = " UPDATE { course_modules}
SET visibleold = visible , visible = 0
WHERE module = ? " ;
$DB -> execute ( $sql , array ( $module -> id ));
2013-07-25 21:53:50 +10:00
// Increment course.cacherev for courses where we just made something invisible.
// This will force cache rebuilding on the next request.
increment_revision_number ( 'course' , 'cacherev' ,
" id IN (SELECT DISTINCT course
2008-05-31 10:43:51 +00:00
FROM { course_modules }
2013-07-25 21:53:50 +10:00
WHERE visibleold = 1 AND module = ? ) " ,
array ( $module -> id ));
2013-10-04 22:40:44 +02:00
core_plugin_manager :: reset_caches ();
2007-12-19 17:35:20 +00:00
admin_get_root ( true , false ); // settings not required - only pages
2003-05-09 17:24:17 +00:00
}
2004-10-03 15:09:31 +00:00
if ( ! empty ( $show ) and confirm_sesskey ()) {
2008-05-31 10:43:51 +00:00
if ( ! $module = $DB -> get_record ( " modules " , array ( " name " => $show ))) {
2008-04-10 02:56:25 +00:00
print_error ( 'moduledoesnotexist' , 'error' );
2003-05-09 17:24:17 +00:00
}
2008-05-31 10:43:51 +00:00
$DB -> set_field ( " modules " , " visible " , " 1 " , array ( " id " => $module -> id )); // Show main module
2008-11-17 07:55:10 +00:00
$DB -> set_field ( 'course_modules' , 'visible' , '1' , array ( 'visibleold' => 1 , 'module' => $module -> id )); // Get the previous saved visible state for the course module.
2013-07-25 21:53:50 +10:00
// Increment course.cacherev for courses where we just made something visible.
// This will force cache rebuilding on the next request.
increment_revision_number ( 'course' , 'cacherev' ,
" id IN (SELECT DISTINCT course
2008-05-31 10:43:51 +00:00
FROM { course_modules }
2013-07-25 21:53:50 +10:00
WHERE visible = 1 AND module = ? ) " ,
array ( $module -> id ));
2013-10-04 22:40:44 +02:00
core_plugin_manager :: reset_caches ();
2007-12-19 17:35:20 +00:00
admin_get_root ( true , false ); // settings not required - only pages
2003-05-09 17:24:17 +00:00
}
2010-03-31 08:05:53 +00:00
echo $OUTPUT -> header ();
2009-08-06 08:17:12 +00:00
echo $OUTPUT -> heading ( $stractivities );
2007-12-19 17:35:20 +00:00
2003-05-09 17:24:17 +00:00
/// Get and sort the existing modules
2010-04-11 12:17:43 +00:00
if ( ! $modules = $DB -> get_records ( 'modules' , array (), 'name ASC' )) {
2008-04-10 02:56:25 +00:00
print_error ( 'moduledoesnotexist' , 'error' );
2003-05-09 17:24:17 +00:00
}
/// Print the table of all modules
2007-02-21 17:09:58 +00:00
// construct the flexible table ready to display
$table = new flexible_table ( MODULE_TABLE );
2013-06-26 13:56:24 +02:00
$table -> define_columns ( array ( 'name' , 'instances' , 'version' , 'hideshow' , 'uninstall' , 'settings' ));
2013-10-04 22:40:44 +02:00
$table -> define_headers ( array ( $stractivitymodule , $stractivities , $strversion , " $strhide / $strshow " , $strsettings , $struninstall ));
2007-02-21 17:27:26 +00:00
$table -> define_baseurl ( $CFG -> wwwroot . '/' . $CFG -> admin . '/modules.php' );
$table -> set_attribute ( 'id' , 'modules' );
2013-10-04 22:40:44 +02:00
$table -> set_attribute ( 'class' , 'admintable generaltable' );
2007-02-21 17:09:58 +00:00
$table -> setup ();
2003-05-09 17:24:17 +00:00
2010-04-11 12:17:43 +00:00
foreach ( $modules as $module ) {
2003-05-09 17:24:17 +00:00
2010-04-11 12:17:43 +00:00
if ( ! file_exists ( " $CFG->dirroot /mod/ $module->name /lib.php " )) {
$strmodulename = '<span class="notifyproblem">' . $module -> name . ' (' . get_string ( 'missingfromdisk' ) . ')</span>' ;
$missing = true ;
} else {
// took out hspace="\10\", because it does not validate. don't know what to replace with.
2017-01-19 16:20:27 +08:00
$icon = " <img src= \" " . $OUTPUT -> image_url ( 'icon' , $module -> name ) . " \" class= \" icon \" alt= \" \" /> " ;
2010-04-11 12:17:43 +00:00
$strmodulename = $icon . ' ' . get_string ( 'modulename' , $module -> name );
$missing = false ;
}
2003-05-09 17:24:17 +00:00
2013-06-26 13:56:24 +02:00
$uninstall = '' ;
2013-10-04 22:40:44 +02:00
if ( $uninstallurl = core_plugin_manager :: instance () -> get_uninstall_url ( 'mod_' . $module -> name , 'manage' )) {
2013-06-26 13:56:24 +02:00
$uninstall = html_writer :: link ( $uninstallurl , $struninstall );
2013-06-26 13:30:24 +02:00
}
2003-05-09 17:24:17 +00:00
2008-09-09 08:30:54 +00:00
if ( file_exists ( " $CFG->dirroot /mod/ $module->name /settings.php " ) ||
file_exists ( " $CFG->dirroot /mod/ $module->name /settingstree.php " )) {
2007-12-19 17:35:20 +00:00
$settings = " <a href= \" settings.php?section=modsetting $module->name\ " > $strsettings </ a > " ;
2003-07-24 12:09:32 +00:00
} else {
$settings = " " ;
}
2011-01-30 13:02:42 +01:00
try {
$count = $DB -> count_records_select ( $module -> name , " course<>0 " );
} catch ( dml_exception $e ) {
$count = - 1 ;
}
2007-02-21 11:42:48 +00:00
if ( $count > 0 ) {
$countlink = " <a href= \" { $CFG -> wwwroot } /course/search.php?modulelist= $module->name " .
2009-01-02 10:43:12 +00:00
" &sesskey= " . sesskey () . " \" title= \" $strshowmodulecourse\ " > $count </ a > " ;
2011-01-30 13:02:42 +01:00
} else if ( $count < 0 ) {
$countlink = get_string ( 'error' );
} else {
2007-02-21 11:42:48 +00:00
$countlink = " $count " ;
}
2004-03-13 10:40:01 +00:00
2010-04-11 12:17:43 +00:00
if ( $missing ) {
$visible = '' ;
$class = '' ;
} else if ( $module -> visible ) {
2009-01-02 10:51:26 +00:00
$visible = " <a href= \" modules.php?hide= $module->name &sesskey= " . sesskey () . " \" title= \" $strhide\ " > " .
2017-01-19 16:20:27 +08:00
$OUTPUT -> pix_icon ( 't/hide' , $strhide ) . '</a>' ;
2010-04-11 12:17:43 +00:00
$class = '' ;
2003-05-09 17:24:17 +00:00
} else {
2009-01-02 10:51:26 +00:00
$visible = " <a href= \" modules.php?show= $module->name &sesskey= " . sesskey () . " \" title= \" $strshow\ " > " .
2017-01-19 16:20:27 +08:00
$OUTPUT -> pix_icon ( 't/show' , $strshow ) . '</a>' ;
2013-10-04 22:40:44 +02:00
$class = 'dimmed_text' ;
2003-05-09 17:24:17 +00:00
}
if ( $module -> name == " forum " ) {
2013-06-26 13:56:24 +02:00
$uninstall = " " ;
2003-05-09 17:24:17 +00:00
$visible = " " ;
$class = " " ;
}
2013-09-14 23:57:21 +02:00
$version = get_config ( 'mod_' . $module -> name , 'version' );
2008-04-30 13:07:58 +00:00
2007-02-21 17:09:58 +00:00
$table -> add_data ( array (
2013-10-04 22:40:44 +02:00
$strmodulename ,
2007-12-19 17:35:20 +00:00
$countlink ,
2013-10-04 22:40:44 +02:00
$version ,
2007-12-19 17:35:20 +00:00
$visible ,
2013-10-04 22:40:44 +02:00
$settings ,
2013-06-26 13:56:24 +02:00
$uninstall ,
2013-10-04 22:40:44 +02:00
), $class );
2003-05-09 17:24:17 +00:00
}
2007-02-21 17:09:58 +00:00
$table -> print_html ();
2003-05-09 17:24:17 +00:00
2009-08-06 14:12:46 +00:00
echo $OUTPUT -> footer ();
2003-05-09 17:24:17 +00:00
2009-11-01 10:57:00 +00:00