94 lines
3.0 KiB
PHP
94 lines
3.0 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;
|
||
|
|
||
|
// Build our Editor instance and process the data coming from _POST
|
||
|
function logChange ( $db, $action, $id, &$values ) {
|
||
|
$db->insert( 'change_log', array(
|
||
|
'user' => $_POST['user'],
|
||
|
'table_' => 'request',
|
||
|
'action' => $action,
|
||
|
'values' => json_encode( $values ),
|
||
|
'row' => $id
|
||
|
|
||
|
//'when' => date('c')
|
||
|
) );
|
||
|
}
|
||
|
|
||
|
Editor::inst($db, 'request')
|
||
|
->where( 'request.user_id', $_POST['id'] )
|
||
|
->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.company'),
|
||
|
Field::inst('company2.name'),
|
||
|
Field::inst('request.date'),
|
||
|
Field::inst('documents.company'),
|
||
|
Field::inst('company.name'),
|
||
|
|
||
|
)
|
||
|
|
||
|
|
||
|
->on( 'postCreate', function ( $editor, $id, &$values, &$row ) {
|
||
|
logChange( $editor->db(), 'create', $id, $values );
|
||
|
$doc_id = $values['request']['document']; // Assign the value of $doc_id
|
||
|
$user_id = $values['request']['user_id']; // Assign the value of $user_id
|
||
|
exec("php actions/create.php id=$id doc_id=$doc_id user_id=$user_id");
|
||
|
//header("Location: ../actions/create.php?doc_id=$doc_id&user_id=$user_id");
|
||
|
//exit();
|
||
|
} )
|
||
|
->on( 'postEdit', function ( $editor, $id, &$values, &$row ) {
|
||
|
logChange( $editor->db(), 'edit', $id, $values );
|
||
|
} )
|
||
|
// ->on( 'postRemove', function ( $editor, &$id, &$values ) {
|
||
|
// logChange( $editor->db(), 'delete', $id, $values );
|
||
|
// } )
|
||
|
|
||
|
|
||
|
->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();
|