upload_word.php 7.0 KB

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