/**
  * Register a new user.
  * @return userId int
  * Last modified: EL on February 22th 2013
  */
 function execute()
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $user = new User();
     $user->setSalutation($this->getData('salutation'));
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setGender($this->getData('gender'));
     $user->setInitials($this->getData('initials'));
     $user->setAffiliation($this->getData('affiliation'), null);
     // Localized
     $user->setEmail($this->getData('email'));
     $user->setUrl($this->getData('userUrl'));
     $user->setPhone($this->getData('phone'));
     $user->setFax($this->getData('fax'));
     $user->setMailingAddress($this->getData('mailingAddress'));
     $user->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setGossip($this->getData('gossip'), null);
     // Localized
     $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
     $authDao =& DAORegistry::getDAO('AuthSourceDAO');
     $auth =& $authDao->getDefaultPlugin();
     $user->setAuthId($auth ? $auth->getAuthId() : 0);
     $site =& Request::getSite();
     $availableLocales = $site->getSupportedLocales();
     $locales = array();
     foreach ($this->getData('userLocales') as $locale) {
         if (Locale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
             array_push($locales, $locale);
         }
     }
     $user->setLocales($locales);
     $user->setUsername($this->getData('username'));
     $password = Validation::generatePassword();
     $sendNotify = $this->getData('sendNotify');
     if (isset($auth)) {
         $user->setPassword($password);
         // FIXME Check result and handle failures
         $auth->doCreateUser($user);
         $user->setAuthId($auth->authId);
         $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
         // Used for PW reset hash only
     } else {
         $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
     }
     $user->setDateRegistered(Core::getCurrentDate());
     $userId = $userDao->insertUser($user);
     // Add reviewing interests to interests table
     $interestDao =& DAORegistry::getDAO('InterestDAO');
     $interests = is_array(Request::getUserVar('interestsKeywords')) ? Request::getUserVar('interestsKeywords') : array();
     if (is_array($interests)) {
         $interests = array_map('urldecode', $interests);
         // The interests are coming in encoded -- Decode them for DB storage
         $interestTextOnly = Request::getUserVar('interests');
         if (!empty($interestsTextOnly)) {
             // If JS is disabled, this will be the input to read
             $interestsTextOnly = explode(",", $interestTextOnly);
         } else {
             $interestsTextOnly = null;
         }
         if ($interestsTextOnly && !isset($interests)) {
             $interests = $interestsTextOnly;
         } elseif (isset($interests) && !is_array($interests)) {
             $interests = array($interests);
         }
         $interestDao->insertInterests($interests, $user->getId(), true);
     }
     $interestDao->insertInterests($interests, $user->getId(), true);
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $journal =& Request::getJournal();
     $ercStatus = $this->getData('ercStatus');
     if ($ercStatus == "Secretary") {
         $role = new Role();
         $role->setJournalId($journal->getId());
         $role->setUserId($userId);
         $role->setRoleId(ROLE_ID_SECTION_EDITOR);
         $roleDao->insertRole($role);
         $sectionEditorsDao =& DAORegistry::getDAO('SectionEditorsDAO');
         $sectionEditorsDao->insertEditor($journal->getId(), $this->sectionId, $userId, 1, 1);
     } elseif ($ercStatus == "Chair" || $ercStatus == "Vice-Chair" || $ercStatus == "Member") {
         $role = new Role();
         $role->setJournalId($journal->getId());
         $role->setUserId($userId);
         $role->setRoleId(ROLE_ID_REVIEWER);
         $roleDao->insertRole($role);
         $ercReviewersDao =& DAORegistry::getDAO('ErcReviewersDAO');
         if ($ercStatus == "Chair") {
             $ercReviewersDao->insertReviewer($journal->getId(), $this->sectionId, $userId, 1);
         } elseif ($ercStatus == "Vice-Chair") {
             $ercReviewersDao->insertReviewer($journal->getId(), $this->sectionId, $userId, 2);
         }
         if ($ercStatus == "Member") {
             $ercReviewersDao->insertReviewer($journal->getId(), $this->sectionId, $userId, 3);
         }
     }
     if ($sendNotify) {
         $sectionDao =& DAORegistry::getDAO('SectionDAO');
         $erc =& $sectionDao->getSection($this->sectionId);
         $thisUser =& Request::getUser();
         // Send welcome email to user
         import('classes.mail.MailTemplate');
         $mail = new MailTemplate('COMMITTEE_REGISTER');
         $mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
         $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName(), 'ercStatus' => $ercStatus, 'ercTitle' => $erc->getLocalizedTitle(), 'editProfile' => Request::url(null, 'user', 'profile'), 'secretaryFullName' => $thisUser->getFullName(), 'secretaryFunctions' => $thisUser->getErcFunction($this->sectionId)));
         $mail->addRecipient($user->getEmail(), $user->getFullName());
         $mail->send();
     }
     return $userId;
 }
