<?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);
}
if(isset( $_SESSION["sess_userid"]) and $_SESSION["sess_userid"]!= "") {
    $userid = $_SESSION["sess_userid"];
}
if (isset($_POST["btnPostFeedback"])) {
    $txtFirstName = $_POST["txtFirstName"];
    $txtLastName = $_POST["txtLastName"];
    $txtEmail = $_POST["txtEmail"];
    $txtFeedback = $_POST["txtFeedback"];
    if (!isNotNull($txtFirstName)) {
        $message .= FIRST_NAME_EMPTY_MSG." <br>";
    }
    if (!isNotNull($txtEmail)) {
        $message .= EMAIL_EMPTY_MSG." <br>";
    } else {
        if (!isValidEmail($txtEmail)) {
            $message .= INVALID_EMAIL_MSG." <br>";
        }
    }
    if (!isNotNull($txtFeedback)) {
        $message .= FEEDBACK_EMPTY_MSG." <br>";
    }
    /*
    $qry2 = "select email from  " . $tableprefix . "users where email='" . $txtEmail . "'";
    if (mysql_num_rows(mysql_query($qry2)) > 0) {
        $message .= "* The email address '$txtEmail' is already in use!. <br>";
    } */

    if ($message != "") { // error
        $message = "<br>".CORRECT_ERRORS_TEXT."<br>" . $message;
    } else { // no error so insert user details
        $sql = "INSERT INTO ".$tableprefix."feedbacks (
			first_name,
			last_name,
			email,
			feedback_content,
			";
        if(isset( $userid) and $userid!= "") {
            $sql .= "user_id,";
        }
        $sql .=	"
			date_added
			) VALUES (
			'".addslashes($txtFirstName)."',
			'".addslashes($txtLastName)."',
			'".addslashes($txtEmail)."',
			'".addslashes($txtFeedback)."',
			";
        if(isset( $userid) and $userid!= "") {
            $sql .= "'".addslashes($userid)."',";
        }
        $sql .=	"
			now()
			)";
        //echo $sql;
        $message = THANK_YOU_MSG;
        //$message = "Thank you $txtFirstName, for posting your valuable feedback about ". stripslashes(htmlentities(SITE_NAME));
        $message .= "<br>".ADMIN_APPROVAL_MSG;
        $txtFirstName = "";
        $txtLastName = "";
        $txtEmail  = "";
        $txtFeedback  = "";
        mysql_query($sql);
    }
} else {//if first time accessing the page and if the user is logged in, populate user's details
    if(isset( $userid) and $userid!= "") {
        $sql = "SELECT * FROM ".$tableprefix."users WHERE user_id = '".addslashes($userid)."' ";
        $result = mysql_query($sql);
        if(mysql_num_rows($result) != 0) {
            $row = mysql_fetch_array($result);
            $txtFirstName = $row["first_name"];
            $txtLastName = $row["last_name"];
            $txtEmail = $row["email"];
        }
    }
}

/*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"]?>" method="POST">

        <div align="left" id="item_details">


            <!--items display area start -->

            <div align="left" id="items_top_area">

                <div align="left" id="items_top_area_ttl"><?php echo POST_FEEDBACK_TEXT;?></div>
            </div>

            <div class="text_information" align="center"><?php echo $message?></div>

            <div class="sellerfeedbk">

                <table cellpadding="2" cellspacing="2" width="100%">
                    <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" width="25%"><?php echo FIRST_NAME_TEXT;?>&nbsp;<span class="required">*</span></td>
                        <td >&nbsp;</td>
                        <td align="left"><input class="textbox" type="text" value="<?php echo $txtFirstName;?>" name="txtFirstName" size="30" maxlength="100"></td>


                    </tr>
                    <tr>
                        <td align="left" ><?php echo LAST_NAME_TEXT;?> &nbsp;</td>
                        <td >&nbsp;</td>
                        <td align="left"><input class="textbox" type="text" value="<?php echo $txtLastName;?>" name="txtLastName" size="30" maxlength="100"></td>

                    </tr>
                    <tr>
                        <td align="left" ><?php echo EMAIL_TEXT;?>&nbsp;<span class="required">*</span></td>
                        <td >&nbsp;</td>
                        <td align="left"><input class="textbox" type="text" value="<?php echo $txtEmail;?>" name="txtEmail" size="30" maxlength="100"></td>                                                
                    </tr>
                    <tr>
                        <td align="left" valign="top"><?php echo YOUR_FEEDBACK_TEXT;?>&nbsp;<span class="required">*</span></td>
                        <td >&nbsp;</td>
                        <td align="left"><TEXTAREA class="textbox" name="txtFeedback" rows="8" cols="35"><?php echo $txtFeedback;?></TEXTAREA></td>                                               
                    </tr>
                    <tr><td colspan="3">&nbsp;</td></tr>
                    <tr>
                        <td colspan="3" align="center">
                            
                            <input type="button" name="back" value="&nbsp;&nbsp;<?php echo BACK_TEXT;?>&nbsp;&nbsp;" class="button" onClick="Javascript:history.go(-1)">
                            <input type="submit" value="<?php echo POST_FEEDBACK_TEXT;?>" name="btnPostFeedback" class="button">
                        </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="clear"></div>
    <!--mainbody area end -->
</div>
<div align="left" class="clear"></div>






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