|
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
|
|
|
use HaaseIT\HCSF\HardcodedText; |
|
24
|
|
|
use HaaseIT\HCSF\HelperConfig; |
|
25
|
|
|
use HaaseIT\Toolbox\Tools; |
|
26
|
|
|
use Zend\ServiceManager\ServiceManager; |
|
27
|
|
|
|
|
28
|
|
|
class Textcatadmin extends Base |
|
29
|
|
|
{ |
|
30
|
|
|
private $textcats; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct(ServiceManager $serviceManager) |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct($serviceManager); |
|
35
|
|
|
$this->textcats = $serviceManager->get('textcats'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function preparePage() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager); |
|
41
|
|
|
$this->P->cb_pagetype = 'content'; |
|
42
|
|
|
$this->P->cb_subnav = 'admin'; |
|
43
|
|
|
|
|
44
|
|
|
$this->P->cb_customcontenttemplate = 'textcatadmin'; |
|
45
|
|
|
|
|
46
|
|
|
$return = ''; |
|
47
|
|
|
|
|
48
|
|
|
$getaction = filter_input(INPUT_GET, 'action'); |
|
49
|
|
|
if (empty($getaction)) { |
|
50
|
|
|
$aData = $this->textcats->getCompleteTextcatForCurrentLang(); |
|
51
|
|
|
|
|
52
|
|
|
$aListSetting = [ |
|
53
|
|
|
['title' => HardcodedText::get('textcatadmin_list_title_key'), 'key' => 'tc_key', 'width' => '20%', 'linked' => false,], |
|
54
|
|
|
['title' => HardcodedText::get('textcatadmin_list_title_text'), 'key' => 'tcl_text', 'width' => '80%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
|
55
|
|
|
[ |
|
56
|
|
|
'title' => HardcodedText::get('textcatadmin_list_title_edit'), |
|
57
|
|
|
'key' => 'tc_id', |
|
58
|
|
|
'width' => 35, |
|
59
|
|
|
'linked' => true, |
|
60
|
|
|
'ltarget' => '/_admin/textcatadmin.html', |
|
61
|
|
|
'lkeyname' => 'id', |
|
62
|
|
|
'lgetvars' => [ |
|
63
|
|
|
'action' => 'edit', |
|
64
|
|
|
], |
|
65
|
|
|
], |
|
66
|
|
|
]; |
|
67
|
|
|
$return .= Tools::makeListtable($aListSetting, $aData, $this->serviceManager->get('twig')); |
|
68
|
|
|
} elseif ($getaction === 'edit' || $getaction === 'delete') { |
|
69
|
|
|
$getid = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); |
|
70
|
|
|
if ($getaction === 'delete' && filter_input(INPUT_POST, 'delete') === 'do') { |
|
71
|
|
|
$this->textcats->deleteText($getid); |
|
72
|
|
|
$this->P->cb_customdata['deleted'] = true; |
|
73
|
|
|
} else { |
|
74
|
|
|
$this->P->cb_customdata['edit'] = true; |
|
75
|
|
|
|
|
76
|
|
|
$this->textcats->initTextIfVoid($getid); |
|
77
|
|
|
|
|
78
|
|
|
// if post:edit is set, update |
|
79
|
|
|
if (filter_input(INPUT_POST, 'edit') === 'do') { |
|
80
|
|
|
$this->textcats->purifier = false; |
|
81
|
|
|
if (HelperConfig::$core['textcat_enable_purifier']) { |
|
82
|
|
|
$this->textcats->purifier = \HaaseIT\HCSF\Helper::getPurifier('textcat'); |
|
83
|
|
|
} |
|
84
|
|
|
$this->textcats->saveText( |
|
85
|
|
|
filter_input(INPUT_POST, 'lid', FILTER_SANITIZE_NUMBER_INT), |
|
86
|
|
|
filter_input(INPUT_POST, 'text') |
|
87
|
|
|
); |
|
88
|
|
|
$this->P->cb_customdata['updated'] = true; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$aData = $this->textcats->getSingleTextByID($getid); |
|
92
|
|
|
$this->P->cb_customdata['editform'] = [ |
|
93
|
|
|
'id' => $aData['tc_id'], |
|
94
|
|
|
'lid' => $aData['tcl_id'], |
|
95
|
|
|
'key' => $aData['tc_key'], |
|
96
|
|
|
'lang' => $aData['tcl_lang'], |
|
97
|
|
|
'text' => $aData['tcl_text'], |
|
98
|
|
|
]; |
|
99
|
|
|
|
|
100
|
|
|
// show archived versions of this textcat |
|
101
|
|
|
$dbal = $this->serviceManager->get('dbal'); |
|
102
|
|
|
|
|
103
|
|
|
/** @var \Doctrine\DBAL\Query\QueryBuilder $queryBuilder */ |
|
104
|
|
|
$queryBuilder = $dbal->createQueryBuilder(); |
|
105
|
|
|
$queryBuilder |
|
106
|
|
|
->select('*') |
|
107
|
|
|
->from('textcat_lang_archive') |
|
108
|
|
|
->where('tcl_id = ?') |
|
109
|
|
|
->andWhere('tcl_lang = ?') |
|
110
|
|
|
->setParameter(0, $aData['tcl_id']) |
|
111
|
|
|
->setParameter(1, HelperConfig::$lang) |
|
112
|
|
|
->orderBy('tcla_timestamp', 'DESC') |
|
113
|
|
|
; |
|
114
|
|
|
$statement = $queryBuilder->execute(); |
|
115
|
|
|
$iArchivedRows = $statement->rowCount(); |
|
116
|
|
|
|
|
117
|
|
|
if ($iArchivedRows > 0) { |
|
118
|
|
|
$aListSetting = [ |
|
119
|
|
|
['title' => 'tcla_timestamp', 'key' => 'tcla_timestamp', 'width' => '15%', 'linked' => false,], |
|
120
|
|
|
['title' => 'tcl_text', 'key' => 'tcl_text', 'width' => '85%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
|
121
|
|
|
]; |
|
122
|
|
|
$aData = $statement->fetchAll(); |
|
123
|
|
|
$this->P->cb_customdata['archived_list'] = Tools::makeListtable($aListSetting, |
|
124
|
|
|
$aData, $this->serviceManager->get('twig')); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
} elseif ($getaction === 'add') { |
|
128
|
|
|
$this->P->cb_customdata['add'] = true; |
|
129
|
|
|
if (filter_input(INPUT_POST, 'add') === 'do') { |
|
130
|
|
|
$postkey = filter_input(INPUT_POST, 'key', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
131
|
|
|
$this->P->cb_customdata['err'] = $this->textcats->verifyAddTextKey($postkey); |
|
132
|
|
|
|
|
133
|
|
|
if (count($this->P->cb_customdata['err']) == 0) { |
|
134
|
|
|
$this->P->cb_customdata['addform'] = [ |
|
135
|
|
|
'key' => $postkey, |
|
136
|
|
|
'id' => $this->textcats->addTextKey($postkey), |
|
137
|
|
|
]; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
$this->P->oPayload->cl_html = $return; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|