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

instr.php (3 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
include_once __DIR__ . '/class/tree.php';
8
9
// Объявляем объекты
10
$insinstrHandler = xoops_getModuleHandler('instruction', 'instruction');
11
$inscatHandler   = xoops_getModuleHandler('category', 'instruction');
12
$inspageHandler  = xoops_getModuleHandler('page', 'instruction');
13
14
$instrid = isset($_GET['id']) ? (int)$_GET['id'] : 0;
15
16
// Существует ли такая инструкция
17
$criteria = new CriteriaCompo();
18
$criteria->add(new Criteria('instrid', $instrid));
19
$criteria->add(new Criteria('status ', '0', '>'));
20
if (0 == $insinstrHandler->getCount($criteria)) {
21
    redirect_header('index.php', 3, _MD_INSTRUCTION_INSTRNOTEXIST);
22
    exit();
23
}
24
//
25
unset($criteria);
26
27
// Находим данные об инструкции
28
$objInsinstr = $insinstrHandler->get($instrid);
29
30
// Задание тайтла
31
$xoopsOption['xoops_pagetitle'] = $GLOBALS['xoopsModule']->name() . ' - ' . $objInsinstr->getVar('title');
32
// Шаблон
33
$GLOBALS['xoopsOption']['template_main'] = $moduleDirName . '_instr.tpl';
34
// Заголовок
35
include_once $GLOBALS['xoops']->path('header.php');
36
// Стили
37
$xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/style.css');
38
// Скрипты
39
$xoTheme->addScript(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/js/tree.js');
40
41
// Права на просмотр инструкции
42
$categories = InstructionUtility::getItemIds();
43 View Code Duplication
if (!in_array($objInsinstr->getVar('cid'), $categories)) {
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...
44
    redirect_header(XOOPS_URL . '/modules/' . $moduleDirName . '/', 3, _NOPERM);
45
    exit();
46
}
47
48
// Массив данных об инструкции
49
$instrs = [];
50
// ID инструкции
51
$instrs['instrid'] = $objInsinstr->getVar('instrid');
52
// Название страницы
53
$instrs['title'] = $objInsinstr->getVar('title');
54
// Описание
55
$instrs['description'] = $objInsinstr->getVar('description');
56
// Если админ, рисуем админлинк
57
if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid())) {
58
    $instrs['adminlink'] = '&nbsp;<a href="'
59
                           . XOOPS_URL
60
                           . '/modules/'
61
                           . $moduleDirName
62
                           . '/admin/instr.php?op=editinstr&instrid='
63
                           . $instrid
64
                           . '"><img style="width:16px;" src="./assets/icons/edit_mini.png" alt='
65
                           . _EDIT
66
                           . ' title='
67
                           . _EDIT
68
                           . '></a>&nbsp;<a href="'
69
                           . XOOPS_URL
70
                           . '/modules/'
71
                           . $moduleDirName
72
                           . '/admin/instr.php?op=delinstr&instrid='
73
                           . $instrid
74
                           . '"><img style="width:16px;" src="./assets/icons/delete_mini.png" alt='
75
                           . _DELETE
76
                           . ' title='
77
                           . _DELETE
78
                           . '></a>&nbsp;';
79
} else {
80
    $instrs['adminlink'] = '';
81
}
82
83
// Выводим в шаблон
84
$GLOBALS['xoopsTpl']->assign('insInstr', $instrs);
85
86
// Мета теги
87
$xoTheme->addMeta('meta', 'keywords', $objInsinstr->getVar('metakeywords'));
88
$xoTheme->addMeta('meta', 'description', $objInsinstr->getVar('metadescription'));
89
90
// Находим данные об категории
91
$objInscat = $inscatHandler->get($objInsinstr->getVar('cid'));
92
93
// Навигация
94
$criteria = new CriteriaCompo();
95
$criteria->setSort('weight ASC, title');
96
$criteria->setOrder('ASC');
97
$inscat_arr    = $inscatHandler->getall($criteria);
98
$mytree        = new XoopsObjectTree($inscat_arr, 'cid', 'pid');
99
$nav_parent_id = $mytree->getAllParent($objInsinstr->getVar('cid'));
100
$titre_page    = $nav_parent_id;
101
$nav_parent_id = array_reverse($nav_parent_id);
102
$navigation    = '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/">' . $GLOBALS['xoopsModule']->name() . '</a>&nbsp;:&nbsp;';
103 View Code Duplication
foreach (array_keys($nav_parent_id) as $i) {
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...
104
    $navigation .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/index.php?cid=' . $nav_parent_id[$i]->getVar('cid') . '">' . $nav_parent_id[$i]->getVar('title') . '</a>&nbsp;:&nbsp;';
105
}
106
$navigation .= '<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/index.php?cid=' . $objInscat->getVar('cid') . '">' . $objInscat->getVar('title') . '</a>&nbsp;:&nbsp;';
107
$navigation .= $objInsinstr->getVar('title');
108
$xoopsTpl->assign('insNav', $navigation);
109
//
110
unset($criteria);
111
112
// Список страниц в данной инструкции
113
$criteria = new CriteriaCompo();
114
$criteria->add(new Criteria('instrid', $instrid, '='));
115
$criteria->add(new Criteria('status ', '0', '>'));
116
$criteria->setSort('weight');
117
$criteria->setOrder('ASC');
118
$ins_page = $inspageHandler->getall($criteria);
119
unset($criteria);
120
// Инициализируем
121
$instree = new InstructionTree($ins_page, 'pageid', 'pid');
122
// Выводим список страниц в шаблон
123
$GLOBALS['xoopsTpl']->assign('insListPage', $instree->makePagesUser());
124
125
// Языковые константы
126
$xoopsTpl->assign('lang_listpages', _MD_INSTRUCTION_LISTPAGES);
127
$xoopsTpl->assign('lang_menu', _MD_INSTRUCTION_MENU);
128
129
// Теги
130
if (xoops_getModuleOption('usetag', 'instruction')) {
131
    include_once $GLOBALS['xoops']->path('modules/tag/include/tagbar.php');
132
    $xoopsTpl->assign('tags', true);
133
    $xoopsTpl->assign('tagbar', tagBar($instrid, 0));
134
} else {
135
    $xoopsTpl->assign('tags', false);
136
}
137
138
// Рейтинг
139 View Code Duplication
if (xoops_getModuleOption('userat', 'instruction')) {
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...
140
    $xoopsTpl->assign('insUserat', true);
141
} else {
142
    $xoopsTpl->assign('insUserat', false);
143
}
144
145
// Подвал
146
include_once $GLOBALS['xoops']->path('footer.php');
147