<?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_adminname"]) and $_SESSION["sess_adminname"] != "") {
	$adminname = $_SESSION["sess_adminname"];
} else {
	header("Location:login.php");
	exit;
}

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

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


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

	$ids = $_POST['txtRId'];
	if (empty($ids)) {
		$message .= PLS_SEL_REWS_TO_DELETE.".<br>";
	}

	if ($message == '') {
		$id_format = substr($_POST['txtRId'], 0, strlen($_POST['txtRId']) - 1);

		$delete_reviews = "DELETE FROM " . $tableprefix . "Review WHERE nRId IN(" . $id_format . ")";

		mysql_query($delete_reviews) or die(mysql_error());

		$message = REWS_DELETED." !!";

		//header("Location:product_reviews.php?page=1&msg".);
	} // end message empty check
}//end first if

$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" . $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 = '<b>'.CHANGES_SAVED_SUCCESSFULLY.'!</b>';
		break;

	case "d":
		$message = '<b>'.REWS_DEL_SUCC.'!</b>';
		break;
}//end switch
?>

<script>
    function addValues(order_value)
    {
		
        var checkbox_values = "";	
	
        for(i=1;i<=document.frmReview.checkCount.value;i++)
        {
	
            var checkbox_name = "RI"+i;
			
            if(document.getElementById(checkbox_name).checked)
            {
                checkbox_values += document.getElementById(checkbox_name).value + ',';
            }
				
            document.frmMyReviews.txtRId.value = checkbox_values;
		
			
        }		
    }

    function checkAllOrders()
    {

        var checkbox_values = "";	
	
        if(document.frmReview.checkAllBox.checked)
        {
				
            for(i=1;i<=document.frmReview.checkCount.value;i++)
            {
		
                var checkbox_name = "RI"+i;
                document.getElementById(checkbox_name).checked = true;	
                checkbox_values += document.getElementById(checkbox_name).value + ',';
						
            }
		
            document.frmMyReviews.txtRId.value = checkbox_values;

        }
        else
        {
            for(i=1;i<=document.frmReview.checkCount.value;i++)
            {
		
                var checkbox_name = "RI"+i;
                document.getElementById(checkbox_name).checked = false;	
			
            }
		
            document.frmMyReviews.txtRId.value = "";
        }


    }

    function deleteReviews()
    {
        if(document.frmMyReviews.txtRId.value == "")
        {
        	return confirm("<?php echo PLS_SEL_REWS_TO_DELETE;?>");
        }
        else
        {
		
            var status =  confirm('<?php echo ARE_YOU_SURE_DEL_REWS;?>!!');
		
            if(status == true)
            {
                document.frmMyReviews.submit();
            }	
        }
	
    }


</script>

<body>

	<center>

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




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

			<!--header area end -->




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



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


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

					<!--content area start -->

					<div align="left" class="page_title">
						<?php echo PRO_REVIEW;?>
					</div>
					<div align="center" class="text_information grey_tr">
						<?php echo $message ?>
					</div>
					<br>
					<div align="right">


						<table border="0" width="100%" cellpadding="0" cellspacing="0"
							class="manage_table">
							<form action="" method="post" name="frmReview">
								<tr class="form_header">
									<th width="6%" align="right">#</th>
									<th width="18%" align="right"><?php echo REVIEW;?></th>
									<th width="14%" align="right"><?php echo POSTED_BY;?>
									</th>
									<th width="14%" align="right"><?php echo PRODUCT_NAME?>
									</th>
									<th width="17%" align="right"><?php echo ACTIVE;?></th>
									<th width="20%" align="right"><input type="checkbox"
										name="checkAllBox" value="1" onClick="checkAllOrders();"> <?php echo SEL_OR_DESELECT;?>
									</th>
									<th width="11%" align="right"><a onClick="deleteReviews();"
										style="cursor: pointer" title="<?php echo TITLE_DELETE_SELECTED; ?>"><img
											border="0" src="../images/btn_del.gif"> </a></th>






								</tr>


								<?php
								if (mysql_num_rows($result) > 0) {
                                $i = 1;
                                while ($row = mysql_fetch_array($rs)) {
                                    $link = "<a class=links href='edit_review.php?rid=" . $row["nRId"] . "&page=" . $_GET['page'] . "'>";

                                    switch ($row['vActive']) {
                                    	case "0":
                                    		$act = NO1;
                                    		break;

                                    	case "1":
                                    		$act = YES;
                                    		break;
                                    }//end switch
                                    ?>
								<tr>
								<td align="right"><?php echo (($page * $limit) + $i - $limit) ?>
									</td>
								<td align="right"><?php echo $link . stripslashes(substr($row["vDes"], 0, 40)) . " ...</a>"; ?>
									</td>
									
									<td align="right"><?php echo $link . ($row["user_name"]) . "</a>"; ?>
									</td>
									<td align="right"><?php echo $link . ($row["product_name"]) . "</a>"; ?>
									</td>
									<td align="right"><?php echo $link . $act . "</a>"; ?></td>
									<td align="right"><?php
									$product_checkbox = "RI" . $i;
									?> <input type="checkbox"
										name="<?php echo $product_checkbox ?>"
										id="<?php echo $product_checkbox ?>"
										value="<?php echo $row['nRId'] ?>"
										onClick="addValues('<?php echo $row['nRId'] ?>');">
									</td>
								</tr>
								<?php
								$i++;
                                }
                                ?>

								<input type="hidden" name="checkCount"
									value="<?php echo $i - 1 ?>">
								<?php
                            } else {
                                ?>
								<tr>
									<td align="center" valign="middle" colspan="7"
										class="text_information"><?php echo NO_REVIEWS_FOUND;?></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'>prev</a>";
                            }


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

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

                            if ($page < $numofpages || $page > 1) {
                                ?>


								<tr>
									<td colspan="7" align="right" valign="middle">
									
									<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 PAGE."(".S.")";?>
												<?php echo $page ?>/<?php echo $numofpages ?>&nbsp;&nbsp;<?php echo GO_TO;?>	
											</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">Go</a>
											</td>
											<td width="41%" align="center"><?php echo $next ?></td>
										</tr>
									</table>      
									</td>
								</tr>
							</form>
							<tr>
								<td colspan="7">
									<form name="frmMyReviews" method="post" action="#">
										<input type="hidden" name="txtRId">
									</form>
								</td>
							</tr>
							<?php
                                    }
                                    ?>
						</table>

					</div>


					<!--content area end-->

				</div>


				<div align="right" 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";
			?>