Location: PHPKode > projects > HuMo-gen > photoalbum.php
<?php
// *****************************
// *** Photoalbum            ***
// *****************************

$show_pictures=8; // *** Default value ***
if(isset($_COOKIE["humogenphotos"])) {
	$show_pictures=$_COOKIE["humogenphotos"];
}
elseif (isset( $_SESSION['save_show_pictures'])){
	$show_pictures=$_SESSION['save_show_pictures'];
}
if (isset($_POST['show_pictures'])){
	$show_pictures=$_POST['show_pictures'];
	$_SESSION['save_show_pictures']=$show_pictures;
	setcookie("humogenphotos", $show_pictures, time()+60*60*24*365);
}
if (isset($_GET['show_pictures'])){
	$show_pictures=$_GET['show_pictures'];
	$_SESSION['save_show_pictures']=$show_pictures;
	setcookie("humogenphotos", $show_pictures, time()+60*60*24*365);
}

$kop="fotoboek";
include("header.php");
include("menu.php");

// *** Check user privileges ***
if ($user["afbeeldingen"]!='j'){
	echo $language["lng_no_authority"];
	exit();
}

include ("include/language_date.php");
include("include/date_place.php");
include('include/person_cls.php');

// *** Photo search ***
$photo_name='';
if (isset($_POST['photo_name'])){ $photo_name=veilig($_POST['photo_name']); }
if (isset($_GET['photo_name'])){ $photo_name=veilig($_GET['photo_name']); }

// *** Read all photos from directory ***
$dir=$dataDb->tree_pict_path;
if (file_exists($dir)){
	$dh  = opendir($dir);
	while (false !== ($filename = readdir($dh))) {
		if (strtolower(substr($filename, -3)) == "jpg" OR strtolower(substr($filename, -3)) == "gif"){

			// *** Use search field (search for person) to show pictures ***
			$show_photo=true;

			if ($photo_name){
				$show_photo=false;
				$sql="SELECT * FROM ".veilig($_SESSION['tree_prefix'])."events
					WHERE event_kind='afbeelding' AND LOWER(event_event)='".strtolower($filename)."'";
				$afbqry=mysql_query($sql,$db);
				while($afbDb=mysql_fetch_object($afbqry)){
					$quicksearch=str_replace(" ", "%", $photo_name);
					$querie= "SELECT * FROM ".veilig($_SESSION['tree_prefix'])."person
						WHERE pers_gedcomnumber='".$afbDb->event_person_id."'
						AND CONCAT(pers_firstname,REPLACE(pers_prefix,'_',' '),pers_lastname) LIKE '%$quicksearch%'";
					$persoon=mysql_query($querie,$db);
					$personDb=mysql_fetch_object($persoon);
					if ($personDb){ $show_photo=true; }
				}
			}

			if ($show_photo AND substr($filename,0,6)!='thumb_'){
				$picture_array[]=$filename;
			}

		}
	}
}
// *** Order pictures by alphabet ***
@sort($picture_array);

// *** Calculate pages ***
$nr_pictures=count($picture_array);


$item=0; if (isset($_GET['item'])){ $item=$_GET['item']; }
$start=0; if (isset($_GET["start"])){ $start=$_GET["start"]; }

	$bladzijderegel=$language["main_page"];

	// "<="
	if ($start>1){
		$start2=$start-20;
		$berekend=($start-2)*$show_pictures;
		$bladzijderegel.= ' <a href="'.$uri_pad.
		"photoalbum.php?".
		"start=".$start2.
		"&amp;item=".$berekend.
		"&amp;show_pictures=".$show_pictures.
		"&amp;photo_name=".$photo_name.
		'">&lt;= </a>';
	}
	if ($start<=0){$start=1;}

	// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
	for ($i=$start; $i<=$start+19; $i++) {
		$berekend=($i-1)*$show_pictures;
		if ($berekend<$nr_pictures){
			if ($item==$berekend){
				$bladzijderegel.=  " <b>$i</b>";
			}
			else {
				$bladzijderegel.= ' <a href="'.$uri_pad.
				"photoalbum.php?".
				"start=".$start.
				"&amp;item=".$berekend.
				"&amp;show_pictures=".$show_pictures.
				"&amp;photo_name=".$photo_name.
				'"> '.$i.'</a>';
			}
		}
	}

	// "=>"
	$berekend=($i-1)*$show_pictures;
	if ($berekend<$nr_pictures){
		$bladzijderegel.= ' <a href="'.$uri_pad.
		"photoalbum.php?".
		"start=".$i.
		"&amp;item=".$berekend.
		"&amp;show_pictures=".$show_pictures.
		"&amp;photo_name=".$photo_name.
		'"> =&gt;</a>';
	}


