From 7dc41dc17ffba93db782249c26970bb1c06a3b53 Mon Sep 17 00:00:00 2001 From: james Date: Wed, 2 Mar 2005 18:47:19 +0000 Subject: [PATCH] Add all the communication emails stuff to send emails to people --- admin/communication.php | 302 ++++++++++++++++++++++++++++ admin/communication_send_status.php | 77 +++++++ admin/index.php | 2 + admin/send_communication.php | 82 ++++++++ 4 files changed, 463 insertions(+) create mode 100644 admin/communication.php create mode 100644 admin/communication_send_status.php create mode 100644 admin/send_communication.php diff --git a/admin/communication.php b/admin/communication.php new file mode 100644 index 00000000..5e0c17d9 --- /dev/null +++ b/admin/communication.php @@ -0,0 +1,302 @@ + + Copyright (C) 2005 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +<< ".i18n("Back to Administration").""; + echo "
"; + echo "
"; + + if($_POST['action']=="add") + { + if(!$_POST['val']) + { + echo error(i18n("Email Key is required")); + $_GET['action']="add"; + } + else if(!$_POST['name']) + { + echo error(i18n("Email Name is required")); + $_GET['action']="add"; + } + else if(!$_POST['from']) + { + echo error(i18n("Email From is required")); + $_GET['action']="add"; + } + else + { + mysql_query("INSERT INTO emails (val,name,description,`from`,subject,body,type) VALUES (". + "'".mysql_escape_string(stripslashes($_POST['val']))."', ". + "'".mysql_escape_string(stripslashes($_POST['name']))."', ". + "'".mysql_escape_string(stripslashes($_POST['description']))."', ". + "'".mysql_escape_string(stripslashes($_POST['from']))."', ". + "'".mysql_escape_string(stripslashes($_POST['subject']))."', ". + "'".mysql_escape_string(stripslashes($_POST['body']))."', ". + "'user')"); + echo mysql_error(); + echo happy(i18n("Email successfully added")); + } + } + + if($_POST['action']=="edit") + { + if(!$_POST['name']) + { + echo error(i18n("Email Name is required")); + $_GET['action']="edit"; + $_GET['edit']=$_POST['edit']; + } + else if(!$_POST['from']) + { + echo error(i18n("Email From is required")); + $_GET['action']="edit"; + $_GET['edit']=$_POST['edit']; + } + else + { + mysql_query("UPDATE emails SET ". + "name='".mysql_escape_string(stripslashes($_POST['name']))."', ". + "description='".mysql_escape_string(stripslashes($_POST['description']))."', ". + "`from`='".mysql_escape_string(stripslashes($_POST['from']))."', ". + "subject='".mysql_escape_string(stripslashes($_POST['subject']))."', ". + "body='".mysql_escape_string(stripslashes($_POST['body']))."' ". + " WHERE id='".$_POST['edit']."'"); + echo mysql_error(); + echo happy(i18n("Email successfully saved")); + } + + } + + if($_GET['action']=="delete" && $_GET['delete']) + { + mysql_query("DELETE FROM emails WHERE id='".$_GET['delete']."'"); + echo happy("Email successfully deleted"); + + } + + if($_GET['action']=="send" && $_GET['send']) + { + $q=mysql_query("SELECT * FROM emails WHERE id='".$_GET['send']."'"); + $r=mysql_fetch_object($q); + + echo i18n("Please confirm you would like to send the following email, and choose who to send it to"); + echo "
"; + echo "
"; + echo "
"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + $body=htmlspecialchars($r->body); + + echo ""; + + echo "
From:".htmlspecialchars($r->from)."
To:"; + echo ""; + echo "
Date:".date("r")."
Subject:".htmlspecialchars($r->subject)."
".nl2br($body)."
"; + + echo ""; + echo ""; + echo "
"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "
"; + echo ""; + echo "
"; + echo "
"; + } + else if($_GET['action']=="reallysend" && $_GET['reallysend'] && $_GET['to']) + { + if(file_exists("../data/communication.lock")) + { + echo error("Another email communication is already in progress"); + $lines=file("../data/communication.lock"); + echo "
"; + echo "Click here to see the status of the communication sending that is in progress"; + } + else + { + switch ($_GET['to']) + { + case "judges_all": + $q=mysql_query("SELECT count(id) AS num FROM judges"); + break; + default: + echo error(i18n("Unknown 'to' to send email communication to (%1)",array($_GET['to']))); + } + $r=mysql_fetch_object($q); + $num_subscribed=$r->num; + if($r->num) + { + + $q=mysql_query("SELECT * FROM emails WHERE id='".$_GET['reallysend']."'"); + $r=mysql_fetch_object($q); + + //communcation lock file lines: + // 1: Email ID + // 2: Date it was started + // 3: Subject + // 4: Total Recipients + // 5: _GET['to'] + $fp=fopen("../data/communication.lock","w"); + fputs($fp,$r->id."\n"); + fputs($fp,date("r")."\n"); + fputs($fp,$r->subject."\n"); + fputs($fp,$num_subscribed."\n"); + fputs($fp,$_GET['to']."\n"); + fclose($fp); + + system("echo \"/usr/local/bin/php -q send_communication.php ".$_GET['reallysend']."\" | at +1 minute"); + + echo "
"; + echo happy("Email Communication sending has started!"); + echo "
"; + echo "Click here to see the sending progress"; + } + else + { + echo error(i18n("No recipients")); + } + } + } + else if($_GET['action']=="add" || $_GET['action']=="edit") + { + echo "
"; + if($_GET['action']=="edit") + { + $q=mysql_query("SELECT * FROM emails WHERE id='".$_GET['edit']."'"); + $r=mysql_fetch_object($q); + $buttontext=i18n("Save Email"); + echo "\n"; + echo "\n"; + echo "

