function testdbRoomLogsModule()
 {
     // Creates some room logs to add to the database
     $today = date('y-m-d');
     $roomLog1 = new RoomLog($today);
     $roomLog2 = new RoomLog("11-02-07");
     // Alter the status and log notes of a room
     $roomLog2->set_log_notes("Room Log 2");
     $roomLog2->set_status("archived");
     // test the insert function
     $this->assertTrue(insert_dbRoomLog($roomLog1));
     $this->assertTrue(insert_dbRoomLog($roomLog2));
     // test the retrieve function
     $this->assertEqual(retrieve_dbRoomLog($roomLog1->get_id())->get_status(), "unpublished");
     $this->assertEqual(retrieve_dbRoomLog($roomLog2->get_id())->get_status(), "archived");
     // test the update function
     $roomLog1->set_log_notes("Room Log 1 notes");
     $this->assertTrue(update_dbRoomLog($roomLog1));
     $this->assertEqual(retrieve_dbRoomLog($roomLog1->get_id())->get_log_notes(), "Room Log 1 notes");
     // test the delete function
     $this->assertTrue(delete_dbRoomLog($roomLog1->get_id()));
     $this->assertFalse(retrieve_dbRoomLog($roomLog1->get_id()));
     $this->assertTrue(delete_dbRoomLog($roomLog2->get_id()));
     echo "testdbRoomLogs complete";
 }
示例#2
0
function admin_rooms()
{
    global $sr_default_chat_name;
    // Show Rooms Page
    if ($_SERVER['REQUEST_METHOD'] != 'POST') {
        if (!sr_is_signed_in()) {
            sr_redirect('/d/main/signin/');
        }
        if (!sr_is_admin()) {
            sr_redirect('/d/');
        }
        $db = sr_pdo();
        $stmt = $db->prepare('SELECT * FROM room ORDER BY start_time DESC LIMIT 10');
        $stmt->execute();
        $room_list = $stmt->fetchAll(PDO::FETCH_CLASS, 'Room');
        foreach ($room_list as $a_room) {
            $room_id = $a_room->id;
            $stmt = $db->prepare("SELECT name FROM participant WHERE room_id='{$room_id}'");
            $stmt->execute();
            $participants = $stmt->fetchAll(PDO::FETCH_COLUMN);
            $a_room->participants = '';
            foreach ($participants as $a_participant) {
                if ($a_participant == '') {
                    $a_participant = $sr_default_chat_name;
                }
                $a_room->participants .= $a_participant . '<br />';
            }
        }
        $stmt = $db->prepare('SELECT * FROM room_log ORDER BY id DESC LIMIT 10');
        $stmt->execute();
        $room_log_list = $stmt->fetchAll(PDO::FETCH_CLASS, 'RoomLog');
        foreach ($room_log_list as $a_room_log) {
            $room_id = $a_room_log->room_id;
            $stmt = $db->prepare("SELECT participant_name FROM participant_log WHERE type=2 AND room_id='{$room_id}'");
            $stmt->execute();
            $participants = $stmt->fetchAll(PDO::FETCH_COLUMN);
            $a_room_log->participants = '';
            foreach ($participants as $a_participant) {
                if ($a_participant == '') {
                    $a_participant = $sr_default_chat_name;
                }
                $a_room_log->participants .= $a_participant . '<br />';
            }
        }
        $context = array('room_list' => $room_list, 'room_log_list' => $room_log_list);
        sr_response('views/admin/rooms.php', $context);
        // Handling Ajax Request
    } else {
        // Pagination or Filtering
        if ($_POST['type'] == 'pagination') {
            try {
                $db = sr_pdo();
                $json = $_POST['filter'];
                $json = stripslashes($json);
                $filter = json_decode($json);
                $where = '';
                $index = 0;
                foreach ($filter as $field => $value) {
                    if ($index++ == 0) {
                        $where .= 'WHERE ';
                    } else {
                        $where .= ' AND ';
                    }
                    $where .= $field . '=' . $value;
                }
                if ($_POST['table'] == 't1') {
                    $total_record_number = Room::getRecordNum($filter);
                } else {
                    $total_record_number = RoomLog::getRecordNum($filter);
                }
                if ($_POST['page_number'] == -1) {
                    $beginRecordNum = (int) ($total_record_number / 10) * 10;
                } else {
                    $beginRecordNum = ($_POST['page_number'] - 1) * 10;
                }
                if ($_POST['table'] == 't1') {
                    $stmt = $db->prepare("SELECT * FROM room {$where} ORDER BY start_time DESC LIMIT {$beginRecordNum}, 10");
                    $stmt->execute();
                    $record_list = $stmt->fetchAll(PDO::FETCH_CLASS, 'Room');
                    foreach ($record_list as $a_room) {
                        $room_id = $a_room->id;
                        $stmt = $db->prepare("SELECT name FROM participant WHERE room_id='{$room_id}'");
                        $stmt->execute();
                        $participants = $stmt->fetchAll(PDO::FETCH_COLUMN);
                        $a_room->participants = '';
                        foreach ($participants as $a_participant) {
                            if ($a_participant == '') {
                                $a_participant = $sr_default_chat_name;
                            }
                            $a_room->participants .= $a_participant . '<br />';
                        }
                    }
                } else {
                    $stmt = $db->prepare("SELECT * FROM room_log {$where} ORDER BY id DESC LIMIT {$beginRecordNum}, 10");
                    $stmt->execute();
                    $record_list = $stmt->fetchAll(PDO::FETCH_CLASS, 'RoomLog');
                    foreach ($record_list as $a_room_log) {
                        $room_id = $a_room_log->room_id;
                        $stmt = $db->prepare("SELECT participant_name FROM participant_log WHERE type=2 AND room_id='{$room_id}'");
                        $stmt->execute();
                        $participants = $stmt->fetchAll(PDO::FETCH_COLUMN);
                        $a_room_log->participants = '';
                        foreach ($participants as $a_participant) {
                            if ($a_participant == '') {
                                $a_participant = $sr_default_chat_name;
                            }
                            $a_room_log->participants .= $a_participant . '<br />';
                        }
                    }
                }
                $result = array('record_list' => $record_list, 'total_record_number' => $total_record_number);
                echo json_encode($result);
            } catch (PDOException $e) {
            }
            // Close Room Request
        } else {
            try {
                $db = sr_pdo();
                $stmt = $db->prepare('SELECT * FROM room WHERE id = :id');
                $stmt->bindParam(':id', $_POST['id']);
                $stmt->setFetchMode(PDO::FETCH_CLASS, 'Room');
                $stmt->execute();
                $room = $stmt->fetch();
                $roomLog = new RoomLog();
                $roomLog->room_id = $room->id;
                $roomLog->name = $room->name;
                $roomLog->title = $room->title;
                $roomLog->description = $room->description;
                $roomLog->is_open = $room->is_open;
                $roomLog->start_time = $room->start_time;
                $roomLog->end_time = Model::getCurrentTime();
                $roomLog->add($db);
                $room->close($db);
            } catch (PDOException $e) {
            }
        }
    }
}
示例#3
0
                    $('#' + table + '_next, #' + table + '_end').attr('class', '');
                }

                if (last_page - first_page_in_view < 4) {
                    for (var btn = (last_page - 1) % 5 + 2; btn <= 5; btn++) {
                        $('#' + table + '_' + ordinal[btn]).attr('class', 'disabled');
                    }
                }
            }

            // Initialize table
            updateTable('t1', <?php 
echo json_encode($context['room_list']);
?>
);
            updateTable('t2', <?php 
echo json_encode($context['room_log_list']);
?>
);
            updatePage('t1', 1, <?php 
echo Room::getRecordNum(array());
?>
);
            updatePage('t2', 1, <?php 
echo RoomLog::getRecordNum(array());
?>
);
        </script>
    </body>
