Completed
Push — master ( b8d8a2...060750 )
by Gino
06:18 queued 02:27
created

TDMCreateXoopsCode::getXoopsCodeEqualsOperator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4286
cc 2
eloc 6
nc 2
nop 3
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: TDMCreateXoopsCode.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') or die('Restricted access');
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
25
/**
26
 * Class TDMCreateXoopsCode.
27
 */
28
class TDMCreateXoopsCode
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
    * @var mixed
32
    */
33
    private $phpcode = null;
34
35
    /*
36
    *  @public function constructor
37
    *  @param null
38
    */
39
    /**
40
     *
41
     */
42
    public function __construct()
43
    {
44
        $this->phpcode = TDMCreatePhpCode::getInstance();
45
    }
46
47
    /*
48
    *  @static function &getInstance
49
    *  @param null
50
    */
51
    /**
52
     * @return TDMCreateXoopsCode
53
     */
54
    public static function &getInstance()
55
    {
56
        static $instance = false;
57
        if (!$instance) {
58
            $instance = new self();
59
        }
60
61
        return $instance;
62
    }
63
64
    /*
65
    *  @public function getXoopsCodeEqualsOperator
66
    *  @param string $left
67
    *  @param string $right
68
    *  @param boolean $ref
69
    *  @return string
70
    */
71
    public function getXoopsCodeEqualsOperator($left, $right, $ref = false)
72
    {
73
        if (false === $ref) {
74
            $ret = "{$left} = {$right};\n";
75
        } else {
76
            $ret = "{$left} =& {$right};\n";
77
        }
78
79
        return $ret;
80
    }
81
82
    /*
83
    *  @public function getXoopsCodeCPHeader
84
    *  @param null
85
    *  @return string
86
    */
87
    public function getXoopsCodeCPHeader()
88
    {
89
        return "xoops_cp_header();\n";
90
    }
91
92
    /*
93
    *  @public function getXoopsCodeCPFooter
94
    *  @param null
95
    *  @return string
96
    */
97
    public function getXoopsCodeCPFooter()
98
    {
99
        return "xoops_cp_footer();\n";
100
    }
101
102
    /**
103
     *  @public function getXoopsCodeLoadLanguage
104
     *
105
     *  @param $lang
106
     *
107
     *  @return string
108
     */
109
    public function getXoopsCodeLoadLanguage($lang)
110
    {
111
        return "xoops_loadLanguage('{$lang}');\n";
112
    }
113
114
    /*
115
    *  @public function getXoopsCodeSetVar
116
    *  @param string $tableName
117
    *  @param string $fieldName
118
    *  @param string $var
119
    *  @return string
120
    */
121
    public function getXoopsCodeSetVar($tableName, $fieldName, $var)
122
    {
123
        return "\${$tableName}Obj->setVar('{$fieldName}', {$var});\n";
124
    }
125
126
    /*
127
    *  @public function getXoopsCodeTextDateSelectSetVar
128
    *  @param string $tableName
129
    *  @param string $fieldName
130
    *  @return string
131
    */
132
    public function getXoopsCodeTextDateSelectSetVar($tableName, $fieldName)
133
    {
134
        return $this->getXoopsCodeSetVar($tableName, $fieldName, "strtotime(\$_POST['{$fieldName}'])");
135
    }
136
137
    /*
138
    *  @public function getXoopsCodeCheckBoxOrRadioYNSetVar
139
    *  @param $tableName
140
    *  @param $fieldName
141
    *  @return string
142
    */
143
    public function getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName)
144
    {
145
        $ret = $this->getXoopsCodeSetVar($tableName, $fieldName, "((1 == \$_REQUEST['{$fieldName}']) ? '1' : '0')");
146
147
        return $ret;
148
    }
149
150
    /*
151
    *  @public function getXoopsCodeGetConfig
152
    *  @param $moduleDirname
153
    *  @param $name
154
    *  @return string
155
    */
156
    public function getXoopsCodeGetConfig($moduleDirname, $name)
