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