form_auction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
/**
3
 * @城市表单
4
 * @license   http://www.blags.org/
5
 * @created   :2010年05月20日 23时52分
6
 * @copyright 1997-2010 The Martin auction
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_auction
17
 */
18
class form_auction extends XoopsThemeForm
19
{
20
    /**
21
     * form_auction constructor.
22
     * @param $AuctionObj
23
     * @param $RoomList
24
     * @param $HotelList
25
     */
26
    public function __construct(&$AuctionObj, &$RoomList, &$HotelList)
27
    {
28
        $this->Obj       = &$AuctionObj;
29
        $this->RoomList  = &$RoomList;
30
        $this->HotelList = &$HotelList;
31
        parent::__construct(_AM_MARTIN_HOTEL_BIDDING, "op", xoops_getenv('PHP_SELF') . "?action=save");
32
        $this->setExtra('enctype="multipart/form-data"');
33
34
        $this->createElements();
35
        $this->createButtons();
36
    }
37
38
    /**
39
     * created elements
40
     * @license   http://www.blags.org/
41
     * @created   :2010年05月21日 20时40分
42
     * @copyright 1997-2010 The Martin auction
43
     * @author    Martin <[email protected]>
44
     * */
45
    public function createElements()
46
    {
47
        //include_once MARTIN_ROOT_PATH . '/include/formdatetime.php';
48
        include_once XOOPS_ROOT_PATH . "/modules/martin/class/xoopsformloader.php";
49
        include_once MARTIN_ROOT_PATH . '/include/formdatetime.php';
50
51
        $RoomStr = '';
52 View Code Duplication
        foreach ($this->RoomList as $room) {
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...
53
            $RoomStr .= "<br><input type=checkbox name=room_id[] value={$room['room_id']} id=room_{$room['room_id']} checked=\"checked\" click=\"RoomRemove(this)\">&nbsp;<label for=room_{$room['room_id']}>{$room['room_name']}</label>&nbsp;&nbsp;"._AM_MARTIN_NUMBER_OF_ROOMS.":<input type=text name=\"room_count_{$room['room_id']}\" value={$room['room_count']}>";
54
        }
55
        $js          = '<script type=\'text/javascript\'>
56
            jQuery.noConflict();
57
            jQuery(document).ready(function($){
58
                $("#hotel_id").click(function(){
59
                    var hotel_id =  Number($(this).val());
60
                    $.post("martin.ajax.php?action=getroomlist",{hotel_id:hotel_id},function(data){
61
                        $("#room").html(data);
62
                    });
63
                });
64
            });
65
            function roomSelect(event)
66
            {
67
                var room_id = Number(jQuery("#ajaxroom").val());
68
                var room_name = jQuery.trim(jQuery("#ajaxroom option:selected").text());
69
                var roomExist = document.getElementById("room_"+room_id);
70
                if(roomExist) return false;
71
                if(room_id > 0)
72
                {
73
                    var Str = "<br><input type=checkbox name=room_id[] value="+room_id+" id=room_"+room_id+" checked=\"checked\" click=\"RoomRemove(this)\">&nbsp;"+"<label for=room_"+room_id+">" + room_name + "</label>";
74
                    var inputStr = "&nbsp;&nbsp;"._AM_MARTIN_NUMBER_OF_ROOMS.":<input type=text name=\"room_count_"+room_id+"\" value=1>";
75
                    jQuery("#rooms").append(Str + inputStr);
76
                }
77
            }
78
            </script>';
79
        $Room        = new XoopsFormElementTray($js . _AM_MARTIN_SELECT_ROOMS . '<br>' . _AM_MARTIN_FILTER_BY_HOTEL);
80
        $RoomElement = new XoopsFormSelect('', 'hotel_id', $this->HotelList, 5, false);
81
        $RoomElement->addOptionArray($this->HotelList);
82
        //$RoomElement->addOption('class','hotel');
83
        $Room->addElement($RoomElement, false);
84
        $Room->addElement(new XoopsFormElementTray('<br><br><div id="room"></div><div id="rooms">' . $RoomStr . '</div>'), false);
85
86
        $this->addElement($Room, false);
87
88
        $this->addElement(new XoopsFormTextDateSelect(_AM_MARTIN_CHECK_IN, 'check_in_date', $size = 15, $this->Obj->check_in_date(), false), true);
89
90
        $this->addElement(new XoopsFormTextDateSelect(_AM_MARTIN_LAUNCH_TIME, 'check_out_date', $size = 15, $this->Obj->check_out_date(), false), true);
91
92
        //$this->addElement( new XoopsFormTextDateSelect(_AM_MARTIN_START_BID_TIME, 'apply_start_date', $size = 15, $this->Obj->apply_start_date(),false ) ,true);
93
        $this->addElement(new MartinFormDateTime(_AM_MARTIN_START_BID_TIME, 'apply_start_date', $size = 15, $this->Obj->apply_start_date()), true);
94
        //$this->addElement( new XoopsFormTextDateSelect(_AM_MARTIN_END_TIME_BIDDING, 'apply_end_date', $size = 15, $this->Obj->apply_end_date() ) ,true);
95
        $this->addElement(new MartinFormDateTime(_AM_MARTIN_END_TIME_BIDDING, 'apply_end_date', $size = 15, $this->Obj->apply_end_date()), true);
96
97
        $this->addElement(new XoopsFormText(_AM_MARTIN_STARTING_PRICE, 'auction_price', 11, 11, $this->Obj->auction_price()), true);
98
        $this->addElement(new XoopsFormText(_AM_MARTIN_CHEAP, 'auction_low_price', 11, 11, $this->Obj->auction_low_price()), true);
99
        $this->addElement(new XoopsFormText(_AM_MARTIN_PRICE_MARKUP, 'auction_add_price', 11, 11, $this->Obj->auction_add_price()), true);
100
        $this->addElement(new XoopsFormText(_AM_MARTIN_GIFT_VOUCHER . '?', 'auction_sented_coupon', 11, 11, (int)($this->Obj->auction_sented_coupon())), true);
101
        $this->addElement(new XoopsFormRadioYN(_AM_MARTIN_CAN_YOU_USE_CASH_VOLUME, 'auction_can_use_coupon', $this->Obj->auction_can_use_coupon(), _YES, _NO), true);
102
        $this->addElement(new XoopsFormRadioYN(_AM_MARTIN_STATUS, 'auction_status', $this->Obj->auction_status(), _AM_MARTIN_PUBLISHED, _AM_MARTIN_DRAFT), true);
103
104
        $this->addElement(new XoopsFormText(_AM_MARTIN_TITLE, 'auction_name', 50, 255, $this->Obj->auction_name()), true);
105
        $editor       = 'tinymce';
106
        $auction_info = $this->Obj->auction_info();
107
        //var_dump($auction_info);
108
        $editor_configs           = array();
109
        $editor_configs["name"]   = "auction_info";
110
        $editor_configs["value"]  = $auction_info;
111
        $editor_configs["rows"]   = empty($xoopsModuleConfig["editor_rows"]) ? 35 : $xoopsModuleConfig["editor_rows"];
0 ignored issues
show
Bug introduced by
The variable $xoopsModuleConfig seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
112
        $editor_configs["cols"]   = empty($xoopsModuleConfig["editor_cols"]) ? 60 : $xoopsModuleConfig["editor_cols"];
113
        $editor_configs["width"]  = empty($xoopsModuleConfig["editor_width"]) ? "100%" : $xoopsModuleConfig["editor_width"];
114
        $editor_configs["height"] = empty($xoopsModuleConfig["editor_height"]) ? "400px" : $xoopsModuleConfig["editor_height"];
115
116
        $this->addElement(new XoopsFormEditor(_AM_MARTIN_AUCTION_DETAILS, $editor, $editor_configs, false, $onfailure = null), false);
117
        $this->addElement(new XoopsFormHidden('id', $this->Obj->auction_id()));
118
    }
119
120
    /**
121
     * @创建按钮
122
     * @license   http://www.blags.org/
123
     * @created   :2010年05月20日 23时52分
124
     * @copyright 1997-2010 The Martin auction
125
     * @author    Martin <[email protected]>
126
     * */
127 View Code Duplication
    public function createButtons()
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...
128
    {
129
        $button_tray = new XoopsFormElementTray('', '');
130
        // No ID for category -- then it's new category, button says 'Create'
131
        if (!$this->Obj->auction_id()) {
132
            $butt_create = new XoopsFormButton('', '', _RESET, 'submit');
133
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
134
            $button_tray->addElement($butt_create);
135
136
            $butt_clear = new XoopsFormButton('', '', _SUBMIT, 'reset');
137
            $button_tray->addElement($butt_clear);
138
139
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
140
            $butt_cancel->setExtra('onclick="history.go(-1)"');
141
            $button_tray->addElement($butt_cancel);
142
143
            $this->addElement($button_tray);
144
        } else {
145
            // button says 'Update'
146
            $butt_create = new XoopsFormButton('', '', _EDIT, 'submit');
147
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
148
            $button_tray->addElement($butt_create);
149
150
            $butt_clear = new XoopsFormButton('', '', _SUBMIT, 'reset');
151
            $button_tray->addElement($butt_clear);
152
153
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
154
            $butt_cancel->setExtra('onclick="history.go(-1)"');
155
            $button_tray->addElement($butt_cancel);
156
157
            $this->addElement($button_tray);
158
        }
159
    }
160
}
161