upload_word.php 7.2 KB

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