<?php
	// We check in which language we will work
	if (isset($_SESSION["DATAGLOBAL"][0]) && !empty($_SESSION["DATAGLOBAL"][0])) $C->LANGUAGE = $_SESSION["DATAGLOBAL"][0];

	$this->load_langfile('inside/dashboard.php');

	// We are here only if you're logged in
	if (!$this->user->is_logged) {
		echo('0: '.$this->lang('dashboard_no_session'));
		die();
	}
	
	$errored = 0;
	$txterror = '';
	
	$action=0;
	
	if (isset($_POST["todo"]) && $_POST["todo"] != '') $action = $this->db1->e($_POST["todo"]);
	if (!is_numeric($action)) {
		$errored = 1;
		$txterror .= 'Error. ';
		echo('0: '.$caderror);
		die();
	}

	if ($action == 1 || $action==2 || $action==3)	{
		$idgroup = 0;
		if (isset($_POST["idg"])) $idgroup = $this->db1->e($_POST["idg"]);
		if (!is_numeric($idgroup) || $idgroup <= 0) { $errored = 1; $txterror .= 'Error. '; }
	}
	
	if ($errored == 1) {
		echo('0: '.$txterror);
	} else {
		
		// Member Request Sent to Group
		if ($action == 1) {
			if( $this->user->sendMemberRequest($idgroup) ) $txtreturn = '1: Ok';
			else $txtreturn = '0: '.$this->lang('dashboard_no_session');
			echo $txtreturn;
			return;
		}

		// Cancel Request ... Made by the user who sent the invitation.
		if ($action == 2) {
			if( $this->user->cancelMemberRequest($idgroup) ) $txtreturn = '1: Ok';
			else $txtreturn = '0: '.$this->lang('dashboard_no_session');
			echo $txtreturn;
			return;
		}
		
		// Leave group ... By the any user
		if ($action == 3) { 
			if( $this->user->leaveGroup($idgroup) ) $txtreturn = '1: Ok';
			else $txtreturn = '0: '.$this->lang('dashboard_no_session');
			echo $txtreturn;
			return;
		}
		
	}
	
?>