tn/7 error when trying to load test page without login

tn/7 error when trying to load test page without login

rob1strob1st Posts: 57Questions: 12Answers: 0

I wanted to try and post a test page for another issue, but this one is stopping me providing the test page.

Page loads fine when I am logged in with no issues, when I remove the security I get the TN7.

I provide control of the dataset via GET which is cleaned and then passed through the session to the server side.

All versions are up to date.

This one has me stumped.

Server log says:

Got error 'PHP message: PHP Fatal error:  Uncaught Error: Call to a member function dbField() on null in /chroot/home/mySite/html/ajax/lib/Editor.php:2345\nStack trace:\n#0 /chroot/home/mySite/html/ajax/lib/Editor.php(972): DataTables\\Editor->_prepJoin()\n#1 /chroot/home/mySite/html/ajax/lib/Editor.php(701): DataTables\\Editor->_process()\n#2 /chroot/home/mySite/html/ajax/at/assets1.php(310): DataTables\\Editor->process()\n#3 {main}\n  thrown in /chroot/home/mySite/html/ajax/lib/Editor.php on line 2345'

The line in question on the server side (/at/assets1.php) is the "->process( $_POST )".

Server side is:

<?php
//SESSION START
if(!isset($_SESSION)) { 
    session_start(); 
  }
  
if(isset($_SESSION['loc'])) {
  $loc = $_SESSION['loc'];
} else {
  $loc = null;
}
if(isset($_SESSION['at'])) {
  $at = $_SESSION['at'];
} else {
  $at = null;
}
if(isset($_SESSION['ss'])) {
  $ss = $_SESSION['ss'];
} else {
  $ss = null;
}
if(isset($_SESSION['disc'])) {
  $disc = $_SESSION['disc'];
} else {
  $disc = null;
}
if(isset($_SESSION['e'])) {
  $e = $_SESSION['e'];
} else {
  $e = null;
}
if(isset($_SESSION['g'])) {
  $g = $_SESSION['g'];
} else {
  $g = null;
}
if(isset($_SESSION['status'])) {
  $status = $_SESSION['status'];
} else {
  $status = null;
}
$userID = null;

include("../lib/DataTables.php");

use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions,
    DataTables\Editor\SearchPaneOptions;

