<?php
include(dirname(__FILE__) . '/../header1.php');
?>
<script>
function room_num_onChange()
{
    set_room_table();
}

function set_room_table()
{
    var room_num = parseInt(document.myform.room_num.value);
    //alert(room_num);
    for (i = 1;; i++)
    {
        var id = 'room_' + i;
        var obj = document.getElementById(id);
        if (obj == null)
        {
            break;
        }
        if (i <= room_num)
        {
            obj.style.display = "block";
        }
        else
        {
            obj.style.display = "none";
        }
    }
}

function stay_days_onChange()
{
    set_option_table();
}

function set_option_table()
{
    var stay_days = parseInt(document.myform.stay_days.value);
    //alert(stay_days);
    for (i = 1;; i++)
    {
        var id = 'option_' + i;
        var obj = document.getElementById(id);
        if (obj == null)
        {
            break;
        }
        if (i <= stay_days)
        {
            obj.style.display = "block";
        }
        else
        {
            obj.style.display = "none";
        }
    }
}
</script>
<?php
$body_js = 'onLoad="set_room_table();set_option_table()"';
include(dirname(__FILE__) . '/../header2.php');
?>
<image src="<?php echo site_url('images/step1.png') ?>">

<h2>宿泊内容入力</h2>

<?php
//var_dump($form_guesttypes);
if (isset($error) && count($error))
{
    echo '<div class="form_error"><ul>' . "\n";
    foreach ($error as $err)
    {
        echo "<li>" . $err . "</li>" . "\n";
    }
    echo '</ul></div>' . "\n";
}
?>

<?php echo form_open('res/index/' . $hotelid . '/' . $planid . '/' . $d, array('name' => 'myform')); ?>

<table class="inp">
<tr>
<th>プラン :</th>
<td><?php echo $plan_name . '(' . $guest_min . '～' . $guest_max . '人)'; ?></td>
</tr>
<tr>
<th>チェックイン日 :</th><td>
<?php
$s_cin = substr($d, 0, 4) . '-' . substr($d, 4, 2) . '-' . substr($d, 6, 2);
echo $s_cin;
echo ' (' . $this->Common_model->week($s_cin) . ')';
?></td></tr>
<tr><th>* 宿泊日数 :</th>
<td>
<?php
$stay_days_options = array();
for ($i = 1; $i <= $max_days; $i++)
{
    $stay_days_options[$i] = $i;
}
$js = 'id="stay_days" onChange="stay_days_onChange();"';
$value = set_value('stay_days', isset($stay_days) ? $stay_days : '');
echo form_dropdown('stay_days', $stay_days_options, $value, $js) . ' 日';
?>
<?php echo form_error('stay_days'); ?>
</td></tr>
<tr><th>部屋タイプ :</th>
<td>
<?php echo $roomtype_name . '(' . $roomtypes_guest_min . '～' . $roomtypes_guest_max . '人)'; ?>
</td></tr>
<tr><th>* 部屋数 :</th>
<td>
<?php
$guest_options = array();
for ($i = 0; $i <= $guest_max; $i++)
{
    $guest_options[$i] = $i;
}
$room_options = array();
for ($i = 1; $i <= $max_rooms; $i++)
{
    $room_options[$i] = $i;
}
$js = 'id="room_num" onChange="room_num_onChange();"';
$value = set_value('room_num', isset($room_num) ? $room_num : '');
echo form_dropdown('room_num', $room_options, $value, $js) . ' 部屋';
?>
<?php echo form_error('room_num'); ?>
</td></tr>
<tr><th>* 人数 :</th><td>
<?php
$i = 0;
foreach ($form_guesttypes as $tmp1)
{
?>
<table class="table_temp" id="room_<?php echo ($i + 1); ?>">
<th><tr>
<td><?php echo ($i + 1) . '部屋目 :' ?></td>
<?php
foreach ($tmp1 as $tmp2)
{
    echo '<td>' . $tmp2['guesttype_name'] . ':' . '</td>';
    echo '<td>';
    $form_name = 'form_guesttypes[' . ($i+1) . '][' . $tmp2['guesttypeid'] . ']';
    $default_n = $tmp2['form_value'];
    if (isset($_POST['form_guesttypes'][$i + 1][$tmp2['guesttypeid']]))
    {
        $default_n = $_POST['form_guesttypes'][$i + 1][$tmp2['guesttypeid']];
    }
    echo form_dropdown($form_name, $guest_options, $default_n) . ' 人';
    echo '</td>';
}
?>
</tr></table>
<?php
    $i++;
}   /* */
?>
<?php
foreach ($guesttypes as $guesttype)
{
    $form_name = 'guesttype_' . $guesttype['guesttypeid'] . '[]';
    echo form_error($form_name);
}
?>
</td>
</tr>

<?php if (isset($has_options)) { ?>
<tr><th>* オプション :</th><td>
<?php
$i = 0;
foreach ($form_options as $key => $value)
{
?>
<table class="table_temp" id="option_<?php echo ($i + 1); ?>">
<th><tr>
<td><?php echo ($i + 1) . '日目(' . $key . '):' ?></td>
<td>
<?php
    $aaa = 0;
    foreach ($value as $key2 => $value2)
    {
        if ($aaa++ != 0)
        {
            echo "<br />\n";
        }
        // key2 -> optionid
        //var_dump($options[$i][$j]);
        $option = $form_options[$key][$key2];
        echo $option['option_name'] . "|";
        //echo $option['summary'] . "<br />\n";
        echo number_format($option['price']) . " 円"  . " x ";
        
        for ($k = 0; $k <= $option['max_num']; $k++)
        {
            $option_options[$k] = $k;
        }
        $dropdown_name = 'form_options[' . $key . '][' . $key2 . ']';
        
        $option_value = 0;
        if (isset($_POST['form_options'][$key][$key2]))
        {
            $option_value = $_POST['form_options'][$key][$key2];
        }
        echo form_dropdown($dropdown_name, $option_options, $option_value);
        echo $option['unitname'];
    }
    //var_dump($options[$i]);
    //echo $key;
    //echo var_dump($value);
    echo "<br />\n";
?>
</td></tr></table>
<?php
$i++;
}   /* /for */
?>
</td><td>
</tr>
<?php } ?>
</table>
<input type="submit" name="mysubmit" value="見積もりへ進む" />

</form>

<?php
include(dirname(__FILE__) . '/../footer.php');
?>
