upload_word.php 7.0 KB

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