martin.auction.php ➔ CreateButton()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 7
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
include_once __DIR__ . '/admin_header.php';
3
/*
4
 * 处理
5
 **/
6
7
//头部
8
include "martin.header.php";
9
$currentFile   = basename(__FILE__);
10
$myModuleAdmin = new ModuleAdmin();
11
echo $myModuleAdmin->addNavigation($currentFile);
12
13
//parameter 参数
14
$action = isset($_POST['action']) ? $_POST['action'] : @$_GET['action'];
15
$action = empty($action) ? 'list' : $action;
16
$action = trim(strtolower($action));
17
$id     = !empty($_POST['id']) ? $_POST['id'] : @$_GET['id'];
18
$id     = (int)($id);
19
$start  = isset($_GET['start']) ? (int)($_GET['start']) : 0;
20
//确认删除
21
$confirm = (isset($_POST['confirm'])) ? $_POST['confirm'] : 0;
22
//parameter 参数
23
24
// martin_adminMenu(8, "订房后台 > 竞价管理");
25
26
$auction_handler      =& xoops_getmodulehandler('auction', MARTIN_DIRNAME, true);
27
$hotelservice_handler =& xoops_getmodulehandler('hotelservice', MARTIN_DIRNAME, true);
28
29
//$HotelServiceObj = $hotelservice_handler->create();
30
$auctionObj = $id > 0 ? $auction_handler->get($id) : $auction_handler->create();
31
32
switch ($action) {
33 View Code Duplication
    case "add":
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...
34
        include MARTIN_ROOT_PATH . 'include/form.auction.php';
35
        martin_collapsableBar('createtable', 'createtableicon', _AM_MARTIN_ADDING_BID, _AM_MARTIN_ADDING_BID);
36
        CreateButton();
37
        //Create_button(array('addcity'=>array('url'=>'mconfirmartin.hotel.city.php?action=add','value'=>_AM_MARTIN_CITY_NAME)));
38
        $form = new form_auction($auctionObj, $auction_handler->getRoomList($id), $hotelservice_handler->GetHotelList());
0 ignored issues
show
Bug introduced by
$auction_handler->getRoomList($id) cannot be passed to __construct() as the parameter $RoomList expects a reference.
Loading history...
Bug introduced by
$hotelservice_handler->GetHotelList() cannot be passed to __construct() as the parameter $HotelList expects a reference.
Loading history...
39
40
        $form->display();
41
        martin_close_collapsable('createtable', 'createtableicon');
0 ignored issues
show
Unused Code introduced by
The call to the function martin_close_collapsable() seems unnecessary as the function has no side-effects.
Loading history...
42
        break;
43
    case "save":
44
        //var_dump(($_POST['auction_info']));exit;
45
        $auctionObj->setVar('auction_id', $id);
46
        $auctionObj->setVar('auction_name', (isset($_POST['auction_name']) ? addslashes($_POST['auction_name']) : ''));
47
        $auctionObj->setVar('auction_info', (isset($_POST['auction_info']) ? ($_POST['auction_info']) : ''));
48
        $auctionObj->setVar('check_in_date', (isset($_POST['check_in_date'])) ? strtotime($_POST['check_in_date']) : 0);
49
        $auctionObj->setVar('check_out_date', (isset($_POST['check_out_date'])) ? strtotime($_POST['check_out_date']) : 0);
50
        $auctionObj->setVar('apply_start_date', (isset($_POST['apply_start_date'])) ? strtotime($_POST['apply_start_date']) : 0);
51
        $auctionObj->setVar('apply_end_date', (isset($_POST['apply_end_date'])) ? strtotime($_POST['apply_end_date']) : 0);
52
        $auctionObj->setVar('auction_price', (isset($_POST['auction_price'])) ? round($_POST['auction_price'], 2) : 0);
53
        $auctionObj->setVar('auction_low_price', (isset($_POST['auction_low_price'])) ? round($_POST['auction_low_price'], 2) : 0);
54
        $auctionObj->setVar('auction_add_price', (isset($_POST['auction_add_price'])) ? round($_POST['auction_add_price'], 2) : 0);
55
        $auctionObj->setVar('auction_can_use_coupon', (isset($_POST['auction_can_use_coupon'])) ? intval($_POST['auction_can_use_coupon'], 2) : 0);
56
        $auctionObj->setVar('auction_sented_coupon', (isset($_POST['auction_sented_coupon'])) ? round($_POST['auction_sented_coupon'], 2) : 0);
57
        $auctionObj->setVar('auction_status', (isset($_POST['auction_status'])) ? intval($_POST['auction_status'], 2) : 0);
58
        $auctionObj->setVar('auction_add_time', time());
59
60
        $room_counts = array();
61
        $room_ids    = $_POST['room_id'];
62
        foreach ($room_ids as $room_id) {
63
            $room_counts[] = $_POST['room_count_' . $room_id];
64
        }
65
66
        //var_dump($auctionObj);exit;
67
        $isNew = false;
68
        if (!$id) {
69
            $isNew = true;
70
            $auctionObj->setNew();
71
        }
72
        if ($auctionObj->isNew()) {
73
            $redirect_msg = _AM_MARTIN_ADDED_SUCCESSFULLY;
74
            $redirect_to  = 'martin.auction.php';
75
        } else {
76
            $redirect_msg = _AM_MARTIN_MODIFIED_SUCCESSFULLY;
77
            $redirect_to  = 'martin.auction.php';
78
        }
79
80 View Code Duplication
        if (!is_array($room_ids) || empty($room_ids)) {
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...
81
            redirect_header('javascript:history.go(-1);', 2, _AM_MARTIN_FAILED_TO_ADD_ROOM.'<br>'._AM_MARTIN_NO_ROOM_CHOSEN);
82
            exit();
83
        }
84
85
        if (!$auction_id = $auction_handler->insert($auctionObj)) {
86
            redirect_header('javascript:history.go(-1);', 2, _AM_MARTIN_OPERATION_FAILED);
87
            exit();
88
        }
89
90
        //$auction_id = $id > 0 ? $id : $auctionObj->auction_id();
91
92
        //var_dump($auction_id);
93 View Code Duplication
        if ($auction_id > 0) {
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...
94
            if (!$auction_handler->InsertAuctionRoom($auction_id, $room_ids, $room_counts, $isNew)) {
95
                redirect_header('javascript:history.go(-1);', 2, _AM_MARTIN_FAILED_TO_ADD_ROOM);
96
                exit();
97
            }
98
        } else {
99
            redirect_header('javascript:history.go(-1);', 2, _AM_MARTIN_FAILED_TO_ADD_ROOM);
100
            exit();
101
        }
102
103
        redirect_header($redirect_to, 2, $redirect_msg);
104
        break;
105 View Code Duplication
    case "del":
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...
106
        if (!$confirm) {
107
            xoops_confirm(array('op' => 'del', 'id' => $auctionObj->auction_id(), 'confirm' => 1, 'name' => $auctionObj->auction_name()), '?action=del', "删除 '" . $auctionObj->auction_name() . "'. <br /> <br /> "._AM_MARTIN_OK_TO_DELETE_THE_BID, _DELETE);
108
        } else {
109
            if ($auction_handler->delete($auctionObj)) {
110
                $redirect_msg = _AM_MARTIN_OK_TO_DELETE_THE_ORDER;
111
                $redirect_to  = "martin.auction.php";
112
            } else {
113
                $redirect_msg = _AM_MARTIN_DELETE_FAILED;
114
                $redirect_to  = "javascript:history.go(-1);";
115
            }
116
            redirect_header($redirect_to, 2, $redirect_msg);
117
        }
118
        break;
119
    case "list":
120
        martin_collapsableBar('createtable', 'createtableicon', _AM_MARTIN_AUCTION_LIST, _AM_MARTIN_AUCTION_LIST);
121
        CreateButton();
122
        $Status      = array('<div style="background-color:#FF0000">' . _AM_MARTIN_DRAFT . '</div>', '<div style="background-color:#00FF00">' . _AM_MARTIN_PUBLISHED . '</div>');
123
        $AuctionObjs = $auction_handler->getAuctions($xoopsModuleConfig['perpage'], $start, 0);
124
        $Cout        = $auction_handler->getCount();
125
        include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
126
        $pagenav = new XoopsPageNav($Cout, $xoopsModuleConfig['perpage'], $start, 'start');
127
        $pavStr  = '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>';
128
129
        // Creating the objects for top categories
130
        echo $pavStr . "<table width='100%' cellspacing=1 cellpadding=12 border=0 class = outer>";
131
        echo "<tr>";
132
        echo "<td class='bg3' align='left'><b>ID</b></td>";
133
        echo "<td class='bg3' align='left'><b>" . _AM_MARTIN_TITLE . "</b></td>";
134
        echo "<td class='bg3' align='left'><b>" . _AM_MARTIN_AUCTION_START_TIME . "</b></td>";
135
        echo "<td class='bg3' align='left'><b>" . _AM_MARTIN_AUCTION_END_TIME . "</b></td>";
136
        echo "<td class='bg3' align='left'><b>" . _AM_MARTIN_CHECK_IN . "</b></td>";
137
        echo "<td class='bg3' align='left'><b>" . _AM_MARTIN_CHECK_OUT . "</b></td>";
138
        echo "<td class='bg3' align='left'><b>" . _AM_MARTIN_STARTING_PRICE . "</b></td>";
139
        echo "<td class='bg3' align='left'><b>" . _AM_MARTIN_CHEAP . "</b></td>";
140
        echo "<td class='bg3' align='left'><b>" . _AM_MARTIN_BID_INCREMENT . "</b></td>";
141
        echo "<td class='bg3' align='left'><b>" . _AM_MARTIN_BUY_PRICE . "</b></td>";
142
        echo "<td class='bg3' align='left'><b>" . _AM_MARTIN_CASH . "</b></td>";
143
        echo "<td width='60' class='bg3' align='center'><b>" . _AM_MARTIN_ACTIONS . "</b></td>";
144
        echo "</tr>";
145
        if (count($AuctionObjs) > 0) {
146
            foreach ($AuctionObjs as $key => $thiscat) {
147
                $modify = "<a href='?action=add&id=" . $thiscat->auction_id() . "'><img src='" . XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/images/icon/edit.gif'/></a>";
148
                $delete = "<a href='?action=del&id=" . $thiscat->auction_id() . "'><img src='" . XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/images/icon/delete.gif'/></a>";
149
                echo "<tr><td class='even' align='left'>" . $thiscat->auction_id() . "</td>";
150
                echo "<td class='even' align='left'>" . $thiscat->auction_name() . "</td>";
151
                echo "<td class='even' align='left'>" . date('Y-m-d', $thiscat->check_in_date()) . "</td>";
152
                echo "<td class='even' align='left'>" . date('Y-m-d', $thiscat->check_out_date()) . "</td>";
153
                echo "<td class='even' align='left'>" . date('Y-m-d', $thiscat->apply_start_date()) . "</td>";
154
                echo "<td class='even' align='left'>" . date('Y-m-d', $thiscat->apply_end_date()) . "</td>";
155
                echo "<td class='even' align='left'>" . $thiscat->auction_price() . "</td>";
156
                echo "<td class='even' align='left'>" . $thiscat->auction_low_price() . "</td>";
157
                echo "<td class='even' align='left'>" . $thiscat->auction_add_price() . "</td>";
158
                echo "<td class='even' align='left'>" . $thiscat->auction_sented_coupon() . "</td>";
159
                echo "<td class='even' align='left'>" . $Status[$thiscat->auction_status()] . "</td>";
160
                echo "<td class='even' align='center'>  $modify $delete </td></tr>";
161
            }
162
        } else {
163
            echo "<tr>";
164
            echo "<td class='head' align='center' colspan= '12'>" . MARTIN_IS_NUll . "</td>";
165
            echo "</tr>";
166
            $categoryid = '0';
167
        }
168
        echo "</table>\n";
169
        echo '<div style="text-align:right;">' . $pavStr . '</div>';
170
        echo "<br />";
171
        martin_close_collapsable('createtable', 'createtableicon');
0 ignored issues
show
Unused Code introduced by
The call to the function martin_close_collapsable() seems unnecessary as the function has no side-effects.
Loading history...
172
        break;
173
    default:
174
        redirect_header(XOOPS_URL, 2, _AM_MARTIN_UNAUTHORIZED_ACCESS);
175
        break;
176
}
177
178 View Code Duplication
function CreateButton()
0 ignored issues
show
Duplication introduced by
This function 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...
179
{
180
    $arr = array(
181
        'addservicetype'  => array('url' => 'martin.auction.php?action=add', 'value' => _AM_MARTIN_ADDING_BID),
182
        'servicetypelist' => array('url' => 'martin.auction.php?action=list', 'value' => _AM_MARTIN_AUCTION_LIST),);
183
    Create_button($arr);
184
}
185
186
//底部
187
include_once __DIR__ . '/admin_footer.php';
188