Example #2
0
 /**
  * Internal function to return a User object from a row.
  * @param $row array
  * @param $callHook boolean
  * @return User
  */
 function &_returnUserFromRow(&$row, $callHook = true)
 {
     $user = new User();
     $user->setId($row['user_id']);
     $user->setUsername($row['username']);
     $user->setPassword($row['password']);
     $user->setSalutation($row['salutation']);
     $user->setFirstName($row['first_name']);
     $user->setMiddleName($row['middle_name']);
     $user->setInitials($row['initials']);
     $user->setLastName($row['last_name']);
     $user->setGender($row['gender']);
     $user->setEmail($row['email']);
     $user->setUrl($row['url']);
     $user->setPhone($row['phone']);
     $user->setFax($row['fax']);
     $user->setMailingAddress($row['mailing_address']);
     $user->setCountry($row['country']);
     $user->setLocales(isset($row['locales']) && !empty($row['locales']) ? explode(':', $row['locales']) : array());
     $user->setDateLastEmail($this->datetimeFromDB($row['date_last_email']));
     $user->setDateRegistered($this->datetimeFromDB($row['date_registered']));
     $user->setDateValidated($this->datetimeFromDB($row['date_validated']));
     $user->setDateLastLogin($this->datetimeFromDB($row['date_last_login']));
     $user->setMustChangePassword($row['must_change_password']);
     $user->setDisabled($row['disabled']);
     $user->setDisabledReason($row['disabled_reason']);
     $user->setAuthId($row['auth_id']);
     $user->setAuthStr($row['auth_str']);
     if ($callHook) {
         HookRegistry::call('UserDAO::_returnUserFromRow', array(&$user, &$row));
     }
     return $user;
 }
