Changeset 873 for trunk/Common/Global.php
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Global.php
r869 r873 25 25 26 26 $UnitIndex = 0; 27 while ($Value > 1024)27 while ($Value > 1024) 28 28 { 29 29 $Value = round($Value / 1024, 3); 30 30 $UnitIndex++; 31 31 } 32 return ($Value.' '.$UnitNames[$UnitIndex]);32 return ($Value.' '.$UnitNames[$UnitIndex]); 33 33 } 34 34 … … 48 48 function HumanDate($Time) 49 49 { 50 if ($Time != '') {50 if ($Time != '') { 51 51 $Date = explode(' ', $Time); 52 52 $Parts = explode('-', $Date[0]); 53 if ($Date != '0000-00-00') return(($Parts[2]*1).'.'.($Parts[1]*1).'.'.$Parts[0]);54 else return (' ');55 } else return (' ');53 if ($Date != '0000-00-00') return (($Parts[2]*1).'.'.($Parts[1]*1).'.'.$Parts[0]); 54 else return (' '); 55 } else return (' '); 56 56 } 57 57 … … 62 62 $Around = 10; 63 63 $Result = ''; 64 if ($Count>1)65 { 66 if ($Page>0)64 if ($Count>1) 65 { 66 if ($Page>0) 67 67 { 68 68 $Result.= '<a href="'.$URL.'0"><<</a> '; … … 71 71 $PagesMax = $Count-1; 72 72 $PagesMin = 0; 73 if ($PagesMax>($Page+$Around)) $PagesMax = $Page+$Around;74 if ($PagesMin<($Page-$Around))73 if ($PagesMax>($Page+$Around)) $PagesMax = $Page+$Around; 74 if ($PagesMin<($Page-$Around)) 75 75 { 76 76 $Result.= ' .. '; 77 77 $PagesMin = $Page-$Around; 78 78 } 79 for ($i=$PagesMin;$i<=$PagesMax;$i++)80 { 81 if ($i==$Page) $Result.= '<strong>';79 for ($i=$PagesMin;$i<=$PagesMax;$i++) 80 { 81 if ($i==$Page) $Result.= '<strong>'; 82 82 $Result.= '<a href="'.$URL.$i.'">'.($i+1).'</a> '; 83 if ($i==$Page) $Result.= '</strong>';84 } 85 if ($PagesMax<($Count-1)) $Result .= ' .. ';86 if ($Page<($Count-1))83 if ($i==$Page) $Result.= '</strong>'; 84 } 85 if ($PagesMax<($Count-1)) $Result .= ' .. '; 86 if ($Page<($Count-1)) 87 87 { 88 88 $Result.= '<a href="'.$URL.($Page+1).'">></a> '; … … 90 90 } 91 91 } 92 return ($Result);92 return ($Result); 93 93 } 94 94 95 95 function ExtractTime($Time) 96 96 { 97 return (array(97 return (array( 98 98 'Year' => date('Y', $Time), 99 99 'Month' => date('n', $Time), … … 109 109 $Result = array(); 110 110 $Parts = explode('&', $QueryString); 111 foreach ($Parts as $Part)112 { 113 if ($Part != '')114 { 115 if (!strpos($Part, '=')) $Part .= '=';111 foreach ($Parts as $Part) 112 { 113 if ($Part != '') 114 { 115 if (!strpos($Part, '=')) $Part .= '='; 116 116 $Item = explode('=', $Part); 117 117 $Result[$Item[0]] = $Item[1]; 118 118 } 119 119 } 120 return ($Result);120 return ($Result); 121 121 } 122 122 … … 124 124 { 125 125 $Parts = array(); 126 foreach ($QueryStringArray as $Index => $Item)126 foreach ($QueryStringArray as $Index => $Item) 127 127 { 128 128 $Parts[] = $Index.'='.$Item; 129 129 } 130 return (implode('&', $Parts));130 return (implode('&', $Parts)); 131 131 } 132 132 … … 138 138 139 139 $Result = ''; 140 if (array_key_exists('all', $QueryItems))140 if (array_key_exists('all', $QueryItems)) 141 141 { 142 142 $PageCount = 1; … … 149 149 } 150 150 151 if (!array_key_exists($ObjectName.'Page', $_SESSION)) $_SESSION[$ObjectName.'Page'] = 0;152 if (array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName)) {153 if (array_key_exists('page', $_GET)) $_SESSION[$ObjectName.'Page'] = $_GET['page'] * 1;154 } 155 if ($_SESSION[$ObjectName.'Page'] < 0) $_SESSION[$ObjectName.'Page'] = 0;156 if ($_SESSION[$ObjectName.'Page'] >= $PageCount) $_SESSION[$ObjectName.'Page'] = $PageCount - 1;151 if (!array_key_exists($ObjectName.'Page', $_SESSION)) $_SESSION[$ObjectName.'Page'] = 0; 152 if (array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName)) { 153 if (array_key_exists('page', $_GET)) $_SESSION[$ObjectName.'Page'] = $_GET['page'] * 1; 154 } 155 if ($_SESSION[$ObjectName.'Page'] < 0) $_SESSION[$ObjectName.'Page'] = 0; 156 if ($_SESSION[$ObjectName.'Page'] >= $PageCount) $_SESSION[$ObjectName.'Page'] = $PageCount - 1; 157 157 $CurrentPage = $_SESSION[$ObjectName.'Page']; 158 158 … … 161 161 162 162 $Result = ''; 163 if ($PageCount > 1)164 { 165 if ($CurrentPage > 0)163 if ($PageCount > 1) 164 { 165 if ($CurrentPage > 0) 166 166 { 167 167 $QueryItems['page'] = 0; … … 172 172 $PagesMax = $PageCount - 1; 173 173 $PagesMin = 0; 174 if ($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;175 if ($PagesMin < ($CurrentPage - $Around))174 if ($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around; 175 if ($PagesMin < ($CurrentPage - $Around)) 176 176 { 177 177 $Result.= ' ... '; 178 178 $PagesMin = $CurrentPage - $Around; 179 179 } 180 for ($i = $PagesMin; $i <= $PagesMax; $i++)181 { 182 if ($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';180 for ($i = $PagesMin; $i <= $PagesMax; $i++) 181 { 182 if ($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> '; 183 183 else { 184 184 $QueryItems['page'] = $i; … … 186 186 } 187 187 } 188 if ($PagesMax < ($PageCount - 1)) $Result .= ' ... ';189 if ($CurrentPage < ($PageCount - 1))188 if ($PagesMax < ($PageCount - 1)) $Result .= ' ... '; 189 if ($CurrentPage < ($PageCount - 1)) 190 190 { 191 191 $QueryItems['page'] = ($CurrentPage + 1); … … 196 196 } 197 197 $QueryItems['all'] = '1'; 198 if ($PageCount > 1) $Result.= ' <a href="?'.SetQueryStringArray($QueryItems).'">Vše</a>';198 if ($PageCount > 1) $Result.= ' <a href="?'.SetQueryStringArray($QueryItems).'">Vše</a>'; 199 199 200 200 $Result = '<div style="text-align: center">'.$Result.'</div>'; 201 return (array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage,201 return (array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage, 202 202 'Page' => $CurrentPage, 203 203 'Output' => $Result, … … 212 212 global $OrderDirSQL, $OrderArrowImage, $Config, $System; 213 213 214 if (array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName))215 { 216 if (array_key_exists('OrderCol', $_GET)) $_SESSION[$ObjectName.'OrderCol'] = $_GET['OrderCol'];217 if (array_key_exists('OrderDir', $_GET)) $_SESSION[$ObjectName.'OrderDir'] = $_GET['OrderDir'];218 } 219 if (!array_key_exists($ObjectName.'OrderCol', $_SESSION)) $_SESSION[$ObjectName.'OrderCol'] = $DefaultColumn;220 if (!array_key_exists($ObjectName.'OrderDir', $_SESSION) ) $_SESSION[$ObjectName.'OrderDir'] = $DefaultOrder;214 if (array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName)) 215 { 216 if (array_key_exists('OrderCol', $_GET)) $_SESSION[$ObjectName.'OrderCol'] = $_GET['OrderCol']; 217 if (array_key_exists('OrderDir', $_GET)) $_SESSION[$ObjectName.'OrderDir'] = $_GET['OrderDir']; 218 } 219 if (!array_key_exists($ObjectName.'OrderCol', $_SESSION)) $_SESSION[$ObjectName.'OrderCol'] = $DefaultColumn; 220 if (!array_key_exists($ObjectName.'OrderDir', $_SESSION) ) $_SESSION[$ObjectName.'OrderDir'] = $DefaultOrder; 221 221 222 222 // Check OrderCol 223 223 $Found = false; 224 foreach ($Columns as $Column)225 { 226 if ($Column['Name'] == $_SESSION[$ObjectName.'OrderCol'])224 foreach ($Columns as $Column) 225 { 226 if ($Column['Name'] == $_SESSION[$ObjectName.'OrderCol']) 227 227 { 228 228 $Found = true; … … 230 230 } 231 231 } 232 if (($_SESSION[$ObjectName.'OrderCol'] == '') or ($Found == false))232 if (($_SESSION[$ObjectName.'OrderCol'] == '') or ($Found == false)) 233 233 { 234 234 $_SESSION[$ObjectName.'OrderCol'] = $DefaultColumn; … … 236 236 } 237 237 // Check OrderDir 238 if (($_SESSION[$ObjectName.'OrderDir'] != 0) and ($_SESSION[$ObjectName.'OrderDir'] != 1))238 if (($_SESSION[$ObjectName.'OrderDir'] != 0) and ($_SESSION[$ObjectName.'OrderDir'] != 1)) 239 239 $_SESSION[$ObjectName.'OrderDir'] = 0; 240 240 241 241 $Result = ''; 242 242 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); 243 foreach ($Columns as $Index => $Column)243 foreach ($Columns as $Index => $Column) 244 244 { 245 245 $QueryItems['ObjectName'] = $ObjectName; 246 246 $QueryItems['OrderCol'] = $Column['Name']; 247 247 $QueryItems['OrderDir'] = 1 - $_SESSION[$ObjectName.'OrderDir']; 248 if ($Column['Name'] == $_SESSION[$ObjectName.'OrderCol'])248 if ($Column['Name'] == $_SESSION[$ObjectName.'OrderCol']) 249 249 $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'. 250 250 $System->Link('/images/'.$OrderArrowImage[$_SESSION[$ObjectName.'OrderDir']]).'" alt="order arrow">'; 251 251 else $ArrowImage = ''; 252 if ($Column['Name'] == '') $Result .= '<th>'.$Column['Title'].'</th>';252 if ($Column['Name'] == '') $Result .= '<th>'.$Column['Title'].'</th>'; 253 253 else $Result .= '<th><a href="?'.SetQueryStringArray($QueryItems).'">'.$Column['Title'].$ArrowImage.'</a></th>'; 254 254 } 255 return (array(255 return (array( 256 256 'SQL' => ' ORDER BY `'.$_SESSION[$ObjectName.'OrderCol'].'` '.$OrderDirSQL[$_SESSION[$ObjectName.'OrderDir']], 257 257 'Output' => '<tr>'.$Result.'</tr>', … … 263 263 function GetRemoteAddress() 264 264 { 265 if (array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR'];265 if (array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR']; 266 266 else $IP = '0.0.0.0'; 267 return ($IP);267 return ($IP); 268 268 } 269 269 … … 274 274 $Result = true; 275 275 $RemoteAddr = GetRemoteAddress(); 276 foreach ($Config['Web']['IntranetSubnets'] as $Subnet)277 { 278 if (substr($RemoteAddr, 0, strlen($Subnet)) == $Subnet)276 foreach ($Config['Web']['IntranetSubnets'] as $Subnet) 277 { 278 if (substr($RemoteAddr, 0, strlen($Subnet)) == $Subnet) 279 279 { 280 280 $Result = false; … … 282 282 } 283 283 } 284 return ($Result);284 return ($Result); 285 285 } 286 286 … … 292 292 '(SELECT `Member` FROM `NetworkDevice` WHERE (SELECT `Device` FROM `NetworkInterface` '. 293 293 'WHERE `LocalIP` = "'.$IP.'") = `NetworkDevice`.`Id`) = `Member`.`Id`'); 294 if ($DbResult->num_rows > 0)294 if ($DbResult->num_rows > 0) 295 295 { 296 296 $DbRow = $DbResult->fetch_assoc(); 297 return ($DbRow['Id']);298 } else return ('');297 return ($DbRow['Id']); 298 } else return (''); 299 299 } 300 300 … … 302 302 { 303 303 $Result = shell_exec('which '.$Command); 304 return (!empty($Result));304 return (!empty($Result)); 305 305 } 306 306 307 307 function RemoveDiacritic($Text) 308 308 { 309 return (str_replace(309 return (str_replace( 310 310 array('á', 'č', 'ď', 'é', 'ě', 'í', 'ľ', 'ň', 'ó', 'ř', 'š', 'ť', 'ú', 'ů', 311 311 'ý', 'ž', 'Á', 'Č', 'Ď', 'É', 'Ě', 'Í', 'Ľ', 'Ň', 'Ó', 'Ř', 'Š', 'Ť', 'Ú', 'Ů', 'Ý', 'Ž'), … … 317 317 function RouterOSIdent($Name) 318 318 { 319 return (strtr(strtolower(trim($Name)), array(' ' => '-', '.' => '', '(' => '-', ')' => '-', ',' => '-',319 return (strtr(strtolower(trim($Name)), array(' ' => '-', '.' => '', '(' => '-', ')' => '-', ',' => '-', 320 320 'č' => 'c', 'š' => 's', 'ě' => 'e', 'ř' => 'r', 'ž' => 'z', 'ý' => 'y', 321 321 'á' => 'a', 'í' => 'i', 'é' => 'e', 'ů' => 'u', 'ú' => 'u', 'ď' => 'd', … … 329 329 function NotBlank($Text) 330 330 { 331 if ($Text == '') return(' ');332 else return ($Text);331 if ($Text == '') return (' '); 332 else return ($Text); 333 333 } 334 334 … … 352 352 function ProcessURL() 353 353 { 354 if (array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))354 if (array_key_exists('REDIRECT_QUERY_STRING', $_SERVER)) 355 355 $PathString = $_SERVER['REDIRECT_QUERY_STRING']; 356 356 else $PathString = ''; 357 if (substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);357 if (substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1); 358 358 $PathItems = explode('/', $PathString); 359 if (array_key_exists('REQUEST_URI', $_SERVER) and (strpos($_SERVER['REQUEST_URI'], '?') !== false))359 if (array_key_exists('REQUEST_URI', $_SERVER) and (strpos($_SERVER['REQUEST_URI'], '?') !== false)) 360 360 $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1); 361 361 else $_SERVER['QUERY_STRING'] = ''; 362 362 parse_str($_SERVER['QUERY_STRING'], $_GET); 363 return ($PathItems);363 return ($PathItems); 364 364 } 365 365 366 366 function RepeatFunction($Period, $Callback) 367 367 { 368 while (1)368 while (1) 369 369 { 370 370 $StartTime = time(); … … 372 372 $EndTime = time(); 373 373 $Delay = $Period - ($EndTime - $StartTime); 374 if ($Delay < 0) $Delay = 0;374 if ($Delay < 0) $Delay = 0; 375 375 376 376 echo('Waiting remaining '.$Delay.' of '.$Period.' seconds period...'."\n");
Note:
See TracChangeset
for help on using the changeset viewer.