forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MDL-45184-master' of git://github.com/junpataleta/moodle
- Loading branch information
Showing
39 changed files
with
2,425 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* This file defines the settings pages for licenses. | ||
* | ||
* @package core | ||
* @copyright 2020 Tom Dickman <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->libdir . '/licenselib.php'); | ||
|
||
if ($hassiteconfig) { | ||
|
||
$temp = new admin_settingpage('licensesettings', new lang_string('licensesettings', 'admin')); | ||
|
||
$licenses = license_manager::get_active_licenses_as_array(); | ||
|
||
$temp->add(new admin_setting_configselect('sitedefaultlicense', | ||
new lang_string('configsitedefaultlicense', 'admin'), | ||
new lang_string('configsitedefaultlicensehelp', 'admin'), | ||
'unknown', | ||
$licenses)); | ||
$temp->add(new admin_setting_configcheckbox('rememberuserlicensepref', | ||
new lang_string('rememberuserlicensepref', 'admin'), | ||
new lang_string('rememberuserlicensepref_help', 'admin'), | ||
1)); | ||
$ADMIN->add('license', $temp); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// 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/>. | ||
|
||
/** | ||
* Modal for confirming deletion of a custom license. | ||
* | ||
* @module tool_licensemanager/delete_license | ||
* @class delete_license | ||
* @package tool_licensemanager | ||
* @copyright 2019 Tom Dickman <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
define(['jquery', 'core/modal_factory', 'core/modal_events', 'core/url', 'core/str'], | ||
function($, ModalFactory, ModalEvents, Url, String) { | ||
|
||
var trigger = $('.delete-license'); | ||
ModalFactory.create({ | ||
type: ModalFactory.types.SAVE_CANCEL, | ||
title: String.get_string('deletelicense', 'tool_licensemanager'), | ||
body: String.get_string('deletelicenseconfirmmessage', 'tool_licensemanager'), | ||
preShowCallback: function(triggerElement, modal) { | ||
triggerElement = $(triggerElement); | ||
let params = { | ||
'action': 'delete', | ||
'license': triggerElement.data('license') | ||
}; | ||
modal.deleteURL = Url.relativeUrl('/admin/tool/licensemanager/index.php', params, true); | ||
}, | ||
large: true, | ||
}, trigger) | ||
.done(function(modal) { | ||
modal.getRoot().on(ModalEvents.save, function(e) { | ||
// Stop the default save button behaviour which is to close the modal. | ||
e.preventDefault(); | ||
// Redirect to delete url. | ||
window.location.href = modal.deleteURL; | ||
}); | ||
}); | ||
}); |
124 changes: 124 additions & 0 deletions
124
admin/tool/licensemanager/classes/form/edit_license.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/>. | ||
|
||
/** | ||
* Form for creating/updating a custom license. | ||
* | ||
* @package tool_licensemanager | ||
* @copyright 2019 Tom Dickman <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace tool_licensemanager\form; | ||
|
||
use moodleform; | ||
use tool_licensemanager\helper; | ||
use tool_licensemanager\manager; | ||
|
||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); | ||
|
||
global $CFG; | ||
require_once($CFG->libdir . '/formslib.php'); | ||
|
||
/** | ||
* Form for creating/updating a custom license. | ||
* | ||
* @package tool_licensemanager | ||
* @copyright 2019 Tom Dickman <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class edit_license extends moodleform { | ||
|
||
/** | ||
* @var string the action form is taking. | ||
*/ | ||
private $action; | ||
|
||
/** | ||
* @var string license shortname if editing or empty string if creating license. | ||
*/ | ||
private $licenseshortname; | ||
|
||
/** | ||
* edit_license constructor. | ||
* | ||
* @param string $action the license_manager action to be taken by form. | ||
* @param string $licenseshortname the shortname of the license to edit. | ||
*/ | ||
public function __construct(string $action, string $licenseshortname) { | ||
$this->action = $action; | ||
$this->licenseshortname = $licenseshortname; | ||
|
||
if ($action == manager::ACTION_UPDATE && !empty($licenseshortname)) { | ||
parent::__construct(helper::get_update_license_url($licenseshortname)); | ||
} else { | ||
parent::__construct(helper::get_create_license_url()); | ||
} | ||
} | ||
|
||
/** | ||
* Form definition for creation and editing of licenses. | ||
*/ | ||
public function definition() { | ||
|
||
$mform = $this->_form; | ||
|
||
$mform->addElement('text', 'shortname', get_string('shortname', 'tool_licensemanager')); | ||
$mform->setType('shortname', PARAM_ALPHANUMEXT); | ||
// Shortname is only editable when user is creating a license. | ||
if ($this->action != manager::ACTION_CREATE) { | ||
$mform->freeze('shortname'); | ||
} else { | ||
$mform->addRule('shortname', get_string('shortnamerequirederror', 'tool_licensemanager'), 'required'); | ||
} | ||
|
||
$mform->addElement('text', 'fullname', get_string('fullname', 'tool_licensemanager')); | ||
$mform->setType('fullname', PARAM_TEXT); | ||
$mform->addRule('fullname', get_string('fullnamerequirederror', 'tool_licensemanager'), 'required'); | ||
|
||
$mform->addElement('text', 'source', get_string('source', 'tool_licensemanager')); | ||
$mform->setType('source', PARAM_URL); | ||
$mform->addHelpButton('source', 'source', 'tool_licensemanager'); | ||
$mform->addRule('source', get_string('sourcerequirederror', 'tool_licensemanager'), 'required'); | ||
|
||
$mform->addElement('date_selector', 'version', get_string('version', 'tool_licensemanager'), get_string('from')); | ||
$mform->addHelpButton('version', 'version', 'tool_licensemanager'); | ||
|
||
$this->add_action_buttons(); | ||
} | ||
|
||
/** | ||
* Validate form data and return errors (if any). | ||
* | ||
* @param array $data array of ("fieldname"=>value) of submitted data | ||
* @param array $files array of uploaded files "element_name"=>tmp_file_path | ||
* @return array of "element_name"=>"error_description" if there are errors, | ||
* or an empty array if everything is OK (true allowed for backwards compatibility too). | ||
*/ | ||
public function validation($data, $files) { | ||
$errors = parent::validation($data, $files); | ||
|
||
if (array_key_exists('source', $data) && !filter_var($data['source'], FILTER_VALIDATE_URL)) { | ||
$errors['source'] = get_string('invalidurl', 'tool_licensemanager'); | ||
} | ||
|
||
if (array_key_exists('version', $data) && $data['version'] > time()) { | ||
$errors['version'] = get_string('versioncannotbefuture', 'tool_licensemanager'); | ||
} | ||
|
||
return $errors; | ||
} | ||
} |
Oops, something went wrong.