Merging in all the resource branch stuff (I know, it's mixed up)

so I can sort out the CVS explosion I had tonight
This commit is contained in:
moodler
2004-07-25 14:00:29 +00:00
parent b5e4a76e20
commit e0161bff4f
6 changed files with 439 additions and 73 deletions
+2 -8
View File
@@ -115,10 +115,7 @@
print_section($course, $thissection, $mods, $modnamesused);
if (isediting($course->id)) {
echo "<div align=right>";
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
$modnames, "section$section", "", "$stradd...", "mods", $stractivities);
echo "</div>";
print_section_add_menus($course, $section, $modnames);
}
echo "</td>";
@@ -208,10 +205,7 @@
print_section($course, $thissection, $mods, $modnamesused);
if (isediting($course->id)) {
echo "<div align=right>";
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
$modnames, "section$section", "", "$stradd...");
echo "</div>";
print_section_add_menus($course, $section, $modnames);
}
echo "</td>";
+2 -8
View File
@@ -104,10 +104,7 @@
print_section($course, $thissection, $mods, $modnamesused);
if (isediting($course->id)) {
echo "<div align=right>";
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
$modnames, "section$section", "", "$stradd...", "mods", $stractivities);
echo "</div>";
print_section_add_menus($course, $section, $modnames);
}
echo "</td>";
@@ -201,10 +198,7 @@
print_section($course, $thissection, $mods, $modnamesused);
if (isediting($course->id)) {
echo "<div align=right>";
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
$modnames, "section$section", "", "$stradd...");
echo "</div>";
print_section_add_menus($course, $section, $modnames);
}
echo "</td>";
+56 -13
View File
@@ -302,7 +302,15 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today"
$selectedactivity = "$mod->cm";
}
}
if (isadmin() && !$course->category) {
$activities["site_errors"] = get_string("siteerrors");
if ($modid === "site_errors") {
$selectedactivity = "site_errors";
}
}
}
$strftimedate = get_string("strftimedate");
$strftimedaydate = get_string("strftimedaydate");
@@ -369,20 +377,19 @@ function make_log_url($module, $url) {
}
}
function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
$url="", $modname="", $modid=0, $modaction="") {
// 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.
// 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.
global $CFG, $db;
if ($course->category) {
$selector = "l.course='$course->id' AND l.userid = u.id";
$joins = array();
if ($course->category) {
$joins[] = "l.course='$course->id'";
} else {
$selector = "l.userid = u.id"; // Show all courses
if ($ccc = get_courses("all", "c.id ASC", "c.id,c.shortname")) {
foreach ($ccc as $cc) {
$courses[$cc->id] = "$cc->shortname";
@@ -391,26 +398,33 @@ function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $per
}
if ($modname) {
$selector .= " AND l.module = '$modname'";
$joins[] = "l.module = '$modname'";
}
if ($modid) {
$selector .= " AND l.cmid = '$modid'";
if ($modid && is_int($modid)) {
$joins[] = "l.cmid = '$modid'";
} else if ($modid == "site_errors") {
$joins[] = "l.action='error'";
}
if ($modaction) {
$selector .= " AND l.action = '$modaction'";
$joins[] = "l.action = '$modaction'";
}
if ($user) {
$selector .= " AND l.userid = '$user'";
$joins[] = "l.userid = '$user'";
}
if ($date) {
$enddate = $date + 86400;
$selector .= " AND l.time > '$date' AND l.time < '$enddate'";
$joins[] = "l.time > '$date' AND l.time < '$enddate'";
}
for ($i = 0; $i < count($joins); $i++) {
$selector .= $joins[$i] . (($i == count($joins)-1) ? " " : " AND ");
}
$totalcount = 0; // Initialise
if (!$logs = get_logs($selector, $order, $page*$perpage, $perpage, $totalcount)) {
@@ -677,7 +691,7 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
// Returns a number of useful structures for course displays
$mods = NULL; // course modules indexed by id
$modnames = NULL; // all course module names
$modnames = NULL; // all course module names (except resource!)
$modnamesplural= NULL; // all course module names (plural form)
$modnamesused = NULL; // course module names used
@@ -705,6 +719,9 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
asort($modnamesused);
}
}
unset($modnames['resource']);
unset($modnames['label']);
}
@@ -873,6 +890,32 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
}
function print_section_add_menus($course, $section, $modnames) {
// Prints the menus to add activities and resources
static $straddactivity, $straddresource, $resources;
if (!isset($straddactivity)) {
$straddactivity = get_string('addactivity');
$straddresource = get_string('addresource');
$resourcetypes = get_list_of_plugins('mod/resource/type');
foreach ($resourcetypes as $resourcetype) {
$resources["resource&type=$resourcetype"] = get_string("resourcetype$resourcetype", 'resource');
}
asort($resources);
$resources['label'] = get_string('resourcetypelabel', 'resource');
}
echo '<div align="right"><table align="right"><tr><td>';
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
$resources, "ressection$section", "", $straddresource);
echo '</td><td>';
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
$modnames, "section$section", "", $straddactivity);
echo '</td></tr></table>';
echo '</div>';
}
function rebuild_course_cache($courseid=0) {
// Rebuilds the cached list of course activities stored in the database
// If a courseid is not specified, then all are rebuilt
+11 -44
View File
@@ -60,6 +60,9 @@
if (is_string($return)) {
error($return, "view.php?id=$course->id");
}
$SESSION->returnpage = "$CFG->wwwroot/mod/$mod->modulename/view.php?id=$mod->coursemodule";
add_to_log($course->id, "course", "update mod",
"../mod/$mod->modulename/view.php?id=$mod->coursemodule",
"$mod->modulename $mod->instance");
@@ -104,6 +107,9 @@
if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
error("Could not update the course module with the correct section");
}
$SESSION->returnpage = "$CFG->wwwroot/mod/$mod->modulename/view.php?id=$mod->coursemodule";
add_to_log($course->id, "course", "add mod",
"../mod/$mod->modulename/view.php?id=$mod->coursemodule",
"$mod->modulename $mod->instance");
@@ -112,49 +118,6 @@
"$mod->instance", $mod->coursemodule);
break;
case "add":
$return = $addinstancefunction($mod);
if (!$return) {
if (file_exists($moderr)) {
$form = $mod;
include_once($moderr);
die;
}
error("Could not add a new instance of $mod->modulename", "view.php?id=$course->id");
}
if (is_string($return)) {
error($return, "view.php?id=$course->id");
}
$mod->groupmode = $course->groupmode; /// Default groupmode the same as course
$mod->instance = $return;
// course_modules and course_sections each contain a reference
// to each other, so we have to update one of them twice.
if (! $mod->coursemodule = add_course_module($mod) ) {
error("Could not add a new course module");
}
if (! $sectionid = add_mod_to_section($mod) ) {
error("Could not add the new course module to that section");
}
//We get the section's visible field status
$visible = get_field("course_sections","visible","id",$sectionid);
if (! set_field("course_modules", "visible", $visible, "id", $mod->coursemodule)) {
error("Could not update the course module with the correct visibility");
}
if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
error("Could not update the course module with the correct section");
}
add_to_log($course->id, "course", "add mod",
"../mod/$mod->modulename/view.php?id=$mod->coursemodule",
"$mod->modulename $mod->instance");
add_to_log($course->id, $mod->modulename, "add",
"view.php?id=$mod->coursemodule",
"$mod->instance", $mod->coursemodule);
break;
case "delete":
if (! $deleteinstancefunction($mod->instance)) {
notify("Could not delete the $mod->modulename (instance)");
@@ -577,6 +540,9 @@
$form->instance = "";
$form->coursemodule = "";
$form->mode = "add";
if (isset($_GET['type'])) {
$form->type = $_GET['type'];
}
$sectionname = get_string("name$course->format");
$fullmodulename = get_string("modulename", $module->name);
@@ -624,6 +590,7 @@
if ($usehtmleditor = can_use_html_editor()) {
$defaultformat = FORMAT_HTML;
$editorfields = '';
} else {
$defaultformat = FORMAT_MOODLE;
}
@@ -636,7 +603,7 @@
print_simple_box_end();
if ($usehtmleditor and empty($nohtmleditorneeded)) {
use_html_editor();
use_html_editor($editorfields);
}
} else {
+365
View File
@@ -0,0 +1,365 @@
<?PHP // $Id$
// Displays all activity for non-quiz modules for a course
///This version allows students to see their own activity, but not that of others.
///For teachers only, clicking on a student's name brings up the Moodle user activity summary.
require_once("../config.php");
require_once("lib.php");
require_once("../lib/datalib.php");
//module, location of user data,pointer
$quick_dataloc["assignment"] = array("assignment_submissions","assignment");
$quick_dataloc["choice"] = array("choice_answers","choice");
$quick_dataloc["dialogue"] = array("dialogue_entries","dialogue");
$quick_dataloc["discussion"] = array("forum_posts","discussion");
$quick_dataloc["journal"] = array("journal_entries","journal");
$quick_dataloc["quiz"] = array("quiz_attempts","quiz");
$quick_dataloc["survey"] = array("survey_analysis","survey");
$quick_dataloc["workshop"] = array("workshop_submissions","workshopid");
$usemods = ",assignment,choice,dialogue,forum,journal,quiz,survey,workshop";
$modlist = get_records("modules","visible",1);
foreach ($modlist as $nowmod){
if (strpos($usemods,$nowmod->name)){
$modnames[$nowmod->id] = $nowmod->name;
}
}
//needed for cases when a particular module type needs special treatment (assignment,forum)
$modname_value = array_flip($modnames);
require_variable($id); // course id
optional_variable($download, ""); // to download data
require_login();
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect");
}
//take each event and create an array type/event/user hierarchy
//we need to get the entire list of enrolled students for the course so that we can list by student
if (isteacher($course->id)) {
$isstudent = 0;
} elseif (isstudent($course->id)) {
$isstudent = 1;
} else {
error("You are not registered for this course");
}
$courseid = $course->id;
//Get the ids of all course users
$allusers = quick_findusers($course->id);
//Get all postings from this course's users
$allposts = quick_findposts($course->id);
//count posts per user by looping thru $allposts and put counts in $post_counts
foreach ($allposts as $thispost){
$post_counts[$thispost->forumid][$thispost->userid]++;
}
$allmods = quick_moduleorder($course->id);
//Now take all mods and build an object $mod_info for only those modules that will be reported
//Concurrently build a $mods_week array that says how many columns will be in the header per week
$modcount = -1;
foreach($allmods as $thismod){
$modcount++;
//get the info on this module from course_modules
$nowmod = get_record("course_modules","id",$thismod[mod]);
$noworder = get_record("course_sections","id",$nowmod->section);
//only add to array the module is contained in the $modnames array
if ($modnames[$nowmod->module]){
//section is the entry in course_sections which says which instances
///reside in the section and which week/section they are in
$mod_info[$modcount][section] = $nowmod->section;
//module is the type of module (assignment, forum, etc.)
$mod_info[$modcount][module] = $nowmod->module;
//modid is the id of the module in "course_modules" table
$mod_info[$modcount][modid] = $nowmod->id;
//week is the current week/section that the module resides in
$mod_info[$modcount][week] = $noworder->section;
//instance in the relevant module table will yield the name
$mod_info[$modcount][instance] = $nowmod->instance;
//Count how many instances in each week for colspan purposes
if ($mods_week[$noworder->section]){
$mods_week[$noworder->section]++;
} else {
$mods_week[$noworder->section] = 1;
}
//Now add the name of the module to $mods_info
$mod_info[$modcount][name] = get_field($modnames[$nowmod->module],"name","id",$nowmod->instance);
} else {
$modcount--;
}
}
//Catalog by user all activity for every module
//This will include modules to be ignored later, but it is easier this way
//Data for each user can be retrieved by matching$rec->name with $mod_info name(created above)
//Create a comma-delimited string in $user_data with the IDs of each user in an array of mod type(module) + modid
foreach ($modnames as $nowtype => $nowname){
$now_module = $nowname;
$now_user_table = $quick_dataloc[$now_module][0]; //name of table containing individual user records
$now_pointer = $quick_dataloc[$now_module][1]; // the field in above with pointer to table with name of activity
// Now set up a table for each separate instance of the module with a listing of the users
$allrecs = quick_findrecs($now_module,$now_user_table,$now_pointer,$course->id);
if ($allrecs) {
foreach ($allrecs as $rec){
$np = $rec->instance;
if ($nowname == "assignment"){
// For assignments, a record is created for all students when the assmt is created
//the timemodified is 0 until the student submits an assignment
if ($rec->timemodified != 0) {
$user_data[$nowtype][$np] = $user_data[$nowtype][$np] . ",$rec->userid,";
}
} else {
$user_data[$nowtype][$np] = $user_data[$nowtype][$np] . ",$rec->userid,";
}
}
}
}
if ($allposts) {
foreach ($allposts as $rec){
$forumval = $modname_value["forum"];
$user_data[$forumval][$rec->forumid] = $user_data[$forumval][$rec->forumid] . ",$rec->userid,";
// echo "<br>" . $rec->forumid . $rec->name . "<br>";
}
}
//now go through the $mod_info array in order of the users, and find whether each user contributed, put in $user_contribs
foreach($allusers as $user){
$uid = $user->id;
foreach ($mod_info as $thismod){
if(strlen($user_data[$thismod[module]][$thismod[instance]]) < 2){
$user_contribs[$uid][] = "-";
continue;
}
//For forums count the number of contributions. For others, just "x" or "-";
if ($thismod[module] == $modname_value["forum"]) {
$puid = $post_counts[$uid];
if ($post_counts[$thismod[instance]][$uid] > 0){
$user_contribs[$uid][] = $post_counts[$thismod[instance]][$uid];
} else {
$user_contribs[$uid][] = "-";
}
} else {
//see if "comma+userid+comma " exists
$sstring = ",$user->id,";
if(strpos($user_data[$thismod[module]][$thismod[instance]],$sstring)> -1){
$user_contribs[$uid][] = "X";
}else {
$user_contribs[$uid][] = "-";
}
}
}
}
//if Excel spreadsheet requested
if ($download == "xls") {
require_once("$CFG->libdir/excel/Worksheet.php");
require_once("$CFG->libdir/excel/Workbook.php");
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$course->shortname"."_quickreport.xls");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
$workbook = new Workbook("-");
// Creating the first worksheet
$myxls = &$workbook->add_worksheet('Quick Report');
$myxls->write_string(0,0,$quiz->name);
$myxls->set_column(0,0,25);
$formaty =& $workbook->add_format();
$formaty->set_bg_color('yellow');
$formatyc =& $workbook->add_format();
$formatyc->set_bg_color('yellow');
$formatyc->set_bold(1);
$formatyc->set_align('center');
$formatc =& $workbook->add_format();
$formatc->set_align('center');
$formatb =& $workbook->add_format();
$formatb->set_bold(1);
$row = 1;
$col = 2;
/// Print names of all the fields
///First labels to show week/section
if ($course->format == "weeks") {$formatname = "Week";} else {$formatname = "Section";}
foreach($mods_week as $week=>$wkcount){
for ($i = 0; $i < $wkcount;$i++) {
$col++;
$col_label = "$formatname $week";
$myxls->write_string($row,$col,$col_label,$formatb);
}
}
//now labels for module names
$row++;
$col=0;
$myxls->write_string($row,$col,"Student",$formatb);
$col++;
$myxls->write_string($row,$col,"Picture",$formatb);
$col++;
$myxls->write_string($row,$col,"Profile",$formatb);
//get the names of each module instance and put in header
foreach($mod_info as $thiscat=>$thismod){
$modname = ucwords($modnames[$thismod[module]]);
$col++;
$col_label = "$modname $thismod[name]";
$myxls->write_string($row,$col,$col_label,$formatb);
}
/// Print all the user data
$row++;
foreach ($user_contribs as $userid=>$thisuser){
$row++;
$col=0;
$fullname = ucwords($allusers[$userid]->lastname) . ", " . ucwords($allusers[$userid]->firstname);
$myxls->write_string($row,$col,$fullname,$formatb);
$col++;
if($allusers[$userid]->picture){
$myxls->write_string($row,$col,"X",$formatc);
} else {
$myxls->write_string($row,$col,"-",$formatc);
}
$col++;
if (strlen($allusers[$userid]->description) > 10) {
$myxls->write_string($row,$col,"X",$formatc);
} else {
$myxls->write_string($row,$col,"-",$formatc);
}
foreach ($thisuser as $thismod) {
$col++;
$myxls->write_string($row,$col,$thismod,$formatc);
}
}
$workbook->close();
exit;
}
quick_headers($course);
$quick_bgcount = 0;
echo "<table>";
//printer header line with weeks
$options["id"] = $course->id;
$options["download"] = "xls";
print ( "<tr valign=top><td colspan=3>");
print_single_button("quickreport.php", $options, get_string("downloadexcel"));
print ("</td>");
if ($course->format == "weeks") {$formatname = "Week";} else {$formatname = "Section";}
foreach($mods_week as $week=>$wkcount){
print "<td colspan=$wkcount>$formatname $week</td>";
}
echo "<tr valign=top><td width='150'>Student</td><td>Picture</td><td>Profile</td>";
//get the names of each module instance and put in header
foreach($mod_info as $thiscat=>$thismod){
$modname = ucwords($modnames[$thismod[module]]);
print ("<td> $modname <br><font size=-1>$thismod[name]</font></td>");
}
echo "</tr>\n";
foreach ($user_contribs as $userid=>$thisuser){
$quick_bgcount++;
if ($quick_bgcount%3 == 0) {
echo "<tr align=center bgcolor='#ffffff'>";
} else {
echo "<tr align=center>";
}
$fullname = ucwords($allusers[$userid]->lastname) . ", " . ucwords($allusers[$userid]->firstname);
if (!$isstudent){
$fullname = "<a href=user.php?id=$course->id&user=$userid>$fullname</a>";
}
echo "<td align=left><b>$fullname</b></td>";
$picture = print_user_picture($userid, $course->id, $allusers[$userid]->picture, false, true);
echo "<td>" . $picture . "</td>";
if (strlen($allusers[$userid]->description) > 10) {quick_show("X");} else {quick_show("-");}
foreach ($thisuser as $thismod) {
quick_show($thismod);
}
echo "</tr>\n";
}
echo "</table>\n";
print_footer($course);
function quick_findusers($courseid){
global $CFG,$USER,$isstudent;
if ($isstudent){
$studcondition = "AND a.id = $USER->id";
} else {
$studcondition = "";
}
$allusers = get_records_sql("SELECT a.id,a.lastname, a.firstname,a.picture,a.description,b.course
FROM {$CFG->prefix}user a,
{$CFG->prefix}user_students b
WHERE b.course = $courseid AND
b.userid = a.id $studcondition
ORDER BY a.lastname ASC, a.firstname ASC");
return $allusers;
}
function quick_findrecs($tbl1,$tbl2,$pointer,$courseid){
global $CFG;
$allrecs = get_records_sql("SELECT b.id,a.id, c.id,c.lastname, c.firstname,a.course,a.name ,b.userid,b.timemodified, b.$pointer as instance
FROM {$CFG->prefix}$tbl1 a,
{$CFG->prefix}$tbl2 b,
{$CFG->prefix}user c,
{$CFG->prefix}course_modules d
WHERE a.course = $courseid AND
a.id = b.$pointer AND
c.id = b.userid AND
d.instance = b.$pointer");
/// ORDER BY e.section ASC
// print("<h3>All records: $tbl1</h3>");
// print_object($allrecs);
return $allrecs;
}
function quick_findposts($courseid){
global $CFG;
//this will allow records to be identified by Forum but not by thread (no b.id)
$allposts = get_records_sql("SELECT
c.id, c.userid,a.id as forumid,a.name
FROM {$CFG->prefix}forum a,
{$CFG->prefix}forum_discussions b,
{$CFG->prefix}forum_posts c
WHERE b.course = $courseid AND
a.id = b.forum AND
c.discussion = b.id
ORDER BY forumid ASC");
return $allposts;
}
function quick_moduleorder($courseid){
//using course_sections which gives the sections & sequence, build an array with each section + item pair
// echo "<br>Course= " . $courseid . "<br>";
$allmods = get_records("course_sections","course",$courseid,"section","id,section,sequence");
// print_object($allmods);
// $modsequence
foreach ($allmods as $thisweek){
// print_object($thisweek);
if ($thisweek->sequence){
// print ("$thisweek->sequence");
$weeklist = explode(",",$thisweek->sequence);
foreach($weeklist as $activity){
$all_list[] =array("mod"=>$activity,"sec"=>$thisweek->section);
}
// print_object($weeklist);
} else {
// print ("<br>No modules this week<br>");
}
}
return $all_list;
}
function quick_headers($course){
global $CFG;
print_header("$course->shortname: 'Quick Report'", "$course->fullname",
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A>
-> 'Quick Report'");
}
function quick_show($x){
echo "<td align=center>";
print ("$x");
echo "</td>";
}
?>
+3
View File
@@ -59,6 +59,7 @@
/// Add a student if one is specified
if (!empty($add)) {
check_for_restricted_user($USER->username, "$CFG->wwwroot/course/student.php?id=$course->id");
if (! enrol_student($add, $course->id)) {
error("Could not add that student to this course!");
}
@@ -67,6 +68,7 @@
/// Remove a student if one is specified.
if (!empty($remove)) {
check_for_restricted_user($USER->username, "$CFG->wwwroot/course/student.php?id=$course->id");
if (! unenrol_student($remove, $course->id)) {
error("Could not remove that student from this course!");
}
@@ -75,6 +77,7 @@
/// Remove all students from specified course
if (!empty($removeall)) {
check_for_restricted_user($USER->username, "$CFG->wwwroot/course/student.php?id=$course->id");
$students = get_course_students($course->id, "u.lastname ASC, u.firstname ASC");
foreach ($students as $student) {
if (! unenrol_student($student->id, $course->id)) {