merge the items dropdown, radio and check to multiplechoice item

merge the items dropdownrated, radiorated to multiplechoicerated item
the creating or editing of an item now use the formslib
This commit is contained in:
agrabs 2008-04-28 09:58:09 +00:00
parent 13b31d6f9d
commit 6ee09cfe8b
25 changed files with 1342 additions and 1708 deletions

View File

@ -141,6 +141,32 @@ function xmldb_feedback_upgrade($oldversion=0) {
}
}
if ($result && $oldversion < 2008042400) { //New version in version.php
if($all_nonanonymous_feedbacks = get_records('feedback', 'anonymous', 2)) {
$update_sql = 'UPDATE '.$CFG->prefix.'feedback_completed SET anonymous_response = 2 WHERE feedback = ';
foreach ($all_nonanonymous_feedbacks as $fb) {
$result = $result && execute_sql($update_sql.$fb->id);
}
}
}
if ($result && $oldversion < 2008042401) { //New version in version.php
if($result) {
$update_sql1 = "UPDATE ".$CFG->prefix."feedback_item SET presentation = CONCAT('r>>>>>',presentation) WHERE typ IN('radio','radiorated')";
$update_sql2 = "UPDATE ".$CFG->prefix."feedback_item SET presentation = CONCAT('d>>>>>',presentation) WHERE typ IN('dropdown','dropdownrated')";
$update_sql3 = "UPDATE ".$CFG->prefix."feedback_item SET presentation = CONCAT('c>>>>>',presentation) WHERE typ = 'check'";
$result = $result && execute_sql($update_sql1);
$result = $result && execute_sql($update_sql2);
$result = $result && execute_sql($update_sql3);
}
if($result) {
$update_sql1 = "UPDATE ".$CFG->prefix."feedback_item SET typ = 'multichoice' WHERE typ IN('radio','check','dropdown')";
$update_sql2 = "UPDATE ".$CFG->prefix."feedback_item SET typ = 'multichoicerated' WHERE typ IN('radiorated','dropdownrated')";
$result = $result && execute_sql($update_sql1);
$result = $result && execute_sql($update_sql2);
}
}
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete

View File

@ -20,10 +20,11 @@
// set up some general variables
$usehtmleditor = can_use_html_editor();
if(($formdata = data_submitted('nomatch')) AND !confirm_sesskey()) {
error('no sesskey defined');
}
if ($id) {
if (! $cm = get_coursemodule_from_id('feedback', $id)) {
error("Course Module ID was incorrect");
@ -69,7 +70,7 @@
if(isset($formdata->cancel)){
redirect(htmlspecialchars('edit.php?id=' . $id));
}
// if(isset($formdata->editcancel) AND $formdata->editcancel == 1){
// redirect(htmlspecialchars('edit.php?id=' . $id));
// }
@ -130,11 +131,55 @@
if(isset($error)){echo $error;}
feedback_print_errors();
//new formdefinition
require_once('blank_form.php');
$itemclass = 'feedback_item_'.$typ;
$itemobj = new $itemclass();
$item_form = &$itemobj->show_edit($item);
// $item_form = new feedback_blank_form();
$i_form = &$item_form->_form;
// $i_form->addElement('header', 'general', 'Titel');
$i_form->addElement('hidden', 'id', $id);
$i_form->addElement('hidden', 'itemid', isset($item->id)?$item->id:'');
$i_form->addElement('hidden', 'typ', $typ);
$i_form->addElement('hidden', 'feedbackid', $feedback->id);
$lastposition = count_records('feedback_item', 'feedback', $feedback->id);
if($position == -1){
$i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1;
}else {
$i_formselect_last = $lastposition;
$i_formselect_value = $item->position;
}
$i_formselect = $i_form->addElement('select',
'position',
get_string('position', 'feedback').'&nbsp;',
array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true));
$i_formselect->setValue($i_formselect_value);
if(!empty($item->id)){
$i_form->addElement('hidden', 'updateitem', '1');
$i_form->addElement('submit', 'update_item', get_string('update_item', 'feedback'));
// echo '<input type="hidden" id="updateitem" name="updateitem" value="1" />';
// echo '<input type="submit" value ="'.get_string('update_item', 'feedback').'" />';
}else{
$i_form->addElement('hidden', 'saveitem', '1');
$i_form->addElement('submit', 'save_item', get_string('save_item', 'feedback'));
// echo '<input type="hidden" id="saveitem" name="saveitem" value="1" />';
// echo '<input type="submit" value="'.get_string('save_item', 'feedback').'" />';
}
$i_form->addElement('cancel');
$item_form->display();
/*
// print_simple_box_start('center');
print_box_start('generalbox boxwidthwide boxaligncenter');
echo '<form action="'.$ME.'" method="post">';
echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
echo '<form action="'.$ME.'" method="post">';
echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
//this div makes the buttons stand side by side
echo '<div>';
@ -142,10 +187,10 @@
$itemobj = new $itemclass();
$itemobj->show_edit($item, $usehtmleditor);
echo '</div>';
echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '<input type="hidden" name="itemid" value="'.(isset($item->id)?$item->id:'').'" />';
echo '<input type="hidden" name="typ" value="'.$typ.'" />';
echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'" />';
echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '<input type="hidden" name="itemid" value="'.(isset($item->id)?$item->id:'').'" />';
echo '<input type="hidden" name="typ" value="'.$typ.'" />';
echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'" />';
//choose the position
$lastposition = count_records('feedback_item', 'feedback', $feedback->id);
@ -172,7 +217,7 @@
echo '</form>';
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
*/
// print_simple_box_end();
print_box_end();

View File

@ -0,0 +1,26 @@
<?php
require_once $CFG->libdir.'/formslib.php';
class feedback_captcha_form extends moodleform {
var $type = "captcha";
var $requiredcheck;
var $itemname;
var $select;
function definition() {
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
$this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"'));
$this->select = $mform->addElement('select',
'count_of_nums',
get_string('count_of_nums', 'feedback').'&nbsp;',
array_slice(range(0,10),3,10,true));
}
}
?>

View File

@ -8,36 +8,25 @@ class feedback_item_captcha extends feedback_item_base {
}
function show_edit($item, $usehtmleditor = false) {
function show_edit($item) {
global $CFG;
require_once('captcha_form.php');
$item_form = new feedback_captcha_form();
$item->presentation=empty($item->presentation)? 3 : $item->presentation;
$item->presentation = empty($item->presentation) ? 3 : $item->presentation;
$item->name = empty($item->name) ? '' : $item->name;
$item->required = isset($item->required) ? $item->required : 1;
if($item->required) {
$item_form->requiredcheck->setValue(true);
}
?>
<table>
<tr>
<th colspan="2"><?php print_string('numeric', 'feedback');?>
&nbsp;(<input type="checkbox" name="required" value="1" <?php
$item->required = isset($item->required) ? $item->required : 1;
echo ($item->required == 1?'checked="checked"':'');
?> />&nbsp;<?php print_string('required', 'feedback');?>)
</th>
</tr>
<tr>
<td><?php print_string('item_name', 'feedback');?></td>
<td><input type="text" id="itemname" name="itemname" size="40" maxlength="255" value="<?php echo isset($item->name)?htmlspecialchars(stripslashes_safe($item->name)):'';?>" /></td>
</tr>
<tr>
<td><?php print_string('count_of_nums', 'feedback');?></td>
<td>
<select name="count_of_nums">
<?php
feedback_print_numeric_option_list(3, 10, $item->presentation);
?>
</select>
</td>
</tr>
</table>
<?php
$item_form->itemname->setValue($item->name);
$item_form->select->setValue($item->presentation);
return $item_form;
}
//liefert eine Struktur ->name, ->data = array(mit Antworten)

View File

@ -23,7 +23,8 @@
$height = 40;
$charcount = $SESSION->feedback->item->captcha->charcount;
$fontfile = $CFG->dirroot.'/mod/feedback/item/captcha/default.ttf';
// $fontfile = $CFG->dirroot.'/mod/feedback/item/captcha/default.ttf';
$fontfile = $CFG->libdir.'/default.ttf';
$ttfbox = imagettfbbox ( 30, 0, $fontfile, 'H' );//the text to measure
$charwidth = $ttfbox[2];

View File

@ -1,314 +0,0 @@
<?PHP // $Id$
defined('FEEDBACK_INCLUDE_TEST') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
define('FEEDBACK_CHECK_LINE_SEP', '|');
define('FEEDBACK_CHECK_ADJUST_SEP', '<<<<<');
class feedback_item_check extends feedback_item_base {
var $type = "check";
function init() {
}
function show_edit($item, $usehtmleditor = false) {
$item->presentation = empty($item->presentation) ? '' : $item->presentation;
//check, whether the buttons are vertical or horizontal
$presentation = $horizontal = '';
@list($presentation, $horizontal) = explode(FEEDBACK_CHECK_ADJUST_SEP, $item->presentation);
if(isset($horizontal) AND $horizontal == 1) {
$horizontal = true;
}else {
$horizontal = false;
}
?>
<table>
<tr><th colspan="2">
<?php print_string('check', 'feedback');?>
&nbsp;(<input type="checkbox" name="required" value="1" <?php
$item->required=isset($item->required) ? $item->required : 0;
echo ($item->required == 1?'checked="checked"':'');
?> />&nbsp;<?php print_string('required', 'feedback');?>)
</th>
</tr>
<tr>
<td colspan="2">
<?php print_string('adjustment', 'feedback');?>:
&nbsp;<?php print_string('vertical', 'feedback');?><input type="radio" name="horizontal" value="0" <?php echo $horizontal ? '' : 'checked="checked"';?> />
&nbsp;<?php print_string('horizontal', 'feedback');?><input type="radio" name="horizontal" value="1" <?php echo $horizontal ? 'checked="checked"' : '';?> />
</td>
</tr>
<tr>
<td><?php print_string('item_name', 'feedback');?></td>
<td><input type="text" id="itemname" name="itemname" size="40" maxlength="255" value="<?php echo isset($item->name)?htmlspecialchars(stripslashes_safe($item->name)):'';?>" /></td>
</tr>
<tr>
<td>
<?php print_string('check_values', 'feedback');?>
<?php print_string('use_one_line_for_each_value', 'feedback');?>
</td>
<td>
<?php
$itemvalues = str_replace(FEEDBACK_CHECK_LINE_SEP, "\n", stripslashes_safe($presentation));
?>
<textarea name="itemvalues" cols="30" rows="5"><?php echo $itemvalues;?></textarea>
</td>
</tr>
</table>
<?php
}
//liefert ein Array mit drei Werten(typ, name, XXX)
//XXX ist ein Array (anzahl der Antworten bei Typ checkbox) Jedes Element ist eine Struktur (answertext, answercount)
function get_analysed($item, $groupid = false, $courseid = false) {
$analysedItem = array();
$analysedItem[] = $item->typ;
$analysedItem[] = $item->name;
//die moeglichen Antworten extrahieren
$answers = null;
$presentation = '';
@list($presentation) = explode(FEEDBACK_CHECK_ADJUST_SEP, $item->presentation); //remove the adjustment-info
$answers = explode (FEEDBACK_CHECK_LINE_SEP, stripslashes_safe($presentation));
if(!is_array($answers)) return null;
//die Werte holen
$values = feedback_get_group_values($item, $groupid, $courseid);
if(!$values) return null;
//schleife ueber den Werten und ueber die Antwortmoeglichkeiten
$analysedAnswer = array();
for($i = 1; $i <= sizeof($answers); $i++) {
$ans = null;
$ans->answertext = $answers[$i-1];
$ans->answercount = 0;
foreach($values as $value) {
//ist die Antwort gleich dem index der Antworten + 1?
$vallist = explode(FEEDBACK_CHECK_LINE_SEP, $value->value);
foreach($vallist as $val) {
if ($val == $i) {
$ans->answercount++;
}
}
}
$ans->quotient = $ans->answercount / sizeof($values);
$analysedAnswer[] = $ans;
}
$analysedItem[] = $analysedAnswer;
return $analysedItem;
}
function get_printval($item, $value) {
$printval = '';
if(!isset($value->value)) return $printval;
@list($presentation) = explode(FEEDBACK_CHECK_ADJUST_SEP, $item->presentation); //remove the adjustment-info
$presentation = array_values(explode (FEEDBACK_CHECK_LINE_SEP, stripslashes_safe($presentation)));
$vallist = array_values(explode (FEEDBACK_CHECK_LINE_SEP, $value->value));
for($i = 0; $i < sizeof($vallist); $i++) {
for($k = 0; $k < sizeof($presentation); $k++) {
if($vallist[$i] == ($k + 1)) {//Die Werte beginnen bei 1, das Array aber mit 0
$printval .= trim($presentation[$k]) . chr(10);
break;
}
}
}
return $printval;
}
function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) {
$sep_dec = get_string('separator_decimal', 'feedback');
if(substr($sep_dec, 0, 2) == '[['){
$sep_dec = FEEDBACK_DECIMAL;
}
$sep_thous = get_string('separator_thousand', 'feedback');
if(substr($sep_thous, 0, 2) == '[['){
$sep_thous = FEEDBACK_THOUSAND;
}
$analysedItem = $this->get_analysed($item, $groupid, $courseid);
if($analysedItem) {
$itemnr++;
$itemname = stripslashes($analysedItem[1]);
echo '<tr><th colspan="2" align="left">'. $itemnr . '.)&nbsp;' . $itemname .'</th></tr>';
$analysedVals = $analysedItem[2];
$pixnr = 0;
foreach($analysedVals as $val) {
if( function_exists("bcmod")) {
$intvalue = bcmod($pixnr, 10);
}else {
$intvalue = 0;
}
$pix = "pics/$intvalue.gif";
$pixnr++;
$pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
$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>';
}
}
return $itemnr;
}
function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
$data = $analysed_item[2];
$worksheet->setFormat("<l><f><ro2><vo><c:green>");
//frage schreiben
$worksheet->write_string($rowOffset, 0, stripslashes($analysed_item[1]));
if(is_array($data)) {
for($i = 0; $i < sizeof($data); $i++) {
$aData = $data[$i];
$worksheet->setFormat("<l><f><ro2><vo><c:blue>");
$worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext));
$worksheet->setFormat("<l><vo>");
$worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount);
$worksheet->setFormat("<l><f><vo><pr>");
$worksheet->write_number($rowOffset + 2, $i + 1, $aData->quotient);
}
}
$rowOffset +=3 ;
return $rowOffset;
}
function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){
$align = get_string('thisdirection') == 'ltr' ? 'left' : 'right';
//extract the adjustment-info
$presentation = $horizontal = '';
@list($presentation, $horizontal) = explode(FEEDBACK_CHECK_ADJUST_SEP, $item->presentation);
if(isset($horizontal) AND $horizontal == 1) {
$horizontal = true;
}else {
$horizontal = false;
}
$presentation = explode (FEEDBACK_CHECK_LINE_SEP, stripslashes_safe($presentation));
if (is_array($value)) {
$values = $value;
}else {
$values = explode(FEEDBACK_CHECK_LINE_SEP, $value);
}
if($highlightrequire AND $item->required AND $values[0] == '') {
$highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
}else {
$highlight = '';
}
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
echo '<td '.$highlight.' valign="top" align="'.$align.'">'.format_text(stripslashes_safe($item->name).$requiredmark, true, false, false).'</td>';
echo '<td valign="top" align="'.$align.'">';
$index = 1;
$checked = '';
if($readonly){
// print_simple_box_start($align);
print_box_start('generalbox boxalign'.$align);
foreach($presentation as $check){
foreach($values as $val) {
if($val == $index){
echo text_to_html($check . '<br />', true, false, false);
break;
}
}
$index++;
}
// print_simple_box_end();
print_box_end();
} else {
if($horizontal) {
echo '<table><tr>';
}
foreach($presentation as $check){
foreach($values as $val) {
if($val == $index){
$checked = 'checked="checked"';
break;
}else{
$checked = '';
}
}
$inputname = $item->typ. '_' . $item->id;
$inputid = $item->typ. '_' . $item->id.'_'.$index;
if($horizontal) {
?>
<td valign="top" align="<?php echo $align;?>"><input type="checkbox"
name="<?php echo $inputname;?>[]"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td><td align="<?php echo $align;?>"><label for="<?php echo $inputid;?>"><?php echo text_to_html($check, true, false, false);?>&nbsp;</label>
</td>
<?php
}else {
?>
<table><tr>
<td valign="top" align="<?php echo $align;?>"><input type="checkbox"
name="<?php echo $inputname;?>[]"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td><td align="<?php echo $align;?>"><label for="<?php echo $inputid;?>"><?php echo text_to_html($check, true, false, false);?>&nbsp;</label>
</td></tr></table>
<?php
}
$index++;
}
if($horizontal) {
echo '</tr></table>';
}
}
?>
<input type="hidden" name="<?php echo $item->typ. '_' . $item->id?>[]" value="" />
</td>
<?php
}
function check_value($value, $item) {
//if the item is not required, so the check is true if no value is given
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;
}
function create_value($data) {
$vallist = $data;
return trim($this->item_arrayToString($vallist));
}
function get_presentation($data) {
$present = str_replace("\n", FEEDBACK_CHECK_LINE_SEP, trim($data->itemvalues));
if($data->horizontal == 1) {
$present .= FEEDBACK_CHECK_ADJUST_SEP.'1';
}
return $present;
}
function get_hasvalue() {
return 1;
}
function item_arrayToString($arr) {
if(!is_array($arr)) {
return '';
}
$retval = '';
$arrvals = array_values($arr);
$arrvals = clean_param($arrvals, PARAM_INT); //prevent sql-injection
$retval = $arrvals[0];
for($i = 1; $i < sizeof($arrvals) - 1; $i++) {
$retval .= FEEDBACK_CHECK_LINE_SEP.$arrvals[$i];
}
return $retval;
}
}
?>

