<?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.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.php: changed 20/02/2006 1.0.2  
#                by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: slideshow.php,v 1.1 2006/10/03 09:03:40 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. 
###########################################################
if (!defined('IN_SAS'))
{
	die("Hacking attempt");
}

// use language file if available, use English by default:
if (file_exists("$cmsdir/languages/$language/sn_allbum/$language.php"))
{
	include ("$cmsdir/languages/$language/sn_allbum/$language.php");
}
else
{
	include ("$cmsdir/languages/EN/sn_allbum/EN.php");
}
$allbum_table = $dbprefix . "m_allbum";
$width = $sas_config['allbum_picsize_x']; //get width from allbum config.

if ($option == "slideshow")
{
	$query = "SELECT id, description, children FROM $allbum_table WHERE id = '$ID'";
	$result = mysql_query($query) or die(mysql_error() . $query);
}
else
{
	$query = "SELECT id, description, children FROM $allbum_table WHERE title = '$pagetitle'";
	$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);
	if (trim($children) == "")
	{
		print "<script language=\"Javascript\">
					   <!--
					   alert (\"" . $sas_lang['sn_allbum_empty_album'] . "\");	
					   //-->
					   </script>"; //return to the user edit window.
		exit;
	}
	$children = explode(",", $children);
	//print_r($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);
		if (substr($path, -1, 1) != "/")
		{
			$path = $path . "/";
		}
		$thumb = mysql_result($result, 0, 1);
		$descr = mysql_result($result, 0, 2);
		print "\n<a id=\"photo_urls_$i\" href=\"" . $cmsdir . "/" . $path . $thumb . "\"></a>";
		$title[$i] = $descr;
		$i++;
	}

	print "$allbum_descr<p>";
?>
<center>
<table width=550 border=0>
  <tr>
    <td  align="center" valign="top">

<script language="JavaScript" SRC="<?php echo $cmsdir ?>/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;
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 = 0;
var loop = 0;

<?php

	foreach ($title as $key => $value)
	{
		print "photo_captions[$key] = \"" . $value . "\";\n";
	}
?>
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 = document.TopForm.time.options[document.TopForm.time.selectedIndex].value * 1000;
	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 + " / " + photo_count + "] ");
}

</Script>


<form name="TopForm">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <td align="center">
<a href='#' onClick='stopOrStart(); return false;'><span id='stopOrStartText'><?php echo $sas_lang['sn_allbum_stop'] ?></span></a>
&nbsp;
<a href='#' onClick='changeDirection(); return false;'><span id='changeDirText'><?php echo $sas_lang['sn_allbum_backward'] ?></span></a>&nbsp;
<select name="time" size=1  onchange="reset_timer()" style="font-size=10px;">
<option value=1 > <?php echo $sas_lang['sn_allbum_seconds_1'] ?>
<option value=2 > <?php echo $sas_lang['sn_allbum_seconds_2'] ?>
<option value=3 > <?php echo $sas_lang['sn_allbum_seconds_3'] ?>
<option value=4 selected> <?php echo $sas_lang['sn_allbum_seconds_4'] ?>
<option value=5 > <?php echo $sas_lang['sn_allbum_seconds_5'] ?>
<option value=10 > <?php echo $sas_lang['sn_allbum_seconds_10'] ?>
<option value=15 > <?php echo $sas_lang['sn_allbum_seconds_15'] ?>
<option value=30 > <?php echo $sas_lang['sn_allbum_seconds_30'] ?>
<option value=45 > <?php echo $sas_lang['sn_allbum_seconds_45'] ?>
<option value=60 > <?php echo $sas_lang['sn_allbum_seconds_60'] ?>
</select>
    <script language="Javascript">
    /* show the blend select if appropriate */
	if (browserCanBlend) 
	{
	document.write('&nbsp;<select name="transitionType" size=1  onchange="change_transition()" style="font-size=10px;"> <option value=0 selected> Blend <option value=1 > Blinds <option value=2 > Checkerboard <option value=3 > Diagonal <option value=4 > Doors <option value=5 > Gradient <option value=6 > Iris <option value=7 > Pinwheel <option value=8 > Pixelate <option value=9 > Radial <option value=10 > Rain <option value=11 > Slide <option value=12 > Snow <option value=13 > Spiral <option value=14 > Stretch <option value=15 > RANDOM! </select> ');
	}
    
    </script>
    &nbsp;<?php echo $sas_lang['sn_allbum_continue'] ?>: <input type="checkbox" name="loopCheck"  onclick='toggleLoop();'>
    </span>
    </td>
  </tr>
</table>

<br>
<div align="center">
<table width=1% border=0 cellspacing=0 cellpadding=0>
  <tr>
    <td>
    <script language="JavaScript">
    document.write("<td><img width=<?php echo $width ?> border=0 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>
<?php

}
?>
