diff --git a/README.txt b/README.txt index b1ac52d86d6..9b2b5782e6c 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -$Id: README.txt,v 1.2 2006/04/24 19:41:14 skodak Exp $ +$Id: README.txt,v 1.3 2007/05/20 06:00:29 skodak Exp $ /////////////////////////////////////////////////////////////////////////// // // @@ -110,5 +110,9 @@ CHANGELOG: * all languages converted to utf-8 * moved to contrib/book_16 directory * added proper content encoding conversion during import +== 1.4alpha - 2007/05/20 ==================================================== + * compatible with 1.8 + * export link enabled - thanks Eloy! + * no new features skodak diff --git a/book_theme.css b/book_theme.css index 84005bf955f..098b19408f8 100644 --- a/book_theme.css +++ b/book_theme.css @@ -1,4 +1,4 @@ -/* $Id: book_theme.css,v 1.1 2006/03/12 18:39:59 skodak Exp $*/ +/* $Id: book_theme.css,v 1.2 2007/05/20 06:00:30 skodak Exp $*/ /* later should be defined in themes*/ @@ -16,6 +16,15 @@ text-align: left; } +img.bigicon { + vertical-align:middle; + margin-right:4px; + margin-left:4px; + width:24px; + height:24px; + border:0px; +} + /* == TOC styles == */ /* toc style NONE */ diff --git a/coursefiles.php b/coursefiles.php index fc2e85afa1f..b3537a2006c 100644 --- a/coursefiles.php +++ b/coursefiles.php @@ -1,4 +1,4 @@ -libdir.'/filelib.php'); + require($CFG->libdir.'/adminlib.php'); $id = required_param('id', PARAM_INT); $file = optional_param('file', '', PARAM_PATH); @@ -16,10 +17,14 @@ $action = optional_param('action', '', PARAM_ACTION); $name = optional_param('name', '', PARAM_FILE); $oldname = optional_param('oldname', '', PARAM_FILE); - $choose = required_param('choose', PARAM_CLEAN); + $choose = optional_param('choose', '', PARAM_FILE); //in fact it is always 'formname.inputname' + $userfile= optional_param('userfile','',PARAM_FILE); + $save = optional_param('save', 0, PARAM_BOOL); + $text = optional_param('text', '', PARAM_RAW); + $confirm = optional_param('confirm', 0, PARAM_BOOL); if ($choose) { - if (count(explode('.', $choose)) != 2) { + if (count(explode('.', $choose)) > 2) { error('Incorrect format for choose parameter'); } } @@ -29,32 +34,26 @@ error("That's an invalid course id"); } - require_login($course->id); + require_login($course); - if (! isteacheredit($course->id) ) { - error("You need to be a teacher with editing privileges"); - } + require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id)); function html_footer() { + global $course, $choose, $adminroot; - global $course, $choose; + echo ''; - if ($choose) { - echo ""; + if ($course->id == SITEID) { + admin_externalpage_print_footer($adminroot); } else { - echo ""; print_footer($course); } } - + function html_header($course, $wdir, $formfield=""){ global $CFG, $ME, $choose; - if (! $site = get_site()) { - error("Invalid site!"); - } - - if ($course->id == $site->id) { + if ($course->id == SITEID) { $strfiles = get_string("sitefiles"); } else { $strfiles = get_string("files"); @@ -80,43 +79,65 @@ print_header(); $chooseparts = explode('.', $choose); - + if (count($chooseparts)==2){ ?> - ', '»', "$course->shortname -> $fullnav"); + } elseif (count($chooseparts)==1){ + ?> + + + ', '»', format_string($course->shortname) . " -> $fullnav"); echo ''; - if ($course->id == $site->id) { + if ($course->id == SITEID and $wdir != "/backupdata") { print_heading(get_string("publicsitefileswarning"), "center", 2); } } else { - if ($course->id == $site->id) { - print_header("$course->shortname: $strfiles", "$course->fullname", - "admin/index.php\">".get_string("administration"). - " -> $fullnav", $formfield); + if ($course->id == SITEID) { - print_heading(get_string("publicsitefileswarning"), "center", 2); + if ($wdir == "/backupdata") { + $adminroot = admin_get_root(); + admin_externalpage_setup('frontpagerestore', $adminroot); + admin_externalpage_print_header($adminroot); + } else { + $adminroot = admin_get_root(); + admin_externalpage_setup('sitefiles', $adminroot); + admin_externalpage_print_header($adminroot); + + print_heading(get_string("publicsitefileswarning"), "center", 2); + + } } else { - print_header("$course->shortname: $strfiles", "$course->fullname", + print_header("$course->shortname: $strfiles", $course->fullname, "id\">$course->shortname". " -> $fullnav", $formfield); } } - echo ""; + echo "
"; echo ""; echo "'; + echo ''; } function displaydir ($wdir) { @@ -623,13 +688,14 @@ function displaydir ($wdir) { global $choose; $fullpath = $basedir.$wdir; + $dirlist = array(); $directory = opendir($fullpath); // Find all files while (false !== ($file = readdir($directory))) { if ($file == "." || $file == "..") { continue; } - + if (is_dir($fullpath."/".$file)) { $dirlist[] = $file; } else { @@ -644,6 +710,8 @@ function displaydir ($wdir) { $straction = get_string("action"); $strmakeafolder = get_string("makeafolder"); $struploadafile = get_string("uploadafile"); + $strselectall = get_string("selectall"); + $strselectnone = get_string("deselectall"); $strwithchosenfiles = get_string("withchosenfiles"); $strmovetoanotherfolder = get_string("movetoanotherfolder"); $strmovefilestohere = get_string("movefilestohere"); @@ -654,25 +722,26 @@ function displaydir ($wdir) { $strunzip = get_string("unzip"); $strlist = get_string("list"); $strrestore= get_string("restore"); - $strchoose = get_string("choose"); + $strchoose = get_string("choose"); + $strfolder = get_string("folder"); + $strfile = get_string("file"); - echo ""; - echo ''; - echo "
"; - echo "
"; @@ -132,15 +153,12 @@ // End of configuration and access control - if (!$wdir) { - $wdir="/"; + if ($wdir == '') { + $wdir = "/"; } - if (($wdir != '/' and detect_munged_arguments($wdir, 0)) - or ($file != '' and detect_munged_arguments($file, 0))) { - $message = "Error: Directories can not contain \"..\""; - $wdir = "/"; - $action = ""; + if ($wdir{0} != '/') { //make sure $wdir starts with slash + $wdir = "/".$wdir; } if ($wdir == "/backupdata") { @@ -149,13 +167,18 @@ } } + if (!is_dir($basedir.$wdir)) { + html_header($course, $wdir); + error("Requested directory does not exist.", "$CFG->wwwroot/files/index.php?id=$id"); + } + switch ($action) { case "upload": html_header($course, $wdir); require_once($CFG->dirroot.'/lib/uploadlib.php'); - - if (!empty($save) and confirm_sesskey()) { + + if ($save and confirm_sesskey()) { $course->maxbytes = 0; // We are ignoring course limits $um = new upload_manager('userfile',false,false,$course,false,0); $dir = "$basedir$wdir"; @@ -173,38 +196,42 @@ $strmaxsize = get_string("maxsize", "", $filesize); $strcancel = get_string("cancel"); - echo "

$struploadafile ($strmaxsize) --> $wdir"; - echo "
"; + echo "

$struploadafile ($strmaxsize) --> $wdir

"; echo "
"; - echo ' '; + echo "
"; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; echo " sesskey\" />"; upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false); - echo "
"; + echo "
"; echo " "; + echo "
"; echo "
"; - echo "
"; echo "
"; - echo ' '; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; echo " "; + echo "
"; echo "
"; - echo "
"; } html_footer(); break; case "delete": - if (!empty($confirm) and confirm_sesskey()) { + if ($confirm and confirm_sesskey()) { html_header($course, $wdir); - foreach ($USER->filelist as $file) { - $fullfile = $basedir.$file; - if (! fulldelete($fullfile)) { - echo "
Error: Could not delete: $fullfile"; + if (!empty($USER->filelist)) { + foreach ($USER->filelist as $file) { + $fullfile = $basedir.'/'.$file; + if (! fulldelete($fullfile)) { + echo "
Error: Could not delete: $fullfile"; + } } } clearfilelist(); @@ -213,15 +240,27 @@ } else { html_header($course, $wdir); + if (setfilelist($_POST)) { - echo "

