2003-05-09 17:24:17 +00:00
< ? PHP // $Id$
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' );
require_once ( '../course/lib.php' );
2003-05-09 17:24:17 +00:00
2006-03-06 14:25:26 +00:00
$show = optional_param ( 'show' , '' , PARAM_SAFEDIR );
$hide = optional_param ( 'hide' , '' , PARAM_SAFEDIR );
$delete = optional_param ( 'delete' , '' , PARAM_SAFEDIR );
$confirm = optional_param ( 'confirm' , '' , PARAM_BOOL );
2003-05-09 17:24:17 +00:00
2004-07-08 01:19:32 +00:00
require_login ();
2003-05-09 17:24:17 +00:00
if ( ! isadmin ()) {
error ( " Only administrators can use this page! " );
}
if ( ! $site = get_site ()) {
error ( " Site isn't defined! " );
}
/// Print headings
$stradministration = get_string ( " administration " );
2003-08-18 16:40:27 +00:00
$strconfiguration = get_string ( " configuration " );
2003-05-09 17:24:17 +00:00
$strmanagemodules = get_string ( " managemodules " );
$strdelete = get_string ( " delete " );
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 " );
2003-07-24 12:09:32 +00:00
print_header ( " $site->shortname : $strmanagemodules " , " $site->fullname " ,
2003-08-18 16:40:27 +00:00
" <a href= \" index.php \" > $stradministration </a> -> " .
" <a href= \" configure.php \" > $strconfiguration </a> -> $strmanagemodules " );
2003-05-09 17:24:17 +00:00
print_heading ( $strmanagemodules );
2006-05-08 03:56:26 +00:00
$coursesaffected = false ;
2006-04-27 03:31:10 +00:00
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 ()) {
2003-05-09 17:24:17 +00:00
if ( ! $module = get_record ( " modules " , " name " , $hide )) {
error ( " Module doesn't exist! " );
}
2006-04-11 08:30:10 +00:00
set_field ( " modules " , " visible " , " 0 " , " id " , $module -> id ); // Hide main module
set_field ( 'course_modules' , 'visibleold' , '1' , 'visible' , '1' , 'module' , $module -> id ); // Remember the previous visible state so we can toggle this back if the module is unhidden.
set_field ( 'course_modules' , 'visibleold' , '0' , 'visible' , '0' , 'module' , $module -> id );
set_field ( " course_modules " , " visible " , " 0 " , " module " , $module -> id ); // Hide all related activity modules
2006-04-27 03:31:10 +00:00
$coursesaffected = true ;
2003-05-09 17:24:17 +00:00
}
2004-10-03 15:09:31 +00:00
if ( ! empty ( $show ) and confirm_sesskey ()) {
2003-05-09 17:24:17 +00:00
if ( ! $module = get_record ( " modules " , " name " , $show )) {
error ( " Module doesn't exist! " );
}
2006-04-11 08:30:10 +00:00
set_field ( " modules " , " visible " , " 1 " , " id " , $module -> id ); // Show main module
set_field ( 'course_modules' , 'visible' , '1' , 'visibleold' , '1' , 'module' , $module -> id ); // Get the previous saved visible state for the course module.
2006-04-27 03:31:10 +00:00
$coursesaffected = true ;
2003-05-09 17:24:17 +00:00
}
2004-10-03 15:09:31 +00:00
if ( ! empty ( $delete ) and confirm_sesskey ()) {
2003-05-09 17:24:17 +00:00
$strmodulename = get_string ( " modulename " , " $delete " );
2006-03-06 14:25:26 +00:00
if ( ! $confirm ) {
2003-05-09 17:24:17 +00:00
notice_yesno ( get_string ( " moduledeleteconfirm " , " " , $strmodulename ),
2006-03-06 14:25:26 +00:00
" modules.php?delete= $delete &confirm=1&sesskey= $USER->sesskey " ,
2003-05-09 17:24:17 +00:00
" modules.php " );
print_footer ();
exit ;
} else { // Delete everything!!
if ( $delete == " forum " ) {
error ( " You can not delete the forum module!! " );
}
if ( ! $module = get_record ( " modules " , " name " , $delete )) {
error ( " Module doesn't exist! " );
}
// OK, first delete all the relevant instances from all course sections
if ( $coursemods = get_records ( " course_modules " , " module " , $module -> id )) {
foreach ( $coursemods as $coursemod ) {
if ( ! delete_mod_from_section ( $coursemod -> id , $coursemod -> section )) {
notify ( " Could not delete the $strmodulename with id = $coursemod->id from section $coursemod->section " );
}
}
}
// Now delete all the course module records
if ( ! delete_records ( " course_modules " , " module " , $module -> id )) {
notify ( " Error occurred while deleting all $strmodulename records in course_modules table " );
}
// Then delete all the logs
if ( ! delete_records ( " log " , " module " , $module -> name )) {
notify ( " Error occurred while deleting all $strmodulename records in log table " );
}
// And log_display information
if ( ! delete_records ( " log_display " , " module " , $module -> name )) {
notify ( " Error occurred while deleting all $strmodulename records in log_display table " );
}
// And the module entry itself
if ( ! delete_records ( " modules " , " name " , $module -> name )) {
notify ( " Error occurred while deleting the $strmodulename record from modules table " );
}
// Then the tables themselves
if ( $tables = $db -> Metatables ()) {
$prefix = $CFG -> prefix . $module -> name ;
foreach ( $tables as $table ) {
if ( strpos ( $table , $prefix ) === 0 ) {
if ( ! execute_sql ( " DROP TABLE $table " , false )) {
notify ( " ERROR: while trying to drop table $table " );
}
}
}
}
2006-04-27 03:31:10 +00:00
//rebuild_course_cache(); // Because things have changed
$coursesaffected = true ;
2003-05-09 17:24:17 +00:00
$a -> module = $strmodulename ;
$a -> directory = " $CFG->dirroot /mod/ $delete " ;
notice ( get_string ( " moduledeletefiles " , " " , $a ), " modules.php " );
}
}
2006-04-27 03:31:10 +00:00
if ( $coursesaffected ) {
rebuild_course_cache (); // Because things have changed
}
2003-05-09 17:24:17 +00:00
/// Get and sort the existing modules
if ( ! $modules = get_records ( " modules " )) {
error ( " No modules found!! " ); // Should never happen
}
foreach ( $modules as $module ) {
$strmodulename = get_string ( " modulename " , " $module->name " );
2006-05-17 16:47:44 +00:00
// Deal with modules which are lacking the language string
if ( $strmodulename == '[[modulename]]' ) {
$strmodulename = $module -> name ;
}
2003-05-09 17:24:17 +00:00
$modulebyname [ $strmodulename ] = $module ;
}
ksort ( $modulebyname );
/// Print the table of all modules
2004-03-13 10:40:01 +00:00
$table -> head = array ( $stractivitymodule , $stractivities , $strversion , " $strhide / $strshow " , $strdelete , $strsettings );
2005-02-08 08:14:53 +00:00
$table -> align = array ( " left " , " right " , " left " , " center " , " center " , " center " );
$table -> wrap = array ( " nowrap " , " " , " " , " " , " " , " " );
$table -> size = array ( " 100% " , " 10 " , " 10 " , " 10 " , " 10 " , " 12 " );
2003-05-09 17:24:17 +00:00
$table -> width = " 100 " ;
foreach ( $modulebyname as $modulename => $module ) {
2005-01-25 17:08:05 +00:00
$icon = " <img src= \" $CFG->modpixpath / $module->name /icon.gif \" hspace= \" 10 \" height= \" 16 \" width= \" 16 \" border= \" 0 \" alt= \" \" /> " ;
2003-05-09 17:24:17 +00:00
2005-02-08 08:14:53 +00:00
$delete = " <a href= \" modules.php?delete= $module->name &sesskey= $USER->sesskey\ " > $strdelete </ a > " ;
2003-05-09 17:24:17 +00:00
2003-08-18 17:21:53 +00:00
if ( file_exists ( " $CFG->dirroot /mod/ $module->name /config.html " )) {
2005-01-22 19:53:28 +00:00
$settings = " <a href= \" module.php?module= $module->name\ " > $strsettings </ a > " ;
2003-07-24 12:09:32 +00:00
} else {
$settings = " " ;
}
2004-03-13 10:40:01 +00:00
$count = count_records ( " $module->name " );
2003-05-09 17:24:17 +00:00
if ( $module -> visible ) {
2004-10-03 15:09:31 +00:00
$visible = " <a href= \" modules.php?hide= $module->name &sesskey= $USER->sesskey\ " title = \ " $strhide\ " > " .
2005-01-25 17:08:05 +00:00
" <img src= \" $CFG->pixpath /i/hide.gif \" align= \" middle \" height= \" 16 \" width= \" 16 \" border= \" 0 \" alt= \" \" /></a> " ;
2003-05-09 17:24:17 +00:00
$class = " " ;
} else {
2004-10-03 15:09:31 +00:00
$visible = " <a href= \" modules.php?show= $module->name &sesskey= $USER->sesskey\ " title = \ " $strshow\ " > " .
2005-01-25 17:08:05 +00:00
" <img src= \" $CFG->pixpath /i/show.gif \" align= \" middle \" height= \" 16 \" width= \" 16 \" border= \" 0 \" alt= \" \" /></a> " ;
2003-05-09 17:24:17 +00:00
$class = " class= \" dimmed_text \" " ;
}
if ( $module -> name == " forum " ) {
$delete = " " ;
$visible = " " ;
$class = " " ;
}
2005-02-08 08:14:53 +00:00
$table -> data [] = array ( " <span $class > $icon $modulename </span> " , $count , $module -> version , $visible , $delete , $settings );
2003-05-09 17:24:17 +00:00
}
print_table ( $table );
echo " <br /><br /> " ;
print_footer ();
?>