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 FormValidator($this, 'affiliation', 'required', 'user.profile.form.affiliationRequired'));
00042 $this->addCheck(new FormValidatorCustom($this, 'email', 'required', 'user.account.form.emailExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByEmail'), array($user->getId(), true), true));
00043 $this->addCheck(new FormValidatorPost($this));
00044 }
00045
00049 function deleteProfileImage() {
00050 $user =& Request::getUser();
00051 $profileImage = $user->getSetting('profileImage');
00052 if (!$profileImage) return false;
00053
00054 import('file.PublicFileManager');
00055 $fileManager = new PublicFileManager();
00056 if ($fileManager->removeSiteFile($profileImage['uploadName'])) {
00057 return $user->updateSetting('profileImage', null);
00058 } else {
00059 return false;
00060 }
00061 }
00062
00063 function uploadProfileImage() {
00064 import('file.PublicFileManager');
00065 $fileManager = new PublicFileManager();
00066
00067 $user =& $this->user;
00068
00069 $type = $fileManager->getUploadedFileType('profileImage');
00070 $extension = $fileManager->getImageExtension($type);
00071 if (!$extension) return false;
00072
00073 $uploadName = 'profileImage-' . (int) $user->getId() . $extension;
00074 if ($fileManager->uploadError('profileImage')) return false;
00075 if (!$fileManager->uploadSiteFile('profileImage', $uploadName)) return false;
00076
00077 $filePath = $fileManager->getSiteFilesPath();
00078 list($width, $height) = getimagesize($filePath . '/' . $uploadName);
00079
00080 if ($width > 150 || $height > 150 || $width <= 0 || $height <= 0) {
00081 $userSetting = null;
00082 $user->updateSetting('profileImage', $userSetting);
00083 $fileManager->removeSiteFile($filePath);
00084 return false;
00085 }
00086
00087 $userSetting = array(
00088 'name' => $fileManager->getUploadedFileName('profileImage'),
00089 'uploadName' => $uploadName,
00090 'width' => $width,
00091 'height' => $height,
00092 'dateUploaded' => Core::getCurrentDate()
00093 );
00094
00095 $user->updateSetting('profileImage', $userSetting);
00096 return true;
00097 }
00098
00102 function display() {
00103 $user =& Request::getUser();
00104
00105 $templateMgr =& TemplateManager::getManager();
00106 $templateMgr->assign('username', $user->getUsername());
00107
00108 $site =& Request::getSite();
00109 $templateMgr->assign('availableLocales', $site->getSupportedLocaleNames());
00110
00111 $roleDao =& DAORegistry::getDAO('RoleDAO');
00112 $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00113 $userSettingsDao =& DAORegistry::getDAO('UserSettingsDAO');
00114 $userDao =& DAORegistry::getDAO('UserDAO');
00115
00116 $schedConfs =& $schedConfDao->getEnabledSchedConfs();
00117 $schedConfs =& $schedConfs->toArray();
00118
00119 foreach ($schedConfs as $thisSchedConf) {
00120 if ($thisSchedConf->getSetting('enableOpenAccessNotification') == true) {
00121 $templateMgr->assign('displayOpenAccessNotification', true);
00122 $templateMgr->assign_by_ref('user', $user);
00123 break;
00124 }
00125 }
00126
00127 $countryDao =& DAORegistry::getDAO('CountryDAO');
00128 $countries =& $countryDao->getCountries();
00129
00130 $templateMgr->assign('genderOptions', $userDao->getGenderOptions());
00131
00132 $templateMgr->assign_by_ref('schedConfs', $schedConfs);
00133 $templateMgr->assign_by_ref('countries', $countries);
00134 $templateMgr->assign('helpTopicId', 'conference.users.index');
00135
00136 $schedConf =& Request::getSchedConf();
00137 if ($schedConf) {
00138 $roleDao =& DAORegistry::getDAO('RoleDAO');
00139 $roles =& $roleDao->getRolesByUserId($user->getId(), $schedConf->getId());
00140 $roleNames = array();
00141 foreach ($roles as $role) $roleNames[$role->getRolePath()] = $role->getRoleName();
00142 import('schedConf.SchedConfAction');
00143 $templateMgr->assign('allowRegReviewer', SchedConfAction::allowRegReviewer($schedConf));
00144 $templateMgr->assign('allowRegAuthor', SchedConfAction::allowRegAuthor($schedConf));
00145 $templateMgr->assign('allowRegReader', SchedConfAction::allowRegReader($schedConf));
00146 $templateMgr->assign('roles', $roleNames);
00147 }
00148
00149 $timeZoneDao =& DAORegistry::getDAO('TimeZoneDAO');
00150 $timeZones =& $timeZoneDao->getTimeZones();
00151 $templateMgr->assign_by_ref('timeZones', $timeZones);
00152
00153 $templateMgr->assign('profileImage', $user->getSetting('profileImage'));
00154
00155 parent::display();
00156 }
00157
00158 function getLocaleFieldNames() {
00159 $userDao =& DAORegistry::getDAO('UserDAO');
00160 return $userDao->getLocaleFieldNames();
00161 }
00162
00166 function initData() {
00167 $user =& Request::getUser();
00168
00169 $this->_data = array(
00170 'salutation' => $user->getSalutation(),
00171 'firstName' => $user->getFirstName(),
00172 'middleName' => $user->getMiddleName(),
00173 'initials' => $user->getInitials(),
00174 'lastName' => $user->getLastName(),
00175 'gender' => $user->getGender(),
00176 'affiliation' => $user->getAffiliation(),
00177 'signature' => $user->getSignature(null),
00178 'email' => $user->getEmail(),
00179 'userUrl' => $user->getUrl(),
00180 'phone' => $user->getPhone(),
00181 'fax' => $user->getFax(),
00182 'mailingAddress' => $user->getMailingAddress(),
00183 'country' => $user->getCountry(),
00184 'timeZone' => $user->getTimeZone(),
00185 'biography' => $user->getBiography(null),
00186 'interests' => $user->getInterests(null),
00187 'userLocales' => $user->getLocales(),
00188 'isAuthor' => Validation::isAuthor(),
00189 'isReader' => Validation::isReader(),
00190 'isReviewer' => Validation::isReviewer()
00191 );
00192
00193
00194 }
00195
00199 function readInputData() {
00200 $this->readUserVars(array(
00201 'salutation',
00202 'firstName',
00203 'middleName',
00204 'lastName',
00205 'gender',
00206 'initials',
00207 'affiliation',
00208 'signature',
00209 'email',
00210 'userUrl',
00211 'phone',
00212 'fax',
00213 'mailingAddress',
00214 'country',
00215 'timeZone',
00216 'biography',
00217 'interests',
00218 'userLocales',
00219 'readerRole',
00220 'authorRole',
00221 'reviewerRole'
00222 ));
00223
00224 if ($this->getData('userLocales') == null || !is_array($this->getData('userLocales'))) {
00225 $this->setData('userLocales', array());
00226 }
00227 }
00228
00232 function execute() {
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->setGender($this->getData('gender'));
00240 $user->setInitials($this->getData('initials'));
00241 $user->setAffiliation($this->getData('affiliation'));
00242 $user->setSignature($this->getData('signature'), null);
00243 $user->setEmail($this->getData('email'));
00244 $user->setUrl($this->getData('userUrl'));
00245 $user->setPhone($this->getData('phone'));
00246 $user->setFax($this->getData('fax'));
00247 $user->setMailingAddress($this->getData('mailingAddress'));
00248 $user->setCountry($this->getData('country'));
00249 $user->setTimeZone($this->getData('timeZone'));
00250 $user->setBiography($this->getData('biography'), null);
00251 $user->setInterests($this->getData('interests'), null);
00252
00253 $site =& Request::getSite();
00254 $availableLocales = $site->getSupportedLocales();
00255
00256 $locales = array();
00257 foreach ($this->getData('userLocales') as $locale) {
00258 if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
00259 array_push($locales, $locale);
00260 }
00261 }
00262 $user->setLocales($locales);
00263
00264 $userDao =& DAORegistry::getDAO('UserDAO');
00265 $userDao->updateObject($user);
00266
00267 $roleDao =& DAORegistry::getDAO('RoleDAO');
00268 $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00269
00270
00271 $schedConf =& Request::getSchedConf();
00272 if ($schedConf) {
00273 import('schedConf.SchedConfAction');
00274 $role = new Role();
00275 $role->setUserId($user->getId());
00276 $role->setConferenceId($schedConf->getConferenceId());
00277 $role->setSchedConfId($schedConf->getId());
00278 if (SchedConfAction::allowRegReviewer($schedConf)) {
00279 $role->setRoleId(ROLE_ID_REVIEWER);
00280 $hasRole = Validation::isReviewer();
00281 $wantsRole = Request::getUserVar('reviewerRole');
00282 if ($hasRole && !$wantsRole) $roleDao->deleteRole($role);
00283 if (!$hasRole && $wantsRole) $roleDao->insertRole($role);
00284 }
00285 if (SchedConfAction::allowRegAuthor($schedConf)) {
00286 $role->setRoleId(ROLE_ID_AUTHOR);
00287 $hasRole = Validation::isAuthor();
00288 $wantsRole = Request::getUserVar('authorRole');
00289 if ($hasRole && !$wantsRole) $roleDao->deleteRole($role);
00290 if (!$hasRole && $wantsRole) $roleDao->insertRole($role);
00291 }
00292 if (SchedConfAction::allowRegReader($schedConf)) {
00293 $role->setRoleId(ROLE_ID_READER);
00294 $hasRole = Validation::isReader();
00295 $wantsRole = Request::getUserVar('readerRole');
00296 if ($hasRole && !$wantsRole) $roleDao->deleteRole($role);
00297 if (!$hasRole && $wantsRole) $roleDao->insertRole($role);
00298 }
00299 }
00300
00301 $openAccessNotify = Request::getUserVar('openAccessNotify');
00302
00303 $userSettingsDao =& DAORegistry::getDAO('UserSettingsDAO');
00304 $schedConfs =& $schedConfDao->getSchedConfs();
00305 $schedConfs =& $schedConfs->toArray();
00306
00307 foreach ($schedConfs as $thisSchedConf) {
00308 if ($thisSchedConf->getSetting('enableOpenAccessNotification') == true) {
00309 $currentlyReceives = $user->getSetting('openAccessNotification', $thisSchedConf->getId());
00310 $shouldReceive = !empty($openAccessNotify) && in_array($thisSchedConf->getId(), $openAccessNotify);
00311 if ($currentlyReceives != $shouldReceive) {
00312 $userSettingsDao->updateSetting($user->getId(), 'openAccessNotification', $shouldReceive, 'bool', $thisSchedConf->getId());
00313 }
00314 }
00315 }
00316
00317 if ($user->getAuthId()) {
00318 $authDao =& DAORegistry::getDAO('AuthSourceDAO');
00319 $auth =& $authDao->getPlugin($user->getAuthId());
00320 }
00321
00322 if (isset($auth)) {
00323 $auth->doSetUserInfo($user);
00324 }
00325 }
00326 }
00327
00328 ?>