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
);
14 $name = optional_param('name', 'id_name', PARAM_FILE
);
16 /// Get the language strings needed
17 $strdeployall = get_string('deployall','resource');
18 $strpreview = get_string('preview','resource');
19 $strchoose = get_string('choose','resource');
20 $strdeploy = get_string('deploy','resource');
21 $strnotdeployed = get_string('notdeployed','resource');
22 $stremptyfolder = get_string('emptyfolder','resource');
24 /// Print header. Blank, nothing fancy.
29 if (!($repository_dir = opendir("$CFG->repository/$directory"))) die("Can't open directory \"$CFG->repository/$directory\"");
31 /// Loops though dir building a list of all relevent entries. Ignores files.
32 /// Asks for deploy if admin user AND no serialized file found.
33 while (false !== ($filename = readdir($repository_dir))) {
34 if ($filename != '.' && $filename != '..' && is_dir("$CFG->repository/$directory/$filename")) {
38 $item->path
= "$directory/$filename";
40 /// No manifest => normal, browsable directory.
41 if (!file_exists("$CFG->repository/$item->path/imsmanifest.xml")) {
42 $item->type
= 'directory';
43 $item->name
= $filename;
45 /// Manifest, so IMS CP.
47 if (file_exists("$CFG->repository/$item->path/moodle_inx.ser")) {
48 $item->type
= 'deployed';
49 $index = ims_load_serialized_file("$CFG->repository/$item->path/moodle_inx.ser");
50 $item->name
= $index['title'];
53 $item->type
= 'not deployed';
54 $item->name
= $filename;
60 closedir($repository_dir);
62 /// Prints the toolbar.
63 echo '<div id="ims_toolbar" style="padding:10px;">';
64 ims_print_crumbtrail($directory, $choose);
66 /// If admin, add extra buttons - redeploy & help.
67 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
))) {
68 echo " | (<a href=\"repository_deploy.php?file=$directory&all=force\">$strdeployall</a>) ";
69 helpbutton("deploy", get_string("deployall", "resource"), "resource", true);
73 /// Prints the file list from list generated above.
74 echo '<div id="ims_filelist">';
76 <script type
="text/javascript">
78 function set_opener_value(field
, txt
, force
) {
79 if (opener
.document
.getElementById(field
)) {
80 if (force ||
!opener
.document
.getElementById(field
).value
) {
81 opener
.document
.getElementById(field
).value
= txt
;
88 echo '<ul style="list-style:none;padding:10px;margin:0px;">';
89 if ($items != array()) {
91 foreach ($items as $item) {
92 if ($item->type
== 'deployed') {
93 echo "<li><img src=\"images/ims.gif\" alt=\"IMS CP Package\" /> $item->name" .
94 "(<a onclick=\"set_opener_value('$choose', '#$item->path', true); set_opener_value('$name', '$item->name', false); window.close()\" href=\"#\">$strchoose</a>) " .
95 "(<a href=\"preview.php?directory=$item->path&choose=$choose\">$strpreview</a>)</li>\n";
97 else if ($item->type
== 'not deployed') {
98 /// Only displays non-deployed IMS CP's if admin user.
99 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
))) {
100 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";
103 else if ($item->type
== 'directory') {
104 echo "<li><img src=\"images/dir.gif\" alt=\"IMS CP Package\" /> <a href=\"?directory=$item->path&choose=$choose\">$item->name</a></li>\n";
109 echo "<li><em>$stremptyfolder</em></li>";
113 /// Print footer and exit.
114 echo "</div></div></div></body></html>";
117 /// Generates the crumbtrial from $directory. Just splits up on '/'.
118 function ims_print_crumbtrail($directory, $choose='') {
119 $strrepository = get_string('repository','resource');
121 $arr = explode('/', $directory);
122 $last = array_pop($arr);
123 if (trim($directory, '/') == '') {
128 $output = "<a href=\"?directory=&choose=$choose\">$strrepository</a> » ";
131 foreach ($arr as $item) {
132 if ($item == '') continue;
133 $itemdir .= '/'.$item;
134 $output .= "<a href=\"?directory=$itemdir&choose=$choose\">$item</a> » ";