captcha now uses the recaptcha-plugin and

some code cleanups
This commit is contained in:
Andreas Grabs
2010-06-04 20:21:08 +00:00
parent b46ba22bf5
commit 6cc1599e09
15 changed files with 293 additions and 315 deletions
+3 -4
View File
@@ -127,11 +127,10 @@ if($check_anonymously) {
foreach($items as $item) {
if($item->hasvalue == 0) continue;
echo '<table width="100%" class="generalbox">';
//get the class of item-typ
$itemclass = 'feedback_item_'.$item->typ;
//get the instance of the item-class
require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php');
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($item->typ);
$itemnr++;
if($feedback->autonumbering) {
$printnr = $itemnr.'.';
+1 -4
View File
@@ -168,10 +168,7 @@ if ($courseitemfilter > 0) {
if($item->hasvalue == 0) continue;
echo '<table width="100%" class="generalbox">';
//get the class from item-typ
$itemclass = 'feedback_item_'.$item->typ;
//get the instance of the item-class
require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php');
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($item->typ);
$itemnr++;
if($feedback->autonumbering) {
$printnr = $itemnr.'.';
+2 -5
View File
@@ -185,9 +185,7 @@ if (empty($items)) {
}
foreach($items as $item) {
//get the class of item-typ
$itemclass = 'feedback_item_'.$item->typ;
//get the instance of the item-class
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($item->typ);
$rowOffset1 = $itemobj->excelprint_item($worksheet1, $rowOffset1, $xlsFormats, $item, $mygroupid, $coursefilter);
}
@@ -295,8 +293,7 @@ function feedback_excelprint_detailed_items(&$worksheet, $xlsFormats, $completed
foreach($items as $item) {
$value = $DB->get_record('feedback_value', array('item'=>$item->id, 'completed'=>$completed->id));
$itemclass = 'feedback_item_'.$item->typ;
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($item->typ);
$printval = $itemobj->get_printval($item, $value);
// $worksheet->setFormat('<l><vo>');
+1 -44
View File
@@ -84,8 +84,7 @@ if($id and $item = $DB->get_record('feedback_item', array('id'=>$id))) {
require_once($CFG->dirroot.'/mod/feedback/item/'.$typ.'/lib.php');
$itemclass = 'feedback_item_'.$typ;
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($typ);
$itemobj->build_editform($item, $feedback, $cm);
@@ -124,48 +123,6 @@ if(isset($error)) {
feedback_print_errors();
$itemobj->show_editform();
/*
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
echo '<form action="edit_item.php" method="post">';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
//this div makes the buttons stand side by side
echo '<div>';
$itemclass = 'feedback_item_'.$typ;
$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.'" />';
//choose the position
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
echo get_string('position', 'feedback').'&nbsp;';
echo '<select name="position">';
//Dropdown-Items for choosing the position
if($position == -1){
feedback_print_numeric_option_list(1, $lastposition + 1, $lastposition + 1);
}else {
feedback_print_numeric_option_list(1, $lastposition, $item->position);
}
echo '</select><hr />';
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
if(!empty($item->id)){
echo '<input type="hidden" id="updateitem" name="updateitem" value="1" />';
echo '<input type="submit" value ="'.get_string('update_item', 'feedback').'" />';
}else{
echo '<input type="hidden" id="saveitem" name="saveitem" value="1" />';
echo '<input type="submit" value="'.get_string('save_item', 'feedback').'" />';
}
echo '<input type="submit" name="cancel" value="'.get_string('cancel').'" />';
echo '</form>';
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
*/
// echo $OUTPUT->box_end();
if ($typ!='label') {
+114 -129
View File
@@ -5,74 +5,73 @@ require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_captcha extends feedback_item_base {
var $type = "captcha";
var $commonparams;
var $item_form;
var $item;
var $item_form = false;
var $item = false;
var $feedback = false;
function init() {
}
function build_editform($item, $feedback, $cm) {
global $DB, $CFG;
require_once('captcha_form.php');
//get the lastposition number of the feedback_items
$position = $item->position;
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
if($position == -1){
$i_formselect_last = $lastposition + 1;
$i_formselect_value = $lastposition + 1;
$item->position = $lastposition + 1;
}else {
$i_formselect_last = $lastposition;
$i_formselect_value = $item->position;
}
//the elements for position dropdownlist
$positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true);
global $DB;
$item->presentation = empty($item->presentation) ? 3 : $item->presentation;
$item->required = 1;
$editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cm->id));
//all items for dependitem
$feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
$commonparams = array('cmid'=>$cm->id,
'id'=>isset($item->id) ? $item->id : NULL,
'typ'=>$item->typ,
'items'=>$feedbackitems,
'feedback'=>$feedback->id);
//ther are no settings for recaptcha
if(isset($item->id) AND $item->id > 0) {
notice(get_string('there_are_no_settings_for_recaptcha', 'feedback'), $editurl->out());
exit;
}
//only one recaptcha can be in a feedback
if($DB->record_exists('feedback_item', array('feedback'=>$feedback->id, 'typ'=>$this->type))) {
notice(get_string('only_one_captcha_allowed', 'feedback'), $editurl->out());
exit;
}
$this->item = $item;
$this->feedback = $feedback;
$this->item_form = true; //dummy
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
//build the form
$this->item_form = new feedback_captcha_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position));
$this->item->feedback = $feedback->id;
$this->item->template = 0;
$this->item->name = get_string('captcha', 'feedback');
$this->item->label = get_string('captcha', 'feedback');
$this->item->presentation = '';
$this->item->typ = $this->type;
$this->item->hasvalue = $this->get_hasvalue();
$this->item->position = $lastposition + 1;
$this->item->required = 1;
$this->item->dependitem = 0;
$this->item->dependvalue = '';
$this->item->options = '';
}
//this function only can used after the call of build_editform()
function show_editform() {
$this->item_form->display();
}
function is_cancelled() {
return $this->item_form->is_cancelled();
return false;
}
function get_data() {
if($this->item = $this->item_form->get_data()) {
return true;
}
return false;
return true;
}
function save_item() {
global $DB;
if(!$item = $this->item_form->get_data()) {
if(!$this->item) {
return false;
}
$item->hasvalue = $this->get_hasvalue();
if(!$item->id) {
$item->id = $DB->insert_record('feedback_item', $item);
$item->id = $DB->insert_record('feedback_item', $this->item);
}else {
$DB->update_record('feedback_item', $item);
$DB->update_record('feedback_item', $this->item);
}
return $DB->get_record('feedback_item', array('id'=>$item->id));
@@ -91,7 +90,7 @@ class feedback_item_captcha extends feedback_item_base {
return $itemnr;
}
function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) {
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) {
return $rowOffset;
}
@@ -103,13 +102,10 @@ class feedback_item_captcha extends feedback_item_base {
* @return void
*/
function print_item_preview($item) {
global $SESSION, $CFG, $DB, $OUTPUT;
global $DB;
$align = right_to_left() ? 'right' : 'left';
$presentation = $item->presentation;
$SESSION->feedback->item->captcha->charcount = $presentation;
$cmid = 0;
$feedbackid = $item->feedback;
if($feedbackid > 0) {
@@ -119,36 +115,14 @@ class feedback_item_captcha extends feedback_item_base {
}
}
if(isset($SESSION->feedback->item->captcha->checked)) {
$checked = $SESSION->feedback->item->captcha->checked == true;
unset($SESSION->feedback->item->captcha->checked);
}else {
$checked = false;
}
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
$requiredmark = '<span class="feedback_required_mark">*</span>';
//print the question and label
echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') ';
echo format_text($item->name.$requiredmark, true, false, false);
if($item->dependitem) {
if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
echo ' <span class="feedback_depend">('.$dependitem->label.'-&gt;'.$item->dependvalue.')</span>';
}
}
echo '</div>';
//print the presentation
echo '<div class="feedback_item_presentation_'.$align.'">';
$imglink = new moodle_url('/mod/feedback/item/captcha/print_captcha.php', array('id'=>$cmid));
echo '<div class="feedback_item_captcha_img_'.$align.'">';
echo '<img alt="'.$this->type.'" src="'.$imglink->out().'" />';
echo '</div>';
echo '<div class="feedback_item_captcha_text_'.$align.'">';
echo '<input type="text" name="'.$item->typ.'_'.$item->id.'" size="'.$presentation.'" maxlength="'.$presentation.'" value="" />';
echo '</div>';
echo '</div>';
}
/**
@@ -161,13 +135,11 @@ class feedback_item_captcha extends feedback_item_base {
* @return void
*/
function print_item_complete($item, $value = '', $highlightrequire = false) {
global $SESSION, $CFG, $DB, $OUTPUT;
global $SESSION, $CFG, $DB, $USER;
require_once($CFG->libdir.'/recaptchalib.php');
$align = right_to_left() ? 'right' : 'left';
$presentation = $item->presentation;
$SESSION->feedback->item->captcha->charcount = $presentation;
$cmid = 0;
$feedbackid = $item->feedback;
if($feedbackid > 0) {
@@ -177,42 +149,57 @@ class feedback_item_captcha extends feedback_item_base {
}
}
if(isset($SESSION->feedback->item->captcha->checked)) {
$checked = $SESSION->feedback->item->captcha->checked == true;
unset($SESSION->feedback->item->captcha->checked);
}else {
$checked = false;
}
//check if an false value even the value is not required
if(!$item->required AND $value != '' AND $SESSION->feedback->item->captcha->checkchar != $value) {
if($highlightrequire AND !$this->check_value($value, $item)) {
$falsevalue = true;
}else {
$falsevalue = false;
}
if(($highlightrequire AND $item->required AND !$checked) OR $falsevalue) {
$highlight = ' missingrequire';
if($falsevalue) {
$highlight = 'missingrequire';
}else {
$highlight = '';
}
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
$requiredmark = '<span class="feedback_required_mark">*</span>';
//print the question and label
echo '<div class="feedback_item_label_'.$align.$highlight.'">';
if(isset($SESSION->feedback->captchacheck) AND $SESSION->feedback->captchacheck == $USER->sesskey AND $value == $USER->sesskey) {
//print the question and label
echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') ';
echo format_text($item->name.$requiredmark, true, false, false);
echo '</div>';
echo '<input type="hidden" value="'.$USER->sesskey.'" name="'.$item->typ.'_'.$item->id.'" />';
echo '</div>';
return;
}
$strincorrectpleasetryagain = get_string('incorrectpleasetryagain', 'auth');
$strenterthewordsabove = get_string('enterthewordsabove', 'auth');
$strenterthenumbersyouhear = get_string('enterthenumbersyouhear', 'auth');
$strgetanothercaptcha = get_string('getanothercaptcha', 'auth');
$strgetanaudiocaptcha = get_string('getanaudiocaptcha', 'auth');
$strgetanimagecaptcha = get_string('getanimagecaptcha', 'auth');
$recaptureoptions = Array('theme'=>'custom', 'custom_theme_widget'=>'recaptcha_widget');
$html = html_writer::script(js_writer::set_variable('RecaptchaOptions', $recaptureoptions));
$html .= '
<div class="'.$highlight.'" id="recaptcha_widget" style="display:none">
<div id="recaptcha_image"></div>
<div class="recaptcha_only_if_incorrect_sol" style="color:red">' . $strincorrectpleasetryagain . '</div>
<span class="recaptcha_only_if_image"><label for="recaptcha_response_field">' . $strenterthewordsabove . $requiredmark. '</label></span>
<span class="recaptcha_only_if_audio"><label for="recaptcha_response_field">' . $strenterthenumbersyouhear . '</label></span>
//print the presentation
echo '<div class="feedback_item_presentation_'.$align.'">';
echo '<div class="feedback_item_captcha_img_'.$align.'">';
$imglink = new moodle_url('/mod/feedback/item/captcha/print_captcha.php', array('id'=>$cmid));
echo '<img alt="'.$this->type.'" src="'.$imglink->out().'" />';
echo '</div>';
echo '<div class="feedback_item_captcha_text_'.$align.'">';
echo '<input type="text" name="'.$item->typ.'_'.$item->id.'" size="'.$presentation.'" maxlength="'.$presentation.'" value="" />';
echo '</div>';
echo '</div>';
<input type="text" id="recaptcha_response_field" name="'.$item->typ.'_'.$item->id.'" />
<div><a href="javascript:Recaptcha.reload()">' . $strgetanothercaptcha . '</a></div>
<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type(\'audio\')">' . $strgetanaudiocaptcha . '</a></div>
<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type(\'image\')">' . $strgetanimagecaptcha . '</a></div>
</div>';
//we have to rename the challengefield
$captchahtml = recaptcha_get_html($CFG->recaptchapublickey, NULL);
echo $html.$captchahtml;
}
/**
@@ -224,57 +211,52 @@ class feedback_item_captcha extends feedback_item_base {
* @return void
*/
function print_item_show_value($item, $value = '') {
global $SESSION, $CFG, $DB, $OUTPUT;
global $DB;
$align = right_to_left() ? 'right' : 'left';
$presentation = $item->presentation;
$SESSION->feedback->item->captcha->charcount = $presentation;
$cmid = 0;
if(isset($SESSION->feedback->item->captcha->checked)) {
$checked = $SESSION->feedback->item->captcha->checked == true;
unset($SESSION->feedback->item->captcha->checked);
}else {
$checked = false;
$feedbackid = $item->feedback;
if($feedbackid > 0) {
$feedback = $DB->get_record('feedback', array('id'=>$feedbackid));
if($cm = get_coursemodule_from_instance("feedback", $feedback->id, $feedback->course)) {
$cmid = $cm->id;
}
}
$requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
$requiredmark = '<span class="feedback_required_mark">*</span>';
//print the question and label
echo '<div class="feedback_item_label_'.$align.'">';
echo '('.$item->label.') ';
echo format_text($item->name . $requiredmark, true, false, false);
echo '</div>';
//print the presentation
echo '<div class="feedback_item_presentation_'.$align.'">';
echo '<div class="feedback_item_captcha_img_'.$align.'">';
$imglink = new moodle_url('/mod/feedback/item/captcha/print_captcha.php', array('id'=>$cmid));
echo '<img alt="'.$this->type.'" src="'.$imglink->out().'" />';
echo '</div>';
echo $OUTPUT->box_start('generalbox boxalign'.$align);
echo $value ? $value : '&nbsp;';
echo $OUTPUT->box_end();
echo '('.$item->label.') ';
echo format_text($item->name.$requiredmark, true, false, false);
echo '</div>';
}
function check_value($value, $item) {
global $SESSION;
//if the item is not required, so the check is true if no value is given
if((!isset($value) OR $value == '') AND $item->required != 1) return true;
if($SESSION->feedback->item->captcha->checkchar == $value) {
$SESSION->feedback->item->captcha->checked = true;
global $SESSION, $CFG, $USER;
require_once($CFG->libdir.'/recaptchalib.php');
$challenge = optional_param('recaptcha_challenge_field', '', PARAM_RAW);
if($value == $USER->sesskey AND $challenge == '') {
return true;
}
$remoteip = getremoteaddr(null);
$response = recaptcha_check_answer($CFG->recaptchaprivatekey, $remoteip, $challenge, $value);
if($response->is_valid) {
$SESSION->feedback->captchacheck = $USER->sesskey;
return true;
}
unset($SESSION->feedback->captchacheck);
return false;
}
function create_value($data) {
$data = clean_text($data);
return $data;
global $USER;
return $USER->sesskey;
}
//compares the dbvalue with the dependvalue
@@ -288,11 +270,14 @@ class feedback_item_captcha extends feedback_item_base {
}
function get_presentation($data) {
return $data->count_of_nums;
return '';
}
function get_hasvalue() {
return 1;
}
function can_switch_require() {
return false;
}
}
?>
+101 -69
View File
@@ -1,64 +1,41 @@
<?php
class feedback_item_base {
abstract class feedback_item_base {
var $type;
/**
* The class constructor
*
*/
function feedback_item_base() {
$this->init();
}
/**
* Fake constructor to keep PHP5 happy
* constructor
*
*/
function __construct() {
$this->feedback_item_base();
$this->init();
}
/**
* prints the item-related sequenz on the edit-item form
*
* @param $item the db-object from feedback_item
* @param $usehtmleditor defines whether the editor should be shown or not
*/
function show_edit($item, $usehtmleditor = false) {
//this function only can used after the call of build_editform()
function show_editform() {
$this->item_form->display();
}
function is_cancelled() {
return $this->item_form->is_cancelled();
}
/**
* returns an Array with three values(typ, name, XXX)
* XXX is also an Array (count of responses on type $this->type)
* each element is a structure (answertext, answercount)
* @param $item the db-object from feedback_item
* @param $groupid if given
* @param $courseid if given
* @return array
*/
function get_analysed($item, $groupid = false, $courseid = false) {
return array();
}
/**
* @param object $item the db-object from feedback_item
* @param string $value a item-related value from feedback_values
* @return string
*/
function get_printval($item, $value) {
return '';
}
/**
* @param $item the db-object from feedback_item
* @param string $itemnr
* @param integer $groupid
* @param integer $courseid
* @return integer the new itemnr
*/
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
return 0;
function get_data() {
if($this->item = $this->item_form->get_data()) {
return true;
}
return false;
}
abstract function init();
abstract function build_editform($item, $feedback, $cm);
abstract function save_item();
abstract function check_value($value, $item);
abstract function create_value($data);
abstract function compare_value($item, $dbvalue, $dependvalue);
abstract function get_presentation($data);
abstract function get_hasvalue();
abstract function can_switch_require();
/**
* @param object $worksheet a reference to the pear_spreadsheet-object
@@ -68,36 +45,91 @@ class feedback_item_base {
* @param integer $courseid
* @return integer the new rowOffset
*/
function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) {
return $rowOffset;
}
abstract function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false);
function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){
}
/**
* @param $item the db-object from feedback_item
* @param string $itemnr
* @param integer $groupid
* @param integer $courseid
* @return integer the new itemnr
*/
abstract function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false);
/**
* @param object $item the db-object from feedback_item
* @param string $value a item-related value from feedback_values
* @return string
*/
abstract function get_printval($item, $value);
/**
* returns an Array with three values(typ, name, XXX)
* XXX is also an Array (count of responses on type $this->type)
* each element is a structure (answertext, answercount)
* @param $item the db-object from feedback_item
* @param $groupid if given
* @param $courseid if given
* @return array
*/
abstract function get_analysed($item, $groupid = false, $courseid = false);
/**
* print the item at the edit-page of feedback
*
* @global object
* @param object $item
* @return void
*/
abstract function print_item_preview($item);
/**
* print the item at the complete-page of feedback
*
* @global object
* @param object $item
* @param string $value
* @param bool $highlightrequire
* @return void
*/
abstract function print_item_complete($item, $value = '', $highlightrequire = false);
function check_value($value, $item) {
return true;
}
/**
* print the item at the complete-page of feedback
*
* @global object
* @param object $item
* @param string $value
* @return void
*/
abstract function print_item_show_value($item, $value = '');
function create_value($data) {
return '';
}
function get_presentation($data) {
return '';
}
function get_hasvalue() {
return 0;
}
}
//a dummy class to realize pagebreaks
class feedback_item_pagebreak extends feedback_item_base {
var $type = "pagebreak";
function init() {
}
function show_editform() {}
function is_cancelled() {}
function get_data() {}
function init() {}
function build_editform($item, $feedback, $cm) {}
function save_item() {}
function check_value($value, $item) {}
function create_value($data) {}
function compare_value($item, $dbvalue, $dependvalue) {}
function get_presentation($data) {}
function get_hasvalue() {}
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) {}
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {}
function get_printval($item, $value) {}
function get_analysed($item, $groupid = false, $courseid = false) {}
function print_item_preview($item) {}
function print_item_complete($item, $value = '', $highlightrequire = false) {}
function print_item_show_value($item, $value = '') {}
function can_switch_require(){}
}
+4 -1
View File
@@ -306,5 +306,8 @@ class feedback_item_info extends feedback_item_base {
function get_hasvalue() {
return 1;
}
function can_switch_require() {
return false;
}
}
?>
+10 -1
View File
@@ -208,5 +208,14 @@ class feedback_item_label extends feedback_item_base {
function get_hasvalue() {
return 0;
}
function can_switch_require() {
return false;
}
function check_value($value, $item) {}
function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) {}
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {}
function get_printval($item, $value) {}
function get_analysed($item, $groupid = false, $courseid = false) {}
}
?>
+4 -2
View File
@@ -700,6 +700,8 @@ class feedback_item_multichoice extends feedback_item_base {
return false;
}
function can_switch_require() {
return true;
}
}
?>
+3 -1
View File
@@ -582,6 +582,8 @@ class feedback_item_multichoicerated extends feedback_item_base {
return false;
}
function can_switch_require() {
return true;
}
}
?>
+4 -1
View File
@@ -411,5 +411,8 @@ class feedback_item_numeric extends feedback_item_base {
function get_hasvalue() {
return 1;
}
function can_switch_require() {
return true;
}
}
?>
+5 -2
View File
@@ -85,7 +85,7 @@ class feedback_item_textarea extends feedback_item_base {
//liefert eine Struktur ->name, ->data = array(mit Antworten)
function get_analysed($item, $groupid, $courseid = false) {
function get_analysed($item, $groupid = false, $courseid = false) {
global $DB;
$aVal = null;
@@ -270,5 +270,8 @@ class feedback_item_textarea extends feedback_item_base {
function get_hasvalue() {
return 1;
}
function can_switch_require() {
return true;
}
}
?>
+4 -1
View File
@@ -264,5 +264,8 @@ class feedback_item_textfield extends feedback_item_base {
function get_hasvalue() {
return 1;
}
function can_switch_require() {
return true;
}
}
?>
+2
View File
@@ -198,6 +198,7 @@ $string['numeric_range_to'] = 'Range to';
$string['of'] = 'of';
$string['oldvaluespreserved'] = 'All old questions and the assigned values will be preserved';
$string['oldvalueswillbedeleted'] = 'The current questions and all your user\'s responses will be deleted';
$string['only_one_captcha_allowed'] = 'Only one captcha is allowed in a feedback';
$string['overview'] = 'Overview';
$string['page'] = 'Page';
$string['page_after_submit'] = 'Page after submit';
@@ -262,6 +263,7 @@ $string['textarea_width'] = 'Width';
$string['textfield'] = 'Short text answer';
$string['textfield_maxlength'] = 'Maximum characters accepted';
$string['textfield_size'] = 'Textfield width';
$string['there_are_no_settings_for_recaptcha'] = 'There are no settings for captcha';
$string['this_feedback_is_already_submitted'] = 'You\'ve already completed this activity.';
$string['timeclose'] = 'Time to close';
$string['timeclose_help'] = 'You can specify times when the feedback is accessible for people to answer the questions. If the checkbox is not ticked there is no limit defined.';
+35 -51
View File
@@ -1113,6 +1113,25 @@ function feedback_get_template_list($course, $onlyown = false) {
////////////////////////////////////////////////
////////////////////////////////////////////////
/**
* load the lib.php from item-plugin-dir and returns the instance of the itemclass
*
* @global object
* @param object $item
* @return object the instanz of itemclass
*/
function feedback_get_item_class($typ) {
global $CFG;
//get the class of item-typ
$itemclass = 'feedback_item_'.$typ;
//get the instance of item-class
if (!class_exists($itemclass)) {
require_once($CFG->dirroot.'/mod/feedback/item/'.$typ.'/lib.php');
}
return new $itemclass();
}
/**
* load the available item plugins from given subdirectory of $CFG->dirroot
* the default is "mod/feedback/item"
@@ -1213,10 +1232,7 @@ function feedback_create_item($data) {
$item->label = get_string('no_itemlabel', 'feedback');
}
//get the used class from item-typ
$itemclass = 'feedback_item_'.$data->typ;
//get the instance of the item class
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($data->typ);
// $item->presentation = $itemobj->get_presentation($data);
$item->presentation = ''; //the date comes from postupdate() of the itemobj
@@ -1320,9 +1336,14 @@ function feedback_delete_all_items($feedbackid){
* @return boolean
*/
function feedback_switch_item_required($item) {
global $DB;
global $DB, $CFG;
return $DB->set_field('feedback_item', 'required', (int)!(bool)$item->required, array('id'=>$item->id));
$itemobj = feedback_get_item_class($item->typ);
if($itemobj->can_switch_require()) {
$DB->set_field('feedback_item', 'required', (int)!(bool)$item->required, array('id'=>$item->id));
}
return true;
}
/**
@@ -1457,13 +1478,8 @@ function feedback_print_item_preview($item){
if($item->typ == 'pagebreak') {
return;
}
//get the class of the given item-typ
$itemclass = 'feedback_item_'.$item->typ;
if (!class_exists($itemclass)) {
require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php');
}
//get the instance of the item-class
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($item->typ);
$itemobj->print_item_preview($item);
}
@@ -1482,13 +1498,8 @@ function feedback_print_item_complete($item, $value = false, $highlightrequire =
return;
}
//get the class of the given item-typ
$itemclass = 'feedback_item_'.$item->typ;
if (!class_exists($itemclass)) {
require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php');
}
//get the instance of the item-class
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($item->typ);
$itemobj->print_item_complete($item, $value, $highlightrequire);
}
@@ -1506,13 +1517,8 @@ function feedback_print_item_show_value($item, $value = false){
return;
}
//get the class of the given item-typ
$itemclass = 'feedback_item_'.$item->typ;
if (!class_exists($itemclass)) {
require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php');
}
//get the instance of the item-class
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($item->typ);
$itemobj->print_item_show_value($item, $value);
}
@@ -1833,12 +1839,9 @@ function feedback_compare_item_value($completedid, $itemid, $dependvalue, $tmp =
//get the class of the given item-typ
$item = $DB->get_record('feedback_item', array('id'=>$itemid));
$itemclass = 'feedback_item_'.$item->typ;
if (!class_exists($itemclass)) {
require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php');
}
//get the instance of the item-class
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($item->typ);
return $itemobj->compare_value($item, $dbvalue, $dependvalue); //true or false
}
@@ -1882,15 +1885,8 @@ function feedback_check_values($firstitem, $lastitem) {
return false;
}
//get the class of the item-typ
$itemclass = 'feedback_item_'.$item->typ;
if (!class_exists($itemclass)) {
require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php');
}
//get the instance of the item-class
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($item->typ);
//now we let check the value by the item-class
if(!$itemobj->check_value($value, $item)) {
@@ -1951,13 +1947,7 @@ function feedback_create_values($usrid, $timemodified, $tmp = false, $guestid =
$value->course_id = $courseid;
//get the class of item-typ
$itemclass = 'feedback_item_'.$item->typ;
//get the instance of item-class
if (!class_exists($itemclass)) {
require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php');
}
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($item->typ);
//the kind of values can be absolutely different so we run create_value directly by the item-class
$value->value = $itemobj->create_value($itemvalue);
@@ -2003,13 +1993,7 @@ function feedback_update_values($completed, $tmp = false) {
$newvalue->course_id = $courseid;
//get the class of item-typ
$itemclass = 'feedback_item_'.$item->typ;
//get the instance of item-class
if (!class_exists($itemclass)) {
require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php');
}
$itemobj = new $itemclass();
$itemobj = feedback_get_item_class($item->typ);
//the kind of values can be absolutely different so we run create_value directly by the item-class
$newvalue->value = $itemobj->create_value($itemvalue);