-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendmessage.php
161 lines (142 loc) · 6.57 KB
/
sendmessage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
if (!$site = get_site()) {
redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
}
$debug = false;
if ($debug) {
echo 'Scrivo dalla riga '.__LINE__.' del file '.__FILE__.'<br />';
echo '$cid = '.$cid.'<br />';
echo '$bid = '.$bid.'<br />';
echo '$rcp = '.$rcp.'<br />';
echo 'count($allhiddenrecipients) = '.count($allhiddenrecipients).'<br />';
echo 'count($allstandardrecipients) = '.count($allstandardrecipients).'<br />';
}
//print_object($fromform);
// definition of $messagehtml
$messagehtml = get_string('commentreceived', 'block_user_contact', $fromform->cf_sendername);
// <strong>Name Surame</strong> sent you a comment from
// <strong>Nome Cognome</strong> ti ha inviato una comunicazione
$a = new object();
$a->sitename = $site->shortname;
if ($cid == SITEID) {
$messagehtml .= get_string('fromhompageof', 'block_user_contact', $a).'<br />';
// <strong>Name Surame</strong> sent you a comment from the <strong>home page</strong> of <strong>M19</strong>
// <strong>Nome Cognome</strong> ti ha inviato una comunicazione dalla <strong>home page</strong> di <strong>M19</strong>
} else {
$a->coursename = $course->shortname;
$messagehtml .= get_string('fromcourse', 'block_user_contact', $a).'<br />';
// Name Surame sent you a comment from course <strong>xxx</strong> of <strong>M19</strong>
// nome cognome ti ha inviato una comunicazione dal corso <strong>xxx</strong> di <strong>M19</strong>
}
$messagehtml .= '<br /><hr />'.format_text($fromform->cf_mailbody['text'],$fromform->cf_mailbody['format']);
$messagehtml .= '<br /><hr />
<h4>Client Info</h4>
<table border="1" cellspacing="0" cellpadding="8" style="border: 1px solid #ccc; border-collapse: collapse">
<tr>
<td>Browser</td>
<td>'.$fromform->cf_browser.'</td>
</tr>
<tr>
<td>Engine</td>
<td>'.$fromform->cf_engine.'</td>
</tr>
<tr>
<td>OS Type</td>
<td>'.$fromform->cf_os.'</td>
</tr>
<tr>
<td>Device</td>
<td>'.$fromform->cf_device.'</td>
</tr>
</table>';
//print_object($fromform);
// end of definition of $messagehtml
// definition of $messagetext
$messagetext = str_replace('<br />', "\n", $messagehtml);
$messagetext = strip_tags($messagetext);
// end of definition of $messagetext
if (false) {
echo 'Scrivo dalla riga '.__LINE__.' del file '.__FILE__.'<br />';
echo '$CFG->block_user_contact_subject_prefix = '.$CFG->block_user_contact_subject_prefix.'<br />'; // [M20]
echo '<hr />';
echo '$rcp = '.$rcp.'<br />';
echo '<hr />';
echo '<div>$messagetext = </div>';
echo '<textarea cols="50" rows="7">';
echo $messagetext;
echo '</textarea>';
echo '<div>$messagehtml = </div>';
echo '<textarea cols="50" rows="7">';
echo $messagehtml;
echo '</textarea>';
echo '<hr />';
echo '<div>$messagetext = ';
echo $messagetext;
echo '</div>';
echo '<div>$messagehtml = ';
echo $messagehtml;
echo '</div>';
echo '<hr />';
die;
}
//sender infos
$from = new object;
$from->firstname = $fromform->cf_sendername;
$from->lastname = '';
$from->email = $fromform->cf_senderemail;
$from->maildisplay = true;
$from->mailformat = $fromform->cf_sendermailformat;
//define the subject starting from the pre-defined prefix
if ($cid == SITEID) {
// as far as I understand, the next if is useless because
// it was defined a default for $CFG->block_user_contact_subject_prefix
if (!isset($CFG->block_user_contact_subject_prefix)) {
$CFG->block_user_contact_subject_prefix = '['.strip_tags($site->shortname).'] ';
}
$subject = $CFG->block_user_contact_subject_prefix.$fromform->cf_mailsubject;
} else {
//set the subject to start with [shortname]
$subject = '['.$course->shortname.'] '.$fromform->cf_mailsubject;
}
if (!$debug) {
//send emails
$fullnamesender = fullname($from);
if ($allhiddenrecipients) {
foreach ($allhiddenrecipients as $thisrecipient) {
$fullnamerecipient = fullname($thisrecipient);
$property = 'cf_teacher'.$thisrecipient->id;
if ( isset($fromform->{$property}) ) {
if ( email_to_user($thisrecipient, $from, $subject, $messagetext, $messagehtml) ) {
add_to_log($cid, 'user_contact', 'send mail', '', 'To: '.$fullnamerecipient.'; From: '.$fullnamesender.'; Subject: '.$subject);
} else {
echo "Error in blocks/user_contact/sendmessage.php: Could not send out mail from $from->firstname to fullname($thisrecipient) ($user->email)\n";
add_to_log($cid, 'user_contact', 'send mail failure', '', 'To: '.$fullnamerecipient.'; From: '.$fullnamesender.'; Subject:'.$subject);
}
}
}
}
if ($allstandardrecipients) {
foreach ($allstandardrecipients as $thisrecipient) {
$fullnamerecipient = fullname($thisrecipient);
$property = 'cf_teacher'.$thisrecipient->id;
if ( isset($fromform->{$property}) ) {
if ( email_to_user($thisrecipient, $from, $subject, $messagetext, $messagehtml) ) {
add_to_log($cid, 'user_contact', 'send mail', '', 'To: '.$fullnamerecipient.'; From: '.$fullnamesender.'; Subject: '.$subject);
} else {
echo "Error in blocks/user_contact/sendmessage.php: Could not send out mail from $from->firstname to fullname($thisrecipient) ($user->email)\n";
add_to_log($cid, 'user_contact', 'send mail failure', '', 'To: '.$fullnamerecipient.'; From: '.$fullnamesender.'; Subject:'.$subject);
}
}
}
}
if ( $rcp == 1 ) {
$subject = get_string('receipt', 'block_user_contact').$subject;
if ( email_to_user($from, $from, $subject, $messagetext, $messagehtml) ) {
add_to_log($cid, 'user_contact', 'send mail', '', 'To: '.$fullnamesender.'; From: '.$fullnamesender.'; Subject: '.$subject);
} else {
echo "Error in blocks/user_contact/sendmessage.php: Could not send out mail from $from->firstname to fullname($thisrecipient) ($user->email)\n";
add_to_log($cid, 'user_contact', 'send mail failure', '', 'To: '.$fullnamesender.'; From: '.$fullnamesender.'; Subject:'.$subject);
}
}
} // end of: if (!$debug)
?>