source: Base/HTML/HTML.php

Last change on this file was 1, checked in by george, 15 years ago
  • Přidáno: Výchozí verze systému.
File size: 4.0 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../Module.php');
4
5class HTML extends Module
6{
7 function ShowArray($Value)
8 {
9 echo('<pre style="font-size: 8pt;">');
10 print_r($Value);
11 echo('</pre>');
12 }
13
14 // Funkce formatovani vystupu
15 function FormatOutput($Text)
16 {
17 $Indentation = 2;
18
19 $Output = '';
20 $Indent = 0;
21 $IndentNew = 0;
22 while($Text != '')
23 {
24 $Start = strpos($Text, '<');
25 $End = strpos($Text, '>');
26 if($Start != 0)
27 {
28 $End = $Start - 1;
29 $Start = 0;
30 }
31 $Line = trim(substr($Text, $Start, $End + 1));
32 if(strlen($Line) > 0)
33 if($Line[0] == '<')
34 {
35 if($Text[$Start + 1] == '/')
36 {
37 $IndentNew = $IndentNew - $Indentation;
38 $Indent = $IndentNew;
39 } else
40 {
41 if(strpos($Line, ' ')) $Command = substr($Line, 1, strpos($Line, ' ') - 1);
42 else $Command = substr($Line, 1, strlen($Line) - $Indentation);
43 if(strpos($Text, '</'.$Command.'>')) $IndentNew = $IndentNew + $Indentation;
44 }
45 }
46 if($Line != '') $Output .= (str_repeat(' ', $Indent).$Line."\n");
47 $Text = substr($Text, $End + 1, strlen($Text));
48 $Indent = $IndentNew;
49 }
50 return($Output);
51 }
52
53 function NotBlank($Text)
54 {
55 if($Text == '') return('&nbsp');
56 else return($Text);
57 }
58
59 function MakeLink($Title, $Target)
60 {
61 return('<a href="'.$Target.'">'.$Title.'</a>');
62 }
63
64 function Table($Table, $Class, $Id = '')
65 {
66 if($Id != '') $Id = ' id="'.$Id.'"';
67 $Result = '<table class="'.$Class.'"'.$Id.'>';
68 if(array_key_exists('Header', $Table))
69 {
70 $Result .= '<tr>';
71 foreach($Table['Header'] as $Item)
72 $Result .= '<th>'.$Item.'</th>';
73 $Result .= '</tr>';
74 }
75 foreach($Table['Rows'] as $Row)
76 {
77 $Result .= '<tr>';
78 foreach($Row as $Index => $Item)
79 {
80 if($Index == 0) $Class = ' class="Header"'; else $Class = '';
81 $Result .= '<td'.$Class.'>'.$Item.'</td>';
82 }
83 $Result .= '</tr>';
84 }
85 $Result .= '</table>';
86 return($Result);
87 }
88
89 // Zobrazení číselný seznamu stránek
90 function PageList($QueryStringVar, $Page, $TotalCount, $CountPerPage, $Around = 10)
91 {
92 $QueryStringArray = $this->System->HTTP->GetQueryStringArray();
93 $Count = ceil($TotalCount / $CountPerPage);
94 $Result = '';
95 if($Count > 1)
96 {
97 if($Page > 0)
98 {
99 $QueryStringArray[$QueryStringVar] = 0;
100 $Result .= '<a href="?'.$this->System->HTTP->SetQueryStringArray($QueryStringArray).'">&lt;&lt;</a> ';
101 $QueryStringArray[$QueryStringVar] = $Page - 1;
102 $Result .= '<a href="?'.$this->System->HTTP->SetQueryStringArray($QueryStringArray).'">&lt;</a> ';
103 }
104 $PagesMax = $Count - 1;
105 $PagesMin = 0;
106 if($PagesMax > ($Page + $Around)) $PagesMax = $Page + $Around;
107 if($PagesMin < ($Page - $Around))
108 {
109 $Result .= ' .. ';
110 $PagesMin = $Page - $Around;
111 }
112 for($i = $PagesMin; $i <= $PagesMax; $i++)
113 {
114 if($i == $Page) $Result .= '<strong>';
115 $QueryStringArray[$QueryStringVar] = $i;
116 $Result .= '<a href="?'.$this->System->HTTP->SetQueryStringArray($QueryStringArray).'">'.($i + 1).'</a> ';
117 if($i == $Page) $Result .= '</strong>';
118 }
119 if($PagesMax < ($Count - 1)) $Result .= ' .. ';
120 if($Page < ($Count - 1))
121 {
122 $QueryStringArray[$QueryStringVar] = $Page + 1;
123 $Result .= '<a href="?'.$this->System->HTTP->SetQueryStringArray($QueryStringArray).'">&gt;</a> ';
124 $QueryStringArray[$QueryStringVar] = $Count - 1;
125 $Result .= '<a href="?'.$this->System->HTTP->SetQueryStringArray($QueryStringArray).'">&gt;&gt;</a>';
126 }
127 }
128 return($Result);
129 }
130
131 function SectionReload($Id, $SectionURL, $RefreshPeriod = 5000)
132 {
133 return('<script type="text/javascript">'.
134 ' var refreshId = setInterval(function() {'.
135 '$(\'#'.$Id.'\').load(\''.$SectionURL.'\');'.
136 '}, '.$RefreshPeriod.');'.
137 '</script>');
138 }
139}
140
141?>
Note: See TracBrowser for help on using the repository browser.