/** * Recursively builds a dynamic tree menu for seleting the categories to filter * search results by. * * @param array $cats An array of category objects from the DB. * @param array $selected An array of currently selected category IDs. * @param string $baseurl The base URL that this menu is being displayed on. * @return array An array of completed HTML_TreeMenu nodes. */ function repository_alfresco_make_category_select_tree_browse($cats, $selected = array(), $baseurl = '') { global $CFG; global $repo; static $catlist; if (empty($cats)) { return; } $icon = 'folder.gif'; $eicon = 'folder-expanded.gif'; $nodes = array(); /// Get the list of all the categories we actually need to display here if (!isset($catlist)) { $catlist = repository_alfresco_make_category_tree(); } $catfilter = repository_alfresco_get_category_filter(); for ($i = 0; $i < count($cats); $i++) { if (!empty($catlist) && !array_key_exists($cats[$i]->id, $catlist)) { continue; } if (empty($catfiler) || in_array($cats[$i]->id, $catfilter)) { if (in_array($cats[$i]->id, $selected)) { $checked = ' checked'; } else { $checked = ''; } $text = '<input type="checkbox" name="categories[]" value="' . $cats[$i]->id . '"' . $checked . ' /> '; } if (!empty($baseurl)) { $text .= '<a href="' . $baseurl . '&search=*&category=' . $cats[$i]->id . '">' . $cats[$i]->title . '</a>'; } else { $text .= $cats[$i]->title; } $node = new HTML_TreeNode(array('text' => $text, 'icon' => $icon, 'expandedIcon' => $eicon, 'expanded' => false)); if ($children = $repo->category_get_children($cats[$i]->id)) { if ($cnodes = repository_alfresco_make_category_select_tree_browse($children, $selected, $baseurl)) { for ($j = 0; $j < count($cnodes); $j++) { $node->addItem($cnodes[$j]); } } } $nodes[] = $node; } return $nodes; }
function displaydir($uuid, $wdir, $courseid = 0) { global $USER; global $CFG; global $basedir; global $id; global $oid; global $shared; global $userid; global $choose; global $repo; //global $uuid; global $canedit; global $category; $search = optional_param('search', '', PARAM_CLEAN); /// Get the context instance for where we originated viewing this browser from. if (!empty($oid)) { $cluster_context = get_context_instance(context_level_base::get_custom_context_level('cluster', 'block_curr_admin'), $oid); } if ($id == SITEID) { $context = get_context_instance(CONTEXT_SYSTEM, SITEID); } else { $context = get_context_instance(CONTEXT_COURSE, $id); } $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"); $strbrowserepo = get_string('browserepository', 'repository'); $strdownloadlocal = get_string('downloadlocally', 'repository'); $dirlist = array(); $filelist = array(); $parentdir = new Object(); if (!empty($userid)) { $ustore = $repo->get_user_store($userid); } if (!empty($search)) { $parentdir->title = ''; $parentdir->url = ''; } else { if (!empty($userid) && ($uuid == '' || $uuid == $ustore)) { if (empty($uuid)) { $uuid = $ustore; } $parentdir->title = ''; $parentdir->url = ''; } else { if (!empty($shared) && ($uuid == '' || $uuid == $repo->suuid)) { if (empty($uuid)) { $uuid = $repo->suuid; } $parentdir->title = ''; $parentdir->url = ''; } else { if (!empty($oid) && ($uuid == '' || $uuid == $repo->get_organization_store($oid))) { if (empty($uuid)) { $uuid = $repo->get_organization_store($oid); } $parentdir->title = ''; $parentdir->url = ''; } else { if ($id != SITEID && ($uuid == '' || !($parent = $repo->get_parent($uuid)) || ($uuid == '' || $uuid == $repo->get_course_store($id)))) { if (empty($uuid)) { $uuid = $repo->get_course_store($id); } $parentdir->title = ''; $parentdir->url = ''; } else { if ($id == SITEID && ($uuid == '' || !($parent = $repo->get_parent($uuid)))) { if (empty($uuid)) { $node = $repo->get_root(); $uuid = $node->uuid; } $parentdir->title = ''; $parentdir->url = ''; } else { $parentdir->uuid = $parent->uuid; $parentdir->name = $parent->title; $parentdir->title = '..'; } } } } } } $dirlist[] = $parentdir; $catselect = array(); if (!empty($search)) { if (($data = data_submitted()) && confirm_sesskey()) { if (!empty($data->categories)) { $catselect = $data->categories; } } else { if (!empty($category)) { $catselect = array($category); } } $search = stripslashes($search); $repodir = $repo->search($search, $catselect); } else { $repodir = $repo->read_dir($uuid); } // Store the UUID value that we are currently browsing. $repo->set_repository_location($uuid, $id, $userid, $shared, $oid); if (!empty($repodir->folders)) { foreach ($repodir->folders as $folder) { $dirlist[] = $folder; } } if (!empty($repodir->files)) { foreach ($repodir->files as $file) { $filelist[] = $file; } } echo '<form action="index.php" method="post" name="reposearch">'; echo '<input type="hidden" name="choose" value="' . $choose . '" />'; echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo "<input type=\"hidden\" name=\"oid\" value=\"{$oid}\" />"; echo "<input type=\"hidden\" name=\"shared\" value=\"{$shared}\" />"; echo "<input type=\"hidden\" name=\"userid\" value=\"{$userid}\" />"; echo "<input type=\"hidden\" name=\"uuid\" value=\"{$uuid}\" /> "; echo "<input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />"; echo '<center>'; echo '<input type="text" name="search" size="40" value="' . s($search) . '" /> '; echo '<input type="submit" value="' . get_string('search') . '" />'; helpbutton('search', get_string('alfrescosearch', 'repository_alfresco'), 'block_repository'); echo '</center><br />'; if ($cats = $repo->category_get_children(0)) { $baseurl = $CFG->wwwroot . '/file/repository/index.php?choose=' . $choose . '&id=' . $id . '&shared=' . $shared . '&oid=' . $oid . '&userid=' . $userid . '&wdir=' . $wdir . '&uuid=' . $uuid; $catfilter = repository_alfresco_get_category_filter(); $icon = 'folder.gif'; $eicon = 'folder-expanded.gif'; $menu = new HTML_TreeMenu(); $tnodes = array(); if ($cats = $repo->category_get_children(0)) { if ($nodes = repository_alfresco_make_category_select_tree_browse($cats, $catselect, $baseurl)) { for ($i = 0; $i < count($nodes); $i++) { $menu->addItem($nodes[$i]); } } } $treemenu = new HTML_TreeMenu_DHTML($menu, array('images' => $CFG->wwwroot . '/lib/HTML_TreeMenu-1.2.0/images')); // Add roll up - roll down code here, similar to Show Advanced in course/modedit // Advanced Search/Hide Advanced Search // "category filter" now has help text - so, how to add that too, but use yui library // for hiding this echo '<script language="JavaScript" type="text/javascript">'; echo "<!--\n"; include $CFG->libdir . '/HTML_TreeMenu-1.2.0/TreeMenu.js'; echo "\n// -->"; echo '</script>'; print_simple_box_start('center', '75%'); //looks for search.html file and gets text alfrescosearch from repository_alfresco lang file which I guess we use too... // now hmmm, so where does search.html go? or in our case, categoryfilter.html, I guess repository/alfresco print_heading(helpbutton('categoryfilter', get_string('alfrescocategoryfilter', 'block_repository'), 'block_repository', true, false, null, true) . get_string('categoryfilter', 'block_repository') . ':', 'center', '3'); $treemenu->printMenu(); echo '<br />'; print_simple_box_end(); } echo '</form>'; echo '<center>'; print_single_button('index.php', array('id' => $id, 'shared' => $shared, 'oid' => $oid, 'userid' => $userid, 'uuid' => $uuid), get_string('showall'), 'get'); echo '</center>'; if ($canedit) { echo "<form action=\"index.php\" method=\"post\" name=\"dirform\" id=\"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"; $count = 0; if (!empty($dirlist)) { foreach ($dirlist as $dir) { if (empty($dir->title)) { continue; } echo "<tr class=\"folder\">"; if ($dir->title == '..' || $dir->title == $strbrowserepo) { if (!empty($dir->url)) { print_cell(); if (!empty($search)) { print_cell('left', '<a href="' . $dir->url . '"><img src="' . $CFG->pixpath . '/f/parent.gif" height="16" width="16" alt="' . $strbrowserepo . '" /></a> <a href="' . $dir->url . '">' . $strbrowserepo . '</a>', 'name'); } else { print_cell('left', '<a href="' . $dir->url . '"><img src="' . $CFG->pixpath . '/f/parent.gif" height="16" width="16" alt="' . get_string('parentfolder') . '" /></a> <a href="' . $dir->url . '">' . get_string('parentfolder') . '</a>', 'name'); } print_cell(); print_cell(); print_cell(); } else { $pdir = urlencode($dir->title); $fileurl = $dir->uuid; print_cell(); print_cell('left', '<a href="index.php?id=' . $id . '&shared=' . $shared . '&oid=' . $oid . '&userid=' . $userid . '&wdir=' . $pdir . '&uuid=' . $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 . '&shared=' . $shared . '&oid=' . $oid . '&userid=' . $userid . '&wdir=' . $pdir . '&uuid=' . $fileurl . '&choose=' . $choose . '">' . get_string('parentfolder') . '</a>', 'name'); print_cell(); print_cell(); print_cell(); } } else { $count++; $filename = $dir->title; $pdir = urlencode($filename); $fileurl = $dir->uuid; $filesafe = rawurlencode($dir->title); $filesize = '-'; $filedate = !empty($dir->modified) ? userdate($dir->modified, "%d %b %Y, %I:%M %p") : '-'; if ($canedit) { print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox'); } else { print_cell(); } print_cell("left", "<a href=\"index.php?id={$id}&shared={$shared}&oid={$oid}&userid={$userid}&wdir={$pdir}&uuid={$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}&shared={$shared}&oid={$oid}&userid={$userid}&wdir={$pdir}&uuid={$fileurl}&choose={$choose}\">" . htmlspecialchars($dir->title) . "</a>", 'name'); print_cell("right", $filesize, 'size'); print_cell("right", $filedate, 'date'); print_cell('right', '-', 'commands'); } echo "</tr>"; } } if (!empty($filelist)) { asort($filelist); echo ' <script language="javascript"> <!-- function openextpopup(url,name,options,fullscreen) { windowobj = window.open(url,name,options); if (fullscreen) { windowobj.moveTo(0,0); windowobj.resizeTo(screen.availWidth,screen.availHeight); } windowobj.focus(); return false; } // --> </script> '; foreach ($filelist as $file) { // $icon = $file->icon; $icon = mimeinfo('icon', $file->title); $count++; $filename = $file->title; $fileurl = $CFG->wwwroot . '/file/repository/alfresco/openfile.php?uuid=' . $file->uuid; $filesafe = rawurlencode($file->title); $fileurlsafe = rawurlencode($fileurl); $filedate = !empty($file->modified) ? userdate($file->modified, "%d %b %Y, %I:%M %p") : '-'; $filesize = ''; $selectfile = $fileurl; echo "<tr class=\"file\">"; if ($canedit) { print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$file->uuid}\" />", 'checkbox'); } else { print_cell(); } 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}"); } $height = 480; $width = 640; $name = '_blank'; $url = $fileurl; $title = 'Popup window'; $linkname = "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$file->title}\" />"; $options = 'menubar=0,location=0,scrollbars,resizable,width=' . $width . ',height=' . $height; if (!empty($search) && !empty($file->parent)) { $pdir = urlencode($file->parent->name); $fileurl = $file->parent->uuid; $motext = get_string('parentfolder', 'repository', $file->parent->name); echo "<a href=\"index.php?id={$id}&shared={$shared}&oid={$oid}&userid={$userid}&wdir={$pdir}&uuid={$fileurl}&choose={$choose}\" title=\"{$motext}\"><img src=\"{$CFG->pixpath}/f/folder.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\"Folder\" /></a> "; } echo '<a target="' . $name . '" title="' . $title . '" href="' . $url . '" ' . ">{$linkname}</a>"; echo ' '; $linkname = htmlspecialchars($file->title); echo '<a target="' . $name . '" title="' . $title . '" href="' . $url . '" ' . ">{$linkname}</a>"; echo "</td>"; print_cell("right", display_size(isset($file->filesize) ? $file->filesize : '-'), 'size'); print_cell("right", $filedate, 'date'); if ($choose) { $edittext = "<strong><a onclick=\"return set_value('{$selectfile}')\" href=\"#\">{$strchoose}</a></strong> "; } else { $edittext = ''; } if (strstr($icon, 'zip.gif') !== false) { $edittext .= "<a href=\"index.php?id={$id}&shared={$shared}&oid={$oid}&userid={$userid}&uuid={$file->uuid}&action=unzip&sesskey={$USER->sesskey}&choose={$choose}\">{$strunzip}</a> "; $edittext .= "<a href=\"index.php?id={$id}&shared={$shared}&oid={$oid}&userid={$userid}&uuid={$file->uuid}&action=listzip&sesskey={$USER->sesskey}&choose={$choose}\">{$strlist}</a> "; } /// User's cannot download files locally if they cannot access the local file storage. if (has_capability('moodle/course:managefiles', $context)) { $popupurl = '/files/index.php?id=' . $id . '&shared=' . $shared . '&oid=' . $oid . '&userid=' . $userid . '&repouuid=' . $file->uuid . '&repofile=' . $filesafe . '&dd=1'; $edittext .= link_to_popup_window($popupurl, 'coursefiles', $strdownloadlocal, 500, 750, $strdownloadlocal, 'none', true); } print_cell('right', $edittext, 'commands'); echo "</tr>"; } } echo "</table>"; echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; /// Don't display the editing form buttons (yet). if (empty($search)) { echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">"; echo "<tr><td>"; if ($canedit) { echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo "<input type=\"hidden\" name=\"oid\" value=\"{$oid}\" />"; echo "<input type=\"hidden\" name=\"shared\" value=\"{$shared}\" />"; echo "<input type=\"hidden\" name=\"userid\" value=\"{$userid}\" />"; echo '<input type="hidden" name="choose" value="' . $choose . '" />'; echo "<input type=\"hidden\" name=\"uuid\" value=\"{$uuid}\" /> "; 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 != $uuid) { 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=\"oid\" value=\"{$oid}\" />"; echo " <input type=\"hidden\" name=\"shared\" value=\"{$shared}\" />"; echo " <input type=\"hidden\" name=\"userid\" value=\"{$userid}\" />"; echo " <input type=\"hidden\" name=\"uuid\" value=\"{$uuid}\" />"; 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>"; if ($canedit) { 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=\"oid\" value=\"{$oid}\" />"; echo " <input type=\"hidden\" name=\"shared\" value=\"{$shared}\" />"; echo " <input type=\"hidden\" name=\"userid\" value=\"{$userid}\" />"; echo " <input type=\"hidden\" name=\"uuid\" value=\"{$uuid}\" />"; 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>"; 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=\"oid\" value=\"{$oid}\" />"; echo " <input type=\"hidden\" name=\"shared\" value=\"{$shared}\" />"; echo " <input type=\"hidden\" name=\"userid\" value=\"{$userid}\" />"; echo " <input type=\"hidden\" name=\"uuid\" value=\"{$uuid}\" />"; echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />"; echo " <input type=\"submit\" value=\"{$struploadafile}\" />"; echo "</form>"; echo "</td>"; } echo '</tr>'; echo "</table>"; } else { $url = 'index.php?id=' . $id . '&shared=' . $shared . '&oid=' . $oid . '&userid=' . $userid . '&uuid=' . $uuid; echo '<h3><a href="' . $url . '">' . get_string('returntofilelist', 'repository') . '</a></h3>'; } if ($canedit) { echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; } }