[1055] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[26461] | 5 | // | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | |
---|
[2297] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[1055] | 23 | |
---|
[25507] | 24 | /** |
---|
| 25 | * @package functions\calendar |
---|
| 26 | */ |
---|
| 27 | |
---|
[1055] | 28 | include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php'); |
---|
| 29 | |
---|
[25507] | 30 | /** level of year view */ |
---|
| 31 | define('CYEAR', 0); |
---|
| 32 | /** level of week view */ |
---|
| 33 | define('CWEEK', 1); |
---|
| 34 | /** level of day view */ |
---|
| 35 | define('CDAY', 2); |
---|
[1057] | 36 | |
---|
[25507] | 37 | |
---|
[1055] | 38 | /** |
---|
| 39 | * Weekly calendar style (composed of years/week in years and days in week) |
---|
| 40 | */ |
---|
[28926] | 41 | class CalendarWeekly extends CalendarBase |
---|
[1055] | 42 | { |
---|
[1059] | 43 | /** |
---|
| 44 | * Initialize the calendar |
---|
[25507] | 45 | * @param string $inner_sql |
---|
[1059] | 46 | */ |
---|
[1086] | 47 | function initialize($inner_sql) |
---|
[1059] | 48 | { |
---|
[1086] | 49 | parent::initialize($inner_sql); |
---|
[12118] | 50 | global $lang, $conf; |
---|
[1069] | 51 | $week_no_labels=array(); |
---|
| 52 | for ($i=1; $i<=53; $i++) |
---|
| 53 | { |
---|
[25005] | 54 | $week_no_labels[$i] = l10n('Week %d', $i); |
---|
[1069] | 55 | //$week_no_labels[$i] = $i; |
---|
| 56 | } |
---|
| 57 | |
---|
[1059] | 58 | $this->calendar_levels = array( |
---|
| 59 | array( |
---|
[4398] | 60 | 'sql'=> pwg_db_get_year($this->date_field), |
---|
[1059] | 61 | 'labels' => null |
---|
| 62 | ), |
---|
| 63 | array( |
---|
[4513] | 64 | 'sql'=> pwg_db_get_week($this->date_field).'+1', |
---|
[1069] | 65 | 'labels' => $week_no_labels, |
---|
[1059] | 66 | ), |
---|
| 67 | array( |
---|
[4513] | 68 | 'sql'=> pwg_db_get_dayofweek($this->date_field).'-1', |
---|
[1059] | 69 | 'labels' => $lang['day'] |
---|
| 70 | ), |
---|
| 71 | ); |
---|
| 72 | //Comment next lines for week starting on Sunday or if MySQL version<4.0.17 |
---|
| 73 | //WEEK(date,5) = "0-53 - Week 1=the first week with a Monday in this year" |
---|
[12118] | 74 | if ('monday' == $conf['week_starts_on']) |
---|
| 75 | { |
---|
| 76 | $this->calendar_levels[CWEEK]['sql'] = pwg_db_get_week($this->date_field, 5).'+1'; |
---|
| 77 | $this->calendar_levels[CDAY]['sql'] = pwg_db_get_weekday($this->date_field); |
---|
[25018] | 78 | $this->calendar_levels[CDAY]['labels'][] = array_shift($this->calendar_levels[CDAY]['labels']); |
---|
[12118] | 79 | } |
---|
[1059] | 80 | } |
---|
| 81 | |
---|
[25507] | 82 | /** |
---|
| 83 | * Generate navigation bars for category page. |
---|
| 84 | * |
---|
| 85 | * @return boolean false indicates that thumbnails where not included |
---|
| 86 | */ |
---|
| 87 | function generate_category_content() |
---|
| 88 | { |
---|
| 89 | global $conf, $page; |
---|
[1055] | 90 | |
---|
[25507] | 91 | if ( count($page['chronology_date'])==0 ) |
---|
| 92 | { |
---|
| 93 | $this->build_nav_bar(CYEAR); // years |
---|
| 94 | } |
---|
| 95 | if ( count($page['chronology_date'])==1 ) |
---|
| 96 | { |
---|
| 97 | $this->build_nav_bar(CWEEK, array()); // week nav bar 1-53 |
---|
| 98 | } |
---|
| 99 | if ( count($page['chronology_date'])==2 ) |
---|
| 100 | { |
---|
| 101 | $this->build_nav_bar(CDAY); // days nav bar Mon-Sun |
---|
| 102 | } |
---|
| 103 | $this->build_next_prev(); |
---|
| 104 | return false; |
---|
[1062] | 105 | } |
---|
[1055] | 106 | |
---|
[25507] | 107 | /** |
---|
| 108 | * Returns a sql WHERE subquery for the date field. |
---|
| 109 | * |
---|
| 110 | * @param int $max_levels (e.g. 2=only year and month) |
---|
| 111 | * @return string |
---|
| 112 | */ |
---|
| 113 | function get_date_where($max_levels=3) |
---|
[1055] | 114 | { |
---|
[25507] | 115 | global $page; |
---|
| 116 | $date = $page['chronology_date']; |
---|
| 117 | while (count($date)>$max_levels) |
---|
| 118 | { |
---|
| 119 | array_pop($date); |
---|
| 120 | } |
---|
| 121 | $res = ''; |
---|
| 122 | if (isset($date[CYEAR]) and $date[CYEAR]!=='any') |
---|
| 123 | { |
---|
| 124 | $y = $date[CYEAR]; |
---|
| 125 | $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'"; |
---|
| 126 | } |
---|
[1055] | 127 | |
---|
[25507] | 128 | if (isset($date[CWEEK]) and $date[CWEEK]!=='any') |
---|
| 129 | { |
---|
| 130 | $res .= ' AND '.$this->calendar_levels[CWEEK]['sql'].'='.$date[CWEEK]; |
---|
| 131 | } |
---|
| 132 | if (isset($date[CDAY]) and $date[CDAY]!=='any') |
---|
| 133 | { |
---|
| 134 | $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY]; |
---|
| 135 | } |
---|
| 136 | if (empty($res)) |
---|
| 137 | { |
---|
| 138 | $res = ' AND '.$this->date_field.' IS NOT NULL'; |
---|
| 139 | } |
---|
| 140 | return $res; |
---|
[1055] | 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
[25507] | 144 | ?> |
---|