".i18n("Edit Email")."

"; + + $val=$r->val; + $name=$r->name; + $description=$r->description; + $subject=$r->subject; + $from=$r->from; + $body=$r->body; + } + else + { + $buttontext=i18n("Add Email"); + echo "\n"; + echo "

".i18n("Add Email")."

"; + } + if($_POST['val']) $val=stripslashes($_POST['val']); + if($_POST['name']) $name=stripslashes($_POST['name']); + if($_POST['description']) $description=stripslashes($_POST['description']); + if($_POST['subject']) $subject=stripslashes($_POST['subject']); + if($_POST['from']) $from=stripslashes($_POST['from']); + if($_POST['body']) $body=stripslashes($_POST['body']); + + echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + echo ""; + echo "\n"; + echo "\n"; + echo ""; + echo ""; + echo "
".i18n("Email Name")."
".i18n("Email Key").""; + if($r->type=="system") + echo $val; + else + echo " (must be unique)"; + echo "
".i18n("Email Description")."

".i18n("Email Subject")."
".i18n("Email From")."
".i18n("Email Body")."
"; + echo "
"; + + } + else + { + + $q=mysql_query("SELECT * FROM emails ORDER BY name"); + echo "Add New Email"; + echo ""; + echo ""; + echo " "; + echo " "; + echo " "; + echo ""; + while($r=mysql_fetch_object($q)) + { + + echo ""; + echo ""; + + echo " \n"; + echo ""; + } + echo "
".i18n("Name")."".i18n("Type")."".i18n("Actions")."
$r->name$r->type"; + echo "id\">"; + + //only user emails can be deleted, system ones are required and cannot be removed + if($r->type=="user") + { + echo " "; + echo "id\">"; + echo " "; + echo "id\">Send"; + } + + echo "
"; + } + + send_footer(); +?> + + + + + + + + + + + + + + + + + + + + diff --git a/admin/communication_send_status.php b/admin/communication_send_status.php new file mode 100644 index 00000000..520a1780 --- /dev/null +++ b/admin/communication_send_status.php @@ -0,0 +1,77 @@ + + Copyright (C) 2005 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +<< ".i18n("Back to Administration").""; + echo " "; + echo "<< ".i18n("Back to Communication").""; + echo "
"; + echo "
"; + +echo "

".i18n("Communication Sending Status")."

\n"; +echo "
"; + +if(file_exists("../data/communication.lock")) +{ + $lines=file("../data/communication.lock"); + echo "Email ID: ".$lines[0]."
"; + echo "Started: ".$lines[1]."
"; + echo "Subject: ".$lines[2]."
"; + echo "Total Recipients: ".$lines[3]."
"; + echo "To: ".$lines[4]."
"; + echo "
"; + + $id=trim($lines[0]); + $total=trim($lines[3]); + + echo "

".i18n("Progress")."

"; + echo "
"; + if(file_exists("../data/commmunication.lock.$id")) + { + $progresslines=file("../data/communication.lock.$id"); + $num=$progresslines[0]; + $percent=round($num/$total*100,1); + echo i18n("%1 of %2 (%3%)",array($num,$total,$percent)); + + } + else + { + echo "Queued to start (should start within the next minute)"; + } + echo "
"; + + echo "

Press your browsers 'Refresh' Button to see updated status"; +} +else +{ + echo notice("No Email Communications are currently being sent out"); + echo ""; +} + + +send_footer(); +?> diff --git a/admin/index.php b/admin/index.php index 196b8e4d..b705e8c5 100644 --- a/admin/index.php +++ b/admin/index.php @@ -32,6 +32,8 @@ echo "
"; echo "Committee Management
"; echo "Awards Management
"; + echo "
"; + echo "Communication (Send Emails)
"; send_footer(); ?> diff --git a/admin/send_communication.php b/admin/send_communication.php new file mode 100644 index 00000000..2024a83c --- /dev/null +++ b/admin/send_communication.php @@ -0,0 +1,82 @@ + + Copyright (C) 2005 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +from; + $subject=$communication->subject; + $body=$communication->body; + $headers="From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n"; + $x=1; + + + + switch ($to) + { + case "judges_all": + $q=mysql_query("SELECT firstname, lastname, email FROM judges ORDER BY email"); + break; + default: + echo i18n("Unknown 'to' to send email communication to (%1)",array($_GET['to'])); + } + + while($r=mysql_fetch_object($q)) + { + if($r->firstname && $r->lastname) + $to="$r->firstname $r->lastname <".$r->email.">"; + else if($r->firstname) + $to="$r->firstname <".$r->email.">"; + else + $to=$r->email; + + mail($to,$subject,$body,$headers); + + $fp=fopen("../data/communication.lock.$id","w"); + fputs($fp,$x."\n"); + fclose($fp); + usleep(rand($sleepmin,$sleepmax)); + $x++; + + } + unlink("../data/communication.lock.$id"); + unlink("../data/communication.lock"); +} +else +{ + //no communication to send... why were we called?!?!?! +} + +?>