* Where Songcircle Status is 5 * AND three hours has passed since the END-TIME of the songcircle */ $sql = "SELECT sc.songcircle_id, songcircle_name, date_of_songcircle, duration,\n\t\t\t\t\t\t\t\tsr.user_id, confirm_status,\tur.user_name, user_email\n\t\t\t\t\t\t\t\t, TIMESTAMPDIFF( MINUTE, CONVERT_TZ( now(), @@global.time_zone, '+0:00' ), ADDTIME(date_of_songcircle, duration) ) AS diff\n\t\t\t\t\t\t\t\tFROM songcircle_create AS sc, songcircle_register AS sr\n\t\t\t\t\t\t\t\tINNER JOIN user_register AS ur ON sr.user_id = ur.user_id\n\t\t\t\t\t\t\t\t-- INNER JOIN user_timezone AS ut ON ur.user_id = ut.user_id\n\t\t\t\t\t\t\t\tWHERE sc.songcircle_id = sr.songcircle_id\n\t\t\t\t\t\t\t\tAND sr.confirm_status = 1\n\t\t\t\t\t\t\t\tAND sc.songcircle_status = 5 -- songcircle is complete\n\t\t\t\t\t\t\t\t-- Target: 3 hours after END of songcircle\n\t\t\t\t\t\t\t\tAND TIMESTAMPDIFF( MINUTE, CONVERT_TZ( now(), @@global.time_zone, '+0:00' ),\n\t\t\t\t\t\t\t\tADDTIME(date_of_songcircle, duration) ) < -179 -- greater than 3 hours\n\t\t\t\t\t\t\t\tAND TIMESTAMPDIFF( MINUTE, CONVERT_TZ( now(), @@global.time_zone, '+0:00' ),\n\t\t\t\t\t\t\t\tADDTIME(date_of_songcircle, duration) ) > -209"; //less than 3.5 hours // if result if ($result = $db->getRows($sql)) { file_put_contents($cronlog_location, $log_time . ' -- got result ' . $result . PHP_EOL, FILE_APPEND); foreach ($result as $songcircle_user_data) { file_put_contents($cronlog_location, $log_time . ' ' . $songcircle_user_data['user_id'] . PHP_EOL, FILE_APPEND); // send each user an email with link to survey // construct email $to = "{$songcircle_user_data['user_name']} <{$songcircle_user_data['user_email']}>"; $subject = "How was " . $songcircle_user_data['songcircle_name'] . "?"; $from = "Songfarm <*****@*****.**>"; if ($message = initiateEmail($email_data['songcircle_survey'], $songcircle_user_data)) { $headers = "From: {$from}\r\n"; $headers .= "Content-Type: text/html; charset=utf-8"; if (mail($to, $subject, $message, $headers, '-fsongfarm')) { file_put_contents($cronlog_location, $log_time . ' -- Survey sent - User ' . $songcircle_user_data['user_id'] . ', ' . $songcircle_user_data['songcircle_id'] . ' diff: ' . $songcircle_user_data['diff'] . PHP_EOL, FILE_APPEND); } else { // could not send email file_put_contents($errorLog_location, $log_time . ' ' . error_get_last() . ' -- FAILED: Could not send survey email (' . $_SERVER['PHP_SELF'] . __LINE__ . ') ' . $songcircle_user_data['songcircle_id'] . ' (' . $songcircle_user_data['songcircle_name'] . ') ' . $songcircle_user_data['date_of_songcircle'] . PHP_EOL, FILE_APPEND); } } else { // could not construct email file_put_contents($errorLog_location, $log_time . ' ' . error_get_last() . ' -- FAILED: Could not construct survey email (' . $_SERVER['PHP_SELF'] . __LINE__ . ') ' . $songcircle_user_data['songcircle_id'] . ' (' . $songcircle_user_data['songcircle_name'] . ') ' . $songcircle_user_data['date_of_songcircle'] . PHP_EOL, FILE_APPEND); } } } else { // no query result
/* * NOTE: user_id, confirmation key is returned from getWaitlist and stored in waitlist_data */ $username = $waitlist_data['user']['username']; $user_email = $waitlist_data['user']['user_email']; $user_timezone = $waitlist_data['user']['timezone']; $songcircle_name = $waitlist_data['songcircle']['songcircle_name']; $date_of_songcircle = $waitlist_data['songcircle']['date_of_songcircle']; unset($waitlist_data['songcircle']['date_of_songcircle']); // get user timezone date_of_songcircle $waitlist_data['date_of_songcircle'] = $songcircle->callUserTimezone($date_of_songcircle, $user_timezone); // construct email $to = "{$username} <{$user_email}>"; $subject = "A spot has opened up for " . $songcircle_name . "!"; $from = "Songfarm <*****@*****.**>"; if ($message = initiateEmail($email_data['waitlist'], $waitlist_data)) { $headers = "From: {$from}\r\n"; $headers .= "Content-Type: text/html; charset=utf-8"; if ($result = mail($to, $subject, $message, $headers, '-fsongfarm')) { // write log text $log_text = ' Waitlist -- User ID: ' . $waitlist_data['user']['user_id'] . ' was notified for Songcircle ID: ' . $waitlist_data['songcircle']['songcircle_id']; // write to log file_put_contents(SITE_ROOT . '/logs/songcircle_' . date("m-d-Y") . '.txt', $currentUTCTime . $log_text . PHP_EOL, FILE_APPEND); } else { $err_msg = " -- ERROR: " . $_SERVER['PHP_SELF'] . " (line " . __LINE__ . ") Failed to send email. "; // write to log file_put_contents(SITE_ROOT . '/logs/error_' . date("m-d-Y") . '.txt', $currentUTCTime . $err_msg . error_get_last() . PHP_EOL, FILE_APPEND); } } else { // write error msg $err_msg = " -- ERROR: " . $_SERVER['PHP_SELF'] . " (line " . __LINE__ . ") case 'unregister' - ";
$to = 'Contact Songfarm <*****@*****.**>'; // this may cause a bug on Windows systems $subject .= " sent " . strftime("%a, %B %d at %I:%M %p", time()); $from = "{$name} <{$email}>"; // this may cause a bug on Windows systems $message = "New message from: {$name}\r\n\r\n{$message}"; $headers = "From: {$from}\r\n"; $headers .= "Reply-to: {$email}\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/plain; charset=utf-8"; $result = mail($to, $subject, $message, $headers, '-fsongfarm'); // 5th arg. possible bug if ($result) { echo "Thank you, {$name}, for getting in touch!"; $user_data = ["name" => $name]; if (!($message = initiateEmail($email_data['contact_us'], $user_data))) { // NOTE: log error $err_msg = " -- ERROR: " . $_SERVER['PHP_SELF'] . " (line " . __LINE__ . ") -- initiateEmail failed"; file_put_contents(SITE_ROOT . '/logs/error_' . date("m-d-Y") . '.txt', date("G:i:s") . $err_msg . PHP_EOL, FILE_APPEND); notifyAdminByEmail("Contact Form autoresponder failed to send -- {$_SERVER['PHP_SELF']}"); } else { $to = "{$name} <{$email}>"; $from = "Songfarm <*****@*****.**>"; $subject = "Message Received!"; $headers = "From: {$from}\r\n"; $headers .= "Content-Type: text/html; charset=utf-8"; if (!($result = mail($to, $subject, $message, $headers, '-fsongfarm'))) { // NOTE: write to error log $err_msg = " -- ERROR: " . $_SERVER['PHP_SELF'] . " (line " . __LINE__ . ") -- PHP mail method failed. Unable to send autoresponse"; file_put_contents(SITE_ROOT . '/logs/error_' . date("m-d-Y") . '.txt', date("G:i:s") . $err_msg . PHP_EOL, FILE_APPEND); notifyAdminByEmail($err_msg);