Completed
Push — master ( 5fe85d...a4e09c )
by Michael
01:40
created

index.php (5 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
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' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
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
$moduleDirName = basename(__DIR__);
47
if (false !== ($moduleHelper = Xmf\Module\Helper::getHelper($moduleDirName))) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

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