/** * Выводит форму для редактирования профиля и обрабатывает её * */ protected function EventProfile() { // * Устанавливаем title страницы E::ModuleViewer()->AddHtmlTitle(E::ModuleLang()->Get('settings_menu_profile')); E::ModuleViewer()->Assign('aUserFields', E::ModuleUser()->GetUserFields('')); E::ModuleViewer()->Assign('aUserFieldsContact', E::ModuleUser()->GetUserFields(array('contact', 'social'))); // * Загружаем в шаблон JS текстовки E::ModuleLang()->AddLangJs(array('settings_profile_field_error_max')); // * Если нажали кнопку "Сохранить" if ($this->isPost('submit_profile_edit')) { E::ModuleSecurity()->ValidateSendForm(); $bError = false; /** * Заполняем профиль из полей формы */ // * Определяем гео-объект if (F::GetRequest('geo_city')) { $oGeoObject = E::ModuleGeo()->GetGeoObject('city', F::GetRequestStr('geo_city')); } elseif (F::GetRequest('geo_region')) { $oGeoObject = E::ModuleGeo()->GetGeoObject('region', F::GetRequestStr('geo_region')); } elseif (F::GetRequest('geo_country')) { $oGeoObject = E::ModuleGeo()->GetGeoObject('country', F::GetRequestStr('geo_country')); } else { $oGeoObject = null; } // * Проверяем имя if (F::CheckVal(F::GetRequestStr('profile_name'), 'text', 2, Config::Get('module.user.name_max'))) { $this->oUserCurrent->setProfileName(F::GetRequestStr('profile_name')); } else { $this->oUserCurrent->setProfileName(null); } // * Проверяем пол if (in_array(F::GetRequestStr('profile_sex'), array('man', 'woman', 'other'))) { $this->oUserCurrent->setProfileSex(F::GetRequestStr('profile_sex')); } else { $this->oUserCurrent->setProfileSex('other'); } // * Проверяем дату рождения $nDay = intval(F::GetRequestStr('profile_birthday_day')); $nMonth = intval(F::GetRequestStr('profile_birthday_month')); $nYear = intval(F::GetRequestStr('profile_birthday_year')); if (checkdate($nMonth, $nDay, $nYear)) { $this->oUserCurrent->setProfileBirthday(date('Y-m-d H:i:s', mktime(0, 0, 0, $nMonth, $nDay, $nYear))); } else { $this->oUserCurrent->setProfileBirthday(null); } // * Проверяем информацию о себе if (F::CheckVal(F::GetRequestStr('profile_about'), 'text', 1, 3000)) { $this->oUserCurrent->setProfileAbout(E::ModuleText()->Parser(F::GetRequestStr('profile_about'))); } else { $this->oUserCurrent->setProfileAbout(null); } // * Ставим дату последнего изменения профиля $this->oUserCurrent->setProfileDate(F::Now()); // * Запускаем выполнение хуков E::ModuleHook()->Run('settings_profile_save_before', array('oUser' => $this->oUserCurrent, 'bError' => &$bError)); // * Сохраняем изменения профиля if (!$bError) { if (E::ModuleUser()->Update($this->oUserCurrent)) { // * Обновляем название личного блога $oBlog = $this->oUserCurrent->getBlog(); if (F::GetRequestStr('blog_title') && $this->checkBlogFields($oBlog)) { $oBlog->setTitle(strip_tags(F::GetRequestStr('blog_title'))); E::ModuleBlog()->UpdateBlog($oBlog); } // * Создаем связь с гео-объектом if ($oGeoObject) { E::ModuleGeo()->CreateTarget($oGeoObject, 'user', $this->oUserCurrent->getId()); if ($oCountry = $oGeoObject->getCountry()) { $this->oUserCurrent->setProfileCountry($oCountry->getName()); } else { $this->oUserCurrent->setProfileCountry(null); } if ($oRegion = $oGeoObject->getRegion()) { $this->oUserCurrent->setProfileRegion($oRegion->getName()); } else { $this->oUserCurrent->setProfileRegion(null); } if ($oCity = $oGeoObject->getCity()) { $this->oUserCurrent->setProfileCity($oCity->getName()); } else { $this->oUserCurrent->setProfileCity(null); } } else { E::ModuleGeo()->DeleteTargetsByTarget('user', $this->oUserCurrent->getId()); $this->oUserCurrent->setProfileCountry(null); $this->oUserCurrent->setProfileRegion(null); $this->oUserCurrent->setProfileCity(null); } E::ModuleUser()->Update($this->oUserCurrent); // * Обрабатываем дополнительные поля, type = '' $aFields = E::ModuleUser()->GetUserFields(''); $aData = array(); foreach ($aFields as $iId => $aField) { if (isset($_REQUEST['profile_user_field_' . $iId])) { $aData[$iId] = F::GetRequestStr('profile_user_field_' . $iId); } } E::ModuleUser()->SetUserFieldsValues($this->oUserCurrent->getId(), $aData); // * Динамические поля контактов, type = array('contact','social') $aType = array('contact', 'social'); $aFields = E::ModuleUser()->GetUserFields($aType); // * Удаляем все поля с этим типом E::ModuleUser()->DeleteUserFieldValues($this->oUserCurrent->getId(), $aType); $aFieldsContactType = F::GetRequest('profile_user_field_type'); $aFieldsContactValue = F::GetRequest('profile_user_field_value'); if (is_array($aFieldsContactType)) { foreach ($aFieldsContactType as $k => $v) { $v = (string) $v; if (isset($aFields[$v]) && isset($aFieldsContactValue[$k]) && is_string($aFieldsContactValue[$k])) { E::ModuleUser()->SetUserFieldsValues($this->oUserCurrent->getId(), array($v => $aFieldsContactValue[$k]), Config::Get('module.user.userfield_max_identical')); } } } E::ModuleMessage()->AddNoticeSingle(E::ModuleLang()->Get('settings_profile_submit_ok')); E::ModuleHook()->Run('settings_profile_save_after', array('oUser' => $this->oUserCurrent)); } else { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error')); } } } // * Загружаем гео-объект привязки $oGeoTarget = E::ModuleGeo()->GetTargetByTarget('user', $this->oUserCurrent->getId()); E::ModuleViewer()->Assign('oGeoTarget', $oGeoTarget); // * Загружаем в шаблон список стран, регионов, городов $aCountries = E::ModuleGeo()->GetCountries(array(), array('sort' => 'asc'), 1, 300); E::ModuleViewer()->Assign('aGeoCountries', $aCountries['collection']); if ($oGeoTarget) { if ($oGeoTarget->getCountryId()) { $aRegions = E::ModuleGeo()->GetRegions(array('country_id' => $oGeoTarget->getCountryId()), array('sort' => 'asc'), 1, 500); E::ModuleViewer()->Assign('aGeoRegions', $aRegions['collection']); } if ($oGeoTarget->getRegionId()) { $aCities = E::ModuleGeo()->GetCities(array('region_id' => $oGeoTarget->getRegionId()), array('sort' => 'asc'), 1, 500); E::ModuleViewer()->Assign('aGeoCities', $aCities['collection']); } } E::ModuleLang()->AddLangJs(array('settings_profile_avatar_resize_title', 'settings_profile_avatar_resize_text', 'settings_profile_photo_resize_title', 'settings_profile_photo_resize_text')); }
/** * Выводит форму для редактирования профиля и обрабатывает её * */ protected function EventProfile() { /** * Устанавливаем title страницы */ $this->Viewer_AddHtmlTitle($this->Lang_Get('settings_menu_profile')); $this->Viewer_Assign('aUserFields', $this->User_getUserFields('')); $this->Viewer_Assign('aUserFieldsContact', $this->User_getUserFields(array('contact', 'social'))); /** * Загружаем в шаблон JS текстовки */ $this->Lang_AddLangJs(array('settings_profile_field_error_max')); /** * Если нажали кнопку "Сохранить" */ if (isPost('submit_profile_edit')) { $this->Security_ValidateSendForm(); $bError = false; /** * Заполняем профиль из полей формы */ /** * Определяем гео-объект */ if (getRequest('geo_city')) { $oGeoObject = $this->Geo_GetGeoObject('city', getRequestStr('geo_city')); } elseif (getRequest('geo_region')) { $oGeoObject = $this->Geo_GetGeoObject('region', getRequestStr('geo_region')); } elseif (getRequest('geo_country')) { $oGeoObject = $this->Geo_GetGeoObject('country', getRequestStr('geo_country')); } else { $oGeoObject = null; } /** * Проверяем имя */ if (func_check(getRequestStr('profile_name'), 'text', 2, Config::Get('module.user.name_max'))) { $this->oUserCurrent->setProfileName(getRequestStr('profile_name')); } else { $this->oUserCurrent->setProfileName(null); } /** * Проверяем пол */ if (in_array(getRequestStr('profile_sex'), array('man', 'woman', 'other'))) { $this->oUserCurrent->setProfileSex(getRequestStr('profile_sex')); } else { $this->oUserCurrent->setProfileSex('other'); } /** * Проверяем дату рождения */ if (func_check(getRequestStr('profile_birthday_day'), 'id', 1, 2) and func_check(getRequestStr('profile_birthday_month'), 'id', 1, 2) and func_check(getRequestStr('profile_birthday_year'), 'id', 4, 4)) { $this->oUserCurrent->setProfileBirthday(date("Y-m-d H:i:s", mktime(0, 0, 0, getRequestStr('profile_birthday_month'), getRequestStr('profile_birthday_day'), getRequestStr('profile_birthday_year')))); } else { $this->oUserCurrent->setProfileBirthday(null); } /** * Проверяем информацию о себе */ if (func_check(getRequestStr('profile_about'), 'text', 1, 3000)) { $this->oUserCurrent->setProfileAbout($this->Text_Parser(getRequestStr('profile_about'))); } else { $this->oUserCurrent->setProfileAbout(null); } /** * Ставим дату последнего изменения профиля */ $this->oUserCurrent->setProfileDate(date("Y-m-d H:i:s")); /** * Запускаем выполнение хуков */ $this->Hook_Run('settings_profile_save_before', array('oUser' => $this->oUserCurrent, 'bError' => &$bError)); /** * Сохраняем изменения профиля */ if (!$bError) { if ($this->User_Update($this->oUserCurrent)) { /** * Создаем связь с гео-объектом */ if ($oGeoObject) { $this->Geo_CreateTarget($oGeoObject, 'user', $this->oUserCurrent->getId()); if ($oCountry = $oGeoObject->getCountry()) { $this->oUserCurrent->setProfileCountry($oCountry->getName()); } else { $this->oUserCurrent->setProfileCountry(null); } if ($oRegion = $oGeoObject->getRegion()) { $this->oUserCurrent->setProfileRegion($oRegion->getName()); } else { $this->oUserCurrent->setProfileRegion(null); } if ($oCity = $oGeoObject->getCity()) { $this->oUserCurrent->setProfileCity($oCity->getName()); } else { $this->oUserCurrent->setProfileCity(null); } } else { $this->Geo_DeleteTargetsByTarget('user', $this->oUserCurrent->getId()); $this->oUserCurrent->setProfileCountry(null); $this->oUserCurrent->setProfileRegion(null); $this->oUserCurrent->setProfileCity(null); } $this->User_Update($this->oUserCurrent); /** * Обрабатываем дополнительные поля, type = '' */ $aFields = $this->User_getUserFields(''); $aData = array(); foreach ($aFields as $iId => $aField) { if (isset($_REQUEST['profile_user_field_' . $iId])) { $aData[$iId] = getRequestStr('profile_user_field_' . $iId); } } $this->User_setUserFieldsValues($this->oUserCurrent->getId(), $aData); /** * Динамические поля контактов, type = array('contact','social') */ $aType = array('contact', 'social'); $aFields = $this->User_getUserFields($aType); /** * Удаляем все поля с этим типом */ $this->User_DeleteUserFieldValues($this->oUserCurrent->getId(), $aType); $aFieldsContactType = getRequest('profile_user_field_type'); $aFieldsContactValue = getRequest('profile_user_field_value'); if (is_array($aFieldsContactType)) { foreach ($aFieldsContactType as $k => $v) { $v = (string) $v; if (isset($aFields[$v]) and isset($aFieldsContactValue[$k]) and is_string($aFieldsContactValue[$k])) { $this->User_setUserFieldsValues($this->oUserCurrent->getId(), array($v => $aFieldsContactValue[$k]), Config::Get('module.user.userfield_max_identical')); } } } $this->Message_AddNoticeSingle($this->Lang_Get('settings_profile_submit_ok')); $this->Hook_Run('settings_profile_save_after', array('oUser' => $this->oUserCurrent)); } else { $this->Message_AddErrorSingle($this->Lang_Get('system_error')); } } } /** * Загружаем гео-объект привязки */ $oGeoTarget = $this->Geo_GetTargetByTarget('user', $this->oUserCurrent->getId()); $this->Viewer_Assign('oGeoTarget', $oGeoTarget); /** * Загружаем в шаблон список стран, регионов, городов */ $aCountries = $this->Geo_GetCountries(array(), array('sort' => 'asc'), 1, 300); $this->Viewer_Assign('aGeoCountries', $aCountries['collection']); if ($oGeoTarget) { if ($oGeoTarget->getCountryId()) { $aRegions = $this->Geo_GetRegions(array('country_id' => $oGeoTarget->getCountryId()), array('sort' => 'asc'), 1, 500); $this->Viewer_Assign('aGeoRegions', $aRegions['collection']); } if ($oGeoTarget->getRegionId()) { $aCities = $this->Geo_GetCities(array('region_id' => $oGeoTarget->getRegionId()), array('sort' => 'asc'), 1, 500); $this->Viewer_Assign('aGeoCities', $aCities['collection']); } } }