View file foto/func/albums.edit.php

File size: 6.05Kb
<?php 

only_reg();
$action = (isset($gallery_id) ? 'edit' : 'create');

if ($action == 'create') {
    $gallery = array('id' => 0, 'name' => '', 'opis' => '', 'privat' => 0, 'privat_komm' => 0, 'pass' => '');
}

if ($action == 'edit' && (!user_access('foto_foto_edit') && $ank['id'] != $user['id'])) {
    header('Location: ?'); 
    exit;
}

if (isset($_POST['ok'])) {
    
    $gallery['name'] = $_POST['name'];
    $gallery['opis'] = $_POST['msg'];
    $gallery['privat'] = (int) $_POST['privat'];
    $gallery['privat_komm'] = (int) $_POST['privat_komm'];
    $gallery['pass'] = $_POST['pass'];
    
    if (strlen2($gallery['name']) > 64) {
        $err[] = 'Название слишком длинное';
    } elseif (strlen2($gallery['name']) < 2) {
        $err[] = 'Название слишком короткое';
    }
    
    if (strlen2($gallery['opis']) > 512) {
        $err[] = 'Описание слишком длинное';
    }
    
    if ($gallery['privat'] == 3) {
        if (strlen2($gallery['pass']) > 12) {
            $err[] = 'Пароль слишком длинный';
        } elseif (strlen2($gallery['pass']) < 3) {
            $err[] = 'Пароль слишком короткий';
        }
    }
    
    if ($gallery['privat'] > 3 || $gallery['privat'] < 0) {
        $gallery['privat'] = 0;
    }
    
    if ($gallery['privat_komm'] > 3 || $gallery['privat_komm'] < 0) {
        $gallery['privat_komm'] = 0;
    }
    
    if (!isset($err)) {
        if ($action == 'edit') {
            mysql_query("UPDATE `gallery` SET `name` = '" . my_esc($gallery['name']) . "', 
                              `privat` = '" . $gallery['privat'] . "', `privat_komm` = '" . $gallery['privat_komm'] . "', 
                              `pass` = '" . my_esc($gallery['pass']) . "', `opis` = '" . my_esc($gallery['opis']) . "' 
                         WHERE `id` = '" . $gallery_id . "' LIMIT 1");
                         
            if ($user['id'] != $ank['id'])
                admin_log('Фотогалерея', 'Фотографии', 'Параметры альбома пользователя [url=/id' . $ank['id'] . ']' . $ank['nick'] . '[/url]');
        } 
        
        else {
            mysql_query("INSERT INTO `gallery` (`opis`, `time_create`, `id_user`, `name`, `time`, `pass`, `privat`, `privat_komm`) 
                     VALUES('" . my_esc($gallery['opis']) . "', '$time', '$user_id', '" . my_esc($gallery['name']) . "', '$time', 
                     '" . my_esc($gallery['pass']) . "', '" . $gallery['privat'] . "', '" . $gallery['privat_komm'] . "')"); 
            $gallery_id = mysql_insert_id();
        } 
        
        $_SESSION['message'] = ($action == 'edit' ? 'Изменения успешно приняты' : 'Фотоальбом успешно создан');
        header('Location: ?'); 
        exit;
    }
}

$set['title'] = $ank['nick'].' - '. ($action == 'edit' ? 'Параметры фотоальбома' : 'Новый фотоальбом');
include_once H.'sys/inc/thead.php';
title();
aut();
err();
?>
<div class="foot">
  <img src="/style/icons/str2.gif"> 
  <a href="/info.php?id=<?php echo $ank['id']; ?>"><?php echo $ank['nick']; ?></a> | 
  <a href="/foto/<?php echo $ank['id']; ?>/">Фотоальбомы</a> | 
  <?php if ($action == 'edit') { ?>
    <a href="/foto/<?php echo $ank['id']; ?>/<?php echo $gallery_id; ?>/"><?php echo text($gallery['name']); ?></a> | 
  <?php } ?>
  <b><?php echo ($action == 'edit' ? 'Параметры' : 'Создать'); ?></b>
</div>

<form action="?func=albums.edit" method="post" class="mess albums_edit">
  <div>
    Название альбома:<br />
    <input type="text" name="name" value="<?php echo text($gallery['name']); ?>" /><br />
  </div>

  <div>
    <?php 
    $insert = text($gallery['opis']); 
    
    if (is_file(H.'style/themes/'.$set['set_them'].'/altername_post_form.php')) {
        include_once H.'style/themes/'.$set['set_them'].'/altername_post_form.php';
    } else {
        echo $tPanel . '<textarea name="msg">' . $insert . '</textarea><br />';
    }
    ?>
  </div>

  <div>
    Могут смотреть:<br />
    <label>
      <input name="privat" type="radio" <?php echo ($gallery['privat'] == 0 ? ' checked="checked"' : null); ?> value="0" />
      <img src="/style/icons/status_all.png" /> Все
    </label>
    
    <label>
      <input name="privat" type="radio" <?php echo ($gallery['privat'] == 1 ? ' checked="checked"' : null); ?> value="1" />
      <img src="/style/icons/status_friends.png" /> Друзья
    </label>
    
    <label>
      <input name="privat" type="radio" <?php echo ($gallery['privat'] == 2 ? ' checked="checked"' : null); ?> value="2" />
      <img src="/style/icons/status_me.png" /> Только я
    </label>
    
    <label>
      <input name="privat" type="radio" <?php echo ($gallery['privat'] == 3 ? ' checked="checked"' : null); ?> value="3" />
      <img src="/style/icons/status_password.png" /> Только по паролю: 
      <input type="text" name="pass" value="<?= text($gallery['pass'])?>" />
    </label>
  </div>
  
  <div>
    Могут комментировать:<br />
    <label>
      <input name="privat_komm" type="radio" <?php echo ($gallery['privat_komm'] == 0 ? ' checked="checked"' : null); ?> value="0" />
      <img src="/style/icons/status_all.png" /> Все
    </label>
    
    <label>
      <input name="privat_komm" type="radio" <?php echo ($gallery['privat_komm'] == 1 ? ' checked="checked"' : null); ?> value="1" />
      <img src="/style/icons/status_friends.png" /> Друзья
    </label>
    
    <label>
      <input name="privat_komm" type="radio" <?php echo ($gallery['privat_komm'] == 2 ? ' checked="checked"' : null); ?> value="2" />
      <img src="/style/icons/status_me.png" /> Только я
    </label>
  </div>
  
  <input class="submit" type="submit" value="<?php echo ($action == 'edit' ? 'Сохранить' : 'Создать'); ?>" name="ok" />
</form>