This repository has been archived by the owner on Jul 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmailUsers.php
217 lines (168 loc) · 5.79 KB
/
EmailUsers.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* Email Users
*
* @package Email module
*/
require_once 'ProgramFunctions/MarkDownHTML.fnc.php';
require_once 'ProgramFunctions/SendEmail.fnc.php';
if ( file_exists( 'ProgramFunctions/Template.fnc.php' ) )
{
// @since 3.6.
require_once 'ProgramFunctions/Template.fnc.php';
}
else
{
// @deprecated.
require_once 'modules/Email/includes/Template.fnc.php';
}
DrawHeader( ProgramTitle() );
if ( User( 'PROFILE' ) === 'teacher' )
{
$_ROSARIO['allow_edit'] = true;
}
if ( $_REQUEST['modfunc'] === 'save'
&& AllowEdit() )
{
if ( count( $_REQUEST['st_arr'] ) )
{
// If $test email is set then this script will only 'go through the motions'
// and email the results to the $test_email address instead of parents.
$test_email = $_REQUEST['test_email'];
// Set the from and cc emails here - the emails can be comma separated list of emails.
$reply_to = '';
if ( filter_var( User( 'EMAIL' ), FILTER_VALIDATE_EMAIL ) )
{
$reply_to = User( 'NAME' ) . ' <' . User( 'EMAIL' ) . '>';
}
elseif ( ! filter_var( $test_email, FILTER_VALIDATE_EMAIL ) )
{
$error[] = _( 'You must set the <b>test mode email</b> or have a user email address to use this script.' );
ErrorMessage( $error, 'fatal' );
}
$subject = isset( $_REQUEST['subject'] ) ?
str_replace( "''", "'", $_REQUEST['subject'] ) :
'';
// FJ bypass strip_tags on the $_REQUEST vars.
$REQUEST_email_text = SanitizeHTML( $_POST['email_text'] );
$st_list = "'" . implode( "','", $_REQUEST['st_arr'] ) . "'";
$extra['WHERE'] = " AND s.STAFF_ID IN (" . $st_list . ")";
$extra['SELECT'] .= ",s.USERNAME,s.LAST_NAME,s.FIRST_NAME,s.MIDDLE_NAME";
// Select Email.
$extra['SELECT'] .= ",s.EMAIL";
SaveTemplate( $REQUEST_email_text );
$RET = GetStaffList( $extra );
$LO_result = array( 0 => array() );
$i = 0;
foreach ( (array) $RET as $user )
{
$email_text = $REQUEST_email_text;
foreach ( (array) $user as $column => $value )
{
$email_text = str_replace( '__' . $column . '__', $value, $email_text );
}
$to = empty( $test_email ) ? $user['EMAIL'] : $test_email;
$result = SendEmail( $to, $subject, $email_text, $reply_to );
$LO_result[] = array(
'STAFF' => $user['FULL_NAME'],
'USERNAME' => $user['USERNAME'],
'EMAIL' => $to,
'RESULT' => $result ? _( 'Success' ) : _( 'Fail' ),
);
$i++;
}
unset( $LO_result[0] );
$columns = array(
'STAFF' => _( 'Student' ),
);
if ( $email_field_key !== 'USERNAME' )
{
$columns['USERNAME'] = _( 'Username' );
}
$columns += array(
'EMAIL' => _( 'Email' ),
'RESULT' => _( 'Result' ),
);
ListOutput( $LO_result, $columns, 'Sending Result', 'Sending Results' );
}
else
{
$error[] = _( 'You must choose at least one student.' );
// Unset modfunc & redirect URL.
RedirectURL( 'modfunc' );
}
}
if ( ! $_REQUEST['modfunc'] )
{
if ( $_REQUEST['search_modfunc'] === 'list' )
{
echo '<form action="Modules.php?modname=' . $_REQUEST['modname'] .
'&modfunc=save&include_inactive=' . $_REQUEST['include_inactive'] .
'&_search_all_schools=' . $_REQUEST['_search_all_schools'] .
'" method="POST">';
$extra['header_right'] = SubmitButton( dgettext( 'Email', 'Send Email to Selected Users' ) );
$extra['extra_header_left'] = '<table>' . $extra['search'] . '</table>';
$extra['search'] = '';
// Subject field.
$extra['extra_header_left'] .= '<table class="width-100p"><tr><td>' .
TextInput(
$subject,
'subject',
dgettext( 'Email', 'Subject' ),
'required maxlength="100" class="width-100p"',
false
) .
'</td></tr>';
// FJ add TinyMCE to the textarea.
$extra['extra_header_left'] .= '<tr><td>' .
TinyMCEInput(
GetTemplate(),
'email_text',
_( 'Email' )
) .
'</textarea></td></tr>';
$extra['extra_header_left'] .= '<tr><td><hr />' . _( 'Substitutions' ) . ':<br /><table><tr class="st">';
$extra['extra_header_left'] .= '<td>__FULL_NAME__</td><td>= ' . _( 'Last, First M' ) . '</td><td> </td>';
$extra['extra_header_left'] .= '</tr><tr class="st">';
$extra['extra_header_left'] .= '<td>__FIRST_NAME__</td><td>= ' . _( 'First Name' ) . '</td><td> </td>';
$extra['extra_header_left'] .= '<td>__LAST_NAME__</td><td>= ' . _( 'Last Name' ) . '</td>';
$extra['extra_header_left'] .= '</tr><tr class="st">';
$extra['extra_header_left'] .= '<td>__MIDDLE_NAME__</td><td>= ' . _( 'Middle Name' ) . '</td><td> </td>';
$extra['extra_header_left'] .= '<td>__STAFF_ID__</td><td>= ' . sprintf( _( '%s ID' ), Config( 'NAME' ) ) . '</td>';
$extra['extra_header_left'] .= '</tr></table></td></tr>';
$extra['extra_header_left'] .= '<tr class="st"><td class="valign-top"><hr />' .
_( 'Test Mode' ) . ':' . '<br />' .
TextInput(
'',
'test_email',
_( 'Email' ),
'',
false
) . '</td></tr>';
$extra['extra_header_left'] .= '</table>';
}
// Select Email.
$extra['SELECT'] .= ",s.EMAIL";
// Add Email column.
$extra['columns_after']['EMAIL'] = _( 'Email' );
$extra['SELECT'] .= ",s.STAFF_ID AS CHECKBOX";
$extra['link'] = array( 'FULL_NAME' => false );
$extra['functions'] = array( 'CHECKBOX' => '_makeChooseCheckbox' );
$extra['columns_before'] = array( 'CHECKBOX' => '</a><input type="checkbox" value="Y" name="controller" checked onclick="checkAll(this.form,this.checked,\'st_arr\');"><A>' );
$extra['options']['search'] = false;
$extra['new'] = true;
Search( 'staff_id', $extra );
if ( $_REQUEST['search_modfunc'] === 'list' )
{
echo '<br /><div class="center">' .
SubmitButton( dgettext( 'Email', 'Send Email to Selected Users' ) ) . '</div></form>';
}
}
function _makeChooseCheckbox( $value, $title )
{
global $THIS_RET;
if ( filter_var( $THIS_RET['EMAIL'], FILTER_VALIDATE_EMAIL ) ) {
// Has email and is valid email, show checkbox.
return '<input type="checkbox" name="st_arr[]" value="' . $value . '" checked />';
}
}