<?php
    if(!$this->showForm) return;

    if(isset($this->agency)){
        $update = true;
        $a = $this->agency;
    }else{
        $update = false;
        $a = null;
    }
?>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>

<form action="" method="post" enctype="multipart/form-data" >
    <fieldset>
    <legend>Informations</legend>
    <div>
            <input type="hidden" readonly="" id="uid" name="uid">
    </div>
    <div>
        <input type="hidden" readonly="" id="id" name="id">
    </div>
        <div>
            <label for="login">Login</label>
            <input type="text" id="login" name="login">
        </div>
        <div>
            <label for="pwd">Password</label>
            <input type="text" id="pwd" name="pwd">
        </div>
        <div>
            <label for="name">nom agence</label>
            <input type="text" id="name" name="name">
        </div>
    <div>
        <label for="email">email</label>
        <input type="text" id="email" name="email">
    </div>
    <div>
        <label for="phone">téléphone</label>
        <input type="text" id="phone" name="phone">
    </div>
    <div>
        <label for="address">adresse</label>
        <input type="text" id="address" name="address">
    </div>
    <div>
        <label for="cp">code postal</label>
        <input type="text" id="cp" name="cp">
    </div>
        <div>
            <label for="short_description">description fr</label>
            <input type="text" id="short_description_fr" name="short_description_fr">
        </div>


        <div>
            <label for="short_description_nl">description NL</label>
            <input type="text" id="short_description_nl" name="short_description_nl">
        </div>

    <div>
        <label for="website">Site internet</label>
        <input type="text" id="website" name="website">
    </div>



        <div>
            <label for="custom_url">Custom Url</label>
            <input type="text" id="custom_url" name="custom_url">
        </div>
        <div>
            <label for="seerus_key">Clé seerus</label>
            <input type="text" id="seerus_key" name="seerus_key">
        </div>
    <div>
        <label for="seerus_secret">Clé secrète seerus</label>
        <input type="text" id="seerus_secret" name="seerus_secret">
    </div>
        <div>
            <label for="seerus_token">Dashboard Token</label>
            <input type="text" id="seerus_token" name="seerus_token">
        </div>
</fieldset>


    <input style="display:block" type="file" name="logo" id="logo">


    <input type="submit" value="Create">
    <div class="result"></div>

</form>



<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
<script>
    $("form").submit(function(e){
        e.preventDefault();

        var form = e.target,
            fd = new FormData( form );

        if ($('#logo')[0].length){
            $.each( $('#logo')[0].files, function(key, value)
            {
                fd.append(key, value);
            });
        }



        $.ajax({
            url : form.action,
            type : 'POST',
            processData: false,
            contentType: false,
            data : fd,
            success : function(response){
                var r = JSON.parse(JSON.stringify(response));

                if (r.success) $('.result').text('Done !');
                else $('.result').text(r.message);
            }
        });

        return false;
    })
</script>