Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate legacy libphp callbacks to hooks #136

Merged
merged 11 commits into from
Aug 7, 2024
1 change: 1 addition & 0 deletions .reboot-server
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
reboot
1 change: 1 addition & 0 deletions .shutdown-server
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shutdown
7 changes: 7 additions & 0 deletions .wifisettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
channel=11
country=CH
password=moodlebox
ssid=4d6f6f646c65426f78
ssidhiddenstate=
passwordprotected=1
ipaddress=192.168.14.1
Empty file modified bin/changepassword.sh
100755 → 100644
Empty file.
Empty file modified bin/changewifisettings.py
100755 → 100644
Empty file.
Empty file modified bin/changewifisettings.sh
100755 → 100644
Empty file.
Empty file modified bin/pijuicestatus.py
100755 → 100644
Empty file.
Empty file modified bin/resizepartition.sh
100755 → 100644
Empty file.
67 changes: 67 additions & 0 deletions classes/form/changepassword_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
// This file is part of Moodle - https://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 tool_moodlebox\form;
use moodleform;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');

/**
* Class changepassword_form
*
* Form class to change MoodleBox password.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class changepassword_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;

$mform->addElement('passwordunmask', 'newpassword1', get_string('newpassword'));
$mform->addRule('newpassword1', get_string('required'), 'required', null, 'client');
$mform->setType('newpassword1', PARAM_RAW_TRIMMED);

$mform->addElement('passwordunmask', 'newpassword2', get_string('newpassword').' ('.get_string('again').')');
$mform->addRule('newpassword2', get_string('required'), 'required', null, 'client');
$mform->setType('newpassword2', PARAM_RAW_TRIMMED);

$this->add_action_buttons(false, get_string('changepassword'));
}

/**
* Validate the form.
*
* @param array $data submitted data
* @param array $files not used
* @return array errors
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);

if ($data['newpassword1'] <> $data['newpassword2']) {
$errors['newpassword1'] = get_string('passwordsdiffer');
$errors['newpassword2'] = get_string('passwordsdiffer');
}

return $errors;
}
}
50 changes: 50 additions & 0 deletions classes/form/datetimeset_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
// This file is part of Moodle - https://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 tool_moodlebox\form;
use moodleform;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');

/**
* Class datetimeset_form
*
* Form class to set time and date.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class datetimeset_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$mform->addElement('date_time_selector', 'currentdatetime', get_string('datetime', 'tool_moodlebox'),
[
'startyear' => date("Y") - 2,
'stopyear' => date("Y") + 2,
'timezone' => 99,
'step' => 1,
'optional' => true,
]);
$mform->addHelpButton('currentdatetime', 'datetime', 'tool_moodlebox');

$this->add_action_buttons(false, get_string('datetimeset', 'tool_moodlebox'));
}
}
44 changes: 44 additions & 0 deletions classes/form/resizepartition_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
// This file is part of Moodle - https://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 tool_moodlebox\form;
use moodleform;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');

/**
* Class resizepartition_form
*
* Form class to resize the partition of the MoodleBox.
*
* @package tool_moodlebox
* @copyright 2018 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resizepartition_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$buttonarray = [];
$buttonarray[] = & $mform->createElement('submit', 'resizepartitionbutton',
get_string('resizepartition', 'tool_moodlebox'));
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
$mform->closeHeaderBefore('buttonar');
}
}
46 changes: 46 additions & 0 deletions classes/form/restartshutdown_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - https://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 tool_moodlebox\form;
use moodleform;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');

/**
* Class restartshutdown_form
*
* Form class to restart and shutdown the MoodleBox.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restartshutdown_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$buttonarray = [];
$buttonarray[] = & $mform->createElement('submit', 'restartbutton',
get_string('restart', 'tool_moodlebox'));
$buttonarray[] = & $mform->createElement('submit', 'shutdownbutton',
get_string('shutdown', 'tool_moodlebox'));
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
$mform->closeHeaderBefore('buttonar');
}
}
140 changes: 3 additions & 137 deletions forms.php → classes/form/wifisettings_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,94 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* MoodleBox dashboard form definition.
*
* @package tool_moodlebox
* @copyright 2018 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_moodlebox\form;
use moodleform;
defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/lib/formslib.php');

/**
* Class datetimeset_form
*
* Form class to set time and date.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class datetimeset_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$mform->addElement('date_time_selector', 'currentdatetime', get_string('datetime', 'tool_moodlebox'),
[
'startyear' => date("Y") - 2,
'stopyear' => date("Y") + 2,
'timezone' => 99,
'step' => 1,
'optional' => true,
]);
$mform->addHelpButton('currentdatetime', 'datetime', 'tool_moodlebox');

$this->add_action_buttons(false, get_string('datetimeset', 'tool_moodlebox'));
}
}

/**
* Class changepassword_form
*
* Form class to change MoodleBox password.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class changepassword_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;

$mform->addElement('passwordunmask', 'newpassword1', get_string('newpassword'));
$mform->addRule('newpassword1', get_string('required'), 'required', null, 'client');
$mform->setType('newpassword1', PARAM_RAW_TRIMMED);

$mform->addElement('passwordunmask', 'newpassword2', get_string('newpassword').' ('.get_string('again').')');
$mform->addRule('newpassword2', get_string('required'), 'required', null, 'client');
$mform->setType('newpassword2', PARAM_RAW_TRIMMED);

$this->add_action_buttons(false, get_string('changepassword'));
}

/**
* Validate the form.
*
* @param array $data submitted data
* @param array $files not used
* @return array errors
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);

if ($data['newpassword1'] <> $data['newpassword2']) {
$errors['newpassword1'] = get_string('passwordsdiffer');
$errors['newpassword2'] = get_string('passwordsdiffer');
}

return $errors;
}
}
require_once($CFG->libdir . '/formslib.php');

/**
* Class wifisettings_form
Expand Down Expand Up @@ -216,53 +132,3 @@ public function validation($data, $files) {
return $errors;
}
}

/**
* Class resizepartition_form
*
* Form class to resize the partition of the MoodleBox.
*
* @package tool_moodlebox
* @copyright 2018 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resizepartition_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$buttonarray = [];
$buttonarray[] = & $mform->createElement('submit', 'resizepartitionbutton',
get_string('resizepartition', 'tool_moodlebox'));
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
$mform->closeHeaderBefore('buttonar');
}
}

/**
* Class restartshutdown_form
*
* Form class to restart and shutdown the MoodleBox.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 w later
*/
class restartshutdown_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$buttonarray = [];
$buttonarray[] = & $mform->createElement('submit', 'restartbutton',
get_string('restart', 'tool_moodlebox'));
$buttonarray[] = & $mform->createElement('submit', 'shutdownbutton',
get_string('shutdown', 'tool_moodlebox'));
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
$mform->closeHeaderBefore('buttonar');
}
}
Loading
Loading