Completed
Push — master ( aeaa5d...9fb24b )
by Gino
23:28 queued 09:34
created

AdminXoopsCode::getXoopsCodeMediaUploader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 4
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 extends AdminObjects
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
{
30
    /*
31
    *  @public function constructor
32
    *  @param null
33
    */
34
    /**
35
     *
36
     */
37
    public function __construct()
38
    {
39
        $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...
40
        $this->adminobjects = AdminObjects::getInstance();
0 ignored issues
show
Bug introduced by
The property adminobjects 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...
41
    }
42
43
    /*
44
    *  @static function &getInstance
45
    *  @param null
46
    */
47
    /**
48
     * @return AdminXoopsCode
49
     */
50
    public static function &getInstance()
51
    {
52
        static $instance = false;
53
        if (!$instance) {
54
            $instance = new self();
55
        }
56
57
        return $instance;
58
    }
59
60
    /*
61
    *  @public function getAdminTemplateMain
62
    *  @param $moduleDirname
63
    *  @param $tableName
64
    *  @return string
65
    */
66
    public function getAdminTemplateMain($moduleDirname, $tableName)
67
    {
68
        return "\$templateMain = '{$moduleDirname}_admin_{$tableName}.tpl';\n";
69
    }
70
71
    /*
72
    *  @public function getAdminTemplateMain
73
    *  @param $moduleDirname
74
    *  @param $tableName
75
    *  @param $admin
76
    *  @return string
77
    */
78
    public function getAdminItemButton($moduleDirname, $tableName, $admin = false)
0 ignored issues
show
Unused Code introduced by
The parameter $moduleDirname 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 $admin 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...
79
    {
80
        $ret = <<<EOT
81
        \$adminMenu->addItemButton({$language}ADD_{$stuTableSoleName}, '{$tableName}.php?op=new', 'add');
0 ignored issues
show
Bug introduced by
The variable $language does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $stuTableSoleName does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
82
        \$adminMenu->addItemButton({$language}{$stuTableName}_LIST, '{$tableName}.php', 'list');
0 ignored issues
show
Bug introduced by
The variable $stuTableName does not exist. Did you mean $tableName?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
83
        \$GLOBALS['xoopsTpl']->assign('navigation', \$adminMenu->addNavigation('{$tableName}.php'));
84
        \$GLOBALS['xoopsTpl']->assign('buttons', \$adminMenu->renderButton());\n
85
EOT;
86
87
        return $ret;
88
    }
89
90
    /**
91
     *  @public function getAdminAddNavigation
92
     *
93
     *  @param $tableName
94
     *
95
     *  @return string
96
     */
97
    public function getAdminAddNavigation($tableName)
98
    {
99
        $ret = <<<EOT
100
        \$GLOBALS['xoopsTpl']->assign('navigation', \$adminMenu->addNavigation('{$tableName}.php'));\n
101
EOT;
102
103
        return $ret;
104
    }
105
106
    /**
107
     *  @public function getAdminObjHandlerCreate
108
     *
109
     *  @param string $tableName
110
     *
111
     *  @return string
112
     */
113
    public function getAdminObjHandlerCreate($tableName)
114
    {
115
        $ret = <<<EOT
116
        \${$tableName}Obj =& \${$tableName}Handler->create();\n
117
EOT;
118
119
        return $ret;
120
    }
121
122
    /*
123
    *  @public function getXoopsCodeAddInfoBox
124
    *  @param $language
125
    *  
126
    *  @return string
127
    */
128
    public function getXoopsCodeAddInfoBox($language)
129
    {
130
        return "\$adminMenu->addInfoBox({$language});\n";
131
    }
132
133
    /*
134
    *  @public function getXoopsCodeAddInfoBoxLine
135
    *  @param $language
136
    *  @param $label
137
    *  @param $var
138
    *  
139
    *  @return string
140
    */
141 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...
142
    {
143
        if ($var != '') {
144
            $ret = "\$adminMenu->addInfoBoxLine({$language}, '<label>'.{$label}.'</label>', {$var});\n";
145
        } else {
146
            $ret = "\$adminMenu->addInfoBoxLine({$language}, '<label>'.{$label}.'</label>');\n";
147
        }
148
149
        return $ret;
150
    }
151
152
    /*
153
    *  @public function getXoopsCodeAddConfigBoxLine
154
    *  @param $language
155
    *  @param $label
156
    *  @param $var
157
    *  
158
    *  @return string
159
    */
160 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...
161
    {
162
        if ($var != '') {
163
            $ret = "\$adminMenu->addConfigBoxLine({$language}, '{$label}', {$var});\n";
164
        } else {
165
            $ret = "\$adminMenu->addConfigBoxLine({$language}, '{$label}');\n";
166
        }
167
168
        return $ret;
169
    }
170
171
    /*
172
    *  @public function getXoopsCodeItemButton
173
    *  @param $language
174
    *  @param $tableName
175
    *  @param $admin
176
    *  @return string
177
    */
178
    public function getXoopsCodeItemButton($language, $tableName, $tableSoleName, $op = '?op=new', $type = 'add')
179
    {
180
        $stuTableName = strtoupper($tableName);
181
        $stuTableSoleName = strtoupper($tableSoleName);
182
        $stuType = strtoupper($type);
183
        $aMIB = '$adminMenu->addItemButton(';
184
        if ($type = 'add') {
185
            $ret = $aMIB."{$language}{$stuType}_{$stuTableSoleName}, '{$tableName}.php{$op}', '{$type}');\n";
186
        } elseif ($type = 'list') {
187
            $ret = $aMIB."{$language}{$stuTableName}_{$stuType}, '{$tableName}.php', '{$type}');\n";
188
        } else {
189
            $ret = $aMIB."{$language}{$stuTableName}_{$stuType}, '{$tableName}.php', '{$type}');\n";
190
        }
191
192
        return $ret;
193
    }
194
195
    /*
196
    *  @public function getXoopsCodeGetConfig
197
    *  @param $var
198
    *  @param $dirPath
199
    *  @param $tableName
200
    *  @param $moduleDirname
201
    *  @return string
202
    */
203
    public function getXoopsCodeMediaUploader($var = '', $dirPath, $tableName, $moduleDirname)
204
    {
205
        return "\${$var} = new XoopsMediaUploader({$dirPath} . '/{$tableName}',
206
														\${$moduleDirname}->getConfig('mimetypes'),
207
                                                        \${$moduleDirname}->getConfig('maxsize'), null, null);\n";
208
    }
