include("include/functions.php");
$link = ConnectDB();
// get project info
$keyword = $_REQUEST['key'];
$query = sprintf("SELECT * FROM project WHERE keyword='%s'", $keyword);
//printf("query is: %s
", $query);
$result = mysql_query($query)
or die("Invalid query: " . mysql_error());
// display project short description
if ($row = mysql_fetch_object($result)) {
$client_id = $row->client_id;
$partner_id = $row->partner_id;
$coll_email = $row->coll_email;
$coll_disable = $row->coll_disable;
$coll_nuke = $row->coll_nuke;
$email_me = $row->email_me;
$email_client = $row->email_client;
$email_partner = $row->email_partner;
$email_subject = $row->email_subject;
$email_message = $row->email_message;
$emails_day = $row->emails_day;
$emails_sent = $row->emails_sent;
$email_date = $row->email_date;
$disable_url = $row->disable_url;
$nuke_url = $row->nuke_url;
}
// check if we need to send out an email message
if (!$coll_email)
$send_email = false;
else if ($emails_day == 0) // unlimited messages
$send_email = true;
else {
$send_email = true;
$today = getdate();
$email_date = getdate(strtotime($email_date));
if (($today['year'] != $email_date['year']) || ($today['yday'] != $email_date['yday'])) // not same day, reset counter & send
$emails_sent = 1;
else if ($emails_sent >= $emails_day) // exceeded limit, don't sent
$send_email = false;
else // update counter & send
$emails_sent++;
}
if ($send_email) {
$comma = "";
$my_email = "lew@abbaroo.com";
if ($email_me) { // send it to me
$email_to = $my_email;
$comma = ",";
}
if ($email_client) { // send to client
$query = "SELECT email FROM client WHERE client_id=" . $client_id;
$result = mysql_query($query)
or die("Invalid query: " . mysql_error());
if ($row = mysql_fetch_object($result)) {
$email_to = sprintf("%s%s", $comma, $row->email);
$comma = ",";
}
}
if ($email_partner) { // send to partner
$query = "SELECT email FROM partner WHERE partner_id=" . $partner_id;
$result = mysql_query($query)
or die("Invalid query: " . mysql_error());
if ($row = mysql_fetch_object($result)) {
$email_to = sprintf("%s%s", $comma, $row->email);
$comma = ",";
}
}
// set up the message
$headers = sprintf("From: abbaroo.com <%s>\n", $my_email);
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n"; // sets the mime type and character set
if (strlen($email_subject) > 0)
$subject = $email_subject;
else
$subject = "website visited";
$email_message = wordwrap( $email_message, 1024 );
$mailOK = mail($email_to, $subject, stripslashes($email_message), $headers);
$query = "UPDATE project SET ";
$query .= sprintf("emails_sent=\"%s\", email_date=\"%s\" WHERE keyword=\"%s\"", $emails_sent, date("Y-m-d H:i:s"), $keyword);
//printf("query is: %s
", $query);
$result = mysql_query($query)
or die("Invalid query: " . mysql_error());
}
// check if we are to disable the site
if ($coll_disable) {
printf("", $disable_url);
header("Location: $disable_url");
}
// check if we are going nuclear
if ($coll_nuke) {
printf("", $nuke_url);
header("Location: $nuke_url");
}
mysql_close($link);
?>