function addQuestion() {
    
    // Resets the form!
    if(document.getElementById("add").innerHTML == "Add Another Question") {
        document.getElementById("add").innerHTML = "Add Question";
        document.getElementById("sysMsg").innerHTML = "";
        document.getElementById("functionName").value = "";
        document.getElementById("q").value = "";
        document.getElementById("ans1").value = "";
        document.getElementById("ans2").value = "";
        document.getElementById("tc1").value = "";
        document.getElementById("tc2").value = "";
        document.getElementById("top").value = "";
        var constraintChecks = document.getElementsByClassName("check");
        for(let box of constraintChecks) {
            box.checked = false;
        }
        while(numCases > 2) {
            delTC();
        }
    }

    // Sending the question over
    else {
        var question = encodeURIComponent(document.getElementById("q").value);
        var difficulty = encodeURIComponent(document.getElementById("diff").value);
        var topic = encodeURIComponent(document.getElementById("top").value);
        var fName = encodeURIComponent(document.getElementById("functionName").value);
        var tcIn = [];
        var tcOut = [];
        var inStr, outStr;
        var checks = document.getElementsByClassName("check");

        for(i = 1; i < numCases+1; i++) {
            inStr = document.getElementById("tc" + i).value;
            outStr = document.getElementById("ans" + i).value;
            tcIn.push(inStr);
            if(parseInt(outStr)) {
                tcOut.push(parseInt(outStr));
            }
            else {
                tcOut.push(outStr);    
            }
        }
        var testCases = new Object();
        testCases.Input = tcIn;
        testCases.Output = tcOut;

        var constraints = new Object();
        constraints.while = checks[0].checked;
        constraints.for = checks[1].checked;
        constraints.print = checks[2].checked;
        console.log(testCases);
        
        // If any fields are empty
        if(question == null || question == "" || difficulty == null || difficulty == "" || topic == null || topic == "" || testCases == null || testCases == [] || fName == null || fName == "") {
            document.getElementById("sysMsg").innerHTML = "All Fields are Required."
        }
        else {
            var xhttp = new XMLHttpRequest();
            var addRequest = "query=InsertQuestion&Question=" + question + "&FunctionName=" + fName + "&Difficulty=" + difficulty + "&Topic=" + topic + "&TestCases=" + encodeURIComponent(JSON.stringify(testCases)) + "&Constraints=" + encodeURIComponent(JSON.stringify(constraints));
            var req = addRequest;
            console.log(req);
            xhttp.onreadystatechange = function() {
                if(this.readyState == 4 && this.status == 200) {
                    var echoed = this.responseText;
                    var response = JSON.parse(echoed);
                    if(response.dbSuccess) {
                        document.getElementById("add").innerHTML = "Add Another Question";
                        document.getElementById("sysMsg").innerHTML = "Question added! Send another?"
                        query();
                    }
                }
                else {
                    document.getElementById("sysMsg").innerHTML = "Error sending message."
                }
            }
            xhttp.open("POST","betaFrontCurl.php", true);
            xhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xhttp.send(req);
        }
    }
}
// Adding a question to the question bank

