Completed
Push — master ( d19713...8239ac )
by Michael
05:12
created

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
use Xmf\Request;
4
5
require_once __DIR__ . '/header.php';
6
7
// Пагинатор
8
include_once $GLOBALS['xoops']->path('class/pagenav.php');
9
10
// Объявляем объекты
11
$insinstrHandler = xoops_getModuleHandler('instruction', 'instruction');
12
$inscatHandler   = xoops_getModuleHandler('category', 'instruction');
13
//$inspageHandler = xoops_getModuleHandler( 'page', 'instruction' );
14
15
// Задание тайтла
16
$xoopsOption['xoops_pagetitle'] = $GLOBALS['xoopsModule']->name();
17
// Шаблон
18
$GLOBALS['xoopsOption']['template_main'] = $moduleDirName . '_index.tpl';
19
// Заголовок
20
include_once $GLOBALS['xoops']->path('header.php');
21
// Стили
22
$xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/style.css');
23
//
24
$cid = isset($_GET['cid']) ? (int)$_GET['cid'] : 0;
25
//
26
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0;
27
//
28
$limit = xoops_getModuleOption('perpagemain', 'instruction');
29
// Права на просмотр
30
$categories = InstructionUtility::getItemIds();
31
// Права на добавление
32
$cat_submit = InstructionUtility::getItemIds($moduleDirName . '_submit');
33
// Права на редактирование
34
$cat_edit = InstructionUtility::getItemIds($moduleDirName . '_edit');
35
36
// Находим список категорий
37
$criteria = new CriteriaCompo();
38
$criteria->add(new Criteria('cid', '( ' . implode(', ', $categories) . ' )', 'IN'));
39
$criteria->setSort('weight ASC, title');
40
$criteria->setOrder('ASC');
41
$inscat_arr = $inscatHandler->getall($criteria);
42
unset($criteria);
43
$mytree = new XoopsObjectTree($inscat_arr, 'cid', 'pid');
44
// Выводим в шаблон
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
//$GLOBALS['xoopsTpl']->assign('insFormSelCat', $mytree->makeSelBox('cid', 'title', '--', $cid, true, 0, "onChange='javascript: document.insformselcat.submit()'"));
46
47
48
if (InstructionUtility::checkVerXoops($module, '2.5.9')) {
49
    $cat_select = $mytree->makeSelectElement('cid', 'title', '--', $cid, true, 0, "onChange='javascript: document.insformselcat.submit()'", '');
50
    $GLOBALS['xoopsTpl']->assign('insFormSelCat', $cat_select->render());
51
} else {
52
    $cat_select = $mytree->makeSelBox('cid', 'title', '--', $cid, true, 0, "onChange='javascript: document.insformselcat.submit()'");
53
    $GLOBALS['xoopsTpl']->assign('insFormSelCat', $cat_select);
54
}
55
56
57
58
// Находим список всех инструкций
59
// Критерий выборки
60
$criteria = new CriteriaCompo();
61
// Все активные
62
$criteria->add(new Criteria('status', '0', '>'));
63
// Если есть категория
64
if ($cid) {
65
    // Если нельзя просматривать эту категорию
66
    if (!in_array($cid, $categories)) {
67
        redirect_header('index.php', 3, _MD_INSTRUCTION_NOPERM_CAT);
68
    }
69
    $criteria->add(new Criteria('cid', $cid, '='));
70
    // Иначе находим список всех
71
} else {
72
    $criteria->add(new Criteria('cid', '( ' . implode(', ', $categories) . ' )', 'IN'));
73
}
74
75
// Число инструкций, удовлетворяющих данному условию
76
$numrows = $insinstrHandler->getCount($criteria);
77
// Число выборки
78
$criteria->setLimit($limit);
79
// Начинасть с данного элемента
80
$criteria->setStart($start);
81
// Сортировать по
82
$criteria->setSort('instrid');
83
// Порядок сортировки
84
$criteria->setOrder('DESC');
85
// Находим все инструкции
86
$instr_arr = $insinstrHandler->getall($criteria);
87
// Если записей больше чем $limit, то выводим пагинатор
88 View Code Duplication
if ($numrows > $limit) {
89
    $pagenav = new XoopsPageNav($numrows, $limit, $start, 'start', 'cid=' . $cid);
90
    $pagenav = $pagenav->renderNav(4);
91
} else {
92
    $pagenav = '';
93
}
94
// Выводим пагинатор в шаблон
95
$GLOBALS['xoopsTpl']->assign('insPagenav', $pagenav);
96
97
// Мета-теги страницы
98
$index_metakeywords = [];
99
$index_metadescript = [];
100
101
// Если есть записи
102
if ($numrows > 0) {
103
    $class = 'odd';
104
    foreach (array_keys($instr_arr) as $i) {
105
106
        //
107
        $class = ('even' == $class) ? 'odd' : 'even';
108
        // ID
109
        $insinstr_instrid = $instr_arr[$i]->getVar('instrid');
110
        // Название
111
        $insinstr_title = $instr_arr[$i]->getVar('title');
112
        // Статус
113
        $insinstr_status = $instr_arr[$i]->getVar('status');
114
        // Количество страниц
115
        $insinstr_pages = $instr_arr[$i]->getVar('pages');
116
        // Категория
117
        $insinstr_cid = $instr_arr[$i]->getVar('cid');
118
        $insinstr_cat = $inscatHandler->get($insinstr_cid);
119
        // Права на добавление
120
        $perm_submit = in_array($insinstr_cid, $cat_submit) ? true : false;
121
        // Права на редактирование
122
        $perm_edit = in_array($insinstr_cid, $cat_edit) ? true : false;
123
        //Мета-теги ключевых слов
124
        $insinstr_metakeywords = $instr_arr[$i]->getVar('metakeywords');
125
        // Если есть - добавляем в мета-теги страницы
126
        if ($insinstr_metakeywords) {
127
            $index_metakeywords[] = $insinstr_metakeywords;
128
        }
129
        // Мета-теги описания
130
        $insinstr_metadescript = $instr_arr[$i]->getVar('metadescription');
131
        // Если есть - добавляем в мета-теги страницы
132
        if ($insinstr_metadescript) {
133
            $index_metadescript[] = $insinstr_metadescript;
134
        }
135
136
        // Выводим в шаблон
137
        $GLOBALS['xoopsTpl']->append('insListInstr', ['instrid' => $insinstr_instrid, 'title' => $insinstr_title, 'status' => $insinstr_status, 'pages' => $insinstr_pages, 'ctitle' => $insinstr_cat->getVar('title'), 'cid' => $insinstr_cid, 'permsubmit' => $perm_submit, 'permedit' => $perm_edit, 'class' => $class]);
138
    }
139
140
    // Языковые константы
141
}
142
143
// Если есть мета-теги
144
if (count($index_metakeywords)) {
145
    $xoTheme->addMeta('meta', 'keywords', implode(', ', $index_metakeywords));
146
}
147
if (count($index_metadescript)) {
148
    $xoTheme->addMeta('meta', 'description', implode(', ', $index_metadescript));
149
}
150
151
// Подвал
152
include_once $GLOBALS['xoops']->path('footer.php');
153