View File

@ -1,233 +0,0 @@
<?PHP // $Id$
defined('FEEDBACK_INCLUDE_TEST') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_dropdown extends feedback_item_base {
var $type = "dropdown";
function init() {
}
function show_edit($item, $usehtmleditor = false) {
$item->presentation=empty($item->presentation)?'':$item->presentation;
?>
<table>
<tr>
<th colspan="2"><?php print_string('dropdown', 'feedback');?>
&nbsp;(<input type="checkbox" name="required" value="1" <?php
$item->required=isset($item->required)?$item->required:0;
echo ($item->required == 1?'checked="checked"':'');
?> />&nbsp;<?php print_string('required', 'feedback');?>)
</th>
</tr>
<tr>
<td><?php print_string('item_name', 'feedback');?></td>
<td><input type="text" id="itemname" name="itemname" size="40" maxlength="255" value="<?php echo isset($item->name)?htmlspecialchars(stripslashes_safe($item->name)):'';?>" /></td>
</tr>
<tr>
<td>
<?php print_string('dropdown_values', 'feedback');?>
<?php print_string('use_one_line_for_each_value', 'feedback');?>
</td>
<td>
<?php
$itemvalues = str_replace('|', "\n", stripslashes_safe($item->presentation));
?>
<textarea name="itemvalues" cols="30" rows="5"><?php echo $itemvalues;?></textarea>
</td>
</tr>
</table>
<?php
}
//liefert ein eindimensionales Array mit drei Werten(typ, name, XXX)
//XXX ist ein eindimensionales Array (anzahl der Antworten bei Typ DropDown) Jedes Element ist eine Struktur (answertext, answercount)
function get_analysed($item, $groupid = false, $courseid = false) {
$analysedItem = array();
$analysedItem[] = $item->typ;
$analysedItem[] = $item->name;
//die moeglichen Antworten extrahieren
$answers = null;
$answers = explode ("|", stripslashes_safe($item->presentation));
if(!is_array($answers)) return null;
//die Werte holen
//$values = get_records('feedback_value', 'item', $item->id);
$values = feedback_get_group_values($item, $groupid, $courseid);
if(!$values) return null;
//schleife ueber den Werten und ueber die Antwortmoeglichkeiten
$analysedAnswer = array();
for($i = 1; $i <= sizeof($answers); $i++) {
$ans = null;
$ans->answertext = $answers[$i-1];
$ans->answercount = 0;
foreach($values as $value) {
//ist die Antwort gleich dem index der Antworten + 1?
if ($value->value == $i) {
$ans->answercount++;
}
}
$ans->quotient = $ans->answercount / sizeof($values);
$analysedAnswer[] = $ans;
}
$analysedItem[] = $analysedAnswer;
return $analysedItem;
}
function get_printval($item, $value) {
$printval = '';
if(!isset($value->value)) return $printval;
$presentation = explode ("|", stripslashes_safe($item->presentation));
$index = 1;
foreach($presentation as $pres){
if($value->value == $index){
$printval = $pres;
break;
}
$index++;
}
return $printval;
}
function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) {
$sep_dec = get_string('separator_decimal', 'feedback');
if(substr($sep_dec, 0, 2) == '[['){
$sep_dec = FEEDBACK_DECIMAL;
}
$sep_thous = get_string('separator_thousand', 'feedback');
if(substr($sep_thous, 0, 2) == '[['){
$sep_thous = FEEDBACK_THOUSAND;
}
$analysedItem = $this->get_analysed($item, $groupid, $courseid);
if($analysedItem) {
//echo '<table>';
$itemnr++;
echo '<tr><th colspan="2" align="left">'. $itemnr . '.)&nbsp;' . stripslashes($analysedItem[1]) .'</th></tr>';
$analysedVals = $analysedItem[2];
$pixnr = 0;
foreach($analysedVals as $val) {
if( function_exists("bcmod")) {
$intvalue = bcmod($pixnr, 10);
}else {
$intvalue = 0;
}
$pix = "pics/$intvalue.gif";
$pixnr++;
$pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
$quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous);
echo '<tr><td valign="top" align="left">-&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>';
}
//echo '</table>';
}
return $itemnr;
}
function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
$data = $analysed_item[2];
$worksheet->setFormat("<l><f><ro2><vo><c:green>");
//frage schreiben
$worksheet->write_string($rowOffset, 0, stripslashes($analysed_item[1]));
if(is_array($data)) {
for($i = 0; $i < sizeof($data); $i++) {
$aData = $data[$i];
$worksheet->setFormat("<l><f><ro2><vo><c:blue>");
$worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext));
$worksheet->setFormat("<l><vo>");
$worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount);
$worksheet->setFormat("<l><f><vo><pr>");
$worksheet->write_number($rowOffset + 2, $i + 1, $aData->quotient);
}
}
$rowOffset +=3 ;
return $rowOffset;
}
function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){
$align = get_string('thisdirection') == 'ltr' ? 'left' : 'right';
$presentation = explode ("|", stripslashes_safe($item->presentation));
if($highlightrequire AND $item->required AND intval($value) <= 0) {
$highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
}else {
$highlight = '';
}
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
?>
<td <?php echo $highlight;?> valign="top" align="<?php echo $align;?>"><?php echo format_text(stripslashes_safe($item->name) . $requiredmark, true, false, false);?></td>
<td valign="top" align="<?php echo $align;?>">
<?php
$index = 1;
$selected = '';
if($readonly){
foreach($presentation as $dropdown){
if($value == $index){
// print_simple_box_start($align);
print_box_start('generalbox boxalign'.$align);
echo text_to_html($dropdown, true, false, false);
// print_simple_box_end();
print_box_end();
break;
}
$index++;
}
} else {
?>
<select name="<?php echo $item->typ .'_' . $item->id;?>" size="1">
<option value="0">&nbsp;</option>
<?php
foreach($presentation as $dropdown){
if($value == $index){
$selected = 'selected="selected"';
}else{
$selected = '';
}
?>
<option value="<?php echo $index;?>" <?php echo $selected;?>><?php echo text_to_html($dropdown, true, false, false);?></option>
<?php
$index++;
}
?>
</select>
<?php
}
?>
</td>
<?php
}
function check_value($value, $item) {
//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($value == 0)return false;
return true;
}
function create_value($data) {
$data = clean_param($data, PARAM_INT);
return $data;
}
function get_presentation($data) {
$present = str_replace("\n", '|', trim($data->itemvalues));
return $present;
}
function get_hasvalue() {
return 1;
}
}
?>

