00001 <?php
00002
00015
00016
00017
00018 import('form.Form');
00019
00020 class ProfileForm extends Form {
00021
00023 var $user;
00024
00028 function ProfileForm() {
00029 parent::Form('user/profile.tpl');
00030
00031 $user =& Request::getUser();
00032 $this->user =& $user;
00033
00034 $site = &Request::getSite();
00035
00036
00037 $this->addCheck(new FormValidator($this, 'firstName', 'required', 'user.profile.form.firstNameRequired'));
00038 $this->addCheck(new FormValidator($this, 'lastName', 'required', 'user.profile.form.lastNameRequired'));
00039 $this->addCheck(new FormValidatorUrl($this, 'userUrl', 'optional', 'user.profile.form.urlInvalid'));
00040 $this->addCheck(new FormValidatorEmail($this, 'email', 'required', 'user.profile.form.emailRequired'));
00041 $this->addCheck(new FormValidatorCustom($this, 'email', 'required', 'user.register.form.emailExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByEmail'), array($user->getUserId(), true), true));
00042 $this->addCheck(new FormValidatorPost($this));
00043 }
00044
00048 function deleteProfileImage() {
00049 $user =& Request::getUser();
00050 $profileImage = $user->getSetting('profileImage');
00051 if (!$profileImage) return false;
00052
00053 import('file.PublicFileManager');
00054 $fileManager = &new PublicFileManager();
00055 if ($fileManager->removeSiteFile($profileImage['uploadName'])) {
00056 return $user->updateSetting('profileImage', null);
00057 } else {
00058 return false;
00059 }
00060 }
00061
00062 function uploadProfileImage() {
00063 import('file.PublicFileManager');
00064 $fileManager = &new PublicFileManager();
00065
00066 $user =& $this->user;
00067
00068 $type = $fileManager->getUploadedFileType('profileImage');
00069 $extension = $fileManager->getImageExtension($type);
00070 if (!$extension) return false;
00071
00072 $uploadName = 'profileImage-' . (int) $user->getUserId() . $extension;
00073 if (!$fileManager->uploadSiteFile('profileImage', $uploadName)) return false;
00074
00075 $filePath = $fileManager->getSiteFilesPath();
00076 list($width, $height) = getimagesize($filePath . '/' . $uploadName);
00077
00078 if ($width > 150 || $height > 150 || $width <= 0 || $height <= 0) {
00079 $userSetting = null;
00080 $user->updateSetting('profileImage', $userSetting);
00081 $fileManager->removeSiteFile($filePath);
00082 return false;
00083 }
00084
00085 $userSetting = array(
00086 'name' => $fileManager->getUploadedFileName('profileImage'),
00087 'uploadName' => $uploadName,
00088 'width' => $width,
00089 'height' => $height,
00090 'dateUploaded' => Core::getCurrentDate()
00091 );
00092
00093 $user->updateSetting('profileImage', $userSetting);
00094 return true;
00095 }
00096
00100 function display() {
00101 $user = &Request::getUser();
00102
00103 $templateMgr = &TemplateManager::getManager();
00104 $templateMgr->assign('username', $user->getUsername());
00105
00106 $site = &Request::getSite();
00107 $templateMgr->assign('availableLocales', $site->getSupportedLocaleNames());
00108
00109 $roleDao = &DAORegistry::getDAO('RoleDAO');
00110 $journalDao = &DAORegistry::getDAO('JournalDAO');
00111 $notificationStatusDao = &DAORegistry::getDAO('NotificationStatusDAO');
00112 $userSettingsDao = &DAORegistry::getDAO('UserSettingsDAO');
00113
00114 $journals = &$journalDao->getJournals();
00115 $journals = &$journals->toArray();
00116
00117 foreach ($journals as $thisJournal) {
00118 if ($thisJournal->getSetting('enableSubscriptions') == true && $thisJournal->getSetting('enableOpenAccessNotification') == true) {
00119 $templateMgr->assign('displayOpenAccessNotification', true);
00120 $templateMgr->assign_by_ref('user', $user);
00121 break;
00122 }
00123 }
00124
00125 $journals = &$journalDao->getJournals();
00126 $journals = &$journals->toArray();
00127 $journalNotifications = &$notificationStatusDao->getJournalNotifications($user->getUserId());
00128
00129 $countryDao =& DAORegistry::getDAO('CountryDAO');
00130 $countries =& $countryDao->getCountries();
00131
00132 $templateMgr->assign_by_ref('journals', $journals);
00133 $templateMgr->assign_by_ref('countries', $countries);
00134 $templateMgr->assign_by_ref('journalNotifications', $journalNotifications);
00135 $templateMgr->assign('helpTopicId', 'user.registerAndProfile');
00136
00137 $journal =& Request::getJournal();
00138 if ($journal) {
00139 $roleDao =& DAORegistry::getDAO('RoleDAO');
00140 $roles =& $roleDao->getRolesByUserId($user->getUserId(), $journal->getJournalId());
00141 $roleNames = array();
00142 foreach ($roles as $role) $roleNames[$role->getRolePath()] = $role->getRoleName();
00143 $templateMgr->assign('allowRegReviewer', $journal->getSetting('allowRegReviewer'));
00144 $templateMgr->assign('allowRegAuthor', $journal->getSetting('allowRegAuthor'));
00145 $templateMgr->assign('allowRegReader', $journal->getSetting('allowRegReader'));
00146 $templateMgr->assign('roles', $roleNames);
00147 }
00148
00149 $templateMgr->assign('profileImage', $user->getSetting('profileImage'));
00150
00151 parent::display();
00152 }
00153
00154 function getLocaleFieldNames() {
00155 $userDao =& DAORegistry::getDAO('UserDAO');
00156 return $userDao->getLocaleFieldNames();
00157 }
00158
00162 function initData() {
00163 $user = &Request::getUser();
00164
00165 $this->_data = array(
00166 'salutation' => $user->getSalutation(),
00167 'firstName' => $user->getFirstName(),
00168 'middleName' => $user->getMiddleName(),
00169 'initials' => $user->getInitials(),
00170 'lastName' => $user->getLastName(),
00171 'gender' => $user->getGender(),
00172 'affiliation' => $user->getAffiliation(),
00173 'signature' => $user->getSignature(null),
00174 'email' => $user->getEmail(),
00175 'userUrl' => $user->getUrl(),
00176 'phone' => $user->getPhone(),
00177 'fax' => $user->getFax(),
00178 'mailingAddress' => $user->getMailingAddress(),
00179 'country' => $user->getCountry(),
00180 'biography' => $user->getBiography(null),
00181 'interests' => $user->getInterests(null),
00182 'userLocales' => $user->getLocales(),
00183 'isAuthor' => Validation::isAuthor(),
00184 'isReader' => Validation::isReader(),
00185 'isReviewer' => Validation::isReviewer()
00186 );
00187 }
00188
00192 function readInputData() {
00193 $this->readUserVars(array(
00194 'salutation',
00195 'firstName',
00196 'middleName',
00197 'lastName',
00198 'gender',
00199 'initials',
00200 'affiliation',
00201 'signature',
00202 'email',
00203 'userUrl',
00204 'phone',
00205 'fax',
00206 'mailingAddress',
00207 'country',
00208 'biography',
00209 'interests',
00210 'userLocales',
00211 'readerRole',
00212 'authorRole',
00213 'reviewerRole'
00214 ));
00215
00216 if ($this->getData('userLocales') == null || !is_array($this->getData('userLocales'))) {
00217 $this->setData('userLocales', array());
00218 }
00219 }
00220
00224 function execute() {
00225 $user = &Request::getUser();
00226
00227 $user->setSalutation($this->getData('salutation'));
00228 $user->setFirstName($this->getData('firstName'));
00229 $user->setMiddleName($this->getData('middleName'));
00230 $user->setLastName($this->getData('lastName'));
00231 $user->setGender($this->getData('gender'));
00232 $user->setInitials($this->getData('initials'));
00233 $user->setAffiliation($this->getData('affiliation'));
00234 $user->setSignature($this->getData('signature'), null);
00235 $user->setEmail($this->getData('email'));
00236 $user->setUrl($this->getData('userUrl'));
00237 $user->setPhone($this->getData('phone'));
00238 $user->setFax($this->getData('fax'));
00239 $user->setMailingAddress($this->getData('mailingAddress'));
00240 $user->setCountry($this->getData('country'));
00241 $user->setBiography($this->getData('biography'), null);
00242 $user->setInterests($this->getData('interests'), null);
00243
00244 $site = &Request::getSite();
00245 $availableLocales = $site->getSupportedLocales();
00246
00247 $locales = array();
00248 foreach ($this->getData('userLocales') as $locale) {
00249 if (Locale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
00250 array_push($locales, $locale);
00251 }
00252 }
00253 $user->setLocales($locales);
00254
00255 $userDao = &DAORegistry::getDAO('UserDAO');
00256 $userDao->updateUser($user);
00257
00258 $roleDao = &DAORegistry::getDAO('RoleDAO');
00259 $journalDao = &DAORegistry::getDAO('JournalDAO');
00260 $notificationStatusDao = &DAORegistry::getDAO('NotificationStatusDAO');
00261
00262
00263 $journal =& Request::getJournal();
00264 if ($journal) {
00265 $role =& new Role();
00266 $role->setUserId($user->getUserId());
00267 $role->setJournalId($journal->getJournalId());
00268 if ($journal->getSetting('allowRegReviewer')) {
00269 $role->setRoleId(ROLE_ID_REVIEWER);
00270 $hasRole = Validation::isReviewer();
00271 $wantsRole = Request::getUserVar('reviewerRole');
00272 if ($hasRole && !$wantsRole) $roleDao->deleteRole($role);
00273 if (!$hasRole && $wantsRole) $roleDao->insertRole($role);
00274 }
00275 if ($journal->getSetting('allowRegAuthor')) {
00276 $role->setRoleId(ROLE_ID_AUTHOR);
00277 $hasRole = Validation::isAuthor();
00278 $wantsRole = Request::getUserVar('authorRole');
00279 if ($hasRole && !$wantsRole) $roleDao->deleteRole($role);
00280 if (!$hasRole && $wantsRole) $roleDao->insertRole($role);
00281 }
00282 if ($journal->getSetting('allowRegReader')) {
00283 $role->setRoleId(ROLE_ID_READER);
00284 $hasRole = Validation::isReader();
00285 $wantsRole = Request::getUserVar('readerRole');
00286 if ($hasRole && !$wantsRole) $roleDao->deleteRole($role);
00287 if (!$hasRole && $wantsRole) $roleDao->insertRole($role);
00288 }
00289 }
00290
00291 $journals = &$journalDao->getJournals();
00292 $journals = &$journals->toArray();
00293 $journalNotifications = $notificationStatusDao->getJournalNotifications($user->getUserId());
00294
00295 $readerNotify = Request::getUserVar('journalNotify');
00296
00297 foreach ($journals as $thisJournal) {
00298 $thisJournalId = $thisJournal->getJournalId();
00299 $currentlyReceives = !empty($journalNotifications[$thisJournalId]);
00300 $shouldReceive = !empty($readerNotify) && in_array($thisJournal->getJournalId(), $readerNotify);
00301 if ($currentlyReceives != $shouldReceive) {
00302 $notificationStatusDao->setJournalNotifications($thisJournalId, $user->getUserId(), $shouldReceive);
00303 }
00304 }
00305
00306 $openAccessNotify = Request::getUserVar('openAccessNotify');
00307
00308 $userSettingsDao = &DAORegistry::getDAO('UserSettingsDAO');
00309 $journals = &$journalDao->getJournals();
00310 $journals = &$journals->toArray();
00311
00312 foreach ($journals as $thisJournal) {
00313 if (($thisJournal->getSetting('enableSubscriptions') == true) && ($thisJournal->getSetting('enableOpenAccessNotification') == true)) {
00314 $currentlyReceives = $user->getSetting('openAccessNotification', $thisJournal->getJournalId());
00315 $shouldReceive = !empty($openAccessNotify) && in_array($thisJournal->getJournalId(), $openAccessNotify);
00316 if ($currentlyReceives != $shouldReceive) {
00317 $userSettingsDao->updateSetting($user->getUserId(), 'openAccessNotification', $shouldReceive, 'bool', $thisJournal->getJournalId());
00318 }
00319 }
00320 }
00321
00322 if ($user->getAuthId()) {
00323 $authDao = &DAORegistry::getDAO('AuthSourceDAO');
00324 $auth = &$authDao->getPlugin($user->getAuthId());
00325 }
00326
00327 if (isset($auth)) {
00328 $auth->doSetUserInfo($user);
00329 }
00330 }
00331 }
00332
00333 ?>