<?php
/**
 * List file in a dir
 * 
 * @copyright Grummfy (http://www.grummfy.com), LGPL licence
 * @version 1.0.0 - october 2006
 */
class ListDir
{
	var $root;

	/**
	 * Constructor
	 *
	 * @param string $root the root dir.
	 * @return ListDir
	 */
	function ListDir($root)
	{
		$this->root = $root;
	}

	/**
	 * Liste files with the extension $ext
	 *
	 * @param string $dir the repertory to lit
	 * @param string $ext the filter on the extension
	 * @return array the files who were found
	 */
	function listerfileextension($dir, $ext)
	{
		if(!is_dir($this->root . $dir))
		{
			die ('error : the dir (' . $this->root . $dir . ') isn\'t a dir ;(');
		}

		return glob($this->root . $dir . '/*' . $ext);
	}
}

if (!isset($_POST['submit']))
{
	$ld = new ListDir('./');
	// list image/test repertory.... with .jpg file
	$files = $ld->listerfileextension('images/test', '.jpg');
	echo '<form action="./dirtogallerie.php" method="post">Choice images and comment for the slideshow';
	$i = 0;
	foreach ($files as $file)
	{
		echo <<<TMP
		#<br />
		<a target="_blank" href="{$file}">Image to add in the slideshow</a><input type="hidden" name="image[]" value="{$file}" /><br />
		Link to a file : <input type="text" name="link[]" value="{$file}" /><br />
		Image's title : <input type="text" name="title[]" value="Image : {$file}" /><br />
		Descripton : <input type="text" name="desc[]" value="{$file}" /><br />
TMP;
	}
	echo '<button type="submit" name="submit">OK</button></form>';
}
else
{
	echo 'Code to copy : <pre>';
	$str = '<script type="text/javascript">
		var mySlideData = new Array();' . "\n";
	$totalimage = count($_POST['image']) - 1;
	for($i = 0; $i <= $totalimage; $i++)
	{
		$str .= <<<JSS
			mySlideData[{$i}] = new Array(
				'{$_POST['image'][ $i ]}',
				'{$_POST['link'][ $i ]}',
				'{$_POST['title'][ $i ]}',
				'{$_POST['desc'][ $i ]}'
			);
JSS;
	}
	$str .= 'countArticle = ' . $totalimage . '</script>';
	echo htmlspecialchars($str, ENT_QUOTES);
	echo '</pre>';
}


?>