<?php

/**
  * BLOG:CMS: PHP/MySQL Personal Content Management System (CMS)
  * http://blogcms.com/
  * ----------------------------------------------------------------
  *
  * Copyright (C) 2003-2005 Radek HULÁN
  * http://hulan.cz/contact/
  *
  * Based on: 
  * ----------------------------------------------------------------
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
  * Copyright (C) 2002-2003 The Nucleus Group
  *
  * ----------------------------------------------------------------
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
**/

class NP_Viewed extends NucleusPlugin {

   function getName() {   return 'Viewed';    }
   function getAuthor()  { return 'Rodrigo Moraes / Edmond Hui'; }
   function getURL() { return 'http://www.tipos.com.br'; }
   function getVersion() {   return '1.2'; }
   function getDescription() {
      return 'This plugin displays viewed items number.';
   }

	function supportsFeature($feature) {
		switch($feature) {
			case 'SqlTablePrefix':
				return 1;
			default:
				return 0;
		}
	}

	function getTableList() {
		return array(sql_table('plugin_views'));
	}

   function doSkinVar($skinType) 
   {
   global $itemid;

   if ($itemid != 0) 
   {
      $query = "SELECT views FROM ".sql_table('plugin_views')." WHERE id=$itemid";
      $res = sql_query($query);
      $row = sql_fetch_object($res);
      
      if (sql_num_rows($res) == 0) {
		  $query = "INSERT INTO ".sql_table('plugin_views')." VALUES ('$itemid','1')";
		  $res = sql_query($query);
      	$views = 1;
	  } else {
		  $views = $row->views;
		  $views++;
		  $query = "UPDATE ".sql_table('plugin_views')." SET views='$views' WHERE id=$itemid";
		  $res = sql_query($query); 
	  }
   
   echo $views."x";
   }
   }
}
?>