<?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'];
$showTitle = ((int)$moduleParameters['showTitle'] > 0) ? true : false;

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 . " ";
}

$responsive = ($moduleParameters['responsive'] == "__EMPTY__" || empty($moduleParameters['responsive'])) ? false : true;

if ($useModuleContainer){
?>
<div id="<?php echo $mn . $sufixID; ?>" data-editable="editable" class="responsive_float">
    <?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
}
$responsive_width = ($responsive) ? 534 : 276;
?> #ody_calendar_container {
            width: 100%;
            max-width: <?php echo $responsive_width;?>px;
            display: block;
            margin: auto;
        }

        #calendar_header {
            height: <?php echo ($showTitle) ? "84px" : "auto";?>;
            background-color: #<?php echo $moduleParameters['headerBackground'];?>;
        }

        #loadDate {
            background-color: #<?php echo $moduleParameters['eventsListBackground'];?>;
        }

        .arrow_right {
            border-left: 15px solid #<?php echo $moduleParameters['buttonBackground'];?>;
        }

        .arrow_left {
            border-right: 15px solid #<?php echo $moduleParameters['buttonBackground'];?>;
        }

        .arrow_right:hover {
            border-left: 15px solid #<?php echo $moduleParameters['buttonBackgroundHover'];?>;
        }

        .arrow_left:hover {
            border-right: 15px solid #<?php echo $moduleParameters['buttonBackgroundHover'];?>;
        }

        #ody_calendar .day span {
            display: none;
            position: absolute;
            top: -2px;
            left: 16px;
            font-family: Arial, sans-serif;
            font-size: 18px;
            color: #<?php echo $moduleParameters['eventsBackground'];?>;
            text-shadow: none !important;
        }

        #eventsBoard {
            height: 130px;
            position: relative;
            padding-top: 7px;
            background: #<?php echo $moduleParameters['eventsListBackground'];?>;
            z-index: 2;
            overflow: hidden;
        }

        #eventsShadow {
            height: 10px;
            width: 100%;
            background: url(<?php echo $mp;?>images/shadow.png) center top no-repeat;
            z-index: 3;
            margin-top: -8px;
            position: absolute;
        }

        .eventButton {
            display: block;
            min-height: 15px;
            font-family: Arial, sans-serif;
            font-size: 12px;
            font-weight: bold;
            border-bottom: 1px solid grey;
            color: #<?php echo $moduleParameters['eventsListColor'];?> !important;
        <?php
        $useEventsListTextShadow = ($moduleParameters['useEventsListTextShadow'] == "__EMPTY__" || empty($moduleParameters['useEventsListTextShadow'])) ? 0 : (int)$moduleParameters['useEventsListTextShadow'];
        if(!empty($useEventsListTextShadow)){
        ?> text-shadow: 1px 1px 1px rgba(0, 0, 0, 1);
        <?php
        }
        ?> text-decoration: none;
            padding: 12px 10px 12px 10px;
            text-align: left;
            -webkit-backface-visibility: hidden;
        }

        .eventButton:hover {
            color: #<?php echo $moduleParameters['eventsListColorHover'];?> !important;
            background-color: #<?php echo $moduleParameters['eventsListBackgroundHover'];?> !important;
        }

        #changeDate {
            width: 100%;
            height: 100%;
            background-color: #<?php echo $moduleParameters['headerBackground'];?>;
            position: absolute;
            top: -42px;
            left: 0;
        }

        .classicSelected {
            color: #ffffff !important;
            text-shadow: 1px 1px 2px rgba(150, 150, 150, 1);
            background-color: #<?php echo $moduleParameters['buttonBackground'];?> !important;
        }

        .classicWithEventSelected {
            color: #ffffff !important;
            text-shadow: 1px 1px 2px rgba(150, 150, 150, 1);
            background: #<?php echo $moduleParameters['eventsBackground'];?> !important;
        }

        .today, .todayWithEvent {
            color: #ffffff !important;
            text-shadow: 1px 1px 2px rgba(150, 150, 150, 1);
            background: #<?php echo $moduleParameters['headerBackground'];?> url(<?php echo $mp;?>images/day_shadow.png) right top no-repeat !important;
        }

        .todaySelected {
            color: #ffffff !important;
            text-shadow: 1px 1px 2px rgba(150, 150, 150, 1);
            background: #<?php echo $moduleParameters['buttonBackground'];?> url(<?php echo $mp;?>images/day_shadow.png) right top no-repeat !important;
        }

        .todayWithEventSelected {
            color: #ffffff !important;
            text-shadow: 1px 1px 2px rgba(0, 0, 0, .5);
            background: #<?php echo $moduleParameters['eventsBackground'];?> url(<?php echo $mp;?>images/day_shadow.png) right top no-repeat !important;
        }

    </style>
    <!--[if gte IE 9]>
    <style type="text/css">
        .gradient {
            filter: none;
        }
    </style>
    <![endif]-->
    <script type="text/javascript">

        function getCalendarData(mode, selectedDay, currentMonth, currentYear) {
            jQuery.ajax({
                type: "POST",
                url: "<?php echo $mp;?>getmonth.php",
                data: "startframe=1&mode=" + mode + "&selectedDay=" + selectedDay + "&currentMonth=" + currentMonth + "&currentYear=" + currentYear + "&langID=<?php echo $langID;?>",
                async: false,
                success: function (response) {
                    //console.log(response);
                    odyssey.response = response;
                }
            });
            return parseQueryData(odyssey.response);
        }

        function getEvents() {
            odyssey.eventsData = getCalendarData("events", odyssey.selectedDay, odyssey.currentMonth, odyssey.currentYear);
            var numOfEvents = odyssey.eventsData.numOfEvents;
            $("#eventsBoard .eventButton").remove();
            if (numOfEvents > 0) {
                $('#noEvents').hide();
                for (var n = 1; n <= numOfEvents; n++) {
                    var btn = odyssey.eventButton.clone().appendTo("#eventButtons");
                    var title = decodeURIComponent(eval("odyssey.eventsData.title" + n));
                    var url = decodeURIComponent(eval("odyssey.eventsData.url" + n));
                    title = title.replace(/\+/g, " ");
                    btn.html(title);
                    btn.attr("href", url);
                    btn.attr("target", "<?php echo $moduleParameters['linkTarget'];?>");
                }
                scrollEvents();
            } else {
                $('#noEvents').show();
            }
        }
    </script>
    <div id="ody_calendar_container">
        <div id="ody_calendar">
            <div id="calendar_header">
                <?php
                if ($showTitle) {
                    ?>
                    <div id="calendar_title"><?php echo t("Ημερολόγιο"); ?></div>
                    <?php
                }
                ?>
                <div id="calendar_controls" class="gradient">
                    <div id="months_navigation">
                        <a class="arrow_left" href="javascript:odyssey.selectedDay=null; prevMonth()"></a>
                        <a id="month_year" href="javascript:showDateChanger()"></a>
                        <a class="arrow_right" href="javascript:odyssey.selectedDay=null; nextMonth()"></a>
                        <div id="changeDate">
                            <select id="month">
                                <option value="1"><?php echo t("Ιανουάριος"); ?></option>
                                <option value="2"><?php echo t("Φεβρουάριος"); ?></option>
                                <option value="3"><?php echo t("Μάρτιος"); ?></option>
                                <option value="4"><?php echo t("Απρίλιος"); ?></option>
                                <option value="5"><?php echo t("Μάιος"); ?></option>
                                <option value="6"><?php echo t("Ιούνιος"); ?></option>
                                <option value="7"><?php echo t("Ιούλιος"); ?></option>
                                <option value="8"><?php echo t("Αύγουστος"); ?></option>
                                <option value="9"><?php echo t("Σεπτέμβριος"); ?></option>
                                <option value="10"><?php echo t("Οκτώβριος"); ?></option>
                                <option value="11"><?php echo t("Νοέμβριος"); ?></option>
                                <option value="12"><?php echo t("Δεκέμβριος"); ?></option>
                            </select>
                            <select id="year"></select>
                            <input id="loadDate" type="button" value="OK" onclick="loadDate()">
                        </div>
                    </div>
                    <div id="days_shortcuts">
                        <span><?php echo t("Δευ"); ?></span>
                        <span><?php echo t("Τρι"); ?></span>
                        <span><?php echo t("Τετ"); ?></span>
                        <span><?php echo t("Πεμ"); ?></span>
                        <span><?php echo t("Παρ"); ?></span>
                        <span><?php echo t("Σαβ"); ?></span>
                        <span><?php echo t("Κυρ"); ?></span>
                    </div>
                </div>
            </div>
            <div id="dates">
                <div id="previous_month">
                    <?php
                    for ($n = 1; $n <= 6; $n++) {
                        for ($m = 1; $m <= 7; $m++) {
                            ?>
                            <div class="day" data-pos="<?php echo $n . "_" . $m; ?>" onclick="handleClick($(this))"><span>•</span></div>
                            <?php
                        }
                    }
                    ?>
                </div>
                <div id="current_month">
                    <?php
                    for ($n = 1; $n <= 6; $n++) {
                        for ($m = 1; $m <= 7; $m++) {
                            ?>
                            <div class="day" data-pos="<?php echo $n . "_" . $m; ?>" onclick="handleClick($(this))"><span>•</span></div>
                            <?php
                        }
                    }
                    ?>
                </div>
                <div id="next_month">
                    <?php
                    for ($n = 1; $n <= 6; $n++) {
                        for ($m = 1; $m <= 7; $m++) {
                            ?>
                            <div class="day" data-pos="<?php echo $n . "_" . $m; ?>" onclick="handleClick($(this))"><span>•</span></div>
                            <?php
                        }
                    }
                    ?>
                </div>
            </div>
            <div id="eventsBoard">
                <div id="eventsShadow"></div>
                <div id="noEvents"> </div>
                <div id="eventButtons"></div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        jQuery().ready(function () {
            getToday();
            for (var y = 1980; y <= 2099; y++) {
                var opt = $("<option></option>");
                opt.attr("value", y);
                opt.html(y);
                if (odyssey.currentDateYear == y) opt.attr("selected", "selected");
                $('#year').append(opt);
            }
            for (var m = 1; m <= 12; m++) {
                if (m == odyssey.currentDateMonth) $('#month').val(m);
            }
            var month1 = '<?php echo t("Ιανουάριος");?>';
            var month2 = '<?php echo t("Φεβρουάριος");?>';
            var month3 = '<?php echo t("Μάρτιος");?>';
            var month4 = '<?php echo t("Απρίλιος");?>';
            var month5 = '<?php echo t("Μάιος");?>';
            var month6 = '<?php echo t("Ιούνιος");?>';
            var month7 = '<?php echo t("Ιούλιος");?>';
            var month8 = '<?php echo t("Αύγουστος");?>';
            var month9 = '<?php echo t("Σεπτέμβριος");?>';
            var month10 = '<?php echo t("Οκτώβριος");?>';
            var month11 = '<?php echo t("Νοέμβριος");?>';
            var month12 = '<?php echo t("Δεκέμβριος");?>';
            odyssey.monthNames = new Array("", month1, month2, month3, month4, month5, month6, month7, month8, month9, month10, month11, month12);
            odyssey.firstRun = 1;
            odyssey.eventHTML = "<span>•</span>";
            odyssey.eventButton = $('<a class="eventButton" href="#"></a>');
            odyssey.headerBackground = "<?php echo $moduleParameters['headerBackground'];?>";
            odyssey.buttonBackground = "<?php echo $moduleParameters['buttonBackground'];?>";
            odyssey.buttonBackgroundHover = "<?php echo $moduleParameters['buttonBackgroundHover'];?>";
            odyssey.eventsBackground = "<?php echo $moduleParameters['eventsBackground'];?>";
            odyssey.eventsListBackground = "<?php echo $moduleParameters['eventsListBackground'];?>";
            odyssey.cellHeight = $('#current_month > [data-pos="1_1"]').outerHeight();
            initializeCalendar();
        });
    </script>
    <?php
    if ($useModuleContainer){
    ?>
</div>
<?php
}
?>
