function importuser() { global $objDatabase, $_ARRAYLANG; $objTpl = new \Cx\Core\Html\Sigma(ASCMS_MODULE_PATH . '/Newsletter/View/Template/Backend'); \Cx\Core\Csrf\Controller\Csrf::add_placeholder($objTpl); $objTpl->setErrorHandling(PEAR_ERROR_DIE); \Env::get('ClassLoader')->loadFile(ASCMS_LIBRARY_PATH . '/importexport/import.class.php'); $objImport = new \Import(); $arrFields = array('email' => $_ARRAYLANG['TXT_NEWSLETTER_EMAIL_ADDRESS'], 'sex' => $_ARRAYLANG['TXT_NEWSLETTER_SEX'], 'salutation' => $_ARRAYLANG['TXT_NEWSLETTER_SALUTATION'], 'title' => $_ARRAYLANG['TXT_NEWSLETTER_TITLE'], 'lastname' => $_ARRAYLANG['TXT_NEWSLETTER_LASTNAME'], 'firstname' => $_ARRAYLANG['TXT_NEWSLETTER_FIRSTNAME'], 'position' => $_ARRAYLANG['TXT_NEWSLETTER_POSITION'], 'company' => $_ARRAYLANG['TXT_NEWSLETTER_COMPANY'], 'industry_sector' => $_ARRAYLANG['TXT_NEWSLETTER_INDUSTRY_SECTOR'], 'address' => $_ARRAYLANG['TXT_NEWSLETTER_ADDRESS'], 'zip' => $_ARRAYLANG['TXT_NEWSLETTER_ZIP'], 'city' => $_ARRAYLANG['TXT_NEWSLETTER_CITY'], 'country_id' => $_ARRAYLANG['TXT_NEWSLETTER_COUNTRY'], 'phone_office' => $_ARRAYLANG['TXT_NEWSLETTER_PHONE'], 'phone_private' => $_ARRAYLANG['TXT_NEWSLETTER_PHONE_PRIVATE'], 'phone_mobile' => $_ARRAYLANG['TXT_NEWSLETTER_PHONE_MOBILE'], 'fax' => $_ARRAYLANG['TXT_NEWSLETTER_FAX'], 'birthday' => $_ARRAYLANG['TXT_NEWSLETTER_BIRTHDAY'], 'uri' => $_ARRAYLANG['TXT_NEWSLETTER_WEBSITE'], 'notes' => $_ARRAYLANG['TXT_NEWSLETTER_NOTES'], 'language' => $_ARRAYLANG['TXT_NEWSLETTER_LANGUAGE']); if (isset($_POST['import_cancel'])) { // Abbrechen. Siehe Abbrechen $objImport->cancel(); \Cx\Core\Csrf\Controller\Csrf::header("Location: index.php?cmd=Newsletter&act=users&tpl=import"); exit; } elseif (isset($_POST['fieldsSelected'])) { // Speichern der Daten. Siehe Final weiter unten. $arrRecipients = $objImport->getFinalData($arrFields); if (empty($_POST['newsletter_recipient_associated_list'])) { self::$strErrMessage = $_ARRAYLANG['TXT_NEWSLETTER_SELECT_CATEGORY']; } else { $arrLists = array(); if (isset($_POST['newsletter_recipient_associated_list'])) { foreach (explode(',', $_POST['newsletter_recipient_associated_list']) as $listId) { array_push($arrLists, intval($listId)); } } $EmailCount = 0; $arrBadEmails = array(); $ExistEmails = 0; $NewEmails = 0; $recipientSendEmailId = isset($_POST['sendEmail']) ? intval($_POST['sendEmail']) : 0; foreach ($arrRecipients as $arrRecipient) { if (empty($arrRecipient['email'])) { continue; } if (!strpos($arrRecipient['email'], '@')) { continue; } $arrRecipient['email'] = trim($arrRecipient['email']); if (!\FWValidator::isEmail($arrRecipient['email'])) { array_push($arrBadEmails, $arrRecipient['email']); } else { $EmailCount++; $arrRecipientLists = $arrLists; // TODO: use FWUSER if (in_array($arrRecipient['salutation'], $this->_getRecipientTitles())) { $arrRecipientTitles = array_flip($this->_getRecipientTitles()); $recipientSalutationId = $arrRecipientTitles[$arrRecipient['salutation']]; } else { $recipientSalutationId = $this->_addRecipientTitle($arrRecipient['salutation']); } // try to parse the imported birthday in a usable format if (!empty($arrRecipient['birthday'])) { $arrDate = date_parse($arrRecipient['birthday']); $arrRecipient['birthday'] = $arrDate['day'] . '-' . $arrDate['month'] . '-' . $arrDate['year']; } $objRecipient = $objDatabase->SelectLimit("SELECT `id`,\n `language`,\n `status`,\n `notes`\n FROM `" . DBPREFIX . "module_newsletter_user`\n WHERE `email` = '" . addslashes($arrRecipient['email']) . "'", 1); if ($objRecipient->RecordCount() == 1) { $recipientId = $objRecipient->fields['id']; $recipientLanguage = $objRecipient->fields['language']; $recipientStatus = $objRecipient->fields['status']; $recipientNotes = !empty($objRecipient->fields['notes']) ? $objRecipient->fields['notes'] . ' ' . $arrRecipient['notes'] : $arrRecipient['notes']; $objList = $objDatabase->Execute("SELECT `category` FROM " . DBPREFIX . "module_newsletter_rel_user_cat WHERE user="******"\n SELECT id\n FROM " . DBPREFIX . "module_newsletter_user\n WHERE email='" . contrexx_input2db($arrRecipient['email']) . "'", 1); $recipientId = $objRecipient->fields['id']; $this->insertTmpEmail($recipientSendEmailId, $arrRecipient['email'], self::USER_TYPE_NEWSLETTER); // setting TmpEntry=1 will set the newsletter status=1, this will force an imediate stop in the newsletter send procedere. if ($this->SendEmail($recipientId, $recipientSendEmailId, $arrRecipient['email'], 1, self::USER_TYPE_NEWSLETTER) == false) { self::$strErrMessage .= $_ARRAYLANG['TXT_SENDING_MESSAGE_ERROR']; } else { // TODO: Unused // $objUpdateCount = $objDatabase->execute(' UPDATE ' . DBPREFIX . 'module_newsletter SET recipient_count = recipient_count+1 WHERE id=' . intval($recipientSendEmailId)); } } } } } self::$strOkMessage = $_ARRAYLANG['TXT_DATA_IMPORT_SUCCESSFUL'] . "<br/>" . $_ARRAYLANG['TXT_CORRECT_EMAILS'] . ": " . $EmailCount . "<br/>" . $_ARRAYLANG['TXT_NOT_VALID_EMAILS'] . ": " . implode(', ', $arrBadEmails) . "<br/>" . $_ARRAYLANG['TXT_EXISTING_EMAILS'] . ": " . $ExistEmails . "<br/>" . $_ARRAYLANG['TXT_NEW_ADDED_EMAILS'] . ": " . $NewEmails; $objImport->initFileSelectTemplate($objTpl); $objTpl->setVariable(array("IMPORT_ACTION" => "index.php?cmd=Newsletter&act=users&tpl=import", 'TXT_FILETYPE' => $_ARRAYLANG['TXT_NEWSLETTER_FILE_TYPE'], 'TXT_HELP' => $_ARRAYLANG['TXT_NEWSLETTER_IMPORT_HELP'], 'IMPORT_ADD_NAME' => $_ARRAYLANG['TXT_NEWSLETTER_SEND_EMAIL'], 'IMPORT_ADD_VALUE' => $this->_getEmailsDropDown(), 'IMPORT_ROWCLASS' => 'row1')); $objTpl->parse("additional"); $objTpl->setVariable(array('IMPORT_ADD_NAME' => $_ARRAYLANG['TXT_NEWSLETTER_LIST'], 'IMPORT_ADD_VALUE' => $this->_getAssociatedListSelection(), 'IMPORT_ROWCLASS' => 'row2')); $objTpl->parse("additional"); $this->_objTpl->setVariable('NEWSLETTER_USER_FILE', $objTpl->get()); } } elseif (empty($_POST['importfile']) || isset($_POST['imported']) && empty($_POST['newsletter_recipient_associated_list'])) { // Dateiauswahldialog. Siehe Fileselect $this->_pageTitle = $_ARRAYLANG['TXT_IMPORT']; $this->_objTpl->addBlockfile('NEWSLETTER_USER_FILE', 'module_newsletter_user_import', 'module_newsletter_user_import.html'); if (isset($_POST['imported']) && empty($_POST['newsletter_recipient_associated_list'])) { self::$strErrMessage = $_ARRAYLANG['TXT_NEWSLETTER_SELECT_CATEGORY']; } $objImport->initFileSelectTemplate($objTpl); $objTpl->setVariable(array("IMPORT_ACTION" => "index.php?cmd=Newsletter&act=users&tpl=import", 'TXT_FILETYPE' => $_ARRAYLANG['TXT_NEWSLETTER_FILE_TYPE'], 'TXT_HELP' => $_ARRAYLANG['TXT_NEWSLETTER_IMPORT_HELP'], 'IMPORT_ADD_NAME' => $_ARRAYLANG['TXT_NEWSLETTER_SEND_EMAIL'], 'IMPORT_ADD_VALUE' => $this->_getEmailsDropDown(), 'IMPORT_ROWCLASS' => 'row1')); $objTpl->parse("additional"); $objTpl->setVariable(array('IMPORT_ADD_NAME' => $_ARRAYLANG['TXT_NEWSLETTER_LIST'], 'IMPORT_ADD_VALUE' => $this->_getAssociatedListSelection(), 'IMPORT_ROWCLASS' => 'row2')); $objTpl->parse("additional"); $this->_objTpl->setVariable(array('TXT_NEWSLETTER_IMPORT_FROM_FILE' => $_ARRAYLANG['TXT_NEWSLETTER_IMPORT_FROM_FILE'], 'TXT_IMPORT' => $_ARRAYLANG['TXT_IMPORT'], 'TXT_NEWSLETTER_LIST' => $_ARRAYLANG['TXT_NEWSLETTER_LIST'], 'TXT_ENTER_EMAIL_ADDRESS' => $_ARRAYLANG['TXT_ENTER_EMAIL_ADDRESS'], 'NEWSLETTER_CATEGORY_MENU' => $this->_getAssociatedListSelection(), 'NEWSLETTER_IMPORT_FRAME' => $objTpl->get())); if (isset($_POST['newsletter_import_plain'])) { if (empty($_POST['newsletter_recipient_associated_list'])) { self::$strErrMessage = $_ARRAYLANG['TXT_NEWSLETTER_SELECT_CATEGORY']; } else { $arrLists = array(); if (isset($_POST['newsletter_recipient_associated_list'])) { foreach ($_POST['newsletter_recipient_associated_list'] as $listId) { array_push($arrLists, intval($listId)); } } $EmailList = str_replace(array(']', '[', "\t", "\n", "\r"), ' ', $_REQUEST["Emails"]); $EmailArray = preg_split('/[\\s"\';,:<>\\n]+/', contrexx_stripslashes($EmailList)); $EmailCount = 0; $arrBadEmails = array(); $ExistEmails = 0; $NewEmails = 0; foreach ($EmailArray as $email) { if (empty($email)) { continue; } if (!strpos($email, '@')) { continue; } if (!\FWValidator::isEmail($email)) { array_push($arrBadEmails, $email); } else { $EmailCount++; $objRecipient = $objDatabase->SelectLimit("SELECT `id` FROM `" . DBPREFIX . "module_newsletter_user` WHERE `email` = '" . addslashes($email) . "'", 1); if ($objRecipient->RecordCount() == 1) { foreach ($arrLists as $listId) { $this->_addRecipient2List($objRecipient->fields['id'], $listId); } $ExistEmails++; } else { $NewEmails++; if ($objDatabase->Execute("\n INSERT INTO `" . DBPREFIX . "module_newsletter_user` (\n `code`, `email`, `status`, `emaildate`\n ) VALUES (\n '" . $this->_emailCode() . "', '" . addslashes($email) . "', 1, " . time() . "\n )") !== false) { $this->_setRecipientLists($objDatabase->Insert_ID(), $arrLists); } else { array_push($arrBadEmails, $email); } } } } self::$strOkMessage = $_ARRAYLANG['TXT_DATA_IMPORT_SUCCESSFUL'] . "<br/>" . $_ARRAYLANG['TXT_CORRECT_EMAILS'] . ": " . $EmailCount . "<br/>" . $_ARRAYLANG['TXT_NOT_VALID_EMAILS'] . ": "" . implode(', ', $arrBadEmails) . ""<br/>" . $_ARRAYLANG['TXT_EXISTING_EMAILS'] . ": " . $ExistEmails . "<br/>" . $_ARRAYLANG['TXT_NEW_ADDED_EMAILS'] . ": " . $NewEmails; } } $this->_objTpl->parse('module_newsletter_user_import'); } else { // Felderzuweisungsdialog. Siehe Fieldselect $objImport->initFieldSelectTemplate($objTpl, $arrFields); $arrLists = array(); if (isset($_POST['newsletter_recipient_associated_list'])) { foreach ($_POST['newsletter_recipient_associated_list'] as $listId) { array_push($arrLists, intval($listId)); } } $objTpl->setVariable(array('IMPORT_HIDDEN_NAME' => 'newsletter_recipient_associated_list', 'IMPORT_HIDDEN_VALUE' => !empty($arrLists) ? implode(',', $arrLists) : '')); $objTpl->parse('hidden_fields'); $objTpl->setVariable(array('IMPORT_HIDDEN_NAME' => 'sendEmail', 'IMPORT_HIDDEN_VALUE' => isset($_POST['sendEmail']) ? intval($_POST['sendEmail']) : 0)); $objTpl->parse('hidden_fields'); $objTpl->setVariable(array('IMPORT_ACTION' => 'index.php?cmd=Newsletter&act=users&tpl=import')); $this->_objTpl->setVariable(array('TXT_REMOVE_PAIR' => $_ARRAYLANG['TXT_REMOVE_PAIR'], 'NEWSLETTER_USER_FILE' => $objTpl->get())); } }
/** * Import * * Shows the import dialog * Customer. * @access private * @global ADONewConnection * @global array */ function _import() { global $objDatabase, $_ARRAYLANG; \Env::get('ClassLoader')->loadFile(ASCMS_LIBRARY_PATH . '/importexport/import.class.php'); $importlib = new \Import(); if (isset($_POST['import_cancel'])) { $importlib->cancel(); \Cx\Core\Csrf\Controller\Csrf::header("Location: index.php?cmd=MemberDir&act=import"); exit; } elseif ($_POST['fieldsSelected']) { $fieldnames = $this->getFieldData($_POST['directory']); foreach ($fieldnames as $fieldKey => $fieldValue) { if ($fieldValue['active']) { $fields[$fieldKey] = $fieldValue['name']; } } $data = $importlib->getFinalData($fields); foreach ($data as $row) { $query = "INSERT INTO " . DBPREFIX . "module_memberdir_values\n (`dirid`, `pic1`, `pic2`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`,\n `10`, `11`, `12`, `13`, `14`, `15`, `16`, `17`, `18`, `lang_id`) VALUES\n ('" . $_POST['directory'] . "',\n 'none', 'none',\n '" . $this->getDbInput($row[1]) . "',\n '" . $this->getDbInput($row[2]) . "',\n '" . $this->getDbInput($row[3]) . "',\n '" . $this->getDbInput($row[4]) . "',\n '" . $this->getDbInput($row[5]) . "',\n '" . $this->getDbInput($row[6]) . "',\n '" . $this->getDbInput($row[7]) . "',\n '" . $this->getDbInput($row[8]) . "',\n '" . $this->getDbInput($row[9]) . "',\n '" . $this->getDbInput($row[10]) . "',\n '" . $this->getDbInput($row[11]) . "',\n '" . $this->getDbInput($row[12]) . "',\n '" . $this->getDbInput($row[13]) . "',\n '" . $this->getDbInput($row[14]) . "',\n '" . $this->getDbInput($row[15]) . "',\n '" . $this->getDbInput($row[16]) . "',\n '" . $this->getDbInput($row[17]) . "',\n '" . $this->getDbInput($row[18]) . "',\n '" . $this->langId . "')\n "; if (!$objDatabase->Execute($query)) { echo $objDatabase->ErrorMsg(); } \Cx\Core\Csrf\Controller\Csrf::header("Location: index.php?cmd=MemberDir&act=showdir&id=" . $_POST['directory']); } } elseif ($_FILES['importfile']['size'] == 0) { $importlib->initFileSelectTemplate($this->_objTpl); /* * We need an additional input field for the selection * of the directory */ $this->_objTpl->setVariable(array("IMPORT_ACTION" => "?cmd=MemberDir&act=import", "IMPORT_ADD_NAME" => $_ARRAYLANG['TXT_DIRECTORY'], "IMPORT_ADD_VALUE" => $this->dirList('directory', $this->firstDir, 200), "IMPORT_ROWCLASS" => "row1", "TXT_HELP" => $_ARRAYLANG['TXT_IMPORT_HELP'])); $this->_objTpl->parse("additional"); } else { $fieldnames = $this->getFieldData($_POST['directory']); foreach ($fieldnames as $key => $value) { if ($value['active']) { $given_fields[$key] = $value['name']; } } $importlib->initFieldSelectTemplate($this->_objTpl, $given_fields); /* * We need to pass the directory value, given by the * file selection template to the next step of importing */ $this->_objTpl->setVariable(array("IMPORT_HIDDEN_NAME" => "directory", "IMPORT_HIDDEN_VALUE" => $_POST['directory'])); } }