</html>
 function testRoomLogModule()
 {
     // Generate a new room log
     $rl = new RoomLog("11-02-07");
     // make a time that was given to the constructor. This will
     // be used for testing
     $test_time = mktime(0, 0, 0, 02, 07, 2011);
     $this->assertEqual($rl->get_id(), date("y-m-d", $test_time));
     $this->assertEqual($rl->get_day_of_month(), date("d", $test_time));
     $this->assertEqual($rl->get_day(), date("D", $test_time));
     $this->assertEqual($rl->get_day_of_week(), date("N", $test_time));
     $this->assertEqual($rl->get_day_of_year(), date("z", $test_time) + 1);
     $this->assertEqual($rl->get_year(), date("Y", $test_time));
     $this->assertEqual($rl->get_status(), "unpublished");
     $this->assertEqual(sizeof($rl->get_rooms()), 21);
     $this->assertEqual($rl->get_name(), "February 7, 2011");
     // New date for testing that has seconds/hours/minutes
     $test_end_time = mktime(23, 59, 59, 02, 07, 2011);
     $this->assertEqual($rl->get_end_time(), $test_end_time);
     // Set some log notes
     $rl->set_log_notes("Some notes");
     $this->assertTrue(strcmp($rl->get_log_notes(), "Some notes") == 0);
     echo "testRoomLog complete";
 }
示例#5
0
function channel_destroyed_log($room)
{
    $db = sr_pdo();
    $r_log = new RoomLog();
    $r_log->room_id = $room->id;
    $r_log->name = $room->name;
    $r_log->title = $room->title;
    $r_log->description = $room->description;
    $r_log->is_open = $room->is_open;
    $r_log->start_time = $room->start_time;
    $r_log->end_time = $r_log->getCurrentTime();
    try {
        $r_log->add($db);
    } catch (PDOException $e) {
        // failed to write the log
        echo $e;
    }
}
function retrieve_mostrecent_dbRoomLog($date)
{
    // connect to the mysql server
    connect();
    // Retrieve the entry
    $query = "SELECT * FROM dbRoomLogs WHERE id <='" . $date . "' ORDER BY id DESC";
    $result = mysql_query($query);
    // check if successful
    if (mysql_num_rows($result) == 0) {
        mysql_close();
        return false;
    }
    // Store the first row of the result = the most recent room log
    $result_row = mysql_fetch_assoc($result);
    mysql_close();
    // Create a new room log from the information given
    $theRoomLog = new RoomLog($result_row['id']);
    // Replace the rooms in the room log
    $roomsString = $result_row['rooms'];
    $rooms = explode(",", $roomsString);
    $theRoomLog->set_rooms($rooms);
    // Add extra information if present
    if ($result_row['log_notes']) {
        $theRoomLog->set_log_notes($result_row['log_notes']);
    }
    if ($result_row['status']) {
        $theRoomLog->set_status($result_row['status']);
    }
    // return the roomlog
    return $theRoomLog;
}