How does the debugger determine what is installed?

How does the debugger determine what is installed?

mmcnair80mmcnair80 Posts: 83Questions: 21Answers: 7
edited November 2016 in Free community support

I'm having trouble implementing server-side processing. I have been testing and have what I think should be working, but when I run the files I get an invalid JSON response and nothing shows up. I don't even get an empty table, I only get the header then nothing. I tried running the debugger and get a result that says nothing is installed except DataTables, when there should be several things installed. (Buttons-1.2.2, ColReorder-1.3.2, DataTables-1.10.12, FixedHeader-3.1.2, JQuery-1.12.3, JQuery-2.2.3, JSZip-2.5.0, pdfmake-0.1.18, Responsive-2.1.0, Scroller-1.4.2, Select-1.2.0)

Here is the TestDataTable.php file:

    <body>
        <?php
            $AdminUsers = include 'AdminUsernames.php';
            if  (in_array($_SERVER['AUTH_USER'],$AdminUsers,TRUE) || in_array($_COOKIE['UserName'],$AdminUsers,TRUE))
            {
                
                include('AdminMenu.php');
            }
            else
            {
                include('Menu.php');
            }
        ?>
        <br><br><br>
        <h1>Test Data Table</h1>
        <?php 
            include ('Selected.php');

            include 'ContentSearchPage.php';
            include 'DBConn.php';
            $getHeadings = $conn->query($hsql);
            $rHeadings = $getHeadings->fetchALL(PDO::FETCH_ASSOC);
            $CountHeadings = count($rHeadings);
            $tsqlHeadings = '';
            for ($row = 0; $row < $CountHeadings; $row++)
            {
                $headings[$row] = $rHeadings[$row]["Headings"];
                $tsqlHeadings = $tsqlHeadings . "[" . $headings[$row] . '],';
            }
            
            if($DataTable == 1)
            {
                $CountTSQL = "Select count(*) " . $tsql;
                $tsql = "Select " . substr($tsqlHeadings,0,strlen($tsqlHeadings)-1) . $tsql;
            }
            else
            {
                $CountTSQL = "Select count(*) " . $tsql;
                $tsql = "Select " . substr($tsqlHeadings,0,strlen($tsqlHeadings)-1) . $tsql . " order by Id OFFSET $offset ROWS FETCH NEXT $limit ROWS ONLY";
            }
        ?>
        <table id="DataTable" class="display nowrap" style="width: 100%; border: 1px">
          <thead>
            <tr>
                <?php
                foreach($headings as $heading)
                {?>
                <th class="cell"><?php echo $heading; ?></th><?php
                }?>
            </tr>
          </thead>
        </table>
    </body>
</html>

Here's how I initialize the DataTable:

<script>
    $(document).ready(function ()
    {
        $('#DataTable').DataTable(
      {
          "lengthMenu": [[25, 50, 75, 100, 150], [25, 50, 75, 100, 150]],
          "ScrollX": true,
          "dom": '<"top"Biflp<"clear">>rt<"bottom"ip<"clear">>',
          "buttons": [
                { extend: 'collection', text: 'Selection', buttons: ['selectAll', 'selectNone'] },
                { extend: 'collection', text: 'Export', buttons: ['excel', 'csv', 'pdf']}],
          "fixedHeader": { header: true, footer: false },
          "select": true,
          "processing": true,
          "serverSide": true,
          "ajax": { "url": "ServerSide.php?PageName=<?php echo $Page; ?>", "dataType": "json" }
      });
    });
</script>

Here's the included CSS and javascript links, both files I got from the download builder:

<link rel="stylesheet" type="text/css" href="DataTables/dataTables.css"/>
<script type="text/javascript" src="DataTables/dataTables.js"></script>
<script type="text/javascript" src="DataTables/DataTables-1.10.12/js/jquery.dataTables.min.js"></script>

Here's my ServerSide.php

<?php
include 'Helper/PageName.php';              //Pulls the page name and Table name and returns the $SQLTableName
include 'DBConn.php'; //echo "<br>Testing"; //DB connection info

$headings = array();
$hsql = "select Headings from TableHeadings where TableName = '$TableName' order by Id";
$getHeadings = $conn->query($hsql);
$rHeadings = $getHeadings->fetchALL(PDO::FETCH_ASSOC);
$CountHeadings = count($rHeadings);
$tsqlHeadings = '';
$ColumnHeader = array();
for ($row = 0; $row < $CountHeadings; $row++)
{
    if($rHeadings[$row]["Headings"] <> "Edit")
    {
        $headings[$row] = $rHeadings[$row]["Headings"];
        $tsqlHeadings = $tsqlHeadings . "[" . $headings[$row] . '],';
    }
}

foreach($headings as $index => $columnName)
{
    $ColumnHeader[] = array('db'=>$columnName,'dt'=>$index);
}

//DB table to use
$table = $SQLTableName;

//Table's primary key
$primaryKey = 'id';

