<?php
/*
// ------------------------------------------------------------------------------------------
// LICENSE
// ------------------------------------------------------------------------------------------

        # bugzilla2mantis.php - Development Status "Alpha" 
        # Convert bugzilla 5.0.3 database to mantis 1.3.3 sql data inserts
        #
        # Copyright (C) 2006  Agusti Fontquerni afontquerni -at- gmail -dot- com
        # This program is distributed under the terms and conditions 
        # of the GNU GENERAL PUBLIC LICENSE Version 2 (http://www.gnu.org/copyleft/gpl.html)

// ------------------------------------------------------------------------------------------
// README
// ------------------------------------------------------------------------------------------
On Set-2006 I was looking for Bugzilla to Mantis (Perl) by Cris Daniluk (http://www.cadencetools.org/projects/bugzilla2mantis/)     

But Nobody didn't find any thing on the web, all web page links are broken or deleted (http://freshmeat.net/redir/bugzilla2mantis/52873/url_tgz/bugzilla2mantis-0.2.tar.gz) ((http://forums.mantisbugtracker.com/viewtopic.php?p=5745&sid=1a679a9fa211306bfd51eb33f7da2579))    

At last, I decided to start my first php script to convert bugs data from bugzilla to mantis (bugzilla2mantis.php).  It is alfa script but its did basic and functional great job.  
I give mantis2bugzilla.php to mantis community to improve bugzilla migration feature

// ------------------------------------------------------------------------------------------
// INSTALL
// ------------------------------------------------------------------------------------------
1) Backup all databases
2) Copy this file to bugzilla web site ( example: /var/www/bugzilla )
3) Modify database parameters "server", "user", "password", "database" ( 'localhost','root','', 'bugzilla' ) in "bz2m_connect()" function 
4) Open "bugzilla2mantis.php" with web browser ( example: localhost:/bugzilla/bugzilla2mantis.php )
5) Check output web page
6) Select all (Ctrl+A). Copy from web browser to test editor. Save to file ( example: mantis.sql )
7) Install mantis website ( http://www.mantisbugtracker.com/ )
8) Modify mantis database from bugzilla data "bugzilla2mantis.php" ( example: mysql -u root bugtracker < mantis.sql )
9) Now, report bugs with mantis ... 

// ------------------------------------------------------------------------------------------
// CHANGELOG
// ------------------------------------------------------------------------------------------
2016.11.21 - Adaptation for PHP 5.6.16, bugzilla version 5.0.3 and Mantis BT version 1.3.3 - french version (groques)
2006.09.24 - Clean code and Documentation (afontquerni)
2006.09.16 - Resolve some major bugs (afontquerni)
2006.09.15 - Add bugnote_table and bugnote_text_table  (afontquerni)
2006.09.14 - Initial release (afontquerni)

// ------------------------------------------------------------------------------------------
// DESCRIPTION STRUCTURE - DOCUMENTATION
// ------------------------------------------------------------------------------------------

bz2m_connect($link); // !!! MODIFY: "server", "user", "password", "database" ( 'localhost','bugzilla3','pasteyourpass_a little_lower', 'bugzilla3' ) !!

echo "DELETE FROM mantis_user_table;";

bz2m_migration_profiles2mantis_user_table();  //CUSTOM
 \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON
 \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON
      \-> bz2m_migration_profiles2mantis_user_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM

bz2m_migration_products2mantis_project_table(); //CUSTOM
 \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON
 \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON
      \-> bz2m_migration_products2mantis_project_table_callback( $row_count, $flag_first, $key, $value );

bz2m_migration_bugs2mantis_bug_table(); //CUSTOM
 \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON
 \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON
      \-> bz2m_migration_bugs2mantis_bug_table_callback( $row_count, $flag_first, $key, $value );

bz2m_migration_bugs2mantis_bug_text_table(); //CUSTOM
 \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON
 \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON
      \-> bz2m_migration_products2mantis_project_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM

bz2m_migration_bugs_activity2mantis_bug_history_table(); //CUSTOM
 \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON
 \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON
      \-> bz2m_migration_bugs_activity2mantis_bug_history_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM

bz2m_migration_longdescs2mantis_bugnote_table(); //CUSTOM
 \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON
 \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON
      \-> bz2m_migration_longdescs2mantis_bugnote_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM

bz2m_migration_longdescs2mantis_bugnote_text_table(); //CUSTOM
 \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON
 \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON
      \-> bz2m_migration_longdescs2mantis_bugnote_text_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM

bz2m_migration_mantis_category_table(); //CUSTOM
 \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON
 \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON
      \-> bz2m_migration_mantis_category_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM

bz2m_migration_mantis_customclient_table(); //CUSTOM
 \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON
 \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON
      \-> bz2m_migration_mantis_customclient_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM

mysql_close( $link);

*/

// ------------------------------------------------------------------------------------------
//     PHP CODE
// ------------------------------------------------------------------------------------------

function bz2m_connect( &$mysqli ) { // BUGZILLA - connect to database
/*********
// PHP version before 5.6.16
	$link = mysql_connect('localhost', 'myuser', 'mypassword');
	if (!$link)
	{
	  die('Could not connect: ' . mysql_error());
	}

	mysql_select_db("bugs",  $link);
*********/
	$myport = 3306;
	$mysqli = new mysqli('localhost', 'myuser', 'mypassword', 'bugs', $myport);
	if ($mysqli->connect_error) {
		die('Erreur de connexion (' . $mysqli->connect_errno . ') '. $mysqli->connect_error);
	}

	echo 'Success... ' . $mysqli->host_info . "\n";
} 

// ------------------------------------------------------------------------------------------

