function calendar_cron() { require 'includes/classes/events.class.php'; require AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php'; //Iterate through each member's preference $sql = "SELECT * FROM %scalendar_notification WHERE 1=1"; $rows_notify = queryDB($sql, array(TABLE_PREFIX)); $event_obj = new Events(); foreach ($rows_notify as $row) { //Send email only when preference is 1 if ($row['status'] == 1) { $all_events = array(); $mail = new ATutorMailer(); //Get personal events $personal_events = $event_obj->get_personal_events($row['memberid']); foreach ($personal_events as $event) { $all_events[] = $event; } //Get course events $sql_q = "SELECT course_id FROM %scourse_enrollment WHERE member_id = %d"; $rows_enrolled = queryDB($sql_q, array(TABLE_PREFIX, TABLE_PREFIX)); foreach ($rows_enrolled as $row_q) { $course_events = $event_obj->get_atutor_events($row['memberid'], $row_q['course_id']); foreach ($course_events as $event) { $all_events[] = $event; } } //Iterate through each event and keep only those events which will start tomorrow $email_msg = _AT('calendar_noti_mail_1') . "\n"; $index = 1; foreach ($all_events as $id => $event) { if (strtotime(substr($event['start'], 0, 10)) == strtotime('tomorrow')) { $email_msg .= _AT('calendar_noti_mail_2') . " #" . $index . " \n"; $email_msg .= _AT('calendar_noti_mail_3') . ": " . substr($event['start'], 0, 10) . " \n"; $email_msg .= _AT('calendar_noti_mail_4') . ": " . substr($event['end'], 0, 10) . " \n"; $email_msg .= _AT('calendar_noti_mail_5') . ": " . $event['title'] . " \n\n"; $index++; } } //Send email using ATutor mailer $mail->From = $_config['contact_email']; $mail->FromName = $_config['site_name']; $mail->AddAddress($_config['contact_email']); $mail->Subject = $stripslashes(_AT('calendar_noti_title')); $mail->Body = $email_msg; $sql_email = "SELECT email FROM %smembers WHERE member_id = %d"; $row_email = queryDB($sql_email, array(TABLE_PREFIX, $row['memberid']), TRUE); $mail->AddBCC($row_email['email']); $mail->Send(); unset($mail); //For testing // echo "<br/>".$email_msg."<br/>".$row_email['mail']; } } }
// choose all instructors $sql = "SELECT * FROM %smembers WHERE status = " . AT_STATUS_INSTRUCTOR; } else { if ($_POST['to'] == 2) { // choose all students $sql = "SELECT * FROM %smembers WHERE status = " . AT_STATUS_STUDENT; } else { // choose all members $sql = "SELECT * FROM %smembers WHERE status = " . AT_STATUS_INSTRUCTOR . " OR status = " . AT_STATUS_STUDENT; } } $rows_members = queryDB($sql, array(TABLE_PREFIX)); require AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php'; $mail = new ATutorMailer(); foreach ($rows_members as $row) { $mail->AddBCC($row['email']); } $mail->From = $_config['contact_email']; $mail->FromName = $_config['site_name']; $mail->AddAddress($_config['contact_email']); $mail->Subject = $stripslashes($_POST['subject']); $mail->Body = $stripslashes($_POST['body']); if (!$mail->Send()) { //echo 'There was an error sending the message'; $msg->printErrors('SENDING_ERROR'); exit; } unset($mail); $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY'); header('Location: users.php'); exit;
$sql = "SELECT * FROM %smembers WHERE member_id IN (SELECT member_id FROM %scourse_enrollment WHERE status=%d and course_id=%d and member_id <> %d)"; $rows_recipients = queryDB($sql, array(TABLE_PREFIX, TABLE_PREFIX, AT_STATUS_STUDENT, $_SESSION['course_id'], $_SESSION['member_id'])); } else { if ($_POST['to'] == 2) { // choose particular login $sql = "SELECT * FROM %smembers WHERE member_id = %d"; $rows_recipients = queryDB($sql, array(TABLE_PREFIX, $_POST['selection'])); } else { //user entered email address } } require AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php'; $mail = new ATutorMailer(); if ($_POST['to'] == 1 || $_POST['to'] == 2) { foreach ($rows_recipients as $row) { $mail->AddBCC($row['email']); } } else { $mail->AddBCC($_POST['emails']); } if (isset($_POST['subject']) && $_POST['subject'] != '') { $calname = $_POST['subject']; } else { $calname = _AT('calendar_of') . " " . get_display_name($_SESSION['member_id']); } $body = get_display_name($_SESSION['member_id']) . _AT('calendar_email_part1') . '"' . $calname . '"' . _AT('calendar_email_part2'); $sql = "SELECT * FROM %smembers WHERE member_id = %d"; $rows_members = queryDB($sql, array(TABLE_PREFIX, $_SESSION['member_id'])); $fromemail = $_config['contact_email']; foreach ($rows_members as $row) { $fromemail = $row['email'];