Skip to content

Commit a275a6f

Browse files
committed
updated permissions to handle multiple permissions / added permissions class and permissions handler
1 parent cb99ad5 commit a275a6f

51 files changed

Lines changed: 1458 additions & 481 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

_TODO.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ I moved files, where I do not know whether they are still needed into folder _ar
99

1010
TODOs:
1111

12+
check getXoopsFormSelectFile
13+
check getClassGetTableSolenameById
1214

15+
Class PreloadsCore - still needed?
1316

1417
Notifications:
1518
there are too much notification, which are not needed/working

class/Files/Admin/AdminHeader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class AdminHeader extends Files\CreateFile
3535
* @var mixed
3636
*/
3737
private $xc = null;
38+
/**
39+
* @var mixed
40+
*/
41+
private $pc = null;
3842

3943
/**
4044
* @public function constructor

class/Files/Admin/AdminIndex.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,17 @@ private function getAdminIndex($module)
103103
$ret .= $pc->getPhpCodeCommentLine('InfoBox Statistics');
104104
$ret .= $axc->getAxcAddInfoBox($language . 'STATISTICS');
105105
$ret .= $pc->getPhpCodeCommentLine('Info elements');
106+
$tableInstall = [];
106107
foreach (array_keys($tables) as $i) {
107108
$tableName = $tables[$i]->getVar('table_name');
108109
$tableInstall[] = $tables[$i]->getVar('table_install');
109110
$stuTableName = $languageThereAre . mb_strtoupper($tableName);
110111
$ucfTableName = ucfirst($tableName);
111-
$ret .= $axc->getAxcAddInfoBoxLine($language . 'STATISTICS', $stuTableName, "\$count{$ucfTableName}");
112+
$ret .= $axc->getAxcAddInfoBoxLine($stuTableName, "\$count{$ucfTableName}");
112113
}
113114

114115
if (null === $tableName) {
115-
$ret .= $axc->getAxcAddInfoBoxLine($language . 'STATISTICS', 'No statistics', '0');
116+
$ret .= $axc->getAxcAddInfoBoxLine('No statistics', '0');
116117
}
117118

118119
if (is_array($tables) && in_array(1, $tableInstall)) {

class/Files/Admin/AdminMenu.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private function getAdminMenuImagesPath($tables, $t)
144144
{
145145
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
146146
$ret = '';
147-
$fields = $this->getTableFields($tables[$t]->getVar('table_id'));
147+
$fields = $this->getTableFields($tables[$t]->getVar('table_mid'), $tables[$t]->getVar('table_id'));
148148
foreach (array_keys($fields) as $f) {
149149
$fieldElement = $fields[$f]->getVar('field_element');
150150
switch ($fieldElement) {
@@ -173,6 +173,7 @@ private function getAdminMenuList($module, $language, $langAbout, $menu)
173173
{
174174
$ret = '';
175175
$tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
176+
$tablePermissions = [];
176177
foreach (array_keys($tables) as $t) {
177178
$tablePermissions[] = $tables[$t]->getVar('table_permissions');
178179
if (1 == $tables[$t]->getVar('table_admin')) {

class/Files/Admin/AdminPermissions.php

Lines changed: 84 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ public static function getInstance()
6565
* @param mixed $tables
6666
* @param string $filename
6767
*
68-
* @return string
68+
* @return null
6969
*/
7070
public function write($module, $tables, $filename)
7171
{
7272
$this->setModule($module);
7373
$this->setTables($tables);
7474
$this->setFileName($filename);
75+
return null;
7576
}
7677

