From 25db4667b44f87378a99a43db71c1de4fee2c4c1 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Thu, 23 May 2024 15:26:09 -0700 Subject: [PATCH 01/46] add PHP code sniffer config file. --- .phpcs.xml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .phpcs.xml diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..a730760 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,4 @@ + + + + From 73c1a01d66faa4bc10feca836100ec3be753af9f Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Thu, 23 May 2024 15:26:41 -0700 Subject: [PATCH 02/46] rigs up CI pipeline via GH Actions. --- .github/workflows/ci.yml | 109 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0768493 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,109 @@ +name: Moodle Plugin CI + +on: + push: + pull_request: + schedule: + - cron: '33 2 * * 1' # weekly, on Monday morning + +jobs: + test: + runs-on: ubuntu-latest + + services: + mariadb: + image: mariadb:10 + env: + MYSQL_USER: 'root' + MYSQL_ALLOW_EMPTY_PASSWORD: "true" + MYSQL_CHARACTER_SET_SERVER: "utf8mb4" + MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci" + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 + + strategy: + fail-fast: false + matrix: + include: + - php: '8.2' + moodle-branch: 'main' + database: 'mariadb' + - php: '8.2' + moodle-branch: 'MOODLE_403_STABLE' + database: 'mariadb' + steps: + - name: Check out repository code + uses: actions/checkout@v3 + with: + path: plugin + + - name: Setup PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: ${{ matrix.extensions }} + ini-values: max_input_vars=5000 + # If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug". + # If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems). + coverage: none + + - name: Initialise moodle-plugin-ci + run: | + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 + echo $(cd ci/bin; pwd) >> $GITHUB_PATH + echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH + sudo locale-gen en_AU.UTF-8 + echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV + + - name: Install moodle-plugin-ci + run: | + moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 + env: + DB: ${{ matrix.database }} + MOODLE_BRANCH: ${{ matrix.moodle-branch }} + + - name: PHP Lint + if: ${{ !cancelled() }} + run: moodle-plugin-ci phplint + + - name: PHP Mess Detector + continue-on-error: true # This step will show errors but will not fail + if: ${{ !cancelled() }} + run: moodle-plugin-ci phpmd + + - name: Moodle Code Checker + if: ${{ !cancelled() }} + run: moodle-plugin-ci phpcs --max-warnings 0 + + - name: Moodle PHPDoc Checker + if: ${{ !cancelled() }} + run: moodle-plugin-ci phpdoc --max-warnings 0 + + - name: Validating + if: ${{ !cancelled() }} + run: moodle-plugin-ci validate + + - name: Check upgrade savepoints + if: ${{ !cancelled() }} + run: moodle-plugin-ci savepoints + + - name: Mustache Lint + if: ${{ !cancelled() }} + run: moodle-plugin-ci mustache + + - name: Grunt + if: ${{ !cancelled() }} + run: moodle-plugin-ci grunt --max-lint-warnings 0 + + - name: PHPUnit tests + if: ${{ !cancelled() }} + run: moodle-plugin-ci phpunit --fail-on-warning + + - name: Behat features + if: ${{ !cancelled() }} + run: moodle-plugin-ci behat --profile chrome + + - name: Mark cancelled jobs as failed. + if: ${{ cancelled() }} + run: exit 1 \ No newline at end of file From 50f4e8b10087df9d5e65dedc002e4e7079760d1b Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Thu, 23 May 2024 15:43:01 -0700 Subject: [PATCH 03/46] auto-fix PHP code linter errors. --- admin_email.php | 170 ++++---- admin_email_form.php | 20 +- alt_form.php | 22 +- alt_lib.php | 136 ++++--- alternate.php | 4 +- .../backup_quickmail_block_task.class.php | 24 +- backup/moodle2/backup_quickmail_stepslib.php | 56 +-- .../restore_quickmail_block_task.class.php | 64 +-- backup/moodle2/restore_quickmail_stepslib.php | 50 +-- block_quickmail.php | 102 +++-- classes/event/alternate_email_added.php | 26 +- classes/message.php | 109 +++--- config_qm.php | 14 +- config_qm_form.php | 55 ++- db/access.php | 72 ++-- db/upgrade.php | 89 +++-- db/upgradelib.php | 80 ++-- email.php | 209 ++++++---- email_form.php | 219 ++++++----- emaillog.php | 89 ++--- lang/en/block_quickmail.php | 6 +- lang/en_us/block_quickmail.php | 8 +- lang/sv/block_quickmail.php | 2 +- lib.php | 366 +++++++++--------- settings.php | 84 ++-- signature.php | 90 +++-- signature_form.php | 33 +- 27 files changed, 1207 insertions(+), 992 deletions(-) diff --git a/admin_email.php b/admin_email.php index 2c10043..2ab8afc 100644 --- a/admin_email.php +++ b/admin_email.php @@ -46,32 +46,32 @@ $context = context_system::instance(); -if(has_capability('block/quickmail:myaddinstance', $context) || is_siteadmin($USER)) { +if (has_capability('block/quickmail:myaddinstance', $context) || is_siteadmin($USER)) { // page params for ui filter - $filterparams = $typeid > 0 ? array('courseid'=>$courseid, 'type'=>$type, 'typeid'=>$typeid) : null; + $filterparams = $typeid > 0 ? ['courseid' => $courseid, 'type' => $type, 'typeid' => $typeid] : null; $PAGE->set_context($context); $PAGE->set_url($CFG->wwwroot . '/blocks/quickmail/admin_email.php'); $PAGE->navbar->add($blockname); $PAGE->navbar->add($header); - $PAGE->set_heading($SITE->shortname.': '.$blockname); + $PAGE->set_heading($SITE->shortname . ': ' . $blockname); $PAGE->set_pagetype(quickmail::PAGE_TYPE); $PAGE->set_pagelayout('standard'); - if($type == 'log'){ - $log_message = $DB->get_record('block_quickmail_' . $type, array('id' => $typeid)); + if ($type == 'log') { + $logmessage = $DB->get_record('block_quickmail_' . $type, ['id' => $typeid]); // try to get the saved, serialized filters from mailto. - if(isset($log_message->mailto)) { + if (isset($logmessage->mailto)) { // will give a Notice if content of mailto in not unserializable. - $filters = @unserialize($log_message->mailto); - if ( $filters !== false && is_array($filters) && ( empty($_POST['addfilter']) && empty($_POST['removeselected']) ) ){ + $filters = @unserialize($logmessage->mailto); + if ($filters !== false && is_array($filters) && ( empty($_POST['addfilter']) && empty($_POST['removeselected']) )) { $SESSION->user_filtering = $filters; } } } // Get Our users - $fields = array( + $fields = [ 'realname' => 1, 'lastname' => 1, 'firstname' => 1, @@ -96,37 +96,67 @@ 'firstnamephonetic' => 1, 'lastnamephonetic' => 1, 'middlename' => 1, - 'alternatename' => 1 - ); + 'alternatename' => 1, + ]; $ufiltering = new user_filtering($fields, null, $filterparams); - list($sql, $params) = $ufiltering->get_sql_filter(); - $usersearchcount = get_users(false, '', true, null, '', '', '', '', '', - '*', $sql, $params); + [$sql, $params] = $ufiltering->get_sql_filter(); + $usersearchcount = get_users( + false, + '', + true, + null, + '', + '', + '', + '', + '', + '*', + $sql, + $params + ); - if($fmid == 1){ - $sql = 'id IN (' . $log_message->failuserids . ')'; + if ($fmid == 1) { + $sql = 'id IN (' . $logmessage->failuserids . ')'; } - $display_users = empty($sql) ? array() : - get_users_listing($sort, $direction, $page*$perpage, - $perpage, '', '', '', $sql, $params); + $displayusers = empty($sql) ? [] : + get_users_listing( + $sort, + $direction, + $page * $perpage, + $perpage, + '', + '', + '', + $sql, + $params + ); - $users = empty($sql) ? array() : - get_users_listing($sort, $direction, 0, - 0, '', '', '', $sql, $params); + $users = empty($sql) ? [] : + get_users_listing( + $sort, + $direction, + 0, + 0, + '', + '', + '', + $sql, + $params + ); - $editor_options = array( + $editoroptions = [ 'trusttext' => true, 'subdirs' => 1, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'accepted_types' => '*', - 'context' => $context - ); + 'context' => $context, + ]; - $form = new admin_email_form(null, array( - 'editor_options' => $editor_options - )); + $form = new admin_email_form(null, [ + 'editor_options' => $editoroptions, + ]); // Process data submission if ($form->is_cancelled()) { @@ -147,20 +177,19 @@ // save record of the message, regardless of errors. $data->id = $DB->insert_record('block_quickmail_log', $data); // Send the messages and save the failed users if there are any - $data->failuserids = implode(',',$message->send()); + $data->failuserids = implode(',', $message->send()); $message->sendAdminReceipt(); // Finished processing // Empty errors mean that you can go back home - if(empty($message->warnings)) { + if (empty($message->warnings)) { unset($SESSION->user_filtering); - if(is_siteadmin($USER->id)) { - redirect(new moodle_url('/blocks/quickmail/emaillog.php', array('courseid' => $COURSE->id))); + if (is_siteadmin($USER->id)) { + redirect(new moodle_url('/blocks/quickmail/emaillog.php', ['courseid' => $COURSE->id])); } else { - redirect(new moodle_url('/my', NULL)); + redirect(new moodle_url('/my', null)); } - } - else{ + } else { // update DB to reflect fail status. $data->status = quickmail::_s('failed_to_send_to') + count($message->warnings) + quickmail::_s('users'); $DB->update_record('block_quickmail_log', $data); @@ -168,14 +197,20 @@ } // get data for form - if(!empty($type)) { - $data = $log_message; - $log_message->messageformat = $USER->mailformat; - $log_message = file_prepare_standard_editor( - $log_message, 'message', $editor_options, $context, 'block_quickmail', $type, $log_message->id + if (!empty($type)) { + $data = $logmessage; + $logmessage->messageformat = $USER->mailformat; + $logmessage = file_prepare_standard_editor( + $logmessage, + 'message', + $editoroptions, + $context, + 'block_quickmail', + $type, + $logmessage->id ); - }else{ - $log_message = new stdClass(); + } else { + $logmessage = new stdClass(); } // begin output. @@ -183,60 +218,63 @@ echo $OUTPUT->heading($header); // Notify the admin. - if(!empty($message->warnings)) { - foreach($message->warnings as $warning) { + if (!empty($message->warnings)) { + foreach ($message->warnings as $warning) { echo $OUTPUT->notification($warning); } } - // Start work - if($fmid != 1){ + // Start work + if ($fmid != 1) { $ufiltering->display_add(); $ufiltering->display_active(); } - $paging_bar = !$sql ? '' : - $OUTPUT->paging_bar($usersearchcount, $page, $perpage, - new moodle_url('/blocks/quickmail/admin_email.php', array( + $pagingbar = !$sql ? '' : + $OUTPUT->paging_bar( + $usersearchcount, + $page, + $perpage, + new moodle_url('/blocks/quickmail/admin_email.php', [ 'sort' => $sort, 'dir' => $direction, - 'perpage' => $perpage - ) - )); + 'perpage' => $perpage, + ]) + ); - if(!empty($sql)) { + if (!empty($sql)) { echo $OUTPUT->heading("Found $usersearchcount User(s)"); } - echo $paging_bar; + echo $pagingbar; - if(!empty($display_users)) { - $columns = array('firstname', 'lastname', 'email', 'city', 'lastaccess'); - foreach($columns as $column) { + if (!empty($displayusers)) { + $columns = ['firstname', 'lastname', 'email', 'city', 'lastaccess']; + foreach ($columns as $column) { $direction = ($sort == $column and $direction == "ASC") ? "DESC" : "ASC"; - $$column = html_writer::link('admin_email.php?sort='.$column.'&dir='. + $$column = html_writer::link('admin_email.php?sort=' . $column . '&dir=' . $direction, get_string($column)); } $table = new html_table(); - $table->head = array("$firstname / $lastname", $email, $city, $lastaccess); - $table->data = array_map(function($user) { + $table->head = ["$firstname / $lastname", $email, $city, $lastaccess]; + $table->data = array_map(function ($user) { $fullname = fullname($user); $email = $user->email; $city = $user->city; - $lastaccess_time = isset($user->lastaccess) ? + $lastaccesstime = isset($user->lastaccess) ? format_time(time() - $user->lastaccess) : get_string('never'); - return array($fullname, $email, $city, $lastaccess_time); - }, $display_users); + return [$fullname, $email, $city, $lastaccesstime]; + }, $displayusers); echo html_writer::table($table); } // need no-reply in both cases. - $log_message->noreply = $CFG->noreplyaddress; + $logmessage->noreply = $CFG->noreplyaddress; // display form and done. - $form->set_data($log_message); + $form->set_data($logmessage); echo $form->display(); - echo $paging_bar; + echo $pagingbar; echo $OUTPUT->footer(); } diff --git a/admin_email_form.php b/admin_email_form.php index c784d67..bfdb068 100644 --- a/admin_email_form.php +++ b/admin_email_form.php @@ -24,25 +24,24 @@ require_once $CFG->libdir . '/formslib.php'; // describe the form created for admin_emial.php class admin_email_form extends moodleform { - function definition() { $mform =& $this->_form; $mform->addElement('text', 'subject', get_string('subject', 'block_quickmail')); $mform->setType('subject', PARAM_TEXT); - + $mform->addElement('text', 'noreply', get_string('noreply', 'block_quickmail')); $mform->setType('noreply', PARAM_EMAIL); - $mform->addElement('editor', 'message_editor', get_string('body', 'block_quickmail'), null, $this->_customdata['editor_options']); + $mform->addElement('editor', 'message_editor', get_string('body', 'block_quickmail'), null, $this->_customdata['editor_options']); $mform->setType('message', PARAM_RAW); - $buttons = array( + $buttons = [ $mform->createElement('submit', 'send', get_string('send_email', 'block_quickmail')), - $mform->createElement('cancel', 'cancel', get_string('cancel')) - ); - $mform->addGroup($buttons, 'actions', ' ', array(' '), false); + $mform->createElement('cancel', 'cancel', get_string('cancel')), + ]; + $mform->addGroup($buttons, 'actions', ' ', [' '], false); $mform->addRule('subject', null, 'required', 'client'); $mform->addRule('noreply', null, 'required', 'client'); @@ -50,10 +49,11 @@ function definition() { } function validation($data, $files) { - $errors = array(); - foreach(array('subject', 'message_editor') as $field) { - if(empty($data[$field])) + $errors = []; + foreach (['subject', 'message_editor'] as $field) { + if (empty($data[$field])) { $errors[$field] = get_string('email_error_field', 'block_quickmail', $field); + } } return $errors; } diff --git a/alt_form.php b/alt_form.php index da46a7f..3e2ae96 100644 --- a/alt_form.php +++ b/alt_form.php @@ -35,23 +35,23 @@ function definition() { $m->addRule('address', get_string('missingemail'), 'required', null, 'server'); $m->addElement('hidden', 'valid', 0); - $m->setType('valid',PARAM_INT); - + $m->setType('valid', PARAM_INT); + $m->addElement('hidden', 'courseid', $course->id); - $m->setType('courseid',PARAM_INT); - + $m->setType('courseid', PARAM_INT); + $m->addElement('hidden', 'id', ''); - $m->setType('id',PARAM_INT); - + $m->setType('id', PARAM_INT); + $m->addElement('hidden', 'action', $this->_customdata['action']); - $m->setType('action',PARAM_ALPHA); + $m->setType('action', PARAM_ALPHA); - $buttons = array( + $buttons = [ $m->createElement('submit', 'submit', get_string('savechanges')), - $m->createElement('cancel') - ); + $m->createElement('cancel'), + ]; - $m->addGroup($buttons, 'buttons', '', array(' '), false); + $m->addGroup($buttons, 'buttons', '', [' '], false); $m->closeHeaderBefore('buttons'); } diff --git a/alt_lib.php b/alt_lib.php index 6e28c9a..3820ef2 100644 --- a/alt_lib.php +++ b/alt_lib.php @@ -31,23 +31,22 @@ interface quickmail_alternate_actions { } abstract class quickmail_alternate implements quickmail_alternate_actions { - - private static function base_url($courseid, $additional= array()) { - $params = array('courseid' => $courseid) + $additional; + private static function base_url($courseid, $additional = []) { + $params = ['courseid' => $courseid] + $additional; return new moodle_url('/blocks/quickmail/alternate.php', $params); } public static function get($course) { global $DB; - $params = array('courseid' => $course->id); + $params = ['courseid' => $course->id]; return $DB->get_records('block_quickmail_alternate', $params, 'valid DESC'); } public static function get_one($id) { global $DB; - $params = array('id' => $id); + $params = ['id' => $id]; return $DB->get_record('block_quickmail_alternate', $params, '*', MUST_EXIST); } @@ -56,21 +55,21 @@ public static function delete($course, $id) { $email = self::get_one($id); - $confirm_url = self::base_url($course->id, array( - 'id' => $email->id, 'action' => self::CONFIRMED - )); + $confirmurl = self::base_url($course->id, [ + 'id' => $email->id, 'action' => self::CONFIRMED, + ]); - $cancel_url = self::base_url($course->id); + $cancelurl = self::base_url($course->id); - return $OUTPUT->confirm(quickmail::_s('sure', $email), $confirm_url, $cancel_url); + return $OUTPUT->confirm(quickmail::_s('sure', $email), $confirmurl, $cancelurl); } public static function confirmed($course, $id) { global $DB; - $DB->delete_records('block_quickmail_alternate', array('id' => $id)); + $DB->delete_records('block_quickmail_alternate', ['id' => $id]); - return redirect(self::base_url($course->id, array('flash' => 1))); + return redirect(self::base_url($course->id, ['flash' => 1])); } public static function verify($course, $id) { @@ -81,25 +80,25 @@ public static function verify($course, $id) { $value = optional_param('key', null, PARAM_TEXT); $userid = optional_param('activator', null, PARAM_INT); - $params = array( + $params = [ 'instance' => $course->id, 'value' => $value, 'userid' => $userid, - 'script' => 'blocks/quickmail' - ); + 'script' => 'blocks/quickmail', + ]; - $back_url = self::base_url($course->id); + $backurl = self::base_url($course->id); // Pass through already valid entries if ($entry->valid) { - redirect($back_url); + redirect($backurl); } // Verify key if (empty($value) or !$key = $DB->get_record('user_private_key', $params)) { - $reactivate = self::base_url($course->id, array( - 'id' => $id, 'action' => self::INFORMATION - )); + $reactivate = self::base_url($course->id, [ + 'id' => $id, 'action' => self::INFORMATION, + ]); $html = $OUTPUT->notification(quickmail::_s('entry_key_not_valid', $entry)); $html .= $OUTPUT->continue_button($reactivate); @@ -115,7 +114,7 @@ public static function verify($course, $id) { $entry->course = $course->fullname; $html = $OUTPUT->notification(quickmail::_s('entry_activated', $entry), 'notifysuccess'); - $html .= $OUTPUT->continue_button($back_url); + $html .= $OUTPUT->continue_button($backurl); return $html; } @@ -131,21 +130,21 @@ public static function inform($course, $id) { $url = self::base_url($course->id); - $approval_url = self::base_url($course->id, array( + $approvalurl = self::base_url($course->id, [ 'id' => $id, 'action' => self::VERIFY, - 'activator' => $USER->id, 'key' => $value - )); + 'activator' => $USER->id, 'key' => $value, + ]); - $a = new stdClass; + $a = new stdClass(); $a->address = $entry->address; - $a->url = html_writer::link($approval_url, $approval_url->out()); + $a->url = html_writer::link($approvalurl, $approvalurl->out()); $a->course = $course->fullname; $a->fullname = fullname($USER); $from = quickmail::_s('alternate_from'); $subject = quickmail::_s('alternate_subject'); - $html_body = quickmail::_s('alternate_body', $a); - $body = strip_tags($html_body); + $htmlbody = quickmail::_s('alternate_body', $a); + $body = strip_tags($htmlbody); // Send email $user = clone($USER); @@ -153,16 +152,16 @@ public static function inform($course, $id) { $user->firstname = quickmail::_s('pluginname'); $user->lastname = quickmail::_s('alternate'); - $result = email_to_user($user, $from, $subject, $body, $html_body); + $result = email_to_user($user, $from, $subject, $body, $htmlbody); // Create the event, trigger it. - $event = \block_quickmail\event\alternate_email_added::create(array( + $event = \block_quickmail\event\alternate_email_added::create([ 'courseid' => $course->id, 'context' => context_course::instance($course->id), - 'other' => array( - 'address'=> $entry->address - ) - )); + 'other' => [ + 'address' => $entry->address, + ], + ]); $event->trigger(); $html = $OUTPUT->box_start(); @@ -181,9 +180,9 @@ public static function inform($course, $id) { } public static function interact($course, $id) { - $form = new quickmail_alternate_form(null, array( - 'course' => $course, 'action' => self::INTERACT - )); + $form = new quickmail_alternate_form(null, [ + 'course' => $course, 'action' => self::INTERACT, + ]); if ($form->is_cancelled()) { redirect(self::base_url($course->id)); @@ -191,9 +190,9 @@ public static function interact($course, $id) { global $DB; // Check if email exists in this course - $older = $DB->get_record('block_quickmail_alternate', array( - 'address' => $data->address, 'courseid' => $data->courseid - )); + $older = $DB->get_record('block_quickmail_alternate', [ + 'address' => $data->address, 'courseid' => $data->courseid, + ]); if ($older) { $data->id = $older->id; @@ -216,9 +215,9 @@ public static function interact($course, $id) { $action = $data->valid ? self::VERIFY : self::INFORMATION; - redirect(self::base_url($course->id, array( - 'action' => $action, 'id' => $data->id - ))); + redirect(self::base_url($course->id, [ + 'action' => $action, 'id' => $data->id, + ])); } if ($id) { @@ -227,10 +226,10 @@ public static function interact($course, $id) { // MDL-31677 $reflect = new ReflectionClass('quickmail_alternate_form'); - $form_field = $reflect->getProperty('_form'); - $form_field->setAccessible(true); + $formfield = $reflect->getProperty('_form'); + $formfield->setAccessible(true); - return $form_field->getValue($form)->toHtml(); + return $formfield->getValue($form)->toHtml(); } public static function view($course) { @@ -238,54 +237,53 @@ public static function view($course) { $alternates = self::get($course); - $new_url = self::base_url($course->id, array('action' => self::INTERACT)); + $newurl = self::base_url($course->id, ['action' => self::INTERACT]); if (empty($alternates)) { - $html = $OUTPUT->notification(quickmail::_s('no_alternates', $course)); - $html .= $OUTPUT->continue_button($new_url); + $html .= $OUTPUT->continue_button($newurl); return $html; } $table = new html_table(); - $table->head = array( + $table->head = [ get_string('email'), quickmail::_s('valid'), - get_string('action') - ); + get_string('action'), + ]; - $approval = array(quickmail::_s('waiting'), quickmail::_s('approved')); + $approval = [quickmail::_s('waiting'), quickmail::_s('approved')]; - $icons = array( + $icons = [ self::INTERACT => $OUTPUT->pix_icon('i/edit', get_string('edit')), - self::DELETE => $OUTPUT->pix_icon('i/invalid', get_string('delete')) - ); + self::DELETE => $OUTPUT->pix_icon('i/invalid', get_string('delete')), + ]; foreach ($alternates as $email) { - $edit_url = self::base_url($course->id, array( - 'action' => self::INTERACT, 'id' => $email->id - )); + $editurl = self::base_url($course->id, [ + 'action' => self::INTERACT, 'id' => $email->id, + ]); - $edit = html_writer::link($edit_url, $icons[self::INTERACT]); + $edit = html_writer::link($editurl, $icons[self::INTERACT]); - $delete_url = self::base_url($course->id, array( - 'action' => self::DELETE, 'id' => $email->id - )); + $deleteurl = self::base_url($course->id, [ + 'action' => self::DELETE, 'id' => $email->id, + ]); - $delete = html_writer::link($delete_url, $icons[self::DELETE]); + $delete = html_writer::link($deleteurl, $icons[self::DELETE]); - $row = array( + $row = [ $email->address, $approval[$email->valid], - implode(' | ', array($edit, $delete)) - ); + implode(' | ', [$edit, $delete]), + ]; $table->data[] = new html_table_row($row); } - $new_link = html_writer::link($new_url, quickmail::_s('alternate_new')); + $newlink = html_writer::link($newurl, quickmail::_s('alternate_new')); - $html = html_writer::tag('div', $new_link, array('class' => 'new_link')); + $html = html_writer::tag('div', $newlink, ['class' => 'new_link']); $html .= $OUTPUT->box_start(); $html .= html_writer::table($table); $html .= $OUTPUT->box_end(); diff --git a/alternate.php b/alternate.php index 30164ce..42beeac 100644 --- a/alternate.php +++ b/alternate.php @@ -31,7 +31,7 @@ $id = optional_param('id', null, PARAM_INT); $flash = optional_param('flash', 0, PARAM_INT); -$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST); $context = context_course::instance($courseid); // Permission @@ -42,7 +42,7 @@ $heading = quickmail::_s('alternate'); $title = "$blockname: $heading"; -$url = new moodle_url('/blocks/quickmail/alternate.php', array('courseid' => $courseid)); +$url = new moodle_url('/blocks/quickmail/alternate.php', ['courseid' => $courseid]); $PAGE->set_url($url); $PAGE->set_context($context); diff --git a/backup/moodle2/backup_quickmail_block_task.class.php b/backup/moodle2/backup_quickmail_block_task.class.php index c437430..018be64 100644 --- a/backup/moodle2/backup_quickmail_block_task.class.php +++ b/backup/moodle2/backup_quickmail_block_task.class.php @@ -25,18 +25,18 @@ class backup_quickmail_block_task extends backup_block_task { protected function define_my_settings() { - $include_history = new backup_generic_setting('include_quickmail_log', base_setting::IS_BOOLEAN, FALSE); - $include_history->get_ui()->set_label(get_string('backup_history', 'block_quickmail')); - $this->add_setting($include_history); + $includehistory = new backup_generic_setting('include_quickmail_log', base_setting::IS_BOOLEAN, false); + $includehistory->get_ui()->set_label(get_string('backup_history', 'block_quickmail')); + $this->add_setting($includehistory); - $this->plan->get_setting('users')->add_dependency($include_history); - $this->plan->get_setting('blocks')->add_dependency($include_history); + $this->plan->get_setting('users')->add_dependency($includehistory); + $this->plan->get_setting('blocks')->add_dependency($includehistory); - $include_config_settings = new backup_generic_setting('include_quickmail_config', base_setting::IS_BOOLEAN, true); - $include_config_settings->get_ui()->set_label(get_string('backup_block_configuration', 'block_quickmail')); - $this->add_setting($include_config_settings); + $includeconfigsettings = new backup_generic_setting('include_quickmail_config', base_setting::IS_BOOLEAN, true); + $includeconfigsettings->get_ui()->set_label(get_string('backup_block_configuration', 'block_quickmail')); + $this->add_setting($includeconfigsettings); - $this->plan->get_setting('blocks')->add_dependency($include_config_settings); + $this->plan->get_setting('blocks')->add_dependency($includeconfigsettings); } protected function define_my_steps() { @@ -45,14 +45,14 @@ protected function define_my_steps() { } public function get_fileareas() { - return array(); + return []; } public function get_configdata_encoded_attributes() { - return array(); + return []; } - static public function encode_content_links($content) { + public static function encode_content_links($content) { // TODO: perhaps needing this when moving away from email zip attaches return $content; } diff --git a/backup/moodle2/backup_quickmail_stepslib.php b/backup/moodle2/backup_quickmail_stepslib.php index 7becaf8..5287102 100644 --- a/backup/moodle2/backup_quickmail_stepslib.php +++ b/backup/moodle2/backup_quickmail_stepslib.php @@ -25,61 +25,63 @@ class backup_quickmail_block_structure_step extends backup_block_structure_step protected function define_structure() { global $DB; - $params = array('courseid' => $this->get_courseid()); - $context = context_course::instance( $params['courseid']); - //LOGS - $quickmail_logs = $DB->get_records('block_quickmail_log', $params); - $include_history = $this->get_setting_value('include_quickmail_log'); + $params = ['courseid' => $this->get_courseid()]; + $context = context_course::instance($params['courseid']); + // LOGS + $quickmaillogs = $DB->get_records('block_quickmail_log', $params); + $includehistory = $this->get_setting_value('include_quickmail_log'); // QM BLOCK CONFIG BACKUP - // attempt to create block settings step for quickmail, so people can restore their quickmail settings + // attempt to create block settings step for quickmail, so people can restore their quickmail settings // WHY IS CONFIGS TABLE SET TO COURSES WITH AN S ID???????? - $paramsTwo = array('coursesid' => $this->get_courseid()); - $quickmail_block_level_settings = $DB->get_records('block_quickmail_config', $paramsTwo); - $include_config = $this->get_setting_value('include_quickmail_config'); + $paramstwo = ['coursesid' => $this->get_courseid()]; + $quickmailblocklevelsettings = $DB->get_records('block_quickmail_config', $paramstwo); + $includeconfig = $this->get_setting_value('include_quickmail_config'); - //LOGS - $backup_logs_and_settings = new backup_nested_element('emaillogs', array('courseid'), null); + // LOGS + $backuplogsandsettings = new backup_nested_element('emaillogs', ['courseid'], null); - $log = new backup_nested_element('log', array('id'), array( + $log = new backup_nested_element('log', ['id'], [ 'userid', 'courseid', 'alternateid', 'mailto', 'subject', - 'message', 'attachment', 'format', 'time','failuserids','additional_emails' - )); + 'message', 'attachment', 'format', 'time', 'failuserids', 'additional_emails', + ]); // courseid name value - $quickmail_settings = new backup_nested_element('block_level_setting', array('id'), array( - 'courseid', 'name', 'value' - )); + $quickmailsettings = new backup_nested_element('block_level_setting', ['id'], [ + 'courseid', 'name', 'value', + ]); - $backup_logs_and_settings->add_child($log); + $backuplogsandsettings->add_child($log); - $backup_logs_and_settings->add_child($quickmail_settings); + $backuplogsandsettings->add_child($quickmailsettings); - $backup_logs_and_settings->set_source_array(array((object)$params)); + $backuplogsandsettings->set_source_array([(object)$params]); - if (!empty($quickmail_logs) and $include_history) { + if (!empty($quickmaillogs) and $includehistory) { $log->set_source_sql( 'SELECT * FROM {block_quickmail_log} - WHERE courseid = ?', array(array('sqlparam' => $this->get_courseid())) + WHERE courseid = ?', + [['sqlparam' => $this->get_courseid()]] ); } - if (!empty($quickmail_block_level_settings) and $include_config) { - $quickmail_settings->set_source_sql( + if (!empty($quickmailblocklevelsettings) and $includeconfig) { + $quickmailsettings->set_source_sql( 'SELECT * FROM {block_quickmail_config} - WHERE coursesid = ?', array(array('sqlparam' => $this->get_courseid())) + WHERE coursesid = ?', + [['sqlparam' => $this->get_courseid()]] ); } $log->annotate_ids('user', 'userid'); - //$quickmail_settings->annotate_ids('setting'); + // $quickmail_settings->annotate_ids('setting'); $log->annotate_files('block_quickmail', 'log', 'id', $context->id); $log->annotate_files('block_quickmail', 'attachment_log', 'id', $context->id); // $quickmail_settings->annotate_files('block_quickmail', 'settings', 'courseid', $context->id); - return $this->prepare_block_structure($backup_logs_and_settings); + return $this->prepare_block_structure($backuplogsandsettings); } } diff --git a/backup/moodle2/restore_quickmail_block_task.class.php b/backup/moodle2/restore_quickmail_block_task.class.php index 2ba1d61..6d82097 100644 --- a/backup/moodle2/restore_quickmail_block_task.class.php +++ b/backup/moodle2/restore_quickmail_block_task.class.php @@ -51,70 +51,74 @@ protected function define_my_settings() { $defaultvalue = false; $changeable = false; - $is_blocks = isset($rootsettings['blocks']) && $rootsettings['blocks']; - $is_users = isset($rootsettings['users']) && $rootsettings['users']; + $isblocks = isset($rootsettings['blocks']) && $rootsettings['blocks']; + $isusers = isset($rootsettings['users']) && $rootsettings['users']; - if ($is_blocks and $is_users) { + if ($isblocks and $isusers) { $defaultvalue = true; $changeable = true; } - $restore_history = new restore_generic_setting('restore_quickmail_history', - base_setting::IS_BOOLEAN, $defaultvalue); - $restore_history->set_ui(new backup_setting_ui_select( - $restore_history, get_string('restore_history', 'block_quickmail'), - array(1 => get_string('yes'), 0 => get_string('no')) + $restorehistory = new restore_generic_setting( + 'restore_quickmail_history', + base_setting::IS_BOOLEAN, + $defaultvalue + ); + $restorehistory->set_ui(new backup_setting_ui_select( + $restorehistory, + get_string('restore_history', 'block_quickmail'), + [1 => get_string('yes'), 0 => get_string('no')] )); if (!$changeable) { - $restore_history->set_value($defaultvalue); - $restore_history->set_status(backup_setting::LOCKED_BY_CONFIG); - $restore_history->set_visibility(backup_setting::HIDDEN); + $restorehistory->set_value($defaultvalue); + $restorehistory->set_status(backup_setting::LOCKED_BY_CONFIG); + $restorehistory->set_visibility(backup_setting::HIDDEN); } - $this->add_setting($restore_history); - $this->get_setting('users')->add_dependency($restore_history); - $this->get_setting('blocks')->add_dependency($restore_history); + $this->add_setting($restorehistory); + $this->get_setting('users')->add_dependency($restorehistory); + $this->get_setting('blocks')->add_dependency($restorehistory); - $overwrite_history = new restore_course_generic_setting('overwrite_quickmail_history', base_setting::IS_BOOLEAN, false); - $overwrite_history->set_ui(new backup_setting_ui_select( - $overwrite_history, + $overwritehistory = new restore_course_generic_setting('overwrite_quickmail_history', base_setting::IS_BOOLEAN, false); + $overwritehistory->set_ui(new backup_setting_ui_select( + $overwritehistory, get_string('overwrite_history', 'block_quickmail'), - array(1 => get_string('yes'), 0 => get_string('no')) + [1 => get_string('yes'), 0 => get_string('no')] )); if ($this->get_target() != backup::TARGET_CURRENT_DELETING and $this->get_target() != backup::TARGET_EXISTING_DELETING) { - - $overwrite_history->set_value(false); - $overwrite_history->set_status(backup_setting::LOCKED_BY_CONFIG); + $overwritehistory->set_value(false); + $overwritehistory->set_status(backup_setting::LOCKED_BY_CONFIG); } - $this->add_setting($overwrite_history); - $restore_history->add_dependency($overwrite_history); + $this->add_setting($overwritehistory); + $restorehistory->add_dependency($overwritehistory); } protected function define_my_steps() { if ($this->history_exists()) { $this->add_step(new restore_quickmail_log_structure_step( - 'quickmail_structure', 'emaillogs_and_block_configuration.xml' + 'quickmail_structure', + 'emaillogs_and_block_configuration.xml' )); } } public function get_fileareas() { - return array(); + return []; } public function get_configdata_encoded_attributes() { - return array(); + return []; } - static public function define_decode_contents() { + public static function define_decode_contents() { // TODO: perhaps needing this when moving away from email zip attaches - return array(); + return []; } - static public function define_decode_rules() { - return array(); + public static function define_decode_rules() { + return []; } } diff --git a/backup/moodle2/restore_quickmail_stepslib.php b/backup/moodle2/restore_quickmail_stepslib.php index 7eeef66..1655e51 100644 --- a/backup/moodle2/restore_quickmail_stepslib.php +++ b/backup/moodle2/restore_quickmail_stepslib.php @@ -23,7 +23,7 @@ class restore_quickmail_log_structure_step extends restore_structure_step { protected function define_structure() { - $paths = array(); + $paths = []; $paths[] = new restore_path_element('block', '/block', true); $paths[] = new restore_path_element('log', '/block/emaillogs/log'); @@ -42,44 +42,44 @@ protected function process_block($data) { // Delete current history, if any if ($overwrite) { - $params = array('courseid' => $this->get_courseid()); + $params = ['courseid' => $this->get_courseid()]; $DB->delete_records('block_quickmail_log', $params); } if ($restore and isset($data->emaillogs['log'])) { global $DB; - $current_context = context_course::instance($this->get_courseid()); + $currentcontext = context_course::instance($this->get_courseid()); - $params = array( + $params = [ 'backupid' => $this->get_restoreid(), 'itemname' => 'context', - 'newitemid' => $current_context->id - ); + 'newitemid' => $currentcontext->id, + ]; $id = $DB->get_record('backup_ids_temp', $params)->itemid; foreach ($data->emaillogs['log'] as $log) { - $this->process_log($log, $id, $current_context); + $this->process_log($log, $id, $currentcontext); } } - if(isset($data->emaillogs['block_level_setting'])){ - foreach ($data->emaillogs['block_level_setting'] as $block_level_setting) { - $this->process_block_level_setting($block_level_setting, $this->get_courseid()); + if (isset($data->emaillogs['block_level_setting'])) { + foreach ($data->emaillogs['block_level_setting'] as $blocklevelsetting) { + $this->process_block_level_setting($blocklevelsetting, $this->get_courseid()); } } } - protected function process_block_level_setting($block_level_setting, $courseid) { + protected function process_block_level_setting($blocklevelsetting, $courseid) { global $DB; - if($block_level_setting['name']){ - //quickmail::default_config($courseid); - $config = new stdClass; + if ($blocklevelsetting['name']) { + // quickmail::default_config($courseid); + $config = new stdClass(); $config->coursesid = $courseid; - $config->name = $block_level_setting['name']; - $config->value = $block_level_setting['value']; + $config->name = $blocklevelsetting['name']; + $config->value = $blocklevelsetting['value']; $DB->insert_record('block_quickmail_config', $config); } } @@ -91,7 +91,7 @@ protected function process_log($log, $oldctx, $context) { $oldid = $log->id; $mailedusers = explode(',', $log->mailto); - $validusers = array(); + $validusers = []; foreach ($mailedusers as $userid) { $validusers[] = $this->get_mappingid('user', $userid); @@ -109,18 +109,22 @@ protected function process_log($log, $oldctx, $context) { $this->set_mapping('log', $oldid, $newid); - foreach (array('log', 'attachment_log') as $filearea) { + foreach (['log', 'attachment_log'] as $filearea) { restore_dbops::send_files_to_pool( - $this->get_basepath(), $this->get_restoreid(), - 'block_quickmail', $filearea, $oldctx, $log->userid + $this->get_basepath(), + $this->get_restoreid(), + 'block_quickmail', + $filearea, + $oldctx, + $log->userid ); $sql = 'UPDATE {files} SET itemid = :newid WHERE contextid = :ctxt AND itemid = :oldid'; - $params = array( - 'newid' => $newid, 'oldid' => $oldid, 'ctxt' => $context->id - ); + $params = [ + 'newid' => $newid, 'oldid' => $oldid, 'ctxt' => $context->id, + ]; $DB->execute($sql, $params); } diff --git a/block_quickmail.php b/block_quickmail.php index 77810fb..7f26b06 100644 --- a/block_quickmail.php +++ b/block_quickmail.php @@ -30,10 +30,10 @@ function init() { function applicable_formats() { global $USER; - if(is_siteadmin($USER->id) || has_capability('block/quickmail:myaddinstance', context_system::instance())) { - return array('site' => true, 'my' => true, 'course-view' => true, 'mod-scorm-view' => true); + if (is_siteadmin($USER->id) || has_capability('block/quickmail:myaddinstance', context_system::instance())) { + return ['site' => true, 'my' => true, 'course-view' => true, 'mod-scorm-view' => true]; } else { - return array('site' => false, 'my' => false, 'course-view' => true, 'mod-scorm-view' => true); + return ['site' => false, 'my' => false, 'course-view' => true, 'mod-scorm-view' => true]; } } function has_config() { @@ -46,17 +46,17 @@ function has_config() { function instance_allow_multiple() { return false; } - + function get_content() { global $USER, $CFG, $COURSE, $OUTPUT; - if ($this->content !== NULL) { + if ($this->content !== null) { return $this->content; } - $this->content = new stdClass; - $this->content->items = array(); - $this->content->icons = array(); + $this->content = new stdClass(); + $this->content->items = []; + $this->content->icons = []; $this->content->footer = ''; $context = context_course::instance($COURSE->id); @@ -64,85 +64,83 @@ function get_content() { $config = quickmail::load_config($COURSE->id); $permission = has_capability('block/quickmail:cansend', $context); - $can_send = ($permission or !empty($config['allowstudents'])); + $cansend = ($permission or !empty($config['allowstudents'])); - $icon_class = array('class' => 'icon'); + $iconclass = ['class' => 'icon']; - $cparam = array('courseid' => $COURSE->id); + $cparam = ['courseid' => $COURSE->id]; - if ($can_send && $COURSE->id != SITEID) { - $send_email_str = quickmail::_s('composenew'); - $icon = $OUTPUT->pix_icon('t/email', $send_email_str, 'moodle', $icon_class); - $send_email = html_writer::link( + if ($cansend && $COURSE->id != SITEID) { + $sendemailstr = quickmail::_s('composenew'); + $icon = $OUTPUT->pix_icon('t/email', $sendemailstr, 'moodle', $iconclass); + $sendemail = html_writer::link( new moodle_url('/blocks/quickmail/email.php', $cparam), - $icon.$send_email_str + $icon . $sendemailstr ); - $this->content->items[] = $send_email; + $this->content->items[] = $sendemail; - $signature_str = quickmail::_s('signature'); - $icon = $OUTPUT->pix_icon('i/edit', $signature_str, 'moodle', $icon_class); + $signaturestr = quickmail::_s('signature'); + $icon = $OUTPUT->pix_icon('i/edit', $signaturestr, 'moodle', $iconclass); $signature = html_writer::link( new moodle_url('/blocks/quickmail/signature.php', $cparam), - $icon.$signature_str + $icon . $signaturestr ); $this->content->items[] = $signature; - $draft_params = $cparam + array('type' => 'drafts'); - $drafts_email_str = quickmail::_s('drafts'); - $icon = $OUTPUT->pix_icon('i/settings', $drafts_email_str, 'moodle', $icon_class); + $draftparams = $cparam + ['type' => 'drafts']; + $draftsemailstr = quickmail::_s('drafts'); + $icon = $OUTPUT->pix_icon('i/settings', $draftsemailstr, 'moodle', $iconclass); $drafts = html_writer::link( - new moodle_url('/blocks/quickmail/emaillog.php', $draft_params), - $icon.$drafts_email_str + new moodle_url('/blocks/quickmail/emaillog.php', $draftparams), + $icon . $draftsemailstr ); $this->content->items[] = $drafts; - $history_str = quickmail::_s('history'); - $icon = $OUTPUT->pix_icon('i/settings', $history_str, 'moodle', $icon_class); + $historystr = quickmail::_s('history'); + $icon = $OUTPUT->pix_icon('i/settings', $historystr, 'moodle', $iconclass); $history = html_writer::link( new moodle_url('/blocks/quickmail/emaillog.php', $cparam), - $icon.$history_str + $icon . $historystr ); $this->content->items[] = $history; if (has_capability('block/quickmail:allowalternate', $context)) { - $alt_str = quickmail::_s('alternate'); - $icon = $OUTPUT->pix_icon('i/edit', $alt_str, 'moodle', $icon_class); + $altstr = quickmail::_s('alternate'); + $icon = $OUTPUT->pix_icon('i/edit', $altstr, 'moodle', $iconclass); $alt = html_writer::link( new moodle_url('/blocks/quickmail/alternate.php', $cparam), - $icon.$alt_str + $icon . $altstr ); $this->content->items[] = $alt; } - - if (has_capability('block/quickmail:canconfig', $context)) { - $config_str = quickmail::_s('config'); - $icon = $OUTPUT->pix_icon('i/settings', $config_str, 'moodle', $icon_class); - $config = html_writer::link( - new moodle_url('/blocks/quickmail/config_qm.php', $cparam), - $icon.$config_str - ); - $this->content->items[] = $config; - } - + if (has_capability('block/quickmail:canconfig', $context)) { + $configstr = quickmail::_s('config'); + $icon = $OUTPUT->pix_icon('i/settings', $configstr, 'moodle', $iconclass); + $config = html_writer::link( + new moodle_url('/blocks/quickmail/config_qm.php', $cparam), + $icon . $configstr + ); + $this->content->items[] = $config; + } } - if((has_capability('block/quickmail:myaddinstance', context_system::instance()) || is_siteadmin($USER->id)) && $COURSE->id == SITEID) { - $send_adminemail_str = quickmail::_s('sendadmin'); - $icon = $OUTPUT->pix_icon('t/email', $send_adminemail_str, 'moodle', $icon_class); - $send_adminemail = html_writer::link( + if ((has_capability('block/quickmail:myaddinstance', context_system::instance()) || is_siteadmin($USER->id)) && $COURSE->id == SITEID) { + $sendadminemailstr = quickmail::_s('sendadmin'); + $icon = $OUTPUT->pix_icon('t/email', $sendadminemailstr, 'moodle', $iconclass); + $sendadminemail = html_writer::link( new moodle_url('/blocks/quickmail/admin_email.php'), - $icon.$send_adminemail_str + $icon . $sendadminemailstr ); - $this->content->items[] = $send_adminemail; - } + $this->content->items[] = $sendadminemail; + } if (is_siteadmin($USER->id) && $COURSE->id == SITEID) { - $history_str = quickmail::_s('history'); - $icon = $OUTPUT->pix_icon('i/settings', $history_str, 'moodle', $icon_class); + $historystr = quickmail::_s('history'); + $icon = $OUTPUT->pix_icon('i/settings', $historystr, 'moodle', $iconclass); $history = html_writer::link( new moodle_url('/blocks/quickmail/emaillog.php', $cparam), - $icon.$history_str + $icon . $historystr ); $this->content->items[] = $history; } diff --git a/classes/event/alternate_email_added.php b/classes/event/alternate_email_added.php index ab3b81e..5a576f2 100644 --- a/classes/event/alternate_email_added.php +++ b/classes/event/alternate_email_added.php @@ -34,41 +34,41 @@ protected function init() { /** * Returns name of the event. - * + * * @return string */ public static function get_name() { return get_string('eventalternateemailadded', 'block_quickmail'); } - + /** * Returns info on when a user with ID has viwed a control panel module (tab). - * + * * @return string */ public function get_description() { return "The user with id '{$this->userid}' has added an alternate email " . "{$this->other['address']}."; } - + /** * Returns URL of the event. - * + * * @return \moodle_url */ public function get_url() { - return new \moodle_url('/blocks/quickmail/alternate.php', array( - 'courseid' => $this->courseid - )); + return new \moodle_url('/blocks/quickmail/alternate.php', [ + 'courseid' => $this->courseid, + ]); } - + /** * Legacy log. - * + * * @return array */ public function get_legacy_logdata() { - return array($this->courseid, 'quickmail', 'add', $this->get_url(), - get_string('alternate', 'block_quickmail') . ' ' . $this->other['address']); + return [$this->courseid, 'quickmail', 'add', $this->get_url(), + get_string('alternate', 'block_quickmail') . ' ' . $this->other['address']]; } -} \ No newline at end of file +} diff --git a/classes/message.php b/classes/message.php index c20a82b..0db6369 100644 --- a/classes/message.php +++ b/classes/message.php @@ -21,117 +21,114 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -//library functions for the admin email part of quickmail. +// library functions for the admin email part of quickmail. class Message { - - public $subject, + public $subject, $text, $html, $users, $admins, $warnings, $noreply, - $sentUsers, + $sentusers, $failuserids, - $startTime, - $endTime; - + $starttime, + $endtime; + /* Message constructor * Constructs a message object for mailing to groups filtered by admin_email * @param array $data - an array of variables related to the emailing * @param array $users - an array of users to be emailed * @return void / nothing */ - public function __construct($data, $users){ + public function __construct($data, $users) { global $DB; - $this->warnings = array(); + $this->warnings = []; $this->subject = $data->subject; $this->html = $data->message_editor['text']; $this->text = strip_tags($data->message_editor['text']); $this->noreply = $data->noreply; - $this->warnings = array(); + $this->warnings = []; $this->users = array_values($DB->get_records_list('user', 'id', $users)); - $this->failuserids = array(); + $this->failuserids = []; } - - /* + + /* * sends the message * @params array $users * @return array $this->failuserids; */ - public function send($users = null){ - + public function send($users = null) { + $this->startTime = time(); $users = empty($users) ? $this->users : $users; - $noreplyUser = new stdClass(); - $noreplyUser->firstname = 'Moodle'; - $noreplyUser->lastname = 'Administrator'; - $noreplyUser->username = 'moodleadmin'; - $noreplyUser->email = $this->noreply; - $noreplyUser->maildisplay = 2; - $noreplyUser->alternatename = ""; - $noreplyUser->firstnamephonetic = ""; - $noreplyUser->lastnamephonetic = ""; - $noreplyUser->middlename = ""; - if(empty($users)){ + $noreplyuser = new stdClass(); + $noreplyuser->firstname = 'Moodle'; + $noreplyuser->lastname = 'Administrator'; + $noreplyuser->username = 'moodleadmin'; + $noreplyuser->email = $this->noreply; + $noreplyuser->maildisplay = 2; + $noreplyuser->alternatename = ""; + $noreplyuser->firstnamephonetic = ""; + $noreplyuser->lastnamephonetic = ""; + $noreplyuser->middlename = ""; + if (empty($users)) { $this->warnings[] = get_string('no_users', 'block_quickmail'); } - foreach($users as $user) { + foreach ($users as $user) { $success = email_to_user( - $user, // to - $noreplyUser, // from - $this->subject, // subj - $this->text, // body in plain text - $this->html, // body in HTML - '', // attachment - '', // attachment name - true, // user true address ($USER) - $this->noreply, // reply-to address - get_string('pluginname', 'block_quickmail') // reply-to name - ); - if(!$success){ - + $user, // to + $noreplyuser, // from + $this->subject, // subj + $this->text, // body in plain text + $this->html, // body in HTML + '', // attachment + '', // attachment name + true, // user true address ($USER) + $this->noreply, // reply-to address + get_string('pluginname', 'block_quickmail') // reply-to name + ); + if (!$success) { $this->warnings[] = get_string('email_error', 'block_quickmail', $user); $this->failuserids[] = $user->id; - } - else{ + } else { $this->sentUsers[] = $user->username; } } - + $this->endTime = time(); - + return $this->failuserids; } /* builds a receipt emailed to admin that displays details of the group message * @return string $usersLine.$warnline.$timeLine.$msgLine.$recipLine */ - - public function buildAdminReceipt(){ + + public function buildadminreceipt() { global $CFG, $DB; - $adminIds = explode(',',$CFG->siteadmins); - $this->admins = $DB->get_records_list('user', 'id',$adminIds); + $adminids = explode(',', $CFG->siteadmins); + $this->admins = $DB->get_records_list('user', 'id', $adminids); - $usersLine = quickmail::_s('message_sent_to') . " " . count($this->sentUsers) . " " . quickmail::_s('users') . "
"; - $timeLine = quickmail::_s('time_elapsed') . " " . ($this->endTime - $this->startTime) . " " . quickmail::_s('seconds') . "
"; + $usersline = quickmail::_s('message_sent_to') . " " . count($this->sentUsers) . " " . quickmail::_s('users') . "
"; + $timeline = quickmail::_s('time_elapsed') . " " . ($this->endTime - $this->startTime) . " " . quickmail::_s('seconds') . "
"; $warnline = quickmail::_s('warnings') . " " . count($this->warnings) . "
"; - $msgLine = quickmail::_s('message_body_as_follows') . "


