<?php

/**
 * @page encoder_decoder_base_64.php
 * @brief Page qui encode et décode du base 64
 *
 * @author hughes monget
 * @see http://monget.com/
 */

$str_texte '';
$str_code  '';

if (isset(
$_REQUEST['texte']) && is_string($_REQUEST['texte']) && strlen($_REQUEST['texte'])
    && isset(
$_REQUEST['bouton']) && is_string($_REQUEST['bouton']))
{
    
$str_texte $_REQUEST['texte'];
    if (
get_magic_quotes_gpc())
    {
        
$str_texte stripslashes($str_texte);
    }

    switch (
$_REQUEST['bouton'])
    {
        case 
'Encoder':
                
$str_code = @base64_encode($str_texte);
            break;
        case 
'Décoder':
                
$str_code = @base64_decode($str_texte);
            break;
        default: break;
    }

}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title>Encoder ou décoder en base 64</title>
        <style type="text/css">
        <!--
        body *
        {
            font-family: monospace;
            font-size: 8pt;
        }

        textarea
        {
            height: 200px;
            width: 600px;
        }
        form
        {
            margin: 0;
        }
        div
        {
            margin: 0 0 5px 0;
        }
        -->
        </style>
        <script type="text/javascript">
        <!--;
            function on_load()
            {
                if (document && document.getElementById)
                {
                    var obj_input = document.getElementById('texte');
                    if (obj_input && obj_input.focus)
                    {
                        obj_input.focus();
                    }
                }
            }
        //-->
        </script>
    </head>
    <body onload="on_load();">
        <form method="post" action="">
            <div>
                <textarea id="texte" name="texte" rows="20" cols="80"><?php echo htmlspecialchars($str_texteENT_QUOTES); ?></textarea>
            </div>
            <div>
                <input type="submit" class="submit" name="bouton" value="Encoder" />
                <input type="submit" class="submit" name="bouton" value="Décoder" />
            </div>
        </form>
<?php
if ($str_code)
{
    echo 
'<div><textarea rows="20" cols="80" onclick="this.select();">',htmlspecialchars($str_codeENT_QUOTES),'</textarea></div>';
}

echo 
'<hr />';
highlight_file(__FILE__);

?>
    </body>
</html>