209
210
    /*
211
    *  @public function getXoopsCodeImageListSetVar
212
    *  @param string $moduleDirname
213
    *  @param string $tableName
214
    *  @param string $fieldName
215
    *  @return string
216
    */
217
    public function getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName)
218
    {
219
        $ret = $this->phpcode->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
220
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
221
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32'", $tableName, $moduleDirname);
222
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
223
        $ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n";
224
        $ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
225
        $contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
226
        $contentIf = "\$errors = \$uploader->getErrors();\n";
227
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
228
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt);
229
        $contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n";
230
231
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt);
232
233
        return $ret;
234
    }
235
236
    /*
237
    *  @public function getXoopsCodeUploadImageSetVar
238
    *  @param string $moduleDirname
239
    *  @param string $tableName
240
    *  @param string $fieldName
241
    *  @return string
242
    */
243
    public function getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain)
244
    {
245
        $stuModuleDirname = strtoupper($moduleDirname);
246
        $ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
247
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
248
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_IMAGE_PATH", $tableName, $moduleDirname);
249
250
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
251
        $ifelse = "\$extension = preg_replace( '/^.+\.([^.]+)$/sU' , '' , \$_FILES['attachedfile']['name']);\n";
252
        $ifelse .= "\$imgName = str_replace(' ', '', \$_POST['{$fieldMain}']).'.'.\$extension;\n";
253
        $ifelse .= "\$uploader->setPrefix(\$imgName);\n";
254
        $ifelse .= "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0]);\n";
255
        $contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
256
        $contentIf = "\$errors = \$uploader->getErrors();\n";
257
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
258
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt);
259
        $contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n";
