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,220 @@
<?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/>.
namespace mod_bigbluebuttonbn\form;
use context;
use core_form\dynamic_form;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\exceptions\bigbluebutton_exception;
use mod_bigbluebuttonbn\task\send_guest_emails;
use moodle_exception;
use moodle_url;
use MoodleQuickForm;
/**
* Popup form to add new guests to a meeting and show/copy credential to access the guest login page.
*
* @package mod_bigbluebuttonbn
* @copyright 2022 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent [at] call-learning [dt] fr)
*/
class guest_add extends dynamic_form {
/**
* Max length for credential and url fields.
*/
const MAX_INPUT_LENGTH = 35;
/**
* Process the form submission, used if form was submitted via AJAX.
*
* @return array
*/
public function process_dynamic_submission(): array {
global $USER;
$data = $this->get_data();
$allmails = [];
if (!empty($data->emails)) {
$emails = explode(',', $data->emails);
foreach ($emails as $email) {
$email = trim($email);
if (validate_email($email)) {
$allmails[] = $email;
}
}
$adhoctask = new send_guest_emails();
$adhoctask->set_custom_data(
[
'emails' => $allmails,
'useridfrom' => $USER->id
]
);
$adhoctask->set_instance_id($data->id);
\core\task\manager::queue_adhoc_task($adhoctask);
}
return [
'result' => true,
'emails' => join(', ', $allmails),
'emailcount' => count($allmails),
'errors' => ''
];
}
/**
* Perform some validation.
*
* @param array $formdata
* @param array $files
* @return array
*/
public function validation($formdata, $files): array {
$errors = [];
$emailserrors = [];
if (!empty($formdata['emails'])) {
$emails = explode(',', $formdata['emails']);
foreach ($emails as $email) {
$email = trim($email);
if (!validate_email($email)) {
$emailserrors[] .= get_string('guestaccess_emails_invalidemail', 'mod_bigbluebuttonbn', $email);
}
}
}
if (!empty($emailserrors)) {
$errors['emails'] = \html_writer::alist($emailserrors);
}
return $errors;
}
/**
* Load in existing data as form defaults (not applicable).
*
* @return void
*/
public function set_data_for_dynamic_submission(): void {
$instance = $this->get_instance_from_params();
$data = [
'id' => $instance->get_instance_id(),
'groupid' => $instance->get_group_id(),
'guestjoinurl' => $instance->get_guest_access_url(),
'guestpassword' => $instance->get_guest_access_password(),
];
$this->set_data($data);
}
/**
* Get BigblueButton instance from context params
*
* @return instance
* @throws moodle_exception
*/
protected function get_instance_from_params(): instance {
$bbid = $this->optional_param('id', null, PARAM_INT);
$groupid = $this->optional_param('groupid', null, PARAM_INT);
if (empty($bbid)) {
throw new moodle_exception('guestaccess_add_no_id', 'mod_bigbluebuttonbn');
}
$instance = instance::get_from_instanceid($bbid);
if ($groupid) {
$instance->set_group_id($groupid);
}
return $instance;
}
/**
* Form definition
*/
protected function definition() {
self::add_meeting_links_elements($this->_form);
$mform = $this->_form;
$mform->addElement('text', 'emails',
get_string('guestaccess_emails', 'mod_bigbluebuttonbn'),
);
$mform->addHelpButton('emails', 'guestaccess_emails', 'mod_bigbluebuttonbn');
$mform->setDefault('emails', '');
$mform->setType('emails', PARAM_RAW);
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'groupid');
$mform->setType('groupid', PARAM_INT);
}
/**
* Add meeting links element. Helper for this form and the mod_form (module form)
*
* @param MoodleQuickForm $mform
* @return void
*/
public static function add_meeting_links_elements(MoodleQuickForm &$mform): void {
global $CFG;
MoodleQuickForm::registerElementType('text_with_copy',
"$CFG->dirroot/mod/bigbluebuttonbn/classes/form/text_with_copy_element.php",
text_with_copy_element::class);
$mform->addElement('text_with_copy', 'guestjoinurl',
get_string('guestaccess_meeting_link', 'mod_bigbluebuttonbn'),
[
'copylabel' => get_string('guestaccess_copy_link', 'mod_bigbluebuttonbn'),
'size' => self::MAX_INPUT_LENGTH,
'readonly' => 'readonly'
]
);
$mform->setType('guestjoinurl', PARAM_URL);
$mform->addElement('text_with_copy', 'guestpassword',
get_string('guestaccess_meeting_password', 'mod_bigbluebuttonbn'),
[
'copylabel' => get_string('guestaccess_copy_password', 'mod_bigbluebuttonbn'),
'readonly' => 'readonly',
'size' => self::MAX_INPUT_LENGTH,
]
);
$mform->setType('guestpassword', PARAM_RAW);
}
/**
* Check if current user has access to this form, otherwise throw exception.
*
* @return void
* @throws moodle_exception
*/
protected function check_access_for_dynamic_submission(): void {
$context = $this->get_context_for_dynamic_submission();
$instance = instance::get_from_cmid($context->instanceid);
if (!$instance->is_moderator()) {
throw new \restricted_context_exception();
}
}
/**
* Return form context
*
* @return context
*/
protected function get_context_for_dynamic_submission(): context {
$instance = $this->get_instance_from_params();
return $instance->get_context();
}
/**
* Returns url to set in $PAGE->set_url() when form is being rendered or submitted via AJAX.
*
* @return moodle_url
*/
protected function get_page_url_for_dynamic_submission(): moodle_url {
$context = $this->get_context_for_dynamic_submission();
return new moodle_url('/mod/bigbluebuttonbn/view.php', ['id' => $context->instanceid]);
}
}
@@ -0,0 +1,78 @@
<?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/>.
namespace mod_bigbluebuttonbn\form;
defined('MOODLE_INTERNAL') || die;
global $CFG;
require_once($CFG->libdir . '/formslib.php');
/**
* Guest login form.
*
* @package mod_bigbluebuttonbn
* @copyright 2022 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent [at] call-learning [dt] fr)
*/
class guest_login extends \moodleform {
/**
* Form definition
*/
protected function definition() {
global $USER;
$mform = $this->_form;
$mform->addElement('text', 'username',
get_string('guestaccess_username', 'mod_bigbluebuttonbn'));
$mform->setType('username', PARAM_NOTAGS);
$mform->addRule('username',
get_string('required'), 'required', null, 'client');
if (isloggedin() && !isguestuser()) {
$mform->setConstant('username', fullname($USER));
$mform->freeze('username');
}
$mform->addElement('password', 'password',
get_string('guestaccess_password', 'mod_bigbluebuttonbn'));
$mform->setType('password', PARAM_RAW);
$mform->addRule('password',
get_string('required'), 'required', null, 'client');
$mform->addElement('hidden', 'uid', $this->_customdata['uid']);
$mform->setType('uid', PARAM_ALPHANUMEXT);
$this->add_action_buttons(false, get_string('guestaccess_join_meeting', 'mod_bigbluebuttonbn'));
}
/**
* Validate form
*
* @param array $data
* @param array $files
* @return array
* @throws \coding_exception
*/
public function validation($data, $files): array {
$errors = parent::validation($data, $files);
$instance = $this->_customdata['instance'];
if ($data['password'] != $instance->get_guest_access_password()) {
$errors['password'] = get_string('guestaccess_meeting_invalid_password', 'mod_bigbluebuttonbn');
}
return $errors;
}
}
@@ -0,0 +1,98 @@
<?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/>.
namespace mod_bigbluebuttonbn\form;
use MoodleQuickForm_text;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once("$CFG->libdir/form/text.php");
/**
* Text type form element with a copy widget
*
* Contains HTML class for a text type element and a link that will copy its content in the copy/paste buffer
*
* @package mod_bigbluebuttonbn
* @copyright 2022 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent [at] call-learning [dt] fr)
*/
class text_with_copy_element extends MoodleQuickForm_text {
/** @var string an element template. */
public $_groupElementTemplate;
/**
* Accepts a renderer
*
* @param object $renderer An HTML_QuickForm_Renderer object
* @param bool $required Whether an element is required
* @param string $error An error message associated with an element
* @return void
*/
public function accept(&$renderer, $required = false, $error = null) {
global $OUTPUT;
$elementname = $this->getName();
// Make sure the element has an id.
$this->_generateId();
$advanced = isset($renderer->_advancedElements[$elementname]);
$elementcontext = $this->export_for_template($OUTPUT);
$helpbutton = '';
if (method_exists($this, 'getHelpButton')) {
$helpbutton = $this->getHelpButton();
}
$label = $this->getLabel();
$text = '';
if (method_exists($this, 'getText')) {
// There currently exists code that adds a form element with an empty label.
// If this is the case then set the label to the description.
if (empty($label)) {
$label = $this->getText();
} else {
$text = $this->getText();
}
}
$context = array(
'element' => $elementcontext,
'label' => $label,
'text' => $text,
'required' => $required,
'advanced' => $advanced,
'helpbutton' => $helpbutton,
'error' => $error,
'copylabel' => $this->_attributes['copylabel'] ?? get_string('copy', 'core_editor')
);
$html = $OUTPUT->render_from_template('mod_bigbluebuttonbn/element_text_with_copy', $context);
if ($renderer->_inGroup) {
$this->_groupElementTemplate = $html;
}
if (($renderer->_inGroup) && !empty($renderer->_groupElementTemplate)) {
$renderer->_groupElementTemplate = $html;
} else if (!isset($renderer->_templates[$elementname])) {
$renderer->_templates[$elementname] = $html;
}
if (in_array($elementname, $renderer->_stopFieldsetElements) && $renderer->_fieldsetsOpen > 0) {
$renderer->_html .= $renderer->_closeFieldsetTemplate;
$renderer->_fieldsetsOpen--;
}
$renderer->_html .= $html;
}
}