<?php
/*
	DevSaver Web Framework
	Copyright (c) 2013-2016 DevSaver. 
	All rights reserved.
		web:  www.devsaver.com
		mail: support@devsaver.com				
*/


class CBlogWidgetArchive extends CWidget {

	/**
	* description
	*
	* @var type
	*
	* @access type
	*/
	var $meta = array(
		"type"	=> "7",
		"name"	=> "Archive Menu",
		"module"	=> array(
			"name"	=> "",
			"id"	=> "",
			"type"	=> "",
		)
	);


	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function Render($widget) {
		global $_SESS;

		//get all topics

		$topics = $this->db->QFetchRowArray(
			"SELECT item_date , item_date_month , item_date_year FROM 
				{$this->tables['plugin:blog_topics']} as t , 
				{$this->tables['plugin:blog_topics_lang']} as l 
			WHERE 
				t.module_id = {$widget[mod_id]} AND 
				l.lang_id={$widget[lang_id]} AND 
				t.item_id=l.item_id AND 
				t.item_status = 1 AND 
				t.item_date < " . time() . "
				" . ( $_SESS["client"] ? "" : " AND item_protect=0 ") . "
			ORDER BY 
			item_date DESC
			"
		);

		if (is_array($topics)) {
			foreach ($topics as $key => $val) {

				$_key = $val["item_date_month"] . "-" . $val["item_date_year"];
				if (!is_array($_count[$_key])) {
					$_count[$_key] = array(
						"month_lang"	=> CDate::ToStr("%B" , $val["item_date"]),
						"month"			=> $val["item_date_month"],
						"month2"		=> $val["item_date_month"] < 10 ? "0" . $val["item_date_month"] : $val["item_date_month"],
						"year"			=> $val["item_date_year"],
						"link"			=> $widget["link"],
					);
				}
				
				$_count[$_key]["count"] ++;
			}

			foreach ($_count as $key => $val) {
				$_count[$key]["link"] = $widget["link"] . $val["month2"] . "-" . $val["year"] . "/";
				$_count[$key]["class"] = ($_GET["module_id"] == $widget["widget_module"]) && ($_GET["month"] == $val["month2"]) && ($_GET["year"] == $val["year"]) ?  $this->tpl->blockReplace("Selected") : "";
			}
		
	
			global $base;

			return $this->tpl->blockreplace(
				"Main" , 
				array(
					"labels"	=> $base->html->Table(
						$this->tpl, 
						"", 
						$_count
					),

					"widget_title"	=> $widget["widget_name"],
				),
				$widget["mod_settings"]
			);

		}

	}
	
	

}


?>