View file chat/rooms.edit.php

File size: 2.81Kb
<?php
#-*- coding: utf-8 -*-
#Name:     chatRooms v1.0 alpha
#Author:    Nugroho Adi Prayatso
#e-mail:     hongoaoi@gmail.com
#Web:        frendzzi.tk

include_once '../sys/inc/start.php';
$doc = new document(4);
$doc->title = 'Rooms settings';

if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    header('Refresh: 1; url=./');
    $doc->err('Error when selecting');
    exit;
}
##

$id_room = (int) $_GET['id'];

$q = mysql_query("SELECT * FROM `chat_rooms` WHERE `id` = '$id_room'");

if (!mysql_num_rows($q)) {
    header('Refresh: 1; url=./');
    $doc->err('Room not found');
    exit;
}
##
$room = mysql_fetch_assoc($q);

if (isset($_POST['save'])) {
    if (isset($_POST['name']) && isset($_POST['opis'])) {
        $name = text::for_name($_POST['name']);
        $opis = text::input_text($_POST['opis']);

        if ($name && $name != $room['name']) {
            $room['name'] = $name;
            mysql_query("UPDATE `chat_rooms` SET `name` = '" . my_esc($room['name']) . "' WHERE `id` = '$room[id]' LIMIT 1");
            $doc->msg(__('Name has been edited'));
        }

        if ($opis != $room['opis']) {
            $room['opis'] = $opis;
            mysql_query("UPDATE `chat_rooms` SET `opis` = '" . my_esc($room['opis']) . "' WHERE `id` = '$room[id]' LIMIT 1");
            $doc->msg('Room description has been edited');

        }
    }

    if (isset($_POST['pos'])) { // позиция
        $pos = (int) $_POST['pos'];
        if ($pos != $room['pos']) {

            $room['pos'] = $pos;
            mysql_query("UPDATE `chat_rooms` SET `pos` = '$room[pos]' WHERE `id` = '$room[id]' LIMIT 1");
            $doc->msg('Position has been edited');
        }
    }

}

$doc->title = 'Settings';

$smarty = new design();
$smarty->assign('method', 'post');
$smarty->assign('action', "?id=$room[id]&amp;" . passgen() . (isset($_GET['return']) ? '&amp;return=' . urlencode($_GET['return']) : null));
$elements = array();

$elements[] = array('type' => 'input_text', 'title' => 'Name', 'br' => 1, 'info' => array('name' => 'name', 'value' => $room['name']));

$elements[] = array('type' => 'textarea', 'title' => 'Description', 'br' => 1, 'info' => array('name' => 'opis', 'value' => $room['opis']));

$elements[] = array('type' => 'input_text', 'title' => 'Position', 'br' => 1, 'info' => array('name' => 'pos', 'value' => $room['pos']));

$elements[] = array('type' => 'submit', 'br' => 0, 'info' => array('name' => 'save', 'value' => 'Save'));
$smarty->assign('el', $elements);
$smarty->display('input.form.tpl');


$doc->act('Delete selected room', 'chat.delete_room.php?id=' . $room['id']);

if (isset($_GET['return']))
    $doc->ret('Back', for_value($_GET['return']));
else
    $doc->ret('Back', 'rooms.post.php?id=' . $room['id']);

$doc->ret('Chat', './');
?>