".get_string("deletecheckwarning").":

"; + notify(get_string('deletecheckwarning').':'); print_simple_box_start("center"); printfilelist($USER->filelist); print_simple_box_end(); echo "
"; - notice_yesno (get_string("deletecheckfiles"), - "coursefiles.php?id=$id&wdir=$wdir&action=delete&confirm=1&sesskey=$USER->sesskey&choose=$choose", - "coursefiles.php?id=$id&wdir=$wdir&action=cancel&choose=$choose"); + + require_once($CFG->dirroot.'/mod/resource/lib.php'); + $block = resource_delete_warning($course, $USER->filelist); + + if (empty($CFG->resource_blockdeletingfile) or $block == '') { + $optionsyes = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'choose'=>$choose); + $optionsno = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose); + notice_yesno (get_string('deletecheckfiles'), 'coursefiles.php', 'coursefiles.php', $optionsyes, $optionsno, 'post', 'get'); + } else { + + notify(get_string('warningblockingdelete', 'resource')); + $options = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose); + print_continue("coursefiles.php?id=$id&wdir=$wdir&action=cancel&choose=$choose"); + } } else { displaydir($wdir); } @@ -234,7 +273,7 @@ if (($count = setfilelist($_POST)) and confirm_sesskey()) { $USER->fileop = $action; $USER->filesource = $wdir; - echo "

"; + echo "

"; print_string("selectednowmove", "moodle", $count); echo "

"; } @@ -247,10 +286,10 @@ if (isset($USER->fileop) and ($USER->fileop == "move") and confirm_sesskey()) { foreach ($USER->filelist as $file) { $shortfile = basename($file); - $oldfile = $basedir.$file; + $oldfile = $basedir.'/'.$file; $newfile = $basedir.$wdir."/".$shortfile; if (!rename($oldfile, $newfile)) { - echo "

