first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,52 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
class feedback_captcha_form extends feedback_item_form {
protected $type = "captcha";
public function definition() {
$item = $this->_customdata['item'];
$common = $this->_customdata['common'];
$positionlist = $this->_customdata['positionlist'];
$position = $this->_customdata['position'];
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$mform->addElement('advcheckbox', 'required', get_string('required', 'feedback'), '' , null , array(0, 1));
$mform->addElement('text',
'name',
get_string('item_name', 'feedback'),
array('size'=>FEEDBACK_ITEM_NAME_TEXTBOX_SIZE, 'maxlength'=>255));
$mform->addElement('text',
'label',
get_string('item_label', 'feedback'),
array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255));
$mform->addElement('select',
'presentation',
get_string('count_of_nums', 'feedback').'&nbsp;',
array_slice(range(0, 10), 3, 10, true));
parent::definition();
$this->set_data($item);
}
}
+213
View File
@@ -0,0 +1,213 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') OR die('not allowed');
require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
class feedback_item_captcha extends feedback_item_base {
protected $type = "captcha";
public function build_editform($item, $feedback, $cm) {
global $DB;
$editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cm->id));
// There 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.
$params = array('feedback' => $feedback->id, 'typ' => $this->type);
if ($DB->record_exists('feedback_item', $params)) {
notice(get_string('only_one_captcha_allowed', 'feedback'), $editurl->out());
exit;
}
$this->item = $item;
$this->item_form = true; // Dummy.
$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
$this->item->feedback = $feedback->id;
$this->item->template = 0;
$this->item->name = get_string('captcha', 'feedback');
$this->item->label = '';
$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 = '';
}
public function show_editform() {
}
public function is_cancelled() {
return false;
}
public function get_data() {
return true;
}
public function save_item() {
global $DB;
if (!$this->item) {
return false;
}
if (empty($this->item->id)) {
$this->item->id = $DB->insert_record('feedback_item', $this->item);
} else {
$DB->update_record('feedback_item', $this->item);
}
return $DB->get_record('feedback_item', array('id'=>$this->item->id));
}
public function get_printval($item, $value) {
return '';
}
public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
return $itemnr;
}
public function excelprint_item(&$worksheet, $row_offset,
$xls_formats, $item,
$groupid, $courseid = false) {
return $row_offset;
}
/**
* Returns the formatted name of the item for the complete form or response view
*
* @param stdClass $item
* @param bool $withpostfix
* @return string
*/
public function get_display_name($item, $withpostfix = true) {
return get_string('captcha', 'feedback');
}
/**
* Adds an input element to the complete form
*
* @param stdClass $item
* @param mod_feedback_complete_form $form
*/
public function complete_form_element($item, $form) {
$name = $this->get_display_name($item);
$inputname = $item->typ . '_' . $item->id;
if ($form->get_mode() != mod_feedback_complete_form::MODE_COMPLETE) {
// Span to hold the element id. The id is used for drag and drop reordering.
$form->add_form_element($item,
['static', $inputname, $name, html_writer::span('', '', ['id' => 'feedback_item_' . $item->id])],
false,
false);
} else {
// Add recaptcha element that is used during the form validation.
$form->add_form_element($item,
['recaptcha', $inputname . 'recaptcha', $name],
false,
false);
// Add hidden element with value "1" that will be saved in the values table after completion.
$form->add_form_element($item, ['hidden', $inputname, 1], false);
$form->set_element_type($inputname, PARAM_INT);
}
// Add recaptcha validation to the form.
$form->add_validation_rule(function($values, $files) use ($item, $form) {
$elementname = $item->typ . '_' . $item->id . 'recaptcha';
$recaptchaelement = $form->get_form_element($elementname);
if (empty($values['g-recaptcha-response'])) {
return array($elementname => get_string('required'));
} else {
$response = $values['g-recaptcha-response'];
if (true !== ($result = $recaptchaelement->verify($response))) {
return array($elementname => $result);
}
}
return true;
});
}
public function create_value($data) {
global $USER;
return $USER->sesskey;
}
public function get_hasvalue() {
global $CFG;
// Is recaptcha configured in moodle?
if (empty($CFG->recaptchaprivatekey) OR empty($CFG->recaptchapublickey)) {
return 0;
}
return 1;
}
public function can_switch_require() {
return false;
}
/**
* Returns the list of actions allowed on this item in the edit mode
*
* @param stdClass $item
* @param stdClass $feedback
* @param cm_info $cm
* @return action_menu_link[]
*/
public function edit_actions($item, $feedback, $cm) {
$actions = parent::edit_actions($item, $feedback, $cm);
unset($actions['update']);
return $actions;
}
public function get_data_for_external($item) {
global $CFG;
if (empty($CFG->recaptchaprivatekey) || empty($CFG->recaptchapublickey)) {
return null;
}
// With reCAPTCHA v2 the captcha will be rendered by the mobile client using just the publickey.
$data[] = $CFG->recaptchapublickey;
return json_encode($data);
}
/**
* Return the analysis data ready for external functions.
*
* @param stdClass $item the item (question) information
* @param int $groupid the group id to filter data (optional)
* @param int $courseid the course id (optional)
* @return array an array of data with non scalar types json encoded
* @since Moodle 3.3
*/
public function get_analysed_for_external($item, $groupid = false, $courseid = false) {
return [];
}
}
+124
View File
@@ -0,0 +1,124 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once('../../../../config.php');
$id = required_param('id', PARAM_INT);
$PAGE->set_url('/mod/feedback/item/captcha/print_captcha.php', array('id'=>$id));
if ($id) {
if (! $cm = get_coursemodule_from_id('feedback', $id)) {
throw new \moodle_exception('invalidcoursemodule');
}
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
throw new \moodle_exception('coursemisconf');
}
if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
throw new \moodle_exception('invalidcoursemodule');
}
}
if (!isset($SESSION->feedback->item->captcha)) {
throw new \moodle_exception('captchanotset', 'feedback');
}
$height = 40;
$charcount = $SESSION->feedback->item->captcha->charcount;
$fontfile = $CFG->libdir.'/default.ttf';
$ttfbox = imagettfbbox ( 30, 0, $fontfile, 'H' );//the text to measure
$charwidth = $ttfbox[2];
$width = $charcount * $charwidth;
$scale = 0.3;
$elipsesize = intval((($width + $height)/2) / 5);
$factor_x = intval($width * $scale);
$factor_y = intval($height * $scale);
//I split the colors in three ranges
//given are the max-min-values
$colors = array(array(0, 40), array(50, 200), array(210, 255));
list($col_text1, $col_el, $col_text2) = $colors;
//if the text is in color_1 so the elipses can be in color_2 or color_3
//if the text is in color_2 so the elipses can be in color_1 or color_3
//and so on.
$textcolnum = rand(1, 3);
//create the numbers to print out
$nums = array();
for ($i = 0; $i < $charcount; $i++) {
$nums[] = rand(0, 9); //Ziffern von 0-
}
//to draw enough elipses so I draw 0.2 * width and 0.2 * height
//we need th colors for that
$properties = array();
for ($x = 0; $x < $factor_x; $x++) {
for ($y = 0; $y < $factor_y; $y++) {
$propobj = new stdClass();
$propobj->x = intval($x / $scale);
$propobj->y = intval($y / $scale);
$propobj->red = get_random_color($col_el[0], $col_el[1]);
$propobj->green = get_random_color($col_el[0], $col_el[1]);
$propobj->blue = get_random_color($col_el[0], $col_el[1]);
$properties[] = $propobj;
}
}
shuffle($properties);
// create a blank image
$image = imagecreatetruecolor($width, $height);
$bg = imagecolorallocate($image, 0, 0, 0);
for ($i = 0; $i < ($factor_x * $factor_y); $i++) {
$propobj = $properties[$i];
// choose a color for the ellipse
$col_ellipse = imagecolorallocate($image, $propobj->red, $propobj->green, $propobj->blue);
// draw the white ellipse
imagefilledellipse($image, $propobj->x, $propobj->y, $elipsesize, $elipsesize, $col_ellipse);
}
$checkchar = '';
for ($i = 0; $i < $charcount; $i++) {
$colnum = rand(1, 2);
$textcol = new stdClass();
$textcol->red = get_random_color(${'col_text'.$colnum}[0], ${'col_text'.$colnum}[1]);
$textcol->green = get_random_color(${'col_text'.$colnum}[0], ${'col_text'.$colnum}[1]);
$textcol->blue = get_random_color(${'col_text'.$colnum}[0], ${'col_text'.$colnum}[1]);
$color_text = imagecolorallocate($image, $textcol->red, $textcol->green, $textcol->blue);
$angle_text = rand(-20, 20);
$left_text = $i * $charwidth;
$text = $nums[$i];
$checkchar .= $text;
imagettftext($image, 30, $angle_text, $left_text, 35, $color_text, $fontfile, $text);
}
$SESSION->feedback->item->captcha->checkchar = $checkchar;
// output the picture
header("Content-type: image/png");
imagepng($image);
function get_random_color($val1 = 0, $val2 = 255) {
$min = $val1 < $val2 ? $val1 : $val2;
$max = $val1 > $val2 ? $val1 : $val2;
return rand($min, $max);
}