{include file="$admingentemplates/admin_top.tpl"}
<div class="back">
    <a href="{$site_url}{$site_root}/admin/admin_settings.php">{$lang.button.back}</a>
</div>
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<font class=red_header>{$header.razdel_name}</font><font class=red_sub_header>&nbsp;|&nbsp;{$lang.admin_user.import.sub_header}</font>
<div class="help_text">
    <div class="close_help">
        <img src="{$site_root}{$template_root}/images/close_help.png" alt="">
    </div>
    <div class="help_body">
        <span class="help_title">{$lang.help}:</span>{$lang.admin_help.users_import}
    </div>
</div>
<table width="100%">
	<tr valign=top>
	{if $par eq ''}
		<td width="50%">
			<form action="{$file_name}" method="POST" enctype="multipart/form-data">
				<input type="hidden" name="sel" value="import">
				<input type="hidden" name="par" value="step_1">
				<table border="0" cellspacing="1" cellpadding="5" width="100%">
					<tr>
						<td align="left" width="20%">
							{$lang.admin_user.import.upload_csv}
						</td>
						<td align="left" width="20%">
							<input type="file" size="25" name="database">
						</td>

					</tr>
					<tr>
						<td align="left" width="20%">
							{$lang.admin_user.import.upload_zip}
						</td>
						<td align="left" width="20%">
							<input type="file" size="25" name="uploads">
						</td>

					</tr>
					<tr>
						<td align="left" width="20%">
							{$lang.admin_user.import.delimiter}
						</td>
						<td align="left" width="20%">
							<select id="delimiter" name="delimiter">
								<option value=";" selected>;</option>
								<option value=",">,</option>
							</select>
	<!--						<input type="text" name="delimiter" size="5">-->
						</td>

					</tr>
					<tr>
						<td align="left" width="20%">
							{$lang.admin_user.import.date_format}
						</td>
						<td align="left" width="20%">
							<input type="text" name="format_date" size="25" value="YYYY-MM-DD HH:MM:SS">
						</td>

					</tr>
					<tr>
						<td align="left" width="20%">
						</td>
						<td align="left" width="20%">
						</td>

					</tr>
					<tr>
						<td align="right" width="20%">
							<input type="submit" class="button" value="{$lang.button.next_step}">
						</td>
						<td align="left" width="20%">
						</td>

					</tr>
				</table>
			</form>
		</td>
		<td width="50%" align="left">
			<table width="100%" cellspacing="1" cellpadding="5" border="0">
				<tr>
					<td colspan="2">
						{$lang.admin_user.dont_have_user_database}
					</td>
				</tr>
				<tr>
					<td valign="top">
						<a href="http://www.saledatingprofiles.com/?from=pilotgroup.net" target="_blank">
							<img alt="SaleDatingProfiles.com" border="0" src="{$site_root}{$template_root}/images/saledatingprofiles_logo.jpg">
						</a>
					</td>
					<td width="100%" valign="top">
						<a href="http://www.saledatingprofiles.com/?from=pilotgroup.net" target="_blank">http://www.saledatingprofiles.com</a><br><br>
						{$lang.admin_user.user_database_promo}
					</td>
				</tr>
			</table>
		</td>
	{elseif $par eq 'step_1'}
			<td width="100%" colspan="2">
				<form action="{$file_name}" method="POST">
				<input type="hidden" name="sel" value="import">
				<input type="hidden" name="par" value="step_2">
				<input type="hidden" name="format" id="format" value="">

				<table border=0 class="table_main" cellspacing=1 cellpadding=5 width="100%">
					<tr bgcolor="#ffffff">
						<td class="table_header" width="30">
							{$lang.admin_user.import.fields_new_database}
						</td> 
						<td class="table_header" width="30%">
							{$lang.admin_user.import.fields_exist_database}
						</td>
						<td class="table_header" width="20%">
						</td>
						<td class="table_header" width="30%">
						</td>
					</tr>
					{section name=i loop=$headers}
					<tr>
						<td class="main_content_text">
							{$headers[i]}
						</td>
						<td class="main_content_text">
							<select name="{$headers[i]}" id="dp_{$headers[i]}" onchange="ShowType('dp_{$headers[i]}');">
								<option></option>
								{section name=j loop=$headers_dp}
									<option value="val_dp_{$headers_dp[j]}">{$headers_dp[j]}</option>
								{/section}
							</select>
						</td>
						<td class="main_content_text">
							<div id="format_dp_{$headers[i]}">
							</div>
						</td>
						<td class="main_content_text">
							<div id="type_dp_{$headers[i]}">
							</div>
						</td>
					</tr>
					{/section}
					<tr>
						<td>
							<input type="button" class="button" value="{$lang.button.import}" onclick="Import();">
						</td>
						<td colspan="3">
							<div id="status_import"></div>
						</td>
					</tr>
				</table>
				</form>
			</td>
	{/if}
	</tr>
