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