HEX
Server: Apache
System: Linux iad1-shared-e1-19 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User: austral3d (14892361)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /home/austral3d/fourdplan.com/cotizario/search.php
<!DOCTYPE html>
<html>
    <head>
    <title>Product Finder</title>
        
    <?php include "files/functions.php" ?>
    <?php $conn = connect_sql() ?>
    <?php include "files/functionsJS.php" ?>
    
    </head>

    <body>
        <?php
        /*
            function search_product($master_list, $product_name, $cmp_function, $epsilon = 0)
            {
                $ordered_list = array();
                foreach($master_list as $name=>$quantity) {
                    if (abs($value = $cmp_function($product_name, $name)) <= $epsilon) {
                        $ordered_list[$product_name] = $value;
                    }
                }
            }

            function simple_compare($needle, $guess)
            {
                // 1 is false, 0 is true
                return !strrpos($guess, $needle) >= 0;
            }
            */

        ?>


        <?php
        /*function read_file_to_array($filename) 
        {
            if (is_file($filename)) {
                $open_file = fopen($filename, 'r');
                $array = array();
                
                // assumes each line only has one item

                while (!feof($open_file)) {
                    $line = fgets($open_file);
                    $firstComma = strpos($line, ',');
                    $secondComma = strpos($line, ',', $firstComma + 1);
                    $productName = trim(substr($line, $firstComma + 1, $secondComma - $firstComma - 1));
                    array_push($array, strToLower($productName));
                }
                
                fclose($open_file);
                return $array;
            }
            return NULL;
        }*/
        ?>

        <!-- Select database and table -->
        <?php
            $data = parse_masterList($_GET['masterList']);
            $db = $data[0];
            $table_name = $data[1];
            mysqli_select_db($conn, $db);
            $columns = get_table_columns($conn, $db, $table_name);
            //var_dump($columns);
        ?>

        <!-- find selections -->

        <!--<input type='button' id='test' value='test' onclick='test()' />-->
        <script>
            let masterList = [];


            function sendData(string) 
            {
                console.log('sending data');
                //console.log('<?php echo $table_name; ?>');
                let xmlhttp = new XMLHttpRequest();
                xmlhttp.onreadystatechange = function() {
                    if(this.readyState == 4 && this.status == 200) {
                        console.log(this.responseText);
                        //console.log(typeof(this.responseText));
                        if (typeof(this.responseText) == 'string') {
                            masterList = JSON.parse(this.responseText);
                        }
                    }
                }
                console.log(string);
                xmlhttp.open("POST", "test.php", false);
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xmlhttp.send("info=" + string
                        + "&tableName=" + '<?php echo $table_name?>'
                        + "&dbName=" + '<?php echo $db ?>');
            }

            function productSearch(cmpFunction)
            {
                resetResults();
                getMasterList();
                console.log('Master list is : [' + masterList + ']');
                let text = document.getElementById('productName');
                let searchTerms = createSplitArray(text.value);
                
                for (let name of searchTerms) {
                    searchProduct(masterList, name, cmpFunction);
                }
                displayResults(20, Object.keys(productList), addCheckbox);
            }


            /*function test()
            {
                let checked = document.querySelectorAll('input:checked');
                if (checked.length) {
                    let checkedArray = [];
                    for (let i = 0; i < checked.length; i++) {
                        if (checked[i].form.id != 'form') {
                            checkedArray.push([checked[i].form.id, checked[i].value]);
                        }
                    }
                    console.log(checkedArray);
                    let arrayData = arrayToStr(checkedArray);
                    sendData(arrayData);
                }
            }

            function sendData(string) 
            {
                console.log('sending data');
                let xmlhttp = new XMLHttpRequest();
                xmlhttp.onreadystatechange = function() {
                    if(this.readyState == 4 && this.status == 200) {
                        console.log(this.responseText);
                        let x = JSON.parse(this.responseText);
                        console.log(typeof(x));
                        console.log(x);
                    }
                }
                xmlhttp.open("GET", "test.php?info=" + string
                                    + "&tableName=" + '<?php echo $table_name?>'
                                    + "&dbName=" + '<?php echo $db ?>', true);
                xmlhttp.send();
            }*/
            //console.log('hello ' + '<?php echo  $table_name?>');
            //console.log(getMasterList());
            //console.log(masterList);
        </script>


        <?php
            //$info = json_decode('[["w", "asdf"], ["w", "ads"], ["w", "fds"]]');
            /*$clause = 'WHERE ';
            $count = 0;
            $len = count($info);
            foreach($info as $pair) {
                $count ++;
                var_dump($pair);
                $name = $pair[0];
                $item = $pair[1];
                $clause .= '`'.$name.'`="'.$item.'" ';
                if ($count < $len) {
                    $clause .= 'OR ';
                }
            }
            echo $clause.'<br />';
            $things = get_table_info($conn, "`".$table_name."`", '*', $clause);
            var_dump($things);*/
            //$item_name = $columns[1];

            //echo json_encode(get_table_items($conn, $table_name, $item_name, $info));
            //echo json_encode(get_table_info($conn, '`'.$table_name.'`', $item_name));
        ?>


        <script>
            
            let food = {'grape':10, 'applpe':20, 'orange':5};
            let currentCSV = [['Term Searched', 'Choice(s) Chosen']];
            let inventory = {
                'grape' : 20,
                'apple' : 50,
                'orange': 30,
                'orange_pie':4,
                'apple_pie':7,
                'banana':80,
                'banana_cream_pie':6,
                'grape_juice':30,
                'apple_juice':18
            };


            productList = {};
            
            
        </script>

            <?php //$master_list = read_file_to_array('test.csv'); 
            //var_dump($master_list);
            //echo json_encode($master_list);
            ?>
        <script>
            //let masterList = '<?php echo json_encode($master_list); ?>';
            //console.log(masterList);
        </script>

        <h1>Product Finder<h1>

        <input type='text' placeholder='Enter Product Name' id='productName'>
        <input type='button' value='Search' onclick='productSearch(simpleCompare)'>





        <!-- Create submenus -->
        <script>
            let choice = 0;
            let menuName = 0;
            let menu = 0;
            let showButton = 0;
            let hideButton = 0;
            let form = 0;
            let div = 0;

            <?php for ($i = 3; $i < count($columns); $i++): ?>
                //console.log('doing things');
                menuName = '<?php echo $columns[$i]; ?>';
                
                // create div
                div = document.createElement('div');
                
                // create p
                menu = document.createElement('h3');
                menu.innerHTML = menuName;
                
                // create select
                form = document.createElement('form');
                form.id = menuName;
                form.style.display = 'none';
                <?php foreach(get_distinct_items($conn, $table_name, $columns[$i]) as $choice) : ?>
                    choice = document.createElement('input');
                    choice.type = 'checkbox';
                    choice.value = '<?php echo $choice?>';
                    form.appendChild(choice);
                    form.innerHTML += '<?php echo $choice.'<br />' ?>';
                <?php endforeach; ?>

                // add show buttom
                showButton = document.createElement('input');
                showButton.type = 'button';
                showButton.value = 'Show choices';
                showButton.onclick = function(){
                    showItem('<?php echo $columns[$i]; ?>');
                };

                // add hide button
                hideButton = document.createElement('input');
                hideButton.type = 'button';
                hideButton.value = 'Hide choices';
                hideButton.onclick = function() {
                    hideItem('<?php echo $columns[$i]; ?>');
                };

                div.appendChild(menu);
                div.appendChild(form);
                div.appendChild(showButton);
                div.appendChild(hideButton);
                //console.log(div);
                document.body.appendChild(div);

                
            <?php endfor; ?>
        </script>







        <!--
        <h3>Results<h3>
        <ul id='list'>
        </ul>

        <input type='button' value='Next Item' onclick='displayNextElement(Object.keys(food), addListItem)'>
        <input type='submit' value='Continue'>
        -->

        <div id='progressBar' >
            <h6 id=percent>0%</h6>
            <p id='bar'>|</p>
        </div>

        


            <h3 id = 'results'>Results</h3>
            <form id='form'></form>
            <input type='button' value='Next Choice' 
                 onclick="displayNextElement(Object.keys(productList), addCheckbox)" />
            <input type = 'button' value='Continue' onclick='isChecked()' />

        <br />
        <br />

        <input type='text' id='downloadFileName' placeholder='Enter File Name' style='display:none'>
        <input type='button' value='Download' id='downloadButton' 
                style='display:none' onclick='downloadFile("downloadFileName")' />
        <br />

        <!--<script>

            const rows = [["name1", "city1", "some other info"], ["name2", "city2", "more info"]];
            let csvContent = "data:text/csv;charset=utf-8,";
            rows.forEach(function(rowArray){
                let row = rowArray.join(",");
                csvContent += row + "\r\n";
            }); 
            generateDownloadLink(csvContent, 'test');
            

            
            
        </script>-->

        <script>
            /*let bar = document.getElementById('bar');
            let length = window.innerWidth/7.3;
            for (let i = 0; i < length; i ++) {
                bar.innerHTML += '|';
            }*/
            /*let length = 1000000;
            for (let i = 0; i < length; i ++) {
                console.log(i);
                changeProgressBar(i/length);
            }*/
        </script>

        <?php
        ?>

    </body>
</html>