Small update
[iDB.git] / inc / calendars.php
blob8f06b81cdda596a5a162e9ed6ce0035987140a41
1 <?php
2 /*
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the Revised BSD License.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 Revised BSD License for more details.
11 Copyright 2004-2019 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
12 Copyright 2004-2019 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
14 $FileInfo: calendars.php - Last Update: 08/02/2019 SVN 905 - Author: cooldude2k $
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="calendars.php"||$File3Name=="/calendars.php") {
18 require('index.php');
19 exit(); }
20 if(isset($_SESSION['OldViewingPage'])) { $_SESSION['AncientViewingPage'] = $_SESSION['OldViewingPage']; } else { $_SESSION['AncientViewingPage'] = url_maker(null,"no+ext","act=view","&","=",$prexqstr['index'],$exqstr['index']); }
21 if(isset($_SESSION['OldViewingFile'])) { $_SESSION['AncientViewingFile'] = $_SESSION['OldViewingFile']; } else {
22 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
23 $_SESSION['AncientViewingFile'] = $exfile['index'].$Settings['file_ext']; }
24 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
25 $_SESSION['AncientViewingFile'] = $exfile['index']; } }
26 if(isset($_SESSION['OldPreViewingTitle'])) { $_SESSION['AncientPreViewingTitle'] = $_SESSION['OldPreViewingTitle']; } else { $_SESSION['AncientPreViewingTitle'] = "Viewing"; }
27 if(isset($_SESSION['OldViewingTitle'])) { $_SESSION['AncientViewingTitle'] = $_SESSION['OldViewingTitle']; } else { $_SESSION['AncientViewingTitle'] = "Board index"; }
28 if(isset($_SESSION['OldExtraData'])) { $_SESSION['AncientExtraData'] = $_SESSION['OldExtraData']; } else { $_SESSION['AncientExtraData'] = "currentact:view; currentcategoryid:0; currentforumid:0; currenttopicid:0; currentmessageid:0; currenteventid:0; currentmemberid:0;"; }
29 if(isset($_SESSION['ViewingPage'])) { $_SESSION['OldViewingPage'] = $_SESSION['ViewingPage']; } else { $_SESSION['OldViewingPage'] = url_maker(null,"no+ext","act=view","&","=",$prexqstr['index'],$exqstr['index']); }
30 if(isset($_SESSION['ViewingFile'])) { $_SESSION['OldViewingFile'] = $_SESSION['ViewingFile']; } else {
31 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
32 $_SESSION['OldViewingFile'] = $exfile['index'].$Settings['file_ext']; }
33 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
34 $_SESSION['OldViewingFile'] = $exfile['index']; } }
35 if(isset($_SESSION['PreViewingTitle'])) { $_SESSION['OldPreViewingTitle'] = $_SESSION['PreViewingTitle']; } else { $_SESSION['OldPreViewingTitle'] = "Viewing"; }
36 if(isset($_SESSION['ViewingTitle'])) { $_SESSION['OldViewingTitle'] = $_SESSION['ViewingTitle']; } else { $_SESSION['OldViewingTitle'] = "Board index"; }
37 if(isset($_SESSION['ExtraData'])) { $_SESSION['OldExtraData'] = $_SESSION['ExtraData']; } else { $_SESSION['OldExtraData'] = "currentact:view; currentcategoryid:0; currentforumid:0; currenttopicid:0; currentmessageid:0; currenteventid:0; currentmemberid:0;"; }
38 $_SESSION['ViewingPage'] = url_maker(null,"no+ext","act=view","&","=",null,null);
39 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
40 $_SESSION['ViewingFile'] = $exfile['calendar'].$Settings['file_ext']; }
41 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
42 $_SESSION['ViewingFile'] = $exfile['calendar']; }
43 $_SESSION['PreViewingTitle'] = "Viewing";
44 $_SESSION['ViewingTitle'] = "Calendar";
45 $_SESSION['ExtraData'] = "currentact:view; currentcategoryid:0; currentforumid:0; currenttopicid:0; currentmessageid:0; currenteventid:0; currentmemberid:0;";
46 $calcurtime = new DateTime();
47 $calcurtime->setTimestamp($defcurtime->getTimestamp());
48 $calcurtime->setTimezone($usertz);
49 if(!isset($_GET['HighligtDay'])) { $_GET['HighligtDay'] = null; }
50 if(!isset($_GET['calmadd'])) { $_GET['calmadd'] = 0; }
51 if(!is_numeric($_GET['calmadd'])) { $_GET['calmadd'] = 0; }
52 if((!isset($_GET['calmonth']) && !isset($_GET['calyear'])) &&
53 isset($_GET['caldate']) && strlen($_GET['caldate'])==2) {
54 $_GET['caldate'] = $_GET['caldate'].$calcurtime->format("Y"); }
55 if((!isset($_GET['calmonth']) && !isset($_GET['calyear'])) &&
56 isset($_GET['caldate']) && strlen($_GET['caldate'])==6) {
57 preg_match_all("/([0-9]{2})([0-9]{4})/is", $_GET['caldate'], $datecheck);
58 $_GET['calmonth'] = $datecheck[1][0];
59 $_GET['calyear'] = $datecheck[2][0]; }
60 if((isset($_GET['calmonth']) && isset($_GET['calyear'])) &&
61 (strlen($_GET['calmonth'])==2&&strlen($_GET['calyear'])==4) ) {
62 $year1 = date("Y", strtotime($_GET['calyear']."-".$_GET['calmonth']."-01"));
63 $year2 = date("Y", $utccurtime->getTimestamp());
64 $month1 = date("m", strtotime($_GET['calyear']."-".$_GET['calmonth']."-01"));
65 $month2 = date("m", $utccurtime->getTimestamp());
66 $redirdate = ((($year2 - $year1) * 12) + ($month2 - $month1)) * -1;
67 $_GET['calmadd'] = $redirdate; }
68 $nextcalm = $_GET['calmadd'] + 1;
69 $backcalm = $_GET['calmadd'] - 1;
70 $calmcount = abs($_GET['calmadd']);
71 $getcurmonth = $usercurtime->format("m");
72 $getcuryear = $usercurtime->format("y");
73 $getcurtmsp = mktime(0, 0, 0, $getcurmonth, 1, $getcuryear);
74 $getnextmsp = mktime(0, 0, 0, ($getcurmonth + $nextcalm), 1, $getcuryear);
75 $nexmonthnum = date("m", $getnextmsp);
76 $nexyearnum = date("Y", $getnextmsp);
77 $nexcaldate = $nexmonthnum.$nexyearnum;
78 $getbactmsp = mktime(0, 0, 0, ($getcurmonth + $backcalm), 1, $getcuryear);
79 $bacmonthnum = date("m", $getbactmsp);
80 $bacyearnum = date("Y", $getbactmsp);
81 $baccaldate = $bacmonthnum.$bacyearnum;
82 $tmpcalmnum = 0;
83 $tmpcalmadd = 0;
84 $tmpcalcount = 1;
85 if($_GET['calmadd']>0) {
86 while($tmpcalcount <= $calmcount) {
87 $calcurtime->setTimestamp($defcurtime->getTimestamp()+$tmpcalmadd);
88 $tmpdaystart = $calcurtime->format("d");
89 $tmpdaycount = $calcurtime->format("t");
90 if($tmpdaystart>=1) { $tmpcalmnum += ($tmpdaycount - $tmpdaystart) + 1; }
91 if($tmpdaystart<1) { $tmpcalmnum += $tmpdaycount; }
92 $tmpcalmadd = $tmpcalmnum * $dayconv['day'];
93 ++$tmpcalcount; }
94 $calmounthaddd = $tmpcalmadd; }
95 if($_GET['calmadd']<0) {
96 while($tmpcalcount <= $calmcount) {
97 $calcurtime->setTimestamp($defcurtime->getTimestamp()+$tmpcalmadd);
98 $tmpdaystart = $calcurtime->format("d");
99 $tmpdaycount = $calcurtime->format("t");
100 if($tmpdaystart>=1) { $tmpcalmnum -= $tmpdaystart + 1; }
101 if($tmpdaystart<1) { $tmpcalmnum -= $tmpdaycount; }
102 $tmpcalmadd = $tmpcalmnum * $dayconv['day'];
103 ++$tmpcalcount; }
104 $calmounthaddd = $tmpcalmadd; }
105 // Extra month stuff
106 $MyRealMonthNum1 = $usercurtime->format("m");
107 $MyRealYear = $usercurtime->format("Y");
108 // Count the Days in this month
109 if(!isset($calmounthaddd)) { $calmounthaddd = 0; }
110 $MyTimeStamp = $utccurtime->getTimestamp() + $calmounthaddd;
111 //$calcurtime->setTimestamp($defcurtime->getTimestamp()+$calmounthaddd);
112 $calcurtime->setDate($_GET['calyear'], $_GET['calmonth'], 1);
113 $CountDays = $calcurtime->format("t");
114 $MyDay = $calcurtime->format("j");
115 $MyDay2 = $calcurtime->format("jS");
116 $MyDayNum = $calcurtime->format("d");
117 $MyDayName = $calcurtime->format("l");
118 $MyYear = $calcurtime->format("Y");
119 $MyYear2 = $calcurtime->format("y");
120 $MyMonth = $calcurtime->format("m");
121 $MyTimeStamp1 = mktime(0,0,0,$MyMonth,1,$MyYear);
122 $MyTimeStamp2 = mktime(23,59,59,$MyMonth,$CountDays,$MyYear);
123 $MyMonthName = $calcurtime->format("F");
124 $MyMonthNum1 = $calcurtime->format("m");
125 $MyMonthNum2 = $calcurtime->format("n");
126 $FirstDayThisMonth = date("w", mktime(0, 0, 0, $MyMonth, 1, $MyYear));
127 $MyCurDay = $usercurtime->format("j");
128 $MyCurYear = $usercurtime->format("Y");
129 $MyCurMonth = $usercurtime->format("m");
130 $EventsName = array();
131 $query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."events\" WHERE (\"EventMonth\">=%i AND \"EventYear\"<%i AND \"EventYearEnd\">=%i) OR (\"EventMonth\"<=%i AND \"EventMonthEnd\">=%i AND \"EventYearEnd\">=%i) OR (\"EventMonth\"<=%i AND \"EventMonthEnd\"<=%i AND \"EventYear\"<=%i AND \"EventYearEnd\">%i)", array($MyMonth,$MyYear,$MyYear,$MyMonth,$MyMonth,$MyYear,$MyMonth,$MyMonth,$MyYear,$MyYear));
132 $result=sql_query($query,$SQLStat);
133 $num=sql_num_rows($result);
134 $is=0;
135 while ($is < $num) {
136 $EventID=sql_result($result,$is,"id");
137 $EventUser=sql_result($result,$is,"UserID");
138 $EventGuest=sql_result($result,$is,"GuestName");
139 $EventName=sql_result($result,$is,"EventName");
140 $EventText=sql_result($result,$is,"EventText");
141 $EventStart=sql_result($result,$is,"TimeStamp");
142 $EventEnd=sql_result($result,$is,"TimeStampEnd");
143 $eventstartcurtime = new DateTime();
144 $eventstartcurtime->setTimestamp($EventStart);
145 $eventstartcurtime->setTimezone($usertz);
146 $eventendcurtime = new DateTime();
147 $eventendcurtime->setTimestamp($EventEnd);
148 $eventendcurtime->setTimezone($usertz);
149 //$EventMonth=sql_result($result,$is,"EventMonth");
150 $EventMonth=$eventstartcurtime->format("m");
151 //$EventMonthEnd=sql_result($result,$is,"EventMonthEnd");
152 $EventMonthEnd=$eventendcurtime->format("m");
153 //$EventDay=sql_result($result,$is,"EventDay");
154 $EventDay=$eventstartcurtime->format("j");
155 //$EventDayEnd=sql_result($result,$is,"EventDayEnd");
156 $EventDayEnd=$eventendcurtime->format("j");
157 //$EventYear=sql_result($result,$is,"EventYear");
158 $EventYear=$eventstartcurtime->format("Y");
159 //$EventYearEnd=sql_result($result,$is,"EventYearEnd");
160 $EventYearEnd=$eventendcurtime->format("Y");
161 if($EventMonthEnd!=$MyMonth) { $EventDayEnd = $CountDays; }
162 if($EventMonth<$MyMonth) { $EventDay = 1; }
163 $oldeventname=$EventName;
164 $EventName1 = pre_substr($EventName,0,20);
165 if (pre_strlen($EventName)>20) { $EventName1 = $EventName1."..."; }
166 $EventName=$EventName1;
167 if(!isset($EventsName[$EventDay])) { $EventsName[$EventDay] = null; }
168 if ($EventsName[$EventDay] != null) {
169 $EventsName[$EventDay] .= ", <a href=\"".url_maker($exfile['event'],$Settings['file_ext'],"act=event&id=".$EventID,$Settings['qstr'],$Settings['qsep'],$prexqstr['event'],$exqstr['event'])."\" style=\"font-size: 9px;\" title=\"View Event ".$oldeventname.".\">".$EventName."</a>"; }
170 if ($EventsName[$EventDay] == null) {
171 $EventsName[$EventDay] = "<a href=\"".url_maker($exfile['event'],$Settings['file_ext'],"act=event&id=".$EventID,$Settings['qstr'],$Settings['qsep'],$prexqstr['event'],$exqstr['event'])."\" style=\"font-size: 9px;\" title=\"View Event ".$oldeventname.".\">".$EventName."</a>"; }
172 if ($EventDay<$EventDayEnd) {
173 $NextDay = $EventDay+1;
174 $EventDayEnd = $EventDayEnd+1;
175 while ($NextDay < $EventDayEnd) {
176 if(!isset($EventsName[$NextDay])) { $EventsName[$NextDay] = null; }
177 if ($EventsName[$NextDay] != null) {
178 $EventsName[$NextDay] .= ", <a href=\"".url_maker($exfile['event'],$Settings['file_ext'],"act=event&id=".$EventID,$Settings['qstr'],$Settings['qsep'],$prexqstr['event'],$exqstr['event'])."\" style=\"font-size: 9px;\" title=\"View Event ".$oldeventname.".\">".$EventName."</a>"; }
179 if ($EventsName[$NextDay] == null) {
180 $EventsName[$NextDay] = "<a href=\"".url_maker($exfile['event'],$Settings['file_ext'],"act=event&id=".$EventID,$Settings['qstr'],$Settings['qsep'],$prexqstr['event'],$exqstr['event'])."\" style=\"font-size: 9px;\" title=\"View Event ".$oldeventname.".\">".$EventName."</a>"; }
181 $NextDay++; } }
182 $EventsID[$EventDay] = $EventID;
183 ++$is; }
184 sql_free_result($result);
185 $bdquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."members\" WHERE \"BirthMonth\"=%i AND \"BirthYear\"<=%i", array($MyMonth, $MyYear));
186 $bdresult=sql_query($bdquery,$SQLStat);
187 $bdnum=sql_num_rows($bdresult);
188 $bdi=0;
189 while ($bdi < $bdnum) {
190 $UserNamebd=sql_result($bdresult,$bdi,"Name");
191 $BirthDay=sql_result($bdresult,$bdi,"BirthDay");
192 $BirthMonth=sql_result($bdresult,$bdi,"BirthMonth");
193 $BirthYear=sql_result($bdresult,$bdi,"BirthYear");
194 $UserCurAge=$MyYear-$BirthYear;
195 $oldusername=$UserNamebd;
196 $UserNamebd1 = pre_substr($UserNamebd,0,20);
197 if (pre_strlen($UserNamebd)>20) { $UserNamebd1 = $UserNamebd1."..."; }
198 $UserNamebd=$UserNamebd1;
199 if(!isset($EventsName[$BirthDay])) { $EventsName[$BirthDay] = null; }
200 if ($EventsName[$BirthDay] != null) {
201 $EventsName[$BirthDay] .= ", <span title=\"".$oldusername." is ".$UserCurAge." years old\">".$UserNamebd1."</span>"; }
202 if ($EventsName[$BirthDay] == null) {
203 $EventsName[$BirthDay] = "<span title=\"".$oldusername." is ".$UserCurAge." years old\">".$UserNamebd1."</span>"; }
204 ++$bdi; }
205 sql_free_result($bdresult);
206 $MyDays = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
207 $DayNames = "";
208 foreach ($MyDays as $x => $y) {
209 $DayNames .= '<th class="CalTableColumn2" style="width: 12%;">' . $y . '</th>'."\r\n";
211 $WeekDays = "";
212 $i = $FirstDayThisMonth + 1;
213 if ($FirstDayThisMonth != "0") {
214 $WeekDays .= '<td class="CalTableColumn3Blank" style="text-align: center;" colspan="' . $FirstDayThisMonth . '">&nbsp;</td>'."\r\n";
216 $Day_i = "1";
217 $ii = $i;
218 for ($i; $i <= ($CountDays + $FirstDayThisMonth) ;$i++) {
219 if ($ii == 8) {
220 $WeekDays .= "</tr><tr class=\"CalTableRow3\">"."\r\n";
221 $ii = 1; }
222 if ($MyCurDay == $Day_i && $MyCurMonth == $MyRealMonthNum1 && $MyCurYear == $MyRealYear) {
223 $Extra = 'CalTableColumn3Current'; }
224 else {
225 $Extra = 'CalTableColumn3'; }
226 if ($Day_i != $_GET['HighligtDay']) {
227 if(!isset($EventsName[$Day_i])) { $EventsName[$Day_i] = null; }
228 if($EventsName[$Day_i]!=null) { $EventsName[$Day_i] = "&nbsp;( ".$EventsName[$Day_i]." )"; }
229 if ($Day_i != $MyCurDay) {
230 $WeekDays .= '<td class="'.$Extra.'" style="vertical-align: top;"><div class="CalDate">' . $Day_i . '</div>' . $EventsName[$Day_i] . '</td>'."\r\n"; } }
231 if ($Day_i == $MyCurDay) {
232 $WeekDays .= '<td class="'.$Extra.'" style="vertical-align: top;"><div class="CalDateCurrent">' . $Day_i . '</div>' . $EventsName[$Day_i] . '</td>'."\r\n"; }
233 $Day_i++;
234 $ii++;
236 if ((8 - $ii) >= "1") {
237 $WeekDays .= '<td class="CalTableColumn3Blank" style="text-align: center;" colspan="' . (8 - $ii) . '">&nbsp;</td>'."\r\n"; } ?>
238 <div class="NavLinks"><?php echo $ThemeSet['NavLinkIcon']; ?><a href="<?php echo url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']); ?>"><?php echo $Settings['board_name']; ?></a><?php echo $ThemeSet['NavLinkDivider']; ?><a href="<?php echo url_maker($exfile['calendar'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['calendar'],$exqstr['calendar']); ?>">Calendar</a></div>
239 <div class="DivNavLinks">&nbsp;</div>
240 <div class="CalTable1Border">
241 <?php if($ThemeSet['TableStyle']=="div") { ?>
242 <div class="CalTableRow1" style="font-weight: bold;">
243 <span style="float: left;"><?php echo $ThemeSet['TitleIcon']; ?><a href="<?php echo url_maker($exfile['calendar'],$Settings['file_ext'],"act=view&caldate=".$MyMonth.$MyYear,$Settings['qstr'],$Settings['qsep'],$prexqstr['calendar'],$exqstr['calendar']); ?>" title="<?php echo "Viewing ".$MyMonthName." ".$MyYear; ?>"><?php echo "Viewing ".$MyMonthName." ".$MyYear; ?></a>&nbsp;</span>&nbsp;
244 <span style="float: right;">&nbsp;<a href="<?php echo url_maker($exfile['calendar'],$Settings['file_ext'],"act=view&caldate=".$baccaldate,$Settings['qstr'],$Settings['qsep'],$prexqstr['calendar'],$exqstr['calendar']); ?>">&lt;</a><?php echo $ThemeSet['LineDivider']; ?><a href="<?php echo url_maker($exfile['calendar'],$Settings['file_ext'],"act=view&caldate=".$nexcaldate,$Settings['qstr'],$Settings['qsep'],$prexqstr['calendar'],$exqstr['calendar']); ?>">&gt;</a>&nbsp;</span>&nbsp;</div>
245 <?php } ?>
246 <table class="CalTable1">
247 <?php if($ThemeSet['TableStyle']=="table") { ?>
248 <tr class="CalTableRow1">
249 <th class="CalTableColumn1" colspan="7">
250 <span style="float: left;"><?php echo $ThemeSet['TitleIcon']; ?><?php echo "Viewing ".$MyMonthName." ".$MyYear; ?>&nbsp;</span>&nbsp;
251 <span style="float: right;">&nbsp;<a href="<?php echo url_maker($exfile['calendar'],$Settings['file_ext'],"act=view&caldate=".$baccaldate,$Settings['qstr'],$Settings['qsep'],$prexqstr['calendar'],$exqstr['calendar']); ?>">&lt;</a><?php echo $ThemeSet['LineDivider']; ?><a href="<?php echo url_maker($exfile['calendar'],$Settings['file_ext'],"act=view&caldate=".$nexcaldate,$Settings['qstr'],$Settings['qsep'],$prexqstr['calendar'],$exqstr['calendar']); ?>">&gt;</a>&nbsp;</span>&nbsp;
252 </th>
253 </tr><?php } ?>
254 <tr class="CalTableRow2">
255 <?php echo $DayNames; ?>
256 </tr><tr class="CalTableRow3">
257 <?php echo $WeekDays; ?>
258 </tr>
259 <tr class="CalTableRow4">
260 <td class="CalTableColumn4" colspan="7">&nbsp;</td>
261 </tr>
262 </table></div>
263 <div class="DivCalendar">&nbsp;</div>