MDL-29804 - Clean up Feedback modules coding style

This commit is contained in:
Andreas Grabs 2011-10-28 00:30:42 +02:00
parent 38e9a1cc79
commit 9c5bc7a580
67 changed files with 5893 additions and 4105 deletions

View File

@ -135,7 +135,8 @@ Now it only runs on Moodle 1.8 or later
- roles are full implemented - roles are full implemented
- now radiobuttons and checkboxes can be aligned horizontally or vertically - now radiobuttons and checkboxes can be aligned horizontally or vertically
- now you can insert pagebreakes - now you can insert pagebreakes
- a feedback what is switch to the next page is saved temporary. the user can cancel the completion and later continue at the last filled page. - a feedback what is switch to the next page is saved temporary.
the user can cancel the completion and later continue at the last filled page.
- now you can ex-/import feedbacks into/from a xml-file - now you can ex-/import feedbacks into/from a xml-file
- course-reseting is supported - course-reseting is supported

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* shows an analysed view of feedback * shows an analysed view of feedback
@ -11,7 +25,6 @@
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
// $SESSION->feedback->current_tab = 'analysis';
$current_tab = 'analysis'; $current_tab = 'analysis';
$id = required_param('id', PARAM_INT); //the POST dominated the GET $id = required_param('id', PARAM_INT); //the POST dominated the GET
@ -39,23 +52,23 @@ if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext'); print_error('badcontext');
} }
if($course->id == SITEID) { if ($course->id == SITEID) {
require_login($course->id, true); require_login($course->id, true);
}else{ } else {
require_login($course->id, true, $cm); require_login($course->id, true, $cm);
} }
//check whether the given courseid exists //check whether the given courseid exists
if($courseid AND $courseid != SITEID) { if ($courseid AND $courseid != SITEID) {
if($course2 = $DB->get_record('course', array('id'=>$courseid))){ if ($course2 = $DB->get_record('course', array('id'=>$courseid))) {
require_course_login($course2); //this overwrites the object $course :-( require_course_login($course2); //this overwrites the object $course :-(
$course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
}else { } else {
print_error('invalidcourseid'); print_error('invalidcourseid');
} }
} }
if( !( ((intval($feedback->publish_stats) == 1) AND if ( !( ((intval($feedback->publish_stats) == 1) AND
has_capability('mod/feedback:viewanalysepage', $context)) OR has_capability('mod/feedback:viewanalysepage', $context)) OR
has_capability('mod/feedback:viewreports', $context))) { has_capability('mod/feedback:viewreports', $context))) {
print_error('error'); print_error('error');
@ -65,30 +78,29 @@ if( !( ((intval($feedback->publish_stats) == 1) AND
$strfeedbacks = get_string("modulenameplural", "feedback"); $strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback"); $strfeedback = get_string("modulename", "feedback");
$PAGE->navbar->add(get_string('analysis','feedback')); $PAGE->navbar->add(get_string('analysis', 'feedback'));
$PAGE->set_heading(format_string($course->fullname)); $PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name)); $PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header(); echo $OUTPUT->header();
/// print the tabs /// print the tabs
include('tabs.php'); require('tabs.php');
//print analysed items //print analysed items
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
//get the groupid //get the groupid
$groupselect = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/feedback/analysis.php?id=' . $cm->id.'&do_show=analysis', true); $myurl = $CFG->wwwroot.'/mod/feedback/analysis.php?id='.$cm->id.'&do_show=analysis';
$groupselect = groups_print_activity_menu($cm, $myurl, true);
$mygroupid = groups_get_activity_group($cm); $mygroupid = groups_get_activity_group($cm);
if( has_capability('mod/feedback:viewreports', $context) ) { if ( has_capability('mod/feedback:viewreports', $context) ) {
echo isset($groupselect) ? $groupselect : ''; echo isset($groupselect) ? $groupselect : '';
echo '<div class="clearer"></div>'; echo '<div class="clearer"></div>';
//button "export to excel" //button "export to excel"
//echo '<div class="mdl-align">';
// echo '<div class="feedback_centered_button">';
echo $OUTPUT->container_start('form-buttons'); echo $OUTPUT->container_start('form-buttons');
$aurl = new moodle_url('analysis_to_excel.php', array('sesskey'=>sesskey(), 'id'=>$id)); $aurl = new moodle_url('analysis_to_excel.php', array('sesskey'=>sesskey(), 'id'=>$id));
echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback')); echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
@ -99,50 +111,55 @@ if( has_capability('mod/feedback:viewreports', $context) ) {
$completedscount = feedback_get_completeds_group_count($feedback, $mygroupid); $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid);
//show the group, if available //show the group, if available
if($mygroupid and $group = $DB->get_record('groups', array('id'=>$mygroupid))) { if ($mygroupid and $group = $DB->get_record('groups', array('id'=>$mygroupid))) {
echo '<b>'.get_string('group').': '.$group->name. '</b><br />'; echo '<b>'.get_string('group').': '.$group->name. '</b><br />';
} }
//show the count //show the count
echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />'; echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';
// get the items of the feedback // get the items of the feedback
$items = $DB->get_records('feedback_item', array('feedback'=>$feedback->id, 'hasvalue'=>1), 'position'); $items = $DB->get_records('feedback_item',
array('feedback'=>$feedback->id, 'hasvalue'=>1),
'position');
//show the count //show the count
if(is_array($items)){ if (is_array($items)) {
echo '<b>'.get_string('questions', 'feedback').': ' .sizeof($items). ' </b><hr />'; echo '<b>'.get_string('questions', 'feedback').': ' .count($items). ' </b><hr />';
} else { } else {
$items=array(); $items=array();
} }
$check_anonymously = true; $check_anonymously = true;
if($mygroupid > 0 AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES) { if ($mygroupid > 0 AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES) {
if($completedscount < FEEDBACK_MIN_ANONYMOUS_COUNT_IN_GROUP) { if ($completedscount < FEEDBACK_MIN_ANONYMOUS_COUNT_IN_GROUP) {
$check_anonymously = false; $check_anonymously = false;
} }
} }
// echo '<div class="mdl-align"><table width="80%" cellpadding="10"><tr><td>';
echo '<div><table width="80%" cellpadding="10"><tr><td>'; echo '<div><table width="80%" cellpadding="10"><tr><td>';
if($check_anonymously) { if ($check_anonymously) {
$itemnr = 0; $itemnr = 0;
//print the items in an analysed form //print the items in an analysed form
foreach($items as $item) { foreach ($items as $item) {
if($item->hasvalue == 0) continue; if ($item->hasvalue == 0) {
continue;
}
echo '<table width="100%" class="generalbox">'; echo '<table width="100%" class="generalbox">';
//get the class of item-typ //get the class of item-typ
$itemobj = feedback_get_item_class($item->typ); $itemobj = feedback_get_item_class($item->typ);
$itemnr++; $itemnr++;
if($feedback->autonumbering) { if ($feedback->autonumbering) {
$printnr = $itemnr.'.'; $printnr = $itemnr.'.';
} else { } else {
$printnr = ''; $printnr = '';
} }
$itemobj->print_analysed($item, $printnr, $mygroupid); $itemobj->print_analysed($item, $printnr, $mygroupid);
// $itemnr = $itemobj->print_analysed($item, $itemnr, $mygroupid);
echo '</table>'; echo '</table>';
} }
}else { } else {
echo $OUTPUT->heading_with_help(get_string('insufficient_responses_for_this_group', 'feedback'), 'insufficient_responses', 'feedback'); echo $OUTPUT->heading_with_help(get_string('insufficient_responses_for_this_group', 'feedback'),
'insufficient_responses',
'feedback');
} }
echo '</td></tr></table></div>'; echo '</td></tr></table></div>';
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();

View File

@ -1,24 +1,36 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* shows an analysed view of a feedback on the mainsite * shows an analysed view of a feedback on the mainsite
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
// $SESSION->feedback->current_tab = 'analysis';
$current_tab = 'analysis'; $current_tab = 'analysis';
$id = required_param('id', PARAM_INT); //the POST dominated the GET $id = required_param('id', PARAM_INT); //the POST dominated the GET
$coursefilter = optional_param('coursefilter', '0', PARAM_INT); $coursefilter = optional_param('coursefilter', '0', PARAM_INT);
$courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT); $courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT);
$courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM); $courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM);
// $searchcourse = optional_param('searchcourse', '', PARAM_ALPHAEXT);
$searchcourse = optional_param('searchcourse', '', PARAM_RAW); $searchcourse = optional_param('searchcourse', '', PARAM_RAW);
$courseid = optional_param('courseid', false, PARAM_INT); $courseid = optional_param('courseid', false, PARAM_INT);
@ -40,7 +52,7 @@ if ($searchcourse !== '') {
} }
$PAGE->set_url($url); $PAGE->set_url($url);
if(($searchcourse OR $courseitemfilter OR $coursefilter) AND !confirm_sesskey()) { if (($searchcourse OR $courseitemfilter OR $coursefilter) AND !confirm_sesskey()) {
print_error('invalidsesskey'); print_error('invalidsesskey');
} }
@ -62,7 +74,7 @@ if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
require_login($course->id, true, $cm); require_login($course->id, true, $cm);
if( !( (intval($feedback->publish_stats) == 1) OR has_capability('mod/feedback:viewreports', $context))) { if (!($feedback->publish_stats OR has_capability('mod/feedback:viewreports', $context))) {
print_error('error'); print_error('error');
} }
@ -75,15 +87,19 @@ $PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header(); echo $OUTPUT->header();
/// print the tabs /// print the tabs
include('tabs.php'); require('tabs.php');
//print the analysed items //print the analysed items
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
if( has_capability('mod/feedback:viewreports', $context) ) { if (has_capability('mod/feedback:viewreports', $context)) {
//button "export to excel" //button "export to excel"
echo $OUTPUT->container_start('mdl-align'); echo $OUTPUT->container_start('mdl-align');
$aurl = new moodle_url('analysis_to_excel.php', array('sesskey'=>sesskey(), 'id'=>$id, 'coursefilter'=>$coursefilter)); $aurl = new moodle_url('analysis_to_excel.php',
array('sesskey' => sesskey(),
'id' => $id,
'coursefilter' => $coursefilter));
echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback')); echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
echo $OUTPUT->container_end(); echo $OUTPUT->container_end();
} }
@ -98,11 +114,14 @@ $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $c
echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />'; echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';
// get the items of the feedback // get the items of the feedback
$items = $DB->get_records('feedback_item', array('feedback'=>$feedback->id, 'hasvalue'=>1), 'position'); $params = array('feedback' => $feedback->id, 'hasvalue' => 1);
$items = $DB->get_records('feedback_item', $params, 'position');
//show the count //show the count
if(is_array($items)){ if (is_array($items)) {
echo '<b>'.get_string('questions', 'feedback').': ' .sizeof($items). ' </b><hr />'; echo '<b>'.get_string('questions', 'feedback').': ' .count($items). ' </b><hr />';
echo '<a href="analysis_course.php?id=' . $id . '&courseid='.$courseid.'">'.get_string('show_all', 'feedback').'</a>'; echo '<a href="analysis_course.php?id=' . $id . '&courseid='.$courseid.'">';
echo get_string('show_all', 'feedback');
echo '</a>';
} else { } else {
$items=array(); $items=array();
} }
@ -114,12 +133,14 @@ if ($courseitemfilter > 0) {
if ($DB->get_dbfamily() == 'postgres') { // TODO: this should be moved to standard sql DML function ;-) if ($DB->get_dbfamily() == 'postgres') { // TODO: this should be moved to standard sql DML function ;-)
$avgvalue = 'avg(cast (value as integer))'; $avgvalue = 'avg(cast (value as integer))';
} }
if ($courses = $DB->get_records_sql ("SELECT fv.course_id, c.shortname, $avgvalue AS avgvalue
FROM {feedback_value} fv, {course} c, {feedback_item} fi $sql = "SELECT fv.course_id, c.shortname, $avgvalue AS avgvalue
WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ? FROM {feedback_value} fv, {course} c, {feedback_item} fi
GROUP BY course_id, shortname WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
ORDER BY avgvalue desc", GROUP BY course_id, shortname
array($courseitemfiltertyp, $courseitemfilter))) { ORDER BY avgvalue desc";
if ($courses = $DB->get_records_sql($sql, array($courseitemfiltertyp, $courseitemfilter))) {
$item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter)); $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter));
echo '<tr><th colspan="2">'.$item->name.'</th></tr>'; echo '<tr><th colspan="2">'.$item->name.'</th></tr>';
echo '<tr><td><table align="left">'; echo '<tr><td><table align="left">';
@ -128,8 +149,15 @@ if ($courseitemfilter > 0) {
$sep_thous = get_string('separator_thousand', 'feedback'); $sep_thous = get_string('separator_thousand', 'feedback');
foreach ($courses as $c) { foreach ($courses as $c) {
$shortname = format_string($c->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $c->course_id))); $coursecontext = get_context_instance(CONTEXT_COURSE, $c->course_id);
echo '<tr><td>'.$shortname.'</td><td align="right">'.number_format(($c->avgvalue), 2, $sep_dec, $sep_thous).'</td></tr>'; $shortname = format_string($c->shortname, true, array('context' => $coursecontext));
echo '<tr>';
echo '<td>'.$shortname.'</td>';
echo '<td align="right">'
echo number_format(($c->avgvalue), 2, $sep_dec, $sep_thous);
echo '</td>';
echo '</tr>';
} }
echo '</table></td></tr>'; echo '</table></td></tr>';
} else { } else {
@ -138,7 +166,8 @@ if ($courseitemfilter > 0) {
} else { } else {
echo get_string('search_course', 'feedback') . ': '; echo get_string('search_course', 'feedback') . ': ';
echo '<input type="text" name="searchcourse" value="'.s($searchcourse).'"/> <input type="submit" value="'.get_string('search').'"/>'; echo '<input type="text" name="searchcourse" value="'.s($searchcourse).'"/> ';
echo '<input type="submit" value="'.get_string('search').'"/>';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="id" value="'.$id.'" />'; echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '<input type="hidden" name="courseitemfilter" value="'.$courseitemfilter.'" />'; echo '<input type="hidden" name="courseitemfilter" value="'.$courseitemfilter.'" />';
@ -158,28 +187,40 @@ if ($courseitemfilter > 0) {
echo ' ' . get_string('filter_by_course', 'feedback') . ': '; echo ' ' . get_string('filter_by_course', 'feedback') . ': ';
echo html_writer::select($courses, 'coursefilter', $coursefilter, null, array('id'=>'coursefilterid')); echo html_writer::select($courses, 'coursefilter', $coursefilter,
$PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('analysis-form', 'coursefilterid', false)); null, array('id'=>'coursefilterid'));
$PAGE->requires->js_init_call('M.util.init_select_autosubmit',
array('analysis-form', 'coursefilterid', false));
} }
echo '<hr />'; echo '<hr />';
$itemnr = 0; $itemnr = 0;
//print the items in an analysed form //print the items in an analysed form
echo '<tr><td>'; echo '<tr><td>';
foreach($items as $item) { foreach ($items as $item) {
if($item->hasvalue == 0) continue; if ($item->hasvalue == 0) {
continue;
}
echo '<table width="100%" class="generalbox">'; echo '<table width="100%" class="generalbox">';
//get the class from item-typ //get the class from item-typ
$itemobj = feedback_get_item_class($item->typ); $itemobj = feedback_get_item_class($item->typ);
$itemnr++; $itemnr++;
if($feedback->autonumbering) { if ($feedback->autonumbering) {
$printnr = $itemnr.'.'; $printnr = $itemnr.'.';
} else { } else {
$printnr = ''; $printnr = '';
} }
$itemobj->print_analysed($item, $printnr, $mygroupid, $coursefilter); $itemobj->print_analysed($item, $printnr, $mygroupid, $coursefilter);
if (preg_match('/rated$/i', $item->typ)) { if (preg_match('/rated$/i', $item->typ)) {
echo '<tr><td colspan="2"><a href="#" onclick="setcourseitemfilter('.$item->id.',\''.$item->typ.'\'); return false;">'. $onclick = 'onclick="setcourseitemfilter'.
get_string('sort_by_course', 'feedback').'</a></td></tr>'; "(".$item->id.",'".$item->typ."');".
' return false;"';
$anker = '<a href="#" '.$onclick.'>'.
get_string('sort_by_course', 'feedback').
'</a>';
echo '<tr><td colspan="2">'.$anker.'</td></tr>';
} }
echo '</table>'; echo '</table>';
} }

View File

@ -1,16 +1,29 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* prints an analysed excel-spreadsheet of the feedback * prints an analysed excel-spreadsheet of the feedback
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
// require_once('easy_excel.php');
require_once("$CFG->libdir/excellib.class.php"); require_once("$CFG->libdir/excellib.class.php");
feedback_load_feedback_items(); feedback_load_feedback_items();
@ -63,12 +76,15 @@ $fstring->username = get_string('username');
$fstring->fullname = get_string('fullnameuser'); $fstring->fullname = get_string('fullnameuser');
$fstring->courseid = get_string('courseid', 'feedback'); $fstring->courseid = get_string('courseid', 'feedback');
$fstring->course = get_string('course'); $fstring->course = get_string('course');
$fstring->anonymous_user = get_string('anonymous_user','feedback'); $fstring->anonymous_user = get_string('anonymous_user', 'feedback');
ob_end_clean(); ob_end_clean();
//get the questions (item-names) //get the questions (item-names)
if(!$items = $DB->get_records('feedback_item', array('feedback'=>$feedback->id, 'hasvalue'=>1), 'position')) { $params = array('feedback' => $feedback->id, 'hasvalue' => 1);
print_error('no_items_available_yet', 'feedback', $CFG->wwwroot.'/mod/feedback/view.php?id='.$id); if (!$items = $DB->get_records('feedback_item', $params, 'position')) {
print_error('no_items_available_yet',
'feedback',
$CFG->wwwroot.'/mod/feedback/view.php?id='.$id);
exit; exit;
} }
@ -77,54 +93,30 @@ $filename = "feedback.xls";
$mygroupid = groups_get_activity_group($cm); $mygroupid = groups_get_activity_group($cm);
// Creating a workbook // Creating a workbook
// $workbook = new EasyWorkbook("-");
$workbook = new MoodleExcelWorkbook('-'); $workbook = new MoodleExcelWorkbook('-');
// $workbook->setTempDir($CFG->tempdir.'');
$workbook->send($filename); $workbook->send($filename);
// $workbook->setVersion(8);
//creating the needed formats //creating the needed formats
$xlsFormats = new stdClass(); $xls_formats = new stdClass();
$xlsFormats->head1 = $workbook->add_format(array( $xls_formats->head1 = $workbook->add_format(array(
'bold'=>1, 'bold'=>1,
'size'=>12)); 'size'=>12));
$xlsFormats->head2 = $workbook->add_format(array( $xls_formats->head2 = $workbook->add_format(array(
'align'=>'left', 'align'=>'left',
'bold'=>1, 'bold'=>1,
'bottum'=>2)); 'bottum'=>2));
$xlsFormats->default = $workbook->add_format(array( $xls_formats->default = $workbook->add_format(array(
'align'=>'left', 'align'=>'left',
'v_align'=>'top')); 'v_align'=>'top'));
// $xlsFormats->head2_green = $workbook->add_format(array( $xls_formats->value_bold = $workbook->add_format(array(
// 'align'=>'left',
// 'bold'=>1,
// 'v_align'=>'top',
// 'bottum'=>2,
// 'fg_color'=>'green'));
$xlsFormats->value_bold = $workbook->add_format(array(
'align'=>'left', 'align'=>'left',
'bold'=>1, 'bold'=>1,
'v_align'=>'top')); 'v_align'=>'top'));
// $xlsFormats->value_blue = $workbook->add_format(array( $xls_formats->procent = $workbook->add_format(array(
// 'align'=>'left',
// 'bold'=>1,
// 'v_align'=>'top',
// 'top'=>2,
// 'fg_color'=>'blue'));
// $xlsFormats->value_red = $workbook->add_format(array(
// 'align'=>'left',
// 'bold'=>1,
// 'v_align'=>'top',
// 'top'=>2,
// 'fg_color'=>'red'));
$xlsFormats->procent = $workbook->add_format(array(
'align'=>'left', 'align'=>'left',
'bold'=>1, 'bold'=>1,
'v_align'=>'top', 'v_align'=>'top',
@ -134,59 +126,57 @@ $xlsFormats->procent = $workbook->add_format(array(
$sheetname = clean_param($feedback->name, PARAM_ALPHANUM); $sheetname = clean_param($feedback->name, PARAM_ALPHANUM);
error_reporting(0); error_reporting(0);
$worksheet1 =& $workbook->add_worksheet(substr($sheetname, 0, 31)); $worksheet1 =& $workbook->add_worksheet(substr($sheetname, 0, 31));
// $worksheet1->set_workbook($workbook);
$worksheet2 =& $workbook->add_worksheet('detailed'); $worksheet2 =& $workbook->add_worksheet('detailed');
// $worksheet2->set_workbook($workbook);
error_reporting($CFG->debug); error_reporting($CFG->debug);
// $worksheet1->pear_excel_worksheet->set_portrait();
// $worksheet1->pear_excel_worksheet->set_paper(9);
// $worksheet1->pear_excel_worksheet->center_horizontally();
$worksheet1->hide_gridlines(); $worksheet1->hide_gridlines();
// $worksheet1->pear_excel_worksheet->set_header("&\"Arial," . $fstring->bold . "\"&14".$feedback->name);
// $worksheet1->pear_excel_worksheet->set_footer($fstring->page." &P " . $fstring->of . " &N");
$worksheet1->set_column(0, 0, 10); $worksheet1->set_column(0, 0, 10);
$worksheet1->set_column(1, 1, 30); $worksheet1->set_column(1, 1, 30);
$worksheet1->set_column(2, 20, 15); $worksheet1->set_column(2, 20, 15);
// $worksheet1->set_margins_LR(0.10);
// $worksheet2->pear_excel_worksheet->set_landscape();
// $worksheet2->pear_excel_worksheet->set_paper(9);
// $worksheet2->pear_excel_worksheet->center_horizontally();
//writing the table header //writing the table header
$rowOffset1 = 0; $row_offset1 = 0;
// $worksheet1->setFormat("<f>",12,false); $worksheet1->write_string($row_offset1, 0, userdate(time()), $xls_formats->head1);
$worksheet1->write_string($rowOffset1, 0, UserDate(time()), $xlsFormats->head1);
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//print the analysed sheet //print the analysed sheet
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//get the completeds //get the completeds
$completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $coursefilter); $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $coursefilter);
if($completedscount > 0){ if ($completedscount > 0) {
//write the count of completeds //write the count of completeds
$rowOffset1++; $row_offset1++;
$worksheet1->write_string($rowOffset1, 0, $fstring->modulenameplural.': '.strval($completedscount), $xlsFormats->head1); $worksheet1->write_string($row_offset1,
0,
$fstring->modulenameplural.': '.strval($completedscount),
$xls_formats->head1);
} }
if(is_array($items)){ if (is_array($items)) {
$rowOffset1++; $row_offset1++;
$worksheet1->write_string($rowOffset1, 0, $fstring->questions.': '. strval(sizeof($items)), $xlsFormats->head1); $worksheet1->write_string($row_offset1,
0,
$fstring->questions.': '. strval(count($items)),
$xls_formats->head1);
} }
$rowOffset1 += 2; $row_offset1 += 2;
$worksheet1->write_string($rowOffset1, 0, $fstring->itemlabel, $xlsFormats->head1); $worksheet1->write_string($row_offset1, 0, $fstring->itemlabel, $xls_formats->head1);
$worksheet1->write_string($rowOffset1, 1, $fstring->question, $xlsFormats->head1); $worksheet1->write_string($row_offset1, 1, $fstring->question, $xls_formats->head1);
$worksheet1->write_string($rowOffset1, 2, $fstring->responses, $xlsFormats->head1); $worksheet1->write_string($row_offset1, 2, $fstring->responses, $xls_formats->head1);
$rowOffset1++ ; $row_offset1++;
if (empty($items)) { if (empty($items)) {
$items=array(); $items=array();
} }
foreach($items as $item) { foreach ($items as $item) {
//get the class of item-typ //get the class of item-typ
$itemobj = feedback_get_item_class($item->typ); $itemobj = feedback_get_item_class($item->typ);
$rowOffset1 = $itemobj->excelprint_item($worksheet1, $rowOffset1, $xlsFormats, $item, $mygroupid, $coursefilter); $row_offset1 = $itemobj->excelprint_item($worksheet1,
$row_offset1,
$xls_formats,
$item,
$mygroupid,
$coursefilter);
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -199,14 +189,18 @@ $completeds = feedback_get_completeds_group($feedback, $mygroupid, $coursefilter
//therefor for each completed we have to iterate over all items of the feedback //therefor for each completed we have to iterate over all items of the feedback
//this is done by feedback_excelprint_detailed_items //this is done by feedback_excelprint_detailed_items
$rowOffset2 = 0; $row_offset2 = 0;
//first we print the table-header //first we print the table-header
$rowOffset2 = feedback_excelprint_detailed_head($worksheet2, $xlsFormats, $items, $rowOffset2); $row_offset2 = feedback_excelprint_detailed_head($worksheet2, $xls_formats, $items, $row_offset2);
if(is_array($completeds)){ if (is_array($completeds)) {
foreach($completeds as $completed) { foreach ($completeds as $completed) {
$rowOffset2 = feedback_excelprint_detailed_items($worksheet2, $xlsFormats, $completed, $items, $rowOffset2); $row_offset2 = feedback_excelprint_detailed_items($worksheet2,
$xls_formats,
$completed,
$items,
$row_offset2);
} }
} }
@ -219,100 +213,102 @@ exit;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
function feedback_excelprint_detailed_head(&$worksheet, $xlsFormats, $items, $rowOffset) { function feedback_excelprint_detailed_head(&$worksheet, $xls_formats, $items, $row_offset) {
global $fstring, $feedback; global $fstring, $feedback;
if(!$items) return; if (!$items) {
$colOffset = 0; return;
}
$col_offset = 0;
// $worksheet->setFormat('<l><f><ru2>'); $worksheet->write_string($row_offset + 1, $col_offset, $fstring->idnumber, $xls_formats->head2);
$col_offset++;
$worksheet->write_string($rowOffset + 1, $colOffset, $fstring->idnumber, $xlsFormats->head2); $worksheet->write_string($row_offset + 1, $col_offset, $fstring->username, $xls_formats->head2);
$colOffset++; $col_offset++;
$worksheet->write_string($rowOffset + 1, $colOffset, $fstring->username, $xlsFormats->head2); $worksheet->write_string($row_offset + 1, $col_offset, $fstring->fullname, $xls_formats->head2);
$colOffset++; $col_offset++;
$worksheet->write_string($rowOffset + 1, $colOffset, $fstring->fullname, $xlsFormats->head2); foreach ($items as $item) {
$colOffset++; $worksheet->write_string($row_offset, $col_offset, $item->name, $xls_formats->head2);
$worksheet->write_string($row_offset + 1, $col_offset, $item->label, $xls_formats->head2);
foreach($items as $item) { $col_offset++;
// $worksheet->setFormat('<l><f><ru2>');
$worksheet->write_string($rowOffset, $colOffset, $item->name, $xlsFormats->head2);
$worksheet->write_string($rowOffset + 1, $colOffset, $item->label, $xlsFormats->head2);
$colOffset++;
} }
// $worksheet->setFormat('<l><f><ru2>'); $worksheet->write_string($row_offset + 1, $col_offset, $fstring->courseid, $xls_formats->head2);
$worksheet->write_string($rowOffset + 1, $colOffset, $fstring->courseid, $xlsFormats->head2); $col_offset++;
$colOffset++;
// $worksheet->setFormat('<l><f><ru2>'); $worksheet->write_string($row_offset + 1, $col_offset, $fstring->course, $xls_formats->head2);
$worksheet->write_string($rowOffset + 1, $colOffset, $fstring->course, $xlsFormats->head2); $col_offset++;
$colOffset++;
return $rowOffset + 2; return $row_offset + 2;
} }
function feedback_excelprint_detailed_items(&$worksheet, $xlsFormats, $completed, $items, $rowOffset) { function feedback_excelprint_detailed_items(&$worksheet, $xls_formats,
$completed, $items, $row_offset) {
global $DB, $fstring; global $DB, $fstring;
if(!$items) return; if (!$items) {
$colOffset = 0; return;
}
$col_offset = 0;
$courseid = 0; $courseid = 0;
$feedback = $DB->get_record('feedback', array('id'=>$completed->feedback)); $feedback = $DB->get_record('feedback', array('id'=>$completed->feedback));
//get the username //get the username
//anonymous users are separated automatically because the userid in the completed is "0" //anonymous users are separated automatically because the userid in the completed is "0"
// $worksheet->setFormat('<l><f><ru2>'); if ($user = $DB->get_record('user', array('id'=>$completed->userid))) {
if($user = $DB->get_record('user', array('id'=>$completed->userid))) {
if ($completed->anonymous_response == FEEDBACK_ANONYMOUS_NO) { if ($completed->anonymous_response == FEEDBACK_ANONYMOUS_NO) {
$worksheet->write_string($rowOffset, $colOffset, $user->idnumber, $xlsFormats->head2); $worksheet->write_string($row_offset, $col_offset, $user->idnumber, $xls_formats->head2);
$colOffset++; $col_offset++;
$userfullname = fullname($user); $userfullname = fullname($user);
$worksheet->write_string($rowOffset, $colOffset, $user->username, $xlsFormats->head2); $worksheet->write_string($row_offset, $col_offset, $user->username, $xls_formats->head2);
$colOffset++; $col_offset++;
} else { } else {
$userfullname = $fstring->anonymous_user; $userfullname = $fstring->anonymous_user;
$worksheet->write_string($rowOffset, $colOffset, '-', $xlsFormats->head2); $worksheet->write_string($row_offset, $col_offset, '-', $xls_formats->head2);
$colOffset++; $col_offset++;
$worksheet->write_string($rowOffset, $colOffset, '-', $xlsFormats->head2); $worksheet->write_string($row_offset, $col_offset, '-', $xls_formats->head2);
$colOffset++; $col_offset++;
} }
}else { } else {
$userfullname = $fstring->anonymous_user; $userfullname = $fstring->anonymous_user;
$worksheet->write_string($rowOffset, $colOffset, '-', $xlsFormats->head2); $worksheet->write_string($row_offset, $col_offset, '-', $xls_formats->head2);
$colOffset++; $col_offset++;
$worksheet->write_string($rowOffset, $colOffset, '-', $xlsFormats->head2); $worksheet->write_string($row_offset, $col_offset, '-', $xls_formats->head2);
$colOffset++; $col_offset++;
} }
$worksheet->write_string($rowOffset, $colOffset, $userfullname, $xlsFormats->head2); $worksheet->write_string($row_offset, $col_offset, $userfullname, $xls_formats->head2);
$colOffset++; $col_offset++;
foreach($items as $item) { foreach ($items as $item) {
$value = $DB->get_record('feedback_value', array('item'=>$item->id, 'completed'=>$completed->id)); $params = array('item' => $item->id, 'completed' => $completed->id);
$value = $DB->get_record('feedback_value', $params);
$itemobj = feedback_get_item_class($item->typ); $itemobj = feedback_get_item_class($item->typ);
$printval = $itemobj->get_printval($item, $value); $printval = $itemobj->get_printval($item, $value);
$printval = trim($printval); $printval = trim($printval);
// $worksheet->setFormat('<l><vo>'); if (is_numeric($printval)) {
if(is_numeric($printval)) { $worksheet->write_number($row_offset, $col_offset, $printval, $xls_formats->default);
$worksheet->write_number($rowOffset, $colOffset, $printval, $xlsFormats->default); } else if ($printval != '') {
} elseif($printval != '') { $worksheet->write_string($row_offset, $col_offset, $printval, $xls_formats->default);
$worksheet->write_string($rowOffset, $colOffset, $printval, $xlsFormats->default);
} }
$printval = ''; $printval = '';
$colOffset++; $col_offset++;
$courseid = isset($value->course_id) ? $value->course_id : 0; $courseid = isset($value->course_id) ? $value->course_id : 0;
if($courseid == 0) $courseid = $feedback->course; if ($courseid == 0) {
$courseid = $feedback->course;
}
} }
$worksheet->write_number($rowOffset, $colOffset, $courseid, $xlsFormats->default); $worksheet->write_number($row_offset, $col_offset, $courseid, $xls_formats->default);
$colOffset++; $col_offset++;
if (isset($courseid) AND $course = $DB->get_record('course', array('id' => $courseid))) { if (isset($courseid) AND $course = $DB->get_record('course', array('id' => $courseid))) {
$shortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid))); $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
$worksheet->write_string($rowOffset, $colOffset, $shortname, $xlsFormats->default); $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
$worksheet->write_string($row_offset, $col_offset, $shortname, $xls_formats->default);
} }
return $rowOffset + 1; return $row_offset + 1;
} }

View File

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify

View File

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -53,7 +52,7 @@ class backup_feedback_activity_task extends backup_activity_task {
static public function encode_content_links($content) { static public function encode_content_links($content) {
global $CFG; global $CFG;
$base = preg_quote($CFG->wwwroot,"/"); $base = preg_quote($CFG->wwwroot, "/");
// Link to the list of feedbacks // Link to the list of feedbacks
$search="/(".$base."\/mod\/feedback\/index.php\?id\=)([0-9]+)/"; $search="/(".$base."\/mod\/feedback\/index.php\?id\=)([0-9]+)/";

View File

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify

View File

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -54,7 +53,6 @@ class backup_feedback_activity_structure_step extends backup_activity_structure_
'timemodified', 'timemodified',
'completionsubmit')); 'completionsubmit'));
$completeds = new backup_nested_element('completeds'); $completeds = new backup_nested_element('completeds');
$completed = new backup_nested_element('completed', array('id'), array( $completed = new backup_nested_element('completed', array('id'), array(
@ -92,7 +90,6 @@ class backup_feedback_activity_structure_step extends backup_activity_structure_
'completed', 'completed',
'value')); 'value'));
// Build the tree // Build the tree
$feedback->add_child($items); $feedback->add_child($items);
$items->add_child($item); $items->add_child($item);

View File

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify

View File

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify

View File

@ -1,68 +1,25 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* prints the form to choose the group you want to analyse * prints the form to choose the group you want to analyse
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
require_once $CFG->libdir.'/formslib.php';
class feedback_choose_group_form extends moodleform {
var $feedbackdata;
function definition() {
$this->feedbackdata = new stdClass();
//this function can not be called, because not all data are available at this time
//I use set_form_elements instead
}
//this function set the data used in set_form_elements()
//in this form the only value have to set is course
//eg: array('course' => $course)
function set_feedbackdata($data) {
if(is_array($data)) {
foreach($data as $key => $val) {
$this->feedbackdata->{$key} = $val;
}
}
}
//here the elements will be set
//this function have to be called manually
//the advantage is that the data are already set
function set_form_elements(){
$mform =& $this->_form;
$elementgroup = array();
//headline
// $mform->addElement('header', 'general', get_string('choose_group', 'feedback'));
// hidden elements
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'do_show');
$mform->setType('do-show', PARAM_INT);
// visible elements
$groups_options = array();
if(isset($this->feedbackdata->groups)){
$groups_options['-1'] = get_string('allgroups');
foreach($this->feedbackdata->groups as $group) {
$groups_options[$group->id] = $group->name;
}
}
$attributes = 'onChange="this.form.submit()"';
$elementgroup[] =& $mform->createElement('select', 'lstgroupid', '', $groups_options, $attributes);
// buttons
$elementgroup[] =& $mform->createElement('submit', 'switch_group', get_string('switch_group', 'feedback'));
$mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
//-------------------------------------------------------------------------------
}
}
//This file can be deleted

File diff suppressed because it is too large Load Diff

View File

@ -1,459 +1,538 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* prints the form so an anonymous user can fill out the feedback on the mainsite * prints the form so an anonymous user can fill out the feedback on the mainsite
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
feedback_init_feedback_session(); feedback_init_feedback_session();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$completedid = optional_param('completedid', false, PARAM_INT); $completedid = optional_param('completedid', false, PARAM_INT);
$preservevalues = optional_param('preservevalues', 0, PARAM_INT); $preservevalues = optional_param('preservevalues', 0, PARAM_INT);
$courseid = optional_param('courseid', false, PARAM_INT); $courseid = optional_param('courseid', false, PARAM_INT);
$gopage = optional_param('gopage', -1, PARAM_INT); $gopage = optional_param('gopage', -1, PARAM_INT);
$lastpage = optional_param('lastpage', false, PARAM_INT); $lastpage = optional_param('lastpage', false, PARAM_INT);
$startitempos = optional_param('startitempos', 0, PARAM_INT); $startitempos = optional_param('startitempos', 0, PARAM_INT);
$lastitempos = optional_param('lastitempos', 0, PARAM_INT); $lastitempos = optional_param('lastitempos', 0, PARAM_INT);
$url = new moodle_url('/mod/feedback/complete_guest.php', array('id'=>$id)); $url = new moodle_url('/mod/feedback/complete_guest.php', array('id'=>$id));
if ($completedid !== false) { if ($completedid !== false) {
$url->param('completedid', $completedid); $url->param('completedid', $completedid);
} }
if ($preservevalues !== 0) { if ($preservevalues !== 0) {
$url->param('preservevalues', $preservevalues); $url->param('preservevalues', $preservevalues);
} }
if ($courseid !== false) { if ($courseid !== false) {
$url->param('courseid', $courseid); $url->param('courseid', $courseid);
} }
if ($gopage !== -1) { if ($gopage !== -1) {
$url->param('gopage', $gopage); $url->param('gopage', $gopage);
} }
if ($lastpage !== false) { if ($lastpage !== false) {
$url->param('lastpage', $lastpage); $url->param('lastpage', $lastpage);
} }
if ($startitempos !== 0) { if ($startitempos !== 0) {
$url->param('startitempos', $startitempos); $url->param('startitempos', $startitempos);
} }
if ($lastitempos !== 0) { if ($lastitempos !== 0) {
$url->param('lastitempos', $lastitempos); $url->param('lastitempos', $lastitempos);
} }
$PAGE->set_url($url); $PAGE->set_url($url);
$highlightrequired = false; $highlightrequired = false;
if(($formdata = data_submitted()) AND !confirm_sesskey()) { if (($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey'); 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 = $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 the use hit enter into a textfield so the form should not submit if (! $cm = get_coursemodule_from_id('feedback', $id)) {
if(isset($formdata->sesskey) AND !isset($formdata->savevalues) AND !isset($formdata->gonextpage) AND !isset($formdata->gopreviouspage)) { print_error('invalidcoursemodule');
$gopage = $formdata->lastpage; }
}
if(isset($formdata->savevalues)) {
$savevalues = true;
}else {
$savevalues = false;
}
if($gopage < 0 AND !$savevalues) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
if(isset($formdata->gonextpage)){ print_error('coursemisconf');
$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)) { if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('coursemisconf'); print_error('badcontext');
} }
if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { $feedback_complete_cap = false;
print_error('invalidcoursemodule');
}
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) { if (isset($CFG->feedback_allowfullanonymous)
print_error('badcontext'); AND $CFG->feedback_allowfullanonymous
} AND $course->id == SITEID
AND (!$courseid OR $courseid == SITEID)
AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
$feedback_complete_cap = true;
}
$feedback_complete_cap = false; //check whether the feedback is anonymous
if (isset($CFG->feedback_allowfullanonymous)
if(isset($CFG->feedback_allowfullanonymous)
AND $CFG->feedback_allowfullanonymous AND $CFG->feedback_allowfullanonymous
AND $course->id == SITEID AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES
AND (!$courseid OR $courseid == SITEID) AND $course->id == SITEID ) {
AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) { $feedback_complete_cap = true;
$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 '<h2><font color="red">';
echo get_string('feedback_is_not_open', 'feedback');
echo '</font></h2>';
echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
exit;
}
//additional check for multiple-submit (prevent browsers back-button).
//the main-check is in view.php
$feedback_can_submit = true;
if ($feedback->multiple_submit == 0 ) {
if (feedback_is_already_submitted($feedback->id, $courseid)) {
$feedback_can_submit = false;
} }
}
//check whether the feedback is anonymous if ($feedback_can_submit) {
if(isset($CFG->feedback_allowfullanonymous) //preserving the items
AND $CFG->feedback_allowfullanonymous if ($preservevalues == 1) {
AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES if (!$SESSION->feedback->is_started == true) {
AND $course->id == SITEID ) { print_error('error', 'error', $CFG->wwwroot.'/course/view.php?id='.$course->id);
$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');
$PAGE->navbar->add($strfeedbacks, new moodle_url('/mod/feedback/index.php', array('id'=>$course->id)));
$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"));
}
feedback_print_errors();
//check, if the feedback is open (timeopen, timeclose)
$checktime = time();
if(($feedback->timeopen > $checktime) OR ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
echo $OUTPUT->box_start('generalbox boxaligncenter');
echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>';
echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
exit;
}
//additional check for multiple-submit (prevent browsers back-button). the main-check is in view.php
$feedback_can_submit = true;
if($feedback->multiple_submit == 0 ) {
// if($multiple_count = $DB->get_record('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedback->id))) {
if(feedback_is_already_submitted($feedback->id, $courseid)) {
$feedback_can_submit = false;
} }
} //check, if all required items have a value
if($feedback_can_submit) { if (feedback_check_values($startitempos, $lastitempos)) {
//preserving the items $userid = $USER->id; //arb
if($preservevalues == 1){ if ($completedid = feedback_save_guest_values(sesskey())) {
if (!$SESSION->feedback->is_started == true) { add_to_log($course->id,
print_error('error', 'error', $CFG->wwwroot.'/course/view.php?id='.$course->id); 'feedback',
} 'startcomplete',
//check, if all required items have a value 'view.php?id='.$cm->id,
if(feedback_check_values($startitempos, $lastitempos)) { $feedback->id);
$userid = $USER->id; //arb
if($completedid = feedback_save_guest_values(sesskey())){
add_to_log($course->id, 'feedback', 'startcomplete', 'view.php?id='.$cm->id, $feedback->id); //arb: log even guest submissions or at least the startcomplete since the other add log event is elsewhere
if(!$gonextpage AND !$gopreviouspage) $preservevalues = false;//es kann gespeichert werden //now it can be saved
if (!$gonextpage AND !$gopreviouspage) {
}else { $preservevalues = false;
$savereturn = 'failed';
if(isset($lastpage)) {
$gopage = $lastpage;
}else {
print_error('parameters_missing', 'feedback');
}
} }
}else {
$savereturn = 'missing'; } else {
$highlightrequired = true; $savereturn = 'failed';
if(isset($lastpage)) { if (isset($lastpage)) {
$gopage = $lastpage; $gopage = $lastpage;
}else { } else {
print_error('parameters_missing', 'feedback'); print_error('parameters_missing', 'feedback');
} }
} }
} else {
$savereturn = 'missing';
$highlightrequired = true;
if (isset($lastpage)) {
$gopage = $lastpage;
} else {
print_error('parameters_missing', 'feedback');
}
} }
}
//saving the items //saving the items
if($savevalues AND !$preservevalues){ if ($savevalues AND !$preservevalues) {
//exists there any pagebreak, so there are values in the feedback_valuetmp //exists there any pagebreak, so there are values in the feedback_valuetmp
$userid = $USER->id; //arb changed from 0 to $USER->id - no strict anonymous feedbacks - if it is a guest taking it then I want to know that it was a guest (at least in the data saved in the feedback tables) //arb changed from 0 to $USER->id
//no strict anonymous feedbacks
//if it is a guest taking it then I want to know that it was
//a guest (at least in the data saved in the feedback tables)
$userid = $USER->id;
$feedbackcompletedtmp = $DB->get_record('feedback_completedtmp', array('id'=>$completedid)); $params = array('id'=>$completedid);
$feedbackcompletedtmp = $DB->get_record('feedback_completedtmp', $params);
//fake saving for switchrole //fake saving for switchrole
$is_switchrole = feedback_check_is_switchrole(); $is_switchrole = feedback_check_is_switchrole();
if($is_switchrole) { if ($is_switchrole) {
$savereturn = 'saved'; $savereturn = 'saved';
feedback_delete_completedtmp($completedid); feedback_delete_completedtmp($completedid);
}else if($new_completed_id = feedback_save_tmp_values($feedbackcompletedtmp, false, $userid)) { } else {
$new_completed_id = feedback_save_tmp_values($feedbackcompletedtmp, false, $userid);
if ($new_completed_id) {
$savereturn = 'saved'; $savereturn = 'saved';
feedback_send_email_anonym($cm, $feedback, $course, $userid); feedback_send_email_anonym($cm, $feedback, $course, $userid);
unset($SESSION->feedback->is_started); unset($SESSION->feedback->is_started);
}else { } else {
$savereturn = 'failed'; $savereturn = 'failed';
} }
} }
}
if($allbreaks = feedback_get_all_break_positions($feedback->id)){ if ($allbreaks = feedback_get_all_break_positions($feedback->id)) {
if($gopage <= 0) { if ($gopage <= 0) {
$startposition = 0;
}else {
if(!isset($allbreaks[$gopage - 1])) {
$gopage = count($allbreaks);
}
$startposition = $allbreaks[$gopage - 1];
}
$ispagebreak = true;
}else {
$startposition = 0; $startposition = 0;
$newpage = 0; } else {
$ispagebreak = false; if (!isset($allbreaks[$gopage - 1])) {
$gopage = count($allbreaks);
}
$startposition = $allbreaks[$gopage - 1];
} }
$ispagebreak = true;
} else {
$startposition = 0;
$newpage = 0;
$ispagebreak = false;
}
//get the feedbackitems after the last shown pagebreak //get the feedbackitems after the last shown pagebreak
$feedbackitems = $DB->get_records_select('feedback_item', 'feedback = ? AND position > ?', array($feedback->id, $startposition), 'position'); $select = 'feedback = ? AND position > ?';
$params = array($feedback->id, $startposition);
$feedbackitems = $DB->get_records_select('feedback_item', $select, $params, 'position');
//get the first pagebreak //get the first pagebreak
if($pagebreaks = $DB->get_records('feedback_item', array('feedback'=>$feedback->id, 'typ'=>'pagebreak'), 'position')) { $params = array('feedback'=>$feedback->id, 'typ'=>'pagebreak');
$pagebreaks = array_values($pagebreaks); if ($pagebreaks = $DB->get_records('feedback_item', $params, 'position')) {
$firstpagebreak = $pagebreaks[0]; $pagebreaks = array_values($pagebreaks);
}else { $firstpagebreak = $pagebreaks[0];
$firstpagebreak = false; } else {
$firstpagebreak = false;
}
$maxitemcount = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
$feedbackcompletedtmp = feedback_get_current_completed($feedback->id,
true,
$courseid,
sesskey());
/// Print the main part of the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
$analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id));
if ($courseid > 0) {
$analysisurl->param('courseid', $courseid);
}
echo $OUTPUT->heading(format_text($feedback->name));
if ( (intval($feedback->publish_stats) == 1) AND
( has_capability('mod/feedback:viewanalysepage', $context)) AND
!( has_capability('mod/feedback:viewreports', $context)) ) {
echo $OUTPUT->box_start('mdl-align');
echo '<a href="'.$analysisurl->out().'">';
echo get_string('completed_feedbacks', 'feedback');
echo '</a>';
echo $OUTPUT->box_end();
}
if (isset($savereturn) && $savereturn == 'saved') {
if ($feedback->page_after_submit) {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
echo format_text($feedback->page_after_submit,
$feedback->page_after_submitformat,
array('overflowdiv' => true));
echo $OUTPUT->box_end();
} else {
echo '<p align="center"><b><font color="green">';
echo get_string('entries_saved', 'feedback');
echo '</font></b></p>';
if ( intval($feedback->publish_stats) == 1) {
echo '<p align="center"><a href="'.$analysisurl->out().'">';
echo get_string('completed_feedbacks', 'feedback').'</a>';
echo '</p>';
}
} }
$maxitemcount = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); if ($feedback->site_after_submit) {
$feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid, sesskey()); $url = feedback_encode_target_url($feedback->site_after_submit);
} else {
/// Print the main part of the page if ($courseid) {
/////////////////////////////////////////////////////////////////////////// if ($courseid == SITEID) {
/////////////////////////////////////////////////////////////////////////// $url = $CFG->wwwroot;
/////////////////////////////////////////////////////////////////////////// } else {
$analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id)); $url = $CFG->wwwroot.'/course/view.php?id='.$courseid;
if($courseid > 0) { }
$analysisurl->param('courseid', $courseid); } else {
if ($course->id == SITEID) {
$url = $CFG->wwwroot;
} else {
$url = $CFG->wwwroot.'/course/view.php?id='.$course->id;
}
}
} }
echo $OUTPUT->heading(format_text($feedback->name)); echo $OUTPUT->continue_button($url);
} else {
if( (intval($feedback->publish_stats) == 1) AND if (isset($savereturn) && $savereturn == 'failed') {
( has_capability('mod/feedback:viewanalysepage', $context)) AND echo $OUTPUT->box_start('mform error');
!( has_capability('mod/feedback:viewreports', $context)) ) { echo get_string('saving_failed', 'feedback');
echo $OUTPUT->box_start('mdl-align');
echo '<a href="'.$analysisurl->out().'">'.get_string('completed_feedbacks', 'feedback').'</a>';
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
if(isset($savereturn) && $savereturn == 'saved') { if (isset($savereturn) && $savereturn == 'missing') {
if($feedback->page_after_submit) { echo $OUTPUT->box_start('mform error');
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo get_string('saving_failed_because_missing_or_false_values', 'feedback');
echo format_text($feedback->page_after_submit, $feedback->page_after_submitformat, array('overflowdiv'=>true)); echo $OUTPUT->box_end();
echo $OUTPUT->box_end(); }
} else {
echo '<p align="center"><b><font color="green">'.get_string('entries_saved','feedback').'</font></b></p>'; //print the items
if( intval($feedback->publish_stats) == 1) { if (is_array($feedbackitems)) {
echo '<p align="center"><a href="'.$analysisurl->out().'">'; echo $OUTPUT->box_start('feedback_form');
echo get_string('completed_feedbacks', 'feedback').'</a>'; echo '<form action="complete_guest.php" method="post" onsubmit=" ">';
echo '</p>'; echo '<fieldset>';
} echo '<input type="hidden" name="anonymous" value="0" />';
} $inputvalue = 'value="'.FEEDBACK_ANONYMOUS_YES.'"';
if($feedback->site_after_submit) { echo '<input type="hidden" name="anonymous_response" '.$inputvalue.' />';
echo $OUTPUT->continue_button(feedback_encode_target_url($feedback->site_after_submit)); echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
}else { //check, if there exists required-elements
if($courseid) { $params = array('feedback'=>$feedback->id, 'required'=>1);
if($courseid == SITEID) { $countreq = $DB->count_records('feedback_item', $params);
echo $OUTPUT->continue_button($CFG->wwwroot); if ($countreq > 0) {
}else { echo '<span class="feedback_required_mark">(*)';
echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid); echo get_string('items_are_required', 'feedback');
} echo '</span>';
}else { }
if($course->id == SITEID) { echo $OUTPUT->box_start('feedback_items');
echo $OUTPUT->continue_button($CFG->wwwroot);
} else { $startitem = null;
echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id); $select = 'feedback = ? AND hasvalue = 1 AND position < ?';
} $params = array($feedback->id, $startposition);
} $itemnr = $DB->count_records_select('feedback_item', $select, $params);
} $lastbreakposition = 0;
}else { $align = right_to_left() ? 'right' : 'left';
if(isset($savereturn) && $savereturn == 'failed') {
echo $OUTPUT->box_start('mform error'); foreach ($feedbackitems as $feedbackitem) {
echo get_string('saving_failed','feedback'); if (!isset($startitem)) {
echo $OUTPUT->box_end(); //avoid showing double pagebreaks
} if ($feedbackitem->typ == 'pagebreak') {
continue;
if(isset($savereturn) && $savereturn == 'missing') { }
echo $OUTPUT->box_start('mform error'); $startitem = $feedbackitem;
echo get_string('saving_failed_because_missing_or_false_values','feedback'); }
echo $OUTPUT->box_end();
} if ($feedbackitem->dependitem > 0) {
//chech if the conditions are ok
//print the items $fb_compare_value = feedback_compare_item_value($feedbackcompletedtmp->id,
if(is_array($feedbackitems)){ $feedbackitem->dependitem,
// echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); $feedbackitem->dependvalue,
echo $OUTPUT->box_start('feedback_form'); true);
echo '<form action="complete_guest.php" method="post" onsubmit=" ">'; if (!isset($feedbackcompletedtmp->id) OR !$fb_compare_value) {
echo '<fieldset>'; $lastitem = $feedbackitem;
echo '<input type="hidden" name="anonymous" value="0" />'; $lastbreakposition = $feedbackitem->position;
echo '<input type="hidden" name="anonymous_response" value="'.FEEDBACK_ANONYMOUS_YES.'" />'; continue;
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; }
//check, if there exists required-elements }
$countreq = $DB->count_records('feedback_item', array('feedback'=>$feedback->id, 'required'=>1));
if($countreq > 0) { if ($feedbackitem->dependitem > 0) {
echo '<span class="feedback_required_mark">(*)' . get_string('items_are_required', 'feedback') . '</span>'; $dependstyle = ' feedback_complete_depend';
} } else {
echo $OUTPUT->box_start('feedback_items'); $dependstyle = '';
}
$startitem = null;
$itemnr = $DB->count_records_select('feedback_item', 'feedback = ? AND hasvalue = 1 AND position < ?', array($feedback->id, $startposition)); echo $OUTPUT->box_start('feedback_item_box_'.$align.$dependstyle);
$lastbreakposition = 0; $value = '';
$align = right_to_left() ? 'right' : 'left'; //get the value
$frmvaluename = $feedbackitem->typ.'_'.$feedbackitem->id;
foreach($feedbackitems as $feedbackitem){ if (isset($savereturn)) {
if(!isset($startitem)) { if (isset($formdata->{$frmvaluename})) {
//avoid showing double pagebreaks $value = $formdata->{$frmvaluename};
if($feedbackitem->typ == 'pagebreak') { } else {
continue; $value = null;
} }
$startitem = $feedbackitem; } else {
} if (isset($feedbackcompletedtmp->id)) {
$value = feedback_get_item_value($feedbackcompletedtmp->id,
if($feedbackitem->dependitem > 0) { $feedbackitem->id,
//chech if the conditions are ok sesskey());
if(!isset($feedbackcompletedtmp->id) OR !feedback_compare_item_value($feedbackcompletedtmp->id, $feedbackitem->dependitem, $feedbackitem->dependvalue, true)) { }
$lastitem = $feedbackitem; }
$lastbreakposition = $feedbackitem->position; if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
continue; $itemnr++;
} echo $OUTPUT->box_start('feedback_item_number_'.$align);
} echo $itemnr;
echo $OUTPUT->box_end();
if($feedbackitem->dependitem > 0) { }
$dependstyle = ' feedback_complete_depend'; if ($feedbackitem->typ != 'pagebreak') {
}else { echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
$dependstyle = ''; feedback_print_item_complete($feedbackitem, $value, $highlightrequired);
} echo $OUTPUT->box_end();
}
echo $OUTPUT->box_start('feedback_item_box_'.$align.$dependstyle); echo $OUTPUT->box_end();
$value = '';
//get the value $lastbreakposition = $feedbackitem->position; //last item-pos (item or pagebreak)
$frmvaluename = $feedbackitem->typ . '_'. $feedbackitem->id; if ($feedbackitem->typ == 'pagebreak') {
if(isset($savereturn)) { break;
$value = isset($formdata->{$frmvaluename})?$formdata->{$frmvaluename}:NULL; } else {
}else { $lastitem = $feedbackitem;
if(isset($feedbackcompletedtmp->id)) { }
$value = feedback_get_item_value($feedbackcompletedtmp->id, $feedbackitem->id, sesskey()); }
} echo $OUTPUT->box_end();
} echo '<input type="hidden" name="id" value="'.$id.'" />';
if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) { echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'" />';
$itemnr++; echo '<input type="hidden" name="lastpage" value="'.$gopage.'" />';
echo $OUTPUT->box_start('feedback_item_number_'.$align); if (isset($feedbackcompletedtmp->id)) {
echo $itemnr; $inputvalue = 'value="'.$feedbackcompletedtmp->id;
echo $OUTPUT->box_end(); } else {
} $inputvalue = 'value=""';
if($feedbackitem->typ != 'pagebreak') { }
echo $OUTPUT->box_start('box generalbox boxalign_'.$align); echo '<input type="hidden" name="completedid" '.$inputvalue.' />';
feedback_print_item_complete($feedbackitem, $value, $highlightrequired); echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
echo $OUTPUT->box_end(); echo '<input type="hidden" name="preservevalues" value="1" />';
} if (isset($startitem)) {
echo $OUTPUT->box_end(); echo '<input type="hidden" name="startitempos" value="'.$startitem->position.'" />';
echo '<input type="hidden" name="lastitempos" value="'.$lastitem->position.'" />';
$lastbreakposition = $feedbackitem->position; //last item-pos (item or pagebreak) }
if($feedbackitem->typ == 'pagebreak'){
break; if ($ispagebreak AND $lastbreakposition > $firstpagebreak->position) {
}else { $inputvalue = 'value="'.get_string('previous_page', 'feedback').'"';
$lastitem = $feedbackitem; echo '<input name="gopreviouspage" type="submit" '.$inputvalue.' />';
} }
} if ($lastbreakposition < $maxitemcount) {
echo $OUTPUT->box_end(); $inputvalue = 'value="'.get_string('next_page', 'feedback').'"';
echo '<input type="hidden" name="id" value="'.$id.'" />'; echo '<input name="gonextpage" type="submit" '.$inputvalue.' />';
echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'" />'; }
echo '<input type="hidden" name="lastpage" value="'.$gopage.'" />'; if ($lastbreakposition >= $maxitemcount) { //last page
echo '<input type="hidden" name="completedid" value="'.(isset($feedbackcompletedtmp->id)?$feedbackcompletedtmp->id:'').'" />'; $inputvalue = 'value="'.get_string('save_entries', 'feedback').'"';
echo '<input type="hidden" name="courseid" value="'. $courseid . '" />'; echo '<input name="savevalues" type="submit" '.$inputvalue.' />';
echo '<input type="hidden" name="preservevalues" value="1" />'; }
if(isset($startitem)) {
echo '<input type="hidden" name="startitempos" value="'. $startitem->position . '" />'; echo '</fieldset>';
echo '<input type="hidden" name="lastitempos" value="'. $lastitem->position . '" />'; echo '</form>';
} echo $OUTPUT->box_end();
if($ispagebreak AND $lastbreakposition > $firstpagebreak->position) { echo $OUTPUT->box_start('feedback_complete_cancel');
echo '<input name="gopreviouspage" type="submit" value="'.get_string('previous_page','feedback').'" />'; if ($courseid) {
} $action = 'action="'.$CFG->wwwroot.'/course/view.php?id='.$courseid.'"';
if($lastbreakposition < $maxitemcount){ } else {
echo '<input name="gonextpage" type="submit" value="'.get_string('next_page','feedback').'" />'; if ($course->id == SITEID) {
} $action = 'action="'.$CFG->wwwroot.'"';
if($lastbreakposition >= $maxitemcount) { //last page } else {
echo '<input name="savevalues" type="submit" value="'.get_string('save_entries','feedback').'" />'; $action = 'action="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'"';
} }
}
echo '</fieldset>'; echo '<form '.$action.' method="post" onsubmit=" ">';
echo '</form>'; echo '<fieldset>';
echo $OUTPUT->box_end(); echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
echo $OUTPUT->box_start('feedback_complete_cancel'); echo '<button type="submit">'.get_string('cancel').'</button>';
if($courseid) { echo '</fieldset>';
echo '<form action="'.$CFG->wwwroot.'/course/view.php?id='.$courseid.'" method="post" onsubmit=" ">'; echo '</form>';
}else{ echo $OUTPUT->box_end();
if($course->id == SITEID) { $SESSION->feedback->is_started = true;
echo '<form action="'.$CFG->wwwroot.'" method="post" onsubmit=" ">';
} else {
echo '<form action="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'" method="post" onsubmit=" ">';
}
}
echo '<fieldset>';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
echo '<button type="submit">'.get_string('cancel').'</button>';
echo '</fieldset>';
echo '</form>';
echo $OUTPUT->box_end();
$SESSION->feedback->is_started = true;
}
} }
}else {
echo $OUTPUT->box_start('generalbox boxaligncenter');
echo '<h2><font color="red">'.get_string('this_feedback_is_already_submitted', 'feedback').'</font></h2>';
echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
echo $OUTPUT->box_end();
} }
/// Finish the page } else {
/////////////////////////////////////////////////////////////////////////// echo $OUTPUT->box_start('generalbox boxaligncenter');
/////////////////////////////////////////////////////////////////////////// echo '<h2><font color="red">';
/////////////////////////////////////////////////////////////////////////// echo get_string('this_feedback_is_already_submitted', 'feedback');
echo '</font></h2>';
echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
echo $OUTPUT->box_end();
}
/// Finish the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->footer(); echo $OUTPUT->footer();

View File

@ -1,4 +1,19 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// //
// Capability definitions for the feedback module. // Capability definitions for the feedback module.
// //

View File

@ -1,9 +1,23 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
function xmldb_feedback_install() { function xmldb_feedback_install() {
global $DB; global $DB;
/// Disable this module by default (because it's not technically part of Moodle 2.0) /// Disable this module by default (because it's not technically part of Moodle 2.0)
$DB->set_field('modules', 'visible', 0, array('name'=>'feedback')); $DB->set_field('modules', 'visible', 0, array('name'=>'feedback'));
} }

View File

@ -168,4 +168,4 @@
</INDEXES> </INDEXES>
</TABLE> </TABLE>
</TABLES> </TABLES>
</XMLDB> </XMLDB>

View File

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify

View File

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// This file keeps track of upgrades to // This file keeps track of upgrades to
// the feedback module // the feedback module
@ -31,15 +45,18 @@ function xmldb_feedback_upgrade($oldversion) {
$table = new xmldb_table('feedback_completedtmp'); $table = new xmldb_table('feedback_completedtmp');
$field = new xmldb_field('id'); $field = new xmldb_field('id');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
XMLDB_NOTNULL, true, null, null);
$table->addField($field); $table->addField($field);
$field = new xmldb_field('feedback'); $field = new xmldb_field('feedback');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
XMLDB_NOTNULL, false, '0', null);
$table->addField($field); $table->addField($field);
$field = new xmldb_field('userid'); $field = new xmldb_field('userid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
XMLDB_NOTNULL, false, '0', null);
$table->addField($field); $table->addField($field);
$field = new xmldb_field('guestid'); $field = new xmldb_field('guestid');
@ -47,7 +64,8 @@ function xmldb_feedback_upgrade($oldversion) {
$table->addField($field); $table->addField($field);
$field = new xmldb_field('timemodified'); $field = new xmldb_field('timemodified');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
XMLDB_NOTNULL, false, '0', null);
$table->addField($field); $table->addField($field);
$key = new xmldb_key('PRIMARY'); $key = new xmldb_key('PRIMARY');
@ -65,23 +83,28 @@ function xmldb_feedback_upgrade($oldversion) {
$table = new xmldb_table('feedback_valuetmp'); $table = new xmldb_table('feedback_valuetmp');
$field = new xmldb_field('id'); $field = new xmldb_field('id');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
XMLDB_NOTNULL, true, null, null);
$table->addField($field); $table->addField($field);
$field = new xmldb_field('course_id'); $field = new xmldb_field('course_id');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
XMLDB_NOTNULL, false, '0', null);
$table->addField($field); $table->addField($field);
$field = new xmldb_field('item'); $field = new xmldb_field('item');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
XMLDB_NOTNULL, false, '0', null);
$table->addField($field); $table->addField($field);
$field = new xmldb_field('completed'); $field = new xmldb_field('completed');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
XMLDB_NOTNULL, false, '0', null);
$table->addField($field); $table->addField($field);
$field = new xmldb_field('tmp_completed'); $field = new xmldb_field('tmp_completed');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
XMLDB_NOTNULL, false, '0', null);
$table->addField($field); $table->addField($field);
$field = new xmldb_field('value'); $field = new xmldb_field('value');
@ -105,25 +128,29 @@ function xmldb_feedback_upgrade($oldversion) {
/// Define field random_response to be added to feedback_completed /// Define field random_response to be added to feedback_completed
$table = new xmldb_table('feedback_completed'); $table = new xmldb_table('feedback_completed');
$field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10',
XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
/// Launch add field1 /// Launch add field1
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
/// Define field anonymous_response to be added to feedback_completed /// Define field anonymous_response to be added to feedback_completed
$table = new xmldb_table('feedback_completed'); $table = new xmldb_table('feedback_completed');
$field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null); $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1',
XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
/// Launch add field2 /// Launch add field2
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
/// Define field random_response to be added to feedback_completed /// Define field random_response to be added to feedback_completed
$table = new xmldb_table('feedback_completedtmp'); $table = new xmldb_table('feedback_completedtmp');
$field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10',
XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
/// Launch add field1 /// Launch add field1
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
/// Define field anonymous_response to be added to feedback_completed /// Define field anonymous_response to be added to feedback_completed
$table = new xmldb_table('feedback_completedtmp'); $table = new xmldb_table('feedback_completedtmp');
$field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null); $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1',
XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
/// Launch add field2 /// Launch add field2
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
@ -135,7 +162,8 @@ function xmldb_feedback_upgrade($oldversion) {
// public is a reserved word on Oracle // public is a reserved word on Oracle
$table = new xmldb_table('feedback_template'); $table = new xmldb_table('feedback_template');
$field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null); $field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
XMLDB_NOTNULL, false, '1', null);
if (!$dbman->field_exists($table, $field)) { if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
} }
@ -144,7 +172,9 @@ function xmldb_feedback_upgrade($oldversion) {
if ($oldversion < 2008042400) { //New version in version.php if ($oldversion < 2008042400) { //New version in version.php
if ($all_nonanonymous_feedbacks = $DB->get_records('feedback', array('anonymous'=>2))) { if ($all_nonanonymous_feedbacks = $DB->get_records('feedback', array('anonymous'=>2))) {
$update_sql = 'UPDATE {feedback_completed} SET anonymous_response = 2 WHERE feedback = '; $update_sql = 'UPDATE {feedback_completed}
SET anonymous_response = 2
WHERE feedback = ';
foreach ($all_nonanonymous_feedbacks as $fb) { foreach ($all_nonanonymous_feedbacks as $fb) {
$DB->execute($update_sql.$fb->id); $DB->execute($update_sql.$fb->id);
} }
@ -153,20 +183,34 @@ function xmldb_feedback_upgrade($oldversion) {
} }
if ($oldversion < 2008042401) { //New version in version.php if ($oldversion < 2008042401) { //New version in version.php
$concat_radio = $DB->sql_concat("'r>>>>>'",'presentation'); $concat_radio = $DB->sql_concat("'r>>>>>'", 'presentation');
$concat_check = $DB->sql_concat("'c>>>>>'",'presentation'); $concat_check = $DB->sql_concat("'c>>>>>'", 'presentation');
$concat_dropdown = $DB->sql_concat("'d>>>>>'",'presentation'); $concat_dropdown = $DB->sql_concat("'d>>>>>'", 'presentation');
$update_sql1 = "UPDATE {feedback_item} SET presentation = ".$concat_radio." WHERE typ IN('radio','radiorated')"; $update_sql1 = "UPDATE {feedback_item}
$update_sql2 = "UPDATE {feedback_item} SET presentation = ".$concat_dropdown." WHERE typ IN('dropdown','dropdownrated')"; SET presentation = ".$concat_radio."
$update_sql3 = "UPDATE {feedback_item} SET presentation = ".$concat_check." WHERE typ = 'check'"; WHERE typ IN('radio','radiorated')";
$update_sql2 = "UPDATE {feedback_item}
SET presentation = ".$concat_dropdown."
WHERE typ IN('dropdown','dropdownrated')";
$update_sql3 = "UPDATE {feedback_item}
SET presentation = ".$concat_check."
WHERE typ = 'check'";
$DB->execute($update_sql1); $DB->execute($update_sql1);
$DB->execute($update_sql2); $DB->execute($update_sql2);
$DB->execute($update_sql3); $DB->execute($update_sql3);
$update_sql1 = "UPDATE {feedback_item} SET typ = 'multichoice' WHERE typ IN('radio','check','dropdown')"; $update_sql1 = "UPDATE {feedback_item}
$update_sql2 = "UPDATE {feedback_item} SET typ = 'multichoicerated' WHERE typ IN('radiorated','dropdownrated')"; SET typ = 'multichoice'
WHERE typ IN('radio','check','dropdown')";
$update_sql2 = "UPDATE {feedback_item}
SET typ = 'multichoicerated'
WHERE typ IN('radiorated','dropdownrated')";
$DB->execute($update_sql1); $DB->execute($update_sql1);
$DB->execute($update_sql2); $DB->execute($update_sql2);
@ -176,7 +220,8 @@ function xmldb_feedback_upgrade($oldversion) {
if ($oldversion < 2008042900) { if ($oldversion < 2008042900) {
/// Define field autonumbering to be added to feedback /// Define field autonumbering to be added to feedback
$table = new xmldb_table('feedback'); $table = new xmldb_table('feedback');
$field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'multiple_submit'); $field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1',
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'multiple_submit');
/// Launch add field2 /// Launch add field2
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
@ -186,7 +231,8 @@ function xmldb_feedback_upgrade($oldversion) {
if ($oldversion < 2008050104) { if ($oldversion < 2008050104) {
/// Define field site_after_submit to be added to feedback /// Define field site_after_submit to be added to feedback
$table = new xmldb_table('feedback'); $table = new xmldb_table('feedback');
$field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'autonumbering'); $field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255',
null, null, false, '', 'autonumbering');
/// Launch add field2 /// Launch add field2
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
@ -203,7 +249,11 @@ function xmldb_feedback_upgrade($oldversion) {
} }
if ($oldversion < 2008073002) { if ($oldversion < 2008073002) {
$update_sql = "UPDATE {feedback_item} SET presentation = '-|-' WHERE " . $DB->sql_compare_text('presentation') . " = '0|0' AND typ = 'numeric'"; $update_sql = "UPDATE {feedback_item}
SET presentation = '-|-'
WHERE " . $DB->sql_compare_text('presentation') . " = '0|0' AND
typ = 'numeric'";
$DB->execute($update_sql); $DB->execute($update_sql);
upgrade_mod_savepoint(true, 2008073002, 'feedback'); upgrade_mod_savepoint(true, 2008073002, 'feedback');
@ -221,34 +271,37 @@ function xmldb_feedback_upgrade($oldversion) {
if ($oldversion < 2009042000) { if ($oldversion < 2009042000) {
/// Rename field summary on table feedback to intro /// Rename field summary on table feedback to intro
$table = new xmldb_table('feedback'); $table = new xmldb_table('feedback');
$field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name'); $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null,
XMLDB_NOTNULL, null, null, 'name');
/// Launch rename field summary /// Launch rename field summary
$dbman->rename_field($table, $field, 'intro'); $dbman->rename_field($table, $field, 'intro');
/// feedback savepoint reached /// feedback savepoint reached
upgrade_mod_savepoint(true, 2009042000, 'feedback'); upgrade_mod_savepoint(true, 2009042000, 'feedback');
} }
if ($oldversion < 2009042001) { if ($oldversion < 2009042001) {
/// Define field introformat to be added to feedback /// Define field introformat to be added to feedback
$table = new xmldb_table('feedback'); $table = new xmldb_table('feedback');
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4',
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
/// Launch add field introformat /// Launch add field introformat
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
/// feedback savepoint reached /// feedback savepoint reached
upgrade_mod_savepoint(true, 2009042001, 'feedback'); upgrade_mod_savepoint(true, 2009042001, 'feedback');
} }
if ($oldversion < 2009112000) { if ($oldversion < 2009112000) {
/// Define field page_after_submitformat to be added to feedback /// Define field page_after_submitformat to be added to feedback
$table = new xmldb_table('feedback'); $table = new xmldb_table('feedback');
$field = new xmldb_field('page_after_submitformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'page_after_submit'); $field = new xmldb_field('page_after_submitformat', XMLDB_TYPE_INTEGER, '2',
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'page_after_submit');
if (!$dbman->field_exists($table, $field)) { if (!$dbman->field_exists($table, $field)) {
// Launch add field page_after_submitformat // Launch add field page_after_submitformat
@ -262,7 +315,8 @@ function xmldb_feedback_upgrade($oldversion) {
if ($oldversion < 2010051101) { if ($oldversion < 2010051101) {
/// Define field options to be added to feedback_item /// Define field options to be added to feedback_item
$table = new xmldb_table('feedback_item'); $table = new xmldb_table('feedback_item');
$field = new xmldb_field('options', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'required'); $field = new xmldb_field('options', XMLDB_TYPE_CHAR, '255',
null, null, false, '', 'required');
/// Launch add field /// Launch add field
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
@ -272,7 +326,8 @@ function xmldb_feedback_upgrade($oldversion) {
if ($oldversion < 2010051600) { if ($oldversion < 2010051600) {
/// Define field options to be added to feedback_item /// Define field options to be added to feedback_item
$table = new xmldb_table('feedback_item'); $table = new xmldb_table('feedback_item');
$field = new xmldb_field('dependitem', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'required'); $field = new xmldb_field('dependitem', XMLDB_TYPE_INTEGER, '10',
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'required');
/// Launch add field /// Launch add field
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
@ -282,7 +337,8 @@ function xmldb_feedback_upgrade($oldversion) {
if ($oldversion < 2010051601) { if ($oldversion < 2010051601) {
/// Define field options to be added to feedback_item /// Define field options to be added to feedback_item
$table = new xmldb_table('feedback_item'); $table = new xmldb_table('feedback_item');
$field = new xmldb_field('dependvalue', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'dependitem'); $field = new xmldb_field('dependvalue', XMLDB_TYPE_CHAR, '255',
null, null, false, '', 'dependitem');
/// Launch add field /// Launch add field
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
@ -293,7 +349,8 @@ function xmldb_feedback_upgrade($oldversion) {
// Define field completionsubmit to be added to feedback // Define field completionsubmit to be added to feedback
$table = new xmldb_table('feedback'); $table = new xmldb_table('feedback');
$field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'timemodified'); $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '1',
null, XMLDB_NOTNULL, null, '0', 'timemodified');
// Conditionally launch add field completionsubmit // Conditionally launch add field completionsubmit
if (!$dbman->field_exists($table, $field)) { if (!$dbman->field_exists($table, $field)) {
@ -303,7 +360,6 @@ function xmldb_feedback_upgrade($oldversion) {
// feedback savepoint reached // feedback savepoint reached
upgrade_mod_savepoint(true, 2010102300, 'feedback'); upgrade_mod_savepoint(true, 2010102300, 'feedback');
} }
// Moodle v2.1.0 release upgrade line // Moodle v2.1.0 release upgrade line
// Put any upgrade step following this // Put any upgrade step following this

View File

@ -1,97 +1,116 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* prints the form to confirm the deleting of a completed * prints the form to confirm the deleting of a completed
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once('delete_completed_form.php'); require_once('delete_completed_form.php');
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$completedid = optional_param('completedid', 0, PARAM_INT); $completedid = optional_param('completedid', 0, PARAM_INT);
$return = optional_param('return', 'entries', PARAM_ALPHA); $return = optional_param('return', 'entries', PARAM_ALPHA);
if($completedid == 0){ if ($completedid == 0) {
print_error('no_complete_to_delete', 'feedback', 'show_entries.php?id='.$id.'&do_show=showentries'); print_error('no_complete_to_delete',
'feedback',
'show_entries.php?id='.$id.'&do_show=showentries');
}
$PAGE->set_url('/mod/feedback/delete_completed.php', array('id'=>$id, 'completed'=>$completedid));
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');
}
require_login($course->id, true, $cm);
require_capability('mod/feedback:deletesubmissions', $context);
$mform = new mod_feedback_delete_completed_form();
$newformdata = array('id'=>$id,
'completedid'=>$completedid,
'confirmdelete'=>'1',
'do_show'=>'edit',
'return'=>$return);
$mform->set_data($newformdata);
$formdata = $mform->get_data();
if ($mform->is_cancelled()) {
if ($return == 'entriesanonym') {
redirect('show_entries_anonym.php?id='.$id);
} else {
redirect('show_entries.php?id='.$id.'&do_show=showentries');
} }
}
$PAGE->set_url('/mod/feedback/delete_completed.php', array('id'=>$id, 'completed'=>$completedid)); if (isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1) {
if ($completed = $DB->get_record('feedback_completed', array('id'=>$completedid))) {
feedback_delete_completed($completedid);
add_to_log($course->id,
'feedback',
'delete',
'view.php?id='.$cm->id,
$feedback->id,
$cm->id);
if (! $cm = get_coursemodule_from_id('feedback', $id)) { if ($return == 'entriesanonym') {
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');
}
require_login($course->id, true, $cm);
require_capability('mod/feedback:deletesubmissions', $context);
$mform = new mod_feedback_delete_completed_form();
$newformdata = array('id'=>$id,
'completedid'=>$completedid,
'confirmdelete'=>'1',
'do_show'=>'edit',
'return'=>$return);
$mform->set_data($newformdata);
$formdata = $mform->get_data();
if ($mform->is_cancelled()) {
if($return == 'entriesanonym') {
redirect('show_entries_anonym.php?id='.$id); redirect('show_entries_anonym.php?id='.$id);
}else { } else {
redirect('show_entries.php?id='.$id.'&do_show=showentries'); redirect('show_entries.php?id='.$id.'&do_show=showentries');
} }
} }
}
if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){ /// Print the page header
if($completed = $DB->get_record('feedback_completed', array('id'=>$completedid))) { $strfeedbacks = get_string("modulenameplural", "feedback");
feedback_delete_completed($completedid); $strfeedback = get_string("modulename", "feedback");
add_to_log($course->id, 'feedback', 'delete', 'view.php?id='.$cm->id, $feedback->id,$cm->id);
if($return == 'entriesanonym') {
redirect('show_entries_anonym.php?id='.$id);
}else {
redirect('show_entries.php?id='.$id.'&do_show=showentries');
}
}
}
/// Print the page header $PAGE->navbar->add(get_string('delete_entry', 'feedback'));
$strfeedbacks = get_string("modulenameplural", "feedback"); $PAGE->set_heading(format_string($course->fullname));
$strfeedback = get_string("modulename", "feedback"); $PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header();
$PAGE->navbar->add(get_string('delete_entry', 'feedback'));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header();
/// Print the main part of the page /// Print the main part of the page
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->heading(format_text($feedback->name)); echo $OUTPUT->heading(format_text($feedback->name));
echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal'); echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
echo $OUTPUT->heading(get_string('confirmdeleteentry', 'feedback')); echo $OUTPUT->heading(get_string('confirmdeleteentry', 'feedback'));
$mform->display(); $mform->display();
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
echo $OUTPUT->footer();
echo $OUTPUT->footer();

View File

@ -1,25 +1,38 @@
<?php <?php
/** // This file is part of Moodle - http://moodle.org/
* prints the form to confirm delete a completed //
* // Moodle is free software: you can redistribute it and/or modify
* @author Andreas Grabs // it under the terms of the GNU General Public License as published by
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License // the Free Software Foundation, either version 3 of the License, or
* @package feedback // (at your option) any later version.
*/ //
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* prints the form to confirm delete a completed
*
* @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback
*/
//It must be included from a Moodle page
if (!defined('MOODLE_INTERNAL')) { if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page die('Direct access to this script is forbidden.');
} }
require_once $CFG->libdir.'/formslib.php'; require_once($CFG->libdir.'/formslib.php');
class mod_feedback_delete_completed_form extends moodleform { class mod_feedback_delete_completed_form extends moodleform {
function definition() { public function definition() {
$mform =& $this->_form; $mform =& $this->_form;
//headline
//$mform->addElement('header', 'general', '');
// hidden elements // hidden elements
$mform->addElement('hidden', 'id'); $mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT); $mform->setType('id', PARAM_INT);

View File

@ -1,78 +1,93 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* deletes an item of the feedback * deletes an item of the feedback
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once('delete_item_form.php'); require_once('delete_item_form.php');
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$deleteitem = required_param('deleteitem', PARAM_INT); $deleteitem = required_param('deleteitem', PARAM_INT);
$PAGE->set_url('/mod/feedback/delete_item.php', array('id'=>$id, 'deleteitem'=>$deleteitem)); $PAGE->set_url('/mod/feedback/delete_item.php', array('id'=>$id, 'deleteitem'=>$deleteitem));
if (! $cm = get_coursemodule_from_id('feedback', $id)) { if (! $cm = get_coursemodule_from_id('feedback', $id)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); print_error('coursemisconf');
} }
if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm); if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_capability('mod/feedback:edititems', $context); require_login($course->id, true, $cm);
$mform = new mod_feedback_delete_item_form(); require_capability('mod/feedback:edititems', $context);
$newformdata = array('id'=>$id,
'deleteitem'=>$deleteitem,
'confirmdelete'=>'1');
$mform->set_data($newformdata);
$formdata = $mform->get_data();
if ($mform->is_cancelled()) { $mform = new mod_feedback_delete_item_form();
redirect('edit.php?id='.$id); $newformdata = array('id'=>$id,
} 'deleteitem'=>$deleteitem,
'confirmdelete'=>'1');
$mform->set_data($newformdata);
$formdata = $mform->get_data();
if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){ if ($mform->is_cancelled()) {
feedback_delete_item($formdata->deleteitem); redirect('edit.php?id='.$id);
redirect('edit.php?id=' . $id); }
}
if (isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1) {
feedback_delete_item($formdata->deleteitem);
redirect('edit.php?id=' . $id);
}
/// Print the page header /// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback"); $strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback"); $strfeedback = get_string("modulename", "feedback");
$PAGE->navbar->add(get_string('delete_item', 'feedback'));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header();
/// Print the main part of the page $PAGE->navbar->add(get_string('delete_item', 'feedback'));
/////////////////////////////////////////////////////////////////////////// $PAGE->set_heading(format_string($course->fullname));
/////////////////////////////////////////////////////////////////////////// $PAGE->set_title(format_string($feedback->name));
/////////////////////////////////////////////////////////////////////////// echo $OUTPUT->header();
echo $OUTPUT->heading(format_text($feedback->name));
echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
echo $OUTPUT->heading(get_string('confirmdeleteitem', 'feedback'));
print_string('relateditemsdeleted','feedback');
$mform->display();
echo $OUTPUT->box_end();
echo $OUTPUT->footer(); /// Print the main part of the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->heading(format_text($feedback->name));
echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
echo $OUTPUT->heading(get_string('confirmdeleteitem', 'feedback'));
print_string('relateditemsdeleted', 'feedback');
$mform->display();
echo $OUTPUT->box_end();
echo $OUTPUT->footer();

View File

@ -1,25 +1,38 @@
<?php <?php
/** // This file is part of Moodle - http://moodle.org/
* prints the form to confirm delete a completed //
* // Moodle is free software: you can redistribute it and/or modify
* @author Andreas Grabs // it under the terms of the GNU General Public License as published by
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License // the Free Software Foundation, either version 3 of the License, or
* @package feedback // (at your option) any later version.
*/ //
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* prints the form to confirm delete a completed
*
* @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback
*/
//It must be included from a Moodle page
if (!defined('MOODLE_INTERNAL')) { if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page die('Direct access to this script is forbidden.');
} }
require_once $CFG->libdir.'/formslib.php'; require_once($CFG->libdir.'/formslib.php');
class mod_feedback_delete_item_form extends moodleform { class mod_feedback_delete_item_form extends moodleform {
function definition() { public function definition() {
$mform =& $this->_form; $mform =& $this->_form;
//headline
//$mform->addElement('header', 'general', '');
// hidden elements // hidden elements
$mform->addElement('hidden', 'id'); $mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT); $mform->setType('id', PARAM_INT);

View File

@ -1,26 +1,38 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* deletes a template * deletes a template
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once('delete_template_form.php'); require_once('delete_template_form.php');
require_once($CFG->libdir.'/tablelib.php'); require_once($CFG->libdir.'/tablelib.php');
// $SESSION->feedback->current_tab = 'templates';
$current_tab = 'templates'; $current_tab = 'templates';
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$canceldelete = optional_param('canceldelete', false, PARAM_INT); $canceldelete = optional_param('canceldelete', false, PARAM_INT);
$shoulddelete = optional_param('shoulddelete', false, PARAM_INT); $shoulddelete = optional_param('shoulddelete', false, PARAM_INT);
$deletetempl = optional_param('deletetempl', false, PARAM_INT); $deletetempl = optional_param('deletetempl', false, PARAM_INT);
// $formdata = data_submitted();
$url = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id)); $url = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
if ($canceldelete !== false) { if ($canceldelete !== false) {
@ -34,11 +46,11 @@ if ($deletetempl !== false) {
} }
$PAGE->set_url($url); $PAGE->set_url($url);
if(($formdata = data_submitted()) AND !confirm_sesskey()) { if (($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey'); print_error('invalidsesskey');
} }
if($canceldelete == 1){ if ($canceldelete == 1) {
$editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$id, 'do_show'=>'templates')); $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$id, 'do_show'=>'templates'));
redirect($editurl->out(false)); redirect($editurl->out(false));
} }
@ -77,12 +89,12 @@ if ($mform->is_cancelled()) {
redirect($deleteurl->out(false)); redirect($deleteurl->out(false));
} }
if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){ if (isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1) {
if(!$template = $DB->get_record("feedback_template", array("id"=>$deletetempl))) { if (!$template = $DB->get_record("feedback_template", array("id"=>$deletetempl))) {
print_error('error'); print_error('error');
} }
if($template->ispublic) { if ($template->ispublic) {
$systemcontext = get_system_context(); $systemcontext = get_system_context();
require_capability('mod/feedback:createpublictemplate', $systemcontext); require_capability('mod/feedback:createpublictemplate', $systemcontext);
require_capability('mod/feedback:deletetemplate', $systemcontext); require_capability('mod/feedback:deletetemplate', $systemcontext);
@ -95,32 +107,33 @@ if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){
/// Print the page header /// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback"); $strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback"); $strfeedback = get_string("modulename", "feedback");
$strdeletefeedback = get_string('delete_template','feedback'); $strdeletefeedback = get_string('delete_template', 'feedback');
$PAGE->set_heading(format_string($course->fullname)); $PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name)); $PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header(); echo $OUTPUT->header();
/// print the tabs /// print the tabs
include('tabs.php'); require('tabs.php');
/// Print the main part of the page /// Print the main part of the page
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->heading($strdeletefeedback); echo $OUTPUT->heading($strdeletefeedback);
if($shoulddelete == 1) { if ($shoulddelete == 1) {
echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal'); echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
echo $OUTPUT->heading(get_string('confirmdeletetemplate', 'feedback')); echo $OUTPUT->heading(get_string('confirmdeletetemplate', 'feedback'));
$mform->display(); $mform->display();
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
}else { } else {
//first we get the own templates //first we get the own templates
$templates = feedback_get_template_list($course, 'own'); $templates = feedback_get_template_list($course, 'own');
if(!is_array($templates)) { if (!is_array($templates)) {
echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), 'generalbox boxaligncenter'); echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'),
}else { 'generalbox boxaligncenter');
} else {
echo $OUTPUT->heading(get_string('course'), 3); echo $OUTPUT->heading(get_string('course'), 3);
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
$tablecolumns = array('template', 'action'); $tablecolumns = array('template', 'action');
@ -137,7 +150,7 @@ if($shoulddelete == 1) {
$tablecourse->set_attribute('class', 'generaltable'); $tablecourse->set_attribute('class', 'generaltable');
$tablecourse->setup(); $tablecourse->setup();
foreach($templates as $template) { foreach ($templates as $template) {
$data = array(); $data = array();
$data[] = $template->name; $data[] = $template->name;
$url = new moodle_url($deleteurl, array( $url = new moodle_url($deleteurl, array(
@ -154,12 +167,13 @@ if($shoulddelete == 1) {
} }
//now we get the public templates if it is permitted //now we get the public templates if it is permitted
$systemcontext = get_system_context(); $systemcontext = get_system_context();
if(has_capability('mod/feedback:createpublictemplate', $systemcontext) AND if (has_capability('mod/feedback:createpublictemplate', $systemcontext) AND
has_capability('mod/feedback:deletetemplate', $systemcontext)) { has_capability('mod/feedback:deletetemplate', $systemcontext)) {
$templates = feedback_get_template_list($course, 'public'); $templates = feedback_get_template_list($course, 'public');
if(!is_array($templates)) { if (!is_array($templates)) {
echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), 'generalbox boxaligncenter'); echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'),
}else { 'generalbox boxaligncenter');
} else {
echo $OUTPUT->heading(get_string('public', 'feedback'), 3); echo $OUTPUT->heading(get_string('public', 'feedback'), 3);
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
$tablecolumns = array('template', 'action'); $tablecolumns = array('template', 'action');
@ -176,9 +190,7 @@ if($shoulddelete == 1) {
$tablepublic->set_attribute('class', 'generaltable'); $tablepublic->set_attribute('class', 'generaltable');
$tablepublic->setup(); $tablepublic->setup();
// echo $OUTPUT->heading(get_string('public', 'feedback'), 3); foreach ($templates as $template) {
// echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
foreach($templates as $template) {
$data = array(); $data = array();
$data[] = $template->name; $data[] = $template->name;
$url = new moodle_url($deleteurl, array( $url = new moodle_url($deleteurl, array(

View File

@ -1,25 +1,38 @@
<?php <?php
/** // This file is part of Moodle - http://moodle.org/
* prints the form to confirm delete a completed //
* // Moodle is free software: you can redistribute it and/or modify
* @author Andreas Grabs // it under the terms of the GNU General Public License as published by
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License // the Free Software Foundation, either version 3 of the License, or
* @package feedback // (at your option) any later version.
*/ //
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* prints the form to confirm delete a completed
*
* @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback
*/
//It must be included from a Moodle page
if (!defined('MOODLE_INTERNAL')) { if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page die('Direct access to this script is forbidden.');
} }
require_once $CFG->libdir.'/formslib.php'; require_once($CFG->libdir.'/formslib.php');
class mod_feedback_delete_template_form extends moodleform { class mod_feedback_delete_template_form extends moodleform {
function definition() { public function definition() {
$mform =& $this->_form; $mform =& $this->_form;
//headline
//$mform->addElement('header', 'general', '');
// hidden elements // hidden elements
$mform->addElement('hidden', 'id'); $mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT); $mform->setType('id', PARAM_INT);
@ -34,4 +47,3 @@ class mod_feedback_delete_template_form extends moodleform {
} }
} }

View File

@ -1,12 +1,26 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* prints the form to edit the feedback items such moving, deleting and so on * prints the form to edit the feedback items such moving, deleting and so on
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
@ -16,7 +30,7 @@ feedback_init_feedback_session();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
if(($formdata = data_submitted()) AND !confirm_sesskey()) { if (($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey'); print_error('invalidsesskey');
} }
@ -27,7 +41,6 @@ $moveitem = optional_param('moveitem', false, PARAM_INT);
$movehere = optional_param('movehere', false, PARAM_INT); $movehere = optional_param('movehere', false, PARAM_INT);
$switchitemrequired = optional_param('switchitemrequired', false, PARAM_INT); $switchitemrequired = optional_param('switchitemrequired', false, PARAM_INT);
// $SESSION->feedback->current_tab = $do_show;
$current_tab = $do_show; $current_tab = $do_show;
$url = new moodle_url('/mod/feedback/edit.php', array('id'=>$id, 'do_show'=>$do_show)); $url = new moodle_url('/mod/feedback/edit.php', array('id'=>$id, 'do_show'=>$do_show));
@ -53,22 +66,22 @@ require_login($course->id, true, $cm);
require_capability('mod/feedback:edititems', $context); require_capability('mod/feedback:edititems', $context);
//move up/down items //move up/down items
if($moveupitem){ if ($moveupitem) {
$item = $DB->get_record('feedback_item', array('id'=>$moveupitem)); $item = $DB->get_record('feedback_item', array('id'=>$moveupitem));
feedback_moveup_item($item); feedback_moveup_item($item);
} }
if($movedownitem){ if ($movedownitem) {
$item = $DB->get_record('feedback_item', array('id'=>$movedownitem)); $item = $DB->get_record('feedback_item', array('id'=>$movedownitem));
feedback_movedown_item($item); feedback_movedown_item($item);
} }
//moving of items //moving of items
if($movehere && isset($SESSION->feedback->moving->movingitem)){ if ($movehere && isset($SESSION->feedback->moving->movingitem)) {
$item = $DB->get_record('feedback_item', array('id'=>$SESSION->feedback->moving->movingitem)); $item = $DB->get_record('feedback_item', array('id'=>$SESSION->feedback->moving->movingitem));
feedback_move_item($item, intval($movehere)); feedback_move_item($item, intval($movehere));
$moveitem = false; $moveitem = false;
} }
if($moveitem){ if ($moveitem) {
$item = $DB->get_record('feedback_item', array('id'=>$moveitem)); $item = $DB->get_record('feedback_item', array('id'=>$moveitem));
$SESSION->feedback->moving->shouldmoving = 1; $SESSION->feedback->moving->shouldmoving = 1;
$SESSION->feedback->moving->movingitem = $moveitem; $SESSION->feedback->moving->movingitem = $moveitem;
@ -76,7 +89,7 @@ if($moveitem){
unset($SESSION->feedback->moving); unset($SESSION->feedback->moving);
} }
if($switchitemrequired) { if ($switchitemrequired) {
$item = $DB->get_record('feedback_item', array('id'=>$switchitemrequired)); $item = $DB->get_record('feedback_item', array('id'=>$switchitemrequired));
@feedback_switch_item_required($item); @feedback_switch_item_required($item);
redirect($url->out(false)); redirect($url->out(false));
@ -89,24 +102,26 @@ $create_template_form->set_feedbackdata(array('context'=>$context, 'course'=>$co
$create_template_form->set_form_elements(); $create_template_form->set_form_elements();
$create_template_form->set_data(array('id'=>$id, 'do_show'=>'templates')); $create_template_form->set_data(array('id'=>$id, 'do_show'=>'templates'));
$create_template_formdata = $create_template_form->get_data(); $create_template_formdata = $create_template_form->get_data();
if(isset($create_template_formdata->savetemplate) && $create_template_formdata->savetemplate == 1) { if (isset($create_template_formdata->savetemplate) && $create_template_formdata->savetemplate == 1) {
//check the capabilities to create templates //check the capabilities to create templates
if(!has_capability('mod/feedback:createprivatetemplate', $context) AND if (!has_capability('mod/feedback:createprivatetemplate', $context) AND
!has_capability('mod/feedback:createpublictemplate', $context)) { !has_capability('mod/feedback:createpublictemplate', $context)) {
print_error('cannotsavetempl', 'feedback'); print_error('cannotsavetempl', 'feedback');
} }
if(trim($create_template_formdata->templatename) == '') { if (trim($create_template_formdata->templatename) == '') {
$savereturn = 'notsaved_name'; $savereturn = 'notsaved_name';
}else { } else {
//if the feedback is located on the frontpage then templates can be public //if the feedback is located on the frontpage then templates can be public
if(has_capability('mod/feedback:createpublictemplate', get_system_context())) { if (has_capability('mod/feedback:createpublictemplate', get_system_context())) {
$create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0; $create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0;
}else { } else {
$create_template_formdata->ispublic = 0; $create_template_formdata->ispublic = 0;
} }
if(!feedback_save_as_template($feedback, $create_template_formdata->templatename, $create_template_formdata->ispublic)) { if (!feedback_save_as_template($feedback,
$create_template_formdata->templatename,
$create_template_formdata->ispublic)) {
$savereturn = 'failed'; $savereturn = 'failed';
}else { } else {
$savereturn = 'saved'; $savereturn = 'saved';
} }
} }
@ -115,12 +130,12 @@ if(isset($create_template_formdata->savetemplate) && $create_template_formdata->
//get the feedbackitems //get the feedbackitems
$lastposition = 0; $lastposition = 0;
$feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position'); $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
if(is_array($feedbackitems)){ if (is_array($feedbackitems)) {
$feedbackitems = array_values($feedbackitems); $feedbackitems = array_values($feedbackitems);
if(count($feedbackitems) > 0) { if (count($feedbackitems) > 0) {
$lastitem = $feedbackitems[count($feedbackitems)-1]; $lastitem = $feedbackitems[count($feedbackitems)-1];
$lastposition = $lastitem->position; $lastposition = $lastitem->position;
}else { } else {
$lastposition = 0; $lastposition = 0;
} }
} }
@ -137,9 +152,6 @@ $use_template_form->set_feedbackdata(array('course' => $course));
$use_template_form->set_form_elements(); $use_template_form->set_form_elements();
$use_template_form->set_data(array('id'=>$id)); $use_template_form->set_data(array('id'=>$id));
//the create_template-form
//$create_template_form = new feedback_edit_create_template_form('use_templ.php');
/// Print the page header /// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback"); $strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback"); $strfeedback = get_string("modulename", "feedback");
@ -150,7 +162,7 @@ $PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header(); echo $OUTPUT->header();
/// print the tabs /// print the tabs
include('tabs.php'); require('tabs.php');
/// Print the main part of the page /// Print the main part of the page
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@ -160,38 +172,45 @@ include('tabs.php');
$savereturn=isset($savereturn)?$savereturn:''; $savereturn=isset($savereturn)?$savereturn:'';
//print the messages //print the messages
if($savereturn == 'notsaved_name') { if ($savereturn == 'notsaved_name') {
echo '<p align="center"><b><font color="red">'.get_string('name_required','feedback').'</font></b></p>'; echo '<p align="center"><b><font color="red">'.
get_string('name_required', 'feedback').
'</font></b></p>';
} }
if($savereturn == 'saved') { if ($savereturn == 'saved') {
echo '<p align="center"><b><font color="green">'.get_string('template_saved','feedback').'</font></b></p>'; echo '<p align="center"><b><font color="green">'.
get_string('template_saved', 'feedback').
'</font></b></p>';
} }
if($savereturn == 'failed') { if ($savereturn == 'failed') {
echo '<p align="center"><b><font color="red">'.get_string('saving_failed','feedback').'</font></b></p>'; echo '<p align="center"><b><font color="red">'.
get_string('saving_failed', 'feedback').
'</font></b></p>';
} }
feedback_print_errors();
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
///print the template-section ///print the template-section
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
if($do_show == 'templates') { if ($do_show == 'templates') {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
$use_template_form->display(); $use_template_form->display();
if(has_capability('mod/feedback:createprivatetemplate', $context) OR if (has_capability('mod/feedback:createprivatetemplate', $context) OR
has_capability('mod/feedback:createpublictemplate', $context)) { has_capability('mod/feedback:createpublictemplate', $context)) {
$deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id)); $deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id' => $id));
$create_template_form->display(); $create_template_form->display();
echo '<p><a href="'.$deleteurl->out().'">'.get_string('delete_templates', 'feedback').'</a></p>'; echo '<p><a href="'.$deleteurl->out().'">'.
}else { get_string('delete_templates', 'feedback').
'</a></p>';
} else {
echo '&nbsp;'; echo '&nbsp;';
} }
if(has_capability('mod/feedback:edititems', $context)) { if (has_capability('mod/feedback:edititems', $context)) {
$exporturl = new moodle_url('/mod/feedback/export.php', array('action'=>'exportfile', 'id'=>$id)); $urlparams = array('action'=>'exportfile', 'id'=>$id);
$exporturl = new moodle_url('/mod/feedback/export.php', $urlparams);
$importurl = new moodle_url('/mod/feedback/import.php', array('id'=>$id)); $importurl = new moodle_url('/mod/feedback/import.php', array('id'=>$id));
echo '<p> echo '<p>
<a href="'.$exporturl->out().'">'.get_string('export_questions', 'feedback').'</a>/ <a href="'.$exporturl->out().'">'.get_string('export_questions', 'feedback').'</a>/
@ -203,11 +222,11 @@ if($do_show == 'templates') {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
///print the Item-Edit-section ///print the Item-Edit-section
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
if($do_show == 'edit') { if ($do_show == 'edit') {
$add_item_form->display(); $add_item_form->display();
if(is_array($feedbackitems)){ if (is_array($feedbackitems)) {
$itemnr = 0; $itemnr = 0;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
@ -215,156 +234,180 @@ if($do_show == 'edit') {
$helpbutton = $OUTPUT->help_icon('preview', 'feedback'); $helpbutton = $OUTPUT->help_icon('preview', 'feedback');
echo $OUTPUT->heading($helpbutton . get_string('preview', 'feedback')); echo $OUTPUT->heading($helpbutton . get_string('preview', 'feedback'));
if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) { if (isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
echo $OUTPUT->heading('<a href="edit.php?id='.$id.'">'.get_string('cancel_moving', 'feedback').'</a>'); $anker = '<a href="edit.php?id='.$id.'">';
$anker .= get_string('cancel_moving', 'feedback');
$anker .= '</a>';
echo $OUTPUT->heading($anker);
} }
// echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
//check, if there exists required-elements //check, if there exists required-elements
$countreq = $DB->count_records('feedback_item', array('feedback'=>$feedback->id, 'required'=> 1)); $params = array('feedback' => $feedback->id, 'required' => 1);
if($countreq > 0) { $countreq = $DB->count_records('feedback_item', $params);
// echo '<font color="red">(*)' . get_string('items_are_required', 'feedback') . '</font>'; if ($countreq > 0) {
echo '<span class="feedback_required_mark">(*)' . get_string('items_are_required', 'feedback') . '</span>'; echo '<span class="feedback_required_mark">(*)';
echo get_string('items_are_required', 'feedback');
echo '</span>';
} }
//use list instead a table //use list instead a table
echo $OUTPUT->box_start('feedback_items'); echo $OUTPUT->box_start('feedback_items');
if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) { if (isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
$moveposition = 1; $moveposition = 1;
$movehereurl = new moodle_url($url, array('movehere'=>$moveposition)); $movehereurl = new moodle_url($url, array('movehere'=>$moveposition));
echo $OUTPUT->box_start('feedback_item_box_'.$align.' clipboard'); //only shown if shouldmoving = 1 //only shown if shouldmoving = 1
$buttonlink = $movehereurl->out(); echo $OUTPUT->box_start('feedback_item_box_'.$align.' clipboard');
echo '<a title="'.get_string('move_here','feedback').'" href="'.$buttonlink.'"> $buttonlink = $movehereurl->out();
<img class="movetarget" alt="'.get_string('move_here','feedback').'" src="'.$OUTPUT->pix_url('movehere') . '" /> $strbutton = get_string('move_here', 'feedback');
</a>'; $src = $OUTPUT->pix_url('movehere');
echo $OUTPUT->box_end(); echo '<a title="'.$strbutton.'" href="'.$buttonlink.'">
} <img class="movetarget" alt="'.$strbutton.'" src="'.$src.'" />
//print the inserted items </a>';
$itempos = 0; echo $OUTPUT->box_end();
foreach($feedbackitems as $feedbackitem){ }
$itempos++; //print the inserted items
if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->movingitem == $feedbackitem->id){ //hiding the item to move $itempos = 0;
foreach ($feedbackitems as $feedbackitem) {
$itempos++;
//hiding the item to move
if (isset($SESSION->feedback->moving)) {
if ($SESSION->feedback->moving->movingitem == $feedbackitem->id) {
continue; continue;
} }
if($feedbackitem->dependitem > 0) {
$dependstyle = ' feedback_depend';
}else {
$dependstyle = '';
}
echo $OUTPUT->box_start('feedback_item_box_'.$align.$dependstyle);
//items without value only are labels
if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
$itemnr++;
echo $OUTPUT->box_start('feedback_item_number_'.$align) . $itemnr . $OUTPUT->box_end();
}
echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
echo $OUTPUT->box_start('feedback_item_commands_'.$align);
echo '<span class="feedback_item_commands">('.get_string('position', 'feedback').':'.$itempos .')</span>';
//print the moveup-button
if($feedbackitem->position > 1){
echo '<span class="feedback_item_command_moveup">';
$moveupurl = new moodle_url($url, array('moveupitem'=>$feedbackitem->id));
$buttonlink = $moveupurl->out();
echo '<a class="icon up" title="'.get_string('moveup_item','feedback').'" href="'.$buttonlink.'">
<img alt="'.get_string('moveup_item','feedback').'" src="'.$OUTPUT->pix_url('t/up') . '" />
</a>';
echo '</span>';
}
//print the movedown-button
if($feedbackitem->position < $lastposition - 1){
echo '<span class="feedback_item_command_movedown">';
$movedownurl = new moodle_url($url, array('movedownitem'=>$feedbackitem->id));
$buttonlink = $movedownurl->out();
echo '<a class="icon down" title="'.get_string('movedown_item','feedback').'" href="'.$buttonlink.'">
<img alt="'.get_string('movedown_item','feedback').'" src="'.$OUTPUT->pix_url('t/down') . '" />
</a>';
echo '</span>';
}
//print the move-button
echo '<span class="feedback_item_command_move">';
$moveurl = new moodle_url($url, array('moveitem'=>$feedbackitem->id));
$buttonlink = $moveurl->out();
echo '<a class="editing_move" title="'.get_string('move_item','feedback').'" href="'.$buttonlink.'">
<img alt="'.get_string('move_item','feedback').'" src="'.$OUTPUT->pix_url('t/move') . '" />
</a>';
echo '</span>';
//print the button to edit the item
if($feedbackitem->typ != 'pagebreak') {
echo '<span class="feedback_item_command_edit">';
$editurl = new moodle_url('/mod/feedback/edit_item.php');
$editurl->params(array('do_show'=>$do_show,
'cmid'=>$id,
'id'=>$feedbackitem->id,
'typ'=>$feedbackitem->typ));
// in edit_item.php the param id is used for the itemid and the cmid is the id to get the module
$buttonlink = $editurl->out();
echo '<a class="editing_update" title="'.get_string('edit_item','feedback').'" href="'.$buttonlink.'">
<img alt="'.get_string('edit_item','feedback').'" src="'.$OUTPUT->pix_url('t/edit') . '" />
</a>';
echo '</span>';
}
//print the toggle-button to switch required yes/no
if($feedbackitem->hasvalue == 1) {
echo '<span class="feedback_item_command_toggle">';
// echo '<form action="edit.php" method="post"><fieldset>';
if($feedbackitem->required == 1) {
// echo '<input title="'.get_string('switch_item_to_not_required','feedback').'" type="image" src="pics/required.gif" hspace="1" height="11" width="11" border="0" />';
// echo '<input class="feedback_required_button" title="'.get_string('switch_item_to_not_required','feedback').'" type="image" src="pics/required.gif" />';
$buttontitle = get_string('switch_item_to_not_required','feedback');
$buttonimg = 'pics/required.gif';
} else {
// echo '<input title="'.get_string('switch_item_to_required','feedback').'" type="image" src="pics/notrequired.gif" hspace="1" height="11" width="11" border="0" />';
// echo '<input class="feedback_required_button" title="'.get_string('switch_item_to_required','feedback').'" type="image" src="pics/notrequired.gif" />';
$buttontitle = get_string('switch_item_to_required','feedback');
$buttonimg = 'pics/notrequired.gif';
}
$requiredurl = new moodle_url($url, array('switchitemrequired'=>$feedbackitem->id));
$buttonlink = $requiredurl->out();
echo '<a class="icon feedback_switchrequired" title="'.$buttontitle.'" href="'.$buttonlink.'">
<img alt="'.$buttontitle.'" src="'.$buttonimg.'" />
</a>';
echo '</span>';
}
//print the delete-button
echo '<span class="feedback_item_command_toggle">';
$deleteitemurl = new moodle_url('/mod/feedback/delete_item.php');
$deleteitemurl->params(array('id'=>$id,
'do_show'=>$do_show,
'deleteitem'=>$feedbackitem->id));
$buttonlink = $deleteitemurl->out();
echo '<a class="icon delete" title="'.get_string('delete_item','feedback').'" href="'.$buttonlink.'">
<img alt="'.get_string('delete_item','feedback').'" src="'.$OUTPUT->pix_url('t/delete') . '" />
</a>';
echo '</span>';
echo $OUTPUT->box_end();
if($feedbackitem->typ != 'pagebreak') {
feedback_print_item_preview($feedbackitem);
}else {
echo $OUTPUT->box_start('feedback_pagebreak');
echo get_string('pagebreak', 'feedback').'<hr class="feedback_pagebreak" />';
echo $OUTPUT->box_end();
}
echo $OUTPUT->box_end();
echo $OUTPUT->box_end();
if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
$moveposition++;
$movehereurl->param('movehere', $moveposition);
echo $OUTPUT->box_start('clipboard'); //only shown if shouldmoving = 1
$buttonlink = $movehereurl->out();
echo '<a title="'.get_string('move_here','feedback').'" href="'.$buttonlink.'">
<img class="movetarget" alt="'.get_string('move_here','feedback').'" src="'.$OUTPUT->pix_url('movehere') . '" />
</a>';
echo $OUTPUT->box_end();
}
echo '<div class="clearer">&nbsp;</div>';
} }
if ($feedbackitem->dependitem > 0) {
$dependstyle = ' feedback_depend';
} else {
$dependstyle = '';
}
echo $OUTPUT->box_start('feedback_item_box_'.$align.$dependstyle);
//items without value only are labels
if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
$itemnr++;
echo $OUTPUT->box_start('feedback_item_number_'.$align);
echo $itemnr;
echo $OUTPUT->box_end();
}
echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
echo $OUTPUT->box_start('feedback_item_commands_'.$align);
echo '<span class="feedback_item_commands">';
echo '('.get_string('position', 'feedback').':'.$itempos .')';
echo '</span>';
//print the moveup-button
if ($feedbackitem->position > 1) {
echo '<span class="feedback_item_command_moveup">';
$moveupurl = new moodle_url($url, array('moveupitem'=>$feedbackitem->id));
$buttonlink = $moveupurl->out();
$strbutton = get_string('moveup_item', 'feedback');
echo '<a class="icon up" title="'.$strbutton.'" href="'.$buttonlink.'">
<img alt="'.$strbutton.'" src="'.$OUTPUT->pix_url('t/up') . '" />
</a>';
echo '</span>';
}
//print the movedown-button
if ($feedbackitem->position < $lastposition - 1) {
echo '<span class="feedback_item_command_movedown">';
$urlparams = array('movedownitem'=>$feedbackitem->id);
$movedownurl = new moodle_url($url, $urlparams);
$buttonlink = $movedownurl->out();
$strbutton = get_string('movedown_item', 'feedback');
echo '<a class="icon down" title="'.$strbutton.'" href="'.$buttonlink.'">
<img alt="'.$strbutton.'" src="'.$OUTPUT->pix_url('t/down') . '" />
</a>';
echo '</span>';
}
//print the move-button
echo '<span class="feedback_item_command_move">';
$moveurl = new moodle_url($url, array('moveitem'=>$feedbackitem->id));
$buttonlink = $moveurl->out();
$strbutton = get_string('move_item', 'feedback');
echo '<a class="editing_move" title="'.$strbutton.'" href="'.$buttonlink.'">
<img alt="'.$strbutton.'" src="'.$OUTPUT->pix_url('t/move') . '" />
</a>';
echo '</span>';
//print the button to edit the item
if ($feedbackitem->typ != 'pagebreak') {
echo '<span class="feedback_item_command_edit">';
$editurl = new moodle_url('/mod/feedback/edit_item.php');
$editurl->params(array('do_show'=>$do_show,
'cmid'=>$id,
'id'=>$feedbackitem->id,
'typ'=>$feedbackitem->typ));
// in edit_item.php the param id is used for the itemid
// and the cmid is the id to get the module
$buttonlink = $editurl->out();
$strbutton = get_string('edit_item', 'feedback');
echo '<a class="editing_update" title="'.$strbutton.'" href="'.$buttonlink.'">
<img alt="'.$strbutton.'" src="'.$OUTPUT->pix_url('t/edit') . '" />
</a>';
echo '</span>';
}
//print the toggle-button to switch required yes/no
if ($feedbackitem->hasvalue == 1) {
echo '<span class="feedback_item_command_toggle">';
if ($feedbackitem->required == 1) {
$buttontitle = get_string('switch_item_to_not_required', 'feedback');
$buttonimg = 'pics/required.gif';
} else {
$buttontitle = get_string('switch_item_to_required', 'feedback');
$buttonimg = 'pics/notrequired.gif';
}
$urlparams = array('switchitemrequired'=>$feedbackitem->id);
$requiredurl = new moodle_url($url, $urlparams);
$buttonlink = $requiredurl->out();
echo '<a class="icon '.
'feedback_switchrequired" '.
'title="'.$buttontitle.'" '.
'href="'.$buttonlink.'">'.
'<img alt="'.$buttontitle.'" src="'.$buttonimg.'" />'.
'</a>';
echo '</span>';
}
//print the delete-button
echo '<span class="feedback_item_command_toggle">';
$deleteitemurl = new moodle_url('/mod/feedback/delete_item.php');
$deleteitemurl->params(array('id'=>$id,
'do_show'=>$do_show,
'deleteitem'=>$feedbackitem->id));
$buttonlink = $deleteitemurl->out();
$strbutton = get_string('delete_item', 'feedback');
$src = $OUTPUT->pix_url('t/delete');
echo '<a class="icon delete" title="'.$strbutton.'" href="'.$buttonlink.'">
<img alt="'.$strbutton.'" src="'.$src.'" />
</a>';
echo '</span>';
echo $OUTPUT->box_end();
if ($feedbackitem->typ != 'pagebreak') {
feedback_print_item_preview($feedbackitem);
} else {
echo $OUTPUT->box_start('feedback_pagebreak');
echo get_string('pagebreak', 'feedback').'<hr class="feedback_pagebreak" />';
echo $OUTPUT->box_end();
}
echo $OUTPUT->box_end();
echo $OUTPUT->box_end();
if (isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
$moveposition++;
$movehereurl->param('movehere', $moveposition);
echo $OUTPUT->box_start('clipboard'); //only shown if shouldmoving = 1
$buttonlink = $movehereurl->out();
$strbutton = get_string('move_here', 'feedback');
$src = $OUTPUT->pix_url('movehere');
echo '<a title="'.$strbutton.'" href="'.$buttonlink.'">
<img class="movetarget" alt="'.$strbutton.'" src="'.$src.'" />
</a>';
echo $OUTPUT->box_end();
}
echo '<div class="clearer">&nbsp;</div>';
}
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
}else{ } else {
echo $OUTPUT->box(get_string('no_items_available_yet','feedback'),'generalbox boxaligncenter'); echo $OUTPUT->box(get_string('no_items_available_yet', 'feedback'),
'generalbox boxaligncenter');
} }
} }
/// Finish the page /// Finish the page

View File

@ -1,31 +1,41 @@
<?php <?php
/** // This file is part of Moodle - http://moodle.org/
* prints the forms to choose an item-typ to create items and to choose a template to use //
* // Moodle is free software: you can redistribute it and/or modify
* @author Andreas Grabs // it under the terms of the GNU General Public License as published by
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License // the Free Software Foundation, either version 3 of the License, or
* @package feedback // (at your option) any later version.
*/ //
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* prints the forms to choose an item-typ to create items and to choose a template to use
*
* @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback
*/
//It must be included from a Moodle page
if (!defined('MOODLE_INTERNAL')) { if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page die('Direct access to this script is forbidden.');
} }
require_once $CFG->libdir.'/formslib.php'; require_once($CFG->libdir.'/formslib.php');
class feedback_edit_add_question_form extends moodleform { class feedback_edit_add_question_form extends moodleform {
function definition() { public function definition() {
$mform =& $this->_form; $mform =& $this->_form;
//headline //headline
$mform->addElement('header', 'general', get_string('add_items', 'feedback')); $mform->addElement('header', 'general', get_string('add_items', 'feedback'));
// visible elements // visible elements
// $feedback_names = feedback_load_feedback_items('mod/feedback/item');
// $feedback_names_options = array();
// $feedback_names_options[' '] = get_string('select');
// foreach($feedback_names as $fn) {
// $feedback_names_options[$fn] = get_string($fn,'feedback');
// }
$feedback_names_options = feedback_load_feedback_items_options(); $feedback_names_options = feedback_load_feedback_items_options();
$attributes = 'onChange="this.form.submit()"'; $attributes = 'onChange="this.form.submit()"';
@ -36,16 +46,16 @@ class feedback_edit_add_question_form extends moodleform {
$mform->setType('cmid', PARAM_INT); $mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'position'); $mform->addElement('hidden', 'position');
$mform->setType('position', PARAM_INT); $mform->setType('position', PARAM_INT);
//-------------------------------------------------------------------------------
// buttons // buttons
$mform->addElement('submit', 'add_item', get_string('add_item', 'feedback')); $mform->addElement('submit', 'add_item', get_string('add_item', 'feedback'));
} }
} }
class feedback_edit_use_template_form extends moodleform { class feedback_edit_use_template_form extends moodleform {
var $feedbackdata; private $feedbackdata;
function definition() { public function definition() {
$this->feedbackdata = new stdClass(); $this->feedbackdata = new stdClass();
//this function can not be called, because not all data are available at this time //this function can not be called, because not all data are available at this time
//I use set_form_elements instead //I use set_form_elements instead
@ -54,9 +64,9 @@ class feedback_edit_use_template_form extends moodleform {
//this function set the data used in set_form_elements() //this function set the data used in set_form_elements()
//in this form the only value have to set is course //in this form the only value have to set is course
//eg: array('course' => $course) //eg: array('course' => $course)
function set_feedbackdata($data) { public function set_feedbackdata($data) {
if(is_array($data)) { if (is_array($data)) {
foreach($data as $key => $val) { foreach ($data as $key => $val) {
$this->feedbackdata->{$key} = $val; $this->feedbackdata->{$key} = $val;
} }
} }
@ -65,7 +75,7 @@ class feedback_edit_use_template_form extends moodleform {
//here the elements will be set //here the elements will be set
//this function have to be called manually //this function have to be called manually
//the advantage is that the data are already set //the advantage is that the data are already set
function set_form_elements(){ public function set_form_elements() {
$mform =& $this->_form; $mform =& $this->_form;
$elementgroup = array(); $elementgroup = array();
@ -81,58 +91,63 @@ class feedback_edit_use_template_form extends moodleform {
$publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public'); $publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public');
$options = array(); $options = array();
if($owntemplates or $publictemplates) { if ($owntemplates or $publictemplates) {
$options[''] = array('' => get_string('choose')); $options[''] = array('' => get_string('choose'));
if($owntemplates) { if ($owntemplates) {
$courseoptions = array(); $courseoptions = array();
foreach($owntemplates as $template) { foreach ($owntemplates as $template) {
$courseoptions[$template->id] = $template->name; $courseoptions[$template->id] = $template->name;
} }
$options[get_string('course')] = $courseoptions; $options[get_string('course')] = $courseoptions;
} }
if($publictemplates) { if ($publictemplates) {
$publicoptions = array(); $publicoptions = array();
foreach($publictemplates as $template) { foreach ($publictemplates as $template) {
$publicoptions[$template->id] = $template->name; $publicoptions[$template->id] = $template->name;
} }
$options[get_string('public', 'feedback')] = $publicoptions; $options[get_string('public', 'feedback')] = $publicoptions;
} }
$attributes = 'onChange="this.form.submit()"'; $attributes = 'onChange="this.form.submit()"';
$elementgroup[] =& $mform->createElement('selectgroups', 'templateid', '', $options, $attributes); $elementgroup[] =& $mform->createElement('selectgroups',
$elementgroup[] =& $mform->createElement('submit', 'use_template', get_string('use_this_template', 'feedback')); 'templateid',
}else { '',
$options,
$attributes);
$elementgroup[] =& $mform->createElement('submit',
'use_template',
get_string('use_this_template', 'feedback'));
} else {
$mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback')); $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
} }
$mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false); $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
//-------------------------------------------------------------------------------
} }
} }
class feedback_edit_create_template_form extends moodleform { class feedback_edit_create_template_form extends moodleform {
var $feedbackdata; private $feedbackdata;
function definition() { public function definition() {
} }
function data_preprocessing(&$default_values){ public function data_preprocessing(&$default_values) {
$default_values['templatename'] = ''; $default_values['templatename'] = '';
} }
function set_feedbackdata($data) { public function set_feedbackdata($data) {
if(is_array($data)) { if (is_array($data)) {
foreach($data as $key => $val) { foreach ($data as $key => $val) {
$this->feedbackdata->{$key} = $val; $this->feedbackdata->{$key} = $val;
} }
} }
} }
function set_form_elements(){ public function set_form_elements() {
$mform =& $this->_form; $mform =& $this->_form;
// $capabilities = $this->feedbackdata->capabilities;
// hidden elements // hidden elements
$mform->addElement('hidden', 'id'); $mform->addElement('hidden', 'id');
@ -148,20 +163,35 @@ class feedback_edit_create_template_form extends moodleform {
// visible elements // visible elements
$elementgroup = array(); $elementgroup = array();
$elementgroup[] =& $mform->createElement('static', 'templatenamelabel', get_string('name', 'feedback')); $elementgroup[] =& $mform->createElement('static',
$elementgroup[] =& $mform->createElement('text', 'templatename', get_string('name', 'feedback'), array('size'=>'40', 'maxlength'=>'200')); 'templatenamelabel',
get_string('name', 'feedback'));
if(has_capability('mod/feedback:createpublictemplate', get_system_context())) { $elementgroup[] =& $mform->createElement('text',
$elementgroup[] =& $mform->createElement('checkbox', 'ispublic', get_string('public', 'feedback'), get_string('public', 'feedback')); 'templatename',
get_string('name', 'feedback'),
array('size'=>'40', 'maxlength'=>'200'));
if (has_capability('mod/feedback:createpublictemplate', get_system_context())) {
$elementgroup[] =& $mform->createElement('checkbox',
'ispublic',
get_string('public', 'feedback'),
get_string('public', 'feedback'));
} }
// buttons // buttons
$elementgroup[] =& $mform->createElement('submit', 'create_template', get_string('save_as_new_template', 'feedback')); $elementgroup[] =& $mform->createElement('submit',
$mform->addGroup($elementgroup, 'elementgroup', get_string('name', 'feedback'), array(' '), false); 'create_template',
get_string('save_as_new_template', 'feedback'));
$mform->addGroup($elementgroup,
'elementgroup',
get_string('name', 'feedback'),
array(' '),
false);
$mform->setType('templatename', PARAM_TEXT); $mform->setType('templatename', PARAM_TEXT);
//-------------------------------------------------------------------------------
} }
} }

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* prints the form to edit a dedicated item * prints the form to edit a dedicated item
@ -13,7 +27,6 @@ require_once("lib.php");
feedback_init_feedback_session(); feedback_init_feedback_session();
// $cmid = optional_param('cmid', NULL, PARAM_INT);
$cmid = required_param('cmid', PARAM_INT); $cmid = required_param('cmid', PARAM_INT);
$typ = optional_param('typ', false, PARAM_ALPHA); $typ = optional_param('typ', false, PARAM_ALPHA);
$id = optional_param('id', false, PARAM_INT); $id = optional_param('id', false, PARAM_INT);
@ -21,7 +34,9 @@ $action = optional_param('action', false, PARAM_ALPHA);
$editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cmid)); $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cmid));
if(!$typ)redirect($editurl->out(false)); if (!$typ) {
redirect($editurl->out(false));
}
$url = new moodle_url('/mod/feedback/edit_item.php', array('cmid'=>$cmid)); $url = new moodle_url('/mod/feedback/edit_item.php', array('cmid'=>$cmid));
if ($typ !== false) { if ($typ !== false) {
@ -36,7 +51,7 @@ $PAGE->set_url($url);
$usehtmleditor = can_use_html_editor(); $usehtmleditor = can_use_html_editor();
if(($formdata = data_submitted()) AND !confirm_sesskey()) { if (($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey'); print_error('invalidsesskey');
} }
@ -61,7 +76,7 @@ require_login($course->id, true, $cm);
require_capability('mod/feedback:edititems', $context); require_capability('mod/feedback:edititems', $context);
//if the typ is pagebreak so the item will be saved directly //if the typ is pagebreak so the item will be saved directly
if($typ == 'pagebreak') { if ($typ == 'pagebreak') {
feedback_create_pagebreak($feedback->id); feedback_create_pagebreak($feedback->id);
redirect($editurl->out(false)); redirect($editurl->out(false));
exit; exit;
@ -69,9 +84,9 @@ if($typ == 'pagebreak') {
//get the existing item or create it //get the existing item or create it
// $formdata->itemid = isset($formdata->itemid) ? $formdata->itemid : NULL; // $formdata->itemid = isset($formdata->itemid) ? $formdata->itemid : NULL;
if($id and $item = $DB->get_record('feedback_item', array('id'=>$id))) { if ($id and $item = $DB->get_record('feedback_item', array('id'=>$id))) {
$typ = $item->typ; $typ = $item->typ;
}else { } else {
$item = new stdClass(); $item = new stdClass();
$item->id = null; $item->id = null;
$item->position = -1; $item->position = -1;
@ -88,12 +103,12 @@ $itemobj = feedback_get_item_class($typ);
$itemobj->build_editform($item, $feedback, $cm); $itemobj->build_editform($item, $feedback, $cm);
if($itemobj->is_cancelled()) { if ($itemobj->is_cancelled()) {
redirect($editurl->out(false)); redirect($editurl->out(false));
exit; exit;
} }
if($itemobj->get_data()) { if ($itemobj->get_data()) {
if($item = $itemobj->save_item()) { if ($item = $itemobj->save_item()) {
feedback_move_item($item, $item->position); feedback_move_item($item, $item->position);
redirect($editurl->out(false)); redirect($editurl->out(false));
} }
@ -113,18 +128,15 @@ $PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name)); $PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header(); echo $OUTPUT->header();
/// print the tabs /// print the tabs
include('tabs.php'); require('tabs.php');
/// Print the main part of the page /// Print the main part of the page
echo $OUTPUT->heading(format_text($feedback->name)); echo $OUTPUT->heading(format_text($feedback->name));
//print errormsg //print errormsg
if(isset($error)) { if (isset($error)) {
echo $error; echo $error;
} }
feedback_print_errors();
$itemobj->show_editform(); $itemobj->show_editform();
// echo $OUTPUT->box_end();
if ($typ!='label') { if ($typ!='label') {
$PAGE->requires->js('/mod/feedback/feedback.js'); $PAGE->requires->js('/mod/feedback/feedback.js');
$PAGE->requires->js_function_call('set_item_focus', Array('id_itemname')); $PAGE->requires->js_function_call('set_item_focus', Array('id_itemname'));
@ -136,4 +148,3 @@ if ($typ!='label') {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->footer(); echo $OUTPUT->footer();

View File

@ -1,159 +1,173 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* prints the form to export the items as xml-file * prints the form to export the items as xml-file
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
// get parameters // get parameters
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$action = optional_param('action', false, PARAM_ALPHA); $action = optional_param('action', false, PARAM_ALPHA);
$url = new moodle_url('/mod/feedback/export.php', array('id'=>$id)); $url = new moodle_url('/mod/feedback/export.php', array('id'=>$id));
if ($action !== false) { if ($action !== false) {
$url->param('action', $action); $url->param('action', $action);
}
$PAGE->set_url($url);
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');
}
require_login($course->id, true, $cm);
require_capability('mod/feedback:edititems', $context);
if ($action == 'exportfile') {
if (!$exportdata = feedback_get_xml_data($feedback->id)) {
print_error('nodata');
} }
$PAGE->set_url($url); @feedback_send_xml_data($exportdata, 'feedback_'.$feedback->id.'.xml');
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');
}
require_login($course->id, true, $cm);
require_capability('mod/feedback:edititems', $context);
if ($action == 'exportfile') {
if(!$exportdata = feedback_get_xml_data($feedback->id)) {
print_error('nodata');
}
@feedback_send_xml_data($exportdata, 'feedback_'.$feedback->id.'.xml');
exit;
}
redirect('view.php?id='.$id);
exit; exit;
}
function feedback_get_xml_data($feedbackid) { redirect('view.php?id='.$id);
global $DB; exit;
$space = ' '; function feedback_get_xml_data($feedbackid) {
//get all items of the feedback global $DB;
if(!$items = $DB->get_records('feedback_item', array('feedback'=>$feedbackid), 'position')) {
return false;
}
//writing the header of the xml file including the charset of the currrent used language $space = ' ';
$data = '<?xml version="1.0" encoding="UTF-8" ?>'."\n"; //get all items of the feedback
$data .= '<FEEDBACK VERSION="200701" COMMENT="XML-Importfile for mod/feedback">'."\n"; if (!$items = $DB->get_records('feedback_item', array('feedback'=>$feedbackid), 'position')) {
$data .= $space.'<ITEMS>'."\n"; return false;
//writing all the items
foreach($items as $item) {
//start of item
$data .= $space.$space.'<ITEM TYPE="'.$item->typ.'" REQUIRED="'.$item->required.'">'."\n";
//start of itemid
$data .= $space.$space.$space.'<ITEMID>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->id;
//end of CDATA
$data .= ']]>'."\n";
//end of itemid
$data .= $space.$space.$space.'</ITEMID>'."\n";
//start of itemtext
$data .= $space.$space.$space.'<ITEMTEXT>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->name;
//end of CDATA
$data .= ']]>'."\n";
//end of itemtext
$data .= $space.$space.$space.'</ITEMTEXT>'."\n";
//start of itemtext
$data .= $space.$space.$space.'<ITEMLABEL>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->label;
//end of CDATA
$data .= ']]>'."\n";
//end of itemtext
$data .= $space.$space.$space.'</ITEMLABEL>'."\n";
//start of presentation
$data .= $space.$space.$space.'<PRESENTATION>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->presentation;
//end of CDATA
$data .= ']]>'."\n";
//end of presentation
$data .= $space.$space.$space.'</PRESENTATION>'."\n";
//start of options
$data .= $space.$space.$space.'<OPTIONS>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->options;
//end of CDATA
$data .= ']]>'."\n";
//end of options
$data .= $space.$space.$space.'</OPTIONS>'."\n";
//start of dependitem
$data .= $space.$space.$space.'<DEPENDITEM>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->dependitem;
//end of CDATA
$data .= ']]>'."\n";
//end of dependitem
$data .= $space.$space.$space.'</DEPENDITEM>'."\n";
//start of dependvalue
$data .= $space.$space.$space.'<DEPENDVALUE>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->dependvalue;
//end of CDATA
$data .= ']]>'."\n";
//end of dependvalue
$data .= $space.$space.$space.'</DEPENDVALUE>'."\n";
//end of item
$data .= $space.$space.'</ITEM>'."\n";
}
//writing the footer of the xml file
$data .= $space.'</ITEMS>'."\n";
$data .= '</FEEDBACK>'."\n";
return $data;
} }
function feedback_send_xml_data($data, $filename) { //writing the header of the xml file including the charset of the currrent used language
@header('Content-Type: application/xml; charset=UTF-8'); $data = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
@header('Content-Disposition: attachment; filename='.$filename); $data .= '<FEEDBACK VERSION="200701" COMMENT="XML-Importfile for mod/feedback">'."\n";
print($data); $data .= $space.'<ITEMS>'."\n";
//writing all the items
foreach ($items as $item) {
//start of item
$data .= $space.$space.'<ITEM TYPE="'.$item->typ.'" REQUIRED="'.$item->required.'">'."\n";
//start of itemid
$data .= $space.$space.$space.'<ITEMID>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->id;
//end of CDATA
$data .= ']]>'."\n";
//end of itemid
$data .= $space.$space.$space.'</ITEMID>'."\n";
//start of itemtext
$data .= $space.$space.$space.'<ITEMTEXT>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->name;
//end of CDATA
$data .= ']]>'."\n";
//end of itemtext
$data .= $space.$space.$space.'</ITEMTEXT>'."\n";
//start of itemtext
$data .= $space.$space.$space.'<ITEMLABEL>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->label;
//end of CDATA
$data .= ']]>'."\n";
//end of itemtext
$data .= $space.$space.$space.'</ITEMLABEL>'."\n";
//start of presentation
$data .= $space.$space.$space.'<PRESENTATION>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->presentation;
//end of CDATA
$data .= ']]>'."\n";
//end of presentation
$data .= $space.$space.$space.'</PRESENTATION>'."\n";
//start of options
$data .= $space.$space.$space.'<OPTIONS>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->options;
//end of CDATA
$data .= ']]>'."\n";
//end of options
$data .= $space.$space.$space.'</OPTIONS>'."\n";
//start of dependitem
$data .= $space.$space.$space.'<DEPENDITEM>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->dependitem;
//end of CDATA
$data .= ']]>'."\n";
//end of dependitem
$data .= $space.$space.$space.'</DEPENDITEM>'."\n";
//start of dependvalue
$data .= $space.$space.$space.'<DEPENDVALUE>'."\n";
//start of CDATA
$data .= $space.$space.$space.$space.'<![CDATA[';
$data .= $item->dependvalue;
//end of CDATA
$data .= ']]>'."\n";
//end of dependvalue
$data .= $space.$space.$space.'</DEPENDVALUE>'."\n";
//end of item
$data .= $space.$space.'</ITEM>'."\n";
} }
//writing the footer of the xml file
$data .= $space.'</ITEMS>'."\n";
$data .= '</FEEDBACK>'."\n";
return $data;
}
function feedback_send_xml_data($data, $filename) {
@header('Content-Type: application/xml; charset=UTF-8');
@header('Content-Disposition: attachment; filename='.$filename);
print($data);
}

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* prints the form to import items from xml-file * prints the form to import items from xml-file
@ -8,282 +22,271 @@
* @package feedback * @package feedback
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once('import_form.php'); require_once('import_form.php');
// get parameters // get parameters
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$choosefile = optional_param('choosefile', false, PARAM_PATH); $choosefile = optional_param('choosefile', false, PARAM_PATH);
$action = optional_param('action', false, PARAM_ALPHA); $action = optional_param('action', false, PARAM_ALPHA);
$url = new moodle_url('/mod/feedback/import.php', array('id'=>$id)); $url = new moodle_url('/mod/feedback/import.php', array('id'=>$id));
if ($choosefile !== false) { if ($choosefile !== false) {
$url->param('choosefile', $choosefile); $url->param('choosefile', $choosefile);
} }
if ($action !== false) { if ($action !== false) {
$url->param('action', $action); $url->param('action', $action);
} }
$PAGE->set_url($url); $PAGE->set_url($url);
if (! $cm = get_coursemodule_from_id('feedback', $id)) { if (! $cm = get_coursemodule_from_id('feedback', $id)) {
print_error('invalidcoursemodule'); 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');
}
require_login($course->id, true, $cm);
require_capability('mod/feedback:edititems', $context);
$mform = new feedback_import_form();
$newformdata = array('id'=>$id,
'deleteolditems'=>'1',
'action'=>'choosefile',
'confirmadd'=>'1',
'do_show'=>'templates');
$mform->set_data($newformdata);
$formdata = $mform->get_data();
if ($mform->is_cancelled()) {
redirect('edit.php?id='.$id.'&do_show=templates');
}
// process if we are happy file is ok
if ($choosefile) {
$xmlcontent = $mform->get_file_content('choosefile');
if (!$xmldata = feedback_load_xml_data($xmlcontent)) {
print_error('cannotloadxml', 'feedback', 'edit.php?id='.$id);
} }
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { $importerror = feedback_import_loaded_data($xmldata, $feedback->id);
print_error('coursemisconf'); if ($importerror->stat == true) {
$url = 'edit.php?id='.$id.'&do_show=templates';
redirect($url, get_string('import_successfully', 'feedback'), 3);
exit;
}
}
/// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback");
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header();
/// print the tabs
require('tabs.php');
/// Print the main part of the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->heading(get_string('import_questions', 'feedback'));
if (isset($importerror->msg) AND is_array($importerror->msg)) {
echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter');
foreach ($importerror->msg as $msg) {
echo $msg.'<br />';
}
echo $OUTPUT->box_end();
}
$mform->display();
echo $OUTPUT->footer();
function feedback_load_xml_data($xmlcontent) {
global $CFG;
require_once($CFG->dirroot.'/lib/xmlize.php');
if (!$xmlcontent = feedback_check_xml_utf8($xmlcontent)) {
return false;
} }
if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { $data = xmlize($xmlcontent, 1, 'UTF-8');
print_error('invalidcoursemodule');
if (intval($data['FEEDBACK']['@']['VERSION']) != 200701) {
return false;
} }
$data = $data['FEEDBACK']['#']['ITEMS'][0]['#']['ITEM'];
return $data;
}
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) { function feedback_import_loaded_data(&$data, $feedbackid) {
print_error('badcontext'); global $CFG, $DB;
}
require_login($course->id, true, $cm); feedback_load_feedback_items();
require_capability('mod/feedback:edititems', $context); $deleteolditems = optional_param('deleteolditems', 0, PARAM_INT);
$mform = new feedback_import_form(); $error = new stdClass();
$newformdata = array('id'=>$id, $error->stat = true;
'deleteolditems'=>'1', $error->msg = array();
'action'=>'choosefile',
'confirmadd'=>'1',
'do_show'=>'templates');
$mform->set_data($newformdata);
$formdata = $mform->get_data();
if ($mform->is_cancelled()) {
redirect('edit.php?id='.$id.'&do_show=templates');
}
// unset($filename);
// if ($action == 'choosefile' AND confirm_sesskey() ) {
////file checks out ok
// $fileisgood = false;
////work out if this is an uploaded file
////or one from the filesarea.
// if ($choosefile) {
// $filename = "{$CFG->dataroot}/{$course->id}/{$choosefile}";
// }
// }
// process if we are happy file is ok
if ($choosefile) {
$xmlcontent = $mform->get_file_content('choosefile');
if(!$xmldata = feedback_load_xml_data($xmlcontent)) {
print_error('cannotloadxml', 'feedback', 'edit.php?id='.$id);
}
$importerror = feedback_import_loaded_data($xmldata, $feedback->id);
if($importerror->stat == true) {
redirect('edit.php?id='.$id.'&do_show=templates', get_string('import_successfully', 'feedback'), 3);
exit;
}
}
/// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback");
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header();
/// print the tabs
include('tabs.php');
/// Print the main part of the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->heading(get_string('import_questions','feedback'));
if(isset($importerror->msg) AND is_array($importerror->msg)) {
echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter');
foreach($importerror->msg as $msg) {
echo $msg.'<br />';
}
echo $OUTPUT->box_end();
}
$mform->display();
// echo $OUTPUT->container_start('mdl-align');
// echo $OUTPUT->single_button(new moodle_url('edit.php', array('id'=>$id, 'do_show'=>'templates')), get_string('cancel'));
// echo $OUTPUT->container_end();
echo $OUTPUT->footer();
function feedback_load_xml_data($xmlcontent) {
global $CFG;
require_once($CFG->dirroot.'/lib/xmlize.php');
if(!$xmlcontent = feedback_check_xml_utf8($xmlcontent)) return false;
$data = xmlize($xmlcontent, 1, 'UTF-8');
if(intval($data['FEEDBACK']['@']['VERSION']) != 200701) {
return false;
}
$data = $data['FEEDBACK']['#']['ITEMS'][0]['#']['ITEM'];
return $data;
}
function feedback_import_loaded_data(&$data, $feedbackid){
global $CFG, $DB;
feedback_load_feedback_items();
$deleteolditems = optional_param('deleteolditems', 0, PARAM_INT);
$error = new stdClass();
$error->stat = true;
$error->msg = array();
if(!is_array($data)) {
$error->msg[] = get_string('data_is_not_an_array', 'feedback');
$error->stat = false;
return $error;
}
if($deleteolditems) {
feedback_delete_all_items($feedbackid);
$position = 0;
} else {
//items will be add to the end of the existing items
$position = $DB->count_records('feedback_item', array('feedback'=>$feedbackid));
}
//depend items we are storing temporary in an mapping list array(new id => dependitem)
//we also store a mapping of all items array(oldid => newid)
$dependitemsmap = array();
$itembackup = array();
foreach($data as $item) {
$position++;
//check the typ
$typ = $item['@']['TYPE'];
//check oldtypes first
switch($typ) {
case 'radio':
$typ = 'multichoice';
$oldtyp = 'radio';
break;
case 'dropdown':
$typ = 'multichoice';
$oldtyp = 'dropdown';
break;
case 'check':
$typ = 'multichoice';
$oldtyp = 'check';
break;
case 'radiorated':
$typ = 'multichoicerated';
$oldtyp = 'radiorated';
break;
case 'dropdownrated':
$typ = 'multichoicerated';
$oldtyp = 'dropdownrated';
break;
default:
$oldtyp = $typ;
}
$itemclass = 'feedback_item_'.$typ;
if($typ != 'pagebreak' AND !class_exists($itemclass)) {
$error->stat = false;
$error->msg[] = 'type ('.$typ.') not found';
continue;
}
$itemobj = new $itemclass();
$newitem = new stdClass();
$newitem->feedback = $feedbackid;
$newitem->template = 0;
$newitem->typ = $typ;
$newitem->name = trim($item['#']['ITEMTEXT'][0]['#']);
$newitem->label = trim($item['#']['ITEMLABEL'][0]['#']);
$newitem->options = trim($item['#']['OPTIONS'][0]['#']);
$newitem->presentation = trim($item['#']['PRESENTATION'][0]['#']);
//check old types of radio, check, and so on
switch($oldtyp) {
case 'radio':
$newitem->presentation = 'r>>>>>'.$newitem->presentation;
break;
case 'dropdown':
$newitem->presentation = 'd>>>>>'.$newitem->presentation;
break;
case 'check':
$newitem->presentation = 'c>>>>>'.$newitem->presentation;
break;
case 'radiorated':
$newitem->presentation = 'r>>>>>'.$newitem->presentation;
break;
case 'dropdownrated':
$newitem->presentation = 'd>>>>>'.$newitem->presentation;
break;
}
if(isset($item['#']['DEPENDITEM'][0]['#'])) {
$newitem->dependitem = intval($item['#']['DEPENDITEM'][0]['#']);
}else {
$newitem->dependitem = 0;
}
if(isset($item['#']['DEPENDVALUE'][0]['#'])) {
$newitem->dependvalue = trim($item['#']['DEPENDVALUE'][0]['#']);
}else {
$newitem->dependvalue = '';
}
$olditemid = intval($item['#']['ITEMID'][0]['#']);
if($typ != 'pagebreak') {
$newitem->hasvalue = $itemobj->get_hasvalue();
}else {
$newitem->hasvalue = 0;
}
$newitem->required = intval($item['@']['REQUIRED']);
$newitem->position = $position;
$newid = $DB->insert_record('feedback_item', $newitem);
$itembackup[$olditemid] = $newid;
if($newitem->dependitem) {
$dependitemsmap[$newid] = $newitem->dependitem;
}
}
//remapping the dependency
foreach($dependitemsmap as $key => $dependitem) {
$newitem = $DB->get_record('feedback_item', array('id'=>$key));
$newitem->dependitem = $itembackup[$newitem->dependitem];
$DB->update_record('feedback_item', $newitem);
}
if (!is_array($data)) {
$error->msg[] = get_string('data_is_not_an_array', 'feedback');
$error->stat = false;
return $error; return $error;
} }
function feedback_check_xml_utf8($text) { if ($deleteolditems) {
//find the encoding feedback_delete_all_items($feedbackid);
$searchpattern = '/^\<\?xml.+(encoding=\"([a-z0-9-]*)\").+\?\>/is'; $position = 0;
} else {
if(!preg_match($searchpattern, $text, $match)) return false; //no xml-file //items will be add to the end of the existing items
$position = $DB->count_records('feedback_item', array('feedback'=>$feedbackid));
//$match[0] = \<\? xml ... \?\> (without \)
//$match[1] = encoding="...."
//$match[2] = ISO-8859-1 or so on
if(isset($match[0]) AND !isset($match[1])){ //no encoding given. we assume utf-8
return $text;
}
if(isset($match[0]) AND isset($match[1]) AND isset($match[2])) { //encoding is given in $match[2]
$enc = $match[2];
$textlib = textlib_get_instance();
return $textlib->convert($text, $enc);
}
} }
//depend items we are storing temporary in an mapping list array(new id => dependitem)
//we also store a mapping of all items array(oldid => newid)
$dependitemsmap = array();
$itembackup = array();
foreach ($data as $item) {
$position++;
//check the typ
$typ = $item['@']['TYPE'];
//check oldtypes first
switch($typ) {
case 'radio':
$typ = 'multichoice';
$oldtyp = 'radio';
break;
case 'dropdown':
$typ = 'multichoice';
$oldtyp = 'dropdown';
break;
case 'check':
$typ = 'multichoice';
$oldtyp = 'check';
break;
case 'radiorated':
$typ = 'multichoicerated';
$oldtyp = 'radiorated';
break;
case 'dropdownrated':
$typ = 'multichoicerated';
$oldtyp = 'dropdownrated';
break;
default:
$oldtyp = $typ;
}
$itemclass = 'feedback_item_'.$typ;
if ($typ != 'pagebreak' AND !class_exists($itemclass)) {
$error->stat = false;
$error->msg[] = 'type ('.$typ.') not found';
continue;
}
$itemobj = new $itemclass();
$newitem = new stdClass();
$newitem->feedback = $feedbackid;
$newitem->template = 0;
$newitem->typ = $typ;
$newitem->name = trim($item['#']['ITEMTEXT'][0]['#']);
$newitem->label = trim($item['#']['ITEMLABEL'][0]['#']);
$newitem->options = trim($item['#']['OPTIONS'][0]['#']);
$newitem->presentation = trim($item['#']['PRESENTATION'][0]['#']);
//check old types of radio, check, and so on
switch($oldtyp) {
case 'radio':
$newitem->presentation = 'r>>>>>'.$newitem->presentation;
break;
case 'dropdown':
$newitem->presentation = 'd>>>>>'.$newitem->presentation;
break;
case 'check':
$newitem->presentation = 'c>>>>>'.$newitem->presentation;
break;
case 'radiorated':
$newitem->presentation = 'r>>>>>'.$newitem->presentation;
break;
case 'dropdownrated':
$newitem->presentation = 'd>>>>>'.$newitem->presentation;
break;
}
if (isset($item['#']['DEPENDITEM'][0]['#'])) {
$newitem->dependitem = intval($item['#']['DEPENDITEM'][0]['#']);
} else {
$newitem->dependitem = 0;
}
if (isset($item['#']['DEPENDVALUE'][0]['#'])) {
$newitem->dependvalue = trim($item['#']['DEPENDVALUE'][0]['#']);
} else {
$newitem->dependvalue = '';
}
$olditemid = intval($item['#']['ITEMID'][0]['#']);
if ($typ != 'pagebreak') {
$newitem->hasvalue = $itemobj->get_hasvalue();
} else {
$newitem->hasvalue = 0;
}
$newitem->required = intval($item['@']['REQUIRED']);
$newitem->position = $position;
$newid = $DB->insert_record('feedback_item', $newitem);
$itembackup[$olditemid] = $newid;
if ($newitem->dependitem) {
$dependitemsmap[$newid] = $newitem->dependitem;
}
}
//remapping the dependency
foreach ($dependitemsmap as $key => $dependitem) {
$newitem = $DB->get_record('feedback_item', array('id'=>$key));
$newitem->dependitem = $itembackup[$newitem->dependitem];
$DB->update_record('feedback_item', $newitem);
}
return $error;
}
function feedback_check_xml_utf8($text) {
//find the encoding
$searchpattern = '/^\<\?xml.+(encoding=\"([a-z0-9-]*)\").+\?\>/is';
if (!preg_match($searchpattern, $text, $match)) {
return false; //no xml-file
}
//$match[0] = \<\? xml ... \?\> (without \)
//$match[1] = encoding="...."
//$match[2] = ISO-8859-1 or so on
if (isset($match[0]) AND !isset($match[1])) { //no encoding given. we assume utf-8
return $text;
}
//encoding is given in $match[2]
if (isset($match[0]) AND isset($match[1]) AND isset($match[2])) {
$enc = $match[2];
$textlib = textlib_get_instance();
return $textlib->convert($text, $enc);
}
}

View File

@ -1,28 +1,47 @@
<?php <?php
/** // This file is part of Moodle - http://moodle.org/
* prints the forms to choose an xml-template file to import items //
* // Moodle is free software: you can redistribute it and/or modify
* @author Andreas Grabs // it under the terms of the GNU General Public License as published by
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License // the Free Software Foundation, either version 3 of the License, or
* @package feedback // (at your option) any later version.
*/ //
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* prints the forms to choose an xml-template file to import items
*
* @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback
*/
//It must be included from a Moodle page
if (!defined('MOODLE_INTERNAL')) { if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page die('Direct access to this script is forbidden.');
} }
require_once $CFG->libdir.'/formslib.php'; require_once($CFG->libdir.'/formslib.php');
class feedback_import_form extends moodleform { class feedback_import_form extends moodleform {
function definition() { public function definition() {
global $CFG; global $CFG;
$mform =& $this->_form; $mform =& $this->_form;
//headline //headline
$mform->addElement('header', 'general', ''); $mform->addElement('header', 'general', '');
$strdeleteolditmes = get_string('delete_old_items', 'feedback').' ('.get_string('oldvalueswillbedeleted','feedback').')'; $strdeleteolditmes = get_string('delete_old_items', 'feedback').
$strnodeleteolditmes = get_string('append_new_items', 'feedback').' ('.get_string('oldvaluespreserved','feedback').')'; ' ('.get_string('oldvalueswillbedeleted', 'feedback').')';
$strnodeleteolditmes = get_string('append_new_items', 'feedback').
' ('.get_string('oldvaluespreserved', 'feedback').')';
$deleteolditemsarray = array(); $deleteolditemsarray = array();
$mform->addElement('radio', 'deleteolditems', '', $strdeleteolditmes, true); $mform->addElement('radio', 'deleteolditems', '', $strdeleteolditmes, true);
$mform->addElement('radio', 'deleteolditems', '', $strnodeleteolditmes); $mform->addElement('radio', 'deleteolditems', '', $strnodeleteolditmes);
@ -31,9 +50,12 @@ class feedback_import_form extends moodleform {
// hidden elements // hidden elements
$mform->addElement('hidden', 'id'); $mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT); $mform->setType('id', PARAM_INT);
$mform->addElement('filepicker', 'choosefile', get_string('file'), null, array('maxbytes' => $CFG->maxbytes, 'filetypes' => '*')); $mform->addElement('filepicker',
'choosefile',
get_string('file'),
null,
array('maxbytes' => $CFG->maxbytes, 'filetypes' => '*'));
//-------------------------------------------------------------------------------
// buttons // buttons
$this->add_action_buttons(true, get_string('yes')); $this->add_action_buttons(true, get_string('yes'));

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* prints the overview of all feedbacks included into the current course * prints the overview of all feedbacks included into the current course
@ -43,7 +57,8 @@ echo $OUTPUT->header();
/// Get all the appropriate data /// Get all the appropriate data
if (! $feedbacks = get_all_instances_in_course("feedback", $course)) { if (! $feedbacks = get_all_instances_in_course("feedback", $course)) {
notice(get_string('thereareno', 'moodle', $strfeedbacks), new moodle_url('/course/view.php', array('id'=>$course->id))); $url = new moodle_url('/course/view.php', array('id'=>$course->id));
notice(get_string('thereareno', 'moodle', $strfeedbacks), $url);
die; die;
} }
@ -62,18 +77,18 @@ $strresponses = get_string('responses', 'feedback');
$table = new html_table(); $table = new html_table();
if ($usesections) { if ($usesections) {
if(has_capability('mod/feedback:viewreports', $context)) { if (has_capability('mod/feedback:viewreports', $context)) {
$table->head = array ($strsectionname, $strname, $strresponses); $table->head = array ($strsectionname, $strname, $strresponses);
$table->align = array ("center", "left", 'center'); $table->align = array ("center", "left", 'center');
}else{ } else {
$table->head = array ($strsectionname, $strname); $table->head = array ($strsectionname, $strname);
$table->align = array ("center", "left"); $table->align = array ("center", "left");
} }
} else { } else {
if(has_capability('mod/feedback:viewreports', $context)) { if (has_capability('mod/feedback:viewreports', $context)) {
$table->head = array ($strname, $strresponses); $table->head = array ($strname, $strresponses);
$table->align = array ("left", "center"); $table->align = array ("left", "center");
}else{ } else {
$table->head = array ($strname); $table->head = array ($strname);
$table->align = array ("left"); $table->align = array ("left");
} }
@ -84,8 +99,8 @@ foreach ($feedbacks as $feedback) {
//get the responses of each feedback //get the responses of each feedback
$viewurl = new moodle_url('/mod/feedback/view.php', array('id'=>$feedback->coursemodule)); $viewurl = new moodle_url('/mod/feedback/view.php', array('id'=>$feedback->coursemodule));
if(has_capability('mod/feedback:viewreports', $context)) { if (has_capability('mod/feedback:viewreports', $context)) {
$completedFeedbackCount = intval(feedback_get_completeds_group_count($feedback)); $completed_feedback_count = intval(feedback_get_completeds_group_count($feedback));
} }
$dimmedclass = $feedback->visible ? '' : 'class="dimmed"'; $dimmedclass = $feedback->visible ? '' : 'class="dimmed"';
@ -96,8 +111,8 @@ foreach ($feedbacks as $feedback) {
} else { } else {
$tabledata = array ($link); $tabledata = array ($link);
} }
if(has_capability('mod/feedback:viewreports', $context)) { if (has_capability('mod/feedback:viewreports', $context)) {
$tabledata[] = $completedFeedbackCount; $tabledata[] = $completed_feedback_count;
} }
$table->data[] = $tabledata; $table->data[] = $tabledata;

View File

@ -1,17 +1,31 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
class feedback_captcha_form extends feedback_item_form { class feedback_captcha_form extends feedback_item_form {
var $type = "captcha"; protected $type = "captcha";
public function definition() {
function definition() {
$item = $this->_customdata['item']; $item = $this->_customdata['item'];
$common = $this->_customdata['common']; $common = $this->_customdata['common'];
$positionlist = $this->_customdata['positionlist']; $positionlist = $this->_customdata['positionlist'];
$position = $this->_customdata['position']; $position = $this->_customdata['position'];
$mform =& $this->_form; $mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback')); $mform->addElement('header', 'general', get_string($this->type, 'feedback'));
@ -28,7 +42,7 @@ class feedback_captcha_form extends feedback_item_form {
$mform->addElement('select', $mform->addElement('select',
'presentation', 'presentation',
get_string('count_of_nums', 'feedback').'&nbsp;', get_string('count_of_nums', 'feedback').'&nbsp;',
array_slice(range(0,10),3,10,true)); array_slice(range(0, 10), 3, 10, true));
parent::definition(); parent::definition();
$this->set_data($item); $this->set_data($item);

View File

@ -1,31 +1,47 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') OR die('not allowed'); defined('MOODLE_INTERNAL') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_captcha extends feedback_item_base { class feedback_item_captcha extends feedback_item_base {
var $type = "captcha"; protected $type = "captcha";
var $commonparams; private $commonparams;
var $item_form = false; private $item_form = false;
var $item = false; private $item = false;
var $feedback = false; private $feedback = false;
function init() { public function init() {
} }
function build_editform($item, $feedback, $cm) { public function build_editform($item, $feedback, $cm) {
global $DB; global $DB;
$editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cm->id)); $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cm->id));
//ther are no settings for recaptcha //ther are no settings for recaptcha
if(isset($item->id) AND $item->id > 0) { if (isset($item->id) AND $item->id > 0) {
notice(get_string('there_are_no_settings_for_recaptcha', 'feedback'), $editurl->out()); notice(get_string('there_are_no_settings_for_recaptcha', 'feedback'), $editurl->out());
exit; exit;
} }
//only one recaptcha can be in a feedback //only one recaptcha can be in a feedback
if($DB->record_exists('feedback_item', array('feedback'=>$feedback->id, 'typ'=>$this->type))) { $params = array('feedback' => $feedback->id, 'typ' => $this->type);
if ($DB->record_exists('feedback_item', $params)) {
notice(get_string('only_one_captcha_allowed', 'feedback'), $editurl->out()); notice(get_string('only_one_captcha_allowed', 'feedback'), $editurl->out());
exit; exit;
} }
@ -50,27 +66,27 @@ class feedback_item_captcha extends feedback_item_base {
$this->item->options = ''; $this->item->options = '';
} }
function show_editform() { public function show_editform() {
} }
function is_cancelled() { public function is_cancelled() {
return false; return false;
} }
function get_data() { public function get_data() {
return true; return true;
} }
function save_item() { public function save_item() {
global $DB; global $DB;
if(!$this->item) { if (!$this->item) {
return false; return false;
} }
if(empty($this->item->id)) { if (empty($this->item->id)) {
$this->item->id = $DB->insert_record('feedback_item', $this->item); $this->item->id = $DB->insert_record('feedback_item', $this->item);
}else { } else {
$DB->update_record('feedback_item', $this->item); $DB->update_record('feedback_item', $this->item);
} }
@ -78,20 +94,22 @@ class feedback_item_captcha extends feedback_item_base {
} }
//liefert eine Struktur ->name, ->data = array(mit Antworten) //liefert eine Struktur ->name, ->data = array(mit Antworten)
function get_analysed($item, $groupid = false, $courseid = false) { public function get_analysed($item, $groupid = false, $courseid = false) {
return null; return null;
} }
function get_printval($item, $value) { public function get_printval($item, $value) {
return ''; return '';
} }
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
return $itemnr; return $itemnr;
} }
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) { public function excelprint_item(&$worksheet, $row_offset,
return $rowOffset; $xls_formats, $item,
$groupid, $courseid = false) {
return $row_offset;
} }
/** /**
@ -101,16 +119,17 @@ class feedback_item_captcha extends feedback_item_base {
* @param object $item * @param object $item
* @return void * @return void
*/ */
function print_item_preview($item) { public function print_item_preview($item) {
global $DB; global $DB;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$cmid = 0; $cmid = 0;
$feedbackid = $item->feedback; $feedbackid = $item->feedback;
if($feedbackid > 0) { if ($feedbackid > 0) {
$feedback = $DB->get_record('feedback', array('id'=>$feedbackid)); $feedback = $DB->get_record('feedback', array('id'=>$feedbackid));
if($cm = get_coursemodule_from_instance("feedback", $feedback->id, $feedback->course)) { $cm = get_coursemodule_from_instance("feedback", $feedback->id, $feedback->course);
if ($cm) {
$cmid = $cm->id; $cmid = $cm->id;
} }
} }
@ -134,7 +153,7 @@ class feedback_item_captcha extends feedback_item_base {
* @param bool $highlightrequire * @param bool $highlightrequire
* @return void * @return void
*/ */
function print_item_complete($item, $value = '', $highlightrequire = false) { public function print_item_complete($item, $value = '', $highlightrequire = false) {
global $SESSION, $CFG, $DB, $USER; global $SESSION, $CFG, $DB, $USER;
require_once($CFG->libdir.'/recaptchalib.php'); require_once($CFG->libdir.'/recaptchalib.php');
@ -142,33 +161,38 @@ class feedback_item_captcha extends feedback_item_base {
$cmid = 0; $cmid = 0;
$feedbackid = $item->feedback; $feedbackid = $item->feedback;
if($feedbackid > 0) { if ($feedbackid > 0) {
$feedback = $DB->get_record('feedback', array('id'=>$feedbackid)); $feedback = $DB->get_record('feedback', array('id'=>$feedbackid));
if($cm = get_coursemodule_from_instance("feedback", $feedback->id, $feedback->course)) { $cm = get_coursemodule_from_instance("feedback", $feedback->id, $feedback->course);
if ($cm) {
$cmid = $cm->id; $cmid = $cm->id;
} }
} }
//check if an false value even the value is not required //check if an false value even the value is not required
if($highlightrequire AND !$this->check_value($value, $item)) { if ($highlightrequire AND !$this->check_value($value, $item)) {
$falsevalue = true; $falsevalue = true;
}else { } else {
$falsevalue = false; $falsevalue = false;
} }
if($falsevalue) { if ($falsevalue) {
$highlight = 'missingrequire'; $highlight = 'missingrequire';
}else { } else {
$highlight = ''; $highlight = '';
} }
$requiredmark = '<span class="feedback_required_mark">*</span>'; $requiredmark = '<span class="feedback_required_mark">*</span>';
if(isset($SESSION->feedback->captchacheck) AND $SESSION->feedback->captchacheck == $USER->sesskey AND $value == $USER->sesskey) { if (isset($SESSION->feedback->captchacheck) AND
$SESSION->feedback->captchacheck == $USER->sesskey AND
$value == $USER->sesskey) {
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.'">'; echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') '; echo '('.$item->label.') ';
echo format_text($item->name.$requiredmark, true, false, false); echo format_text($item->name.$requiredmark, true, false, false);
echo '<input type="hidden" value="'.$USER->sesskey.'" name="'.$item->typ.'_'.$item->id.'" />'; $inputname = 'name="'.$item->typ.'_'.$item->id.'"';
echo '<input type="hidden" value="'.$USER->sesskey.'" '.$inputname.' />';
echo '</div>'; echo '</div>';
return; return;
} }
@ -187,19 +211,31 @@ class feedback_item_captcha extends feedback_item_base {
<div class="'.$highlight.'" id="recaptcha_widget" style="display:none"> <div class="'.$highlight.'" id="recaptcha_widget" style="display:none">
<div id="recaptcha_image"></div> <div id="recaptcha_image"></div>
<div class="recaptcha_only_if_incorrect_sol" style="color:red">' . $strincorrectpleasetryagain . '</div> <div class="recaptcha_only_if_incorrect_sol" style="color:red">'.
<span class="recaptcha_only_if_image"><label for="recaptcha_response_field">' . $strenterthewordsabove . $requiredmark. '</label></span> $strincorrectpleasetryagain.
<span class="recaptcha_only_if_audio"><label for="recaptcha_response_field">' . $strenterthenumbersyouhear . '</label></span> '</div>
<span class="recaptcha_only_if_image">
<label for="recaptcha_response_field">'.$strenterthewordsabove.$requiredmark.'</label>
</span>
<span class="recaptcha_only_if_audio">
<label for="recaptcha_response_field">'.$strenterthenumbersyouhear.'</label>
</span>
<input type="text" id="recaptcha_response_field" name="'.$item->typ.'_'.$item->id.'" /> <input type="text" id="recaptcha_response_field" name="'.$item->typ.'_'.$item->id.'" />
<div><a href="javascript:Recaptcha.reload()">' . $strgetanothercaptcha . '</a></div> <div><a href="javascript:Recaptcha.reload()">' . $strgetanothercaptcha . '</a></div>
<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type(\'audio\')">' . $strgetanaudiocaptcha . '</a></div> <div class="recaptcha_only_if_image">
<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type(\'image\')">' . $strgetanimagecaptcha . '</a></div> <a href="javascript:Recaptcha.switch_type(\'audio\')">' . $strgetanaudiocaptcha . '</a>
</div>
<div class="recaptcha_only_if_audio">
<a href="javascript:Recaptcha.switch_type(\'image\')">' . $strgetanimagecaptcha . '</a>
</div>
</div>'; </div>';
//we have to rename the challengefield //we have to rename the challengefield
$captchahtml = recaptcha_get_html($CFG->recaptchapublickey, NULL); if (!empty($CFG->recaptchaprivatekey) AND !empty($CFG->recaptchapublickey)) {
echo $html.$captchahtml; $captchahtml = recaptcha_get_html($CFG->recaptchapublickey, null);
echo $html.$captchahtml;
}
} }
/** /**
@ -210,16 +246,16 @@ class feedback_item_captcha extends feedback_item_base {
* @param string $value * @param string $value
* @return void * @return void
*/ */
function print_item_show_value($item, $value = '') { public function print_item_show_value($item, $value = '') {
global $DB; global $DB;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$cmid = 0; $cmid = 0;
$feedbackid = $item->feedback; $feedbackid = $item->feedback;
if($feedbackid > 0) { if ($feedbackid > 0) {
$feedback = $DB->get_record('feedback', array('id'=>$feedbackid)); $feedback = $DB->get_record('feedback', array('id'=>$feedbackid));
if($cm = get_coursemodule_from_instance("feedback", $feedback->id, $feedback->course)) { if ($cm = get_coursemodule_from_instance("feedback", $feedback->id, $feedback->course)) {
$cmid = $cm->id; $cmid = $cm->id;
} }
} }
@ -234,18 +270,22 @@ class feedback_item_captcha extends feedback_item_base {
} }
function check_value($value, $item) { public function check_value($value, $item) {
global $SESSION, $CFG, $USER; global $SESSION, $CFG, $USER;
require_once($CFG->libdir.'/recaptchalib.php'); require_once($CFG->libdir.'/recaptchalib.php');
//is recaptcha configured in moodle?
if (empty($CFG->recaptchaprivatekey) OR empty($CFG->recaptchapublickey)) {
return true;
}
$challenge = optional_param('recaptcha_challenge_field', '', PARAM_RAW); $challenge = optional_param('recaptcha_challenge_field', '', PARAM_RAW);
if($value == $USER->sesskey AND $challenge == '') { if ($value == $USER->sesskey AND $challenge == '') {
return true; return true;
} }
$remoteip = getremoteaddr(null); $remoteip = getremoteaddr(null);
$response = recaptcha_check_answer($CFG->recaptchaprivatekey, $remoteip, $challenge, $value); $response = recaptcha_check_answer($CFG->recaptchaprivatekey, $remoteip, $challenge, $value);
if($response->is_valid) { if ($response->is_valid) {
$SESSION->feedback->captchacheck = $USER->sesskey; $SESSION->feedback->captchacheck = $USER->sesskey;
return true; return true;
} }
@ -254,7 +294,7 @@ class feedback_item_captcha extends feedback_item_base {
return false; return false;
} }
function create_value($data) { public function create_value($data) {
global $USER; global $USER;
return $USER->sesskey; return $USER->sesskey;
} }
@ -262,22 +302,28 @@ class feedback_item_captcha extends feedback_item_base {
//compares the dbvalue with the dependvalue //compares the dbvalue with the dependvalue
//dbvalue is value stored in the db //dbvalue is value stored in the db
//dependvalue is the value to check //dependvalue is the value to check
function compare_value($item, $dbvalue, $dependvalue) { public function compare_value($item, $dbvalue, $dependvalue) {
if($dbvalue == $dependvalue) { if ($dbvalue == $dependvalue) {
return true; return true;
} }
return false; return false;
} }
function get_presentation($data) { public function get_presentation($data) {
return ''; return '';
} }
function get_hasvalue() { public function get_hasvalue() {
global $CFG;
//is recaptcha configured in moodle?
if (empty($CFG->recaptchaprivatekey) OR empty($CFG->recaptchapublickey)) {
return 0;
}
return 1; return 1;
} }
function can_switch_require() { public function can_switch_require() {
return false; return false;
} }
} }

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once('../../../../config.php'); require_once('../../../../config.php');
@ -20,13 +34,12 @@ if ($id) {
} }
} }
if(!isset($SESSION->feedback->item->captcha)) { if (!isset($SESSION->feedback->item->captcha)) {
print_error('captchanotset', 'feedback'); print_error('captchanotset', 'feedback');
} }
$height = 40; $height = 40;
$charcount = $SESSION->feedback->item->captcha->charcount; $charcount = $SESSION->feedback->item->captcha->charcount;
// $fontfile = $CFG->dirroot.'/mod/feedback/item/captcha/default.ttf';
$fontfile = $CFG->libdir.'/default.ttf'; $fontfile = $CFG->libdir.'/default.ttf';
$ttfbox = imagettfbbox ( 30, 0, $fontfile, 'H' );//the text to measure $ttfbox = imagettfbbox ( 30, 0, $fontfile, 'H' );//the text to measure
@ -36,14 +49,12 @@ $width = $charcount * $charwidth;
$scale = 0.3; $scale = 0.3;
$elipsesize = intval((($width + $height)/2) / 5); $elipsesize = intval((($width + $height)/2) / 5);
$factorX = intval($width * $scale); $factor_x = intval($width * $scale);
$factorY = intval($height * $scale); $factor_y = intval($height * $scale);
//I split the colors in three ranges //I split the colors in three ranges
//given are the max-min-values //given are the max-min-values
//$colors = array(80, 155, 255); $colors = array(array(0, 40), array(50, 200), array(210, 255));
$colors = array(array(0,40),array(50,200),array(210,255));
//shuffle($colors);
list($col_text1, $col_el, $col_text2) = $colors; list($col_text1, $col_el, $col_text2) = $colors;
//if the text is in color_1 so the elipses can be in color_2 or color_3 //if the text is in color_1 so the elipses can be in color_2 or color_3
@ -53,18 +64,15 @@ $textcolnum = rand(1, 3);
//create the numbers to print out //create the numbers to print out
$nums = array(); $nums = array();
for($i = 0; $i < $charcount; $i++) { for ($i = 0; $i < $charcount; $i++) {
$nums[] = rand(0,9); //Ziffern von 0- $nums[] = rand(0, 9); //Ziffern von 0-
} }
// $nums = range(0, 9);
// shuffle($nums);
//to draw enough elipses so I draw 0.2 * width and 0.2 * height //to draw enough elipses so I draw 0.2 * width and 0.2 * height
//we need th colors for that //we need th colors for that
$properties = array(); $properties = array();
for($x = 0; $x < $factorX; $x++) { for ($x = 0; $x < $factor_x; $x++) {
for($y = 0; $y < $factorY; $y++) { for ($y = 0; $y < $factor_y; $y++) {
$propobj = new stdClass(); $propobj = new stdClass();
$propobj->x = intval($x / $scale); $propobj->x = intval($x / $scale);
$propobj->y = intval($y / $scale); $propobj->y = intval($y / $scale);
@ -79,7 +87,7 @@ shuffle($properties);
// create a blank image // create a blank image
$image = imagecreatetruecolor($width, $height); $image = imagecreatetruecolor($width, $height);
$bg = imagecolorallocate($image, 0, 0, 0); $bg = imagecolorallocate($image, 0, 0, 0);
for($i = 0; $i < ($factorX * $factorY); $i++) { for ($i = 0; $i < ($factor_x * $factor_y); $i++) {
$propobj = $properties[$i]; $propobj = $properties[$i];
// choose a color for the ellipse // choose a color for the ellipse
$col_ellipse = imagecolorallocate($image, $propobj->red, $propobj->green, $propobj->blue); $col_ellipse = imagecolorallocate($image, $propobj->red, $propobj->green, $propobj->blue);
@ -88,8 +96,8 @@ for($i = 0; $i < ($factorX * $factorY); $i++) {
} }
$checkchar = ''; $checkchar = '';
for($i = 0; $i < $charcount; $i++) { for ($i = 0; $i < $charcount; $i++) {
$colnum = rand(1,2); $colnum = rand(1, 2);
$textcol = new stdClass(); $textcol = new stdClass();
$textcol->red = get_random_color(${'col_text'.$colnum}[0], ${'col_text'.$colnum}[1]); $textcol->red = get_random_color(${'col_text'.$colnum}[0], ${'col_text'.$colnum}[1]);
$textcol->green = get_random_color(${'col_text'.$colnum}[0], ${'col_text'.$colnum}[1]); $textcol->green = get_random_color(${'col_text'.$colnum}[0], ${'col_text'.$colnum}[1]);
@ -99,7 +107,7 @@ for($i = 0; $i < $charcount; $i++) {
$left_text = $i * $charwidth; $left_text = $i * $charwidth;
$text = $nums[$i]; $text = $nums[$i];
$checkchar .= $text; $checkchar .= $text;
ImageTTFText ($image, 30, $angle_text, $left_text, 35, $color_text, $fontfile, $text); imagettftext($image, 30, $angle_text, $left_text, 35, $color_text, $fontfile, $text);
} }
$SESSION->feedback->item->captcha->checkchar = $checkchar; $SESSION->feedback->item->captcha->checkchar = $checkchar;
@ -114,5 +122,3 @@ function get_random_color($val1 = 0, $val2 = 255) {
return rand($min, $max); return rand($min, $max);
} }

View File

@ -1,51 +1,75 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
abstract class feedback_item_base { abstract class feedback_item_base {
var $type; protected $type;
/** /**
* constructor * constructor
* *
*/ */
function __construct() { public function __construct() {
$this->init(); $this->init();
} }
//this function only can used after the call of build_editform() //this function only can used after the call of build_editform()
function show_editform() { public function show_editform() {
$this->item_form->display(); $this->item_form->display();
} }
function is_cancelled() { public function is_cancelled() {
return $this->item_form->is_cancelled(); return $this->item_form->is_cancelled();
} }
function get_data() { public function get_data() {
if($this->item = $this->item_form->get_data()) { if ($this->item = $this->item_form->get_data()) {
return true; return true;
} }
return false; return false;
} }
abstract function init(); public function value_type() {
abstract function build_editform($item, $feedback, $cm); return PARAM_RAW;
abstract function save_item(); }
abstract function check_value($value, $item);
abstract function create_value($data); public function value_is_array() {
abstract function compare_value($item, $dbvalue, $dependvalue); return false;
abstract function get_presentation($data); }
abstract function get_hasvalue();
abstract function can_switch_require(); abstract public function init();
abstract public function build_editform($item, $feedback, $cm);
abstract public function save_item();
abstract public function check_value($value, $item);
abstract public function create_value($data);
abstract public function compare_value($item, $dbvalue, $dependvalue);
abstract public function get_presentation($data);
abstract public function get_hasvalue();
abstract public function can_switch_require();
/** /**
* @param object $worksheet a reference to the pear_spreadsheet-object * @param object $worksheet a reference to the pear_spreadsheet-object
* @param integer $rowOffset * @param integer $row_offset
* @param object $item the db-object from feedback_item * @param object $item the db-object from feedback_item
* @param integer $groupid * @param integer $groupid
* @param integer $courseid * @param integer $courseid
* @return integer the new rowOffset * @return integer the new row_offset
*/ */
abstract function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false); abstract public function excelprint_item(&$worksheet, $row_offset,
$xls_formats, $item,
$groupid, $courseid = false);
/** /**
* @param $item the db-object from feedback_item * @param $item the db-object from feedback_item
@ -53,16 +77,16 @@ abstract class feedback_item_base {
* @param integer $groupid * @param integer $groupid
* @param integer $courseid * @param integer $courseid
* @return integer the new itemnr * @return integer the new itemnr
*/ */
abstract function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false); abstract public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false);
/** /**
* @param object $item the db-object from feedback_item * @param object $item the db-object from feedback_item
* @param string $value a item-related value from feedback_values * @param string $value a item-related value from feedback_values
* @return string * @return string
*/ */
abstract function get_printval($item, $value); abstract public function get_printval($item, $value);
/** /**
* returns an Array with three values(typ, name, XXX) * returns an Array with three values(typ, name, XXX)
* XXX is also an Array (count of responses on type $this->type) * XXX is also an Array (count of responses on type $this->type)
@ -71,9 +95,9 @@ abstract class feedback_item_base {
* @param $groupid if given * @param $groupid if given
* @param $courseid if given * @param $courseid if given
* @return array * @return array
*/ */
abstract function get_analysed($item, $groupid = false, $courseid = false); abstract public function get_analysed($item, $groupid = false, $courseid = false);
/** /**
* print the item at the edit-page of feedback * print the item at the edit-page of feedback
* *
@ -81,8 +105,8 @@ abstract class feedback_item_base {
* @param object $item * @param object $item
* @return void * @return void
*/ */
abstract function print_item_preview($item); abstract public function print_item_preview($item);
/** /**
* print the item at the complete-page of feedback * print the item at the complete-page of feedback
* *
@ -92,7 +116,7 @@ abstract class feedback_item_base {
* @param bool $highlightrequire * @param bool $highlightrequire
* @return void * @return void
*/ */
abstract function print_item_complete($item, $value = '', $highlightrequire = false); abstract public function print_item_complete($item, $value = '', $highlightrequire = false);
/** /**
* print the item at the complete-page of feedback * print the item at the complete-page of feedback
@ -102,33 +126,55 @@ abstract class feedback_item_base {
* @param string $value * @param string $value
* @return void * @return void
*/ */
abstract function print_item_show_value($item, $value = ''); abstract public function print_item_show_value($item, $value = '');
} }
//a dummy class to realize pagebreaks //a dummy class to realize pagebreaks
class feedback_item_pagebreak extends feedback_item_base { class feedback_item_pagebreak extends feedback_item_base {
var $type = "pagebreak"; protected $type = "pagebreak";
function show_editform() {} public function show_editform() {
function is_cancelled() {} }
function get_data() {} public function is_cancelled() {
function init() {} }
function build_editform($item, $feedback, $cm) {} public function get_data() {
function save_item() {} }
function check_value($value, $item) {} public function init() {
function create_value($data) {} }
function compare_value($item, $dbvalue, $dependvalue) {} public function build_editform($item, $feedback, $cm) {
function get_presentation($data) {} }
function get_hasvalue() {} public function save_item() {
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) {} }
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {} public function check_value($value, $item) {
function get_printval($item, $value) {} }
function get_analysed($item, $groupid = false, $courseid = false) {} public function create_value($data) {
function print_item_preview($item) {} }
function print_item_complete($item, $value = '', $highlightrequire = false) {} public function compare_value($item, $dbvalue, $dependvalue) {
function print_item_show_value($item, $value = '') {} }
function can_switch_require(){} public function get_presentation($data) {
}
public function get_hasvalue() {
}
public function excelprint_item(&$worksheet, $row_offset,
$xls_formats, $item,
$groupid, $courseid = false) {
}
public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
}
public function get_printval($item, $value) {
}
public function get_analysed($item, $groupid = false, $courseid = false) {
}
public function print_item_preview($item) {
}
public function print_item_complete($item, $value = '', $highlightrequire = false) {
}
public function print_item_show_value($item, $value = '') {
}
public function can_switch_require() {
}
} }

View File

@ -1,13 +1,27 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once $CFG->libdir.'/formslib.php'; require_once($CFG->libdir.'/formslib.php');
define('FEEDBACK_ITEM_NAME_TEXTBOX_SIZE', 80); define('FEEDBACK_ITEM_NAME_TEXTBOX_SIZE', 80);
define('FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE', 20); define('FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE', 20);
abstract class feedback_item_form extends moodleform { abstract class feedback_item_form extends moodleform {
function definition() { public function definition() {
$item = $this->_customdata['item']; //the item object $item = $this->_customdata['item']; //the item object
//common is an array like: //common is an array like:
// array('cmid'=>$cm->id, // array('cmid'=>$cm->id,
// 'id'=>isset($item->id) ? $item->id : NULL, // 'id'=>isset($item->id) ? $item->id : NULL,
@ -15,16 +29,16 @@ abstract class feedback_item_form extends moodleform {
// 'items'=>$feedbackitems, // 'items'=>$feedbackitems,
// 'feedback'=>$feedback->id); // 'feedback'=>$feedback->id);
$common = $this->_customdata['common']; $common = $this->_customdata['common'];
//positionlist is an array with possible positions for the item location //positionlist is an array with possible positions for the item location
$positionlist = $this->_customdata['positionlist']; $positionlist = $this->_customdata['positionlist'];
//the current position of the item //the current position of the item
$position = $this->_customdata['position']; $position = $this->_customdata['position'];
$mform =& $this->_form; $mform =& $this->_form;
if($common['items']) { if ($common['items']) {
$mform->addElement('select', $mform->addElement('select',
'dependitem', 'dependitem',
get_string('dependitem', 'feedback').'&nbsp;', get_string('dependitem', 'feedback').'&nbsp;',
@ -35,7 +49,7 @@ abstract class feedback_item_form extends moodleform {
'dependvalue', 'dependvalue',
get_string('dependvalue', 'feedback'), get_string('dependvalue', 'feedback'),
array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255)); array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255));
}else { } else {
$mform->addElement('hidden', 'dependitem', 0); $mform->addElement('hidden', 'dependitem', 0);
$mform->setType('dependitem', PARAM_INT); $mform->setType('dependitem', PARAM_INT);
$mform->addElement('hidden', 'dependvalue', ''); $mform->addElement('hidden', 'dependvalue', '');
@ -47,23 +61,22 @@ abstract class feedback_item_form extends moodleform {
get_string('position', 'feedback').'&nbsp;', get_string('position', 'feedback').'&nbsp;',
$positionlist); $positionlist);
$position_select->setValue($position); $position_select->setValue($position);
$mform->addElement('hidden', 'cmid', $common['cmid']); $mform->addElement('hidden', 'cmid', $common['cmid']);
$mform->setType('cmid', PARAM_INT); $mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'id', $common['id']); $mform->addElement('hidden', 'id', $common['id']);
$mform->setType('id', PARAM_INT); $mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'feedback', $common['feedback']); $mform->addElement('hidden', 'feedback', $common['feedback']);
$mform->setType('feedback', PARAM_INT); $mform->setType('feedback', PARAM_INT);
$mform->addElement('hidden', 'template', 0); $mform->addElement('hidden', 'template', 0);
$mform->setType('template', PARAM_INT); $mform->setType('template', PARAM_INT);
$mform->setType('name', PARAM_RAW); $mform->setType('name', PARAM_RAW);
$mform->setType('label', PARAM_ALPHANUM); $mform->setType('label', PARAM_ALPHANUM);
$mform->addElement('hidden', 'typ', $this->type); $mform->addElement('hidden', 'typ', $this->type);
$mform->setType('typ', PARAM_ALPHA); $mform->setType('typ', PARAM_ALPHA);
@ -74,17 +87,24 @@ abstract class feedback_item_form extends moodleform {
$mform->setType('options', PARAM_ALPHA); $mform->setType('options', PARAM_ALPHA);
$buttonarray = array(); $buttonarray = array();
if(!empty($item->id)){ if (!empty($item->id)) {
$buttonarray[] = &$mform->createElement('submit', 'update_item', get_string('update_item', 'feedback')); $buttonarray[] = &$mform->createElement('submit',
$buttonarray[] = &$mform->createElement('submit', 'clone_item', get_string('save_as_new_item', 'feedback')); 'update_item',
}else{ get_string('update_item', 'feedback'));
$buttonarray[] = &$mform->createElement('submit',
'clone_item',
get_string('save_as_new_item', 'feedback'));
} else {
$mform->addElement('hidden', 'clone_item', 0); $mform->addElement('hidden', 'clone_item', 0);
$mform->setType('clone_item', PARAM_INT); $mform->setType('clone_item', PARAM_INT);
$buttonarray[] = &$mform->createElement('submit', 'save_item', get_string('save_item', 'feedback')); $buttonarray[] = &$mform->createElement('submit',
'save_item',
get_string('save_item', 'feedback'));
} }
$buttonarray[] = &$mform->createElement('cancel'); $buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '&nbsp;', array(' '), false); $mform->addGroup($buttonarray, 'buttonar', '&nbsp;', array(' '), false);
} }
} }

View File

@ -1,17 +1,31 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
class feedback_info_form extends feedback_item_form { class feedback_info_form extends feedback_item_form {
var $type = "info"; protected $type = "info";
public function definition() {
function definition() {
$item = $this->_customdata['item']; $item = $this->_customdata['item'];
$common = $this->_customdata['common']; $common = $this->_customdata['common'];
$positionlist = $this->_customdata['positionlist']; $positionlist = $this->_customdata['positionlist'];
$position = $this->_customdata['position']; $position = $this->_customdata['position'];
$mform =& $this->_form; $mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback')); $mform->addElement('header', 'general', get_string($this->type, 'feedback'));
@ -31,7 +45,10 @@ class feedback_info_form extends feedback_item_form {
$options[1] = get_string('responsetime', 'feedback'); $options[1] = get_string('responsetime', 'feedback');
$options[2] = get_string('course'); $options[2] = get_string('course');
$options[3] = get_string('coursecategory'); $options[3] = get_string('coursecategory');
$this->infotype = &$mform->addElement('select', 'presentation', get_string('infotype', 'feedback'), $options); $this->infotype = &$mform->addElement('select',
'presentation',
get_string('infotype', 'feedback'),
$options);
parent::definition(); parent::definition();
$this->set_data($item); $this->set_data($item);

View File

@ -1,34 +1,49 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') OR die('not allowed'); defined('MOODLE_INTERNAL') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_info extends feedback_item_base { class feedback_item_info extends feedback_item_base {
var $type = "info"; protected $type = "info";
var $commonparams; private $commonparams;
var $item_form; private $item_form;
var $item; private $item;
function init() { public function init() {
} }
function build_editform($item, $feedback, $cm) { public function build_editform($item, $feedback, $cm) {
global $DB, $CFG; global $DB, $CFG;
require_once('info_form.php'); require_once('info_form.php');
//get the lastposition number of the feedback_items //get the lastposition number of the feedback_items
$position = $item->position; $position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){ if ($position == -1) {
$i_formselect_last = $lastposition + 1; $i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1; $i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1; $item->position = $lastposition + 1;
}else { } else {
$i_formselect_last = $lastposition; $i_formselect_last = $lastposition;
$i_formselect_value = $item->position; $i_formselect_value = $item->position;
} }
//the elements for position dropdownlist //the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true); $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
$item->presentation = empty($item->presentation) ? 1 : $item->presentation; $item->presentation = empty($item->presentation) ? 1 : $item->presentation;
$item->required = 0; $item->required = 0;
@ -36,47 +51,51 @@ class feedback_item_info extends feedback_item_base {
//all items for dependitem //all items for dependitem
$feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
$commonparams = array('cmid'=>$cm->id, $commonparams = array('cmid'=>$cm->id,
'id'=>isset($item->id) ? $item->id : NULL, 'id'=>isset($item->id) ? $item->id : null,
'typ'=>$item->typ, 'typ'=>$item->typ,
'items'=>$feedbackitems, 'items'=>$feedbackitems,
'feedback'=>$feedback->id); 'feedback'=>$feedback->id);
//build the form //build the form
$this->item_form = new feedback_info_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position)); $this->item_form = new feedback_info_form('edit_item.php',
array('item'=>$item,
'common'=>$commonparams,
'positionlist'=>$positionlist,
'position' => $position));
} }
//this function only can used after the call of build_editform() //this function only can used after the call of build_editform()
function show_editform() { public function show_editform() {
$this->item_form->display(); $this->item_form->display();
} }
function is_cancelled() { public function is_cancelled() {
return $this->item_form->is_cancelled(); return $this->item_form->is_cancelled();
} }
function get_data() { public function get_data() {
if($this->item = $this->item_form->get_data()) { if ($this->item = $this->item_form->get_data()) {
return true; return true;
} }
return false; return false;
} }
function save_item() { public function save_item() {
global $DB; global $DB;
if(!$item = $this->item_form->get_data()) { if (!$item = $this->item_form->get_data()) {
return false; return false;
} }
if(isset($item->clone_item) AND $item->clone_item) { if (isset($item->clone_item) AND $item->clone_item) {
$item->id = ''; //to clone this item $item->id = ''; //to clone this item
$item->position++; $item->position++;
} }
$item->hasvalue = $this->get_hasvalue(); $item->hasvalue = $this->get_hasvalue();
if(!$item->id) { if (!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item); $item->id = $DB->insert_record('feedback_item', $item);
}else { } else {
$DB->update_record('feedback_item', $item); $DB->update_record('feedback_item', $item);
} }
@ -84,23 +103,22 @@ class feedback_item_info extends feedback_item_base {
} }
//liefert eine Struktur ->name, ->data = array(mit Antworten) //liefert eine Struktur ->name, ->data = array(mit Antworten)
function get_analysed($item, $groupid = false, $courseid = false) { public function get_analysed($item, $groupid = false, $courseid = false) {
$presentation = $item->presentation; $presentation = $item->presentation;
$aVal = null; $analysed_val = null;
$aVal->data = null; $analysed_val->data = null;
$aVal->name = $item->name; $analysed_val->name = $item->name;
//$values = get_records('feedback_value', 'item', $item->id);
$values = feedback_get_group_values($item, $groupid, $courseid); $values = feedback_get_group_values($item, $groupid, $courseid);
if($values) { if ($values) {
$data = array(); $data = array();
$datavalue = new stdClass(); $datavalue = new stdClass();
foreach($values as $value) { foreach ($values as $value) {
switch($presentation) { switch($presentation) {
case 1: case 1:
$datavalue->value = $value->value; $datavalue->value = $value->value;
$datavalue->show = UserDate($datavalue->value); $datavalue->show = userdate($datavalue->value);
break; break;
case 2: case 2:
$datavalue->value = $value->value; $datavalue->value = $value->value;
@ -114,50 +132,54 @@ class feedback_item_info extends feedback_item_base {
$data[] = $datavalue; $data[] = $datavalue;
} }
$aVal->data = $data; $analysed_val->data = $data;
} }
return $aVal; return $analysed_val;
} }
function get_printval($item, $value) { public function get_printval($item, $value) {
if(!isset($value->value)) return ''; if (!isset($value->value)) {
return UserDate($value->value); return '';
}
return userdate($value->value);
} }
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid); $analysed_item = $this->get_analysed($item, $groupid, $courseid);
$data = $analysed_item->data; $data = $analysed_item->data;
if (is_array($data)) { if (is_array($data)) {
echo '<tr><th colspan="2" align="left">'. $itemnr . '&nbsp;('. $item->label .') ' . $item->name .'</th></tr>'; echo '<tr><th colspan="2" align="left">';
$sizeofdata = sizeof($data); echo $itemnr.'&nbsp;('.$item->label.') '.$item->name;
echo '</th></tr>';
$sizeofdata = count($data);
for ($i = 0; $i < $sizeofdata; $i++) { for ($i = 0; $i < $sizeofdata; $i++) {
echo '<tr><td colspan="2" valign="top" align="left">-&nbsp;&nbsp;' . str_replace("\n", '<br />', $data[$i]->show) . '</td></tr>'; echo '<tr><td colspan="2" valign="top" align="left">-&nbsp;&nbsp;';
echo str_replace("\n", '<br />', $data[$i]->show);
echo '</td></tr>';
} }
} }
// return $itemnr;
} }
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) { public function excelprint_item(&$worksheet, $row_offset,
$xls_formats, $item,
$groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid); $analysed_item = $this->get_analysed($item, $groupid, $courseid);
// $worksheet->setFormat("<l><f><ro2><vo><c:green>"); $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2);
$worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2); $worksheet->write_string($row_offset, 1, $item->name, $xls_formats->head2);
$worksheet->write_string($rowOffset, 1, $item->name, $xlsFormats->head2);
$data = $analysed_item->data; $data = $analysed_item->data;
if (is_array($data)) { if (is_array($data)) {
// $worksheet->setFormat("<l><ro2><vo>"); $worksheet->write_string($row_offset, 2, $data[0]->show, $xls_formats->value_bold);
$worksheet->write_string($rowOffset, 2, $data[0]->show, $xlsFormats->value_bold); $row_offset++;
$rowOffset++; $sizeofdata = count($data);
$sizeofdata = sizeof($data);
for ($i = 1; $i < $sizeofdata; $i++) { for ($i = 1; $i < $sizeofdata; $i++) {
// $worksheet->setFormat("<l><vo>"); $worksheet->write_string($row_offset, 2, $data[$i]->show, $xls_formats->default);
$worksheet->write_string($rowOffset, 2, $data[$i]->show, $xlsFormats->default); $row_offset++;
$rowOffset++;
} }
} }
$rowOffset++; $row_offset++;
return $rowOffset; return $row_offset;
} }
/** /**
@ -167,29 +189,52 @@ class feedback_item_info extends feedback_item_base {
* @param object $item * @param object $item
* @return void * @return void
*/ */
function print_item_preview($item) { public function print_item_preview($item) {
global $USER, $DB, $OUTPUT; global $USER, $DB, $OUTPUT;
$align = right_to_left() ? 'right' : 'left';
$align = right_to_left() ? 'right' : 'left';
$presentation = $item->presentation; $presentation = $item->presentation;
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
$feedback = $DB->get_record('feedback', array('id'=>$item->feedback)); if ($item->feedback) {
$course = $DB->get_record('course', array('id'=>$feedback->course)); $courseid = $DB->get_field('feedback', 'course', array('id'=>$item->feedback));
$coursecategory = $DB->get_record('course_categories', array('id'=>$course->category)); } else { // the item must be a template item
$cmid = required_param('id', PARAM_INT);
$courseid = $DB->get_field('course_modules', 'course', array('id'=>$cmid));
}
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
print_error('error');
}
if ($course->id !== SITEID) {
$coursecategory = $DB->get_record('course_categories', array('id'=>$course->category));
} else {
$coursecategory = false;
}
switch($presentation) { switch($presentation) {
case 1: case 1:
$itemvalue = time(); $itemvalue = time();
$itemshowvalue = UserDate($itemvalue); $itemshowvalue = userdate($itemvalue);
break; break;
case 2: case 2:
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$itemvalue = format_string($course->shortname, true, array('context' => $coursecontext)); $itemvalue = format_string($course->shortname,
true,
array('context' => $coursecontext));
$itemshowvalue = $itemvalue; $itemshowvalue = $itemvalue;
break; break;
case 3: case 3:
$itemvalue = format_string($coursecategory->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $coursecategory->id))); if ($coursecategory) {
$itemshowvalue = $itemvalue; $category_context = get_context_instance(CONTEXT_COURSECAT, $coursecategory->id);
$itemvalue = format_string($coursecategory->name,
true,
array('context' => $category_context));
$itemshowvalue = $itemvalue;
} else {
$itemvalue = '';
$itemshowvalue = '';
}
break; break;
} }
@ -197,16 +242,18 @@ class feedback_item_info extends feedback_item_base {
echo '<div class="feedback_item_label_'.$align.'">'; echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') '; echo '('.$item->label.') ';
echo format_text($item->name.$requiredmark, true, false, false); echo format_text($item->name.$requiredmark, true, false, false);
if($item->dependitem) { if ($item->dependitem) {
if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
echo ' <span class="feedback_depend">('.$dependitem->label.'-&gt;'.$item->dependvalue.')</span>'; echo ' <span class="feedback_depend">';
echo '('.$dependitem->label.'-&gt;'.$item->dependvalue.')';
echo '</span>';
} }
} }
echo '</div>'; echo '</div>';
//print the presentation //print the presentation
echo '<div class="feedback_item_presentation_'.$align.'">'; echo '<div class="feedback_item_presentation_'.$align.'">';
echo '<input type="hidden" name="'.$item->typ.'_'.$item->id.'" value="'.$itemvalue.'" />'; echo '<input type="hidden" name="'.$item->typ.'_'.$item->id.'" value="'.$itemvalue.'" />';
echo '<span class="feedback_item_info">'.$itemshowvalue.'</span>'; echo '<span class="feedback_item_info">'.$itemshowvalue.'</span>';
echo '</div>'; echo '</div>';
} }
@ -219,34 +266,52 @@ class feedback_item_info extends feedback_item_base {
* @param bool $highlightrequire * @param bool $highlightrequire
* @return void * @return void
*/ */
function print_item_complete($item, $value = '', $highlightrequire = false) { public function print_item_complete($item, $value = '', $highlightrequire = false) {
global $USER, $DB, $OUTPUT; global $USER, $DB, $OUTPUT;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$presentation = $item->presentation; $presentation = $item->presentation;
if($highlightrequire AND $item->required AND strval($value) == '') { if ($highlightrequire AND $item->required AND strval($value) == '') {
$highlight = ' missingrequire'; $highlight = ' missingrequire';
}else { } else {
$highlight = ''; $highlight = '';
} }
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
$feedback = $DB->get_record('feedback', array('id'=>$item->feedback)); $feedback = $DB->get_record('feedback', array('id'=>$item->feedback));
$course = $DB->get_record('course', array('id'=>$feedback->course)); $course = $DB->get_record('course', array('id'=>$feedback->course));
$coursecategory = $DB->get_record('course_categories', array('id'=>$course->category));
if ($course->id !== SITEID) {
$coursecategory = $DB->get_record('course_categories', array('id'=>$course->category));
} else {
$coursecategory = false;
}
switch($presentation) { switch($presentation) {
case 1: case 1:
$itemvalue = time(); $itemvalue = time();
$itemshowvalue = UserDate($itemvalue); $itemshowvalue = userdate($itemvalue);
break; break;
case 2: case 2:
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$itemvalue = format_string($course->shortname, true, array('context' => $coursecontext)); $itemvalue = format_string($course->shortname,
true,
array('context' => $coursecontext));
$itemshowvalue = $itemvalue; $itemshowvalue = $itemvalue;
break; break;
case 3: case 3:
$itemvalue = format_string($coursecategory->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $coursecategory->id))); if ($coursecategory) {
$itemshowvalue = $itemvalue; $category_context = get_context_instance(CONTEXT_COURSECAT, $coursecategory->id);
$itemvalue = format_string($coursecategory->name,
true,
array('context' => $category_context));
$itemshowvalue = $itemvalue;
} else {
$itemvalue = '';
$itemshowvalue = '';
}
break; break;
} }
@ -257,8 +322,8 @@ class feedback_item_info extends feedback_item_base {
//print the presentation //print the presentation
echo '<div class="feedback_item_presentation_'.$align.'">'; echo '<div class="feedback_item_presentation_'.$align.'">';
echo '<input type="hidden" name="'.$item->typ.'_'.$item->id.'" value="'.$itemvalue.'" />'; echo '<input type="hidden" name="'.$item->typ.'_'.$item->id.'" value="'.$itemvalue.'" />';
echo '<span class="feedback_item_info">'.$itemshowvalue.'</span>'; echo '<span class="feedback_item_info">'.$itemshowvalue.'</span>';
echo '</div>'; echo '</div>';
} }
@ -270,15 +335,15 @@ class feedback_item_info extends feedback_item_base {
* @param string $value * @param string $value
* @return void * @return void
*/ */
function print_item_show_value($item, $value = '') { public function print_item_show_value($item, $value = '') {
global $USER, $DB, $OUTPUT; global $USER, $DB, $OUTPUT;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$presentation = $item->presentation; $presentation = $item->presentation;
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
if($presentation == 1) { if ($presentation == 1) {
$value = $value ? UserDate($value) : '&nbsp;'; $value = $value ? userdate($value) : '&nbsp;';
} }
//print the question and label //print the question and label
@ -293,11 +358,11 @@ class feedback_item_info extends feedback_item_base {
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
function check_value($value, $item) { public function check_value($value, $item) {
return true; return true;
} }
function create_value($data) { public function create_value($data) {
$data = clean_text($data); $data = clean_text($data);
return $data; return $data;
} }
@ -305,22 +370,22 @@ class feedback_item_info extends feedback_item_base {
//compares the dbvalue with the dependvalue //compares the dbvalue with the dependvalue
//the values can be the shortname of a course or the category name //the values can be the shortname of a course or the category name
//the date is not compareable :(. //the date is not compareable :(.
function compare_value($item, $dbvalue, $dependvalue) { public function compare_value($item, $dbvalue, $dependvalue) {
if($dbvalue == $dependvalue) { if ($dbvalue == $dependvalue) {
return true; return true;
} }
return false; return false;
} }
function get_presentation($data) { public function get_presentation($data) {
return $data->infotype; return $data->infotype;
} }
function get_hasvalue() { public function get_hasvalue() {
return 1; return 1;
} }
function can_switch_require() { public function can_switch_require() {
return false; return false;
} }
} }

View File

@ -1,20 +1,34 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
class feedback_label_form extends feedback_item_form { class feedback_label_form extends feedback_item_form {
var $type = "label"; protected $type = "label";
var $area; private $area;
function definition() { public function definition() {
global $CFG; global $CFG;
$item = $this->_customdata['item']; $item = $this->_customdata['item'];
$common = $this->_customdata['common']; $common = $this->_customdata['common'];
$presentationoptions = $this->_customdata['presentationoptions']; $presentationoptions = $this->_customdata['presentationoptions'];
$positionlist = $this->_customdata['positionlist']; $positionlist = $this->_customdata['positionlist'];
$position = $this->_customdata['position']; $position = $this->_customdata['position'];
$context = get_context_instance(CONTEXT_MODULE, $common['cmid']); $context = get_context_instance(CONTEXT_MODULE, $common['cmid']);
$mform =& $this->_form; $mform =& $this->_form;
@ -25,12 +39,11 @@ class feedback_label_form extends feedback_item_form {
$mform->setType('template', PARAM_ALPHA); $mform->setType('template', PARAM_ALPHA);
$mform->addElement('hidden', 'label', '-'); $mform->addElement('hidden', 'label', '-');
$mform->setType('label', PARAM_ALPHA); $mform->setType('label', PARAM_ALPHA);
$mform->addElement('header', 'general', get_string($this->type, 'feedback')); $mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$mform->addElement('editor', 'presentation_editor', '', null, $presentationoptions); $mform->addElement('editor', 'presentation_editor', '', null, $presentationoptions);
$mform->setType('presentation_editor', PARAM_CLEANHTML); $mform->setType('presentation_editor', PARAM_CLEANHTML);
parent::definition(); parent::definition();
$this->set_data($item); $this->set_data($item);

View File

@ -1,57 +1,73 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') OR die('not allowed'); defined('MOODLE_INTERNAL') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
class feedback_item_label extends feedback_item_base { class feedback_item_label extends feedback_item_base {
var $type = "label"; protected $type = "label";
var $presentationoptions = null; private $presentationoptions = null;
var $commonparams; private $commonparams;
var $item_form; private $item_form;
var $context; private $context;
var $item; private $item;
function init() { public function init() {
global $CFG; global $CFG;
$this->presentationoptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext'=>true); $this->presentationoptions = array('maxfiles' => EDITOR_UNLIMITED_FILES,
'trusttext'=>true);
} }
function build_editform($item, $feedback, $cm) { public function build_editform($item, $feedback, $cm) {
global $DB, $CFG; global $DB, $CFG;
require_once('label_form.php'); require_once('label_form.php');
//get the lastposition number of the feedback_items //get the lastposition number of the feedback_items
$position = $item->position; $position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){ if ($position == -1) {
$i_formselect_last = $lastposition + 1; $i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1; $i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1; $item->position = $lastposition + 1;
}else { } else {
$i_formselect_last = $lastposition; $i_formselect_last = $lastposition;
$i_formselect_value = $item->position; $i_formselect_value = $item->position;
} }
//the elements for position dropdownlist //the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true); $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
//all items for dependitem //all items for dependitem
$feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
$commonparams = array('cmid'=>$cm->id, $commonparams = array('cmid'=>$cm->id,
'id'=>isset($item->id) ? $item->id : NULL, 'id'=>isset($item->id) ? $item->id : null,
'typ'=>$item->typ, 'typ'=>$item->typ,
'items'=>$feedbackitems, 'items'=>$feedbackitems,
'feedback'=>$feedback->id); 'feedback'=>$feedback->id);
$this->context = get_context_instance(CONTEXT_MODULE, $cm->id); $this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
//preparing the editor for new file-api //preparing the editor for new file-api
$item->presentationformat = FORMAT_HTML; $item->presentationformat = FORMAT_HTML;
$item->presentationtrust = 1; $item->presentationtrust = 1;
// Append editor context to presentation options, giving preference to existing context. // Append editor context to presentation options, giving preference to existing context.
$this->presentationoptions = array_merge(array('context' => $this->context), $this->presentationoptions); $this->presentationoptions = array_merge(array('context' => $this->context),
$this->presentationoptions);
$item = file_prepare_standard_editor($item, $item = file_prepare_standard_editor($item,
'presentation', //name of the form element 'presentation', //name of the form element
@ -62,33 +78,39 @@ class feedback_item_label extends feedback_item_base {
$item->id); $item->id);
//build the form //build the form
$this->item_form = new feedback_label_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position, 'presentationoptions'=>$this->presentationoptions)); $customdata = array('item' => $item,
'common' => $commonparams,
'positionlist' => $positionlist,
'position' => $position,
'presentationoptions' => $this->presentationoptions);
$this->item_form = new feedback_label_form('edit_item.php', $customdata);
} }
//this function only can used after the call of build_editform() //this function only can used after the call of build_editform()
function show_editform() { public function show_editform() {
$this->item_form->display(); $this->item_form->display();
} }
function is_cancelled() { public function is_cancelled() {
return $this->item_form->is_cancelled(); return $this->item_form->is_cancelled();
} }
function get_data() { public function get_data() {
if($this->item = $this->item_form->get_data()) { if ($this->item = $this->item_form->get_data()) {
return true; return true;
} }
return false; return false;
} }
function save_item() { public function save_item() {
global $DB; global $DB;
if(!$item = $this->item_form->get_data()) { if (!$item = $this->item_form->get_data()) {
return false; return false;
} }
if(isset($item->clone_item) AND $item->clone_item) { if (isset($item->clone_item) AND $item->clone_item) {
$item->id = ''; //to clone this item $item->id = ''; //to clone this item
$item->position++; $item->position++;
} }
@ -96,9 +118,9 @@ class feedback_item_label extends feedback_item_base {
$item->presentation = ''; $item->presentation = '';
$item->hasvalue = $this->get_hasvalue(); $item->hasvalue = $this->get_hasvalue();
if(!$item->id) { if (!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item); $item->id = $DB->insert_record('feedback_item', $item);
}else { } else {
$DB->update_record('feedback_item', $item); $DB->update_record('feedback_item', $item);
} }
@ -115,21 +137,21 @@ class feedback_item_label extends feedback_item_base {
return $DB->get_record('feedback_item', array('id'=>$item->id)); return $DB->get_record('feedback_item', array('id'=>$item->id));
} }
function print_item($item){ public function print_item($item) {
global $DB, $CFG; global $DB, $CFG;
require_once($CFG->libdir . '/filelib.php'); require_once($CFG->libdir . '/filelib.php');
//is the item a template? //is the item a template?
if(!$item->feedback AND $item->template) { if (!$item->feedback AND $item->template) {
$template = $DB->get_record('feedback_template', array('id'=>$item->template)); $template = $DB->get_record('feedback_template', array('id'=>$item->template));
if($template->ispublic) { if ($template->ispublic) {
$context = get_system_context(); $context = get_system_context();
}else { } else {
$context = get_context_instance(CONTEXT_COURSE, $template->course); $context = get_context_instance(CONTEXT_COURSE, $template->course);
} }
$filearea = 'template'; $filearea = 'template';
}else { } else {
$cm = get_coursemodule_from_instance('feedback', $item->feedback); $cm = get_coursemodule_from_instance('feedback', $item->feedback);
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
$filearea = 'item'; $filearea = 'item';
@ -138,7 +160,13 @@ class feedback_item_label extends feedback_item_base {
$item->presentationformat = FORMAT_HTML; $item->presentationformat = FORMAT_HTML;
$item->presentationtrust = 1; $item->presentationtrust = 1;
$output = file_rewrite_pluginfile_urls($item->presentation, 'pluginfile.php', $context->id, 'mod_feedback', $filearea, $item->id); $output = file_rewrite_pluginfile_urls($item->presentation,
'pluginfile.php',
$context->id,
'mod_feedback',
$filearea,
$item->id);
echo format_text($output, FORMAT_HTML, array('overflowdiv'=>true)); echo format_text($output, FORMAT_HTML, array('overflowdiv'=>true));
} }
@ -149,12 +177,14 @@ class feedback_item_label extends feedback_item_base {
* @param object $item * @param object $item
* @return void * @return void
*/ */
function print_item_preview($item) { public function print_item_preview($item) {
global $OUTPUT, $DB; global $OUTPUT, $DB;
if($item->dependitem) { if ($item->dependitem) {
if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
echo ' <span class="feedback_depend">('.$dependitem->label.'-&gt;'.$item->dependvalue.')</span>'; echo ' <span class="feedback_depend">';
echo '('.$dependitem->label.'-&gt;'.$item->dependvalue.')';
echo '</span>';
} }
} }
$this->print_item($item); $this->print_item($item);
@ -169,7 +199,7 @@ class feedback_item_label extends feedback_item_base {
* @param bool $highlightrequire * @param bool $highlightrequire
* @return void * @return void
*/ */
function print_item_complete($item, $value = '', $highlightrequire = false) { public function print_item_complete($item, $value = '', $highlightrequire = false) {
$this->print_item($item); $this->print_item($item);
} }
@ -181,58 +211,62 @@ class feedback_item_label extends feedback_item_base {
* @param string $value * @param string $value
* @return void * @return void
*/ */
function print_item_show_value($item, $value = '') { public function print_item_show_value($item, $value = '') {
$this->print_item($item); $this->print_item($item);
} }
function create_value($data) { public function create_value($data) {
return false; return false;
} }
function compare_value($item, $dbvalue, $dependvalue) { public function compare_value($item, $dbvalue, $dependvalue) {
return false; return false;
} }
//used by create_item and update_item functions, //used by create_item and update_item functions,
//when provided $data submitted from feedback_show_edit //when provided $data submitted from feedback_show_edit
function get_presentation($data) { public function get_presentation($data) {
// $context = get_context_instance(CONTEXT_MODULE, $data->cmid);
// $presentation = new stdClass();
// $presentation->id = null;
// $presentation->definition = '';
// $presentation->format = FORMAT_HTML;
// $draftid_editor = file_get_submitted_draft_itemid('presentation');
// $currenttext = file_prepare_draft_area($draftid_editor, $context->id, 'mod_feedback', 'item_label', $presentation->id, array('subdirs'=>true), $presentation->definition);
// $presentation->entry = array('text'=>$currenttext, 'format'=>$presentation->format, 'itemid'=>$draftid_editor);
// return $data->presentation;
} }
function postupdate($item) { public function postupdate($item) {
global $DB; global $DB;
$context = get_context_instance(CONTEXT_MODULE, $item->cmid); $context = get_context_instance(CONTEXT_MODULE, $item->cmid);
$item = file_postupdate_standard_editor($item, 'presentation', $this->presentationoptions, $context, 'mod_feedback', 'item', $item->id); $item = file_postupdate_standard_editor($item,
'presentation',
$this->presentationoptions,
$context,
'mod_feedback',
'item',
$item->id);
// $item = new stdClass();
// $item->id = $data->id
$DB->update_record('feedback_item', $item); $DB->update_record('feedback_item', $item);
return $item->id; return $item->id;
} }
function get_hasvalue() { public function get_hasvalue() {
return 0; return 0;
} }
function can_switch_require() { public function can_switch_require() {
return false; return false;
} }
function check_value($value, $item) {} public function check_value($value, $item) {
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) {} }
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {}
function get_printval($item, $value) {} public function excelprint_item(&$worksheet,
function get_analysed($item, $groupid = false, $courseid = false) {} $row_offset,
$xls_formats,
$item,
$groupid,
$courseid = false) {
}
public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
}
public function get_printval($item, $value) {
}
public function get_analysed($item, $groupid = false, $courseid = false) {
}
} }

View File

@ -1,4 +1,19 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') OR die('not allowed'); defined('MOODLE_INTERNAL') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
@ -9,32 +24,32 @@ define('FEEDBACK_MULTICHOICE_IGNOREEMPTY', 'i');
define('FEEDBACK_MULTICHOICE_HIDENOSELECT', 'h'); define('FEEDBACK_MULTICHOICE_HIDENOSELECT', 'h');
class feedback_item_multichoice extends feedback_item_base { class feedback_item_multichoice extends feedback_item_base {
var $type = "multichoice"; protected $type = "multichoice";
var $commonparams; private $commonparams;
var $item_form; private $item_form;
var $item; private $item;
function init() { public function init() {
} }
function build_editform($item, $feedback, $cm) { public function build_editform($item, $feedback, $cm) {
global $DB, $CFG; global $DB, $CFG;
require_once('multichoice_form.php'); require_once('multichoice_form.php');
//get the lastposition number of the feedback_items //get the lastposition number of the feedback_items
$position = $item->position; $position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){ if ($position == -1) {
$i_formselect_last = $lastposition + 1; $i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1; $i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1; $item->position = $lastposition + 1;
}else { } else {
$i_formselect_last = $lastposition; $i_formselect_last = $lastposition;
$i_formselect_value = $item->position; $i_formselect_value = $item->position;
} }
//the elements for position dropdownlist //the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true); $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
$item->presentation = empty($item->presentation) ? '' : $item->presentation; $item->presentation = empty($item->presentation) ? '' : $item->presentation;
$info = $this->get_info($item); $info = $this->get_info($item);
@ -45,39 +60,45 @@ class feedback_item_multichoice extends feedback_item_base {
//all items for dependitem //all items for dependitem
$feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
$commonparams = array('cmid'=>$cm->id, $commonparams = array('cmid'=>$cm->id,
'id'=>isset($item->id) ? $item->id : NULL, 'id'=>isset($item->id) ? $item->id : null,
'typ'=>$item->typ, 'typ'=>$item->typ,
'items'=>$feedbackitems, 'items'=>$feedbackitems,
'feedback'=>$feedback->id); 'feedback'=>$feedback->id);
//build the form //build the form
$this->item_form = new feedback_multichoice_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position, 'info'=>$info)); $customdata = array('item' => $item,
'common' => $commonparams,
'positionlist' => $positionlist,
'position' => $position,
'info' => $info);
$this->item_form = new feedback_multichoice_form('edit_item.php', $customdata);
} }
//this function only can used after the call of build_editform() //this function only can used after the call of build_editform()
function show_editform() { public function show_editform() {
$this->item_form->display(); $this->item_form->display();
} }
function is_cancelled() { public function is_cancelled() {
return $this->item_form->is_cancelled(); return $this->item_form->is_cancelled();
} }
function get_data() { public function get_data() {
if($this->item = $this->item_form->get_data()) { if ($this->item = $this->item_form->get_data()) {
return true; return true;
} }
return false; return false;
} }
function save_item() { public function save_item() {
global $DB; global $DB;
if(!$item = $this->item_form->get_data()) { if (!$item = $this->item_form->get_data()) {
return false; return false;
} }
if(isset($item->clone_item) AND $item->clone_item) { if (isset($item->clone_item) AND $item->clone_item) {
$item->id = ''; //to clone this item $item->id = ''; //to clone this item
$item->position++; $item->position++;
} }
@ -86,9 +107,9 @@ class feedback_item_multichoice extends feedback_item_base {
$this->set_hidenoselect($item, $item->hidenoselect); $this->set_hidenoselect($item, $item->hidenoselect);
$item->hasvalue = $this->get_hasvalue(); $item->hasvalue = $this->get_hasvalue();
if(!$item->id) { if (!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item); $item->id = $DB->insert_record('feedback_item', $item);
}else { } else {
$DB->update_record('feedback_item', $item); $DB->update_record('feedback_item', $item);
} }
@ -96,30 +117,32 @@ class feedback_item_multichoice extends feedback_item_base {
} }
//liefert ein eindimensionales Array mit drei Werten(typ, name, XXX) //gets an array with three values(typ, name, XXX)
//XXX ist ein eindimensionales Array (anzahl der Antworten bei Typ Radio) Jedes Element ist eine Struktur (answertext, answercount) //XXX is an object with answertext, answercount and quotient
function get_analysed($item, $groupid = false, $courseid = false) { public function get_analysed($item, $groupid = false, $courseid = false) {
$info = $this->get_info($item); $info = $this->get_info($item);
$analysedItem = array(); $analysed_item = array();
$analysedItem[] = $item->typ; $analysed_item[] = $item->typ;
$analysedItem[] = $item->name; $analysed_item[] = $item->name;
//die moeglichen Antworten extrahieren
//get the possible answers
$answers = null; $answers = null;
// $presentation = '';
// @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info
$answers = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); $answers = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
if(!is_array($answers)) return null; if (!is_array($answers)) {
return null;
}
//die Werte holen //get the values
$values = feedback_get_group_values($item, $groupid, $courseid, $this->ignoreempty($item)); $values = feedback_get_group_values($item, $groupid, $courseid, $this->ignoreempty($item));
if(!$values) return null; if (!$values) {
//schleife ueber den Werten und ueber die Antwortmoeglichkeiten return null;
}
$analysedAnswer = array(); //get answertext, answercount and quotient for each answer
if($info->subtype == 'c') { $analysed_answer = array();
$sizeofanswers = sizeof($answers); if ($info->subtype == 'c') {
$sizeofanswers = count($answers);
for ($i = 1; $i <= $sizeofanswers; $i++) { for ($i = 1; $i <= $sizeofanswers; $i++) {
$ans = null; $ans = null;
$ans->answertext = $answers[$i-1]; $ans->answertext = $answers[$i-1];
@ -129,15 +152,15 @@ class feedback_item_multichoice extends feedback_item_base {
$vallist = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value->value); $vallist = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value->value);
foreach ($vallist as $val) { foreach ($vallist as $val) {
if ($val == $i) { if ($val == $i) {
$ans->answercount++; $ans->answercount++;
} }
} }
} }
$ans->quotient = $ans->answercount / sizeof($values); $ans->quotient = $ans->answercount / count($values);
$analysedAnswer[] = $ans; $analysed_answer[] = $ans;
} }
}else { } else {
$sizeofanswers = sizeof($answers); $sizeofanswers = count($answers);
for ($i = 1; $i <= $sizeofanswers; $i++) { for ($i = 1; $i <= $sizeofanswers; $i++) {
$ans = null; $ans = null;
$ans->answertext = $answers[$i-1]; $ans->answertext = $answers[$i-1];
@ -148,15 +171,15 @@ class feedback_item_multichoice extends feedback_item_base {
$ans->answercount++; $ans->answercount++;
} }
} }
$ans->quotient = $ans->answercount / sizeof($values); $ans->quotient = $ans->answercount / count($values);
$analysedAnswer[] = $ans; $analysed_answer[] = $ans;
} }
} }
$analysedItem[] = $analysedAnswer; $analysed_item[] = $analysed_answer;
return $analysedItem; return $analysed_item;
} }
function get_printval($item, $value) { public function get_printval($item, $value) {
$info = $this->get_info($item); $info = $this->get_info($item);
$printval = ''; $printval = '';
@ -165,14 +188,12 @@ class feedback_item_multichoice extends feedback_item_base {
return $printval; return $printval;
} }
// @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info
$presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
if ($info->subtype == 'c') { if ($info->subtype == 'c') {
$vallist = array_values(explode (FEEDBACK_MULTICHOICE_LINE_SEP, $value->value)); $vallist = array_values(explode (FEEDBACK_MULTICHOICE_LINE_SEP, $value->value));
$sizeofvallist = sizeof($vallist); $sizeofvallist = count($vallist);
$sizeofpresentation = sizeof($presentation); $sizeofpresentation = count($presentation);
for ($i = 0; $i < $sizeofvallist; $i++) { for ($i = 0; $i < $sizeofvallist; $i++) {
for ($k = 0; $k < $sizeofpresentation; $k++) { for ($k = 0; $k < $sizeofpresentation; $k++) {
if ($vallist[$i] == ($k + 1)) {//Die Werte beginnen bei 1, das Array aber mit 0 if ($vallist[$i] == ($k + 1)) {//Die Werte beginnen bei 1, das Array aber mit 0
@ -183,8 +204,8 @@ class feedback_item_multichoice extends feedback_item_base {
} }
} else { } else {
$index = 1; $index = 1;
foreach($presentation as $pres){ foreach ($presentation as $pres) {
if ($value->value == $index){ if ($value->value == $index) {
$printval = $pres; $printval = $pres;
break; break;
} }
@ -194,61 +215,83 @@ class feedback_item_multichoice extends feedback_item_base {
return $printval; return $printval;
} }
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
$sep_dec = get_string('separator_decimal', 'feedback'); $sep_dec = get_string('separator_decimal', 'feedback');
if(substr($sep_dec, 0, 2) == '[['){ if (substr($sep_dec, 0, 2) == '[[') {
$sep_dec = FEEDBACK_DECIMAL; $sep_dec = FEEDBACK_DECIMAL;
} }
$sep_thous = get_string('separator_thousand', 'feedback'); $sep_thous = get_string('separator_thousand', 'feedback');
if(substr($sep_thous, 0, 2) == '[['){ if (substr($sep_thous, 0, 2) == '[[') {
$sep_thous = FEEDBACK_THOUSAND; $sep_thous = FEEDBACK_THOUSAND;
} }
$analysedItem = $this->get_analysed($item, $groupid, $courseid); $analysed_item = $this->get_analysed($item, $groupid, $courseid);
if($analysedItem) { if ($analysed_item) {
// $itemnr++; $itemname = $analysed_item[1];
$itemname = $analysedItem[1]; echo '<tr><th colspan="2" align="left">';
echo '<tr><th colspan="2" align="left">'. $itemnr . '&nbsp;('. $item->label .') ' . $itemname .'</th></tr>'; echo $itemnr.'&nbsp;('.$item->label.') '.$itemname;
$analysedVals = $analysedItem[2]; echo '</th></tr>';
$analysed_vals = $analysed_item[2];
$pixnr = 0; $pixnr = 0;
foreach($analysedVals as $val) { foreach ($analysed_vals as $val) {
$intvalue = $pixnr % 10; $intvalue = $pixnr % 10;
$pix = "pics/$intvalue.gif"; $pix = "pics/$intvalue.gif";
$pixnr++; $pixnr++;
$pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH); $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
$quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous);
echo '<tr><td align="left" valign="top">-&nbsp;&nbsp;' . trim($val->answertext) . ':</td><td align="left" style="width: '.FEEDBACK_MAX_PIX_LENGTH.'"><img alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />&nbsp;' . $val->answercount . (($val->quotient > 0)?'&nbsp;('. $quotient . '&nbsp;%)':'').'</td></tr>'; $str_quotient = '';
if ($val->quotient > 0) {
$str_quotient = '&nbsp;('. $quotient . '&nbsp;%)';
}
echo '<tr>';
echo '<td align="left" valign="top">
-&nbsp;&nbsp;'.trim($val->answertext).':
</td>
<td align="left" style="width:'.FEEDBACK_MAX_PIX_LENGTH.';">
<img alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />
&nbsp;'.$val->answercount.$str_quotient.'
</td>';
echo '</tr>';
} }
} }
// return $itemnr;
} }
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) { public function excelprint_item(&$worksheet, $row_offset,
$xls_formats, $item,
$groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid); $analysed_item = $this->get_analysed($item, $groupid, $courseid);
$data = $analysed_item[2]; $data = $analysed_item[2];
// $worksheet->setFormat("<l><f><ro2><vo><c:green>");
//frage schreiben //frage schreiben
$worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2); $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2);
$worksheet->write_string($rowOffset, 1, $analysed_item[1], $xlsFormats->head2); $worksheet->write_string($row_offset, 1, $analysed_item[1], $xls_formats->head2);
if (is_array($data)) { if (is_array($data)) {
$sizeofdata = sizeof($data); $sizeofdata = count($data);
for ($i = 0; $i < $sizeofdata; $i++) { for ($i = 0; $i < $sizeofdata; $i++) {
$aData = $data[$i]; $analysed_data = $data[$i];
// $worksheet->setFormat("<l><f><ro2><vo><c:blue>"); $worksheet->write_string($row_offset,
$worksheet->write_string($rowOffset, $i + 2, trim($aData->answertext), $xlsFormats->head2); $i + 2,
trim($analysed_data->answertext),
$xls_formats->head2);
// $worksheet->setFormat("<l><vo>"); $worksheet->write_number($row_offset + 1,
$worksheet->write_number($rowOffset + 1, $i + 2, $aData->answercount, $xlsFormats->default); $i + 2,
// $worksheet->setFormat("<l><f><vo><pr>"); $analysed_data->answercount,
$worksheet->write_number($rowOffset + 2, $i + 2, $aData->quotient, $xlsFormats->procent); $xls_formats->default);
$worksheet->write_number($row_offset + 2,
$i + 2,
$analysed_data->quotient,
$xls_formats->procent);
} }
} }
$rowOffset += 3; $row_offset += 3;
return $rowOffset; return $row_offset;
} }
/** /**
@ -258,25 +301,27 @@ class feedback_item_multichoice extends feedback_item_base {
* @param object $item * @param object $item
* @return void * @return void
*/ */
function print_item_preview($item) { public function print_item_preview($item) {
global $OUTPUT, $DB; global $OUTPUT, $DB;
$info = $this->get_info($item); $info = $this->get_info($item);
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
$str_required_mark = '<span class="feedback_required_mark">*</span>';
//test if required and no value is set so we have to mark this item //test if required and no value is set so we have to mark this item
//we have to differ check and the other subtypes //we have to differ check and the other subtypes
$requiredmark = ($item->required == 1) ? '<span class="feedback_required_mark">*</span>' : ''; $requiredmark = ($item->required == 1) ? $str_required_mark : '';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.'">'; echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') '; echo '('.$item->label.') ';
echo format_text($item->name.$requiredmark, true, false, false); echo format_text($item->name.$requiredmark, true, false, false);
if($item->dependitem) { if ($item->dependitem) {
if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
echo ' <span class="feedback_depend">('.$dependitem->label.'-&gt;'.$item->dependvalue.')</span>'; echo ' <span class="feedback_depend">';
echo '('.$dependitem->label.'-&gt;'.$item->dependvalue.')';
echo '</span>';
} }
} }
echo '</div>'; echo '</div>';
@ -286,23 +331,30 @@ class feedback_item_multichoice extends feedback_item_base {
$index = 1; $index = 1;
$checked = ''; $checked = '';
echo '<ul>'; echo '<ul>';
if($info->horizontal) { if ($info->horizontal) {
$hv = 'h'; $hv = 'h';
}else { } else {
$hv = 'v'; $hv = 'v';
} }
if($info->subtype == 'r' AND !$this->hidenoselect($item)) { if ($info->subtype == 'r' AND !$this->hidenoselect($item)) {
//print the "not_selected" item on radiobuttons //print the "not_selected" item on radiobuttons
?> ?>
<li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
<span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
<input type="radio" name="<?php echo $item->typ . '_' . $item->id ;?>" id="<?php echo $item->typ . '_' . $item->id.'_xxx';?>" value="" checked="checked" /> <?php
</span> echo '<input type="radio" '.
<span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> 'name="'.$item->typ.'_'.$item->id.'[]" '.
<label for="<?php echo $item->typ . '_' . $item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?>&nbsp;</label> 'id="'.$item->typ.'_'.$item->id.'_xxx" '.
</span> 'value="" checked="checked" />';
</li> ?>
</span>
<span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
<label for="<?php echo $item->typ . '_' . $item->id.'_xxx';?>">
<?php print_string('not_selected', 'feedback');?>&nbsp;
</label>
</span>
</li>
<?php <?php
} }
@ -330,36 +382,40 @@ class feedback_item_multichoice extends feedback_item_base {
* @param bool $highlightrequire * @param bool $highlightrequire
* @return void * @return void
*/ */
function print_item_complete($item, $value = '', $highlightrequire = false) { public function print_item_complete($item, $value = null, $highlightrequire = false) {
global $OUTPUT; global $OUTPUT;
$info = $this->get_info($item); $info = $this->get_info($item);
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
if ($value == null) {
$value = array();
}
$presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
$str_required_mark = '<span class="feedback_required_mark">*</span>';
//test if required and no value is set so we have to mark this item //test if required and no value is set so we have to mark this item
//we have to differ check and the other subtypes //we have to differ check and the other subtypes
if($info->subtype == 'c') { // if ($info->subtype == 'c') {
if (is_array($value)) { if (is_array($value)) {
$values = $value; $values = $value;
}else { } else {
$values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value); $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value);
} }
if($highlightrequire AND $item->required AND $values[0] == '') { $highlight = '';
$highlight = ' missingrequire'; if ($highlightrequire AND $item->required) {
}else { if (count($values) == 0 OR $values[0] == '' OR $values[0] == 0) {
$highlight = ''; $highlight = ' missingrequire';
}
} }
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1) ? $str_required_mark : '';
}else { // } else {
if($highlightrequire AND $item->required AND intval($value) <= 0) { // if ($highlightrequire AND $item->required AND intval($value) <= 0) {
$highlight = ' missingrequire'; // $highlight = ' missingrequire';
}else { // } else {
$highlight = ''; // $highlight = '';
} // }
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; // $requiredmark = ($item->required == 1) ? $str_required_mark : '';
} // }
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.$highlight.'">'; echo '<div class="feedback_item_label_'.$align.$highlight.'">';
@ -370,20 +426,34 @@ class feedback_item_multichoice extends feedback_item_base {
echo '<div class="feedback_item_presentation_'.$align.$highlight.'">'; echo '<div class="feedback_item_presentation_'.$align.$highlight.'">';
echo '<ul>'; echo '<ul>';
if($info->horizontal) { if ($info->horizontal) {
$hv = 'h'; $hv = 'h';
}else { } else {
$hv = 'v'; $hv = 'v';
} }
//print the "not_selected" item on radiobuttons //print the "not_selected" item on radiobuttons
if($info->subtype == 'r' AND !$this->hidenoselect($item)) { if ($info->subtype == 'r' AND !$this->hidenoselect($item)) {
?> ?>
<li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
<span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
<input type="radio" name="<?php echo $item->typ.'_'.$item->id ;?>" id="<?php echo $item->typ . '_' . $item->id.'_xxx';?>" value="" <?php echo $value ? '' : 'checked="checked"';?> /> <?php
$checked = '';
// if (!$value) {
// $checked = 'checked="checked"';
// }
if (count($values) == 0 OR $values[0] == '' OR $values[0] == 0) {
$checked = 'checked="checked"';
}
echo '<input type="radio" '.
'name="'.$item->typ.'_'.$item->id.'[]" '.
'id="'.$item->typ.'_'.$item->id.'_xxx" '.
'value="" '.$checked.' />';
?>
</span> </span>
<span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
<label for="<?php echo $item->typ.'_'.$item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?>&nbsp;</label> <label for="<?php echo $item->typ.'_'.$item->id.'_xxx';?>">
<?php print_string('not_selected', 'feedback');?>&nbsp;
</label>
</span> </span>
</li> </li>
<?php <?php
@ -412,25 +482,29 @@ class feedback_item_multichoice extends feedback_item_base {
* @param string $value * @param string $value
* @return void * @return void
*/ */
function print_item_show_value($item, $value = '') { public function print_item_show_value($item, $value = null) {
global $OUTPUT; global $OUTPUT;
$info = $this->get_info($item); $info = $this->get_info($item);
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); if ($value == null) {
$value = array();
}
$presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
//test if required and no value is set so we have to mark this item //test if required and no value is set so we have to mark this item
//we have to differ check and the other subtypes //we have to differ check and the other subtypes
if($info->subtype == 'c') { if ($info->subtype == 'c') {
if (is_array($value)) { if (is_array($value)) {
$values = $value; $values = $value;
}else { } else {
$values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value); $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value);
} }
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; }
}else { $requiredmark = '';
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; if ($item->required == 1) {
$requiredmark = '<span class="feedback_required_mark">*</span>';
} }
//print the question and label //print the question and label
@ -442,11 +516,11 @@ class feedback_item_multichoice extends feedback_item_base {
//print the presentation //print the presentation
echo '<div class="feedback_item_presentation_'.$align.'">'; echo '<div class="feedback_item_presentation_'.$align.'">';
$index = 1; $index = 1;
if($info->subtype == 'c') { if ($info->subtype == 'c') {
echo $OUTPUT->box_start('generalbox boxalign'.$align); echo $OUTPUT->box_start('generalbox boxalign'.$align);
foreach($presentation as $pres){ foreach ($presentation as $pres) {
foreach($values as $val) { foreach ($values as $val) {
if($val == $index){ if ($val == $index) {
echo '<div class="feedback_item_multianswer">'; echo '<div class="feedback_item_multianswer">';
echo text_to_html($pres, true, false, false); echo text_to_html($pres, true, false, false);
echo '</div>'; echo '</div>';
@ -456,9 +530,9 @@ class feedback_item_multichoice extends feedback_item_base {
$index++; $index++;
} }
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
}else { } else {
foreach($presentation as $pres){ foreach ($presentation as $pres) {
if($value == $index){ if ($value == $index) {
echo $OUTPUT->box_start('generalbox boxalign'.$align); echo $OUTPUT->box_start('generalbox boxalign'.$align);
echo text_to_html($pres, true, false, false); echo text_to_html($pres, true, false, false);
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
@ -470,47 +544,42 @@ class feedback_item_multichoice extends feedback_item_base {
echo '</div>'; echo '</div>';
} }
function check_value($value, $item) { public function check_value($value, $item) {
$info = $this->get_info($item); $info = $this->get_info($item);
if($info->subtype == 'c') { if ($item->required != 1) {
if((!isset($value) OR !is_array($value) OR $value[0] == '' OR $value[0] == 0) AND $item->required != 1){
return true;
}
if($value[0] == ""){
return false;
}
return true; return true;
}else {
//if the item is not required, so the check is true if no value is given
if((!isset($value) OR $value == '' OR $value == 0) AND $item->required != 1) return true;
if(intval($value) > 0)return true;
} }
return false;
if (!isset($value) OR !is_array($value) OR $value[0] == '' OR $value[0] == 0) {
return false;
}
return true;
} }
function create_value($data) { public function create_value($data) {
$vallist = $data; $vallist = $data;
return trim($this->item_arrayToString($vallist)); return trim($this->item_array_to_string($vallist));
} }
//compares the dbvalue with the dependvalue //compares the dbvalue with the dependvalue
//dbvalue is the number of one selection //dbvalue is the number of one selection
//dependvalue is the presentation of one selection //dependvalue is the presentation of one selection
function compare_value($item, $dbvalue, $dependvalue) { public function compare_value($item, $dbvalue, $dependvalue) {
if (is_array($dbvalue)) { if (is_array($dbvalue)) {
$dbvalues = $dbvalue; $dbvalues = $dbvalue;
}else { } else {
$dbvalues = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $dbvalue); $dbvalues = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $dbvalue);
} }
$info = $this->get_info($item); $info = $this->get_info($item);
$presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
$index = 1; $index = 1;
foreach($presentation as $pres) { foreach ($presentation as $pres) {
foreach($dbvalues as $dbval) { foreach ($dbvalues as $dbval) {
if($dbval == $index AND trim($pres) == $dependvalue) { if ($dbval == $index AND trim($pres) == $dependvalue) {
return true; return true;
} }
} }
@ -519,24 +588,24 @@ class feedback_item_multichoice extends feedback_item_base {
return false; return false;
} }
function get_presentation($data) { public function get_presentation($data) {
$present = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($data->itemvalues)); $present = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($data->itemvalues));
if(!isset($data->subtype)) { if (!isset($data->subtype)) {
$subtype = 'r'; $subtype = 'r';
}else { } else {
$subtype = substr($data->subtype, 0, 1); $subtype = substr($data->subtype, 0, 1);
} }
if(isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') { if (isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') {
$present .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1'; $present .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1';
} }
return $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$present; return $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$present;
} }
function get_hasvalue() { public function get_hasvalue() {
return 1; return 1;
} }
function get_info($item) { private function get_info($item) {
$presentation = empty($item->presentation) ? '' : $item->presentation; $presentation = empty($item->presentation) ? '' : $item->presentation;
$info = new stdClass(); $info = new stdClass();
@ -546,62 +615,80 @@ class feedback_item_multichoice extends feedback_item_base {
$info->presentation = ''; $info->presentation = '';
$info->horizontal = false; $info->horizontal = false;
@list($info->subtype, $info->presentation) = explode(FEEDBACK_MULTICHOICE_TYPE_SEP, $item->presentation); $parts = explode(FEEDBACK_MULTICHOICE_TYPE_SEP, $item->presentation);
if(!isset($info->subtype)) { @list($info->subtype, $info->presentation) = $parts;
if (!isset($info->subtype)) {
$info->subtype = 'r'; $info->subtype = 'r';
} }
if($info->subtype != 'd') { if ($info->subtype != 'd') {
@list($info->presentation, $info->horizontal) = explode(FEEDBACK_MULTICHOICE_ADJUST_SEP, $info->presentation); $parts = explode(FEEDBACK_MULTICHOICE_ADJUST_SEP, $info->presentation);
if(isset($info->horizontal) AND $info->horizontal == 1) { @list($info->presentation, $info->horizontal) = $parts;
if (isset($info->horizontal) AND $info->horizontal == 1) {
$info->horizontal = true; $info->horizontal = true;
}else { } else {
$info->horizontal = false; $info->horizontal = false;
} }
} }
return $info; return $info;
} }
function item_arrayToString($value) { private function item_array_to_string($value) {
if (!is_array($value)) { if (!is_array($value)) {
return $value; return $value;
} }
$retval = ''; $retval = '';
$arrvals = array_values($value); $arrvals = array_values($value);
$arrvals = clean_param($arrvals, PARAM_INT); //prevent sql-injection $arrvals = clean_param_array($arrvals, PARAM_INT); //prevent sql-injection
$retval = $arrvals[0]; $retval = $arrvals[0];
$sizeofarrvals = sizeof($arrvals); $sizeofarrvals = count($arrvals);
for ($i = 1; $i < $sizeofarrvals; $i++) { for ($i = 1; $i < $sizeofarrvals; $i++) {
$retval .= FEEDBACK_MULTICHOICE_LINE_SEP.$arrvals[$i]; $retval .= FEEDBACK_MULTICHOICE_LINE_SEP.$arrvals[$i];
} }
return $retval; return $retval;
} }
function print_item_radio($presentation, $item, $value, $info, $align) { private function print_item_radio($presentation, $item, $value, $info, $align) {
$index = 1; $index = 1;
$checked = ''; $checked = '';
if($info->horizontal) { if (is_array($value)) {
$values = $value;
} else {
$values = array($value);
}
if ($info->horizontal) {
$hv = 'h'; $hv = 'h';
}else { } else {
$hv = 'v'; $hv = 'v';
} }
foreach($presentation as $radio){ foreach ($presentation as $radio) {
if($value == $index){ foreach ($values as $val) {
$checked = 'checked="checked"'; if ($val == $index) {
}else{ $checked = 'checked="checked"';
$checked = ''; break;
} else {
$checked = '';
}
} }
$inputname = $item->typ . '_' . $item->id; $inputname = $item->typ . '_' . $item->id;
$inputid = $inputname.'_'.$index; $inputid = $inputname.'_'.$index;
?> ?>
<li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
<span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
<input type="radio" name="<?php echo $inputname;?>" id="<?php echo $inputid;?>" value="<?php echo $index;?>" <?php echo $checked;?> /> <?php
echo '<input type="radio" '.
'name="'.$inputname.'[]" '.
'id="'.$inputid.'" '.
'value="'.$index.'" '.$checked.' />';
?>
</span> </span>
<span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
<label for="<?php echo $inputid;?>"><?php echo text_to_html($radio, true, false, false);?>&nbsp;</label> <label for="<?php echo $inputid;?>">
<?php echo text_to_html($radio, true, false, false);?>&nbsp;
</label>
</span> </span>
</li> </li>
<?php <?php
@ -609,28 +696,28 @@ class feedback_item_multichoice extends feedback_item_base {
} }
} }
function print_item_check($presentation, $item, $value, $info, $align) { private function print_item_check($presentation, $item, $value, $info, $align) {
if (is_array($value)) { if (is_array($value)) {
$values = $value; $values = $value;
}else { } else {
$values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value); $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value);
} }
if($info->horizontal) { if ($info->horizontal) {
$hv = 'h'; $hv = 'h';
}else { } else {
$hv = 'v'; $hv = 'v';
} }
$index = 1; $index = 1;
$checked = ''; $checked = '';
foreach($presentation as $check){ foreach ($presentation as $check) {
foreach($values as $val) { foreach ($values as $val) {
if($val == $index){ if ($val == $index) {
$checked = 'checked="checked"'; $checked = 'checked="checked"';
break; break;
}else{ } else {
$checked = ''; $checked = '';
} }
} }
@ -639,10 +726,17 @@ class feedback_item_multichoice extends feedback_item_base {
?> ?>
<li class="feedback_item_check_<?php echo $hv.'_'.$align;?>"> <li class="feedback_item_check_<?php echo $hv.'_'.$align;?>">
<span class="feedback_item_check_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_check_<?php echo $hv.'_'.$align;?>">
<input type="checkbox" name="<?php echo $inputname;?>[]" id="<?php echo $inputid;?>" value="<?php echo $index;?>" <?php echo $checked;?> /> <?php
echo '<input type="checkbox" '.
'name="'.$inputname.'[]" '.
'id="'.$inputid.'" '.
'value="'.$index.'" '.$checked.' />';
?>
</span> </span>
<span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
<label for="<?php echo $inputid;?>"><?php echo text_to_html($check, true, false, false);?>&nbsp;</label> <label for="<?php echo $inputid;?>">
<?php echo text_to_html($check, true, false, false);?>&nbsp;
</label>
</span> </span>
</li> </li>
<?php <?php
@ -650,28 +744,39 @@ class feedback_item_multichoice extends feedback_item_base {
} }
} }
function print_item_dropdown($presentation, $item, $value, $info, $align) { private function print_item_dropdown($presentation, $item, $value, $info, $align) {
if($info->horizontal) { if (is_array($value)) {
$values = $value;
} else {
$values = array($value);
}
if ($info->horizontal) {
$hv = 'h'; $hv = 'h';
}else { } else {
$hv = 'v'; $hv = 'v';
} }
?> ?>
<li class="feedback_item_select_<?php echo $hv.'_'.$align;?>"> <li class="feedback_item_select_<?php echo $hv.'_'.$align;?>">
<select name="<?php echo $item->typ .'_' . $item->id;?>" size="1"> <select name="<?php echo $item->typ .'_' . $item->id;?>[]" size="1">
<option value="0">&nbsp;</option> <option value="0">&nbsp;</option>
<?php <?php
$index = 1; $index = 1;
$checked = ''; $selected = '';
foreach($presentation as $dropdown){ foreach ($presentation as $dropdown) {
if($value == $index){ foreach ($values as $val) {
$selected = 'selected="selected"'; if ($val == $index) {
}else{ $selected = 'selected="selected"';
$selected = ''; break;
} else {
$selected = '';
}
} }
?> ?>
<option value="<?php echo $index;?>" <?php echo $selected;?>><?php echo text_to_html($dropdown, true, false, false);?></option> <option value="<?php echo $index;?>" <?php echo $selected;?>>
<?php echo text_to_html($dropdown, true, false, false);?>
</option>
<?php <?php
$index++; $index++;
} }
@ -681,36 +786,43 @@ class feedback_item_multichoice extends feedback_item_base {
<?php <?php
} }
function set_ignoreempty($item, $ignoreempty=true) { public function set_ignoreempty($item, $ignoreempty=true) {
$item->options = str_replace(FEEDBACK_MULTICHOICE_IGNOREEMPTY, '', $item->options); $item->options = str_replace(FEEDBACK_MULTICHOICE_IGNOREEMPTY, '', $item->options);
if($ignoreempty) { if ($ignoreempty) {
$item->options .= FEEDBACK_MULTICHOICE_IGNOREEMPTY; $item->options .= FEEDBACK_MULTICHOICE_IGNOREEMPTY;
} }
} }
function ignoreempty($item) { public function ignoreempty($item) {
if(strstr($item->options, FEEDBACK_MULTICHOICE_IGNOREEMPTY)) { if (strstr($item->options, FEEDBACK_MULTICHOICE_IGNOREEMPTY)) {
return true; return true;
} }
return false; return false;
} }
function set_hidenoselect($item, $hidenoselect=true) { public function set_hidenoselect($item, $hidenoselect=true) {
$item->options = str_replace(FEEDBACK_MULTICHOICE_HIDENOSELECT, '', $item->options); $item->options = str_replace(FEEDBACK_MULTICHOICE_HIDENOSELECT, '', $item->options);
if($hidenoselect) { if ($hidenoselect) {
$item->options .= FEEDBACK_MULTICHOICE_HIDENOSELECT; $item->options .= FEEDBACK_MULTICHOICE_HIDENOSELECT;
} }
} }
function hidenoselect($item) { public function hidenoselect($item) {
if(strstr($item->options, FEEDBACK_MULTICHOICE_HIDENOSELECT)) { if (strstr($item->options, FEEDBACK_MULTICHOICE_HIDENOSELECT)) {
return true; return true;
} }
return false; return false;
} }
public function can_switch_require() {
return true;
}
function can_switch_require() { public function value_type() {
return PARAM_INT;
}
public function value_is_array() {
return true; return true;
} }
} }

View File

@ -1,11 +1,25 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
class feedback_multichoice_form extends feedback_item_form { class feedback_multichoice_form extends feedback_item_form {
var $type = "multichoice"; protected $type = "multichoice";
function definition() { public function definition() {
$item = $this->_customdata['item']; $item = $this->_customdata['item'];
$common = $this->_customdata['common']; $common = $this->_customdata['common'];
$positionlist = $this->_customdata['positionlist']; $positionlist = $this->_customdata['positionlist'];
@ -20,16 +34,20 @@ class feedback_multichoice_form extends feedback_item_form {
$mform->addElement('text', $mform->addElement('text',
'name', 'name',
get_string('item_name', 'feedback'), get_string('item_name', 'feedback'),
array('size'=>FEEDBACK_ITEM_NAME_TEXTBOX_SIZE, 'maxlength'=>255)); array('size' => FEEDBACK_ITEM_NAME_TEXTBOX_SIZE,
'maxlength' => 255));
$mform->addElement('text', $mform->addElement('text',
'label', 'label',
get_string('item_label', 'feedback'), get_string('item_label', 'feedback'),
array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255)); array('size' => FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE,
'maxlength' => 255));
$mform->addElement('select', $mform->addElement('select',
'horizontal', 'horizontal',
get_string('adjustment', 'feedback').'&nbsp;', get_string('adjustment', 'feedback').'&nbsp;',
array(0 => get_string('vertical', 'feedback'), 1 => get_string('horizontal', 'feedback'))); array(0 => get_string('vertical', 'feedback'),
1 => get_string('horizontal', 'feedback')));
$mform->addElement('select', $mform->addElement('select',
'subtype', 'subtype',
@ -38,11 +56,18 @@ class feedback_multichoice_form extends feedback_item_form {
'c'=>get_string('check', 'feedback'), 'c'=>get_string('check', 'feedback'),
'd'=>get_string('dropdown', 'feedback'))); 'd'=>get_string('dropdown', 'feedback')));
$mform->addElement('selectyesno',
$mform->addElement('selectyesno', 'ignoreempty', get_string('do_not_analyse_empty_submits', 'feedback')); 'ignoreempty',
$mform->addElement('selectyesno', 'hidenoselect', get_string('hide_no_select_option', 'feedback')); get_string('do_not_analyse_empty_submits', 'feedback'));
$mform->addElement('static', 'hint', get_string('multichoice_values', 'feedback'), get_string('use_one_line_for_each_value', 'feedback')); $mform->addElement('selectyesno',
'hidenoselect',
get_string('hide_no_select_option', 'feedback'));
$mform->addElement('static',
'hint',
get_string('multichoice_values', 'feedback'),
get_string('use_one_line_for_each_value', 'feedback'));
$mform->addElement('textarea', 'values', '', 'wrap="virtual" rows="10" cols="65"'); $mform->addElement('textarea', 'values', '', 'wrap="virtual" rows="10" cols="65"');
@ -50,8 +75,8 @@ class feedback_multichoice_form extends feedback_item_form {
$this->set_data($item); $this->set_data($item);
} }
function set_data($item) { public function set_data($item) {
$info = $this->_customdata['info']; $info = $this->_customdata['info'];
$item->horizontal = $info->horizontal; $item->horizontal = $info->horizontal;
@ -61,27 +86,26 @@ class feedback_multichoice_form extends feedback_item_form {
$itemvalues = str_replace(FEEDBACK_MULTICHOICE_LINE_SEP, "\n", $info->presentation); $itemvalues = str_replace(FEEDBACK_MULTICHOICE_LINE_SEP, "\n", $info->presentation);
$itemvalues = str_replace("\n\n", "\n", $itemvalues); $itemvalues = str_replace("\n\n", "\n", $itemvalues);
$item->values = $itemvalues; $item->values = $itemvalues;
return parent::set_data($item); return parent::set_data($item);
} }
function get_data() { public function get_data() {
if(!$item = parent::get_data()) { if (!$item = parent::get_data()) {
return false; return false;
} }
$presentation = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($item->values)); $presentation = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($item->values));
if(!isset($item->subtype)) { if (!isset($item->subtype)) {
$subtype = 'r'; $subtype = 'r';
}else { } else {
$subtype = substr($item->subtype, 0, 1); $subtype = substr($item->subtype, 0, 1);
} }
if(isset($item->horizontal) AND $item->horizontal == 1 AND $subtype != 'd') { if (isset($item->horizontal) AND $item->horizontal == 1 AND $subtype != 'd') {
$presentation .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1'; $presentation .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1';
} }
$item->presentation = $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$presentation; $item->presentation = $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$presentation;
return $item; return $item;
} }
} }

View File

@ -1,4 +1,19 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') OR die('not allowed'); defined('MOODLE_INTERNAL') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
@ -14,32 +29,32 @@ define('FEEDBACK_MULTICHOICERATED_IGNOREEMPTY', 'i');
define('FEEDBACK_MULTICHOICERATED_HIDENOSELECT', 'h'); define('FEEDBACK_MULTICHOICERATED_HIDENOSELECT', 'h');
class feedback_item_multichoicerated extends feedback_item_base { class feedback_item_multichoicerated extends feedback_item_base {
var $type = "multichoicerated"; protected $type = "multichoicerated";
var $commonparams; private $commonparams;
var $item_form; private $item_form;
var $item; private $item;
function init() { public function init() {
} }
function build_editform($item, $feedback, $cm) { public function build_editform($item, $feedback, $cm) {
global $DB, $CFG; global $DB, $CFG;
require_once('multichoicerated_form.php'); require_once('multichoicerated_form.php');
//get the lastposition number of the feedback_items //get the lastposition number of the feedback_items
$position = $item->position; $position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){ if ($position == -1) {
$i_formselect_last = $lastposition + 1; $i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1; $i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1; $item->position = $lastposition + 1;
}else { } else {
$i_formselect_last = $lastposition; $i_formselect_last = $lastposition;
$i_formselect_value = $item->position; $i_formselect_value = $item->position;
} }
//the elements for position dropdownlist //the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true); $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
$item->presentation = empty($item->presentation) ? '' : $item->presentation; $item->presentation = empty($item->presentation) ? '' : $item->presentation;
$info = $this->get_info($item); $info = $this->get_info($item);
@ -50,39 +65,45 @@ class feedback_item_multichoicerated extends feedback_item_base {
//all items for dependitem //all items for dependitem
$feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
$commonparams = array('cmid'=>$cm->id, $commonparams = array('cmid'=>$cm->id,
'id'=>isset($item->id) ? $item->id : NULL, 'id'=>isset($item->id) ? $item->id : null,
'typ'=>$item->typ, 'typ'=>$item->typ,
'items'=>$feedbackitems, 'items'=>$feedbackitems,
'feedback'=>$feedback->id); 'feedback'=>$feedback->id);
//build the form //build the form
$this->item_form = new feedback_multichoicerated_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position, 'info'=>$info)); $customdata = array('item' => $item,
'common' => $commonparams,
'positionlist' => $positionlist,
'position' => $position,
'info' => $info);
$this->item_form = new feedback_multichoicerated_form('edit_item.php', $customdata);
} }
//this function only can used after the call of build_editform() //this function only can used after the call of build_editform()
function show_editform() { public function show_editform() {
$this->item_form->display(); $this->item_form->display();
} }
function is_cancelled() { public function is_cancelled() {
return $this->item_form->is_cancelled(); return $this->item_form->is_cancelled();
} }
function get_data() { public function get_data() {
if($this->item = $this->item_form->get_data()) { if ($this->item = $this->item_form->get_data()) {
return true; return true;
} }
return false; return false;
} }
function save_item() { public function save_item() {
global $DB; global $DB;
if(!$item = $this->item_form->get_data()) { if (!$item = $this->item_form->get_data()) {
return false; return false;
} }
if(isset($item->clone_item) AND $item->clone_item) { if (isset($item->clone_item) AND $item->clone_item) {
$item->id = ''; //to clone this item $item->id = ''; //to clone this item
$item->position++; $item->position++;
} }
@ -91,9 +112,9 @@ class feedback_item_multichoicerated extends feedback_item_base {
$this->set_hidenoselect($item, $item->hidenoselect); $this->set_hidenoselect($item, $item->hidenoselect);
$item->hasvalue = $this->get_hasvalue(); $item->hasvalue = $this->get_hasvalue();
if(!$item->id) { if (!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item); $item->id = $DB->insert_record('feedback_item', $item);
}else { } else {
$DB->update_record('feedback_item', $item); $DB->update_record('feedback_item', $item);
} }
@ -101,33 +122,37 @@ class feedback_item_multichoicerated extends feedback_item_base {
} }
//liefert ein eindimensionales Array mit drei Werten(typ, name, XXX) //gets an array with three values(typ, name, XXX)
//XXX ist ein eindimensionales Array (Mittelwert der Werte der Antworten bei Typ Radio_rated) Jedes Element ist eine Struktur (answertext, avg) //XXX is an object with answertext, answercount and quotient
function get_analysed($item, $groupid = false, $courseid = false) { public function get_analysed($item, $groupid = false, $courseid = false) {
$analysedItem = array(); $analysed_item = array();
$analysedItem[] = $item->typ; $analysed_item[] = $item->typ;
$analysedItem[] = $item->name; $analysed_item[] = $item->name;
//die moeglichen Antworten extrahieren //die moeglichen Antworten extrahieren
$info = $this->get_info($item); $info = $this->get_info($item);
$lines = null; $lines = null;
$lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation); $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
if(!is_array($lines)) return null; if (!is_array($lines)) {
return null;
}
//die Werte holen //die Werte holen
$values = feedback_get_group_values($item, $groupid, $courseid, $this->ignoreempty($item)); $values = feedback_get_group_values($item, $groupid, $courseid, $this->ignoreempty($item));
if(!$values) return null; if (!$values) {
return null;
}
//schleife ueber den Werten und ueber die Antwortmoeglichkeiten //schleife ueber den Werten und ueber die Antwortmoeglichkeiten
$analysedAnswer = array(); $analysed_answer = array();
$sizeoflines = sizeof($lines); $sizeoflines = count($lines);
for($i = 1; $i <= $sizeoflines; $i++) { for ($i = 1; $i <= $sizeoflines; $i++) {
$item_values = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $lines[$i-1]); $item_values = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $lines[$i-1]);
$ans = null; $ans = null;
$ans->answertext = $item_values[1]; $ans->answertext = $item_values[1];
$avg = 0.0; $avg = 0.0;
$anscount = 0; $anscount = 0;
foreach($values as $value) { foreach ($values as $value) {
//ist die Antwort gleich dem index der Antworten + 1? //ist die Antwort gleich dem index der Antworten + 1?
if ($value->value == $i) { if ($value->value == $i) {
$avg += $item_values[0]; //erst alle Werte aufsummieren $avg += $item_values[0]; //erst alle Werte aufsummieren
@ -135,26 +160,28 @@ class feedback_item_multichoicerated extends feedback_item_base {
} }
} }
$ans->answercount = $anscount; $ans->answercount = $anscount;
$ans->avg = doubleval($avg) / doubleval(sizeof($values)); $ans->avg = doubleval($avg) / doubleval(count($values));
$ans->value = $item_values[0]; $ans->value = $item_values[0];
$ans->quotient = $ans->answercount / sizeof($values); $ans->quotient = $ans->answercount / count($values);
$analysedAnswer[] = $ans; $analysed_answer[] = $ans;
} }
$analysedItem[] = $analysedAnswer; $analysed_item[] = $analysed_answer;
return $analysedItem; return $analysed_item;
} }
function get_printval($item, $value) { public function get_printval($item, $value) {
$printval = ''; $printval = '';
if(!isset($value->value)) return $printval; if (!isset($value->value)) {
return $printval;
}
$info = $this->get_info($item); $info = $this->get_info($item);
$presentation = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation); $presentation = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
$index = 1; $index = 1;
foreach($presentation as $pres){ foreach ($presentation as $pres) {
if($value->value == $index){ if ($value->value == $index) {
$item_label = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $pres); $item_label = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $pres);
$printval = $item_label[1]; $printval = $item_label[1];
break; break;
@ -164,26 +191,26 @@ class feedback_item_multichoicerated extends feedback_item_base {
return $printval; return $printval;
} }
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
$sep_dec = get_string('separator_decimal', 'feedback'); $sep_dec = get_string('separator_decimal', 'feedback');
if(substr($sep_dec, 0, 2) == '[['){ if (substr($sep_dec, 0, 2) == '[[') {
$sep_dec = FEEDBACK_DECIMAL; $sep_dec = FEEDBACK_DECIMAL;
} }
$sep_thous = get_string('separator_thousand', 'feedback'); $sep_thous = get_string('separator_thousand', 'feedback');
if(substr($sep_thous, 0, 2) == '[['){ if (substr($sep_thous, 0, 2) == '[[') {
$sep_thous = FEEDBACK_THOUSAND; $sep_thous = FEEDBACK_THOUSAND;
} }
$analysedItem = $this->get_analysed($item, $groupid, $courseid); $analysed_item = $this->get_analysed($item, $groupid, $courseid);
if($analysedItem) { if ($analysed_item) {
//echo '<table>'; echo '<tr><th colspan="2" align="left">';
// $itemnr++; echo $itemnr.'&nbsp;('.$item->label.') '.$analysed_item[1];
echo '<tr><th colspan="2" align="left">'. $itemnr . '&nbsp;('. $item->label .') ' . $analysedItem[1] .'</th></tr>'; echo '</th></tr>';
$analysedVals = $analysedItem[2]; $analysed_vals = $analysed_item[2];
$pixnr = 0; $pixnr = 0;
$avg = 0.0; $avg = 0.0;
foreach($analysedVals as $val) { foreach ($analysed_vals as $val) {
$intvalue = $pixnr % 10; $intvalue = $pixnr % 10;
$pix = "pics/$intvalue.gif"; $pix = "pics/$intvalue.gif";
$pixnr++; $pixnr++;
@ -191,48 +218,68 @@ class feedback_item_multichoicerated extends feedback_item_base {
$avg += $val->avg; $avg += $val->avg;
$quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous);
echo '<tr><td align="left" valign="top">-&nbsp;&nbsp;' . trim($val->answertext) . ' ('.$val->value.'):</td><td align="left" style="width: '.FEEDBACK_MAX_PIX_LENGTH.'"><img alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />' . $val->answercount. (($val->quotient > 0)?'&nbsp;('. $quotient . '&nbsp;%)':'') . '</td></tr>'; echo '<tr>';
echo '<td align="left" valign="top">';
echo '-&nbsp;&nbsp;'.trim($val->answertext).' ('.$val->value.'):</td>';
echo '<td align="left" style="width: '.FEEDBACK_MAX_PIX_LENGTH.'">';
echo '<img alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />';
echo $val->answercount;
if ($val->quotient > 0) {
echo '&nbsp;('.$quotient.'&nbsp;%)';
} else {
echo '';
}
echo '</td></tr>';
} }
$avg = number_format(($avg), 2, $sep_dec, $sep_thous); $avg = number_format(($avg), 2, $sep_dec, $sep_thous);
echo '<tr><td align="left" colspan="2"><b>'.get_string('average', 'feedback').': '.$avg.'</b></td></tr>'; echo '<tr><td align="left" colspan="2"><b>';
//echo '</table>'; echo get_string('average', 'feedback').': '.$avg.'</b>';
echo '</td></tr>';
} }
// return $itemnr;
} }
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) { public function excelprint_item(&$worksheet, $row_offset,
$xls_formats, $item,
$groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid); $analysed_item = $this->get_analysed($item, $groupid, $courseid);
$data = $analysed_item[2]; $data = $analysed_item[2];
// $worksheet->setFormat("<l><f><ro2><vo><c:green>"); //write the item
//frage schreiben $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2);
$worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2); $worksheet->write_string($row_offset, 1, $analysed_item[1], $xls_formats->head2);
$worksheet->write_string($rowOffset, 1, $analysed_item[1], $xlsFormats->head2); if (is_array($data)) {
if(is_array($data)) {
$avg = 0.0; $avg = 0.0;
$sizeofdata = sizeof($data); $sizeofdata = count($data);
for($i = 0; $i < $sizeofdata; $i++) { for ($i = 0; $i < $sizeofdata; $i++) {
$aData = $data[$i]; $analysed_data = $data[$i];
// $worksheet->setFormat("<l><f><ro2><vo><c:blue>"); $worksheet->write_string($row_offset,
$worksheet->write_string($rowOffset, $i + 2, trim($aData->answertext).' ('.$aData->value.')', $xlsFormats->value_bold); $i + 2,
trim($analysed_data->answertext).' ('.$analysed_data->value.')',
$xls_formats->value_bold);
// $worksheet->setFormat("<l><vo>"); $worksheet->write_number($row_offset + 1,
$worksheet->write_number($rowOffset + 1, $i + 2, $aData->answercount, $xlsFormats->default); $i + 2,
//$worksheet->setFormat("<l><f><vo>"); $analysed_data->answercount,
//$worksheet->write_number($rowOffset + 2, $i + 1, $aData->avg); $xls_formats->default);
$avg += $aData->avg;
$avg += $analysed_data->avg;
} }
//mittelwert anzeigen //mittelwert anzeigen
// $worksheet->setFormat("<l><f><ro2><vo><c:red>"); $worksheet->write_string($row_offset,
$worksheet->write_string($rowOffset, sizeof($data) + 2, get_string('average', 'feedback'), $xlsFormats->value_bold); count($data) + 2,
get_string('average', 'feedback'),
$xls_formats->value_bold);
// $worksheet->setFormat("<l><f><vo>"); $worksheet->write_number($row_offset + 1,
$worksheet->write_number($rowOffset + 1, sizeof($data) + 2, $avg, $xlsFormats->value_bold); count($data) + 2,
$avg,
$xls_formats->value_bold);
} }
$rowOffset +=2 ; $row_offset +=2;
return $rowOffset; return $row_offset;
} }
/** /**
@ -242,21 +289,24 @@ class feedback_item_multichoicerated extends feedback_item_base {
* @param object $item * @param object $item
* @return void * @return void
*/ */
function print_item_preview($item) { public function print_item_preview($item) {
global $OUTPUT, $DB; global $OUTPUT, $DB;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$info = $this->get_info($item); $info = $this->get_info($item);
$str_required_mark = '<span class="feedback_required_mark">*</span>';
$lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation); $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1) ? $str_required_mark : '';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.'">'; echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') '; echo '('.$item->label.') ';
echo format_text($item->name.$requiredmark, true, false, false); echo format_text($item->name.$requiredmark, true, false, false);
if($item->dependitem) { if ($item->dependitem) {
if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
echo ' <span class="feedback_depend">('.$dependitem->label.'-&gt;'.$item->dependvalue.')</span>'; echo ' <span class="feedback_depend">';
echo '('.$dependitem->label.'-&gt;'.$item->dependvalue.')';
echo '</span>';
} }
} }
echo '</div>'; echo '</div>';
@ -283,16 +333,17 @@ class feedback_item_multichoicerated extends feedback_item_base {
* @param bool $highlightrequire * @param bool $highlightrequire
* @return void * @return void
*/ */
function print_item_complete($item, $value = '', $highlightrequire = false) { public function print_item_complete($item, $value = '', $highlightrequire = false) {
global $OUTPUT; global $OUTPUT;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$info = $this->get_info($item); $info = $this->get_info($item);
$str_required_mark = '<span class="feedback_required_mark">*</span>';
$lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation); $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1) ? $str_required_mark : '';
if($highlightrequire AND $item->required AND intval($value) <= 0) { if ($highlightrequire AND $item->required AND intval($value) <= 0) {
$highlight = ' missingrequire'; $highlight = ' missingrequire';
}else { } else {
$highlight = ''; $highlight = '';
} }
@ -322,13 +373,13 @@ class feedback_item_multichoicerated extends feedback_item_base {
* @param string $value * @param string $value
* @return void * @return void
*/ */
function print_item_show_value($item, $value = '') { public function print_item_show_value($item, $value = '') {
global $OUTPUT; global $OUTPUT;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$info = $this->get_info($item); $info = $this->get_info($item);
$lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation); $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.'">'; echo '<div class="feedback_item_label_'.$align.'">';
@ -339,8 +390,8 @@ class feedback_item_multichoicerated extends feedback_item_base {
//print the presentation //print the presentation
echo '<div class="feedback_item_presentation_'.$align.'">'; echo '<div class="feedback_item_presentation_'.$align.'">';
$index = 1; $index = 1;
foreach($lines as $line){ foreach ($lines as $line) {
if($value == $index){ if ($value == $index) {
$item_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line); $item_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
echo $OUTPUT->box_start('generalbox boxalign'.$align); echo $OUTPUT->box_start('generalbox boxalign'.$align);
echo text_to_html($item_value[1], true, false, false); echo text_to_html($item_value[1], true, false, false);
@ -352,13 +403,17 @@ class feedback_item_multichoicerated extends feedback_item_base {
echo '</div>'; echo '</div>';
} }
function check_value($value, $item) { public function check_value($value, $item) {
if((!isset($value) OR $value == '' OR $value == 0) AND $item->required != 1) return true; if ((!isset($value) OR $value == '' OR $value == 0) AND $item->required != 1) {
if(intval($value) > 0)return true; return true;
}
if (intval($value) > 0) {
return true;
}
return false; return false;
} }
function create_value($data) { public function create_value($data) {
$data = trim($data); $data = trim($data);
return $data; return $data;
} }
@ -366,22 +421,22 @@ class feedback_item_multichoicerated extends feedback_item_base {
//compares the dbvalue with the dependvalue //compares the dbvalue with the dependvalue
//dbvalue is the number of one selection //dbvalue is the number of one selection
//dependvalue is the presentation of one selection //dependvalue is the presentation of one selection
function compare_value($item, $dbvalue, $dependvalue) { public function compare_value($item, $dbvalue, $dependvalue) {
if (is_array($dbvalue)) { if (is_array($dbvalue)) {
$dbvalues = $dbvalue; $dbvalues = $dbvalue;
}else { } else {
$dbvalues = explode(FEEDBACK_MULTICHOICERATED_LINE_SEP, $dbvalue); $dbvalues = explode(FEEDBACK_MULTICHOICERATED_LINE_SEP, $dbvalue);
} }
$info = $this->get_info($item); $info = $this->get_info($item);
$presentation = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation); $presentation = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
$index = 1; $index = 1;
foreach($presentation as $pres) { foreach ($presentation as $pres) {
$presvalues = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $pres); $presvalues = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $pres);
foreach($dbvalues as $dbval) { foreach ($dbvalues as $dbval) {
if($dbval == $index AND trim($presvalues[1]) == $dependvalue) { if ($dbval == $index AND trim($presvalues[1]) == $dependvalue) {
return true; return true;
} }
} }
@ -389,26 +444,27 @@ class feedback_item_multichoicerated extends feedback_item_base {
} }
return false; return false;
} }
function get_presentation($data) {
// $present = str_replace("\n", FEEDBACK_MULTICHOICERATED_LINE_SEP, trim($data->itemvalues)); public function get_presentation($data) {
$present = $this->prepare_presentation_values_save(trim($data->itemvalues), FEEDBACK_MULTICHOICERATED_VALUE_SEP2, FEEDBACK_MULTICHOICERATED_VALUE_SEP); $present = $this->prepare_presentation_values_save(trim($data->itemvalues),
// $present = str_replace("\n", FEEDBACK_MULTICHOICERATED_LINE_SEP, trim($data->itemvalues)); FEEDBACK_MULTICHOICERATED_VALUE_SEP2,
if(!isset($data->subtype)) { FEEDBACK_MULTICHOICERATED_VALUE_SEP);
if (!isset($data->subtype)) {
$subtype = 'r'; $subtype = 'r';
}else { } else {
$subtype = substr($data->subtype, 0, 1); $subtype = substr($data->subtype, 0, 1);
} }
if(isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') { if (isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') {
$present .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'1'; $present .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'1';
} }
return $subtype.FEEDBACK_MULTICHOICERATED_TYPE_SEP.$present; return $subtype.FEEDBACK_MULTICHOICERATED_TYPE_SEP.$present;
} }
function get_hasvalue() { public function get_hasvalue() {
return 1; return 1;
} }
function get_info($item) { private function get_info($item) {
$presentation = empty($item->presentation) ? '' : $item->presentation; $presentation = empty($item->presentation) ? '' : $item->presentation;
$info = new stdClass(); $info = new stdClass();
@ -418,53 +474,63 @@ class feedback_item_multichoicerated extends feedback_item_base {
$info->presentation = ''; $info->presentation = '';
$info->horizontal = false; $info->horizontal = false;
@list($info->subtype, $info->presentation) = explode(FEEDBACK_MULTICHOICERATED_TYPE_SEP, $item->presentation); $parts = explode(FEEDBACK_MULTICHOICERATED_TYPE_SEP, $item->presentation);
@list($info->subtype, $info->presentation) = $parts;
if(!isset($info->subtype)) { if (!isset($info->subtype)) {
$info->subtype = 'r'; $info->subtype = 'r';
} }
if ($info->subtype != 'd') {
$parts = explode(FEEDBACK_MULTICHOICERATED_ADJUST_SEP, $info->presentation);
@list($info->presentation, $info->horizontal) = $parts;
if($info->subtype != 'd') { if (isset($info->horizontal) AND $info->horizontal == 1) {
@list($info->presentation, $info->horizontal) = explode(FEEDBACK_MULTICHOICERATED_ADJUST_SEP, $info->presentation);
if(isset($info->horizontal) AND $info->horizontal == 1) {
$info->horizontal = true; $info->horizontal = true;
}else { } else {
$info->horizontal = false; $info->horizontal = false;
} }
} }
$info->values = $this->prepare_presentation_values_print($info->presentation, FEEDBACK_MULTICHOICERATED_VALUE_SEP, FEEDBACK_MULTICHOICERATED_VALUE_SEP2); $info->values = $this->prepare_presentation_values_print($info->presentation,
FEEDBACK_MULTICHOICERATED_VALUE_SEP,
FEEDBACK_MULTICHOICERATED_VALUE_SEP2);
return $info; return $info;
} }
function print_item_radio($item, $value, $info, $align, $showrating, $lines) { private function print_item_radio($item, $value, $info, $align, $showrating, $lines) {
$index = 1; $index = 1;
$checked = ''; $checked = '';
if($info->horizontal) { if ($info->horizontal) {
$hv = 'h'; $hv = 'h';
}else { } else {
$hv = 'v'; $hv = 'v';
} }
echo '<ul>'; echo '<ul>';
if(!$this->hidenoselect($item)) { if (!$this->hidenoselect($item)) {
?> ?>
<li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
<span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
<input type="radio" name="<?php echo $item->typ . '_' . $item->id ;?>" id="<?php echo $item->typ . '_' . $item->id.'_xxx';?>" value="" checked="checked" /> <?php
echo '<input type="radio" '.
'name="'.$item->typ.'_'.$item->id.'" '.
'id="'.$item->typ.'_'.$item->id.'_xxx" '.
'value="" checked="checked" />';
?>
</span> </span>
<span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
<label for="<?php echo $item->typ . '_' . $item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?>&nbsp;</label> <label for="<?php echo $item->typ . '_' . $item->id.'_xxx';?>">
<?php print_string('not_selected', 'feedback');?>&nbsp;
</label>
</span> </span>
</li> </li>
<?php <?php
} }
foreach($lines as $line){ foreach ($lines as $line) {
if($value == $index){ if ($value == $index) {
$checked = 'checked="checked"'; $checked = 'checked="checked"';
}else{ } else {
$checked = ''; $checked = '';
} }
$radio_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line); $radio_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
@ -473,14 +539,20 @@ class feedback_item_multichoicerated extends feedback_item_base {
?> ?>
<li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
<span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
<input type="radio" name="<?php echo $inputname;?>" id="<?php echo $inputid;?>" value="<?php echo $index;?>" <?php echo $checked;?> /> <?php
echo '<input type="radio" '.
'name="'.$inputname.'" '.
'id="'.$inputid.'" '.
'value="'.$index.'" '.$checked.' />';
?>
</span> </span>
<span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
<label for="<?php echo $inputid;?>"> <label for="<?php echo $inputid;?>">
<?php <?php
if($showrating) { if ($showrating) {
echo text_to_html('('.$radio_value[0].') '.$radio_value[1], true, false, false); $str_rating_value = '('.$radio_value[0].') '.$radio_value[1];
}else { echo text_to_html($str_rating_value, true, false, false);
} else {
echo text_to_html($radio_value[1], true, false, false); echo text_to_html($radio_value[1], true, false, false);
} }
?> ?>
@ -493,10 +565,10 @@ class feedback_item_multichoicerated extends feedback_item_base {
echo '</ul>'; echo '</ul>';
} }
function print_item_dropdown($item, $value, $info, $align, $showrating, $lines) { private function print_item_dropdown($item, $value, $info, $align, $showrating, $lines) {
if($info->horizontal) { if ($info->horizontal) {
$hv = 'h'; $hv = 'h';
}else { } else {
$hv = 'v'; $hv = 'v';
} }
echo '<ul>'; echo '<ul>';
@ -507,17 +579,21 @@ class feedback_item_multichoicerated extends feedback_item_base {
<?php <?php
$index = 1; $index = 1;
$checked = ''; $checked = '';
foreach($lines as $line){ foreach ($lines as $line) {
if($value == $index){ if ($value == $index) {
$selected = 'selected="selected"'; $selected = 'selected="selected"';
}else{ } else {
$selected = ''; $selected = '';
} }
$dropdown_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line); $dropdown_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
if($showrating) { if ($showrating) {
echo '<option value="'.$index.'" '.$selected.'>'.clean_text('('.$dropdown_value[0].') '.$dropdown_value[1]).'</option>'; echo '<option value="'.$index.'" '.$selected.'>';
}else { echo clean_text('('.$dropdown_value[0].') '.$dropdown_value[1]);
echo '<option value="'.$index.'" '.$selected.'>'.clean_text($dropdown_value[1]).'</option>'; echo '</option>';
} else {
echo '<option value="'.$index.'" '.$selected.'>';
echo clean_text($dropdown_value[1]);
echo '</option>';
} }
$index++; $index++;
} }
@ -528,16 +604,21 @@ class feedback_item_multichoicerated extends feedback_item_base {
echo '</ul>'; echo '</ul>';
} }
function prepare_presentation_values($linesep1, $linesep2, $valuestring, $valuesep1, $valuesep2) { public function prepare_presentation_values($linesep1,
$linesep2,
$valuestring,
$valuesep1,
$valuesep2) {
$lines = explode($linesep1, $valuestring); $lines = explode($linesep1, $valuestring);
$newlines = array(); $newlines = array();
foreach($lines as $line) { foreach ($lines as $line) {
$value = ''; $value = '';
$text = ''; $text = '';
if(strpos($line, $valuesep1) === false) { if (strpos($line, $valuesep1) === false) {
$value = 0; $value = 0;
$text = $line; $text = $line;
}else { } else {
@list($value, $text) = explode($valuesep1, $line, 2); @list($value, $text) = explode($valuesep1, $line, 2);
} }
@ -548,43 +629,51 @@ class feedback_item_multichoicerated extends feedback_item_base {
return $newlines; return $newlines;
} }
function prepare_presentation_values_print($valuestring, $valuesep1, $valuesep2) { public function prepare_presentation_values_print($valuestring, $valuesep1, $valuesep2) {
return $this->prepare_presentation_values(FEEDBACK_MULTICHOICERATED_LINE_SEP, "\n", $valuestring, $valuesep1, $valuesep2); return $this->prepare_presentation_values(FEEDBACK_MULTICHOICERATED_LINE_SEP,
"\n",
$valuestring,
$valuesep1,
$valuesep2);
} }
function prepare_presentation_values_save($valuestring, $valuesep1, $valuesep2) { public function prepare_presentation_values_save($valuestring, $valuesep1, $valuesep2) {
return $this->prepare_presentation_values("\n", FEEDBACK_MULTICHOICERATED_LINE_SEP, $valuestring, $valuesep1, $valuesep2); return $this->prepare_presentation_values("\n",
FEEDBACK_MULTICHOICERATED_LINE_SEP,
$valuestring,
$valuesep1,
$valuesep2);
} }
function set_ignoreempty($item, $ignoreempty=true) { public function set_ignoreempty($item, $ignoreempty=true) {
$item->options = str_replace(FEEDBACK_MULTICHOICERATED_IGNOREEMPTY, '', $item->options); $item->options = str_replace(FEEDBACK_MULTICHOICERATED_IGNOREEMPTY, '', $item->options);
if($ignoreempty) { if ($ignoreempty) {
$item->options .= FEEDBACK_MULTICHOICERATED_IGNOREEMPTY; $item->options .= FEEDBACK_MULTICHOICERATED_IGNOREEMPTY;
} }
} }
function ignoreempty($item) { public function ignoreempty($item) {
if(strstr($item->options, FEEDBACK_MULTICHOICERATED_IGNOREEMPTY)) { if (strstr($item->options, FEEDBACK_MULTICHOICERATED_IGNOREEMPTY)) {
return true; return true;
} }
return false; return false;
} }
function set_hidenoselect($item, $hidenoselect=true) { public function set_hidenoselect($item, $hidenoselect=true) {
$item->options = str_replace(FEEDBACK_MULTICHOICERATED_HIDENOSELECT, '', $item->options); $item->options = str_replace(FEEDBACK_MULTICHOICERATED_HIDENOSELECT, '', $item->options);
if($hidenoselect) { if ($hidenoselect) {
$item->options .= FEEDBACK_MULTICHOICERATED_HIDENOSELECT; $item->options .= FEEDBACK_MULTICHOICERATED_HIDENOSELECT;
} }
} }
function hidenoselect($item) { public function hidenoselect($item) {
if(strstr($item->options, FEEDBACK_MULTICHOICERATED_HIDENOSELECT)) { if (strstr($item->options, FEEDBACK_MULTICHOICERATED_HIDENOSELECT)) {
return true; return true;
} }
return false; return false;
} }
function can_switch_require() { public function can_switch_require() {
return true; return true;
} }

View File

@ -1,11 +1,25 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
class feedback_multichoicerated_form extends feedback_item_form { class feedback_multichoicerated_form extends feedback_item_form {
var $type = "multichoicerated"; protected $type = "multichoicerated";
function definition() { public function definition() {
$item = $this->_customdata['item']; $item = $this->_customdata['item'];
$common = $this->_customdata['common']; $common = $this->_customdata['common'];
$positionlist = $this->_customdata['positionlist']; $positionlist = $this->_customdata['positionlist'];
@ -20,16 +34,20 @@ class feedback_multichoicerated_form extends feedback_item_form {
$mform->addElement('text', $mform->addElement('text',
'name', 'name',
get_string('item_name', 'feedback'), get_string('item_name', 'feedback'),
array('size'=>FEEDBACK_ITEM_NAME_TEXTBOX_SIZE, 'maxlength'=>255)); array('size'=>FEEDBACK_ITEM_NAME_TEXTBOX_SIZE,
'maxlength'=>255));
$mform->addElement('text', $mform->addElement('text',
'label', 'label',
get_string('item_label', 'feedback'), get_string('item_label', 'feedback'),
array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255)); array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE,
'maxlength'=>255));
$mform->addElement('select', $mform->addElement('select',
'horizontal', 'horizontal',
get_string('adjustment', 'feedback').'&nbsp;', get_string('adjustment', 'feedback').'&nbsp;',
array(0 => get_string('vertical', 'feedback'), 1 => get_string('horizontal', 'feedback'))); array(0 => get_string('vertical', 'feedback'),
1 => get_string('horizontal', 'feedback')));
$mform->addElement('select', $mform->addElement('select',
'subtype', 'subtype',
@ -37,19 +55,30 @@ class feedback_multichoicerated_form extends feedback_item_form {
array('r'=>get_string('radio', 'feedback'), array('r'=>get_string('radio', 'feedback'),
'd'=>get_string('dropdown', 'feedback'))); 'd'=>get_string('dropdown', 'feedback')));
$mform->addElement('selectyesno', 'ignoreempty', get_string('do_not_analyse_empty_submits', 'feedback')); $mform->addElement('selectyesno',
$mform->addElement('selectyesno', 'hidenoselect', get_string('hide_no_select_option', 'feedback')); 'ignoreempty',
get_string('do_not_analyse_empty_submits', 'feedback'));
$mform->addElement('static', 'hint', get_string('multichoice_values', 'feedback'), get_string('use_one_line_for_each_value', 'feedback'));
$this->values = $mform->addElement('textarea', 'values', '', 'wrap="virtual" rows="10" cols="65"'); $mform->addElement('selectyesno',
'hidenoselect',
get_string('hide_no_select_option', 'feedback'));
$mform->addElement('static',
'hint',
get_string('multichoice_values', 'feedback'),
get_string('use_one_line_for_each_value', 'feedback'));
$this->values = $mform->addElement('textarea',
'values',
'',
'wrap="virtual" rows="10" cols="65"');
parent::definition(); parent::definition();
$this->set_data($item); $this->set_data($item);
} }
function set_data($item) { public function set_data($item) {
$info = $this->_customdata['info']; $info = $this->_customdata['info'];
$item->horizontal = $info->horizontal; $item->horizontal = $info->horizontal;
@ -58,27 +87,28 @@ class feedback_multichoicerated_form extends feedback_item_form {
$item->values = $info->values; $item->values = $info->values;
return parent::set_data($item); return parent::set_data($item);
} }
function get_data() { public function get_data() {
if(!$item = parent::get_data()) { if (!$item = parent::get_data()) {
return false; return false;
} }
$itemobj = new feedback_item_multichoicerated(); $itemobj = new feedback_item_multichoicerated();
$presentation = $itemobj->prepare_presentation_values_save(trim($item->values), FEEDBACK_MULTICHOICERATED_VALUE_SEP2, FEEDBACK_MULTICHOICERATED_VALUE_SEP); $presentation = $itemobj->prepare_presentation_values_save(trim($item->values),
if(!isset($item->subtype)) { FEEDBACK_MULTICHOICERATED_VALUE_SEP2,
FEEDBACK_MULTICHOICERATED_VALUE_SEP);
if (!isset($item->subtype)) {
$subtype = 'r'; $subtype = 'r';
}else { } else {
$subtype = substr($item->subtype, 0, 1); $subtype = substr($item->subtype, 0, 1);
} }
if(isset($item->horizontal) AND $item->horizontal == 1 AND $subtype != 'd') { if (isset($item->horizontal) AND $item->horizontal == 1 AND $subtype != 'd') {
$presentation .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'1'; $presentation .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'1';
} }
$item->presentation = $subtype.FEEDBACK_MULTICHOICERATED_TYPE_SEP.$presentation; $item->presentation = $subtype.FEEDBACK_MULTICHOICERATED_TYPE_SEP.$presentation;
return $item; return $item;
} }
} }

View File

@ -1,119 +1,152 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') OR die('not allowed'); defined('MOODLE_INTERNAL') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_numeric extends feedback_item_base { class feedback_item_numeric extends feedback_item_base {
var $type = "numeric"; protected $type = "numeric";
var $sep_dec, $sep_thous; public $sep_dec, $sep_thous;
var $commonparams; private $commonparams;
var $item_form; private $item_form;
var $item; private $item;
function init() { public function init() {
$this->sep_dec = get_string('separator_decimal', 'feedback'); $this->sep_dec = get_string('separator_decimal', 'feedback');
if(substr($this->sep_dec, 0, 2) == '[['){ if (substr($this->sep_dec, 0, 2) == '[[') {
$this->sep_dec = FEEDBACK_DECIMAL; $this->sep_dec = FEEDBACK_DECIMAL;
} }
$this->sep_thous = get_string('separator_thousand', 'feedback'); $this->sep_thous = get_string('separator_thousand', 'feedback');
if(substr($this->sep_thous, 0, 2) == '[['){ if (substr($this->sep_thous, 0, 2) == '[[') {
$this->sep_thous = FEEDBACK_THOUSAND; $this->sep_thous = FEEDBACK_THOUSAND;
} }
} }
function build_editform($item, $feedback, $cm) { public function build_editform($item, $feedback, $cm) {
global $DB, $CFG; global $DB, $CFG;
require_once('numeric_form.php'); require_once('numeric_form.php');
//get the lastposition number of the feedback_items //get the lastposition number of the feedback_items
$position = $item->position; $position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){ if ($position == -1) {
$i_formselect_last = $lastposition + 1; $i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1; $i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1; $item->position = $lastposition + 1;
}else { } else {
$i_formselect_last = $lastposition; $i_formselect_last = $lastposition;
$i_formselect_value = $item->position; $i_formselect_value = $item->position;
} }
//the elements for position dropdownlist //the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true); $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
$item->presentation = empty($item->presentation) ? '' : $item->presentation; $item->presentation = empty($item->presentation) ? '' : $item->presentation;
$range_from_to = explode('|',$item->presentation); $range_from_to = explode('|', $item->presentation);
$range_from = (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) ? str_replace(FEEDBACK_DECIMAL, $this->sep_dec, floatval($range_from_to[0])) : '-'; if (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) {
$range_to = (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) ? str_replace(FEEDBACK_DECIMAL, $this->sep_dec, floatval($range_from_to[1])) : '-'; $range_from = str_replace(FEEDBACK_DECIMAL,
$this->sep_dec,
floatval($range_from_to[0]));
} else {
$range_from = '-';
}
if (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) {
$range_to = str_replace(FEEDBACK_DECIMAL,
$this->sep_dec,
floatval($range_from_to[1]));
} else {
$range_to = '-';
}
$item->rangefrom = $range_from; $item->rangefrom = $range_from;
$item->rangeto = $range_to; $item->rangeto = $range_to;
//all items for dependitem //all items for dependitem
$feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
$commonparams = array('cmid'=>$cm->id, $commonparams = array('cmid'=>$cm->id,
'id'=>isset($item->id) ? $item->id : NULL, 'id'=>isset($item->id) ? $item->id : null,
'typ'=>$item->typ, 'typ'=>$item->typ,
'items'=>$feedbackitems, 'items'=>$feedbackitems,
'feedback'=>$feedback->id); 'feedback'=>$feedback->id);
//build the form //build the form
$this->item_form = new feedback_numeric_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position)); $customdata = array('item' => $item,
'common' => $commonparams,
'positionlist' => $positionlist,
'position' => $position);
$this->item_form = new feedback_numeric_form('edit_item.php', $customdata);
} }
//this function only can used after the call of build_editform() //this function only can used after the call of build_editform()
function show_editform() { public function show_editform() {
$this->item_form->display(); $this->item_form->display();
} }
function is_cancelled() { public function is_cancelled() {
return $this->item_form->is_cancelled(); return $this->item_form->is_cancelled();
} }
function get_data() { public function get_data() {
if($this->item = $this->item_form->get_data()) { if ($this->item = $this->item_form->get_data()) {
return true; return true;
} }
return false; return false;
} }
function save_item() { public function save_item() {
global $DB; global $DB;
if(!$item = $this->item_form->get_data()) { if (!$item = $this->item_form->get_data()) {
return false; return false;
} }
if(isset($item->clone_item) AND $item->clone_item) { if (isset($item->clone_item) AND $item->clone_item) {
$item->id = ''; //to clone this item $item->id = ''; //to clone this item
$item->position++; $item->position++;
} }
$item->hasvalue = $this->get_hasvalue(); $item->hasvalue = $this->get_hasvalue();
if(!$item->id) { if (!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item); $item->id = $DB->insert_record('feedback_item', $item);
}else { } else {
$DB->update_record('feedback_item', $item); $DB->update_record('feedback_item', $item);
} }
return $DB->get_record('feedback_item', array('id'=>$item->id)); return $DB->get_record('feedback_item', array('id'=>$item->id));
} }
//liefert eine Struktur ->name, ->data = array(mit Antworten) //liefert eine Struktur ->name, ->data = array(mit Antworten)
function get_analysed($item, $groupid = false, $courseid = false) { public function get_analysed($item, $groupid = false, $courseid = false) {
global $DB; global $DB;
$analysed = null; $analysed = null;
$analysed->data = array(); $analysed->data = array();
$analysed->name = $item->name; $analysed->name = $item->name;
//$values = $DB->get_records('feedback_value', array('item'=>$item->id));
$values = feedback_get_group_values($item, $groupid, $courseid); $values = feedback_get_group_values($item, $groupid, $courseid);
$avg = 0.0; $avg = 0.0;
$counter = 0; $counter = 0;
if($values) { if ($values) {
$data = array(); $data = array();
foreach($values as $value) { foreach ($values as $value) {
if(is_numeric($value->value)) { if (is_numeric($value->value)) {
$data[] = $value->value; $data[] = $value->value;
$avg += $value->value; $avg += $value->value;
$counter++; $counter++;
@ -126,64 +159,67 @@ class feedback_item_numeric extends feedback_item_base {
return $analysed; return $analysed;
} }
function get_printval($item, $value) { public function get_printval($item, $value) {
if(!isset($value->value)) return ''; if (!isset($value->value)) {
return '';
}
return $value->value; return $value->value;
} }
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
// $values = feedback_get_group_values($item, $groupid, $courseid);
$values = $this->get_analysed($item, $groupid, $courseid); $values = $this->get_analysed($item, $groupid, $courseid);
if(isset($values->data) AND is_array($values->data)) { if (isset($values->data) AND is_array($values->data)) {
//echo '<table>';2 echo '<tr><th colspan="2" align="left">';
// $itemnr++; echo $itemnr.'&nbsp;('.$item->label.') '.$item->name;
echo '<tr><th colspan="2" align="left">'. $itemnr . '&nbsp;('. $item->label .') ' . $item->name .'</th></tr>'; echo '</th></tr>';
foreach($values->data as $value) {
echo '<tr><td colspan="2" valign="top" align="left">-&nbsp;&nbsp;' . number_format($value, 2, $this->sep_dec, $this->sep_thous) . '</td></tr>'; foreach ($values->data as $value) {
echo '<tr><td colspan="2" valign="top" align="left">';
echo '-&nbsp;&nbsp;'.number_format($value, 2, $this->sep_dec, $this->sep_thous);
echo '</td></tr>';
} }
//echo '</table>';
if(isset($values->avg)) { if (isset($values->avg)) {
$avg = number_format($values->avg, 2, $this->sep_dec, $this->sep_thous); $avg = number_format($values->avg, 2, $this->sep_dec, $this->sep_thous);
} else { } else {
$avg = number_format(0, 2, $this->sep_dec, $this->sep_thous); $avg = number_format(0, 2, $this->sep_dec, $this->sep_thous);
} }
echo '<tr><td align="left" colspan="2"><b>'.get_string('average', 'feedback').': '.$avg.'</b></td></tr>'; echo '<tr><td align="left" colspan="2"><b>';
echo get_string('average', 'feedback').': '.$avg;
echo '</b></td></tr>';
} }
// return $itemnr;
} }
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) { public function excelprint_item(&$worksheet, $row_offset,
$xls_formats, $item,
$groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid); $analysed_item = $this->get_analysed($item, $groupid, $courseid);
// $worksheet->setFormat("<l><f><ro2><vo><c:green>"); $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2);
$worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2); $worksheet->write_string($row_offset, 1, $item->name, $xls_formats->head2);
$worksheet->write_string($rowOffset, 1, $item->name, $xlsFormats->head2);
$data = $analysed_item->data; $data = $analysed_item->data;
if(is_array($data)) { if (is_array($data)) {
// $worksheet->setFormat("<l><ro2><vo>");
// $worksheet->write_number($rowOffset, 1, $data[0]);
// $rowOffset++;
// for($i = 1; $i < sizeof($data); $i++) {
// $worksheet->setFormat("<l><vo>");
// $worksheet->write_number($rowOffset, 1, $data[$i]);
// $rowOffset++;
// }
//mittelwert anzeigen //mittelwert anzeigen
// $worksheet->setFormat("<l><f><ro2><vo><c:red>"); $worksheet->write_string($row_offset,
$worksheet->write_string($rowOffset, 2, get_string('average', 'feedback'), $xlsFormats->value_bold); 2,
get_string('average', 'feedback'),
$xls_formats->value_bold);
// $worksheet->setFormat("<l><f><vo>"); $worksheet->write_number($row_offset + 1,
$worksheet->write_number($rowOffset + 1, 2, $analysed_item->avg, $xlsFormats->value_bold); 2,
$rowOffset++; $analysed_item->avg,
$xls_formats->value_bold);
$row_offset++;
} }
$rowOffset++; $row_offset++;
return $rowOffset; return $row_offset;
} }
/** /**
* print the item at the edit-page of feedback * print the item at the edit-page of feedback
* *
@ -191,52 +227,75 @@ class feedback_item_numeric extends feedback_item_base {
* @param object $item * @param object $item
* @return void * @return void
*/ */
function print_item_preview($item) { public function print_item_preview($item) {
global $OUTPUT, $DB; global $OUTPUT, $DB;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$str_required_mark = '<span class="feedback_required_mark">*</span>';
//get the range //get the range
$range_from_to = explode('|',$item->presentation); $range_from_to = explode('|', $item->presentation);
//get the min-value //get the min-value
$range_from = (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) ? floatval($range_from_to[0]) : 0; if (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) {
$range_from = floatval($range_from_to[0]);
} else {
$range_from = 0;
}
//get the max-value //get the max-value
$range_to = (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) ? floatval($range_from_to[1]) : 0; if (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) {
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $range_to = floatval($range_from_to[1]);
} else {
$range_to = 0;
}
$requiredmark = ($item->required == 1) ? $str_required_mark : '';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.'">'; echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') '; echo '('.$item->label.') ';
echo format_text($item->name . $requiredmark, true, false, false); echo format_text($item->name . $requiredmark, true, false, false);
if($item->dependitem) { if ($item->dependitem) {
if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { $params = array('id'=>$item->dependitem);
echo ' <span class="feedback_depend">('.$dependitem->label.'-&gt;'.$item->dependvalue.')</span>'; if ($dependitem = $DB->get_record('feedback_item', $params)) {
} echo ' <span class="feedback_depend">';
echo '('.$dependitem->label.'-&gt;'.$item->dependvalue.')';
echo '</span>';
} }
echo '<span class="feedback_item_numinfo">'; }
switch(true) { echo '<span class="feedback_item_numinfo">';
case ($range_from === '-' AND is_numeric($range_to)): switch(true) {
echo ' ('.get_string('maximal', 'feedback').': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')'; case ($range_from === '-' AND is_numeric($range_to)):
break; echo ' ('.get_string('maximal', 'feedback').
case (is_numeric($range_from) AND $range_to === '-'): ': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
echo ' ('.get_string('minimal', 'feedback').': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).')'; break;
break; case (is_numeric($range_from) AND $range_to === '-'):
case ($range_from === '-' AND $range_to === '-'): echo ' ('.get_string('minimal', 'feedback').
break; ': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).')';
default: break;
echo ' ('.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).' - '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')'; case ($range_from === '-' AND $range_to === '-'):
break; break;
} default:
echo '</span>'; echo ' ('.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).
' - '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
break;
}
echo '</span>';
echo '</div>'; echo '</div>';
//print the presentation //print the presentation
echo '<div class="feedback_item_presentation_'.$align.'">'; echo '<div class="feedback_item_presentation_'.$align.'">';
echo '<span class="feedback_item_textfield">'; echo '<span class="feedback_item_textfield">';
echo '<input type="text" name="'.$item->typ.'_'.$item->id.'" size="10" maxlength="10" value="" />'; echo '<input type="text" '.
'name="'.$item->typ.'_'.$item->id.'" '.
'size="10" '.
'maxlength="10" '.
'value="" />';
echo '</span>'; echo '</span>';
echo '</div>'; echo '</div>';
} }
/** /**
* print the item at the complete-page of feedback * print the item at the complete-page of feedback
* *
@ -246,47 +305,67 @@ class feedback_item_numeric extends feedback_item_base {
* @param bool $highlightrequire * @param bool $highlightrequire
* @return void * @return void
*/ */
function print_item_complete($item, $value = '', $highlightrequire = false) { public function print_item_complete($item, $value = '', $highlightrequire = false) {
global $OUTPUT; global $OUTPUT;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$str_required_mark = '<span class="feedback_required_mark">*</span>';
//get the range //get the range
$range_from_to = explode('|',$item->presentation); $range_from_to = explode('|', $item->presentation);
//get the min-value //get the min-value
$range_from = (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) ? floatval($range_from_to[0]) : 0; if (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) {
$range_from = floatval($range_from_to[0]);
} else {
$range_from = 0;
}
//get the max-value //get the max-value
$range_to = (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) ? floatval($range_from_to[1]) : 0; if (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) {
if($highlightrequire AND (!$this->check_value($value, $item))) { $range_to = floatval($range_from_to[1]);
} else {
$range_to = 0;
}
if ($highlightrequire AND (!$this->check_value($value, $item))) {
$highlight = ' missingrequire'; $highlight = ' missingrequire';
}else { } else {
$highlight = ''; $highlight = '';
} }
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1) ? $str_required_mark : '';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.$highlight.'">'; echo '<div class="feedback_item_label_'.$align.$highlight.'">';
echo format_text($item->name . $requiredmark, true, false, false); echo format_text($item->name . $requiredmark, true, false, false);
echo '<span class="feedback_item_numinfo">'; echo '<span class="feedback_item_numinfo">';
switch(true) { switch(true) {
case ($range_from === '-' AND is_numeric($range_to)): case ($range_from === '-' AND is_numeric($range_to)):
echo ' ('.get_string('maximal', 'feedback').': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')'; echo ' ('.get_string('maximal', 'feedback').
break; ': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
case (is_numeric($range_from) AND $range_to === '-'): break;
echo ' ('.get_string('minimal', 'feedback').': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).')'; case (is_numeric($range_from) AND $range_to === '-'):
break; echo ' ('.get_string('minimal', 'feedback').
case ($range_from === '-' AND $range_to === '-'): ': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).')';
break; break;
default: case ($range_from === '-' AND $range_to === '-'):
echo ' ('.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).' - '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')'; break;
break; default:
} echo ' ('.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).
echo '</span>'; ' - '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
break;
}
echo '</span>';
echo '</div>'; echo '</div>';
//print the presentation //print the presentation
echo '<div class="feedback_item_presentation_'.$align.$highlight.'">'; echo '<div class="feedback_item_presentation_'.$align.$highlight.'">';
echo '<span class="feedback_item_textfield">'; echo '<span class="feedback_item_textfield">';
echo '<input type="text" name="'.$item->typ.'_'.$item->id.'" size="10" maxlength="10" value="'.($value ? $value : '').'" />'; echo '<input type="text" '.
'name="'.$item->typ.'_'.$item->id.'" '.
'size="10" '.
'maxlength="10" '.
'value="'.($value ? $value : '').'" />';
echo '</span>'; echo '</span>';
echo '</div>'; echo '</div>';
} }
@ -299,79 +378,114 @@ class feedback_item_numeric extends feedback_item_base {
* @param string $value * @param string $value
* @return void * @return void
*/ */
function print_item_show_value($item, $value = '') { public function print_item_show_value($item, $value = '') {
global $OUTPUT; global $OUTPUT;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$str_required_mark = '<span class="feedback_required_mark">*</span>';
//get the range //get the range
$range_from_to = explode('|',$item->presentation); $range_from_to = explode('|', $item->presentation);
//get the min-value //get the min-value
$range_from = (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) ? floatval($range_from_to[0]) : 0; if (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) {
$range_from = floatval($range_from_to[0]);
} else {
$range_from = 0;
}
//get the max-value //get the max-value
$range_to = (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) ? floatval($range_from_to[1]) : 0; if (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) {
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $range_to = floatval($range_from_to[1]);
} else {
$range_to = 0;
}
$requiredmark = ($item->required == 1) ? $str_required_mark : '';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.'">'; echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') '; echo '('.$item->label.') ';
echo format_text($item->name . $requiredmark, true, false, false); echo format_text($item->name . $requiredmark, true, false, false);
switch(true) { switch(true) {
case ($range_from === '-' AND is_numeric($range_to)): case ($range_from === '-' AND is_numeric($range_to)):
echo ' ('.get_string('maximal', 'feedback').': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')'; echo ' ('.get_string('maximal', 'feedback').
break; ': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
case (is_numeric($range_from) AND $range_to === '-'): break;
echo ' ('.get_string('minimal', 'feedback').': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).')'; case (is_numeric($range_from) AND $range_to === '-'):
break; echo ' ('.get_string('minimal', 'feedback').
case ($range_from === '-' AND $range_to === '-'): ': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).')';
break; break;
default: case ($range_from === '-' AND $range_to === '-'):
echo ' ('.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).' - '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')'; break;
break; default:
} echo ' ('.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).
' - '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
break;
}
echo '</div>'; echo '</div>';
//print the presentation //print the presentation
echo '<div class="feedback_item_presentation_'.$align.'">'; echo '<div class="feedback_item_presentation_'.$align.'">';
echo $OUTPUT->box_start('generalbox boxalign'.$align); echo $OUTPUT->box_start('generalbox boxalign'.$align);
echo (is_numeric($value)) ? number_format($value, 2, $this->sep_dec, $this->sep_thous) : '&nbsp;'; if (is_numeric($value)) {
$str_num_value = number_format($value, 2, $this->sep_dec, $this->sep_thous);
} else {
$str_num_value = '&nbsp;';
}
echo $str_num_value;
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
echo '</div>'; echo '</div>';
} }
function check_value($value, $item) { public function check_value($value, $item) {
$value = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $value); $value = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $value);
//if the item is not required, so the check is true if no value is given //if the item is not required, so the check is true if no value is given
if((!isset($value) OR $value == '') AND $item->required != 1) return true; if ((!isset($value) OR $value == '') AND $item->required != 1) {
if(!is_numeric($value))return false; return true;
}
if (!is_numeric($value)) {
return false;
}
$range_from_to = explode('|',$item->presentation); $range_from_to = explode('|', $item->presentation);
$range_from = (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) ? floatval($range_from_to[0]) : '-'; if (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) {
$range_to = (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) ? floatval($range_from_to[1]) : '-'; $range_from = floatval($range_from_to[0]);
} else {
$range_from = '-';
}
if (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) {
$range_to = floatval($range_from_to[1]);
} else {
$range_to = '-';
}
switch(true) { switch(true) {
case ($range_from === '-' AND is_numeric($range_to)): case ($range_from === '-' AND is_numeric($range_to)):
if(floatval($value) <= $range_to) return true; if (floatval($value) <= $range_to) {
return true;
}
break; break;
case (is_numeric($range_from) AND $range_to === '-'): case (is_numeric($range_from) AND $range_to === '-'):
if(floatval($value) >= $range_from) return true; if (floatval($value) >= $range_from) {
return true;
}
break; break;
case ($range_from === '-' AND $range_to === '-'): case ($range_from === '-' AND $range_to === '-'):
return true; return true;
break; break;
default: default:
if(floatval($value) >= $range_from AND floatval($value) <= $range_to) return true; if (floatval($value) >= $range_from AND floatval($value) <= $range_to) {
return true;
}
break; break;
} }
return false; return false;
} }
function create_value($data) { public function create_value($data) {
$data = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data); $data = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data);
if(is_numeric($data)) { if (is_numeric($data)) {
$data = floatval($data); $data = floatval($data);
}else { } else {
$data = ''; $data = '';
} }
return $data; return $data;
@ -380,44 +494,44 @@ class feedback_item_numeric extends feedback_item_base {
//compares the dbvalue with the dependvalue //compares the dbvalue with the dependvalue
//dbvalue is the number put in by the user //dbvalue is the number put in by the user
//dependvalue is the value that is compared //dependvalue is the value that is compared
function compare_value($item, $dbvalue, $dependvalue) { public function compare_value($item, $dbvalue, $dependvalue) {
if($dbvalue == $dependvalue) { if ($dbvalue == $dependvalue) {
return true; return true;
} }
return false; return false;
} }
function get_presentation($data) { public function get_presentation($data) {
$num1 = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data->numericrangefrom); $num1 = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data->numericrangefrom);
if(is_numeric($num1)) { if (is_numeric($num1)) {
$num1 = floatval($num1); $num1 = floatval($num1);
}else { } else {
$num1 = '-'; $num1 = '-';
} }
$num2 = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data->numericrangeto); $num2 = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data->numericrangeto);
if(is_numeric($num2)) { if (is_numeric($num2)) {
$num2 = floatval($num2); $num2 = floatval($num2);
}else { } else {
$num2 = '-'; $num2 = '-';
} }
if($num1 === '-' OR $num2 === '-') { if ($num1 === '-' OR $num2 === '-') {
return $num1 . '|'. $num2; return $num1 . '|'. $num2;
} }
if($num1 > $num2) { if ($num1 > $num2) {
return $num2 . '|'. $num1; return $num2 . '|'. $num1;
}else { } else {
return $num1 . '|'. $num2; return $num1 . '|'. $num2;
} }
} }
function get_hasvalue() { public function get_hasvalue() {
return 1; return 1;
} }
function can_switch_require() { public function can_switch_require() {
return true; return true;
} }
} }

View File

@ -1,17 +1,31 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
class feedback_numeric_form extends feedback_item_form { class feedback_numeric_form extends feedback_item_form {
var $type = "numeric"; protected $type = "numeric";
public function definition() {
function definition() {
$item = $this->_customdata['item']; $item = $this->_customdata['item'];
$common = $this->_customdata['common']; $common = $this->_customdata['common'];
$positionlist = $this->_customdata['positionlist']; $positionlist = $this->_customdata['positionlist'];
$position = $this->_customdata['position']; $position = $this->_customdata['position'];
$mform =& $this->_form; $mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback')); $mform->addElement('header', 'general', get_string($this->type, 'feedback'));
@ -34,46 +48,45 @@ class feedback_numeric_form extends feedback_item_form {
$mform->addElement('text', $mform->addElement('text',
'rangeto', 'rangeto',
get_string('numeric_range_to', 'feedback'), get_string('numeric_range_to', 'feedback'),
array('size'=>10,'maxlength'=>10)); array('size'=>10, 'maxlength'=>10));
parent::definition(); parent::definition();
$this->set_data($item); $this->set_data($item);
} }
function get_data() { public function get_data() {
if(!$item = parent::get_data()) { if (!$item = parent::get_data()) {
return false; return false;
} }
$itemobj = new feedback_item_numeric(); $itemobj = new feedback_item_numeric();
$num1 = str_replace($itemobj->sep_dec, FEEDBACK_DECIMAL, $item->rangefrom); $num1 = str_replace($itemobj->sep_dec, FEEDBACK_DECIMAL, $item->rangefrom);
if(is_numeric($num1)) { if (is_numeric($num1)) {
$num1 = floatval($num1); $num1 = floatval($num1);
}else { } else {
$num1 = '-'; $num1 = '-';
} }
$num2 = str_replace($itemobj->sep_dec, FEEDBACK_DECIMAL, $item->rangeto); $num2 = str_replace($itemobj->sep_dec, FEEDBACK_DECIMAL, $item->rangeto);
if(is_numeric($num2)) { if (is_numeric($num2)) {
$num2 = floatval($num2); $num2 = floatval($num2);
}else { } else {
$num2 = '-'; $num2 = '-';
} }
if($num1 === '-' OR $num2 === '-') { if ($num1 === '-' OR $num2 === '-') {
$item->presentation = $num1 . '|'. $num2; $item->presentation = $num1 . '|'. $num2;
return $item; return $item;
} }
if($num1 > $num2) { if ($num1 > $num2) {
$item->presentation = $num2 . '|'. $num1; $item->presentation = $num2 . '|'. $num1;
}else { } else {
$item->presentation = $num1 . '|'. $num2; $item->presentation = $num1 . '|'. $num2;
} }
return $item; return $item;
} }
} }

View File

@ -1,158 +1,195 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') OR die('not allowed'); defined('MOODLE_INTERNAL') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_textarea extends feedback_item_base { class feedback_item_textarea extends feedback_item_base {
var $type = "textarea"; protected $type = "textarea";
var $commonparams; private $commonparams;
var $item_form; private $item_form;
var $item; private $item;
function init() { public function init() {
} }
function build_editform($item, $feedback, $cm) { public function build_editform($item, $feedback, $cm) {
global $DB, $CFG; global $DB, $CFG;
require_once('textarea_form.php'); require_once('textarea_form.php');
//get the lastposition number of the feedback_items //get the lastposition number of the feedback_items
$position = $item->position; $position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){ if ($position == -1) {
$i_formselect_last = $lastposition + 1; $i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1; $i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1; $item->position = $lastposition + 1;
}else { } else {
$i_formselect_last = $lastposition; $i_formselect_last = $lastposition;
$i_formselect_value = $item->position; $i_formselect_value = $item->position;
} }
//the elements for position dropdownlist //the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true); $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
$item->presentation = empty($item->presentation) ? '' : $item->presentation; $item->presentation = empty($item->presentation) ? '' : $item->presentation;
$widthAndHeight = explode('|',$item->presentation); $width_and_height = explode('|', $item->presentation);
$itemwidth = (isset($widthAndHeight[0]) AND $widthAndHeight[0] >= 5) ? $widthAndHeight[0] : 30;
$itemheight = isset($widthAndHeight[1]) ? $widthAndHeight[1] : 5; if (isset($width_and_height[0]) AND $width_and_height[0] >= 5) {
$itemwidth = $width_and_height[0];
} else {
$itemwidth = 30;
}
if (isset($width_and_height[1])) {
$itemheight = $width_and_height[1];
} else {
$itemheight = 5;
}
$item->itemwidth = $itemwidth; $item->itemwidth = $itemwidth;
$item->itemheight = $itemheight; $item->itemheight = $itemheight;
//all items for dependitem //all items for dependitem
$feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
$commonparams = array('cmid'=>$cm->id, $commonparams = array('cmid'=>$cm->id,
'id'=>isset($item->id) ? $item->id : NULL, 'id'=>isset($item->id) ? $item->id : null,
'typ'=>$item->typ, 'typ'=>$item->typ,
'items'=>$feedbackitems, 'items'=>$feedbackitems,
'feedback'=>$feedback->id); 'feedback'=>$feedback->id);
//build the form //build the form
$this->item_form = new feedback_textarea_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position)); $customdata = array('item' => $item,
'common' => $commonparams,
'positionlist' => $positionlist,
'position' => $position);
$this->item_form = new feedback_textarea_form('edit_item.php', $customdata);
} }
//this function only can used after the call of build_editform() //this function only can used after the call of build_editform()
function show_editform() { public function show_editform() {
$this->item_form->display(); $this->item_form->display();
} }
function is_cancelled() { public function is_cancelled() {
return $this->item_form->is_cancelled(); return $this->item_form->is_cancelled();
} }
function get_data() { public function get_data() {
if($this->item = $this->item_form->get_data()) { if ($this->item = $this->item_form->get_data()) {
return true; return true;
} }
return false; return false;
} }
function save_item() { public function save_item() {
global $DB; global $DB;
if(!$item = $this->item_form->get_data()) { if (!$item = $this->item_form->get_data()) {
return false; return false;
} }
if(isset($item->clone_item) AND $item->clone_item) { if (isset($item->clone_item) AND $item->clone_item) {
$item->id = ''; //to clone this item $item->id = ''; //to clone this item
$item->position++; $item->position++;
} }
$item->hasvalue = $this->get_hasvalue(); $item->hasvalue = $this->get_hasvalue();
if(!$item->id) { if (!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item); $item->id = $DB->insert_record('feedback_item', $item);
}else { } else {
$DB->update_record('feedback_item', $item); $DB->update_record('feedback_item', $item);
} }
return $DB->get_record('feedback_item', array('id'=>$item->id)); return $DB->get_record('feedback_item', array('id'=>$item->id));
} }
//liefert eine Struktur ->name, ->data = array(mit Antworten) //liefert eine Struktur ->name, ->data = array(mit Antworten)
function get_analysed($item, $groupid = false, $courseid = false) { public function get_analysed($item, $groupid = false, $courseid = false) {
global $DB; global $DB;
$aVal = null; $analysed_val = null;
$aVal->data = array(); $analysed_val->data = array();
$aVal->name = $item->name; $analysed_val->name = $item->name;
//$values = $DB->get_records('feedback_value', array('item'=>$item->id));
$values = feedback_get_group_values($item, $groupid, $courseid); $values = feedback_get_group_values($item, $groupid, $courseid);
if($values) { if ($values) {
$data = array(); $data = array();
foreach($values as $value) { foreach ($values as $value) {
$data[] = str_replace("\n", '<br />', $value->value); $data[] = str_replace("\n", '<br />', $value->value);
} }
$aVal->data = $data; $analysed_val->data = $data;
} }
return $aVal; return $analysed_val;
} }
function get_printval($item, $value) { public function get_printval($item, $value) {
if(!isset($value->value)) return ''; if (!isset($value->value)) {
return '';
}
return $value->value; return $value->value;
} }
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
$values = feedback_get_group_values($item, $groupid, $courseid); $values = feedback_get_group_values($item, $groupid, $courseid);
if($values) { if ($values) {
//echo '<table>';2 echo '<tr><th colspan="2" align="left">';
// $itemnr++; echo $itemnr.'&nbsp;('.$item->label.') '.$item->name;
echo '<tr><th colspan="2" align="left">'. $itemnr . '&nbsp;('. $item->label .') ' . $item->name .'</th></tr>'; echo '</th></tr>';
foreach($values as $value) { foreach ($values as $value) {
echo '<tr><td valign="top" align="left">-&nbsp;&nbsp;</td><td align="left" valign="top">' . str_replace("\n", '<br />', $value->value) . '</td></tr>'; echo '<tr>';
echo '<td valign="top" align="left">';
echo '-&nbsp;&nbsp;';
echo '</td>';
echo '<td align="left" valign="top">';
echo str_replace("\n", '<br />', $value->value);
echo '</td>';
echo '</tr>';
} }
//echo '</table>';
} }
// return $itemnr;
} }
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) { public function excelprint_item(&$worksheet, $row_offset,
$xls_formats, $item,
$groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid); $analysed_item = $this->get_analysed($item, $groupid, $courseid);
// $worksheet->setFormat("<l><f><ro2><vo><c:green>"); $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2);
$worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2); $worksheet->write_string($row_offset, 1, $item->name, $xls_formats->head2);
$worksheet->write_string($rowOffset, 1, $item->name, $xlsFormats->head2);
$data = $analysed_item->data; $data = $analysed_item->data;
if(is_array($data)) { if (is_array($data)) {
// $worksheet->setFormat("<l><ro2><vo>"); if (isset($data[0])) {
if(isset($data[0])) { $worksheet->write_string($row_offset, 2, $data[0], $xls_formats->value_bold);
$worksheet->write_string($rowOffset, 2, $data[0], $xlsFormats->value_bold);
} }
$rowOffset++; $row_offset++;
$sizeofdata = sizeof($data); $sizeofdata = count($data);
for($i = 1; $i < $sizeofdata; $i++) { for ($i = 1; $i < $sizeofdata; $i++) {
// $worksheet->setFormat("<l><vo>"); $worksheet->write_string($row_offset, 2, $data[$i], $xls_formats->default);
$worksheet->write_string($rowOffset, 2, $data[$i], $xlsFormats->default); $row_offset++;
$rowOffset++;
} }
} }
$rowOffset++; $row_offset++;
return $rowOffset; return $row_offset;
} }
/** /**
* print the item at the edit-page of feedback * print the item at the edit-page of feedback
* *
@ -160,20 +197,23 @@ class feedback_item_textarea extends feedback_item_base {
* @param object $item * @param object $item
* @return void * @return void
*/ */
function print_item_preview($item) { public function print_item_preview($item) {
global $OUTPUT, $DB; global $OUTPUT, $DB;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$str_required_mark = '<span class="feedback_required_mark">*</span>';
$presentation = explode ("|", $item->presentation); $presentation = explode ("|", $item->presentation);
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1) ? $str_required_mark : '';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.'">'; echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') '; echo '('.$item->label.') ';
echo format_text($item->name.$requiredmark, true, false, false); echo format_text($item->name.$requiredmark, true, false, false);
if($item->dependitem) { if ($item->dependitem) {
if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
echo ' <span class="feedback_depend">('.$dependitem->label.'-&gt;'.$item->dependvalue.')</span>'; echo ' <span class="feedback_depend">';
echo '('.$dependitem->label.'-&gt;'.$item->dependvalue.')';
echo '</span>';
} }
} }
echo '</div>'; echo '</div>';
@ -181,11 +221,14 @@ class feedback_item_textarea extends feedback_item_base {
//print the presentation //print the presentation
echo '<div class="feedback_item_presentation_'.$align.'">'; echo '<div class="feedback_item_presentation_'.$align.'">';
echo '<span class="feedback_item_textarea">'; echo '<span class="feedback_item_textarea">';
echo '<textarea name="'.$item->typ.'_'.$item->id.'" cols="'.$presentation[0].'" rows="'.$presentation[1].'"></textarea>'; echo '<textarea name="'.$item->typ.'_'.$item->id.'" '.
'cols="'.$presentation[0].'" '.
'rows="'.$presentation[1].'">';
echo '</textarea>';
echo '</span>'; echo '</span>';
echo '</div>'; echo '</div>';
} }
/** /**
* print the item at the complete-page of feedback * print the item at the complete-page of feedback
* *
@ -195,27 +238,32 @@ class feedback_item_textarea extends feedback_item_base {
* @param bool $highlightrequire * @param bool $highlightrequire
* @return void * @return void
*/ */
function print_item_complete($item, $value = '', $highlightrequire = false) { public function print_item_complete($item, $value = '', $highlightrequire = false) {
global $OUTPUT; global $OUTPUT;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$str_required_mark = '<span class="feedback_required_mark">*</span>';
$presentation = explode ("|", $item->presentation); $presentation = explode ("|", $item->presentation);
if($highlightrequire AND $item->required AND strval($value) == '') { if ($highlightrequire AND $item->required AND strval($value) == '') {
$highlight = ' missingrequire'; $highlight = ' missingrequire';
}else { } else {
$highlight = ''; $highlight = '';
} }
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1) ? $str_required_mark :'';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.$highlight.'">'; echo '<div class="feedback_item_label_'.$align.$highlight.'">';
echo format_text($item->name . $requiredmark, true, false, false); echo format_text($item->name . $requiredmark, true, false, false);
echo '</div>'; echo '</div>';
//print the presentation //print the presentation
echo '<div class="feedback_item_presentation_'.$align.$highlight.'">'; echo '<div class="feedback_item_presentation_'.$align.$highlight.'">';
echo '<span class="feedback_item_textarea">'; echo '<span class="feedback_item_textarea">';
echo '<textarea name="'.$item->typ.'_'.$item->id.'" cols="'.$presentation[0].'" rows="'.$presentation[1].'">'.($value ? htmlspecialchars($value) : '').'</textarea>'; echo '<textarea name="'.$item->typ.'_'.$item->id.'" '.
'cols="'.$presentation[0].'" '.
'rows="'.$presentation[1].'">';
echo ($value ? htmlspecialchars($value) : '');
echo '</textarea>';
echo '</span>'; echo '</span>';
echo '</div>'; echo '</div>';
} }
@ -228,33 +276,38 @@ class feedback_item_textarea extends feedback_item_base {
* @param string $value * @param string $value
* @return void * @return void
*/ */
function print_item_show_value($item, $value = '') { public function print_item_show_value($item, $value = '') {
global $OUTPUT; global $OUTPUT;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$str_required_mark = '<span class="feedback_required_mark">*</span>';
$presentation = explode ("|", $item->presentation); $presentation = explode ("|", $item->presentation);
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1) ? $str_required_mark : '';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.'">'; echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') '; echo '('.$item->label.') ';
echo format_text($item->name . $requiredmark, true, false, false); echo format_text($item->name . $requiredmark, true, false, false);
echo '</div>'; echo '</div>';
//print the presentation //print the presentation
echo $OUTPUT->box_start('generalbox boxalign'.$align); echo $OUTPUT->box_start('generalbox boxalign'.$align);
echo $value?str_replace("\n",'<br />',$value):'&nbsp;'; echo $value ? str_replace("\n", '<br />', $value) : '&nbsp;';
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
function check_value($value, $item) { public function check_value($value, $item) {
//if the item is not required, so the check is true if no value is given //if the item is not required, so the check is true if no value is given
if((!isset($value) OR $value == '') AND $item->required != 1) return true; if ((!isset($value) OR $value == '') AND $item->required != 1) {
if($value == "")return false; return true;
}
if ($value == "") {
return false;
}
return true; return true;
} }
function create_value($data) { public function create_value($data) {
$data = clean_text($data); $data = clean_text($data);
return $data; return $data;
} }
@ -262,22 +315,22 @@ class feedback_item_textarea extends feedback_item_base {
//compares the dbvalue with the dependvalue //compares the dbvalue with the dependvalue
//dbvalue is the value put in by the user //dbvalue is the value put in by the user
//dependvalue is the value that is compared //dependvalue is the value that is compared
function compare_value($item, $dbvalue, $dependvalue) { public function compare_value($item, $dbvalue, $dependvalue) {
if($dbvalue == $dependvalue) { if ($dbvalue == $dependvalue) {
return true; return true;
} }
return false; return false;
} }
function get_presentation($data) { public function get_presentation($data) {
return $data->itemwidth . '|'. $data->itemheight; return $data->itemwidth.'|'.$data->itemheight;
} }
function get_hasvalue() { public function get_hasvalue() {
return 1; return 1;
} }
function can_switch_require() { public function can_switch_require() {
return true; return true;
} }
} }

View File

@ -1,11 +1,25 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
class feedback_textarea_form extends feedback_item_form { class feedback_textarea_form extends feedback_item_form {
var $type = "textarea"; protected $type = "textarea";
function definition() { public function definition() {
$item = $this->_customdata['item']; $item = $this->_customdata['item'];
$common = $this->_customdata['common']; $common = $this->_customdata['common'];
$positionlist = $this->_customdata['positionlist']; $positionlist = $this->_customdata['positionlist'];
@ -28,23 +42,23 @@ class feedback_textarea_form extends feedback_item_form {
$mform->addElement('select', $mform->addElement('select',
'itemwidth', 'itemwidth',
get_string('textarea_width', 'feedback').'&nbsp;', get_string('textarea_width', 'feedback').'&nbsp;',
array_slice(range(0,80),5,80,true)); array_slice(range(0, 80), 5, 80, true));
$mform->addElement('select', $mform->addElement('select',
'itemheight', 'itemheight',
get_string('textarea_height', 'feedback').'&nbsp;', get_string('textarea_height', 'feedback').'&nbsp;',
array_slice(range(0,40),5,40,true)); array_slice(range(0, 40), 5, 40, true));
parent::definition(); parent::definition();
$this->set_data($item); $this->set_data($item);
} }
function get_data() { public function get_data() {
if(!$item = parent::get_data()) { if (!$item = parent::get_data()) {
return false; return false;
} }
$item->presentation = $item->itemwidth . '|'. $item->itemheight; $item->presentation = $item->itemwidth . '|'. $item->itemheight;
return $item; return $item;
} }

View File

@ -1,155 +1,184 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') OR die('not allowed'); defined('MOODLE_INTERNAL') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_textfield extends feedback_item_base { class feedback_item_textfield extends feedback_item_base {
var $type = "textfield"; protected $type = "textfield";
var $commonparams; private $commonparams;
var $item_form; private $item_form;
var $item; private $item;
function init() { public function init() {
} }
function build_editform($item, $feedback, $cm) { public function build_editform($item, $feedback, $cm) {
global $DB, $CFG; global $DB, $CFG;
require_once('textfield_form.php'); require_once('textfield_form.php');
//get the lastposition number of the feedback_items //get the lastposition number of the feedback_items
$position = $item->position; $position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){ if ($position == -1) {
$i_formselect_last = $lastposition + 1; $i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1; $i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1; $item->position = $lastposition + 1;
}else { } else {
$i_formselect_last = $lastposition; $i_formselect_last = $lastposition;
$i_formselect_value = $item->position; $i_formselect_value = $item->position;
} }
//the elements for position dropdownlist //the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true); $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
$item->presentation = empty($item->presentation) ? '' : $item->presentation; $item->presentation = empty($item->presentation) ? '' : $item->presentation;
$sizeAndLength = explode('|',$item->presentation); $size_and_length = explode('|', $item->presentation);
$itemsize = (isset($sizeAndLength[0]) AND $sizeAndLength[0] >= 5) ? $sizeAndLength[0] : 30;
$itemlength = isset($sizeAndLength[1]) ? $sizeAndLength[1] : 5; if (isset($size_and_length[0]) AND $size_and_length[0] >= 5) {
$itemsize = $size_and_length[0];
} else {
$itemsize = 30;
}
$itemlength = isset($size_and_length[1]) ? $size_and_length[1] : 5;
$item->itemsize = $itemsize; $item->itemsize = $itemsize;
$item->itemmaxlength = $itemlength; $item->itemmaxlength = $itemlength;
//all items for dependitem //all items for dependitem
$feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
$commonparams = array('cmid'=>$cm->id, $commonparams = array('cmid' => $cm->id,
'id'=>isset($item->id) ? $item->id : NULL, 'id' => isset($item->id) ? $item->id : null,
'typ'=>$item->typ, 'typ' => $item->typ,
'items'=>$feedbackitems, 'items' => $feedbackitems,
'feedback'=>$feedback->id); 'feedback' => $feedback->id);
//build the form //build the form
$this->item_form = new feedback_textfield_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position)); $customdata = array('item' => $item,
'common' => $commonparams,
'positionlist' => $positionlist,
'position' => $position);
$this->item_form = new feedback_textfield_form('edit_item.php', $customdata);
} }
//this function only can used after the call of build_editform() //this function only can used after the call of build_editform()
function show_editform() { public function show_editform() {
$this->item_form->display(); $this->item_form->display();
} }
function is_cancelled() { public function is_cancelled() {
return $this->item_form->is_cancelled(); return $this->item_form->is_cancelled();
} }
function get_data() { public function get_data() {
if($this->item = $this->item_form->get_data()) { if ($this->item = $this->item_form->get_data()) {
return true; return true;
} }
return false; return false;
} }
function save_item() { public function save_item() {
global $DB; global $DB;
if(!$item = $this->item_form->get_data()) { if (!$item = $this->item_form->get_data()) {
return false; return false;
} }
if(isset($item->clone_item) AND $item->clone_item) { if (isset($item->clone_item) AND $item->clone_item) {
$item->id = ''; //to clone this item $item->id = ''; //to clone this item
$item->position++; $item->position++;
} }
$item->hasvalue = $this->get_hasvalue(); $item->hasvalue = $this->get_hasvalue();
if(!$item->id) { if (!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item); $item->id = $DB->insert_record('feedback_item', $item);
}else { } else {
$DB->update_record('feedback_item', $item); $DB->update_record('feedback_item', $item);
} }
return $DB->get_record('feedback_item', array('id'=>$item->id)); return $DB->get_record('feedback_item', array('id'=>$item->id));
} }
//liefert eine Struktur ->name, ->data = array(mit Antworten) //liefert eine Struktur ->name, ->data = array(mit Antworten)
function get_analysed($item, $groupid = false, $courseid = false) { public function get_analysed($item, $groupid = false, $courseid = false) {
global $DB; global $DB;
$aVal = null; $analysed_val = null;
$aVal->data = null; $analysed_val->data = null;
$aVal->name = $item->name; $analysed_val->name = $item->name;
//$values = $DB->get_records('feedback_value', array('item'=>$item->id));
$values = feedback_get_group_values($item, $groupid, $courseid); $values = feedback_get_group_values($item, $groupid, $courseid);
if($values) { if ($values) {
$data = array(); $data = array();
foreach($values as $value) { foreach ($values as $value) {
$data[] = str_replace("\n", '<br />', $value->value); $data[] = str_replace("\n", '<br />', $value->value);
} }
$aVal->data = $data; $analysed_val->data = $data;
} }
return $aVal; return $analysed_val;
} }
function get_printval($item, $value) { public function get_printval($item, $value) {
if(!isset($value->value)) return ''; if (!isset($value->value)) {
return '';
}
return $value->value; return $value->value;
} }
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
$values = feedback_get_group_values($item, $groupid, $courseid); $values = feedback_get_group_values($item, $groupid, $courseid);
if($values) { if ($values) {
//echo '<table>';2 echo '<tr><th colspan="2" align="left">';
// $itemnr++; echo $itemnr.'&nbsp;('.$item->label.') '.$item->name;
echo '<tr><th colspan="2" align="left">'. $itemnr . '&nbsp;('. $item->label .') ' . $item->name .'</th></tr>'; echo '</th></tr>';
foreach($values as $value) { foreach ($values as $value) {
echo '<tr><td colspan="2" valign="top" align="left">-&nbsp;&nbsp;' . str_replace("\n", '<br />', $value->value) . '</td></tr>'; echo '<tr><td colspan="2" valign="top" align="left">';
echo '-&nbsp;&nbsp;'.str_replace("\n", '<br />', $value->value);
echo '</td></tr>';
} }
//echo '</table>';
} }
// return $itemnr;
} }
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) { public function excelprint_item(&$worksheet, $row_offset,
$xls_formats, $item,
$groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid); $analysed_item = $this->get_analysed($item, $groupid, $courseid);
// $worksheet->setFormat("<l><f><ro2><vo><c:green>"); $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2);
$worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2); $worksheet->write_string($row_offset, 1, $item->name, $xls_formats->head2);
$worksheet->write_string($rowOffset, 1, $item->name, $xlsFormats->head2);
$data = $analysed_item->data; $data = $analysed_item->data;
if(is_array($data)) { if (is_array($data)) {
// $worksheet->setFormat("<l><ro2><vo>"); $worksheet->write_string($row_offset, 2, $data[0], $xls_formats->value_bold);
$worksheet->write_string($rowOffset, 2, $data[0], $xlsFormats->value_bold); $row_offset++;
$rowOffset++; $sizeofdata = count($data);
$sizeofdata = sizeof($data); for ($i = 1; $i < $sizeofdata; $i++) {
for($i = 1; $i < $sizeofdata; $i++) { $worksheet->write_string($row_offset, 2, $data[$i], $xls_formats->default);
// $worksheet->setFormat("<l><vo>"); $row_offset++;
$worksheet->write_string($rowOffset, 2, $data[$i], $xlsFormats->default);
$rowOffset++;
} }
} }
$rowOffset++; $row_offset++;
return $rowOffset; return $row_offset;
} }
/** /**
* print the item at the edit-page of feedback * print the item at the edit-page of feedback
* *
@ -157,19 +186,22 @@ class feedback_item_textfield extends feedback_item_base {
* @param object $item * @param object $item
* @return void * @return void
*/ */
function print_item_preview($item) { public function print_item_preview($item) {
global $OUTPUT, $DB; global $OUTPUT, $DB;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$str_required_mark = '<span class="feedback_required_mark">*</span>';
$presentation = explode ("|", $item->presentation); $presentation = explode ("|", $item->presentation);
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1) ? $str_required_mark : '';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.'">'; echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') '; echo '('.$item->label.') ';
echo format_text($item->name.$requiredmark, true, false, false); echo format_text($item->name.$requiredmark, true, false, false);
if($item->dependitem) { if ($item->dependitem) {
if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
echo ' <span class="feedback_depend">('.$dependitem->label.'-&gt;'.$item->dependvalue.')</span>'; echo ' <span class="feedback_depend">';
echo '('.$dependitem->label.'-&gt;'.$item->dependvalue.')';
echo '</span>';
} }
} }
echo '</div>'; echo '</div>';
@ -177,11 +209,15 @@ class feedback_item_textfield extends feedback_item_base {
//print the presentation //print the presentation
echo '<div class="feedback_item_presentation_'.$align.'">'; echo '<div class="feedback_item_presentation_'.$align.'">';
echo '<span class="feedback_item_textfield">'; echo '<span class="feedback_item_textfield">';
echo '<input type="text" name="'.$item->typ . '_' . $item->id.'" size="'.$presentation[0].'" maxlength="'.$presentation[1].'" value="" />'; echo '<input type="text" '.
'name="'.$item->typ.'_'.$item->id.'" '.
'size="'.$presentation[0].'" '.
'maxlength="'.$presentation[1].'" '.
'value="" />';
echo '</span>'; echo '</span>';
echo '</div>'; echo '</div>';
} }
/** /**
* print the item at the complete-page of feedback * print the item at the complete-page of feedback
* *
@ -191,27 +227,32 @@ class feedback_item_textfield extends feedback_item_base {
* @param bool $highlightrequire * @param bool $highlightrequire
* @return void * @return void
*/ */
function print_item_complete($item, $value = '', $highlightrequire = false) { public function print_item_complete($item, $value = '', $highlightrequire = false) {
global $OUTPUT; global $OUTPUT;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$str_required_mark = '<span class="feedback_required_mark">*</span>';
$presentation = explode ("|", $item->presentation); $presentation = explode ("|", $item->presentation);
if($highlightrequire AND $item->required AND strval($value) == '') { if ($highlightrequire AND $item->required AND strval($value) == '') {
$highlight = ' missingrequire'; $highlight = ' missingrequire';
}else { } else {
$highlight = ''; $highlight = '';
} }
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1) ? $str_required_mark : '';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.$highlight.'">'; echo '<div class="feedback_item_label_'.$align.$highlight.'">';
echo format_text($item->name.$requiredmark, true, false, false); echo format_text($item->name.$requiredmark, true, false, false);
echo '</div>'; echo '</div>';
//print the presentation //print the presentation
echo '<div class="feedback_item_presentation_'.$align.$highlight.'">'; echo '<div class="feedback_item_presentation_'.$align.$highlight.'">';
echo '<span class="feedback_item_textfield">'; echo '<span class="feedback_item_textfield">';
echo '<input type="text" name="'.$item->typ.'_'.$item->id.'" size="'.$presentation[0].'" maxlength="'.$presentation[1].'" value="'.($value ? htmlspecialchars($value) : '').'" />'; echo '<input type="text" '.
'name="'.$item->typ.'_'.$item->id.'" '.
'size="'.$presentation[0].'" '.
'maxlength="'.$presentation[1].'" '.
'value="'.($value ? htmlspecialchars($value) : '').'" />';
echo '</span>'; echo '</span>';
echo '</div>'; echo '</div>';
} }
@ -224,13 +265,14 @@ class feedback_item_textfield extends feedback_item_base {
* @param string $value * @param string $value
* @return void * @return void
*/ */
function print_item_show_value($item, $value = '') { public function print_item_show_value($item, $value = '') {
global $OUTPUT; global $OUTPUT;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$str_required_mark = '<span class="feedback_required_mark">*</span>';
$presentation = explode ("|", $item->presentation); $presentation = explode ("|", $item->presentation);
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; $requiredmark = ($item->required == 1) ? $str_required_mark : '';
//print the question and label //print the question and label
echo '<div class="feedback_item_label_'.$align.'">'; echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') '; echo '('.$item->label.') ';
@ -241,14 +283,18 @@ class feedback_item_textfield extends feedback_item_base {
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
function check_value($value, $item) { public function check_value($value, $item) {
//if the item is not required, so the check is true if no value is given //if the item is not required, so the check is true if no value is given
if((!isset($value) OR $value == '') AND $item->required != 1) return true; if ((!isset($value) OR $value == '') AND $item->required != 1) {
if($value == "")return false; return true;
}
if ($value == "") {
return false;
}
return true; return true;
} }
function create_value($data) { public function create_value($data) {
$data = clean_text($data); $data = clean_text($data);
return $data; return $data;
} }
@ -256,22 +302,22 @@ class feedback_item_textfield extends feedback_item_base {
//compares the dbvalue with the dependvalue //compares the dbvalue with the dependvalue
//dbvalue is the value put in by the user //dbvalue is the value put in by the user
//dependvalue is the value that is compared //dependvalue is the value that is compared
function compare_value($item, $dbvalue, $dependvalue) { public function compare_value($item, $dbvalue, $dependvalue) {
if($dbvalue == $dependvalue) { if ($dbvalue == $dependvalue) {
return true; return true;
} }
return false; return false;
} }
function get_presentation($data) { public function get_presentation($data) {
return $data->itemsize . '|'. $data->itemmaxlength; return $data->itemsize . '|'. $data->itemmaxlength;
} }
function get_hasvalue() { public function get_hasvalue() {
return 1; return 1;
} }
function can_switch_require() { public function can_switch_require() {
return true; return true;
} }
} }

View File

@ -1,11 +1,25 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php'); require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
class feedback_textfield_form extends feedback_item_form { class feedback_textfield_form extends feedback_item_form {
var $type = "textfield"; protected $type = "textfield";
function definition() { public function definition() {
$item = $this->_customdata['item']; $item = $this->_customdata['item'];
$common = $this->_customdata['common']; $common = $this->_customdata['common'];
$positionlist = $this->_customdata['positionlist']; $positionlist = $this->_customdata['positionlist'];
@ -28,23 +42,23 @@ class feedback_textfield_form extends feedback_item_form {
$mform->addElement('select', $mform->addElement('select',
'itemsize', 'itemsize',
get_string('textfield_size', 'feedback').'&nbsp;', get_string('textfield_size', 'feedback').'&nbsp;',
array_slice(range(0,255),5,255,true)); array_slice(range(0, 255), 5, 255, true));
$mform->addElement('select', $mform->addElement('select',
'itemmaxlength', 'itemmaxlength',
get_string('textfield_maxlength', 'feedback').'&nbsp;', get_string('textfield_maxlength', 'feedback').'&nbsp;',
array_slice(range(0,255),5,255,true)); array_slice(range(0, 255), 5, 255, true));
parent::definition(); parent::definition();
$this->set_data($item); $this->set_data($item);
} }
function get_data() { public function get_data() {
if(!$item = parent::get_data()) { if (!$item = parent::get_data()) {
return false; return false;
} }
$item->presentation = $item->itemsize . '|'. $item->itemmaxlength; $item->presentation = $item->itemsize . '|'. $item->itemmaxlength;
return $item; return $item;
} }

View File

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -97,12 +96,12 @@ $string['edit_items'] = 'Edit questions';
$string['email_notification'] = 'Send e-mail notifications'; $string['email_notification'] = 'Send e-mail notifications';
$string['emailnotification'] = 'emailnotifications'; $string['emailnotification'] = 'emailnotifications';
$string['emailnotification_help'] = 'If enabled, administrators receive email notification of feedback submissions.'; $string['emailnotification_help'] = 'If enabled, administrators receive email notification of feedback submissions.';
$string['emailteachermail'] = '{$a->username} has completed feedback activity : \'{$a->feedback}\' $string['emailteachermail'] = '{$a->username} has completed feedback activity : \'{$a->feedback}\'
You can view it here: You can view it here:
{$a->url}'; {$a->url}';
$string['emailteachermailhtml'] = '{$a->username} has completed feedback activity : <i>\'{$a->feedback}\'</i><br /><br /> $string['emailteachermailhtml'] = '{$a->username} has completed feedback activity : <i>\'{$a->feedback}\'</i><br /><br />
You can view it <a href="{$a->url}">here</a>.'; You can view it <a href="{$a->url}">here</a>.';
$string['entries_saved'] = 'Your answers have been saved. Thank you.'; $string['entries_saved'] = 'Your answers have been saved. Thank you.';
$string['export_questions'] = 'Export questions'; $string['export_questions'] = 'Export questions';

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* print the form to map courses for global feedbacks * print the form to map courses for global feedbacks
@ -29,11 +43,10 @@ if ($courseid !== false) {
} }
$PAGE->set_url($url); $PAGE->set_url($url);
if(($formdata = data_submitted()) AND !confirm_sesskey()) { if (($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey'); print_error('invalidsesskey');
} }
// $SESSION->feedback->current_tab = 'mapcourse';
$current_tab = 'mapcourse'; $current_tab = 'mapcourse';
if (! $cm = get_coursemodule_from_id('feedback', $id)) { if (! $cm = get_coursemodule_from_id('feedback', $id)) {
@ -76,7 +89,7 @@ $PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name)); $PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header(); echo $OUTPUT->header();
include('tabs.php'); require('tabs.php');
echo $OUTPUT->box(get_string('mapcourseinfo', 'feedback'), 'generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box(get_string('mapcourseinfo', 'feedback'), 'generalbox boxaligncenter boxwidthwide');
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
@ -95,18 +108,22 @@ if (($courses = $DB->get_records_sql_menu($sql, $params)) && !empty($searchcours
echo html_writer::select($courses, 'coursefilter', $coursefilter); echo html_writer::select($courses, 'coursefilter', $coursefilter);
echo '<input type="submit" value="'.get_string('mapcourse', 'feedback').'"/>'; echo '<input type="submit" value="'.get_string('mapcourse', 'feedback').'"/>';
echo $OUTPUT->help_icon('mapcourses', 'feedback'); echo $OUTPUT->help_icon('mapcourses', 'feedback');
echo '<input type="button" value="'.get_string('searchagain').'" onclick="document.location=\'mapcourse.php?id='.$id.'\'"/>'; echo '<input type="button" '.
'value="'.get_string('searchagain').'" '.
'onclick="document.location=\'mapcourse.php?id='.$id.'\'"/>';
echo '<input type="hidden" name="searchcourse" value="'.$searchcourse.'"/>'; echo '<input type="hidden" name="searchcourse" value="'.$searchcourse.'"/>';
echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'"/>'; echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'"/>';
echo $OUTPUT->help_icon('searchcourses', 'feedback'); echo $OUTPUT->help_icon('searchcourses', 'feedback');
} else { } else {
echo '<input type="text" name="searchcourse" value="'.$searchcourse.'"/> <input type="submit" value="'.get_string('searchcourses').'"/>'; echo '<input type="text" name="searchcourse" value="'.$searchcourse.'"/> ';
echo '<input type="submit" value="'.get_string('searchcourses').'"/>';
echo $OUTPUT->help_icon('searchcourses', 'feedback'); echo $OUTPUT->help_icon('searchcourses', 'feedback');
} }
echo '</form>'; echo '</form>';
if($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) { if ($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) {
$table = new flexible_table('coursemaps'); $table = new flexible_table('coursemaps');
$table->define_columns( array('course')); $table->define_columns( array('course'));
$table->define_headers( array(get_string('mappedcourses', 'feedback'))); $table->define_headers( array(get_string('mappedcourses', 'feedback')));
@ -117,9 +134,13 @@ if($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) {
foreach ($coursemap as $cmap) { foreach ($coursemap as $cmap) {
$cmapcontext = get_context_instance(CONTEXT_COURSE, $cmap->id); $cmapcontext = get_context_instance(CONTEXT_COURSE, $cmap->id);
$cmapshortname = format_string($cmap->shortname, true, array('context' => $cmapcontext)); $cmapshortname = format_string($cmap->shortname, true, array('context' => $cmapcontext));
$cmapfullname = format_string($cmap->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $cmap->courseid))); $coursecontext = get_context_instance(CONTEXT_COURSE, $cmap->courseid);
$cmapfullname = format_string($cmap->fullname, true, array('context' => $coursecontext));
$unmapurl->params(array('id'=>$id, 'cmapid'=>$cmap->id)); $unmapurl->params(array('id'=>$id, 'cmapid'=>$cmap->id));
$table->add_data(array('<a href="'.$unmapurl->out().'"><img src="'.$OUTPUT->pix_url('t/delete') . '" alt="Delete" /></a> ('.$cmapshortname.') '.$cmapfullname)); $anker = '<a href="'.$unmapurl->out().'">';
$anker .= '<img src="'.$OUTPUT->pix_url('t/delete').'" alt="Delete" />';
$anker .= '</a>';
$table->add_data(array($anker.' ('.$cmapshortname.') '.$cmapfullname));
} }
$table->print_html(); $table->print_html();
@ -131,4 +152,3 @@ if($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) {
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
echo $OUTPUT->footer(); echo $OUTPUT->footer();

View File

@ -1,21 +1,37 @@
<?php <?php
/** // This file is part of Moodle - http://moodle.org/
* print the form to add or edit a feedback-instance //
* // Moodle is free software: you can redistribute it and/or modify
* @author Andreas Grabs // it under the terms of the GNU General Public License as published by
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License // the Free Software Foundation, either version 3 of the License, or
* @package feedback // (at your option) any later version.
*/ //
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* print the form to add or edit a feedback-instance
*
* @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback
*/
//It must be included from a Moodle page
if (!defined('MOODLE_INTERNAL')) { if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page die('Direct access to this script is forbidden.');
} }
require_once ($CFG->dirroot.'/course/moodleform_mod.php'); require_once($CFG->dirroot.'/course/moodleform_mod.php');
class mod_feedback_mod_form extends moodleform_mod { class mod_feedback_mod_form extends moodleform_mod {
function definition() { public function definition() {
global $CFG, $DB; global $CFG, $DB;
$mform =& $this->_form; $mform =& $this->_form;
@ -33,16 +49,32 @@ class mod_feedback_mod_form extends moodleform_mod {
$mform->addElement('header', 'timinghdr', get_string('timing', 'form')); $mform->addElement('header', 'timinghdr', get_string('timing', 'form'));
$enableopengroup = array(); $enableopengroup = array();
$enableopengroup[] =& $mform->createElement('checkbox', 'openenable', get_string('feedbackopen', 'feedback')); $enableopengroup[] =& $mform->createElement('checkbox',
'openenable',
get_string('feedbackopen', 'feedback'));
$enableopengroup[] =& $mform->createElement('date_time_selector', 'timeopen', ''); $enableopengroup[] =& $mform->createElement('date_time_selector', 'timeopen', '');
$mform->addGroup($enableopengroup, 'enableopengroup', get_string('feedbackopen', 'feedback'), ' ', false); $mform->addGroup($enableopengroup,
'enableopengroup',
get_string('feedbackopen', 'feedback'),
' ',
false);
$mform->addHelpButton('enableopengroup', 'timeopen', 'feedback'); $mform->addHelpButton('enableopengroup', 'timeopen', 'feedback');
$mform->disabledIf('enableopengroup', 'openenable', 'notchecked'); $mform->disabledIf('enableopengroup', 'openenable', 'notchecked');
$enableclosegroup = array(); $enableclosegroup = array();
$enableclosegroup[] =& $mform->createElement('checkbox', 'closeenable', get_string('feedbackclose', 'feedback')); $enableclosegroup[] =& $mform->createElement('checkbox',
'closeenable',
get_string('feedbackclose', 'feedback'));
$enableclosegroup[] =& $mform->createElement('date_time_selector', 'timeclose', ''); $enableclosegroup[] =& $mform->createElement('date_time_selector', 'timeclose', '');
$mform->addGroup($enableclosegroup, 'enableclosegroup', get_string('feedbackclose', 'feedback'), ' ', false); $mform->addGroup($enableclosegroup,
'enableclosegroup',
get_string('feedbackclose', 'feedback'),
' ',
false);
$mform->addHelpButton('enableclosegroup', 'timeclose', 'feedback'); $mform->addHelpButton('enableclosegroup', 'timeclose', 'feedback');
$mform->disabledIf('enableclosegroup', 'closeenable', 'notchecked'); $mform->disabledIf('enableclosegroup', 'closeenable', 'notchecked');
@ -52,27 +84,48 @@ class mod_feedback_mod_form extends moodleform_mod {
$options=array(); $options=array();
$options[1] = get_string('anonymous', 'feedback'); $options[1] = get_string('anonymous', 'feedback');
$options[2] = get_string('non_anonymous', 'feedback'); $options[2] = get_string('non_anonymous', 'feedback');
$mform->addElement('select', 'anonymous', get_string('anonymous_edit', 'feedback'), $options); $mform->addElement('select',
'anonymous',
get_string('anonymous_edit', 'feedback'),
$options);
$mform->addElement('selectyesno',
'publish_stats',
get_string('show_analysepage_after_submit', 'feedback'));
$mform->addElement('selectyesno',
'email_notification',
get_string('email_notification', 'feedback'));
$mform->addElement('selectyesno', 'publish_stats', get_string('show_analysepage_after_submit', 'feedback'));
$mform->addElement('selectyesno', 'email_notification', get_string('email_notification', 'feedback'));
$mform->addHelpButton('email_notification', 'emailnotification', 'feedback'); $mform->addHelpButton('email_notification', 'emailnotification', 'feedback');
// check if there is existing responses to this feedback // check if there is existing responses to this feedback
if (is_numeric($this->_instance) AND $this->_instance and $feedback = $DB->get_record("feedback", array("id"=>$this->_instance))) { if (is_numeric($this->_instance) AND
$completedFeedbackCount = feedback_get_completeds_group_count($feedback); $this->_instance AND
$feedback = $DB->get_record("feedback", array("id"=>$this->_instance))) {
$completed_feedback_count = feedback_get_completeds_group_count($feedback);
} else { } else {
$completedFeedbackCount = false; $completed_feedback_count = false;
} }
if($completedFeedbackCount) { if ($completed_feedback_count) {
$multiple_submit_value = $feedback->multiple_submit ? get_string('yes') : get_string('no'); $multiple_submit_value = $feedback->multiple_submit ? get_string('yes') : get_string('no');
$mform->addElement('text', 'multiple_submit_static', get_string('multiple_submit', 'feedback'), array('size'=>'4','disabled'=>'disabled', 'value'=>$multiple_submit_value)); $mform->addElement('text',
'multiple_submit_static',
get_string('multiple_submit', 'feedback'),
array('size'=>'4',
'disabled'=>'disabled',
'value'=>$multiple_submit_value));
$mform->addElement('hidden', 'multiple_submit', ''); $mform->addElement('hidden', 'multiple_submit', '');
$mform->setType('', PARAM_INT); $mform->setType('', PARAM_INT);
$mform->addHelpButton('multiple_submit_static', 'multiplesubmit', 'feedback'); $mform->addHelpButton('multiple_submit_static', 'multiplesubmit', 'feedback');
}else { } else {
$mform->addElement('selectyesno', 'multiple_submit', get_string('multiple_submit', 'feedback')); $mform->addElement('selectyesno',
'multiple_submit',
get_string('multiple_submit', 'feedback'));
$mform->addHelpButton('multiple_submit', 'multiplesubmit', 'feedback'); $mform->addHelpButton('multiple_submit', 'multiplesubmit', 'feedback');
} }
$mform->addElement('selectyesno', 'autonumbering', get_string('autonumbering', 'feedback')); $mform->addElement('selectyesno', 'autonumbering', get_string('autonumbering', 'feedback'));
@ -81,10 +134,19 @@ class mod_feedback_mod_form extends moodleform_mod {
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
$mform->addElement('header', 'aftersubmithdr', get_string('after_submit', 'feedback')); $mform->addElement('header', 'aftersubmithdr', get_string('after_submit', 'feedback'));
$mform->addElement('editor', 'page_after_submit', get_string("page_after_submit", "feedback"), null, null); $mform->addElement('editor',
'page_after_submit',
get_string("page_after_submit", "feedback"),
null,
null);
$mform->setType('page_after_submit', PARAM_RAW); $mform->setType('page_after_submit', PARAM_RAW);
$mform->addElement('text', 'site_after_submit', get_string('url_for_continue_button', 'feedback'), array('size'=>'64','maxlength'=>'255')); $mform->addElement('text',
'site_after_submit',
get_string('url_for_continue_button', 'feedback'),
array('size'=>'64', 'maxlength'=>'255'));
$mform->setType('site_after_submit', PARAM_TEXT); $mform->setType('site_after_submit', PARAM_TEXT);
$mform->addHelpButton('site_after_submit', 'url_for_continue', 'feedback'); $mform->addHelpButton('site_after_submit', 'url_for_continue', 'feedback');
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
@ -94,7 +156,7 @@ class mod_feedback_mod_form extends moodleform_mod {
$this->add_action_buttons(); $this->add_action_buttons();
} }
function data_preprocessing(&$default_values){ public function data_preprocessing(&$default_values) {
if (empty($default_values['timeopen'])) { if (empty($default_values['timeopen'])) {
$default_values['openenable'] = 0; $default_values['openenable'] = 0;
} else { } else {
@ -111,41 +173,46 @@ class mod_feedback_mod_form extends moodleform_mod {
if (!isset($default_values['page_after_submit'])) { if (!isset($default_values['page_after_submit'])) {
$default_values['page_after_submit'] = ''; $default_values['page_after_submit'] = '';
} }
$default_values['page_after_submit'] = array('text'=>$default_values['page_after_submit'],'format'=>$default_values['page_after_submitformat']); $default_values['page_after_submit'] = array('text'=>$default_values['page_after_submit'],
'format'=>$default_values['page_after_submitformat']);
} }
function get_data() { public function get_data() {
$data = parent::get_data(); $data = parent::get_data();
if ($data) { if ($data) {
$data->page_after_submitformat = $data->page_after_submit['format']; $data->page_after_submitformat = $data->page_after_submit['format'];
$data->page_after_submit = $data->page_after_submit['text']; $data->page_after_submit = $data->page_after_submit['text'];
// Turn off completion settings if the checkboxes aren't ticked // Turn off completion settings if the checkboxes aren't ticked
$autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC; $autocompletion = !empty($data->completion) AND
if(empty($data->completion) || !$autocompletion) { $data->completion==COMPLETION_TRACKING_AUTOMATIC;
if (empty($data->completion) || !$autocompletion) {
$data->completionsubmit=0; $data->completionsubmit=0;
} }
if(empty($data->completionsubmit)) { if (empty($data->completionsubmit)) {
$data->completionsubmit=0; $data->completionsubmit=0;
} }
} }
return $data; return $data;
} }
function validation($data, $files){ public function validation($data, $files) {
$errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
return $errors; return $errors;
} }
function add_completion_rules() { public function add_completion_rules() {
$mform =& $this->_form; $mform =& $this->_form;
$mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'feedback')); $mform->addElement('checkbox',
'completionsubmit',
'',
get_string('completionsubmit', 'feedback'));
return array('completionsubmit'); return array('completionsubmit');
} }
function completion_rule_enabled($data) { public function completion_rule_enabled($data) {
return !empty($data['completionsubmit']); return !empty($data['completionsubmit']);
} }
} }

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* print a printview of feedback-items * print a printview of feedback-items
@ -40,7 +54,8 @@ $PAGE->set_pagelayout('embedded');
$strfeedbacks = get_string("modulenameplural", "feedback"); $strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback"); $strfeedback = get_string("modulename", "feedback");
$PAGE->navbar->add($strfeedbacks, new moodle_url('/mod/feedback/index.php', array('id'=>$course->id))); $feedback_url = new moodle_url('/mod/feedback/index.php', array('id'=>$course->id));
$PAGE->navbar->add($strfeedbacks, $feedback_url);
$PAGE->navbar->add(format_string($feedback->name)); $PAGE->navbar->add(format_string($feedback->name));
$PAGE->set_title(format_string($feedback->name)); $PAGE->set_title(format_string($feedback->name));
@ -56,42 +71,46 @@ echo $OUTPUT->heading(format_text($feedback->name));
$feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position'); $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
echo $OUTPUT->continue_button('view.php?id='.$id); echo $OUTPUT->continue_button('view.php?id='.$id);
if(is_array($feedbackitems)){ if (is_array($feedbackitems)) {
$itemnr = 0; $itemnr = 0;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
echo $OUTPUT->box_start('feedback_items printview'); echo $OUTPUT->box_start('feedback_items printview');
//check, if there exists required-elements //check, if there exists required-elements
$countreq = $DB->count_records('feedback_item', array('feedback'=>$feedback->id, 'required'=>1)); $params = array('feedback'=>$feedback->id, 'required'=>1);
if($countreq > 0) { $countreq = $DB->count_records('feedback_item', $params);
echo '<span class="feedback_required_mark">(*)' . get_string('items_are_required', 'feedback') . '</span>'; if ($countreq > 0) {
echo '<span class="feedback_required_mark">(*)';
echo get_string('items_are_required', 'feedback');
echo '</span>';
} }
//print the inserted items //print the inserted items
$itempos = 0; $itempos = 0;
foreach($feedbackitems as $feedbackitem){ foreach ($feedbackitems as $feedbackitem) {
echo $OUTPUT->box_start('feedback_item_box_'.$align); echo $OUTPUT->box_start('feedback_item_box_'.$align);
$itempos++; $itempos++;
//Items without value only are labels //Items without value only are labels
if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) { if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
$itemnr++; $itemnr++;
echo $OUTPUT->box_start('feedback_item_number_'.$align); echo $OUTPUT->box_start('feedback_item_number_'.$align);
echo $itemnr; echo $itemnr;
echo $OUTPUT->box_end();
}
echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
if($feedbackitem->typ != 'pagebreak') {
feedback_print_item_complete($feedbackitem, false, false);
}else {
echo $OUTPUT->box_start('feedback_pagebreak');
echo '<hr class="feedback_pagebreak" />';
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
if ($feedbackitem->typ != 'pagebreak') {
feedback_print_item_complete($feedbackitem, false, false);
} else {
echo $OUTPUT->box_start('feedback_pagebreak');
echo '<hr class="feedback_pagebreak" />';
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
}
echo $OUTPUT->box_end();
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
}else{ } else {
echo $OUTPUT->box(get_string('no_items_available_yet','feedback'),'generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box(get_string('no_items_available_yet', 'feedback'),
'generalbox boxaligncenter boxwidthwide');
} }
echo $OUTPUT->continue_button('view.php?id='.$id); echo $OUTPUT->continue_button('view.php?id='.$id);
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();

View File

@ -1,10 +1,25 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die; defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) { if ($ADMIN->fulltree) {
$options = array(0=>get_string('no'), 1=>get_string('yes')); $options = array(0=>get_string('no'), 1=>get_string('yes'));
$str = get_string('configallowfullanonymous', 'feedback'); $str = get_string('configallowfullanonymous', 'feedback');
$settings->add(new admin_setting_configselect('feedback_allowfullanonymous', get_string('allowfullanonymous', 'feedback'), $settings->add(new admin_setting_configselect('feedback_allowfullanonymous',
$str, 0, $options)); get_string('allowfullanonymous', 'feedback'),
} $str, 0, $options));
}

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* print the single entries * print the single entries
@ -27,7 +41,7 @@ $current_tab = $do_show;
//get the objects //get the objects
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
if($userid) { if ($userid) {
$formdata->userid = intval($userid); $formdata->userid = intval($userid);
} }
@ -53,7 +67,7 @@ if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
require_login($course->id, true, $cm); require_login($course->id, true, $cm);
if(($formdata = data_submitted()) AND !confirm_sesskey()) { if (($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey'); print_error('invalidsesskey');
} }
@ -62,10 +76,15 @@ require_capability('mod/feedback:viewreports', $context);
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
//get the responses of given user //get the responses of given user
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
if($do_show == 'showoneentry') { if ($do_show == 'showoneentry') {
//get the feedbackitems //get the feedbackitems
$feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position'); $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
$feedbackcompleted = $DB->get_record('feedback_completed', array('feedback'=>$feedback->id, 'userid'=>$userid, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO)); //arb
$params = array('feedback'=>$feedback->id,
'userid'=>$userid,
'anonymous_response'=>FEEDBACK_ANONYMOUS_NO);
$feedbackcompleted = $DB->get_record('feedback_completed', $params); //arb
} }
/// Print the page header /// Print the page header
@ -76,7 +95,7 @@ $PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name)); $PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header(); echo $OUTPUT->header();
include('tabs.php'); require('tabs.php');
/// Print the main part of the page /// Print the main part of the page
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@ -86,9 +105,9 @@ include('tabs.php');
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
/// Print the links to get responses and analysis /// Print the links to get responses and analysis
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
if($do_show == 'showentries'){ if ($do_show == 'showentries') {
//print the link to analysis //print the link to analysis
if(has_capability('mod/feedback:viewreports', $context)) { if (has_capability('mod/feedback:viewreports', $context)) {
//get the effective groupmode of this course and module //get the effective groupmode of this course and module
if (isset($cm->groupmode) && empty($course->groupmodeforce)) { if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode; $groupmode = $cm->groupmode;
@ -96,7 +115,6 @@ if($do_show == 'showentries'){
$groupmode = $course->groupmode; $groupmode = $course->groupmode;
} }
// $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/feedback/show_entries.php?id=' . $cm->id.'&do_show=showentries', true);
$groupselect = groups_print_activity_menu($cm, $url->out(), true); $groupselect = groups_print_activity_menu($cm, $url->out(), true);
$mygroupid = groups_get_activity_group($cm); $mygroupid = groups_get_activity_group($cm);
@ -107,7 +125,7 @@ if($do_show == 'showentries'){
$tablecolumns = array('userpic', 'fullname', 'c.timemodified'); $tablecolumns = array('userpic', 'fullname', 'c.timemodified');
$tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('date')); $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('date'));
if(has_capability('mod/feedback:deletesubmissions', $context)) { if (has_capability('mod/feedback:deletesubmissions', $context)) {
$tablecolumns[] = 'deleteentry'; $tablecolumns[] = 'deleteentry';
$tableheaders[] = ''; $tableheaders[] = '';
} }
@ -130,9 +148,9 @@ if($do_show == 'showentries'){
)); ));
$table->setup(); $table->setup();
if($table->get_sql_sort()) { if ($table->get_sql_sort()) {
$sort = $table->get_sql_sort(); $sort = $table->get_sql_sort();
}else { } else {
$sort = ''; $sort = '';
} }
@ -142,79 +160,101 @@ if($do_show == 'showentries'){
} }
//get students in conjunction with groupmode //get students in conjunction with groupmode
if($groupmode > 0) { if ($groupmode > 0) {
if($mygroupid > 0) { if ($mygroupid > 0) {
$usedgroupid = $mygroupid; $usedgroupid = $mygroupid;
} else { } else {
$usedgroupid = false; $usedgroupid = false;
} }
}else { } else {
$usedgroupid = false; $usedgroupid = false;
} }
$matchcount = feedback_count_complete_users($cm, $usedgroupid); $matchcount = feedback_count_complete_users($cm, $usedgroupid);
$table->initialbars(true); $table->initialbars(true);
if($showall) { if ($showall) {
$startpage = false; $startpage = false;
$pagecount = false; $pagecount = false;
}else { } else {
$table->pagesize($perpage, $matchcount); $table->pagesize($perpage, $matchcount);
$startpage = $table->get_page_start(); $startpage = $table->get_page_start();
$pagecount = $table->get_page_size(); $pagecount = $table->get_page_size();
} }
$students = feedback_get_complete_users($cm, $usedgroupid, $where, $params, $sort, $startpage, $pagecount); $students = feedback_get_complete_users($cm, $usedgroupid, $where, $params, $sort, $startpage, $pagecount);
$str_analyse = get_string('analysis', 'feedback');
$str_complete = get_string('completed_feedbacks', 'feedback');
$str_course = get_string('course');
$completedFeedbackCount = feedback_get_completeds_group_count($feedback, $mygroupid); $completed_fb_count = feedback_get_completeds_group_count($feedback, $mygroupid);
if($feedback->course == SITEID){ if ($feedback->course == SITEID) {
$analysisurl = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id, 'courseid'=>$courseid)); $analysisurl = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id, 'courseid'=>$courseid));
echo $OUTPUT->box_start('mdl-align'); echo $OUTPUT->box_start('mdl-align');
echo '<a href="'.$analysisurl->out().'">'.get_string('course').' '.get_string('analysis', 'feedback').' ('.get_string('completed_feedbacks', 'feedback').': '.intval($completedFeedbackCount).')</a>'; echo '<a href="'.$analysisurl->out().'">';
echo $str_course.' '.$str_analyse.' ('.$str_complete.': '.intval($completed_fb_count).')';
echo '</a>';
echo $OUTPUT->help_icon('viewcompleted', 'feedback'); echo $OUTPUT->help_icon('viewcompleted', 'feedback');
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
}else { } else {
$analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid)); $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid));
echo $OUTPUT->box_start('mdl-align'); echo $OUTPUT->box_start('mdl-align');
echo '<a href="'.$analysisurl->out().'">'.get_string('analysis', 'feedback').' ('.get_string('completed_feedbacks', 'feedback').': '.intval($completedFeedbackCount).')</a>'; echo '<a href="'.$analysisurl->out().'">';
echo $str_analyse.' ('.$str_complete.': '.intval($completed_fb_count).')';
echo '</a>';
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
} }
//####### viewreports-start //####### viewreports-start
if(has_capability('mod/feedback:viewreports', $context)) { if (has_capability('mod/feedback:viewreports', $context)) {
//print the list of students //print the list of students
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
echo isset($groupselect) ? $groupselect : ''; echo isset($groupselect) ? $groupselect : '';
echo '<div class="clearer"></div>'; echo '<div class="clearer"></div>';
echo $OUTPUT->box_start('mdl-align'); echo $OUTPUT->box_start('mdl-align');
// echo '<table><tr><td width="400">';
if (!$students) { if (!$students) {
if($courseid != SITEID){ if ($courseid != SITEID) {
echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol')); echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
} }
} else{ } else {
echo print_string('non_anonymous_entries', 'feedback'); echo print_string('non_anonymous_entries', 'feedback');
echo ' ('.count($students).')<hr />'; echo ' ('.count($students).')<hr />';
foreach ($students as $student){ foreach ($students as $student) {
$completedCount = $DB->count_records('feedback_completed', array('userid'=>$student->id, 'feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO)); $params = array('userid'=>$student->id,
if($completedCount > 0) { 'feedback'=>$feedback->id,
'anonymous_response'=>FEEDBACK_ANONYMOUS_NO);
$completed_count = $DB->count_records('feedback_completed', $params);
if ($completed_count > 0) {
//userpicture and link to the profilepage //userpicture and link to the profilepage
$profilelink = '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id.'">'.fullname($student).'</a></strong>'; $fullname_url = $CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id;
$profilelink = '<strong><a href="'.$fullname_url.'">'.fullname($student).'</a></strong>';
$data = array ($OUTPUT->user_picture($student, array('courseid'=>$course->id)), $profilelink); $data = array ($OUTPUT->user_picture($student, array('courseid'=>$course->id)), $profilelink);
//link to the entry of the user //link to the entry of the user
$feedbackcompleted = $DB->get_record('feedback_completed', array('feedback'=>$feedback->id, 'userid'=>$student->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO)); $params = array('feedback'=>$feedback->id,
$showentryurl = new moodle_url($url, array('userid'=>$student->id, 'do_show'=>'showoneentry')); 'userid'=>$student->id,
$showentrylink = '<a href="'.$showentryurl->out().'">'.UserDate($feedbackcompleted->timemodified).'</a>'; 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO);
$feedbackcompleted = $DB->get_record('feedback_completed', $params);
$showentryurl_params = array('userid'=>$student->id, 'do_show'=>'showoneentry');
$showentryurl = new moodle_url($url, $showentryurl_params);
$showentrylink = '<a href="'.$showentryurl->out().'">'.userdate($feedbackcompleted->timemodified).'</a>';
$data[] = $showentrylink; $data[] = $showentrylink;
//link to delete the entry //link to delete the entry
if(has_capability('mod/feedback:deletesubmissions', $context)) { if (has_capability('mod/feedback:deletesubmissions', $context)) {
$deleteentryurl = new moodle_url($CFG->wwwroot.'/mod/feedback/delete_completed.php', array('id'=>$cm->id, 'completedid'=>$feedbackcompleted->id, 'do_show'=>'showoneentry')); $delete_url_params = array('id' => $cm->id,
$deleteentrylink = '<a href="'.$deleteentryurl->out().'">'.get_string('delete_entry', 'feedback').'</a>'; 'completedid' => $feedbackcompleted->id,
'do_show' => 'showoneentry');
$deleteentryurl = new moodle_url($CFG->wwwroot.'/mod/feedback/delete_completed.php', $delete_url_params);
$deleteentrylink = '<a href="'.$deleteentryurl->out().'">'.
get_string('delete_entry', 'feedback').
'</a>';
$data[] = $deleteentrylink; $data[] = $deleteentrylink;
} }
$table->add_data($data); $table->add_data($data);
@ -226,28 +266,44 @@ if($do_show == 'showentries'){
if ($showall) { if ($showall) {
$allurl->param('showall', 0); $allurl->param('showall', 0);
echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)), array(), 'showall'); echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
array(),
'showall');
} else if ($matchcount > 0 && $perpage < $matchcount) { } else if ($matchcount > 0 && $perpage < $matchcount) {
$allurl->param('showall', 1); $allurl->param('showall', 1);
echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall'); echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)),
array(),
'showall');
} }
} }
?> ?>
<hr /> <hr />
<table width="100%"> <table width="100%">
<tr> <tr>
<td align="left" colspan="2"> <td align="left" colspan="2">
<?php print_string('anonymous_entries', 'feedback');?>&nbsp;(<?php echo $DB->count_records('feedback_completed', array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES));?>) <?php
$params = array('feedback' => $feedback->id,
'anonymous_response' => FEEDBACK_ANONYMOUS_YES);
$feedback_completeds_count = $DB->count_records('feedback_completed', $params);
print_string('anonymous_entries', 'feedback');
echo '&nbsp;('.$feedback_completeds_count.')';
?>
</td> </td>
<td align="right"> <td align="right">
<?php <?php
$aurl = new moodle_url('show_entries_anonym.php', array('sesskey'=>sesskey(), 'userid'=>0, 'do_show'=>'showoneentry', 'id'=>$id)); $url_params = array('sesskey'=>sesskey(),
'userid'=>0,
'do_show'=>'showoneentry',
'id'=>$id);
$aurl = new moodle_url('show_entries_anonym.php', $url_params);
echo $OUTPUT->single_button($aurl, get_string('show_entries', 'feedback')); echo $OUTPUT->single_button($aurl, get_string('show_entries', 'feedback'));
?> ?>
</td> </td>
</tr> </tr>
</table> </table>
<?php <?php
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
@ -256,38 +312,39 @@ if($do_show == 'showentries'){
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
/// Print the responses of the given user /// Print the responses of the given user
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
if($do_show == 'showoneentry') { if ($do_show == 'showoneentry') {
echo $OUTPUT->heading(format_text($feedback->name)); echo $OUTPUT->heading(format_text($feedback->name));
//print the items //print the items
if(is_array($feedbackitems)){ if (is_array($feedbackitems)) {
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
$usr = $DB->get_record('user', array('id'=>$userid)); $usr = $DB->get_record('user', array('id'=>$userid));
if($feedbackcompleted) { if ($feedbackcompleted) {
echo $OUTPUT->heading(UserDate($feedbackcompleted->timemodified).' ('.fullname($usr).')', 3); echo $OUTPUT->heading(userdate($feedbackcompleted->timemodified).' ('.fullname($usr).')', 3);
} else { } else {
echo $OUTPUT->heading(get_string('not_completed_yet','feedback'), 3); echo $OUTPUT->heading(get_string('not_completed_yet', 'feedback'), 3);
} }
echo $OUTPUT->box_start('feedback_items'); echo $OUTPUT->box_start('feedback_items');
$itemnr = 0; $itemnr = 0;
foreach($feedbackitems as $feedbackitem){ foreach ($feedbackitems as $feedbackitem) {
//get the values //get the values
$value = $DB->get_record('feedback_value', array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id)); $params = array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id);
$value = $DB->get_record('feedback_value', $params);
echo $OUTPUT->box_start('feedback_item_box_'.$align); echo $OUTPUT->box_start('feedback_item_box_'.$align);
if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) { if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
$itemnr++; $itemnr++;
echo $OUTPUT->box_start('feedback_item_number_'.$align); echo $OUTPUT->box_start('feedback_item_number_'.$align);
echo $itemnr; echo $itemnr;
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
if($feedbackitem->typ != 'pagebreak') { if ($feedbackitem->typ != 'pagebreak') {
echo $OUTPUT->box_start('box generalbox boxalign_'.$align); echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
if(isset($value->value)) { if (isset($value->value)) {
feedback_print_item_show_value($feedbackitem, $value->value); feedback_print_item_show_value($feedbackitem, $value->value);
}else { } else {
feedback_print_item_show_value($feedbackitem, false); feedback_print_item_show_value($feedbackitem, false);
} }
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* print the single-values of anonymous completeds * print the single-values of anonymous completeds
@ -12,10 +26,7 @@ require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once($CFG->libdir.'/tablelib.php'); require_once($CFG->libdir.'/tablelib.php');
// $SESSION->feedback->current_tab = 'showoneentry';
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
// $userid = optional_param('userid', false, PARAM_INT);
$showcompleted = optional_param('showcompleted', false, PARAM_INT); $showcompleted = optional_param('showcompleted', false, PARAM_INT);
$do_show = optional_param('do_show', false, PARAM_ALPHA); $do_show = optional_param('do_show', false, PARAM_ALPHA);
$perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT); // how many per page $perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT); // how many per page
@ -61,28 +72,34 @@ echo $OUTPUT->header();
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
include('tabs.php'); require('tabs.php');
echo $OUTPUT->heading(format_text($feedback->name)); echo $OUTPUT->heading(format_text($feedback->name));
//print the list with anonymous completeds //print the list with anonymous completeds
if(!$showcompleted) { if (!$showcompleted) {
//get the completeds //get the completeds
// if a new anonymous record has not been assigned a random response number // if a new anonymous record has not been assigned a random response number
if ($feedbackcompleteds = $DB->get_records('feedback_completed', array('feedback'=>$feedback->id, 'random_response'=>0, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES), 'random_response')){ //arb $params = array('feedback'=>$feedback->id,
'random_response'=>0,
'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
if ($feedbackcompleteds = $DB->get_records('feedback_completed', $params, 'random_response')) {
//then get all of the anonymous records and go through them //then get all of the anonymous records and go through them
$feedbackcompleteds = $DB->get_records('feedback_completed', array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES), 'id'); //arb $params = array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
$feedbackcompleteds = $DB->get_records('feedback_completed', $params, 'id'); //arb
shuffle($feedbackcompleteds); shuffle($feedbackcompleteds);
$num = 1; $num = 1;
foreach($feedbackcompleteds as $compl){ foreach ($feedbackcompleteds as $compl) {
$compl->random_response = $num; $compl->random_response = $num;
$DB->update_record('feedback_completed', $compl); $DB->update_record('feedback_completed', $compl);
$num++; $num++;
} }
} }
$feedbackcompletedscount = $DB->count_records('feedback_completed', array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES)); $params = array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
$feedbackcompletedscount = $DB->count_records('feedback_completed', $params);
// preparing the table for output // preparing the table for output
$baseurl = new moodle_url('/mod/feedback/show_entries_anonym.php'); $baseurl = new moodle_url('/mod/feedback/show_entries_anonym.php');
@ -90,8 +107,8 @@ if(!$showcompleted) {
$tablecolumns = array('response', 'showresponse'); $tablecolumns = array('response', 'showresponse');
$tableheaders = array('', ''); $tableheaders = array('', '');
if(has_capability('mod/feedback:deletesubmissions', $context)) { if (has_capability('mod/feedback:deletesubmissions', $context)) {
$tablecolumns[] = 'deleteentry'; $tablecolumns[] = 'deleteentry';
$tableheaders[] = ''; $tableheaders[] = '';
} }
@ -117,51 +134,57 @@ if(!$showcompleted) {
$matchcount = $feedbackcompletedscount; $matchcount = $feedbackcompletedscount;
$table->initialbars(true); $table->initialbars(true);
if($showall) { if ($showall) {
$startpage = false; $startpage = false;
$pagecount = false; $pagecount = false;
}else { } else {
$table->pagesize($perpage, $matchcount); $table->pagesize($perpage, $matchcount);
$startpage = $table->get_page_start(); $startpage = $table->get_page_start();
$pagecount = $table->get_page_size(); $pagecount = $table->get_page_size();
} }
$feedbackcompleteds = $DB->get_records('feedback_completed', $feedbackcompleteds = $DB->get_records('feedback_completed',
array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES), array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES),
'random_response', 'random_response',
'id,random_response', 'id,random_response',
$startpage, $startpage,
$pagecount); $pagecount);
if(is_array($feedbackcompleteds)) { if (is_array($feedbackcompleteds)) {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
echo $OUTPUT->heading(get_string('anonymous_entries', 'feedback'), 3); echo $OUTPUT->heading(get_string('anonymous_entries', 'feedback'), 3);
foreach($feedbackcompleteds as $compl) { foreach ($feedbackcompleteds as $compl) {
$data = array(); $data = array();
$data[] = get_string('response_nr', 'feedback').': '. $compl->random_response; $data[] = get_string('response_nr', 'feedback').': '. $compl->random_response;
//link to the entry //link to the entry
$showentryurl = new moodle_url($baseurl, array('showcompleted'=>$compl->id)); $showentryurl = new moodle_url($baseurl, array('showcompleted'=>$compl->id));
$showentrylink = '<a href="'.$showentryurl->out().'">'.get_string('show_entry', 'feedback').'</a>'; $showentrylink = '<a href="'.$showentryurl->out().'">'.get_string('show_entry', 'feedback').'</a>';
$data[] = $showentrylink; $data[] = $showentrylink;
//link to delete the entry //link to delete the entry
if(has_capability('mod/feedback:deletesubmissions', $context)) { if (has_capability('mod/feedback:deletesubmissions', $context)) {
$deleteentryurl = new moodle_url($CFG->wwwroot.'/mod/feedback/delete_completed.php', array('id'=>$cm->id, 'completedid'=>$compl->id, 'do_show'=>'', 'return'=>'entriesanonym')); $delet_url_params = array('id'=>$cm->id,
'completedid'=>$compl->id,
'do_show'=>'',
'return'=>'entriesanonym');
$deleteentryurl = new moodle_url($CFG->wwwroot.'/mod/feedback/delete_completed.php', $delet_url_params);
$deleteentrylink = '<a href="'.$deleteentryurl->out().'">'.get_string('delete_entry', 'feedback').'</a>'; $deleteentrylink = '<a href="'.$deleteentryurl->out().'">'.get_string('delete_entry', 'feedback').'</a>';
$data[] = $deleteentrylink; $data[] = $deleteentrylink;
} }
$table->add_data($data); $table->add_data($data);
} }
$table->print_html(); $table->print_html();
$allurl = new moodle_url($baseurl); $allurl = new moodle_url($baseurl);
if ($showall) { if ($showall) {
$allurl->param('showall', 0); $allurl->param('showall', 0);
echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)), array(), 'showall'); $str_showperpage = get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT);
echo $OUTPUT->container(html_writer::link($allurl, $str_showperpage), array(), 'showall');
} else if ($matchcount > 0 && $perpage < $matchcount) { } else if ($matchcount > 0 && $perpage < $matchcount) {
$allurl->param('showall', 1); $allurl->param('showall', 1);
echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall'); echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
@ -170,44 +193,47 @@ if(!$showcompleted) {
} }
} }
//print the items //print the items
// if(isset($formdata->showanonym) && $formdata->showanonym == FEEDBACK_ANONYMOUS_YES) { if ($showcompleted) {
if($showcompleted) { $continueurl = new moodle_url('/mod/feedback/show_entries_anonym.php',
$continueurl = new moodle_url('/mod/feedback/show_entries_anonym.php', array('id'=>$id, 'do_show'=>'')); array('id'=>$id, 'do_show'=>''));
echo $OUTPUT->continue_button($continueurl); echo $OUTPUT->continue_button($continueurl);
//get the feedbackitems //get the feedbackitems
$feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position'); $params = array('feedback'=>$feedback->id);
$feedbackitems = $DB->get_records('feedback_item', $params, 'position');
$feedbackcompleted = $DB->get_record('feedback_completed', array('id'=>$showcompleted)); $feedbackcompleted = $DB->get_record('feedback_completed', array('id'=>$showcompleted));
if(is_array($feedbackitems)){ if (is_array($feedbackitems)) {
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
if($feedbackcompleted) { if ($feedbackcompleted) {
echo $OUTPUT->box_start('feedback_info'); echo $OUTPUT->box_start('feedback_info');
echo get_string('chosen_feedback_response', 'feedback'); echo get_string('chosen_feedback_response', 'feedback');
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
echo $OUTPUT->box_start('feedback_info'); echo $OUTPUT->box_start('feedback_info');
echo get_string('response_nr', 'feedback').': '. $feedbackcompleted->random_response.' ('.get_string('anonymous', 'feedback').')'; echo get_string('response_nr', 'feedback').': ';
echo $feedbackcompleted->random_response.' ('.get_string('anonymous', 'feedback').')';
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} else { } else {
echo $OUTPUT->box_start('feedback_info'); echo $OUTPUT->box_start('feedback_info');
echo get_string('not_completed_yet','feedback'); echo get_string('not_completed_yet', 'feedback');
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
echo $OUTPUT->box_start('feedback_items'); echo $OUTPUT->box_start('feedback_items');
// echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
$itemnr = 0; $itemnr = 0;
foreach($feedbackitems as $feedbackitem){ foreach ($feedbackitems as $feedbackitem) {
//get the values //get the values
$value = $DB->get_record('feedback_value', array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id)); $params = array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id);
$value = $DB->get_record('feedback_value', $params);
echo $OUTPUT->box_start('feedback_item_box_'.$align); echo $OUTPUT->box_start('feedback_item_box_'.$align);
if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) { if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
$itemnr++; $itemnr++;
echo $OUTPUT->box_start('feedback_item_number_'.$align); echo $OUTPUT->box_start('feedback_item_number_'.$align);
echo $itemnr; echo $itemnr;
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
if($feedbackitem->typ != 'pagebreak') { if ($feedbackitem->typ != 'pagebreak') {
echo $OUTPUT->box_start('box generalbox boxalign_'.$align); echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
$itemvalue = isset($value->value) ? $value->value : false; $itemvalue = isset($value->value) ? $value->value : false;
feedback_print_item_show_value($feedbackitem, $itemvalue); feedback_print_item_show_value($feedbackitem, $itemvalue);
@ -215,7 +241,6 @@ if($showcompleted) {
} }
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
// echo $OUTPUT->box_end();
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
} }

View File

@ -1,279 +1,298 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* print the single entries * print the single entries
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once($CFG->libdir.'/tablelib.php'); require_once($CFG->libdir.'/tablelib.php');
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
//get the params //get the params
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$subject = optional_param('subject','',PARAM_CLEANHTML); $subject = optional_param('subject', '', PARAM_CLEANHTML);
$message = optional_param('message','',PARAM_CLEANHTML); $message = optional_param('message', '', PARAM_CLEANHTML);
$format = optional_param('format',FORMAT_MOODLE,PARAM_INT); $format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
$messageuser = optional_param('messageuser', false, PARAM_INT); $messageuser = optional_param('messageuser', false, PARAM_INT);
$action = optional_param('action', '',PARAM_ALPHA); $action = optional_param('action', '', PARAM_ALPHA);
$perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT); // how many per page $perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT); // how many per page
$showall = optional_param('showall', false, PARAM_INT); // should we show all users $showall = optional_param('showall', false, PARAM_INT); // should we show all users
// $SESSION->feedback->current_tab = $do_show; // $SESSION->feedback->current_tab = $do_show;
$current_tab = 'nonrespondents'; $current_tab = 'nonrespondents';
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
//get the objects //get the objects
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
if (! $cm = get_coursemodule_from_id('feedback', $id)) { if (! $cm = get_coursemodule_from_id('feedback', $id)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); print_error('coursemisconf');
} }
if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
//this page only can be shown on nonanonymous feedbacks in courses //this page only can be shown on nonanonymous feedbacks in courses
//we should never reach this page //we should never reach this page
if($feedback->anonymous != FEEDBACK_ANONYMOUS_NO OR $feedback->course == SITEID) { if ($feedback->anonymous != FEEDBACK_ANONYMOUS_NO OR $feedback->course == SITEID) {
print_error('error'); print_error('error');
} }
$url = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$cm->id)); $url = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$cm->id));
$PAGE->set_url($url); $PAGE->set_url($url);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) { if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext'); print_error('badcontext');
} }
//we need the coursecontext to allow sending of mass mails //we need the coursecontext to allow sending of mass mails
if (!$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id)) { if (!$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id)) {
print_error('badcontext'); print_error('badcontext');
} }
require_login($course->id, true, $cm); require_login($course->id, true, $cm);
if(($formdata = data_submitted()) AND !confirm_sesskey()) { if (($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey'); print_error('invalidsesskey');
} }
require_capability('mod/feedback:viewreports', $context); require_capability('mod/feedback:viewreports', $context);
if($action == 'sendmessage' AND has_capability('moodle/course:bulkmessaging', $coursecontext)) { if ($action == 'sendmessage' AND has_capability('moodle/course:bulkmessaging', $coursecontext)) {
// require_once($CFG->dirroot.'/message/lib.php'); $good = 1;
$good = 1; if (is_array($messageuser)) {
if(is_array($messageuser)) { foreach ($messageuser as $userid) {
foreach ($messageuser as $userid) { $senduser = $DB->get_record('user', array('id'=>$userid));
$senduser = $DB->get_record('user', array('id'=>$userid)); $eventdata = new stdClass();
$eventdata = new stdClass(); $eventdata->name = 'message';
$eventdata->name = 'message'; $eventdata->component = 'mod_feedback';
$eventdata->component = 'mod_feedback'; $eventdata->userfrom = $USER;
$eventdata->userfrom = $USER; $eventdata->userto = $senduser;
$eventdata->userto = $senduser; $eventdata->subject = $subject;
$eventdata->subject = $subject; $eventdata->fullmessage = $message;
$eventdata->fullmessage = $message; $eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = '';
$eventdata->fullmessagehtml = ''; $eventdata->smallmessage = '';
$eventdata->smallmessage = ''; $good = $good && message_send($eventdata);
$good = $good && message_send($eventdata);
}
if (!empty($good)) {
$msg = $OUTPUT->heading(get_string('messagedselectedusers'));
} else {
$msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
}
redirect($url, $msg, 4);
exit;
} }
} if (!empty($good)) {
$msg = $OUTPUT->heading(get_string('messagedselectedusers'));
////////////////////////////////////////////////////////
//get the responses of given user
////////////////////////////////////////////////////////
/// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback");
$PAGE->navbar->add(get_string('show_nonrespondents','feedback'));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header();
include('tabs.php');
/// Print the main part of the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
/// Print the users with no responses
////////////////////////////////////////////////////////
//get the effective groupmode of this course and module
if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode;
} else {
$groupmode = $course->groupmode;
}
$groupselect = groups_print_activity_menu($cm, $url->out(), true);
$mygroupid = groups_get_activity_group($cm);
// preparing the table for output
$baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
$baseurl->params(array('id'=>$id, 'showall'=>$showall));
$tablecolumns = array('userpic', 'fullname', 'status');
$tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
if(has_capability('moodle/course:bulkmessaging', $coursecontext)) {
$tablecolumns[] = 'select';
$tableheaders[] = get_string('select');
}
$table = new flexible_table('feedback-shownonrespondents-'.$course->id);
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($baseurl);
$table->sortable(true, 'lastname', SORT_DESC);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'showentrytable');
$table->set_attribute('class', 'generaltable generalbox');
$table->set_control_variables(array(
TABLE_VAR_SORT => 'ssort',
TABLE_VAR_IFIRST => 'sifirst',
TABLE_VAR_ILAST => 'silast',
TABLE_VAR_PAGE => 'spage'
));
$table->no_sorting('select');
$table->no_sorting('status');
$table->setup();
if($table->get_sql_sort()) {
$sort = $table->get_sql_sort();
}else {
$sort = '';
}
//get students in conjunction with groupmode
if($groupmode > 0) {
if($mygroupid > 0) {
$usedgroupid = $mygroupid;
} else { } else {
$usedgroupid = false; $msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
} }
}else { redirect($url, $msg, 4);
exit;
}
}
////////////////////////////////////////////////////////
//get the responses of given user
////////////////////////////////////////////////////////
/// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback");
$PAGE->navbar->add(get_string('show_nonrespondents', 'feedback'));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header();
require('tabs.php');
/// Print the main part of the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
/// Print the users with no responses
////////////////////////////////////////////////////////
//get the effective groupmode of this course and module
if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode;
} else {
$groupmode = $course->groupmode;
}
$groupselect = groups_print_activity_menu($cm, $url->out(), true);
$mygroupid = groups_get_activity_group($cm);
// preparing the table for output
$baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
$baseurl->params(array('id'=>$id, 'showall'=>$showall));
$tablecolumns = array('userpic', 'fullname', 'status');
$tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
$tablecolumns[] = 'select';
$tableheaders[] = get_string('select');
}
$table = new flexible_table('feedback-shownonrespondents-'.$course->id);
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($baseurl);
$table->sortable(true, 'lastname', SORT_DESC);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'showentrytable');
$table->set_attribute('class', 'generaltable generalbox');
$table->set_control_variables(array(
TABLE_VAR_SORT => 'ssort',
TABLE_VAR_IFIRST => 'sifirst',
TABLE_VAR_ILAST => 'silast',
TABLE_VAR_PAGE => 'spage'
));
$table->no_sorting('select');
$table->no_sorting('status');
$table->setup();
if ($table->get_sql_sort()) {
$sort = $table->get_sql_sort();
} else {
$sort = '';
}
//get students in conjunction with groupmode
if ($groupmode > 0) {
if ($mygroupid > 0) {
$usedgroupid = $mygroupid;
} else {
$usedgroupid = false; $usedgroupid = false;
} }
} else {
$usedgroupid = false;
}
$matchcount = feedback_count_incomplete_users($cm, $usedgroupid); $matchcount = feedback_count_incomplete_users($cm, $usedgroupid);
$table->initialbars(false); $table->initialbars(false);
if($showall) { if ($showall) {
$startpage = false; $startpage = false;
$pagecount = false; $pagecount = false;
}else { } else {
$table->pagesize($perpage, $matchcount); $table->pagesize($perpage, $matchcount);
$startpage = $table->get_page_start(); $startpage = $table->get_page_start();
$pagecount = $table->get_page_size(); $pagecount = $table->get_page_size();
}
$students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount);
//####### viewreports-start
//print the list of students
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
echo isset($groupselect) ? $groupselect : '';
echo '<div class="clearer"></div>';
echo $OUTPUT->box_start('mdl-align');
if (!$students) {
echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
} else {
echo print_string('non_respondents_students', 'feedback');
echo ' ('.$matchcount.')<hr />';
if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
} }
foreach ($students as $student) {
$user = $DB->get_record('user', array('id'=>$student));
//userpicture and link to the profilepage
$profile_url = $CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id;
$profilelink = '<strong><a href="'.$profile_url.'">'.fullname($user).'</a></strong>';
$data = array ($OUTPUT->user_picture($user, array('courseid'=>$course->id)), $profilelink);
$students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount); if ($DB->record_exists('feedback_completedtmp', array('userid'=>$user->id))) {
//####### viewreports-start $data[] = get_string('started', 'feedback');
//print the list of students } else {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); $data[] = get_string('not_started', 'feedback');
echo isset($groupselect) ? $groupselect : '';
echo '<div class="clearer"></div>';
echo $OUTPUT->box_start('mdl-align');
// echo '<table><tr><td width="400">';
if (!$students) {
echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
} else{
echo print_string('non_respondents_students', 'feedback');
echo ' ('.$matchcount.')<hr />';
if(has_capability('moodle/course:bulkmessaging', $coursecontext)) {
echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
} }
foreach ($students as $student){
$user = $DB->get_record('user', array('id'=>$student));
//userpicture and link to the profilepage
$profilelink = '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.fullname($user).'</a></strong>';
$data = array ($OUTPUT->user_picture($user, array('courseid'=>$course->id)), $profilelink);
if($DB->record_exists('feedback_completedtmp', array('userid'=>$user->id))) { //selections to bulk messaging
$data[] = get_string('started', 'feedback'); if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
}else { $data[] = '<input type="checkbox" class="usercheckbox" name="messageuser[]" value="'.$user->id.'" />';
$data[] = get_string('not_started', 'feedback');
}
//selections to bulk messaging
if(has_capability('moodle/course:bulkmessaging', $coursecontext)) {
$data[] = '<input type="checkbox" class="usercheckbox" name="messageuser[]" value="'.$user->id.'" />';
}
$table->add_data($data);
}
$table->print_html();
$allurl = new moodle_url($baseurl);
if ($showall) {
$allurl->param('showall', 0);
echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)), array(), 'showall');
} else if ($matchcount > 0 && $perpage < $matchcount) {
$allurl->param('showall', 1);
echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
}
if(has_capability('moodle/course:bulkmessaging', $coursecontext)) {
$usehtmleditor = can_use_html_editor();
echo '<div class="buttons"><br />';
echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> ';
echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> ';
echo '</div>';
echo '<fieldset class="clearfix">';
echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
echo '<div><label for="feedback_subject">'.get_string('subject', 'feedback').'&nbsp;</label><input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.$subject.'" /></div>';
print_textarea($usehtmleditor, 15, 25, 30, 10, "message", $message);
if ($usehtmleditor) {
print_string('formathtml');
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
} else {
choose_from_menu(format_text_menu(), "format", $format, "");
}
echo '<br /><div class="buttons">';
echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" />';
echo '</div>';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="action" value="sendmessage" />';
echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '</fieldset>';
echo '</form>';
//include the needed js
$module = array('name'=>'mod_feedback', 'fullpath'=>'/mod/feedback/feedback.js');
$PAGE->requires->js_init_call('M.mod_feedback.init_sendmessage', null, false, $module);
} }
$table->add_data($data);
} }
echo $OUTPUT->box_end(); $table->print_html();
echo $OUTPUT->box_end();
/// Finish the page $allurl = new moodle_url($baseurl);
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->footer(); if ($showall) {
$allurl->param('showall', 0);
echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
array(), 'showall');
} else if ($matchcount > 0 && $perpage < $matchcount) {
$allurl->param('showall', 1);
echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
}
if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
$usehtmleditor = can_use_html_editor();
echo '<div class="buttons"><br />';
echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> ';
echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> ';
echo '</div>';
echo '<fieldset class="clearfix">';
echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
echo '<div>';
echo '<label for="feedback_subject">'.get_string('subject', 'feedback').'&nbsp;</label>';
echo '<input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.$subject.'" />';
echo '</div>';
print_textarea($usehtmleditor, 15, 25, 30, 10, "message", $message);
if ($usehtmleditor) {
print_string('formathtml');
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
} else {
choose_from_menu(format_text_menu(), "format", $format, "");
}
echo '<br /><div class="buttons">';
echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" />';
echo '</div>';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="action" value="sendmessage" />';
echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '</fieldset>';
echo '</form>';
//include the needed js
$module = array('name'=>'mod_feedback', 'fullpath'=>'/mod/feedback/feedback.js');
$PAGE->requires->js_init_call('M.mod_feedback.init_sendmessage', null, false, $module);
}
}
echo $OUTPUT->box_end();
echo $OUTPUT->box_end();
/// Finish the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->footer();

View File

@ -81,4 +81,4 @@ hr.feedback_pagebreak {
color:#aaaaaa; color:#aaaaaa;
background-color:#aaaaaa; background-color:#aaaaaa;
border:0px; border:0px;
} }

View File

@ -1,68 +1,95 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* prints the tabbed bar * prints the tabbed bar
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
defined('MOODLE_INTERNAL') OR die('not allowed'); defined('MOODLE_INTERNAL') OR die('not allowed');
$tabs = array(); $tabs = array();
$row = array(); $row = array();
$inactive = array(); $inactive = array();
$activated = array(); $activated = array();
//some pages deliver the cmid instead the id //some pages deliver the cmid instead the id
if(isset($cmid) AND intval($cmid) AND $cmid > 0) { if (isset($cmid) AND intval($cmid) AND $cmid > 0) {
$usedid = $cmid; $usedid = $cmid;
}else { } else {
$usedid = $id; $usedid = $id;
}
if (!$context = get_context_instance(CONTEXT_MODULE, $usedid)) {
print_error('badcontext');
}
$courseid = optional_param('courseid', false, PARAM_INT);
// $current_tab = $SESSION->feedback->current_tab;
if (!isset($current_tab)) {
$current_tab = '';
}
$viewurl = new moodle_url('/mod/feedback/view.php', array('id'=>$usedid, 'do_show'=>'view'));
$row[] = new tabobject('view', $viewurl->out(), get_string('overview', 'feedback'));
if (has_capability('mod/feedback:edititems', $context)) {
$editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$usedid, 'do_show'=>'edit'));
$row[] = new tabobject('edit', $editurl->out(), get_string('edit_items', 'feedback'));
$templateurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$usedid, 'do_show'=>'templates'));
$row[] = new tabobject('templates', $templateurl->out(), get_string('templates', 'feedback'));
}
if (has_capability('mod/feedback:viewreports', $context)) {
if ($feedback->course == SITEID) {
$url_params = array('id'=>$usedid, 'courseid'=>$courseid, 'do_show'=>'analysis');
$analysisurl = new moodle_url('/mod/feedback/analysis_course.php', $url_params);
$row[] = new tabobject('analysis',
$analysisurl->out(),
get_string('analysis', 'feedback'));
} else {
$url_params = array('id'=>$usedid, 'courseid'=>$courseid, 'do_show'=>'analysis');
$analysisurl = new moodle_url('/mod/feedback/analysis.php', $url_params);
$row[] = new tabobject('analysis',
$analysisurl->out(),
get_string('analysis', 'feedback'));
} }
if (!$context = get_context_instance(CONTEXT_MODULE, $usedid)) { $url_params = array('id'=>$usedid, 'do_show'=>'showentries');
print_error('badcontext'); $reporturl = new moodle_url('/mod/feedback/show_entries.php', $url_params);
$row[] = new tabobject('showentries',
$reporturl->out(),
get_string('show_entries', 'feedback'));
if ($feedback->anonymous == FEEDBACK_ANONYMOUS_NO AND $feedback->course != SITEID) {
$nonrespondenturl = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$usedid));
$row[] = new tabobject('nonrespondents',
$nonrespondenturl->out(),
get_string('show_nonrespondents', 'feedback'));
} }
}
if (count($row) > 1) {
$tabs[] = $row;
$courseid = optional_param('courseid', false, PARAM_INT); print_tabs($tabs, $current_tab, $inactive, $activated);
// $current_tab = $SESSION->feedback->current_tab; }
if (!isset($current_tab)) {
$current_tab = '';
}
$viewurl = new moodle_url('/mod/feedback/view.php', array('id'=>$usedid, 'do_show'=>'view'));
$row[] = new tabobject('view', $viewurl->out(), get_string('overview', 'feedback'));
if(has_capability('mod/feedback:edititems', $context)) {
$editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$usedid, 'do_show'=>'edit'));
$row[] = new tabobject('edit', $editurl->out(), get_string('edit_items', 'feedback'));
$templateurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$usedid, 'do_show'=>'templates'));
$row[] = new tabobject('templates', $templateurl->out(), get_string('templates', 'feedback'));
}
if(has_capability('mod/feedback:viewreports', $context)) {
if($feedback->course == SITEID){
$analysisurl = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$usedid, 'courseid'=>$courseid, 'do_show'=>'analysis'));
$row[] = new tabobject('analysis', $analysisurl->out(), get_string('analysis', 'feedback'));
}else {
$analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$usedid, 'courseid'=>$courseid, 'do_show'=>'analysis'));
$row[] = new tabobject('analysis', $analysisurl->out(), get_string('analysis', 'feedback'));
}
$reporturl = new moodle_url('/mod/feedback/show_entries.php', array('id'=>$usedid, 'do_show'=>'showentries'));
$row[] = new tabobject('showentries', $reporturl->out(), get_string('show_entries', 'feedback'));
if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO AND $feedback->course != SITEID) {
$nonrespondenturl = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$usedid));
$row[] = new tabobject('nonrespondents', $nonrespondenturl->out(), get_string('show_nonrespondents', 'feedback'));
}
}
if(count($row) > 1) {
$tabs[] = $row;
print_tabs($tabs, $current_tab, $inactive, $activated);
}

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* drops records from feedback_sitecourse_map * drops records from feedback_sitecourse_map

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* print the confirm dialog to use template and create new items from template * print the confirm dialog to use template and create new items from template
@ -16,11 +30,11 @@ $id = required_param('id', PARAM_INT);
$templateid = optional_param('templateid', false, PARAM_INT); $templateid = optional_param('templateid', false, PARAM_INT);
$deleteolditems = optional_param('deleteolditems', 0, PARAM_INT); $deleteolditems = optional_param('deleteolditems', 0, PARAM_INT);
if(!$templateid) { if (!$templateid) {
redirect('edit.php?id='.$id); redirect('edit.php?id='.$id);
} }
$url = new moodle_url('/mod/feedback/use_templ.php', array('id'=>$id,'templateid'=>$templateid)); $url = new moodle_url('/mod/feedback/use_templ.php', array('id'=>$id, 'templateid'=>$templateid));
if ($deleteolditems !== 0) { if ($deleteolditems !== 0) {
$url->param('deleteolditems', $deleteolditems); $url->param('deleteolditems', $deleteolditems);
} }
@ -59,7 +73,7 @@ if ($mform->is_cancelled()) {
redirect('edit.php?id='.$id.'&do_show=templates'); redirect('edit.php?id='.$id.'&do_show=templates');
} }
if(isset($formdata->confirmadd) AND $formdata->confirmadd == 1){ if (isset($formdata->confirmadd) AND $formdata->confirmadd == 1) {
feedback_items_from_template($feedback, $templateid, $deleteolditems); feedback_items_from_template($feedback, $templateid, $deleteolditems);
redirect('edit.php?id=' . $id); redirect('edit.php?id=' . $id);
} }
@ -88,37 +102,38 @@ $mform->display();
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
$templateitems = $DB->get_records('feedback_item', array('template'=>$templateid), 'position'); $templateitems = $DB->get_records('feedback_item', array('template'=>$templateid), 'position');
if(is_array($templateitems)){ if (is_array($templateitems)) {
$templateitems = array_values($templateitems); $templateitems = array_values($templateitems);
} }
if(is_array($templateitems)){ if (is_array($templateitems)) {
$itemnr = 0; $itemnr = 0;
$align = right_to_left() ? 'right' : 'left'; $align = right_to_left() ? 'right' : 'left';
echo $OUTPUT->box_start('feedback_items'); echo $OUTPUT->box_start('feedback_items');
foreach($templateitems as $templateitem){ foreach ($templateitems as $templateitem) {
echo $OUTPUT->box_start('feedback_item_box_'.$align); echo $OUTPUT->box_start('feedback_item_box_'.$align);
if($templateitem->hasvalue == 1 AND $feedback->autonumbering) { if ($templateitem->hasvalue == 1 AND $feedback->autonumbering) {
$itemnr++; $itemnr++;
echo $OUTPUT->box_start('feedback_item_number_'.$align); echo $OUTPUT->box_start('feedback_item_number_'.$align);
echo $itemnr; echo $itemnr;
echo $OUTPUT->box_end();
}
echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
if($templateitem->typ != 'pagebreak') {
// echo '<div class="feedback_item_'.$align.'">';
feedback_print_item_preview($templateitem);
}else {
echo $OUTPUT->box_start('feedback_pagebreak');
echo get_string('pagebreak', 'feedback').'<hr class="feedback_pagebreak" />';
echo $OUTPUT->box_end();
}
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
}
echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
if ($templateitem->typ != 'pagebreak') {
// echo '<div class="feedback_item_'.$align.'">';
feedback_print_item_preview($templateitem);
} else {
echo $OUTPUT->box_start('feedback_pagebreak');
echo get_string('pagebreak', 'feedback').'<hr class="feedback_pagebreak" />';
echo $OUTPUT->box_end();
}
echo $OUTPUT->box_end();
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
}else{ } else {
echo $OUTPUT->box(get_string('no_items_available_at_this_template','feedback'),'generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box(get_string('no_items_available_at_this_template', 'feedback'),
'generalbox boxaligncenter boxwidthwide');
} }
echo $OUTPUT->footer(); echo $OUTPUT->footer();

View File

@ -1,20 +1,35 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* prints the form to confirm use template * prints the form to confirm use template
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
if (!defined('MOODLE_INTERNAL')) { if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
} }
require_once $CFG->libdir.'/formslib.php'; require_once($CFG->libdir.'/formslib.php');
class mod_feedback_use_templ_form extends moodleform { class mod_feedback_use_templ_form extends moodleform {
function definition() { public function definition() {
$mform =& $this->_form; $mform =& $this->_form;
//headline //headline

View File

@ -1,17 +1,31 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Code fragment to define the version of feedback * Code fragment to define the version of feedback
* This fragment is called by moodle_needs_upgrading() and /admin/index.php * This fragment is called by moodle_needs_upgrading() and /admin/index.php
* *
* @author Andreas Grabs * @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback * @package feedback
*/ */
$module->version = 2011100800; // The current module version (Date: YYYYMMDDXX) $module->version = 2011102800; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2010080300; // Requires this Moodle version $module->requires = 2011102700; // Requires this Moodle version
$feedback_version_intern = 1; //this version is used for restore older backups $feedback_version_intern = 1; //this version is used for restore older backups
$module->cron = 0; // Period for cron to check this module (secs) $module->cron = 0; // Period for cron to check this module (secs)

View File

@ -1,4 +1,18 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* the first page to view the feedback * the first page to view the feedback
@ -13,7 +27,6 @@ require_once("lib.php");
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$courseid = optional_param('courseid', false, PARAM_INT); $courseid = optional_param('courseid', false, PARAM_INT);
// $SESSION->feedback->current_tab = 'view';
$current_tab = 'view'; $current_tab = 'view';
if (! $cm = get_coursemodule_from_id('feedback', $id)) { if (! $cm = get_coursemodule_from_id('feedback', $id)) {
@ -34,11 +47,11 @@ if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
$feedback_complete_cap = false; $feedback_complete_cap = false;
if(has_capability('mod/feedback:complete', $context)) { if (has_capability('mod/feedback:complete', $context)) {
$feedback_complete_cap = true; $feedback_complete_cap = true;
} }
if(isset($CFG->feedback_allowfullanonymous) if (isset($CFG->feedback_allowfullanonymous)
AND $CFG->feedback_allowfullanonymous AND $CFG->feedback_allowfullanonymous
AND $course->id == SITEID AND $course->id == SITEID
AND (!$courseid OR $courseid == SITEID) AND (!$courseid OR $courseid == SITEID)
@ -47,52 +60,53 @@ if(isset($CFG->feedback_allowfullanonymous)
} }
//check whether the feedback is located and! started from the mainsite //check whether the feedback is located and! started from the mainsite
if($course->id == SITEID AND !$courseid) { if ($course->id == SITEID AND !$courseid) {
$courseid = SITEID; $courseid = SITEID;
} }
//check whether the feedback is mapped to the given courseid //check whether the feedback is mapped to the given courseid
if($course->id == SITEID AND !has_capability('mod/feedback:edititems', $context)) { if ($course->id == SITEID AND !has_capability('mod/feedback:edititems', $context)) {
if($DB->get_records('feedback_sitecourse_map', array('feedbackid'=>$feedback->id))) { if ($DB->get_records('feedback_sitecourse_map', array('feedbackid'=>$feedback->id))) {
if(!$DB->get_record('feedback_sitecourse_map', array('feedbackid'=>$feedback->id, 'courseid'=>$courseid))){ $params = array('feedbackid'=>$feedback->id, 'courseid'=>$courseid);
if (!$DB->get_record('feedback_sitecourse_map', $params)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
} }
} }
if($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) { if ($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
if($course->id == SITEID) { if ($course->id == SITEID) {
require_login($course->id, true); require_login($course->id, true);
}else { } else {
require_login($course->id, true, $cm); require_login($course->id, true, $cm);
} }
} else { } else {
if($course->id == SITEID) { if ($course->id == SITEID) {
require_course_login($course, true); require_course_login($course, true);
}else { } else {
require_course_login($course, true, $cm); require_course_login($course, true, $cm);
} }
} }
//check whether the given courseid exists //check whether the given courseid exists
if($courseid AND $courseid != SITEID) { if ($courseid AND $courseid != SITEID) {
if($course2 = $DB->get_record('course', array('id'=>$courseid))){ if ($course2 = $DB->get_record('course', array('id'=>$courseid))) {
require_course_login($course2); //this overwrites the object $course :-( require_course_login($course2); //this overwrites the object $course :-(
$course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
}else { } else {
print_error('invalidcourseid'); print_error('invalidcourseid');
} }
} }
if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) { if ($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
add_to_log($course->id, 'feedback', 'view', 'view.php?id='.$cm->id, $feedback->id,$cm->id); add_to_log($course->id, 'feedback', 'view', 'view.php?id='.$cm->id, $feedback->id, $cm->id);
} }
/// Print the page header /// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback"); $strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback"); $strfeedback = get_string("modulename", "feedback");
if($course->id == SITEID) { if ($course->id == SITEID) {
$PAGE->set_context($context); $PAGE->set_context($context);
$PAGE->set_cm($cm, $course); // set's up global $COURSE $PAGE->set_cm($cm, $course); // set's up global $COURSE
$PAGE->set_pagelayout('incourse'); $PAGE->set_pagelayout('incourse');
@ -104,13 +118,14 @@ echo $OUTPUT->header();
//ishidden check. //ishidden check.
//feedback in courses //feedback in courses
if ((empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) AND $course->id != SITEID) { $cap_viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context);
if ((empty($cm->visible) and !$cap_viewhiddenactivities) AND $course->id != SITEID) {
notice(get_string("activityiscurrentlyhidden")); notice(get_string("activityiscurrentlyhidden"));
} }
//ishidden check. //ishidden check.
//feedback on mainsite //feedback on mainsite
if ((empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) AND $courseid == SITEID) { if ((empty($cm->visible) and !$cap_viewhiddenactivities) AND $courseid == SITEID) {
notice(get_string("activityiscurrentlyhidden")); notice(get_string("activityiscurrentlyhidden"));
} }
@ -120,7 +135,7 @@ if ((empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/// print the tabs /// print the tabs
include('tabs.php'); require('tabs.php');
$previewimg = $OUTPUT->pix_icon('t/preview', get_string('preview')); $previewimg = $OUTPUT->pix_icon('t/preview', get_string('preview'));
$previewlnk = '<a href="'.$CFG->wwwroot.'/mod/feedback/print.php?id='.$id.'">'.$previewimg.'</a>'; $previewlnk = '<a href="'.$CFG->wwwroot.'/mod/feedback/print.php?id='.$id.'">'.$previewimg.'</a>';
@ -128,36 +143,58 @@ $previewlnk = '<a href="'.$CFG->wwwroot.'/mod/feedback/print.php?id='.$id.'">'.$
echo $OUTPUT->heading(format_text($feedback->name.' '.$previewlnk)); echo $OUTPUT->heading(format_text($feedback->name.' '.$previewlnk));
//show some infos to the feedback //show some infos to the feedback
if(has_capability('mod/feedback:edititems', $context)) { if (has_capability('mod/feedback:edititems', $context)) {
//get the groupid //get the groupid
$groupselect = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/feedback/view.php?id=' . $cm->id, true); $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id, true);
$mygroupid = groups_get_activity_group($cm); $mygroupid = groups_get_activity_group($cm);
echo $OUTPUT->box_start('boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('boxaligncenter boxwidthwide');
echo $groupselect.'<div class="clearer">&nbsp;</div>'; echo $groupselect.'<div class="clearer">&nbsp;</div>';
$completedscount = feedback_get_completeds_group_count($feedback, $mygroupid); $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid);
echo $OUTPUT->box_start('feedback_info'); echo $OUTPUT->box_start('feedback_info');
echo '<span class="feedback_info">'.get_string('completed_feedbacks', 'feedback').': </span><span class="feedback_info_value">'.$completedscount. '</span>'; echo '<span class="feedback_info">';
echo $OUTPUT->box_end(); echo get_string('completed_feedbacks', 'feedback').': ';
$itemscount = $DB->count_records('feedback_item', array('feedback'=>$feedback->id, 'hasvalue'=>1)); echo '</span>';
echo $OUTPUT->box_start('feedback_info'); echo '<span class="feedback_info_value">';
echo '<span class="feedback_info">'.get_string('questions', 'feedback').': </span><span class="feedback_info_value">' .$itemscount. '</span>'; echo $completedscount;
echo '</span>';
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
if($feedback->timeopen) { $params = array('feedback'=>$feedback->id, 'hasvalue'=>1);
$itemscount = $DB->count_records('feedback_item', $params);
echo $OUTPUT->box_start('feedback_info');
echo '<span class="feedback_info">';
echo get_string('questions', 'feedback').': ';
echo '</span>';
echo '<span class="feedback_info_value">';
echo $itemscount;
echo '</span>';
echo $OUTPUT->box_end();
if ($feedback->timeopen) {
echo $OUTPUT->box_start('feedback_info'); echo $OUTPUT->box_start('feedback_info');
echo '<span class="feedback_info">'.get_string('feedbackopen', 'feedback').': </span><span class="feedback_info_value">' .UserDate($feedback->timeopen). '</span>'; echo '<span class="feedback_info">';
echo get_string('feedbackopen', 'feedback').': ';
echo '</span>';
echo '<span class="feedback_info_value">';
echo userdate($feedback->timeopen);
echo '</span>';
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
if($feedback->timeclose) { if ($feedback->timeclose) {
echo $OUTPUT->box_start('feedback_info'); echo $OUTPUT->box_start('feedback_info');
echo '<span class="feedback_info">'.get_string('timeclose', 'feedback').': </span><span class="feedback_info_value">' .UserDate($feedback->timeclose). '</span>'; echo '<span class="feedback_info">';
echo get_string('timeclose', 'feedback').': ';
echo '</span>';
echo '<span class="feedback_info_value">';
echo userdate($feedback->timeclose);
echo '</span>';
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
if(has_capability('mod/feedback:edititems', $context)) { if (has_capability('mod/feedback:edititems', $context)) {
echo $OUTPUT->heading(get_string('description', 'feedback'), 4); echo $OUTPUT->heading(get_string('description', 'feedback'), 4);
} }
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
@ -165,28 +202,33 @@ $options = (object)array('noclean'=>true);
echo format_module_intro('feedback', $feedback, $cm->id); echo format_module_intro('feedback', $feedback, $cm->id);
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
if(has_capability('mod/feedback:edititems', $context)) { if (has_capability('mod/feedback:edititems', $context)) {
echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4); echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4);
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
echo format_text($feedback->page_after_submit, $feedback->page_after_submitformat, array('overflowdiv'=>true)); echo format_text($feedback->page_after_submit,
$feedback->page_after_submitformat,
array('overflowdiv'=>true));
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
if( (intval($feedback->publish_stats) == 1) AND if ( (intval($feedback->publish_stats) == 1) AND
( has_capability('mod/feedback:viewanalysepage', $context)) AND ( has_capability('mod/feedback:viewanalysepage', $context)) AND
!( has_capability('mod/feedback:viewreports', $context)) ) { !( has_capability('mod/feedback:viewreports', $context)) ) {
if($multiple_count = $DB->count_records('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedback->id))) {
$analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid)); $params = array('userid'=>$USER->id, 'feedback'=>$feedback->id);
if ($multiple_count = $DB->count_records('feedback_tracking', $params)) {
$url_params = array('id'=>$id, 'courseid'=>$courseid);
$analysisurl = new moodle_url('/mod/feedback/analysis.php', $url_params);
echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">'; echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
echo get_string('completed_feedbacks', 'feedback').'</a>'; echo get_string('completed_feedbacks', 'feedback').'</a>';
echo '</div>'; echo '</div>';
} }
} }
// echo '<p>';
//####### mapcourse-start //####### mapcourse-start
if(has_capability('mod/feedback:mapcourse', $context)) { if (has_capability('mod/feedback:mapcourse', $context)) {
if($feedback->course == SITEID) { if ($feedback->course == SITEID) {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
echo '<div class="mdl-align">'; echo '<div class="mdl-align">';
echo '<form action="mapcourse.php" method="get">'; echo '<form action="mapcourse.php" method="get">';
@ -205,13 +247,15 @@ if(has_capability('mod/feedback:mapcourse', $context)) {
//####### mapcourse-end //####### mapcourse-end
//####### completed-start //####### completed-start
if($feedback_complete_cap) { if ($feedback_complete_cap) {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
//check, whether the feedback is open (timeopen, timeclose) //check, whether the feedback is open (timeopen, timeclose)
$checktime = time(); $checktime = time();
if(($feedback->timeopen > $checktime) OR ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) { if (($feedback->timeopen > $checktime) OR
echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>'; ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>';
echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
echo $OUTPUT->footer(); echo $OUTPUT->footer();
exit; exit;
@ -219,42 +263,45 @@ if($feedback_complete_cap) {
//check multiple Submit //check multiple Submit
$feedback_can_submit = true; $feedback_can_submit = true;
if($feedback->multiple_submit == 0 ) { if ($feedback->multiple_submit == 0 ) {
if(feedback_is_already_submitted($feedback->id, $courseid)) { if (feedback_is_already_submitted($feedback->id, $courseid)) {
$feedback_can_submit = false; $feedback_can_submit = false;
} }
} }
if($feedback_can_submit) { if ($feedback_can_submit) {
//if the user is not known so we cannot save the values temporarly //if the user is not known so we cannot save the values temporarly
if(!isloggedin() or isguestuser()) { if (!isloggedin() or isguestuser()) {
$completefile = 'complete_guest.php'; $completefile = 'complete_guest.php';
$guestid = sesskey(); $guestid = sesskey();
}else { } else {
$completefile = 'complete.php'; $completefile = 'complete.php';
$guestid = false; $guestid = false;
} }
$completeurl = new moodle_url('/mod/feedback/'.$completefile, array('id'=>$id, 'courseid'=>$courseid, 'gopage'=>0)); $url_params = array('id'=>$id, 'courseid'=>$courseid, 'gopage'=>0);
$completeurl = new moodle_url('/mod/feedback/'.$completefile, $url_params);
if($feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid, $guestid)) { $feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid, $guestid);
if($startpage = feedback_get_page_to_continue($feedback->id, $courseid, $guestid)) { if ($feedbackcompletedtmp) {
if ($startpage = feedback_get_page_to_continue($feedback->id, $courseid, $guestid)) {
$completeurl->param('gopage', $startpage); $completeurl->param('gopage', $startpage);
} }
echo '<a href="'.$completeurl->out().'">'.get_string('continue_the_form', 'feedback').'</a>'; echo '<a href="'.$completeurl->out().'">'.get_string('continue_the_form', 'feedback').'</a>';
}else { } else {
echo '<a href="'.$completeurl->out().'">'.get_string('complete_the_form', 'feedback').'</a>'; echo '<a href="'.$completeurl->out().'">'.get_string('complete_the_form', 'feedback').'</a>';
} }
}else { } else {
echo '<h2><font color="red">'.get_string('this_feedback_is_already_submitted', 'feedback').'</font></h2>'; echo '<h2><font color="red">';
if($courseid) { echo get_string('this_feedback_is_already_submitted', 'feedback');
echo '</font></h2>';
if ($courseid) {
echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid); echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid);
}else { } else {
echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id); echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
} }
} }
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
} }
//####### completed-end //####### completed-end
// echo "</p>";
/// Finish the page /// Finish the page
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////