Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 60 additions & 60 deletions scripts/alertgonemps.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,47 @@
$num = [];
$db = new ParlDB();
foreach ($alertdata as $alertitem) {
$email = $alertitem['email'];
$criteria = $alertitem['criteria'];
if (!strstr($criteria, 'speaker:')) {
continue;
}

preg_match('#speaker:(\d+)#', $criteria, $m);
$person_id = $m[1];
if (!isset($leftd[$person_id])) {
$q = $db->query('SELECT first_name,last_name,MAX(left_house) as l FROM member WHERE person_id = ' . $person_id . ' GROUP BY first_name');
$leftd[$person_id] = $q->field(0, 'l');
$named[$person_id] = $q->field(0, 'first_name') . ' ' . $q->field(0, 'last_name');
}
$left = $leftd[$person_id];
$name = $named[$person_id];
if ($left == '9999-12-31') {
continue;
}

if ($email != $current_email) {
if ($email_text) {
print "$current_email : $email_text\n";
$email = $alertitem['email'];
$criteria = $alertitem['criteria'];
if (!strstr($criteria, 'speaker:')) {
continue;
}
$current_email = $email;
$email_text = '';
$q = $db->query('SELECT user_id FROM users WHERE email = \'' . mysqli_real_escape_string($db, $email) . "'");
if ($q->rows() > 0) {
$user_id = $q->field(0, 'user_id');
$registered++;

preg_match('#speaker:(\d+)#', $criteria, $m);
$person_id = $m[1];
if (!isset($leftd[$person_id])) {
$q = $db->query('SELECT first_name,last_name,MAX(left_house) as l FROM member WHERE person_id = ' . $person_id . ' GROUP BY first_name');
$leftd[$person_id] = $q->field(0, 'l');
$named[$person_id] = $q->field(0, 'first_name') . ' ' . $q->field(0, 'last_name');
}
else {
$user_id = 0;
$unregistered++;
$left = $leftd[$person_id];
$name = $named[$person_id];
if ($left == '9999-12-31') {
continue;
}

if ($email != $current_email) {
if ($email_text) {
print "$current_email : $email_text\n";
}
$current_email = $email;
$email_text = '';
$q = $db->query('SELECT user_id FROM users WHERE email = \'' . mysqli_real_escape_string($db, $email) . "'");
if ($q->rows() > 0) {
$user_id = $q->field(0, 'user_id');
$registered++;
}
else {
$user_id = 0;
$unregistered++;
}
}
}

$email_text .= "$name, ";
$num[$person_id] = 1;
$email_text .= "$name, ";
$num[$person_id] = 1;
}
if ($email_text) {
print "$current_email : $email_text\n";
print "$current_email : $email_text\n";
}

print "Number of different MPs: " . count($num) . "\n";
Expand All @@ -87,29 +87,29 @@
*
*/
function write_and_send_email($email, $user_id, $data) {
global $globalsuccess, $out, $sentemails, $nomail;

if ($user_id) {
$data = "As a registered user, visit http://www.openaustralia.org/user/\nto unsubscribe from, or manage, your alerts.\n\n" . $data;
}
else {
$data = "If you register on the site, you will be able to manage your\nalerts there as well as post comments. :)\n\n" . $data;
}
$out .= "SEND: Sending email to $email\n";
print "SEND: Sending email to $email\n";
$sentemails++;
$d = ['to' => $email, 'template' => 'alert_mailout'];
$m = ['DATA' => $data];
if (!$nomail) {
$success = send_template_email($d, $m);
usleep(500000);
}
else {
$success = 1;
$out .= $data . "\n\n";
// Print $data . "\n\n";.
}
if (!$success) {
$globalsuccess = 0;
}
global $globalsuccess, $out, $sentemails, $nomail;

if ($user_id) {
$data = "As a registered user, visit http://www.openaustralia.org/user/\nto unsubscribe from, or manage, your alerts.\n\n" . $data;
}
else {
$data = "If you register on the site, you will be able to manage your\nalerts there as well as post comments. :)\n\n" . $data;
}
$out .= "SEND: Sending email to $email\n";
print "SEND: Sending email to $email\n";
$sentemails++;
$d = ['to' => $email, 'template' => 'alert_mailout'];
$m = ['DATA' => $data];
if (!$nomail) {
$success = send_template_email($d, $m);
usleep(500000);
}
else {
$success = 1;
$out .= $data . "\n\n";
// Print $data . "\n\n";.
}
if (!$success) {
$globalsuccess = 0;
}
}
Loading
Loading