<?php

/** !
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* [filename] is a part of PeopleAggregator.
* [description including history]
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* @author [creator, or "Original Author"]
* @license http://bit.ly/aVWqRV PayAsYouGo License
* @copyright Copyright (c) 2010 Broadband Mechanics
* @package PeopleAggregator
*/
error_reporting(E_ALL);
$login_required = FALSE;
include_once "web/includes/page.php";
include_once "web/Widgets/ViewTracker/ViewTracker.php";
$error = null;
if ($_POST) {
    $obj = new ViewTracker();
    try {
        $obj->set_type($_POST['type']);
        $obj->title = $_POST['title'];
        $obj->url = $_POST['url'];
        $obj->time_stamp = time();
        $obj->save();
    } catch (PAException $e) {
        print 'Type does not exist';
    }
}
* @license http://bit.ly/aVWqRV PayAsYouGo License
* @copyright Copyright (c) 2010 Broadband Mechanics
* @package PeopleAggregator
*/
error_reporting(E_ALL);
$login_required = FALSE;
include_once "web/includes/page.php";
include_once "web/Widgets/ViewTracker/ViewTracker.php";
$type = NULL;
if (!empty($_GET['type'])) {
    $type = htmlspecialchars($_GET['type']);
}
$error = NULL;
$view_content = array();
//fetching the data according to view count.
$obj = new ViewTracker();
try {
    $obj->set_type($type);
    $view_content = $obj->get_most_viewed_pages();
} catch (PAException $e) {
    $error = '<li>' . $e->message . '</li>';
}
$html = '<ul>';
if (!empty($view_content)) {
    foreach ($view_content as $value) {
        if (!empty($value->title)) {
            $html .= '<li><a href= "' . $value->url . '">' . $value->title . '</a></li>';
        }
    }
} else {
    $html .= $error;