2005-03-02 18:47:19 +00:00
< ?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website : http :// www . sfiab . ca
Copyright ( C ) 2005 Sci - Tech Ontario Inc < info @ scitechontario . org >
Copyright ( C ) 2005 James Grant < james @ lightbox . org >
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 .
*/
?>
< ?
2009-10-14 03:25:47 +00:00
require_once ( " ../common.inc.php " );
2007-11-21 17:02:09 +00:00
require_once ( " ../user.inc.php " );
2007-11-18 23:50:23 +00:00
user_auth_required ( 'committee' , 'admin' );
2009-10-14 03:25:47 +00:00
2009-12-01 22:02:03 +00:00
function launchQueue () {
if ( ! file_exists ( " ../data/logs " )) {
mkdir ( " ../data/logs " );
}
exec ( " php -q send_emailqueue.php >>../data/logs/emailqueue.log 2>&1 & " );
}
2009-10-14 03:25:47 +00:00
/* dialog_choose
* select : comm_dialog_choose_select ( emails_id )
* cancel : comm_dialog_choose_cancel () */
switch ( $_GET [ 'action' ]) {
case 'dialog_choose_load' :
$emails_id = intval ( $_GET [ 'emails_id' ]);
$q = mysql_query ( " SELECT * FROM emails WHERE id=' $emails_id ' " );
$e = mysql_fetch_assoc ( $q );
?>
< table class = " editor " >
< tr >< td class = " label " style = " width:15% " >< ? = i18n ( 'Name' ) ?> :</td><td class="input"><?=$e['name']?></td></tr>
< tr >< td class = " label " >< ? = i18n ( 'Subject' ) ?> :</td><td class="input"><?=$e['subject']?></td></tr>
< tr >< td class = " label " >< ? = i18n ( 'From Address' ) ?> :</td><td class="input"><?=$e['from']?></td></tr>
< tr >< td ></ td >< td >
< div style = " border:1px solid black; overflow:auto; height=300px; " >< ? = $e [ 'bodyhtml' ] ?> </div>
</ td ></ tr ></ table >
< ?
exit ;
case 'dialog_choose' :
?>
< div id = " comm_dialog_choose " title = " Select a Communication " style = " display: none " >
< h4 >< ? = i18n ( " Select a Communication " ) ?> :</h4>
< form id = " choose " onchange = " dialog_choose_change() " onkeypress = " dialog_choose_change() " >
< table style = " width:100% " >< tr >< td >
< select id = " comm_dialog_choose_emails_id " >
< option value = " -1 " >-- < ? = i18n ( 'Choose a Communication' ) ?> --</option>
< ?
$type = mysql_real_escape_string ( $_GET [ 'type' ]);
$q = mysql_query ( " SELECT * FROM emails WHERE type=' $type ' " );
while ( $e = mysql_fetch_assoc ( $q )) {
echo " <option value= \" { $e [ 'id' ] } \" > { $e [ 'name' ] } </option> " ;
}
?>
</ select >
</ td >< td style = " text-align:right " >
< input class = " comm_dialog_choose_email_button " disabled = " disabled " type = " submit " value = " <?=i18n('Choose')?> " >
< input class = " comm_dialog_choose_cancel_button " type = " submit " value = " <?=i18n('Cancel')?> " >
</ td ></ tr ></ table >
< hr />
< div id = " comm_dialog_choose_info " ></ div >
< hr />
< input class = " comm_dialog_choose_email_button " disabled = " disabled " type = " submit " value = " <?=i18n('Choose')?> " >
< input class = " comm_dialog_choose_cancel_button " type = " submit " value = " <?=i18n('Cancel')?> " >
</ form >
</ div >
< script type = " text/javascript " >
2009-10-14 04:56:28 +00:00
var comm_dialog_choose_selected = - 1 ;
2009-10-14 03:25:47 +00:00
$ ( " .comm_dialog_choose_email_button " ) . click ( function () {
var sel = $ ( " #comm_dialog_choose_emails_id " ) . val ();
2009-10-14 04:56:28 +00:00
comm_dialog_choose_selected = sel ;
2009-10-14 03:25:47 +00:00
$ ( '#comm_dialog_choose' ) . dialog ( " close " );
return false ;
});
$ ( " .comm_dialog_choose_cancel_button " ) . click ( function () {
$ ( '#comm_dialog_choose' ) . dialog ( " close " );
return false ;
});
function dialog_choose_change ()
{
var sel = $ ( " #comm_dialog_choose_emails_id " ) . val ();
$ ( " #comm_dialog_choose_info " ) . html ( " Loading... " );
$ ( " #comm_dialog_choose_info " ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/admin/communication.php?action=dialog_choose_load&emails_id= " + sel );
if ( sel == - 1 ) {
$ ( " .comm_dialog_choose_email_button " ) . attr ( 'disabled' , 'disabled' );
} else {
$ ( " .comm_dialog_choose_email_button " ) . removeAttr ( 'disabled' );
}
return false ;
}
$ ( " #comm_dialog_choose " ) . dialog ({
2009-10-14 04:56:28 +00:00
bgiframe : true , autoOpen : true ,
2009-10-14 03:25:47 +00:00
modal : true , resizable : false ,
draggable : false ,
2009-10-14 04:56:28 +00:00
width : 700 , //(document.documentElement.clientWidth * 0.8);
height : ( document . documentElement . clientHeight * 0.8 ),
2009-10-14 03:25:47 +00:00
close : function () {
$ ( this ) . dialog ( 'destroy' );
$ ( '#comm_dialog_choose' ) . remove ();
2009-10-14 04:56:28 +00:00
/* Run callbacks */
if ( comm_dialog_choose_selected != - 1 ) {
if ( typeof ( comm_dialog_choose_select ) == 'function' ) {
comm_dialog_choose_select ( comm_dialog_choose_selected );
}
} else {
if ( typeof ( comm_dialog_choose_cancel ) == 'function' ) {
comm_dialog_choose_cancel ();
}
2009-10-14 03:25:47 +00:00
}
2009-10-14 04:56:28 +00:00
}
2009-10-14 03:25:47 +00:00
});
</ script >
< ?
exit ;
case 'email_save' :
$id = intval ( $_POST [ 'emails_id' ]);
2009-10-15 21:58:51 +00:00
$name = mysql_real_escape_string ( stripslashes ( $_POST [ 'name' ]));
$description = mysql_real_escape_string ( stripslashes ( $_POST [ 'description' ]));
$from = mysql_real_escape_string ( stripslashes ( $_POST [ 'from' ]));
$subject = mysql_real_escape_string ( stripslashes ( $_POST [ 'subject' ]));
$bodyhtml = mysql_real_escape_string ( stripslashes ( $_POST [ 'bodyhtml' ]));
2009-10-14 03:25:47 +00:00
$type = mysql_real_escape_string ( $_POST [ 'type' ]);
2009-10-14 04:56:28 +00:00
$key = mysql_real_escape_string ( $_POST [ 'key' ]);
$fcid = mysql_real_escape_string ( $_POST [ 'fcid' ]);
2009-10-14 03:25:47 +00:00
if ( $id == 0 ) {
2009-12-02 22:17:20 +00:00
if ( $key && $name ) {
mysql_query ( " INSERT INTO emails(type,val) VALUES(' $type ',' $key ') " );
echo mysql_error ();
$id = mysql_insert_id ();
} else {
error_ ( " Email Key and Name are required " );
exit ;
}
2009-10-14 03:25:47 +00:00
}
2009-10-14 04:56:28 +00:00
/* Allow the fundraising campaigns id to be NULL, it'll never be 0 */
$fcstr = ( $fcid == 0 ) ? 'NULL' : " ' $fcid ' " ;
2010-02-11 16:41:17 +00:00
$bodyhtml = iconv ( " UTF-8 " , " ISO-8859-1 " , $bodyhtml );
$name = iconv ( " UTF-8 " , " ISO-8859-1 " , $name );
$description = iconv ( " UTF-8 " , " ISO-8859-1 " , $description );
$from = iconv ( " UTF-8 " , " ISO-8859-1 " , $from );
$subject = iconv ( " UTF-8 " , " ISO-8859-1 " , $subject );
2009-12-02 22:17:20 +00:00
2009-12-02 23:11:25 +00:00
$body = getTextFromHtml ( $bodyhtml );
2009-12-02 22:17:20 +00:00
mysql_query ( " UPDATE emails SET
name = '$name' ,
description = '$description' ,
`from` = '$from' ,
subject = '$subject' ,
body = '$body' ,
bodyhtml = '$bodyhtml' ,
2009-10-14 04:56:28 +00:00
fundraising_campaigns_id = $fcstr
2009-10-14 03:25:47 +00:00
WHERE id = '$id' " );
echo mysql_error ();
happy_ ( " Email Saved " );
exit ;
case 'dialog_edit' :
2010-02-04 06:48:42 +00:00
2009-10-14 03:25:47 +00:00
if ( array_key_exists ( 'id' , $_GET )) {
$id = intval ( $_GET [ 'id' ]);
2009-10-14 04:56:28 +00:00
$cloneid = 0 ;
} else if ( array_key_exists ( 'cloneid' , $_GET )) {
$id = intval ( $_GET [ 'cloneid' ]);
$clone_id = $id ;
2009-10-14 03:25:47 +00:00
} else {
2009-10-14 04:56:28 +00:00
/* new email, set defaults which may be specified */
$id = 0 ;
$key = htmlspecialchars ( $_GET [ 'key' ]);
if ( array_key_exists ( 'fundraising_campaigns_id' , $_GET )) {
$fcid = intval ( $_GET [ 'fundraising_campaigns_id' ]);
$type = 'fundraising' ;
2009-12-01 22:02:03 +00:00
$q = mysql_query ( " SELECT * FROM fundraising_campaigns WHERE id=' $fcid ' " );
$fc = mysql_fetch_object ( $q );
$name = i18n ( " %1 communication for %2 " , array ( ucfirst ( $key ), $fc -> name ));
2009-10-14 04:56:28 +00:00
} else {
$fcid = 0 ;
$type = ( array_key_exists ( 'type' , $_GET )) ? $_GET [ 'type' ] : 'user' ;
}
2009-12-02 22:17:20 +00:00
$from = $_SESSION [ 'name' ] . " < " . $_SESSION [ 'email' ] . " > " ;
2009-10-14 03:25:47 +00:00
}
2009-10-14 04:56:28 +00:00
if ( $id ) {
$q = mysql_query ( " SELECT * FROM emails WHERE id=' $id ' " );
2009-10-14 03:25:47 +00:00
if ( mysql_num_rows ( $q ) != 1 ) {
echo " Ambiguous edit " ;
exit ;
}
$e = mysql_fetch_assoc ( $q );
2009-10-14 04:56:28 +00:00
/* If we ' re supposed to clone it , load it then zero out the
* id so we make a new record on save , and override the key */
if ( $clone_id ) {
$e [ 'id' ] = 0 ;
$e [ 'val' ] = $_GET [ 'key' ];
$e [ 'fundraising_campaigns_id' ] = $_GET [ 'fundraising_campaigns_id' ];
}
2009-10-14 03:25:47 +00:00
$emails_id = $e [ 'id' ];
$name = htmlspecialchars ( $e [ 'name' ]);
2009-10-14 04:56:28 +00:00
$key = htmlspecialchars ( $e [ 'val' ]);
2009-10-14 03:25:47 +00:00
$description = htmlspecialchars ( $e [ 'description' ]);
$from = htmlspecialchars ( $e [ 'from' ]);
2009-12-02 22:17:20 +00:00
if ( ! $from && $config [ 'fairmanageremail' ]) $from = " Fair Manager < " . $config [ 'fairmanageremail' ] . " > " ;
2009-10-14 03:25:47 +00:00
$subject = htmlspecialchars ( $e [ 'subject' ]);
$body = $e [ 'body' ];
$bodyhtml = $e [ 'bodyhtml' ];
2009-10-14 04:56:28 +00:00
$fcid = intval ( $e [ 'fundraising_campaigns_id' ]);
2009-12-02 22:17:20 +00:00
if ( $bodyhtml == '' ) $bodyhtml = nl2br ( $body );
2009-10-14 03:25:47 +00:00
}
?>
< div id = " comm_dialog_edit " title = " Edit a Communication " style = " display: none " >
< br />
< form id = " comm_dialog_edit_form " >
< input type = " hidden " name = " type " value = " <?= $type ?> " />
2009-10-14 04:56:28 +00:00
< input type = " hidden " name = " fcid " value = " <?= $fcid ?> " />
2009-12-02 22:17:20 +00:00
< table class = " editor " style = " width: 95% " >
< ?
if ( $emails_id ) {
?>
< input type = " hidden " name = " emails_id " value = " <?= $emails_id ?> " />
< input type = " hidden " name = " key " value = " <?= $key ?> " />
< tr >
< td class = " label " >< ? = i18n ( " Email Key " ) ?> :</td>
< td class = " input " >< ? = $key ?> </td>
</ tr >
< ?
}
2009-12-03 19:41:25 +00:00
else if ( $key ) {
echo " <input type= \" hidden \" name= \" key \" value= \" $key\ " /> \n " ;
}
2009-12-02 22:17:20 +00:00
else {
?>
< tr >
< td class = " label " >< ? = i18n ( " Email Key " ) ?> :</td>
< td class = " input " >< input type = " text " name = " key " size = " 60 " value = " " /></ td >
</ tr >
< ?
}
/* ="fcid=$fcid, key=$key, type=$type"*/ ?>
< tr >
2009-10-16 15:21:58 +00:00
< td class = " label " >< ? = i18n ( " Name " ) ?> :</td>
2009-10-14 03:25:47 +00:00
< td class = " input " >< input type = " text " name = " name " size = " 60 " value = " <?= $name ?> " /></ td >
2009-12-02 22:17:20 +00:00
</ tr >
< tr >
2009-10-14 03:25:47 +00:00
< td class = " label " >< ? = i18n ( " Description " ) ?> :</td>
< td class = " input " >< input type = " text " name = " description " size = " 60 " value = " <?= $description ?> " /></ td >
</ tr >< tr >
< tr >< td colspan = " 2 " >< hr /></ td >
</ tr >< tr >
< td class = " label " >< ? = i18n ( " From Address " ) ?> :</td>
< td class = " input " >< input type = " text " name = " from " size = " 60 " value = " <?= $from ?> " /></ td >
2009-10-16 06:16:48 +00:00
</ tr >< tr >
2009-10-16 15:21:58 +00:00
< td class = " label " >< ? = i18n ( " Subject " ) ?> :</td>
2009-10-16 06:16:48 +00:00
< td class = " input " >< input type = " text " name = " subject " size = " 60 " value = " <?= $subject ?> " /></ td >
2009-10-14 03:25:47 +00:00
</ tr >< tr >
2009-10-14 19:48:40 +00:00
< td colspan = " 2 " class = " input " >
2009-10-15 07:11:43 +00:00
< table width = " 100% " >< tr >< td width = " 85% " >
< div id = " fck " >
2009-10-15 21:58:51 +00:00
< textarea id = " bodyhtml " name = " bodyhtml " rows = 6 cols = 80 >< ? = $bodyhtml ?> </textarea>
2009-10-15 07:11:43 +00:00
</ div >
2009-10-14 19:48:40 +00:00
</ td >< td width = " 15% " >
2009-10-16 15:21:58 +00:00
< select id = " comm_dialog_insert_field " name = " insert_field " size = " 20 " style = " height:300 " >
2009-10-16 06:16:48 +00:00
< option value = " EMAIL " > [ EMAIL ] </ option >
2009-10-14 19:48:40 +00:00
< option value = " FAIRNAME " > [ FAIRNAME ] </ option >
2009-10-16 06:16:48 +00:00
< option value = " FIRSTNAME " > [ FIRSTNAME ] </ option >
< option value = " LASTNAME " > [ LASTNAME ] </ option >
< option value = " NAME " > [ NAME ] </ option >
2009-12-02 22:17:20 +00:00
< option value = " SALUTATION " > [ SALUTATION ] </ option >
2009-10-16 06:16:48 +00:00
< option value = " PASSWORD " > [ PASSWORD ] </ option >
2009-12-02 22:17:20 +00:00
< option value = " REGNUM " > [ REGNUM ] </ option >
2010-01-27 20:24:14 +00:00
< option value = " URLMAIN " > [ URLMAIN ] </ option >
< option value = " URLLOGIN " > [ URLLOGIN ] </ option >
2009-10-14 19:48:40 +00:00
</ select >
</ td ></ tr ></ table >
2009-10-14 03:25:47 +00:00
</ td >
</ tr ></ table >
< hr />
< div align = " right " >
< input type = " submit " id = " comm_dialog_edit_save_button " value = " <?=i18n('Save')?> " />
< input type = " submit " id = " comm_dialog_edit_cancel_button " value = " <?=i18n('Cancel')?> " />
</ div >
</ form >
</ div >
2009-10-15 07:11:43 +00:00
< script type = " text/javascript " src = " <?= $config['SFIABDIRECTORY'] ?>/fckeditor/fckeditor.js " ></ script >
2009-10-14 03:25:47 +00:00
< script type = " text/javascript " >
2009-10-14 04:56:28 +00:00
var comm_dialog_edit_saved = false ;
2009-10-14 03:25:47 +00:00
$ ( " #comm_dialog_edit_save_button " ) . click ( function () {
2009-10-15 21:58:51 +00:00
var oFCKeditor = FCKeditorAPI . GetInstance ( 'bodyhtml' ) ;
var value = oFCKeditor . GetHTML ();
$ ( '#bodyhtml' ) . val ( value );
2009-10-14 03:25:47 +00:00
$ ( " #debug " ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/admin/communication.php?action=email_save " , $ ( " #comm_dialog_edit_form " ) . serializeArray (),
function () {
2009-10-14 04:56:28 +00:00
comm_dialog_edit_saved = true ;
2009-10-14 03:25:47 +00:00
$ ( '#comm_dialog_edit' ) . dialog ( " close " );
});
return false ;
}
);
$ ( " #comm_dialog_edit_cancel_button " ) . click ( function () {
$ ( '#comm_dialog_edit' ) . dialog ( " close " );
return false ;
}
);
2010-02-04 06:48:42 +00:00
2009-10-14 03:25:47 +00:00
$ ( " #comm_dialog_edit " ) . dialog ({
2009-10-14 04:56:28 +00:00
bgiframe : true , autoOpen : true ,
2009-10-14 03:25:47 +00:00
modal : true , resizable : false ,
draggable : false ,
2009-10-14 04:56:28 +00:00
width : 800 , //(document.documentElement.clientWidth * 0.8);
height : ( document . documentElement . clientHeight * 0.8 ),
2009-10-14 03:25:47 +00:00
close : function () {
$ ( this ) . dialog ( 'destroy' );
$ ( '#comm_dialog_edit' ) . remove ();
2009-10-14 04:56:28 +00:00
/* Run callbacks */
if ( comm_dialog_edit_saved == true ) {
if ( typeof ( comm_dialog_edit_save ) == 'function' ) {
comm_dialog_edit_save ( < ? = $emails_id ?> );
}
} else {
if ( typeof ( comm_dialog_edit_cancel ) == 'function' ) {
comm_dialog_edit_cancel ();
}
}
2009-12-02 22:17:20 +00:00
if ( typeof ( refreshEmailList ) == 'function' ) {
refreshEmailList ();
}
2009-10-14 04:56:28 +00:00
2009-10-14 03:25:47 +00:00
}
});
2009-10-16 15:21:58 +00:00
$ ( " #comm_dialog_insert_field " ) . click ( function () {
var oFCKeditor = FCKeditorAPI . GetInstance ( 'bodyhtml' ) ;
var value = oFCKeditor . GetHTML ();
oFCKeditor . InsertHtml ( " [ " + this . value + " ] " );
return false ;
}
);
2009-10-15 07:11:43 +00:00
var oFCKeditor = new FCKeditor ( 'bodyhtml' ) ;
oFCKeditor . BasePath = " ../fckeditor/ " ;
oFCKeditor . ToolbarSet = 'sfiab' ;
oFCKeditor . Width = " 100% " ;
oFCKeditor . Height = 300 ;
2009-10-15 21:58:51 +00:00
// $('#fck').html(oFCKeditor.CreateHtml());
oFCKeditor . ReplaceTextarea () ;
2009-10-14 03:25:47 +00:00
</ script >
< ?
exit ;
2009-12-01 22:02:03 +00:00
case 'dialog_send' :
?>
< div id = " comm_dialog_send " title = " Send Communication " style = " display: none " >
< ?
$fcid = intval ( $_GET [ 'fundraising_campaigns_id' ]);
$emailid = intval ( $_GET [ 'emails_id' ]);
$fcq = mysql_query ( " SELECT * FROM fundraising_campaigns WHERE id=' $fcid ' " );
$fc = mysql_fetch_object ( $fcq );
$emailq = mysql_query ( " SELECT * FROM emails WHERE id=' $emailid ' " );
$email = mysql_fetch_object ( $emailq );
?>
< form id = " send " >
< table style = " width:100% " >
< ?
$q = mysql_query ( " SELECT COUNT(*) AS num FROM fundraising_campaigns_users_link WHERE fundraising_campaigns_id=' $fcid ' " );
$r = mysql_fetch_object ( $q );
$numrecipients = $r -> num ;
echo " <tr><td> " . i18n ( " Appeal " ) . " </td><td> " . $fc -> name . " - " . i18n ( ucfirst ( $email -> val )) . " </td></tr> \n " ;
echo " <tr><td> " . i18n ( " From " ) . " </td><td> " . htmlspecialchars ( $email -> from ) . " </td></tr> \n " ;
echo " <tr><td> " . i18n ( " Subject " ) . " </td><td> " . htmlspecialchars ( $email -> subject ) . " </td></tr> \n " ;
echo " <tr><td> " . i18n ( " Recipients " ) . " </td><td> " . $numrecipients . " </td></tr> \n " ;
?>
</ table >
< hr />
< div id = " comm_dialog_send_info " >
< ?
if ( $numrecipients > 0 ) {
echo i18n ( " Please confirm you wish to send this email to %1 recipients. Clicking the Send button below will begin sending the emails immediately. " , array ( $numrecipients ));
echo " <br /> \n " ;
echo " <br /> \n " ;
echo " <input class= \" comm_dialog_send_send_button \" type= \" submit \" value= \" " . i18n ( 'Send' ) . " \" /> \n " ;
}
else {
echo i18n ( " You have not selected any recipients on the Prospects tab. Press Cancel and click on Prospects to add recipients " );
echo " <br /> \n " ;
echo " <br /> \n " ;
}
?>
< input class = " comm_dialog_send_cancel_button " type = " submit " value = " <?=i18n('Cancel')?> " >
</ div >
< div id = " comm_dialog_send_processing " style = " display: none; " >
< ? = i18n ( " Please wait while the email queue is initialized... " ) ?>
< br />
< img src = " ../images/ajax-loader.gif " >
</ div >
< div id = " comm_dialog_send_status " style = " display: none; " >
< ? = i18n ( " The email has been queued to send " ); ?>
< br />< br />< input class = " comm_dialog_send_status_button " type = " submit " value = " <?=i18n('Close and view sending status')?> " >
< input class = " comm_dialog_send_close_button " type = " submit " value = " <?=i18n('Close and continue')?> " >
</ div >
</ form >
</ div >
< script type = " text/javascript " >
var comm_dialog_choose_selected = - 1 ;
$ ( " .comm_dialog_send_send_button " ) . click ( function () {
$ ( " #comm_dialog_send_info " ) . hide ();
$ ( " #comm_dialog_send_processing " ) . show ();
$ . post ( " communication.php?action=sendqueue " ,{ fundraising_campaigns_id : < ? = $fcid ?> , emails_id: <?=$emailid?>}, function() {
$ ( " #comm_dialog_send_processing " ) . hide ();
$ ( " #comm_dialog_send_status " ) . show ();
});
// $('#comm_dialog_send').dialog("close");
return false ;
});
$ ( " .comm_dialog_send_cancel_button " ) . click ( function () {
$ ( '#comm_dialog_send' ) . dialog ( " close " );
return false ;
});
$ ( " .comm_dialog_send_close_button " ) . click ( function () {
$ ( '#comm_dialog_send' ) . dialog ( " close " );
return false ;
});
$ ( " .comm_dialog_send_status_button " ) . click ( function () {
$ ( '#comm_dialog_send' ) . dialog ( " close " );
window . location . href = " communication_send_status.php " ;
return false ;
});
$ ( " #comm_dialog_send " ) . dialog ({
bgiframe : true , autoOpen : true ,
modal : true , resizable : false ,
draggable : false ,
width : 600 , //(document.documentElement.clientWidth * 0.8);
close : function () {
$ ( this ) . dialog ( 'destroy' );
$ ( '#comm_dialog_send' ) . remove ();
/* Run callbacks */
if ( typeof ( update_tab_communications ) == 'function' ) {
update_tab_communications ();
}
}
});
</ script >
< ?
exit ;
2009-12-02 22:17:20 +00:00
//dialog_sender is used to send a one-off communication based on a given template to a given user
//receives 'uid' and an optional 'template'
case 'dialog_sender' :
$u = user_load_by_uid ( intval ( $_GET [ 'uid' ]));
if ( $_GET [ 'template' ]) {
$emailq = mysql_query ( " SELECT * FROM emails WHERE `val`=' " . mysql_real_escape_string ( $_GET [ 'template' ]) . " ' " );
$e = mysql_fetch_assoc ( $emailq );
}
else
$e = null ;
$from = htmlspecialchars ( $_SESSION [ 'name' ] . " < " . $_SESSION [ 'email' ] . " > " );
$to = htmlspecialchars ( $u [ 'emailrecipient' ]);
$subject = htmlspecialchars ( $e [ 'subject' ]);
//useless but we might as well have it
$name = htmlspecialchars ( $e [ 'name' ]);
$key = htmlspecialchars ( $e [ 'val' ]);
$description = htmlspecialchars ( $e [ 'description' ]);
//do the replacements from the template now, so what the person see's is what gets sent.
$body = communication_replace_vars ( $e [ 'body' ], $u );
$bodyhtml = communication_replace_vars ( $e [ 'bodyhtml' ], $u );
//if there's no html,. grab the html from the non-html version
if ( $bodyhtml == '' ) $bodyhtml = nl2br ( $body );
?>
< div id = " comm_dialog_sender " title = " Send an Email " style = " display: none " >
< br />
< form id = " comm_dialog_sender_form " >
< ? /* ="fcid=$fcid, key=$key, type=$type"*/ ?>
< table class = " editor " style = " width:95% " >
< ?
if ( $e ) {
echo " <tr><td class= \" label \" > " . i18n ( " Using Template " ) . " :</td><td class= \" input \" ><a href= \" communication.php?action=edit&val= $key\ " > $name ( " .i18n( " click to edit template " ). " ) </ a ></ td ></ tr > \n " ;
echo " <tr><td colspan= \" 2 \" ><hr /></td></tr> \n " ;
}
?>
< tr >
< td class = " label " >< ? = i18n ( " From " ) ?> :</td>
< td class = " input " >< input type = " text " name = " from " size = " 60 " value = " <?= $from ?> " /></ td >
</ tr >< tr >
< td class = " label " >< ? = i18n ( " To " ) ?> :</td>
< td class = " input " >< input type = " text " name = " to " size = " 60 " value = " <?= $to ?> " /></ td >
</ tr >< tr >
< td class = " label " >< ? = i18n ( " Subject " ) ?> :</td>
< td class = " input " >< input type = " text " name = " subject " size = " 60 " value = " <?= $subject ?> " /></ td >
</ tr >< tr >
< td colspan = " 2 " class = " input " >
< div id = " fck " >
< textarea id = " bodyhtml " name = " bodyhtml " rows = 6 cols = 80 >< ? = $bodyhtml ?> </textarea>
</ div >
</ td >
</ tr ></ table >
< hr />
< div align = " right " >
< input type = " submit " id = " comm_dialog_sender_send_button " value = " <?=i18n('Send')?> " />
< input type = " submit " id = " comm_dialog_sender_cancel_button " value = " <?=i18n('Cancel')?> " />
</ div >
</ form >
</ div >
< script type = " text/javascript " src = " <?= $config['SFIABDIRECTORY'] ?>/fckeditor/fckeditor.js " ></ script >
< script type = " text/javascript " >
$ ( " #comm_dialog_sender_send_button " ) . click ( function () {
var oFCKeditor = FCKeditorAPI . GetInstance ( 'bodyhtml' ) ;
var value = oFCKeditor . GetHTML ();
$ ( '#bodyhtml' ) . val ( value );
$ ( " #debug " ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/admin/communication.php?action=email_send " , $ ( " #comm_dialog_sender_form " ) . serializeArray (),
function () {
$ ( '#comm_dialog_sender' ) . dialog ( " close " );
});
return false ;
}
);
$ ( " #comm_dialog_sender_cancel_button " ) . click ( function () {
$ ( '#comm_dialog_sender' ) . dialog ( " close " );
return false ;
}
);
$ ( " #comm_dialog_sender " ) . dialog ({
bgiframe : true , autoOpen : true ,
modal : true , resizable : false ,
draggable : false ,
width : 800 , //(document.documentElement.clientWidth * 0.8);
close : function () {
$ ( this ) . dialog ( 'destroy' );
$ ( '#comm_dialog_sender' ) . remove ();
/* Run callbacks */
}
});
var oFCKeditor = new FCKeditor ( 'bodyhtml' ) ;
oFCKeditor . BasePath = " ../fckeditor/ " ;
oFCKeditor . ToolbarSet = 'sfiab' ;
oFCKeditor . Width = " 100% " ;
oFCKeditor . Height = 300 ;
// $('#fck').html(oFCKeditor.CreateHtml());
oFCKeditor . ReplaceTextarea () ;
</ script >
< ?
exit ;
case " email_send " :
2009-12-02 23:11:25 +00:00
$body = getTextFromHtml ( $_POST [ 'bodyhtml' ]);
2009-12-03 21:12:13 +00:00
email_send_new ( stripslashes ( $_POST [ 'to' ]), stripslashes ( $_POST [ 'from' ]), stripslashes ( $_POST [ 'subject' ]), stripslashes ( $body ), stripslashes ( $_POST [ 'bodyhtml' ]));
2009-12-02 22:17:20 +00:00
happy_ ( " Email Successfully Sent " );
exit ;
case " email_get_list " :
$q = mysql_query ( " SELECT * FROM emails ORDER BY type,name " );
echo " <table class= \" tableview \" > " ;
echo " <tr> " ;
echo " <th> " . i18n ( " Name " ) . " </th> " ;
echo " <th> " . i18n ( " Type " ) . " </th> " ;
echo " <th> " . i18n ( " Actions " ) . " </th> " ;
echo " </tr> " ;
while ( $r = mysql_fetch_object ( $q )) {
if ( $r -> fundraising_campaigns_id ) $fcid = $r -> fundraising_campaigns_id ;
else $fcid = 'null' ;
if ( $r -> name ) $name = $r -> name ;
else $name = i18n ( " no email name specified " );
2010-02-12 18:24:22 +00:00
echo " <tr><td><a href= \" # \" onclick= \" return opencommunicationeditor(' " . addslashes ( $r -> val ) . " ', $r->id , $fcid ) \" > " , htmlspecialchars ( $name ) . " </a></td> " ;
2009-12-02 22:17:20 +00:00
echo " <td> $r->type </td> " ;
echo " <td align= \" center \" > " ;
//only user emails can be deleted, system ones are required and cannot be removed
if ( $r -> type == " user " ) {
echo " " ;
echo " <a onclick= \" return confirmClick('Are you sure you want to remove email?') \" href= \" communication.php?action=delete&delete= $r->id\ " >< img border = 0 src = \ " " . $config [ 'SFIABDIRECTORY' ] . " /images/16/button_cancel. " . $config [ 'icon_extension' ] . " \" ></a> " ;
echo " " ;
echo " <a href= \" communication.php?action=send&send= $r->id\ " > " .i18n( " Send " ). " </ a > " ;
}
echo " </td> \n " ;
echo " </tr> " ;
}
echo " </table> " ;
exit ;
2010-02-11 15:58:26 +00:00
case 'cancel' :
if ( $_GET [ 'cancel' ]) {
mysql_query ( " UPDATE emailqueue SET finished=NOW() WHERE id=' " . intval ( $_GET [ 'cancel' ]) . " ' " );
mysql_query ( " UPDATE emailqueue_recipients SET result='cancelled' WHERE emailqueue_id=' " . intval ( $_GET [ 'cancel' ]) . " ' AND sent IS NULL AND result IS NULL " );
echo " ok " ;
}
exit ;
2009-12-01 22:02:03 +00:00
}
2009-10-14 03:25:47 +00:00
2006-03-01 15:59:51 +00:00
include " communication.inc.php " ;
2009-12-01 22:02:03 +00:00
if ( $_GET [ 'action' ] == " sendqueue " ) {
$fcid = intval ( $_POST [ 'fundraising_campaigns_id' ]);
$emailid = intval ( $_POST [ 'emails_id' ]);
$fcq = mysql_query ( " SELECT * FROM fundraising_campaigns WHERE id=' $fcid ' " );
$fc = mysql_fetch_object ( $fcq );
$emailq = mysql_query ( " SELECT * FROM emails WHERE id=' $emailid ' " );
$email = mysql_fetch_object ( $emailq );
$recipq = mysql_query ( " SELECT * FROM fundraising_campaigns_users_link
WHERE fundraising_campaigns_id = '$fcid' " );
echo mysql_error ();
$numtotal = mysql_num_rows ( $recipq );
mysql_query ( " INSERT INTO emailqueue (val,name,users_uid,`from`,subject,body,bodyhtml,`type`,fundraising_campaigns_id,started,finished,numtotal,numsent) VALUES (
'".mysql_real_escape_string($email->val)."' ,
'".mysql_real_escape_string($email->name)."' ,
'".$_SESSION[' users_uid ']."' ,
'".mysql_real_escape_string($email->from)."' ,
'".mysql_real_escape_string($email->subject)."' ,
'".mysql_real_escape_string($email->body)."' ,
'".mysql_real_escape_string($email->bodyhtml)."' ,
'".mysql_real_escape_string($email->type)."' ,
$fcid ,
NOW (),
NULL ,
$numtotal ,
0 ) " );
$emailqueueid = mysql_insert_id ();
echo mysql_error ();
2010-01-27 20:24:16 +00:00
$urlproto = $_SERVER [ 'SERVER_PORT' ] == 443 ? " https:// " : " http:// " ;
$urlmain = " $urlproto { $_SERVER [ 'HTTP_HOST' ] } { $config [ 'SFIABDIRECTORY' ] } " ;
$urllogin = " $urlmain /login.php " ;
2009-12-01 22:02:03 +00:00
while ( $r = mysql_fetch_object ( $recipq )) {
$u = user_load_by_uid ( $r -> users_uid );
$replacements = array (
" FAIRNAME " => $config [ 'fairname' ],
" SALUTATION " => $u [ 'salutation' ],
" FIRSTNAME " => $u [ 'firstname' ],
" LASTNAME " => $u [ 'lastname' ],
2010-01-27 20:24:14 +00:00
" NAME " => $u [ 'name' ],
2009-12-01 22:02:03 +00:00
" EMAIL " => $u [ 'email' ],
2010-01-27 20:24:16 +00:00
" ORGANIZATION " => $u [ 'sponsor' ][ 'organization' ],
" URLMAIN " => $urlmain ,
" URLLOGIN " => $urllogin ,
2009-12-01 22:02:03 +00:00
);
2010-01-27 20:24:14 +00:00
if ( $u [ 'email' ]) {
2009-12-01 22:02:03 +00:00
mysql_query ( " INSERT INTO emailqueue_recipients (emailqueue_id,toemail,toname,replacements,sent) VALUES (
'$emailqueueid' ,
2010-01-27 20:24:14 +00:00
'".mysql_real_escape_string($u[' email '])."' ,
'".mysql_real_escape_string($u[' name '])."' ,
2010-02-06 22:05:39 +00:00
'".mysql_real_escape_string(json_encode($replacements))."' ,
2009-12-01 22:02:03 +00:00
NULL ) " );
echo mysql_error ();
}
mysql_query ( " UPDATE emails SET lastsent=NOW() WHERE id=' $emailid ' " );
}
echo " ok " ;
launchQueue ();
exit ;
2009-12-02 22:17:20 +00:00
}
2007-11-18 23:50:23 +00:00
send_header ( " Communication " ,
array ( 'Committee Main' => 'committee_main.php' ,
2008-08-22 20:50:38 +00:00
'Administration' => 'admin/index.php' ),
" communication "
2007-11-18 23:50:23 +00:00
);
2005-03-02 18:47:19 +00:00
echo " <br /> " ;
2009-12-01 22:02:03 +00:00
if ( $_GET [ 'action' ] == " delete " && $_GET [ 'delete' ]) {
2009-12-02 22:17:20 +00:00
mysql_query ( " DELETE FROM emails WHERE id=' " . $_GET [ 'delete' ] . " ' AND `type`='user' " );
2005-03-02 18:47:19 +00:00
echo happy ( " Email successfully deleted " );
}
2009-10-22 17:12:23 +00:00
if ( $_GET [ 'action' ] == " send " && $_GET [ 'send' ]) {
2005-03-02 18:47:19 +00:00
$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 " <br> " ;
echo " <br> " ;
2009-12-02 22:17:20 +00:00
echo " <form method= \" post \" action= \" communication.php \" > " ;
2005-03-02 18:47:19 +00:00
echo " <table cellspacing=0 cellpadding=3 border=1> " ;
echo " <tr><td><b>From:</b></td><td> " . htmlspecialchars ( $r -> from ) . " </td></tr> " ;
echo " <tr><td><b>To:</b></td><td> " ;
echo " <select name= \" to \" > " ;
echo " <option value= \" \" >Choose Email Recipients</option> " ;
2009-09-18 15:57:35 +00:00
$str = " " ;
2009-10-22 17:12:23 +00:00
foreach ( $mailqueries AS $k => $mq ) {
2006-03-01 15:59:51 +00:00
$tq = mysql_query ( $mq [ 'query' ]);
2009-09-18 15:57:35 +00:00
if ( mysql_error ()) {
echo mysql_error ();
exit ;
}
2006-03-01 15:59:51 +00:00
$num = mysql_num_rows ( $tq );
2009-09-18 15:57:35 +00:00
$str .= " <h2> " . $mq [ 'name' ] . " $num </h2> " ;
while ( $tr = mysql_fetch_object ( $tq )) {
$str .= " [ " . $tr -> uid . " ][ " . $tr -> year . " ] " . $tr -> firstname . " " . $tr -> lastname . " < { $tr -> email } ><br /> " ;
}
2006-03-01 15:59:51 +00:00
echo " <option value= \" $k\ " > " .i18n( $mq['name'] ). " ( " .i18n( " % 1 recipients " ,array( $num ),array( " number " )). " ) </ option > " ;
}
2005-03-02 18:47:19 +00:00
echo " </select> " ;
echo " </td></tr> " ;
echo " <tr><td><b>Date:</b></td><td> " . date ( " r " ) . " </td></tr> " ;
2010-02-11 16:41:17 +00:00
echo " <tr><td><b>Subject:</b></td><td> " . htmlspecialchars ( $r -> subject ) . " </td></tr> " ;
2009-12-02 22:17:20 +00:00
if ( $r -> bodyhtml ) {
2010-02-11 16:41:17 +00:00
$body = $r -> bodyhtml ;
2009-12-03 20:55:16 +00:00
}
else {
2010-02-11 16:41:17 +00:00
$body = nl2br ( htmlspecialchars ( $r -> body ));
2009-12-02 22:17:20 +00:00
}
2005-03-02 18:47:19 +00:00
2009-12-02 22:17:20 +00:00
echo " <tr><td colspan=2> " . $body . " </td></tr> " ;
2005-03-02 18:47:19 +00:00
echo " </table> " ;
2008-07-17 18:33:11 +00:00
if ( ! function_exists ( " exec " )) {
echo " <div class= \" error \" >Sending requires php's exec() function to be available</div> \n " ;
2007-11-16 17:58:59 +00:00
}
2009-12-03 20:55:16 +00:00
else {
2005-03-02 18:47:19 +00:00
echo " <table border=0 cellspacing=0 cellpadding=30 width= \" 100% \" > " ;
echo " <tr><td align=center> " ;
echo " <input type=hidden name=action value= \" reallysend \" > " ;
echo " <input type=hidden name=reallysend value= \" " . $_GET [ 'send' ] . " \" > " ;
echo " <input type=submit value= \" Yes, Send Email \" > " ;
echo " </form> " ;
echo " </td><td> " ;
echo " <form method=get action= \" communication.php \" > " ;
echo " <input type=submit value= \" No, Do Not Send \" > " ;
echo " </form> " ;
echo " </td></tr> " ;
echo " </table> " ;
2007-11-16 17:58:59 +00:00
}
2009-10-22 17:12:23 +00:00
//echo $str;
2005-03-02 18:47:19 +00:00
}
2009-12-02 22:17:20 +00:00
else if ( $_POST [ 'action' ] == " reallysend " && $_POST [ 'reallysend' ] && $_POST [ 'to' ]) {
$emailid = intval ( $_POST [ 'reallysend' ]);
$emailq = mysql_query ( " SELECT * FROM emails WHERE id=' $emailid ' " );
$email = mysql_fetch_object ( $emailq );
$to = $_POST [ 'to' ];
if ( array_key_exists ( $to , $mailqueries )) {
$recipq = mysql_query ( $mailqueries [ $to ][ 'query' ]);
2005-03-02 18:47:19 +00:00
}
2006-03-01 15:59:51 +00:00
2009-12-02 22:17:20 +00:00
$numtotal = mysql_num_rows ( $recipq );
mysql_query ( " INSERT INTO emailqueue (val,name,users_uid,`from`,subject,body,bodyhtml,`type`,fundraising_campaigns_id,started,finished,numtotal,numsent) VALUES (
'".mysql_real_escape_string($email->val)."' ,
'".mysql_real_escape_string($email->name)."' ,
'".$_SESSION[' users_uid ']."' ,
'".mysql_real_escape_string($email->from)."' ,
'".mysql_real_escape_string($email->subject)."' ,
'".mysql_real_escape_string($email->body)."' ,
'".mysql_real_escape_string($email->bodyhtml)."' ,
'".mysql_real_escape_string($email->type)."' ,
NULL ,
NOW (),
NULL ,
$numtotal ,
0 ) " );
$emailqueueid = mysql_insert_id ();
echo mysql_error ();
2006-03-01 15:59:51 +00:00
2010-01-27 20:24:16 +00:00
$urlproto = $_SERVER [ 'SERVER_PORT' ] == 443 ? " https:// " : " http:// " ;
$urlmain = " $urlproto { $_SERVER [ 'HTTP_HOST' ] } { $config [ 'SFIABDIRECTORY' ] } " ;
$urllogin = " $urlmain /login.php " ;
2009-12-02 22:17:20 +00:00
while ( $r = mysql_fetch_object ( $recipq )) {
if ( $r -> uid )
$u = user_load_by_uid ( $r -> uid );
else if ( $r -> users_uid )
$u = user_load_by_uid ( $r -> users_uid );
else {
$toname = $r -> firstname . " " . $r -> lastname ;
$toemail = $r -> email ;
$replacements = array (
" FAIRNAME " => $config [ 'fairname' ],
" FIRSTNAME " => $r -> firstname ,
" LASTNAME " => $r -> lastname ,
" NAME " => $r -> firstname . " " . $r -> lastname ,
" EMAIL " => $r -> email ,
2010-01-27 20:24:16 +00:00
" ORGANIZATION " => $r -> organization ,
" URLMAIN " => $urlmain ,
" URLLOGIN " => $urllogin ,
2009-12-02 22:17:20 +00:00
);
}
if ( $u ) {
$replacements = array (
" FAIRNAME " => $config [ 'fairname' ],
" SALUTATION " => $u [ 'salutation' ],
" FIRSTNAME " => $u [ 'firstname' ],
" LASTNAME " => $u [ 'lastname' ],
2010-01-27 20:24:14 +00:00
" NAME " => $u [ 'name' ],
2009-12-02 22:17:20 +00:00
" EMAIL " => $u [ 'email' ],
2010-01-27 20:24:16 +00:00
" ORGANIZATION " => $u [ 'sponsor' ][ 'organization' ],
" URLMAIN " => $urlmain ,
" URLLOGIN " => $urllogin ,
2009-12-02 22:17:20 +00:00
);
2010-01-27 20:24:14 +00:00
$toname = $u [ 'name' ];
2009-12-02 22:17:20 +00:00
$toemail = $u [ 'email' ];
2005-03-02 18:47:19 +00:00
}
2006-03-01 15:59:51 +00:00
2009-12-02 22:17:20 +00:00
if ( $toemail ) {
mysql_query ( " INSERT INTO emailqueue_recipients (emailqueue_id,toemail,toname,replacements,sent) VALUES (
'$emailqueueid' ,
'".mysql_real_escape_string($toemail)."' ,
'".mysql_real_escape_string($toname)."' ,
2010-02-06 22:05:39 +00:00
'".mysql_real_escape_string(json_encode($replacements))."' ,
2009-12-02 22:17:20 +00:00
NULL ) " );
echo mysql_error ();
}
mysql_query ( " UPDATE emails SET lastsent=NOW() WHERE id=' $emailid ' " );
2005-03-02 18:47:19 +00:00
}
2009-12-02 22:17:20 +00:00
launchQueue ();
echo " <br /> " ;
echo happy ( " Email Communication sending has started! " );
echo " <br> " ;
echo " <a href= \" communication_send_status.php \" >Click here to see the sending progress</a> " ;
2005-03-02 18:47:19 +00:00
2009-12-02 22:17:20 +00:00
}
2010-02-10 17:05:49 +00:00
else if ( $_GET [ 'action' ] == " restartqueue " )
{
launchQueue ();
echo " <br /> " ;
echo happy ( " Email Communication sending has started! " );
echo " <br> " ;
echo " <a href= \" communication_send_status.php \" >Click here to see the sending progress</a> " ;
}
2009-12-02 22:17:20 +00:00
else {
if ( ! $config [ 'fairmanageremail' ])
echo notice ( i18n ( " Warning: The 'Fair Manager Email' has not been set in SFIAB Configuration / Configuration Variables / Global. Please set it. The 'Fair Manager Email' is the default 'From' address for all emails and without a 'From' address, no emails can be sent! " ));
echo " <a href= \" communication_send_status.php \" > " . i18n ( " Email Queue Status and History " ) . " </a><br /> " ;
echo " <a href= \" # \" onclick= \" return opencommunicationeditor(null,null,null) \" > " . i18n ( " Add New Email " ) . " </a> " ;
echo " <br /> \n " ;
echo " <br /> \n " ;
echo " <div id= \" emaillist \" ></div> " ;
?>
< script type = " text/javascript " >
function refreshEmailList () {
$ ( " #emaillist " ) . load ( " communication.php?action=email_get_list " , null , function () {
});
2005-03-02 18:47:19 +00:00
}
2009-12-02 22:17:20 +00:00
$ ( document ) . ready ( function () {
refreshEmailList ();
}
);
</ script >
< ?
2005-03-02 18:47:19 +00:00
}
2009-12-02 22:17:20 +00:00
send_footer ();
2005-03-02 18:47:19 +00:00
?>