/** * Import users from CSV after all necessary mapping info has been provided. * * @return string formatted HTML to be printed */ public function importUsers() { // we need the UIDs of existing users later if we want to update users // unfortunately, sql_insert_id() doesn't work for SQL UPDATE statements // even though the MySQL reference handbook tells you so... $res = $this->getDatabaseConnection()->exec_SELECTquery($this->uniqueUserIdentifier . ',uid', $this->userTypeDBTable, 'pid=' . $this->defaultUserData['pid']); while ($row = $this->getDatabaseConnection()->sql_fetch_row($res)) { $users[] = $row[0]; $userIDS[] = $row[1]; } $this->getDatabaseConnection()->sql_free_result($res); // read the import file $CSV = $this->readDataFromFile(false); /** * Hook added on request of Franz Ripfel: * hook for pre-processing of read-in data. At this time of the import session, we have read in * the CSV as an array and pass it and the object itself to the external function as a REFERENCE. * Your external function may manipulate the array as it likes (fx. delete, alter datasets). * See function readCSV() for import details. */ if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rs_userimp']['beforeImportHook'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rs_userimp']['beforeImportHook'] as $_classRef) { $_procObj =& GeneralUtility::getUserObj($_classRef); $CSV = $_procObj->manipulateData($CSV, $this); } } $content = ''; // line counter $n = 0; // $main[] holds all read CSV values $users = array(); foreach ($CSV as $row) { // we are not working with numerical indexes, // so we need the keys for CSV values foreach ($this->numMap as $key => $value) { $sub[$key] = $row[$value]; } // merge in defaultUserData[] $users[$n] = array_merge($sub, $this->defaultUserData); // substitute customValues if ($this->enableAutoValues && is_array($this->inData['autoval'])) { // to save time, only defined values get computed foreach ($this->inData['autoval'] as $key2 => $val2) { // we need a second array for to store generated custom values // because it might happen that a user maps a field to a new value // and later wants to map the original field again (would have been overwritten by then). // the original value is preserved that way and may // be used throughout the whole mapping process. $sub2[$n][$this->inData['fieldmap'][$key2]] = $this->generateCustomValue($users[$n][$this->inData['fieldmap'][$key2]], $this->inData['customValue'][$key2], $row); } // merge the 2 arrays, $sub2 takes precedence $users[$n] = array_merge($users[$n], $sub2[$n]); } if (array_key_exists('useEMailAsUsername', $this->inData['settings']) && $this->inData['settings']['useEMailAsUsername'] == 1) { // Use e-mail as username if requested $users[$n]['username'] = $users[$n]['email']; } if (array_key_exists('generatePassword', $this->inData['settings']) && $this->inData['settings']['generatePassword'] == 1) { // Generate random password if configured $users[$n]['password'] = \Visol\RsUserimp\Utility\Algorithms::generateRandomString(32); } unset($sub); $n++; } // some counters $i = 0; // total users imported $j = 0; // total users skipped $m = 0; // total users read from CSV $u = 0; // total users updated // process users one by one foreach ($users as $user) { $msg = array(); $importUser = TRUE; $updateUser = FALSE; // check the imported user data - values are manipulated // and are passed by REFERENCE switch ((string) $this->userType) { case 'FE': $msg[] = $this->checkUserDataFE($user, $importUser); break; case 'TT': $msg[] = $this->checkUserDataTT($user, $importUser); break; case 'BE': $msg[] = $this->checkUserDataBE($user, $importUser); break; default: die($this->getLanguageService()->getLL('f1.tab5.error.unknownFatalError')); } // the user array has now only valid values // handle the user array: check if we have users, rename them if necessary, // skip import if necessary. // if we have already users in the DB... if (!empty($users) && $importUser) { // the username already exists while (in_array($user[$this->uniqueUserIdentifier], $users)) { if (!$this->enableAutoRename && !$this->enableUpdate) { $msg = array(); $msg[] = $this->getLanguageService()->getLL('f1.tab5.error.duplicateUserName'); $importUser = FALSE; // jump out of while break 1; } elseif ($this->enableUpdate) { //$msg = array(); //$msg[] = ;//$this->getLanguageService()->getLL('f1.tab5.error.duplicateUserName'); $updateUser = TRUE; break 1; } elseif ($this->enableAutoRename) { // rename current import users $newName = $user[$this->uniqueUserIdentifier] . '0'; // $msg[] = $this->getLanguageService()->getLL('f1.tab5.error.renamed'); // check for max value if (strlen($newName) > 39) { $msg = array(); $msg[] = $this->getLanguageService()->getLL('f1.tab5.error.userNameTooLong'); $importUser = FALSE; // jump out of while break 1; } else { $user[$this->uniqueUserIdentifier] = $newName; $main[$i][$this->uniqueUserIdentifier] = $user[$this->uniqueUserIdentifier]; } } } } // Use TCAdefaults to set default field values if the fields affected were not set by the import table $targetPidTsConfig = GeneralUtility::removeDotsFromTS(BackendUtility::getPagesTSconfig($user['pid'])); if (array_key_exists('TCAdefaults', $targetPidTsConfig) && array_key_exists($this->userTypeDBTable, $targetPidTsConfig['TCAdefaults'])) { $tcaDefaults = $targetPidTsConfig['TCAdefaults'][$this->userTypeDBTable]; foreach ($tcaDefaults as $key => $value) { if (!array_key_exists($key, $user)) { $user[$key] = $value; } } } $uid = $userIDS[$m]; if ($importUser) { if ($updateUser) { // Update existing user // SQL injection prevention foreach ($user as $key => $val) { $user[$key] = $this->getDatabaseConnection()->quoteStr($val, $this->userTypeDBTable); } $res = $this->getDatabaseConnection()->exec_UPDATEquery($this->userTypeDBTable, $this->uniqueUserIdentifier . "='" . $main[$m][$this->uniqueUserIdentifier] . "'", $user); // set uid $GLOBALS['BE_USER']->writelog(1, 1, 0, '', 'User %s [UID %s] updated by CSV import action', array($user['username'], $uid)); $content .= '<li><strong>' . sprintf($this->getLanguageService()->getLL('f1.tab5.userUpdated'), $user[$this->uniqueUserIdentifier], $userIDS[$m]) . '</strong> ' . (!empty($msg) ? implode(',', $msg) : '') . '</li>'; $u++; // BEWARE: updated users are added to the rollback dataset!!! $rollbackDataTemp[] = $uid; } else { // Insert new user // SQL injection prevention foreach ($user as $key => $val) { $user[$key] = $this->getDatabaseConnection()->quoteStr($val, $this->userTypeDBTable); } $res = $this->getDatabaseConnection()->exec_INSERTquery($this->userTypeDBTable, $user); // get uid $uid = $this->getDatabaseConnection()->sql_insert_id(); $GLOBALS['BE_USER']->writelog(1, 1, 0, '', 'User %s [UID %s] created by CSV import action', array($user[$this->uniqueUserIdentifier], $uid)); $users[] = $user[$this->uniqueUserIdentifier]; $i++; $content .= '<li><strong>' . sprintf($this->getLanguageService()->getLL('f1.tab5.userInserted'), $user[$this->uniqueUserIdentifier], $user['name'], $uid) . '</strong> ' . (!empty($msg) ? implode(',', $msg) : '') . '</li>'; $rollbackDataTemp[] = $uid; } } else { $export[] = $CSV[$m]; $content .= '<li><strong>' . sprintf($this->getLanguageService()->getLL('f1.tab5.userSkipped'), $user[$this->uniqueUserIdentifier], $uid) . '</strong> ' . (!empty($msg) ? implode(',', $msg) : '') . '</li>'; $j++; } $m++; } $content = '<strong>' . sprintf($this->getLanguageService()->getLL('f1.tab5.usersImported'), $m, $i, $u, $j) . '</strong><ul class="import-log">' . $content . '</ul>'; /** * If createDropFile is set, create a drop file which holds all skipped users. * The CSV format is determined by the import settings, so this file may be edited and re-imported * by simply using the previous preset (mapping). */ if ($this->createDropFile && is_array($export)) { $fileInfo = \TYPO3\CMS\Core\Utility\File\BasicFileUtility::getTotalFileInfo($this->file); $newFileName = 'DROPPED_' . $fileInfo['file']; $fileContent = array(); $fileContent[0][] = $this->columnNamesFromCSV; $fileContent = array_merge($fileContent[0], $export); $newAbsFile = GeneralUtility::getFileAbsFileName('uploads/tx_rsuserimp/' . 'DROPPED_' . $fileInfo['file']); //PATH_site.'typo3temp/'.$newFileName; $newRelFile = '/uploads/tx_rsuserimp/' . $newFileName; fputcsv($newAbsFile, $fileContent, $this->fieldDelimiter, $this->fieldEncaps); $content .= '<div align="center"><a href="' . $newRelFile . '">' . $this->getLanguageService()->getLL('f1.tab5.downloadFile') . '</a>'; } if (!empty($rollbackDataTemp)) { $fileInfo = \TYPO3\CMS\Core\Utility\File\BasicFileUtility::getTotalFileInfo($this->file); $file = $fileInfo['file']; $rollbackDataSets = implode(",", $rollbackDataTemp); $rollbackData = array('crdate' => time(), 'target_pid' => $this->defaultUserData['pid'], 'user_uid' => $GLOBALS['BE_USER']->user['uid'], 'title' => 'Import session of user ' . $GLOBALS['BE_USER']->user['username'] . ' [UID ' . $GLOBALS['BE_USER']->user['uid'] . ']: ' . $i . ' users imported to PID ' . $this->defaultUserData['pid'], 'usertype' => $this->userType, 'db_table' => $this->userTypeDBTable, 'unique_identifier' => $this->uniqueUserIdentifier, 'num_imp' => $i, 'num_drop' => $j, 'num_upd' => $u, 'file' => $file, 'dropfile' => $newAbsFile, 'active' => '1', 'deleted' => '0', 'session_data' => $rollbackDataSets); $res = $this->getDatabaseConnection()->exec_INSERTquery('tx_rsuserimp_sessions', $rollbackData); //insert } /** * After parsing the CSV file, the file gets deleted by either moving it to the recycler (if * present) or by deleting it. */ $FILE = array(); $FILE['delete'][] = array('data' => $this->file); $fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility'); $fileProcessor->init($this->getBackendUserAuthentication()->getFileMountRecords(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); $fileProcessor->init_actionPerms($GLOBALS['BE_USER']->user['fileoper_perms']); // use recycler: 0 = no, 1 = if available, 2 = always $fileProcessor->useRecycler = $this->useRecycler; $fileProcessor->start($FILE); $fileProcessor->processData(); return $content; }
/** * import CSV-Data in step-by-step mode * * @return string HTML form */ function cmd_displayImport() { $step = GeneralUtility::_GP('importStep'); $defaultConf = array('remove_existing' => 0, 'first_fieldname' => 0, 'valid_email' => 0, 'remove_dublette' => 0, 'update_unique' => 0); if (GeneralUtility::_GP('CSV_IMPORT')) { $importerConfig = GeneralUtility::_GP('CSV_IMPORT'); if ($step['next'] == 'mapping') { $this->indata = GeneralUtility::array_merge($defaultConf, $importerConfig); } else { $this->indata = $importerConfig; } } if (empty($this->indata)) { $this->indata = array(); } if (empty($this->params)) { $this->params = array(); } // merge it with inData, but inData has priority. $this->indata = GeneralUtility::array_merge($this->params, $this->indata); $currentFileInfo = BasicFileUtility::getTotalFileInfo($this->indata['newFile']); $currentFileName = $currentFileInfo['file']; $currentFileSize = GeneralUtility::formatSize($currentFileInfo['size']); $currentFileMessage = $currentFileName . ' (' . $currentFileSize . ')'; if (empty($this->indata['csv']) && !empty($_FILES['upload_1']['name'])) { $this->indata['newFile'] = $this->checkUpload(); // TYPO3 6.0 returns an object... if (is_object($this->indata['newFile'][0])) { $storageConfig = $this->indata['newFile'][0]->getStorage()->getConfiguration(); $this->indata['newFile'] = $storageConfig['basePath'] . ltrim($this->indata['newFile'][0]->getIdentifier(), '/'); } } elseif (!empty($this->indata['csv']) && empty($_FILES['upload_1']['name'])) { if ((strpos($currentFileInfo['file'], 'import') === false ? 0 : 1) && $currentFileInfo['realFileext'] === 'txt') { //do nothing } else { unset($this->indata['newFile']); } } if ($this->indata['back']) { $stepCurrent = $step['back']; } elseif ($this->indata['next']) { $stepCurrent = $step['next']; } elseif ($this->indata['update']) { $stepCurrent = 'mapping'; } if (strlen($this->indata['csv']) > 0) { $this->indata['mode'] = 'csv'; $this->indata['newFile'] = $this->writeTempFile(); } elseif (!empty($this->indata['newFile'])) { $this->indata['mode'] = 'file'; } else { unset($stepCurrent); } //check if "email" is mapped if ($stepCurrent === 'import') { $map = $this->indata['map']; $error = array(); //check noMap $newMap = GeneralUtility::removeArrayEntryByValue(array_unique($map), 'noMap'); if (empty($newMap)) { $error[] = 'noMap'; } elseif (!GeneralUtility::inArray($map, 'email')) { $error[] = 'email'; } if ($error) { $stepCurrent = 'mapping'; } } $out = ""; switch ($stepCurrent) { case 'conf': //get list of sysfolder //TODO: maybe only subtree von this->id?? $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title', 'pages', 'doktype = 254 AND ' . $GLOBALS['BE_USER']->getPagePermsClause(3) . BackendUtility::deleteClause('pages') . BackendUtility::BEenableFields('pages'), '', 'uid'); $optStorage = array(); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { if (BackendUtility::readPageAccess($row['uid'], $GLOBALS['BE_USER']->getPagePermsClause(1))) { $optStorage[] = array($row['uid'], $row['title'] . ' [uid:' . $row['uid'] . ']'); } } $GLOBALS['TYPO3_DB']->sql_free_result($res); $optDelimiter = array(array('comma', $GLOBALS['LANG']->getLL('mailgroup_import_separator_comma')), array('semicolon', $GLOBALS['LANG']->getLL('mailgroup_import_separator_semicolon')), array('colon', $GLOBALS['LANG']->getLL('mailgroup_import_separator_colon')), array('tab', $GLOBALS['LANG']->getLL('mailgroup_import_separator_tab'))); $optEncap = array(array('doubleQuote', ' " '), array('singleQuote', " ' ")); //TODO: make it variable? $optUnique = array(array('email', 'email'), array('name', 'name')); $this->params['inputDisable'] == 1 ? $disableInput = 'disabled="disabled"' : ($disableInput = ''); //show configuration $out = '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_header_conf') . '</h3>'; $tblLines = array(); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_storage'), $this->makeDropdown('CSV_IMPORT[storage]', $optStorage, $this->indata['storage'])); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_remove_existing'), '<input type="checkbox" name="CSV_IMPORT[remove_existing]" value="1"' . (!$this->indata['remove_existing'] ? '' : ' checked="checked"') . ' ' . $disableInput . '/> '); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_first_fieldnames'), '<input type="checkbox" name="CSV_IMPORT[first_fieldname]" value="1"' . (!$this->indata['first_fieldname'] ? '' : ' checked="checked"') . ' ' . $disableInput . '/> '); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_separator'), $this->makeDropdown('CSV_IMPORT[delimiter]', $optDelimiter, $this->indata['delimiter'], $disableInput)); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_encapsulation'), $this->makeDropdown('CSV_IMPORT[encapsulation]', $optEncap, $this->indata['encapsulation'], $disableInput)); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_csv_validemail-description'), '<input type="checkbox" name="CSV_IMPORT[valid_email]" value="1"' . (!$this->indata['valid_email'] ? '' : ' checked="checked"') . ' ' . $disableInput . '/> '); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_csv_dublette-description'), '<input type="checkbox" name="CSV_IMPORT[remove_dublette]" value="1"' . (!$this->indata['remove_dublette'] ? '' : ' checked="checked"') . ' ' . $disableInput . '/> '); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_update_unique'), '<input type="checkbox" name="CSV_IMPORT[update_unique]" value="1"' . (!$this->indata['update_unique'] ? '' : ' checked="checked"') . ' ' . $disableInput . '/>'); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_record_unique'), $this->makeDropdown('CSV_IMPORT[record_unique]', $optUnique, $this->indata['record_unique'], $disableInput)); $out .= $this->formatTable($tblLines, array('width=300', 'nowrap'), 0, array(0, 1)); $out .= '<br /><br />'; $out .= '<input type="submit" name="CSV_IMPORT[back]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_back') . '" /> <input type="submit" name="CSV_IMPORT[next]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_next') . '" />' . $this->makeHidden(array('CMD' => 'displayImport', 'importStep[next]' => 'mapping', 'importStep[back]' => 'upload', 'CSV_IMPORT[newFile]' => $this->indata['newFile'])); break; case 'mapping': //show charset selector $cs = array_unique(array_values($GLOBALS['LANG']->csConvObj->synonyms)); $charSets = array(); foreach ($cs as $charset) { $charSets[] = array($charset, $charset); } if (!isset($this->indata['charset'])) { $this->indata['charset'] = 'iso-8859-1'; } $out .= '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_mapping_charset') . '</h3>'; $tblLines = array(); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_mapping_charset_choose'), $this->makeDropdown('CSV_IMPORT[charset]', $charSets, $this->indata['charset'])); $out .= $this->formatTable($tblLines, array('nowrap', 'nowrap'), 0, array(1, 1), 'border="0" cellpadding="0" cellspacing="0" class="typo3-dblist"'); $out .= '<input type="submit" name="CSV_IMPORT[update]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_update') . '"/>'; unset($tblLines); //show mapping form $out .= '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_mapping_conf') . '</h3>'; if ($this->indata['first_fieldname']) { //read csv $csvData = $this->readExampleCSV(4); $csv_firstRow = $csvData[0]; $csvData = array_slice($csvData, 1); } else { //read csv $csvData = $this->readExampleCSV(3); $fieldsAmount = count($csvData[0]); $csv_firstRow = array(); for ($i = 0; $i < $fieldsAmount; $i++) { $csv_firstRow[] = 'field_' . $i; } } //read tt_address TCA $no_map = array('image'); $tt_address_fields = array_keys($GLOBALS['TCA']['tt_address']['columns']); foreach ($no_map as $v) { $tt_address_fields = GeneralUtility::removeArrayEntryByValue($tt_address_fields, $v); } $mapFields = array(); foreach ($tt_address_fields as $map) { $mapFields[] = array($map, str_replace(':', '', $GLOBALS['LANG']->sL($GLOBALS['TCA']['tt_address']['columns'][$map]['label']))); } //add 'no value' array_unshift($mapFields, array('noMap', $GLOBALS['LANG']->getLL('mailgroup_import_mapping_mapTo'))); $mapFields[] = array('cats', $GLOBALS['LANG']->getLL('mailgroup_import_mapping_categories')); reset($csv_firstRow); reset($csvData); $tblLines = array(); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_mapping_number'), $GLOBALS['LANG']->getLL('mailgroup_import_mapping_description'), $GLOBALS['LANG']->getLL('mailgroup_import_mapping_mapping'), $GLOBALS['LANG']->getLL('mailgroup_import_mapping_value')); for ($i = 0; $i < count($csv_firstRow); $i++) { //example CSV $exampleLines = array(); for ($j = 0; $j < count($csvData); $j++) { $exampleLines[] = array($csvData[$j][$i]); } $tblLines[] = array($i + 1, $csv_firstRow[$i], $this->makeDropdown('CSV_IMPORT[map][' . $i . ']', $mapFields, $this->indata['map'][$i]), $this->formatTable($exampleLines, array('nowrap'), 0, array(0), 'border="0" cellpadding="0" cellspacing="0" class="typo3-dblist" style="width:100%; border:0px; margin:0px;"')); } if ($error) { $out .= '<h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_mapping_error') . '</h3>'; $out .= $GLOBALS['LANG']->getLL('mailgroup_import_mapping_error_detail') . '<br /><ul>'; foreach ($error as $errorDetail) { $out .= '<li>' . $GLOBALS['LANG']->getLL('mailgroup_import_mapping_error_' . $errorDetail) . '</li>'; } $out .= '</ul>'; } //additional options $tblLinesAdd = array(); //header $tblLinesAdd[] = array($GLOBALS['LANG']->getLL('mailgroup_import_mapping_all_html'), '<input type="checkbox" name="CSV_IMPORT[all_html]" value="1"' . (!$this->indata['all_html'] ? '' : ' checked="checked"') . '/> '); //get categories $temp = BackendUtility::getModTSconfig($this->parent->id, 'TCEFORM.sys_dmail_group.select_categories.PAGE_TSCONFIG_IDLIST'); if (is_numeric($temp['value'])) { $rowCat = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_dmail_category', 'pid IN (' . $temp['value'] . ')' . BackendUtility::deleteClause('sys_dmail_category') . BackendUtility::BEenableFields('sys_dmail_category')); if (!empty($rowCat)) { $tblLinesAdd[] = array($GLOBALS['LANG']->getLL('mailgroup_import_mapping_cats'), ''); if ($this->indata['update_unique']) { $tblLinesAdd[] = array($GLOBALS['LANG']->getLL('mailgroup_import_mapping_cats_add'), '<input type="checkbox" name="CSV_IMPORT[add_cat]" value="1"' . ($this->indata['add_cat'] ? ' checked="checked"' : '') . '/> '); } foreach ($rowCat as $k => $v) { $tblLinesAdd[] = array(' ' . htmlspecialchars($v['category']), '<input type="checkbox" name="CSV_IMPORT[cat][' . $k . ']" value="' . $v['uid'] . '"' . ($this->indata['cat'][$k] != $v['uid'] ? '' : ' checked="checked"') . '/> '); } } } $out .= $this->formatTable($tblLines, array('nowrap', 'nowrap', 'nowrap', 'nowrap'), 1, array(0, 0, 1, 1), 'border="0" cellpadding="0" cellspacing="0" class="typo3-dblist"'); $out .= '<br /><br />'; //additional options $out .= '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_mapping_conf_add') . '</h3>'; $out .= $this->formatTable($tblLinesAdd, array('nowrap', 'nowrap'), 0, array(1, 1), 'border="0" cellpadding="0" cellspacing="0" class="typo3-dblist"'); $out .= '<br /><br />'; $out .= '<input type="submit" name="CSV_IMPORT[back]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_back') . '"/> <input type="submit" name="CSV_IMPORT[next]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_next') . '"/>' . $this->makeHidden(array('CMD' => 'displayImport', 'importStep[next]' => 'import', 'importStep[back]' => 'conf', 'CSV_IMPORT[newFile]' => $this->indata['newFile'], 'CSV_IMPORT[storage]' => $this->indata['storage'], 'CSV_IMPORT[remove_existing]' => $this->indata['remove_existing'], 'CSV_IMPORT[first_fieldname]' => $this->indata['first_fieldname'], 'CSV_IMPORT[delimiter]' => $this->indata['delimiter'], 'CSV_IMPORT[encapsulation]' => $this->indata['encapsulation'], 'CSV_IMPORT[valid_email]' => $this->indata['valid_email'], 'CSV_IMPORT[remove_dublette]' => $this->indata['remove_dublette'], 'CSV_IMPORT[update_unique]' => $this->indata['update_unique'], 'CSV_IMPORT[record_unique]' => $this->indata['record_unique'])); break; case 'import': //show import messages $out .= '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_ready_import') . '</h3>'; $out .= $GLOBALS['LANG']->getLL('mailgroup_import_ready_import_label') . '<br /><br />'; $out .= '<input type="submit" name="CSV_IMPORT[back]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_back') . '" /> <input type="submit" name="CSV_IMPORT[next]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_import') . '" />' . $this->makeHidden(array('CMD' => 'displayImport', 'importStep[next]' => 'startImport', 'importStep[back]' => 'mapping', 'CSV_IMPORT[newFile]' => $this->indata['newFile'], 'CSV_IMPORT[storage]' => $this->indata['storage'], 'CSV_IMPORT[remove_existing]' => $this->indata['remove_existing'], 'CSV_IMPORT[first_fieldname]' => $this->indata['first_fieldname'], 'CSV_IMPORT[delimiter]' => $this->indata['delimiter'], 'CSV_IMPORT[encapsulation]' => $this->indata['encapsulation'], 'CSV_IMPORT[valid_email]' => $this->indata['valid_email'], 'CSV_IMPORT[remove_dublette]' => $this->indata['remove_dublette'], 'CSV_IMPORT[update_unique]' => $this->indata['update_unique'], 'CSV_IMPORT[record_unique]' => $this->indata['record_unique'], 'CSV_IMPORT[all_html]' => $this->indata['all_html'], 'CSV_IMPORT[add_cat]' => $this->indata['add_cat'], 'CSV_IMPORT[charset]' => $this->indata['charset'])); $hiddenMapped = array(); foreach ($this->indata['map'] as $fieldNr => $fieldMapped) { $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[map][' . $fieldNr . ']', $fieldMapped); } if (is_array($this->indata['cat'])) { foreach ($this->indata['cat'] as $k => $catUID) { $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[cat][' . $k . ']', $catUID); } } $out .= implode('', $hiddenMapped); break; case 'startImport': //starting import & show errors //read csv if ($this->indata['first_fieldname']) { //read csv $csvData = $this->readCSV(); $csvData = array_slice($csvData, 1); } else { //read csv $csvData = $this->readCSV(); } //show not imported record and reasons, $result = $this->doImport($csvData); $out = '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_done') . '</h3>'; $defaultOrder = array('new', 'update', 'invalid_email', 'double'); if (!empty($this->params['resultOrder'])) { $resultOrder = GeneralUtility::trimExplode(',', $this->params['resultOrder']); } else { $resultOrder = array(); } $diffOrder = array_diff($defaultOrder, $resultOrder); $endOrder = array_merge($resultOrder, $diffOrder); foreach ($endOrder as $order) { $tblLines = array(); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_report_' . $order)); if (is_array($result[$order])) { foreach ($result[$order] as $k => $v) { $mapKeys = array_keys($v); $tblLines[] = array($k + 1, $v[$mapKeys[0]], $v['email']); } } $out .= $this->formatTable($tblLines, array('nowrap', 'first' => 'colspan="3"'), 1, array(1)); } //back button $out .= $this->makeHidden(array('CMD' => 'displayImport', 'importStep[back]' => 'import', 'CSV_IMPORT[newFile]' => $this->indata['newFile'], 'CSV_IMPORT[storage]' => $this->indata['storage'], 'CSV_IMPORT[remove_existing]' => $this->indata['remove_existing'], 'CSV_IMPORT[first_fieldname]' => $this->indata['first_fieldname'], 'CSV_IMPORT[delimiter]' => $this->indata['delimiter'], 'CSV_IMPORT[encapsulation]' => $this->indata['encapsulation'], 'CSV_IMPORT[valid_email]' => $this->indata['valid_email'], 'CSV_IMPORT[remove_dublette]' => $this->indata['remove_dublette'], 'CSV_IMPORT[update_unique]' => $this->indata['update_unique'], 'CSV_IMPORT[record_unique]' => $this->indata['record_unique'], 'CSV_IMPORT[all_html]' => $this->indata['all_html'], 'CSV_IMPORT[charset]' => $this->indata['charset'])); $hiddenMapped = array(); foreach ($this->indata['map'] as $fieldNr => $fieldMapped) { $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[map][' . $fieldNr . ']', $fieldMapped); } if (is_array($this->indata['cat'])) { foreach ($this->indata['cat'] as $k => $catUID) { $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[cat][' . $k . ']', $catUID); } } $out .= implode('', $hiddenMapped); break; case 'upload': default: //show upload file form $out = '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_header_upload') . '</h3>'; $tempDir = $this->userTempFolder(); $tblLines[] = $GLOBALS['LANG']->getLL('mailgroup_import_upload_file') . '<input type="file" name="upload_1" size="30" />'; if ($this->indata['mode'] == 'file' && !((strpos($currentFileInfo['file'], 'import') === false ? 0 : 1) && $currentFileInfo['realFileext'] === 'txt')) { $tblLines[] = $GLOBALS['LANG']->getLL('mailgroup_import_current_file') . '<b>' . $currentFileMessage . '</b>'; } if ((strpos($currentFileInfo['file'], 'import') === false ? 0 : 1) && $currentFileInfo['realFileext'] === 'txt') { $handleCSV = fopen($this->indata['newFile'], 'r'); $this->indata['csv'] = fread($handleCSV, filesize($this->indata['newFile'])); fclose($handleCSV); } $tblLines[] = ''; $tblLines[] = '<b>' . $GLOBALS['LANG']->getLL('mailgroup_import_or') . '</b>'; $tblLines[] = ''; $tblLines[] = $GLOBALS['LANG']->getLL('mailgroup_import_paste_csv'); $tblLines[] = '<textarea name="CSV_IMPORT[csv]" rows="25" wrap="off"' . $this->parent->doc->formWidthText(48, '', 'off') . '>' . GeneralUtility::formatForTextarea($this->indata['csv']) . '</textarea>'; $tblLines[] = '<input type="submit" name="CSV_IMPORT[next]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_next') . '" />'; $out .= implode('<br />', $tblLines); $out .= '<input type="hidden" name="CMD" value="displayImport" /> <input type="hidden" name="importStep[next]" value="conf" /> <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($tempDir) . '" ' . ($_POST['importNow'] ? 'disabled' : '') . '/> <input type="hidden" name="file[upload][1][data]" value="1" /> <input type="hidden" name="CSV_IMPORT[newFile]" value ="' . $this->indata['newFile'] . '">'; break; } $theOutput = $this->parent->doc->section($GLOBALS['LANG']->getLL('mailgroup_import') . BackendUtility::cshItem($this->cshTable, 'mailgroup_import', $GLOBALS['BACK_PATH']), $out, 1, 1, 0, TRUE); /** * Hook for cmd_displayImport * use it to manipulate the steps in the import process */ if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['cmd_displayImport'])) { $hookObjectsArr = array(); foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['cmd_displayImport'] as $classRef) { $hookObjectsArr[] =& GeneralUtility::getUserObj($classRef); } } if (is_array($hookObjectsArr)) { foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'cmd_displayImport')) { $theOutput = ''; $theOutput = $hookObj->cmd_displayImport($this); } } } return $theOutput; }