00001 <?php
00002
00015
00016
00017 import('classes.plugins.ImportExportPlugin');
00018
00019 import('xml.XMLCustomWriter');
00020
00021 class UserImportExportPlugin extends ImportExportPlugin {
00028 function register($category, $path) {
00029 $success = parent::register($category, $path);
00030 $this->addLocaleData();
00031 return $success;
00032 }
00033
00039 function getName() {
00040 return 'UserImportExportPlugin';
00041 }
00042
00043 function getDisplayName() {
00044 return __('plugins.importexport.users.displayName');
00045 }
00046
00047 function getDescription() {
00048 return __('plugins.importexport.users.description');
00049 }
00050
00051 function display(&$args) {
00052 $templateMgr =& TemplateManager::getManager();
00053 parent::display($args);
00054
00055 $templateMgr->assign('roleOptions', array(
00056 '' => 'manager.people.doNotEnroll',
00057 'manager' => 'user.role.manager',
00058 'director' => 'user.role.director',
00059 'trackDirector' => 'user.role.trackDirector',
00060 'reviewer' => 'user.role.reviewer',
00061 'author' => 'user.role.author',
00062 'reader' => 'user.role.reader'
00063 ));
00064
00065 $roleDao =& DAORegistry::getDAO('RoleDAO');
00066
00067 $schedConf =& Request::getSchedConf();
00068
00069 switch (array_shift($args)) {
00070 case 'confirm':
00071 $this->import('UserXMLParser');
00072 $templateMgr->assign('helpTopicId', 'conference.currentConference.importExport');
00073
00074 $sendNotify = (bool) Request::getUserVar('sendNotify');
00075 $continueOnError = (bool) Request::getUserVar('continueOnError');
00076
00077 import('file.FileManager');
00078 if (($userFile = FileManager::getUploadedFilePath('userFile')) !== false) {
00079
00080 $parser = new UserXMLParser($schedConf->getConferenceId(), $schedConf->getId());
00081 $users =& $parser->parseData($userFile);
00082
00083 $i = 0;
00084 $usersRoles = array();
00085 foreach ($users as $user) {
00086 $usersRoles[$i] = array();
00087 foreach ($user->getRoles() as $role) {
00088 array_push($usersRoles[$i], $role->getRoleName());
00089 }
00090 $i++;
00091 }
00092
00093 $templateMgr->assign_by_ref('users', $users);
00094 $templateMgr->assign_by_ref('usersRoles', $usersRoles);
00095 $templateMgr->assign('sendNotify', $sendNotify);
00096 $templateMgr->assign('continueOnError', $continueOnError);
00097 $templateMgr->assign('errors', $parser->errors);
00098
00099
00100 $templateMgr->display($this->getTemplatePath() . 'importUsersConfirm.tpl');
00101 }
00102 break;
00103 case 'import':
00104 $this->import('UserXMLParser');
00105 $userKeys = Request::getUserVar('userKeys');
00106 if (!is_array($userKeys)) $userKeys = array();
00107 $sendNotify = (bool) Request::getUserVar('sendNotify');
00108 $continueOnError = (bool) Request::getUserVar('continueOnError');
00109
00110 $users = array();
00111 foreach ($userKeys as $i) {
00112 $newUser = new ImportedUser();
00113 $newUser->setFirstName(Request::getUserVar($i.'_firstName'));
00114 $newUser->setMiddleName(Request::getUserVar($i.'_middleName'));
00115 $newUser->setLastName(Request::getUserVar($i.'_lastName'));
00116 $newUser->setUsername(Request::getUserVar($i.'_username'));
00117 $newUser->setEmail(Request::getUserVar($i.'_email'));
00118
00119 $locales = array();
00120 if (Request::getUserVar($i.'_locales') != null || is_array(Request::getUserVar($i.'_locales'))) {
00121 foreach (Request::getUserVar($i.'_locales') as $locale) {
00122 array_push($locales, $locale);
00123 }
00124 }
00125 $newUser->setLocales($locales);
00126 $newUser->setSignature(Request::getUserVar($i.'_signature'), null);
00127 $newUser->setBiography(Request::getUserVar($i.'_biography'), null);
00128 $newUser->setInterests(Request::getUserVar($i.'_interests'), null);
00129 $newUser->setGossip(Request::getUserVar($i.'_gossip'), null);
00130 $newUser->setCountry(Request::getUserVar($i.'_country'));
00131 $newUser->setMailingAddress(Request::getUserVar($i.'_mailingAddress'));
00132 $newUser->setFax(Request::getUserVar($i.'_fax'));
00133 $newUser->setPhone(Request::getUserVar($i.'_phone'));
00134 $newUser->setUrl(Request::getUserVar($i.'_url'));
00135 $newUser->setAffiliation(Request::getUserVar($i.'_affiliation'));
00136 $newUser->setGender(Request::getUserVar($i.'_gender'));
00137 $newUser->setInitials(Request::getUserVar($i.'_initials'));
00138 $newUser->setSalutation(Request::getUserVar($i.'_salutation'));
00139 $newUser->setPassword(Request::getUserVar($i.'_password'));
00140 $newUser->setMustChangePassword(Request::getUserVar($i.'_mustChangePassword'));
00141 $newUser->setUnencryptedPassword(Request::getUserVar($i.'_unencryptedPassword'));
00142
00143 $newUserRoles = Request::getUserVar($i.'_roles');
00144 if (is_array($newUserRoles) && count($newUserRoles) > 0) {
00145 foreach ($newUserRoles as $newUserRole) {
00146 if ($newUserRole != '') {
00147 $role = new Role();
00148 $role->setRoleId(RoleDAO::getRoleIdFromPath($newUserRole));
00149 $newUser->AddRole($role);
00150 }
00151 }
00152 }
00153 array_push($users, $newUser);
00154 }
00155
00156 $parser = new UserXMLParser($schedConf->getConferenceId(), $schedConf->getId());
00157 $parser->setUsersToImport($users);
00158 if (!$parser->importUsers($sendNotify, $continueOnError)) {
00159
00160 $templateMgr->assign('isError', true);
00161 $templateMgr->assign('errors', $parser->getErrors());
00162 }
00163 $templateMgr->assign('importedUsers', $parser->getImportedUsers());
00164 $templateMgr->display($this->getTemplatePath() . 'importUsersResults.tpl');
00165 break;
00166 case 'exportAll':
00167 $this->import('UserExportDom');
00168 $users =& $roleDao->getUsersBySchedConfId($schedConf->getId());
00169 $users =& $users->toArray();
00170 $doc =& UserExportDom::exportUsers($schedConf, $users);
00171 header("Content-Type: application/xml");
00172 header("Cache-Control: private");
00173 header("Content-Disposition: attachment; filename=\"users.xml\"");
00174 echo XMLCustomWriter::getXML($doc);
00175 break;
00176 case 'exportByRole':
00177 $this->import('UserExportDom');
00178 $users = array();
00179 $rolePaths = array();
00180 foreach (Request::getUserVar('roles') as $rolePath) {
00181 $roleId = $roleDao->getRoleIdFromPath($rolePath);
00182 $thisRoleUsers =& $roleDao->getUsersByRoleId($roleId, $schedConf->getConferenceId(), $schedConf->getId());
00183 foreach ($thisRoleUsers->toArray() as $user) {
00184 $users[$user->getId()] = $user;
00185 }
00186 $rolePaths[] = $rolePath;
00187 }
00188 $users = array_values($users);
00189 $doc =& UserExportDom::exportUsers($schedConf, $users, $rolePaths);
00190 header("Content-Type: application/xml");
00191 header("Cache-Control: private");
00192 header("Content-Disposition: attachment; filename=\"users.xml\"");
00193 echo XMLCustomWriter::getXML($doc);
00194 break;
00195 default:
00196 $this->setBreadcrumbs();
00197 $templateMgr->display($this->getTemplatePath() . 'index.tpl');
00198 }
00199 }
00200
00205 function executeCLI($scriptName, &$args) {
00206 $command = array_shift($args);
00207 $xmlFile = array_shift($args);
00208 $schedConfPath = array_shift($args);
00209 $flags =& $args;
00210
00211 $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00212 $userDao =& DAORegistry::getDAO('UserDAO');
00213
00214 $schedConf =& $schedConfDao->getSchedConfByPath($schedConfPath);
00215
00216 if (!$schedConf) {
00217 if ($schedConfPath != '') {
00218 echo __('plugins.importexport.users.import.errorsOccurred') . ":\n";
00219 echo __('plugins.importexport.users.unknownSchedConf', array('schedConfPath' => $schedConfPath)) . "\n\n";
00220 }
00221 $this->usage($scriptName);
00222 return;
00223 }
00224 switch ($command) {
00225 case 'import':
00226 $this->import('UserXMLParser');
00227
00228 $sendNotify = in_array('send_notify', $flags);
00229 $continueOnError = in_array('continue_on_error', $flags);
00230
00231 import('file.FileManager');
00232
00233
00234 $parser = new UserXMLParser($schedConf->getConferenceId(), $schedConf->getId());
00235 $users =& $parser->parseData($xmlFile);
00236
00237 if (!$parser->importUsers($sendNotify, $continueOnError)) {
00238
00239 echo __('plugins.importexport.users.import.errorsOccurred') . ":\n";
00240 foreach ($parser->getErrors() as $error) {
00241 echo "\t$error\n";
00242 }
00243 return false;
00244 }
00245
00246
00247 echo __('plugins.importexport.users.import.usersWereImported') . ":\n";
00248 foreach ($parser->getImportedUsers() as $user) {
00249 echo "\t" . $user->getUserName() . "\n";
00250 }
00251
00252 return true;
00253 break;
00254 case 'export':
00255 $this->import('UserExportDom');
00256 $roleDao =& DAORegistry::getDAO('RoleDAO');
00257 $rolePaths = null;
00258 if (empty($args)) {
00259 $users =& $roleDao->getUsersBySchedConfId($schedConf->getId());
00260 $users =& $users->toArray();
00261 } else {
00262 $users = array();
00263 $rolePaths = array();
00264 foreach ($args as $rolePath) {
00265 $roleId = $roleDao->getRoleIdFromPath($rolePath);
00266 $thisRoleUsers =& $roleDao->getUsersByRoleId($roleId, $schedConf->getId());
00267 foreach ($thisRoleUsers->toArray() as $user) {
00268 $users[$user->getId()] = $user;
00269 }
00270 $rolePaths[] = $rolePath;
00271 }
00272 $users = array_values($users);
00273 }
00274 $doc =& UserExportDom::exportUsers($schedConf, $users, $rolePaths);
00275 if (($h = fopen($xmlFile, 'wb'))===false) {
00276 echo __('plugins.importexport.users.export.errorsOccurred') . ":\n";
00277 echo __('plugins.importexport.users.export.couldNotWriteFile', array('fileName' => $xmlFile)) . "\n";
00278 return false;
00279 }
00280 fwrite($h, XMLCustomWriter::getXML($doc));
00281 fclose($h);
00282 return true;
00283 }
00284 $this->usage($scriptName);
00285 }
00286
00290 function usage($scriptName) {
00291 echo __('plugins.importexport.users.cliUsage', array(
00292 'scriptName' => $scriptName,
00293 'pluginName' => $this->getName()
00294 )) . "\n";
00295 }
00296 }
00297
00298 ?>