<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com  2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

function add_slash($val){
	if (get_magic_quotes_gpc()) return stripslashes($val);
	else return $val;
}

if(isset($_GET["artistid"]) && $_GET["artistid"]!=""){
	$artistid = $_GET["artistid"];
}else if(isset($_POST["artistid"]) && $_POST["artistid"]!=""){
	$artistid = $_POST["artistid"];
}else{
	header("Location:viewcatalog.php");
	exit();
}
if(isset( $_GET["productid"]) && $_GET["productid"]!=""){
	$productid = $_GET["productid"];
}else if(isset( $_POST["productid"]) && $_POST["productid"]!=""){
	$productid = $_POST["productid"];
}

if(isset( $_SESSION["sess_userid"]) && $_SESSION["sess_userid"]!=""){
	$userid = $_SESSION["sess_userid"];
}else{
	//$userid = 0;
	//header("Location:login.php?action=sendmessagetoseller&artistid=$artistid&productid=$productid");
	//exit();
}

if (isset($_POST['btnSendMessage'])) {
	
	$txtMessage   	= add_slash($_POST["txtMessage"]);
	$subject      	= add_slash($_POST["subject"]);
	$artistid	  	= add_slash($_POST["artistid"]);
	$productid	  	= add_slash($_POST["productid"]);
	$contact_name	= add_slash($_POST["contact_name"]);
	$email_address	= add_slash($_POST["email_address"]);

	if (!isNotNull($contact_name)) {
        $message .= CONTACT_NAME_EMPTY_MSG." <br>";
    }
	/*
	$email_pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
	if (!isNotNull($email_address)) {
        $message .= "* Email address cannot be empty! <br>";
    }
	elseif (!eregi($email_pattern, $email_address)) {
       $message .= "* Email address cannot be invalid! <br>";
	}
	*/

        if (!isNotNull($email_address)) {
            $message .= EMAIL_ADDR_EMPTY__MSG." <br>";
        }
	elseif (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$email_address)) {
            $message .= INVALID_EMAIL_ADDR_MSG." <br>";
	}

        
	if (!isNotNull($subject)) {
        $message .= SUBJECT_EMPTY_MSG." <br>";
    }
	
	if (!isNotNull($txtMessage)) {
        $message .= MSG_EMPTY_MSG." <br>";
    }


    if ($message != "") { // error
        $message = "<br>".CORRECT_ERRORS_TEXT."<br>" . $message;
    } else { // no error so insert user details
	
			//echo "SELECT * FROM artists WHERE artist_id = '".$artistid."'"; 
	    ////// sent message to seller....
		  $sql         = "SELECT * FROM ".$tableprefix."artists WHERE artist_id = '".$artistid."'";
		  $rs		   = mysql_query($sql) or die(mysql_error());
		  if(mysql_num_rows($rs)>0)
		  {
			  $sell        = mysql_fetch_array($rs);
			  $sell_email  = $sell['email'];
                          
                        $insQ = "INSERT INTO ".$tableprefix."message_to_seller
                                        SET artist_id = '" . mysql_real_escape_string($artistid). "',
                                            name = '" . mysql_real_escape_string($contact_name). "',
                                            email = '" . mysql_real_escape_string($email_address). "',
                                            subject = '" . mysql_real_escape_string($subject). "',
                                            message 	= '" . mysql_real_escape_string($txtMessage). "'";
                        mysql_query($insQ) or die(mysql_error());
                          
                          
			  $headers     = "MIME-Version: 1.0" . "\r\n";
			  $headers  = "MIME-Version: 1.0" . "\r\n";
                            $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
                            $headers .= "From: ".$contact_name."<".$email_address.">" . "\r\n";
                            $headers .= "Reply-To: ".SITE_NAME."<".SITE_EMAIL.">" . "\r\n";
                            $headers .= "Return-Path: ".SITE_NAME."<".SITE_EMAIL.">"."\r\n"; 
                            $headers .= "Organization: ".SITE_NAME."\r\n";
			  
			  if(mail($sell_email,"Message from " . SITE_NAME . " - ".$subject,$txtMessage,$headers)){
				  $message      = MSG_SEND_TEXT;
				  $contact_name = "";
				  $email_address= "";
				  $txtMessage   = "";
				  $subject      = "";
			  }
			  
		  }
		////// message sending ends......
    }
}
else {
		$sql1        = mysql_query("SELECT * FROM ".$tableprefix."users WHERE user_id = '".$_SESSION["sess_userid"]."'");
		$buyr        = mysql_fetch_assoc($sql1);
		$email_address  = $buyr['email'];
		$contact_name   = $buyr['user_name'];
		if (strstr($contact_name,'Guest')!='') $contact_name   = '';
}

