]> andersk Git - sql-web.git/blob - lib/display.lib.php
move chars_encode to display library
[sql-web.git] / lib / display.lib.php
1 <?php
2
3 ## FORMATTING FUNCTIONS
4
5 function sprintSize($bytes, $float=2) {
6         if (is_null($bytes)) return null;
7         $kb = round($bytes / 1024, $float);
8         $mb = round($bytes / 1024 / 1024, $float);
9         $gb = round($bytes / 1024 / 1024 / 1024, $float);
10         
11         return ($bytes<1||$kb<1?$bytes.' B':($mb<1?$kb.' KB':($gb<1?$mb.' MB':$gb.' GB')));
12 }
13
14 function sprintTS($timestamp) { 
15         return substr($timestamp,0,4).
16                 '-'.substr($timestamp,4,2).
17                 '-'.substr($timestamp,6,2).
18                 ' '.substr($timestamp,8,2).
19                 ':'.substr($timestamp,10,2).
20                 ':'.substr($timestamp,12,2);
21 }
22
23 function printBar($percent, $txt1 = '', $txt2 = '') {
24         $color1 = 'black';
25         $color2 = 'white';
26         $color3 = 'white';
27         $color4 = 'black';
28         /* if ($percent>1) {
29                 $percent = $percent/100;
30         }
31         } elseif (!is_integer($percent) && $percent<2) {
32                 $percent = $percent*100;
33         } elseif ($percent == 1) {
34                 $percent = 100;
35         } */
36         $per1 = $per2 = floor($percent*100);
37         if ($per1>100) {
38                 $per1 = 100;
39                 $per2 = 0;
40         } else {
41                 $per2 = 100 - $per2;
42         }
43         $per1 .= "%";
44         $per2 .= "%";
45 /*      return '<table cellpadding=0 cellspacing=0 width="100%" class="bargraph">
46                                 <tr>
47                                 <td class="bar" align="left" width="'.$per1.'"><div style="position: relative;"><div style="left: 0; display: inline; position: absolute;">&nbsp;'.$txt1.'&nbsp;</div>&nbsp;</div></td>
48                                 <td class="fill" align="left" width="'.$per2.'"><div style="position: relative;">&nbsp;<div style="right: 0; display: inline; position: absolute;">'.$txt2.'&nbsp;<em>'.$per1.'</em></div></div></td>
49                                 </tr></table>';*/
50         return '<table cellpadding=0 cellspacing=0 width="100%" class="bargraph">
51                                 <tr>
52                                 <td class="bar" align="left" width="'.$per1.'"><div style="position: relative;"></div></td>
53                                 <td class="fill" align="right" width="'.$per2.'"><div style="position: relative;"></div></td>
54                                 </tr>
55                         </table><table cellpadding=0 cellspacing=0 width="100%">
56                                 <tr style="height: 1px;">
57                                 <td class="bar" align="left" width="50%"><div style="position: relative;"><div style="bottom: 3px; left: 5px; position: absolute;">'.$txt1.'</div></div></td>
58                                 <td class="fill" align="right" width="50%"><div style="position: relative;"><div style="bottom: 3px; right: 3px; position: absolute;">'.$txt2.'&nbsp;&nbsp;<em>'.$per1.'</em></div></div></td>
59                                 </tr>
60                                 </table>';
61 }
62
63 function chars_encode($string) {
64    $chars = array();
65    $ent = null;
66    $chars = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);
67    for ($i = 0; $i < count($chars); $i++)
68                 $ent[$i] = '&#' . ord($chars[$i]) . ';';
69    if (sizeof($ent) < 1) return '';
70    return implode('',$ent);
71 }
72
73 ?>
This page took 0.048154 seconds and 5 git commands to generate.