<?php

###############################################################################
#                      ALLbum-1.0.0: slideshow.php                            #
#                (SAS maintainer interface component)                         #
#                                                                             #
# ALLbum is a module for the Content Management System                        #
# "Site@School"  (http://siteatschool.sourceforge.net).                       #
#                                                                             # 
# Slideshow_full.php is addition to the allbum module, javascript came from:  #
# http://sourceforge.net/projects/gallery/                                    #
#                                                                             #
# ALLbum is copyrighted by OBS Rosa Boekdrukker, Amsterdam, The Netherlands   #
# (http://www.rosaboekdrukker.nl)                                             #
# ALLbum is licenced by GNU General Public Licence                            #
###############################################################################
# slideshow_full.php: changed 22/08/2006 2.4.03                               #  
#                by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: slideshow_full.php,v 1.2 2006/10/15 19:08:54 fstuurman Exp $            #
###############################################################################
#                                                                             #
#                            LICENCE INFORMATION                              #
#                                                                             #
# Copyright (c) 2003-2004, OBS Rosa Boekdrukker, Amsterdam, The Netherlands.  #
#                                                                             #
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. #
###############################################################################
$speed = 4;

if (IsSet ($_GET['loc_id']))
{
	$loc_id = intval($_GET['loc_id']);
}

include ("../configuration/database.inc.php"); //connect to mysql
mysql_connect("$db_server", "$db_username", "$db_password");
mysql_select_db("$db_name");

$scripts_table = $dbprefix . "m_scripts";

if (IsSet ($_GET['album_name']))
{
	$album_name = $_GET['album_name'];
	$album_name = htmlspecialchars(strip_tags($album_name)); //remove html tags
}
else
{
	$query = "SELECT value1 FROM $scripts_table WHERE active = '1' AND loc_id = '" . $loc_id . "'";
	$result = mysql_query($query) or die_script(mysql_error());
	$RecordCount = mysql_num_rows($result);
	if ($RecordCount > 0)
	{
		$album_name = mysql_result($result, 0, 0); //get the page to display
	}
}

if (IsSet ($_GET['speed']))
{
	$speed = $_GET['speed'];
}
else
{
	$query = "SELECT value2 FROM $scripts_table WHERE active = '1' AND loc_id = '" . $loc_id . "'";
	$result = mysql_query($query) or die_script(mysql_error());
	$RecordCount = mysql_num_rows($result);
	if ($RecordCount > 0)
	{
		$speed = mysql_result($result, 0, 0); //get the speed
	}
	else
	{
		$speed = 4;
	}
	unset ($query);
	unset ($result);
}
if (IsSet ($speed))
{
	$s = $speed * 1000;
}
else
{
	$s = 4000;
}

if (IsSet ($_GET['t']))
{
	$t = $_GET['t'];
}
else
{
	$t = 0;
}

if (IsSet ($_GET['w']))
{
	$width = "width=" . $_GET['w'];
}
else
{
	$query = "SELECT value3 FROM $scripts_table WHERE active = '1' AND loc_id = '" . $loc_id . "'";
	$result = mysql_query($query) or die_script(mysql_error());
	$RecordCount = mysql_num_rows($result);
	if ($RecordCount > 0)
	{
		$width = mysql_result($result, 0, 0); //get the width
	}

	unset ($query);
	unset ($result);
	$width = "width=" . $width;
}

$allbum_table = $dbprefix . "m_allbum";

