Beispiel #1
0
/* PROGRAMMING FOR WEB II
   LAB 4 / TASK 3 ANSWER */
//Create array.
$months = array(array('January', 31), array('February', 28), array('March', 31), array('April', 30), array('May', 31), array('June', 30), array('July', 31), array('August', 31), array('September', 30), array('October', 31), array('November', 30), array('December', 31));
//print array
function printMonths($arr)
{
    echo "I am the first function -- printing months array!<br><br>";
    for ($i = 0; $i < 12; $i++) {
        $txt = "'" . $arr[$i][0] . "'=>" . $arr[$i][1] . " days";
        $txt .= $i == 11 ? "<br>" : ",";
        $txt .= "<br>";
        echo $txt;
    }
}
//modify the array
function modifyMonths(&$arr)
{
    echo "I am the second function -- modifying months array!<br>";
    for ($i = 0; $i < 12; $i++) {
        if ($arr[$i][1] == 31) {
            $arr[$i][0] = strrev(ucfirst(strrev(strtolower($arr[$i][0]))));
        }
    }
}
printMonths($months);
modifyMonths($months);
printMonths($months);
?>
   
Beispiel #2
0
function roomList(array $areas, $areaUrlString, array $rooms, $roomUrlString, $heading, $thisFile, $year, $month, $day, $selectedType, $selected)
{
    global $login;
    $room_names = array();
    $allRoomsNameAlreadyAdded = false;
    foreach ($rooms as $room) {
        if ($room['room_id'] == 0) {
            if ($allRoomsNameAlreadyAdded) {
                continue;
            }
            $allRoomsNameAlreadyAdded = true;
        }
        $room_names[] = $room['room_name'];
    }
    # Table with areas, rooms, minicals.
    ?>
<table height="140" width="100%" class="hiddenprint" id="roomlist">
    <tr>
        <?php 
    $area_names = array();
    foreach ($areas as $area_tmp) {
        $area_names[] = $area_tmp['area_name'];
    }
    $this_area_name = '';
    ?>
        <!-- All areas -->
        <td width="200">
            <img src="./img/icons/house.png" style="border: 0 solid black; vertical-align: middle;" alt="<?php 
    echo __('Areas');
    ?>
">
            <span style="text-decoration: underline"><?php 
    echo __("Areas");
    ?>
</span><br>
            <?php 
    $res = mysql_query("select id as area_id, area_name from mrbs_area order by area_name");
    if (mysql_num_rows($res)) {
        while ($row = mysql_fetch_assoc($res)) {
            $area_name = htmlspecialchars($row['area_name']);
            $area_selected = array_key_exists($row['area_id'], $areas);
            ?>
                        <input type="checkbox" name="roomlist_areaSelector"
                              value="<?php 
            echo $row['area_id'];
            ?>
"<?php 
            echo $area_selected ? ' checked="checked"' : '';
            ?>
>
                        <a href="<?php 
            echo $thisFile;
            ?>
?year=<?php 
            echo $year;
            ?>
&month=<?php 
            echo $month;
            ?>
&day=<?php 
            echo $day;
            ?>
&area=<?php 
            echo $row['area_id'];
            ?>
"
                            <?php 
            echo $area_selected ? ' style="color: red;"' : '';
            ?>
><?php 
            echo $area_name;
            ?>
</a><br>
                    <?php 
        }
    }
    ?>
            <br><br><br>
        </td>
        <td width="200">
            <?php 
    function printRoomSelector($room_id, $room_name)
    {
        global $thisFile, $year, $month, $day, $areaUrlString, $rooms;
        $room_selected = array_key_exists($room_id, $rooms);
        ?>
                <input type="checkbox" name="roomlist_roomSelector"
                   value="<?php 
        echo $room_id;
        ?>
"<?php 
        echo $room_selected ? ' checked="checked"' : '';
        ?>
>
                <a href="<?php 
        echo $thisFile;
        ?>
?year=<?php 
        echo $year;
        ?>
&month=<?php 
        echo $month;
        ?>
&day=<?php 
        echo $day;
        ?>
&area=<?php 
        echo $areaUrlString;
        ?>
&room=<?php 
        echo $room_id;
        ?>
"
                <?php 
        echo $room_selected ? ' style="color: red;"' : '';
        ?>
><?php 
        echo $room_name;
        ?>
</a><br>
                <?php 
    }
    ?>
            <img src="./img/icons/shape_square.png" style="border: 0 solid black; vertical-align: middle;" alt="<?php 
    echo __('Device');
    ?>
">

            <span style="text-decoration: underline"><?php 
    echo __("Device");
    ?>
</span><br>
            <?php 
    printRoomSelector(0, __('Whole area'));
    ?>
            <?php 
    $i = 1;
    $area_ids = array();
    foreach ($areas as $area) {
        $area_ids[] = 'area_id = \'' . $area['area_id'] . '\'';
    }
    $Q_room = mysql_query('SELECT id, room_name FROM mrbs_room WHERE (' . implode(' OR ', $area_ids) . ') AND hidden=\'false\' ORDER BY room_name');
    while ($R_room = mysql_fetch_assoc($Q_room)) {
        if ($i > 0 && $i % 6 == 0) {
            echo "</td><td width=200><br>";
        }
        $this_room_name = htmlspecialchars($R_room['room_name']);
        printRoomSelector($R_room['id'], $this_room_name);
        $i++;
    }
    ?>
        </td>

        <!-- Headings -->
        <td style="padding: 10px 10px 10px 10px;">
        <h1 align=center><?php 
    echo $heading;
    ?>
</h1>
        <h3 align=center><?php 
    echo implode(', ', $area_names) . ' - ' . implode(', ', $room_names);
    ?>
</h3>
        <?php 
    /* ## ADDING CALENDAR ## */
    $print_in_top = TRUE;
    echo '</td><td align="right">' . chr(10);
    include "trailer.inc.php";
    printMonths($areaUrlString, $rooms, $roomUrlString, $year, $month, $day, $selected, $selectedType);
    echo "</td>\n";
    echo "</tr></table>\n";
    echo '<table class="print" width="100%">' . chr(10);
    echo '<tr><td><b>' . __('Area') . ':</b> ' . implode(', ', $area_names) . ', <b>' . __('Room') . ':</b> ' . implode(', ', $room_names) . '</td></tr>' . chr(10);
    echo '<tr><td>' . __('Data collected/printed') . ' ' . date('H:i:s d-m-Y') . ' ' . __('by') . ' ' . $login['user_name'] . '</td></tr>' . chr(10);
    echo '<tr><td>' . __('Type of view') . ': ';
    if ($thisFile == 'day.php') {
        echo __('day');
    } elseif ($thisFile == 'week.php') {
        echo __('week');
    } elseif ($thisFile == 'month.php') {
        echo __('month');
    }
    echo '</td></tr>' . chr(10);
    echo '<tr><td>&nbsp;</td></tr>' . chr(10);
    echo '<tr><td>';
    echo '<h1>' . $heading . ':</h1>' . chr(10);
    echo '</td></tr>' . chr(10);
    echo '</table>';
    ?>
    <form method="GET" action="<?php 
    echo $thisFile;
    ?>
" id="roomlistForm">
        <input type="hidden" name="year"  value="<?php 
    echo $year;
    ?>
"          />
        <input type="hidden" name="month" value="<?php 
    echo $month;
    ?>
"         />
        <input type="hidden" name="day"   value="<?php 
    echo $day;
    ?>
"           />
        <input type="hidden" name="area"  value="<?php 
    echo $areaUrlString;
    ?>
" />
        <input type="hidden" name="room"  value="<?php 
    echo $roomUrlString;
    ?>
" />
    </form>
<?php 
    echo '<script type="text/javascript" src="js/entry-overview.js"></script>';
}
    $reply .= '</section>';
    return $reply;
}
function printMonths()
{
    global $months;
    $monthIndex = 0;
    $output = '<li>';
    // print out the calendar structure
    // Loop over each month
    foreach ($months as $month) {
        // print out the month name
        $name = $month[0];
        $days = $month[1];
        $output .= printDays($name, $days);
        ++$monthIndex;
    }
    $output .= '</li>';
    $output .= '</ul>';
    return $output;
}
?>
<div id="calendar">
    <?php 
echo printMonths();
?>
</div>