[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/admin/check/ -> check_api.php (source)

   1  <?php
   2  # MantisBT - A PHP based bugtracking system
   3  
   4  # MantisBT is free software: you can redistribute it and/or modify
   5  # it under the terms of the GNU General Public License as published by
   6  # the Free Software Foundation, either version 2 of the License, or
   7  # (at your option) any later version.
   8  #
   9  # MantisBT is distributed in the hope that it will be useful,
  10  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  # GNU General Public License for more details.
  13  #
  14  # You should have received a copy of the GNU General Public License
  15  # along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * @package MantisBT
  19   * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
  20   * @copyright Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
  21   * @link http://www.mantisbt.org
  22   */
  23  
  24  $g_show_all = false;
  25  $g_show_errors = false;
  26  
  27  $g_failed_test = false;
  28  $g_passed_test_with_warnings = false;
  29  
  30  $g_alternate_row = 1;
  31  
  32  $g_errors_temporarily_suppressed = false;
  33  $g_errors_raised = array();
  34  
  35  function check_init_error_handler() {
  36      set_error_handler( 'check_error_handler' );
  37      error_reporting( E_ALL );
  38  }
  39  
  40  function check_error_handler( $p_type, $p_error, $p_file, $p_line, $p_context ) {
  41      global $g_errors_raised;
  42      $g_errors_raised[] = array(
  43          'type' => $p_type,
  44          'error' => $p_error,
  45          'file' => $p_file,
  46          'line' => $p_line,
  47          'context' => $p_context
  48      );
  49  }
  50  
  51  function check_unhandled_errors_exist() {
  52      global $g_errors_raised;
  53      if ( count( $g_errors_raised ) > 0 ) {
  54          return true;
  55      }
  56      return false;
  57  }
  58  
  59  function check_print_error_rows() {
  60      global $g_show_errors, $g_errors_temporarily_suppressed, $g_errors_raised;
  61      if( !$g_show_errors || $g_errors_temporarily_suppressed ) {
  62          $g_errors_raised = array();
  63          return;
  64      }
  65      foreach( $g_errors_raised as $t_error ) {
  66          # build an appropriate error string
  67          switch( $t_error['type'] ) {
  68              case E_WARNING:
  69                  $t_error_type = 'SYSTEM WARNING';
  70                  $t_error_description = htmlentities( $t_error['error'] );
  71                  break;
  72              case E_NOTICE:
  73                  $t_error_type = 'SYSTEM NOTICE';
  74                  $t_error_description = htmlentities( $t_error['error'] );
  75                  break;
  76              case E_USER_ERROR:
  77                  $t_error_type = 'APPLICATION ERROR #' . $t_error['error'];
  78                  $t_error_description = htmlentities( error_string( $t_error['error'] ) );
  79                  break;
  80              case E_USER_WARNING:
  81                  $t_error_type = 'APPLICATION WARNING #' . $t_error['error'];
  82                  $t_error_description = htmlentities( error_string( $t_error['error'] ) );
  83                  break;
  84              case E_USER_NOTICE:
  85                  # used for debugging
  86                  $t_error_type = 'DEBUG';
  87                  $t_error_description = htmlentities( $t_error['error'] );
  88                  break;
  89              default:
  90                  # shouldn't happen, just display the error just in case
  91                  $t_error_type = '';
  92                  $t_error_description = htmlentities( $t_error['error'] );
  93          }
  94          echo "\t<tr>\n\t\t<td colspan=\"2\" class=\"error\">";
  95          echo "<strong>$t_error_type:</strong> $t_error_description<br />";
  96          echo '<em>Raised in file ' . htmlentities( $t_error['file'] ) . ' on line ' . htmlentities( $t_error['line'] ) . '</em>';
  97          echo "</td>\n\t</tr>\n";
  98      }
  99      $g_errors_raised = array();
 100  }
 101  
 102  function check_print_section_header_row( $p_heading ) {
 103  ?>
 104      <tr>
 105          <td colspan="2" class="thead2"><strong><?php echo $p_heading ?></strong></td>
 106      </tr>
 107  <?php
 108  }
 109  
 110  function check_print_info_row( $p_description, $p_info = null ) {
 111      global $g_alternate_row, $g_show_all;
 112      if( !$g_show_all ) {
 113          return;
 114      }
 115      echo "\t<tr>\n\t\t<td class=\"description$g_alternate_row\">$p_description</td>\n";
 116      echo "\t\t<td class=\"info$g_alternate_row\">$p_info</td>\n\t</tr>\n";
 117      $g_alternate_row = $g_alternate_row === 1 ? 2 : 1;
 118  }
 119  
 120  function check_print_test_result( $p_result ) {
 121      global $g_alternate_row, $g_failed_test, $g_passed_test_with_warnings;
 122      switch ( $p_result ) {
 123          case BAD:
 124              echo "\t\t<td class=\"fail$g_alternate_row\">FAIL</td>\n";
 125              $g_failed_test = true;
 126              break;
 127          case GOOD:
 128              echo "\t\t<td class=\"pass$g_alternate_row\">PASS</td>\n";
 129              break;
 130          case WARN:
 131              echo "\t\t<td class=\"warn$g_alternate_row\">WARN</td>\n";
 132              $g_passed_test_with_warnings = true;
 133              break;
 134      }
 135  }
 136  
 137  function check_print_test_row( $p_description, $p_pass, $p_info = null ) {
 138      global $g_alternate_row, $g_show_all;
 139      if ( !$g_show_all && $p_pass ) {
 140          return $p_pass;
 141      }
 142      echo "\t<tr>\n\t\t<td class=\"description$g_alternate_row\">$p_description";
 143      if( $p_info !== null) {
 144          if( is_array( $p_info ) && isset( $p_info[$p_pass] ) ) {
 145              echo '<br /><em>' . $p_info[$p_pass] . '</em>';
 146          } else if( !is_array( $p_info ) ) {
 147              echo '<br /><em>' . $p_info . '</em>';
 148          }
 149      }
 150      echo "</td>\n";
 151      if( $p_pass && !check_unhandled_errors_exist() ) {
 152          check_print_test_result( GOOD );
 153      } else {
 154          check_print_test_result( BAD );
 155      }
 156      echo "\t</tr>\n";
 157      if( check_unhandled_errors_exist() ) {
 158          check_print_error_rows();
 159      }
 160      $g_alternate_row = $g_alternate_row === 1 ? 2 : 1;
 161      return $p_pass;
 162  }
 163  
 164  function check_print_test_warn_row( $p_description, $p_pass, $p_info = null ) {
 165      global $g_alternate_row, $g_show_all;
 166      if ( !$g_show_all && $p_pass ) {
 167          return $p_pass;
 168      }
 169      echo "\t<tr>\n\t\t<td class=\"description$g_alternate_row\">$p_description";
 170      if( $p_info !== null) {
 171          if( is_array( $p_info ) && isset( $p_info[$p_pass] ) ) {
 172              echo '<br /><em>' . $p_info[$p_pass] . '</em>';
 173          } else if( !is_array( $p_info ) ) {
 174              echo '<br /><em>' . $p_info . '</em>';
 175          }
 176      }
 177      echo "</td>\n";
 178      if( $p_pass && !check_unhandled_errors_exist() ) {
 179          check_print_test_result( GOOD );
 180      } else if( !check_unhandled_errors_exist() ) {
 181          check_print_test_result( WARN );
 182      } else {
 183          check_print_test_result( BAD );
 184      }
 185      echo "\t</tr>\n";
 186      if( check_unhandled_errors_exist() ) {
 187          check_print_error_rows();
 188      }
 189      $g_alternate_row = $g_alternate_row === 1 ? 2 : 1;
 190      return $p_pass;
 191  }


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7