Example #3
0
 /**
  * Register a new user.
  * @return $userId int
  */
 function execute()
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $user = new User();
     $user->setSalutation($this->getData('salutation'));
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setGender($this->getData('gender'));
     $user->setInitials($this->getData('initials'));
     $user->setAffiliation($this->getData('affiliation'));
     $user->setEmail($this->getData('email'));
     $user->setUrl($this->getData('userUrl'));
     $user->setPhone($this->getData('phone'));
     $user->setFax($this->getData('fax'));
     $user->setMailingAddress($this->getData('mailingAddress'));
     $user->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setInterests($this->getData('interests'), null);
     // Localized
     $user->setGossip($this->getData('gossip'), null);
     // Localized
     $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
     $authDao =& DAORegistry::getDAO('AuthSourceDAO');
     $auth =& $authDao->getDefaultPlugin();
     $user->setAuthId($auth ? $auth->getAuthId() : 0);
     $site =& Request::getSite();
     $availableLocales = $site->getSupportedLocales();
     $locales = array();
     foreach ($this->getData('userLocales') as $locale) {
         if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
             array_push($locales, $locale);
         }
     }
     $user->setLocales($locales);
     $user->setUsername($this->getData('username'));
     $password = Validation::generatePassword();
     $sendNotify = $this->getData('sendNotify');
     if (isset($auth)) {
         $user->setPassword($password);
         // FIXME Check result and handle failures
         $auth->doCreateUser($user);
         $user->setAuthId($auth->authId);
         $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
         // Used for PW reset hash only
     } else {
         $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
     }
     $user->setDateRegistered(Core::getCurrentDate());
     $userId = $userDao->insertUser($user);
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $schedConf =& Request::getSchedConf();
     $role = new Role();
     $role->setConferenceId($schedConf->getConferenceId());
     $role->setSchedConfId($schedConf->getId());
     $role->setUserId($userId);
     $role->setRoleId(ROLE_ID_REVIEWER);
     $roleDao->insertRole($role);
     if ($sendNotify) {
         // Send welcome email to user
         import('mail.MailTemplate');
         $mail = new MailTemplate('USER_REGISTER');
         $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName'));
         $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password));
         $mail->addRecipient($user->getEmail(), $user->getFullName());
         $mail->send();
     }
     return $userId;
 }
 /**
  * Register a new user.
  */
 function execute()
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $journal =& Request::getJournal();
     if (isset($this->userId)) {
         $user =& $userDao->getById($this->userId);
     }
     if (!isset($user)) {
         $user = new User();
     }
     $user->setSalutation($this->getData('salutation'));
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setInitials($this->getData('initials'));
     $user->setGender($this->getData('gender'));
     $user->setAffiliation($this->getData('affiliation'), null);
     // Localized
     $user->setSignature($this->getData('signature'), null);
     // Localized
     $user->setEmail($this->getData('email'));
     $user->setData('orcid', $this->getData('orcid'));
     $user->setUrl($this->getData('userUrl'));
     $user->setPhone($this->getData('phone'));
     $user->setFax($this->getData('fax'));
     $user->setMailingAddress($this->getData('mailingAddress'));
     $user->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setGossip($this->getData('gossip'), null);
     // Localized
     $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
     $user->setAuthId((int) $this->getData('authId'));
     $site =& Request::getSite();
     $availableLocales = $site->getSupportedLocales();
     $locales = array();
     foreach ($this->getData('userLocales') as $locale) {
         if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
             array_push($locales, $locale);
         }
     }
     $user->setLocales($locales);
     if ($user->getAuthId()) {
         $authDao =& DAORegistry::getDAO('AuthSourceDAO');
         $auth =& $authDao->getPlugin($user->getAuthId());
     }
     if ($user->getId() != null) {
         $userId = $user->getId();
         if ($this->getData('password') !== '') {
             if (isset($auth)) {
                 $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
                 $user->setPassword(Validation::encryptCredentials($userId, Validation::generatePassword()));
                 // Used for PW reset hash only
             } else {
                 $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
             }
         }
         if (isset($auth)) {
             // FIXME Should try to create user here too?
             $auth->doSetUserInfo($user);
         }
         $userDao->updateObject($user);
     } else {
         $user->setUsername($this->getData('username'));
         if ($this->getData('generatePassword')) {
             $password = Validation::generatePassword();
             $sendNotify = true;
         } else {
             $password = $this->getData('password');
             $sendNotify = $this->getData('sendNotify');
         }
         if (isset($auth)) {
             $user->setPassword($password);
             // FIXME Check result and handle failures
             $auth->doCreateUser($user);
             $user->setAuthId($auth->authId);
             $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
             // Used for PW reset hash only
         } else {
             $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
         }
         $user->setDateRegistered(Core::getCurrentDate());
         $userId = $userDao->insertUser($user);
         $isManager = Validation::isJournalManager();
         if (!empty($this->_data['enrollAs'])) {
             foreach ($this->getData('enrollAs') as $roleName) {
                 // Enroll new user into an initial role
                 $roleDao =& DAORegistry::getDAO('RoleDAO');
                 $roleId = $roleDao->getRoleIdFromPath($roleName);
                 if (!$isManager && $roleId != ROLE_ID_READER) {
                     continue;
                 }
                 if ($roleId != null) {
                     $role = new Role();
                     $role->setJournalId($journal->getId());
                     $role->setUserId($userId);
                     $role->setRoleId($roleId);
                     $roleDao->insertRole($role);
                 }
             }
         }
         if ($sendNotify) {
             // Send welcome email to user
             import('classes.mail.MailTemplate');
             $mail = new MailTemplate('USER_REGISTER');
             $mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
             $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName()));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
         }
     }
     // Insert the user interests
     $interests = $this->getData('interestsKeywords') ? $this->getData('interestsKeywords') : $this->getData('interestsTextOnly');
     import('lib.pkp.classes.user.InterestManager');
     $interestManager = new InterestManager();
     $interestManager->setInterestsForUser($user, $interests);
 }
