129 lines
3.6 KiB
PHP
129 lines
3.6 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_' => 'documents',
|
||
|
'action' => $action,
|
||
|
'values' => json_encode( $values ),
|
||
|
'row' => $id
|
||
|
//'when' => date('c')
|
||
|
) );
|
||
|
}
|
||
|
Editor::inst($db, 'documents')
|
||
|
//->where('documents.company', $_POST['company'])
|
||
|
->fields(
|
||
|
Field::inst('documents.id'),
|
||
|
Field::inst('documents.date'),
|
||
|
Field::inst('documents.type')
|
||
|
->options(
|
||
|
Options::inst()
|
||
|
->table('type')
|
||
|
->value('id')
|
||
|
->label('name')
|
||
|
)
|
||
|
->validator(Validate::dbValues()),
|
||
|
Field::inst('documents.description'),
|
||
|
Field::inst('documents.company')
|
||
|
->options(
|
||
|
Options::inst()
|
||
|
->table('company')
|
||
|
->value('id')
|
||
|
->label('name')
|
||
|
)
|
||
|
->validator(Validate::dbValues()),
|
||
|
Field::inst('documents.department')
|
||
|
->options(
|
||
|
Options::inst()
|
||
|
->table('department')
|
||
|
->value('id')
|
||
|
->label('name')
|
||
|
)
|
||
|
->validator(Validate::dbValues()),
|
||
|
Field::inst('documents.region')
|
||
|
->options(
|
||
|
Options::inst()
|
||
|
->table('region')
|
||
|
->value('id')
|
||
|
->label('name')
|
||
|
)
|
||
|
->validator(Validate::dbValues()),
|
||
|
Field::inst('documents.province')
|
||
|
->options(
|
||
|
Options::inst()
|
||
|
->table('province')
|
||
|
->value('id')
|
||
|
->label('name')
|
||
|
)
|
||
|
->validator(Validate::dbValues()),
|
||
|
Field::inst('documents.city'),
|
||
|
Field::inst('documents.number'),
|
||
|
Field::inst('documents.area'),
|
||
|
Field::inst('documents.unit')
|
||
|
->options(
|
||
|
Options::inst()
|
||
|
->table('unit')
|
||
|
->value('id')
|
||
|
->label('name')
|
||
|
)
|
||
|
->validator(Validate::dbValues()),
|
||
|
Field::inst('documents.file')
|
||
|
->setFormatter( Format::ifEmpty( null ) )
|
||
|
->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/__ID__.__EXTN__' )
|
||
|
->db( 'files', 'id', array(
|
||
|
'filename' => Upload::DB_FILE_NAME,
|
||
|
'filesize' => Upload::DB_FILE_SIZE,
|
||
|
'web_path' => Upload::DB_WEB_PATH,
|
||
|
'system_path' => Upload::DB_SYSTEM_PATH
|
||
|
) )
|
||
|
->validator( Validate::fileSize( 900000, 'Files must be smaller that 500K' ) )
|
||
|
->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Please upload an image" ) )
|
||
|
),
|
||
|
Field::inst('documents.vault'),
|
||
|
Field::inst('documents.folder'),
|
||
|
Field::inst('type.name'),
|
||
|
Field::inst('company.name'),
|
||
|
Field::inst('department.name'),
|
||
|
Field::inst('unit.name'),
|
||
|
Field::inst('region.name'),
|
||
|
Field::inst('province.name'),
|
||
|
Field::inst('city.name')
|
||
|
)
|
||
|
|
||
|
->on( 'postCreate', function ( $editor, $id, &$values, &$row ) {
|
||
|
logChange( $editor->db(), 'create', $id, $values );
|
||
|
} )
|
||
|
->on( 'postEdit', function ( $editor, $id, &$values, &$row ) {
|
||
|
logChange( $editor->db(), 'edit', $id, $values );
|
||
|
} )
|
||
|
|
||
|
->leftJoin('city', 'city.id', '=', 'documents.city')
|
||
|
->leftJoin('province', 'province.id', '=', 'documents.province')
|
||
|
->leftJoin('region', 'region.id', '=', 'documents.region')
|
||
|
->leftJoin('unit', 'unit.id', '=', 'documents.unit')
|
||
|
->leftJoin('department', 'department.id', '=', 'documents.department')
|
||
|
->leftJoin('company', 'company.id', '=', 'documents.company')
|
||
|
->leftJoin('type', 'type.id', '=', 'documents.type')
|
||
|
->process($_POST)
|
||
|
->json();
|
||
|
|