function bz2m_select($con, $sql_fields, $sql_table, &$data, &$total ) { // BUGZILLA -  read bugs

	$sql="SELECT ";

	$flag_first = true;

	foreach ($sql_fields as $key1=> $value1 ) {
		if($flag_first ) {
			$flag_first = false;
			$sql = $sql."`".$value1."`";
		}
		else {
			$sql = $sql.","."`".$value1."`";
		}
	}
	$sql = $sql." FROM "."`".$sql_table."`";
//	$sql = $sql." FROM "."`".$sql_table."` WHERE `bug_id`<3";
//	$sql = $sql." FROM "."`".$sql_table."`  limit 0 ,3;";

	echo "<br />"; echo $sql;  echo "<br />";
	

	$result = mysqli_query($con, $sql );

	$columns = array();
	$data = array();

	// Table(Rows)
	while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
	{
		foreach ($sql_fields as $key1=> $value1 ) {
			$columns[]= $row[$value1];
			//echo "$value1 $row[$value1] <br />";
		}
		$data[]= $columns;
		unset($columns);
	}

	$total = mysqli_num_rows($result);
	mysqli_free_result($result);
}

// ------------------------------------------------------------------------------------------

function bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, &$data, $callback_function ) { // MANTIS -  write bugs

	$sql="INSERT INTO `$sql_table` (";

	$flag_first = true;

	foreach ($sql_fields as $key1=> $value1 ) {
		if($flag_first ) {
			$flag_first = false;
			$sql = $sql."`".$value1."`";
		}
		else {
			$sql = $sql.","."`".$value1."`";
		}
	}
	$sql = $sql.") VALUES( ";

	$sql_header = $sql;

	foreach ($data as $key0 => $value0 ) {
		unset($sql);
		$sql = $sql_header;
		$row_count = $key0 + 1;

		$flag_first = true;

		foreach ($value0 as $key1 => $value1 ) {
			$sql.= call_user_func( $callback_function, $row_count, $flag_first, $sql_fields_source[$key1], $value1);
			if($flag_first )
				$flag_first = false;
			//echo "<br />"; echo "$key1 $value1"; echo "<br />";

		}
		$sql.= " );";
		echo $sql; echo "<br />";

		
	}
}

// ------------------------------------------------------------------------------------------

function bz2m_migration_profiles2mantis_user_table($mysqli) //USERS
{
/*
USERS
#####

mysql> describe profiles;
+----------------+--------------+------+-----+---------+----------------+
| Field          | Type         | Null | Key | Default | Extra          |
+----------------+--------------+------+-----+---------+----------------+
| userid         | mediumint(9) | NO   | PRI | NULL    | auto_increment |
| login_name     | varchar(255) | NO   | UNI | NULL    |                |
| cryptpassword  | varchar(128) | YES  |     | NULL    |                |
| realname       | varchar(255) | YES  |     | NULL    |                |
| disabledtext   | mediumtext   | NO   |     | NULL    |                |
| disable_mail   | tinyint(4)   | NO   |     | 0       |                |
| mybugslink     | tinyint(4)   | NO   |     | 1       |                |
| extern_id      | varchar(64)  | YES  |     | NULL    |                |
| is_enabled 	 | tinyint(4)   | NO   |     | 1 	   |                |
| last_seen_date | datetime     | NO   |     | NULL    |                |
| email          | varchar(255) | NO   |     | NULL    |                |
+----------------+--------------+------+-----+---------+----------------+
11 rows in set (0.00 sec)

#####

mysql> describe mantis_user_table;
+-----------------------------+------------------+------+-----+---------------------+----------------+
| Field                       | Type             | Null | Key | Default             | Extra          |
+-----------------------------+------------------+------+-----+---------------------+----------------+
| id                          | int(10) unsigned | NO   | PRI | NULL                | auto_increment |
| username                    | varchar(32)      | NO   | UNI | NULL                |                |
| realname                    | varchar(64)      | NO   |     | NULL                |                |
| email                       | varchar(64)      | NO   |     | NULL                |                |
| password                    | varchar(32)      | NO   |     | NULL                |                |
| enabled                     | tinyint(4)       | NO   | MUL | 1                   |                |
| protected                   | tinyint(4)       | NO   |     | 0                   |                |
| access_level                | smallint(6)      | NO   | MUL | 10                  |                |
| login_count                 | int(11)          | NO   |     | 0                   |                |
| lost_password_request_count | smallint(6)      | NO   |     | 0                   |                |
| failed_login_count          | smallint(6)      | NO   |     | 0                   |                |
| cookie_string               | varchar(64)      | NO   | UNI | NULL                |                |
| last_visit                  | datetime         | NO   |     | 1970-01-01 00:00:01 |                |
| date_created                | datetime         | NO   |     | 1970-01-01 00:00:01 |                |
+-----------------------------+------------------+------+-----+---------------------+----------------+
14 rows in set (0.00 sec)

*/


$sql_table_source= "profiles";
$sql_fields_source=array( "userid","login_name","cryptpassword","realname","login_name", "last_seen_date", "cryptpassword" );

$sql_table= "mantis_user_table";
$sql_fields = array("id","username","password","realname","email","date_created", "cookie_string");
$callback_function = "bz2m_migration_profiles2mantis_user_table_callback";

// ------

$data = array();
$total = 0;

bz2m_select($mysqli, $sql_fields_source, $sql_table_source, $data, $total );
//echo "<br />"; echo "total:$total"; echo "<br />";
bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function );

}

// ------------------------------------------------------------------------------------------

function bz2m_migration_profiles2mantis_user_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS -  write bugs

	$sql = "";
	//echo "$key $value <br />";

switch ($key)
{
	case "userid":
		$value1 = $value;
		break;
	case "login_name":
	case "cryptpassword":
	case "realname":
	case "refreshed_when":
		$value1 = "'".str_replace("'", "''", $value)."'";
		break;
	default:
		$value1 = "DEFAULT_".$key."=".$value."_DEFAULT";
		break;
}


	if( isset($value1)  ) {

		if($flag_first ) {
			$sql = $value1;
		}
		else {
			$sql = ",".$value1;
		}
	}

		//echo "<br />"; echo $sql;
	return $sql;
}

// ------------------------------------------------------------------------------------------

