<?php

    $submit = getuserdata('submit');
    $actiune = getuserdata('actiune');
    $motto = getuserdata('motto', '');
    $oferta = getuserdata('oferta', '');
    $email_sugestii = getuserdata('email_sugestii', '');
    $email_comenzi = getuserdata('email_comenzi', '');
    $email_newsletter = getuserdata('email_newsletter', '');
    
    switch ($actiune)
    {
        case 'do_editare':
            if ($submit != 'Salvează')
            {
                header("Location: {$_SERVER['PHP_SELF']}?pagina=$pagina");
                exit;
            }
            $q = mysql_query("SELECT * FROM optiuni");
            if ($r = mysql_fetch_assoc($q))
            {
                mysql_query("UPDATE optiuni SET motto = '$motto', oferta = '$oferta', ".
                            "email_sugestii = '$email_sugestii', email_comenzi = '$email_comenzi', email_newsletter = '$email_newsletter'");
                $eroare = mysql_error();
            }
            else
            {
                mysql_query("INSERT INTO optiuni (motto, oferta, email_sugestii, email_comenzi, email_newsletter) ".
                            "VALUES ('$motto', '$oferta', '$email_sugestii', '$email_comenzi', '$email_newsletter')");
                $eroare = mysql_error();
            }
            if (!$eroare)
            {
                header("Location: {$_SERVER['PHP_SELF']}?pagina=$pagina");
                exit;
            }
    }
    writepagetitle();
    writepagetop();
    writeinfolayer();
    $q = mysql_query("SELECT * FROM optiuni");
    if ($r = mysql_fetch_assoc($q))
    {
        $motto = $r['motto'];
        $oferta = $r['oferta'];
        $email_sugestii = $r['email_sugestii'];
        $email_comenzi = $r['email_comenzi'];
        $email_newsletter = $r['email_newsletter'];
    }
    echo "<form action='{$_SERVER['PHP_SELF']}' method='POST'>";
    echo "<input type='hidden' name='pagina' value='$pagina'>";
    echo "<input type='hidden' name='actiune' value='do_editare'>";
    echo "<center><table class='formular'>";
    echo "<tr><th>Motto BizMedica:</th><td><input type='text' name='motto' value='$motto'></td></tr>";
    echo "<tr><th>Oferta BizMedica:</th><td><input type='text' name='oferta' value='$oferta'></td></tr>";
    echo "<tr><th>E-mail trimitere sugestii:</th><td><input type='text' name='email_sugestii' value='$email_sugestii'></td></tr>";
    echo "<tr><th>E-mail trimitere comenzi:</th><td><input type='text' name='email_comenzi' value='$email_comenzi'></td></tr>";
    echo "<tr><th>E-mail trimitere abonare newsletter:</th><td><input type='text' name='email_newsletter' value='$email_newsletter'></td></tr>";
    echo "<tr><td>&nbsp;</td><td class='butoane'>";
    echo "<input type='submit' name='submit' id='save' value='Salvează'>";
    echo "<input type='submit' name='submit' id='cancel' value='Anulează'>";
    echo "</td></tr></table></center></form>";
    writepagebottom();
?>