1
|
<?php
|
2
|
/* --------------------------------------------------------------
|
3
|
itrecht_config.php 2013-06-04 mabr
|
4
|
Gambio GmbH
|
5
|
http://www.gambio.de
|
6
|
Copyright (c) 2013 Gambio GmbH
|
7
|
Released under the GNU General Public License (Version 2)
|
8
|
[http://www.gnu.org/licenses/gpl-2.0.html]
|
9
|
--------------------------------------------------------------
|
10
|
*/
|
11
|
|
12
|
require_once 'includes/application_top.php';
|
13
|
define('PAGE_URL', HTTP_SERVER.DIR_WS_ADMIN.basename(__FILE__));
|
14
|
|
15
|
ob_start();
|
16
|
|
17
|
$messages_ns = 'messages_'.basename(__FILE__);
|
18
|
if(!isset($_SESSION[$messages_ns])) {
|
19
|
$_SESSION[$messages_ns] = array();
|
20
|
}
|
21
|
|
22
|
function replaceLanguagePlaceholders($content)
|
23
|
{
|
24
|
$coo_txt = MainFactory::create_object('LanguageTextManager', array('itrecht', $_SESSION['languages_id']));
|
25
|
while(preg_match('/##(\w+)\b/', $content, $matches) == 1) {
|
26
|
$replacement = $coo_txt->get_text($matches[1]);
|
27
|
if(empty($replacement)) {
|
28
|
$replacement = $matches[1];
|
29
|
}
|
30
|
$content = preg_replace('/##'.$matches[1].'/', $replacement.'$1', $content, 1);
|
31
|
}
|
32
|
return $content;
|
33
|
}
|
34
|
|
35
|
function filelink($file) {
|
36
|
$fullpath = DIR_FS_CATALOG.$file;
|
37
|
if(file_exists($fullpath)) {
|
38
|
$fdate = filemtime($fullpath);
|
39
|
$text = date('c', $fdate);
|
40
|
$url = HTTP_SERVER.DIR_WS_CATALOG.$file;
|
41
|
$out = '<a href="'.$url.'" target="_new">'.$text.'</a>';
|
42
|
}
|
43
|
else {
|
44
|
$out = "<em>$file ##not_received_yet</em>";
|
45
|
}
|
46
|
return $out;
|
47
|
}
|
48
|
|
49
|
function getCmGroupIdForType($type) {
|
50
|
$mapping = array(
|
51
|
'agb' => 3,
|
52
|
'impressum' => 4,
|
53
|
'datenschutz' => 2,
|
54
|
'widerruf' => 3889896,
|
55
|
);
|
56
|
if(array_key_exists($type, $mapping)) {
|
57
|
return $mapping[$type];
|
58
|
}
|
59
|
return false;
|
60
|
}
|
61
|
|
62
|
|
63
|
function cmConfigured($languages_id, $type, $filename) {
|
64
|
$group_id = getCmGroupIdForType($type);
|
65
|
if($group_id === false) {
|
66
|
return false;
|
67
|
}
|
68
|
$query = "SELECT content_id FROM content_manager WHERE content_group = ".$group_id." AND languages_id = ".$languages_id." AND content_file = '".$filename."'";
|
69
|
$result = xtc_db_query($query);
|
70
|
if(xtc_db_num_rows($result) > 0) {
|
71
|
return true;
|
72
|
}
|
73
|
return false;
|
74
|
}
|
75
|
|
76
|
$supported_languages = array('de');
|
77
|
$languages_query = "SELECT languages_id, code FROM languages";
|
78
|
$languages_result = xtc_db_query($languages_query);
|
79
|
$languages = array();
|
80
|
while($lang_row = xtc_db_fetch_array($languages_result)) {
|
81
|
if(in_array($lang_row['code'], $supported_languages)) {
|
82
|
$languages[$lang_row['code']] = $lang_row['languages_id'];
|
83
|
}
|
84
|
}
|
85
|
|
86
|
$rechtstext_types = array('agb', 'impressum', 'datenschutz', 'widerruf');
|
87
|
|
88
|
$files = array();
|
89
|
|
90
|
foreach($languages as $code => $l_id) {
|
91
|
foreach($rechtstext_types as $rttype) {
|
92
|
if(!isset($files[$rtype])) {
|
93
|
$file[$rtype] = array();
|
94
|
}
|
95
|
$files[$rttype][$code] = array(
|
96
|
'txt' => 'media/content/'.$rttype.'_'.$code.'.txt',
|
97
|
'html' => 'media/content/'.$rttype.'_'.$code.'.html',
|
98
|
'pdf' => 'media/content/'.$rttype.'_'.$code.'.pdf',
|
99
|
);
|
100
|
}
|
101
|
}
|
102
|
|
103
|
if($_SERVER['REQUEST_METHOD'] == 'POST') {
|
104
|
if(isset($_POST['gen_token'])) {
|
105
|
$token = md5(uniqid().uniqid());
|
106
|
gm_set_conf('ITRECHT_TOKEN', $token);
|
107
|
$_SESSION[$messages_ns][] = '##token_generated';
|
108
|
}
|
109
|
else if(isset($_POST['use_in_cm'])) {
|
110
|
$lang_id = $languages[$_POST['lang']];
|
111
|
$content_group = getCmGroupIdForType($_POST['type']);
|
112
|
if($content_group !== false) {
|
113
|
$query = "UPDATE content_manager SET content_file = ':file' WHERE languages_id = :languages_id AND content_group = :content_group";
|
114
|
$query = strtr($query, array(':file' => xtc_db_input($_POST['file']), ':languages_id' => (int)$lang_id, ':content_group' => $content_group));
|
115
|
xtc_db_query($query);
|
116
|
$_SESSION[$messages_ns][] = '##legal_text_copied_to_content_manager';
|
117
|
}
|
118
|
else {
|
119
|
$_SESSION[$messages_ns][] = '##not_copied_to_cm_type_incompatible';
|
120
|
}
|
121
|
}
|
122
|
else {
|
123
|
// save configuration
|
124
|
/*
|
125
|
gm_set_conf('ITRECHT_API_USER', $_POST['api_username']);
|
126
|
gm_set_conf('ITRECHT_API_PASSWORD', $_POST['api_password']);
|
127
|
gm_set_conf('ITRECHT_USER', $_POST['username']);
|
128
|
gm_set_conf('ITRECHT_PASSWORD', $_POST['password']);
|
129
|
*/
|
130
|
gm_set_conf('ITRECHT_TOKEN', xtc_db_input(trim($_POST['token'])));
|
131
|
gm_set_conf('ITRECHT_USE_AGB_IN_PDF', ($_POST['use_agb_in_pdf'] == true ? '1' : '0'));
|
132
|
gm_set_conf('ITRECHT_USE_WITHDRAWAL_IN_PDF', ($_POST['use_withdrawal_in_pdf'] == true ? '1' : '0'));
|
133
|
|
134
|
if($_POST['use_agb_in_pdf'] == true && file_exists(DIR_FS_CATALOG.$files['agb']['txt'])) {
|
135
|
$conditions_txt = file_get_contents(DIR_FS_CATALOG.$files['agb']['txt']);
|
136
|
gm_set_content('GM_PDF_CONDITIONS', $conditions_txt, 2);
|
137
|
}
|
138
|
if($_POST['use_withdrawal_in_pdf'] == true && file_exists(DIR_FS_CATALOG.$files['widerrufsbelehrung']['txt'])) {
|
139
|
$withdrawal_txt = file_get_contents(DIR_FS_CATALOG.$files['widerrufsbelehrung']['txt']);
|
140
|
gm_set_content('GM_PDF_WITHDRAWAL', $withdrawal_txt, 2);
|
141
|
}
|
142
|
|
143
|
$_SESSION[$messages_ns][] = '##configuration_saved';
|
144
|
}
|
145
|
|
146
|
xtc_redirect(PAGE_URL);
|
147
|
}
|
148
|
|
149
|
$messages = $_SESSION[$messages_ns];
|
150
|
$_SESSION[$messages_ns] = array();
|
151
|
|
152
|
$data = array(
|
153
|
/*
|
154
|
'api_username' => gm_get_conf('ITRECHT_API_USER'),
|
155
|
'api_password' => gm_get_conf('ITRECHT_API_PASSWORD'),
|
156
|
'username' => gm_get_conf('ITRECHT_USER'),
|
157
|
'password' => gm_get_conf('ITRECHT_PASSWORD'),
|
158
|
*/
|
159
|
'token' => gm_get_conf('ITRECHT_TOKEN'),
|
160
|
'use_agb_in_pdf' => gm_get_conf('ITRECHT_USE_AGB_IN_PDF'),
|
161
|
'use_withdrawal_in_pdf' => gm_get_conf('ITRECHT_USE_WITHDRAWAL_IN_PDF'),
|
162
|
);
|
163
|
|
164
|
|
165
|
?>
|
166
|
<!doctype HTML>
|
167
|
<html <?php echo HTML_PARAMS; ?>>
|
168
|
<head>
|
169
|
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['language_charset']; ?>">
|
170
|
<title><?php echo TITLE; ?></title>
|
171
|
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
|
172
|
<style>
|
173
|
p.message {margin: .5ex auto; background: rgb(240, 230, 140); border: 1px solid rgb(255, 0, 0); padding: 1em; }
|
174
|
p.warning {text-align: center; font: bold 1.2em sans-serif; padding: 1em; background-color: #faa; }
|
175
|
div.green { background-color: #ADD3B5; padding: .3ex .5ex;}
|
176
|
div.red { background-color: #E2A8A7; padding: .3ex .5ex; }
|
177
|
dl.adminform {position: relative; overflow: auto; background: #eef; }
|
178
|
dl.adminform dd, dl.adminform dt {float: left; margin: 1px 0; }
|
179
|
dl.adminform dt {clear: left; width: 15em; }
|
180
|
input[type="submit"].btn_wide {width: auto; }
|
181
|
table.files {border-collapse: collapse; }
|
182
|
table.files th, table.files td {padding: .3ex .5ex; }
|
183
|
table.files thead {background: #ddd; } table.files tbody {background: #eee; }
|
184
|
|
185
|
form.bluegray {font-size: 0.9em; }
|
186
|
form.bluegray fieldset {border: none; padding: 0; margin: 1ex 0 0 0; }
|
187
|
form.bluegray legend {font-weight: bolder; font-size: 1.4em; background: #585858; color: #FFFFFF; padding: .2ex 0.5%; width: 99%; }
|
188
|
form.bluegray dl.adminform {margin: 0; }
|
189
|
form.bluegray dl.adminform dt, form.bluegray dl.adminform dd {line-height: 1.3; padding: 3px 0; margin: 0; }
|
190
|
form.bluegray dl.adminform dt {width: 20%; float: left; font-weight: bold; padding: 2px;}
|
191
|
form.bluegray dl.adminform dd {border-bottom: 1px dotted rgb(90, 90, 90); width: 78%; float: none; padding-left: 22%; background-color: #F7F7F7; min-height: 2.5em; }
|
192
|
form.bluegray dl.adminform dd:nth-child(4n) {background: #D6E6F3; }
|
193
|
</style>
|
194
|
</head>
|
195
|
<body>
|
196
|
<!-- header //-->
|
197
|
<?php require DIR_WS_INCLUDES . 'header.php'; ?>
|
198
|
<!-- header_eof //-->
|
199
|
|
200
|
<!-- body //-->
|
201
|
<table border="0" width="100%" cellspacing="2" cellpadding="2">
|
202
|
<tr>
|
203
|
<td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
|
204
|
<!-- left_navigation //-->
|
205
|
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
|
206
|
<!-- left_navigation_eof //-->
|
207
|
</td>
|
208
|
|
209
|
<!-- body_text //-->
|
210
|
|
211
|
<td class="boxCenter" width="100%" valign="top">
|
212
|
<table border="0" width="100%" cellspacing="0" cellpadding="0" class="">
|
213
|
<tr>
|
214
|
<td>
|
215
|
<table border="0" width="100%" cellspacing="0" cellpadding="0">
|
216
|
<tr>
|
217
|
<td class="pageHeading" style="padding-left: 0px">##config_heading</td>
|
218
|
<td width="80" rowspan="2"> </td>
|
219
|
</tr>
|
220
|
<tr>
|
221
|
<td class="main" valign="top"> </td>
|
222
|
</tr>
|
223
|
</table>
|
224
|
</td>
|
225
|
</tr>
|
226
|
<tr>
|
227
|
<td class="main">
|
228
|
<?php foreach($messages as $msg): ?>
|
229
|
<p class="message"><?php echo $msg ?></p>
|
230
|
<?php endforeach; ?>
|
231
|
|
232
|
<?php if(!(ini_get('allow_url_fopen') == 1)): ?>
|
233
|
<p class="warning">##ITRECHTTXT_CONFIG_WARNING_URL_FOPEN</p>
|
234
|
<?php endif ?>
|
235
|
|
236
|
<h2>##configuration</h2>
|
237
|
|
238
|
<form class="bluegray" action="<?php echo PAGE_URL ?>" method="POST">
|
239
|
<dl class="adminform">
|
240
|
<dt><label for="token">##ITRECHTTXT_CONFIG_TOKEN</label></dt>
|
241
|
<dd>
|
242
|
<input id="token" name="token" type="text" value="<?php echo $data['token'] ?>" size="40">
|
243
|
<input type="submit" value="##ITRECHTTXT_CONFIG_GENERATE_TOKEN" name="gen_token">
|
244
|
<br>
|
245
|
##your_api_url: <tt><?php echo HTTP_SERVER.DIR_WS_CATALOG.'api-it-recht-kanzlei.php'; ?></tt>
|
246
|
</dd>
|
247
|
<dt><label for="use_agb_in_pdf">##ITRECHTTXT_CONFIG_USE_AGB_IN_PDF</label></dt>
|
248
|
<dd>
|
249
|
<input id="use_agb_in_pdf" type="checkbox" value="1" name="use_agb_in_pdf" <?php echo ($data['use_agb_in_pdf'] == true) ? 'checked="checked"' : '' ?>>
|
250
|
<span class="warning">##ITRECHTTXT_PDF_CONDITIONS_WARNING</span>
|
251
|
</dd>
|
252
|
<dt><label for="use_withdrawal_in_pdf">##ITRECHTTXT_CONFIG_USE_WITHDRAWAL_IN_PDF</label></dt>
|
253
|
<dd>
|
254
|
<input id="use_withdrawal_in_pdf" type="checkbox" value="1" name="use_withdrawal_in_pdf" <?php echo ($data['use_withdrawal_in_pdf'] == true) ? 'checked="checked"' : '' ?>>
|
255
|
<span class="warning">##ITRECHTTXT_PDF_CONDITIONS_WARNING</span>
|
256
|
</dd>
|
257
|
</dl>
|
258
|
<input class="button btn_wide" type="submit" value="##ITRECHTTXT_CONFIG_SAVE">
|
259
|
</form>
|
260
|
<h2>##texts_received</h2>
|
261
|
<table class="files">
|
262
|
<thead>
|
263
|
<tr><th>##legal_text</th><th>##type_text</th><th>##type_html</th><th>##type_pdf</th><th> </th></tr>
|
264
|
</thead>
|
265
|
<tbody>
|
266
|
<?php foreach($files as $rtype => $lang): ?>
|
267
|
<?php foreach($lang as $code => $langfiles): ?>
|
268
|
<tr>
|
269
|
<td><?php echo $rtype.' ('.$code.')' ?></td>
|
270
|
<?php foreach($langfiles as $type => $file): ?>
|
271
|
<td><?php echo filelink($file); ?></td>
|
272
|
<?php endforeach ?>
|
273
|
<td>
|
274
|
<?php
|
275
|
$cmfile = $rtype.'_'.$code.'.html';
|
276
|
if(file_exists(DIR_FS_CATALOG.'media/content/'.$cmfile)):
|
277
|
?>
|
278
|
<?php if(!cmConfigured($languages[$code], $rtype, $cmfile)): ?>
|
279
|
<form action="" method="post">
|
280
|
<input type="hidden" name="lang" value="<?php echo $code ?>">
|
281
|
<input type="hidden" name="type" value="<?php echo $rtype ?>">
|
282
|
<input type="hidden" name="file" value="<?php echo $cmfile ?>">
|
283
|
<input type="submit" name="use_in_cm" value="##use_in_content_manager">
|
284
|
</form>
|
285
|
<?php else: ?>
|
286
|
<div class="green">##used_in_content_manager</div>
|
287
|
<?php endif ?>
|
288
|
<?php else: ?>
|
289
|
<div class="red">##html_file_not_available</div>
|
290
|
<?php endif ?>
|
291
|
</td>
|
292
|
</tr>
|
293
|
<?php endforeach ?>
|
294
|
<?php endforeach ?>
|
295
|
</tbody>
|
296
|
</table>
|
297
|
|
298
|
</td>
|
299
|
</tr>
|
300
|
</table>
|
301
|
</td>
|
302
|
|
303
|
<!-- body_text_eof //-->
|
304
|
|
305
|
</tr>
|
306
|
</table>
|
307
|
<!-- body_eof //-->
|
308
|
|
309
|
<!-- footer //-->
|
310
|
<?php require DIR_WS_INCLUDES . 'footer.php'; ?>
|
311
|
<!-- footer_eof //-->
|
312
|
</body>
|
313
|
</html>
|
314
|
<?php
|
315
|
echo replaceLanguagePlaceholders(ob_get_clean());
|
316
|
require DIR_WS_INCLUDES . 'application_bottom.php';
|