/*display the active template*/

$active_template = displayTemplate();


include "includes/htmltop.php";

/* Top File Name */

include_once ("includes/".$active_template[0]);

?>



			<div align="left" class="main_body">
			
			<!--mainbody area start -->
			
			<div align="left" id="body_left_area">
				<!--body left area start -->
		
				
				
			<!--categories area start -->
			
<?php

	include_once("includes/categorylist.php");

?>			
			
			<!--categories area end -->	
			
			<!--body left area end -->
				
				</div>


		<!--center content area start-->		

		<form name="frmPostFeedback" action="<?php echo $_SERVER["PHP_SELF"]?>?artistid=<?php echo $artistid;?>" method="POST">
			<input type="hidden" name="artistid" value="<?php echo $artistid;?>" >
			<input type="hidden" name="productid" value="<?php echo $productid;?>" >
			
		<div align="left" id="item_details">
	
                    <div align="left" id="items_top_area">
				
				<div align="left" id="items_top_area_ttl"><?php echo SEND_SELLER_MSG;?></div>
		</div>
		
		<div class="text_information" align="center"><?php echo $message?></div>
		
		<div class="sellerfeedbk">	
                    
		<!--items display area start -->
			
		<table cellpadding="2" cellspacing="2" width="100%" border=0 class="heading">
			<tr>
				<td colspan="3" align="right"><span class="required">*</span><?php echo MANDATORY_FIELDS_TEXT;?></td>
			</tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			<tr><td align="left" valign="top" width="32%"><?php echo CONTACT_NAME_TEXT;?>&nbsp;<span class="required">*</span></td><td >&nbsp;</td><td align="left"><input type="text" name="contact_name" id="contact_name" value="<?php echo ($contact_name);?>" size="40"></td></tr>
			<tr><td align="left" valign="top" width="32%"><?php echo EMAIL_MSG_TEXT;?>&nbsp;<span class="required">*</span></td><td >&nbsp;</td><td align="left"><input type="text" name="email_address" id="email_address" value="<?php echo ($email_address);?>" size="40"></td></tr>
			<tr><td align="left" valign="top" width="32%"><?php echo SUBJECT_TEXT;?>&nbsp;<span class="required">*</span></td><td >&nbsp;</td><td align="left"><input type="text" name="subject" id="subject" value="<?php echo ($subject);?>" size="40"></td></tr>
			<tr><td align="left" valign="top" width="32%"><?php echo MSG_TEXT;?>&nbsp;<span class="required">*</span></td><td >&nbsp;</td><td align="left"><textarea class="textbox" name="txtMessage" rows="8" cols="40"><?php echo ($txtMessage);?></textarea></td></tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			<tr><td colspan="3" align="center">
				<input type="submit" class="button" value="<?php echo SEND_MSG_BUTTON;?>" name="btnSendMessage">&nbsp;&nbsp;
				<?php if ($productid!='') { ?>
					<input class="button" type="button" value="<?php echo BACK_TEXT;?>" onClick="window.location.href='productdetails.php?productid=<?php echo $productid;?>';" >
				<?php } else { ?>
					<input class="button" type="button" value="<?php echo BACK_TEXT;?>" onClick="window.location.href='showportfolio.php?artistid=<?php echo $artistid; ?>';" >
				<?php } ?>
			</td></tr>
		</table>
		
		</div>	
	
	
		<div align="left" class="float_clear1"></div>
					
					
		 <!--items display area end -->
		  </div>
		
		</form>
		<!--center content area end-->	


		<div align="left" class="float_clear"><img src="images/clear.gif" alt="" width="1" height="1" /></div>		
		<!--mainbody area end -->
        </div>
		<div align="left" class="float_clear"><img src="images/clear.gif" alt="" width="1" height="1" /></div>


<?php
include "includes/".$active_template[2];	/* Bottom File Name */
?>