<?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.                                                       |
// +----------------------------------------------------------------------+
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";


if (isset($_SESSION["sess_artistid"]) and $_SESSION["sess_artistid"] != "") {
    $artistid = $_SESSION["sess_artistid"];
} else {
    header("Location:login.php");
    exit;
}

if(checkArtistExpired($artistid)){
    header("Location:seller_plan_upgrade.php?sellerid=".$artistid);
    exit;
}

if (isset($_POST['gotoPage'])) {

    header("Location:" . $_SERVER['PHP_SELF'] . "?page=" . $_POST['gotoPage']);
}

//approve review
if (isset($_GET['mode']) && $_GET['mode'] == 'a') {
    mysql_query("UPDATE " . $tableprefix . "Review SET vActive='1' WHERE nRId='" . $_GET['rid'] . "'") or die(mysql_error());
    $message = MSG_REVIEW_APPR;
    $status = "approved";
}//end if
//disapprove review
if (isset($_GET['mode']) && $_GET['mode'] == 'da') {
    mysql_query("UPDATE " . $tableprefix . "Review SET vActive='0' WHERE nRId='" . $_GET['rid'] . "'") or die(mysql_error());
    $message = MSG_REVIEW_DISAPPR;
    $status = "not approved";
}//end if


if ($_GET['mode']) {
    // Send Mails to Seller 
    $subject = MAIL_SELLER_PRODUCT_REVIEW_SUBJECT_1." " . SITE_NAME . " ".MAIL_SELLER_PRODUCT_REVIEW_SUBJECT_2." $status";
    $link = "<a href='" . SITE_URL . "/productdetails.php?productid=" . $_GET["pid"] . "' target='_blank'>".MAIL_SELLER_PRODUCT_REVIEW_TEXT_CLICK_HERE."</a>";
    $user_sql = "select first_name,last_name,email from " . $tableprefix . "users where user_id=(select nUserId from " . $tableprefix . "Review where nRId = " . $_GET['rid'] . ")";
    $user_rs = mysql_query($user_sql);
    $user_rw = mysql_fetch_array($user_rs);
    $to = $user_rw["email"];

    /* -------Email Template Reading Fuction Call-------- */
    $mailcontent = readEmailTemplate('product_review_approved');
    $mailcontent = htmlentities(stripslashes($mailcontent));

    $mailcontent = str_replace('[user_name]', $user_rw["first_name"] . " " . $user_rw["last_name"], $mailcontent);
    $mailcontent = str_replace('[approved_by]', "Seller", $mailcontent);
    $mailcontent = str_replace('[status]', $status, $mailcontent);
    $mailcontent = str_replace('[product_name]', urldecode($_GET["name"]), $mailcontent);
    $mailcontent = str_replace('[link]', $link, $mailcontent);

    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
    $headers .= "From: " . SITE_EMAIL . "<" . SITE_EMAIL . ">" . "\r\n";
    $mailcontent = nl2br($mailcontent);
    $mail_send_details = '<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title >'.SITE_NAME.'</title>
  <link href="./themes/' . $active_template[4] . ' rel="stylesheet" type="text/css">
</head>
<body>

<table width="103%" cellspacing="10" cellpadding="0" bgcolor="#EAEAEA">
   <tr>
     <td align="center" valign="top">
         
         <table width="600" border="0" cellpadding="0" cellspacing="0" bordercolor="#EAEAEA" bgcolor="#FFFFFF" class="manage_table">
            <tr>
               <td align="right" >
              </td>
            </tr>
            <tr>
               <td valign="middle" align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                 <tr>
                   <td  bgcolor="#EAEAEA" > <img src=' . SITE_URL . '/banners/' . getSettingsValue('site_logo') . ' width="125" height="60"/></td>
                 </tr>
               </table></td>
            </tr>
            <tr>
              <td align="center" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="10">
                <tr>
                  <td align="left"><p>' . $mailcontent . '</p>
                  </td>
                </tr>
              </table></td>
            </tr>
            <tr>
               <td align="center" bgcolor="#EAEAEA" class="footer">
                  <p>&nbsp;</p>
              </td>
            </tr>
       </table>

     </td>
   </tr>
</table>


</body>
</html>';

    $mailsent = mail($to, $subject, $mail_send_details, $headers);
}