</table>
{literal}
<script language="JavaScript" type="text/javascript">
var arr = new Array();
	i=0;
	{/literal}
	{section name=j loop=$headers}
	{literal}
	arr[i] = '{/literal}{$headers[j]}{literal}'
	i++;
	{/literal}
	{/section}
	{literal}
	
function ShowType(par) {
	text = $('#'+par).val();
	if(text == 'val_dp_password') {
		for(i=0;i<{/literal}{$headers|@sizeof}{literal};i++) {
			$("#format_dp_"+arr[i]).html("");
			$("#type_dp_"+arr[i]).html("");
		}
		$('#format').val("");
		$("#format_"+par).html("{/literal}{$lang.admin_user.import.format}{literal}");
		$("#type_"+par).html("<div><input type=\"radio\" name=\"type\" value=\"0\" onclick=\"SetFormat('0')\">{/literal}{$lang.admin_user.import.format_md5_yes}{literal}</div><div><input type=\"radio\" name=\"type\" value=\"1\" onclick=\"SetFormat('1')\">{/literal}{$lang.admin_user.import.format_md5_no}{literal}</div>");
	}
	if(text == 'val_dp_user_type') {
	}
}
function SetFormat(par) {
	$('#format').val(par);
}
function Import() {
	i=0;
	arr_select = new Array();
	arr_select_sort = new Array();
	arr_sort = new Array();
	arr_post = new Array();
	for (j=0;j<{/literal}{$headers|@sizeof}{literal};j++) {
		text = $('#dp_'+arr[j]).val();
		if(text != "") {
			arr_select[i] = text;
			arr_select_sort[i] = text;
			arr_post[i] = arr[j];
			i++;
			}
	}
	arr_select_sort.sort();
	k=0
	for(i=0;i<arr_select_sort.length-1;i++){
		if(arr_select_sort[i] != arr_select_sort[i+1]) {
			arr_sort[k] = arr_select_sort[i];
			k++;
		}
		if (i==arr_select_sort.length-2) {
			if(arr_select_sort[i] != arr_select_sort[i+1]) {
				arr_sort[k] = arr_select_sort[i+1];
			}
		}
	}

	if (arr_sort.length>0 && arr_sort.length<arr_select.length) {
		//несколько раз одно и то же поле
		$("#status_import").text("{/literal}{$lang.admin_user.import.err_fields_copy}{literal}");
		return;
	}

	format = $('#format').val();
	format_date = $('#format_date').val();
	str = '&sel=import&format='+format;
	for (i=0;i<{/literal}{$headers_dp|@sizeof}{literal};i++) {
		str = str+'&'+arr_select[i]+'='+arr_post[i];
	}
	$("#status_import").text("{/literal}{$lang.admin_user.import.process}{literal}")
	$.post(SERVER+"/backend.php?language_code={/literal}{$lang_code}{literal}"+str,function(data){
		ShowAjaxError(data);
		$("#status_import").html(data)
	});
}
</script>
{/literal}
{include file="$admingentemplates/admin_bottom.tpl"}