00001 <?php
00002
00017 import('lib.pkp.classes.form.Form');
00018
00019 class ProfileForm extends Form {
00020
00022 var $_user;
00023
00027 function ProfileForm($user) {
00028 parent::Form('user/profile.tpl');
00029
00030 $this->_user =& $user;
00031 assert($user);
00032
00033
00034 $this->addCheck(new FormValidator($this, 'firstName', 'required', 'user.profile.form.firstNameRequired'));
00035 $this->addCheck(new FormValidator($this, 'lastName', 'required', 'user.profile.form.lastNameRequired'));
00036 $this->addCheck(new FormValidatorUrl($this, 'userUrl', 'optional', 'user.profile.form.urlInvalid'));
00037 $this->addCheck(new FormValidatorEmail($this, 'email', 'required', 'user.profile.form.emailRequired'));
00038 $this->addCheck(new FormValidatorCustom($this, 'email', 'required', 'user.register.form.emailExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByEmail'), array($user->getId(), true), true));
00039 $this->addCheck(new FormValidator($this, 'country', 'required', 'user.profile.form.countryRequired'));
00040 $this->addCheck(new FormValidatorPost($this));
00041 }
00042
00046 function getUser() {
00047 return $this->_user;
00048 }
00049
00053 function deleteProfileImage() {
00054 $user =& $this->getUser();
00055 $profileImage = $user->getSetting('profileImage');
00056 if (!$profileImage) return false;
00057
00058 import('classes.file.PublicFileManager');
00059 $publicFileManager = new PublicFileManager();
00060 if ($publicFileManager->removeSiteFile($profileImage['uploadName'])) {
00061 return $user->updateSetting('profileImage', null);
00062 } else {
00063 return false;
00064 }
00065 }
00066
00067 function uploadProfileImage() {
00068 import('classes.file.PublicFileManager');
00069 $publicFileManager = new PublicFileManager();
00070
00071 $user =& $this->getUser();
00072
00073 $type = $publicFileManager->getUploadedFileType('profileImage');
00074 $extension = $publicFileManager->getImageExtension($type);
00075 if (!$extension) return false;
00076
00077 $uploadName = 'profileImage-' . (int) $user->getId() . $extension;
00078 if (!$publicFileManager->uploadSiteFile('profileImage', $uploadName)) return false;
00079
00080 $filePath = $publicFileManager->getSiteFilesPath();
00081 list($width, $height) = getimagesize($filePath . '/' . $uploadName);
00082
00083 if ($width > 150 || $height > 150 || $width <= 0 || $height <= 0) {
00084 $userSetting = null;
00085 $user->updateSetting('profileImage', $userSetting);
00086 $publicFileManager->removeSiteFile($filePath);
00087 return false;
00088 }
00089
00090 $userSetting = array(
00091 'name' => $publicFileManager->getUploadedFileName('profileImage'),
00092 'uploadName' => $uploadName,
00093 'width' => $width,
00094 'height' => $height,
00095 'dateUploaded' => Core::getCurrentDate()
00096 );
00097
00098 $user->updateSetting('profileImage', $userSetting);
00099 return true;
00100 }
00101
00105 function display($args, &$request) {
00106 $templateMgr =& TemplateManager::getManager();
00107
00108 $user =& $this->getUser();
00109 $templateMgr->assign('username', $user->getUsername());
00110
00111 $site =& $request->getSite();
00112 $templateMgr->assign('availableLocales', $site->getSupportedLocaleNames());
00113
00114
00115 $userDao =& DAORegistry::getDAO('UserDAO');
00116 $templateMgr->assign('genderOptions', $userDao->getGenderOptions());
00117
00118 $pressDao =& DAORegistry::getDAO('PressDAO');
00119 $presses =& $pressDao->getPresses();
00120 $presses =& $presses->toArray();
00121 $templateMgr->assign_by_ref('presses', $presses);
00122
00123 $countryDao =& DAORegistry::getDAO('CountryDAO');
00124 $countries =& $countryDao->getCountries();
00125 $templateMgr->assign_by_ref('countries', $countries);
00126
00127 $templateMgr->assign('helpTopicId', 'user.registerAndProfile');
00128
00129 $press =& $request->getPress();
00130 if ($press) {
00131 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00132 $userGroupAssignmentDao =& DAORegistry::getDAO('UserGroupAssignmentDAO');
00133 $userGroupAssignments =& $userGroupAssignmentDao->getByUserId($user->getId(), $press->getId());
00134 $userGroupIds = array();
00135 while ($assignment =& $userGroupAssignments->next()) {
00136 $userGroupIds[] = $assignment->getUserGroupId();
00137 unset($assignment);
00138 }
00139 $templateMgr->assign('allowRegReviewer', $press->getSetting('allowRegReviewer'));
00140 $templateMgr->assign_by_ref('reviewerUserGroups', $userGroupDao->getByRoleId($press->getId(), ROLE_ID_REVIEWER));
00141 $templateMgr->assign('allowRegAuthor', $press->getSetting('allowRegAuthor'));
00142 $templateMgr->assign_by_ref('authorUserGroups', $userGroupDao->getByRoleId($press->getId(), ROLE_ID_AUTHOR));
00143 $templateMgr->assign('userGroupIds', $userGroupIds);
00144 }
00145
00146 $templateMgr->assign('profileImage', $user->getSetting('profileImage'));
00147
00148 parent::display();
00149 }
00150
00151 function getLocaleFieldNames() {
00152 $userDao =& DAORegistry::getDAO('UserDAO');
00153 return $userDao->getLocaleFieldNames();
00154 }
00155
00161 function initData(&$args, &$request) {
00162 $user =& $this->getUser();
00163
00164 import('lib.pkp.classes.user.InterestManager');
00165 $interestManager = new InterestManager();
00166
00167 $this->_data = array(
00168 'salutation' => $user->getSalutation(),
00169 'firstName' => $user->getFirstName(),
00170 'middleName' => $user->getMiddleName(),
00171 'initials' => $user->getInitials(),
00172 'lastName' => $user->getLastName(),
00173 'suffix' => $user->getSuffix(),
00174 'gender' => $user->getGender(),
00175 'affiliation' => $user->getAffiliation(null),
00176 'signature' => $user->getSignature(null),
00177 'email' => $user->getEmail(),
00178 'userUrl' => $user->getUrl(),
00179 'phone' => $user->getPhone(),
00180 'fax' => $user->getFax(),
00181 'mailingAddress' => $user->getMailingAddress(),
00182 'country' => $user->getCountry(),
00183 'biography' => $user->getBiography(null),
00184 'userLocales' => $user->getLocales(),
00185 'interestsKeywords' => $interestManager->getInterestsForUser($user),
00186 'interestsTextOnly' => $interestManager->getInterestsString($user)
00187 );
00188 }
00189
00193 function readInputData() {
00194 $this->readUserVars(array(
00195 'salutation',
00196 'firstName',
00197 'middleName',
00198 'lastName',
00199 'suffix',
00200 'gender',
00201 'initials',
00202 'affiliation',
00203 'signature',
00204 'email',
00205 'userUrl',
00206 'phone',
00207 'fax',
00208 'mailingAddress',
00209 'country',
00210 'biography',
00211 'reviewerGroup',
00212 'authorGroup',
00213 'keywords',
00214 'interestsTextOnly',
00215 'userLocales'
00216 ));
00217
00218 if ($this->getData('userLocales') == null || !is_array($this->getData('userLocales'))) {
00219 $this->setData('userLocales', array());
00220 }
00221
00222 $keywords = $this->getData('keywords');
00223 if ($keywords != null && is_array($keywords['interests'])) {
00224
00225 $this->setData('interestsKeywords', array_map('urldecode', $keywords['interests']));
00226 }
00227 }
00228
00232 function execute($request) {
00233 $user =& $request->getUser();
00234
00235 $user->setSalutation($this->getData('salutation'));
00236 $user->setFirstName($this->getData('firstName'));
00237 $user->setMiddleName($this->getData('middleName'));
00238 $user->setLastName($this->getData('lastName'));
00239 $user->setSuffix($this->getData('suffix'));
00240 $user->setGender($this->getData('gender'));
00241 $user->setInitials($this->getData('initials'));
00242 $user->setAffiliation($this->getData('affiliation'), null);
00243 $user->setSignature($this->getData('signature'), null);
00244 $user->setEmail($this->getData('email'));
00245 $user->setUrl($this->getData('userUrl'));
00246 $user->setPhone($this->getData('phone'));
00247 $user->setFax($this->getData('fax'));
00248 $user->setMailingAddress($this->getData('mailingAddress'));
00249 $user->setCountry($this->getData('country'));
00250 $user->setBiography($this->getData('biography'), null);
00251
00252
00253 $interests = $this->getData('interestsKeywords') ? $this->getData('interestsKeywords') : $this->getData('interestsTextOnly');
00254 import('lib.pkp.classes.user.InterestManager');
00255 $interestManager = new InterestManager();
00256 $interestManager->setInterestsForUser($user, $interests);
00257
00258 $site =& $request->getSite();
00259 $availableLocales = $site->getSupportedLocales();
00260
00261 $locales = array();
00262 foreach ($this->getData('userLocales') as $locale) {
00263 if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
00264 array_push($locales, $locale);
00265 }
00266 }
00267 $user->setLocales($locales);
00268
00269 $userDao =& DAORegistry::getDAO('UserDAO');
00270 $userDao->updateObject($user);
00271
00272
00273 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00274 $press =& $request->getPress();
00275 if ($press) {
00276 foreach (array(
00277 array('setting' => 'allowRegReviewer', 'roleId' => ROLE_ID_REVIEWER, 'formElement' => 'reviewerGroup'),
00278 array('setting' => 'allowRegAuthor', 'roleId' => ROLE_ID_AUTHOR, 'formElement' => 'authorGroup'),
00279 ) as $groupData) {
00280 $groupFormData = (array) $this->getData($groupData['formElement']);
00281 if (!$press->getSetting($groupData['setting'])) continue;
00282 $userGroups =& $userGroupDao->getByRoleId($press->getId(), $groupData['roleId']);
00283 while ($userGroup =& $userGroups->next()) {
00284 $groupId = $userGroup->getId();
00285 $inGroup = $userGroupDao->userInGroup($user->getId(), $groupId);
00286 if (!$inGroup && array_key_exists($groupId, $groupFormData)) {
00287 $userGroupDao->assignUserToGroup($user->getId(), $groupId, $press->getId());
00288 } elseif ($inGroup && !array_key_exists($groupId, $groupFormData)) {
00289 $userGroupDao->removeUserFromGroup($user->getId(), $groupId, $press->getId());
00290 }
00291 unset($userGroup);
00292 }
00293 unset($userGroups);
00294 }
00295 }
00296
00297 $notificationStatusDao =& DAORegistry::getDAO('NotificationStatusDAO');
00298 $pressNotifications = $notificationStatusDao->getPressNotifications($user->getId());
00299 $readerNotify = $request->getUserVar('pressNotify');
00300
00301 $pressDao =& DAORegistry::getDAO('PressDAO');
00302 $presses =& $pressDao->getPresses();
00303 while ($thisPress =& $presses->next()) {
00304 $thisPressId = $thisPress->getId();
00305 $currentlyReceives = !empty($pressNotifications[$thisPressId]);
00306 $shouldReceive = !empty($readerNotify) && in_array($thisPress->getId(), $readerNotify);
00307 if ($currentlyReceives != $shouldReceive) {
00308 $notificationStatusDao->setPressNotifications($thisPressId, $user->getId(), $shouldReceive);
00309 }
00310 unset($thisPress);
00311 }
00312
00313 if ($user->getAuthId()) {
00314 $authDao =& DAORegistry::getDAO('AuthSourceDAO');
00315 $auth =& $authDao->getPlugin($user->getAuthId());
00316 }
00317
00318 if (isset($auth)) {
00319 $auth->doSetUserInfo($user);
00320 }
00321 }
00322 }
00323
00324 ?>