Error: $shortfile not moved"; + echo "

Error: $shortfile not moved

"; } } } @@ -260,25 +299,30 @@ break; case "rename": - if (!empty($name) and confirm_sesskey()) { + if (($name != '') and confirm_sesskey()) { html_header($course, $wdir); $name = clean_filename($name); if (file_exists($basedir.$wdir."/".$name)) { - echo "Error: $name already exists!"; + echo "
Error: $name already exists!
"; } else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) { - echo "Error: could not rename $oldname to $name"; + echo "

Error: could not rename $oldname to $name

"; + } else { + //file was renamed now update resources if needed + require_once($CFG->dirroot.'/mod/resource/lib.php'); + resource_renamefiles($course, $wdir, $oldname, $name); } displaydir($wdir); - + } else { $strrename = get_string("rename"); $strcancel = get_string("cancel"); $strrenamefileto = get_string("renamefileto", "moodle", $file); html_header($course, $wdir, "form.name"); - echo "

$strrenamefileto:"; + echo "

$strrenamefileto:

"; echo "
"; - echo "
"; - echo ' '; + echo ""; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; @@ -286,54 +330,61 @@ echo " sesskey\" />"; echo " "; echo " "; + echo "
"; echo "
"; echo "
"; echo "
"; - echo ' '; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; echo " "; + echo "
"; echo "
"; echo "
"; } html_footer(); break; - case "mkdir": - if (!empty($name) and confirm_sesskey()) { + case "makedir": + if (($name != '') and confirm_sesskey()) { html_header($course, $wdir); $name = clean_filename($name); if (file_exists("$basedir$wdir/$name")) { echo "Error: $name already exists!"; - } else if (! make_upload_directory("$course->id/$wdir/$name")) { + } else if (! make_upload_directory("$course->id$wdir/$name")) { echo "Error: could not create $name"; } displaydir($wdir); - + } else { $strcreate = get_string("create"); $strcancel = get_string("cancel"); $strcreatefolder = get_string("createfolder", "moodle", $wdir); html_header($course, $wdir, "form.name"); - echo "

$strcreatefolder:"; + echo "

$strcreatefolder:

"; echo "
"; - echo "
"; - echo ' '; + echo ""; + echo "
"; + echo ' '; echo " "; echo " "; - echo " "; + echo " "; echo " "; echo " sesskey\" />"; echo " "; + echo "
"; echo "
"; echo "
"; echo "
"; - echo ' '; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; echo " "; + echo "
"; echo "
"; echo "
"; } @@ -342,16 +393,17 @@ case "edit": html_header($course, $wdir); - if (isset($text) and confirm_sesskey()) { - $fileptr = fopen($basedir.$file,"w"); + if (($text != '') and confirm_sesskey()) { + $fileptr = fopen($basedir.'/'.$file,"w"); + $text = preg_replace('/\x0D/', '', $text); // http://moodle.org/mod/forum/discuss.php?d=38860 fputs($fileptr, stripslashes($text)); fclose($fileptr); displaydir($wdir); - + } else { $streditfile = get_string("edit", "", "$file"); - $fileptr = fopen($basedir.$file, "r"); - $contents = fread($fileptr, filesize($basedir.$file)); + $fileptr = fopen($basedir.'/'.$file, "r"); + $contents = fread($fileptr, filesize($basedir.'/'.$file)); fclose($fileptr); if (mimeinfo("type", $file) == "text/html") { @@ -364,8 +416,9 @@ print_heading("$streditfile"); echo "
"; - echo "
"; - echo ' '; + echo ""; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; @@ -374,18 +427,21 @@ print_textarea($usehtmleditor, 25, 80, 680, 400, "text", $contents); echo "
"; echo " "; + echo ""; echo ""; echo ""; echo "
"; - echo ' '; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; echo " "; + echo "
"; echo "
"; echo "
"; - if ($usehtmleditor) { + if ($usehtmleditor) { use_html_editor(); } @@ -395,7 +451,7 @@ break; case "zip": - if (!empty($name) and confirm_sesskey()) { + if (($name != '') and confirm_sesskey()) { html_header($course, $wdir); $name = clean_filename($name); @@ -404,13 +460,13 @@ $files[] = "$basedir/$file"; } - if (!zip_files($files,"$basedir/$wdir/$name")) { + if (!zip_files($files,"$basedir$wdir/$name")) { error(get_string("zipfileserror","error")); } clearfilelist(); displaydir($wdir); - + } else { html_header($course, $wdir, "form.name"); @@ -420,24 +476,28 @@ printfilelist($USER->filelist); print_simple_box_end(); echo "
"; - echo "

".get_string("whattocallzip"); + echo "

".get_string("whattocallzip")."

