function save($send_confirmation_email = false) { $db = DB::connect(DB_CONNECTION_STRING); //Check if it exists, the do an update or insert $exists = false; if ($this->user_id != 0) { $sql = "select user_id from user where user_id = " . $this->user_id; $results = $db->query($sql); if (sizeof($results) != 0) { $exists = true; } } if (!$exists) { $this->add(); } else { $this->update(); } //Send email if ($send_confirmation_email == true) { $smarty = new Smarty(); $smarty->force_compile = true; $smarty->compile_dir = SMARTY_COMPILE_DIRECTORY; $smarty->assign("email", $this->email); $smarty->assign("postcode", clean_postcode($this->postcode)); $smarty->assign("url", BASE_URL . "/confirmed.php?cid=" . $this->confirm_id); //Get the email text $email_text = $smarty->fetch('confirm_email_text.tpl'); //Send the email send_text_email($this->email, EMAIL_FROM_NAME, EMAIL_FROM_ADDRESS, "Please confirm your planning alert", $email_text); } }
function send_fail($email) { $smarty = new Smarty(); $smarty->compile_dir = SMARTY_PATH; $smarty->compile_check = true; $smarty->template_dir = TEMPLATE_DIR; $smarty->assign('site_name', SITE_NAME); $smarty->assign('www_server', WWW_SERVER); $subject = 'Failed to upload leadflet'; $body = $smarty->fetch(TEMPLATE_DIR . '/emails/emailin_fail.tlp'); //send email send_text_email(trim($email), SITE_NAME, CONFIRMATION_EMAIL, $subject, $body); }
function send_alert($email_alert, $leaflets) { $smarty = new Smarty(); $smarty->compile_dir = SMARTY_PATH; $smarty->compile_check = true; $smarty->template_dir = TEMPLATE_DIR; $smarty->assign('leaflets', $leaflets); $smarty->assign('leaflet_count', $leaflets); $smarty->assign('url', get_url($email_alert)); $subject = 'New ' . $email_alert->title; $body = $smarty->fetch(TEMPLATE_DIR . '/emails/send_alert.tpl'); //send email send_text_email($email_alert->email, SITE_NAME, CONFIRMATION_EMAIL, $subject, $body); }
function process() { if ($this->validate()) { if ($this->viewstate['sent'] == false) { //send email $email = $this->data['txtEmail']; $name = $this->data['txtName']; $message = "Leaflet link: " . WWW_SERVER . "/leaflets/" . $this->viewstate['leaflet_id'] . "\n"; $message .= "Name: " . $this->data['txtName'] . "\n"; $message .= "Email: " . $this->data['txtEmail'] . "\n"; $message .= "Details: " . $this->data['txtDetails'] . "\n"; send_text_email(CONTACT_EMAIL, $name, $this->data['txtEmail'], "[" . SITE_NAME . "ABUSE REPORT]", $message); } $this->viewstate['message_sent'] = true; } $this->bind(); $this->render(); }
function send_alert($email_alert, $leaflets) { $smarty = new Smarty(); $smarty->compile_dir = SMARTY_PATH; $smarty->compile_check = true; $smarty->template_dir = TEMPLATE_DIR; $smarty->assign('leaflets', $leaflets); $smarty->assign('leaflet_count', $leaflets); $smarty->assign('url', WWW_SERVER . '/leaflets/'); $smarty->assign('unsub_url', WWW_SERVER . '/alerts/manage.php?q=' . $email_alert->confirm_id); $subject = 'New ' . $email_alert->title; $body = $smarty->fetch(TEMPLATE_DIR . '/emails/send_alert.tpl'); //send email if (ALERT_DEBUG_RECIPIENT) { send_text_email(ALERT_DEBUG_RECIPIENT, SITE_NAME, CONFIRMATION_EMAIL, $subject, $body); } else { send_text_email($email_alert->email, SITE_NAME, CONFIRMATION_EMAIL, $subject, $body); } }
function email_log() { //Email log send_text_email(LOG_EMAIL, "parser@" . DOMAIN, "parser@" . DOMAIN, "Planning parser log", print_r($this->log, true)); $this->store_log("Debug email sent to " . LOG_EMAIL); }
public function send_confirmation() { //Setup email text $smarty = new Smarty(); $smarty->compile_dir = SMARTY_PATH; $smarty->compile_check = true; $smarty->template_dir = TEMPLATE_DIR; $smarty->assign('heading', $this->title_parts); $smarty->assign('url', WWW_SERVER . '/alerts/confirm.php?q=' . $this->email_alert->confirm_id); $subject = 'confirm your email alert'; $body = $smarty->fetch(TEMPLATE_DIR . '/emails/confirm_alert.tpl'); //send email send_text_email(trim($this->data['txtEmail']), SITE_NAME, CONFIRMATION_EMAIL, $subject, $body); }
function error_handler($errno, $errmsg, $filename, $linenum, $vars) { $errortype = array(E_ERROR => "Error", E_WARNING => "Warning", E_PARSE => "Parsing Error", E_NOTICE => "Notice", E_CORE_ERROR => "Core Error", E_CORE_WARNING => "Core Warning", E_COMPILE_ERROR => "Compile Error", E_COMPILE_WARNING => "Compile Warning", E_USER_ERROR => "User Error", E_USER_WARNING => "User Warning", E_USER_NOTICE => "User Notice", E_STRICT => "PHP 5 Strict Notice", E_RECOVERABLE_ERROR => 'PHP 5.2 Recoverable Error'); //check error is of an appropriate level $errors_to_report = bit_compactor(ini_get('error_reporting')); if (!in_array($errno, $errors_to_report)) { // There's nothing to report here return; } //get the back trace $backtrace = debug_backtrace(); $backtrace = array_slice($backtrace, 1); //make the message $fatal_errors = array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR); $err = ''; if (isset($_SERVER['REQUEST_URI'])) { $err .= "URL:\t\thttp://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . "\n"; } else { $err .= "URL:\t\tNone - running from command line?\n"; } if (isset($_SERVER['HTTP_REFERER'])) { $err .= "Referer:\t" . $_SERVER['HTTP_REFERER'] . "\n"; } else { $err .= "Referer:\tNone\n"; } if (isset($_SERVER['REMOTE_ADDR'])) { $err .= "REMOTE IP:\t" . $_SERVER['REMOTE_ADDR'] . "\n"; } else { $err .= "REMOTE IP:\tNone\n"; } if (isset($_SERVER['SERVER_ADDR'])) { $err .= "SERVER ADDR:\t" . $_SERVER['SERVER_ADDR'] . "\n"; } else { $err .= "SERVER_ADDR:\tNone\n"; } if (isset($_SERVER['REQUEST_METHOD'])) { $err .= "REQUEST METHOD:\t" . $_SERVER['REQUEST_METHOD'] . "\n"; } else { $err .= "REQUEST METHOD:\tNone\n"; } if (isset($_SERVER['HTTP_USER_AGENT'])) { $err .= "User-Agent:\t" . $_SERVER['HTTP_USER_AGENT'] . "\n"; } else { $err .= "User-Agent:\tNone\n"; } $err .= "Number:\t\t{$errno}\n"; $err .= "Type:\t\t" . $errortype[$errno] . "\n"; $err .= "Message:\t{$errmsg}\n"; $err .= "File:\t\t{$filename}\n"; $err .= "Line:\t\t{$linenum}\n"; // Add in the suplimentry data if (isset($GLOBALS['_REPORT_ERROR_MESSAGE']) && !empty($GLOBALS['_REPORT_ERROR_MESSAGE'])) { $err .= "Info:\t\t" . $GLOBALS['_REPORT_ERROR_MESSAGE'] . "\n"; unset($GLOBALS['_REPORT_ERROR_MESSAGE']); } // get the details of where the error is if (is_readable($filename)) { $source = file($filename); $err .= "\nSource:\n\n"; // show the line, plus prev and next, with line numbers. $err .= $linenum - 2 . " " . $source[$linenum - 3]; $err .= $linenum - 1 . " " . $source[$linenum - 2]; $err .= "<b>" . $linenum . " " . $source[$linenum - 1] . "</b>"; $err .= $linenum + 1 . " " . $source[$linenum]; $err .= $linenum + 2 . " " . $source[$linenum + 1]; } // add in the back trace $err .= "\nBacktrace:\n " . adodb_backtrace(false, $backtrace); // Now we want to add in the session, request and suplimentry data if (isset($_REQUEST) && is_array($_REQUEST) && count($_REQUEST) > 0) { $err .= "\nREQUEST Data:\n\n"; $err .= print_r($_REQUEST, true); } if (isset($GLOBALS['_REPORT_ERROR_DATA'])) { $err .= "\nADDITIONAL Data:\n\n"; $err .= print_r($GLOBALS['_REPORT_ERROR_DATA'], true); unset($GLOBALS['_REPORT_ERROR_DATA']); } //anything useful in the session if (isset($_SESSION) && is_array($_SESSION) && count($_SESSION) > 0) { $session = $_SESSION; $err .= "\nSESSION Data:\n\n"; $err .= print_r($session, true); } //either display the message on screen or email it (if on the live site) $fatal = false; if (DEVSITE) { print '<pre>' . $err . '</pre>'; } else { //send the email $subject = BUG_EMAIL_PREFIX . ' ' . ($errno != E_USER_WARNING ? 'FATAL ' : 'WARNING ') . (defined('APP_NAME') ? '(' . APP_NAME . ') ' : '') . $errmsg; send_text_email(BUG_TO_EMAIL, BUG_EMAIL_PREFIX, BUG_FROM_EMAIL, $subject, $err); if ($errno != E_USER_WARNING) { //tell people something bad happened print '<div style="text-align:center;">'; print '<h1>Sorry, something went wrong</h1>'; print '<h3>An email has been sent to the geeks!</h3>'; print '<p><a href="http://www.thestraightchoice.org">click here to go back to the homepage</a></p>'; print '</div>'; $fatal = true; } } //Copy error to the error log error_log($errortype[$errno] . ' : ' . $errmsg . ' ( ' . $filename . ' [' . $linenum . '] )'); //if fatal then die() if ($fatal || in_array($errno, $fatal_errors)) { die; } }
function run() { $db = DB::connect(DB_CONNECTION_STRING); //Grab all the users $sql = "select user_id, email, postcode, bottom_left_x, bottom_left_y, top_right_x, top_right_y, alert_area_size, confirm_id\n from user\n where confirmed = 1 and last_sent < " . $db->quote(mysql_date(time() - 20 * 60 * 60)); $this->store_log("Grabbing users"); $user_results = $db->getAll($sql); $this->store_log("Found " . sizeof($user_results) . " who havnt been checked since " . mysql_date(time() - 20 * 60 * 60)); if (sizeof($user_results) > 0) { //Loop though users for ($i = 0; $i < sizeof($user_results); $i++) { //Find applications for that user $sql = "select distinct council_reference, address, \n postcode, description, info_tinyurl, \n comment_tinyurl, map_url, full_name\n from application\n inner join authority on application.authority_id = authority.authority_id \n where date_scraped > " . $db->quote(mysql_date(time() - 24 * 60 * 60)) . " and (application.x > " . $user_results[$i][3] . " and application.x < " . $user_results[$i][5] . ")\n and (application.y > " . $user_results[$i][4] . " and application.y < " . $user_results[$i][6] . ") and (application.y <> 0 and application.y <> 0 )"; $application_results = $db->getAll($sql); //Send email if we have any if (sizeof($application_results) > 0) { //Setup applications array (bit pikey this) $applications = array(); for ($ii = 0; $ii < sizeof($application_results); $ii++) { $application = new application(); $application->council_reference = $application_results[$ii][0]; $application->address = $application_results[$ii][1]; $application->postcode = $application_results[$ii][2]; $application->description = $application_results[$ii][3]; $application->info_tinyurl = $application_results[$ii][4]; $application->comment_tinyurl = $application_results[$ii][5]; $application->map_url = $application_results[$ii][6]; $application->authority_name = $application_results[$ii][7]; array_push($applications, $application); } $this->application_count += sizeof($applications); //Smarty template $smarty = new Smarty(); $smarty->force_compile = true; $smarty->compile_dir = SMARTY_COMPILE_DIRECTORY; $smarty->assign("applications", $applications); $smarty->assign("base_url", BASE_URL); $smarty->assign("confirm_id", $user_results[$i][8]); $smarty->assign("alert_area_size", $user_results[$i][7]); $smarty->assign("alert_postcode", $user_results[$i][2]); //Get the email text $email_text = $smarty->fetch(SMARTY_TEMPLATE_DIRECTORY . 'alert_email_text.tpl'); //Send the email if ($email_text != "") { send_text_email($user_results[$i][1], EMAIL_FROM_NAME, EMAIL_FROM_ADDRESS, "Planning applications near " . strtoupper($user_results[$i][2]), $email_text); $this->email_count += 1; } else { $this->store_log("BLANK EMAIL TEXT !!! EMAIL NOT SENT"); } //Update last sent $sql = "update user set last_sent = " . $db->quote(mysql_date(time())) . " where user_id = " . $user_results[$i][0]; $db->query($sql); $this->store_log("Updating last checked date/time"); } } } $this->store_log("Sent " . $this->application_count . " applications to " . $this->email_count . " people!"); //update the number of apps sent $sql = "select `key`, `value` from stats"; $stats_results = $db->getAll($sql); $new_application_total = 0; $new_email_total = 0; for ($i = 0; $i < sizeof($stats_results); $i++) { if ($stats_results[$i][0] == 'applications_sent') { $new_application_total = $stats_results[$i][1] + $this->application_count; $new_email_total = $stats_results[$i][1] + $this->email_count; } } //add stats to email $this->store_log("Total applications ever sent: " . $new_application_total); $this->store_log("Total emails ever sent: " . $new_email_total); //update stats in DB $sql = "update stats set `value` = " . $new_application_total . " where `key` = 'applications_sent'"; $db->query($sql); $sql = "update stats set `value` = " . $new_email_total . " where `key` = 'emails_sent'"; $db->query($sql); //Send the log send_text_email(LOG_EMAIL, "mailer@" . DOMAIN, "mailer@" . DOMAIN, "Planning mailer log", print_r($this->log, true)); }