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

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

improvement: calendar navigation now uses at maximum one navigation bar
together with a next/previous date links

improvement: calendar view styles now shown in DIV.titrePage (I still need
to move padding from H2 to DIV.titrePage ...)

fix: moved all calendar css colors from template to the theme

  • Property svn:eol-style set to native
File size: 4.5 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    $this->calendar_levels = array(
50      array(
51          'sql'=> 'YEAR('.$this->date_field.')',
52          'labels' => null
53        ),
54      array(
55          'sql'=> 'WEEK('.$this->date_field.')+1',
56          'labels' => null
57        ),
58      array(
59          'sql'=> 'DAYOFWEEK('.$this->date_field.')-1',
60          'labels' => $lang['day']
61        ),
62     );
63    //Comment next lines for week starting on Sunday or if MySQL version<4.0.17
64    //WEEK(date,5) = "0-53 - Week 1=the first week with a Monday in this year"
65    $this->calendar_levels[CWEEK]['sql'] = 'WEEK('.$this->date_field.',5)+1';
66    $this->calendar_levels[CDAY]['sql'] = 'WEEKDAY('.$this->date_field.')';
67    array_push( $this->calendar_levels[CDAY]['labels'],
68                array_shift( $this->calendar_levels[CDAY]['labels'] ) );
69  }
70
71/**
72 * Generate navigation bars for category page
73 * @return boolean false to indicate that thumbnails where not included here
74 */
75function generate_category_content($url_base, $view_type)
76{
77  global $conf;
78
79  $this->url_base = $url_base;
80
81  assert($view_type==CAL_VIEW_LIST);
82
83  if ( count($this->date_components)==0 )
84  {
85    $this->build_nav_bar(CYEAR); // years
86  }
87  if ( count($this->date_components)==1 )
88  {
89    $this->build_nav_bar(CWEEK); // week nav bar 1-53
90  }
91  if ( count($this->date_components)==2 )
92  {
93    $this->build_nav_bar(CDAY); // days nav bar Mon-Sun
94  }
95  $this->build_next_prev();
96  return false;
97}
98
99
100/**
101 * Returns a sql where subquery for the date field
102 * @param int max_levels return the where up to this level
103 * (e.g. 2=only year and week in year)
104 * @return string
105 */
106function get_date_where($max_levels=3)
107{
108  $date = $this->date_components;
109  while (count($date)>$max_levels)
110  {
111    array_pop($date);
112  }
113  $res = '';
114  if (isset($date[CYEAR]) and $date[CYEAR]!='any')
115  {
116    $y = $date[CYEAR];
117    $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
118  }
119
120  if (isset($date[CWEEK]) and $date[CWEEK]!='any')
121  {
122    $res .= ' AND '.$this->calendar_levels[CWEEK]['sql'].'='.$date[CWEEK];
123  }
124  if (isset($date[CDAY]) and $date[CDAY]!='any')
125  {
126    $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
127  }
128  if (empty($res))
129  {
130    $res = ' AND '.$this->date_field.' IS NOT NULL';
131  }
132  return $res;
133}
134
135}
136
137?>
Note: See TracBrowser for help on using the repository browser.