Файл: modules/user/edit.php
Строк: 198
<?php
/****
* @package LiveCMS
* @link livecms.org
* @author MyZik
* @version See attached file VERSION.txt
* @license See attached file LICENSE.txt
* @copyright Copyright (C) LiveCMS Development Team
****/
ob_start();
$lang_pe = load_lng('profile_edit'); // Подключаем файл языка
$title = $lang_pe['edit_profile']; // Заголовок страницы
$module = 'edit'; // Модуль
  /**
    * Проверка наличия авторизации
  **/
  if (!isset($user)) {
    require_once(HOME .'/incfiles/header.php');
echo '<div class="error">' . $lang['only_users'] . '</div>';
    echo '<div class="home">' .
    '<img src="/design/themes/' . $set_user['theme'] . '/images/back.png" alt="" /> <a href="/index.php">' . $lang['back'] . '</a>' .
    '</div>';
    require_once(HOME .'/incfiles/footer.php');
      }
  /**
    * Если задан верный параметр, определяем ИД юзера, в противном случае — свой ИД
  **/
  if (isset($_GET['id']))
    $ID = intval($_GET['id']);
  else
    $ID = $user['id'];
        $profile = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $ID . "'")); // получаем данные пользователя
  /**
    * Если пытаемся редактировать чужой профиль, проверяем права доступа
  **/
  if (($ID != $user['id']) && ($user['rights'] < 8) || ($user['rights'] >= 8 && $user['rights'] < $profile['rights'])) {
    require_once(HOME .'/incfiles/header.php');
    echo '<div class="error">' . $lang_pe['error_rights'] . '</div>';
    require_once(HOME .'/incfiles/footer.php');
  }
    /**
      * Проверяем, верен ли заданный параметр
    **/
    if (isset($_GET['id']) && !is_numeric($_GET['id'])) {
      require_once(HOME .'/incfiles/header.php');
      echo '<div class="error">' . $lang['error_parameter'] . '</div>';
      require_once(HOME .'/incfiles/footer.php');
        }
  /**
    * Показываем разделы для редактирования
  **/
  if (!isset($_GET['act'])) {
    require_once(HOME .'/incfiles/header.php'); // подключаем шапку
    /**
      * Небольшая панель навигации
    **/
    echo '<div class="title"><a href="cabinet.php">' . $lang['my_cabinet'] . '</a> | <b>' . $lang_pe['edit_profile'] . ($ID != $user['id'] ? ' "' . $profile['login'] . '"' : '') . '</b></div>';
    echo '<div class="main">' .
    '<b>' . $lang_pe['change_section'] . '</b><br />' .
    '<img src="/design/themes/' . $set_user['theme'] . '/images/act.png" alt=">" /> <a href="?act=personal' . ($ID != $user['id'] ? '&id=' . $ID . '' : '') . '">' . $lang_pe['personal_data'] . '</a><br />' .
    '<img src="/design/themes/' . $set_user['theme'] . '/images/act.png" alt=">" /> <a href="?act=contacts' . ($ID != $user['id'] ? '&id=' . $ID . '' : ''). '">' . $lang_pe['contacts'] . '</a><br />' .
    (($user['rights'] >= 8) && $user['id'] != $ID && $user['rights'] > $profile['rights'] ? '<img src="/design/themes/' . $set_user['theme'] . '/images/act.png" alt=">" /> <a href="avatar.php?id=' . $ID . '">' . $lang_pe['avatar'] . '</a><br />' : '') .
    (($user['rights'] >= 8) && $user['id'] != $ID && $user['rights'] > $profile['rights'] ? '<img src="/design/themes/' . $set_user['theme'] . '/images/act.png" alt=">" /> <a href="photo.php?id=' . $ID . '">' . $lang_pe['photo_profile'] . '</a><br />' : '') .
    (($user['rights'] >= 8) && $user['id'] != $ID && $user['rights'] > $profile['rights'] ? '<img src="/design/themes/' . $set_user['theme'] . '/images/act.png" alt=">" /> <a href="rank.php?id=' . $ID . '">' . $lang_pe['rank'] . '</a><br />' : '') .
    (($user['rights'] >= 8) && $user['id'] != $ID && $user['rights'] > $profile['rights'] ? '<img src="/design/themes/' . $set_user['theme'] . '/images/act.png" alt=">" /> <a href="settings.php?id=' . $ID . '">' . $lang_pe['settings'] . '</a><br />' : '') .
    (($user['id'] == $ID) || ($user['rights'] >= 7) && $user['rights'] > $profile['rights'] ? '<img src="/design/themes/' . $set_user['theme'] . '/images/act.png" alt=">" /> <a href="status.php?id=' . $ID . '">' . $lang_pe['status'] . '</a>' : '') .
    '</div>';
    require_once(HOME .'/incfiles/footer.php'); // подключаем ноги
  }
  /**
    * Редактирование личных данных
  **/
  if (isset($_GET['act']) && $_GET['act'] == 'personal') {
    require_once(HOME .'/incfiles/header.php'); // подключаем шапку
    /**
      * Небольшая панель навигации
    **/
    echo '<div class="title"><a href="edit.php' . ($ID != $user['id'] ? '&id=' . $ID . '' : '')  . '">' . $lang_pe['edit_profile'] . ($ID != $user['id'] ? ' "' . $profile['login'] . '"' : '') . '</a> | <b>' . $lang_pe['personal_data'] . '</b></div>';
    if (isset($_POST['submit'])) {
      $profile['name'] = isset($_POST['name']) ? input(mb_substr($_POST['name'], 0, 25)) : ''; // Имя
      $profile['lastname'] = isset($_POST['lastname']) ? input(mb_substr($_POST['lastname'], 0, 25)) : ''; // Фамилия
      $profile['live'] = isset($_POST['live']) ? input(mb_substr($_POST['live'], 0, 30)) : ''; // Место жительства
      $profile['dbirth'] = isset($_POST['dbirth']) ? num($_POST['dbirth']) : ''; // День рождения
      $profile['mbirth'] = isset($_POST['mbirth']) ? num($_POST['mbirth']) : ''; // Месяц рождения
      $profile['ybirth'] = isset($_POST['ybirth']) ? num($_POST['ybirth']) : ''; // Год рождения
      $profile['about'] = isset($_POST['about']) ? input(mb_substr($_POST['about'], 0, 600)) : ''; // Доп. информация
      /**
        * Проверяем формат даты рождения
      **/
      if ($profile['dbirth'] || $profile['mbirth'] || $profile['ybirth']) {
        if (($profile['dbirth'] > 31 || $profile['dbirth'] < 1) || ($profile['mbirth'] > 12 || $profile['mbirth'] < 1))
          $err[] = $lang_pe['error_birthday'];
             }
      /**
        * Минимальная длина имени
      **/
      if ($profile['name'] && strlen($profile['name']) < 2)
          $err[] = $lang_pe['error_strlen_name'];
      /**
        * Минимальная длина фамилии
      **/
      if ($profile['lastname'] &&strlen($profile['lastname']) < 2)
        $err[] = $lang_pe['error_strlen_lastname'];
      /**
        * Минимальная длина места жительства
      **/
      if ($profile['live'] && strlen($profile['live']) < 4)
        $err[] = $lang_pe['error_strlen_live'];
      /**
        * Минимальная длина доп. информации
      **/
      if ($profile['about'] && strlen($profile['about']) < 6)
        $err[] = $lang_pe['error_strlen_about'];
      /**
        * Если нет ошибок, заносим данные
      **/
      if (!isset($err)) {
        mysql_query("UPDATE `users` SET
           `name` = '" . $profile['name'] . "',
           `lastname` = '" . $profile['lastname'] . "',
           `dbirth` = '" . $profile['dbirth'] . "',
           `mbirth` = '" . $profile['mbirth'] . "',
           `ybirth` = '" . $profile['ybirth'] . "',
           `live` = '" . $profile['live'] . "',
           `about` = '" . $profile['about'] . "'
           WHERE `id` = '" . $ID . "' LIMIT 1");
       echo display_message($lang_pe['edit_success']);
           } else {
        echo error($err); // Выводим ошибки
          }
            }
      /**
        * Форма
      **/
      echo '<div class="main">' .
      '<form method="post" action="edit.php?act=personal' . ($ID != $user['id'] ? "&id=" . $ID . "" : "") . '">' .
      $lang_pe['your_name'] . '<br />' .
      '<input type="text" name="name" value="' . $profile['name'] . '" /><br />' . 
      $lang_pe['your_lastname'] . '<br />' .
      '<input type="text" name="lastname" value="' . $profile['lastname'] . '" /><br />' .
      $lang_pe['your_live'] . '<br />' .
      '<input type="text" name="live" value="' . $profile['live'] . '" /><br />' .
      $lang_pe['your_birthday'] . '<br />' .
      '<input type="text" name="dbirth" value="' . $profile['dbirth'] . '" size="3" /> <input type="text" name="mbirth" value="' . $profile['mbirth'] . '" size="3" /> <input type="text" name="ybirth" value="' . $profile['ybirth'] . '" size="6" /><br />' .
       $lang_pe['formate_birthday'] . '<br />' .
       $lang_pe['about'] . '<br />' .
       '<textarea name="about">' . $profile['about'] . '</textarea><br />' . $lang_pe['about_info'] . '<br />' .
       '<input type="submit" name="submit" value="' . $lang['save'] . '" />' .
       '</form></div>';
  require_once(HOME .'/incfiles/footer.php'); // подключаем ноги
    }
// Если был запрос на редактирование контактных данных, выводим
       if (isset($_GET['act']) && $_GET['act'] == 'contacts') {
require_once(HOME .'/incfiles/header.php'); // Подключаем шапку
    /**
      * Небольшая панель навигации
    **/
    echo '<div class="title"><a href="edit.php' . ($ID != $user['id'] ? '&id=' . $ID . '' : '')  . '">' . $lang_pe['edit_profile'] . ($ID != $user['id'] ? ' "' . $profile['login'] . '"' : '') . '</a> | <b>' . $lang_pe['contacts'] . '</b></div>';
   // Сохраняем данные
            if (isset($_POST['submit'])) {
              // Данные
              $email = isset($_POST['email']) ? input(mb_substr($_POST['email'], 0, 45)) : '';
              $icq = isset($_POST['icq']) ? num($_POST['icq']) : 0;
                   $skype = isset($_POST['skype']) ? input(mb_substr($_POST['skype'], 0, 40)) : '';
                    $jabber = isset($_POST['jabber']) ? input(mb_substr($_POST['jabber'], 0, 35)) : '';
                    $site = isset($_POST['site']) ? input(mb_substr($_POST['site'], 0, 35)) : '';
     // Проверка на ошибки
         if (($icq && ($icq > 999999999 || $icq < 10000)) || !is_numeric($icq))
               $err[] = $lang_pe['error_icq'];
         if ($email && !preg_match('#^[A-z0-9-._]+@[A-z0-9]{2,}.[A-z]{2,4}$#ui', $email))
               $err[] = $lang_pe['error_email'];
           if (!isset($err)) {
      mysql_query("UPDATE `users` SET
        `email` = '" . $email . "',
        `icq` = '" . $icq . "',
        `skype` = '" . $skype . "',
        `jabber` = '" . $jabber . "',
        `site` = '" . $site . "'
        WHERE `id` = '" . $ID . "' LIMIT 1");
           header('Refresh: 0; URL=edit.php?act=contacts' . ($ID != $user['id'] ? "&id=" . $ID . "" : "") . '');
           }
             echo '<div class="sohr">' . $lang_pe['edit_success'] . '</div>';
            }
     echo error($err); // Выводим ошибки
          // Форма ;)
              echo '<div class="main">
              <form method="post" action="edit.php?act=contacts' . ($ID != $user['id'] ? "&id=" . $ID . "" : "") . '">' .
              $lang_pe['your_email'] . '<br />' .
              '<input type="text" name="email" value="' . $profile['email'] . '" /><br />' . $lang_pe['email_info'] . '<br />' .
              $lang_pe['your_icq'] . '<br />' .
              '<input type="text" name="icq" value="' . $profile['icq'] . '" /><br />' .
              $lang_pe['your_skype'] . '<br />' .
              '<input type="text" name="skype" value="' . $profile['skype'] . '" /><br />' .
              $lang_pe['your_jabber'] . '<br />' .
              '<input type="text" name="jabber" value="' . $profile['jabber'] . '" /><br />' .
              $lang_pe['your_site'] . '<br />' .
              '<input type="text" name="site" value="' . $profile['site'] . '" /><br />' . $lang_pe['site_info'] . '<br />' .
               '<input type="submit" name="submit" value="' . $lang['save'] . '" />' .
               '</form></div>';
// Подключаем  ноги
require_once(HOME .'/incfiles/footer.php');
}
ob_end_flush();
?>