" . $this->html . "
"; - if(count($this->sentUsers) > 0) { - $recipLine = quickmail::_s("sent_successfully_to_the_following_users") . "

" . implode(', ', $this->sentUsers); + $msgline = quickmail::_s('message_body_as_follows') . "


" . $this->html . "
"; + if (count($this->sentUsers) > 0) { + $recipline = quickmail::_s("sent_successfully_to_the_following_users") . "

" . implode(', ', $this->sentUsers); } else { - $recipLine = quickmail::_s('something_broke'); + $recipline = quickmail::_s('something_broke'); } - return $usersLine.$timeLine.$warnline.$msgLine.$recipLine; + return $usersline . $timeline . $warnline . $msgline . $recipline; } /* * sends the admin receipt */ - public function sendAdminReceipt(){ + public function sendadminreceipt() { $this->html = $this->buildAdminReceipt(); $this->text = $this->buildAdminReceipt(); $this->subject = quickmail::_s("admin_email_send_receipt"); diff --git a/config_qm.php b/config_qm.php index d8f37f3..6c550b5 100644 --- a/config_qm.php +++ b/config_qm.php @@ -30,7 +30,7 @@ $courseid = required_param('courseid', PARAM_INT); $reset = optional_param('reset', 0, PARAM_INT); -if (!$course = $DB->get_record('course', array('id' => $courseid))) { +if (!$course = $DB->get_record('course', ['id' => $courseid])) { print_error('no_course', 'block_quickmail', '', $courseid); } @@ -43,9 +43,9 @@ $PAGE->set_context($context); $PAGE->set_course($course); -$PAGE->set_url('/blocks/quickmail/config_qm.php', array('courseid' => $courseid)); -$PAGE->set_title($blockname . ': '. $header); -$PAGE->set_heading($blockname. ': '. $header); +$PAGE->set_url('/blocks/quickmail/config_qm.php', ['courseid' => $courseid]); +$PAGE->set_title($blockname . ': ' . $header); +$PAGE->set_heading($blockname . ': ' . $header); $PAGE->navbar->add($blockname); $PAGE->navbar->add($header); $PAGE->set_pagetype(quickmail::PAGE_TYPE); @@ -60,10 +60,10 @@ $roles = role_fix_names(get_all_roles($context), $context, ROLENAME_ALIAS, true); -$form = new config_form(null, array( +$form = new config_form(null, [ 'courseid' => $courseid, - 'roles' => $roles -)); + 'roles' => $roles, +]); if ($data = $form->get_data()) { $config = get_object_vars($data); diff --git a/config_qm_form.php b/config_qm_form.php index 819c7a4..d9dd647 100644 --- a/config_qm_form.php +++ b/config_qm_form.php @@ -27,45 +27,62 @@ class config_form extends moodleform { public function definition() { $mform =& $this->_form; - $reset_link = html_writer::link( - new moodle_url('/blocks/quickmail/config_qm.php', array( + $resetlink = html_writer::link( + new moodle_url('/blocks/quickmail/config_qm.php', [ 'courseid' => $this->_customdata['courseid'], - 'reset' => 1 - )), quickmail::_s('reset') + 'reset' => 1, + ]), + quickmail::_s('reset') ); - $mform->addElement('static', 'reset', '', $reset_link); + $mform->addElement('static', 'reset', '', $resetlink); - $student_select = array(0 => get_string('no'), 1 => get_string('yes')); + $studentselect = [0 => get_string('no'), 1 => get_string('yes')]; $allowstudents = get_config('moodle', 'block_quickmail_allowstudents'); if ($allowstudents != -1) { // If we disallow "Allow students to use Quickmail" at the site // level, then disallow the config to be set at the course level. - $mform->addElement('select', 'allowstudents', - quickmail::_s('allowstudents'), $student_select); + $mform->addElement( + 'select', + 'allowstudents', + quickmail::_s('allowstudents'), + $studentselect + ); } - $roles =& $mform->addElement('select', 'roleselection', - quickmail::_s('select_roles'), $this->_customdata['roles']); + $roles =& $mform->addElement( + 'select', + 'roleselection', + quickmail::_s('select_roles'), + $this->_customdata['roles'] + ); $roles->setMultiple(true); - $options = array( + $options = [ 0 => get_string('none'), 'idnumber' => get_string('idnumber'), - 'shortname' => get_string('shortname') - ); + 'shortname' => get_string('shortname'), + ]; - $mform->addElement('select', 'prepend_class', - quickmail::_s('prepend_class'), $options); + $mform->addElement( + 'select', + 'prepend_class', + quickmail::_s('prepend_class'), + $options + ); - $mform->addElement('select', 'receipt', - quickmail::_s('receipt'), $student_select); + $mform->addElement( + 'select', + 'receipt', + quickmail::_s('receipt'), + $studentselect + ); $mform->addElement('submit', 'save', get_string('savechanges')); - + $mform->addElement('hidden', 'courseid', $this->_customdata['courseid']); - $mform->setType('courseid',PARAM_INT); + $mform->setType('courseid', PARAM_INT); $mform->addRule('roleselection', null, 'required'); } diff --git a/db/access.php b/db/access.php index 804a558..8eedb2e 100644 --- a/db/access.php +++ b/db/access.php @@ -2,74 +2,74 @@ // Written at Louisiana State University -$capabilities = array( - 'block/quickmail:myaddinstance' => array( +$capabilities = [ + 'block/quickmail:myaddinstance' => [ 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'frontpage' => CAP_PREVENT, - 'user' => CAP_PREVENT - ) - ), + 'user' => CAP_PREVENT, + ], + ], - 'block/quickmail:addinstance' => array( + 'block/quickmail:addinstance' => [ 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_BLOCK, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'coursecreator' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'moodle/site:manageblocks' - ), + 'coursecreator' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'moodle/site:manageblocks', + ], - 'block/quickmail:cansend' => array( + 'block/quickmail:cansend' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'teacher' => CAP_ALLOW - ) - ), + 'teacher' => CAP_ALLOW, + ], + ], - 'block/quickmail:allowalternate' => array( + 'block/quickmail:allowalternate' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'teacher' => CAP_ALLOW, - 'coursecreator' => CAP_ALLOW - ) - ), + 'coursecreator' => CAP_ALLOW, + ], + ], - 'block/quickmail:canconfig' => array( + 'block/quickmail:canconfig' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW - ) - ), + 'editingteacher' => CAP_ALLOW, + ], + ], - 'block/quickmail:canimpersonate' => array( + 'block/quickmail:canimpersonate' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, - ) - ), + ], + ], - 'block/quickmail:candelete' => array( + 'block/quickmail:candelete' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, - ) - ), -); + ], + ], +]; diff --git a/db/upgrade.php b/db/upgrade.php index 84f9607..5ce582a 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -36,7 +36,7 @@ function xmldb_block_quickmail_upgrade($oldversion) { $table->add_field('default_flag', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); // Adding keys to table block_quickmail_signatures - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); // Conditionally launch create table for block_quickmail_signatures if (!$dbman->table_exists($table)) { @@ -58,7 +58,7 @@ function xmldb_block_quickmail_upgrade($oldversion) { $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); // Adding keys to table block_quickmail_drafts - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); // Conditionally launch create table for block_quickmail_drafts if (!$dbman->table_exists($table)) { @@ -75,7 +75,7 @@ function xmldb_block_quickmail_upgrade($oldversion) { $table->add_field('value', XMLDB_TYPE_CHAR, '125', null, null, null, null); // Adding keys to table block_quickmail_config - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); // Conditionally launch create table for block_quickmail_config if (!$dbman->table_exists($table)) { @@ -90,31 +90,59 @@ function xmldb_block_quickmail_upgrade($oldversion) { $table = new xmldb_table('block_quickmail_alternate'); $field = new xmldb_field('id'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, - XMLDB_NOTNULL, true, null, null); + $field->set_attributes( + XMLDB_TYPE_INTEGER, + '10', + XMLDB_UNSIGNED, + XMLDB_NOTNULL, + true, + null, + null + ); $table->addField($field); $field = new xmldb_field('courseid'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, - XMLDB_NOTNULL, false, null, 'id'); + $field->set_attributes( + XMLDB_TYPE_INTEGER, + '10', + XMLDB_UNSIGNED, + XMLDB_NOTNULL, + false, + null, + 'id' + ); $table->addField($field); $field = new xmldb_field('address'); - $field->set_attributes(XMLDB_TYPE_CHAR, '100', null, - XMLDB_NOTNULL, false, null, 'courseid'); + $field->set_attributes( + XMLDB_TYPE_CHAR, + '100', + null, + XMLDB_NOTNULL, + false, + null, + 'courseid' + ); $table->addField($field); $field = new xmldb_field('valid'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, - XMLDB_NOTNULL, false, '0', 'address'); + $field->set_attributes( + XMLDB_TYPE_INTEGER, + '1', + XMLDB_UNSIGNED, + XMLDB_NOTNULL, + false, + '0', + 'address' + ); $table->addField($field); $key = new xmldb_key('PRIMARY'); - $key->set_attributes(XMLDB_KEY_PRIMARY, array('id')); + $key->set_attributes(XMLDB_KEY_PRIMARY, ['id']); $table->addKey($key); @@ -122,11 +150,19 @@ function xmldb_block_quickmail_upgrade($oldversion) { $dbman->create_table($table); } - foreach (array('log', 'drafts') as $table) { + foreach (['log', 'drafts'] as $table) { // Define field alternateid to be added to block_quickmail_log $table = new xmldb_table('block_quickmail_' . $table); - $field = new xmldb_field('alternateid', XMLDB_TYPE_INTEGER, '10', - XMLDB_UNSIGNED, null, null, null, 'userid'); + $field = new xmldb_field( + 'alternateid', + XMLDB_TYPE_INTEGER, + '10', + XMLDB_UNSIGNED, + null, + null, + null, + 'userid' + ); // Conditionally launch add field alternateid if (!$dbman->field_exists($table, $field)) { @@ -140,11 +176,11 @@ function xmldb_block_quickmail_upgrade($oldversion) { if ($oldversion < 2012061112) { // Restructure database references to the new filearea locations - foreach (array('log', 'drafts') as $type) { - $params = array( + foreach (['log', 'drafts'] as $type) { + $params = [ 'component' => 'block_quickmail_' . $type, - 'filearea' => 'attachment' - ); + 'filearea' => 'attachment', + ]; $attachments = $DB->get_records('files', $params); @@ -159,11 +195,10 @@ function xmldb_block_quickmail_upgrade($oldversion) { upgrade_block_savepoint($result, 2012061112, 'quickmail'); } if ($oldversion < 2012061112) { - migrate_quickmail_20(); + migrate_quickmail_20(); } - - if($oldversion < 2014042914){ + if ($oldversion < 2014042914) { // Define field status to be dropped from block_quickmail_log. $table = new xmldb_table('block_quickmail_log'); $field = new xmldb_field('status'); @@ -175,16 +210,16 @@ function xmldb_block_quickmail_upgrade($oldversion) { // Define field status to be added to block_quickmail_log. $table = new xmldb_table('block_quickmail_log'); - $field = new xmldb_field('failuserids', XMLDB_TYPE_TEXT, null, null, null, null, null, 'time'); + $field = new xmldb_field('failuserids', XMLDB_TYPE_TEXT, null, null, null, null, null, 'time'); $field2 = new xmldb_field('additional_emails', XMLDB_TYPE_TEXT, null, null, null, null, null, 'failuserids'); // Conditionally launch add field status. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - if (!$dbman->field_exists($table, $field2)) { + if (!$dbman->field_exists($table, $field2)) { $dbman->add_field($table, $field2); } - + // Define field additional_emails to be added to block_quickmail_drafts. $table = new xmldb_table('block_quickmail_drafts'); $field = new xmldb_field('additional_emails', XMLDB_TYPE_TEXT, null, null, null, null, null, 'time'); @@ -193,8 +228,8 @@ function xmldb_block_quickmail_upgrade($oldversion) { if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - - + + // Quickmail savepoint reached. upgrade_block_savepoint(true, 2014042914, 'quickmail'); } diff --git a/db/upgradelib.php b/db/upgradelib.php index c8ad939..878a77e 100644 --- a/db/upgradelib.php +++ b/db/upgradelib.php @@ -2,9 +2,9 @@ /** * Folder plugin version information * - * @package - * @subpackage - * @copyright 2012 unistra {@link http://unistra.fr} + * @package + * @subpackage + * @copyright block_quickmail * @author Celine Perves * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.cecill.info/licences/Licence_CeCILL_V2-en.html @@ -12,41 +12,41 @@ /** * function to migrate quickmail history files attachment to the new file version from 1.9 to 2.x */ -function migrate_quickmail_20(){ - global $DB; - //migration of attachments - $fs = get_file_storage(); - $quickmail_log_records=$DB->get_records_select('block_quickmail_log','attachment<>\'\''); - foreach($quickmail_log_records as $quickmail_log_record){ - //searching file into mdl_files - //analysing attachment content - $filename=$quickmail_log_record->attachment; - $filepath=''; - $notrootfile=strstr($quickmail_log_record->attachment,'/'); - if($notrootfile){ - $filename=substr($quickmail_log_record->attachment,strrpos($quickmail_log_record->attachment, '/',-1)+1); - $filepath='/'.substr($quickmail_log_record->attachment,0,strrpos($quickmail_log_record->attachment,'/',-1)+1); - }else{ - $filepath='/'; - $filename=$quickmail_log_record->attachment; - } - $fs = get_file_storage(); - $coursecontext = context_course::instance($quickmail_log_record->courseid); +function migrate_quickmail_20() { + global $DB; + // migration of attachments + $fs = get_file_storage(); + $quickmaillogrecords = $DB->get_records_select('block_quickmail_log', 'attachment<>\'\''); + foreach ($quickmaillogrecords as $quickmaillogrecord) { + // searching file into mdl_files + // analysing attachment content + $filename = $quickmaillogrecord->attachment; + $filepath = ''; + $notrootfile = strstr($quickmaillogrecord->attachment, '/'); + if ($notrootfile) { + $filename = substr($quickmaillogrecord->attachment, strrpos($quickmaillogrecord->attachment, '/', -1) + 1); + $filepath = '/' . substr($quickmaillogrecord->attachment, 0, strrpos($quickmaillogrecord->attachment, '/', -1) + 1); + } else { + $filepath = '/'; + $filename = $quickmaillogrecord->attachment; + } + $fs = get_file_storage(); + $coursecontext = context_course::instance($quickmaillogrecord->courseid); - $coursefile=$fs->get_file($coursecontext->id, 'course', 'legacy', 0, $filepath, $filename); - if($coursefile){ - if($notrootfile){ - //rename - $filename=str_replace('/', '_', $quickmail_log_record->attachment); - $filepath='/'; - $quickmail_log_record->attachment=$filename; - $DB->update_record('block_quickmail_log', $quickmail_log_record); - } - $file_record = array('contextid'=>$coursecontext->id, 'component'=>'block_quickmail', 'filearea'=>'attachment_log', 'itemid'=>$quickmail_log_record->id, 'filepath'=>$filepath, 'filename'=>$filename, - 'timecreated'=>$coursefile->get_timecreated(), 'timemodified'=>$coursefile->get_timemodified()); - if(!$fs->file_exists($coursecontext->id, 'block_quickmail', 'attachment_log', 0, $filepath, $filename)){ - $fs->create_file_from_storedfile($file_record, $coursefile->get_id()); - } - } - } -} \ No newline at end of file + $coursefile = $fs->get_file($coursecontext->id, 'course', 'legacy', 0, $filepath, $filename); + if ($coursefile) { + if ($notrootfile) { + // rename + $filename = str_replace('/', '_', $quickmaillogrecord->attachment); + $filepath = '/'; + $quickmaillogrecord->attachment = $filename; + $DB->update_record('block_quickmail_log', $quickmaillogrecord); + } + $filerecord = ['contextid' => $coursecontext->id, 'component' => 'block_quickmail', 'filearea' => 'attachment_log', 'itemid' => $quickmaillogrecord->id, 'filepath' => $filepath, 'filename' => $filename, + 'timecreated' => $coursefile->get_timecreated(), 'timemodified' => $coursefile->get_timemodified()]; + if (!$fs->file_exists($coursecontext->id, 'block_quickmail', 'attachment_log', 0, $filepath, $filename)) { + $fs->create_file_from_storedfile($filerecord, $coursefile->get_id()); + } + } + } +} diff --git a/email.php b/email.php index 9345aa9..96a2fb8 100644 --- a/email.php +++ b/email.php @@ -33,18 +33,18 @@ $type = optional_param('type', '', PARAM_ALPHA); $typeid = optional_param('typeid', 0, PARAM_INT); $sigid = optional_param('sigid', 0, PARAM_INT); -$messageIDresend = optional_param('fmid', 0, PARAM_INT); +$messageidresend = optional_param('fmid', 0, PARAM_INT); -if (!$course = $DB->get_record('course', array('id' => $courseid))) { +if (!$course = $DB->get_record('course', ['id' => $courseid])) { print_error('no_course', 'block_quickmail', '', $courseid); } -if (!empty($type) and !in_array($type, array('log', 'drafts'))) { +if (!empty($type) and !in_array($type, ['log', 'drafts'])) { print_error('no_type', 'block_quickmail', '', $type); } if (!empty($type) and empty($typeid)) { - $string = new stdclass; + $string = new stdclass(); $string->tpe = $type; $string->id = $typeid; @@ -54,19 +54,19 @@ $config = quickmail::load_config($courseid); $context = context_course::instance($courseid); -$has_permission = ( +$haspermission = ( has_capability('block/quickmail:cansend', $context) or !empty($config['allowstudents']) ); -if (!$has_permission) { +if (!$haspermission) { print_error('no_permission', 'block_quickmail'); } -$sigs = $DB->get_records('block_quickmail_signatures', array('userid' => $USER->id), 'default_flag DESC'); +$sigs = $DB->get_records('block_quickmail_signatures', ['userid' => $USER->id], 'default_flag DESC'); -$alt_params = array('courseid' => $course->id, 'valid' => 1); -$alternates = $DB->get_records_menu('block_quickmail_alternate', $alt_params, '', 'id, address'); +$altparams = ['courseid' => $course->id, 'valid' => 1]; +$alternates = $DB->get_records_menu('block_quickmail_alternate', $altparams, '', 'id, address'); $blockname = quickmail::_s('pluginname'); $header = quickmail::_s('email'); @@ -77,18 +77,18 @@ $PAGE->navbar->add($header); $PAGE->set_title($blockname . ': ' . $header); $PAGE->set_heading($blockname . ': ' . $header); -$PAGE->set_url('/blocks/quickmail/email.php', array('courseid' => $courseid)); +$PAGE->set_url('/blocks/quickmail/email.php', ['courseid' => $courseid]); $PAGE->set_pagetype(quickmail::PAGE_TYPE); $PAGE->set_pagelayout('standard'); $PAGE->requires->jquery(); $PAGE->requires->js('/blocks/quickmail/js/selection.js'); -$course_roles = get_roles_used_in_context($context); +$courseroles = get_roles_used_in_context($context); -$filter_roles = $DB->get_records_select('role', sprintf('id IN (%s)', $config['roleselection'])); +$filterroles = $DB->get_records_select('role', sprintf('id IN (%s)', $config['roleselection'])); -$roles = quickmail::filter_roles($course_roles, $filter_roles); +$roles = quickmail::filter_roles($courseroles, $filterroles); $allgroups = groups_get_all_groups($courseid); @@ -96,32 +96,32 @@ $groups = $allgroups; $attributes = null; -$restricted_view = ( +$restrictedview = ( !has_capability('moodle/site:accessallgroups', $context) and $config['ferpa'] == 'strictferpa' ); -$respected_view = ( +$respectedview = ( !has_capability('moodle/site:accessallgroups', $context) and $course->groupmode == 1 and $config['ferpa'] == 'courseferpa' ); -if ($restricted_view || $respected_view) { +if ($restrictedview || $respectedview) { $mastercap = false; $mygroups = groups_get_user_groups($courseid); $gids = implode(',', array_values($mygroups['0'])); $groups = empty($gids) ? - array() : + [] : $DB->get_records_select('groups', 'id IN (' . $gids . ')'); } $globalaccess = empty($allgroups); // Fill the course users by -$users = array(); -$users_to_roles = array(); -$users_to_groups = array(); +$users = []; +$userstoroles = []; +$userstogroups = []; $everyone = quickmail::get_non_suspended_users($context, $courseid); @@ -136,14 +136,19 @@ $filterd = quickmail::filter_roles($userroles, $roles); // Available groups - if ((!$globalaccess and !$mastercap) and - empty($gids) or empty($filterd) or $userid == $USER->id) + if ( + (!$globalaccess and !$mastercap) and + empty($gids) or empty($filterd) or $userid == $USER->id + ) { continue; + } - $groupmapper = function($id) use ($allgroups) { return $allgroups[$id]; }; + $groupmapper = function ($id) use ($allgroups) { + return $allgroups[$id]; + }; - $users_to_groups[$userid] = array_map($groupmapper, $gids); - $users_to_roles[$userid] = $filterd; + $userstogroups[$userid] = array_map($groupmapper, $gids); + $userstoroles[$userid] = $filterd; if (!$user->suspended) { $users[$userid] = $user; } @@ -155,57 +160,61 @@ echo $OUTPUT->heading($blockname); echo $OUTPUT->notification(quickmail::_s('no_usergroups'), 'notifyproblem'); - echo html_writer::start_tag('div', array('class' => 'no-overflow')); + echo html_writer::start_tag('div', ['class' => 'no-overflow']); echo html_writer::link(new moodle_url('/course/view.php', ['id' => $courseid]), get_string('back_to_previous', 'block_quickmail'), null); echo html_writer::end_tag('div'); echo $OUTPUT->footer(); } else { - // we are presenting the form with values populated from either the log or drafts table in the db if (!empty($type)) { - - $email = $DB->get_record('block_quickmail_' . $type, array('id' => $typeid)); - //$emailmailto = array(); + $email = $DB->get_record('block_quickmail_' . $type, ['id' => $typeid]); + // $emailmailto = array(); if ($type == 'log') { - $attributes = array ('id' => "{$typeid}_id_message_editor"); + $attributes = ['id' => "{$typeid}_id_message_editor"]; } - if ($messageIDresend == 1) { - list($email->mailto, $email->additional_emails) = quickmail::clean($email->failuserids); + if ($messageidresend == 1) { + [$email->mailto, $email->additional_emails] = quickmail::clean($email->failuserids); } } else { - $email = new stdClass; + $email = new stdClass(); $email->id = null; } - $email->messageformat = editors_get_preferred_format(); - $default_sigid = $DB->get_field('block_quickmail_signatures', 'id', array( - 'userid' => $USER->id, 'default_flag' => 1 - )); - $email->sigid = $default_sigid ? $default_sigid : -1; + $email->messageformat = editors_get_preferred_format(); + $defaultsigid = $DB->get_field('block_quickmail_signatures', 'id', [ + 'userid' => $USER->id, 'default_flag' => 1, + ]); + $email->sigid = $defaultsigid ? $defaultsigid : -1; // Some setters for the form $email->type = $type; $email->typeid = $typeid; - $editor_options = array( + $editoroptions = [ 'trusttext' => false, 'subdirs' => 1, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'accepted_types' => '*', - 'context' => $context - ); + 'context' => $context, + ]; $email = file_prepare_standard_editor( - $email, 'message', $editor_options, $context, 'block_quickmail', $type, $email->id + $email, + 'message', + $editoroptions, + $context, + 'block_quickmail', + $type, + $email->id ); - $selected = array(); + $selected = []; if (!empty($email->mailto)) { foreach (explode(',', $email->mailto) as $id) { - $selected[$id] = (object) array('id'=>$id,'firstname'=>null,'lastname'=>null,'email'=>$id,'mailformat'=>'1','suspended'=>'0','maildisplay'=>'2','status'=>'0'); - if(is_numeric($selected[$id]->id)) { + $selected[$id] = (object) ['id' => $id, 'firstname' => null, 'lastname' => null, 'email' => $id, 'mailformat' => '1', 'suspended' => '0', 'maildisplay' => '2', 'status' => '0']; + if (is_numeric($selected[$id]->id)) { $selected[$id] = $users[$id]; } unset($users[$id]); @@ -213,21 +222,22 @@ } - $form = new email_form(null, array( - 'editor_options' => $editor_options, + $form = new email_form(null, [ + 'editor_options' => $editoroptions, 'selected' => $selected, 'users' => $users, 'roles' => $roles, 'groups' => $groups, - 'users_to_roles' => $users_to_roles, - 'users_to_groups' => $users_to_groups, - 'sigs' => array_map(function($sig) { return $sig->title; }, $sigs), + 'users_to_roles' => $userstoroles, + 'users_to_groups' => $userstogroups, + 'sigs' => array_map(function ($sig) { + return $sig->title; + }, $sigs), 'alternates' => $alternates, - 'attributes' => $attributes - )); + 'attributes' => $attributes, + ]); - $warnings = array(); - // + $warnings = []; if ($form->is_cancelled()) { redirect(new moodle_url('/course/view.php?id=' . $courseid)); // DWE we should check if we have selected users or emails around here. @@ -260,7 +270,13 @@ } } $data = file_postupdate_standard_editor( - $data, 'message', $editor_options, $context, 'block_quickmail', $table, $data->id + $data, + 'message', + $editoroptions, + $context, + 'block_quickmail', + $table, + $data->id ); $DB->update_record('block_quickmail_' . $table, $data); @@ -273,7 +289,12 @@ // An instance id is needed before storing the file repository ///////// file_save_draft_area_files( - $data->attachments, $context->id, 'block_quickmail', 'attachment_' . $table, $data->id, $editor_options + $data->attachments, + $context->id, + 'block_quickmail', + 'attachment_' . $table, + $data->id, + $editoroptions ); // Send emails ///////////////////////////////////////////////////////// @@ -284,25 +305,27 @@ // deal with possible signature, will be appended to message in a little bit. if (!empty($sigs) and $data->sigid > -1) { $sig = $sigs[$data->sigid]; - $signaturetext = file_rewrite_pluginfile_urls($sig->signature, 'pluginfile.php', $context->id, 'block_quickmail', 'signature', $sig->id, $editor_options); + $signaturetext = file_rewrite_pluginfile_urls($sig->signature, 'pluginfile.php', $context->id, 'block_quickmail', 'signature', $sig->id, $editoroptions); } // Prepare html content of message ///////////////////////////////// - $data->message = file_rewrite_pluginfile_urls($data->message, 'pluginfile.php', $context->id, 'block_quickmail', $table, $data->id, $editor_options); + $data->message = file_rewrite_pluginfile_urls($data->message, 'pluginfile.php', $context->id, 'block_quickmail', $table, $data->id, $editoroptions); - if(empty($signaturetext)){ + if (empty($signaturetext)) { $data->messageWithSigAndAttach = $data->message; - } - else{ - if($data->format == 0 || $data->format == 2 ){ - $data->messageWithSigAndAttach = $data->message . "\n\n" .$signaturetext; - }else{ - $data->messageWithSigAndAttach = $data->message . "

