1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
You may not change or alter any portion of this comment or credits |
5
|
|
|
of supporting developers from this source code or any supporting source code |
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Module: Equipment |
15
|
|
|
* |
16
|
|
|
* @category Module |
17
|
|
|
* @package equipment |
18
|
|
|
* @author XOOPS Development Team <[email protected]> - <http://xoops.org> |
19
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
20
|
|
|
* @license GPL 2.0 or later |
21
|
|
|
* @link https://xoops.org/ |
22
|
|
|
* @since 1.0.0 |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
use Xmf\Request; |
26
|
|
|
use Xmf\Module\Helper; |
27
|
|
|
use Xmf\Module\Helper\Permission; |
28
|
|
|
|
29
|
|
|
require_once __DIR__ . '/../../include/config.php'; |
30
|
|
|
|
31
|
|
|
$moduleDirName = basename(dirname(dirname(__DIR__))); |
32
|
|
|
$moduleHelper = Xmf\Module\Helper::getHelper($moduleDirName); |
33
|
|
|
$permHelper = new Permission($moduleDirName); |
34
|
|
|
|
35
|
|
|
xoops_load('XoopsFormLoader'); |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Class EquipmentCustomerForm |
39
|
|
|
*/ |
40
|
|
|
class EquipmentCustomerForm extends XoopsThemeForm |
41
|
|
|
{ |
42
|
|
|
public $targetObject; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Constructor |
46
|
|
|
* |
47
|
|
|
* @param $target |
48
|
|
|
*/ |
49
|
|
|
public function __construct($target) |
50
|
|
|
{ |
51
|
|
|
global $moduleHelper; |
52
|
|
|
$this->targetObject = $target; |
53
|
|
|
|
54
|
|
|
$title = $this->targetObject->isNew() ? sprintf(AM_EQUIPMENT_CUSTOMER_ADD) : sprintf(AM_EQUIPMENT_CUSTOMER_EDIT); |
55
|
|
|
parent::__construct($title, 'form', xoops_getenv('PHP_SELF'), 'post', true); |
56
|
|
|
$this->setExtra('enctype="multipart/form-data"'); |
57
|
|
|
|
58
|
|
|
//include ID field, it's needed so the module knows if it is a new form or an edited form |
59
|
|
|
|
60
|
|
|
$hidden = new XoopsFormHidden('id', $this->targetObject->getVar('id')); |
61
|
|
|
$this->addElement($hidden); |
62
|
|
|
unset($hidden); |
63
|
|
|
|
64
|
|
|
// Id |
65
|
|
|
$this->addElement(new XoopsFormLabel(AM_EQUIPMENT_CUSTOMER_ID, $this->targetObject->getVar('id'), 'id')); |
66
|
|
|
// First |
67
|
|
|
$this->addElement(new XoopsFormText(AM_EQUIPMENT_CUSTOMER_FIRST, 'first', 50, 255, $this->targetObject->getVar('first')), false); |
68
|
|
|
// Last |
69
|
|
|
$this->addElement(new XoopsFormText(AM_EQUIPMENT_CUSTOMER_LAST, 'last', 50, 255, $this->targetObject->getVar('last')), false); |
70
|
|
|
// Address |
71
|
|
|
$this->addElement(new XoopsFormText(AM_EQUIPMENT_CUSTOMER_ADDRESS, 'address', 50, 255, $this->targetObject->getVar('address')), false); |
72
|
|
|
// City |
73
|
|
|
$this->addElement(new XoopsFormText(AM_EQUIPMENT_CUSTOMER_CITY, 'city', 50, 255, $this->targetObject->getVar('city')), false); |
74
|
|
|
// Country |
75
|
|
|
$this->addElement(new XoopsFormText(AM_EQUIPMENT_CUSTOMER_COUNTRY, 'country', 50, 255, $this->targetObject->getVar('country')), false); |
76
|
|
|
// Created |
77
|
|
|
$this->addElement(new XoopsFormTextDateSelect(AM_EQUIPMENT_CUSTOMER_CREATED, 'created', '', strtotime($this->targetObject->getVar('created')))); |
78
|
|
|
|
79
|
|
|
//permissions |
80
|
|
|
/** @var XoopsMemberHandler $memberHandler */ |
81
|
|
|
$memberHandler = xoops_getHandler('member'); |
82
|
|
|
$groupList = $memberHandler->getGroupList(); |
83
|
|
|
/** @var XoopsGroupPermHandler $gpermHandler */ |
84
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
85
|
|
|
$fullList = array_keys($groupList); |
|
|
|
|
86
|
|
|
|
87
|
|
|
//======================================================================== |
88
|
|
|
|
89
|
|
|
$mid = $GLOBALS['xoopsModule']->mid(); |
90
|
|
|
$groupIdAdmin = 0; |
91
|
|
|
$groupNameAdmin = ''; |
92
|
|
|
|
93
|
|
|
// create admin checkbox |
94
|
|
|
foreach ($groupList as $groupId => $groupName) { |
95
|
|
|
if ($groupId == XOOPS_GROUP_ADMIN) { |
96
|
|
|
$groupIdAdmin = $groupId; |
97
|
|
|
$groupNameAdmin = $groupName; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$selectPermAdmin = new XoopsFormCheckBox('', 'admin', XOOPS_GROUP_ADMIN); |
102
|
|
|
$selectPermAdmin->addOption($groupIdAdmin, $groupNameAdmin); |
103
|
|
|
$selectPermAdmin->setExtra("disabled='disabled'"); //comment it out, if you want to allow to remove permissions for the admin |
104
|
|
|
|
105
|
|
|
// ******************************************************** |
106
|
|
|
// permission view items |
107
|
|
|
$cat_gperms_read = $gpermHandler->getGroupIds('equipment_view', $this->targetObject->getVar('id'), $mid); |
108
|
|
|
$arr_cat_gperms_read = $this->targetObject->isNew() ? '0' : $cat_gperms_read; |
109
|
|
|
|
110
|
|
|
$permsTray = new XoopsFormElementTray(AM_EQUIPMENT_PERMISSIONS_VIEW, ''); |
111
|
|
|
|
112
|
|
|
$selectAllReadCheckbox = new XoopsFormCheckBox('', 'adminbox1', 1); |
113
|
|
|
$selectAllReadCheckbox->addOption('allbox', _AM_SYSTEM_ALL); |
114
|
|
|
$selectAllReadCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox1\" , \"groupsRead[]\");' "); |
115
|
|
|
$selectAllReadCheckbox->setClass('xo-checkall'); |
116
|
|
|
$permsTray->addElement($selectAllReadCheckbox); |
117
|
|
|
|
118
|
|
|
// checkbox webmaster |
119
|
|
|
$permsTray->addElement($selectPermAdmin, false); |
120
|
|
|
// checkboxes other groups |
121
|
|
|
//$selectPerm = new XoopsFormCheckBox('', 'cat_gperms_read', $arr_cat_gperms_read); |
|
|
|
|
122
|
|
|
//$selectPerm = new XoopsFormCheckBox('', 'groupsRead[]', $this->targetObject->getGroupsRead()); |
|
|
|
|
123
|
|
|
$selectPerm = new XoopsFormCheckBox('', 'groupsRead[]', $arr_cat_gperms_read); |
124
|
|
|
foreach ($groupList as $groupId => $groupName) { |
125
|
|
|
if ($groupId != XOOPS_GROUP_ADMIN) { |
126
|
|
|
$selectPerm->addOption($groupId, $groupName); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
$permsTray->addElement($selectPerm, false); |
130
|
|
|
$this->addElement($permsTray, false); |
131
|
|
|
unset($permsTray, $selectPerm); |
132
|
|
|
|
133
|
|
|
// ******************************************************** |
134
|
|
|
// permission submit item |
135
|
|
|
$cat_gperms_create = $gpermHandler->getGroupIds('equipment_submit', $this->targetObject->getVar('id'), $mid); |
136
|
|
|
$arr_cat_gperms_create = $this->targetObject->isNew() ? '0' : $cat_gperms_create; |
137
|
|
|
|
138
|
|
|
$permsTray = new XoopsFormElementTray(AM_EQUIPMENT_PERMISSIONS_SUBMIT, ''); |
139
|
|
|
|
140
|
|
|
$selectAllSubmitCheckbox = new XoopsFormCheckBox('', 'adminbox2', 1); |
141
|
|
|
$selectAllSubmitCheckbox->addOption('allbox', _AM_SYSTEM_ALL); |
142
|
|
|
$selectAllSubmitCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox2\" , \"groupsSubmit[]\");' "); |
143
|
|
|
$selectAllSubmitCheckbox->setClass('xo-checkall'); |
144
|
|
|
$permsTray->addElement($selectAllSubmitCheckbox); |
145
|
|
|
|
146
|
|
|
// checkbox webmaster |
147
|
|
|
$permsTray->addElement($selectPermAdmin, false); |
148
|
|
|
// checkboxes other groups |
149
|
|
|
//$selectPerm = new XoopsFormCheckBox('', 'cat_gperms_create', $arr_cat_gperms_create); |
|
|
|
|
150
|
|
|
$selectPerm = new XoopsFormCheckBox('', 'groupsSubmit[]', $arr_cat_gperms_create); |
151
|
|
|
foreach ($groupList as $groupId => $groupName) { |
152
|
|
|
if ($groupId != XOOPS_GROUP_ADMIN) { |
153
|
|
|
$selectPerm->addOption($groupId, $groupName); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
$permsTray->addElement($selectPerm, false); |
157
|
|
|
$this->addElement($permsTray, false); |
158
|
|
|
unset($permsTray, $selectPerm); |
159
|
|
|
|
160
|
|
|
// ******************************************************** |
161
|
|
|
// permission approve items |
162
|
|
|
$cat_gperms_admin = $gpermHandler->getGroupIds('equipment_approve', $this->targetObject->getVar('id'), $mid); |
163
|
|
|
$arr_cat_gperms_admin = $this->targetObject->isNew() ? '0' : $cat_gperms_admin; |
164
|
|
|
|
165
|
|
|
$permsTray = new XoopsFormElementTray(AM_EQUIPMENT_PERMISSIONS_APPROVE, ''); |
166
|
|
|
|
167
|
|
|
$selectAllModerateCheckbox = new XoopsFormCheckBox('', 'adminbox3', 1); |
168
|
|
|
$selectAllModerateCheckbox->addOption('allbox', _AM_SYSTEM_ALL); |
169
|
|
|
$selectAllModerateCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox3\" , \"groupsModeration[]\");' "); |
170
|
|
|
$selectAllModerateCheckbox->setClass('xo-checkall'); |
171
|
|
|
$permsTray->addElement($selectAllModerateCheckbox); |
172
|
|
|
|
173
|
|
|
// checkbox webmaster |
174
|
|
|
$permsTray->addElement($selectPermAdmin, false); |
175
|
|
|
// checkboxes other groups |
176
|
|
|
//$selectPerm = new XoopsFormCheckBox('', 'cat_gperms_admin', $arr_cat_gperms_admin); |
|
|
|
|
177
|
|
|
$selectPerm = new XoopsFormCheckBox('', 'groupsModeration[]', $arr_cat_gperms_admin); |
178
|
|
View Code Duplication |
foreach ($groupList as $groupId => $groupName) { |
|
|
|
|
179
|
|
|
if ($groupId != XOOPS_GROUP_ADMIN && $groupId != XOOPS_GROUP_ANONYMOUS) { |
180
|
|
|
$selectPerm->addOption($groupId, $groupName); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
$permsTray->addElement($selectPerm, false); |
184
|
|
|
$this->addElement($permsTray, false); |
185
|
|
|
unset($permsTray, $selectPerm); |
186
|
|
|
|
187
|
|
|
//========================================================================= |
188
|
|
|
$this->addElement(new XoopsFormHidden('op', 'save')); |
189
|
|
|
$this->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.