Completed
Branch master (c92e39)
by Michael
02:32
created

open_index.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 */
8
9
include_once __DIR__ . '/header.php';
10
11
global $xoopsConfig, $xoopsModuleConfig, $xoopsModule;
12
13
// At which record shall we start for the Categories
14
$catstart = isset($_GET['catstart']) ? (int)$_GET['catstart'] : 0;
15
16
// At which record shall we start for the FAQs
17
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0;
18
19
// Creating the category handler object
20
$categoryHandler = sf_gethandler('category');
21
22
// Get the total number of categories
23
$totalCategories = count($categoryHandler->getCategories());
24
25
// Creating the faq handler object
26
$faqHandler = sf_gethandler('faq');
27
28
// Total number of published FAQ in the module
29
$totalFaqs = $faqHandler->getFaqsCount(-1, _SF_STATUS_OPENED);
30
if ($totalFaqs == 0) {
31
    redirect_header('request.php', 2, _MD_SF_NO_OPEN_QUESTION);
32
}
33
34
// Creating the categories objects
35
$categoriesObj = $categoryHandler->getCategories($xoopsModuleConfig['catperpage'], $catstart);
36
37
// If no categories are found, exit
38
$totalCategoriesOnPage = count($categoriesObj);
39
if ($totalCategoriesOnPage == 0) {
40
    redirect_header('javascript:history.go(-1)', 2, _AM_SF_NO_CAT_EXISTS);
41
}
42
43
$GLOBALS['xoopsOption']['template_main'] = 'smartfaq_index.tpl';
44
45
include_once XOOPS_ROOT_PATH . '/header.php';
46
include_once __DIR__ . '/footer.php';
47
48
//get all categories for future reference
49
$allcategories = $categoryHandler->getObjects(null, true);
50
51
// Arrays that will hold the informations passed on to smarty variables
52
$qnas       = array();
53
$categories = array();
54
$subcats    = $categoryHandler->getSubCats($categoriesObj);
55
$totalQnas  = $categoryHandler->faqsCount(0, array(_SF_STATUS_OPENED));
56
57
$faqHandler  = sf_gethandler('faq');
58
$last_qnaObj = $faqHandler->getLastPublishedByCat(array(_SF_STATUS_OPENED));
59
60
foreach ($categoriesObj as $cat_id => $category) {
61
    $total = 0;
62
    if (isset($subcats[$cat_id]) && count($subcats[$cat_id]) > 0) {
63 View Code Duplication
        foreach ($subcats[$cat_id] as $key => $subcat) {
64
            $subcat_id = $subcat->getVar('categoryid');
65
            if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) {
66
                if (isset($last_qnaObj[$subcat_id])) {
67
                    $subcat->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid'));
68
                    $subcat->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question(50) . '</a>');
69
                }
70
                $subcat->setVar('faqcount', $totalQnas[$subcat_id]);
71
                $categories[$cat_id]['subcats'][$subcat_id] = $subcat->toArray(null, true);
72
                $total                                      += $totalQnas[$subcat_id];
73
            }
74
        }
75
    }
76 View Code Duplication
    if (isset($totalQnas[$cat_id]) && $totalQnas[$cat_id] > 0) {
77
        $total += $totalQnas[$cat_id];
78
    }
79
    if ($total > 0) {
80
        $category->setVar('faqcount', $total);
81
        if (!isset($categories[$cat_id])) {
82
            $categories[$cat_id] = array();
83
        }
84
        $categories[$cat_id]                 = $category->toArray($categories[$cat_id], true);
85
        $categories[$cat_id]['categoryPath'] = $category->getCategoryPath();
86
    }
