| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- class DBG {
- /**
- * @param $reqKqy - key in $_REQUEST array (if true then always show)
- * @param $reqValueExpr - expression to compare req value
- * true - always visible - only for fast DBG without $reqKey in REQUEST
- * '>*', '>=*', '<*', '<=*' - compare $reqValue
- * examples:
- * - show when $_REQUEST['DBG_SCH'] == '1'
- * DBG::_('DBG_SCH', '1', "fieldsConfig({$idTable})", $fieldsConfig, __CLASS__, __FUNCTION__, __LINE__);
- * - show when $_REQUEST['DBG_SCH'] > '1'
- * DBG::_('DBG_SCH', '>1', "fieldsConfig({$idTable})", $fieldsConfig, __CLASS__, __FUNCTION__, __LINE__);
- * - show when any value: strlen($_REQUEST['DBG_SCH']) > 0
- * DBG::_('DBG_SCH', true, "fieldsConfig({$idTable})", $fieldsConfig, __CLASS__, __FUNCTION__, __LINE__);
- * - always show
- * DBG::_(true, true, "fieldsConfig({$idTable})", $fieldsConfig, __CLASS__, __FUNCTION__, __LINE__);
- */
- public static function _($reqKey, $reqValueExpr, $label, $variable, $className, $functionName, $lineNumber, $borderColor = 'red') {
- $showDBG = false;
- $reqValue = V::get($reqKey, '', $_GET);
- if (true === $reqKey) {
- $showDBG = true;
- }
- else if (strlen($reqValue) == 0) {
- return;
- }
- else if ($reqValue == $reqValueExpr) {
- $showDBG = true;
- }
- else if (true === $reqValueExpr) {
- $showDBG = true;
- }
- else {
- if ('>=' == substr($reqValueExpr, 0, 2)) {
- if ($reqValue >= substr($reqValueExpr, 2)) {
- $showDBG = true;
- }
- }
- else if ('>' == substr($reqValueExpr, 0, 1)) {
- if ($reqValue > substr($reqValueExpr, 1)) {
- $showDBG = true;
- }
- }
- else if ('<=' == substr($reqValueExpr, 0, 2)) {
- if ($reqValue <= substr($reqValueExpr, 2)) {
- $showDBG = true;
- }
- }
- else if ('<' == substr($reqValueExpr, 0, 1)) {
- if ($reqValue < substr($reqValueExpr, 1)) {
- $showDBG = true;
- }
- }
- else {
- if ($reqValue = $reqValueExpr) {
- $showDBG = true;
- }
- }
- }
- if ($showDBG) {
- ?>
- <pre style="max-height:200px;max-width:800px;overflow:auto;border:1px solid <?php echo $borderColor; ?>;text-align:left;"
- ><?php echo "{$label} ({$className}::{$functionName}:{$lineNumber}):\n"; ?>
- <?php print_r($variable);?>
- </pre>
- <?php
- }
- }
- public static function table($label, $table, $className, $functionName, $lineNumber) {
- $cols = array();
- if (is_array($table) && !empty($table)) {
- $firstRow = array();
- foreach ($table as $row) {
- $firstRow = $row;
- break;
- }
- if (is_array($firstRow)) {
- $cols = array_keys($firstRow);
- }
- else if (is_object($firstRow)) {
- $cols = array_keys((array)$firstRow);
- }
- else {
- return;// bad table item type
- }
- }
- ?>
- <table class="table table-bordered">
- <caption><?php echo "{$label} ({$className}::{$functionName}:{$lineNumber}):"; ?></caption>
- <thead>
- <tr>
- <th style="padding:2px;">Lp.</th>
- <?php foreach ($cols as $colName) : ?>
- <th style="padding:2px;"><?php echo $colName; ?></th>
- <?php endforeach; ?>
- </tr>
- </thead>
- <tbody>
- <?php $i = 0; foreach ($table as $row) : $i++; ?>
- <tr>
- <td style="padding:2px;"><?php echo $i; ?></td>
- <?php foreach ($cols as $colName) : ?>
- <td style="padding:2px;"><?php echo V::get($colName, '', $row); ?></td>
- <?php endforeach; ?>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php
- }
- }
|