function bz2m_migration_products2mantis_project_table($mysqli) //PROJECTS
{

/*
PROJECTS
#####
mysql> describe products;
+-------------------+-------------+------+-----+---------+----------------+
| Field             | Type        | Null | Key | Default | Extra          |
+-------------------+-------------+------+-----+---------+----------------+
| id                | smallint(6) | NO   | PRI | NULL    | auto_increment |
| name              | varchar(64) | NO   | UNI | NULL    |                |
| classification_id | smallint(6) | NO   |     | 1       |                |
| description       | mediumtext  | YES  |     | NULL    |                |
| isactive 	        | tinyint(4)  | NO   |     | 1       |                |
| votesperuser      | smallint(6) | NO   |     | NULL    |                |
| maxvotesperbug    | smallint(6) | NO   |     | 10000   |                |
| votestoconfirm    | smallint(6) | NO   |     | NULL    |                |
| defaultmilestone  | varchar(20) | NO   |     | ---     |                |
| allows_unconfirmed| tinyint(4)  | NO   |     | 1       |                |
+-------------------+-------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)

mysql> 

#####

mysql> describe mantis_project_table;
+----------------+------------------+------+-----+---------+----------------+
| Field          | Type             | Null | Key | Default | Extra          |
+----------------+------------------+------+-----+---------+----------------+
| id             | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name           | varchar(128)     | NO   | UNI | NULL    |                |
| status         | smallint(6)      | NO   |     | 10      |                |
| enabled        | tinyint(4)       | NO   |     | 1       |                |
| view_state     | smallint(6)      | NO   | MUL | 10      |                |
| access_min     | smallint(6)      | NO   |     | 10      |                |
| file_path      | varchar(250)     | NO   |     | NULL    |                |
| description    | text             | NO   |     | NULL    |                |
| category_id    | int(10) unsigned | NO   |     | 1       |                |
| inherit_global | tinyint(4)       | NO   |     | 0       |                |
+----------------+------------------+------+-----+---------+----------------+
10 rows in set (0.01 sec)

*/

$sql_table_source= "products";
$sql_fields_source= array( "id","name","description","votesperuser","votestoconfirm" );

$sql_table= "mantis_project_table";
$callback_function = "bz2m_migration_products2mantis_project_table_callback";
$sql_fields = array("id","name","description", "status", "enabled");


// ----

$data = array();
$total = 0;

bz2m_select($mysqli, $sql_fields_source, $sql_table_source, $data, $total );
//echo "<br />"; echo "total:$total"; echo "<br />";
bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function );

}

// ------------------------------------------------------------------------------------------

function bz2m_migration_products2mantis_project_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS -  write bugs

$sql = "";

	//echo "$key $value <br />";

switch ($key)
{
	case "id":
		$value1 = $value;
		break;
	case "name":
	case "description":
		$value1 = "'".str_replace("'", "''", htmlentities($value, ENT_HTML5, 'ISO-8859-15'))."'";
		break;
	case "votesperuser":
		$value1 = 10;
		break;
	case "votestoconfirm":
		$value1 = 1;
		break;
	default:
		$value1 = "DEFAULT_".$key."=".$value."_DEFAULT";
		break;
}


	if( isset($value1)  ) {

		if($flag_first ) {
			$sql = $value1;
		}
		else {
			$sql = ",".$value1;
		}
	}

		//echo "<br />"; echo $sql;
	return $sql;
}

// ------------------------------------------------------------------------------------------

