@@ -29,31 +29,31 @@ discard block |
||
| 29 | 29 | // parameter represents the DataTables column identifier. In this case simple |
| 30 | 30 | // indexes |
| 31 | 31 | $columns = array( |
| 32 | - array( 'db' => 'first_name', 'dt' => 0 ), |
|
| 33 | - array( 'db' => 'last_name', 'dt' => 1 ), |
|
| 34 | - array( 'db' => 'position', 'dt' => 2 ), |
|
| 35 | - array( 'db' => 'office', 'dt' => 3 ), |
|
| 36 | - array( |
|
| 37 | - 'db' => 'start_date', |
|
| 38 | - 'dt' => 4, |
|
| 39 | - 'formatter' => function( $d, $row ) { |
|
| 40 | - return date( 'jS M y', strtotime($d)); |
|
| 41 | - } |
|
| 42 | - ), |
|
| 43 | - array( |
|
| 44 | - 'db' => 'salary', |
|
| 45 | - 'dt' => 5, |
|
| 46 | - 'formatter' => function( $d, $row ) { |
|
| 47 | - return '$'.number_format($d); |
|
| 48 | - } |
|
| 49 | - ) |
|
| 32 | + array( 'db' => 'first_name', 'dt' => 0 ), |
|
| 33 | + array( 'db' => 'last_name', 'dt' => 1 ), |
|
| 34 | + array( 'db' => 'position', 'dt' => 2 ), |
|
| 35 | + array( 'db' => 'office', 'dt' => 3 ), |
|
| 36 | + array( |
|
| 37 | + 'db' => 'start_date', |
|
| 38 | + 'dt' => 4, |
|
| 39 | + 'formatter' => function( $d, $row ) { |
|
| 40 | + return date( 'jS M y', strtotime($d)); |
|
| 41 | + } |
|
| 42 | + ), |
|
| 43 | + array( |
|
| 44 | + 'db' => 'salary', |
|
| 45 | + 'dt' => 5, |
|
| 46 | + 'formatter' => function( $d, $row ) { |
|
| 47 | + return '$'.number_format($d); |
|
| 48 | + } |
|
| 49 | + ) |
|
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | 52 | $sql_details = array( |
| 53 | - 'user' => '', |
|
| 54 | - 'pass' => '', |
|
| 55 | - 'db' => '', |
|
| 56 | - 'host' => '' |
|
| 53 | + 'user' => '', |
|
| 54 | + 'pass' => '', |
|
| 55 | + 'db' => '', |
|
| 56 | + 'host' => '' |
|
| 57 | 57 | ); |
| 58 | 58 | |
| 59 | 59 | |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | // Validate the JSONP to make use it is an okay Javascript function to execute |
| 67 | 67 | $jsonp = preg_match('/^[$A-Z_][0-9A-Z_$]*$/i', $_GET['callback']) ? |
| 68 | - $_GET['callback'] : |
|
| 69 | - false; |
|
| 68 | + $_GET['callback'] : |
|
| 69 | + false; |
|
| 70 | 70 | |
| 71 | 71 | if ( $jsonp ) { |
| 72 | - echo $jsonp.'('.json_encode( |
|
| 73 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 74 | - ).');'; |
|
| 72 | + echo $jsonp.'('.json_encode( |
|
| 73 | + SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 74 | + ).');'; |
|
| 75 | 75 | } |
| 76 | 76 | |
@@ -29,22 +29,22 @@ discard block |
||
| 29 | 29 | // parameter represents the DataTables column identifier. In this case simple |
| 30 | 30 | // indexes |
| 31 | 31 | $columns = array( |
| 32 | - array( 'db' => 'first_name', 'dt' => 0 ), |
|
| 33 | - array( 'db' => 'last_name', 'dt' => 1 ), |
|
| 34 | - array( 'db' => 'position', 'dt' => 2 ), |
|
| 35 | - array( 'db' => 'office', 'dt' => 3 ), |
|
| 32 | + array('db' => 'first_name', 'dt' => 0), |
|
| 33 | + array('db' => 'last_name', 'dt' => 1), |
|
| 34 | + array('db' => 'position', 'dt' => 2), |
|
| 35 | + array('db' => 'office', 'dt' => 3), |
|
| 36 | 36 | array( |
| 37 | 37 | 'db' => 'start_date', |
| 38 | 38 | 'dt' => 4, |
| 39 | - 'formatter' => function( $d, $row ) { |
|
| 40 | - return date( 'jS M y', strtotime($d)); |
|
| 39 | + 'formatter' => function($d, $row) { |
|
| 40 | + return date('jS M y', strtotime($d)); |
|
| 41 | 41 | } |
| 42 | 42 | ), |
| 43 | 43 | array( |
| 44 | 44 | 'db' => 'salary', |
| 45 | 45 | 'dt' => 5, |
| 46 | - 'formatter' => function( $d, $row ) { |
|
| 47 | - return '$'.number_format($d); |
|
| 46 | + 'formatter' => function($d, $row) { |
|
| 47 | + return '$' . number_format($d); |
|
| 48 | 48 | } |
| 49 | 49 | ) |
| 50 | 50 | ); |
@@ -61,16 +61,15 @@ discard block |
||
| 61 | 61 | * If you just want to use the basic configuration for DataTables with PHP |
| 62 | 62 | * server-side, there is no need to edit below this line. |
| 63 | 63 | */ |
| 64 | -require( 'ssp.class.php' ); |
|
| 64 | +require('ssp.class.php'); |
|
| 65 | 65 | |
| 66 | 66 | // Validate the JSONP to make use it is an okay Javascript function to execute |
| 67 | 67 | $jsonp = preg_match('/^[$A-Z_][0-9A-Z_$]*$/i', $_GET['callback']) ? |
| 68 | - $_GET['callback'] : |
|
| 69 | - false; |
|
| 68 | + $_GET['callback'] : false; |
|
| 70 | 69 | |
| 71 | -if ( $jsonp ) { |
|
| 72 | - echo $jsonp.'('.json_encode( |
|
| 73 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 74 | - ).');'; |
|
| 70 | +if ($jsonp) { |
|
| 71 | + echo $jsonp . '(' . json_encode( |
|
| 72 | + SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns) |
|
| 73 | + ) . ');'; |
|
| 75 | 74 | } |
| 76 | 75 | |
@@ -29,42 +29,42 @@ discard block |
||
| 29 | 29 | // parameter represents the DataTables column identifier. In this case simple |
| 30 | 30 | // indexes + the primary key column for the id |
| 31 | 31 | $columns = array( |
| 32 | - array( |
|
| 33 | - 'db' => 'id', |
|
| 34 | - 'dt' => 'DT_RowId', |
|
| 35 | - 'formatter' => function( $d, $row ) { |
|
| 36 | - // Technically a DOM id cannot start with an integer, so we prefix |
|
| 37 | - // a string. This can also be useful if you have multiple tables |
|
| 38 | - // to ensure that the id is unique with a different prefix |
|
| 39 | - return 'row_'.$d; |
|
| 40 | - } |
|
| 41 | - ), |
|
| 42 | - array( 'db' => 'first_name', 'dt' => 0 ), |
|
| 43 | - array( 'db' => 'last_name', 'dt' => 1 ), |
|
| 44 | - array( 'db' => 'position', 'dt' => 2 ), |
|
| 45 | - array( 'db' => 'office', 'dt' => 3 ), |
|
| 46 | - array( |
|
| 47 | - 'db' => 'start_date', |
|
| 48 | - 'dt' => 4, |
|
| 49 | - 'formatter' => function( $d, $row ) { |
|
| 50 | - return date( 'jS M y', strtotime($d)); |
|
| 51 | - } |
|
| 52 | - ), |
|
| 53 | - array( |
|
| 54 | - 'db' => 'salary', |
|
| 55 | - 'dt' => 5, |
|
| 56 | - 'formatter' => function( $d, $row ) { |
|
| 57 | - return '$'.number_format($d); |
|
| 58 | - } |
|
| 59 | - ) |
|
| 32 | + array( |
|
| 33 | + 'db' => 'id', |
|
| 34 | + 'dt' => 'DT_RowId', |
|
| 35 | + 'formatter' => function( $d, $row ) { |
|
| 36 | + // Technically a DOM id cannot start with an integer, so we prefix |
|
| 37 | + // a string. This can also be useful if you have multiple tables |
|
| 38 | + // to ensure that the id is unique with a different prefix |
|
| 39 | + return 'row_'.$d; |
|
| 40 | + } |
|
| 41 | + ), |
|
| 42 | + array( 'db' => 'first_name', 'dt' => 0 ), |
|
| 43 | + array( 'db' => 'last_name', 'dt' => 1 ), |
|
| 44 | + array( 'db' => 'position', 'dt' => 2 ), |
|
| 45 | + array( 'db' => 'office', 'dt' => 3 ), |
|
| 46 | + array( |
|
| 47 | + 'db' => 'start_date', |
|
| 48 | + 'dt' => 4, |
|
| 49 | + 'formatter' => function( $d, $row ) { |
|
| 50 | + return date( 'jS M y', strtotime($d)); |
|
| 51 | + } |
|
| 52 | + ), |
|
| 53 | + array( |
|
| 54 | + 'db' => 'salary', |
|
| 55 | + 'dt' => 5, |
|
| 56 | + 'formatter' => function( $d, $row ) { |
|
| 57 | + return '$'.number_format($d); |
|
| 58 | + } |
|
| 59 | + ) |
|
| 60 | 60 | ); |
| 61 | 61 | |
| 62 | 62 | // SQL server connection information |
| 63 | 63 | $sql_details = array( |
| 64 | - 'user' => '', |
|
| 65 | - 'pass' => '', |
|
| 66 | - 'db' => '', |
|
| 67 | - 'host' => '' |
|
| 64 | + 'user' => '', |
|
| 65 | + 'pass' => '', |
|
| 66 | + 'db' => '', |
|
| 67 | + 'host' => '' |
|
| 68 | 68 | ); |
| 69 | 69 | |
| 70 | 70 | |
@@ -76,6 +76,6 @@ discard block |
||
| 76 | 76 | require( 'ssp.class.php' ); |
| 77 | 77 | |
| 78 | 78 | echo json_encode( |
| 79 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 79 | + SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 80 | 80 | ); |
| 81 | 81 | |
@@ -32,29 +32,29 @@ discard block |
||
| 32 | 32 | array( |
| 33 | 33 | 'db' => 'id', |
| 34 | 34 | 'dt' => 'DT_RowId', |
| 35 | - 'formatter' => function( $d, $row ) { |
|
| 35 | + 'formatter' => function($d, $row) { |
|
| 36 | 36 | // Technically a DOM id cannot start with an integer, so we prefix |
| 37 | 37 | // a string. This can also be useful if you have multiple tables |
| 38 | 38 | // to ensure that the id is unique with a different prefix |
| 39 | - return 'row_'.$d; |
|
| 39 | + return 'row_' . $d; |
|
| 40 | 40 | } |
| 41 | 41 | ), |
| 42 | - array( 'db' => 'first_name', 'dt' => 0 ), |
|
| 43 | - array( 'db' => 'last_name', 'dt' => 1 ), |
|
| 44 | - array( 'db' => 'position', 'dt' => 2 ), |
|
| 45 | - array( 'db' => 'office', 'dt' => 3 ), |
|
| 42 | + array('db' => 'first_name', 'dt' => 0), |
|
| 43 | + array('db' => 'last_name', 'dt' => 1), |
|
| 44 | + array('db' => 'position', 'dt' => 2), |
|
| 45 | + array('db' => 'office', 'dt' => 3), |
|
| 46 | 46 | array( |
| 47 | 47 | 'db' => 'start_date', |
| 48 | 48 | 'dt' => 4, |
| 49 | - 'formatter' => function( $d, $row ) { |
|
| 50 | - return date( 'jS M y', strtotime($d)); |
|
| 49 | + 'formatter' => function($d, $row) { |
|
| 50 | + return date('jS M y', strtotime($d)); |
|
| 51 | 51 | } |
| 52 | 52 | ), |
| 53 | 53 | array( |
| 54 | 54 | 'db' => 'salary', |
| 55 | 55 | 'dt' => 5, |
| 56 | - 'formatter' => function( $d, $row ) { |
|
| 57 | - return '$'.number_format($d); |
|
| 56 | + 'formatter' => function($d, $row) { |
|
| 57 | + return '$' . number_format($d); |
|
| 58 | 58 | } |
| 59 | 59 | ) |
| 60 | 60 | ); |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | * server-side, there is no need to edit below this line. |
| 74 | 74 | */ |
| 75 | 75 | |
| 76 | -require( 'ssp.class.php' ); |
|
| 76 | +require('ssp.class.php'); |
|
| 77 | 77 | |
| 78 | 78 | echo json_encode( |
| 79 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 79 | + SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns) |
|
| 80 | 80 | ); |
| 81 | 81 | |
@@ -29,32 +29,32 @@ discard block |
||
| 29 | 29 | // parameter represents the DataTables column identifier. In this case object |
| 30 | 30 | // parameter names |
| 31 | 31 | $columns = array( |
| 32 | - array( 'db' => 'first_name', 'dt' => 'first_name' ), |
|
| 33 | - array( 'db' => 'last_name', 'dt' => 'last_name' ), |
|
| 34 | - array( 'db' => 'position', 'dt' => 'position' ), |
|
| 35 | - array( 'db' => 'office', 'dt' => 'office' ), |
|
| 36 | - array( |
|
| 37 | - 'db' => 'start_date', |
|
| 38 | - 'dt' => 'start_date', |
|
| 39 | - 'formatter' => function( $d, $row ) { |
|
| 40 | - return date( 'jS M y', strtotime($d)); |
|
| 41 | - } |
|
| 42 | - ), |
|
| 43 | - array( |
|
| 44 | - 'db' => 'salary', |
|
| 45 | - 'dt' => 'salary', |
|
| 46 | - 'formatter' => function( $d, $row ) { |
|
| 47 | - return '$'.number_format($d); |
|
| 48 | - } |
|
| 49 | - ) |
|
| 32 | + array( 'db' => 'first_name', 'dt' => 'first_name' ), |
|
| 33 | + array( 'db' => 'last_name', 'dt' => 'last_name' ), |
|
| 34 | + array( 'db' => 'position', 'dt' => 'position' ), |
|
| 35 | + array( 'db' => 'office', 'dt' => 'office' ), |
|
| 36 | + array( |
|
| 37 | + 'db' => 'start_date', |
|
| 38 | + 'dt' => 'start_date', |
|
| 39 | + 'formatter' => function( $d, $row ) { |
|
| 40 | + return date( 'jS M y', strtotime($d)); |
|
| 41 | + } |
|
| 42 | + ), |
|
| 43 | + array( |
|
| 44 | + 'db' => 'salary', |
|
| 45 | + 'dt' => 'salary', |
|
| 46 | + 'formatter' => function( $d, $row ) { |
|
| 47 | + return '$'.number_format($d); |
|
| 48 | + } |
|
| 49 | + ) |
|
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | 52 | // SQL server connection information |
| 53 | 53 | $sql_details = array( |
| 54 | - 'user' => '', |
|
| 55 | - 'pass' => '', |
|
| 56 | - 'db' => '', |
|
| 57 | - 'host' => '' |
|
| 54 | + 'user' => '', |
|
| 55 | + 'pass' => '', |
|
| 56 | + 'db' => '', |
|
| 57 | + 'host' => '' |
|
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | 60 | |
@@ -66,6 +66,6 @@ discard block |
||
| 66 | 66 | require( 'ssp.class.php' ); |
| 67 | 67 | |
| 68 | 68 | echo json_encode( |
| 69 | - SSP::simple( $_POST, $sql_details, $table, $primaryKey, $columns ) |
|
| 69 | + SSP::simple( $_POST, $sql_details, $table, $primaryKey, $columns ) |
|
| 70 | 70 | ); |
| 71 | 71 | |
@@ -29,22 +29,22 @@ discard block |
||
| 29 | 29 | // parameter represents the DataTables column identifier. In this case object |
| 30 | 30 | // parameter names |
| 31 | 31 | $columns = array( |
| 32 | - array( 'db' => 'first_name', 'dt' => 'first_name' ), |
|
| 33 | - array( 'db' => 'last_name', 'dt' => 'last_name' ), |
|
| 34 | - array( 'db' => 'position', 'dt' => 'position' ), |
|
| 35 | - array( 'db' => 'office', 'dt' => 'office' ), |
|
| 32 | + array('db' => 'first_name', 'dt' => 'first_name'), |
|
| 33 | + array('db' => 'last_name', 'dt' => 'last_name'), |
|
| 34 | + array('db' => 'position', 'dt' => 'position'), |
|
| 35 | + array('db' => 'office', 'dt' => 'office'), |
|
| 36 | 36 | array( |
| 37 | 37 | 'db' => 'start_date', |
| 38 | 38 | 'dt' => 'start_date', |
| 39 | - 'formatter' => function( $d, $row ) { |
|
| 40 | - return date( 'jS M y', strtotime($d)); |
|
| 39 | + 'formatter' => function($d, $row) { |
|
| 40 | + return date('jS M y', strtotime($d)); |
|
| 41 | 41 | } |
| 42 | 42 | ), |
| 43 | 43 | array( |
| 44 | 44 | 'db' => 'salary', |
| 45 | 45 | 'dt' => 'salary', |
| 46 | - 'formatter' => function( $d, $row ) { |
|
| 47 | - return '$'.number_format($d); |
|
| 46 | + 'formatter' => function($d, $row) { |
|
| 47 | + return '$' . number_format($d); |
|
| 48 | 48 | } |
| 49 | 49 | ) |
| 50 | 50 | ); |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | * server-side, there is no need to edit below this line. |
| 64 | 64 | */ |
| 65 | 65 | |
| 66 | -require( 'ssp.class.php' ); |
|
| 66 | +require('ssp.class.php'); |
|
| 67 | 67 | |
| 68 | 68 | echo json_encode( |
| 69 | - SSP::simple( $_POST, $sql_details, $table, $primaryKey, $columns ) |
|
| 69 | + SSP::simple($_POST, $sql_details, $table, $primaryKey, $columns) |
|
| 70 | 70 | ); |
| 71 | 71 | |
@@ -29,32 +29,32 @@ discard block |
||
| 29 | 29 | // parameter represents the DataTables column identifier. In this case simple |
| 30 | 30 | // indexes |
| 31 | 31 | $columns = array( |
| 32 | - array( 'db' => 'first_name', 'dt' => 0 ), |
|
| 33 | - array( 'db' => 'last_name', 'dt' => 1 ), |
|
| 34 | - array( 'db' => 'position', 'dt' => 2 ), |
|
| 35 | - array( 'db' => 'office', 'dt' => 3 ), |
|
| 36 | - array( |
|
| 37 | - 'db' => 'start_date', |
|
| 38 | - 'dt' => 4, |
|
| 39 | - 'formatter' => function( $d, $row ) { |
|
| 40 | - return date( 'jS M y', strtotime($d)); |
|
| 41 | - } |
|
| 42 | - ), |
|
| 43 | - array( |
|
| 44 | - 'db' => 'salary', |
|
| 45 | - 'dt' => 5, |
|
| 46 | - 'formatter' => function( $d, $row ) { |
|
| 47 | - return '$'.number_format($d); |
|
| 48 | - } |
|
| 49 | - ) |
|
| 32 | + array( 'db' => 'first_name', 'dt' => 0 ), |
|
| 33 | + array( 'db' => 'last_name', 'dt' => 1 ), |
|
| 34 | + array( 'db' => 'position', 'dt' => 2 ), |
|
| 35 | + array( 'db' => 'office', 'dt' => 3 ), |
|
| 36 | + array( |
|
| 37 | + 'db' => 'start_date', |
|
| 38 | + 'dt' => 4, |
|
| 39 | + 'formatter' => function( $d, $row ) { |
|
| 40 | + return date( 'jS M y', strtotime($d)); |
|
| 41 | + } |
|
| 42 | + ), |
|
| 43 | + array( |
|
| 44 | + 'db' => 'salary', |
|
| 45 | + 'dt' => 5, |
|
| 46 | + 'formatter' => function( $d, $row ) { |
|
| 47 | + return '$'.number_format($d); |
|
| 48 | + } |
|
| 49 | + ) |
|
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | 52 | // SQL server connection information |
| 53 | 53 | $sql_details = array( |
| 54 | - 'user' => '', |
|
| 55 | - 'pass' => '', |
|
| 56 | - 'db' => '', |
|
| 57 | - 'host' => '' |
|
| 54 | + 'user' => '', |
|
| 55 | + 'pass' => '', |
|
| 56 | + 'db' => '', |
|
| 57 | + 'host' => '' |
|
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | 60 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | require( 'ssp.class.php' ); |
| 67 | 67 | |
| 68 | 68 | echo json_encode( |
| 69 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 69 | + SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | 72 | |
@@ -29,22 +29,22 @@ discard block |
||
| 29 | 29 | // parameter represents the DataTables column identifier. In this case simple |
| 30 | 30 | // indexes |
| 31 | 31 | $columns = array( |
| 32 | - array( 'db' => 'first_name', 'dt' => 0 ), |
|
| 33 | - array( 'db' => 'last_name', 'dt' => 1 ), |
|
| 34 | - array( 'db' => 'position', 'dt' => 2 ), |
|
| 35 | - array( 'db' => 'office', 'dt' => 3 ), |
|
| 32 | + array('db' => 'first_name', 'dt' => 0), |
|
| 33 | + array('db' => 'last_name', 'dt' => 1), |
|
| 34 | + array('db' => 'position', 'dt' => 2), |
|
| 35 | + array('db' => 'office', 'dt' => 3), |
|
| 36 | 36 | array( |
| 37 | 37 | 'db' => 'start_date', |
| 38 | 38 | 'dt' => 4, |
| 39 | - 'formatter' => function( $d, $row ) { |
|
| 40 | - return date( 'jS M y', strtotime($d)); |
|
| 39 | + 'formatter' => function($d, $row) { |
|
| 40 | + return date('jS M y', strtotime($d)); |
|
| 41 | 41 | } |
| 42 | 42 | ), |
| 43 | 43 | array( |
| 44 | 44 | 'db' => 'salary', |
| 45 | 45 | 'dt' => 5, |
| 46 | - 'formatter' => function( $d, $row ) { |
|
| 47 | - return '$'.number_format($d); |
|
| 46 | + 'formatter' => function($d, $row) { |
|
| 47 | + return '$' . number_format($d); |
|
| 48 | 48 | } |
| 49 | 49 | ) |
| 50 | 50 | ); |
@@ -63,10 +63,10 @@ discard block |
||
| 63 | 63 | * server-side, there is no need to edit below this line. |
| 64 | 64 | */ |
| 65 | 65 | |
| 66 | -require( 'ssp.class.php' ); |
|
| 66 | +require('ssp.class.php'); |
|
| 67 | 67 | |
| 68 | 68 | echo json_encode( |
| 69 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 69 | + SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns) |
|
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | 72 | |
@@ -19,502 +19,502 @@ |
||
| 19 | 19 | // REMOVE THIS BLOCK - used for DataTables test environment only! |
| 20 | 20 | $file = $_SERVER['DOCUMENT_ROOT'].'/datatables/mysql.php'; |
| 21 | 21 | if ( is_file( $file ) ) { |
| 22 | - include( $file ); |
|
| 22 | + include( $file ); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | class SSP { |
| 27 | - /** |
|
| 28 | - * Create the data output array for the DataTables rows |
|
| 29 | - * |
|
| 30 | - * @param array $columns Column information array |
|
| 31 | - * @param array $data Data from the SQL get |
|
| 32 | - * @return array Formatted data in a row based format |
|
| 33 | - */ |
|
| 34 | - static function data_output ( $columns, $data ) |
|
| 35 | - { |
|
| 36 | - $out = array(); |
|
| 37 | - |
|
| 38 | - for ( $i=0, $ien=count($data) ; $i<$ien ; $i++ ) { |
|
| 39 | - $row = array(); |
|
| 40 | - |
|
| 41 | - for ( $j=0, $jen=count($columns) ; $j<$jen ; $j++ ) { |
|
| 42 | - $column = $columns[$j]; |
|
| 43 | - |
|
| 44 | - // Is there a formatter? |
|
| 45 | - if ( isset( $column['formatter'] ) ) { |
|
| 46 | - $row[ $column['dt'] ] = $column['formatter']( $data[$i][ $column['db'] ], $data[$i] ); |
|
| 47 | - } |
|
| 48 | - else { |
|
| 49 | - $row[ $column['dt'] ] = $data[$i][ $columns[$j]['db'] ]; |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - $out[] = $row; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - return $out; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Database connection |
|
| 62 | - * |
|
| 63 | - * Obtain an PHP PDO connection from a connection details array |
|
| 64 | - * |
|
| 65 | - * @param array $conn SQL connection details. The array should have |
|
| 66 | - * the following properties |
|
| 67 | - * * host - host name |
|
| 68 | - * * db - database name |
|
| 69 | - * * user - user name |
|
| 70 | - * * pass - user password |
|
| 71 | - * @return resource PDO connection |
|
| 72 | - */ |
|
| 73 | - static function db ( $conn ) |
|
| 74 | - { |
|
| 75 | - if ( is_array( $conn ) ) { |
|
| 76 | - return self::sql_connect( $conn ); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - return $conn; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Paging |
|
| 85 | - * |
|
| 86 | - * Construct the LIMIT clause for server-side processing SQL query |
|
| 87 | - * |
|
| 88 | - * @param array $request Data sent to server by DataTables |
|
| 89 | - * @param array $columns Column information array |
|
| 90 | - * @return string SQL limit clause |
|
| 91 | - */ |
|
| 92 | - static function limit ( $request, $columns ) |
|
| 93 | - { |
|
| 94 | - $limit = ''; |
|
| 95 | - |
|
| 96 | - if ( isset($request['start']) && $request['length'] != -1 ) { |
|
| 97 | - $limit = "LIMIT ".intval($request['start']).", ".intval($request['length']); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return $limit; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Ordering |
|
| 106 | - * |
|
| 107 | - * Construct the ORDER BY clause for server-side processing SQL query |
|
| 108 | - * |
|
| 109 | - * @param array $request Data sent to server by DataTables |
|
| 110 | - * @param array $columns Column information array |
|
| 111 | - * @return string SQL order by clause |
|
| 112 | - */ |
|
| 113 | - static function order ( $request, $columns ) |
|
| 114 | - { |
|
| 115 | - $order = ''; |
|
| 116 | - |
|
| 117 | - if ( isset($request['order']) && count($request['order']) ) { |
|
| 118 | - $orderBy = array(); |
|
| 119 | - $dtColumns = self::pluck( $columns, 'dt' ); |
|
| 120 | - |
|
| 121 | - for ( $i=0, $ien=count($request['order']) ; $i<$ien ; $i++ ) { |
|
| 122 | - // Convert the column index into the column data property |
|
| 123 | - $columnIdx = intval($request['order'][$i]['column']); |
|
| 124 | - $requestColumn = $request['columns'][$columnIdx]; |
|
| 125 | - |
|
| 126 | - $columnIdx = array_search( $requestColumn['data'], $dtColumns ); |
|
| 127 | - $column = $columns[ $columnIdx ]; |
|
| 128 | - |
|
| 129 | - if ( $requestColumn['orderable'] == 'true' ) { |
|
| 130 | - $dir = $request['order'][$i]['dir'] === 'asc' ? |
|
| 131 | - 'ASC' : |
|
| 132 | - 'DESC'; |
|
| 133 | - |
|
| 134 | - $orderBy[] = '`'.$column['db'].'` '.$dir; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $order = 'ORDER BY '.implode(', ', $orderBy); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $order; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Searching / Filtering |
|
| 147 | - * |
|
| 148 | - * Construct the WHERE clause for server-side processing SQL query. |
|
| 149 | - * |
|
| 150 | - * NOTE this does not match the built-in DataTables filtering which does it |
|
| 151 | - * word by word on any field. It's possible to do here performance on large |
|
| 152 | - * databases would be very poor |
|
| 153 | - * |
|
| 154 | - * @param array $request Data sent to server by DataTables |
|
| 155 | - * @param array $columns Column information array |
|
| 156 | - * @param array $bindings Array of values for PDO bindings, used in the |
|
| 157 | - * sql_exec() function |
|
| 158 | - * @return string SQL where clause |
|
| 159 | - */ |
|
| 160 | - static function filter ( $request, $columns, &$bindings ) |
|
| 161 | - { |
|
| 162 | - $globalSearch = array(); |
|
| 163 | - $columnSearch = array(); |
|
| 164 | - $dtColumns = self::pluck( $columns, 'dt' ); |
|
| 165 | - |
|
| 166 | - if ( isset($request['search']) && $request['search']['value'] != '' ) { |
|
| 167 | - $str = $request['search']['value']; |
|
| 168 | - |
|
| 169 | - for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) { |
|
| 170 | - $requestColumn = $request['columns'][$i]; |
|
| 171 | - $columnIdx = array_search( $requestColumn['data'], $dtColumns ); |
|
| 172 | - $column = $columns[ $columnIdx ]; |
|
| 173 | - |
|
| 174 | - if ( $requestColumn['searchable'] == 'true' ) { |
|
| 175 | - $binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR ); |
|
| 176 | - $globalSearch[] = "`".$column['db']."` LIKE ".$binding; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // Individual column filtering |
|
| 182 | - for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) { |
|
| 183 | - $requestColumn = $request['columns'][$i]; |
|
| 184 | - $columnIdx = array_search( $requestColumn['data'], $dtColumns ); |
|
| 185 | - $column = $columns[ $columnIdx ]; |
|
| 186 | - |
|
| 187 | - $str = $requestColumn['search']['value']; |
|
| 188 | - |
|
| 189 | - if ( $requestColumn['searchable'] == 'true' && |
|
| 190 | - $str != '' ) { |
|
| 191 | - $binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR ); |
|
| 192 | - $columnSearch[] = "`".$column['db']."` LIKE ".$binding; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - // Combine the filters into a single string |
|
| 197 | - $where = ''; |
|
| 198 | - |
|
| 199 | - if ( count( $globalSearch ) ) { |
|
| 200 | - $where = '('.implode(' OR ', $globalSearch).')'; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - if ( count( $columnSearch ) ) { |
|
| 204 | - $where = $where === '' ? |
|
| 205 | - implode(' AND ', $columnSearch) : |
|
| 206 | - $where .' AND '. implode(' AND ', $columnSearch); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if ( $where !== '' ) { |
|
| 210 | - $where = 'WHERE '.$where; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - return $where; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Perform the SQL queries needed for an server-side processing requested, |
|
| 219 | - * utilising the helper functions of this class, limit(), order() and |
|
| 220 | - * filter() among others. The returned array is ready to be encoded as JSON |
|
| 221 | - * in response to an SSP request, or can be modified if needed before |
|
| 222 | - * sending back to the client. |
|
| 223 | - * |
|
| 224 | - * @param array $request Data sent to server by DataTables |
|
| 225 | - * @param array|PDO $conn PDO connection resource or connection parameters array |
|
| 226 | - * @param string $table SQL table to query |
|
| 227 | - * @param string $primaryKey Primary key of the table |
|
| 228 | - * @param array $columns Column information array |
|
| 229 | - * @return array Server-side processing response array |
|
| 230 | - */ |
|
| 231 | - static function simple ( $request, $conn, $table, $primaryKey, $columns ) |
|
| 232 | - { |
|
| 233 | - $bindings = array(); |
|
| 234 | - $db = self::db( $conn ); |
|
| 235 | - |
|
| 236 | - // Build the SQL query string from the request |
|
| 237 | - $limit = self::limit( $request, $columns ); |
|
| 238 | - $order = self::order( $request, $columns ); |
|
| 239 | - $where = self::filter( $request, $columns, $bindings ); |
|
| 240 | - |
|
| 241 | - // Main query to actually get the data |
|
| 242 | - $data = self::sql_exec( $db, $bindings, |
|
| 243 | - "SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", self::pluck($columns, 'db'))."` |
|
| 27 | + /** |
|
| 28 | + * Create the data output array for the DataTables rows |
|
| 29 | + * |
|
| 30 | + * @param array $columns Column information array |
|
| 31 | + * @param array $data Data from the SQL get |
|
| 32 | + * @return array Formatted data in a row based format |
|
| 33 | + */ |
|
| 34 | + static function data_output ( $columns, $data ) |
|
| 35 | + { |
|
| 36 | + $out = array(); |
|
| 37 | + |
|
| 38 | + for ( $i=0, $ien=count($data) ; $i<$ien ; $i++ ) { |
|
| 39 | + $row = array(); |
|
| 40 | + |
|
| 41 | + for ( $j=0, $jen=count($columns) ; $j<$jen ; $j++ ) { |
|
| 42 | + $column = $columns[$j]; |
|
| 43 | + |
|
| 44 | + // Is there a formatter? |
|
| 45 | + if ( isset( $column['formatter'] ) ) { |
|
| 46 | + $row[ $column['dt'] ] = $column['formatter']( $data[$i][ $column['db'] ], $data[$i] ); |
|
| 47 | + } |
|
| 48 | + else { |
|
| 49 | + $row[ $column['dt'] ] = $data[$i][ $columns[$j]['db'] ]; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + $out[] = $row; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return $out; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Database connection |
|
| 62 | + * |
|
| 63 | + * Obtain an PHP PDO connection from a connection details array |
|
| 64 | + * |
|
| 65 | + * @param array $conn SQL connection details. The array should have |
|
| 66 | + * the following properties |
|
| 67 | + * * host - host name |
|
| 68 | + * * db - database name |
|
| 69 | + * * user - user name |
|
| 70 | + * * pass - user password |
|
| 71 | + * @return resource PDO connection |
|
| 72 | + */ |
|
| 73 | + static function db ( $conn ) |
|
| 74 | + { |
|
| 75 | + if ( is_array( $conn ) ) { |
|
| 76 | + return self::sql_connect( $conn ); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + return $conn; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Paging |
|
| 85 | + * |
|
| 86 | + * Construct the LIMIT clause for server-side processing SQL query |
|
| 87 | + * |
|
| 88 | + * @param array $request Data sent to server by DataTables |
|
| 89 | + * @param array $columns Column information array |
|
| 90 | + * @return string SQL limit clause |
|
| 91 | + */ |
|
| 92 | + static function limit ( $request, $columns ) |
|
| 93 | + { |
|
| 94 | + $limit = ''; |
|
| 95 | + |
|
| 96 | + if ( isset($request['start']) && $request['length'] != -1 ) { |
|
| 97 | + $limit = "LIMIT ".intval($request['start']).", ".intval($request['length']); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return $limit; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Ordering |
|
| 106 | + * |
|
| 107 | + * Construct the ORDER BY clause for server-side processing SQL query |
|
| 108 | + * |
|
| 109 | + * @param array $request Data sent to server by DataTables |
|
| 110 | + * @param array $columns Column information array |
|
| 111 | + * @return string SQL order by clause |
|
| 112 | + */ |
|
| 113 | + static function order ( $request, $columns ) |
|
| 114 | + { |
|
| 115 | + $order = ''; |
|
| 116 | + |
|
| 117 | + if ( isset($request['order']) && count($request['order']) ) { |
|
| 118 | + $orderBy = array(); |
|
| 119 | + $dtColumns = self::pluck( $columns, 'dt' ); |
|
| 120 | + |
|
| 121 | + for ( $i=0, $ien=count($request['order']) ; $i<$ien ; $i++ ) { |
|
| 122 | + // Convert the column index into the column data property |
|
| 123 | + $columnIdx = intval($request['order'][$i]['column']); |
|
| 124 | + $requestColumn = $request['columns'][$columnIdx]; |
|
| 125 | + |
|
| 126 | + $columnIdx = array_search( $requestColumn['data'], $dtColumns ); |
|
| 127 | + $column = $columns[ $columnIdx ]; |
|
| 128 | + |
|
| 129 | + if ( $requestColumn['orderable'] == 'true' ) { |
|
| 130 | + $dir = $request['order'][$i]['dir'] === 'asc' ? |
|
| 131 | + 'ASC' : |
|
| 132 | + 'DESC'; |
|
| 133 | + |
|
| 134 | + $orderBy[] = '`'.$column['db'].'` '.$dir; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $order = 'ORDER BY '.implode(', ', $orderBy); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $order; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Searching / Filtering |
|
| 147 | + * |
|
| 148 | + * Construct the WHERE clause for server-side processing SQL query. |
|
| 149 | + * |
|
| 150 | + * NOTE this does not match the built-in DataTables filtering which does it |
|
| 151 | + * word by word on any field. It's possible to do here performance on large |
|
| 152 | + * databases would be very poor |
|
| 153 | + * |
|
| 154 | + * @param array $request Data sent to server by DataTables |
|
| 155 | + * @param array $columns Column information array |
|
| 156 | + * @param array $bindings Array of values for PDO bindings, used in the |
|
| 157 | + * sql_exec() function |
|
| 158 | + * @return string SQL where clause |
|
| 159 | + */ |
|
| 160 | + static function filter ( $request, $columns, &$bindings ) |
|
| 161 | + { |
|
| 162 | + $globalSearch = array(); |
|
| 163 | + $columnSearch = array(); |
|
| 164 | + $dtColumns = self::pluck( $columns, 'dt' ); |
|
| 165 | + |
|
| 166 | + if ( isset($request['search']) && $request['search']['value'] != '' ) { |
|
| 167 | + $str = $request['search']['value']; |
|
| 168 | + |
|
| 169 | + for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) { |
|
| 170 | + $requestColumn = $request['columns'][$i]; |
|
| 171 | + $columnIdx = array_search( $requestColumn['data'], $dtColumns ); |
|
| 172 | + $column = $columns[ $columnIdx ]; |
|
| 173 | + |
|
| 174 | + if ( $requestColumn['searchable'] == 'true' ) { |
|
| 175 | + $binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR ); |
|
| 176 | + $globalSearch[] = "`".$column['db']."` LIKE ".$binding; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // Individual column filtering |
|
| 182 | + for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) { |
|
| 183 | + $requestColumn = $request['columns'][$i]; |
|
| 184 | + $columnIdx = array_search( $requestColumn['data'], $dtColumns ); |
|
| 185 | + $column = $columns[ $columnIdx ]; |
|
| 186 | + |
|
| 187 | + $str = $requestColumn['search']['value']; |
|
| 188 | + |
|
| 189 | + if ( $requestColumn['searchable'] == 'true' && |
|
| 190 | + $str != '' ) { |
|
| 191 | + $binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR ); |
|
| 192 | + $columnSearch[] = "`".$column['db']."` LIKE ".$binding; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + // Combine the filters into a single string |
|
| 197 | + $where = ''; |
|
| 198 | + |
|
| 199 | + if ( count( $globalSearch ) ) { |
|
| 200 | + $where = '('.implode(' OR ', $globalSearch).')'; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + if ( count( $columnSearch ) ) { |
|
| 204 | + $where = $where === '' ? |
|
| 205 | + implode(' AND ', $columnSearch) : |
|
| 206 | + $where .' AND '. implode(' AND ', $columnSearch); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if ( $where !== '' ) { |
|
| 210 | + $where = 'WHERE '.$where; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + return $where; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Perform the SQL queries needed for an server-side processing requested, |
|
| 219 | + * utilising the helper functions of this class, limit(), order() and |
|
| 220 | + * filter() among others. The returned array is ready to be encoded as JSON |
|
| 221 | + * in response to an SSP request, or can be modified if needed before |
|
| 222 | + * sending back to the client. |
|
| 223 | + * |
|
| 224 | + * @param array $request Data sent to server by DataTables |
|
| 225 | + * @param array|PDO $conn PDO connection resource or connection parameters array |
|
| 226 | + * @param string $table SQL table to query |
|
| 227 | + * @param string $primaryKey Primary key of the table |
|
| 228 | + * @param array $columns Column information array |
|
| 229 | + * @return array Server-side processing response array |
|
| 230 | + */ |
|
| 231 | + static function simple ( $request, $conn, $table, $primaryKey, $columns ) |
|
| 232 | + { |
|
| 233 | + $bindings = array(); |
|
| 234 | + $db = self::db( $conn ); |
|
| 235 | + |
|
| 236 | + // Build the SQL query string from the request |
|
| 237 | + $limit = self::limit( $request, $columns ); |
|
| 238 | + $order = self::order( $request, $columns ); |
|
| 239 | + $where = self::filter( $request, $columns, $bindings ); |
|
| 240 | + |
|
| 241 | + // Main query to actually get the data |
|
| 242 | + $data = self::sql_exec( $db, $bindings, |
|
| 243 | + "SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", self::pluck($columns, 'db'))."` |
|
| 244 | 244 | FROM `$table` |
| 245 | 245 | $where |
| 246 | 246 | $order |
| 247 | 247 | $limit" |
| 248 | - ); |
|
| 248 | + ); |
|
| 249 | 249 | |
| 250 | - // Data set length after filtering |
|
| 251 | - $resFilterLength = self::sql_exec( $db, |
|
| 252 | - "SELECT FOUND_ROWS()" |
|
| 253 | - ); |
|
| 254 | - $recordsFiltered = $resFilterLength[0][0]; |
|
| 250 | + // Data set length after filtering |
|
| 251 | + $resFilterLength = self::sql_exec( $db, |
|
| 252 | + "SELECT FOUND_ROWS()" |
|
| 253 | + ); |
|
| 254 | + $recordsFiltered = $resFilterLength[0][0]; |
|
| 255 | 255 | |
| 256 | - // Total data set length |
|
| 257 | - $resTotalLength = self::sql_exec( $db, |
|
| 258 | - "SELECT COUNT(`{$primaryKey}`) |
|
| 256 | + // Total data set length |
|
| 257 | + $resTotalLength = self::sql_exec( $db, |
|
| 258 | + "SELECT COUNT(`{$primaryKey}`) |
|
| 259 | 259 | FROM `$table`" |
| 260 | - ); |
|
| 261 | - $recordsTotal = $resTotalLength[0][0]; |
|
| 260 | + ); |
|
| 261 | + $recordsTotal = $resTotalLength[0][0]; |
|
| 262 | 262 | |
| 263 | 263 | |
| 264 | - /* |
|
| 264 | + /* |
|
| 265 | 265 | * Output |
| 266 | 266 | */ |
| 267 | - return array( |
|
| 268 | - "draw" => intval( $request['draw'] ), |
|
| 269 | - "recordsTotal" => intval( $recordsTotal ), |
|
| 270 | - "recordsFiltered" => intval( $recordsFiltered ), |
|
| 271 | - "data" => self::data_output( $columns, $data ) |
|
| 272 | - ); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * The difference between this method and the `simple` one, is that you can |
|
| 278 | - * apply additional `where` conditions to the SQL queries. These can be in |
|
| 279 | - * one of two forms: |
|
| 280 | - * |
|
| 281 | - * * 'Result condition' - This is applied to the result set, but not the |
|
| 282 | - * overall paging information query - i.e. it will not effect the number |
|
| 283 | - * of records that a user sees they can have access to. This should be |
|
| 284 | - * used when you want apply a filtering condition that the user has sent. |
|
| 285 | - * * 'All condition' - This is applied to all queries that are made and |
|
| 286 | - * reduces the number of records that the user can access. This should be |
|
| 287 | - * used in conditions where you don't want the user to ever have access to |
|
| 288 | - * particular records (for example, restricting by a login id). |
|
| 289 | - * |
|
| 290 | - * @param array $request Data sent to server by DataTables |
|
| 291 | - * @param array|PDO $conn PDO connection resource or connection parameters array |
|
| 292 | - * @param string $table SQL table to query |
|
| 293 | - * @param string $primaryKey Primary key of the table |
|
| 294 | - * @param array $columns Column information array |
|
| 295 | - * @param string $whereResult WHERE condition to apply to the result set |
|
| 296 | - * @param string $whereAll WHERE condition to apply to all queries |
|
| 297 | - * @return array Server-side processing response array |
|
| 298 | - */ |
|
| 299 | - static function complex ( $request, $conn, $table, $primaryKey, $columns, $whereResult=null, $whereAll=null ) |
|
| 300 | - { |
|
| 301 | - $bindings = array(); |
|
| 302 | - $db = self::db( $conn ); |
|
| 303 | - $localWhereResult = array(); |
|
| 304 | - $localWhereAll = array(); |
|
| 305 | - $whereAllSql = ''; |
|
| 306 | - |
|
| 307 | - // Build the SQL query string from the request |
|
| 308 | - $limit = self::limit( $request, $columns ); |
|
| 309 | - $order = self::order( $request, $columns ); |
|
| 310 | - $where = self::filter( $request, $columns, $bindings ); |
|
| 311 | - |
|
| 312 | - $whereResult = self::_flatten( $whereResult ); |
|
| 313 | - $whereAll = self::_flatten( $whereAll ); |
|
| 314 | - |
|
| 315 | - if ( $whereResult ) { |
|
| 316 | - $where = $where ? |
|
| 317 | - $where .' AND '.$whereResult : |
|
| 318 | - 'WHERE '.$whereResult; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - if ( $whereAll ) { |
|
| 322 | - $where = $where ? |
|
| 323 | - $where .' AND '.$whereAll : |
|
| 324 | - 'WHERE '.$whereAll; |
|
| 325 | - |
|
| 326 | - $whereAllSql = 'WHERE '.$whereAll; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - // Main query to actually get the data |
|
| 330 | - $data = self::sql_exec( $db, $bindings, |
|
| 331 | - "SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", self::pluck($columns, 'db'))."` |
|
| 267 | + return array( |
|
| 268 | + "draw" => intval( $request['draw'] ), |
|
| 269 | + "recordsTotal" => intval( $recordsTotal ), |
|
| 270 | + "recordsFiltered" => intval( $recordsFiltered ), |
|
| 271 | + "data" => self::data_output( $columns, $data ) |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * The difference between this method and the `simple` one, is that you can |
|
| 278 | + * apply additional `where` conditions to the SQL queries. These can be in |
|
| 279 | + * one of two forms: |
|
| 280 | + * |
|
| 281 | + * * 'Result condition' - This is applied to the result set, but not the |
|
| 282 | + * overall paging information query - i.e. it will not effect the number |
|
| 283 | + * of records that a user sees they can have access to. This should be |
|
| 284 | + * used when you want apply a filtering condition that the user has sent. |
|
| 285 | + * * 'All condition' - This is applied to all queries that are made and |
|
| 286 | + * reduces the number of records that the user can access. This should be |
|
| 287 | + * used in conditions where you don't want the user to ever have access to |
|
| 288 | + * particular records (for example, restricting by a login id). |
|
| 289 | + * |
|
| 290 | + * @param array $request Data sent to server by DataTables |
|
| 291 | + * @param array|PDO $conn PDO connection resource or connection parameters array |
|
| 292 | + * @param string $table SQL table to query |
|
| 293 | + * @param string $primaryKey Primary key of the table |
|
| 294 | + * @param array $columns Column information array |
|
| 295 | + * @param string $whereResult WHERE condition to apply to the result set |
|
| 296 | + * @param string $whereAll WHERE condition to apply to all queries |
|
| 297 | + * @return array Server-side processing response array |
|
| 298 | + */ |
|
| 299 | + static function complex ( $request, $conn, $table, $primaryKey, $columns, $whereResult=null, $whereAll=null ) |
|
| 300 | + { |
|
| 301 | + $bindings = array(); |
|
| 302 | + $db = self::db( $conn ); |
|
| 303 | + $localWhereResult = array(); |
|
| 304 | + $localWhereAll = array(); |
|
| 305 | + $whereAllSql = ''; |
|
| 306 | + |
|
| 307 | + // Build the SQL query string from the request |
|
| 308 | + $limit = self::limit( $request, $columns ); |
|
| 309 | + $order = self::order( $request, $columns ); |
|
| 310 | + $where = self::filter( $request, $columns, $bindings ); |
|
| 311 | + |
|
| 312 | + $whereResult = self::_flatten( $whereResult ); |
|
| 313 | + $whereAll = self::_flatten( $whereAll ); |
|
| 314 | + |
|
| 315 | + if ( $whereResult ) { |
|
| 316 | + $where = $where ? |
|
| 317 | + $where .' AND '.$whereResult : |
|
| 318 | + 'WHERE '.$whereResult; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + if ( $whereAll ) { |
|
| 322 | + $where = $where ? |
|
| 323 | + $where .' AND '.$whereAll : |
|
| 324 | + 'WHERE '.$whereAll; |
|
| 325 | + |
|
| 326 | + $whereAllSql = 'WHERE '.$whereAll; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + // Main query to actually get the data |
|
| 330 | + $data = self::sql_exec( $db, $bindings, |
|
| 331 | + "SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", self::pluck($columns, 'db'))."` |
|
| 332 | 332 | FROM `$table` |
| 333 | 333 | $where |
| 334 | 334 | $order |
| 335 | 335 | $limit" |
| 336 | - ); |
|
| 336 | + ); |
|
| 337 | 337 | |
| 338 | - // Data set length after filtering |
|
| 339 | - $resFilterLength = self::sql_exec( $db, |
|
| 340 | - "SELECT FOUND_ROWS()" |
|
| 341 | - ); |
|
| 342 | - $recordsFiltered = $resFilterLength[0][0]; |
|
| 338 | + // Data set length after filtering |
|
| 339 | + $resFilterLength = self::sql_exec( $db, |
|
| 340 | + "SELECT FOUND_ROWS()" |
|
| 341 | + ); |
|
| 342 | + $recordsFiltered = $resFilterLength[0][0]; |
|
| 343 | 343 | |
| 344 | - // Total data set length |
|
| 345 | - $resTotalLength = self::sql_exec( $db, $bindings, |
|
| 346 | - "SELECT COUNT(`{$primaryKey}`) |
|
| 344 | + // Total data set length |
|
| 345 | + $resTotalLength = self::sql_exec( $db, $bindings, |
|
| 346 | + "SELECT COUNT(`{$primaryKey}`) |
|
| 347 | 347 | FROM `$table` ". |
| 348 | - $whereAllSql |
|
| 349 | - ); |
|
| 350 | - $recordsTotal = $resTotalLength[0][0]; |
|
| 348 | + $whereAllSql |
|
| 349 | + ); |
|
| 350 | + $recordsTotal = $resTotalLength[0][0]; |
|
| 351 | 351 | |
| 352 | - /* |
|
| 352 | + /* |
|
| 353 | 353 | * Output |
| 354 | 354 | */ |
| 355 | - return array( |
|
| 356 | - "draw" => intval( $request['draw'] ), |
|
| 357 | - "recordsTotal" => intval( $recordsTotal ), |
|
| 358 | - "recordsFiltered" => intval( $recordsFiltered ), |
|
| 359 | - "data" => self::data_output( $columns, $data ) |
|
| 360 | - ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Connect to the database |
|
| 366 | - * |
|
| 367 | - * @param array $sql_details SQL server connection details array, with the |
|
| 368 | - * properties: |
|
| 369 | - * * host - host name |
|
| 370 | - * * db - database name |
|
| 371 | - * * user - user name |
|
| 372 | - * * pass - user password |
|
| 373 | - * @return resource Database connection handle |
|
| 374 | - */ |
|
| 375 | - static function sql_connect ( $sql_details ) |
|
| 376 | - { |
|
| 377 | - try { |
|
| 378 | - $db = @new PDO( |
|
| 379 | - "mysql:host={$sql_details['host']};dbname={$sql_details['db']}", |
|
| 380 | - $sql_details['user'], |
|
| 381 | - $sql_details['pass'], |
|
| 382 | - array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) |
|
| 383 | - ); |
|
| 384 | - } |
|
| 385 | - catch (PDOException $e) { |
|
| 386 | - self::fatal( |
|
| 387 | - "An error occurred while connecting to the database. ". |
|
| 388 | - "The error reported by the server was: ".$e->getMessage() |
|
| 389 | - ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $db; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Execute an SQL query on the database |
|
| 398 | - * |
|
| 399 | - * @param resource $db Database handler |
|
| 400 | - * @param array $bindings Array of PDO binding values from bind() to be |
|
| 401 | - * used for safely escaping strings. Note that this can be given as the |
|
| 402 | - * SQL query string if no bindings are required. |
|
| 403 | - * @param string $sql SQL query to execute. |
|
| 404 | - * @return array Result from the query (all rows) |
|
| 405 | - */ |
|
| 406 | - static function sql_exec ( $db, $bindings, $sql=null ) |
|
| 407 | - { |
|
| 408 | - // Argument shifting |
|
| 409 | - if ( $sql === null ) { |
|
| 410 | - $sql = $bindings; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - $stmt = $db->prepare( $sql ); |
|
| 414 | - //echo $sql; |
|
| 415 | - |
|
| 416 | - // Bind parameters |
|
| 417 | - if ( is_array( $bindings ) ) { |
|
| 418 | - for ( $i=0, $ien=count($bindings) ; $i<$ien ; $i++ ) { |
|
| 419 | - $binding = $bindings[$i]; |
|
| 420 | - $stmt->bindValue( $binding['key'], $binding['val'], $binding['type'] ); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - // Execute |
|
| 425 | - try { |
|
| 426 | - $stmt->execute(); |
|
| 427 | - } |
|
| 428 | - catch (PDOException $e) { |
|
| 429 | - self::fatal( "An SQL error occurred: ".$e->getMessage() ); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - // Return all |
|
| 433 | - return $stmt->fetchAll(); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
| 355 | + return array( |
|
| 356 | + "draw" => intval( $request['draw'] ), |
|
| 357 | + "recordsTotal" => intval( $recordsTotal ), |
|
| 358 | + "recordsFiltered" => intval( $recordsFiltered ), |
|
| 359 | + "data" => self::data_output( $columns, $data ) |
|
| 360 | + ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Connect to the database |
|
| 366 | + * |
|
| 367 | + * @param array $sql_details SQL server connection details array, with the |
|
| 368 | + * properties: |
|
| 369 | + * * host - host name |
|
| 370 | + * * db - database name |
|
| 371 | + * * user - user name |
|
| 372 | + * * pass - user password |
|
| 373 | + * @return resource Database connection handle |
|
| 374 | + */ |
|
| 375 | + static function sql_connect ( $sql_details ) |
|
| 376 | + { |
|
| 377 | + try { |
|
| 378 | + $db = @new PDO( |
|
| 379 | + "mysql:host={$sql_details['host']};dbname={$sql_details['db']}", |
|
| 380 | + $sql_details['user'], |
|
| 381 | + $sql_details['pass'], |
|
| 382 | + array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) |
|
| 383 | + ); |
|
| 384 | + } |
|
| 385 | + catch (PDOException $e) { |
|
| 386 | + self::fatal( |
|
| 387 | + "An error occurred while connecting to the database. ". |
|
| 388 | + "The error reported by the server was: ".$e->getMessage() |
|
| 389 | + ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $db; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Execute an SQL query on the database |
|
| 398 | + * |
|
| 399 | + * @param resource $db Database handler |
|
| 400 | + * @param array $bindings Array of PDO binding values from bind() to be |
|
| 401 | + * used for safely escaping strings. Note that this can be given as the |
|
| 402 | + * SQL query string if no bindings are required. |
|
| 403 | + * @param string $sql SQL query to execute. |
|
| 404 | + * @return array Result from the query (all rows) |
|
| 405 | + */ |
|
| 406 | + static function sql_exec ( $db, $bindings, $sql=null ) |
|
| 407 | + { |
|
| 408 | + // Argument shifting |
|
| 409 | + if ( $sql === null ) { |
|
| 410 | + $sql = $bindings; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + $stmt = $db->prepare( $sql ); |
|
| 414 | + //echo $sql; |
|
| 415 | + |
|
| 416 | + // Bind parameters |
|
| 417 | + if ( is_array( $bindings ) ) { |
|
| 418 | + for ( $i=0, $ien=count($bindings) ; $i<$ien ; $i++ ) { |
|
| 419 | + $binding = $bindings[$i]; |
|
| 420 | + $stmt->bindValue( $binding['key'], $binding['val'], $binding['type'] ); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + // Execute |
|
| 425 | + try { |
|
| 426 | + $stmt->execute(); |
|
| 427 | + } |
|
| 428 | + catch (PDOException $e) { |
|
| 429 | + self::fatal( "An SQL error occurred: ".$e->getMessage() ); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + // Return all |
|
| 433 | + return $stmt->fetchAll(); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
| 438 | 438 | * Internal methods |
| 439 | 439 | */ |
| 440 | 440 | |
| 441 | - /** |
|
| 442 | - * Throw a fatal error. |
|
| 443 | - * |
|
| 444 | - * This writes out an error message in a JSON string which DataTables will |
|
| 445 | - * see and show to the user in the browser. |
|
| 446 | - * |
|
| 447 | - * @param string $msg Message to send to the client |
|
| 448 | - */ |
|
| 449 | - static function fatal ( $msg ) |
|
| 450 | - { |
|
| 451 | - echo json_encode( array( |
|
| 452 | - "error" => $msg |
|
| 453 | - ) ); |
|
| 454 | - |
|
| 455 | - exit(0); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Create a PDO binding key which can be used for escaping variables safely |
|
| 460 | - * when executing a query with sql_exec() |
|
| 461 | - * |
|
| 462 | - * @param array &$a Array of bindings |
|
| 463 | - * @param * $val Value to bind |
|
| 464 | - * @param int $type PDO field type |
|
| 465 | - * @return string Bound key to be used in the SQL where this parameter |
|
| 466 | - * would be used. |
|
| 467 | - */ |
|
| 468 | - static function bind ( &$a, $val, $type ) |
|
| 469 | - { |
|
| 470 | - $key = ':binding_'.count( $a ); |
|
| 471 | - |
|
| 472 | - $a[] = array( |
|
| 473 | - 'key' => $key, |
|
| 474 | - 'val' => $val, |
|
| 475 | - 'type' => $type |
|
| 476 | - ); |
|
| 477 | - |
|
| 478 | - return $key; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * Pull a particular property from each assoc. array in a numeric array, |
|
| 484 | - * returning and array of the property values from each item. |
|
| 485 | - * |
|
| 486 | - * @param array $a Array to get data from |
|
| 487 | - * @param string $prop Property to read |
|
| 488 | - * @return array Array of property values |
|
| 489 | - */ |
|
| 490 | - static function pluck ( $a, $prop ) |
|
| 491 | - { |
|
| 492 | - $out = array(); |
|
| 493 | - |
|
| 494 | - for ( $i=0, $len=count($a) ; $i<$len ; $i++ ) { |
|
| 495 | - $out[] = $a[$i][$prop]; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - return $out; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Return a string from an array or a string |
|
| 504 | - * |
|
| 505 | - * @param array|string $a Array to join |
|
| 506 | - * @param string $join Glue for the concatenation |
|
| 507 | - * @return string Joined string |
|
| 508 | - */ |
|
| 509 | - static function _flatten ( $a, $join = ' AND ' ) |
|
| 510 | - { |
|
| 511 | - if ( ! $a ) { |
|
| 512 | - return ''; |
|
| 513 | - } |
|
| 514 | - else if ( $a && is_array($a) ) { |
|
| 515 | - return implode( $join, $a ); |
|
| 516 | - } |
|
| 517 | - return $a; |
|
| 518 | - } |
|
| 441 | + /** |
|
| 442 | + * Throw a fatal error. |
|
| 443 | + * |
|
| 444 | + * This writes out an error message in a JSON string which DataTables will |
|
| 445 | + * see and show to the user in the browser. |
|
| 446 | + * |
|
| 447 | + * @param string $msg Message to send to the client |
|
| 448 | + */ |
|
| 449 | + static function fatal ( $msg ) |
|
| 450 | + { |
|
| 451 | + echo json_encode( array( |
|
| 452 | + "error" => $msg |
|
| 453 | + ) ); |
|
| 454 | + |
|
| 455 | + exit(0); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Create a PDO binding key which can be used for escaping variables safely |
|
| 460 | + * when executing a query with sql_exec() |
|
| 461 | + * |
|
| 462 | + * @param array &$a Array of bindings |
|
| 463 | + * @param * $val Value to bind |
|
| 464 | + * @param int $type PDO field type |
|
| 465 | + * @return string Bound key to be used in the SQL where this parameter |
|
| 466 | + * would be used. |
|
| 467 | + */ |
|
| 468 | + static function bind ( &$a, $val, $type ) |
|
| 469 | + { |
|
| 470 | + $key = ':binding_'.count( $a ); |
|
| 471 | + |
|
| 472 | + $a[] = array( |
|
| 473 | + 'key' => $key, |
|
| 474 | + 'val' => $val, |
|
| 475 | + 'type' => $type |
|
| 476 | + ); |
|
| 477 | + |
|
| 478 | + return $key; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * Pull a particular property from each assoc. array in a numeric array, |
|
| 484 | + * returning and array of the property values from each item. |
|
| 485 | + * |
|
| 486 | + * @param array $a Array to get data from |
|
| 487 | + * @param string $prop Property to read |
|
| 488 | + * @return array Array of property values |
|
| 489 | + */ |
|
| 490 | + static function pluck ( $a, $prop ) |
|
| 491 | + { |
|
| 492 | + $out = array(); |
|
| 493 | + |
|
| 494 | + for ( $i=0, $len=count($a) ; $i<$len ; $i++ ) { |
|
| 495 | + $out[] = $a[$i][$prop]; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + return $out; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Return a string from an array or a string |
|
| 504 | + * |
|
| 505 | + * @param array|string $a Array to join |
|
| 506 | + * @param string $join Glue for the concatenation |
|
| 507 | + * @return string Joined string |
|
| 508 | + */ |
|
| 509 | + static function _flatten ( $a, $join = ' AND ' ) |
|
| 510 | + { |
|
| 511 | + if ( ! $a ) { |
|
| 512 | + return ''; |
|
| 513 | + } |
|
| 514 | + else if ( $a && is_array($a) ) { |
|
| 515 | + return implode( $join, $a ); |
|
| 516 | + } |
|
| 517 | + return $a; |
|
| 518 | + } |
|
| 519 | 519 | } |
| 520 | 520 | |
@@ -17,9 +17,9 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | // REMOVE THIS BLOCK - used for DataTables test environment only! |
| 20 | -$file = $_SERVER['DOCUMENT_ROOT'].'/datatables/mysql.php'; |
|
| 21 | -if ( is_file( $file ) ) { |
|
| 22 | - include( $file ); |
|
| 20 | +$file = $_SERVER['DOCUMENT_ROOT'] . '/datatables/mysql.php'; |
|
| 21 | +if (is_file($file)) { |
|
| 22 | + include($file); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -31,22 +31,22 @@ discard block |
||
| 31 | 31 | * @param array $data Data from the SQL get |
| 32 | 32 | * @return array Formatted data in a row based format |
| 33 | 33 | */ |
| 34 | - static function data_output ( $columns, $data ) |
|
| 34 | + static function data_output($columns, $data) |
|
| 35 | 35 | { |
| 36 | 36 | $out = array(); |
| 37 | 37 | |
| 38 | - for ( $i=0, $ien=count($data) ; $i<$ien ; $i++ ) { |
|
| 38 | + for ($i = 0, $ien = count($data); $i < $ien; $i++) { |
|
| 39 | 39 | $row = array(); |
| 40 | 40 | |
| 41 | - for ( $j=0, $jen=count($columns) ; $j<$jen ; $j++ ) { |
|
| 41 | + for ($j = 0, $jen = count($columns); $j < $jen; $j++) { |
|
| 42 | 42 | $column = $columns[$j]; |
| 43 | 43 | |
| 44 | 44 | // Is there a formatter? |
| 45 | - if ( isset( $column['formatter'] ) ) { |
|
| 46 | - $row[ $column['dt'] ] = $column['formatter']( $data[$i][ $column['db'] ], $data[$i] ); |
|
| 45 | + if (isset($column['formatter'])) { |
|
| 46 | + $row[$column['dt']] = $column['formatter']($data[$i][$column['db']], $data[$i]); |
|
| 47 | 47 | } |
| 48 | 48 | else { |
| 49 | - $row[ $column['dt'] ] = $data[$i][ $columns[$j]['db'] ]; |
|
| 49 | + $row[$column['dt']] = $data[$i][$columns[$j]['db']]; |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | * * pass - user password |
| 71 | 71 | * @return resource PDO connection |
| 72 | 72 | */ |
| 73 | - static function db ( $conn ) |
|
| 73 | + static function db($conn) |
|
| 74 | 74 | { |
| 75 | - if ( is_array( $conn ) ) { |
|
| 76 | - return self::sql_connect( $conn ); |
|
| 75 | + if (is_array($conn)) { |
|
| 76 | + return self::sql_connect($conn); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | return $conn; |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | * @param array $columns Column information array |
| 90 | 90 | * @return string SQL limit clause |
| 91 | 91 | */ |
| 92 | - static function limit ( $request, $columns ) |
|
| 92 | + static function limit($request, $columns) |
|
| 93 | 93 | { |
| 94 | 94 | $limit = ''; |
| 95 | 95 | |
| 96 | - if ( isset($request['start']) && $request['length'] != -1 ) { |
|
| 97 | - $limit = "LIMIT ".intval($request['start']).", ".intval($request['length']); |
|
| 96 | + if (isset($request['start']) && $request['length'] != -1) { |
|
| 97 | + $limit = "LIMIT " . intval($request['start']) . ", " . intval($request['length']); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | return $limit; |
@@ -110,32 +110,31 @@ discard block |
||
| 110 | 110 | * @param array $columns Column information array |
| 111 | 111 | * @return string SQL order by clause |
| 112 | 112 | */ |
| 113 | - static function order ( $request, $columns ) |
|
| 113 | + static function order($request, $columns) |
|
| 114 | 114 | { |
| 115 | 115 | $order = ''; |
| 116 | 116 | |
| 117 | - if ( isset($request['order']) && count($request['order']) ) { |
|
| 117 | + if (isset($request['order']) && count($request['order'])) { |
|
| 118 | 118 | $orderBy = array(); |
| 119 | - $dtColumns = self::pluck( $columns, 'dt' ); |
|
| 119 | + $dtColumns = self::pluck($columns, 'dt'); |
|
| 120 | 120 | |
| 121 | - for ( $i=0, $ien=count($request['order']) ; $i<$ien ; $i++ ) { |
|
| 121 | + for ($i = 0, $ien = count($request['order']); $i < $ien; $i++) { |
|
| 122 | 122 | // Convert the column index into the column data property |
| 123 | 123 | $columnIdx = intval($request['order'][$i]['column']); |
| 124 | 124 | $requestColumn = $request['columns'][$columnIdx]; |
| 125 | 125 | |
| 126 | - $columnIdx = array_search( $requestColumn['data'], $dtColumns ); |
|
| 127 | - $column = $columns[ $columnIdx ]; |
|
| 126 | + $columnIdx = array_search($requestColumn['data'], $dtColumns); |
|
| 127 | + $column = $columns[$columnIdx]; |
|
| 128 | 128 | |
| 129 | - if ( $requestColumn['orderable'] == 'true' ) { |
|
| 129 | + if ($requestColumn['orderable'] == 'true') { |
|
| 130 | 130 | $dir = $request['order'][$i]['dir'] === 'asc' ? |
| 131 | - 'ASC' : |
|
| 132 | - 'DESC'; |
|
| 131 | + 'ASC' : 'DESC'; |
|
| 133 | 132 | |
| 134 | - $orderBy[] = '`'.$column['db'].'` '.$dir; |
|
| 133 | + $orderBy[] = '`' . $column['db'] . '` ' . $dir; |
|
| 135 | 134 | } |
| 136 | 135 | } |
| 137 | 136 | |
| 138 | - $order = 'ORDER BY '.implode(', ', $orderBy); |
|
| 137 | + $order = 'ORDER BY ' . implode(', ', $orderBy); |
|
| 139 | 138 | } |
| 140 | 139 | |
| 141 | 140 | return $order; |
@@ -157,57 +156,56 @@ discard block |
||
| 157 | 156 | * sql_exec() function |
| 158 | 157 | * @return string SQL where clause |
| 159 | 158 | */ |
| 160 | - static function filter ( $request, $columns, &$bindings ) |
|
| 159 | + static function filter($request, $columns, &$bindings) |
|
| 161 | 160 | { |
| 162 | 161 | $globalSearch = array(); |
| 163 | 162 | $columnSearch = array(); |
| 164 | - $dtColumns = self::pluck( $columns, 'dt' ); |
|
| 163 | + $dtColumns = self::pluck($columns, 'dt'); |
|
| 165 | 164 | |
| 166 | - if ( isset($request['search']) && $request['search']['value'] != '' ) { |
|
| 165 | + if (isset($request['search']) && $request['search']['value'] != '') { |
|
| 167 | 166 | $str = $request['search']['value']; |
| 168 | 167 | |
| 169 | - for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) { |
|
| 168 | + for ($i = 0, $ien = count($request['columns']); $i < $ien; $i++) { |
|
| 170 | 169 | $requestColumn = $request['columns'][$i]; |
| 171 | - $columnIdx = array_search( $requestColumn['data'], $dtColumns ); |
|
| 172 | - $column = $columns[ $columnIdx ]; |
|
| 170 | + $columnIdx = array_search($requestColumn['data'], $dtColumns); |
|
| 171 | + $column = $columns[$columnIdx]; |
|
| 173 | 172 | |
| 174 | - if ( $requestColumn['searchable'] == 'true' ) { |
|
| 175 | - $binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR ); |
|
| 176 | - $globalSearch[] = "`".$column['db']."` LIKE ".$binding; |
|
| 173 | + if ($requestColumn['searchable'] == 'true') { |
|
| 174 | + $binding = self::bind($bindings, '%' . $str . '%', PDO::PARAM_STR); |
|
| 175 | + $globalSearch[] = "`" . $column['db'] . "` LIKE " . $binding; |
|
| 177 | 176 | } |
| 178 | 177 | } |
| 179 | 178 | } |
| 180 | 179 | |
| 181 | 180 | // Individual column filtering |
| 182 | - for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) { |
|
| 181 | + for ($i = 0, $ien = count($request['columns']); $i < $ien; $i++) { |
|
| 183 | 182 | $requestColumn = $request['columns'][$i]; |
| 184 | - $columnIdx = array_search( $requestColumn['data'], $dtColumns ); |
|
| 185 | - $column = $columns[ $columnIdx ]; |
|
| 183 | + $columnIdx = array_search($requestColumn['data'], $dtColumns); |
|
| 184 | + $column = $columns[$columnIdx]; |
|
| 186 | 185 | |
| 187 | 186 | $str = $requestColumn['search']['value']; |
| 188 | 187 | |
| 189 | - if ( $requestColumn['searchable'] == 'true' && |
|
| 190 | - $str != '' ) { |
|
| 191 | - $binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR ); |
|
| 192 | - $columnSearch[] = "`".$column['db']."` LIKE ".$binding; |
|
| 188 | + if ($requestColumn['searchable'] == 'true' && |
|
| 189 | + $str != '') { |
|
| 190 | + $binding = self::bind($bindings, '%' . $str . '%', PDO::PARAM_STR); |
|
| 191 | + $columnSearch[] = "`" . $column['db'] . "` LIKE " . $binding; |
|
| 193 | 192 | } |
| 194 | 193 | } |
| 195 | 194 | |
| 196 | 195 | // Combine the filters into a single string |
| 197 | 196 | $where = ''; |
| 198 | 197 | |
| 199 | - if ( count( $globalSearch ) ) { |
|
| 200 | - $where = '('.implode(' OR ', $globalSearch).')'; |
|
| 198 | + if (count($globalSearch)) { |
|
| 199 | + $where = '(' . implode(' OR ', $globalSearch) . ')'; |
|
| 201 | 200 | } |
| 202 | 201 | |
| 203 | - if ( count( $columnSearch ) ) { |
|
| 202 | + if (count($columnSearch)) { |
|
| 204 | 203 | $where = $where === '' ? |
| 205 | - implode(' AND ', $columnSearch) : |
|
| 206 | - $where .' AND '. implode(' AND ', $columnSearch); |
|
| 204 | + implode(' AND ', $columnSearch) : $where . ' AND ' . implode(' AND ', $columnSearch); |
|
| 207 | 205 | } |
| 208 | 206 | |
| 209 | - if ( $where !== '' ) { |
|
| 210 | - $where = 'WHERE '.$where; |
|
| 207 | + if ($where !== '') { |
|
| 208 | + $where = 'WHERE ' . $where; |
|
| 211 | 209 | } |
| 212 | 210 | |
| 213 | 211 | return $where; |
@@ -228,19 +226,19 @@ discard block |
||
| 228 | 226 | * @param array $columns Column information array |
| 229 | 227 | * @return array Server-side processing response array |
| 230 | 228 | */ |
| 231 | - static function simple ( $request, $conn, $table, $primaryKey, $columns ) |
|
| 229 | + static function simple($request, $conn, $table, $primaryKey, $columns) |
|
| 232 | 230 | { |
| 233 | 231 | $bindings = array(); |
| 234 | - $db = self::db( $conn ); |
|
| 232 | + $db = self::db($conn); |
|
| 235 | 233 | |
| 236 | 234 | // Build the SQL query string from the request |
| 237 | - $limit = self::limit( $request, $columns ); |
|
| 238 | - $order = self::order( $request, $columns ); |
|
| 239 | - $where = self::filter( $request, $columns, $bindings ); |
|
| 235 | + $limit = self::limit($request, $columns); |
|
| 236 | + $order = self::order($request, $columns); |
|
| 237 | + $where = self::filter($request, $columns, $bindings); |
|
| 240 | 238 | |
| 241 | 239 | // Main query to actually get the data |
| 242 | - $data = self::sql_exec( $db, $bindings, |
|
| 243 | - "SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", self::pluck($columns, 'db'))."` |
|
| 240 | + $data = self::sql_exec($db, $bindings, |
|
| 241 | + "SELECT SQL_CALC_FOUND_ROWS `" . implode("`, `", self::pluck($columns, 'db')) . "` |
|
| 244 | 242 | FROM `$table` |
| 245 | 243 | $where |
| 246 | 244 | $order |
@@ -248,13 +246,13 @@ discard block |
||
| 248 | 246 | ); |
| 249 | 247 | |
| 250 | 248 | // Data set length after filtering |
| 251 | - $resFilterLength = self::sql_exec( $db, |
|
| 249 | + $resFilterLength = self::sql_exec($db, |
|
| 252 | 250 | "SELECT FOUND_ROWS()" |
| 253 | 251 | ); |
| 254 | 252 | $recordsFiltered = $resFilterLength[0][0]; |
| 255 | 253 | |
| 256 | 254 | // Total data set length |
| 257 | - $resTotalLength = self::sql_exec( $db, |
|
| 255 | + $resTotalLength = self::sql_exec($db, |
|
| 258 | 256 | "SELECT COUNT(`{$primaryKey}`) |
| 259 | 257 | FROM `$table`" |
| 260 | 258 | ); |
@@ -265,10 +263,10 @@ discard block |
||
| 265 | 263 | * Output |
| 266 | 264 | */ |
| 267 | 265 | return array( |
| 268 | - "draw" => intval( $request['draw'] ), |
|
| 269 | - "recordsTotal" => intval( $recordsTotal ), |
|
| 270 | - "recordsFiltered" => intval( $recordsFiltered ), |
|
| 271 | - "data" => self::data_output( $columns, $data ) |
|
| 266 | + "draw" => intval($request['draw']), |
|
| 267 | + "recordsTotal" => intval($recordsTotal), |
|
| 268 | + "recordsFiltered" => intval($recordsFiltered), |
|
| 269 | + "data" => self::data_output($columns, $data) |
|
| 272 | 270 | ); |
| 273 | 271 | } |
| 274 | 272 | |
@@ -296,39 +294,37 @@ discard block |
||
| 296 | 294 | * @param string $whereAll WHERE condition to apply to all queries |
| 297 | 295 | * @return array Server-side processing response array |
| 298 | 296 | */ |
| 299 | - static function complex ( $request, $conn, $table, $primaryKey, $columns, $whereResult=null, $whereAll=null ) |
|
| 297 | + static function complex($request, $conn, $table, $primaryKey, $columns, $whereResult = null, $whereAll = null) |
|
| 300 | 298 | { |
| 301 | 299 | $bindings = array(); |
| 302 | - $db = self::db( $conn ); |
|
| 300 | + $db = self::db($conn); |
|
| 303 | 301 | $localWhereResult = array(); |
| 304 | 302 | $localWhereAll = array(); |
| 305 | 303 | $whereAllSql = ''; |
| 306 | 304 | |
| 307 | 305 | // Build the SQL query string from the request |
| 308 | - $limit = self::limit( $request, $columns ); |
|
| 309 | - $order = self::order( $request, $columns ); |
|
| 310 | - $where = self::filter( $request, $columns, $bindings ); |
|
| 306 | + $limit = self::limit($request, $columns); |
|
| 307 | + $order = self::order($request, $columns); |
|
| 308 | + $where = self::filter($request, $columns, $bindings); |
|
| 311 | 309 | |
| 312 | - $whereResult = self::_flatten( $whereResult ); |
|
| 313 | - $whereAll = self::_flatten( $whereAll ); |
|
| 310 | + $whereResult = self::_flatten($whereResult); |
|
| 311 | + $whereAll = self::_flatten($whereAll); |
|
| 314 | 312 | |
| 315 | - if ( $whereResult ) { |
|
| 313 | + if ($whereResult) { |
|
| 316 | 314 | $where = $where ? |
| 317 | - $where .' AND '.$whereResult : |
|
| 318 | - 'WHERE '.$whereResult; |
|
| 315 | + $where . ' AND ' . $whereResult : 'WHERE ' . $whereResult; |
|
| 319 | 316 | } |
| 320 | 317 | |
| 321 | - if ( $whereAll ) { |
|
| 318 | + if ($whereAll) { |
|
| 322 | 319 | $where = $where ? |
| 323 | - $where .' AND '.$whereAll : |
|
| 324 | - 'WHERE '.$whereAll; |
|
| 320 | + $where . ' AND ' . $whereAll : 'WHERE ' . $whereAll; |
|
| 325 | 321 | |
| 326 | - $whereAllSql = 'WHERE '.$whereAll; |
|
| 322 | + $whereAllSql = 'WHERE ' . $whereAll; |
|
| 327 | 323 | } |
| 328 | 324 | |
| 329 | 325 | // Main query to actually get the data |
| 330 | - $data = self::sql_exec( $db, $bindings, |
|
| 331 | - "SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", self::pluck($columns, 'db'))."` |
|
| 326 | + $data = self::sql_exec($db, $bindings, |
|
| 327 | + "SELECT SQL_CALC_FOUND_ROWS `" . implode("`, `", self::pluck($columns, 'db')) . "` |
|
| 332 | 328 | FROM `$table` |
| 333 | 329 | $where |
| 334 | 330 | $order |
@@ -336,15 +332,15 @@ discard block |
||
| 336 | 332 | ); |
| 337 | 333 | |
| 338 | 334 | // Data set length after filtering |
| 339 | - $resFilterLength = self::sql_exec( $db, |
|
| 335 | + $resFilterLength = self::sql_exec($db, |
|
| 340 | 336 | "SELECT FOUND_ROWS()" |
| 341 | 337 | ); |
| 342 | 338 | $recordsFiltered = $resFilterLength[0][0]; |
| 343 | 339 | |
| 344 | 340 | // Total data set length |
| 345 | - $resTotalLength = self::sql_exec( $db, $bindings, |
|
| 341 | + $resTotalLength = self::sql_exec($db, $bindings, |
|
| 346 | 342 | "SELECT COUNT(`{$primaryKey}`) |
| 347 | - FROM `$table` ". |
|
| 343 | + FROM `$table` " . |
|
| 348 | 344 | $whereAllSql |
| 349 | 345 | ); |
| 350 | 346 | $recordsTotal = $resTotalLength[0][0]; |
@@ -353,10 +349,10 @@ discard block |
||
| 353 | 349 | * Output |
| 354 | 350 | */ |
| 355 | 351 | return array( |
| 356 | - "draw" => intval( $request['draw'] ), |
|
| 357 | - "recordsTotal" => intval( $recordsTotal ), |
|
| 358 | - "recordsFiltered" => intval( $recordsFiltered ), |
|
| 359 | - "data" => self::data_output( $columns, $data ) |
|
| 352 | + "draw" => intval($request['draw']), |
|
| 353 | + "recordsTotal" => intval($recordsTotal), |
|
| 354 | + "recordsFiltered" => intval($recordsFiltered), |
|
| 355 | + "data" => self::data_output($columns, $data) |
|
| 360 | 356 | ); |
| 361 | 357 | } |
| 362 | 358 | |
@@ -372,20 +368,20 @@ discard block |
||
| 372 | 368 | * * pass - user password |
| 373 | 369 | * @return resource Database connection handle |
| 374 | 370 | */ |
| 375 | - static function sql_connect ( $sql_details ) |
|
| 371 | + static function sql_connect($sql_details) |
|
| 376 | 372 | { |
| 377 | 373 | try { |
| 378 | 374 | $db = @new PDO( |
| 379 | 375 | "mysql:host={$sql_details['host']};dbname={$sql_details['db']}", |
| 380 | 376 | $sql_details['user'], |
| 381 | 377 | $sql_details['pass'], |
| 382 | - array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) |
|
| 378 | + array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) |
|
| 383 | 379 | ); |
| 384 | 380 | } |
| 385 | 381 | catch (PDOException $e) { |
| 386 | 382 | self::fatal( |
| 387 | - "An error occurred while connecting to the database. ". |
|
| 388 | - "The error reported by the server was: ".$e->getMessage() |
|
| 383 | + "An error occurred while connecting to the database. " . |
|
| 384 | + "The error reported by the server was: " . $e->getMessage() |
|
| 389 | 385 | ); |
| 390 | 386 | } |
| 391 | 387 | |
@@ -403,21 +399,21 @@ discard block |
||
| 403 | 399 | * @param string $sql SQL query to execute. |
| 404 | 400 | * @return array Result from the query (all rows) |
| 405 | 401 | */ |
| 406 | - static function sql_exec ( $db, $bindings, $sql=null ) |
|
| 402 | + static function sql_exec($db, $bindings, $sql = null) |
|
| 407 | 403 | { |
| 408 | 404 | // Argument shifting |
| 409 | - if ( $sql === null ) { |
|
| 405 | + if ($sql === null) { |
|
| 410 | 406 | $sql = $bindings; |
| 411 | 407 | } |
| 412 | 408 | |
| 413 | - $stmt = $db->prepare( $sql ); |
|
| 409 | + $stmt = $db->prepare($sql); |
|
| 414 | 410 | //echo $sql; |
| 415 | 411 | |
| 416 | 412 | // Bind parameters |
| 417 | - if ( is_array( $bindings ) ) { |
|
| 418 | - for ( $i=0, $ien=count($bindings) ; $i<$ien ; $i++ ) { |
|
| 413 | + if (is_array($bindings)) { |
|
| 414 | + for ($i = 0, $ien = count($bindings); $i < $ien; $i++) { |
|
| 419 | 415 | $binding = $bindings[$i]; |
| 420 | - $stmt->bindValue( $binding['key'], $binding['val'], $binding['type'] ); |
|
| 416 | + $stmt->bindValue($binding['key'], $binding['val'], $binding['type']); |
|
| 421 | 417 | } |
| 422 | 418 | } |
| 423 | 419 | |
@@ -426,7 +422,7 @@ discard block |
||
| 426 | 422 | $stmt->execute(); |
| 427 | 423 | } |
| 428 | 424 | catch (PDOException $e) { |
| 429 | - self::fatal( "An SQL error occurred: ".$e->getMessage() ); |
|
| 425 | + self::fatal("An SQL error occurred: " . $e->getMessage()); |
|
| 430 | 426 | } |
| 431 | 427 | |
| 432 | 428 | // Return all |
@@ -446,11 +442,11 @@ discard block |
||
| 446 | 442 | * |
| 447 | 443 | * @param string $msg Message to send to the client |
| 448 | 444 | */ |
| 449 | - static function fatal ( $msg ) |
|
| 445 | + static function fatal($msg) |
|
| 450 | 446 | { |
| 451 | - echo json_encode( array( |
|
| 447 | + echo json_encode(array( |
|
| 452 | 448 | "error" => $msg |
| 453 | - ) ); |
|
| 449 | + )); |
|
| 454 | 450 | |
| 455 | 451 | exit(0); |
| 456 | 452 | } |
@@ -465,9 +461,9 @@ discard block |
||
| 465 | 461 | * @return string Bound key to be used in the SQL where this parameter |
| 466 | 462 | * would be used. |
| 467 | 463 | */ |
| 468 | - static function bind ( &$a, $val, $type ) |
|
| 464 | + static function bind(&$a, $val, $type) |
|
| 469 | 465 | { |
| 470 | - $key = ':binding_'.count( $a ); |
|
| 466 | + $key = ':binding_' . count($a); |
|
| 471 | 467 | |
| 472 | 468 | $a[] = array( |
| 473 | 469 | 'key' => $key, |
@@ -487,11 +483,11 @@ discard block |
||
| 487 | 483 | * @param string $prop Property to read |
| 488 | 484 | * @return array Array of property values |
| 489 | 485 | */ |
| 490 | - static function pluck ( $a, $prop ) |
|
| 486 | + static function pluck($a, $prop) |
|
| 491 | 487 | { |
| 492 | 488 | $out = array(); |
| 493 | 489 | |
| 494 | - for ( $i=0, $len=count($a) ; $i<$len ; $i++ ) { |
|
| 490 | + for ($i = 0, $len = count($a); $i < $len; $i++) { |
|
| 495 | 491 | $out[] = $a[$i][$prop]; |
| 496 | 492 | } |
| 497 | 493 | |
@@ -506,13 +502,13 @@ discard block |
||
| 506 | 502 | * @param string $join Glue for the concatenation |
| 507 | 503 | * @return string Joined string |
| 508 | 504 | */ |
| 509 | - static function _flatten ( $a, $join = ' AND ' ) |
|
| 505 | + static function _flatten($a, $join = ' AND ') |
|
| 510 | 506 | { |
| 511 | - if ( ! $a ) { |
|
| 507 | + if (!$a) { |
|
| 512 | 508 | return ''; |
| 513 | 509 | } |
| 514 | - else if ( $a && is_array($a) ) { |
|
| 515 | - return implode( $join, $a ); |
|
| 510 | + else if ($a && is_array($a)) { |
|
| 511 | + return implode($join, $a); |
|
| 516 | 512 | } |
| 517 | 513 | return $a; |
| 518 | 514 | } |
@@ -44,8 +44,7 @@ discard block |
||
| 44 | 44 | // Is there a formatter? |
| 45 | 45 | if ( isset( $column['formatter'] ) ) { |
| 46 | 46 | $row[ $column['dt'] ] = $column['formatter']( $data[$i][ $column['db'] ], $data[$i] ); |
| 47 | - } |
|
| 48 | - else { |
|
| 47 | + } else { |
|
| 49 | 48 | $row[ $column['dt'] ] = $data[$i][ $columns[$j]['db'] ]; |
| 50 | 49 | } |
| 51 | 50 | } |
@@ -381,8 +380,7 @@ discard block |
||
| 381 | 380 | $sql_details['pass'], |
| 382 | 381 | array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) |
| 383 | 382 | ); |
| 384 | - } |
|
| 385 | - catch (PDOException $e) { |
|
| 383 | + } catch (PDOException $e) { |
|
| 386 | 384 | self::fatal( |
| 387 | 385 | "An error occurred while connecting to the database. ". |
| 388 | 386 | "The error reported by the server was: ".$e->getMessage() |
@@ -424,8 +422,7 @@ discard block |
||
| 424 | 422 | // Execute |
| 425 | 423 | try { |
| 426 | 424 | $stmt->execute(); |
| 427 | - } |
|
| 428 | - catch (PDOException $e) { |
|
| 425 | + } catch (PDOException $e) { |
|
| 429 | 426 | self::fatal( "An SQL error occurred: ".$e->getMessage() ); |
| 430 | 427 | } |
| 431 | 428 | |
@@ -510,8 +507,7 @@ discard block |
||
| 510 | 507 | { |
| 511 | 508 | if ( ! $a ) { |
| 512 | 509 | return ''; |
| 513 | - } |
|
| 514 | - else if ( $a && is_array($a) ) { |
|
| 510 | + } else if ( $a && is_array($a) ) { |
|
| 515 | 511 | return implode( $join, $a ); |
| 516 | 512 | } |
| 517 | 513 | return $a; |
@@ -15,32 +15,32 @@ discard block |
||
| 15 | 15 | // parameter represents the DataTables column identifier. In this case object |
| 16 | 16 | // parameter names |
| 17 | 17 | $columns = array( |
| 18 | - array( 'db' => 'first_name', 'dt' => 'first_name' ), |
|
| 19 | - array( 'db' => 'last_name', 'dt' => 'last_name' ), |
|
| 20 | - array( 'db' => 'position', 'dt' => 'position' ), |
|
| 21 | - array( 'db' => 'office', 'dt' => 'office' ), |
|
| 22 | - array( |
|
| 23 | - 'db' => 'start_date', |
|
| 24 | - 'dt' => 'start_date', |
|
| 25 | - 'formatter' => function( $d, $row ) { |
|
| 26 | - return date( 'jS M y', strtotime($d)); |
|
| 27 | - } |
|
| 28 | - ), |
|
| 29 | - array( |
|
| 30 | - 'db' => 'salary', |
|
| 31 | - 'dt' => 'salary', |
|
| 32 | - 'formatter' => function( $d, $row ) { |
|
| 33 | - return '$'.number_format($d); |
|
| 34 | - } |
|
| 35 | - ) |
|
| 18 | + array( 'db' => 'first_name', 'dt' => 'first_name' ), |
|
| 19 | + array( 'db' => 'last_name', 'dt' => 'last_name' ), |
|
| 20 | + array( 'db' => 'position', 'dt' => 'position' ), |
|
| 21 | + array( 'db' => 'office', 'dt' => 'office' ), |
|
| 22 | + array( |
|
| 23 | + 'db' => 'start_date', |
|
| 24 | + 'dt' => 'start_date', |
|
| 25 | + 'formatter' => function( $d, $row ) { |
|
| 26 | + return date( 'jS M y', strtotime($d)); |
|
| 27 | + } |
|
| 28 | + ), |
|
| 29 | + array( |
|
| 30 | + 'db' => 'salary', |
|
| 31 | + 'dt' => 'salary', |
|
| 32 | + 'formatter' => function( $d, $row ) { |
|
| 33 | + return '$'.number_format($d); |
|
| 34 | + } |
|
| 35 | + ) |
|
| 36 | 36 | ); |
| 37 | 37 | |
| 38 | 38 | // SQL server connection information |
| 39 | 39 | $sql_details = array( |
| 40 | - 'user' => '', |
|
| 41 | - 'pass' => '', |
|
| 42 | - 'db' => '', |
|
| 43 | - 'host' => '' |
|
| 40 | + 'user' => '', |
|
| 41 | + 'pass' => '', |
|
| 42 | + 'db' => '', |
|
| 43 | + 'host' => '' |
|
| 44 | 44 | ); |
| 45 | 45 | |
| 46 | 46 | |
@@ -52,6 +52,6 @@ discard block |
||
| 52 | 52 | require( 'ssp.class.php' ); |
| 53 | 53 | |
| 54 | 54 | echo json_encode( |
| 55 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 55 | + SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 56 | 56 | ); |
| 57 | 57 | |
@@ -15,22 +15,22 @@ discard block |
||
| 15 | 15 | // parameter represents the DataTables column identifier. In this case object |
| 16 | 16 | // parameter names |
| 17 | 17 | $columns = array( |
| 18 | - array( 'db' => 'first_name', 'dt' => 'first_name' ), |
|
| 19 | - array( 'db' => 'last_name', 'dt' => 'last_name' ), |
|
| 20 | - array( 'db' => 'position', 'dt' => 'position' ), |
|
| 21 | - array( 'db' => 'office', 'dt' => 'office' ), |
|
| 18 | + array('db' => 'first_name', 'dt' => 'first_name'), |
|
| 19 | + array('db' => 'last_name', 'dt' => 'last_name'), |
|
| 20 | + array('db' => 'position', 'dt' => 'position'), |
|
| 21 | + array('db' => 'office', 'dt' => 'office'), |
|
| 22 | 22 | array( |
| 23 | 23 | 'db' => 'start_date', |
| 24 | 24 | 'dt' => 'start_date', |
| 25 | - 'formatter' => function( $d, $row ) { |
|
| 26 | - return date( 'jS M y', strtotime($d)); |
|
| 25 | + 'formatter' => function($d, $row) { |
|
| 26 | + return date('jS M y', strtotime($d)); |
|
| 27 | 27 | } |
| 28 | 28 | ), |
| 29 | 29 | array( |
| 30 | 30 | 'db' => 'salary', |
| 31 | 31 | 'dt' => 'salary', |
| 32 | - 'formatter' => function( $d, $row ) { |
|
| 33 | - return '$'.number_format($d); |
|
| 32 | + 'formatter' => function($d, $row) { |
|
| 33 | + return '$' . number_format($d); |
|
| 34 | 34 | } |
| 35 | 35 | ) |
| 36 | 36 | ); |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | * server-side, there is no need to edit below this line. |
| 50 | 50 | */ |
| 51 | 51 | |
| 52 | -require( 'ssp.class.php' ); |
|
| 52 | +require('ssp.class.php'); |
|
| 53 | 53 | |
| 54 | 54 | echo json_encode( |
| 55 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 55 | + SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns) |
|
| 56 | 56 | ); |
| 57 | 57 | |
@@ -29,41 +29,41 @@ discard block |
||
| 29 | 29 | // parameter represents the DataTables column identifier - in this case object |
| 30 | 30 | // parameter names |
| 31 | 31 | $columns = array( |
| 32 | - array( |
|
| 33 | - 'db' => 'id', |
|
| 34 | - 'dt' => 'DT_RowId', |
|
| 35 | - 'formatter' => function( $d, $row ) { |
|
| 36 | - // Technically a DOM id cannot start with an integer, so we prefix |
|
| 37 | - // a string. This can also be useful if you have multiple tables |
|
| 38 | - // to ensure that the id is unique with a different prefix |
|
| 39 | - return 'row_'.$d; |
|
| 40 | - } |
|
| 41 | - ), |
|
| 42 | - array( 'db' => 'first_name', 'dt' => 'first_name' ), |
|
| 43 | - array( 'db' => 'last_name', 'dt' => 'last_name' ), |
|
| 44 | - array( 'db' => 'position', 'dt' => 'position' ), |
|
| 45 | - array( 'db' => 'office', 'dt' => 'office' ), |
|
| 46 | - array( |
|
| 47 | - 'db' => 'start_date', |
|
| 48 | - 'dt' => 'start_date', |
|
| 49 | - 'formatter' => function( $d, $row ) { |
|
| 50 | - return date( 'jS M y', strtotime($d)); |
|
| 51 | - } |
|
| 52 | - ), |
|
| 53 | - array( |
|
| 54 | - 'db' => 'salary', |
|
| 55 | - 'dt' => 'salary', |
|
| 56 | - 'formatter' => function( $d, $row ) { |
|
| 57 | - return '$'.number_format($d); |
|
| 58 | - } |
|
| 59 | - ) |
|
| 32 | + array( |
|
| 33 | + 'db' => 'id', |
|
| 34 | + 'dt' => 'DT_RowId', |
|
| 35 | + 'formatter' => function( $d, $row ) { |
|
| 36 | + // Technically a DOM id cannot start with an integer, so we prefix |
|
| 37 | + // a string. This can also be useful if you have multiple tables |
|
| 38 | + // to ensure that the id is unique with a different prefix |
|
| 39 | + return 'row_'.$d; |
|
| 40 | + } |
|
| 41 | + ), |
|
| 42 | + array( 'db' => 'first_name', 'dt' => 'first_name' ), |
|
| 43 | + array( 'db' => 'last_name', 'dt' => 'last_name' ), |
|
| 44 | + array( 'db' => 'position', 'dt' => 'position' ), |
|
| 45 | + array( 'db' => 'office', 'dt' => 'office' ), |
|
| 46 | + array( |
|
| 47 | + 'db' => 'start_date', |
|
| 48 | + 'dt' => 'start_date', |
|
| 49 | + 'formatter' => function( $d, $row ) { |
|
| 50 | + return date( 'jS M y', strtotime($d)); |
|
| 51 | + } |
|
| 52 | + ), |
|
| 53 | + array( |
|
| 54 | + 'db' => 'salary', |
|
| 55 | + 'dt' => 'salary', |
|
| 56 | + 'formatter' => function( $d, $row ) { |
|
| 57 | + return '$'.number_format($d); |
|
| 58 | + } |
|
| 59 | + ) |
|
| 60 | 60 | ); |
| 61 | 61 | |
| 62 | 62 | $sql_details = array( |
| 63 | - 'user' => '', |
|
| 64 | - 'pass' => '', |
|
| 65 | - 'db' => '', |
|
| 66 | - 'host' => '' |
|
| 63 | + 'user' => '', |
|
| 64 | + 'pass' => '', |
|
| 65 | + 'db' => '', |
|
| 66 | + 'host' => '' |
|
| 67 | 67 | ); |
| 68 | 68 | |
| 69 | 69 | |
@@ -75,6 +75,6 @@ discard block |
||
| 75 | 75 | require( 'ssp.class.php' ); |
| 76 | 76 | |
| 77 | 77 | echo json_encode( |
| 78 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 78 | + SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 79 | 79 | ); |
| 80 | 80 | |
@@ -32,29 +32,29 @@ discard block |
||
| 32 | 32 | array( |
| 33 | 33 | 'db' => 'id', |
| 34 | 34 | 'dt' => 'DT_RowId', |
| 35 | - 'formatter' => function( $d, $row ) { |
|
| 35 | + 'formatter' => function($d, $row) { |
|
| 36 | 36 | // Technically a DOM id cannot start with an integer, so we prefix |
| 37 | 37 | // a string. This can also be useful if you have multiple tables |
| 38 | 38 | // to ensure that the id is unique with a different prefix |
| 39 | - return 'row_'.$d; |
|
| 39 | + return 'row_' . $d; |
|
| 40 | 40 | } |
| 41 | 41 | ), |
| 42 | - array( 'db' => 'first_name', 'dt' => 'first_name' ), |
|
| 43 | - array( 'db' => 'last_name', 'dt' => 'last_name' ), |
|
| 44 | - array( 'db' => 'position', 'dt' => 'position' ), |
|
| 45 | - array( 'db' => 'office', 'dt' => 'office' ), |
|
| 42 | + array('db' => 'first_name', 'dt' => 'first_name'), |
|
| 43 | + array('db' => 'last_name', 'dt' => 'last_name'), |
|
| 44 | + array('db' => 'position', 'dt' => 'position'), |
|
| 45 | + array('db' => 'office', 'dt' => 'office'), |
|
| 46 | 46 | array( |
| 47 | 47 | 'db' => 'start_date', |
| 48 | 48 | 'dt' => 'start_date', |
| 49 | - 'formatter' => function( $d, $row ) { |
|
| 50 | - return date( 'jS M y', strtotime($d)); |
|
| 49 | + 'formatter' => function($d, $row) { |
|
| 50 | + return date('jS M y', strtotime($d)); |
|
| 51 | 51 | } |
| 52 | 52 | ), |
| 53 | 53 | array( |
| 54 | 54 | 'db' => 'salary', |
| 55 | 55 | 'dt' => 'salary', |
| 56 | - 'formatter' => function( $d, $row ) { |
|
| 57 | - return '$'.number_format($d); |
|
| 56 | + 'formatter' => function($d, $row) { |
|
| 57 | + return '$' . number_format($d); |
|
| 58 | 58 | } |
| 59 | 59 | ) |
| 60 | 60 | ); |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * server-side, there is no need to edit below this line. |
| 73 | 73 | */ |
| 74 | 74 | |
| 75 | -require( 'ssp.class.php' ); |
|
| 75 | +require('ssp.class.php'); |
|
| 76 | 76 | |
| 77 | 77 | echo json_encode( |
| 78 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 78 | + SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns) |
|
| 79 | 79 | ); |
| 80 | 80 | |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( isset( $_POST['src'] ) && preg_match( '/scripts\/[a-zA-Z_\-_]+\.php/', $_POST['src'] ) !== 0 ) { |
| 4 | - echo htmlspecialchars( file_get_contents( '../server_side/'.$_POST['src'] ) ); |
|
| 4 | + echo htmlspecialchars( file_get_contents( '../server_side/'.$_POST['src'] ) ); |
|
| 5 | 5 | } |
| 6 | 6 | else { |
| 7 | - echo ''; |
|
| 7 | + echo ''; |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( isset( $_POST['src'] ) && preg_match( '/scripts\/[a-zA-Z_\-_]+\.php/', $_POST['src'] ) !== 0 ) { |
|
| 4 | - echo htmlspecialchars( file_get_contents( '../server_side/'.$_POST['src'] ) ); |
|
| 3 | +if (isset($_POST['src']) && preg_match('/scripts\/[a-zA-Z_\-_]+\.php/', $_POST['src']) !== 0) { |
|
| 4 | + echo htmlspecialchars(file_get_contents('../server_side/' . $_POST['src'])); |
|
| 5 | 5 | } |
| 6 | 6 | else { |
| 7 | 7 | echo ''; |
@@ -2,8 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | if ( isset( $_POST['src'] ) && preg_match( '/scripts\/[a-zA-Z_\-_]+\.php/', $_POST['src'] ) !== 0 ) { |
| 4 | 4 | echo htmlspecialchars( file_get_contents( '../server_side/'.$_POST['src'] ) ); |
| 5 | -} |
|
| 6 | -else { |
|
| 5 | +} else { |
|
| 7 | 6 | echo ''; |
| 8 | 7 | } |
| 9 | 8 | |
@@ -29,19 +29,19 @@ discard block |
||
| 29 | 29 | // parameter represents the DataTables column identifier. In this case simple |
| 30 | 30 | // indexes |
| 31 | 31 | $columns = array( |
| 32 | - array( 'db' => 'id', 'dt' => 0 ), |
|
| 33 | - array( 'db' => 'firstname', 'dt' => 1 ), |
|
| 34 | - array( 'db' => 'surname', 'dt' => 2 ), |
|
| 35 | - array( 'db' => 'zip', 'dt' => 3 ), |
|
| 36 | - array( 'db' => 'country', 'dt' => 4 ) |
|
| 32 | + array( 'db' => 'id', 'dt' => 0 ), |
|
| 33 | + array( 'db' => 'firstname', 'dt' => 1 ), |
|
| 34 | + array( 'db' => 'surname', 'dt' => 2 ), |
|
| 35 | + array( 'db' => 'zip', 'dt' => 3 ), |
|
| 36 | + array( 'db' => 'country', 'dt' => 4 ) |
|
| 37 | 37 | ); |
| 38 | 38 | |
| 39 | 39 | // SQL server connection information |
| 40 | 40 | $sql_details = array( |
| 41 | - 'user' => '', |
|
| 42 | - 'pass' => '', |
|
| 43 | - 'db' => '', |
|
| 44 | - 'host' => '' |
|
| 41 | + 'user' => '', |
|
| 42 | + 'pass' => '', |
|
| 43 | + 'db' => '', |
|
| 44 | + 'host' => '' |
|
| 45 | 45 | ); |
| 46 | 46 | |
| 47 | 47 | |
@@ -53,6 +53,6 @@ discard block |
||
| 53 | 53 | require( '../../../../examples/server_side/scripts/ssp.class.php' ); |
| 54 | 54 | |
| 55 | 55 | echo json_encode( |
| 56 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 56 | + SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 57 | 57 | ); |
| 58 | 58 | |
@@ -29,11 +29,11 @@ discard block |
||
| 29 | 29 | // parameter represents the DataTables column identifier. In this case simple |
| 30 | 30 | // indexes |
| 31 | 31 | $columns = array( |
| 32 | - array( 'db' => 'id', 'dt' => 0 ), |
|
| 33 | - array( 'db' => 'firstname', 'dt' => 1 ), |
|
| 34 | - array( 'db' => 'surname', 'dt' => 2 ), |
|
| 35 | - array( 'db' => 'zip', 'dt' => 3 ), |
|
| 36 | - array( 'db' => 'country', 'dt' => 4 ) |
|
| 32 | + array('db' => 'id', 'dt' => 0), |
|
| 33 | + array('db' => 'firstname', 'dt' => 1), |
|
| 34 | + array('db' => 'surname', 'dt' => 2), |
|
| 35 | + array('db' => 'zip', 'dt' => 3), |
|
| 36 | + array('db' => 'country', 'dt' => 4) |
|
| 37 | 37 | ); |
| 38 | 38 | |
| 39 | 39 | // SQL server connection information |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | * server-side, there is no need to edit below this line. |
| 51 | 51 | */ |
| 52 | 52 | |
| 53 | -require( '../../../../examples/server_side/scripts/ssp.class.php' ); |
|
| 53 | +require('../../../../examples/server_side/scripts/ssp.class.php'); |
|
| 54 | 54 | |
| 55 | 55 | echo json_encode( |
| 56 | - SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ) |
|
| 56 | + SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns) |
|
| 57 | 57 | ); |
| 58 | 58 | |