PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/resource/type/directory/resource.class.php

https://github.com/nadavkav/Moodle-RTL--Shenkar-Translation-Team-
PHP | 196 lines | 148 code | 46 blank | 2 comment | 15 complexity | 66fe2c530028447bcb221f281300ab2d MD5 | raw file
  1. <?php // $Id: resource.class.php,v 1.38.2.3 2008/05/02 08:17:27 scyrma Exp $
  2. class resource_directory extends resource_base {
  3. function resource_directory($cmid=0) {
  4. parent::resource_base($cmid);
  5. }
  6. function add_instance($resource) {
  7. $this->_postprocess($resource);
  8. return parent::add_instance($resource);
  9. }
  10. function update_instance($resource) {
  11. $this->_postprocess($resource);
  12. return parent::update_instance($resource);
  13. }
  14. function _postprocess(&$resource) {
  15. if($resource->reference=='0')
  16. $resource->reference = '';
  17. $resource->popup = '';
  18. $resource->alltext = '';
  19. }
  20. function display() {
  21. global $CFG;
  22. /// Set up generic stuff first, including checking for access
  23. parent::display();
  24. /// Set up some shorthand variables
  25. $cm = $this->cm;
  26. $course = $this->course;
  27. $resource = $this->resource;
  28. require_once($CFG->libdir.'/filelib.php');
  29. $subdir = optional_param('subdir','', PARAM_PATH);
  30. $resource->reference = clean_param($resource->reference, PARAM_PATH);
  31. $formatoptions = new object();
  32. $formatoptions->noclean = true;
  33. $formatoptions->para = false; // MDL-12061, <p> in html editor breaks xhtml strict
  34. add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);
  35. if ($resource->reference) {
  36. $relativepath = "{$course->id}/{$resource->reference}";
  37. } else {
  38. $relativepath = "{$course->id}";
  39. }
  40. if ($subdir) {
  41. $relativepath = "$relativepath$subdir";
  42. if (stripos($relativepath, 'backupdata') !== FALSE or stripos($relativepath, $CFG->moddata) !== FALSE) {
  43. error("Access not allowed!");
  44. }
  45. $subs = explode('/', $subdir);
  46. array_shift($subs);
  47. $countsubs = count($subs);
  48. $count = 0;
  49. $backsub = '';
  50. foreach ($subs as $sub) {
  51. $count++;
  52. if ($count < $countsubs) {
  53. $backsub .= "/$sub";
  54. $this->navlinks[] = array('name' => $sub, 'link' => "view.php?id={$cm->id}", 'type' => 'title');
  55. } else {
  56. $this->navlinks[] = array('name' => $sub, 'link' => '', 'type' => 'title');
  57. }
  58. }
  59. }
  60. $pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
  61. $update = update_module_button($cm->id, $course->id, $this->strresource);
  62. if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id))) {
  63. $options = array('id'=>$course->id, 'wdir'=>'/'.$resource->reference.$subdir);
  64. $editfiles = print_single_button("$CFG->wwwroot/files/index.php", $options, get_string("editfiles"), 'get', '', true);
  65. $update = $editfiles.$update;
  66. }
  67. $navigation = build_navigation($this->navlinks, $cm);
  68. print_header($pagetitle, $course->fullname, $navigation,
  69. "", "", true, $update,
  70. navmenu($course, $cm));
  71. if (trim(strip_tags($resource->summary))) {
  72. print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center");
  73. print_spacer(10,10);
  74. }
  75. $files = get_directory_list("$CFG->dataroot/$relativepath", array($CFG->moddata, 'backupdata'), false, true, true);
  76. if (!$files) {
  77. print_heading(get_string("nofilesyet"));
  78. print_footer($course);
  79. exit;
  80. }
  81. print_simple_box_start("center", "", "", '0' );
  82. $strftime = get_string('strftimedatetime');
  83. $strname = get_string("name");
  84. $strsize = get_string("size");
  85. $strmodified = get_string("modified");
  86. $strfolder = get_string("folder");
  87. $strfile = get_string("file");
  88. echo '<table cellpadding="4" cellspacing="1" class="files" summary="">';
  89. echo "<tr><th class=\"header name\" scope=\"col\">$strname</th>".
  90. "<th align=\"right\" colspan=\"2\" class=\"header size\" scope=\"col\">$strsize</th>".
  91. "<th align=\"right\" class=\"header date\" scope=\"col\">$strmodified</th>".
  92. "</tr>";
  93. foreach ($files as $file) {
  94. if (is_dir("$CFG->dataroot/$relativepath/$file")) { // Must be a directory
  95. $icon = "folder.gif";
  96. $relativeurl = "/view.php?blah";
  97. $filesize = display_size(get_directory_size("$CFG->dataroot/$relativepath/$file"));
  98. } else {
  99. $icon = mimeinfo("icon", $file);
  100. $relativeurl = get_file_url("$relativepath/$file");
  101. $filesize = display_size(filesize("$CFG->dataroot/$relativepath/$file"));
  102. }
  103. if ($icon == 'folder.gif') {
  104. echo '<tr class="folder">';
  105. echo '<td class="name">';
  106. echo "<a href=\"view.php?id={$cm->id}&amp;subdir=$subdir/$file\">";
  107. echo "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"$strfolder\" />&nbsp;$file</a>";
  108. } else {
  109. echo '<tr class="file">';
  110. echo '<td class="name">';
  111. link_to_popup_window($relativeurl, "resourcedirectory{$resource->id}", "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" />&nbsp;$file", 450, 600, '');
  112. }
  113. echo '</td>';
  114. echo '<td>&nbsp;</td>';
  115. echo '<td align="right" class="size">';
  116. echo $filesize;
  117. echo '</td>';
  118. echo '<td align="right" class="date">';
  119. echo userdate(filemtime("$CFG->dataroot/$relativepath/$file"), $strftime);
  120. echo '</td>';
  121. echo '</tr>';
  122. }
  123. echo '</table>';
  124. print_simple_box_end();
  125. print_footer($course);
  126. }
  127. function setup($form) {
  128. global $CFG;
  129. parent::setup($form);
  130. $rawdirs = get_directory_list("$CFG->dataroot/{$this->course->id}", array($CFG->moddata, 'backupdata'), true, true, false);
  131. $dirs = array();
  132. foreach ($rawdirs as $rawdir) {
  133. $dirs[$rawdir] = $rawdir;
  134. }
  135. include("$CFG->dirroot/mod/resource/type/directory/directory.html");
  136. parent::setup_end();
  137. }
  138. function setup_elements(&$mform) {
  139. global $CFG;
  140. $rawdirs = get_directory_list($CFG->dataroot.'/'.$this->course->id, array($CFG->moddata, 'backupdata'), true, true, false);
  141. $dirs = array();
  142. $dirs[0]=get_string('maindirectory', 'resource');
  143. foreach ($rawdirs as $rawdir) {
  144. $dirs[$rawdir] = $rawdir;
  145. }
  146. $mform->addElement('select', 'reference', get_string('resourcetypedirectory', 'resource'), $dirs);
  147. $mform->setDefault('windowpopup', 0);
  148. }
  149. }
  150. ?>