View File

@ -1,303 +0,0 @@
<?PHP // $Id$
defined('FEEDBACK_INCLUDE_TEST') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
define('FEEDBACK_DROPDOWNRATED_MAXCOUNT', 10); //count of possible items
define('FEEDBACK_DROPDOWN_LINE_SEP', '|');
define('FEEDBACK_DROPDOWN_VALUE_SEP', '####');
class feedback_item_dropdownrated extends feedback_item_base {
var $type = "dropdownrated";
function init() {
}
function show_edit($item, $usehtmleditor = false) {
$item->presentation=empty($item->presentation)?'':$item->presentation;
?>
<table>
<tr>
<th colspan="2"><?php print_string('dropdownrated', 'feedback');?>
&nbsp;(<input type="checkbox" name="required" value="1" <?php
$item->required=isset($item->required)?$item->required:0;
echo ($item->required == 1?'checked="checked"':'');
?> />&nbsp;<?php print_string('required', 'feedback');?>)
</th>
</tr>
<tr>
<td><?php print_string('item_name', 'feedback');?></td>
<td><input type="text" id="itemname" name="itemname" size="40" maxlength="255" value="<?php echo isset($item->name)?htmlspecialchars(stripslashes_safe($item->name)):'';?>" /></td>
</tr>
<tr>
<td>
<?php print_string('dropdown_values', 'feedback');?>
</td>
<td>
<?php
//$itemvalues = str_replace('|', "\n", stripslashes_safe($item->presentation));
if($itemvalues = explode(FEEDBACK_DROPDOWN_LINE_SEP, stripslashes_safe($item->presentation), FEEDBACK_DROPDOWNRATED_MAXCOUNT)){
echo '<table>';
echo '<tr>';
echo '<td><b>'.get_string('line_values', 'feedback').'</b></td><td><b>'.get_string('line_labels', 'feedback').'</b></td>';
echo '</tr>';
for ($i = 0; $i < FEEDBACK_DROPDOWNRATED_MAXCOUNT; $i++) {
if(count($itemvalues) > $i) {
$value = explode(FEEDBACK_DROPDOWN_VALUE_SEP, $itemvalues[$i]);
if(count($value) <= 1) {
$value[0] = ''; $value[1] = '';
}
}else {
$value[0] = ''; $value[1] = '';
}
echo '<tr>';
echo '<td><input type="text" name="fr_val[]" size="4" maxlength="4" value="'.$value[0].'" /></td>';
echo '<td><input type="text" name="fr_label[]" size="40" maxlength="255" value="'.$value[1].'" /></td>';
echo '</tr>';
}
echo '</table>';
}
?>
</td>
</tr>
</table>
<?php
}
//liefert ein eindimensionales Array mit drei Werten(typ, name, XXX)
//XXX ist ein eindimensionales Array (Mittelwert der Werte der Antworten bei Typ dropdown_rated) Jedes Element ist eine Struktur (answertext, avg)
function get_analysed($item, $groupid = false, $courseid = false) {
$analysedItem = array();
$analysedItem[] = $item->typ;
$analysedItem[] = $item->name;
//die moeglichen Antworten extrahieren
$lines = null;
$lines = explode (FEEDBACK_DROPDOWN_LINE_SEP, stripslashes_safe($item->presentation));
if(!is_array($lines)) return null;
//die Werte holen
//$values = get_records('feedback_value', 'item', $item->id);
$values = feedback_get_group_values($item, $groupid, $courseid);
if(!$values) return null;
//schleife ueber den Werten und ueber die Antwortmoeglichkeiten
$analysedAnswer = array();
for($i = 1; $i <= sizeof($lines); $i++) {
$item_values = explode(FEEDBACK_DROPDOWN_VALUE_SEP, $lines[$i-1]);
$ans = null;
$ans->answertext = $item_values[1];
$avg = 0.0;
$anscount = 0;
foreach($values as $value) {
//ist die Antwort gleich dem index der Antworten + 1?
if ($value->value == $i) {
$avg += $item_values[0]; //erst alle Werte aufsummieren
$anscount++;
}
}
$ans->answercount = $anscount;
$ans->avg = doubleval($avg) / doubleval(sizeof($values));
$ans->value = $item_values[0];
$ans->quotient = $ans->answercount / sizeof($values);
$analysedAnswer[] = $ans;
}
$analysedItem[] = $analysedAnswer;
return $analysedItem;
}
function get_printval($item, $value) {
$printval = '';
if(!isset($value->value)) return $printval;
$presentation = explode (FEEDBACK_DROPDOWN_LINE_SEP, stripslashes_safe($item->presentation));
$index = 1;
foreach($presentation as $pres){
if($value->value == $index){
$dropdown_label = explode(FEEDBACK_DROPDOWN_VALUE_SEP, $pres);
$printval = $dropdown_label[1];
break;
}
$index++;
}
return $printval;
}
function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) {
$sep_dec = get_string('separator_decimal', 'feedback');
if(substr($sep_dec, 0, 2) == '[['){
$sep_dec = FEEDBACK_DECIMAL;
}
$sep_thous = get_string('separator_thousand', 'feedback');
if(substr($sep_thous, 0, 2) == '[['){
$sep_thous = FEEDBACK_THOUSAND;
}
$analysedItem = $this->get_analysed($item, $groupid, $courseid);
if($analysedItem) {
//echo '<table>';
$itemnr++;
echo '<tr><th colspan="2" align="left">'. $itemnr . '.)&nbsp;' . stripslashes($analysedItem[1]) .'</th></tr>';
$analysedVals = $analysedItem[2];
$pixnr = 0;
$avg = 0.0;
foreach($analysedVals as $val) {
if( function_exists("bcmod")) {
$intvalue = bcmod($pixnr, 10);
}else {
$intvalue = 0;
}
$pix = "pics/$intvalue.gif";
$pixnr++;
$pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
$avg += $val->avg;
$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>';
}
$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 '</table>';
}
return $itemnr;
}
function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
$data = $analysed_item[2];
$worksheet->setFormat("<l><f><ro2><vo><c:green>");
//frage schreiben
$worksheet->write_string($rowOffset, 0, stripslashes($analysed_item[1]));
if(is_array($data)) {
$avg = 0.0;
for($i = 0; $i < sizeof($data); $i++) {
$aData = $data[$i];
$worksheet->setFormat("<l><f><ro2><vo><c:blue>");
$worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext).' ('.$aData->value.')');
$worksheet->setFormat("<l><vo>");
$worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount);
//$worksheet->setFormat("<l><f><vo>");
//$worksheet->write_number($rowOffset + 2, $i + 1, $aData->avg);
$avg += $aData->avg;
}
//mittelwert anzeigen
$worksheet->setFormat("<l><f><ro2><vo><c:red>");
$worksheet->write_string($rowOffset, sizeof($data) + 1, get_string('average', 'feedback'));
$worksheet->setFormat("<l><f><vo>");
$worksheet->write_number($rowOffset + 1, sizeof($data) + 1, $avg);
}
$rowOffset +=2 ;
return $rowOffset;
}
function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){
$align = get_string('thisdirection') == 'ltr' ? 'left' : 'right';
$lines = explode (FEEDBACK_DROPDOWN_LINE_SEP, stripslashes_safe($item->presentation));
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
if($highlightrequire AND $item->required AND intval($value) <= 0) {
$highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
}else {
$highlight = '';
}
?>
<td <?php echo $highlight;?> valign="top" align="<?php echo $align;?>"><?php echo format_text(stripslashes_safe($item->name) . $requiredmark, true, false, false);?></td>
<td valign="top" align="<?php echo $align;?>">
<?php
$index = 1;
$selected = '';
if($readonly){
foreach($lines as $line){
if($value == $index){
$dropdown_value = explode(FEEDBACK_DROPDOWN_VALUE_SEP, $line);
// print_simple_box_start($align);
print_box_start('generalbox boxalign'.$align);
echo text_to_html($dropdown_value[1], true, false, false);
// print_simple_box_end();
print_box_end();
break;
}
$index++;
}
} else {
echo '<select name="'. $item->typ . '_' . $item->id . '">';
echo '<option value="0">&nbsp;</option>';
foreach($lines as $line){
if($value == $index){
$selected = 'selected="selected"';
}else{
$selected = '';
}
$dropdown_value = explode(FEEDBACK_DROPDOWN_VALUE_SEP, $line);
if($edit) {
echo '<option value="'. $index.'" '. $selected.'>'. clean_text('('.$dropdown_value[0].') '.$dropdown_value[1]).'</option>';
}else {
echo '<option value="'. $index.'" '. $selected.'>'. clean_text($dropdown_value[1]).'</option>';
}
$index++;
}
echo '</select>';
/*
if($item->required == 1) {
echo '<input type="hidden" name="'.$item->typ . '_' . $item->id.'" value="1" />';
}
*/
}
?>
</td>
<?php
}
function check_value($value, $item) {
//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;
}
function create_value($data) {
$data = clean_param($data, PARAM_INT);
return $data;
}
function get_presentation($data) {
$valuelines = $data->fr_val;
$labellines = $data->fr_label;
$present = '';
if(!is_array($valuelines) AND !is_array($labellines)) {
return $present;
}
//if( trim($valuelines[0]) != ''){
$value = intval($valuelines[0]);
$label = $labellines[0];
$present .= $value.FEEDBACK_DROPDOWN_VALUE_SEP.$label;
//}
for($i = 1; $i < FEEDBACK_DROPDOWNRATED_MAXCOUNT; $i++) {
if( (trim($valuelines[$i]) == '') AND (trim($labellines[$i]) == ''))continue;
$value = intval($valuelines[$i]);
$label = $labellines[$i];
$present .= FEEDBACK_DROPDOWN_LINE_SEP.$value.FEEDBACK_DROPDOWN_VALUE_SEP.$label;
}
//$present = str_replace("\n", '|', trim($data->itemvalues));
return $present;
}
function get_hasvalue() {
return 1;
}
}
?>

View File

@ -0,0 +1,18 @@
<?php
require_once $CFG->libdir.'/formslib.php';
class feedback_label_form extends moodleform {
var $type = "label";
var $area;
function definition() {
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$mform->addElement('hidden', 'itemname', $this->type);
$this->area = $mform->addElement('htmleditor', 'presentation', '', array('rows'=>20));
}
}
?>

View File