7778
/**
@@ -90,9 +91,10 @@ private function getPermissionsHeader($module, $language)
9091
$axc = Tdmcreate\Files\Admin\AdminXoopsCode::getInstance();
9192
$moduleDirname = $module->getVar('mod_dirname');
9293
$tables = $this->getTableTables($module->getVar('mod_id'));
94+
$tableNames = [];
9395
foreach (array_keys($tables) as $t) {
9496
if (1 == $tables[$t]->getVar('table_permissions')) {
95-
$tableName = $tables[$t]->getVar('table_name');
97+
$tableNames[] = $tables[$t]->getVar('table_name');
9698
}
9799
}
98100
$ret = $pc->getPhpCodeUseNamespace(['Xmf', 'Request'], '', '');
@@ -106,18 +108,16 @@ private function getPermissionsHeader($module, $language)
106108
$ret .= $pc->getBlankLine();
107109
$ret .= $xc->getXcXoopsRequest('op', 'op', 'global');
108110
$ret .= $pc->getBlankLine();
109-
$ret .= $pc->getPhpCodeCommentLine('Get handler');
110-
$ret .= $xc->getXoopsHandlerLine($tableName);
111-
$ret .= $pc->getBlankLine();
112111
$ret .= $pc->getPhpCodeCommentLine('Get Form');
113112
$ret .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsform/grouppermform', true);
114113
$ret .= $xc->getXcLoad('XoopsFormLoader');
115-
$optionsSelect = [
116-
'global' => "{$language}PERMISSIONS_GLOBAL",
117-
'approve' => "{$language}PERMISSIONS_APPROVE",
118-
'submit' => "{$language}PERMISSIONS_SUBMIT",
119-
'view' => "{$language}PERMISSIONS_VIEW",
120-
];
114+
$optionsSelect['global'] = "{$language}PERMISSIONS_GLOBAL";
115+
foreach ($tableNames as $tableName) {
116+
$ucfTablename = ucfirst($tableName);
117+
$optionsSelect["approve_{$tableName}"] = "{$language}PERMISSIONS_APPROVE . ' {$ucfTablename}'";
118+
$optionsSelect["submit_{$tableName}"] = "{$language}PERMISSIONS_SUBMIT . ' {$ucfTablename}'";
119+
$optionsSelect["view_{$tableName}"] = "{$language}PERMISSIONS_VIEW . ' {$ucfTablename}'";
120+
}
121121
$formSelect = $xc->getXoopsFormSelectExtraOptions('formSelect', '\'\'', 'op', $optionsSelect, 'onchange="document.fselperm.submit()"');
122122
$ret .= $cc->getXoopsSimpleForm('permTableForm', 'formSelect', $formSelect, '\'\'', 'fselperm', 'permissions');
123123

@@ -126,38 +126,48 @@ private function getPermissionsHeader($module, $language)
126126

127127
/**
128128
* @private function getPermissionsSwitch
129-
* @param $moduleDirname
129+
* @param $module
130130
* @param $language
131131
*
132132
* @return string
133133
*/
134-
private function getPermissionsSwitch($moduleDirname, $language)
134+
private function getPermissionsSwitch($module, $language)
135135
{
136136
$pc = Tdmcreate\Files\CreatePhpCode::getInstance();
137-
$cases = [
138-
'global' => [
137+
138+
$moduleDirname = $module->getVar('mod_dirname');
139+
$tables = $this->getTableTables($module->getVar('mod_id'));
140+
141+
$cases['global']= [
139142
"\$formTitle = {$language}PERMISSIONS_GLOBAL;",
140143
"\$permName = '{$moduleDirname}_ac';",
141144
"\$permDesc = {$language}PERMISSIONS_GLOBAL_DESC;",
142145
"\$globalPerms = array( '4' => {$language}PERMISSIONS_GLOBAL_4, '8' => {$language}PERMISSIONS_GLOBAL_8, '16' => {$language}PERMISSIONS_GLOBAL_16 );",
143-
],
144-
'approve' => [
145-
"\$formTitle = {$language}PERMISSIONS_APPROVE;",
146-
"\$permName = '{$moduleDirname}_approve';",
147-
"\$permDesc = {$language}PERMISSIONS_APPROVE_DESC;",
148-
],
149-
'submit' => [
150-
"\$formTitle = {$language}PERMISSIONS_SUBMIT;",
151-
"\$permName = '{$moduleDirname}_submit';",
152-
"\$permDesc = {$language}PERMISSIONS_SUBMIT_DESC;",
153-
],
154-
'view' => [
155-
"\$formTitle = {$language}PERMISSIONS_VIEW;",
156-
"\$permName = '{$moduleDirname}_view';",
157-
"\$permDesc = {$language}PERMISSIONS_VIEW_DESC;",
158-
],
159-
];
160-
146+
];
147+
foreach (array_keys($tables) as $t) {
148+
if (1 == $tables[$t]->getVar('table_permissions')) {
149+
$tableName = $tables[$t]->getVar('table_name');
150+
$ucfTablename = ucfirst($tableName);
151+
$cases["approve_{$tableName}"] = [
152+
"\$formTitle = {$language}PERMISSIONS_APPROVE;",
153+
"\$permName = '{$moduleDirname}_approve_{$tableName}';",
154+
"\$permDesc = {$language}PERMISSIONS_APPROVE_DESC . ' {$ucfTablename}';",
155+
"\$handler = \$helper->getHandler('{$tableName}');",
156+
];
157+
$cases["submit_{$tableName}"] = [
158+
"\$formTitle = {$language}PERMISSIONS_SUBMIT;",
159+
"\$permName = '{$moduleDirname}_submit_{$tableName}';",
160+
"\$permDesc = {$language}PERMISSIONS_SUBMIT_DESC . ' {$ucfTablename}';",
161+
"\$handler = \$helper->getHandler('{$tableName}');",
162+
];
163+
$cases["view_{$tableName}"] = [
164+
"\$formTitle = {$language}PERMISSIONS_VIEW;",
165+
"\$permName = '{$moduleDirname}_view_{$tableName}';",
166+
"\$permDesc = {$language}PERMISSIONS_VIEW_DESC . ' {$ucfTablename}';",
167+
"\$handler = \$helper->getHandler('{$tableName}');",
168+
];
169+
}
170+
}
161171
$contentSwitch = $pc->getPhpCodeCaseSwitch($cases, true, false, "\t");
162172

163173
return $pc->getPhpCodeSwitch('op', $contentSwitch);
@@ -173,50 +183,56 @@ private function getPermissionsSwitch($moduleDirname, $language)
173183
*/
174184
private function getPermissionsBody($module, $language)
175185
{
176-
$pc = Tdmcreate\Files\CreatePhpCode::getInstance();
177-
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
178-
$tables = $this->getTableTables($module->getVar('mod_id'));
179-
$tableName = '';
186+
$pc = Tdmcreate\Files\CreatePhpCode::getInstance();
187+
$xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
188+
$tables = $this->getTableTables($module->getVar('mod_id'));
189+
190+
$ret = $xc->getXcGetVar('moduleId', 'xoopsModule', 'mid');
191+
$ret .= $xc->getXcGroupPermForm('permform', '$formTitle', '$moduleId', '$permName', '$permDesc', "'admin/permissions.php'");
192+
$ret .= $xc->getXcEqualsOperator('$permFound', 'false');
193+
$foreach1 = $xc->getXcAddItem('permform', '$gPermId', '$gPermName', "\t");
194+
$if1 = $pc->getPhpCodeForeach('globalPerms', false, 'gPermId', 'gPermName', $foreach1, "\t");
195+
$if1 .= $xc->getXcTplAssign('form', '$permform->render()', true, "\t");
196+
$if1 .= $xc->getXcEqualsOperator('$permFound', 'true', null, false, "\t");
197+
$ret .= $pc->getPhpCodeConditions('$op', ' === ', "'global'", $if1, false);
198+
180199
foreach (array_keys($tables) as $t) {
181200
if (1 == $tables[$t]->getVar('table_permissions')) {
182201
$tableId = $tables[$t]->getVar('table_id');
183202
$tableMid = $tables[$t]->getVar('table_mid');
184203
$tableName = $tables[$t]->getVar('table_name');
185-
}
186-
}
187-
$ucfTableName = ucfirst($tableName);
188-
$fields = $this->getTableFields($tableMid, $tableId);
189-
$fieldId = 'id';
190-
$fieldMain = 'title';
191-
foreach (array_keys($fields) as $f) {
192-
$fieldName = $fields[$f]->getVar('field_name');
193-
if (0 == $f) {
194-
$fieldId = $fieldName;
195-
}
196-
if (1 == $fields[$f]->getVar('field_main')) {
197-
$fieldMain = $fieldName;
204+
$fields = $this->getTableFields($tableMid, $tableId);
205+
$fieldId = 'id';
206+
$fieldMain = 'title';
207+
foreach (array_keys($fields) as $f) {
208+
$fieldName = $fields[$f]->getVar('field_name');
209+
if (0 == $f) {
210+
$fieldId = $fieldName;
211+
}
212+
if (1 == $fields[$f]->getVar('field_main')) {
213+
$fieldMain = $fieldName;
214+
}
215+
}
216+
$if_count = $xc->getXcObjHandlerAll($tableName, $fieldMain, 0, 0, "\t\t");
217+
$getVar1 = $xc->getXcGetVar('', "{$tableName}All[\$i]", $fieldId, true);
218+
$getVar2 = $xc->getXcGetVar('', "{$tableName}All[\$i]", $fieldMain, true);
219+
$fe_content = $xc->getXcAddItem('permform', $getVar1, $getVar2, "\t");
220+
$if_table = $xc->getXcObjHandlerCount($tableName, "\t");
221+
$if_count .= $pc->getPhpCodeForeach("{$tableName}All", true, false, 'i', $fe_content, "\t\t");
222+
$if_count .= $xc->getXcTplAssign('form', '$permform->render()', true, "\t\t");
223+
$if_table .= $pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $if_count, false, "\t");
224+
$if_table .= $xc->getXcEqualsOperator('$permFound', 'true', null, false, "\t");
225+
$cond = "\$op === 'approve_{$tableName}' || \$op === 'submit_{$tableName}' || \$op === 'view_{$tableName}'";
226+
$ret .= $pc->getPhpCodeConditions($cond, '', '', $if_table, false);
198227
}
199228
}
200229

201-
$ret = $xc->getXcGetVar('moduleId', 'xoopsModule', 'mid');
202-
$ret .= $xc->getXcGroupPermForm('permform', '$formTitle', '$moduleId', '$permName', '$permDesc', "'admin/permissions.php'");
203-
$foreach1 = $xc->getXcAddItem('permform', '$gPermId', '$gPermName', "\t");
204-
$if1 = $pc->getPhpCodeForeach('globalPerms', false, 'gPermId', 'gPermName', $foreach1, "\t");
205-
$if1 .= $xc->getXcTplAssign('form', '$permform->render()', true, "\t");
206-
$else = $xc->getXcObjHandlerCount($tableName, "\t");
207-
$if2 = $xc->getXcObjHandlerAll($tableName, $fieldMain, 0, 0, "\t\t");
208-
$getVar1 = $xc->getXcGetVar('', "{$tableName}All[\$i]", $fieldId, true);
209-
$getVar2 = $xc->getXcGetVar('', "{$tableName}All[\$i]", $fieldMain, true);
210-
$foreach2 = $xc->getXcAddItem('permform', $getVar1, $getVar2, "\t") . "\r";
211-
$if2 .= $pc->getPhpCodeForeach("{$tableName}All", true, false, 'i', $foreach2, "\t\t");
212-
$if2 .= $xc->getXcTplAssign('form', '$permform->render()', true, "\t\t");
213-
$elseInter = $xc->getXcRedirectHeader($tableName, '?op=new', '3', "{$language}NO_PERMISSIONS_SET", true, "\t\t");
214-
$elseInter .= $this->getSimpleString("\t\texit();");
215-
$else .= $pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $if2, $elseInter, "\t");
216-
217-
$ret .= $pc->getPhpCodeConditions('$op', ' === ', "'global'", $if1, $else);
218230
$ret .= $pc->getPhpCodeUnset('permform');
219231

