<?php
	if( !$this->user->is_logged ) {
		$this->redirect('home');
	}
	
	
	/*************************************************************************/
	// needed before proceeding
	require_once('_all-required-language.php');
	
	$this->load_langfile('global/global.php');	
	$this->load_langfile('inside/dashboard.php');

	/*************************************************************************/
	
	
	require_once('_all-required-dashboard.php');
	

	/*************************************************************************/
	
	$D->cadsearch = '';
	if ($this->param('q')) $D->cadsearch = $this->db1->e($this->param('q'));
	
	$D->cadShort = 0;
	if (!empty($D->cadsearch) && strlen($D->cadsearch)<=3) $D->cadShort = 1;

	$D->doSearch = 0;

	if (!empty($D->cadsearch) && $D->cadShort==0) {
	
		$listgroups = $this->db2->fetch_all("
		SELECT groups.* FROM groups 
		WHERE 
		status=1 
		AND privacy<>2 
		AND (name_group LIKE '%".$D->cadsearch."%' OR about_group LIKE '%".$D->cadsearch."%') 
		ORDER BY num_members DESC
		");
		
		$D->doSearch = 1;
	
		$D->htmlGroups = '';
		
		foreach($listgroups as $onegroup) {
			$D->idgroup = $onegroup->idgroup;
			$D->codegroup = $onegroup->code;
			$D->num_members = $onegroup->num_members;
			$D->numpostsgroup = $onegroup->num_posts;
			$D->namegroup = stripslashes($onegroup->name_group);
			$D->urlgroup = $onegroup->url;
			$D->status = $onegroup->status;
			$D->privacy = $onegroup->privacy;
			$D->isMyGroup = $onegroup->idcreator == $this->user->id ? TRUE : FALSE;
			if ($D->isMyGroup) {
				$D->numrequest = $this->db1->fetch_field('SELECT count(id) FROM groups_members WHERE status=0 AND idgroup='.$D->idgroup);
			}
			$D->htmlGroups .= $this->load_template('__dashboard-one-group.php', FALSE);
		}
		
		unset($listgroups, $onegroup);
		
	}
	
	/*************************************************************************/

	$D->optionactive = 12;
	$D->tab_active = 3;
	$this->load_template('dashboard-groups-search.php');
?>