Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / mod / resource / type / ims / preview.php
blob5611c4c63ac131c0ab49607d31dad836fe1f41b4
1 <?php
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 = required_param ('directory', PARAM_PATH);
12 $choose = optional_param ('choose', 'id_reference_value', PARAM_FILE);
13 $page = optional_param ('page', 0, PARAM_INT);
15 /// Calculate the path of the IMS CP to be displayed
16 $deploydir = $CFG->repository . '/' . $directory;
18 /// Confirm that the IMS package has been deployed. Hash not generated
19 /// for repository ones.
20 if (!file_exists($deploydir.'/moodle_inx.ser')) {
21 $errortext = "Not Deployed";
22 print_header();
23 print_simple_box_start('center', '60%');
24 echo '<p align="center">'.$errortext.'</p>';
25 print_footer();
26 exit;
29 /// Load serialized IMS CP index to memory only once.
30 if (empty($items)) {
31 if (!$items = ims_load_serialized_file($deploydir.'/moodle_inx.ser')) {
32 error (get_string('errorreadingfile', 'error', 'moodle_inx.ser'));
36 /// fast forward to first non-index page
37 while (empty($items[$page]->href)) $page++;
39 /// Select direction
40 if (get_string('thisdirection') == 'rtl') {
41 $direction = ' dir="rtl"';
42 } else {
43 $direction = ' dir="ltr"';
46 /// Conditional argument to pass to IMS JavaScript. Need to be global to retrieve it from our custom javascript! :-(
47 global $jsarg;
48 $jsarg = 'true';
49 /// Define $CFG->javascript to use our custom javascript. Save the original one to add it from ours. Global too! :-(
50 global $standard_javascript;
51 $standard_javascript = $CFG->javascript; // Save original javascript file
52 $CFG->javascript = $CFG->dirroot.'/mod/resource/type/ims/javascript.php'; //Use our custom IMS javascript code
54 /// The output here
56 /// moodle header
57 print_header();
58 /// content - this produces everything else
60 /// adds side navigation bar if needed. must also adjust width of iframe to accomodate
61 echo "<div id=\"ims-menudiv\">";
62 preview_buttons($directory, $items['title'], $choose);
63 echo preview_ims_generate_toc($items, $directory, 0, $page); echo "</div>";
65 $fullurl = "$CFG->repositorywebroot/$directory/".$items[$page]->href;
66 /// prints iframe filled with $fullurl ;width:".$iframewidth." missing also height=\"420px\"
67 echo "<iframe id=\"ims-contentframe\" name=\"ims-contentframe\" src=\"{$fullurl}\"></iframe>"; //Content frame
68 /// moodle footer
69 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) {
76 global $CFG;
78 $contents = '';
80 /// Configure links behaviour
81 $fullurl = '?directory='.$directory.'&amp;page=';
83 /// Iterate over items to build the menu
84 $currlevel = 0;
85 $currorder = 0;
86 $endlevel = 0;
87 $openlielement = false;
88 foreach ($items as $item) {
89 if (!is_object($item)) {
90 continue;
92 /// Skip pages until we arrive to $page
93 if ($item->id < $page) {
94 continue;
96 /// Arrive to page, we store its level
97 if ($item->id == $page) {
98 $endlevel = $item->level;
99 continue;
101 /// We are after page and inside it (level > endlevel)
102 if ($item->id > $page && $item->level > $endlevel) {
103 /// Start Level
104 if ($item->level > $currlevel) {
105 $contents .= '<ol class="listlevel_'.$item->level.'">';
106 $openlielement = false;
108 /// End Level
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>';
117 /// Add item
118 $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>';
123 } else {
124 $contents .= $item->title;
126 $currlevel = $item->level;
127 $openlielement = true;
128 continue;
130 /// We have reached endlevel, exit
131 if ($item->id > $page && $item->level <= $endlevel) {
132 break;
135 /// Close up to $endlevel
136 for ($i=$currlevel;$i>$endlevel;$i--) {
137 $contents .= '</li>';
138 $contents .= '</ol>';
141 return $contents;
144 function preview_buttons($directory, $name, $choose='') {
145 $strchoose = get_string('choose','resource');
146 $strback = get_string('back','resource');
148 $path = $directory;
149 $arr = explode('/', $directory);
150 array_pop($arr);
151 $directory = implode('/', $arr);
153 <script type="text/javascript">
154 //<![CDATA[
155 function set_value(txt) {
156 opener.document.getElementById('<?php echo $choose ?>').value = txt;
157 window.close();
159 //]]>
160 </script>
161 <?php
162 echo "<div id=\"ims_preview_buttons\" style=\"padding:10px;\">".
163 "(<a href=\"finder.php?directory=$directory&amp;choose=$choose\">$strback</a>) ".
164 "(<a onclick=\"return set_value('#$path')\" href=\"#\">$strchoose</a>)</div>";