function bz2m_migration_bugs2mantis_bug_table($con) //BUGS
{

/*
BUGS
#####
mysql> describe bugs;
+---------------------+--------------+------+-----+---------+----------------+
| Field               | Type         | Null | Key | Default | Extra          |
+---------------------+--------------+------+-----+---------+----------------+
| bug_id              | mediumint(9) | NO   | PRI | NULL    | auto_increment |
| assigned_to         | mediumint(9) | NO   | MUL | NULL    |                |
| bug_file_loc        | text         | YES  |     | NULL    |                |
| bug_severity        | varchar(64)  | NO   | MUL | NULL    |                |
| bug_status          | varchar(64)  | NO   | MUL | NULL    |                |
| creation_ts         | datetime     | YES  | MUL | NULL    |                |
| delta_ts            | datetime     | NO   | MUL | NULL    |                |
| short_desc          | mediumtext   | NO   | MUL | NULL    |                |
| op_sys              | varchar(64)  | NO   | MUL | NULL    |                |
| priority            | varchar(64)  | NO   | MUL | NULL    |                |
| product_id          | smallint(6)  | NO   | MUL | NULL    |                |
| rep_platform        | varchar(64)  | NO   |     | NULL    |                |
| reporter            | mediumint(9) | NO   | MUL | NULL    |                |
| version             | varchar(64)  | NO   | MUL | NULL    |                |
| component_id        | smallint(6)  | NO   | MUL | NULL    |                |
| resolution          | varchar(64)  | NO   | MUL | NULL    |                |
| target_milestone    | varchar(20)  | NO   | MUL | ---     |                |
| qa_contact          | mediumint(9) | YES  | MUL | NULL    |                |
| status_whiteboard   | mediumtext   | NO   |     | NULL    |                |
| votes               | mediumint(9) | NO   | MUL | 0       |                |
| lastdiffed          | datetime     | YES  |     | NULL    |                |
| everconfirmed       | tinyint(4)   | NO   |     | NULL    |                |
| reporter_accessible | tinyint(4)   | NO   |     | 1       |                |
| cclist_accessible   | tinyint(4)   | NO   |     | 1       |                |
| estimated_time      | decimal(5,2) | NO   |     | 0.00    |                |
| remaining_time      | decimal(5,2) | NO   |     | 0.00    |                |
| deadline            | datetime     | YES  |     | NULL    |                |
| cf_client           | varchar(255) | NO   |     |         |                |
| cf_customer         | varchar(64)  | NO   |     |         |                |
+---------------------+--------------+------+-----+---------+----------------+
29 rows in set (0.00 sec)


#####
mysql> describe mantis_bug_table;
+-------------------+------------------+------+-----+---------------------+----------------+
| Field             | Type             | Null | Key | Default             | Extra          |
+-------------------+------------------+------+-----+---------------------+----------------+
| id                | int(10) unsigned | NO   | PRI | NULL                | auto_increment |
| project_id        | int(10) unsigned | NO   | MUL | 0                   |                |
| reporter_id       | int(10) unsigned | NO   |     | 0                   |                |
| handler_id        | int(10) unsigned | NO   |     | 0                   |                |
| duplicate_id      | int(10) unsigned | NO   |     | 0                   |                |
| priority          | smallint(6)      | NO   |     | 30                  |                |
| severity          | smallint(6)      | NO   |     | 50                  |                |
| reproducibility   | smallint(6)      | NO   |     | 10                  |                |
| status            | smallint(6)      | NO   | MUL | 10                  |                |
| resolution        | smallint(6)      | NO   |     | 10                  |                |
| projection        | smallint(6)      | NO   |     | 10                  |                |
| eta               | smallint(6)      | NO   |     | 10                  |                |
| bug_text_id       | int(10) unsigned | NO   |     | 0                   |                |
| os                | varchar(32)      | NO   |     | NULL                |                |
| os_build          | varchar(32)      | NO   |     | NULL                |                |
| platform          | varchar(32)      | NO   |     | NULL                |                |
| version           | varchar(64)      | NO   |     | NULL                |                |
| fixed_in_version  | varchar(64)      | NO   | MUL | NULL                |                |
| build             | varchar(32)      | NO   |     | NULL                |                |
| profile_id        | int(10) unsigned | NO   |     | 0                   |                |
| view_state        | smallint(6)      | NO   |     | 10                  |                |
| summary           | varchar(128)     | NO   |     | NULL                |                |
| sponsorship_total | int(11)          | NO   | MUL | 0                   |                |
| sticky            | tinyint(4)       | NO   |     | 0                   |                |
| category_id       | int(10) unsigned | NO   |     | 1                   |                |
| date_submitted    | int(10) unsigned | NO   |     | 1                   |                |
| due_date          | int(10) unsigned | NO   |     | 1                   |                |
| last_updated      | int(10) unsigned | NO   |     | 1                   |                |
+-------------------+------------------+------+-----+---------------------+----------------+
29 rows in set (0.00 sec)

mysql>
*/

$sql_table_source= "bugs";
$sql_fields_source = array( "bug_id","assigned_to","bug_severity","bug_status","product_id","creation_ts","creation_ts","priority","reporter", "short_desc", "bug_id" , "component_id","resolution","version");

$sql_table= "mantis_bug_table";
$callback_function = "bz2m_migration_bugs2mantis_bug_table_callback";
$sql_fields = array("id","handler_id","severity","status","project_id","date_submitted","last_updated","priority","reporter_id", "summary", "bug_text_id", "category_id","resolution","version" );

// ---

$data = array();
$total = 0;

bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total );
//echo "<br />"; echo "total:$total"; echo "<br />";
bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function );

}

// ------------------------------------------------------------------------------------------

function bz2m_migration_bugs2mantis_bug_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS -  write bugs

$sql = "";
/*
Bugzilla
Bug, Evolution, Paramétrage, Documentation, Savoir

Bas, Haut, ND, Normal, TBas, THaut

Mantis
$s_severity_enum_string = '10:fonctionnalité,20:simple,30:texte,40:cosmétique,50:mineur,60:majeur,70:critique,80:bloquant';
$s_resolution_enum_string = '10:ouvert,20:corrigé,30:réouvert,40:impossible à reproduire,50:impossible à corriger,60:doublon,70:pas un bogue,80:suspendu,90:ne sera pas corrigé';
$s_status_enum_string = '10:nouveau,20:retour  d\'informations,30:accepté,40:confirmé,50:affecté,80:traité,90:fermé';
$s_priority_enum_string = '10:aucune,20:basse,30:normale,40:élevée,50:urgente,60:immédiate';
*/
$bug_severity_map = array( "Evolution"=>10, "Paramétrage"=>20, "Documentation"=>30, "Savoir"=>40, "Bug"=>60 );
$bug_status_map = array( "UNCONFIRMED"=>10, "NEW"=>40, "ASSIGNED"=>50, "VERIFIED"=>50, "RESOLVED"=>80, "CLOSED"=>90, "NON CONFIRMÉ"=>10, "RÉOUVERT"=>40, "REOPEN"=>40, "NOUVEAU"=>40, "ASSIGNÉ"=>50, "VÉRIFIÉ"=>50, "RESOLU"=>80, "FERMÉ"=>90 );
$bug_resolution_map = array( ""=>10, "DUPLICATE"=>60, "FIXED"=>20, "INVALID"=>70, "TESTNEEDED"=>30, "WONTFIX"=>90, "WORKSFORME"=>40 );
$bug_priority_map = array( "ND"=>10, "TBas"=>20, "Bas"=>20, "Normal"=>30, "Haut"=>40, "THaut"=>50 );

	//echo "$key $value <br />";

