Location: PHPKode > projects > Gallereazy > gallereazy/MainPage.class.php
<?php

class MainPage 
{
	var $_arCategories = array();
	var $_stHeading;
	var $_arLatestTenComments = array();
	var $_stCurrentAlbumDescription;
	var $_arFiles = array();
	var $_iCurrentAlbum;
	var $_iCurrentCategory;
	var $_arCategoryNames = array();
	var $_stJavaScriptFileArray;
		

	function populateCategoryArray($iCategory, $iAlbum)
	{
   		$this->_iCurrentAlbum = $iAlbum;
		$this->_iCurrentCategory = $iCategory;
		
		// get categories not in an album
		$result = mysql_query (" 
			SELECT albums.id, albums.name, albums.default, albums.description, albums.order
			FROM albums
			WHERE albums.user= '" . USER . "' AND albums.category=0 
			ORDER BY albums.order ASC, albums.id DESC
			");
		if($result)
		{
			while ($row = mysql_fetch_assoc($result))
			{
			    //echo"<pre>";print_r($row);echo"</pre>";
				$this->_arCategories[0][$row['id']] = $row;
				
				if($this->_iCurrentCategory == null || $this->_iCurrentCategory === 0)
				{
					if($this->_iCurrentAlbum == null || $this->_iCurrentAlbum == 0) // Sets the album to the first one returned
					{
						$this->_iCurrentAlbum = $row['id'];
					}	
					
					if($iAlbum == null && $row['default']=='1') // Overrides first one set to set the default
					{
						$this->_iCurrentAllbum = $row['id'];
						$this->_iCurrentCategory = 0;
						
						$iAlbum = $row['id'];
						$iCategory = 0;
					}
				}
			}//end while
		}// end if
	
		//echo"<pre>";print_r($categories);echo"</pre>";
		
		// get albums assigned to a category
		$result = mysql_query (" 
				SELECT albums.id, albums.name, categories.id as 'categoryId', categories.name as 'categoryName', albums.default, albums.description 
				FROM albums, categories 
				WHERE albums.category=categories.id AND albums.user = '" . USER . "'
				ORDER BY categories.order ASC, albums.order ASC
				");
		if($result)
		{
			while ($row = mysql_fetch_assoc($result))
			{
			    //echo"<pre>";print_r($row);echo"</pre>";
				$this->_arCategoryNames[$row['categoryId']] = $row['categoryName'];
				$this->_arCategories[$row['categoryId']][$row['id']] = $row;
				
				if($iAlbum != null)
				{
					if($this->_iCurrentAlbum == $row['id'])
						$this->_iCurrentCategory = $row['categoryId'];
				}
				else
				{
					if($iCategory == null)
					{		
						if($this->_iCurrentCategory == null) // Sets the category to the first one returned
						{
							$this->_iCurrentAlbum = $row['id'];
							$this->_iCurrentCategory = $row['categoryId'];
						}	
						
						if($iAlbum == null && $row['default']==1) // Overrides first one set to set the default
						{
							$this->_iCurrentAlbum = $row['id'];
							$this->_iCurrentCategory = $row['categoryId'];
						}
					}
					else // category IS set
					{
						if($this->_iCurrentCategory == $row['categoryId'])
						{
							if($row['default'] == 1) // If default happens to be in this year, use it
								$this->_iCurrentAlbum = $row['id'];
								
							if($this->_iCurrentAlbum == null) // Otherwise use the first one
								$this->_iCurrentAlbum = $row['id'];	
						}			
					}	
				}
			}
		}
		//echo'<pre>';print_r($this->_arCategories);echo'</pre>';
	}
	
	function populateLatestTenComments($increment = 0)
	{
		$start = $increment * 10;
		
		$query= "
				SELECT  comments.id AS comment_id, comments.picture, albums.id AS album, comments.name, comments.comment, pictures.width, pictures.height
				FROM  `comments` ,  `albums`, `pictures`
				WHERE albums.user =  '" . USER . "' 
				AND comments.picture = pictures.id  
				AND pictures.album = albums.id
				ORDER BY comment_id DESC LIMIT $start, 11
				";
			### I took this out of the query:"MAX(comments.id)" "GROUP BY comments.picture"
		
		$result = mysql_query ($query);
		
		if($result)
		{
			while ($row = mysql_fetch_assoc($result))
				$this->_arLatestTenComments[]=$row;
		}
	}
	
	// set which albums are to be displayed based on
	// what category the user is currently viewing
	function setAlbumDisplayValue($stYear)
	{
		if(isset($this->_arCategories))
		{
			foreach($this->_arCategories as $key=>$value)
			{
				foreach($value as $k2=>$v2)
				{
					if("$stYear" == $key || $key == "0")
						$v2['display'] = "block";
					else
						$v2['display'] = "none";
						
					$value[$k2] = $v2;
				}
				
				$this->_arCategories[$key] = $value;
			}
		}
	}
	
	
	function populateFileArray()
	{//print_r($this->_iCurrentAlbum);
		$result = mysql_query(" SELECT * FROM pictures WHERE album = '$this->_iCurrentAlbum' ORDER BY `order`, id");
		while($o = mysql_fetch_object($result))
		{
			$o->_arComments = array();
			$this->_arFiles[$o->id] = $o;
		}

		$result = mysql_query(" SELECT * FROM comments WHERE album = '$this->_iCurrentAlbum' ");
		while($o = mysql_fetch_object($result))
		{
			$this->_arFiles[$o->picture]->_arComments[$o->id] = $o;
		}

		//echo "<pre>"; print_r($this->_arFiles);
		$this->_stJavaScriptFileArray = '[';
		
		if(isset($this->_arFiles))
		{
			$i = 0;
			foreach($this->_arFiles as $oFile)
			{
			    if($oFile->width == '666' && $oFile->height == '666')
			    {
					$thumb = theme("movie.gif");
					$this->_arFiles[$oFile->id]->link = "<a name=\"$oFile->id\" id=\"$file\" href=\"$file\" target=\"_blank\"><img class=\"file\" border=\"0\" src=\"$thumb\"></a><br />";
			    }
			    else
			    {
					$thumb = "thumb_".$oFile->id.".jpg";
					$width = $oFile->height;
					$height = $oFile->height;
					$description = $oFile->description;
					$this->_arFiles[$oFile->id]->link = "<a name=\"$oFile->id\" href=\"javascript:pictureWindow($i)\"><img class=\"image\" border=\"0\" src=\"photos/$thumb\"></a><br />";
				 }
				   
			    if(ALLOW_COMMENTS)
			    {
			    		$comment_count = count($oFile->_arComments);
				    		
				    if($comment_count > 0)
				    		$this->_arFiles[$oFile->id]->link .= "<a class=\"comment_link\" href=\"javascript:display('$oFile->id')\">show comments ($comment_count)</a><br />";
				    	
				    $this->_arFiles[$oFile->id]->link .= "<a class=\"comment_link\" href=\"javascript:comment($oFile->id, $this->_iCurrentAlbum, false)\">add comment</a>";
				}
				 
				 //$oMainPage->_arFiles = $files;				 
				 // fill in javascript array string
				 $this->_stJavaScriptFileArray .= '"' . $oFile->id . '",';
				 
				 $i++;
			}
		}
		
		if(strlen($this->_stJavaScriptFileArray) > 1)
			$this->_stJavaScriptFileArray = substr($this->_stJavaScriptFileArray, 0, -1) . ']';
		else 
			$this->_stJavaScriptFileArray = 'new Array()';
	}


	function isCurrentAlbum($current)
	{ 
	    if($current == $this->_iCurrentAlbum)
	        return true;
	}
}
?>
Return current item: Gallereazy