<?php
// send a notification email, if something is queued.

if(!function_exists('__autoload')){
	/**
		* tries include the class defintion automatically, if the class is used
		*/
	function __autoload($className) {
			require_once $className . '.php';
	}
}

# if any queued manufacturer are present, display the link
$reciever = "meganizer@engsas.de";
$from = "From: ManuServer <meganizer@engsas.de>\n";
$from .= "Reply-To: meganizer@engsas.de\n";
$from .= "Content-Type: text/html\n";

$countManus = 0;
$countMintypes = 0;
$countPrefixes = 0;
$connId = @ mysql_connect("localhost", Settings::value("SUBMITUSER"), Settings::value("SUBMITPASSWORD"));
if(!$connId){
	$subject = "ManuServer - Could not connect to the database";
	$body = "Could not connect to the database";
	mail($reciever, $subject, $body, $from);
}
else{
	if(!mysql_select_db(Settings::value("DBNAME"))){
		$subject = "ManuServer - Could not select the database";
		$body = "Could not select the wanted database";
		mail($reciever, $subject, $body, $from);
		mysql_close($connId);
	}
	else{
		$res = mysql_query("SELECT id FROM manufacturerhasmins_queue");
		$countPrefixes = mysql_num_rows($res);
		$res = mysql_query("SELECT id FROM mintypes_queue");
		$countMintypes = mysql_num_rows($res);
		$res = mysql_query("SELECT id FROM manufacturers_queue");
		$countManus = mysql_num_rows($res);
		mysql_close($connId);
	}
}
if(($countManus > 0) || ($countMintypes > 0) || ($countPrefixes > 0)){
	$subject = "ManuServer - Pending items: ". $countManus ." Manufacturers, ". $countMintypes ." MIN-Types, ". $countPrefixes ." Prefixes";
	$body = "Their are queued items for the ManuServer.<br>";
	$body .= "<ul>\n";
	if($countManus > 0)
		$body .= "	<li>". $countManus ." Manufacturers</li>\n";
	if($countMintypes > 0)
		$body .= "	<li>". $countMintypes ." MIN-Types</li>\n";
	if($countPrefixes > 0)
		$body .= "	<li>". $countPrefixes ." Prefixes</li>\n";
	$body .= "</ul>\n";
	$body .= "<br>";
	$body .= "To process those items, visit <a href=\"https://mins.engsas.de/admin.php\" title=\"Process manufacturers\">https://mins.engsas.de/admin.php</a>.\n";

	mail($reciever, $subject, $body, $from);
}

?>