source: trunk/include/calendar_base.class.php @ 1055

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

try and set propset svn:eol-style native

  • Property svn:eol-style set to native
File size: 5.6 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
27/**
28 * Base class for monthly and weekly calendar styles
29 */
30class CalendarBase
31{
32  // db column on which this calendar works
33  var $date_field;
34  // used for queries (INNER JOIN or normal)
35  var $inner_sql;
36  // base url used when generating html links
37  var $url_base;
38
39  function get_date_where()
40  {
41    die("get_date_where not extended");
42  }
43
44  /**
45   * Initialize the calendar
46   * @param string date_field db column on which this calendar works
47   * @param string inner_sql used for queries (INNER JOIN or normal)
48   */
49  function initialize($date_field, $inner_sql)
50  {
51    $this->date_field = $date_field;
52    $this->inner_sql = $inner_sql;
53  }
54
55//--------------------------------------------------------- private members ---
56
57  /**
58   * Creates a calendar navigation bar.
59   *
60   * @param string url_base - links start with this root
61   * @param array items - hash of items to put in the bar (e.g. 2005,2006)
62   * @param array selected_item - item currently selected (e.g. 2005)
63   * @param string class_prefix - html class attribute prefix for span elements
64   * @param bool allow_any - adds any to the end of the bar
65   * @param array labels - optional labels for items (e.g. Jan,Feb,...)
66   * @return string the navigation bar
67   */
68  function get_nav_bar_from_items($url_base, $items, $selected_item,
69                                  $class_prefix, $allow_any, $labels=null)
70  {
71    $nav_bar = '';
72     
73    foreach ($items as $item => $nb_images)
74    {
75      $label = $item;
76      if (isset($labels[$item]))
77      {
78        $label = $labels[$item];
79      }
80      if (isset($selected_item) and $item == $selected_item)
81      {
82        $nav_bar .= '<span class="'.$class_prefix.'Sel">';
83        $nav_bar .= $label;
84      }
85      else
86      {
87        $nav_bar .= '<span class="'.$class_prefix.'">';
88        $url = $url_base . $item;
89        $nav_bar .= '<a href="'.$url.'">';
90        $nav_bar .= $label;
91        $nav_bar .= '</a>';
92      }
93      if ($nb_images > 0)
94      {
95        $nav_bar .= '('.$nb_images.')';
96      }
97      $nav_bar.= '</span>';
98    }
99
100    if ($allow_any and count($items) > 1)
101    {
102      $label = l10n('calendar_any');
103      if (isset($selected_item) and 'any' == $selected_item)
104      {
105        $nav_bar .= '<span class="'.$class_prefix.'Sel">';
106        $nav_bar .= $label;
107      }
108      else
109      {
110        $nav_bar .= '<span class="'.$class_prefix.'">';
111        $url = $url_base . 'any';
112        $nav_bar .= '<a href="'.$url.'">';
113        $nav_bar .= $label;
114        $nav_bar .= '</a>';
115      }
116      $nav_bar.= '</span>';
117    }
118    return $nav_bar;
119  }
120
121  /**
122   * Creates a calendar navigation bar for a given level.
123   *
124   * @param string view_type - list or calendar (e.g. 'l' or 'c')
125   * @param array requested - array of current selected elements (e.g. 2005,10)
126   * @param string sql_func - YEAR/MONTH/DAY/WEEK/DAYOFWEEK ...
127   * @param string sql_offset - (e.g. +1 for WEEK - first in year is 1)
128   * @param array labels - optional labels to show in the navigation bar
129   * @return void
130   */
131  function build_nav_bar($view_type, $requested, $level, $sql_func,
132                         $sql_offset='', $labels=null)
133  {
134    global $template;
135   
136    $query = '
137SELECT DISTINCT('.$sql_func.'('.$this->date_field.')'.$sql_offset
138      .') as period';
139    $query.= $this->inner_sql;
140    $query.= $this->get_date_where($requested, $level);
141    $query.= '
142  GROUP BY period
143;';
144
145    $level_items = array();
146    $result = pwg_query($query);
147    while ($row = mysql_fetch_array($result))
148    {
149      $level_items[$row['period']] = 0;
150    }
151
152    $url_base = $this->url_base;
153    $url_base .= $view_type.'-';
154    for ($i=0; $i<$level; $i++)
155    {
156      if (isset($requested[$i]))
157      {
158        $url_base .= $requested[$i].'-';
159      }
160    }
161
162    $nav_bar = $this->get_nav_bar_from_items(
163      $url_base,
164      $level_items,
165      $requested[$level],
166      'cal',
167      true,
168      $labels
169      );
170
171    $template->assign_block_vars(
172      'calendar.navbar',
173      array(
174        'BAR' => $nav_bar
175        )
176      );
177  }
178}
179?>
Note: See TracBrowser for help on using the repository browser.