"; echo "
"; - echo "
"; - echo ' '; + echo ""; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; echo " "; echo " sesskey\" />"; echo " "; + echo "
"; echo ""; echo "
"; echo "
"; - echo ' '; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; echo " "; + echo "
"; echo "
"; echo "
"; } else { @@ -450,7 +510,7 @@ case "unzip": html_header($course, $wdir); - if (!empty($file) and confirm_sesskey()) { + if (($file != '') and confirm_sesskey()) { $strok = get_string("ok"); $strunpacking = get_string("unpacking", "", $file); @@ -458,18 +518,20 @@ $file = basename($file); - if (!unzip_file("$basedir/$wdir/$file")) { + if (!unzip_file("$basedir$wdir/$file")) { error(get_string("unzipfileserror","error")); } - echo "
"; - echo ' '; + echo "
"; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; echo " "; + echo "
"; echo ""; - echo "
"; + echo ""; } else { displaydir($wdir); } @@ -478,7 +540,7 @@ case "listzip": html_header($course, $wdir); - if (!empty($file) and confirm_sesskey()) { + if (($file != '') and confirm_sesskey()) { $strname = get_string("name"); $strsize = get_string("size"); $strmodified = get_string("modified"); @@ -489,16 +551,16 @@ $file = basename($file); include_once("$CFG->libdir/pclzip/pclzip.lib.php"); - $archive = new PclZip(cleardoubleslashes("$basedir/$wdir/$file")); - if (!$list = $archive->listContent(cleardoubleslashes("$basedir/$wdir"))) { + $archive = new PclZip(cleardoubleslashes("$basedir$wdir/$file")); + if (!$list = $archive->listContent(cleardoubleslashes("$basedir$wdir"))) { notify($archive->errorInfo(true)); } else { echo ""; - echo ""; + echo ""; foreach ($list as $item) { echo ""; - print_cell("left", $item['filename'], 'name'); + print_cell("left", s($item['filename']), 'name'); if (! $item['folder']) { print_cell("right", display_size($item['size']), 'size'); } else { @@ -511,11 +573,13 @@ echo "
$strname$strsize$strmodified
$strname$strsize$strmodified
"; } echo "
"; - echo ' '; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; echo " "; + echo "
"; echo "
"; echo "
"; } else { @@ -526,7 +590,7 @@ case "restore": html_header($course, $wdir); - if (!empty($file) and confirm_sesskey()) { + if (($file != '') and confirm_sesskey()) { echo "

".get_string("youaregoingtorestorefrom").":

"; print_simple_box_start("center"); echo $file; @@ -535,14 +599,14 @@ echo "

".get_string("areyousuretorestorethisinfo")."