$query = "SELECT id, description, children FROM $allbum_table WHERE title = '" . $album_name . "'";
$result = mysql_query($query) or die(mysql_error() . $query);
$RecordCount = mysql_num_rows($result);
if ($RecordCount == 0)
{
	print $sas_lang['sn_allbum_no_linkpage'];
}
else
{
	$allbum_id = mysql_result($result, 0, 0);
	$allbum_descr = mysql_result($result, 0, 1);
	$sort_order = mysql_result($result, 0, 2);
	$sort_array = explode(",", $sort_order);

	$query = "SELECT children FROM $allbum_table WHERE id='" . $allbum_id . "'";
	$result = mysql_query($query) or die(mysql_error() . $query);
	$children = mysql_result($result, 0);
	$children = explode(",", $children);

	$i = 1;
	$count = count($sort_array);
	foreach ($sort_array as $value)
	{
		$query = "SELECT path, thumb, description FROM $allbum_table WHERE id = '" . $value . "'";
		$result = mysql_query($query) or die(mysql_error() . $query);
		$path = mysql_result($result, 0, 0);
		$thumb = mysql_result($result, 0, 1);
		$descr = mysql_result($result, 0, 2);
		print "\n<a id=\"photo_urls_$i\" href=\"../" . $path . "/" . $thumb . "\"></a>";
		$title[$i] = $descr;
		$i++;
	}
?>

<script language="JavaScript" SRC="../modules/sn_allbum/client_sniff.js">
 </script>
<script language="JavaScript">
var timer; 
var current_location = 1;
var next_location = 1; 
var pics_loaded = 0;
var onoff = 0;
var direction = 1;
var timeout_value = 4;
var images = new Array;
var photo_urls = new Array;
var photo_captions = new Array;
var transitionNames = new Array;
var transitions = new Array;
var current_transition = <?php echo $t ?>;
var loop = 1;

transitions[0] = "progid:DXImageTransform.Microsoft.Fade(duration=1)";
transitions[1] = "progid:DXImageTransform.Microsoft.Blinds(Duration=1,bands=20)";
transitions[2] = "progid:DXImageTransform.Microsoft.Checkerboard(Duration=1,squaresX=20,squaresY=20)";
transitions[3] = "progid:DXImageTransform.Microsoft.Strips(Duration=1,motion=rightdown)";
transitions[4] = "progid:DXImageTransform.Microsoft.Barn(Duration=1,orientation=vertical)";
transitions[5] = "progid:DXImageTransform.Microsoft.GradientWipe(duration=1)";
transitions[6] = "progid:DXImageTransform.Microsoft.Iris(Duration=1,motion=out)";
transitions[7] = "progid:DXImageTransform.Microsoft.Wheel(Duration=1,spokes=12)";
transitions[8] = "progid:DXImageTransform.Microsoft.Pixelate(maxSquare=10,duration=1)";
transitions[9] = "progid:DXImageTransform.Microsoft.RadialWipe(Duration=1,wipeStyle=clock)";
transitions[10] = "progid:DXImageTransform.Microsoft.RandomBars(Duration=1,orientation=vertical)";
transitions[11] = "progid:DXImageTransform.Microsoft.Slide(Duration=1,slideStyle=push)";
transitions[12] = "progid:DXImageTransform.Microsoft.RandomDissolve(Duration=1,orientation=vertical)";
transitions[13] = "progid:DXImageTransform.Microsoft.Spiral(Duration=1,gridSizeX=40,gridSizeY=40)";
transitions[14] = "progid:DXImageTransform.Microsoft.Stretch(Duration=1,stretchStyle=push)";
transitions[15] = "special case";
var transition_count = 15;
var photo_count = <?php echo $count ?>; 

// Browser capabilities detection ---
// - assume only IE4+ and NAV6+ can do image resizing, others redirect to low 
if (is_ie4up || is_opera5up || is_nav6up) {
    //-- it's all good ---
} else {
    //-- any other browser we go low-tech ---
    document.location = slideShowLow;
}

// - IE5.5 and up can do the blending transition.
var browserCanBlend = (is_ie5_5up);

function stopOrStart() {
    if (onoff) {
	stop();
    } else {
	play();
    }
}

function toggleLoop() {
    if (loop) {
	loop = 0;
    } else {
	loop = 1;
    }
}

function changeElementText(id, newText) {
    element = document.getElementById(id);
    element.innerHTML = newText;
}

function stop() {
//    changeElementText("stopOrStartText", "<?php echo $sas_lang['sn_allbum_play'] ?>");
    onoff = 0;
    status = "<?php echo $sas_lang['sn_allbum_status_stopped'] ?>" ;    
    clearTimeout(timer);
}

function play() {
//    changeElementText("stopOrStartText","<?php echo $sas_lang['sn_allbum_stop'] ?>");

    onoff = 1;
status = "<?php echo $sas_lang['sn_allbum_status_running'] ?>" ;    go_to_next_photo();
}

function changeDirection() {
    if (direction == 1) {
	direction = -1;
//	changeElementText("changeDirText", "<?php echo $sas_lang['sn_allbum_forward'] ?>");
    } else {
	direction = 1;
//	changeElementText("changeDirText", "<?php echo $sas_lang['sn_allbum_backward'] ?>");
    }
    preload_next_photo();

}

function change_transition() {
    current_transition = document.TopForm.transitionType.selectedIndex;
}

function preload_complete() {
}

function reset_timer() {
    clearTimeout(timer);
    if (onoff) {
	timeout_value =  <?php echo $s ?>;
	timer = setTimeout('go_to_next_photo()', timeout_value);
    }
}

function wait_for_current_photo() {

    /* Show the current photo */
    if (!show_current_photo()) {

	/*
	 * The current photo isn't loaded yet.  Set a short timer just to wait
	 * until the current photo is loaded.
	 */
	status= "Picture is loading...(" + current_location + " of" + photo_count + ") Please Wait...";	clearTimeout(timer);
	timer = setTimeout('wait_for_current_photo()', 500);
	return 0;
    } else {
   status = "The Slidshow is running ..." ;	preload_next_photo();
	reset_timer();
    }
}

function go_to_next_photo() {
    /* Go to the next location */
    current_location = next_location;

    /* Show the current photo */
    if (!show_current_photo()) {
	wait_for_current_photo();
	return 0;
    }

    preload_next_photo();
    reset_timer();
}

function preload_next_photo() {
    
    /* Calculate the new next location */
    next_location = (parseInt(current_location) + parseInt(direction));
    if (next_location > photo_count) {
	next_location = 1;
	if (!loop) {
	    stop();
	}
    }
    if (next_location == 0) {
        next_location = photo_count;
	if (!loop) {
	    stop();
	}
    }
    
    /* Preload the next photo */
    preload_photo(next_location);
}

function show_current_photo() {

    /*
     * If the current photo is not completely loaded don't display it.
     */
    if (!images[current_location] || !images[current_location].complete) {
	preload_photo(current_location);
	return 0;
    }
    
    /* transistion effects */
    if (browserCanBlend){
	var do_transition;
	if (current_transition == (transition_count)) {
	    do_transition = Math.floor(Math.random() * transition_count);
	} else {
	    do_transition = current_transition;
	}
	document.images.slide.style.filter=transitions[do_transition];
	document.images.slide.filters[0].Apply();
    }
    document.slide.src = images[current_location].src;
//    setCaption(photo_captions[current_location]);

    if (browserCanBlend) {
	document.images.slide.filters[0].Play();
    }

    return 1;
}

function preload_photo(index) {

    /* Load the next picture */
    if (pics_loaded < photo_count) {

	/* not all the pics are loaded.  Is the next one loaded? */
	if (!images[index]) {
	    images[index] = new Image;
	    images[index].onLoad = preload_complete();
	    images[index].src = document.getElementById("photo_urls_" + index).href;
	    pics_loaded++;
	}
    } 
}

function setCaption(text) {
    changeElementText("caption", text + "<br>[" + current_location + " of " + photo_count + "] ");
}

</Script>
<!DOCTYPE  HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html> 
<head>
  <title>SlideShow</title>
<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 bgcolor="#FFFFFF">
<center>
<table width=100% border=0>
  <tr>
    <td  align="center" valign="top">
<form name="TopForm">

<div align="center">

<table width=100% border=0 cellspacing=0 cellpadding=0>
  <tr>
    <td>'
    <script language="JavaScript">
    document.write("<td><img border=0 <?php echo $width ?> src="+document.getElementById("photo_urls_1").href+" name=slide></td>");
    </script>
  </tr>
</table>
<br>

<script language="Javascript">
/* show the caption */
document.write("<div class='desc' id='caption'></div>");

/* Load the first picture */
//setCaption(photo_captions[1]);
preload_photo(1);

/* Start the show. */
play();

</script>
</div>
</form>
    </td>
  </tr>
</table>
</body>
</html>

<?php

}
?>
