<?php
    require_once('call_flow_functions.php');
    header("content-type: text/xml");
    $good_bye = defalt_voice_message("good_bye.wav");

    // Safe cast input to integer to avoid malicious strings
    $call_pin = isset($_REQUEST['call_pin']) ? intval($_REQUEST['call_pin']) : null;
    echo '<?xml version="1.0" encoding="UTF-8"?>';

    if ($call_pin === 2) {
        echo "<Response>";
        echo "<Gather input='dtmf' action='handle_data.php?caller_code=1' method='POST' timeout='20' numDigits='4'>";
        echo "<Say>Your code is wrong, Please try again</Say>";
        echo "</Gather>";

        echo $good_bye;
        echo "<Hangup/>";
        echo "</Response>";    
    } else {
        echo "<Response>";
        echo "<Gather input='dtmf' action='handle_data.php?check_code=1' method='POST' timeout='20' numDigits='4'>";
        echo "<Say>Your code is wrong, Please try again</Say>";
        echo "</Gather>";
        echo $good_bye;
        echo "<Hangup/>";
        echo "</Response>";    
    }
?>
