Cleaned up logic by adding a separate menu for publishing vs privacy.
$CHOICE_PUBLISH = array (CHOICE_PUBLISH_ANONYMOUS => get_string("publishanonymous", "choice"),
CHOICE_PUBLISH_NAMES => get_string("publishnames", "choice"));
-$CHOICE_RELEASE = array (CHOICE_RELEASE_NOT => get_string("releasenot", "choice"),
- CHOICE_RELEASE_AFTER_ANSWER => get_string("releaseafteranswer", "choice"),
- CHOICE_RELEASE_AFTER_CLOSE => get_string("releaseafterclose", "choice"),
- CHOICE_RELEASE_ALWAYS => get_string("releasealways", "choice"));
+$CHOICE_RELEASE = array (CHOICE_RELEASE_NOT => get_string("publishnot", "choice"),
+ CHOICE_RELEASE_AFTER_ANSWER => get_string("publishafteranswer", "choice"),
+ CHOICE_RELEASE_AFTER_CLOSE => get_string("publishafterclose", "choice"),
+ CHOICE_RELEASE_ALWAYS => get_string("publishalways", "choice"));
/// Standard functions /////////////////////////////////////////////////////////
$choice->timemodified = time();
+ if ($choice->timerestrict) {
+ $choice->timeopen = make_timestamp($choice->openyear, $choice->openmonth, $choice->openday,
+ $choice->openhour, $choice->openminute, 0);
+ $choice->timeclose = make_timestamp($choice->closeyear, $choice->closemonth, $choice->closeday,
+ $choice->closehour, $choice->closeminute, 0);
+ } else {
+ $choice->timeopen = 0;
+ $choice->timeclose = 0;
+ }
+
return insert_record("choice", $choice);
}
$choice->id = $choice->instance;
$choice->timemodified = time();
+
+ if ($choice->timerestrict) {
+ $choice->timeopen = make_timestamp($choice->openyear, $choice->openmonth, $choice->openday,
+ $choice->openhour, $choice->openminute, 0);
+ $choice->timeclose = make_timestamp($choice->closeyear, $choice->closemonth, $choice->closeday,
+ $choice->closehour, $choice->closeminute, 0);
+ } else {
+ $choice->timeopen = 0;
+ $choice->timeclose = 0;
+ }
+
+// global $db; $db->debug=true;
+
return update_record("choice", $choice);
}
if (empty($form->answer6)) {
$form->answer6 = "";
}
+ if (empty($form->timeopen)) {
+ $form->timeopen = "";
+ $form->timerestrict = 0;
+ } else {
+ $form->timerestrict = 1;
+ }
+ if (empty($form->timeclose)) {
+ $form->timeclose = "";
+ }
if (empty($form->publish)) {
$form->publish = 0;
}
+ if (empty($form->release)) {
+ $form->release = 0;
+ }
+ if (empty($form->allowupdate)) {
+ $form->allowupdate = 0;
+ }
if (empty($form->showunanswered)) {
$form->showunanswered = 0;
}
<?php helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
</td>
</tr>
+
+<tr valign=top>
+ <td align=right><p><b><?php print_string("timerestrict", "choice") ?>:</b></p></td>
+ <td>
+ <script>
+ var timeitems = ['openday','openmonth','openyear','openhour', 'openminute', 'closeday','closemonth','closeyear','closehour','closeminute'];
+ </script>
+
+ <input name="timerestrict" type="checkbox" value="1" onclick="return lockoptions('form','timerestrict', timeitems)" <?php if ($form->timerestrict) echo "checked"; ?> >
+ <?php
+ helpbutton("timerestrict", get_string("timerestrict","choice"), "choice");
+ ?>
+ </td>
+</tr>
+<tr valign=top>
+ <td><p> </p></td>
+ <td>
+
+ <table>
+ <tr>
+ <td align="right"><p><b><?php print_string("choiceopen", "choice") ?>:</b></p></td>
+ <td>
+
+ <?php
+ if (!$form->timeopen and $course->format == "weeks") {
+ $form->timeopen = $course->startdate + (($form->section - 1) * 608400);
+ }
+ print_date_selector("openday", "openmonth", "openyear", $form->timeopen);
+ print_time_selector("openhour", "openminute", $form->timeopen);
+ ?>
+
+ <input type="hidden" name="hopenday" value="0">
+ <input type="hidden" name="hopenmonth" value="0">
+ <input type="hidden" name="hopenyear" value="0">
+ <input type="hidden" name="hopenhour" value="0">
+ <input type="hidden" name="hopenminute" value="0">
+ </td>
+ </tr>
+ <tr>
+ <td align=right><p><b><?php print_string("choiceclose", "choice") ?>:</b></p></td>
+ <td>
+
+ <?php
+ if (!$form->timeclose and $course->format == "weeks") {
+ $form->timeclose = $course->startdate + (($form->section) * 608400);
+ }
+ print_date_selector("closeday", "closemonth", "closeyear", $form->timeclose);
+ print_time_selector("closehour", "closeminute", $form->timeclose);
+ ?>
+
+ <input type="hidden" name="hcloseday" value="0">
+ <input type="hidden" name="hclosemonth" value="0">
+ <input type="hidden" name="hcloseyear" value="0">
+ <input type="hidden" name="hclosehour" value="0">
+ <input type="hidden" name="hcloseminute" value="0">
+
+ <?php
+ if (! $form->timerestrict) {
+ echo "<script>";
+ echo "lockoptions('form','timerestrict', timeitems);";
+ echo "</script>\n";
+ }
+ ?>
+
+ </td>
+ </tr>
+ </table>
+
+ </td>
+</tr>
+
<tr valign=top>
<td align=right><P><B><?php print_string("publish","choice") ?>:</b></p></td>
<td>
<?php
- require("$CFG->dirroot/mod/choice/lib.php");
+ require_once("$CFG->dirroot/mod/choice/lib.php");
+ choose_from_menu($CHOICE_RELEASE, "release", "$form->release", "");
+ ?>
+ <br />
+ </td>
+</tr>
+
+<tr valign=top>
+ <td align=right><P><B><?php print_string("privacy","choice") ?>:</b></p></td>
+ <td>
+ <?php
+ require_once("$CFG->dirroot/mod/choice/lib.php");
choose_from_menu($CHOICE_PUBLISH, "publish", "$form->publish", "");
?>
<br />
</td>
</tr>
+
+
+<tr valign=top>
+ <td align=right><P><B><?php print_string("allowupdate","choice") ?>:</b></p></td>
+ <td>
+ <?php
+ $options[0] = get_string("no");
+ $options[1] = get_string("yes");
+ choose_from_menu($options, "allowupdate", "$form->allowupdate", "");
+ ?>
+ <br />
+ </td>
+</tr>
+
+
<tr valign=top>
<td align=right><P><B><?php print_string("showunanswered","choice") ?>:</b></p></td>
<td>
add_to_log($course->id, "choice", "choose", "view.php?id=$cm->id", $choice->id, $cm->id);
}
}
- redirect("$CFG->wwwroot/course/view.php?id=$course->id");
+ redirect("view.php?id=$cm->id");
exit;
}
notice(get_string("activityiscurrentlyhidden"));
}
- print_simple_box( text_to_html($choice->text) , "center");
+ print_simple_box( format_text($choice->text) , "center");
- if (!$current or !$choice->publish) { // They haven't made their choice yet
+
+ // print the form
+
+ if ($choice->timeopen > time() ) {
+ print_simple_box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "center");
+ print_footer();
+ exit;
+ }
+
+ if ( (!$current or $choice->allowupdate) and ($choice->timeclose >= time() or $choice->timeclose == 0) ) {
+ // They haven't made their choice yet or updates allowed and choice is open
+
echo "<CENTER><P><FORM name=\"form\" method=\"post\" action=\"view.php\">";
echo "<TABLE CELLPADDING=20 CELLSPACING=20><TR>";
echo "</TR></TABLE>";
echo "<INPUT type=hidden name=id value=\"$cm->id\">";
- if (!isguest()) {
+ if (isstudent($course->id) or isteacher($course->id, 0, false)) {
echo "<INPUT type=submit value=\"".get_string("savemychoice","choice")."\">";
}
echo "</P></FORM></CENTER>";
- } else { // Print results.
+ }
+
+
+ // print the results
+
+ if ( $choice->release == CHOICE_RELEASE_ALWAYS or
+ ( $choice->release == CHOICE_RELEASE_AFTER_ANSWER and $current ) or
+ ( $choice->release == CHOICE_RELEASE_AFTER_CLOSE and $choice->timeclose <= time() ) ) {
+
print_heading(get_string("responses", "choice"));
if ($currentgroup) {