@ -8,16 +8,17 @@ class feedback_item_label extends feedback_item_base {
}
function show_edit($item, $usehtmleditor = false) {
$item->presentation=isset($item->presentation)?$item->presentation:'';
print_string('label', 'feedback');
echo '<br />';
print_textarea($usehtmleditor, 20, 0, 0, 0, "presentation", $item->presentation);
echo '<input type="hidden" id="itemname" name="itemname" value="label" />';
if ($usehtmleditor) {
use_html_editor();
}
function show_edit($item) {
global $CFG;
require_once('label_form.php');
$item_form = new feedback_label_form();
$item->presentation = isset($item->presentation) ? $item->presentation : '';
$item_form->area->setValue($item->presentation);
return $item_form;
}
function print_item($item){
?>

View File

@ -0,0 +1,499 @@
<?php // $Id$
defined('FEEDBACK_INCLUDE_TEST') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
define('FEEDBACK_MULTICHOICE_TYPE_SEP', '>>>>>');
define('FEEDBACK_MULTICHOICE_LINE_SEP', '|');
define('FEEDBACK_MULTICHOICE_ADJUST_SEP', '<<<<<');
class feedback_item_multichoice extends feedback_item_base {
var $type = "multichoice";
function init() {
}
function show_edit($item) {
global $CFG;
require_once('multichoice_form.php');
$item_form = new feedback_multichoice_form();
$item->presentation = empty($item->presentation) ? '' : $item->presentation;
$item->name = empty($item->name) ? '' : $item->name;
$info = $this->get_info($item);
$item->required = isset($item->required) ? $item->required : 0;
if($item->required) {
$item_form->requiredcheck->setValue(true);
}
$item_form->itemname->setValue($item->name);
$item_form->selectadjust->setValue($info->horizontal);
$item_form->selecttype->setValue($info->subtype);
$itemvalues = str_replace(FEEDBACK_MULTICHOICE_LINE_SEP, "\n", stripslashes_safe($info->presentation));
$itemvalues = str_replace("\n\n", "\n", $itemvalues);
$item_form->values->setValue($itemvalues);
return $item_form;
}
//liefert ein eindimensionales Array mit drei Werten(typ, name, XXX)
//XXX ist ein eindimensionales Array (anzahl der Antworten bei Typ Radio) Jedes Element ist eine Struktur (answertext, answercount)
function get_analysed($item, $groupid = false, $courseid = false) {
$info = $this->get_info($item);
$analysedItem = array();
$analysedItem[] = $item->typ;
$analysedItem[] = $item->name;
//die moeglichen Antworten extrahieren
$answers = null;
// $presentation = '';
// @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info
$answers = explode (FEEDBACK_MULTICHOICE_LINE_SEP, stripslashes_safe($info->presentation));
if(!is_array($answers)) return null;
//die Werte holen
$values = feedback_get_group_values($item, $groupid, $courseid);
if(!$values) return null;
//schleife ueber den Werten und ueber die Antwortmoeglichkeiten
$analysedAnswer = array();
if($info->subtype == 'c') {
for($i = 1; $i <= sizeof($answers); $i++) {
$ans = null;
$ans->answertext = $answers[$i-1];
$ans->answercount = 0;
foreach($values as $value) {
//ist die Antwort gleich dem index der Antworten + 1?
$vallist = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value->value);
foreach($vallist as $val) {
if ($val == $i) {
$ans->answercount++;
}
}
}
$ans->quotient = $ans->answercount / sizeof($values);
$analysedAnswer[] = $ans;
}
}else {
for($i = 1; $i <= sizeof($answers); $i++) {
$ans = null;
$ans->answertext = $answers[$i-1];
$ans->answercount = 0;
foreach($values as $value) {
//ist die Antwort gleich dem index der Antworten + 1?
if ($value->value == $i) {
$ans->answercount++;
}
}
$ans->quotient = $ans->answercount / sizeof($values);
$analysedAnswer[] = $ans;
}
}
$analysedItem[] = $analysedAnswer;
return $analysedItem;
}
function get_printval($item, $value) {
$info = $this->get_info($item);
$printval = '';
if(!isset($value->value)) return $printval;
// @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info
$presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, stripslashes_safe($info->presentation));
if($info->subtype == 'c') {
$vallist = array_values(explode (FEEDBACK_MULTICHOICE_LINE_SEP, $value->value));
for($i = 0; $i < sizeof($vallist); $i++) {
for($k = 0; $k < sizeof($presentation); $k++) {
if($vallist[$i] == ($k + 1)) {//Die Werte beginnen bei 1, das Array aber mit 0
$printval .= trim($presentation[$k]) . chr(10);
break;
}
}
}
}else {
$index = 1;
foreach($presentation as $pres){
if($value->value == $index){
$printval = $pres;
break;
}
$index++;
}
}
return $printval;
}
function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) {
$sep_dec = get_string('separator_decimal', 'feedback');
if(substr($sep_dec, 0, 2) == '[['){
$sep_dec = FEEDBACK_DECIMAL;
}
$sep_thous = get_string('separator_thousand', 'feedback');
if(substr($sep_thous, 0, 2) == '[['){
$sep_thous = FEEDBACK_THOUSAND;
}
$analysedItem = $this->get_analysed($item, $groupid, $courseid);
if($analysedItem) {
$itemnr++;
$itemname = stripslashes($analysedItem[1]);
echo '<tr><th colspan="2" align="left">'. $itemnr . '.)&nbsp;' . $itemname .'</th></tr>';
$analysedVals = $analysedItem[2];
$pixnr = 0;
foreach($analysedVals as $val) {
if( function_exists("bcmod")) {
$intvalue = bcmod($pixnr, 10);
}else {
$intvalue = 0;
}
$pix = "pics/$intvalue.gif";
$pixnr++;
$pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
$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>';
}
}
return $itemnr;
}
function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
$data = $analysed_item[2];
$worksheet->setFormat("<l><f><ro2><vo><c:green>");
//frage schreiben
$worksheet->write_string($rowOffset, 0, stripslashes($analysed_item[1]));
if(is_array($data)) {
for($i = 0; $i < sizeof($data); $i++) {
$aData = $data[$i];
$worksheet->setFormat("<l><f><ro2><vo><c:blue>");
$worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext));
$worksheet->setFormat("<l><vo>");
$worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount);
$worksheet->setFormat("<l><f><vo><pr>");
$worksheet->write_number($rowOffset + 2, $i + 1, $aData->quotient);
}
}
$rowOffset +=3 ;
return $rowOffset;
}
function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){
$info = $this->get_info($item);
$align = get_string('thisdirection') == 'ltr' ? 'left' : 'right';
$presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, stripslashes_safe($info->presentation));
//test if required and no value is set so we have to mark this item
//we have to differ check and the other subtypes
if($info->subtype == 'c') {
if (is_array($value)) {
$values = $value;
}else {
$values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value);
}
if($highlightrequire AND $item->required AND $values[0] == '') {
$highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
}else {
$highlight = '';
}
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
echo '<td '.$highlight.' valign="top" align="'.$align.'">'.format_text(stripslashes_safe($item->name).$requiredmark, true, false, false).'</td>';
echo '<td valign="top" align="'.$align.'">';
}else {
if($highlightrequire AND $item->required AND intval($value) <= 0) {
$highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
}else {
$highlight = '';
}
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
?>
<td <?php echo $highlight;?> valign="top" align="<?php echo $align;?>"><?php echo format_text(stripslashes_safe($item->name) . $requiredmark, true, false, false);?></td>
<td valign="top" align="<?php echo $align;?>">
<?php
}
$index = 1;
$checked = '';
if($readonly){
if($info->subtype == 'c') {
print_box_start('generalbox boxalign'.$align);
foreach($presentation as $pres){
foreach($values as $val) {
if($val == $index){
echo text_to_html($pres . '<br />', true, false, false);
break;
}
}
$index++;
}
// print_simple_box_end();
print_box_end();
}else {
foreach($presentation as $pres){
if($value == $index){
// print_simple_box_start($align);
print_box_start('generalbox boxalign'.$align);
echo text_to_html($pres, true, false, false);
// print_simple_box_end();
print_box_end();
break;
}
$index++;
}
}
} else {
//print the "not_selected" item on radiobuttons
if($info->subtype == 'r') {
?>
<table><tr>
<td valign="top" align="<?php echo $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"';?> />
</td>
<td align="<?php echo $align;?>">
<label for="<?php echo $item->typ . '_' . $item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?>&nbsp;</label>
</td>
</tr></table>
<?php
}
if($info->subtype != 'd') {
if($info->horizontal) {
echo '<table><tr>';
}
}
switch($info->subtype) {
case 'r':
$this->print_item_radio($presentation, $item, $value, $info, $align);
break;
case 'c':
$this->print_item_check($presentation, $item, $value, $info, $align);
break;
case 'd':
$this->print_item_dropdown($presentation, $item, $value, $info, $align);
break;
}
if($info->subtype != 'd') {
if($info->horizontal) {
echo '</tr></table>';
}
}
/*
if($item->required == 1) {
echo '<input type="hidden" name="'.$item->typ . '_' . $item->id.'" value="1" />';
}
*/
}
?>
</td>
<?php
}
function check_value($value, $item) {
$info = $this->get_info($item);
if($info->subtype == 'c') {
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;
}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;
}
function create_value($data) {
$vallist = $data;
return trim($this->item_arrayToString($vallist));
}
function get_presentation($data) {
$present = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($data->itemvalues));
if(!isset($data->subtype)) {
$subtype = 'r';
}else {
$subtype = substr($data->subtype, 0, 1);
}
if(isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') {
$present .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1';
}
return $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$present;
}
function get_hasvalue() {
return 1;
}
function get_info($item) {
$presentation = empty($item->presentation) ? '' : $item->presentation;
$info = new object();
//check the subtype of the multichoice
//it can be check(c), radio(r) or dropdown(d)
$info->subtype = '';
$info->presentation = '';
$info->horizontal = false;
@list($info->subtype, $info->presentation) = explode(FEEDBACK_MULTICHOICE_TYPE_SEP, $item->presentation);
if(!isset($info->subtype)) {
$info->subtype = 'r';
}
if($info->subtype != 'd') {
@list($info->presentation, $info->horizontal) = explode(FEEDBACK_MULTICHOICE_ADJUST_SEP, $info->presentation);
if(isset($info->horizontal) AND $info->horizontal == 1) {
$info->horizontal = true;
}else {
$info->horizontal = false;
}
}
return $info;
}
function item_arrayToString($value) {
if(!is_array($value)) {
return $value;
}
$retval = '';
$arrvals = array_values($value);
$arrvals = clean_param($arrvals, PARAM_INT); //prevent sql-injection
$retval = $arrvals[0];
for($i = 1; $i < sizeof($arrvals) - 1; $i++) {
$retval .= FEEDBACK_MULTICHOICE_LINE_SEP.$arrvals[$i];
}
return $retval;
}
function print_item_radio($presentation, $item, $value, $info, $align) {
$index = 1;
$checked = '';
foreach($presentation as $radio){
if($value == $index){
$checked = 'checked="checked"';
}else{
$checked = '';
}
$inputname = $item->typ . '_' . $item->id;
$inputid = $inputname.'_'.$index;
if($info->horizontal) {
?>
<td valign="top" align="<?php echo $align;?>"><input type="radio"
name="<?php echo $inputname;?>"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td>
<td align="<?php echo $align;?>">
<label for="<?php echo $inputid;?>"><?php echo text_to_html($radio, true, false, false);?>&nbsp;</label>
</td>
<?php
}else {
?>
<table><tr>
<td valign="top" align="<?php echo $align;?>"><input type="radio"
name="<?php echo $inputname;?>"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td><td align="<?php echo $align;?>"><label for="<?php echo $inputid;?>"><?php echo text_to_html($radio, true, false, false);?>&nbsp;</label>
</td></tr></table>
<?php
}
$index++;
}
}
function print_item_check($presentation, $item, $value, $info, $align) {
if (is_array($value)) {
$values = $value;
}else {
$values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value);
}
$index = 1;
$checked = '';
foreach($presentation as $check){
foreach($values as $val) {
if($val == $index){
$checked = 'checked="checked"';
break;
}else{
$checked = '';
}
}
$inputname = $item->typ. '_' . $item->id;
$inputid = $item->typ. '_' . $item->id.'_'.$index;
if($info->horizontal) {
?>
<td valign="top" align="<?php echo $align;?>"><input type="checkbox"
name="<?php echo $inputname;?>[]"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td><td align="<?php echo $align;?>"><label for="<?php echo $inputid;?>"><?php echo text_to_html($check, true, false, false);?>&nbsp;</label>
</td>
<?php
}else {
?>
<table><tr>
<td valign="top" align="<?php echo $align;?>"><input type="checkbox"
name="<?php echo $inputname;?>[]"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td><td align="<?php echo $align;?>"><label for="<?php echo $inputid;?>"><?php echo text_to_html($check, true, false, false);?>&nbsp;</label>
</td></tr></table>
<?php
}
$index++;
}
}
function print_item_dropdown($presentation, $item, $value, $info, $align) {
?>
<select name="<?php echo $item->typ .'_' . $item->id;?>" size="1">
<option value="0">&nbsp;</option>
<?php
$index = 1;
$checked = '';
foreach($presentation as $dropdown){
if($value == $index){
$selected = 'selected="selected"';
}else{
$selected = '';
}
?>
<option value="<?php echo $index;?>" <?php echo $selected;?>><?php echo text_to_html($dropdown, true, false, false);?></option>
<?php
$index++;
}
?>
</select>
<?php
}
}
?>

View File

