<?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');
	
	$errored = 0;
	$txterror = '';

	$numitems = $iduser = 0;
	$codealbum = '';
	
	if (isset($_POST["ni"]) && !empty($_POST["ni"])) $numitems = $this->db1->e($_POST["ni"]);
	if (isset($_POST["idu"]) && !empty($_POST["idu"])) $iduser = $this->db1->e($_POST["idu"]);
	if (isset($_POST["coda"]) && !empty($_POST["coda"])) $codealbum = $this->db1->e($_POST["coda"]);
	
	if (!is_numeric($numitems) || $numitems <= 0) { $errored = 1; $txterror .= 'Error... '; }
	if (!is_numeric($iduser) || $iduser <= 0) { $errored = 1; $txterror .= 'Error... '; }
	if (empty($codealbum)) { $errored = 1; $txterror .= 'Error... '; }

	if ($errored == 1) {
		echo('0: '.$txterror);
	} else {

		$idalbum = $this->db2->fetch_field("SELECT idalbum FROM albums WHERE code='".$codealbum."'");

		$totalitems = $this->db2->fetch_field('SELECT COUNT(idalbum) FROM albums_photos WHERE idalbum='.$idalbum);
		$r = $this->db2->query('SELECT * FROM albums_photos WHERE idalbum='.$idalbum.' ORDER BY whendate DESC LIMIT '.$numitems.','.$C->NUM_PHOTOS_PAGE);
	
		$numitemsnow = $this->db2->num_rows();
		
		$htmlResults = '';
		$D->codalbum = $codealbum;
		while( $obj = $this->db2->fetch_object($r) ) {
			$D->codephoto = $obj->code;
			$D->idphoto = $obj->idphoto;
			$D->photofile = $obj->photo;
			$D->isMyPhoto = $obj->iduser == $this->user->id ? TRUE : FALSE;
			$htmlResults .= $this->load_template('__one-photo-albums.php', FALSE);
		}
			
		unset($r, $obj);
		
		if ($totalitems <= $numitemsnow + $numitems) {
			echo("2: ".$htmlResults);
			return;
		} else {
			echo("1: ".$htmlResults);
			return;	
		}		
	}
?>