Completed
Pull Request — master (#48)
by Gino
03:19
created

AdminXoopsCode::getAdminAddNavigation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 28 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: AdminXoopsCode.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
/**
26
 * Class AdminXoopsCode.
27
 */
28
class AdminXoopsCode
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
29
{    	
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
30
	/*
31
    * @var string
32
    */
33
    private $xoopscode;
34
	
35
	/*
36
    *  @public function constructor
37
    *  @param null
38
    */
39
    /**
40
     *
41
     */
42
    public function __construct()
43
    {
44
        $this->phpcode = TDMCreatePhpCode::getInstance();
0 ignored issues
show
Bug introduced by
The property phpcode does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
45
		$this->xoopscode = TDMCreateXoopsCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateXoopsCode::getInstance() of type object<TDMCreateXoopsCode> is incompatible with the declared type string of property $xoopscode.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
    }
47
48
    /*
49
    *  @static function &getInstance
50
    *  @param null
51
    */
52
    /**
53
     * @return AdminXoopsCode
54
     */
55
    public static function &getInstance()
56
    {
57
        static $instance = false;
58
        if (!$instance) {
59
            $instance = new self();
60
        }
61
62
        return $instance;
63
    }
64
65
    /*
66
     *  @public function getAdminTemplateMain
67
     *  @param $moduleDirname
68
     *  @param $tableName
69
	 *
70
     *  @return string
71
     */
72
    public function getAdminTemplateMain($moduleDirname, $tableName)
73
    {
74
        return "\$templateMain = '{$moduleDirname}_admin_{$tableName}.tpl';\n";
75
    }
76
77
    /*
78
     *  @public function getAdminTemplateMain
79
     *  @param $language
80
     *  @param $tableName
81
	 *  @param $stuTableSoleName
82
     *  @param $type
83
	 *
84
     *  @return string
85
     */
86
    public function getAdminItemButton($language, $tableName, $stuTableSoleName, $op = '?op=new', $type = 'add')
87
    {
88
        $stuType = strtoupper($type);
89
		$adminMenu = '$adminMenu->addItemButton(';
90
		if($type === 'add') {
91
			$ret = $adminMenu."{$language}ADD_{$stuTableSoleName}, '{$tableName}.php{$op}', '{$type}');\n";
92
		} else {
93
			$ret = $adminMenu."{$language}{$stuTableSoleName}_{$stuType}, '{$tableName}.php{$op}', '{$type}');\n";
94
		}
95
96
        return $ret;
97
    }
98
99
    /**
100
     *  @public function getAdminAddNavigation
101
     *
102
     *  @param $tableName
103
     *
104
     *  @return string
105
     */
106
    public function getAdminAddNavigation($tableName)
107
    {        
108
        return "\$adminMenu->addNavigation('{$tableName}.php')";
109
    }
110
111
    /**
112
     *  @public function getAdminObjHandlerCreate
113
     *
114
     *  @param string $tableName
115
     *
116
     *  @return string
117
     */
118
    public function getAdminObjHandlerCreate($tableName)
119
    {
120
        $ret = <<<EOT
121
        \${$tableName}Obj =& \${$tableName}Handler->create();\n
122
EOT;
123
124
        return $ret;
125
    }
126
127
    /*
128
    *  @public function getXoopsCodeAddInfoBox
129
    *  @param $language
130
    *  
131
    *  @return string
132
    */
133
    public function getXoopsCodeAddInfoBox($language)
134
    {
135
        return "\$adminMenu->addInfoBox({$language});\n";
136
    }
137
138
    /*
139
    *  @public function getXoopsCodeAddInfoBoxLine
140
    *  @param $language
141
    *  @param $label
142
    *  @param $var
143
    *  
144
    *  @return string
145
    */
146 View Code Duplication
    public function getXoopsCodeAddInfoBoxLine($language, $label = '', $var = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
147
    {
148
        $aMenu = '$adminMenu->addInfoBoxLine(';
149
		if ($var != '') {
150
            $ret = $aMenu."{$language}, '<label>'.{$label}.'</label>', {$var});\n";
151
        } else {
152
            $ret = $aMenu."{$language}, '<label>'.{$label}.'</label>');\n";
153
        }
154
155
        return $ret;
156
    }
157
158
    /*
159
    *  @public function getXoopsCodeAddConfigBoxLine
160
    *  @param $language
161
    *  @param $label
162
    *  @param $var
163
    *  
164
    *  @return string
165
    */
166 View Code Duplication
    public function getXoopsCodeAddConfigBoxLine($language, $label = '', $var = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
167
    {
168
        $aMenu = '$adminMenu->addConfigBoxLine(';
169
		if ($var != '') {
170
            $ret = $aMenu."{$language}, '{$label}', {$var});\n";
171
        } else {
172
            $ret = $aMenu."{$language}, '{$label}');\n";
173
        }
174
175
        return $ret;
176
    }    
177
    
178
    /*
179
    *  @public function getXoopsCodeImageListSetVar
180
    *  @param string $moduleDirname
181
    *  @param string $tableName
182
    *  @param string $fieldName
183
    *  @return string
184
    */
185
    public function getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName)
186
    {
187
        $ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
188
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
189
        $ret .= $this->xoopscode->getXoopsCodeMediaUploader('uploader', "XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32'", $tableName, $moduleDirname);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeMediaUploader cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
190
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
191
        $ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n";
192
        $ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
193
        $contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
194
        $contentIf = "\$errors = \$uploader->getErrors();\n";
195
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
196
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt);
197
        $contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n";
198
199
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt);
200
201
        return $ret;
202
    }
203
204
    /*
205
    *  @public function getXoopsCodeUploadImageSetVar
206
    *  @param string $moduleDirname
207
    *  @param string $tableName
208
    *  @param string $fieldName
209
    *  @return string
210
    */
211
    public function getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain)
