. /** * prints the form so an anonymous user can fill out the feedback on the mainsite * * @author Andreas Grabs * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package feedback */ require_once("../../config.php"); require_once("lib.php"); feedback_init_feedback_session(); $id = required_param('id', PARAM_INT); $completedid = optional_param('completedid', false, PARAM_INT); $preservevalues = optional_param('preservevalues', 0, PARAM_INT); $courseid = optional_param('courseid', false, PARAM_INT); $gopage = optional_param('gopage', -1, PARAM_INT); $lastpage = optional_param('lastpage', false, PARAM_INT); $startitempos = optional_param('startitempos', 0, PARAM_INT); $lastitempos = optional_param('lastitempos', 0, PARAM_INT); $url = new moodle_url('/mod/feedback/complete_guest.php', array('id'=>$id)); if ($completedid !== false) { $url->param('completedid', $completedid); } if ($preservevalues !== 0) { $url->param('preservevalues', $preservevalues); } if ($courseid !== false) { $url->param('courseid', $courseid); } if ($gopage !== -1) { $url->param('gopage', $gopage); } if ($lastpage !== false) { $url->param('lastpage', $lastpage); } if ($startitempos !== 0) { $url->param('startitempos', $startitempos); } if ($lastitempos !== 0) { $url->param('lastitempos', $lastitempos); } $PAGE->set_url($url); $highlightrequired = false; if (($formdata = data_submitted()) AND !confirm_sesskey()) { print_error('invalidsesskey'); } //if the use hit enter into a textfield so the form should not submit if (isset($formdata->sesskey) AND !isset($formdata->savevalues) AND !isset($formdata->gonextpage) AND !isset($formdata->gopreviouspage)) { $gopage = (int) $formdata->lastpage; } if (isset($formdata->savevalues)) { $savevalues = true; } else { $savevalues = false; } if ($gopage < 0 AND !$savevalues) { if (isset($formdata->gonextpage)) { $gopage = $lastpage + 1; $gonextpage = true; $gopreviouspage = false; } else if (isset($formdata->gopreviouspage)) { $gopage = $lastpage - 1; $gonextpage = false; $gopreviouspage = true; } else { print_error('parameters_missing', 'feedback'); } } else { $gonextpage = $gopreviouspage = false; } if (! $cm = get_coursemodule_from_id('feedback', $id)) { print_error('invalidcoursemodule'); } if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { print_error('coursemisconf'); } if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { print_error('invalidcoursemodule'); } if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) { print_error('badcontext'); } $feedback_complete_cap = false; if (isset($CFG->feedback_allowfullanonymous) AND $CFG->feedback_allowfullanonymous AND $course->id == SITEID AND (!$courseid OR $courseid == SITEID) AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) { $feedback_complete_cap = true; } //check whether the feedback is anonymous if (isset($CFG->feedback_allowfullanonymous) AND $CFG->feedback_allowfullanonymous AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES AND $course->id == SITEID ) { $feedback_complete_cap = true; } if ($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) { print_error('feedback_is_not_for_anonymous', 'feedback'); } //check whether the user has a session // there used to be a sesskey test - this could not work - sorry //check whether the feedback is located and! started from the mainsite if ($course->id == SITEID AND !$courseid) { $courseid = SITEID; } require_course_login($course); if ($courseid AND $courseid != SITEID) { $course2 = $DB->get_record('course', array('id'=>$courseid)); require_course_login($course2); //this overwrites the object $course :-( $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround } if (!$feedback_complete_cap) { print_error('error'); } /// Print the page header $strfeedbacks = get_string("modulenameplural", "feedback"); $strfeedback = get_string("modulename", "feedback"); $PAGE->set_cm($cm, $course); // set's up global $COURSE $PAGE->set_pagelayout('incourse'); $urlparams = array('id'=>$course->id); $PAGE->navbar->add($strfeedbacks, new moodle_url('/mod/feedback/index.php', $urlparams)); $PAGE->navbar->add(format_string($feedback->name)); $PAGE->set_heading(format_string($course->fullname)); $PAGE->set_title(format_string($feedback->name)); echo $OUTPUT->header(); //ishidden check. //hidden feedbacks except feedbacks on mainsite are only accessible with related capabilities if ((empty($cm->visible) AND !has_capability('moodle/course:viewhiddenactivities', $context)) AND $course->id != SITEID) { notice(get_string("activityiscurrentlyhidden")); } //check, if the feedback is open (timeopen, timeclose) $checktime = time(); $feedback_is_closed = ($feedback->timeopen > $checktime) OR ($feedback->timeclose < $checktime AND $feedback->timeclose > 0); if ($feedback_is_closed) { echo $OUTPUT->box_start('generalbox boxaligncenter'); echo '
'; echo get_string('entries_saved', 'feedback'); echo '
'; if ( intval($feedback->publish_stats) == 1) { echo ''; echo get_string('completed_feedbacks', 'feedback').''; echo '
'; } } if ($feedback->site_after_submit) { $url = feedback_encode_target_url($feedback->site_after_submit); } else { if ($courseid) { if ($courseid == SITEID) { $url = $CFG->wwwroot; } else { $url = $CFG->wwwroot.'/course/view.php?id='.$courseid; } } else { if ($course->id == SITEID) { $url = $CFG->wwwroot; } else { $url = $CFG->wwwroot.'/course/view.php?id='.$course->id; } } } echo $OUTPUT->continue_button($url); } else { if (isset($savereturn) && $savereturn == 'failed') { echo $OUTPUT->box_start('mform error'); echo get_string('saving_failed', 'feedback'); echo $OUTPUT->box_end(); } if (isset($savereturn) && $savereturn == 'missing') { echo $OUTPUT->box_start('mform error'); echo get_string('saving_failed_because_missing_or_false_values', 'feedback'); echo $OUTPUT->box_end(); } //print the items if (is_array($feedbackitems)) { echo $OUTPUT->box_start('feedback_form'); echo ''; echo $OUTPUT->box_end(); echo $OUTPUT->box_start('feedback_complete_cancel'); if ($courseid) { $action = 'action="'.$CFG->wwwroot.'/course/view.php?id='.$courseid.'"'; } else { if ($course->id == SITEID) { $action = 'action="'.$CFG->wwwroot.'"'; } else { $action = 'action="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'"'; } } echo ''; echo $OUTPUT->box_end(); $SESSION->feedback->is_started = true; } } } else { echo $OUTPUT->box_start('generalbox boxaligncenter'); echo '