// named params array $approvecap = has_capability('mod/data:approve', $context); if ($approve && confirm_sesskey() && $approvecap) { if ($approverecord = $DB->get_record('data_records', array('id' => $approve))) { // Need to check this is valid if ($approverecord->dataid == $data->id) { // Must be from this database $newrecord = new stdClass(); $newrecord->id = $approverecord->id; $newrecord->approved = 1; $DB->update_record('data_records', $newrecord); echo $OUTPUT->notification(get_string('recordapproved', 'data'), 'notifysuccess'); } } } $numentries = data_numentries($data); /// Check the number of entries required against the number of entries already made (doesn't apply to teachers) if ($data->requiredentries > 0 && $numentries < $data->requiredentries && !has_capability('mod/data:manageentries', $context)) { $data->entriesleft = $data->requiredentries - $numentries; $strentrieslefttoadd = get_string('entrieslefttoadd', 'data', $data); echo $OUTPUT->notification($strentrieslefttoadd); } /// Check the number of entries required before to view other participant's entries against the number of entries already made (doesn't apply to teachers) $requiredentries_allowed = true; if ($data->requiredentriestoview > 0 && $numentries < $data->requiredentriestoview && !has_capability('mod/data:manageentries', $context)) { $data->entrieslefttoview = $data->requiredentriestoview - $numentries; $strentrieslefttoaddtoview = get_string('entrieslefttoaddtoview', 'data', $data); echo $OUTPUT->notification($strentrieslefttoaddtoview); $requiredentries_allowed = false; } /// setup group and approve restrictions
$replacements[] = $field->display_add_field($rid); $patterns[] = "[[" . $field->field->name . "#id]]"; $replacements[] = 'field_' . $field->field->id; } $newtext = str_ireplace($patterns, $replacements, $data->{$mode}); } else { //if the add template is not yet defined, print the default form! echo data_generate_default_template($data, 'addtemplate', $rid, true, false); $newtext = ''; } echo $newtext; echo '<div class="mdl-align"><input type="submit" name="saveandview" value="' . get_string('saveandview', 'data') . '" />'; if ($rid) { echo ' <input type="submit" name="cancel" value="' . get_string('cancel') . '" onclick="javascript:history.go(-1)" />'; } else { if (!$data->maxentries || has_capability('mod/data:manageentries', $context) || data_numentries($data) < $data->maxentries - 1) { echo ' <input type="submit" value="' . get_string('saveandadd', 'data') . '" />'; } } echo '</div>'; echo $OUTPUT->box_end(); echo '</div></form>'; /// Finish the page // Print the stuff that need to come after the form fields. if (!($fields = $DB->get_records('data_fields', array('dataid' => $data->id)))) { print_error('nofieldindatabase', 'data'); } foreach ($fields as $eachfield) { $field = data_get_field($eachfield, $data); $field->print_after_form(); }
$replacements[] = 'field_'.$field->field->id; } $newtext = str_ireplace($patterns, $replacements, $data->{$mode}); } else { //if the add template is not yet defined, print the default form! echo data_generate_default_template($data, 'addtemplate', $rid, true, false); $newtext = ''; } echo $newtext; echo '<div class="mdl-align"><input type="submit" name="saveandview" value="'.get_string('saveandview','data').'" />'; if ($rid) { echo ' <input type="submit" name="cancel" value="'.get_string('cancel').'" onclick="javascript:history.go(-1)" />'; } else { if ( (!$data->maxentries) || (data_numentries($data)<($data->maxentries-1)) ) { echo ' <input type="submit" value="'.get_string('saveandadd','data').'" />'; } } echo '</div>'; echo $OUTPUT->box_end(); echo '</div></form>'; /// Finish the page // Print the stuff that need to come after the form fields. if (!$fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) { print_error('nofieldindatabase', 'data'); } foreach ($fields as $eachfield) {
function data_extend_navigation($navigation, $course, $module, $cm) { global $CFG, $OUTPUT, $USER, $DB; $rid = optional_param('rid', 0, PARAM_INT); $data = $DB->get_record('data', array('id'=>$cm->instance)); $currentgroup = groups_get_activity_group($cm); $groupmode = groups_get_activity_groupmode($cm); $numentries = data_numentries($data); /// Check the number of entries required against the number of entries already made (doesn't apply to teachers) if ($data->requiredentries > 0 && $numentries < $data->requiredentries && !has_capability('mod/data:manageentries', get_context_instance(CONTEXT_MODULE, $cm->id))) { $data->entriesleft = $data->requiredentries - $numentries; $entriesnode = $navigation->add(get_string('entrieslefttoadd', 'data', $data)); $entriesnode->add_class('note'); } $navigation->add(get_string('list', 'data'), new moodle_url('/mod/data/view.php', array('d'=>$cm->instance))); if (!empty($rid)) { $navigation->add(get_string('single', 'data'), new moodle_url('/mod/data/view.php', array('d'=>$cm->instance, 'rid'=>$rid))); } else { $navigation->add(get_string('single', 'data'), new moodle_url('/mod/data/view.php', array('d'=>$cm->instance, 'mode'=>'single'))); } $navigation->add(get_string('search', 'data'), new moodle_url('/mod/data/view.php', array('d'=>$cm->instance, 'mode'=>'search'))); }
$replacements[] = 'field_'.$field->field->id; } $newtext = str_ireplace($patterns, $replacements, $data->{$mode}); } else { //if the add template is not yet defined, print the default form! echo data_generate_default_template($data, 'addtemplate', $rid, true, false); $newtext = ''; } echo $newtext; echo '<div class="mdl-align"><input type="submit" name="saveandview" value="'.get_string('saveandview','data').'" />'; if ($rid) { echo ' <input type="submit" name="cancel" value="'.get_string('cancel').'" onclick="javascript:history.go(-1)" />'; } else { if ((!$data->maxentries) || has_capability('mod/data:manageentries', $context) || (data_numentries($data) < ($data->maxentries - 1))) { echo ' <input type="submit" value="'.get_string('saveandadd','data').'" />'; } } echo '</div>'; echo $OUTPUT->box_end(); echo '</div></form>'; /// Finish the page // Print the stuff that need to come after the form fields. if (!$fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) { print_error('nofieldindatabase', 'data'); } foreach ($fields as $eachfield) {
function data_atmaxentries($data) { if (!$data->maxentries) { return false; } else { return data_numentries($data) >= $data->maxentries; } }
if ($approve && confirm_sesskey() && has_capability('mod/data:approve', $context)) { if ($approverecord = get_record('data_records', 'id', $approve)) { // Need to check this is valid if ($approverecord->dataid == $data->id) { // Must be from this database $newrecord->id = $approverecord->id; $newrecord->approved = 1; if (update_record('data_records', $newrecord)) { notify(get_string('recordapproved', 'data'), 'notifysuccess'); } } } } // If not teacher, check whether user has sufficient records to view if (!has_capability('mod/data:managetemplates', $context) and data_numentries($data) < $data->requiredentriestoview) { notify($data->requiredentriestoview - data_numentries($data) . ' ' . get_string('insufficiententries', 'data')); echo '</td></tr></table>'; print_footer($course); exit; } /// We need to examine the whole dataset to produce the correct paging if (!has_capability('mod/data:managetemplates', $context) && $data->approval) { if (isloggedin()) { $approveselect = ' AND (r.approved=1 OR r.userid=' . $USER->id . ') '; } else { $approveselect = ' AND r.approved=1 '; } } else { $approveselect = ' '; } if ($currentgroup) {
} foreach ($generalnotifications as $notification) { echo $OUTPUT->notification($notification); } echo $newtext; echo '<div class="mdl-align m-t-1"><input type="submit" class="btn btn-primary" name="saveandview" ' . 'value="' . get_string('saveandview', 'data') . '" />'; if ($rid) { echo ' <input type="submit" class="btn btn-primary" name="cancel" ' . 'value="' . get_string('cancel') . '" onclick="javascript:history.go(-1)" />'; } else { if ((!$data->maxentries) || has_capability('mod/data:manageentries', $context) || (data_numentries($data) < ($data->maxentries - 1))) { echo ' <input type="submit" class="btn btn-primary" name="saveandadd" ' . 'value="' . get_string('saveandadd', 'data') . '" />'; } } echo '</div>'; echo $OUTPUT->box_end(); echo '</div></form>'; /// Finish the page // Print the stuff that need to come after the form fields. if (!$fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) { print_error('nofieldindatabase', 'data'); }
$replacements[] = $field->display_add_field($rid); $patterns[] = "[[" . $field->field->name . "#id]]"; $replacements[] = 'field_' . $field->field->id; } $newtext = str_ireplace($patterns, $replacements, $data->{$mode}); } else { //if the add template is not yet defined, print the default form! echo data_generate_default_template($data, 'addtemplate', $rid, true, false); $newtext = ''; } echo $newtext; echo '<div style="text-align:center"><input type="submit" name="saveandview" value="' . get_string('saveandview', 'data') . '" />'; if ($rid) { echo ' <input type="submit" name="cancel" value="' . get_string('cancel') . '" onclick="javascript:history.go(-1)" />'; } else { if (!$data->maxentries || data_numentries($data) < $data->maxentries - 1) { echo ' <input type="submit" value="' . get_string('saveandadd', 'data') . '" />'; } } echo '</div>'; print_simple_box_end(); echo '</div></form>'; /// Upload records section. Only for teachers and the admin. if (has_capability('mod/data:manageentries', $context)) { if ($import) { print_simple_box_start('center', '80%'); print_heading(get_string('uploadrecords', 'data'), '', 3); $maxuploadsize = get_max_upload_file_size(); echo '<div style="text-align:center">'; echo '<form enctype="multipart/form-data" action="import.php" method="post">'; echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . $maxuploadsize . '" />';