/**
	 * There has been a file selected; check that file for headers and what not to display something useful to the user.
	 */
	private function _import2(){
		$view = $this->getView();
		$request = $this->getPageRequest();

		$filename = \Core\Session::Get('user-import/file');
		$file = \Core\Filestore\Factory::File($filename);
		$contents = $file->getContentsObject();

		if(!$contents instanceof \Core\Filestore\Contents\ContentCSV){
			\Core\set_message($file->getBaseFilename() . ' does not appear to be a valid CSV file!', 'error');
			\Core\Session::UnsetKey('user-import/file');
			\Core\reload();
		}

		$hasheader = $contents->hasHeader();
		$data = $contents->parse();
		$total = sizeof($data);

		// Since I don't want to display the entire dataset in the preview...
		if($hasheader){
			$header = $contents->getHeader();
		}
		else{
			$header = array();
			$i=0;
			foreach($data[0] as $k => $v){
				$header[$i] = 'Column ' . ($i+1);
				$i++;
			}
		}
		$colcount = sizeof($header);

		if($total > 11){
			$preview = array_splice($data, 0, 10);
		}
		else{
			$preview = $data;
		}

		$form = new Form();
		$form->set('callsmethod', 'User\\ImportHelper::FormHandler2');
		$form->addElement('system', ['name' => 'key', 'value' => \Core\Session::Get('user-import/key')]);
		$form->addElement(
			'checkbox',
			[
				'name' => 'has_header',
				'title' => 'Has Header',
				'value' => 1,
				'checked' => $hasheader,
				'description' => 'If this CSV has a header record on line 1, (as illustrated below), check this to ignore that line.'
			]
		);

		$form->addElement(
			'checkbox',
			[
				'name' => 'merge_duplicates',
				'title' => 'Merge Duplicate Records',
				'value' => 1,
				'checked' => true,
				'description' => 'Merge duplicate records that may be found in the import.'
			]
		);

		// Only display the user groups if the current user has access to manage user groups.
		$usergroups = UserGroupModel::Find(['context = ']);
		if(sizeof($usergroups) && \Core\user()->checkAccess('p:/user/groups/manage')){
			$usergroupopts = array();
			foreach($usergroups as $ug){
				$usergroupopts[$ug->get('id')] = $ug->get('name');
			}
			$form->addElement(
				'checkboxes',
				[
					'name' => 'groups[]',
					'title' => 'User Groups to Assign',
					'options' => $usergroupopts,
					'description' => 'Check which groups to set the imported users to.  If merge duplicate records is selected, any found users will be set to the checked groups, (and consequently unset from any unchecked groups).',
				]
			);
		}
		else{
			$form->addElement('hidden', ['name' => 'groups[]', 'value' => '']);
		}

		// Get the map-to options.
		$maptos = ['' => '-- Do Not Map --', 'email' => 'Email', 'password' => 'Password'];

		$configs = UserConfigModel::Find([], null, 'weight asc, name desc');
		foreach($configs as $c){
			$maptos[ $c->get('key') ] = $c->get('name');
		}

		$maptoselects = [];
		foreach($header as $key => $title){
			$value = '';
			if(isset($maptos[$key])) $value = $key;
			if(array_search($title, $maptos)) $value = array_search($title, $maptos);

			$form->addElement(
				'select',
				[
					'name' => 'mapto[' . $key . ']',
					'title' => $title,
					'options' => $maptos,
					'value' => $value
				]
			);
		}


		$view->templatename = 'pages/user/import2.tpl';
		$view->assign('has_header', $hasheader);
		$view->assign('header', $header);
		$view->assign('preview', $preview);
		$view->assign('form', $form);
		$view->assign('total', $total);
		$view->assign('col_count', $colcount);
	}
	/**
	 * Internal function to parse and handle the user configs in the component.xml file.
	 * This is used for installations and upgrades.
	 *
	 * Returns false if nothing changed, else will return an int of the number of configuration options changed.
	 *
	 * @param boolean $install   Set to false to force uninstall/disable mode.
	 * @param int     $verbosity (default 0) 0: standard output, 1: real-time, 2: real-time verbose output.
	 *
	 * @return boolean | int
	 * @throws InstallerException
	 */
	public function _parseUserConfigs($install = true, $verbosity = 0) {
		// If the class isn't available, don't do anything here.
		// This is possible if I'm currently loading the user component!
		if(!class_exists('UserConfigModel')) return false;

		// Keep track of if this changed anything.
		$changes = array();

		$action = $install ? 'Installing' : 'Uninstalling';

		Core\Utilities\Logger\write_debug($action . ' User Configs for ' . $this->getName());

		// I need to get the schema definitions first.
		$node = $this->_xmlloader->getElement('userconfigs', false);

		if($node){
			trigger_error('Use of the <userconfigs/> metatag is deprecated in favour of the <users/> metatag.  (In the ' . $this->getName() . ' component)', E_USER_DEPRECATED);
		}
		else{
			// Try the 2.8 version, <users/>.
			$node = $this->_xmlloader->getElement('users');
		}

		// Now, get every table under this node.
		foreach ($node->getElementsByTagName('userconfig') as $confignode) {
			/** @var DOMElement $confignode */

			//<userconfig key="first_name" name="First Name"/>
			//<userconfig key="last_name" name="Last Name" default="" formtype="" onregistration="" options=""/>

			$key        = $confignode->getAttribute('key');
			$name       = $confignode->getAttribute('name');
			$default    = $confignode->getAttribute('default');
			$formtype   = $confignode->getAttribute('formtype');
			$onreg      = $confignode->getAttribute('onregistration');
			$onedit     = $confignode->getAttribute('onedit');
			$hidden     = $confignode->getAttribute('hidden');
			$options    = $confignode->getAttribute('options');
			$searchable = $confignode->getAttribute('searchable');
			$validation = $confignode->getAttribute('validation');
			$required   = $confignode->getAttribute('required');
			$weight     = $confignode->getAttribute('weight');

			// Defaults
			if($onreg === null)      $onreg = 1;
			if($onedit === null)     $onedit = 1;
			if($searchable === null) $searchable = 0;
			if($required === null)   $required = 0;
			if($weight === null)     $weight = 0;
			if($weight == '')        $weight = 0;
			if($hidden === null)     $hidden = 0;

			// OVERRIDES!
			// Any hidden config option must be set to not-onedit and not-onreg.
			if($hidden){
				$onedit = 0;
				$onreg  = 0;
			}

			if($verbosity == 2){
				CLI::PrintActionStart($action . ' userconfig ' . $key);
			}

			$model = UserConfigModel::Construct($key);
			$isnew = !$model->exists();

			if($install){
				// Installations create/save it!

				// First, all the default and non-editable fields.
				$model->set('default_name', $name);
				if($default)  $model->set('default_value', $default);
				if($formtype) $model->set('formtype', $formtype);
				$model->set('default_onregistration', $onreg);
				$model->set('default_onedit', $onedit);
				$model->set('searchable', $searchable);
				$model->set('hidden', $hidden);
				if($options)  $model->set('options', $options);
				$model->set('validation', $validation);
				$model->set('required', $required);
				$model->set('default_weight', $weight);

				// And now the admin-editable fields.
				// These only get set if the configuration option does not exist prior.
				if($isnew || $hidden){
					$model->set('name', $name);
					$model->set('onregistration', $onreg);
					$model->set('onedit', $onedit);
					$model->set('weight', $weight);
				}

				if($default)  $model->set('default_value', $default);
				if($formtype) $model->set('formtype', $formtype);

				if($model->save()){
					if($isnew){
						$changes[] = 'Created user config [' . $model->get('key') . '] as a [' . $model->get('formtype') . ' input]';
					}
					else{
						$changes[] = 'Updated user config [' . $model->get('key') . '] as a [' . $model->get('formtype') . ' input]';
					}
					if($verbosity == 2){
						CLI::PrintActionStatus(true);
					}
				}
				else{
					if($verbosity == 2){
						CLI::PrintActionStatus('skip');
					}
				}
			}
			else{
				// Uninstallations remove user configuration keys.
				$model->delete();
				$changes[] = 'Removed user config [' . $key . ']';
				if($verbosity == 2){
					CLI::PrintActionStatus(true);
				}
			}
		}

		return (sizeof($changes)) ? $changes : false;

	} // private function _parseUserConfigs