phpMyFAQ /phpmyfaq/admin/record.edit.php

Language PHP Lines 945
MD5 Hash 866134481180213cd02b48d08df0108a
Repository https://github.com/cyrke/phpMyFAQ.git View Raw File
  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
<?php
/**
 * The FAQ record editor.
 *
 * PHP Version 5.3
 *
 * This Source Code Form is subject to the terms of the Mozilla Public License,
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
 * obtain one at http://mozilla.org/MPL/2.0/.
 *
 * @category  phpMyFAQ
 * @package   Administration
 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
 * @copyright 2003-2012 phpMyFAQ Team
 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
 * @link      http://www.phpmyfaq.de
 * @since     2003-02-23
 */

if (!defined('IS_VALID_PHPMYFAQ')) {
    header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
    exit();
}

// Re-evaluate $user
$user = PMF_User_CurrentUser::getFromSession($faqConfig);

if (($permission['editbt']|| $permission['addbt']) && !PMF_Db::checkOnEmptyTable('faqcategories')) {

    $category = new PMF_Category($faqConfig, false);
    $category->setUser($currentAdminUser);
    $category->setGroups($currentAdminGroups);
    $category->buildTree();

    $categoryHelper = new PMF_Helper_Category();
    $categoryHelper->setCategory($category);

    $selectedCategory = '';
    $categories       = array();
    $faqData          = array(
        'id'          => 0,
        'lang'        => $LANGCODE,
        'revision_id' => 0,
        'title'       => '',
        'dateStart'   => '',
        'dateEnd'     => ''
    );

    $tagging = new PMF_Tags($faqConfig);
    $date    = new PMF_Date($faqConfig);

    if ('takequestion' === $action) {
        $questionId       = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
        $question         = $faq->getQuestion($questionId);
        $selectedCategory = $question['category_id'];
        $faqData['title'] = $question['question'];
        $notifyUser       = $question['username'];
        $notifyEmail      = $question['email'];
        $categories       = array(
            'category_id'   => $selectedCategory,
            'category_lang' => $faqData['lang']
        );
    } else {
        $questionId  = 0;
        $notifyUser  = '';
        $notifyEmail = '';
    }

    if ('editpreview' === $action) {

        $faqData['id'] = PMF_Filter::filterInput(INPUT_POST, 'id', FILTER_VALIDATE_INT);
        if (!is_null($faqData['id'])) {
            $queryString = 'saveentry&amp;id=' . $faqData['id'];
        } else {
            $queryString = 'insertentry';
        }
        
        $faqData['lang']  = PMF_Filter::filterInput(INPUT_POST, 'lang', FILTER_SANITIZE_STRING);
        $selectedCategory = isset($_POST['rubrik']) ? $_POST['rubrik'] : null;
        if (is_array($selectedCategory)) {
            foreach ($selectedCategory as $cats) {
                $categories[] = array('category_id' => $cats, 'category_lang' => $faqData['lang']);
            }
        }
        $faqData['active']      = PMF_Filter::filterInput(INPUT_POST, 'active', FILTER_SANITIZE_STRING);
        $faqData['keywords']    = PMF_Filter::filterInput(INPUT_POST, 'keywords', FILTER_SANITIZE_STRING);
        $faqData['title']       = PMF_Filter::filterInput(INPUT_POST, 'thema', FILTER_SANITIZE_STRING);
        $faqData['content']     = PMF_Filter::filterInput(INPUT_POST, 'content', FILTER_SANITIZE_SPECIAL_CHARS);
        $faqData['author']      = PMF_Filter::filterInput(INPUT_POST, 'author', FILTER_SANITIZE_STRING);
        $faqData['email']       = PMF_Filter::filterInput(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
        $faqData['comment']     = PMF_Filter::filterInput(INPUT_POST, 'comment', FILTER_SANITIZE_STRING);
        $faqData['solution_id'] = PMF_Filter::filterInput(INPUT_POST, 'solution_id', FILTER_VALIDATE_INT);
        $faqData['revision_id'] = PMF_Filter::filterInput(INPUT_POST, 'revision_id', FILTER_VALIDATE_INT, 0);
        $faqData['sticky']      = PMF_Filter::filterInput(INPUT_POST, 'sticky', FILTER_VALIDATE_INT);
        $faqData['tags']        = PMF_Filter::filterInput(INPUT_POST, 'tags', FILTER_SANITIZE_STRING);
        $faqData['changed']     = PMF_Filter::filterInput(INPUT_POST, 'changed', FILTER_SANITIZE_STRING);
        $faqData['dateStart']   = PMF_Filter::filterInput(INPUT_POST, 'dateStart', FILTER_SANITIZE_STRING);
        $faqData['dateEnd']     = PMF_Filter::filterInput(INPUT_POST, 'dateEnd', FILTER_SANITIZE_STRING);
        $faqData['content']     = html_entity_decode($faqData['content']);
        
    } elseif ('editentry' === $action) {

        $id   = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
        $lang = PMF_Filter::filterInput(INPUT_GET, 'lang', FILTER_SANITIZE_STRING);
        if ((!isset($selectedCategory) && !isset($faqData['title'])) || !is_null($id)) {
            $logging = new PMF_Logging($faqConfig);
            $logging->logAdmin($user, 'Beitragedit, ' . $id);

            $categories = $category->getCategoryRelationsFromArticle($id, $lang);

            $faq->getRecord($id, null, true);
            $faqData         = $faq->faqRecord;
            $faqData['tags'] = implode(',', $tagging->getAllTagsById($faqData['id']));
            $queryString     = 'saveentry&amp;id=' . $faqData['id'];
        } else {
            $queryString = 'insertentry';
        }

    } elseif ('copyentry' === $action) {

        $faqData['id']   = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
        $faqData['lang'] = PMF_Filter::filterInput(INPUT_GET, 'lang', FILTER_SANITIZE_STRING);
        $faq->language   = $faqData['lang'];
        $categories      = $category->getCategoryRelationsFromArticle($faqData['id'], $faqData['lang']);

        $faq->getRecord($faqData['id'], null, true);

        $faqData     = $faq->faqRecord;
        $queryString = 'insertentry';

    } else {
        $logging = new PMF_Logging($faqConfig);
        $logging->logAdmin($user, 'Beitragcreate');
        $queryString = 'insertentry';
        if (!is_array($categories)) {
            $categories = array();
        }
    }
    
    // Revisions
    $selectedRevisionId = PMF_Filter::filterInput(INPUT_POST, 'revisionid_selected', FILTER_VALIDATE_INT);
    if (is_null($selectedRevisionId)) {
        $selectedRevisionId = $faqData['revision_id'];
    }

    // User permissions
    $userPermission = $faq->getPermission('user', $faqData['id']);
    if (count($userPermission) == 0 || $userPermission[0] == -1) {
        $allUsers          = true;
        $restrictedUsers   = false;
        $userPermission[0] = -1;
    } else {
        $allUsers        = false;
        $restrictedUsers = true;
    }

    // Group permissions
    $groupPermission = $faq->getPermission('group', $faqData['id']);
    if (count($groupPermission) == 0 || $groupPermission[0] == -1) {
        $allGroups          = true;
        $restrictedGroups   = false;
        $groupPermission[0] = -1;
    } else {
        $allGroups        = false;
        $restrictedGroups = true;
    }

    // Set data for forms
    $faqData['title']    = (isset($faqData['title']) ? PMF_String::htmlspecialchars($faqData['title']) : '');
    $faqData['content']  = (isset($faqData['content']) ? trim(PMF_String::htmlentities($faqData['content'])) : '');
    $faqData['tags']     = (isset($faqData['tags']) ? PMF_String::htmlspecialchars($faqData['tags']) : '');
    $faqData['keywords'] = (isset($faqData['keywords']) ? PMF_String::htmlspecialchars($faqData['keywords']) : '');
    $faqData['author']   = (isset($faqData['author']) ? PMF_String::htmlspecialchars($faqData['author']) : $user->getUserData('display_name'));
    $faqData['email']    = (isset($faqData['email']) ? PMF_String::htmlspecialchars($faqData['email']) : $user->getUserData('email'));
    $faqData['date']     = (isset($faqData['date']) ? $date->format($faqData['date']) : $date->format(date('Y-m-d H:i')));
    $faqData['changed']  = (isset($faqData['changed']) ? $faqData['changed'] : '');

    if (isset($faqData['comment']) && $faqData['comment'] == 'y') {
        $faqData['comment'] = ' checked="checked"';
    } elseif ($faqConfig->get('records.defaultAllowComments')) {
        $faqData['comment'] = ' checked="checked"';
    } else {
        $faqData['comment'] = '';
    }

    // Start header
    if (0 !== $faqData['id'] && 'copyentry' !== $action) {
        $currentRevision = sprintf(
            ' <span class="badge badge-important">%s 1.%d</span> ',
            $PMF_LANG['ad_entry_revision'],
            $selectedRevisionId
        );
        printf(
            '<header><h2>%s <span class="text-error">%s</span> %s %s</h2></header>',
            $PMF_LANG['ad_entry_edit_1'],
            (0 === $faqData['id'] ? '' : $faqData['id']),
            $PMF_LANG['ad_entry_edit_2'],
            $currentRevision
        );
    } else {
        printf(
            '<header><h2>%s</h2></header>',
            $PMF_LANG['ad_entry_add']
        );
    }
?>
        <div class="row-fluid">
            <!-- Revisions -->

        </div>

        <div class="row-fluid">

            <form id="faqEditor" action="?action=<?php echo $queryString; ?>" method="post">
            <input type="hidden" name="revision_id" id="revision_id" value="<?php echo $faqData['revision_id']; ?>" />
            <input type="hidden" name="record_id" id="record_id" value="<?php echo $faqData['id']; ?>" />
            <input type="hidden" name="csrf" value="<?php echo $user->getCsrfTokenFromSession(); ?>" />
            <input type="hidden" name="openQuestionId" id="openQuestionId" value="<?php echo $questionId; ?>" />
            <input type="hidden" name="notifyUser" id="notifyUser" value="<?php echo $notifyUser ?>" />
            <input type="hidden" name="notifyEmail" id="notifyEmail" value="<?php echo $notifyEmail ?>" />

            <!-- main editor window -->
            <div class="span8">
                <fieldset class="form-inline">
                    <!-- Question -->
                    <div class="control-group">
                        <div class="controls">
                            <input type="text" name="question" id="question" class="admin-question"
                                   placeholder="<?php echo $PMF_LANG['ad_entry_theme']; ?>" maxlength="255"
                                   value="<?php echo $faqData['title'] ?>" />
                        </div>
                    </div>
                    <!-- Answer -->
                    <div class="control-group">
                        <div class="controls">
                            <noscript>Please enable JavaScript to use the WYSIWYG editor!</noscript>
                            <textarea id="answer" name="answer" class="span8">
                                <?php echo $faqData['content'] ?>
                            </textarea>
                        </div>
                    </div>
                </fieldset>
                <fieldset class="form-horizontal">
                    <!-- Meta data -->
                    <?php if ($faqConfig->get('main.enableGoogleTranslation') === true): ?>
                        <input type="hidden" id="lang" name="lang" value="<?php echo $faqData['lang']; ?>" />
                    <?php else: ?>
                    <div class="control-group">
                        <label class="control-label" for="lang"><?php echo $PMF_LANG["ad_entry_locale"]; ?>:</label>
                        <div class="controls">
                            <?php echo PMF_Language::selectLanguages($faqData['lang'], false, array(), 'lang'); ?>
                        </div>
                     </div>
                     <?php endif; ?>
                </fieldset>
                <fieldset class="form-horizontal">
                    <!-- Attachments -->
                    <?php if ($permission['addattachment']): ?>
                    <div class="control-group">
                        <label class="control-label"><?php echo $PMF_LANG['ad_menu_attachments'] ?>:</label>
                        <div class="controls">
                            <ul class="adminAttachments">
                                <?php
                                $attList = PMF_Attachment_Factory::fetchByRecordId($faqConfig, $faqData['id']);
                                foreach ($attList as $att) {
                                    printf(
                                        '<li><a href="../%s">%s</a> ',
                                        $att->buildUrl(),
                                        $att->getFilename()
                                    );
                                    if ($permission['delattachment']) {
                                        printf(
                                            '<a class="label label-important" href="?action=delatt&amp;record_id=%d&amp;id=%d&amp;lang=%s"><i class="icon-trash icon-white"></i></a>',
                                            $faqData['id'],
                                            $att->getId(),
                                            $faqData['lang']
                                        );
                                    }
                                    echo "</li>\n";
                                }
                                ?>
                            </ul>
                                <?php
                                if (0 === $faqData['id']) {
                                    $faqData['id'] = $faqConfig->getDb()->nextId(
                                        PMF_Db::getTablePrefix() . 'faqdata',
                                        'id'
                                    );
                                }
                                printf(
                                    '<a class="btn btn-success" onclick="addAttachment(\'attachment.php?record_id=%d&amp;record_lang=%s\', \'Attachment\');">%s</a>',
                                    $faqData['id'],
                                    $faqData['lang'],
                                    $PMF_LANG['ad_att_add']
                                );
                            ?>
                        </div>
                    </div>
                    <?php endif; ?>
                    <!-- Tags -->
                    <div class="control-group">
                        <label class="control-label" for="tags"><?php echo $PMF_LANG['ad_entry_tags']; ?>:</label>
                        <div class="controls">
                            <input type="text" name="tags" id="tags" value="<?php echo $faqData['tags'] ?>"
                                   data-provide="typeahead" data-mode="multiple" />
                            <span id="tagsHelp" class="hide"><?php echo $PMF_LANG['msgShowHelp']; ?></span>
                        </div>
                    </div>
                    <!-- Keywords -->
                    <div class="control-group">
                        <label class="control-label" for="keywords"><?php echo $PMF_LANG["ad_entry_keywords"]; ?></label>
                        <div class="controls">
                            <input type="text" name="keywords" id="keywords"  maxlength="255"
                                   value="<?php echo $faqData['keywords'] ?>" />
                            <span id="keywordsHelp" class="hide"><?php echo $PMF_LANG['msgShowHelp']; ?></span>
                        </div>
                    </div>
                </fieldset>
                <fieldset class="form-horizontal">
                    <?php
                    if ('00000000000000' == $faqData['dateStart']) {
                        $faqData['dateStart'] = '';
                    } else {
                        $faqData['dateStart'] = preg_replace("/(\d{4})(\d{2})(\d{2}).*/", "$1-$2-$3", $faqData['dateStart']);
                    }

                    if ('99991231235959' == $faqData['dateEnd']) {
                        $faqData['dateEnd'] = '';
                    } else {
                        $faqData['dateEnd'] = preg_replace("/(\d{4})(\d{2})(\d{2}).*/", "$1-$2-$3", $faqData['dateEnd']);
                    }
                    ?>
                    <legend><?php echo $PMF_LANG['ad_record_expiration_window']; ?></legend>
                    <div class="control-group">
                        <label class="control-label" for="dateStart"><?php echo $PMF_LANG['ad_news_from']; ?></label>
                        <div class="controls">
                            <input name="dateStart" id="dateStart" class="date-pick span2"  maxlength="10"
                                   value="<?php echo $faqData['dateStart']; ?>" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="dateEnd"><?php echo $PMF_LANG['ad_news_to']; ?></label>
                        <div class="controls">
                            <input name="dateEnd" id="dateEnd" class="date-pick span2" maxlength="10"
                                   value="<?php echo $faqData['dateEnd']; ?>" />
                        </div>
                    </div>
                </fieldset>
                <fieldset class="form-horizontal">
                    <!-- Author -->
                    <div class="control-group">
                        <label class="control-label" for="author"><?php echo $PMF_LANG["ad_entry_author"]; ?></label>
                        <div class="controls">
                            <input type="text" name="author" id="author" value="<?php echo $faqData['author'] ?>" />
                        </div>
                    </div>
                    <!-- E-Mail -->
                    <div class="control-group">
                        <label class="control-label" for="email"><?php echo $PMF_LANG["ad_entry_email"]; ?></label>
                        <div class="controls">
                            <input type="email" name="email" id="email" value="<?php echo $faqData['email'] ?>" />
                        </div>
                    </div>
                </fieldset>
                <fieldset class="form-horizontal">
                    <legend><?php echo $PMF_LANG['ad_entry_changelog']; ?></legend>
                    <div class="control-group" id="editChangelog">
                        <label class="control-label"><?php echo $PMF_LANG["ad_entry_date"]; ?></label>
                        <div class="controls">
                            <span class="input-medium uneditable-input"><?php echo $faqData['date'] ?></span>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="changed"><?php echo $PMF_LANG["ad_entry_changed"]; ?></label>
                        <div class="controls">
                            <textarea name="changed" id="changed" class="span8">
                                <?php echo $faqData['changed'] ?>
                            </textarea>
                        </div>
                    </div>
                </fieldset>
                <!-- Changelog -->
                <?php if (is_numeric($faqData['id'])): ?>
                <fieldset>
                    <legend>
                        <a href="javascript:void(0);" onclick="javascript:toggleFieldset('editChangelogHistory');">
                            <?php echo $PMF_LANG['ad_entry_changelog_history']; ?>
                        </a>
                    </legend>
                    <div id="editChangelogHistory" class="hide">
                        <?php
                        foreach ($faq->getChangeEntries($faqData['id']) as $entry) {
                            $user->getUserById($entry['user']);
                            ?>
                            <p style="font-size: 10px;">
                                <label>
                                    <?php printf('%s  1.%d<br/>%s<br/>%s: %s',
                                    $PMF_LANG['ad_entry_revision'],
                                    $entry['revision_id'],
                                    $date->format(date('Y-m-d H:i', $entry['date'])),
                                    $PMF_LANG['ad_entry_author'],
                                    $user->getUserData('display_name')); ?>
                                </label>
                                <?php echo $entry['changelog']; ?>
                            </p>
                            <?php } ?>
                </fieldset>
                <?php endif; ?>
            </div>

            <!-- sidebar -->
            <div class="well span3">
                <!-- form actions -->
                <fieldset>
                    <div class="control-group">
                        <label class="control-label" for="dateActualize"><?php echo $PMF_LANG["ad_entry_date"]; ?></label>
                        <div class="controls">
                            <label class="radio">
                                <input type="radio" id="dateActualize" checked="checked" name="recordDateHandling"
                                       onchange="setRecordDate(this.id);" />
                                <?php echo $PMF_LANG['msgUpdateFaqDate']; ?>
                            </label>
                            <label class="radio">
                                <input type="radio" id="dateKeep" name="recordDateHandling"
                                       onchange="setRecordDate(this.id);" />
                                <?php echo $PMF_LANG['msgKeepFaqDate']; ?>
                            </label>
                            <label class="radio">
                                <input type="radio" id="dateCustomize" name="recordDateHandling"
                                       onchange="setRecordDate(this.id);" />
                                <?php echo $PMF_LANG['msgEditFaqDat']; ?>
                            </label>
                        </div>
                    </div>
                    <div id="recordDateInputContainer" class="control-group hide">
                        <div class="controls">
                            <input type="text" name="date" id="date" maxlength="16" value="" />
                        </div>
                    </div>
                    <?php if ($selectedRevisionId == $faqData['revision_id']): ?>
                    <div class="form-actions">
                        <button class="btn btn-primary" type="submit">
                            <?php echo $PMF_LANG["ad_entry_save"]; ?>
                        </button>
                        <button class="btn btn-info" type="reset">
                            <?php echo $PMF_LANG["ad_gen_reset"]; ?>
                        </button>
                    </div>
                    <?php endif; ?>
                </fieldset>
                <!-- categories -->
                <fieldset>
                    <div class="control-group">
                        <label class="control-label"><?php echo $PMF_LANG["ad_entry_category"]; ?></label>
                        <div class="controls">
                            <select name="rubrik[]" id="rubrik" size="5" multiple="multiple" class="input-medium">
                                <?php echo $categoryHelper->renderOptions($categories); ?>
                            </select>
                        </div>
                    </div>
                </fieldset>
                <!-- Activation -->
                <fieldset>
                    <div class="control-group">
                        <label class="control-label" for="active"><?php echo $PMF_LANG["ad_entry_active"]; ?></label>
                        <div class="controls">
                        <?php if($permission['approverec']):
                        if (isset($faqData['active']) && $faqData['active'] == 'yes') {
                            $suf = ' checked="checked"';
                            $sul = null;
                        } elseif ($faqConfig->get('records.defaultActivation')) {
                            $suf = ' checked="checked"';
                            $sul = null;
                        } else {
                            $suf = null;
                            $sul = ' checked="checked"';
                        }
                        ?>
                            <label class="radio">
                                <input type="radio" id="active" name="active"  value="yes"<?php if (isset($suf)) { echo $suf; } ?> />
                                <?php echo $PMF_LANG['ad_gen_yes']; ?>
                            </label>
                            <label class="radio">
                                <input type="radio" name="active"  value="no"<?php if (isset($sul)) { echo $sul; } ?> />
                                <?php echo $PMF_LANG['ad_gen_no']; ?>
                            </label>
                            <?php else: ?>
                            <label class="radio">
                                <input type="radio" name="active"  value="no" checked="checked" />
                                <?php echo $PMF_LANG['ad_gen_no']; ?>
                            </label>
                        <?php endif; ?>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="sticky"><?php echo $PMF_LANG['ad_entry_sticky']; ?>:</label>
                        <div class="controls">
                            <label class="checkbox">
                                <input type="checkbox" id="sticky" name="sticky" <?php echo (isset($faqData['sticky']) && $faqData['sticky'] ? 'checked="checked"' : '') ?> />
                                &nbsp;
                            </label>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="comment">
                            <?php echo $PMF_LANG['ad_entry_allowComments']; ?>
                        </label>
                        <div class="controls">
                            <label class="checkbox">
                                <input type="checkbox" name="comment" id="comment" value="y"<?php echo $faqData['comment'] ?> />
                                <?php echo $PMF_LANG['ad_gen_yes']; ?>
                            </label>
                        </div>
                    </div>
                    <?php if ($queryString != 'insertentry'): ?>
                    <div class="control-group">
                        <label class="control-label" for="revision">
                            <?php echo $PMF_LANG['ad_entry_new_revision']; ?>
                        </label>
                        <?php
                        if ($queryString != 'insertentry') {
                            $rev_yes = ' checked="checked"';
                            $rev_no  = null;
                        }
                        if (isset($faqData['active']) && $faqData['active'] == 'no') {
                            $rev_no  = ' checked="checked"';
                            $rev_yes = null;
                        }
                        ?>
                        <div class="controls">
                            <label class="radio">
                                <input type="radio" name="revision" id="revision" value="yes"<?php echo isset($rev_yes) ? $rev_yes : ''; ?>/>
                                <?php echo $PMF_LANG["ad_gen_yes"]; ?>
                            </label>
                            <label class="radio">
                                <input type="radio" name="revision" value="no"<?php echo isset($rev_no) ? $rev_no : ''; ?>/>
                                <?php echo $PMF_LANG["ad_gen_no"]; ?>
                            </label>
                        </div>
                    </div>
                    <?php endif; ?>
                    <div class="control-group">
                        <label class="control-label" for="solution_id"><?php echo $PMF_LANG['ad_entry_solution_id']; ?>:</label>
                        <div class="controls">
                            <input name="solution_id" id="solution_id" style="width: 50px; text-align: right;" size="5"
                                   readonly="readonly" value="<?php echo (isset($faqData['solution_id']) ? $faqData['solution_id'] : $faq->getSolutionId()); ?>"  />
                        </div>
                    </div>
                </fieldset>
                <!-- Permissions -->
                <fieldset class="form-inline">
                    <?php if ($faqConfig->get('security.permLevel') != 'basic'): ?>
                    <div class="control-group">
                        <label class="control-label" for="grouppermission"><?php echo $PMF_LANG['ad_entry_grouppermission']; ?></label>
                        <div class="controls">
                            <label class="radio">
                                <input type="radio" id="grouppermission" name="grouppermission"  value="all" <?php echo ($allGroups ? 'checked="checked"' : ''); ?>/>
                                <?php echo $PMF_LANG['ad_entry_all_groups']; ?>
                            </label>
                            <label class="radio">
                                <input type="radio" name="grouppermission"  value="restricted" <?php echo ($restrictedGroups ? 'checked="checked"' : ''); ?>/>
                                <?php echo $PMF_LANG['ad_entry_restricted_groups']; ?>
                                <select name="restricted_groups" size="1" class="input-medium">
                                    <?php echo $user->perm->getAllGroupsOptions($groupPermission); ?>
                                </select>
                            </label>
                        </div>
                    </div>
                    <?php else: ?>
                    <input type="hidden" name="grouppermission"  value="all" />
                    <?php endif; ?>
                    <div class="control-group">
                        <label class="control-label" for="userpermission"><?php echo $PMF_LANG['ad_entry_userpermission']; ?></label>
                        <div class="controls">
                            <label class="radio">
                                <input type="radio" id="userpermission" name="userpermission"  value="all" <?php echo ($allUsers ? 'checked="checked"' : ''); ?>/>
                                <?php echo $PMF_LANG['ad_entry_all_users']; ?>
                            </label>
                            <label class="radio">
                                <input type="radio" name="userpermission"  value="restricted" <?php echo ($restrictedUsers ? 'checked="checked"' : ''); ?>/>
                                <?php echo $PMF_LANG['ad_entry_restricted_users']; ?>
                                <select name="restricted_users" size="1" class="input-medium">
                                    <?php echo $user->getAllUserOptions($userPermission[0]); ?>
                                </select>
                            </label>
                        </div>
                    </div>
                </fieldset>
            </div>
            </form>
        </div>
















<?php

    if ($permission["changebtrevs"]) {

        $revisions = $faq->getRevisionIds($faqData['id'], $faqData['lang']);
        if (count($revisions)) {
?>
            <form id="selectRevision" name="selectRevision" method="post"
                  action="?action=editentry&amp;id=<?php echo $faqData['id'] ?>&amp;lang=<?php echo $faqData['lang'] ?>">
            <fieldset>
                <legend><?php echo $PMF_LANG['ad_changerev']; ?></legend>
                <p>
                    <select name="revisionid_selected" onchange="selectRevision.submit();">
                        <option value="<?php echo $faqData['revision_id']; ?>">
                            <?php echo $PMF_LANG['ad_changerev']; ?>
                        </option>
    <?php foreach ($revisions as $revisionId => $revisionData) { ?>
                        <option value="<?php echo $revisionData['revision_id']; ?>" <?php if ($selectedRevisionId == $revisionData['revision_id']) { echo 'selected="selected"'; } ?> >
                            <?php printf(
                                '%s 1.%d: %s - %s',
                                $PMF_LANG['ad_entry_revision'],
                                $revisionData['revision_id'],
                                PMF_Date::createIsoDate($revisionData['datum']),
                                $revisionData['author']
                            ); ?>
                        </option>
    <?php } ?>
                    </select>
                </p>
            </fieldset>
            </form>
<?php
        }

        if (isset($selectedRevisionId) &&
            isset($faqData['revision_id']) &&
            $selectedRevisionId != $faqData['revision_id']) {

            $faq->language = $faqData['lang'];
            $faq->getRecord($faqData['id'], $selectedRevisionId, true);
            $faqData         = $faq->faqRecord;
            $faqData['tags'] = implode(',', $tagging->getAllTagsById($faqData['id']));
        }
    }
?>
                <?php if ($faqConfig->get('main.enableGoogleTranslation') === true):  ?>
                <fieldset class="form-horizontal">
                    <legend>
                        <a href="javascript:void(0);" onclick="javascript:toggleFieldset('Translations');">
                            <?php echo $PMF_LANG["ad_menu_translations"]; ?>
                        </a>
                    </legend>

                    <div class="control-group hide" id="editTranslations">
                        <?php
                        if ($faqConfig->get('main.googleTranslationKey') == '') {
                            echo $PMF_LANG["msgNoGoogleApiKeyFound"];
                        } else {
                            ?>
                            <label class="control-label" for="langTo"><?php echo $PMF_LANG["ad_entry_locale"]; ?>:</label>
                            <div class="controls">
                                <?php echo PMF_Language::selectLanguages($faqData['lang'], false, array(), 'langTo'); ?>
                            </div>

                            <input type="hidden" name="used_translated_languages" id="used_translated_languages" value="" />
                            <div id="getedTranslations">
                            </div>
                            <?php
                        }
                        ?>
                    </div>
                </fieldset>
                <?php endif; ?>


    
    <script type="text/javascript">
    /* <![CDATA[ */

    function extractor(query) {
        var result = /([^,]+)$/.exec(query);
        if(result && result[1])
            return result[1].trim();
        return '';
    }
    $('#tags').typeahead({
        source: function (query, process) {
            return $.get("index.php?action=ajax&ajax=tags_list", { q: query }, function (data) {
                return process(data.tags);
            });
        },
        updater: function(item) {
            return this.$element.val().replace(/[^,]*$/,'')+item+',';
        },
        matcher: function (item) {
            var tquery = extractor(this.query);
            if(!tquery) return false;
            return ~item.toLowerCase().indexOf(tquery)
        },
        highlighter: function (item) {
            var query = extractor(this.query).replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&')
            return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
                return '<strong>' + match + '</strong>'
            })
        }
    });

    $(function() {
        $('.date-pick').datePicker();

        $('#date').datePicker({startDate: '1900-01-01'});
        $('#date').bind('dateSelected', function (e, date, $td, status)
        {
            if(status) {
                var dt = new Date();

                var hours   = dt.getHours();
                var minutes = dt.getMinutes();
                
                $('#date').val(date.asString() +
                               ' ' + (hours < 10 ? '0' : '') + hours +
                               ':' + (minutes < 10 ? '0' : '') + minutes);
            }
        });

        $('#keywords').focus(function() { showHelp('keywords'); });
        $('#tags').focus(function() { showHelp('tags'); });
        
    });

    /**
     * Toggle fieldsets
     *
     * @param fieldset ID of the fieldset
     *
     * @return void
     */
    function toggleFieldset(fieldset) {
        if ($('#edit' + fieldset).css('display') == 'none') {
            $('#edit' + fieldset).fadeIn('fast');
        } else {
            $('#edit' + fieldset).fadeOut('fast');
        }
    }
    
    /**
     * Toggle input date container show
     *
     * @return void
     */
    function showIDContainer() {
        var display = 0 == arguments.length || !!arguments[0] ? 'block' : 'none';
        $('#recordDateInputContainer').attr('style', 'display: ' + display);
    }

    function setRecordDate(how) {
        if('dateActualize' == how) {
            showIDContainer(false);
            $('#date').val('');
        } else if ('dateKeep' == how) {
            showIDContainer(false);
            $('#date').val('<?php echo $faqData['date']; ?>');
        } else if('dateCustomize' == how) {
            showIDContainer(true);
            $('#date').val('');
        }
    }
        
    /**
     * Shows help for keywords and tags input fields
     *
     * @param option
     *
     * @return void
     */
    function showHelp(option) {
        $('#' + option + 'Help').fadeIn(500);
        $('#' + option + 'Help').fadeOut(2500);
    }
    /* ]]> */
    </script>
