Viewing file: function.php (14.34 KB) -rw-rw-rw- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
$PMNL_VERSION = "0.8beta5";
function escape_string($string,$dbcon=false) {
if(version_compare(phpversion(),"4.3.0")== -1) {
return(mysql_escape_string($string));
} else {
return(mysql_real_escape_string($string));
}
}
function flushTempTable($host,$login, $pass, $database, $temp_table, $limit)
{
$date = date("Y/m/d");
$elts = explode("/", $date);
$y = $elts[0];
$m = $elts[1];
$d = $elts[2];
$before = mktime(0, 0, 0, $m, $d - $limit, $y);
$before = date("Ymd", $before);
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql= "DELETE FROM $temp_table where date < '$before'";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError() .">".$sql;
return 0;
}
return 1;
}
/** Check if admin password is correct **/
function checkAdminAccess($conf_pass, $admin_pass)
{
if(!empty($_COOKIE['PMNLNG_admin_password']) && ($_COOKIE['PMNLNG_admin_password'] == $conf_pass)){
return 1;
}else {
if($conf_pass == md5($admin_pass)){
setcookie("PMNLNG_admin_password",md5($admin_pass));
return 1;
} else {
return 0;
}
}
}
function leaveAdmin()
{
if(setcookie("PMNLNG_admin_password"))
return 1;
return 0;
}
function saveConfigFile($db_host, $db_login, $db_pass, $db_name, $db_config_table, $db_type='mysql')
{
$configfile ="<?\nif (!defined( \"_CONFIG\" ) || \$forceUpdate == 1 )\n\t{\n\n\t\tif (!defined( \"_CONFIG\" )) define(\"_CONFIG\", 1);";
$configfile.="\n\n\n\t\t$"."db_type = \"$db_type\";";
$configfile.="\n\t\t$"."hostname = \"$db_host\";";
$configfile.="\n\t\t$"."login = \"$db_login\";";
$configfile.="\n\t\t$"."pass = \"$db_pass\";";
$configfile.="\n\t\t$"."database = \"$db_name\";";
$configfile.="\n\t\t$"."table_global_config=\"$db_config_table\";";
$configfile.="\n\t\t$"."pmnl_version =\"0.8beta3\";\n\n\t}\n\n?>";
if(is_writable("../include/config.php")){
$fc = fopen("../include/config.php", "w");
$w = fwrite ($fc, $configfile );
return 1;
} else {
return -1;
}
}
function sendEmail($send_method,$to, $from, $from_name, $subject, $body, $auth=0, $smtp_host='', $smtp_login='',$smtp_pass='' , $charset='UTF-8')
{
$mail = new phpmailer();
$mail->CharSet= $charset;;
$mail->PluginDir= "include/lib/";
switch($send_method){
case "smtp":
$mail->IsSMTP();
$mail->Host = $smtp_host;
if($auth){
$mail->SMTPAuth = true;
$mail->Username = $smtp_login;
$mail->Password = $smtp_pass;
}
break;
case "php_mail":
$mail->IsMail();
break;
case "online_mail":
$mail->IsOnlineEMail();
break;
default:
break;
}
$mail->From = $from;
$mail->FromName = $from_name;
//get address
$mail->AddAddress($to);
// $mail->WordWrap = 50;
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send())
{
echo $mail->ErrorInfo;
return -2;
}
return 1;
}
function isValidSubscriber($host,$login ,$pass,$database,$table_email, $list_id, $email_addr)
{
$email_addr=strtolower($email_addr);
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql = "SELECT hash FROM $table_email WHERE list_id='$list_id' AND email='$email_addr'";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -1;
}
$sub = $db->DbNumRows();
if($sub==0) return 0;
$h = $db->DBNextRow();
return $h[0];
}
function isValidNewsletter($host,$login ,$pass,$database,$table_list, $list_id)
{
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql = "SELECT list_id FROM $table_list WHERE list_id='$list_id'";
$db->DbQuery($sql);
if($db->DbError())
{
echo $db->DbError();
return 0;
}
return $db->DbNumRows();
}
function addSubscriberTemp($host,$login ,$pass,$database,$table_email,$table_temp, $list_id, $addr)
{
$addr=strtolower($addr);
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql = "SELECT email FROM $table_email WHERE list_id='$list_id' AND email='$addr'";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -1;
}
$mail = $db->DbNumRows();
$sql = "SELECT email FROM $table_temp WHERE list_id='$list_id' AND email='$addr'";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -1;
}
$mail+= $db->DbNumRows();
if($mail) return 0;
$hash = unique_id();
$date=date("Ymd");
$sql = "INSERT INTO $table_temp (`email`, `list_id` , `hash` , `date`) VALUES ('$addr', '$list_id','$hash' , '$date')";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -1;
}
return $hash;
}
function addSubscriber($host,$login ,$pass,$database,$table_email,$table_temp, $list_id, $addr, $hash)
{
$addr=strtolower($addr);
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql = "SELECT email FROM $table_temp WHERE list_id='$list_id' AND email='$addr' AND hash='$hash'";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -1;
}
$add = $db->DbNumRows();
if($add==0) return -1;
$sql = "INSERT INTO $table_email (`email`, `list_id` , `hash`) VALUES ('$addr', '$list_id','$hash')";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -2;
}
$sql = "DELETE FROM $table_temp WHERE email='$addr' AND list_id='$list_id' AND hash='$hash'";
// echo $sql;
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -3;
}
return 1;
}
function addSubscriberDirect($host,$login ,$pass,$database,$table_email,$list_id, $addr)
{
$addr=strtolower($addr);
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql = "SELECT email FROM $table_email WHERE list_id='$list_id' AND email='$addr'";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -1;
}
$add = $db->DbNumRows();
if($add) return -1;
$hash = unique_id();
$sql = "INSERT INTO $table_email (`email`, `list_id` , `hash`) VALUES ('$addr', '$list_id','$hash')";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -2;
}
return $hash;
}
function removeSubscriber($host,$login ,$pass,$database,$table_email, $list_id, $addr, $hash)
{
$addr=strtolower($addr);
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql = "SELECT email FROM $table_email WHERE list_id='$list_id' AND email='$addr' AND hash='$hash'";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -1;
}
$rm= $db->DbNumRows();
if($rm==0) return -1;
$sql = "DELETE FROM $table_email WHERE email='$addr' AND list_id='$list_id' AND hash='$hash'";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -2;
}
return 1;
}
function removeSubscriberDirect($host,$login ,$pass,$database,$table_email, $list_id, $addr)
{
$addr=strtolower($addr);
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql = "SELECT email FROM $table_email WHERE list_id='$list_id' AND email='$addr'";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -1;
}
$rm= $db->DbNumRows();
if($rm==0) return -1;
$sql = "DELETE FROM $table_email WHERE email='$addr' AND list_id='$list_id'";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -2;
}
return 1;
}
function deleteNewsletter($host,$login ,$pass,$database,$table_list,$table_archives, $table_email,$table_temp, $list_id)
{
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql = "DELETE FROM $table_list WHERE list_id='$list_id'";
$db->DbQuery($sql);
if($db->DbError())
{
echo $db->DbError();
return 0;
}
$sql = "DELETE FROM $table_email WHERE list_id='$list_id'";
$db->DbQuery($sql);
if($db->DbError())
{
echo $db->DbError();
return 0;
}
$sql = "DELETE FROM $table_temp WHERE list_id='$list_id'";
$db->DbQuery($sql);
if($db->DbError())
{
echo $db->DbError();
return 0;
}
$sql = "DELETE FROM $table_archives WHERE list_id='$list_id'";
$db->DbQuery($sql);
if($db->DbError())
{
echo $db->DbError();
return 0;
}
return 1;
}
function createNewsletter($db_host, $db_login, $db_pass, $db_name, $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);
$sql="SELECT list_id FROM $table_listsconfig ORDER BY list_id DESC";
$db->DbQuery($sql);
$id = $db->DbNextRow();
$newid = $id[0]+1;
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 ="INSERT INTO $table_listsconfig ";
$sql.="(`list_id` , `newsletter_name` , `from_addr` , `from_name` , `subject` , `header` , `footer` , `subscription_subject` , `subscription_body`, `welcome_subject` , `welcome_body` , `quit_subject` ,`quit_body`) VALUES ";
$sql.="('$newid','$newsletter_name', '$from', '$from_name', '$subject', '$header', '$footer', '$subscription_subject', '$subscription_body', '$welcome_subject','$welcome_body', '$quit_subject', '$quit_body')";
$db->DbQuery($sql);
if($db->DbError()) {
echo $db->DbError();
return 0;
}
else return $newid;
}
function save_message($host,$login ,$pass,$database, $table_archive,$subject,$format, $body, $date,$list_id)
{
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql="SELECT id FROM $table_archive ORDER BY id DESC";
$db->DbQuery($sql);
$id = $db->DbNextRow();
$newid = $id[0]+1;
$sql="INSERT into $table_archive (`id`, `date`,`type`, `subject` , `message`, `list_id`) VALUES ('$newid', '$date','$format','$subject','$body', '$list_id')";
$db->DbQuery($sql);
if($db->DbError())
{
echo $db->DbError();
return -1;
}
return $newid;
}
function get_message($host,$login ,$pass,$database, $table_archive,$msg_id)
{
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql="SELECT type, subject, message FROM $table_archive WHERE id='$msg_id'";
$db->DbQuery($sql);
$message = $db->DbNextRow();
return $message;
}
function unique_id()
{
mt_srand((double)microtime()*1000000);
return md5( mt_rand(0,9999999) );
}
function get_subscribers($host,$login ,$pass,$database, $table_email, $list_id)
{
$i=0;
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$db->DbQuery("SELECT email from $table_email WHERE list_id = '$list_id' ORDER BY email");
$subscribers = array();
$toAdd = $db->DbNextRow();
while( $toAdd['email'] ){
$subscribers[$i] = $toAdd['email'];
$toAdd = $db->DbNextRow();
$i++;
}
asort($subscribers);
return $subscribers;
}
function delete_subscriber($host,$login ,$pass,$database, $table_email, $list_id, $del_addr)
{
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql = "DELETE from $table_email WHERE list_id = '$list_id' AND email='$del_addr'";
$db->DbQuery($sql);
if($db->DbError())
{
echo $db->DbError();
echo $sql;
return 0;
}
else return 1;
}
function add_subscriber($host,$login ,$pass,$database, $table_email, $list_id, $add_addr)
{
$add_addr=strtolower($add_addr);
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql = "SELECT hash FROM $table_email WHERE list_id='$list_id' AND email='$add_addr'";
$db->DbQuery($sql);
if($db->DbError()){
echo $db->DbError();
return -2;
}
$add = $db->DbNumRows();
if($add!=0) return -1;
$hash = unique_id();
$db->DbQuery("INSERT INTO $table_email (`email`, `list_id`, `hash`) VALUES ('$add_addr', '$list_id', '$hash')");
if($db->DbError()) return 0;
else return 1;
}
function moderate_subscriber($host,$login ,$pass,$database, $table_email, $table_sub, $list_id, $mod_addr)
{
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$db->DbQuery("DELETE from $table_moderation WHERE list_id = '$list_id' AND email='$mod_addr'");
if($db->DbError())
{
echo $db->DbError();
return 0;
}
$hash = unique_id();
$sql = "INSERT INTO $table_email (`email`, `list_id`, `hash`) VALUES ('$mod_addr', '$list_id','$hash')";
$db->DbQuery($sql);
if($db->DbError())
{
echo $db->DbError();
return 0;
}
else return $hash;
}
function upgrade($host,$login ,$pass,$database, $table_global_config){
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$db->DbQuery("SHOW COLUMNS FROM $table_global_config");
$found = 0;
while($i = $db->DbNextRow()){
if ($i['Field'] == "charset"){
$found = 1;
break;
}
}
//let's go for upgrade
if($found != 1){
$sql = "ALTER TABLE $table_global_config ADD charset varchar(255) NOT NULL default 'utf-8'";
$db->DbQuery($sql);
}
}
/* As of 0.8beta5 admin password is stored hashed in the DB, so we
need to update it ! */
function upgrade_password($host,$login ,$pass,$database, $table_global_config, $admin_pass){
$db= new Db();
$db->DbConnect($host, $login, $pass, $database);
$sql = "UPDATE $table_global_config SET admin_pass='".md5($admin_pass)."' WHERE admin_pass = '".$admin_pass."'";
$db->DbQuery($sql);
return $db->DbAffectedRows();
}
?>
|