157
    {
158
        return "\${$moduleDirname}->getConfig('{$name}')";
159
    }
160
161
    /*
162
    *  @public function getXoopsCodeGetConfig
163
    *  @param $var
164
    *  @param $dirPath
165
    *  @param $tableName
166
    *  @param $moduleDirname
167
    *  @return string
168
    */
169
    public function getXoopsCodeMediaUploader($var = '', $dirPath, $tableName, $moduleDirname)
170
    {
171
        return "\${$var} = new XoopsMediaUploader({$dirPath} . '/{$tableName}',
172
														\${$moduleDirname}->getConfig('mimetypes'),
173
                                                        \${$moduleDirname}->getConfig('maxsize'), null, null);\n";
174
    }
175
176
    /*
177
    *  @public function getXoopsCodeImageListSetVar
178
    *  @param string $moduleDirname
179
    *  @param string $tableName
180
    *  @param string $fieldName
181
    *  @return string
182
    */
183
    public function getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName)
184
    {
185
        $ret = $this->phpcode->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
186
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
187
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32'", $tableName, $moduleDirname);
188
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
189
        $ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n";
190
        $ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
191
        $contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
192
        $contentIf = "\$errors = \$uploader->getErrors();\n";
193
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
194
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt);
195
        $contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n";
196
197
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt);
198
199
        return $ret;
200
    }
201
202
    /*
203
    *  @public function getXoopsCodeUploadImageSetVar
204
    *  @param string $moduleDirname
205
    *  @param string $tableName
206
    *  @param string $fieldName
207
    *  @return string
208
    */
209
    public function getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain)
210
    {
211
        $stuModuleDirname = strtoupper($moduleDirname);
212
        $ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
213
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
214
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_IMAGE_PATH", $tableName, $moduleDirname);
215
216
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
217
        $ifelse = "\$extension = preg_replace( '/^.+\.([^.]+)$/sU' , '' , \$_FILES['attachedfile']['name']);\n";
218
        $ifelse .= "\$imgName = str_replace(' ', '', \$_POST['{$fieldMain}']).'.'.\$extension;\n";
219
        $ifelse .= "\$uploader->setPrefix(\$imgName);\n";
220
        $ifelse .= "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0]);\n";
221
        $contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
222
        $contentIf = "\$errors = \$uploader->getErrors();\n";
223
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
224
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt);
225
        $contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n";
226
227
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt);
228
229
        return $ret;
230
    }
231
232
    /*
233
    *  @public function getXoopsCodeFileSetVar
234
    *  @param $moduleDirname
235
    *  @param $tableName
236
    *  @param $fieldName
237
    *  @param $formatUrl
238
    *  @return string
239
    */
240
    public function getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName, $formatUrl = false)
241
    {
242
        $stuModuleDirname = strtoupper($moduleDirname);
243
        if ($formatUrl) {
244
            $ret = $this->getXoopsCodeSetVar($tableName, $fieldName, "formatUrl(\$_REQUEST['{$fieldName}'])");
245
            $ret .= $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
246
        } else {
247
            $ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
248
        }
249
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
250
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_FILES_PATH", $tableName, $moduleDirname);
251
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
252
        if ($formatUrl) {
253
            $ifelse = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
254
        } else {
255
            $ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n";
256
            $ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
257
        }
258
        $contentElse = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
259
        $contentIf = "\$errors = \$uploader->getErrors();\n";
260
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
261
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElse);
262
263
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse);
264
265
        return $ret;
266
    }
267
268
    /*
269
    *  @public function getXoopsCodeIdGetVar
270
    *  @param string $lpFieldName
271
    *  @return string
272
    */
273
    public function getXoopsCodeIdGetVar($lpFieldName)
274
    {
275
        return "\${$lpFieldName}['id'] = \$i;\n";
276
    }
277
278
    /*
279
    *  @public function getXoopsCodeGetVarAll
280
    *  @param string $lpFieldName
281
    *  @param string $rpFieldName
282
    *  @param string $tableName
283
    *  @param string $fieldName
284
    *  @return string
285
    */