switch ($key)
{
	case "bug_id":
	case "assigned_to":
	case "reporter":
	case "product_id":
	case "component_id":
		$value1 = $value;
		break;
	case "short_desc":
		$value = str_replace("\"","'",htmlentities($value, ENT_HTML5, 'ISO-8859-15') );
		$value1 = "\"".$value."\"";
		break;
	case "version":
		$value = str_replace("\"","'",$value );
		$value1 = "\"".$value."\"";
		break;
	case "creation_ts":
		$value1 = strtotime( $value );
		break;

	case "bug_severity":
		if( isset($bug_severity_map[$value]) ) {
			$value1 = $bug_severity_map[$value];
		}
		else {
			$value1 = "VALUE_ERROR_".$value."_VALUE_ERROR";
		}
		break;
	case "bug_status":
		if( isset($bug_status_map[$value]) ) {
			$value1 = $bug_status_map[$value];
		}
		else {
			$value1 = "VALUE_ERROR_".$value."_VALUE_ERROR";
		}
		break;
	case "priority":
		if( isset($bug_priority_map[$value]) ) {
			$value1 = $bug_priority_map[$value];
		}
		else {
			$value1 = "VALUE_ERROR_".$value."_VALUE_ERROR";
		}
		break;

	case "resolution":
		if( isset($bug_resolution_map[$value]) ) {
			$value1 = $bug_resolution_map[$value];
		}
		else {
			$value1 = "VALUE_ERROR_".$value."_VALUE_ERROR";
		}
		break;
	default:
		$value1 = "DEFAULT_".$key."=".$value."_DEFAULT";
		break;
}


	if( isset($value1)  ) {

		if($flag_first ) {
			$sql = $value1;
		}
		else {
			$sql = ",".$value1;
		}
	}

		//echo "<br />"; echo $sql;
	return $sql;
}

// ------------------------------------------------------------------------------------------

function bz2m_migration_bugs_activity2mantis_bug_history_table($con) //BUGS HISTORY
{

/*
BUGS HISTORY
#####
mysql> describe bugs_activity;
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| bug_id    | mediumint(9) | NO   | MUL | NULL    |       |
| attach_id | mediumint(9) | YES  |     | NULL    |       |
| who       | mediumint(9) | NO   | MUL | NULL    |       |
| bug_when  | datetime     | NO   | MUL | NULL    |       |
| fieldid   | mediumint(9) | NO   | MUL | NULL    |       |
| added     | tinytext     | YES  |     | NULL    |       |
| removed   | tinytext     | YES  |     | NULL    |       |
| comment_id| int(11)      | YES  |     | NULL    |       |
| id        | int(11)      | NO   |     | AUTO    |       |
+-----------+--------------+------+-----+---------+-------+
9 rows in set (0.00 sec)

#####

mysql> describe mantis_bug_history_table;
+---------------+------------------+------+-----+---------------------+----------------+
| Field         | Type             | Null | Key | Default             | Extra          |
+---------------+------------------+------+-----+---------------------+----------------+
| id            | int(10) unsigned | NO   | PRI | NULL                | auto_increment |
| user_id       | int(10) unsigned | NO   | MUL | 0                   |                |
| bug_id        | int(10) unsigned | NO   | MUL | 0                   |                |
| field_name    | varchar(32)      | NO   |     | NULL                |                |
| old_value     | varchar(128)     | NO   |     | NULL                |                |
| new_value     | varchar(128)     | NO   |     | NULL                |                |
| type          | smallint(6)      | NO   |     | 0                   |                |
| date_modified | int              | NO   |     | NULL                |                |
+---------------+------------------+------+-----+---------------------+----------------+
8 rows in set (0.00 sec)

*/

$sql_table_source= "bugs_activity";
$sql_fields_source = array( "bug_id","who","bug_when","fieldid","added","removed" );

$sql_table= "mantis_bug_history_table";
$callback_function = "bz2m_migration_bugs_activity2mantis_bug_history_table_callback";
$sql_fields = array("bug_id","user_id","date_modified","field_name","old_value","new_value");

// ----

$data = array();
$total = 0;

bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total );
//echo "<br />"; echo "total:$total"; echo "<br />";
bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function );

}

// ------------------------------------------------------------------------------------------

function bz2m_migration_bugs_activity2mantis_bug_history_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS -  write bugs

$sql = "";

	//echo "$key $value <br />";

switch ($key)
{
	case "bug_id":
	case "who":
		$value1 = $value;
		break;	    
	case "bug_when":
		$value1 = strtotime( $value );
		break;
	case "fieldid":
	case "added":
	case "removed":
		$value1 = "'".str_replace("'", "''", $value)."'";
		break;
	default:
		$value1 = "DEFAULT_".$key."=".$value."_DEFAULT";
		break;
}


	if( isset($value1)  ) {

		if($flag_first ) {
			$sql = $value1;
		}
		else {
			$sql = ",".$value1;
		}
	}

		//echo "<br />"; echo $sql;
	return $sql;
}

// ------------------------------------------------------------------------------------------

function bz2m_migration_longdescs2mantis_bugnote_table($con) //BUGS DESCRIPTION
{

/*
BUGS DESCRIPTION
#####
                                       |
mysql> describe longdescs;
+-----------------+--------------+------+-----+---------+-------+
| Field           | Type         | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| comment_id      | mediumint(9) | NO   | MUL | NULL    |       |
| bug_id          | mediumint(9) | NO   | MUL | NULL    |       |
| who             | mediumint(9) | NO   | MUL | NULL    |       |
| bug_when        | datetime     | NO   | MUL | NULL    |       |
| work_time       | decimal(5,2) | NO   |     | 0.00    |       |
| thetext         | mediumtext   | YES  | MUL | NULL    |       |
| isprivate       | tinyint(4)   | NO   |     | 0       |       |
| already_wrapped | tinyint(4)   | NO   |     | 0       |       |
| type            | smallint(6)  | NO   |     | 0       |       |
| extra_data      | varchar(255) | NO   |     | 0       |       |
+-----------------+--------------+------+-----+---------+-------+
10 rows in set (0.00 sec)

#####

mysql> describe mantis_bugnote_table;
+-----------------+------------------+------+-----+---------------------+----------------+
| Field           | Type             | Null | Key | Default             | Extra          |
+-----------------+------------------+------+-----+---------------------+----------------+
| id              | int(10) unsigned | NO   | PRI | NULL                |                |
| bug_id          | int(10) unsigned | NO   | MUL | 0                   |                |
| reporter_id     | int(10) unsigned | NO   |     | 0                   |                |
| bugnote_text_id | int(10) unsigned | NO   |     | 0                   |                |
| view_state      | smallint(6)      | NO   |     | 10                  |                |
| note_type       | int(11)          | YES  |     | 0                   |                |
| note_attr       | varchar(250)     | YES  |     | NULL                |                |
| time_tracking   | int(10) unsigned | NO   |     | 0                   |                |
| last_modified   | int(10) unsigned | NO   | MUL | 1                   |                |
| date_submitted  | int(10) unsigned | NO   |     | 1                   |                |
+-----------------+------------------+------+-----+---------------------+----------------+
10 rows in set (0.01 sec)

mysql>

#####

*/

$sql_table_source= "longdescs";
$sql_fields_source = array("comment_id", "bug_id","who","bug_when","bug_when","work_time", );

$sql_table= "mantis_bugnote_table";
$callback_function = "bz2m_migration_longdescs2mantis_bugnote_table_callback";
$sql_fields = array("id", "bug_id","reporter_id","date_submitted","last_modified","bugnote_text_id",);

// ---------

$data = array();
$total = 0;

bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total );
//echo "<br />"; echo "total:$total"; echo "<br />";
bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function );

}

