/** * Parse a user's newsletter-list subscription interface * @param User User object of whoem the newsletter-list subscriptions shall be parsed */ protected function parseNewsletterLists($objUser) { global $_CONFIG, $objDatabase, $objInit; if (!$this->_objTpl->blockExists('access_newsletter')) { return; } if (\Cx\Core_Modules\License\License::getCached($_CONFIG, $objDatabase)->isInLegalComponents('Newsletter')) { $arrSubscribedNewsletterListIDs = $objUser->getSubscribedNewsletterListIDs(); $arrNewsletterLists = \Cx\Modules\Newsletter\Controller\NewsletterLib::getLists(); if (!count($arrNewsletterLists)) { $this->_objTpl->hideBlock('access_newsletter_list'); return; } $row = 0; foreach ($arrNewsletterLists as $listId => $arrList) { if ($objInit->mode != 'backend' && !$arrList['status'] && !in_array($listId, $arrSubscribedNewsletterListIDs)) { continue; } $this->_objTpl->setVariable(array($this->modulePrefix . 'NEWSLETTER_ID' => $listId, $this->modulePrefix . 'NEWSLETTER_NAME' => contrexx_raw2xhtml($arrList['name']), $this->modulePrefix . 'NEWSLETTER_SELECTED' => in_array($listId, $arrSubscribedNewsletterListIDs) ? 'checked="checked"' : '', $this->modulePrefix . 'NEWSLETTER_ROW_CLASS' => $row++ % 2 + 1)); $this->_objTpl->parse('access_newsletter_list'); } $this->_objTpl->touchBlock('access_newsletter'); if ($this->_objTpl->blockExists('access_newsletter_tab')) { $this->_objTpl->touchBlock('access_newsletter_tab'); } } else { $this->_objTpl->hideBlock('access_newsletter'); if ($this->_objTpl->blockExists('access_newsletter_tab')) { $this->_objTpl->hideBlock('access_newsletter_tab'); } } }
/** * Import Users from a CSV file * * Sets up common User and Profile fields as well as * Newsletter list relations. * Fields and their mapping: * Anrede -> Titel * Vorname * Name * eMail * Firma * Strasse -> Zusammen mit Hausnummer in Adresse * Hausnummer -> Zusammen mit Strasse in Adresse * PLZ * Ort * Land * Bundesland -> Evtl in Ort? * Tel.-Vorwahl -> Zusammen mit Tel.-Nummer in phone_office * Tel.-Nummer -> Zusammen mit Tel.-Vorwahl in phone_office * Fax-Vorwahl -> Zusammen mit Fax.-Nummer in phone_fax * Fax-Nummer -> Zusammen mit Fax.-Vorwahl in phone_fax * Mobil-Vorwahl -> Zusammen mit Mobil-Nummer in phone_mobile * Mobil-Nummer -> Zusammen mit Mobil-Vorwahl in phone_mobile * P1 -> Interessen: Newsletter Listen, kommagetrennt * -> Nicht vorhandene Listen werden angelegt * P2 -> Antwort: ? * P3 -> ? * P4 -> Titel: ? * P5 -> ? * Ursprungsformular -> ? * Permission -> ? * Ausgetragen -> Wenn true, alle Listenzuordnungen entfernen, sonst fehlende anlegen * Anzahl Hard-Bounces -> Nicht vorhanden? * Status -> Bedeutung? * Sprache -> Wird die verwendet? * ID -> Bedeutung? * Eintragungsdatum -> regdate * Aenderungsdatum -> ? (Nur regdate) * Austragungsdatum -> ? (Nur regdate) * @param string $file_name The CSV file name */ static function import_csv($file_name) { global $_ARRAYLANG; \Env::get('ClassLoader')->loadFile(ASCMS_LIBRARY_PATH . '/importexport/lib/csv.class.php'); //DBG::activate(DBG_ADODB_ERROR|DBG_LOG_FIREPHP|DBG_PHP); $objUser = \FWUser::getFWUserObject()->objUser; $objCsv = new \CsvLib(); $arrCsv = $objCsv->parse($file_name); // $arrFields = $arrCsv['fieldnames']; $arrUsers = $arrCsv['data']; //DBG::log("Found ".count($arrUsers)." Users in the CSV file"); foreach ($arrUsers as $arrUser) { //echo(var_export($arrUser, true)."<br />");// var_export($objUser, true)."<hr />" $email = $arrUser['3']; //DBG::log("Found e-mail $email"); if (!\FWValidator::isEmail($email)) { self::$arrStatusMsg['error'][] = sprintf($_ARRAYLANG['TXT_ACCESS_IMPORT_MESSAGE_TEMPLATE'], $email, $_ARRAYLANG['TXT_ACCESS_IMPORT_ERROR_INVALID_EMAIL']); continue; } // TODO: I suppose that the imported file is ISO-8859-1 or so $title = utf8_encode($arrUser[0]); $gender = preg_match('//', $title) ? 'gender_male' : 'gender_female'; $firstname = utf8_encode($arrUser[1]); $lastname = utf8_encode($arrUser[2]); $company = utf8_encode($arrUser[4]); $address = utf8_encode($arrUser[5]) . ' ' . utf8_encode($arrUser[6]); $zip = utf8_encode($arrUser[7]); $city = utf8_encode($arrUser[8]); $country = utf8_encode($arrUser[9]); $state = utf8_encode($arrUser[10]); if ($state) { $city .= ", {$state}"; } $phone_office = utf8_encode($arrUser[11]) . ' ' . utf8_encode($arrUser[12]); $phone_fax = utf8_encode($arrUser[13]) . ' ' . utf8_encode($arrUser[14]); $phone_mobile = utf8_encode($arrUser[15]) . ' ' . utf8_encode($arrUser[16]); $p1_lists = utf8_encode($arrUser[17]); $unsubscribed = utf8_encode($arrUser[24]); $language = utf8_encode($arrUser[27]); // These are all unused for the time being // $p2_answer = $arrUser[18]; // $p3 = $arrUser[19]; // $p4_title = $arrUser[20]; // $p5 = $arrUser[21]; // $source = $arrUser[22]; // $permission = $arrUser[23]; // $bounces = $arrUser[25]; // $status = $arrUser[26]; // $id = $arrUser[28]; // $date_subscribed = $arrUser[29]; // $date_changed = $arrUser[30]; // $date_unsubscribe = $arrUser[31]; $objUser = new \User(); $objUser = $objUser->getUsers(array('email' => array($email))); $new_user = false; if (!$objUser) { $new_user = true; $objUser = new \User(); $objUser->setUsername(\User::makeUsername($lastname, $firstname)); $objUser->setPassword(\User::makePassword()); $objUser->setEmail($email); } // TODO: Make new Users active or inactive? // $objUser->setActiveStatus(0); // $objUser->setAdminStatus(0); $lang_id = \FWLanguage::getLanguageIdByCode($language); $objUser->setFrontendLanguage($lang_id); $objUser->setBackendLanguage($lang_id); $objUser->setProfile(array('gender' => array($gender), 'title' => array($title), 'firstname' => array($firstname), 'lastname' => array($lastname), 'company' => array($company), 'address' => array($address), 'city' => array($city), 'zip' => array($zip), 'country' => array($country), 'phone_office' => array($phone_office), 'phone_mobile' => array($phone_mobile), 'phone_fax' => array($phone_fax))); $arrLists = preg_split('/\\s*,\\s*/', $p1_lists, null, PREG_SPLIT_NO_EMPTY); $arrListId = array(); if (preg_match('/false/i', $unsubscribed)) { // User has not unsubscribed (yet), collect the List IDs foreach ($arrLists as $list_name) { $list_id = \Cx\Modules\Newsletter\Controller\NewsletterLib::getListIdByName($list_name); //DBG::log("List '$list_name' => ID $list_id"); if (!$list_id) { // TODO: Shall I do this? $list_id = \Cx\Modules\Newsletter\Controller\NewsletterLib::_addList(addslashes($list_name)); self::$arrStatusMsg['ok'][] = sprintf($_ARRAYLANG['TXT_ACCESS_IMPORT_MESSAGE_TEMPLATE'], $list_name, $_ARRAYLANG['TXT_ACCESS_IMPORT_SUCCESS_LIST_CREATED']); } $arrListId[$list_id] = $list_id; } } $objUser->setNewsletterCategories($arrListId); if ($objUser->store()) { self::$arrStatusMsg['ok'][] = sprintf($_ARRAYLANG['TXT_ACCESS_IMPORT_MESSAGE_TEMPLATE'], $email, $new_user ? $_ARRAYLANG['TXT_ACCESS_IMPORT_SUCCESS_USER_CREATED'] : $_ARRAYLANG['TXT_ACCESS_IMPORT_SUCCESS_USER_UPDATED']); } else { self::$arrStatusMsg['error'][] = sprintf($_ARRAYLANG['TXT_ACCESS_IMPORT_MESSAGE_TEMPLATE'], $email, $_ARRAYLANG['TXT_ACCESS_IMPORT_ERROR_CREATING_USER']); } } }
/** * Store the user's newsletter-list-subscriptions to the database * @param mixed $subscriptionChange If $subscriptionChange is provided, then in case any * newsletter list subscription changes are being * flushed to the database, $subscriptionChange will * be set to TRUE, otherwise it'll be left untouched. * @return bool */ private function storeNewsletterSubscriptions(&$subscriptionChange = null) { global $objDatabase; if (!isset($this->arrNewsletterListIDs)) { return true; } $categories = $this->arrNewsletterListIDs; if (count($categories)) { foreach (array_keys($categories) as $key) { // Make sure they're integers $categories[$key] = intval($categories[$key]); $query = sprintf(' INSERT IGNORE INTO `%smodule_newsletter_access_user` ( `accessUserId`, `newsletterCategoryID`, `code` ) VALUES ( %s, %s, \'%s\' )', DBPREFIX, $this->id, $categories[$key], \Cx\Modules\Newsletter\Controller\NewsletterLib::_emailCode()); $objDatabase->Execute($query); if ($objDatabase->Affected_Rows()) { // track flushed db change $subscriptionChange = true; } } $delString = implode(',', $categories); $query = sprintf(' DELETE FROM `%smodule_newsletter_access_user` WHERE `newsletterCategoryID` NOT IN (%s) AND `accessUserId`=%s', DBPREFIX, $delString, $this->id); } else { $query = sprintf(' DELETE FROM `%smodule_newsletter_access_user` WHERE `accessUserId`=%s', DBPREFIX, $this->id); } if ($objDatabase->Execute($query) === false) { return false; } if ($objDatabase->Affected_Rows()) { // track flushed db change $subscriptionChange = true; } return true; }