upload.document.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Process part of the document sub-process for upload. This script MUST BE included by upload/index.php
  5. * as it prepares most of the variables needed here.
  6. *
  7. * @todo check if this file is deprecated ... jmontoya
  8. * @package chamilo.upload
  9. * @author Yannick Warnier <ywarnier@beeznest.org>
  10. */
  11. /**
  12. * Process the document and return to the document tool
  13. */
  14. /*
  15. Libraries
  16. */
  17. //many useful functions in main_api.lib.php, by default included
  18. if(!function_exists('api_get_path')){header('location: upload.php');die;}
  19. require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
  20. require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
  21. require_once '../document/document.inc.php';
  22. $courseDir = $_course['path']."/document";
  23. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  24. $base_work_dir = $sys_course_path.$courseDir;
  25. $noPHP_SELF=true;
  26. $max_filled_space = DocumentManager::get_course_quota();
  27. //what's the current path?
  28. if(isset($_POST['curdirpath'])) {
  29. $path = $_POST['curdirpath'];
  30. }else{
  31. $path = '/';
  32. }
  33. // Check the path
  34. // If the path is not found (no document id), set the path to /
  35. if(!DocumentManager::get_document_id($_course,$path)) { $path = '/'; }
  36. /**
  37. * Header
  38. */
  39. $nameTools = get_lang('UplUploadDocument');
  40. $interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($path).$req_gid, "name"=> $langDocuments);
  41. Display::display_header($nameTools,"Doc");
  42. //show the title
  43. api_display_tool_title($nameTools.$add_group_to_title);
  44. /**
  45. * Process
  46. */
  47. //user has submitted a file
  48. if(isset($_FILES['user_upload'])) {
  49. $upload_ok = process_uploaded_file($_FILES['user_upload']);
  50. if($upload_ok) {
  51. //file got on the server without problems, now process it
  52. $new_path = handle_uploaded_document($_course, $_FILES['user_upload'],$base_work_dir,$_POST['curdirpath'],$_user['user_id'],$to_group_id,$to_user_id,$max_filled_space,$_POST['unzip'],$_POST['if_exists']);
  53. $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
  54. $new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
  55. if ($new_path && ($new_comment || $new_title))
  56. if (($docid = DocumentManager::get_document_id($_course, $new_path)))
  57. {
  58. $table_document = Database::get_course_table(TABLE_DOCUMENT);
  59. $ct = '';
  60. if ($new_comment) $ct .= ", comment='$new_comment'";
  61. if ($new_title) $ct .= ", title='$new_title'";
  62. Database::query("UPDATE $table_document SET" . substr($ct, 1) .
  63. " WHERE id = '$docid'");
  64. }
  65. //check for missing images in html files
  66. $missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path);
  67. if($missing_files)
  68. {
  69. //show a form to upload the missing files
  70. Display::display_normal_message(build_missing_files_form($missing_files,$_POST['curdirpath'],$_FILES['user_upload']['name']));
  71. }
  72. }
  73. }
  74. //missing images are submitted
  75. if(isset($_POST['submit_image'])) {
  76. $number_of_uploaded_images = count($_FILES['img_file']['name']);
  77. //if images are uploaded
  78. if ($number_of_uploaded_images > 0)
  79. {
  80. //we could also create a function for this, I'm not sure...
  81. //create a directory for the missing files
  82. $img_directory = str_replace('.','_',$_POST['related_file']."_files");
  83. $missing_files_dir = create_unexisting_directory($_course,$_user['user_id'],api_get_session_id(), $to_group_id,$to_user_id,$base_work_dir,$img_directory);
  84. //put the uploaded files in the new directory and get the paths
  85. $paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'],$base_work_dir,$missing_files_dir,$_user['user_id'],$to_group_id,$to_user_id,$max_filled_space);
  86. //open the html file and replace the paths
  87. replace_img_path_in_html_file($_POST['img_file_path'],$paths_to_replace_in_file,$base_work_dir.$_POST['related_file']);
  88. //update parent folders
  89. item_property_update_on_folder($_course,$_POST['curdirpath'],$_user['user_id']);
  90. }
  91. }
  92. //they want to create a directory
  93. if(isset($_POST['create_dir']) && $_POST['dirname']!='')
  94. {
  95. $added_slash = ($path=='/')?'':'/';
  96. $dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']);
  97. $created_dir = create_unexisting_directory($_course,$_user['user_id'],api_get_session_id(), $to_group_id,$to_user_id,$base_work_dir,$dir_name,$_POST['dirname']);
  98. if($created_dir)
  99. {
  100. //Display::display_normal_message("<strong>".$created_dir."</strong> was created!");
  101. Display::display_normal_message(get_lang('DirCr'));
  102. $path = $created_dir;
  103. }
  104. else
  105. {
  106. display_error(get_lang('CannotCreateDir'));
  107. }
  108. }
  109. if(isset($_GET['createdir']))
  110. {
  111. //create the form that asks for the directory name
  112. $new_folder_text = '<form action="'.api_get_self().'" method="POST">';
  113. $new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>';
  114. $new_folder_text .= get_lang('NewDir') .' ';
  115. $new_folder_text .= '<input type="text" name="dirname"/>';
  116. $new_folder_text .= '<input type="submit" name="create_dir" value="'.get_lang('Ok').'"/>';
  117. $new_folder_text .= '</form>';
  118. //show the form
  119. Display::display_normal_message($new_folder_text);
  120. }
  121. else { //give them a link to create a directory
  122. ?>
  123. <p><a href="<?php echo api_get_self(); ?>?path=<?php echo $path; ?>&amp;createdir=1"><img src="../img/new_folder.gif" border="0" align="absmiddle" alt ="" /> <?php echo(get_lang('CreateDir'));?></a></p>
  124. <?php
  125. }
  126. ?>
  127. <div id="folderselector">
  128. <?php
  129. //form to select directory
  130. //$folders = DocumentManager::get_all_document_folders($_course,$to_group_id,$is_allowed_to_edit);
  131. //echo(build_directory_selector($folders,$path,$group_properties['directory']));
  132. ?>
  133. </div>
  134. <!-- start upload form -->
  135. <form action="<?php echo api_get_self(); ?>" method="POST" name="upload" enctype="multipart/form-data">
  136. <!-- <input type="hidden" name="MAX_FILE_SIZE" value="5400"> -->
  137. <input type="hidden" name="curdirpath" value="<?php echo $path; ?>">
  138. <table>
  139. <tr>
  140. <td valign="top">
  141. <?php echo get_lang('File'); ?>
  142. </td>
  143. <td>
  144. <input type="file" name="user_upload"/>
  145. </td>
  146. </tr>
  147. <?php
  148. if(api_get_setting('use_document_title')=='true')
  149. {
  150. ?>
  151. <tr>
  152. <td><?php echo get_lang('Title');?></td>
  153. <td><input type="text" size="20" name="title" style="width:300px;"></td>
  154. </tr>
  155. <?php
  156. }
  157. ?>
  158. <tr>
  159. <td valign="top"><?php echo get_lang('Comment');?></td>
  160. <td><textarea rows="3" cols="20" name="comment" wrap="virtual" style="width:300px;"></textarea></td>
  161. </tr>
  162. <tr>
  163. <td valign="top">
  164. <?php echo get_lang('Options'); ?>
  165. </td>
  166. <td>
  167. - <input type="checkbox" name="unzip" value="1" onclick="check_unzip()"/> <?php echo(get_lang('Uncompress'));?><br/>
  168. - <?php echo (get_lang('UplWhatIfFileExists'));?><br/>
  169. &nbsp;&nbsp;&nbsp;<input type="radio" name="if_exists" value="nothing" title="<?php echo (get_lang('UplDoNothingLong'));?>" checked="checked"/> <?php echo (get_lang('UplDoNothing'));?><br/>
  170. &nbsp;&nbsp;&nbsp;<input type="radio" name="if_exists" value="overwrite" title="<?php echo (get_lang('UplOverwriteLong'));?>"/> <?php echo (get_lang('UplOverwrite'));?><br/>
  171. &nbsp;&nbsp;&nbsp;<input type="radio" name="if_exists" value="rename" title="<?php echo (get_lang('UplRenameLong'));?>"/> <?php echo (get_lang('UplRename'));?>
  172. </td>
  173. </tr>
  174. </table>
  175. <input type="submit" value="<?php echo(get_lang('Ok'));?>">
  176. </form>
  177. <!-- end upload form -->
  178. <!-- so they can get back to the documents -->
  179. <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>
  180. <?php
  181. Display::display_footer();