Adding a question to the question bank
Adding a question to the question bank
function addQuestion() {
    if(document.getElementById("add").innerHTML == "Add Another Question") {
        document.getElementById("add").innerHTML = "Add Question";
        document.getElementById("sysMsg").innerHTML = "";
        document.getElementById("functionName").value = "";
        document.getElementById("q").value = "";
        document.getElementById("ans1").value = "";
        document.getElementById("ans2").value = "";
        document.getElementById("tc1").value = "";
        document.getElementById("tc2").value = "";
        document.getElementById("top").value = "";
        var constraintChecks = document.getElementsByClassName("check");
        for(let box of constraintChecks) {
            box.checked = false;
        }
        while(numCases > 2) {
            delTC();
        }
    }
    else {
        var question = encodeURIComponent(document.getElementById("q").value);
        var difficulty = encodeURIComponent(document.getElementById("diff").value);
        var topic = encodeURIComponent(document.getElementById("top").value);
        var fName = encodeURIComponent(document.getElementById("functionName").value);
        var tcIn = [];
        var tcOut = [];
        var inStr, outStr;
        var checks = document.getElementsByClassName("check");
        for(i = 1; i < numCases+1; i++) {
            inStr = document.getElementById("tc" + i).value;
            outStr = document.getElementById("ans" + i).value;
            tcIn.push(inStr);
            if(parseInt(outStr)) {
                tcOut.push(parseInt(outStr));
            }
            else {
                tcOut.push(outStr);    
            }
        }
        var testCases = new Object();
        testCases.Input = tcIn;
        testCases.Output = tcOut;
        var constraints = new Object();
        constraints.while = checks[0].checked;
        constraints.for = checks[1].checked;
        constraints.print = checks[2].checked;
        console.log(testCases);
        if(question == null || question == "" || difficulty == null || difficulty == "" || topic == null || topic == "" || testCases == null || testCases == [] || fName == null || fName == "") {
            document.getElementById("sysMsg").innerHTML = "All Fields are Required."
        }
        else {
            var xhttp = new XMLHttpRequest();
            var addRequest = "query=InsertQuestion&Question=" + question + "&FunctionName=" + fName + "&Difficulty=" + difficulty + "&Topic=" + topic + "&TestCases=" + encodeURIComponent(JSON.stringify(testCases)) + "&Constraints=" + encodeURIComponent(JSON.stringify(constraints));
            var req = addRequest;
            console.log(req);
            xhttp.onreadystatechange = function() {
                if(this.readyState == 4 && this.status == 200) {
                    var echoed = this.responseText;
                    var response = JSON.parse(echoed);
                    if(response.dbSuccess) {
                        document.getElementById("add").innerHTML = "Add Another Question";
                        document.getElementById("sysMsg").innerHTML = "Question added! Send another?"
                        query();
                    }
                }
                else {
                    document.getElementById("sysMsg").innerHTML = "Error sending message."
                }
            }
            xhttp.open("POST","betaFrontCurl.php", true);
            xhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xhttp.send(req);
        }
    }
}
function addQuestion ( ) { if ( document . getElementById ( "add" ) . innerHTML == "Add Another Question" ) { document . getElementById ( "add" ) . innerHTML = "Add Question" ; document . getElementById ( "sysMsg" ) . innerHTML = "" ; document . getElementById ( "functionName" ) . value = "" ; document . getElementById ( "q" ) . value = "" ; document . getElementById ( "ans1" ) . value = "" ; document . getElementById ( "ans2" ) . value = "" ; document . getElementById ( "tc1" ) . value = "" ; document . getElementById ( "tc2" ) . value = "" ; document . getElementById ( "top" ) . value = "" ; var constraintChecks = document . getElementsByClassName ( "check" ) ; for ( let box of constraintChecks ) { box . checked = false ; } while ( numCases > 2 ) { delTC ( ) ; } } else { var question = encodeURIComponent ( document . getElementById ( "q" ) . value ) ; var difficulty = encodeURIComponent ( document . getElementById ( "diff" ) . value ) ; var topic = encodeURIComponent ( document . getElementById ( "top" ) . value ) ; var fName = encodeURIComponent ( document . getElementById ( "functionName" ) . value ) ; var tcIn = [ ] ; var tcOut = [ ] ; var inStr , outStr ; var checks = document . getElementsByClassName ( "check" ) ; for ( i = 1 ; i < numCases + 1 ; i ++ ) { inStr = document . getElementById ( "tc" + i ) . value ; outStr = document . getElementById ( "ans" + i ) . value ; tcIn . push ( inStr ) ; if ( parseInt ( outStr ) ) { tcOut . push ( parseInt ( outStr ) ) ; } else { tcOut . push ( outStr ) ; } } var testCases = new Object ( ) ; testCases . Input = tcIn ; testCases . Output = tcOut ; var constraints = new Object ( ) ; constraints . while = checks [ 0 ] . checked ; constraints . for = checks [ 1 ] . checked ; constraints . print = checks [ 2 ] . checked ; console . log ( testCases ) ; if ( question == null || question == "" || difficulty == null || difficulty == "" || topic == null || topic == "" || testCases == null || testCases == [ ] || fName == null || fName == "" ) { document . getElementById ( "sysMsg" ) . innerHTML = "All Fields are Required." } else { var xhttp = new XMLHttpRequest ( ) ; var addRequest = "query=InsertQuestion&Question=" + question + "&FunctionName=" + fName + "&Difficulty=" + difficulty + "&Topic=" + topic + "&TestCases=" + encodeURIComponent ( JSON . stringify ( testCases ) ) + "&Constraints=" + encodeURIComponent ( JSON . stringify ( constraints ) ) ; var req = addRequest ; console . log ( req ) ; xhttp . onreadystatechange = function ( ) { if ( this . readyState == 4 && this . status == 200 ) { var echoed = this . responseText ; var response = JSON . parse ( echoed ) ; if ( response . dbSuccess ) { document . getElementById ( "add" ) . innerHTML = "Add Another Question" ; document . getElementById ( "sysMsg" ) . innerHTML = "Question added! Send another?" query ( ) ; } } else { document . getElementById ( "sysMsg" ) . innerHTML = "Error sending message." } } xhttp . open ( "POST" , "betaFrontCurl.php" , true ) ; xhttp . setRequestHeader ( "Content-Type" , "application/x-www-form-urlencoded" ) ; xhttp . send ( req ) ; } } }
Adding a question to the question bank
Adding a question to the question bank
// Resets the form!
 // Sending the question over
 // If any fields are empty
