-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
131 lines (111 loc) · 2.47 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/*-----------------------------------------------------------------------------
cheetan is licensed under the MIT license.
copyright (c) 2006 cheetan all right reserved.
http://php.cheetan.net/
-----------------------------------------------------------------------------*/
class CView extends CObject
{
var $template;
var $viewfile;
var $variables;
var $sanitize;
var $controller;
var $debug = false;
function SetFile( $template, $viewfile )
{
$this->template = $template;
$this->viewfile = $viewfile;
}
function SetVariable( &$variable )
{
$this->variables = $variable;
}
function SetSanitize( &$sanitize )
{
$this->sanitize = $sanitize;
}
function SetController( &$controller )
{
$this->controller = $controller;
}
function SetSqlLog( $sqllog )
{
if( $this->debug )
{
$log = '<table class="cheetan_sql_log">'
. '<tr>'
. '<th width="60%">SQL</th>'
. '<th width="10%">ERROR</th>'
. '<th width="10%">ROWS</th>'
. '<th width="10%">TIME</th>'
. '</tr>'
;
foreach( $sqllog as $name => $rows )
{
$log .= '<tr>'
. '<td colspan="4"><b>' . htmlspecialchars( $name ) . '</b></td>'
. '</tr>'
;
foreach( $rows as $i => $row )
{
$log .= '<tr>'
. '<td>' . htmlspecialchars( $row['query'] ) . '</td>'
. '<td>' . htmlspecialchars( $row['error'] ) . '</td>'
. '<td>' . $row['affected_rows'] . '</td>'
. '<td>' . sprintf( '%.5f', $row['query_time'] ) . '</td>'
. '</tr>'
;
}
}
$log .= '</table>';
$this->variables['cheetan_sql_log'] = $log;
}
}
function SetDebug( $debug )
{
$this->debug = $debug;
}
function display()
{
if( $this->template )
{
$this->_display_template();
}
else
{
$this->content();
}
}
function content()
{
if( file_exists( $this->viewfile ) )
{
$data = $this->variables;
$sanitize = $this->sanitize;
$s = $this->sanitize;
$controller = $this->controller;
$c = $this->controller;
extract($this->variables, EXTR_SKIP);
require_once( $this->viewfile );
}
}
function _display_template()
{
if( file_exists( $this->template ) )
{
$data = $this->variables;
$sanitize = $this->sanitize;
$s = $this->sanitize;
$controller = $this->controller;
$c = $this->controller;
extract($this->variables, EXTR_SKIP);
require_once( $this->template );
}
else
{
print "Template '$this->template' is not exist.";
}
}
}
?>