87
}
88
$xoopsTpl->assign('categories', $categories);
89
90
$displaylastfaqs = $xoopsModuleConfig['displaylastfaqs'];
91
if ($displaylastfaqs) {
92
    // Creating the last FAQs
93
    $faqsObj         = $faqHandler->getFaqs($xoopsModuleConfig['indexperpage'], $start, _SF_STATUS_OPENED);
94
    $totalQnasOnPage = count($faqsObj);
95
96 View Code Duplication
    if ($faqsObj) {
97
        $userids = array();
98
        foreach ($faqsObj as $key => $thisfaq) {
99
            $faqids[]                 = $thisfaq->getVar('faqid');
100
            $userids[$thisfaq->uid()] = 1;
101
        }
102
103
        $memberHandler = xoops_getHandler('member');
104
        $users         = $memberHandler->getUsers(new Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true);
105
        for ($i = 0; $i < $totalQnasOnPage; ++$i) {
106
            $faq = $faqsObj[$i]->toArray(null, $allcategories);
107
108
            $faq['adminlink'] = sf_getAdminLinks($faqsObj[$i]->faqid(), true);
109
110
            $faq['who_when'] = $faqsObj[$i]->getWhoAndWhen(null, $users);
111
112
            $xoopsTpl->append('faqs', $faq);
113
        }
114
    }
115
}
116
// Language constants
117
$moduleName =& $myts->displayTarea($xoopsModule->getVar('name'));
118
$xoopsTpl->assign(array(
119
                      'lang_on'       => _MD_SF_ON,
120
                      'lang_postedby' => _MD_SF_POSTEDBY,
121
                      'lang_total'    => $totalQnasOnPage,
122
                      'lang_faq'      => _MD_SF_FAQ,
123
                      'lang_datesub'  => _MD_SF_DATESUB,
124
                      'lang_hits'     => _MD_SF_HITS
125
                  ));
126
127
$moduleName =& $myts->displayTarea($xoopsModule->getVar('name'));
128
$xoopsTpl->assign('lang_mainhead', sprintf(_MD_SF_OPEN_WELCOME, $xoopsConfig['sitename']));
129
$xoopsTpl->assign('lang_mainintro', $myts->displayTarea($xoopsModuleConfig['openquestionintromsg'], 1));
130
$xoopsTpl->assign('lang_total', _MD_SF_TOTAL_QUESTIONS);
131
$xoopsTpl->assign('lang_home', _MD_SF_HOME);
132
$xoopsTpl->assign('lang_description', _MD_SF_DESCRIPTION);
133
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
134
$xoopsTpl->assign('sectionname', $moduleName);
135
$xoopsTpl->assign('whereInSection', "<a href='index.php'>" . $moduleName . '</a> > ' . _MD_SF_OPEN_SECTION);
136
137
$xoopsTpl->assign('displayFull', false);
138
$xoopsTpl->assign('displaylastfaqs', $xoopsModuleConfig['displaylastfaqs']);
139
$xoopsTpl->assign('display_categoryname', true);
140
141
$xoopsTpl->assign('lang_reads', _MD_SF_READS);
142
$xoopsTpl->assign('lang_smartfaqs', _MD_SF_SMARTFAQS);
143
$xoopsTpl->assign('lang_last_smartfaq', _MD_SF_LAST_SMARTFAQ);
144
$xoopsTpl->assign('lang_categories_summary', _MD_SF_INDEX_CATEGORIES_SUMMARY);
145
$xoopsTpl->assign('lang_categories_summary_info', _MD_SF_INDEX_CATEGORIES_QUESTIONS_SUMMARY_INFO);
146
$xoopsTpl->assign('lang_index_faqs', _MD_SF_INDEX_QUESTIONS);
147
$xoopsTpl->assign('lang_index_faqs_info', _MD_SF_INDEX_QUESTIONS_INFO);
148
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
149
150
// Category Navigation Bar
151
include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
152
$pagenav = new XoopsPageNav($totalCategories, $xoopsModuleConfig['catperpage'], $catstart, 'catstart', '');
153 View Code Duplication
if ($xoopsModuleConfig['useimagenavpage'] == 1) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
154
    $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
155
} else {
156
    $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
157
}
158
159
// FAQ Navigation Bar
160
$pagenav = new XoopsPageNav($totalFaqs, $xoopsModuleConfig['indexperpage'], $start, 'start', '');
161 View Code Duplication
if ($xoopsModuleConfig['useimagenavpage'] == 1) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
162
    $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
163
} else {
164
    $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
165
}
166
167
// Page Title Hack by marcan
168
$module_name = $myts->htmlSpecialChars($xoopsModule->getVar('name'));
169
$xoopsTpl->assign('xoops_pagetitle', $module_name . ' - ' . $category->getVar('name'));
170
// End Page Title Hack by marcan
171
172
include_once XOOPS_ROOT_PATH . '/footer.php';
173