168 lines
4.4 KiB
PHP
168 lines
4.4 KiB
PHP
<?php namespace App\Controllers;
|
|
|
|
use App\Libraries\Crud;
|
|
|
|
|
|
class CRUDController extends BaseController {
|
|
|
|
|
|
protected $crud;
|
|
|
|
public function CRUD_view($cols) {
|
|
helper(['tools','form']);
|
|
$data['tab'] = 'admin';
|
|
|
|
$page = 1;
|
|
if (isset($_GET['page'])) {
|
|
$page = (int) $_GET['page'];
|
|
$page = max(1, $page);
|
|
}
|
|
|
|
$data['title'] = $this->crud->getTableTitle();
|
|
|
|
$per_page = session()->get('pager_num');
|
|
$columns = $cols;
|
|
$where = null;//['DeletedAt =' => 'null'];
|
|
|
|
// imposto l'ordinamento richiesto:
|
|
CheckSort( $this->crud->getTable(), true);
|
|
$data['sortCol'] = session()->get('sort')['col'];
|
|
$data['sortDir'] = session()->get('sort')['dir'];
|
|
$order = [
|
|
[$data['sortCol'], $data['sortDir']]
|
|
];
|
|
$data['order']=$order;
|
|
$data['table'] = $this->crud->MRK_view($page, $per_page, $columns, $where, $order);
|
|
return view('pages/crud_table', $data);
|
|
}//function CRUD_view
|
|
|
|
public function CRUD_viewSelect($cols) {
|
|
helper(['tools','form']);
|
|
$data['tab'] = 'admin';
|
|
|
|
$page = 1;
|
|
if (isset($_GET['page'])) {
|
|
$page = (int) $_GET['page'];
|
|
$page = max(1, $page);
|
|
}
|
|
|
|
$data['title'] = $this->crud->getTableTitle();
|
|
|
|
$per_page = session()->get('pager_num');
|
|
$columns = $cols;
|
|
$where = null;//['DeletedAt =' => 'null'];
|
|
|
|
// imposto l'ordinamento richiesto:
|
|
CheckSort( $this->crud->getTable(), true);
|
|
$data['sortCol'] = session()->get('sort')['col'];
|
|
$data['sortDir'] = session()->get('sort')['dir'];
|
|
$order = [
|
|
[$data['sortCol'], $data['sortDir']]
|
|
];
|
|
$data['order']=$order;
|
|
$data['table'] = $this->crud->mrk_viewSelectCommessa($page, $per_page, $columns, $where, $order);
|
|
return view('pages/crud_table', $data);
|
|
}//function CRUD_view
|
|
|
|
|
|
public function CRUD_add() {
|
|
helper(['tools','form']);
|
|
|
|
// Verifico sessione e livello:
|
|
if (!CheckLevel(3)) {
|
|
session()->setFlashdata('warning', 'L\'utente non ha i permessi per inserire un nuovo record');
|
|
$pg = $this->crud->getTable();
|
|
return redirect()->to("/$pg");
|
|
}
|
|
|
|
$data['tab'] = 'admin';
|
|
$data['form'] = $form = $this->crud->form();
|
|
$data['title'] = $this->crud->getAddTitle();
|
|
|
|
if(is_array($form) && isset($form['redirect']))
|
|
return redirect()->to($form['redirect']);
|
|
|
|
return view('pages/crud_form', $data);
|
|
}//function CRUD_add
|
|
|
|
|
|
public function CRUD_edit($id) {
|
|
helper(['tools','form']);
|
|
|
|
// Verifico sessione e livello:
|
|
if (!CheckLevel(3)) {
|
|
session()->setFlashdata('warning', 'L\'utente non ha i permessi per editare un record');
|
|
$pg = $this->crud->getTable();
|
|
return redirect()->to("/$pg");
|
|
}
|
|
|
|
$data['tab'] = 'admin';
|
|
|
|
if(!$this->crud->current_values($id))
|
|
return redirect()->to($this->crud->getBase() . '/' . $this->crud->getTable());
|
|
|
|
$data['item_id'] = $id;
|
|
$data['form'] = $form = $this->crud->form();
|
|
$data['title'] = $this->crud->getEditTitle();
|
|
|
|
if (is_array($form) && isset($form['redirect']))
|
|
return redirect()->to($form['redirect']);
|
|
|
|
return view('pages/crud_form', $data);
|
|
}//function CRUD_edit
|
|
|
|
|
|
function CRUD_delete($id) {
|
|
$data = [];
|
|
helper(['tools','form']);
|
|
|
|
// Verifico sessione e livello:
|
|
if (!CheckLevel(3)) {
|
|
session()->setFlashdata('warning', 'L\'utente non ha i permessi per eliminare un record');
|
|
} else {
|
|
// Debug
|
|
//$data['form'] = $this->crud->MRK_deleteItem($id);
|
|
//return view('test', $data);
|
|
// Elimino il record:
|
|
if ($this->crud->MRK_deleteItem($id)) {
|
|
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
|
|
|
} else {
|
|
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
|
}
|
|
}
|
|
$pg = $this->crud->getTable();
|
|
return redirect()->to("/$pg");
|
|
|
|
}//function CRUD_delete
|
|
|
|
|
|
function CRUD_sort($col, $dir){
|
|
helper(['tools']);
|
|
SetSort($this->crud->getTable(), $col, $dir);
|
|
|
|
//return $this->CRUD_view();
|
|
$pg = $this->crud->getTable();
|
|
return redirect()->to("/$pg");
|
|
}//function CRUD_sort
|
|
|
|
|
|
function CRUD_exp(){
|
|
helper(['tools']);
|
|
|
|
session()->setFlashdata('warning', 'Esportazione dei record, per ora non abilitata.');
|
|
|
|
$pg = $this->crud->getTable();
|
|
return redirect()->to("/$pg");
|
|
}//function CRUD_exp
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
// Auto CRUD terminato
|
|
//--------------------------------------------------------------------
|
|
|
|
|
|
|
|
} |