Example #5
0
 /**
  * Import papers (including metadata and files).
  */
 function importPapers()
 {
     if ($this->hasOption('verbose')) {
         printf("Importing papers\n");
     }
     import('classes.file.PaperFileManager');
     import('classes.search.PaperSearchIndex');
     $userDao =& DAORegistry::getDAO('UserDAO');
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $trackDao =& DAORegistry::getDAO('TrackDAO');
     $paperDao =& DAORegistry::getDAO('PaperDAO');
     $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
     $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
     $unassignedTrackId = null;
     $result =& $this->importDao->retrieve('SELECT * FROM papers ORDER by id');
     while (!$result->EOF) {
         $row =& $result->fields;
         $schedConf =& $this->schedConfMap[$row['cf']];
         $schedConfId = $schedConf->getId();
         // Bring in the primary user for this paper.
         $user = $userDao->getUserByUsername(Core::cleanVar($row['login']));
         if (!$user) {
             unset($user);
             $user = new User();
             $user->setUsername(Core::cleanVar($row['login']));
             $user->setFirstName(Core::cleanVar($row['first_name']));
             $user->setLastName(Core::cleanVar($row['surname']));
             $user->setAffiliation(Core::cleanVar($row['affiliation']), Locale::getLocale());
             $user->setEmail(Core::cleanVar($row['email']));
             $user->setUrl(Core::cleanVar($row['url']));
             $user->setBiography(Core::cleanVar($row['bio']), Locale::getLocale());
             $user->setLocales(array());
             $user->setDateRegistered($row['created']);
             $user->setDateLastLogin($row['created']);
             $user->setMustChangePassword(1);
             $password = Validation::generatePassword();
             $user->setPassword(Validation::encryptCredentials($user->getUsername(), $password));
             if ($this->hasOption('emailUsers')) {
                 import('classes.mail.MailTemplate');
                 $mail = new MailTemplate('USER_REGISTER');
                 $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName'));
                 $mail->assignParams(array('username' => $user->getUsername(), 'password' => $password, 'conferenceName' => $schedConf->getFullTitle()));
                 $mail->addRecipient($user->getEmail(), $user->getFullName());
                 $mail->send();
             }
             $user->setDisabled(0);
             $otherUser =& $userDao->getUserByEmail(Core::cleanVar($row['email']));
             if ($otherUser !== null) {
                 // User exists with this email -- munge it to make unique
                 $user->setEmail('ocs-' . Core::cleanVar($row['login']) . '+' . Core::cleanVar($row['email']));
                 $this->conflicts[] = array(&$otherUser, &$user);
             }
             unset($otherUser);
             $userDao->insertUser($user);
             // Make this user a author
             $role = new Role();
             $role->setSchedConfId($schedConf->getId());
             $role->setConferenceId($schedConf->getConferenceId());
             $role->setUserId($user->getId());
             $role->setRoleId(ROLE_ID_AUTHOR);
             $roleDao->insertRole($role);
             unset($role);
         }
         $userId = $user->getId();
         // Bring in the basic entry for the paper
         $paper = new Paper();
         $paper->setUserId($userId);
         $paper->setLocale(Locale::getPrimaryLocale());
         $paper->setSchedConfId($schedConfId);
         $oldTrackId = $row['primary_track_id'];
         if (!$oldTrackId || !isset($this->trackMap[$oldTrackId])) {
             $oldTrackId = $row['secondary_track_id'];
         }
         if (!$oldTrackId || !isset($this->trackMap[$oldTrackId])) {
             if (!$unassignedTrackId) {
                 // Create an "Unassigned" track to use for submissions
                 // that didn't have a track in OCS 1.x.
                 $track = new Track();
                 $track->setSchedConfId($schedConf->getId());
                 $track->setTitle('UNASSIGNED', Locale::getLocale());
                 $track->setSequence(REALLY_BIG_NUMBER);
                 $track->setDirectorRestricted(1);
                 $track->setMetaReviewed(1);
                 $unassignedTrackId = $trackDao->insertTrack($track);
             }
             $newTrackId = $unassignedTrackId;
         } else {
             $newTrackId = $this->trackMap[$oldTrackId];
         }
         $paper->setTrackId($newTrackId);
         $paper->setTitle(Core::cleanVar($row['title']), Locale::getLocale());
         $paper->setAbstract(Core::cleanVar($row['abstract']), Locale::getLocale());
         $paper->setDiscipline(Core::cleanVar($row['discipline']), Locale::getLocale());
         $paper->setSponsor(Core::cleanVar($row['sponsor']), Locale::getLocale());
         $paper->setSubject(Core::cleanVar($row['topic']), Locale::getLocale());
         $paper->setLanguage(Core::cleanVar($row['language']));
         $paper->setDateSubmitted($row['created']);
         $paper->setDateStatusModified($row['timestamp']);
         // $paper->setTypeConst($row['present_format'] == 'multiple' ? SUBMISSION_TYPE_PANEL : SUBMISSION_TYPE_SINGLE); FIXME
         $paper->setCurrentRound(REVIEW_ROUND_ABSTRACT);
         $paper->setSubmissionProgress(0);
         $paper->setPages('');
         // Bring in authors
         $firstNames = split("\n", Core::cleanVar($row['first_name'] . "\n" . $row['add_first_names']));
         $lastNames = split("\n", Core::cleanVar($row['surname'] . "\n" . $row['add_surnames']));
         $emails = split("\n", Core::cleanVar($row['email'] . "\n" . $row['add_emails']));
         $affiliations = split("\n", Core::cleanVar($row['affiliation'] . "\n" . $row['add_affiliations']));
         $urls = split("\n", Core::cleanVar($row['url'] . "\n" . $row['add_urls']));
         foreach ($emails as $key => $email) {
             if (empty($email)) {
                 continue;
             }
             $author = new Author();
             $author->setEmail($email);
             $author->setFirstName($firstNames[$key]);
             $author->setLastName($lastNames[$key]);
             $author->setAffiliation($affiliations[$key], Locale::getLocale());
             @$author->setUrl($urls[$key]);
             // Suppress warnings from inconsistent OCS 1.x data
             $author->setPrimaryContact($key == 0 ? 1 : 0);
             $paper->addAuthor($author);
             unset($author);
         }
         switch ($row['accepted']) {
             case 'true':
                 $paper->setStatus(STATUS_PUBLISHED);
                 $paperId = $paperDao->insertPaper($paper);
                 $publishedPaper = new PublishedPaper();
                 $publishedPaper->setPaperId($paperId);
                 $publishedPaper->setSchedConfId($schedConfId);
                 $publishedPaper->setDatePublished(Core::getCurrentDate());
                 $publishedPaper->setSeq(REALLY_BIG_NUMBER);
                 $publishedPaper->setViews(0);
                 $publishedPaperDao->insertPublishedPaper($publishedPaper);
                 $publishedPaperDao->resequencePublishedPapers($paper->getTrackId(), $schedConfId);
                 break;
             case 'reject':
                 $paper->setStatus(STATUS_DECLINED);
                 $paperId = $paperDao->insertPaper($paper);
                 break;
             default:
                 $paper->setStatus(STATUS_QUEUED);
                 $paperId = $paperDao->insertPaper($paper);
         }
         $this->paperMap[$row['id']] =& $paper;
         $paperFileManager = new PaperFileManager($paperId);
         if (!empty($row['paper']) && $row['paper'] != 'PDF') {
             $format = 'text/html';
             $extension = $paperFileManager->getDocumentExtension($format);
             $fileId = $paperFileManager->writeSubmissionFile('migratedFile' . $extension, $row['paper'], $format);
             $paper->setSubmissionFileId($fileId);
             $paperDao->updatePaper($paper);
             $fileId = $paperFileManager->writePublicFile('migratedGalley' . $extension, $row['paper'], $format);
             PaperSearchIndex::updateFileIndex($paperId, PAPER_SEARCH_GALLEY_FILE, $fileId);
             if (strstr($format, 'html')) {
                 $galley = new PaperHTMLGalley();
                 $galley->setLabel('HTML');
             } else {
                 $galley = new PaperGalley();
                 switch ($format) {
                     case 'application/pdf':
                         $galley->setLabel('PDF');
                         break;
                     case 'application/postscript':
                         $galley->setLabel('PostScript');
                         break;
                     case 'application/msword':
                         $galley->setLabel('Word');
                         break;
                     case 'text/xml':
                         $galley->setLabel('XML');
                         break;
                     case 'application/powerpoint':
                         $galley->setLabel('Slideshow');
                         break;
                     default:
                         $galley->setLabel('Untitled');
                         break;
                 }
             }
             $galley->setLocale(Locale::getLocale());
             $galley->setPaperId($paperId);
             $galley->setFileId($fileId);
             $galleyDao->insertGalley($galley);
             unset($galley);
         } elseif ($row['paper'] == 'PDF') {
             $fileId = $paperFileManager->copySubmissionFile($this->importPath . '/papers/' . $row['pdf'], 'application/pdf');
             $paper->setSubmissionFileId($fileId);
             $paperDao->updatePaper($paper);
             $fileId = $paperFileManager->copyPublicFile($this->importPath . '/papers/' . $row['pdf'], 'application/pdf');
             PaperSearchIndex::updateFileIndex($paperId, PAPER_SEARCH_GALLEY_FILE, $fileId);
             $galley = new PaperGalley();
             $galley->setLabel('PDF');
             $galley->setLocale(Locale::getLocale());
             $galley->setPaperId($paperId);
             $galley->setFileId($fileId);
             $galleyDao->insertGalley($galley);
             unset($galley);
         }
         // FIXME: The following fields from OCS 1.x are UNUSED:
         // program_insert approach coverage format relation appendix_names appendix_dates
         // appendix appendix_pdf secondary_track_id multiple_* restrict_access paper_email
         // delete_paper comment_email
         unset($user);
         unset($paper);
         unset($schedConf);
         unset($paperFileManager);
         $result->MoveNext();
     }
     $result->Close();
 }
 /**
  * Register a new user.
  */
 function execute()
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $journal =& Request::getJournal();
     if (isset($this->userId)) {
         $user =& $userDao->getUser($this->userId);
     }
     if (!isset($user)) {
         $user = new User();
     }
     $user->setSalutation($this->getData('salutation'));
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setInitials($this->getData('initials'));
     $user->setGender($this->getData('gender'));
     $user->setAffiliation($this->getData('affiliation'), null);
     // Localized
     $user->setSignature($this->getData('signature'), null);
     // Localized
     $user->setEmail($this->getData('email'));
     $user->setUrl($this->getData('userUrl'));
     $user->setPhone($this->getData('phone'));
     $user->setFax($this->getData('fax'));
     $user->setMailingAddress($this->getData('mailingAddress'));
     $user->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setGossip($this->getData('gossip'), null);
     // Localized
     $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
     $user->setAuthId((int) $this->getData('authId'));
     $site =& Request::getSite();
     $availableLocales = $site->getSupportedLocales();
     $locales = array();
     foreach ($this->getData('userLocales') as $locale) {
         if (Locale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
             array_push($locales, $locale);
         }
     }
     $user->setLocales($locales);
     if ($user->getAuthId()) {
         $authDao =& DAORegistry::getDAO('AuthSourceDAO');
         $auth =& $authDao->getPlugin($user->getAuthId());
     }
     if ($user->getId() != null) {
         $userId = $user->getId();
         if ($this->getData('password') !== '') {
             if (isset($auth)) {
                 $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
                 $user->setPassword(Validation::encryptCredentials($userId, Validation::generatePassword()));
                 // Used for PW reset hash only
             } else {
                 $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
             }
         }
         if (isset($auth)) {
             // FIXME Should try to create user here too?
             $auth->doSetUserInfo($user);
         }
         $userDao->updateObject($user);
     } else {
         $user->setUsername($this->getData('username'));
         if ($this->getData('generatePassword')) {
             $password = Validation::generatePassword();
             $sendNotify = true;
         } else {
             $password = $this->getData('password');
             $sendNotify = $this->getData('sendNotify');
         }
         if (isset($auth)) {
             $user->setPassword($password);
             // FIXME Check result and handle failures
             $auth->doCreateUser($user);
             $user->setAuthId($auth->authId);
             $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
             // Used for PW reset hash only
         } else {
             $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
         }
         $user->setDateRegistered(Core::getCurrentDate());
         $userId = $userDao->insertUser($user);
         $isManager = Validation::isJournalManager();
         // EL on March 13th 2013
         // If this is used, it should be totally modified
         if (!empty($this->_data['enrollAs'])) {
             foreach ($this->getData('enrollAs') as $roleName) {
                 // Enroll new user into an initial role
                 $roleDao =& DAORegistry::getDAO('RoleDAO');
                 $roleId = $roleDao->getRoleIdFromPath($roleName);
                 if (!$isManager && $roleId != ROLE_ID_READER) {
                     continue;
                 }
                 if ($roleId != null) {
                     $role = new Role();
                     $role->setJournalId($journal->getId());
                     $role->setUserId($userId);
                     $role->setRoleId($roleId);
                     $roleDao->insertRole($role);
                 }
             }
         }
         if ($sendNotify) {
             // Send welcome email to user
             import('classes.mail.MailTemplate');
             $mail = new MailTemplate('USER_REGISTER');
             $mail->setFrom($journal->getSetting('supportEmail'), $journal->getSetting('supportName'));
             $mail->assignParams(array('username' => $this->getData('username'), 'password' => String::substr($this->getData('password'), 0, 30), 'supportName' => $journal->getSetting('supportName'), 'userFullName' => $user->getFullName()));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
         }
     }
     // Add reviewing interests to interests table
     $interestDao =& DAORegistry::getDAO('InterestDAO');
     $interests = is_array(Request::getUserVar('interestsKeywords')) ? Request::getUserVar('interestsKeywords') : array();
     if (is_array($interests)) {
         $interests = array_map('urldecode', $interests);
         // The interests are coming in encoded -- Decode them for DB storage
         $interestTextOnly = Request::getUserVar('interests');
         if (!empty($interestsTextOnly)) {
             // If JS is disabled, this will be the input to read
             $interestsTextOnly = explode(",", $interestTextOnly);
         } else {
             $interestsTextOnly = null;
         }
         if ($interestsTextOnly && !isset($interests)) {
             $interests = $interestsTextOnly;
         } elseif (isset($interests) && !is_array($interests)) {
             $interests = array($interests);
         }
         $interestDao->insertInterests($interests, $userId, true);
     }
 }
 function importUsers()
 {
     assert($this->xml->name == 'users');
     import('lib.pkp.classes.user.InterestManager');
     $interestManager = new InterestManager();
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $userDAO =& DAORegistry::getDAO('UserDAO');
     $publicFileManager =& new PublicFileManager();
     $site =& Request::getSite();
     $siteSupportedLocales = $site->getSupportedLocales();
     $this->nextElement();
     while ($this->xml->name == 'user') {
         $userXML = $this->getCurrentElementAsDom();
         $username = (string) $userXML->username;
         $email = (string) $userXML->email;
         $userByEmail = $userDAO->getUserByEmail($email);
         $user = null;
         if (!empty($userByEmail)) {
             $user = $userByEmail;
         } else {
             $user = new User();
             $user->setUsername((string) $userXML->username);
             $user->setPassword((string) $userXML->password);
             $user->setSalutation((string) $userXML->salutation);
             $user->setFirstName((string) $userXML->firstName);
             $user->setMiddleName((string) $userXML->middleName);
             $user->setInitials((string) $userXML->initials);
             $user->setLastName((string) $userXML->lastName);
             $user->setSuffix((string) $userXML->suffix);
             $user->setGender((string) $userXML->gender);
             $user->setEmail((string) $userXML->email);
             $user->setUrl((string) $userXML->url);
             $user->setPhone((string) $userXML->phone);
             $user->setFax((string) $userXML->fax);
             $user->setMailingAddress((string) $userXML->mailingAddress);
             $user->setBillingAddress((string) $userXML->billingAddress);
             $user->setCountry((string) $userXML->country);
             $locales = array();
             foreach (explode(':', (string) $userXML->locales) as $locale) {
                 if (AppLocale::isLocaleValid($locale) && in_array($locale, $siteSupportedLocales)) {
                     array_push($locales, $locale);
                 }
             }
             $user->setLocales($locales);
             $user->setDateLastEmail((string) $userXML->dateLastEmail);
             $user->setDateRegistered((string) $userXML->dateRegistered);
             $user->setDateValidated((string) $userXML->dateValidated);
             $user->setDateLastLogin((string) $userXML->dateLastLogin);
             $user->setMustChangePassword((int) $userXML->mustChangePassword);
             $user->setDisabled((int) $userXML->disabled);
             $user->setDisabledReason((string) $userXML->disabledReason);
             $user->setAuthId((int) $userXML->authId);
             $user->setAuthStr((string) $userXML->authStr);
             $user->setInlineHelp((int) $userXML->inlineHelp);
             $this->generateUsername($user);
             $userDAO->insertUser($user);
             $this->restoreDataObjectSettings($userDAO, $userXML->settings, 'user_settings', 'user_id', $user->getId());
             $user = $userDAO->getById($user->getId());
             $profileImage =& $user->getSetting('profileImage');
             if ($profileImage) {
                 $oldProfileImage = $profileImage['uploadName'];
                 $extension = $publicFileManager->getExtension($oldProfileImage);
                 $newProfileImage = 'profileImage-' . $user->getId() . "." . $extension;
                 $sourceFile = $this->siteFolderPath . '/' . $oldProfileImage;
                 $publicFileManager->copyFile($sourceFile, $publicFileManager->getSiteFilesPath() . "/" . $newProfileImage);
                 unlink($sourceFile);
                 $profileImage['uploadName'] = $newProfileImage;
                 $user->updateSetting('profileImage', $profileImage);
             }
             $interests = array();
             foreach ($userXML->interest as $interest) {
                 $interests[] = (string) $interest;
             }
             $interestManager->setInterestsForUser($user, $interests);
         }
         $this->idTranslationTable->register(INTERNAL_TRANSFER_OBJECT_USER, (int) $userXML->oldId, $user->getId());
         foreach ($userXML->role as $roleXML) {
             $role = new Role();
             $role->setRoleId((int) $roleXML);
             $role->setUserId($user->getId());
             $role->setJournalId($this->journal->getId());
             $roleDao->insertRole($role);
         }
         $this->nextElement();
     }
 }
