Passed
Push — master ( 2744eb...81ba93 )
by Michael
02:46
created

include/displayfaqs.php (1 issue)

1
<?php
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 */
8
9
use XoopsModules\Smartfaq;
10
use XoopsModules\Smartfaq\Constants;
11
/** @var Smartfaq\Helper $helper */
12
$helper = Smartfaq\Helper::getInstance();
13
14
global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB,  $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
15
16
echo "<br>\n";
17
if (!isset($categoryid) || ($categoryid < 1)) {
18
    $faqs_title         = _AM_SF_PUBLISHEDFAQS;
19
    $faqs_info          = _AM_SF_PUBLISHED_DSC;
20
    $sel_cat            = -1;
21
    $pagenav_extra_args = '';
22
} else {
23
    $faqs_title         = _AM_SF_PUBLISHEDFAQS_CAT;
24
    $faqs_info          = _AM_SF_PUBLISHED_CAT_DSC;
25
    $sel_cat            = $categoryid;
26
    $pagenav_extra_args = "op=mod&categoryid=$categoryid";
27
}
28
29
Smartfaq\Utility::collapsableBar('toptable', 'toptableicon');
30
31
echo "<img id='toptableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a>&nbsp;" . $faqs_title . '</h3>';
32
echo "<div id='toptable'>";
33
echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $faqs_info . '</span>';
34
35
// Get the total number of published FAQs
36
$totalfaqs = $faqHandler->getFaqsCount($sel_cat, [Constants::SF_STATUS_PUBLISHED, Constants::SF_STATUS_NEW_ANSWER]);
37
38
// creating the FAQ objects that are published
39
$faqsObj         = $faqHandler->getAllPublished($helper->getConfig('perpage'), $startfaq, $sel_cat);
40
//$totalFaqsOnPage = count($faqsObj);
41
$allCats         = $categoryHandler->getObjects(null, true);
42
echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
43
echo '<tr>';
44
echo "<th width='40' class='bg3' align='center'><b>" . _AM_SF_ARTID . '</b></td>';
45
echo "<th width='20%' class='bg3' align='left'><b>" . _AM_SF_ARTCOLNAME . '</b></td>';
46
echo "<th class='bg3' align='left'><b>" . _AM_SF_QUESTION . '</b></td>';
47
48
echo "<th width='90' class='bg3' align='center'><b>" . _AM_SF_ASKED . '</b></td>';
49
echo "<th width='90' class='bg3' align='center'><b>" . _AM_SF_ANSWERED . '</b></td>';
50
51
echo "<th width='90' class='bg3' align='center'><b>" . _AM_SF_CREATED . '</b></td>';
52
echo "<th width='60' class='bg3' align='center'><b>" . _AM_SF_ACTION . '</b></td>';
53
echo '</tr>';
54
if ($totalfaqs > 0) {
55
    global $pathIcon16, $smartModuleConfig;
56
    foreach ($faqsObj as $iValue) {
57
        $categoryObj = $allCats[$iValue->categoryid()];
58
        $modify      = "<a href='faq.php?op=mod&amp;faqid=" . $iValue->faqid() . "'><img src='" . $pathIcon16 . '/edit.png' . "' title='" . _AM_SF_EDITART . "' alt='" . _AM_SF_EDITART . "'></a>";
59
        $delete      = "<a href='faq.php?op=del&amp;faqid=" . $iValue->faqid() . "'><img src='" . $pathIcon16 . '/delete.png' . "' title='" . _AM_SF_EDITART . "' alt='" . _AM_SF_DELETEART . "'></a>";
60
61
        //adding name of the Question Submitter
62
        $requester = Smartfaq\Utility::getLinkedUnameFromId($iValue->uid(), $smartModuleConfig['userealname']);
63
64
        //adding name of the Answer Submitter
65
        /** @var \XoopsModules\Smartfaq\AnswerHandler $answerHandler */
66
        $answerHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Answer');
67
68
        $criteria = new \CriteriaCompo();
69
        $criteria->add(new \Criteria('faqid', $iValue->faqid()));
70
        $criteria->add(new \Criteria('status', true));
71
72
        $answerObjects =& $answerHandler->getObjects($criteria, true);
73
74
        foreach (array_keys($answerObjects) as $j) {
75
            $answerObj = $answerObjects[$j];
76
        }
77
78
        if (isset($answerObj->vars['uid']['value'])) {
79
            $answerSubmitterID = $answerObj->vars['uid']['value'];
80
81
            $answerSubmitter = Smartfaq\Utility::getLinkedUnameFromId($answerSubmitterID, $smartModuleConfig['userealname']);
82
        } else {
83
            $answerSubmitter = '--------';
84
        }
85
86
        echo '<tr>';
87
        echo "<td class='head' align='center'>" . $iValue->faqid() . '</td>';
88
        echo "<td class='even' align='left'>" . $categoryObj->name() . '</td>';
89
        echo "<td class='even' align='left'><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/faq.php?faqid=' . $iValue->faqid() . "'>" . $iValue->question(100) . '</a></td>';
90
91
        echo "<td class='even' align='center'>" . $requester . '</td>';
92
        echo "<td class='even' align='center'>" . $answerSubmitter . '</td>';
93
94
        echo "<td class='even' align='center'>" . $iValue->datesub('s') . '</td>';
95
        echo "<td class='even' align='center'> $modify $delete </td>";
96
        echo '</tr>';
97
    }
98
} else {
99
    $faqid = -1;
100
    echo '<tr>';
101
    echo "<td class='head' align='center' colspan= '7'>" . _AM_SF_NOFAQS . '</td>';
102
    echo '</tr>';
103
}
104
echo "</table>\n";
105
echo "<br>\n";
106
107
$pagenav = new \XoopsPageNav($totalfaqs, $helper->getConfig('perpage'), $startfaq, 'startfaq', $pagenav_extra_args);
108
echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>';
109
echo '</div>';
110