Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
/*************************
3
  Coppermine Photo Gallery
4
  ************************
5
  Copyright (c) 2003-2005 Coppermine Dev Team
6
  v1.1 originaly written by Gregory DEMAR
7
 
8
  This program is free software; you can redistribute it and/or modify
9
  it under the terms of the GNU General Public License as published by
10
  the Free Software Foundation; either version 2 of the License, or
11
  (at your option) any later version.
12
  ********************************************
13
  Coppermine version: 1.3.3
14
  $Source: /cvsroot/coppermine/stable/calendar.php,v $
15
  $Revision: 1.4 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:10 $
18
**********************************************/
19
 
20
define('IN_COPPERMINE', true);
21
define('CALENDAR_PHP', true);
22
 
23
require('include/init.inc.php');
24
 
25
 
26
if ($_REQUEST['action'] == 'banning') {
27
?>
28
<html>
29
  <head>
30
    <title>Calendar</title>
31
<link rel="stylesheet" href="themes/
32
<?php
33
if ($USER['theme']) {
34
    print $USER['theme'];
35
} else {
36
    print $CONFIG['theme'];
37
}
38
?>
39
/style.css" />
40
<script language="JavaScript">
41
 
42
// get the date format
43
var calendarFormat = 'y-m-d';
44
var targetDateField = window.opener.calendarTarget;
45
 
46
function sendDate(month, day, year)
47
{
48
    // pad with blank zeros numbers under 10
49
    month = month < 10 ? '0' + month : month;
50
    day   = day   < 10 ? '0' + day   : day;
51
    selectedDate = parent.calendarFormat;
52
    selectedDate = selectedDate.replace(/m/, month);
53
    selectedDate = selectedDate.replace(/d/, day);
54
    selectedDate = selectedDate.replace(/y/, year);
55
    selectedDate = selectedDate + ' 00:00:00';
56
    if (selectedDate == '-0-0 00:00:00') {
57
       selectedDate = '';
58
       }
59
    targetDateField.value = selectedDate;
60
    parent.window.close();
61
}
62
</script>
63
</head>
64
<body>
65
<?php
66
 
67
class MyCalendar extends Calendar
68
{
69
    function getCalendarLink($month, $year)
70
    {
71
        // Redisplay the current page, but with some parameters
72
        // to set the new month and year
73
        $s = getenv('SCRIPT_NAME');
74
        return "$s?action=".$_REQUEST['action']."&month=$month&year=$year";
75
    }
76
 
77
    function getDateLink($day, $month, $year)
78
    {
79
            $link = "<a href=\"#\" onclick=\"sendDate('".$month."', '".$day."', '".$year."');\" class=\"user_thumb_infobox\">";
80
        return $link;
81
    }
82
}
83
 
84
 
85
 
86
 
87
$month = $_REQUEST['month'];
88
$year = $_REQUEST['year'];
89
 
90
$cal = new MyCalendar;
91
$cal->setMonthNames($lang_month);
92
$cal->setDayNames($lang_day_of_week);
93
$cal->setStartDay(1);
94
echo $cal->getMonthView($month, $year);
95
 
96
?>
97
<div align="center"><a href="javascript:window.close()" class="admin_menu">close</a> <a href="#" onclick="sendDate('', '', '');" class="admin_menu">clear date</a></div>
98
<br />
99
</body>
100
<?php
101
} // end action=banning
102
 
103
 
104
 
105
/////////////////////////////////////////////////////////////////////////////////////////
106
// PHP Calendar Class Version 1.4 (5th March 2001)
107
//
108
// Copyright David Wilkinson 2000 - 2001. All Rights reserved.
109
//
110
// This software may be used, modified and distributed freely
111
// providing this copyright notice remains intact at the head
112
// of the file.
113
//
114
// This software is freeware. The author accepts no liability for
115
// any loss or damages whatsoever incurred directly or indirectly
116
// from the use of this script. The author of this software makes
117
// no claims as to its fitness for any purpose whatsoever. If you
118
// wish to use this software you should first satisfy yourself that
119
// it meets your requirements.
120
//
121
// URL:   http://www.cascade.org.uk/software/php/calendar/
122
// Email: davidw@cascade.org.uk
123
 
