diff --git a/add_form.php b/add_form.php index 5d40c25..2d294a6 100644 --- a/add_form.php +++ b/add_form.php @@ -189,27 +189,33 @@ class mod_attendance_add_form extends moodleform { $mform->setType('previoussessiondate', PARAM_INT); // Students can mark own attendance. - if (!empty(get_config('attendance', 'studentscanmark'))) { - $mform->addElement('header', 'headerstudentmarking', get_string('studentmarking', 'attendance'), true); - if (!empty($pluginconfig->studentrecordingexpanded)) { - $mform->setExpanded('headerstudentmarking'); - } + $studentscanmark = get_config('attendance', 'studentscanmark'); + + $mform->addElement('header', 'headerstudentmarking', get_string('studentmarking', 'attendance'), true); + if (!empty($pluginconfig->studentrecordingexpanded)) { + $mform->setExpanded('headerstudentmarking'); + } + if (!empty($studentscanmark)) { $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance')); $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance'); + } else { + $mform->addElement('hidden', 'studentscanmark', '0'); + $mform->settype('studentscanmark', PARAM_INT); + } - $options = attendance_get_automarkoptions(); + $options = attendance_get_automarkoptions(); - $mform->addElement('select', 'automark', get_string('automark', 'attendance'), $options); - $mform->setType('automark', PARAM_INT); - $mform->addHelpButton('automark', 'automark', 'attendance'); - $mform->hideif('automark', 'studentscanmark', 'notchecked'); - $mform->setDefault('automark', $this->_customdata['att']->automark); + $mform->addElement('select', 'automark', get_string('automark', 'attendance'), $options); + $mform->setType('automark', PARAM_INT); + $mform->addHelpButton('automark', 'automark', 'attendance'); + $mform->setDefault('automark', $this->_customdata['att']->automark); + if (!empty($studentscanmark)) { $mgroup = array(); - $mgroup[] = & $mform->createElement('text', 'studentpassword', get_string('studentpassword', 'attendance')); - $mgroup[] = & $mform->createElement('checkbox', 'randompassword', '', get_string('randompassword', 'attendance')); - $mgroup[] = & $mform->createElement('checkbox', 'includeqrcode', '', get_string('includeqrcode', 'attendance')); + $mgroup[] = &$mform->createElement('text', 'studentpassword', get_string('studentpassword', 'attendance')); + $mgroup[] = &$mform->createElement('checkbox', 'randompassword', '', get_string('randompassword', 'attendance')); + $mgroup[] = &$mform->createElement('checkbox', 'includeqrcode', '', get_string('includeqrcode', 'attendance')); $mform->addGroup($mgroup, 'passwordgrp', get_string('passwordgrp', 'attendance'), array(' '), false); $mform->setType('studentpassword', PARAM_TEXT); @@ -237,63 +243,41 @@ class mod_attendance_add_form extends moodleform { if (isset($pluginconfig->automark_default)) { $mform->setDefault('automark', $pluginconfig->automark_default); } - $mgroup2 = array(); - $mgroup2[] = & $mform->createElement('text', 'subnet', get_string('requiresubnet', 'attendance')); - if (empty(get_config('attendance', 'subnetactivitylevel'))) { - $mform->setDefault('subnet', get_config('attendance', 'subnet')); - } else { - $mform->setDefault('subnet', $this->_customdata['att']->subnet); - } - - $mgroup2[] = & $mform->createElement('checkbox', 'usedefaultsubnet', get_string('usedefaultsubnet', 'attendance')); - $mform->setDefault('usedefaultsubnet', 1); - $mform->setType('subnet', PARAM_TEXT); - - $mform->addGroup($mgroup2, 'subnetgrp', get_string('requiresubnet', 'attendance'), array(' '), false); - $mform->setAdvanced('subnetgrp'); - $mform->addHelpButton('subnetgrp', 'requiresubnet', 'attendance'); - - $mform->hideif('subnetgrp', 'studentscanmark', 'notchecked'); - $mform->hideif('subnet', 'usedefaultsubnet', 'checked'); - - $mgroup3 = array(); - $options = attendance_get_sharedipoptions(); - $mgroup3[] = & $mform->createElement('select', 'preventsharedip', - get_string('preventsharedip', 'attendance'), $options); - $mgroup3[] = & $mform->createElement('text', 'preventsharediptime', - get_string('preventsharediptime', 'attendance'), '', 'test'); - $mform->addGroup($mgroup3, 'preventsharedgroup', get_string('preventsharedip', 'attendance'), array(' '), false); - $mform->addHelpButton('preventsharedgroup', 'preventsharedip', 'attendance'); - $mform->setAdvanced('preventsharedgroup'); - $mform->setType('preventsharedip', PARAM_INT); - $mform->setType('preventsharediptime', PARAM_INT); - $mform->hideif('preventsharedgroup', 'studentscanmark', 'notchecked'); - $mform->hideIf('preventsharediptime', 'preventsharedip', 'noteq', ATTENDANCE_SHAREDIP_MINUTES); - - if (isset($pluginconfig->preventsharedip)) { - $mform->setDefault('preventsharedip', $pluginconfig->preventsharedip); - } - if (isset($pluginconfig->preventsharediptime)) { - $mform->setDefault('preventsharediptime', $pluginconfig->preventsharediptime); - } - + } + $mgroup2 = array(); + $mgroup2[] = & $mform->createElement('text', 'subnet', get_string('requiresubnet', 'attendance')); + if (empty(get_config('attendance', 'subnetactivitylevel'))) { + $mform->setDefault('subnet', get_config('attendance', 'subnet')); } else { - $mform->addElement('hidden', 'studentscanmark', '0'); - $mform->settype('studentscanmark', PARAM_INT); - $mform->addElement('hidden', 'automark', '0'); - $mform->setType('automark', PARAM_INT); - $mform->addElement('hidden', 'autoassignstatus', '0'); - $mform->setType('autoassignstatus', PARAM_INT); - - $mform->addElement('hidden', 'subnet', ''); - $mform->setType('subnet', PARAM_TEXT); - - $mform->addElement('hidden', 'preventsharedip', '0'); - $mform->setType('preventsharedip', PARAM_INT); + $mform->setDefault('subnet', $this->_customdata['att']->subnet); + } - $sharedtime = isset($pluginconfig->preventsharediptime) ? $pluginconfig->preventsharediptime : null; - $mform->addElement('hidden', 'preventsharediptime', $sharedtime); - $mform->setType('preventsharediptime', PARAM_INT); + $mgroup2[] = & $mform->createElement('checkbox', 'usedefaultsubnet', get_string('usedefaultsubnet', 'attendance')); + $mform->setDefault('usedefaultsubnet', 1); + $mform->setType('subnet', PARAM_TEXT); + + $mform->addGroup($mgroup2, 'subnetgrp', get_string('requiresubnet', 'attendance'), array(' '), false); + $mform->setAdvanced('subnetgrp'); + $mform->addHelpButton('subnetgrp', 'requiresubnet', 'attendance'); + $mform->hideif('subnet', 'usedefaultsubnet', 'checked'); + + $mgroup3 = array(); + $options = attendance_get_sharedipoptions(); + $mgroup3[] = & $mform->createElement('select', 'preventsharedip', + get_string('preventsharedip', 'attendance'), $options); + $mgroup3[] = & $mform->createElement('text', 'preventsharediptime', + get_string('preventsharediptime', 'attendance'), '', 'test'); + $mform->addGroup($mgroup3, 'preventsharedgroup', get_string('preventsharedip', 'attendance'), array(' '), false); + $mform->addHelpButton('preventsharedgroup', 'preventsharedip', 'attendance'); + $mform->setAdvanced('preventsharedgroup'); + $mform->setType('preventsharedip', PARAM_INT); + $mform->setType('preventsharediptime', PARAM_INT); + + if (isset($pluginconfig->preventsharedip)) { + $mform->setDefault('preventsharedip', $pluginconfig->preventsharedip); + } + if (isset($pluginconfig->preventsharediptime)) { + $mform->setDefault('preventsharediptime', $pluginconfig->preventsharediptime); } $this->add_action_buttons(true, get_string('add', 'attendance')); diff --git a/classes/structure.php b/classes/structure.php index 9090216..6b2f14f 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -558,30 +558,31 @@ class mod_attendance_structure { if (!empty($formdata->autoassignstatus)) { $sess->autoassignstatus = $formdata->autoassignstatus; } - if (!empty(get_config('attendance', 'studentscanmark')) && + $studentscanmark = get_config('attendance', 'studentscanmark'); + + if (!empty($studentscanmark) && !empty($formdata->studentscanmark)) { $sess->studentscanmark = $formdata->studentscanmark; $sess->studentpassword = $formdata->studentpassword; $sess->autoassignstatus = $formdata->autoassignstatus; - if (!empty($formdata->usedefaultsubnet)) { - $sess->subnet = $this->subnet; - } else { - $sess->subnet = $formdata->subnet; - } - - if (!empty($formdata->automark)) { - $sess->automark = $formdata->automark; - } - if (!empty($formdata->preventsharedip)) { - $sess->preventsharedip = $formdata->preventsharedip; - } - if (!empty($formdata->preventsharediptime)) { - $sess->preventsharediptime = $formdata->preventsharediptime; - } if (!empty($formdata->includeqrcode)) { $sess->includeqrcode = $formdata->includeqrcode; } + } + if (!empty($formdata->usedefaultsubnet)) { + $sess->subnet = $this->subnet; + } else { + $sess->subnet = $formdata->subnet; + } + if (!empty($formdata->automark)) { + $sess->automark = $formdata->automark; + } + if (!empty($formdata->preventsharedip)) { + $sess->preventsharedip = $formdata->preventsharedip; + } + if (!empty($formdata->preventsharediptime)) { + $sess->preventsharediptime = $formdata->preventsharediptime; } $sess->timemodified = time(); diff --git a/locallib.php b/locallib.php index 7ac157d..bc3a7e7 100644 --- a/locallib.php +++ b/locallib.php @@ -634,18 +634,26 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st $sess->absenteereport = $absenteereport; $sess->studentpassword = ''; $sess->includeqrcode = 0; + if (!empty($formdata->usedefaultsubnet)) { + $sess->subnet = $att->subnet; + } else { + $sess->subnet = $formdata->subnet; + } + $sess->automark = $formdata->automark; + $sess->automarkcompleted = 0; + if (!empty($formdata->preventsharedip)) { + $sess->preventsharedip = $formdata->preventsharedip; + } + if (!empty($formdata->preventsharediptime)) { + $sess->preventsharediptime = $formdata->preventsharediptime; + } + if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance. $sess->studentscanmark = 1; - if (!empty($formdata->usedefaultsubnet)) { - $sess->subnet = $att->subnet; - } else { - $sess->subnet = $formdata->subnet; - } - $sess->automark = $formdata->automark; if (isset($formdata->autoassignstatus)) { $sess->autoassignstatus = 1; } - $sess->automarkcompleted = 0; + if (!empty($formdata->randompassword)) { $sess->studentpassword = attendance_random_string(); } else if (!empty($formdata->studentpassword)) { @@ -654,18 +662,6 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st if (!empty($formdata->includeqrcode)) { $sess->includeqrcode = $formdata->includeqrcode; } - if (!empty($formdata->preventsharedip)) { - $sess->preventsharedip = $formdata->preventsharedip; - } - if (!empty($formdata->preventsharediptime)) { - $sess->preventsharediptime = $formdata->preventsharediptime; - } - } else { - $sess->subnet = ''; - $sess->automark = 0; - $sess->automarkcompleted = 0; - $sess->preventsharedip = 0; - $sess->preventsharediptime = ''; } $sess->statusset = $formdata->statusset; @@ -695,6 +691,22 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st $sess->absenteereport = $absenteereport; $sess->includeqrcode = 0; + if (!empty($formdata->usedefaultsubnet)) { + $sess->subnet = $att->subnet; + } else { + $sess->subnet = $formdata->subnet; + } + + if (!empty($formdata->automark)) { + $sess->automark = $formdata->automark; + } + if (!empty($formdata->preventsharedip)) { + $sess->preventsharedip = $formdata->preventsharedip; + } + if (!empty($formdata->preventsharediptime)) { + $sess->preventsharediptime = $formdata->preventsharediptime; + } + if (isset($formdata->studentscanmark) && !empty($formdata->studentscanmark)) { // Students will be able to mark their own attendance. $sess->studentscanmark = 1; @@ -709,21 +721,6 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st if (!empty($formdata->includeqrcode)) { $sess->includeqrcode = $formdata->includeqrcode; } - if (!empty($formdata->usedefaultsubnet)) { - $sess->subnet = $att->subnet; - } else { - $sess->subnet = $formdata->subnet; - } - - if (!empty($formdata->automark)) { - $sess->automark = $formdata->automark; - } - if (!empty($formdata->preventsharedip)) { - $sess->preventsharedip = $formdata->preventsharedip; - } - if (!empty($formdata->preventsharediptime)) { - $sess->preventsharediptime = $formdata->preventsharediptime; - } } $sess->statusset = $formdata->statusset; diff --git a/renderer.php b/renderer.php index db4e228..d11caa9 100644 --- a/renderer.php +++ b/renderer.php @@ -1742,11 +1742,6 @@ class mod_attendance_renderer extends plugin_renderer_base { protected function render_attendance_preferences_data($prefdata) { $this->page->requires->js('/mod/attendance/module.js'); - $studentscanmark = false; - if (!empty(get_config('attendance', 'studentscanmark'))) { - $studentscanmark = true; - } - $table = new html_table(); $table->width = '100%'; $table->head = array('#', @@ -1754,15 +1749,15 @@ class mod_attendance_renderer extends plugin_renderer_base { get_string('description'), get_string('points', 'attendance')); $table->align = array('center', 'center', 'center', 'center', 'center', 'center'); - if ($studentscanmark) { - $table->head[] = get_string('studentavailability', 'attendance'). - $this->output->help_icon('studentavailability', 'attendance'); - $table->align[] = 'center'; - $table->head[] = get_string('setunmarked', 'attendance'). - $this->output->help_icon('setunmarked', 'attendance'); - $table->align[] = 'center'; - } + $table->head[] = get_string('studentavailability', 'attendance'). + $this->output->help_icon('studentavailability', 'attendance'); + $table->align[] = 'center'; + + $table->head[] = get_string('setunmarked', 'attendance'). + $this->output->help_icon('setunmarked', 'attendance'); + $table->align[] = 'center'; + $table->head[] = get_string('action'); $i = 1; @@ -1783,14 +1778,13 @@ class mod_attendance_renderer extends plugin_renderer_base { $cells[] = $this->construct_text_input('description['.$st->id.']', 30, 30, $st->description) . $emptydescription; $cells[] = $this->construct_text_input('grade['.$st->id.']', 4, 4, $st->grade); - if ($studentscanmark) { - $checked = ''; - if ($st->setunmarked) { - $checked = ' checked '; - } - $cells[] = $this->construct_text_input('studentavailability['.$st->id.']', 4, 5, $st->studentavailability); - $cells[] = ''; + $checked = ''; + if ($st->setunmarked) { + $checked = ' checked '; } + $cells[] = $this->construct_text_input('studentavailability['.$st->id.']', 4, 5, $st->studentavailability); + $cells[] = ''; + $cells[] = $this->construct_preferences_actions_icons($st, $prefdata); $table->data[$i] = new html_table_row($cells); @@ -1802,9 +1796,8 @@ class mod_attendance_renderer extends plugin_renderer_base { $table->data[$i][] = $this->construct_text_input('newacronym', 2, 2); $table->data[$i][] = $this->construct_text_input('newdescription', 30, 30); $table->data[$i][] = $this->construct_text_input('newgrade', 4, 4); - if ($studentscanmark) { - $table->data[$i][] = $this->construct_text_input('newstudentavailability', 4, 5); - } + $table->data[$i][] = $this->construct_text_input('newstudentavailability', 4, 5); + $table->data[$i][] = $this->construct_preferences_button(get_string('add', 'attendance'), mod_attendance_preferences_page_params::ACTION_ADD); diff --git a/update_form.php b/update_form.php index 56a3a53..ead2a65 100644 --- a/update_form.php +++ b/update_form.php @@ -128,20 +128,25 @@ class mod_attendance_update_form extends moodleform { } // Students can mark own attendance. - if (!empty(get_config('attendance', 'studentscanmark'))) { - $mform->addElement('header', 'headerstudentmarking', get_string('studentmarking', 'attendance'), true); - $mform->setExpanded('headerstudentmarking'); + $studentscanmark = get_config('attendance', 'studentscanmark'); + $mform->addElement('header', 'headerstudentmarking', get_string('studentmarking', 'attendance'), true); + $mform->setExpanded('headerstudentmarking'); + if (!empty($studentscanmark)) { $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance')); $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance'); + } else { + $mform->addElement('hidden', 'studentscanmark', '0'); + $mform->settype('studentscanmark', PARAM_INT); + } - $options2 = attendance_get_automarkoptions(); + $options2 = attendance_get_automarkoptions(); - $mform->addElement('select', 'automark', get_string('automark', 'attendance'), $options2); - $mform->setType('automark', PARAM_INT); - $mform->addHelpButton('automark', 'automark', 'attendance'); - $mform->hideif('automark', 'studentscanmark', 'notchecked'); + $mform->addElement('select', 'automark', get_string('automark', 'attendance'), $options2); + $mform->setType('automark', PARAM_INT); + $mform->addHelpButton('automark', 'automark', 'attendance'); + if (!empty($studentscanmark)) { $mform->addElement('text', 'studentpassword', get_string('studentpassword', 'attendance')); $mform->setType('studentpassword', PARAM_TEXT); $mform->addHelpButton('studentpassword', 'passwordgrp', 'attendance'); @@ -153,50 +158,35 @@ class mod_attendance_update_form extends moodleform { $mform->addElement('checkbox', 'autoassignstatus', '', get_string('autoassignstatus', 'attendance')); $mform->addHelpButton('autoassignstatus', 'autoassignstatus', 'attendance'); $mform->hideif('autoassignstatus', 'studentscanmark', 'notchecked'); - - $mgroup = array(); - $mgroup[] = & $mform->createElement('text', 'subnet', get_string('requiresubnet', 'attendance')); - $mform->setDefault('subnet', $this->_customdata['att']->subnet); - $mgroup[] = & $mform->createElement('checkbox', 'usedefaultsubnet', get_string('usedefaultsubnet', 'attendance')); - $mform->setDefault('usedefaultsubnet', 1); - $mform->setType('subnet', PARAM_TEXT); - - $mform->addGroup($mgroup, 'subnetgrp', get_string('requiresubnet', 'attendance'), array(' '), false); - $mform->setAdvanced('subnetgrp'); - $mform->addHelpButton('subnetgrp', 'requiresubnet', 'attendance'); - - $mform->hideif('subnetgrp', 'studentscanmark', 'notchecked'); - $mform->hideif('subnet', 'usedefaultsubnet', 'checked'); - - $mform->addElement('hidden', 'automarkcompleted', '0'); - $mform->settype('automarkcompleted', PARAM_INT); - - $mgroup3 = array(); - $options = attendance_get_sharedipoptions(); - $mgroup3[] = & $mform->createElement('select', 'preventsharedip', - get_string('preventsharedip', 'attendance'), $options); - $mgroup3[] = & $mform->createElement('text', 'preventsharediptime', - get_string('preventsharediptime', 'attendance'), '', 'test'); - $mform->addGroup($mgroup3, 'preventsharedgroup', - get_string('preventsharedip', 'attendance'), array(' '), false); - $mform->addHelpButton('preventsharedgroup', 'preventsharedip', 'attendance'); - $mform->setAdvanced('preventsharedgroup'); - $mform->setType('preventsharediptime', PARAM_INT); - $mform->hideif('preventsharedgroup', 'studentscanmark', 'notchecked'); - $mform->hideIf('preventsharediptime', 'preventsharedip', 'noteq', ATTENDANCE_SHAREDIP_MINUTES); - } else { - $mform->addElement('hidden', 'studentscanmark', '0'); - $mform->settype('studentscanmark', PARAM_INT); - $mform->addElement('hidden', 'subnet', '0'); - $mform->settype('subnet', PARAM_TEXT); - $mform->addElement('hidden', 'automark', '0'); - $mform->settype('automark', PARAM_INT); - $mform->addElement('hidden', 'automarkcompleted', '0'); - $mform->settype('automarkcompleted', PARAM_INT); - $mform->addElement('hidden', 'autoassignstatus', '0'); - $mform->setType('autoassignstatus', PARAM_INT); } + $mgroup = array(); + $mgroup[] = & $mform->createElement('text', 'subnet', get_string('requiresubnet', 'attendance')); + $mform->setDefault('subnet', $this->_customdata['att']->subnet); + $mgroup[] = & $mform->createElement('checkbox', 'usedefaultsubnet', get_string('usedefaultsubnet', 'attendance')); + $mform->setDefault('usedefaultsubnet', 1); + $mform->setType('subnet', PARAM_TEXT); + + $mform->addGroup($mgroup, 'subnetgrp', get_string('requiresubnet', 'attendance'), array(' '), false); + $mform->setAdvanced('subnetgrp'); + $mform->addHelpButton('subnetgrp', 'requiresubnet', 'attendance'); + $mform->hideif('subnet', 'usedefaultsubnet', 'checked'); + + $mform->addElement('hidden', 'automarkcompleted', '0'); + $mform->settype('automarkcompleted', PARAM_INT); + + $mgroup3 = array(); + $options = attendance_get_sharedipoptions(); + $mgroup3[] = & $mform->createElement('select', 'preventsharedip', + get_string('preventsharedip', 'attendance'), $options); + $mgroup3[] = & $mform->createElement('text', 'preventsharediptime', + get_string('preventsharediptime', 'attendance'), '', 'test'); + $mform->addGroup($mgroup3, 'preventsharedgroup', + get_string('preventsharedip', 'attendance'), array(' '), false); + $mform->addHelpButton('preventsharedgroup', 'preventsharedip', 'attendance'); + $mform->setAdvanced('preventsharedgroup'); + $mform->setType('preventsharediptime', PARAM_INT); + $mform->setDefaults($data); $this->add_action_buttons(true); }