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