<div id="Flash" class="flash_notice_error"></div>
<form id="importUsers" action="<?php echo $this->moduleBaseUrl ?>/users/importupload/" ENCTYPE="multipart/form-data">

	<table class="settings" style="margin:0px;">
		<tbody>
			<tr>
				<td colspan="2" class="contact_field">
					<h2><?php echo $this->translate('Import Users') ?></h2>
					<small style="font-weight:normal;">
						<?php print $this->translate('Upload a CSV file to import users into the system for bulk automation. See the table below for the fields required to batch import users. You can export a CSV from Spreadsheets such as Excel or build your own using a text-editor/utility.') ?>
						<a target='_blank' href='<?php echo $this->siteBaseUrl ?>/downloads/sample-users.csv'><?php print $this->translate('Download sample CSV</a> for import fields required.') ?>
						
					</small>
				</td>
			</tr>	
			

		</table>
				</div>
		
		<div class="divider"></div>
				
		<table class="settings">
			<tr>
				<td class="contact_field" style="width:150px;">
					<strong>
						<?php print $this->translate('Step 1. Upload CSV')?>
					</strong>
				</td>
				
				<td>					
					<div id="back_button" class='chooseCsv'><a href=""><span><?php echo $this->translate('Choose CSV file') ?></span></a></div>
					
					<div style='float: left; clear:both;'>
						<span class='importStatus'></span>
					
						<small>
							<?php print $this->translate(
                            'Import users from a CSV file. Upload a CSV file that defines the following fields for each user 
                            (one user per line): "email-address,firstname,lastname,password". Be careful to preserve the correct 
                            field order when creating your CSV file.')?>
						</small>
					
					</div>

					<br/>

				</td>
			</tr>
			<!--
			<tr>
				<td colspan="2">
				
				<div class="import-users-sample">
				<table class="sample"><tbody><tr class="header"><td><b>Email address</b></td> <td><b>First name</b></td> <td><b>Last name</b></td> <td><b>Password</b></td> </tr> <tr><td>simon.lambert@domain.com.au</td> <td>Simon</td> <td>Lambert</td> <td>83ha21pnb</td> </tr> <tr class="divide"><td>charlie@domain.com.au</td> <td>Charlie</td> <td>Cooper</td> <td>gy653js9s</td> </tr> <tr> <td>ariel@domain.com.au</td> <td>Ariel</td> <td>Jahns</td> <td>8uyb4630c</td> </tr></tbody></table>
									
				</td>
			</tr>
			-->
			
			</table>
				
		<div class="divider"></div>
		
		<table class="settings">
			
			<tr>
				<td colspan="2">
					<strong>
						<?php print $this->translate('Step 2. Import Options')?>
					</strong>
				</td>
			</tr>
			
			<!-- <tr>
				<td class="contact_field" style="width:150px;">
					<label>
						<?php print $this->translate('Import Users')?>
					</label>
				</td>
			
				
				<td>
					<input name="importUsers" type='hidden' value='0' />
					<input name="importUsers" type="checkbox" class="iphoneStyle" value="1" checked disabled/>
					<small>
						<?php print $this->translate('Import users listed in the CSV file')?>
					</small>
					
				</td>
			</tr>
			
			-->

			<tr class="space" id="pushSection">
				<td class="contact_field">
					<label class="settings_label">
						<?php echo $this->translate('Update Users') ?>
					</label>
				</td>
				<td>
					<input type="hidden" name="updatePass" value="0" />
					<input type="checkbox" name="updatePass" class="iphoneStyle" value="1"/>
					<small><?php print $this->translate('If existing users already exist in the system, update the account with the specified password in the CSV file')?></small>
				</td>
			</tr>

<?php if($this->userData['UMasterAdmin'] == '1') :?>
			<tr class="space" id="pushSection">
				<td class="contact_field">
					<label class="settings_label">
						<?php echo $this->translate('Auto Add Domains') ?>
					</label>
				</td>
				<td>
					<input type="hidden" name="addDomain" value="0" />
					<input type="checkbox" name="addDomain" class="iphoneStyle" value="1" checked/>
					<small><?php print $this->translate('Automatically import domains into the system that exist in the CSV file')?></small>
				</td>
			</tr>
<?php endif ?>						
			<tr>
				<td class="contact_field" style="width:150px;">
					<label>
						<?php print $this->translate('Email Welcome Message')?>
					</label>
				</td>
				
				<td>
					<input name="sendWelcome" type='hidden' value='0' />
					<input name="sendWelcome" type="checkbox" class="iphoneStyle" value="1" checked/>
					<small>
						<?php print $this->translate('Email new users the system welcome message, describing their account and setup information.')?>
					</small>
					
				</td>
			</tr>
			
	</table>

	<div class="divider"></div>

	<table class="settings">
		<tbody>
			<tr>
				<td colspan="2" class="contact_field">
					<div id="back_button" class='updategroup'><a href="#"><span><?php echo $this->translate('Upload CSV and Import Users') ?></span></a></div>
				</td>
			</tr>
		</tbody>
	</table>

</form>
<script type="text/javascript" language="JavaScript">

$( function()
{
	$('.iphoneStyle').iphoneStyle();
	
	$('.stronglastword').each( function() { $(this).stronglastword() })

	// bind to the form's submit event and cancel legacy submit
	$('.updategroup').bind('click', function() { $("form#importUsers").submit() })

	$("form#importUsers").submit( function()
	{
		
		if( !$("input[name=tmpfname]").val() ) {
			alert('Please upload a valid CSV file of users');
			return false;
		}
				
		$.php( $(this).attr("action"),$(this).serializeArray() )
		
		$("SPAN.importStatus").html("Importing Users - This may take several minutes ... <div class='upload-spin'></div>");
		
		return false

	});


	new AjaxUpload( $('DIV.chooseCsv'), {
		// Location of the server-side upload script
		action: "<?php echo $this->moduleBaseUrl ?>/users/importcsv/",
		// File upload name
		name: 'csvImport',
		// Submit file after selection
		autoSubmit: true,
		onSubmit: function(file, extension) 
		{ 
			//alert('in to submit');
			// Add an ajax spinnder
			$("SPAN.importStatus").html("<div class='upload-spin'></div>");

		},
		onChange: function(file, ext) {
			//alert('in to onchange');
		}, 
		onComplete: function(file, responseHTML) 
		{
			//alert('on complete');
			$("SPAN.importStatus").html(responseHTML);
		}

	});

	
})
</script>