212
    {
213
        $stuModuleDirname = strtoupper($moduleDirname);
214
        $ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
215
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
216
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_IMAGE_PATH", $tableName, $moduleDirname);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeMediaUploader() does not seem to exist on object<AdminXoopsCode>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
217
218
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
219
        $ifelse = "\$extension = preg_replace( '/^.+\.([^.]+)$/sU' , '' , \$_FILES['attachedfile']['name']);\n";
220
        $ifelse .= "\$imgName = str_replace(' ', '', \$_POST['{$fieldMain}']).'.'.\$extension;\n";
221
        $ifelse .= "\$uploader->setPrefix(\$imgName);\n";
222
        $ifelse .= "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0]);\n";
223
        $contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
224
        $contentIf = "\$errors = \$uploader->getErrors();\n";
225
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
226
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt);
227
        $contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n";
228
229
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt);
230
231
        return $ret;
232
    }
233
234
    /*
235
    *  @public function getXoopsCodeFileSetVar
236
    *  @param $moduleDirname
237
    *  @param $tableName
238
    *  @param $fieldName
239
    *  @param $formatUrl
240
    *  @return string
241
    */
242
    public function getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName, $formatUrl = false)
243
    {
244
        $stuModuleDirname = strtoupper($moduleDirname);
245
        if ($formatUrl) {
246
            $ret = $this->getXoopsCodeSetVar($tableName, $fieldName, "formatUrl(\$_REQUEST['{$fieldName}'])");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeSetVar() does not exist on AdminXoopsCode. Did you maybe mean getXoopsCodeFileSetVar()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
247
            $ret .= $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
248
        } else {
249
            $ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
250
        }
251
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
252
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_FILES_PATH", $tableName, $moduleDirname);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeMediaUploader() does not seem to exist on object<AdminXoopsCode>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
253
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
254
        if ($formatUrl) {
255
            $ifelse = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
256
        } else {
257
            $ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n";
258
            $ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
259
        }
260
        $contentElse = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
261
        $contentIf = "\$errors = \$uploader->getErrors();\n";
262
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
263
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElse);
264
265
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse);
266
267
        return $ret;
