[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/ -> csv_export.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   * @uses core.php
  24   * @uses authentication_api.php
  25   * @uses columns_api.php
  26   * @uses constant_inc.php
  27   * @uses csv_api.php
  28   * @uses file_api.php
  29   * @uses filter_api.php
  30   * @uses helper_api.php
  31   * @uses print_api.php
  32   */
  33  
  34  /**
  35   * MantisBT Core API's
  36   */
  37  require_once ( 'core.php' );
  38  require_api( 'authentication_api.php' );
  39  require_api( 'columns_api.php' );
  40  require_api( 'constant_inc.php' );
  41  require_api( 'csv_api.php' );
  42  require_api( 'file_api.php' );
  43  require_api( 'filter_api.php' );
  44  require_api( 'helper_api.php' );
  45  require_api( 'print_api.php' );
  46  
  47  auth_ensure_user_authenticated();
  48  
  49  helper_begin_long_process();
  50  
  51  $t_page_number = 1;
  52  $t_per_page = -1;
  53  $t_bug_count = null;
  54  $t_page_count = null;
  55  
  56  $t_nl = csv_get_newline();
  57  $t_sep = csv_get_separator();
  58  
  59  # Get bug rows according to the current filter
  60  $t_rows = filter_get_bug_rows( $t_page_number, $t_per_page, $t_page_count, $t_bug_count );
  61  if ( $t_rows === false ) {
  62      print_header_redirect( 'view_all_set.php?type=0' );
  63  }
  64  
  65  $t_filename = csv_get_default_filename();
  66  
  67  # Send headers to browser to activate mime loading
  68  
  69  # Make sure that IE can download the attachments under https.
  70  header( 'Pragma: public' );
  71  
  72  header( 'Content-Type: text/plain; name=' . urlencode( file_clean_name( $t_filename ) ) );
  73  header( 'Content-Transfer-Encoding: BASE64;' );
  74  
  75  # Added Quotes (") around file name.
  76  header( 'Content-Disposition: attachment; filename="' . urlencode( file_clean_name( $t_filename ) ) . '"' );
  77  
  78  # Get columns to be exported
  79  $t_columns = csv_get_columns();
  80  
  81  # export the titles
  82  $t_first_column = true;
  83  ob_start();
  84  $t_titles = array();
  85  foreach ( $t_columns as $t_column ) {
  86      if ( !$t_first_column ) {
  87          echo $t_sep;
  88      } else {
  89          $t_first_column = false;
  90      }
  91  
  92      echo column_get_title( $t_column );
  93  }
  94  
  95  echo $t_nl;
  96  
  97  $t_header = ob_get_clean();
  98  
  99  # Fixed for a problem in Excel where it prompts error message "SYLK: File Format Is Not Valid"
 100  # See Microsoft Knowledge Base Article - 323626
 101  # http://support.microsoft.com/default.aspx?scid=kb;en-us;323626&Product=xlw
 102  $t_first_three_chars = utf8_substr( $t_header, 0, 3 );
 103  if ( strcmp( $t_first_three_chars, 'ID' . $t_sep ) == 0 ) {
 104      $t_header = str_replace( 'ID' . $t_sep, 'Id' . $t_sep, $t_header );
 105  }
 106  # end of fix
 107  
 108  echo $t_header;
 109  
 110  # export the rows
 111  foreach ( $t_rows as $t_row ) {
 112      $t_first_column = true;
 113  
 114      foreach ( $t_columns as $t_column ) {
 115          if ( !$t_first_column ) {
 116              echo $t_sep;
 117          } else {
 118              $t_first_column = false;
 119          }
 120  
 121          $t_custom_field = column_get_custom_field_name( $t_column );
 122          if ( $t_custom_field !== null ) {
 123              ob_start();
 124              $t_column_value_function = 'print_column_value';
 125              helper_call_custom_function( $t_column_value_function, array( $t_column, $t_row, COLUMNS_TARGET_CSV_PAGE ) );
 126              $t_value = ob_get_clean();
 127  
 128              echo csv_escape_string($t_value);
 129          } else {
 130              $t_function = 'csv_format_' . $t_column;
 131              echo $t_function( $t_row->$t_column );
 132          }
 133      }
 134  
 135      echo $t_nl;
 136  }


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