2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
13 if (!defined('TR_INCLUDE_PATH')) { exit; }
14 require_once(TR_INCLUDE_PATH.'classes/DAO/CoursesDAO.class.php');
16 global $_course_id, $MaxCourseSize, $_content_id;
18 $editable_file_types = array('txt', 'html', 'htm', 'xml', 'css', 'asc', 'csv', 'sql');
19 $_SESSION['prefs']['PREF_CONTENT_EDITOR'] = 1;
21 $coursesDAO = new CoursesDAO();
23 function get_file_extension($file_name) {
24 $ext = pathinfo($file_name);
25 return $ext['extension'];
28 function get_file_type_icon($file_name) {
31 $ext = get_file_extension($file_name);
34 require(TR_INCLUDE_PATH .'lib/mime.inc.php');
37 if (isset($mime[$ext]) && $mime[$ext][1]) {
38 return $mime[$ext][1];
43 function get_relative_path($src, $dest) {
46 } else if (substr($dest, 0, strlen($src)) == $src) {
47 $path = substr($dest, strlen($src) + 1);
49 $depth = substr_count($src, '/');
50 for ($i = 0; $i < $depth + 1; $i++) // $depth+1 because the last '/' is not recorded in content.content_path
58 // get the course total in Bytes
59 $course_total = FileUtility::dirsize($current_path);
61 $framed = intval($_GET['framed']);
62 $popup = intval($_GET['popup']);
64 $cid = $_content_id; // content id, used at "adapted content" page, => add/edit alternatives
65 $pid = intval($_GET['pid']); // primary resource id, used at "adapted content" page, => add/edit alternatives
66 $a_type = intval($_GET['a_type']); // alternative_type, used at "adapted content" page, => add/edit alternatives
68 if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) {
69 $get_file = 'get.php/';
71 $get_file = 'content/' . $_course_id . '/';
75 global $pathext, $framed, $popup, $cp, $cid, $pid, $a_type, $_course_id;
76 echo '<p>'._AT('current_path').' ';
78 if (isset($pathext) && $pathext != '') {
79 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.SEP.'_course_id='.$_course_id.'">'._AT('home').'</a> ';
87 if ($pathext == '' && isset($_POST['pathext'])) {
89 $pathext = urlencode($_POST['pathext']);
93 $bits = explode('/', $pathext);
95 foreach ($bits as $bit) {
97 $bit_path .= $bit . '/';
100 if ($bit_path == $pathext) {
103 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.SEP.'_course_id='.$_course_id.'">' . $bit . '</a>';
114 if ($popup == TRUE) {
121 if (TRUE || $framed != TRUE) {
124 if ($_GET['overwrite'] != '') {
125 // get file name, out of the full path
126 $path_parts = pathinfo($current_path.$_GET['overwrite']);
128 if (!file_exists($path_parts['dirname'].'/'.$pathext.$path_parts['basename'])
129 || !file_exists($path_parts['dirname'].'/'.$pathext.substr($path_parts['basename'], 5))) {
130 /* source and/or destination does not exist */
131 $msg->addErrors('CANNOT_OVERWRITE_FILE');
133 @unlink($path_parts['dirname'].'/'.$pathext.substr($path_parts['basename'], 5));
134 $result = @rename($path_parts['dirname'].'/'.$pathext.$path_parts['basename'], $path_parts['dirname'].'/'.$pathext.substr($path_parts['basename'], 5));
137 $msg->addFeedback('FILE_OVERWRITE');
139 $msg->addErrors('CANNOT_OVERWRITE_FILE');
144 // filemanager listing table
145 // make new directory
146 echo '<div class="input-form"><fieldset class="group_form"><legend class="group_form">'._AT('add_file_folder').'</legend>'."\n";
147 echo ' <div class="row">'."\n";
148 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";
150 if ($depth < $MaxDirDepth) {
151 echo ' <label for="dirname">'._AT('create_folder_here').'</label><br />'."\n";
152 echo ' <small class="spacer">'._AT('keep_it_short').'</small><br />'."\n";
153 echo ' <input type="text" name="dirname" id="dirname" size="20" /> '."\n";
154 echo ' <input type="hidden" name="mkdir_value" value="true" /> '."\n";
155 echo ' <input type="submit" name="mkdir" value="'._AT('create_folder').'" class="button" />'."\n";
157 echo _AT('depth_reached')."\n";
160 echo ' <input type="hidden" name="pathext" value="'.$pathext.'" />'."\n";
161 echo ' </form>'."\n";
164 echo ' <div class="row"><hr /></div>'."\n";
166 // If flash is available, provide the option of using Fluid's uploader or the basic uploader
167 if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") {
168 echo '<div class="row">'."\n";
169 if (isset($_COOKIE["fluid_on"]) && $_COOKIE["fluid_on"]=="yes")
170 $fluid_on = 'checked="checked"';
171 echo '(<input type="checkbox" id="fluid_on" name="fluid_on" value="yes" '.$fluid_on.' /> '."\n";
172 echo '<label for="fluid_on" >'._AT('enable_uploader').'</label>)'."\n";
176 echo ' <div class="row" style="float: left;"><input type="button" class="button" name="new_file" value="' . _AT('file_manager_new') . '" onclick="window.location.href=\''.TR_BASE_HREF.'file_manager/new.php?pathext=' . urlencode($pathext) . SEP . 'framed=' . $framed . SEP . 'popup=' . $popup . SEP.'_course_id='.$_course_id. '\'"/></div>'."\n";
178 $course_row = $coursesDAO->get($_course_id);
179 if ($course_row['max_quota'] == '' || is_null($course_row['max_quota']))
180 $my_MaxCourseSize = $MaxCourseSize;
183 if ($course_row['max_quota'] == TR_COURSESIZE_UNLIMITED || $my_MaxCourseSize-$course_total > 0) {
184 echo ' <div class="row" style="float: left;">'._AT('OR').'</div>'."\n".' <div class="row" style="float: left;">'."\n";
185 if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") {
187 <div id="uploader-error-container"></div>
188 <div id="fluid-container">
190 <!-- Basic upload controls, used when JavaScript is unavailable -->
191 <form method="post" enctype="multipart/form-data" class="fl-progEnhance-basic">
192 <p>Use the Browse button to add a file, and the Save button to upload it.</p>
193 <input name="fileData" type="file" />
194 <input type="hidden" name="_course_id" value ="<?php echo $_course_id; ?>" />
195 <input class="fl-uploader-basic-save" type="submit" value="Save"/>
198 <!-- Uploader container -->
199 <form class="flc-uploader fl-uploader fl-progEnhance-enhanced" method="get" enctype="multipart/form-data">
201 <!-- File Queue, which is split up into two separate tables: one for the header and body -->
202 <table class="fl-uploader-header">
204 <th class="fl-uploader-file-name">File Name</th>
205 <th class="fl-uploader-file-size">Size</th>
206 <th class="fl-uploader-file-actions"></th>
210 <!-- File Queue body, which is the default container for the FileQueueView component -->
211 <table summary="The list of files" class="flc-uploader-queue fl-uploader-queue">
212 <caption>File Upload Queue:</caption>
214 <!-- Template for file row -->
215 <tr class="flc-uploader-file-tmplt flc-uploader-file">
216 <td class="flc-uploader-file-name fl-uploader-file-name">File Name Placeholder</td>
217 <td class="flc-uploader-file-size fl-uploader-file-size">0 KB</td>
218 <td class="fl-uploader-file-actions">
219 <button type="button" class="flc-uploader-file-action" tabindex="-1"></button>
223 <!-- Template for error info row -->
224 <tr class="flc-uploader-file-error-tmplt fl-uploader-file-error">
225 <td colspan="3" class="flc-uploader-file-error"></td>
230 <!-- File progress bar template, used to generate progress bars for each file in the queue -->
231 <div class="flc-uploader-file-progressor-tmplt fl-uploader-file-progress"></div>
233 <!-- Initial instructions -->
234 <div class="flc-uploader-browse-instructions fl-uploader-browse-instructions">
235 Choose <em>Browse files</em> to add files to the queue.
238 <!-- Status footer -->
239 <div class="flc-uploader-queue-footer fl-uploader-queue-footer fl-fix">
240 <div class="flc-uploader-total-progress-text fl-uploader-total-progress-text fl-force-left">
241 Total: 0 files (0 KB)
243 <div class="fl-text-align-right fl-force-right">
244 <span class="flc-uploader-button-browse fl-uploader-browse">
245 <span class="flc-uploader-button-browse-text">Browse files</span>
248 <!-- Total progress bar -->
249 <div class="flc-uploader-total-progress fl-uploader-total-progress-okay"></div>
250 <div class="flc-uploader-errorsPanel fl-uploader-errorsPanel">
251 <div class="fl-uploader-errorsPanel-header"><span class="flc-uploader-errorPanel-header">Warnings:</span></div>
253 <!-- The markup for each error section will be rendered into these containers. -->
254 <div class="flc-uploader-errorPanel-section-fileSize"></div>
255 <div class="flc-uploader-errorPanel-section-numFiles"></div>
257 <!-- Error section template.-->
258 <div class="flc-uploader-errorPanel-section-tmplt fl-uploader-hidden-templates">
259 <div class="flc-uploader-errorPanel-section-title fl-uploader-errorPanel-section-title">
260 x files were too y and were not added to the queue.
263 <div class="flc-uploader-errorPanel-section-details fl-uploader-errorPanel-section-details">
264 <p>The following files were not added:</p>
265 <p class="flc-uploader-errorPanel-section-files">file_1, file_2, file_3, file_4, file_5 </p>
268 <button type="button" class="flc-uploader-errorPanel-section-toggleDetails fl-uploader-errorPanel-section-toggleDetails">Hide this list</button>
269 <button type="button" class="flc-uploader-errorPanel-section-removeButton fl-uploader-errorPanel-section-removeButton">
270 <span class="flc-uploader-erroredButton-text fl-uploader-hidden">Remove error</span>
276 <!-- Upload buttons -->
277 <div class="fl-uploader-buttons">
278 <button type="button" class="flc-uploader-button-pause fl-uploader-button-stop fl-uploader-hidden">Stop Upload</button>
279 <button type="button" class="flc-uploader-button-upload fl-uploader-button-upload fl-uploader-dim">Upload</button>
282 <div class="flc-uploader-status-region fl-offScreen-hidden"></div>
285 <script type="text/javascript">
286 var myUploader = fluid.uploader(".flc-uploader", {
288 uploadURL: '<?php echo TR_BASE_HREF; ?>file_manager/upload.php',
291 postParams: {pathext: '<?php echo $pathext; ?>', type: 'ajax', submit: 'submit', _course_id: '<?php echo $_course_id; ?>'},
292 fileSizeLimit: <?php echo $my_MaxCourseSize/1024; ?>
296 event: "onFileSuccess",
299 fileName: "{arguments}.0.name",
300 responseText: "{arguments}.1"
305 event: "onFileError",
308 fileName: "{arguments}.0.name",
309 statusCode: "{arguments}.2",
310 responseText: "{arguments}.3.responseText"
316 onSuccess: function (response){
317 // example assumes that the server code passes the new image URL in the serverData
318 console.log("Success triggered", response);
319 jQuery('#uploader-error-container').html(response.responseText);
321 onError: function(response) {
322 console.log("Error triggered", response);
323 jQuery('#uploader-error-container').html(response.responseText);
325 onUploadStart: function() {
326 jQuery('#uploader-error-container').html("");
328 afterUploadComplete: function () {
329 window.location = "<?php echo TR_BASE_HREF . 'file_manager/index.php?popup='.$popup.SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$cid.SEP.'a_type='.$a_type.SEP.'_course_id='.$_course_id; ?>"
335 flashMovieSettings: {
336 flashURL: "<?php echo TR_BASE_HREF; ?>include/jscripts/infusion/lib/swfupload/flash/swfupload.swf",
337 flashButtonImageURL: "<?php echo TR_BASE_HREF; ?>include/jscripts/infusion/components/uploader/images/browse.png"
344 //bind fluid checkbox
345 jQuery('#fluid_on').bind("click", function() {
346 toggleform('simple-container', 'fluid-container');
347 setCheckboxCookie(this, 'fluid_on=yes', 'fluid_on=no','December 31, 2099');
351 //hide multifile uploader if it's not checked
352 if (!jQuery('#fluid_on').attr('checked')) {
353 jQuery('#fluid-container').hide();
359 if (isset($_COOKIE["fluid_on"]) && $_COOKIE["fluid_on"]=="yes")
360 echo '<div id="simple-container" style="display: none;">';
362 echo '<div id="simple-container">';
364 // Display as regular if there's no Flash detected
365 echo '<div id="simple-container">'."\n";
368 // Simple single file uploader
369 echo '<form onsubmit="openWindow(\''.TR_BASE_HREF.'home/prog.php\');" name="form1" method="post" action="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">';
370 echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$my_MaxFileSize.'" />';
372 echo '<label for="uploadedfile">'._AT('upload_files').'</label><br />'."\n";
373 echo '<input type="file" name="uploadedfile" id="uploadedfile" class="formfield" size="20" /> ';
374 echo '<input type="submit" name="submit" value="'._AT('upload').'" class="button" />';
375 echo '<input type="hidden" name="_course_id" value ="'.$_course_id.'" />';
376 echo '<input type="hidden" name="pathext" value="'.$pathext.'" /> ';
378 if ($popup == TRUE) {
379 echo '<input type="hidden" name="popup" value="1" />';
383 echo ' </div>'."\n".' </fieldset></div>';
385 echo ' </fieldset></div>'."\n";
386 $msg->printInfos('OVER_QUOTA');
391 // Directory and File listing
392 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">';
393 echo '<input type="hidden" name="pathext" value ="'.$pathext.'" />';
394 echo '<input type="hidden" name="_course_id" value ="'.$_course_id.'" />';
395 if ($cid > 0) echo '<input type="hidden" name="_cid" value ="'.$cid.'" />';
397 // display the section to use a remote URL as an alternative
400 <div class="input-form" style="min-height:10px">
401 <fieldset class="group_form" style="min-height: 0px;"><legend class="group_form"><?php echo _AT('use_url_as_alternative'); ?></legend>
403 <input name="remote_alternative" id="remote_alternative" value="http://" size="60" />
404 <input class="button" type="button" name="alternative" value="<?php echo _AT('use_as_alternative'); ?>" onclick="javascript: setURLAlternative();" />
410 <table class="data static" summary="" border="0" rules="groups" style="width: 90%">
418 <th scope="col"><input type="checkbox" name="checkall" onclick="Checkall(checkform);" id="selectall" title="<?php echo _AT('select_all'); ?>" /></th>
420 <th scope="col"><?php echo _AT('name'); ?></th>
421 <th scope="col"><?php echo _AT('date'); ?></th>
422 <th scope="col"><?php echo _AT('size'); ?></th>
427 <td colspan="5"><input type="submit" name="rename" value="<?php echo _AT('rename'); ?>" />
428 <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" />
429 <input type="submit" name="move" value="<?php echo _AT('move'); ?>" /></td>
433 <td colspan="4" align="right"><strong><?php echo _AT('directory_total'); ?>:</strong></td>
434 <td align="right"> <strong><?php echo FileUtility::get_human_size(FileUtility::dirsize($current_path.$pathext.$file.'/')); ?></strong> </td>
438 <td colspan="4" align="right"><strong><?php echo _AT('course_total'); ?>:</strong></td>
439 <td align="right"> <strong><?php echo FileUtility::get_human_size($course_total); ?></strong> </td>
442 <td colspan="4" align="right"><strong><?php echo _AT('course_available'); ?>:</strong></td>
443 <td align="right"><strong><?php
444 if ($my_MaxCourseSize == TR_COURSESIZE_UNLIMITED) {
445 echo _AT('unlimited');
446 } else if ($my_MaxCourseSize == TR_COURSESIZE_DEFAULT) {
447 echo FileUtility::get_human_size($MaxCourseSize-$course_total);
449 echo FileUtility::get_human_size($my_MaxCourseSize-$course_total);
450 } ?></strong> </td>
458 <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.SEP.'_course_id='.$_course_id; ?>"><img src="images/arrowicon.gif" border="0" height="11" width="10" alt="" /> <?php echo _AT('back'); ?></a></td>
465 $dir=opendir($current_path);
467 // loop through folder to get files and directory listing
468 while (false !== ($file = readdir($dir)) ) {
470 // if the name is not a directory
471 if( ($file == '.') || ($file == '..') ) {
475 // get some info about the file
476 $filedata = stat($current_path.$pathext.$file);
477 $path_parts = pathinfo($file);
478 $ext = strtolower($path_parts['extension']);
482 // if it is a directory change the file name to a directory link
483 if(is_dir($current_path.$pathext.$file)) {
484 $size = FileUtility::dirsize($current_path.$pathext.$file.'/');
485 $totalBytes += $size;
486 $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.SEP.'_course_id='.$_course_id.'">'.$file.'</a>';
487 $fileicon = ' ';
488 $fileicon .= '<img src="images/folder.gif" alt="'._AT('folder').':'.$file.'" height="18" width="20" class="img-size-fm1" />';
489 $fileicon .= ' ';
495 } else if ($ext == 'zip') {
497 $totalBytes += $filedata[7];
499 $fileicon = ' <img src="images/icon-zip.gif" alt="'._AT('zip_archive').':'.$file.'" height="16" width="16" border="0" class="img-size-fm2" /> ';
502 $totalBytes += $filedata[7];
504 $fileicon = ' <img src="images/file_types/'.get_file_type_icon($filename).'.gif" height="16" width="16" alt="" title="" class="img-size-fm2" /> ';
506 $file1 = strtolower($file);
507 // create listing for dirctor or file
510 $dirs[$file1] .= '<tr><td align="center" width="0%">';
511 $dirs[$file1] .= '<input type="checkbox" id="'.$file.'" value="'.$file.'" name="check[]"/></td>';
512 $dirs[$file1] .= '<td align="center"><label for="'.$file.'" >'.$fileicon.'</label></td>';
513 $dirs[$file1] .= '<td > ';
514 $dirs[$file1] .= $filename.'</td>';
515 $dirs[$file1] .= '<td align="right"> ';
516 $dirs[$file1] .= AT_date(_AT('filemanager_date_format'), $filedata[10], TR_DATE_UNIX_TIMESTAMP);
517 $dirs[$file1] .= ' </td>';
518 $dirs[$file1] .= '<td align="right">';
519 $dirs[$file1] .= FileUtility::get_human_size($size).'</td></tr>';
523 $files[$file1] .= '<tr> <td align="center">';
524 $files[$file1] .= '<input type="checkbox" id="'.$file.'" value="'.$file.'" name="check[]"/> </td>';
525 $files[$file1] .= '<td align="center"><label for="'.$file.'">'.$fileicon.'</label></td>';
526 $files[$file1] .= '<td > ';
529 $files[$file1] .= '<a href="'.$get_file.$pathext.urlencode($filename).'">'.$filename.'</a>';
531 $files[$file1] .= '<a href="file_manager/preview.php?file='.$pathext.$filename.SEP.'pathext='.urlencode($pathext).SEP.'popup='.$popup.SEP.'_course_id='.$_course_id.'">'.$filename.'</a>';
535 $files[$file1] .= ' <a href="file_manager/zip.php?'.(($pathext!='') ? 'pathext='.urlencode($pathext).SEP : ''). 'file=' . urlencode($file) . SEP . 'popup=' . $popup . SEP . 'framed=' . $framed .SEP.'_course_id='.$_course_id.'">';
536 $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" />';
537 $files[$file1] .= '</a>';
540 if (in_array($ext, $editable_file_types)) {
541 $files[$file1] .= ' <a href="file_manager/edit.php?'.(($pathext!='') ? 'pathext='.urlencode($pathext).SEP : ''). 'popup=' . $popup . SEP . 'framed=' . $framed . SEP.'_course_id='.$_course_id. SEP . 'file=' . urlencode($file) . '">';
542 $files[$file1] .= '<img src="images/edit.gif" border="0" alt="'._AT('edit').'" title="'._AT('edit').'" height="15" width="18" class="img-size-fm4" />';
543 $files[$file1] .= '</a>';
546 $files[$file1] .= ' </td>';
548 $files[$file1] .= '<td align="right" style="white-space:nowrap">';
550 if ($popup == TRUE) {
551 if ($a_type > 0) // define content alternative
553 $files[$file1] .= '<input class="button" type="button" name="alternative" value="' ._AT('use_as_alternative') . '" onclick="javascript: setAlternative(\''.get_relative_path($_GET['cp'], $pathext).$file.'\', \''.TR_BASE_HREF.$get_file.$pathext.urlencode($file).'\', \''.$cid.'\', \''.$pid.'\', \''.$a_type.'\');" /> ';
556 $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']. '\');" /> ';
559 $files[$file1] .= AT_date(_AT('filemanager_date_format'), $filedata[10], TR_DATE_UNIX_TIMESTAMP);
560 $files[$file1] .= ' </td>';
562 $files[$file1] .= '<td align="right" style="white-space:nowrap">';
563 $files[$file1] .= FileUtility::get_human_size($filedata[7]).'</td></tr>';
567 // sort listing and output directories
568 if (is_array($dirs)) {
569 ksort($dirs, SORT_STRING);
570 foreach($dirs as $x => $y) {
575 //sort listing and output files
576 if (is_array($files)) {
577 ksort($files, SORT_STRING);
578 foreach($files as $x => $y) {
583 echo '</table></form>';
586 <script type="text/javascript">
588 function insertFile(fileName, pathTo, ext, ed_pref) {
589 // pathTo + fileName should be relative to current path (specified by the Content Package Path)
590 if (ext == "gif" || ext == "jpg" || ext == "jpeg" || ext == "png") {
591 var info = "<?php echo _AT('alternate_text'); ?>";
592 var html = '<img src="' + pathTo+fileName + '" border="0" alt="' + info + '" />';
593 } else if (ext == "mpg" || ext == "avi" || ext == "wmv" || ext == "mov" || ext == "swf" || ext == "mp3" || ext == "wav" || ext == "ogg" || ext == "mid" ||ext == "flv"|| ext == "mp4") {
594 var html = '[media]'+ pathTo + fileName + '[/media]';
596 var info = "<?php echo _AT('put_link'); ?>";
597 var html = '<a href="' + pathTo+fileName + '">' + info + '</a>';
600 // insertLink(html, ed_pref);
603 //function insertLink(html, ed_pref)
604 function insertLink(html)
606 // if (window.opener) {
607 // var isNotVisual = window.opener.document.form.html.checked;
610 if (!window.opener || $('#html:checked').val() !== null) {
611 if (!window.opener && window.parent.tinyMCE)
612 window.parent.tinyMCE.execCommand('mceInsertContent', false, html);
614 if (window.opener && window.opener.tinyMCE)
615 window.opener.tinyMCE.execCommand('mceInsertContent', false, html);
617 insertAtCursor(window.opener.document.form.body_text, html);
621 function insertAtCursor(myField, myValue) {
623 if (window.opener.document.selection) {
625 sel = window.opener.document.selection.createRange();
628 //MOZILLA/NETSCAPE support
629 else if (myField.selectionStart || myField.selectionStart == '0') {
630 var startPos = myField.selectionStart;
631 var endPos = myField.selectionEnd;
632 myField.value = myField.value.substring(0, startPos)
634 + myField.value.substring(endPos, myField.value.length);
637 myField.value += myValue;
642 // This function does:
643 // 1. save into db via ajax
644 // 2. set the according field in opener window to the selected file
645 // 3. close file manager itself
646 function setAlternative(file, file_preview_link, cid, pid, a_type) {
647 jQuery.post("<?php echo TR_BASE_HREF; ?>home/editor/save_alternative.php",
648 {"pid":pid, "a_type":a_type, "alternative":file},
652 <a href="'+file_preview_link+'" title="<?php echo _AT('new_window'); ?>" target="_new">'+file+'</a><br /> \
653 <a href="#" onclick="trans.utility.poptastic(\\\'<?php echo TR_BASE_HREF; ?>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'); ?>"> \
654 <img src="<?php echo TR_BASE_HREF; ?>images/alter.png" border="0" title="<?php echo _AT('alter'); ?>" alt="<?php echo _AT('alter'); ?>" /> \
656 <a href="#" onclick="removeAlternative(\\\'<?php echo $cp; ?>\\\', '+cid+','+pid+','+a_type+');return false;"> \
657 <img src="<?php echo TR_BASE_HREF; ?>images/remove.gif" border="0" title="<?php echo _AT('remove'); ?>" alt="<?php echo _AT('remove'); ?>" /> \
661 eval("window.opener.document.getElementById(\""+pid+"_"+a_type+"\").innerHTML = '"+link_html+"'");
666 // This function validates the url then call setAlternative()
667 function setURLAlternative() {
668 remote_url = jQuery('#remote_alternative').val();
669 if (remote_url == '' || remote_url == 'http://') {
670 alert("<?php echo _AT('empty_url'); ?>");
673 setAlternative(remote_url, remote_url, '<?php echo $cid; ?>.', '<?php echo $pid; ?>', '<?php echo $a_type; ?>');
676 <?php if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") { ?>
678 function setCheckboxCookie(obj, value1, value2, date)
680 var today = new Date();
681 var the_date = new Date(date);
682 var the_cookie_date = the_date.toGMTString();
683 if (obj.checked==true)
684 var the_cookie = value1 + ";expires=" + the_cookie_date;
686 var the_cookie = value2 + ";expires=" + the_cookie_date;
687 document.cookie = the_cookie;
690 // toggle the view between div object and button
691 function toggleform(id, link) {
692 var obj = document.getElementById(id);
693 var btn = document.getElementById(link);
695 if (obj.style.display == "none") {
697 obj.style.display='';
700 btn.style.display = 'none';
705 obj.style.display='none';
706 btn.style.display = '';
712 // When uploading a file as an alternative content, set the alternative field in the opener window
713 // and close "file manager" once the upload is successful
714 if ($a_type > 0 && isset($_GET['uploadfile']) && $_GET['uploadfile'] <> '') { ?>
715 function setAlternativeAndClose() {
716 setAlternative('<?php echo get_relative_path($_GET['cp'], $pathext).$_GET['uploadfile']; ?>', '<?php echo TR_BASE_HREF.$get_file.$pathext.urlencode($_GET['uploadfile']); ?>', '<?php echo $_content_id; ?>', '<?php echo $pid; ?>', '<?php echo $a_type; ?>');
720 window.onload=setAlternativeAndClose;