[6779] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare API - nextmatchs * |
---|
| 4 | * Written by Joseph Engo <jengo@phpgroupware.org> * |
---|
| 5 | * and Bettina Gille [ceb@phpgroupware.org] * |
---|
| 6 | * Handles limiting number of rows displayed * |
---|
| 7 | * Copyright (C) 2000, 2001 Joseph Engo * |
---|
| 8 | * Copyright (C) 2002, 2003 Joseph Engo, Bettina Gille * |
---|
| 9 | * ------------------------------------------------------------------------ * |
---|
| 10 | * This library is part of the eGroupWare API * |
---|
| 11 | * http://www.egroupware.org * |
---|
| 12 | * ------------------------------------------------------------------------ * |
---|
| 13 | * This library is free software; you can redistribute it and/or modify it * |
---|
| 14 | * under the terms of the GNU Lesser General Public License as published by * |
---|
| 15 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
| 16 | * or any later version. * |
---|
| 17 | * This library is distributed in the hope that it will be useful, but * |
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
| 20 | * See the GNU Lesser General Public License for more details. * |
---|
| 21 | * You should have received a copy of the GNU Lesser General Public License * |
---|
| 22 | * along with this library; if not, write to the Free Software Foundation, * |
---|
| 23 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
| 24 | \**************************************************************************/ |
---|
| 25 | |
---|
| 26 | /*! |
---|
| 27 | @class nextmatchs |
---|
| 28 | @abstract |
---|
| 29 | */ |
---|
| 30 | class nextmatchs |
---|
| 31 | { |
---|
| 32 | var $maxmatches; |
---|
| 33 | var $action; |
---|
| 34 | var $template; |
---|
| 35 | var $extra_filters = array(); |
---|
| 36 | |
---|
| 37 | function nextmatchs($website=False) |
---|
| 38 | { |
---|
| 39 | if(!$website) |
---|
| 40 | { |
---|
| 41 | $this->template = createobject('phpgwapi.Template',PHPGW_TEMPLATE_DIR); |
---|
| 42 | $this->template->set_file(array( |
---|
| 43 | '_nextmatchs' => 'nextmatchs.tpl' |
---|
| 44 | )); |
---|
| 45 | $this->template->set_block('_nextmatchs','nextmatchs'); |
---|
| 46 | $this->template->set_block('_nextmatchs','filter'); |
---|
| 47 | $this->template->set_block('_nextmatchs','form'); |
---|
| 48 | $this->template->set_block('_nextmatchs','icon'); |
---|
| 49 | $this->template->set_block('_nextmatchs','link'); |
---|
| 50 | $this->template->set_block('_nextmatchs','search'); |
---|
| 51 | $this->template->set_block('_nextmatchs','cats'); |
---|
| 52 | $this->template->set_block('_nextmatchs','search_filter'); |
---|
| 53 | $this->template->set_block('_nextmatchs','cats_search_filter'); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | if(isset($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) && |
---|
| 57 | (int)$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0) |
---|
| 58 | { |
---|
| 59 | $this->maxmatches = (int)$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']; |
---|
| 60 | } |
---|
| 61 | else |
---|
| 62 | { |
---|
| 63 | $this->maxmatches = 15; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | $this->_start = (int) get_var('start',array('GLOBAL','POST','GET')); |
---|
| 67 | |
---|
| 68 | foreach(array('menuaction','filter','qfield','order','sort') as $name) |
---|
| 69 | { |
---|
| 70 | $var = '_'.$name; |
---|
| 71 | $this->$var = get_var($name,array('GLOBAL','POST','GET')); |
---|
| 72 | if (!preg_match('/^[a-z0-9_. -]*$/i',$this->$var)) |
---|
| 73 | { |
---|
| 74 | $this->$var = ''; |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | if (!is_object($GLOBALS['phpgw']->html)) |
---|
| 78 | { |
---|
| 79 | $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html'); |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | /*! |
---|
| 84 | @function set_icon |
---|
| 85 | @abstract ? |
---|
| 86 | @param $align ? |
---|
| 87 | @param $img_src ? |
---|
| 88 | @param $label ? |
---|
| 89 | */ |
---|
| 90 | function set_icon($align,$img,$label) |
---|
| 91 | { |
---|
| 92 | $var = array( |
---|
| 93 | 'align' => $align, |
---|
| 94 | 'img' => $GLOBALS['phpgw']->common->image('phpgwapi',$img), |
---|
| 95 | 'label' => lang($label), |
---|
| 96 | 'border' => 0 |
---|
| 97 | ); |
---|
| 98 | $this->template->set_var($var); |
---|
| 99 | return $this->template->fp('out','link'); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | /*! |
---|
| 103 | @function page |
---|
| 104 | @abstract ? |
---|
| 105 | */ |
---|
| 106 | function page($extravars='') |
---|
| 107 | { |
---|
| 108 | if($extravars && is_string($extravars) && substr($extravars,0,1)!='&') |
---|
| 109 | { |
---|
| 110 | $extras = '&'.$extravars; |
---|
| 111 | } |
---|
| 112 | elseif($extravars && is_array($extravars)) |
---|
| 113 | { |
---|
| 114 | foreach($extravars as $var => $value) |
---|
| 115 | { |
---|
| 116 | if($var != 'menuaction') |
---|
| 117 | { |
---|
| 118 | $t_extras[] = $var.'='.$value; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | $extras = "&".implode($t_extras,'&'); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | return $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->_menuaction.$extras); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | /*! |
---|
| 128 | @function set_link |
---|
| 129 | @abstract ? |
---|
| 130 | @param $img_src ? |
---|
| 131 | @param $label ? |
---|
| 132 | @param $link ? |
---|
| 133 | @param $extravars ? |
---|
| 134 | */ |
---|
| 135 | function set_link($align,$img,$link,$alt,$extravars) |
---|
| 136 | { |
---|
| 137 | $var = Array( |
---|
| 138 | 'align' => $align, |
---|
| 139 | 'action' => ($this->_menuaction?$this->page($extravars):$GLOBALS['phpgw']->link($link)), |
---|
| 140 | 'form_name' => $img, |
---|
| 141 | 'hidden' => $GLOBALS['phpgw']->html->input_hidden($extravars), |
---|
| 142 | 'img' => $GLOBALS['phpgw']->common->image('phpgwapi',$img), |
---|
| 143 | 'label' => $alt, |
---|
| 144 | 'border' => 0, |
---|
| 145 | 'start' => $extravars['start'] |
---|
| 146 | ); |
---|
| 147 | $this->template->set_var($var); |
---|
| 148 | return $this->template->fp('out','form'); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | /*! |
---|
| 152 | @function show_tpl |
---|
| 153 | @abstract ? |
---|
| 154 | @param $sn ? |
---|
| 155 | @param $start ? |
---|
| 156 | @param $total ? |
---|
| 157 | @param $extra ? |
---|
| 158 | @param $twidth ? |
---|
| 159 | @param $bgtheme ? |
---|
| 160 | @param $search_obj ? |
---|
| 161 | @param $filter_obj ? |
---|
| 162 | @param $showsearch ? |
---|
| 163 | */ |
---|
| 164 | function show_tpl($sn,$localstart,$total,$extra, $twidth, $bgtheme,$search_obj=0,$filter_obj=1,$showsearch=1,$yours=0,$cat_id=0,$cat_field='fcat_id') |
---|
| 165 | { |
---|
| 166 | if (!is_object($GLOBALS['phpgw']->categories)) |
---|
| 167 | { |
---|
| 168 | $GLOBALS['phpgw']->categories = CreateObject('phpgwapi.categories'); |
---|
| 169 | } |
---|
| 170 | $extravars = $this->split_extras($extravars,$extra); |
---|
| 171 | |
---|
| 172 | $var = array( |
---|
| 173 | 'form_action' => ($this->_menuaction?$this->page($extra):$GLOBALS['phpgw']->link($sn, $extra)), |
---|
| 174 | 'lang_category' => lang('Category'), |
---|
| 175 | 'lang_all' => lang('All'), |
---|
| 176 | 'lang_select' => lang('Select'), |
---|
| 177 | 'cat_field' => $cat_field, |
---|
| 178 | 'categories' => $GLOBALS['phpgw']->categories->formated_list('select','all',$cat_id,'True'), |
---|
| 179 | 'hidden' => $GLOBALS['phpgw']->html->input_hidden(array( |
---|
| 180 | 'filter' => $this->_filter, |
---|
| 181 | 'qfield' => $this->_qfield, |
---|
| 182 | 'start' => (int)$localstart, |
---|
| 183 | 'order' => $this->_order, |
---|
| 184 | 'sort' => $this->_sort, |
---|
| 185 | 'query' => $GLOBALS['query'], |
---|
| 186 | )), |
---|
| 187 | 'query_value' => $GLOBALS['phpgw']->html->htmlspecialchars($GLOBALS['query']), |
---|
| 188 | 'table_width' => $twidth, |
---|
| 189 | 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], |
---|
| 190 | 'left' => $this->left($sn,(int)$localstart,$total,$extra), |
---|
| 191 | 'search' => ($showsearch?$this->search($search_obj):''), |
---|
| 192 | 'filter' => ($filter_obj?$this->filter($filter_obj,$yours):''), |
---|
| 193 | 'right' => $this->right($sn,(int)$localstart,$total,$extra) |
---|
| 194 | ); |
---|
| 195 | $this->template->set_var($var); |
---|
| 196 | $this->template->parse('cats','cats'); |
---|
| 197 | $this->template->parse('cats_search_filter_data','cats_search_filter'); |
---|
| 198 | return $this->template->fp('out','nextmatchs'); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | function split_extras($extravars,$extradata) |
---|
| 202 | { |
---|
| 203 | if($extradata) |
---|
| 204 | { |
---|
| 205 | if(!is_array($extradata)) |
---|
| 206 | { |
---|
| 207 | parse_str($extradata,$extradata); |
---|
| 208 | } |
---|
| 209 | foreach($extradata as $var => $value) |
---|
| 210 | { |
---|
| 211 | if($var != 'menuaction') |
---|
| 212 | { |
---|
| 213 | $extravars[$var] = $value; |
---|
| 214 | } |
---|
| 215 | else |
---|
| 216 | { |
---|
| 217 | $this->_menuaction = $value; |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | return $extravars; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | function extras_to_string($extra) |
---|
| 225 | { |
---|
| 226 | if(is_array($extra)) |
---|
| 227 | { |
---|
| 228 | foreach($extra as $var => $value) |
---|
| 229 | { |
---|
| 230 | $t_extras[] = $var . '=' . urlencode($value); |
---|
| 231 | } |
---|
| 232 | $extra_s = '&' . implode('&',$t_extras); |
---|
| 233 | } |
---|
| 234 | return $extra_s; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | /*! |
---|
| 238 | @function left |
---|
| 239 | @abstract ? |
---|
| 240 | @param $scriptname ? |
---|
| 241 | @param $start ? |
---|
| 242 | @param $total ? |
---|
| 243 | @param $extradate ? |
---|
| 244 | */ |
---|
| 245 | function left($scriptname,$start,$total,$extradata = '') |
---|
| 246 | { |
---|
| 247 | $extravars = Array( |
---|
| 248 | 'order' => $this->_order, |
---|
| 249 | 'filter' => $this->_filter, |
---|
| 250 | 'q_field' => $this->_qfield, |
---|
| 251 | 'sort' => $this->_sort, |
---|
| 252 | 'query' => urlencode(stripslashes(@$GLOBALS['query'])) |
---|
| 253 | ); |
---|
| 254 | |
---|
| 255 | $extravars = $this->split_extras($extravars,$extradata); |
---|
| 256 | $ret_str = ''; |
---|
| 257 | |
---|
| 258 | $start = (int) $start; |
---|
| 259 | |
---|
| 260 | if ($start != 0) |
---|
| 261 | { |
---|
| 262 | $extravars['start'] = 0; |
---|
| 263 | $ret_str .= $this->set_link('left','first.png',$scriptname,lang('First page'),$extravars); |
---|
| 264 | // Changing the sorting order screaws up the starting number |
---|
| 265 | if (($start - $this->maxmatches) < 0) |
---|
| 266 | { |
---|
| 267 | $extravars['start'] = 0; |
---|
| 268 | } |
---|
| 269 | else |
---|
| 270 | { |
---|
| 271 | $extravars['start'] = ($start - $this->maxmatches); |
---|
| 272 | } |
---|
| 273 | $ret_str .= $this->set_link('left','left.png',$scriptname,lang('Previous page'),$extravars); |
---|
| 274 | } |
---|
| 275 | else |
---|
| 276 | { |
---|
| 277 | $ret_str .= $this->set_icon('left','first-grey.png','First page'); |
---|
| 278 | $ret_str .= $this->set_icon('left','left-grey.png','Previous page'); |
---|
| 279 | } |
---|
| 280 | return $ret_str; |
---|
| 281 | } /* left() */ |
---|
| 282 | |
---|
| 283 | /*! |
---|
| 284 | @function right |
---|
| 285 | @abstract ? |
---|
| 286 | @param $scriptname ? |
---|
| 287 | @param $start ? |
---|
| 288 | @param $total ? |
---|
| 289 | @param $extradate ? |
---|
| 290 | */ |
---|
| 291 | function right($scriptname,$start,$total,$extradata = '') |
---|
| 292 | { |
---|
| 293 | $extravars = Array( |
---|
| 294 | 'order' => $this->_order, |
---|
| 295 | 'filter' => $this->_filter, |
---|
| 296 | 'q_field' => $this->_qfield, |
---|
| 297 | 'sort' => $this->_sort, |
---|
| 298 | 'query' => urlencode(stripslashes(@$GLOBALS['query'])) |
---|
| 299 | ); |
---|
| 300 | |
---|
| 301 | $extravars = $this->split_extras($extravars,$extradata); |
---|
| 302 | $ret_str = ''; |
---|
| 303 | |
---|
| 304 | $start = (int) $start; |
---|
| 305 | |
---|
| 306 | if (($total > $this->maxmatches) && |
---|
| 307 | ($total > $start + $this->maxmatches)) |
---|
| 308 | { |
---|
| 309 | $extravars['start'] = ($start + $this->maxmatches); |
---|
| 310 | $ret_str .= $this->set_link('right','right.png',$scriptname,lang('Next page'),$extravars); |
---|
| 311 | $num_regs_last_page = $total % $this->maxmatches; |
---|
| 312 | $extravars['start'] = ($total - $num_regs_last_page); |
---|
| 313 | $ret_str .= $this->set_link('right','last.png',$scriptname,lang('Last page'),$extravars); |
---|
| 314 | } |
---|
| 315 | else |
---|
| 316 | { |
---|
| 317 | $ret_str .= $this->set_icon('right','right-grey.png','Next page'); |
---|
| 318 | $ret_str .= $this->set_icon('right','last-grey.png','Last page'); |
---|
| 319 | } |
---|
| 320 | return $ret_str; |
---|
| 321 | } /* right() */ |
---|
| 322 | |
---|
| 323 | /*! |
---|
| 324 | @function search_filter |
---|
| 325 | @abstract ? |
---|
| 326 | @param $search_obj default 0 |
---|
| 327 | */ |
---|
| 328 | function search_filter($search_obj=0,$filter_obj=1,$yours=0,$link='',$extra='') |
---|
| 329 | { |
---|
| 330 | $var = array( |
---|
| 331 | 'form_action' => ($this->_menuaction?$this->page($extra):$GLOBALS['phpgw']->link($sn, $extra)), |
---|
| 332 | 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], |
---|
| 333 | 'hidden' => $GLOBALS['phpgw']->html->input_hidden(array( |
---|
| 334 | 'filter' => $this->_filter, |
---|
| 335 | 'qfield' => $this->_qfield, |
---|
| 336 | 'start' => 0, |
---|
| 337 | 'order' => $this->_order, |
---|
| 338 | 'sort' => $this->_sort, |
---|
| 339 | 'query' => $GLOBALS['query'], |
---|
| 340 | )), |
---|
| 341 | 'search' => $this->search($search_obj), |
---|
| 342 | 'filter' => ($filter_obj?$this->filter($filter_obj,$yours):'') |
---|
| 343 | ); |
---|
| 344 | $this->template->set_var($var); |
---|
| 345 | return $this->template->fp('out','search_filter'); |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | /*! |
---|
| 349 | @function cats_search_filter |
---|
| 350 | @abstract ? |
---|
| 351 | @param $search_obj default 0 |
---|
| 352 | */ |
---|
| 353 | function cats_search_filter($search_obj=0,$filter_obj=1,$yours=0,$cat_id=0,$cat_field='fcat_id',$link='',$extra='') |
---|
| 354 | { |
---|
| 355 | if (!is_object($GLOBALS['phpgw']->categories)) |
---|
| 356 | { |
---|
| 357 | $GLOBALS['phpgw']->categories = CreateObject('phpgwapi.categories'); |
---|
| 358 | } |
---|
| 359 | $var = array( |
---|
| 360 | 'form_action' => ($this->_menuaction?$this->page($extra):$GLOBALS['phpgw']->link($sn, $extra)), |
---|
| 361 | 'lang_category' => lang('Category'), |
---|
| 362 | 'lang_all' => lang('All'), |
---|
| 363 | 'lang_select' => lang('Select'), |
---|
| 364 | 'cat_field' => $cat_field, |
---|
| 365 | 'categories' => $GLOBALS['phpgw']->categories->formated_list('select','all',(int)$cat_id,'True'), |
---|
| 366 | 'hidden' => $GLOBALS['phpgw']->html->input_hidden(array( |
---|
| 367 | 'filter' => $this->_filter, |
---|
| 368 | 'qfield' => $this->_qfield, |
---|
| 369 | 'start' => 0, |
---|
| 370 | 'order' => $this->_order, |
---|
| 371 | 'sort' => $this->_sort, |
---|
| 372 | 'query' => $GLOBALS['query'], |
---|
| 373 | )), |
---|
| 374 | 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], |
---|
| 375 | 'search' => $this->search($search_obj), |
---|
| 376 | 'filter' => ($filter_obj?$this->filter($filter_obj,$yours):'') |
---|
| 377 | ); |
---|
| 378 | $this->template->set_var($var); |
---|
| 379 | return $this->template->fp('out','cats_search_filter'); |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | /*! |
---|
| 383 | @function search |
---|
| 384 | @abstract ? |
---|
| 385 | @param $search_obj default 0 |
---|
| 386 | */ |
---|
| 387 | function search($search_obj=0) |
---|
| 388 | { |
---|
| 389 | if(is_array($search_obj)) |
---|
| 390 | { |
---|
| 391 | $params = $search_obj; |
---|
| 392 | $s_query = stripslashes($params['query']); |
---|
| 393 | $search_obj = $params['search_obj']; |
---|
| 394 | } |
---|
| 395 | else |
---|
| 396 | { |
---|
| 397 | $_query = stripslashes($GLOBALS['query']); |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | // If they place a '"' in their search, it will mess everything up |
---|
| 401 | // Our only option is to remove it |
---|
| 402 | if(strstr($query,'"')) |
---|
| 403 | { |
---|
| 404 | $_query = str_replace('"','',$_query); |
---|
| 405 | } |
---|
| 406 | $var = array |
---|
| 407 | ( |
---|
| 408 | 'query_value' => $GLOBALS['phpgw']->html->htmlspecialchars($_query), |
---|
| 409 | 'lang_search' => lang('Search') |
---|
| 410 | ); |
---|
| 411 | |
---|
| 412 | if (is_array($search_obj)) |
---|
| 413 | { |
---|
| 414 | $var['searchby'] = $this->searchby($search_obj); |
---|
| 415 | } |
---|
| 416 | |
---|
| 417 | $this->template->set_var($var); |
---|
| 418 | return $this->template->fp('out','search'); |
---|
| 419 | } /* search() */ |
---|
| 420 | |
---|
| 421 | /*! |
---|
| 422 | @function filterobj |
---|
| 423 | @abstract ? |
---|
| 424 | @param $filtertable |
---|
| 425 | @param $indxfieldname ? |
---|
| 426 | @param $strfieldname ? |
---|
| 427 | */ |
---|
| 428 | function filterobj($filtertable, $idxfieldname, $strfieldname) |
---|
| 429 | { |
---|
| 430 | $filter_obj = array(array('none','show all')); |
---|
| 431 | $index = 0; |
---|
| 432 | |
---|
| 433 | $GLOBALS['phpgw']->db->query("SELECT $idxfieldname, $strfieldname FROM $filtertable",__LINE__,__FILE__); |
---|
| 434 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 435 | { |
---|
| 436 | $index++; |
---|
| 437 | $filter_obj[$index][0] = $GLOBALS['phpgw']->db->f($idxfieldname); |
---|
| 438 | $filter_obj[$index][1] = $GLOBALS['phpgw']->db->f($strfieldname); |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | return $filter_obj; |
---|
| 442 | } /* filterobj() */ |
---|
| 443 | |
---|
| 444 | /*! |
---|
| 445 | @function searchby |
---|
| 446 | @abstract ? |
---|
| 447 | @param $search_obj ? |
---|
| 448 | */ |
---|
| 449 | function searchby($search_obj) |
---|
| 450 | { |
---|
| 451 | $str = ''; |
---|
| 452 | if (is_array($search_obj)) |
---|
| 453 | { |
---|
| 454 | $indexlimit = count($search_obj); |
---|
| 455 | for ($index=0; $index<$indexlimit; $index++) |
---|
| 456 | { |
---|
| 457 | if ($this->_qfield == '') |
---|
| 458 | { |
---|
| 459 | $this->_qfield = $search_obj[$index][0]; |
---|
| 460 | } |
---|
| 461 | $str .= '<option value="' . $search_obj[$index][0] . '"' . ($this->_qfield == $search_obj[$index][0]?' selected':'') . '>' . lang($search_obj[$index][1]) . '</option>'; |
---|
| 462 | } |
---|
| 463 | $str = '<select name="qfield">' . $str . '</select>' . "\n"; |
---|
| 464 | } |
---|
| 465 | return $str; |
---|
| 466 | } /* searchby() */ |
---|
| 467 | |
---|
| 468 | /*! |
---|
| 469 | @function filter |
---|
| 470 | @abstract ? |
---|
| 471 | @param $filter_obj |
---|
| 472 | */ |
---|
| 473 | function filter($filter_obj,$yours=0) |
---|
| 474 | { |
---|
| 475 | if (is_array($yours)) |
---|
| 476 | { |
---|
| 477 | $params = $yours; |
---|
| 478 | $this->_filter = $params['filter']; |
---|
| 479 | $yours = $params['yours']; |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | if (is_long($filter_obj)) |
---|
| 483 | { |
---|
| 484 | if ($filter_obj == 1) |
---|
| 485 | { |
---|
| 486 | // $user_groups = $GLOBALS['phpgw']->accounts->membership($GLOBALS['phpgw_info']['user']['account_id']); |
---|
| 487 | $indexlimit = count($user_groups); |
---|
| 488 | |
---|
| 489 | if ($yours) |
---|
| 490 | { |
---|
| 491 | $filter_obj = array |
---|
| 492 | ( |
---|
| 493 | array('none',lang('Show all')), |
---|
| 494 | array('yours',lang('Only yours')), |
---|
| 495 | array('private',lang('private')) |
---|
| 496 | ); |
---|
| 497 | } |
---|
| 498 | else |
---|
| 499 | { |
---|
| 500 | $filter_obj = array |
---|
| 501 | ( |
---|
| 502 | array('none',lang('Show all')), |
---|
| 503 | array('private',lang('private')) |
---|
| 504 | ); |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | while (is_array($this->extra_filters) && list(,$efilter) = each($this->extra_filters)) |
---|
| 508 | { |
---|
| 509 | $filter_obj[] = $efilter; |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | for ($index=0; $index<$indexlimit; $index++) |
---|
| 513 | { |
---|
| 514 | $filter_obj[2+$index][0] = $user_groups[$index]['account_id']; |
---|
| 515 | $filter_obj[2+$index][1] = 'Group - ' . $user_groups[$index]['account_name']; |
---|
| 516 | } |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | if (is_array($filter_obj)) |
---|
| 521 | { |
---|
| 522 | $str = ''; |
---|
| 523 | $indexlimit = count($filter_obj); |
---|
| 524 | |
---|
| 525 | for ($index=0; $index<$indexlimit; $index++) |
---|
| 526 | { |
---|
| 527 | if ($this->_filter == '') |
---|
| 528 | { |
---|
| 529 | $this->_filter = $filter_obj[$index][0]; |
---|
| 530 | } |
---|
| 531 | $str .= ' <option value="' . $filter_obj[$index][0] . '"'.($this->_filter == $filter_obj[$index][0]?' selected="1"':'') . '>' . $filter_obj[$index][1] . '</option>'."\n"; |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | $str = ' <select name="filter" onChange="this.form.submit()">'."\n" . $str . ' </select>'; |
---|
| 535 | $this->template->set_var('select',$str); |
---|
| 536 | $this->template->set_var('lang_filter',lang('Filter')); |
---|
| 537 | } |
---|
| 538 | |
---|
| 539 | return $this->template->fp('out','filter'); |
---|
| 540 | } /* filter() */ |
---|
| 541 | |
---|
| 542 | /* replacement for function filter */ |
---|
| 543 | function new_filter($data=0) |
---|
| 544 | { |
---|
| 545 | if(is_array($data)) |
---|
| 546 | { |
---|
| 547 | $filter = (isset($data['filter'])?$data['filter']:''); |
---|
| 548 | $format = (isset($data['format'])?$data['format']:'all'); |
---|
| 549 | } |
---|
| 550 | else |
---|
| 551 | { |
---|
| 552 | //$filter = get_var('filter',Array('GET','POST')); |
---|
| 553 | $filter = $data; |
---|
| 554 | $format = 'all'; |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | switch($format) |
---|
| 558 | { |
---|
| 559 | case 'yours': |
---|
| 560 | $filter_obj = array |
---|
| 561 | ( |
---|
| 562 | array('none',lang('show all')), |
---|
| 563 | array('yours',lang('only yours')) |
---|
| 564 | ); |
---|
| 565 | break; |
---|
| 566 | case 'private': |
---|
| 567 | $filter_obj = array |
---|
| 568 | ( |
---|
| 569 | array('none',lang('show all')), |
---|
| 570 | array('private',lang('only private')) |
---|
| 571 | ); |
---|
| 572 | break; |
---|
| 573 | default: |
---|
| 574 | $filter_obj = array |
---|
| 575 | ( |
---|
| 576 | array('none',lang('show all')), |
---|
| 577 | array('yours',lang('only yours')), |
---|
| 578 | array('private',lang('only private')) |
---|
| 579 | ); |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | $str = ''; |
---|
| 583 | $indexlimit = count($filter_obj); |
---|
| 584 | |
---|
| 585 | for($index=0; $index<$indexlimit; $index++) |
---|
| 586 | { |
---|
| 587 | if($filter == '') |
---|
| 588 | { |
---|
| 589 | $filter = $filter_obj[$index][0]; |
---|
| 590 | } |
---|
| 591 | $str .= ' <option value="' . $filter_obj[$index][0] . '"'.($filter == $filter_obj[$index][0]?' selected="1"':'') . '>' . $filter_obj[$index][1] . '</option>'."\n"; |
---|
| 592 | } |
---|
| 593 | |
---|
| 594 | $str = ' <select name="filter" onChange="this.form.submit()">'."\n" . $str . ' </select>'; |
---|
| 595 | $this->template->set_var('select',$str); |
---|
| 596 | $this->template->set_var('lang_filter',lang('Filter')); |
---|
| 597 | |
---|
| 598 | return $this->template->fp('out','filter'); |
---|
| 599 | } /* filter() */ |
---|
| 600 | |
---|
| 601 | /*! |
---|
| 602 | @function alternate_row_color |
---|
| 603 | @abstract alternate row colour |
---|
| 604 | @param $currentcolor default '' |
---|
| 605 | @param $do_class boolean default False return the color-value or just the class-name |
---|
| 606 | */ |
---|
| 607 | function alternate_row_color($currentcolor = '',$do_class=False) |
---|
| 608 | { |
---|
| 609 | if (! $currentcolor) |
---|
| 610 | { |
---|
| 611 | $currentcolor = @$GLOBALS['tr_color']; |
---|
| 612 | } |
---|
| 613 | |
---|
| 614 | if ($currentcolor == $GLOBALS['phpgw_info']['theme']['row_on']) |
---|
| 615 | { |
---|
| 616 | $GLOBALS['tr_color'] = $GLOBALS['phpgw_info']['theme'][$class='row_off']; |
---|
| 617 | } |
---|
| 618 | else |
---|
| 619 | { |
---|
| 620 | $GLOBALS['tr_color'] = $GLOBALS['phpgw_info']['theme'][$class='row_on']; |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | return $do_class ? $class : $GLOBALS['tr_color']; |
---|
| 624 | } |
---|
| 625 | |
---|
| 626 | // If you are using the common bgcolor="{tr_color}" |
---|
| 627 | // This function is a little cleanier approch |
---|
| 628 | /*! |
---|
| 629 | @function template_alternate_row_color |
---|
| 630 | @abstract ? |
---|
| 631 | @param $tpl ? |
---|
| 632 | */ |
---|
| 633 | function template_alternate_row_color(&$tpl) |
---|
| 634 | { |
---|
| 635 | $tpl->set_var('tr_color',$this->alternate_row_color()); |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | /*! |
---|
| 639 | @function show_sort_order |
---|
| 640 | @abstract ? |
---|
| 641 | @param $sort ? |
---|
| 642 | @param $var ? |
---|
| 643 | @param $order ? |
---|
| 644 | @param $program ? |
---|
| 645 | @param $text ? |
---|
| 646 | @param $extra default '' |
---|
| 647 | */ |
---|
| 648 | function show_sort_order($sort,$var,$order,$program,$text,$extra='',$build_a_href=True) |
---|
| 649 | { |
---|
| 650 | if ($order == $var) |
---|
| 651 | { |
---|
| 652 | $sort = $sort == 'ASC' ? 'DESC' : 'ASC'; |
---|
| 653 | |
---|
| 654 | $text = '<b>'.$text.'</b> <img border="0" src="'.$GLOBALS['phpgw']->common->image('phpgwapi',$sort=='ASC'?'up':'down').'">'; |
---|
| 655 | } |
---|
| 656 | else |
---|
| 657 | { |
---|
| 658 | $sort = 'ASC'; |
---|
| 659 | } |
---|
| 660 | |
---|
| 661 | if (is_array($extra)) |
---|
| 662 | { |
---|
| 663 | $extra = $this->extras_to_string($extra); |
---|
| 664 | } |
---|
| 665 | |
---|
| 666 | $extravar = 'order='.$var.'&sort='.$sort.'&filter='.$this->_filter.'&qfield='.$this->_qfield.'&start='.$this->_start.'&query='.urlencode(stripslashes(@$GLOBALS['query'])).$extra; |
---|
| 667 | |
---|
| 668 | $link = ($this->_menuaction?$this->page($extravar):$GLOBALS['phpgw']->link($program,$extravar)); |
---|
| 669 | |
---|
| 670 | if ($build_a_href) |
---|
| 671 | { |
---|
| 672 | return '<a href="' . $link . '">' . $text . '</a>'; |
---|
| 673 | } |
---|
| 674 | else |
---|
| 675 | { |
---|
| 676 | return $link; |
---|
| 677 | } |
---|
| 678 | } |
---|
| 679 | |
---|
| 680 | function show_hits($total_records='',$start=0) |
---|
| 681 | { |
---|
| 682 | if ($total_records > $this->maxmatches) |
---|
| 683 | { |
---|
| 684 | if ($start + $this->maxmatches > $total_records) |
---|
| 685 | { |
---|
| 686 | $end = $total_records; |
---|
| 687 | } |
---|
| 688 | else |
---|
| 689 | { |
---|
| 690 | $end = $start + $this->maxmatches; |
---|
| 691 | } |
---|
| 692 | return lang('showing %1 - %2 of %3',($start + 1),$end,$total_records); |
---|
| 693 | } |
---|
| 694 | else |
---|
| 695 | { |
---|
| 696 | return lang('showing %1',$total_records); |
---|
| 697 | } |
---|
| 698 | } |
---|
| 699 | |
---|
| 700 | /*! |
---|
| 701 | @function show_sort_order_imap |
---|
| 702 | @abstract ? |
---|
| 703 | @param $old_sort : the current sort value |
---|
| 704 | @param $new_sort : the sort value you want if you click on this |
---|
| 705 | @param $default_order : users preference for ordering list items (force this when a new [different] sorting is requested) |
---|
| 706 | @param $order : the current order (will be flipped if old_sort = new_sort) |
---|
| 707 | @param $program : script file name |
---|
| 708 | @param $text : Text the link will show |
---|
| 709 | @param $extra : any extra stuff you want to pass, url style |
---|
| 710 | */ |
---|
| 711 | function show_sort_order_imap($old_sort,$new_sort,$default_order,$order,$program,$text,$extra='') |
---|
| 712 | { |
---|
| 713 | if(is_array($extra)) |
---|
| 714 | { |
---|
| 715 | $extra = $this->extras_to_string($extra); |
---|
| 716 | } |
---|
| 717 | if($old_sort == $new_sort) |
---|
| 718 | { |
---|
| 719 | // alternate order, like on outkrook, click on present sorting reverses order |
---|
| 720 | if((int)$order == 1) |
---|
| 721 | { |
---|
| 722 | $our_order = 0; |
---|
| 723 | } |
---|
| 724 | elseif((int)$order == 0) |
---|
| 725 | { |
---|
| 726 | $our_order = 1; |
---|
| 727 | } |
---|
| 728 | else |
---|
| 729 | { |
---|
| 730 | // we should never get here |
---|
| 731 | $our_order = 1; |
---|
| 732 | } |
---|
| 733 | } |
---|
| 734 | else |
---|
| 735 | { |
---|
| 736 | //user has selected a new sort scheme, reset the order to users default |
---|
| 737 | $our_order = $default_order; |
---|
| 738 | } |
---|
| 739 | |
---|
| 740 | $extravar = 'order='.$our_order.'&sort='.$new_sort.$extra; |
---|
| 741 | |
---|
| 742 | $link = ($this->_menuaction?$this->page($extravar):$GLOBALS['phpgw']->link($program,$extravar)); |
---|
| 743 | return '<a href="' .$link .'">' .$text .'</a>'; |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | /*! |
---|
| 747 | @function nav_left_right_imap |
---|
| 748 | @abstract same code as left and right (as of Dec 07, 2001) except all combined into one function |
---|
| 749 | @param feed_vars : array with these elements: <br> |
---|
| 750 | start |
---|
| 751 | total |
---|
| 752 | cmd_prefix |
---|
| 753 | cmd_suffix |
---|
| 754 | @return array, combination of functions left and right above, with these elements: |
---|
| 755 | first_page |
---|
| 756 | prev_page |
---|
| 757 | next_page |
---|
| 758 | last_page |
---|
| 759 | @author: jengo, some changes by Angles |
---|
| 760 | */ |
---|
| 761 | function nav_left_right_imap($feed_vars) |
---|
| 762 | { |
---|
| 763 | $return_array = Array( |
---|
| 764 | 'first_page' => '', |
---|
| 765 | 'prev_page' => '', |
---|
| 766 | 'next_page' => '', |
---|
| 767 | 'last_page' => '' |
---|
| 768 | ); |
---|
| 769 | $out_vars = array(); |
---|
| 770 | // things that might change |
---|
| 771 | $out_vars['start'] = $feed_vars['start']; |
---|
| 772 | // things that stay the same |
---|
| 773 | $out_vars['common_uri'] = $feed_vars['common_uri']; |
---|
| 774 | $out_vars['total'] = $feed_vars['total']; |
---|
| 775 | |
---|
| 776 | // first page |
---|
| 777 | if(($feed_vars['start'] != 0) && |
---|
| 778 | ($feed_vars['start'] > $this->maxmatches)) |
---|
| 779 | { |
---|
| 780 | $out_vars['start'] = 0; |
---|
| 781 | $return_array['first_page'] = $this->set_link_imap('left','first.png',lang('First page'),$out_vars); |
---|
| 782 | } |
---|
| 783 | else |
---|
| 784 | { |
---|
| 785 | $return_array['first_page'] = $this->set_icon_imap('left','first-grey.png',lang('First page')); |
---|
| 786 | } |
---|
| 787 | // previous page |
---|
| 788 | if($feed_vars['start'] != 0) |
---|
| 789 | { |
---|
| 790 | // Changing the sorting order screaws up the starting number |
---|
| 791 | if(($feed_vars['start'] - $this->maxmatches) < 0) |
---|
| 792 | { |
---|
| 793 | $out_vars['start'] = 0; |
---|
| 794 | } |
---|
| 795 | else |
---|
| 796 | { |
---|
| 797 | $out_vars['start'] = ($feed_vars['start'] - $this->maxmatches); |
---|
| 798 | } |
---|
| 799 | $return_array['prev_page'] = $this->set_link_imap('left','left.png',lang('Previous page'),$out_vars); |
---|
| 800 | } |
---|
| 801 | else |
---|
| 802 | { |
---|
| 803 | $return_array['prev_page'] = $this->set_icon_imap('left','left-grey.png',lang('Previous page')); |
---|
| 804 | } |
---|
| 805 | |
---|
| 806 | // re-initialize the out_vars |
---|
| 807 | // things that might change |
---|
| 808 | $out_vars['start'] = $feed_vars['start']; |
---|
| 809 | // next page |
---|
| 810 | if(($feed_vars['total'] > $this->maxmatches) && |
---|
| 811 | ($feed_vars['total'] > $feed_vars['start'] + $this->maxmatches)) |
---|
| 812 | { |
---|
| 813 | $out_vars['start'] = ($feed_vars['start'] + $this->maxmatches); |
---|
| 814 | $return_array['next_page'] = $this->set_link_imap('right','right.png',lang('Next page'),$out_vars); |
---|
| 815 | } |
---|
| 816 | else |
---|
| 817 | { |
---|
| 818 | $return_array['next_page'] = $this->set_icon_imap('right','right-grey.png',lang('Next page')); |
---|
| 819 | } |
---|
| 820 | // last page |
---|
| 821 | if(($feed_vars['start'] != $feed_vars['total'] - $this->maxmatches) && |
---|
| 822 | (($feed_vars['total'] - $this->maxmatches) > ($feed_vars['start'] + $this->maxmatches))) |
---|
| 823 | { |
---|
| 824 | $out_vars['start'] = ($feed_vars['total'] - $this->maxmatches); |
---|
| 825 | $return_array['last_page'] = $this->set_link_imap('right','last.png',lang('Last page'),$out_vars); |
---|
| 826 | } |
---|
| 827 | else |
---|
| 828 | { |
---|
| 829 | $return_array['last_page'] = $this->set_icon_imap('right','last-grey.png',lang('Last page')); |
---|
| 830 | } |
---|
| 831 | return $return_array; |
---|
| 832 | } |
---|
| 833 | |
---|
| 834 | /*! |
---|
| 835 | @function set_link_imap |
---|
| 836 | @abstract ? |
---|
| 837 | @param $img_src ? |
---|
| 838 | @param $label ? |
---|
| 839 | @param $link ? |
---|
| 840 | @param $extravars ? |
---|
| 841 | */ |
---|
| 842 | function set_link_imap($align,$img,$alt_text,$out_vars) |
---|
| 843 | { |
---|
| 844 | $img_full = $GLOBALS['phpgw']->common->image('phpgwapi',$img); |
---|
| 845 | $image_part = '<img src="'.$img_full.'" border="0" alt="'.$alt_text.'" width="12" height="12">'; |
---|
| 846 | return '<a href="'.$out_vars['common_uri'].'&start='.$out_vars['start'].'">'.$image_part.'</a>'; |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | function set_icon_imap($align,$img,$alt_text) |
---|
| 850 | { |
---|
| 851 | $img_full = $GLOBALS['phpgw']->common->image('phpgwapi',$img); |
---|
| 852 | return '<img src="'.$img_full.'" border="0" width="12" height="12" alt="'.$alt_text.'">'."\r\n"; |
---|
| 853 | } |
---|
| 854 | } // End of nextmatchs class |
---|
| 855 | ?> |
---|