1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace XoopsModules\Tdmdownloads; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* TDMDownload |
9
|
|
|
* |
10
|
|
|
* You may not change or alter any portion of this comment or credits |
11
|
|
|
* of supporting developers from this source code or any supporting source code |
12
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16
|
|
|
* |
17
|
|
|
* @copyright Gregory Mage (Aka Mage) |
18
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
19
|
|
|
* @author Gregory Mage (Aka Mage) |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
use Xmf\Module\Helper\Permission; |
23
|
|
|
|
24
|
|
|
/** @var Helper $helper */ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class Category |
28
|
|
|
* @package XoopsModules\Tdmdownloads |
29
|
|
|
*/ |
30
|
|
|
class Category extends \XoopsObject |
31
|
|
|
{ |
32
|
|
|
// constructor |
33
|
|
|
public $helper; |
34
|
|
|
public $permHelper; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Category constructor. |
38
|
|
|
*/ |
39
|
|
|
public function __construct() |
40
|
|
|
{ |
41
|
|
|
parent::__construct(); |
42
|
|
|
$this->helper = Helper::getInstance(); |
43
|
|
|
$this->permHelper = new Permission(); |
44
|
|
|
$this->initVar('cat_cid', \XOBJ_DTYPE_INT, null, false, 5); |
45
|
|
|
$this->initVar('cat_pid', \XOBJ_DTYPE_INT, null, false, 5); |
46
|
|
|
$this->initVar('cat_title', \XOBJ_DTYPE_TXTBOX, null, false); |
47
|
|
|
$this->initVar('cat_imgurl', \XOBJ_DTYPE_TXTBOX, null, false); |
48
|
|
|
$this->initVar('cat_description_main', \XOBJ_DTYPE_TXTAREA, null, false); |
49
|
|
|
// Pour autoriser le html |
50
|
|
|
$this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false); |
51
|
|
|
$this->initVar('cat_weight', \XOBJ_DTYPE_INT, 0, false, 11); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param null|\XoopsDatabase $db |
56
|
|
|
* @return mixed |
57
|
|
|
*/ |
58
|
|
|
public function getNewEnreg($db = null) |
59
|
|
|
{ |
60
|
|
|
$newEnreg = 0; |
61
|
|
|
/** @var \XoopsMySQLDatabase $db */ |
62
|
|
|
if (null !== $db) { |
63
|
|
|
$newEnreg = $db->getInsertId(); |
64
|
|
|
} |
65
|
|
|
return $newEnreg; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param bool $action |
70
|
|
|
* |
71
|
|
|
* @return \XoopsThemeForm |
72
|
|
|
*/ |
73
|
|
|
public function getForm($action = false) |
74
|
|
|
{ |
75
|
|
|
$helper = Helper::getInstance(); |
76
|
|
|
if (!$action) { |
77
|
|
|
$action = $_SERVER['REQUEST_URI']; |
78
|
|
|
} |
79
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
80
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
81
|
|
|
//nom du formulaire selon l'action (editer ou ajouter): |
82
|
|
|
$title = $this->isNew() ? \sprintf(_AM_TDMDOWNLOADS_FORMADD) : \sprintf(_AM_TDMDOWNLOADS_FORMEDIT); |
83
|
|
|
//création du formulaire |
84
|
|
|
$form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
85
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
86
|
|
|
//titre |
87
|
|
|
$form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMTITLE, 'cat_title', 50, 255, $this->getVar('cat_title')), true); |
|
|
|
|
88
|
|
|
//editeur |
89
|
|
|
$editorConfigs = []; |
90
|
|
|
$editorConfigs['name'] = 'cat_description_main'; |
91
|
|
|
$editorConfigs['value'] = $this->getVar('cat_description_main', 'e'); |
92
|
|
|
$editorConfigs['rows'] = 20; |
93
|
|
|
$editorConfigs['cols'] = 160; |
94
|
|
|
$editorConfigs['width'] = '100%'; |
95
|
|
|
$editorConfigs['height'] = '400px'; |
96
|
|
|
$editorConfigs['editor'] = $helper->getConfig('editor'); |
97
|
|
|
$form->addElement(new \XoopsFormEditor(_AM_TDMDOWNLOADS_FORMTEXT, 'cat_description_main', $editorConfigs), false); |
98
|
|
|
//image |
99
|
|
|
$categoryImage = $this->getVar('cat_imgurl') ?: 'blank.gif'; |
100
|
|
|
$uploadirectory = '/uploads/' . $moduleDirName . '/images/cats'; |
101
|
|
|
$imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG, '<br>'); |
102
|
|
|
$imgpath = \sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); |
103
|
|
|
$imageselect = new \XoopsFormSelect($imgpath, 'downloadscat_img', $categoryImage); |
104
|
|
|
$topics_array = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); |
105
|
|
|
foreach ($topics_array as $image) { |
106
|
|
|
$imageselect->addOption($image, $image); |
107
|
|
|
} |
108
|
|
|
$imageselect->setExtra("onchange='showImgSelected(\"image3\", \"downloadscat_img\", \"" . $uploadirectory . '", "", "' . XOOPS_URL . "\")'"); |
109
|
|
|
$imgtray->addElement($imageselect, false); |
110
|
|
|
$imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadirectory . '/' . $categoryImage . "' name='image3' id='image3' alt=''>")); |
111
|
|
|
$fileseltray = new \XoopsFormElementTray('', '<br>'); |
112
|
|
|
$fileseltray->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxuploadsize')), false); |
113
|
|
|
$fileseltray->addElement(new \XoopsFormLabel(''), false); |
114
|
|
|
$imgtray->addElement($fileseltray); |
115
|
|
|
$form->addElement($imgtray); |
116
|
|
|
// Pour faire une sous-catégorie |
117
|
|
|
$categoryHandler = Helper::getInstance()->getHandler('Category'); |
118
|
|
|
$criteria = new \CriteriaCompo(); |
119
|
|
|
$criteria->setSort('cat_weight ASC, cat_title'); |
120
|
|
|
$criteria->setOrder('ASC'); |
121
|
|
|
$downloadscatArray = $categoryHandler->getAll($criteria); |
122
|
|
|
$mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid'); |
123
|
|
|
$form->addElement($mytree->makeSelectElement('cat_pid', 'cat_title', '--', $this->getVar('cat_pid'), true, 0, '', _AM_TDMDOWNLOADS_FORMINCAT), true); |
|
|
|
|
124
|
|
|
//poids de la catégorie |
125
|
|
|
$form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMWEIGHT, 'cat_weight', 5, 5, $this->getVar('cat_weight', 'e')), false); |
126
|
|
|
//permissions |
127
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
128
|
|
|
$memberHandler = \xoops_getHandler('member'); |
129
|
|
|
$group_list = $memberHandler->getGroupList(); |
130
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
131
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
132
|
|
|
$full_list = \array_keys($group_list); |
133
|
|
|
global $xoopsModule; |
134
|
|
|
if (!$this->isNew()) { |
135
|
|
|
$groups_ids_view = $grouppermHandler->getGroupIds('tdmdownloads_view', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); |
136
|
|
|
$groups_ids_submit = $grouppermHandler->getGroupIds('tdmdownloads_submit', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); |
137
|
|
|
$groups_ids_download = $grouppermHandler->getGroupIds('tdmdownloads_download', $this->getVar('cat_cid'), $xoopsModule->getVar('mid')); |
138
|
|
|
$groups_ids_view = \array_values($groups_ids_view); |
139
|
|
|
$groups_news_can_view_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_VIEW_DSC, 'groups_view[]', $groups_ids_view); |
140
|
|
|
$groups_ids_submit = \array_values($groups_ids_submit); |
141
|
|
|
$groups_news_can_submit_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_SUBMIT_DSC, 'groups_submit[]', $groups_ids_submit); |
142
|
|
|
$groups_ids_download = \array_values($groups_ids_download); |
143
|
|
|
$groups_news_can_download_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_DOWNLOAD_DSC, 'groups_download[]', $groups_ids_download); |
144
|
|
|
} else { |
145
|
|
|
$groups_news_can_view_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_VIEW_DSC, 'groups_view[]', $full_list); |
146
|
|
|
$groups_news_can_submit_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_SUBMIT_DSC, 'groups_submit[]', $full_list); |
147
|
|
|
$groups_news_can_download_checkbox = new \XoopsFormCheckBox(_AM_TDMDOWNLOADS_PERM_DOWNLOAD_DSC, 'groups_download[]', $full_list); |
148
|
|
|
} |
149
|
|
|
// pour voir |
150
|
|
|
$groups_news_can_view_checkbox->addOptionArray($group_list); |
151
|
|
|
$form->addElement($groups_news_can_view_checkbox); |
152
|
|
|
// pour editer |
153
|
|
|
$groups_news_can_submit_checkbox->addOptionArray($group_list); |
154
|
|
|
$form->addElement($groups_news_can_submit_checkbox); |
155
|
|
|
// pour télécharger |
156
|
|
|
if (1 == $helper->getConfig('permission_download')) { |
157
|
|
|
$groups_news_can_download_checkbox->addOptionArray($group_list); |
158
|
|
|
$form->addElement($groups_news_can_download_checkbox); |
159
|
|
|
} |
160
|
|
|
// pour passer "cid" si on modifie la catégorie |
161
|
|
|
if (!$this->isNew()) { |
162
|
|
|
$form->addElement(new \XoopsFormHidden('cat_cid', $this->getVar('cat_cid'))); |
|
|
|
|
163
|
|
|
$form->addElement(new \XoopsFormHidden('categorie_modified', true)); |
|
|
|
|
164
|
|
|
} |
165
|
|
|
//pour enregistrer le formulaire |
166
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'save_cat')); |
167
|
|
|
//boutton d'envoi du formulaire |
168
|
|
|
$form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', 'submit', false)); |
169
|
|
|
return $form; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|