/** * Сохраняет данные формы сгенерированной фукцией AdminUserEditor * * @param $back_link * @param string $a * @param int $id * @param bool $IsAdmin * @return void */ function AdminUserEditSave($back_link, $a = 'insert', $id = 0, $IsAdmin = false) { $SystemAdmin = System::user()->isSuperUser(); $edit = $a == 'update'; $editProfile = $edit && !$SystemAdmin && $id == System::user()->Get('u_id'); // Администратор редактирует свой профиль $editStatus = false; // Разрешено редактирование статуса $editType = false; // Разрешено редактировать тип пользователя // Загружаем данные пользователя из БД if ($edit) { $user = System::database()->SelectOne('users', "`id`='{$id}'" . ($IsAdmin ? " and `type`='1'" : " and `type`='2'")); if (!$user) { AddTextBox('Ошибка', '<p align="center">Пользователь не найден, либо у вас не достаточно прав для редактирования администраторов.</p>'); return; } } // Устанавливаем ограничения доступа if ($IsAdmin) { // Редактируем администратора if ($SystemAdmin) { // Только системные администраторы могут редактировать статус и тип администраторов if (!$edit) { $editStatus = true; } elseif (!(groupIsSystem(SafeEnv($user['access'], 11, int)) && GetSystemAdminsCount() <= 1)) { // Если он не системный или системных больше 1 $editStatus = true; } $editType = $editStatus; } } else { // Если пользователь $editStatus = true; // Все администраторы с доступом могут редактировать статус пользователя $editType = $SystemAdmin; // Только системные администраторы могут создавать администраторов } // Обрабатываем данные $errors = array(); // Логин if (isset($_POST['login']) && CheckLogin($_POST['login'], $errors, !$edit)) { $login = SafeEnv($_POST['login'], 30, str); } else { $login = ''; } // Пароль $pass = ''; if (!$edit || $_POST['pass'] != '') { $pass_generate_message = ''; if (isset($_POST['pass']) && CheckPass($_POST['pass'], $errors)) { $pass = SafeEnv($_POST['pass'], 30, str); if (!isset($_POST['rpass']) || SafeEnv($_POST['rpass'], 30, str) != $pass) { $errors[] = 'Пароли не совпадают.'; } } else { $pass = ''; } if (isset($_POST['pass']) && $_POST['pass'] == '') { srand(time()); $pass = GenBPass(rand(System::config('user/pass_min_length'), 15)); $pass_generate_message = '<br />Так как вы не указали пароль, он был сгенерирован автоматически и выслан на указанный E-mail пользователя.'; } $pass2 = md5($pass); } // e-mail if (isset($_POST['email']) && $_POST['email'] != '') { if (!CheckEmail($_POST['email'])) { $errors[] = 'Не правильный формат E-mail. Он должен быть вида: <b>domain@host.ru</b> .'; } $email = SafeEnv($_POST['email'], 50, str, true); } else { $email = ''; $errors[] = 'Вы не ввели E-mail.'; } // Скрыть e-mail if (isset($_POST['hideemail'])) { $hide_email = '1'; } else { $hide_email = '0'; } // Имя пользователя на сайте if (isset($_POST['nikname']) && CheckNikname($_POST['nikname'], $errors, !$edit)) { $nik_name = SafeEnv($_POST['nikname'], 50, str, true); } else { $nik_name = ''; } // Полное имя if (isset($_POST['realname'])) { $real_name = SafeEnv($_POST['realname'], 250, str, true); } else { $real_name = ''; } // Возраст if (isset($_POST['age'])) { if ($_POST['age'] == '' || is_numeric($_POST['age'])) { $age = SafeEnv($_POST['age'], 3, int); } else { $errors[] = 'Ваш возраст должен быть числом!'; } } else { $age = ''; } // Домашняя страница if (isset($_POST['homepage'])) { if ($_POST['homepage'] != '' && substr($_POST['homepage'], 0, 7) == 'http://') { $_POST['homepage'] = substr($_POST['homepage'], 7); } $homepage = SafeEnv($_POST['homepage'], 250, str, true); } else { $homepage = ''; } // Номер ICQ if (isset($_POST['icq'])) { if ($_POST['icq'] == '' || is_numeric($_POST['icq'])) { $icq = SafeEnv($_POST['icq'], 15, str, true); } else { $errors[] = 'Номер ICQ должен содержать только числа!'; } } else { $icq = ''; } // Город if (isset($_POST['city'])) { $city = SafeEnv($_POST['city'], 100, str, true); } else { $city = ''; } // Часовой пояс if (isset($_POST['gmt'])) { $gmt = SafeEnv($_POST['gmt'], 255, str); } else { $gmt = System::config('general/default_timezone'); } // О себе if (isset($_POST['about'])) { $about = SafeEnv($_POST['about'], System::config('user/about_max_length'), str, true); } else { $about = ''; } // Подписка на новости if (isset($_POST['snews'])) { $server_news = '1'; } else { $server_news = '0'; } //Обрабатываем аватар $updateAvatar = true; if (isset($_POST['avatar'])) { if (System::config('user/avatar_transfer') == '1' && isset($_FILES['upavatar']) && file_exists($_FILES['upavatar']['tmp_name'])) { if ($edit) { $avatar = $user['avatar']; $a_personal = $user['a_personal']; } else { $avatar = ''; $a_personal = '0'; } UserLoadAvatar($errors, $avatar, $a_personal, $avatar, $a_personal, $edit); } elseif ($_POST['avatar'] == '') { $updateAvatar = false; } elseif (file_exists(RealPath2(System::config('general/avatars_dir') . $_POST['avatar']))) { if ($edit) { if ($user['a_personal'] == '1') { UnlinkUserAvatarFiles($user['avatar']); } } $a_personal = '0'; $avatar = $_POST['avatar']; } else { $avatar = ''; $a_personal = '0'; } } else { $avatar = ''; $a_personal = '0'; } $SendActivation = false; if ($edit) { $active = SafeEnv($user['active'], 11, int); $code = SafeEnv($user['activate'], 11, int); } else { $active = '1'; $code = ''; } if ($editStatus) { $activate = $_POST['activate']; $lastactivate = 'manual'; if ($active == '0' && $code != '') { $lastactivate = 'mail'; } elseif ($active == '1' && $code == '') { $lastactivate = 'auto'; } if ($activate != $lastactivate) { switch ($activate) { case 'manual': $active = '0'; $code = ''; $SendActivation = false; break; case 'auto': $active = '1'; $code = ''; $SendActivation = false; break; case 'mail': $active = '0'; $code = GenRandomString(8, 'qwertyuiopasdfghjklzxcvbnm'); $SendActivation = true; break; } } } if ($edit) { $access = SafeEnv($user['type'], 11, int); $user_type = SafeEnv($user['access'], 11, int); } else { $access = '2'; $user_type = '-1'; } if ($editType && $_POST['status'] != 'member') { $access = '1'; $user_type = SafeEnv($_POST['status'], 11, int); } $reg_date = time(); $last_visit = time(); $ip = getip(); $points = 0; $visits = 0; if ($SendActivation) { UserSendActivationMail($nik_name, $email, $login, $pass, $code, $reg_date); } elseif (!$edit) { UserSendEndRegMail($email, $nik_name, $login, $pass, $reg_date); } if (!$edit) { $values = Values('', $login, $pass2, $nik_name, $real_name, $age, $email, $hide_email, $city, $icq, $homepage, $gmt, $avatar, $about, $server_news, $reg_date, $last_visit, $ip, $points, $visits, $active, $code, $access, $user_type, $a_personal, serialize(array())); System::database()->Insert('users', $values); } else { $set = "`login`='{$login}',`email`='{$email}',`hideemail`='{$hide_email}',`name`='{$nik_name}'," . "`truename`='{$real_name}',`age`='{$age}',`url`='{$homepage}',`icq`='{$icq}',`city`='{$city}'," . "`timezone`='{$gmt}'" . ($updateAvatar == true ? ",`avatar`='{$avatar}',`a_personal`='{$a_personal}'" : '') . "," . "`about`='{$about}',`servernews`='{$server_news}'" . ($pass != '' ? ",`pass`='{$pass2}'" : '') . ",`type`='{$access}'," . "`access`='{$user_type}',`active`='{$active}',`activate`='{$code}'"; System::database()->Update('users', $set, "`id`='" . $id . "'"); System::user()->UpdateMemberSession(); UpdateUserComments($id, $id, $nik_name, $email, $hide_email, $homepage); } if (count($errors) > 0) { $text = 'Аккаунт сохранен, но имели место следующие ошибки:<br /><ul>'; foreach ($errors as $error) { $text .= '<li>' . $error; } $text .= '</ul>'; AddTextBox('Внимание', $text); } else { // Очищаем кэш пользователей System::cache()->Delete(system_cache, 'users'); if (!$editProfile) { GO(ADMIN_FILE . '?exe=' . $back_link); } else { System::admin()->AddCenterBox('Редактирование профиля'); System::admin()->Highlight('Ваш профиль сохранён, обновите страницу.'); } } }
function AdminsDelete() { $userid = SafeEnv($_GET['id'], 11, int); System::database()->Select('users', "`id`='" . $userid . "' and `type`='1'"); $user = System::database()->FetchRow(); if (groupIsSystem(SafeEnv($user['access'], 11, int)) && GetSystemAdminsCount() <= 1) { System::admin()->AddCenterBox('Ошибка'); System::admin()->HighlightError('Нельзя удалить последнего системного администратора.'); return; } if (isset($_GET['ok']) && $_GET['ok'] == '1') { // Удалить $id = SafeEnv($_GET['id'], 11, int); if (!isset($_POST['del_comments'])) { System::database()->Select('users', "`id`='{$id}'"); if (System::database()->NumRows() > 0) { $suser = System::database()->FetchRow(); UpdateUserComments($id, '0', SafeEnv($suser['name'], 50, str), SafeEnv($suser['email'], 50, str), SafeEnv($suser['hideemail'], 1, bool), SafeEnv($suser['url'], 250, str)); } } else { DeleteAllUserComments($id); } System::database()->Delete('users', "`id`='{$id}' and `type`='1'"); System::cache()->Delete(system_cache, 'users'); Audit('Администраторы: Удаление администратора "' . $user['name'] . '"'); GO(ADMIN_FILE . '?exe=admins'); } elseif (isset($_GET['ok']) && $_GET['ok'] == '2') { // Сделать пользователем System::database()->Update('users', "type='2',access='-1'", "`id`='" . SafeEnv($_GET['id'], 11, int) . "' and `type`='1'"); System::cache()->Delete(system_cache, 'users'); Audit('Администраторы: "' . $user['name'] . '" разжалован в пользователи'); GO(ADMIN_FILE . '?exe=admins'); } else { System::admin()->AddJS(' AjaxDeleteAdmin = function(){ var del = $("#del_comments:checked").val(); if(del == null){ del = "0"; } Admin.LoadPage("' . ADMIN_FILE . '?exe=admins&a=deladmin&id=' . $userid . '&ok=1&del_comments="+del, undefined, "Удаление"); }; AjaxAdminSetToUser = function(){ Admin.LoadPage("' . ADMIN_FILE . '?exe=admins&a=deladmin&id=' . $userid . '&ok=2"); }; '); AddCenterBox('Удаление администратора'); $Text = 'Что вы хотите сделать с администратором "' . SafeDB($user['name'], 255, str) . '"?'; $Text .= '<br /><br />' . System::admin()->Check('del_comments', '1', false, 'id="del_comments"') . '<label for="del_comments" style="cursor: pointer;">Удалить все комментарии этого пользователя</label><br /><br />' . System::admin()->SpeedButton('Отмена', 'javascript:history.go(-1)', 'images/admin/cancel.png', false, true) . ' ' . System::admin()->SpeedConfirmJs('Удалить', 'AjaxDeleteAdmin();', 'images/admin/delete.png', '', true) . ' ' . System::admin()->SpeedConfirmJs('Сделать пользователем', 'AjaxAdminSetToUser();', 'images/user_green.png', '', true); System::admin()->Highlight($Text); } }