Start Point al 2026
This commit is contained in:
commit
8a76e1db3b
371 files changed
+160283
No files matched your search
@@ -0,0 +1,355 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Crud;
|
||||
use App\Models\SIMs_Model;
|
||||
use App\Models\SIMEvents_Model;
|
||||
|
||||
|
||||
class Sims extends CRUDController {
|
||||
|
||||
// Tab: SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smStato', 'smCreatedAt', 'smUpdatedAt', 'smDeletedAt'];
|
||||
|
||||
protected $crud;
|
||||
|
||||
function __construct() {
|
||||
|
||||
$params = [
|
||||
'table' => 'SIMs',
|
||||
'dev' => false,
|
||||
'fields' => $this->field_options(),
|
||||
'form_title_add' => 'Add SIM',
|
||||
'form_title_update' => 'Edit SIM',
|
||||
'form_submit' => 'Add',
|
||||
'table_title' => 'Pagina per la tabella SIMs',
|
||||
'form_submit_update' => 'Update',
|
||||
'base' => '',
|
||||
'UpdatedAt' => 'smUpdatedAt',
|
||||
'DeletedAt' => 'smDeletedAt',
|
||||
];
|
||||
|
||||
$this->crud = new Crud($params, service('request'));
|
||||
}// __construct
|
||||
|
||||
protected function field_options() {
|
||||
|
||||
$fields = [];
|
||||
$fields['smIDsim'] = ['label' => 'ID', 'helper' => 'Identificativo univoco del record nel database'];
|
||||
$fields['smNumero'] = ['label' => 'Numero', 'helper' => 'Numero telefonico (max 16 caratteri)', 'required' => true];
|
||||
$fields['smPIN'] = ['label' => 'PIN', 'helper' => 'PIN della SIM (max 16 caratteri)', 'required' => true];
|
||||
$fields['smPUK'] = ['label' => 'PUK', 'helper' => 'PUK della SIM (max 16 caratteri)', 'required' => true];
|
||||
$fields['smDescrizione'] = ['label' => 'Descrizione', 'helper' => 'Descrizione esaustiva della SIM', 'required' => true];
|
||||
$fields['smCredito'] = ['label' => 'Credito', 'helper' => 'Credito stimato sulla SIM', 'required' => true];
|
||||
$fields['smStato'] = ['label' => 'Stato', 'helper' => 'Stato di disponmibilità della SIM', 'required' => true];
|
||||
$fields['smCreatedAt'] = ['label' => 'Created At', 'helper' => 'Data di creazione del record relativo nel database', 'only_edit'=> true];
|
||||
$fields['smUpdatedAt'] = ['label' => 'Updated At', 'helper' => 'Timestamp dell\'ultimo aggiornamento del record nel database', 'type' => 'unset'];
|
||||
$fields['smDeletedAt'] = ['label' => 'Deleted At', 'helper' => 'Data di cancellazione del record relativo nel database', 'type' => 'unset'];
|
||||
|
||||
return $fields;
|
||||
}// field_options
|
||||
|
||||
|
||||
public function index() { return $this->CRUD_view(['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smStato', 'smCreatedAt', 'smUpdatedAt', 'smDeletedAt']); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Auto CRUD terminato
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function select($IDsim = null) {
|
||||
helper(['tools','form']);
|
||||
$data['tab'] = 'sims';
|
||||
$model = new SIMs_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/select -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// memorizzo la selezione
|
||||
session()->set('filter_sim', $IDsim);
|
||||
|
||||
// visualizzo gli eventi della carta selezionata:
|
||||
return redirect()->to('/SIMEvents/show');
|
||||
}//function select
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function add() {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/add -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Solo amministratori possono inserire una nuova sim:
|
||||
if (!$enable){
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per inserire una nuova SIM aziendale.');
|
||||
return redirect()->to('/dashboard/sims');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'sims';
|
||||
$data['add'] = true;
|
||||
$data['title'] = 'Dettagli nuova SIM';
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
//
|
||||
$rules = [
|
||||
'Numero' => 'trim|required|min_length[8]|max_length[20]',
|
||||
'PIN' => 'trim|required|min_length[4]|max_length[16]',
|
||||
'PUK' => 'trim|required|min_length[4]|max_length[16]',
|
||||
'Credito' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
//'Stato' => 'trim|required',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'inserimento
|
||||
// SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smCreatedAt', 'smUpdatedAt', 'smStato', 'smDeletedAt'];
|
||||
$newData = [
|
||||
'smNumero' => $this->request->getVar('Numero'),
|
||||
'smPIN' => $this->request->getVar('PIN'),
|
||||
'smPUK' => $this->request->getVar('PUK'),
|
||||
'smCredito' => $this->request->getVar('Credito'),
|
||||
'smDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'smStato' => 'Disponibile',
|
||||
];
|
||||
|
||||
$model = new Sims_Model();
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Record inserito con successo sul DB');
|
||||
if(isset($_POST['crea_continua'])) {
|
||||
// è stato premuto il secondo pulsante, quindi inserisco un secondo valore:
|
||||
//return redirect()->to('/dashboard/orari');
|
||||
} else {
|
||||
return redirect()->to('/dashboard/sims');
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'inserimento del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/sims_form_add_edit', $data);
|
||||
}//function add
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function edit($IDsim = null) {
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDsim==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/edit -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/add -> Error code 002'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Ricavo livello del lavoratore (solo amministratori o superiori, possono editare tutti i campi)
|
||||
$data['enable'] = $enable = CheckLevel(3, false);
|
||||
|
||||
// Solo amministratori possono editare una carta:
|
||||
if (!$enable){
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per editare i dati di una carta di credito aziendale.');
|
||||
return redirect()->to('/dashboard/sims');
|
||||
}
|
||||
|
||||
// preparo i dati
|
||||
$data['tab'] = 'sims';
|
||||
$data['add'] = false;
|
||||
$data['title'] = 'Dettagli della SIM telefonica';
|
||||
|
||||
// Ricavo il profilo dell'orario da editare
|
||||
// SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smCreatedAt', 'smUpdatedAt', 'smStato', 'smDeletedAt'];
|
||||
$model = new Sims_Model();
|
||||
$data['sim'] = $model->where('smIDsim', $IDsim)
|
||||
->first();
|
||||
|
||||
// Verifico che esista il record dell'orario:
|
||||
if (null==$data['sim']) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/edit -> Error code 003'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Gestione POST
|
||||
if ($this->request->getMethod() == 'post') {
|
||||
// Regole per validare i campi introdotti nel form:
|
||||
$rules = [
|
||||
'Numero' => 'trim|required|min_length[8]|max_length[20]',
|
||||
'PIN' => 'trim|required|min_length[4]|max_length[16]',
|
||||
'PUK' => 'trim|required|min_length[4]|max_length[16]',
|
||||
'Credito' => 'trim|required',
|
||||
'Descrizione' => 'trim|required|min_length[8]',
|
||||
'Stato' => 'trim|required',
|
||||
];
|
||||
|
||||
// analisi della validazione
|
||||
if (! $this->validate($rules)) {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', $data['validation']->listErrors());
|
||||
|
||||
}else{
|
||||
// validazione passata
|
||||
// Preparo i dati per l'aggiornamento
|
||||
// Tab: sims = ['smIDsim', 'ccNumero', 'ccDescrizione', 'ccScadeIl', 'ccPIN', 'ccCreatedAt', 'ccUpdatedAt', 'ccStato', 'ccDeletedAt'];
|
||||
$newData = [
|
||||
'smIDsim' => $this->request->getVar('IDsim'),
|
||||
'smNumero' => $this->request->getVar('Numero'),
|
||||
'smPIN' => $this->request->getVar('PIN'),
|
||||
'smPUK' => $this->request->getVar('PUK'),
|
||||
'smCredito' => $this->request->getVar('Credito'),
|
||||
'smDescrizione' => $this->request->getVar('Descrizione'),
|
||||
'smStato' => $this->request->getVar('Stato'),
|
||||
];
|
||||
|
||||
$model = new Sims_Model();
|
||||
if ($model->save($newData)) {
|
||||
session()->setFlashdata('success', 'Successfuly Updated');
|
||||
return redirect()->to('/dashboard/sims');
|
||||
} else {
|
||||
session()->setFlashdata('danger', 'Errore durante l\'update del record nel DB.');
|
||||
}
|
||||
|
||||
}// analisi validazione
|
||||
|
||||
}// Gestione POST
|
||||
|
||||
|
||||
// Show form
|
||||
echo view('pages/form/sims_form_add_edit', $data);
|
||||
}//function edit
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function delete($IDsim = null){
|
||||
helper(['tools']);
|
||||
$data = [];
|
||||
$model = new Sims_Model();
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(3)) {
|
||||
session()->setFlashdata('warning', 'Non si hanno i permessi per cancellare una SIM aziendale.');
|
||||
return redirect()->to('/dashboard/sims');
|
||||
}
|
||||
|
||||
// Verifico dato introdotto:
|
||||
if ($IDsim==null) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/delete -> Error code 001'); }
|
||||
return redirect()->to('/dashboard');
|
||||
}
|
||||
|
||||
// Elimino il record:
|
||||
if ($model->delete($IDsim)) {
|
||||
session()->setFlashdata('success', 'Recors cancellato correttamente.');
|
||||
|
||||
} else {
|
||||
$data['validation'] = $this->validator;
|
||||
session()->setFlashdata('warning', 'Errore durante la cancellazione del record.');
|
||||
}
|
||||
|
||||
// Show profile
|
||||
return redirect()->to('/dashboard/sims');
|
||||
} // function delete($id)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public function export_csv(){
|
||||
helper(['tools','form']);
|
||||
|
||||
// Verifico sessione e livello:
|
||||
if (!CheckLevel(1)) {
|
||||
if (ENVIRONMENT === 'development') { session()->setFlashdata('warning', '/SIMs/export_csv -> Error code 001'); }
|
||||
return redirect()->to('/Lavoratori/login');
|
||||
}
|
||||
|
||||
// Ricavo le ore dell'utente:
|
||||
// SIMs = ['smIDsim', 'smNumero', 'smPIN', 'smPUK', 'smDescrizione', 'smCredito', 'smCreatedAt', 'smUpdatedAt', 'smStato', 'smDeletedAt'];
|
||||
$model = new Sims_Model();
|
||||
|
||||
// Costruisco la query per selezionare le ore da esportare:
|
||||
// - applico eventuale filtro per lo stato:
|
||||
|
||||
// imposto l'ordinamento richiesto:
|
||||
CheckSort('sims',true);
|
||||
$data['sortCol'] = session()->get('sort')['col'];
|
||||
$data['sortDir'] = session()->get('sort')['dir'];
|
||||
$model->orderBy($data['sortCol'], $data['sortDir']);
|
||||
|
||||
// eseguo la query:
|
||||
$data['dataset'] = $model->asArray()
|
||||
->findAll();
|
||||
|
||||
// Imposto il nome del file da downloadare:
|
||||
$filepath = $_SERVER['MRK_FILE_PATH'];
|
||||
$filename = 'CSiCoDB_SIMs_il_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
// file creation
|
||||
$file = fopen($filepath . $filename,"w");
|
||||
// Esport header
|
||||
fputcsv($file,['ID SIM', 'Numero', 'PIN', 'PUK', 'Descrizione', 'Credito', 'CreatedAt', 'UpdatedAt', 'Stato']);
|
||||
|
||||
foreach ($data['dataset'] as $line){
|
||||
fputcsv($file,$line);
|
||||
}
|
||||
// Chiudo il file
|
||||
fclose($file);
|
||||
// download
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-Disposition: attachment; filename=".$filename);
|
||||
header("Content-Type: application/csv; ");
|
||||
readfile($filepath . $filename);
|
||||
// deleting file
|
||||
unlink($filepath . $filename);
|
||||
exit();
|
||||
} // function export_csv
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}//class Sims
|
||||
Reference in new issue
Block a user