2 require_once('../../../../config.php');
3 require_once('../../lib.php');
4 require_once('resource.class.php');
5 require_once('../../../../backup/lib.php');
6 require_once('../../../../lib/filelib.php');
7 require_once('../../../../lib/xmlize.php');
9 require_once('repository_config.php');
11 /// Directory to browse, inside repository. Starts on ''.
12 $directory = optional_param ('directory', '', PARAM_PATH
);
13 $choose = optional_param('choose', 'id_reference_value', PARAM_FILE
);
15 /// Get the language strings needed
16 $strdeployall = get_string('deployall','resource');
17 $strpreview = get_string('preview','resource');
18 $strchoose = get_string('choose','resource');
19 $strdeploy = get_string('deploy','resource');
20 $strnotdeployed = get_string('notdeployed','resource');
21 $stremptyfolder = get_string('emptyfolder','resource');
23 /// Print header. Blank, nothing fancy.
28 if (!($repository_dir = opendir("$CFG->repository/$directory"))) die("Can't open directory \"$CFG->repository/$directory\"");
30 /// Loops though dir building a list of all relevent entries. Ignores files.
31 /// Asks for deploy if admin user AND no serialized file found.
32 while (false != ($filename = readdir($repository_dir))) {
33 if ($filename != '.' && $filename != '..' && is_dir("$CFG->repository/$directory/$filename")) {
37 $item->path
= "$directory/$filename";
39 /// No manifest => normal, browsable directory.
40 if (!file_exists("$CFG->repository/$item->path/imsmanifest.xml")) {
41 $item->type
= 'directory';
42 $item->name
= $filename;
44 /// Manifest, so IMS CP.
46 if (file_exists("$CFG->repository/$item->path/moodle_inx.ser")) {
47 $item->type
= 'deployed';
48 $index = ims_load_serialized_file("$CFG->repository/$item->path/moodle_inx.ser");
49 $item->name
= $index['title'];
52 $item->type
= 'not deployed';
53 $item->name
= $filename;
59 closedir($repository_dir);
61 /// Prints the toolbar.
62 echo '<div id="ims_toolbar" style="padding:10px;">';
63 ims_print_crumbtrail($directory, $choose);
65 /// If admin, add extra buttons - redeploy & help.
66 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
67 echo " | (<a href=\"repository_deploy.php?file=$directory&all=force\">$strdeployall</a>) ";
68 helpbutton("deploy", get_string("deployall", "resource"), "resource", true);
72 /// Prints the file list from list generated above.
73 echo '<div id="ims_filelist">';
75 <script type
="text/javascript">
77 function set_value(txt
) {
78 opener
.document
.getElementById('<?php echo $choose ?>').value
= txt
;
84 echo '<ul style="list-style:none;padding:10px;margin:0px;">';
85 if ($items != array()) {
87 foreach ($items as $item) {
88 if ($item->type
== 'deployed') {
89 echo "<li><img src=\"images/ims.gif\" alt=\"IMS CP Package\" /> $item->name" .
90 "(<a onclick=\"return set_value('#$item->path')\" href=\"#\">$strchoose</a>) " .
91 "(<a href=\"preview.php?directory=$item->path&choose=$choose\">$strpreview</a>)</li>\n";
93 else if ($item->type
== 'not deployed') {
94 /// Only displays non-deployed IMS CP's if admin user.
95 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
96 echo "<li><img src=\"images/ims.gif\" alt=\"IMS CP Package\" /> <em>$item->path - $strnotdeployed</em> (<a href=\"repository_deploy.php?file=$item->path\">$strdeploy</a>)</li>\n";
99 else if ($item->type
== 'directory') {
100 echo "<li><img src=\"images/dir.gif\" alt=\"IMS CP Package\" /> <a href=\"?directory=$item->path&choose=$choose\">$item->name</a></li>\n";
105 echo "<li><em>$stremptyfolder</em></li>";
109 /// Print footer and exit.
110 echo "</div></div></div></body></html>";
113 /// Generates the crumbtrial from $directory. Just splits up on '/'.
114 function ims_print_crumbtrail($directory, $choose='') {
115 $strrepository = get_string('repository','resource');
117 $arr = explode('/', $directory);
118 $last = array_pop($arr);
119 if (trim($directory, '/') == '') {
124 $output = "<a href=\"?directory=&choose=$choose\">$strrepository</a> » ";
127 foreach ($arr as $item) {
128 if ($item == '') continue;
129 $itemdir .= '/'.$item;
130 $output .= "<a href=\"?directory=$itemdir&choose=$choose\">$item</a> » ";