260
261
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt);
262
263
        return $ret;
264
    }
265
266
    /*
267
    *  @public function getXoopsCodeFileSetVar
268
    *  @param $moduleDirname
269
    *  @param $tableName
270
    *  @param $fieldName
271
    *  @param $formatUrl
272
    *  @return string
273
    */
274
    public function getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName, $formatUrl = false)
275
    {
276
        $stuModuleDirname = strtoupper($moduleDirname);
277
        if ($formatUrl) {
278
            $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...
279
            $ret .= $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
280
        } else {
281
            $ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
282
        }
283
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
284
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_FILES_PATH", $tableName, $moduleDirname);
285
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
286
        if ($formatUrl) {
287
            $ifelse = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
288
        } else {
289
            $ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n";
290
            $ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
291
        }
292
        $contentElse = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
293
        $contentIf = "\$errors = \$uploader->getErrors();\n";
294
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
295
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElse);
296
297
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse);
298
299
        return $ret;
300
    }
301
302
    /**
303
     *  @public function getAdminXoopsCodeSetVarsObjects
304
     *
305
     *  @param $moduleDirname
306
     *  @param $tableName
307
     *  @param $fields
308
     *
309
     *  @return string
310
     */
311
    public function getAdminXoopsCodeSetVarsObjects($moduleDirname, $tableName, $fields)
312
    {
313
        $ret = $this->phpcode->getPhpCodeCommentLine($comment = 'Set Vars', $var = '');
314
        foreach (array_keys($fields) as $f) {
315
            $fieldName = $fields[$f]->getVar('field_name');
316
            $fieldElement = $fields[$f]->getVar('field_element');
317
            if ($f > 0) { // If we want to hide field id
318
                switch ($fieldElement) {
319
                    case 5:
320
                    case 6:
321
                        $ret .= $this->adminobjects->getCheckBoxOrRadioYNSetVar($tableName, $fieldName);
322
                        break;
323
                    case 11:
324
                        $ret .= $this->adminobjects->getImageListSetVar($moduleDirname, $tableName, $fieldName);
325
                        break;
326
                    case 12:
327
                        $ret .= $this->adminobjects->getUrlFileSetVar($moduleDirname, $tableName, $fieldName);
328
                        break;
329
                    case 13:
330
                        if (1 == $fields[$f]->getVar('field_main')) {
331
                            $fieldMain = $fieldName;
332
                        }
333
                        $ret .= $this->adminobjects->getUploadImageSetVar($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...
334
                        break;
335
                    case 14:
336
                        $ret .= $this->adminobjects->getUploadFileSetVar($moduleDirname, $tableName, $fieldName);
337
                        break;
338
                    case 15:
339
                        $ret .= $this->adminobjects->getTextDateSelectSetVar($tableName, $fieldName);
340
                        break;
341
                    default:
342
                        $ret .= $this->adminobjects->getSimpleSetVar($tableName, $fieldName);
343
                        break;
344
                }
345
            }
346
        }
347
348
        return $ret;
349
    }
350
351
    /**
352
     *  @public function getAdminXoopsCodeXoopsSecurity
353
     *
354
     *  @param $tableName
355
     *
356
     *  @return string
357
     */
358
    public function getAdminXoopsCodeXoopsSecurity($tableName)
359
    {
360
        $ret = <<<EOT
361
        if ( !\$GLOBALS['xoopsSecurity']->check() ) {
362
			redirect_header('{$tableName}.php', 3, implode(',', \$GLOBALS['xoopsSecurity']->getErrors()));
363
        }\n
364
EOT;
365
366
        return $ret;
367
    }
368
369
    /*
370
    *  @public function getAdminXoopsCodeInsertData
371
    *  @param $tableName
372
    *  @param $language
373
    *  @return string
374
    */
375
    public function getAdminXoopsCodeInsertData($tableName, $language)
376
    {
377
        $ret = <<<EOT
378
        // Insert Data
379
        if (\${$tableName}Handler->insert(\${$tableName}Obj)) {
380
			redirect_header('{$tableName}.php?op=list', 2, {$language}FORM_OK);
381
        }\n
382
EOT;
383
384
        return $ret;
385
    }
386
387
    /**
388
     *  @public function getAdminXoopsCodeGetFormError
389
     *
390
     *  @param $tableName
391
     *
392
     *  @return string
393
     */
394
    public function getAdminXoopsCodeGetFormError($tableName)
395
    {
396
        $ret = <<<EOT
397
        // Get Form
398
        \$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors());
399
        \$form =& \${$tableName}Obj->getForm();
400
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n
401
EOT;
402
403
        return $ret;
404
    }
