2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
15 if (!defined('AT_INCLUDE_PATH')) { exit; }
17 function get_file_extension($file_name) {
18 $ext = pathinfo($file_name);
19 return $ext['extension'];
22 function get_file_type_icon($file_name) {
25 $ext = get_file_extension($file_name);
28 require(AT_INCLUDE_PATH .'lib/mime.inc.php');
31 if (isset($mime[$ext]) && $mime[$ext][1]) {
32 return $mime[$ext][1];
37 function get_relative_path($src, $dest) {
40 } else if (substr($dest, 0, strlen($src)) == $src) {
41 $path = substr($dest, strlen($src) + 1);
43 $depth = substr_count($src, '/');
44 for ($i = 0; $i < $depth + 1; $i++) // $depth+1 because the last '/' is not recorded in content.content_path
52 // get the course total in Bytes
53 $course_total = dirsize($current_path);
55 $framed = intval($_GET['framed']);
56 $popup = intval($_GET['popup']);
58 $cid = intval($_GET['cid']); // content id, used at "adapted content" page, => add/edit alternatives
59 $pid = intval($_GET['pid']); // primary resource id, used at "adapted content" page, => add/edit alternatives
60 $a_type = intval($_GET['a_type']); // alternative_type, used at "adapted content" page, => add/edit alternatives
62 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
63 $get_file = 'get.php/';
65 $get_file = 'content/' . $_SESSION['course_id'] . '/';
69 global $pathext, $framed, $popup, $cp, $cid, $pid, $a_type;
70 echo '<p>'._AT('current_path').' ';
72 if (isset($pathext) && $pathext != '') {
73 echo '<a href="'.$_SERVER['PHP_SELF'].'?popup=' . $popup . SEP . 'framed=' . $framed.SEP . 'cp=' . $cp.SEP . 'cid=' . $cid.SEP . 'pid=' . $pid.SEP . 'a_type=' . $a_type.'">'._AT('home').'</a> ';
81 if ($pathext == '' && isset($_POST['pathext'])) {
83 $pathext = urlencode($_POST['pathext']);
87 $bits = explode('/', $pathext);
89 foreach ($bits as $bit) {
91 $bit_path .= $bit . '/';
94 if ($bit_path == $pathext) {
97 echo '<a href="'.$_SERVER['PHP_SELF'].'?pathext=' . urlencode($bit_path) . SEP . 'popup=' . $popup . SEP . 'framed=' . $framed . SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$cid.SEP.'a_type='.$a_type.'">' . $bit . '</a>';
108 if ($popup == TRUE) {
115 if (TRUE || $framed != TRUE) {
117 if ($_GET['overwrite'] != '') {
118 // get file name, out of the full path
119 $path_parts = pathinfo($current_path.$_GET['overwrite']);
121 if (!file_exists($path_parts['dirname'].'/'.$pathext.$path_parts['basename'])
122 || !file_exists($path_parts['dirname'].'/'.$pathext.substr($path_parts['basename'], 5))) {
123 /* source and/or destination does not exist */
124 $msg->addErrors('CANNOT_OVERWRITE_FILE');
126 @unlink($path_parts['dirname'].'/'.$pathext.substr($path_parts['basename'], 5));
127 $result = @rename($path_parts['dirname'].'/'.$pathext.$path_parts['basename'], $path_parts['dirname'].'/'.$pathext.substr($path_parts['basename'], 5));
130 $msg->addFeedback('FILE_OVERWRITE');
132 $msg->addErrors('CANNOT_OVERWRITE_FILE');
137 // filemanager listing table
138 // make new directory
139 echo '<div class="input-form"><fieldset class="group_form"><legend class="group_form">'._AT('add_file_folder').'</legend>'."\n";
140 echo ' <div class="row">'."\n";
141 echo ' <form name="form1" method="post" action="'.$_SERVER['PHP_SELF'].'?'.(($pathext != '') ? 'pathext='.urlencode($pathext).SEP : ''). 'popup='.$popup.SEP.'cp='.SEP.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$cid.SEP.'a_type='.$a_type.'">'."\n";
143 if ($depth < $MaxDirDepth) {
144 echo ' <label for="dirname">'._AT('create_folder_here').'</label><br />'."\n";
145 echo ' <small class="spacer">'._AT('keep_it_short').'</small><br />'."\n";
146 echo ' <input type="text" name="dirname" id="dirname" size="20" /> '."\n";
147 echo ' <input type="hidden" name="mkdir_value" value="true" /> '."\n";
148 echo ' <input type="submit" name="mkdir" value="'._AT('create_folder').'" class="button" />'."\n";
150 echo _AT('depth_reached')."\n";
153 echo ' <input type="hidden" name="pathext" value="'.$pathext.'" />'."\n";
154 echo ' </form>'."\n";
157 echo ' <div class="row"><hr /></div>'."\n";
159 // If flash is available, provide the option of using Fluid's uploader or the basic uploader
160 if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") {
161 echo '<div class="row">'."\n";
162 if (isset($_COOKIE["fluid_on"]) && $_COOKIE["fluid_on"]=="yes")
163 $fluid_on = 'checked="checked"';
164 echo '(<input type="checkbox" id="fluid_on" name="fluid_on" value="yes" '.$fluid_on.' /> '."\n";
165 echo '<label for="fluid_on" >'._AT('enable_uploader').'</label>)'."\n";
169 echo ' <div class="row" style="float: left;"><input type="button" class="button" name="new_file" value="' . _AT('file_manager_new') . '" onclick="window.location.href=\''.AT_BASE_HREF.'mods/_core/file_manager/new.php?pathext=' . urlencode($pathext) . SEP . 'framed=' . $framed . SEP . 'popup=' . $popup . '\'"/></div>'."\n";
171 $my_MaxCourseSize = $system_courses[$_SESSION['course_id']]['max_quota'];
174 if (($my_MaxCourseSize == AT_COURSESIZE_UNLIMITED)
175 || (($my_MaxCourseSize == AT_COURSESIZE_DEFAULT) && ($course_total < $MaxCourseSize))
176 || ($my_MaxCourseSize-$course_total > 0)) {
177 echo ' <div class="row" style="float: left;">'._AT('OR').'</div>'."\n".' <div class="row" style="float: left;">'."\n";
178 if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") {
180 <div id="uploader-error-container"></div>
181 <div id="fluid-container">
183 <!-- Basic upload controls, used when JavaScript is unavailable -->
184 <form method="post" enctype="multipart/form-data" class="fl-progEnhance-basic">
185 <p>Use the Browse button to add a file, and the Save button to upload it.</p>
186 <input name="fileData" type="file" />
187 <input class="fl-uploader-basic-save" type="submit" value="Save"/>
190 <!-- Uploader container -->
191 <form class="flc-uploader fl-uploader fl-progEnhance-enhanced" method="get" enctype="multipart/form-data">
193 <!-- File Queue, which is split up into two separate tables: one for the header and body -->
194 <table class="fl-uploader-header">
196 <th class="fl-uploader-file-name">File Name</th>
197 <th class="fl-uploader-file-size">Size</th>
198 <th class="fl-uploader-file-actions"></th>
202 <!-- File Queue body, which is the default container for the FileQueueView component -->
203 <table summary="The list of files" class="flc-uploader-queue fl-uploader-queue">
204 <caption>File Upload Queue:</caption>
206 <!-- Template for file row -->
207 <tr class="flc-uploader-file-tmplt flc-uploader-file">
208 <td class="flc-uploader-file-name fl-uploader-file-name">File Name Placeholder</td>
209 <td class="flc-uploader-file-size fl-uploader-file-size">0 KB</td>
210 <td class="fl-uploader-file-actions">
211 <button type="button" class="flc-uploader-file-action" tabindex="-1"></button>
215 <!-- Template for error info row -->
216 <tr class="flc-uploader-file-error-tmplt fl-uploader-file-error">
217 <td colspan="3" class="flc-uploader-file-error"></td>
222 <!-- File progress bar template, used to generate progress bars for each file in the queue -->
223 <div class="flc-uploader-file-progressor-tmplt fl-uploader-file-progress"></div>
225 <!-- Initial instructions -->
226 <div class="flc-uploader-browse-instructions fl-uploader-browse-instructions">
227 Choose <em>Browse files</em> to add files to the queue.
230 <!-- Status footer -->
231 <div class="flc-uploader-queue-footer fl-uploader-queue-footer fl-fix">
232 <div class="flc-uploader-total-progress-text fl-uploader-total-progress-text fl-force-left">
233 Total: 0 files (0 KB)
235 <div class="fl-text-align-right fl-force-right">
236 <span class="flc-uploader-button-browse fl-uploader-browse">
237 <span class="flc-uploader-button-browse-text">Browse files</span>
240 <!-- Total progress bar -->
241 <div class="flc-uploader-total-progress fl-uploader-total-progress-okay"></div>
242 <div class="flc-uploader-errorsPanel fl-uploader-errorsPanel">
243 <div class="fl-uploader-errorsPanel-header"><span class="flc-uploader-errorPanel-header">Warnings:</span></div>
245 <!-- The markup for each error section will be rendered into these containers. -->
246 <div class="flc-uploader-errorPanel-section-fileSize"></div>
247 <div class="flc-uploader-errorPanel-section-numFiles"></div>
249 <!-- Error section template.-->
250 <div class="flc-uploader-errorPanel-section-tmplt fl-uploader-hidden-templates">
251 <div class="flc-uploader-errorPanel-section-title fl-uploader-errorPanel-section-title">
252 x files were too y and were not added to the queue.
255 <div class="flc-uploader-errorPanel-section-details fl-uploader-errorPanel-section-details">
256 <p>The following files were not added:</p>
257 <p class="flc-uploader-errorPanel-section-files">file_1, file_2, file_3, file_4, file_5 </p>
260 <button type="button" class="flc-uploader-errorPanel-section-toggleDetails fl-uploader-errorPanel-section-toggleDetails">Hide this list</button>
261 <button type="button" class="flc-uploader-errorPanel-section-removeButton fl-uploader-errorPanel-section-removeButton">
262 <span class="flc-uploader-erroredButton-text fl-uploader-hidden">Remove error</span>
268 <!-- Upload buttons -->
269 <div class="fl-uploader-buttons">
270 <button type="button" class="flc-uploader-button-pause fl-uploader-button-stop fl-uploader-hidden">Stop Upload</button>
271 <button type="button" class="flc-uploader-button-upload fl-uploader-button-upload fl-uploader-dim">Upload</button>
274 <div class="flc-uploader-status-region fl-offScreen-hidden"></div>
277 <script type="text/javascript">
278 var myUploader = fluid.uploader(".flc-uploader", {
280 uploadURL: '<?php echo AT_BASE_HREF; ?>mods/_core/file_manager/upload.php',
283 postParams: {pathext: '<?php echo $pathext; ?>', type: 'ajax', submit: 'submit'},
284 fileSizeLimit: <?php echo $my_MaxFileSize/1024; ?>
288 event: "onFileSuccess",
291 fileName: "{arguments}.0.name",
292 responseText: "{arguments}.1"
297 event: "onFileError",
300 fileName: "{arguments}.0.name",
301 statusCode: "{arguments}.2",
302 responseText: "{arguments}.3.responseText"
308 onSuccess: function (response){
309 // example assumes that the server code passes the new image URL in the serverData
310 console.log("Success triggered", response);
311 jQuery('#uploader-error-container').html(response.responseText);
313 onError: function(response) {
314 console.log("Error triggered", response);
315 jQuery('#uploader-error-container').html(response.responseText);
317 onUploadStart: function() {
318 jQuery('#uploader-error-container').html("");
320 afterUploadComplete: function () {
321 window.location = "<?php echo AT_BASE_HREF; ?>mods/_core/file_manager/index.php?pathext=<?php echo $pathext; ?>";
326 //bind fluid checkbox
327 jQuery('#fluid_on').bind("click", function() {
328 toggleform('simple-container', 'fluid-container');
329 setCheckboxCookie(this, 'fluid_on=yes', 'fluid_on=no','December 31, 2099');
333 //hide multifile uploader if it's not checked
334 if (!jQuery('#fluid_on').attr('checked')) {
335 jQuery('#fluid-container').hide();
341 if (isset($_COOKIE["fluid_on"]) && $_COOKIE["fluid_on"]=="yes")
342 echo '<div id="simple-container" style="display: none;">';
344 echo '<div id="simple-container">';
346 // Display as regular if there's no Flash detected
347 echo '<div id="simple-container">'."\n";
350 // Simple single file uploader
351 echo '<form onsubmit="openWindow(\''.AT_BASE_HREF.'tools/prog.php\');" name="form1" method="post" action="mods/_core/file_manager/upload.php?popup='.$popup.SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$cid.SEP.'a_type='.$a_type.'" enctype="multipart/form-data">';
352 echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$my_MaxFileSize.'" />';
353 echo '<label for="uploadedfile">'._AT('upload_files').'</label><br />'."\n";
354 echo '<input type="file" name="uploadedfile" id="uploadedfile" class="formfield" size="20" /> ';
355 echo '<input type="submit" name="submit" value="'._AT('upload').'" class="button" />';
356 echo '<input type="hidden" name="pathext" value="'.$pathext.'" /> ';
358 if ($popup == TRUE) {
359 echo '<input type="hidden" name="popup" value="1" />';
363 echo ' </div>'."\n".' </fieldset></div>';
365 echo ' </fieldset></div>'."\n";
366 $msg->printInfos('OVER_QUOTA');
370 // Directory and File listing
371 echo '<form name="checkform" action="'.$_SERVER['PHP_SELF'].'?'.(($pathext!='') ? 'pathext='.urlencode($pathext).SEP : '').'popup='.$popup .SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$cid.SEP.'a_type='.$a_type.'" method="post">';
372 echo '<input type="hidden" name="pathext" value ="'.$pathext.'" />';
374 // display the section to use a remote URL as an alternative
377 <div class="input-form" style="min-height:10px">
378 <fieldset class="group_form" style="min-height: 0px;"><legend class="group_form"><?php echo _AT('use_url_as_alternative'); ?></legend>
380 <input name="remote_alternative" id="remote_alternative" value="http://" size="60" />
381 <input class="button" type="button" name="alternative" value="<?php echo _AT('use_as_alternative'); ?>" onclick="javascript: setURLAlternative();" />
387 <table class="data static" summary="" border="0" rules="groups" style="width: 90%">
395 <th scope="col"><input type="checkbox" name="checkall" onclick="Checkall(checkform);" id="selectall" title="<?php echo _AT('select_all'); ?>" /></th>
397 <th scope="col"><?php echo _AT('name'); ?></th>
398 <th scope="col"><?php echo _AT('date'); ?></th>
399 <th scope="col"><?php echo _AT('size'); ?></th>
404 <td colspan="5"><input type="submit" name="rename" value="<?php echo _AT('rename'); ?>" />
405 <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" />
406 <input type="submit" name="move" value="<?php echo _AT('move'); ?>" /></td>
410 <td colspan="4" align="right"><strong><?php echo _AT('directory_total'); ?>:</strong></td>
411 <td align="right"> <strong><?php echo get_human_size(dirsize($current_path.$pathext.$file.'/')); ?></strong> </td>
415 <td colspan="4" align="right"><strong><?php echo _AT('course_total'); ?>:</strong></td>
416 <td align="right"> <strong><?php echo get_human_size($course_total); ?></strong> </td>
419 <td colspan="4" align="right"><strong><?php echo _AT('course_available'); ?>:</strong></td>
420 <td align="right"><strong><?php
421 if ($my_MaxCourseSize == AT_COURSESIZE_UNLIMITED) {
422 echo _AT('unlimited');
423 } else if ($my_MaxCourseSize == AT_COURSESIZE_DEFAULT) {
424 echo get_human_size($MaxCourseSize-$course_total);
426 echo get_human_size($my_MaxCourseSize-$course_total);
427 } ?></strong> </td>
435 <td colspan="5"><a href="<?php echo $_SERVER['PHP_SELF'].'?back=1'.SEP.'pathext='.$pathext.SEP. 'popup=' . $popup .SEP. 'framed=' . $framed .SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$cid.SEP.'a_type='.$a_type; ?>"><img src="images/arrowicon.gif" border="0" height="11" width="10" alt="" /> <?php echo _AT('back'); ?></a></td>
442 $dir=opendir($current_path);
444 // loop through folder to get files and directory listing
445 while (false !== ($file = readdir($dir)) ) {
447 // if the name is not a directory
448 if( ($file == '.') || ($file == '..') ) {
452 // get some info about the file
453 $filedata = stat($current_path.$pathext.$file);
454 $path_parts = pathinfo($file);
455 $ext = strtolower($path_parts['extension']);
459 // if it is a directory change the file name to a directory link
460 if(is_dir($current_path.$pathext.$file)) {
461 $size = dirsize($current_path.$pathext.$file.'/');
462 $totalBytes += $size;
463 $filename = '<a href="'.$_SERVER['PHP_SELF'].'?pathext='.urlencode($pathext.$file.'/'). SEP . 'popup=' . $popup . SEP . 'framed='. $framed . SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$cid.SEP.'a_type='.$a_type.'">'.$file.'</a>';
464 $fileicon = ' ';
465 $fileicon .= '<img src="images/folder.gif" alt="'._AT('folder').':'.$file.'" height="18" width="20" class="img-size-fm1" />';
466 $fileicon .= ' ';
472 } else if ($ext == 'zip') {
474 $totalBytes += $filedata[7];
476 $fileicon = ' <img src="images/icon-zip.gif" alt="'._AT('zip_archive').':'.$file.'" height="16" width="16" border="0" class="img-size-fm2" /> ';
479 $totalBytes += $filedata[7];
481 $fileicon = ' <img src="images/file_types/'.get_file_type_icon($filename).'.gif" height="16" width="16" alt="" title="" class="img-size-fm2" /> ';
483 $file1 = strtolower($file);
484 // create listing for dirctor or file
487 $dirs[$file1] .= '<tr><td align="center" width="0%">';
488 $dirs[$file1] .= '<input type="checkbox" id="'.$file.'" value="'.$file.'" name="check[]"/></td>';
489 $dirs[$file1] .= '<td align="center"><label for="'.$file.'" >'.$fileicon.'</label></td>';
490 $dirs[$file1] .= '<td > ';
491 $dirs[$file1] .= $filename.'</td>';
492 $dirs[$file1] .= '<td align="right"> ';
493 $dirs[$file1] .= AT_date(_AT('filemanager_date_format'), $filedata[10], AT_DATE_UNIX_TIMESTAMP);
494 $dirs[$file1] .= ' </td>';
495 $dirs[$file1] .= '<td align="right">';
496 $dirs[$file1] .= get_human_size($size).'</td></tr>';
500 $files[$file1] .= '<tr> <td align="center">';
501 $files[$file1] .= '<input type="checkbox" id="'.$file.'" value="'.$file.'" name="check[]"/> </td>';
502 $files[$file1] .= '<td align="center"><label for="'.$file.'">'.$fileicon.'</label></td>';
503 $files[$file1] .= '<td > ';
506 $files[$file1] .= '<a href="'.$get_file.$pathext.urlencode($filename).'">'.$filename.'</a>';
508 $files[$file1] .= '<a href="mods/_core/file_manager/preview.php?file='.$pathext.$filename.SEP.'pathext='.urlencode($pathext).SEP.'popup='.$popup.'">'.$filename.'</a>';
512 $files[$file1] .= ' <a href="mods/_core/file_manager/zip.php?'.(($pathext!='') ? 'pathext='.urlencode($pathext).SEP : ''). 'file=' . urlencode($file) . SEP . 'popup=' . $popup . SEP . 'framed=' . $framed .'">';
513 $files[$file1] .= '<img src="images/archive.gif" border="0" alt="'._AT('extract_archive').'" title="'._AT('extract_archive').'"height="16" width="11" class="img-size-fm3" />';
514 $files[$file1] .= '</a>';
517 if (in_array($ext, $editable_file_types)) {
518 $files[$file1] .= ' <a href="mods/_core/file_manager/edit.php?'.(($pathext!='') ? 'pathext='.urlencode($pathext).SEP : ''). 'popup=' . $popup . SEP . 'framed=' . $framed . SEP . 'file=' . $file . '">';
519 $files[$file1] .= '<img src="images/edit.gif" border="0" alt="'._AT('extract_archive').'" title="'._AT('edit').'" height="15" width="18" class="img-size-fm4" />';
520 $files[$file1] .= '</a>';
523 $files[$file1] .= ' </td>';
525 $files[$file1] .= '<td align="right" style="white-space:nowrap">';
527 if ($popup == TRUE) {
528 if ($a_type > 0) // define content alternative
530 $files[$file1] .= '<input class="button" type="button" name="alternative" value="' ._AT('use_as_alternative') . '" onclick="javascript: setAlternative(\''.get_relative_path($_GET['cp'], $pathext).$file.'\', \''.AT_BASE_HREF.$get_file.$pathext.urlencode($file).'\', \''.$cid.'\', \''.$pid.'\', \''.$a_type.'\');" /> ';
533 $files[$file1] .= '<input class="button" type="button" name="insert" value="' ._AT('insert') . '" onclick="javascript:insertFile(\'' . $file . '\', \'' . get_relative_path($_GET['cp'], $pathext) . '\', \'' . $ext . '\', \'' .$_SESSION['prefs']['PREF_CONTENT_EDITOR']. '\');" /> ';
536 $files[$file1] .= AT_date(_AT('filemanager_date_format'), $filedata[10], AT_DATE_UNIX_TIMESTAMP);
537 $files[$file1] .= ' </td>';
539 $files[$file1] .= '<td align="right" style="white-space:nowrap">';
540 $files[$file1] .= get_human_size($filedata[7]).'</td></tr>';
544 // sort listing and output directories
545 if (is_array($dirs)) {
546 ksort($dirs, SORT_STRING);
547 foreach($dirs as $x => $y) {
552 //sort listing and output files
553 if (is_array($files)) {
554 ksort($files, SORT_STRING);
555 foreach($files as $x => $y) {
559 echo '</table></form>';
562 <script type="text/javascript">
564 function insertFile(fileName, pathTo, ext, ed_pref) {
565 // pathTo + fileName should be relative to current path (specified by the Content Package Path)
567 if (ext == "gif" || ext == "jpg" || ext == "jpeg" || ext == "png") {
568 var info = "<?php echo _AT('alternate_text'); ?>";
569 var html = '<img src="' + pathTo+fileName + '" border="0" alt="' + info + '" />';
571 insertLink(html, ed_pref);
572 } else if (ext == "mpg" || ext == "avi" || ext == "wmv" || ext == "mov" || ext == "swf" || ext == "mp3" || ext == "wav" || ext == "ogg" || ext == "mid" ||ext == "flv"|| ext == "mp4") {
573 var html = '[media]'+ pathTo + fileName + '[/media]';
575 insertLink(html, ed_pref);
577 var info = "<?php echo _AT('put_link'); ?>";
578 var html = '<a href="' + pathTo+fileName + '">' + info + '</a>';
580 insertLink(html, ed_pref);
584 function insertLink(html, ed_pref)
586 var isVisual = false;
589 if (typeof window.opener.jQuery("#html_visual_editor:checked").val() !== "undefined") {
594 if (!window.opener || isVisual) {
595 if (!window.opener && window.parent.tinyMCE)
596 window.parent.tinyMCE.execCommand('mceInsertContent', false, html);
598 if (window.opener && window.opener.tinyMCE)
599 window.opener.tinyMCE.execCommand('mceInsertContent', false, html);
601 insertAtCursor(window.opener.document.form.body_text, html);
605 function insertAtCursor(myField, myValue) {
607 if (window.opener.document.selection) {
609 sel = window.opener.document.selection.createRange();
612 //MOZILLA/NETSCAPE support
613 else if (myField.selectionStart || myField.selectionStart == '0') {
614 var startPos = myField.selectionStart;
615 var endPos = myField.selectionEnd;
616 myField.value = myField.value.substring(0, startPos)
618 + myField.value.substring(endPos, myField.value.length);
621 myField.value += myValue;
626 // This function does:
627 // 1. save into db via ajax
628 // 2. set the according field in opener window to the selected file
629 // 3. close file manager itself
630 function setAlternative(file, file_preview_link, cid, pid, a_type) {
631 // HTML encode the name of the secondary resource
632 file = jQuery('<div/>').text(file).html();
634 // save the selected secondary resource into db
635 jQuery.post("<?php echo AT_BASE_HREF; ?>mods/_core/editor/save_alternative.php",
636 {"pid":pid, "a_type":a_type, "alternative":file},
640 <a href="'+file_preview_link+'" title="<?php echo _AT('new_window'); ?>" target="_new">'+file+'</a><br /> \
641 <a href="#" onclick="ATutor.poptastic(\\\'<?php echo AT_BASE_HREF; ?>mods/_core/file_manager/index.php?framed=1<?php echo SEP; ?>popup=1<?php echo SEP; ?>cp=<?php echo $cp.SEP; ?>cid='+cid+'<?php echo SEP; ?>pid='+pid+'<?php echo SEP; ?>a_type='+a_type+'\\\');return false;" title="<?php echo _AT('new_window'); ?>"> \
642 <img src="<?php echo AT_BASE_HREF; ?>images/home-tests_sm.png" border="0" title="<?php echo _AT('alter'); ?>" alt="<?php echo _AT('alter'); ?>" /> \
644 <a href="#" onclick="removeAlternative(\\\'<?php echo $cp; ?>\\\', '+cid+','+pid+','+a_type+');return false;"> \
645 <img src="<?php echo AT_BASE_HREF; ?>images/icon_delete.gif" border="0" title="<?php echo _AT('remove'); ?>" alt="<?php echo _AT('remove'); ?>" /> \
649 eval("window.opener.document.getElementById(\""+pid+"_"+a_type+"\").innerHTML = '"+link_html+"'");
654 // This function validates the url then call setAlternative()
655 function setURLAlternative() {
656 remote_url = jQuery('#remote_alternative').val();
657 if (remote_url == '' || remote_url == 'http://') {
658 alert("<?php echo _AT('empty_url'); ?>");
661 setAlternative(remote_url, remote_url, '<?php echo $cid; ?>.', '<?php echo $pid; ?>', '<?php echo $a_type; ?>');
664 <?php if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes"): ?>
665 // toggle the view between div object and button
666 function toggleform(id, link) {
667 var obj = document.getElementById(id);
668 var btn = document.getElementById(link);
670 if (obj.style.display == "none") {
672 obj.style.display='';
675 btn.style.display = 'none';
680 obj.style.display='none';
681 btn.style.display = '';
686 function setCheckboxCookie(obj, value1, value2, date)
688 var today = new Date();
689 var the_date = new Date(date);
690 var the_cookie_date = the_date.toGMTString();
691 if (obj.checked==true)
692 var the_cookie = value1 + ";expires=" + the_cookie_date;
694 var the_cookie = value2 + ";expires=" + the_cookie_date;
695 document.cookie = the_cookie;
700 // When uploading a file as an alternative content, set the alternative field in the opener window
701 // and close "file manager" once the upload is successful
702 if ($a_type > 0 && isset($_GET['uploadfile']) && $_GET['uploadfile'] <> '') { ?>
703 function setAlternativeAndClose() {
704 setAlternative('<?php echo get_relative_path($_GET['cp'], $pathext).$_GET['uploadfile']; ?>', '<?php echo AT_BASE_HREF.$get_file.$pathext.urlencode($_GET['uploadfile']); ?>', '<?php echo $cid; ?>', '<?php echo $pid; ?>', '<?php echo $a_type; ?>');
708 window.onload=setAlternativeAndClose;