public function __construct($path = SEARCH_INDEX_PATH) { global $CFG, $db; $this->path = $path; //test to see if there is a valid index on disk, at the specified path try { $test_index = new Zend_Search_Lucene($this->path, false); $validindex = true; } catch (Exception $e) { $validindex = false; } //retrieve file system info about the index if it is valid if ($validindex) { $this->size = display_size(get_directory_size($this->path)); $index_dir = get_directory_list($this->path, '', false, false); $this->filecount = count($index_dir); $this->indexcount = $test_index->count(); } else { $this->size = 0; $this->filecount = 0; $this->indexcount = 0; } $db_exists = false; //for now //get all the current tables in moodle $admin_tables = $db->MetaTables(); //TODO: use new IndexDBControl class for database checks? //check if our search table exists if (in_array($CFG->prefix . SEARCH_DATABASE_TABLE, $admin_tables)) { //retrieve database information if it does $db_exists = true; //total documents $this->dbcount = count_records(SEARCH_DATABASE_TABLE); //individual document types // $types = search_get_document_types(); $types = search_collect_searchables(true, false); sort($types); foreach ($types as $type) { $c = count_records(SEARCH_DATABASE_TABLE, 'doctype', $type); $this->types[$type] = (int) $c; } } else { $this->dbcount = 0; $this->types = array(); } //check if the busy flag is set if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') { $this->complete = false; } else { $this->complete = true; } //get the last run date for the indexer if ($this->valid() && $CFG->search_indexer_run_date) { $this->time = $CFG->search_indexer_run_date; } else { $this->time = 0; } }
/** * Standard modular run function. * * @return tempcode The result of execution. */ function run() { if (!addon_installed('filedump')) { return new ocp_tempcode(); } if (!file_exists(get_custom_file_base() . '/uploads/filedump')) { return new ocp_tempcode(); } require_lang('filedump'); require_code('files2'); $bits = new ocp_tempcode(); if (get_option('filedump_show_stats_count_total_files', true) == '1') { $bits->attach(do_template('BLOCK_SIDE_STATS_SUBLINE', array('KEY' => do_lang_tempcode('COUNT_FILES'), 'VALUE' => integer_format(count(get_directory_contents(get_custom_file_base() . '/uploads/filedump')))))); } if (get_option('filedump_show_stats_count_total_space', true) == '1') { $bits->attach(do_template('BLOCK_SIDE_STATS_SUBLINE', array('KEY' => do_lang_tempcode('DISK_USAGE'), 'VALUE' => clean_file_size(get_directory_size(get_custom_file_base() . '/uploads/filedump'))))); } if ($bits->is_empty()) { return new ocp_tempcode(); } $section = do_template('BLOCK_SIDE_STATS_SECTION', array('SECTION' => do_lang_tempcode('FILE_DUMP'), 'CONTENT' => $bits)); return $section; }
/** * Adds up all the files in a directory and works out the size. * * @param string $rootdir The directory to start from * @param string $excludefile A file to exclude when summing directory size * @return int The summed size of all files and subfiles within the root directory */ function get_directory_size($rootdir, $excludefile = '') { global $CFG; // Do it this way if we can, it's much faster. if (!empty($CFG->pathtodu) && is_executable(trim($CFG->pathtodu))) { $command = trim($CFG->pathtodu) . ' -sk ' . escapeshellarg($rootdir); $output = null; $return = null; exec($command, $output, $return); if (is_array($output)) { // We told it to return k. return get_real_size(intval($output[0]) . 'k'); } } if (!is_dir($rootdir)) { // Must be a directory. return 0; } if (!($dir = @opendir($rootdir))) { // Can't open it for some reason. return 0; } $size = 0; while (false !== ($file = readdir($dir))) { $firstchar = substr($file, 0, 1); if ($firstchar == '.' or $file == 'CVS' or $file == $excludefile) { continue; } $fullfile = $rootdir . '/' . $file; if (filetype($fullfile) == 'dir') { $size += get_directory_size($fullfile, $excludefile); } else { $size += filesize($fullfile); } } closedir($dir); return $size; }
function displaydir($wdir) { // $wdir == / or /a or /a/b/c/d etc global $basedir; global $id; global $USER, $CFG; 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 { $filelist[] = $file; } } closedir($directory); $strname = get_string("name"); $strsize = get_string("size"); $strmodified = get_string("modified"); $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"); $strdeletecompletely = get_string("deletecompletely"); $strcreateziparchive = get_string("createziparchive"); $strrename = get_string("rename"); $stredit = get_string("edit"); $strunzip = get_string("unzip"); $strlist = get_string("list"); $strrestore = get_string("restore"); $strchoose = get_string("choose"); $strfolder = get_string("folder"); $strfile = get_string("file"); echo "<form action=\"index.php\" method=\"post\" id=\"dirform\">"; echo "<div>"; echo '<input type="hidden" name="choose" value="' . $choose . '" />'; // echo "<hr align=\"center\" noshade=\"noshade\" size=\"1\" />"; echo "<hr/>"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\" class=\"files\">"; echo "<tr>"; echo "<th class=\"header\" scope=\"col\"></th>"; echo "<th class=\"header name\" scope=\"col\">{$strname}</th>"; echo "<th class=\"header size\" scope=\"col\">{$strsize}</th>"; echo "<th class=\"header date\" scope=\"col\">{$strmodified}</th>"; echo "<th class=\"header commands\" scope=\"col\">{$straction}</th>"; echo "</tr>\n"; if ($wdir != "/") { $dirlist[] = '..'; } $count = 0; if (!empty($dirlist)) { asort($dirlist); foreach ($dirlist as $dir) { echo "<tr class=\"folder\">"; if ($dir == '..') { $fileurl = rawurlencode(dirname($wdir)); print_cell(); // alt attribute intentionally empty to prevent repetition in screen reader 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'); print_cell(); print_cell(); print_cell(); } else { $count++; $filename = $fullpath . "/" . $dir; $fileurl = rawurlencode($wdir . "/" . $dir); $filesafe = rawurlencode($dir); $filesize = display_size(get_directory_size("{$fullpath}/{$dir}")); $filedate = userdate(filemtime($filename), get_string("strftimedatetime")); if ($wdir . $dir === '/moddata') { print_cell(); } else { print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox'); } 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'); print_cell("right", $filesize, 'size'); print_cell("right", $filedate, 'date'); if ($wdir . $dir === '/moddata') { print_cell(); } else { print_cell("right", "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$filesafe}&action=rename&choose={$choose}\">{$strrename}</a>", 'commands'); } } echo "</tr>"; } } if (!empty($filelist)) { asort($filelist); foreach ($filelist as $file) { $icon = mimeinfo("icon", $file); $count++; $filename = $fullpath . "/" . $file; $fileurl = trim($wdir, "/") . "/{$file}"; $filesafe = rawurlencode($file); $fileurlsafe = rawurlencode($fileurl); $filedate = userdate(filemtime($filename), get_string("strftimedatetime")); $selectfile = trim($fileurl, "/"); echo "<tr class=\"file\">"; print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox'); echo "<td align=\"left\" style=\"white-space:nowrap\" class=\"name\">"; $ffurl = get_file_url($id . '/' . $fileurl); link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" /> " . htmlspecialchars($file), 480, 640); echo "</td>"; $file_size = filesize($filename); print_cell("right", display_size($file_size), 'size'); print_cell("right", $filedate, 'date'); if ($choose) { $edittext = "<strong><a onclick=\"return set_value('{$selectfile}')\" href=\"#\">{$strchoose}</a></strong> "; } else { $edittext = ''; } if ($icon == "text.gif" || $icon == "html.gif") { $edittext .= "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=edit&choose={$choose}\">{$stredit}</a>"; } else { if ($icon == "zip.gif") { $edittext .= "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=unzip&sesskey={$USER->sesskey}&choose={$choose}\">{$strunzip}</a> "; $edittext .= "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=listzip&sesskey={$USER->sesskey}&choose={$choose}\">{$strlist}</a> "; if (!empty($CFG->backup_version) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) { $edittext .= "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$filesafe}&action=restore&sesskey={$USER->sesskey}&choose={$choose}\">{$strrestore}</a> "; } } } print_cell("right", "{$edittext} <a href=\"index.php?id={$id}&wdir={$wdir}&file={$filesafe}&action=rename&choose={$choose}\">{$strrename}</a>", 'commands'); echo "</tr>"; } } echo "</table>"; echo "<hr />"; //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">"; echo "<tr><td>"; echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo '<input type="hidden" name="choose" value="' . $choose . '" />'; echo "<input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" /> "; echo "<input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />"; $options = array("move" => "{$strmovetoanotherfolder}", "delete" => "{$strdeletecompletely}", "zip" => "{$strcreateziparchive}"); if (!empty($count)) { choose_from_menu($options, "action", "", "{$strwithchosenfiles}...", "javascript:getElementById('dirform').submit()"); echo '<div id="noscriptgo" style="display: inline;">'; echo '<input type="submit" value="' . get_string('go') . '" />'; echo '<script type="text/javascript">' . "\n//<![CDATA[\n" . 'document.getElementById("noscriptgo").style.display = "none";' . "\n//]]>\n" . '</script>'; echo '</div>'; } echo "</td></tr></table>"; echo "</div>"; echo "</form>"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>"; echo "<td align=\"center\">"; if (!empty($USER->fileop) and $USER->fileop == "move" and $USER->filesource != $wdir) { echo "<form action=\"index.php\" method=\"get\">"; echo "<div>"; echo ' <input type="hidden" name="choose" value="' . $choose . '" />'; echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />"; echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />"; echo " <input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />"; echo " <input type=\"submit\" value=\"{$strmovefilestohere}\" />"; echo "</div>"; echo "</form>"; } echo "</td>"; echo "<td align=\"right\">"; echo "<form action=\"index.php\" method=\"get\">"; echo "<div>"; echo ' <input type="hidden" name="choose" value="' . $choose . '" />'; echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />"; echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />"; echo " <input type=\"submit\" value=\"{$strmakeafolder}\" />"; echo "</div>"; echo "</form>"; echo "</td>"; echo "<td align=\"right\">"; echo "<form action=\"index.php\" method=\"get\">"; //dummy form - alignment only echo "<fieldset class=\"invisiblefieldset\">"; echo " <input type=\"button\" value=\"{$strselectall}\" onclick=\"checkall();\" />"; echo " <input type=\"button\" value=\"{$strselectnone}\" onclick=\"uncheckall();\" />"; echo "</fieldset>"; echo "</form>"; echo "</td>"; echo "<td align=\"right\">"; echo "<form action=\"index.php\" method=\"get\">"; echo "<div>"; echo ' <input type="hidden" name="choose" value="' . $choose . '" />'; echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />"; echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />"; echo " <input type=\"submit\" value=\"{$struploadafile}\" />"; echo "</div>"; echo "</form>"; echo "</td></tr>"; echo "</table>"; echo "<hr/>"; //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; }
function display() { global $CFG; /// Set up generic stuff first, including checking for access parent::display(); /// Set up some shorthand variables $cm = $this->cm; $course = $this->course; $resource = $this->resource; require_once $CFG->libdir . '/filelib.php'; $subdir = optional_param('subdir', '', PARAM_PATH); $resource->reference = clean_param($resource->reference, PARAM_PATH); $formatoptions = new object(); $formatoptions->noclean = true; $formatoptions->para = false; // MDL-12061, <p> in html editor breaks xhtml strict add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id); if ($resource->reference) { $relativepath = "{$course->id}/{$resource->reference}"; } else { $relativepath = "{$course->id}"; } if ($subdir) { $relativepath = "{$relativepath}{$subdir}"; if (stripos($relativepath, 'backupdata') !== FALSE or stripos($relativepath, $CFG->moddata) !== FALSE) { error("Access not allowed!"); } $subs = explode('/', $subdir); array_shift($subs); $countsubs = count($subs); $count = 0; $backsub = ''; foreach ($subs as $sub) { $count++; if ($count < $countsubs) { $backsub .= "/{$sub}"; $this->navlinks[] = array('name' => $sub, 'link' => "view.php?id={$cm->id}", 'type' => 'title'); } else { $this->navlinks[] = array('name' => $sub, 'link' => '', 'type' => 'title'); } } } $pagetitle = strip_tags($course->shortname . ': ' . format_string($resource->name)); $update = update_module_button($cm->id, $course->id, $this->strresource); if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id))) { $options = array('id' => $course->id, 'wdir' => '/' . $resource->reference . $subdir); $editfiles = print_single_button("{$CFG->wwwroot}/files/index.php", $options, get_string("editfiles"), 'get', '', true); $update = $editfiles . $update; } $navigation = build_navigation($this->navlinks, $cm); print_header($pagetitle, $course->fullname, $navigation, "", "", true, $update, navmenu($course, $cm)); if (trim(strip_tags($resource->summary))) { print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center"); print_spacer(10, 10); } $files = get_directory_list("{$CFG->dataroot}/{$relativepath}", array($CFG->moddata, 'backupdata'), false, true, true); if (!$files) { print_heading(get_string("nofilesyet")); print_footer($course); exit; } print_simple_box_start("center", "", "", '0'); $strftime = get_string('strftimedatetime'); $strname = get_string("name"); $strsize = get_string("size"); $strmodified = get_string("modified"); $strfolder = get_string("folder"); $strfile = get_string("file"); echo '<table cellpadding="4" cellspacing="1" class="files" summary="">'; echo "<tr><th class=\"header name\" scope=\"col\">{$strname}</th>" . "<th align=\"right\" colspan=\"2\" class=\"header size\" scope=\"col\">{$strsize}</th>" . "<th align=\"right\" class=\"header date\" scope=\"col\">{$strmodified}</th>" . "</tr>"; foreach ($files as $file) { if (is_dir("{$CFG->dataroot}/{$relativepath}/{$file}")) { // Must be a directory $icon = "folder.gif"; $relativeurl = "/view.php?blah"; $filesize = display_size(get_directory_size("{$CFG->dataroot}/{$relativepath}/{$file}")); } else { $icon = mimeinfo("icon", $file); $relativeurl = get_file_url("{$relativepath}/{$file}"); $filesize = display_size(filesize("{$CFG->dataroot}/{$relativepath}/{$file}")); } if ($icon == 'folder.gif') { echo '<tr class="folder">'; echo '<td class="name">'; echo "<a href=\"view.php?id={$cm->id}&subdir={$subdir}/{$file}\">"; echo "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfolder}\" /> {$file}</a>"; } else { echo '<tr class="file">'; echo '<td class="name">'; link_to_popup_window($relativeurl, "resourcedirectory{$resource->id}", "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" /> {$file}", 450, 600, ''); } echo '</td>'; echo '<td> </td>'; echo '<td align="right" class="size">'; echo $filesize; echo '</td>'; echo '<td align="right" class="date">'; echo userdate(filemtime("{$CFG->dataroot}/{$relativepath}/{$file}"), $strftime); echo '</td>'; echo '</tr>'; } echo '</table>'; print_simple_box_end(); print_footer($course); }
function repository_get_directory_size($rootdir, $excludefile = '') { global $CFG; if (($r = repository_is_local($rootdir)) !== false) { return get_directory_size($r->local_path($rootdir), $excludefile); } if (!repository_is_dir($rootdir)) { // Must be a directory return 0; } if (!($dir = @opendir($rootdir))) { // Can't open it for some reason return 0; } $size = 0; while (false !== ($file = readdir($dir))) { $firstchar = substr($file, 0, 1); if ($firstchar == '.' or $file == 'CVS' or $file == $excludefile) { continue; } $fullfile = $rootdir . '/' . $file; if (repository_is_dir($fullfile)) { $size += repository_get_directory_size($fullfile, $excludefile); } else { $size += repository_filesize($fullfile); } } closedir($dir); return $size; }
/** * The main user interface for the file dump. * * @return tempcode The UI. */ function module_do_gui() { $title = get_page_title('FILE_DUMP'); $place = filter_naughty(get_param('place', '/')); if (substr($place, -1, 1) != '/') { $place .= '/'; } $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=filedump&filter=' . $place; // Show tree $dirs = explode('/', substr($place, 0, strlen($place) - 1)); $i = 0; $pre = ''; $file_tree = new ocp_tempcode(); while (array_key_exists($i, $dirs)) { if ($i > 0) { $d = $dirs[$i]; } else { $d = do_lang('FILE_DUMP'); } if (array_key_exists($i + 1, $dirs)) { $tree_url = build_url(array('page' => '_SELF', 'place' => $pre . $dirs[$i] . '/'), '_SELF'); if (!$file_tree->is_empty()) { $file_tree->attach(do_template('BREADCRUMB', array('_GUID' => '7ee62e230d53344a7d9667dc59be21c6'))); } $file_tree->attach(hyperlink($tree_url, $d)); } $pre .= $dirs[$i] . '/'; $i++; } if (!$file_tree->is_empty()) { breadcrumb_add_segment($file_tree, $d); } else { breadcrumb_set_self($i == 1 ? do_lang_tempcode('FILE_DUMP') : make_string_tempcode(escape_html($d))); } // Check directory exists $fullpath = get_custom_file_base() . '/uploads/filedump' . $place; if (!file_exists(get_custom_file_base() . '/uploads/filedump' . $place)) { if (has_specific_permission(get_member(), 'upload_filedump')) { @mkdir($fullpath, 0777) or warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY', escape_html($fullpath), escape_html(dirname($fullpath)))); fix_permissions($fullpath, 0777); sync_file($fullpath); } } // Find all files in the incoming directory $handle = opendir(get_custom_file_base() . '/uploads/filedump' . $place); $i = 0; $filename = array(); $description = array(); $filesize = array(); $filetime = array(); $directory = array(); $deletable = array(); while (false !== ($file = readdir($handle))) { if (!should_ignore_file('uploads/filedump' . $place . $file, IGNORE_ACCESS_CONTROLLERS | IGNORE_HIDDEN_FILES)) { $directory[$i] = !is_file(get_custom_file_base() . '/uploads/filedump' . $place . $file); $filename[$i] = $directory[$i] ? $file . '/' : $file; if ($directory[$i]) { $filesize[$i] = do_lang_tempcode('NA_EM'); } $dbrows = $GLOBALS['SITE_DB']->query_select('filedump', array('description', 'the_member'), array('name' => $file, 'path' => $place)); if (!array_key_exists(0, $dbrows)) { $description[$i] = $directory[$i] ? do_lang_tempcode('NA_EM') : do_lang_tempcode('NONE_EM'); } else { $description[$i] = make_string_tempcode(escape_html(get_translated_text($dbrows[0]['description']))); } if ($description[$i]->is_empty()) { $description[$i] = do_lang_tempcode('NONE_EM'); } $deletable[$i] = array_key_exists(0, $dbrows) && $dbrows[0]['the_member'] == get_member() || has_specific_permission(get_member(), 'delete_anything_filedump'); if ($directory[$i]) { $size = get_directory_size(get_custom_file_base() . '/uploads/filedump' . $place . $file); $timestamp = NULL; } else { $size = filesize(get_custom_file_base() . '/uploads/filedump' . $place . $file); $timestamp = filemtime(get_custom_file_base() . '/uploads/filedump' . $place . $file); } $filesize[$i] = clean_file_size($size); $filetime[$i] = is_null($timestamp) ? NULL : get_timezoned_date($timestamp); $i++; } } closedir($handle); if ($i != 0) { require_code('templates_table_table'); $header_row = table_table_header_row(array(do_lang_tempcode('FILENAME'), do_lang_tempcode('DESCRIPTION'), do_lang_tempcode('SIZE'), do_lang_tempcode('DATE_TIME'), do_lang_tempcode('ACTIONS'))); $rows = new ocp_tempcode(); for ($a = 0; $a < $i; $a++) { if ($directory[$a]) { $link = build_url(array('page' => '_SELF', 'place' => $place . $filename[$a]), '_SELF'); } else { $link = make_string_tempcode(get_custom_base_url() . '/uploads/filedump' . str_replace('%2F', '/', rawurlencode($place . $filename[$a]))); } if (!$directory[$a]) { if ($deletable[$a]) { $delete_url = build_url(array('page' => '_SELF', 'type' => 'ed', 'file' => $filename[$a], 'place' => $place), '_SELF'); $actions = do_template('TABLE_TABLE_ACTION_DELETE_ENTRY', array('_GUID' => '9b91e485d80417b1664145f9bca5a2f5', 'NAME' => $filename[$a], 'URL' => $delete_url)); } else { $actions = new ocp_tempcode(); } } else { $delete_url = build_url(array('page' => '_SELF', 'type' => 'ec', 'file' => $filename[$a], 'place' => $place), '_SELF'); $actions = do_template('TABLE_TABLE_ACTION_DELETE_CATEGORY', array('_GUID' => '0fa7d4090c6195328191399a14799169', 'NAME' => $filename[$a], 'URL' => $delete_url)); } $rows->attach(table_table_row(array(hyperlink($link, escape_html($filename[$a]), !$directory[$a]), escape_html($description[$a]), escape_html($filesize[$a]), is_null($filetime[$a]) ? do_lang_tempcode('NA') : make_string_tempcode(escape_html($filetime[$a])), $actions))); } $files = do_template('TABLE_TABLE', array('_GUID' => '1c0a91d47c5fc8a7c2b35c7d9b36132f', 'HEADER_ROW' => $header_row, 'ROWS' => $rows)); } else { $files = new ocp_tempcode(); } // Do a form so people can upload their own stuff if (has_specific_permission(get_member(), 'upload_filedump')) { $post_url = build_url(array('page' => '_SELF', 'type' => 'ad', 'uploading' => 1), '_SELF'); $submit_name = do_lang_tempcode('FILEDUMP_UPLOAD'); $max = floatval(get_max_file_size()); $text = new ocp_tempcode(); if ($max < 30.0) { $config_url = get_upload_limit_config_url(); $text->attach(do_lang_tempcode(is_null($config_url) ? 'MAXIMUM_UPLOAD' : 'MAXIMUM_UPLOAD_STAFF', escape_html($max > 10.0 ? integer_format(intval($max)) : float_format($max / 1024.0 / 1024.0)), escape_html(is_null($config_url) ? '' : $config_url))); } require_code('form_templates'); $fields = form_input_upload(do_lang_tempcode('UPLOAD'), do_lang_tempcode('_DESCRIPTION_UPLOAD'), 'file', true); $fields->attach(form_input_line(do_lang_tempcode('DESCRIPTION'), do_lang_tempcode('DESCRIPTION_DESCRIPTION'), 'description', '', false)); $hidden = new ocp_tempcode(); $hidden->attach(form_input_hidden('place', $place)); handle_max_file_size($hidden); $upload_form = do_template('FORM', array('TABINDEX' => strval(get_form_field_tabindex()), 'SKIP_REQUIRED' => true, 'HIDDEN' => $hidden, 'TEXT' => $text, 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url)); } else { $upload_form = new ocp_tempcode(); } // Do a form so people can make folders if (get_option('is_on_folder_create') == '1') { $post_url = build_url(array('page' => '_SELF', 'type' => 'ac'), '_SELF'); require_code('form_templates'); $fields = form_input_line(do_lang_tempcode('NAME'), do_lang_tempcode('DESCRIPTION_NAME'), 'name', '', true); $hidden = form_input_hidden('place', $place); $submit_name = do_lang_tempcode('FILEDUMP_CREATE_FOLDER'); $create_folder_form = do_template('FORM', array('_GUID' => '043f9b595d3699b7d8cd7f2284cdaf98', 'TABINDEX' => strval(get_form_field_tabindex()), 'SKIP_REQUIRED' => true, 'SECONDARY_FORM' => true, 'HIDDEN' => $hidden, 'TEXT' => '', 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url)); } else { $create_folder_form = new ocp_tempcode(); } return do_template('FILE_DUMP_SCREEN', array('_GUID' => '3f49a8277a11f543eff6488622949c84', 'TITLE' => $title, 'PLACE' => $place, 'FILES' => $files, 'UPLOAD_FORM' => $upload_form, 'CREATE_FOLDER_FORM' => $create_folder_form)); }
$table->head = array($hdrid, $hdrname, $hdrsize); $table->size = array('*', '*', '*'); $table->align = array('right', 'left', 'right'); $table->width = '80%'; $table->data = array(); $table->tablealign = 'center'; $table->rowclass = array(); $data = array(); $total = 0; foreach ($courses as $c) { if ($c->id == SITEID) { $c->fullname .= ' (' . $strsite . ')'; } elseif ($cat) { $c->fullname .= ' (' . $c->name . ')'; } $duraw = get_directory_size($CFG->dataroot . '/' . $c->id); $total += $duraw; $du = display_size($duraw); $courselink = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>'; $data[] = array($c->id, $courselink, $duraw); $table->rowclass[] = 'coursesize_data'; } /// Sort the data by size if required if ($sort == 'size_ASC') { usort($data, 'coursesize_sort_by_size_asc'); } elseif ($sort == 'size_DESC') { usort($data, 'coursesize_sort_by_size_desc'); } /// Now we need to make the sizes human readable /// We can't do this earlier because the size sort won't work foreach ($data as $row) {
/** * Get Directory Size - get_video_file($vdata,$no_video,false); */ function get_directory_size($path) { $totalsize = 0; $totalcount = 0; $dircount = 0; if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { $nextpath = $path . '/' . $file; if ($file != '.' && $file != '..' && !is_link($nextpath)) { if (is_dir($nextpath)) { $dircount++; $result = get_directory_size($nextpath); $totalsize += $result['size']; $totalcount += $result['count']; $dircount += $result['dircount']; } elseif (is_file($nextpath)) { $totalsize += filesize($nextpath); $totalcount++; } } } } closedir($handle); $total['size'] = $totalsize; $total['count'] = $totalcount; $total['dircount'] = $dircount; return $total; }
/** * Adds up all the files in a directory and works out the size. * * @param string $rootdir ? * @param string $excludefile ? * @return array * @todo Finish documenting this function */ function get_directory_size($rootdir, $excludefile = '') { global $CFG; $textlib = textlib_get_instance(); // do it this way if we can, it's much faster if (!empty($CFG->pathtodu) && is_executable(trim($CFG->pathtodu))) { $command = trim($CFG->pathtodu) . ' -sk --apparent-size ' . escapeshellarg($rootdir); exec($command, $output, $return); if (is_array($output)) { return get_real_size(intval($output[0]) . 'k'); // we told it to return k. } } $size = 0; if (!is_dir($rootdir)) { // Must be a directory return $dirs; } if (!($dir = @opendir($rootdir))) { // Can't open it for some reason return $dirs; } while (false !== ($file = readdir($dir))) { $firstchar = $textlib->substr($file, 0, 1); if ($firstchar == '.' or $file == 'CVS' or $file == $excludefile) { continue; } $fullfile = $rootdir . '/' . $file; if (filetype($fullfile) == 'dir') { $size += get_directory_size($fullfile, $excludefile); } else { $size += filesize($fullfile); } } closedir($dir); return $size; }
function displaydir($wdir) { // $wdir == / or /a or /a/b/c/d etc global $basedir; global $id; global $USER, $CFG; global $choose; $fullpath = $basedir . $wdir; check_dir_exists($fullpath, true); $directory = opendir($fullpath); // Find all files while (false !== ($file = readdir($directory))) { if ($file == "." || $file == "..") { continue; } if (is_dir($fullpath . "/" . $file)) { $dirlist[] = $file; } else { $filelist[] = $file; } } closedir($directory); $strname = get_string("name"); $strsize = get_string("size"); $strmodified = get_string("modified"); $straction = get_string("action"); $strmakeafolder = get_string("makeafolder"); $struploadafile = get_string("uploadafile"); $strwithchosenfiles = get_string("withchosenfiles"); $strmovetoanotherfolder = get_string("movetoanotherfolder"); $strmovefilestohere = get_string("movefilestohere"); $strdeletecompletely = get_string("deletecompletely"); $strcreateziparchive = get_string("createziparchive"); $strrename = get_string("rename"); $stredit = get_string("edit"); $strunzip = get_string("unzip"); $strlist = get_string("list"); $strrestore = get_string("restore"); $strchoose = get_string("choose"); $prop = null; $prop->action = "index.php"; $prop->method = "post"; $prop->id = "dirform"; wiki_form_start($prop); wiki_div_start(); $prop = null; $prop->name = "choose"; $prop->value = $choose; wiki_input_hidden($prop); wiki_hr(); $prop = null; $prop->border = "0"; $prop->spacing = "2"; $prop->padding = "2"; $prop->width = "640"; $prop->class = "files"; $prop->header = true; $prop->styleth = "width:5%"; wiki_table_start($prop); $prop = null; $prop->header = true; $prop->align = "left"; $prop->class = "header name"; wiki_change_column($prop); echo $strname; $prop = null; $prop->header = true; $prop->align = "right"; $prop->class = "header size"; wiki_change_column($prop); echo $strsize; $prop = null; $prop->header = true; $prop->align = "right"; $prop->class = "header date"; wiki_change_column($prop); echo $strmodified; $prop = null; $prop->header = true; $prop->align = "right"; $prop->class = "header commands"; wiki_change_column($prop); echo $straction; if ($wdir == "/") { $wdir = ""; } if (!empty($wdir)) { $dirlist[] = '..'; } $count = 0; $header = true; if (!empty($dirlist)) { asort($dirlist); foreach ($dirlist as $dir) { if ($header) { $header = false; $prop = null; $prop->header = true; } else { $prop = null; } if ($dir == '..') { $fileurl = rawurlencode(dirname($wdir)); $prop->style = "white-space: nowrap;"; $prop->align = "center"; $prop->classtr = "folder"; wiki_change_row($prop); echo ' '; $prop = null; $prop->class = 'name'; $prop->align = 'left'; $prop->style = "white-space: nowrap;"; wiki_change_column($prop); $prop = null; $prop->src = $CFG->pixpath . '/f/parent.gif'; $prop->height = "16"; $prop->width = "16"; $prop->alt = get_string('parentfolder'); $out = wiki_img($prop, true); $prop = null; $prop->href = 'index.php?id=' . $id . '&wdir=' . $fileurl; wiki_a($out, $prop); $prop = null; $prop->href = 'index.php?id=' . $id . '&wdir=' . $fileurl; wiki_a(get_string('parentfolder'), $prop); wiki_change_column(); echo ' '; wiki_change_column(); echo ' '; wiki_change_column(); echo ' '; } else { $count++; $filename = $fullpath . "/" . $dir; $fileurl = rawurlencode($wdir . "/" . $dir); $filesafe = rawurlencode($dir); $filesize = display_size(get_directory_size("{$fullpath}/{$dir}")); $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); $prop->align = "center"; $prop->style = "white-space: nowrap;"; $prop->class = "checkbox"; $prop->classtr = "folder"; wiki_change_row($prop); $prop = null; $prop->name = 'file' . $count; $prop->value = $fileurl; wiki_input_checkbox($prop); $prop = null; $prop->class = 'name'; $prop->align = "left"; $prop->style = "white-space: nowrap;"; wiki_change_column($prop); $prop = null; $prop->src = $CFG->pixpath . '/f/folder.gif'; $prop->height = "16"; $prop->width = "16"; $prop->alt = "Folder"; $out = wiki_img($prop, true); $prop = null; $prop->href = 'index.php?id=' . $id . '&wdir=' . $fileurl . '&choose=' . $choose; wiki_a($out, $prop); $prop = null; $prop->href = 'index.php?id=' . $id . '&wdir=' . $fileurl . '&choose=' . $choose; wiki_a(htmlspecialchars($dir), $prop); $prop = null; $prop->class = 'size'; $prop->align = "right"; $prop->style = "white-space: nowrap;"; wiki_change_column($prop); echo $filesize; $prop = null; $prop->class = 'date'; $prop->align = "right"; $prop->style = "white-space: nowrap;"; wiki_change_column($prop); echo $filedate; $prop = null; $prop->class = 'commands'; $prop->align = "right"; $prop->style = "white-space: nowrap;"; wiki_change_column($prop); $prop = null; $prop->href = 'index.php?id=' . $id . '&wdir=' . $wdir . '&file=' . $filesafe . '&action=rename&choose=' . $choose; wiki_a($strrename, $prop); //echo "<a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>"; } } } if (!empty($filelist)) { asort($filelist); foreach ($filelist as $file) { $icon = mimeinfo("icon", $file); $count++; $filename = $fullpath . "/" . $file; $fileurl = "{$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; } if ($header) { $header = false; $prop = null; $prop->header = true; } else { $prop = null; } $prop->align = "center"; $prop->style = "white-space: nowrap;"; $prop->class = "checkbox"; $prop->classtr = "file"; wiki_change_row($prop); $prop = null; $prop->name = 'file' . $count; $prop->value = $fileurl; wiki_input_checkbox($prop); $prop = null; $prop->align = "left"; $prop->class = "name nwikileftnow"; wiki_change_column($prop); if ($CFG->slasharguments) { $ffurl = "/file.php/" . $id . $fileurl; } else { $ffurl = "/file.php?file=/" . $id . $fileurl; } link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" height=\"16\" width=\"16\" alt=\"File\" />", 480, 640); echo ' '; link_to_popup_window($ffurl, "display", htmlspecialchars($file), 480, 640); $file_size = filesize($filename); $prop = null; $prop->class = 'size'; $prop->align = "right"; $prop->style = "white-space: nowrap;"; wiki_change_column($prop); echo display_size($file_size); $prop = null; $prop->class = 'date'; $prop->align = "right"; $prop->style = "white-space: nowrap;"; wiki_change_column($prop); echo $filedate; if ($choose) { $edittext = "<b><a onMouseDown=\"return set_value('{$selectfile}')\" href=\"\">{$strchoose}</a></b> "; } else { $edittext = ''; } if ($icon == "text.gif" || $icon == "html.gif") { $edittext .= "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=edit&choose={$choose}\">{$stredit}</a>"; } else { if ($icon == "zip.gif") { $edittext .= "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=unzip&sesskey={$USER->sesskey}&choose={$choose}\">{$strunzip}</a> "; $edittext .= "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=listzip&sesskey={$USER->sesskey}&choose={$choose}\">{$strlist}</a> "; } } $prop = null; $prop->class = 'commands'; $prop->align = "right"; $prop->style = "white-space: nowrap;"; wiki_change_column($prop); echo $edittext; echo "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$filesafe}&action=rename&choose={$choose}\">{$strrename}</a>"; } } if ($header) { $prop = null; $prop->header = true; wiki_table_end($prop); $header = false; } else { wiki_table_end(); } wiki_hr(); if (empty($wdir)) { $wdir = "/"; } $prop = null; $prop->name = "id"; $prop->value = $id; wiki_input_hidden($prop); $prop = null; $prop->name = "choose"; $prop->value = $choose; wiki_input_hidden($prop); $prop = null; $prop->name = "wdir"; $prop->value = $wdir; wiki_input_hidden($prop); $prop = null; $prop->name = "sesskey"; $prop->value = $USER->sesskey; wiki_input_hidden($prop); $options = array("move" => "{$strmovetoanotherfolder}", "delete" => "{$strdeletecompletely}", "zip" => "{$strcreateziparchive}"); if (!empty($count)) { choose_from_menu($options, "action", "", "{$strwithchosenfiles}...", "javascript:document.forms['dirform'].submit()"); } wiki_div_end(); wiki_form_end(); $prop = null; $prop->border = "0"; $prop->spacing = "2"; $prop->padding = "2"; $prop->class = "boxalignright"; $prop->aligntd = "center"; wiki_table_start($prop); if (!empty($USER->fileop) and $USER->fileop == "move" and $USER->filesource != $wdir) { $prop = null; $prop->action = "index.php"; $prop->method = "get"; wiki_form_start($prop); wiki_div_start(); $prop = null; $prop->name = "choose"; $prop->value = $choose; wiki_input_hidden($prop); $prop = null; $prop->name = "id"; $prop->value = $id; wiki_input_hidden($prop); $prop = null; $prop->name = "wdir"; $prop->value = $wdir; wiki_input_hidden($prop); $prop = null; $prop->name = "action"; $prop->value = "paste"; wiki_input_hidden($prop); $prop = null; $prop->name = "sesskey"; $prop->value = $USER->sesskey; wiki_input_hidden($prop); $prop = null; $prop->value = $strmovefilestohere; wiki_input_submit($prop); wiki_div_end(); wiki_form_end(); $prop = null; $prop->align = "right"; wiki_change_column($prop); } $prop = null; $prop->action = "index.php"; $prop->method = "get"; wiki_form_start($prop); wiki_div_start(); $prop = null; $prop->name = "choose"; $prop->value = $choose; wiki_input_hidden($prop); $prop = null; $prop->name = "id"; $prop->value = $id; wiki_input_hidden($prop); $prop = null; $prop->name = "wdir"; $prop->value = $wdir; wiki_input_hidden($prop); $prop = null; $prop->name = "action"; $prop->value = "mkdir"; wiki_input_hidden($prop); $prop = null; $prop->value = $strmakeafolder; wiki_input_submit($prop); wiki_div_end(); wiki_form_end(); $prop = null; $prop->align = "right"; wiki_change_column($prop); $prop = null; $prop->action = "index.php"; $prop->method = "get"; wiki_form_start($prop); wiki_div_start(); $prop = null; $prop->name = "choose"; $prop->value = $choose; wiki_input_hidden($prop); $prop = null; $prop->name = "id"; $prop->value = $id; wiki_input_hidden($prop); $prop = null; $prop->name = "wdir"; $prop->value = $wdir; wiki_input_hidden($prop); $prop = null; $prop->name = "action"; $prop->value = "upload"; wiki_input_hidden($prop); $prop = null; $prop->value = $struploadafile; wiki_input_submit($prop); wiki_div_end(); wiki_form_end(); wiki_table_end(); wiki_hr(); }
} else { $icon = mimeinfo("icon", $file); echo "<img src=\"{$CFG->pixpath}/f/{$icon}\" height=\"16\" width=\"16\" alt=\"\" /> {$file}<br />"; } } } function print_cell($alignment = 'center', $text = ' ', $class = '') { if ($class) { $class = ' class="' . $class . '"'; } echo '<td align="' . $alignment . '" nowrap="nowrap"' . $class . '>' . $text . '</td>'; } function displaydir($wdir) { // $wdir == / or /a or /a/b/c/d etc global $basedir; global $podcast; global $id; global $USER, $CFG; 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 { $filelist[] = $file; } } closedir($directory); $strname = get_string("name"); $strsize = get_string("size"); $strmodified = get_string("modified"); $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"); $strdeletecompletely = get_string("deletecompletely"); $strcreateziparchive = get_string("createziparchive"); $strrename = get_string("rename"); $stredit = get_string("edit"); $strunzip = get_string("unzip"); $strlist = get_string("list"); $strrestore = get_string("restore"); $strchoose = get_string("choose"); echo "<form action=\"index.php\" method=\"post\" name=\"dirform\">"; echo '<input type="hidden" name="choose" value="' . $choose . '" />'; echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\" class=\"files\">"; echo "<tr>"; echo "<th width=\"5\"></th>"; echo "<th align=\"left\" class=\"header name\">{$strname}</th>"; echo "<th align=\"right\" class=\"header size\">{$strsize}</th>"; echo "<th align=\"right\" class=\"header date\">{$strmodified}</th>"; echo "<th align=\"right\" class=\"header commands\">{$straction}</th>"; echo "</tr>\n"; if ($wdir != "/") { $dirlist[] = '..'; } $count = 0; if (!empty($dirlist)) { asort($dirlist); foreach ($dirlist as $dir) { echo "<tr class=\"folder\">"; if ($dir == '..') { $fileurl = rawurlencode(dirname($wdir)); print_cell(); print_cell('left', '<a href="index.php?id=' . $id . '&pod=' . $podcast . '&wdir=' . $fileurl . '&choose=' . $choose . '"><img src="' . $CFG->pixpath . '/f/parent.gif" height="16" width="16" alt="' . get_string('parentfolder') . '" /></a> <a href="index.php?id=' . $id . '&pod=' . $podcast . '&wdir=' . $fileurl . '&choose=' . $choose . '">' . get_string('parentfolder') . '</a>', 'name'); print_cell(); print_cell(); print_cell(); } else { $count++; $filename = $fullpath . "/" . $dir; $fileurl = rawurlencode($wdir . "/" . $dir); $filesafe = rawurlencode($dir); $filesize = display_size(get_directory_size("{$fullpath}/{$dir}")); $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox'); print_cell("left", "<a href=\"index.php?id={$id}&pod={$podcast}&wdir={$fileurl}&choose={$choose}\"><img src=\"{$CFG->pixpath}/f/folder.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\"Folder\" /></a> <a href=\"index.php?id={$id}&pod={$podcast}&wdir={$fileurl}&choose={$choose}\">" . htmlspecialchars($dir) . "</a>", 'name'); print_cell("right", $filesize, 'size'); print_cell("right", $filedate, 'date'); print_cell("right", "<a href=\"index.php?id={$id}&pod={$podcast}&wdir={$wdir}&file={$filesafe}&action=rename&choose={$choose}\">{$strrename}</a>", 'commands'); } echo "</tr>"; } } if (!empty($filelist)) { asort($filelist); foreach ($filelist as $file) { $icon = mimeinfo("icon", $file); $count++; $filename = $fullpath . "/" . $file; $fileurl = trim($wdir, "/") . "/{$file}"; $filesafe = rawurlencode($file); $fileurlsafe = rawurlencode($fileurl); $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); $selectfile = trim($fileurl, "/"); echo "<tr class=\"file\">"; print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox'); echo "<td align=\"left\" nowrap=\"nowrap\" class=\"name\">"; if ($CFG->slasharguments) { $ffurl = str_replace('//', '/', "/file.php/{$id}/{$fileurl}"); } else { $ffurl = str_replace('//', '/', "/file.php?file=/{$id}/{$fileurl}"); } link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" height=\"16\" width=\"16\" border=\"0\" alt=\"File\" />", 480, 640); echo ' '; link_to_popup_window($ffurl, "display", htmlspecialchars($file), 480, 640); echo "</td>"; $file_size = filesize($filename); print_cell("right", display_size($file_size), 'size'); print_cell("right", $filedate, 'date'); if ($choose) { $edittext = "<strong><a onclick=\"return set_value('{$selectfile}')\" href=\"#\">{$strchoose}</a></strong> "; } else { $edittext = ''; } if ($icon == "text.gif" || $icon == "html.gif") { $edittext .= "<a href=\"index.php?id={$id}&pod={$podcast}&wdir={$wdir}&file={$fileurl}&action=edit&choose={$choose}\">{$stredit}</a>"; } else { if ($icon == "zip.gif") { $edittext .= "<a href=\"index.php?id={$id}&pod={$podcast}&wdir={$wdir}&file={$fileurl}&action=unzip&sesskey={$USER->sesskey}&choose={$choose}\">{$strunzip}</a> "; $edittext .= "<a href=\"index.php?id={$id}&pod={$podcast}&wdir={$wdir}&file={$fileurl}&action=listzip&sesskey={$USER->sesskey}&choose={$choose}\">{$strlist}</a> "; } } print_cell("right", "{$edittext} <a href=\"index.php?id={$id}&pod={$podcast}&wdir={$wdir}&file={$filesafe}&action=rename&choose={$choose}\">{$strrename}</a>", 'commands'); echo "</tr>"; } } echo "</table>"; echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">"; echo "<tr><td>"; echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo " <input type=\"hidden\" name=\"pod\" value=\"{$podcast}\" />"; echo '<input type="hidden" name="choose" value="' . $choose . '" />'; echo "<input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" /> "; echo "<input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />"; $options = array("move" => "{$strmovetoanotherfolder}", "delete" => "{$strdeletecompletely}", "zip" => "{$strcreateziparchive}"); if (!empty($count)) { choose_from_menu($options, "action", "", "{$strwithchosenfiles}...", "javascript:document.dirform.submit()"); } echo "</form>"; echo "<td align=\"center\">"; if (!empty($USER->fileop) and $USER->fileop == "move" and $USER->filesource != $wdir) { echo "<form action=\"index.php\" method=\"get\">"; echo ' <input type="hidden" name="choose" value="' . $choose . '" />'; echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo " <input type=\"hidden\" name=\"pod\" value=\"{$podcast}\" />"; echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />"; echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />"; echo " <input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />"; echo " <input type=\"submit\" value=\"{$strmovefilestohere}\" />"; echo "</form>"; } echo "</td>"; echo "<td align=\"right\">"; echo "<form action=\"index.php\" method=\"get\">"; echo ' <input type="hidden" name="choose" value="' . $choose . '" />'; echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo " <input type=\"hidden\" name=\"pod\" value=\"{$podcast}\" />"; echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />"; echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />"; echo " <input type=\"submit\" value=\"{$strmakeafolder}\" />"; echo "</form>"; echo "</td>"; echo "<td align=\"right\">"; echo "<form action=\"index.php\" method=\"get\">"; //dummy form - alignment only echo " <input type=\"button\" value=\"{$strselectall}\" onclick=\"checkall();\" />"; echo " <input type=\"button\" value=\"{$strselectnone}\" onclick=\"uncheckall();\" />"; echo "</form>"; echo "</td>";
$userquery->admin_login_check(); $userquery->login_check('web_config_access'); /* Assigning page and subpage */ if (!defined('MAIN_PAGE')) { define('MAIN_PAGE', 'Stats And Configurations'); } if (!defined('SUB_PAGE')) { define('SUB_PAGE', 'Reports & Stats'); } $vid_dir = get_directory_size(VIDEOS_DIR); $thumb_dir = get_directory_size(THUMBS_DIR); $orig_dir = get_directory_size(ORIGINAL_DIR); $user_thumbs = get_directory_size(USER_THUMBS_DIR); $user_bg = get_directory_size(USER_BG_DIR); $grp_thumbs = get_directory_size(GP_THUMB_DIR); $cat_thumbs = get_directory_size(CAT_THUMB_DIR); assign('vid_dir', $vid_dir); assign('thumb_dir', $thumb_dir); assign('orig_dir', $orig_dir); assign('user_thumbs', $user_thumbs); assign('user_bg', $user_bg); assign('grp_thumbs', $grp_thumbs); assign('cat_thumbs', $cat_thumbs); if (!defined('MAIN_PAGE')) { define('MAIN_PAGE', 'Stats And Configurations'); } if (!defined('SUB_PAGE')) { if ($_GET['view'] == 'search') { define('SUB_PAGE', 'Search Members'); } else { define('SUB_PAGE', 'Reports & Stats');
/** * Check disk space usage against page view ratio for shared hosting. * * @param integer The extra space in bytes requested */ function check_shared_space_usage($extra) { global $SITE_INFO; if (array_key_exists('throttle_space_registered', $SITE_INFO)) { $views_till_now = intval(get_value('page_views')); $bandwidth_allowed = $SITE_INFO['throttle_space_registered']; $total_space = get_directory_size(get_custom_file_base() . '/uploads'); if ($bandwidth_allowed * 1024 * 1024 >= $total_space + $extra) { return; } } if (array_key_exists('throttle_space_complementary', $SITE_INFO)) { // $timestamp_start=$SITE_INFO['custom_user_'].current_share_user(); // $days_till_now=(time()-$timestamp_start)/(24*60*60); $views_till_now = intval(get_value('page_views')); $space_allowed = $SITE_INFO['throttle_space_complementary'] + $SITE_INFO['throttle_space_views_per_meg'] * $views_till_now; $total_space = get_directory_size(get_custom_file_base() . '/uploads'); if ($space_allowed * 1024 * 1024 < $total_space + $extra) { critical_error('RELAY', 'The hosted user has exceeded their shared-hosting "disk-space to page-view" ratio. More pages must be viewed before this may be uploaded.'); } } }
} // we know it's a directory now, but lets ignore non-numeric directories as course data is stored in moodledata in a directory named after its course id if (!is_numeric($file)) { // site files are stored in /moodledata/$courseid where $courseid is a number - we want to filter out nonsite related directories continue; } if (is_dir("{$path}/backupdata")) { $bdata = display_size(get_directory_size("{$path}/backupdata")); $bdatatotal += (int) get_directory_size("{$path}/backupdata"); } else { $bdata = display_size((int) 0); $bdatatotal += (int) 0; } if (is_dir($path)) { $sdata = display_size(get_directory_size($path)); $sdatatotal += (int) get_directory_size($path); } else { $sdata = display_size((int) 0); $sdatatotal += (int) 0; } $instructors = get_records_sql("select userid from {$CFG->prefix}role_assignments where roleid=3 and contextid=(select id from {$CFG->prefix}context where contextlevel=50 and instanceid={$file})"); if (!empty($instructors)) { $catid = get_record("course", "id", $file); // $file is course id $category = get_record("course_categories", "id", $catid->category); $parentcategory = null; if (isset($category->parent) && $category->parent !== "0") { $parentcategory = get_record("course_categories", "id", $category->parent); } foreach ($instructors as $instructor) { $userdetail = get_record_sql("select firstname, lastname, email from {$CFG->prefix}user where id={$instructor->userid}");
$currdir = $CFG->dataroot . '/' . $id; if (!file_exists($currdir)) { echo '<div class="notifyproblem" align="center">You Have No File Resources to Migrate</div>' . "<br />\n"; return false; } // get term (or category) of course // TODO: see if this query actually works $sql = "SELECT path\n \t\t\t \t FROM {$CFG->prefix}course_categories cat\n \t\t\t\t WHERE cat.id = {$course->category}"; $path = get_field_sql($sql); $paths = explode('/', $path); $path = is_null($paths[2]) ? $paths[1] : $paths[2]; $sql = "SELECT cc.name FROM {$CFG->prefix}course_categories cc\n \t\t\t WHERE cc.id = {$path}"; $term = get_field_sql($sql); if ($action === null) { html_header($course, 'Migrating Files', 'Morsle File Migration'); $space = number_format(get_directory_size("{$CFG->dataroot}/{$course->id}/") / 1024 / 1024, 2); echo '<div align="center">'; echo "<div font-color=\"#FF0000\">{$space} MB Will Be Migrated to Google Docs<br />Make Sure You Have Enough Space Before You Proceed</div><br />"; echo "<form action=\"morsle_migrate.php?id={$id}\" method=\"post\" id=\"dirform\">"; echo '<input type="hidden" name="checkaccounts" value=1>'; echo '<input type="hidden" name="space" value=' . $space . '>'; $options = array("own" => "{$strownuser}"); if (isset($deptfeed->id)) { $options['department'] = $strdepartmentuser; } if (isset($coursefeed->id)) { $options['course'] = $strcourseuser; } /* $options = array ( "course" => "$strcourseuser",