268
    }
269
270
    /**
271
     *  @public function getAdminXoopsCodeSetVarsObjects
272
     *
273
     *  @param $moduleDirname
274
     *  @param $tableName
275
     *  @param $fields
276
     *
277
     *  @return string
278
     */
279
    public function getAdminXoopsCodeSetVarsObjects($moduleDirname, $tableName, $fields)
280
    {
281
        $ret = $this->phpcode->getPhpCodeCommentLine($comment = 'Set Vars', $var = '');
282
        foreach (array_keys($fields) as $f) {
283
            $fieldName = $fields[$f]->getVar('field_name');
284
            $fieldElement = $fields[$f]->getVar('field_element');
285
            if ($f > 0) { // If we want to hide field id
286
                switch ($fieldElement) {
287
                    case 5:
288
                    case 6:
289
                        $ret .= $this->xoopscode->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeCheckBoxOrRadioYNSetVar cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
290
                        break;
291
                    case 11:
292
                        $ret .= $this->xoopscode->getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeImageListSetVar cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
293
                        break;
294
                    case 12:
295
                        $ret .= $this->xoopscode->getXoopsCodeUrlFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeUrlFileSetVar cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
296
                        break;
297
                    case 13:
298
                        if (1 == $fields[$f]->getVar('field_main')) {
299
                            $fieldMain = $fieldName;
300
                        }
301
                        $ret .= $this->xoopscode->getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
0 ignored issues
show
Bug introduced by
The variable $fieldMain does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The method getXoopsCodeUploadImageSetVar cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
302
                        break;
303
                    case 14:
304
                        $ret .= $this->xoopscode->getXoopsCodeUploadFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeUploadFileSetVar cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
305
                        break;
306
                    case 15:
307
                        $ret .= $this->xoopscode->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeTextDateSelectSetVar cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
308
                        break;
309
                    default:
310
                        $ret .= $this->xoopscode->getXoopsCodeSimpleSetVar($tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeSimpleSetVar cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
311
                        break;
312
                }
313
            }
314
        }
315
316
        return $ret;
317
    }
318
319
    /**
320
     *  @public function getAdminXoopsCodeXoopsSecurity
321
     *
322
     *  @param $tableName
323
     *
324
     *  @return string
325
     */
326
    public function getAdminXoopsCodeXoopsSecurity($tableName)
327
    {
328
        $ret = <<<EOT
329
        if ( !\$GLOBALS['xoopsSecurity']->check() ) {
330
			redirect_header('{$tableName}.php', 3, implode(',', \$GLOBALS['xoopsSecurity']->getErrors()));
331
        }\n
332
EOT;
333
334
        return $ret;
335
    }
336
337
    /*
338
    *  @public function getAdminXoopsCodeInsertData
339
    *  @param $tableName
340
    *  @param $language
341
    *  @return string
342
    */
343
    public function getAdminXoopsCodeInsertData($tableName, $language)
344
    {
345
        $ret = <<<EOT
346
        // Insert Data
347
        if (\${$tableName}Handler->insert(\${$tableName}Obj)) {
348
			redirect_header('{$tableName}.php?op=list', 2, {$language}FORM_OK);
349
        }\n
350
EOT;
351
352
        return $ret;
353
    }
354
355
    /**
356
     *  @public function getAdminXoopsCodeGetFormError
357
     *
358
     *  @param $tableName
359
     *
360
     *  @return string
361
     */
362
    public function getAdminXoopsCodeGetFormError($tableName)
363
    {
364
        $ret = <<<EOT
365
        // Get Form
366
        \$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors());
367
        \$form =& \${$tableName}Obj->getForm();
368
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n
369
EOT;
370
371
        return $ret;
372
    }
