-
Notifications
You must be signed in to change notification settings - Fork 0
/
Faq.php
2993 lines (2716 loc) · 88.4 KB
/
Faq.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* The main FAQ class
*
* PHP Version 5.2
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* @category phpMyFAQ
* @package PMF_Faq
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @author Matteo Scaramuccia <matteo@scaramuccia.com>
* @author Georgi Korchev <korchev@yahoo.com>
* @author Adrianna Musiol <musiol@imageaccess.de>
* @copyright 2005-2012 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License Version 1.1
* @link http://www.phpmyfaq.de
* @since 2005-12-20
*/
if (!defined('IS_VALID_PHPMYFAQ')) {
exit();
}
/**
* SQL constants definitions
*/
define('FAQ_SQL_YES', 'y');
define('FAQ_SQL_NO', 'n');
define('FAQ_SQL_ACTIVE_YES', 'yes');
define('FAQ_SQL_ACTIVE_NO', 'no');
/**
* Query type definitions
*/
define('FAQ_QUERY_TYPE_DEFAULT', 'faq_default');
define('FAQ_QUERY_TYPE_APPROVAL', 'faq_approval');
define('FAQ_QUERY_TYPE_EXPORT_PDF', 'faq_export_pdf');
define('FAQ_QUERY_TYPE_EXPORT_XHTML', 'faq_export_xhtml');
define('FAQ_QUERY_TYPE_EXPORT_XML', 'faq_export_xml');
define('FAQ_QUERY_TYPE_RSS_LATEST', 'faq_rss_latest');
/**
* Sorting type definitions
*/
define('FAQ_SORTING_TYPE_NONE', 0);
define('FAQ_SORTING_TYPE_CATID_FAQID', 1);
define('FAQ_SORTING_TYPE_FAQTITLE_FAQID', 2);
define('FAQ_SORTING_TYPE_DATE_FAQID', 3);
define('FAQ_SORTING_TYPE_FAQID', 4);
/**
* PMF_Faq
*
* @category phpMyFAQ
* @package PMF_Faq
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @author Matteo Scaramuccia <matteo@scaramuccia.com>
* @author Georgi Korchev <korchev@yahoo.com>
* @author Adrianna Musiol <musiol@imageaccess.de>
* @copyright 2005-2012 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License Version 1.1
* @link http://www.phpmyfaq.de
* @since 2005-12-20
*/
class PMF_Faq
{
/**
* DB handle
*
* @var PMF_Db
*/
private $db;
/**
* Language
*
* @var string
*/
public $language;
/**
* Language strings
*
* @var string
*/
private $pmf_lang;
/**
* Plural form support
*
* @var PMF_Language_Plurals
*/
private $plr;
/**
* The current FAQ record
*
* @var array
*/
public $faqRecord = array();
/**
* All current FAQ records in an array
*
* @var array
*/
public $faqRecords = array();
/**
* Users
*
* @var array
*/
private $user = null;
/**
* Groups
*
* @var array
*/
private $groups = array();
/**
* Flag for Group support
*
* @var boolean
*/
private $groupSupport = false;
/**
* Constructor
*
* @param integer $user User
* @param array $groups Groups
* @return void
*/
public function __construct($user = null, $groups = null)
{
global $PMF_LANG, $plr;
$this->db = PMF_Db::getInstance();
$this->language = PMF_Language::$language;
$this->pmf_lang = $PMF_LANG;
$this->plr = $plr;
if (is_null($user)) {
$this->user = -1;
} else {
$this->user = $user;
}
if (is_null($groups)) {
$this->groups = array(-1);
} else {
$this->groups = $groups;
}
$faqconfig = PMF_Configuration::getInstance();
if ($faqconfig->get('security.permLevel') == 'medium') {
$this->groupSupport = true;
}
}
//
//
// PUBLIC METHODS
//
//
/**
* This function returns all not expired records from one category
*
* @param int $category_id Category ID
* @param string $orderby Order by
* @param string $sortby Sorty by
* @return array
*/
public function getAllRecordPerCategory($category_id, $orderby = 'id', $sortby = 'ASC')
{
global $sids;
$faqdata = array();
if ($orderby == 'visits') {
$current_table = 'fv';
} else {
$current_table = 'fd';
}
if ($this->groupSupport) {
$permPart = sprintf("( fdg.group_id IN (%s)
OR
(fdu.user_id = %d AND fdg.group_id IN (%s)))",
implode(', ', $this->groups),
$this->user,
implode(', ', $this->groups));
} else {
$permPart = sprintf("( fdu.user_id = %d OR fdu.user_id = -1 )",
$this->user);
}
$now = date('YmdHis');
$query = sprintf("
SELECT
fd.id AS id,
fd.lang AS lang,
fd.thema AS thema,
fd.content AS record_content,
fd.datum AS record_date,
fcr.category_id AS category_id,
fv.visits AS visits
FROM
%sfaqdata AS fd
LEFT JOIN
%sfaqcategoryrelations AS fcr
ON
fd.id = fcr.record_id
AND
fd.lang = fcr.record_lang
LEFT JOIN
%sfaqvisits AS fv
ON
fd.id = fv.id
AND
fv.lang = fd.lang
LEFT JOIN
%sfaqdata_group AS fdg
ON
fd.id = fdg.record_id
LEFT JOIN
%sfaqdata_user AS fdu
ON
fd.id = fdu.record_id
WHERE
fd.date_start <= '%s'
AND
fd.date_end >= '%s'
AND
fd.active = 'yes'
AND
fcr.category_id = %d
AND
fd.lang = '%s'
AND
%s
ORDER BY
%s.%s %s",
SQLPREFIX,
SQLPREFIX,
SQLPREFIX,
SQLPREFIX,
SQLPREFIX,
$now,
$now,
$category_id,
$this->language,
$permPart,
$current_table,
$this->db->escape_string($orderby),
$this->db->escape_string($sortby));
$result = $this->db->query($query);
$num = $this->db->num_rows($result);
if ($num > 0) {
while (($row = $this->db->fetch_object($result))) {
if (empty($row->visits)) {
$visits = 0;
} else {
$visits = $row->visits;
}
$url = sprintf('%saction=artikel&cat=%d&id=%d&artlang=%s',
$sids,
$row->category_id,
$row->id,
$row->lang
);
$oLink = new PMF_Link(PMF_Link::getSystemRelativeUri().'?'.$url);
$oLink->itemTitle = $oLink->text = $oLink->tooltip = $row->thema;;
$faqdata[] = array(
'record_id' => $row->id,
'record_lang' => $row->lang,
'category_id' => $row->category_id,
'record_title' => $row->thema,
'record_preview' => PMF_Utils::chopString(strip_tags($row->record_content), 25),
'record_link' => $oLink->toString(),
'record_date' => $row->record_date,
'visits' => $visits);
}
} else {
return $faqdata;
}
return $faqdata;
}
/**
* This function returns all not expired records from one category
*
* @param int $category_id Category ID
* @param string $orderby Order by
* @param string $sortby Sorty by
* @return string
*/
public function showAllRecords($category_id, $orderby = 'id', $sortby = 'ASC')
{
global $sids, $category;
$faqconfig = PMF_Configuration::getInstance();
$page = PMF_Filter::filterInput(INPUT_GET, 'seite', FILTER_VALIDATE_INT, 1);
$output = '';
if ($orderby == 'visits') {
$current_table = 'fv';
} else {
$current_table = 'fd';
}
if ($this->groupSupport) {
$permPart = sprintf("( fdg.group_id IN (%s)
OR
(fdu.user_id = %d AND fdg.group_id IN (%s)))",
implode(', ', $this->groups),
$this->user,
implode(', ', $this->groups));
} else {
$permPart = sprintf("( fdu.user_id = %d OR fdu.user_id = -1 )",
$this->user);
}
$now = date('YmdHis');
$query = sprintf("
SELECT
fd.id AS id,
fd.lang AS lang,
fd.sticky AS sticky,
fd.thema AS thema,
fcr.category_id AS category_id,
fv.visits AS visits
FROM
%sfaqdata AS fd
LEFT JOIN
%sfaqcategoryrelations AS fcr
ON
fd.id = fcr.record_id
AND
fd.lang = fcr.record_lang
LEFT JOIN
%sfaqvisits AS fv
ON
fd.id = fv.id
AND
fv.lang = fd.lang
LEFT JOIN
%sfaqdata_group AS fdg
ON
fd.id = fdg.record_id
LEFT JOIN
%sfaqdata_user AS fdu
ON
fd.id = fdu.record_id
WHERE
fd.date_start <= '%s'
AND
fd.date_end >= '%s'
AND
fd.active = 'yes'
AND
fcr.category_id = %d
AND
fd.lang = '%s'
AND
%s
ORDER BY
fd.sticky DESC, %s.%s %s",
SQLPREFIX,
SQLPREFIX,
SQLPREFIX,
SQLPREFIX,
SQLPREFIX,
$now,
$now,
$category_id,
$this->language,
$permPart,
$current_table,
$this->db->escape_string($orderby),
$this->db->escape_string($sortby));
$result = $this->db->query($query);
$num = $this->db->num_rows($result);
$pages = ceil($num / $faqconfig->get("records.numberOfRecordsPerPage"));
if ($page == 1) {
$first = 0;
} else {
$first = ($page * $faqconfig->get("records.numberOfRecordsPerPage")) - $faqconfig->get("records.numberOfRecordsPerPage");
}
if ($num > 0) {
if ($pages > 1) {
$output .= sprintf('<p><strong>%s %s %s</strong></p>',
$this->pmf_lang['msgPage'] . $page,
$this->pmf_lang['msgVoteFrom'],
$pages . $this->pmf_lang['msgPages']);
}
$output .= '<ul class="phpmyfaq_ul">';
$counter = 0;
$displayedCounter = 0;
while (($row = $this->db->fetch_object($result)) && $displayedCounter < $faqconfig->get("records.numberOfRecordsPerPage")) {
$counter ++;
if ($counter <= $first) {
continue;
}
$displayedCounter++;
if (empty($row->visits)) {
$visits = 0;
} else {
$visits = $row->visits;
}
$title = $row->thema;
$url = sprintf('%saction=artikel&cat=%d&id=%d&artlang=%s',
$sids,
$row->category_id,
$row->id,
$row->lang);
$oLink = new PMF_Link(PMF_Link::getSystemRelativeUri().'?'.$url);
$oLink->itemTitle = $oLink->text = $oLink->tooltip = $title;
$listItem = sprintf('<li>%s<span id="viewsPerRecord"><br /><span class="little">(%s)</span>%s</span></li>',
$oLink->toHtmlAnchor(),
$this->plr->GetMsg('plmsgViews', $visits),
($row->sticky == 1) ? '<br /><br />' : '');
$output .= $listItem;
}
$output .= '</ul><span id="totFaqRecords" style="display: none;">'.$num.'</span>';
} else {
return false;
}
if ($pages > 1) {
$baseUrl = PMF_Link::getSystemRelativeUri() . '?' .
(empty($sids) ? '' : $sids) .
'action=show&cat=' . $category_id .
'&seite=' . $page;
$options = array('baseUrl' => $baseUrl,
'total' => $num,
'perPage' => $faqconfig->get('records.numberOfRecordsPerPage'),
'pageParamName' => 'seite',
'seoName' => $title,
'nextPageLinkTpl' => '<a href="{LINK_URL}">' . $this->pmf_lang['msgNext'] . '</a>',
'prevPageLinkTpl' => '<a href="{LINK_URL}">' . $this->pmf_lang['msgPrevious'] . '</a>',
'layoutTpl' => '<p align="center"><strong>{LAYOUT_CONTENT}</strong></p>');
$pagination = new PMF_Pagination($options);
$output .= $pagination->render();
}
return $output;
}
/**
* This function returns all not expired records from the given record ids
*
* @param array $record_ids Array of record ids
* @param string $orderby Order by
* @param string $sortby Sort by
* @return string
*/
public function showAllRecordsByIds(Array $record_ids, $orderby = 'fd.id', $sortby = 'ASC')
{
global $sids;
$faqconfig = PMF_Configuration::getInstance();
$records = implode(', ', $record_ids);
$page = PMF_Filter::filterInput(INPUT_GET, 'seite', FILTER_VALIDATE_INT, 1);
$tagging_id = PMF_Filter::filterInput(INPUT_GET, 'tagging_id', FILTER_VALIDATE_INT);
$output = '';
if ($this->groupSupport) {
$permPart = sprintf("( fdg.group_id IN (%s)
OR
(fdu.user_id = %d AND fdg.group_id IN (%s)))",
implode(', ', $this->groups),
$this->user,
implode(', ', $this->groups));
} else {
$permPart = sprintf("( fdu.user_id = %d OR fdu.user_id = -1 )",
$this->user);
}
$now = date('YmdHis');
$query = sprintf("
SELECT
fd.id AS id,
fd.lang AS lang,
fd.thema AS thema,
fcr.category_id AS category_id,
fv.visits AS visits
FROM
%sfaqdata AS fd
LEFT JOIN
%sfaqcategoryrelations AS fcr
ON
fd.id = fcr.record_id
AND
fd.lang = fcr.record_lang
LEFT JOIN
%sfaqvisits AS fv
ON
fd.id = fv.id
AND
fv.lang = fd.lang
LEFT JOIN
%sfaqdata_group AS fdg
ON
fd.id = fdg.record_id
LEFT JOIN
%sfaqdata_user AS fdu
ON
fd.id = fdu.record_id
WHERE
fd.date_start <= '%s'
AND
fd.date_end >= '%s'
AND
fd.active = 'yes'
AND
fd.id IN (%s)
AND
fd.lang = '%s'
AND
%s
ORDER BY
%s %s",
SQLPREFIX,
SQLPREFIX,
SQLPREFIX,
SQLPREFIX,
SQLPREFIX,
$now,
$now,
$records,
$this->language,
$permPart,
$this->db->escape_string($orderby),
$this->db->escape_string($sortby));
$result = $this->db->query($query);
$num = $this->db->num_rows($result);
$pages = ceil($num / $faqconfig->get('records.numberOfRecordsPerPage'));
if ($page == 1) {
$first = 0;
} else {
$first = ($page * $faqconfig->get('records.numberOfRecordsPerPage')) - $faqconfig->get('records.numberOfRecordsPerPage');
}
if ($num > 0) {
if ($pages > 1) {
$output .= sprintf('<p><strong>%s %s %s</strong></p>',
$this->pmf_lang['msgPage'] . $page,
$this->pmf_lang['msgVoteFrom'],
$pages . $this->pmf_lang['msgPages']);
}
$output .= '<ul class="phpmyfaq_ul">';
$counter = 0;
$displayedCounter = 0;
$lastFaqId = 0;
while (($row = $this->db->fetch_object($result)) && $displayedCounter < $faqconfig->get('records.numberOfRecordsPerPage')) {
$counter ++;
if ($counter <= $first) {
continue;
}
$displayedCounter++;
if ($lastFaqId == $row->id) {
continue; // Don't show multiple FAQs
}
if (empty($row->visits)) {
$visits = 0;
} else {
$visits = $row->visits;
}
$title = $row->thema;
$url = sprintf('%saction=artikel&cat=%d&id=%d&artlang=%s',
$sids,
$row->category_id,
$row->id,
$row->lang
);
$oLink = new PMF_Link(PMF_Link::getSystemRelativeUri().'?'.$url);
$oLink->itemTitle = $row->thema;
$oLink->text = $title;
$oLink->tooltip = $title;
$listItem = sprintf('<li>%s<br /><span class="little">('.$this->plr->GetMsg('plmsgViews',$visits).')</span></li>',
$oLink->toHtmlAnchor());
$output .= $listItem;
$lastFaqId = $row->id;
}
$output .= '</ul><span id="totFaqRecords" style="display: none;">'.$num.'</span>';
} else {
return false;
}
if ($num > $faqconfig->get('records.numberOfRecordsPerPage')) {
$output .= "<p align=\"center\"><strong>";
if (!isset($page)) {
$page = 1;
}
$vor = $page - 1;
$next = $page + 1;
if ($vor != 0) {
$url = $sids.'&action=search&tagging_id='.$tagging_id.'&seite='.$vor;
$oLink = new PMF_Link(PMF_Link::getSystemRelativeUri().'?'.$url);
$oLink->itemTitle = 'tag';
$oLink->text = $this->pmf_lang["msgPrevious"];
$oLink->tooltip = $this->pmf_lang["msgPrevious"];
$output .= '[ '.$oLink->toHtmlAnchor().' ]';
}
$output .= " ";
if ($next <= $pages) {
$url = $sids.'&action=search&tagging_id='.$tagging_id.'&seite='.$next;
$oLink = new PMF_Link(PMF_Link::getSystemRelativeUri().'?'.$url);
$oLink->itemTitle = 'tag';
$oLink->text = $this->pmf_lang["msgNext"];
$oLink->tooltip = $this->pmf_lang["msgNext"];
$output .= '[ '.$oLink->toHtmlAnchor().' ]';
}
$output .= "</strong></p>";
}
return $output;
}
/**
* Returns an array with all data from a FAQ record
*
* @param integer $record_id Record id
* @param integer $revision_id Revidion id
* @param boolean $admin must be true if it is called by an admin/author context
* @return void
*/
public function getRecord($id, $revision_id = null, $admin = false)
{
global $PMF_LANG;
if ($this->groupSupport) {
$permPart = sprintf("( fdg.group_id IN (%s)
OR
(fdu.user_id = %d AND fdg.group_id IN (%s)))",
implode(', ', $this->groups),
$this->user,
implode(', ', $this->groups));
} else {
$permPart = sprintf("( fdu.user_id = %d OR fdu.user_id = -1 )",
$this->user);
}
$query = sprintf(
"SELECT
id, lang, solution_id, revision_id, active, sticky, keywords,
thema, content, author, email, comment, datum, links_state,
links_check_date, date_start, date_end
FROM
%s%s fd
LEFT JOIN
%sfaqdata_group fdg
ON
fd.id = fdg.record_id
LEFT JOIN
%sfaqdata_user fdu
ON
fd.id = fdu.record_id
WHERE
fd.id = %d
%s
AND
fd.lang = '%s'
AND
%s",
SQLPREFIX,
isset($revision_id) ? 'faqdata_revisions': 'faqdata',
SQLPREFIX,
SQLPREFIX,
$id,
isset($revision_id) ? 'AND revision_id = '.$revision_id : '',
$this->language,
($admin) ? '1=1' : $permPart);
$result = $this->db->query($query);
if ($row = $this->db->fetch_object($result)) {
$content = $row->content;
$active = ('yes' == $row->active);
$expired = (date('YmdHis') > $row->date_end);
if (!$admin) {
if (!$active) {
$content = $this->pmf_lang['err_inactiveArticle'];
}
if ($expired) {
$content = $this->pmf_lang['err_expiredArticle'];
}
}
$this->faqRecord = array(
'id' => $row->id,
'lang' => $row->lang,
'solution_id' => $row->solution_id,
'revision_id' => $row->revision_id,
'active' => $row->active,
'sticky' => $row->sticky,
'keywords' => $row->keywords,
'title' => $row->thema,
'content' => $content,
'author' => $row->author,
'email' => $row->email,
'comment' => $row->comment,
'date' => PMF_Date::createIsoDate($row->datum),
'dateStart' => $row->date_start,
'dateEnd' => $row->date_end,
'linkState' => $row->links_state,
'linkCheckDate' => $row->links_check_date
);
} else {
$this->faqRecord = array(
'id' => $id,
'lang' => $this->language,
'solution_id' => 42,
'revision_id' => 0,
'active' => 'no',
'sticky' => 0,
'keywords' => '',
'title' => '',
'content' => $PMF_LANG['err_inactiveArticle'],
'author' => '',
'email' => '',
'comment' => '',
'date' => PMF_Date::createIsoDate(date('YmdHis')),
'dateStart' => '',
'dateEnd' => '',
'linkState' => '',
'linkCheckDate' => ''
);
}
}
/**
* Adds a new record
*
* @param array $data Array of FAQ data
* @param boolean $new_record New record?
* @return integer
*/
public function addRecord(Array $data, $new_record = true)
{
if ($new_record) {
$record_id = $this->db->nextID(SQLPREFIX.'faqdata', 'id');
} else {
$record_id = $data['id'];
}
// Add new entry
$query = sprintf(
"INSERT INTO
%sfaqdata
VALUES
(%d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s')",
SQLPREFIX,
$record_id,
$data['lang'],
$this->getSolutionId(),
0,
$data['active'],
$data['sticky'],
$this->db->escape_string($data['keywords']),
$this->db->escape_string($data['thema']),
$this->db->escape_string($data['content']),
$this->db->escape_string($data['author']),
$data['email'],
$data['comment'],
$data['date'],
$data['linkState'],
$data['linkDateCheck'],
$data['dateStart'],
$data['dateEnd']);
$this->db->query($query);
return $record_id;
}
/**
* Updates a record
*
* @param array $data Array of FAQ data
* @return boolean
*/
public function updateRecord(Array $data)
{
// Update entry
$query = sprintf("
UPDATE
%sfaqdata
SET
revision_id = %d,
active = '%s',
sticky = %d,
keywords = '%s',
thema = '%s',
content = '%s',
author = '%s',
email = '%s',
comment = '%s',
datum = '%s',
links_state = '%s',
links_check_date = %d,
date_start = '%s',
date_end = '%s'
WHERE
id = %d
AND
lang = '%s'",
SQLPREFIX,
$data['revision_id'],
$data['active'],
$data['sticky'],
$this->db->escape_string($data['keywords']),
$this->db->escape_string($data['thema']),
$this->db->escape_string($data['content']),
$this->db->escape_string($data['author']),
$data['email'],
$data['comment'],
$data['date'],
$data['linkState'],
$data['linkDateCheck'],
$data['dateStart'],
$data['dateEnd'],
$data['id'],
$data['lang']);
$this->db->query($query);
return true;
}
/**
* Deletes a record and all the dependencies
*
* @param integer $record_id Record id
* @param string $record_lang Record language
*
* @return boolean
*/
public function deleteRecord($record_id, $record_lang)
{
$queries = array(
sprintf("DELETE FROM %sfaqchanges WHERE beitrag = %d AND lang = '%s'",
SQLPREFIX, $record_id, $record_lang),
sprintf("DELETE FROM %sfaqcategoryrelations WHERE record_id = %d AND record_lang = '%s'",
SQLPREFIX, $record_id, $record_lang),
sprintf("DELETE FROM %sfaqdata WHERE id = %d AND lang = '%s'",
SQLPREFIX, $record_id, $record_lang),
sprintf("DELETE FROM %sfaqdata_revisions WHERE id = %d AND lang = '%s'",
SQLPREFIX, $record_id, $record_lang),
sprintf("DELETE FROM %sfaqvisits WHERE id = %d AND lang = '%s'",
SQLPREFIX, $record_id, $record_lang),
sprintf("DELETE FROM %sfaqdata_user WHERE record_id = %d",
SQLPREFIX, $record_id, $record_lang),
sprintf("DELETE FROM %sfaqdata_group WHERE record_id = %d",
SQLPREFIX, $record_id, $record_lang),
sprintf("DELETE FROM %sfaqdata_tags WHERE record_id = %d",
SQLPREFIX, $record_id),
sprintf('DELETE FROM %sfaqdata_tags WHERE %sfaqdata_tags.record_id NOT IN (SELECT %sfaqdata.id FROM %sfaqdata)',
SQLPREFIX, SQLPREFIX, SQLPREFIX, SQLPREFIX),
sprintf("DELETE FROM %sfaqcomments WHERE id = %d",
SQLPREFIX, $record_id),
sprintf("DELETE FROM %sfaqvoting WHERE artikel = %d",
SQLPREFIX, $record_id));
foreach($queries as $query) {
$this->db->query($query);
}
return true;
}
/**
* Checks if a record is already translated
*
* @param integer $record_id Record id
* @param string $record_lang Record language
* @return boolean
*/
public function isAlreadyTranslated($record_id, $record_lang)
{
$query = sprintf("
SELECT
id, lang
FROM
%sfaqdata
WHERE
id = %d
AND
lang = '%s'",
SQLPREFIX,
$record_id,
$record_lang);
$result = $this->db->query($query);
if ($this->db->num_rows($result)) {
return true;
}
return false;
}
/**
* Checks, if comments are disabled for the FAQ record
*
* @param integer $record_id Id of FAQ or news entry
* @param string $record_lang Language
* @param string $record_type Type of comment: faq or news
* @return boolean true, if comments are disabled
*/
public function commentDisabled($record_id, $record_lang, $record_type = 'faq')
{
if ('news' == $record_type) {
$table = 'faqnews';
} else {
$table = 'faqdata';
}
$query = sprintf("
SELECT
comment
FROM
%s%s
WHERE
id = %d
AND
lang = '%s'",
SQLPREFIX,
$table,
$record_id,
$record_lang);
$result = $this->db->query($query);
if ($row = $this->db->fetch_object($result)) {
return ($row->comment === 'y') ? false : true;
} else {
return true;
}
}
/**
* Adds new category relations to a record
*
* @param array $categories Array of categories
* @param integer $record_id Record id
* @param string $language Language
* @return integer
*/
public function addCategoryRelations(Array $categories, $record_id, $language)
{
if (!is_array($categories)) {
return false;
}
foreach ($categories as $_category) {
$this->db->query(sprintf(
"INSERT INTO
%sfaqcategoryrelations
VALUES
(%d, '%s', %d, '%s')",