[1055] | 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 | include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php'); |
---|
| 28 | |
---|
[1057] | 29 | define ('CYEAR', 0); |
---|
| 30 | define ('CWEEK', 1); |
---|
| 31 | define ('CDAY', 2); |
---|
| 32 | |
---|
[1055] | 33 | /** |
---|
| 34 | * Weekly calendar style (composed of years/week in years and days in week) |
---|
| 35 | */ |
---|
| 36 | class Calendar extends CalendarBase |
---|
| 37 | { |
---|
| 38 | |
---|
[1059] | 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 | |
---|
[1055] | 71 | /** |
---|
| 72 | * Generate navigation bars for category page |
---|
| 73 | * @return boolean false to indicate that thumbnails where not included here |
---|
| 74 | */ |
---|
[1057] | 75 | function generate_category_content($url_base, $view_type) |
---|
[1055] | 76 | { |
---|
[1059] | 77 | global $conf; |
---|
[1055] | 78 | |
---|
| 79 | $this->url_base = $url_base; |
---|
| 80 | |
---|
| 81 | assert($view_type==CAL_VIEW_LIST); |
---|
| 82 | |
---|
[1059] | 83 | $this->build_nav_bar(CYEAR); // years |
---|
| 84 | if ( count($this->date_components)>=1 ) |
---|
[1057] | 85 | { |
---|
[1059] | 86 | $this->build_nav_bar(CWEEK); // week nav bar 1-53 |
---|
[1057] | 87 | } |
---|
| 88 | if ( count($this->date_components)>=2 ) |
---|
| 89 | { |
---|
[1059] | 90 | $this->build_nav_bar(CDAY); // days nav bar Mon-Sun |
---|
[1057] | 91 | } |
---|
[1055] | 92 | return false; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | /** |
---|
| 97 | * Returns a sql where subquery for the date field |
---|
| 98 | * @param int max_levels return the where up to this level |
---|
| 99 | * (e.g. 2=only year and week in year) |
---|
| 100 | * @return string |
---|
| 101 | */ |
---|
[1057] | 102 | function get_date_where($max_levels=3) |
---|
[1055] | 103 | { |
---|
[1059] | 104 | $date = $this->date_components; |
---|
| 105 | while (count($date)>$max_levels) |
---|
[1055] | 106 | { |
---|
[1059] | 107 | array_pop($date); |
---|
[1055] | 108 | } |
---|
| 109 | $res = ''; |
---|
[1059] | 110 | if (isset($date[CYEAR]) and $date[CYEAR]!='any') |
---|
[1055] | 111 | { |
---|
[1059] | 112 | $y = $date[CYEAR]; |
---|
[1055] | 113 | $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'"; |
---|
| 114 | } |
---|
| 115 | |
---|
[1059] | 116 | if (isset($date[CWEEK]) and $date[CWEEK]!='any') |
---|
[1055] | 117 | { |
---|
[1059] | 118 | $res .= ' AND '.$this->calendar_levels[CWEEK]['sql'].'='.$date[CWEEK]; |
---|
[1055] | 119 | } |
---|
[1059] | 120 | if (isset($date[CDAY]) and $date[CDAY]!='any') |
---|
[1055] | 121 | { |
---|
[1059] | 122 | $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY]; |
---|
[1055] | 123 | } |
---|
| 124 | if (empty($res)) |
---|
| 125 | { |
---|
| 126 | $res = ' AND '.$this->date_field.' IS NOT NULL'; |
---|
| 127 | } |
---|
| 128 | return $res; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | } |
---|
| 132 | |
---|
[1050] | 133 | ?> |
---|