mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
added repeat_elements method to moodleform and used method for choice form
This commit is contained in:
parent
dfdce7fba9
commit
ebd3c7ac94
@ -18,4 +18,6 @@ $string['nonexistentformelements'] = 'Trying to add help buttons to nonexistent
|
||||
$string['requiredelement'] = 'Required field.';
|
||||
$string['general'] = 'General Settings';
|
||||
$string['modstandardels']='Common Module Settings';
|
||||
?>
|
||||
$string['miscellaneoussettings']='Miscellaneous Settings';
|
||||
$string['addfields']='Add $a fields to form';
|
||||
?>
|
@ -63,6 +63,13 @@ class moodleform {
|
||||
*/
|
||||
var $_upload_manager; //
|
||||
|
||||
/**
|
||||
* Array of buttons that if pressed do not result in the processing of the form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_nosubmitbuttons=array();
|
||||
|
||||
/**
|
||||
* The constructor function calls the abstract function definition() and it will then
|
||||
* process and clean and attempt to validate incoming data.
|
||||
@ -229,7 +236,7 @@ class moodleform {
|
||||
* Must be used BEFORE creating of file element!
|
||||
*
|
||||
* @param object $course
|
||||
* @param object $modbytes - max size limit defined in module
|
||||
* @param object $modbytes - max size limit defined in module
|
||||
*/
|
||||
function set_max_file_size($course=null, $modbytes=0) {
|
||||
global $CFG, $COURSE;
|
||||
@ -292,6 +299,11 @@ class moodleform {
|
||||
* @return object submitted data; NULL if not valid or not submitted
|
||||
*/
|
||||
function data_submitted($slashed=true) {
|
||||
foreach ($this->_nosubmitbuttons as $nosubmitbutton){
|
||||
if (optional_param($nosubmitbutton, 0, PARAM_TEXT)){
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if ($this->is_submitted() and $this->is_validated()) {
|
||||
$data = $this->_form->exportValues(null, $slashed);
|
||||
unset($data['sesskey']); // we do not need to return sesskey
|
||||
@ -358,6 +370,71 @@ class moodleform {
|
||||
function validation($data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function _register_no_submit_button($addfieldsname){
|
||||
$this->_nosubmitbuttons[]=$addfieldsname;
|
||||
}
|
||||
|
||||
function repeat_elements($elementobjs, $repeats, $options, $repeathiddenname, $addfieldsname, $addfieldsno=5, $addstring=array('addfields', 'form')){
|
||||
$repeats = optional_param($repeathiddenname, $repeats, PARAM_INT);
|
||||
$addfields = optional_param($addfieldsname, '', PARAM_TEXT);
|
||||
if (!empty($addfields)){
|
||||
$repeats += $addfieldsno;
|
||||
}
|
||||
$this->_register_no_submit_button($addfieldsname);
|
||||
$mform =& $this->_form;
|
||||
$mform->addElement('hidden', $repeathiddenname, $repeats);
|
||||
//value not to be overridden by submitted value
|
||||
$mform->setConstants(array($repeathiddenname=>$repeats));
|
||||
for ($i=0; $i<$repeats; $i++) {
|
||||
foreach ($elementobjs as $elementobj){
|
||||
$elementclone=clone($elementobj);
|
||||
$name=$elementclone->getName();
|
||||
$elementclone->setName($name."[$i]");
|
||||
if (is_a($elementclone, 'HTML_QuickForm_header')){
|
||||
$value=$elementclone->_text;
|
||||
$elementclone->setValue($value.' '.($i+1));
|
||||
|
||||
}
|
||||
$mform->addElement($elementclone);
|
||||
}
|
||||
}
|
||||
for ($i=0; $i<$repeats; $i++) {
|
||||
foreach ($options as $elementname => $elementoptions){
|
||||
$pos=strpos($elementname, '[');
|
||||
if ($pos!==FALSE){
|
||||
$realelementname = substr($elementname, 0, $pos+1)."[$i]";
|
||||
$realelementname .= substr($elementname, $pos+1);
|
||||
}else {
|
||||
$realelementname = $elementname."[$i]";
|
||||
}
|
||||
foreach ($elementoptions as $option => $params){
|
||||
|
||||
switch ($option){
|
||||
case 'default' :
|
||||
$mform->setDefault($realelementname, $params);
|
||||
break;
|
||||
case 'type' :
|
||||
$mform->setType($realelementname, $params);
|
||||
break;
|
||||
case 'helpbutton' :
|
||||
$mform->setHelpButton($realelementname, $params);
|
||||
break;
|
||||
case 'disabledif' :
|
||||
$mform->disabledIf($realelementname, $params[0], $params[1], $params[2]);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$mform->addElement('submit', $addfieldsname, get_string('addfields', 'form', $addfieldsno),
|
||||
array('onclick'=>'this.form.submit();'));//need this to bypass client validation
|
||||
|
||||
$renderer =& $mform->defaultRenderer();
|
||||
$renderer->addStopFieldsetElements($addfieldsname);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,38 +48,31 @@ function choice_user_complete($course, $user, $mod, $choice) {
|
||||
|
||||
|
||||
function choice_add_instance($choice) {
|
||||
// Given an object containing all the necessary data,
|
||||
// (defined by the form in mod.html) this function
|
||||
// will create a new instance and return the id number
|
||||
// Given an object containing all the necessary data,
|
||||
// (defined by the form in mod.html) this function
|
||||
// will create a new instance and return the id number
|
||||
// of the new instance.
|
||||
|
||||
$choice->timemodified = time();
|
||||
|
||||
if (!empty($choice->timerestrict) and $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 {
|
||||
if (empty($choice->timerestrict)) {
|
||||
$choice->timeopen = 0;
|
||||
$choice->timeclose = 0;
|
||||
}
|
||||
|
||||
//insert answers
|
||||
if ($choice->id = insert_record("choice", $choice)) {
|
||||
foreach ($choice as $name => $value) {
|
||||
if (strstr($name, "newoption")) { /// New option
|
||||
$value = trim($value);
|
||||
if (isset($value) && $value <> '') {
|
||||
$option = NULL;
|
||||
$option->text = $value;
|
||||
$option->choiceid = $choice->id;
|
||||
if (isset($choice->{'newlimit'.substr($name, 9)})) {
|
||||
$option->maxanswers = $choice->{'newlimit'.substr($name, 9)};
|
||||
}
|
||||
$option->timemodified = time();
|
||||
insert_record("choice_options", $option);
|
||||
foreach ($choice->option as $key => $value) {
|
||||
$value = trim($value);
|
||||
if (isset($value) && $value <> '') {
|
||||
$option = new object();
|
||||
$option->text = $value;
|
||||
$option->choiceid = $choice->id;
|
||||
if (isset($choice->limit[$key])) {
|
||||
$option->maxanswers = $choice->limit[$key];
|
||||
}
|
||||
$option->timemodified = time();
|
||||
insert_record("choice_options", $option);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,52 +81,38 @@ function choice_add_instance($choice) {
|
||||
|
||||
|
||||
function choice_update_instance($choice) {
|
||||
// Given an object containing all the necessary data,
|
||||
// (defined by the form in mod.html) this function
|
||||
// Given an object containing all the necessary data,
|
||||
// (defined by the form in mod.html) this function
|
||||
// will update an existing instance with new data.
|
||||
|
||||
$choice->id = $choice->instance;
|
||||
$choice->timemodified = time();
|
||||
|
||||
|
||||
if (!empty($choice->timerestrict) and $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 {
|
||||
if (empty($choice->timerestrict)) {
|
||||
$choice->timeopen = 0;
|
||||
$choice->timeclose = 0;
|
||||
}
|
||||
|
||||
//update answers
|
||||
|
||||
foreach ($choice as $name => $value) {
|
||||
//update, delete or insert answers
|
||||
foreach ($choice->option as $key => $value) {
|
||||
$value = trim($value);
|
||||
|
||||
if (strstr($name, "oldoption")) { // Old option
|
||||
$option = new object();
|
||||
$option->text = $value;
|
||||
$option->choiceid = $choice->id;
|
||||
if (isset($choice->limit[$key])) {
|
||||
$option->maxanswers = $choice->limit[$key];
|
||||
}
|
||||
$option->timemodified = time();
|
||||
if (isset($choice->optionid[$key])){//existing choice record
|
||||
$option->id=$choice->optionid[$key];
|
||||
if (isset($value) && $value <> '') {
|
||||
$option = NULL;
|
||||
$option->id = substr($name, 9); // Get the ID of the answer that needs to be updated.
|
||||
$option->text = $value;
|
||||
$option->choiceid = $choice->id;
|
||||
if (isset($choice->{'oldlimit'.substr($name, 9)})) {
|
||||
$option->maxanswers = $choice->{'oldlimit'.substr($name, 9)};
|
||||
}
|
||||
$option->timemodified = time();
|
||||
update_record("choice_options", $option);
|
||||
} else { //empty old option - needs to be deleted.
|
||||
delete_records("choice_options", "id", substr($name, 9));
|
||||
delete_records("choice_options", "id", $option->id);
|
||||
}
|
||||
} else if (strstr($name, "newoption")) { /// New option
|
||||
if (isset($value)&& $value <> '') {
|
||||
$option = NULL;
|
||||
$option->text = $value;
|
||||
$option->choiceid = $choice->id;
|
||||
if (isset($choice->{'newlimit'.substr($name, 9)})) {
|
||||
$option->maxanswers = $choice->{'newlimit'.substr($name, 9)};
|
||||
}
|
||||
$option->timemodified = time();
|
||||
} else {
|
||||
if (isset($value) && $value <> '') {
|
||||
insert_record("choice_options", $option);
|
||||
}
|
||||
}
|
||||
@ -144,7 +123,7 @@ function choice_update_instance($choice) {
|
||||
}
|
||||
|
||||
function choice_show_form($choice, $user, $cm) {
|
||||
|
||||
|
||||
//$cdisplay is an array of the display info for a choice $cdisplay[$optionid]->text - text name of option.
|
||||
// ->maxanswers -maxanswers for this option
|
||||
// ->full - whether this option is full or not. 0=not full, 1=full
|
||||
@ -154,7 +133,7 @@ function choice_show_form($choice, $user, $cm) {
|
||||
foreach ($choice->option as $optionid => $text) {
|
||||
if (isset($text)) { //make sure there are no dud entries in the db with blank text values.
|
||||
$countanswers = (get_records("choice_answers", "optionid", $optionid));
|
||||
$countans = 0;
|
||||
$countans = 0;
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
if (!empty($countanswers)) {
|
||||
foreach ($countanswers as $ca) { //only return enrolled users.
|
||||
@ -183,7 +162,7 @@ function choice_show_form($choice, $user, $cm) {
|
||||
if ($choice->limitanswers && ($countans >= $maxans) && (empty($cdisplay[$aid]->checked)) ) {
|
||||
$cdisplay[$aid]->disabled = ' disabled="disabled" ';
|
||||
} else {
|
||||
$cdisplay[$aid]->disabled = '';
|
||||
$cdisplay[$aid]->disabled = '';
|
||||
}
|
||||
$aid++;
|
||||
}
|
||||
@ -192,11 +171,11 @@ function choice_show_form($choice, $user, $cm) {
|
||||
switch ($choice->display) {
|
||||
case CHOICE_DISPLAY_HORIZONTAL:
|
||||
echo "<table cellpadding=\"20\" cellspacing=\"20\" align=\"center\"><tr>";
|
||||
|
||||
foreach ($cdisplay as $cd) {
|
||||
|
||||
foreach ($cdisplay as $cd) {
|
||||
echo "<td align=\"center\" valign=\"top\">";
|
||||
echo "<input type=\"radio\" name=\"answer\" value=\"".$cd->optionid."\" alt=\"".strip_tags(format_text($cd->text))."\"". $cd->checked.$cd->disabled." />";
|
||||
if (!empty($cd->disabled)) {
|
||||
if (!empty($cd->disabled)) {
|
||||
echo format_text($cd->text."<br /><strong>".get_string('full', 'choice')."</strong>");
|
||||
} else {
|
||||
echo format_text($cd->text);
|
||||
@ -272,7 +251,7 @@ function choice_user_submit_response($formanswer, $choice, $userid, $courseid, $
|
||||
|
||||
if (!($choice->limitanswers && ($countanswers >= $maxans) )) {
|
||||
if ($current) {
|
||||
|
||||
|
||||
$newanswer = $current;
|
||||
$newanswer->optionid = $formanswer;
|
||||
$newanswer->timemodified = time();
|
||||
@ -293,7 +272,7 @@ function choice_user_submit_response($formanswer, $choice, $userid, $courseid, $
|
||||
}
|
||||
} else {
|
||||
if (!($current->optionid==$formanswer)) { //check to see if current choice already selected - if not display error
|
||||
error("this choice is full!");
|
||||
error("this choice is full!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -383,7 +362,7 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') {
|
||||
echo '<input type="hidden" name="mode" value="overview" />';
|
||||
}
|
||||
|
||||
echo "<table cellpadding=\"5\" cellspacing=\"10\" align=\"center\" class=\"results names\">";
|
||||
echo "<table cellpadding=\"5\" cellspacing=\"10\" align=\"center\" class=\"results names\">";
|
||||
echo "<tr>";
|
||||
$count = 0;
|
||||
foreach ($useranswer as $optionid => $userlist) {
|
||||
@ -442,8 +421,8 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') {
|
||||
}
|
||||
echo "<td align=\"center\" class=\"count\">";
|
||||
$countanswers = get_records("choice_answers", "optionid", $optionid);
|
||||
$countans = 0;
|
||||
if (!empty($countanswers)) {
|
||||
$countans = 0;
|
||||
if (!empty($countanswers)) {
|
||||
foreach ($countanswers as $ca) { //only return enrolled users.
|
||||
if (has_capability('mod/choice:choose', get_context_instance(CONTEXT_MODULE, $cm->id))) {
|
||||
$countans = $countans+1;
|
||||
@ -461,7 +440,7 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') {
|
||||
echo "</td>";
|
||||
$count++;
|
||||
}
|
||||
|
||||
|
||||
/// Print "Select all" etc.
|
||||
if (has_capability('mod/choice:readresponses', $context)) {
|
||||
echo '<tr><td><p>';
|
||||
@ -476,7 +455,7 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') {
|
||||
echo '<script type="text/javascript">'."\n<!--\n".'document.getElementById("noscriptmenuaction").style.display = "none";'."\n-->\n".'</script>';
|
||||
echo '</p></td></tr>';
|
||||
}
|
||||
|
||||
|
||||
echo "</tr></table>";
|
||||
if (has_capability('mod/choice:readresponses', $context)) {
|
||||
echo "</form></div>";
|
||||
@ -561,12 +540,12 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') {
|
||||
echo "</tr></table>";
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function choice_delete_responses($attemptids) {
|
||||
|
||||
|
||||
if(!is_array($attemptids) || empty($attemptids)) {
|
||||
return false;
|
||||
}
|
||||
@ -581,15 +560,15 @@ function choice_delete_responses($attemptids) {
|
||||
if ($todelete = get_record('choice_answers', 'id', $attemptid)) {
|
||||
delete_records('choice_answers', 'id', $attemptid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function choice_delete_instance($id) {
|
||||
// Given an ID of an instance of this module,
|
||||
// this function will permanently delete the instance
|
||||
// and any data that depends on it.
|
||||
// Given an ID of an instance of this module,
|
||||
// this function will permanently delete the instance
|
||||
// and any data that depends on it.
|
||||
|
||||
if (! $choice = get_record("choice", "id", "$id")) {
|
||||
return false;
|
||||
@ -607,7 +586,7 @@ function choice_delete_instance($id) {
|
||||
|
||||
if (! delete_records("choice", "id", "$choice->id")) {
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
@ -645,7 +624,7 @@ function choice_get_choice($choiceid) {
|
||||
if ($choice = get_record("choice", "id", $choiceid)) {
|
||||
if ($options = get_records("choice_options", "choiceid", $choiceid, "id")) {
|
||||
foreach ($options as $option) {
|
||||
$choice->option[$option->id] = $option->text;
|
||||
$choice->option[$option->id] = $option->text;
|
||||
$choice->maxanswers[$option->id] = $option->maxanswers;
|
||||
}
|
||||
return $choice;
|
||||
|
@ -1,320 +0,0 @@
|
||||
<?php
|
||||
if (empty($form->name)) {
|
||||
$form->name = "";
|
||||
}
|
||||
if (empty($form->text)) {
|
||||
$form->text = "";
|
||||
}
|
||||
if (empty($form->format)) {
|
||||
$form->format = 0;
|
||||
}
|
||||
if (empty($form->display)) {
|
||||
$form->display = 0;
|
||||
}
|
||||
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->showresults)) {
|
||||
$form->showresults = 0;
|
||||
}
|
||||
if (empty($form->allowupdate)) {
|
||||
$form->allowupdate = 0;
|
||||
}
|
||||
if (empty($form->showunanswered)) {
|
||||
$form->showunanswered = 0;
|
||||
}
|
||||
if (empty($form->limitanswers)) {
|
||||
$form->limitanswers = 0;
|
||||
}
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function lockselects(form, master, subitems) {
|
||||
// subitems is an array of names of sub items
|
||||
// requires that each item in subitems has a
|
||||
// companion hidden item in the form with the
|
||||
// same name but prefixed by "h"
|
||||
// master is the name of the selct
|
||||
// x is the option that is selcted to enforce the lock.
|
||||
if (eval("document."+form+"."+master+".selected")) {
|
||||
for (i=0; i<subitems.length; i++) {
|
||||
lockoption(form, subitems[i]);
|
||||
}
|
||||
} else {
|
||||
for (i=0; i<subitems.length; i++) {
|
||||
unlockoption(form, subitems[i]);
|
||||
}
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
</script>
|
||||
<form name="form" method="post" action="mod.php">
|
||||
|
||||
<table cellpadding="5">
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right"><strong><?php print_string("choicename","choice") ?>:</strong></td>
|
||||
<td colspan="2">
|
||||
<input type="text" name="name" size="30" alt="<?php print_string("choicename","choice") ?>" value="<?php p($form->name) ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right"><strong><?php print_string("choicetext","choice") ?>:</strong><br /><br />
|
||||
<?php
|
||||
helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
|
||||
echo "<br />";
|
||||
helpbutton("questions", get_string("helpquestions"), "moodle", true, true);
|
||||
echo "<br />";
|
||||
if ($usehtmleditor) {
|
||||
helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
|
||||
} else {
|
||||
emoticonhelpbutton("form", "text");
|
||||
}
|
||||
echo "<br />";
|
||||
?>
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<?php
|
||||
print_textarea($usehtmleditor, 20, 60, 680, 400, "text", $form->text);
|
||||
|
||||
if ($usehtmleditor) {
|
||||
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
|
||||
} else {
|
||||
echo "<div align=\"right\">";
|
||||
helpbutton("textformat", get_string("formattexttype"));
|
||||
print_string("formattexttype");
|
||||
echo ": ";
|
||||
if (!$form->format) {
|
||||
$form->format = $defaultformat;
|
||||
}
|
||||
choose_from_menu(format_text_menu(), "format", $form->format, "");
|
||||
echo "</div>";
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
$standardblanks = 10;
|
||||
$count = 0;
|
||||
$limitfieldlist = '';
|
||||
if (!empty($form->instance) && ($options = get_records_menu('choice_options','choiceid', $form->instance, 'id', 'id,text')) && ($options2 = get_records_menu('choice_options','choiceid', $form->instance, 'id', 'id,maxanswers')) ) {
|
||||
foreach ($options as $id => $text) {
|
||||
$count++;
|
||||
?>
|
||||
<tr valign=top>
|
||||
<td align="right"><strong><?php echo get_string("choice","choice").' '.$count; ?>:</strong></td>
|
||||
<td>
|
||||
<input type="text" name="oldoption<?php p($id) ?>" size="60" value="<?php p($text) ?>" id="oldoption<?php p($id) ?>" />
|
||||
<?php helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
|
||||
</td>
|
||||
<td align="right"><strong><?php p(get_string("limit","choice")) ?>:</strong>
|
||||
<input type="text" name="oldlimit<?php p($id) ?>" size="4" value="<?php p($options2[$id]) ?>" id="oldlimit<?php p($id) ?>" />
|
||||
<input type="hidden" name="holdlimit<?php p($id) ?>" value="0"/>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$limitfieldlist .= "'oldlimit".$id."',";
|
||||
}
|
||||
$standardblanks = 2;
|
||||
}
|
||||
for ($i=1; $i<=$standardblanks; $i++) {
|
||||
$count++;
|
||||
?>
|
||||
<tr valign=top>
|
||||
<td align="right"><strong><?php echo get_string("choice","choice").' '.$count; ?>:</strong></td>
|
||||
<td>
|
||||
<input type="text" name="newoption<?php p($i) ?>" size="60" value="" id="newoption<?php p($i) ?>">
|
||||
<?php helpbutton("options", get_string("modulenameplural", "choice"), "choice") ?>
|
||||
</td>
|
||||
<td align="right"><strong><?php p(get_string("limit","choice")) ?>:</strong>
|
||||
<input type="text" name="newlimit<?php p($i)?>" size="4" value="0" id="newlimit<?php p($i) ?>" />
|
||||
<input type="hidden" name="hnewlimit<?php p($i) ?>" value="0" />
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$limitfieldlist .= "'newlimit".$i."',";
|
||||
}
|
||||
$limitfieldlist = trim($limitfieldlist, ",");
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
limititems = [<?php p($limitfieldlist); ?>];
|
||||
</script>
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right" colspan="2"><strong><?php print_string("limitanswers", "choice") ?>:</strong></td>
|
||||
<td align="right">
|
||||
<?php
|
||||
$menuoptions[0] = get_string("disable");
|
||||
$menuoptions[1] = get_string("enable");
|
||||
helpbutton("limit", get_string("limit", "choice"), "choice");
|
||||
echo ' ';
|
||||
choose_from_menu($menuoptions, "limitanswers", "$form->limitanswers", "", "return lockselects('form','limitanswers.options[0]', limititems)");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php if ($form->limitanswers == 0) { //lock the limit fields if limit isn't used.
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
lockoptions('form','limitanswers', limititems);
|
||||
</script>
|
||||
<?php }?>
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right"><strong><?php print_string("timerestrict", "choice") ?>:</strong></td>
|
||||
<td colspan="2">
|
||||
<script type="text/javascript">
|
||||
var timeitems = ['openday','openmonth','openyear','openhour', 'openminute', 'closeday','closemonth','closeyear','closehour','closeminute'];
|
||||
</script>
|
||||
|
||||
<input name="timerestrict" type="checkbox" value="1" alt="<?php print_string("timerestrict", "choice") ?>" onclick="return lockoptions('form','timerestrict', timeitems)" <?php if ($form->timerestrict) echo 'checked="checked"'; ?> />
|
||||
<?php
|
||||
helpbutton("timerestrict", get_string("timerestrict","choice"), "choice");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td> </td>
|
||||
<td colspan="2">
|
||||
<table>
|
||||
<tr>
|
||||
<td align="right"><strong><?php print_string("choiceopen", "choice") ?>:</strong></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"><strong><?php print_string("choiceclose", "choice") ?>:</strong></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 type=\"text/javascript\">";
|
||||
echo "lockoptions('form','timerestrict', timeitems);";
|
||||
echo "</script>\n";
|
||||
}
|
||||
?>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right"><strong><?php print_string("displaymode","choice") ?>:</strong></td>
|
||||
<td colspan="2">
|
||||
<?php
|
||||
require_once("$CFG->dirroot/mod/choice/lib.php");
|
||||
choose_from_menu($CHOICE_DISPLAY, "display", "$form->display", "");
|
||||
?>
|
||||
<br />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right"><strong><?php print_string("publish","choice") ?>:</strong></td>
|
||||
<td colspan="2">
|
||||
<?php
|
||||
require_once("$CFG->dirroot/mod/choice/lib.php");
|
||||
choose_from_menu($CHOICE_SHOWRESULTS, "showresults", "$form->showresults", "", "return lockselects('form','showresults.options[0]',['publish'])");
|
||||
?>
|
||||
<br />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right"><strong><?php print_string("privacy","choice") ?>:</strong></td>
|
||||
<td colspan="2">
|
||||
<?php
|
||||
require_once("$CFG->dirroot/mod/choice/lib.php");
|
||||
choose_from_menu($CHOICE_PUBLISH, "publish", "$form->publish", "");
|
||||
?>
|
||||
<br />
|
||||
<input type="hidden" name="hpublish" value="0" />
|
||||
</td>
|
||||
</tr>
|
||||
<script type="text/javascript">
|
||||
lockselects('form','showresults.options[0]',['publish']);
|
||||
</script>
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right"><strong><?php print_string("allowupdate","choice") ?>:</strong></td>
|
||||
<td colspan="2">
|
||||
<?php
|
||||
$menuoptions[0] = get_string("no");
|
||||
$menuoptions[1] = get_string("yes");
|
||||
choose_from_menu($menuoptions, "allowupdate", "$form->allowupdate", "");
|
||||
?>
|
||||
<br />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right"><strong><?php print_string("showunanswered","choice") ?>:</strong></td>
|
||||
<td colspan="2">
|
||||
<?php
|
||||
$menuoptions[0] = get_string("no");
|
||||
$menuoptions[1] = get_string("yes");
|
||||
choose_from_menu($menuoptions, "showunanswered", "$form->showunanswered", "");
|
||||
?>
|
||||
<br />
|
||||
</td>
|
||||
</tr>
|
||||
<?php print_standard_coursemodule_settings($form); ?>
|
||||
</table>
|
||||
|
||||
<center>
|
||||
<input type="hidden" name="course" value="<?php p($form->course) ?>" />
|
||||
<input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />
|
||||
<input type="hidden" name="coursemodule" value="<?php p($form->coursemodule) ?>" />
|
||||
<input type="hidden" name="section" value="<?php p($form->section) ?>" />
|
||||
<input type="hidden" name="module" value="<?php p($form->module) ?>" />
|
||||
<input type="hidden" name="modulename" value="<?php p($form->modulename) ?>" />
|
||||
<input type="hidden" name="instance" value="<?php p($form->instance) ?>" />
|
||||
<input type="hidden" name="mode" value="<?php p($form->mode) ?>" />
|
||||
<input type="submit" value="<?php print_string("savechanges") ?>" />
|
||||
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
|
||||
</center>
|
||||
</form>
|
116
mod/choice/mod_form.php
Normal file
116
mod/choice/mod_form.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
require_once ('moodleform_mod.php');
|
||||
|
||||
class choice_mod_form extends moodleform_mod {
|
||||
|
||||
function definition() {
|
||||
global $CHOICE_SHOWRESULTS, $CHOICE_PUBLISH, $CHOICE_DISPLAY;
|
||||
|
||||
$mform =& $this->_form;
|
||||
$renderer =& $mform->defaultRenderer();
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('choicename', 'choice'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
$mform->addElement('htmleditor', 'text', get_string('choicetext', 'choice'));
|
||||
$mform->setType('text', PARAM_RAW);
|
||||
$mform->addRule('text', null, 'required', null, 'client');
|
||||
|
||||
$mform->addElement('format', 'format', get_string('format'));
|
||||
|
||||
$repeatarray=array();
|
||||
$repeatarray[] = &MoodleQuickForm::createElement('header', '', get_string('choice','choice'));
|
||||
$repeatarray[] = &MoodleQuickForm::createElement('text', 'option', get_string('choice','choice'));
|
||||
$repeatarray[] = &MoodleQuickForm::createElement('text', 'limit', get_string('limit','choice'));
|
||||
$repeatarray[] = &MoodleQuickForm::createElement('hidden', 'optionid', 0);
|
||||
|
||||
if ($this->_instance){
|
||||
$repeatno=count_records('choice_options', 'choiceid', $this->_instance);
|
||||
$repeatno+=2;
|
||||
} else {
|
||||
$repeatno=10;
|
||||
}
|
||||
|
||||
$this->repeat_elements($repeatarray, $repeatno,
|
||||
array('limit'=>array('default'=>0,
|
||||
'type'=>PARAM_INT,
|
||||
'disabledif'=>array('limitanswers', 'eq', 0)),
|
||||
|
||||
'option' =>array('type'=>PARAM_TEXT,
|
||||
'helpbutton'=>array('options', get_string('modulenameplural', 'choice'), 'choice')),
|
||||
'optionid' =>array('type'=>PARAM_INT)),
|
||||
'option_repeats', 'option_add_fields');
|
||||
|
||||
|
||||
|
||||
$menuoptions=array();
|
||||
$menuoptions[0] = get_string('disable');
|
||||
$menuoptions[1] = get_string('enable');
|
||||
$mform->addElement('select', 'limitanswers', get_string('limitanswers', 'choice'), $menuoptions);
|
||||
$mform->setHelpButton('limitanswers', array('limit', get_string('limit', 'choice'), 'choice'));
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'timerestricthdr', get_string('timerestrict', 'choice'));
|
||||
$mform->addElement('checkbox', 'timerestrict', get_string('timerestrict', 'choice'));
|
||||
$mform->setHelpButton('timerestrict', array("timerestrict", get_string("timerestrict","choice"), "choice"));
|
||||
|
||||
|
||||
$mform->addElement('date_time_selector', 'timeopen', get_string("choiceopen", "choice"));
|
||||
$mform->disabledIf('timeopen', 'timerestrict');
|
||||
|
||||
$mform->addElement('date_time_selector', 'timeclose', get_string("choiceclose", "choice"));
|
||||
$mform->disabledIf('timeclose', 'timerestrict');
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'miscellaneoussettingshdr', get_string('miscellaneoussettings', 'form'));
|
||||
|
||||
$mform->addElement('select', 'display', get_string("displaymode","choice"), $CHOICE_DISPLAY);
|
||||
|
||||
$mform->addElement('select', 'showresults', get_string("publish", "choice"), $CHOICE_SHOWRESULTS);
|
||||
|
||||
$mform->addElement('select', 'publish', get_string("privacy", "choice"), $CHOICE_PUBLISH);
|
||||
$mform->disabledIf('publish', 'showresults', 'eq', 0);
|
||||
|
||||
$mform->addElement('selectyesno', 'allowupdate', get_string("allowupdate", "choice"));
|
||||
|
||||
$mform->addElement('selectyesno', 'showunanswered', get_string("showunanswered", "choice"));
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
$this->standard_coursemodule_elements();
|
||||
//-------------------------------------------------------------------------------
|
||||
|
||||
$buttonarray=array();
|
||||
$buttonarray[] = &MoodleQuickForm::createElement('submit', 'submit', get_string('savechanges'));
|
||||
$buttonarray[] = &MoodleQuickForm::createElement('submit', 'cancel', get_string('cancel'));
|
||||
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
|
||||
$renderer->addStopFieldsetElements('buttonar');
|
||||
}
|
||||
|
||||
function defaults_preprocessing(&$default_values){
|
||||
if (!empty($this->_instance) && ($options = get_records_menu('choice_options','choiceid', $this->_instance, 'id', 'id,text'))
|
||||
&& ($options2 = get_records_menu('choice_options','choiceid', $this->_instance, 'id', 'id,maxanswers')) ) {
|
||||
$choiceids=array_keys($options);
|
||||
$options=array_values($options);
|
||||
$options2=array_values($options2);
|
||||
|
||||
foreach (array_keys($options) as $key){
|
||||
$default_values['option['.$key.']'] = $options[$key];
|
||||
$default_values['limit['.$key.']'] = $options2[$key];
|
||||
$default_values['optionid['.$key.']'] = $choiceids[$key];
|
||||
}
|
||||
|
||||
}
|
||||
if (empty($default_values['timeopen'])) {
|
||||
$default_values['timerestrict'] = 0;
|
||||
} else {
|
||||
$default_values['timerestrict'] = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user