// ------------------------------------------------------------------------------------------

function bz2m_migration_longdescs2mantis_bugnote_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS -  write bugs

$sql = "";

	//echo "$key $value <br />";

switch ($key)
{
	case "bug_id":
	case "who":
	case "comment_id":
		$value1 = $value;
		break;
	case "bug_when":
		$value1 = strtotime( $value );
		break;
	case "work_time":
		$value1 = $row_count;
		break;
	case "thetext":
		$value = str_replace("\"","'",htmlentities($value, ENT_HTML5, 'ISO-8859-15') );
		$value = str_replace("\\","\\\\",$value );
		$value = str_replace("\n","<br />",$value );
		$value1 = "\"".$value."\"";
		break;
	default:
		$value1 = "DEFAULT_".$key."=".$value."_DEFAULT";
		break;
}


	if( isset($value1)  ) {

		if($flag_first ) {
			$sql = $value1;
		}
		else {
			$sql = ",".$value1;
		}
	}

		//echo "<br />"; echo $sql;
	return $sql;
}

// ------------------------------------------------------------------------------------------

function bz2m_migration_longdescs2mantis_bugnote_text_table($con) //BUGS DESCRIPTION
{

/*
BUGS DESCRIPTION
#####
                                       |
mysql> describe longdescs;
+-----------------+--------------+------+-----+---------+-------+
| Field           | Type         | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| comment_id      | mediumint(9) | NO   | MUL | NULL    |       |
| bug_id          | mediumint(9) | NO   | MUL | NULL    |       |
| who             | mediumint(9) | NO   | MUL | NULL    |       |
| bug_when        | datetime     | NO   | MUL | NULL    |       |
| work_time       | decimal(5,2) | NO   |     | 0.00    |       |
| thetext         | mediumtext   | YES  | MUL | NULL    |       |
| isprivate       | tinyint(4)   | NO   |     | 0       |       |
| already_wrapped | tinyint(4)   | NO   |     | 0       |       |
| type            | smallint(6)  | NO   |     | 0       |       |
| extra_data      | varchar(255) | NO   |     | 0       |       |
+-----------------+--------------+------+-----+---------+-------+
10 rows in set (0.00 sec)


mysql> describe mantis_bugnote_text_table;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    |                |
| note  | text             | NO   |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)


#####

*/

$sql_table_source= "longdescs";
$sql_fields_source = array("comment_id", "thetext" );

$sql_table= "mantis_bugnote_text_table";
$callback_function = "bz2m_migration_longdescs2mantis_bugnote_text_table_callback";
$sql_fields = array("id", "note");

// ---------

$data = array();
$total = 0;

bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total );
//echo "<br />"; echo "total:$total"; echo "<br />";
bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function );

}

// ------------------------------------------------------------------------------------------

function bz2m_migration_longdescs2mantis_bugnote_text_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS -  write bugs

$sql = "";

	//echo "$key $value <br />";

switch ($key)
{
	case "bug_id":
	case "comment_id":
		$value1 = $value;
		break;
	case "thetext":
		$value = str_replace("\"","'",htmlentities($value, ENT_HTML5, 'ISO-8859-15') );
		$value = str_replace("\\","\\\\",$value );
		$value = str_replace("\n","<br />",$value );
		$value1 = "\"".$value."\"";
		break;
	default:
		$value1 = "DEFAULT_".$key."=".$value."_DEFAULT";
		break;
}


	if( isset($value1)  ) {

		if($flag_first ) {
			$sql = $value1;
		}
		else {
			$sql = ",".$value1;
		}
	}

		//echo "<br />"; echo $sql;
	return $sql;
}
// ------------------------------------------------------------------------------------------

