MDL-73935 user: Update support form to not require SMTP setting

This commit is contained in:
Michael Hawkins
2022-02-28 12:42:47 +08:00
parent 9cd77c4130
commit a0b3cf4898
6 changed files with 43 additions and 37 deletions
+1 -1
View File
@@ -374,7 +374,7 @@ $string['configstatsruntimestart'] = 'What time should the cronjob that does the
$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.';
+1 -1
View File
@@ -321,7 +321,7 @@
#page-user-contactsitesupport {
.supporticon {
i {
font-size: 64px;
font-size: 35px;
}
}
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
+22 -22
View File
@@ -38,34 +38,34 @@ $PAGE->has_secondary_navigation_setter(false);
$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;
@@ -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:[email protected]\">[email protected]</a>"
"supportemail": "<a href=\"mailto:[email protected]\">[email protected]</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>