echo '<div class="centreren">';
	echo $language["photo_nr_photos"];
	print '<select name="show_pictures" onChange="window.location=this.value">';
	for ($i=4; $i<=60; $i++) {
		print '<option value="'.$uri_pad.'photoalbum.php?
			show_pictures='.$i.'
			&amp;start=0&amp;item=0"';
		if ($i == $show_pictures) print ' selected="selected"';
		print ">".$i."</option>\n";
	}
	print '</select> ';

	echo $bladzijderegel;

	// *** Search by photo name ***
	echo ' <form method="post" action="photoalbum.php" style="display:inline">';
	print ' <input type="text" class="fonts" name="photo_name" value="'.$photo_name.'" size="20">';
	print ' <input class="fonts" type="submit" value="'.$language["main_search"].'">';
	print ' </form>';

echo '</div><br>';

// *** Show photos ***
for ($picture_nr=$item; $picture_nr<($item+$show_pictures); $picture_nr++){
	if (isset($picture_array[$picture_nr])){
		$filename=$picture_array[$picture_nr];
		$picture_text='';		// Text with link to person
		$picture_text2='';	// Text without link to person

		$sql="SELECT * FROM ".veilig($_SESSION['tree_prefix'])."events
			WHERE event_kind='afbeelding' AND LOWER(event_event)='".strtolower($filename)."'";
		$afbqry=mysql_query($sql,$db);

		while($afbDb=mysql_fetch_object($afbqry)){
			$persoon_cls = New persoon_cls;
			$persoon=mysql_query("SELECT * FROM ".veilig($_SESSION['tree_prefix'])."person WHERE pers_gedcomnumber='".$afbDb->event_person_id."'",$db);
			while(@$personDb=mysql_fetch_object($persoon)){
				$picture_text.='<a href="gezin.php?database='.$_SESSION['tree_prefix'].
					'&amp;id='.$personDb->pers_indexnr.
					'&amp;hoofdpersoon='.$personDb->pers_gedcomnumber.'">'.$persoon_cls->naam($personDb).'</a><br>';
				$picture_text2.=$persoon_cls->naam($personDb).'<br>';
			}
			$picture_text.=$afbDb->event_text.'<br>';
			$picture_text2.=$afbDb->event_text.'<br>';
		}

		// *** If possible show a thumb picture ***
		if (file_exists($dir.'thumb_'.$filename)){
			// *** Check if thumbnail fits ***
			list($width, $height) = getimagesize($dir.'thumb_'.$filename);
			$newwidth=$width;
			if ($width>180){
				$newwidth=180;
				//$factor=$width/$newwidth;
				//$newheight=$height/$factor;
			}

			$picture='<img src="'.$dir.'thumb_'.$filename.'" width="'.floor($newwidth).'" alt="'.$filename.'"></a>';
			//$picture='<img src="'.$dir.'thumb_'.$filename.'" height="'.$newheight.'" width="'.$newwidth.'"></a>';
		}
		else{
			// *** Formaat aanpassen ***
			list($width, $height) = getimagesize($dir.$filename);
			$newheight=120;
			$factor=$height/$newheight;
			$newwidth=$width/$factor;

			// *** If picture is too width, resize it ***
			if ($newwidth>180){
				$newwidth=180;

				$factor=$width/$newwidth;
				$newheight=$height/$factor;
			}

			// $picture='<img src="'.$dir.$filename.'" width="100"></a>';
			//$picture='<img src="'.$dir.$filename.'" height="120"></a>';
			//$picture='<img src="'.$dir.$filename.'" height="120" width="'.$newwidth.'"></a>';
			$picture='<img src="'.$dir.$filename.'" height="'.floor($newheight).'" width="'.floor($newwidth).'" alt="'.$filename.'"></a>';
		}

		echo '<div class="photobook">';
			// *** Show photo using the lightbox effect ***
			echo '<a href="'.$dir.$filename.'" rel="lightbox" title="'.$picture_text2.'">';
			echo $picture;
			echo '<div class="photobooktext">'.$picture_text.'</div>';
		echo '</div>';
	}
}

echo '<br clear="all"><br>';
echo '<div class="centreren">'.$bladzijderegel.'</div>';

include("footer.php");
?>
Return current item: HuMo-gen