upload.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Main script for the documents tool
  5. *
  6. * This script allows the user to manage files and directories on a remote http server.
  7. *
  8. * The user can : - navigate through files and directories.
  9. * - upload a file
  10. * - delete, copy a file or a directory
  11. * - edit properties & content (name, comments, html content)
  12. *
  13. * The script is organised in four sections.
  14. *
  15. * 1) Execute the command called by the user
  16. * Note: somme commands of this section are organised in two steps.
  17. * The script always begins with the second step,
  18. * so it allows to return more easily to the first step.
  19. *
  20. * Note (March 2004) some editing functions (renaming, commenting)
  21. * are moved to a separate page, edit_document.php. This is also
  22. * where xml and other stuff should be added.
  23. *
  24. * 2) Define the directory to display
  25. *
  26. * 3) Read files and directories from the directory defined in part 2
  27. * 4) Display all of that on an HTML page
  28. *
  29. * @todo eliminate code duplication between
  30. * document/document.php, scormdocument.php
  31. *
  32. * @package chamilo.document
  33. */
  34. // Name of the language file that needs to be included
  35. $language_file = array('document','gradebook');
  36. // Including the global initialization file
  37. require_once '../inc/global.inc.php';
  38. // Including additional libraries
  39. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  40. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  41. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  42. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  43. require_once 'document.inc.php';
  44. // Adding extra javascript to the form
  45. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>';
  46. $htmlHeadXtra[] = '<script type="text/javascript">
  47. function check_unzip() {
  48. if(document.upload.unzip.checked){
  49. document.upload.if_exists[0].disabled=true;
  50. document.upload.if_exists[1].checked=true;
  51. document.upload.if_exists[2].disabled=true;
  52. } else {
  53. document.upload.if_exists[0].checked=true;
  54. document.upload.if_exists[0].disabled=false;
  55. document.upload.if_exists[2].disabled=false;
  56. }
  57. }
  58. function advanced_parameters() {
  59. if(document.getElementById(\'options\').style.display == \'none\') {
  60. document.getElementById(\'options\').style.display = \'block\';
  61. document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;<img style="vertical-align:middle;" src="../img/div_hide.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'\';
  62. } else {
  63. document.getElementById(\'options\').style.display = \'none\';
  64. document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;<img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'\';
  65. }
  66. }
  67. function setFocus(){
  68. $("#title_file").focus();
  69. }
  70. $(document).ready(function () {
  71. setFocus();
  72. });
  73. </script>';
  74. /**
  75. * Obtains the text inside the file with the right parser
  76. */
  77. function get_text_content($doc_path, $doc_mime) {
  78. // TODO: review w$ compatibility
  79. // Use usual exec output lines array to store stdout instead of a temp file
  80. // because we need to store it at RAM anyway before index on DokeosIndexer object
  81. $ret_val = null;
  82. switch ($doc_mime) {
  83. case 'text/plain':
  84. $handle = fopen($doc_path, 'r');
  85. $output = array(fread($handle, filesize($doc_path)));
  86. fclose($handle);
  87. break;
  88. case 'application/pdf':
  89. exec("pdftotext $doc_path -", $output, $ret_val);
  90. break;
  91. case 'application/postscript':
  92. $temp_file = tempnam(sys_get_temp_dir(), 'chamilo');
  93. exec("ps2pdf $doc_path $temp_file", $output, $ret_val);
  94. if ($ret_val !== 0) { // shell fail, probably 127 (command not found)
  95. return false;
  96. }
  97. exec("pdftotext $temp_file -", $output, $ret_val);
  98. unlink($temp_file);
  99. //var_dump($output);
  100. break;
  101. case 'application/msword':
  102. exec("catdoc $doc_path", $output, $ret_val);
  103. //var_dump($output);
  104. break;
  105. case 'text/html':
  106. exec("html2text $doc_path", $output, $ret_val);
  107. break;
  108. case 'text/rtf':
  109. // Note: correct handling of code pages in unrtf
  110. // on debian lenny unrtf v0.19.2 can not, but unrtf v0.20.5 can
  111. exec("unrtf --text $doc_path", $output, $ret_val);
  112. if ($ret_val == 127) { // command not found
  113. return false;
  114. }
  115. // Avoid index unrtf comments
  116. if (is_array($output) && count($output) > 1) {
  117. $parsed_output = array();
  118. foreach ($output as & $line) {
  119. if (!preg_match('/^###/', $line, $matches)) {
  120. if (!empty($line)) {
  121. $parsed_output[] = $line;
  122. }
  123. }
  124. }
  125. $output = $parsed_output;
  126. }
  127. break;
  128. case 'application/vnd.ms-powerpoint':
  129. exec("catppt $doc_path", $output, $ret_val);
  130. break;
  131. case 'application/vnd.ms-excel':
  132. exec("xls2csv -c\" \" $doc_path", $output, $ret_val);
  133. break;
  134. }
  135. $content = '';
  136. if (!is_null($ret_val)) {
  137. if ($ret_val !== 0) { // shell fail, probably 127 (command not found)
  138. return false;
  139. }
  140. }
  141. if (isset($output)) {
  142. foreach ($output as & $line) {
  143. $content .= $line."\n";
  144. }
  145. return $content;
  146. }
  147. else {
  148. return false;
  149. }
  150. }
  151. // Variables
  152. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  153. $courseDir = $_course['path'].'/document';
  154. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  155. $base_work_dir = $sys_course_path.$courseDir;
  156. $noPHP_SELF = true;
  157. // What's the current path?
  158. if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') {
  159. $path = $_GET['curdirpath'];
  160. } elseif (isset($_POST['curdirpath'])) {
  161. $path = $_POST['curdirpath'];
  162. } else {
  163. $path = '/';
  164. }
  165. // Check the path: if the path is not found (no document id), set the path to /
  166. if (!DocumentManager::get_document_id($_course, $path)) {
  167. $path = '/';
  168. }
  169. // This needs cleaning!
  170. if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') { // If the group id is set, check if the user has the right to be here
  171. // Needed for group related stuff
  172. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  173. // Get group info
  174. $group_properties = GroupManager::get_group_properties($_SESSION['_gid']);
  175. $noPHP_SELF = true;
  176. if ($is_allowed_to_edit || GroupManager::is_user_in_group($_user['user_id'], $_SESSION['_gid'])) { // Only courseadmin or group members allowed
  177. $to_group_id = $_SESSION['_gid'];
  178. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  179. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace'));
  180. } else {
  181. api_not_allowed(true);
  182. }
  183. } elseif ($is_allowed_to_edit || is_my_shared_folder($_user['user_id'], $path,api_get_session_id())) { // Admin for "regular" upload, no group documents. And check if is my shared folder
  184. $to_group_id = 0;
  185. $req_gid = '';
  186. } else { // No course admin and no group member...
  187. api_not_allowed(true);
  188. }
  189. // Group docs can only be uploaded in the group directory
  190. if ($to_group_id != 0 && $path == '/') {
  191. $path = $group_properties['directory'];
  192. }
  193. // I'm in the certification module?
  194. $is_certificate_mode = false;
  195. $is_certificate_array = explode('/', $path);
  196. array_shift($is_certificate_array);
  197. if ($is_certificate_array[0] == 'certificates') {
  198. $is_certificate_mode = true;
  199. }
  200. // If we want to unzip a file, we need the library
  201. if (isset($_POST['unzip']) && $_POST['unzip'] == 1) {
  202. require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
  203. }
  204. // Variables
  205. $max_filled_space = DocumentManager::get_course_quota();
  206. // Title of the tool
  207. if ($to_group_id != 0) { // Add group name after for group documents
  208. $add_group_to_title = ' ('.$group_properties['name'].')';
  209. }
  210. if (isset($_REQUEST['certificate'])) {
  211. $nameTools = get_lang('UploadCertificate').$add_group_to_title;
  212. } else {
  213. $nameTools = get_lang('UplUploadDocument').$add_group_to_title;
  214. }
  215. // Breadcrumbs
  216. if ($is_certificate_mode) {
  217. $interbreadcrumb[] = array('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
  218. } else {
  219. $interbreadcrumb[] = array('url' => './document.php?curdirpath='.urlencode($path).$req_gid, 'name'=> get_lang('Documents'));
  220. }
  221. $this_section = SECTION_COURSES;
  222. // Display the header
  223. Display::display_header($nameTools, 'Doc');
  224. /* Here we do all the work */
  225. // User has submitted a file
  226. if (isset($_FILES['user_upload'])) {
  227. //echo('<pre>');
  228. //print_r($_FILES['user_upload']);
  229. //echo('</pre>');
  230. $upload_ok = process_uploaded_file($_FILES['user_upload']);
  231. if ($upload_ok) {
  232. // File got on the server without problems, now process it
  233. $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']);
  234. $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
  235. $new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
  236. if ($new_path && ($new_comment || $new_title)) {
  237. if (($docid = DocumentManager::get_document_id($_course, $new_path))) {
  238. $table_document = Database::get_course_table(TABLE_DOCUMENT);
  239. $ct = '';
  240. if ($new_comment) $ct .= ", comment='$new_comment'";
  241. if ($new_title) $ct .= ", title='$new_title'";
  242. Database::query("UPDATE $table_document SET".substr($ct, 1)." WHERE id = '$docid'");
  243. }
  244. }
  245. // Showing message when sending zip files
  246. if ($new_path === true && $_POST['unzip'] == 1) {
  247. Display::display_confirmation_message(get_lang('UplUploadSucceeded').'<br />', false);
  248. }
  249. if ((api_get_setting('search_enabled') == 'true') && ($docid = DocumentManager::get_document_id($_course, $new_path))) {
  250. $table_document = Database::get_course_table(TABLE_DOCUMENT);
  251. $result = Database::query("SELECT * FROM $table_document WHERE id = '$docid' LIMIT 1");
  252. if (Database::num_rows($result) == 1) {
  253. $row = Database::fetch_array($result);
  254. $doc_path = api_get_path(SYS_COURSE_PATH).$courseDir.$row['path'];
  255. //TODO: mime_content_type is deprecated, fileinfo php extension is enabled by default as of PHP 5.3.0
  256. // now versions of PHP on Debian testing(5.2.6-5) and Ubuntu(5.2.6-2ubuntu) are lower, so wait for a while
  257. $doc_mime = mime_content_type($doc_path);
  258. //echo $doc_mime;
  259. //TODO: more mime types
  260. $allowed_mime_types = array('text/plain', 'application/pdf', 'application/postscript', 'application/msword', 'text/html', 'text/rtf', 'application/vnd.ms-powerpoint', 'application/vnd.ms-excel');
  261. // mime_content_type does not detect correctly some formats that are going to be supported for index, so an extensions array is used by the moment
  262. if (empty($doc_mime)) {
  263. $allowed_extensions = array('ppt', 'pps', 'xls');
  264. $extensions = preg_split("/[\/\\.]/", $doc_path) ;
  265. $doc_ext = strtolower($extensions[count($extensions) - 1]);
  266. if (in_array($doc_ext, $allowed_extensions)) {
  267. switch ($doc_ext) {
  268. case 'ppt':
  269. case 'pps':
  270. $doc_mime = 'application/vnd.ms-powerpoint';
  271. break;
  272. case 'xls':
  273. $doc_mime = 'application/vnd.ms-excel';
  274. break;
  275. }
  276. }
  277. }
  278. if (in_array($doc_mime, $allowed_mime_types) && isset($_POST['index_document']) && $_POST['index_document']) {
  279. $file_title = $row['title'];
  280. $file_content = get_text_content($doc_path, $doc_mime);
  281. $courseid = api_get_course_id();
  282. $lang = isset($_POST['language']) ? Database::escape_string($_POST['language']) : 'english';
  283. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  284. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  285. $ic_slide = new IndexableChunk();
  286. $ic_slide->addValue('title', $file_title);
  287. $ic_slide->addCourseId($courseid);
  288. $ic_slide->addToolId(TOOL_DOCUMENT);
  289. $xapian_data = array(
  290. SE_COURSE_ID => $courseid,
  291. SE_TOOL_ID => TOOL_DOCUMENT,
  292. SE_DATA => array('doc_id' => (int)$docid),
  293. SE_USER => (int)api_get_user_id(),
  294. );
  295. $ic_slide->xapian_data = serialize($xapian_data);
  296. $di = new DokeosIndexer();
  297. $di->connectDb(null, null, $lang);
  298. $specific_fields = get_specific_field_list();
  299. // process different depending on what to do if file exists
  300. /**
  301. * FIXME: Find a way to really verify if the file had been
  302. * overwriten. Now all work is done at
  303. * handle_uploaded_document() and it's difficult to verify it
  304. */
  305. if (!empty($_POST['if_exists']) && $_POST['if_exists'] == 'overwrite') {
  306. // overwrite the file on search engine
  307. // actually, it consists on delete terms from db, insert new ones, create a new search engine document, and remove the old one
  308. // Get search_did
  309. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  310. $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1';
  311. $sql = sprintf($sql, $tbl_se_ref, $courseid, TOOL_DOCUMENT, $docid);
  312. $res = Database::query($sql);
  313. if (Database::num_rows($res) > 0) {
  314. $se_ref = Database::fetch_array($res);
  315. $di->remove_document((int)$se_ref['search_did']);
  316. $all_specific_terms = '';
  317. foreach ($specific_fields as $specific_field) {
  318. delete_all_specific_field_value($courseid, $specific_field['id'], TOOL_DOCUMENT, $docid);
  319. // Update search engine
  320. $sterms = trim($_REQUEST[$specific_field['code']]);
  321. $all_specific_terms .= ' '. $sterms;
  322. $sterms = explode(',', $sterms);
  323. foreach ($sterms as $sterm) {
  324. $sterm = trim($sterm);
  325. if (!empty($sterm)) {
  326. $ic_slide->addTerm($sterm, $specific_field['code']);
  327. add_specific_field_value($specific_field['id'], $courseid, TOOL_DOCUMENT, $docid, $value);
  328. }
  329. }
  330. }
  331. // Add terms also to content to make terms findable by probabilistic search
  332. $file_content = $all_specific_terms .' '. $file_content;
  333. $ic_slide->addValue('content', $file_content);
  334. $di->addChunk($ic_slide);
  335. // Index and return a new search engine document id
  336. $did = $di->index();
  337. if ($did) {
  338. // update the search_did on db
  339. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  340. $sql = 'UPDATE %s SET search_did=%d WHERE id=%d LIMIT 1';
  341. $sql = sprintf($sql, $tbl_se_ref, (int)$did, (int)$se_ref['id']);
  342. Database::query($sql);
  343. }
  344. }
  345. } else {
  346. // Add all terms
  347. $all_specific_terms = '';
  348. foreach ($specific_fields as $specific_field) {
  349. if (isset($_REQUEST[$specific_field['code']])) {
  350. $sterms = trim($_REQUEST[$specific_field['code']]);
  351. $all_specific_terms .= ' '. $sterms;
  352. if (!empty($sterms)) {
  353. $sterms = explode(',', $sterms);
  354. foreach ($sterms as $sterm) {
  355. $ic_slide->addTerm(trim($sterm), $specific_field['code']);
  356. add_specific_field_value($specific_field['id'], $courseid, TOOL_DOCUMENT, $docid, $sterm);
  357. }
  358. }
  359. }
  360. }
  361. // Add terms also to content to make terms findable by probabilistic search
  362. $file_content = $all_specific_terms .' '. $file_content;
  363. $ic_slide->addValue('content', $file_content);
  364. $di->addChunk($ic_slide);
  365. // Index and return search engine document id
  366. $did = $di->index();
  367. if ($did) {
  368. // Save it to db
  369. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  370. $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did)
  371. VALUES (NULL , \'%s\', \'%s\', %s, %s)';
  372. $sql = sprintf($sql, $tbl_se_ref, $courseid, TOOL_DOCUMENT, $docid, $did);
  373. Database::query($sql);
  374. }
  375. }
  376. }
  377. }
  378. }
  379. // Check for missing images in html files
  380. $missing_files = check_for_missing_files($base_work_dir.$new_path);
  381. if ($missing_files) {
  382. // Show a form to upload the missing files
  383. Display::display_normal_message(build_missing_files_form($missing_files, $_POST['curdirpath'], $_FILES['user_upload']['name']), false);
  384. }
  385. }
  386. }
  387. // Missing images are submitted
  388. if (isset($_POST['submit_image'])) {
  389. $number_of_uploaded_images = count($_FILES['img_file']['name']);
  390. //if images are uploaded
  391. if ($number_of_uploaded_images > 0) {
  392. // We could also create a function for this, I'm not sure...
  393. // Create a directory for the missing files
  394. $img_directory = str_replace('.', '_', $_POST['related_file'].'_files');
  395. $missing_files_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $img_directory);
  396. // Put the uploaded files in the new directory and get the paths
  397. $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);
  398. // Open the html file and replace the paths
  399. replace_img_path_in_html_file($_POST['img_file_path'], $paths_to_replace_in_file, $base_work_dir.$_POST['related_file']);
  400. // Update parent folders
  401. item_property_update_on_folder($_course, $_POST['curdirpath'], $_user['user_id']);
  402. }
  403. }
  404. // They want to create a directory
  405. if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
  406. $added_slash = ($path=='/') ? '' : '/';
  407. $dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']);
  408. $created_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $dir_name, $_POST['dirname']);
  409. if ($created_dir) {
  410. Display::display_confirmation_message(get_lang('DirCr'), false);
  411. $path = $created_dir;
  412. } else {
  413. display_error(get_lang('CannotCreateDir'));
  414. }
  415. }
  416. // Tracking not needed here?
  417. //event_access_tool(TOOL_DOCUMENT);
  418. /* They want to create a new directory */
  419. if (isset($_GET['createdir'])) {
  420. // create the form that asks for the directory name
  421. $new_folder_text = '<form action="'.api_get_self().'" method="POST">';
  422. $new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>';
  423. $new_folder_text .= get_lang('NewDir') .' ';
  424. $new_folder_text .= '<input type="text" name="dirname"/>';
  425. $new_folder_text .= '<button type="submit" class="save" name="create_dir">'.get_lang('CreateFolder').'</button>';
  426. $new_folder_text .= '</form>';
  427. // Show the form
  428. //Display::display_normal_message($new_folder_text, false);
  429. echo create_dir_form();
  430. }
  431. // Actions
  432. echo '<div class="actions">';
  433. // Link back to the documents overview
  434. if ($is_certificate_mode) {
  435. echo '<a href="document.php?curdirpath='.$path.'&selectcat=' . Security::remove_XSS($_GET['selectcat']).'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('CertificateOverview')).get_lang('BackTo').' '.get_lang('CertificateOverview').'</a>';
  436. } else {
  437. echo '<a href="document.php?curdirpath='.$path.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview')).get_lang('BackTo').' '.get_lang('DocumentsOverview').'</a>';
  438. }
  439. // Link to create a folder
  440. if (!isset($_GET['createdir']) && !is_my_shared_folder($_user['user_id'], $path, api_get_session_id()) && !$is_certificate_mode) {
  441. echo '<a href="'.api_get_self().'?path='.$path.'&amp;createdir=1">'.Display::return_icon('folder_new.gif', get_lang('CreateDir')).get_lang('CreateDir').'</a>';
  442. }
  443. echo '</div>';
  444. // Form to select directory
  445. $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit);
  446. if (!$is_certificate_mode) {
  447. echo(build_directory_selector($folders, $path, $group_properties['directory']));
  448. }
  449. $form = new FormValidator('upload', 'POST', api_get_self(), '', 'enctype="multipart/form-data"');
  450. $form->addElement('hidden', 'curdirpath', $path);
  451. $form->addElement('file', 'user_upload', get_lang('File'), 'id="user_upload" size="45"');
  452. $form->addElement('html', '<div class="row" style="font-size:smaller;font-style:italic;"><div class="label">&nbsp;</div><div class="formw">'.get_lang('MaxFileSize').': '.ini_get('upload_max_filesize').'<br/>'.get_lang('DocumentQuota').': '.(round(DocumentManager::get_course_quota()/1000000)-round(documents_total_space($_course)/1000000)).' M</div></div>');
  453. if (api_get_setting('use_document_title') == 'true') {
  454. $form->addElement('text', 'title', get_lang('Title'), array('size' => '20', 'style' => 'width:300px', 'id' => 'title_file'));
  455. $form->addElement('textarea', 'comment', get_lang('Comment'), 'wrap="virtual" style="width:300px;"');
  456. }
  457. // Advanced parameters
  458. $form -> addElement('html', '<div class="row">
  459. <div class="label">&nbsp;</div>
  460. <div class="formw">
  461. <a href="javascript://" onclick=" return advanced_parameters()"><span id="img_plus_and_minus"><div style="vertical-align:top;" ><img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'</div></span></a>
  462. </div>
  463. </div>');
  464. $form -> addElement('html', '<div id="options" style="display:none">');
  465. // Check box options
  466. $form->addElement('checkbox', 'unzip', get_lang('Options'), get_lang('Uncompress'), 'onclick="javascript: check_unzip();" value="1"');
  467. if (api_get_setting('search_enabled') == 'true') {
  468. //TODO: include language file
  469. $supported_formats = 'Supported formats for index: Text plain, PDF, Postscript, MS Word, HTML, RTF, MS Power Point';
  470. $form -> addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument').'<div style="font-size: 80%" >'.$supported_formats.'</div>');
  471. $form -> addElement('html', '<br /><div class="row">');
  472. $form -> addElement('html', '<div class="label">'.get_lang('SearchFeatureDocumentLanguage').'</div>');
  473. $form -> addElement('html', '<div class="formw">'.api_get_languages_combo().'</div>');
  474. $form -> addElement('html', '</div><div class="sub-form">');
  475. $specific_fields = get_specific_field_list();
  476. foreach ($specific_fields as $specific_field) {
  477. $form -> addElement('text', $specific_field['code'], $specific_field['name'].' : ');
  478. }
  479. $form -> addElement('html', '</div>');
  480. }
  481. $form->addElement('radio', 'if_exists', get_lang('UplWhatIfFileExists'), get_lang('UplDoNothing'), 'nothing');
  482. $form->addElement('radio', 'if_exists', '', get_lang('UplOverwriteLong'), 'overwrite');
  483. $form->addElement('radio', 'if_exists', '', get_lang('UplRenameLong'), 'rename');
  484. // Close the java script and avoid the footer up
  485. $form -> addElement('html', '</div>');
  486. // Button send document
  487. $form->addElement('style_submit_button', 'submitDocument', get_lang('SendDocument'), 'class="upload"');
  488. $form->add_real_progress_bar('DocumentUpload', 'user_upload');
  489. $defaults = array('index_document' => 'checked="checked"');
  490. $form->setDefaults($defaults);
  491. $form->display();
  492. // Footer
  493. Display::display_footer();