<?php

/**
 * timelinestyle - timeline configuration 
 * 
 * @package timelinestyle
 * @author ColdTrick IT Solutions
 * @copyright Coldtrick IT Solutions 2009
 * @link http://www.coldtrick.com/
 */
gatekeeper();
$current_user = $_SESSION['user']->getGUID();
$currentConfig = get_timeline_style_from_metadata($current_user, 'timelinestyletimeline');
global $CONFIG;
$wallpaper_path = "mod/timeline_theme/graphics/wallpapers";
$imageArray = array();
$dir_handle = opendir($CONFIG->path . $wallpaper_path);
while (($file = readdir($dir_handle)) !== false) {
    if ($file != '.' && $file != '..' && !is_dir($dir . $entry)) {
        $dotPosition = strrpos($file, ".");
        if ($dotPosition) {
            $shortFileName = substr($file, 0, $dotPosition);
            $imageArray[elgg_echo($shortFileName)] = $wallpaper_path . "/" . str_replace(" ", "%20", $file);
        }
    }
}
$body = "<br />";
$body .= "<table id='gallery'><tr>";
$i = 0;
// own image
if ($currentConfig["timeline-image"]) {
    //colors configured
    ?>
		<style type="text/css" title="timelinestylesheet">
		/* timelinestylecolors */
		<?php 
    foreach ($currentConfig as $key => $value) {
        $rowData = explode("|", $key);
        if ($rowData[0] != "") {
            echo $rowData[0] . " { \n" . $rowData[1] . ": " . $value . $important . ";\n }\n";
        }
    }
    ?>
		</style>
		<?php 
}
$currentConfig = get_timeline_style_from_metadata(elgg_get_page_owner_guid(), 'timelinestyletimeline');
if ($currentConfig) {
    // background configured
    ?>
			<style type="text/css" title="timelinestylesheet">
				/* timelinestylebackground */
				body {
					<?php 
    foreach ($currentConfig as $key => $value) {
        if ($key == 'timeline-image') {
            echo $key . ": url(" . $CONFIG->wwwroot . $value . ")" . $important . ";\n";
        } else {
            echo $key . ": " . $value . $important . ";\n";
        }
    }
    ?>