<?php    
        if ($faqConfig->get('main.enableGoogleTranslation') === true) {
?>        
    <script src="https://www.google.com/jsapi?key=<?php echo $faqConfig->get('main.googleTranslationKey')?>" type="text/javascript"></script>
    <script type="text/javascript">
    /* <![CDATA[ */
    google.load("language", "1");

    var langFromSelect = $("#lang");
    var langToSelect   = $("#langTo");
        
    // Add a onChange to the faq language select
    langFromSelect.change(
        function() {
            $("#langTo").val($(this).val());
        }
    );
    
    // Add a onChange to the translation select
    langToSelect.change(
        function() {
            var langTo = $(this).val();

            if (! $('#question_translated_' + langTo).val()) {

                // Add language value
                var languages = $('#used_translated_languages').val();
                if (languages == '') {
                    $('#used_translated_languages').val(langTo);
                } else {
                    $('#used_translated_languages').val(languages + ',' + langTo);
                }
               
                var fieldset = $('<fieldset></fieldset>')
                    .append($('<legend></legend>').html($("#langTo option:selected").text()));

                // Text for question
                fieldset
                    .append(
                        '<div class="control-group">' +
                        '<label class="control-label" for="question_translated_' + langTo + '">' +
                        '<?php echo $PMF_LANG["ad_entry_theme"]; ?>' +
                        '</label>' +
                        '<div class="controls">' +
                        '<input type="text" id="question_translated_' + langTo + '" name="question_translated_' + langTo + '" maxlength="255" >' +
                        '</div>' +
                        '</div>'
                    );


                // Textarea for answer
                fieldset
                    .append(
                        '<div class="control-group">' +
                        '<label class="control-label" for="answer_translated_' + langTo + '">' +
                        '<?php echo $PMF_LANG["ad_entry_content"]; ?>' +
                        '</label>' +
                        '<div class="controls">' +
                        '<textarea id="answer_translated_' + langTo + '" name="answer_translated_' + langTo + '" cols="80" rows="3" ></textarea>' +
                        '</div>' +
                        '</div>'
                    );


                // Textarea for keywords
                fieldset
                    .append(
                        '<div class="control-group">' +
                        '<label class="control-label" for="keywords_translated_' + langTo + '">' +
                        '<?php echo $PMF_LANG["ad_entry_keywords"]; ?>' +
                        '</label>' +
                        '<div class="controls">' +
                        '<textarea id="keywords_translated_' + langTo + '" name="keywords_translated_' + langTo + '" cols="80" rows="3" ></textarea>' +
                        '</div>' +
                        '</div>'
                    );

                $('#getedTranslations').append(fieldset);
                
                // Call the init for a new tinyMCE
                createTinyMCE('answer_translated_' + langTo);
            }

            var langFrom = $('#lang').val();
            
            // Set the translated text
            getGoogleTranslation('#question_translated_' + langTo, $('#question').val(), langFrom, langTo);
            getGoogleTranslation('answer_translated_' + langTo, tinymce.get('answer').getContent(), langFrom, langTo, 'answer');

            // Keywords must be translated separately
            $('#keywords_translated_' + langTo).val('');
            var words = new String($('#keywords').val()).split(',');
            for (var i = 0; i < words.length; i++) {
                var word = $.trim(words[i]);
                getGoogleTranslation('#keywords_translated_' + langTo, word, langFrom, langTo, 'keywords');
            }
        }
    );

    /**
     * Call the init for a new tinyMCE
     *
     * @param field  id of the input to fill.
     *
     * @return void
     */
    function createTinyMCE(field) {
        tinyMCE.init({
            // General options
            mode     : "exact",
            language : "<?php echo (PMF_Language::isASupportedTinyMCELanguage($LANGCODE) ? $LANGCODE : 'en'); ?>",
            elements : field,
            width    : "720",
            height   : "480",
            theme    : "advanced",
            plugins  : "spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,syntaxhl,phpmyfaq",
            theme_advanced_blockformats : "p,div,h1,h2,h3,h4,h5,h6,blockquote,dt,dd,code,samp",
                
            // Theme options
            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
            theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,phpmyfaq,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,syntaxhl,|,insertdate,inserttime,preview,|,forecolor,backcolor",
            theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen,help",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",
            relative_urls           : false,
            convert_urls            : false,
            remove_linebreaks       : false, 
            use_native_selects      : true,
            extended_valid_elements : "code",
                
            // Ajax-based file manager
            file_browser_callback : "ajaxfilemanager",
                
            // Example content CSS (should be your site CSS)
            content_css : "../assets/template/<?php echo PMF_Template::getTplSetName(); ?>/css/style.css",
                
            // Drop lists for link/image/media/template dialogs
            template_external_list_url : "js/template_list.js",
                
            // Replace values for the template plugin
            template_replace_values : {
                username : "<?php echo $user->userdata->get('display_name'); ?>",
                user_id  : "<?php echo $user->userdata->get('user_id'); ?>"
            }
        });
    }    
    /* ]]> */
    </script>
<?php
    }
} elseif ($permission["editbt"] != 1 && !PMF_Db::checkOnEmptyTable('faqcategories')) {
    echo $PMF_LANG["err_NotAuth"];
} elseif ($permission["editbt"] && PMF_Db::checkOnEmptyTable('faqcategories')) {
    echo $PMF_LANG["no_cats"];
}
Back to Top