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