1 | <?php declare(strict_types=1); |
||
2 | |||
3 | /* |
||
4 | You may not change or alter any portion of this comment or credits |
||
5 | of supporting developers from this source code or any supporting source code |
||
6 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
7 | |||
8 | This program is distributed in the hope that it will be useful, |
||
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
11 | */ |
||
12 | |||
13 | /** |
||
14 | * wgEvents module for xoops |
||
15 | * |
||
16 | * @copyright 2020 XOOPS Project (https://xooops.org) |
||
17 | * @license GPL 2.0 or later |
||
18 | * @package wgevents |
||
19 | * @author wedega - Email:<[email protected]> - Website:<https://xoops.wedega.com> |
||
20 | */ |
||
21 | |||
22 | use Xmf\Request; |
||
23 | use XoopsModules\Wgevents\ { |
||
24 | Constants, |
||
25 | SimpleCalendar |
||
26 | }; |
||
27 | |||
28 | require __DIR__ . '/header.php'; |
||
29 | $GLOBALS['xoopsOption']['template_main'] = 'wgevents_calendar.tpl'; |
||
30 | require_once \XOOPS_ROOT_PATH . '/header.php'; |
||
31 | |||
32 | if (!$permissionsHandler->getPermEventsView()) { |
||
33 | \redirect_header('index.php?op=list', 3, \_NOPERM); |
||
34 | } |
||
35 | |||
36 | //request |
||
37 | $op = Request::getCmd('op', 'list'); |
||
38 | $filterFrom = Request::getInt('filterFrom'); |
||
39 | $filterTo = Request::getInt('filterTo'); |
||
40 | |||
41 | if (Request::hasVar('gotoMonth')) { |
||
42 | $month = Request::getInt('gotoMonth'); |
||
43 | $year = Request::getInt('gotoYear'); |
||
44 | } else { |
||
45 | //default params |
||
46 | $year = (int)\date('Y'); |
||
47 | $month = (int)\date('n'); |
||
48 | } |
||
49 | $lastday = (int)\date('t', \strtotime($month . '/1/' . $year)); |
||
50 | $dayStart = \mktime(0, 0, 0, $month, 1, $year); |
||
51 | $dayEnd = \mktime(23, 59, 59, $month, $lastday, $year); |
||
52 | |||
53 | //$filterCat = Request::getInt('filterCat'); |
||
54 | $filterSort = 'datefrom-ASC'; |
||
55 | if (0 == $filterFrom || Request::hasVar('gotoMonth')) { |
||
56 | $filterFrom = (int)$dayStart; |
||
57 | $filterTo = (int)$dayEnd; |
||
58 | } |
||
59 | |||
60 | $filterFromPrevM = \mktime(0, 0, 0, (int)\date('n', $filterFrom - 1), 1, (int)\date('Y', $filterFrom - 1)); |
||
61 | $filterToPrevM = $filterFrom - 1; |
||
62 | $filterFromNextM = $filterTo + 1; |
||
63 | $filterToNextM = \mktime(23, 59, 59, (int)\date('n', $filterFromNextM), (int)\date('t', $filterFromNextM), (int)\date('Y', $filterFromNextM)); |
||
64 | $filterFromPrevY = \mktime(0, 0, 0, (int)\date('n', $filterFrom), 1, (int)\date('Y', $filterFrom) - 1); |
||
65 | $filterToPrevY = \mktime(23, 59, 59, (int)\date('n', $filterTo), (int)\date('t', $filterTo), (int)\date('Y', $filterTo) - 1); |
||
66 | $filterFromNextY = \mktime(0, 0, 0, (int)\date('n', $filterFrom), 1, (int)\date('Y', $filterFrom) + 1); |
||
67 | $filterToNextY = \mktime(23, 59, 59, (int)\date('n', $filterTo), (int)\date('t', $filterTo), (int)\date('Y', $filterTo) + 1); |
||
68 | |||
69 | /*calendar nav bar*/ |
||
70 | $arrMonth = [ |
||
71 | 1 => \_MA_WGEVENTS_CAL_JANUARY, |
||
72 | 2 => \_MA_WGEVENTS_CAL_FEBRUARY, |
||
73 | 3 => \_MA_WGEVENTS_CAL_MARCH, |
||
74 | 4 => \_MA_WGEVENTS_CAL_APRIL, |
||
75 | 5 => \_MA_WGEVENTS_CAL_MAY, |
||
76 | 6 => \_MA_WGEVENTS_CAL_JUNE, |
||
77 | 7 => \_MA_WGEVENTS_CAL_JULY, |
||
78 | 8 => \_MA_WGEVENTS_CAL_AUGUST, |
||
79 | 9 => \_MA_WGEVENTS_CAL_SEPTEMBER, |
||
80 | 10 => \_MA_WGEVENTS_CAL_OCTOBER, |
||
81 | 11 => \_MA_WGEVENTS_CAL_NOVEMBER, |
||
82 | 12 => \_MA_WGEVENTS_CAL_DECEMBER |
||
83 | ]; |
||
84 | $GLOBALS['xoopsTpl']->assign('monthNav', $arrMonth[\date('n', $filterFrom)]); |
||
85 | $GLOBALS['xoopsTpl']->assign('yearNav', \date('Y', $filterFrom)); |
||
86 | $GLOBALS['xoopsTpl']->assign('filterFromPrevM', $filterFromPrevM); |
||
87 | $GLOBALS['xoopsTpl']->assign('filterToPrevM', $filterToPrevM); |
||
88 | $GLOBALS['xoopsTpl']->assign('filterFromNextM', $filterFromNextM); |
||
89 | $GLOBALS['xoopsTpl']->assign('filterToNextM', $filterToNextM); |
||
90 | $GLOBALS['xoopsTpl']->assign('filterFromPrevY', $filterFromPrevY); |
||
91 | $GLOBALS['xoopsTpl']->assign('filterToPrevY', $filterToPrevY); |
||
92 | $GLOBALS['xoopsTpl']->assign('filterFromNextY', $filterFromNextY); |
||
93 | $GLOBALS['xoopsTpl']->assign('filterToNextY', $filterToNextY); |
||
94 | //$otherParams = "op=filter&filterByOwner=$filterByOwner&filterGroup=$filterGroup"; |
||
95 | //$GLOBALS['xoopsTpl']->assign('otherParams', $otherParams); |
||
96 | |||
97 | $lengthTitle = 30; |
||
98 | |||
99 | |||
100 | /* |
||
101 | if (Constants::FILTERBY_OWN === $filterByOwner) { |
||
102 | $op = 'filterOwn'; |
||
103 | } else if (Constants::FILTERBY_GROUP === $filterByOwner) { |
||
104 | $op = 'filterGroup'; |
||
105 | } else { |
||
106 | $op = 'list'; |
||
107 | } |
||
108 | */ |
||
109 | |||
110 | $op = 'list'; |
||
111 | [$sortBy, $orderBy] = \explode('-', $filterSort); |
||
112 | |||
113 | // Define Stylesheet |
||
114 | $GLOBALS['xoTheme']->addStylesheet($style, null); |
||
115 | // Keywords |
||
116 | $keywords = []; |
||
117 | // Breadcrumbs |
||
118 | $xoBreadcrumbs[] = ['title' => \_MA_WGEVENTS_CAL_ITEMS]; |
||
119 | // Paths |
||
120 | $GLOBALS['xoopsTpl']->assign('wgevents_url', \WGEVENTS_URL); |
||
121 | $GLOBALS['xoopsTpl']->assign('wgevents_icons_url_16', \WGEVENTS_ICONS_URL . '/16/'); |
||
122 | |||
123 | $GLOBALS['xoTheme']->addStylesheet(\WGEVENTS_URL . '/class/SimpleCalendar/css/SimpleCalendar.css', null); |
||
124 | $calendar = new SimpleCalendar\SimpleCalendar(); |
||
125 | $calendar->setStartOfWeek($helper->getConfig('cal_firstday')); |
||
126 | $calendar->setWeekDayNames([ |
||
127 | \_MA_WGEVENTS_CAL_MIN_SUNDAY, |
||
128 | \_MA_WGEVENTS_CAL_MIN_MONDAY, |
||
129 | \_MA_WGEVENTS_CAL_MIN_TUESDAY, |
||
130 | \_MA_WGEVENTS_CAL_MIN_WEDNESDAY, |
||
131 | \_MA_WGEVENTS_CAL_MIN_THURSDAY, |
||
132 | \_MA_WGEVENTS_CAL_MIN_FRIDAY, |
||
133 | \_MA_WGEVENTS_CAL_MIN_SATURDAY ]); |
||
134 | |||
135 | $uid = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0; |
||
136 | |||
137 | $formSimpleCal = new SimpleCalendar\SimpleCalendarforms(); |
||
138 | $formFilter = $formSimpleCal->getFormGotoMonth($arrMonth, \date('n', $filterFrom), \date('Y', $filterFrom)); |
||
139 | $GLOBALS['xoopsTpl']->assign('formGoto', $formFilter->render()); |
||
140 | |||
141 | /* |
||
142 | $filterHandler = new Filterhandler(); |
||
143 | $filterHandler->filterByOwner = $filterByOwner; |
||
144 | $filterHandler->filterGroup = $filterGroup; |
||
145 | $filterHandler->filterCat = $filterCat; |
||
146 | $filterHandler->filterSort = $filterSort; |
||
147 | $filterHandler->showLimit = false; |
||
148 | $filterHandler->showSort = false; |
||
149 | $filterHandler->showPeriod = false; |
||
150 | |||
151 | $formFilter = $filterHandler->getFormFilterItems(); |
||
152 | $GLOBALS['xoopsTpl']->assign('formFilter', $formFilter->render()); |
||
153 | */ |
||
154 | $filtered = false; |
||
155 | |||
156 | $gmapsEnableCal = false; |
||
157 | $gmapsHeight = false; |
||
158 | $useGMaps = (bool)$helper->getConfig('use_gmaps'); |
||
159 | if ($useGMaps) { |
||
160 | $gmapsPositionList = (string)$helper->getConfig('gmaps_enablecal'); |
||
161 | $gmapsEnableCal = ('top' == $gmapsPositionList || 'bottom' == $gmapsPositionList); |
||
162 | $gmapsHeight = $helper->getConfig('gmaps_height'); |
||
163 | } |
||
164 | |||
165 | // get categories collection |
||
166 | $categories = $categoryHandler->getCollection(); |
||
167 | // get events of period |
||
168 | $eventsArr = $eventHandler->getEvents(0, 0, $filterFrom, $filterTo, $sortBy, $orderBy); |
||
169 | |||
170 | $eventsCount = $eventsArr['count']; |
||
171 | if ($eventsCount > 0) { |
||
172 | $eventsAll = $eventsArr['eventsAll']; |
||
173 | $eventsMap = []; |
||
174 | $calendar->setDate($filterFrom); |
||
175 | $GLOBALS['xoopsTpl']->assign('eventsCount', $eventsCount); |
||
176 | foreach (\array_keys($eventsAll) as $i) { |
||
177 | $event = $eventsAll[$i]->getValuesEvents(); |
||
178 | $linkStyle = 'color:' . $categories[$event['catid']]['color'] . '!important;'; |
||
179 | $linkStyle .= 'border:1px solid ' . $categories[$event['catid']]['bordercolor'] . '!important;'; |
||
180 | $linkStyle .= 'background-color:' . $categories[$event['catid']]['bgcolor'] . '!important;'; |
||
181 | $linkStyle .= $categories[$event['catid']]['othercss']; |
||
182 | $evTitle = \_MA_WGEVENTS_EVENT_NAME . ': ' . $event['name'] . PHP_EOL; |
||
183 | $evTitle .= \_MA_WGEVENTS_EVENT_DATE . ': ' . $eventHandler->getDateFromToText($event['datefrom'], $event['dateto'], $event['allday']) . PHP_EOL; |
||
184 | if ($event['location']) { |
||
185 | $evTitle .= \_MA_WGEVENTS_EVENT_LOCATION . ': ' .$event['location'] . PHP_EOL; |
||
186 | } |
||
187 | $eventLink = '<a href="event.php?op=show&id=' . $event['id'] .'" title="' . $evTitle .'">'; |
||
188 | /* |
||
189 | if ($event['catlogo']) { |
||
190 | $eventLink .= '<img class="wg-cal-catlogo" src="' . \WGEVENTS_UPLOAD_CATLOGOS_URL . '/' . $event['catlogo'] .'" alt="' . \_MA_WGEVENTS_CATEGORY_LOGO .'" title="' . \_MA_WGEVENTS_CATEGORY_LOGO .'">'; |
||
191 | } |
||
192 | */ |
||
193 | $eventLink .= '<span class="wg-cal-eventtext">'; |
||
194 | $evName = $event['name']; |
||
195 | if (\strlen($evName) > $lengthTitle) { |
||
196 | $evName = \substr($evName, 0, $lengthTitle - 3) . '...'; |
||
197 | } |
||
198 | $eventLink .= $evName; |
||
199 | if ($useGMaps && $gmapsEnableCal && (float)$event['locgmlat'] > 0) { |
||
200 | $eventsMap[$event['id']] = [ |
||
201 | 'name' => $evName, |
||
202 | 'location' => $event['location_text_user'], |
||
203 | 'from' => $event['datefrom_text'], |
||
204 | 'url' => 'event.php?op=show&id=' . $event['id'], |
||
205 | 'lat' => (float)$event['locgmlat'], |
||
206 | 'lon' => (float)$event['locgmlon'] |
||
207 | ]; |
||
208 | } |
||
209 | |||
210 | $eventLink .= '</span><i class="fa fa-edit wg-cal-icon pull-right" title="' . \_MA_WGEVENTS_CAL_EDITITEM . '"></i></a>'; |
||
211 | $calendar->addDailyHtml($eventLink, $event['datefrom'], $event['dateto'], $linkStyle); |
||
212 | } |
||
213 | if ($useGMaps && count($eventsMap) > 0) { |
||
214 | if ('show' == $op) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
215 | $GLOBALS['xoopsTpl']->assign('gmapsShow', true); |
||
216 | } else { |
||
217 | $GLOBALS['xoopsTpl']->assign('gmapsShowList', true); |
||
218 | $GLOBALS['xoopsTpl']->assign('gmapsEnableCal', $gmapsEnableCal); |
||
219 | $GLOBALS['xoopsTpl']->assign('gmapsHeight', $gmapsHeight); |
||
220 | $GLOBALS['xoopsTpl']->assign('gmapsPositionList', $gmapsPositionList); |
||
221 | } |
||
222 | $GLOBALS['xoopsTpl']->assign('api_key', $helper->getConfig('gmaps_api')); |
||
223 | $GLOBALS['xoopsTpl']->assign('eventsMap', $eventsMap); |
||
224 | } |
||
225 | } |
||
226 | $calendar->setPermSubmit($permissionsHandler->getPermEventsSubmit()); |
||
227 | $GLOBALS['xoopsTpl']->assign('events_calendar', $calendar->render()); |
||
228 | |||
229 | // Keywords |
||
230 | wgeventsMetaKeywords($helper->getConfig('keywords') . ', ' . \implode(',', $keywords)); |
||
231 | unset($keywords); |
||
232 | // Description |
||
233 | wgeventsMetaDescription(\_MA_WGEVENTS_INDEX_DESC); |
||
234 | $GLOBALS['xoopsTpl']->assign('xoops_mpageurl', \WGEVENTS_URL.'/index.php'); |
||
235 | |||
236 | require __DIR__ . '/footer.php'; |
||
237 |