Changeset 303 for trunk/global.php
- Timestamp:
- Jan 30, 2011, 8:19:57 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/global.php
r267 r303 183 183 return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit); 184 184 } 185 186 function Link($Target) 187 { 188 global $Config; 189 190 return($Config['Web']['RootFolder'].$Target); 191 } 185 192 } 186 193 … … 297 304 } 298 305 306 function GetQueryStringArray($QueryString) 307 { 308 $Result = array(); 309 $Parts = explode('&', $QueryString); 310 foreach($Parts as $Part) 311 { 312 if($Part != '') 313 { 314 if(!strpos($Part, '=')) $Part .= '='; 315 $Item = explode('=', $Part); 316 $Result[$Item[0]] = $Item[1]; 317 } 318 } 319 return($Result); 320 } 321 322 function SetQueryStringArray($QueryStringArray) 323 { 324 $Parts = array(); 325 foreach($QueryStringArray as $Index => $Item) 326 { 327 $Parts[] = $Index.'='.$Item; 328 } 329 return(implode('&', $Parts)); 330 } 331 332 function GetPageList($TotalCount) 333 { 334 global $System; 335 336 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); 337 338 $ItemPerPage = $System->Config['Web']['ItemsPerPage']; 339 $Around = round($System->Config['Web']['VisiblePagingItems'] / 2); 340 $Result = ''; 341 $PageCount = floor($TotalCount / $ItemPerPage) + 1; 342 343 if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0; 344 if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1; 345 if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0; 346 if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1; 347 $CurrentPage = $_SESSION['Page']; 348 349 350 $Result .= 'Počet položek: <strong>'.$TotalCount.'</strong> Stránky: '; 351 352 $Result = ''; 353 if($PageCount > 1) 354 { 355 if($CurrentPage > 0) 356 { 357 $QueryItems['page'] = 0; 358 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'"><<</a> '; 359 $QueryItems['page'] = ($CurrentPage - 1); 360 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'"><</a> '; 361 } 362 $PagesMax = $PageCount - 1; 363 $PagesMin = 0; 364 if($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around; 365 if($PagesMin < ($CurrentPage - $Around)) 366 { 367 $Result.= ' ... '; 368 $PagesMin = $CurrentPage - $Around; 369 } 370 for($i = $PagesMin; $i <= $PagesMax; $i++) 371 { 372 if($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> '; 373 else { 374 $QueryItems['page'] = $i; 375 $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> '; 376 } 377 } 378 if($PagesMax < ($PageCount - 1)) $Result .= ' ... '; 379 if($CurrentPage < ($PageCount - 1)) 380 { 381 $QueryItems['page'] = ($CurrentPage + 1); 382 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">></a> '; 383 $QueryItems['page'] = ($PageCount - 1); 384 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">>></a>'; 385 } 386 } 387 $Result = '<div style="text-align: center">'.$Result.'</div>'; 388 return(array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage, 389 'Page' => $CurrentPage, 390 'Output' => $Result, 391 )); 392 } 393 394 $OrderDirSQL = array('ASC', 'DESC'); 395 $OrderArrowImage = array('sort_asc.png', 'sort_desc.png'); 396 397 function GetOrderTableHeader($Columns, $DefaultColumn, $DefaultOrder = 0) 398 { 399 global $OrderDirSQL, $OrderArrowImage, $Config, $System; 400 401 if(array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol']; 402 if(array_key_exists('OrderDir', $_GET)) $_SESSION['OrderDir'] = $_GET['OrderDir']; 403 if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $DefaultColumn; 404 if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $DefaultOrder; 405 406 // Check OrderCol 407 $Found = false; 408 foreach($Columns as $Column) 409 { 410 if($Column['Name'] == $_SESSION['OrderCol']) 411 { 412 $Found = true; 413 break; 414 } 415 } 416 if($Found == false) 417 { 418 $_SESSION['OrderCol'] = $DefaultColumn; 419 $_SESSION['OrderDir'] = $DefaultOrder; 420 } 421 // Check OrderDir 422 if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) $_SESSION['OrderDir'] = 0; 423 424 $Result = ''; 425 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); 426 foreach($Columns as $Index => $Column) 427 { 428 $QueryItems['OrderCol'] = $Column['Name']; 429 $QueryItems['OrderDir'] = 1 - $_SESSION['OrderDir']; 430 if($Column['Name'] == $_SESSION['OrderCol']) $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'.$System->Link('/images/'.$OrderArrowImage[$_SESSION['OrderDir']]).'" alt="order arrow">'; 431 else $ArrowImage = ''; 432 if($Column['Name'] == '') $Result .= '<th>'.$Column['Title'].'</th>'; 433 else $Result .= '<th><a href="?'.SetQueryStringArray($QueryItems).'">'.$Column['Title'].$ArrowImage.'</a></th>'; 434 } 435 return(array( 436 'SQL' => ' ORDER BY `'.$_SESSION['OrderCol'].'` '.$OrderDirSQL[$_SESSION['OrderDir']], 437 'Output' => '<tr>'.$Result.'</tr>', 438 'Column' => $_SESSION['OrderCol'], 439 'Direction' => $_SESSION['OrderDir'], 440 )); 441 } 299 442 function GetRemoteAddress() 300 443 {
Note:
See TracChangeset
for help on using the changeset viewer.