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');
     }
 }
 /**
  * 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);
     $journalDao =& DAORegistry::getDAO('JournalDAO');
     $journal =& $journalDao->getById($this->journalId);
     $journalPrimaryLocale = AppLocale::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_codesafe($attrib->getValue()));
                             break;
                         case 'password':
                             $newUser->setMustChangePassword($attrib->getAttribute('change') == 'true' ? 1 : 0);
                             $encrypted = $attrib->getAttribute('encrypted');
                             if (isset($encrypted) && $encrypted !== 'plaintext') {
                                 $ojsEncryptionScheme = Config::getVar('security', 'encryption');
                                 if ($encrypted != $ojsEncryptionScheme) {
                                     $this->errors[] = __('plugins.importexport.users.import.encryptionMismatch', array('importHash' => $encrypted, 'ojsHash' => $ojsEncryptionScheme));
                                 }
                                 $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 = $journalPrimaryLocale;
                             }
                             $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 = $journalPrimaryLocale;
                             }
                             $newUser->setSignature($attrib->getValue(), $locale);
                             break;
                         case 'interests':
                             $newUser->setTemporaryInterests($attrib->getValue());
                             break;
                         case 'gossip':
                             $locale = $attrib->getAttribute('locale');
                             if (empty($locale)) {
                                 $locale = $journalPrimaryLocale;
                             }
                             $newUser->setGossip($attrib->getValue(), $locale);
                             break;
                         case 'biography':
                             $locale = $attrib->getAttribute('locale');
                             if (empty($locale)) {
                                 $locale = $journalPrimaryLocale;
                             }
                             $newUser->setBiography($attrib->getValue(), $locale);
                             break;
                         case 'locales':
                             $locales = array();
                             foreach (explode(':', $attrib->getValue()) as $locale) {
                                 if (AppLocale::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, $request)
 {
     $templateMgr = TemplateManager::getManager($request);
     parent::display($args, $request);
     $templateMgr->assign('roleOptions', array('' => 'manager.people.doNotEnroll', 'manager' => 'user.role.manager', 'editor' => 'user.role.editor', 'sectionEditor' => 'user.role.sectionEditor', 'layoutEditor' => 'user.role.layoutEditor', 'reviewer' => 'user.role.reviewer', 'copyeditor' => 'user.role.copyeditor', 'proofreader' => 'user.role.proofreader', 'author' => 'user.role.author', 'reader' => 'user.role.reader', 'subscriptionManager' => 'user.role.subscriptionManager'));
     $roleDao = DAORegistry::getDAO('RoleDAO');
     $journal = $request->getJournal();
     set_time_limit(0);
     switch (array_shift($args)) {
         case 'confirm':
             $this->import('UserXMLParser');
             $sendNotify = (bool) $request->getUserVar('sendNotify');
             $continueOnError = (bool) $request->getUserVar('continueOnError');
             import('lib.pkp.classes.file.FileManager');
             $fileManager = new FileManager();
             if (($userFile = $fileManager->getUploadedFilePath('userFile')) !== false) {
                 // Import the uploaded file
                 $parser = new UserXMLParser($journal->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('users', $users);
                 $templateMgr->assign('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');
             $roleDao = DAORegistry::getDAO('RoleDAO');
             $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->setTemporaryInterests($request->getUserVar($i . '_interests'));
                 $newUser->setGossip($request->getUserVar($i . '_gossip'), 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'), null);
                 $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($journal->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');
             $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
             $users = $userGroupDao->getUsersByContextId($journal->getId());
             $users = $users->toArray();
             $userExportDom = new UserExportDom();
             $doc = $userExportDom->exportUsers($journal, $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, $journal->getId());
                 foreach ($thisRoleUsers->toArray() as $user) {
                     $users[$user->getId()] = $user;
                 }
                 $rolePaths[] = $rolePath;
             }
             $users = array_values($users);
             $userExportDom = new UserExportDom();
             $doc =& $userExportDom->exportUsers($journal, $users, $rolePaths);
             header("Content-Type: application/xml");
             header("Cache-Control: private");
             header("Content-Disposition: attachment; filename=\"users.xml\"");
             echo XMLCustomWriter::getXML($doc);
             break;
         default:
             $templateMgr->display($this->getTemplatePath() . 'index.tpl');
     }
 }