@ -0,0 +1,40 @@
<?php
require_once $CFG->libdir.'/formslib.php';
class feedback_multichoice_form extends moodleform {
var $type = "multichoice";
var $requiredcheck;
var $itemname;
var $selectadjust;
var $selecttype;
var $values;
function definition() {
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
$this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"'));
$this->selectadjust = $mform->addElement('select',
'horizontal',
get_string('adjustment', 'feedback').'&nbsp;',
array(0 => get_string('vertical', 'feedback'), 1 => get_string('horizontal', 'feedback')));
$this->selecttype = $mform->addElement('select',
'subtype',
get_string('multichoicetype', 'feedback').'&nbsp;',
array('r'=>get_string('radio', 'feedback'),
'c'=>get_string('check', 'feedback'),
'd'=>get_string('dropdown', 'feedback')));
$mform->addElement('static', 'hint', get_string('multichoice_values', 'feedback'), get_string('use_one_line_for_each_value', 'feedback'));
$this->values = $mform->addElement('textarea', 'itemvalues', '', 'wrap="virtual" rows="10" cols="30"');
}
}
?>

View File

@ -0,0 +1,419 @@
<?php // $Id$
defined('FEEDBACK_INCLUDE_TEST') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
define('FEEDBACK_RADIORATED_ADJUST_SEP', '<<<<<');
define('FEEDBACK_MULTICHOICERATED_MAXCOUNT', 10); //count of possible items
define('FEEDBACK_MULTICHOICERATED_VALUE_SEP', '####');
define('FEEDBACK_MULTICHOICERATED_VALUE_SEP2', '/');
define('FEEDBACK_MULTICHOICERATED_TYPE_SEP', '>>>>>');
define('FEEDBACK_MULTICHOICERATED_LINE_SEP', '|');
define('FEEDBACK_MULTICHOICERATED_ADJUST_SEP', '<<<<<');
class feedback_item_multichoicerated extends feedback_item_base {
var $type = "multichoicerated";
function init() {
}
function show_edit($item) {
global $CFG;
require_once('multichoicerated_form.php');
$item_form = new feedback_multichoicerated_form();
$item->presentation = empty($item->presentation) ? '' : $item->presentation;
$item->name = empty($item->name) ? '' : $item->name;
$info = $this->get_info($item);
$item->required = isset($item->required) ? $item->required : 0;
if($item->required) {
$item_form->requiredcheck->setValue(true);
}
$item_form->itemname->setValue($item->name);
$item_form->selectadjust->setValue($info->horizontal);
$item_form->selecttype->setValue($info->subtype);
$itemvalues = $this->prepare_presentation_values_print($info->presentation, FEEDBACK_MULTICHOICERATED_VALUE_SEP, FEEDBACK_MULTICHOICERATED_VALUE_SEP2);
$item_form->values->setValue($itemvalues);
return $item_form;
}
//liefert ein eindimensionales Array mit drei Werten(typ, name, XXX)
//XXX ist ein eindimensionales Array (Mittelwert der Werte der Antworten bei Typ Radio_rated) Jedes Element ist eine Struktur (answertext, avg)
function get_analysed($item, $groupid = false, $courseid = false) {
$analysedItem = array();
$analysedItem[] = $item->typ;
$analysedItem[] = $item->name;
//die moeglichen Antworten extrahieren
$info = $this->get_info($item);
$lines = null;
$lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, stripslashes_safe($info->presentation));
if(!is_array($lines)) return null;
//die Werte holen
$values = feedback_get_group_values($item, $groupid, $courseid);
if(!$values) return null;
//schleife ueber den Werten und ueber die Antwortmoeglichkeiten
$analysedAnswer = array();
for($i = 1; $i <= sizeof($lines); $i++) {
$item_values = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $lines[$i-1]);
$ans = null;
$ans->answertext = $item_values[1];
$avg = 0.0;
$anscount = 0;
foreach($values as $value) {
//ist die Antwort gleich dem index der Antworten + 1?
if ($value->value == $i) {
$avg += $item_values[0]; //erst alle Werte aufsummieren
$anscount++;
}
}
$ans->answercount = $anscount;
$ans->avg = doubleval($avg) / doubleval(sizeof($values));
$ans->value = $item_values[0];
$ans->quotient = $ans->answercount / sizeof($values);
$analysedAnswer[] = $ans;
}
$analysedItem[] = $analysedAnswer;
return $analysedItem;
}
function get_printval($item, $value) {
$printval = '';
if(!isset($value->value)) return $printval;
$info = $this->get_info($item);
$presentation = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, stripslashes_safe($info->presentation));
$index = 1;
foreach($presentation as $pres){
if($value->value == $index){
$item_label = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $pres);
$printval = $item_label[1];
break;
}
$index++;
}
return $printval;
}
function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) {
$sep_dec = get_string('separator_decimal', 'feedback');
if(substr($sep_dec, 0, 2) == '[['){
$sep_dec = FEEDBACK_DECIMAL;
}
$sep_thous = get_string('separator_thousand', 'feedback');
if(substr($sep_thous, 0, 2) == '[['){
$sep_thous = FEEDBACK_THOUSAND;
}
$analysedItem = $this->get_analysed($item, $groupid, $courseid);
if($analysedItem) {
//echo '<table>';
$itemnr++;
echo '<tr><th colspan="2" align="left">'. $itemnr . '.)&nbsp;' . stripslashes($analysedItem[1]) .'</th></tr>';
$analysedVals = $analysedItem[2];
$pixnr = 0;
$avg = 0.0;
foreach($analysedVals as $val) {
if( function_exists("bcmod")) {
$intvalue = bcmod($pixnr, 10);
}else {
$intvalue = 0;
}
$pix = "pics/$intvalue.gif";
$pixnr++;
$pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
$avg += $val->avg;
$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>';
}
$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 '</table>';
}
return $itemnr;
}
function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
$data = $analysed_item[2];
$worksheet->setFormat("<l><f><ro2><vo><c:green>");
//frage schreiben
$worksheet->write_string($rowOffset, 0, stripslashes($analysed_item[1]));
if(is_array($data)) {
$avg = 0.0;
for($i = 0; $i < sizeof($data); $i++) {
$aData = $data[$i];
$worksheet->setFormat("<l><f><ro2><vo><c:blue>");
$worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext).' ('.$aData->value.')');
$worksheet->setFormat("<l><vo>");
$worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount);
//$worksheet->setFormat("<l><f><vo>");
//$worksheet->write_number($rowOffset + 2, $i + 1, $aData->avg);
$avg += $aData->avg;
}
//mittelwert anzeigen
$worksheet->setFormat("<l><f><ro2><vo><c:red>");
$worksheet->write_string($rowOffset, sizeof($data) + 1, get_string('average', 'feedback'));
$worksheet->setFormat("<l><f><vo>");
$worksheet->write_number($rowOffset + 1, sizeof($data) + 1, $avg);
}
$rowOffset +=2 ;
return $rowOffset;
}
function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){
$align = get_string('thisdirection') == 'ltr' ? 'left' : 'right';
$info = $this->get_info($item);
$lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, stripslashes_safe($info->presentation));
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
if($highlightrequire AND $item->required AND intval($value) <= 0) {
$highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
}else {
$highlight = '';
}
?>
<td <?php echo $highlight;?> valign="top" align="<?php echo $align;?>"><?php echo format_text(stripslashes_safe($item->name) . $requiredmark, true, false, false);?></td>
<td valign="top" align="<?php echo $align;?>">
<?php
$index = 1;
$checked = '';
if($readonly){
foreach($lines as $line){
if($value == $index){
$item_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
// print_simple_box_start('left');
print_box_start('generalbox boxalign'.$align);
echo text_to_html($item_value[1], true, false, false);
// print_simple_box_end();
print_box_end();
break;
}
$index++;
}
} else {
switch($info->subtype) {
case 'r':
$this->print_item_radio($item, $value, $info, $align, $edit, $lines);
break;
case 'd':
$this->print_item_dropdown($item, $value, $info, $align, $edit, $lines);
break;
}
}
?>
</td>
<?php
}
function check_value($value, $item) {
if((!isset($value) OR $value == '' OR $value == 0) AND $item->required != 1) return true;
if(intval($value) > 0)return true;
return false;
}
function create_value($data) {
$data = clean_param($data, PARAM_INT);
return $data;
}
function get_presentation($data) {
// $present = str_replace("\n", FEEDBACK_MULTICHOICERATED_LINE_SEP, trim($data->itemvalues));
$present = $this->prepare_presentation_values_save(trim($data->itemvalues), FEEDBACK_MULTICHOICERATED_VALUE_SEP2, FEEDBACK_MULTICHOICERATED_VALUE_SEP);
// $present = str_replace("\n", FEEDBACK_MULTICHOICERATED_LINE_SEP, trim($data->itemvalues));
if(!isset($data->subtype)) {
$subtype = 'r';
}else {
$subtype = substr($data->subtype, 0, 1);
}
if(isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') {
$present .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'1';
}
return $subtype.FEEDBACK_MULTICHOICERATED_TYPE_SEP.$present;
}
function get_hasvalue() {
return 1;
}
function get_info($item) {
$presentation = empty($item->presentation) ? '' : $item->presentation;
$info = new object();
//check the subtype of the multichoice
//it can be check(c), radio(r) or dropdown(d)
$info->subtype = '';
$info->presentation = '';
$info->horizontal = false;
@list($info->subtype, $info->presentation) = explode(FEEDBACK_MULTICHOICE_TYPE_SEP, $item->presentation);
if(!isset($info->subtype)) {
$info->subtype = 'r';
}
if($info->subtype != 'd') {
@list($info->presentation, $info->horizontal) = explode(FEEDBACK_MULTICHOICE_ADJUST_SEP, $info->presentation);
if(isset($info->horizontal) AND $info->horizontal == 1) {
$info->horizontal = true;
}else {
$info->horizontal = false;
}
}
return $info;
}
function print_item_radio($item, $value, $info, $align, $edit, $lines) {
$index = 1;
$checked = '';
?>
<table><tr>
<td valign="top" align="<?php echo $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"';?> />
</td>
<td align="<?php echo $align;?>">
<label for="<?php echo $item->typ.'_'.$item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?>&nbsp;</label>
</td>
</tr></table>
<?php
if($info->horizontal) {
echo '<table><tr>';
}
foreach($lines as $line){
if($value == $index){
$checked = 'checked="checked"';
}else{
$checked = '';
}
$radio_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
$inputname = $item->typ . '_' . $item->id;
$inputid = $inputname.'_'.$index;
if($info->horizontal) {
?>
<td valign="top" align="<?php echo $align;?>"><input type="radio"
name="<?php echo $inputname;?>"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td><td align="<?php echo $align;?>"><label for="<?php echo $inputid;?>"><?php
if($edit) {
echo text_to_html('('.$radio_value[0].') '.$radio_value[1], true, false, false);
}else {
echo text_to_html($radio_value[1], true, false, false);
}
?>&nbsp;</label>
</td>
<?php
}else {
?>
<table><tr>
<td valign="top" align="<?php echo $align;?>"><input type="radio"
name="<?php echo $inputname;?>"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td><td align="<?php echo $align;?>"><label for="<?php echo $inputid;?>"><?php
if($edit) {
echo text_to_html('('.$radio_value[0].') '.$radio_value[1], true, false, false);
}else {
echo text_to_html($radio_value[1], true, false, false);
}
?>&nbsp;</label>
</td></tr></table>
<?php
}
$index++;
}
if($info->horizontal) {
echo '</tr></table>';
}
}
function print_item_dropdown($item, $value, $info, $align, $edit, $lines) {
echo '<select name="'. $item->typ . '_' . $item->id . '">';
echo '<option value="0">&nbsp;</option>';
$index = 1;
$checked = '';
foreach($lines as $line){
if($value == $index){
$selected = 'selected="selected"';
}else{
$selected = '';
}
$dropdown_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
if($edit) {
echo '<option value="'. $index.'" '. $selected.'>'. clean_text('('.$dropdown_value[0].') '.$dropdown_value[1]).'</option>';
}else {
echo '<option value="'. $index.'" '. $selected.'>'. clean_text($dropdown_value[1]).'</option>';
}
$index++;
}
echo '</select>';
}
function prepare_presentation_values_print($valuestring, $valuesep1, $valuesep2) {
$lines = explode(FEEDBACK_MULTICHOICERATED_LINE_SEP, $valuestring);
$newlines = array();
foreach($lines as $line) {
$value = '';
$text = '';
if(strpos($line, $valuesep1) === false) {
$value = 0;
$text = $line;
}else {
@list($value, $text) = explode($valuesep1, $line, 2);
}
$value = intval($value);
$newlines[] = $value.$valuesep2.$text;
}
$newlines = implode("\n", $newlines);
return $newlines;
}
function prepare_presentation_values_save($valuestring, $valuesep1, $valuesep2) {
$lines = explode("\n", $valuestring);
$newlines = array();
foreach($lines as $line) {
$value = '';
$text = '';
if(strpos($line, $valuesep1) === false) {
$value = 0;
$text = $line;
}else {
@list($value, $text) = explode($valuesep1, $line, 2);
}
$value = intval($value);
$newlines[] = $value.$valuesep2.$text;
}
$newlines = implode(FEEDBACK_MULTICHOICERATED_LINE_SEP, $newlines);
return $newlines;
}
}
?>

