3 require_once('../../../../config.php');
4 require_once('../../lib.php');
5 require_once('resource.class.php');
6 require_once('../../../../backup/lib.php');
7 require_once('../../../../lib/filelib.php');
8 require_once('../../../../lib/xmlize.php');
10 require_once('repository_config.php');
12 $directory = required_param ('directory', PARAM_PATH
);
13 $choose = optional_param ('choose', 'id_reference_value', PARAM_FILE
);
14 $page = optional_param ('page', 0, PARAM_INT
);
16 /// Calculate the path of the IMS CP to be displayed
17 $deploydir = $CFG->repository
. '/' . $directory;
19 /// Confirm that the IMS package has been deployed. Hash not generated
20 /// for repository ones.
21 if (!file_exists($deploydir.'/moodle_inx.ser')) {
22 $errortext = "Not Deployed";
24 print_simple_box_start('center', '60%');
25 echo '<p align="center">'.$errortext.'</p>';
30 /// Load serialized IMS CP index to memory only once.
32 if (!$items = ims_load_serialized_file($deploydir.'/moodle_inx.ser')) {
33 error (get_string('errorreadingfile', 'error', 'moodle_inx.ser'));
37 /// fast forward to first non-index page
38 while (empty($items[$page]->href
)) $page++
;
41 if (get_string('thisdirection') == 'rtl') {
42 $direction = ' dir="rtl"';
44 $direction = ' dir="ltr"';
47 /// Conditional argument to pass to IMS JavaScript. Need to be global to retrieve it from our custom javascript! :-(
50 /// Define $CFG->javascript to use our custom javascript. Save the original one to add it from ours. Global too! :-(
51 global $standard_javascript;
52 $standard_javascript = $CFG->javascript
; // Save original javascript file
53 $CFG->javascript
= $CFG->dirroot
.'/mod/resource/type/ims/javascript.php'; //Use our custom IMS javascript code
59 /// content - this produces everything else
61 /// adds side navigation bar if needed. must also adjust width of iframe to accomodate
62 echo "<div id=\"ims-menudiv\">";
63 preview_buttons($directory, $items['title'], $choose);
64 echo preview_ims_generate_toc($items, $directory, 0, $page); echo "</div>";
66 $fullurl = "$CFG->repositorywebroot/$directory/".$items[$page]->href
;
67 /// prints iframe filled with $fullurl ;width:".$iframewidth." missing also height=\"420px\"
68 echo "<iframe id=\"ims-contentframe\" name=\"ims-contentframe\" src=\"{$fullurl}\"></iframe>"; //Content frame
70 echo "</div></div><script type=\"text/javascript\">resizeiframe($jsarg);</script></body></html>";
72 /*** This function will generate the TOC file for the package
73 * from an specified parent to be used in the view of the IMS
75 function preview_ims_generate_toc($items, $directory, $page=0, $selected_page) {
80 /// Configure links behaviour
81 $fullurl = '?directory='.$directory.'&page=';
83 /// Iterate over items to build the menu
87 $openlielement = false;
88 foreach ($items as $item) {
89 if (!is_object($item)) {
92 /// Skip pages until we arrive to $page
93 if ($item->id
< $page) {
96 /// Arrive to page, we store its level
97 if ($item->id
== $page) {
98 $endlevel = $item->level
;
101 /// We are after page and inside it (level > endlevel)
102 if ($item->id
> $page && $item->level
> $endlevel) {
104 if ($item->level
> $currlevel) {
105 $contents .= '<ol class="listlevel_'.$item->level
.'">';
106 $openlielement = false;
109 if ($item->level
< $currlevel) {
110 $contents .= '</li>';
111 $contents .= '</ol>';
113 /// If we have some openlielement, just close it
114 if ($openlielement) {
115 $contents .= '</li>';
119 if (!empty($item->href
)) {
120 if ($item->id
== $selected_page) $contents .= '<div id="ims-toc-selected">';
121 $contents .= '<a href="'.$fullurl.$item->id
.'" target="_parent">'.$item->title
.'</a>';
122 if ($item->id
== $selected_page) $contents .= '</div>';
124 $contents .= $item->title
;
126 $currlevel = $item->level
;
127 $openlielement = true;
130 /// We have reached endlevel, exit
131 if ($item->id
> $page && $item->level
<= $endlevel) {
135 /// Close up to $endlevel
136 for ($i=$currlevel;$i>$endlevel;$i--) {
137 $contents .= '</li>';
138 $contents .= '</ol>';
144 function preview_buttons($directory, $name, $choose='') {
145 $strchoose = get_string('choose','resource');
146 $strback = get_string('back','resource');
149 $arr = explode('/', $directory);
151 $directory = implode('/', $arr);
153 <script type
="text/javascript">
155 function set_value(txt
) {
156 opener
.document
.getElementById('<?php echo $choose ?>').value
= txt
;
162 echo "<div id=\"ims_preview_buttons\" style=\"padding:10px;\">".
163 "(<a href=\"finder.php?directory=$directory&choose=$choose\">$strback</a>) ".
164 "(<a onclick=\"return set_value('#$path')\" href=\"#\">$strchoose</a>)</div>";