function bz2m_migration_bugs2mantis_bug_text_table($con) //BUGS DESCRIPTION
{

/*
BUGS DESCRIPTION
#####
mysql> describe bugs;
+---------------------+--------------+------+-----+---------+----------------+
| Field               | Type         | Null | Key | Default | Extra          |
+---------------------+--------------+------+-----+---------+----------------+
| bug_id              | mediumint(9) | NO   | PRI | NULL    | auto_increment |
| assigned_to         | mediumint(9) | NO   | MUL | NULL    |                |
| bug_file_loc        | text         | YES  |     | NULL    |                |
| bug_severity        | varchar(64)  | NO   | MUL | NULL    |                |
| bug_status          | varchar(64)  | NO   | MUL | NULL    |                |
| creation_ts         | datetime     | YES  | MUL | NULL    |                |
| delta_ts            | datetime     | NO   | MUL | NULL    |                |
| short_desc          | mediumtext   | NO   | MUL | NULL    |                |
| op_sys              | varchar(64)  | NO   | MUL | NULL    |                |
| priority            | varchar(64)  | NO   | MUL | NULL    |                |
| product_id          | smallint(6)  | NO   | MUL | NULL    |                |
| rep_platform        | varchar(64)  | NO   |     | NULL    |                |
| reporter            | mediumint(9) | NO   | MUL | NULL    |                |
| version             | varchar(64)  | NO   | MUL | NULL    |                |
| component_id        | smallint(6)  | NO   | MUL | NULL    |                |
| resolution          | varchar(64)  | NO   | MUL | NULL    |                |
| target_milestone    | varchar(20)  | NO   | MUL | ---     |                |
| qa_contact          | mediumint(9) | YES  | MUL | NULL    |                |
| status_whiteboard   | mediumtext   | NO   |     | NULL    |                |
| votes               | mediumint(9) | NO   | MUL | 0       |                |
| lastdiffed          | datetime     | YES  |     | NULL    |                |
| everconfirmed       | tinyint(4)   | NO   |     | NULL    |                |
| reporter_accessible | tinyint(4)   | NO   |     | 1       |                |
| cclist_accessible   | tinyint(4)   | NO   |     | 1       |                |
| estimated_time      | decimal(5,2) | NO   |     | 0.00    |                |
| remaining_time      | decimal(5,2) | NO   |     | 0.00    |                |
| deadline            | datetime     | YES  |     | NULL    |                |
| cf_client           | varchar(255) | NO   |     | NULL    |                |
| cf_customer         | varchar(64)  | NO   |     | NULL    |                |
+---------------------+--------------+------+-----+---------+----------------+
29 rows in set (0.00 sec)


mysql> describe mantis_bug_text_table;
+------------------------+------------------+------+-----+---------+----------------+
| Field                  | Type             | Null | Key | Default | Extra          |
+------------------------+------------------+------+-----+---------+----------------+
| id                     | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| description            | text             | NO   |     | NULL    |                |
| steps_to_reproduce     | text             | NO   |     | NULL    |                |
| additional_information | text             | NO   |     | NULL    |                |
+------------------------+------------------+------+-----+---------+----------------+
mysql>

#####

*/

$sql_table_source= "bugs";
$sql_fields_source = array( "bug_id","short_desc","resolution","votes");

$sql_table= "mantis_bug_text_table";
$callback_function = "bz2m_migration_bugs2mantis_bug_text_table_callback";
$sql_fields = array("id","description","additional_information","steps_to_reproduce");

// ---

$data = array();
$total = 0;

bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total );
//echo "<br />"; echo "total:$total"; echo "<br />";
bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function );

}

// ------------------------------------------------------------------------------------------

function bz2m_migration_bugs2mantis_bug_text_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS -  write bugs

$sql = "";

	//echo "$key $value <br />";

switch ($key)
{
	case "bug_id":
		$value1 = $value;
		break;
	case "short_desc":
	case "resolution":
		$value = str_replace("\"","'",htmlentities($value, ENT_HTML5, 'ISO-8859-15') );
		$value = str_replace("\\","\\\\",$value );
		$value = str_replace("\n","<br />",$value );
		$value1 = "\"".$value."\"";
		break;
	case "votes":
	    $value1 = "\"\"";
		break;
	default:
		$value1 = "DEFAULT_".$key."=".$value."_DEFAULT";
		break;
}


	if( isset($value1)  ) {

		if($flag_first ) {
			$sql = $value1;
		}
		else {
			$sql = ",".$value1;
		}
	}

		//echo "<br />"; echo $sql;
	return $sql;
}

// ------------------------------------------------------------------------------------------

function bz2m_migration_mantis_category_table($con) //BUGS CATEGORY
{

/*
BUGS DESCRIPTION
#####
                                       |
mysql> describe components;
+-----------------+--------------+------+-----+---------+-------+
| Field           | Type         | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| id              | mediumint(9) | NO   | PRI | NULL    | AUTO  |
| name            | varchar(64)  | NO   | MUL | NULL    |       |
| product_id      | smallint(6)  | NO   | MUL | NULL    |       |
| initialowner    | mediumint(9) | NO   | MUL | NULL    |       |
| initialqacontact| mediumint(9) | YES  | MUL | NULL    |       |
| description     | mediumtext   | NO   |     | NULL    |       |
| isactive        | tinyint(4)   | NO   |     | 1       |       |
+-----------------+--------------+------+-----+---------+-------+
7 rows in set (0.00 sec)


mysql> describe mantis_category_table;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(10) unsigned | NO   | PRI | NULL    |  AUTO          |
| project_id  | int(10) unsigned | NO   | MUL | 0       |                |
| user_id     | int(10) unsigned | NO   |     | 0       |                |
| name        | varchar(128)     | NO   |     |         |                |
| status      | int(10) unsigned | NO   |     | 0       |                |
+-------------+------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)


#####

*/

$sql_table_source= "components";
$sql_fields_source = array("id", "name" , "product_id", "isactive");

$sql_table= "mantis_category_table";
$callback_function = "bz2m_migration_mantis_category_table_callback";
$sql_fields = array("id", "name", "project_id", "status");

// ---------

$data = array();
$total = 0;

bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total );
//echo "<br />"; echo "total:$total"; echo "<br />";
bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function );

}

// ------------------------------------------------------------------------------------------

function bz2m_migration_mantis_category_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS -  write category

$sql = "";

	//echo "$key $value <br />";

switch ($key)
{
	case "id":
	case "product_id":
	case "isactive":
		$value1 = $value;
		break;
	case "name":
		$value = str_replace("\"","'",htmlentities($value, ENT_HTML5, 'ISO-8859-15') );
		$value = str_replace("\\","\\\\",$value );
		$value = str_replace("\n","<br />",$value );
		$value1 = "\"".$value."\"";
		break;
	default:
		$value1 = "DEFAULT_".$key."=".$value."_DEFAULT";
		break;
}


	if( isset($value1)  ) {

		if($flag_first ) {
			$sql = $value1;
		}
		else {
			$sql = ",".$value1;
		}
	}

		//echo "<br />"; echo $sql;
	return $sql;
}

// ------------------------------------------------------------------------------------------

