<?PHP
/*
Uber-Simple Portfolio Gallery v1.1
copyright 2006 Ryan J. Pilling
Released: November 13, 2006
By WebWowTools.com (Ryan Pilling)
Online: http://www.webwowtools.com/uber-simple-portfolio


    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/////////////////////////////////////////////////////////////////
///////// SETTINGS //////////////////////////////////////////////

$portfolio_file_folder = 'portfoliofiles'; // the name of the folder that holds your project files
$portfolio_file_extensions = array('png','gif','jpg','jpeg'); // the type of image files allowed
$portfolio_menu_type = 'automatic'; // create the menu automatically from the portfolio folders
//$portfolio_menu_type = 'manual'; // create the menu yourself using HTML in menu.php

/////////////////////////////////////////////////////////////////


if ($_GET['project']!=''){
	if (is_dir($portfolio_file_folder.'/'.$_GET['project'])){
	$project = $_GET['project'];
	
	} else {
	$project = 'default';
	}
} else {
$project = 'default';
}


if ($portfolio_menu_type == 'automatic'){
$gallery_menu = array();
}

if ($handle = opendir($portfolio_file_folder)) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != "..") {
           
		   if (is_dir($portfolio_file_folder.'/'.$file)){
		   	if ($file == $project){ // this directory is the current project
		   
		   // create gallery image list
		   $gallery = opendir($portfolio_file_folder.'/'.$file);
		   $count = 1;
		   while (false !== ($galleryfile = readdir($gallery))) {
       	   if ($galleryfile != "." && $galleryfile != ".." && $galleryfile != "info.php" && !strstr($galleryfile,'_thumb')) {
		   // get file extension and name
		   $dotposition = strpos($galleryfile, '.');
		   $file_ext = substr($galleryfile, $dotposition+1);
		   $file_name = substr($galleryfile, 0, $dotposition);
		   // check to make sure thumbnail file exists
		   if (is_file($portfolio_file_folder.'/'.$file.'/'.$file_name.'_thumb.'.$file_ext)){
		   $thumbs .= '<img id="thumb'.$count.'" src="'.$portfolio_file_folder.'/'.$file.'/'.$file_name.'_thumb.'.$file_ext.'" class="thumbnail" onclick="showimage('.$count.');" />';
		   $images .= 'images['.$count.'] = \'<img src="'.$portfolio_file_folder.'/'.$file.'/'.$file_name.'.'.$file_ext.'" style="width: 400px; height: 250px;" />\''."\n";
		   $count++;
		   }
		   }
		   }
		   
		   		if ($portfolio_menu_type == 'automatic'){ // add this folder to the menu
					$projectinfo = ''; // clear the values before including
					if (include ($portfolio_file_folder.'/'.$file.'/info.php')){
					if ($projectinfo['title']==''){ $projectinfo['title'] = 'Untitled'; }
					if ($projectinfo['menu']==''){ $projectinfo['menu'] = $projectinfo['title']; }
					if ($projectinfo['order']==''){ $projectinfo['order'] = 2; }
					$projectinfo['folder'] = $file;
					array_push($gallery_menu,$projectinfo);
					}
				} else {
				// include the info for current gallery for manual menu as well
				include ($portfolio_file_folder.'/'.$file.'/info.php');
				}
				
			// set active info
			$active_title = $projectinfo['title'];
			$active_desc = $projectinfo['description'];
			
		   } else { // this directory is not the current project
		   
		   		if ($portfolio_menu_type == 'automatic'){ // add this folder to the menu
					$projectinfo = ''; // clear the values before including
					if (include ($portfolio_file_folder.'/'.$file.'/info.php')){
					if ($projectinfo['title']==''){ $projectinfo['title'] = 'Untitled'; }
					if ($projectinfo['menu']==''){ $projectinfo['menu'] = $projectinfo['title']; }
					if ($projectinfo['order']==''){ $projectinfo['order'] = 2; }
					$projectinfo['folder'] = $file;
					array_push($gallery_menu,$projectinfo);
					}
				}
		   }
		   }
       }
   }
   closedir($handle);
}

// make the menu
if ($portfolio_menu_type == 'automatic'){
function cmp($a, $b) {
if($a['order'] == $b['order']) { return 0; }
return ($a['order'] < $b['order']) ? -1 : 1;
}
usort($gallery_menu, 'cmp');
foreach ($gallery_menu as $menu){
$menulinks .= '<p><a href="index.php?project='.$menu['folder'].'">'.stripslashes($menu['menu']).'</a></p>'."\n";
}

}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Design Portfolio - <?PHP print stripslashes($active_title); ?></title>
<link href="<?PHP print $portfolio_file_folder; ?>/portfolio.css" rel="stylesheet" type="text/css" />

<script language="JavaScript" type="text/javascript">

function showimage(selected){

var images = new Array();
<?PHP print $images; ?>

var count = 1;
while (count<images.length){
	if (count == selected){
	document.getElementById('viewer').innerHTML = images[count];
	document.getElementById('thumb'+count).style.border = 'solid 1px #FFCC00';
	} else {
	document.getElementById('thumb'+count).style.border = 'solid 1px #CCCCCC';
	}
count++;
}

}

function createitem(){

var thumbs = '<?PHP print $thumbs; ?>';
document.getElementById('picker_thumbs').innerHTML = thumbs;
document.getElementById('picker_thumbs').style.width = '<?PHP print (($count-1)*92); ?>px';
showimage(1);

}

</script>


</head>

<body onload="createitem();">
<div id="wrap">
<div id="sidebar"><a href="index.php"><img src="<?PHP print $portfolio_file_folder; ?>/header.gif" alt="Ryan J. Pilling Portfolio" width="191" height="68" border="0" style="margin-bottom: 20px; border: 0px;" /></a>
<div id="menu">

<?PHP
// show the menu
if ($portfolio_menu_type == 'automatic'){
print ($menulinks);
} else {
include ('menu.php');
}
?>

<br />
<br />
<a href="http://www.webwowtools.com/uber-simple-portfolio" title="Powered by Uber Simple Portfolio Gallery"><img src="portfoliofiles/poweredbyuspg.gif" alt="Powered by Uber Simple Portfolio Gallery" width="14" height="19" border="0" /></a></div>
</div>
<div style="margin-left: 200px;">
<div id="title"><div id="titletext"><?PHP print stripslashes($active_title); ?></div></div>
<div id="viewer" style="background-image:url(<?PHP print $portfolio_file_folder; ?>/loadingbg.gif);">
</div>
<div id="picker">
<div id="picker_thumbs">
</div>
</div>

<div id="description">
<?PHP print nl2br(stripslashes($active_desc)); ?>
</div>
</div>
<br style="clear: both;" />
</div>
<div id="notice">All images on this site are copyright &copy; 2006</div>
</body>
</html>
