<?php
//define this module's name and path
$mn = basename(__FILE__, ".php");
include("modules/modules.php");

/*
Available variables:
All system classes
All request variables
$p (the template path)
$mp (the module path)
$sufixID (id sufix for this module's divs)
*/

$marginTop = ($moduleParameters['marginTop'] == "__EMPTY__" || empty($moduleParameters['marginTop'])) ? 0 : $moduleParameters['marginTop'];
$marginRight = ($moduleParameters['marginRight'] == "__EMPTY__" || empty($moduleParameters['marginRight'])) ? 0 : $moduleParameters['marginRight'];
$marginBottom = ($moduleParameters['marginBottom'] == "__EMPTY__" || empty($moduleParameters['marginBottom'])) ? 0 : $moduleParameters['marginBottom'];
$marginLeft = ($moduleParameters['marginLeft'] == "__EMPTY__" || empty($moduleParameters['marginLeft'])) ? 0 : $moduleParameters['marginLeft'];
$paddingTop = ($moduleParameters['paddingTop'] == "__EMPTY__" || empty($moduleParameters['paddingTop'])) ? 0 : $moduleParameters['paddingTop'];
$paddingRight = ($moduleParameters['paddingRight'] == "__EMPTY__" || empty($moduleParameters['paddingRight'])) ? 0 : $moduleParameters['paddingRight'];
$paddingBottom = ($moduleParameters['paddingBottom'] == "__EMPTY__" || empty($moduleParameters['paddingBottom'])) ? 0 : $moduleParameters['paddingBottom'];
$paddingLeft = ($moduleParameters['paddingLeft'] == "__EMPTY__" || empty($moduleParameters['paddingLeft'])) ? 0 : $moduleParameters['paddingLeft'];
$useModuleContainer = ($moduleParameters['useModuleContainer'] == "__EMPTY__" || empty($moduleParameters['useModuleContainer'])) ? 0 : (int)$moduleParameters['useModuleContainer'];
$widthInPixels = ($moduleParameters['widthInPixels'] == "__EMPTY__" || empty($moduleParameters['widthInPixels'])) ? null : (int)$moduleParameters['widthInPixels'];

if (empty($marginTop) && empty($marginRight) && empty($marginBottom) && empty($marginLeft)) {
    $Mmargin = "0";
} else {
    $Mmargin = $marginTop . " " . $marginRight . " " . $marginBottom . " " . $marginLeft . " ";
}
if (empty($paddingTop) && empty($paddingRight) && empty($paddingBottom) && empty($paddingLeft)) {
    $Mpadding = "0";
} else {
    $Mpadding = $paddingTop . " " . $paddingRight . " " . $paddingBottom . " " . $paddingLeft . " ";
}


$RelatedArticlesHeader = $moduleParameters["RelatedArticlesHeader"];
$maxArticles = $moduleParameters["maxArticles"];
$displayTags = ($moduleParameters['displayTags'] == "__EMPTY__" || empty($moduleParameters['displayTags'])) ? null : (int)$moduleParameters['displayTags'];
$displayRelatedArticles = ($moduleParameters['displayRelatedArticles'] == "__EMPTY__" || empty($moduleParameters['displayRelatedArticles'])) ? null : (int)$moduleParameters['displayRelatedArticles'];
$querySymbol = (preg_match('/\?/', $sef->url("index.php", false))) ? "&" : "?";


if ($useModuleContainer){
?>
<div id="<?php echo $mn . $sufixID; ?>" class="responsive_float" data-editable="editable">
    <?php
    }
    ?>

    <style type="text/css">
        <?php
        if($useModuleContainer ){
            ?>
        #<?php echo $mn.$sufixID;?>{
	<?php 
	$alignRule = ($moduleParameters['moduleAlign'] == "center") ? "text-align" : "float";
	echo $alignRule.": ".$moduleParameters['moduleAlign'].";".PHP_EOL;
	?>
	margin : <?php echo $Mmargin;?>;
	padding : <?php echo $Mpadding;?>;
<?php
if($widthInPixels){
	?>
	width: <?php echo $widthInPixels;?>px;
	<?php 
}	

if($moduleParameters['moduleAlign'] && $moduleParameters['moduleHR']){ // there are system parameters...

if($moduleParameters['moduleHR'] == "top" || $moduleParameters['moduleHR'] == "bottom"){
?>
	border-<?php echo $moduleParameters['moduleHR'];?> : 1px solid black;
<?php 
}
}
?>
}

        <?php
        }
        ?>
    </style>
    <div style="text-align:left">
        <?php
        if ($displayTags) {
            $tags = $content->getTags($section, $id, $langID);
            if ($tags) {
                ?>
                <span class="tags_subheader">Tags: </span>
                <?php
            }
            foreach ($tags as $tag) {
                ?>
                <a href="<?php echo $sef->url("index.php?section=$section&view=list", false) . $querySymbol . "tag=" . $tag; ?>" class="rainbow tag_label"><?php echo $tag; ?></a>
                <?php
            }
        }
        if ($displayRelatedArticles) {
            $relatedContent = $content->getRelatedContent($section, $id, $langID);
            if (is_array($relatedContent)) {
                ?>
                <div class="rainbow_color related_articles">
                    <h3><?php echo t($RelatedArticlesHeader); ?></h3>
                    <ul>
                        <?php
                        foreach ($relatedContent as $thisItem) {
                            ?>
                            <li><a href="<?php $sef->url("index.php?section=" . $section . "&view=node&id=" . $thisItem->id . ""); ?>"><?php echo $thisItem->title; ?></a></li>
                            <?php
                        }
                        ?>
                    </ul>
                </div>
                <?php
            }
        }
        ?>
    </div>
    <?php
    if ($useModuleContainer){
    ?>
</div>
<?php
}
?>
