PageRenderTime 43ms CodeModel.GetById 25ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/com_joomleague/components/com_joomleague/modules/mod_joomleague_calendar/calendarClass.php

https://gitlab.com/volleyuisp/joomleague
PHP | 303 lines | 232 code | 32 blank | 39 comment | 21 complexity | 20aa9434fc394956879cd3332872e3ef MD5 | raw file
  1<?php
  2//this is the PHP Calendar Class
  3
  4// PHP Calendar Class Version 1.4 (5th March 2001)
  5//  
  6// Copyright David Wilkinson 2000 - 2001. All Rights reserved.
  7// 
  8// This software may be used, modified and distributed freely
  9// providing this copyright notice remains intact at the head 
 10// of the file.
 11//
 12// This software is freeware. The author accepts no liability for
 13// any loss or damages whatsoever incurred directly or indirectly 
 14// from the use of this script. The author of this software makes 
 15// no claims as to its fitness for any purpose whatsoever. If you 
 16// wish to use this software you should first satisfy yourself that 
 17// it meets your requirements.
 18//
 19// URL:   http://www.cascade.org.uk/software/php/calendar/
 20// Email: davidw@cascade.org.uk
 21
 22
 23class PHPCalendar
 24{
 25
 26
 27  
 28  function getDayNames(){return $this->dayNames;}
 29  function setDayNames($names){$this->dayNames = $names;}
 30  function getMonthNames(){return $this->monthNames;}
 31  function setMonthNames($names){$this->monthNames = $names;}
 32  function getStartDay(){return $this->startDay;}
 33  function setStartDay($day){$this->startDay = $day;    }
 34  function getStartMonth(){return $this->startMonth;}
 35  function setStartMonth($month){$this->startMonth = $month;}
 36     
 37   /*
 38        Return the HTML for a specified month
 39    */
 40  function getMonthView($month, $year)
 41  {
 42        return $this->getMonthHTML($month, $year);
 43  }
 44    
 45   
 46    
 47    
 48    /********************************************************************************
 49    
 50        The rest are private methods. No user-servicable parts inside.
 51        
 52        You shouldn't need to call any of these functions directly.
 53        
 54    *********************************************************************************/
 55
 56
 57    /*
 58        Calculate the number of days in a month, taking into account leap years.
 59    */
 60  function getDaysInMonth($month, $year)
 61  {
 62        if ($month < 1 || $month > 12)
 63        {
 64            return 0;
 65        }
 66   
 67        $d = $this->daysInMonth[$month - 1];
 68   
 69        if ($month == 2)
 70        {
 71            // Check for leap year
 72            // Forget the 4000 rule, I doubt I'll be around then...
 73        
 74            if ($year%4 == 0)
 75            {
 76                if ($year%100 == 0)
 77                {
 78                    if ($year%400 == 0)
 79                    {
 80                        $d = 29;
 81                    }
 82                }
 83                else
 84                {
 85                    $d = 29;
 86                }
 87            }
 88        }
 89    
 90        return $d;
 91    }
 92
 93
 94    /*
 95        Generate the HTML for a given month
 96    */
 97    function getMonthHTML($m, $y, $showYear = 1)
 98    {
 99      
100        $doc = JFactory::getDocument();  
101        $s = "";
102        
103        $a = $this->adjustDate($m, $y);
104        $month = $a[0];
105        $year = $a[1];        
106        
107        $daysInMonth = $this->getDaysInMonth($month, $year);
108        $date = getdate(mktime(12, 0, 0, $month, 1, $year));
109        $daysInLastMonth = $this->getDaysInMonth(($month-1), $year);
110        $first = $date["wday"];
111        $monthName = $this->monthNames[$month - 1];
112      
113        $prev = $this->adjustDate($month - 1, $year);
114        $next = $this->adjustDate($month + 1, $year);
115      
116        if ($showYear == 1)
117        {
118          $prevMonth = $this->getCalendarLink($prev[0], $prev[1]);
119          $nextMonth = $this->getCalendarLink($next[0], $next[1]);
120          $nextYear  = $this->getCalendarLink($next[0], $next[1]);
121          $prevYear  = $this->getCalendarLink($prev[0], $prev[1]);
122        }
123        else
124        {
125          $prevMonth = "";
126          $nextMonth = "";
127          $prevYear = "";
128          $nextYear = "";
129        }
130        $todaylink='';
131        $language= JFactory::getLanguage(); //get the current language
132        $language->load( 'mod_joomleague_calendar' ); //load the language ini file of the module
133        $header = $monthName . (($showYear > 0) ? " " . $year : "");
134        $s .= '<table id="jlctableCalendar-'.$this->modid.'" class="jlcCalendar">'."\n";
135        $s .= "   <tr>\n";
136        $s .= '      <td align="center" class="jlcCalendarHeader jlcheaderArrow">' . '<a class="jlcheaderArrow" title="'
137           .  $language->_('MOD_JOOMLEAGUE_CALENDAR_PREVYEAR').'" id="jlcprevYear-' . $this->modid 
138           .  '" href="javascript:void(0)" onclick="jlcnewDate('.$month.",". ($year-1).",".$this->modid
139           .  ');">&lt;&lt;</a>'  . "</td>\n";
140        $s .= '      <td align="center" class="jlcCalendarHeader jlcheaderArrow">' . '<a class="jlcheaderArrow" title="'
141           .  $language->_('MOD_JOOMLEAGUE_CALENDAR_PREVMONTH').'" id="jlcprevMonth-' . $this->modid 
142           .  '" href="javascript:void(0)" onclick="jlcnewDate('.$prev[0].",". $prev[1].",".$this->modid
143           .  ');">&lt;</a>'  . "</td>\n";
144        $s .= '<td align="center" class="jlcCalendarHeader jlcheaderDate" colspan="3">'.$header."</td>\n";
145        $s .= '<td align="center" class="jlcCalendarHeader jlcheaderArrow">' . '<a class="jlcheaderArrow" title="'
146           .  $language->_('MOD_JOOMLEAGUE_CALENDAR_NEXTMONTH').'" id="jlcnextMonth-' . $this->modid 
147           .  '" href="'.'javascript:void(0)'.'" onclick="'."jlcnewDate(".$next[0].",". $next[1].",".$this->modid
148           .');" >&gt;</a>'  . "</td>\n";
149        $s .= '<td align="center" class="jlcCalendarHeader jlcheaderArrow">' . '<a class="jlcheaderArrow" title="'
150           .  $language->_('MOD_JOOMLEAGUE_CALENDAR_NEXTYEAR').'" id="jlcnextYear-' . $this->modid 
151           .  '" href="'.'javascript:void(0)'.'" onclick="'."jlcnewDate(".$month.",". ($year+1).",".$this->modid
152           .');" >&gt;&gt;</a>'  . "</td>\n";
153        $s .= "</tr>\n";
154      
155        $s .= "<tr>\n";
156        for($i=0;$i<7;$i++)
157        {
158        
159          $s .= '<td class="jlcdayName">' . $this->dayNames[($this->startDay+$i)%7] . "</td>\n";
160        
161        }
162        $s .= "</tr>\n";
163      
164        $d = $this->startDay + 1 - $first;
165        while ($d > 1)
166        {
167          $d -= 7;
168        }
169
170       // if(!$day){
171          $today = getdate(time());
172        //}
173        //else{$today = array("year"=>$y,"mon"=>$m,"mday"=>$day);}
174      
175    
176        while ($d <= $daysInMonth)
177        {
178          
179          $s .= "<tr>\n";
180          for ($i = 0; $i < 7; $i++)
181          {
182              $class = ($year == $today["year"] && $month == $today["mon"] && $d == $today["mday"]) ? "highlight jlcCalendarDay jlcCalendarToday " : "jlcCalendarDay ";
183              $s .= "<td class=\"";
184              $tdEnd='">';
185              if ($d > 0 && $d <= $daysInMonth)
186              {
187                $divday = ($d > 9) ? $d : '0'.$d;
188                $divm = ($month > 9) ? $month : '0'.$month;
189                $divid = 'jlcal_' . $year.'-'.$divm.'-'.$divday;
190                $link = $this->getDateLink($d, $month, $year);
191                $click = $this->getDateClick($d, $month, $year);
192                $modalrel = ($link == "") ? '' : " rel=\"{handler: 'adopt', adopt:'jlCalList-".$this->modid."_temp'}\"";
193                if($link && $class=="highlight jlcCalendarDay jlcCalendarToday ")
194                {
195                  $todaylink=$click;
196                  $s .= $class . 'jlcCalendarTodayLink' . $tdEnd 
197                     . '<a class="hasTip jlcCalendarToday jlcmodal' . $this->modid. '"' 
198                     . ' href="' . $link . '" onclick="' . $click . '"';
199                  $s .= $modalrel . " >$divday</a>";
200                }
201                else
202                {
203                  $s .= (($link == "") ? $class.$tdEnd.$divday : "jlcCalendarDay"
204                     .  $tdEnd.'<a class="jlcCalendarDay hasTip jlcmodal' . $this->modid
205                     .  '" href="' . $link . '" onclick="' . $click . '"'
206                     .  $modalrel . " >$divday</a>");
207                }
208              }
209              else
210              {
211                   if($d <= 0) { 
212                     $do = ($daysInLastMonth + $d);
213                   }
214                   else { $do = '0'.($d - $daysInMonth);}
215                  $s .= "jlcCalendarDay jlcCalendarDayEmpty " . $tdEnd . "$do";
216              }
217                $s .= "</td>\n";       
218              $d++;
219          }
220          $s .= "</tr>\n";    
221      }
222
223      $s .= "</table>\n";
224
225      if($todaylink!='' && $this->ajax == 0 && $this->lightbox == 1 && $this->lightbox_on_pageload == 1)
226      {
227        $doc->addScriptDeclaration('window.addEvent(\'domready\', function() {
228  			'.$todaylink.'
229  		});
230		');
231      }
232      $output = array();
233      $output['calendar'] = $s;
234      $output['list'] = $this->matches_output($m, $y, $d);
235      $output['teamslist'] = $this->output_teamlist();
236   
237      return $output;
238    }
239    
240 
241    function adjustDate($month, $year)
242    {
243        $a = array();  
244        $a[0] = $month;
245        $a[1] = $year;
246        
247        while ($a[0] > 12)
248        {
249            $a[0] -= 12;
250            $a[1]++;
251        }
252        
253        while ($a[0] <= 0)
254        {
255            $a[0] += 12;
256            $a[1]--;
257        }
258        
259        return $a;
260    }
261
262
263    /* 
264        The start day of the week. This is the day that appears in the first column
265        of the calendar. Sunday = 0.
266    */
267    var $startDay = 0;
268
269    /* 
270        The start month of the year. This is the month that appears in the first slot
271        of the calendar in the year view. January = 1.
272    */
273    var $startMonth = 1;
274
275    /*
276        The labels to display for the days of the week. The first entry in this array
277        represents Sunday.
278    */
279    var $dayNames = array("S", "M", "T", "W", "T", "F", "S");
280    
281    /*
282        The labels to display for the months of the year. The first entry in this array
283        represents January.
284    */
285    var $monthNames = array("January", "February", "March", "April", "May", "June",
286                            "July", "August", "September", "October", "November", "December");
287                            
288                            
289    /*
290        The number of days in each month. You're unlikely to want to change this...
291        The first entry in this array represents January.
292    */
293    var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
294  
295    var $modid = "";
296    var $ajax = 0;
297    var $lightbox = 0;
298    var $lightbox_on_pageload = 0;
299    var $usedteams = '';
300    var $usedclubs = '';
301}
302
303?>