public function import() { $show_form = false; $done = false; $temp_dir = JPATH_SITE . '/tmp'; $file_list = xJUtility::getFileArray($temp_dir, 'csv', false, true); $params = array(); $lists = array(); if (!empty($_FILES)) { if (strpos($_FILES['import_file']['name'], '.csv') === false) { $last = strrpos($_FILES['import_file']['name'], '.'); $filename = substr($_FILES['import_file']['name'], 0, $last) . '.csv'; } else { $filename = $_FILES['import_file']['name']; } $destination = $temp_dir . '/' . $filename; if (move_uploaded_file($_FILES['import_file']['tmp_name'], $destination)) { $file_select = $filename; } } if (empty($file_select)) { $file_select = aecGetParam('file_select', ''); } if (empty($file_select)) { $show_form = true; $params['file_select'] = array('list', ''); $params['MAX_FILE_SIZE'] = array('hidden', '5120000'); $params['import_file'] = array('file', 'Upload', 'Upload a file and select it for importing', ''); $file_htmllist = array(); $file_htmllist[] = JHTML::_('select.option', '', JText::_('AEC_CMN_NONE_SELECTED')); if (!empty($file_list)) { foreach ($file_list as $name) { $file_htmllist[] = JHTML::_('select.option', $name, $name); } } $lists['file_select'] = JHTML::_('select.genericlist', $file_htmllist, 'file_select', 'size="' . min(count($file_htmllist) + 1, 25) . '"', 'value', 'text', 0); } else { $options = array(); if (!empty($_POST['assign_plan'])) { $options['assign_plan'] = $_POST['assign_plan']; } $import = new aecImport($temp_dir . '/' . $file_select, $options); if (!$import->read()) { die('could not read file'); } $import->parse(); if (empty($import->rows)) { die('could not find any entries in this file'); } $params['file_select'] = array('hidden', $file_select); if (!isset($_POST['convert_field_0'])) { $fields = array('id' => 'User ID', 'name' => 'User Full Name', 'username' => 'Username', 'email' => 'User Email', 'password' => 'Password', 'plan_id' => 'Payment Plan ID', 'invoice_number' => 'Invoice Number', 'expiration' => 'Membership Expiration'); $mis = array_merge(microIntegrationHandler::getMIList(false, false, false, false, 'mi_aecuserdetails')); foreach ($mis as $entry) { $mi = new microIntegration(); $mi->load($entry->id); if ($mi->callIntegration()) { $fields = array_merge($fields, $mi->mi_class->getCustomFields()); } } $field_htmllist = array(); $field_htmllist[] = JHTML::_('select.option', 0, 'Ignore'); foreach ($fields as $name => $longname) { $field_htmllist[] = JHTML::_('select.option', $name, $longname); } $cols = count($import->rows[0]); $columns = array(); for ($i = 0; $i < $cols; $i++) { $columns[] = 'convert_field_' . $i; $params['convert_field_' . $i] = array('list', '', '', ''); $lists['convert_field_' . $i] = JHTML::_('select.genericlist', $field_htmllist, 'convert_field_' . $i, 'size="1" class="select2-bootstrap"', 'value', 'text', 0); } $rows_count = count($import->rows); $rowcount = min($rows_count, 5); $rows = array(); for ($i = 0; $i < $rowcount; $i++) { $rows[] = $import->rows[$i]; } $params['assign_plan'] = array('list', 'Assign Plan', 'Assign users to a specific payment plan. Is overridden if you provide an individual plan ID with the "Payment Plan ID" field assignment.'); $params['skip_first'] = array('toggle', 'Skip First Line', 'Do not import the first line (use this if you have column names in the first line).'); $available_plans = SubscriptionPlanHandler::getActivePlanList(); $lists['assign_plan'] = JHTML::_('select.genericlist', $available_plans, 'assign_plan', 'size="5"', 'value', 'text', 0); } else { $import->getConversionList(); $import->import(array('skip_first' => $_POST['skip_first'])); $done = true; } } $settingsparams = array(); $settings = new aecSettings('import', 'general'); $settings->fullSettingsArray($params, $settingsparams, $lists); // Call HTML Class $aecHTML = new aecHTML($settings->settings, $settings->lists); $aecHTML->form = $show_form; $aecHTML->done = $done; if (!empty($import->errors)) { $aecHTML->errors = $import->errors; } if (!$show_form && !$done) { $aecHTML->user_rows = $rows; $aecHTML->user_rows_count = $rows_count; $aecHTML->columns = $columns; } HTML_AcctExp::import($aecHTML); }