"; $restore_path = "$CFG->wwwroot/backup/restore.php"; notice_yesno (get_string("areyousuretorestorethis"), - $restore_path."?id=".$id."&file=".cleardoubleslashes($id.$wdir."/".$file), + $restore_path."?id=".$id."&file=".cleardoubleslashes($id.$wdir."/".$file)."&method=manual", "coursefiles.php?id=$id&wdir=$wdir&action=cancel"); } else { displaydir($wdir); } html_footer(); break; - + case "cancel": clearfilelist(); @@ -568,9 +632,7 @@ function setfilelist($VARS) { if (substr($key,0,4) == "file") { $count++; $val = rawurldecode($val); - if (!detect_munged_arguments($val, 0)) { - $USER->filelist[] = $val; - } + $USER->filelist[] = clean_param($val, PARAM_PATH); } } return $count; @@ -587,11 +649,14 @@ function clearfilelist() { function printfilelist($filelist) { global $CFG, $basedir; + $strfolder = get_string("folder"); + $strfile = get_string("file"); + foreach ($filelist as $file) { - if (is_dir($basedir.$file)) { - echo "pixpath/f/folder.gif\" height=\"16\" width=\"16\" alt=\"\" /> $file
"; + if (is_dir($basedir.'/'.$file)) { + echo "pixpath/f/folder.gif\" class=\"icon\" alt=\"$strfolder\" /> $file
"; $subfilelist = array(); - $currdir = opendir($basedir.$file); + $currdir = opendir($basedir.'/'.$file); while (false !== ($subfile = readdir($currdir))) { if ($subfile <> ".." && $subfile <> ".") { $subfilelist[] = $file."/".$subfile; @@ -599,9 +664,9 @@ function printfilelist($filelist) { } printfilelist($subfilelist); - } else { + } else { $icon = mimeinfo("icon", $file); - echo "pixpath/f/$icon\" height=\"16\" width=\"16\" alt=\"\" /> $file
"; + echo "pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" /> $file
"; } } } @@ -611,7 +676,7 @@ function print_cell($alignment='center', $text=' ', $class='') { if ($class) { $class = ' class="'.$class.'"'; } - echo '
'.$text.''.$text.'
"; + echo ""; + echo "
"; + echo ''; + // echo "
"; + echo "
"; + echo "
"; echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; echo "\n"; - if ($wdir == "/") { - $wdir = ""; - } - if (!empty($wdir)) { + if ($wdir != "/") { $dirlist[] = '..'; } @@ -683,17 +752,11 @@ function displaydir ($wdir) { foreach ($dirlist as $dir) { echo ""; - $dirurl = "$wdir/$dir"; - if (substr($dirurl,0,1) == '/') { - $selectdir = substr($dirurl,1); - } else { - $selectdir = $dirurl; - } - if ($dir == '..') { $fileurl = rawurlencode(dirname($wdir)); print_cell(); - print_cell('left', ''.get_string('parentfolder').''.get_string('parentfolder').'', 'name'); + // alt attribute intentionally empty to prevent repetition in screen reader + print_cell('left', ' '.get_string('parentfolder').'', 'name'); print_cell(); print_cell(); print_cell(); @@ -705,18 +768,19 @@ function displaydir ($wdir) { $filesafe = rawurlencode($dir); $filesize = display_size(get_directory_size("$fullpath/$dir")); $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); + $selectfile = trim($wdir."/".$dir, "/"); print_cell("center", "", 'checkbox'); - print_cell("left", "pixpath/f/folder.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\"Folder\" />".htmlspecialchars($dir)."", 'name'); + print_cell("left", "pixpath/f/folder.gif\" class=\"icon\" alt=\"$strfolder\" /> ".htmlspecialchars($dir)."", 'name'); print_cell("right", $filesize, 'size'); print_cell("right", $filedate, 'date'); if ($choose) { - $edittext = "$strchoose "; - } else { - $edittext = ''; - } + $edittext = "$strchoose "; + } else { + $edittext = ''; + } print_cell("right", "$edittext $strrename", 'commands'); } - + echo ""; } } @@ -730,32 +794,24 @@ function displaydir ($wdir) { $count++; $filename = $fullpath."/".$file; - $fileurl = "$wdir/$file"; + $fileurl = trim($wdir, "/")."/$file"; $filesafe = rawurlencode($file); $fileurlsafe = rawurlencode($fileurl); $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); - if (substr($fileurl,0,1) == '/') { - $selectfile = substr($fileurl,1); - } else { - $selectfile = $fileurl; - } + $selectfile = trim($fileurl, "/"); echo ""; print_cell("center", "", 'checkbox'); - echo ""; @@ -763,8 +819,8 @@ function displaydir ($wdir) { print_cell("right", display_size($file_size), 'size'); print_cell("right", $filedate, 'date'); - if ($choose && $icon == "html.gif") { - $edittext = "$strchoose "; + if ($choose) { + $edittext = "$strchoose "; } else { $edittext = ''; } @@ -775,24 +831,24 @@ function displaydir ($wdir) { } else if ($icon == "zip.gif") { $edittext .= "sesskey&choose=$choose\">$strunzip "; $edittext .= "sesskey&choose=$choose\">$strlist "; + if (!empty($CFG->backup_version) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) { + $edittext .= "sesskey&choose=$choose\">$strrestore "; + } } print_cell("right", "$edittext $strrename", 'commands'); - + echo ""; } } echo "
$strname$strsize$strmodified$straction$strname$strsize$strmodified$straction
"; + echo ""; if ($CFG->slasharguments) { - $ffurl = "/file.php/$id$fileurl"; + $ffurl = str_replace('//', '/', "/file.php/$id/$fileurl"); } else { - $ffurl = "/file.php?file=/$id$fileurl"; + $ffurl = str_replace('//', '/', "/file.php?file=/$id/$fileurl"); } - link_to_popup_window ($ffurl, "display", - "pixpath/f/$icon\" height=\"16\" width=\"16\" border=\"0\" alt=\"File\" />", - 480, 640); - echo ' '; - link_to_popup_window ($ffurl, "display", - htmlspecialchars($file), + link_to_popup_window ($ffurl, "display", + "pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" /> ".htmlspecialchars($file), 480, 640); echo "
"; - echo "
"; + echo "
"; + //echo "
"; - if (empty($wdir)) { - $wdir = "/"; - } - - echo ""; + echo "
"; echo "
"; echo ""; - echo ''; + echo ''; echo " "; echo "sesskey\" />"; $options = array ( @@ -801,41 +857,59 @@ function displaydir ($wdir) { "zip" => "$strcreateziparchive" ); if (!empty($count)) { - choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:document.dirform.submit()"); + choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:getElementById('dirform').submit()"); } - + echo "
"; + echo ""; echo ""; + echo ""; echo ""; echo ""; + echo ""; echo ""; echo "
"; if (!empty($USER->fileop) and ($USER->fileop == "move") and ($USER->filesource <> $wdir)) { echo "
"; - echo ' '; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; echo " sesskey\" />"; echo " "; + echo "
"; echo "
"; } + echo "
"; echo "
"; - echo ' '; + echo "
"; + echo ' '; echo " "; echo " "; - echo " "; + echo " "; echo " "; + echo "
"; + echo "
"; + echo "
"; + echo "
"; //dummy form - alignment only + echo "
"; + echo " "; + echo " "; + echo "
"; echo "
"; echo "
"; echo "
"; - echo ' '; + echo "
"; + echo ' '; echo " "; echo " "; echo " "; echo " "; + echo "
"; echo "
"; echo "
"; - echo "
"; + echo "
"; + //echo "
"; } diff --git a/edit.php b/edit.php index ba74f755d2a..23049f6ede3 100644 --- a/edit.php +++ b/edit.php @@ -1,4 +1,4 @@ -course)) { error('Course is misconfigured'); } -if (!isteacheredit($course->id)) { - error('Only editing teachers can edit books!', $_SERVER['HTTP_REFERER']); -} +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +require_capability('moodle/course:manageactivities', $context); if (!$book = get_record('book', 'id', $cm->instance)) { error('Course module is incorrect'); diff --git a/generateimscp.php b/generateimscp.php index 1112dbcde0a..60f5799967c 100644 --- a/generateimscp.php +++ b/generateimscp.php @@ -1,4 +1,4 @@ -dirroot . '/backup/lib.php'); require_once($CFG->dirroot . '/lib/filelib.php'); -$id = required_param('id', PARAM_INT); // Course Module ID +$id = required_param('id', PARAM_INT); // Course Module ID -if ($CFG->forcelogin) { - require_login(); -} +require_login(); -if (!$cm = get_record('course_modules', 'id', $id)) { +if (!$cm = get_coursemodule_from_id('book', $id)) { error('Course Module ID was incorrect'); } @@ -43,22 +41,13 @@ if (!$course = get_record('course', 'id', $cm->course)) { error('Course is misconfigured'); } -if ($course->category) { - require_login($course->id); -} - -if (!$cm->visible and !isteacher($course->id)) { - notice(get_string('activityiscurrentlyhidden')); -} +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +require_capability('moodle/course:manageactivities', $context); if (!$book = get_record('book', 'id', $cm->instance)) { error('Course module is incorrect'); } -if (!isteacher($course->id)) { - error('Only teachers are allowed to generate IMS CP packages'); -} - $strbooks = get_string('modulenameplural', 'book'); $strbook = get_string('modulename', 'book'); $strtop = get_string('top', 'book'); @@ -220,6 +209,7 @@ function chapter2html($chapter, $courseid, $bookid) { $content .= '' . "\n"; $content .= '' . "\n"; $content .= '

' . $chapter->title . '

' ."\n"; + $options = new object(); $options->noclean = true; $content .= format_text($chapter->content, '', $options, $courseid) . "\n"; $content .= '' . "\n"; @@ -255,7 +245,7 @@ function chapter2html($chapter, $courseid, $bookid) { } /// Build the final object needed to have all the info in order to create the manifest - $object = new stdClass; + $object = new object(); $object->content = $content; $object->localfiles = $basefiles; diff --git a/import.php b/import.php index 3f345a59856..f53f09fa3ed 100644 --- a/import.php +++ b/import.php @@ -1,4 +1,4 @@ -course)) { error('Course is misconfigured'); } -if (!isteacheredit($course->id)) { - error('Only editing teachers can edit books!'); -} +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +require_capability('moodle/course:manageactivities', $context); if (!$book = get_record('book', 'id', $cm->instance)) { error('Course module is incorrect'); @@ -150,8 +149,8 @@ if (($form = data_submitted()) && (confirm_sesskey())) {  '; - button_to_popup_window ('/mod/book/coursefiles.php?choose=theform.reference&id='.$course->id, + echo ' '; + button_to_popup_window ('/mod/book/coursefiles.php?choose=id_reference&id='.$course->id, 'coursefiles', $strchoose, 500, 750, $strchoose); ?> diff --git a/index.php b/index.php index 7f315062077..445af84addb 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,4 @@ -forcelogin) { - require_login(); -} if (!$course = get_record('course', 'id', $id)) { error('Course ID is incorrect'); } -if ($course->category) { - require_login($course->id); -} +require_course_login($course, true); //check all variables unset($id); diff --git a/lang/en_utf8/book.php b/lang/en_utf8/book.php index 19113cd9a5e..f6171e170f7 100644 --- a/lang/en_utf8/book.php +++ b/lang/en_utf8/book.php @@ -1,4 +1,4 @@ -Chapters are sorted alphabetically using file names.
Files named \'sub_*.*\' are always imported as subchapters.'; diff --git a/lib.php b/lib.php index fc8f8a372cc..37d17d3251a 100644 --- a/lib.php +++ b/lib.php @@ -1,19 +1,21 @@ - get_string('numbering0', 'book'), - NUM_NUMBERS => get_string('numbering1', 'book'), - NUM_BULLETS => get_string('numbering2', 'book'), - NUM_INDENTED => get_string('numbering3', 'book') ); if (!isset($CFG->book_tocwidth)) { set_config("book_tocwidth", 180); // default toc width } +function book_get_numbering_types() { + return array (NUM_NONE => get_string('numbering0', 'book'), + NUM_NUMBERS => get_string('numbering1', 'book'), + NUM_BULLETS => get_string('numbering2', 'book'), + NUM_INDENTED => get_string('numbering3', 'book') ); +} /// Library of functions and constants for module 'book' @@ -25,6 +27,12 @@ function book_add_instance($book) { $book->timecreated = time(); $book->timemodified = $book->timecreated; + if (!isset($book->customtitles)) { + $book->customtitles = 0; + } + if (!isset($book->disableprinting)) { + $book->disableprinting = 0; + } return insert_record('book', $book); } @@ -37,6 +45,12 @@ function book_update_instance($book) { $book->timemodified = time(); $book->id = $book->instance; + if (!isset($book->customtitles)) { + $book->customtitles = 0; + } + if (!isset($book->disableprinting)) { + $book->disableprinting = 0; + } # May have to add extra stuff in here # @@ -64,6 +78,20 @@ function book_delete_instance($id) { return $result; } + +function book_get_types() { + global $CFG; + + $types = array(); + + $type = new object(); + $type->modclass = MOD_CLASS_RESOURCE; + $type->type = 'book'; + $type->typestr = get_string('modulename', 'book'); + $types[] = $type; + + return $types; +} function book_user_outline($course, $user, $mod, $book) { /// Return a small object with summary information about what a /// user has done with a given particular instance of this module @@ -178,11 +206,11 @@ function book_edit_button($id, $courseid, $chapterid) { $string = get_string("turneditingon"); $edit = '1'; } - return '
'. + return '
'. ''. ''. ''. - ''; + '
'; } else { return ''; } diff --git a/mod.html b/mod.html deleted file mode 100644 index d29c4bcb68c..00000000000 --- a/mod.html +++ /dev/null @@ -1,116 +0,0 @@ -dirroot.'/mod/book/lib.php'); - -if (empty($form->name)) { - $form->name = ''; -} -if (empty($form->summary)) { - $form->summary = ''; -} -if (empty($form->numbering)) { - $form->numbering = NUM_NONE; -} -if (empty($form->disableprinting)) { - $form->disableprinting = 0; -} -if (empty($form->customtitles)) { - $form->customtitles = 0; -} -?> - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -

:

- -

:

- - "; - helpbutton("questions", get_string("helpquestions"), "moodle", true, true); - echo "
"; - if ($usehtmleditor) { - helpbutton("richtext", get_string("helprichtext"), "moodle", true, true); - } else { - emoticonhelpbutton("form", "description"); - } - ?> -
-
-
- summary); ?> -

:

- numbering, ''); - helpbutton('numberingtype', get_string('numbering', 'book'), 'book'); - ?> -

