index.php 3.38 KB
Newer Older
1
<?PHP // $Id: index.php,v 1.3 2008/03/25 20:19:49 poltawski Exp $
Petr Skoda's avatar
Petr Skoda committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

/// This page lists all the instances of book in a particular course

require_once('../../config.php');
require_once('lib.php');

$id = required_param('id', PARAM_INT);           // Course Module ID

// =========================================================================
// security checks START - teachers and students view
// =========================================================================

if (!$course = get_record('course', 'id', $id)) {
    error('Course ID is incorrect');
}

18
require_course_login($course, true);
Petr Skoda's avatar
Petr Skoda committed
19
20
21
22
23
24
25
26
27
28
29
30
31

//check all variables
unset($id);

// =========================================================================
// security checks END
// =========================================================================

/// Get all required strings
$strbooks = get_string('modulenameplural', 'book');
$strbook  = get_string('modulename', 'book');


32
33
34
35
36
$navlinks = array();
$navlinks[] = array('name' => $strbooks, 'link' => '', 'type' => 'activity');
$navigation = build_navigation($navlinks);

print_header_simple($strbooks, '', $navigation, '', '', true, '', navmenu($course));
Petr Skoda's avatar
Petr Skoda committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

add_to_log($course->id, 'book', 'view all', 'index.php?id='.$course->id, '');

/// Get all the appropriate data
if (!$books = get_all_instances_in_course('book', $course)) {
    notice('There are no books', '../../course/view.php?id='.$course->id);
    die;
}

/// Print the list of instances
$strname  = get_string('name');
$strweek  = get_string('week');
$strtopic  = get_string('topic');
$strsummary = get_string('summary');
$strchapters  = get_string('chapterscount', 'book');

if ($course->format == 'weeks') {
    $table->head  = array ($strweek, $strname, $strsummary, $strchapters);
    $table->align = array ('center', 'left', 'left', 'center');
} else if ($course->format == 'topics') {
    $table->head  = array ($strtopic, $strname, $strsummary, $strchapters);
    $table->align = array ('center', 'left', 'left', 'center');
} else {
    $table->head  = array ($strname, $strsummary, $strchapters);
    $table->align = array ('left', 'left', 'left');
}

$currentsection = '';
foreach ($books as $book) {
    $nocleanoption = new object();
    $nocleanoption->noclean = true;
    $book->summary = format_text($book->summary, FORMAT_HTML, $nocleanoption, $course->id);
    $book->summary = '<span style="font-size:x-small;">'.$book->summary.'</span>';

    if (!$book->visible) {
        //Show dimmed if the mod is hidden
        $link = '<a class="dimmed" href="view.php?id='.$book->coursemodule.'">'.$book->name.'</a>';
    } else {
        //Show normal if the mod is visible
        $link = '<a href="view.php?id='.$book->coursemodule.'">'.$book->name.'</a>';
    }

    $count = count_records('book_chapters', 'bookid', $book->id, 'hidden', '0');

    if ($course->format == 'weeks' or $course->format == 'topics') {
        $printsection = '';
        if ($book->section !== $currentsection) {
            if ($book->section) {
                $printsection = $book->section;
            }
            if ($currentsection !== '') {
                $table->data[] = 'hr';
            }
            $currentsection = $book->section;
        }
        $table->data[] = array ($printsection, $link, $book->summary, $count);
    } else {
        $table->data[] = array ($link, $book->summary, $count);
    }
}

echo '<br />';
print_table($table);

print_footer($course);

?>