Viewing file: libnewsletter.php (6.16 KB) -rw-rw-rw- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
//16/05/2002 <gregory.kokanosky@free.fr>
// phpMyNewsletter v0.8.x
// a class for managing Newsletter
if (!defined( "_NEWSLETTER_LIB" ))
{
define("_NEWSLETTER_LIB", 1);
function validEmailAddress($email){
// regx to test for valid e-mail adres
$regex = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$';
if (eregi($regex, $email)) return true;
else return false;
}
class Newsletter {
var $list_id;
var $name; //name of the newsletter
var $from;
var $from_name;
var $subscription_subject;
var $subscription_body;
var $welcome_subject;
var $welcome_body;
var $quit_subject;
var $quit_body;
var $subject;
var $header;
var $footer;
var $db_host;
var $db_login;
var $db_pass;
var $db_name;
function getConfig($host, $login, $pass, $database, $list_id , $list_table){
$this->list_id = $list_id;
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$db->DbQuery("SELECT * FROM $list_table WHERE list_id='$list_id'");
$conf = $db->DbNextRow();
$this->db_host =$host;
$this->db_login=$login;
$this->db_pass =$pass;
$this->db_name =$database;
$this->name= $conf[1];
$this->from= $conf[2];
$this->from_name = $conf[3];
$this->subject= $conf[4];
$this->header = $conf[5];
$this->footer = $conf[6];
$this->subscription_subject = $conf[7];
$this->subscription_body = $conf[8];
$this->welcome_subject = $conf[9];
$this->welcome_body = $conf[10];
$this->quit_subject = $conf[11];
$this->quit_body = $conf[12];
}
function getAddress($mail_table, $begin='', $limit='')
{
$Addr = array();
$db= new Db();
$db->DbConnect($this->db_host, $this->db_login, $this->db_pass, $this->db_name);
$sql = "SELECT email FROM $mail_table WHERE list_id='$this->list_id'";
$db->DbQuery($sql ,$begin, $limit, 1);
for($i=0; $i<$db->DbNumRows(); $i++){
$addr = $db->DbNextRow();
$Addr[$i]=$addr[0];
}
return $Addr;
}
function saveConfig($db_host, $db_login, $db_pass, $db_name, $list_id, $table_listsconfig, $newsletter_name, $from, $from_name, $subject, $header, $footer, $subscription_subject, $subscription_body, $welcome_subject, $welcome_body, $quit_subject, $quit_body){
$db= new Db();
$db->DbConnect($db_host, $db_login, $db_pass, $db_name);
if(!get_magic_quotes_gpc()){
$newsletter_name = escape_string($newsletter_name);
$from = escape_string($from);
$from_name = escape_string($from_name);
$subject = escape_string($subject);
$header = escape_string($header);
$footer = escape_string($footer);
$subscription_subject = escape_string($subscription_subject);
$subscription_body = escape_string($subscription_body);
$welcome_subject = escape_string($welcome_subject);
$welcome_body = escape_string($welcome_body);
$quit_subject = escape_string($quit_subject);
$quit_body =escape_string($quit_body);
}
$sql ="UPDATE $table_listsconfig SET newsletter_name=\"$newsletter_name\", from_addr=\"$from\", from_name=\"$from_name\", subject=\"$subject\", header=\"$header\" , footer=\"$footer\" , subscription_subject=\"$subscription_subject\", subscription_body=\"$subscription_body\", welcome_subject=\"$welcome_subject\", welcome_body=\"$welcome_body\", quit_subject=\"$quit_subject\", quit_body=\"$quit_body\" WHERE list_id='$list_id'";
$db->DbQuery($sql);
if($db->DbError()) return 0;
else return 1;
}
function getSubscribersNumbers($table_email){
$db= new Db();
$db->DbConnect($this->db_host, $this->db_login, $this->db_pass, $this->db_name);
$db->DbQuery("SELECT COUNT(*) FROM $table_email WHERE list_id='$this->list_id'");
$num = $db->DbNextRow();
return $num[0];
}
function deleteArchive($table_archives, $msg_id){
$db= new Db();
$db->DbConnect($this->db_host, $this->db_login, $this->db_pass, $this->db_name);
$db->DbQuery("DELETE FROM $table_archives WHERE id='$msg_id'");
if($db->DbError()) return 0;
else return 1;
}
function getArchivesSelectList($table_archives, $msg_id='', $form_name='archive_form2'){
$db= new Db();
$db->DbConnect($this->db_host, $this->db_login, $this->db_pass, $this->db_name);
$sql = "SELECT id, date, subject FROM $table_archives WHERE list_id='$this->list_id' ORDER BY date DESC";
$db->DbQuery($sql);
if($db->DbNumRows() == 0) return -1;
else {
echo "<select name=\"msg_id\" onchange=\"document.$form_name.submit()\">\n";
while($archives = $db->DBNextRow())
{
echo "<option value=\"$archives[0]\" ";
if ($msg_id==$archives[0]) echo "selected='selected'";
echo ">".stripslashes(htmlspecialchars($archives[2]))." </option>\n";
}
echo "</select>";
}
}
function getArchiveMsg($table_archives, $msg_id)
{
if( empty($offset)) $offset=0;
$db= new Db();
$db->DbConnect($this->db_host, $this->db_login, $this->db_pass, $this->db_name);
$sql = "SELECT date, type, subject, message FROM $table_archives WHERE id='$msg_id'";
$db->DbQuery($sql);
if($db->DbNumRows() == 0) return -1;
else{
$archive = $db->DbNextRow();
echo "<div class='subsection' >";
$subject = htmlspecialchars($archive[2]);
$subject = stripslashes($subject);
$date = $archive[0];
echo "<div class='archivetitle'>".$subject." - ".$date."</div>";
//echo translate("ARCHIVE_SUBJECT").": ".$subject."<br />\n";
//echo translate("ARCHIVE_DATE").": ".$archive[0]."<br />\n";
//echo translate("ARCHIVE_FORMAT").": ".$archive[1]."<br /><br />\n";
echo "<div class='subcontent'>";
if($archive[1] != "html"){
$body = str_replace("<","<", $archive[3]);
$body = str_replace(">",">", $body);
$body = nl2br(stripslashes($body));
} else {
$body = stripslashes( $archive[3] );
}
echo "\t".$body;
echo "</div></div>\n";
echo "<br />";
}
}
}
}
?>
|