Editor::inst( $db, 'asset A', 'A.id' )
->field(
    //Static Fields - No Validation
    Field::inst( 'S.assetStatus' )
    ->searchPaneOptions(SearchPaneOptions::inst()),
    Field::inst( 'ST.assetTag AS specTag' ),
    Field::inst( 'A.MATPTag' ),
    Field::inst( 'T.assetType' )
    ->searchPaneOptions(SearchPaneOptions::inst()),
    Field::inst( 'D.discipline' )
    ->searchPaneOptions(SearchPaneOptions::inst()),
    Field::inst( 'E.entityTLA' )
    ->searchPaneOptions(SearchPaneOptions::inst()),
    Field::inst( 'L1.levelTLA' )
    ->searchPaneOptions(SearchPaneOptions::inst()),
    Field::inst( 'L.LocationName' )
    ->searchPaneOptions(SearchPaneOptions::inst()),
    Field::inst( 'A.oldID AS oldID' ),             
    Field::inst( 'TR.reportStatus AS PR' )
    ->searchPaneOptions(SearchPaneOptions::inst()),  
    Field::inst( 'TR1.reportStatus AS SR' )
    ->searchPaneOptions(SearchPaneOptions::inst()), 
    Field::inst( 'T.spec' )
    ->searchPaneOptions(SearchPaneOptions::inst()),
    Field::inst( 'SY.systemName AS subsystem' )
    ->searchPaneOptions(SearchPaneOptions::inst()), 
    Field::inst( 'P.phase' )
    ->searchPaneOptions(SearchPaneOptions::inst()),  
    Field::inst( 'C1.procedureTag AS PICO' )
    ->searchPaneOptions(SearchPaneOptions::inst()), 
    Field::inst( 'C2.procedureTag AS SAT' )
    ->searchPaneOptions(SearchPaneOptions::inst()),
    Field::inst( 'U.username' )
    ->searchPaneOptions(SearchPaneOptions::inst()),
    Field::inst( 'A.comment' )
    ->searchPaneOptions(SearchPaneOptions::inst()),
    Field::inst( 'A.seq AS seq' ),
    Field::inst( 'A.Room AS room' )
    ->searchPaneOptions(SearchPaneOptions::inst()),
    
    //Static fields - with validation
    Field::inst( 'A.dwgTag AS designTag' )
      ->validator( Validate::notEmpty( ValidateOptions::inst()
        ->message( 'What is the asset called on the design?' )
      ) ),
    Field::inst( 'ST.MATP AS assetTag' ),
    Field::inst( 'A.dwgNo AS design' ),

    //Select Fields
    Field::inst( 'A.loc' )
      ->options( Options::inst()
        ->table('loc')
        ->value('id')
        ->label('LocationName')
        ->order('id')
      )
      ->validator( Validate::dbValues() )
      ->validator( Validate::notEmpty( ValidateOptions::inst()
        ->message( 'What location are we using?' )
      ) ), 
    
    Field::inst( 'A.assetType' )
      ->options( Options::inst()
        ->table('assettype')
        ->value('assetTypeID')
        ->label('assetType')
      )
      ->validator( Validate::dbValues() )
      ->validator( Validate::notEmpty( ValidateOptions::inst()
        ->message( 'What type of asset is it?' )
      ) ),
 
    Field::inst( 'A.entity' )
      ->options( Options::inst()
        ->table('entity')
        ->value('entityID')
        ->label('entityTLA')
        ->order('entityID')
      )
      ->validator( Validate::dbValues() )
      ->validator( Validate::notEmpty( ValidateOptions::inst()
        ->message( 'Which entity will own the asset when in service?' )
      ) ),

    Field::inst( 'A.assetStatus' )
      ->options( Options::inst()
        ->table('assetstatus')
        ->value('id')
        ->label('assetStatus')
        ->order('id')
      )
      ->validator( Validate::dbValues() )
      ->validator( Validate::notEmpty( ValidateOptions::inst()
        ->message( 'What status are we allocating?' )
      ) ),

    Field::inst( 'A.bic' )
      ->options( Options::inst()
        ->table('users_enc')
        ->value('id')
        ->label( array('lastname','firstname') )
        ->Render( function ( $row ) {
          return $row['lastname'].', '.$row['firstname'];
        } )
        ->order('lastname')
      )
    ->validator( Validate::dbValues() )
    ->setFormatter( Format::ifEmpty( null )),

    Field::inst( 'A.phase' )
      ->options( Options::inst()
        ->table('phase')
        ->value('phaseID')
        ->label('phase')
        ->order('phase')
      )
      ->validator( Validate::dbValues() )
      ->setFormatter( Format::ifEmpty( null )),
    
    Field::inst( 'A.levels' )
      ->options( Options::inst()
        ->table('levels')
        ->value('levelID')
        ->label('levels')
        ->order('levels')
      )
      ->validator( Validate::dbValues() )
      ->setFormatter( Format::ifEmpty( null )),

      Field::inst( 'A.picoReport' )
      ->options( Options::inst()
        ->table('reports')
        ->value('id')
        ->label( array('docConNo', 'revision'))
        ->render( function ( $row ) {
          return $row['docConNo'].'_'.$row['revision'];
      } )
        ->where( function ( $q ) {
          $q->where('docConNo', '%XQ%', 'LIKE');
        })
        ->order('docConNo')
      )
      ->validator( Validate::dbValues() )
      ->setFormatter( Format::ifEmpty( null )),

      Field::inst( 'A.satReport' )
      ->options( Options::inst()
        ->table('reports')
        ->value('id')
        ->label( array('docConNo', 'revision'))
        ->render( function ( $row ) {
          return $row['docConNo'].'_'.$row['revision'];
      } )
        ->where( function ( $q ) {
          $q->where('docConNo', '%XR%', 'LIKE');
        })
        ->order('docConNo')
      )
      ->validator( Validate::dbValues() )
      ->setFormatter( Format::ifEmpty( null )),

      Field::inst( 'A.satReportStatus' )
      ->options( Options::inst()
        ->table('testStatus')
        ->value('reportStatusID')
        ->label( 'reportStatus')
        ->order('reportStatusID')
      )
      ->validator( Validate::dbValues() )
      ->setFormatter( Format::ifEmpty( null )),

      Field::inst( 'A.picoReportStatus' )
      ->options( Options::inst()
        ->table('testStatus')
        ->value('reportStatusID')
        ->label( 'reportStatus')
        ->order('reportStatusID')
      )
      ->validator( Validate::dbValues() )
      ->setFormatter( Format::ifEmpty( null )),
)

