<?php
function getIfSet(&$value, $default = null)
{
    return isset($value) ? $value : $default;
}


require_once('config.php');

try {
    $image1 = ",";
    $var_arr = array($pms = getIfSet($_REQUEST['pms']), $methodid = getIfSet($_REQUEST['methodid']), $pharmacyname = getIfSet($_REQUEST['pharmacyname']), $qone = getIfSet($_REQUEST['qone']), $qtwo = getIfSet($_REQUEST['qtwo']),
        $qthree = getIfSet($_REQUEST['qthree']), $qfour = getIfSet($_REQUEST['qfour']), $qfive = getIfSet($_REQUEST['qfive']), $qsix = getIfSet($_REQUEST['qsix']), $qseven = getIfSet($_REQUEST['qseven']),
        $qeight = getIfSet($_REQUEST['qeight']), $qnine = getIfSet($_REQUEST['qnine']), $qten = getIfSet($_REQUEST['qten']), $qeleven = getIfSet($_REQUEST['qeleven']), $qtwelve = getIfSet($_REQUEST['qtwelve']), $qthirteen = getIfSet($_REQUEST['qthirteen']),
        $qfourteen = getIfSet($_REQUEST['qfourteen']), $qfifteen = getIfSet($_REQUEST['qfifteen']), $qsixteen = getIfSet($_REQUEST['qsixteen']), $qseventeen = getIfSet($_REQUEST['qseventeen']), $qeighteen = getIfSet($_REQUEST['qeighteen']),
        $qnineteen = getIfSet($_REQUEST['qnineteen']), $qtwenty = getIfSet($_REQUEST['qtwenty']), $qtwentyone = getIfSet($_REQUEST['qtwentyone']), $qtwentytwo = getIfSet($_REQUEST['qtwentytwo']), $qtwentythree = getIfSet($_REQUEST['qtwentythree']),
        $qtwentyfour = getIfSet($_REQUEST['qtwentyfour']), $qtwentyfive = getIfSet($_REQUEST['qtwentyfive']), $qtwentysix = getIfSet($_REQUEST['qtwentysix']), $qtwentyseven = getIfSet($_REQUEST['qtwentyseven']), $qtwentyeight = getIfSet($_REQUEST['qtwentyeight']),
        $qtwentynine = getIfSet($_REQUEST['qtwentynine']), $qthirty = getIfSet($_REQUEST['qthirty']), $qthirtyone = getIfSet($_REQUEST['qthirtyone']), $qthirtytwo = getIfSet($_REQUEST['qthirtytwo']), $datesigned = getIfSet($_REQUEST['datesigned']),
        $image1 = getIfSet($_REQUEST["signature"]), $qthirtythree = getIfSet($_REQUEST["qthirtythree"])

    );

//echo $image1;

    if ($pms == "kroll") {
        $data1 = array(
            'Pharmacy Name' => addslashes($pharmacyname),
            'PMS' => addslashes($pms),
            'Please select from one of the call flows below for your pharmacy\'s Phone IVR Rx refill call flow configuration:' => addslashes($qone),
            'Type of Printer:' => addslashes($qtwo),
            '(If thermal, please send us a picture of the label or receipt depending on where you want to print the card) is on file within their patient profile of your pharmacy' => addslashes($qthirtythree),
            'How many digits are in the Rx #\'s?' => addslashes($qthree),
            'Windows Store Admin Password' => addslashes($qfour),
            'Please send us a picture of a sample receipt with a barcode:' => $qseven,
            'Do you use original # on rx number?' => addslashes($qfive),
            'How many terminals do you have?' => addslashes($qsix),
            'What version of Kroll are you running?' => addslashes($qeight),
            'What P.O.S system do you use for barcode scanning?' => addslashes($qnine),
            'Is Amjay Software developing your pharmacy app?' => addslashes($qten),
            'For the feature of sending in a picture of a new Rx from your pharmacy App, where would you like the picture of the Rx to be sent to?' => addslashes($qeleven),
            'Fax Number OR Email Address' => addslashes($qtwelve),
            'Is there an IT department managing your main server access?' => addslashes($qfourteen),
            'Please provide the contact information for the IT department we should contact to get a team viewer to your main server when it\'s time to install the software' => '-',
            'IT company name:' => addslashes($qfifteen),
            'Contact person name' => addslashes($qsixteen),
            'Phone #' => addslashes($qseventeen),
            'Email' => addslashes($qeighteen),
            'Please indicate the pharmacy staff member we should contact to get a team viewer to your main server when it\'s time to install the software' => '-',
            'Name:' => addslashes($qtwenty),
            'Email:' => addslashes($qtwentyone),
            'Cell Phone' => addslashes($qtwentytwo),
            'Is the pharmacy main server shared with other locations (central server for multiple pharmacies)? Or is the pharmacy\'s main server used for this single pharmacy location only?' => addslashes($qtwentythree),
            'Please provide the contact info for the location/pharmacy where your central server resides?' => '-',
            'Location of Central Server' => addslashes($qtwentyfive),
            'Contact Person Name' => addslashes($qtwentysix),
            'Phone# of Contact' => addslashes($qtwentyseven),
            'Email of Contact' => addslashes($qtwentyeight),
            'Please submit a pharmacy logo:' => $qtwentynine,
            'Does your pharmacy have an existing website or will Amjay be developing one for you?' => addslashes($qthirty),
            'Website Domain' => addslashes($qthirtyone),
            'Provide recommendations for what they would like as a new domain):' => addslashes($qthirtytwo),
            'Sign Date' => addslashes($datesigned),
            'Signature' => $image1
        );
    } elseif ($pms == "pclicknexys") {
        $data1 = array(
            'Pharmacy Name' => addslashes($pharmacyname),
            'PMS' => addslashes($pms),
            'Please select from one of the call flows below for your pharmacy\'s Phone IVR Rx refill call flow configuration:' => addslashes($qone),
            'Type of Printer:' => addslashes($qtwo),
            '(If thermal, please send us a picture of the label or receipt depending on where you want to print the card) is on file within their patient profile of your pharmacy' => addslashes($qthirtythree),
            'How many digits are in the Rx #\'s?' => addslashes($qthree),
            'Windows Store Admin Password' => addslashes($qfour),
            'Please send us a picture of a sample receipt with a barcode:' => $qseven,
            'Do you use original # on rx number?' => addslashes($qfive),
            'How many terminals do you have?' => addslashes($qsix),
            'What P.O.S system do you use for barcode scanning?' => addslashes($qnine),
            'Is Amjay Software developing your pharmacy app?' => addslashes($qten),
            'For the feature of sending in a picture of a new Rx from your pharmacy App, where would you like the picture of the Rx to be sent to?' => addslashes($qeleven),
            'Fax Number OR Email Address' => addslashes($qtwelve),
            'Is there an IT department managing your main server access?' => addslashes($qfourteen),
            'Please provide the contact information for the IT department we should contact to get a team viewer to your main server when it\'s time to install the software' => '-',
            'IT company name:' => addslashes($qfifteen),
            'Contact person name' => addslashes($qsixteen),
            'Phone #' => addslashes($qseventeen),
            'Email' => addslashes($qeighteen),
            'Please indicate the pharmacy staff member we should contact to get a team viewer to your main server when it\'s time to install the software' => '-',
            'Name:' => addslashes($qtwenty),
            'Email:' => addslashes($qtwentyone),
            'Cell Phone' => addslashes($qtwentytwo),
            'Is the pharmacy main server shared with other locations (central server for multiple pharmacies)? Or is the pharmacy\'s main server used for this single pharmacy location only?' => addslashes($qtwentythree),
            'Please provide the contact info for the location/pharmacy where your central server resides?' => '-',
            'Location of Central Server' => addslashes($qtwentyfive),
            'Contact Person Name' => addslashes($qtwentysix),
            'Phone# of Contact' => addslashes($qtwentyseven),
            'Email of Contact' => addslashes($qtwentyeight),
            'Please submit a pharmacy logo:' => $qtwentynine,
            'Does your pharmacy have an existing website or will Amjay be developing one for you?' => addslashes($qthirty),
            'Website Domain' => addslashes($qthirtyone),
            'Provide recommendations for what they would like as a new domain):' => addslashes($qthirtytwo),
            'Sign Date' => addslashes($datesigned),
            'Signature' => $image1
        );
    } elseif ($pms == "fillware") {
        $data1 = array(
            'Pharmacy Name' => addslashes($pharmacyname),
            'PMS' => addslashes($pms),
            'Please select from one of the call flows below for your pharmacy\'s Phone IVR Rx refill call flow configuration:' => addslashes($qone),
            'Type of Printer:' => addslashes($qtwo),
            '(If thermal, please send us a picture of the label or receipt depending on where you want to print the card) is on file within their patient profile of your pharmacy' => addslashes($qthirtythree),
            'How many digits are in the Rx #\'s?' => addslashes($qthree),
            'Windows Store Admin Password' => addslashes($qfour),
            'Please send us a picture of a sample receipt with a barcode:' => $qseven,
            'Do you use original # on rx number?' => addslashes($qfive),
            'How many terminals do you have?' => addslashes($qsix),
            'What P.O.S system do you use for barcode scanning?' => addslashes($qnine),
            'Is Amjay Software developing your pharmacy app?' => addslashes($qten),
            'For the feature of sending in a picture of a new Rx from your pharmacy App, where would you like the picture of the Rx to be sent to?' => addslashes($qeleven),
            'Fax Number OR Email Address' => addslashes($qtwelve),
            'Is there an IT department managing your main server access?' => addslashes($qfourteen),
            'Please provide the contact information for the IT department we should contact to get a team viewer to your main server when it\'s time to install the software' => '-',
            'IT company name:' => addslashes($qfifteen),
            'Contact person name' => addslashes($qsixteen),
            'Phone #' => addslashes($qseventeen),
            'Email' => addslashes($qeighteen),
            'Please indicate the pharmacy staff member we should contact to get a team viewer to your main server when it\'s time to install the software' => '-',
            'Name:' => addslashes($qtwenty),
            'Email:' => addslashes($qtwentyone),
            'Cell Phone' => addslashes($qtwentytwo),
            'Is the pharmacy main server shared with other locations (central server for multiple pharmacies)? Or is the pharmacy\'s main server used for this single pharmacy location only?' => addslashes($qtwentythree),
            'Please provide the contact info for the location/pharmacy where your central server resides?' => '-',
            'Location of Central Server' => addslashes($qtwentyfive),
            'Contact Person Name' => addslashes($qtwentysix),
            'Phone# of Contact' => addslashes($qtwentyseven),
            'Email of Contact' => addslashes($qtwentyeight),
            'Please submit a pharmacy logo:' => $qtwentynine,
            'Does your pharmacy have an existing website or will Amjay be developing one for you?' => addslashes($qthirty),
            'Website Domain' => addslashes($qthirtyone),
            'Provide recommendations for what they would like as a new domain):' => addslashes($qthirtytwo),
            'Sign Date' => addslashes($datesigned),
            'Signature' => $image1
        );
    } elseif ($pms == "propelrx") {
        $data1 = array(
            'Pharmacy Name' => addslashes($pharmacyname),
            'PMS' => addslashes($pms),
            'Please select from one of the call flows below for your pharmacy\'s Phone IVR Rx refill call flow configuration:' => addslashes($qone),
            'Type of Printer:' => addslashes($qtwo),
            '(If thermal, please send us a picture of the label or receipt depending on where you want to print the card) is on file within their patient profile of your pharmacy' => addslashes($qthirtythree),
            'How many digits are in the Rx #\'s?' => addslashes($qthree),
            'Windows Store Admin Password' => addslashes($qfour),
            'Please send us a picture of a sample receipt with a barcode:' => $qseven,
            'Do you use original # on rx number?' => addslashes($qfive),
            'How many terminals do you have?' => addslashes($qsix),
            'What P.O.S system do you use for barcode scanning?' => addslashes($qnine),
            'Is Amjay Software developing your pharmacy app?' => addslashes($qten),
            'For the feature of sending in a picture of a new Rx from your pharmacy App, where would you like the picture of the Rx to be sent to?' => addslashes($qeleven),
            'Fax Number OR Email Address' => addslashes($qtwelve),
            'Is there an IT department managing your main server access?' => addslashes($qfourteen),
            'Please provide the contact information for the IT department we should contact to get a team viewer to your main server when it\'s time to install the software' => '-',
            'IT company name:' => addslashes($qfifteen),
            'Contact person name' => addslashes($qsixteen),
            'Phone #' => addslashes($qseventeen),
            'Email' => addslashes($qeighteen),
            'Please indicate the pharmacy staff member we should contact to get a team viewer to your main server when it\'s time to install the software' => '-',
            'Name:' => addslashes($qtwenty),
            'Email:' => addslashes($qtwentyone),
            'Cell Phone' => addslashes($qtwentytwo),
            'Is the pharmacy main server shared with other locations (central server for multiple pharmacies)? Or is the pharmacy\'s main server used for this single pharmacy location only?' => addslashes($qtwentythree),
            'Please provide the contact info for the location/pharmacy where your central server resides?' => '-',
            'Location of Central Server' => addslashes($qtwentyfive),
            'Contact Person Name' => addslashes($qtwentysix),
            'Phone# of Contact' => addslashes($qtwentyseven),
            'Email of Contact' => addslashes($qtwentyeight),
            'Please submit a pharmacy logo:' => $qtwentynine,
            'Does your pharmacy have an existing website or will Amjay be developing one for you?' => addslashes($qthirty),
            'Website Domain' => addslashes($qthirtyone),
            'Provide recommendations for what they would like as a new domain):' => addslashes($qthirtytwo),
            'Sign Date' => addslashes($datesigned),
            'Signature' => $image1
        );
    } elseif ($pms == "winrx") {
        $data1 = array(
            'Pharmacy Name' => addslashes($pharmacyname),
            'PMS' => addslashes($pms),
            'Type of Printer:' => addslashes($qtwo),
            '(If thermal, please send us a picture of the label or receipt depending on where you want to print the card) is on file within their patient profile of your pharmacy' => addslashes($qthirtythree),
            'How many digits are in the Rx #\'s?' => addslashes($qthree),
            'Windows Store Admin Password' => addslashes($qfour),
            'Please send us a picture of a sample receipt with a barcode:' => $qseven,
            'Do you use original # on rx number?' => addslashes($qfive),
            'How many terminals do you have?' => addslashes($qsix),
            'What P.O.S system do you use for barcode scanning?' => addslashes($qnine),
            'Is Amjay Software developing your pharmacy app?' => addslashes($qten),
            'For the feature of sending in a picture of a new Rx from your pharmacy App, where would you like the picture of the Rx to be sent to?' => addslashes($qeleven),
            'Fax Number OR Email Address' => addslashes($qtwelve),
            'Is there an IT department managing your main server access?' => addslashes($qfourteen),
            'Please provide the contact information for the IT department we should contact to get a team viewer to your main server when it\'s time to install the software' => '-',
            'IT company name:' => addslashes($qfifteen),
            'Contact person name' => addslashes($qsixteen),
            'Phone #' => addslashes($qseventeen),
            'Email' => addslashes($qeighteen),
            'Please indicate the pharmacy staff member we should contact to get a team viewer to your main server when it\'s time to install the software' => '-',
            'Name:' => addslashes($qtwenty),
            'Email:' => addslashes($qtwentyone),
            'Cell Phone' => addslashes($qtwentytwo),
            'Is the pharmacy main server shared with other locations (central server for multiple pharmacies)? Or is the pharmacy\'s main server used for this single pharmacy location only?' => addslashes($qtwentythree),
            'Please provide the contact info for the location/pharmacy where your central server resides?' => '-',
            'Location of Central Server' => addslashes($qtwentyfive),
            'Contact Person Name' => addslashes($qtwentysix),
            'Phone# of Contact' => addslashes($qtwentyseven),
            'Email of Contact' => addslashes($qtwentyeight),
            'Please submit a pharmacy logo:' => $qtwentynine,
            'Does your pharmacy have an existing website or will Amjay be developing one for you?' => addslashes($qthirty),
            'Website Domain' => addslashes($qthirtyone),
            'Provide recommendations for what they would like as a new domain):' => addslashes($qthirtytwo),
            'Sign Date' => addslashes($datesigned),
            'Signature' => $image1
        );
    }
    $insert = json_encode($data1);
    $linkID = new PDO('mysql:host=' . Config::DB_HOST . ';dbname=' . Config::DB_NAME, Config::DB_USERNAME, Config::DB_PASSWORD);
    $linkID->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Setting ERRMODE
    $today = date("Y-m-d h:i:sa");

    $checkifexists = $linkID->query("SELECT count(*) FROM amjay_config_doc WHERE method_id=" . $methodid)->fetchAll(PDO::FETCH_ASSOC);
    $dataone = [
        'method_id' => $methodid,
        'key_val' => $insert,
        'date_time' => $today
    ];
    if ($checkifexists[0]['count(*)'] == 0) {
        $sqlone = "INSERT INTO `amjay_config_doc`(`method_id`, `key_val`, `date_time`) VALUES (:method_id,:key_val,:date_time)";
    } else {
        $checkifexistsname = $linkID->query("SELECT *FROM amjay_config_doc WHERE method_id=" . $methodid)->fetchAll(PDO::FETCH_ASSOC);
        $sqlone = "UPDATE `amjay_config_doc` SET `method_id`=:method_id,`key_val`=:key_val,`date_time`=:date_time WHERE method_id=" . $checkifexistsname[0]['method_id'];
    }
    $stmtone = $linkID->prepare($sqlone);
    $stmtone->execute($dataone);
}catch(Exception $e) {
        echo 'Message: ' .$e->getMessage();
}
echo 'Process completed. ';