function bz2m_migration_mantis_customclient_table($con) //BUGS CUSTOMCLIENT
{

/*
BUGS DESCRIPTION
#####
mysql> describe bugs;
+---------------------+--------------+------+-----+---------+----------------+
| Field               | Type         | Null | Key | Default | Extra          |
+---------------------+--------------+------+-----+---------+----------------+
| bug_id              | mediumint(9) | NO   | PRI | NULL    | auto_increment |
| assigned_to         | mediumint(9) | NO   | MUL | NULL    |                |
| bug_file_loc        | text         | YES  |     | NULL    |                |
| bug_severity        | varchar(64)  | NO   | MUL | NULL    |                |
| bug_status          | varchar(64)  | NO   | MUL | NULL    |                |
| creation_ts         | datetime     | YES  | MUL | NULL    |                |
| delta_ts            | datetime     | NO   | MUL | NULL    |                |
| short_desc          | mediumtext   | NO   | MUL | NULL    |                |
| op_sys              | varchar(64)  | NO   | MUL | NULL    |                |
| priority            | varchar(64)  | NO   | MUL | NULL    |                |
| product_id          | smallint(6)  | NO   | MUL | NULL    |                |
| rep_platform        | varchar(64)  | NO   |     | NULL    |                |
| reporter            | mediumint(9) | NO   | MUL | NULL    |                |
| version             | varchar(64)  | NO   | MUL | NULL    |                |
| component_id        | smallint(6)  | NO   | MUL | NULL    |                |
| resolution          | varchar(64)  | NO   | MUL | NULL    |                |
| target_milestone    | varchar(20)  | NO   | MUL | ---     |                |
| qa_contact          | mediumint(9) | YES  | MUL | NULL    |                |
| status_whiteboard   | mediumtext   | NO   |     | NULL    |                |
| votes               | mediumint(9) | NO   | MUL | 0       |                |
| lastdiffed          | datetime     | YES  |     | NULL    |                |
| everconfirmed       | tinyint(4)   | NO   |     | NULL    |                |
| reporter_accessible | tinyint(4)   | NO   |     | 1       |                |
| cclist_accessible   | tinyint(4)   | NO   |     | 1       |                |
| estimated_time      | decimal(5,2) | NO   |     | 0.00    |                |
| remaining_time      | decimal(5,2) | NO   |     | 0.00    |                |
| deadline            | datetime     | YES  |     | NULL    |                |
| cf_client           | varchar(255) | NO   |     |         |                |
| cf_customer         | varchar(64)  | NO   |     |         |                |
+---------------------+--------------+------+-----+---------+----------------+
29 rows in set (0.00 sec)


mysql> describe mantis_custom_field_string_table;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| field_id  | int(11) unsigned   | NO   | PRI | 0       |  AUTO          |
| bug_id  	| int(11) unsigned   | NO   | MUL | 0       |                |
| value     | varchar(255)       | NO   |     |         |                |
| text      | int(10) unsigned   | YES  |     |         |                |
+-------------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)


#####

*/

$sql_table_source= "bugs";
$sql_fields_source = array("cf_client", "bug_id", "cf_customer");

$sql_table= "mantis_custom_field_string_table";
$callback_function = "bz2m_migration_mantis_customclient_table_callback";
$sql_fields = array("field_id", "bug_id", "value");

// ---------

$data = array();
$total = 0;

bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total );
//echo "<br />"; echo "total:$total"; echo "<br />";
bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function );

}

// ------------------------------------------------------------------------------------------

function bz2m_migration_mantis_customclient_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS -  write customer

$sql = "";

	//echo "$key $value <br />";

switch ($key)
{
	case "cf_client":
		$value1 = 1;
		break;
	case "bug_id":
		$value1 = $value;
		break;
	case "cf_customer":
		if ($value == '---')
			$value1 = "\"\"";
		else
			$value1 = "\"|".htmlentities($value, ENT_HTML5, 'ISO-8859-15')."|\"";
		break;
	default:
		$value1 = "DEFAULT_".$key."=".$value."_DEFAULT";
		break;
}


	if( isset($value1)  ) {

		if($flag_first ) {
			$sql = $value1;
		}
		else {
			$sql = ",".$value1;
		}
	}

		//echo "<br />"; echo $sql;
	return $sql;
}

// ------------------------------------------------------------------------------------------

{ // BUGZILLA - MAIN

//echo "/* NB : FIRST CREATE ALL YOUR USER ACCOUNT IN MANTIS WITH THE CORRESPONDING ID FROM BUGZILLA */";
//echo "<br>";

echo "<html lang='fr' xmlns='http://www.w3.org/1999/xhtml'>
	<head>
		<title>Migration bugzilla to Mantis</title>
		<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
		<meta http-equiv='Content-Language' content='fr-fr' />
    </head>
    <body>";

bz2m_connect($mysqli);
/*
bz2m_migration_profiles2mantis_user_table($mysqli);

bz2m_migration_products2mantis_project_table($mysqli);

bz2m_migration_bugs2mantis_bug_table($mysqli);
bz2m_migration_bugs2mantis_bug_text_table($mysqli);

bz2m_migration_bugs_activity2mantis_bug_history_table($mysqli);

bz2m_migration_longdescs2mantis_bugnote_table($mysqli);
bz2m_migration_longdescs2mantis_bugnote_text_table($mysqli);

bz2m_migration_mantis_category_table($mysqli);

bz2m_migration_mantis_customclient_table($mysqli);
*/
echo "</body>
        </html>";
$mysqli->close();

/*********
// PHP version before 5.6.16
bz2m_migration_profiles2mantis_user_table();

bz2m_migration_products2mantis_project_table();

bz2m_migration_bugs2mantis_bug_table();
bz2m_migration_bugs2mantis_bug_text_table();

bz2m_migration_bugs_activity2mantis_bug_history_table();

bz2m_migration_longdescs2mantis_bugnote_table();
bz2m_migration_longdescs2mantis_bugnote_text_table();

mysql_close( $link);
*********/
}


?>