286
    public function getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName)
287
    {
288
        return "\${$lpFieldName}['{$rpFieldName}'] = \${$tableName}All[\$i]->getVar('{$fieldName}');\n";
289
    }
290
291
    /*
292
    *  @public function getXoopsCodeTopicGetVar
293
    *  @param string $lpFieldName
294
    *  @param string $rpFieldName
295
    *  @param string $tableName
296
    *  @param string $tableNameTopic
297
    *  @param string $fieldNameParent
298
    *  @param string $fieldNameTopic
299
    *  @return string
300
    */
301
    public function getXoopsCodeTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic)
302
    {
303
        $ret = <<<EOT
304
\t\t\t\t// Get Var {$fieldNameParent}
305
\t\t\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
306
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
307
EOT;
308
309
        return $ret;
310
    }
311
312
    /*
313
    *  @public function getXoopsCodeParentTopicGetVar
314
    *  @param string $moduleDirname
315
    *  @param string $lpFieldName
316
    *  @param string $rpFieldName
317
    *  @param string $tableName
318
    *  @param string $tableSoleNameTopic
319
    *  @param string $tableNameTopic
320
    *  @param string $fieldNameParent
321
    *  @return string
322
    */
323 View Code Duplication
    public function getXoopsCodeParentTopicGetVar($moduleDirname, $lpFieldName, $rpFieldName, $tableName, $tableSoleNameTopic, $tableNameTopic, $fieldNameParent)
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...
324
    {
325
        $ret = <<<EOT
326
\t\t\t\tif(!isset(\${$tableNameTopic}Handler)) {
327
\t\t\t\t\t// Get {$tableNameTopic} Handler
328
\t\t\t\t\t\${$tableNameTopic}Handler =& \${$moduleDirname}->getHandler('{$tableNameTopic}');
329
\t\t\t\t}
330
\t\t\t\t// Get Var {$fieldNameParent}
331
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$tableNameTopic}Handler->get{$tableSoleNameTopic}FromId(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));\n
332
EOT;
333
334
        return $ret;
335
    }
336
337
    /*
338
    *  @public function getXoopsCodeUploadImageGetVar
339
    *  @param string $lpFieldName
340
    *  @param string $rpFieldName
341
    *  @param string $tableName
342
    *  @param string $fieldName
343
    *  @return string
344
    */
345
    public function getXoopsCodeUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
346
    {
347
        $ret = <<<EOT
348
\t\t\t\t// Get Var {$fieldName}
349
\t\t\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
350
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$fieldName} ? \${$fieldName} : 'blank.gif';\n
351
EOT;
352
353
        return $ret;
354
    }
355
    /*
356
    *  @public function getXoopsCodeUrlFileGetVar
357
    *  @param string $lpFieldName
358
    *  @param string $rpFieldName
359
    *  @param string $tableName
360
    *  @param string $fieldName
361
    *  @return string
362
    */
363
    public function getXoopsCodeUrlFileGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
364
    {
365
        return $this->getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName);
366
    }
367
    /*
368
    *  @public function getXoopsCodeTextAreaGetVar
369
    *  @param string $lpFieldName
370
    *  @param string $rpFieldName
371
    *  @param string $tableName
372
    *  @param string $fieldName
373
    *  @return string
374
    */
375
    public function getXoopsCodeTextAreaGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
376
    {
377
        return "\${$lpFieldName}['{$rpFieldName}'] = strip_tags(\${$tableName}All[\$i]->getVar('{$fieldName}'));\n";
378
    }
379
380
    /*
381
    *  @public function getXoopsCodeSelectUserGetVar
382
    *  @param string $lpFieldName
383
    *  @param string $rpFieldName
384
    *  @param string $tableName
385
    *  @param string $fieldName
386
    * @return string
387
    */
388
    public function getXoopsCodeSelectUserGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
389
    {
390
        return "\${$lpFieldName}['{$rpFieldName}'] = XoopsUser::getUnameFromId(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
391
    }
392
393
    /*
394
    *  @public function getXoopsCodeTextDateSelectGetVar
395
    *  @param string $lpFieldName
396
    *  @param string $rpFieldName
397
    *  @param string $tableName
398
    *  @param string $fieldName
399
    *  @return string
400
    */
401
    public function getXoopsCodeTextDateSelectGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
402
    {
403
        return "\${$lpFieldName}['{$rpFieldName}'] = formatTimeStamp(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
404
    }
405
406
    /*
407
    *  @public function getXoopsCodeUserHeader
408
    *  @param string $moduleDirname
409
    *  @param string $tableName
410
    *  @return string
411
    */
412
    public function getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName)
413
    {
414
        return "\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
415
    }
416
417
    /*
418
    *  @public function getXoopsCodeUserHeader
419
    *  @param string $moduleDirname
420
    *  @param string $tableName
421
    *  @return string
422
    */
423
    public function getXoopsCodeUserHeader($moduleDirname, $tableName)
424
    {
425
        $ret = $this->phpcode->getPhpCodeIncludeDir('__DIR__', 'header');
426
        $ret .= $this->getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName);
427
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
428
429
        return $ret;
430
    }
431
432
    /*
433
    *  @public function getXoopsCodePermissionsHeader
434
    *  @param null
435
    */
436
    /**
437
     * @return string
438
     */
439
    public function getXoopsCodePermissionsHeader()
440
    {
441
        $ret = <<<EOT
442
// Permission
443
include_once XOOPS_ROOT_PATH.'/class/xoopsform/grouppermform.php';
444
\$gperm_handler =& xoops_gethandler('groupperm');
445
if (is_object(\$xoopsUser)) {
446
    \$groups = \$xoopsUser->getGroups();
447
} else {
448
    \$groups = XOOPS_GROUP_ANONYMOUS;
449
}
450
EOT;
451
452
        return $ret;
453
    }
454
455
    /**
456
     *  @public function getXoopsCodeGetFieldId
457
     *
458
     *  @param $fields
459
     *
460
     *  @return string
461
     */
462 View Code Duplication
    public function getXoopsCodeGetFieldId($fields)
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...
463
    {
464
        $fieldId = 'id';
465
        foreach (array_keys($fields) as $f) {
466
            $fieldName = $fields[$f]->getVar('field_name');
467
            if (0 == $f) {
468
                $fieldId = $fieldName;
469
            }
470
        }
471
472
        return $fieldId;
473
    }
474
475
    /**
476
     *  @public function getXoopsCodeGetFieldName
477
     *
478
     *  @param $fields
479
     *
480
     *  @return string
481
     */
482
    public function getXoopsCodeGetFieldName($fields)
483
    {
484
        foreach (array_keys($fields) as $f) {
485
            $fieldName = $fields[$f]->getVar('field_name');
486
        }
487
488
        return $fieldName;
0 ignored issues
show
Bug introduced by
The variable $fieldName 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...
489
    }
490
491
    /**
492
     *  @public function getXoopsCodeGetFieldParentId
493
     *
494
     *  @param $fields
495
     *
496
     *  @return string
497
     */
498 View Code Duplication
    public function getXoopsCodeGetFieldParentId($fields)
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...
499
    {
500
        $fieldPid = 'pid';
501
        foreach (array_keys($fields) as $f) {
502
            $fieldName = $fields[$f]->getVar('field_name');
503
            if (1 == $fields[$f]->getVar('field_parent')) {
504
                $fieldPid = $fieldName;
505
            }
506
        }
507
508
        return $fieldPid;
509
    }
510
511
    /**
512
     *  @public function getXoopsCodeUserSaveElements
513
     *
514
     *  @param $moduleDirname
515
     *  @param $tableName
516
     *  @param $fields
517
     *
518
     *  @return string
519
     */
520
    public function getXoopsCodeUserSaveElements($moduleDirname, $tableName, $fields)
521
    {
522
        $ret = '';
523
        foreach (array_keys($fields) as $f) {
524
            $fieldName = $fields[$f]->getVar('field_name');
525
            $fieldElement = $fields[$f]->getVar('field_element');
526
            if (1 == $fields[$f]->getVar('field_main')) {
527
                $fieldMain = $fieldName;
528
            }
529
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
530
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
531
            } elseif (13 == $fieldElement) {
532
                $ret .= $this->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...
533
            } elseif (14 == $fieldElement) {
534
                $ret .= $this->getXoopsCodeUploadFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeUploadFileSetVar() does not seem to exist on object<TDMCreateXoopsCode>.

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...
535
            } elseif (15 == $fieldElement) {
536
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
537
            } else {
538
                $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
539
            }
540
        }
541
542
        return $ret;
543
    }
544
545
    /*
546
    *  @public function getXoopsCodeXoopsRequest
547
    *  @param $left
548
    *  @param $var1
549
    *  @param $var2
550
    *  @param $type
551
    *  @param $metod
552
    *  @return string
553
    */
554
    public function getXoopsCodeXoopsRequest($left = '', $var1 = '', $var2 = '', $type = 'String', $metod = false)
555
    {
556
        if ($type == 'String') {
557
            $ret = "\${$left} = XoopsRequest::getString('{$var1}', '{$var2}');\n";
558
        } elseif ($type == 'Int') {
559
            $ret = "\${$left} = XoopsRequest::getInt('{$var1}', {$var2});\n";
560
        } elseif ($type == 'Int' && $metod !== false) {
561
            $ret = "\${$left} = XoopsRequest::getInt('{$var1}', {$var2}, '{$metod}');\n";
562
        }
563
564
        return $ret;
0 ignored issues
show
Bug introduced by
The variable $ret 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...
565
    }
566
567
    /*
568
    *  @public function getXoopsCodeAddInfoBox
569
    *  @param $language
570
    *  
571
    *  @return string
572
    */
573
    public function getXoopsCodeAddInfoBox($language)
574
    {
575
        return "\$adminMenu->addInfoBox({$language});\n";
576
    }
577
578
    /*
579
    *  @public function getXoopsCodeAddInfoBoxLine
580
    *  @param $language
581
    *  @param $label
582
    *  @param $var
583
    *  
584
    *  @return string
585
    */
586
    public function getXoopsCodeAddInfoBoxLine($language, $label = '', $var = '', $isLabel = false)
587
    {
588
        if ($var != '') {
589 View Code Duplication
            if ($isLabel === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
590
                $ret = "\$adminMenu->addInfoBoxLine({$language}, {$label}, {$var});\n";
591
            } else {
592
                $ret = "\$adminMenu->addInfoBoxLine({$language}, '<label>'.{$label}.'</label>', {$var});\n";
593
            }
594 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
595
            if ($isLabel === false) {
596
                $ret = "\$adminMenu->addInfoBoxLine({$language}, {$label});\n";
597
            } else {
598
                $ret = "\$adminMenu->addInfoBoxLine({$language}, '<label>'.{$label}.'</label>');\n";
599
            }
600
        }
601
602
        return $ret;
603
    }
604
605
    /*
606
    *  @public function getXoopsCodeTemplateMain
607
    *  @param $moduleDirname
608
    *  @param $filename
609
    *  @return string
610
    */
611
    public function getXoopsCodeTemplateMain($moduleDirname, $filename)
612
    {
613
        return "\$templateMain = '{$moduleDirname}_admin_{$filename}.tpl';\n";
614
    }
615
616
    /**
617
     *  @public function getXoopsCodeTplAssign
618
     *
619
     *  @param string $tplString
620
     *  @param string $phpRender
621
     *
622
     *  @return string
623
     */
624
    public function getXoopsCodeTplAssign($tplString, $phpRender)
625
    {
626
        return "\$GLOBALS['xoopsTpl']->assign('{$tplString}', {$phpRender});\n";
627
    }
628
629
    /**
630
     *  @public function getXoopsCodeXoopsTplAppend
631
     *
632
     *  @param string $tplString
633
     *  @param string $phpRender
634
     *
635
     *  @return string
636
     */
637
    public function getXoopsCodeXoopsTplAppend($tplString, $phpRender)
638
    {
639
        return "\$GLOBALS['xoopsTpl']->append('{$tplString}', {$phpRender});\n";
640
    }
641
642
    /**
643
     *  @public function getXoopsCodeXoopsTplAppendByRef
644
     *
645
     *  @param string $tplString
646
     *  @param string $phpRender
647
     *
648
     *  @return string
649
     */
650
    public function getXoopsCodeXoopsTplAppendByRef($tplString, $phpRender)
651
    {
652
        return "\$GLOBALS['xoopsTpl']->appendByRef('{$tplString}', {$phpRender});\n";
653
    }
654
655
    /**
656
     *  @public function getXoopsCodePath
657
     *
658
     *  @param $directory
659
     *  @param $filename
660
     *  @param $condition
661
     *
662
     *  @return string
663
     */
664
    public function getXoopsCodePath($directory, $filename, $condition = false)
665
    {
666
        if ($condition === false) {
667
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php');\n";
668
        } else {
669
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php')";
670
        }
671
672
        return $ret;
673
    }
674
675
    /**
676
     *  @public function getXoopsCodeTplDisplay
677
     *
678
     *  @param null
679
     *
680
     *  @return string
681
     */
682
    public function getXoopsCodeTplDisplay()
683
    {
684
        return "\$GLOBALS['xoopsTpl']->display(\"db:{\$templateMain}\");\n";
685
    }
686
687
    /*
688
    *  @public function getXoopsCodeItemButton
689
    *  @param $language
690
    *  @param $tableName
691
    *  @param $admin
692
    *  @return string
693
    */
694
    public function getXoopsCodeItemButton($language, $tableName, $tableSoleName, $op = '?op=new', $type = 'add')
695
    {
696
        $stuTableName = strtoupper($tableName);
697
        $stuTableSoleName = strtoupper($tableSoleName);
698
        $stuType = strtoupper($type);
699
        $aMIB = '$adminMenu->addItemButton(';
700
        if ($type = 'add') {
701
            $ret = $aMIB."{$language}{$stuType}_{$stuTableSoleName}, '{$tableName}.php{$op}', '{$type}');\n";
702
        } elseif ($type = 'list') {
703
            $ret = $aMIB."{$language}{$stuTableName}_{$stuType}, '{$tableName}.php', '{$type}');\n";
704
        } else {
705
            $ret = $aMIB."{$language}{$stuTableName}_{$stuType}, '{$tableName}.php', '{$type}');\n";
706
        }
707
708
        return $ret;
709
    }
710
711
    /**
712
     *  @public function getXoopsCodeGetInfo
713
     *
714
     *  @param $string
715
     *  @param $isParam
716
     *
717
     *  @return string
718
     */
719
    public function getXoopsCodeGetInfo($string, $isParam = false)
720
    {
721
        if ($isParam === false) {
722
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}');\n";
723
        } else {
724
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}')";
725
        }
726
727
        return $ret;
728
    }
729
730
    /**
731
     *  @public function getXoopsCodeObjHandlerCreate
732
     *
733
     *  @param string $tableName
734
     *
735
     *  @return string
736
     */
737
    public function getXoopsCodeObjHandlerCreate($tableName)
738
    {
739
        $ret = "\${$tableName}Obj =& \${$tableName}Handler->create();\n";
740
741
        return $ret;
742
    }
743
744
    /**
745
     *  @public function getXoopsCodeSetVarsObjects
746
     *
747
     *  @param $moduleDirname
748
     *  @param $tableName
749
     *  @param $fields
750
     *
751
     *  @return string
752
     */
753
    public function getXoopsCodeSetVarsObjects($moduleDirname, $tableName, $fields)
754
    {
755
        $ret = '';
756
757
        foreach (array_keys($fields) as $f) {
758
            $fieldName = $fields[$f]->getVar('field_name');
759
            $fieldElement = $fields[$f]->getVar('field_element');
760
            if (1 == $fields[$f]->getVar('field_main')) {
761
                $fieldMain = $fieldName;
762
            }
763
            if ($f > 0) { // If we want to hide field id
764
                switch ($fieldElement) {
765
                    case 5:
766
                    case 6:
767
                        $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
768
                        break;
769
                    case 11:
770
                        $ret .= $this->getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName);
771
                        break;
772
                    case 12:
773
                        $ret .= $this->getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName, true);
774
                        break;
775
                    case 13:
776
                        $ret .= $this->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...
777
                        break;
778
                    case 14:
779
                        $ret .= $this->getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName);
780
                        break;
781
                    case 15:
782
                        $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
783
                        break;
784
                    default:
785
                        $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
786
                        break;
787
                }
788
            }
789
        }
790
791
        return $ret;
792
    }
793
794
    /**
795
     *  @public function getXoopsCodeSecurity
796
     *
797
     *  @param $tableName
798
     *
799
     *  @return string
800
     */
801
    public function getXoopsCodeSecurity($tableName)
802
    {
803
        $securityError = $this->getXoopsCodeSecurityGetError();
804
        $implode = $this->phpcode->getPhpCodeImplode(',', $securityError);
805
        $content = $this->getXoopsCodeRedirectHeader($tableName, '', 3, $implode);
806
        $securityCheck = $this->getXoopsCodeSecurityCheck();
807
808
        return $this->phpcode->getPhpCodeConditions('!'.$securityCheck, '', '', $content);
809
    }
810
811
    /*
812
    *  @public function getXoopsCodeInsertData
813
    *  @param $tableName
814
    *  @param $language
815
    *  @return string
816
    */
817
    public function getXoopsCodeInsertData($tableName, $language)
818
    {
819
        $content = $this->getXoopsCodeRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_OK");
820
        $handlerInsert = $this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
821
822
        return $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $content);
823
    }
824
825
    /*
826
    *  @public function getXoopsCodeRedirectHeader
827
    *  @param $tableName
828
    *  @param $options
829
    *  @param $numb
830
    *  @param $var
831
    *  @return string
832
    */
833
    public function getXoopsCodeRedirectHeader($tableName, $options = '', $numb = '2', $var)
834
    {
835
        return "redirect_header('{$tableName}.php{$options}', {$numb}, {$var});\n";
836
    }
837
838
    /*
839
    *  @public function getXoopsCodeSecurityCheck
840
    *  @param null
841
    *  @return boolean
842
    */
843
    public function getXoopsCodeSecurityCheck()
844
    {
845
        return "\$GLOBALS['xoopsSecurity']->check()";
846
    }
847
848
    /*
849
    *  @public function getXoopsCodeSecurityGetError
850
    *  @param null
851
    *  @return string
852
    */
853
    public function getXoopsCodeSecurityGetError()
854
    {
855
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
856
    }
857
858
    /**
859
     *  @public function getXoopsCodeGetFormError
860
     *
861
     *  @param $tableName
862
     *
863
     *  @return string
864
     */
865
    public function getXoopsCodeGetFormError($tableName)
866
    {
867
        $ret = <<<EOT
868
        // Get Form
869
        \$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors());
870
        \$form =& \${$tableName}Obj->getForm();
871
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n
872
EOT;
873
874
        return $ret;
875
    }
876
877
    /**
878
     *  @public function getXoopsCodeGetFormId
879
     *
880
     *  @param string $tableName
881
     *  @param string $fieldId
882
     *
883
     *  @return string
884
     */
885
    public function getXoopsCodeGetFormId($tableName, $fieldId)
886
    {
887
        $ret = <<<EOT
888
        // Get Form
889
        \${$tableName}Obj = \${$tableName}Handler->get(\${$fieldId});
890
        \$form = \${$tableName}Obj->getForm();
891
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n
892
EOT;
893
894
        return $ret;
895
    }
896
897
    /**
898
     *  @public function getXoopsCodeHandler
899
     *
900
     *  @param string $tableName
901
     *  @param string $var
902
     *
903
     *  @return string
904
     */
905
    public function getXoopsCodeHandler($tableName, $var, $get = false, $insert = false, $delete = false, $obj = '')
906
    {
907
        if ($get) {
908
            $ret = "\${$tableName}Handler->get(\${$var});";
909
        } elseif ($insert && ($obj != '')) {
910
            $ret = "\${$tableName}Handler->insert(\${$var}{$obj});";
911
        } elseif ($delete && ($obj != '')) {
912
            $ret = "\${$tableName}Handler->delete(\${$var}{$obj});";
913
        }
914
915
        return $ret;
0 ignored issues
show
Bug introduced by
The variable $ret 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...
916
    }
917
918
    /*
919
    *  @public function getXoopsCodeCaseDelete
920
    *  @param string $tableName
921
    *  @param string $language
922
    *  @param string $fieldId
923
    *  @param string $fieldMain
924
    *  @return string
925
    */
926
    public function getXoopsCodeCaseDelete($language, $tableName, $fieldId, $fieldMain)
927
    {
928
        $content = <<<EOT
929
        \${$tableName}Obj =& \${$tableName}Handler->get(\${$fieldId});
930
        if (isset(\$_REQUEST['ok']) && 1 == \$_REQUEST['ok']) {
931
            if ( !\$GLOBALS['xoopsSecurity']->check() ) {
932
                redirect_header('{$tableName}.php', 3, implode(', ', \$GLOBALS['xoopsSecurity']->getErrors()));
933
            }
934
            if (\${$tableName}Handler->delete(\${$tableName}Obj)) {
935
                redirect_header('{$tableName}.php', 3, {$language}FORM_DELETE_OK);
936
            } else {
937
                echo \${$tableName}Obj->getHtmlErrors();
938
            }
939
        } else {
940
            xoops_confirm(array('ok' => 1, '{$fieldId}' => \${$fieldId}, 'op' => 'delete'), \$_SERVER['REQUEST_URI'], sprintf({$language}FORM_SURE_DELETE, \${$tableName}Obj->getVar('{$fieldMain}')));
941
        }\n
942
EOT;
943
        /*$isset = $this->phpcode->getPhpCodeIsset($fieldId);
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
944
        $if1 = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
945
        $get = $this->getXoopsCodeHandler($tableName, $fieldId, true);
946
        $if2 = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
947
        $content = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
948
        //$content .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
949
        $handlerInsert = $this->$this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
950
        $redirect = $this->getXoopsCodeRedirectHeader($tableName, '', 2, "{$language}FORM_DELETE_OK");
951
952
        $else = $this->getXoopsCodeTplAssign('error', "\${$tableName}Obj->getHtmlErrors()");
953
954
        $content .= $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $redirect, $else);*/
955
956
        return $this->phpcode->getPhpCodeCaseSwitch('delete', $content);
957
    }
958
959
    /*
960
    *  @public function getXoopsCodeUpdate
961
    *  @param $language
962
    *  @param $tableName
963
    *  @param $fieldId
964
    *  @param $fieldName
965
    *  @return string
966
    */
967
    public function getXoopsCodeUpdate($language, $tableName, $fieldId, $fieldName)
968
    {
969
        $isset = $this->phpcode->getPhpCodeIsset($fieldId);
970
        $get = $this->getXoopsCodeHandler($tableName, $fieldId, true);
971
        $content = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
972
        $content .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
973
        $handlerInsert = $this->$this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
974
        $redirect = $this->getXoopsCodeRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_UPDATE_OK");
975
        $content .= $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $redirect);
976
977
        $content .= $this->getXoopsCodeTplAssign('error', "\${$tableName}Obj->getHtmlErrors()");
978
979
        return $this->phpcode->getPhpCodeCaseSwitch('update', $content);
980
    }
981
}
982