From: samhemelryk Date: Thu, 17 Sep 2009 04:11:46 +0000 (+0000) Subject: mod-survey MDL-20262 Upgraded survey module in the following ways X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a5cb6242ae3836550e5e114b318d8a24044433cc;p=moodle.git mod-survey MDL-20262 Upgraded survey module in the following ways * Upgraded legacy code to use PAGE and OUTPUT methods * Added integration with the new navigation blocks * Fixed up several bugs within the download script --- diff --git a/lang/en_utf8/survey.php b/lang/en_utf8/survey.php index 2910df937a..e0c432d100 100644 --- a/lang/en_utf8/survey.php +++ b/lang/en_utf8/survey.php @@ -1,6 +1,27 @@ -. + +/** + * Language strings for the survey module as introduced in Moodle 1.7 beta + * + * @package mod-survey + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ $string['actual'] = 'Actual'; $string['actualclass'] = 'Class actual'; @@ -171,6 +192,7 @@ $string['done'] = 'Done'; $string['download'] = 'Download'; $string['downloadexcel'] = 'Download data as Excel spreadsheet'; $string['downloadinfo'] = 'You can download the complete raw data for this survey in a form suitable for analysis in Excel, SPSS or other package.'; +$string['downloadresults'] = 'Download results'; $string['downloadtext'] = 'Download data as a plain text file'; $string['editingasurvey'] = 'Editing a survey'; $string['guestsnotallowed'] = 'Guests are not allowed to submit surveys'; @@ -200,6 +222,7 @@ $string['questionsnotanswered'] = 'Some of the multiple choice questions have no $string['deleteallanswers'] = 'Delete all survey responses'; $string['deleteanalysis'] = 'Delete response analysis'; $string['report'] = 'Survey report'; +$string['responsereports'] = 'Response reports'; $string['responses'] = 'Responses'; $string['savednotes'] = 'Your notes were saved'; $string['scaleagree5'] = 'Strongly disagree,Somewhat disagree,Neither agree nor disagree,Somewhat agree,Strongly agree'; @@ -211,6 +234,7 @@ $string['summary'] = 'Summary'; $string['survey:download'] = 'Download responses'; $string['survey:participate'] = 'Respond to survey'; $string['survey:readresponses'] = 'View responses'; +$string['surveyadministration'] = 'Survey Administration'; $string['surveycompleted'] = 'You\'ve completed this survey. The graph below shows a summary of your results compared to the class averages.'; $string['surveygraph'] = 'Survey graph'; $string['surveyname'] = 'Survey name'; diff --git a/mod/survey/download.php b/mod/survey/download.php index cef7c12390..8f906e128e 100644 --- a/mod/survey/download.php +++ b/mod/survey/download.php @@ -1,308 +1,317 @@ -. + +/** + * This file is responsible for producing the downloadable versions of a survey + * module. + * + * @package mod-survey + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once ("../../config.php"); // Check that all the parameters have been provided. - $id = required_param('id', PARAM_INT); // Course Module ID - $type = optional_param('type', 'xls', PARAM_ALPHA); - $group = optional_param('group', 0, PARAM_INT); +$id = required_param('id', PARAM_INT); // Course Module ID +$type = optional_param('type', 'xls', PARAM_ALPHA); +$group = optional_param('group', 0, PARAM_INT); - if (! $cm = $DB->get_record("course_modules", array("id"=>$id))) { - print_error('invalidcoursemodule'); - } +if (! $cm = get_coursemodule_from_id('survey', $id)) { + print_error('invalidcoursemodule'); +} - if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { - print_error('coursemisconf'); - } +if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { + print_error('coursemisconf'); +} - $context = get_context_instance(CONTEXT_MODULE, $cm->id); +$context = get_context_instance(CONTEXT_MODULE, $cm->id); - require_login($course->id, false, $cm); - require_capability('mod/survey:download', $context) ; +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/survey/download.php', array('id'=>$id, 'type'=>$type, 'group'=>$group))); - if (! $survey = $DB->get_record("survey", array("id"=>$cm->instance))) { - print_error('invalidsurveyid', 'survey'); - } +require_login($course->id, false, $cm); +require_capability('mod/survey:download', $context) ; - add_to_log($course->id, "survey", "download", "download.php?id=$cm->id&type=$type", "$survey->id", $cm->id); +if (! $survey = $DB->get_record("survey", array("id"=>$cm->instance))) { + print_error('invalidsurveyid', 'survey'); +} -/// Check to see if groups are being used in this survey - - $groupmode = groups_get_activity_groupmode($cm); // Groups are being used +add_to_log($course->id, "survey", "download", $PAGE->url->out(), "$survey->id", $cm->id); - if ($groupmode and $group) { - $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $group, null, false); - } else { - $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', '', null, false); - $group = false; - } +/// Check to see if groups are being used in this survey -// Get all the questions and their proper order +$groupmode = groups_get_activity_groupmode($cm); // Groups are being used - $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions)); - $order = explode(",", $survey->questions); +if ($groupmode and $group) { + $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $group, null, false); +} else { + $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', '', null, false); + $group = false; +} - $virtualscales = false; - foreach ($order as $key => $qid) { // Do we have virtual scales? - $question = $questions[$qid]; - if ($question->type < 0) { - $virtualscales = true; - break; - } - } +// The order of the questions +$order = explode(",", $survey->questions); - $fullorderlist = array(); - foreach ($order as $key => $qid) { // build up list of actual questions - $question = $questions[$qid]; +// Get the actual questions from the database +$questions = $DB->get_records_list("survey_questions", "id", $order); - if ($question->multi) { - $addlist = $question->multi; - } else { - $addlist = $qid; - } +// Get an ordered array of questions +$orderedquestions = array(); - if ($virtualscales && ($question->type < 0)) { // only use them - $fullorderlist[] = $addlist; - - } else if (!$virtualscales && ($question->type >= 0)){ // ignore them - $fullorderlist[] = $addlist; - } +$virtualscales = false; +foreach ($order as $qid) { + $orderedquestions[$qid] = $questions[$qid]; + // Check if this question is using virtual scales + if (!$virtualscales && $questions[$qid]->type < 0) { + $virtualscales = true; } - - $fullquestions = $DB->get_records_list("survey_questions", "id", $fullorderlist); - -// Question type of multi-questions overrides the type of single questions - foreach ($order as $key => $qid) { - $question = $questions[$qid]; - - if ($question->multi) { - $subs = explode(",", $question->multi); - while (list ($skey, $sqid) = each ($subs)) { - $fullquestions["$sqid"]->type = $question->type; +} +$nestedorder = array(); +$preparray = array(); +foreach ($orderedquestions as $qid=>$question) { + $orderedquestions[$qid]->text = get_string($question->text, "survey"); + if (!empty($question->multi)) { + $actualqid = explode(",", $questions[$qid]->multi); + foreach ($actualqid as $subqid) { + if (!empty($orderedquestions[$subqid]->type)) { + $orderedquestions[$subqid]->type = $questions[$qid]->type; } } + } else { + $actualqid = array($qid); } - - $questions = $fullquestions; - -// Translate all the question texts - - foreach ($questions as $key => $question) { - $questions[$key]->text = get_string($question->text, "survey"); + if ($virtualscales && $questions[$qid]->type < 0) { + $nestedorder[$qid] = $actualqid; + } else if (!$virtualscales && $question->type >= 0) { + $nestedorder[$qid] = $actualqid; } - +} +$reversednestedorder = array(); +foreach ($nestedorder as $qid=>$subqidarray) { + foreach ($subqidarray as $subqui) { + $reversednestedorder[$subqui] = $qid; + } +} // Get and collate all the results in one big array +if (! $surveyanswers = $DB->get_records("survey_answers", array("survey"=>$survey->id), "time ASC")) { + print_error('cannotfindanswer', 'survey'); +} - if (! $aaa = $DB->get_records("survey_answers", array("survey"=>$survey->id), "time ASC")) { - print_error('cannotfindanswer', 'survey'); - } +$results = array(); - foreach ($aaa as $a) { - if (!$group or isset($users[$a->userid])) { - if (empty($results[$a->userid])) { // init new array - $results[$a->userid]["time"] = $a->time; - foreach ($fullorderlist as $qid) { - $results[$a->userid][$qid]["answer1"] = ""; - $results[$a->userid][$qid]["answer2"] = ""; - } - } - $results[$a->userid][$a->question]["answer1"] = $a->answer1; - $results[$a->userid][$a->question]["answer2"] = $a->answer2; +foreach ($surveyanswers as $surveyanswer) { + if (!$group || isset($users[$surveyanswer->userid])) { + $questionid = $reversednestedorder[$surveyanswer->question]; + if (!array_key_exists($surveyanswer->userid, $results)) { + $results[$surveyanswer->userid] = array('time'=>$surveyanswer->time); } + $results[$surveyanswer->userid][$questionid]['answer1'] = $surveyanswer->answer1; + $results[$surveyanswer->userid][$questionid]['answer2'] = $surveyanswer->answer2; } +} // Output the file as a valid ODS spreadsheet if required - if ($type == "ods") { - require_once("$CFG->libdir/odslib.class.php"); - - /// Calculate file name - $downloadfilename = clean_filename("$course->shortname ".strip_tags(format_string($survey->name,true))).'.ods'; - /// Creating a workbook - $workbook = new MoodleODSWorkbook("-"); - /// Sending HTTP headers - $workbook->send($downloadfilename); - /// Creating the first worksheet - $myxls =& $workbook->add_worksheet(substr(strip_tags(format_string($survey->name,true)), 0, 31)); - - $header = array("surveyid","surveyname","userid","firstname","lastname","email","idnumber","time", "notes"); - $col=0; - foreach ($header as $item) { - $myxls->write_string(0,$col++,$item); +if ($type == "ods") { + require_once("$CFG->libdir/odslib.class.php"); + +/// Calculate file name + $downloadfilename = clean_filename("$course->shortname ".strip_tags(format_string($survey->name,true))).'.ods'; +/// Creating a workbook + $workbook = new MoodleODSWorkbook("-"); +/// Sending HTTP headers + $workbook->send($downloadfilename); +/// Creating the first worksheet + $myxls =& $workbook->add_worksheet(substr(strip_tags(format_string($survey->name,true)), 0, 31)); + + $header = array("surveyid","surveyname","userid","firstname","lastname","email","idnumber","time", "notes"); + $col=0; + foreach ($header as $item) { + $myxls->write_string(0,$col++,$item); + } + foreach ($order as $key => $qid) { + $question = $orderedquestions[$qid]; + if ($question->type == "0" || $question->type == "1" || $question->type == "3" || $question->type == "-1") { + $myxls->write_string(0,$col++,"$question->text"); } - foreach ($order as $key => $qid) { - $question = $questions[$qid]; - if ($question->type == "0" || $question->type == "1" || $question->type == "3" || $question->type == "-1") { - $myxls->write_string(0,$col++,"$question->text"); - } - if ($question->type == "2" || $question->type == "3") { - $myxls->write_string(0,$col++,"$question->text (preferred)"); - } + if ($question->type == "2" || $question->type == "3") { + $myxls->write_string(0,$col++,"$question->text (preferred)"); } + } // $date = $workbook->addformat(); // $date->set_num_format('mmmm-d-yyyy h:mm:ss AM/PM'); // ?? adjust the settings to reflect the PHP format below - $row = 0; - foreach ($results as $user => $rest) { - $col = 0; - $row++; - if (! $u = $DB->get_record("user", array("id"=>$user))) { - print_error('invaliduserid'); - } - if ($n = $DB->get_record("survey_analysis", array("survey"=>$survey->id, "userid"=>$user))) { - $notes = $n->notes; - } else { - $notes = "No notes made"; - } - $myxls->write_string($row,$col++,$survey->id); - $myxls->write_string($row,$col++,strip_tags(format_text($survey->name,true))); - $myxls->write_string($row,$col++,$user); - $myxls->write_string($row,$col++,$u->firstname); - $myxls->write_string($row,$col++,$u->lastname); - $myxls->write_string($row,$col++,$u->email); - $myxls->write_string($row,$col++,$u->idnumber); - $myxls->write_string($row,$col++, userdate($results[$user]["time"], "%d-%b-%Y %I:%M:%S %p") ); -// $myxls->write_number($row,$col++,$results[$user]["time"],$date); - $myxls->write_string($row,$col++,$notes); - - foreach ($order as $key => $qid) { - $question = $questions[$qid]; - if ($question->type == "0" || $question->type == "1" || $question->type == "3" || $question->type == "-1") { - $myxls->write_string($row,$col++, $results[$user][$qid]["answer1"] ); - } - if ($question->type == "2" || $question->type == "3") { - $myxls->write_string($row, $col++, $results[$user][$qid]["answer2"] ); - } - } + $row = 0; + foreach ($results as $user => $rest) { + $col = 0; + $row++; + if (! $u = $DB->get_record("user", array("id"=>$user))) { + print_error('invaliduserid'); } - $workbook->close(); - - exit; - } - -// Output the file as a valid Excel spreadsheet if required - - if ($type == "xls") { - require_once("$CFG->libdir/excellib.class.php"); - - /// Calculate file name - $downloadfilename = clean_filename("$course->shortname ".strip_tags(format_string($survey->name,true))).'.xls'; - /// Creating a workbook - $workbook = new MoodleExcelWorkbook("-"); - /// Sending HTTP headers - $workbook->send($downloadfilename); - /// Creating the first worksheet - $myxls =& $workbook->add_worksheet(substr(strip_tags(format_string($survey->name,true)), 0, 31)); - - $header = array("surveyid","surveyname","userid","firstname","lastname","email","idnumber","time", "notes"); - $col=0; - foreach ($header as $item) { - $myxls->write_string(0,$col++,$item); + if ($n = $DB->get_record("survey_analysis", array("survey"=>$survey->id, "userid"=>$user))) { + $notes = $n->notes; + } else { + $notes = "No notes made"; } + $myxls->write_string($row,$col++,$survey->id); + $myxls->write_string($row,$col++,strip_tags(format_text($survey->name,true))); + $myxls->write_string($row,$col++,$user); + $myxls->write_string($row,$col++,$u->firstname); + $myxls->write_string($row,$col++,$u->lastname); + $myxls->write_string($row,$col++,$u->email); + $myxls->write_string($row,$col++,$u->idnumber); + $myxls->write_string($row,$col++, userdate($results[$user]["time"], "%d-%b-%Y %I:%M:%S %p") ); +// $myxls->write_number($row,$col++,$results[$user]["time"],$date); + $myxls->write_string($row,$col++,$notes); + foreach ($order as $key => $qid) { - $question = $questions[$qid]; + $question = $orderedquestions[$qid]; if ($question->type == "0" || $question->type == "1" || $question->type == "3" || $question->type == "-1") { - $myxls->write_string(0,$col++,"$question->text"); + $myxls->write_string($row,$col++, $results[$user][$qid]["answer1"] ); } if ($question->type == "2" || $question->type == "3") { - $myxls->write_string(0,$col++,"$question->text (preferred)"); + $myxls->write_string($row, $col++, $results[$user][$qid]["answer2"] ); } } - -// $date = $workbook->addformat(); -// $date->set_num_format('mmmm-d-yyyy h:mm:ss AM/PM'); // ?? adjust the settings to reflect the PHP format below - - $row = 0; - foreach ($results as $user => $rest) { - $col = 0; - $row++; - if (! $u = $DB->get_record("user", array("id"=>$user))) { - print_error('invaliduserid'); - } - if ($n = $DB->get_record("survey_analysis", array("survey"=>$survey->id, "userid"=>$user))) { - $notes = $n->notes; - } else { - $notes = "No notes made"; - } - $myxls->write_string($row,$col++,$survey->id); - $myxls->write_string($row,$col++,strip_tags(format_text($survey->name,true))); - $myxls->write_string($row,$col++,$user); - $myxls->write_string($row,$col++,$u->firstname); - $myxls->write_string($row,$col++,$u->lastname); - $myxls->write_string($row,$col++,$u->email); - $myxls->write_string($row,$col++,$u->idnumber); - $myxls->write_string($row,$col++, userdate($results[$user]["time"], "%d-%b-%Y %I:%M:%S %p") ); -// $myxls->write_number($row,$col++,$results[$user]["time"],$date); - $myxls->write_string($row,$col++,$notes); - - foreach ($order as $key => $qid) { - $question = $questions[$qid]; - if ($question->type == "0" || $question->type == "1" || $question->type == "3" || $question->type == "-1") { - $myxls->write_string($row,$col++, $results[$user][$qid]["answer1"] ); - } - if ($question->type == "2" || $question->type == "3") { - $myxls->write_string($row, $col++, $results[$user][$qid]["answer2"] ); - } - } - } - $workbook->close(); - - exit; } + $workbook->close(); -// Otherwise, return the text file. - -// Print header to force download - - header("Content-Type: application/download\n"); - - $downloadfilename = clean_filename("$course->shortname ".strip_tags(format_string($survey->name,true))); - header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\""); + exit; +} -// Print names of all the fields +// Output the file as a valid Excel spreadsheet if required - echo "surveyid surveyname userid firstname lastname email idnumber time "; +if ($type == "xls") { + require_once("$CFG->libdir/excellib.class.php"); + +/// Calculate file name + $downloadfilename = clean_filename("$course->shortname ".strip_tags(format_string($survey->name,true))).'.xls'; +/// Creating a workbook + $workbook = new MoodleExcelWorkbook("-"); +/// Sending HTTP headers + $workbook->send($downloadfilename); +/// Creating the first worksheet + $myxls =& $workbook->add_worksheet(substr(strip_tags(format_string($survey->name,true)), 0, 31)); + + $header = array("surveyid","surveyname","userid","firstname","lastname","email","idnumber","time", "notes"); + $col=0; + foreach ($header as $item) { + $myxls->write_string(0,$col++,$item); + } foreach ($order as $key => $qid) { - $question = $questions[$qid]; + $question = $orderedquestions[$qid]; if ($question->type == "0" || $question->type == "1" || $question->type == "3" || $question->type == "-1") { - echo "$question->text "; + $myxls->write_string(0,$col++,"$question->text"); } if ($question->type == "2" || $question->type == "3") { - echo "$question->text (preferred) "; + $myxls->write_string(0,$col++,"$question->text (preferred)"); } } - echo "\n"; -// Print all the lines of data. +// $date = $workbook->addformat(); +// $date->set_num_format('mmmm-d-yyyy h:mm:ss AM/PM'); // ?? adjust the settings to reflect the PHP format below + $row = 0; foreach ($results as $user => $rest) { + $col = 0; + $row++; if (! $u = $DB->get_record("user", array("id"=>$user))) { print_error('invaliduserid'); } - echo $survey->id."\t"; - echo strip_tags(format_string($survey->name,true))."\t"; - echo $user."\t"; - echo $u->firstname."\t"; - echo $u->lastname."\t"; - echo $u->email."\t"; - echo $u->idnumber."\t"; - echo userdate($results[$user]["time"], "%d-%b-%Y %I:%M:%S %p")."\t"; + if ($n = $DB->get_record("survey_analysis", array("survey"=>$survey->id, "userid"=>$user))) { + $notes = $n->notes; + } else { + $notes = "No notes made"; + } + $myxls->write_string($row,$col++,$survey->id); + $myxls->write_string($row,$col++,strip_tags(format_text($survey->name,true))); + $myxls->write_string($row,$col++,$user); + $myxls->write_string($row,$col++,$u->firstname); + $myxls->write_string($row,$col++,$u->lastname); + $myxls->write_string($row,$col++,$u->email); + $myxls->write_string($row,$col++,$u->idnumber); + $myxls->write_string($row,$col++, userdate($results[$user]["time"], "%d-%b-%Y %I:%M:%S %p") ); +// $myxls->write_number($row,$col++,$results[$user]["time"],$date); + $myxls->write_string($row,$col++,$notes); foreach ($order as $key => $qid) { - $question = $questions[$qid]; + $question = $orderedquestions[$qid]; if ($question->type == "0" || $question->type == "1" || $question->type == "3" || $question->type == "-1") { - echo $results[$user][$qid]["answer1"]." "; + $myxls->write_string($row,$col++, $results[$user][$qid]["answer1"] ); } if ($question->type == "2" || $question->type == "3") { - echo $results[$user][$qid]["answer2"]." "; + $myxls->write_string($row, $col++, $results[$user][$qid]["answer2"] ); } } - echo "\n"; } + $workbook->close(); + exit; +} +// Otherwise, return the text file. + +// Print header to force download + +header("Content-Type: application/download\n"); + +$downloadfilename = clean_filename("$course->shortname ".strip_tags(format_string($survey->name,true))); +header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\""); + +// Print names of all the fields + +echo "surveyid surveyname userid firstname lastname email idnumber time "; +foreach ($orderedquestions as $key => $question) { + if ($question->type == "0" || $question->type == "1" || $question->type == "3" || $question->type == "-1") { + echo "$question->text "; + } + if ($question->type == "2" || $question->type == "3") { + echo "$question->text (preferred) "; + } +} +echo "\n"; + +// Print all the lines of data. +foreach ($results as $user => $rest) { + if (! $u = $DB->get_record("user", array("id"=>$user))) { + print_error('invaliduserid'); + } + echo $survey->id."\t"; + echo strip_tags(format_string($survey->name,true))."\t"; + echo $user."\t"; + echo $u->firstname."\t"; + echo $u->lastname."\t"; + echo $u->email."\t"; + echo $u->idnumber."\t"; + echo userdate($results[$user]["time"], "%d-%b-%Y %I:%M:%S %p")."\t"; + + foreach ($order as $key => $qid) { + $question = $orderedquestions[$qid]; + if ($question->type == "0" || $question->type == "1" || $question->type == "3" || $question->type == "-1") { + echo $results[$user][$qid]["answer1"]." "; + } + if ($question->type == "2" || $question->type == "3") { + echo $results[$user][$qid]["answer2"]." "; + } + } + echo "\n"; +} -?> +exit; \ No newline at end of file diff --git a/mod/survey/lib.php b/mod/survey/lib.php index 55515a62f7..137ba095dd 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -791,3 +791,85 @@ function survey_supports($feature) { default: return null; } } + +/** + * This fucntion extends the global navigaiton for the site. + * It is important to note that you should not rely on PAGE objects within this + * body of code as there is no guarantee that during an AJAX request they are + * available + * + * @param navigation_node $navigation The quiz node within the global navigation + * @param stdClass $course The course object returned from the DB + * @param stdClass $module The module object returned from the DB + * @param stdClass $cm The course module isntance returned from the DB + */ +function survey_extend_navigation($navigation, $course, $module, $cm) { + /** + * This is currently just a stub so that it can be easily expanded upon. + * When expanding just remove this comment and the line below and then add + * you content. + */ + $navigation->nodetype = navigation_node::NODETYPE_LEAF; +} + +/** + * This function extends the settings navigation block for the site. + * + * It is safe to rely on PAGE here as we will only ever be within the module + * context when this is called + * + * @param navigation_node $settings + * @param stdClass $module + */ +function survey_extend_settings_navigation($settings, $module) { + global $PAGE, $CFG, $DB, $USER, $OUTPUT; + + $survey = $DB->get_record('quiz', array('id'=>$PAGE->cm->instance)); + $surveynavkey = $settings->add(get_string('surveyadministration', 'survey')); + $surveynav = $settings->get($surveynavkey); + $surveynav->forceopen = true; + + $strreport = get_string("report", "survey"); + $strsurvey = get_string("modulename", "survey"); + $strsurveys = get_string("modulenameplural", "survey"); + $strsummary = get_string("summary", "survey"); + $strscales = get_string("scales", "survey"); + $strquestion = get_string("question", "survey"); + $strquestions = get_string("questions", "survey"); + $strdownload = get_string("download", "survey"); + $strallscales = get_string("allscales", "survey"); + $strallquestions = get_string("allquestions", "survey"); + $strselectedquestions = get_string("selectedquestions", "survey"); + $strseemoredetail = get_string("seemoredetail", "survey"); + $strnotes = get_string("notes", "survey"); + + if (has_capability('mod/survey:readresponses', $PAGE->cm->context)) { + $key = $surveynav->add(get_string("responsereports", "survey")); + + $url = new moodle_url($CFG->wwwroot.'/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'summary')); + $surveynav->get($key)->add(get_string("summary", "survey"), $url); + + $url = new moodle_url($CFG->wwwroot.'/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'scales')); + $surveynav->get($key)->add(get_string("scales", "survey"), $url); + + $url = new moodle_url($CFG->wwwroot.'/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'questions')); + $surveynav->get($key)->add(get_string("question", "survey"), $url); + + $url = new moodle_url($CFG->wwwroot.'/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'students')); + $surveynav->get($key)->add(get_string('participants'), $url); + + if (has_capability('mod/survey:download', $PAGE->cm->context)) { + $url = new moodle_url($CFG->wwwroot.'/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'download')); + $surveynav->add(get_string('downloadresults', 'survey'), $url); + } + } + + if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) { + $url = new moodle_url($CFG->wwwroot.'/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey())); + $surveynav->add(get_string('updatethis', '', get_string('modulename', 'quiz')), $url); + } + + if (count($surveynav->children)<1) { + $settings->remove_child($surveynavkey); + } +} \ No newline at end of file diff --git a/mod/survey/report.php b/mod/survey/report.php index 528c830138..9a31a9862d 100644 --- a/mod/survey/report.php +++ b/mod/survey/report.php @@ -1,4 +1,27 @@ -. + +/** + * This file is responsible for producing the survey reports + * + * @package mod-survey + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ require_once("../../config.php"); require_once("lib.php"); @@ -23,6 +46,21 @@ print_error('coursemisconf'); } + $url = new moodle_url($CFG->wwwroot.'/mod/survey/report.php', array('id'=>$id)); + if ($action !== '') { + $url->param('action', $action); + } + if ($qid !== 0) { + $url->param('qid', $qid); + } + if ($student !== 0) { + $url->param('student', $student); + } + if ($notes !== '') { + $url->param('notes', $notes); + } + $PAGE->set_url($url); + require_login($course->id, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); @@ -56,7 +94,28 @@ add_to_log($course->id, "survey", "view report", "report.php?id=$cm->id", "$survey->id", $cm->id); - $PAGE->navbar->add($strreport); + switch ($action) { + case 'download': + $PAGE->navbar->add(get_string('downloadresults', 'survey')); + break; + case 'summary': + case 'scales': + case 'questions': + $PAGE->navbar->add($strreport); + $PAGE->navbar->add(${'str'.$action}); + break; + case 'students': + $PAGE->navbar->add($strreport); + $PAGE->navbar->add(get_string('participants')); + break; + case '': + $PAGE->navbar->add($strreport); + $PAGE->navbar->add($strsummary); + break; + default: + $PAGE->navbar->add($strreport); + break; + } $PAGE->set_title("$course->shortname: ".format_string($survey->name)); $PAGE->set_heading($course->fullname); diff --git a/mod/survey/save.php b/mod/survey/save.php index 88b4763572..c122dbe920 100644 --- a/mod/survey/save.php +++ b/mod/survey/save.php @@ -1,4 +1,28 @@ -. + +/** + * This file is responsible for saving the results of a users survey and displaying + * the final message. + * + * @package mod-survey + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ require_once('../../config.php'); require_once('lib.php'); @@ -20,6 +44,7 @@ print_error('coursemisconf'); } + $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/survey/save.php', array('id'=>$id))); require_login($course->id, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); diff --git a/mod/survey/view.php b/mod/survey/view.php index 76bbb0958c..d5e9384cd5 100644 --- a/mod/survey/view.php +++ b/mod/survey/view.php @@ -1,4 +1,27 @@ -. + +/** + * This file is responsible for displaying the survey + * + * @package mod-survey + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ require_once("../../config.php"); require_once("lib.php"); @@ -13,6 +36,7 @@ print_error('coursemisconf'); } + $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/survey/view.php', array('id'=>$id))); require_login($course->id, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id);