405
406
    /**
407
     *  @public function getAdminXoopsCodeGetFormId
408
     *
409
     *  @param string $tableName
410
     *  @param string $fieldId
411
     *
412
     *  @return string
413
     */
414
    public function getAdminXoopsCodeGetFormId($tableName, $fieldId)
415
    {
416
        $ret = <<<EOT
417
        // Get Form
418
        \${$tableName}Obj = \${$tableName}Handler->get(\${$fieldId});
419
        \$form = \${$tableName}Obj->getForm();
420
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n
421
EOT;
422
423
        return $ret;
424
    }
425
426
    /**
427
     *  @public function getAdminXoopsCodeGetObjHandlerId
428
     *
429
     *  @param string $tableName
430
     *  @param string $fieldId
431
     *
432
     *  @return string
433
     */
434
    public function getAdminXoopsCodeGetObjHandlerId($tableName, $fieldId)
435
    {
436
        $ret = <<<EOT
437
        \${$tableName}Obj =& \${$tableName}Handler->get(\${$fieldId});\n
438
EOT;
439
440
        return $ret;
441
    }
442
443
    /*
444
    *  @public function getAdminXoopsCodeDelete
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 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...
452
    {
453
        $ret = <<<EOT
454
    case 'delete':
455
        \${$tableName}Obj =& \${$tableName}Handler->get(\${$fieldId});
456
        if (isset(\$_REQUEST['ok']) && 1 == \$_REQUEST['ok']) {
457
            if ( !\$GLOBALS['xoopsSecurity']->check() ) {
458
                redirect_header('{$tableName}.php', 3, implode(', ', \$GLOBALS['xoopsSecurity']->getErrors()));
459
            }
460
            if (\${$tableName}Handler->delete(\${$tableName}Obj)) {
461
                redirect_header('{$tableName}.php', 3, {$language}FORMDELOK);
462
            } else {
463
                echo \${$tableName}Obj->getHtmlErrors();
464
            }
465
        } else {
466
            xoops_confirm(array('ok' => 1, '{$fieldId}' => \${$fieldId}, 'op' => 'delete'), \$_SERVER['REQUEST_URI'], sprintf({$language}FORMSUREDEL, \${$tableName}Obj->getVar('{$fieldMain}')));
467
        }
468
    break;\n
469
EOT;
470
471
        return $ret;
472
    }
473
474
    /*
475
    *  @public function getAdminXoopsCodeUpdate
476
    *  @param string $moduleDirname
477
    *  @param string $tableName
478
    *  @param string $language
479
    *  @param string $fieldId
480
    *  @param string $fieldMain
481
    *  @return string
482
    */
483 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...
484
    {
485
        $upModuleName = strtoupper($moduleDirname);
486
        $ret = <<<EOT
487
    case 'update':
488
        if (isset(\${$fieldId})) {
489
            \${$tableName}Obj =& \${$tableName}Handler->get(\${$fieldId});
490
        }
491
        \${$tableName}Obj->setVar("\${$tableName}_display", \$_POST["\${$tableName}_display"]);
492
493
        if (\${$tableName}Handler->insert(\${$tableName}Obj)) {
494
            redirect_header("\${$tableName}.php", 3, _AM_{$upModuleName}_FORMOK);
495
        }
496
        echo \${$tableName}Obj->getHtmlErrors();
497
    break;\n
498
EOT;
499
500
        return $ret;
501
    }
502
}
503