<?php
/****************************************************************/
/* ATutor														*/
/****************************************************************/
/* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg        */
/* Adaptive Technology Resource Centre / University of Toronto  */
/* http://atutor.ca												*/
/*                                                              */
/* This program is free software. You can redistribute it and/or*/
/* modify it under the terms of the GNU General Public License  */
/* as published by the Free Software Foundation.				*/
/****************************************************************/
// $Id: index.php 7984 2008-10-02 13:10:16Z greg $

define('AT_INCLUDE_PATH', '../../include/');
require(AT_INCLUDE_PATH.'vitals.inc.php');
require(AT_INCLUDE_PATH.'lib/filemanager.inc.php');


if ((isset($_REQUEST['popup']) && $_REQUEST['popup']) && 
	(!isset($_REQUEST['framed']) || !$_REQUEST['framed'])) {
	$popup = TRUE;
	$framed = FALSE;
} else if (isset($_REQUEST['framed']) && $_REQUEST['framed'] && isset($_REQUEST['popup']) && $_REQUEST['popup']) {
	$popup = TRUE;
	$framed = TRUE;
} else {
	$popup = FALSE;
	$framed = FALSE;
}


// If Flash is detected, call the necessary css and js, and configure settings to use the Fluid Uploader
if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") {
    /* Provide the option of switching between Fluid Uploader and simple single file uploader
       and save the user preference as a cookie */
    if (!isset($_COOKIE["fluid_on"]))
        setcookie("fluid_on", "yes", time()+1200); 

    $fluid_dir = 'jscripts/fluid-components/';
    $framed = intval($_GET['framed']);
    $popup = intval($_GET['popup']);
    $current_path = AT_CONTENT_DIR.$_SESSION['course_id'].'/';

    if ($_GET['pathext'] != '') {
        $pathext = urldecode($_GET['pathext']);
    } else if ($_POST['pathext'] != '') {
        $pathext = $_POST['pathext'];
    }

    if($_GET['back'] == 1) {
        $pathext  = substr($pathext, 0, -1);
        $slashpos = strrpos($pathext, '/');
        if($slashpos == 0) {
            $pathext = '';
        } else {
            $pathext = substr($pathext, 0, ($slashpos+1));
        }

    }


    $_custom_head .= '
        <link href="'.$fluid_dir.'css/infusion-theme.css" rel="stylesheet" type="text/css" />
        <link href="'.$fluid_dir.'css/Uploader.css" rel="stylesheet" type="text/css" />
        <script src="'.$fluid_dir.'js/Fluid-all.js" type="text/javascript"></script>
        <script language="JavaScript" type="text/javascript">

            // set to empty to use demo upload js code instead actual server side upload handlers
            var uploadURL = "'.$_base_href.'include/lib/upload.php?path='.urlencode($current_path.$pathext).'";  // relative to the swf file
            var flashURL = "jscripts/fluid-components/swfupload/swfupload_f9.swf";
            var settings =   {
                whenDone: "'.$_SERVER['PHP_SELF'].'?pathext=' . urlencode($pathext) . SEP . 'popup=' . $popup . SEP . 'framed=' . $framed . SEP . 'msg=FILEUPLOAD_DONE",
                whenCancel: function(){},
                whenFileUploaded: function(fileName, serverResponse) {},
                continueAfterUpload: true,
                debug: false
            };
            var myUpload; // mostly used for testing
            $(document).ready(function() {
                myUpload = new fluid.Uploader("single-inline-fluid-uploader", uploadURL, flashURL, settings);
            });
        </script>
        <style type="text/css">
            .fluid-uploader {
                margin-top: 2em;
                padding: 1em 2em;
                display: block;
                clear: both;
            }
        </style>
    ';
}

global $msg;
if (isset($_GET['msg']))
	$msg -> addFeedback($_GET['msg']);

require('top.php');
$_SESSION['done'] = 1;

require(AT_INCLUDE_PATH.'html/filemanager_display.inc.php');

closedir($dir);

?>
<script type="text/javascript">
//<!--
function Checkall(form){ 
  for (var i = 0; i < form.elements.length; i++){    
    eval("form.elements[" + i + "].checked = form.checkall.checked");  
  } 
}
function openWindow(page) {
	newWindow = window.open(page, "progWin", "width=400,height=200,toolbar=no,location=no");
	newWindow.focus();
}
//-->
</script>
<?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>