" .$signaturetext; + } else { + if ($data->format == 0 || $data->format == 2) { + $data->messageWithSigAndAttach = $data->message . "\n\n" . $signaturetext; + } else { + $data->messageWithSigAndAttach = $data->message . "

" . $signaturetext; } } // Append links to attachments, if any ///////////////////////////// $data->messageWithSigAndAttach .= quickmail::process_attachments( - $context, $data, $table, $data->id + $context, + $data, + $table, + $data->id ); // Same user, alternate email ////////////////////////////////////// @@ -312,7 +335,7 @@ } else { $user = $USER; } - $data->failuserids = array(); + $data->failuserids = []; // DWE -> Begin hopefully new way of dealing with messagetext and messagehtml // TEXT @@ -320,16 +343,26 @@ $messagetext = format_text_email($data->messageWithSigAndAttach, $data->format); // HTML - $options = array('filter' => false); + $options = ['filter' => false]; $messagehtml = format_text($data->messageWithSigAndAttach, $data->format, $options); - if(!empty($data->mailto)) { - + if (!empty($data->mailto)) { foreach (explode(',', $data->mailto) as $userid) { // Email gets sent here - if ($everyone[$userid]->value) { $everyone[$userid]->email = $everyone[$userid]->value; } - $success = email_to_user($everyone[$userid], $user, $subject,$messagetext, $messagehtml, - '', '', false, $user->email); + if ($everyone[$userid]->value) { + $everyone[$userid]->email = $everyone[$userid]->value; + } + $success = email_to_user( + $everyone[$userid], + $user, + $subject, + $messagetext, + $messagehtml, + '', + '', + false, + $user->email + ); if (!$success) { $warnings[] = get_string("no_email", 'block_quickmail', $everyone[$userid]); $data->failuserids[] = $userid; @@ -337,25 +370,25 @@ } } - if(!empty($data->additional_emails)){ - $additional_email_array = preg_split('/[,;]/', $data->additional_emails); + if (!empty($data->additional_emails)) { + $additionalemailarray = preg_split('/[,;]/', $data->additional_emails); $i = 0; - foreach ($additional_email_array as $additional_email) { - $additional_email = trim($additional_email); + foreach ($additionalemailarray as $additionalemail) { + $additionalemail = trim($additionalemail); $fakeuser = new stdClass(); $fakeuser->id = 99999900 + $i; - $fakeuser->email = $additional_email; + $fakeuser->email = $additionalemail; // TODO make this into a menu option $fakeuser->mailformat = 1; - $additional_email_success = email_to_user($fakeuser, $user, $subject, $messagetext, $messagehtml); - if (!$additional_email_success) { - $data->failuserids[] = $additional_email; + $additionalemailsuccess = email_to_user($fakeuser, $user, $subject, $messagetext, $messagehtml); + if (!$additionalemailsuccess) { + $data->failuserids[] = $additionalemail; // will need to notify that an email is incorrect $warnings[] = get_string("no_email_address", 'block_quickmail', $fakeuser->email); } $i++; } - } + } $data->failuserids = implode(',', $data->failuserids); $DB->update_record('block_quickmail_log', $data); @@ -372,7 +405,11 @@ if (!empty($type)) { $attachid = file_get_submitted_draft_itemid('attachment'); file_prepare_draft_area( - $attachid, $context->id, 'block_quickmail', 'attachment_' . $type, $typeid + $attachid, + $context->id, + 'block_quickmail', + 'attachment_' . $type, + $typeid ); $email->attachments = $attachid; } @@ -381,7 +418,7 @@ $form->set_data($email); if (empty($warnings)) { if (isset($email->send)) { - redirect(new moodle_url('/blocks/quickmail/emaillog.php', array('courseid' => $course->id))); + redirect(new moodle_url('/blocks/quickmail/emaillog.php', ['courseid' => $course->id])); } else if (isset($email->draft)) { $warnings['success'] = get_string("changessaved"); } @@ -395,7 +432,7 @@ echo $OUTPUT->notification($warning, $class); } - echo html_writer::start_tag('div', array('class' => 'no-overflow')); + echo html_writer::start_tag('div', ['class' => 'no-overflow']); $form->display(); echo html_writer::end_tag('div'); echo $OUTPUT->footer(); diff --git a/email_form.php b/email_form.php index 7792744..22200a0 100644 --- a/email_form.php +++ b/email_form.php @@ -26,43 +26,49 @@ class email_form extends moodleform { private function reduce_users($in, $user) { - return $in . ''; + return $in . ''; } private function option_display($user) { - $users_to_groups = $this->_customdata['users_to_groups']; + $userstogroups = $this->_customdata['users_to_groups']; - if (empty($users_to_groups[$user->id])) { + if (empty($userstogroups[$user->id])) { $groups = quickmail::_s('no_section'); } else { - $only_names = function($group) { return $group->name; }; - $groups = implode(',', array_map($only_names, $users_to_groups[$user->id])); + $onlynames = function ($group) { + return $group->name; + }; + $groups = implode(',', array_map($onlynames, $userstogroups[$user->id])); } return sprintf("%s (%s)", fullname($user), $groups); } private function option_value($user) { - $users_to_groups = $this->_customdata['users_to_groups']; - $users_to_roles = $this->_customdata['users_to_roles']; - $only_sn = function($role) { return $role->shortname; }; - if(!is_numeric($user->id)) { - $roles = NULL; + $userstogroups = $this->_customdata['users_to_groups']; + $userstoroles = $this->_customdata['users_to_roles']; + $onlysn = function ($role) { + return $role->shortname; + }; + if (!is_numeric($user->id)) { + $roles = null; } else { - $roles = implode(',', array_map($only_sn, $users_to_roles[$user->id])); + $roles = implode(',', array_map($onlysn, $userstoroles[$user->id])); } // everyone defaults to none - if(is_numeric($user->id)) { - $roles .= ',none'; + if (is_numeric($user->id)) { + $roles .= ',none'; } - if (empty($users_to_groups[$user->id])) { + if (empty($userstogroups[$user->id])) { $groups = 0; } else { - $only_id = function($group) { return $group->id; }; - $groups = implode(',', array_map($only_id, $users_to_groups[$user->id])); + $onlyid = function ($group) { + return $group->id; + }; + $groups = implode(',', array_map($onlyid, $userstogroups[$user->id])); $groups .= ',all'; } $groups .= ',allusers'; @@ -78,7 +84,7 @@ public function definition() { $mform->setType('mailto', PARAM_TEXT); $mform->addElement('hidden', 'userid', $USER->id); - $mform->setType('userid',PARAM_INT); + $mform->setType('userid', PARAM_INT); $mform->addElement('hidden', 'courseid', $COURSE->id); $mform->setType('courseid', PARAM_INT); @@ -89,163 +95,194 @@ public function definition() { $mform->addElement('hidden', 'typeid', 0); $mform->setType('typeid', PARAM_INT); - $role_options = array('none' => quickmail::_s('no_filter')); + $roleoptions = ['none' => quickmail::_s('no_filter')]; foreach ($this->_customdata['roles'] as $role) { - $role_options[$role->shortname] = role_get_name($role); + $roleoptions[$role->shortname] = role_get_name($role); } - $group_options = empty($this->_customdata['groups']) ? array() : array( - 'allusers' => quickmail::_s('allusers') - ); + $groupoptions = empty($this->_customdata['groups']) ? [] : [ + 'allusers' => quickmail::_s('allusers'), + ]; - $group_options['all'] = quickmail::_s('all_sections'); + $groupoptions['all'] = quickmail::_s('all_sections'); foreach ($this->_customdata['groups'] as $group) { - $group_options[$group->id] = $group->name; + $groupoptions[$group->id] = $group->name; } - $group_options[0] = quickmail::_s('no_section'); + $groupoptions[0] = quickmail::_s('no_section'); - $user_options = array(); + $useroptions = []; foreach ($this->_customdata['users'] as $user) { - $user_options[$this->option_value($user)] = $this->option_display($user); + $useroptions[$this->option_value($user)] = $this->option_display($user); } - $links = array(); - $gen_url = function($type) use ($COURSE) { - $email_param = array('courseid' => $COURSE->id, 'type' => $type); - return new moodle_url('emaillog.php', $email_param); + $links = []; + $genurl = function ($type) use ($COURSE) { + $emailparam = ['courseid' => $COURSE->id, 'type' => $type]; + return new moodle_url('emaillog.php', $emailparam); }; - $draft_link = html_writer::link ($gen_url('drafts'), quickmail::_s('drafts')); - $links[] =& $mform->createElement('static', 'draft_link', '', $draft_link); + $draftlink = html_writer::link($genurl('drafts'), quickmail::_s('drafts')); + $links[] =& $mform->createElement('static', 'draft_link', '', $draftlink); $context = context_course::instance($COURSE->id); $config = quickmail::load_config($COURSE->id); - $can_send = ( + $cansend = ( has_capability('block/quickmail:cansend', $context) or !empty($config['allowstudents']) ); - if ($can_send) { - $history_link = html_writer::link($gen_url('log'), quickmail::_s('history')); - $links[] =& $mform->createElement('static', 'history_link', '', $history_link); + if ($cansend) { + $historylink = html_writer::link($genurl('log'), quickmail::_s('history')); + $links[] =& $mform->createElement('static', 'history_link', '', $historylink); } - $mform->addGroup($links, 'links', ' ', array(' | '), false); + $mform->addGroup($links, 'links', ' ', [' | '], false); $table = new html_table(); $table->attributes['class'] = 'emailtable'; - $selected_label = new html_table_cell(); - $selected_label->text = html_writer::tag('strong', - quickmail::_s('selected') . " "); + $selectedlabel = new html_table_cell(); + $selectedlabel->text = html_writer::tag( + 'strong', + quickmail::_s('selected') . " " + ); - $role_filter_label = new html_table_cell(); - $role_filter_label->colspan = "2"; - $role_filter_label->text = html_writer::tag('div', - quickmail::_s('role_filter'), array('class' => 'object_labels')); + $rolefilterlabel = new html_table_cell(); + $rolefilterlabel->colspan = "2"; + $rolefilterlabel->text = html_writer::tag( + 'div', + quickmail::_s('role_filter'), + ['class' => 'object_labels'] + ); - $select_filter = new html_table_cell(); - $select_filter->text = html_writer::tag('select', - array_reduce($this->_customdata['selected'], array($this, 'reduce_users'), ''), - array('id' => 'mail_users', 'class' => 'select custom-select menu', 'multiple' => 'multiple', 'size' => 30)); + $selectfilter = new html_table_cell(); + $selectfilter->text = html_writer::tag( + 'select', + array_reduce($this->_customdata['selected'], [$this, 'reduce_users'], ''), + ['id' => 'mail_users', 'class' => 'select custom-select menu', 'multiple' => 'multiple', 'size' => 30] + ); $embed = function ($text, $id) { - return html_writer::tag('p', - html_writer::empty_tag('input', array( - 'value' => $text, 'type' => 'button', 'class' => 'btn btn-secondary' , 'id' => $id - )) + return html_writer::tag( + 'p', + html_writer::empty_tag('input', [ + 'value' => $text, 'type' => 'button', 'class' => 'btn btn-secondary', 'id' => $id, + ]) ); }; - $embed_quick = function ($text) use ($embed) { + $embedquick = function ($text) use ($embed) { return $embed(quickmail::_s($text), $text); }; - $center_buttons = new html_table_cell(); - $center_buttons->text = ( + $centerbuttons = new html_table_cell(); + $centerbuttons->text = ( $embed($OUTPUT->larrow() . ' ' . quickmail::_s('add_button'), 'add_button') . $embed(quickmail::_s('remove_button') . ' ' . $OUTPUT->rarrow(), 'remove_button') . - $embed_quick('add_all') . - $embed_quick('remove_all') + $embedquick('add_all') . + $embedquick('remove_all') ); $filters = new html_table_cell(); - $filters->text = html_writer::tag('div', - html_writer::select($role_options, '', 'none', null, array('id' => 'roles')) - ) . html_writer::tag('div', + $filters->text = html_writer::tag( + 'div', + html_writer::select($roleoptions, '', 'none', null, ['id' => 'roles']) + ) . html_writer::tag( + 'div', quickmail::_s('potential_sections'), - array('class' => 'object_labels') - ) . html_writer::tag('div', - html_writer::select($group_options, '', 'all', null, - array('id' => 'groups', 'multiple' => 'multiple', 'size' => 5)) - ) . html_writer::tag('div', + ['class' => 'object_labels'] + ) . html_writer::tag( + 'div', + html_writer::select( + $groupoptions, + '', + 'all', + null, + ['id' => 'groups', 'multiple' => 'multiple', 'size' => 5] + ) + ) . html_writer::tag( + 'div', quickmail::_s('potential_users'), - array('class' => 'object_labels') - ) . html_writer::tag('div', - html_writer::select($user_options, '', '', null, - array('id' => 'from_users', 'multiple' => 'multiple', 'size' => 20)) + ['class' => 'object_labels'] + ) . html_writer::tag( + 'div', + html_writer::select( + $useroptions, + '', + '', + null, + ['id' => 'from_users', 'multiple' => 'multiple', 'size' => 20] + ) ); // DWE -> NON REQUIRED VERSION - $table->data[] = new html_table_row(array($selected_label, $role_filter_label)); + $table->data[] = new html_table_row([$selectedlabel, $rolefilterlabel]); - //$table->data[] = new html_table_row(array($selected_required_label, $role_filter_label)); - $table->data[] = new html_table_row(array($select_filter, $center_buttons, $filters)); + // $table->data[] = new html_table_row(array($selected_required_label, $role_filter_label)); + $table->data[] = new html_table_row([$selectfilter, $centerbuttons, $filters]); if (has_capability('block/quickmail:allowalternate', $context)) { $alternates = $this->_customdata['alternates']; } else { - $alternates = array(); + $alternates = []; } if (empty($alternates)) { $mform->addElement('static', 'from', quickmail::_s('from'), $USER->email); } else { - $options = array(0 => $USER->email) + $alternates; + $options = [0 => $USER->email] + $alternates; $mform->addElement('select', 'alternateid', quickmail::_s('from'), $options); } $mform->addElement('static', 'selectors', '', html_writer::table($table)); if (!empty($CFG->block_quickmail_addionalemail)) { - $mform->addElement('text', 'additional_emails', quickmail::_s('additional_emails'), array('style'=>'width: 50%;')); - $mform->setType('additional_emails', PARAM_TEXT); - $mform->addRule('additional_emails', 'One or more email addresses is invalid', 'callback', 'block_quickmail_mycallback', 'client'); - $mform->addHelpButton('additional_emails', 'additional_emails', 'block_quickmail'); + $mform->addElement('text', 'additional_emails', quickmail::_s('additional_emails'), ['style' => 'width: 50%;']); + $mform->setType('additional_emails', PARAM_TEXT); + $mform->addRule('additional_emails', 'One or more email addresses is invalid', 'callback', 'block_quickmail_mycallback', 'client'); + $mform->addHelpButton('additional_emails', 'additional_emails', 'block_quickmail'); } $mform->addElement( - 'filemanager', 'attachments', quickmail::_s('attachment'), - null, array('subdirs' => 1, 'accepted_types' => '*') + 'filemanager', + 'attachments', + quickmail::_s('attachment'), + null, + ['subdirs' => 1, 'accepted_types' => '*'] ); $mform->addElement('text', 'subject', quickmail::_s('subject')); $mform->setType('subject', PARAM_TEXT); $mform->addRule('subject', null, 'required'); - $mform->addElement('editor', 'message_editor', quickmail::_s('message'), - $this->_customdata['attributes'], $this->_customdata['editor_options']); + $mform->addElement( + 'editor', + 'message_editor', + quickmail::_s('message'), + $this->_customdata['attributes'], + $this->_customdata['editor_options'] + ); - $options = $this->_customdata['sigs'] + array(-1 => quickmail::_s('no').' '.quickmail::_s('sig')); + $options = $this->_customdata['sigs'] + [-1 => quickmail::_s('no') . ' ' . quickmail::_s('sig')]; $mform->addElement('select', 'sigid', quickmail::_s('signature'), $options); - $radio = array( + $radio = [ $mform->createElement('radio', 'receipt', '', get_string('yes'), 1), - $mform->createElement('radio', 'receipt', '', get_string('no'), 0) - ); + $mform->createElement('radio', 'receipt', '', get_string('no'), 0), + ]; - $mform->addGroup($radio, 'receipt_action', quickmail::_s('receipt'), array(' '), false); + $mform->addGroup($radio, 'receipt_action', quickmail::_s('receipt'), [' '], false); $mform->addHelpButton('receipt_action', 'receipt', 'block_quickmail'); $mform->setDefault('receipt', !empty($config['receipt'])); - $buttons = array(); + $buttons = []; $buttons[] =& $mform->createElement('submit', 'send', quickmail::_s('send_email')); $buttons[] =& $mform->createElement('submit', 'draft', quickmail::_s('save_draft')); $buttons[] =& $mform->createElement('cancel'); - $mform->addGroup($buttons, 'buttons', quickmail::_s('actions'), array(' '), false); + $mform->addGroup($buttons, 'buttons', quickmail::_s('actions'), [' '], false); } } diff --git a/emaillog.php b/emaillog.php index ec29ef5..2f15539 100644 --- a/emaillog.php +++ b/emaillog.php @@ -34,14 +34,14 @@ $perpage = optional_param('perpage', 10, PARAM_INT); $userid = optional_param('userid', $USER->id, PARAM_INT); -if (!$course = $DB->get_record('course', array('id' => $courseid))) { +if (!$course = $DB->get_record('course', ['id' => $courseid])) { print_error('no_course', 'block_quickmail', '', $courseid); } $context = context_course::instance($courseid); // Has to be in on of these -if (!in_array($type, array('log', 'drafts'))) { +if (!in_array($type, ['log', 'drafts'])) { print_error('not_valid', 'block_quickmail', '', $type); } @@ -52,22 +52,22 @@ $config = quickmail::load_config($courseid); -$valid_actions = array('delete', 'confirm'); +$validactions = ['delete', 'confirm']; -$can_send = has_capability('block/quickmail:cansend', $context); +$cansend = has_capability('block/quickmail:cansend', $context); -$proper_permission = ($can_send or !empty($config['allowstudents'])); +$properpermission = ($cansend or !empty($config['allowstudents'])); -//managers can delete by capability 'candelete'; -//those with 'cansend' (incl students, if $config['allowstudents']) can only delete drafts; -$can_delete = (has_capability('block/quickmail:candelete', $context) or ($can_send and $type == 'drafts') or ($proper_permission and $type == 'drafts')); +// managers can delete by capability 'candelete'; +// those with 'cansend' (incl students, if $config['allowstudents']) can only delete drafts; +$candelete = (has_capability('block/quickmail:candelete', $context) or ($cansend and $type == 'drafts') or ($properpermission and $type == 'drafts')); // Stops students from tempering with history -if (!$proper_permission or (!$can_delete and in_array($action, $valid_actions))) { +if (!$properpermission or (!$candelete and in_array($action, $validactions))) { print_error('no_permission', 'block_quickmail'); } -if (isset($action) and !in_array($action, $valid_actions)) { +if (isset($action) and !in_array($action, $validactions)) { print_error('not_valid_action', 'block_quickmail', '', $action); } @@ -84,89 +84,90 @@ $PAGE->navbar->add($header); $PAGE->set_title($blockname . ': ' . $header); $PAGE->set_heading($blockname . ': ' . $header); -$PAGE->set_url('/blocks/quickmail/emaillog.php', array('courseid' => $courseid)); +$PAGE->set_url('/blocks/quickmail/emaillog.php', ['courseid' => $courseid]); $PAGE->set_pagetype(quickmail::PAGE_TYPE); $PAGE->set_pagelayout('standard'); $dbtable = 'block_quickmail_' . $type; -$params = array('userid' => $userid, 'courseid' => $courseid); +$params = ['userid' => $userid, 'courseid' => $courseid]; $count = $DB->count_records($dbtable, $params); switch ($action) { case "confirm": if (quickmail::cleanup($dbtable, $context->id, $typeid)) { - $url = new moodle_url('/blocks/quickmail/emaillog.php', array( + $url = new moodle_url('/blocks/quickmail/emaillog.php', [ 'courseid' => $courseid, - 'type' => $type - )); + 'type' => $type, + ]); redirect($url); - } else + } else { print_error('delete_failed', 'block_quickmail', '', $typeid); + } case "delete": $html = quickmail::delete_dialog($courseid, $type, $typeid); break; default: - $html = quickmail::list_entries($courseid, $type, $page, $perpage, $userid, $count, $can_delete); + $html = quickmail::list_entries($courseid, $type, $page, $perpage, $userid, $count, $candelete); } -if($courseid == SITEID) { - $html.= html_writer::link( +if ($courseid == SITEID) { + $html .= html_writer::link( new moodle_url('/blocks/quickmail/admin_email.php'), quickmail::_s('composenew') - ); + ); } else { - $html.= html_writer::link( + $html .= html_writer::link( new moodle_url( '/blocks/quickmail/email.php', - array('courseid' => $courseid)), + ['courseid' => $courseid] + ), quickmail::_s('composenew') ); } -if($canimpersonate and $USER->id != $userid) { - $user = $DB->get_record('user', array('id' => $userid)); +if ($canimpersonate and $USER->id != $userid) { + $user = $DB->get_record('user', ['id' => $userid]); // http://docs.moodle.org/dev/Additional_name_fields - $header .= ' for '. fullname($user); - - + $header .= ' for ' . fullname($user); } echo $OUTPUT->header(); echo $OUTPUT->heading($header); -if($canimpersonate) { - - $get_name_string = 'u.firstname, u.lastname'; +if ($canimpersonate) { + $getnamestring = 'u.firstname, u.lastname'; - if($CFG->version >= 2013111800){ - $get_name_string = block_quickmail_get_all_user_name_fields('u'); + if ($CFG->version >= 2013111800) { + $getnamestring = block_quickmail_get_all_user_name_fields('u'); } - $sql = "SELECT DISTINCT(l.userid)," . $get_name_string . " + $sql = "SELECT DISTINCT(l.userid)," . $getnamestring . " FROM {block_quickmail_$type} l, {user} u WHERE u.id = l.userid AND courseid = ? ORDER BY u.lastname"; - $users = $DB->get_records_sql($sql, array($courseid)); - $user_options = array_map(function($user) { return fullname($user); }, $users); + $users = $DB->get_records_sql($sql, [$courseid]); + $useroptions = array_map(function ($user) { + return fullname($user); + }, $users); - $url = new moodle_url('emaillog.php', array( + $url = new moodle_url('emaillog.php', [ 'courseid' => $courseid, - 'type' => $type - )); + 'type' => $type, + ]); - $default_option = array('' => quickmail::_s('select_users')); + $defaultoption = ['' => quickmail::_s('select_users')]; - echo $OUTPUT->single_select($url, 'userid', $user_options, $userid, $default_option); + echo $OUTPUT->single_select($url, 'userid', $useroptions, $userid, $defaultoption); } -if(empty($count)) { - echo $OUTPUT->notification(quickmail::_s('no_'.$type)); +if (empty($count)) { + echo $OUTPUT->notification(quickmail::_s('no_' . $type)); if ($COURSE->id == 1) { - echo $OUTPUT->continue_button('/blocks/quickmail/admin_email.php?courseid='.$courseid); + echo $OUTPUT->continue_button('/blocks/quickmail/admin_email.php?courseid=' . $courseid); } else { - echo $OUTPUT->continue_button('/blocks/quickmail/email.php?courseid='.$courseid); + echo $OUTPUT->continue_button('/blocks/quickmail/email.php?courseid=' . $courseid); } echo $OUTPUT->footer(); diff --git a/lang/en/block_quickmail.php b/lang/en/block_quickmail.php index bd52b6a..a6f1752 100644 --- a/lang/en/block_quickmail.php +++ b/lang/en/block_quickmail.php @@ -43,7 +43,7 @@ $string['title'] = 'Title'; $string['no'] = 'No'; $string['new'] = 'New'; -$string['sig'] ='Signature'; +$string['sig'] = 'Signature'; $string['default_flag'] = 'Default'; $string['config'] = 'Configuration'; $string['downloads'] = 'Require login for attachments'; @@ -152,7 +152,7 @@ $string['draftssuccess'] = "Draft"; -//admin +// admin $string['sendadmin'] = 'Send Admin Email'; $string['noreply'] = 'No-Reply'; $string['body'] = 'Body'; @@ -163,7 +163,7 @@ $string['message_sent_to'] = 'Message sent to '; $string['warnings'] = 'Warnings'; $string['message_body_as_follows'] = 'message body as follows '; -$string['sent_successfully_to_the_following_users'] = 'sent successfully to the following users: ' ; +$string['sent_successfully_to_the_following_users'] = 'sent successfully to the following users: '; $string['seconds'] = 'seconds'; $string['admin_email_send_receipt'] = 'Admin Email Send Receipt'; $string['something_broke'] = 'It looks like you either have email sending disabled or things are very broken'; diff --git a/lang/en_us/block_quickmail.php b/lang/en_us/block_quickmail.php index 25b813b..64f23d7 100644 --- a/lang/en_us/block_quickmail.php +++ b/lang/en_us/block_quickmail.php @@ -1,7 +1,7 @@ delete_area_files( - $contextid, 'block_quickmail', - 'attachment_' . $filearea, $itemid + $contextid, + 'block_quickmail', + 'attachment_' . $filearea, + $itemid ); $fs->delete_area_files( - $contextid, 'block_quickmail', - $filearea, $itemid + $contextid, + 'block_quickmail', + $filearea, + $itemid ); - return $DB->delete_records($table, array('id' => $itemid)); + return $DB->delete_records($table, ['id' => $itemid]); } static function history_cleanup($contextid, $itemid) { - return quickmail::cleanup('block_quickmail_log', $contextid, $itemid); + return self::cleanup('block_quickmail_log', $contextid, $itemid); } static function draft_cleanup($contextid, $itemid) { - return quickmail::cleanup('block_quickmail_drafts', $contextid, $itemid); + return self::cleanup('block_quickmail_drafts', $contextid, $itemid); } - private static function flatten_subdirs($tree, $gen_link, $level=0) { + private static function flatten_subdirs($tree, $genlink, $level = 0) { $attachments = $spaces = ''; foreach (range(0, $level) as $space) { $spaces .= " - "; } foreach ($tree['files'] as $filename => $file) { - $attachments .= $spaces . " " . $gen_link($filename) . "\n
"; + $attachments .= $spaces . " " . $genlink($filename) . "\n
"; } foreach ($tree['subdirs'] as $dirname => $subdir) { - $attachments .= $spaces . " ". $dirname . "\n
"; - $attachments .= self::flatten_subdirs($subdir, $gen_link, $level + 2); + $attachments .= $spaces . " " . $dirname . "\n
"; + $attachments .= self::flatten_subdirs($subdir, $genlink, $level + 2); } return $attachments; @@ -96,11 +99,14 @@ static function process_attachments($context, $email, $table, $id) { $fs = get_file_storage(); $tree = $fs->get_area_tree( - $context->id, 'block_quickmail', - 'attachment_' . $table, $id, 'id' + $context->id, + 'block_quickmail', + 'attachment_' . $table, + $id, + 'id' ); - $base_url = "/$context->id/block_quickmail/attachment_{$table}/$id"; + $baseurl = "/$context->id/block_quickmail/attachment_{$table}/$id"; /** * @param string $filename name of the file for which we are generating a download link @@ -108,17 +114,17 @@ static function process_attachments($context, $email, $table, $id) { * @param bool $plain if itrue, we will output a clean url for plain text email users * */ - $gen_link = function ($filename, $text = '', $plain=false) use ($base_url) { + $genlink = function ($filename, $text = '', $plain = false) use ($baseurl) { if (empty($text)) { $text = $filename; } - $url = moodle_url::make_file_url('/pluginfile.php', "$base_url/$filename", true); + $url = moodle_url::make_file_url('/pluginfile.php', "$baseurl/$filename", true); - //to prevent double encoding of ampersands in urls for our plaintext users, - //we use the out() method of moodle_url - //@see http://phpdocs.moodle.org/HEAD/moodlecore/moodle_url.html - if($plain){ + // to prevent double encoding of ampersands in urls for our plaintext users, + // we use the out() method of moodle_url + // @see http://phpdocs.moodle.org/HEAD/moodlecore/moodle_url.html + if ($plain) { return $url->out(false); } @@ -127,33 +133,33 @@ static function process_attachments($context, $email, $table, $id) { - $link = $gen_link("{$email->time}_attachments.zip", self::_s('download_all')); + $link = $genlink("{$email->time}_attachments.zip", self::_s('download_all')); - //get a plain text version of the link - //by calling gen_link with @param $plain set to true - $tlink = $gen_link("{$email->time}_attachments.zip", '', true); + // get a plain text version of the link + // by calling gen_link with @param $plain set to true + $tlink = $genlink("{$email->time}_attachments.zip", '', true); $attachments .= "\n
-------\n
"; $attachments .= self::_s('moodle_attachments', $link); - $attachments .= "\n
".$tlink; + $attachments .= "\n
" . $tlink; $attachments .= "\n
-------\n
"; $attachments .= self::_s('qm_contents') . "\n
"; - return $attachments . self::flatten_subdirs($tree, $gen_link); + return $attachments . self::flatten_subdirs($tree, $genlink); } static function zip_attachments($context, $table, $id) { global $CFG, $USER; - $base_path = "block_quickmail/{$USER->id}"; - $moodle_base = "$CFG->tempdir/$base_path"; + $basepath = "block_quickmail/{$USER->id}"; + $moodlebase = "$CFG->tempdir/$basepath"; - if (!file_exists($moodle_base)) { - mkdir($moodle_base, $CFG->directorypermissions, true); + if (!file_exists($moodlebase)) { + mkdir($moodlebase, $CFG->directorypermissions, true); } $zipname = "attachment.zip"; - $actual_zip = "$moodle_base/$zipname"; + $actualzip = "$moodlebase/$zipname"; $fs = get_file_storage(); $packer = get_file_packer(); @@ -166,18 +172,18 @@ static function zip_attachments($context, $table, $id) { 'id' ); - $stored_files = array(); + $storedfiles = []; foreach ($files as $file) { if ($file->is_directory() and $file->get_filename() == '.') { continue; } - $stored_files[$file->get_filepath().$file->get_filename()] = $file; + $storedfiles[$file->get_filepath() . $file->get_filename()] = $file; } - $packer->archive_to_pathname($stored_files, $actual_zip); + $packer->archive_to_pathname($storedfiles, $actualzip); - return $actual_zip; + return $actualzip; } static function attachment_names($draft) { @@ -187,19 +193,21 @@ static function attachment_names($draft) { $fs = get_file_storage(); $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draft, 'id'); - $only_files = array_filter($files, function($file) { + $onlyfiles = array_filter($files, function ($file) { return !$file->is_directory() and $file->get_filename() != '.'; }); - $only_names = function ($file) { return $file->get_filename(); }; + $onlynames = function ($file) { + return $file->get_filename(); + }; - $only_named_files = array_map($only_names, $only_files); + $onlynamedfiles = array_map($onlynames, $onlyfiles); - return implode(',', $only_named_files); + return implode(',', $onlynamedfiles); } - static function filter_roles($user_roles, $master_roles) { - return array_uintersect($master_roles, $user_roles, function($a, $b) { + static function filter_roles($userroles, $masterroles) { + return array_uintersect($masterroles, $userroles, function ($a, $b) { return strcmp($a->shortname, $b->shortname); }); } @@ -208,7 +216,7 @@ static function load_config($courseid) { global $DB; $fields = 'name,value'; - $params = array('coursesid' => $courseid); + $params = ['coursesid' => $courseid]; $table = 'block_quickmail_config'; $config = $DB->get_records_menu($table, $params, '', $fields); @@ -226,20 +234,19 @@ static function load_config($courseid) { $allowstudents = 0; } - $config = array( + $config = [ 'allowstudents' => $allowstudents, 'roleselection' => $roleselection, 'prepend_class' => $prepender, 'receipt' => $receipt, - 'ferpa' => $ferpa - ); - + 'ferpa' => $ferpa, + ]; } else { // See if allow students is disabled at the site level. $allowstudents = get_config('moodle', 'block_quickmail_allowstudents'); - if ($allowstudents == -1) { - $config['allowstudents'] = 0; - } + if ($allowstudents == -1) { + $config['allowstudents'] = 0; + } $config['ferpa'] = get_config('moodle', 'block_quickmail_ferpa'); } @@ -249,17 +256,17 @@ static function load_config($courseid) { static function default_config($courseid) { global $DB; - $params = array('coursesid' => $courseid); + $params = ['coursesid' => $courseid]; $DB->delete_records('block_quickmail_config', $params); } static function save_config($courseid, $data) { global $DB; - quickmail::default_config($courseid); + self::default_config($courseid); foreach ($data as $name => $value) { - $config = new stdClass; + $config = new stdClass(); $config->coursesid = $courseid; $config->name = $name; $config->value = $value; @@ -271,143 +278,145 @@ static function save_config($courseid, $data) { static function delete_dialog($courseid, $type, $typeid) { global $CFG, $DB, $USER, $OUTPUT; - $email = $DB->get_record('block_quickmail_'.$type, array('id' => $typeid)); + $email = $DB->get_record('block_quickmail_' . $type, ['id' => $typeid]); - if (empty($email)) + if (empty($email)) { print_error('not_valid_typeid', 'block_quickmail', '', $typeid); + } - $params = array('courseid' => $courseid, 'type' => $type); - $yes_params = $params + array('typeid' => $typeid, 'action' => 'confirm'); + $params = ['courseid' => $courseid, 'type' => $type]; + $yesparams = $params + ['typeid' => $typeid, 'action' => 'confirm']; - $optionyes = new moodle_url('/blocks/quickmail/emaillog.php', $yes_params); + $optionyes = new moodle_url('/blocks/quickmail/emaillog.php', $yesparams); $optionno = new moodle_url('/blocks/quickmail/emaillog.php', $params); $table = new html_table(); - $table->head = array(get_string('date'), quickmail::_s('subject')); - if($courseid ==1 ) { - $table->data = array( - new html_table_row(array( - new html_table_cell(quickmail::format_time($email->time)), - new html_table_cell($email->subject)) - ) - ); + $table->head = [get_string('date'), self::_s('subject')]; + if ($courseid == 1) { + $table->data = [ + new html_table_row([ + new html_table_cell(self::format_time($email->time)), + new html_table_cell($email->subject)]), + ]; } else { - $table->data = array( - new html_table_row(array( - new html_table_cell(quickmail::format_time($email->time)), - new html_table_cell($email->subject)) - ) - ); + $table->data = [ + new html_table_row([ + new html_table_cell(self::format_time($email->time)), + new html_table_cell($email->subject)]), + ]; } - $msg = quickmail::_s('delete_confirm', html_writer::table($table)); + $msg = self::_s('delete_confirm', html_writer::table($table)); $html = $OUTPUT->confirm($msg, $optionyes, $optionno); return $html; } - static function list_entries($courseid, $type, $page, $perpage, $userid, $count, $can_delete) { + static function list_entries($courseid, $type, $page, $perpage, $userid, $count, $candelete) { global $CFG, $DB, $OUTPUT; - $dbtable = 'block_quickmail_'.$type; + $dbtable = 'block_quickmail_' . $type; $table = new html_table(); - $params = array('courseid' => $courseid, 'userid' => $userid); - $logs = $DB->get_records($dbtable, $params, - 'time DESC', '*', $page * $perpage, $perpage); - if($courseid == '1'){ - $table->head= array(get_string('date'), quickmail::_s('subject'),get_string('action'), quickmail::_s('status'), quickmail::_s('failed_to_send_to'),quickmail::_s('send_again')); - } - else{ - $table->head= array(get_string('date'), quickmail::_s('subject'), - quickmail::_s('attachment'), get_string('action'), quickmail::_s('status'), quickmail::_s('failed_to_send_to'),quickmail::_s('send_again')); + $params = ['courseid' => $courseid, 'userid' => $userid]; + $logs = $DB->get_records( + $dbtable, + $params, + 'time DESC', + '*', + $page * $perpage, + $perpage + ); + if ($courseid == '1') { + $table->head = [get_string('date'), self::_s('subject'), get_string('action'), self::_s('status'), self::_s('failed_to_send_to'), self::_s('send_again')]; + } else { + $table->head = [get_string('date'), self::_s('subject'), + self::_s('attachment'), get_string('action'), self::_s('status'), self::_s('failed_to_send_to'), self::_s('send_again')]; } - $table->data = array(); + $table->data = []; foreach ($logs as $log) { - $array_of_failed_user_ids = array(); - $date = quickmail::format_time($log->time); + $arrayoffaileduserids = []; + $date = self::format_time($log->time); $subject = $log->subject; $attachments = $log->attachment; - if( ! empty($log->failuserids) ){ + if (! empty($log->failuserids)) { // DWE -> keep track of user ids that failed. - $array_of_failed_user_ids = explode(",",$log->failuserids); + $arrayoffaileduserids = explode(",", $log->failuserids); } - $params = array( + $params = [ 'courseid' => $log->courseid, 'type' => $type, - 'typeid' => $log->id - ); - - $actions = array(); - if($courseid == '1'){ - $open_link = html_writer::link( - new moodle_url('/blocks/quickmail/admin_email.php', $params), - $OUTPUT->pix_icon('i/search', 'Open Email') - ); - } - else{ - $open_link = html_writer::link( - new moodle_url('/blocks/quickmail/email.php', $params), - $OUTPUT->pix_icon('i/search', 'Open Email') - ); + 'typeid' => $log->id, + ]; + + $actions = []; + if ($courseid == '1') { + $openlink = html_writer::link( + new moodle_url('/blocks/quickmail/admin_email.php', $params), + $OUTPUT->pix_icon('i/search', 'Open Email') + ); + } else { + $openlink = html_writer::link( + new moodle_url('/blocks/quickmail/email.php', $params), + $OUTPUT->pix_icon('i/search', 'Open Email') + ); } - $actions[] = $open_link; + $actions[] = $openlink; - if ($can_delete) { - $delete_params = $params + array( + if ($candelete) { + $deleteparams = $params + [ 'userid' => $userid, - 'action' => 'delete' - ); + 'action' => 'delete', + ]; - $delete_link = html_writer::link ( - new moodle_url('/blocks/quickmail/emaillog.php', $delete_params), + $deletelink = html_writer::link( + new moodle_url('/blocks/quickmail/emaillog.php', $deleteparams), $OUTPUT->pix_icon("i/invalid", "Delete Email") ); - $actions[] = $delete_link; + $actions[] = $deletelink; } - $action_links = implode(' ', $actions); + $actionlinks = implode(' ', $actions); - $statusSENTorNot = quickmail::_s($type."success"); + $statussentornot = self::_s($type . "success"); - if ( ! empty ($array_of_failed_user_ids) ){ - $statusSENTorNot = quickmail::_s('message_failure'); - $params += array( + if (! empty($arrayoffaileduserids)) { + $statussentornot = self::_s('message_failure'); + $params += [ 'fmid' => 1, - ); - $text = quickmail::_s('send_again'); + ]; + $text = self::_s('send_again'); - if($courseid == '1'){ + if ($courseid == '1') { $sendagain = html_writer::link(new moodle_url("/blocks/quickmail/admin_email.php", $params), $text); - }else{ + } else { $sendagain = html_writer::link(new moodle_url("/blocks/quickmail/email.php", $params), $text); } - $listFailIDs = count($array_of_failed_user_ids); - - $failCount = (($listFailIDs === 1) ? $listFailIDs . " " . quickmail::_s("user") : $listFailIDs . " " . quickmail::_s("users")); - - } - - else{ + $listfailids = count($arrayoffaileduserids); - $listFailIDs = $array_of_failed_user_ids; + $failcount = (($listfailids === 1) ? $listfailids . " " . self::_s("user") : $listfailids . " " . self::_s("users")); + } else { + $listfailids = $arrayoffaileduserids; $sendagain = ""; - $failCount = ""; + $failcount = ""; } if ($courseid == 1) { - $table->data[] = array($date, $subject, $action_links, $statusSENTorNot, $failCount, $sendagain); + $table->data[] = [$date, $subject, $actionlinks, $statussentornot, $failcount, $sendagain]; } else { - $table->data[] = array($date, $subject, $attachments, $action_links, $statusSENTorNot,$failCount,$sendagain); - } - + $table->data[] = [$date, $subject, $attachments, $actionlinks, $statussentornot, $failcount, $sendagain]; } + } - $paging = $OUTPUT->paging_bar($count, $page, $perpage, - '/blocks/quickmail/emaillog.php?type='.$type.'&courseid='.$courseid.'&userid='.$userid); + $paging = $OUTPUT->paging_bar( + $count, + $page, + $perpage, + '/blocks/quickmail/emaillog.php?type=' . $type . '&courseid=' . $courseid . '&userid=' . $userid + ); $html = $paging; $html .= html_writer::table($table); @@ -420,18 +429,18 @@ static function list_entries($courseid, $type, $page, $perpage, $userid, $count, * @param $context a moodle context id * @return array of sparse user objects */ - public static function get_all_users($context){ + public static function get_all_users($context) { global $DB, $CFG; // List everyone with role in course. // // Note that users with multiple roles will be squashed into one // record. - $get_name_string = 'u.firstname, u.lastname'; + $getnamestring = 'u.firstname, u.lastname'; - if($CFG->version >= 2013111800){ - $get_name_string = block_quickmail_get_all_user_name_fields('u'); + if ($CFG->version >= 2013111800) { + $getnamestring = block_quickmail_get_all_user_name_fields('u'); } - $sql = "SELECT DISTINCT u.id, " . $get_name_string . ", + $sql = "SELECT DISTINCT u.id, " . $getnamestring . ", u.email, up.value, u.mailformat, u.suspended, u.maildisplay FROM {role_assignments} ra JOIN {user} u ON u.id = ra.userid @@ -439,7 +448,7 @@ public static function get_all_users($context){ JOIN {role} r ON ra.roleid = r.id WHERE (ra.contextid = ? ) "; - $everyone = $DB->get_records_sql($sql, array($context->id)); + $everyone = $DB->get_records_sql($sql, [$context->id]); return $everyone; } @@ -453,17 +462,17 @@ public static function get_all_users($context){ * @param $context moodle context id * @param $courseid the course id */ - public static function get_non_suspended_users($context, $courseid){ + public static function get_non_suspended_users($context, $courseid) { global $DB, $CFG; $everyone = self::get_all_users($context); - $get_name_string = 'u.firstname, u.lastname'; + $getnamestring = 'u.firstname, u.lastname'; - if($CFG->version >= 2013111800){ - $get_name_string = block_quickmail_get_all_user_name_fields('u'); + if ($CFG->version >= 2013111800) { + $getnamestring = block_quickmail_get_all_user_name_fields('u'); } - $sql = "SELECT u.id, " . $get_name_string . " , u.email, up.value, u.username, u.mailformat, u.suspended, u.maildisplay, ue.status + $sql = "SELECT u.id, " . $getnamestring . " , u.email, up.value, u.username, u.mailformat, u.suspended, u.maildisplay, ue.status FROM {user} u JOIN {user_enrolments} ue ON u.id = ue.userid @@ -476,11 +485,11 @@ public static function get_non_suspended_users($context, $courseid){ AND ue.status = ? ORDER BY u.lastname, u.firstname"; - //let's use a recordset in case the enrollment is huge - $rs_valids = $DB->get_recordset_sql($sql, array($courseid, 0)); + // let's use a recordset in case the enrollment is huge + $rsvalids = $DB->get_recordset_sql($sql, [$courseid, 0]); - //container for user_enrolments records - $valids = array(); + // container for user_enrolments records + $valids = []; /** * @TODO use a cleaner mechanism from std lib to do this without iterating over the array @@ -489,37 +498,36 @@ public static function get_non_suspended_users($context, $courseid){ * using the id number as the array key; * this matches the format used by self::get_all_users */ - foreach($rs_valids as $rsv){ + foreach ($rsvalids as $rsv) { $valids[$rsv->id] = $rsv; } - //required to close the recordset - $rs_valids->close(); + // required to close the recordset + $rsvalids->close(); - //get the intersection of self::all_users and this potentially shorter list - $evryone_not_suspended = array_intersect_key($valids, $everyone); + // get the intersection of self::all_users and this potentially shorter list + $evryonenotsuspended = array_intersect_key($valids, $everyone); - return $evryone_not_suspended; + return $evryonenotsuspended; } - public static function clean($failuserids){ - $additional_emails = array(); - $failuserids = explode(',', $failuserids); + public static function clean($failuserids) { + $additionalemails = []; + $failuserids = explode(',', $failuserids); - foreach ($failuserids as $id => $failed_address_or_id) { - if ( ! is_numeric($failed_address_or_id)) { - $additional_emails [] = $failed_address_or_id; + foreach ($failuserids as $id => $failedaddressorid) { + if (! is_numeric($failedaddressorid)) { + $additionalemails[] = $failedaddressorid; - unset($failuserids[$id]); - } - } - - $additional_emails = implode(',', $additional_emails); - $mailto = implode(',', $failuserids); + unset($failuserids[$id]); + } + } - return array($mailto, $additional_emails); - } + $additionalemails = implode(',', $additionalemails); + $mailto = implode(',', $failuserids); + return [$mailto, $additionalemails]; + } } function block_quickmail_pluginfile($course, $record, $context, $filearea, $args, $forcedownload) { @@ -530,12 +538,12 @@ function block_quickmail_pluginfile($course, $record, $context, $filearea, $args require_course_login($course, true, $record); } - list($itemid, $filename) = $args; + [$itemid, $filename] = $args; if ($filearea == 'attachment_log') { - $time = $DB->get_field('block_quickmail_log', 'time', array( - 'id' => $itemid - )); + $time = $DB->get_field('block_quickmail_log', 'time', [ + 'id' => $itemid, + ]); if ("{$time}_attachments.zip" == $filename) { $path = quickmail::zip_attachments($context, 'log', $itemid); @@ -543,12 +551,12 @@ function block_quickmail_pluginfile($course, $record, $context, $filearea, $args } } - $params = array( + $params = [ 'component' => 'block_quickmail', 'filearea' => $filearea, 'itemid' => $itemid, - 'filename' => $filename - ); + 'filename' => $filename, + ]; $instanceid = $DB->get_field('files', 'id', $params); diff --git a/settings.php b/settings.php index 646a09e..b52718b 100644 --- a/settings.php +++ b/settings.php @@ -23,82 +23,102 @@ defined('MOODLE_INTERNAL') || die; -if($ADMIN->fulltree) { +if ($ADMIN->fulltree) { require_once $CFG->dirroot . '/blocks/quickmail/lib.php'; - $select = array(-1 => get_string('never'), 0 => get_string('no'), 1 => get_string('yes')); + $select = [-1 => get_string('never'), 0 => get_string('no'), 1 => get_string('yes')]; $allow = quickmail::_s('allowstudents'); $allowdesc = quickmail::_s('allowstudentsdesc'); $settings->add( - new admin_setting_configselect('block_quickmail_allowstudents', - $allow, $allowdesc, 0, $select + new admin_setting_configselect( + 'block_quickmail_allowstudents', + $allow, + $allowdesc, + 0, + $select ) ); $roles = $DB->get_records('role', null, 'sortorder ASC'); - $default_sns = array('editingteacher', 'teacher', 'student'); - $defaults = array_filter($roles, function ($role) use ($default_sns) { - return in_array($role->shortname, $default_sns); + $defaultsns = ['editingteacher', 'teacher', 'student']; + $defaults = array_filter($roles, function ($role) use ($defaultsns) { + return in_array($role->shortname, $defaultsns); }); - $only_names = function ($role) { return $role->name ? trim(format_string($role->name)) : $role->shortname; }; + $onlynames = function ($role) { + return $role->name ? trim(format_string($role->name)) : $role->shortname; + }; - $select_roles = quickmail::_s('select_roles'); + $selectroles = quickmail::_s('select_roles'); $settings->add( - new admin_setting_configmultiselect('block_quickmail_roleselection', - $select_roles, $select_roles, + new admin_setting_configmultiselect( + 'block_quickmail_roleselection', + $selectroles, + $selectroles, array_keys($defaults), - array_map($only_names, $roles) + array_map($onlynames, $roles) ) ); $settings->add( - new admin_setting_configselect('block_quickmail_receipt', - quickmail::_s('receipt'), quickmail::_s('receipt_help'), - 0, $select + new admin_setting_configselect( + 'block_quickmail_receipt', + quickmail::_s('receipt'), + quickmail::_s('receipt_help'), + 0, + $select ) ); - $options = array( + $options = [ 0 => get_string('none'), 'idnumber' => get_string('idnumber'), - 'shortname' => get_string('shortname') - ); + 'shortname' => get_string('shortname'), + ]; $settings->add( - new admin_setting_configselect('block_quickmail_prepend_class', - quickmail::_s('prepend_class'), quickmail::_s('prepend_class_desc'), - 0, $options + new admin_setting_configselect( + 'block_quickmail_prepend_class', + quickmail::_s('prepend_class'), + quickmail::_s('prepend_class_desc'), + 0, + $options ) ); - $groupoptions = array( + $groupoptions = [ 'strictferpa' => get_string('strictferpa', 'block_quickmail'), 'courseferpa' => get_string('courseferpa', 'block_quickmail'), - 'noferpa' => get_string('noferpa', 'block_quickmail') - ); + 'noferpa' => get_string('noferpa', 'block_quickmail'), + ]; $settings->add( - new admin_setting_configselect('block_quickmail_ferpa', - quickmail::_s('ferpa'), quickmail::_s('ferpa_desc'), - 'strictferpa', $groupoptions + new admin_setting_configselect( + 'block_quickmail_ferpa', + quickmail::_s('ferpa'), + quickmail::_s('ferpa_desc'), + 'strictferpa', + $groupoptions ) ); $settings->add( - new admin_setting_configcheckbox('block_quickmail_downloads', - quickmail::_s('downloads'), quickmail::_s('downloads_desc'), + new admin_setting_configcheckbox( + 'block_quickmail_downloads', + quickmail::_s('downloads'), + quickmail::_s('downloads_desc'), 1 ) ); $settings->add( - new admin_setting_configcheckbox('block_quickmail_addionalemail', - quickmail::_s('addionalemail'), quickmail::_s('addionalemail_desc'), + new admin_setting_configcheckbox( + 'block_quickmail_addionalemail', + quickmail::_s('addionalemail'), + quickmail::_s('addionalemail_desc'), 0 ) ); - } diff --git a/signature.php b/signature.php index 79a43b0..a466944 100644 --- a/signature.php +++ b/signature.php @@ -32,19 +32,19 @@ $flash = optional_param('flash', 0, PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_INT); -if ($courseid and !$course = $DB->get_record('course', array('id' => $courseid))) { +if ($courseid and !$course = $DB->get_record('course', ['id' => $courseid])) { print_error('no_course', 'block_quickmail', '', $courseid); } $config = quickmail::load_config($courseid); $context = context_course::instance($courseid); -$has_permission = ( +$haspermission = ( has_capability('block/quickmail:cansend', $context) or !empty($config['allowstudents']) ); -if (!$has_permission) { +if (!$haspermission) { print_error('no_permission', 'block_quickmail'); } @@ -56,9 +56,9 @@ $PAGE->set_context($context); $PAGE->set_course($course); -$PAGE->set_url('/blocks/quickmail/signature.php', array( - 'courseid' => $courseid, 'id' => $sigid -)); +$PAGE->set_url('/blocks/quickmail/signature.php', [ + 'courseid' => $courseid, 'id' => $sigid, +]); $PAGE->navbar->add($blockname); $PAGE->navbar->add($header); @@ -67,13 +67,13 @@ $PAGE->set_pagetype(quickmail::PAGE_TYPE); $PAGE->set_pagelayout('standard'); -$params = array('userid' => $USER->id); +$params = ['userid' => $USER->id]; $dbsigs = $DB->get_records('block_quickmail_signatures', $params); -$sig = (!empty($sigid) and isset($sigs[$sigid])) ? $sigs[$sigid] : new stdClass; +$sig = (!empty($sigid) and isset($sigs[$sigid])) ? $sigs[$sigid] : new stdClass(); if (empty($sigid) or !isset($dbsigs[$sigid])) { - $sig = new stdClass; + $sig = new stdClass(); $sig->id = null; $sig->title = ''; $sig->signature = ''; @@ -84,28 +84,35 @@ $sig->courseid = $courseid; $sig->signatureformat = $USER->mailformat; -$options = array( +$options = [ 'trusttext' => true, 'subdirs' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, - 'context' => $context + 'context' => $context, +]; + +$sig = file_prepare_standard_editor( + $sig, + 'signature', + $options, + $context, + 'block_quickmail', + 'signature', + $sig->id ); -$sig = file_prepare_standard_editor($sig, 'signature', $options, $context, - 'block_quickmail', 'signature', $sig->id); - -$form = new signature_form(null, array('signature_options' => $options)); +$form = new signature_form(null, ['signature_options' => $options]); if ($confirm) { - $DB->delete_records('block_quickmail_signatures', array('id' => $sigid)); - redirect(new moodle_url('/blocks/quickmail/signature.php', array( + $DB->delete_records('block_quickmail_signatures', ['id' => $sigid]); + redirect(new moodle_url('/blocks/quickmail/signature.php', [ 'courseid' => $courseid, - 'flash' => 1 - ))); + 'flash' => 1, + ])); } if ($form->is_cancelled()) { - redirect(new moodle_url('/course/view.php', array('id' => $courseid))); + redirect(new moodle_url('/course/view.php', ['id' => $courseid])); } else if ($data = $form->get_data()) { if (isset($data->delete)) { $delete = true; @@ -122,7 +129,7 @@ $data->default_flag = 0; } - $params = array('userid' => $USER->id, 'default_flag' => 1); + $params = ['userid' => $USER->id, 'default_flag' => 1]; $default = $DB->get_record('block_quickmail_signatures', $params); if ($default and !empty($data->default_flag)) { @@ -140,14 +147,21 @@ } // Persist relative links - $data = file_postupdate_standard_editor($data, 'signature', $options, - $context, 'block_quickmail', 'signature', $data->id); + $data = file_postupdate_standard_editor( + $data, + 'signature', + $options, + $context, + 'block_quickmail', + 'signature', + $data->id + ); $DB->update_record('block_quickmail_signatures', $data); - $url = new moodle_url('signature.php', array( - 'id' => $data->id, 'courseid' => $course->id, 'flash' => 1 - )); + $url = new moodle_url('signature.php', [ + 'id' => $data->id, 'courseid' => $course->id, 'flash' => 1, + ]); redirect($url); } } @@ -155,11 +169,11 @@ echo $OUTPUT->header(); echo $OUTPUT->heading($header); -$first = array(0 => quickmail::_s('new').' '.quickmail::_s('sig')); -$only_names = function ($sig) { - return ($sig->default_flag) ? $sig->title . ' (Default)': $sig->title; +$first = [0 => quickmail::_s('new') . ' ' . quickmail::_s('sig')]; +$onlynames = function ($sig) { + return ($sig->default_flag) ? $sig->title . ' (Default)' : $sig->title; }; -$sig_options = $first + array_map($only_names, $dbsigs); +$sigoptions = $first + array_map($onlynames, $dbsigs); $form->set_data($sig); @@ -169,18 +183,18 @@ if (!empty($delete)) { $msg = get_string('are_you_sure', 'block_quickmail', $sig); - $confirm_url = new moodle_url('/blocks/quickmail/signature.php', array( + $confirmurl = new moodle_url('/blocks/quickmail/signature.php', [ 'id' => $sig->id, 'courseid' => $courseid, - 'confirm' => 1 - )); - $cancel_url = new moodle_url('/blocks/quickmail/signature.php', array( + 'confirm' => 1, + ]); + $cancelurl = new moodle_url('/blocks/quickmail/signature.php', [ 'id' => $sig->id, - 'courseid' => $courseid - )); - echo $OUTPUT->confirm($msg, $confirm_url, $cancel_url); + 'courseid' => $courseid, + ]); + echo $OUTPUT->confirm($msg, $confirmurl, $cancelurl); } else { - echo $OUTPUT->single_select('signature.php?courseid='.$courseid, 'id', $sig_options, $sigid); + echo $OUTPUT->single_select('signature.php?courseid=' . $courseid, 'id', $sigoptions, $sigid); $form->display(); } diff --git a/signature_form.php b/signature_form.php index c6625ae..eb3f91f 100644 --- a/signature_form.php +++ b/signature_form.php @@ -30,29 +30,34 @@ public function definition() { $mform =& $this->_form; $mform->addElement('hidden', 'courseid', ''); - $mform->setType('courseid',PARAM_INT); - + $mform->setType('courseid', PARAM_INT); + $mform->addElement('hidden', 'id', ''); - $mform->setType('id',PARAM_INT); - + $mform->setType('id', PARAM_INT); + $mform->addElement('hidden', 'userid', $USER->id); - $mform->setType('userid',PARAM_INT); - + $mform->setType('userid', PARAM_INT); + $mform->addElement('text', 'title', quickmail::_s('title')); - $mform->setType('title',PARAM_TEXT); - - $mform->addElement('editor', 'signature_editor', quickmail::_s('sig'), - null, $this->_customdata['signature_options']); + $mform->setType('title', PARAM_TEXT); + + $mform->addElement( + 'editor', + 'signature_editor', + quickmail::_s('sig'), + null, + $this->_customdata['signature_options'] + ); $mform->setType('signature_editor', PARAM_RAW); $mform->addElement('checkbox', 'default_flag', quickmail::_s('default_flag')); - $buttons = array( + $buttons = [ $mform->createElement('submit', 'save', get_string('savechanges')), $mform->createElement('submit', 'delete', get_string('delete')), - $mform->createElement('cancel') - ); + $mform->createElement('cancel'), + ]; - $mform->addGroup($buttons, 'buttons', quickmail::_s('actions'), array(' '), false); + $mform->addGroup($buttons, 'buttons', quickmail::_s('actions'), [' '], false); $mform->addRule('title', null, 'required', null, 'client'); } } From a25817fc7135d71e87829b7b4c4f06bc3672c865 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Thu, 23 May 2024 15:55:40 -0700 Subject: [PATCH 04/46] corrects code linting errors in admin_email script. --- admin_email.php | 52 +++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/admin_email.php b/admin_email.php index 2ab8afc..cad9529 100644 --- a/admin_email.php +++ b/admin_email.php @@ -15,23 +15,25 @@ // along with Moodle. If not, see . /** + * Page for the admin email form. + * * @package block_quickmail * @copyright 2008-2017 Louisiana State University * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +require_once('../../config.php'); global $CFG, $USER, $SESSION, $PAGE, $SITE, $OUTPUT, $DB; -require_once '../../config.php'; -require_once "$CFG->dirroot/course/lib.php"; -require_once "$CFG->libdir/adminlib.php"; -require_once "$CFG->dirroot/user/filters/lib.php"; -require_once 'lib.php'; -require_once 'classes/message.php'; -require_once 'admin_email_form.php'; +require_once("$CFG->dirroot/course/lib.php"); +require_once("$CFG->libdir/adminlib.php"); +require_once("$CFG->dirroot/user/filters/lib.php"); +require_once('lib.php'); +require_once('classes/message.php'); +require_once('admin_email_form.php'); require_login(); -// get page params +// Get page params. $page = optional_param('page', 0, PARAM_INT); $perpage = optional_param('perpage', 20, PARAM_INT); $sort = optional_param('sort', 'lastname', PARAM_ACTION); @@ -47,7 +49,7 @@ $context = context_system::instance(); if (has_capability('block/quickmail:myaddinstance', $context) || is_siteadmin($USER)) { - // page params for ui filter + // Page params for ui filter. $filterparams = $typeid > 0 ? ['courseid' => $courseid, 'type' => $type, 'typeid' => $typeid] : null; $PAGE->set_context($context); @@ -60,9 +62,9 @@ if ($type == 'log') { $logmessage = $DB->get_record('block_quickmail_' . $type, ['id' => $typeid]); - // try to get the saved, serialized filters from mailto. + // Try to get the saved, serialized filters from mailto. if (isset($logmessage->mailto)) { - // will give a Notice if content of mailto in not unserializable. + // Will give a Notice if content of mailto in not unserializable. $filters = @unserialize($logmessage->mailto); if ($filters !== false && is_array($filters) && ( empty($_POST['addfilter']) && empty($_POST['removeselected']) )) { $SESSION->user_filtering = $filters; @@ -70,7 +72,7 @@ } } - // Get Our users + // Get Our users. $fields = [ 'realname' => 1, 'lastname' => 1, @@ -158,14 +160,14 @@ 'editor_options' => $editoroptions, ]); - // Process data submission + // Process data submission. if ($form->is_cancelled()) { unset($SESSION->user_filtering); redirect(new moodle_url('/blocks/quickmail/admin_email.php')); } else if ($data = $form->get_data()) { $message = new Message($data, array_keys($users)); - // @todo refactor so that we're not building two similar structures, namely: $data and $message. + // Todo: Refactor so that we're not building two similar structures, namely: $data and $message. $data->courseid = SITEID; $data->userid = $USER->id; $data->mailto = isset($SESSION->user_filtering) ? serialize($SESSION->user_filtering) : "unknown filter"; @@ -174,14 +176,14 @@ $data->attachment = ''; $data->time = time(); - // save record of the message, regardless of errors. + // Save record of the message, regardless of errors. $data->id = $DB->insert_record('block_quickmail_log', $data); - // Send the messages and save the failed users if there are any + // Send the messages and save the failed users if there are any. $data->failuserids = implode(',', $message->send()); $message->sendAdminReceipt(); - // Finished processing - // Empty errors mean that you can go back home + // Finished processing. + // Empty errors mean that you can go back home. if (empty($message->warnings)) { unset($SESSION->user_filtering); if (is_siteadmin($USER->id)) { @@ -190,13 +192,13 @@ redirect(new moodle_url('/my', null)); } } else { - // update DB to reflect fail status. + // Update DB to reflect fail status. $data->status = quickmail::_s('failed_to_send_to') + count($message->warnings) + quickmail::_s('users'); $DB->update_record('block_quickmail_log', $data); } } - // get data for form + // Get data for form. if (!empty($type)) { $data = $logmessage; $logmessage->messageformat = $USER->mailformat; @@ -213,7 +215,7 @@ $logmessage = new stdClass(); } - // begin output. + // Begin output. echo $OUTPUT->header(); echo $OUTPUT->heading($header); @@ -224,7 +226,7 @@ } } - // Start work + // Start work. if ($fmid != 1) { $ufiltering->display_add(); $ufiltering->display_active(); @@ -251,7 +253,7 @@ if (!empty($displayusers)) { $columns = ['firstname', 'lastname', 'email', 'city', 'lastaccess']; foreach ($columns as $column) { - $direction = ($sort == $column and $direction == "ASC") ? "DESC" : "ASC"; + $direction = ($sort == $column && $direction == "ASC") ? "DESC" : "ASC"; $$column = html_writer::link('admin_email.php?sort=' . $column . '&dir=' . $direction, get_string($column)); } @@ -269,10 +271,10 @@ echo html_writer::table($table); } - // need no-reply in both cases. + // Need no-reply in both cases. $logmessage->noreply = $CFG->noreplyaddress; - // display form and done. + // Display form and done. $form->set_data($logmessage); echo $form->display(); echo $pagingbar; From d4103867c85763958d40b0e7b36b59c67f52bae6 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Thu, 23 May 2024 16:12:04 -0700 Subject: [PATCH 05/46] corrects code linting errors in admin_email_form.php --- admin_email_form.php | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/admin_email_form.php b/admin_email_form.php index bfdb068..11fc23a 100644 --- a/admin_email_form.php +++ b/admin_email_form.php @@ -15,17 +15,31 @@ // along with Moodle. If not, see . /** + * Admin email form. + * * @package block_quickmail * @copyright 2008-2017 Louisiana State University * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -require_once $CFG->libdir . '/formslib.php'; -// describe the form created for admin_emial.php -class admin_email_form extends moodleform { - function definition() { +defined('MOODLE_INTERNAL') || die; + +require_once($CFG->libdir . '/formslib.php'); +/** + * Admin email form. + * + * @package block_quickmail + * @copyright 2008-2017 Louisiana State University + * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class admin_email_form extends moodleform { + /** + * Form definition. + */ + public function definition(): void { $mform =& $this->_form; $mform->addElement('text', 'subject', get_string('subject', 'block_quickmail')); @@ -34,7 +48,13 @@ function definition() { $mform->addElement('text', 'noreply', get_string('noreply', 'block_quickmail')); $mform->setType('noreply', PARAM_EMAIL); - $mform->addElement('editor', 'message_editor', get_string('body', 'block_quickmail'), null, $this->_customdata['editor_options']); + $mform->addElement( + 'editor', + 'message_editor', + get_string('body', 'block_quickmail'), + null, + $this->_customdata['editor_options'] + ); $mform->setType('message', PARAM_RAW); $buttons = [ @@ -48,7 +68,14 @@ function definition() { $mform->addRule('message_editor', null, 'required'); } - function validation($data, $files) { + /** + * Performs additional form validation steps. + * + * @param array $data Submitted form data. + * @param array $files Uploaded form files. + * @return array A list of validation errors. + */ + public function validation($data, $files): array { $errors = []; foreach (['subject', 'message_editor'] as $field) { if (empty($data[$field])) { From e5135307f7a8af22f1076c0af6c27e91cfb584cb Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 24 May 2024 07:53:29 -0700 Subject: [PATCH 06/46] corrects code linting errors in email.php --- email.php | 112 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 42 deletions(-) diff --git a/email.php b/email.php index 96a2fb8..e695119 100644 --- a/email.php +++ b/email.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Page for the email form. + * * @package block_quickmail * @copyright 2008-2017 Louisiana State University * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo @@ -36,31 +38,30 @@ $messageidresend = optional_param('fmid', 0, PARAM_INT); if (!$course = $DB->get_record('course', ['id' => $courseid])) { - print_error('no_course', 'block_quickmail', '', $courseid); + throw new moodle_exception('no_course', 'block_quickmail', '', $courseid); } -if (!empty($type) and !in_array($type, ['log', 'drafts'])) { - print_error('no_type', 'block_quickmail', '', $type); +if (!empty($type) && !in_array($type, ['log', 'drafts'])) { + throw new moodle_exception('no_type', 'block_quickmail', '', $type); } -if (!empty($type) and empty($typeid)) { +if (!empty($type) && empty($typeid)) { $string = new stdclass(); $string->tpe = $type; $string->id = $typeid; - - print_error('no_typeid', 'block_quickmail', '', $string); + throw new moodle_exception('no_typeid', 'block_quickmail', '', $string); } $config = quickmail::load_config($courseid); $context = context_course::instance($courseid); $haspermission = ( - has_capability('block/quickmail:cansend', $context) or + has_capability('block/quickmail:cansend', $context) || !empty($config['allowstudents']) ); if (!$haspermission) { - print_error('no_permission', 'block_quickmail'); + throw new moodle_exception('no_permission', 'block_quickmail'); } $sigs = $DB->get_records('block_quickmail_signatures', ['userid' => $USER->id], 'default_flag DESC'); @@ -97,13 +98,13 @@ $attributes = null; $restrictedview = ( - !has_capability('moodle/site:accessallgroups', $context) and + !has_capability('moodle/site:accessallgroups', $context) && $config['ferpa'] == 'strictferpa' ); $respectedview = ( - !has_capability('moodle/site:accessallgroups', $context) and - $course->groupmode == 1 and + !has_capability('moodle/site:accessallgroups', $context) && + $course->groupmode == 1 && $config['ferpa'] == 'courseferpa' ); @@ -118,7 +119,7 @@ $globalaccess = empty($allgroups); -// Fill the course users by +// Fill the course users by. $users = []; $userstoroles = []; $userstogroups = []; @@ -128,17 +129,17 @@ foreach ($everyone as $userid => $user) { $usergroups = groups_get_user_groups($courseid, $userid); - $gids = ($globalaccess or $mastercap) ? + $gids = ($globalaccess || $mastercap) ? array_values($usergroups['0']) : array_intersect(array_values($mygroups['0']), array_values($usergroups['0'])); $userroles = get_user_roles($context, $userid); $filterd = quickmail::filter_roles($userroles, $roles); - // Available groups + // Available groups. if ( - (!$globalaccess and !$mastercap) and - empty($gids) or empty($filterd) or $userid == $USER->id + (!$globalaccess && !$mastercap) && + empty($gids) || empty($filterd) || $userid == $USER->id ) { continue; } @@ -154,22 +155,25 @@ } } -// if we have no users to email, show an error page with explanation and a link back +// If we have no users to email, show an error page with explanation and a link back. if (empty($users)) { echo $OUTPUT->header(); echo $OUTPUT->heading($blockname); echo $OUTPUT->notification(quickmail::_s('no_usergroups'), 'notifyproblem'); echo html_writer::start_tag('div', ['class' => 'no-overflow']); - echo html_writer::link(new moodle_url('/course/view.php', ['id' => $courseid]), get_string('back_to_previous', 'block_quickmail'), null); + echo html_writer::link( + new moodle_url('/course/view.php', ['id' => $courseid]), + get_string('back_to_previous', 'block_quickmail'), + null + ); echo html_writer::end_tag('div'); echo $OUTPUT->footer(); } else { - // we are presenting the form with values populated from either the log or drafts table in the db + // We are presenting the form with values populated from either the log or drafts table in the db. if (!empty($type)) { $email = $DB->get_record('block_quickmail_' . $type, ['id' => $typeid]); - // $emailmailto = array(); if ($type == 'log') { $attributes = ['id' => "{$typeid}_id_message_editor"]; } @@ -188,7 +192,7 @@ ]); $email->sigid = $defaultsigid ? $defaultsigid : -1; - // Some setters for the form + // Some setters for the form. $email->type = $type; $email->typeid = $typeid; @@ -213,7 +217,16 @@ $selected = []; if (!empty($email->mailto)) { foreach (explode(',', $email->mailto) as $id) { - $selected[$id] = (object) ['id' => $id, 'firstname' => null, 'lastname' => null, 'email' => $id, 'mailformat' => '1', 'suspended' => '0', 'maildisplay' => '2', 'status' => '0']; + $selected[$id] = (object) [ + 'id' => $id, + 'firstname' => null, + 'lastname' => null, + 'email' => $id, + 'mailformat' => '1', + 'suspended' => '0', + 'maildisplay' => '2', + 'status' => '0', + ]; if (is_numeric($selected[$id]->id)) { $selected[$id] = $users[$id]; } @@ -221,7 +234,6 @@ } } - $form = new email_form(null, [ 'editor_options' => $editoroptions, 'selected' => $selected, @@ -249,20 +261,20 @@ $warnings[] = get_string('no_users', 'block_quickmail'); } if (empty($warnings)) { - // Submitted data ////////////////////////////////////////////////////// + // Submitted data. $data->time = time(); $data->format = $data->message_editor['format']; $data->message = $data->message_editor['text']; $data->attachment = quickmail::attachment_names($data->attachments); $data->messageWithSigAndAttach = ""; - // Store data; id is needed for file storage /////////////////////////// + // Store data; id is needed for file storage. if (isset($data->send)) { $data->id = $DB->insert_record('block_quickmail_log', $data); $table = 'log'; } else if (isset($data->draft)) { $table = 'drafts'; - if (!empty($typeid) and $type == 'drafts') { + if (!empty($typeid) && $type == 'drafts') { $data->id = $typeid; $DB->update_record('block_quickmail_drafts', $data); } else { @@ -281,13 +293,13 @@ $DB->update_record('block_quickmail_' . $table, $data); $prepender = $config['prepend_class']; - if (!empty($prepender) and !empty($course->$prepender)) { + if (!empty($prepender) && !empty($course->$prepender)) { $subject = "[{$course->$prepender}] $data->subject"; } else { $subject = $data->subject; } - // An instance id is needed before storing the file repository ///////// + // An instance id is needed before storing the file repository. file_save_draft_area_files( $data->attachments, $context->id, @@ -297,19 +309,35 @@ $editoroptions ); - // Send emails ///////////////////////////////////////////////////////// + // Send emails. if (isset($data->send)) { if ($type == 'drafts') { quickmail::draft_cleanup($context->id, $typeid); } - // deal with possible signature, will be appended to message in a little bit. - if (!empty($sigs) and $data->sigid > -1) { + // Deal with possible signature, will be appended to message in a little bit. + if (!empty($sigs) && $data->sigid > -1) { $sig = $sigs[$data->sigid]; - $signaturetext = file_rewrite_pluginfile_urls($sig->signature, 'pluginfile.php', $context->id, 'block_quickmail', 'signature', $sig->id, $editoroptions); + $signaturetext = file_rewrite_pluginfile_urls( + $sig->signature, + 'pluginfile.php', + $context->id, + 'block_quickmail', + 'signature', + $sig->id, + $editoroptions + ); } - // Prepare html content of message ///////////////////////////////// - $data->message = file_rewrite_pluginfile_urls($data->message, 'pluginfile.php', $context->id, 'block_quickmail', $table, $data->id, $editoroptions); + // Prepare html content of message. + $data->message = file_rewrite_pluginfile_urls( + $data->message, + 'pluginfile.php', + $context->id, + 'block_quickmail', + $table, + $data->id, + $editoroptions + ); if (empty($signaturetext)) { $data->messageWithSigAndAttach = $data->message; @@ -320,7 +348,7 @@ $data->messageWithSigAndAttach = $data->message . "

" . $signaturetext; } } - // Append links to attachments, if any ///////////////////////////// + // Append links to attachments, if any. $data->messageWithSigAndAttach .= quickmail::process_attachments( $context, $data, @@ -328,7 +356,7 @@ $data->id ); - // Same user, alternate email ////////////////////////////////////// + // Same user, alternate email. if (!empty($data->alternateid)) { $user = clone($USER); $user->email = $alternates[$data->alternateid]; @@ -336,19 +364,19 @@ $user = $USER; } $data->failuserids = []; - // DWE -> Begin hopefully new way of dealing with messagetext and messagehtml + // DWE -> Begin hopefully new way of dealing with messagetext and messagehtml. - // TEXT + // TEXT. // This is where we'll need to factor in the preferences of the receiver. $messagetext = format_text_email($data->messageWithSigAndAttach, $data->format); - // HTML + // HTML. $options = ['filter' => false]; $messagehtml = format_text($data->messageWithSigAndAttach, $data->format, $options); if (!empty($data->mailto)) { foreach (explode(',', $data->mailto) as $userid) { - // Email gets sent here + // Email gets sent here. if ($everyone[$userid]->value) { $everyone[$userid]->email = $everyone[$userid]->value; } @@ -378,12 +406,12 @@ $fakeuser = new stdClass(); $fakeuser->id = 99999900 + $i; $fakeuser->email = $additionalemail; - // TODO make this into a menu option + // Todo: Make this into a menu option. $fakeuser->mailformat = 1; $additionalemailsuccess = email_to_user($fakeuser, $user, $subject, $messagetext, $messagehtml); if (!$additionalemailsuccess) { $data->failuserids[] = $additionalemail; - // will need to notify that an email is incorrect + // Will need to notify that an email is incorrect. $warnings[] = get_string("no_email_address", 'block_quickmail', $fakeuser->email); } $i++; From fdfa4f56131e0b9309e73dab8cd28f8fd1e62174 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 24 May 2024 08:13:12 -0700 Subject: [PATCH 07/46] corrects code linting errors in language files. --- lang/en/block_quickmail.php | 31 +++++++++++++++++++++++++++---- lang/en_us/block_quickmail.php | 33 ++++++++++++++++++++++++++++----- lang/sv/block_quickmail.php | 7 ++----- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/lang/en/block_quickmail.php b/lang/en/block_quickmail.php index a6f1752..94d772d 100644 --- a/lang/en/block_quickmail.php +++ b/lang/en/block_quickmail.php @@ -1,4 +1,27 @@ . + +/** + * English language pack. + * + * @package block_quickmail + * @copyright 2008-2017 Louisiana State University + * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ $string['allusers'] = ' All Users'; $string['pluginname'] = 'Quickmail'; $string['sendadmin'] = 'Admin Email'; @@ -63,7 +86,7 @@ $string['qm_contents'] = 'Download File Contents'; $string['back_to_previous'] = 'Back to previous page'; -// Config form strings +// Config form strings. $string['allowstudents'] = 'Allow students to use Quickmail'; $string['allowstudentsdesc'] = 'Allow students to use Quickmail. If you choose "Never", the block cannot be configured to allow students access at the course level.'; @@ -103,7 +126,7 @@ $string['are_you_sure'] = 'Are you sure you want to delete {$a->title}? This action cannot be reversed.'; -// Alternate Email strings +// Alternate Email strings. $string['alternate_new'] = 'Add Alternate Address'; $string['sure'] = 'Are you sure you want to delete {$a->address}? This action cannot be undone.'; $string['valid'] = 'Activation Status'; @@ -140,7 +163,7 @@ '; -// Strings for Error Reporting +// Strings for Error Reporting. $string['sent_success'] = 'all messages sent successfully'; $string['logsuccess'] = 'all messages sent successfully'; $string['message_failure'] = 'some users did not get message'; @@ -152,7 +175,7 @@ $string['draftssuccess'] = "Draft"; -// admin +// Admin. $string['sendadmin'] = 'Send Admin Email'; $string['noreply'] = 'No-Reply'; $string['body'] = 'Body'; diff --git a/lang/en_us/block_quickmail.php b/lang/en_us/block_quickmail.php index 64f23d7..d1d1145 100644 --- a/lang/en_us/block_quickmail.php +++ b/lang/en_us/block_quickmail.php @@ -1,4 +1,27 @@ . + +/** + * US-English language pack. + * + * @package block_quickmail + * @copyright 2008-2017 Louisiana State University + * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ $string['allusers'] = ' All Users'; $string['pluginname'] = 'Quickmail'; $string['sendadmin'] = 'Admin Email'; @@ -62,7 +85,7 @@ $string['download_all'] = 'Download All'; $string['qm_contents'] = 'Download File Contents'; -// Config form strings +// Config form strings. $string['allowstudents'] = 'Allow students to use Quickmail'; $string['allowstudentsdesc'] = 'Allow students to use Quickmail. If you choose "Never", the block cannot be configured to allow students access at the course level.'; @@ -102,7 +125,7 @@ $string['are_you_sure'] = 'Are you sure you want to delete {$a->title}? This action cannot be reversed.'; -// Alternate Email strings +// Alternate Email strings. $string['alternate_new'] = 'Add Alternate Address'; $string['sure'] = 'Are you sure you want to delete {$a->address}? This action cannot be undone.'; $string['valid'] = 'Activation Status'; @@ -139,7 +162,7 @@ '; -// Strings for Error Reporting +// Strings for Error Reporting. $string['sent_success'] = 'all messages sent successfully'; $string['logsuccess'] = 'all messages sent successfully'; $string['message_failure'] = 'some users did not get message'; @@ -151,7 +174,7 @@ $string['draftssuccess'] = "Draft"; -// admin +// Admin. $string['sendadmin'] = 'Send Admin Email'; $string['noreply'] = 'No-Reply'; $string['body'] = 'Body'; @@ -169,6 +192,6 @@ $string['time_elapsed'] = 'Time Elapsed: '; $string['additional_emails'] = 'Additional Emails'; $string['additional_emails_help'] = 'Other email addresses you would like the message sent to, in a comma or semicolon separated list. Example: - + email1@example.com, email2@example.com '; diff --git a/lang/sv/block_quickmail.php b/lang/sv/block_quickmail.php index b544f29..3bf9f16 100644 --- a/lang/sv/block_quickmail.php +++ b/lang/sv/block_quickmail.php @@ -1,5 +1,4 @@ . /** - * Swedish language pack by Linnaeus University + * Swedish language pack by Linnaeus University. * * @package block_quickmail * @subpackage quickmail + * @copyright Linnaeus University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - $string['add_all'] = 'Lägg till alla'; $string['add_button'] = 'Lägg till'; $string['all_sections'] = 'Alla sektioner'; From ee8bdb48ae8a0fd7988644ea7fca7843ccb8737a Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 24 May 2024 08:16:04 -0700 Subject: [PATCH 08/46] Corrects PHP linter errors in version.php --- version.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/version.php b/version.php index f1f0261..aab0ae7 100644 --- a/version.php +++ b/version.php @@ -15,11 +15,13 @@ // along with Moodle. If not, see . /** + * Version information for block_quickmail plugin. * @package block_quickmail * @copyright 2008-2017 Louisiana State University * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); $plugin->version = 2024032300; $plugin->requires = 2023100400; From 8602a07f1ac7a010a81a40b3c61f00caa8303c69 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 24 May 2024 08:18:39 -0700 Subject: [PATCH 09/46] corrects PHP linting errors in alternate.php --- alternate.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/alternate.php b/alternate.php index 42beeac..eeacde3 100644 --- a/alternate.php +++ b/alternate.php @@ -15,16 +15,17 @@ // along with Moodle. If not, see . /** + * Page for alternate email form. * @package block_quickmail * @copyright 2008-2017 Louisiana State University * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -require_once '../../config.php'; -require_once 'lib.php'; -require_once 'alt_lib.php'; -require_once 'alt_form.php'; +require_once('../../config.php'); +require_once('lib.php'); +require_once('alt_lib.php'); +require_once('alt_form.php'); $courseid = required_param('courseid', PARAM_INT); $action = optional_param('action', 'view', PARAM_TEXT); @@ -34,7 +35,7 @@ $course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST); $context = context_course::instance($courseid); -// Permission +// Permission. require_login($course); require_capability('block/quickmail:allowalternate', $context); @@ -57,7 +58,7 @@ $PAGE->set_pagelayout('standard'); if (!method_exists('quickmail_alternate', $action)) { - // Always fallback on view + // Always fallback on view. $action = 'view'; } From 8b08f0b56511110044f266945ecc0815b2e6f67f Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 24 May 2024 09:38:30 -0700 Subject: [PATCH 10/46] corrects PHP linting erros in alt_lib.php --- alt_lib.php | 125 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 116 insertions(+), 9 deletions(-) diff --git a/alt_lib.php b/alt_lib.php index 3820ef2..12d6325 100644 --- a/alt_lib.php +++ b/alt_lib.php @@ -15,27 +15,74 @@ // along with Moodle. If not, see . /** + * Class library for alternate email functionality. + * * @package block_quickmail * @copyright 2008-2017 Louisiana State University * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + +// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses +/** + * Alternate action interface. + * + * @package block_quickmail + * @copyright 2008-2017 Louisiana State University + * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ interface quickmail_alternate_actions { + /** @var string View action. */ const VIEW = 'view'; + + /** @var string Delete Action */ const DELETE = 'delete'; + + /** @var string Interact action. */ const INTERACT = 'interact'; + + /** @var string Confirmed action. */ const CONFIRMED = 'confirmed'; + + /** @var string Information action. */ const INFORMATION = 'inform'; + + /** @var string Verify action. */ const VERIFY = 'verify'; } +/** + * Alternate action base class. + * + * @package block_quickmail + * @copyright 2008-2017 Louisiana State University + * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ abstract class quickmail_alternate implements quickmail_alternate_actions { + /** + * Creates and returns a base URL to the alternate email page for a given course. + * + * @param int $courseid The course ID. + * @param array $additional Additional URL query parameters. + * @return moodle_url The generated URL. + * @throws moodle_exception + */ private static function base_url($courseid, $additional = []) { $params = ['courseid' => $courseid] + $additional; return new moodle_url('/blocks/quickmail/alternate.php', $params); } + /** + * Retrieves a list of alternate email records for a given course. + * + * @param stdClass $course A course object. + * @return array A list of alternate email records. + * @throws dml_exception + */ public static function get($course) { global $DB; @@ -43,6 +90,12 @@ public static function get($course) { return $DB->get_records('block_quickmail_alternate', $params, 'valid DESC'); } + /** + * Retrieves a alternate email record by its ID. + * @param int $id The ID. + * @return stdClass The alternate email record. + * @throws dml_exception If none or multiples are found. + */ public static function get_one($id) { global $DB; @@ -50,6 +103,14 @@ public static function get_one($id) { return $DB->get_record('block_quickmail_alternate', $params, '*', MUST_EXIST); } + /** + * Returns the markup for an alternate email deletion confirmation dialog. + * @param stdClass $course The course. + * @param int $id The alternate email ID. + * @return string The deletion confirmation dialog markup. + * @throws dml_exception + * @throws moodle_exception + */ public static function delete($course, $id) { global $OUTPUT, $DB; @@ -64,6 +125,15 @@ public static function delete($course, $id) { return $OUTPUT->confirm(quickmail::_s('sure', $email), $confirmurl, $cancelurl); } + /** + * Deletes a given alternate email, then redirects the user to the alternate email page for a given course. + * + * @param stdClass $course The course. + * @param int $id The alternate email ID. + * @return null + * @throws dml_exception + * @throws moodle_exception + */ public static function confirmed($course, $id) { global $DB; @@ -72,6 +142,16 @@ public static function confirmed($course, $id) { return redirect(self::base_url($course->id, ['flash' => 1])); } + /** + * Verifies the given alternate email and prints a notification dialog to the user on completion. + * + * @param stdClass $course The course. + * @param int $id The alternate email ID. + * @return string The notification dialog markup. + * @throws coding_exception + * @throws dml_exception + * @throws moodle_exception + */ public static function verify($course, $id) { global $DB, $OUTPUT; @@ -89,13 +169,13 @@ public static function verify($course, $id) { $backurl = self::base_url($course->id); - // Pass through already valid entries + // Pass through already valid entries. if ($entry->valid) { redirect($backurl); } - // Verify key - if (empty($value) or !$key = $DB->get_record('user_private_key', $params)) { + // Verify key. + if (empty($value) || !$key = $DB->get_record('user_private_key', $params)) { $reactivate = self::base_url($course->id, [ 'id' => $id, 'action' => self::INFORMATION, ]); @@ -105,7 +185,7 @@ public static function verify($course, $id) { return $html; } - // One at a time...They can resend the link if they want + // One at a time...They can resend the link if they want. delete_user_key('blocks/quickmail', $userid); $entry->valid = 1; @@ -119,13 +199,22 @@ public static function verify($course, $id) { return $html; } + /** + * Sends a verification email to a given alternate email and prints a notification dialog to the user on completion. + * @param stdClass $course The course. + * @param int $id The alternate email ID. + * @return string The notification dialog markup. + * @throws coding_exception + * @throws dml_exception + * @throws moodle_exception + */ public static function inform($course, $id) { global $DB, $OUTPUT, $USER; $entry = self::get_one($id); - // No restriction - // Valid forever + // No restriction. + // Valid forever. $value = get_user_key('blocks/quickmail', $USER->id, $course->id); $url = self::base_url($course->id); @@ -146,7 +235,7 @@ public static function inform($course, $id) { $htmlbody = quickmail::_s('alternate_body', $a); $body = strip_tags($htmlbody); - // Send email + // Send email. $user = clone($USER); $user->email = $entry->address; $user->firstname = quickmail::_s('pluginname'); @@ -179,6 +268,14 @@ public static function inform($course, $id) { return $html; } + /** + * Returns edit form for a given alternate email, or saves/cancels edits. + * @param stdClass $course The course used as context for the redirect on save/cancel. + * @param int $id The alternate email id. + * @return string|null The markup for the edit form, or no return value on save/cancel. + * @throws dml_exception + * @throws moodle_exception + */ public static function interact($course, $id) { $form = new quickmail_alternate_form(null, [ 'course' => $course, 'action' => self::INTERACT, @@ -189,7 +286,7 @@ public static function interact($course, $id) { } else if ($data = $form->get_data()) { global $DB; - // Check if email exists in this course + // Check if email exists in this course. $older = $DB->get_record('block_quickmail_alternate', [ 'address' => $data->address, 'courseid' => $data->courseid, ]); @@ -224,7 +321,7 @@ public static function interact($course, $id) { $form->set_data(self::get_one($id)); } - // MDL-31677 + // See: MDL-31677. $reflect = new ReflectionClass('quickmail_alternate_form'); $formfield = $reflect->getProperty('_form'); $formfield->setAccessible(true); @@ -232,6 +329,14 @@ public static function interact($course, $id) { return $formfield->getValue($form)->toHtml(); } + /** + * Prints out alternative emails for a given course. + * @param stdClass $course The course. + * @return string The markup. + * @throws coding_exception + * @throws dml_exception + * @throws moodle_exception + */ public static function view($course) { global $OUTPUT; @@ -290,3 +395,5 @@ public static function view($course) { return $html; } } +// phpcs:enable PSR1.Classes.ClassDeclaration.MultipleClasses + From a0a439d2ea47897df7c89f41d6124ecd02142b56 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 24 May 2024 09:52:01 -0700 Subject: [PATCH 11/46] Corrects PHP linter errors in alt_form.php --- alt_form.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/alt_form.php b/alt_form.php index 3e2ae96..a30ad41 100644 --- a/alt_form.php +++ b/alt_form.php @@ -15,16 +15,34 @@ // along with Moodle. If not, see . /** + * Alternate email form file. + * * @package block_quickmail * @copyright 2008-2017 Louisiana State University * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -require_once $CFG->libdir . '/formslib.php'; +defined('MOODLE_INTERNAL') || die(); +require_once($CFG->libdir . '/formslib.php'); + +/** + * The alternate email form. + * + * @package block_quickmail + * @copyright 2008-2017 Louisiana State University + * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class quickmail_alternate_form extends moodleform { - function definition() { + /** + * The form definition. + * + * @return void + * @throws coding_exception + */ + protected function definition(): void { $m =& $this->_form; $course = $this->_customdata['course']; From a62affffc5770c69d58899eed7d6146f1c384250 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 24 May 2024 09:52:42 -0700 Subject: [PATCH 12/46] aligns function visibility scope of definition() with overwritten parent method. --- admin_email_form.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/admin_email_form.php b/admin_email_form.php index 11fc23a..1db67a5 100644 --- a/admin_email_form.php +++ b/admin_email_form.php @@ -37,9 +37,12 @@ */ class admin_email_form extends moodleform { /** - * Form definition. + * The form definition. + * + * @return void + * @throws coding_exception */ - public function definition(): void { + protected function definition(): void { $mform =& $this->_form; $mform->addElement('text', 'subject', get_string('subject', 'block_quickmail')); From 04d49410af755f0cdf58b4538841f115ea0da8eb Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 24 May 2024 09:55:49 -0700 Subject: [PATCH 13/46] Corrects PHP linter errors in signature_form.php realigns visibility of definition() method with its overridden parent method while at it. --- signature_form.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/signature_form.php b/signature_form.php index eb3f91f..7ba5a06 100644 --- a/signature_form.php +++ b/signature_form.php @@ -15,16 +15,33 @@ // along with Moodle. If not, see . /** + * Signature form file. + * * @package block_quickmail * @copyright 2008-2017 Louisiana State University * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die; + require_once($CFG->libdir . '/formslib.php'); +/** + * The signature form. + * + * @package block_quickmail + * @copyright 2008-2017 Louisiana State University + * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class signature_form extends moodleform { - public function definition() { + /** + * The form definition. + * @return void + * @throws coding_exception + */ + protected function definition(): void { global $USER; $mform =& $this->_form; From d0b55a558f4983f4adb9443630d6eccc4b5db1e3 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 24 May 2024 10:01:51 -0700 Subject: [PATCH 14/46] Corrects PHP linter errors in signature.php --- signature.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/signature.php b/signature.php index a466944..b790a45 100644 --- a/signature.php +++ b/signature.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * The email signature page. + * * @package block_quickmail * @copyright 2008-2017 Louisiana State University * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo @@ -22,30 +24,29 @@ */ require_once('../../config.php'); +require_login(); require_once('lib.php'); require_once('signature_form.php'); -require_login(); - $courseid = required_param('courseid', PARAM_INT); $sigid = optional_param('id', 0, PARAM_INT); $flash = optional_param('flash', 0, PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_INT); -if ($courseid and !$course = $DB->get_record('course', ['id' => $courseid])) { - print_error('no_course', 'block_quickmail', '', $courseid); +if ($courseid && !$course = $DB->get_record('course', ['id' => $courseid])) { + throw new moodle_exception('no_course', 'block_quickmail', '', $courseid); } $config = quickmail::load_config($courseid); $context = context_course::instance($courseid); $haspermission = ( - has_capability('block/quickmail:cansend', $context) or + has_capability('block/quickmail:cansend', $context) || !empty($config['allowstudents']) ); if (!$haspermission) { - print_error('no_permission', 'block_quickmail'); + throw new moodle_exception('no_permission', 'block_quickmail'); } $blockname = quickmail::_s('pluginname'); @@ -70,9 +71,9 @@ $params = ['userid' => $USER->id]; $dbsigs = $DB->get_records('block_quickmail_signatures', $params); -$sig = (!empty($sigid) and isset($sigs[$sigid])) ? $sigs[$sigid] : new stdClass(); +$sig = (!empty($sigid) && isset($sigs[$sigid])) ? $sigs[$sigid] : new stdClass(); -if (empty($sigid) or !isset($dbsigs[$sigid])) { +if (empty($sigid) || !isset($dbsigs[$sigid])) { $sig = new stdClass(); $sig->id = null; $sig->title = ''; @@ -122,7 +123,7 @@ $warnings[] = quickmail::_s('required'); } - if (empty($warnings) and empty($delete)) { + if (empty($warnings) && empty($delete)) { $data->signature = $data->signature_editor['text']; if (empty($data->default_flag)) { @@ -132,7 +133,7 @@ $params = ['userid' => $USER->id, 'default_flag' => 1]; $default = $DB->get_record('block_quickmail_signatures', $params); - if ($default and !empty($data->default_flag)) { + if ($default && !empty($data->default_flag)) { $default->default_flag = 0; $DB->update_record('block_quickmail_signatures', $default); } @@ -146,7 +147,7 @@ $data->id = $DB->insert_record('block_quickmail_signatures', $data); } - // Persist relative links + // Persist relative links. $data = file_postupdate_standard_editor( $data, 'signature', From 890d3218feb05b4dc8b19fa3819ad86020cfbbbf Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 24 May 2024 10:30:58 -0700 Subject: [PATCH 15/46] Corrects PHP linting errors in block_quickmail.php --- block_quickmail.php | 47 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/block_quickmail.php b/block_quickmail.php index 7f26b06..6f343c1 100644 --- a/block_quickmail.php +++ b/block_quickmail.php @@ -15,20 +15,36 @@ // along with Moodle. If not, see . /** + * The quickmail block. * @package block_quickmail * @copyright 2008-2017 Louisiana State University * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + require_once($CFG->dirroot . '/blocks/quickmail/lib.php'); +/** + * The quickmail block class. + * @package block_quickmail + * @copyright 2008-2017 Louisiana State University + * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class block_quickmail extends block_list { - function init() { + /** + * Set the initial properties for the block. + */ + public function init(): void { $this->title = quickmail::_s('pluginname'); } - function applicable_formats() { + /** + * {@inheritdoc} + */ + public function applicable_formats(): array { global $USER; if (is_siteadmin($USER->id) || has_capability('block/quickmail:myaddinstance', context_system::instance())) { return ['site' => true, 'my' => true, 'course-view' => true, 'mod-scorm-view' => true]; @@ -36,18 +52,25 @@ function applicable_formats() { return ['site' => false, 'my' => false, 'course-view' => true, 'mod-scorm-view' => true]; } } - function has_config() { + + /** + * {@inheritdoc} + */ + public function has_config(): bool { return true; } + /** - * Disable multiple instances of this block - * @return bool Returns false + * {@inheritdoc} */ - function instance_allow_multiple() { + public function instance_allow_multiple(): bool { return false; } - function get_content() { + /** + * {@inheritdoc} + */ + public function get_content(): stdClass { global $USER, $CFG, $COURSE, $OUTPUT; if ($this->content !== null) { @@ -64,7 +87,7 @@ function get_content() { $config = quickmail::load_config($COURSE->id); $permission = has_capability('block/quickmail:cansend', $context); - $cansend = ($permission or !empty($config['allowstudents'])); + $cansend = ($permission || !empty($config['allowstudents'])); $iconclass = ['class' => 'icon']; @@ -126,7 +149,12 @@ function get_content() { } } - if ((has_capability('block/quickmail:myaddinstance', context_system::instance()) || is_siteadmin($USER->id)) && $COURSE->id == SITEID) { + if ( + ( + has_capability('block/quickmail:myaddinstance', context_system::instance()) || + is_siteadmin($USER->id) + ) && $COURSE->id == SITEID + ) { $sendadminemailstr = quickmail::_s('sendadmin'); $icon = $OUTPUT->pix_icon('t/email', $sendadminemailstr, 'moodle', $iconclass); $sendadminemail = html_writer::link( @@ -145,7 +173,6 @@ function get_content() { $this->content->items[] = $history; } - return $this->content; } } From 6ca686be14b3fd251c0b7c5b40d493a0da3886d0 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 24 May 2024 10:52:28 -0700 Subject: [PATCH 16/46] Corrects PHP linter errors in email_form.php --- email_form.php | 60 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/email_form.php b/email_form.php index 22200a0..71b8da4 100644 --- a/email_form.php +++ b/email_form.php @@ -15,22 +15,45 @@ // along with Moodle. If not, see . /** + * The email form. + * * @package block_quickmail * @copyright 2008-2017 Louisiana State University * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + require_once($CFG->libdir . '/formslib.php'); $PAGE->requires->js('/blocks/quickmail/validation.js'); +/** + * The email form class. + * + * @package block_quickmail + * @copyright 2008-2017 Louisiana State University + * @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class email_form extends moodleform { - private function reduce_users($in, $user) { + /** + * Returns an '; } - private function option_display($user) { + /** + * Returns the text for an