upload.document.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. $courseDir = $_course['path'] . "/document";
  12. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  13. $base_work_dir = $sys_course_path . $courseDir;
  14. $noPHP_SELF = true;
  15. $max_filled_space = DocumentManager::get_course_quota();
  16. //what's the current path?
  17. if (isset($_POST['curdirpath'])) {
  18. $path = $_POST['curdirpath'];
  19. } else {
  20. $path = '/';
  21. }
  22. // Check the path
  23. // If the path is not found (no document id), set the path to /
  24. if (!DocumentManager::get_document_id($_course, $path)) {
  25. $path = '/';
  26. }
  27. /**
  28. * Header
  29. */
  30. $nameTools = get_lang('UplUploadDocument');
  31. $interbreadcrumb[] = array(
  32. "url" => "./document.php?curdirpath=" . urlencode(
  33. $path
  34. ) . $req_gid,
  35. "name" => $langDocuments
  36. );
  37. Display::display_header($nameTools, "Doc");
  38. //show the title
  39. api_display_tool_title($nameTools . $add_group_to_title);
  40. /**
  41. * Process
  42. */
  43. //user has submitted a file
  44. if (isset($_FILES['user_upload'])) {
  45. $upload_ok = process_uploaded_file($_FILES['user_upload']);
  46. if ($upload_ok) {
  47. //file got on the server without problems, now process it
  48. $new_path = handle_uploaded_document(
  49. $_course,
  50. $_FILES['user_upload'],
  51. $base_work_dir,
  52. $_POST['curdirpath'],
  53. $_user['user_id'],
  54. $to_group_id,
  55. $to_user_id,
  56. $_POST['unzip'],
  57. $_POST['if_exists']
  58. );
  59. $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
  60. $new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
  61. if ($new_path && ($new_comment || $new_title))
  62. if (($docid = DocumentManager::get_document_id($_course, $new_path))) {
  63. $table_document = Database::get_course_table(TABLE_DOCUMENT);
  64. $ct = '';
  65. if ($new_comment) $ct .= ", comment='$new_comment'";
  66. if ($new_title) $ct .= ", title='$new_title'";
  67. Database::query("UPDATE $table_document SET" . substr($ct, 1) ." WHERE id = '$docid'");
  68. }
  69. //check for missing images in html files
  70. $missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path);
  71. if ($missing_files) {
  72. //show a form to upload the missing files
  73. Display::display_normal_message(
  74. build_missing_files_form(
  75. $missing_files,
  76. $_POST['curdirpath'],
  77. $_FILES['user_upload']['name']
  78. )
  79. );
  80. }
  81. }
  82. }
  83. //missing images are submitted
  84. if (isset($_POST['submit_image'])) {
  85. $number_of_uploaded_images = count($_FILES['img_file']['name']);
  86. //if images are uploaded
  87. if ($number_of_uploaded_images > 0) {
  88. //we could also create a function for this, I'm not sure...
  89. //create a directory for the missing files
  90. $img_directory = str_replace('.','_',$_POST['related_file']."_files");
  91. $folderData = create_unexisting_directory(
  92. $_course,
  93. $_user['user_id'],
  94. api_get_session_id(),
  95. $to_group_id,
  96. $to_user_id,
  97. $base_work_dir,
  98. $img_directory
  99. );
  100. $missing_files_dir = $folderData['path'];
  101. //put the uploaded files in the new directory and get the paths
  102. $paths_to_replace_in_file = move_uploaded_file_collection_into_directory(
  103. $_course,
  104. $_FILES['img_file'],
  105. $base_work_dir,
  106. $missing_files_dir,
  107. $_user['user_id'],
  108. $to_group_id,
  109. $to_user_id,
  110. $max_filled_space
  111. );
  112. //open the html file and replace the paths
  113. replace_img_path_in_html_file(
  114. $_POST['img_file_path'],
  115. $paths_to_replace_in_file,
  116. $base_work_dir . $_POST['related_file']
  117. );
  118. //update parent folders
  119. item_property_update_on_folder($_course,$_POST['curdirpath'],$_user['user_id']);
  120. }
  121. }
  122. //they want to create a directory
  123. if (isset($_POST['create_dir']) && $_POST['dirname']!='') {
  124. $added_slash = ($path=='/')?'':'/';
  125. $dir_name = $path.$added_slash.api_replace_dangerous_char($_POST['dirname']);
  126. $created_dir = create_unexisting_directory(
  127. $_course,
  128. $_user['user_id'],
  129. api_get_session_id(),
  130. $to_group_id,
  131. $to_user_id,
  132. $base_work_dir,
  133. $dir_name,
  134. $_POST['dirname']
  135. );
  136. if ($created_dir) {
  137. Display::display_normal_message(get_lang('DirCr'));
  138. $path = $created_dir;
  139. } else {
  140. display_error(get_lang('CannotCreateDir'));
  141. }
  142. }
  143. if (isset($_GET['createdir'])) {
  144. //create the form that asks for the directory name
  145. $new_folder_text = '<form action="'.api_get_self().'" method="POST">';
  146. $new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>';
  147. $new_folder_text .= get_lang('NewDir') .' ';
  148. $new_folder_text .= '<input type="text" name="dirname"/>';
  149. $new_folder_text .= '<input type="submit" name="create_dir" value="'.get_lang('Ok').'"/>';
  150. $new_folder_text .= '</form>';
  151. //show the form
  152. Display::display_normal_message($new_folder_text);
  153. } else { //give them a link to create a directory
  154. ?>
  155. <p>
  156. <a href="<?php echo api_get_self(); ?>?path=<?php echo $path; ?>&amp;createdir=1">
  157. <?php echo Display::return_icon('new_folder.gif'); ?>
  158. <?php echo(get_lang('CreateDir'));?>
  159. </a>
  160. </p>
  161. <?php
  162. }
  163. ?>
  164. <div id="folderselector">
  165. </div>
  166. <!-- start upload form -->
  167. <form action="<?php echo api_get_self(); ?>" method="POST" name="upload" enctype="multipart/form-data">
  168. <!-- <input type="hidden" name="MAX_FILE_SIZE" value="5400"> -->
  169. <input type="hidden" name="curdirpath" value="<?php echo $path; ?>">
  170. <table>
  171. <tr>
  172. <td valign="top">
  173. <?php echo get_lang('File'); ?>
  174. </td>
  175. <td>
  176. <input type="file" name="user_upload"/>
  177. </td>
  178. </tr>
  179. <tr>
  180. <td><?php echo get_lang('Title');?></td>
  181. <td><input type="text" size="20" name="title" style="width:300px;"></td>
  182. </tr>
  183. <tr>
  184. <td valign="top"><?php echo get_lang('Comment');?></td>
  185. <td><textarea rows="3" cols="20" name="comment" wrap="virtual" style="width:300px;"></textarea></td>
  186. </tr>
  187. <tr>
  188. <td valign="top">
  189. <?php echo get_lang('Options'); ?>
  190. </td>
  191. <td>
  192. - <input type="checkbox" name="unzip" value="1" onclick="check_unzip()"/> <?php echo(get_lang('Uncompress'));?><br/>
  193. - <?php echo (get_lang('UplWhatIfFileExists'));?><br/>
  194. &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/>
  195. &nbsp;&nbsp;&nbsp;<input type="radio" name="if_exists" value="overwrite" title="<?php echo (get_lang('UplOverwriteLong'));?>"/> <?php echo (get_lang('UplOverwrite'));?><br/>
  196. &nbsp;&nbsp;&nbsp;<input type="radio" name="if_exists" value="rename" title="<?php echo (get_lang('UplRenameLong'));?>"/> <?php echo (get_lang('UplRename'));?>
  197. </td>
  198. </tr>
  199. </table>
  200. <input type="submit" value="<?php echo(get_lang('Ok'));?>">
  201. </form>
  202. <!-- end upload form -->
  203. <!-- so they can get back to the documents -->
  204. <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>
  205. <?php
  206. Display::display_footer();