<?php
if( $a == 'list' ){
	if( isset( $iProduct ) && is_numeric( $iProduct ) ){
		$sTable = DB_PRODUCTS_COMMENTS;
		$iLink = $iProduct;
		$sLink = 'iProduct';
	}
	if( isset( $iPage ) && is_numeric( $iPage ) ){
		$sTable = null;
		$iLink = $iPage;
		$sLink = 'iPage';
	}
	if( !isset( $iLink ) ) $iLink = null;
	if( !isset( $sTable ) ) $sTable = null;
	$aComments = throwComments( $iLink, $sTable, $rating, false, false );
	if( isset( $sOption ) ){
		$content.= $oTpl->parse( 'message_done.tpl' );
	}
	$oTpl->assign( 'sLink', $sLink );
	$oTpl->assign( 'aComments', $aComments );
	$content.= $oTpl->parse( 'comments_list.tpl' );
} elseif( $a == 'delete' && isset( $iComment ) && is_numeric( $iComment ) ){
	$sLink = 'iPage';
	$sTable = null;
	if( isset( $iProduct ) ){
		$sTable = DB_PRODUCTS_COMMENTS;
		$sLink = 'iProduct';
	} else $iProduct = null;
	if( !isset( $iPage ) ) $iPage = null;
	deleteComment( $iComment, $sTable );
	header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $aActions['f'] . '-list&sOption=del&' . $sLink . '=' . $iPage . $iProduct );
	exit;
} elseif( $a == 'accept' && isset( $iComment ) && is_numeric( $iComment ) ){
	$sTable = null;
	$sLink = 'iPage';
	if( !isset( $iProduct ) ){
		$iProduct = null;
	} else{
		$sLink = 'iProduct';
		$sTable = DB_PRODUCTS_COMMENTS;
	}
	if( !isset( $iPage ) ) $iPage = null;
	acceptComment( $iComment, $sTable );
	header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $aActions['f'] . '-list&sOption=accept&' . $sLink . '=' . $iPage . $iProduct );
	exit;
} elseif( $a == 'edit' && isset( $iComment ) && is_numeric( $iComment ) ){
	$sTable = null;
	$sLink = 'iPage';
	if( !isset( $iPage ) ) $iPage = null;
	if( isset( $iProduct ) ){
		$sLink = 'iProduct';
		$sTable = DB_PRODUCTS_COMMENTS;
	} else $iProduct = null;
	if( isset( $_POST['sOption'] ) && $_POST['sOption'] == 'saveComment' && !empty( $_POST['sContent'] ) && !preg_match( "/(\[url)|(<a href=)/i", $_POST['sContent'] ) && !empty( $_POST['sName'] ) ){
		saveComment( $_POST, $iComment, $sTable );
		header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $aActions['f'] . '-list&' . $sLink . '=' . $iPage . $iProduct );
		exit;
	}
	$aComment = commentInfo( $iComment, $sTable );
	$aComment['sContent'] = str_replace( "<br />", "\r\n", $aComment['sContent'] ) ;
	$aRatings = Array( '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5' );
	$aYesNo = Array( '0' => $lang['no'], '1' => $lang['yes'] );
	$oTpl->assign( 'aComment', $aComment );
	$oTpl->assign( 'aRatings', $aRatings );
	$oTpl->assign( 'aYesNo', $aYesNo );
	$content.= $oTpl->parse( 'comments_form.tpl' );
}
?>