<?

include '../../config.php';
include '../../func.php';
head();


$id = num($_GET['id']);
$vote = mysql_fetch_assoc(mysql_query("SELECT * FROM `votes` WHERE `id` = '".$id."'"));

if ( empty( $vote['id'] ) ) {
    
    echo head . "<b>Ошибка</b>" . div;  
    echo link2 . 'Опрос не найден' . div;
    pod_navig();
    foot();
    exit();
    
}

if ( isset($_POST['submit']) ) {
    
    $nazv = html($_POST['name']);
    $vopros = html($_POST['vopros']);
    $v_1 = html($_POST['v1']);
    $v_2 = html($_POST['v2']);
    $v_3 = html($_POST['v3']);
    $v_4 = html($_POST['v4']);
    $v_5 = html($_POST['v5']);

    $result = mysql_query("UPDATE `votes` SET `nazv` = '".$nazv."', `vopros` = '".$vopros."', `v_1` = '".$v_1."',`v_2` = '".$v_2."',`v_3` = '".$v_3."', `v_4` = '".$v_4."',`v_5` = '".$v_5."' WHERE `id` = '".$id."'");
    if ( $result != NULL ) {
        
        header('Location: index.php?mod=vote_edit&result=good');
        
    } else {
        
        header('Location: index.php?mod=vote_edit&result=error');
        
    }    
    
    
}
echo '<form action="vote_edit.php?id='.$id.'" method="post" name="form">';
echo link2 . '
Название:<br/ ><textarea id="tarea" name="name" cols="30" rows="5" style="width: 99%;">'.$vote['nazv'].'</textarea><br/ ><br/ >
Вопрос:<br/ ><textarea id="tarea" name="vopros" cols="30" rows="5" style="width: 99%;">'.$vote['vopros'].'</textarea><br/ ><br/ >

1. <br/ ><textarea id="tarea" name="v1" cols="30" rows="5" style="width: 99%;">'.$vote['v_1'].'</textarea><br/ >
2. <br/ ><textarea id="tarea" name="v2" cols="30" rows="5" style="width: 99%;">'.$vote['v_2'].'</textarea><br/ >
3. <br/ ><textarea id="tarea" name="v3" cols="30" rows="5" style="width: 99%;">'.$vote['v_3'].'</textarea><br/ >
4. <br/ ><textarea id="tarea" name="v4" cols="30" rows="5" style="width: 99%;">'.$vote['v_4'].'</textarea><br/ >
5. <br/ ><textarea id="tarea" name="v5" cols="30" rows="5" style="width: 99%;">'.$vote['v_5'].'</textarea><br/ >
' . div;
echo link2 . '<input name="submit" type="submit" class="button" value="Сохранить" /></form>' . div;