373
374
    /**
375
     *  @public function getAdminXoopsCodeGetFormId
376
     *
377
     *  @param string $tableName
378
     *  @param string $fieldId
379
     *
380
     *  @return string
381
     */
382
    public function getAdminXoopsCodeGetFormId($tableName, $fieldId)
383
    {
384
        $ret = <<<EOT
385
        // Get Form
386
        \${$tableName}Obj = \${$tableName}Handler->get(\${$fieldId});
387
        \$form = \${$tableName}Obj->getForm();
388
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n
389
EOT;
390
391
        return $ret;
392
    }
393
394
    /**
395
     *  @public function getAdminXoopsCodeGetObjHandlerId
396
     *
397
     *  @param string $tableName
398
     *  @param string $fieldId
399
     *
400
     *  @return string
401
     */
402
    public function getAdminXoopsCodeGetObjHandlerId($tableName, $fieldId)
403
    {
404
        $ret = <<<EOT
405
        \${$tableName}Obj =& \${$tableName}Handler->get(\${$fieldId});\n
406
EOT;
407
408
        return $ret;
409
    }
410
411
    /*
412
    *  @public function getAdminXoopsCodeDelete
413
    *  @param string $tableName
414
    *  @param string $language
415
    *  @param string $fieldId
416
    *  @param string $fieldMain
417
    *  @return string
418
    */
419 View Code Duplication
    public function getAdminXoopsCodeDelete($tableName, $language, $fieldId, $fieldMain)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
420
    {
421
        $ret = <<<EOT
422
    case 'delete':
423
        \${$tableName}Obj =& \${$tableName}Handler->get(\${$fieldId});
424
        if (isset(\$_REQUEST['ok']) && 1 == \$_REQUEST['ok']) {
425
            if ( !\$GLOBALS['xoopsSecurity']->check() ) {
426
                redirect_header('{$tableName}.php', 3, implode(', ', \$GLOBALS['xoopsSecurity']->getErrors()));
427
            }
428
            if (\${$tableName}Handler->delete(\${$tableName}Obj)) {
429
                redirect_header('{$tableName}.php', 3, {$language}FORMDELOK);
430
            } else {
431
                echo \${$tableName}Obj->getHtmlErrors();
432
            }
433
        } else {
434
            xoops_confirm(array('ok' => 1, '{$fieldId}' => \${$fieldId}, 'op' => 'delete'), \$_SERVER['REQUEST_URI'], sprintf({$language}FORMSUREDEL, \${$tableName}Obj->getVar('{$fieldMain}')));
435
        }
436
    break;\n
437
EOT;
438
439
        return $ret;
440
    }
441
442
    /*
443
    *  @public function getAdminXoopsCodeUpdate
444
    *  @param string $moduleDirname
445
    *  @param string $tableName
446
    *  @param string $language
447
    *  @param string $fieldId
448
    *  @param string $fieldMain
449
    *  @return string
450
    */
451 View Code Duplication
    public function getAdminXoopsCodeUpdate($moduleDirname, $tableName, $language, $fieldId, $fieldMain)
0 ignored issues
show
Unused Code introduced by
The parameter $language is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $fieldMain is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
452
    {
453
        $upModuleName = strtoupper($moduleDirname);
454
        $ret = <<<EOT
455
    case 'update':
456
        if (isset(\${$fieldId})) {
457
            \${$tableName}Obj =& \${$tableName}Handler->get(\${$fieldId});
458
        }
459
        \${$tableName}Obj->setVar("\${$tableName}_display", \$_POST["\${$tableName}_display"]);
460
461
        if (\${$tableName}Handler->insert(\${$tableName}Obj)) {
462
            redirect_header("\${$tableName}.php", 3, _AM_{$upModuleName}_FORMOK);
463
        }
464
        echo \${$tableName}Obj->getHtmlErrors();
465
    break;\n
466
EOT;
467
468
        return $ret;
469
    }
470
}
471