upload_word.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Action controller for the upload process. The display scripts (web forms)
  5. * redirect
  6. * the process here to do what needs to be done with each file.
  7. * @package chamilo.upload
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. */
  10. include '../inc/global.inc.php';
  11. $form_style= '<style>
  12. .row {
  13. width: 200px;
  14. }
  15. .convert_button{
  16. background: url("'.Display::returnIconPath('learnpath.png').'") 0px 0px no-repeat;
  17. padding: 2px 0px 2px 22px;
  18. }
  19. #dynamic_div_container{float:left;margin-right:10px;}
  20. #dynamic_div_waiter_container{float:left;}
  21. </style>';
  22. $htmlHeadXtra[] = '<script type="text/javascript">
  23. var myUpload = new upload(0);
  24. </script>';
  25. $htmlHeadXtra[] = $form_style;
  26. if (api_get_setting('search.search_enabled') == 'true') {
  27. $specific_fields = get_specific_field_list();
  28. }
  29. if (isset($_POST['convert'])) {
  30. $cwdir = getcwd();
  31. if (isset($_FILES['user_file'])) {
  32. $allowed_extensions = array('doc','docx','odt','txt','sxw','rtf');
  33. if (in_array(strtolower(pathinfo($_FILES['user_file']['name'],PATHINFO_EXTENSION)),$allowed_extensions)) {
  34. require('../newscorm/lp_upload.php');
  35. if (isset($o_doc) && $first_item_id != 0) {
  36. // Search-related section
  37. if (api_get_setting('search.search_enabled') == 'true') {
  38. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  39. $specific_fields = get_specific_field_list();
  40. foreach ($specific_fields as $specific_field) {
  41. $values = explode(',', trim($_POST[$specific_field['code']]));
  42. if (!empty($values)) {
  43. foreach ($values as $value) {
  44. $value = trim($value);
  45. if (!empty($value)) {
  46. add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $o_doc->lp_id, $value);
  47. }
  48. }
  49. }
  50. }
  51. } //end of search-related section
  52. header('Location: ../newscorm/lp_controller.php?'.api_get_cidreq().'&lp_id='.$o_doc->lp_id.'&action=view_item&id='.$first_item_id);
  53. } else {
  54. if (!empty($o_doc->error)) {
  55. $errorMessage = $o_doc->error;
  56. } else {
  57. $errorMessage = get_lang('OogieUnknownError');
  58. }
  59. }
  60. } else {
  61. $errorMessage = get_lang('WoogieBadExtension');
  62. }
  63. }
  64. }
  65. Event::event_access_tool(TOOL_UPLOAD);
  66. // check access permissions (edit permission is needed to add a document or a LP)
  67. $is_allowed_to_edit = api_is_allowed_to_edit();
  68. if (!$is_allowed_to_edit) {
  69. api_not_allowed(true);
  70. }
  71. $interbreadcrumb[]= array ("url"=>"../newscorm/lp_controller.php?action=list", "name"=> get_lang("Doc"));
  72. $nameTools = get_lang("WoogieConversionPowerPoint");
  73. Display :: display_header($nameTools);
  74. echo '<span style="color: #5577af; font-size: 16px; font-family: Arial; margin-left: 10px;">'.get_lang("WelcomeWoogieSubtitle").'</span><br>';
  75. $message = get_lang("WelcomeWoogieConverter");
  76. echo '<br />';
  77. $s_style = "border-width: 1px;
  78. border-style: solid;
  79. margin-left: 0;
  80. margin-top: 10px;
  81. margin-bottom: 0px;
  82. min-height: 30px;
  83. padding: 5px;
  84. position: relative;
  85. width: 500px;
  86. background-color: #E5EDF9;
  87. border-color: #4171B5;
  88. color: #000;";
  89. $s_style_error="border-width: 1px;
  90. border-style: solid;
  91. margin-left: 0;
  92. margin-top: 10px;
  93. margin-bottom: 10px;
  94. min-height: 30px;
  95. padding: 5px;
  96. position: relative;
  97. width: 500px;
  98. background-color: #FFD1D1;
  99. border-color: #FF0000;
  100. color: #000;";
  101. echo '<div style="'.$s_style.'"><div style="float:left; margin-right:10px;">
  102. <img src="'.Display::returnIconPath('message_normal.gif').'" alt="'.$alt_text.'" '.$attribute_list.' /></div><div style="margin-left: 43px">'.$message.'</div></div>';
  103. if (!empty($errorMessage)) {
  104. echo '<div style="'.$s_style_error.'"><div style="float:left; margin-right:10px;">
  105. <img src="'.Display::returnIconPath('message_error.gif').'" alt="'.$alt_text.'" '.$attribute_list.' /></div><div style="margin-left: 43px">'.$errorMessage.'</div></div>';
  106. }
  107. $form = new FormValidator('update_course', 'POST', '', '', 'style="margin: 0;"');
  108. // build the form
  109. $form -> addElement ('html','<br>');
  110. $div_upload_limit = '&nbsp;&nbsp;'.get_lang('UploadMaxSize').' : '.ini_get('post_max_size');
  111. $renderer = $form->defaultRenderer();
  112. // set template for user_file element
  113. $user_file_template =
  114. <<<EOT
  115. <div class="row" style="margin-top:10px;width:100%">
  116. <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}{element}$div_upload_limit
  117. <!-- BEGIN error --><br /><span class="form_error">{error}</span><!-- END error -->
  118. </div>
  119. EOT;
  120. $renderer->setElementTemplate($user_file_template,'user_file');
  121. // set template for other elements
  122. $user_file_template =
  123. <<<EOT
  124. <div class="row" style="margin-top:10px;width:100%">
  125. <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}{element}
  126. <!-- BEGIN error --><br /><span class="form_error">{error}</span><!-- END error -->
  127. </div>
  128. EOT;
  129. $renderer->setCustomElementTemplate($user_file_template);
  130. $form -> addElement ('file', 'user_file', Display::return_icon('word_big.gif'));
  131. if (api_get_setting('search.search_enabled') == 'true') {
  132. $form -> addElement ('checkbox', 'index_document','', get_lang('SearchFeatureDoIndexDocument'));
  133. $form -> addElement ('html','<br />');
  134. $form -> addElement ('html', get_lang('SearchFeatureDocumentLanguage').': &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'. api_get_languages_combo());
  135. $form -> addElement ('html','<div class="sub-form">');
  136. foreach ($specific_fields as $specific_field) {
  137. $form -> addElement ('text', $specific_field['code'], $specific_field['name'].' : ');
  138. }
  139. $form -> addElement ('html','</div>');
  140. }
  141. /*
  142. * commented because SplitStepsPerChapter is not stable at all
  143. * $form -> addElement ('radio', 'split_steps',null, get_lang('SplitStepsPerPage'),'per_page');
  144. * $form -> addElement ('radio', 'split_steps',null, get_lang('SplitStepsPerChapter'),'per_chapter');
  145. */
  146. $form -> addElement ('hidden', 'split_steps','per_page');
  147. $form -> addElement ('submit', 'convert', get_lang('ConvertToLP'), 'class="convert_button"');
  148. $form -> addElement ('hidden', 'woogie', 'true');
  149. $form -> add_real_progress_bar(md5(rand(0,10000)), 'user_file', 1, true);
  150. $defaults = array('split_steps'=>'per_page','index_document'=>'checked="checked"');
  151. $form -> setDefaults($defaults);
  152. // display the form
  153. $form -> display();
  154. Display::display_footer();