Example #1
0
    public static function insertOrUpdateRoomPlan($hotelId, $roomPlanId, $roomTypeId, $roomPlanName, $roomMaxPersons, $startTime, $endTime, $roomSize, $roomPlanDesc, $breakfast, $dinner, $useCon, $conFromTime, $conToTime, $nights, $priceAll, $priceAsia, $priceEuro, $liaojin = 1, $zaiku = 1)
    {
        $roomPlanName = mysql_real_escape_string($roomPlanName);
        $roomPlanDesc = mysql_real_escape_string($roomPlanDesc);
        //first check if already exist.
        if ($roomPlanId == 0) {
            // if insert
            //check if already exist.
            $tblRoomPlan = _DB_PREFIX_ . "RoomPlan A";
            $tblLink = _DB_PREFIX_ . "HotelRoomPlanLink B";
            $sql = "SELECT A.`RoomPlanId` FROM {$tblRoomPlan}, {$tblLink} \n\t\t\t\t\tWHERE A.`RoomPlanName`='{$roomPlanName}' AND A.`RoomTypeId` = '{$roomTypeId}' AND A.`StartTime`='{$startTime}'\n\t\t\t\t\t      AND A.`EndTime`='{$endTime}' AND B.`HotelId` = {$hotelId}";
            $result = Db::getInstance()->getRow($sql);
            if ($result) {
                //if alreay exist, return 0;
                return 0;
            }
        }
        $startTime = '2012-01-01';
        $endTime = '2112-01-01';
        if ($breakfast == '') {
            $breakfast = 0;
        }
        if ($dinner == '') {
            $dinner = 0;
        }
        if ($useCon == '') {
            $useCon = 0;
        }
        if ($roomSize == '') {
            $roomSize = 0;
        }
        if ($nights == '') {
            $nights = 0;
        }
        if ($priceAll == '') {
            $priceAll = 0;
        }
        if ($priceAsia == '') {
            $priceAsia = 0;
        }
        if ($priceEuro == '') {
            $priceEuro = 0;
        }
        if ($liaojin == '') {
            $liaojin = 0;
        }
        if ($zaiku == '') {
            $zaiku = 0;
        }
        global $cookie;
        $iso = Language::getIsoById((int) $cookie->LanguageID);
        /*
        $sql = 'REPLACE INTO '._DB_PREFIX_.'RoomPlan(RoomPlanId, RoomTypeId, RoomPlanName_'.$iso.', RoomMaxPersons, StartTime,
        EndTime, RoomSize, RoomPlanDescription_'.$iso.', Breakfast, Dinner, UseCon, ConFromTime, ConToTime, Nights, PriceAll, PriceAsia, PriceEuro, Active) ';
        $sql .="values($roomPlanId, '$roomTypeId', '$roomPlanName', $roomMaxPersons, '$startTime', '$endTime', $roomSize, '$roomPlanDesc', $breakfast, ".
        "$dinner, $useCon, '$conFromTime', '$conToTime', $nights, $priceAll, $priceAsia, $priceEuro, 1)";
        */
        //此处需要用insert 和 update组合 不能用replace, replace会在插入前加原有数据删除
        if ($roomPlanId == 0) {
            $sql = 'INSERT INTO ' . _DB_PREFIX_ . 'RoomPlan(RoomPlanId, RoomTypeId, RoomPlanName_en,RoomPlanName_jp,RoomPlanName_S_CN,RoomPlanName_T_CN, RoomMaxPersons, StartTime,
				EndTime, RoomSize, RoomPlanDescription_' . $iso . ', Breakfast, Dinner, UseCon, ConFromTime, ConToTime, Nights, PriceAll, PriceAsia, PriceEuro, Active) ';
            $sql .= "values({$roomPlanId}, '{$roomTypeId}', '{$roomPlanName}','{$roomPlanName}','{$roomPlanName}','{$roomPlanName}', {$roomMaxPersons}, '{$startTime}', '{$endTime}', {$roomSize}, '{$roomPlanDesc}', {$breakfast}, " . "{$dinner}, {$useCon}, '{$conFromTime}', '{$conToTime}', {$nights}, {$priceAll}, {$priceAsia}, {$priceEuro}, 1)";
        } else {
            $sql = "update " . _DB_PREFIX_ . "RoomPlan set RoomTypeId = '{$roomTypeId}', RoomPlanName_" . $iso . " = '{$roomPlanName}', RoomMaxPersons = {$roomMaxPersons}, \n\t\t\t\t\t\tliaojin = '{$liaojin}', zaiku = '{$zaiku}', RoomSize = {$roomSize}, RoomPlanDescription_" . $iso . " = '{$roomPlanDesc}',\n\t\t\t\t\t\tBreakfast = {$breakfast}, Dinner = {$dinner}, UseCon = {$useCon}, ConFromTime = '{$conFromTime}', ConToTime = '{$conToTime}', \n\t\t\t\t\t\tNights = {$nights}, PriceAll = {$priceAll}, PriceAsia = {$priceAsia}, PriceEuro = {$priceEuro}, Active = 1  \n\t\t\t\twhere RoomPlanId = {$roomPlanId}";
        }
        Db::getInstance()->ExecuteS($sql);
        //echo $sql;
        if ($roomPlanId != 0) {
            if (RoomPlan::getRoomPlanName($roomPlanId, 'en') == null) {
                RoomPlan::updateRoomPlanName($roomPlanId, 'en', $roomPlanName);
            }
            if (RoomPlan::getRoomPlanName($roomPlanId, 'jp') == null) {
                RoomPlan::updateRoomPlanName($roomPlanId, 'jp', $roomPlanName);
            }
            if (RoomPlan::getRoomPlanName($roomPlanId, 'S_CN') == null) {
                RoomPlan::updateRoomPlanName($roomPlanId, 'S_CN', $roomPlanName);
            }
            if (RoomPlan::getRoomPlanName($roomPlanId, 'T_CN') == null) {
                RoomPlan::updateRoomPlanName($roomPlanId, 'T_CN', $roomPlanName);
            }
        }
        if ($roomPlanId == 0) {
            // get new inserted room plan id
            $new_rpid = Db::getInstance()->Insert_ID();
            // insert HotelRoomPlanLink
            $sql = 'insert into ' . _DB_PREFIX_ . 'HotelRoomPlanLink(HotelId, RoomPlanId) ';
            $sql .= "values({$hotelId}, {$new_rpid})";
            Db::getInstance()->ExecuteS($sql);
            return $new_rpid;
            // inserted id
        }
        return 0;
        // update
    }