<?
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
* Class		:	feedback
* Version :	1.0
* Date    :	20 October 2009
* Author  :	Darwish Khalil
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/

// Class Definition
class feedback
{
	var $ID;
	var $FirstName;
	var $To;
	var $Subject;
	var $Description;
	var $CustomerID;

	/*
	 * Class constructor
	 */
  function feedback($ID = -1)
  {
  	if ((!empty($ID)) && ($ID != -1))
  	{
  		$this->ID = $ID;
			$this->getInfo();
		}
	}

	/*
	 * Retrieves feedback information
	 */
	function getInfo()
	{
		$query = "
							Select * From feedback
					 	  Where ID = $this->ID
					 	 ";

		$result = mysql_query($query);
		$row = mysql_fetch_object($result);

    // Set class data members
    $this->FirstName 		= stripslashes($row->FirstName);
    $this->To 			    = $row->To;
    $this->Subject 			= stripslashes($row->Subject);
    $this->Description 	= stripslashes($row->Description);
    $this->CustomerID 	= $row->CustomerID;
  }

	// Add new feedback request
	function add($obj)
	{
		global $language;

		// Add slashes to object variables
	 	addslashes_object_vars(&$obj);

		$query =
						"
							Insert Into feedback(`FirstName`, `To`, `Subject`, `Description`, `CustomerID`, `Language`)
							Values('$obj->FirstName','$obj->To','$obj->Subject','$obj->Description',$obj->CustomerID,'$language')
						";

		// exit($query);
		mysql_query($query) or die(mysql_error());
	}

	/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
	*                         Send Email Functions
	*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
	/*
	 * Sends feedback to the relevant department
	 */
	function sendEmail()
	{
		global $config;
		global $customer;

		// Prepare headers for sending an html mail
		$headers  = "MIME-Version: 1.0\r\n";
		$headers .= "Content-type: text/html; charset=windows-1256\r\n";

		if ($config['USE_CUSTOMER_EMAIL'])
		{
			$headers .= "From: " . $customer->Email . "\r\n";
		}
		else
		{
			$headers .= "From: " . $config['FEEDBACK_EMAIL'] . "\r\n";
		}

		$to = $this->To;
		$subject = "FinFisher Feedback - " . $this->Subject;

		$message = $this->generateFeedbackMessage();

		// Send Message
		if(eregi("win",strtolower(PHP_OS)))
		{
			include_once "mail.class.php";
			$msg = new email();
	 		$msg->send_mail(0, $to, $subject, $message, $headers);
			// exit($message);
		}
	  elseif(eregi("linux",strtolower(PHP_OS)))
	  {
			mail($to, $subject, $message, $headers);
		}
	}

	/*
	 * Generates the contents of the email to be sent to the relevant department
	 */
	function generateFeedbackMessage()
	{
		global $config;
		global $customer;

		$msg =
					'
						<html>
							<head>
								<link href="'.$config['ROOT_URL'].'/Styles/style.css.php?Lang=en" rel="stylesheet" type="text/css">
							</head>
							<body class="en">
								<table border="0" cellpadding="0" cellspacing="0" width="100%">
									<tr>
										<td class="Success">
											You have received an email from <b>'.$this->FirstName.'</b> (CustomerID = '.$customer->Username.'),<br><br>

											<b>Description:</b><pre>'.$this->Description.'</pre>
										</td>
									</tr>
								</table>
							</body>
						</html>
					';
		return stripslashes(trim($msg));
	}

}
?>