<?php
	if( !$this->user->is_logged ) {
		$this->redirect('home');
	}
	
	$D->codgroup = '';
	if ($this->param('g')) $D->codgroup = $this->param('g');

	if (empty($D->codgroup)) $this->redirect($C->SITE_URL.'dashboard/groups');	
	
	/*************************************************************************/
	// 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');
	

	/*************************************************************************/

	$r = $this->db2->query("SELECT * FROM groups WHERE code='".$D->codgroup."' AND idcreator=".$this->user->id." LIMIT 1");
	
	if (!$obj = $this->db2->fetch_object($r)) {
		$this->redirect($C->SITE_URL.'dashboard/groups');
	} else {
		$D->idgroup = $obj->idgroup;
		$D->codegroup = $obj->code;
		$D->num_members = $obj->num_members;
		$D->numpostsgroup = $obj->num_posts;
		$D->covergroup = $obj->cover_group;
		$D->namegroup = stripslashes($obj->name_group);
		$D->aboutgroup = stripslashes($obj->about_group);
		$D->urlgroup = $obj->url;
		$D->privacy = $obj->privacy;
		$D->numrequest = $this->db1->fetch_field('SELECT count(id) FROM groups_members WHERE idgroup='.$D->idgroup.' AND status=0');
	}
	
	$D->totalrequests = $this->db2->fetch_field("
	SELECT count(groups_members.iduser) 
	FROM groups_members, users 
	WHERE 
	groups_members.iduser=users.iduser 
	AND idgroup=".$D->idgroup." 
	AND status=0");
	
	$r = $this->db2->query("
	SELECT users.iduser, code, users.iduser, firstname, lastname, username, avatar, num_posts, num_friends, verified 
	FROM groups_members, users 
	WHERE 
	groups_members.iduser=users.iduser 
	AND idgroup=".$D->idgroup." 
	AND status=0 
	ORDER BY when_request DESC 
	LIMIT 0,".$C->NUM_MEMBERS_PAGE);
	
	$D->numrequests = $this->db2->num_rows();

	$D->htmlRequests = '';
	
	while( $obj = $this->db2->fetch_object($r) ) {
		$D->isThisUserVerified = $obj->verified==1?TRUE:FALSE;
		$D->f_name = (empty($obj->firstname) || empty($obj->lastname))?stripslashes($obj->username):(stripslashes($obj->firstname).' '.stripslashes($obj->lastname));
		$D->f_codeuser = $obj->code;
		$D->f_avatar = $obj->avatar;
		$D->f_iduser = $obj->iduser;
		$D->f_numfriends = $obj->num_friends;
		$D->f_username = $obj->username;
		$D->htmlRequests .= $this->load_template('__dashboard-one-request-group.php', FALSE);
	}

	unset($r, $obj);	

	
	/*************************************************************************/

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