View File

@ -0,0 +1,39 @@
<?php
require_once $CFG->libdir.'/formslib.php';
class feedback_multichoicerated_form extends moodleform {
var $type = "multichoicerated";
var $requiredcheck;
var $itemname;
var $selectadjust;
var $selecttype;
var $values;
function definition() {
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
$this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"'));
$this->selectadjust = $mform->addElement('select',
'horizontal',
get_string('adjustment', 'feedback').'&nbsp;',
array(0 => get_string('vertical', 'feedback'), 1 => get_string('horizontal', 'feedback')));
$this->selecttype = $mform->addElement('select',
'subtype',
get_string('multichoicetype', 'feedback').'&nbsp;',
array('r'=>get_string('radio', 'feedback'),
'd'=>get_string('dropdown', 'feedback')));
$mform->addElement('static', 'hint', get_string('multichoice_values', 'feedback'), get_string('use_one_line_for_each_value', 'feedback'));
$this->values = $mform->addElement('textarea', 'itemvalues', '', 'wrap="virtual" rows="10" cols="30"');
}
}
?>

View File

@ -8,44 +8,32 @@ class feedback_item_numeric extends feedback_item_base {
}
function show_edit($item, $usehtmleditor = false) {
function show_edit($item) {
global $CFG;
require_once('numeric_form.php');
$item_form = new feedback_numeric_form();
$item->presentation=empty($item->presentation)?'':$item->presentation;
$item->presentation = empty($item->presentation) ? '' : $item->presentation;
$item->name = empty($item->name) ? '' : $item->name;
$item->required = isset($item->required) ? $item->required : 0;
if($item->required) {
$item_form->requiredcheck->setValue(true);
}
?>
<table>
<tr>
<th colspan="2"><?php print_string('numeric', 'feedback');?>
&nbsp;(<input type="checkbox" name="required" value="1" <?php
$item->required=isset($item->required)?$item->required:0;
echo ($item->required == 1?'checked="checked"':'');
?> />&nbsp;<?php print_string('required', 'feedback');?>)
</th>
</tr>
<tr>
<td><?php print_string('item_name', 'feedback');?></td>
<td><input type="text" id="itemname" name="itemname" size="40" maxlength="255" value="<?php echo isset($item->name)?htmlspecialchars(stripslashes_safe($item->name)):'';?>" /></td>
</tr>
<tr>
<?php
//Dropdown-Items fuer die Textfeldbreite
$range_from_to = explode('|',$item->presentation);
$range_from = isset($range_from_to[0]) ? intval($range_from_to[0]) : 0;
$range_to = isset($range_from_to[1]) ? intval($range_from_to[1]) : 0;
?>
<td><?php print_string('numeric_range_from', 'feedback');?></td>
<td>
<input type="text" name="numericrangefrom" value="<?php echo $range_from;?>" />
</td>
</tr>
<tr>
<td><?php print_string('numeric_range_to', 'feedback');?></td>
<td>
<input type="text" name="numericrangeto" value="<?php echo $range_to;?>" />
</td>
</tr>
</table>
<?php
$item_form->itemname->setValue($item->name);
$range_from_to = explode('|',$item->presentation);
$range_from = isset($range_from_to[0]) ? intval($range_from_to[0]) : 0;
$range_to = isset($range_from_to[1]) ? intval($range_from_to[1]) : 0;
$item_form->selectfrom->setValue($range_from);
$item_form->selectto->setValue($range_to);
return $item_form;
}
//liefert eine Struktur ->name, ->data = array(mit Antworten)

View File

@ -0,0 +1,26 @@
<?php
require_once $CFG->libdir.'/formslib.php';
class feedback_numeric_form extends moodleform {
var $type = "numeric";
var $requiredcheck;
var $itemname;
var $selectfrom;
var $selectto;
function definition() {
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
$this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"'));
$this->selectfrom = $mform->addElement('text', 'numericrangefrom', get_string('numeric_range_from', 'feedback'), array('size="10"','maxlength="10"'));
$this->selectto = $mform->addElement('text', 'numericrangeto', get_string('numeric_range_to', 'feedback'), array('size="10"','maxlength="10"'));
}
}
?>

View File

@ -1,307 +0,0 @@
<?php // $Id$
defined('FEEDBACK_INCLUDE_TEST') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
define('FEEDBACK_RADIO_LINE_SEP', '|');
define('FEEDBACK_RADIO_ADJUST_SEP', '<<<<<');
class feedback_item_radio extends feedback_item_base {
var $type = "radio";
function init() {
}
function show_edit($item, $usehtmleditor = false) {
$item->presentation = empty($item->presentation) ? '' : $item->presentation;
//check, whether the buttons are vertical or horizontal
$presentation = $horizontal = '';
@list($presentation, $horizontal) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation);
if(isset($horizontal) AND $horizontal == 1) {
$horizontal = true;
}else {
$horizontal = false;
}
?>
<table>
<tr>
<th colspan="2"><?php print_string('radio', 'feedback');?>
&nbsp;(<input type="checkbox" name="required" value="1" <?php
$item->required=isset($item->required)?$item->required:0;
echo ($item->required == 1?'checked="checked"':'');
?> />&nbsp;<?php print_string('required', 'feedback');?>)
</th>
</tr>
<tr>
<td colspan="2">
<?php print_string('adjustment', 'feedback');?>:
&nbsp;<?php print_string('vertical', 'feedback');?><input type="radio" name="horizontal" value="0" <?php echo $horizontal ? '' : 'checked="checked"';?> />
&nbsp;<?php print_string('horizontal', 'feedback');?><input type="radio" name="horizontal" value="1" <?php echo $horizontal ? 'checked="checked"' : '';?> />
</td>
</tr>
<tr>
<td><?php print_string('item_name', 'feedback');?></td>
<td><input type="text" id="itemname" name="itemname" size="40" maxlength="255" value="<?php echo isset($item->name)?htmlspecialchars(stripslashes_safe($item->name)):'';?>" /></td>
</tr>
<tr>
<td>
<?php print_string('radio_values', 'feedback');?>
<?php print_string('use_one_line_for_each_value', 'feedback');?>
</td>
<td>
<?php
$itemvalues = str_replace(FEEDBACK_RADIO_LINE_SEP, "\n", stripslashes_safe($presentation));
?>
<textarea name="itemvalues" cols="30" rows="5"><?php echo $itemvalues;?></textarea>
</td>
</tr>
</table>
<?php
}
//liefert ein eindimensionales Array mit drei Werten(typ, name, XXX)
//XXX ist ein eindimensionales Array (anzahl der Antworten bei Typ Radio) Jedes Element ist eine Struktur (answertext, answercount)
function get_analysed($item, $groupid = false, $courseid = false) {
//fuer den Anfang erstmal nur die Radiobuttons
$analysedItem = array();
$analysedItem[] = $item->typ;
$analysedItem[] = $item->name;
//die moeglichen Antworten extrahieren
$answers = null;
$presentation = '';
@list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info
$answers = explode (FEEDBACK_RADIO_LINE_SEP, stripslashes_safe($presentation));
if(!is_array($answers)) return null;
//die Werte holen
//$values = get_records('feedback_value', 'item', $item->id);
$values = feedback_get_group_values($item, $groupid, $courseid);
if(!$values) return null;
//schleife ueber den Werten und ueber die Antwortmoeglichkeiten
$analysedAnswer = array();
for($i = 1; $i <= sizeof($answers); $i++) {
$ans = null;
$ans->answertext = $answers[$i-1];
$ans->answercount = 0;
foreach($values as $value) {
//ist die Antwort gleich dem index der Antworten + 1?
if ($value->value == $i) {
$ans->answercount++;
}
}
$ans->quotient = $ans->answercount / sizeof($values);
$analysedAnswer[] = $ans;
}
$analysedItem[] = $analysedAnswer;
return $analysedItem;
}
function get_printval($item, $value) {
$printval = '';
if(!isset($value->value)) return $printval;
@list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info
$presentation = explode (FEEDBACK_RADIO_LINE_SEP, stripslashes_safe($presentation));
$index = 1;
foreach($presentation as $pres){
if($value->value == $index){
$printval = $pres;
break;
}
$index++;
}
return $printval;
}
function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) {
$sep_dec = get_string('separator_decimal', 'feedback');
if(substr($sep_dec, 0, 2) == '[['){
$sep_dec = FEEDBACK_DECIMAL;
}
$sep_thous = get_string('separator_thousand', 'feedback');
if(substr($sep_thous, 0, 2) == '[['){
$sep_thous = FEEDBACK_THOUSAND;
}
$analysedItem = $this->get_analysed($item, $groupid, $courseid);
if($analysedItem) {
//echo '<table>';
$itemnr++;
echo '<tr><th colspan="2" align="left">'. $itemnr . '.)&nbsp;' . $analysedItem[1] .'</th></tr>';
$analysedVals = $analysedItem[2];
$pixnr = 0;
foreach($analysedVals as $val) {
if( function_exists("bcmod")) {
$intvalue = bcmod($pixnr, 10);
}else {
$intvalue = 0;
}
$pix = "pics/$intvalue.gif";
$pixnr++;
$pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
$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>';
}
//echo '</table>';
}
return $itemnr;
}
function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
$data = $analysed_item[2];
$worksheet->setFormat("<l><f><ro2><vo><c:green>");
//frage schreiben
$worksheet->write_string($rowOffset, 0, $analysed_item[1]);
if(is_array($data)) {
for($i = 0; $i < sizeof($data); $i++) {
$aData = $data[$i];
$worksheet->setFormat("<l><f><ro2><vo><c:blue>");
$worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext));
$worksheet->setFormat("<l><vo>");
$worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount);
$worksheet->setFormat("<l><f><vo><pr>");
$worksheet->write_number($rowOffset + 2, $i + 1, $aData->quotient);
}
}
$rowOffset +=3 ;
return $rowOffset;
}
function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){
$align = get_string('thisdirection') == 'ltr' ? 'left' : 'right';
//extract the adjustment-info
$presentation = $horizontal = '';
@list($presentation, $horizontal) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation);
if(isset($horizontal) AND $horizontal == 1) {
$horizontal = true;
}else {
$horizontal = false;
}
$presentation = explode (FEEDBACK_RADIO_LINE_SEP, stripslashes_safe($presentation));
if($highlightrequire AND $item->required AND intval($value) <= 0) {
$highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
}else {
$highlight = '';
}
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
?>
<td <?php echo $highlight;?> valign="top" align="<?php echo $align;?>"><?php echo format_text(stripslashes_safe($item->name) . $requiredmark, true, false, false);?></td>
<td valign="top" align="<?php echo $align;?>">
<?php
$index = 1;
$checked = '';
if($readonly){
foreach($presentation as $radio){
if($value == $index){
// print_simple_box_start($align);
print_box_start('generalbox boxalign'.$align);
echo text_to_html($radio, true, false, false);
// print_simple_box_end();
print_box_end();
break;
}
$index++;
}
} else {
?>
<table><tr>
<td valign="top" align="<?php echo $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"';?> />
</td>
<td align="<?php echo $align;?>">
<label for="<?php echo $item->typ . '_' . $item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?>&nbsp;</label>
</td>
</tr></table>
<?php
if($horizontal) {
echo '<table><tr>';
}
foreach($presentation as $radio){
if($value == $index){
$checked = 'checked="checked"';
}else{
$checked = '';
}
$inputname = $item->typ . '_' . $item->id;
$inputid = $inputname.'_'.$index;
if($horizontal) {
?>
<td valign="top" align="<?php echo $align;?>"><input type="radio"
name="<?php echo $inputname;?>"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td>
<td align="<?php echo $align;?>">
<label for="<?php echo $inputid;?>"><?php echo text_to_html($radio, true, false, false);?>&nbsp;</label>
</td>
<?php
}else {
?>
<table><tr>
<td valign="top" align="<?php echo $align;?>"><input type="radio"
name="<?php echo $inputname;?>"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td><td align="<?php echo $align;?>"><label for="<?php echo $inputid;?>"><?php echo text_to_html($radio, true, false, false);?>&nbsp;</label>
</td></tr></table>
<?php
}
$index++;
}
if($horizontal) {
echo '</tr></table>';
}
/*
if($item->required == 1) {
echo '<input type="hidden" name="'.$item->typ . '_' . $item->id.'" value="1" />';
}
*/
}
?>
</td>
<?php
}
function check_value($value, $item) {
//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;
}
function create_value($data) {
$data = clean_param($data, PARAM_INT);
return $data;
}
function get_presentation($data) {
$present = str_replace("\n", FEEDBACK_RADIO_LINE_SEP, trim($data->itemvalues));
if($data->horizontal == 1) {
$present .= FEEDBACK_RADIO_ADJUST_SEP.'1';
}
return $present;
}
function get_hasvalue() {
return 1;
}
}
?>

