upload_word.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. */
  10. require_once __DIR__.'/../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[] = $form_style;
  23. if (api_get_setting('search_enabled') == 'true') {
  24. $specific_fields = get_specific_field_list();
  25. }
  26. if (isset($_POST['convert'])) {
  27. $cwdir = getcwd();
  28. if (isset($_FILES['user_file'])) {
  29. $allowed_extensions = ['doc', 'docx', 'odt', 'txt', 'sxw', 'rtf'];
  30. if (in_array(strtolower(pathinfo($_FILES['user_file']['name'], PATHINFO_EXTENSION)), $allowed_extensions)) {
  31. require '../lp/lp_upload.php';
  32. if (isset($o_doc) && $first_item_id != 0) {
  33. // Search-related section
  34. if (api_get_setting('search_enabled') == 'true') {
  35. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  36. $specific_fields = get_specific_field_list();
  37. foreach ($specific_fields as $specific_field) {
  38. $values = explode(',', trim($_POST[$specific_field['code']]));
  39. if (!empty($values)) {
  40. foreach ($values as $value) {
  41. $value = trim($value);
  42. if (!empty($value)) {
  43. add_specific_field_value(
  44. $specific_field['id'],
  45. api_get_course_id(),
  46. TOOL_LEARNPATH,
  47. $o_doc->lp_id,
  48. $value
  49. );
  50. }
  51. }
  52. }
  53. }
  54. } //end of search-related section
  55. header('Location: ../lp/lp_controller.php?'.api_get_cidreq().'&lp_id='.$o_doc->lp_id.'&action=view_item&id='.$first_item_id);
  56. } else {
  57. if (!empty($o_doc->error)) {
  58. $errorMessage = $o_doc->error;
  59. } else {
  60. $errorMessage = get_lang('The conversion failed for an unknown reason.<br />Please contact your administrator to get more information.');
  61. }
  62. }
  63. } else {
  64. $errorMessage = get_lang('Please upload text documents only. Filename extension should be .doc, .docx or .odt');
  65. }
  66. }
  67. }
  68. Event::event_access_tool(TOOL_UPLOAD);
  69. // check access permissions (edit permission is needed to add a document or a LP)
  70. $is_allowed_to_edit = api_is_allowed_to_edit();
  71. if (!$is_allowed_to_edit) {
  72. api_not_allowed(true);
  73. }
  74. $interbreadcrumb[] = ["url" => "../lp/lp_controller.php?action=list", "name" => get_lang("Document")];
  75. $nameTools = get_lang("Woogie : Word conversion");
  76. Display :: display_header($nameTools);
  77. echo '<span style="color: #5577af; font-size: 16px; font-family: Arial; margin-left: 10px;">'.
  78. get_lang("MS Word to course converter").'</span><br>';
  79. $message = get_lang('Welcome to Woogie Rapid Learning<ul type="1"><li>Browse your hard disk to find any .doc, .sxw or .odt file<li>Upload it to Woogie. It will convert it into a SCORM course<li>You will then be able to add audio comments on each page and insert quizzes and other activities between pages</ul>');
  80. echo '<br />';
  81. $s_style = "border-width: 1px;
  82. border-style: solid;
  83. margin-left: 0;
  84. margin-top: 10px;
  85. margin-bottom: 0px;
  86. min-height: 30px;
  87. padding: 5px;
  88. position: relative;
  89. width: 500px;
  90. background-color: #E5EDF9;
  91. border-color: #4171B5;
  92. color: #000;";
  93. $s_style_error = "border-width: 1px;
  94. border-style: solid;
  95. margin-left: 0;
  96. margin-top: 10px;
  97. margin-bottom: 10px;
  98. min-height: 30px;
  99. padding: 5px;
  100. position: relative;
  101. width: 500px;
  102. background-color: #FFD1D1;
  103. border-color: #FF0000;
  104. color: #000;";
  105. echo '<div style="'.$s_style.'"><div style="float:left; margin-right:10px;">
  106. <img src="'.Display::returnIconPath('message_normal.png').'" alt="'.$alt_text.'" '.$attribute_list.' /></div>
  107. <div style="margin-left: 43px">'.$message.'</div></div>';
  108. if (!empty($errorMessage)) {
  109. echo '<div style="'.$s_style_error.'"><div style="float:left; margin-right:10px;">
  110. <img src="'.Display::returnIconPath('message_error.png').'" alt="'.$alt_text.'" '.$attribute_list.' /></div>
  111. <div style="margin-left: 43px">'.$errorMessage.'</div></div>';
  112. }
  113. $form = new FormValidator('update_course', 'POST', '', '', 'style="margin: 0;"');
  114. // build the form
  115. $form->addElement('html', '<br>');
  116. $div_upload_limit = '&nbsp;&nbsp;'.get_lang('Upload max size').' : '.ini_get('post_max_size');
  117. $renderer = $form->defaultRenderer();
  118. // set template for user_file element
  119. $user_file_template =
  120. <<<EOT
  121. <div class="row" style="margin-top:10px;width:100%">
  122. <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}{element}$div_upload_limit
  123. <!-- BEGIN error --><br /><span class="form_error">{error}</span><!-- END error -->
  124. </div>
  125. EOT;
  126. $renderer->setElementTemplate($user_file_template, 'user_file');
  127. // set template for other elements
  128. $user_file_template =
  129. <<<EOT
  130. <div class="row" style="margin-top:10px;width:100%">
  131. <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}{element}
  132. <!-- BEGIN error --><br /><span class="form_error">{error}</span><!-- END error -->
  133. </div>
  134. EOT;
  135. $renderer->setCustomElementTemplate($user_file_template);
  136. $form->addElement('file', 'user_file', Display::return_icon('word_big.gif'));
  137. if (api_get_setting('search_enabled') === 'true') {
  138. $form->addElement('checkbox', 'index_document', '', get_lang('Index document text?ument'));
  139. $form->addElement('html', '<br />');
  140. $form->addElement(
  141. 'html',
  142. get_lang(
  143. 'SearchFeatureDocumentumentLanguage'
  144. ).': &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.api_get_languages_combo()
  145. );
  146. $form->addElement('html', '<div class="sub-form">');
  147. foreach ($specific_fields as $specific_field) {
  148. $form->addElement('text', $specific_field['code'], $specific_field['name'].' : ');
  149. }
  150. $form->addElement('html', '</div>');
  151. }
  152. /*
  153. * commented because A section, a learning object is not stable at all
  154. * $form -> addElement ('radio', 'split_steps',null, get_lang('A page, a learning object'),'per_page');
  155. * $form -> addElement ('radio', 'split_steps',null, get_lang('A section, a learning object'),'per_chapter');
  156. */
  157. $form->addElement('hidden', 'split_steps', 'per_page');
  158. $form->addElement('submit', 'convert', get_lang('Convert to course'), 'class="convert_button"');
  159. $form->addElement('hidden', 'woogie', 'true');
  160. $form->addProgress();
  161. $defaults = ['split_steps' => 'per_page', 'index_document' => 'checked="checked"'];
  162. $form->setDefaults($defaults);
  163. // display the form
  164. $form->display();
  165. Display::display_footer();