<?php

$day = $this->day;

if(!is_null($this->agency)){

    $a = $this->agency;



    $getter = 'get' . ucfirst(strtolower($day)) . '_am_start';

    if(method_exists($a, $getter )){

        $am_st = $a->$getter();

    }



    $getter = 'get' . ucfirst(strtolower($day)) . '_am_end';

    if(method_exists($a, $getter )){

        $am_end = $a->$getter();

    }



    $getter = 'get' . ucfirst(strtolower($day)) . '_pm_start';

    if(method_exists($a, $getter )){

        $pm_st = $a->$getter();

    }



    $getter = 'get' . ucfirst(strtolower($day)) . '_pm_end';

    if(method_exists($a, $getter )){

        $pm_end = $a->$getter();

    }

}



?>



<fieldset>

    <legend><?= $day ?></legend>



    <label for="<?= $day ?>_is_open">Ouvert</label>

    <select name="<?= $day ?>_is_open" class="day-is-open" id="<?= $day ?>_is_open">

        <option value="1">oui</option>

        <option value="0" >non</option>

        <option value="2">sur rdv</option>

    </select>



    <label for="<?= $day ?>_has_lunch" class="<?= $day ?> open">Pause de midi</label>

    <select name="<?= $day ?>_has_lunch" class="day-has-lunch <?= $day ?> open" id="<?= $day ?>_has_lunch">

        <option value="1">non</option>

        <option value="0" selected>oui</option>

    </select>



    <div style="display: inline-block; vertical-align: top" class="<?= $day ?> open am">

        <span>AM</span>

        <input type="checkbox" id="<?= $day ?>_am_rdv"><span>sur rdv</span>

        <input type="text" name="<?= $day ?>_am_start" id="<?= $day ?>_am_start" value="<?= $am_st ?>">

        <input type="text" name="<?= $day ?>_am_end" id="<?= $day ?>_am_end" value="<?= $am_end ?>">

    </div>



    <div style="display: inline-block; vertical-align: top" class="<?= $day ?> open pm">



        <span>PM</span>

        <input type="checkbox" id="<?= $day ?>_pm_rdv"><span>sur rdv</span>

        <input type="text" name="<?= $day ?>_pm_start" id="<?= $day ?>_pm_start" value="<?= $pm_st ?>">

        <input type="text" name="<?= $day ?>_pm_end" id="<?= $day ?>_pm_end"  value="<?= $pm_end ?>">

    </div>



</fieldset>



<script>

    $('#<?= $day ?>_is_open').on('change', function() {

        switch(this.value){

            case '0' : // ferm�

                $('#<?= $day ?>_am_start').val(0);

                $('#<?= $day ?>_am_end').val(0);

                $('#<?= $day ?>_pm_start').val(0);

                $('#<?= $day ?>_pm_end').val(0);

                $('.<?= $day ?>.open').hide();

                break;

            case '2' : // sur rdv

                $('#<?= $day ?>_am_start').val(-1);

                $('#<?= $day ?>_am_end').val(-1);

                $('#<?= $day ?>_pm_start').val(-1);

                $('#<?= $day ?>_pm_end').val(-1);

                $('.<?= $day ?>.open').hide();

                break;

            case '1' : // ouvert

                $('#<?= $day ?>_am_start').val('');

                $('#<?= $day ?>_am_end').val('');

                $('#<?= $day ?>_pm_start').val('');

                $('#<?= $day ?>_pm_end').val('');

                $('.<?= $day ?>.open').show();



                break;



        }

    });



    $('#<?= $day ?>_has_lunch').on('change', function() {

        switch(this.value){

            case '1' : // lunch

                $('#<?= $day ?>_am_end').val(-3).hide();

                $('#<?= $day ?>_pm_start').val(-3).hide();

                $('.<?= $day ?>.open span').hide();

                $('.<?= $day ?>.open input[type="checkbox"]').hide();

                break;

            case '0' : // pas de lunch

                $('#<?= $day ?>_am_end').val('').show();

                $('#<?= $day ?>_pm_start').val('').show();

                $('.<?= $day ?>.open span').show();

                $('.<?= $day ?>.open input[type="checkbox"]').show();

                break;

        }



    });



    $('#<?= $day ?>_am_rdv').click (function(){

        if ($(this).is(':checked')){ // rdv matin

            $('#<?= $day ?>_am_start').val(-1).hide();

            $('#<?= $day ?>_am_end').val(-1).hide();

        }else{ //ouvert pm

            $('#<?= $day ?>_am_start').val('').show();

            $('#<?= $day ?>_am_end').val('').show();

        }

    });



    $('#<?= $day ?>_pm_rdv').click (function(){

        if ($(this).is(':checked')){ // rdv pm

            $('#<?= $day ?>_pm_start').val(-1).hide();

            $('#<?= $day ?>_pm_end').val(-1).hide();

        }else{ // ouvert pm

            $('#<?= $day ?>_pm_start').val('').show();

            $('#<?= $day ?>_pm_end').val('').show();

        }

    });

</script>