forked from GregMage/xmdoc
/
docmanager.php
203 lines (180 loc) · 7.81 KB
/
docmanager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* xmdoc module
*
* @copyright XOOPS Project (https://xoops.org)
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Mage Gregory (AKA Mage)
*/
use Xmf\Request;
use Xmf\Module\Helper;
require_once dirname(dirname(__DIR__)) . '/mainfile.php';
require_once $GLOBALS['xoops']->path('class/template.php');
$xoopsTpl = new XoopsTpl();
include __DIR__ . '/include/common.php';
xoops_load('utility', basename(__DIR__));
include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
// Get Permission to submit
$viewPermissionCat = XmdocUtility::getPermissionCat('xmdoc_view');
// Get values
$search = Request::getString('search', '');
$reset = Request::getString('reset', '');
$select = Request::getString('select', '');
$sessionHelper = new Helper\Session();
$bootstrap = XOOPS_THEME_PATH . '/' . $GLOBALS['xoopsConfig']['theme_set'] . '/css/bootstrap.css';
$bootstrap_min = XOOPS_THEME_PATH . '/' . $GLOBALS['xoopsConfig']['theme_set'] . '/css/bootstrap.min.css';
if (file_exists($bootstrap) || file_exists($bootstrap_min)){
if (file_exists($bootstrap_min)){
$xoopsTpl->assign('bootstrap_css', XOOPS_THEME_URL . '/' . $GLOBALS['xoopsConfig']['theme_set'] . '/css/bootstrap.min.css');
} else {
$xoopsTpl->assign('bootstrap_css', XOOPS_THEME_URL . '/' . $GLOBALS['xoopsConfig']['theme_set'] . '/css/bootstrap.css');
}
} else{
$xoopsTpl->assign('bootstrap_css', '');
}
if (isset($_REQUEST['selectreset'])){
$sessionHelper->del('selectiondocs');
}
if (isset($_REQUEST['selDocs'])){
if (isset($_REQUEST['selDocs']) && is_array($_REQUEST['selDocs'])) {
if ($sessionHelper->get('selectiondocs') != false){
$arr_selectiondocs = $sessionHelper->get('selectiondocs');
} else {
$arr_selectiondocs = array();
}
foreach ($_REQUEST['selDocs'] as $index) {
if (!in_array($index, $arr_selectiondocs)){
$arr_selectiondocs[] = $index;
}
}
$sessionHelper->set('selectiondocs', $arr_selectiondocs);
}
}
if ($sessionHelper->get('selectiondocs') != False){
$xoopsTpl->assign('selected', true);
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('document_status', 1));
if (is_array($sessionHelper->get('selectiondocs'))){
$criteria->add(new Criteria('document_id', '(' . implode(',', $sessionHelper->get('selectiondocs')) . ')','IN'));
}
$criteria->setSort('document_weight ASC, document_name');
$criteria->setOrder('ASC');
$documentHandler->table_link = $documentHandler->db->prefix("xmdoc_category");
$documentHandler->field_link = "category_id";
$documentHandler->field_object = "document_category";
$seldoc_arr = $documentHandler->getByLink($criteria);
$seldoc_count = $documentHandler->getCount($criteria);
$xoopsTpl->assign('seldoc_count', $seldoc_count);
if ($seldoc_count > 0) {
$count = 1;
foreach (array_keys($seldoc_arr) as $i) {
$seldoc['name'] = $seldoc_arr[$i]->getVar('document_name');
$seldoc_img = $seldoc_arr[$i]->getVar('document_logo') ?: 'blank_doc.gif';
$seldoc['logo'] = '<img src="' . $url_logo_document . $seldoc_img . '" alt="' . $seldoc_img . '" style="max-width:100px" />';
$seldoc['count'] = $count;
$xoopsTpl->append_by_ref('seldoc', $seldoc);
unset($seldoc);
$count++;
}
} else {
$xoopsTpl->assign('error_message', _MA_XMDOC_ERROR_NODOCUMENT);
}
$reset = '';
}
if ($reset == ''){
$s_name = Request::getString('s_name', '');
$s_cat = Request::getInt('s_cat', 0);
} else {
$s_name = '';
$s_cat = 0;
}
$nb_limit = $helper->getConfig('general_perpage', 15);
// Get start pager
$start = Request::getInt('start', 0);
$form = new XoopsThemeForm('', 'form', 'docmanager.php', 'post', true);
// name
$form->addElement(new XoopsFormText(_MA_XMDOC_DOCUMENT_NAME, 's_name', 50, 255, $s_name));
// category
$category = new XoopsFormSelect(_MA_XMDOC_DOCUMENT_INCATEGORY, 's_cat', $s_cat);
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('category_status', 1));
$criteria->setSort('category_weight ASC, category_name');
$criteria->setOrder('ASC');
if (!empty($viewPermissionCat)){
$criteria->add(new Criteria('category_id', '(' . implode(',', $viewPermissionCat) . ')','IN'));
}
$category_arr = $categoryHandler->getall($criteria);
if (count($category_arr) == 0 || empty($viewPermissionCat)){
redirect_header(XOOPS_URL, 3, _MA_XMDOC_ERROR_NOACESSCATEGORY);
}
$category->addOption(0, _ALL);
foreach (array_keys($category_arr) as $i) {
$category->addOption($category_arr[$i]->getVar('category_id'), $category_arr[$i]->getVar('category_name'));
}
$form->addElement($category, true);
// search
$button = new XoopsFormElementTray('');
$button->addElement(new XoopsFormButton('', 'search', _SEARCH, 'submit'));
$button->addElement(new XoopsFormButton('', 'reset', _RESET, 'submit'));
$form->addElement($button);
$xoopsTpl->assign('form', $form->render());
if ($search != ''){
$arguments = 's_cat=' . $s_cat . '&';
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('document_status', 1));
if ($s_name != '') {
$criteria->add(new Criteria('document_name', '%' . $s_name . '%', 'LIKE'));
$arguments .= 's_name=' . $s_name . '&';
}
if ($s_cat != 0){
$criteria->add(new Criteria('document_category', $s_cat));
}
if (!empty($viewPermissionCat)){
$criteria->add(new Criteria('document_category', '(' . implode(',', $viewPermissionCat) . ')','IN'));
}
$criteria->setSort('document_weight ASC, document_name');
$criteria->setOrder('ASC');
$criteria->setStart($start);
$criteria->setLimit($nb_limit);
$documentHandler->table_link = $documentHandler->db->prefix("xmdoc_category");
$documentHandler->field_link = "category_id";
$documentHandler->field_object = "document_category";
$document_arr = $documentHandler->getByLink($criteria);
$document_count = $documentHandler->getCount($criteria);
$xoopsTpl->assign('document_count', $document_count);
if ($document_count > 0) {
foreach (array_keys($document_arr) as $i) {
$document_id = $document_arr[$i]->getVar('document_id');
$document['id'] = $document_id;
$document['name'] = $document_arr[$i]->getVar('document_name');
if (false == strpos($document_arr[$i]->getVar('document_description', 'e'), '[break]')){
$document['description'] = $document_arr[$i]->getVar('document_description', 'show');
}else{
$document['description'] = substr($document_arr[$i]->getVar('document_description', 'show'), 0, strpos($document_arr[$i]->getVar('document_description', 'show'),'[break]'));
}
$document['category'] = $document_arr[$i]->getVar('category_name');
$document['categoryid'] = $document_arr[$i]->getVar('document_category');
$document_img = $document_arr[$i]->getVar('document_logo') ?: 'blank_doc.gif';
$document['logo'] = '<img src="' . $url_logo_document . $document_img . '" alt="' . $document_img . '" style="max-width:100px" />';
$xoopsTpl->append_by_ref('document', $document);
unset($document);
}
// Display Page Navigation
if ($document_count > $nb_limit) {
include_once $GLOBALS['xoops']->path('class/pagenav.php');
$nav = new XoopsPageNav($document_count, $nb_limit, $start, 'start', 'search=Y&' . $arguments);
$xoopsTpl->assign('nav_menu', $nav->renderNav(4));
}
} else {
$xoopsTpl->assign('error_message', _MA_XMDOC_ERROR_NODOCUMENT);
}
}
$xoopsTpl->display('db:xmdoc_docmanager.tpl');