1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* The eduplayer share configuration form
|
|
|
19 |
*
|
|
|
20 |
* It uses the standard core Moodle formslib. For more info about them, please
|
|
|
21 |
* visit: http://docs.moodle.org/en/Development:lib/formslib.php
|
|
|
22 |
*
|
|
|
23 |
* @package mod
|
|
|
24 |
* @subpackage eduplayer
|
|
|
25 |
* @author Humanage Srl <info@humanage.it>
|
|
|
26 |
* @copyright 2013 Humanage Srl <info@humanage.it>
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
defined('MOODLE_INTERNAL') || die();
|
|
|
31 |
|
|
|
32 |
require_once("$CFG->libdir/formslib.php");
|
|
|
33 |
|
|
|
34 |
class shareform_form extends moodleform {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Defines forms elements
|
|
|
38 |
*/
|
|
|
39 |
public function definition() {
|
|
|
40 |
global $CFG;
|
|
|
41 |
|
|
|
42 |
$f = $this->_form;
|
|
|
43 |
$f->addElement('html', '<p>'. get_string('sharetext', 'eduplayer') .'</p>');
|
|
|
44 |
$f->addElement('text', 'email', get_string('email'));
|
|
|
45 |
$f->setType('email', PARAM_NOTAGS);
|
|
|
46 |
$f->addRule('email', get_string('missingemail'), 'required', null, 'server');
|
|
|
47 |
$f->addRule('email', get_string('validemail','eduplayer'), 'email', null, 'server');
|
|
|
48 |
|
|
|
49 |
$f->addElement('submit', 'intro', get_string('share', 'eduplayer') );
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Share the link provided by email
|
|
|
54 |
*
|
|
|
55 |
* @global cgf
|
|
|
56 |
* @global user
|
|
|
57 |
* @uses SITEID
|
|
|
58 |
* @param stdClass $eduplay the activity object
|
|
|
59 |
* @return bool Returns true if mail was sent OK and false if there was an error.
|
|
|
60 |
*/
|
|
|
61 |
public function shareEmailLink( $eduplay ){
|
|
|
62 |
global $CFG;
|
|
|
63 |
global $USER;
|
|
|
64 |
|
|
|
65 |
$subject=get_string('sharesubbject', 'eduplayer', $USER );
|
|
|
66 |
$from=$USER;
|
|
|
67 |
$to=$this->get_data()->email;
|
|
|
68 |
$messagetext='';
|
|
|
69 |
$messagehtml=$eduplay->sharemailmessage. "<p>". $eduplay->sharelink ."</p>";
|
|
|
70 |
|
|
|
71 |
if (!empty($CFG->noemailever)) {
|
|
|
72 |
// hidden setting for development sites, set in config.php if needed
|
|
|
73 |
$noemail = 'Not sending email due to noemailever config setting';
|
|
|
74 |
error_log($noemail);
|
|
|
75 |
if (CLI_SCRIPT) {
|
|
|
76 |
mtrace('Error: lib/moodlelib.php email_to_user(): '.$noemail);
|
|
|
77 |
}
|
|
|
78 |
return true;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
// Overwrite the receiver
|
|
|
82 |
if (!empty($CFG->divertallemailsto)) {
|
|
|
83 |
$subject = "[DIVERTED {$to}] $subject";
|
|
|
84 |
$to = $CFG->divertallemailsto;
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
// we can not send emails to invalid addresses - it might create security issue or confuse the mailer
|
|
|
88 |
if (!validate_email($to)) {
|
|
|
89 |
$invalidemail = "Email $to is invalid! Not sending.";
|
|
|
90 |
error_log($invalidemail);
|
|
|
91 |
if (CLI_SCRIPT) {
|
|
|
92 |
mtrace('Error: mod/eduplayer/share_form.php shareEmailLink(): '.$invalidemail);
|
|
|
93 |
}
|
|
|
94 |
return false;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
$mail = get_mailer();
|
|
|
98 |
$mail->AddAddress( $to );
|
|
|
99 |
if (!empty($mail->SMTPDebug)) {
|
|
|
100 |
echo '<pre>' . "\n";
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
$tempreplyto = array();
|
|
|
104 |
$supportuser = generate_email_supportuser();
|
|
|
105 |
|
|
|
106 |
if ($from->maildisplay) {
|
|
|
107 |
$mail->From = $from->email;
|
|
|
108 |
$mail->FromName = fullname($from);
|
|
|
109 |
$mail->Sender = $from->email;
|
|
|
110 |
} else {
|
|
|
111 |
$mail->From = $CFG->noreplyaddress;
|
|
|
112 |
$mail->FromName = fullname($from);
|
|
|
113 |
if (empty($replyto)) {
|
|
|
114 |
$tempreplyto[] = array($CFG->noreplyaddress, get_string('noreplyname'));
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
if (!empty($replyto)) {
|
|
|
119 |
$tempreplyto[] = array($replyto, $replytoname);
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
$mail->Subject = substr($subject, 0, 900);
|
|
|
123 |
$mail->WordWrap = 79;
|
|
|
124 |
|
|
|
125 |
if (!empty($from->customheaders)) { // Add custom headers
|
|
|
126 |
if (is_array($from->customheaders)) {
|
|
|
127 |
foreach ($from->customheaders as $customheader) {
|
|
|
128 |
$mail->AddCustomHeader($customheader);
|
|
|
129 |
}
|
|
|
130 |
} else {
|
|
|
131 |
$mail->AddCustomHeader($from->customheaders);
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
if (!empty($from->priority)) {
|
|
|
136 |
$mail->Priority = $from->priority;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
$mail->IsHTML(true);
|
|
|
140 |
$mail->Encoding = 'quoted-printable'; // Encoding to use
|
|
|
141 |
$mail->Body = $messagehtml;
|
|
|
142 |
$mail->AltBody = "\n$messagetext\n";
|
|
|
143 |
|
|
|
144 |
// Check if the email should be sent in an other charset then the default UTF-8
|
|
|
145 |
if ((!empty($CFG->sitemailcharset) || !empty($CFG->allowusermailcharset))) {
|
|
|
146 |
|
|
|
147 |
// use the defined site mail charset or eventually the one preferred by the recipient
|
|
|
148 |
$charset = $CFG->sitemailcharset;
|
|
|
149 |
if (!empty($CFG->allowusermailcharset)) {
|
|
|
150 |
if ($useremailcharset = get_user_preferences('mailcharset', '0', $user->id)) {
|
|
|
151 |
$charset = $useremailcharset;
|
|
|
152 |
}
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
// convert all the necessary strings if the charset is supported
|
|
|
156 |
$charsets = get_list_of_charsets();
|
|
|
157 |
unset($charsets['UTF-8']);
|
|
|
158 |
if (in_array($charset, $charsets)) {
|
|
|
159 |
$mail->CharSet = $charset;
|
|
|
160 |
$mail->FromName = textlib::convert($mail->FromName, 'utf-8', strtolower($charset));
|
|
|
161 |
$mail->Subject = textlib::convert($mail->Subject, 'utf-8', strtolower($charset));
|
|
|
162 |
$mail->Body = textlib::convert($mail->Body, 'utf-8', strtolower($charset));
|
|
|
163 |
$mail->AltBody = textlib::convert($mail->AltBody, 'utf-8', strtolower($charset));
|
|
|
164 |
|
|
|
165 |
foreach ($tempreplyto as $key => $values) {
|
|
|
166 |
$tempreplyto[$key][1] = textlib::convert($values[1], 'utf-8', strtolower($charset));
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
foreach ($tempreplyto as $values) {
|
|
|
172 |
$mail->AddReplyTo($values[0], $values[1]);
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
if ($mail->Send()) {
|
|
|
176 |
set_send_count($USER);
|
|
|
177 |
$mail->IsSMTP(); // use SMTP directly
|
|
|
178 |
if (!empty($mail->SMTPDebug)) {
|
|
|
179 |
echo '</pre>';
|
|
|
180 |
}
|
|
|
181 |
return true;
|
|
|
182 |
} else {
|
|
|
183 |
add_to_log(SITEID, 'library', 'mailer', qualified_me(), 'ERROR: '. $mail->ErrorInfo);
|
|
|
184 |
if (CLI_SCRIPT) {
|
|
|
185 |
mtrace('Error: mod/eduplayer/share_form.php shareEmailLink(): '.$mail->ErrorInfo);
|
|
|
186 |
}
|
|
|
187 |
if (!empty($mail->SMTPDebug)) {
|
|
|
188 |
echo '</pre>';
|
|
|
189 |
}
|
|
|
190 |
return false;
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
//Custom validation should be added here
|
|
|
196 |
function validation($data, $files) {
|
|
|
197 |
return array();
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
/**
|
|
|
201 |
* Print o screen a template customized share form
|
|
|
202 |
*/
|
|
|
203 |
function displayCustom(){
|
|
|
204 |
global $USER;
|
|
|
205 |
$html = '
|
|
|
206 |
<form autocomplete="off" action="?id=10" method="post" accept-charset="utf-8" id="mform1" class="mform">
|
|
|
207 |
<div style="display: none;"><input name="sesskey" type="hidden" value="'. $USER->sesskey .'">
|
|
|
208 |
<input name="_qf__shareform_form" type="hidden" value="1">
|
|
|
209 |
</div>
|
|
|
210 |
<p>'. get_string('sharetext','eduplayer') .'</p>
|
|
|
211 |
<label for="id_email">
|
|
|
212 |
'. get_string('shareemaillabel','eduplayer') .'
|
|
|
213 |
<input name="email" type="text" id="id_email" />
|
|
|
214 |
</label>
|
|
|
215 |
<input name="intro" value="'. get_string('share','eduplayer') .'" type="submit" id="id_intro" />
|
|
|
216 |
</form>';
|
|
|
217 |
echo $html;
|
|
|
218 |
}
|
|
|
219 |
}
|