<?php
/**
 * @package Flatnux_module_textandphotos
 * @author Alessandro Vernassa <speleoalex@gmail.com>
 * @copyright Copyright (c) 2012
 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License
 * 
 */
defined('_FNEXEC') or die('Restricted access');
global $_FN;
$tablename = "TANDD_{$_FN['mod']}";
//--------------------------------init tables---------------------------------->
TANDD_InitTables();
//--------------------------------init tables----------------------------------<
//----------------------------------DOWNLOAD FILE  ---------------------------->
$downloadfile = FN_GetParam("downloadfile", $_GET, "flat");
if ($downloadfile != "")
{

    if (file_exists($downloadfile) && preg_match("#^{$_FN['datadir']}/{$_FN['database']}/{$tablename}/#s", $downloadfile))
    {
        FN_SaveFile(file_get_contents($downloadfile), basename($downloadfile));
        die();
    }
}
//----------------------------------DOWNLOAD FILE  ----------------------------<

$str = FN_HtmlStaticContent("sections/{$_FN['mod']}");
$strphotos = TANDD_StrPhotos();

$str.= $strphotos;

echo $str;
/**
 *
 * @global string $_FN
 * @return string 
 */
function TANDD_StrPhotos()
{
    global $_FN;
    $html = "";
    $tablename = "TANDD_{$_FN['mod']}";
    $Table = FN_XmlTable($tablename);
    $photos = $Table->GetRecords();
    if (is_array($photos))
        foreach ($photos as $photo)
        {
            $photopath = $Table->getFilePath($photo, "photo");
            $html .="<a  title=\"{$photo['title']}\"  rel=\"jqlightbox\" href=\"$photopath\"><img height=\"90px\" title=\"{$photo['title']}\" alt=\"{$photo['title']}\" src=\"$photopath\" /></a> ";
        }
    return $html;
}
/**
 *
 * @global string $_FN 
 */
function TANDD_InitTables()
{
    global $_FN;
    $tablename = "TANDD_{$_FN['mod']}";
    if (!file_exists("{$_FN['datadir']}/fndatabase/{$tablename}.php"))
    {
        $str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<?php exit(0);?>
<tables>
	<field>
		<name>unirecid</name>
		<primarykey>1</primarykey>
		<extra>autoincrement</extra>
		<frm_show>0</frm_show>
	</field>
	<field>
		<name>position</name>
		<frm_i18n>position</frm_i18n>
	</field>
	<field>
		<name>title</name>
		<frm_i18n>title</frm_i18n>
	</field>
	<field>
		<name>photo</name>
		<frm_i18n>photo</frm_i18n>
		<thumb_listheight>64</thumb_listheight>
		<type>image</type>
		<thumbsize>64</thumbsize>
	</field>
</tables>
";
        FN_Write($str, "{$_FN['datadir']}/{$_FN['database']}/{$tablename}.php", "w");
    }
}
?>
