2004-09-12 16:24:41 +00:00
< ? php // $Id$
2003-09-16 03:07:21 +00:00
/// This page lists all the instances of glossary in a particular course
/// Replace glossary with the name of your module
require_once ( " ../../config.php " );
require_once ( " lib.php " );
2005-01-25 06:09:31 +00:00
require_once ( " $CFG->libdir /rsslib.php " );
2008-02-01 09:09:04 +00:00
require_once ( " $CFG->dirroot /course/lib.php " );
2003-09-16 03:07:21 +00:00
2005-12-07 06:21:58 +00:00
$id = required_param ( 'id' , PARAM_INT ); // course
2003-09-16 03:07:21 +00:00
2008-06-01 18:12:24 +00:00
if ( ! $course = $DB -> get_record ( 'course' , array ( 'id' => $id ))) {
2008-06-06 03:15:53 +00:00
print_error ( 'invalidcourseid' );
2003-09-16 03:07:21 +00:00
}
2004-08-22 14:38:47 +00:00
require_course_login ( $course );
2006-08-26 19:19:36 +00:00
$context = get_context_instance ( CONTEXT_COURSE , $course -> id );
2003-09-16 03:07:21 +00:00
add_to_log ( $course -> id , " glossary " , " view all " , " index.php?id= $course->id " , " " );
/// Get all required strings
$strglossarys = get_string ( " modulenameplural " , " glossary " );
$strglossary = get_string ( " modulename " , " glossary " );
2004-08-08 18:44:45 +00:00
$strrss = get_string ( " rss " );
2003-09-16 03:07:21 +00:00
/// Print the header
2007-07-05 04:55:24 +00:00
$navlinks = array ();
2007-07-05 04:40:48 +00:00
$navlinks [] = array ( 'name' => $strglossarys , 'link' => " index.php?id= $course->id " , 'type' => 'activity' );
$navigation = build_navigation ( $navlinks );
2008-01-24 20:33:50 +00:00
2007-04-16 21:16:38 +00:00
print_header_simple ( " $strglossarys " , " " , $navigation , " " , " " , true , " " , navmenu ( $course ));
2003-09-16 03:07:21 +00:00
/// Get all the appropriate data
2008-02-05 21:40:21 +00:00
if ( ! $glossarys = get_all_instances_in_course ( " glossary " , $course )) {
2007-10-29 10:44:50 +00:00
notice ( get_string ( 'thereareno' , 'moodle' , $strglossarys ), " ../../course/view.php?id= $course->id " );
2003-09-16 03:07:21 +00:00
die ;
}
/// Print the list of instances (your module will probably extend this)
$timenow = time ();
$strname = get_string ( " name " );
$strweek = get_string ( " week " );
$strtopic = get_string ( " topic " );
2003-10-26 08:14:54 +00:00
$strentries = get_string ( " entries " , " glossary " );
2003-09-16 03:07:21 +00:00
if ( $course -> format == " weeks " ) {
2003-10-26 08:14:54 +00:00
$table -> head = array ( $strweek , $strname , $strentries );
$table -> align = array ( " CENTER " , " LEFT " , " CENTER " );
2003-09-16 03:07:21 +00:00
} else if ( $course -> format == " topics " ) {
2003-10-26 08:14:54 +00:00
$table -> head = array ( $strtopic , $strname , $strentries );
$table -> align = array ( " CENTER " , " LEFT " , " CENTER " );
2003-09-16 03:07:21 +00:00
} else {
2003-10-26 08:14:54 +00:00
$table -> head = array ( $strname , $strentries );
$table -> align = array ( " LEFT " , " CENTER " );
2003-09-16 03:07:21 +00:00
}
2006-09-22 02:52:48 +00:00
if ( $show_rss = ( isset ( $CFG -> enablerssfeeds ) && isset ( $CFG -> glossary_enablerssfeeds ) &&
2004-08-08 18:44:45 +00:00
$CFG -> enablerssfeeds && $CFG -> glossary_enablerssfeeds )) {
$table -> head [] = $strrss ;
$table -> align [] = " CENTER " ;
}
2004-01-26 12:21:44 +00:00
$currentsection = " " ;
2008-02-05 21:40:21 +00:00
foreach ( $glossarys as $glossary ) {
if ( ! $glossary -> visible && has_capability ( 'moodle/course:viewhiddenactivities' , $context )) {
// Show dimmed if the mod is hidden.
$link = " <a class= \" dimmed \" href= \" view.php?id= $glossary->coursemodule\ " > " .format_string( $glossary->name ,true). " </ a > " ;
} else if ( $glossary -> visible ) {
// Show normal if the mod is visible.
$link = " <a href= \" view.php?id= $glossary->coursemodule\ " > " .format_string( $glossary->name ,true). " </ a > " ;
} else {
// Don't show the glossary.
2006-09-22 02:52:48 +00:00
continue ;
2003-09-28 10:57:22 +00:00
}
2004-01-26 12:21:44 +00:00
$printsection = " " ;
2008-02-05 21:40:21 +00:00
if ( $glossary -> section !== $currentsection ) {
if ( $glossary -> section ) {
$printsection = $glossary -> section ;
2004-01-26 12:21:44 +00:00
}
if ( $currentsection !== " " ) {
$table -> data [] = 'hr' ;
}
2008-02-05 21:40:21 +00:00
$currentsection = $glossary -> section ;
2004-01-26 12:21:44 +00:00
}
2003-09-16 03:07:21 +00:00
2008-01-24 20:33:50 +00:00
// TODO: count only approved if not allowed to see them
2008-06-08 10:43:39 +00:00
$count = $DB -> count_records_sql ( " SELECT COUNT(*) FROM { glossary_entries} WHERE (glossaryid = ? OR sourceglossaryid = ?) " , array ( $glossary -> id , $glossary -> id ));
2003-10-26 08:14:54 +00:00
2004-08-08 18:44:45 +00:00
//If this glossary has RSS activated, calculate it
if ( $show_rss ) {
$rsslink = '' ;
2008-02-05 21:40:21 +00:00
if ( $glossary -> rsstype and $glossary -> rssarticles ) {
2004-08-08 18:44:45 +00:00
//Calculate the tolltip text
2008-02-05 21:40:21 +00:00
$tooltiptext = get_string ( " rsssubscriberss " , " glossary " , format_string ( $glossary -> name ));
2004-10-05 23:21:38 +00:00
if ( empty ( $USER -> id )) {
$userid = 0 ;
} else {
$userid = $USER -> id ;
}
2004-08-08 18:44:45 +00:00
//Get html code for RSS link
2008-02-05 21:40:21 +00:00
$rsslink = rss_get_link ( $course -> id , $userid , " glossary " , $glossary -> id , $tooltiptext );
2004-08-08 18:44:45 +00:00
}
}
2003-09-16 03:07:21 +00:00
if ( $course -> format == " weeks " or $course -> format == " topics " ) {
2004-08-08 18:44:45 +00:00
$linedata = array ( $printsection , $link , $count );
2003-09-16 03:07:21 +00:00
} else {
2004-08-08 18:44:45 +00:00
$linedata = array ( $link , $count );
}
if ( $show_rss ) {
$linedata [] = $rsslink ;
2003-09-16 03:07:21 +00:00
}
2004-08-08 18:44:45 +00:00
$table -> data [] = $linedata ;
2003-09-16 03:07:21 +00:00
}
2003-10-26 08:14:54 +00:00
echo " <br /> " ;
2003-09-16 03:07:21 +00:00
print_table ( $table );
/// Finish the page
print_footer ( $course );
2007-10-29 10:44:50 +00:00
?>