-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportCardsEmailParents.php
480 lines (370 loc) · 12.5 KB
/
ReportCardsEmailParents.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<?php
ini_set("memory_limit","2048M");
/**
* Email Report Cards to Parents
*
* @package Email Parents module
*/
require_once 'modules/CustomReportCard/includes/ReportCards.fnc.php';
require_once 'modules/CustomReportCard/includes/ReportCardsHeader.fnc.php';
require_once 'ProgramFunctions/SendEmail.fnc.php';
// @deprecated since 4.2.
require_once 'modules/Email_Parents/includes/MakeChooseCheckbox.fnc.php';
if ( file_exists( 'ProgramFunctions/Template.fnc.php' ) )
{
// @since 3.6.
require_once 'ProgramFunctions/Template.fnc.php';
}
else
{
// @deprecated.
require_once 'modules/Email_Parents/includes/Template.fnc.php';
}
if ( file_exists( 'ProgramFunctions/Substitutions.fnc.php' ) )
{
// @since 4.3.
require_once 'ProgramFunctions/Substitutions.fnc.php';
}
else
{
// @deprecated.
require_once 'modules/Email_Parents/includes/Substitutions.fnc.php';
}
//Clean out the print directory
// Folder path to be flushed
$folder_path = dirname(__FILE__) . '/pdfreportcards/';
// List of name of files inside
// specified folder
$files = glob($folder_path.'/*');
// Deleting all the files in the list
foreach($files as $file) {
if(is_file($file))
// Delete the given file
unlink($file);
}
DrawHeader( ProgramTitle() );
// Send emails.
if ( isset( $_REQUEST['modfunc'] )
&& $_REQUEST['modfunc'] === 'save'
&& AllowEdit() )
{
if ( isset( $_POST['mp_arr'] )
&& isset( $_POST['student'] ) )
{
SaveTemplate( $_REQUEST['inputreportcardsemailtext'] );
$message = str_replace( "''", "'", $_REQUEST['inputreportcardsemailtext'] );
$_REQUEST['_ROSARIO_PDF'] = 'true';
// Generate and get Report Cards HTML.
$report_cards = ReportCardsGenerate( $_REQUEST['student'], $_REQUEST['mp_arr'] );
if ( $report_cards )
{
$i=0;
$files =array();
// PDF
require_once __DIR__ . '/mpdf/autoload.php';
$st_list = "'" . implode( "','", $_REQUEST['student'] ) . "'";
// SELECT Staff details.
$extra['SELECT'] .= ",(SELECT st.FIRST_NAME||' '||st.LAST_NAME
FROM STAFF st,STUDENTS_JOIN_USERS sju
WHERE sju.STAFF_ID=st.STAFF_ID
AND s.STUDENT_ID=sju.STUDENT_ID
AND st.EMAIL is Not Null
AND st.SYEAR='" . UserSyear() . "'
ORDER BY st.FIRST_NAME LIMIT 1) AS A_PARENT_NAME";
// SELECT Staff details.
$extra['SELECT'] .= ",(SELECT st.FIRST_NAME||' '||st.LAST_NAME
FROM STAFF st,STUDENTS_JOIN_USERS sju
WHERE sju.STAFF_ID=st.STAFF_ID
AND s.STUDENT_ID=sju.STUDENT_ID
AND st.EMAIL is Not Null
AND st.SYEAR='" . UserSyear() . "'
ORDER BY st.FIRST_NAME LIMIT 1 OFFSET 1) AS B_PARENT_NAME";
// AND st.SYEAR='" . UserSyear() . "' LIMIT 1) AS PARENT_NAME";
$extra['SELECT'] .= ",(SELECT st.EMAIL
FROM STAFF st,STUDENTS_JOIN_USERS sju
WHERE sju.STAFF_ID=st.STAFF_ID
AND s.STUDENT_ID=sju.STUDENT_ID
AND st.EMAIL is Not Null
AND st.SYEAR='" . UserSyear() . "'
ORDER BY st.FIRST_NAME LIMIT 1) AS A_PARENT_EMAIL";
$extra['SELECT'] .= ",(SELECT st.EMAIL
FROM STAFF st,STUDENTS_JOIN_USERS sju
WHERE sju.STAFF_ID=st.STAFF_ID
AND s.STUDENT_ID=sju.STUDENT_ID
AND st.EMAIL is Not Null
AND st.SYEAR='" . UserSyear() . "'
ORDER BY st.FIRST_NAME LIMIT 1 OFFSET 1) AS B_PARENT_EMAIL";
$extra['WHERE'] = " AND s.STUDENT_ID IN (" . $st_list . ")";
$student_RET = GetStuList( $extra );
// echo '<pre>'; var_dump($student_RET); echo '</pre>';
$error_email_list = array();
$lastRecord = count($student_RET);
foreach ( (array) $student_RET as $students )
{
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf(['orientation' => 'L'],
['fontdata' => $fontData + [
'engraver' => [
'R' => 'Englisht.ttf',
],
'fancyscript' => [
'R' => 'Promocyja.ttf',
]
]
]);
$mpdf->SetWatermarkText('Immaculate Conception Academy',0.06);
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'TimesNewRoman';
$mpdf->SetHTMLFooter('<table width="100%">
<tr>
<td width="33%" style="text-align: right;font-size:9;"><i>Immaculate Conception Academy</i> </td>
</tr>
</table>');
$bcc='';
$count=0;
$myto = array();
if($students['A_PARENT_EMAIL']){
$myto[0] = $students['A_PARENT_EMAIL'];
//$myto[0] ='[email protected]';
}
if($students['B_PARENT_EMAIL'] > '' && $students['A_PARENT_EMAIL'] != $students['B_PARENT_EMAIL']){
$myto[1] = $students['B_PARENT_EMAIL'];
//$myto[1] ='[email protected]';
}
/*
if($students['A_PARENT_EMAIL'] > '' && $students['B_PARENT_EMAIL'] > ''){
if($students['A_PARENT_EMAIL'] != $students['B_PARENT_EMAIL']){
$bcc = $students['A_PARENT_EMAIL'] . ',' . $students['B_PARENT_EMAIL'];
$count = 2;
}else{
$bcc = $students['A_PARENT_EMAIL'];
$count=1;
}
}elseif($students['A_PARENT_EMAIL'] > '' && ! $students['B_PARENT_EMAIL'] ){
$bcc = $students['A_PARENT_EMAIL'];
}elseif(! $students['A_PARENT_EMAIL'] && $students['B_PARENT_EMAIL'] > '' ){
$bcc = $students['B_PARENT_EMAIL'];
}
*/
//$to = '[email protected]';/// Take no Chance. $student['PARENT_EMAIL'];
$reply_to = $cc = null;
if ( filter_var( User( 'EMAIL' ), FILTER_VALIDATE_EMAIL ) )
{
$reply_to = User( 'NAME' ) . ' <' . User( 'EMAIL' ) . '>';
}
$subject = _( 'Report Card' ) .
' - ' . $students['FULL_NAME'];
$substitutions = array(
'A__PARENT_NAME__' => $students['A_PARENT_NAME'],
'B__PARENT_NAME__' => $students['B_PARENT_NAME'],
'__FIRST_NAME__' => $students['FIRST_NAME'],
'__LAST_NAME__' => $students['LAST_NAME'],
'__SCHOOL_ID__' => SchoolInfo( 'TITLE' ),
);
// Substitutions.
$msg = SubstitutionsTextMake( $substitutions, $message );
//$msg .= 'This would have been emailed to ' . $bcc;
//$msg .;= '** This report card booklet is best printed landsape 2-sided.';
$report_card = '';
$report_card = $report_cards[ $students['STUDENT_ID'] ];
if ( $report_card )
{
//give pdf a place to go
//$files[$i] = dirname(__FILE__) . '/pdfreportcards/' . $students['STUDENT_ID'] .'.pdf';
$mpdf->WriteHTML(utf8_encode($report_card));
//$mpdf->Output($files[$i], 'F');
$files[$i] = dirname(__FILE__) . '/pdfreportcards/' . $students['FIRST_NAME'] .'_' . $students['LAST_NAME'] . '.pdf';
$pdf_name = 'Report Card ' . $students['FIRST_NAME'] .'_' . $students['LAST_NAME'] . '.pdf';
$mpdf->Output($files[$i], 'F');
unset($mpdf);
//$pdf_file = $mpdf->Output('', 'S');
//error_log('Student report card ' . $pdf_name);
//error_log('report card ' . $pdf_file);
// Send Email.
/* $result = SendEmail(
$to,
$subject,
$msg,
$reply_to,
$bcc,
$cc,
array( array( $pdf_file, $pdf_name ) )
);*/
for($j = 0; $j < count($myto); $j++){
$cc='';
$to=$myto[$j];
$bcc='';
$result = SendEmail(
$to,
$subject,
$msg,
$reply_to,
$bcc,
$cc,
array( array( $files[$i],$pdf_name) )
);
if ( ! $result )
{
// $error_email_list[] = $student['PARENT_NAME'] .
// ' (' . $student['PARENT_EMAIL'] . ')';
$error_email_list[] = $students['A_PARENT_NAME'] . ' OR ' . $students['B_PARENT_NAME'] . ' (' . $students['A_PARENT_EMAIL'] . ' ' . $students['B_PARENT_EMAIL'] .')';
}
}
// Delete PDF file.
unlink($files[$i]);
unset($myto);
}
$i++;
}
if ( ! empty( $error_email_list ) )
{
$error_email_list = implode( ', ', $error_email_list );
$error[] = sprintf(
dgettext( 'Email_Parents', 'Email not sent to: %s' ),
$error_email_list
);
}
$note[] = dgettext( 'Email_Parents', 'The report cards email routine is complete.' );
}
else
$error[] = _( 'No Students were found.' );
}
// No Users / MP selected.
else
$error[] = _( 'You must choose at least one student and one marking period.' );
unset( $_SESSION['_REQUEST_vars']['modfunc'] );
unset( $_REQUEST['modfunc'] );
}
// Display errors if any.
if ( isset( $error ) )
{
echo ErrorMessage( $error );
}
// Display notes if any.
if ( isset( $note ) )
{
echo ErrorMessage( $note, 'note' );
}
// Display Search screen or Student list.
if ( empty( $_REQUEST['modfunc'] )
|| $_REQUEST['search_modfunc'] === 'list' )
{
// Open Form & Display Email options.
if ( $_REQUEST['search_modfunc'] === 'list' )
{
echo '<form action="' . PreparePHP_SELF(
$_REQUEST,
array( 'search_modfunc' ),
array( 'modfunc' => 'save' )
) . '" method="POST">';
$extra['header_right'] = SubmitButton( dgettext( 'Email_Parents', 'Send Report Cards to Selected Parents' ) );
$extra['extra_header_left'] = '<table class="width-100p">';
$template = GetTemplate();
// Email Template Textarea.
$extra['extra_header_left'] .= '<tr class="st"><td>' .TextAreaInput(
$template,
'inputreportcardsemailtext',
_( 'Report Cards' ) . ' - ' . _( 'Email Text' ),
'',
false,
'text'
);
$substitutions = array(
'A__PARENT_NAME__' => _( 'A Parent Name' ),
'B__PARENT_NAME__' => _( 'B Parent Name' ),
'__FIRST_NAME__' => _( 'Student First Name' ),
'__LAST_NAME__' => _( 'Student Last Name' ),
'__SCHOOL_ID__' => _( 'School' )
);
$extra['extra_header_left'] .= '<tr><td>' . SubstitutionsInput( $substitutions ) . '<hr /></td></tr>';
$extra['extra_header_left'] .= '</table>';
// Add Include in Report Cards Log form.
$extra['extra_header_left'] .= ReportCardsIncludeForm();
}
$extra['SELECT'] = ",s.STUDENT_ID AS CHECKBOX";
// SELECT Staff details.
$extra['SELECT'] .= ",(SELECT st.FIRST_NAME||' '||st.LAST_NAME
FROM STAFF st,STUDENTS_JOIN_USERS sju
WHERE sju.STAFF_ID=st.STAFF_ID
AND s.STUDENT_ID=sju.STUDENT_ID
AND st.EMAIL is Not Null
AND st.SYEAR='" . UserSyear() . "'
ORDER BY st.FIRST_NAME LIMIT 1) AS A_PARENT_NAME";
// SELECT Staff details.
$extra['SELECT'] .= ",(SELECT st.FIRST_NAME||' '||st.LAST_NAME
FROM STAFF st,STUDENTS_JOIN_USERS sju
WHERE sju.STAFF_ID=st.STAFF_ID
AND s.STUDENT_ID=sju.STUDENT_ID
AND st.EMAIL is Not Null
AND st.SYEAR='" . UserSyear() . "'
ORDER BY st.FIRST_NAME LIMIT 1 OFFSET 1) AS B_PARENT_NAME";
// AND st.SYEAR='" . UserSyear() . "' LIMIT 1) AS PARENT_NAME";
$extra['SELECT'] .= ",(SELECT st.EMAIL
FROM STAFF st,STUDENTS_JOIN_USERS sju
WHERE sju.STAFF_ID=st.STAFF_ID
AND s.STUDENT_ID=sju.STUDENT_ID
AND st.EMAIL is Not Null
AND st.SYEAR='" . UserSyear() . "'
ORDER BY st.FIRST_NAME LIMIT 1) AS A_PARENT_EMAIL";
$extra['SELECT'] .= ",(SELECT st.EMAIL
FROM STAFF st,STUDENTS_JOIN_USERS sju
WHERE sju.STAFF_ID=st.STAFF_ID
AND s.STUDENT_ID=sju.STUDENT_ID
AND st.EMAIL is Not Null
AND st.SYEAR='" . UserSyear() . "'
ORDER BY st.FIRST_NAME LIMIT 1 OFFSET 1) AS B_PARENT_EMAIL";
// ORDER BY Name.
$extra['ORDER_BY'] = 'FULL_NAME';
// Call functions to format Columns.
$extra['functions'] = array( 'CHECKBOX' => '_makeChooseCheckbox' );
// Columns Titles.
$extra['columns_before'] = array(
'CHECKBOX' => MakeChooseCheckbox( '', '', 'student' ),
);
$extra['columns_after'] = array(
'A_PARENT_NAME' => _( '1st Parent Name' ),
'A_PARENT_EMAIL' => _( '1st Email' ),
'B_PARENT_NAME' => _( '2nd Parent Name' ),
'B_PARENT_EMAIL' => _( '2nd Email' ),
);
// No link for Student's name.
$extra['link'] = array( 'FULL_NAME' => false );
// Remove Current Student if any.
$extra['new'] = true;
// Display Search screen or Search Students.
Search( 'student_id', $extra );
// Submit & Close Form.
if ( $_REQUEST['search_modfunc'] === 'list' )
{
echo '<br /><div class="center">' .
SubmitButton( dgettext( 'Email_Parents', 'Send Report Cards to Selected Parents' ) ) . '</div>';
echo '</form>';
}
}
/**
* Make Choose Checkbox
*
* Local function
* DBGet() callback
*
* @uses MakChooseCheckbox
*
* @param string $value STUDENT_ID value.
* @param string $column 'CHECKBOX'.
*
* @return string Checkbox or empty string if no Email or no Referrals
*/
function _makeChooseCheckbox( $value, $column )
{
global $THIS_RET;
// If valid email & has Referrals.
if ( filter_var( $THIS_RET['A_PARENT_EMAIL'], FILTER_VALIDATE_EMAIL ) )
{
return MakeChooseCheckbox( $value, $column );
}
else
return '';
}