Import/Export

Description

Features:

  • Multiple export format supported.
  • User can create new format.
  • Easy to install.

Requirements:

Installation

  • Use the plugin manager to install the last release.

Usage

Add link to the plugin

You can add a link to the plugin by using the function print_plugins_importexport_link() in the different pages of Mantis.

print_plugins_importexport_link( $p_id = 0, $p_format = null, $p_list = null, $p_tag = null );
     // $p_id: The id of the bug to export
     // $p_format: The format of the export (pdf, csv...)
     // $p_list: The list of fields to export (id, status, reporter_id...)
     // $p_tag: The tag to display ('Export in PDF', '<img src="pdf.gif" />'...)

Examples

  • In the View Issues page, add two lines (marked by the ”# new line”) in the view_all_inc.php file:
    		<span class="small"> <?php
    				# -- Print and Export links --
    
    				print_bracket_link( 'print_all_bug_page.php', lang_get( 'print_all_bug_page_link' ) );
    				echo '&nbsp;';
    				print_bracket_link( 'csv_export.php', lang_get( 'csv_export' ) );
    				echo '&nbsp;'; # new line
    				print_plugins_importexport_link(); # new line
    		?> </span>
  • In an Issue page, add three lines (marked by the ”<!– # new line –>”) in the bug_view_page.php and/or bug_viaw_advanced_page.php:
    		<span class="small">
    			<?php print_bracket_link( 'wiki.php?id='.$f_bug_id, lang_get( 'wiki' ) ) ?>
    		</span>
    	<?php
    		}
    	?>
    		<span class="small"> <!-- # new line -->
    			<?php print_plugins_importexport_link( $f_bug_id ) ?> <!-- # new line -->
    		</span> <!-- # new line -->
    	</td>
     
    	<!-- prev/next links -->

File formats

Actual file formats

Add your own file format

To create a new file format you need to create a new directory in the MANTIS_ROOT/plugins/importexport/format/ directory. The directory name must be in lower case and containing only letters or numbers (so 'a' to 'z' and '0' to '9').

In this directory, you must create two files: info.php and index.php.

The info.php file must contain a function named plugins_importexport_format_<directory_name> with <directory_name> the name of the directory that you have created. This function must return an array containing the version of the file format and its name. Example:

function plugins_importexport_format_xml() {
    return array( 'version' => '0.0.2', 'name' => 'XML' );
}

The index.php file contains the generator of the result file. Three variables are set before sourcing this file:

$t_username = 'username'; // The current user username
$t_fields = array( 'column1', 'column2', ... ); // The column titles
$t_bugs = array( array( 'id' => 1, 'columns' => array( 'column1_value', 'column2_value', ... ),
                 ... ); // The bug data

Example:

<?php
if ( !ereg( 'plugins_page.php', $_SERVER['PHP_SELF'] ) ) {
    header( 'Location: ../../../../plugins_page.php' );
    exit();
}
 
header( 'Pragma: public' );
header( 'Content-Type: application/vnd.ms-excel' );
header( 'Content-Transfer-Encoding: none;' );
header( 'Content-Disposition: attachment; filename="' . $t_username . '-' . date( 'Ymd-hi' ) .'.xls"' );
 
echo '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">' . "\n";
 
?>
  <head>
    <style id="Classeur1_16681_Styles"></style>
    <meta http-equiv="Content-type" content="text/html;charset='<?php echo lang_get( 'charset' ) ?>'" />
  </head>
  <body>
    <div id="Classeur1_16681" align=center x:publishsource="Excel">
      <table x:str border=0 cellpadding=0 cellspacing=0 width=100% style='border-collapse: collapse'>
        <tr>
        <?php foreach( $t_fields as $t_field => $t_translated ) { ?><?php if ( $t_field != 'bugnote' ) { ?>  <td class=xl2316681><b><?php echo $t_translated ?></b></td>
        <?php } ?><?php } ?></tr>
      <?php foreach( $t_bugs as $t_bug ) { ?>  <tr bgcolor="<?php echo get_status_color( bug_get_field( $t_bug['id'], 'status' ) ) ?>">
        <?php foreach( $t_bug['columns'] as $t_data ) { ?><?php if ( !is_array( $t_data ) ) { ?>  <td class=xl2216681 nowrap><?php echo $t_data ?></td>
        <?php } ?><?php } ?></tr>
      <?php } ?></table>
    </div>
  </body>
</html>