source: trunk/include/calendar_weekly.class.php @ 1069

Last change on this file since 1069 was 1069, checked in by rvelices, 18 years ago

calendar: removed some warnings, improved display for weekly style and
worked on css (still not perfect due to IE)

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | branch        : BSF (Best So Far)
7// | file          : $RCSfile$
8// | last update   : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 1014 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php');
28
29define ('CYEAR', 0);
30define ('CWEEK', 1);
31define ('CDAY',  2);
32
33/**
34 * Weekly calendar style (composed of years/week in years and days in week)
35 */
36class Calendar extends CalendarBase
37{
38
39  /**
40   * Initialize the calendar
41   * @param string date_field db column on which this calendar works
42   * @param string inner_sql used for queries (INNER JOIN or normal)
43   * @param array date_components
44   */
45  function initialize($date_field, $inner_sql, $date_components)
46  {
47    parent::initialize($date_field, $inner_sql, $date_components);
48    global $lang;
49    $week_no_labels=array();
50    for ($i=1; $i<=53; $i++)
51    {
52      $week_no_labels[$i] = sprintf( l10n("Week %d"), $i);
53      //$week_no_labels[$i] = $i;
54    }
55
56    $this->calendar_levels = array(
57      array(
58          'sql'=> 'YEAR('.$this->date_field.')',
59          'labels' => null
60        ),
61      array(
62          'sql'=> 'WEEK('.$this->date_field.')+1',
63          'labels' => $week_no_labels,
64        ),
65      array(
66          'sql'=> 'DAYOFWEEK('.$this->date_field.')-1',
67          'labels' => $lang['day']
68        ),
69     );
70    //Comment next lines for week starting on Sunday or if MySQL version<4.0.17
71    //WEEK(date,5) = "0-53 - Week 1=the first week with a Monday in this year"
72    $this->calendar_levels[CWEEK]['sql'] = 'WEEK('.$this->date_field.',5)+1';
73    $this->calendar_levels[CDAY]['sql'] = 'WEEKDAY('.$this->date_field.')';
74    array_push( $this->calendar_levels[CDAY]['labels'],
75                array_shift( $this->calendar_levels[CDAY]['labels'] ) );
76  }
77
78/**
79 * Generate navigation bars for category page
80 * @return boolean false to indicate that thumbnails where not included here
81 */
82function generate_category_content($url_base, $view_type)
83{
84  global $conf;
85
86  $this->url_base = $url_base;
87
88  assert($view_type==CAL_VIEW_LIST);
89
90  if ( count($this->date_components)==0 )
91  {
92    $this->build_nav_bar(CYEAR); // years
93  }
94  if ( count($this->date_components)==1 )
95  {
96    $this->build_nav_bar(CWEEK, array()); // week nav bar 1-53
97  }
98  if ( count($this->date_components)==2 )
99  {
100    $this->build_nav_bar(CDAY); // days nav bar Mon-Sun
101  }
102  $this->build_next_prev();
103  return false;
104}
105
106
107/**
108 * Returns a sql where subquery for the date field
109 * @param int max_levels return the where up to this level
110 * (e.g. 2=only year and week in year)
111 * @return string
112 */
113function get_date_where($max_levels=3)
114{
115  $date = $this->date_components;
116  while (count($date)>$max_levels)
117  {
118    array_pop($date);
119  }
120  $res = '';
121  if (isset($date[CYEAR]) and $date[CYEAR]!=='any')
122  {
123    $y = $date[CYEAR];
124    $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
125  }
126
127  if (isset($date[CWEEK]) and $date[CWEEK]!=='any')
128  {
129    $res .= ' AND '.$this->calendar_levels[CWEEK]['sql'].'='.$date[CWEEK];
130  }
131  if (isset($date[CDAY]) and $date[CDAY]!=='any')
132  {
133    $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
134  }
135  if (empty($res))
136  {
137    $res = ' AND '.$this->date_field.' IS NOT NULL';
138  }
139  return $res;
140}
141
142}
143
144?>
Note: See TracBrowser for help on using the repository browser.