View File

@ -1,378 +0,0 @@
<?php // $Id$
defined('FEEDBACK_INCLUDE_TEST') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
define('FEEDBACK_RADIORATED_MAXCOUNT', 10); //count of possible items
define('FEEDBACK_RADIORATED_LINE_SEP', '|');
define('FEEDBACK_RADIORATED_VALUE_SEP', '####');
define('FEEDBACK_RADIORATED_ADJUST_SEP', '<<<<<');
class feedback_item_radiorated extends feedback_item_base {
var $type = "radiorated";
function init() {
}
function show_edit($item, $usehtmleditor = false) {
$item->presentation = empty($item->presentation) ? '' : $item->presentation;
//check, whether the buttons are vertical or horizontal
$presentation = $horizontal = '';
@list($presentation, $horizontal) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation);
if(isset($horizontal) AND $horizontal == 1) {
$horizontal = true;
}else {
$horizontal = false;
}
?>
<table>
<tr>
<th colspan="2"><?php print_string('radiorated', 'feedback');?>
&nbsp;(<input type="checkbox" name="required" value="1" <?php
$item->required=isset($item->required)?$item->required:0;
echo ($item->required == 1?'checked="checked"':'');
?> />&nbsp;<?php print_string('required', 'feedback');?>)
</th>
</tr>
<tr>
<td colspan="2">
<?php print_string('adjustment', 'feedback');?>:
&nbsp;<?php print_string('vertical', 'feedback');?><input type="radio" name="horizontal" value="0" <?php echo $horizontal ? '' : 'checked="checked"';?> />
&nbsp;<?php print_string('horizontal', 'feedback');?><input type="radio" name="horizontal" value="1" <?php echo $horizontal ? 'checked="checked"' : '';?> />
</td>
</tr>
<tr>
<td><?php print_string('item_name', 'feedback');?></td>
<td><input type="text" id="itemname" name="itemname" size="40" maxlength="255" value="<?php echo isset($item->name)?htmlspecialchars(stripslashes_safe($item->name)):'';?>" /></td>
</tr>
<tr>
<td>
<?php print_string('radio_values', 'feedback');?>
</td>
<td>
<?php
//$itemvalues = str_replace('|', "\n", stripslashes_safe($item->presentation));
if($itemvalues = explode(FEEDBACK_RADIORATED_LINE_SEP, stripslashes_safe($presentation), FEEDBACK_RADIORATED_MAXCOUNT)){
echo '<table>';
echo '<tr>';
echo '<td><b>'.get_string('line_values', 'feedback').'</b></td><td><b>'.get_string('line_labels', 'feedback').'</b></td>';
echo '</tr>';
for ($i = 0; $i < FEEDBACK_RADIORATED_MAXCOUNT; $i++) {
if(count($itemvalues) > $i) {
$value = explode(FEEDBACK_RADIORATED_VALUE_SEP, $itemvalues[$i]);
if(count($value) <= 1) {
$value[0] = ''; $value[1] = '';
}
}else {
$value[0] = ''; $value[1] = '';
}
echo '<tr>';
echo '<td><input type="text" name="fr_val[]" size="4" maxlength="4" value="'.$value[0].'" /></td>';
echo '<td><input type="text" name="fr_label[]" size="40" maxlength="255" value="'.$value[1].'" /></td>';
echo '</tr>';
}
echo '</table>';
}
?>
</td>
</tr>
</table>
<?php
}
//liefert ein eindimensionales Array mit drei Werten(typ, name, XXX)
//XXX ist ein eindimensionales Array (Mittelwert der Werte der Antworten bei Typ Radio_rated) Jedes Element ist eine Struktur (answertext, avg)
function get_analysed($item, $groupid = false, $courseid = false) {
$analysedItem = array();
$analysedItem[] = $item->typ;
$analysedItem[] = $item->name;
//die moeglichen Antworten extrahieren
$lines = null;
$presentation = '';
@list($presentation) = explode(FEEDBACK_RADIORATED_ADJUST_SEP, $item->presentation); //remove the adjustment-info
$lines = explode (FEEDBACK_RADIORATED_LINE_SEP, stripslashes_safe($presentation));
if(!is_array($lines)) return null;
//die Werte holen
//$values = get_records('feedback_value', 'item', $item->id);
$values = feedback_get_group_values($item, $groupid, $courseid);
if(!$values) return null;
//schleife ueber den Werten und ueber die Antwortmoeglichkeiten
$analysedAnswer = array();
for($i = 1; $i <= sizeof($lines); $i++) {
$item_values = explode(FEEDBACK_RADIORATED_VALUE_SEP, $lines[$i-1]);
$ans = null;
$ans->answertext = $item_values[1];
$avg = 0.0;
$anscount = 0;
foreach($values as $value) {
//ist die Antwort gleich dem index der Antworten + 1?
if ($value->value == $i) {
$avg += $item_values[0]; //erst alle Werte aufsummieren
$anscount++;
}
}
$ans->answercount = $anscount;
$ans->avg = doubleval($avg) / doubleval(sizeof($values));
$ans->value = $item_values[0];
$ans->quotient = $ans->answercount / sizeof($values);
$analysedAnswer[] = $ans;
}
$analysedItem[] = $analysedAnswer;
return $analysedItem;
}
function get_printval($item, $value) {
$printval = '';
if(!isset($value->value)) return $printval;
@list($presentation) = explode(FEEDBACK_RADIORATED_ADJUST_SEP, $item->presentation); //remove the adjustment-info
$presentation = explode (FEEDBACK_RADIORATED_LINE_SEP, stripslashes_safe($presentation));
$index = 1;
foreach($presentation as $pres){
if($value->value == $index){
$radio_label = explode(FEEDBACK_RADIORATED_VALUE_SEP, $pres);
$printval = $radio_label[1];
break;
}
$index++;
}
return $printval;
}
function print_analysed($item, $itemnr = 0, $groupid = false, $courseid = false) {
$sep_dec = get_string('separator_decimal', 'feedback');
if(substr($sep_dec, 0, 2) == '[['){
$sep_dec = FEEDBACK_DECIMAL;
}
$sep_thous = get_string('separator_thousand', 'feedback');
if(substr($sep_thous, 0, 2) == '[['){
$sep_thous = FEEDBACK_THOUSAND;
}
$analysedItem = $this->get_analysed($item, $groupid, $courseid);
if($analysedItem) {
//echo '<table>';
$itemnr++;
echo '<tr><th colspan="2" align="left">'. $itemnr . '.)&nbsp;' . $analysedItem[1] .'</th></tr>';
$analysedVals = $analysedItem[2];
$pixnr = 0;
$avg = 0.0;
foreach($analysedVals as $val) {
if( function_exists("bcmod")) {
$intvalue = bcmod($pixnr, 10);
}else {
$intvalue = 0;
}
$pix = "pics/$intvalue.gif";
$pixnr++;
$pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
$avg += $val->avg;
$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>';
}
$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 '</table>';
}
return $itemnr;
}
function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
$data = $analysed_item[2];
$worksheet->setFormat("<l><f><ro2><vo><c:green>");
//frage schreiben
$worksheet->write_string($rowOffset, 0, $analysed_item[1]);
if(is_array($data)) {
$avg = 0.0;
for($i = 0; $i < sizeof($data); $i++) {
$aData = $data[$i];
$worksheet->setFormat("<l><f><ro2><vo><c:blue>");
$worksheet->write_string($rowOffset, $i + 1, trim($aData->answertext).' ('.$aData->value.')');
$worksheet->setFormat("<l><vo>");
$worksheet->write_number($rowOffset + 1, $i + 1, $aData->answercount);
//$worksheet->setFormat("<l><f><vo>");
//$worksheet->write_number($rowOffset + 2, $i + 1, $aData->avg);
$avg += $aData->avg;
}
//mittelwert anzeigen
$worksheet->setFormat("<l><f><ro2><vo><c:red>");
$worksheet->write_string($rowOffset, sizeof($data) + 1, get_string('average', 'feedback'));
$worksheet->setFormat("<l><f><vo>");
$worksheet->write_number($rowOffset + 1, sizeof($data) + 1, $avg);
}
$rowOffset +=2 ;
return $rowOffset;
}
function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){
$align = get_string('thisdirection') == 'ltr' ? 'left' : 'right';
//extract the adjustment-info
$presentation = $horizontal = '';
@list($presentation, $horizontal) = explode(FEEDBACK_RADIORATED_ADJUST_SEP, $item->presentation);
if(isset($horizontal) AND $horizontal == 1) {
$horizontal = true;
}else {
$horizontal = false;
}
$lines = explode (FEEDBACK_RADIORATED_LINE_SEP, stripslashes_safe($presentation));
if($highlightrequire AND $item->required AND intval($value) <= 0) {
$highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
}else {
$highlight = '';
}
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
?>
<td <?php echo $highlight;?> valign="top" align="<?php echo $align;?>"><?php echo format_text(stripslashes_safe($item->name) . $requiredmark, true, false, false);?></td>
<td valign="top" align="<?php echo $align;?>">
<?php
$index = 1;
$checked = '';
if($readonly){
foreach($lines as $line){
if($value == $index){
$radio_value = explode(FEEDBACK_RADIORATED_VALUE_SEP, $line);
// print_simple_box_start('left');
print_box_start('generalbox boxalign'.$align);
echo text_to_html($radio_value[1], true, false, false);
// print_simple_box_end();
print_box_end();
break;
}
$index++;
}
} else {
?>
<table><tr>
<td valign="top" align="<?php echo $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"';?> />
</td>
<td align="<?php echo $align;?>">
<label for="<?php echo $item->typ.'_'.$item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?>&nbsp;</label>
</td>
</tr></table>
<?php
if($horizontal) {
echo '<table><tr>';
}
foreach($lines as $line){
if($value == $index){
$checked = 'checked="checked"';
}else{
$checked = '';
}
$radio_value = explode(FEEDBACK_RADIORATED_VALUE_SEP, $line);
$inputname = $item->typ . '_' . $item->id;
$inputid = $inputname.'_'.$index;
if($horizontal) {
?>
<td valign="top" align="<?php echo $align;?>"><input type="radio"
name="<?php echo $inputname;?>"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td><td align="<?php echo $align;?>"><label for="<?php echo $inputid;?>"><?php
if($edit) {
echo text_to_html('('.$radio_value[0].') '.$radio_value[1], true, false, false);
}else {
echo text_to_html($radio_value[1], true, false, false);
}
?>&nbsp;</label>
</td>
<?php
}else {
?>
<table><tr>
<td valign="top" align="<?php echo $align;?>"><input type="radio"
name="<?php echo $inputname;?>"
id="<?php echo $inputid;?>"
value="<?php echo $index;?>" <?php echo $checked;?> />
</td><td align="<?php echo $align;?>"><label for="<?php echo $inputid;?>"><?php
if($edit) {
echo text_to_html('('.$radio_value[0].') '.$radio_value[1], true, false, false);
}else {
echo text_to_html($radio_value[1], true, false, false);
}
?>&nbsp;</label>
</td></tr></table>
<?php
}
$index++;
}
if($horizontal) {
echo '</tr></table>';
}
/*
if($item->required == 1) {
echo '<input type="hidden" name="'.$item->typ . '_' . $item->id.'" value="1" />';
}
*/
}
?>
</td>
<?php
}
function check_value($value, $item) {
if((!isset($value) OR $value == '' OR $value == 0) AND $item->required != 1) return true;
if(intval($value) > 0)return true;
return false;
}
function create_value($data) {
$data = clean_param($data, PARAM_INT);
return $data;
}
function get_presentation($data) {
$valuelines = $data->fr_val;
$labellines = $data->fr_label;
$present = '';
if(!is_array($valuelines) AND !is_array($labellines)) {
return $present;
}
//if( trim($valuelines[0]) != ''){
$value = intval($valuelines[0]);
$label = $labellines[0];
$present .= $value.FEEDBACK_RADIORATED_VALUE_SEP.$label;
//}
for($i = 1; $i < FEEDBACK_RADIORATED_MAXCOUNT; $i++) {
if( (trim($valuelines[$i]) == '') AND (trim($labellines[$i]) == ''))continue;
$value = intval($valuelines[$i]);
$label = $labellines[$i];
$present .= FEEDBACK_RADIORATED_LINE_SEP.$value.FEEDBACK_RADIORATED_VALUE_SEP.$label;
}
//$present = str_replace("\n", '|', trim($data->itemvalues));
if($data->horizontal == 1) {
$present .= FEEDBACK_RADIORATED_ADJUST_SEP.'1';
}
return $present;
}
function get_hasvalue() {
return 1;
}
}
?>

