This repository has been archived by the owner on Aug 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
108 lines (81 loc) · 2.93 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* DeskCal
*
* Requires at least PHP 5.1.0
*
* LICENSE: CC BY-NC-SA 3.0
* http://creativecommons.org/licenses/by-nc-sa/3.0/
*
* @author Mihai Zaharie <[email protected]>
*/
/**
* Settings
*/
$debug = false;
$settings = array(
'timezone' => 'Europe/Bucharest'
);
/**
* Paths
*/
define('CONFIG_DIR', '');
define('LIBRARIES_DIR', 'libraries');
define('TEMPLATES_DIR', 'templates');
define('SMARTY_USER_PLUGINS_DIR', LIBRARIES_DIR . '/Smarty/userplugins');
define('TEMPLATES_COMPILED_DIR', 'cache/templates/compiled');
define('TEMPLATES_CACHED_DIR', 'cache/templates/cached');
/**
* Bootstrapper
*/
// Set the localization
date_default_timezone_set($settings['timezone']);
// Load and setup Smarty
require_once(LIBRARIES_DIR . '/Smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = TEMPLATES_DIR;
$smarty->compile_dir = TEMPLATES_COMPILED_DIR;
$smarty->config_dir = CONFIG_DIR;
$smarty->cache_dir = TEMPLATES_CACHED_DIR;
$smarty->debugging = $debug;
$smarty->caching = false;
$smarty->compile_check = $debug;
$smarty->addPluginsDir(SMARTY_USER_PLUGINS_DIR);
// User request
$requestMonth = (isset($_GET['month']) && preg_match('/^(0?[1-9]|1[012])$/i', $_GET['month'])) ? $_GET['month'] : date('n');
$requestYear = (isset($_GET['year'])) ? $_GET['year'] : date('Y');
// Prepare the calendar data
$timestamp = mktime(0, 0, 0, $requestMonth, 1, $requestYear);
$month['name'] = date('F', $timestamp) . ' ' . $requestYear;
$previousMonth = strtotime(date('Y-m-d', $timestamp) . ' - 1 month');
$month['previous'] = array('year' => date('Y', $previousMonth), 'month' => date('n', $previousMonth));
$nextMonth = strtotime(date('Y-m-d', $timestamp) . ' + 1 month');
$month['next'] = array('year' => date('Y', $nextMonth), 'month' => date('n', $nextMonth));
$week = (int) date('W', $timestamp);
for ($w = 1; $w <= 6; $w++)
{
$year = ($requestMonth == 1 && $week > 6) ? $requestYear - 1 : $requestYear;
$lastWeekOfYear = (int) date('W', mktime(0, 0, 0, 12, 31, $year));
if ($lastWeekOfYear >= 52 && $week > $lastWeekOfYear)
{
$week = 1;
$year = $requestYear;
}
$month['weeks'][$week]['number'] = $week;
for ($d = 1; $d <= 7; $d++)
{
$timestamp = strtotime($year . 'W' . str_pad($week, 2, '0', STR_PAD_LEFT) . $d);
$day = date('d', $timestamp);
$name = date('l', $timestamp);
$monthCheck = date('n', $timestamp);
$month['weeks'][$week]['days'][$day]['number'] = $day;
$month['weeks'][$week]['days'][$day]['name'] = $name;
$month['weeks'][$week]['days'][$day]['today'] = (mktime(0, 0, 0) == $timestamp) ? 'today' : '';
$month['weeks'][$week]['days'][$day]['offMonth'] = (date('n') != $monthCheck) ? 'off-month' : '';
$month['weeks'][$week]['days'][$day]['date'] = date('Y-m-d', $timestamp);
}
$week++;
}
// Display the calendar
$smarty->assign('month', $month);
$smarty->display('month.tpl');