<?php
/*************************************************************
* The MyDB librairy and applications are product of SQLFusion
* It may be used and/or distributed under the terms of the Q Public
* License (QPL) version 1.0, enclosed in the file licence.txt.
****************************************************************/
/** General classes un functions **/
/** Author Philippe Lewicki **/
class mydatafusion {
var $sql_query ;
var $sql_order ;
var $cfgEmailField;
var $mBody;
var $mBodyHtml ;
var $mSubject ;
var $mSenderEmail ;
var $mSenderName ;
function fusion($dbc, $result) {
$iddbc = $dbc->start();
$numsent = 0;
while ($row = mysql_fetch_array($result)) {
set_time_limit(3600);
$numsent++;
$table_def = mysql_db_query($dbc->db, "SHOW FIELDS FROM $dbc->table", $iddbc);
$SendBody = $this->mBody;
$SendBodyHtml = $this->mBodyHtml ;
$SendSubject = $this->mSubject;
for ($i=0;$i<mysql_num_rows($table_def);$i++)
{
$row_table_def = mysql_fetch_array($table_def);
$field = $row_table_def["Field"];
$SendBody = eregi_replace("\[$field\]", $row[$field], $SendBody) ;
$SendBodyHtml = eregi_replace("\[$field\]", $row[$field], $SendBodyHtml) ;
$SendSubject = eregi_replace("\[$field\]", $row[$field], $SendSubject) ;
}
mysql_free_result($table_def);
$SendBody = ereg_replace("\r","", $SendBody);
$header = "X-Mailer: SQLFusion ".$dbc->table." hide@address.com\nReturn-Path: ".$this->mSenderEmail." \nFrom: $this->mSenderName <".$this->mSenderEmail.">" ;
mail_html($row[$this->cfgEmailField], $SendSubject, $SendBody, $SendBodyHtml, $header) ;
if (is_integer($numsent/10)) { echo ".";}
if (is_integer($numsent/100)) {echo $numsent." <br>\n"; }
}
return $numsent;
}
function stringfusion($dbc, $thestring, $row) {
$iddbc= $dbc->start();
$table_def = mysql_db_query($dbc->db, "SHOW FIELDS FROM $dbc->table", $iddbc);
for ($i=0;$i<mysql_num_rows($table_def);$i++)
{
$row_table_def = mysql_fetch_array($table_def);
$field = $row_table_def["Field"];
$thestring = eregi_replace("\[$field\]", $row[$field], $thestring) ;
}
return $thestring;
}
function query($dbc) {
$this->sql_query = stripslashes($this->sql_query);
if ($this->sql_query == "") {
$this->sql_query= "select * from $dbc->table group by $this->cfgEmailField" ;
}
/* Take select disctinct emails */
list($oldsel, $from) = explode("from", $this->sql_query) ;
$this->sql_query = "select * from $from group by $this->cfgEmailField ";
// $iddbc = $dbc->start();
$rquery = mysql_db_query($dbc->db,$this->sql_query);
return $rquery ;
}
}
function validateEmail ( $email )
{
// used for SMTP HELO argument
global $SERVER_NAME;
// initialize our return array, populating with default values
$return = array ( false, "", "", "" );
// assign our user part and domain parts respectively to seperate
// variables
list ( $user, $domain ) = split ( "@", $email, 2 );
// split up the domain name into sub-parts
$arr = explode ( ".", $domain );
// figure out how many parts to the host/domain name portion there are
$count = count ( $arr );
// get our Top-Level Domain portion (i.e. foobar.org)
$tld = $arr[$count - 2] . "." . $arr[$count - 1];
// check that an MX record exists for Top-Level Domain, and if so
// start our email address checking
if ( checkdnsrr ( $tld, "ANY" ) )
{
$return[0] = true ;
} else {
// No MX record appears for the specified Top-Level Domain; possibly
// an invalid host/domain name was specified.
$return[0] = false;
$return[1] = "Invalid email address (bad domain name)";
$return[2] = false;
} // end if checkdnsrr()
if (($return[0]==false) && ($count > 2))
{
$tld = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1] ;
if ( checkdnsrr ( $tld, "MX" ) )
{
$return[0] = true ;
} else {
// No MX record appears for the specified Top-Level Domain; possibly
// an invalid host/domain name was specified.
$return[0] = false;
$return[1] = "Invalid email address (bad domain name)";
$return[2] = false;
} // end if checkdnsrr()
}
if (!eregi("@", $email)) {
$return[0] = false ;
}
// return the array for the user to test against
return $return;
}
// $val_results =validateEmail ( $email ) ;
// $val_results[0] = true;
/*
send_join_mail
Its a function that send email with attachement in base64 encoding
send_join_mail(email adress, subject, body, attachement, Mimefiletype)
it returns nothing.
*/
function send_join_mail ($email, $subject, $body, $file, $filename, $headini)
{
// $filename = "Document.pdf" ;
$header = $headini ;
$header .="\nMIME-Version: 1.0" ;
$header .= "\nContent-Type: multipart/mixed;" ;
$header .=" boundary=\"---------_nWlrBbmQBhCDarzOwKkYHIDdqSCD\"" ;
$filestring = "";
$fp = fopen ($file, "r") ;
$filestring = fread($fp, filesize( $file) ) ;
fclose ($fp) ;
$filebase64 = chunk_split(base64_encode($filestring)) ;
// $filebase64 = base64_encode($filestring) ;
// $filebase64 = ereg_replace("(.{72})","\\1\n",$filebase64) ;
$startbody = "\nThis is a multi-part message in MIME format." ;
$startbody .= "\n-----------_nWlrBbmQBhCDarzOwKkYHIDdqSCD" ;
$startbody .= "\nContent-Type: text/plain;";
$startbody .= "\nContent-Transfer-Encoding: 8bit\n\n" ;
$body = $startbody.$body ;
$body .= "\n-----------_nWlrBbmQBhCDarzOwKkYHIDdqSCD" ;
$body .= "\nContent-Type: application/unknown; name=\"".$filename."\"" ;
// $body .= "\nContent-Type: image/jpeg; name=\"".$filename."\"" ;
$body .= "\nContent-Transfer-Encoding: base64" ;
// $body .="\nContent-Disposition: inline; filename=\"".$filename."\"\n" ;
$body .="\nContent-Disposition: attachment; filename=\"".$filename."\"\n" ;
$body .="\n".$filebase64 ;
$body .="\n-----------_nWlrBbmQBhCDarzOwKkYHIDdqSCD--" ;
mail ($email, $subject, $body, $header) ;
return "vide" ;
};
function mail_html($email, $subject, $body, $bodyhtml, $headini)
{
$header = $headini ;
$header .="\nMIME-Version: 1.0" ;
$header .= "\nContent-Type: multipart/alternative;" ;
$header .=" boundary=\"---------_nWlrBbmQBhCDarzOwKkYHIDdqSCD\"" ;
// $startbody = "\nThis is a multi-part message in MIME format." ;
$startbody = "\n\n\n-----------_nWlrBbmQBhCDarzOwKkYHIDdqSCD" ;
$startbody .= "\nContent-Type: text/plain;";
$startbody .= "\nContent-Transfer-Encoding: 7bit\n\n" ;
$body = $startbody.$body ;
$body .= "\n\n\n-----------_nWlrBbmQBhCDarzOwKkYHIDdqSCD" ;
$body .= "\nContent-Type: text/html; charset=us-ascii " ;
$body .= "\nContent-Transfer-Encoding: 7bit" ;
$body .="\n";
$body .="\n".$bodyhtml ;
$body .="\n\n-----------_nWlrBbmQBhCDarzOwKkYHIDdqSCD--" ;
mail ($email, $subject, $body, $header) ;
return "vide" ;
};
?>