View File

@ -8,49 +8,30 @@ class feedback_item_textarea extends feedback_item_base {
}
function show_edit($item, $usehtmleditor = false) {
function show_edit($item) {
global $CFG;
$item->presentation=empty($item->presentation)?'':$item->presentation;
require_once('textarea_form.php');
$item_form = new feedback_textarea_form();
?>
<table>
<tr>
<th colspan="2"><?php print_string('textarea', 'feedback');?>
&nbsp;(<input type="checkbox" name="required" value="1" <?php
$item->required=isset($item->required)?$item->required:0;
echo ($item->required == 1?'checked="checked"':'');
?> />&nbsp;<?php print_string('required', 'feedback');?>)
</th>
</tr>
<tr>
<td><?php print_string('item_name', 'feedback');?></td>
<td><input type="text" id="itemname" name="itemname" size="40" maxlength="255" value="<?php echo isset($item->name)?htmlspecialchars(stripslashes_safe($item->name)):'';?>" /></td>
</tr>
<tr>
<td><?php print_string('textarea_width', 'feedback');?></td>
<td>
<select name="itemwidth">
<?php
//Dropdown-Items fuer die Textareabreite
$widthAndHeight = explode('|',$item->presentation);
feedback_print_numeric_option_list(5, 80, $widthAndHeight[0]?$widthAndHeight[0]:30, 5);
?>
</select>
</td>
</tr>
<tr>
<td><?php print_string('textarea_height', 'feedback');?></td>
<td>
<select name="itemheight">
<?php
//Dropdown-Items fuer die Textareahoehe
feedback_print_numeric_option_list(5, 40, $widthAndHeight[1], 5);
?>
</select>
</td>
</tr>
</table>
<?php
$item->presentation = empty($item->presentation) ? '' : $item->presentation;
$item->name = empty($item->name) ? '' : $item->name;
$item->required = isset($item->required) ? $item->required : 0;
if($item->required) {
$item_form->requiredcheck->setValue(true);
}
$item_form->itemname->setValue($item->name);
$widthAndHeight = explode('|',$item->presentation);
$itemwidth = isset($widthAndHeight[0]) ? $widthAndHeight[0] : 30;
$itemheight = isset($widthAndHeight[1]) ? $widthAndHeight[1] : 5;
$item_form->selectwith->setValue($itemwidth);
$item_form->selectheight->setValue($itemheight);
return $item_form;
}
//liefert eine Struktur ->name, ->data = array(mit Antworten)

View File

@ -0,0 +1,32 @@
<?php
require_once $CFG->libdir.'/formslib.php';
class feedback_textarea_form extends moodleform {
var $type = "textarea";
var $requiredcheck;
var $itemname;
var $selectwith;
var $selectheight;
function definition() {
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
$this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"'));
$this->selectwith = $mform->addElement('select',
'itemwidth',
get_string('textarea_width', 'feedback').'&nbsp;',
array_slice(range(0,80),5,80,true));
$this->selectheight = $mform->addElement('select',
'itemheight',
get_string('textarea_height', 'feedback').'&nbsp;',
array_slice(range(0,40),5,40,true));
}
}
?>

View File

@ -8,50 +8,30 @@ class feedback_item_textfield extends feedback_item_base {
}
function show_edit($item, $usehtmleditor = false) {
function show_edit($item) {
global $CFG;
require_once('textfield_form.php');
$item_form = new feedback_textfield_form();
$item->presentation = empty($item->presentation) ? '' : $item->presentation;
$item->name = empty($item->name) ? '' : $item->name;
$item->required = isset($item->required) ? $item->required : 0;
if($item->required) {
$item_form->requiredcheck->setValue(true);
}
$item->presentation=empty($item->presentation)?'':$item->presentation;
$item_form->itemname->setValue($item->name);
?>
<table>
<tr>
<th colspan="2"><?php print_string('textfield', 'feedback');?>
&nbsp;(<input type="checkbox" name="required" value="1" <?php
$item->required=isset($item->required)?$item->required:0;
echo ($item->required == 1?'checked="checked"':'');
?> />&nbsp;<?php print_string('required', 'feedback');?>)
</th>
</tr>
<tr>
<td><?php print_string('item_name', 'feedback');?></td>
<td><input type="text" id="itemname" name="itemname" size="40" maxlength="255" value="<?php echo isset($item->name)?htmlspecialchars(stripslashes_safe($item->name)):'';?>" /></td>
</tr>
<tr>
<td><?php print_string('textfield_size', 'feedback');?></td>
<td>
<select name="itemsize">
<?php
//Dropdown-Items fuer die Textfeldbreite
$sizeAndLength = explode('|',$item->presentation);
$selected = '';
feedback_print_numeric_option_list(5, 50, ($sizeAndLength[0])?$sizeAndLength[0]:40, 5);
?>
</select>
</td>
</tr>
<tr>
<td><?php print_string('textfield_maxlength', 'feedback');?></td>
<td>
<select name="itemmaxlength">
<?php
//Dropdown-Items fuer die Textlaenge
feedback_print_numeric_option_list(5, 50, ($sizeAndLength[1])?$sizeAndLength[1]:40, 5);
?>
</select>
</td>
</tr>
</table>
<?php
$sizeAndLength = explode('|',$item->presentation);
$itemsize = isset($sizeAndLength[0]) ? $sizeAndLength[0] : 30;
$itemlength = isset($sizeAndLength[1]) ? $sizeAndLength[1] : 5;
$item_form->selectwith->setValue($itemsize);
$item_form->selectheight->setValue($itemlength);
return $item_form;
}
//liefert eine Struktur ->name, ->data = array(mit Antworten)

View File

@ -0,0 +1,32 @@
<?php
require_once $CFG->libdir.'/formslib.php';
class feedback_textfield_form extends moodleform {
var $type = "textfield";
var $requiredcheck;
var $itemname;
var $selectwith;
var $selectheight;
function definition() {
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$this->requiredcheck = $mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
$this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="40"','maxlength="255"'));
$this->selectwith = $mform->addElement('select',
'itemsize',
get_string('textfield_size', 'feedback').'&nbsp;',
array_slice(range(0,80),5,80,true));
$this->selectheight = $mform->addElement('select',
'itemmaxlength',
get_string('textfield_maxlength', 'feedback').'&nbsp;',
array_slice(range(0,40),5,40,true));
}
}
?>

View File

@ -26,12 +26,14 @@
//
//-----------------------------------------------------------
define('FEEDBACK_MULTICHOICERESTORE_TYPE_SEP', '>>>>>');
function feedback_restore_mods($mod,$restore) {
global $CFG;
$allValues = array();
$allTrackings = array();
// $allValues = array();
// $allTrackings = array();
$status = true;
$restore_userdata = restore_userdata_selected($restore,'feedback',$mod->id);
@ -119,6 +121,28 @@
if($version >= 1) {
$item->typ = backup_todb($item_info['#']['TYP']['0']['#']);
$item->hasvalue = backup_todb($item_info['#']['HASVALUE']['0']['#']);
switch($item->typ) {
case 'radio':
$item->typ = 'multichoice';
$item->presentation = 'r'.FEEDBACK_MULTICHOICERESTORE_TYPE_SEP.$item->presentation;
break;
case 'check':
$item->typ = 'multichoice';
$item->presentation = 'c'.FEEDBACK_MULTICHOICERESTORE_TYPE_SEP.$item->presentation;
break;
case 'dropdown':
$item->typ = 'multichoice';
$item->presentation = 'd'.FEEDBACK_MULTICHOICERESTORE_TYPE_SEP.$item->presentation;
break;
case 'radiorated':
$item->typ = 'multichoicerated';
$item->presentation = 'r'.FEEDBACK_MULTICHOICERESTORE_TYPE_SEP.$item->presentation;
break;
case 'dropdownrated':
$item->typ = 'multichoicerated';
$item->presentation = 'd'.FEEDBACK_MULTICHOICERESTORE_TYPE_SEP.$item->presentation;
break;
}
} else {
$oldtyp = intval(backup_todb($item_info['#']['TYP']['0']['#']));
switch($oldtyp) {
@ -158,6 +182,7 @@
$values = $item_info['#']['FBVALUES']['0']['#']['FBVALUE'];
for($ii = 0; $ii < sizeof($values); $ii++) {
$value_info = $values[$ii];
$value = new object();
$value->id = '';
$value->item = $newitemid;
$value->completed = 0;
@ -168,7 +193,7 @@
//put this new value into the database
$newvalueid = insert_record('feedback_value', $value);
$value->id = $newvalueid;
$allValues[] = $value;
// $allValues[] = $value;
}
}
}
@ -178,6 +203,7 @@
$trackings = $info['MOD']['#']['TRACKINGS']['0']['#']['TRACKING'];
for($i = 0; $i < sizeof($trackings); $i++) {
$tracking_info = $trackings[$i];
$tracking = new object();
$tracking->id = '';
$tracking->userid = backup_todb($tracking_info['#']['USERID']['0']['#']); //have to change later
$tracking->feedback = $newid;
@ -194,13 +220,14 @@
//save the tracking
$newtrackingid = insert_record('feedback_tracking', $tracking);
$tracking->id = $newtrackingid;
$allTrackings[] = $tracking;
// $allTrackings[] = $tracking;
}
//restore completeds
$completeds = $info['MOD']['#']['COMPLETEDS']['0']['#']['COMPLETED'];
for($i = 0; $i < sizeof($completeds); $i++) {
$completed_info = $completeds[$i];
$completed = new object();
$completed->feedback = $newid;
$completed->userid = backup_todb($completed_info['#']['USERID']['0']['#']);
$completed->timemodified = backup_todb($completed_info['#']['TIMEMODIFIED']['0']['#']);

View File

@ -10,7 +10,7 @@
*/
$module->version = 2008042300; // The current module version (Date: YYYYMMDDXX)
$module->version = 2008042401; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2007101503; // Requires this Moodle version
$feedback_version_intern = 1; //this version is used for restore older backups
$module->cron = 0; // Period for cron to check this module (secs)