Changeset 1057


Ignore:
Timestamp:
Feb 24, 2006, 6:58:48 AM (18 years ago)
Author:
rvelices
Message:

calendar: added posted/created chronology

calendar: added a where are we bar (like: created/2005/august)

calendar: possibility to hide the All/Any buttons ($confcalendar_show_any)

calendar: possibility to display a single navigation bar instead of
several navigation bars ($confcalendar_multi_bar)

calendar: tried to simplify code and improve readability
(still requires a review)

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/category.php

    r1056 r1057  
    302302  'special_cat',
    303303  array(
    304     'URL' => PHPWG_ROOT_PATH.'category.php?calendar=m-c',
     304    'URL' => PHPWG_ROOT_PATH.'category.php?calendar=monthly-c',
    305305    'TITLE' => $lang['calendar_hint'],
    306306    'NAME' => $lang['calendar']
  • trunk/include/calendar_base.class.php

    r1056 r1057  
    3636  // base url used when generating html links
    3737  var $url_base;
     38  // array of date components e.g. (2005,10,12) ...
     39  var $date_components;
    3840
    39   function get_date_where()
    40   {
    41     die("get_date_where not extended");
    42   }
    4341
    4442  /**
     
    4644   * @param string date_field db column on which this calendar works
    4745   * @param string inner_sql used for queries (INNER JOIN or normal)
     46   * @param array date_components
    4847   */
    49   function initialize($date_field, $inner_sql)
     48  function initialize($date_field, $inner_sql, $date_components)
    5049  {
    5150    $this->date_field = $date_field;
    5251    $this->inner_sql = $inner_sql;
     52    $this->date_components = $date_components;
    5353  }
    5454
    5555//--------------------------------------------------------- private members ---
    56 
     56  /**
     57   * Returns a display name for a date component optionally using labels
     58  */
     59  function get_date_component_label($date_component, $labels=null)
     60  {
     61    $label = $date_component;
     62    if (isset($labels[$date_component]))
     63    {
     64      $label = $labels[$date_component];
     65    }
     66    elseif ($date_component == 'any' )
     67    {
     68      $label = l10n('calendar_any');
     69    }
     70    return $label;
     71  }
     72 
    5773  /**
    5874   * Creates a calendar navigation bar.
     
    97113      $nav_bar.= '</span>';
    98114    }
    99 
    100     if ($allow_any and count($items) > 1)
     115    global $conf;
     116    if ($conf['calendar_show_any'] and $allow_any and count($items) > 1)
    101117    {
    102118      $label = l10n('calendar_any');
     
    122138   * Creates a calendar navigation bar for a given level.
    123139   *
    124    * @param string view_type - list or calendar (e.g. 'l' or 'c')
    125    * @param array requested - array of current selected elements (e.g. 2005,10)
    126140   * @param string sql_func - YEAR/MONTH/DAY/WEEK/DAYOFWEEK ...
    127141   * @param string sql_offset - (e.g. +1 for WEEK - first in year is 1)
     
    129143   * @return void
    130144   */
    131   function build_nav_bar($view_type, $requested, $level, $sql_func,
     145  function build_nav_bar($level, $sql_func,
    132146                         $sql_offset='', $labels=null)
    133147  {
     
    138152      .') as period';
    139153    $query.= $this->inner_sql;
    140     $query.= $this->get_date_where($requested, $level);
     154    $query.= $this->get_date_where($level);
    141155    $query.= '
    142156  GROUP BY period
     
    151165
    152166    $url_base = $this->url_base;
    153     $url_base .= $view_type.'-';
    154167    for ($i=0; $i<$level; $i++)
    155168    {
    156       if (isset($requested[$i]))
     169      if (isset($this->date_components[$i]))
    157170      {
    158         $url_base .= $requested[$i].'-';
     171        $url_base .= $this->date_components[$i].'-';
    159172      }
    160173    }
    161 
     174    $selected = null;
     175    if ( isset($this->date_components[$level]) )
     176    {
     177      $selected = $this->date_components[$level];
     178    }
    162179    $nav_bar = $this->get_nav_bar_from_items(
    163180      $url_base,
    164181      $level_items,
    165       isset($requested[$level]) ? $requested[$level] : null,
     182      $selected,
    166183      'cal',
    167184      true,
  • trunk/include/calendar_monthly.class.php

    r1056 r1057  
    2727include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php');
    2828
     29define ('CYEAR',  0);
     30define ('CMONTH', 1);
     31define ('CDAY',   2);
     32
    2933/**
    3034 * Monthly calendar style (composed of years/months and days)
     
    3842 * where not included here, true otherwise
    3943 */
    40 function generate_category_content($url_base, $view_type, &$requested)
    41 {
    42   global $lang;
     44function generate_category_content($url_base, $view_type)
     45{
     46  global $lang, $conf;
    4347
    4448  $this->url_base = $url_base;
    4549
    46   if ($view_type==CAL_VIEW_CALENDAR and count($requested)==0)
    47   {//case A: no year given - display all years+months
    48     if ($this->build_global_calendar($requested))
     50  if ($view_type==CAL_VIEW_CALENDAR)
     51  {
     52    if ( count($this->date_components)==0 )
     53    {//case A: no year given - display all years+months
     54      if ($this->build_global_calendar())
     55        return true;
     56    }
     57
     58    if ( count($this->date_components)==1 )
     59    {//case B: year given - display all days in given year
     60      if ($this->build_year_calendar())
     61      {
     62        if ( $conf['calendar_multi_bar'] )
     63          $this->build_nav_bar2(CYEAR, 'YEAR'); // years
     64        return true;
     65      }
     66    }
     67
     68    if ( count($this->date_components)==2 )
     69    {//case C: year+month given - display a nice month calendar
     70      $this->build_month_calendar();
     71      if ( $conf['calendar_multi_bar'] )
     72      {
     73        $this->build_nav_bar2(CYEAR, 'YEAR'); // years
     74      }
     75      if (count($this->date_components)>=1 and
     76          ( $conf['calendar_multi_bar'] or count($this->date_components)==1 ) )
     77      {
     78        $this->build_nav_bar2(CMONTH, 'MONTH', $lang['month']); // month
     79      }
    4980      return true;
    50   }
    51 
    52   if ($view_type==CAL_VIEW_CALENDAR and count($requested)==1)
    53   {//case B: year given - display all days in given year
    54     if ($this->build_year_calendar($requested))
    55     {
    56       $this->build_nav_bar2($view_type, $requested, 0, 'YEAR'); // years
    57       return true;
    58     }
    59   }
    60 
    61   if ($view_type==CAL_VIEW_CALENDAR and count($requested)==2)
    62   {//case C: year+month given - display a nice month calendar
    63     $this->build_month_calendar($requested);
    64     $this->build_nav_bar2(CAL_VIEW_CALENDAR, $requested, 0, 'YEAR'); // years
    65     if (count($requested)>0)
    66       $this->build_nav_bar2(CAL_VIEW_CALENDAR, $requested, 1, 'MONTH', $lang['month']); // month
    67     return true;
    68   }
    69 
    70   if ($view_type==CAL_VIEW_LIST or count($requested)==3)
    71   {
    72     $this->build_nav_bar2($view_type, $requested, 0, 'YEAR'); // years
    73     if (count($requested)>0)
    74       $this->build_nav_bar2($view_type, $requested, 1, 'MONTH', $lang['month']); // month
    75     if (count($requested)>1)
    76       $this->build_nav_bar2($view_type, $requested, 2, 'DAYOFMONTH' ); // days
     81    }
     82  }
     83
     84  if ($view_type==CAL_VIEW_LIST or count($this->date_components)==3)
     85  {
     86    if ( $conf['calendar_multi_bar'] or count($this->date_components)==0 )
     87    {
     88      $this->build_nav_bar2(CYEAR, 'YEAR'); // years
     89    }
     90    if ( count($this->date_components)>=1 and
     91        ( $conf['calendar_multi_bar'] or count($this->date_components)==1 )
     92       )
     93    {
     94      $this->build_nav_bar2(CMONTH, 'MONTH', $lang['month']); // month
     95    }
     96    if ( count($this->date_components)>=2 )
     97    {
     98      $this->build_nav_bar2(CDAY, 'DAYOFMONTH' ); // days
     99    }
    77100  }
    78101  return false;
     
    82105/**
    83106 * Returns a sql where subquery for the date field
    84  * @param array requested selected levels for this calendar
    85  * (e.g. 2005,11,5 for 5th of November 2005)
    86107 * @param int max_levels return the where up to this level
    87108 * (e.g. 2=only year and month)
    88109 * @return string
    89110 */
    90 function get_date_where($requested, $max_levels=3)
    91 {
    92   while (count($requested)>$max_levels)
    93   {
    94     array_pop($requested);
     111function get_date_where($max_levels=3)
     112{
     113  $date = $this->date_components;
     114  while (count($date)>$max_levels)
     115  {
     116    array_pop($date);
    95117  }
    96118  $res = '';
    97   if (isset($requested[0]) and $requested[0]!='any')
    98   {
    99     $b = $requested[0] . '-';
    100     $e = $requested[0] . '-';
    101     if (isset($requested[1]) and $requested[1]!='any')
    102     {
    103       $b .= $requested[1] . '-';
    104       $e .= $requested[1] . '-';
    105       if (isset($requested[2]) and $requested[2]!='any')
    106       {
    107         $b .= $requested[2];
    108         $e .= $requested[2];
     119  if (isset($date[CYEAR]) and $date[CYEAR]!='any')
     120  {
     121    $b = $date[CYEAR] . '-';
     122    $e = $date[CYEAR] . '-';
     123    if (isset($date[CMONTH]) and $date[CMONTH]!='any')
     124    {
     125      $b .= $date[CMONTH] . '-';
     126      $e .= $date[CMONTH] . '-';
     127      if (isset($date[CDAY]) and $date[CDAY]!='any')
     128      {
     129        $b .= $date[CDAY];
     130        $e .= $date[CDAY];
    109131      }
    110132      else
     
    118140      $b .= '01-01';
    119141      $e .= '12-31';
    120       if (isset($requested[1]) and $requested[1]!='any')
    121       {
    122         $res .= ' AND MONTH('.$this->date_field.')='.$requested[1];
    123       }
    124       if (isset($requested[2]) and $requested[2]!='any')
    125       {
    126         $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$requested[2];
     142      if (isset($date[CMONTH]) and $date[CMONTH]!='any')
     143      {
     144        $res .= ' AND MONTH('.$this->date_field.')='.$date[CMONTH];
     145      }
     146      if (isset($date[2]) and $date[2]!='any')
     147      {
     148        $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$date[CDAY];
    127149      }
    128150    }
     
    132154  {
    133155    $res = ' AND '.$this->date_field.' IS NOT NULL';
    134     if (isset($requested[1]) and $requested[1]!='any')
    135     {
    136       $res .= ' AND MONTH('.$this->date_field.')='.$requested[1];
    137     }
    138     if (isset($requested[2]) and $requested[2]!='any')
    139     {
    140       $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$requested[2];
     156    if (isset($date[CMONTH]) and $date[CMONTH]!='any')
     157    {
     158      $res .= ' AND MONTH('.$this->date_field.')='.$date[CMONTH];
     159    }
     160    if (isset($date[CDAY]) and $date[CDAY]!='any')
     161    {
     162      $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$date[CDAY];
    141163    }
    142164  }
     
    144166}
    145167
     168
     169function get_display_name()
     170{
     171  global $conf, $lang;
     172  $res = '';
     173  $url = $this->url_base;
     174  if ( isset($this->date_components[CYEAR]) )
     175  {
     176    $res .= $conf['level_separator'];
     177    $url .= $this->date_components[CYEAR].'-';
     178    $res .=
     179      '<a href="'.$url.'">'
     180      .$this->get_date_component_label($this->date_components[CYEAR])
     181      .'</a>';
     182  }
     183  if ( isset($this->date_components[CMONTH]) )
     184  {
     185    $res .= $conf['level_separator'];
     186    $url .= $this->date_components[CMONTH].'-';
     187    $res .=
     188      '<a href="'.$url.'">'
     189      .$this->get_date_component_label(
     190                     $this->date_components[CMONTH],
     191                     $lang['month']
     192                    )
     193      .'</a>';
     194  }
     195  if ( isset($this->date_components[CDAY]) )
     196  {
     197    $res .= $conf['level_separator'];
     198    $url .= $this->date_components[CDAY].'-';
     199    $res .=
     200      '<a href="'.$url.'">'
     201      .$this->get_date_component_label($this->date_components[CDAY])
     202      .'</a>';
     203  }
     204
     205  return $res;
     206}
     207
     208
    146209//--------------------------------------------------------- private members ---
    147 function build_nav_bar2($view_type, $requested, $level, $sql_func, $labels=null)
    148 {
    149   parent::build_nav_bar($view_type, $requested, $level, $sql_func, '', $labels);
    150 }
    151 
    152 function build_global_calendar(&$requested)
    153 {
    154   assert( count($requested) == 0 );
     210function build_nav_bar2($level, $sql_func, $labels=null)
     211{
     212  parent::build_nav_bar($level, $sql_func, '', $labels);
     213}
     214
     215function build_global_calendar()
     216{
     217  assert( count($this->date_components) == 0 );
    155218  $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%Y%m")) as period,
    156219            COUNT(id) as count';
    157220  $query.= $this->inner_sql;
    158   $query.= $this->get_date_where($requested);
     221  $query.= $this->get_date_where();
    159222  $query.= '
    160223  GROUP BY period';
     
    176239  {// only one year exists so bail out to year view
    177240    list($y) = array_keys($items);
    178     array_push($requested, $y );
     241    $this->date_components[CYEAR] = $y;
    179242    return false;
    180243  }
     
    183246  foreach ( $items as $year=>$year_data)
    184247  {
    185     $url_base = $this->url_base .'c-'.$year;
     248    $url_base = $this->url_base.$year;
    186249
    187250    $nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">'.$year.'</a>';
     
    200263}
    201264
    202 function build_year_calendar(&$requested)
    203 {
    204   assert( count($requested) == 1 );
     265function build_year_calendar()
     266{
     267  assert( count($this->date_components) == 1 );
    205268  $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%m%d")) as period,
    206269            COUNT(id) as count';
    207270  $query.= $this->inner_sql;
    208   $query.= $this->get_date_where($requested);
     271  $query.= $this->get_date_where();
    209272  $query.= '
    210273  GROUP BY period';
     
    226289  { // only one month exists so bail out to month view
    227290    list($m) = array_keys($items);
    228     array_push($requested, $m );
     291    $this->date_components[CMONTH] = $m;
    229292    if (count($items[$m]['children'])==1)
    230293    { // or even to day view if everything occured in one day
    231294      list($d) = array_keys($items[$m]['children']);
    232       array_push($requested, $d);
     295      $this->date_components[CDAY] = $d;
    233296    }
    234297    return false;
     
    237300  foreach ( $items as $month=>$month_data)
    238301  {
    239     $url_base = $this->url_base.'c-'.$requested[0].'-'.$month;
     302    $url_base = $this->url_base.$this->date_components[CYEAR].'-'.$month;
    240303
    241304    $nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">';
     
    256319}
    257320
    258 function build_month_calendar($requested)
     321function build_month_calendar()
    259322{
    260323  $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%d")) as period,
    261324            COUNT(id) as count';
    262325  $query.= $this->inner_sql;
    263   $query.= $this->get_date_where($requested, 2);
     326  $query.= $this->get_date_where($this->date_components);
    264327  $query.= '
    265328  GROUP BY period';
     
    278341  foreach ( $items as $day=>$nb_images)
    279342  {
    280     $url_base = $this->url_base.'c-'.$requested[0].'-'.$requested[1].'-'.$day;
    281     $requested[2]=$day;
     343    $url_base = $this->url_base.
     344          $this->date_components[CYEAR].'-'.
     345          $this->date_components[CMONTH].'-'.$day;
     346    $this->date_components[CDAY]=$day;
    282347    $query = '
    283348SELECT file,tn_ext,path, DAYOFWEEK('.$this->date_field.')-1 as dw';
    284349    $query.= $this->inner_sql;
    285     $query.= $this->get_date_where($requested);
     350    $query.= $this->get_date_where();
    286351    $query.= '
    287352  ORDER BY RAND()
    288353  LIMIT 0,1';
     354    unset ( $this->date_components[CDAY] );
    289355
    290356    $row = mysql_fetch_array(pwg_query($query));
  • trunk/include/calendar_weekly.class.php

    r1055 r1057  
    2727include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php');
    2828
     29define ('CYEAR', 0);
     30define ('CWEEK', 1);
     31define ('CDAY',  2);
     32
    2933/**
    3034 * Weekly calendar style (composed of years/week in years and days in week)
     
    3741 * @return boolean false to indicate that thumbnails where not included here
    3842 */
    39 function generate_category_content($url_base, $view_type, &$requested)
     43function generate_category_content($url_base, $view_type)
    4044{
    41   global $lang;
     45  global $lang, $conf;
    4246
    4347  $this->url_base = $url_base;
     
    4549  assert($view_type==CAL_VIEW_LIST);
    4650
    47   $this->build_nav_bar($view_type, $requested, 0, 'YEAR'); // years
    48   if (count($requested)>0)
    49     $this->build_nav_bar($view_type, $requested, 1, 'WEEK', '+1' ); // month
    50   if (count($requested)>1)
    51     $this->build_nav_bar($view_type, $requested, 2, 'DAYOFWEEK', '-1',
     51  if ( $conf['calendar_multi_bar'] or count($this->date_components)==0 )
     52  {
     53    $this->build_nav_bar(CYEAR, 'YEAR'); // years
     54  }
     55  if ( count($this->date_components)>=1 and
     56      ( $conf['calendar_multi_bar'] or count($this->date_components)==1 )
     57     )
     58  {
     59    $this->build_nav_bar(CWEEK, 'WEEK', '+1' ); // month
     60  }
     61  if ( count($this->date_components)>=2 )
     62  {
     63    $this->build_nav_bar(CDAY, 'DAYOFWEEK', '-1',
    5264                         $lang['day'] ); // days
     65  }
    5366  return false;
    5467}
     
    5770/**
    5871 * Returns a sql where subquery for the date field
    59  * @param array requested selected levels for this calendar
    60  * (e.g. 2005,42,1 for 41st week of 2005, Monday)
    6172 * @param int max_levels return the where up to this level
    6273 * (e.g. 2=only year and week in year)
    6374 * @return string
    6475 */
    65 function get_date_where($requested, $max_levels=3)
     76function get_date_where($max_levels=3)
    6677{
    67   while (count($requested)>$max_levels)
     78  $date_components = $this->date_components;
     79  while (count($date_components)>$max_levels)
    6880  {
    69     array_pop($requested);
     81    array_pop($date_components);
    7082  }
    7183  $res = '';
    72   if (isset($requested[0]) and $requested[0]!='any')
     84  if (isset($date_components[CYEAR]) and $date_components[CYEAR]!='any')
    7385  {
    74     $y = $requested[0];
     86    $y = $date_components[CYEAR];
    7587    $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
    7688  }
    7789
    78   if (isset($requested[1]) and $requested[1]!='any')
     90  if (isset($date_components[CWEEK]) and $date_components[CWEEK]!='any')
    7991  {
    80     $res .= ' AND WEEK('.$this->date_field.')+1='.$requested[1];
     92    $res .= ' AND WEEK('.$this->date_field.')+1='.$date_components[CWEEK];
    8193  }
    82   if (isset($requested[2]) and $requested[2]!='any')
     94  if (isset($date_components[CDAY]) and $date_components[CDAY]!='any')
    8395  {
    84     $res .= ' AND DAYOFWEEK('.$this->date_field.')-1='.$requested[2];
     96    $res .= ' AND DAYOFWEEK('.$this->date_field.')-1='
     97            .$date_components[CDAY];
    8598  }
    8699  if (empty($res))
     
    91104}
    92105
     106function get_display_name()
     107{
     108  global $conf,$lang;
     109  $res = '';
     110  $url = $this->url_base;
     111  if ( isset($this->date_components[CYEAR]) )
     112  {
     113    $res .= $conf['level_separator'];
     114    $url .= $this->date_components[CYEAR].'-';
     115    $res .=
     116      '<a href="'.$url.'">'
     117      .$this->get_date_component_label($this->date_components[CYEAR])
     118      .'</a>';
     119  }
     120  if ( isset($this->date_components[CWEEK]) )
     121  {
     122    $res .= $conf['level_separator'];
     123    $url .= $this->date_components[CWEEK].'-';
     124    $res .=
     125      '<a href="'.$url.'">'
     126      .$this->get_date_component_label($this->date_components[CWEEK])
     127      .'</a>';
     128  }
     129  if ( isset($this->date_components[CDAY]) )
     130  {
     131    $res .= $conf['level_separator'];
     132    $url .= $this->date_components[CDAY].'-';
     133    $res .=
     134      '<a href="'.$url.'">'
     135      .$this->get_date_component_label(
     136                    $this->date_components[CDAY],
     137                    $lang['day']
     138                    )
     139      .'</a>';
     140  }
     141  return $res;
     142}
     143
    93144}
    94145
  • trunk/include/config_default.inc.php

    r1044 r1057  
    9191$conf['calendar_datefield'] = 'date_creation';
    9292
     93// calendar_multi_bar : the calendar shows a maximum number of
     94// year/month/week/day navigation bars
     95$conf['calendar_multi_bar'] = true;
     96
     97// calendar_show_any : the calendar shows an aditional 'any' button in the
     98// year/month/week/day navigation bars
     99$conf['calendar_show_any'] = true;
     100
    93101// newcat_default_commentable : at creation, must a category be commentable
    94102// or not ?
  • trunk/include/functions_calendar.inc.php

    r1056 r1057  
    2828define('CAL_VIEW_CALENDAR', 'c');
    2929
     30function get_calendar_parameter($options, &$parameters )
     31{
     32  if ( count($parameters) and isset($options[$parameters[0]]) )
     33  {
     34    return array_shift($parameters);
     35  }
     36  else
     37  {
     38    foreach ($options as $option => $data)
     39    {
     40       if ( empty( $data['default_link'] ) )
     41       {
     42         break;
     43       }
     44    }
     45    return $option;
     46  }
     47}
     48
    3049function initialize_calendar()
    3150{
     
    7493//-------------------------------------- initialize the calendar parameters ---
    7594  pwg_debug('start initialize_calendar');
    76  
    77   $cal_styles = array(
     95  // the parameters look like (FIELD)?(STYLE)?(VIEW)?(DATE COMPONENTS)?
     96  // FIELD = (created-|posted-)
     97  // STYLE = (m-|w-)
     98  // VIEW  = (l-|c-)
     99  // DATE COMPONENTS= YEAR(-MONTH/WEEK)?(-DAY)?
     100
     101  $fields = array(
     102    // Created
     103    'created' => array(
     104       // TODO change next line when calendar_datefield disapears
     105      'default_link'   => ( $conf['calendar_datefield']=='date_creation' ? '' : 'created-' ),
     106      'label'          => l10n('Creation date'),
     107      'db_field'       => 'date_creation',
     108      ),
     109    // Posted
     110    'posted' => array(
     111      // TODO change next line when calendar_datefield disapears
     112      'default_link'   => ( $conf['calendar_datefield']=='date_available' ? '' : 'posted-' ),
     113      'label'          => l10n('Availability date'),
     114      'db_field'       => 'date_available',
     115      ),
     116    );
     117
     118  $styles = array(
    78119    // Monthly style
    79     array(
    80       'link'           => 'm',
     120    'monthly' => array(
    81121      'default_link'   => '',
    82       'name'           => l10n('Monthly'),
     122      'label'           => l10n('Monthly'),
    83123      'include'        => 'calendar_monthly.class.php',
    84124      'view_calendar'  => true,
    85125      ),
    86126    // Weekly style   
    87     array(
    88       'link'           => 'w',
    89       'default_link'   => 'w-',
    90       'name'           => l10n('Weekly'),
     127    'weekly' => array(
     128      'default_link'   => 'weekly-',
     129      'label'           => l10n('Weekly'),
    91130      'include'        => 'calendar_weekly.class.php',
    92131      'view_calendar'  => false,
     
    94133    );
    95134
     135  $views = array(
     136    // list view
     137    CAL_VIEW_LIST => array(
     138      'default_link'   => '',
     139      'label' => l10n('List')
     140      ),
     141    // calendar view
     142    CAL_VIEW_CALENDAR => array(
     143      'default_link'   => CAL_VIEW_CALENDAR.'-',
     144      'label' => l10n('calendar')
     145      ),
     146    );
     147
    96148  $requested = explode('-', $_GET['calendar']);
    97   $calendar = null;
    98   foreach ($cal_styles as $cal_style)
    99   {
    100     if ($requested[0] == $cal_style['link'])
    101     {
    102       include(PHPWG_ROOT_PATH.'include/'.$cal_style['include']);
    103       $calendar = new Calendar();
    104       array_shift($requested);
    105       break;
    106     }
    107   }
    108  
    109   if (!isset($calendar))
    110   {
    111     foreach($cal_styles as $cal_style)
    112     {
    113       if ('' == $cal_style['default_link'])
    114       {
    115         break;
    116       }
    117     }
    118     include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']);
    119     $calendar = new Calendar();
    120   }
    121 
    122   $view_type = CAL_VIEW_LIST;
    123   if ($requested[0] == CAL_VIEW_LIST)
    124   {
    125     array_shift($requested);
    126   }
    127   elseif ($requested[0] == CAL_VIEW_CALENDAR)
    128   {
    129     if ($cal_style['view_calendar'])
    130     {
    131       $view_type = CAL_VIEW_CALENDAR;
    132     }
    133     array_shift($requested);
    134   }
     149 
     150  // Retrieve calendar field
     151  $cal_field = get_calendar_parameter($fields, $requested);
     152 
     153  // Retrieve style
     154  $cal_style = get_calendar_parameter($styles, $requested);
     155  include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']);
     156  $calendar = new Calendar();
     157
     158  // Retrieve view
     159  $cal_view = get_calendar_parameter($views, $requested);
     160  if ( CAL_VIEW_CALENDAR==$cal_view and !$styles[$cal_style]['view_calendar'] )
     161  {
     162    $cal_view=CAL_VIEW_LIST;
     163  }
     164
    135165  // perform a sanity check on $requested
    136166  while (count($requested) > 3)
     
    144174    if ($requested[$i] == 'any')
    145175    {
    146       if ($view_type == CAL_VIEW_CALENDAR)
     176      if ($cal_view == CAL_VIEW_CALENDAR)
    147177      {// we dont allow any in calendar view
    148178        while ($i < count($requested))
     
    166196    array_pop($requested);
    167197  }
    168 
    169   $calendar->initialize($conf['calendar_datefield'], $inner_sql);
    170   //echo ('<pre>'. var_export($requested, true) . '</pre>');
    171   //echo ('<pre>'. var_export($calendar, true) . '</pre>');
    172 
    173   // TODO: what makes the list view required?
    174   $must_show_list = true;
    175  
     198 
     199  $calendar->initialize($fields[$cal_field]['db_field'], $inner_sql, $requested);
     200 
     201  //echo ('<pre>'. var_export($fields, true) . '</pre>');
     202
     203  $url_base =
     204    PHPWG_ROOT_PATH.'category.php'
     205    .get_query_string_diff(array('start', 'calendar'))
     206    .(empty($url_base) ? '?' : '&')
     207    .'calendar='.$cal_field.'-'
     208    ;
     209
     210  $must_show_list = true; // true until calendar generates its own display
    176211  if (basename($_SERVER["PHP_SELF"]) == 'category.php')
    177212  {
    178213    $template->assign_block_vars('calendar', array());
    179214
    180     $url_base =
    181       PHPWG_ROOT_PATH.'category.php'
    182       .get_query_string_diff(array('start', 'calendar'))
    183       .(empty($url_base) ? '?' : '&')
    184       .'calendar='
    185       ;
    186 
    187215    if ($calendar->generate_category_content(
    188           $url_base.$cal_style['default_link'],
    189           $view_type,
    190           $requested
     216          $url_base.$cal_style.'-'.$cal_view.'-',
     217          $cal_view
    191218          )
    192219       )
     
    200227      $must_show_list = false;
    201228    }
    202 
    203     if ($cal_style['view_calendar'])
    204     { // Build bar for views (List/Calendar)
    205       $views = array(
    206         // list view
    207         array(
    208           'type'  => CAL_VIEW_LIST,
    209           'label' => l10n('List')
    210           ),
    211         // calendar view
    212         array(
    213           'type'  => CAL_VIEW_CALENDAR,
    214           'label' => l10n('calendar')
    215           ),
    216         );
    217      
    218       $views_bar = '';
    219 
    220       foreach ($views as $view)
     229   
     230    $template->assign_block_vars( 'calendar.views', array() );
     231    foreach ($styles as $style => $style_data)
     232    {
     233      foreach ($views as $view => $view_data)
    221234      {
    222         if ($view_type != $view['type'])
     235        if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR)
    223236        {
    224           $views_bar.=
    225             '<a href="'
    226             .$url_base.$cal_style['default_link'].$view['type'].'-'
    227             .implode('-', $requested)
    228             .'">'.$view['label'].'</a> ';
     237          $selected = '';
     238          $url = $url_base.$style.'-'.$view;
     239          if ($style==$cal_style)
     240          {
     241            $url .= '-'.implode('-', $calendar->date_components);
     242            if ( $view==$cal_view )
     243            {
     244              $selected = 'SELECTED';
     245            }
     246          }
     247          else
     248          {
     249            if (isset($calendar->date_components[0]))
     250            {
     251              $url .= '-' . $calendar->date_components[0];
     252            }
     253          }
     254          $template->assign_block_vars(
     255            'calendar.views.view',
     256            array(
     257              'VALUE' => $url,
     258              'CONTENT' => $style_data['label'].' ('.$view_data['label'].')',
     259              'SELECTED' => $selected,
     260              )
     261            );
    229262        }
    230         else
    231         {
    232           $views_bar.= $view['label'].' ';
    233         }
    234        
    235         $views_bar.= ' ';
    236263      }
    237      
    238       $template->assign_block_vars(
    239         'calendar.views',
    240         array(
    241           'BAR' => $views_bar,
    242           )
    243         );
    244     }
    245 
    246     // Build bar for calendar styles (Monthly, Weekly)
    247     $styles_bar = '';
    248     foreach ($cal_styles as $style)
    249     {
    250       if ($cal_style['link'] != $style['link'])
    251       {
    252         $url = $url_base.$style['default_link'];
    253         $url .= $view_type;
    254         if (isset($requested[0]))
    255         {
    256           $url .= '-' . $requested[0];
    257         }
    258         $styles_bar .= '<a href="'. $url . '">'.$style['name'].'</a> ';
    259       }
    260       else
    261       {
    262         $styles_bar .=  $style['name'].' ';
    263       }
    264     }
    265     $template->assign_block_vars(
    266       'calendar.styles',
    267       array(
    268         'BAR' => $styles_bar,
    269         )
    270       );
     264    }
    271265  } // end category calling
    272266
     267  $calendar_title =
     268      '<a href="'.$url_base.$cal_style.'-'.$cal_view.'">'
     269      .$fields[$cal_field]['label'].'</a>';
     270  $calendar_title.= $calendar->get_display_name();
     271  $template->assign_block_vars(
     272    'calendar',
     273    array(
     274      'TITLE' => $calendar_title,
     275      )
     276    );
     277 
    273278  if ($must_show_list)
    274279  {
    275280    $query = 'SELECT DISTINCT(id)';
    276281    $query .= $calendar->inner_sql;
    277     $query .= $calendar->get_date_where($requested);
     282    $query .= $calendar->get_date_where();
    278283    if ( isset($page['super_order_by']) )
    279284    {
  • trunk/picture.php

    r1056 r1057  
    794794{
    795795  $val = format_date($picture['current']['date_creation']);
    796   if ( $conf['calendar_datefield'] == 'date_creation' )
    797   {
    798     $infos['INFO_CREATION_DATE'] = '<a href="'.
    799        PHPWG_ROOT_PATH.'category.php?calendar=c-'.
     796  $infos['INFO_CREATION_DATE'] = '<a href="'.
     797       PHPWG_ROOT_PATH.'category.php?calendar=created-c-'.
    800798       $picture['current']['date_creation'].'">'.$val.'</a>';
    801   }
    802   else
    803   {
    804      $infos['INFO_CREATION_DATE'] = $val;
    805   }
    806799}
    807800else
     
    812805// date of availability
    813806$val = format_date($picture['current']['date_available'], 'mysql_datetime');
    814 if ( $conf['calendar_datefield'] == 'date_available' )
    815 {
    816   $infos['INFO_AVAILABILITY_DATE'] = '<a href="'.
    817      PHPWG_ROOT_PATH.'category.php?calendar=c-'.
    818      substr($picture['current']['date_available'],0,10).'">'.$val.'</a>';
    819 }
    820 else
    821 {
    822    $infos['INFO_AVAILABILITY_DATE'] = $val;
    823 }
     807$infos['INFO_AVAILABILITY_DATE'] = '<a href="'.
     808   PHPWG_ROOT_PATH.'category.php?calendar=posted-c-'.
     809   substr($picture['current']['date_available'],0,10).'">'.$val.'</a>';
    824810
    825811// size in pixels
  • trunk/template/yoga/category.tpl

    r1051 r1057  
    139139    </ul>
    140140   
    141   <h2>{TITLE}</h2>
    142    
     141  <h2>{TITLE}
     142  <!-- BEGIN calendar -->
     143  <br/>{calendar.TITLE}
     144  <!-- END calendar --></h2>
    143145  </div> <!-- content -->
    144146   
    145147<!-- BEGIN calendar -->
    146 <!-- BEGIN styles -->
    147 <div class="calendarStyles">Style: {calendar.styles.BAR}</div>
    148 <!-- END styles -->
    149 
    150148<!-- BEGIN views -->
    151 <div class="calendarViews">{calendar.views.BAR}</div>
     149<div class="calendarViews">
     150<select onchange="document.location = this.options[this.selectedIndex].value;">
     151<!-- BEGIN view -->
     152  <option value="{calendar.views.view.VALUE}" {calendar.views.view.SELECTED}>{calendar.views.view.CONTENT}</option>
     153<!-- END view -->
     154</select>
     155</div><br/>
    152156<!-- END views -->
    153 <br/>
     157
    154158<!-- BEGIN navbar -->
    155159<div class="navigationBar">{calendar.navbar.BAR}</div>
  • trunk/template/yoga/content.css

    r1050 r1057  
    180180
    181181
    182 #content DIV.calendarStyles {
     182#content DIV.calendarViews {
    183183  float: left;
    184 }
    185 
    186 #content DIV.calendarViews {
    187   float: right;
    188184}
    189185
Note: See TracChangeset for help on using the changeset viewer.