232+
$elseInter = $xc->getXcRedirectHeader("'permissions.php'", '', '3', "{$language}NO_PERMISSIONS_SET", false, "\t");
233+
$elseInter .= $this->getSimpleString("exit();", "\t");
234+
$ret .= $pc->getPhpCodeConditions('$permFound', ' !== ', 'true', $elseInter, false);
235+
220236
return $ret;
221237
}
222238

@@ -235,7 +251,7 @@ public function render()
235251
$language = $this->getLanguage($moduleDirname, 'AM');
236252
$content = $this->getHeaderFilesComments($module, $filename);
237253
$content .= $this->getPermissionsHeader($module, $language);
238-
$content .= $this->getPermissionsSwitch($moduleDirname, $language);
254+
$content .= $this->getPermissionsSwitch($module, $language);
239255
$content .= $this->getPermissionsBody($module, $language);
240256
$content .= $this->getInclude('footer');
241257

class/Files/Blocks/BlocksFiles.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ private function getBlocksShow($moduleDirname, $tableName, $tableFieldname, $fie
8383
{
8484
$pc = Tdmcreate\Files\CreatePhpCode::getInstance();
8585
$stuModuleDirname = mb_strtoupper($moduleDirname);
86-
$ucfModuleDirname = ucfirst($moduleDirname);
8786
$ret = $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname], '', '');
8887
$ret .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Helper'], '', '');
8988
$ret .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Constants']);
@@ -276,9 +275,11 @@ public function render()
276275
$moduleDirname = $module->getVar('mod_dirname');
277276
$tableName = $table->getVar('table_name');
278277
$tableFieldname = $table->getVar('table_fieldname');
279-
$tableCategory = $table->getVar('table_category');
280278
$language = $this->getLanguage($moduleDirname, 'MB');
281279
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
280+
$fieldId = null;
281+
$fieldParent = null;
282+
$fieldMain = null;
282283
foreach (array_keys($fields) as $f) {
283284
$fieldName = $fields[$f]->getVar('field_name');
284285
$fieldParent = $fields[$f]->getVar('field_parent');

0 commit comments

Comments
 (0)