//Array of database columns which should be read and sent back to DataTables
$columns = $headings;

// Get data to display 
$Query = "SELECT  ".str_replace(" , ", " ", implode(", ", $columns))." FROM $table";

$whereResult = array();
if($TableName == 'COEI_OPR' || $TableName == 'OSP_OPR' || $TableName == 'MaterialTracking' || $TableName == 'MaterialReceived' || $TableName = 'ApprovedProjects_PrevDay' || $TableName == 'ApprovedProjects' || $TableName == 'M6Action' || $TableName == 'OPR_COEI' || $TableName == 'OPR_OSP')
{
    include 'SearchTerm.php';
}
$request = array();
$request = $_GET;
require('FilterSort.class.php');

echo json_encode(FilterSort::complex($request,$sqlConnect,$table,$primaryKey,$ColumnHeader,$whereResult));
?>

The included file SearchTerm.php is the file that would fill out the $whereResult array with the filters that the user wants, if there are any available to them. I've been testing with a table that doesn't allow any filters so that file is not included for testing purposes.

Then I also have a modified version of the ssp.class.php (FilterSort.class.php) file that uses the Complex method only and PDO:SQLSRV instead of MySql. I can add that as well if needed, but what is sent to the server appears to be correct. It's just the response that isn't what is expected.

Edit

Just realized I didn't have some of the info included. Here is the part of the file ContentSearchPage.php that gives the sql for the headings:

        case 'QDefs':
            try
            {
                include 'SearchParameters.php';
                include 'DBConn.php';
                //echo "Made it to the right place!";
                $Edit = 1;
                $OneButton = 1;
                $SQLArray = array("searchState" => $searchState,"searchProject"=>$searchProject);

                $CountSQL = "select count(*) from pmdb.v_QDefs";
                //print_r($CountSQL); echo "<br>CountSQL<br>";
                $TotalRows = $conn->query($CountSQL)->fetchColumn();
                //print_r($TotalRows); echo "<br>TotalRows<br>";
                if($TotalRows > 500)
                {
                    include 'NavButtons.php';
                    $DataTable = 0;
                }
                elseif($TotalRows <= 500)
                {
                    $offset = '';
                    $currentpage = '';
                    $DataTable = 1;
                }
                $tsql = " from pmdb.v_QDefs";
                $hsql = "select Headings from TableHeadings where TableName = 'v_QDefs' and Headings != 'Edit' order by Id";
            }

Any ideas where I'm going wrong?

EDIT 2
I've attached the FilterSort.class.php file. It was too big to copy paste.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,950Questions: 1Answers: 10,158 Site admin

    I thin the issue with the debugger is that it looks like you are loading DataTables on top of an existing DataTables load. You probably don't need to include DataTables/DataTables-1.10.12/js/jquery.dataTables.min.js.

    Regarding the server-side processing aspect, does FilterSort::complex implement server-side processing?

    Does your server show any errors in its error log?

    Allan

  • mmcnair80mmcnair80 Posts: 83Questions: 21Answers: 7
    edited November 2016

    I can exclude the DataTables/DataTables-1.10.12/js/jquery.dataTables.min.js

    I think I have the FilterSort::complex using server-side processing. I followed the file that you sent me in another question ssp.class.php. I only updated it to use only the complex and not simple and then to use PDO::SQLSRV instead of MySql.

    I will have to check the server logs, but I doubt that there are errors. I'll post them if I find anything.

    Also where would I find any logs for DataTables? Are they set in a particular folder?

  • allanallan Posts: 61,950Questions: 1Answers: 10,158 Site admin
    Answer ✓

    Ah I see - yes, if that is SSP class just renamed, it should work.

    For the logs, I was meaning the server's HTTP error log. /var/log/apache/error_log is the standard location for Apache on Linux. But your system might be something else or configured differently.

    Allan

  • mmcnair80mmcnair80 Posts: 83Questions: 21Answers: 7

    There are no errors in any of the logs that I can find. We use a Windows Server setup. I've gone through the logs and only see logons from the website. No errors.

    It looks like the response is HTML, and then at the end of the HTML is the JSON that DataTables is looking for. I just can't figure out where the HTML is coming from.

  • mmcnair80mmcnair80 Posts: 83Questions: 21Answers: 7

    I found it with the help of one of my colleges. In the ServerSide.php file there is this part:

    if($TableName == 'COEI_OPR' || $TableName == 'OSP_OPR' || $TableName == 'MaterialTracking' || $TableName == 'MaterialReceived' || $TableName == 'ApprovedProjects_PrevDay' || $TableName == 'ApprovedProjects' || $TableName == 'M6Action' || $TableName == 'OPR_COEI' || $TableName == 'OPR_OSP')
    {
        include 'SearchTerm.php';
    }
    

    One of the OR'ed statements was assigning the value with = instead of checking it with ==. I fixed that and it's returning the correct JSON response.

    Now for other questions!

This discussion has been closed.