Skip to content

Commit

Permalink
MDL-73935 user: Update support form to not require SMTP setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mickhawkins committed Feb 28, 2022
1 parent 9cd77c4 commit a0b3cf4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lang/en/admin.php
Expand Up @@ -374,7 +374,7 @@
$string['configstatsuserthreshold'] = 'This setting specifies the minimum number of enrolled users for a course to be included in statistics calculations.';
$string['configstrictformsrequired'] = 'If enabled, users are prevented from entering a space or line break only in required fields in forms.';
$string['configstripalltitletags'] = 'Uncheck this setting to allow HTML tags in activity and resource names.';
$string['configsupportemail'] = 'If SMTP is configured on this site and a support page is not configured, this email address will be sent general help requests submitted through the support form (for example, when new users create their own accounts). If SMTP is not configured, this email address will be displayed to logged in users on the support form page.';
$string['configsupportemail'] = 'If SMTP is configured on this site and a support page is not configured, this email address will be sent general help requests submitted through the support form (for example, when new users create their own accounts). If sending fails, this email address will be displayed to logged in users.';
$string['configsupportname'] = 'This is the name of a person or other entity offering general help via the support email or web address.';
$string['configsupportpage'] = 'This web address will be published to users of this site as the one to go to when they need general help (for example, when new users create their own accounts). If this address is left blank then a link to the support email form will be supplied.';
$string['configtempdatafoldercleanup'] = 'Remove temporary data files from the data folder that are older than the selected time.';
Expand Down
2 changes: 1 addition & 1 deletion theme/boost/scss/moodle/user.scss
Expand Up @@ -321,7 +321,7 @@
#page-user-contactsitesupport {
.supporticon {
i {
font-size: 64px;
font-size: 35px;
}

}
Expand Down
2 changes: 1 addition & 1 deletion theme/boost/style/moodle.css
Expand Up @@ -17150,7 +17150,7 @@ body.path-question-type .mform fieldset.hidden {
display: block; }

#page-user-contactsitesupport .supporticon i {
font-size: 64px; }
font-size: 35px; }

.search-results .result {
margin-left: 0;
Expand Down
2 changes: 1 addition & 1 deletion theme/classic/style/moodle.css
Expand Up @@ -17150,7 +17150,7 @@ body.path-question-type .mform fieldset.hidden {
display: block; }

#page-user-contactsitesupport .supporticon i {
font-size: 64px; }
font-size: 35px; }

.search-results .result {
margin-left: 0;
Expand Down
44 changes: 22 additions & 22 deletions user/contactsitesupport.php
Expand Up @@ -38,34 +38,34 @@
$user = isloggedin() && !isguestuser() ? $USER : null;
$renderer = $PAGE->get_renderer('user');

if (!$CFG->smtphosts) {
$supportemail = $CFG->supportemail;
$templatectx = $user ? ['supportemail' => html_writer::link("mailto:{$supportemail}", $supportemail)] : [];
$output = $renderer->render_from_template('user/contact_site_support_not_available', $templatectx);
} else {
$form = new \core_user\form\contactsitesupport_form(null, $user);
if ($form->is_cancelled()) {
redirect($CFG->wwwroot);
} else if ($form->is_submitted() && $form->is_validated() && confirm_sesskey()) {
$data = $form->get_data();
$form = new \core_user\form\contactsitesupport_form(null, $user);
if ($form->is_cancelled()) {
redirect($CFG->wwwroot);
} else if ($form->is_submitted() && $form->is_validated() && confirm_sesskey()) {
$data = $form->get_data();

$from = $user ?? core_user::get_noreply_user();
$subject = get_string('supportemailsubject', 'admin', format_string($SITE->fullname));
$data->notloggedinuser = (!$user);
$message = $renderer->render_from_template('user/contact_site_support_email_body', $data);
$from = $user ?? core_user::get_noreply_user();
$subject = get_string('supportemailsubject', 'admin', format_string($SITE->fullname));
$data->notloggedinuser = (!$user);
$message = $renderer->render_from_template('user/contact_site_support_email_body', $data);

if (!email_to_user(core_user::get_support_user(), $from, $subject, $message)) {
$form->set_data($data);
$notificationmessage = get_string('supportmessagenotsent', 'user');
\core\notification::add($notificationmessage, \core\output\notification::NOTIFY_ERROR);
} else {
$level = \core\output\notification::NOTIFY_SUCCESS;
redirect($CFG->wwwroot, get_string('supportmessagesent', 'user'), 3, $level);
}
if (!email_to_user(core_user::get_support_user(), $from, $subject, $message)) {
$supportemail = $CFG->supportemail;
$form->set_data($data);
$templatectx = [
'supportemail' => $user ? html_writer::link("mailto:{$supportemail}", $supportemail) : false,
'supportform' => $form->render(),
];

$output = $renderer->render_from_template('user/contact_site_support_not_available', $templatectx);
} else {
$level = \core\output\notification::NOTIFY_SUCCESS;
redirect($CFG->wwwroot, get_string('supportmessagesent', 'user'), 3, $level);
}
} else {
$output = $form->render();
}

echo $OUTPUT->header();

echo $output;
Expand Down
28 changes: 17 additions & 11 deletions user/templates/contact_site_support_not_available.mustache
Expand Up @@ -17,23 +17,29 @@
{{!
@template core_user/contact_site_support_not_available
Fallback for the contact support page if smtp is not configured.
Content displayed on the contact site support page if attempting to submit the support form fails.
Example context (json):
{
"supportemail": "<a href=\"mailto:support@mail.com\">support@mail.com</a>"
"supportemail": "<a href=\"mailto:support@mail.com\">support@mail.com</a>",
"supportform": "<input type='text' value='test'>"
}
}}
<div class="card">
<div class="card-body bg-light text-center">
<div class="supporticon mt-6">{{#pix}}t/life-ring, core{{/pix}}</div>
<div class="my-3 p-3 h3 font-weight-normal">{{#str}}supportmessagenotsent, user{{/str}}</div>
{{#supportemail}}
<div class="mb-6 p-3">
<span class="w-75 rounded border p-3">
{{#str}}supportmessagealternative, user, {{{supportemail}}}{{/str}}
</span>
<div class="card-body bg-light d-flex flex-row">
<div class="p-3 mr-3 align-self-center supporticon">{{#pix}}t/life-ring, core{{/pix}}</div>
<div class = "p-1 align-self-center text-muted">
<div class="h4 font-weight-normal mb-0">{{#str}}supportmessagenotsent, user{{/str}}</div>
{{#supportemail}}
<div class="py-3 mt-2">
<span class="h5 font-weight-normal w-75 rounded border p-3">
{{#str}}supportmessagealternative, user, {{{supportemail}}}{{/str}}
</span>
</div>
{{/supportemail}}
</div>
{{/supportemail}}
</div>
</div>
<div class="py-1 pt-3">
{{{supportform}}}
</div>

0 comments on commit a0b3cf4

Please sign in to comment.