$qryopt = "";

$sql = "SELECT r.*,u.user_name,p.product_name FROM " . $tableprefix . "Review r LEFT JOIN " . $tableprefix . "users u ON r.nUserId=u.user_id 
					LEFT JOIN " . $tableprefix . "products p ON r.nProdId=p.product_id WHERE p.product_artist_id=" . $_SESSION['sess_artistid'] . $qryopt;


if (!(isset($pagenum))) {
    $pagenum = 1;
}

$limit = getSettingsValue('npagination_limit');

$page = isset($_GET['page']) ? trim($_GET['page']) : 1;


if (empty($page)) {
    $page = 1;
}

$result = mysql_query($sql) or die(mysql_error());

$totalrows = mysql_num_rows($result);

$limitvalue = ($page - 1) * $limit;

$query_string = " LIMIT $limitvalue, $limit";

$sql = $sql . $query_string;

$rs = mysql_query($sql) or die(mysql_error());

$numofpages = ceil($totalrows / $limit);

include "../includes/htmltop.php";

switch ($_GET['msg']) {
    case "e":
        $message = MSG_CHNG_SAVE_SUC;
        break;
}//end switch
?>
<body>

<center>

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




        <!--header area start -->
        <?php
        include_once("../includes/topheader_seller.php")
        ?>

        <!--header area end -->




        <div align="left" class="main_body">
            <!--main body start -->



            <?php
            include_once("../includes/artisttopmenu.php")
            ?>		


            <div align="left" class="content_area">

                <!--content area start -->
                <div align="left" class="page_title"><?php echo TEXT_PRODUCT_REVIEWS?></div>
                <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                <br>
                <div align="left">					


                    <table border="0" width="100%" cellpadding="0" cellspacing="0" class="manage_table">
                        <form action="" method="post" name="frmReview">
                            <tr class="form_header">
                                <th width="5%">#</th>
                                <th width="18%"><?php echo TEXT_REVIEW;?></th>
                                <th width="13%"><?php echo TEXT_POSTED_BY?></th>
                                <th width="13%"><?php echo TEXT_PRODUCT;?><?php echo TEXT_NAME;?> </th>							
                                <th width="16%"><?php echo TEXT_ACTIVE;?></th>
                                <?php if (getSettingsValue('vReview') == 'vendors') { ?><th width="33%"><?php echo TEXT_ACTION;?></th><?php }//end if ?>
                            </tr>


                            <?php
                            if (mysql_num_rows($result) > 0) {
                                $i = 1;
                                while ($row = mysql_fetch_array($rs)) {
                                //--- Update seller view status ---//
                                $sql = "UPDATE ".$tableprefix."Review SET seller_viewed_status = 1 WHERE nRId = '".addslashes($row['nRId'])."'";			
                                mysql_query($sql) or die (mysql_error());   
                                
                                    switch ($row['vActive']) {
                                        case "0":
                                            $act = TEXT_NO;
                                            $act2 = '<a href="product_reviews.php?rid=' . $row['nRId'] . '&pid=' . $row['nProdId'] . '&name=' . urlencode($row["product_name"]) . '&mode=a">'.TEXT_APPR.'</a>';
                                            break;

                                        case "1":
                                            $act = TEXT_YES;
                                            $act2 = '<a href="product_reviews.php?rid=' . $row['nRId'] . '&pid=' . $row['nProdId'] . '&name=' . urlencode($row["product_name"]) . '&user=' . urlencode($row["user_name"]) . '&mode=da">'.TEXT_DIS_APPR.'</a>';
                                            break;
                                    }//end switch				
                                    ?>
                                    <tr> 
                                        <td align="left" valign="top"><?php echo $i ?></td>
                                        <td align="left" valign="top"><?php echo nl2br(stripslashes($row["vDes"])); ?></td>
                                        <td align="left" valign="top"><?php echo $row["user_name"]; ?></td>
                                        <td align="left" valign="top"><?php echo stripslashes($row["product_name"]); ?></td>
                                        <td align="left" valign="top"><?php echo $act; ?></td>
                                        <?php if (getSettingsValue('vReview') == 'vendors') { ?><td align="left" valign="top"><?php echo $act2; ?></td>
                                        <?php }//end if?>
                                    </tr>
                                    <?php
                                    $i++;
                                }
                                ?>	

                                <input type="hidden" name="checkCount" value="<?php echo $i - 1 ?>">
                                <?php
                            } else {
                                ?>					
                                <tr>
                                    <td align="center" valign="middle" colspan="6"  class="text_information"><?php echo TEXT_NO_REVIEW;?></td>
                                </tr>					
                                <?php
                            }

                            if ($page > 1) {
                                $pageprev = $page - 1;

                                $previous_page = "<a href=" . $_SERVER['PHP_SELF'] . "?page=$pageprev alt='Previous' border='0' class='small_gray_button'>".TEXT_PAGES_PREV."</a>";
                            }


                            if ($page < $numofpages) {
                                $pagenext = ($page + 1);

                                $next = "<a href=" . $_SERVER['PHP_SELF'] . "?page=$pagenext alt='Next' border='0' class='small_gray_button'>".TEXT_PAGES_NEXT."</a>";
                            }
                            ?>


                            <tr>
                                <td class="page_nos"  align="center" colspan="2">&nbsp;</td>
                                <td align="right" valign="middle" class="page_nos btn_gotbl" colspan="4">&nbsp;</td>
                            </tr>
                            <?php
                            if ($page < $numofpages || $page > 1) {
                                ?>
                                <tr>
                                    <td align="center" colspan="6">
										<table width="100%" border="0" cellspacing="10" cellpadding="0">
											<tr align="left" valign="middle">
												<td width="21%" align="right"><?php echo $previous_page ?></td>
												<td width="23%" align="right">
													<?php echo TEXT_PAGES; ?> <?php echo $page ?>/<?php echo $numofpages ?>&nbsp;&nbsp;<?php echo TEXT_GOTO; ?>&nbsp;&nbsp; 
												</td>
												<td width="8%" align="right">
													<select class="textarea2" name="gotoPage" style="padding:4px 5px; margin-bottom:1px; ">
                                            <?php
                                            for ($i = 1; $i <= $numofpages; $i++) {


                                                if ($i == $_GET['page']) {
                                                    $page_selected = "selected";
                                                } else {
                                                    $page_selected = "";
                                                }
                                                ?>									
                                                <option value="<?php echo $i ?>" <?php echo $page_selected ?>><?php echo $i ?></option>

                                                <?php
                                            }
                                            ?>									
                                        </select>
												</td>
												<td width="7%">
													<a onClick="Javascript:document.frmReview.submit();" class="go_button_2"><?php echo BTN_GO; ?></a>
												</td>
												<td width="41%" align="center"><?php echo $next ?></td>
											</tr>
										</table>
									</td>
                                </tr>
                                <?php
                            }
                            ?>
                        </form>
                        <tr>
                            <td colspan="6">
                                <form name="frmMyReviews" method="post" action="#">
                                    <input type="hidden" name="txtRId">
                                </form>										</td>
                        </tr>
                    </table>

                </div>


                <!--content area end-->

            </div>


            <div align="left" class="clear_float"><img src="<?php echo $imagefolder; ?>/clear.gif" alt="" width="1" height="1" /></div>
            <!--main body end -->
        </div>


        <?php
        include "../includes/footer.php";
        ?>