1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use App\Models\ConfigModel; |
6
|
|
|
use Core\AdminController; |
7
|
|
|
use Core\Traits\StringFunctions; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* all to do with the config page |
11
|
|
|
* Class Config |
12
|
|
|
* @package App\Controllers\Admin |
13
|
|
|
*/ |
14
|
|
|
class Config extends AdminController |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
use StringFunctions; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Shows the config page with all of the config options |
21
|
|
|
* @throws \Twig_Error_Loader |
22
|
|
|
* @throws \Twig_Error_Runtime |
23
|
|
|
* @throws \Twig_Error_Syntax |
24
|
|
|
* @throws \ReflectionException |
25
|
|
|
*/ |
26
|
|
|
public function index() |
27
|
|
|
{ |
28
|
|
|
$this->onlyAdmin(); |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
$configObj = new ConfigModel($this->container); |
32
|
|
|
$this->data['configList'] = $configObj->getAllConfigOrdered(); |
33
|
|
|
$this->renderView('Admin/Config'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* gets the information in post and sets the corresponding site config details |
39
|
|
|
* this is pure php with no ajax |
40
|
|
|
* @throws \Exception |
41
|
|
|
*/ |
42
|
|
|
public function updateConfig() |
43
|
|
|
{ |
44
|
|
|
//Security checks |
45
|
|
|
$this->onlyAdmin(); |
46
|
|
|
if (!$this->container->getRequest()->isPost()) { |
47
|
|
|
$this->alertBox->setAlert('Only post messages allowed', 'error'); |
48
|
|
|
$this->container->getResponse()->redirect('admin'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$configModel = new ConfigModel($this->container); |
52
|
|
|
$posts = $this->container->getRequest()->getDataFull(); |
53
|
|
|
$success = true; |
54
|
|
|
|
55
|
|
|
foreach ($posts as $key => $config) { |
56
|
|
|
if (!$configModel->updateConfig($key, $config)) { |
57
|
|
|
$success = false; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
if ($success) { |
61
|
|
|
$this->alertBox->setAlert('Configuration updates successfully'); |
62
|
|
|
} else { |
63
|
|
|
$this->alertBox->setAlert('error in configuration update', 'error'); |
64
|
|
|
} |
65
|
|
|
$this->container->getResponse()->redirect('admin/config'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|