81 lines
2.4 KiB
PHP
81 lines
2.4 KiB
PHP
|
<?php
|
||
|
|
||
|
/*
|
||
|
* Example PHP implementation used for the index.html example
|
||
|
*/
|
||
|
|
||
|
// DataTables PHP library
|
||
|
include("editor/lib/DataTables.php");
|
||
|
|
||
|
// Alias Editor classes so they are easy to use
|
||
|
use
|
||
|
DataTables\Editor,
|
||
|
DataTables\Editor\Field,
|
||
|
DataTables\Editor\Format,
|
||
|
DataTables\Editor\Mjoin,
|
||
|
DataTables\Editor\Options,
|
||
|
DataTables\Editor\Upload,
|
||
|
DataTables\Editor\Validate,
|
||
|
DataTables\Editor\ValidateOptions;
|
||
|
|
||
|
if (isset($_POST['type'])) {
|
||
|
$type = $_POST['type'];
|
||
|
} else {
|
||
|
$type = '%';
|
||
|
}
|
||
|
if ($_POST['status']>6) {
|
||
|
$status1 = 7;
|
||
|
$status2 = 8;
|
||
|
} else {
|
||
|
$status1 = $_POST['status'];
|
||
|
$status2 = $_POST['status'];
|
||
|
}
|
||
|
// Build our Editor instance and process the data coming from _POST
|
||
|
Editor::inst($db, 'request')
|
||
|
->where('request.type', $type, 'LIKE')
|
||
|
->where( function ( $q ) use ($status1, $status2) {
|
||
|
$q
|
||
|
->where('request.status', $status1 )
|
||
|
->or_where('request.status', $status2 );
|
||
|
} )
|
||
|
|
||
|
->fields(
|
||
|
Field::inst('request.id'),
|
||
|
Field::inst('request.type'),
|
||
|
Field::inst('request.reason'),
|
||
|
Field::inst('request.status')
|
||
|
->options(
|
||
|
Options::inst()
|
||
|
->table('status')
|
||
|
->value('id')
|
||
|
->label('name')
|
||
|
)
|
||
|
->validator(Validate::dbValues()),
|
||
|
Field::inst('documents.number'),
|
||
|
Field::inst('type.name'),
|
||
|
Field::inst('documents.description'),
|
||
|
Field::inst('status.name'),
|
||
|
Field::inst('request.document')
|
||
|
->options(
|
||
|
Options::inst()
|
||
|
->table('documents')
|
||
|
->value('id')
|
||
|
->label('description')
|
||
|
)
|
||
|
->validator(Validate::dbValues()),
|
||
|
Field::inst('request.user_id'),
|
||
|
Field::inst('request.name'),
|
||
|
Field::inst('request.date'),
|
||
|
Field::inst('request.company'),
|
||
|
Field::inst('company2.name'),
|
||
|
Field::inst('documents.company'),
|
||
|
Field::inst('company.name'),
|
||
|
)
|
||
|
->leftJoin('status', 'status.id', '=', 'request.status')
|
||
|
->leftJoin('documents', 'documents.id', '=', 'request.document')
|
||
|
->leftJoin('type', 'type.id', '=', 'documents.type')
|
||
|
->leftJoin('company', 'company.id', '=', 'documents.company')
|
||
|
->leftJoin('company AS company2', 'company2.id', '=', 'request.company')
|
||
|
->process($_POST)
|
||
|
->json();
|