:

- -

:

- -
-
- -
- - - - - - - - -
- diff --git a/mod_form.php b/mod_form.php new file mode 100644 index 00000000000..61e613f892a --- /dev/null +++ b/mod_form.php @@ -0,0 +1,44 @@ +dirroot.'/mod/book/lib.php'); +require_once('moodleform_mod.php'); + +class mod_book_mod_form extends moodleform_mod { + + function definition() { + + global $CFG; + $mform =& $this->_form; + +//------------------------------------------------------------------------------- + $mform->addElement('header', 'general', get_string('general', 'form')); + + $mform->addElement('text', 'name', get_string('name'), array('size'=>'64')); + $mform->setType('name', PARAM_TEXT); + $mform->addRule('name', null, 'required', null, 'client'); + + $mform->addElement('htmleditor', 'summary', get_string('summary')); + $mform->setType('summary', PARAM_RAW); + $mform->addRule('summary', null, 'required', null, 'client'); + $mform->setHelpButton('summary', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton'); + + $mform->addElement('select', 'numbering', get_string('numbering', 'book'), book_get_numbering_types()); + $mform->setHelpButton('numbering', array('numberingtype', get_string('numbering', 'book'), 'book')); + + $mform->addElement('checkbox', 'disableprinting', get_string('disableprinting', 'book')); + $mform->setHelpButton('disableprinting', array('disableprinting', get_string('disableprinting', 'book'), 'book')); + $mform->setDefault('disableprinting', 0); + + $mform->addElement('checkbox', 'customtitles', get_string('customtitles', 'book')); + $mform->setHelpButton('customtitles', array('customtitles', get_string('customtitles', 'book'), 'book')); + $mform->setDefault('customtitles', 0); + + $this->standard_coursemodule_elements(); + +//------------------------------------------------------------------------------- + // buttons + $this->add_action_buttons(); + } + + +} +?> \ No newline at end of file diff --git a/print.php b/print.php index 269c9a2c85a..8582d7614c9 100644 --- a/print.php +++ b/print.php @@ -1,4 +1,4 @@ -forcelogin) { - require_login(); -} - -if (!$cm = get_record('course_modules', 'id', $id)) { +if (!$cm = get_coursemodule_from_id('book', $id)) { error('Course Module ID was incorrect'); } @@ -21,13 +17,7 @@ if (!$course = get_record('course', 'id', $cm->course)) { error('Course is misconfigured'); } -if ($course->category) { - require_login($course->id); -} - -if (!$cm->visible and !isteacher($course->id)) { - notice(get_string('activityiscurrentlyhidden')); -} +require_course_login($course, true, $cm); if (!$book = get_record('book', 'id', $cm->instance)) { error('Course module is incorrect'); @@ -61,23 +51,15 @@ unset($chapterid); $strbooks = get_string('modulenameplural', 'book'); $strbook = get_string('modulename', 'book'); -$strtop = get_string('top', 'book'); - -if (!empty($CFG->unicode)) { - $encoding = 'utf-8'; -} else { - $encoding = get_string('thischarset'); -} - -moodle_setlocale(); //workaround for buggy forced course language +$strtop = get_string('top', 'book'); @header('Cache-Control: private, pre-check=0, post-check=0, max-age=0'); @header('Pragma: no-cache'); @header('Expires: '); @header('Accept-Ranges: none'); -@header('Content-type: text/html; charset='.$encoding); +@header('Content-type: text/html; charset=utf-8'); -$formatoptions = new stdClass; +$formatoptions = new object(); $formatoptions->noclean = true; if ($chapter) { @@ -94,9 +76,9 @@ if ($chapter) { - <?PHP echo str_replace('"', '"', $book->name) ?> - - name) ?>" /> + <?PHP echo format_string($book->name) ?> + + @@ -125,28 +107,28 @@ if ($chapter) { - <?PHP echo str_replace('"', '"', $book->name) ?> + <?PHP echo format_string(name) ?> - name) ?>" /> + -

name) ?>

-

summary) ?>

