1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
HCSF - A multilingual CMS and Shopsystem |
5
|
|
|
Copyright (C) 2014 Marcus Haase - [email protected] |
6
|
|
|
|
7
|
|
|
This program is free software: you can redistribute it and/or modify |
8
|
|
|
it under the terms of the GNU General Public License as published by |
9
|
|
|
the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
(at your option) any later version. |
11
|
|
|
|
12
|
|
|
This program is distributed in the hope that it will be useful, |
13
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
GNU General Public License for more details. |
16
|
|
|
|
17
|
|
|
You should have received a copy of the GNU General Public License |
18
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace HaaseIT\HCSF\Controller\Admin; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
use HaaseIT\Toolbox\Tools; |
25
|
|
|
use Zend\ServiceManager\ServiceManager; |
26
|
|
|
|
27
|
|
|
class Textcatadmin extends Base |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var \HaaseIT\Toolbox\Textcat |
31
|
|
|
*/ |
32
|
|
|
private $textcats; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \HaaseIT\HCSF\HardcodedText |
36
|
|
|
*/ |
37
|
|
|
private $hardcodedtextcats; |
38
|
|
|
|
39
|
|
|
public function __construct(ServiceManager $serviceManager) |
40
|
|
|
{ |
41
|
|
|
parent::__construct($serviceManager); |
42
|
|
|
$this->textcats = $serviceManager->get('textcats'); |
43
|
|
|
$this->hardcodedtextcats = $serviceManager->get('hardcodedtextcats'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function preparePage() |
47
|
|
|
{ |
48
|
|
|
$this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager, [], 'admin/base.twig'); |
49
|
|
|
$this->P->cb_pagetype = 'content'; |
50
|
|
|
$this->P->cb_subnav = 'admin'; |
51
|
|
|
|
52
|
|
|
$this->P->cb_customcontenttemplate = 'textcatadmin'; |
53
|
|
|
|
54
|
|
|
$return = ''; |
55
|
|
|
|
56
|
|
|
$getaction = filter_input(INPUT_GET, 'action'); |
57
|
|
|
if (empty($getaction)) { |
58
|
|
|
$aData = $this->textcats->getCompleteTextcatForCurrentLang(); |
59
|
|
|
|
60
|
|
|
$aListSetting = [ |
61
|
|
|
['title' => $this->hardcodedtextcats->get('textcatadmin_list_title_key'), 'key' => 'tc_key', 'width' => '20%', 'linked' => false,], |
62
|
|
|
['title' => $this->hardcodedtextcats->get('textcatadmin_list_title_text'), 'key' => 'tcl_text', 'width' => '80%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
63
|
|
|
[ |
64
|
|
|
'title' => $this->hardcodedtextcats->get('textcatadmin_list_title_edit'), |
65
|
|
|
'key' => 'tc_id', |
66
|
|
|
'width' => 35, |
67
|
|
|
'linked' => true, |
68
|
|
|
'ltarget' => '/_admin/textcatadmin.html', |
69
|
|
|
'lkeyname' => 'id', |
70
|
|
|
'lgetvars' => [ |
71
|
|
|
'action' => 'edit', |
72
|
|
|
], |
73
|
|
|
], |
74
|
|
|
]; |
75
|
|
|
$return .= Tools::makeListtable($aListSetting, $aData, $this->serviceManager->get('twig')); |
76
|
|
|
} elseif ($getaction === 'edit' || $getaction === 'delete') { |
77
|
|
|
$getid = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); |
78
|
|
|
if ($getaction === 'delete' && filter_input(INPUT_POST, 'delete') === 'do') { |
79
|
|
|
$this->textcats->deleteText($getid); |
80
|
|
|
$this->P->cb_customdata['deleted'] = true; |
81
|
|
|
} else { |
82
|
|
|
$this->P->cb_customdata['edit'] = true; |
83
|
|
|
|
84
|
|
|
$this->textcats->initTextIfVoid($getid); |
85
|
|
|
|
86
|
|
|
// if post:edit is set, update |
87
|
|
|
if (filter_input(INPUT_POST, 'edit') === 'do') { |
88
|
|
|
$this->textcats->purifier = false; |
89
|
|
|
if ($this->config->getCore('textcat_enable_purifier')) { |
90
|
|
|
$this->textcats->purifier = $this->helper->getPurifier('textcat'); |
91
|
|
|
} |
92
|
|
|
$this->textcats->saveText( |
93
|
|
|
filter_input(INPUT_POST, 'lid', FILTER_SANITIZE_NUMBER_INT), |
94
|
|
|
filter_input(INPUT_POST, 'text') |
95
|
|
|
); |
96
|
|
|
$this->P->cb_customdata['updated'] = true; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$aData = $this->textcats->getSingleTextByID($getid); |
100
|
|
|
$this->P->cb_customdata['editform'] = [ |
101
|
|
|
'id' => $aData['tc_id'], |
102
|
|
|
'lid' => $aData['tcl_id'], |
103
|
|
|
'key' => $aData['tc_key'], |
104
|
|
|
'lang' => $aData['tcl_lang'], |
105
|
|
|
'text' => $aData['tcl_text'], |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
// show archived versions of this textcat |
109
|
|
|
$dbal = $this->serviceManager->get('dbal'); |
110
|
|
|
|
111
|
|
|
/** @var \Doctrine\DBAL\Query\QueryBuilder $queryBuilder */ |
112
|
|
|
$queryBuilder = $dbal->createQueryBuilder(); |
113
|
|
|
$queryBuilder |
114
|
|
|
->select('*') |
115
|
|
|
->from('textcat_lang_archive') |
116
|
|
|
->where('tcl_id = ?') |
117
|
|
|
->andWhere('tcl_lang = ?') |
118
|
|
|
->setParameter(0, $aData['tcl_id']) |
119
|
|
|
->setParameter(1, $this->config->getLang()) |
120
|
|
|
->orderBy('tcla_timestamp', 'DESC') |
121
|
|
|
; |
122
|
|
|
$statement = $queryBuilder->execute(); |
123
|
|
|
$iArchivedRows = $statement->rowCount(); |
124
|
|
|
|
125
|
|
|
if ($iArchivedRows > 0) { |
126
|
|
|
$aListSetting = [ |
127
|
|
|
['title' => 'tcla_timestamp', 'key' => 'tcla_timestamp', 'width' => '15%', 'linked' => false,], |
128
|
|
|
['title' => 'tcl_text', 'key' => 'tcl_text', 'width' => '85%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
129
|
|
|
]; |
130
|
|
|
$aData = $statement->fetchAll(); |
131
|
|
|
$this->P->cb_customdata['archived_list'] = Tools::makeListtable($aListSetting, |
132
|
|
|
$aData, $this->serviceManager->get('twig')); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
} elseif ($getaction === 'add') { |
136
|
|
|
$this->P->cb_customdata['add'] = true; |
137
|
|
|
if (filter_input(INPUT_POST, 'add') === 'do') { |
138
|
|
|
$postkey = filter_input(INPUT_POST, 'key', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
139
|
|
|
$this->P->cb_customdata['err'] = $this->textcats->verifyAddTextKey($postkey); |
140
|
|
|
|
141
|
|
|
if (count($this->P->cb_customdata['err']) == 0) { |
142
|
|
|
$this->P->cb_customdata['addform'] = [ |
143
|
|
|
'key' => $postkey, |
144
|
|
|
'id' => $this->textcats->addTextKey($postkey), |
145
|
|
|
]; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
$this->P->oPayload->cl_html = $return; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|