source: trunk/workflow/inc/local/functions/function.wf_debug.php @ 7655

Revision 7655, 4.2 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Melhorias de performance no codigo do Expresso.

Line 
1<?php
2function wf_debug($name = null)
3{
4        /* variable used to avoid the insertion of the same javascript file */
5        static $workflowFunctionsWf_debug = false;
6
7        /* load the backtrace */
8        $backTrace = debug_backtrace();
9
10        /* if no name is supplied, then use de name of the file from which the wf_debug was called */
11        if (is_null($name))
12                $name = substr(strrchr($backTrace[0]['file'], '/'), 1);
13
14        /* prepare the backtrace array */
15        $importantBacktrace = array();
16    $backTrace_count = count($backTrace);
17        for ($i = 0; $i < $backTrace_count; ++$i)
18        {
19                if (strpos($backTrace[$i]['file'], 'class.run_activity.inc.php') !== false)
20                        break;
21                $importantBacktrace[] = $backTrace[$i];
22        }
23        $importantBacktrace = array_reverse($importantBacktrace);
24
25        /* initialize the $output variable */
26        $output = '';
27
28        /* if it's the first time the function is called, then insert the javascript file reference */
29        if (!$workflowFunctionsWf_debug)
30        {
31                $output = '<script language="javascript1.2" src="workflow/js/jscode/debug.js"></script>';
32                $workflowFunctionsWf_debug = true;
33        }
34
35        /* start the visible output */
36        $output .= '<table style="border: 1px solid" width="100%">';
37        $output .= '<tr style="cursor: pointer; background-color: #000000; color: #FFFFFF" onclick="toggleTableDisplay(this.parentNode);"><th colspan="2">Debug: ' . $name . '</th></tr>';
38
39        /* start the backtrace section */
40        $output .= '<tr>';
41        $output .= '<td>Backtrace</td>';
42        $output .= '<td>';
43
44        $i = 1;
45        $output .= '<table>';
46        foreach ($importantBacktrace as $call)
47        {
48                /* show some general information */
49                $output .= '<tr' . ((($i % 2) == 1) ? ' bgcolor="#FFFFFF"' : '') . '><td><font color="red"><strong>' . $i++ . '- </strong></font></td><td>';
50                $output .= '<strong>Arquivo:</strong> ' . $call['file'] . '<br/>';
51                $output .= '<strong>Linha:</strong> ' . $call['line'] . '<br/>';
52
53                /* show different information for methods and functions */
54                if (isset($call['class']))
55                        $output .= '<strong>Método:</strong> ' . $call['class'] . $call['type'] . $call['function'] . '()<br/>';
56                else
57                        $output .= '<strong>Função:</strong> ' . $call['function'] . '()<br/>';
58
59                /* show the parameters used in the call */
60                $output .= '<strong>Parâmetros:</strong> ';
61                if (empty($call['args']))
62                {
63                        $output .= '<i>nenhum</i><br/>';
64                }
65                else
66                {
67                        $output .= '<br/>';
68                        $j = 1;
69                        foreach ($call['args'] as $arg)
70                        {
71                                if (is_array($arg))
72                                        $arg = '<i>array</i>';
73                                else
74                                        if (is_object($arg))
75                                                $arg = '<i>object</i>';
76                                $output .= '&nbsp;&nbsp;&nbsp;<strong>#' . $j++ . ':</strong> ' . $arg . '<br/>';
77                        }
78                }
79
80                $output .= '</td></tr>';
81        }
82        $output .= '</table>';
83        $output .= '</td></tr>';
84
85        /* start the $_REQUEST section */
86        $randomName = mt_rand() . '_' . mt_rand(); /* unique preffix */
87        $formInput = '';
88        $output .= '<tr><td>$_REQUEST</td><td>';
89        $output .= '<form method="post">';
90        $output .= '<table><tr><th style="font-size: 12px">Propriedade</th><th style="font-size: 12px">Valor</th></tr>';
91        foreach ($_REQUEST as $key => $value)
92        {
93                /* highlight the 'action' and 'params' elements */
94                $showKey = $key;
95                if (($key == 'action') || ($key == 'params'))
96                        $showKey = '<font color="red"><strong>' . $key . '</strong></font>';
97                /* generate the table row */
98                $output .= '<tr>';
99                $output .= '<td>' . $showKey . '</td>';
100                $output .= '<td id="' . $randomName . '_' . $key . '_td">' . $value . '</td>';
101
102                /* allow the developer to edit the parameters */
103                $output .= '<td><a href="#" onclick="' . "editField('{$randomName}', '{$key}'); return false;" . '">editar</a></td>';
104                $output .= '</tr>';
105
106                /* generate the form that can be submited at any time */
107                $formInput .= '<input type="hidden" id="' . $randomName . '_' . $key . '" name="' . $key . '" value="' . $value . '"/>';
108        }
109        $output .= '<tr><td colspan="3"><strong>Submeter formulário novamente: </strong>' . $formInput . '<input type="submit" value="enviar"/></td></tr>';
110        $output .= '</table>';
111        $output .= '</form>';
112        $output .= '</td></tr>';
113
114        /* check if exists a database connection */
115        $env = wf_get_env();
116        $output .= '<tr><td>Banco de Dados</td><td>' . (($env['dao']->Link_ID === 0) ? '<font color="red">não conectado</font>' : '<font color="green">conectado</font>') . '</td></tr>';
117
118        /* end the table */
119        $output .= '</table><br/>';
120
121        /* send the output */
122        echo $output;
123}
124?>
Note: See TracBrowser for help on using the repository browser.