| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: index.php,v 1.121.2.7 2008/07/11 02:28:31 scyrma Exp $ 2 3 // Manage all uploaded files in a course file area 4 5 // All the Moodle-specific stuff is in this top section 6 // Configuration and access control occurs here. 7 // Must define: USER, basedir, baseweb, html_header and html_footer 8 // USER is a persistent variable using sessions 9 10 require ('../config.php'); 11 require($CFG->libdir.'/filelib.php'); 12 require($CFG->libdir.'/adminlib.php'); 13 14 $id = required_param('id', PARAM_INT); 15 $file = optional_param('file', '', PARAM_PATH); 16 $wdir = optional_param('wdir', '', PARAM_PATH); 17 $action = optional_param('action', '', PARAM_ACTION); 18 $name = optional_param('name', '', PARAM_FILE); 19 $oldname = optional_param('oldname', '', PARAM_FILE); 20 $choose = optional_param('choose', '', PARAM_FILE); //in fact it is always 'formname.inputname' 21 $userfile= optional_param('userfile','',PARAM_FILE); 22 $save = optional_param('save', 0, PARAM_BOOL); 23 $text = optional_param('text', '', PARAM_RAW); 24 $confirm = optional_param('confirm', 0, PARAM_BOOL); 25 26 if ($choose) { 27 if (count(explode('.', $choose)) > 2) { 28 error('Incorrect format for choose parameter'); 29 } 30 } 31 32 33 if (! $course = get_record("course", "id", $id) ) { 34 error("That's an invalid course id"); 35 } 36 37 require_login($course); 38 39 require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id)); 40 41 function html_footer() { 42 global $COURSE, $choose; 43 44 echo '</td></tr></table>'; 45 46 print_footer($COURSE); 47 } 48 49 function html_header($course, $wdir, $formfield=""){ 50 global $CFG, $ME, $choose; 51 52 $navlinks = array(); 53 // $navlinks[] = array('name' => $course->shortname, 'link' => "../course/view.php?id=$course->id", 'type' => 'misc'); 54 55 if ($course->id == SITEID) { 56 $strfiles = get_string("sitefiles"); 57 } else { 58 $strfiles = get_string("files"); 59 } 60 61 if ($wdir == "/") { 62 $navlinks[] = array('name' => $strfiles, 'link' => null, 'type' => 'misc'); 63 } else { 64 $dirs = explode("/", $wdir); 65 $numdirs = count($dirs); 66 $link = ""; 67 $navlinks[] = array('name' => $strfiles, 68 'link' => $ME."?id=$course->id&wdir=/&choose=$choose", 69 'type' => 'misc'); 70 71 for ($i=1; $i<$numdirs-1; $i++) { 72 $link .= "/".urlencode($dirs[$i]); 73 $navlinks[] = array('name' => $dirs[$i], 74 'link' => $ME."?id=$course->id&wdir=$link&choose=$choose", 75 'type' => 'misc'); 76 } 77 $navlinks[] = array('name' => $dirs[$numdirs-1], 'link' => null, 'type' => 'misc'); 78 } 79 80 $navigation = build_navigation($navlinks); 81 82 if ($choose) { 83 print_header(); 84 85 $chooseparts = explode('.', $choose); 86 if (count($chooseparts)==2){ 87 ?> 88 <script type="text/javascript"> 89 //<![CDATA[ 90 function set_value(txt) { 91 opener.document.forms['<?php echo $chooseparts[0]."'].".$chooseparts[1] ?>.value = txt; 92 window.close(); 93 } 94 //]]> 95 </script> 96 97 <?php 98 } elseif (count($chooseparts)==1){ 99 ?> 100 <script type="text/javascript"> 101 //<![CDATA[ 102 function set_value(txt) { 103 opener.document.getElementById('<?php echo $chooseparts[0] ?>').value = txt; 104 window.close(); 105 } 106 //]]> 107 </script> 108 109 <?php 110 111 } 112 $fullnav = ''; 113 $i = 0; 114 foreach ($navlinks as $navlink) { 115 // If this is the last link do not link 116 if ($i == count($navlinks) - 1) { 117 $fullnav .= $navlink['name']; 118 } else { 119 $fullnav .= '<a href="'.$navlink['link'].'">'.$navlink['name'].'</a>'; 120 } 121 $fullnav .= ' -> '; 122 $i++; 123 } 124 $fullnav = substr($fullnav, 0, -4); 125 $fullnav = str_replace('->', '»', format_string($course->shortname) . " -> " . $fullnav); 126 echo '<div id="nav-bar">'.$fullnav.'</div>'; 127 128 if ($course->id == SITEID and $wdir != "/backupdata") { 129 print_heading(get_string("publicsitefileswarning"), "center", 2); 130 } 131 132 } else { 133 134 if ($course->id == SITEID) { 135 136 if ($wdir == "/backupdata") { 137 admin_externalpage_setup('frontpagerestore'); 138 admin_externalpage_print_header(); 139 } else { 140 admin_externalpage_setup('sitefiles'); 141 admin_externalpage_print_header(); 142 143 print_heading(get_string("publicsitefileswarning"), "center", 2); 144 145 } 146 147 } else { 148 print_header("$course->shortname: $strfiles", $course->fullname, $navigation, $formfield); 149 } 150 } 151 152 153 echo "<table border=\"0\" style=\"margin-left:auto;margin-right:auto\" cellspacing=\"3\" cellpadding=\"3\" width=\"640\">"; 154 echo "<tr>"; 155 echo "<td colspan=\"2\">"; 156 157 } 158 159 160 if (! $basedir = make_upload_directory("$course->id")) { 161 error("The site administrator needs to fix the file permissions"); 162 } 163 164 $baseweb = $CFG->wwwroot; 165 166 // End of configuration and access control 167 168 169 if ($wdir == '') { 170 $wdir = "/"; 171 } 172 173 if ($wdir{0} != '/') { //make sure $wdir starts with slash 174 $wdir = "/".$wdir; 175 } 176 177 if ($wdir == "/backupdata") { 178 if (! make_upload_directory("$course->id/backupdata")) { // Backup folder 179 error("Could not create backupdata folder. The site administrator needs to fix the file permissions"); 180 } 181 } 182 183 if (!is_dir($basedir.$wdir)) { 184 html_header($course, $wdir); 185 error("Requested directory does not exist.", "$CFG->wwwroot/files/index.php?id=$id"); 186 } 187 188 switch ($action) { 189 190 case "upload": 191 html_header($course, $wdir); 192 require_once($CFG->dirroot.'/lib/uploadlib.php'); 193 194 if ($save and confirm_sesskey()) { 195 $course->maxbytes = 0; // We are ignoring course limits 196 $um = new upload_manager('userfile',false,false,$course,false,0); 197 $dir = "$basedir$wdir"; 198 if ($um->process_file_uploads($dir)) { 199 notify(get_string('uploadedfile')); 200 } 201 // um will take care of error reporting. 202 displaydir($wdir); 203 } else { 204 $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes); 205 $filesize = display_size($upload_max_filesize); 206 207 $struploadafile = get_string("uploadafile"); 208 $struploadthisfile = get_string("uploadthisfile"); 209 $strmaxsize = get_string("maxsize", "", $filesize); 210 $strcancel = get_string("cancel"); 211 212 echo "<p>$struploadafile ($strmaxsize) --> <b>$wdir</b></p>"; 213 echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"index.php\">"; 214 echo "<div>"; 215 echo "<table><tr><td colspan=\"2\">"; 216 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 217 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 218 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 219 echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />"; 220 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; 221 upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false); 222 echo " </td></tr></table>"; 223 echo " <input type=\"submit\" name=\"save\" value=\"$struploadthisfile\" />"; 224 echo "</div>"; 225 echo "</form>"; 226 echo "<form action=\"index.php\" method=\"get\">"; 227 echo "<div>"; 228 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 229 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 230 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 231 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; 232 echo " <input type=\"submit\" value=\"$strcancel\" />"; 233 echo "</div>"; 234 echo "</form>"; 235 } 236 html_footer(); 237 break; 238 239 case "delete": 240 if ($confirm and confirm_sesskey()) { 241 html_header($course, $wdir); 242 if (!empty($USER->filelist)) { 243 foreach ($USER->filelist as $file) { 244 $fullfile = $basedir.'/'.$file; 245 if (! fulldelete($fullfile)) { 246 echo "<br />Error: Could not delete: $fullfile"; 247 } 248 } 249 } 250 clearfilelist(); 251 displaydir($wdir); 252 html_footer(); 253 254 } else { 255 html_header($course, $wdir); 256 257 if (setfilelist($_POST)) { 258 notify(get_string('deletecheckwarning').':'); 259 print_simple_box_start("center"); 260 printfilelist($USER->filelist); 261 print_simple_box_end(); 262 echo "<br />"; 263 264 require_once($CFG->dirroot.'/mod/resource/lib.php'); 265 $block = resource_delete_warning($course, $USER->filelist); 266 267 if (empty($CFG->resource_blockdeletingfile) or $block == '') { 268 $optionsyes = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'choose'=>$choose); 269 $optionsno = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose); 270 notice_yesno (get_string('deletecheckfiles'), 'index.php', 'index.php', $optionsyes, $optionsno, 'post', 'get'); 271 } else { 272 273 notify(get_string('warningblockingdelete', 'resource')); 274 $options = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose); 275 print_continue("index.php?id=$id&wdir=$wdir&action=cancel&choose=$choose"); 276 } 277 } else { 278 displaydir($wdir); 279 } 280 html_footer(); 281 } 282 break; 283 284 case "move": 285 html_header($course, $wdir); 286 if (($count = setfilelist($_POST)) and confirm_sesskey()) { 287 $USER->fileop = $action; 288 $USER->filesource = $wdir; 289 echo "<p class=\"centerpara\">"; 290 print_string("selectednowmove", "moodle", $count); 291 echo "</p>"; 292 } 293 displaydir($wdir); 294 html_footer(); 295 break; 296 297 case "paste": 298 html_header($course, $wdir); 299 if (isset($USER->fileop) and ($USER->fileop == "move") and confirm_sesskey()) { 300 foreach ($USER->filelist as $file) { 301 $shortfile = basename($file); 302 $oldfile = $basedir.'/'.$file; 303 $newfile = $basedir.$wdir."/".$shortfile; 304 if (!rename($oldfile, $newfile)) { 305 echo "<p>Error: $shortfile not moved</p>"; 306 } 307 } 308 } 309 clearfilelist(); 310 displaydir($wdir); 311 html_footer(); 312 break; 313 314 case "rename": 315 if (($name != '') and confirm_sesskey()) { 316 html_header($course, $wdir); 317 $name = clean_filename($name); 318 if (file_exists($basedir.$wdir."/".$name)) { 319 echo "<center>Error: $name already exists!</center>"; 320 } else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) { 321 echo "<p align=\"center\">Error: could not rename $oldname to $name</p>"; 322 } else { 323 //file was renamed now update resources if needed 324 require_once($CFG->dirroot.'/mod/resource/lib.php'); 325 resource_renamefiles($course, $wdir, $oldname, $name); 326 } 327 displaydir($wdir); 328 329 } else { 330 $strrename = get_string("rename"); 331 $strcancel = get_string("cancel"); 332 $strrenamefileto = get_string("renamefileto", "moodle", $file); 333 html_header($course, $wdir, "form.name"); 334 echo "<p>$strrenamefileto:</p>"; 335 echo "<table><tr><td>"; 336 echo "<form action=\"index.php\" method=\"post\">"; 337 echo "<fieldset class=\"invisiblefieldset\">"; 338 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 339 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 340 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 341 echo " <input type=\"hidden\" name=\"action\" value=\"rename\" />"; 342 echo " <input type=\"hidden\" name=\"oldname\" value=\"$file\" />"; 343 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; 344 echo " <input type=\"text\" name=\"name\" size=\"35\" value=\"$file\" />"; 345 echo " <input type=\"submit\" value=\"$strrename\" />"; 346 echo "</fieldset>"; 347 echo "</form>"; 348 echo "</td><td>"; 349 echo "<form action=\"index.php\" method=\"get\">"; 350 echo "<div>"; 351 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 352 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 353 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 354 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; 355 echo " <input type=\"submit\" value=\"$strcancel\" />"; 356 echo "</div>"; 357 echo "</form>"; 358 echo "</td></tr></table>"; 359 } 360 html_footer(); 361 break; 362 363 case "makedir": 364 if (($name != '') and confirm_sesskey()) { 365 html_header($course, $wdir); 366 $name = clean_filename($name); 367 if (file_exists("$basedir$wdir/$name")) { 368 echo "Error: $name already exists!"; 369 } else if (! make_upload_directory("$course->id$wdir/$name")) { 370 echo "Error: could not create $name"; 371 } 372 displaydir($wdir); 373 374 } else { 375 $strcreate = get_string("create"); 376 $strcancel = get_string("cancel"); 377 $strcreatefolder = get_string("createfolder", "moodle", $wdir); 378 html_header($course, $wdir, "form.name"); 379 echo "<p>$strcreatefolder:</p>"; 380 echo "<table><tr><td>"; 381 echo "<form action=\"index.php\" method=\"post\">"; 382 echo "<fieldset class=\"invisiblefieldset\">"; 383 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 384 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 385 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 386 echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />"; 387 echo " <input type=\"text\" name=\"name\" size=\"35\" />"; 388 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; 389 echo " <input type=\"submit\" value=\"$strcreate\" />"; 390 echo "</fieldset>"; 391 echo "</form>"; 392 echo "</td><td>"; 393 echo "<form action=\"index.php\" method=\"get\">"; 394 echo "<div>"; 395 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 396 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 397 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 398 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; 399 echo " <input type=\"submit\" value=\"$strcancel\" />"; 400 echo "</div>"; 401 echo "</form>"; 402 echo "</td></tr></table>"; 403 } 404 html_footer(); 405 break; 406 407 case "edit": 408 html_header($course, $wdir); 409 if (($text != '') and confirm_sesskey()) { 410 $fileptr = fopen($basedir.'/'.$file,"w"); 411 $text = preg_replace('/\x0D/', '', $text); // http://moodle.org/mod/forum/discuss.php?d=38860 412 fputs($fileptr, stripslashes($text)); 413 fclose($fileptr); 414 displaydir($wdir); 415 416 } else { 417 $streditfile = get_string("edit", "", "<b>$file</b>"); 418 $fileptr = fopen($basedir.'/'.$file, "r"); 419 $contents = fread($fileptr, filesize($basedir.'/'.$file)); 420 fclose($fileptr); 421 422 if (mimeinfo("type", $file) == "text/html") { 423 $usehtmleditor = can_use_html_editor(); 424 } else { 425 $usehtmleditor = false; 426 } 427 $usehtmleditor = false; // Always keep it off for now 428 429 print_heading("$streditfile"); 430 431 echo "<table><tr><td colspan=\"2\">"; 432 echo "<form action=\"index.php\" method=\"post\">"; 433 echo "<div>"; 434 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 435 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 436 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 437 echo " <input type=\"hidden\" name=\"file\" value=\"$file\" />"; 438 echo " <input type=\"hidden\" name=\"action\" value=\"edit\" />"; 439 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; 440 print_textarea($usehtmleditor, 25, 80, 680, 400, "text", $contents); 441 echo "</td></tr><tr><td>"; 442 echo " <input type=\"submit\" value=\"".get_string("savechanges")."\" />"; 443 echo "</div>"; 444 echo "</form>"; 445 echo "</td><td>"; 446 echo "<form action=\"index.php\" method=\"get\">"; 447 echo "<div>"; 448 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 449 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 450 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 451 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; 452 echo " <input type=\"submit\" value=\"".get_string("cancel")."\" />"; 453 echo "</div>"; 454 echo "</form>"; 455 echo "</td></tr></table>"; 456 457 if ($usehtmleditor) { 458 use_html_editor(); 459 } 460 461 462 } 463 html_footer(); 464 break; 465 466 case "zip": 467 if (($name != '') and confirm_sesskey()) { 468 html_header($course, $wdir); 469 $name = clean_filename($name); 470 471 $files = array(); 472 foreach ($USER->filelist as $file) { 473 $files[] = "$basedir/$file"; 474 } 475 476 if (!zip_files($files,"$basedir$wdir/$name")) { 477 print_error("zipfileserror","error"); 478 } 479 480 clearfilelist(); 481 displaydir($wdir); 482 483 } else { 484 html_header($course, $wdir, "form.name"); 485 486 if (setfilelist($_POST)) { 487 echo "<p align=\"center\">".get_string("youareabouttocreatezip").":</p>"; 488 print_simple_box_start("center"); 489 printfilelist($USER->filelist); 490 print_simple_box_end(); 491 echo "<br />"; 492 echo "<p align=\"center\">".get_string("whattocallzip")."</p>"; 493 echo "<table><tr><td>"; 494 echo "<form action=\"index.php\" method=\"post\">"; 495 echo "<fieldset class=\"invisiblefieldset\">"; 496 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 497 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 498 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 499 echo " <input type=\"hidden\" name=\"action\" value=\"zip\" />"; 500 echo " <input type=\"text\" name=\"name\" size=\"35\" value=\"new.zip\" />"; 501 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; 502 echo " <input type=\"submit\" value=\"".get_string("createziparchive")."\" />"; 503 echo "<fieldset>"; 504 echo "</form>"; 505 echo "</td><td>"; 506 echo "<form action=\"index.php\" method=\"get\">"; 507 echo "<div>"; 508 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 509 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 510 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 511 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; 512 echo " <input type=\"submit\" value=\"".get_string("cancel")."\" />"; 513 echo "</div>"; 514 echo "</form>"; 515 echo "</td></tr></table>"; 516 } else { 517 displaydir($wdir); 518 clearfilelist(); 519 } 520 } 521 html_footer(); 522 break; 523 524 case "unzip": 525 html_header($course, $wdir); 526 if (($file != '') and confirm_sesskey()) { 527 $strok = get_string("ok"); 528 $strunpacking = get_string("unpacking", "", $file); 529 530 echo "<p align=\"center\">$strunpacking:</p>"; 531 532 $file = basename($file); 533 534 if (!unzip_file("$basedir$wdir/$file")) { 535 print_error("unzipfileserror","error"); 536 } 537 538 echo "<div style=\"text-align:center\"><form action=\"index.php\" method=\"get\">"; 539 echo "<div>"; 540 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 541 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 542 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 543 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; 544 echo " <input type=\"submit\" value=\"$strok\" />"; 545 echo "</div>"; 546 echo "</form>"; 547 echo "</div>"; 548 } else { 549 displaydir($wdir); 550 } 551 html_footer(); 552 break; 553 554 case "listzip": 555 html_header($course, $wdir); 556 if (($file != '') and confirm_sesskey()) { 557 $strname = get_string("name"); 558 $strsize = get_string("size"); 559 $strmodified = get_string("modified"); 560 $strok = get_string("ok"); 561 $strlistfiles = get_string("listfiles", "", $file); 562 563 echo "<p align=\"center\">$strlistfiles:</p>"; 564 $file = basename($file); 565 566 include_once("$CFG->libdir/pclzip/pclzip.lib.php"); 567 $archive = new PclZip(cleardoubleslashes("$basedir$wdir/$file")); 568 if (!$list = $archive->listContent(cleardoubleslashes("$basedir$wdir"))) { 569 notify($archive->errorInfo(true)); 570 571 } else { 572 echo "<table cellpadding=\"4\" cellspacing=\"2\" border=\"0\" width=\"640\" class=\"files\">"; 573 echo "<tr class=\"file\"><th align=\"left\" class=\"header name\" scope=\"col\">$strname</th><th align=\"right\" class=\"header size\" scope=\"col\">$strsize</th><th align=\"right\" class=\"header date\" scope=\"col\">$strmodified</th></tr>"; 574 foreach ($list as $item) { 575 echo "<tr>"; 576 print_cell("left", s($item['filename']), 'name'); 577 if (! $item['folder']) { 578 print_cell("right", display_size($item['size']), 'size'); 579 } else { 580 echo "<td> </td>"; 581 } 582 $filedate = userdate($item['mtime'], get_string("strftimedatetime")); 583 print_cell("right", $filedate, 'date'); 584 echo "</tr>"; 585 } 586 echo "</table>"; 587 } 588 echo "<br /><center><form action=\"index.php\" method=\"get\">"; 589 echo "<div>"; 590 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 591 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 592 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 593 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; 594 echo " <input type=\"submit\" value=\"$strok\" />"; 595 echo "</div>"; 596 echo "</form>"; 597 echo "</center>"; 598 } else { 599 displaydir($wdir); 600 } 601 html_footer(); 602 break; 603 604 case "restore": 605 html_header($course, $wdir); 606 if (($file != '') and confirm_sesskey()) { 607 echo "<p align=\"center\">".get_string("youaregoingtorestorefrom").":</p>"; 608 print_simple_box_start("center"); 609 echo $file; 610 print_simple_box_end(); 611 echo "<br />"; 612 echo "<p align=\"center\">".get_string("areyousuretorestorethisinfo")."</p>"; 613 $restore_path = "$CFG->wwwroot/backup/restore.php"; 614 notice_yesno (get_string("areyousuretorestorethis"), 615 $restore_path."?id=".$id."&file=".cleardoubleslashes($id.$wdir."/".$file)."&method=manual", 616 "index.php?id=$id&wdir=$wdir&action=cancel"); 617 } else { 618 displaydir($wdir); 619 } 620 html_footer(); 621 break; 622 623 case "cancel": 624 clearfilelist(); 625 626 default: 627 html_header($course, $wdir); 628 displaydir($wdir); 629 html_footer(); 630 break; 631 } 632 633 634 /// FILE FUNCTIONS /////////////////////////////////////////////////////////// 635 636 637 function setfilelist($VARS) { 638 global $USER; 639 640 $USER->filelist = array (); 641 $USER->fileop = ""; 642 643 $count = 0; 644 foreach ($VARS as $key => $val) { 645 if (substr($key,0,4) == "file") { 646 $count++; 647 $val = rawurldecode($val); 648 $USER->filelist[] = clean_param($val, PARAM_PATH); 649 } 650 } 651 return $count; 652 } 653 654 function clearfilelist() { 655 global $USER; 656 657 $USER->filelist = array (); 658 $USER->fileop = ""; 659 } 660 661 662 function printfilelist($filelist) { 663 global $CFG, $basedir; 664 665 $strfolder = get_string("folder"); 666 $strfile = get_string("file"); 667 668 foreach ($filelist as $file) { 669 if (is_dir($basedir.'/'.$file)) { 670 echo '<img src="'. $CFG->pixpath .'/f/folder.gif" class="icon" alt="'. $strfolder .'" /> '. htmlspecialchars($file) .'<br />'; 671 $subfilelist = array(); 672 $currdir = opendir($basedir.'/'.$file); 673 while (false !== ($subfile = readdir($currdir))) { 674 if ($subfile <> ".." && $subfile <> ".") { 675 $subfilelist[] = $file."/".$subfile; 676 } 677 } 678 printfilelist($subfilelist); 679 680 } else { 681 $icon = mimeinfo("icon", $file); 682 echo '<img src="'. $CFG->pixpath .'/f/'. $icon .'" class="icon" alt="'. $strfile .'" /> '. htmlspecialchars($file) .'<br />'; 683 } 684 } 685 } 686 687 688 function print_cell($alignment='center', $text=' ', $class='') { 689 if ($class) { 690 $class = ' class="'.$class.'"'; 691 } 692 echo '<td align="'.$alignment.'" style="white-space:nowrap "'.$class.'>'.$text.'</td>'; 693 } 694 695 function displaydir ($wdir) { 696 // $wdir == / or /a or /a/b/c/d etc 697 698 global $basedir; 699 global $id; 700 global $USER, $CFG; 701 global $choose; 702 703 $fullpath = $basedir.$wdir; 704 $dirlist = array(); 705 706 $directory = opendir($fullpath); // Find all files 707 while (false !== ($file = readdir($directory))) { 708 if ($file == "." || $file == "..") { 709 continue; 710 } 711 712 if (is_dir($fullpath."/".$file)) { 713 $dirlist[] = $file; 714 } else { 715 $filelist[] = $file; 716 } 717 } 718 closedir($directory); 719 720 $strname = get_string("name"); 721 $strsize = get_string("size"); 722 $strmodified = get_string("modified"); 723 $straction = get_string("action"); 724 $strmakeafolder = get_string("makeafolder"); 725 $struploadafile = get_string("uploadafile"); 726 $strselectall = get_string("selectall"); 727 $strselectnone = get_string("deselectall"); 728 $strwithchosenfiles = get_string("withchosenfiles"); 729 $strmovetoanotherfolder = get_string("movetoanotherfolder"); 730 $strmovefilestohere = get_string("movefilestohere"); 731 $strdeletecompletely = get_string("deletecompletely"); 732 $strcreateziparchive = get_string("createziparchive"); 733 $strrename = get_string("rename"); 734 $stredit = get_string("edit"); 735 $strunzip = get_string("unzip"); 736 $strlist = get_string("list"); 737 $strrestore= get_string("restore"); 738 $strchoose = get_string("choose"); 739 $strfolder = get_string("folder"); 740 $strfile = get_string("file"); 741 742 743 echo "<form action=\"index.php\" method=\"post\" id=\"dirform\">"; 744 echo "<div>"; 745 echo '<input type="hidden" name="choose" value="'.$choose.'" />'; 746 // echo "<hr align=\"center\" noshade=\"noshade\" size=\"1\" />"; 747 echo "<hr/>"; 748 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\" class=\"files\">"; 749 echo "<tr>"; 750 echo "<th class=\"header\" scope=\"col\"></th>"; 751 echo "<th class=\"header name\" scope=\"col\">$strname</th>"; 752 echo "<th class=\"header size\" scope=\"col\">$strsize</th>"; 753 echo "<th class=\"header date\" scope=\"col\">$strmodified</th>"; 754 echo "<th class=\"header commands\" scope=\"col\">$straction</th>"; 755 echo "</tr>\n"; 756 757 if ($wdir != "/") { 758 $dirlist[] = '..'; 759 } 760 761 $count = 0; 762 763 if (!empty($dirlist)) { 764 asort($dirlist); 765 foreach ($dirlist as $dir) { 766 echo "<tr class=\"folder\">"; 767 768 if ($dir == '..') { 769 $fileurl = rawurlencode(dirname($wdir)); 770 print_cell(); 771 // alt attribute intentionally empty to prevent repetition in screen reader 772 print_cell('left', '<a href="index.php?id='.$id.'&wdir='.$fileurl.'&choose='.$choose.'"><img src="'.$CFG->pixpath.'/f/parent.gif" class="icon" alt="" /> '.get_string('parentfolder').'</a>', 'name'); 773 print_cell(); 774 print_cell(); 775 print_cell(); 776 777 } else { 778 $count++; 779 $filename = $fullpath."/".$dir; 780 $fileurl = rawurlencode($wdir."/".$dir); 781 $filesafe = rawurlencode($dir); 782 $filesize = display_size(get_directory_size("$fullpath/$dir")); 783 $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); 784 print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" />", 'checkbox'); 785 print_cell("left", "<a href=\"index.php?id=$id&wdir=$fileurl&choose=$choose\"><img src=\"$CFG->pixpath/f/folder.gif\" class=\"icon\" alt=\"$strfolder\" /> ".htmlspecialchars($dir)."</a>", 'name'); 786 print_cell("right", $filesize, 'size'); 787 print_cell("right", $filedate, 'date'); 788 print_cell("right", "<a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>", 'commands'); 789 } 790 791 echo "</tr>"; 792 } 793 } 794 795 796 if (!empty($filelist)) { 797 asort($filelist); 798 foreach ($filelist as $file) { 799 800 $icon = mimeinfo("icon", $file); 801 802 $count++; 803 $filename = $fullpath."/".$file; 804 $fileurl = trim($wdir, "/")."/$file"; 805 $filesafe = rawurlencode($file); 806 $fileurlsafe = rawurlencode($fileurl); 807 $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); 808 809 $selectfile = trim($fileurl, "/"); 810 811 echo "<tr class=\"file\">"; 812 813 print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" />", 'checkbox'); 814 echo "<td align=\"left\" style=\"white-space:nowrap\" class=\"name\">"; 815 816 $ffurl = get_file_url($id.'/'.$fileurl); 817 link_to_popup_window ($ffurl, "display", 818 "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" /> ".htmlspecialchars($file), 819 480, 640); 820 echo "</td>"; 821 822 $file_size = filesize($filename); 823 print_cell("right", display_size($file_size), 'size'); 824 print_cell("right", $filedate, 'date'); 825 826 if ($choose) { 827 $edittext = "<strong><a onclick=\"return set_value('$selectfile')\" href=\"#\">$strchoose</a></strong> "; 828 } else { 829 $edittext = ''; 830 } 831 832 833 if ($icon == "text.gif" || $icon == "html.gif") { 834 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=edit&choose=$choose\">$stredit</a>"; 835 } else if ($icon == "zip.gif") { 836 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip&sesskey=$USER->sesskey&choose=$choose\">$strunzip</a> "; 837 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=listzip&sesskey=$USER->sesskey&choose=$choose\">$strlist</a> "; 838 if (!empty($CFG->backup_version) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) { 839 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=restore&sesskey=$USER->sesskey&choose=$choose\">$strrestore</a> "; 840 } 841 } 842 843 print_cell("right", "$edittext <a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>", 'commands'); 844 845 echo "</tr>"; 846 } 847 } 848 echo "</table>"; 849 echo "<hr />"; 850 //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; 851 852 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">"; 853 echo "<tr><td>"; 854 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />"; 855 echo '<input type="hidden" name="choose" value="'.$choose.'" />'; 856 echo "<input type=\"hidden\" name=\"wdir\" value=\"$wdir\" /> "; 857 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; 858 $options = array ( 859 "move" => "$strmovetoanotherfolder", 860 "delete" => "$strdeletecompletely", 861 "zip" => "$strcreateziparchive" 862 ); 863 if (!empty($count)) { 864 865 choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:getElementById('dirform').submit()"); 866 echo '<div id="noscriptgo" style="display: inline;">'; 867 echo '<input type="submit" value="'.get_string('go').'" />'; 868 echo '<script type="text/javascript">'. 869 "\n//<![CDATA[\n". 870 'document.getElementById("noscriptgo").style.display = "none";'. 871 "\n//]]>\n".'</script>'; 872 echo '</div>'; 873 874 } 875 echo "</td></tr></table>"; 876 echo "</div>"; 877 echo "</form>"; 878 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>"; 879 echo "<td align=\"center\">"; 880 if (!empty($USER->fileop) and ($USER->fileop == "move") and ($USER->filesource <> $wdir)) { 881 echo "<form action=\"index.php\" method=\"get\">"; 882 echo "<div>"; 883 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 884 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 885 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 886 echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />"; 887 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; 888 echo " <input type=\"submit\" value=\"$strmovefilestohere\" />"; 889 echo "</div>"; 890 echo "</form>"; 891 } 892 echo "</td>"; 893 echo "<td align=\"right\">"; 894 echo "<form action=\"index.php\" method=\"get\">"; 895 echo "<div>"; 896 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 897 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 898 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 899 echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />"; 900 echo " <input type=\"submit\" value=\"$strmakeafolder\" />"; 901 echo "</div>"; 902 echo "</form>"; 903 echo "</td>"; 904 echo "<td align=\"right\">"; 905 echo "<form action=\"index.php\" method=\"get\">"; //dummy form - alignment only 906 echo "<fieldset class=\"invisiblefieldset\">"; 907 echo " <input type=\"button\" value=\"$strselectall\" onclick=\"checkall();\" />"; 908 echo " <input type=\"button\" value=\"$strselectnone\" onclick=\"uncheckall();\" />"; 909 echo "</fieldset>"; 910 echo "</form>"; 911 echo "</td>"; 912 echo "<td align=\"right\">"; 913 echo "<form action=\"index.php\" method=\"get\">"; 914 echo "<div>"; 915 echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; 916 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; 917 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; 918 echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />"; 919 echo " <input type=\"submit\" value=\"$struploadafile\" />"; 920 echo "</div>"; 921 echo "</form>"; 922 echo "</td></tr>"; 923 echo "</table>"; 924 echo "<hr/>"; 925 //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; 926 927 } 928 929 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |