<?php

// ##############################################################################||
// #
// #   PowerBB Version 2.0.0
// #   http://www.PBBoard.com
// #   Copyright (c) 2009 by Abu.Rakan
// #
// #   filename : archive.module.php
// #
// ##############################################################################||

(!defined('IN_PowerBB')) ? die() : '';

$CALL_SYSTEM				=	array();
$CALL_SYSTEM['SECTION'] 	= 	true;

include('common.php');

define('CLASS_NAME','PowerBBIndexArchiveMOD');

class PowerBBIndexArchiveMOD
{
	function run()
	{
		// Who can live without $PowerBB ? ;)
		global $PowerBB;
 		if ($PowerBB->_CONF['info_row']['active_archive'] == '0')
		{
		exit;
		}
		/**
		 * Firstly we get sections list
		 */
		$this->_GetSections();

		/**
		 * Show main template
		 */
		$this->_CallTemplate();

	}

	/**
	 * Get sections list from cache and show it.
	 */
		/**
	 * Get sections list from cache and show it.
	 */
	function _GetSections()
	{
		global $PowerBB;


		$SecArr 						= 	array();
		$SecArr['get_from']				=	'db';

		$SecArr['proc'] 				= 	array();
		$SecArr['proc']['*'] 			= 	array('method'=>'clean','param'=>'html');

		$SecArr['order']				=	array();
		$SecArr['order']['field']		=	'sort';
		$SecArr['order']['type']		=	'ASC';

		$SecArr['where']				=	array();
		$SecArr['where'][0]['name']		= 	'parent';
		$SecArr['where'][0]['oper']		= 	'=';
		$SecArr['where'][0]['value']	= 	'0';

		// Get main sections
		$cats = $PowerBB->section->GetSectionsList($SecArr);

		// We will use forums_list to store list of forums which will view in main page
		$PowerBB->_CONF['template']['foreach']['forums_list'] = array();

		// Loop to read the information of main sections
		foreach ($cats as $cat)
		{
			// Get the groups information to know view this section or not
			$groups = unserialize(base64_decode($cat['sectiongroup_cache']));

			if (is_array($groups[$PowerBB->_CONF['group_info']['id']]))
			{
				if ($groups[$PowerBB->_CONF['group_info']['id']]['view_section'])
				{
					$PowerBB->_CONF['template']['foreach']['forums_list'][$cat['id'] . '_m'] = $cat;
				}
			}

			unset($groups);

			if (!empty($cat['forums_cache']))
			{
				$forums = unserialize(base64_decode($cat['forums_cache']));

				foreach ($forums as $forum)
				{
					if (is_array($forum['groups'][$PowerBB->_CONF['group_info']['id']]))
					{
						if ($forum['groups'][$PowerBB->_CONF['group_info']['id']]['view_section'])
						{
							//////////


							$forum['is_sub_archive'] 	= 	0;
							$forum['sub_archive']		=	'';

							if (!empty($forum['forums_cache']))
							{
								$subs = unserialize(base64_decode($forum['forums_cache']));

								if (is_array($subs))
								{
									foreach ($subs as $sub)
									{
										if (is_array($sub['groups'][$PowerBB->_CONF['group_info']['id']]))
										{
											if ($sub['groups'][$PowerBB->_CONF['group_info']['id']]['view_section'])
											{
												if (!$forum['is_sub_archive'])
												{
													$forum['is_sub_archive'] = 1;
												}

                                               if ($PowerBB->_CONF['info_row']['rewriterule'] == '1')
                                                {
												$forum['sub_archive'] .= '<li><a href="Af' . $sub['id'] . '.html">' . $sub['title'] . '</a></li>  ';
											    }
												else
												{
												$forum['sub_archive'] .= '<li><a href="index.php?page=forum_archive&amp;show=1&amp;id=' . $sub['id'] . '">' . $sub['title'] . '</a></li>  ';
											    }

											}
										}
									}
								}
							}




							$PowerBB->_CONF['template']['foreach']['forums_list'][$forum['id'] . '_f'] = $forum;
						}
					} // end if is_array
				} // end foreach ($forums)
			} // end !empty($forums_cache)
		} // end foreach ($cats)


		//////////
	}


	function _CallTemplate()
	{
		global $PowerBB;
		$PowerBB->template->display('archive_main');
		$PowerBB->template->display('archive_footer');
	}
}

// The end , Hey it's first module wrote for PowerBB 2.0 :) , 24/5/2009 -> 4:24 PM

?>