->leftJoin( 'assettype T', 'T.assetTypeID', '=', 'A.assetType' )
->leftJoin( 'entity E', 'E.entityID', '=', 'A.entity' )
->leftJoin( 'loc L', 'L.id', '=', 'A.loc' )
->leftJoin( 'assetstatus S', 'S.id', '=', 'A.assetStatus' )
->leftJoin( 'testStatus TR', 'TR.reportStatusID', '=', 'A.picoReportStatus' )
->leftJoin( 'testStatus TR1', 'TR1.reportStatusID', '=', 'A.satReportStatus' )
->leftJoin( 'system SY', 'SY.id', '=', 'T.subsystem' )
->leftJoin( 'cxprocedure C1', 'C1.id', '=', 'T.PICO' )
->leftJoin( 'cxprocedure C2', 'C2.id', '=', 'T.SAT' )
->leftJoin( 'users_enc U', 'U.id', '=', 'A.bic' )
->leftJoin( 'phase P', 'P.phaseID', '=', 'A.phase' )
->leftJoin( 'assetTag ST', 'ST.assetID', '=', 'A.id' )
->leftJoin( 'discipline D', 'D.disciplineID', '=', 'SY.discipline' )
->leftJoin( 'levels L1', 'L1.levelID', '=', 'A.levels' )
->where( function ( $q ) use ( $loc, $at, $ss, $e, $disc, $g, $status ) {
  if(isset($status)) {
    $q->where('A.assetStatus', 99, '<');
  } else {
    $q->where('A.assetStatus', 2, '!=');
  }
  if(isset($loc)) {
    $q->and_where('A.loc', $loc, '='); 
  }
  if(isset($at)) {
    $q->and_where('A.assetType', $at, '='); 
  }
  if(isset($ss)) {
    $q->and_where('T.subsystem', $ss, '='); 
  }
  if(isset($e)) {
    $q->and_where('A.entity', $e, '='); 
  }
  if(isset($disc)) {
    $q->and_where('SY.discipline', $disc, '='); 
  }
  if(isset($g)) {
    $q->and_where('D.FS', $g, '='); 
  }
  if(isset($status)) {
    $q->and_where('A.assetStatus', $status, '='); 
  }
} )
->debug(true)
->process( $_POST )
->json();

unset($_SESSION['loc']);
unset($_SESSION['at']);
unset($_SESSION['ss']);
unset($_SESSION['e']);
unset($_SESSION['disc']);
unset($_SESSION['g']);
unset($_SESSION['status']);
?>

