2009-09-25 05:24:13 +00:00
< ? php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Library of useful functions
*
* @ copyright 1999 Martin Dougiamas http :// dougiamas . com
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
* @ package core
* @ subpackage course
2009-09-25 05:24:13 +00:00
*/
2001-11-22 06:23:56 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
defined ( 'MOODLE_INTERNAL' ) || die ;
2008-07-28 12:31:29 +00:00
require_once ( $CFG -> libdir . '/completionlib.php' );
2009-11-04 06:14:06 +00:00
require_once ( $CFG -> libdir . '/filelib.php' );
2001-11-22 06:23:56 +00:00
2006-05-15 05:01:00 +00:00
define ( 'COURSE_MAX_LOGS_PER_PAGE' , 1000 ); // records
define ( 'COURSE_MAX_RECENT_PERIOD' , 172800 ); // Two days, in seconds
define ( 'COURSE_MAX_SUMMARIES_PER_PAGE' , 10 ); // courses
2006-01-16 03:15:48 +00:00
define ( 'COURSE_MAX_COURSES_PER_DROPDOWN' , 1000 ); // max courses in log dropdown before switching to optional
2006-05-15 05:01:00 +00:00
define ( 'COURSE_MAX_USERS_PER_DROPDOWN' , 1000 ); // max users in log dropdown before switching to optional
2007-12-19 17:35:20 +00:00
define ( 'FRONTPAGENEWS' , '0' );
define ( 'FRONTPAGECOURSELIST' , '1' );
define ( 'FRONTPAGECATEGORYNAMES' , '2' );
define ( 'FRONTPAGETOPICONLY' , '3' );
define ( 'FRONTPAGECATEGORYCOMBO' , '4' );
2006-07-19 12:10:07 +00:00
define ( 'FRONTPAGECOURSELIMIT' , 200 ); // maximum number of courses displayed on the frontpage
define ( 'EXCELROWS' , 65535 );
define ( 'FIRSTUSEDEXCELROW' , 3 );
2004-11-23 00:16:24 +00:00
2007-01-02 09:33:07 +00:00
define ( 'MOD_CLASS_ACTIVITY' , 0 );
define ( 'MOD_CLASS_RESOURCE' , 1 );
2002-05-31 09:34:50 +00:00
function make_log_url ( $module , $url ) {
switch ( $module ) {
2006-05-01 06:04:22 +00:00
case 'course' :
case 'file' :
case 'login' :
case 'lib' :
case 'admin' :
case 'calendar' :
2007-08-06 18:19:15 +00:00
case 'mnet course' :
2009-01-07 23:00:59 +00:00
if ( strpos ( $url , '../' ) === 0 ) {
$url = ltrim ( $url , '.' );
} else {
$url = " /course/ $url " ;
}
2007-08-06 18:19:15 +00:00
break ;
2008-03-19 22:48:13 +00:00
case 'user' :
2006-05-01 06:04:22 +00:00
case 'blog' :
2009-01-07 23:00:59 +00:00
$url = " / $module / $url " ;
2002-05-31 09:34:50 +00:00
break ;
2006-05-01 06:04:22 +00:00
case 'upload' :
2009-01-07 23:00:59 +00:00
$url = $url ;
2004-09-17 00:10:53 +00:00
break ;
2008-06-30 09:04:07 +00:00
case 'coursetags' :
2009-01-07 23:00:59 +00:00
$url = '/' . $url ;
2008-06-30 09:04:07 +00:00
break ;
2006-05-01 06:04:22 +00:00
case 'library' :
case '' :
2009-01-07 23:00:59 +00:00
$url = '/' ;
2004-08-17 14:26:47 +00:00
break ;
2008-01-09 10:12:31 +00:00
case 'message' :
2009-01-07 23:00:59 +00:00
$url = " /message/ $url " ;
break ;
case 'notes' :
$url = " /notes/ $url " ;
2008-01-09 10:12:31 +00:00
break ;
2009-09-09 02:43:43 +00:00
case 'tag' :
$url = " /tag/ $url " ;
break ;
2009-09-09 12:45:45 +00:00
case 'role' :
$url = '/' . $url ;
break ;
2002-05-31 09:34:50 +00:00
default :
2009-01-07 23:00:59 +00:00
$url = " /mod/ $module / $url " ;
2002-05-31 09:34:50 +00:00
break ;
}
2009-01-07 23:00:59 +00:00
//now let's sanitise urls - there might be some ugly nasties:-(
$parts = explode ( '?' , $url );
$script = array_shift ( $parts );
if ( strpos ( $script , 'http' ) === 0 ) {
$script = clean_param ( $script , PARAM_URL );
} else {
$script = clean_param ( $script , PARAM_PATH );
}
$query = '' ;
if ( $parts ) {
$query = implode ( '' , $parts );
$query = str_replace ( '&' , '&' , $query ); // both & and & are stored in db :-|
$parts = explode ( '&' , $query );
$eq = urlencode ( '=' );
foreach ( $parts as $key => $part ) {
$part = urlencode ( urldecode ( $part ));
$part = str_replace ( $eq , '=' , $part );
$parts [ $key ] = $part ;
}
$query = '?' . implode ( '&' , $parts );
}
return $script . $query ;
2002-05-31 09:34:50 +00:00
}
2006-05-15 05:01:00 +00:00
2007-01-04 03:22:51 +00:00
function build_mnet_logs_array ( $hostid , $course , $user = 0 , $date = 0 , $order = " l.time ASC " , $limitfrom = '' , $limitnum = '' ,
$modname = " " , $modid = 0 , $modaction = " " , $groupid = 0 ) {
2008-06-01 19:05:07 +00:00
global $CFG , $DB ;
2007-01-04 03:22:51 +00:00
// It is assumed that $date is the GMT time of midnight for that day,
// and so the next 86400 seconds worth of logs are printed.
/// Setup for group handling.
2008-06-04 06:38:03 +00:00
// TODO: I don't understand group/context/etc. enough to be able to do
2007-01-04 03:22:51 +00:00
// something interesting with it here
// What is the context of a remote course?
2008-06-04 06:38:03 +00:00
2007-01-04 03:22:51 +00:00
/// If the group mode is separate, and this user does not have editing privileges,
/// then only the user's group can be viewed.
//if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
// $groupid = get_current_group($course->id);
//}
/// If this course doesn't have groups, no groupid can be specified.
//else if (!$course->groupmode) {
// $groupid = 0;
//}
2008-06-01 19:05:07 +00:00
2007-01-04 03:22:51 +00:00
$groupid = 0 ;
$joins = array ();
2008-06-01 19:05:07 +00:00
$qry = " SELECT l.*, u.firstname, u.lastname, u.picture
FROM { mnet_log } l
LEFT JOIN { user } u ON l . userid = u . id
WHERE " ;
$params = array ();
$where .= " l.hostid = :hostid " ;
$params [ 'hostid' ] = $hostid ;
2007-01-04 03:22:51 +00:00
// TODO: Is 1 really a magic number referring to the sitename?
2008-06-01 19:05:07 +00:00
if ( $course != SITEID || $modid != 0 ) {
$where .= " AND l.course=:courseid " ;
$params [ 'courseid' ] = $course ;
2007-01-04 03:22:51 +00:00
}
if ( $modname ) {
2008-06-01 19:05:07 +00:00
$where .= " AND l.module = :modname " ;
$params [ 'modname' ] = $modname ;
2007-01-04 03:22:51 +00:00
}
if ( 'site_errors' === $modid ) {
2008-06-01 19:05:07 +00:00
$where .= " AND ( l.action='error' OR l.action='infected' ) " ;
2007-01-04 03:22:51 +00:00
} else if ( $modid ) {
2008-06-04 06:38:03 +00:00
//TODO: This assumes that modids are the same across sites... probably
2007-01-04 03:22:51 +00:00
//not true
2008-06-01 19:05:07 +00:00
$where .= " AND l.cmid = :modid " ;
$params [ 'modid' ] = $modid ;
2007-01-04 03:22:51 +00:00
}
if ( $modaction ) {
$firstletter = substr ( $modaction , 0 , 1 );
2010-09-04 12:36:00 +00:00
if ( $firstletter == '-' ) {
2010-09-04 14:52:47 +00:00
$where .= " AND " . $DB -> sql_like ( 'l.action' , ':modaction' , false , true , true );
2010-09-04 12:36:00 +00:00
$params [ 'modaction' ] = '%' . substr ( $modaction , 1 ) . '%' ;
} else {
$where .= " AND " . $DB -> sql_like ( 'l.action' , ':modaction' , false );
$params [ 'modaction' ] = '%' . $modaction . '%' ;
2007-01-04 03:22:51 +00:00
}
}
if ( $user ) {
2008-06-01 19:05:07 +00:00
$where .= " AND l.userid = :user " ;
$params [ 'user' ] = $user ;
2007-01-04 03:22:51 +00:00
}
if ( $date ) {
$enddate = $date + 86400 ;
2008-06-01 19:05:07 +00:00
$where .= " AND l.time > :date AND l.time < :enddate " ;
$params [ 'date' ] = $date ;
$params [ 'enddate' ] = $enddate ;
2007-01-04 03:22:51 +00:00
}
$result = array ();
2008-06-01 19:05:07 +00:00
$result [ 'totalcount' ] = $DB -> count_records_sql ( " SELECT COUNT('x') FROM { mnet_log} l WHERE $where " , $params );
2007-01-04 03:22:51 +00:00
if ( ! empty ( $result [ 'totalcount' ])) {
2008-06-01 19:05:07 +00:00
$where .= " ORDER BY $order " ;
$result [ 'logs' ] = $DB -> get_records_sql ( " $qry $where " , $params , $limitfrom , $limitnum );
2007-01-04 03:22:51 +00:00
} else {
$result [ 'logs' ] = array ();
}
return $result ;
}
2006-05-15 05:01:00 +00:00
function build_logs_array ( $course , $user = 0 , $date = 0 , $order = " l.time ASC " , $limitfrom = '' , $limitnum = '' ,
$modname = " " , $modid = 0 , $modaction = " " , $groupid = 0 ) {
2010-09-17 12:08:46 +00:00
global $DB , $SESSION , $USER ;
2004-07-25 14:00:29 +00:00
// It is assumed that $date is the GMT time of midnight for that day,
// and so the next 86400 seconds worth of logs are printed.
2001-11-22 06:23:56 +00:00
2004-07-28 15:52:51 +00:00
/// Setup for group handling.
2006-11-09 18:25:58 +00:00
2004-07-28 15:52:51 +00:00
/// If the group mode is separate, and this user does not have editing privileges,
/// then only the user's group can be viewed.
2006-09-05 08:50:23 +00:00
if ( $course -> groupmode == SEPARATEGROUPS and ! has_capability ( 'moodle/course:managegroups' , get_context_instance ( CONTEXT_COURSE , $course -> id ))) {
2009-10-16 03:12:41 +00:00
if ( isset ( $SESSION -> currentgroup [ $course -> id ])) {
$groupid = $SESSION -> currentgroup [ $course -> id ];
} else {
$groupid = groups_get_all_groups ( $course -> id , $USER -> id );
if ( is_array ( $groupid )) {
$groupid = array_shift ( array_keys ( $groupid ));
$SESSION -> currentgroup [ $course -> id ] = $groupid ;
} else {
$groupid = 0 ;
}
}
2004-07-28 15:52:51 +00:00
}
/// If this course doesn't have groups, no groupid can be specified.
else if ( ! $course -> groupmode ) {
$groupid = 0 ;
}
2004-07-25 14:00:29 +00:00
$joins = array ();
2010-10-19 15:38:53 +00:00
$params = array ();
2002-08-08 16:22:44 +00:00
2006-04-21 05:39:20 +00:00
if ( $course -> id != SITEID || $modid != 0 ) {
2008-05-30 16:47:21 +00:00
$joins [] = " l.course = :courseid " ;
$params [ 'courseid' ] = $course -> id ;
2006-04-21 05:39:20 +00:00
}
2001-11-22 06:23:56 +00:00
2004-02-14 02:44:35 +00:00
if ( $modname ) {
2008-05-30 16:47:21 +00:00
$joins [] = " l.module = :modname " ;
2008-06-04 06:38:03 +00:00
$params [ 'modname' ] = $modname ;
2004-01-15 07:17:12 +00:00
}
2004-08-12 09:55:12 +00:00
if ( 'site_errors' === $modid ) {
2004-12-09 21:35:20 +00:00
$joins [] = " ( l.action='error' OR l.action='infected' ) " ;
2004-08-12 09:55:12 +00:00
} else if ( $modid ) {
2008-05-30 16:47:21 +00:00
$joins [] = " l.cmid = :modid " ;
$params [ 'modid' ] = $modid ;
2004-01-31 14:47:57 +00:00
}
if ( $modaction ) {
2006-03-28 17:33:40 +00:00
$firstletter = substr ( $modaction , 0 , 1 );
2010-09-04 12:36:00 +00:00
if ( $firstletter == '-' ) {
2010-09-04 14:52:47 +00:00
$joins [] = $DB -> sql_like ( 'l.action' , ':modaction' , false , true , true );
2008-05-30 16:47:21 +00:00
$params [ 'modaction' ] = '%' . substr ( $modaction , 1 ) . '%' ;
2010-09-04 12:36:00 +00:00
} else {
$joins [] = $DB -> sql_like ( 'l.action' , ':modaction' , false );
$params [ 'modaction' ] = '%' . $modaction . '%' ;
2006-03-28 17:33:40 +00:00
}
2004-01-15 07:17:12 +00:00
}
2008-06-04 06:38:03 +00:00
2004-07-28 15:52:51 +00:00
/// Getting all members of a group.
if ( $groupid and ! $user ) {
2007-08-16 09:28:18 +00:00
if ( $gusers = groups_get_members ( $groupid )) {
$gusers = array_keys ( $gusers );
2007-06-07 16:04:23 +00:00
$joins [] = 'l.userid IN (' . implode ( ',' , $gusers ) . ')' ;
} else {
2007-10-05 04:24:42 +00:00
$joins [] = 'l.userid = 0' ; // No users in groups, so we want something that will always be false.
2004-07-28 15:52:51 +00:00
}
}
else if ( $user ) {
2008-05-30 16:47:21 +00:00
$joins [] = " l.userid = :userid " ;
$params [ 'userid' ] = $user ;
2001-11-22 06:23:56 +00:00
}
if ( $date ) {
$enddate = $date + 86400 ;
2008-05-30 16:47:21 +00:00
$joins [] = " l.time > :date AND l.time < :enddate " ;
$params [ 'date' ] = $date ;
$params [ 'enddate' ] = $enddate ;
2001-11-22 06:23:56 +00:00
}
2007-06-07 16:04:23 +00:00
$selector = implode ( ' AND ' , $joins );
2004-07-25 14:00:29 +00:00
2003-08-28 11:57:21 +00:00
$totalcount = 0 ; // Initialise
2006-05-15 05:01:00 +00:00
$result = array ();
2008-05-30 16:47:21 +00:00
$result [ 'logs' ] = get_logs ( $selector , $params , $order , $limitfrom , $limitnum , $totalcount );
2006-05-15 05:01:00 +00:00
$result [ 'totalcount' ] = $totalcount ;
return $result ;
}
2006-11-09 18:25:58 +00:00
2006-05-15 05:01:00 +00:00
function print_log ( $course , $user = 0 , $date = 0 , $order = " l.time ASC " , $page = 0 , $perpage = 100 ,
$url = " " , $modname = " " , $modid = 0 , $modaction = " " , $groupid = 0 ) {
2006-11-09 18:25:58 +00:00
2009-08-06 14:10:33 +00:00
global $CFG , $DB , $OUTPUT ;
2006-11-09 18:25:58 +00:00
2006-05-15 05:01:00 +00:00
if ( ! $logs = build_logs_array ( $course , $user , $date , $order , $page * $perpage , $perpage ,
$modname , $modid , $modaction , $groupid )) {
2009-08-18 04:58:26 +00:00
echo $OUTPUT -> notification ( " No logs found! " );
2009-08-06 14:10:33 +00:00
echo $OUTPUT -> footer ();
2001-11-22 06:23:56 +00:00
exit ;
}
2006-11-09 18:25:58 +00:00
2006-12-21 10:58:18 +00:00
$courses = array ();
2006-05-15 05:01:00 +00:00
if ( $course -> id == SITEID ) {
$courses [ 0 ] = '' ;
2008-05-07 18:28:59 +00:00
if ( $ccc = get_courses ( 'all' , 'c.id ASC' , 'c.id,c.shortname' )) {
2006-05-15 05:01:00 +00:00
foreach ( $ccc as $cc ) {
2008-05-07 18:28:59 +00:00
$courses [ $cc -> id ] = $cc -> shortname ;
2006-05-15 05:01:00 +00:00
}
}
2006-12-21 10:58:18 +00:00
} else {
2008-05-07 18:28:59 +00:00
$courses [ $course -> id ] = $course -> shortname ;
2006-05-15 05:01:00 +00:00
}
2006-11-09 18:25:58 +00:00
2006-05-15 05:01:00 +00:00
$totalcount = $logs [ 'totalcount' ];
2001-11-22 06:23:56 +00:00
$count = 0 ;
2004-07-29 18:01:32 +00:00
$ldcache = array ();
2001-11-22 06:23:56 +00:00
$tt = getdate ( time ());
$today = mktime ( 0 , 0 , 0 , $tt [ " mon " ], $tt [ " mday " ], $tt [ " year " ]);
2003-01-01 08:21:19 +00:00
2003-01-15 10:55:54 +00:00
$strftimedatetime = get_string ( " strftimedatetime " );
2007-01-15 21:28:25 +00:00
echo " <div class= \" info \" > \n " ;
2003-08-22 06:07:18 +00:00
print_string ( " displayingrecords " , " " , $totalcount );
2007-01-15 21:28:25 +00:00
echo " </div> \n " ;
2003-01-01 08:21:19 +00:00
2010-02-17 16:59:41 +00:00
echo $OUTPUT -> paging_bar ( $totalcount , $page , $perpage , " $url &perpage= $perpage " );
2003-08-22 06:07:18 +00:00
2010-01-28 08:49:28 +00:00
$table = new html_table ();
2010-03-25 06:38:21 +00:00
$table -> classes = array ( 'logtable' , 'generalbox' );
2010-01-28 08:49:28 +00:00
$table -> align = array ( 'right' , 'left' , 'left' );
$table -> head = array (
get_string ( 'time' ),
get_string ( 'ip_address' ),
2011-07-03 22:12:05 +01:00
get_string ( 'fullnameuser' ),
2010-01-28 08:49:28 +00:00
get_string ( 'action' ),
get_string ( 'info' )
);
$table -> data = array ();
2010-06-17 22:50:25 +00:00
2005-05-12 08:04:47 +00:00
if ( $course -> id == SITEID ) {
2010-01-28 08:49:28 +00:00
array_unshift ( $table -> align , 'left' );
array_unshift ( $table -> head , get_string ( 'course' ));
2005-05-12 08:04:47 +00:00
}
2007-06-07 16:04:23 +00:00
// Make sure that the logs array is an array, even it is empty, to avoid warnings from the foreach.
2006-09-27 07:41:38 +00:00
if ( empty ( $logs [ 'logs' ])) {
2007-06-07 16:04:23 +00:00
$logs [ 'logs' ] = array ();
2006-09-27 07:41:38 +00:00
}
2008-06-04 06:38:03 +00:00
2006-05-15 05:01:00 +00:00
foreach ( $logs [ 'logs' ] as $log ) {
2002-05-31 09:34:50 +00:00
2004-07-29 18:01:32 +00:00
if ( isset ( $ldcache [ $log -> module ][ $log -> action ])) {
$ld = $ldcache [ $log -> module ][ $log -> action ];
} else {
2008-06-01 19:05:07 +00:00
$ld = $DB -> get_record ( 'log_display' , array ( 'module' => $log -> module , 'action' => $log -> action ));
2004-07-29 18:01:32 +00:00
$ldcache [ $log -> module ][ $log -> action ] = $ld ;
}
2007-06-07 15:33:56 +00:00
if ( $ld && is_numeric ( $log -> info )) {
2005-01-16 17:27:40 +00:00
// ugly hack to make sure fullname is shown correctly
2010-01-28 08:49:28 +00:00
if ( $ld -> mtable == 'user' && $ld -> field == $DB -> sql_concat ( 'firstname' , " ' ' " , 'lastname' )) {
2008-06-01 19:05:07 +00:00
$log -> info = fullname ( $DB -> get_record ( $ld -> mtable , array ( 'id' => $log -> info )), true );
2005-01-16 17:27:40 +00:00
} else {
2008-06-01 19:05:07 +00:00
$log -> info = $DB -> get_field ( $ld -> mtable , $ld -> field , array ( 'id' => $log -> info ));
2005-01-16 17:27:40 +00:00
}
2002-05-31 09:34:50 +00:00
}
2006-11-09 18:25:58 +00:00
//Filter log->info
2005-03-27 22:31:54 +00:00
$log -> info = format_string ( $log -> info );
2008-03-13 15:32:08 +00:00
// If $log->url has been trimmed short by the db size restriction
// code in add_to_log, keep a note so we don't add a link to a broken url
$tl = textlib_get_instance ();
$brokenurl = ( $tl -> strlen ( $log -> url ) == 100 && $tl -> substr ( $log -> url , 97 ) == '...' );
2010-01-28 08:49:28 +00:00
$row = array ();
2005-05-12 08:04:47 +00:00
if ( $course -> id == SITEID ) {
2007-08-06 18:19:15 +00:00
if ( empty ( $log -> course )) {
2010-01-28 08:49:28 +00:00
$row [] = get_string ( 'site' );
2007-08-06 18:19:15 +00:00
} else {
2010-01-28 08:49:28 +00:00
$row [] = " <a href= \" { $CFG -> wwwroot } /course/view.php?id= { $log -> course } \" > " . format_string ( $courses [ $log -> course ]) . " </a> " ;
2007-08-06 18:19:15 +00:00
}
2002-06-12 04:22:41 +00:00
}
2010-06-17 22:50:25 +00:00
2010-01-28 08:49:28 +00:00
$row [] = userdate ( $log -> time , '%a' ) . ' ' . userdate ( $log -> time , $strftimedatetime );
2010-06-17 22:50:25 +00:00
2010-02-11 16:27:53 +00:00
$link = new moodle_url ( " /iplookup/index.php?ip= $log->ip &user= $log->userid " );
$row [] = $OUTPUT -> action_link ( $link , $log -> ip , new popup_action ( 'click' , $link , 'iplookup' , array ( 'height' => 440 , 'width' => 700 )));
2010-01-28 08:49:28 +00:00
2010-02-16 16:24:49 +00:00
$row [] = html_writer :: link ( new moodle_url ( " /user/view.php?id= { $log -> userid } &course= { $log -> course } " ), fullname ( $log , has_capability ( 'moodle/site:viewfullnames' , get_context_instance ( CONTEXT_COURSE , $course -> id ))));
2010-01-28 08:49:28 +00:00
2008-03-13 15:32:08 +00:00
$displayaction = " $log->module $log->action " ;
2010-01-28 08:49:28 +00:00
if ( $brokenurl ) {
$row [] = $displayaction ;
2008-03-13 15:32:08 +00:00
} else {
2010-02-11 16:27:53 +00:00
$link = make_log_url ( $log -> module , $log -> url );
$row [] = $OUTPUT -> action_link ( $link , $displayaction , new popup_action ( 'click' , $link , 'fromloglive' ), array ( 'height' => 440 , 'width' => 700 ));
2008-03-13 15:32:08 +00:00
}
2010-01-28 08:49:28 +00:00
$row [] = $log -> info ;
2010-01-28 09:11:32 +00:00
$table -> data [] = $row ;
2001-11-22 06:23:56 +00:00
}
2003-08-22 06:07:18 +00:00
2010-03-20 22:15:54 +00:00
echo html_writer :: table ( $table );
2010-02-17 16:59:41 +00:00
echo $OUTPUT -> paging_bar ( $totalcount , $page , $perpage , " $url &perpage= $perpage " );
2001-11-22 06:23:56 +00:00
}
2007-01-04 03:22:51 +00:00
function print_mnet_log ( $hostid , $course , $user = 0 , $date = 0 , $order = " l.time ASC " , $page = 0 , $perpage = 100 ,
$url = " " , $modname = " " , $modid = 0 , $modaction = " " , $groupid = 0 ) {
2008-06-04 06:38:03 +00:00
2009-08-06 14:10:33 +00:00
global $CFG , $DB , $OUTPUT ;
2008-06-04 06:38:03 +00:00
2007-01-04 03:22:51 +00:00
if ( ! $logs = build_mnet_logs_array ( $hostid , $course , $user , $date , $order , $page * $perpage , $perpage ,
$modname , $modid , $modaction , $groupid )) {
2009-08-18 04:58:26 +00:00
echo $OUTPUT -> notification ( " No logs found! " );
2009-08-06 14:10:33 +00:00
echo $OUTPUT -> footer ();
2007-01-04 03:22:51 +00:00
exit ;
}
2008-06-04 06:38:03 +00:00
2007-01-04 03:22:51 +00:00
if ( $course -> id == SITEID ) {
$courses [ 0 ] = '' ;
if ( $ccc = get_courses ( 'all' , 'c.id ASC' , 'c.id,c.shortname,c.visible' )) {
foreach ( $ccc as $cc ) {
$courses [ $cc -> id ] = $cc -> shortname ;
}
}
}
2008-06-04 06:38:03 +00:00
2007-01-04 03:22:51 +00:00
$totalcount = $logs [ 'totalcount' ];
$count = 0 ;
$ldcache = array ();
$tt = getdate ( time ());
$today = mktime ( 0 , 0 , 0 , $tt [ " mon " ], $tt [ " mday " ], $tt [ " year " ]);
$strftimedatetime = get_string ( " strftimedatetime " );
2007-01-15 21:28:25 +00:00
echo " <div class= \" info \" > \n " ;
2007-01-04 03:22:51 +00:00
print_string ( " displayingrecords " , " " , $totalcount );
2007-01-15 21:28:25 +00:00
echo " </div> \n " ;
2007-01-04 03:22:51 +00:00
2010-02-17 16:59:41 +00:00
echo $OUTPUT -> paging_bar ( $totalcount , $page , $perpage , " $url &perpage= $perpage " );
2007-01-04 03:22:51 +00:00
2007-01-15 21:28:25 +00:00
echo " <table class= \" logtable \" cellpadding= \" 3 \" cellspacing= \" 0 \" > \n " ;
2007-01-04 03:22:51 +00:00
echo " <tr> " ;
if ( $course -> id == SITEID ) {
echo " <th class= \" c0 header \" > " . get_string ( 'course' ) . " </th> \n " ;
}
echo " <th class= \" c1 header \" > " . get_string ( 'time' ) . " </th> \n " ;
echo " <th class= \" c2 header \" > " . get_string ( 'ip_address' ) . " </th> \n " ;
2011-07-03 22:12:05 +01:00
echo " <th class= \" c3 header \" > " . get_string ( 'fullnameuser' ) . " </th> \n " ;
2007-01-04 03:22:51 +00:00
echo " <th class= \" c4 header \" > " . get_string ( 'action' ) . " </th> \n " ;
echo " <th class= \" c5 header \" > " . get_string ( 'info' ) . " </th> \n " ;
echo " </tr> \n " ;
if ( empty ( $logs [ 'logs' ])) {
echo " </table> \n " ;
return ;
}
$row = 1 ;
foreach ( $logs [ 'logs' ] as $log ) {
2008-06-04 06:38:03 +00:00
2007-01-04 03:22:51 +00:00
$log -> info = $log -> coursename ;
$row = ( $row + 1 ) % 2 ;
if ( isset ( $ldcache [ $log -> module ][ $log -> action ])) {
$ld = $ldcache [ $log -> module ][ $log -> action ];
} else {
2008-06-02 08:13:24 +00:00
$ld = $DB -> get_record ( 'log_display' , array ( 'module' => $log -> module , 'action' => $log -> action ));
2007-01-04 03:22:51 +00:00
$ldcache [ $log -> module ][ $log -> action ] = $ld ;
}
if ( 0 && $ld && ! empty ( $log -> info )) {
// ugly hack to make sure fullname is shown correctly
2008-06-01 19:05:07 +00:00
if (( $ld -> mtable == 'user' ) and ( $ld -> field == $DB -> sql_concat ( 'firstname' , " ' ' " , 'lastname' ))) {
$log -> info = fullname ( $DB -> get_record ( $ld -> mtable , array ( 'id' => $log -> info )), true );
2007-01-04 03:22:51 +00:00
} else {
2008-06-01 19:05:07 +00:00
$log -> info = $DB -> get_field ( $ld -> mtable , $ld -> field , array ( 'id' => $log -> info ));
2007-01-04 03:22:51 +00:00
}
}
2008-06-04 06:38:03 +00:00
//Filter log->info
2007-01-04 03:22:51 +00:00
$log -> info = format_string ( $log -> info );
echo '<tr class="r' . $row . '">' ;
if ( $course -> id == SITEID ) {
2011-09-07 11:46:28 +12:00
$courseshortname = format_string ( $courses [ $log -> course ], true , array ( 'context' => get_context_instance ( CONTEXT_COURSE , SITEID )));
2007-01-15 21:28:25 +00:00
echo " <td class= \" r $row c0 \" > \n " ;
2011-09-07 11:46:28 +12:00
echo " <a href= \" { $CFG -> wwwroot } /course/view.php?id= { $log -> course } \" > " . $courseshortname . " </a> \n " ;
2007-01-04 03:22:51 +00:00
echo " </td> \n " ;
}
2007-01-15 21:28:25 +00:00
echo " <td class= \" r $row c1 \" align= \" right \" > " . userdate ( $log -> time , '%a' ) .
2007-01-04 03:22:51 +00:00
' ' . userdate ( $log -> time , $strftimedatetime ) . " </td> \n " ;
2007-01-15 21:28:25 +00:00
echo " <td class= \" r $row c2 \" > \n " ;
2010-02-11 16:27:53 +00:00
$link = new moodle_url ( " /iplookup/index.php?ip= $log->ip &user= $log->userid " );
echo $OUTPUT -> action_link ( $link , $log -> ip , new popup_action ( 'click' , $link , 'iplookup' , array ( 'height' => 400 , 'width' => 700 )));
2007-01-04 03:22:51 +00:00
echo " </td> \n " ;
$fullname = fullname ( $log , has_capability ( 'moodle/site:viewfullnames' , get_context_instance ( CONTEXT_COURSE , $course -> id )));
2007-01-15 21:28:25 +00:00
echo " <td class= \" r $row c3 \" > \n " ;
2007-01-04 03:22:51 +00:00
echo " <a href= \" $CFG->wwwroot /user/view.php?id= { $log -> userid } \" > $fullname </a> \n " ;
echo " </td> \n " ;
2007-01-15 21:28:25 +00:00
echo " <td class= \" r $row c4 \" > \n " ;
2007-01-04 03:22:51 +00:00
echo $log -> action . ': ' . $log -> module ;
echo " </td> \n " ;;
2007-01-15 21:28:25 +00:00
echo " <td class= \" r $row c5 \" > { $log -> info } </td> \n " ;
2007-01-04 03:22:51 +00:00
echo " </tr> \n " ;
}
echo " </table> \n " ;
2010-02-17 16:59:41 +00:00
echo $OUTPUT -> paging_bar ( $totalcount , $page , $perpage , " $url &perpage= $perpage " );
2007-01-04 03:22:51 +00:00
}
2006-05-15 05:01:00 +00:00
function print_log_csv ( $course , $user , $date , $order = 'l.time DESC' , $modname ,
$modid , $modaction , $groupid ) {
2008-06-01 19:05:07 +00:00
global $DB ;
2006-09-26 05:03:46 +00:00
2006-08-25 07:09:28 +00:00
$text = get_string ( 'course' ) . " \t " . get_string ( 'time' ) . " \t " . get_string ( 'ip_address' ) . " \t " .
2011-07-03 22:12:05 +01:00
get_string ( 'fullnameuser' ) . " \t " . get_string ( 'action' ) . " \t " . get_string ( 'info' );
2006-11-09 18:25:58 +00:00
2006-08-25 07:09:28 +00:00
if ( ! $logs = build_logs_array ( $course , $user , $date , $order , '' , '' ,
2006-05-15 05:01:00 +00:00
$modname , $modid , $modaction , $groupid )) {
return false ;
}
2006-11-09 18:25:58 +00:00
2006-12-21 10:58:18 +00:00
$courses = array ();
2006-05-15 05:01:00 +00:00
if ( $course -> id == SITEID ) {
$courses [ 0 ] = '' ;
if ( $ccc = get_courses ( 'all' , 'c.id ASC' , 'c.id,c.shortname' )) {
foreach ( $ccc as $cc ) {
$courses [ $cc -> id ] = $cc -> shortname ;
}
}
2006-12-21 10:58:18 +00:00
} else {
$courses [ $course -> id ] = $course -> shortname ;
2006-05-15 05:01:00 +00:00
}
2006-11-09 18:25:58 +00:00
2006-05-15 05:01:00 +00:00
$count = 0 ;
$ldcache = array ();
$tt = getdate ( time ());
$today = mktime ( 0 , 0 , 0 , $tt [ " mon " ], $tt [ " mday " ], $tt [ " year " ]);
$strftimedatetime = get_string ( " strftimedatetime " );
2010-04-10 17:35:19 +00:00
$filename = 'logs_' . userdate ( time (), get_string ( 'backupnameformat' , 'langconfig' ), 99 , false );
2006-08-25 07:09:28 +00:00
$filename .= '.txt' ;
2006-11-09 18:25:58 +00:00
header ( " Content-Type: application/download \n " );
2006-08-25 07:09:28 +00:00
header ( " Content-Disposition: attachment; filename= $filename " );
header ( " Expires: 0 " );
header ( " Cache-Control: must-revalidate,post-check=0,pre-check=0 " );
header ( " Pragma: public " );
echo get_string ( 'savedat' ) . userdate ( time (), $strftimedatetime ) . " \n " ;
2011-07-18 23:46:08 +01:00
echo $text . " \n " ;
2006-08-25 07:09:28 +00:00
2006-09-27 07:41:38 +00:00
if ( empty ( $logs [ 'logs' ])) {
return true ;
}
2006-08-25 07:09:28 +00:00
foreach ( $logs [ 'logs' ] as $log ) {
if ( isset ( $ldcache [ $log -> module ][ $log -> action ])) {
$ld = $ldcache [ $log -> module ][ $log -> action ];
} else {
2008-06-02 08:13:24 +00:00
$ld = $DB -> get_record ( 'log_display' , array ( 'module' => $log -> module , 'action' => $log -> action ));
2006-08-25 07:09:28 +00:00
$ldcache [ $log -> module ][ $log -> action ] = $ld ;
}
if ( $ld && ! empty ( $log -> info )) {
// ugly hack to make sure fullname is shown correctly
2008-06-01 19:05:07 +00:00
if (( $ld -> mtable == 'user' ) and ( $ld -> field == $DB -> sql_concat ( 'firstname' , " ' ' " , 'lastname' ))) {
$log -> info = fullname ( $DB -> get_record ( $ld -> mtable , array ( 'id' => $log -> info )), true );
2006-08-25 07:09:28 +00:00
} else {
2008-06-01 19:05:07 +00:00
$log -> info = $DB -> get_field ( $ld -> mtable , $ld -> field , array ( 'id' => $log -> info ));
2006-08-25 07:09:28 +00:00
}
}
2006-11-09 18:25:58 +00:00
//Filter log->info
2006-08-25 07:09:28 +00:00
$log -> info = format_string ( $log -> info );
$log -> info = strip_tags ( urldecode ( $log -> info )); // Some XSS protection
2011-09-07 11:46:28 +12:00
$coursecontext = get_context_instance ( CONTEXT_COURSE , $course -> id );
$firstField = format_string ( $courses [ $log -> course ], true , array ( 'context' => $coursecontext ));
$fullname = fullname ( $log , has_capability ( 'moodle/site:viewfullnames' , $coursecontext ));
2006-08-25 07:09:28 +00:00
$row = array ( $firstField , userdate ( $log -> time , $strftimedatetime ), $log -> ip , $fullname , $log -> module . ' ' . $log -> action , $log -> info );
$text = implode ( " \t " , $row );
echo $text . " \n " ;
}
return true ;
2006-05-15 05:01:00 +00:00
}
function print_log_xls ( $course , $user , $date , $order = 'l.time DESC' , $modname ,
$modid , $modaction , $groupid ) {
2006-11-09 18:25:58 +00:00
2008-06-01 19:05:07 +00:00
global $CFG , $DB ;
2006-05-15 05:01:00 +00:00
2006-08-25 07:09:28 +00:00
require_once ( " $CFG->libdir /excellib.class.php " );
2006-11-09 18:25:58 +00:00
2006-08-25 07:09:28 +00:00
if ( ! $logs = build_logs_array ( $course , $user , $date , $order , '' , '' ,
2006-05-15 05:01:00 +00:00
$modname , $modid , $modaction , $groupid )) {
return false ;
}
2006-11-09 18:25:58 +00:00
2006-12-21 10:58:18 +00:00
$courses = array ();
2006-05-15 05:01:00 +00:00
if ( $course -> id == SITEID ) {
$courses [ 0 ] = '' ;
if ( $ccc = get_courses ( 'all' , 'c.id ASC' , 'c.id,c.shortname' )) {
foreach ( $ccc as $cc ) {
$courses [ $cc -> id ] = $cc -> shortname ;
}
}
2006-12-21 10:58:18 +00:00
} else {
$courses [ $course -> id ] = $course -> shortname ;
2006-05-15 05:01:00 +00:00
}
2006-11-09 18:25:58 +00:00
2006-05-15 05:01:00 +00:00
$count = 0 ;
$ldcache = array ();
$tt = getdate ( time ());
$today = mktime ( 0 , 0 , 0 , $tt [ " mon " ], $tt [ " mday " ], $tt [ " year " ]);
$strftimedatetime = get_string ( " strftimedatetime " );
2006-08-25 07:09:28 +00:00
$nroPages = ceil ( count ( $logs ) / ( EXCELROWS - FIRSTUSEDEXCELROW + 1 ));
2010-04-10 17:35:19 +00:00
$filename = 'logs_' . userdate ( time (), get_string ( 'backupnameformat' , 'langconfig' ), 99 , false );
2006-08-25 07:09:28 +00:00
$filename .= '.xls' ;
2006-11-09 18:25:58 +00:00
2006-05-15 05:01:00 +00:00
$workbook = new MoodleExcelWorkbook ( '-' );
$workbook -> send ( $filename );
2006-11-09 18:25:58 +00:00
2006-08-25 07:09:28 +00:00
$worksheet = array ();
$headers = array ( get_string ( 'course' ), get_string ( 'time' ), get_string ( 'ip_address' ),
2011-07-03 22:12:05 +01:00
get_string ( 'fullnameuser' ), get_string ( 'action' ), get_string ( 'info' ));
2006-11-09 18:25:58 +00:00
2006-08-25 07:09:28 +00:00
// Creating worksheets
for ( $wsnumber = 1 ; $wsnumber <= $nroPages ; $wsnumber ++ ) {
2008-04-11 05:47:20 +00:00
$sheettitle = get_string ( 'logs' ) . ' ' . $wsnumber . '-' . $nroPages ;
2006-08-25 07:09:28 +00:00
$worksheet [ $wsnumber ] =& $workbook -> add_worksheet ( $sheettitle );
$worksheet [ $wsnumber ] -> set_column ( 1 , 1 , 30 );
$worksheet [ $wsnumber ] -> write_string ( 0 , 0 , get_string ( 'savedat' ) .
userdate ( time (), $strftimedatetime ));
$col = 0 ;
foreach ( $headers as $item ) {
$worksheet [ $wsnumber ] -> write ( FIRSTUSEDEXCELROW - 1 , $col , $item , '' );
$col ++ ;
}
}
2006-09-27 07:41:38 +00:00
if ( empty ( $logs [ 'logs' ])) {
$workbook -> close ();
return true ;
}
2006-08-25 07:09:28 +00:00
$formatDate =& $workbook -> add_format ();
$formatDate -> set_num_format ( get_string ( 'log_excel_date_format' ));
$row = FIRSTUSEDEXCELROW ;
$wsnumber = 1 ;
$myxls =& $worksheet [ $wsnumber ];
foreach ( $logs [ 'logs' ] as $log ) {
if ( isset ( $ldcache [ $log -> module ][ $log -> action ])) {
$ld = $ldcache [ $log -> module ][ $log -> action ];
} else {
2008-06-01 19:05:07 +00:00
$ld = $DB -> get_record ( 'log_display' , array ( 'module' => $log -> module , 'action' => $log -> action ));
2006-08-25 07:09:28 +00:00
$ldcache [ $log -> module ][ $log -> action ] = $ld ;
}
if ( $ld && ! empty ( $log -> info )) {
// ugly hack to make sure fullname is shown correctly
2008-06-01 19:05:07 +00:00
if (( $ld -> mtable == 'user' ) and ( $ld -> field == $DB -> sql_concat ( 'firstname' , " ' ' " , 'lastname' ))) {
$log -> info = fullname ( $DB -> get_record ( $ld -> mtable , array ( 'id' => $log -> info )), true );
2006-08-25 07:09:28 +00:00
} else {
2008-06-01 19:05:07 +00:00
$log -> info = $DB -> get_field ( $ld -> mtable , $ld -> field , array ( 'id' => $log -> info ));
2006-08-25 07:09:28 +00:00
}
}
// Filter log->info
$log -> info = format_string ( $log -> info );
$log -> info = strip_tags ( urldecode ( $log -> info )); // Some XSS protection
if ( $nroPages > 1 ) {
if ( $row > EXCELROWS ) {
$wsnumber ++ ;
$myxls =& $worksheet [ $wsnumber ];
$row = FIRSTUSEDEXCELROW ;
}
}
2006-11-09 18:25:58 +00:00
2011-09-07 11:46:28 +12:00
$coursecontext = get_context_instance ( CONTEXT_COURSE , $course -> id );
$myxls -> write ( $row , 0 , format_string ( $courses [ $log -> course ], true , array ( 'context' => $coursecontext )), '' );
2010-02-25 10:17:46 +00:00
$myxls -> write_date ( $row , 1 , $log -> time , $formatDate ); // write_date() does conversion/timezone support. MDL-14934
2006-08-25 07:09:28 +00:00
$myxls -> write ( $row , 2 , $log -> ip , '' );
2011-09-07 11:46:28 +12:00
$fullname = fullname ( $log , has_capability ( 'moodle/site:viewfullnames' , $coursecontext ));
2006-08-25 07:09:28 +00:00
$myxls -> write ( $row , 3 , $fullname , '' );
$myxls -> write ( $row , 4 , $log -> module . ' ' . $log -> action , '' );
$myxls -> write ( $row , 5 , $log -> info , '' );
2006-11-09 18:25:58 +00:00
2006-08-25 07:09:28 +00:00
$row ++ ;
}
$workbook -> close ();
2006-12-21 10:58:18 +00:00
return true ;
}
function print_log_ods ( $course , $user , $date , $order = 'l.time DESC' , $modname ,
$modid , $modaction , $groupid ) {
2008-06-01 19:05:07 +00:00
global $CFG , $DB ;
2006-12-21 10:58:18 +00:00
require_once ( " $CFG->libdir /odslib.class.php " );
if ( ! $logs = build_logs_array ( $course , $user , $date , $order , '' , '' ,
$modname , $modid , $modaction , $groupid )) {
return false ;
}
$courses = array ();
if ( $course -> id == SITEID ) {
$courses [ 0 ] = '' ;
if ( $ccc = get_courses ( 'all' , 'c.id ASC' , 'c.id,c.shortname' )) {
foreach ( $ccc as $cc ) {
$courses [ $cc -> id ] = $cc -> shortname ;
}
}
} else {
$courses [ $course -> id ] = $course -> shortname ;
}
$count = 0 ;
$ldcache = array ();
$tt = getdate ( time ());
$today = mktime ( 0 , 0 , 0 , $tt [ " mon " ], $tt [ " mday " ], $tt [ " year " ]);
$strftimedatetime = get_string ( " strftimedatetime " );
$nroPages = ceil ( count ( $logs ) / ( EXCELROWS - FIRSTUSEDEXCELROW + 1 ));
2010-04-10 17:35:19 +00:00
$filename = 'logs_' . userdate ( time (), get_string ( 'backupnameformat' , 'langconfig' ), 99 , false );
2006-12-21 10:58:18 +00:00
$filename .= '.ods' ;
$workbook = new MoodleODSWorkbook ( '-' );
$workbook -> send ( $filename );
$worksheet = array ();
$headers = array ( get_string ( 'course' ), get_string ( 'time' ), get_string ( 'ip_address' ),
2011-07-03 22:12:05 +01:00
get_string ( 'fullnameuser' ), get_string ( 'action' ), get_string ( 'info' ));
2006-12-21 10:58:18 +00:00
// Creating worksheets
for ( $wsnumber = 1 ; $wsnumber <= $nroPages ; $wsnumber ++ ) {
2008-04-11 05:47:20 +00:00
$sheettitle = get_string ( 'logs' ) . ' ' . $wsnumber . '-' . $nroPages ;
2006-12-21 10:58:18 +00:00
$worksheet [ $wsnumber ] =& $workbook -> add_worksheet ( $sheettitle );
$worksheet [ $wsnumber ] -> set_column ( 1 , 1 , 30 );
$worksheet [ $wsnumber ] -> write_string ( 0 , 0 , get_string ( 'savedat' ) .
userdate ( time (), $strftimedatetime ));
$col = 0 ;
foreach ( $headers as $item ) {
$worksheet [ $wsnumber ] -> write ( FIRSTUSEDEXCELROW - 1 , $col , $item , '' );
$col ++ ;
}
}
if ( empty ( $logs [ 'logs' ])) {
$workbook -> close ();
return true ;
}
$formatDate =& $workbook -> add_format ();
$formatDate -> set_num_format ( get_string ( 'log_excel_date_format' ));
$row = FIRSTUSEDEXCELROW ;
$wsnumber = 1 ;
$myxls =& $worksheet [ $wsnumber ];
foreach ( $logs [ 'logs' ] as $log ) {
if ( isset ( $ldcache [ $log -> module ][ $log -> action ])) {
$ld = $ldcache [ $log -> module ][ $log -> action ];
} else {
2008-06-01 19:05:07 +00:00
$ld = $DB -> get_record ( 'log_display' , array ( 'module' => $log -> module , 'action' => $log -> action ));
2006-12-21 10:58:18 +00:00
$ldcache [ $log -> module ][ $log -> action ] = $ld ;
}
if ( $ld && ! empty ( $log -> info )) {
// ugly hack to make sure fullname is shown correctly
2008-06-02 21:56:06 +00:00
if (( $ld -> mtable == 'user' ) and ( $ld -> field == $DB -> sql_concat ( 'firstname' , " ' ' " , 'lastname' ))) {
2008-06-01 19:05:07 +00:00
$log -> info = fullname ( $DB -> get_record ( $ld -> mtable , array ( 'id' => $log -> info )), true );
2006-12-21 10:58:18 +00:00
} else {
2008-06-01 19:05:07 +00:00
$log -> info = $DB -> get_field ( $ld -> mtable , $ld -> field , array ( 'id' => $log -> info ));
2006-12-21 10:58:18 +00:00
}
}
// Filter log->info
$log -> info = format_string ( $log -> info );
$log -> info = strip_tags ( urldecode ( $log -> info )); // Some XSS protection
if ( $nroPages > 1 ) {
if ( $row > EXCELROWS ) {
$wsnumber ++ ;
$myxls =& $worksheet [ $wsnumber ];
$row = FIRSTUSEDEXCELROW ;
}
}
2011-09-07 11:46:28 +12:00
$coursecontext = get_context_instance ( CONTEXT_COURSE , $course -> id );
$myxls -> write_string ( $row , 0 , format_string ( $courses [ $log -> course ], true , array ( 'context' => $context )));
2006-12-21 19:46:29 +00:00
$myxls -> write_date ( $row , 1 , $log -> time );
$myxls -> write_string ( $row , 2 , $log -> ip );
2011-09-07 11:46:28 +12:00
$fullname = fullname ( $log , has_capability ( 'moodle/site:viewfullnames' , $coursecontext ));
2006-12-21 19:46:29 +00:00
$myxls -> write_string ( $row , 3 , $fullname );
$myxls -> write_string ( $row , 4 , $log -> module . ' ' . $log -> action );
$myxls -> write_string ( $row , 5 , $log -> info );
2006-12-21 10:58:18 +00:00
$row ++ ;
}
$workbook -> close ();
2006-08-25 07:09:28 +00:00
return true ;
2006-05-15 05:01:00 +00:00
}
2010-11-16 13:40:34 +00:00
function print_overview ( $courses , array $remote_courses = array ()) {
2009-08-06 08:15:43 +00:00
global $CFG , $USER , $DB , $OUTPUT ;
2005-08-16 00:25:39 +00:00
2006-01-17 20:49:43 +00:00
$htmlarray = array ();
2008-06-02 08:13:24 +00:00
if ( $modules = $DB -> get_records ( 'modules' )) {
2005-09-05 01:31:08 +00:00
foreach ( $modules as $mod ) {
if ( file_exists ( dirname ( dirname ( __FILE__ )) . '/mod/' . $mod -> name . '/lib.php' )) {
2008-01-24 02:20:25 +00:00
include_once ( dirname ( dirname ( __FILE__ )) . '/mod/' . $mod -> name . '/lib.php' );
2005-09-05 01:31:08 +00:00
$fname = $mod -> name . '_print_overview' ;
2005-08-16 00:25:39 +00:00
if ( function_exists ( $fname )) {
2006-01-17 20:49:43 +00:00
$fname ( $courses , $htmlarray );
2005-08-16 00:25:39 +00:00
}
}
}
}
2006-01-17 20:49:43 +00:00
foreach ( $courses as $course ) {
2011-09-06 13:40:44 +12:00
$fullname = format_string ( $course -> fullname , true , array ( 'context' => get_context_instance ( CONTEXT_COURSE , $course -> id )));
2010-11-16 13:40:34 +00:00
echo $OUTPUT -> box_start ( 'coursebox' );
2011-09-06 13:40:44 +12:00
$attributes = array ( 'title' => s ( $fullname ));
2006-01-17 20:49:43 +00:00
if ( empty ( $course -> visible )) {
2010-11-16 13:40:34 +00:00
$attributes [ 'class' ] = 'dimmed' ;
2006-01-17 20:49:43 +00:00
}
2010-11-16 13:40:34 +00:00
echo $OUTPUT -> heading ( html_writer :: link (
2011-09-06 13:40:44 +12:00
new moodle_url ( '/course/view.php' , array ( 'id' => $course -> id )), $fullname , $attributes ), 3 );
2006-01-17 20:49:43 +00:00
if ( array_key_exists ( $course -> id , $htmlarray )) {
foreach ( $htmlarray [ $course -> id ] as $modname => $html ) {
echo $html ;
}
}
2009-08-18 04:58:26 +00:00
echo $OUTPUT -> box_end ();
2006-01-17 20:49:43 +00:00
}
2010-11-16 13:40:34 +00:00
if ( ! empty ( $remote_courses )) {
echo $OUTPUT -> heading ( get_string ( 'remotecourses' , 'mnet' ));
}
foreach ( $remote_courses as $course ) {
echo $OUTPUT -> box_start ( 'coursebox' );
$attributes = array ( 'title' => s ( $course -> fullname ));
echo $OUTPUT -> heading ( html_writer :: link (
new moodle_url ( '/auth/mnet/jump.php' , array ( 'hostid' => $course -> hostid , 'wantsurl' => '/course/view.php?id=' . $course -> remoteid )),
format_string ( $course -> shortname ),
$attributes ) . ' (' . format_string ( $course -> hostname ) . ')' , 3 );
echo $OUTPUT -> box_end ();
}
2005-08-16 00:25:39 +00:00
}
2008-06-01 19:05:07 +00:00
/**
* This function trawls through the logs looking for
* anything new since the user ' s last login
*/
2002-05-31 09:34:50 +00:00
function print_recent_activity ( $course ) {
// $course is an object
2009-08-06 01:38:17 +00:00
global $CFG , $USER , $SESSION , $DB , $OUTPUT ;
2002-05-31 09:34:50 +00:00
2006-10-24 14:37:04 +00:00
$context = get_context_instance ( CONTEXT_COURSE , $course -> id );
2003-11-19 16:30:09 +00:00
2008-01-24 20:33:50 +00:00
$viewfullnames = has_capability ( 'moodle/site:viewfullnames' , $context );
$timestart = round ( time () - COURSE_MAX_RECENT_PERIOD , - 2 ); // better db caching for guests - 100 seconds
2004-02-23 18:05:59 +00:00
2010-03-31 07:41:31 +00:00
if ( ! isguestuser ()) {
2006-10-24 14:37:04 +00:00
if ( ! empty ( $USER -> lastcourseaccess [ $course -> id ])) {
if ( $USER -> lastcourseaccess [ $course -> id ] > $timestart ) {
$timestart = $USER -> lastcourseaccess [ $course -> id ];
}
2004-05-15 14:58:12 +00:00
}
2003-04-26 12:17:30 +00:00
}
2004-02-23 18:05:59 +00:00
2004-10-08 13:34:48 +00:00
echo '<div class="activitydate">' ;
2005-03-10 14:09:45 +00:00
echo get_string ( 'activitysince' , '' , userdate ( $timestart ));
2004-10-08 13:34:48 +00:00
echo '</div>' ;
echo '<div class="activityhead">' ;
2004-02-23 18:05:59 +00:00
2004-10-08 13:34:48 +00:00
echo '<a href="' . $CFG -> wwwroot . '/course/recent.php?id=' . $course -> id . '">' . get_string ( 'recentactivityreport' ) . '</a>' ;
2004-02-23 18:05:59 +00:00
2006-05-16 10:59:27 +00:00
echo " </div> \n " ;
2004-02-23 18:05:59 +00:00
2002-05-31 09:34:50 +00:00
$content = false ;
2003-04-26 15:08:34 +00:00
2008-01-24 20:33:50 +00:00
/// Firstly, have there been any new enrolments?
2003-08-17 01:46:00 +00:00
$users = get_recent_enrolments ( $course -> id , $timestart );
2003-04-26 15:08:34 +00:00
2006-05-16 10:59:27 +00:00
//Accessibility: new users now appear in an <OL> list.
2003-08-17 01:46:00 +00:00
if ( $users ) {
2005-03-10 14:09:45 +00:00
echo '<div class="newusers">' ;
2009-08-06 01:38:17 +00:00
echo $OUTPUT -> heading ( get_string ( " newusers " ) . ':' , 3 );
2008-01-24 20:33:50 +00:00
$content = true ;
2006-05-16 10:59:27 +00:00
echo " <ol class= \" list \" > \n " ;
2003-08-17 01:46:00 +00:00
foreach ( $users as $user ) {
2008-01-24 20:33:50 +00:00
$fullname = fullname ( $user , $viewfullnames );
echo '<li class="name"><a href="' . " $CFG->wwwroot /user/view.php?id= $user->id &course= $course->id\ " > $fullname </ a ></ li > \n " ;
2002-05-31 09:34:50 +00:00
}
2006-05-16 10:59:27 +00:00
echo " </ol> \n </div> \n " ;
2002-05-31 09:34:50 +00:00
}
2008-01-24 20:33:50 +00:00
/// Next, have there been any modifications to the course structure?
$modinfo =& get_fast_modinfo ( $course );
$changelist = array ();
2003-04-26 15:08:34 +00:00
2008-06-01 19:05:07 +00:00
$logs = $DB -> get_records_select ( 'log' , " time > ? AND course = ? AND
module = 'course' AND
( action = 'add mod' OR action = 'update mod' OR action = 'delete mod' ) " ,
array ( $timestart , $course -> id ), " id ASC " );
2003-04-26 15:08:34 +00:00
if ( $logs ) {
2008-01-24 20:33:50 +00:00
$actions = array ( 'add mod' , 'update mod' , 'delete mod' );
$newgones = array (); // added and later deleted items
2003-04-26 15:08:34 +00:00
foreach ( $logs as $key => $log ) {
2008-01-24 20:33:50 +00:00
if ( ! in_array ( $log -> action , $actions )) {
continue ;
}
2010-07-20 03:27:36 +00:00
$info = explode ( ' ' , $log -> info );
2003-09-14 12:25:16 +00:00
2011-01-26 10:29:16 +00:00
// note: in most cases I replaced hardcoding of label with use of
// $cm->has_view() but it was not possible to do this here because
// we don't necessarily have the $cm for it
2008-01-24 20:33:50 +00:00
if ( $info [ 0 ] == 'label' ) { // Labels are ignored in recent activity
2003-09-14 12:25:16 +00:00
continue ;
}
2008-01-24 20:33:50 +00:00
if ( count ( $info ) != 2 ) {
debugging ( " Incorrect log entry info: id = " . $log -> id , DEBUG_DEVELOPER );
continue ;
}
$modname = $info [ 0 ];
$instanceid = $info [ 1 ];
if ( $log -> action == 'delete mod' ) {
// unfortunately we do not know if the mod was visible
if ( ! array_key_exists ( $log -> info , $newgones )) {
$strdeleted = get_string ( 'deletedactivity' , 'moodle' , get_string ( 'modulename' , $modname ));
$changelist [ $log -> info ] = array ( 'operation' => 'delete' , 'text' => $strdeleted );
}
} else {
if ( ! isset ( $modinfo -> instances [ $modname ][ $instanceid ])) {
if ( $log -> action == 'add mod' ) {
// do not display added and later deleted activities
$newgones [ $log -> info ] = true ;
}
continue ;
}
$cm = $modinfo -> instances [ $modname ][ $instanceid ];
if ( ! $cm -> uservisible ) {
2008-07-05 13:20:21 +00:00
continue ;
2008-01-24 20:33:50 +00:00
}
if ( $log -> action == 'add mod' ) {
$stradded = get_string ( 'added' , 'moodle' , get_string ( 'modulename' , $modname ));
$changelist [ $log -> info ] = array ( 'operation' => 'add' , 'text' => " $stradded :<br /><a href= \" $CFG->wwwroot /mod/ $cm->modname /view.php?id= { $cm -> id } \" > " . format_string ( $cm -> name , true ) . " </a> " );
} else if ( $log -> action == 'update mod' and empty ( $changelist [ $log -> info ])) {
$strupdated = get_string ( 'updated' , 'moodle' , get_string ( 'modulename' , $modname ));
$changelist [ $log -> info ] = array ( 'operation' => 'update' , 'text' => " $strupdated :<br /><a href= \" $CFG->wwwroot /mod/ $cm->modname /view.php?id= { $cm -> id } \" > " . format_string ( $cm -> name , true ) . " </a> " );
2002-05-31 09:34:50 +00:00
}
2002-06-01 09:23:37 +00:00
}
}
}
2002-12-29 17:32:32 +00:00
if ( ! empty ( $changelist )) {
2009-08-06 01:38:17 +00:00
echo $OUTPUT -> heading ( get_string ( " courseupdates " ) . ':' , 3 );
2008-01-24 20:33:50 +00:00
$content = true ;
2002-06-01 09:23:37 +00:00
foreach ( $changelist as $changeinfo => $change ) {
2008-01-24 20:33:50 +00:00
echo '<p class="activity">' . $change [ 'text' ] . '</p>' ;
2002-05-31 09:34:50 +00:00
}
2004-05-28 10:53:54 +00:00
}
2003-08-26 18:45:54 +00:00
2008-01-24 20:33:50 +00:00
/// Now display new things from each module
2003-11-21 12:54:09 +00:00
2008-01-24 20:33:50 +00:00
$usedmodules = array ();
foreach ( $modinfo -> cms as $cm ) {
if ( isset ( $usedmodules [ $cm -> modname ])) {
continue ;
}
if ( ! $cm -> uservisible ) {
continue ;
}
$usedmodules [ $cm -> modname ] = $cm -> modname ;
}
2006-10-24 14:37:04 +00:00
2008-01-24 20:33:50 +00:00
foreach ( $usedmodules as $modname ) { // Each module gets it's own logs and prints them
if ( file_exists ( $CFG -> dirroot . '/mod/' . $modname . '/lib.php' )) {
include_once ( $CFG -> dirroot . '/mod/' . $modname . '/lib.php' );
$print_recent_activity = $modname . '_print_recent_activity' ;
2007-12-28 16:04:30 +00:00
if ( function_exists ( $print_recent_activity )) {
2008-01-24 20:33:50 +00:00
// NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
$content = $print_recent_activity ( $course , $viewfullnames , $timestart ) || $content ;
2002-05-31 09:34:50 +00:00
}
2007-12-28 16:04:30 +00:00
} else {
2008-06-04 06:38:03 +00:00
debugging ( " Missing lib.php in lib/ { $modname } - please reinstall files or uninstall the module " );
2002-05-31 09:34:50 +00:00
}
}
if ( ! $content ) {
2005-03-10 14:09:45 +00:00
echo '<p class="message">' . get_string ( 'nothingnew' ) . '</p>' ;
2002-05-31 09:34:50 +00:00
}
}
2008-06-01 19:05:07 +00:00
/**
* For a given course , returns an array of course activity objects
* Each item in the array contains he following properties :
*/
2002-11-10 07:37:15 +00:00
function get_array_of_activities ( $courseid ) {
// cm - course module id
// mod - name of the module (eg forum)
// section - the number of the section (eg week or topic)
// name - the name of the instance
2003-05-09 17:24:17 +00:00
// visible - is the instance visible or not
2007-08-20 10:52:59 +00:00
// groupingid - grouping id
// groupmembersonly - is this instance visible to group members only
2003-07-20 13:53:31 +00:00
// extra - contains extra string to include in any link
2008-06-01 19:05:07 +00:00
global $CFG , $DB ;
2008-12-17 16:37:35 +00:00
if ( ! empty ( $CFG -> enableavailability )) {
require_once ( $CFG -> libdir . '/conditionlib.php' );
}
2003-10-22 13:14:56 +00:00
2009-04-02 06:59:14 +00:00
$course = $DB -> get_record ( 'course' , array ( 'id' => $courseid ));
if ( empty ( $course )) {
throw new moodle_exception ( 'courseidnotfound' );
}
2002-11-10 07:37:15 +00:00
$mod = array ();
2009-04-02 06:59:14 +00:00
$rawmods = get_course_mods ( $courseid );
if ( empty ( $rawmods )) {
2008-01-24 20:33:50 +00:00
return $mod ; // always return array
2002-11-10 07:37:15 +00:00
}
2008-06-01 19:05:07 +00:00
if ( $sections = $DB -> get_records ( " course_sections " , array ( " course " => $courseid ), " section ASC " )) {
2002-11-10 07:37:15 +00:00
foreach ( $sections as $section ) {
2003-03-21 04:53:08 +00:00
if ( ! empty ( $section -> sequence )) {
2002-11-10 07:37:15 +00:00
$sequence = explode ( " , " , $section -> sequence );
foreach ( $sequence as $seq ) {
2003-01-14 14:56:57 +00:00
if ( empty ( $rawmods [ $seq ])) {
continue ;
}
2008-01-24 20:33:50 +00:00
$mod [ $seq ] -> id = $rawmods [ $seq ] -> instance ;
$mod [ $seq ] -> cm = $rawmods [ $seq ] -> id ;
$mod [ $seq ] -> mod = $rawmods [ $seq ] -> modname ;
2011-03-11 17:26:23 +00:00
// Oh dear. Inconsistent names left here for backward compatibility.
2008-01-24 20:33:50 +00:00
$mod [ $seq ] -> section = $section -> section ;
2011-03-11 17:26:23 +00:00
$mod [ $seq ] -> sectionid = $rawmods [ $seq ] -> section ;
$mod [ $seq ] -> module = $rawmods [ $seq ] -> module ;
$mod [ $seq ] -> added = $rawmods [ $seq ] -> added ;
$mod [ $seq ] -> score = $rawmods [ $seq ] -> score ;
2010-05-28 01:53:09 +00:00
$mod [ $seq ] -> idnumber = $rawmods [ $seq ] -> idnumber ;
2008-01-24 20:33:50 +00:00
$mod [ $seq ] -> visible = $rawmods [ $seq ] -> visible ;
2011-03-11 17:26:23 +00:00
$mod [ $seq ] -> visibleold = $rawmods [ $seq ] -> visibleold ;
2008-01-24 20:33:50 +00:00
$mod [ $seq ] -> groupmode = $rawmods [ $seq ] -> groupmode ;
$mod [ $seq ] -> groupingid = $rawmods [ $seq ] -> groupingid ;
2007-08-20 10:52:59 +00:00
$mod [ $seq ] -> groupmembersonly = $rawmods [ $seq ] -> groupmembersonly ;
2008-12-17 16:37:35 +00:00
$mod [ $seq ] -> indent = $rawmods [ $seq ] -> indent ;
$mod [ $seq ] -> completion = $rawmods [ $seq ] -> completion ;
2008-01-24 20:33:50 +00:00
$mod [ $seq ] -> extra = " " ;
2011-03-11 17:26:23 +00:00
$mod [ $seq ] -> completiongradeitemnumber =
$rawmods [ $seq ] -> completiongradeitemnumber ;
$mod [ $seq ] -> completionview = $rawmods [ $seq ] -> completionview ;
$mod [ $seq ] -> completionexpected = $rawmods [ $seq ] -> completionexpected ;
$mod [ $seq ] -> availablefrom = $rawmods [ $seq ] -> availablefrom ;
$mod [ $seq ] -> availableuntil = $rawmods [ $seq ] -> availableuntil ;
$mod [ $seq ] -> showavailability = $rawmods [ $seq ] -> showavailability ;
2011-07-20 17:24:55 +01:00
$mod [ $seq ] -> showdescription = $rawmods [ $seq ] -> showdescription ;
2011-03-11 17:26:23 +00:00
if ( ! empty ( $CFG -> enableavailability )) {
2008-12-17 16:37:35 +00:00
condition_info :: fill_availability_conditions ( $rawmods [ $seq ]);
$mod [ $seq ] -> conditionscompletion = $rawmods [ $seq ] -> conditionscompletion ;
$mod [ $seq ] -> conditionsgrade = $rawmods [ $seq ] -> conditionsgrade ;
}
2003-10-22 13:14:56 +00:00
$modname = $mod [ $seq ] -> mod ;
$functionname = $modname . " _get_coursemodule_info " ;
2008-04-30 12:24:54 +00:00
if ( ! file_exists ( " $CFG->dirroot /mod/ $modname /lib.php " )) {
continue ;
}
2003-10-22 13:14:56 +00:00
include_once ( " $CFG->dirroot /mod/ $modname /lib.php " );
2011-07-21 15:05:36 +01:00
if ( $hasfunction = function_exists ( $functionname )) {
2004-04-26 15:31:22 +00:00
if ( $info = $functionname ( $rawmods [ $seq ])) {
if ( ! empty ( $info -> icon )) {
$mod [ $seq ] -> icon = $info -> icon ;
}
2010-02-14 20:18:10 +00:00
if ( ! empty ( $info -> iconcomponent )) {
$mod [ $seq ] -> iconcomponent = $info -> iconcomponent ;
}
2008-02-01 08:15:38 +00:00
if ( ! empty ( $info -> name )) {
2010-02-14 20:18:10 +00:00
$mod [ $seq ] -> name = $info -> name ;
2008-02-01 08:15:38 +00:00
}
2011-01-26 10:29:16 +00:00
if ( $info instanceof cached_cm_info ) {
// When using cached_cm_info you can include three new fields
// that aren't available for legacy code
if ( ! empty ( $info -> content )) {
$mod [ $seq ] -> content = $info -> content ;
}
if ( ! empty ( $info -> extraclasses )) {
$mod [ $seq ] -> extraclasses = $info -> extraclasses ;
}
2011-11-07 17:42:56 +01:00
if ( ! empty ( $info -> iconurl )) {
$mod [ $seq ] -> iconurl = $info -> iconurl ;
}
2011-01-26 10:29:16 +00:00
if ( ! empty ( $info -> onclick )) {
$mod [ $seq ] -> onclick = $info -> onclick ;
}
if ( ! empty ( $info -> customdata )) {
$mod [ $seq ] -> customdata = $info -> customdata ;
}
} else {
// When using a stdclass, the (horrible) deprecated ->extra field
// is available for BC
if ( ! empty ( $info -> extra )) {
$mod [ $seq ] -> extra = $info -> extra ;
}
}
2003-09-14 12:25:16 +00:00
}
}
2011-07-21 15:05:36 +01:00
// When there is no modname_get_coursemodule_info function,
// but showdescriptions is enabled, then we use the 'intro'
// and 'introformat' fields in the module table
if ( ! $hasfunction && $rawmods [ $seq ] -> showdescription ) {
if ( $modvalues = $DB -> get_record ( $rawmods [ $seq ] -> modname ,
array ( 'id' => $rawmods [ $seq ] -> instance ), 'name, intro, introformat' )) {
// Set content from intro and introformat. Filters are disabled
// because we filter it with format_text at display time
$mod [ $seq ] -> content = format_module_intro ( $rawmods [ $seq ] -> modname ,
$modvalues , $rawmods [ $seq ] -> id , false );
// To save making another query just below, put name in here
$mod [ $seq ] -> name = $modvalues -> name ;
}
}
2008-02-01 08:15:38 +00:00
if ( ! isset ( $mod [ $seq ] -> name )) {
2010-02-14 20:18:10 +00:00
$mod [ $seq ] -> name = $DB -> get_field ( $rawmods [ $seq ] -> modname , " name " , array ( " id " => $rawmods [ $seq ] -> instance ));
2008-02-01 08:15:38 +00:00
}
2011-01-26 10:29:16 +00:00
// Minimise the database size by unsetting default options when they are
// 'empty'. This list corresponds to code in the cm_info constructor.
2011-07-20 17:24:55 +01:00
foreach ( array ( 'idnumber' , 'groupmode' , 'groupingid' , 'groupmembersonly' ,
2011-11-07 17:42:56 +01:00
'indent' , 'completion' , 'extra' , 'extraclasses' , 'iconurl' , 'onclick' , 'content' ,
2011-03-11 17:26:23 +00:00
'icon' , 'iconcomponent' , 'customdata' , 'showavailability' , 'availablefrom' ,
'availableuntil' , 'conditionscompletion' , 'conditionsgrade' ,
2011-07-20 17:24:55 +01:00
'completionview' , 'completionexpected' , 'score' , 'showdescription' )
as $property ) {
2011-01-26 10:29:16 +00:00
if ( property_exists ( $mod [ $seq ], $property ) &&
empty ( $mod [ $seq ] -> { $property })) {
unset ( $mod [ $seq ] -> { $property });
}
}
2011-03-11 17:26:23 +00:00
// Special case: this value is usually set to null, but may be 0
if ( property_exists ( $mod [ $seq ], 'completiongradeitemnumber' ) &&
is_null ( $mod [ $seq ] -> completiongradeitemnumber )) {
unset ( $mod [ $seq ] -> completiongradeitemnumber );
}
2002-11-10 07:37:15 +00:00
}
}
}
}
return $mod ;
}
2008-06-01 19:05:07 +00:00
/**
* Returns a number of useful structures for course displays
*/
2002-08-02 17:38:18 +00:00
function get_all_mods ( $courseid , & $mods , & $modnames , & $modnamesplural , & $modnamesused ) {
2010-04-11 09:05:48 +00:00
global $CFG , $DB , $COURSE ;
2002-07-23 16:24:12 +00:00
2008-01-24 20:33:50 +00:00
$mods = array (); // course modules indexed by id
$modnames = array (); // all course module names (except resource!)
$modnamesplural = array (); // all course module names (plural form)
$modnamesused = array (); // course module names used
2002-07-23 16:24:12 +00:00
2008-06-01 19:05:07 +00:00
if ( $allmods = $DB -> get_records ( " modules " )) {
2002-08-02 17:38:18 +00:00
foreach ( $allmods as $mod ) {
2010-04-11 09:05:48 +00:00
if ( ! file_exists ( " $CFG->dirroot /mod/ $mod->name /lib.php " )) {
continue ;
}
2003-05-09 17:24:17 +00:00
if ( $mod -> visible ) {
$modnames [ $mod -> name ] = get_string ( " modulename " , " $mod->name " );
$modnamesplural [ $mod -> name ] = get_string ( " modulenameplural " , " $mod->name " );
}
2002-08-02 17:38:18 +00:00
}
2011-08-10 12:56:04 +08:00
collatorlib :: asort ( $modnames );
2002-08-02 17:38:18 +00:00
} else {
2008-05-07 06:02:51 +00:00
print_error ( " nomodules " , 'debug' );
2002-08-02 17:38:18 +00:00
}
2008-12-17 16:37:35 +00:00
$course = ( $courseid == $COURSE -> id ) ? $COURSE : $DB -> get_record ( 'course' , array ( 'id' => $courseid ));
$modinfo = get_fast_modinfo ( $course );
if ( $rawmods = $modinfo -> cms ) {
2002-07-23 16:24:12 +00:00
foreach ( $rawmods as $mod ) { // Index the mods
2005-04-19 12:40:00 +00:00
if ( empty ( $modnames [ $mod -> modname ])) {
continue ;
}
2008-01-24 20:33:50 +00:00
$mods [ $mod -> id ] = $mod ;
$mods [ $mod -> id ] -> modfullname = $modnames [ $mod -> modname ];
if ( ! $mod -> visible and ! has_capability ( 'moodle/course:viewhiddenactivities' , get_context_instance ( CONTEXT_COURSE , $courseid ))) {
continue ;
}
2007-08-20 10:52:59 +00:00
// Check groupings
if ( ! groups_course_module_visible ( $mod )) {
continue ;
}
2008-01-24 20:33:50 +00:00
$modnamesused [ $mod -> modname ] = $modnames [ $mod -> modname ];
2002-07-23 16:24:12 +00:00
}
2003-04-22 20:46:12 +00:00
if ( $modnamesused ) {
2011-08-10 12:56:04 +08:00
collatorlib :: asort ( $modnamesused );
2003-04-22 20:46:12 +00:00
}
2002-07-23 16:24:12 +00:00
}
}
2010-06-08 06:21:25 +00:00
/**
* Returns an array of sections for the requested course id
*
* This function stores the sections against the course id within a staticvar encase
* of subsequent requests . This is used all over + in some standard libs and course
* format callbacks so subsequent requests are a reality .
*
* @ staticvar array $coursesections
* @ param int $courseid
* @ return array Array of sections
*/
2002-07-23 16:24:12 +00:00
function get_all_sections ( $courseid ) {
2008-06-01 19:05:07 +00:00
global $DB ;
2010-06-08 06:21:25 +00:00
static $coursesections = array ();
if ( ! array_key_exists ( $courseid , $coursesections )) {
$coursesections [ $courseid ] = $DB -> get_records ( " course_sections " , array ( " course " => " $courseid " ), " section " ,
" section, id, course, name, summary, summaryformat, sequence, visible " );
}
return $coursesections [ $courseid ];
2002-07-23 16:24:12 +00:00
}
2011-02-12 22:45:17 +01:00
/**
2011-02-12 23:06:11 +01:00
* Returns the course section to display or 0 meaning show all sections . Returns 0 for guests .
* It also sets the $USER -> display cache to array ( $courseid => return value )
*
2011-02-12 22:45:17 +01:00
* @ param int $courseid The course id
2011-02-12 23:06:11 +01:00
* @ return int Course section to display , 0 means all
2011-02-12 22:45:17 +01:00
*/
function course_get_display ( $courseid ) {
global $USER , $DB ;
if ( ! isloggedin () or isguestuser ()) {
//do not get settings in db for guests
return 0 ; //return the implicit setting
}
if ( ! isset ( $USER -> display [ $courseid ])) {
2011-02-12 23:06:11 +01:00
if ( ! $display = $DB -> get_field ( 'course_display' , 'display' , array ( 'userid' => $USER -> id , 'course' => $courseid ))) {
$display = 0 ; // all sections option is not stored in DB, this makes the table much smaller
2011-02-12 22:45:17 +01:00
}
2011-02-12 23:06:11 +01:00
//use display cache for one course only - we need to keep session small
$USER -> display = array ( $courseid => $display );
2011-02-12 22:45:17 +01:00
}
2011-02-12 23:06:11 +01:00
2011-02-12 22:45:17 +01:00
return $USER -> display [ $courseid ];
}
2011-02-12 23:06:11 +01:00
/**
* Show one section only or all sections .
*
* @ param int $courseid The course id
* @ param mixed $display show only this section , 0 or 'all' means show all sections
* @ return int Course section to display , 0 means all
*/
function course_set_display ( $courseid , $display ) {
2008-06-01 19:05:07 +00:00
global $USER , $DB ;
2003-04-28 13:29:26 +00:00
2011-02-12 23:06:11 +01:00
if ( $display === 'all' or empty ( $display )) {
2003-04-28 13:29:26 +00:00
$display = 0 ;
}
2010-03-31 07:41:31 +00:00
if ( ! isloggedin () or isguestuser ()) {
2006-12-04 09:02:17 +00:00
//do not store settings in db for guests
2011-02-12 23:06:11 +01:00
return 0 ;
}
if ( $display == 0 ) {
//show all, do not store anything in database
$DB -> delete_records ( 'course_display' , array ( 'userid' => $USER -> id , 'course' => $courseid ));
2003-04-28 13:29:26 +00:00
} else {
2011-02-12 23:06:11 +01:00
if ( $DB -> record_exists ( 'course_display' , array ( 'userid' => $USER -> id , 'course' => $courseid ))) {
$DB -> set_field ( 'course_display' , 'display' , $display , array ( 'userid' => $USER -> id , 'course' => $courseid ));
2011-02-12 22:45:17 +01:00
} else {
2011-02-12 23:06:11 +01:00
$record = new stdClass ();
$record -> userid = $USER -> id ;
$record -> course = $courseid ;
$record -> display = $display ;
$DB -> insert_record ( 'course_display' , $record );
2011-02-12 22:45:17 +01:00
}
2003-04-28 13:29:26 +00:00
}
2011-02-12 23:06:11 +01:00
//use display cache for one course only - we need to keep session small
$USER -> display = array ( $courseid => $display );
return $display ;
2003-04-28 13:29:26 +00:00
}
2008-06-01 19:05:07 +00:00
/**
2010-09-17 12:16:27 +00:00
* For a given course section , marks it visible or hidden ,
2008-06-01 19:05:07 +00:00
* and does the same for every activity in that section
*/
2003-05-04 07:59:46 +00:00
function set_section_visible ( $courseid , $sectionnumber , $visibility ) {
2008-06-01 19:05:07 +00:00
global $DB ;
2003-05-04 07:59:46 +00:00
2008-06-01 19:05:07 +00:00
if ( $section = $DB -> get_record ( " course_sections " , array ( " course " => $courseid , " section " => $sectionnumber ))) {
$DB -> set_field ( " course_sections " , " visible " , " $visibility " , array ( " id " => $section -> id ));
2003-05-04 07:59:46 +00:00
if ( ! empty ( $section -> sequence )) {
$modules = explode ( " , " , $section -> sequence );
foreach ( $modules as $moduleid ) {
2006-04-12 03:11:34 +00:00
set_coursemodule_visible ( $moduleid , $visibility , true );
2003-05-04 07:59:46 +00:00
}
}
2003-05-09 17:24:17 +00:00
rebuild_course_cache ( $courseid );
2003-05-04 07:59:46 +00:00
}
}
2002-09-09 11:48:11 +00:00
2011-01-26 10:29:16 +00:00
/**
* Obtains shared data that is used in print_section when displaying a
* course - module entry .
*
* Calls format_text or format_string as appropriate , and obtains the correct icon .
*
* This data is also used in other areas of the code .
* @ param cm_info $cm Course - module data ( must come from get_fast_modinfo )
* @ param object $course Moodle course object
* @ return array An array with the following values in this order :
* $content ( optional extra content for after link ),
* $instancename ( text of link )
*/
function get_print_section_cm_text ( cm_info $cm , $course ) {
global $OUTPUT ;
// Get content from modinfo if specified. Content displays either
// in addition to the standard link (below), or replaces it if
// the link is turned off by setting ->url to null.
if (( $content = $cm -> get_content ()) !== '' ) {
2011-09-06 15:10:57 +01:00
// Improve filter performance by preloading filter setttings for all
// activities on the course (this does nothing if called multiple
// times)
filter_preload_activities ( $cm -> get_modinfo ());
// Get module context
$modulecontext = get_context_instance ( CONTEXT_MODULE , $cm -> id );
2011-01-26 10:29:16 +00:00
$labelformatoptions = new stdClass ();
$labelformatoptions -> noclean = true ;
$labelformatoptions -> overflowdiv = true ;
2011-09-06 15:10:57 +01:00
$labelformatoptions -> context = $modulecontext ;
2011-01-26 10:29:16 +00:00
$content = format_text ( $content , FORMAT_HTML , $labelformatoptions );
} else {
$content = '' ;
}
2011-09-06 15:10:57 +01:00
// Get course context
$coursecontext = get_context_instance ( CONTEXT_COURSE , $course -> id );
2011-01-26 10:29:16 +00:00
$stringoptions = new stdClass ;
$stringoptions -> context = $coursecontext ;
$instancename = format_string ( $cm -> name , true , $stringoptions );
return array ( $content , $instancename );
}
2008-06-01 19:05:07 +00:00
/**
* Prints a section full of activity modules
*/
2008-07-28 12:31:29 +00:00
function print_section ( $course , $section , $mods , $modnamesused , $absolute = false , $width = " 100% " , $hidecompletion = false ) {
2009-07-02 12:07:58 +00:00
global $CFG , $USER , $DB , $PAGE , $OUTPUT ;
2003-07-14 13:08:38 +00:00
2008-01-24 20:33:50 +00:00
static $initialised ;
2004-01-31 08:40:38 +00:00
static $groupbuttons ;
2004-02-15 04:13:25 +00:00
static $groupbuttonslink ;
2003-07-12 06:52:26 +00:00
static $isediting ;
2003-07-14 13:08:38 +00:00
static $ismoving ;
static $strmovehere ;
static $strmovefull ;
2005-01-29 09:56:42 +00:00
static $strunreadpostsone ;
2008-01-24 20:33:50 +00:00
static $groupings ;
2011-01-26 10:29:16 +00:00
static $modulenames ;
2004-02-15 03:20:51 +00:00
2008-01-24 20:33:50 +00:00
if ( ! isset ( $initialised )) {
2004-08-12 11:23:47 +00:00
$groupbuttons = ( $course -> groupmode or ( ! $course -> groupmodeforce ));
2004-02-15 04:13:25 +00:00
$groupbuttonslink = ( ! $course -> groupmodeforce );
2009-05-06 08:59:29 +00:00
$isediting = $PAGE -> user_is_editing ();
2008-01-24 20:33:50 +00:00
$ismoving = $isediting && ismoving ( $course -> id );
2004-01-31 08:40:38 +00:00
if ( $ismoving ) {
2008-01-24 20:33:50 +00:00
$strmovehere = get_string ( " movehere " );
$strmovefull = strip_tags ( get_string ( " movefull " , " " , " ' $USER->activitycopyname ' " ));
2004-01-31 08:40:38 +00:00
}
2011-01-26 10:29:16 +00:00
$modulenames = array ();
2008-01-24 20:33:50 +00:00
$initialised = true ;
2003-07-14 13:08:38 +00:00
}
2008-01-24 20:33:50 +00:00
2011-01-26 10:29:16 +00:00
$tl = textlib_get_instance ();
2002-08-03 08:16:31 +00:00
2008-01-24 20:33:50 +00:00
$modinfo = get_fast_modinfo ( $course );
2009-07-15 14:19:24 +00:00
$completioninfo = new completion_info ( $course );
2002-08-03 08:16:31 +00:00
2010-09-17 12:16:27 +00:00
//Accessibility: replace table with list <ul>, but don't output empty list.
2003-03-21 04:53:08 +00:00
if ( ! empty ( $section -> sequence )) {
2002-08-03 08:16:31 +00:00
2006-04-13 16:07:12 +00:00
// Fix bug #5027, don't want style=\"width:$width\".
2007-09-25 15:15:07 +00:00
echo " <ul class= \" section img-text \" > \n " ;
2002-08-03 08:16:31 +00:00
$sectionmods = explode ( " , " , $section -> sequence );
foreach ( $sectionmods as $modnumber ) {
2003-01-13 14:11:05 +00:00
if ( empty ( $mods [ $modnumber ])) {
continue ;
}
2008-01-24 20:33:50 +00:00
2011-01-26 10:29:16 +00:00
/**
* @ var cm_info
*/
2002-08-03 08:16:31 +00:00
$mod = $mods [ $modnumber ];
2003-09-14 12:25:16 +00:00
2008-01-24 20:33:50 +00:00
if ( $ismoving and $mod -> id == $USER -> activitycopy ) {
// do not display moving mod
continue ;
}
2003-09-14 12:25:16 +00:00
2008-01-24 20:33:50 +00:00
if ( isset ( $modinfo -> cms [ $modnumber ])) {
2008-12-19 10:51:33 +00:00
// We can continue (because it will not be displayed at all)
// if:
// 1) The activity is not visible to users
// and
// 2a) The 'showavailability' option is not set (if that is set,
2009-08-07 07:18:01 +00:00
// we need to display the activity so we can show
2008-12-19 10:51:33 +00:00
// availability info)
// or
2009-08-07 07:18:01 +00:00
// 2b) The 'availableinfo' is empty, i.e. the activity was
// hidden in a way that leaves no info, such as using the
2008-12-19 10:51:33 +00:00
// eye icon.
2008-12-17 16:37:35 +00:00
if ( ! $modinfo -> cms [ $modnumber ] -> uservisible &&
2008-12-19 10:51:33 +00:00
( empty ( $modinfo -> cms [ $modnumber ] -> showavailability ) ||
empty ( $modinfo -> cms [ $modnumber ] -> availableinfo ))) {
2008-01-24 20:33:50 +00:00
// visibility shortcut
continue ;
2003-07-20 13:53:31 +00:00
}
2008-01-24 20:33:50 +00:00
} else {
2008-04-30 12:39:31 +00:00
if ( ! file_exists ( " $CFG->dirroot /mod/ $mod->modname /lib.php " )) {
// module not installed
continue ;
}
2008-12-17 16:37:35 +00:00
if ( ! coursemodule_visible_for_user ( $mod ) &&
empty ( $mod -> showavailability )) {
2008-01-24 20:33:50 +00:00
// full visibility check
continue ;
2004-04-26 15:31:22 +00:00
}
2008-01-24 20:33:50 +00:00
}
2011-01-26 10:29:16 +00:00
if ( ! isset ( $modulenames [ $mod -> modname ])) {
$modulenames [ $mod -> modname ] = get_string ( 'modulename' , $mod -> modname );
}
$modulename = $modulenames [ $mod -> modname ];
2009-08-07 07:18:01 +00:00
// In some cases the activity is visible to user, but it is
2009-04-17 11:07:59 +00:00
// dimmed. This is done if viewhiddenactivities is true and if:
// 1. the activity is not visible, or
// 2. the activity has dates set which do not include current, or
// 3. the activity has any other conditions set (regardless of whether
// current user meets them)
$canviewhidden = has_capability (
'moodle/course:viewhiddenactivities' ,
get_context_instance ( CONTEXT_MODULE , $mod -> id ));
$accessiblebutdim = false ;
if ( $canviewhidden ) {
$accessiblebutdim = ! $mod -> visible ;
if ( ! empty ( $CFG -> enableavailability )) {
$accessiblebutdim = $accessiblebutdim ||
$mod -> availablefrom > time () ||
( $mod -> availableuntil && $mod -> availableuntil < time ()) ||
2009-08-07 07:18:01 +00:00
count ( $mod -> conditionsgrade ) > 0 ||
2009-04-17 11:07:59 +00:00
count ( $mod -> conditionscompletion ) > 0 ;
}
}
2010-11-19 04:02:21 +00:00
$liclasses = array ();
$liclasses [] = 'activity' ;
$liclasses [] = $mod -> modname ;
$liclasses [] = 'modtype_' . $mod -> modname ;
2011-01-26 10:29:16 +00:00
$extraclasses = $mod -> get_extra_classes ();
if ( $extraclasses ) {
$liclasses = array_merge ( $liclasses , explode ( ' ' , $extraclasses ));
}
2010-11-19 04:02:21 +00:00
echo html_writer :: start_tag ( 'li' , array ( 'class' => join ( ' ' , $liclasses ), 'id' => 'module-' . $modnumber ));
2008-01-24 20:33:50 +00:00
if ( $ismoving ) {
echo '<a title="' . $strmovefull . '"' .
2009-01-02 10:36:25 +00:00
' href="' . $CFG -> wwwroot . '/course/mod.php?moveto=' . $mod -> id . '&sesskey=' . sesskey () . '">' .
2009-12-16 21:50:45 +00:00
'<img class="movetarget" src="' . $OUTPUT -> pix_url ( 'movehere' ) . '" ' .
2008-01-24 20:33:50 +00:00
' alt="' . $strmovehere . ' " /></a><br />
' ;
}
2004-04-26 15:31:22 +00:00
2010-11-19 04:02:21 +00:00
$classes = array ( 'mod-indent' );
if ( ! empty ( $mod -> indent )) {
$classes [] = 'mod-indent-' . $mod -> indent ;
if ( $mod -> indent > 15 ) {
$classes [] = 'mod-indent-huge' ;
}
2008-01-24 20:33:50 +00:00
}
2010-11-19 04:02:21 +00:00
echo html_writer :: start_tag ( 'div' , array ( 'class' => join ( ' ' , $classes )));
2008-01-24 20:33:50 +00:00
2011-01-26 10:29:16 +00:00
// Get data about this course-module
list ( $content , $instancename ) =
get_print_section_cm_text ( $modinfo -> cms [ $modnumber ], $course );
//Accessibility: for files get description via icon, this is very ugly hack!
$altname = '' ;
$altname = $mod -> modfullname ;
if ( ! empty ( $customicon )) {
$archetype = plugin_supports ( 'mod' , $mod -> modname , FEATURE_MOD_ARCHETYPE , MOD_ARCHETYPE_OTHER );
if ( $archetype == MOD_ARCHETYPE_RESOURCE ) {
$mimetype = mimeinfo_from_icon ( 'type' , $customicon );
$altname = get_mimetype_description ( $mimetype );
}
}
// Avoid unnecessary duplication: if e.g. a forum name already
// includes the word forum (or Forum, etc) then it is unhelpful
// to include that in the accessible description that is added.
if ( false !== strpos ( $tl -> strtolower ( $instancename ),
$tl -> strtolower ( $altname ))) {
$altname = '' ;
}
// File type after name, for alphabetic lists (screen reader).
if ( $altname ) {
$altname = get_accesshide ( ' ' . $altname );
2008-07-10 08:50:43 +00:00
}
2008-01-24 20:33:50 +00:00
2011-01-26 10:29:16 +00:00
// We may be displaying this just in order to show information
// about visibility, without the actual link
$contentpart = '' ;
if ( $mod -> uservisible ) {
// Nope - in this case the link is fully working for user
$linkclasses = '' ;
$textclasses = '' ;
if ( $accessiblebutdim ) {
$linkclasses .= ' dimmed' ;
$textclasses .= ' dimmed_text' ;
$accesstext = '<span class="accesshide">' .
get_string ( 'hiddenfromstudents' ) . ': </span>' ;
2010-06-02 02:20:17 +00:00
} else {
2011-01-26 10:29:16 +00:00
$accesstext = '' ;
2008-01-24 20:33:50 +00:00
}
2011-01-26 10:29:16 +00:00
if ( $linkclasses ) {
$linkcss = 'class="' . trim ( $linkclasses ) . '" ' ;
} else {
$linkcss = '' ;
}
if ( $textclasses ) {
$textcss = 'class="' . trim ( $textclasses ) . '" ' ;
} else {
$textcss = '' ;
2008-02-24 10:32:59 +00:00
}
2003-09-14 16:31:33 +00:00
2011-01-26 10:29:16 +00:00
// Get on-click attribute value if specified
$onclick = $mod -> get_on_click ();
if ( $onclick ) {
$onclick = ' onclick="' . $onclick . '"' ;
}
2003-09-14 12:25:16 +00:00
2011-01-26 10:29:16 +00:00
if ( $url = $mod -> get_url ()) {
// Display link itself
echo '<a ' . $linkcss . $mod -> extra . $onclick .
' href="' . $url . '"><img src="' . $mod -> get_icon_url () .
'" class="activityicon" alt="' .
$modulename . '" /> ' .
$accesstext . '<span class="instancename">' .
$instancename . $altname . '</span></a>' ;
// If specified, display extra content after link
if ( $content ) {
$contentpart = '<div class="contentafterlink' .
trim ( $textclasses ) . '">' . $content . '</div>' ;
2009-04-03 01:13:42 +00:00
}
2008-01-24 20:33:50 +00:00
} else {
2011-01-26 10:29:16 +00:00
// No link, so display only content
$contentpart = '<div ' . $textcss . $mod -> extra . '>' .
$accesstext . $content . '</div>' ;
2008-01-24 20:33:50 +00:00
}
2007-09-24 17:26:40 +00:00
2011-01-26 10:29:16 +00:00
if ( ! empty ( $mod -> groupingid ) && has_capability ( 'moodle/course:managegroups' , get_context_instance ( CONTEXT_COURSE , $course -> id ))) {
if ( ! isset ( $groupings )) {
$groupings = groups_get_all_groupings ( $course -> id );
2007-09-25 15:15:07 +00:00
}
2011-01-26 10:29:16 +00:00
echo " <span class= \" groupinglabel \" >( " . format_string ( $groupings [ $mod -> groupingid ] -> name ) . ')</span>' ;
2008-01-24 20:33:50 +00:00
}
2011-01-26 10:29:16 +00:00
} else {
$textclasses = $extraclasses ;
$textclasses .= ' dimmed_text' ;
if ( $textclasses ) {
$textcss = 'class="' . trim ( $textclasses ) . '" ' ;
} else {
$textcss = '' ;
2008-01-24 20:33:50 +00:00
}
2011-01-26 10:29:16 +00:00
$accesstext = '<span class="accesshide">' .
get_string ( 'notavailableyet' , 'condition' ) .
': </span>' ;
2007-09-25 15:15:07 +00:00
2011-01-26 10:29:16 +00:00
if ( $url = $mod -> get_url ()) {
2008-12-17 16:37:35 +00:00
// Display greyed-out text of link
2011-01-26 10:29:16 +00:00
echo '<div ' . $textcss . $mod -> extra .
' >' . '<img src="' . $mod -> get_icon_url () .
'" class="activityicon" alt="' .
$modulename .
'" /> <span>' . $instancename . $altname .
'</span></div>' ;
// Do not display content after link when it is greyed out like this.
} else {
// No link, so display only content (also greyed)
$contentpart = '<div ' . $textcss . $mod -> extra . '>' .
$accesstext . $content . '</div>' ;
2005-01-29 09:49:42 +00:00
}
2008-01-24 20:33:50 +00:00
}
2005-01-29 09:49:42 +00:00
2011-01-26 10:29:16 +00:00
// Module can put text after the link (e.g. forum unread)
echo $mod -> get_after_link ();
2011-04-14 17:28:53 +01:00
// If there is content but NO link (eg label), then display the
// content here (BEFORE any icons). In this case cons must be
// displayed after the content so that it makes more sense visually
// and for accessibility reasons, e.g. if you have a one-line label
// it should work similarly (at least in terms of ordering) to an
// activity.
if ( empty ( $url )) {
echo $contentpart ;
}
2008-01-24 20:33:50 +00:00
if ( $isediting ) {
2010-07-25 18:04:36 +00:00
if ( $groupbuttons and plugin_supports ( 'mod' , $mod -> modname , FEATURE_GROUPS , 0 )) {
2008-01-24 20:33:50 +00:00
if ( ! $mod -> groupmodelink = $groupbuttonslink ) {
$mod -> groupmode = $course -> groupmode ;
2004-01-31 08:40:38 +00:00
}
2008-01-24 20:33:50 +00:00
} else {
$mod -> groupmode = false ;
2003-09-14 12:25:16 +00:00
}
2008-01-24 20:33:50 +00:00
echo ' ' ;
echo make_editing_buttons ( $mod , $absolute , true , $mod -> indent , $section -> section );
2011-01-26 10:29:16 +00:00
echo $mod -> get_after_edit_icons ();
2002-08-03 08:16:31 +00:00
}
2008-07-28 12:31:29 +00:00
// Completion
2009-04-17 10:22:56 +00:00
$completion = $hidecompletion
2008-07-28 12:31:29 +00:00
? COMPLETION_TRACKING_NONE
: $completioninfo -> is_enabled ( $mod );
2009-08-07 07:18:01 +00:00
if ( $completion != COMPLETION_TRACKING_NONE && isloggedin () &&
2008-12-17 16:37:35 +00:00
! isguestuser () && $mod -> uservisible ) {
2009-04-17 10:22:56 +00:00
$completiondata = $completioninfo -> get_data ( $mod , true );
$completionicon = '' ;
if ( $isediting ) {
switch ( $completion ) {
2008-10-08 12:22:04 +00:00
case COMPLETION_TRACKING_MANUAL :
2009-04-17 10:22:56 +00:00
$completionicon = 'manual-enabled' ; break ;
2008-10-08 12:22:04 +00:00
case COMPLETION_TRACKING_AUTOMATIC :
2009-04-17 10:22:56 +00:00
$completionicon = 'auto-enabled' ; break ;
2008-07-28 12:31:29 +00:00
default : // wtf
}
2009-04-17 10:22:56 +00:00
} else if ( $completion == COMPLETION_TRACKING_MANUAL ) {
2008-07-28 12:31:29 +00:00
switch ( $completiondata -> completionstate ) {
case COMPLETION_INCOMPLETE :
2009-04-17 10:22:56 +00:00
$completionicon = 'manual-n' ; break ;
2008-07-28 12:31:29 +00:00
case COMPLETION_COMPLETE :
2009-04-17 10:22:56 +00:00
$completionicon = 'manual-y' ; break ;
2008-07-28 12:31:29 +00:00
}
} else { // Automatic
switch ( $completiondata -> completionstate ) {
case COMPLETION_INCOMPLETE :
2009-04-17 10:22:56 +00:00
$completionicon = 'auto-n' ; break ;
2008-07-28 12:31:29 +00:00
case COMPLETION_COMPLETE :
2009-04-17 10:22:56 +00:00
$completionicon = 'auto-y' ; break ;
2008-07-28 12:31:29 +00:00
case COMPLETION_COMPLETE_PASS :
2009-04-17 10:22:56 +00:00
$completionicon = 'auto-pass' ; break ;
2008-07-28 12:31:29 +00:00
case COMPLETION_COMPLETE_FAIL :
2009-04-17 10:22:56 +00:00
$completionicon = 'auto-fail' ; break ;
2008-07-28 12:31:29 +00:00
}
}
2009-04-17 10:22:56 +00:00
if ( $completionicon ) {
2009-12-16 21:50:45 +00:00
$imgsrc = $OUTPUT -> pix_url ( 'i/completion-' . $completionicon );
2010-02-04 22:41:49 +00:00
$imgalt = s ( get_string ( 'completion-alt-' . $completionicon , 'completion' ));
if ( $completion == COMPLETION_TRACKING_MANUAL && ! $isediting ) {
$imgtitle = s ( get_string ( 'completion-title-' . $completionicon , 'completion' ));
2009-04-17 10:22:56 +00:00
$newstate =
2008-07-28 12:31:29 +00:00
$completiondata -> completionstate == COMPLETION_COMPLETE
2008-10-08 12:22:04 +00:00
? COMPLETION_INCOMPLETE
: COMPLETION_COMPLETE ;
2009-01-15 17:09:02 +00:00
// In manual mode the icon is a toggle form...
// If this completion state is used by the
// conditional activities system, we need to turn
// off the JS.
2009-08-07 07:18:01 +00:00
if ( ! empty ( $CFG -> enableavailability ) &&
2010-02-04 22:41:49 +00:00
condition_info :: completion_value_used_as_condition ( $course , $mod )) {
2009-01-15 17:09:02 +00:00
$extraclass = ' preventjs' ;
} else {
$extraclass = '' ;
}
2008-07-28 12:31:29 +00:00
echo "
2011-03-25 11:57:41 +00:00
< form class = 'togglecompletion$extraclass' method = 'post' action = '".$CFG->wwwroot."/course/togglecompletion.php' >< div >
2008-07-28 12:31:29 +00:00
< input type = 'hidden' name = 'id' value = '{$mod->id}' />
2010-02-03 17:50:26 +00:00
< input type = 'hidden' name = 'sesskey' value = '".sesskey()."' />
2008-07-28 12:31:29 +00:00
< input type = 'hidden' name = 'completionstate' value = '$newstate' />
< input type = 'image' src = '$imgsrc' alt = '$imgalt' title = '$imgtitle' />
</ div ></ form > " ;
} else {
// In auto mode, or when editing, the icon is just an image
2008-08-22 11:51:24 +00:00
echo " <span class='autocompletion'> " ;
echo " <img src=' $imgsrc ' alt=' $imgalt ' title=' $imgalt ' /></span> " ;
2008-07-28 12:31:29 +00:00
}
}
}
2011-04-14 17:28:53 +01:00
// If there is content AND a link, then display the content here
// (AFTER any icons). Otherwise it was displayed before
if ( ! empty ( $url )) {
echo $contentpart ;
}
2011-01-26 10:29:16 +00:00
2009-08-07 07:18:01 +00:00
// Show availability information (for someone who isn't allowed to
2008-12-17 16:37:35 +00:00
// see the activity itself, or for staff)
2009-04-17 10:22:56 +00:00
if ( ! $mod -> uservisible ) {
2008-12-17 16:37:35 +00:00
echo '<div class="availabilityinfo">' . $mod -> availableinfo . '</div>' ;
2009-04-17 11:07:59 +00:00
} else if ( $canviewhidden && ! empty ( $CFG -> enableavailability )) {
2008-12-17 16:37:35 +00:00
$ci = new condition_info ( $mod );
2009-04-17 10:22:56 +00:00
$fullinfo = $ci -> get_full_information ();
2008-12-17 16:37:35 +00:00
if ( $fullinfo ) {
2009-08-07 07:18:01 +00:00
echo '<div class="availabilityinfo">' . get_string ( $mod -> showavailability
2008-12-17 16:37:35 +00:00
? 'userrestriction_visible'
: 'userrestriction_hidden' , 'condition' ,
$fullinfo ) . '</div>' ;
}
}
2010-11-19 04:02:21 +00:00
echo html_writer :: end_tag ( 'div' );
echo html_writer :: end_tag ( 'li' ) . " \n " ;
2002-08-03 08:16:31 +00:00
}
2008-01-24 20:33:50 +00:00
2006-04-13 16:07:12 +00:00
} elseif ( $ismoving ) {
echo " <ul class= \" section \" > \n " ;
2006-11-09 18:25:58 +00:00
}
2008-01-24 20:33:50 +00:00
2003-07-14 13:08:38 +00:00
if ( $ismoving ) {
2006-04-13 09:44:33 +00:00
echo '<li><a title="' . $strmovefull . '"' .
2009-01-02 10:36:25 +00:00
' href="' . $CFG -> wwwroot . '/course/mod.php?movetosection=' . $section -> id . '&sesskey=' . sesskey () . '">' .
2009-12-16 21:50:45 +00:00
'<img class="movetarget" src="' . $OUTPUT -> pix_url ( 'movehere' ) . '" ' .
2006-03-27 16:21:56 +00:00
' alt="' . $strmovehere . ' " /></a></li>
2004-09-08 19:24:38 +00:00
' ;
2003-07-14 13:08:38 +00:00
}
2006-03-27 16:21:56 +00:00
if ( ! empty ( $section -> sequence ) || $ismoving ) {
echo " </ul><!--class='section'--> \n \n " ;
}
2002-08-04 13:25:53 +00:00
}
2007-01-02 09:33:07 +00:00
/**
* Prints the menus to add activities and resources .
*/
2004-07-26 16:05:09 +00:00
function print_section_add_menus ( $course , $section , $modnames , $vertical = false , $return = false ) {
2009-08-08 09:31:01 +00:00
global $CFG , $OUTPUT ;
2004-07-25 14:00:29 +00:00
2007-02-16 07:57:19 +00:00
// check to see if user can add menus
if ( ! has_capability ( 'moodle/course:manageactivities' , get_context_instance ( CONTEXT_COURSE , $course -> id ))) {
2007-02-23 06:03:09 +00:00
return false ;
2007-02-16 07:57:19 +00:00
}
2010-02-10 11:25:17 +00:00
$urlbase = " /course/mod.php?id= $course->id §ion= $section &sesskey= " . sesskey () . '&add=' ;
2010-03-20 14:44:35 +00:00
$resources = array ();
$activities = array ();
2004-08-02 19:11:15 +00:00
2010-03-20 14:44:35 +00:00
foreach ( $modnames as $modname => $modnamestr ) {
if ( ! course_allowed_module ( $course , $modname )) {
continue ;
}
2004-08-02 19:11:15 +00:00
2010-03-20 14:44:35 +00:00
$libfile = " $CFG->dirroot /mod/ $modname /lib.php " ;
if ( ! file_exists ( $libfile )) {
continue ;
}
include_once ( $libfile );
$gettypesfunc = $modname . '_get_types' ;
if ( function_exists ( $gettypesfunc )) {
// NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
if ( $types = $gettypesfunc ()) {
$menu = array ();
$atype = null ;
$groupname = null ;
foreach ( $types as $type ) {
2010-02-10 11:25:17 +00:00
if ( $type -> typestr === '--' ) {
2010-03-20 14:44:35 +00:00
continue ;
2008-02-13 17:03:25 +00:00
}
2010-03-20 14:44:35 +00:00
if ( strpos ( $type -> typestr , '--' ) === 0 ) {
$groupname = str_replace ( '--' , '' , $type -> typestr );
continue ;
2007-01-02 09:33:07 +00:00
}
2010-03-20 14:44:35 +00:00
$type -> type = str_replace ( '&' , '&' , $type -> type );
if ( $type -> modclass == MOD_CLASS_RESOURCE ) {
$atype = MOD_CLASS_RESOURCE ;
}
$menu [ $urlbase . $type -> type ] = $type -> typestr ;
2007-01-02 09:33:07 +00:00
}
2010-03-20 14:44:35 +00:00
if ( ! is_null ( $groupname )) {
if ( $atype == MOD_CLASS_RESOURCE ) {
$resources [] = array ( $groupname => $menu );
} else {
$activities [] = array ( $groupname => $menu );
}
2009-08-13 20:45:50 +00:00
} else {
2010-03-20 14:44:35 +00:00
if ( $atype == MOD_CLASS_RESOURCE ) {
$resources = array_merge ( $resources , $menu );
} else {
$activities = array_merge ( $activities , $menu );
}
2009-08-13 20:45:50 +00:00
}
2007-01-02 09:33:07 +00:00
}
2010-03-20 14:44:35 +00:00
} else {
$archetype = plugin_supports ( 'mod' , $modname , FEATURE_MOD_ARCHETYPE , MOD_ARCHETYPE_OTHER );
if ( $archetype == MOD_ARCHETYPE_RESOURCE ) {
$resources [ $urlbase . $modname ] = $modnamestr ;
} else {
// all other archetypes are considered activity
$activities [ $urlbase . $modname ] = $modnamestr ;
}
2005-08-16 06:15:49 +00:00
}
2004-07-25 14:00:29 +00:00
}
2007-01-02 09:33:07 +00:00
$straddactivity = get_string ( 'addactivity' );
$straddresource = get_string ( 'addresource' );
2007-01-04 12:44:58 +00:00
$output = '<div class="section_add_menus">' ;
if ( ! $vertical ) {
$output .= '<div class="horizontal">' ;
}
2009-08-10 03:35:14 +00:00
2007-01-02 09:33:07 +00:00
if ( ! empty ( $resources )) {
2010-02-10 11:25:17 +00:00
$select = new url_select ( $resources , '' , array ( '' => $straddresource ), " ressection $section " );
2010-04-14 08:54:17 +00:00
$select -> set_help_icon ( 'resources' );
2010-02-10 11:25:17 +00:00
$output .= $OUTPUT -> render ( $select );
2005-08-16 06:15:49 +00:00
}
2004-07-26 16:05:09 +00:00
2007-01-02 09:33:07 +00:00
if ( ! empty ( $activities )) {
2010-02-10 11:25:17 +00:00
$select = new url_select ( $activities , '' , array ( '' => $straddactivity ), " section $section " );
2010-04-14 08:54:17 +00:00
$select -> set_help_icon ( 'activities' );
2010-02-10 11:25:17 +00:00
$output .= $OUTPUT -> render ( $select );
2005-08-16 06:15:49 +00:00
}
2007-01-04 12:44:58 +00:00
if ( ! $vertical ) {
2005-05-10 00:31:32 +00:00
$output .= '</div>' ;
}
2004-07-26 16:05:09 +00:00
$output .= '</div>' ;
if ( $return ) {
return $output ;
} else {
echo $output ;
}
2004-07-25 14:00:29 +00:00
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
/**
* Return the course category context for the category with id $categoryid , except
* that if $categoryid is 0 , return the system context .
*
* @ param integer $categoryid a category id or 0.
* @ return object the corresponding context
*/
function get_category_or_system_context ( $categoryid ) {
if ( $categoryid ) {
return get_context_instance ( CONTEXT_COURSECAT , $categoryid );
} else {
return get_context_instance ( CONTEXT_SYSTEM );
}
}
2008-06-01 19:05:07 +00:00
/**
2010-09-17 12:16:27 +00:00
* Gets the child categories of a given courses category . Uses a static cache
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
* to make repeat calls efficient .
*
2010-09-17 12:04:48 +00:00
* @ param int $parentid the id of a course category .
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
* @ return array all the child course categories .
2008-06-01 19:05:07 +00:00
*/
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
function get_child_categories ( $parentid ) {
2007-12-17 04:49:27 +00:00
static $allcategories = null ;
// only fill in this variable the first time
if ( null == $allcategories ) {
$allcategories = array ();
$categories = get_categories ();
foreach ( $categories as $category ) {
if ( empty ( $allcategories [ $category -> parent ])) {
$allcategories [ $category -> parent ] = array ();
}
$allcategories [ $category -> parent ][] = $category ;
}
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( empty ( $allcategories [ $parentid ])) {
2007-12-17 04:49:27 +00:00
return array ();
} else {
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
return $allcategories [ $parentid ];
2007-12-17 04:49:27 +00:00
}
}
2008-06-01 19:05:07 +00:00
/**
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
* This function recursively travels the categories , building up a nice list
* for display . It also makes an array that list all the parents for each
* category .
*
* For example , if you have a tree of categories like :
* Miscellaneous ( id = 1 )
* Subcategory ( id = 2 )
* Sub - subcategory ( id = 4 )
* Other category ( id = 3 )
* Then after calling this function you will have
* $list = array ( 1 => 'Miscellaneous' , 2 => 'Miscellaneous / Subcategory' ,
* 4 => 'Miscellaneous / Subcategory / Sub-subcategory' ,
* 3 => 'Other category' );
* $parents = array ( 2 => array ( 1 ), 4 => array ( 1 , 2 ));
*
* If you specify $requiredcapability , then only categories where the current
* user has that capability will be added to $list , although all categories
* will still be added to $parents , and if you only have $requiredcapability
* in a child category , not the parent , then the child catgegory will still be
* included .
*
* If you specify the option $excluded , then that category , and all its children ,
* are omitted from the tree . This is useful when you are doing something like
* moving categories , where you do not want to allow people to move a category
* to be the child of itself .
*
* @ param array $list For output , accumulates an array categoryid => full category path name
* @ param array $parents For output , accumulates an array categoryid => list of parent category ids .
2008-12-08 07:28:19 +00:00
* @ param string / array $requiredcapability if given , only categories where the current
* user has this capability will be added to $list . Can also be an array of capabilities ,
* in which case they are all required .
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
* @ param integer $excludeid Omit this category and its children from the lists built .
* @ param object $category Build the tree starting at this category - otherwise starts at the top level .
* @ param string $path For internal use , as part of recursive calls .
2008-06-01 19:05:07 +00:00
*/
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
function make_categories_list ( & $list , & $parents , $requiredcapability = '' ,
$excludeid = 0 , $category = NULL , $path = " " ) {
2005-09-06 22:29:16 +00:00
// initialize the arrays if needed
if ( ! is_array ( $list )) {
2006-11-09 18:25:58 +00:00
$list = array ();
2005-09-06 22:29:16 +00:00
}
if ( ! is_array ( $parents )) {
2006-11-09 18:25:58 +00:00
$parents = array ();
2005-09-06 22:29:16 +00:00
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( empty ( $category )) {
// Start at the top level.
$category = new stdClass ;
$category -> id = 0 ;
} else {
// This is the excluded category, don't include it.
if ( $excludeid > 0 && $excludeid == $category -> id ) {
return ;
}
2011-08-30 17:48:46 +12:00
$context = get_context_instance ( CONTEXT_COURSECAT , $category -> id );
$categoryname = format_string ( $category -> name , true , array ( 'context' => $context ));
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
// Update $path.
2003-07-30 13:02:45 +00:00
if ( $path ) {
2011-08-30 17:48:46 +12:00
$path = $path . ' / ' . $categoryname ;
2003-07-30 13:02:45 +00:00
} else {
2011-08-30 17:48:46 +12:00
$path = $categoryname ;
2003-07-30 13:02:45 +00:00
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
// Add this category to $list, if the permissions check out.
2008-12-09 16:25:38 +00:00
if ( empty ( $requiredcapability )) {
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
$list [ $category -> id ] = $path ;
2008-12-09 16:25:38 +00:00
} else {
$requiredcapability = ( array ) $requiredcapability ;
2011-08-30 17:48:46 +12:00
if ( has_all_capabilities ( $requiredcapability , $context )) {
2008-12-09 16:25:38 +00:00
$list [ $category -> id ] = $path ;
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
}
2003-07-30 13:02:45 +00:00
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
// Add all the children recursively, while updating the parents array.
if ( $categories = get_child_categories ( $category -> id )) {
2003-07-30 13:02:45 +00:00
foreach ( $categories as $cat ) {
if ( ! empty ( $category -> id )) {
2003-09-20 17:33:55 +00:00
if ( isset ( $parents [ $category -> id ])) {
2003-09-20 17:08:45 +00:00
$parents [ $cat -> id ] = $parents [ $category -> id ];
}
2003-07-30 13:02:45 +00:00
$parents [ $cat -> id ][] = $category -> id ;
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
make_categories_list ( $list , $parents , $requiredcapability , $excludeid , $cat , $path );
2003-07-30 13:02:45 +00:00
}
}
}
2010-05-27 01:40:11 +00:00
/**
* This function generates a structured array of courses and categories .
*
* The depth of categories is limited by $CFG -> maxcategorydepth however there
* is no limit on the number of courses !
*
* Suitable for use with the course renderers course_category_tree method :
* $renderer = $PAGE -> get_renderer ( 'core' , 'course' );
* echo $renderer -> course_category_tree ( get_course_category_tree ());
*
* @ global moodle_database $DB
* @ param int $id
* @ param int $depth
*/
function get_course_category_tree ( $id = 0 , $depth = 0 ) {
2010-09-17 12:09:38 +00:00
global $DB , $CFG ;
2010-05-27 01:40:11 +00:00
$viewhiddencats = has_capability ( 'moodle/category:viewhiddencategories' , get_context_instance ( CONTEXT_SYSTEM ));
$categories = get_child_categories ( $id );
$categoryids = array ();
foreach ( $categories as $key => & $category ) {
if ( ! $category -> visible && ! $viewhiddencats ) {
unset ( $categories [ $key ]);
continue ;
}
$categoryids [ $category -> id ] = $category ;
if ( empty ( $CFG -> maxcategorydepth ) || $depth <= $CFG -> maxcategorydepth ) {
list ( $category -> categories , $subcategories ) = get_course_category_tree ( $category -> id , $depth + 1 );
2010-06-03 06:11:39 +00:00
foreach ( $subcategories as $subid => $subcat ) {
$categoryids [ $subid ] = $subcat ;
}
2010-05-27 01:40:11 +00:00
$category -> courses = array ();
}
}
if ( $depth > 0 ) {
// This is a recursive call so return the required array
return array ( $categories , $categoryids );
}
// The depth is 0 this function has just been called so we can finish it off
list ( $ccselect , $ccjoin ) = context_instance_preload_sql ( 'c.id' , CONTEXT_COURSE , 'ctx' );
list ( $catsql , $catparams ) = $DB -> get_in_or_equal ( array_keys ( $categoryids ));
$sql = " SELECT
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
c . id , c . sortorder , c . visible , c . fullname , c . shortname , c . summary , c . category
2010-05-27 01:40:11 +00:00
$ccselect
FROM { course } c
$ccjoin
WHERE c . category $catsql ORDER BY c . sortorder ASC " ;
if ( $courses = $DB -> get_records_sql ( $sql , $catparams )) {
// loop throught them
foreach ( $courses as $course ) {
if ( $course -> id == SITEID ) {
continue ;
}
context_instance_preload ( $course );
if ( ! empty ( $course -> visible ) || has_capability ( 'moodle/course:viewhiddencourses' , get_context_instance ( CONTEXT_COURSE , $course -> id ))) {
$categoryids [ $course -> category ] -> courses [ $course -> id ] = $course ;
}
}
}
return $categories ;
}
2003-07-30 13:02:45 +00:00
2008-06-01 19:05:07 +00:00
/**
* Recursive function to print out all the categories in a nice format
* with or without courses included
*/
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
function print_whole_category_list ( $category = NULL , $displaylist = NULL , $parentslist = NULL , $depth =- 1 , $showcourses = true ) {
2004-04-05 03:13:10 +00:00
global $CFG ;
2005-01-11 07:56:45 +00:00
2009-01-14 04:48:22 +00:00
// maxcategorydepth == 0 meant no limit
if ( ! empty ( $CFG -> maxcategorydepth ) && $depth >= $CFG -> maxcategorydepth ) {
2005-01-11 07:56:45 +00:00
return ;
2004-04-05 03:13:10 +00:00
}
2003-07-30 13:02:45 +00:00
if ( ! $displaylist ) {
2003-07-31 12:23:49 +00:00
make_categories_list ( $displaylist , $parentslist );
2003-07-30 13:02:45 +00:00
}
if ( $category ) {
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( $category -> visible or has_capability ( 'moodle/category:viewhiddencategories' , get_context_instance ( CONTEXT_SYSTEM ))) {
print_category_info ( $category , $depth , $showcourses );
2003-07-30 13:02:45 +00:00
} else {
return ; // Don't bother printing children of invisible categories
}
2004-05-28 10:53:54 +00:00
2003-07-30 13:02:45 +00:00
} else {
$category -> id = " 0 " ;
}
2007-12-17 04:49:27 +00:00
if ( $categories = get_child_categories ( $category -> id )) { // Print all the children recursively
2003-07-30 13:02:45 +00:00
$countcats = count ( $categories );
$count = 0 ;
$first = true ;
$last = false ;
foreach ( $categories as $cat ) {
$count ++ ;
if ( $count == $countcats ) {
$last = true ;
}
$up = $first ? false : true ;
$down = $last ? false : true ;
$first = false ;
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
print_whole_category_list ( $cat , $displaylist , $parentslist , $depth + 1 , $showcourses );
2003-07-30 13:02:45 +00:00
}
}
}
2008-06-01 19:05:07 +00:00
/**
2010-02-11 09:28:14 +00:00
* This function will return $options array for html_writer :: select (), with whitespace to denote nesting .
2008-06-01 19:05:07 +00:00
*/
2005-08-16 06:15:49 +00:00
function make_categories_options () {
make_categories_list ( $cats , $parents );
foreach ( $cats as $key => $value ) {
if ( array_key_exists ( $key , $parents )) {
if ( $indent = count ( $parents [ $key ])) {
for ( $i = 0 ; $i < $indent ; $i ++ ) {
$cats [ $key ] = ' ' . $cats [ $key ];
}
}
}
}
return $cats ;
}
2003-07-30 13:02:45 +00:00
2011-10-10 13:50:01 +01:00
/**
* Gets the name of a course to be displayed when showing a list of courses .
* By default this is just $course -> fullname but user can configure it . The
* result of this function should be passed through print_string .
* @ param object $course Moodle course object
* @ return string Display name of course ( either fullname or short + fullname )
*/
function get_course_display_name_for_list ( $course ) {
global $CFG ;
if ( ! empty ( $CFG -> courselistshortnames )) {
return $course -> shortname . ' ' . $course -> fullname ;
} else {
return $course -> fullname ;
}
}
2008-06-01 19:05:07 +00:00
/**
* Prints the category info in indented fashion
* This function is only used by print_whole_category_list () above
*/
2010-09-17 08:49:19 +00:00
function print_category_info ( $category , $depth = 0 , $showcourses = false ) {
2009-07-02 10:53:31 +00:00
global $CFG , $DB , $OUTPUT ;
2003-07-30 13:02:45 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$strsummary = get_string ( 'summary' );
2002-09-09 11:48:11 +00:00
2010-07-26 05:43:10 +00:00
$catlinkcss = null ;
if ( ! $category -> visible ) {
$catlinkcss = array ( 'class' => 'dimmed' );
}
2009-05-14 06:04:35 +00:00
static $coursecount = null ;
if ( null === $coursecount ) {
// only need to check this once
$coursecount = $DB -> count_records ( 'course' ) <= FRONTPAGECOURSELIMIT ;
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( $showcourses and $coursecount ) {
2009-12-16 21:50:45 +00:00
$catimage = '<img src="' . $OUTPUT -> pix_url ( 'i/course' ) . '" alt="" />' ;
2003-09-03 12:13:08 +00:00
} else {
2006-01-16 03:01:28 +00:00
$catimage = " " ;
2003-08-21 09:33:07 +00:00
}
2010-07-23 08:34:59 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$courses = get_courses ( $category -> id , 'c.sortorder ASC' , 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary' );
2011-08-30 17:48:46 +12:00
$context = get_context_instance ( CONTEXT_COURSECAT , $category -> id );
$fullname = format_string ( $category -> name , true , array ( 'context' => $context ));
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( $showcourses and $coursecount ) {
2010-08-01 09:52:54 +00:00
echo '<div class="categorylist clearfix">' ;
2010-07-23 08:34:59 +00:00
$cat = '' ;
2010-08-01 09:52:54 +00:00
$cat .= html_writer :: tag ( 'div' , $catimage , array ( 'class' => 'image' ));
2011-08-30 17:48:46 +12:00
$catlink = html_writer :: link ( new moodle_url ( '/course/category.php' , array ( 'id' => $category -> id )), $fullname , $catlinkcss );
2010-07-23 08:34:59 +00:00
$cat .= html_writer :: tag ( 'div' , $catlink , array ( 'class' => 'name' ));
2010-07-26 05:43:10 +00:00
$html = '' ;
2010-07-23 08:34:59 +00:00
if ( $depth > 0 ) {
for ( $i = 0 ; $i < $depth ; $i ++ ) {
2010-07-26 05:43:10 +00:00
$html = html_writer :: tag ( 'div' , $html . $cat , array ( 'class' => 'indentation' ));
2010-07-23 08:34:59 +00:00
$cat = '' ;
2010-07-23 08:11:22 +00:00
}
2010-07-23 08:34:59 +00:00
} else {
2010-07-26 05:43:10 +00:00
$html = $cat ;
2010-07-23 08:34:59 +00:00
}
2010-08-01 09:52:54 +00:00
echo html_writer :: tag ( 'div' , $html , array ( 'class' => 'category' ));
2010-07-23 08:34:59 +00:00
echo html_writer :: tag ( 'div' , '' , array ( 'class' => 'clearfloat' ));
2003-09-03 12:13:08 +00:00
2009-01-14 04:48:22 +00:00
// does the depth exceed maxcategorydepth
2010-07-23 08:34:59 +00:00
// maxcategorydepth == 0 or unset meant no limit
2009-01-14 04:48:22 +00:00
$limit = ! ( isset ( $CFG -> maxcategorydepth ) && ( $depth >= $CFG -> maxcategorydepth - 1 ));
if ( $courses && ( $limit || $CFG -> maxcategorydepth == 0 )) {
2003-07-30 13:02:45 +00:00
foreach ( $courses as $course ) {
2010-07-26 05:43:10 +00:00
$linkcss = null ;
if ( ! $course -> visible ) {
$linkcss = array ( 'class' => 'dimmed' );
}
2010-08-01 09:52:54 +00:00
2011-10-10 13:50:01 +01:00
$coursename = get_course_display_name_for_list ( $course );
$courselink = html_writer :: link ( new moodle_url ( '/course/view.php' , array ( 'id' => $course -> id )), format_string ( $coursename ), $linkcss );
2010-07-23 08:34:59 +00:00
2010-08-18 09:02:05 +00:00
// print enrol info
2010-09-17 08:49:19 +00:00
$courseicon = '' ;
2010-08-18 09:02:05 +00:00
if ( $icons = enrol_get_course_info_icons ( $course )) {
foreach ( $icons as $pix_icon ) {
2010-09-17 08:49:19 +00:00
$courseicon = $OUTPUT -> render ( $pix_icon ) . ' ' ;
2010-08-18 09:02:05 +00:00
}
}
2010-09-17 08:49:19 +00:00
$coursecontent = html_writer :: tag ( 'div' , $courseicon . $courselink , array ( 'class' => 'name' ));
2003-09-03 12:13:08 +00:00
if ( $course -> summary ) {
2010-02-11 16:27:53 +00:00
$link = new moodle_url ( '/course/info.php?id=' . $course -> id );
2010-07-23 08:34:59 +00:00
$actionlink = $OUTPUT -> action_link ( $link , '<img alt="' . $strsummary . '" src="' . $OUTPUT -> pix_url ( 'i/info' ) . '" />' ,
2010-02-11 16:27:53 +00:00
new popup_action ( 'click' , $link , 'courseinfo' , array ( 'height' => 400 , 'width' => 500 )),
array ( 'title' => $strsummary ));
2010-07-23 08:34:59 +00:00
$coursecontent .= html_writer :: tag ( 'div' , $actionlink , array ( 'class' => 'info' ));
}
2010-07-26 05:43:10 +00:00
$html = '' ;
2010-09-17 08:49:19 +00:00
for ( $i = 0 ; $i <= $depth ; $i ++ ) {
2010-07-26 05:43:10 +00:00
$html = html_writer :: tag ( 'div' , $html . $coursecontent , array ( 'class' => 'indentation' ));
2010-07-23 08:34:59 +00:00
$coursecontent = '' ;
2002-09-10 13:47:56 +00:00
}
2010-07-26 05:43:10 +00:00
echo html_writer :: tag ( 'div' , $html , array ( 'class' => 'course clearfloat' ));
2010-07-23 08:34:59 +00:00
}
2002-09-09 11:48:11 +00:00
}
2010-07-23 08:34:59 +00:00
echo '</div>' ;
} else {
2010-08-01 09:52:54 +00:00
echo '<div class="categorylist">' ;
2010-07-26 05:43:10 +00:00
$html = '' ;
2011-08-30 17:48:46 +12:00
$cat = html_writer :: link ( new moodle_url ( '/course/category.php' , array ( 'id' => $category -> id )), $fullname , $catlinkcss );
2011-08-06 22:12:07 +01:00
if ( count ( $courses ) > 0 ) {
$cat .= html_writer :: tag ( 'span' , ' (' . count ( $courses ) . ')' , array ( 'title' => get_string ( 'numberofcourses' ), 'class' => 'numberofcourse' ));
}
2010-08-01 09:52:54 +00:00
2010-07-26 05:43:10 +00:00
if ( $depth > 0 ) {
for ( $i = 0 ; $i < $depth ; $i ++ ) {
$html = html_writer :: tag ( 'div' , $html . $cat , array ( 'class' => 'indentation' ));
$cat = '' ;
}
} else {
$html = $cat ;
}
2010-08-01 09:52:54 +00:00
echo html_writer :: tag ( 'div' , $html , array ( 'class' => 'category' ));
2010-07-26 05:43:10 +00:00
echo html_writer :: tag ( 'div' , '' , array ( 'class' => 'clearfloat' ));
2010-07-23 08:11:22 +00:00
echo '</div>' ;
2010-07-23 08:34:59 +00:00
}
2003-07-30 13:02:45 +00:00
}
2008-12-05 08:56:54 +00:00
/**
* Print the buttons relating to course requests .
*
* @ param object $systemcontext the system context .
*/
function print_course_request_buttons ( $systemcontext ) {
2009-08-20 08:40:19 +00:00
global $CFG , $DB , $OUTPUT ;
2008-12-05 08:56:54 +00:00
if ( empty ( $CFG -> enablecourserequests )) {
return ;
}
2010-03-31 07:41:31 +00:00
if ( ! has_capability ( 'moodle/course:create' , $systemcontext ) && has_capability ( 'moodle/course:request' , $systemcontext )) {
2008-12-05 08:56:54 +00:00
/// Print a button to request a new course
2010-01-03 15:46:14 +00:00
echo $OUTPUT -> single_button ( 'request.php' , get_string ( 'requestcourse' ), 'get' );
2008-12-05 08:56:54 +00:00
}
/// Print a button to manage pending requests
if ( has_capability ( 'moodle/site:approvecourse' , $systemcontext )) {
2010-01-03 15:46:14 +00:00
$disabled = ! $DB -> record_exists ( 'course_request' , array ());
echo $OUTPUT -> single_button ( 'pending.php' , get_string ( 'coursespending' ), 'get' , array ( 'disabled' => $disabled ));
2008-12-05 08:56:54 +00:00
}
}
2009-07-28 03:03:35 +00:00
/**
* Does the user have permission to edit things in this category ?
*
* @ param integer $categoryid The id of the category we are showing , or 0 for system context .
* @ return boolean has_any_capability ( array ( ... ), ... ); in the appropriate context .
*/
function can_edit_in_category ( $categoryid = 0 ) {
$context = get_category_or_system_context ( $categoryid );
return has_any_capability ( array ( 'moodle/category:manage' , 'moodle/course:create' ), $context );
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
/**
* Prints the turn editing on / off button on course / index . php or course / category . php .
*
* @ param integer $categoryid The id of the category we are showing , or 0 for system context .
* @ return string HTML of the editing button , or empty string , if this user is not allowed
* to see it .
*/
function update_category_button ( $categoryid = 0 ) {
2009-08-20 08:40:19 +00:00
global $CFG , $PAGE , $OUTPUT ;
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
// Check permissions.
2009-07-28 03:03:35 +00:00
if ( ! can_edit_in_category ( $categoryid )) {
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
return '' ;
}
// Work out the appropriate action.
2009-05-06 08:59:29 +00:00
if ( $PAGE -> user_is_editing ()) {
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
$label = get_string ( 'turneditingoff' );
$edit = 'off' ;
} else {
$label = get_string ( 'turneditingon' );
$edit = 'on' ;
}
2003-07-30 13:02:45 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
// Generate the button HTML.
$options = array ( 'categoryedit' => $edit , 'sesskey' => sesskey ());
if ( $categoryid ) {
$options [ 'id' ] = $categoryid ;
$page = 'category.php' ;
} else {
$page = 'index.php' ;
}
2010-01-16 15:39:56 +00:00
return $OUTPUT -> single_button ( new moodle_url ( '/course/' . $page , $options ), $label , 'get' );
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
}
2007-09-24 17:26:40 +00:00
2008-06-01 19:05:07 +00:00
/**
* Category is 0 ( for all courses ) or an object
*/
2007-09-19 07:50:41 +00:00
function print_courses ( $category ) {
2009-08-07 07:18:01 +00:00
global $CFG , $OUTPUT ;
2003-07-30 13:02:45 +00:00
2007-09-19 07:26:54 +00:00
if ( ! is_object ( $category ) && $category == 0 ) {
2007-12-17 04:49:27 +00:00
$categories = get_child_categories ( 0 ); // Parent = 0 ie top-level categories only
2007-09-19 07:26:54 +00:00
if ( is_array ( $categories ) && count ( $categories ) == 1 ) {
2003-07-30 13:56:17 +00:00
$category = array_shift ( $categories );
2008-06-04 06:38:03 +00:00
$courses = get_courses_wmanagers ( $category -> id ,
'c.sortorder ASC' ,
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
array ( 'summary' , 'summaryformat' ));
2003-07-30 13:56:17 +00:00
} else {
2008-06-04 06:38:03 +00:00
$courses = get_courses_wmanagers ( 'all' ,
'c.sortorder ASC' ,
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
array ( 'summary' , 'summaryformat' ));
2003-07-30 13:56:17 +00:00
}
unset ( $categories );
2003-01-05 06:45:20 +00:00
} else {
2008-06-04 06:38:03 +00:00
$courses = get_courses_wmanagers ( $category -> id ,
'c.sortorder ASC' ,
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
array ( 'summary' , 'summaryformat' ));
2003-07-30 13:02:45 +00:00
}
2007-09-19 07:50:28 +00:00
if ( $courses ) {
2010-09-21 02:56:39 +00:00
echo html_writer :: start_tag ( 'ul' , array ( 'class' => 'unlist' ));
2003-07-30 13:02:45 +00:00
foreach ( $courses as $course ) {
2010-03-31 07:41:31 +00:00
$coursecontext = get_context_instance ( CONTEXT_COURSE , $course -> id );
if ( $course -> visible == 1 || has_capability ( 'moodle/course:viewhiddencourses' , $coursecontext )) {
2010-09-21 02:56:39 +00:00
echo html_writer :: start_tag ( 'li' );
2007-09-19 07:26:54 +00:00
print_course ( $course );
2010-09-21 02:56:39 +00:00
echo html_writer :: end_tag ( 'li' );
2007-09-19 07:26:54 +00:00
}
2003-07-30 13:02:45 +00:00
}
2010-09-21 02:56:39 +00:00
echo html_writer :: end_tag ( 'ul' );
2003-07-30 13:02:45 +00:00
} else {
2009-08-06 08:15:43 +00:00
echo $OUTPUT -> heading ( get_string ( " nocoursesyet " ));
2008-04-24 08:39:47 +00:00
$context = get_context_instance ( CONTEXT_SYSTEM );
2006-08-14 05:55:40 +00:00
if ( has_capability ( 'moodle/course:create' , $context )) {
2006-04-10 15:41:57 +00:00
$options = array ();
2010-05-14 14:06:39 +00:00
if ( ! empty ( $category -> id )) {
$options [ 'category' ] = $category -> id ;
} else {
$options [ 'category' ] = $CFG -> defaultrequestcategory ;
}
2010-09-21 02:56:39 +00:00
echo html_writer :: start_tag ( 'div' , array ( 'class' => 'addcoursebutton' ));
2010-01-16 15:39:56 +00:00
echo $OUTPUT -> single_button ( new moodle_url ( '/course/edit.php' , $options ), get_string ( " addnewcourse " ));
2010-09-21 02:56:39 +00:00
echo html_writer :: end_tag ( 'div' );
2006-04-10 15:41:57 +00:00
}
2003-07-30 13:02:45 +00:00
}
}
2008-12-11 10:47:48 +00:00
/**
* Print a description of a course , suitable for browsing in a list .
*
* @ param object $course the course object .
* @ param string $highlightterms ( optional ) some search terms that should be highlighted in the display .
*/
function print_course ( $course , $highlightterms = '' ) {
2009-07-03 04:23:05 +00:00
global $CFG , $USER , $DB , $OUTPUT ;
2003-07-30 13:02:45 +00:00
2010-03-31 07:41:31 +00:00
$context = get_context_instance ( CONTEXT_COURSE , $course -> id );
2004-06-26 09:51:13 +00:00
2009-11-04 06:14:06 +00:00
// Rewrite file URLs so that they are correct
2010-07-03 13:37:13 +00:00
$course -> summary = file_rewrite_pluginfile_urls ( $course -> summary , 'pluginfile.php' , $context -> id , 'course' , 'summary' , NULL );
2009-11-04 06:14:06 +00:00
2010-09-21 02:56:39 +00:00
echo html_writer :: start_tag ( 'div' , array ( 'class' => 'coursebox clearfix' ));
echo html_writer :: start_tag ( 'div' , array ( 'class' => 'info' ));
echo html_writer :: start_tag ( 'h3' , array ( 'class' => 'name' ));
2003-08-21 17:30:39 +00:00
2010-09-21 02:56:39 +00:00
$linkhref = new moodle_url ( '/course/view.php' , array ( 'id' => $course -> id ));
2011-10-10 13:50:01 +01:00
$coursename = get_course_display_name_for_list ( $course );
$linktext = highlight ( $highlightterms , format_string ( $coursename ));
2010-09-21 02:56:39 +00:00
$linkparams = array ( 'title' => get_string ( 'entercourse' ));
if ( empty ( $course -> visible )) {
$linkparams [ 'class' ] = 'dimmed' ;
}
echo html_writer :: link ( $linkhref , $linktext , $linkparams );
echo html_writer :: end_tag ( 'h3' );
2008-06-04 06:38:03 +00:00
2006-11-17 08:57:50 +00:00
/// first find all roles that are supposed to be displayed
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( ! empty ( $CFG -> coursecontact )) {
2010-07-20 03:27:36 +00:00
$managerroles = explode ( ',' , $CFG -> coursecontact );
2007-09-19 07:26:54 +00:00
$namesarray = array ();
2011-10-24 14:42:24 +01:00
$rusers = array ();
2008-05-21 12:03:22 +00:00
2011-10-24 14:42:24 +01:00
if ( ! isset ( $course -> managers )) {
$rusers = get_role_users ( $managerroles , $context , true ,
' ra . id AS raid , u . id , u . username , u . firstname , u . lastname ,
r . name AS rolename , r . sortorder , r . id AS roleid ' ,
'r.sortorder ASC, u.lastname ASC' );
} else {
// use the managers array if we have it for perf reasosn
// populate the datastructure like output of get_role_users();
foreach ( $course -> managers as $manager ) {
$u = new stdClass ();
$u = $manager -> user ;
$u -> roleid = $manager -> roleid ;
$u -> rolename = $manager -> rolename ;
2010-03-31 07:41:31 +00:00
2011-10-24 14:42:24 +01:00
$rusers [] = $u ;
2007-09-19 07:26:54 +00:00
}
2011-10-24 14:42:24 +01:00
}
2008-09-18 15:16:02 +00:00
2011-10-24 14:42:24 +01:00
/// Rename some of the role names if needed
if ( isset ( $context )) {
$aliasnames = $DB -> get_records ( 'role_names' , array ( 'contextid' => $context -> id ), '' , 'roleid,contextid,name' );
}
2008-09-18 15:16:02 +00:00
2011-10-24 14:42:24 +01:00
$namesarray = array ();
$canviewfullnames = has_capability ( 'moodle/site:viewfullnames' , $context );
foreach ( $rusers as $ra ) {
if ( isset ( $namesarray [ $ra -> id ])) {
// only display a user once with the higest sortorder role
continue ;
}
2008-09-18 15:16:02 +00:00
2011-10-24 14:42:24 +01:00
if ( isset ( $aliasnames [ $ra -> roleid ])) {
$ra -> rolename = $aliasnames [ $ra -> roleid ] -> name ;
2007-09-19 07:26:27 +00:00
}
2011-10-24 14:42:24 +01:00
$fullname = fullname ( $ra , $canviewfullnames );
$namesarray [ $ra -> id ] = format_string ( $ra -> rolename ) . ': ' .
html_writer :: link ( new moodle_url ( '/user/view.php' , array ( 'id' => $ra -> id , 'course' => SITEID )), $fullname );
2003-07-30 13:02:45 +00:00
}
2007-09-19 07:26:27 +00:00
2006-11-17 08:57:50 +00:00
if ( ! empty ( $namesarray )) {
2010-09-21 02:56:39 +00:00
echo html_writer :: start_tag ( 'ul' , array ( 'class' => 'teachers' ));
foreach ( $namesarray as $name ) {
echo html_writer :: tag ( 'li' , $name );
}
echo html_writer :: end_tag ( 'ul' );
2006-09-16 15:23:41 +00:00
}
2003-07-30 13:02:45 +00:00
}
2010-09-21 02:56:39 +00:00
echo html_writer :: end_tag ( 'div' ); // End of info div
2008-06-04 06:38:03 +00:00
2010-09-21 02:56:39 +00:00
echo html_writer :: start_tag ( 'div' , array ( 'class' => 'summary' ));
2004-09-30 06:46:26 +00:00
$options = NULL ;
$options -> noclean = true ;
2004-09-30 08:42:34 +00:00
$options -> para = false ;
2010-11-05 02:53:47 +00:00
$options -> overflowdiv = true ;
2009-11-04 06:14:06 +00:00
if ( ! isset ( $course -> summaryformat )) {
$course -> summaryformat = FORMAT_MOODLE ;
}
echo highlight ( $highlightterms , format_text ( $course -> summary , $course -> summaryformat , $options , $course -> id ));
2011-07-15 10:39:47 +08:00
if ( $icons = enrol_get_course_info_icons ( $course )) {
2010-09-21 02:56:39 +00:00
echo html_writer :: start_tag ( 'div' , array ( 'class' => 'enrolmenticons' ));
foreach ( $icons as $icon ) {
echo $OUTPUT -> render ( $icon );
}
echo html_writer :: end_tag ( 'div' ); // End of enrolmenticons div
}
echo html_writer :: end_tag ( 'div' ); // End of summary div
echo html_writer :: end_tag ( 'div' ); // End of coursebox div
2003-07-30 13:02:45 +00:00
}
2008-06-01 19:05:07 +00:00
/**
* Prints custom user information on the home page .
* Over time this can include all sorts of information
*/
2003-07-30 13:02:45 +00:00
function print_my_moodle () {
2009-08-18 04:58:26 +00:00
global $USER , $CFG , $DB , $OUTPUT ;
2003-07-30 13:02:45 +00:00
2010-03-31 07:41:31 +00:00
if ( ! isloggedin () or isguestuser ()) {
2008-05-07 06:02:51 +00:00
print_error ( 'nopermissions' , '' , '' , 'See My Moodle' );
2003-07-30 13:02:45 +00:00
}
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$courses = enrol_get_my_courses ( 'summary' , 'visible DESC,sortorder ASC' );
2009-08-03 07:35:41 +00:00
$rhosts = array ();
$rcourses = array ();
if ( ! empty ( $CFG -> mnet_dispatcher_mode ) && $CFG -> mnet_dispatcher_mode === 'strict' ) {
$rcourses = get_my_remotecourses ( $USER -> id );
$rhosts = get_my_remotehosts ();
}
if ( ! empty ( $courses ) || ! empty ( $rcourses ) || ! empty ( $rhosts )) {
if ( ! empty ( $courses )) {
echo '<ul class="unlist">' ;
foreach ( $courses as $course ) {
if ( $course -> id == SITEID ) {
continue ;
}
echo '<li>' ;
print_course ( $course );
echo " </li> \n " ;
2007-01-19 09:23:47 +00:00
}
2009-08-03 07:35:41 +00:00
echo " </ul> \n " ;
2007-01-19 09:23:47 +00:00
}
2009-08-03 07:35:41 +00:00
// MNET
if ( ! empty ( $rcourses )) {
// at the IDP, we know of all the remote courses
foreach ( $rcourses as $course ) {
print_remote_course ( $course , " 100% " );
}
} elseif ( ! empty ( $rhosts )) {
// non-IDP, we know of all the remote servers, but not courses
foreach ( $rhosts as $host ) {
print_remote_host ( $host , " 100% " );
}
}
2007-01-19 09:23:47 +00:00
unset ( $course );
2009-08-03 07:35:41 +00:00
unset ( $host );
2003-08-11 09:45:50 +00:00
2008-06-01 19:05:07 +00:00
if ( $DB -> count_records ( " course " ) > ( count ( $courses ) + 1 ) ) { // Some courses not being displayed
2003-10-21 02:25:22 +00:00
echo " <table width= \" 100% \" ><tr><td align= \" center \" > " ;
print_course_search ( " " , false , " short " );
echo " </td><td align= \" center \" > " ;
2010-01-03 15:46:14 +00:00
echo $OUTPUT -> single_button ( " $CFG->wwwroot /course/index.php " , get_string ( " fulllistofcourses " ), " get " );
2003-10-21 02:25:22 +00:00
echo " </td></tr></table> \n " ;
}
2007-01-19 09:23:47 +00:00
2003-08-07 16:41:33 +00:00
} else {
2008-06-01 19:05:07 +00:00
if ( $DB -> count_records ( " course_categories " ) > 1 ) {
2009-08-18 04:58:26 +00:00
echo $OUTPUT -> box_start ( " categorybox " );
2003-08-07 16:41:33 +00:00
print_whole_category_list ();
2009-08-18 04:58:26 +00:00
echo $OUTPUT -> box_end ();
2003-08-07 16:41:33 +00:00
} else {
2007-02-14 04:56:26 +00:00
print_courses ( 0 );
2003-08-07 16:41:33 +00:00
}
2003-01-05 06:45:20 +00:00
}
2002-07-27 09:44:01 +00:00
}
2002-08-01 03:50:27 +00:00
2003-08-19 05:32:20 +00:00
function print_course_search ( $value = " " , $return = false , $format = " plain " ) {
2003-08-11 09:45:50 +00:00
global $CFG ;
2007-02-05 07:58:29 +00:00
static $count = 0 ;
$count ++ ;
$id = 'coursesearch' ;
if ( $count > 1 ) {
$id .= $count ;
}
2003-08-11 09:45:50 +00:00
$strsearchcourses = get_string ( " searchcourses " );
2004-09-08 19:24:38 +00:00
if ( $format == 'plain' ) {
2007-02-05 07:58:29 +00:00
$output = '<form id="' . $id . '" action="' . $CFG -> wwwroot . '/course/search.php" method="get">' ;
2007-01-05 14:13:26 +00:00
$output .= '<fieldset class="coursesearchbox invisiblefieldset">' ;
2007-06-19 03:22:58 +00:00
$output .= '<label for="coursesearchbox">' . $strsearchcourses . ': </label>' ;
2008-06-01 19:05:07 +00:00
$output .= '<input type="text" id="coursesearchbox" size="30" name="search" value="' . s ( $value ) . '" />' ;
2007-06-19 03:22:58 +00:00
$output .= '<input type="submit" value="' . get_string ( 'go' ) . '" />' ;
2007-01-05 14:13:26 +00:00
$output .= '</fieldset></form>' ;
2004-09-08 19:24:38 +00:00
} else if ( $format == 'short' ) {
2007-02-05 07:58:29 +00:00
$output = '<form id="' . $id . '" action="' . $CFG -> wwwroot . '/course/search.php" method="get">' ;
2007-01-05 14:13:26 +00:00
$output .= '<fieldset class="coursesearchbox invisiblefieldset">' ;
2008-03-25 01:25:54 +00:00
$output .= '<label for="shortsearchbox">' . $strsearchcourses . ': </label>' ;
2008-06-01 19:05:07 +00:00
$output .= '<input type="text" id="shortsearchbox" size="12" name="search" alt="' . s ( $strsearchcourses ) . '" value="' . s ( $value ) . '" />' ;
2007-06-19 03:22:58 +00:00
$output .= '<input type="submit" value="' . get_string ( 'go' ) . '" />' ;
2007-01-05 14:13:26 +00:00
$output .= '</fieldset></form>' ;
2004-09-08 19:24:38 +00:00
} else if ( $format == 'navbar' ) {
2007-01-05 14:13:26 +00:00
$output = '<form id="coursesearchnavbar" action="' . $CFG -> wwwroot . '/course/search.php" method="get">' ;
$output .= '<fieldset class="coursesearchbox invisiblefieldset">' ;
2008-03-25 01:25:54 +00:00
$output .= '<label for="navsearchbox">' . $strsearchcourses . ': </label>' ;
2008-06-01 19:05:07 +00:00
$output .= '<input type="text" id="navsearchbox" size="20" name="search" alt="' . s ( $strsearchcourses ) . '" value="' . s ( $value ) . '" />' ;
2007-06-19 03:22:58 +00:00
$output .= '<input type="submit" value="' . get_string ( 'go' ) . '" />' ;
2007-01-05 14:13:26 +00:00
$output .= '</fieldset></form>' ;
2003-08-19 05:32:20 +00:00
}
if ( $return ) {
return $output ;
}
echo $output ;
2003-08-11 09:45:50 +00:00
}
2002-08-01 03:50:27 +00:00
2007-01-19 09:23:47 +00:00
function print_remote_course ( $course , $width = " 100% " ) {
global $CFG , $USER ;
$linkcss = '' ;
$url = " { $CFG -> wwwroot } /auth/mnet/jump.php?hostid= { $course -> hostid } &wantsurl=/course/view.php?id= { $course -> remoteid } " ;
2007-11-16 07:29:14 +00:00
echo '<div class="coursebox remotecoursebox clearfix">' ;
2007-01-19 09:23:47 +00:00
echo '<div class="info">' ;
echo '<div class="name"><a title="' . get_string ( 'entercourse' ) . '"' .
$linkcss . ' href="' . $url . '">'
2007-02-28 06:25:22 +00:00
. format_string ( $course -> fullname ) . '</a><br />'
. format_string ( $course -> hostname ) . ' : '
2008-06-04 06:38:03 +00:00
. format_string ( $course -> cat_name ) . ' : '
. format_string ( $course -> shortname ) . '</div>' ;
2007-01-19 09:23:47 +00:00
echo '</div><div class="summary">' ;
$options = NULL ;
$options -> noclean = true ;
$options -> para = false ;
2010-11-05 02:53:47 +00:00
$options -> overflowdiv = true ;
2010-07-17 22:34:12 +00:00
echo format_text ( $course -> summary , $course -> summaryformat , $options );
2007-01-19 09:23:47 +00:00
echo '</div>' ;
echo '</div>' ;
}
2007-01-19 09:36:40 +00:00
function print_remote_host ( $host , $width = " 100% " ) {
2009-07-02 10:53:31 +00:00
global $OUTPUT ;
2007-01-19 09:36:40 +00:00
$linkcss = '' ;
2007-11-16 07:29:14 +00:00
echo '<div class="coursebox clearfix">' ;
2007-01-19 09:36:40 +00:00
echo '<div class="info">' ;
echo '<div class="name">' ;
2009-12-16 21:50:45 +00:00
echo '<img src="' . $OUTPUT -> pix_url ( 'i/mnethost' ) . '" class="icon" alt="' . get_string ( 'course' ) . '" />' ;
2007-01-19 09:36:40 +00:00
echo '<a title="' . s ( $host [ 'name' ]) . '" href="' . s ( $host [ 'url' ]) . '">'
. s ( $host [ 'name' ]) . '</a> - ' ;
2007-01-19 09:37:28 +00:00
echo $host [ 'count' ] . ' ' . get_string ( 'courses' );
2007-01-19 09:36:40 +00:00
echo '</div>' ;
echo '</div>' ;
2007-01-22 01:57:05 +00:00
echo '</div>' ;
2007-01-19 09:36:40 +00:00
}
2007-01-19 09:23:47 +00:00
2002-08-01 03:50:27 +00:00
/// MODULE FUNCTIONS /////////////////////////////////////////////////////////////////
function add_course_module ( $mod ) {
2008-06-01 19:05:07 +00:00
global $DB ;
2002-08-01 03:50:27 +00:00
2002-10-21 03:00:40 +00:00
$mod -> added = time ();
2004-08-08 15:14:25 +00:00
unset ( $mod -> id );
2002-08-01 03:50:27 +00:00
2008-06-01 19:05:07 +00:00
return $DB -> insert_record ( " course_modules " , $mod );
2002-08-01 03:50:27 +00:00
}
2007-08-26 15:30:51 +00:00
/**
* Returns course section - creates new if does not exist yet .
* @ param int $relative section number
* @ param int $courseid
* @ return object $course_section object
*/
function get_course_section ( $section , $courseid ) {
2008-06-01 19:05:07 +00:00
global $DB ;
if ( $cw = $DB -> get_record ( " course_sections " , array ( " section " => $section , " course " => $courseid ))) {
2007-08-26 15:30:51 +00:00
return $cw ;
}
2010-09-21 08:13:11 +00:00
$cw = new stdClass ();
2008-06-01 19:05:07 +00:00
$cw -> course = $courseid ;
$cw -> section = $section ;
$cw -> summary = " " ;
2010-06-10 18:25:06 +00:00
$cw -> summaryformat = FORMAT_HTML ;
2007-08-26 15:30:51 +00:00
$cw -> sequence = " " ;
2008-06-01 19:05:07 +00:00
$id = $DB -> insert_record ( " course_sections " , $cw );
2008-06-04 23:45:31 +00:00
return $DB -> get_record ( " course_sections " , array ( " id " => $id ));
2007-08-26 15:30:51 +00:00
}
2007-10-03 12:22:25 +00:00
/**
* Given a full mod object with section and course already defined , adds this module to that section .
*
* @ param object $mod
* @ param int $beforemod An existing ID which we will insert the new module before
* @ return int The course_sections ID where the mod is inserted
*/
2003-07-14 13:08:38 +00:00
function add_mod_to_section ( $mod , $beforemod = NULL ) {
2008-06-01 19:05:07 +00:00
global $DB ;
2002-08-01 03:50:27 +00:00
2008-06-01 19:05:07 +00:00
if ( $section = $DB -> get_record ( " course_sections " , array ( " course " => $mod -> course , " section " => $mod -> section ))) {
2003-07-14 13:08:38 +00:00
$section -> sequence = trim ( $section -> sequence );
if ( empty ( $section -> sequence )) {
2002-08-01 03:50:27 +00:00
$newsequence = " $mod->coursemodule " ;
2003-07-14 13:08:38 +00:00
} else if ( $beforemod ) {
$modarray = explode ( " , " , $section -> sequence );
2008-08-27 16:33:50 +00:00
if ( $key = array_keys ( $modarray , $beforemod -> id )) {
2003-07-14 13:08:38 +00:00
$insertarray = array ( $mod -> id , $beforemod -> id );
array_splice ( $modarray , $key [ 0 ], 1 , $insertarray );
$newsequence = implode ( " , " , $modarray );
} else { // Just tack it on the end anyway
$newsequence = " $section->sequence , $mod->coursemodule " ;
}
} else {
$newsequence = " $section->sequence , $mod->coursemodule " ;
2002-08-01 03:50:27 +00:00
}
2004-05-28 10:53:54 +00:00
2010-09-03 18:14:55 +00:00
$DB -> set_field ( " course_sections " , " sequence " , $newsequence , array ( " id " => $section -> id ));
return $section -> id ; // Return course_sections ID that was used.
2004-05-28 10:53:54 +00:00
2002-08-01 03:50:27 +00:00
} else { // Insert a new record
2008-06-01 19:05:07 +00:00
$section -> course = $mod -> course ;
$section -> section = $mod -> section ;
$section -> summary = " " ;
2010-06-10 18:25:06 +00:00
$section -> summaryformat = FORMAT_HTML ;
2002-10-21 03:00:40 +00:00
$section -> sequence = $mod -> coursemodule ;
2008-06-01 19:05:07 +00:00
return $DB -> insert_record ( " course_sections " , $section );
2002-08-01 03:50:27 +00:00
}
}
2005-02-12 21:41:22 +00:00
function set_coursemodule_groupmode ( $id , $groupmode ) {
2008-06-01 19:05:07 +00:00
global $DB ;
2008-06-02 21:39:23 +00:00
return $DB -> set_field ( " course_modules " , " groupmode " , $groupmode , array ( " id " => $id ));
2004-01-31 08:40:38 +00:00
}
2007-04-11 09:19:24 +00:00
function set_coursemodule_idnumber ( $id , $idnumber ) {
2008-06-01 19:05:07 +00:00
global $DB ;
2008-06-04 06:38:03 +00:00
return $DB -> set_field ( " course_modules " , " idnumber " , $idnumber , array ( " id " => $id ));
2007-04-11 09:19:24 +00:00
}
2008-07-28 12:31:29 +00:00
2006-04-12 03:11:34 +00:00
/**
* $prevstateoverrides = true will set the visibility of the course module
* to what is defined in visibleold . This enables us to remember the current
* visibility when making a whole section hidden , so that when we toggle
* that section back to visible , we are able to return the visibility of
* the course module back to what it was originally .
*/
function set_coursemodule_visible ( $id , $visible , $prevstateoverrides = false ) {
2010-09-03 02:49:04 +00:00
global $DB , $CFG ;
2010-09-16 08:16:26 +00:00
require_once ( $CFG -> libdir . '/gradelib.php' );
2008-06-01 19:05:07 +00:00
if ( ! $cm = $DB -> get_record ( 'course_modules' , array ( 'id' => $id ))) {
2006-09-24 06:06:24 +00:00
return false ;
}
2008-06-01 19:05:07 +00:00
if ( ! $modulename = $DB -> get_field ( 'modules' , 'name' , array ( 'id' => $cm -> module ))) {
2006-09-24 06:06:24 +00:00
return false ;
}
2008-06-01 19:05:07 +00:00
if ( $events = $DB -> get_records ( 'event' , array ( 'instance' => $cm -> instance , 'modulename' => $modulename ))) {
2004-05-05 07:07:56 +00:00
foreach ( $events as $event ) {
2005-02-12 21:41:22 +00:00
if ( $visible ) {
show_event ( $event );
} else {
hide_event ( $event );
}
2004-05-05 07:07:56 +00:00
}
}
2010-09-03 02:49:04 +00:00
2010-09-16 08:16:26 +00:00
// hide the associated grade items so the teacher doesn't also have to go to the gradebook and hide them there
$grade_items = grade_item :: fetch_all ( array ( 'itemtype' => 'mod' , 'itemmodule' => $modulename , 'iteminstance' => $cm -> instance , 'courseid' => $cm -> course ));
if ( $grade_items ) {
foreach ( $grade_items as $grade_item ) {
$grade_item -> set_hidden ( ! $visible );
}
2010-09-03 02:49:04 +00:00
}
2010-09-03 18:14:55 +00:00
2006-04-12 03:11:34 +00:00
if ( $prevstateoverrides ) {
if ( $visible == '0' ) {
// Remember the current visible state so we can toggle this back.
2008-06-01 19:05:07 +00:00
$DB -> set_field ( 'course_modules' , 'visibleold' , $cm -> visible , array ( 'id' => $id ));
2006-04-12 03:11:34 +00:00
} else {
// Get the previous saved visible states.
2008-06-01 19:05:07 +00:00
return $DB -> set_field ( 'course_modules' , 'visible' , $cm -> visibleold , array ( 'id' => $id ));
2006-04-12 03:11:34 +00:00
}
}
2008-06-01 19:05:07 +00:00
return $DB -> set_field ( " course_modules " , " visible " , $visible , array ( " id " => $id ));
2003-04-14 15:11:09 +00:00
}
2008-06-01 19:05:07 +00:00
/**
2005-03-28 06:47:54 +00:00
* Delete a course module and any associated data at the course level ( events )
2006-11-09 18:25:58 +00:00
* Until 1.5 this function simply marked a deleted flag ... now it
2005-03-28 06:47:54 +00:00
* deletes it completely .
*
*/
2005-02-12 21:41:22 +00:00
function delete_course_module ( $id ) {
2008-06-01 19:05:07 +00:00
global $CFG , $DB ;
2007-08-03 19:25:22 +00:00
require_once ( $CFG -> libdir . '/gradelib.php' );
2009-09-04 00:36:43 +00:00
require_once ( $CFG -> dirroot . '/blog/lib.php' );
2007-08-03 19:25:22 +00:00
2008-06-01 19:05:07 +00:00
if ( ! $cm = $DB -> get_record ( 'course_modules' , array ( 'id' => $id ))) {
2005-03-28 06:47:54 +00:00
return true ;
}
2008-06-01 19:05:07 +00:00
$modulename = $DB -> get_field ( 'modules' , 'name' , array ( 'id' => $cm -> module ));
2007-08-03 19:25:22 +00:00
//delete events from calendar
2008-06-01 19:05:07 +00:00
if ( $events = $DB -> get_records ( 'event' , array ( 'instance' => $cm -> instance , 'modulename' => $modulename ))) {
2004-05-05 07:07:56 +00:00
foreach ( $events as $event ) {
2007-07-27 18:39:54 +00:00
delete_event ( $event -> id );
2004-05-05 07:07:56 +00:00
}
}
2007-08-03 19:25:22 +00:00
//delete grade items, outcome items and grades attached to modules
if ( $grade_items = grade_item :: fetch_all ( array ( 'itemtype' => 'mod' , 'itemmodule' => $modulename ,
'iteminstance' => $cm -> instance , 'courseid' => $cm -> course ))) {
foreach ( $grade_items as $grade_item ) {
$grade_item -> delete ( 'moddelete' );
}
}
2010-09-01 17:02:56 +00:00
// Delete completion and availability data; it is better to do this even if the
// features are not turned on, in case they were turned on previously (these will be
// very quick on an empty table)
$DB -> delete_records ( 'course_modules_completion' , array ( 'coursemoduleid' => $cm -> id ));
$DB -> delete_records ( 'course_modules_availability' , array ( 'coursemoduleid' => $cm -> id ));
2009-01-09 05:32:08 +00:00
delete_context ( CONTEXT_MODULE , $cm -> id );
2009-10-01 14:41:20 +00:00
return $DB -> delete_records ( 'course_modules' , array ( 'id' => $cm -> id ));
2002-08-01 03:50:27 +00:00
}
function delete_mod_from_section ( $mod , $section ) {
2008-06-01 19:05:07 +00:00
global $DB ;
2002-08-01 03:50:27 +00:00
2008-06-01 19:05:07 +00:00
if ( $section = $DB -> get_record ( " course_sections " , array ( " id " => $section )) ) {
2002-08-01 03:50:27 +00:00
2002-10-21 03:00:40 +00:00
$modarray = explode ( " , " , $section -> sequence );
2002-08-01 03:50:27 +00:00
if ( $key = array_keys ( $modarray , $mod )) {
array_splice ( $modarray , $key [ 0 ], 1 );
$newsequence = implode ( " , " , $modarray );
2008-06-01 19:05:07 +00:00
return $DB -> set_field ( " course_sections " , " sequence " , $newsequence , array ( " id " => $section -> id ));
2002-08-01 03:50:27 +00:00
} else {
return false ;
}
2004-05-28 10:53:54 +00:00
2002-08-01 03:50:27 +00:00
}
2003-07-14 13:08:38 +00:00
return false ;
2002-08-01 03:50:27 +00:00
}
2008-08-08 05:25:54 +00:00
/**
* Moves a section up or down by 1. CANNOT BE USED DIRECTLY BY AJAX !
*
* @ param object $course
* @ param int $section
* @ param int $move ( - 1 or 1 )
*/
2003-06-10 15:27:09 +00:00
function move_section ( $course , $section , $move ) {
/// Moves a whole course section up and down within the course
2008-06-01 19:05:07 +00:00
global $USER , $DB ;
2003-06-10 15:27:09 +00:00
if ( ! $move ) {
return true ;
}
$sectiondest = $section + $move ;
if ( $sectiondest > $course -> numsections or $sectiondest < 1 ) {
return false ;
}
2008-06-01 19:05:07 +00:00
if ( ! $sectionrecord = $DB -> get_record ( " course_sections " , array ( " course " => $course -> id , " section " => $section ))) {
2003-06-10 15:27:09 +00:00
return false ;
}
2008-06-01 19:05:07 +00:00
if ( ! $sectiondestrecord = $DB -> get_record ( " course_sections " , array ( " course " => $course -> id , " section " => $sectiondest ))) {
2003-06-10 15:27:09 +00:00
return false ;
}
2010-09-03 18:14:55 +00:00
$DB -> set_field ( " course_sections " , " section " , $sectiondest , array ( " id " => $sectionrecord -> id ));
$DB -> set_field ( " course_sections " , " section " , $section , array ( " id " => $sectiondestrecord -> id ));
2005-01-16 17:54:34 +00:00
// if the focus is on the section that is being moved, then move the focus along
2011-02-12 22:45:17 +01:00
if ( course_get_display ( $course -> id ) == $section ) {
2005-01-16 17:54:34 +00:00
course_set_display ( $course -> id , $sectiondest );
}
2005-10-14 03:12:41 +00:00
2006-07-19 12:30:39 +00:00
// Check for duplicates and fix order if needed.
2005-10-14 03:12:41 +00:00
// There is a very rare case that some sections in the same course have the same section id.
2008-06-01 19:05:07 +00:00
$sections = $DB -> get_records ( 'course_sections' , array ( 'course' => $course -> id ), 'section ASC' );
2006-07-19 12:30:39 +00:00
$n = 0 ;
foreach ( $sections as $section ) {
if ( $section -> section != $n ) {
2010-09-03 18:14:55 +00:00
$DB -> set_field ( 'course_sections' , 'section' , $n , array ( 'id' => $section -> id ));
2005-10-14 03:12:41 +00:00
}
2006-07-19 12:30:39 +00:00
$n ++ ;
2005-10-14 03:12:41 +00:00
}
2003-06-10 15:27:09 +00:00
return true ;
}
2008-08-08 05:25:54 +00:00
/**
* Moves a section within a course , from a position to another .
* Be very careful : $section and $destination refer to section number ,
* not id !.
*
* @ param object $course
* @ param int $section Section number ( not id !!! )
* @ param int $destination
* @ return boolean Result
*/
function move_section_to ( $course , $section , $destination ) {
/// Moves a whole course section up and down within the course
global $USER , $DB ;
2008-10-08 12:22:04 +00:00
if ( ! $destination && $destination != 0 ) {
2008-08-08 05:25:54 +00:00
return true ;
}
2008-10-08 12:22:04 +00:00
if ( $destination > $course -> numsections ) {
2008-08-08 05:25:54 +00:00
return false ;
}
// Get all sections for this course and re-order them (2 of them should now share the same section number)
if ( ! $sections = $DB -> get_records_menu ( 'course_sections' , array ( 'course' => $course -> id ),
'section ASC, id ASC' , 'id, section' )) {
return false ;
}
$sections = reorder_sections ( $sections , $section , $destination );
// Update all sections
foreach ( $sections as $id => $position ) {
$DB -> set_field ( 'course_sections' , 'section' , $position , array ( 'id' => $id ));
}
// if the focus is on the section that is being moved, then move the focus along
2011-02-12 22:45:17 +01:00
if ( course_get_display ( $course -> id ) == $section ) {
2008-08-08 05:25:54 +00:00
course_set_display ( $course -> id , $destination );
}
return true ;
}
/**
* Reordering algorithm for course sections . Given an array of section -> section indexed by section -> id ,
* an original position number and a target position number , rebuilds the array so that the
* move is made without any duplication of section positions .
* Note : The target_position is the position AFTER WHICH the moved section will be inserted . If you want to
* insert a section before the first one , you must give 0 as the target ( section 0 can never be moved ) .
*
* @ param array $sections
* @ param int $origin_position
* @ param int $target_position
* @ return array
*/
function reorder_sections ( $sections , $origin_position , $target_position ) {
if ( ! is_array ( $sections )) {
return false ;
}
// We can't move section position 0
if ( $origin_position < 1 ) {
echo " We can't move section position 0 " ;
return false ;
}
// Locate origin section in sections array
if ( ! $origin_key = array_search ( $origin_position , $sections )) {
echo " searched position not in sections array " ;
return false ; // searched position not in sections array
}
// Extract origin section
$origin_section = $sections [ $origin_key ];
unset ( $sections [ $origin_key ]);
// Find offset of target position (stupid PHP's array_splice requires offset instead of key index!)
$found = false ;
$append_array = array ();
foreach ( $sections as $id => $position ) {
if ( $found ) {
$append_array [ $id ] = $position ;
unset ( $sections [ $id ]);
}
if ( $position == $target_position ) {
$found = true ;
}
}
// Append moved section
$sections [ $origin_key ] = $origin_section ;
// Append rest of array (if applicable)
if ( ! empty ( $append_array )) {
foreach ( $append_array as $id => $position ) {
$sections [ $id ] = $position ;
}
}
// Renumber positions
$position = 0 ;
foreach ( $sections as $id => $p ) {
$sections [ $id ] = $position ;
$position ++ ;
}
return $sections ;
}
2008-06-01 19:05:07 +00:00
/**
* Move the module object $mod to the specified $section
* If $beforemod exists then that is the module
* before which $modid should be inserted
* All parameters are objects
*/
2003-07-14 13:08:38 +00:00
function moveto_module ( $mod , $section , $beforemod = NULL ) {
2009-08-18 04:58:26 +00:00
global $DB , $OUTPUT ;
2003-07-14 13:08:38 +00:00
/// Remove original module from original section
if ( ! delete_mod_from_section ( $mod -> id , $mod -> section )) {
2009-08-18 04:58:26 +00:00
echo $OUTPUT -> notification ( " Could not delete module from existing section " );
2003-07-14 13:08:38 +00:00
}
/// Update module itself if necessary
if ( $mod -> section != $section -> id ) {
2004-05-28 10:53:54 +00:00
$mod -> section = $section -> id ;
2009-06-13 17:17:10 +00:00
$DB -> update_record ( " course_modules " , $mod );
2005-02-12 21:41:22 +00:00
// if moving to a hidden section then hide module
if ( ! $section -> visible ) {
set_coursemodule_visible ( $mod -> id , 0 );
}
2003-07-14 13:08:38 +00:00
}
/// Add the module into the new section
$mod -> course = $section -> course ;
$mod -> section = $section -> section ; // need relative reference
$mod -> coursemodule = $mod -> id ;
if ( ! add_mod_to_section ( $mod , $beforemod )) {
return false ;
}
return true ;
}
2011-08-25 18:02:35 +12:00
/**
* Produces the editing buttons for a module
*
* @ global core_renderer $OUTPUT
* @ staticvar type $str
* @ param stdClass $mod The module to produce editing buttons for
* @ param bool $absolute If true an absolute link is produced ( default true )
* @ param bool $moveselect If true a move seleciton process is used ( default true )
* @ param int $indent The current indenting
* @ param int $section The section to link back to
* @ return string XHTML for the editing buttons
*/
function make_editing_buttons ( stdClass $mod , $absolute = true , $moveselect = true , $indent =- 1 , $section =- 1 ) {
global $CFG , $OUTPUT ;
2002-08-03 08:16:31 +00:00
2004-01-31 08:40:38 +00:00
static $str ;
2011-08-25 18:02:35 +12:00
$coursecontext = get_context_instance ( CONTEXT_COURSE , $mod -> course );
2007-02-16 07:57:19 +00:00
$modcontext = get_context_instance ( CONTEXT_MODULE , $mod -> id );
2011-08-25 18:02:35 +12:00
2007-02-16 07:57:19 +00:00
// no permission to edit
if ( ! has_capability ( 'moodle/course:manageactivities' , $modcontext )) {
2007-02-23 06:03:09 +00:00
return false ;
2007-02-16 07:57:19 +00:00
}
2004-01-31 08:40:38 +00:00
if ( ! isset ( $str )) {
2011-08-25 18:02:35 +12:00
$str = new stdClass ;
2008-04-17 06:41:00 +00:00
$str -> assign = get_string ( " assignroles " , 'role' );
2006-11-21 04:19:01 +00:00
$str -> delete = get_string ( " delete " );
$str -> move = get_string ( " move " );
$str -> moveup = get_string ( " moveup " );
$str -> movedown = get_string ( " movedown " );
$str -> moveright = get_string ( " moveright " );
$str -> moveleft = get_string ( " moveleft " );
$str -> update = get_string ( " update " );
$str -> duplicate = get_string ( " duplicate " );
$str -> hide = get_string ( " hide " );
$str -> show = get_string ( " show " );
2004-01-31 08:40:38 +00:00
$str -> clicktochange = get_string ( " clicktochange " );
2004-02-15 04:13:25 +00:00
$str -> forcedmode = get_string ( " forcedmode " );
2004-01-31 08:40:38 +00:00
$str -> groupsnone = get_string ( " groupsnone " );
$str -> groupsseparate = get_string ( " groupsseparate " );
$str -> groupsvisible = get_string ( " groupsvisible " );
2003-04-14 15:11:09 +00:00
}
2002-08-03 08:16:31 +00:00
2011-08-25 18:02:35 +12:00
if ( $absolute ) {
$baseurl = new moodle_url ( '/course/mod.php' , array ( 'sesskey' => sesskey ()));
2005-03-05 05:19:26 +00:00
} else {
2011-08-25 18:02:35 +12:00
$baseurl = new moodle_url ( 'mod.php' , array ( 'sesskey' => sesskey ()));
2005-03-05 05:19:26 +00:00
}
2011-08-25 18:02:35 +12:00
if ( $section >= 0 ) {
$baseurl -> param ( 'sr' , $section );
}
$actions = array ();
// leftright
if ( has_capability ( 'moodle/course:update' , $coursecontext )) {
if ( right_to_left ()) { // Exchange arrows on RTL
$rightarrow = 't/left' ;
$leftarrow = 't/right' ;
} else {
$rightarrow = 't/right' ;
$leftarrow = 't/left' ;
}
if ( $indent > 0 ) {
$actions [] = new action_link (
new moodle_url ( $baseurl , array ( 'id' => $mod -> id , 'indent' => '-1' )),
new pix_icon ( $leftarrow , $str -> moveleft , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => 'editing_moveleft' , 'title' => $str -> moveleft )
);
}
if ( $indent >= 0 ) {
$actions [] = new action_link (
new moodle_url ( $baseurl , array ( 'id' => $mod -> id , 'indent' => '1' )),
new pix_icon ( $rightarrow , $str -> moveright , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => 'editing_moveright' , 'title' => $str -> moveright )
);
}
2003-04-28 04:32:55 +00:00
}
2011-08-25 18:02:35 +12:00
// move
if ( has_capability ( 'moodle/course:update' , $coursecontext )) {
if ( $moveselect ) {
$actions [] = new action_link (
new moodle_url ( $baseurl , array ( 'copy' => $mod -> id )),
new pix_icon ( 't/move' , $str -> move , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => 'editing_move' , 'title' => $str -> move )
);
} else {
$actions [] = new action_link (
new moodle_url ( $baseurl , array ( 'id' => $mod -> id , 'move' => '-1' )),
new pix_icon ( 't/up' , $str -> moveup , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => 'editing_moveup' , 'title' => $str -> moveup )
);
$actions [] = new action_link (
new moodle_url ( $baseurl , array ( 'id' => $mod -> id , 'move' => '1' )),
new pix_icon ( 't/down' , $str -> movedown , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => 'editing_movedown' , 'title' => $str -> movedown )
);
}
}
// Update
$actions [] = new action_link (
new moodle_url ( $baseurl , array ( 'update' => $mod -> id )),
new pix_icon ( 't/edit' , $str -> update , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => 'editing_update' , 'title' => $str -> update )
);
2011-09-09 15:53:02 +02:00
// Duplicate (require both target import caps to be able to duplicate, see modduplicate.php)
$dupecaps = array ( 'moodle/backup:backuptargetimport' , 'moodle/restore:restoretargetimport' );
if ( has_all_capabilities ( $dupecaps , $coursecontext )) {
$actions [] = new action_link (
new moodle_url ( $baseurl , array ( 'duplicate' => $mod -> id )),
new pix_icon ( 't/copy' , $str -> duplicate , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => 'editing_duplicate' , 'title' => $str -> duplicate )
);
}
2011-08-25 18:02:35 +12:00
// Delete
$actions [] = new action_link (
new moodle_url ( $baseurl , array ( 'delete' => $mod -> id )),
new pix_icon ( 't/delete' , $str -> delete , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => 'editing_delete' , 'title' => $str -> delete )
);
// hideshow
2007-02-16 07:57:19 +00:00
if ( has_capability ( 'moodle/course:activityvisibility' , $modcontext )) {
if ( $mod -> visible ) {
2011-08-25 18:02:35 +12:00
$actions [] = new action_link (
new moodle_url ( $baseurl , array ( 'hide' => $mod -> id )),
new pix_icon ( 't/hide' , $str -> hide , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => 'editing_hide' , 'title' => $str -> hide )
);
2007-02-16 07:57:19 +00:00
} else {
2011-08-25 18:02:35 +12:00
$actions [] = new action_link (
new moodle_url ( $baseurl , array ( 'show' => $mod -> id )),
new pix_icon ( 't/show' , $str -> show , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => 'editing_show' , 'title' => $str -> show )
);
2007-02-16 07:57:19 +00:00
}
2003-07-14 13:08:38 +00:00
}
2008-04-25 14:03:17 +00:00
2011-08-25 18:02:35 +12:00
// groupmode
2004-01-31 08:40:38 +00:00
if ( $mod -> groupmode !== false ) {
if ( $mod -> groupmode == SEPARATEGROUPS ) {
2011-08-25 18:02:35 +12:00
$groupmode = 0 ;
2004-02-15 04:13:25 +00:00
$grouptitle = $str -> groupsseparate ;
2007-03-22 07:16:57 +00:00
$groupclass = 'editing_groupsseparate' ;
2011-08-25 18:02:35 +12:00
$groupimage = 't/groups' ;
2004-01-31 08:40:38 +00:00
} else if ( $mod -> groupmode == VISIBLEGROUPS ) {
2011-08-25 18:02:35 +12:00
$groupmode = 1 ;
2004-02-15 04:13:25 +00:00
$grouptitle = $str -> groupsvisible ;
2007-03-22 07:16:57 +00:00
$groupclass = 'editing_groupsvisible' ;
2011-08-25 18:02:35 +12:00
$groupimage = 't/groupv' ;
2004-02-15 04:13:25 +00:00
} else {
2011-08-25 18:02:35 +12:00
$groupmode = 2 ;
2004-02-15 04:13:25 +00:00
$grouptitle = $str -> groupsnone ;
2006-11-21 04:19:01 +00:00
$groupclass = 'editing_groupsnone' ;
2011-08-25 18:02:35 +12:00
$groupimage = 't/groupn' ;
2004-02-15 04:13:25 +00:00
}
if ( $mod -> groupmodelink ) {
2011-08-25 18:02:35 +12:00
$actions [] = new action_link (
new moodle_url ( $baseurl , array ( 'id' => $mod -> id , 'groupmode' => $groupmode )),
new pix_icon ( $groupimage , $grouptitle , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => $groupclass , 'title' => $grouptitle . ' (' . $str -> clicktochange . ')' )
);
2004-01-31 08:40:38 +00:00
} else {
2011-08-25 18:02:35 +12:00
$actions [] = new pix_icon ( $groupimage , $grouptitle , 'moodle' , array ( 'title' => $grouptitle . ' (' . $str -> forcedmode . ')' , 'class' => 'iconsmall' ));
2004-01-31 08:40:38 +00:00
}
2003-07-14 13:08:38 +00:00
}
2011-08-25 18:02:35 +12:00
// Assign
if ( has_capability ( 'moodle/course:managegroups' , $modcontext )){
$actions [] = new action_link (
new moodle_url ( '/' . $CFG -> admin . '/roles/assign.php' , array ( 'contextid' => $modcontext -> id )),
new pix_icon ( 'i/roles' , $str -> assign , 'moodle' , array ( 'class' => 'iconsmall' )),
null ,
array ( 'class' => 'editing_assign' , 'title' => $str -> assign )
);
}
$output = html_writer :: start_tag ( 'span' , array ( 'class' => 'commands' ));
foreach ( $actions as $action ) {
if ( $action instanceof renderable ) {
$output .= $OUTPUT -> render ( $action );
2009-12-16 18:00:58 +00:00
} else {
2011-08-25 18:02:35 +12:00
$output .= $action ;
2007-02-16 07:57:19 +00:00
}
2005-03-14 19:05:39 +00:00
}
2011-08-25 18:02:35 +12:00
$output .= html_writer :: end_tag ( 'span' );
return $output ;
2002-08-02 17:38:18 +00:00
}
2005-01-24 22:21:28 +00:00
/**
2006-11-09 18:25:58 +00:00
* given a course object with shortname & fullname , this function will
2005-01-24 22:21:28 +00:00
* truncate the the number of chars allowed and add ... if it was too long
*/
function course_format_name ( $course , $max = 100 ) {
2006-11-09 18:25:58 +00:00
2011-09-07 11:46:28 +12:00
$context = get_context_instance ( CONTEXT_COURSE , $course -> id );
$shortname = format_string ( $course -> shortname , true , array ( 'context' => $context ));
2011-09-06 13:40:44 +12:00
$fullname = format_string ( $course -> fullname , true , array ( 'context' => get_context_instance ( CONTEXT_COURSE , $course -> id )));
2011-09-13 16:06:21 +08:00
$str = $shortname . ': ' . $fullname ;
2011-09-10 10:21:31 +02:00
if ( textlib :: strlen ( $str ) <= $max ) {
2005-01-24 22:21:28 +00:00
return $str ;
}
else {
2011-09-10 10:21:31 +02:00
return textlib :: substr ( $str , 0 , $max - 3 ) . '...' ;
2005-01-24 22:21:28 +00:00
}
}
2008-06-01 19:05:07 +00:00
function update_restricted_mods ( $course , $mods ) {
global $DB ;
2008-02-21 15:17:41 +00:00
/// Delete all the current restricted list
2008-06-01 19:05:07 +00:00
$DB -> delete_records ( 'course_allowed_modules' , array ( 'course' => $course -> id ));
2008-02-21 15:17:41 +00:00
2005-08-16 06:15:49 +00:00
if ( empty ( $course -> restrictmodules )) {
2008-02-21 15:17:41 +00:00
return ; // We're done
2005-08-16 06:15:49 +00:00
}
2008-02-21 15:17:41 +00:00
/// Insert the new list of restricted mods
foreach ( $mods as $mod ) {
if ( $mod == 0 ) {
continue ; // this is the 'allow none' option
2005-08-16 06:15:49 +00:00
}
2010-09-21 08:13:11 +00:00
$am = new stdClass ();
2008-02-21 15:17:41 +00:00
$am -> course = $course -> id ;
$am -> module = $mod ;
2008-06-01 19:05:07 +00:00
$DB -> insert_record ( 'course_allowed_modules' , $am );
2005-08-16 06:15:49 +00:00
}
}
/**
* This function will take an int ( module id ) or a string ( module name )
* and return true or false , whether it ' s allowed in the given course ( object )
2006-11-09 18:25:58 +00:00
* $mod is not allowed to be an object , as the field for the module id is inconsistent
2005-08-16 06:15:49 +00:00
* depending on where in the code it ' s called from ( sometimes $mod -> id , sometimes $mod -> module )
*/
function course_allowed_module ( $course , $mod ) {
2008-06-01 19:05:07 +00:00
global $DB ;
2008-06-04 06:38:03 +00:00
2005-08-16 06:15:49 +00:00
if ( empty ( $course -> restrictmodules )) {
return true ;
}
2006-11-09 18:25:58 +00:00
2008-02-21 15:17:41 +00:00
// Admins and admin-like people who can edit everything can also add anything.
2010-09-17 12:16:27 +00:00
// Originally there was a course:update test only, but it did not match the test in course edit form
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( has_capability ( 'moodle/site:config' , get_context_instance ( CONTEXT_SYSTEM ))) {
2005-08-16 06:15:49 +00:00
return true ;
}
2008-02-21 15:17:41 +00:00
2005-08-16 06:15:49 +00:00
if ( is_numeric ( $mod )) {
$modid = $mod ;
} else if ( is_string ( $mod )) {
2008-06-01 19:05:07 +00:00
$modid = $DB -> get_field ( 'modules' , 'id' , array ( 'name' => $mod ));
2005-08-16 06:15:49 +00:00
}
if ( empty ( $modid )) {
return false ;
}
2008-06-04 06:38:03 +00:00
2008-06-01 19:05:07 +00:00
return $DB -> record_exists ( 'course_allowed_modules' , array ( 'course' => $course -> id , 'module' => $modid ));
2005-08-16 06:15:49 +00:00
}
2008-05-13 21:52:38 +00:00
/**
* Recursively delete category including all subcategories and courses .
2010-09-17 12:04:48 +00:00
* @ param stdClass $category
2009-04-16 07:48:34 +00:00
* @ param boolean $showfeedback display some notices
* @ return array return deleted courses
2008-05-13 21:52:38 +00:00
*/
function category_delete_full ( $category , $showfeedback = true ) {
2008-06-01 19:05:07 +00:00
global $CFG , $DB ;
2008-05-13 21:52:38 +00:00
require_once ( $CFG -> libdir . '/gradelib.php' );
require_once ( $CFG -> libdir . '/questionlib.php' );
2010-04-23 09:14:36 +00:00
require_once ( $CFG -> dirroot . '/cohort/lib.php' );
2008-05-13 21:52:38 +00:00
2008-06-01 19:05:07 +00:00
if ( $children = $DB -> get_records ( 'course_categories' , array ( 'parent' => $category -> id ), 'sortorder ASC' )) {
2008-05-13 21:52:38 +00:00
foreach ( $children as $childcat ) {
2009-04-16 07:48:34 +00:00
category_delete_full ( $childcat , $showfeedback );
2008-05-13 21:52:38 +00:00
}
}
2009-04-16 07:48:34 +00:00
$deletedcourses = array ();
2008-06-01 19:05:07 +00:00
if ( $courses = $DB -> get_records ( 'course' , array ( 'category' => $category -> id ), 'sortorder ASC' )) {
2008-05-13 21:52:38 +00:00
foreach ( $courses as $course ) {
2008-07-06 17:57:06 +00:00
if ( ! delete_course ( $course , false )) {
2009-04-16 07:48:34 +00:00
throw new moodle_exception ( 'cannotdeletecategorycourse' , '' , '' , $course -> shortname );
2008-05-13 21:52:38 +00:00
}
2009-04-16 07:48:34 +00:00
$deletedcourses [] = $course ;
2008-05-13 21:52:38 +00:00
}
}
2010-04-23 09:14:36 +00:00
// move or delete cohorts in this context
cohort_delete_category ( $category );
2008-05-13 21:52:38 +00:00
// now delete anything that may depend on course category context
grade_course_category_delete ( $category -> id , 0 , $showfeedback );
if ( ! question_delete_course_category ( $category , 0 , $showfeedback )) {
2009-04-16 07:48:34 +00:00
throw new moodle_exception ( 'cannotdeletecategoryquestions' , '' , '' , $category -> name );
2008-05-13 21:52:38 +00:00
}
// finally delete the category and it's context
2008-06-01 19:05:07 +00:00
$DB -> delete_records ( 'course_categories' , array ( 'id' => $category -> id ));
2008-05-13 21:52:38 +00:00
delete_context ( CONTEXT_COURSECAT , $category -> id );
2008-07-06 17:57:06 +00:00
events_trigger ( 'course_category_deleted' , $category );
2008-05-13 21:52:38 +00:00
2009-08-07 07:18:01 +00:00
return $deletedcourses ;
2008-05-13 21:52:38 +00:00
}
/**
* Delete category , but move contents to another category .
* @ param object $ccategory
* @ param int $newparentid category id
* @ return bool status
*/
function category_delete_move ( $category , $newparentid , $showfeedback = true ) {
2009-08-18 04:58:26 +00:00
global $CFG , $DB , $OUTPUT ;
2008-05-13 21:52:38 +00:00
require_once ( $CFG -> libdir . '/gradelib.php' );
require_once ( $CFG -> libdir . '/questionlib.php' );
2010-04-23 09:14:36 +00:00
require_once ( $CFG -> dirroot . '/cohort/lib.php' );
2008-05-13 21:52:38 +00:00
2008-06-01 19:05:07 +00:00
if ( ! $newparentcat = $DB -> get_record ( 'course_categories' , array ( 'id' => $newparentid ))) {
2008-05-13 21:52:38 +00:00
return false ;
}
2008-06-01 19:05:07 +00:00
if ( $children = $DB -> get_records ( 'course_categories' , array ( 'parent' => $category -> id ), 'sortorder ASC' )) {
2008-05-13 21:52:38 +00:00
foreach ( $children as $childcat ) {
2009-02-17 16:33:32 +00:00
move_category ( $childcat , $newparentcat );
2008-05-13 21:52:38 +00:00
}
}
2008-06-01 19:05:07 +00:00
if ( $courses = $DB -> get_records ( 'course' , array ( 'category' => $category -> id ), 'sortorder ASC' , 'id' )) {
2008-05-13 21:52:38 +00:00
if ( ! move_courses ( array_keys ( $courses ), $newparentid )) {
2009-08-18 04:58:26 +00:00
echo $OUTPUT -> notification ( " Error moving courses " );
2008-05-13 21:52:38 +00:00
return false ;
}
2009-08-18 04:58:26 +00:00
echo $OUTPUT -> notification ( get_string ( 'coursesmovedout' , '' , format_string ( $category -> name )), 'notifysuccess' );
2008-05-13 21:52:38 +00:00
}
2010-04-23 09:14:36 +00:00
// move or delete cohorts in this context
cohort_delete_category ( $category );
2008-05-13 21:52:38 +00:00
// now delete anything that may depend on course category context
grade_course_category_delete ( $category -> id , $newparentid , $showfeedback );
if ( ! question_delete_course_category ( $category , $newparentcat , $showfeedback )) {
2009-08-18 04:58:26 +00:00
echo $OUTPUT -> notification ( get_string ( 'errordeletingquestionsfromcategory' , 'question' , $category ), 'notifysuccess' );
2008-05-13 21:52:38 +00:00
return false ;
}
// finally delete the category and it's context
2008-06-01 19:05:07 +00:00
$DB -> delete_records ( 'course_categories' , array ( 'id' => $category -> id ));
2008-05-13 21:52:38 +00:00
delete_context ( CONTEXT_COURSECAT , $category -> id );
2008-07-06 17:57:06 +00:00
events_trigger ( 'course_category_deleted' , $category );
2008-05-13 21:52:38 +00:00
2009-08-18 04:58:26 +00:00
echo $OUTPUT -> notification ( get_string ( 'coursecategorydeleted' , '' , format_string ( $category -> name )), 'notifysuccess' );
2008-05-13 21:52:38 +00:00
return true ;
}
2008-06-01 19:05:07 +00:00
/**
* Efficiently moves many courses around while maintaining
* sortorder in order .
*
2010-09-17 12:04:48 +00:00
* @ param array $courseids is an array of course ids
* @ param int $categoryid
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
* @ return bool success
2008-06-01 19:05:07 +00:00
*/
function move_courses ( $courseids , $categoryid ) {
2009-08-18 04:58:26 +00:00
global $CFG , $DB , $OUTPUT ;
2005-09-01 04:48:22 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( empty ( $courseids )) {
// nothing to do
return ;
}
2006-11-09 18:25:58 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( ! $category = $DB -> get_record ( 'course_categories' , array ( 'id' => $categoryid ))) {
return false ;
}
2007-09-19 07:14:23 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$courseids = array_reverse ( $courseids );
2011-07-14 11:00:09 +08:00
$newparent = get_context_instance ( CONTEXT_COURSECAT , $category -> id );
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$i = 1 ;
2008-06-16 14:25:53 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
foreach ( $courseids as $courseid ) {
if ( $course = $DB -> get_record ( 'course' , array ( 'id' => $courseid ), 'id, category' )) {
2011-07-14 11:00:09 +08:00
$course = new stdClass ();
$course -> id = $courseid ;
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$course -> category = $category -> id ;
$course -> sortorder = $category -> sortorder + MAX_COURSES_IN_CATEGORY - $i ++ ;
if ( $category -> visible == 0 ) {
// hide the course when moving into hidden category,
// do not update the visibleold flag - we want to get to previous state if somebody unhides the category
$course -> visible = 0 ;
2005-09-01 04:48:22 +00:00
}
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$DB -> update_record ( 'course' , $course );
$context = get_context_instance ( CONTEXT_COURSE , $course -> id );
context_moved ( $context , $newparent );
2006-11-09 18:25:58 +00:00
}
2008-06-16 14:25:53 +00:00
}
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
fix_course_sortorder ();
2005-09-01 04:48:22 +00:00
return true ;
}
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
/**
* Hide course category and child course and subcategories
2010-09-17 12:04:48 +00:00
* @ param stdClass $category
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
* @ return void
*/
function course_category_hide ( $category ) {
global $DB ;
$category -> visible = 0 ;
$DB -> set_field ( 'course_categories' , 'visible' , 0 , array ( 'id' => $category -> id ));
$DB -> set_field ( 'course_categories' , 'visibleold' , 0 , array ( 'id' => $category -> id ));
$DB -> execute ( " UPDATE { course} SET visibleold = visible WHERE category = ? " , array ( $category -> id )); // store visible flag so that we can return to it if we immediately unhide
$DB -> set_field ( 'course' , 'visible' , 0 , array ( 'category' => $category -> id ));
// get all child categories and hide too
if ( $subcats = $DB -> get_records_select ( 'course_categories' , " path LIKE ? " , array ( " $category->path /% " ))) {
foreach ( $subcats as $cat ) {
$DB -> set_field ( 'course_categories' , 'visibleold' , $cat -> visible , array ( 'id' => $cat -> id ));
$DB -> set_field ( 'course_categories' , 'visible' , 0 , array ( 'id' => $cat -> id ));
$DB -> execute ( " UPDATE { course} SET visibleold = visible WHERE category = ? " , array ( $cat -> id ));
$DB -> set_field ( 'course' , 'visible' , 0 , array ( 'category' => $cat -> id ));
}
}
}
/**
* Show course category and child course and subcategories
2010-09-17 12:04:48 +00:00
* @ param stdClass $category
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
* @ return void
*/
function course_category_show ( $category ) {
global $DB ;
$category -> visible = 1 ;
$DB -> set_field ( 'course_categories' , 'visible' , 1 , array ( 'id' => $category -> id ));
$DB -> set_field ( 'course_categories' , 'visibleold' , 1 , array ( 'id' => $category -> id ));
$DB -> execute ( " UPDATE { course} SET visible = visibleold WHERE category = ? " , array ( $category -> id ));
// get all child categories and unhide too
if ( $subcats = $DB -> get_records_select ( 'course_categories' , " path LIKE ? " , array ( " $category->path /% " ))) {
foreach ( $subcats as $cat ) {
if ( $cat -> visibleold ) {
$DB -> set_field ( 'course_categories' , 'visible' , 1 , array ( 'id' => $cat -> id ));
}
$DB -> execute ( " UPDATE { course} SET visible = visibleold WHERE category = ? " , array ( $cat -> id ));
}
}
}
2008-06-01 19:05:07 +00:00
/**
* Efficiently moves a category - NOTE that this can have
* a huge impact access - control - wise ...
*/
2009-02-17 16:33:32 +00:00
function move_category ( $category , $newparentcat ) {
2008-06-01 19:05:07 +00:00
global $CFG , $DB ;
2007-09-19 07:14:23 +00:00
2007-10-02 22:34:12 +00:00
$context = get_context_instance ( CONTEXT_COURSECAT , $category -> id );
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$hidecat = false ;
2007-10-02 22:34:12 +00:00
if ( empty ( $newparentcat -> id )) {
2009-02-17 16:33:32 +00:00
$DB -> set_field ( 'course_categories' , 'parent' , 0 , array ( 'id' => $category -> id ));
2008-06-16 14:25:53 +00:00
2007-10-02 22:34:12 +00:00
$newparent = get_context_instance ( CONTEXT_SYSTEM );
2008-06-16 14:25:53 +00:00
2007-10-02 22:34:12 +00:00
} else {
2009-02-17 16:33:32 +00:00
$DB -> set_field ( 'course_categories' , 'parent' , $newparentcat -> id , array ( 'id' => $category -> id ));
2007-10-02 22:34:12 +00:00
$newparent = get_context_instance ( CONTEXT_COURSECAT , $newparentcat -> id );
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( ! $newparentcat -> visible and $category -> visible ) {
// better hide category when moving into hidden category, teachers may unhide afterwards and the hidden children will be restored properly
$hidecat = true ;
}
2007-09-19 07:14:23 +00:00
}
context_moved ( $context , $newparent );
2008-08-08 05:25:54 +00:00
// now make it last in new category
2008-06-16 14:25:53 +00:00
$DB -> set_field ( 'course_categories' , 'sortorder' , MAX_COURSES_IN_CATEGORY * MAX_COURSE_CATEGORIES , array ( 'id' => $category -> id ));
// and fix the sortorders
2007-09-19 07:14:23 +00:00
fix_course_sortorder ();
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( $hidecat ) {
course_category_hide ( $category );
}
2007-09-19 07:14:23 +00:00
}
2006-12-11 15:47:23 +00:00
/**
2010-06-08 06:21:25 +00:00
* Returns the display name of the given section that the course prefers .
*
* This function utilizes a callback that can be implemented within the course
* formats lib . php file to customize the display name that is used to reference
* the section .
*
* By default ( if callback is not defined ) the method
* { @ see get_numeric_section_name } is called instead .
*
* @ param stdClass $course The course to get the section name for
* @ param stdClass $section Section object from database
* @ return Display name that the course format prefers , e . g . " Week 2 "
*
* @ see get_generic_section_name
2006-12-11 15:47:23 +00:00
*/
2010-06-08 06:21:25 +00:00
function get_section_name ( stdClass $course , stdClass $section ) {
global $CFG ;
/// Inelegant hack for bug 3408
if ( $course -> format == 'site' ) {
return get_string ( 'site' );
}
// Use course formatter callback if it exists
$namingfile = $CFG -> dirroot . '/course/format/' . $course -> format . '/lib.php' ;
$namingfunction = 'callback_' . $course -> format . '_get_section_name' ;
if ( ! function_exists ( $namingfunction ) && file_exists ( $namingfile )) {
require_once $namingfile ;
}
if ( function_exists ( $namingfunction )) {
return $namingfunction ( $course , $section );
}
// else, default behavior:
return get_generic_section_name ( $course -> format , $section );
}
/**
* Gets the generic section name for a courses section .
2010-06-17 22:50:25 +00:00
*
2010-06-08 06:21:25 +00:00
* @ param string $format Course format ID e . g . 'weeks' $course -> format
* @ param stdClass $section Section object from database
* @ return Display name that the course format prefers , e . g . " Week 2 "
*/
function get_generic_section_name ( $format , stdClass $section ) {
return get_string ( 'sectionname' , " format_ $format " ) . ' ' . $section -> section ;
}
function course_format_uses_sections ( $format ) {
global $CFG ;
$featurefile = $CFG -> dirroot . '/course/format/' . $format . '/lib.php' ;
$featurefunction = 'callback_' . $format . '_uses_sections' ;
if ( ! function_exists ( $featurefunction ) && file_exists ( $featurefile )) {
require_once $featurefile ;
}
if ( function_exists ( $featurefunction )) {
return $featurefunction ();
}
return false ;
2006-12-11 15:47:23 +00:00
}
2010-11-09 11:54:58 +00:00
/**
* Returns the information about the ajax support in the given source format
*
* The returned object ' s property ( boolean ) capable indicates that
* the course format supports Moodle course ajax features .
* The property ( array ) testedbrowsers can be used as a parameter for { @ see ajaxenabled ()} .
*
* @ param string $format
* @ return stdClass
*/
function course_format_ajax_support ( $format ) {
global $CFG ;
// set up default values
$ajaxsupport = new stdClass ();
$ajaxsupport -> capable = false ;
$ajaxsupport -> testedbrowsers = array ();
// get the information from the course format library
$featurefile = $CFG -> dirroot . '/course/format/' . $format . '/lib.php' ;
$featurefunction = 'callback_' . $format . '_ajax_support' ;
if ( ! function_exists ( $featurefunction ) && file_exists ( $featurefile )) {
require_once $featurefile ;
}
if ( function_exists ( $featurefunction )) {
$formatsupport = $featurefunction ();
if ( isset ( $formatsupport -> capable )) {
$ajaxsupport -> capable = $formatsupport -> capable ;
}
if ( is_array ( $formatsupport -> testedbrowsers )) {
$ajaxsupport -> testedbrowsers = $formatsupport -> testedbrowsers ;
}
}
return $ajaxsupport ;
}
2007-02-16 08:46:55 +00:00
/**
* Can the current user delete this course ?
2009-05-04 19:56:32 +00:00
* Course creators have exception ,
* 1 day after the creation they can sill delete the course .
2007-02-16 08:46:55 +00:00
* @ param int $courseid
* @ return boolean
*/
function can_delete_course ( $courseid ) {
2009-05-04 19:56:32 +00:00
global $USER , $DB ;
2007-02-16 08:46:55 +00:00
$context = get_context_instance ( CONTEXT_COURSE , $courseid );
2009-05-04 19:56:32 +00:00
if ( has_capability ( 'moodle/course:delete' , $context )) {
return true ;
}
// hack: now try to find out if creator created this course recently (1 day)
if ( ! has_capability ( 'moodle/course:create' , $context )) {
return false ;
}
$since = time () - 60 * 60 * 24 ;
$params = array ( 'userid' => $USER -> id , 'url' => " view.php?id= $courseid " , 'since' => $since );
$select = " module = 'course' AND action = 'new' AND userid = :userid AND url = :url AND time > :since " ;
return $DB -> record_exists_select ( 'log' , $select , $params );
2007-02-16 08:46:55 +00:00
}
2008-11-13 08:11:10 +00:00
/**
* Save the Your name for 'Some role' strings .
*
* @ param integer $courseid the id of this course .
* @ param array $data the data that came from the course settings form .
*/
function save_local_role_names ( $courseid , $data ) {
global $DB ;
$context = get_context_instance ( CONTEXT_COURSE , $courseid );
foreach ( $data as $fieldname => $value ) {
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( strpos ( $fieldname , 'role_' ) !== 0 ) {
2008-11-13 08:11:10 +00:00
continue ;
}
list ( $ignored , $roleid ) = explode ( '_' , $fieldname );
// make up our mind whether we want to delete, update or insert
if ( ! $value ) {
$DB -> delete_records ( 'role_names' , array ( 'contextid' => $context -> id , 'roleid' => $roleid ));
} else if ( $rolename = $DB -> get_record ( 'role_names' , array ( 'contextid' => $context -> id , 'roleid' => $roleid ))) {
$rolename -> name = $value ;
$DB -> update_record ( 'role_names' , $rolename );
} else {
$rolename = new stdClass ;
$rolename -> contextid = $context -> id ;
$rolename -> roleid = $roleid ;
$rolename -> name = $value ;
$DB -> insert_record ( 'role_names' , $rolename );
}
}
}
2007-02-16 08:46:55 +00:00
2008-05-30 16:47:21 +00:00
/**
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
* Create a course and either return a $course object
*
* Please note this functions does not verify any access control ,
* the calling code is responsible for all validation ( usually it is the form definition ) .
2007-03-23 02:29:05 +00:00
*
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
* @ param array $editoroptions course description editor options
2007-03-23 02:29:05 +00:00
* @ param object $data - all the data needed for an entry in the 'course' table
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
* @ return object new course instance
2007-03-23 02:29:05 +00:00
*/
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
function create_course ( $data , $editoroptions = NULL ) {
global $CFG , $DB ;
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
//check the categoryid - must be given for all new courses
$category = $DB -> get_record ( 'course_categories' , array ( 'id' => $data -> category ), '*' , MUST_EXIST );
2009-03-20 06:53:03 +00:00
//check if the shortname already exist
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( ! empty ( $data -> shortname )) {
if ( $DB -> record_exists ( 'course' , array ( 'shortname' => $data -> shortname ))) {
2009-03-20 06:53:03 +00:00
throw new moodle_exception ( 'shortnametaken' );
}
}
//check if the id number already exist
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( ! empty ( $data -> idnumber )) {
if ( $DB -> record_exists ( 'course' , array ( 'idnumber' => $data -> idnumber ))) {
2009-03-20 06:53:03 +00:00
throw new moodle_exception ( 'idnumbertaken' );
}
}
2009-08-07 07:18:01 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$data -> timecreated = time ();
$data -> timemodified = $data -> timecreated ;
2009-03-20 06:53:03 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
// place at beginning of any category
$data -> sortorder = 0 ;
2009-05-08 14:24:56 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( $editoroptions ) {
// summary text is updated later, we need context to store the files first
$data -> summary = '' ;
$data -> summary_format = FORMAT_HTML ;
}
2010-07-14 14:23:32 +00:00
if ( ! isset ( $data -> visible )) {
// data not from form, add missing visibility info
2010-07-19 17:44:08 +00:00
$data -> visible = $category -> visible ;
2007-03-23 02:29:05 +00:00
}
2010-07-14 14:23:32 +00:00
$data -> visibleold = $data -> visible ;
2007-02-16 08:46:55 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$newcourseid = $DB -> insert_record ( 'course' , $data );
$context = get_context_instance ( CONTEXT_COURSE , $newcourseid , MUST_EXIST );
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( $editoroptions ) {
// Save the files used in the summary editor and store
2010-07-03 13:37:13 +00:00
$data = file_postupdate_standard_editor ( $data , 'summary' , $editoroptions , $context , 'course' , 'summary' , 0 );
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$DB -> set_field ( 'course' , 'summary' , $data -> summary , array ( 'id' => $newcourseid ));
$DB -> set_field ( 'course' , 'summaryformat' , $data -> summary_format , array ( 'id' => $newcourseid ));
}
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$course = $DB -> get_record ( 'course' , array ( 'id' => $newcourseid ));
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
// Setup the blocks
blocks_add_default_course_blocks ( $course );
2007-03-23 02:29:05 +00:00
2010-09-21 08:13:11 +00:00
$section = new stdClass ();
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$section -> course = $course -> id ; // Create a default section.
$section -> section = 0 ;
$section -> summaryformat = FORMAT_HTML ;
$DB -> insert_record ( 'course_sections' , $section );
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
fix_course_sortorder ();
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
// update module restrictions
if ( $course -> restrictmodules ) {
if ( isset ( $data -> allowedmods )) {
2010-09-17 12:08:10 +00:00
update_restricted_mods ( $course , $data -> allowedmods );
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
} else {
if ( ! empty ( $CFG -> defaultallowedmodules )) {
update_restricted_mods ( $course , explode ( ',' , $CFG -> defaultallowedmodules ));
}
}
}
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
// new context created - better mark it as dirty
mark_context_dirty ( $context -> path );
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
// Save any custom role names.
2010-09-17 12:04:48 +00:00
save_local_role_names ( $course -> id , ( array ) $data );
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
// set up enrolments
enrol_course_updated ( true , $course , $data );
2008-11-13 08:11:10 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
add_to_log ( SITEID , 'course' , 'new' , 'view.php?id=' . $course -> id , $data -> fullname . ' (ID ' . $course -> id . ')' );
2008-07-06 17:57:06 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
// Trigger events
events_trigger ( 'course_created' , $course );
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
return $course ;
2007-03-23 02:29:05 +00:00
}
2008-05-30 16:47:21 +00:00
/**
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
* Update a course .
*
* Please note this functions does not verify any access control ,
* the calling code is responsible for all validation ( usually it is the form definition ) .
2007-03-23 02:29:05 +00:00
*
* @ param object $data - all the data needed for an entry in the 'course' table
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
* @ param array $editoroptions course description editor options
* @ return void
2007-03-23 02:29:05 +00:00
*/
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
function update_course ( $data , $editoroptions = NULL ) {
global $CFG , $DB ;
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$data -> timemodified = time ();
2008-02-21 15:17:41 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$oldcourse = $DB -> get_record ( 'course' , array ( 'id' => $data -> id ), '*' , MUST_EXIST );
$context = get_context_instance ( CONTEXT_COURSE , $oldcourse -> id );
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( $editoroptions ) {
2010-07-03 13:37:13 +00:00
$data = file_postupdate_standard_editor ( $data , 'summary' , $editoroptions , $context , 'course' , 'summary' , 0 );
2009-03-20 06:53:03 +00:00
}
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( ! isset ( $data -> category ) or empty ( $data -> category )) {
// prevent nulls and 0 in category field
2007-03-23 02:29:05 +00:00
unset ( $data -> category );
}
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$movecat = ( isset ( $data -> category ) and $oldcourse -> category != $data -> category );
2007-03-23 02:29:05 +00:00
2010-07-14 14:23:32 +00:00
if ( ! isset ( $data -> visible )) {
// data not from form, add missing visibility info
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$data -> visible = $oldcourse -> visible ;
}
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( $data -> visible != $oldcourse -> visible ) {
// reset the visibleold flag when manually hiding/unhiding course
$data -> visibleold = $data -> visible ;
} else {
2007-09-19 07:13:57 +00:00
if ( $movecat ) {
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$newcategory = $DB -> get_record ( 'course_categories' , array ( 'id' => $data -> category ));
if ( empty ( $newcategory -> visible )) {
// make sure when moving into hidden category the course is hidden automatically
$data -> visible = 0 ;
}
2007-09-19 07:13:57 +00:00
}
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
}
2007-09-19 07:13:57 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
// Update with the new data
$DB -> update_record ( 'course' , $data );
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
$course = $DB -> get_record ( 'course' , array ( 'id' => $data -> id ));
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
if ( $movecat ) {
$newparent = get_context_instance ( CONTEXT_COURSECAT , $course -> category );
context_moved ( $context , $newparent );
}
2008-06-04 06:38:03 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
fix_course_sortorder ();
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
// Test for and remove blocks which aren't appropriate anymore
blocks_remove_inappropriate ( $course );
2007-03-23 02:29:05 +00:00
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
// update module restrictions
if ( isset ( $data -> allowedmods )) {
2010-07-15 18:24:20 +00:00
update_restricted_mods ( $course , $data -> allowedmods );
2007-03-23 02:29:05 +00:00
}
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
// Save any custom role names.
save_local_role_names ( $course -> id , $data );
// update enrol settings
enrol_course_updated ( false , $course , $data );
add_to_log ( $course -> id , " course " , " update " , " edit.php?id= $course->id " , $course -> id );
// Trigger events
events_trigger ( 'course_updated' , $course );
2007-03-23 02:29:05 +00:00
}
2007-02-16 08:46:55 +00:00
2010-05-01 05:05:55 +00:00
/**
2010-10-18 08:01:32 +00:00
* Average number of participants
2010-05-01 05:05:55 +00:00
* @ return integer
*/
function average_number_of_participants () {
2010-10-18 08:01:32 +00:00
global $DB , $SITE ;
//count total of enrolments for visible course (except front page)
$sql = ' SELECT COUNT ( * ) FROM (
SELECT DISTINCT ue . userid , e . courseid
FROM { user_enrolments } ue , { enrol } e , { course } c
2010-11-17 06:23:56 +00:00
WHERE ue . enrolid = e . id
2010-10-18 08:01:32 +00:00
AND e . courseid <> : siteid
AND c . id = e . courseid
AND c . visible = 1 ) as total ' ;
$params = array ( 'siteid' => $SITE -> id );
$enrolmenttotal = $DB -> count_records_sql ( $sql , $params );
//count total of visible courses (minus front page)
$coursetotal = $DB -> count_records ( 'course' , array ( 'visible' => 1 ));
$coursetotal = $coursetotal - 1 ;
//average of enrolment
if ( empty ( $coursetotal )) {
$participantaverage = 0 ;
} else {
$participantaverage = $enrolmenttotal / $coursetotal ;
}
return $participantaverage ;
2010-05-01 05:05:55 +00:00
}
/**
2010-10-18 08:01:32 +00:00
* Average number of course modules
2010-05-01 05:05:55 +00:00
* @ return integer
*/
function average_number_of_courses_modules () {
2010-10-18 08:01:32 +00:00
global $DB , $SITE ;
//count total of visible course module (except front page)
$sql = ' SELECT COUNT ( * ) FROM (
SELECT cm . course , cm . module
FROM { course } c , { course_modules } cm
2010-11-17 06:23:56 +00:00
WHERE c . id = cm . course
2010-10-18 08:01:32 +00:00
AND c . id <> : siteid
AND cm . visible = 1
AND c . visible = 1 ) as total ' ;
$params = array ( 'siteid' => $SITE -> id );
$moduletotal = $DB -> count_records_sql ( $sql , $params );
//count total of visible courses (minus front page)
$coursetotal = $DB -> count_records ( 'course' , array ( 'visible' => 1 ));
$coursetotal = $coursetotal - 1 ;
//average of course module
if ( empty ( $coursetotal )) {
$coursemoduleaverage = 0 ;
} else {
$coursemoduleaverage = $moduletotal / $coursetotal ;
}
return $coursemoduleaverage ;
2010-05-01 05:05:55 +00:00
}
2009-11-04 06:14:06 +00:00
/**
* This class pertains to course requests and contains methods associated with
* create , approving , and removing course requests .
*
2010-07-03 13:37:13 +00:00
* Please note we do not allow embedded images here because there is no context
* to store them with proper access control .
*
2009-11-04 06:14:06 +00:00
* @ copyright 2009 Sam Hemelryk
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
* @ since Moodle 2.0
*
* @ property - read int $id
* @ property - read string $fullname
* @ property - read string $shortname
* @ property - read string $summary
* @ property - read int $summaryformat
* @ property - read int $summarytrust
* @ property - read string $reason
* @ property - read int $requester
*/
class course_request {
/**
* This is the stdClass that stores the properties for the course request
2010-09-17 12:16:27 +00:00
* and is externally accessed through the __get magic method
2009-11-04 06:14:06 +00:00
* @ var stdClass
*/
protected $properties ;
/**
* An array of options for the summary editor used by course request forms .
* This is initially set by { @ link summary_editor_options ()}
* @ var array
* @ static
*/
protected static $summaryeditoroptions ;
/**
* Static function to prepare the summary editor for working with a course
* request .
*
* @ static
* @ param null | stdClass $data Optional , an object containing the default values
* for the form , these may be modified when preparing the
* editor so this should be called before creating the form
* @ return stdClass An object that can be used to set the default values for
* an mforms form
*/
public static function prepare ( $data = null ) {
if ( $data === null ) {
$data = new stdClass ;
}
2010-07-03 13:37:13 +00:00
$data = file_prepare_standard_editor ( $data , 'summary' , self :: summary_editor_options ());
2009-11-04 06:14:06 +00:00
return $data ;
}
/**
* Static function to create a new course request when passed an array of properties
* for it .
*
* This function also handles saving any files that may have been used in the editor
*
* @ static
* @ param stdClass $data
* @ return course_request The newly created course request
*/
public static function create ( $data ) {
global $USER , $DB , $CFG ;
$data -> requester = $USER -> id ;
2010-07-03 13:37:13 +00:00
// Summary is a required field so copy the text over
$data -> summary = $data -> summary_editor [ 'text' ];
$data -> summaryformat = $data -> summary_editor [ 'format' ];
2009-11-04 06:14:06 +00:00
$data -> id = $DB -> insert_record ( 'course_request' , $data );
2010-07-03 13:37:13 +00:00
2009-11-04 06:14:06 +00:00
// Create a new course_request object and return it
$request = new course_request ( $data );
// Notify the admin if required.
2010-05-18 16:59:08 +00:00
if ( $users = get_users_from_config ( $CFG -> courserequestnotify , 'moodle/site:approvecourse' )) {
2009-11-04 08:11:02 +00:00
2009-11-04 06:14:06 +00:00
$a = new stdClass ;
$a -> link = " $CFG->wwwroot /course/pending.php " ;
$a -> user = fullname ( $USER );
$subject = get_string ( 'courserequest' );
$message = get_string ( 'courserequestnotifyemail' , 'admin' , $a );
foreach ( $users as $user ) {
2010-08-01 09:52:54 +00:00
$request -> notify ( $user , $USER , 'courserequested' , $subject , $message );
2009-11-04 06:14:06 +00:00
}
}
return $request ;
}
/**
* Returns an array of options to use with a summary editor
*
* @ uses course_request :: $summaryeditoroptions
* @ return array An array of options to use with the editor
*/
public static function summary_editor_options () {
global $CFG ;
if ( self :: $summaryeditoroptions === null ) {
2010-07-03 13:37:13 +00:00
self :: $summaryeditoroptions = array ( 'maxfiles' => 0 , 'maxbytes' => 0 );
2009-11-04 06:14:06 +00:00
}
return self :: $summaryeditoroptions ;
}
/**
* Loads the properties for this course request object . Id is required and if
* only id is provided then we load the rest of the properties from the database
*
* @ param stdClass | int $properties Either an object containing properties
* or the course_request id to load
*/
public function __construct ( $properties ) {
global $DB ;
if ( empty ( $properties -> id )) {
if ( empty ( $properties )) {
throw new coding_exception ( 'You must provide a course request id when creating a course_request object' );
}
$id = $properties ;
$properties = new stdClass ;
$properties -> id = ( int ) $id ;
unset ( $id );
}
if ( empty ( $properties -> requester )) {
if ( ! ( $this -> properties = $DB -> get_record ( 'course_request' , array ( 'id' => $properties -> id )))) {
print_error ( 'unknowncourserequest' );
}
} else {
$this -> properties = $properties ;
}
$this -> properties -> collision = null ;
}
/**
* Returns the requested property
*
* @ param string $key
* @ return mixed
*/
public function __get ( $key ) {
return $this -> properties -> $key ;
}
/**
* Override this to ensure empty ( $request -> blah ) calls return a reliable answer ...
*
* This is required because we define the __get method
*
* @ param mixed $key
* @ return bool True is it not empty , false otherwise
*/
public function __isset ( $key ) {
return ( ! empty ( $this -> properties -> $key ));
}
/**
* Returns the user who requested this course
*
* Uses a static var to cache the results and cut down the number of db queries
*
* @ staticvar array $requesters An array of cached users
* @ return stdClass The user who requested the course
*/
public function get_requester () {
global $DB ;
static $requesters = array ();
if ( ! array_key_exists ( $this -> properties -> requester , $requesters )) {
$requesters [ $this -> properties -> requester ] = $DB -> get_record ( 'user' , array ( 'id' => $this -> properties -> requester ));
}
return $requesters [ $this -> properties -> requester ];
}
/**
* Checks that the shortname used by the course does not conflict with any other
* courses that exist
*
* @ param string | null $shortnamemark The string to append to the requests shortname
* should a conflict be found
* @ return bool true is there is a conflict , false otherwise
*/
public function check_shortname_collision ( $shortnamemark = '[*]' ) {
global $DB ;
if ( $this -> properties -> collision !== null ) {
return $this -> properties -> collision ;
}
if ( empty ( $this -> properties -> shortname )) {
debugging ( 'Attempting to check a course request shortname before it has been set' , DEBUG_DEVELOPER );
$this -> properties -> collision = false ;
} else if ( $DB -> record_exists ( 'course' , array ( 'shortname' => $this -> properties -> shortname ))) {
if ( ! empty ( $shortnamemark )) {
$this -> properties -> shortname .= ' ' . $shortnamemark ;
}
$this -> properties -> collision = true ;
} else {
$this -> properties -> collision = false ;
}
return $this -> properties -> collision ;
}
/**
* This function approves the request turning it into a course
*
* This function converts the course request into a course , at the same time
2010-09-17 12:16:27 +00:00
* transferring any files used in the summary to the new course and then removing
2009-11-04 06:14:06 +00:00
* the course request and the files associated with it .
*
* @ return int The id of the course that was created from this request
*/
public function approve () {
global $CFG , $DB , $USER ;
2010-07-10 15:46:07 +00:00
$user = $DB -> get_record ( 'user' , array ( 'id' => $this -> properties -> requester , 'deleted' => 0 ), '*' , MUST_EXIST );
2009-11-04 06:14:06 +00:00
$category = get_course_category ( $CFG -> defaultrequestcategory );
$courseconfig = get_config ( 'moodlecourse' );
// Transfer appropriate settings
2010-07-10 15:46:07 +00:00
$data = clone ( $this -> properties );
unset ( $data -> id );
unset ( $data -> reason );
unset ( $data -> requester );
2009-11-04 06:14:06 +00:00
// Set category
2010-07-10 15:46:07 +00:00
$data -> category = $category -> id ;
$data -> sortorder = $category -> sortorder ; // place as the first in category
2009-11-04 06:14:06 +00:00
// Set misc settings
2010-07-10 15:46:07 +00:00
$data -> requested = 1 ;
2009-11-04 06:14:06 +00:00
if ( ! empty ( $CFG -> restrictmodulesfor ) && $CFG -> restrictmodulesfor != 'none' && ! empty ( $CFG -> restrictbydefault )) {
2010-07-10 15:46:07 +00:00
$data -> restrictmodules = 1 ;
2009-11-04 06:14:06 +00:00
}
// Apply course default settings
2010-07-10 15:46:07 +00:00
$data -> format = $courseconfig -> format ;
$data -> numsections = $courseconfig -> numsections ;
$data -> hiddensections = $courseconfig -> hiddensections ;
$data -> newsitems = $courseconfig -> newsitems ;
$data -> showgrades = $courseconfig -> showgrades ;
$data -> showreports = $courseconfig -> showreports ;
$data -> maxbytes = $courseconfig -> maxbytes ;
$data -> groupmode = $courseconfig -> groupmode ;
$data -> groupmodeforce = $courseconfig -> groupmodeforce ;
$data -> visible = $courseconfig -> visible ;
$data -> visibleold = $data -> visible ;
$data -> lang = $courseconfig -> lang ;
2009-11-04 06:14:06 +00:00
2010-07-10 15:46:07 +00:00
$course = create_course ( $data );
$context = get_context_instance ( CONTEXT_COURSE , $course -> id , MUST_EXIST );
2009-11-04 06:14:06 +00:00
2010-07-10 15:46:07 +00:00
// add enrol instances
if ( ! $DB -> record_exists ( 'enrol' , array ( 'courseid' => $course -> id , 'enrol' => 'manual' ))) {
if ( $manual = enrol_get_plugin ( 'manual' )) {
$manual -> add_default_instance ( $course );
}
2009-11-04 06:14:06 +00:00
}
2010-07-10 15:46:07 +00:00
// enrol the requester as teacher if necessary
if ( ! empty ( $CFG -> creatornewroleid ) and ! is_viewing ( $context , $user , 'moodle/role:assign' ) and ! is_enrolled ( $context , $user , 'moodle/role:assign' )) {
enrol_try_internal_enrol ( $course -> id , $user -> id , $CFG -> creatornewroleid );
}
$this -> delete ();
2010-09-21 08:13:11 +00:00
$a = new stdClass ();
2011-09-06 13:40:44 +12:00
$a -> name = format_string ( $course -> fullname , true , array ( 'context' => get_context_instance ( CONTEXT_COURSE , $course -> id )));
2010-07-10 15:46:07 +00:00
$a -> url = $CFG -> wwwroot . '/course/view.php?id=' . $course -> id ;
$this -> notify ( $user , $USER , 'courserequestapproved' , get_string ( 'courseapprovedsubject' ), get_string ( 'courseapprovedemail2' , 'moodle' , $a ));
return $course -> id ;
2009-11-04 06:14:06 +00:00
}
/**
* Reject a course request
*
* This function rejects a course request , emailing the requesting user the
* provided notice and then removing the request from the database
*
* @ param string $notice The message to display to the user
*/
public function reject ( $notice ) {
2010-07-10 15:46:07 +00:00
global $USER , $DB ;
$user = $DB -> get_record ( 'user' , array ( 'id' => $this -> properties -> requester ), '*' , MUST_EXIST );
2009-11-04 06:14:06 +00:00
$this -> notify ( $user , $USER , 'courserequestrejected' , get_string ( 'courserejectsubject' ), get_string ( 'courserejectemail' , 'moodle' , $notice ));
$this -> delete ();
}
/**
* Deletes the course request and any associated files
*/
public function delete () {
global $DB ;
$DB -> delete_records ( 'course_request' , array ( 'id' => $this -> properties -> id ));
}
/**
* Send a message from one user to another using events_trigger
*
* @ param object $touser
* @ param object $fromuser
* @ param string $name
* @ param string $subject
* @ param string $message
*/
protected function notify ( $touser , $fromuser , $name = 'courserequested' , $subject , $message ) {
2010-09-21 08:13:11 +00:00
$eventdata = new stdClass ();
2011-01-04 13:35:08 +08:00
$eventdata -> component = 'moodle' ;
2009-11-04 06:14:06 +00:00
$eventdata -> name = $name ;
$eventdata -> userfrom = $fromuser ;
$eventdata -> userto = $touser ;
$eventdata -> subject = $subject ;
$eventdata -> fullmessage = $message ;
$eventdata -> fullmessageformat = FORMAT_PLAIN ;
$eventdata -> fullmessagehtml = '' ;
$eventdata -> smallmessage = '' ;
2011-01-04 13:35:08 +08:00
$eventdata -> notification = 1 ;
2009-11-07 10:27:57 +00:00
message_send ( $eventdata );
2009-11-04 06:14:06 +00:00
}
2010-02-25 10:17:46 +00:00
}
MDL-26105 Block settings should contains less options, and be more user friendly
AMOS BEGIN
MOV [page-blog-index, pagetype], [page-blog-index, blog]
MOV [page-blog-x, pagetype], [page-blog-x, blog]
MOV [page-tag-x, pagetype], [page-tag-x, tag]
MOV [page-course-view-weeks, pagetype], [page-course-view-weeks, format_weeks]
MOV [page-course-view-weeks-x, pagetype], [page-course-view-weeks-x, format_weeks]
MOV [page-course-view-topics, pagetype], [page-course-view-topics, format_topics]
MOV [page-course-view-topics-x, pagetype], [page-course-view-topics-x, format_topics]
AMOS END
2011-04-28 11:20:30 +08:00
/**
* Return a list of page types
* @ param string $pagetype current page type
* @ param stdClass $parentcontext Block ' s parent context
* @ param stdClass $currentcontext Current context of block
*/
2011-06-17 16:23:10 +08:00
function course_page_type_list ( $pagetype , $parentcontext , $currentcontext ) {
MDL-26105 Block settings should contains less options, and be more user friendly
AMOS BEGIN
MOV [page-blog-index, pagetype], [page-blog-index, blog]
MOV [page-blog-x, pagetype], [page-blog-x, blog]
MOV [page-tag-x, pagetype], [page-tag-x, tag]
MOV [page-course-view-weeks, pagetype], [page-course-view-weeks, format_weeks]
MOV [page-course-view-weeks-x, pagetype], [page-course-view-weeks-x, format_weeks]
MOV [page-course-view-topics, pagetype], [page-course-view-topics, format_topics]
MOV [page-course-view-topics-x, pagetype], [page-course-view-topics-x, format_topics]
AMOS END
2011-04-28 11:20:30 +08:00
// if above course context ,display all course fomats
list ( $currentcontext , $course , $cm ) = get_context_info_array ( $currentcontext -> id );
if ( $course -> id == SITEID ) {
return array ( '*' => get_string ( 'page-x' , 'pagetype' ));
} else {
return array ( '*' => get_string ( 'page-x' , 'pagetype' ),
'course-*' => get_string ( 'page-course-x' , 'pagetype' ),
2011-06-30 15:30:34 +08:00
'course-view-*' => get_string ( 'page-course-view-x' , 'pagetype' )
MDL-26105 Block settings should contains less options, and be more user friendly
AMOS BEGIN
MOV [page-blog-index, pagetype], [page-blog-index, blog]
MOV [page-blog-x, pagetype], [page-blog-x, blog]
MOV [page-tag-x, pagetype], [page-tag-x, tag]
MOV [page-course-view-weeks, pagetype], [page-course-view-weeks, format_weeks]
MOV [page-course-view-weeks-x, pagetype], [page-course-view-weeks-x, format_weeks]
MOV [page-course-view-topics, pagetype], [page-course-view-topics, format_topics]
MOV [page-course-view-topics-x, pagetype], [page-course-view-topics-x, format_topics]
AMOS END
2011-04-28 11:20:30 +08:00
);
}
2011-07-03 22:12:05 +01:00
}