Changeset 1053
- Timestamp:
- Feb 23, 2006, 5:53:11 PM (18 years ago)
- Location:
- trunk/include
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/calendar_base.class.php
r1050 r1053 30 30 class CalendarBase 31 31 { 32 // db column on which this calendar works33 var $date_field;34 // used for queries (INNER JOIN or normal)35 var $inner_sql;36 // base url used when generating html links37 var $url_base;32 // db column on which this calendar works 33 var $date_field; 34 // used for queries (INNER JOIN or normal) 35 var $inner_sql; 36 // base url used when generating html links 37 var $url_base; 38 38 39 function get_date_where()40 {41 die("get_date_where not extended");42 }39 function get_date_where() 40 { 41 die("get_date_where not extended"); 42 } 43 43 44 /**45 * Initialize the calendar46 * @param string date_field db column on which this calendar works47 * @param string inner_sql used for queries (INNER JOIN or normal)48 */49 function initialize($date_field, $inner_sql)50 {51 $this->date_field = $date_field;52 $this->inner_sql = $inner_sql;53 }44 /** 45 * Initialize the calendar 46 * @param string date_field db column on which this calendar works 47 * @param string inner_sql used for queries (INNER JOIN or normal) 48 */ 49 function initialize($date_field, $inner_sql) 50 { 51 $this->date_field = $date_field; 52 $this->inner_sql = $inner_sql; 53 } 54 54 55 55 //--------------------------------------------------------- private members --- 56 /** 57 * Creates a calendar navigation bar. 58 * @param string url_base - links start with this root 59 * @param array items - hash of items to put in the bar (e.g. 2005,2006) 60 * @param array selected_item - item currently selected (e.g. 2005) 61 * @param string class_prefix - html class attribute prefix for span elements 62 * @param bool allow_any - adds any to the end of the bar 63 * @param array labels - optional labels for items (e.g. Jan,Feb,...) 64 * @return string the navigation bar 65 */ 66 function get_nav_bar_from_items($url_base, $items, $selected_item, 67 $class_prefix, $allow_any, $labels=null) 68 { 69 $nav_bar=''; 70 foreach ($items as $item => $nb_images) 56 57 /** 58 * Creates a calendar navigation bar. 59 * 60 * @param string url_base - links start with this root 61 * @param array items - hash of items to put in the bar (e.g. 2005,2006) 62 * @param array selected_item - item currently selected (e.g. 2005) 63 * @param string class_prefix - html class attribute prefix for span elements 64 * @param bool allow_any - adds any to the end of the bar 65 * @param array labels - optional labels for items (e.g. Jan,Feb,...) 66 * @return string the navigation bar 67 */ 68 function get_nav_bar_from_items($url_base, $items, $selected_item, 69 $class_prefix, $allow_any, $labels=null) 71 70 { 72 $label = $item; 73 if (isset($labels[$item])) 71 $nav_bar = ''; 72 73 foreach ($items as $item => $nb_images) 74 74 { 75 $label = $labels[$item]; 75 $label = $item; 76 if (isset($labels[$item])) 77 { 78 $label = $labels[$item]; 79 } 80 if (isset($selected_item) and $item == $selected_item) 81 { 82 $nav_bar .= '<span class="'.$class_prefix.'Sel">'; 83 $nav_bar .= $label; 84 } 85 else 86 { 87 $nav_bar .= '<span class="'.$class_prefix.'">'; 88 $url = $url_base . $item; 89 $nav_bar .= '<a href="'.$url.'">'; 90 $nav_bar .= $label; 91 $nav_bar .= '</a>'; 92 } 93 if ($nb_images > 0) 94 { 95 $nav_bar .= '('.$nb_images.')'; 96 } 97 $nav_bar.= '</span>'; 76 98 } 77 if ( isset($selected_item) and $item==$selected_item ) 99 100 if ($allow_any and count($items) > 1) 78 101 { 79 $nav_bar .= '<span class="'.$class_prefix.'Sel">'; 80 $nav_bar .= $label; 102 $label = l10n('calendar_any'); 103 if (isset($selected_item) and 'any' == $selected_item) 104 { 105 $nav_bar .= '<span class="'.$class_prefix.'Sel">'; 106 $nav_bar .= $label; 107 } 108 else 109 { 110 $nav_bar .= '<span class="'.$class_prefix.'">'; 111 $url = $url_base . 'any'; 112 $nav_bar .= '<a href="'.$url.'">'; 113 $nav_bar .= $label; 114 $nav_bar .= '</a>'; 115 } 116 $nav_bar.= '</span>'; 81 117 } 82 else 83 { 84 $nav_bar .= '<span class="'.$class_prefix.'">'; 85 $url = $url_base . $item; 86 $nav_bar .= '<a href="'.$url.'">'; 87 $nav_bar .= $label; 88 $nav_bar .= '</a>'; 89 } 90 if ($nb_images>0) 91 { 92 $nav_bar .= '('.$nb_images.')'; 93 } 94 $nav_bar.= '</span>'; 118 return $nav_bar; 95 119 } 96 120 97 if ($allow_any and count($items)>1 ) 121 /** 122 * Creates a calendar navigation bar for a given level. 123 * 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) 126 * @param string sql_func - YEAR/MONTH/DAY/WEEK/DAYOFWEEK ... 127 * @param string sql_offset - (e.g. +1 for WEEK - first in year is 1) 128 * @param array labels - optional labels to show in the navigation bar 129 * @return void 130 */ 131 function build_nav_bar($view_type, $requested, $level, $sql_func, 132 $sql_offset='', $labels=null) 98 133 { 99 $label = l10n('calendar_any'); 100 if ( isset($selected_item) and 'any'==$selected_item ) 134 global $template; 135 136 $query = ' 137 SELECT DISTINCT('.$sql_func.'('.$this->date_field.')'.$sql_offset 138 .') as period'; 139 $query.= $this->inner_sql; 140 $query.= $this->get_date_where($requested, $level); 141 $query.= ' 142 GROUP BY period 143 ;'; 144 145 $level_items = array(); 146 $result = pwg_query($query); 147 while ($row = mysql_fetch_array($result)) 101 148 { 102 $nav_bar .= '<span class="'.$class_prefix.'Sel">'; 103 $nav_bar .= $label; 149 $level_items[$row['period']] = 0; 104 150 } 105 else 151 152 $url_base = $this->url_base; 153 $url_base .= $view_type.'-'; 154 for ($i=0; $i<$level; $i++) 106 155 { 107 $nav_bar .= '<span class="'.$class_prefix.'">'; 108 $url = $url_base . 'any'; 109 $nav_bar .= '<a href="'.$url.'">'; 110 $nav_bar .= $label; 111 $nav_bar .= '</a>'; 156 if (isset($requested[$i])) 157 { 158 $url_base .= $requested[$i].'-'; 159 } 112 160 } 113 $nav_bar.= '</span>'; 161 162 $nav_bar = $this->get_nav_bar_from_items( 163 $url_base, 164 $level_items, 165 $requested[$level], 166 'cal', 167 true, 168 $labels 169 ); 170 171 $template->assign_block_vars( 172 'calendar.navbar', 173 array( 174 'BAR' => $nav_bar 175 ) 176 ); 114 177 } 115 return $nav_bar;116 178 } 117 118 119 /**120 * Creates a calendar navigation bar for a given level.121 * @param string view_type - list or calendar (e.g. 'l' or 'c')122 * @param array requested - array of current selected elements (e.g. 2005,10)123 * @param string sql_func - YEAR/MONTH/DAY/WEEK/DAYOFWEEK ...124 * @param string sql_offset - (e.g. +1 for WEEK - first in year is 1)125 * @param array labels - optional labels to show in the navigation bar126 * @return void127 */128 function build_nav_bar($view_type, $requested, $level, $sql_func,129 $sql_offset='', $labels=null)130 {131 global $template;132 $query = 'SELECT DISTINCT('.$sql_func.'('.$this->date_field.')'.$sql_offset133 .') as period';134 $query.= $this->inner_sql;135 $query.= $this->get_date_where($requested, $level);136 $query.= '137 GROUP BY period';138 139 $level_items=array();140 $result = pwg_query($query);141 while ($row = mysql_fetch_array($result))142 {143 $level_items[$row['period']] = 0;144 }145 146 $url_base = $this->url_base;147 $url_base .= $view_type.'-';148 for ($i=0; $i<$level; $i++)149 {150 if (isset($requested[$i]))151 {152 $url_base .= $requested[$i].'-';153 }154 }155 156 $nav_bar = $this->get_nav_bar_from_items( $url_base, $level_items,157 $requested[$level], 'cal', true, $labels);158 159 $template->assign_block_vars( 'calendar.navbar',160 array( 'BAR' => $nav_bar)161 );162 }163 }164 165 179 ?> -
trunk/include/calendar_monthly.class.php
r1051 r1053 74 74 $this->build_nav_bar2($view_type, $requested, 1, 'MONTH', $lang['month']); // month 75 75 if (count($requested)>1) 76 $this->build_nav_bar2($view_type, $requested, 2, 'DAY ' ); // days76 $this->build_nav_bar2($view_type, $requested, 2, 'DAYOFWEEK' ); // days 77 77 } 78 78 return false; … … 124 124 if (isset($requested[2]) and $requested[2]!='any') 125 125 { 126 $res .= ' AND DAY ('.$this->date_field.')='.$requested[2];126 $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$requested[2]; 127 127 } 128 128 } … … 138 138 if (isset($requested[2]) and $requested[2]!='any') 139 139 { 140 $res .= ' AND DAY ('.$this->date_field.')='.$requested[2];140 $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$requested[2]; 141 141 } 142 142 } -
trunk/include/category_default.inc.php
r1047 r1053 80 80 $thumbnail_title .= ' : '.$row['filesize'].' KB'; 81 81 } 82 82 83 // url link on picture.php page 83 $url_link = PHPWG_ROOT_PATH.'picture.php?'; 84 if ( isset($page['cat']) ) 84 $url_link = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id']; 85 86 if (isset($page['cat'])) 85 87 { 86 $url_link .= 'cat='.$page['cat'].'&'; 88 $url_link.= 'cat='.$page['cat'].'&'; 89 90 if ($page['cat'] == 'search') 91 { 92 $url_link.= '&search='.$_GET['search']; 93 } 94 else if ($page['cat'] == 'list') 95 { 96 $url_link.= '&list='.$_GET['list']; 97 } 87 98 } 88 $url_link.= 'image_id='.$row['id']; 89 if ($page['cat'] == 'search') 90 { 91 $url_link.= '&search='.$_GET['search']; 92 } 93 else if ($page['cat'] == 'list') 94 { 95 $url_link.= '&list='.$_GET['list']; 96 } 97 if ( isset($_GET['calendar']) ) 99 100 if (isset($_GET['calendar'])) 98 101 { 99 102 $url_link.= '&calendar='.$_GET['calendar']; -
trunk/include/functions_calendar.inc.php
r1051 r1053 25 25 // +-----------------------------------------------------------------------+ 26 26 27 define('CAL_VIEW_LIST', 'l');28 define('CAL_VIEW_CALENDAR', 'c');27 define('CAL_VIEW_LIST', 'l'); 28 define('CAL_VIEW_CALENDAR', 'c'); 29 29 30 30 function initialize_calendar() … … 34 34 //------------------ initialize the condition on items to take into account --- 35 35 $inner_sql = ' FROM ' . IMAGES_TABLE; 36 if ( !isset($page['cat']) or is_numeric($page['cat']) ) 36 37 if (!isset($page['cat']) or is_numeric($page['cat'])) 37 38 { // we will regenerate the items by including subcats elements 38 $page['cat_nb_images'] =0;39 $page['items'] =array();39 $page['cat_nb_images'] = 0; 40 $page['items'] = array(); 40 41 $inner_sql .= ' 41 42 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; 42 if ( is_numeric($page['cat']) ) 43 { 44 $sub_ids = get_subcat_ids(array($page['cat'])); 45 $sub_ids = array_diff($sub_ids, 46 explode(',', $user['forbidden_categories']) ); 43 44 if (isset($page['cat']) and is_numeric($page['cat'])) 45 { 46 $sub_ids = array_diff( 47 get_subcat_ids(array($page['cat'])), 48 explode(',', $user['forbidden_categories']) 49 ); 50 47 51 if (empty($sub_ids)) 48 52 { … … 70 74 //-------------------------------------- initialize the calendar parameters --- 71 75 pwg_debug('start initialize_calendar'); 76 72 77 $cal_styles = array( 73 array('link'=>'m', 'default_link'=>'', 'name'=>l10n('Monthly'), 74 'include'=>'calendar_monthly.class.php', 'view_calendar'=>true ), 75 array('link'=>'w', 'default_link'=>'w-', 'name'=>l10n('Weekly'), 76 'include'=>'calendar_weekly.class.php', ), 78 // Weekly style 79 array( 80 'link' => 'm', 81 'default_link' => '', 82 'name' => l10n('Monthly'), 83 'include' => 'calendar_monthly.class.php', 84 'view_calendar' => true, 85 ), 86 // Monthly style 87 array( 88 'link' => 'w', 89 'default_link' => 'w-', 90 'name' => l10n('Weekly'), 91 'include' => 'calendar_weekly.class.php', 92 ), 77 93 ); 78 94 79 95 $requested = explode('-', $_GET['calendar']); 80 96 $calendar = null; 81 foreach ($cal_styles as $cal_style)82 { 83 if ($requested[0] ==$cal_style['link'])84 { 85 include( 97 foreach ($cal_styles as $cal_style) 98 { 99 if ($requested[0] == $cal_style['link']) 100 { 101 include(PHPWG_ROOT_PATH.'include/'.$cal_style['include']); 86 102 $calendar = new Calendar(); 87 103 array_shift($requested); … … 89 105 } 90 106 } 91 if ( !isset($calendar) ) 92 { 93 foreach( $cal_styles as $cal_style) 94 { 95 if (''==$cal_style['default_link']) 107 108 if (!isset($calendar)) 109 { 110 foreach($cal_styles as $cal_style) 111 { 112 if ('' == $cal_style['default_link']) 113 { 96 114 break; 115 } 97 116 } 98 117 include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']); … … 100 119 } 101 120 102 $view_type =CAL_VIEW_LIST;103 if ($requested[0] ==CAL_VIEW_LIST)121 $view_type = CAL_VIEW_LIST; 122 if ($requested[0] == CAL_VIEW_LIST) 104 123 { 105 124 array_shift($requested); 106 125 } 107 elseif ($requested[0] ==CAL_VIEW_CALENDAR)126 elseif ($requested[0] == CAL_VIEW_CALENDAR) 108 127 { 109 128 if ($cal_style['view_calendar']) 110 129 { 111 $view_type =CAL_VIEW_CALENDAR;130 $view_type = CAL_VIEW_CALENDAR; 112 131 } 113 132 array_shift($requested); 114 133 } 115 134 // perform a sanity check on $requested 116 while (count($requested) >3)135 while (count($requested) > 3) 117 136 { 118 137 array_pop($requested); … … 120 139 121 140 $any_count = 0; 122 for ($i =0; $i<count($requested); $i++)123 { 124 if ($requested[$i] =='any')125 { 126 if ($view_type ==CAL_VIEW_CALENDAR)141 for ($i = 0; $i < count($requested); $i++) 142 { 143 if ($requested[$i] == 'any') 144 { 145 if ($view_type == CAL_VIEW_CALENDAR) 127 146 {// we dont allow any in calendar view 128 while ($i <count($requested))129 { 130 array_pop( $requested);147 while ($i < count($requested)) 148 { 149 array_pop($requested); 131 150 } 132 151 break; … … 134 153 $any_count++; 135 154 } 136 elseif ( $requested[$i]=='')137 { 138 while ($i <count($requested))139 { 140 array_pop( $requested);141 } 142 } 143 } 144 if ($any_count ==3)155 elseif ($requested[$i] == '') 156 { 157 while ($i < count($requested)) 158 { 159 array_pop($requested); 160 } 161 } 162 } 163 if ($any_count == 3) 145 164 { 146 165 array_pop($requested); … … 151 170 //echo ('<pre>'. var_export($calendar, true) . '</pre>'); 152 171 153 $category_calling = false; 172 // TODO: what makes the list view required? 173 $must_show_list = true; 174 154 175 if (basename($_SERVER["PHP_SELF"]) == 'category.php') 155 176 { 156 $category_calling = true;157 }158 159 $must_show_list = true;160 if ($category_calling)161 {162 177 $template->assign_block_vars('calendar', array()); 163 178 164 $url_base = get_query_string_diff(array('start','calendar')); 165 $url_base .= empty($url_base) ? '?' : '&'; 166 $url_base .= 'calendar='; 167 $url_base = PHPWG_ROOT_PATH.'category.php'.$url_base; 168 169 if ( $calendar->generate_category_content( 170 $url_base.$cal_style['default_link'], $view_type, $requested) ) 171 { 172 unset( $page['thumbnails_include'] ); 173 unset( $page['items'] ); 174 unset( $page['cat_nb_images'] ); 179 $url_base = 180 PHPWG_ROOT_PATH.'category.php' 181 .get_query_string_diff(array('start', 'calendar')) 182 .(empty($url_base) ? '?' : '&') 183 .'calendar=' 184 ; 185 186 if ($calendar->generate_category_content( 187 $url_base.$cal_style['default_link'], 188 $view_type, 189 $requested 190 ) 191 ) 192 { 193 unset( 194 $page['thumbnails_include'], 195 $page['items'], 196 $page['cat_nb_images'] 197 ); 198 175 199 $must_show_list = false; 176 200 } 177 201 178 202 if ($cal_style['view_calendar']) 179 { // Build bar for view modes (List/Calendar)203 { // Build bar for views (List/Calendar) 180 204 $views = array( 181 array(CAL_VIEW_LIST, l10n('List') ), 182 array(CAL_VIEW_CALENDAR, l10n('calendar') ), 183 ); 205 // list view 206 array( 207 'type' => CAL_VIEW_LIST, 208 'label' => l10n('List') 209 ), 210 // calendar view 211 array( 212 'type' => CAL_VIEW_CALENDAR, 213 'label' => l10n('calendar') 214 ), 215 ); 216 184 217 $views_bar = ''; 185 foreach( $views as $view ) 186 { 187 $v = $view[1]; 188 if ( $view_type!=$view[0] ) 189 { 190 $url = $url_base.$cal_style['default_link'].$view[0].'-'; 191 $url .= implode('-', $requested); 192 $v = '<a href="'.$url.'">'.$v.'</a> '; 218 219 foreach ($views as $view) 220 { 221 if ($view_type != $view['type']) 222 { 223 $views_bar.= 224 '<a href="' 225 .$url_base.$cal_style['default_link'].$view['type'].'-' 226 .implode('-', $requested) 227 .'">'.$view['label'].'</a> '; 193 228 } 194 229 else 195 230 { 196 $v = $v.' '; 197 } 198 $views_bar .= $v . ' '; 199 } 200 $template->assign_block_vars('calendar.views', array( 201 'BAR'=>$views_bar 202 )); 231 $views_bar.= $view['label'].' '; 232 } 233 234 $views_bar.= ' '; 235 } 236 237 $template->assign_block_vars( 238 'calendar.views', 239 array( 240 'BAR' => $views_bar, 241 ) 242 ); 203 243 } 204 244 205 245 // Build bar for calendar styles (Monthly, Weekly) 206 246 $styles_bar = ''; 207 foreach ( 208 { 209 if ($cal_style['link'] !=$style['link'])247 foreach ($cal_styles as $style) 248 { 249 if ($cal_style['link'] != $style['link']) 210 250 { 211 251 $url = $url_base.$style['default_link']; … … 222 262 } 223 263 } 224 $template->assign_block_vars( 'calendar.styles', 225 array( 'BAR' => $styles_bar) 226 ); 264 $template->assign_block_vars( 265 'calendar.styles', 266 array( 267 'BAR' => $styles_bar, 268 ) 269 ); 227 270 } // end category calling 228 271 … … 240 283 { 241 284 $order_by = str_replace( 242 243 244 285 'ORDER BY ', 286 'ORDER BY '.$calendar->date_field.',', $conf['order_by'] 287 ); 245 288 $query .= $order_by; 246 289 } 247 290 248 $page['items'] = array_from_query($query, 'id');249 $page['cat_nb_images'] = count($page['items']);291 $page['items'] = array_from_query($query, 'id'); 292 $page['cat_nb_images'] = count($page['items']); 250 293 $page['thumbnails_include'] = 'include/category_default.inc.php'; 251 294 }
Note: See TracChangeset
for help on using the changeset viewer.