<?php

if (!is_writeable('./config.inc.php')) {
	showmessage('config_writedisable');
}
$datadir = XCONVERT_ROOT.'./data/';
$childtypes = $childarrs = $tmparr = array();
if(is_dir($datadir)) {
	$cdir = dir($datadir);
	while($entry = $cdir->read()) {
		if(is_dir($datadir.$entry) && ($entry != '.' && $entry != '..')) {
			$childtypes[] = $entry;
			$cdir_extra = dir($datadir.$entry);
			while($entry_extra = $cdir_extra->read()) {
				if(is_dir($datadir.$entry.'/'.$entry_extra) && ($entry_extra != '.' && $entry_extra != '..')) {
					if(file_exists($datadir.$entry.'/'.$entry_extra.'/config.php')) {
						$childarrs[$entry][] = $entry_extra;
					}
				}
			}
			$cdir_extra->close();
		}
	}
	$cdir->close();

	$versions_arr = array();
	foreach($childarrs as $type => $childs) {
		foreach($childs as $child) {
			$childitemarr = explode("-", $child);
			if($childitemarr['1']) {
				$childitemarr['1'] = trim($childitemarr['1']);
				$version = substr($childitemarr['1'], 0, 2);
				if(substr($childitemarr['1'], -1) == 'X') {
					$tmparr[$type]['x'.$version][] = $child;
				} elseif(substr($childitemarr['1'], -2) == 'uc' || substr($childitemarr['1'], -3) == 'uch') {
					$tmparr[$type]['dz'.$version][] = $child;
				}
			} else {
				$tmparr[$type]['dz60'][] = $child;
			}
		}
		krsort($tmparr[$type]);
		foreach($tmparr[$type] as $key => $value) {
			$versions_arr[$type][] = $key;
			arsort($value);
			$tmparr[$type][$key] = $value;
		}
	}
	$childarrs = $tmparr;

	include template('childselect');
} else {
	showmessage('config_child_error');
}

?>