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] [Dump Settings]



 $data)
	{
		$fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "$data[table]" . (!$data['orderfree'] ? " ORDER BY {$data[table]}id ASC" : ""));
		foreach ($fetch as $fitem)
		{
			$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);
			chmod('./docs/datatools_store.php', 0777);
		}
		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 '';
}

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

if ($_REQUEST['do'] == 'settings')
{
	$fout = <<query("SELECT * FROM " . TABLE_PREFIX . "setting");
	foreach ($settings as $setting)
	{
		$fout .= "\n\t'$setting[varname]' => '" . str_replace("'", "\'", $setting['value']) . "',";
	}
	
	$fout .= <<
FILE;
	
	file_put_contents('install/settings.php', $fout);
	chmod('install/settings.php', 0777);
	
	echo 'Dumping current settings into install/settings.php';
}

?>