<?php
session_start();
include ('private/mysql.php');
include ('tmp/head.php');




switch($sd){
default:
if($uid=='68' or $uid=='7'){
    echo "<a href=?sd=add>Создать</a><hr>";
}

$q = mysql_query("SELECT * FROM `wiki` ORDER BY `id` DESC");

echo "<ul class='list_page'><div class='linem'></div>";

While($w = mysql_fetch_assoc($q)){
    
    echo "<li><a href='?sd=view&id=$w[id]'>$w[name]</li></li>";
    
}

echo "</ul><div class='linem2'></div>";

break;

case 'view':
$q = mysql_query("SELECT * FROM `wiki` WHERE `id`='$id'");
$e = mysql_num_rows($q);
if($e=='0'){
    header('Location: wiki.php');
    exit;
}
$w = mysql_fetch_assoc($q);

echo "<b>$w[name]</b><br>$w[text]<hr>← <a href='wiki.php'>назад</a>";

break;

case 'add':
if($uid!=='68' or $uid!=='7'){
    header('Location: wiki.php');
    exit;
}

if(empty($_POST['submit'])){
    
    echo "<form action='wiki.php?sd=add' method='post'>
    Название:<br>
    <input type='text' name='name' class='enter'><br>
    <textarea name='text' class='enter'></textarea><br>
    <input type='submit' name='submit' class='enter' value='Создать'></form>";
    
}else{
    
    $name = htmlspecialchars($_POST['name']);
    $text = htmlspecialchars($_POST['text']);
    
    mysql_query("INSERT INTO `wiki` SET `name`='$name',`text`='$text'");
    
    header('Location: wiki.php');
    exit;
    
}

break;


}
include ('tmp/foot.php');
?>