1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* The main FAQ class |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.3 |
6
|
|
|
* |
7
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public License, |
8
|
|
|
* v. 2.0. If a copy of the MPL was not distributed with this file, You can |
9
|
|
|
* obtain one at http://mozilla.org/MPL/2.0/. |
10
|
|
|
* |
11
|
|
|
* @category phpMyFAQ |
12
|
|
|
* @package Faq |
13
|
|
|
* @author Thorsten Rinne <[email protected]> |
14
|
|
|
* @author Matteo Scaramuccia <[email protected]> |
15
|
|
|
* @author Georgi Korchev <[email protected]> |
16
|
|
|
* @author Adrianna Musiol <[email protected]> |
17
|
|
|
* @author Peter Caesar <[email protected]> |
18
|
|
|
* @copyright 2005-2016 phpMyFAQ Team |
19
|
|
|
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
20
|
|
|
* @link http://www.phpmyfaq.de |
21
|
|
|
* @since 2005-12-20 |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
if (!defined('IS_VALID_PHPMYFAQ')) { |
25
|
|
|
exit(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* SQL constants definitions |
30
|
|
|
*/ |
31
|
|
|
define('FAQ_SQL_YES', 'y'); |
32
|
|
|
define('FAQ_SQL_NO', 'n'); |
33
|
|
|
define('FAQ_SQL_ACTIVE_YES', 'yes'); |
34
|
|
|
define('FAQ_SQL_ACTIVE_NO', 'no'); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Query type definitions |
38
|
|
|
*/ |
39
|
|
|
define('FAQ_QUERY_TYPE_DEFAULT', 'faq_default'); |
40
|
|
|
define('FAQ_QUERY_TYPE_APPROVAL', 'faq_approval'); |
41
|
|
|
define('FAQ_QUERY_TYPE_EXPORT_PDF', 'faq_export_pdf'); |
42
|
|
|
define('FAQ_QUERY_TYPE_EXPORT_XHTML', 'faq_export_xhtml'); |
43
|
|
|
define('FAQ_QUERY_TYPE_EXPORT_XML', 'faq_export_xml'); |
44
|
|
|
define('FAQ_QUERY_TYPE_RSS_LATEST', 'faq_rss_latest'); |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Sorting type definitions |
48
|
|
|
*/ |
49
|
|
|
define('FAQ_SORTING_TYPE_NONE', 0); |
50
|
|
|
define('FAQ_SORTING_TYPE_CATID_FAQID', 1); |
51
|
|
|
define('FAQ_SORTING_TYPE_FAQTITLE_FAQID', 2); |
52
|
|
|
define('FAQ_SORTING_TYPE_DATE_FAQID', 3); |
53
|
|
|
define('FAQ_SORTING_TYPE_FAQID', 4); |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Faq - 3K LOC of funny things for phpMyFAQ |
57
|
|
|
* |
58
|
|
|
* @category phpMyFAQ |
59
|
|
|
* @package Faq |
60
|
|
|
* @author Thorsten Rinne <[email protected]> |
61
|
|
|
* @author Matteo Scaramuccia <[email protected]> |
62
|
|
|
* @author Georgi Korchev <[email protected]> |
63
|
|
|
* @author Adrianna Musiol <[email protected]> |
64
|
|
|
* @author Peter Caesar <[email protected]> |
65
|
|
|
* @copyright 2005-2016 phpMyFAQ Team |
66
|
|
|
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
67
|
|
|
* @link http://www.phpmyfaq.de |
68
|
|
|
* @since 2005-12-20 |
69
|
|
|
*/ |
70
|
|
|
class PMF_Faq |
71
|
|
|
{ |
72
|
|
|
/** |
73
|
|
|
* @var PMF_Configuration |
74
|
|
|
*/ |
75
|
|
|
private $_config; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Language strings |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
private $pmf_lang; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Plural form support |
86
|
|
|
* |
87
|
|
|
* @var PMF_Language_Plurals |
88
|
|
|
*/ |
89
|
|
|
private $plr; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* The current FAQ record |
93
|
|
|
* |
94
|
|
|
* @var array |
95
|
|
|
*/ |
96
|
|
|
public $faqRecord = array(); |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* All current FAQ records in an array |
100
|
|
|
* |
101
|
|
|
* @var array |
102
|
|
|
*/ |
103
|
|
|
public $faqRecords = array(); |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Users |
107
|
|
|
* |
108
|
|
|
* @var integer |
109
|
|
|
*/ |
110
|
|
|
private $user = -1; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Groups |
114
|
|
|
* |
115
|
|
|
* @var array |
116
|
|
|
*/ |
117
|
|
|
private $groups = array(-1); |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Flag for Group support |
121
|
|
|
* |
122
|
|
|
* @var boolean |
123
|
|
|
*/ |
124
|
|
|
private $groupSupport = false; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Constructor |
128
|
|
|
* |
129
|
|
|
* @param PMF_Configuration $config |
130
|
|
|
* |
131
|
|
|
* @return PMF_Faq |
132
|
|
|
*/ |
133
|
|
|
public function __construct(PMF_Configuration $config) |
134
|
|
|
{ |
135
|
|
|
global $PMF_LANG, $plr; |
136
|
|
|
|
137
|
|
|
$this->_config = $config; |
138
|
|
|
$this->pmf_lang = $PMF_LANG; |
139
|
|
|
$this->plr = $plr; |
140
|
|
|
|
141
|
|
|
if ($this->_config->get('security.permLevel') == 'medium') { |
142
|
|
|
$this->groupSupport = true; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
// |
147
|
|
|
// |
148
|
|
|
// PUBLIC METHODS |
149
|
|
|
// |
150
|
|
|
// |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param integer $userId |
154
|
|
|
*/ |
155
|
|
|
public function setUser($userId = -1) |
156
|
|
|
{ |
157
|
|
|
$this->user = $userId; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param array $groups |
162
|
|
|
*/ |
163
|
|
|
public function setGroups(Array $groups) |
164
|
|
|
{ |
165
|
|
|
$this->groups = $groups; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* This function returns all not expired records from one category |
170
|
|
|
* |
171
|
|
|
* @param int $category_id Category ID |
172
|
|
|
* @param string $orderby Order by |
173
|
|
|
* @param string $sortby Sorty by |
174
|
|
|
* @return array |
175
|
|
|
*/ |
176
|
|
|
public function getAllRecordPerCategory($category_id, $orderby = 'id', $sortby = 'ASC') |
177
|
|
|
{ |
178
|
|
|
global $sids; |
179
|
|
|
|
180
|
|
|
$faqdata = array(); |
181
|
|
|
|
182
|
|
|
if ($orderby == 'visits') { |
183
|
|
|
$current_table = 'fv'; |
184
|
|
|
} else { |
185
|
|
|
$current_table = 'fd'; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
$now = date('YmdHis'); |
189
|
|
|
$query = sprintf(" |
190
|
|
|
SELECT |
191
|
|
|
fd.id AS id, |
192
|
|
|
fd.lang AS lang, |
193
|
|
|
fd.thema AS thema, |
194
|
|
|
fd.content AS record_content, |
195
|
|
|
fd.datum AS record_date, |
196
|
|
|
fcr.category_id AS category_id, |
197
|
|
|
fv.visits AS visits |
198
|
|
|
FROM |
199
|
|
|
%sfaqdata AS fd |
200
|
|
|
LEFT JOIN |
201
|
|
|
%sfaqcategoryrelations AS fcr |
202
|
|
|
ON |
203
|
|
|
fd.id = fcr.record_id |
204
|
|
|
AND |
205
|
|
|
fd.lang = fcr.record_lang |
206
|
|
|
LEFT JOIN |
207
|
|
|
%sfaqvisits AS fv |
208
|
|
|
ON |
209
|
|
|
fd.id = fv.id |
210
|
|
|
AND |
211
|
|
|
fv.lang = fd.lang |
212
|
|
|
LEFT JOIN |
213
|
|
|
%sfaqdata_group AS fdg |
214
|
|
|
ON |
215
|
|
|
fd.id = fdg.record_id |
216
|
|
|
LEFT JOIN |
217
|
|
|
%sfaqdata_user AS fdu |
218
|
|
|
ON |
219
|
|
|
fd.id = fdu.record_id |
220
|
|
|
WHERE |
221
|
|
|
fd.date_start <= '%s' |
222
|
|
|
AND |
223
|
|
|
fd.date_end >= '%s' |
224
|
|
|
AND |
225
|
|
|
fd.active = 'yes' |
226
|
|
|
AND |
227
|
|
|
fcr.category_id = %d |
228
|
|
|
AND |
229
|
|
|
fd.lang = '%s' |
230
|
|
|
%s |
231
|
|
|
ORDER BY |
232
|
|
|
%s.%s %s", |
233
|
|
|
PMF_Db::getTablePrefix(), |
234
|
|
|
PMF_Db::getTablePrefix(), |
235
|
|
|
PMF_Db::getTablePrefix(), |
236
|
|
|
PMF_Db::getTablePrefix(), |
237
|
|
|
PMF_Db::getTablePrefix(), |
238
|
|
|
$now, |
239
|
|
|
$now, |
240
|
|
|
$category_id, |
241
|
|
|
$this->_config->getLanguage()->getLanguage(), |
242
|
|
|
$this->queryPermission($this->groupSupport), |
243
|
|
|
$current_table, |
244
|
|
|
$this->_config->getDb()->escape($orderby), |
245
|
|
|
$this->_config->getDb()->escape($sortby)); |
246
|
|
|
|
247
|
|
|
$result = $this->_config->getDb()->query($query); |
248
|
|
|
$num = $this->_config->getDb()->numRows($result); |
249
|
|
|
|
250
|
|
|
if ($num > 0) { |
251
|
|
|
while (($row = $this->_config->getDb()->fetchObject($result))) { |
252
|
|
|
|
253
|
|
|
if (empty($row->visits)) { |
254
|
|
|
$visits = 0; |
255
|
|
|
} else { |
256
|
|
|
$visits = $row->visits; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
$url = sprintf( |
260
|
|
|
'%s?%saction=artikel&cat=%d&id=%d&artlang=%s', |
261
|
|
|
PMF_Link::getSystemRelativeUri(), |
262
|
|
|
$sids, |
263
|
|
|
$row->category_id, |
264
|
|
|
$row->id, |
265
|
|
|
$row->lang |
266
|
|
|
); |
267
|
|
|
$oLink = new PMF_Link($url, $this->_config); |
268
|
|
|
$oLink->itemTitle = $oLink->text = $oLink->tooltip = $row->thema;; |
269
|
|
|
|
270
|
|
|
$faqdata[] = array( |
271
|
|
|
'record_id' => $row->id, |
272
|
|
|
'record_lang' => $row->lang, |
273
|
|
|
'category_id' => $row->category_id, |
274
|
|
|
'record_title' => $row->thema, |
275
|
|
|
'record_preview' => PMF_Utils::chopString(strip_tags($row->record_content), 25), |
276
|
|
|
'record_link' => $oLink->toString(), |
277
|
|
|
'record_date' => $row->record_date, |
278
|
|
|
'visits' => $visits |
279
|
|
|
); |
280
|
|
|
} |
281
|
|
|
} else { |
282
|
|
|
return $faqdata; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
return $faqdata; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* This function returns all not expired records from one category |
290
|
|
|
* |
291
|
|
|
* @param integer $categoryId Category ID |
292
|
|
|
* @param string $orderby Order by |
293
|
|
|
* @param string $sortby Sorty by |
294
|
|
|
* |
295
|
|
|
* @return string |
296
|
|
|
*/ |
297
|
|
|
public function showAllRecords($categoryId, $orderby = 'id', $sortby = 'ASC') |
298
|
|
|
{ |
299
|
|
|
global $sids; |
300
|
|
|
|
301
|
|
|
$numPerPage = $this->_config->get('records.numberOfRecordsPerPage'); |
302
|
|
|
$page = PMF_Filter::filterInput(INPUT_GET, 'seite', FILTER_VALIDATE_INT, 1); |
303
|
|
|
$output = ''; |
304
|
|
|
$title = ''; |
305
|
|
|
|
306
|
|
|
if ($orderby == 'visits') { |
307
|
|
|
$currentTable = 'fv'; |
308
|
|
|
} else { |
309
|
|
|
$currentTable = 'fd'; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
// If random FAQs are activated, we don't need an order |
313
|
|
|
if (true === $this->_config->get('records.randomSort')) { |
314
|
|
|
$order = ''; |
315
|
|
|
} else { |
316
|
|
|
$order = sprintf( |
317
|
|
|
"ORDER BY fd.sticky DESC, %s.%s %s", |
318
|
|
|
$currentTable, |
319
|
|
|
$this->_config->getDb()->escape($orderby), |
320
|
|
|
$this->_config->getDb()->escape($sortby) |
321
|
|
|
); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
$now = date('YmdHis'); |
325
|
|
|
$query = sprintf(" |
326
|
|
|
SELECT |
327
|
|
|
fd.id AS id, |
328
|
|
|
fd.lang AS lang, |
329
|
|
|
fd.sticky AS sticky, |
330
|
|
|
fd.thema AS thema, |
331
|
|
|
fcr.category_id AS category_id, |
332
|
|
|
fv.visits AS visits |
333
|
|
|
FROM |
334
|
|
|
%sfaqdata AS fd |
335
|
|
|
LEFT JOIN |
336
|
|
|
%sfaqcategoryrelations AS fcr |
337
|
|
|
ON |
338
|
|
|
fd.id = fcr.record_id |
339
|
|
|
AND |
340
|
|
|
fd.lang = fcr.record_lang |
341
|
|
|
LEFT JOIN |
342
|
|
|
%sfaqvisits AS fv |
343
|
|
|
ON |
344
|
|
|
fd.id = fv.id |
345
|
|
|
AND |
346
|
|
|
fv.lang = fd.lang |
347
|
|
|
LEFT JOIN |
348
|
|
|
%sfaqdata_group AS fdg |
349
|
|
|
ON |
350
|
|
|
fd.id = fdg.record_id |
351
|
|
|
LEFT JOIN |
352
|
|
|
%sfaqdata_user AS fdu |
353
|
|
|
ON |
354
|
|
|
fd.id = fdu.record_id |
355
|
|
|
WHERE |
356
|
|
|
fd.date_start <= '%s' |
357
|
|
|
AND |
358
|
|
|
fd.date_end >= '%s' |
359
|
|
|
AND |
360
|
|
|
fd.active = 'yes' |
361
|
|
|
AND |
362
|
|
|
fcr.category_id = %d |
363
|
|
|
AND |
364
|
|
|
fd.lang = '%s' |
365
|
|
|
%s |
366
|
|
|
%s", |
367
|
|
|
PMF_Db::getTablePrefix(), |
368
|
|
|
PMF_Db::getTablePrefix(), |
369
|
|
|
PMF_Db::getTablePrefix(), |
370
|
|
|
PMF_Db::getTablePrefix(), |
371
|
|
|
PMF_Db::getTablePrefix(), |
372
|
|
|
$now, |
373
|
|
|
$now, |
374
|
|
|
$categoryId, |
375
|
|
|
$this->_config->getLanguage()->getLanguage(), |
376
|
|
|
$this->queryPermission($this->groupSupport), |
377
|
|
|
$order |
378
|
|
|
); |
379
|
|
|
|
380
|
|
|
$result = $this->_config->getDb()->query($query); |
381
|
|
|
$num = $this->_config->getDb()->numRows($result); |
382
|
|
|
$pages = (int)ceil($num / $numPerPage); |
383
|
|
|
|
384
|
|
|
if ($page == 1) { |
385
|
|
|
$first = 0; |
386
|
|
|
} else { |
387
|
|
|
$first = $page * $numPerPage - $numPerPage; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
if ($num > 0) { |
391
|
|
View Code Duplication |
if ($pages > 1) { |
392
|
|
|
$output .= sprintf('<p><strong>%s %s %s</strong></p>', |
393
|
|
|
$this->pmf_lang['msgPage'] . $page, |
394
|
|
|
$this->pmf_lang['msgVoteFrom'], |
395
|
|
|
$pages . $this->pmf_lang['msgPages']); |
396
|
|
|
} |
397
|
|
|
$output .= '<ul class="phpmyfaq_ul">'; |
398
|
|
|
|
399
|
|
|
$counter = 0; |
400
|
|
|
$displayedCounter = 0; |
401
|
|
|
$renderedItems = array(); |
402
|
|
|
while (($row = $this->_config->getDb()->fetchObject($result)) && $displayedCounter < $numPerPage) { |
403
|
|
|
$counter ++; |
404
|
|
|
if ($counter <= $first) { |
405
|
|
|
continue; |
406
|
|
|
} |
407
|
|
|
$displayedCounter++; |
408
|
|
|
|
409
|
|
|
if (empty($row->visits)) { |
410
|
|
|
$visits = 0; |
411
|
|
|
} else { |
412
|
|
|
$visits = $row->visits; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
$title = $row->thema; |
416
|
|
|
$url = sprintf( |
417
|
|
|
'%s?%saction=artikel&cat=%d&id=%d&artlang=%s', |
418
|
|
|
PMF_Link::getSystemRelativeUri(), |
419
|
|
|
$sids, |
420
|
|
|
$row->category_id, |
421
|
|
|
$row->id, |
422
|
|
|
$row->lang |
423
|
|
|
); |
424
|
|
|
|
425
|
|
|
$oLink = new PMF_Link($url, $this->_config); |
426
|
|
|
$oLink->itemTitle = $oLink->text = $oLink->tooltip = $title; |
427
|
|
|
|
428
|
|
|
// If random FAQs are activated, we don't need sticky FAQs |
429
|
|
|
if (true === $this->_config->get('records.randomSort')) { |
430
|
|
|
$row->sticky = 0; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
$renderedItems[$row->id] = sprintf( |
434
|
|
|
'<li%s>%s<span id="viewsPerRecord"><br /><small>(%s)</small></span></li>', |
435
|
|
|
($row->sticky == 1) ? ' class="sticky-faqs"' : '', |
436
|
|
|
$oLink->toHtmlAnchor(), |
437
|
|
|
$this->plr->GetMsg('plmsgViews', $visits) |
438
|
|
|
); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
// If random FAQs are activated, shuffle the FAQs :-) |
442
|
|
|
if (true === $this->_config->get('records.randomSort')) { |
443
|
|
|
shuffle($renderedItems); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
$output .= implode("\n", $renderedItems); |
447
|
|
|
$output .= '</ul><span class="totalFaqRecords hide">'.$num.'</span>'; |
448
|
|
|
} else { |
449
|
|
|
return false; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
if ($pages > 1) { |
453
|
|
|
// Set rewrite URL, if needed |
454
|
|
|
if ($this->_config->get('main.enableRewriteRules')) { |
455
|
|
|
$link = new PMF_Link(PMF_Link::getSystemRelativeUri('index.php'), $this->_config); |
456
|
|
|
$useRewrite = true; |
457
|
|
|
$rewriteUrl = sprintf( |
458
|
|
|
"%scategory/%d/%%d/%s.html", |
459
|
|
|
PMF_Link::getSystemRelativeUri('index.php'), |
460
|
|
|
$categoryId, |
461
|
|
|
$link->getSEOItemTitle($title) |
462
|
|
|
); |
463
|
|
|
} else { |
464
|
|
|
$useRewrite = false; |
465
|
|
|
$rewriteUrl = ''; |
466
|
|
|
} |
467
|
|
|
$baseUrl = sprintf( |
468
|
|
|
"%s?%saction=show&cat=%d&seite=%d", |
469
|
|
|
PMF_Link::getSystemRelativeUri(), |
470
|
|
|
(empty($sids) ? '' : $sids), |
471
|
|
|
$categoryId, |
472
|
|
|
$page |
473
|
|
|
); |
474
|
|
|
|
475
|
|
|
$options = array( |
476
|
|
|
'baseUrl' => $baseUrl, |
477
|
|
|
'total' => $num, |
478
|
|
|
'perPage' => $this->_config->get('records.numberOfRecordsPerPage'), |
479
|
|
|
'useRewrite' => $useRewrite, |
480
|
|
|
'rewriteUrl' => $rewriteUrl, |
481
|
|
|
'pageParamName' => 'seite' |
482
|
|
|
); |
483
|
|
|
|
484
|
|
|
$pagination = new PMF_Pagination($this->_config, $options); |
485
|
|
|
$output .= $pagination->render(); |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
return $output; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* This function returns all not expired records from the given record ids |
493
|
|
|
* |
494
|
|
|
* @param array $record_ids Array of record ids |
495
|
|
|
* @param string $orderby Order by |
496
|
|
|
* @param string $sortby Sort by |
497
|
|
|
* @return string |
498
|
|
|
*/ |
499
|
|
|
public function showAllRecordsByIds(Array $record_ids, $orderby = 'fd.id', $sortby = 'ASC') |
500
|
|
|
{ |
501
|
|
|
global $sids; |
502
|
|
|
|
503
|
|
|
$records = implode(', ', $record_ids); |
504
|
|
|
$page = PMF_Filter::filterInput(INPUT_GET, 'seite', FILTER_VALIDATE_INT, 1); |
505
|
|
|
$tagging_id = PMF_Filter::filterInput(INPUT_GET, 'tagging_id', FILTER_VALIDATE_INT); |
506
|
|
|
$output = ''; |
507
|
|
|
|
508
|
|
|
$now = date('YmdHis'); |
509
|
|
|
$query = sprintf(" |
510
|
|
|
SELECT |
511
|
|
|
fd.id AS id, |
512
|
|
|
fd.lang AS lang, |
513
|
|
|
fd.thema AS thema, |
514
|
|
|
fcr.category_id AS category_id, |
515
|
|
|
fv.visits AS visits |
516
|
|
|
FROM |
517
|
|
|
%sfaqdata AS fd |
518
|
|
|
LEFT JOIN |
519
|
|
|
%sfaqcategoryrelations AS fcr |
520
|
|
|
ON |
521
|
|
|
fd.id = fcr.record_id |
522
|
|
|
AND |
523
|
|
|
fd.lang = fcr.record_lang |
524
|
|
|
LEFT JOIN |
525
|
|
|
%sfaqvisits AS fv |
526
|
|
|
ON |
527
|
|
|
fd.id = fv.id |
528
|
|
|
AND |
529
|
|
|
fv.lang = fd.lang |
530
|
|
|
LEFT JOIN |
531
|
|
|
%sfaqdata_group AS fdg |
532
|
|
|
ON |
533
|
|
|
fd.id = fdg.record_id |
534
|
|
|
LEFT JOIN |
535
|
|
|
%sfaqdata_user AS fdu |
536
|
|
|
ON |
537
|
|
|
fd.id = fdu.record_id |
538
|
|
|
WHERE |
539
|
|
|
fd.date_start <= '%s' |
540
|
|
|
AND |
541
|
|
|
fd.date_end >= '%s' |
542
|
|
|
AND |
543
|
|
|
fd.active = 'yes' |
544
|
|
|
AND |
545
|
|
|
fd.id IN (%s) |
546
|
|
|
AND |
547
|
|
|
fd.lang = '%s' |
548
|
|
|
%s |
549
|
|
|
ORDER BY |
550
|
|
|
%s %s", |
551
|
|
|
PMF_Db::getTablePrefix(), |
552
|
|
|
PMF_Db::getTablePrefix(), |
553
|
|
|
PMF_Db::getTablePrefix(), |
554
|
|
|
PMF_Db::getTablePrefix(), |
555
|
|
|
PMF_Db::getTablePrefix(), |
556
|
|
|
$now, |
557
|
|
|
$now, |
558
|
|
|
$records, |
559
|
|
|
$this->_config->getLanguage()->getLanguage(), |
560
|
|
|
$this->queryPermission($this->groupSupport), |
561
|
|
|
$this->_config->getDb()->escape($orderby), |
562
|
|
|
$this->_config->getDb()->escape($sortby)); |
563
|
|
|
|
564
|
|
|
$result = $this->_config->getDb()->query($query); |
565
|
|
|
|
566
|
|
|
$num = $this->_config->getDb()->numRows($result); |
567
|
|
|
$pages = ceil($num / $this->_config->get('records.numberOfRecordsPerPage')); |
568
|
|
|
|
569
|
|
|
if ($page == 1) { |
570
|
|
|
$first = 0; |
571
|
|
|
} else { |
572
|
|
|
$first = ($page * $this->_config->get('records.numberOfRecordsPerPage')) - $this->_config->get('records.numberOfRecordsPerPage'); |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
if ($num > 0) { |
576
|
|
View Code Duplication |
if ($pages > 1) { |
577
|
|
|
$output .= sprintf('<p><strong>%s %s %s</strong></p>', |
578
|
|
|
$this->pmf_lang['msgPage'] . $page, |
579
|
|
|
$this->pmf_lang['msgVoteFrom'], |
580
|
|
|
$pages . $this->pmf_lang['msgPages']); |
581
|
|
|
} |
582
|
|
|
$output .= '<ul class="phpmyfaq_ul">'; |
583
|
|
|
$counter = 0; |
584
|
|
|
$displayedCounter = 0; |
585
|
|
|
|
586
|
|
|
$lastFaqId = 0; |
587
|
|
|
while (($row = $this->_config->getDb()->fetchObject($result)) && $displayedCounter < $this->_config->get('records.numberOfRecordsPerPage')) { |
588
|
|
|
$counter ++; |
589
|
|
|
if ($counter <= $first) { |
590
|
|
|
continue; |
591
|
|
|
} |
592
|
|
|
$displayedCounter++; |
593
|
|
|
|
594
|
|
|
if ($lastFaqId == $row->id) { |
595
|
|
|
continue; // Don't show multiple FAQs |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
if (empty($row->visits)) { |
599
|
|
|
$visits = 0; |
600
|
|
|
} else { |
601
|
|
|
$visits = $row->visits; |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
$title = $row->thema; |
605
|
|
|
$url = sprintf( |
606
|
|
|
'%s?%saction=artikel&cat=%d&id=%d&artlang=%s', |
607
|
|
|
PMF_Link::getSystemRelativeUri(), |
608
|
|
|
$sids, |
609
|
|
|
$row->category_id, |
610
|
|
|
$row->id, |
611
|
|
|
$row->lang |
612
|
|
|
); |
613
|
|
|
$oLink = new PMF_Link($url, $this->_config); |
614
|
|
|
$oLink->itemTitle = $row->thema; |
615
|
|
|
$oLink->text = $title; |
616
|
|
|
$oLink->tooltip = $title; |
617
|
|
|
$listItem = sprintf( |
618
|
|
|
'<li>%s<br /><small>(%s)</small></li>', |
619
|
|
|
$oLink->toHtmlAnchor(), |
620
|
|
|
$this->plr->GetMsg('plmsgViews',$visits) |
621
|
|
|
); |
622
|
|
|
|
623
|
|
|
$output .= $listItem; |
624
|
|
|
|
625
|
|
|
$lastFaqId = $row->id; |
626
|
|
|
} |
627
|
|
|
$output .= '</ul><span id="totFaqRecords" style="display: none;">'.$num.'</span>'; |
628
|
|
|
} else { |
629
|
|
|
return false; |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
if ($num > $this->_config->get('records.numberOfRecordsPerPage')) { |
633
|
|
|
$output .= "<p class=\"text-center\"><strong>"; |
634
|
|
|
if (!isset($page)) { |
635
|
|
|
$page = 1; |
636
|
|
|
} |
637
|
|
|
$vor = $page - 1; |
638
|
|
|
$next = $page + 1; |
639
|
|
View Code Duplication |
if ($vor != 0) { |
640
|
|
|
$url = $sids.'&action=search&tagging_id='.$tagging_id.'&seite='.$vor; |
641
|
|
|
$oLink = new PMF_Link(PMF_Link::getSystemRelativeUri().'?'.$url, $this->_config); |
642
|
|
|
$oLink->itemTitle = 'tag'; |
643
|
|
|
$oLink->text = $this->pmf_lang["msgPrevious"]; |
644
|
|
|
$oLink->tooltip = $this->pmf_lang["msgPrevious"]; |
645
|
|
|
$output .= '[ '.$oLink->toHtmlAnchor().' ]'; |
646
|
|
|
} |
647
|
|
|
$output .= " "; |
648
|
|
View Code Duplication |
if ($next <= $pages) { |
649
|
|
|
$url = $sids.'&action=search&tagging_id='.$tagging_id.'&seite='.$next; |
650
|
|
|
$oLink = new PMF_Link(PMF_Link::getSystemRelativeUri().'?'.$url, $this->_config); |
651
|
|
|
$oLink->itemTitle = 'tag'; |
652
|
|
|
$oLink->text = $this->pmf_lang["msgNext"]; |
653
|
|
|
$oLink->tooltip = $this->pmf_lang["msgNext"]; |
654
|
|
|
$output .= '[ '.$oLink->toHtmlAnchor().' ]'; |
655
|
|
|
} |
656
|
|
|
$output .= "</strong></p>"; |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
return $output; |
660
|
|
|
} |
661
|
|
|
|
662
|
|
|
/** |
663
|
|
|
* Returns an array with all data from a FAQ record |
664
|
|
|
* |
665
|
|
|
* @param integer $id Record id |
666
|
|
|
* @param integer $revisionId Revision id |
667
|
|
|
* @param boolean $isAdmin Must be true if it is called by an admin/author context |
668
|
|
|
* |
669
|
|
|
* @return void |
670
|
|
|
*/ |
671
|
|
|
public function getRecord($id, $revisionId = null, $isAdmin = false) |
672
|
|
|
{ |
673
|
|
|
global $PMF_LANG; |
674
|
|
|
|
675
|
|
|
$query = sprintf( |
676
|
|
|
"SELECT |
677
|
|
|
id, lang, solution_id, revision_id, active, sticky, keywords, |
678
|
|
|
thema, content, author, email, comment, datum, links_state, |
679
|
|
|
links_check_date, date_start, date_end |
680
|
|
|
FROM |
681
|
|
|
%s%s fd |
682
|
|
|
LEFT JOIN |
683
|
|
|
%sfaqdata_group fdg |
684
|
|
|
ON |
685
|
|
|
fd.id = fdg.record_id |
686
|
|
|
LEFT JOIN |
687
|
|
|
%sfaqdata_user fdu |
688
|
|
|
ON |
689
|
|
|
fd.id = fdu.record_id |
690
|
|
|
WHERE |
691
|
|
|
fd.id = %d |
692
|
|
|
%s |
693
|
|
|
AND |
694
|
|
|
fd.lang = '%s' |
695
|
|
|
%s", |
696
|
|
|
PMF_Db::getTablePrefix(), |
697
|
|
|
isset($revisionId) ? 'faqdata_revisions': 'faqdata', |
698
|
|
|
PMF_Db::getTablePrefix(), |
699
|
|
|
PMF_Db::getTablePrefix(), |
700
|
|
|
$id, |
701
|
|
|
isset($revisionId) ? 'AND revision_id = '.$revisionId : '', |
702
|
|
|
$this->_config->getLanguage()->getLanguage(), |
703
|
|
|
($isAdmin) ? 'AND 1=1' : $this->queryPermission($this->groupSupport) |
704
|
|
|
); |
705
|
|
|
|
706
|
|
|
$result = $this->_config->getDb()->query($query); |
707
|
|
|
|
708
|
|
|
if ($row = $this->_config->getDb()->fetchObject($result)) { |
709
|
|
|
|
710
|
|
|
$question = nl2br($row->thema); |
711
|
|
|
$content = $row->content; |
712
|
|
|
$active = ('yes' == $row->active); |
713
|
|
|
$expired = (date('YmdHis') > $row->date_end); |
714
|
|
|
|
715
|
|
|
if (!$isAdmin) { |
716
|
|
|
if (!$active) { |
717
|
|
|
$content = $this->pmf_lang['err_inactiveArticle']; |
718
|
|
|
} |
719
|
|
|
if ($expired) { |
720
|
|
|
$content = $this->pmf_lang['err_expiredArticle']; |
721
|
|
|
} |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
$this->faqRecord = array( |
725
|
|
|
'id' => $row->id, |
726
|
|
|
'lang' => $row->lang, |
727
|
|
|
'solution_id' => $row->solution_id, |
728
|
|
|
'revision_id' => $row->revision_id, |
729
|
|
|
'active' => $row->active, |
730
|
|
|
'sticky' => $row->sticky, |
731
|
|
|
'keywords' => $row->keywords, |
732
|
|
|
'title' => $question, |
733
|
|
|
'content' => $content, |
734
|
|
|
'author' => $row->author, |
735
|
|
|
'email' => $row->email, |
736
|
|
|
'comment' => $row->comment, |
737
|
|
|
'date' => PMF_Date::createIsoDate($row->datum), |
738
|
|
|
'dateStart' => $row->date_start, |
739
|
|
|
'dateEnd' => $row->date_end, |
740
|
|
|
'linkState' => $row->links_state, |
741
|
|
|
'linkCheckDate' => $row->links_check_date |
742
|
|
|
); |
743
|
|
|
} else { |
744
|
|
|
$this->faqRecord = array( |
745
|
|
|
'id' => $id, |
746
|
|
|
'lang' => $this->_config->getLanguage()->getLanguage(), |
747
|
|
|
'solution_id' => 42, |
748
|
|
|
'revision_id' => 0, |
749
|
|
|
'active' => 'no', |
750
|
|
|
'sticky' => 0, |
751
|
|
|
'keywords' => '', |
752
|
|
|
'title' => '', |
753
|
|
|
'content' => $PMF_LANG['msgAccessDenied'], |
754
|
|
|
'author' => '', |
755
|
|
|
'email' => '', |
756
|
|
|
'comment' => '', |
757
|
|
|
'date' => PMF_Date::createIsoDate(date('YmdHis')), |
758
|
|
|
'dateStart' => '', |
759
|
|
|
'dateEnd' => '', |
760
|
|
|
'linkState' => '', |
761
|
|
|
'linkCheckDate' => '' |
762
|
|
|
); |
763
|
|
|
} |
764
|
|
|
} |
765
|
|
|
|
766
|
|
|
/** |
767
|
|
|
* Adds a new record |
768
|
|
|
* |
769
|
|
|
* @param array $data Array of FAQ data |
770
|
|
|
* @param boolean $new_record New record? |
771
|
|
|
* @return integer |
772
|
|
|
*/ |
773
|
|
|
public function addRecord(Array $data, $new_record = true) |
774
|
|
|
{ |
775
|
|
|
if ($new_record) { |
776
|
|
|
$record_id = $this->_config->getDb()->nextId(PMF_Db::getTablePrefix().'faqdata', 'id'); |
777
|
|
|
} else { |
778
|
|
|
$record_id = $data['id']; |
779
|
|
|
} |
780
|
|
|
|
781
|
|
|
// Add new entry |
782
|
|
|
$query = sprintf( |
783
|
|
|
"INSERT INTO |
784
|
|
|
%sfaqdata |
785
|
|
|
VALUES |
786
|
|
|
(%d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s')", |
787
|
|
|
PMF_Db::getTablePrefix(), |
788
|
|
|
$record_id, |
789
|
|
|
$data['lang'], |
790
|
|
|
$this->getSolutionId(), |
791
|
|
|
0, |
792
|
|
|
$data['active'], |
793
|
|
|
$data['sticky'], |
794
|
|
|
$this->_config->getDb()->escape($data['keywords']), |
795
|
|
|
$this->_config->getDb()->escape($data['thema']), |
796
|
|
|
$this->_config->getDb()->escape($data['content']), |
797
|
|
|
$this->_config->getDb()->escape($data['author']), |
798
|
|
|
$data['email'], |
799
|
|
|
$data['comment'], |
800
|
|
|
$data['date'], |
801
|
|
|
$data['linkState'], |
802
|
|
|
$data['linkDateCheck'], |
803
|
|
|
$data['dateStart'], |
804
|
|
|
$data['dateEnd']); |
805
|
|
|
|
806
|
|
|
$this->_config->getDb()->query($query); |
807
|
|
|
return $record_id; |
808
|
|
|
} |
809
|
|
|
|
810
|
|
|
/** |
811
|
|
|
* Updates a record |
812
|
|
|
* |
813
|
|
|
* @param array $data Array of FAQ data |
814
|
|
|
* @return boolean |
815
|
|
|
*/ |
816
|
|
|
public function updateRecord(Array $data) |
817
|
|
|
{ |
818
|
|
|
// Update entry |
819
|
|
|
$query = sprintf(" |
820
|
|
|
UPDATE |
821
|
|
|
%sfaqdata |
822
|
|
|
SET |
823
|
|
|
revision_id = %d, |
824
|
|
|
active = '%s', |
825
|
|
|
sticky = %d, |
826
|
|
|
keywords = '%s', |
827
|
|
|
thema = '%s', |
828
|
|
|
content = '%s', |
829
|
|
|
author = '%s', |
830
|
|
|
email = '%s', |
831
|
|
|
comment = '%s', |
832
|
|
|
datum = '%s', |
833
|
|
|
links_state = '%s', |
834
|
|
|
links_check_date = %d, |
835
|
|
|
date_start = '%s', |
836
|
|
|
date_end = '%s' |
837
|
|
|
WHERE |
838
|
|
|
id = %d |
839
|
|
|
AND |
840
|
|
|
lang = '%s'", |
841
|
|
|
PMF_Db::getTablePrefix(), |
842
|
|
|
$data['revision_id'], |
843
|
|
|
$data['active'], |
844
|
|
|
$data['sticky'], |
845
|
|
|
$this->_config->getDb()->escape($data['keywords']), |
846
|
|
|
$this->_config->getDb()->escape($data['thema']), |
847
|
|
|
$this->_config->getDb()->escape($data['content']), |
848
|
|
|
$this->_config->getDb()->escape($data['author']), |
849
|
|
|
$data['email'], |
850
|
|
|
$data['comment'], |
851
|
|
|
$data['date'], |
852
|
|
|
$data['linkState'], |
853
|
|
|
$data['linkDateCheck'], |
854
|
|
|
$data['dateStart'], |
855
|
|
|
$data['dateEnd'], |
856
|
|
|
$data['id'], |
857
|
|
|
$data['lang']); |
858
|
|
|
|
859
|
|
|
$this->_config->getDb()->query($query); |
860
|
|
|
return true; |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
/** |
864
|
|
|
* Deletes a record and all the dependencies |
865
|
|
|
* |
866
|
|
|
* @param integer $recordId Record id |
867
|
|
|
* @param string $recordLang Record language |
868
|
|
|
* |
869
|
|
|
* @return boolean |
870
|
|
|
*/ |
871
|
|
|
public function deleteRecord($recordId, $recordLang) |
872
|
|
|
{ |
873
|
|
|
$queries = array( |
874
|
|
|
sprintf( |
875
|
|
|
"DELETE FROM %sfaqchanges WHERE beitrag = %d AND lang = '%s'", |
876
|
|
|
PMF_Db::getTablePrefix(), |
877
|
|
|
$recordId, |
878
|
|
|
$recordLang |
879
|
|
|
), |
880
|
|
|
sprintf( |
881
|
|
|
"DELETE FROM %sfaqcategoryrelations WHERE record_id = %d AND record_lang = '%s'", |
882
|
|
|
PMF_Db::getTablePrefix(), |
883
|
|
|
$recordId, |
884
|
|
|
$recordLang |
885
|
|
|
), |
886
|
|
|
sprintf( |
887
|
|
|
"DELETE FROM %sfaqdata WHERE id = %d AND lang = '%s'", |
888
|
|
|
PMF_Db::getTablePrefix(), |
889
|
|
|
$recordId, |
890
|
|
|
$recordLang |
891
|
|
|
), |
892
|
|
|
sprintf( |
893
|
|
|
"DELETE FROM %sfaqdata_revisions WHERE id = %d AND lang = '%s'", |
894
|
|
|
PMF_Db::getTablePrefix(), |
895
|
|
|
$recordId, |
896
|
|
|
$recordLang |
897
|
|
|
), |
898
|
|
|
sprintf( |
899
|
|
|
"DELETE FROM %sfaqvisits WHERE id = %d AND lang = '%s'", |
900
|
|
|
PMF_Db::getTablePrefix(), |
901
|
|
|
$recordId, |
902
|
|
|
$recordLang |
903
|
|
|
), |
904
|
|
|
sprintf( |
905
|
|
|
"DELETE FROM %sfaqdata_user WHERE record_id = %d", |
906
|
|
|
PMF_Db::getTablePrefix(), |
907
|
|
|
$recordId, |
908
|
|
|
$recordLang |
909
|
|
|
), |
910
|
|
|
sprintf( |
911
|
|
|
"DELETE FROM %sfaqdata_group WHERE record_id = %d", |
912
|
|
|
PMF_Db::getTablePrefix(), |
913
|
|
|
$recordId, |
914
|
|
|
$recordLang |
915
|
|
|
), |
916
|
|
|
sprintf( |
917
|
|
|
"DELETE FROM %sfaqdata_tags WHERE record_id = %d", |
918
|
|
|
PMF_Db::getTablePrefix(), |
919
|
|
|
$recordId |
920
|
|
|
), |
921
|
|
|
sprintf( |
922
|
|
|
'DELETE FROM %sfaqdata_tags WHERE %sfaqdata_tags.record_id NOT IN (SELECT %sfaqdata.id FROM %sfaqdata)', |
923
|
|
|
PMF_Db::getTablePrefix(), |
924
|
|
|
PMF_Db::getTablePrefix(), |
925
|
|
|
PMF_Db::getTablePrefix(), |
926
|
|
|
PMF_Db::getTablePrefix() |
927
|
|
|
), |
928
|
|
|
sprintf( |
929
|
|
|
"DELETE FROM %sfaqcomments WHERE id = %d", |
930
|
|
|
PMF_Db::getTablePrefix(), |
931
|
|
|
$recordId |
932
|
|
|
), |
933
|
|
|
sprintf( |
934
|
|
|
"DELETE FROM %sfaqvoting WHERE artikel = %d", |
935
|
|
|
PMF_Db::getTablePrefix(), |
936
|
|
|
$recordId |
937
|
|
|
) |
938
|
|
|
); |
939
|
|
|
|
940
|
|
|
foreach ($queries as $query) { |
941
|
|
|
$this->_config->getDb()->query($query); |
942
|
|
|
} |
943
|
|
|
|
944
|
|
|
// Delete possible attachments |
945
|
|
|
$attId = PMF_Attachment_Factory::fetchByRecordId($this->_config, $recordId); |
946
|
|
|
$attachment = PMF_Attachment_Factory::create($attId); |
947
|
|
|
$attachment->delete(); |
948
|
|
|
|
949
|
|
|
return true; |
950
|
|
|
} |
951
|
|
|
|
952
|
|
|
/** |
953
|
|
|
* Checks if a record is already translated |
954
|
|
|
* |
955
|
|
|
* @param integer $record_id Record id |
956
|
|
|
* @param string $record_lang Record language |
957
|
|
|
* @return boolean |
958
|
|
|
*/ |
959
|
|
|
public function isAlreadyTranslated($record_id, $record_lang) |
960
|
|
|
{ |
961
|
|
|
$query = sprintf(" |
962
|
|
|
SELECT |
963
|
|
|
id, lang |
964
|
|
|
FROM |
965
|
|
|
%sfaqdata |
966
|
|
|
WHERE |
967
|
|
|
id = %d |
968
|
|
|
AND |
969
|
|
|
lang = '%s'", |
970
|
|
|
PMF_Db::getTablePrefix(), |
971
|
|
|
$record_id, |
972
|
|
|
$record_lang); |
973
|
|
|
|
974
|
|
|
$result = $this->_config->getDb()->query($query); |
975
|
|
|
|
976
|
|
|
if ($this->_config->getDb()->numRows($result)) { |
977
|
|
|
return true; |
978
|
|
|
} |
979
|
|
|
|
980
|
|
|
return false; |
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
/** |
984
|
|
|
* Checks, if comments are disabled for the FAQ record |
985
|
|
|
* |
986
|
|
|
* @param integer $record_id Id of FAQ or news entry |
987
|
|
|
* @param string $record_lang Language |
988
|
|
|
* @param string $record_type Type of comment: faq or news |
989
|
|
|
* @return boolean true, if comments are disabled |
990
|
|
|
*/ |
991
|
|
|
public function commentDisabled($record_id, $record_lang, $record_type = 'faq') |
992
|
|
|
{ |
993
|
|
|
if ('news' == $record_type) { |
994
|
|
|
$table = 'faqnews'; |
995
|
|
|
} else { |
996
|
|
|
$table = 'faqdata'; |
997
|
|
|
} |
998
|
|
|
|
999
|
|
|
$query = sprintf(" |
1000
|
|
|
SELECT |
1001
|
|
|
comment |
1002
|
|
|
FROM |
1003
|
|
|
%s%s |
1004
|
|
|
WHERE |
1005
|
|
|
id = %d |
1006
|
|
|
AND |
1007
|
|
|
lang = '%s'", |
1008
|
|
|
PMF_Db::getTablePrefix(), |
1009
|
|
|
$table, |
1010
|
|
|
$record_id, |
1011
|
|
|
$record_lang); |
1012
|
|
|
|
1013
|
|
|
$result = $this->_config->getDb()->query($query); |
1014
|
|
|
|
1015
|
|
|
if ($row = $this->_config->getDb()->fetchObject($result)) { |
1016
|
|
|
return ($row->comment === 'y') ? false : true; |
1017
|
|
|
} else { |
1018
|
|
|
return true; |
1019
|
|
|
} |
1020
|
|
|
} |
1021
|
|
|
|
1022
|
|
|
/** |
1023
|
|
|
* Adds new category relations to a record |
1024
|
|
|
* |
1025
|
|
|
* @param array $categories Array of categories |
1026
|
|
|
* @param integer $record_id Record id |
1027
|
|
|
* @param string $language Language |
1028
|
|
|
* @return integer |
1029
|
|
|
*/ |
1030
|
|
|
public function addCategoryRelations(Array $categories, $record_id, $language) |
1031
|
|
|
{ |
1032
|
|
|
if (!is_array($categories)) { |
1033
|
|
|
return false; |
1034
|
|
|
} |
1035
|
|
|
|
1036
|
|
|
foreach ($categories as $_category) { |
1037
|
|
|
$this->_config->getDb()->query(sprintf( |
1038
|
|
|
"INSERT INTO |
1039
|
|
|
%sfaqcategoryrelations |
1040
|
|
|
VALUES |
1041
|
|
|
(%d, '%s', %d, '%s')", |
1042
|
|
|
PMF_Db::getTablePrefix(), |
1043
|
|
|
$_category, |
1044
|
|
|
$language, |
1045
|
|
|
$record_id, |
1046
|
|
|
$language)); |
1047
|
|
|
} |
1048
|
|
|
|
1049
|
|
|
return true; |
1050
|
|
|
} |
1051
|
|
|
|
1052
|
|
|
/** |
1053
|
|
|
* Adds new category relation to a record |
1054
|
|
|
* |
1055
|
|
|
* @param mixed $category Category or array of categories |
1056
|
|
|
* @param integer $record_id Record id |
1057
|
|
|
* @param string $language Language |
1058
|
|
|
* |
1059
|
|
|
* @return boolean |
1060
|
|
|
*/ |
1061
|
|
|
public function addCategoryRelation($category, $record_id, $language) |
1062
|
|
|
{ |
1063
|
|
|
// Just a fallback when (wrong case) $category is an array |
1064
|
|
|
if (is_array($category)) { |
1065
|
|
|
$this->addCategoryRelations($category, $record_id, $language); |
1066
|
|
|
} |
1067
|
|
|
$categories[] = $category; |
1068
|
|
|
|
1069
|
|
|
return $this->addCategoryRelations($categories, $record_id, $language); |
1070
|
|
|
} |
1071
|
|
|
|
1072
|
|
|
/** |
1073
|
|
|
* Deletes category relations to a record |
1074
|
|
|
* |
1075
|
|
|
* @param integer $record_id Record id |
1076
|
|
|
* @param string $record_lang Language |
1077
|
|
|
* @return boolean |
1078
|
|
|
*/ |
1079
|
|
|
public function deleteCategoryRelations($record_id, $record_lang) |
1080
|
|
|
{ |
1081
|
|
|
$query = sprintf(" |
1082
|
|
|
DELETE FROM |
1083
|
|
|
%sfaqcategoryrelations |
1084
|
|
|
WHERE |
1085
|
|
|
record_id = %d |
1086
|
|
|
AND |
1087
|
|
|
record_lang = '%s'", |
1088
|
|
|
PMF_Db::getTablePrefix(), |
1089
|
|
|
$record_id, |
1090
|
|
|
$record_lang); |
1091
|
|
|
$this->_config->getDb()->query($query); |
1092
|
|
|
|
1093
|
|
|
return true; |
1094
|
|
|
} |
1095
|
|
|
|
1096
|
|
|
/** |
1097
|
|
|
* Returns an array with all data from a FAQ record |
1098
|
|
|
* |
1099
|
|
|
* @param integer $solutionId Solution ID |
1100
|
|
|
* @return void |
1101
|
|
|
*/ |
1102
|
|
|
public function getRecordBySolutionId($solutionId) |
1103
|
|
|
{ |
1104
|
|
|
$query = sprintf( |
1105
|
|
|
"SELECT |
1106
|
|
|
* |
1107
|
|
|
FROM |
1108
|
|
|
%sfaqdata fd |
1109
|
|
|
LEFT JOIN |
1110
|
|
|
%sfaqdata_group fdg |
1111
|
|
|
ON |
1112
|
|
|
fd.id = fdg.record_id |
1113
|
|
|
LEFT JOIN |
1114
|
|
|
%sfaqdata_user fdu |
1115
|
|
|
ON |
1116
|
|
|
fd.id = fdu.record_id |
1117
|
|
|
WHERE |
1118
|
|
|
fd.solution_id = %d |
1119
|
|
|
%s", |
1120
|
|
|
PMF_Db::getTablePrefix(), |
1121
|
|
|
PMF_Db::getTablePrefix(), |
1122
|
|
|
PMF_Db::getTablePrefix(), |
1123
|
|
|
$solutionId, |
1124
|
|
|
$this->queryPermission($this->groupSupport) |
1125
|
|
|
); |
1126
|
|
|
|
1127
|
|
|
$result = $this->_config->getDb()->query($query); |
1128
|
|
|
|
1129
|
|
|
if ($row = $this->_config->getDb()->fetchObject($result)) { |
1130
|
|
|
|
1131
|
|
|
$question = nl2br($row->thema); |
1132
|
|
|
$content = $row->content; |
1133
|
|
|
$active = ('yes' == $row->active); |
1134
|
|
|
$expired = (date('YmdHis') > $row->date_end); |
1135
|
|
|
|
1136
|
|
|
if (!$active) { |
1137
|
|
|
$content = $this->pmf_lang['err_inactiveArticle']; |
1138
|
|
|
} |
1139
|
|
|
if ($expired) { |
1140
|
|
|
$content = $this->pmf_lang['err_expiredArticle']; |
1141
|
|
|
} |
1142
|
|
|
|
1143
|
|
|
$this->faqRecord = array( |
1144
|
|
|
'id' => $row->id, |
1145
|
|
|
'lang' => $row->lang, |
1146
|
|
|
'solution_id' => $row->solution_id, |
1147
|
|
|
'revision_id' => $row->revision_id, |
1148
|
|
|
'active' => $row->active, |
1149
|
|
|
'sticky' => $row->sticky, |
1150
|
|
|
'keywords' => $row->keywords, |
1151
|
|
|
'title' => $question, |
1152
|
|
|
'content' => $content, |
1153
|
|
|
'author' => $row->author, |
1154
|
|
|
'email' => $row->email, |
1155
|
|
|
'comment' => $row->comment, |
1156
|
|
|
'date' => PMF_Date::createIsoDate($row->datum), |
1157
|
|
|
'dateStart' => $row->date_start, |
1158
|
|
|
'dateEnd' => $row->date_end, |
1159
|
|
|
'linkState' => $row->links_state, |
1160
|
|
|
'linkCheckDate' => $row->links_check_date |
1161
|
|
|
); |
1162
|
|
|
} |
1163
|
|
|
} |
1164
|
|
|
|
1165
|
|
|
/** |
1166
|
|
|
* Gets the record ID from a given solution ID |
1167
|
|
|
* |
1168
|
|
|
* @param integer $solution_id Solution ID |
1169
|
|
|
* @return array |
1170
|
|
|
*/ |
1171
|
|
|
public function getIdFromSolutionId($solution_id) |
1172
|
|
|
{ |
1173
|
|
|
$query = sprintf(" |
1174
|
|
|
SELECT |
1175
|
|
|
id, lang, content |
1176
|
|
|
FROM |
1177
|
|
|
%sfaqdata |
1178
|
|
|
WHERE |
1179
|
|
|
solution_id = %d", |
1180
|
|
|
PMF_Db::getTablePrefix(), |
1181
|
|
|
$solution_id); |
1182
|
|
|
|
1183
|
|
|
$result = $this->_config->getDb()->query($query); |
1184
|
|
|
|
1185
|
|
|
if ($row = $this->_config->getDb()->fetchObject($result)) { |
1186
|
|
|
return array('id' => $row->id, |
1187
|
|
|
'lang' => $row->lang, |
1188
|
|
|
'content' => $row->content); |
1189
|
|
|
} |
1190
|
|
|
|
1191
|
|
|
return null; |
1192
|
|
|
} |
1193
|
|
|
|
1194
|
|
|
/** |
1195
|
|
|
* Gets the latest solution id for a FAQ record |
1196
|
|
|
* |
1197
|
|
|
* @return integer |
1198
|
|
|
*/ |
1199
|
|
|
public function getSolutionId() |
1200
|
|
|
{ |
1201
|
|
|
$latest_id = 0; |
1202
|
|
|
$next_solution_id = 0; |
1203
|
|
|
|
1204
|
|
|
$query = sprintf(' |
1205
|
|
|
SELECT |
1206
|
|
|
MAX(solution_id) AS solution_id |
1207
|
|
|
FROM |
1208
|
|
|
%sfaqdata', |
1209
|
|
|
PMF_Db::getTablePrefix()); |
1210
|
|
|
$result = $this->_config->getDb()->query($query); |
1211
|
|
|
|
1212
|
|
|
if ($result && $row = $this->_config->getDb()->fetchObject($result)) { |
1213
|
|
|
$latest_id = $row->solution_id; |
1214
|
|
|
} |
1215
|
|
|
|
1216
|
|
|
if ($latest_id < PMF_SOLUTION_ID_START_VALUE) { |
1217
|
|
|
$next_solution_id = PMF_SOLUTION_ID_START_VALUE; |
1218
|
|
|
} else { |
1219
|
|
|
$next_solution_id = $latest_id + PMF_SOLUTION_ID_INCREMENT_VALUE; |
1220
|
|
|
} |
1221
|
|
|
|
1222
|
|
|
return $next_solution_id; |
1223
|
|
|
} |
1224
|
|
|
|
1225
|
|
|
/** |
1226
|
|
|
* Returns an array with all data from all FAQ records |
1227
|
|
|
* |
1228
|
|
|
* @param integer $sortType Sorting type |
1229
|
|
|
* @param array $condition Condition |
1230
|
|
|
* @param string $sortOrder Sorting order |
1231
|
|
|
* @return void |
1232
|
|
|
*/ |
1233
|
|
|
public function getAllRecords($sortType = FAQ_SORTING_TYPE_CATID_FAQID, Array $condition = null, $sortOrder = 'ASC') |
1234
|
|
|
{ |
1235
|
|
|
$where = ''; |
1236
|
|
|
if (!is_null($condition)) { |
1237
|
|
|
$num = count($condition); |
1238
|
|
|
$where = 'WHERE '; |
1239
|
|
|
foreach ($condition as $field => $data) { |
1240
|
|
|
$num--; |
1241
|
|
|
$where .= $field; |
1242
|
|
|
if (is_array($data)) { |
1243
|
|
|
$where .= " IN ("; |
1244
|
|
|
$separator = ""; |
1245
|
|
|
foreach ($data as $value) { |
1246
|
|
|
$where .= $separator."'".$this->_config->getDb()->escape($value)."'"; |
1247
|
|
|
$separator = ", "; |
1248
|
|
|
} |
1249
|
|
|
$where .= ")"; |
1250
|
|
|
} else { |
1251
|
|
|
$where .= " = '".$this->_config->getDb()->escape($data)."'"; |
1252
|
|
|
} |
1253
|
|
|
if ($num > 0) { |
1254
|
|
|
$where .= " AND "; |
1255
|
|
|
} |
1256
|
|
|
} |
1257
|
|
|
} |
1258
|
|
|
|
1259
|
|
|
switch ($sortType) { |
1260
|
|
|
|
1261
|
|
|
case FAQ_SORTING_TYPE_CATID_FAQID: |
1262
|
|
|
$orderBy = sprintf(" |
1263
|
|
|
ORDER BY |
1264
|
|
|
fcr.category_id, |
1265
|
|
|
fd.id %s", |
1266
|
|
|
$sortOrder); |
1267
|
|
|
break; |
1268
|
|
|
|
1269
|
|
|
case FAQ_SORTING_TYPE_FAQID: |
1270
|
|
|
$orderBy = sprintf(" |
1271
|
|
|
ORDER BY |
1272
|
|
|
fd.id %s", |
1273
|
|
|
$sortOrder); |
1274
|
|
|
break; |
1275
|
|
|
|
1276
|
|
|
case FAQ_SORTING_TYPE_FAQTITLE_FAQID: |
1277
|
|
|
$orderBy = sprintf(" |
1278
|
|
|
ORDER BY |
1279
|
|
|
fcr.category_id, |
1280
|
|
|
fd.thema %s", |
1281
|
|
|
$sortOrder); |
1282
|
|
|
break; |
1283
|
|
|
|
1284
|
|
|
case FAQ_SORTING_TYPE_DATE_FAQID: |
1285
|
|
|
$orderBy = sprintf(" |
1286
|
|
|
ORDER BY |
1287
|
|
|
fcr.category_id, |
1288
|
|
|
fd.datum %s", |
1289
|
|
|
$sortOrder); |
1290
|
|
|
break; |
1291
|
|
|
|
1292
|
|
|
default: |
1293
|
|
|
$orderBy = ''; |
1294
|
|
|
break; |
1295
|
|
|
} |
1296
|
|
|
|
1297
|
|
|
$query = sprintf(" |
1298
|
|
|
SELECT |
1299
|
|
|
fd.id AS id, |
1300
|
|
|
fd.lang AS lang, |
1301
|
|
|
fcr.category_id AS category_id, |
1302
|
|
|
fd.solution_id AS solution_id, |
1303
|
|
|
fd.revision_id AS revision_id, |
1304
|
|
|
fd.active AS active, |
1305
|
|
|
fd.sticky AS sticky, |
1306
|
|
|
fd.keywords AS keywords, |
1307
|
|
|
fd.thema AS thema, |
1308
|
|
|
fd.content AS content, |
1309
|
|
|
fd.author AS author, |
1310
|
|
|
fd.email AS email, |
1311
|
|
|
fd.comment AS comment, |
1312
|
|
|
fd.datum AS datum, |
1313
|
|
|
fd.links_state AS links_state, |
1314
|
|
|
fd.links_check_date AS links_check_date, |
1315
|
|
|
fd.date_start AS date_start, |
1316
|
|
|
fd.date_end AS date_end, |
1317
|
|
|
fd.sticky AS sticky |
1318
|
|
|
FROM |
1319
|
|
|
%sfaqdata fd |
1320
|
|
|
LEFT JOIN |
1321
|
|
|
%sfaqcategoryrelations fcr |
1322
|
|
|
ON |
1323
|
|
|
fd.id = fcr.record_id |
1324
|
|
|
AND |
1325
|
|
|
fd.lang = fcr.record_lang |
1326
|
|
|
%s |
1327
|
|
|
%s", |
1328
|
|
|
PMF_Db::getTablePrefix(), |
1329
|
|
|
PMF_Db::getTablePrefix(), |
1330
|
|
|
$where, |
1331
|
|
|
$orderBy |
1332
|
|
|
); |
1333
|
|
|
|
1334
|
|
|
$result = $this->_config->getDb()->query($query); |
1335
|
|
|
|
1336
|
|
|
while ($row = $this->_config->getDb()->fetchObject($result)) { |
1337
|
|
|
$content = $row->content; |
1338
|
|
|
$active = ('yes' == $row->active); |
1339
|
|
|
$expired = (date('YmdHis') > $row->date_end); |
1340
|
|
|
|
1341
|
|
|
if (!$active) { |
1342
|
|
|
$content = $this->pmf_lang['err_inactiveArticle']; |
1343
|
|
|
} |
1344
|
|
|
if ($expired) { |
1345
|
|
|
$content = $this->pmf_lang['err_expiredArticle']; |
1346
|
|
|
} |
1347
|
|
|
|
1348
|
|
|
$this->faqRecords[] = array( |
1349
|
|
|
'id' => $row->id, |
1350
|
|
|
'category_id' => $row->category_id, |
1351
|
|
|
'lang' => $row->lang, |
1352
|
|
|
'solution_id' => $row->solution_id, |
1353
|
|
|
'revision_id' => $row->revision_id, |
1354
|
|
|
'active' => $row->active, |
1355
|
|
|
'sticky' => $row->sticky, |
1356
|
|
|
'keywords' => $row->keywords, |
1357
|
|
|
'title' => $row->thema, |
1358
|
|
|
'content' => $content, |
1359
|
|
|
'author' => $row->author, |
1360
|
|
|
'email' => $row->email, |
1361
|
|
|
'comment' => $row->comment, |
1362
|
|
|
'date' => PMF_Date::createIsoDate($row->datum), |
1363
|
|
|
'dateStart' => $row->date_start, |
1364
|
|
|
'dateEnd' => $row->date_end |
1365
|
|
|
); |
1366
|
|
|
} |
1367
|
|
|
} |
1368
|
|
|
|
1369
|
|
|
/** |
1370
|
|
|
* Returns the FAQ record title from the ID and language |
1371
|
|
|
* |
1372
|
|
|
* @param integer $id Record id |
1373
|
|
|
* @return string |
1374
|
|
|
*/ |
1375
|
|
|
public function getRecordTitle($id) |
1376
|
|
|
{ |
1377
|
|
|
if (isset($this->faqRecord['id']) && ($this->faqRecord['id'] == $id)) { |
1378
|
|
|
return $this->faqRecord['title']; |
1379
|
|
|
} |
1380
|
|
|
|
1381
|
|
|
$query = sprintf( |
1382
|
|
|
"SELECT |
1383
|
|
|
thema |
1384
|
|
|
FROM |
1385
|
|
|
%sfaqdata |
1386
|
|
|
WHERE |
1387
|
|
|
id = %d AND lang = '%s'", |
1388
|
|
|
PMF_Db::getTablePrefix(), |
1389
|
|
|
$id, |
1390
|
|
|
$this->_config->getLanguage()->getLanguage() |
1391
|
|
|
); |
1392
|
|
|
$result = $this->_config->getDb()->query($query); |
1393
|
|
|
|
1394
|
|
|
if ($this->_config->getDb()->numRows($result) > 0) { |
1395
|
|
|
while ($row = $this->_config->getDb()->fetchObject($result)) { |
1396
|
|
|
$output = $row->thema; |
1397
|
|
|
} |
1398
|
|
|
} else { |
1399
|
|
|
$output = $this->pmf_lang['no_cats']; |
1400
|
|
|
} |
1401
|
|
|
|
1402
|
|
|
return $output; |
1403
|
|
|
} |
1404
|
|
|
|
1405
|
|
|
/** |
1406
|
|
|
* Gets all revisions from a given record ID |
1407
|
|
|
* |
1408
|
|
|
* @param integer $record_id Record id |
1409
|
|
|
* @param string $record_lang Record language |
1410
|
|
|
* @return array |
1411
|
|
|
*/ |
1412
|
|
|
public function getRevisionIds($record_id, $record_lang) |
1413
|
|
|
{ |
1414
|
|
|
$revision_data = array(); |
1415
|
|
|
|
1416
|
|
|
$query = sprintf(" |
1417
|
|
|
SELECT |
1418
|
|
|
revision_id, datum, author |
1419
|
|
|
FROM |
1420
|
|
|
%sfaqdata_revisions |
1421
|
|
|
WHERE |
1422
|
|
|
id = %d |
1423
|
|
|
AND |
1424
|
|
|
lang = '%s' |
1425
|
|
|
ORDER BY |
1426
|
|
|
revision_id", |
1427
|
|
|
PMF_Db::getTablePrefix(), |
1428
|
|
|
$record_id, |
1429
|
|
|
$record_lang); |
1430
|
|
|
|
1431
|
|
|
$result = $this->_config->getDb()->query($query); |
1432
|
|
|
|
1433
|
|
|
if ($this->_config->getDb()->numRows($result) > 0) { |
1434
|
|
|
while ($row = $this->_config->getDb()->fetchObject($result)) { |
1435
|
|
|
$revision_data[] = array( |
1436
|
|
|
'revision_id' => $row->revision_id, |
1437
|
|
|
'datum' => $row->datum, |
1438
|
|
|
'author' => $row->author); |
1439
|
|
|
} |
1440
|
|
|
} |
1441
|
|
|
|
1442
|
|
|
return $revision_data; |
1443
|
|
|
} |
1444
|
|
|
|
1445
|
|
|
/** |
1446
|
|
|
* Adds a new revision from a given record ID |
1447
|
|
|
* |
1448
|
|
|
* @param integer $record_id Record id |
1449
|
|
|
* @param string $record_lang Record language |
1450
|
|
|
* @return array |
1451
|
|
|
*/ |
1452
|
|
|
public function addNewRevision($record_id, $record_lang) |
1453
|
|
|
{ |
1454
|
|
|
$query = sprintf(" |
1455
|
|
|
INSERT INTO |
1456
|
|
|
%sfaqdata_revisions |
1457
|
|
|
SELECT * FROM |
1458
|
|
|
%sfaqdata |
1459
|
|
|
WHERE |
1460
|
|
|
id = %d |
1461
|
|
|
AND |
1462
|
|
|
lang = '%s'", |
1463
|
|
|
PMF_Db::getTablePrefix(), |
1464
|
|
|
PMF_Db::getTablePrefix(), |
1465
|
|
|
$record_id, |
1466
|
|
|
$record_lang); |
1467
|
|
|
$this->_config->getDb()->query($query); |
1468
|
|
|
|
1469
|
|
|
return true; |
1470
|
|
|
} |
1471
|
|
|
|
1472
|
|
|
|
1473
|
|
|
/** |
1474
|
|
|
* Returns the keywords of a FAQ record from the ID and language |
1475
|
|
|
* |
1476
|
|
|
* @param integer $id record id |
1477
|
|
|
* @return string |
1478
|
|
|
*/ |
1479
|
|
|
public function getRecordKeywords($id) |
1480
|
|
|
{ |
1481
|
|
|
if (isset($this->faqRecord['id']) && ($this->faqRecord['id'] == $id)) { |
1482
|
|
|
return $this->faqRecord['keywords']; |
1483
|
|
|
} |
1484
|
|
|
|
1485
|
|
|
$query = sprintf( |
1486
|
|
|
"SELECT |
1487
|
|
|
keywords |
1488
|
|
|
FROM |
1489
|
|
|
%sfaqdata |
1490
|
|
|
WHERE id = %d AND lang = '%s'", |
1491
|
|
|
PMF_Db::getTablePrefix(), |
1492
|
|
|
$id, |
1493
|
|
|
$this->_config->getLanguage()->getLanguage()); |
1494
|
|
|
|
1495
|
|
|
$result = $this->_config->getDb()->query($query); |
1496
|
|
|
|
1497
|
|
|
if ($this->_config->getDb()->numRows($result) > 0) { |
1498
|
|
|
$row = $this->_config->getDb()->fetchObject($result); |
1499
|
|
|
return PMF_String::htmlspecialchars($row->keywords, ENT_QUOTES, 'utf-8'); |
1500
|
|
|
} else { |
1501
|
|
|
return ''; |
1502
|
|
|
} |
1503
|
|
|
} |
1504
|
|
|
|
1505
|
|
|
/** |
1506
|
|
|
* Returns a answer preview of the FAQ record |
1507
|
|
|
* |
1508
|
|
|
* @param integer $recordId FAQ record ID |
1509
|
|
|
* @param integer $wordCount Number of words, default: 12 |
1510
|
|
|
* |
1511
|
|
|
* @return string |
1512
|
|
|
*/ |
1513
|
|
|
public function getRecordPreview($recordId, $wordCount = 12) |
1514
|
|
|
{ |
1515
|
|
|
$answerPreview = ''; |
1516
|
|
|
|
1517
|
|
|
if (isset($this->faqRecord['id']) && ($this->faqRecord['id'] == $recordId)) { |
1518
|
|
|
$answerPreview = $this->faqRecord['content']; |
1519
|
|
|
} |
1520
|
|
|
|
1521
|
|
|
$query = sprintf(" |
1522
|
|
|
SELECT |
1523
|
|
|
content as answer |
1524
|
|
|
FROM |
1525
|
|
|
%sfaqdata |
1526
|
|
|
WHERE |
1527
|
|
|
id = %d |
1528
|
|
|
AND |
1529
|
|
|
lang = '%s'", |
1530
|
|
|
PMF_Db::getTablePrefix(), |
1531
|
|
|
$recordId, |
1532
|
|
|
$this->_config->getLanguage()->getLanguage()); |
1533
|
|
|
|
1534
|
|
|
$result = $this->_config->getDb()->query($query); |
1535
|
|
|
|
1536
|
|
|
if ($this->_config->getDb()->numRows($result) > 0) { |
1537
|
|
|
$row = $this->_config->getDb()->fetchObject($result); |
1538
|
|
|
$answerPreview = strip_tags($row->answer); |
1539
|
|
|
} else { |
1540
|
|
|
$answerPreview = $this->_config->get('main.metaDescription'); |
1541
|
|
|
} |
1542
|
|
|
|
1543
|
|
|
return PMF_Utils::makeShorterText($answerPreview, $wordCount); |
1544
|
|
|
} |
1545
|
|
|
|
1546
|
|
|
/** |
1547
|
|
|
* Returns the number of activated and not expired records, optionally |
1548
|
|
|
* not limited to the current language |
1549
|
|
|
* |
1550
|
|
|
* @param string $language Language |
1551
|
|
|
* @return int |
1552
|
|
|
*/ |
1553
|
|
|
public function getNumberOfRecords($language = null) |
1554
|
|
|
{ |
1555
|
|
|
$now = date('YmdHis'); |
1556
|
|
|
|
1557
|
|
|
$query = sprintf(" |
1558
|
|
|
SELECT |
1559
|
|
|
id |
1560
|
|
|
FROM |
1561
|
|
|
%sfaqdata |
1562
|
|
|
WHERE |
1563
|
|
|
active = 'yes' |
1564
|
|
|
%s |
1565
|
|
|
AND |
1566
|
|
|
date_start <= '%s' |
1567
|
|
|
AND |
1568
|
|
|
date_end >= '%s'", |
1569
|
|
|
PMF_Db::getTablePrefix(), |
1570
|
|
|
null == $language ? '' : "AND lang = '".$language."'", |
1571
|
|
|
$now, |
1572
|
|
|
$now); |
1573
|
|
|
|
1574
|
|
|
$num = $this->_config->getDb()->numRows($this->_config->getDb()->query($query)); |
1575
|
|
|
|
1576
|
|
|
if ($num > 0) { |
1577
|
|
|
return $num; |
1578
|
|
|
} else { |
1579
|
|
|
return 0; |
1580
|
|
|
} |
1581
|
|
|
} |
1582
|
|
|
|
1583
|
|
|
/** |
1584
|
|
|
* This function generates a list with the mosted voted or most visited records |
1585
|
|
|
* |
1586
|
|
|
* @param string $type Type definition visits/voted |
1587
|
|
|
* @access public |
1588
|
|
|
* @since 2009-11-03 |
1589
|
|
|
* @author Max Köhler <[email protected]> |
1590
|
|
|
* @return array |
1591
|
|
|
*/ |
1592
|
|
|
public function getTopTen($type = 'visits') |
1593
|
|
|
{ |
1594
|
|
|
if ('visits' == $type) { |
1595
|
|
|
$result = $this->getTopTenData(PMF_NUMBER_RECORDS_TOPTEN, 0, $this->_config->getLanguage()->getLanguage()); |
1596
|
|
|
} else { |
1597
|
|
|
$result = $this->getTopVotedData(PMF_NUMBER_RECORDS_TOPTEN, 0, $this->_config->getLanguage()->getLanguage()); |
1598
|
|
|
} |
1599
|
|
|
$output = array(); |
1600
|
|
|
|
1601
|
|
|
if (count($result) > 0) { |
1602
|
|
|
foreach ($result as $row) { |
1603
|
|
|
if ('visits' == $type) { |
1604
|
|
|
$output['title'][] = PMF_Utils::makeShorterText($row['thema'], 8); |
1605
|
|
|
$output['url'][] = $row['url']; |
1606
|
|
|
$output['visits'][] = $this->plr->GetMsg('plmsgViews', $row['visits']); |
1607
|
|
|
} else { |
1608
|
|
|
$output['title'][] = PMF_Utils::makeShorterText($row['thema'], 8); |
1609
|
|
|
$output['url'][] = $row['url']; |
1610
|
|
|
$output['voted'][] = sprintf( |
1611
|
|
|
'%s %s 5 - %s', |
1612
|
|
|
round($row['avg'], 2), |
1613
|
|
|
$this->pmf_lang['msgVoteFrom'], |
1614
|
|
|
$this->plr->GetMsg('plmsgVotes', $row['user']) |
1615
|
|
|
); |
1616
|
|
|
} |
1617
|
|
|
} |
1618
|
|
|
} else { |
1619
|
|
|
$output['error'] = $this->pmf_lang['err_noTopTen']; |
1620
|
|
|
} |
1621
|
|
|
|
1622
|
|
|
return $output; |
1623
|
|
|
} |
1624
|
|
|
|
1625
|
|
|
/** |
1626
|
|
|
* This function generates the list with the latest published records |
1627
|
|
|
* |
1628
|
|
|
* @return array |
1629
|
|
|
*/ |
1630
|
|
|
public function getLatest() |
1631
|
|
|
{ |
1632
|
|
|
$date = new PMF_Date($this->_config); |
1633
|
|
|
$result = $this->getLatestData(PMF_NUMBER_RECORDS_LATEST, $this->_config->getLanguage()->getLanguage()); |
1634
|
|
|
$output = array(); |
1635
|
|
|
|
1636
|
|
|
if (count ($result) > 0) { |
1637
|
|
|
foreach ($result as $row) { |
1638
|
|
|
$output['url'][] = $row['url']; |
1639
|
|
|
$output['title'][] = PMF_Utils::makeShorterText($row['thema'], 8); |
1640
|
|
|
$output['date'][] = $date->format(PMF_Date::createIsoDate($row['datum'])); |
1641
|
|
|
} |
1642
|
|
|
} else { |
1643
|
|
|
$output['error'] = $this->pmf_lang["err_noArticles"]; |
1644
|
|
|
} |
1645
|
|
|
|
1646
|
|
|
return $output; |
1647
|
|
|
} |
1648
|
|
|
|
1649
|
|
|
/** |
1650
|
|
|
* Deletes a question for the table faquestion |
1651
|
|
|
* |
1652
|
|
|
* @param integer $questionId |
1653
|
|
|
* |
1654
|
|
|
* @return boolean |
1655
|
|
|
*/ |
1656
|
|
|
function deleteQuestion($questionId) |
1657
|
|
|
{ |
1658
|
|
|
$delete = sprintf(' |
1659
|
|
|
DELETE FROM |
1660
|
|
|
%sfaqquestions |
1661
|
|
|
WHERE |
1662
|
|
|
id = %d', |
1663
|
|
|
PMF_Db::getTablePrefix(), |
1664
|
|
|
$questionId |
1665
|
|
|
); |
1666
|
|
|
|
1667
|
|
|
$this->_config->getDb()->query($delete); |
1668
|
|
|
return true; |
1669
|
|
|
} |
1670
|
|
|
|
1671
|
|
|
/** |
1672
|
|
|
* Returns the visibilty of a question |
1673
|
|
|
* |
1674
|
|
|
* @param integer $question_id |
1675
|
|
|
* @return string |
1676
|
|
|
* @access public |
1677
|
|
|
* @since 2006-11-04 |
1678
|
|
|
* @author Thorsten Rinne <[email protected]> |
1679
|
|
|
*/ |
1680
|
|
|
function getVisibilityOfQuestion($question_id) |
1681
|
|
|
{ |
1682
|
|
|
$query = sprintf(' |
1683
|
|
|
SELECT |
1684
|
|
|
is_visible |
1685
|
|
|
FROM |
1686
|
|
|
%sfaqquestions |
1687
|
|
|
WHERE |
1688
|
|
|
id = %d', |
1689
|
|
|
PMF_Db::getTablePrefix(), |
1690
|
|
|
$question_id); |
1691
|
|
|
|
1692
|
|
|
$result = $this->_config->getDb()->query($query); |
1693
|
|
|
if ($this->_config->getDb()->numRows($result) > 0) { |
1694
|
|
|
$row = $this->_config->getDb()->fetchObject($result); |
1695
|
|
|
return $row->is_visible; |
1696
|
|
|
} |
1697
|
|
|
return null; |
1698
|
|
|
} |
1699
|
|
|
|
1700
|
|
|
/** |
1701
|
|
|
* Sets the visibilty of a question |
1702
|
|
|
* |
1703
|
|
|
* @param integer $question_id |
1704
|
|
|
* @param string $is_visible |
1705
|
|
|
* @return boolean |
1706
|
|
|
* @access public |
1707
|
|
|
* @since 2006-11-04 |
1708
|
|
|
* @author Thorsten Rinne <[email protected]> |
1709
|
|
|
*/ |
1710
|
|
|
function setVisibilityOfQuestion($question_id, $is_visible) |
1711
|
|
|
{ |
1712
|
|
|
$query = sprintf(" |
1713
|
|
|
UPDATE |
1714
|
|
|
%sfaqquestions |
1715
|
|
|
SET |
1716
|
|
|
is_visible = '%s' |
1717
|
|
|
WHERE |
1718
|
|
|
id = %d", |
1719
|
|
|
PMF_Db::getTablePrefix(), |
1720
|
|
|
$is_visible, |
1721
|
|
|
$question_id); |
1722
|
|
|
|
1723
|
|
|
$this->_config->getDb()->query($query); |
1724
|
|
|
return true; |
1725
|
|
|
} |
1726
|
|
|
|
1727
|
|
|
/** |
1728
|
|
|
* This function generates a data-set with the mosted voted recors |
1729
|
|
|
* |
1730
|
|
|
* @param integer $count Number of records |
1731
|
|
|
* @param integer $category Category ID |
1732
|
|
|
* @param string $language Language |
1733
|
|
|
* @return array |
1734
|
|
|
*/ |
1735
|
|
|
public function getTopVotedData($count = PMF_NUMBER_RECORDS_TOPTEN, $category = 0, $language = nuLL) |
1736
|
|
|
{ |
1737
|
|
|
global $sids; |
1738
|
|
|
|
1739
|
|
|
$now = date('YmdHis'); |
1740
|
|
|
$query = |
1741
|
|
|
' SELECT |
1742
|
|
|
fd.id AS id, |
1743
|
|
|
fd.lang AS lang, |
1744
|
|
|
fd.thema AS thema, |
1745
|
|
|
fd.datum AS datum, |
1746
|
|
|
fcr.category_id AS category_id, |
1747
|
|
|
(fv.vote/fv.usr) AS avg, |
1748
|
|
|
fv.usr AS user |
1749
|
|
|
FROM |
1750
|
|
|
'.PMF_Db::getTablePrefix().'faqvoting fv, |
1751
|
|
|
'.PMF_Db::getTablePrefix().'faqdata fd |
1752
|
|
|
LEFT JOIN |
1753
|
|
|
'.PMF_Db::getTablePrefix().'faqcategoryrelations fcr |
1754
|
|
|
ON |
1755
|
|
|
fd.id = fcr.record_id |
1756
|
|
|
AND |
1757
|
|
|
fd.lang = fcr.record_lang |
1758
|
|
|
LEFT JOIN |
1759
|
|
|
'.PMF_Db::getTablePrefix().'faqdata_group AS fdg |
1760
|
|
|
ON |
1761
|
|
|
fd.id = fdg.record_id |
1762
|
|
|
LEFT JOIN |
1763
|
|
|
'.PMF_Db::getTablePrefix().'faqdata_user AS fdu |
1764
|
|
|
ON |
1765
|
|
|
fd.id = fdu.record_id |
1766
|
|
|
WHERE |
1767
|
|
|
fd.date_start <= \''.$now.'\' |
1768
|
|
|
AND fd.date_end >= \''.$now.'\' |
1769
|
|
|
AND fd.id = fv.artikel |
1770
|
|
|
AND fd.active = \'yes\''; |
1771
|
|
|
|
1772
|
|
View Code Duplication |
if (isset($categoryId) && is_numeric($categoryId) && ($categoryId != 0)) { |
1773
|
|
|
$query .= ' |
1774
|
|
|
AND |
1775
|
|
|
fcr.category_id = \''.$categoryId.'\''; |
1776
|
|
|
} |
1777
|
|
|
if (isset($language) && PMF_Language::isASupportedLanguage($language)) { |
1778
|
|
|
$query .= ' |
1779
|
|
|
AND |
1780
|
|
|
fd.lang = \''.$language.'\''; |
1781
|
|
|
} |
1782
|
|
|
$query .= ' |
1783
|
|
|
' . $this->queryPermission($this->groupSupport) . ' |
1784
|
|
|
ORDER BY |
1785
|
|
|
avg DESC'; |
1786
|
|
|
|
1787
|
|
|
$result = $this->_config->getDb()->query($query); |
1788
|
|
|
$topten = array(); |
1789
|
|
|
$data = array(); |
1790
|
|
|
|
1791
|
|
|
$i = 1; |
1792
|
|
|
$oldId = 0; |
1793
|
|
|
while (($row = $this->_config->getDb()->fetchObject($result)) && $i <= $count) { |
1794
|
|
|
if ($oldId != $row->id) { |
1795
|
|
|
$data['avg'] = $row->avg; |
1796
|
|
|
$data['thema'] = $row->thema; |
1797
|
|
|
$data['date'] = $row->datum; |
1798
|
|
|
$data['user'] = $row->user; |
1799
|
|
|
|
1800
|
|
|
$title = $row->thema; |
1801
|
|
|
$url = sprintf( |
1802
|
|
|
'%s?%saction=artikel&cat=%d&id=%d&artlang=%s', |
1803
|
|
|
PMF_Link::getSystemRelativeUri(), |
1804
|
|
|
$sids, |
1805
|
|
|
$row->category_id, |
1806
|
|
|
$row->id, |
1807
|
|
|
$row->lang |
1808
|
|
|
); |
1809
|
|
|
$oLink = new PMF_Link($url, $this->_config); |
1810
|
|
|
$oLink->itemTitle = $row->thema; |
1811
|
|
|
$oLink->tooltip = $title; |
1812
|
|
|
$data['url'] = $oLink->toString(); |
1813
|
|
|
|
1814
|
|
|
$topten[] = $data; |
1815
|
|
|
$i++; |
1816
|
|
|
} |
1817
|
|
|
$oldId = $row->id; |
1818
|
|
|
} |
1819
|
|
|
|
1820
|
|
|
return $topten; |
1821
|
|
|
} |
1822
|
|
|
|
1823
|
|
|
/** |
1824
|
|
|
* This function generates the Top Ten data with the mosted viewed records |
1825
|
|
|
* |
1826
|
|
|
* @param integer $count Number of records |
1827
|
|
|
* @param integer $categoryId Category ID |
1828
|
|
|
* @param string $language Language |
1829
|
|
|
* @return array |
1830
|
|
|
*/ |
1831
|
|
|
public function getTopTenData($count = PMF_NUMBER_RECORDS_TOPTEN, $categoryId = 0, $language = null) |
1832
|
|
|
{ |
1833
|
|
|
global $sids; |
1834
|
|
|
|
1835
|
|
|
$now = date('YmdHis'); |
1836
|
|
|
$query = |
1837
|
|
|
' SELECT |
1838
|
|
|
fd.id AS id, |
1839
|
|
|
fd.lang AS lang, |
1840
|
|
|
fd.thema AS thema, |
1841
|
|
|
fd.datum AS datum, |
1842
|
|
|
fcr.category_id AS category_id, |
1843
|
|
|
fv.visits AS visits, |
1844
|
|
|
fv.last_visit AS last_visit, |
1845
|
|
|
fdg.group_id AS group_id, |
1846
|
|
|
fdu.user_id AS user_id |
1847
|
|
|
FROM |
1848
|
|
|
'.PMF_Db::getTablePrefix().'faqvisits fv, |
1849
|
|
|
'.PMF_Db::getTablePrefix().'faqdata fd |
1850
|
|
|
LEFT JOIN |
1851
|
|
|
'.PMF_Db::getTablePrefix().'faqcategoryrelations fcr |
1852
|
|
|
ON |
1853
|
|
|
fd.id = fcr.record_id |
1854
|
|
|
AND |
1855
|
|
|
fd.lang = fcr.record_lang |
1856
|
|
|
LEFT JOIN |
1857
|
|
|
'.PMF_Db::getTablePrefix().'faqdata_group AS fdg |
1858
|
|
|
ON |
1859
|
|
|
fd.id = fdg.record_id |
1860
|
|
|
LEFT JOIN |
1861
|
|
|
'.PMF_Db::getTablePrefix().'faqdata_user AS fdu |
1862
|
|
|
ON |
1863
|
|
|
fd.id = fdu.record_id |
1864
|
|
|
WHERE |
1865
|
|
|
fd.date_start <= \''.$now.'\' |
1866
|
|
|
AND fd.date_end >= \''.$now.'\' |
1867
|
|
|
AND fd.id = fv.id |
1868
|
|
|
AND fd.lang = fv.lang |
1869
|
|
|
AND fd.active = \'yes\''; |
1870
|
|
|
|
1871
|
|
View Code Duplication |
if (isset($categoryId) && is_numeric($categoryId) && ($categoryId != 0)) { |
1872
|
|
|
$query .= ' |
1873
|
|
|
AND |
1874
|
|
|
fcr.category_id = \''.$categoryId.'\''; |
1875
|
|
|
} |
1876
|
|
|
if (isset($language) && PMF_Language::isASupportedLanguage($language)) { |
1877
|
|
|
$query .= ' |
1878
|
|
|
AND |
1879
|
|
|
fd.lang = \''.$language.'\''; |
1880
|
|
|
} |
1881
|
|
|
$query .= ' |
1882
|
|
|
' . $this->queryPermission($this->groupSupport) . ' |
1883
|
|
|
ORDER BY |
1884
|
|
|
fv.visits DESC'; |
1885
|
|
|
|
1886
|
|
|
$result = $this->_config->getDb()->query($query); |
1887
|
|
|
$topten = array(); |
1888
|
|
|
$data = array(); |
1889
|
|
|
|
1890
|
|
|
$i = 1; |
1891
|
|
|
$oldId = 0; |
1892
|
|
View Code Duplication |
while (($row = $this->_config->getDb()->fetchObject($result)) && $i <= $count) { |
1893
|
|
|
if ($oldId != $row->id) { |
1894
|
|
|
|
1895
|
|
|
if ($this->groupSupport) { |
1896
|
|
|
if (!in_array($row->user_id, array(-1, $this->user)) || !in_array($row->group_id, $this->groups)) { |
1897
|
|
|
continue; |
1898
|
|
|
} |
1899
|
|
|
} else { |
1900
|
|
|
if (!in_array($row->user_id, array(-1, $this->user))) { |
1901
|
|
|
continue; |
1902
|
|
|
} |
1903
|
|
|
} |
1904
|
|
|
|
1905
|
|
|
$data['visits'] = $row->visits; |
1906
|
|
|
$data['thema'] = $row->thema; |
1907
|
|
|
$data['date'] = $row->datum; |
1908
|
|
|
$data['last_visit'] = $row->last_visit; |
1909
|
|
|
|
1910
|
|
|
$title = $row->thema; |
1911
|
|
|
$url = sprintf( |
1912
|
|
|
'%s?%saction=artikel&cat=%d&id=%d&artlang=%s', |
1913
|
|
|
PMF_Link::getSystemRelativeUri(), |
1914
|
|
|
$sids, |
1915
|
|
|
$row->category_id, |
1916
|
|
|
$row->id, |
1917
|
|
|
$row->lang |
1918
|
|
|
); |
1919
|
|
|
$oLink = new PMF_Link($url, $this->_config); |
1920
|
|
|
$oLink->itemTitle = $row->thema; |
1921
|
|
|
$oLink->tooltip = $title; |
1922
|
|
|
$data['url'] = $oLink->toString(); |
1923
|
|
|
|
1924
|
|
|
$topten[] = $data; |
1925
|
|
|
$i++; |
1926
|
|
|
} |
1927
|
|
|
$oldId = $row->id; |
1928
|
|
|
} |
1929
|
|
|
|
1930
|
|
|
return $topten; |
1931
|
|
|
} |
1932
|
|
|
|
1933
|
|
|
/** |
1934
|
|
|
* This function generates an array with a specified number of most recent |
1935
|
|
|
* published records |
1936
|
|
|
* |
1937
|
|
|
* @param integer $count Number of records |
1938
|
|
|
* @param string $language Language |
1939
|
|
|
* |
1940
|
|
|
* @return array |
1941
|
|
|
*/ |
1942
|
|
|
public function getLatestData($count = PMF_NUMBER_RECORDS_LATEST, $language = null) |
1943
|
|
|
{ |
1944
|
|
|
global $sids; |
1945
|
|
|
|
1946
|
|
|
$now = date('YmdHis'); |
1947
|
|
|
$query = |
1948
|
|
|
' SELECT |
1949
|
|
|
fd.id AS id, |
1950
|
|
|
fd.lang AS lang, |
1951
|
|
|
fcr.category_id AS category_id, |
1952
|
|
|
fd.thema AS thema, |
1953
|
|
|
fd.content AS content, |
1954
|
|
|
fd.datum AS datum, |
1955
|
|
|
fv.visits AS visits, |
1956
|
|
|
fdg.group_id AS group_id, |
1957
|
|
|
fdu.user_id AS user_id |
1958
|
|
|
FROM |
1959
|
|
|
'.PMF_Db::getTablePrefix().'faqvisits fv, |
1960
|
|
|
'.PMF_Db::getTablePrefix().'faqdata fd |
1961
|
|
|
LEFT JOIN |
1962
|
|
|
'.PMF_Db::getTablePrefix().'faqcategoryrelations fcr |
1963
|
|
|
ON |
1964
|
|
|
fd.id = fcr.record_id |
1965
|
|
|
AND |
1966
|
|
|
fd.lang = fcr.record_lang |
1967
|
|
|
LEFT JOIN |
1968
|
|
|
'.PMF_Db::getTablePrefix().'faqdata_group AS fdg |
1969
|
|
|
ON |
1970
|
|
|
fd.id = fdg.record_id |
1971
|
|
|
LEFT JOIN |
1972
|
|
|
'.PMF_Db::getTablePrefix().'faqdata_user AS fdu |
1973
|
|
|
ON |
1974
|
|
|
fd.id = fdu.record_id |
1975
|
|
|
WHERE |
1976
|
|
|
fd.date_start <= \''.$now.'\' |
1977
|
|
|
AND fd.date_end >= \''.$now.'\' |
1978
|
|
|
AND fd.id = fv.id |
1979
|
|
|
AND fd.lang = fv.lang |
1980
|
|
|
AND fd.active = \'yes\''; |
1981
|
|
|
|
1982
|
|
|
if (isset($language) && PMF_Language::isASupportedLanguage($language)) { |
1983
|
|
|
$query .= ' |
1984
|
|
|
AND |
1985
|
|
|
fd.lang = \''.$language.'\''; |
1986
|
|
|
} |
1987
|
|
|
$query .= ' |
1988
|
|
|
' . $this->queryPermission($this->groupSupport) . ' |
1989
|
|
|
ORDER BY |
1990
|
|
|
fd.datum DESC'; |
1991
|
|
|
|
1992
|
|
|
$result = $this->_config->getDb()->query($query); |
1993
|
|
|
$latest = array(); |
1994
|
|
|
$data = array(); |
1995
|
|
|
|
1996
|
|
|
$i = 0; |
1997
|
|
|
$oldId = 0; |
1998
|
|
View Code Duplication |
while (($row = $this->_config->getDb()->fetchObject($result)) && $i < $count ) { |
1999
|
|
|
if ($oldId != $row->id) { |
2000
|
|
|
|
2001
|
|
|
if ($this->groupSupport) { |
2002
|
|
|
if (!in_array($row->user_id, array(-1, $this->user)) || !in_array($row->group_id, $this->groups)) { |
2003
|
|
|
continue; |
2004
|
|
|
} |
2005
|
|
|
} else { |
2006
|
|
|
if (!in_array($row->user_id, array(-1, $this->user))) { |
2007
|
|
|
continue; |
2008
|
|
|
} |
2009
|
|
|
} |
2010
|
|
|
|
2011
|
|
|
$data['datum'] = $row->datum; |
2012
|
|
|
$data['thema'] = $row->thema; |
2013
|
|
|
$data['content'] = $row->content; |
2014
|
|
|
$data['visits'] = $row->visits; |
2015
|
|
|
|
2016
|
|
|
$title = $row->thema; |
2017
|
|
|
$url = sprintf( |
2018
|
|
|
'%s?%saction=artikel&cat=%d&id=%d&artlang=%s', |
2019
|
|
|
PMF_Link::getSystemRelativeUri(), |
2020
|
|
|
$sids, |
2021
|
|
|
$row->category_id, |
2022
|
|
|
$row->id, |
2023
|
|
|
$row->lang |
2024
|
|
|
); |
2025
|
|
|
$oLink = new PMF_Link($url, $this->_config); |
2026
|
|
|
$oLink->itemTitle = $row->thema; |
2027
|
|
|
$oLink->tooltip = $title; |
2028
|
|
|
$data['url'] = $oLink->toString(); |
2029
|
|
|
|
2030
|
|
|
$latest[] = $data; |
2031
|
|
|
$i++; |
2032
|
|
|
} |
2033
|
|
|
$oldId = $row->id; |
2034
|
|
|
} |
2035
|
|
|
|
2036
|
|
|
return $latest; |
2037
|
|
|
} |
2038
|
|
|
|
2039
|
|
|
/** |
2040
|
|
|
* Reload locking for user votings |
2041
|
|
|
* |
2042
|
|
|
* @param integer $id FAQ record id |
2043
|
|
|
* @param string $ip IP |
2044
|
|
|
* @return boolean |
2045
|
|
|
*/ |
2046
|
|
|
public function votingCheck($id, $ip) |
2047
|
|
|
{ |
2048
|
|
|
$check = $_SERVER['REQUEST_TIME'] - 300; |
2049
|
|
|
$query = sprintf( |
2050
|
|
|
"SELECT |
2051
|
|
|
id |
2052
|
|
|
FROM |
2053
|
|
|
%sfaqvoting |
2054
|
|
|
WHERE |
2055
|
|
|
artikel = %d AND (ip = '%s' AND datum > '%s')", |
2056
|
|
|
PMF_Db::getTablePrefix(), |
2057
|
|
|
$id, |
2058
|
|
|
$ip, |
2059
|
|
|
$check); |
2060
|
|
|
if ($this->_config->getDb()->numRows($this->_config->getDb()->query($query))) { |
2061
|
|
|
return false; |
2062
|
|
|
} |
2063
|
|
|
return true; |
2064
|
|
|
} |
2065
|
|
|
|
2066
|
|
|
/** |
2067
|
|
|
* Returns the number of users from the table faqvotings |
2068
|
|
|
* |
2069
|
|
|
* @param integer $record_id |
2070
|
|
|
* @return integer |
2071
|
|
|
* @access public |
2072
|
|
|
* @since 2006-06-18 |
2073
|
|
|
* @author Thorsten Rinne <[email protected]> |
2074
|
|
|
*/ |
2075
|
|
View Code Duplication |
function getNumberOfVotings($record_id) |
2076
|
|
|
{ |
2077
|
|
|
$query = sprintf( |
2078
|
|
|
'SELECT |
2079
|
|
|
usr |
2080
|
|
|
FROM |
2081
|
|
|
%sfaqvoting |
2082
|
|
|
WHERE |
2083
|
|
|
artikel = %d', |
2084
|
|
|
PMF_Db::getTablePrefix(), |
2085
|
|
|
$record_id); |
2086
|
|
|
if ($result = $this->_config->getDb()->query($query)) { |
2087
|
|
|
if ($row = $this->_config->getDb()->fetchObject($result)) { |
2088
|
|
|
return $row->usr; |
2089
|
|
|
} |
2090
|
|
|
} |
2091
|
|
|
return 0; |
2092
|
|
|
} |
2093
|
|
|
|
2094
|
|
|
/** |
2095
|
|
|
* Adds a new voting record |
2096
|
|
|
* |
2097
|
|
|
* @param array $votingData |
2098
|
|
|
* @return boolean |
2099
|
|
|
* @access public |
2100
|
|
|
* @since 2006-06-18 |
2101
|
|
|
* @author Thorsten Rinne <[email protected]> |
2102
|
|
|
*/ |
2103
|
|
|
function addVoting($votingData) |
2104
|
|
|
{ |
2105
|
|
|
if (!is_array($votingData)) { |
2106
|
|
|
return false; |
2107
|
|
|
} |
2108
|
|
|
|
2109
|
|
|
$query = sprintf( |
2110
|
|
|
"INSERT INTO |
2111
|
|
|
%sfaqvoting |
2112
|
|
|
VALUES |
2113
|
|
|
(%d, %d, %d, 1, %d, '%s')", |
2114
|
|
|
PMF_Db::getTablePrefix(), |
2115
|
|
|
$this->_config->getDb()->nextId(PMF_Db::getTablePrefix().'faqvoting', 'id'), |
2116
|
|
|
$votingData['record_id'], |
2117
|
|
|
$votingData['vote'], |
2118
|
|
|
$_SERVER['REQUEST_TIME'], |
2119
|
|
|
$votingData['user_ip']); |
2120
|
|
|
$this->_config->getDb()->query($query); |
2121
|
|
|
|
2122
|
|
|
return true; |
2123
|
|
|
} |
2124
|
|
|
|
2125
|
|
|
/** |
2126
|
|
|
* Adds a new question |
2127
|
|
|
* |
2128
|
|
|
* @param array $questionData |
2129
|
|
|
* |
2130
|
|
|
* @return boolean |
2131
|
|
|
*/ |
2132
|
|
|
function addQuestion(Array $questionData) |
2133
|
|
|
{ |
2134
|
|
|
$query = sprintf(" |
2135
|
|
|
INSERT INTO |
2136
|
|
|
%sfaqquestions |
2137
|
|
|
VALUES |
2138
|
|
|
(%d, '%s', '%s', %d, '%s', '%s', '%s', %d)", |
2139
|
|
|
PMF_Db::getTablePrefix(), |
2140
|
|
|
$this->_config->getDb()->nextId(PMF_Db::getTablePrefix().'faqquestions', 'id'), |
2141
|
|
|
$this->_config->getDb()->escape($questionData['username']), |
2142
|
|
|
$this->_config->getDb()->escape($questionData['email']), |
2143
|
|
|
$questionData['category_id'], |
2144
|
|
|
$this->_config->getDb()->escape($questionData['question']), |
2145
|
|
|
date('YmdHis'), |
2146
|
|
|
$questionData['is_visible'], |
2147
|
|
|
0 |
2148
|
|
|
); |
2149
|
|
|
$this->_config->getDb()->query($query); |
2150
|
|
|
|
2151
|
|
|
return true; |
2152
|
|
|
} |
2153
|
|
|
|
2154
|
|
|
|
2155
|
|
|
/** |
2156
|
|
|
* Returns a new question |
2157
|
|
|
* |
2158
|
|
|
* @param integer $question_id |
2159
|
|
|
* @return array |
2160
|
|
|
* @access public |
2161
|
|
|
* @since 2006-11-11 |
2162
|
|
|
* @author Thorsten Rinne <[email protected]> |
2163
|
|
|
*/ |
2164
|
|
|
function getQuestion($id_question) |
2165
|
|
|
{ |
2166
|
|
|
$question = array( |
2167
|
|
|
'id' => 0, |
2168
|
|
|
'username' => '', |
2169
|
|
|
'email' => '', |
2170
|
|
|
'category_id' => '', |
2171
|
|
|
'question' => '', |
2172
|
|
|
'created' => '', |
2173
|
|
|
'is_visible' => ''); |
2174
|
|
|
|
2175
|
|
|
if (!is_int($id_question)) { |
2176
|
|
|
return $question; |
2177
|
|
|
} |
2178
|
|
|
|
2179
|
|
|
$question = array(); |
2180
|
|
|
|
2181
|
|
|
$query = sprintf(' |
2182
|
|
|
SELECT |
2183
|
|
|
id, username, email, category_id, question, created, is_visible |
2184
|
|
|
FROM |
2185
|
|
|
%sfaqquestions |
2186
|
|
|
WHERE |
2187
|
|
|
id = %d', |
2188
|
|
|
PMF_Db::getTablePrefix(), |
2189
|
|
|
$id_question); |
2190
|
|
|
|
2191
|
|
View Code Duplication |
if ($result = $this->_config->getDb()->query($query)) { |
2192
|
|
|
if ($row = $this->_config->getDb()->fetchObject($result)) { |
2193
|
|
|
$question = array( |
2194
|
|
|
'id' => $row->id, |
2195
|
|
|
'username' => $row->username, |
2196
|
|
|
'email' => $row->email, |
2197
|
|
|
'category_id' => $row->category_id, |
2198
|
|
|
'question' => $row->question, |
2199
|
|
|
'created' => $row->created, |
2200
|
|
|
'is_visible' => $row->is_visible); |
2201
|
|
|
} |
2202
|
|
|
} |
2203
|
|
|
|
2204
|
|
|
return $question; |
2205
|
|
|
} |
2206
|
|
|
|
2207
|
|
|
/** |
2208
|
|
|
* Returns all open questions |
2209
|
|
|
* |
2210
|
|
|
* @param $all boolean If true, then return visible and unvisble questions; otherwise only visible ones |
2211
|
|
|
* @return array |
2212
|
|
|
*/ |
2213
|
|
|
public function getAllOpenQuestions($all = true) |
2214
|
|
|
{ |
2215
|
|
|
$questions = array(); |
2216
|
|
|
|
2217
|
|
|
$query = sprintf(" |
2218
|
|
|
SELECT |
2219
|
|
|
id, username, email, category_id, question, created, answer_id, is_visible |
2220
|
|
|
FROM |
2221
|
|
|
%sfaqquestions |
2222
|
|
|
%s |
2223
|
|
|
ORDER BY |
2224
|
|
|
created ASC", |
2225
|
|
|
PMF_Db::getTablePrefix(), |
2226
|
|
|
($all == false ? "WHERE is_visible = 'Y'" : '')); |
2227
|
|
|
|
2228
|
|
View Code Duplication |
if ($result = $this->_config->getDb()->query($query)) { |
2229
|
|
|
while ($row = $this->_config->getDb()->fetchObject($result)) { |
2230
|
|
|
$questions[] = array( |
2231
|
|
|
'id' => $row->id, |
2232
|
|
|
'username' => $row->username, |
2233
|
|
|
'email' => $row->email, |
2234
|
|
|
'category_id' => $row->category_id, |
2235
|
|
|
'question' => $row->question, |
2236
|
|
|
'created' => $row->created, |
2237
|
|
|
'answer_id' => $row->answer_id, |
2238
|
|
|
'is_visible' => $row->is_visible |
2239
|
|
|
); |
2240
|
|
|
} |
2241
|
|
|
} |
2242
|
|
|
return $questions; |
2243
|
|
|
} |
2244
|
|
|
|
2245
|
|
|
/** |
2246
|
|
|
* Updates an existing voting record |
2247
|
|
|
* |
2248
|
|
|
* @param array $votingData |
2249
|
|
|
* @return boolean |
2250
|
|
|
* @access public |
2251
|
|
|
* @since 2006-06-18 |
2252
|
|
|
* @author Thorsten Rinne <[email protected]> |
2253
|
|
|
*/ |
2254
|
|
View Code Duplication |
function updateVoting($votingData) |
2255
|
|
|
{ |
2256
|
|
|
if (!is_array($votingData)) { |
2257
|
|
|
return false; |
2258
|
|
|
} |
2259
|
|
|
|
2260
|
|
|
$query = sprintf( |
2261
|
|
|
"UPDATE |
2262
|
|
|
%sfaqvoting |
2263
|
|
|
SET |
2264
|
|
|
vote = vote + %d, |
2265
|
|
|
usr = usr + 1, |
2266
|
|
|
datum = %d, |
2267
|
|
|
ip = '%s' |
2268
|
|
|
WHERE |
2269
|
|
|
artikel = %d", |
2270
|
|
|
PMF_Db::getTablePrefix(), |
2271
|
|
|
$votingData['vote'], |
2272
|
|
|
$_SERVER['REQUEST_TIME'], |
2273
|
|
|
$votingData['user_ip'], |
2274
|
|
|
$votingData['record_id']); |
2275
|
|
|
$this->_config->getDb()->query($query); |
2276
|
|
|
|
2277
|
|
|
return true; |
2278
|
|
|
} |
2279
|
|
|
|
2280
|
|
|
|
2281
|
|
|
/** |
2282
|
|
|
* Adds a new changelog entry in the table faqchanges |
2283
|
|
|
* |
2284
|
|
|
* @param integer $id |
2285
|
|
|
* @param integer $userId |
2286
|
|
|
* @param string $text |
2287
|
|
|
* @param string $lang |
2288
|
|
|
* @param integer $revision_id |
2289
|
|
|
* @return boolean |
2290
|
|
|
* @access private |
2291
|
|
|
* @since 2006-08-18 |
2292
|
|
|
* @author Thorsten Rinne <[email protected]> |
2293
|
|
|
* @author Matteo Scaramuccia <[email protected]> |
2294
|
|
|
*/ |
2295
|
|
|
function createChangeEntry($id, $userId, $text, $lang, $revision_id = 0) |
2296
|
|
|
{ |
2297
|
|
|
if ( !is_numeric($id) |
2298
|
|
|
&& !is_numeric($userId) |
2299
|
|
|
&& !is_string($text) |
2300
|
|
|
&& !is_string($lang) |
2301
|
|
|
) { |
2302
|
|
|
return false; |
2303
|
|
|
} |
2304
|
|
|
|
2305
|
|
|
$query = sprintf( |
2306
|
|
|
"INSERT INTO |
2307
|
|
|
%sfaqchanges |
2308
|
|
|
(id, beitrag, lang, revision_id, usr, datum, what) |
2309
|
|
|
VALUES |
2310
|
|
|
(%d, %d, '%s', %d, %d, %d, '%s')", |
2311
|
|
|
PMF_Db::getTablePrefix(), |
2312
|
|
|
$this->_config->getDb()->nextId(PMF_Db::getTablePrefix().'faqchanges', 'id'), |
2313
|
|
|
$id, |
2314
|
|
|
$lang, |
2315
|
|
|
$revision_id, |
2316
|
|
|
$userId, |
2317
|
|
|
$_SERVER['REQUEST_TIME'], |
2318
|
|
|
$text); |
2319
|
|
|
|
2320
|
|
|
$this->_config->getDb()->query($query); |
2321
|
|
|
|
2322
|
|
|
return true; |
2323
|
|
|
} |
2324
|
|
|
|
2325
|
|
|
/** |
2326
|
|
|
* Returns the changelog of a FAQ record |
2327
|
|
|
* |
2328
|
|
|
* @param integer $record_id |
2329
|
|
|
* @return array |
2330
|
|
|
* @access public |
2331
|
|
|
* @since 2007-03-03 |
2332
|
|
|
* @author Thorsten Rinne <[email protected]> |
2333
|
|
|
*/ |
2334
|
|
View Code Duplication |
function getChangeEntries($record_id) |
2335
|
|
|
{ |
2336
|
|
|
$entries = array(); |
2337
|
|
|
|
2338
|
|
|
$query = sprintf(" |
2339
|
|
|
SELECT |
2340
|
|
|
DISTINCT revision_id, usr, datum, what |
2341
|
|
|
FROM |
2342
|
|
|
%sfaqchanges |
2343
|
|
|
WHERE |
2344
|
|
|
beitrag = %d |
2345
|
|
|
ORDER BY id DESC", |
2346
|
|
|
PMF_Db::getTablePrefix(), |
2347
|
|
|
$record_id |
2348
|
|
|
); |
2349
|
|
|
|
2350
|
|
|
if ($result = $this->_config->getDb()->query($query)) { |
2351
|
|
|
while ($row = $this->_config->getDb()->fetchObject($result)) { |
2352
|
|
|
$entries[] = array( |
2353
|
|
|
'revision_id' => $row->revision_id, |
2354
|
|
|
'user' => $row->usr, |
2355
|
|
|
'date' => $row->datum, |
2356
|
|
|
'changelog' => $row->what); |
2357
|
|
|
} |
2358
|
|
|
} |
2359
|
|
|
|
2360
|
|
|
return $entries; |
2361
|
|
|
} |
2362
|
|
|
|
2363
|
|
|
/** |
2364
|
|
|
* Retrieve faq records according to the constraints provided |
2365
|
|
|
* |
2366
|
|
|
* @param string $QueryType |
2367
|
|
|
* @param integer $nCatid |
2368
|
|
|
* @param bool $bDownwards |
2369
|
|
|
* @param string $lang |
2370
|
|
|
* @param string $date |
2371
|
|
|
* |
2372
|
|
|
* @return array |
2373
|
|
|
*/ |
2374
|
|
|
function get($QueryType = FAQ_QUERY_TYPE_DEFAULT, $nCatid = 0, $bDownwards = true, $lang = '', $date = '') |
2375
|
|
|
{ |
2376
|
|
|
$faqs = array(); |
2377
|
|
|
|
2378
|
|
|
$result = $this->_config->getDb()->query($this->_getSQLQuery($QueryType, $nCatid, $bDownwards, $lang, $date)); |
2379
|
|
|
|
2380
|
|
|
if ($this->_config->getDb()->numRows($result) > 0) { |
2381
|
|
|
$i = 0; |
2382
|
|
|
while ($row = $this->_config->getDb()->fetchObject($result)) { |
2383
|
|
|
$faq = array(); |
2384
|
|
|
$faq['id'] = $row->id; |
2385
|
|
|
$faq['solution_id'] = $row->solution_id; |
2386
|
|
|
$faq['revision_id'] = $row->revision_id; |
2387
|
|
|
$faq['lang'] = $row->lang; |
2388
|
|
|
$faq['category_id'] = $row->category_id; |
2389
|
|
|
$faq['active'] = $row->active; |
2390
|
|
|
$faq['sticky'] = $row->sticky; |
2391
|
|
|
$faq['keywords'] = $row->keywords; |
2392
|
|
|
$faq['topic'] = $row->thema; |
2393
|
|
|
$faq['content'] = $row->content; |
2394
|
|
|
$faq['author_name'] = $row->author; |
2395
|
|
|
$faq['author_email'] = $row->email; |
2396
|
|
|
$faq['comment_enable'] = $row->comment; |
2397
|
|
|
$faq['lastmodified'] = $row->datum; |
2398
|
|
|
$faq['hits'] = $row->visits; |
2399
|
|
|
$faq['hits_last'] = $row->last_visit; |
2400
|
|
|
$faqs[$i] = $faq; |
2401
|
|
|
$i++; |
2402
|
|
|
} |
2403
|
|
|
} |
2404
|
|
|
|
2405
|
|
|
return $faqs; |
2406
|
|
|
} |
2407
|
|
|
|
2408
|
|
|
/** |
2409
|
|
|
* Build a logic sequence, for a WHERE statement, of those category IDs |
2410
|
|
|
* children of the provided category ID, if any |
2411
|
|
|
* |
2412
|
|
|
* @param $nCatid |
2413
|
|
|
* @param $logicOp |
2414
|
|
|
* @param $oCat |
2415
|
|
|
* @return string |
2416
|
|
|
* @access private |
2417
|
|
|
* @since 2005-11-02 |
2418
|
|
|
* @author Matteo Scaramuccia <[email protected]> |
2419
|
|
|
*/ |
2420
|
|
|
function _getCatidWhereSequence($nCatid, $logicOp = 'OR', $oCat = null) |
2421
|
|
|
{ |
2422
|
|
|
$sqlWherefilter = ''; |
2423
|
|
|
|
2424
|
|
|
if (!isset($oCat)) { |
2425
|
|
|
$oCat = new PMF_Category($this->_config); |
2426
|
|
|
} |
2427
|
|
|
$aChildren = array_values($oCat->getChildren($nCatid)); |
2428
|
|
|
|
2429
|
|
|
foreach ($aChildren as $catid) { |
2430
|
|
|
$sqlWherefilter .= " ".$logicOp." fcr.category_id = ".$catid; |
2431
|
|
|
$sqlWherefilter .= $this->_getCatidWhereSequence($catid, 'OR', $oCat); |
2432
|
|
|
} |
2433
|
|
|
|
2434
|
|
|
return $sqlWherefilter; |
2435
|
|
|
} |
2436
|
|
|
|
2437
|
|
|
/** |
2438
|
|
|
* Build the SQL query for retrieving faq records according to the constraints provided |
2439
|
|
|
* |
2440
|
|
|
* @param $QueryType |
2441
|
|
|
* @param $nCatid |
2442
|
|
|
* @param $bDownwards |
2443
|
|
|
* @param $lang |
2444
|
|
|
* @param $date |
2445
|
|
|
* @param $faqid |
2446
|
|
|
* @return array |
2447
|
|
|
* @access private |
2448
|
|
|
* @since 2005-11-02 |
2449
|
|
|
* @author Matteo Scaramuccia <[email protected]> |
2450
|
|
|
*/ |
2451
|
|
|
private function _getSQLQuery($QueryType, $nCatid, $bDownwards, $lang, $date, $faqid = 0) |
2452
|
|
|
{ |
2453
|
|
|
$now = date('YmdHis'); |
2454
|
|
|
$query = sprintf(" |
2455
|
|
|
SELECT |
2456
|
|
|
fd.id AS id, |
2457
|
|
|
fd.solution_id AS solution_id, |
2458
|
|
|
fd.revision_id AS revision_id, |
2459
|
|
|
fd.lang AS lang, |
2460
|
|
|
fcr.category_id AS category_id, |
2461
|
|
|
fd.active AS active, |
2462
|
|
|
fd.sticky AS sticky, |
2463
|
|
|
fd.keywords AS keywords, |
2464
|
|
|
fd.thema AS thema, |
2465
|
|
|
fd.content AS content, |
2466
|
|
|
fd.author AS author, |
2467
|
|
|
fd.email AS email, |
2468
|
|
|
fd.comment AS comment, |
2469
|
|
|
fd.datum AS datum, |
2470
|
|
|
fv.visits AS visits, |
2471
|
|
|
fv.last_visit AS last_visit |
2472
|
|
|
FROM |
2473
|
|
|
%sfaqdata fd, |
2474
|
|
|
%sfaqvisits fv, |
2475
|
|
|
%sfaqcategoryrelations fcr |
2476
|
|
|
WHERE |
2477
|
|
|
fd.id = fcr.record_id |
2478
|
|
|
AND |
2479
|
|
|
fd.lang = fcr.record_lang |
2480
|
|
|
AND |
2481
|
|
|
fd.date_start <= '%s' |
2482
|
|
|
AND |
2483
|
|
|
fd.date_end >= '%s' |
2484
|
|
|
AND ", |
2485
|
|
|
PMF_Db::getTablePrefix(), |
2486
|
|
|
PMF_Db::getTablePrefix(), |
2487
|
|
|
PMF_Db::getTablePrefix(), |
2488
|
|
|
$now, |
2489
|
|
|
$now); |
2490
|
|
|
// faqvisits data selection |
2491
|
|
|
if (!empty($faqid)) { |
2492
|
|
|
// Select ONLY the faq with the provided $faqid |
2493
|
|
|
$query .= "fd.id = '".$faqid."' AND "; |
2494
|
|
|
} |
2495
|
|
|
$query .= "fd.id = fv.id |
2496
|
|
|
AND |
2497
|
|
|
fd.lang = fv.lang"; |
2498
|
|
|
$needAndOp = true; |
2499
|
|
|
if ((!empty($nCatid)) && is_int($nCatid) && $nCatid > 0) { |
2500
|
|
|
if ($needAndOp) { |
2501
|
|
|
$query .= " AND"; |
2502
|
|
|
} |
2503
|
|
|
$query .= " (fcr.category_id = ".$nCatid; |
2504
|
|
|
if ($bDownwards) { |
2505
|
|
|
$query .= $this->_getCatidWhereSequence($nCatid, "OR"); |
2506
|
|
|
} |
2507
|
|
|
$query .= ")"; |
2508
|
|
|
$needAndOp = true; |
2509
|
|
|
} |
2510
|
|
View Code Duplication |
if ((!empty($date)) && PMF_Utils::isLikeOnPMFDate($date)) { |
2511
|
|
|
if ($needAndOp) { |
2512
|
|
|
$query .= " AND"; |
2513
|
|
|
} |
2514
|
|
|
$query .= " fd.datum LIKE '".$date."'"; |
2515
|
|
|
$needAndOp = true; |
2516
|
|
|
} |
2517
|
|
View Code Duplication |
if ((!empty($lang)) && PMF_Utils::isLanguage($lang)) { |
2518
|
|
|
if ($needAndOp) { |
2519
|
|
|
$query .= " AND"; |
2520
|
|
|
} |
2521
|
|
|
$query .= " fd.lang = '".$lang."'"; |
2522
|
|
|
$needAndOp = true; |
2523
|
|
|
} |
2524
|
|
|
switch ($QueryType) { |
2525
|
|
|
case FAQ_QUERY_TYPE_APPROVAL: |
2526
|
|
|
if ($needAndOp) { |
2527
|
|
|
$query .= " AND"; |
2528
|
|
|
} |
2529
|
|
|
$query .= " fd.active = '".FAQ_SQL_ACTIVE_NO."'"; |
2530
|
|
|
$needAndOp = true; |
2531
|
|
|
break; |
2532
|
|
|
case FAQ_QUERY_TYPE_EXPORT_PDF: |
2533
|
|
|
case FAQ_QUERY_TYPE_EXPORT_XHTML: |
2534
|
|
View Code Duplication |
case FAQ_QUERY_TYPE_EXPORT_XML: |
2535
|
|
|
if ($needAndOp) { |
2536
|
|
|
$query .= " AND"; |
2537
|
|
|
} |
2538
|
|
|
$query .= " fd.active = '".FAQ_SQL_ACTIVE_YES."'"; |
2539
|
|
|
$needAndOp = true; |
2540
|
|
|
break; |
2541
|
|
View Code Duplication |
default: |
2542
|
|
|
if ($needAndOp) { |
2543
|
|
|
$query .= " AND"; |
2544
|
|
|
} |
2545
|
|
|
$query .= " fd.active = '".FAQ_SQL_ACTIVE_YES."'"; |
2546
|
|
|
$needAndOp = true; |
2547
|
|
|
break; |
2548
|
|
|
} |
2549
|
|
|
// Sort criteria |
2550
|
|
|
switch ($QueryType) { |
2551
|
|
|
case FAQ_QUERY_TYPE_EXPORT_PDF: |
2552
|
|
|
case FAQ_QUERY_TYPE_EXPORT_XHTML: |
2553
|
|
|
case FAQ_QUERY_TYPE_EXPORT_XML: |
2554
|
|
|
$query .= "\nORDER BY fcr.category_id, fd.id"; |
2555
|
|
|
break; |
2556
|
|
|
case FAQ_QUERY_TYPE_RSS_LATEST: |
2557
|
|
|
$query .= "\nORDER BY fd.datum DESC"; |
2558
|
|
|
break; |
2559
|
|
|
default: |
2560
|
|
|
// Normal ordering |
2561
|
|
|
$query .= "\nORDER BY fcr.category_id, fd.id"; |
2562
|
|
|
break; |
2563
|
|
|
} |
2564
|
|
|
|
2565
|
|
|
return $query; |
2566
|
|
|
} |
2567
|
|
|
|
2568
|
|
|
/** |
2569
|
|
|
* Adds the record permissions for users and groups |
2570
|
|
|
* |
2571
|
|
|
* @param string $mode 'group' or 'user' |
2572
|
|
|
* @param integer $recordId ID of the current record |
2573
|
|
|
* @param array $ids Array of group or user IDs |
2574
|
|
|
* |
2575
|
|
|
* @return boolean |
2576
|
|
|
*/ |
2577
|
|
|
function addPermission($mode, $recordId, $ids) |
2578
|
|
|
{ |
2579
|
|
|
if ('user' !== $mode && 'group' !== $mode) { |
2580
|
|
|
return false; |
2581
|
|
|
} |
2582
|
|
|
|
2583
|
|
|
foreach ($ids as $id) { |
2584
|
|
|
$query = sprintf(" |
2585
|
|
|
INSERT INTO |
2586
|
|
|
%sfaqdata_%s |
2587
|
|
|
(record_id, %s_id) |
2588
|
|
|
VALUES |
2589
|
|
|
(%d, %d)", |
2590
|
|
|
PMF_Db::getTablePrefix(), |
2591
|
|
|
$mode, |
2592
|
|
|
$mode, |
2593
|
|
|
$recordId, |
2594
|
|
|
$id |
2595
|
|
|
); |
2596
|
|
|
|
2597
|
|
|
$this->_config->getDb()->query($query); |
2598
|
|
|
} |
2599
|
|
|
|
2600
|
|
|
return true; |
2601
|
|
|
} |
2602
|
|
|
|
2603
|
|
|
/** |
2604
|
|
|
* Deletes the record permissions for users and groups |
2605
|
|
|
* |
2606
|
|
|
* @param string $mode 'group' or 'user' |
2607
|
|
|
* @param integer $record_id ID of the current record |
2608
|
|
|
* @return boolean |
2609
|
|
|
* @access public |
2610
|
|
|
* @author Thorsten Rinne <[email protected]> |
2611
|
|
|
*/ |
2612
|
|
View Code Duplication |
function deletePermission($mode, $record_id) |
2613
|
|
|
{ |
2614
|
|
|
if (!($mode == "user" || $mode == "group")) { |
2615
|
|
|
return false; |
2616
|
|
|
} |
2617
|
|
|
if (!is_int($record_id)) { |
2618
|
|
|
return false; |
2619
|
|
|
} |
2620
|
|
|
|
2621
|
|
|
$query = sprintf(" |
2622
|
|
|
DELETE FROM |
2623
|
|
|
%sfaqdata_%s |
2624
|
|
|
WHERE |
2625
|
|
|
record_id = %d", |
2626
|
|
|
PMF_Db::getTablePrefix(), |
2627
|
|
|
$mode, |
2628
|
|
|
$record_id); |
2629
|
|
|
$this->_config->getDb()->query($query); |
2630
|
|
|
|
2631
|
|
|
return true; |
2632
|
|
|
} |
2633
|
|
|
|
2634
|
|
|
/** |
2635
|
|
|
* Returns the record permissions for users and groups |
2636
|
|
|
* |
2637
|
|
|
* @param string $mode 'group' or 'user' |
2638
|
|
|
* @param integer $recordId |
2639
|
|
|
* @return array |
2640
|
|
|
* @access boolean |
2641
|
|
|
* @author Thorsten Rinne <[email protected]> |
2642
|
|
|
*/ |
2643
|
|
|
function getPermission($mode, $recordId) |
2644
|
|
|
{ |
2645
|
|
|
$permissions = array(); |
2646
|
|
|
|
2647
|
|
|
if (!($mode == 'user' || $mode == 'group')) { |
2648
|
|
|
return false; |
2649
|
|
|
} |
2650
|
|
|
|
2651
|
|
|
$query = sprintf(" |
2652
|
|
|
SELECT |
2653
|
|
|
%s_id AS permission |
2654
|
|
|
FROM |
2655
|
|
|
%sfaqdata_%s |
2656
|
|
|
WHERE |
2657
|
|
|
record_id = %d", |
2658
|
|
|
$mode, |
2659
|
|
|
PMF_Db::getTablePrefix(), |
2660
|
|
|
$mode, |
2661
|
|
|
(int)$recordId); |
2662
|
|
|
|
2663
|
|
|
$result = $this->_config->getDb()->query($query); |
2664
|
|
|
|
2665
|
|
|
if ($this->_config->getDb()->numRows($result) > 0) { |
2666
|
|
|
while (($row = $this->_config->getDb()->fetchObject($result))) { |
2667
|
|
|
$permissions[] = (int)$row->permission; |
2668
|
|
|
} |
2669
|
|
|
} |
2670
|
|
|
|
2671
|
|
|
return $permissions; |
2672
|
|
|
} |
2673
|
|
|
|
2674
|
|
|
/** |
2675
|
|
|
* Returns all records of one category |
2676
|
|
|
* |
2677
|
|
|
* @param integer $category |
2678
|
|
|
* @return string |
2679
|
|
|
* @access public |
2680
|
|
|
* @since 2007-04-04 |
2681
|
|
|
* @author Georgi Korchev <[email protected]> |
2682
|
|
|
*/ |
2683
|
|
|
function showAllRecordsWoPaging($category) { |
2684
|
|
|
|
2685
|
|
|
global $sids; |
2686
|
|
|
|
2687
|
|
|
$now = date('YmdHis'); |
2688
|
|
|
$query = ' |
2689
|
|
|
SELECT |
2690
|
|
|
fd.id AS id, |
2691
|
|
|
fd.lang AS lang, |
2692
|
|
|
fd.thema AS thema, |
2693
|
|
|
fcr.category_id AS category_id, |
2694
|
|
|
fv.visits AS visits |
2695
|
|
|
FROM |
2696
|
|
|
'.PMF_Db::getTablePrefix().'faqdata fd |
2697
|
|
|
LEFT JOIN |
2698
|
|
|
'.PMF_Db::getTablePrefix().'faqcategoryrelations fcr |
2699
|
|
|
ON |
2700
|
|
|
fd.id = fcr.record_id |
2701
|
|
|
AND |
2702
|
|
|
fd.lang = fcr.record_lang |
2703
|
|
|
LEFT JOIN |
2704
|
|
|
'.PMF_Db::getTablePrefix().'faqvisits fv |
2705
|
|
|
ON |
2706
|
|
|
fd.id = fv.id |
2707
|
|
|
AND |
2708
|
|
|
fv.lang = fd.lang |
2709
|
|
|
LEFT JOIN |
2710
|
|
|
'.PMF_Db::getTablePrefix().'faqdata_group fdg |
2711
|
|
|
ON |
2712
|
|
|
fd.id = fdg.record_id |
2713
|
|
|
LEFT JOIN |
2714
|
|
|
'.PMF_Db::getTablePrefix().'faqdata_user fdu |
2715
|
|
|
ON |
2716
|
|
|
fd.id = fdu.record_id |
2717
|
|
|
WHERE |
2718
|
|
|
fd.date_start <= \''.$now.'\' |
2719
|
|
|
AND |
2720
|
|
|
fd.date_end >= \''.$now.'\' |
2721
|
|
|
AND |
2722
|
|
|
fd.active = \'yes\' |
2723
|
|
|
AND |
2724
|
|
|
fcr.category_id = '.$category.' |
2725
|
|
|
AND |
2726
|
|
|
fd.lang = \''.$this->_config->getLanguage()->getLanguage().'\' |
2727
|
|
|
ORDER BY |
2728
|
|
|
fd.id'; |
2729
|
|
|
|
2730
|
|
|
$result = $this->_config->getDb()->query($query); |
2731
|
|
|
|
2732
|
|
|
$output = '<ul class="phpmyfaq_ul">'; |
2733
|
|
|
|
2734
|
|
|
while (($row = $this->_config->getDb()->fetchObject($result))) { |
2735
|
|
|
$title = $row->thema; |
2736
|
|
|
$url = sprintf( |
2737
|
|
|
'%s?%saction=artikel&cat=%d&id=%d&artlang=%s', |
2738
|
|
|
PMF_Link::getSystemRelativeUri(), |
2739
|
|
|
$sids, |
2740
|
|
|
$row->category_id, |
2741
|
|
|
$row->id, |
2742
|
|
|
$row->lang |
2743
|
|
|
); |
2744
|
|
|
|
2745
|
|
|
$oLink = new PMF_Link($url, $this->_config); |
2746
|
|
|
$oLink->itemTitle = $row->thema; |
2747
|
|
|
$oLink->text = $title; |
2748
|
|
|
$oLink->tooltip = $title; |
2749
|
|
|
$listItem = sprintf('<li>%s</li>', $oLink->toHtmlAnchor(), $this->pmf_lang['msgViews']); |
2750
|
|
|
$listItem = '<li>'.$oLink->toHtmlAnchor().'</li>'; |
2751
|
|
|
|
2752
|
|
|
$output .= $listItem; |
2753
|
|
|
} |
2754
|
|
|
|
2755
|
|
|
$output .= '</ul>'; |
2756
|
|
|
|
2757
|
|
|
return $output; |
2758
|
|
|
} |
2759
|
|
|
|
2760
|
|
|
/** |
2761
|
|
|
* Prints the open questions as a XHTML table |
2762
|
|
|
* |
2763
|
|
|
* @return string |
2764
|
|
|
* @access public |
2765
|
|
|
* @since 2002-09-17 |
2766
|
|
|
* @author Thorsten Rinne <[email protected]> |
2767
|
|
|
*/ |
2768
|
|
|
function printOpenQuestions() |
2769
|
|
|
{ |
2770
|
|
|
global $sids, $category; |
2771
|
|
|
|
2772
|
|
|
$date = new PMF_Date($this->_config); |
2773
|
|
|
$mail = new PMF_Mail($this->_config); |
2774
|
|
|
|
2775
|
|
|
$query = sprintf(" |
2776
|
|
|
SELECT |
2777
|
|
|
COUNT(id) AS num |
2778
|
|
|
FROM |
2779
|
|
|
%sfaqquestions |
2780
|
|
|
WHERE |
2781
|
|
|
is_visible != 'Y'", |
2782
|
|
|
PMF_Db::getTablePrefix() |
2783
|
|
|
); |
2784
|
|
|
|
2785
|
|
|
$result = $this->_config->getDb()->query($query); |
2786
|
|
|
$row = $this->_config->getDb()->fetchObject($result); |
2787
|
|
|
$numOfInvisibles = $row->num; |
2788
|
|
|
|
2789
|
|
|
if ($numOfInvisibles > 0) { |
2790
|
|
|
$extraout = sprintf( |
2791
|
|
|
'<tr><td colspan="3"><small>%s %s</small></td></tr>', |
2792
|
|
|
$this->pmf_lang['msgQuestionsWaiting'], |
2793
|
|
|
$numOfInvisibles |
2794
|
|
|
); |
2795
|
|
|
} else { |
2796
|
|
|
$extraout = ''; |
2797
|
|
|
} |
2798
|
|
|
|
2799
|
|
|
$query = sprintf(" |
2800
|
|
|
SELECT |
2801
|
|
|
* |
2802
|
|
|
FROM |
2803
|
|
|
%sfaqquestions |
2804
|
|
|
WHERE |
2805
|
|
|
is_visible = 'Y' |
2806
|
|
|
ORDER BY |
2807
|
|
|
created ASC", |
2808
|
|
|
PMF_Db::getTablePrefix() |
2809
|
|
|
); |
2810
|
|
|
|
2811
|
|
|
$result = $this->_config->getDb()->query($query); |
2812
|
|
|
$output = ''; |
2813
|
|
|
|
2814
|
|
|
if ($result && $this->_config->getDb()->numRows($result) > 0) { |
2815
|
|
|
while ($row = $this->_config->getDb()->fetchObject($result)) { |
2816
|
|
|
$output .= '<tr class="openquestions">'; |
2817
|
|
|
$output .= sprintf( |
2818
|
|
|
'<td><small>%s</small><br /><a href="mailto:%s">%s</a></td>', |
2819
|
|
|
$date->format(PMF_Date::createIsoDate($row->created)), |
2820
|
|
|
$mail->safeEmail($row->email), |
2821
|
|
|
$row->username |
2822
|
|
|
); |
2823
|
|
|
$output .= sprintf( |
2824
|
|
|
'<td><strong>%s:</strong><br />%s</td>', |
2825
|
|
|
isset($category->categoryName[$row->category_id]['name']) ? $category->categoryName[$row->category_id]['name'] : '', |
2826
|
|
|
strip_tags($row->question) |
2827
|
|
|
); |
2828
|
|
|
if ($this->_config->get('records.enableCloseQuestion') && $row->answer_id) { |
2829
|
|
|
$output .= sprintf( |
2830
|
|
|
'<td><a id="PMF_openQuestionAnswered" href="?%saction=artikel&cat=%d&id=%d">%s</a></td>', |
2831
|
|
|
$sids, |
2832
|
|
|
$row->category_id, |
2833
|
|
|
$row->answer_id, |
2834
|
|
|
$this->pmf_lang['msg2answerFAQ'] |
2835
|
|
|
); |
2836
|
|
|
} else { |
2837
|
|
|
$output .= sprintf( |
2838
|
|
|
'<td><a class="btn btn-primary" href="?%saction=add&question=%d&cat=%d">%s</a></td>', |
2839
|
|
|
$sids, |
2840
|
|
|
$row->id, |
2841
|
|
|
$row->category_id, |
2842
|
|
|
$this->pmf_lang['msg2answer'] |
2843
|
|
|
); |
2844
|
|
|
} |
2845
|
|
|
$output .= '</tr>'; |
2846
|
|
|
} |
2847
|
|
|
} else { |
2848
|
|
|
$output = sprintf( |
2849
|
|
|
'<tr><td colspan="3">%s</td></tr>', |
2850
|
|
|
$this->pmf_lang['msgNoQuestionsAvailable'] |
2851
|
|
|
); |
2852
|
|
|
} |
2853
|
|
|
|
2854
|
|
|
return $output . $extraout; |
2855
|
|
|
} |
2856
|
|
|
|
2857
|
|
|
/** |
2858
|
|
|
* Set or unset a faq item flag |
2859
|
|
|
* |
2860
|
|
|
* @param integer $id Record id |
2861
|
|
|
* @param string $lang language code which is valid with Language::isASupportedLanguage |
2862
|
|
|
* @param boolean $flag weither or not the record is set to sticky |
2863
|
|
|
* @param string $type type of the flag to set, use the column name |
2864
|
|
|
* |
2865
|
|
|
* @return boolean |
2866
|
|
|
*/ |
2867
|
|
|
public function updateRecordFlag($id, $lang, $flag, $type) |
2868
|
|
|
{ |
2869
|
|
|
$retval = false; |
2870
|
|
|
|
2871
|
|
|
switch ($type) { |
2872
|
|
|
case 'sticky': |
2873
|
|
|
$flag = ($flag === 'checked' ? 1 : 0); |
2874
|
|
|
break; |
2875
|
|
|
|
2876
|
|
|
case 'active': |
2877
|
|
|
$flag = ($flag === 'checked' ? "'yes'" : "'no'"); |
2878
|
|
|
break; |
2879
|
|
|
|
2880
|
|
|
default: |
2881
|
|
|
// This is because we would run into unknown db column |
2882
|
|
|
$flag = null; |
2883
|
|
|
break; |
2884
|
|
|
} |
2885
|
|
|
|
2886
|
|
|
if (null !== $flag) { |
2887
|
|
|
|
2888
|
|
|
$update = sprintf(" |
2889
|
|
|
UPDATE |
2890
|
|
|
%sfaqdata |
2891
|
|
|
SET |
2892
|
|
|
%s = %s |
2893
|
|
|
WHERE |
2894
|
|
|
id = %d |
2895
|
|
|
AND |
2896
|
|
|
lang = '%s'", |
2897
|
|
|
PMF_Db::getTablePrefix(), |
2898
|
|
|
$type, |
2899
|
|
|
$flag, |
2900
|
|
|
$id, |
2901
|
|
|
$lang |
2902
|
|
|
); |
2903
|
|
|
|
2904
|
|
|
$retval = (bool)$this->_config->getDb()->query($update); |
2905
|
|
|
|
2906
|
|
|
} |
2907
|
|
|
|
2908
|
|
|
return $retval; |
2909
|
|
|
} |
2910
|
|
|
|
2911
|
|
|
/** |
2912
|
|
|
* Returns the sticky records with URL and Title |
2913
|
|
|
* |
2914
|
|
|
* @return array |
2915
|
|
|
*/ |
2916
|
|
|
private function getStickyRecordsData() |
2917
|
|
|
{ |
2918
|
|
|
global $sids; |
2919
|
|
|
|
2920
|
|
|
$now = date('YmdHis'); |
2921
|
|
|
$query = sprintf(" |
2922
|
|
|
SELECT |
2923
|
|
|
fd.id AS id, |
2924
|
|
|
fd.lang AS lang, |
2925
|
|
|
fd.thema AS thema, |
2926
|
|
|
fcr.category_id AS category_id |
2927
|
|
|
FROM |
2928
|
|
|
%sfaqdata fd |
2929
|
|
|
LEFT JOIN |
2930
|
|
|
%sfaqcategoryrelations fcr |
2931
|
|
|
ON |
2932
|
|
|
fd.id = fcr.record_id |
2933
|
|
|
AND |
2934
|
|
|
fd.lang = fcr.record_lang |
2935
|
|
|
LEFT JOIN |
2936
|
|
|
%sfaqdata_group AS fdg |
2937
|
|
|
ON |
2938
|
|
|
fd.id = fdg.record_id |
2939
|
|
|
LEFT JOIN |
2940
|
|
|
%sfaqdata_user AS fdu |
2941
|
|
|
ON |
2942
|
|
|
fd.id = fdu.record_id |
2943
|
|
|
WHERE |
2944
|
|
|
fd.lang = '%s' |
2945
|
|
|
AND |
2946
|
|
|
fd.date_start <= '%s' |
2947
|
|
|
AND |
2948
|
|
|
fd.date_end >= '%s' |
2949
|
|
|
AND |
2950
|
|
|
fd.active = 'yes' |
2951
|
|
|
AND |
2952
|
|
|
fd.sticky = 1 |
2953
|
|
|
%s", |
2954
|
|
|
PMF_Db::getTablePrefix(), |
2955
|
|
|
PMF_Db::getTablePrefix(), |
2956
|
|
|
PMF_Db::getTablePrefix(), |
2957
|
|
|
PMF_Db::getTablePrefix(), |
2958
|
|
|
$this->_config->getLanguage()->getLanguage(), |
2959
|
|
|
$now, |
2960
|
|
|
$now, |
2961
|
|
|
$this->queryPermission($this->groupSupport) |
2962
|
|
|
); |
2963
|
|
|
|
2964
|
|
|
$result = $this->_config->getDb()->query($query); |
2965
|
|
|
$sticky = array(); |
2966
|
|
|
$data = array(); |
2967
|
|
|
|
2968
|
|
|
$oldId = 0; |
2969
|
|
|
while (($row = $this->_config->getDb()->fetchObject($result))) { |
2970
|
|
|
if ($oldId != $row->id) { |
2971
|
|
|
$data['thema'] = $row->thema; |
2972
|
|
|
|
2973
|
|
|
$title = $row->thema; |
2974
|
|
|
$url = sprintf( |
2975
|
|
|
'%s?%saction=artikel&cat=%d&id=%d&artlang=%s', |
2976
|
|
|
PMF_Link::getSystemRelativeUri(), |
2977
|
|
|
$sids, |
2978
|
|
|
$row->category_id, |
2979
|
|
|
$row->id, |
2980
|
|
|
$row->lang |
2981
|
|
|
); |
2982
|
|
|
$oLink = new PMF_Link($url, $this->_config); |
2983
|
|
|
$oLink->itemTitle = $row->thema; |
2984
|
|
|
$oLink->tooltip = $title; |
2985
|
|
|
$data['url'] = $oLink->toString(); |
2986
|
|
|
|
2987
|
|
|
$sticky[] = $data; |
2988
|
|
|
} |
2989
|
|
|
$oldId = $row->id; |
2990
|
|
|
} |
2991
|
|
|
|
2992
|
|
|
return $sticky; |
2993
|
|
|
} |
2994
|
|
|
|
2995
|
|
|
/** |
2996
|
|
|
* Prepares and returns the sticky records for the frontend |
2997
|
|
|
* |
2998
|
|
|
* @return array |
2999
|
|
|
*/ |
3000
|
|
|
public function getStickyRecords() |
3001
|
|
|
{ |
3002
|
|
|
$result = $this->getStickyRecordsData(); |
3003
|
|
|
$output = array(); |
3004
|
|
|
|
3005
|
|
|
if (count($result) > 0) { |
3006
|
|
|
foreach ($result as $row) { |
3007
|
|
|
$output[] = array( |
3008
|
|
|
'title' => PMF_Utils::makeShorterText($row['thema'], 8), |
3009
|
|
|
'url' => $row['url'] |
3010
|
|
|
); |
3011
|
|
|
} |
3012
|
|
|
} else { |
3013
|
|
|
$output['error'] = sprintf('<li>%s</li>', $this->pmf_lang['err_noTopTen']); |
3014
|
|
|
} |
3015
|
|
|
if (!isset($output['error'])) { |
3016
|
|
|
$html = ''; |
3017
|
|
|
foreach ($output as $entry) { |
3018
|
|
|
$html .= sprintf( |
3019
|
|
|
'<li><a href="%s">%s</a></li>', |
3020
|
|
|
$entry['url'], |
3021
|
|
|
$entry['title'] |
3022
|
|
|
); |
3023
|
|
|
} |
3024
|
|
|
$output['html'] = $html; |
3025
|
|
|
} |
3026
|
|
|
return $output; |
3027
|
|
|
} |
3028
|
|
|
|
3029
|
|
|
/** |
3030
|
|
|
* Updates field answer_id in faqquestion |
3031
|
|
|
* |
3032
|
|
|
* @param integer $openQuestionId |
3033
|
|
|
* @param integer $faqId |
3034
|
|
|
* @param integer $categoryId |
3035
|
|
|
* |
3036
|
|
|
* @return boolean |
3037
|
|
|
*/ |
3038
|
|
View Code Duplication |
public function updateQuestionAnswer($openQuestionId, $faqId, $categoryId) |
3039
|
|
|
{ |
3040
|
|
|
$query = sprintf( |
3041
|
|
|
'UPDATE %sfaqquestions SET answer_id = %d, category_id= %d, WHERE id= %d', |
3042
|
|
|
PMF_Db::getTablePrefix(), |
3043
|
|
|
$faqId, |
3044
|
|
|
$categoryId, |
3045
|
|
|
$openQuestionId |
3046
|
|
|
); |
3047
|
|
|
|
3048
|
|
|
return $this->_config->getDb()->query($query); |
3049
|
|
|
} |
3050
|
|
|
|
3051
|
|
|
/** |
3052
|
|
|
* Returns a part of a query to check permissions |
3053
|
|
|
* |
3054
|
|
|
* @param boolean $hasGroupSupport |
3055
|
|
|
* |
3056
|
|
|
* @return string |
3057
|
|
|
*/ |
3058
|
|
|
protected function queryPermission($hasGroupSupport = false) |
3059
|
|
|
{ |
3060
|
|
|
if ($hasGroupSupport) { |
3061
|
|
|
if (-1 === $this->user) { |
3062
|
|
|
return sprintf( |
3063
|
|
|
"AND fdg.group_id IN (%s)", |
3064
|
|
|
implode(', ', $this->groups), |
3065
|
|
|
$this->user, |
3066
|
|
|
implode(', ', $this->groups)); |
3067
|
|
View Code Duplication |
} else { |
3068
|
|
|
return sprintf( |
3069
|
|
|
"AND ( fdg.group_id IN (%s) OR (fdu.user_id = %d OR fdg.group_id IN (%s)) )", |
3070
|
|
|
implode(', ', $this->groups), |
3071
|
|
|
$this->user, |
3072
|
|
|
implode(', ', $this->groups) |
3073
|
|
|
); |
3074
|
|
|
} |
3075
|
|
|
} else { |
3076
|
|
|
if (-1 !== $this->user) { |
3077
|
|
|
return sprintf( |
3078
|
|
|
"AND ( fdu.user_id = %d OR fdu.user_id = -1 )", |
3079
|
|
|
$this->user |
3080
|
|
|
); |
3081
|
|
|
} else { |
3082
|
|
|
return sprintf( |
3083
|
|
|
"AND fdu.user_id = -1", |
3084
|
|
|
$this->user |
3085
|
|
|
); |
3086
|
|
|
} |
3087
|
|
|
} |
3088
|
|
|
} |
3089
|
|
|
} |
3090
|
|
|
|