Skip to content

Commit

Permalink
add notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaudiomv committed Oct 10, 2018
1 parent d86bb54 commit 50fdf78
Show file tree
Hide file tree
Showing 75 changed files with 9,469 additions and 4 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ These will be added as links to main menu if they exist in the config.

* static $bmlt_instructional_video = 'https://www.dropbox.com/s/of7xevt0o62rgb1/meetings.mp4?dl=0';

# BMLT Notify

Sends an email with all BMLT changes in x amount of days

# install
download the repository and edit the config.php then put on a server and create cron job. the config $homanydays should be set to the same amount of time you set your cron job for.

# example
example cron job calls, this would set to call the script at 6pm on sunday

0 18 * * 0 wget -q -O - https://someserver.org/bmltnotify.php >/dev/null

0 18 * * 0 curl --silent https://someserver.org/bmltnotify.php >/dev/null

# Timezones for config
Eastern ........... America/New_York
Expand Down
134 changes: 134 additions & 0 deletions bmltnotify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php
include 'config.php';
require_once 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;

date_default_timezone_set("$timezone");
$today=date("Y-m-d");
$dateminus=date('Y-m-d', strtotime("-$howmanydays days"));

// show beginning header
$message = "<H2>" .$service_body_name. " CHANGES</H2>Changes for last $howmanydays day(s) from " .date("l jS \of F Y h:i A") . "<br><hr>";

$url = $bmlt_server. "/client_interface/xml/?switcher=GetChanges&start_date=" .$dateminus. "&end_date=" .$today. "&service_body_id=" .$service_body_id;

// get xml file contents
$xml = simplexml_load_file($url);

if (empty($xml)) {
// if no changes found do nothing
}

else {
// loop begins
foreach($xml->row as $row) {
if( strpos( $row->meeting_name, '_YAP_' ) !== false ) {
// dont show YAP data
}
else {
// begin new paragraph
$message .= "<p>";

// show Date
$message .= "<strong>Date:</strong> ".$row->date_string." - ";

// show Change Type
$change_type=$row->change_type;
if ($change_type == "comdef_change_type_change") { $change_type = "Change"; }
if ($change_type == "comdef_change_type_delete") { $change_type = "DELETE"; }
if ($change_type == "comdef_change_type_new") { $change_type = "New"; }
$message .= "<strong>Change Type:</strong> ".$change_type."<br/>";

// show Meeting ID
$message .= "<strong>Meeting (ID) Name:</strong> (".$row->meeting_id.") " .$row->meeting_name."<br/>";

// show User Name
$message .= "<strong>User Name:</strong> ".$row->user_name."<br/>";

// Show Service Body
$message .= "<strong>Service Body:</strong> ".$row->service_body_name."</br><OL>";

// show details
$details=$row->details;
// remove root_server_uri info
$details = str_replace(". root_server_uri was added as \"https:\" "," ",$details);
// Remove last . at end of details
$details = preg_replace('/.$/',"",$details);
// Remove the weird #@-@# from the format codes
$details = str_replace("#@-@#"," ",$details);
// protect email . from being replaced with </br> tag
$details = preg_replace_callback(
'/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})/',
function ($email) {
return str_replace(".","~DOT~",$email[0]);
},
$details
);
// Look for Latittude and Longitude, change . to ~DOT~ This must happen so we can then find the individual changes and add <li>
$details = preg_replace_callback(
'/from \"[0-9]+\./',
function ($matches) {
return str_replace(".","~DOT~",$matches[0]);
},
$details
);
$details = preg_replace_callback(
'/to \"[0-9]+\./',
function ($matches) {
return str_replace(".","~DOT~",$matches[0]);
},
$details
);
$details = preg_replace_callback(
'/from \"-+[0-9]+\./',
function ($matches) {
return str_replace(".","~DOT~",$matches[0]);
},
$details
);
$details = preg_replace_callback(
'/to \"-+[0-9]+\./',
function ($matches) {
return str_replace(".","~DOT~",$matches[0]);
},
$details
);

// Change all the . to <LI>
$details = str_replace(".","<LI>",$details);

//Change all the ~DOT~ back to .
$details = str_replace("~DOT~",".",$details);
// $details = str_replace("from \"-75</br>"," from \"-75.",$details);
$message .= "<strong>Details:</strong><LI> ".$details."</OL>";
$message .= "</p> <hr>";
// end paragraph
}
}
// loop ends
$message .= "END of BMLT Changes";
//echo $message; // for testing

//Send Email
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = $smtp_host;
$mail->SMTPAuth = true;
$mail->Username = $smtp_username;
$mail->Password = $smtp_password;
$mail->SMTPSecure = $smtp_secure;
if ($smtp_alt_port) {
$mail->Port = $smtp_alt_port;
} elseif ($smtp_secure == 'tls') {
$mail->Port = 587;
} elseif ($smtp_secure == 'ssl') {
$mail->Port = 465;
}
$mail->setFrom($smtp_from_address, $smtp_from_name);
$mail->isHTML(true);
$mail->addAddress($smtp_to_address, $smtp_to_name);
$mail->Body = $message;
$mail->Subject = $smtp_email_subject;
$mail->send();
}
?>
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"phpmailer/phpmailer": "6.0.5"
}
}
84 changes: 84 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
<?php
static $bmlt_server = 'http://crna.org/main_server';
static $timezone = 'America/New_York';
static $service_body_name = 'Carolina Region';
static $service_body_shortname = 'CRNA';
static $service_body_website = 'http://crna.org';
static $bmlt_server = '';
static $service_body_name = '';
static $service_body_shortname = '';
static $service_body_website = '';
static $service_body_id = '1'; // the BMLT parent service body id number
static $howmanydays = '30'; // this should be set to the same number of days your cron job is set to



//static $from_name = 'Service Body Admin';
//static $from_email = '[email protected]';

static $smtp_to_name = '';
static $smtp_to_address = '';
static $smtp_email_subject = 'Service Body BMLT Changes';

static $smtp_host = ''; // the smtp server
static $smtp_username = ''; // the smtp username
static $smtp_password = ''; // the smtp password
static $smtp_secure = ''; // either ssl (port 486) or more securely tls (port 587)
static $smtp_from_address = ''; // the address where the email will be sent from
static $smtp_from_name = ''; // the label name on the from address
4 changes: 4 additions & 0 deletions upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
mv config.php ../
git pull origin master
mv ../config.php .
Binary file added vendor/.DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit211839d18b0c3e24c5457707508f819b::getLoader();
Loading

0 comments on commit 50fdf78

Please sign in to comment.