123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- <?php // $Id: upload.php 9246 2006-09-25 13:24:53Z bmol $
- /*
- ==============================================================================
- Dokeos - elearning and course management software
- Copyright (c) 2004-2005 Dokeos S.A.
- Copyright (c) 2003 Ghent University (UGent)
- Copyright (c) 2001 Universite catholique de Louvain (UCL)
- Copyright (c) various contributors
- For a full list of contributors, see "credits.txt".
- The full license can be read in "license.txt".
- 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; either version 2
- of the License, or (at your option) any later version.
- See the GNU General Public License for more details.
- Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
- ==============================================================================
- */
- /**
- ==============================================================================
- * Main script for the documents tool
- *
- * This script allows the user to manage files and directories on a remote http server.
- *
- * The user can : - navigate through files and directories.
- * - upload a file
- * - delete, copy a file or a directory
- * - edit properties & content (name, comments, html content)
- *
- * The script is organised in four sections.
- *
- * 1) Execute the command called by the user
- * Note: somme commands of this section are organised in two steps.
- * The script always begins with the second step,
- * so it allows to return more easily to the first step.
- *
- * Note (March 2004) some editing functions (renaming, commenting)
- * are moved to a separate page, edit_document.php. This is also
- * where xml and other stuff should be added.
- *
- * 2) Define the directory to display
- *
- * 3) Read files and directories from the directory defined in part 2
- * 4) Display all of that on an HTML page
- *
- * @todo eliminate code duplication between
- * document/document.php, scormdocument.php
- *
- * @package dokeos.document
- ==============================================================================
- */
- /*
- ==============================================================================
- INIT SECTION
- ==============================================================================
- */
- // name of the language file which needs to be included
- // 'inc.php' is automatically appended to the file name
- $langFile = "document";
- // global settings initialisation
- // also provides access to main api (inc/lib/main_api.lib.php)
- include("../inc/global.inc.php");
- include('document.inc.php');
- $htmlHeadXtra[] =
- "<script type=\"text/javascript\">
- <!-- //
- function check_unzip() {
- if(document.upload.unzip.checked==true){
- document.upload.if_exists[0].disabled=true;
- document.upload.if_exists[1].checked=true;
- document.upload.if_exists[2].disabled=true;
- }
- else {
- document.upload.if_exists[0].checked=true;
- document.upload.if_exists[0].disabled=false;
- document.upload.if_exists[2].disabled=false;
- }
- }
- // -->
- </script>";
- /*
- -----------------------------------------------------------
- Variables
- - some need defining before inclusion of libraries
- -----------------------------------------------------------
- */
- $is_allowed_to_edit = api_is_allowed_to_edit();
- $courseDir = $_course['path']."/document";
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $base_work_dir = $sys_course_path.$courseDir;
- $noPHP_SELF=true;
- //this needs cleaning!
- if(isset($_SESSION['_gid']) && $_SESSION['_gid']!='') //if the group id is set, check if the user has the right to be here
- {
- //needed for group related stuff
- include_once(api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php');
- //get group info
- $group_properties = GroupManager::get_group_properties($_SESSION['_gid']);
- $noPHP_SELF=true;
-
- if($is_allowed_to_edit || GroupManager::is_user_in_group($_uid,$_SESSION['_gid'])) //only courseadmin or group members allowed
- {
- $to_group_id = $_SESSION['_gid'];
- $req_gid = '&gidReq='.$_SESSION['_gid'];
- $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['_gid'], "name"=> get_lang('GroupSpace'));
- }
- else
- {
- api_not_allowed();
- }
- }
- elseif($is_allowed_to_edit) //admin for "regular" upload, no group documents
- {
- $to_group_id = 0;
- $req_gid = '';
- }
- else //no course admin and no group member...
- {
- api_not_allowed();
- }
- //what's the current path?
- if(isset($_GET['path']) && $_GET['path']!='')
- {
- $path = $_GET['path'];
- }
- elseif (isset($_POST['curdirpath']))
- {
- $path = $_POST['curdirpath'];
- }
- else
- {
- $path = '/';
- }
- /*
- -----------------------------------------------------------
- Libraries
- -----------------------------------------------------------
- */
- //many useful functions in main_api.lib.php, by default included
- include_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
- include_once(api_get_path(LIBRARY_PATH) . 'events.lib.inc.php');
- include_once(api_get_path(LIBRARY_PATH) . 'document.lib.php');
- //check the path
- //if the path is not found (no document id), set the path to /
- if(!DocumentManager::get_document_id($_course,$path))
- {
- $path = '/';
- }
- //group docs can only be uploaded in the group directory
- if($to_group_id!=0 && $path=='/')
- {
- $path = $group_properties['directory'];
- }
- //if we want to unzip a file, we need the library
- if (isset($_POST['unzip']) && $_POST['unzip'] == 1)
- {
- include(api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php');
- }
- /*
- -----------------------------------------------------------
- Variables
- -----------------------------------------------------------
- */
- $max_filled_space = DocumentManager::get_course_quota();
- /*
- -----------------------------------------------------------
- Header
- -----------------------------------------------------------
- */
- $nameTools = get_lang('UplUploadDocument');
- $interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($path).$req_gid, "name"=> $langDocuments);
- Display::display_header($nameTools,"Doc");
- if($to_group_id !=0) //add group name after for group documents
- {
- $add_group_to_title = ' ('.$group_properties['name'].')';
- }
- //show the title
- api_display_tool_title($nameTools.$add_group_to_title);
- /*
- -----------------------------------------------------------
- Here we do all the work
- -----------------------------------------------------------
- */
- //user has submitted a file
- if(isset($_FILES['user_upload']))
- {
- //echo("<pre>");
- //print_r($_FILES['user_upload']);
- //echo("</pre>");
-
- $upload_ok = process_uploaded_file($_FILES['user_upload']);
- if($upload_ok)
- {
- //file got on the server without problems, now process it
- $new_path = handle_uploaded_document($_course, $_FILES['user_upload'],$base_work_dir,$_POST['curdirpath'],$_uid,$to_group_id,$to_user_id,$max_filled_space,$_POST['unzip'],$_POST['if_exists']);
- $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
- $new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
-
- if ($new_path && ($new_comment || $new_title))
- if (($docid = DocumentManager::get_document_id($_course, $new_path)))
- {
- $table_document = Database::get_course_table(DOCUMENT_TABLE);
- $ct = '';
- if ($new_comment) $ct .= ", comment='$new_comment'";
- if ($new_title) $ct .= ", title='$new_title'";
- api_sql_query("UPDATE $table_document SET" . substr($ct, 1) .
- " WHERE id = '$docid'", __FILE__, __LINE__);
- }
- //check for missing images in html files
- $missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path);
- if($missing_files)
- {
- //show a form to upload the missing files
- Display::display_normal_message(build_missing_files_form($missing_files,$_POST['curdirpath'],$_FILES['user_upload']['name']));
- }
- }
- }
- //missing images are submitted
- if(isset($_POST['submit_image']))
- {
- $number_of_uploaded_images = count($_FILES['img_file']['name']);
- //if images are uploaded
- if ($number_of_uploaded_images > 0)
- {
- //we could also create a function for this, I'm not sure...
- //create a directory for the missing files
- $img_directory = str_replace('.','_',$_POST['related_file']."_files");
- $missing_files_dir = create_unexisting_directory($_course,$_uid,$to_group_id,$to_user_id,$base_work_dir,$img_directory);
- //put the uploaded files in the new directory and get the paths
- $paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'],$base_work_dir,$missing_files_dir,$_uid,$to_group_id,$to_user_id,$max_filled_space);
- //open the html file and replace the paths
- replace_img_path_in_html_file($_POST['img_file_path'],$paths_to_replace_in_file,$base_work_dir.$_POST['related_file']);
- //update parent folders
- item_property_update_on_folder($_course,$_POST['curdirpath'],$_uid);
- }
- }
- //they want to create a directory
- if(isset($_POST['create_dir']) && $_POST['dirname']!='')
- {
- $added_slash = ($path=='/')?'':'/';
- $dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']);
- $created_dir = create_unexisting_directory($_course,$_uid,$to_group_id,$to_user_id,$base_work_dir,$dir_name,$_POST['dirname']);
- if($created_dir)
- {
- //Display::display_normal_message("<strong>".$created_dir."</strong> was created!");
- Display::display_normal_message(get_lang('DirCr'));
- $path = $created_dir;
- }
- else
- {
- display_error(get_lang('CannotCreateDir'));
- }
- }
- //tracking not needed here?
- //event_access_tool(TOOL_DOCUMENT);
- /*============================================================================*/
- ?>
- <?php
- //=======================================//
- //they want to create a new directory//
- //=======================================//
- if(isset($_GET['createdir']))
- {
- //create the form that asks for the directory name
- $new_folder_text = '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
- $new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>';
- $new_folder_text .= get_lang('NewDir') .' ';
- $new_folder_text .= '<input type="text" name="dirname"/>';
- $new_folder_text .= '<input type="submit" name="create_dir" value="'.get_lang('Ok').'"/>';
- $new_folder_text .= '</form>';
- //show the form
- Display::display_normal_message($new_folder_text);
- }
- else { //give them a link to create a directory
- ?>
- <p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?path=<?php echo $path; ?>&createdir=1"><img src="../img/new_folder.gif" border="0" align="absmiddle" alt ="" /> <?php echo(get_lang('CreateDir'));?></a></p>
- <?php
- }
- ?>
- <div id="folderselector">
- <?php
- //form to select directory
- $folders = DocumentManager::get_all_document_folders($_course,$to_group_id,$is_allowed_to_edit);
- echo(build_directory_selector($folders,$path,$group_properties['directory']));
- ?>
- </div>
- <!-- start upload form -->
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" name="upload" enctype="multipart/form-data">
- <!-- <input type="hidden" name="MAX_FILE_SIZE" value="5400"> -->
- <input type="hidden" name="curdirpath" value="<?php echo $path; ?>">
- <table>
- <tr>
- <td valign="top">
- <?php echo get_lang('File'); ?>
- </td>
- <td>
- <input type="file" name="user_upload"/>
- </td>
- </tr>
- <?php
- if(get_setting('use_document_title')=='true')
- {
- ?>
- <tr>
- <td><?php echo get_lang('Title');?></td>
- <td><input type="text" size="20" name="title" style="width:300px;"></td>
- </tr>
- <?php
- }
- ?>
- <tr>
- <td valign="top"><?php echo get_lang('Comment');?></td>
- <td><textarea rows="3" cols="20" name="comment" wrap="virtual" style="width:300px;"></textarea></td>
- </tr>
- <tr>
- <td valign="top">
- <?php echo get_lang('Options'); ?>
- </td>
- <td>
- - <input type="checkbox" name="unzip" value="1" onclick="check_unzip()"/> <?php echo(get_lang('Uncompress'));?><br/>
- - <?php echo (get_lang('UplWhatIfFileExists'));?><br/>
- <input type="radio" name="if_exists" value="nothing" title="<?php echo (get_lang('UplDoNothingLong'));?>" checked="checked"/> <?php echo (get_lang('UplDoNothing'));?><br/>
- <input type="radio" name="if_exists" value="overwrite" title="<?php echo (get_lang('UplOverwriteLong'));?>"/> <?php echo (get_lang('UplOverwrite'));?><br/>
- <input type="radio" name="if_exists" value="rename" title="<?php echo (get_lang('UplRenameLong'));?>"/> <?php echo (get_lang('UplRename'));?>
- </td>
- </tr>
- </table>
- <input type="submit" value="<?php echo(get_lang('Ok'));?>">
- </form>
- <!-- end upload form -->
- <!-- so they can get back to the documents -->
- <p><?php echo (get_lang('Back'));?> <?php echo (get_lang('To'));?> <a href="document.php?curdirpath=<?php echo $path; ?>"><?php echo (get_lang('DocumentsOverview'));?></a></p>
- <?php
- /*
- ==============================================================================
- FOOTER
- ==============================================================================
- */
- Display::display_footer();
- ?>
|