Answers

  • rob1strob1st Posts: 57Questions: 12Answers: 0

    I tried to post the PHP but it's too long for the post, but I am not sure it's fully relevant.

  • allanallan Posts: 54,688Questions: 1Answers: 8,553 Site admin

    I've got to confess, I'm at a bit of a loss with this one!

    This is the line it is failing at - but that suggests that $this->_fields has a null value in it. I've no idea why that would be from your code!

    Could you add print_r($this->_fields); just before that for loop in your copy of Editor.php and let me know what the result of that is in the response when you load it in the non-logged in state please? It will give an error in Javascript, but hopefully the result will help trace this one down.

    Allan

  • rob1strob1st Posts: 57Questions: 12Answers: 0

    Allan,

    I am getting an error telling me the post is too long, was the character limits on the forum posts changed?

    I can't post the result from your request.

  • rob1strob1st Posts: 57Questions: 12Answers: 0

    Just looking through the results though, there are some fields that will be null such as this:

    [_dbField:DataTables\Editor\Field:private] => TR1.reportStatus 
    
  • allanallan Posts: 54,688Questions: 1Answers: 8,553 Site admin

    No - no change, but the debug output must have been fairly big!

    I’m not sure why TR1.reportStatus would be null? I don’t see anything in your code that would make it null? I think I’ll need to try and replicate this when I get into the office tomorrow. I’m wondering if the as aliases might be causing an issue…

    Allan

  • rob1strob1st Posts: 57Questions: 12Answers: 0
    edited September 10

    The status it pulls from the database is null in some cases, but I am assuming that's not what you meant.

    This is one section of the output

    [0] => DataTables\Editor\Field Object ( 
        [_dbField:DataTables\Editor\Field:private] => S.assetStatus 
        [_get:DataTables\Editor\Field:private] => 1 
        [_getFormatter:DataTables\Editor\Field:private] => 
        [_getFormatterOpts:DataTables\Editor\Field:private] => 
        [_getValue:DataTables\Editor\Field:private] => 
        [_opts:DataTables\Editor\Field:private] => 
        [_spopts:DataTables\Editor\Field:private] => DataTables\Editor\SearchPaneOptions 
        Object ( 
          [_table:DataTables\Editor\SearchPaneOptions:private] => 
          [_value:DataTables\Editor\SearchPaneOptions:private] => 
          [_label:DataTables\Editor\SearchPaneOptions:private] => 
          Array ( ) [_leftJoin:DataTables\Editor\SearchPaneOptions:private] => 
          Array ( ) [_renderer:DataTables\Editor\SearchPaneOptions:private] => 
          [_where:DataTables\Editor\SearchPaneOptions:private] => 
          [_order:DataTables\Editor\SearchPaneOptions:private] => 
        ) 
        [_optsFn:DataTables\Editor\Field:private] => 
        [_spoptsFn:DataTables\Editor\Field:private] => 
        [_name:DataTables\Editor\Field:private] => S.assetStatus 
        [_set:DataTables\Editor\Field:private] => both 
        [_setFormatter:DataTables\Editor\Field:private] => 
        [_setFormatterOpts:DataTables\Editor\Field:private] => 
        [_setValue:DataTables\Editor\Field:private] => 
        [_validator:DataTables\Editor\Field:private] => Array ( ) 
        [_upload:DataTables\Editor\Field:private] => 
        [_xss:DataTables\Editor\Field:private] => 
        [_xssFormat:DataTables\Editor\Field:private] => 1 
      ) 
    

    there are 34 more for the other columns, seems a lot of data for one column.

    And I couldn't leave the printr in the Editor as it stops the other tables from rendering, but can uncomment it whenever needed.

  • allanallan Posts: 54,688Questions: 1Answers: 8,553 Site admin

    I've just tried this with v2.0.5 of the PHP libraries for Editor, and I'm not getting quite the same error message - what version of the libraries are you using please?

    This is with the code as is above, so the session variables won't have values, which is presumably the same as your not logged in state.

    The error I did get however was:

    1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'system SY ON `SY`.`id` = `T`.`subsystem`  LEFT JOIN cxprocedure C1 ON `C1`.`id` ' at line 1
    

    That is because SYSTEM is a reserved word in MySQL.

    I've just made a commit that will resolve that error. Perhaps you could try using the libraries from that repo to ensure you are on the latest version?

    Allan

  • rob1strob1st Posts: 57Questions: 12Answers: 0

    I uploaded all the libraries from the 2.0.5 when I upgraded.

    I need to rename the system table, aware of that but have been putting it off because I got lazy.

    I'll work on that later this weekend see if that makes any issue.

  • rob1strob1st Posts: 57Questions: 12Answers: 0

    Going to upload the new libraries to test tonight, just so this doesn't go stale. Real life got in the way.

Sign In or Register to comment.