+

name) ?>

+

summary) ?>

- + - + - + - + diff --git a/teacheraccess.php b/teacheraccess.php index 5f2f6e23806..45ecbc7414b 100644 --- a/teacheraccess.php +++ b/teacheraccess.php @@ -1,4 +1,4 @@ -course)) { error('Course is misconfigured'); } -if (!isteacheredit($course->id)) { - error('Only editing teachers can edit books!'); -} +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +require_capability('moodle/course:manageactivities', $context); if (!$book = get_record('book', 'id', $cm->instance)) { error('Course module is incorrect'); diff --git a/toc.php b/toc.php index 94782fb5204..090f7f593d6 100644 --- a/toc.php +++ b/toc.php @@ -1,4 +1,4 @@ -id.'&chapterid='.$ch->id.'">'.$title.''; + $toc .= ''.$title.''; } $toc .= '  '; if ($i != 1) { - $toc .= ' '; + $toc .= ' '.get_string('up').''; } if ($i != count($chapters)) { - $toc .= ' '; + $toc .= ' '.get_string('down').''; } - $toc .= ' '; - $toc .= ' '; + $toc .= ' '.get_string('edit').''; + $toc .= ' '.get_string('delete').''; if ($ch->hidden) { - $toc .= ' '; + $toc .= ' '.get_string('show').''; } else { - $toc .= ' '; + $toc .= ' '.get_string('hide').''; } - $toc .= ' '; + $toc .= ' '.get_string('addafter', 'book').''; $toc .= (!$ch->subchapter) ? '
:fullname) ?>fullname) ?>
:fullname) ?>fullname) ?>
:name) ?>name) ?>
:
:
'. +$buttons = $allowedit ? '
'.update_module_button($cm->id, $course->id, $strbook).'
'. '
'.update_module_button($cm->id, $course->id, $strbook).' '.book_edit_button($cm->id, $course->id, $chapter->id).'
' : ' '; @@ -148,19 +140,18 @@ if ($ch == current($chapters)) { } $chnavigation = ''; if ($previd) { - $chnavigation .= ''; + $chnavigation .= ''.get_string('navprev', 'book').''; } else { - $chnavigation .= ''; + $chnavigation .= ''; } -$chnavigation .= '    '; if ($nextid) { - $chnavigation .= ''; + $chnavigation .= ''.get_string('navnext', 'book').''; } else { $sec = ''; if ($section = get_record('course_sections', 'id', $cm->section)) { $sec = $section->section; } - $chnavigation .= ''; + $chnavigation .= ''.get_string('navexit', 'book').''; } /// prepare print icons @@ -168,8 +159,8 @@ if ($book->disableprinting) { $printbook = ''; $printchapter = ''; } else { - $printbook = ''; - $printchapter = ''; + $printbook = ''.get_string('printbook', 'book').''; + $printchapter = ''.get_string('printchapter', 'book').''; } // prepare $toc and $currtitle, $currsubtitle @@ -181,7 +172,8 @@ if ($edit) { $tocwidth = $CFG->book_tocwidth; } -$doimport = ($isteacher and $edit) ? ' ('.get_string('doimport', 'book').')' : ''; +$doimport = ($allowedit and $edit) ? ''.get_string('doimport', 'book').'' : ''; +$doexport = ($allowedit and $edit) ? ''.get_string('doexport', 'book').'' : ''; // ===================================================== @@ -194,12 +186,17 @@ $doimport = ($isteacher and $edit) ? ' (" valign="bottom"> - + ($doimport, $doexport)"; + } + ?> - +
@@ -210,10 +207,10 @@ $doimport = ($isteacher and $edit) ? ' (
" valign="top" align="left">
'; helpbutton('faq', get_string('faq','book'), 'book', true, true); echo '
'; @@ -222,7 +219,7 @@ $doimport = ($isteacher and $edit) ? ' ( customtitles) { if ($currsubtitle == ' ') { @@ -238,9 +235,9 @@ $doimport = ($isteacher and $edit) ? ' ('; echo format_text($content, FORMAT_HTML, $nocleanoption, $course->id); echo '
'; - print_simple_box_end(); + print_box_end(); /// lower navigation - echo '

'.$chnavigation.'

'; + echo '

'.$chnavigation.'

'; ?>