.
/**
* Book module local lib functions
*
* @package mod
* @subpackage book
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
define('BOOK_NUM_NONE', '0');
define('BOOK_NUM_NUMBERS', '1');
define('BOOK_NUM_BULLETS', '2');
define('BOOK_NUM_INDENTED', '3');
require_once($CFG->dirroot.'/mod/book/lib.php');
function book_get_numbering_types() {
return array (BOOK_NUM_NONE => get_string('numbering0', 'mod_book'),
BOOK_NUM_NUMBERS => get_string('numbering1', 'mod_book'),
BOOK_NUM_BULLETS => get_string('numbering2', 'mod_book'),
BOOK_NUM_INDENTED => get_string('numbering3', 'mod_book') );
}
//////////////////////////////////////////////////////////////////////////////////////
/// Any other book functions go here. Each of them must have a name that
/// starts with book_
//check chapter ordering and
//make sure subchapter is not first in book
//hidden chapter must have all subchapters hidden too
function book_check_structure($bookid) {
if ($chapters = get_records('book_chapters', 'bookid', $bookid, 'pagenum', 'id, pagenum, subchapter, hidden')) {
$first = true;
$hidesub = true;
$i = 1;
foreach($chapters as $ch) {
if ($first and $ch->subchapter) {
$ch->subchapter = 0;
}
$first = false;
if (!$ch->subchapter) {
$hidesub = $ch->hidden;
} else {
$ch->hidden = $hidesub ? true : $ch->hidden;
}
$ch->pagenum = $i;
update_record('book_chapters', $ch);
$i++;
}
}
}
/// prepare button to turn chapter editing on - connected with course editing
function book_edit_button($id, $courseid, $chapterid) {
global $CFG, $USER;
if (isteacheredit($courseid)) {
if (!empty($USER->editing)) {
$string = get_string("turneditingoff");
$edit = '0';
} else {
$string = get_string("turneditingon");
$edit = '1';
}
return '
';
} else {
return '';
}
}
/// general function for logging to table
function book_log($str1, $str2, $level = 0) {
switch ($level) {
case 1:
echo '