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; ?>";
327 flashMovieSettings: {
328 flashURL: "<?php echo AT_BASE_HREF; ?>jscripts/infusion/lib/swfupload/flash/swfupload.swf",
329 flashButtonImageURL: "<?php echo AT_BASE_HREF; ?>jscripts/infusion/components/uploader/images/browse.png"
336 //bind fluid checkbox
337 jQuery('#fluid_on').bind("click", function() {
338 toggleform('simple-container', 'fluid-container');
339 setCheckboxCookie(this, 'fluid_on=yes', 'fluid_on=no','December 31, 2099');
343 //hide multifile uploader if it's not checked
344 if (!jQuery('#fluid_on').attr('checked')) {
345 jQuery('#fluid-container').hide();
351 if (isset($_COOKIE["fluid_on"]) && $_COOKIE["fluid_on"]=="yes")
352 echo '<div id="simple-container" style="display: none;">';
354 echo '<div id="simple-container">';
356 // Display as regular if there's no Flash detected
357 echo '<div id="simple-container">'."\n";
360 // Simple single file uploader
361 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">';
362 echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$my_MaxFileSize.'" />';
363 echo '<label for="uploadedfile">'._AT('upload_files').'</label><br />'."\n";
364 echo '<input type="file" name="uploadedfile" id="uploadedfile" class="formfield" size="20" /> ';
365 echo '<input type="submit" name="submit" value="'._AT('upload').'" class="button" />';
366 echo '<input type="hidden" name="pathext" value="'.$pathext.'" /> ';
368 if ($popup == TRUE) {
369 echo '<input type="hidden" name="popup" value="1" />';
373 echo ' </div>'."\n".' </fieldset></div>';
375 echo ' </fieldset></div>'."\n";
376 $msg->printInfos('OVER_QUOTA');
380 // Directory and File listing
381 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">';
382 echo '<input type="hidden" name="pathext" value ="'.$pathext.'" />';
384 // display the section to use a remote URL as an alternative
387 <div class="input-form" style="min-height:10px">
388 <fieldset class="group_form" style="min-height: 0px;"><legend class="group_form"><?php echo _AT('use_url_as_alternative'); ?></legend>
390 <input name="remote_alternative" id="remote_alternative" value="http://" size="60" />
391 <input class="button" type="button" name="alternative" value="<?php echo _AT('use_as_alternative'); ?>" onclick="javascript: setURLAlternative();" />
397 <table class="data static" summary="" border="0" rules="groups" style="width: 90%">
405 <th scope="col"><input type="checkbox" name="checkall" onclick="Checkall(checkform);" id="selectall" title="<?php echo _AT('select_all'); ?>" /></th>
407 <th scope="col"><?php echo _AT('name'); ?></th>
408 <th scope="col"><?php echo _AT('date'); ?></th>
409 <th scope="col"><?php echo _AT('size'); ?></th>
414 <td colspan="5"><input type="submit" name="rename" value="<?php echo _AT('rename'); ?>" />
415 <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" />
416 <input type="submit" name="move" value="<?php echo _AT('move'); ?>" /></td>
420 <td colspan="4" align="right"><strong><?php echo _AT('directory_total'); ?>:</strong></td>
421 <td align="right"> <strong><?php echo get_human_size(dirsize($current_path.$pathext.$file.'/')); ?></strong> </td>
425 <td colspan="4" align="right"><strong><?php echo _AT('course_total'); ?>:</strong></td>
426 <td align="right"> <strong><?php echo get_human_size($course_total); ?></strong> </td>
429 <td colspan="4" align="right"><strong><?php echo _AT('course_available'); ?>:</strong></td>
430 <td align="right"><strong><?php
431 if ($my_MaxCourseSize == AT_COURSESIZE_UNLIMITED) {
432 echo _AT('unlimited');
433 } else if ($my_MaxCourseSize == AT_COURSESIZE_DEFAULT) {
434 echo get_human_size($MaxCourseSize-$course_total);
436 echo get_human_size($my_MaxCourseSize-$course_total);
437 } ?></strong> </td>
445 <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>
452 $dir=opendir($current_path);
454 // loop through folder to get files and directory listing
455 while (false !== ($file = readdir($dir)) ) {
457 // if the name is not a directory
458 if( ($file == '.') || ($file == '..') ) {
462 // get some info about the file
463 $filedata = stat($current_path.$pathext.$file);
464 $path_parts = pathinfo($file);
465 $ext = strtolower($path_parts['extension']);
469 // if it is a directory change the file name to a directory link
470 if(is_dir($current_path.$pathext.$file)) {
471 $size = dirsize($current_path.$pathext.$file.'/');
472 $totalBytes += $size;
473 $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>';
474 $fileicon = ' ';
475 $fileicon .= '<img src="images/folder.gif" alt="'._AT('folder').':'.$file.'" height="18" width="20" class="img-size-fm1" />';
476 $fileicon .= ' ';
482 } else if ($ext == 'zip') {
484 $totalBytes += $filedata[7];
486 $fileicon = ' <img src="images/icon-zip.gif" alt="'._AT('zip_archive').':'.$file.'" height="16" width="16" border="0" class="img-size-fm2" /> ';
489 $totalBytes += $filedata[7];
491 $fileicon = ' <img src="images/file_types/'.get_file_type_icon($filename).'.gif" height="16" width="16" alt="" title="" class="img-size-fm2" /> ';
493 $file1 = strtolower($file);
494 // create listing for dirctor or file
497 $dirs[$file1] .= '<tr><td align="center" width="0%">';
498 $dirs[$file1] .= '<input type="checkbox" id="'.$file.'" value="'.$file.'" name="check[]"/></td>';
499 $dirs[$file1] .= '<td align="center"><label for="'.$file.'" >'.$fileicon.'</label></td>';
500 $dirs[$file1] .= '<td > ';
501 $dirs[$file1] .= $filename.'</td>';
502 $dirs[$file1] .= '<td align="right"> ';
503 $dirs[$file1] .= AT_date(_AT('filemanager_date_format'), $filedata[10], AT_DATE_UNIX_TIMESTAMP);
504 $dirs[$file1] .= ' </td>';
505 $dirs[$file1] .= '<td align="right">';
506 $dirs[$file1] .= get_human_size($size).'</td></tr>';
510 $files[$file1] .= '<tr> <td align="center">';
511 $files[$file1] .= '<input type="checkbox" id="'.$file.'" value="'.$file.'" name="check[]"/> </td>';
512 $files[$file1] .= '<td align="center"><label for="'.$file.'">'.$fileicon.'</label></td>';
513 $files[$file1] .= '<td > ';
516 $files[$file1] .= '<a href="'.$get_file.$pathext.urlencode($filename).'">'.$filename.'</a>';
518 $files[$file1] .= '<a href="mods/_core/file_manager/preview.php?file='.$pathext.$filename.SEP.'pathext='.urlencode($pathext).SEP.'popup='.$popup.'">'.$filename.'</a>';
522 $files[$file1] .= ' <a href="mods/_core/file_manager/zip.php?'.(($pathext!='') ? 'pathext='.urlencode($pathext).SEP : ''). 'file=' . urlencode($file) . SEP . 'popup=' . $popup . SEP . 'framed=' . $framed .'">';
523 $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" />';
524 $files[$file1] .= '</a>';
527 if (in_array($ext, $editable_file_types)) {
528 $files[$file1] .= ' <a href="mods/_core/file_manager/edit.php?'.(($pathext!='') ? 'pathext='.urlencode($pathext).SEP : ''). 'popup=' . $popup . SEP . 'framed=' . $framed . SEP . 'file=' . $file . '">';
529 $files[$file1] .= '<img src="images/edit.gif" border="0" alt="'._AT('extract_archive').'" title="'._AT('edit').'" height="15" width="18" class="img-size-fm4" />';
530 $files[$file1] .= '</a>';
533 $files[$file1] .= ' </td>';
535 $files[$file1] .= '<td align="right" style="white-space:nowrap">';
537 if ($popup == TRUE) {
538 if ($a_type > 0) // define content alternative
540 $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.'\');" /> ';
543 $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']. '\');" /> ';
546 $files[$file1] .= AT_date(_AT('filemanager_date_format'), $filedata[10], AT_DATE_UNIX_TIMESTAMP);
547 $files[$file1] .= ' </td>';
549 $files[$file1] .= '<td align="right" style="white-space:nowrap">';
550 $files[$file1] .= get_human_size($filedata[7]).'</td></tr>';
554 // sort listing and output directories
555 if (is_array($dirs)) {
556 ksort($dirs, SORT_STRING);
557 foreach($dirs as $x => $y) {
562 //sort listing and output files
563 if (is_array($files)) {
564 ksort($files, SORT_STRING);
565 foreach($files as $x => $y) {
569 echo '</table></form>';
572 <script type="text/javascript">
574 function insertFile(fileName, pathTo, ext, ed_pref) {
575 // pathTo + fileName should be relative to current path (specified by the Content Package Path)
577 if (ext == "gif" || ext == "jpg" || ext == "jpeg" || ext == "png") {
578 var info = "<?php echo _AT('alternate_text'); ?>";
579 var html = '<img src="' + pathTo+fileName + '" border="0" alt="' + info + '" />';
581 insertLink(html, ed_pref);
582 } else if (ext == "mpg" || ext == "avi" || ext == "wmv" || ext == "mov" || ext == "swf" || ext == "mp3" || ext == "wav" || ext == "ogg" || ext == "mid" ||ext == "flv"|| ext == "mp4") {
583 var html = '[media]'+ pathTo + fileName + '[/media]';
585 insertLink(html, ed_pref);
587 var info = "<?php echo _AT('put_link'); ?>";
588 var html = '<a href="' + pathTo+fileName + '">' + info + '</a>';
590 insertLink(html, ed_pref);
594 function insertLink(html, ed_pref)
596 var isVisual = false;
599 if (typeof window.opener.jQuery("#html_visual_editor:checked").val() !== "undefined") {
604 if (!window.opener || isVisual) {
605 if (!window.opener && window.parent.tinyMCE)
606 window.parent.tinyMCE.execCommand('mceInsertContent', false, html);
608 if (window.opener && window.opener.tinyMCE)
609 window.opener.tinyMCE.execCommand('mceInsertContent', false, html);
611 insertAtCursor(window.opener.document.form.body_text, html);
615 function insertAtCursor(myField, myValue) {
617 if (window.opener.document.selection) {
619 sel = window.opener.document.selection.createRange();
622 //MOZILLA/NETSCAPE support
623 else if (myField.selectionStart || myField.selectionStart == '0') {
624 var startPos = myField.selectionStart;
625 var endPos = myField.selectionEnd;
626 myField.value = myField.value.substring(0, startPos)
628 + myField.value.substring(endPos, myField.value.length);
631 myField.value += myValue;
636 // This function does:
637 // 1. save into db via ajax
638 // 2. set the according field in opener window to the selected file
639 // 3. close file manager itself
640 function setAlternative(file, file_preview_link, cid, pid, a_type) {
641 // HTML encode the name of the secondary resource
642 file = jQuery('<div/>').text(file).html();
644 // save the selected secondary resource into db
645 jQuery.post("<?php echo AT_BASE_HREF; ?>mods/_core/editor/save_alternative.php",
646 {"pid":pid, "a_type":a_type, "alternative":file},
650 <a href="'+file_preview_link+'" title="<?php echo _AT('new_window'); ?>" target="_new">'+file+'</a><br /> \
651 <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'); ?>"> \
652 <img src="<?php echo AT_BASE_HREF; ?>images/home-tests_sm.png" border="0" title="<?php echo _AT('alter'); ?>" alt="<?php echo _AT('alter'); ?>" /> \
654 <a href="#" onclick="removeAlternative(\\\'<?php echo $cp; ?>\\\', '+cid+','+pid+','+a_type+');return false;"> \
655 <img src="<?php echo AT_BASE_HREF; ?>images/icon_delete.gif" border="0" title="<?php echo _AT('remove'); ?>" alt="<?php echo _AT('remove'); ?>" /> \
659 eval("window.opener.document.getElementById(\""+pid+"_"+a_type+"\").innerHTML = '"+link_html+"'");
664 // This function validates the url then call setAlternative()
665 function setURLAlternative() {
666 remote_url = jQuery('#remote_alternative').val();
667 if (remote_url == '' || remote_url == 'http://') {
668 alert("<?php echo _AT('empty_url'); ?>");
671 setAlternative(remote_url, remote_url, '<?php echo $cid; ?>.', '<?php echo $pid; ?>', '<?php echo $a_type; ?>');
674 <?php if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes"): ?>
675 // toggle the view between div object and button
676 function toggleform(id, link) {
677 var obj = document.getElementById(id);
678 var btn = document.getElementById(link);
680 if (obj.style.display == "none") {
682 obj.style.display='';
685 btn.style.display = 'none';
690 obj.style.display='none';
691 btn.style.display = '';
696 function setCheckboxCookie(obj, value1, value2, date)
698 var today = new Date();
699 var the_date = new Date(date);
700 var the_cookie_date = the_date.toGMTString();
701 if (obj.checked==true)
702 var the_cookie = value1 + ";expires=" + the_cookie_date;
704 var the_cookie = value2 + ";expires=" + the_cookie_date;
705 document.cookie = the_cookie;
710 // When uploading a file as an alternative content, set the alternative field in the opener window
711 // and close "file manager" once the upload is successful
712 if ($a_type > 0 && isset($_GET['uploadfile']) && $_GET['uploadfile'] <> '') { ?>
713 function setAlternativeAndClose() {
714 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; ?>');
718 window.onload=setAlternativeAndClose;