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

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

calendar redesign: monthly and weekly styles + list/calendar views for monthly

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