Add analytics
[bus.git] / busui / owa / includes / pqp / display.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
 
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 Title : HTML Output for Php Quick Profiler
 Author : Created by Ryan Campbell
 URL : http://particletree.com/features/php-quick-profiler/
 
 Last Updated : April 22, 2009
 
 Description : This is a horribly ugly function used to output
 the PQP HTML. This is great because it will just work in your project,
 but it is hard to maintain and read. See the README file for how to use
 the Smarty file we provided with PQP.
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
function displayPqp($output, $config) {
        
$cssUrl = $config.'css/pQp.css';
                
echo <<<JAVASCRIPT
<!-- JavaScript -->
<script type="text/javascript">
        var PQP_DETAILS = true;
        var PQP_HEIGHT = "short";
        
        addEvent(window, 'load', loadCSS);
 
        function changeTab(tab) {
                var pQp = document.getElementById('pQp');
                hideAllTabs();
                addClassName(pQp, tab, true);
        }
        
        function hideAllTabs() {
                var pQp = document.getElementById('pQp');
                removeClassName(pQp, 'console');
                removeClassName(pQp, 'speed');
                removeClassName(pQp, 'queries');
                removeClassName(pQp, 'memory');
                removeClassName(pQp, 'files');
        }
        
        function toggleDetails(){
                var container = document.getElementById('pqp-container');
                
                if(PQP_DETAILS){
                        addClassName(container, 'hideDetails', true);
                        PQP_DETAILS = false;
                }
                else{
                        removeClassName(container, 'hideDetails');
                        PQP_DETAILS = true;
                }
        }
        function toggleHeight(){
                var container = document.getElementById('pqp-container');
                
                if(PQP_HEIGHT == "short"){
                        addClassName(container, 'tallDetails', true);
                        PQP_HEIGHT = "tall";
                }
                else{
                        removeClassName(container, 'tallDetails');
                        PQP_HEIGHT = "short";
                }
        }
        
        function loadCSS() {
                var sheet = document.createElement("link");
                sheet.setAttribute("rel", "stylesheet");
                sheet.setAttribute("type", "text/css");
                sheet.setAttribute("href", "$cssUrl");
                document.getElementsByTagName("head")[0].appendChild(sheet);
                setTimeout(function(){document.getElementById("pqp-container").style.display = "block"}, 10);
        }
        
        
        //http://www.bigbold.com/snippets/posts/show/2630
        function addClassName(objElement, strClass, blnMayAlreadyExist){
           if ( objElement.className ){
              var arrList = objElement.className.split(' ');
              if ( blnMayAlreadyExist ){
                 var strClassUpper = strClass.toUpperCase();
                 for ( var i = 0; i < arrList.length; i++ ){
                    if ( arrList[i].toUpperCase() == strClassUpper ){
                       arrList.splice(i, 1);
                       i--;
                     }
                   }
              }
              arrList[arrList.length] = strClass;
              objElement.className = arrList.join(' ');
           }
           else{  
              objElement.className = strClass;
              }
        }
 
        //http://www.bigbold.com/snippets/posts/show/2630
        function removeClassName(objElement, strClass){
           if ( objElement.className ){
              var arrList = objElement.className.split(' ');
              var strClassUpper = strClass.toUpperCase();
              for ( var i = 0; i < arrList.length; i++ ){
                 if ( arrList[i].toUpperCase() == strClassUpper ){
                    arrList.splice(i, 1);
                    i--;
                 }
              }
              objElement.className = arrList.join(' ');
           }
        }
 
        //http://ejohn.org/projects/flexible-javascript-events/
        function addEvent( obj, type, fn ) {
          if ( obj.attachEvent ) {
            obj["e"+type+fn] = fn;
            obj[type+fn] = function() { obj["e"+type+fn]( window.event ) };
            obj.attachEvent( "on"+type, obj[type+fn] );
          } 
          else{
            obj.addEventListener( type, fn, false );    
          }
        }
</script>
JAVASCRIPT;
 
echo '<div id="pqp-container" class="pQp" style="display:none">';
 
$logCount = count($output['logs']['console']);
$fileCount = count($output['files']);
$memoryUsed = $output['memoryTotals']['used'];
$queryCount = $output['queryTotals']['count'];
$speedTotal = $output['speedTotals']['total'];
 
echo <<<PQPTABS
<div id="pQp" class="console">
<table id="pqp-metrics" cellspacing="0">
<tr>
        <td class="green" onclick="changeTab('console');">
                <var>$logCount</var>
                <h4>Console</h4>
        </td>
        <td class="blue" onclick="changeTab('speed');">
                <var>$speedTotal</var>
                <h4>Load Time</h4>
        </td>
        <td class="purple" onclick="changeTab('queries');">
                <var>$queryCount Queries</var>
                <h4>Database</h4>
        </td>
        <td class="orange" onclick="changeTab('memory');">
                <var>$memoryUsed</var>
                <h4>Memory Used</h4>
        </td>
        <td class="red" onclick="changeTab('files');">
                <var>{$fileCount} Files</var>
                <h4>Included</h4>
        </td>
</tr>
</table>
PQPTABS;
 
echo '<div id="pqp-console" class="pqp-box">';
 
if($logCount ==  0) {
        echo '<h3>This panel has no log items.</h3>';
}
else {
        echo '<table class="side" cellspacing="0">
                <tr>
                        <td class="alt1"><var>'.$output['logs']['logCount'].'</var><h4>Logs</h4></td>
                        <td class="alt2"><var>'.$output['logs']['errorCount'].'</var> <h4>Errors</h4></td>
                </tr>
                <tr>
                        <td class="alt3"><var>'.$output['logs']['memoryCount'].'</var> <h4>Memory</h4></td>
                        <td class="alt4"><var>'.$output['logs']['speedCount'].'</var> <h4>Speed</h4></td>
                </tr>
                </table>
                <table class="main" cellspacing="0">';
                
                $class = '';
                foreach($output['logs']['console'] as $log) {
                        echo '<tr class="log-'.$log['type'].'">
                                <td class="type">'.$log['type'].'</td>
                                <td class="'.$class.'">';
                        if($log['type'] == 'log') {
                                echo '<div><pre>'.$log['data'].'</pre></div>';
                        }
                        elseif($log['type'] == 'memory') {
                                echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['dataType'].'</em>: '.$log['name'].' </div>';
                        }
                        elseif($log['type'] == 'speed') {
                                echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>';
                        }
                        elseif($log['type'] == 'error') {
                                echo '<div><em>Line '.$log['line'].'</em> : '.$log['data'].' <pre>'.$log['file'].'</pre></div>';
                        }
                
                        echo '</td></tr>';
                        if($class == '') $class = 'alt';
                        else $class = '';
                }
                        
                echo '</table>';
}
 
echo '</div>';
 
echo '<div id="pqp-speed" class="pqp-box">';
 
if($output['logs']['speedCount'] ==  0) {
        echo '<h3>This panel has no log items.</h3>';
}
else {
        echo '<table class="side" cellspacing="0">
                  <tr><td><var>'.$output['speedTotals']['total'].'</var><h4>Load Time</h4></td></tr>
                  <tr><td class="alt"><var>'.$output['speedTotals']['allowed'].'</var> <h4>Max Execution Time</h4></td></tr>
                 </table>
                <table class="main" cellspacing="0">';
                
                $class = '';
                foreach($output['logs']['console'] as $log) {
                        if($log['type'] == 'speed') {
                                echo '<tr class="log-'.$log['type'].'">
                                <td class="'.$class.'">';
                                echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>';
                                echo '</td></tr>';
                                if($class == '') $class = 'alt';
                                else $class = '';
                        }
                }
                        
                echo '</table>';
}
 
echo '</div>';
 
echo '<div id="pqp-queries" class="pqp-box">';
 
if($output['queryTotals']['count'] ==  0) {
        echo '<h3>This panel has no log items.</h3>';
}
else {
        echo '<table class="side" cellspacing="0">
                  <tr><td><var>'.$output['queryTotals']['count'].'</var><h4>Total Queries</h4></td></tr>
                  <tr><td class="alt"><var>'.$output['queryTotals']['time'].'</var> <h4>Total Time</h4></td></tr>
                  <tr><td><var>0</var> <h4>Duplicates</h4></td></tr>
                 </table>
                <table class="main" cellspacing="0">';
                
                $class = '';
                foreach($output['queries'] as $query) {
                        echo '<tr>
                                <td class="'.$class.'">'.$query['sql'];
                        if($query['explain']) {
                                        echo '<em>
                                                Possible keys: <b>'.$query['explain']['possible_keys'].'</b> &middot; 
                                                Key Used: <b>'.$query['explain']['key'].'</b> &middot; 
                                                Type: <b>'.$query['explain']['type'].'</b> &middot; 
                                                Rows: <b>'.$query['explain']['rows'].'</b> &middot; 
                                                Speed: <b>'.$query['time'].'</b>
                                        </em>';
                        }
                        echo '</td></tr>';
                        if($class == '') $class = 'alt';
                        else $class = '';
                }
                        
                echo '</table>';
}
 
echo '</div>';
 
echo '<div id="pqp-memory" class="pqp-box">';
 
if($output['logs']['memoryCount'] ==  0) {
        echo '<h3>This panel has no log items.</h3>';
}
else {
        echo '<table class="side" cellspacing="0">
                  <tr><td><var>'.$output['memoryTotals']['used'].'</var><h4>Used Memory</h4></td></tr>
                  <tr><td class="alt"><var>'.$output['memoryTotals']['total'].'</var> <h4>Total Available</h4></td></tr>
                 </table>
                <table class="main" cellspacing="0">';
                
                $class = '';
                foreach($output['logs']['console'] as $log) {
                        if($log['type'] == 'memory') {
                                echo '<tr class="log-'.$log['type'].'">';
                                echo '<td class="'.$class.'"><b>'.$log['data'].'</b> <em>'.$log['dataType'].'</em>: '.$log['name'].'</td>';
                                echo '</tr>';
                                if($class == '') $class = 'alt';
                                else $class = '';
                        }
                }
                        
                echo '</table>';
}
 
echo '</div>';
 
echo '<div id="pqp-files" class="pqp-box">';
 
if($output['fileTotals']['count'] ==  0) {
        echo '<h3>This panel has no log items.</h3>';
}
else {
        echo '<table class="side" cellspacing="0">
                        <tr><td><var>'.$output['fileTotals']['count'].'</var><h4>Total Files</h4></td></tr>
                        <tr><td class="alt"><var>'.$output['fileTotals']['size'].'</var> <h4>Total Size</h4></td></tr>
                        <tr><td><var>'.$output['fileTotals']['largest'].'</var> <h4>Largest</h4></td></tr>
                 </table>
                <table class="main" cellspacing="0">';
                
                $class ='';
                foreach($output['files'] as $file) {
                        echo '<tr><td class="'.$class.'"><b>'.$file['size'].'</b> '.$file['name'].'</td></tr>';
                        if($class == '') $class = 'alt';
                        else $class = '';
                }
                        
                echo '</table>';
}
 
echo '</div>';
 
echo <<<FOOTER
        <table id="pqp-footer" cellspacing="0">
                <tr>
                        <td class="credit">
                                <a href="http://particletree.com" target="_blank">
                                <strong>PHP</strong> 
                                <b class="green">Q</b><b class="blue">u</b><b class="purple">i</b><b class="orange">c</b><b class="red">k</b>
                                Profiler</a></td>
                        <td class="actions">
                                <a href="#" onclick="toggleDetails();return false">Details</a>
                                <a class="heightToggle" href="#" onclick="toggleHeight();return false">Height</a>