public function run($profile) { // проверяем наличие доступа if ($profile['id'] != $this->cms_user->id) { cmsCore::error404(); } // Форма отправлена? $is_submitted = $this->request->has('submit'); if (!$is_submitted && !$profile['invites_count']) { cmsCore::error404(); } $form = new cmsForm(); $fieldset_id = $form->addFieldset(); if ($profile['invites_count'] > 1) { $form->addField($fieldset_id, new fieldText('emails', array('title' => LANG_USERS_INVITES_EMAILS, 'hint' => LANG_USERS_INVITES_EMAILS_HINT, 'rules' => array(array('required'))))); } if ($profile['invites_count'] == 1) { $form->addField($fieldset_id, new fieldString('emails', array('title' => LANG_USERS_INVITES_EMAIL, 'rules' => array(array('required'), array('email'))))); } $input = array(); if ($is_submitted) { // Парсим форму и получаем поля записи $input = $form->parse($this->request, $is_submitted); // Проверям правильность заполнения $errors = $form->validate($this, $input); if (!$errors) { $results = $this->sendInvites($profile, $input['emails']); return $this->cms_template->render('profile_invites_results', array('id' => $profile['id'], 'profile' => $profile, 'results' => $results)); } if ($errors) { cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error'); } } return $this->cms_template->render('profile_invites', array('id' => $profile['id'], 'profile' => $profile, 'form' => $form, 'input' => $input, 'errors' => isset($errors) ? $errors : false)); }
public function run($ctype_id, $parent_id) { $items = $this->request->get('selected'); $is_submitted = $this->request->has('items'); $template = cmsTemplate::getInstance(); $content_model = cmsCore::getModel('content'); $ctype = $content_model->getContentType($ctype_id); $fields = $content_model->getContentFields($ctype['name']); $form = new cmsForm(); $fieldset_id = $form->addFieldset(LANG_MOVE_TO_CATEGORY); $form->addField($fieldset_id, new fieldList('category_id', array('default' => $parent_id, 'generator' => function ($data) { $content_model = cmsCore::getModel('content'); $tree = $content_model->getCategoriesTree($data['ctype_name']); foreach ($tree as $c) { $items[$c['id']] = str_repeat('- ', $c['ns_level']) . ' ' . $c['title']; } return $items; }))); $form->addField($fieldset_id, new fieldHidden('items')); $data = $form->parse($this->request, $is_submitted); if ($is_submitted) { // Проверяем правильность заполнения $errors = $form->validate($this, $data); if (!$errors) { $data['items'] = explode(',', $data['items']); $content_model->moveContentItemsToCategory($ctype, $data['category_id'], $data['items'], $fields); $template->renderJSON(array('errors' => false, 'callback' => 'contentItemsMoved')); } if ($errors) { $template->renderJSON(array('errors' => true)); } $this->halt(); } return $template->render('content_item_move', array('ctype' => $ctype, 'parent_id' => $parent_id, 'items' => $items, 'form' => $form, 'errors' => isset($errors) ? $errors : false)); }
public function run($profile) { $user = cmsUser::getInstance(); $template = cmsTemplate::getInstance(); // проверяем наличие доступа if ($profile['id'] != $user->id && !$user->is_admin) { cmsCore::error404(); } $pricacy_types = cmsEventsManager::hookAll('user_privacy_types'); $form = new cmsForm(); $fieldset_id = $form->addFieldset(); $default_options = array('', 'anyone', 'friends'); foreach ($pricacy_types as $list) { foreach ($list as $name => $type) { $options = array(); if (!isset($type['options'])) { $type['options'] = $default_options; } foreach ($type['options'] as $option) { if (!$option) { $options[''] = LANG_USERS_PRIVACY_FOR_NOBODY; } else { $options[$option] = constant('LANG_USERS_PRIVACY_FOR_' . mb_strtoupper($option)); } } $form->addField($fieldset_id, new fieldList($name, array('title' => $type['title'], 'default' => 'anyone', 'items' => $options))); } } // Форма отправлена? $is_submitted = $this->request->has('submit'); $options = $this->model->getUserPrivacyOptions($profile['id']); if ($is_submitted) { // Парсим форму и получаем поля записи $options = array_merge($options, $form->parse($this->request, $is_submitted, $options)); // Проверям правильность заполнения $errors = $form->validate($this, $options); if (!$errors) { // Обновляем профиль и редиректим на его просмотр $this->model->updateUserPrivacyOptions($profile['id'], $options); $this->redirectTo('users', $profile['id']); } if ($errors) { cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error'); } } return $template->render('profile_edit_privacy', array('id' => $profile['id'], 'profile' => $profile, 'options' => $options, 'form' => $form, 'errors' => isset($errors) ? $errors : false)); }
public function run($profile, $do = false) { if (!cmsUser::isLogged()) { cmsCore::error404(); } $user = cmsUser::getInstance(); // если нужно, передаем управление другому экшену if ($do) { $this->runAction('profile_edit_' . $do, array($profile) + array_slice($this->params, 2)); return; } // проверяем наличие доступа if ($profile['id'] != $user->id && !$user->is_admin) { cmsCore::error404(); } // Получаем поля $content_model = cmsCore::getModel('content'); $content_model->setTablePrefix(''); $content_model->orderBy('ordering'); $fields = $content_model->getContentFields('{users}'); // Строим форму $form = new cmsForm(); // Разбиваем поля по группам $fieldsets = cmsForm::mapFieldsToFieldsets($fields, function ($field, $user) { // проверяем что группа пользователя имеет доступ к редактированию этого поля if ($field['groups_edit'] && !$user->isInGroups($field['groups_edit'])) { return false; } return true; }); // Добавляем поля в форму foreach ($fieldsets as $fieldset) { $fieldset_id = $form->addFieldset($fieldset['title']); foreach ($fieldset['fields'] as $field) { // добавляем поле в форму $form->addField($fieldset_id, $field['handler']); } } // Добавляем поле выбора часового пояса $config = cmsConfig::getInstance(); $fieldset_id = $form->addFieldset(LANG_TIME_ZONE); $form->addField($fieldset_id, new fieldList('time_zone', array('default' => $config->time_zone, 'generator' => function ($item) { return cmsCore::getTimeZones(); }))); // Форма отправлена? $is_submitted = $this->request->has('submit'); if ($is_submitted) { // Парсим форму и получаем поля записи $new = $form->parse($this->request, $is_submitted, $profile); $old = $profile; $profile = array_merge($profile, $new); // Проверям правильность заполнения $errors = $form->validate($this, $profile); if (!$errors) { $is_allowed = cmsEventsManager::hookAll('user_profile_update', $profile, true); if ($is_allowed !== true && in_array(false, $is_allowed)) { $errors = true; } } if (!$errors) { // Обновляем профиль и редиректим на его просмотр $this->model->updateUser($profile['id'], $profile); // Отдельно обновляем часовой пояс в сессии cmsUser::sessionSet('user_data:time_zone', $profile['time_zone']); // Постим уведомление о смене аватара в ленту if (!$this->model->isAvatarsEqual($new['avatar'], $old['avatar'])) { $activity_controller = cmsCore::getController('activity'); $activity_controller->deleteEntry($this->name, "avatar", $profile['id']); if (!empty($new['avatar'])) { $activity_controller->addEntry($this->name, "avatar", array('user_id' => $profile['id'], 'subject_title' => $profile['nickname'], 'subject_id' => $profile['id'], 'subject_url' => href_to('users', $profile['id']), 'is_private' => 0, 'group_id' => null, 'images' => array(array('url' => href_to('users', $profile['id']), 'src' => html_image_src($new['avatar'], 'normal'))), 'images_count' => 1)); } } $this->redirectTo('users', $profile['id']); } if ($errors) { cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error'); } } return cmsTemplate::getInstance()->render('profile_edit', array('do' => 'edit', 'id' => $profile['id'], 'profile' => $profile, 'form' => $form, 'errors' => isset($errors) ? $errors : false)); }