/** * Parse an XML users file into a set of users to import. * @param $file string path to the XML file to parse * @return array ImportedUsers the collection of users read from the file */ function &parseData($file) { $roleDao =& DAORegistry::getDAO('RoleDAO'); $success = true; $this->usersToImport = array(); $tree = $this->parser->parse($file); $schedConfDao =& DAORegistry::getDAO('SchedConfDAO'); $schedConf =& $schedConfDao->getSchedConf($this->schedConfId); $schedConfPrimaryLocale = Locale::getPrimaryLocale(); $site =& Request::getSite(); $siteSupportedLocales = $site->getSupportedLocales(); if ($tree !== false) { foreach ($tree->getChildren() as $user) { if ($user->getName() == 'user') { // Match user element $newUser = new ImportedUser(); foreach ($user->getChildren() as $attrib) { switch ($attrib->getName()) { case 'username': // Usernames must be lowercase $newUser->setUsername(strtolower($attrib->getValue())); break; case 'password': $newUser->setMustChangePassword($attrib->getAttribute('change') == 'true' ? 1 : 0); $encrypted = $attrib->getAttribute('encrypted'); if (isset($encrypted) && $encrypted !== 'plaintext') { $ocsEncryptionScheme = Config::getVar('security', 'encryption'); if ($encrypted != $ocsEncryptionScheme) { $this->errors[] = Locale::translate('plugins.importexport.users.import.encryptionMismatch', array('importHash' => $encrypted, 'ocsHash' => $ocsEncryptionScheme)); } $newUser->setPassword($attrib->getValue()); } else { $newUser->setUnencryptedPassword($attrib->getValue()); } break; case 'salutation': $newUser->setSalutation($attrib->getValue()); break; case 'first_name': $newUser->setFirstName($attrib->getValue()); break; case 'middle_name': $newUser->setMiddleName($attrib->getValue()); break; case 'last_name': $newUser->setLastName($attrib->getValue()); break; case 'initials': $newUser->setInitials($attrib->getValue()); break; case 'gender': $newUser->setGender($attrib->getValue()); break; case 'affiliation': $locale = $attrib->getAttribute('locale'); if (empty($locale)) { $locale = $schedConfPrimaryLocale; } $newUser->setAffiliation($attrib->getValue(), $locale); break; case 'email': $newUser->setEmail($attrib->getValue()); break; case 'url': $newUser->setUrl($attrib->getValue()); break; case 'phone': $newUser->setPhone($attrib->getValue()); break; case 'fax': $newUser->setFax($attrib->getValue()); break; case 'mailing_address': $newUser->setMailingAddress($attrib->getValue()); break; case 'country': $newUser->setCountry($attrib->getValue()); break; case 'signature': $locale = $attrib->getAttribute('locale'); if (empty($locale)) { $locale = $schedConfPrimaryLocale; } $newUser->setSignature($attrib->getValue(), $locale); break; case 'interests': $locale = $attrib->getAttribute('locale'); if (empty($locale)) { $locale = $schedConfPrimaryLocale; } $newUser->setInterests($attrib->getValue(), $locale); break; case 'gossip': $locale = $attrib->getAttribute('locale'); if (empty($locale)) { $locale = $schedConfPrimaryLocale; } $newUser->setGossip($attrib->getValue(), $locale); break; case 'biography': $locale = $attrib->getAttribute('locale'); if (empty($locale)) { $locale = $schedConfPrimaryLocale; } $newUser->setBiography($attrib->getValue(), $locale); break; case 'locales': $locales = array(); foreach (explode(':', $attrib->getValue()) as $locale) { if (Locale::isLocaleValid($locale) && in_array($locale, $siteSupportedLocales)) { array_push($locales, $locale); } } $newUser->setLocales($locales); break; case 'role': $roleType = $attrib->getAttribute('type'); if ($this->validRole($roleType)) { $role = new Role(); $role->setRoleId($roleDao->getRoleIdFromPath($roleType)); $newUser->addRole($role); } break; } } array_push($this->usersToImport, $newUser); } } } return $this->usersToImport; }
function display(&$args) { $templateMgr =& TemplateManager::getManager(); parent::display($args); $templateMgr->assign('roleOptions', array('' => 'manager.people.doNotEnroll', 'manager' => 'user.role.manager', 'director' => 'user.role.director', 'trackDirector' => 'user.role.trackDirector', 'reviewer' => 'user.role.reviewer', 'author' => 'user.role.author', 'reader' => 'user.role.reader')); $roleDao =& DAORegistry::getDAO('RoleDAO'); $schedConf =& Request::getSchedConf(); switch (array_shift($args)) { case 'confirm': $this->import('UserXMLParser'); $templateMgr->assign('helpTopicId', 'conference.currentConference.importExport'); $sendNotify = (bool) Request::getUserVar('sendNotify'); $continueOnError = (bool) Request::getUserVar('continueOnError'); import('file.FileManager'); if (($userFile = FileManager::getUploadedFilePath('userFile')) !== false) { // Import the uploaded file $parser = new UserXMLParser($schedConf->getConferenceId(), $schedConf->getId()); $users =& $parser->parseData($userFile); $i = 0; $usersRoles = array(); foreach ($users as $user) { $usersRoles[$i] = array(); foreach ($user->getRoles() as $role) { array_push($usersRoles[$i], $role->getRoleName()); } $i++; } $templateMgr->assign_by_ref('users', $users); $templateMgr->assign_by_ref('usersRoles', $usersRoles); $templateMgr->assign('sendNotify', $sendNotify); $templateMgr->assign('continueOnError', $continueOnError); $templateMgr->assign('errors', $parser->errors); // Show confirmation form $templateMgr->display($this->getTemplatePath() . 'importUsersConfirm.tpl'); } break; case 'import': $this->import('UserXMLParser'); $userKeys = Request::getUserVar('userKeys'); if (!is_array($userKeys)) { $userKeys = array(); } $sendNotify = (bool) Request::getUserVar('sendNotify'); $continueOnError = (bool) Request::getUserVar('continueOnError'); $users = array(); foreach ($userKeys as $i) { $newUser = new ImportedUser(); $newUser->setFirstName(Request::getUserVar($i . '_firstName')); $newUser->setMiddleName(Request::getUserVar($i . '_middleName')); $newUser->setLastName(Request::getUserVar($i . '_lastName')); $newUser->setUsername(Request::getUserVar($i . '_username')); $newUser->setEmail(Request::getUserVar($i . '_email')); $locales = array(); if (Request::getUserVar($i . '_locales') != null || is_array(Request::getUserVar($i . '_locales'))) { foreach (Request::getUserVar($i . '_locales') as $locale) { array_push($locales, $locale); } } $newUser->setLocales($locales); $newUser->setSignature(Request::getUserVar($i . '_signature'), null); $newUser->setBiography(Request::getUserVar($i . '_biography'), null); $newUser->setInterests(Request::getUserVar($i . '_interests'), null); $newUser->setCountry(Request::getUserVar($i . '_country')); $newUser->setMailingAddress(Request::getUserVar($i . '_mailingAddress')); $newUser->setFax(Request::getUserVar($i . '_fax')); $newUser->setPhone(Request::getUserVar($i . '_phone')); $newUser->setUrl(Request::getUserVar($i . '_url')); $newUser->setAffiliation(Request::getUserVar($i . '_affiliation')); $newUser->setGender(Request::getUserVar($i . '_gender')); $newUser->setInitials(Request::getUserVar($i . '_initials')); $newUser->setSalutation(Request::getUserVar($i . '_salutation')); $newUser->setPassword(Request::getUserVar($i . '_password')); $newUser->setMustChangePassword(Request::getUserVar($i . '_mustChangePassword')); $newUser->setUnencryptedPassword(Request::getUserVar($i . '_unencryptedPassword')); $newUserRoles = Request::getUserVar($i . '_roles'); if (is_array($newUserRoles) && count($newUserRoles) > 0) { foreach ($newUserRoles as $newUserRole) { if ($newUserRole != '') { $role = new Role(); $role->setRoleId(RoleDAO::getRoleIdFromPath($newUserRole)); $newUser->AddRole($role); } } } array_push($users, $newUser); } $parser = new UserXMLParser($schedConf->getConferenceId(), $schedConf->getId()); $parser->setUsersToImport($users); if (!$parser->importUsers($sendNotify, $continueOnError)) { // Failures occurred $templateMgr->assign('isError', true); $templateMgr->assign('errors', $parser->getErrors()); } $templateMgr->assign('importedUsers', $parser->getImportedUsers()); $templateMgr->display($this->getTemplatePath() . 'importUsersResults.tpl'); break; case 'exportAll': $this->import('UserExportDom'); $users =& $roleDao->getUsersBySchedConfId($schedConf->getId()); $users =& $users->toArray(); $doc =& UserExportDom::exportUsers($schedConf, $users); header("Content-Type: application/xml"); header("Cache-Control: private"); header("Content-Disposition: attachment; filename=\"users.xml\""); echo XMLCustomWriter::getXML($doc); break; case 'exportByRole': $this->import('UserExportDom'); $users = array(); $rolePaths = array(); foreach (Request::getUserVar('roles') as $rolePath) { $roleId = $roleDao->getRoleIdFromPath($rolePath); $thisRoleUsers =& $roleDao->getUsersByRoleId($roleId, $schedConf->getId()); foreach ($thisRoleUsers->toArray() as $user) { $users[$user->getId()] = $user; } $rolePaths[] = $rolePath; } $users = array_values($users); $doc =& UserExportDom::exportUsers($schedConf, $users, $rolePaths); header("Content-Type: application/xml"); header("Cache-Control: private"); header("Content-Disposition: attachment; filename=\"users.xml\""); echo XMLCustomWriter::getXML($doc); break; default: $this->setBreadcrumbs(); $templateMgr->display($this->getTemplatePath() . 'index.tpl'); } }