124
class Calendar
125
{
126
    /*
127
        Constructor for the Calendar class
128
    */
129
    function Calendar()
130
    {
131
    }
132
 
133
 
134
    /*
135
        Get the array of strings used to label the days of the week. This array contains seven
136
        elements, one for each day of the week. The first entry in this array represents Sunday.
137
    */
138
    function getDayNames()
139
    {
140
        return $this->dayNames;
141
    }
142
 
143
 
144
    /*
145
        Set the array of strings used to label the days of the week. This array must contain seven
146
        elements, one for each day of the week. The first entry in this array represents Sunday.
147
    */
148
    function setDayNames($names)
149
    {
150
        $this->dayNames = $names;
151
    }
152
 
153
    /*
154
        Get the array of strings used to label the months of the year. This array contains twelve
155
        elements, one for each month of the year. The first entry in this array represents January.
156
    */
157
    function getMonthNames()
158
    {
159
        return $this->monthNames;
160
    }
161
 
162
    /*
163
        Set the array of strings used to label the months of the year. This array must contain twelve
164
        elements, one for each month of the year. The first entry in this array represents January.
165
    */
166
    function setMonthNames($names)
167
    {
168
        $this->monthNames = $names;
169
    }
170
 
171
 
172
 
173
    /*
174
        Gets the start day of the week. This is the day that appears in the first column
175
        of the calendar. Sunday = 0.
176
    */
177
      function getStartDay()
178
    {
179
        return $this->startDay;
180
    }
181
 
182
    /*
183
        Sets the start day of the week. This is the day that appears in the first column
184
        of the calendar. Sunday = 0.
185
    */
186
    function setStartDay($day)
187
    {
188
        $this->startDay = $day;
189
    }
190
 
191
 
192
    /*
193
        Gets the start month of the year. This is the month that appears first in the year
194
        view. January = 1.
195
    */
196
    function getStartMonth()
197
    {
198
        return $this->startMonth;
199
    }
200
 
201
    /*
202
        Sets the start month of the year. This is the month that appears first in the year
203
        view. January = 1.
204
    */
205
    function setStartMonth($month)
206
    {
207
        $this->startMonth = $month;
208
    }
209
 
210
 
211
    /*
212
        Return the URL to link to in order to display a calendar for a given month/year.
213
        You must override this method if you want to activate the "forward" and "back"
214
        feature of the calendar.
215
 
216
        Note: If you return an empty string from this function, no navigation link will
217
        be displayed. This is the default behaviour.
218
 
219
        If the calendar is being displayed in "year" view, $month will be set to zero.
220
    */
221
    //function getCalendarLink($month, $year)
222
    //{
223
    //    return "";
224
    //}
225
 
226
    /*
227
        Return the URL to link to  for a given date.
228
        You must override this method if you want to activate the date linking
229
        feature of the calendar.
230
 
231
        Note: If you return an empty string from this function, no navigation link will
232
        be displayed. This is the default behaviour.
233
    */
234
    function getDateLink($day, $month, $year)
235
    {
236
        return "";
237
    }
238
 
239
 
240
    /*
241
        Return the HTML for the current month
242
    */
243
    function getCurrentMonthView()
244
    {
245
        $d = getdate(time());
246
        return $this->getMonthView($d["mon"], $d["year"]);
247
    }
248
 
249
 
250
    /*
251
        Return the HTML for the current year
252
    */
253
    function getCurrentYearView()
254
    {
255
        $d = getdate(time());
256
        return $this->getYearView($d["year"]);
257
    }
258
 
259
 
260
    /*
261
        Return the HTML for a specified month
262
    */
263
    function getMonthView($month, $year)
264
    {
265
        return $this->getMonthHTML($month, $year);
266
    }
267
 
268
 
269
    /*
270
        Return the HTML for a specified year
271
    */
272
    function getYearView($year)
273
    {
274
        return $this->getYearHTML($year);
275
    }
276
 
277
 
278
 
279
    /********************************************************************************
280
 
281
        The rest are private methods. No user-servicable parts inside.
282
 
283
        You shouldn't need to call any of these functions directly.
284
 
285
    *********************************************************************************/
286
 
287
 
288
    /*
289
        Calculate the number of days in a month, taking into account leap years.
290
    */
291
    function getDaysInMonth($month, $year)
292
    {
293
        if ($month < 1 || $month > 12)
294
        {
295
            return 0;
296
        }
297
 
298
        $d = $this->daysInMonth[$month - 1];
299
 
300
        if ($month == 2)
301
        {
302
            // Check for leap year
303
            // Forget the 4000 rule, I doubt I'll be around then...
304
 
305
            if ($year%4 == 0)
306
            {
307
                if ($year%100 == 0)
308
                {
309
                    if ($year%400 == 0)
310
                    {
311
                        $d = 29;
312
                    }
313
                }
314
                else
315
                {
316
                    $d = 29;
317
                }
318
            }
319
        }
320
 
321
        return $d;
322
    }
323
 
324
 
325
    /*
326
        Generate the HTML for a given month
327
    */
328
    function getMonthHTML($m, $y, $showYear = 1)
329
    {
330
        $s = "";
331
 
332
        $a = $this->adjustDate($m, $y);
333
        $month = $a[0];
334
        $year = $a[1];
335
 
336
      $daysInMonth = $this->getDaysInMonth($month, $year);
337
      $date = getdate(mktime(12, 0, 0, $month, 1, $year));
338
 
339
      $first = $date["wday"];
340
      $monthName = $this->monthNames[$month - 1];
341
 
342
      $prev = $this->adjustDate($month - 1, $year);
343
      $next = $this->adjustDate($month + 1, $year);
344
 
345
      if ($showYear == 1)
346
      {
347
          $prevMonth = $this->getCalendarLink($prev[0], $prev[1]);
348
          $nextMonth = $this->getCalendarLink($next[0], $next[1]);
349
      }
350
      else
351
      {
352
          $prevMonth = "";
353
          $nextMonth = "";
354
      }
355
 
356
      $header = $monthName . (($showYear > 0) ? " " . $year : "");
357
 
358
      $s .= "<table class=\"maintable\">\n";
359
      $s .= "<tr>\n";
360
      $s .= "<td align=\"center\" valign=\"top\">" . (($prevMonth == "") ? "&nbsp;" : "<a href=\"$prevMonth\" class=\"user_thumb_infobox\">&laquo;</a>")  . "</td>\n";
361
      $s .= "<td align=\"center\" valign=\"top\" class=\"tableh1\" colspan=\"5\">$header</td>\n";
362
      $s .= "<td align=\"center\" valign=\"top\">" . (($nextMonth == "") ? "&nbsp;" : "<a href=\"$nextMonth\" class=\"user_thumb_infobox\">&raquo;</a>")  . "</td>\n";
363
      $s .= "</tr>\n";
364
 
365
      $s .= "<tr>\n";
366
      $s .= "<td align=\"center\" valign=\"top\" class=\"tableh1_compact\">" . $this->dayNames[($this->startDay)%7] . "</td>\n";
367
      $s .= "<td align=\"center\" valign=\"top\" class=\"tableh1_compact\">" . $this->dayNames[($this->startDay+1)%7] . "</td>\n";
368
      $s .= "<td align=\"center\" valign=\"top\" class=\"tableh1_compact\">" . $this->dayNames[($this->startDay+2)%7] . "</td>\n";
369
      $s .= "<td align=\"center\" valign=\"top\" class=\"tableh1_compact\">" . $this->dayNames[($this->startDay+3)%7] . "</td>\n";
370
      $s .= "<td align=\"center\" valign=\"top\" class=\"tableh1_compact\">" . $this->dayNames[($this->startDay+4)%7] . "</td>\n";
371
      $s .= "<td align=\"center\" valign=\"top\" class=\"tableh1_compact\">" . $this->dayNames[($this->startDay+5)%7] . "</td>\n";
372
      $s .= "<td align=\"center\" valign=\"top\" class=\"tableh1_compact\">" . $this->dayNames[($this->startDay+6)%7] . "</td>\n";
373
      $s .= "</tr>\n";
374
 
375
      // We need to work out what date to start at so that the first appears in the correct column
376
      $d = $this->startDay + 1 - $first;
377
      while ($d > 1)
378
      {
379
          $d -= 7;
380
      }
381
 
382
        // Make sure we know when today is, so that we can use a different CSS style
383
        $today = getdate(time());
384
 
385
      while ($d <= $daysInMonth)
386
      {
387
          $s .= "<tr>\n";
388
 
389
          for ($i = 0; $i < 7; $i++)
390
          {
391
              $class = ($year == $today["year"] && $month == $today["mon"] && $d == $today["mday"]) ? "tableb" : "tableh2";
392
              $s .= "<td class=\"$class\" align=\"right\" valign=\"top\">";
393
              if ($d > 0 && $d <= $daysInMonth)
394
              {
395
                  $link = $this->getDateLink($d, $month, $year);
396
                  $s .= (($link == "") ? $d : $link.$d."</a>");
397
              }
398
              else
399
              {
400
                  $s .= "&nbsp;";
401
              }
402
                $s .= "</td>\n";
403
              $d++;
404
          }
405
          $s .= "</tr>\n";
406
      }
407
 
408
      $s .= "</table>\n";
409
 
410
      return $s;
411
    }
412
 
413
 
414
    /*
415
        Generate the HTML for a given year
416
    */
417
    function getYearHTML($year)
418
    {
419
        $s = "";
420
      $prev = $this->getCalendarLink(0, $year - 1);
421
      $next = $this->getCalendarLink(0, $year + 1);
422
 
423
        $s .= "<table class=\"maintable\" border=\"0\">\n";
424
        $s .= "<tr>";
425
      $s .= "<td align=\"center\" valign=\"top\" align=\"left\">" . (($prev == "") ? "&nbsp;" : "<a href=\"$prev\">&lt;&lt;</a>")  . "</td>\n";
426
        $s .= "<td class=\"tableh1\" valign=\"top\" align=\"center\">" . (($this->startMonth > 1) ? $year . " - " . ($year + 1) : $year) ."</td>\n";
427
      $s .= "<td align=\"center\" valign=\"top\" align=\"right\">" . (($next == "") ? "&nbsp;" : "<a href=\"$next\">&gt;&gt;</a>")  . "</td>\n";
428
        $s .= "</tr>\n";
429
        $s .= "<tr>";
430
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(0 + $this->startMonth, $year, 0) ."</td>\n";
431
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(1 + $this->startMonth, $year, 0) ."</td>\n";
432
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(2 + $this->startMonth, $year, 0) ."</td>\n";
433
        $s .= "</tr>\n";
434
        $s .= "<tr>\n";
435
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(3 + $this->startMonth, $year, 0) ."</td>\n";
436
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(4 + $this->startMonth, $year, 0) ."</td>\n";
437
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(5 + $this->startMonth, $year, 0) ."</td>\n";
438
        $s .= "</tr>\n";
439
        $s .= "<tr>\n";
440
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(6 + $this->startMonth, $year, 0) ."</td>\n";
441
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(7 + $this->startMonth, $year, 0) ."</td>\n";
442
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(8 + $this->startMonth, $year, 0) ."</td>\n";
443
        $s .= "</tr>\n";
444
        $s .= "<tr>\n";
445
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(9 + $this->startMonth, $year, 0) ."</td>\n";
446
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(10 + $this->startMonth, $year, 0) ."</td>\n";
447
        $s .= "<td class=\"tableh1_compact\" valign=\"top\">" . $this->getMonthHTML(11 + $this->startMonth, $year, 0) ."</td>\n";
448
        $s .= "</tr>\n";
449
        $s .= "</table>\n";
450
 
451
        return $s;
452
    }
453
 
454
    /*
455
        Adjust dates to allow months > 12 and < 0. Just adjust the years appropriately.
456
        e.g. Month 14 of the year 2001 is actually month 2 of year 2002.
457
    */
458
    function adjustDate($month, $year)
459
    {
460
        $a = array();
461
        $a[0] = $month;
462
        $a[1] = $year;
463
 
464
        while ($a[0] > 12)
465
        {
466
            $a[0] -= 12;
467
            $a[1]++;
468
        }
469
 
470
        while ($a[0] <= 0)
471
        {
472
            $a[0] += 12;
473
            $a[1]--;
474
        }
475
 
476
        return $a;
477
    }
478
 
479
    /*
480
        The start day of the week. This is the day that appears in the first column
481
        of the calendar. Sunday = 0.
482
    */
483
    var $startDay = 0;
484
 
485
    /*
486
        The start month of the year. This is the month that appears in the first slot
487
        of the calendar in the year view. January = 1.
488
    */
489
    var $startMonth = 1;
490
 
491
    /*
492
        The labels to display for the days of the week. The first entry in this array
493
        represents Sunday.
494
    */
495
    var $dayNames = array("S", "M", "T", "W", "T", "F", "S");
496
 
497
    /*
498
        The labels to display for the months of the year. The first entry in this array
499
        represents January.
500
    */
501
    var $monthNames = array("January", "February", "March", "April", "May", "June",
502
                            "July", "August", "September", "October", "November", "December");
503
 
504
 
505
    /*
506
        The number of days in each month. You're unlikely to want to change this...
507
        The first entry in this array represents January.
508
    */
509
    var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
510
 
511
}
512
 
513
?>