upload_word.php 7.7 KB

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