source-function-F_send_report_emails

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
Overview

Classes

Interfaces

Exceptions

Functions

  1: <?php
  2: //============================================================+
  3: // File name   : tce_functions_email_reports.php
  4: // Begin       : 2005-02-24
  5: // Last Update : 2017-04-22
  6: //
  7: // Description : Sends email test reports to users.
  8: //
  9: // Author: Nicola Asuni
 10: //
 11: // (c) Copyright:
 12: //               Nicola Asuni
 13: //               Tecnick.com LTD
 14: //               www.tecnick.com
 15: //               info@tecnick.com
 16: //
 17: // License:
 18: //    Copyright (C) 2004-2017 Nicola Asuni - Tecnick.com LTD
 19: //    See LICENSE.TXT file for more information.
 20: //============================================================+
 21: 
 22: /**
 23:  * @file
 24:  * Functions to send email reports to users.
 25:  * @package com.tecnick.tcexam.admin
 26:  * @author Nicola Asuni
 27:  * @since 2005-02-24
 28:  */
 29: 
 30: /**
 31:  * Sends email test reports to users.
 32:  * @author Nicola Asuni
 33:  * @since 2005-02-24
 34:  * @param $test_id (int) TEST ID
 35:  * @param $user_id (int) USER ID (0 means all users)
 36:  * @param $testuser_id (int) test-user ID - if greater than zero, filter stats for the specified test-user.
 37:  * @param $group_id (int) GROUP ID (0 means all groups)
 38:  * @param $startdate (int) start date ID - if greater than zero, filter stats for the specified starting date
 39:  * @param $enddate (int) end date ID - if greater than zero, filter stats for the specified ending date
 40:  * @param $mode (int) type of report to send: 0=detailed report; 1=summary report (without questions)
 41:  * @param $display_mode display (int) mode: 0 = disabled; 1 = minimum; 2 = module; 3 = subject; 4 = question; 5 = answer.
 42:  * @param $show_graph (boolean) If true display the score graph.
 43:  */
 44: function F_send_report_emails($test_id, $user_id = 0, $testuser_id = 0, $group_id = 0, $startdate = 0, $enddate = 0, $mode = 0, $display_mode = 1, $show_graph = false)
 45: {
 46:     global $l, $db;
 47:     require_once('../config/tce_config.php');
 48:     require_once('../../shared/code/tce_functions_test.php');
 49:     require_once('../../shared/code/tce_functions_test_stats.php');
 50:     require_once('../../shared/code/tce_class_mailer.php');
 51:     require_once('tce_functions_user_select.php');
 52: 
 53:     $mode = intval($mode);
 54:     if ($test_id > 0) {
 55:         $test_id = intval($test_id);
 56:         if (!F_isAuthorizedUser(K_TABLE_TESTS, 'test_id', $test_id, 'test_user_id')) {
 57:             return;
 58:         }
 59:     } else {
 60:         $test_id = 0;
 61:     }
 62:     if ($user_id > 0) {
 63:         $user_id = intval($user_id);
 64:     } else {
 65:         $user_id = 0;
 66:     }
 67:     if ($testuser_id > 0) {
 68:         $testuser_id = intval($testuser_id);
 69:     } else {
 70:         $testuser_id = 0;
 71:     }
 72:     if ($group_id > 0) {
 73:         $group_id = intval($group_id);
 74:     } else {
 75:         $group_id = 0;
 76:     }
 77:     if (!empty($startdate)) {
 78:         $startdate_time = strtotime($startdate);
 79:         $startdate = date(K_TIMESTAMP_FORMAT, $startdate_time);
 80:     } else {
 81:         $startdate = '';
 82:     }
 83:     if (!empty($enddate)) {
 84:         $enddate_time = strtotime($enddate);
 85:         $enddate = date(K_TIMESTAMP_FORMAT, $enddate_time);
 86:     } else {
 87:         $enddate = '';
 88:     }
 89: 
 90:     // Instantiate C_mailer class
 91:     $mail = new C_mailer;
 92: 
 93:     //Load default values
 94:     $mail->setLanguageData($l);
 95:     $mail->Priority = $emailcfg['Priority'];
 96:     $mail->ContentType = $emailcfg['ContentType'];
 97:     $mail->Encoding = $emailcfg['Encoding'];
 98:     $mail->WordWrap = $emailcfg['WordWrap'];
 99:     $mail->Mailer = $emailcfg['Mailer'];
100:     $mail->Sendmail = $emailcfg['Sendmail'];
101:     $mail->UseMSMailHeaders = $emailcfg['UseMSMailHeaders'];
102:     $mail->Host = $emailcfg['Host'];
103:     $mail->Port = $emailcfg['Port'];
104:     $mail->Helo = $emailcfg['Helo'];
105:     $mail->SMTPAuth = $emailcfg['SMTPAuth'];
106:     $mail->SMTPSecure = $emailcfg['SMTPSecure'];
107:     $mail->Username = $emailcfg['Username'];
108:     $mail->Password = $emailcfg['Password'];
109:     $mail->Timeout = $emailcfg['Timeout'];
110:     $mail->SMTPDebug = $emailcfg['SMTPDebug'];
111:     $mail->PluginDir = $emailcfg['PluginDir'];
112:     $mail->Sender = $emailcfg['Sender'];
113:     $mail->From = $emailcfg['From'];
114:     $mail->FromName = $emailcfg['FromName'];
115:     if ($emailcfg['Reply']) {
116:         $mail->AddReplyTo($emailcfg['Reply'], $emailcfg['ReplyName']);
117:     }
118:     $mail->CharSet = $l['a_meta_charset'];
119:     if (!$mail->CharSet) {
120:         $mail->CharSet = $emailcfg['CharSet'];
121:     }
122:     $mail->Subject = $l['t_result_user'];
123:     $mail->IsHTML(true); // Set message type to HTML.
124: 
125:     $email_num = 0; // count emails;
126:     
127:     // get all data
128:     $data = F_getAllUsersTestStat($test_id, $group_id, $user_id, $startdate, $enddate, 'total_score', false, $display_mode);
129: 
130:     foreach ($data['testuser'] as $tu) {
131:         if (strlen($tu['user_email']) > 3) {
132:             // set HTML header
133:             $mail->Body = $emailcfg['MsgHeader'];
134:             // compose alternate TEXT message
135:             $mail->AltBody = ''.$l['t_result_user'].' ['.$tu['testuser_creation_time'].']'.K_NEWLINE;
136:             $mail->AltBody .= $l['w_test'].': '.$tu['test']['test_name'].K_NEWLINE;
137: 
138:             $passmsg = '';
139:             if ($tu['test']['test_score_threshold'] > 0) {
140:                 $mail->AltBody .= $l['w_test_score_threshold'].': '.$tu['test']['test_score_threshold'];
141:                 if ($tu['total_score'] >= $tu['test']['test_score_threshold']) {
142:                     $passmsg = ' - '.$l['w_passed'];
143:                 } else {
144:                     $passmsg = ' - '.$l['w_not_passed'];
145:                 }
146:                 $mail->AltBody .= K_NEWLINE;
147:             }
148: 
149:             $mail->AltBody .= $l['w_score'].': '.F_formatFloat($tu['total_score']).' '.F_formatPercentage($tu['total_score_perc'], false).$passmsg.K_NEWLINE;
150:             if ($display_mode > 0) {
151:                 $mail->AltBody .= $l['w_answers_right'].': '.$tu['right'].'&nbsp;'.F_formatPercentage($tu['right_perc'], false).K_NEWLINE;
152:                 $mail->AltBody .= $l['w_answers_wrong'].': '.$tu['wrong'].'&nbsp;'.F_formatPercentage($tu['wrong_perc'], false).K_NEWLINE;
153:                 $mail->AltBody .= $l['w_questions_unanswered'].': '.$tu['unanswered'].'&nbsp;'.F_formatPercentage($tu['unanswered_perc'], false).K_NEWLINE;
154:                 $mail->AltBody .= $l['w_questions_undisplayed'].': '.$tu['undisplayed'].'&nbsp;'.F_formatPercentage($tu['undisplayed_perc'], false).K_NEWLINE;
155:             }
156: 
157:             if ($mode == 0) {
158:                 $pdfkey = getPasswordHash(date('Y').$tu['id'].K_RANDOM_SECURITY.$tu['test']['test_id'].date('m').$tu['user_id']);
159:                 // create PDF doc
160:                 $pdf_content = file_get_contents(K_PATH_HOST.K_PATH_TCEXAM.'admin/code/tce_pdf_results.php?mode=3&diplay_mode='.$display_mode.'&show_graph='.$show_graph.'&test_id='.$tu['test']['test_id'].'&user_id='.$tu['user_id'].'&testuser_id='.$tu['id'].'&email='.urlencode($pdfkey));
161:                 // set PDF document file name
162:                 $doc_name = 'tcexam_report';
163:                 $doc_name .= '_3';
164:                 $doc_name .= '_0';
165:                 $doc_name .= '_'.$tu['test']['test_id'];
166:                 $doc_name .= '_0';
167:                 $doc_name .= '_'.$tu['user_id'];
168:                 $doc_name .= '_'.$tu['id'];
169:                 $doc_name .= '.pdf';
170: 
171:                 // attach document
172:                 $mail->AddStringAttachment($pdf_content, $doc_name, $emailcfg['AttachmentsEncoding'], 'application/octet-stream');
173:                 $mail->AltBody .= K_NEWLINE.$l['w_attachment'].': '.$doc_name.K_NEWLINE;
174:             }
175: 
176:             // convert alternate text to HTML
177:             $mail->Body .= str_replace(K_NEWLINE, '<br />'.K_NEWLINE, $mail->AltBody);
178: 
179:             // add HTML footer
180:             $mail->Body .= $emailcfg['MsgFooter'];
181: 
182:             //--- Elaborate user Templates ---
183:             $mail->Body = str_replace('#CHARSET#', $l['a_meta_charset'], $mail->Body);
184:             $mail->Body = str_replace('#LANG#', $l['a_meta_language'], $mail->Body);
185:             $mail->Body = str_replace('#LANGDIR#', $l['a_meta_dir'], $mail->Body);
186:             $mail->Body = str_replace('#EMAIL#', $tu['user_email'], $mail->Body);
187:             $mail->Body = str_replace('#USERNAME#', htmlspecialchars($tu['user_name'], ENT_NOQUOTES, $l['a_meta_charset']), $mail->Body);
188:             $mail->Body = str_replace('#USERFIRSTNAME#', htmlspecialchars($tu['user_firstname'], ENT_NOQUOTES, $l['a_meta_charset']), $mail->Body);
189:             $mail->Body = str_replace('#USERLASTNAME#', htmlspecialchars($tu['user_lastname'], ENT_NOQUOTES, $l['a_meta_charset']), $mail->Body);
190: 
191:             // add a "To" address
192:             $mail->AddAddress($tu['user_email'], $tu['user_name']);
193: 
194:             $email_num++;
195:             $progresslog = ''.$email_num.'. '.$tu['user_email'].' ['.$tu['user_name'].']'; //output user data
196: 
197:             if (!$mail->Send()) { //send email to user
198:                 $progresslog .= ' ['.$l['t_error'].']'; //display error message
199:             }
200: 
201:             $mail->ClearAddresses(); // Clear all addresses for next loop
202:             $mail->ClearAttachments(); // Clears all previously set filesystem, string, and binary attachments
203:         } else {
204:             $progresslog = '['.$l['t_error'].'] '.$tu['user_name'].': '.$l['m_unknown_email'].''; //output user data
205:         }
206:         echo $progresslog.'<br />'.K_NEWLINE; //output processed emails
207:         flush(); // force browser output
208:     }
209: 
210:     $mail->ClearAddresses(); // Clear all addresses for next loop
211:     $mail->ClearCustomHeaders(); // Clears all custom headers
212:     $mail->ClearAllRecipients(); // Clears all recipients assigned in the TO, CC and BCC
213:     $mail->ClearAttachments(); // Clears all previously set filesystem, string, and binary attachments
214:     $mail->ClearReplyTos(); // Clears all recipients assigned in the ReplyTo array
215:     return;
216: }
217: 
218: //============================================================+
219: // END OF FILE
220: //============================================================+
221: 
 

© 2004-2018 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy