Completed
Push — master ( 31307f...55a138 )
by Michael
03:27
created

ThemeForm::render()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 22
nc 1
nop 0
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
1
<?php namespace XoopsModules\Extcal\Form;
2
3
//include __DIR__ . '/formdatetime.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% 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...
4
//include __DIR__ . '/formrecurrules.php';
5
//include __DIR__ . '/formfilecheckbox.php';
6
//include __DIR__ . '/FormRRuleCheckBox.php';
7
8
/**
9
 * Class ThemeForm.
10
 */
11
class ThemeForm extends \XoopsThemeForm
12
{
13
    /**
14
     * create HTML to output the form as a theme-enabled table with validation.
15
     *
16
     * @return string
17
     */
18
    public function render()
19
    {
20
        $ret = "\n<script type=\"text/javascript\">\n";
21
        $ret .= "function validDate(startDateInput, startTimeSelect, endDateInput, endTimeSelect) {\n";
22
        $ret .= "startDateInput = document.getElementById(startDateInput);\n";
23
        $ret .= "startTimeSelect = document.getElementById(startTimeSelect);\n";
24
        $ret .= "endDateInput = document.getElementById(endDateInput);\n";
25
        $ret .= "endTimeSelect = document.getElementById(endTimeSelect);\n";
26
27
        $ret .= "var pattern = new RegExp(\"-\", \"g\");\n";
28
29
        $ret .= "var startDateString = startDateInput.value;\n";
30
        $ret .= "var startDateArray = startDateString.split(pattern);\n";
31
        $ret .= "var startDate = new Date(startDateArray[0], startDateArray[2], startDateArray[1]);\n";
32
33
        $ret .= "var endDateString = endDateInput.value;\n";
34
        $ret .= "var endDateArray = endDateString.split(pattern);\n";
35
        $ret .= "var endDate = new Date(endDateArray[0], endDateArray[2], endDateArray[1]);\n";
36
37
        $ret .= "if ((startDate.getTime() + startTimeSelect.options[startTimeSelect.selectedIndex].value) > (endDate.getTime() + endTimeSelect.options[endTimeSelect.selectedIndex].value)) {\n";
38
        $ret .= "endDateInput.value = startDateInput.value;\n";
39
        $ret .= "endTimeSelect.selectedIndex = startTimeSelect.selectedIndex;\n";
40
        $ret .= "}\n";
41
42
        $ret .= "}\n";
43
        $ret .= "</script>\n";
44
45
        $ret .= parent::render();
46
47
        return $ret;
48
    }
49
}
50