<?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('global/global.php');
	$this->load_langfile('inside/dashboard.php');

	// We put the number of notices to 0
	$this->db2->query('UPDATE users SET num_notifications=0 WHERE iduser='.$this->user->id.' LIMIT 1');

	// We extract the notifications	
	$r = $this->db2->query('SELECT notif_type, notif_object_id, username, firstname, lastname, avatar, date, idresult FROM notifications, users WHERE users.iduser=from_user_id AND to_user_id='.$this->user->id.' ORDER BY date DESC LIMIT '.$C->NUM_NOTIFICATIONS_ALERT);


	$txtResult = '';
	ob_start();
	while( $obj = $this->db2->fetch_object($r) ) {
		$D->n_nameUser = (empty($obj->firstname) || empty($obj->lastname))?$obj->username:($obj->firstname.' '.$obj->lastname);
		$D->n_username = $obj->username;
		$D->n_avatar = $obj->avatar;
		$D->n_fdate = $obj->{'date'};
		$D->n_idpost = $obj->notif_object_id;
		$D->n_typenotifications = $obj->notif_type;
		
		$D->n_usernamePost = $this->user->info->username;
		if ($obj->notif_type == 2 || $obj->notif_type == 3) {
			$infoPost = $this->db2->fetch('SELECT posted_in, id_wall FROM posts WHERE idpost='.$D->n_idpost);
			if ($infoPost->posted_in == 1) {
				$D->n_usernamePost = $this->network->getURLPage($infoPost->id_wall);
			}
			if ($infoPost->posted_in == 2) {
				$D->n_usernamePost = $this->network->getURLGroup($infoPost->id_wall);
			}			
		}
		
		if ($obj->notif_type == 7) {
			$D->n_postcode = $this->network->getCodePost($obj->idresult);
		} else {
			$D->n_postcode = $this->network->getCodePost($D->n_idpost);
		}
		if ($obj->notif_type == 9) {
			$D->n_urlpage = $this->network->getURLPage($obj->notif_object_id);
		}
		if ($obj->notif_type == 10) {
			$D->n_codegroup = $this->network->getCodeGroup($obj->notif_object_id);
		}
		if ($obj->notif_type == 11) {
			$infoGroup = $this->network->getInfoGroup($obj->notif_object_id);
			$D->n_urlgroup = $infoGroup->url;
			$D->n_namegroup = stripslashes($infoGroup->name_group);
		}

		if ($obj->notif_type == 12) {
			$infoGroup = $this->network->getInfoGroup($obj->notif_object_id);
			$D->n_urlgroup = $infoGroup->url;
			$D->n_namegroup = stripslashes($infoGroup->name_group);
		}

		$this->load_template('__dashboard-one-alert-notifications.php');
	}
	$txtResult = ob_get_contents();
	ob_end_clean();
	
	unset($r, $obj);

	if (!empty($txtResult)) {
		echo('1: '.$txtResult);
		return;
	} else {
		echo('1: <div style="text-align:center; padding:10px 5px 10px">'.$this->lang('dashboard_mynotifications_nonotifications').'</div>');
		return;
	}
	
		
?>