Completed
Push — master ( 5be1c3...395766 )
by Michael
26:05
created

form_room_price::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4286
cc 1
eloc 7
nc 1
nop 2
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 18 and the first side effect is on line 10.

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
 * @license   http://www.blags.org/
5
 * @created   :2010年05月20日 23时52分
6
 * @copyright 1997-2010 The Martin Group
7
 * @author    Martin <[email protected]>
8
 * */
9
if (!defined('XOOPS_ROOT_PATH')) {
10
    return;
11
}
12
13
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
14
15
/**
16
 * Class form_room_price
17
 */
18
class form_room_price extends XoopsThemeForm
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...
19
{
20
    /**
21
     * form_room_price constructor.
22
     * @param $RoomPriceObj
23
     * @param $RoomList
24
     */
25
    public function __construct(&$RoomPriceObj, &$RoomList)
26
    {
27
        $this->Obj      = &$RoomPriceObj;
28
        $this->RoomList = &$RoomList;
29
        parent::__construct(_AM_MARTIN_HOTEL_ROOM_RATES, "op", xoops_getenv('PHP_SELF') . "?action=pricesave&room_id=" . @$RoomPriceObj['room_id'] . "&room_date=" . date('Y-m-d', @$RoomPriceObj['room_date']));
30
        $this->setExtra('enctype="multipart/form-data"');
31
32
        $this->createElements();
33
        $this->createButtons();
34
    }
35
36
    /**
37
     * created elements
38
     * @license   http://www.blags.org/
39
     * @created   :2010年05月21日 20时40分
40
     * @copyright 1997-2010 The Martin Group
41
     * @author    Martin <[email protected]>
42
     * */
43
    public function createElements()
44
    {
45
        $Price     = &$this->Obj;
46
        $today     = (int)(date('d'));
47
        $MouthDays = (int)($this->MouthDays(date('m')));
48
49
        $js         = '<script type=\'text/javascript\'>
50
            jQuery.noConflict();
51
            jQuery(document).ready(function($){
52
                $("#sub").click(function(){
53
                    var result = true;
54
                    $("form input[type=text]").each(function(Element){
55
                        if($.trim($(this).val()) == "" && $.trim($(this).attr("class")) != "")
56
                        {
57
                            $(this).focus();
58
                            result = false;
59
                            return false;
60
                        }
61
                    });
62
                    if(result)
63
                    {
64
                        $("#op").submit();
65
                    }else{
66
                        alert("只能数字,不能为空");
67
                    }
68
                });
69
                $(".sel").click(function(){
70
                    var Check = $(this).prev("input[type=checkbox]").attr("checked") ? false : true;
71
                    $(this).prev("input[type=checkbox]").attr("checked",Check);
72
                });
73
                /*$(".even").parent("tr").click(function(){
74
                    var Check = $(this).find("input[type=checkbox]").attr("checked") ? false : true;
75
                    $(this).find("input[type=checkbox]").attr("checked",Check);
76
                    $(this).attr("style","background-color: rgb(0, 255, 0);");
77
                });*/
78
                $("#room_price_all").click(function(){
79
                    var value = $(this).next("input").val();
80
                    if(!parseFloat(value)){alert("this must be Number.");$(this).focus();return false;}
81
                    $(".room_price").val(value);
82
                });
83
                $("#room_advisory_range_max_all").click(function(){
84
                    var value = $(this).next("input").val();
85
                    if(!parseFloat(value)){alert("this must be Number.");$(this).focus();return false;}
86
                    $(".room_advisory_range_max").val(value);
87
                });
88
                $("#room_advisory_range_min_all").click(function(){
89
                    var value = $(this).next("input").val();
90
                    if(!parseFloat(value)){alert("this must be Number.");$(this).focus();return false;}
91
                    $(".room_advisory_range_small").val(value);
92
                });
93
                $("#room_sented_coupon_all").click(function(){
94
                    var value = $(this).next("input").val();
95
                    if(!parseFloat(value)){alert("this must be Number.");$(this).focus();return false;}
96
                    $(".room_sented_coupon").val(value);
97
                });
98
            });
99
            </script>';
100
        $button_str = '
101
                        <table><tr><td width="150px;align=center;"><input type="button" id="room_price_all" value="ALL">&nbsp;<input type="text" size=5></td>
102
                        <td width="100px;align=center;"><input type="button" id="room_advisory_range_min_all" value="ALL">&nbsp;<input type="text" size=5></td>
103
                        <td width="150px;align=center;"><input type="button" id="room_advisory_range_max_all" value="ALL">&nbsp;<input type="text" size=5></td>
104
                        <td width="150px;align=center;"><input type="button" id="room_sented_coupon_all" value="ALL">&nbsp;<input type="text" size=5></td></tr></table>
105
                    ';
106
        //var_dump($Price);
107
        if (!empty($Price) && is_array($Price) && isset($Price['room_price'])) {
108
            $PriceArea   = new XoopsFormElementTray($js . '房间价格');
109
            $RoomElement = new XoopsFormSelect(_AM_MARTIN_GUEST_ROOM, 'room_id', $Price['room_id'], 1);
110
            $RoomElement->addOptionArray($this->RoomList);
111
            $PriceArea->addElement($RoomElement, true);
112
            $PriceArea->addElement(new XoopsFormText(_AM_MARTIN_PRICE . ':', 'room_price', 11, 11, $Price['room_price']), true);
113
            $PriceArea->addElement(new XoopsFormText(_AM_MARTIN_PRICE_RANGE . ':', 'room_advisory_range_small', 11, 11, $Price['room_advisory_range_small']), true);
114
            $PriceArea->addElement(new XoopsFormText('-', 'room_advisory_range_max', 11, 11, $Price['room_advisory_range_max']), true);
115
            //_AM_MARTIN_GIFT_VOUCHER
116
            $PriceArea->addElement(new XoopsFormText(_AM_MARTIN_GIFT_VOUCHER . ':', 'room_sented_coupon', 11, 11, $Price['room_sented_coupon']), true);
117
            $Special = new XoopsFormCheckBox('', "room_is_today_special", $Price['room_is_today_special']);
118
            $Special->addOption(1, '<label for="room_is_today_special">' . _YES . ' ' . _AM_MARTIN_LAST_MINUTE . '</label>');
119
            //$PriceArea->addElement(new XoopsFormText('时间:', 'room_date', 11, 11, date("Y-m-d",$Price['room_date'])), true); 
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
120
            $PriceArea->addElement(new XoopsFormHidden('room_date[]', $Price['room_date']));
121
            $PriceArea->addElement($Special, false);
122
            $this->addElement($PriceArea, false);
123
        } else {
124
            $RoomElement = new XoopsFormSelect($js . _AM_MARTIN_GUEST_ROOM . '<br><font color=red><b>' . _AM_MARTIN_DO_NOT_MODIFY_TIME . '</b></font>', 'room_id', '', 1);
125
            $RoomElement->addOptionArray($this->RoomList);
126
            $this->addElement($RoomElement);
127
            $Select = new XoopsFormElementTray(_AM_MARTIN_BATCH_PROCESSING);
128
            $Select->addElement(new XoopsFormLabel("", $button_str));
129
130
            $this->addElement($Select);
131
132
            //var_dump($Price[1277395200]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
88% 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...
133
            //$countDate = count($Price) > 0 ? count($Price) + $today : $MouthDays + $today;
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% 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...
134
            $countDate = $MouthDays + $today;
135
            for ($today; $today <= $countDate; $today++) {
136
                $date     = ($today > $MouthDays) ? date("Y") . '-' . (date("m") + 1) . '-' . ($today - $MouthDays) : date("Y") . '-' . date("m") . '-' . $today;
137
                $dateTime = strtotime($date);
138
139
                //var_dump($Price[$dateTime]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
140
//                ${"PriceArea" . $today} = new XoopsFormElementTray(_AM_MARTIN_ROOM . $date . ' ' . _AM_MARTIN_PRICE_ON);
141
                ${"PriceArea" . $today} = new XoopsFormElementTray(_AM_MARTIN_ROOM_PRICE_ON_DATE . $date );
142
                $room_price             = new XoopsFormText(_AM_MARTIN_PRICE . ':', 'room_price[]', 11, 11, isset($Price[$dateTime]) ? $Price[$dateTime]['room_price'] : '0.00');
143
                $room_price->setExtra("class='room_price'");
144
                ${"PriceArea" . $today}->addElement($room_price, true);
145
146
                $room_advisory_range_small = new XoopsFormText(_AM_MARTIN_PRICE_RANGE . ':', 'room_advisory_range_small[]', 11, 11, isset($Price[$dateTime]) ? $Price[$dateTime]['room_advisory_range_small'] : '0.00');
147
                $room_advisory_range_small->setExtra("class='room_advisory_range_small'");
148
                ${"PriceArea" . $today}->addElement($room_advisory_range_small, true);
149
150
                $room_advisory_range_max = new XoopsFormText('-', 'room_advisory_range_max[]', 11, 11, isset($Price[$dateTime]) ? $Price[$dateTime]['room_advisory_range_max'] : '0.00');
151
                $room_advisory_range_max->setExtra("class='room_advisory_range_max'");
152
                ${"PriceArea" . $today}->addElement($room_advisory_range_max, true);
153
                //_AM_MARTIN_GIFT_VOUCHER
154
                $room_sented_coupon = new XoopsFormText(_AM_MARTIN_GIFT_VOUCHER . ':', 'room_sented_coupon[]', 11, 11, isset($Price[$dateTime]) ? $Price[$dateTime]['room_sented_coupon'] : '0.00');
155
                $room_sented_coupon->setExtra("class='room_sented_coupon'");
156
                ${"PriceArea" . $today}->addElement($room_sented_coupon, true);
157
158
                $Special = new XoopsFormCheckBox('', "room_is_today_special[$dateTime]", isset($Price[$dateTime]) ? $Price[$dateTime]['room_is_today_special'] : 0);
159
                $Special->addOption(1, '<label class="sel">' . _YES . ' ' . _AM_MARTIN_LAST_MINUTE . '</label>');
160
                //echo isset($Price[$dateTime]) ? $Price[$dateTime]['room_is_today_special'] : 0;echo '<br>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% 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...
161
                //hide time 
162
                //${"PriceArea".$today}->addElement(new XoopsFormText('时间:', 'room_date[]', 11, 11, $date), true); 
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
163
                ${"PriceArea" . $today}->addElement(new XoopsFormHidden('room_date[]', $date));
164
                ${"PriceArea" . $today}->addElement($Special, false);
165
                $this->addElement(${"PriceArea" . $today}, false);
166
                unset(${"PriceArea" . $today}, $dateTime, $date, $room_price, $room_advisory_range_max, $room_advisory_range_small, $room_sented_coupon, $Special);
167
            }
168
        }
169
        /*$this->addElement( new XoopsFormText(_AM_MARTIN_ROOM_NAME, 'room_name', 45, 45, $this->Obj->room_name()), true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
170
        $this->addElement( new XoopsFormText(_AM_MARTIN_ROOMS_AREA, 'room_area', 11, 11, $this->Obj->room_area()), true);
171
        $this->addElement( new XoopsFormText(_AM_MARTIN_ROOM_FLOOR, 'room_floor', 45, 45, $this->Obj->room_floor()), true);
172
        
173
        $this->addElement( new XoopsFormText('加价', 'room_add_money', 11, 11, $this->Obj->room_add_money()), false);
174
        $this->addElement( new XoopsFormTextArea('床描述', 'room_bed_info', $this->Obj->room_bed_info()) , false);
175
        $this->addElement( new XoopsFormRadioYN(_AM_MARTIN_ROOM_STATUS, 'room_status', $this->Obj->room_status(), _AM_MARTIN_PUBLISHED,  _AM_MARTIN_DRAFT) , true);
176
        $this->addElement( new XoopsFormText(_AM_MARTIN_GIFT_VOUCHER, 'room_sented_coupon', 11, 11, (int)($this->Obj->room_sented_coupon())), false);*/
177
    }
178
179
    /**
180
     * @创建按钮
181
     * @license   http://www.blags.org/
182
     * @created   :2010年05月20日 23时52分
183
     * @copyright 1997-2010 The Martin Group
184
     * @author    Martin <[email protected]>
185
     * */
186
    public function createButtons()
187
    {
188
        $button_tray = new XoopsFormElementTray('', '');
189
        // No ID for category -- then it's new category, button says 'Create'
190
        if (empty($this->Obj)) {
191
            $butt_create = new XoopsFormButton('', 'sub', _SUBMIT, 'button');
192
            //$butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% 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...
193
            $button_tray->addElement($butt_create);
194
195
            $butt_clear = new XoopsFormButton('', '', _RESET, 'reset');
196
            $button_tray->addElement($butt_clear);
197
198
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
199
            $butt_cancel->setExtra('onclick="history.go(-1)"');
200
            $button_tray->addElement($butt_cancel);
201
202
            $this->addElement($button_tray);
203
        } else {
204
            // button says 'Update'
205
            $butt_create = new XoopsFormButton('', 'sub', _EDIT, 'button');
206
            //$butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% 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...
207
            $button_tray->addElement($butt_create);
208
209
            $butt_clear = new XoopsFormButton('', '', _RESET, 'reset');
210
            $button_tray->addElement($butt_clear);
211
212
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
213
            $butt_cancel->setExtra('onclick="history.go(-1)"');
214
            $button_tray->addElement($butt_cancel);
215
216
            $this->addElement($button_tray);
217
        }
218
    }
219
220
    /**
221
     * @param $mouth
222
     * @return array|bool|int|string
223
     */
224
    public function MouthDays($mouth)
225
    {
226
        $date     = date('Y') . '-' . $mouth . '-' . date('d');
227
        $firstday = date('Y-m-01', strtotime($date));
228
        $lastday  = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
229
        $lastday  = explode('-', $lastday);
230
        $lastday  = array_reverse($lastday);
231
        $lastday  = (int)$lastday[0];
232
233
        return $lastday;
234
    }
235
}
236