if (!User::is_logged_in() || User::get_id() != 1) {
    header('Location: index.php');
    exit;
}
if (isset($_GET['d'])) {
    $d = (int) $_GET['d'];
    AdReview::delete($d);
}
$tct = AdReview::count();
//total count
$rpp = 10;
//row per page
$pager_options = array('mode' => 'Sliding', 'perPage' => $rpp, 'delta' => 2, 'totalItems' => $tct, 'excludeVars' => array('o', 'r', 'd', 't', 'e'));
$pager = @Pager::factory($pager_options);
list($from, $to) = $pager->getOffsetByPageId();
$reviews = AdReview::get_all(array(), '', $from - 1 . ", {$rpp}");
include "page-header.php";
?>

<div id="wrapper">
	
	<?php 
include "page-left.php";
?>

	<div id="content">

		<?php 
if ($tct > $rpp) {
    echo $pager->links . '<br /><br />';
}
<?php

/**
 * Classified-ads-script
 * 
 * @copyright  Copyright (c) Szilard Szabo
 * @license    GPL v3
 * @package    Frontend
 */
include "./admin/include/common.php";
include "Pager/Pager.php";
$g_id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$exists = Ad::exists($g_id, array("active  " => 1));
if ($exists) {
    $ad = Ad::get_one($g_id);
    $is_favourite = Favourite::exists(User::get_id(), $ad['id']);
    $reviews = AdReview::get_all(array('ad_id' => $g_id));
}
include "./templates/ad.php";
    if ($p_rate < 1 || $p_rate > 5) {
        $success = false;
        array_push($errors, "Please provide a valid rate.");
    }
    if ($p_comment == '') {
        $success = false;
        array_push($errors, "The comment field is required!");
    }
    if ($p_comment != '' && !preg_match('/^[\\s\\S]{0,500}$/u', $p_comment)) {
        $success = false;
        array_push($errors, "The comment must be no more than 500 character long.");
    }
    if ($success) {
        $update = array('rate' => $p_rate, 'comment' => $p_comment);
        AdReview::update($g_id, $update);
        $adreview = AdReview::get_one($g_id);
    }
}
include "page-header.php";
?>

<div id="wrapper">

	<?php 
include "page-left.php";
?>

	<div id="content">
			
		<form name="form_adreview_edit" id="form_adreview_edit" method="post" enctype='application/x-www-form-urlencoded' accept-charset="UTF-8" class="form">
 * @package    Frontend
 */
include "./admin/include/common.php";
$r_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$exists = Ad::exists($r_id, array("active" => 1));
if ($exists) {
    $ad = Ad::get_one($r_id);
    if (isset($_POST['send']) && User::is_logged_in()) {
        $success = true;
        $errors = array();
        $p_rate = isset($_POST['rate']) ? (int) $_POST['rate'] : 0;
        $p_comment = strip_tags($_POST['comment']);
        if (AdReview::exists($r_id, User::get_id())) {
            $success = false;
            array_push($errors, "You have already reviewed this ad.");
        } else {
            if ($p_rate < 1 || $p_rate > 5) {
                $success = false;
                array_push($errors, "Please provide a valid rate.");
            }
            if ($p_comment != '' && !preg_match('/^[\\s\\S]{0,200}$/u', $p_comment)) {
                $success = false;
                array_push($errors, "The comment must be no more than 200 character long.");
            }
            if ($success) {
                AdReview::create(array('ad_id' => $r_id, 'user_id' => User::get_id(), 'rate' => $p_rate, 'comment' => $p_comment));
            }
        }
    }
}
include "./templates/ad-review.php";