44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php namespace App\Controllers;
|
|
|
|
use CodeIgniter\Session\Session;
|
|
use App\Models\mAccounts;
|
|
use Config\App;
|
|
|
|
class Accounts extends BaseController {
|
|
private \App\Models\mAccounts $accounts;
|
|
|
|
public function __construct() {
|
|
$this->accounts = new mAccounts;
|
|
}
|
|
|
|
public function index(){
|
|
if ($this->request->is('post')) {
|
|
return $this->editAccount();
|
|
}
|
|
else
|
|
return $this->viewAccountsTree();
|
|
}
|
|
|
|
private function viewAccountsTree($data = array()){
|
|
helper('form');
|
|
$data = array_merge($data,$this->accounts->getTreeData());
|
|
$data['ddlist'] = $this->accounts->getDropDownList( 'all', false,true );
|
|
return view('accountstree',$data);
|
|
}
|
|
|
|
private function editAccount(){
|
|
$rules = [
|
|
'description' => 'required',
|
|
];
|
|
if (! $this->validate($rules)) {
|
|
return $this->viewAccountsTree(['errors'=>$this->validator->getErrors()]);
|
|
}
|
|
$saveDB = array();
|
|
if ($this->accounts->saveAccount($this->request->getPost()))
|
|
$saveDB = ['mode'=>'alert-success','message'=>'Erfolgreich gespeichert'];
|
|
else
|
|
$saveDB = ['mode'=>'alert-danger','message'=>'Speichern fehlgeschlagen'];
|
|
|
|
return $this->viewAccountsTree(['saveDB'=>$saveDB]);
|
|
}
|
|
}; |