Update of /cvsroot/aimmath/moodle/mod/math_assignment
In directory sc8-pr-cvs1:/tmp/cvs-serv21659/mod/math_assignment
Modified Files:
editgrade.php email.php index.php lib.php mod.html
updatepapergrades.php version.php view.php
Log Message:
More work on emails. Emails to students can now be sent from view.php.
Index: editgrade.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/editgrade.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** editgrade.php 9 Sep 2003 18:31:07 -0000 1.1
--- editgrade.php 26 Sep 2003 22:23:23 -0000 1.2
***************
*** 39,43 ****
$gradeobj->aimgrade = -1; // not attempted
$gradeobj->aimtimemodified = 0;
! $gradeobj->aimoverride = 0;
$gradeobj->aimcomment = "";
if (isset($grade) && isset($comment))
--- 39,43 ----
$gradeobj->aimgrade = -1; // not attempted
$gradeobj->aimtimemodified = 0;
! $gradeobj->aimoverride = AIMOVR_OFF;
$gradeobj->aimcomment = "";
if (isset($grade) && isset($comment))
***************
*** 51,64 ****
if ($grade == "-") { // reset override (clear grade)
$gradeobj->aimgrade = -1;
! $gradeobj->aimoverride = 0;
$gradeobj->aimcomment = $comment;
}
else if ($grade == "") { // clear override (leave grade alone)
! $gradeobj->aimoverride = 0;
$gradeobj->aimcomment = $comment;
}
else if ($grade >= 0 && $grade <= $math_assignment->aimgrade && $comment) { // set override
$gradeobj->aimtimemodified = time();
! $gradeobj->aimoverride = 1;
$gradeobj->aimcomment = $comment;
$gradeobj->aimgrade = $grade;
--- 51,64 ----
if ($grade == "-") { // reset override (clear grade)
$gradeobj->aimgrade = -1;
! $gradeobj->aimoverride = AIMOVR_RESET;
$gradeobj->aimcomment = $comment;
}
else if ($grade == "") { // clear override (leave grade alone)
! $gradeobj->aimoverride = AIMOVR_RESET;
$gradeobj->aimcomment = $comment;
}
else if ($grade >= 0 && $grade <= $math_assignment->aimgrade && $comment) { // set override
$gradeobj->aimtimemodified = time();
! $gradeobj->aimoverride = AIMOVR_SET;
$gradeobj->aimcomment = $comment;
$gradeobj->aimgrade = $grade;
***************
*** 69,73 ****
$err = math_assignment_update_grades($gradeobj) ? 0 : 1;
if (!$err)
! redirect("view.php?id=$cm->id", get_string("changessaved"), 1);
}
}
--- 69,73 ----
$err = math_assignment_update_grades($gradeobj) ? 0 : 1;
if (!$err)
! redirect("view.php?id=$cm->id", get_string("changessaved") . "\n" . get_string("delaymessage", "math_assignment", format_time($CFG->maxeditingtime)), 2);
}
}
***************
*** 156,160 ****
<td align="right"><p><b><?php echo $strnewgrade; ?>:</b></p></td>
<td>
! <input type="text" name="grade" size="20" maxlength="20" value="<?php if ($gradeobj->aimoverride) echo max($gradeobj->aimgrade, 0);?>" /> / <?php echo "$math_assignment->aimgrade "; helpbutton ("editgrade_new", $strnewgrade, "math_assignment"); ?>
</td>
</tr>
--- 156,160 ----
<td align="right"><p><b><?php echo $strnewgrade; ?>:</b></p></td>
<td>
! <input type="text" name="grade" size="20" maxlength="20" value="<?php if ($gradeobj->aimoverride > AIMOVR_RESET) echo max($gradeobj->aimgrade, 0);?>" /> / <?php echo "$math_assignment->aimgrade "; helpbutton ("editgrade_new", $strnewgrade, "math_assignment"); ?>
</td>
</tr>
Index: email.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/email.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** email.php 25 Sep 2003 22:14:09 -0000 1.2
--- email.php 26 Sep 2003 22:23:23 -0000 1.3
***************
*** 41,53 ****
foreach ($students as $student) {
// send email to the student
! if (!math_assignment_email_grades($math_assignment, $student))
$failed++;
}
}
! if ($failed == count($students))
error(get_string("failed", "math_assignment"), "view.php?id=$cm->id");
// send email to secretaries
! if (!math_assignment_email_all_grades($math_assignment, $students))
! error(get_string("failed", "math_assignment"), "view.php?id=$cm->id");
// set flag in database
//set_field("math_assignment", "papersheetsreturned", "1", "id", $math_assignment->id);
--- 41,53 ----
foreach ($students as $student) {
// send email to the student
! if (!math_assignment_email_grades($course, $math_assignment, $student))
$failed++;
}
}
! if ($failed > 0 && $failed == count($students))
error(get_string("failed", "math_assignment"), "view.php?id=$cm->id");
// send email to secretaries
! /*if (!math_assignment_email_all_grades($course, $math_assignment, $students))
! error(get_string("failed", "math_assignment"), "view.php?id=$cm->id");*/
// set flag in database
//set_field("math_assignment", "papersheetsreturned", "1", "id", $math_assignment->id);
Index: index.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/index.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** index.php 25 Sep 2003 17:15:41 -0000 1.7
--- index.php 26 Sep 2003 22:23:23 -0000 1.8
***************
*** 152,156 ****
$grade->papergrade = -1;
$grade->aimgrade = -1;
! $grade->aimoverride = 0;
$grade->aimcomment = "";
}
--- 152,156 ----
$grade->papergrade = -1;
$grade->aimgrade = -1;
! $grade->aimoverride = AIMOVR_OFF;
$grade->aimcomment = "";
}
***************
*** 164,168 ****
else
$aimgrade = "";
! if ($grade->aimoverride)
$aimgrade .= " (" . get_string("gradeoverride", "math_assignment") . ")";
}
--- 164,168 ----
else
$aimgrade = "";
! if ($grade->aimoverride > AIMOVR_RESET)
$aimgrade .= " (" . get_string("gradeoverride", "math_assignment") . ")";
}
Index: lib.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/lib.php,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** lib.php 25 Sep 2003 22:14:09 -0000 1.23
--- lib.php 26 Sep 2003 22:23:23 -0000 1.24
***************
*** 5,8 ****
--- 5,13 ----
/// Library of functions and constants for module math_assignment
+ define("AIMOVR_OFF", 0);
+ define("AIMOVR_RESET", 1);
+ define("AIMOVR_SET", 2);
+ define("AIMOVR_ON", 3);
+
function math_assignment_add_instance($math_assignment) {
/// Given an object containing all the necessary data,
***************
*** 175,185 ****
global $CFG;
! $math_assignments = get_records_sql("SELECT `id`,`course`,`name`,`papergrade`,`aimgrade`,`timedue` FROM `{$CFG->prefix}math_assignment` WHERE `papersheetsreturned` = '0' AND `timedue` < NOW() AND `papergrade` = '0'");
! if ($math_assignments) {
foreach ($math_assignments as $math_assignment) {
! if ($students = math_assignment_get_grades($math_assignment))
! math_assignment_email_all_grades($math_assignment, $students);
}
}
return true;
}
--- 180,195 ----
global $CFG;
! $time = time();
! // look for assignments which need closing
! if ($math_assignments = get_records_sql("SELECT `id`,`course`,`name`,`papergrade`,`aimgrade`,`timedue` FROM `{$CFG->prefix}math_assignment` WHERE `papersheetsreturned` = '0' AND `timedue` < $time AND `papergrade` = '0'")) {
foreach ($math_assignments as $math_assignment) {
! if ($course = get_record("course", "id", $math_assignment->course) && $students = math_assignment_get_grades($math_assignment))
! math_assignment_email_all_grades($course, $math_assignment, $students);
}
}
+ // look for emails which need sending
+ /*$time = time() - $CFG->maxeditingtime;
+ if ($grades = get_records_sql("SELECT * FROM `{$CFG->prefix}math_assignment_grades` WHERE `aimoverride` = '" . AIMOVR_SET . "' AND `timemodified` < '$time'")) {
+ }*/
return true;
}
***************
*** 723,727 ****
$changed = true;
}
! if ($aimgrade >= 0 && !$entry->aimoverride) { // don't update if the teacher has manually updated
$entry->aimgrade = $aimgrade;
$entry->aimtimemodified = time();
--- 733,737 ----
$changed = true;
}
! if ($aimgrade >= 0 && $entry->aimoverride <= AIMOVR_RESET) { // don't update if the teacher has manually updated
$entry->aimgrade = $aimgrade;
$entry->aimtimemodified = time();
***************
*** 738,742 ****
$entry->aimgrade = $aimgrade;
$entry->aimtimemodified = ($aimgrade >= 0) ? time() : 0;
! $entry->aimoverride = 0;
$entry->aimcomment = "";
insert_record("math_assignment_grades", $entry, false);
--- 748,752 ----
$entry->aimgrade = $aimgrade;
$entry->aimtimemodified = ($aimgrade >= 0) ? time() : 0;
! $entry->aimoverride = AIMOVR_OFF;
$entry->aimcomment = "";
insert_record("math_assignment_grades", $entry, false);
***************
*** 763,767 ****
// get the grade from the database
if ($entry = get_record("math_assignment_grades", "assignment", $math_assignment->id, "userid", $userid)) {
! if ($entry->aimoverride) {
print_simple_box_start("left");
echo "<b>";
--- 773,777 ----
// get the grade from the database
if ($entry = get_record("math_assignment_grades", "assignment", $math_assignment->id, "userid", $userid)) {
! if ($entry->aimoverride > AIMOVR_RESET) {
print_simple_box_start("left");
echo "<b>";
***************
*** 818,822 ****
$students[$key]->papergrade = -1;
$students[$key]->aimgrade = -1;
! $students[$key]->aimoverride = 0 ;
$students[$key]->aimcomment = "";
$students[$key]->totalgrade = 0;
--- 828,832 ----
$students[$key]->papergrade = -1;
$students[$key]->aimgrade = -1;
! $students[$key]->aimoverride = AIMOVR_OFF ;
$students[$key]->aimcomment = "";
$students[$key]->totalgrade = 0;
***************
*** 849,861 ****
}
! function math_assignment_email_grades($math_assignment, $student) {
/// Function which constructs an email telling the student what their grade is
! // build the email
! // send the email to $student->email
! return true;
}
! function math_assignment_email_all_grades($math_assignment, $students) {
/// Function which constructs an email listing all the grades found and emails it to the secretaries
--- 859,959 ----
}
! function math_assignment_email_grades($course, $math_assignment, $student) {
/// Function which constructs an email telling the student what their grade is
! global $CFG;
!
! // send from the main teacher
! if (!$teachers = get_records_sql("SELECT u.*,t.role,t.editall FROM {$CFG->prefix}user u, {$CFG->prefix}user_teachers t WHERE t.course = '$course->id' AND t.userid = u.id AND u.deleted = '0' AND t.authority > '0' ORDER BY t.authority ASC"))
! return false;
! $teacher = reset($teachers);
! $hasaim = $math_assignment->aimquiz;
! $papergrade = min(max((int) $student->papergrade, 0), $math_assignment->papergrade);
! if ($hasaim)
! $aimgrade = min(max((int) $student->aimgrade, 0), $math_assignment->aimgrade);
! if ($student->mailformat) {
! // build html email
! $lang = current_language();
! $messagehtml = "<!doctype html public \"-//w3c//dtd html 4.0 strict//$lang\">\n";
! $messagehtml .= "<html><head>\n";
! if ($lang == "en")
! $messagehtml .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n";
! else
! $messagehtml .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . get_string("thischarset") . "\" />\n";
! $messagehtml .= "<style type=\"text/css\"><!--\n";
! $messagehtml .= "BODY{\nfont-family: \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;\nfont-size: 12pt;\nfont-weight: normal;\n}\n";
! $messagehtml .= "H2{\nfont-family: \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;\nfont-size: 18pt;\nfont-weight: bold;\ntext-align: left;\nmargin-top: 0px;\nmargin-bottom: 0px;\n}\n";
! $messagehtml .= "H3{\nfont-family: \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;\nfont-size: 12pt;\nfont-weight: bold;\ntext-align: left;\nbackground-color: #FFE0A0;\npadding-top: 1px;\npadding-bottom: 1px;\npadding-left: 4px;\npadding-right: 4px;\n}\n";
! $messagehtml .= "H4{\nfont-family: \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;\nfont-size: 12pt;\nfont-weight: normal;\nfont-style: italic;\ntext-align: left;\n}\n";
! $messagehtml .= "P{\nfont-family: \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;\nfont-size: 12pt;\nfont-weight: normal;\ntext-align: left;\n}\n";
! if ($hasaim) {
! $messagehtml .= "TABLE{\nclear: both;\nmargin-bottom: 16px;\n}\n";
! $messagehtml .= "TH{\nfont-family: \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;\nfont-size: 12pt;\nfont-weight: bold;\ntext-align: left;\nbackground-color: #FFD080;\n}\n";
! $messagehtml .= "TD{\nfont-family: \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;\nfont-size: 12pt;\nfont-weight: bold;\ntext-align: center;\nbackground-color: #FFF0D0;\n}\n";
! $messagehtml .= "TD.unused{\nbackground-color: transparent;\n}\n";
! $messagehtml .= "TD.total{\nbackground-color: #FFE8C8;\n}\n";
! }
! $messagehtml .= "--></style>\n";
! $messagehtml .= "</head>\n";
! $messagehtml .= "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#0000ff\" alink=\"#ff0000\" vlink=\"#800080\">\n";
! $messagehtml .= "<h2>$course->fullname</h2>\n<h3>$math_assignment->name</h3>\n";
! $messagehtml .= "<p>" . get_string("gradeemailmessage", "math_assignment") . "</p>\n";
! $messagehtml .= "<p>" . get_string("gradeemailobtained", "math_assignment");
! if ($hasaim) {
! $messagehtml .= ":</p>\n<table border=\"0\" align=\"left\" cellspacing=\"2\" cellpadding=\"4\">\n";
! $messagehtml .= "<tr><td class=\"unused\"></td><th>" . get_string("maximumgrade") . "</th><th>" . get_string("grade") . "</th>";
! if ($student->aimoverride > AIMOVR_RESET)
! $messagehtml .= "<th>" . get_string("extra") . "</th>";
! $messagehtml .= "</tr>\n";
! $messagehtml .= "<tr valign=\"top\"><th align=\"left\">" . get_string("paper", "math_assignment") . "</th>\n";
! $messagehtml .= "<td align=\"center\">$math_assignment->papergrade</td>\n";
! $messagehtml .= "<td align=\"center\">$papergrade</td>\n";
! if ($student->aimoverride > AIMOVR_RESET)
! $messagehtml .= "<td></td>\n";
! $messagehtml .= "</tr>\n";
! $messagehtml .= "<tr valign=\"top\"><th align=\"left\">" . get_string("computer", "math_assignment") . "</th>\n";
! $messagehtml .= "<td align=\"center\">$math_assignment->aimgrade</td>\n";
! $messagehtml .= "<td align=\"center\">$aimgrade</td>\n";
! if ($student->aimoverride > AIMOVR_RESET)
! $messagehtml .= "<td align=\"left\">" . get_string("gradeoverride", "math_assignment") . "</td>\n";
! $messagehtml .= "</tr>\n";
! $totalgrade = $papergrade + $aimgrade;
! $totalmax = $math_assignment->papergrade + $math_assignment->aimgrade;
! $messagehtml .= "<tr valign=\"top\"><th align=\"left\">" . get_string("total") . "</th>\n";
! $messagehtml .= "<td align=\"center\">$totalmax</td>\n<td align=\"center\" class=\"total\">$totalgrade</td>\n";
! if ($student->aimoverride > AIMOVR_RESET)
! $messagehtml .= "<td></td>";
! $messagehtml .= "</tr>\n";
! $messagehtml .= "</table>\n<br clear=\"all\" />\n";
! }
! else
! $messagehtml .= " $papergrade / $math_assignment->papergrade.</p>\n";
! $messagehtml .= "<h4>$teacher->firstname $teacher->lastname</h4><p><a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">" . get_string("course") . " " . get_string("home") . "</a></p>\n";
! $messagehtml .= "</body></html>";
! }
! else
! $messagehtml = "";
! // build plain text email
! $message = "$course->fullname\n$math_assignment->name\n\n";
! $message .= get_string("gradeemailmessage", "math_assignment") . "\n";
! $message .= get_string("gradeemailobtained", "math_assignment") . ":\n\n";
! if ($hasaim)
! $message .= get_string("paper", "math_assignment") . ": ";
! $message .= "$papergrade / $math_assignment->papergrade\n";
! if ($hasaim) {
! $message .= get_string("computer", "math_assignment") . ": ";
! $message .= "$aimgrade / $math_assignment->aimgrade";
! if ($student->aimoverride > AIMOVR_RESET)
! $message .= " (" . get_string("gradeoverride", "math_assignment") . ")";
! $message .= "\n";
! $totalgrade = $papergrade + $aimgrade;
! $totalmax = $math_assignment->papergrade + $math_assignment->aimgrade;
! $message .= get_string("total") . ": $totalgrade / $totalmax\n";
! }
! $message .= "\n$teacher->firstname $teacher->lastname\n\n" . get_string("course") . " " . get_string("home") . ": $CFG->wwwroot/course/view.php?id=$course->id";
! return email_to_user($student, $teacher, $course->shortname . ": " . $math_assignment->name, $message, $messagehtml);
}
! function math_assignment_email_all_grades($course, $math_assignment, $students) {
/// Function which constructs an email listing all the grades found and emails it to the secretaries
Index: mod.html
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/mod.html,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** mod.html 25 Sep 2003 15:02:23 -0000 1.21
--- mod.html 26 Sep 2003 22:23:23 -0000 1.22
***************
*** 46,50 ****
// Now we set the defaults
if (!$form->name)
! $form->name = get_string("modulename", "math_assignment");
// get aimsubject from database
--- 46,50 ----
// Now we set the defaults
if (!$form->name)
! $form->name = get_string("modulename", "math_assignment") . ($form->section ? " $form->section" : "");
// get aimsubject from database
Index: updatepapergrades.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/updatepapergrades.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** updatepapergrades.php 9 Sep 2003 18:31:07 -0000 1.1
--- updatepapergrades.php 26 Sep 2003 22:23:23 -0000 1.2
***************
*** 48,52 ****
$gradeobj->aimgrade = -1; // not attempted
$gradeobj->aimtimemodified = 0;
! $gradeobj->aimoverride = 0;
$gradeobj->aimcomment = "";
insert_record("math_assignment_grades", $gradeobj, false);
--- 48,52 ----
$gradeobj->aimgrade = -1; // not attempted
$gradeobj->aimtimemodified = 0;
! $gradeobj->aimoverride = AIMOVR_OFF;
$gradeobj->aimcomment = "";
insert_record("math_assignment_grades", $gradeobj, false);
Index: version.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/version.php,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** version.php 25 Sep 2003 22:14:09 -0000 1.11
--- version.php 26 Sep 2003 22:23:23 -0000 1.12
***************
*** 7,11 ****
$module->version = 2003092523; // The (date) version of this module
! $module->cron = 1200; // How often should cron check this module (seconds)?
?>
--- 7,11 ----
$module->version = 2003092523; // The (date) version of this module
! $module->cron = 60; // How often should cron check this module (seconds)?
?>
Index: view.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/view.php,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** view.php 25 Sep 2003 22:14:09 -0000 1.17
--- view.php 26 Sep 2003 22:23:23 -0000 1.18
***************
*** 107,111 ****
$grade->papergrade = -1;
$grade->aimgrade = -1;
! $grade->aimoverride = 0;
$grade->aimcomment = "";
}
--- 107,111 ----
$grade->papergrade = -1;
$grade->aimgrade = -1;
! $grade->aimoverride = AIMOVR_OFF;
$grade->aimcomment = "";
}
***************
*** 290,294 ****
else
print_string("notattempted", "math_assignment");
! if ($grade->aimoverride) {
echo " (";
print_string("gradeoverride", "math_assignment");
--- 290,294 ----
else
print_string("notattempted", "math_assignment");
! if ($grade->aimoverride > AIMOVR_RESET) {
echo " (";
print_string("gradeoverride", "math_assignment");
***************
*** 351,355 ****
$aimgrade = "";
! if ($student->aimoverride) {
$edited = "$stredited (";
$editedclose = ")";
--- 351,355 ----
$aimgrade = "";
! if ($student->aimoverride > AIMOVR_RESET) {
$edited = "$stredited (";
$editedclose = ")";
***************
*** 437,441 ****
echo math_assignment_get_file_links($math_assignment, "center");
if ($hasaim) {
! if ($grade->aimoverride) {
echo "<p align=\"center\">";
print_string("gradeoverridemsg", "math_assignment");
--- 437,441 ----
echo math_assignment_get_file_links($math_assignment, "center");
if ($hasaim) {
! if ($grade->aimoverride > AIMOVR_RESET) {
echo "<p align=\"center\">";
print_string("gradeoverridemsg", "math_assignment");
|