url_base = $url_base; if ($view_type==CAL_VIEW_CALENDAR and count($requested)==0) {//case A: no year given - display all years+months if ($this->build_global_calendar($requested)) return true; } if ($view_type==CAL_VIEW_CALENDAR and count($requested)==1) {//case B: year given - display all days in given year if ($this->build_year_calendar($requested)) { $this->build_nav_bar2($view_type, $requested, 0, 'YEAR'); // years return true; } } if ($view_type==CAL_VIEW_CALENDAR and count($requested)==2) {//case C: year+month given - display a nice month calendar $this->build_month_calendar($requested); $this->build_nav_bar2(CAL_VIEW_CALENDAR, $requested, 0, 'YEAR'); // years if (count($requested)>0) $this->build_nav_bar2(CAL_VIEW_CALENDAR, $requested, 1, 'MONTH', $lang['month']); // month return true; } if ($view_type==CAL_VIEW_LIST or count($requested)==3) { $this->build_nav_bar2($view_type, $requested, 0, 'YEAR'); // years if (count($requested)>0) $this->build_nav_bar2($view_type, $requested, 1, 'MONTH', $lang['month']); // month if (count($requested)>1) $this->build_nav_bar2($view_type, $requested, 2, 'DAYOFWEEK' ); // days } return false; } /** * Returns a sql where subquery for the date field * @param array requested selected levels for this calendar * (e.g. 2005,11,5 for 5th of November 2005) * @param int max_levels return the where up to this level * (e.g. 2=only year and month) * @return string */ function get_date_where($requested, $max_levels=3) { while (count($requested)>$max_levels) { array_pop($requested); } $res = ''; if (isset($requested[0]) and $requested[0]!='any') { $b = $requested[0] . '-'; $e = $requested[0] . '-'; if (isset($requested[1]) and $requested[1]!='any') { $b .= $requested[1] . '-'; $e .= $requested[1] . '-'; if (isset($requested[2]) and $requested[2]!='any') { $b .= $requested[2]; $e .= $requested[2]; } else { $b .= '01'; $e .= '31'; } } else { $b .= '01-01'; $e .= '12-31'; if (isset($requested[1]) and $requested[1]!='any') { $res .= ' AND MONTH('.$this->date_field.')='.$requested[1]; } if (isset($requested[2]) and $requested[2]!='any') { $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$requested[2]; } } $res = " AND $this->date_field BETWEEN '$b' AND '$e 23:59:59'" . $res; } else { $res = ' AND '.$this->date_field.' IS NOT NULL'; if (isset($requested[1]) and $requested[1]!='any') { $res .= ' AND MONTH('.$this->date_field.')='.$requested[1]; } if (isset($requested[2]) and $requested[2]!='any') { $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$requested[2]; } } return $res; } //--------------------------------------------------------- private members --- function build_nav_bar2($view_type, $requested, $level, $sql_func, $labels=null) { parent::build_nav_bar($view_type, $requested, $level, $sql_func, '', $labels); } function build_global_calendar(&$requested) { $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%Y%m")) as period, COUNT(id) as count'; $query.= $this->inner_sql; $query.= $this->get_date_where($requested, 0); $query.= ' GROUP BY period'; $result = pwg_query($query); while ($row = mysql_fetch_array($result)) { $y = substr($row['period'], 0, 4); $m = (int)substr($row['period'], 4, 2); if ( ! isset($items[$y]) ) { $items[$y] = array('nb_images'=>0, 'children'=>array() ); } $items[$y]['children'][$m] = $row['count']; $items[$y]['nb_images'] += $row['count']; } //echo ('
'. var_export($items, true) . ''); if (count($items)==1) {// only one year exists so bail out to year view list($y) = array_keys($items); array_push($requested, $y ); return false; } global $lang, $template; foreach ( $items as $year=>$year_data) { $url_base = $this->url_base .'c-'.$year; $nav_bar = ''.$year.''; $nav_bar .= ' ('.$year_data['nb_images'].')'; $nav_bar .= '
'. var_export($items, true) . ''); if (count($items)==1) { // only one month exists so bail out to month view list($m) = array_keys($items); array_push($requested, $m ); if (count($items[$m]['children'])==1) { // or even to day view if everything occured in one day list($d) = array_keys($items[$m]['children']); array_push($requested, $d); } return false; } global $lang, $template; foreach ( $items as $month=>$month_data) { $url_base = $this->url_base.'c-'.$requested[0].'-'.$month; $nav_bar = ''; $nav_bar .= $lang['month'][$month].''; $nav_bar .= ' ('.$month_data['nb_images'].')'; $nav_bar .= '