<?php
(!defined('IN_PowerBB')) ? die() : '';
include('common.php');
define('CLASS_NAME','PowerBBMemberlistMOD');

class PowerBBMemberlistMOD
{
	function run()
	{
		global $PowerBB;

		$this->_GetJumpSectionsList();
       		$PowerBB->functions->ShowHeader();

		if (!$PowerBB->_CONF['group_info']['memberlist_allow'])
		{
          if (!$PowerBB->_CONF['member_permission'])
              {
              $PowerBB->template->display('login');
              $PowerBB->functions->error_stop();
			}
	        else
	        {
	        $PowerBB->functions->error($PowerBB->_CONF['template']['lang']['no_online']);
	        }
	     }

		if ($PowerBB->_GET['index'])
	  {
			if ($PowerBB->_GET['show'])
         {
            	$this->_GetMemberList();
         }

          elseif (($PowerBB->_GET['order'] <= 1) or ($PowerBB->_GET['order'] > 3))
         {

          if ($PowerBB->_GET['order_type'] == 'DESC')
            {
           	   $this->_GetMemberList1();
            }

         }
         elseif ($PowerBB->_GET['order'] == 2)
         {
             if ($PowerBB->_GET['order_type'] == 'DESC')
             {
             	$this->_GetMemberList2();
             }
         }

         elseif ($PowerBB->_GET['order'] == 3)
         {
             if ($PowerBB->_GET['order_type'] == 'DESC')
             {
               $this->_GetMemberList3();
             }

	    }

		else
		{
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['path_not_true']);
		}

		$PowerBB->functions->GetFooter();
	}
}

    /**
	 * Get the Jump Sections List
	 */
	function _GetJumpSectionsList()
    {
		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
		$catsy = $PowerBB->section->GetSectionsList($SecArr);

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

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

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

					if (!empty($caty['forums_cache']))
					{
						$forumsy = unserialize(base64_decode($caty['forums_cache']));

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

									// Get the first-level sub forums as a _link_ and store it in $forumy['sub']

									$forumy['is_sub'] 	= 	0;
									$forumy['sub']		=	'';

									if (!empty($forumy['forums_cache']))
									{
										$subsy = unserialize(base64_decode($forumy['forums_cache']));

										if (is_array($subsy))
										{
											foreach ($subsy as $suby)
											{
												if (is_array($suby['groups'][$PowerBB->_CONF['group_info']['id']]))
												{
													if ($suby['groups'][$PowerBB->_CONF['group_info']['id']]['view_section'])
													{
														if (!$forumy['is_sub'])
														{
															$forumy['is_sub'] = 1;
														}

														$forumy['sub'] .= ('<option value="index.php?page=forum&amp;show=1&amp;id=' . $suby['id'] . '">---'  . $suby['title'] . '</option>');
													}
												}
											}
										}
									}


									$PowerBB->_CONF['template']['foreach']['forumsy_list'][$forumy['id'] . '_f'] = $forumy;
								}
							} // end if is_array
						} // end foreach ($forumsy)
					} // end !empty($forums_cache)
					unset($groups);

				}
			}


		} // end foreach ($catsy)

		//////////
   }


	function _GetMemberList()
	{
		global $PowerBB;

		$PowerBB->_GET['count'] = (!isset($PowerBB->_GET['count'])) ? 0 : $PowerBB->_GET['count'];
                $PowerBB->_GET['count'] = $PowerBB->functions->CleanVariable($PowerBB->_GET['count'],'intval');

		$ListArr 						= 	array();

		// Order data
		$ListArr['order']				=	array();
		$ListArr['order']['field']		=	'id';
		$ListArr['order']['type']		=	'DESC';

		$ListArr['limit']		        =	$PowerBB->_CONF['info_row']['perpage'];
		// Clean data from HTML
		$ListArr['proc'] 				= 	array();
		$ListArr['proc']['*'] 			= 	array('method'=>'clean','param'=>'html');

		// Pager setup
		$ListArr['pager'] 				= 	array();
		$ListArr['pager']['total']		= 	$PowerBB->member->GetMemberNumber(array('get_from'=>'db'));
		$ListArr['pager']['perpage'] 	= 	$PowerBB->_CONF['info_row']['perpage'];
		$ListArr['pager']['count'] 		= 	$PowerBB->_GET['count'];
		$ListArr['pager']['location'] 	= 	'index.php?page=member_list&amp;index=1&amp;show=1&amp;id=' . $this->Section['id'];
		$ListArr['pager']['var'] 		= 	'count';

		$GetMemberList = $PowerBB->member->GetMemberList($ListArr);

		$PowerBB->_CONF['template']['while']['MemberList'] = $GetMemberList;

		if ($PowerBB->member->GetMemberNumber(array('get_from'=>'db')) > $PowerBB->_CONF['info_row']['perpage'])
		{
		$PowerBB->template->assign('pager',$PowerBB->pager->show());
		}



		$PowerBB->template->display('show_memberlist');

	}

		function _GetMemberList1()
	{
		global $PowerBB;



		$PowerBB->_GET['count'] = (!isset($PowerBB->_GET['count'])) ? 0 : $PowerBB->_GET['count'];
		$PowerBB->_GET['count'] = $PowerBB->functions->CleanVariable($PowerBB->_GET['count'],'intval');

		$ListArr 						= 	array();

		// Order data
		$ListArr['order']				=	array();
		$ListArr['order']['field']		=	'posts';
		$ListArr['order']['type']		=	'DESC';

		$ListArr['limit']		        =	$PowerBB->_CONF['info_row']['perpage'];

		// Clean data from HTML
		$ListArr['proc'] 				= 	array();
		$ListArr['proc']['*'] 			= 	array('method'=>'clean','param'=>'html');

		// Pager setup
		$ListArr['pager'] 				= 	array();
		$ListArr['pager']['total']		= 	$PowerBB->member->GetMemberNumber(array('get_from'=>'db'));
		$ListArr['pager']['perpage'] 	= 	$PowerBB->_CONF['info_row']['perpage'];
		$ListArr['pager']['count'] 		= 	$PowerBB->_GET['count'];
		$ListArr['pager']['location'] 	= 	'index.php?page=member_list&amp;index=1&amp;order=1&amp;order_type=DESC&amp;id=' . $this->Section['id'];
		$ListArr['pager']['var'] 		= 	'count';

		$GetMemberList = $PowerBB->member->GetMemberList($ListArr);

		$PowerBB->_CONF['template']['while']['MemberList'] = $GetMemberList;

		if ($PowerBB->member->GetMemberNumber(array('get_from'=>'db')) > $PowerBB->_CONF['info_row']['perpage'])
		{
		$PowerBB->template->assign('pager',$PowerBB->pager->show());
		}

		$PowerBB->template->display('show_memberlist');

	}

		function _GetMemberList2()
	{
		global $PowerBB;



		$PowerBB->_GET['count'] = (!isset($PowerBB->_GET['count'])) ? 0 : $PowerBB->_GET['count'];
		$PowerBB->_GET['count'] = $PowerBB->functions->CleanVariable($PowerBB->_GET['count'],'intval');

		$ListArr 						= 	array();

		// Order data
		$ListArr['order']				=	array();
		$ListArr['order']['field']		=	'id';
		$ListArr['order']['type']		=	'ASC';

		$ListArr['limit']		        =	$PowerBB->_CONF['info_row']['perpage'];

		// Clean data from HTML
		$ListArr['proc'] 				= 	array();
		$ListArr['proc']['*'] 			= 	array('method'=>'clean','param'=>'html');

		// Pager setup
		$ListArr['pager'] 				= 	array();
		$ListArr['pager']['total']		= 	$PowerBB->member->GetMemberNumber(array('get_from'=>'db'));
		$ListArr['pager']['perpage'] 	= 	$PowerBB->_CONF['info_row']['perpage'];
		$ListArr['pager']['count'] 		= 	$PowerBB->_GET['count'];
		$ListArr['pager']['location'] 	= 	'index.php?page=member_list&amp;index=1&amp;order=2&amp;order_type=DESC&amp;id=' . $this->Section['id'];
		$ListArr['pager']['var'] 		= 	'count';

		$GetMemberList = $PowerBB->member->GetMemberList($ListArr);

		$PowerBB->_CONF['template']['while']['MemberList'] = $GetMemberList;

		if ($PowerBB->member->GetMemberNumber(array('get_from'=>'db')) > $PowerBB->_CONF['info_row']['perpage'])
		{
		$PowerBB->template->assign('pager',$PowerBB->pager->show());
		}

		$PowerBB->template->display('show_memberlist');

	}

		function _GetMemberList3()
	{
		global $PowerBB;


		$PowerBB->_GET['count'] = (!isset($PowerBB->_GET['count'])) ? 0 : $PowerBB->_GET['count'];
		$PowerBB->_GET['count'] = $PowerBB->functions->CleanVariable($PowerBB->_GET['count'],'intval');

		$ListArr 						= 	array();

		// Order data
		$ListArr['order']				=	array();
		$ListArr['order']['field']		=	'visitor';
		$ListArr['order']['type']		=	'DESC';

		$ListArr['limit']		        =	$PowerBB->_CONF['info_row']['perpage'];

		// Clean data from HTML
		$ListArr['proc'] 				= 	array();
		$ListArr['proc']['*'] 			= 	array('method'=>'clean','param'=>'html');

		// Pager setup
		$ListArr['pager'] 				= 	array();
		$ListArr['pager']['total']		= 	$PowerBB->member->GetMemberNumber(array('get_from'=>'db'));
		$ListArr['pager']['perpage'] 	= 	$PowerBB->_CONF['info_row']['perpage'];
		$ListArr['pager']['count'] 		= 	$PowerBB->_GET['count'];
		$ListArr['pager']['location'] 	= 	'index.php?page=member_list&amp;index=1&amp;order=3&amp;order_type=DESC&amp;id=' . $this->Section['id'];
		$ListArr['pager']['var'] 		= 	'count';

		$GetMemberList = $PowerBB->member->GetMemberList($ListArr);

		$PowerBB->_CONF['template']['while']['MemberList'] = $GetMemberList;

		if ($PowerBB->member->GetMemberNumber(array('get_from'=>'db')) > $PowerBB->_CONF['info_row']['perpage'])
		{
		$PowerBB->template->assign('pager',$PowerBB->pager->show());
		}

		$PowerBB->template->display('show_memberlist');


	}


}
?>