Example #8
0
 /**
  * Create or update a user.
  * @param $args array
  * @param $request PKPRequest
  */
 function &execute($args, &$request)
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $press =& $request->getPress();
     if (isset($this->userId)) {
         $userId = $this->userId;
         $user =& $userDao->getUser($userId);
     }
     if (!isset($user)) {
         $user = new User();
     }
     $user->setSalutation($this->getData('salutation'));
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setInitials($this->getData('initials'));
     $user->setGender($this->getData('gender'));
     $user->setAffiliation($this->getData('affiliation'), null);
     // Localized
     $user->setSignature($this->getData('signature'), null);
     // Localized
     $user->setEmail($this->getData('email'));
     $user->setUrl($this->getData('userUrl'));
     $user->setPhone($this->getData('phone'));
     $user->setFax($this->getData('fax'));
     $user->setMailingAddress($this->getData('mailingAddress'));
     $user->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setGossip($this->getData('gossip'), null);
     // Localized
     $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
     $user->setAuthId((int) $this->getData('authId'));
     $site =& $request->getSite();
     $availableLocales = $site->getSupportedLocales();
     $locales = array();
     foreach ($this->getData('userLocales') as $locale) {
         if (Locale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
             array_push($locales, $locale);
         }
     }
     $user->setLocales($locales);
     if ($user->getAuthId()) {
         $authDao =& DAORegistry::getDAO('AuthSourceDAO');
         $auth =& $authDao->getPlugin($user->getAuthId());
     }
     if ($user->getId() != null) {
         if ($this->getData('password') !== '') {
             if (isset($auth)) {
                 $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
                 $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
                 // Used for PW reset hash only
             } else {
                 $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
             }
         }
         if (isset($auth)) {
             // FIXME Should try to create user here too?
             $auth->doSetUserInfo($user);
         }
         $userDao->updateObject($user);
     } else {
         $user->setUsername($this->getData('username'));
         if ($this->getData('generatePassword')) {
             $password = Validation::generatePassword();
             $sendNotify = true;
         } else {
             $password = $this->getData('password');
             $sendNotify = $this->getData('sendNotify');
         }
         if (isset($auth)) {
             $user->setPassword($password);
             // FIXME Check result and handle failures
             $auth->doCreateUser($user);
             $user->setAuthId($auth->authId);
             $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
             // Used for PW reset hash only
         } else {
             $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
         }
         $user->setDateRegistered(Core::getCurrentDate());
         $userId = $userDao->insertUser($user);
         if ($sendNotify) {
             // Send welcome email to user
             import('classes.mail.MailTemplate');
             $mail = new MailTemplate('USER_REGISTER');
             $mail->setFrom($press->getSetting('contactEmail'), $press->getSetting('contactName'));
             $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName()));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
         }
     }
     // Add reviewing interests to interests table
     import('lib.pkp.classes.user.InterestManager');
     $interestManager = new InterestManager();
     $interestManager->insertInterests($userId, $this->getData('interestsKeywords'), $this->getData('interests'));
     return $user;
 }