Source for file api.php
Documentation is available at api.php
/* See license terms in /dokeos_license.txt */
==============================================================================
* This is an interface between Dokeos and Videoconference application
==============================================================================
define('VIDEOCONF_UPLOAD_PATH', '/videoconf');
$presentation_extension = array('.ppt', '.odp');
$image_extension = array ('.png', '.jpg', '.gif', '.jpeg');
/*==== Flash loose the cookie ===*/
/* needed when using the nice upload window :
if ($_SERVER['HTTP_USER_AGENT'] == 'Shockwave Flash') {
if ($debug>0) error_log("reusing: ".$sid);
require_once ('../inc/global.inc.php');
require_once (api_get_path(LIBRARY_PATH). "course.lib.php");
require_once (api_get_path(LIBRARY_PATH). "document.lib.php");
require_once (api_get_path(LIBRARY_PATH). "fileUpload.lib.php");
require_once ("../newscorm/learnpath.class.php");
require_once ("../newscorm/openoffice_presentation.class.php");
/*==== Variables initialisation ====*/
$action = $_REQUEST["action"]; //safe as only used in if()'s
$seek = array('/','%2F','..');
$destroy = array('','','');
$cidReq = str_replace($seek,$destroy,$_REQUEST["cidReq"]);
$_course['path'] = $_course['directory'];
// FIXME: add_document needs this to work
$_course['dbName'] = $_course['db_name'];
// FIXME: check if CourseManager::get_user_in_course_status return !=
// COURSEMANAGER when the code is not valid
if ($action == "uploadgui")
echo '<form enctype="multipart/form-data" action="api.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
<input type="hidden" name="action" value="upload" />
<input type="hidden" name="cidReq" value="'. $cidReq. '" />
'. get_lang('SelectFile'). ': <input name="Filedata" type="file" /><br />
<input type="submit" value="'. get_lang('UploadFile'). '" />
else if ($action == "upload")
if ($debug > 0) error_log("upload". $_FILES['Filedata']);
if ($debug > 0) error_log("Upload from videoconf not allowed !!!",0);
die('Not allowed'); // this user is not allowed to add upload documents
/*==== creation of /videoconf ====*/
if ($debug> 0) error_log("Can't create ". $destPath. " folder",0);
/*==== file upload ====*/
$newPath = $_FILES['Filedata']['name'];
/*==== extension extraction ====*/
/*==== conversion if needed ====*/
if($debug> 0) error_log("converting: ". $file_extension);
$take_slide_name = false;
$o_ppt -> set_slide_size(640,480);
$o_ppt -> convert_document($_FILES['Filedata'],'add_docs_to_visio');
echo '<html><body><script language="javascript">setTimeout(1000,window.close());</script></body></html>';
else if ($action == "service")
if ($debug> 0) error_log("sending file list",0);
$subaction = $_REQUEST["subaction"];
if ($subaction == "list")
// FIXME: check security around $_REQUEST["cwd"]
$nParent = 0; // the number of /.. into the url
while (substr($cwd, - 3, 3) == "/..")
// go to parent directory
if (strlen($cwd) == 0) $cwd= "/";
for (;$nParent > 0; $nParent-- ){
if (strlen($cwd) == 0) $cwd= "/";
// check if user can delete files. He must be manager and be inside /videoconf
if($debug> 0) error_log('Current working directory: '. $cwd);
/* $canDelete = ($canDelete && $isBellowVideoConfUploadPath);
$can_delete = ($is_manager && $is_below_videoconf_dir);
printf("<dokeosobject><fileListMeta></fileListMeta><fileList>");
strlen($files[$k]['title']) > 32 ?
substr($files[$k]['title'],0, 32). "..." :
// removing '<', '>' and '_'
$files[$k]['title'] = str_replace(array('<','>','_'),' ', $files[$k]['title']);
if ($i["filetype"] == "folder")
printf('<folder><path>%s</path><title>%s</title><canDelete>%s</canDelete></folder>', $i['path'],$i['title'],($can_delete? 'true': 'false'));
printf('<file><path>%s</path><title>%s</title><canDelete>%s</canDelete></file>', $i['path'],$i['title'],($can_delete? 'true': 'false'));
printf("</fileList></dokeosobject>");
else if ($subaction == "delete")
if ($debug > 0) error_log("Upload from videoconf not allowed !!!",0);
die(); // this user is not allowed to add upload documents
if ($debug > 0 ) error_log("Delete from videoconf for "+ $path+ " NOT ALLOWED",0);
echo "<result>OK</result>"; // We have to returns something to OpenLaszlo
else if ($action == "download")
//check if the document is in the database
if ($debug> 0) error_log("404 ". $_REQUEST["file"]);
header("HTTP/1.0 404 Not Found");
$error404 = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
$error404 .= '<html><head>';
$error404 .= '<title>404 Not Found</title>';
$error404 .= '</head><body>';
$error404 .= '<h1>Not Found</h1>';
$error404 .= '<p>The requested URL was not found on this server.</p>';
$error404 .= '</body></html>';
$full_file_name = $coursePath. $doc_url;
|