array('table' => db table, 'rebuild' => rebuild function) $THELIST = array( 'usergroups' => array( 'table' => 'usergroup', 'rebuild' => 'build_usergroups' ), 'statuses' => array( 'table' => 'status', 'rebuild' => 'build_statuses' ), 'severity' => array( 'table' => 'severity', 'rebuild' => 'build_severities' ), 'priorities' => array( 'table' => 'priority', 'rebuild' => 'build_priorities' ), 'resolutions' => array( 'table' => 'resolution', 'rebuild' => 'build_resolutions' ), 'user help' => array( 'table' => 'fieldhelp', 'rebuild' => 'build_user_help', 'orderfree' => true ) ); ?>

Data Tools

Here you can either export or import the standard data tables for Bugdar. These include things such as usergroups, priorities, etc.

[Export] [Import] [View]



 $data)
	{
		$fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "$data[table]" . (!$data['orderfree'] ? " ORDER BY {$data[table]}id ASC" : ""));
		while ($fitem = $db->fetch_array($fetch))
		{
			$exportlist["$display"][] = $fitem;
		}
		$db->free_result($fetch);
		
		echo "Exported $display\n";
	}
	
	$phpfile = '';
	
	if ($handle = fopen('./docs/datatools_store.php', 'w'))
	{
		if (fwrite($handle, $phpfile))
		{
			fclose($handle);
		}
		else
		{
			echo 'Could not write the file';
			exit;
		}
	}
	else
	{
		echo 'Could not open the file with mode "w"';
		exit;
	}
	
	echo "Wrote the file\n";
}

// ###################################################################

if ($_REQUEST['do'] == 'import')
{
	require('./docs/datatools_store.php');
	$DATASTORE = unserialize(stripslashes($DATASTORE));
	
	foreach ($THELIST AS $display => $data)
	{
		$db->query("TRUNCATE TABLE " . TABLE_PREFIX . "$data[table]");
		
		$fields = array();
		$values = array();
		foreach ($DATASTORE["$display"] AS $mainarray)
		{
			$fields = $values = array();
			foreach ($mainarray AS $field => $value)
			{
				$fields[] = $field;
				$values[] = "'" . $bugsys->escape($value) . "'";
			}
			$query = "INSERT INTO " . TABLE_PREFIX . "$data[table] (" . implode(', ', $fields) . ") VALUES (" . implode(', ', $values) . ")";
			echo str_replace(array('>', '<'), array('>', '<'), $query) . "\n";
			$db->query($query);
		}
		
		$data['rebuild']();
		echo "Rebuilding $data[table]\n\n";
	}
}

// ###################################################################

if ($_REQUEST['do'] == 'view')
{
	require_once('./docs/datatools_store.php');
	$DATASTORE = unserialize(stripslashes($DATASTORE));
	
	$build = '$data = array(';
	
	foreach ($THELIST AS $display => $data)
	{
		$build .= "\n\t'$data[table]' => array(";
		foreach ($DATASTORE["$display"] AS $mainarray)
		{
			$build .= "\n\t\tarray(";
			foreach ($mainarray AS $field => $value)
			{
				$build .= "\n\t\t\t'" . addslashes($field) . "' => '" . addslashes($value) . "',";
			}
			$build = substr($build, 0, strlen($build) - 1);
			$build .= "\n\t\t),";
		}
		$build = substr($build, 0, strlen($build) - 1);
		$build .= "\n\t),";
	}
	$build = substr($build, 0, strlen($build) - 1);
	
	$build .= "\n);";
	
	echo '';
}

?>