upload_word.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. // Search-related section
  47. if (api_get_setting('search_enabled') == 'true') {
  48. require_once(api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php');
  49. $specific_fields = get_specific_field_list();
  50. foreach ($specific_fields as $specific_field) {
  51. $values = explode(',', trim($_POST[$specific_field['code']]));
  52. if (!empty($values)) {
  53. foreach ($values as $value) {
  54. $value = trim($value);
  55. if (!empty($value)) {
  56. add_specific_field_value(
  57. $specific_field['id'],
  58. api_get_course_id(),
  59. TOOL_LEARNPATH,
  60. $o_doc->lp_id,
  61. $value
  62. );
  63. }
  64. }
  65. }
  66. }
  67. } //end of search-related section
  68. header('Location: ../newscorm/lp_controller.php?'.api_get_cidreq().'&lp_id='.$o_doc->lp_id.'&action=view_item&id='.$first_item_id);
  69. exit;
  70. } else {
  71. if (!empty($o_doc->error)) {
  72. $errorMessage = $o_doc->error;
  73. } else {
  74. $errorMessage = get_lang('OogieUnknownError');
  75. }
  76. }
  77. } else {
  78. $errorMessage = get_lang('WoogieBadExtension');
  79. }
  80. }
  81. }
  82. event_access_tool(TOOL_UPLOAD);
  83. // check access permissions (edit permission is needed to add a document or a LP)
  84. $is_allowed_to_edit = api_is_allowed_to_edit();
  85. if (!$is_allowed_to_edit) {
  86. api_not_allowed(true);
  87. }
  88. $interbreadcrumb[] = array("url" => "../newscorm/lp_controller.php?action=list", "name" => get_lang("Doc"));
  89. $nameTools = get_lang("WoogieConversionPowerPoint");
  90. Display :: display_header($nameTools);
  91. //echo '<img src="../img/mascot.png"><br />';
  92. echo '<span style="color: #5577af; font-size: 16px; font-family: Arial; margin-left: 10px;">'.get_lang("WelcomeWoogieSubtitle").'</span><br>';
  93. $message = get_lang("WelcomeWoogieConverter");
  94. echo '<br />';
  95. $s_style = "border-width: 1px;
  96. border-style: solid;
  97. margin-left: 0;
  98. margin-top: 10px;
  99. margin-bottom: 0px;
  100. min-height: 30px;
  101. padding: 5px;
  102. position: relative;
  103. width: 500px;
  104. background-color: #E5EDF9;
  105. border-color: #4171B5;
  106. color: #000;";
  107. $s_style_error = "border-width: 1px;
  108. border-style: solid;
  109. margin-left: 0;
  110. margin-top: 10px;
  111. margin-bottom: 10px;
  112. min-height: 30px;
  113. padding: 5px;
  114. position: relative;
  115. width: 500px;
  116. background-color: #FFD1D1;
  117. border-color: #FF0000;
  118. color: #000;";
  119. 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>';
  120. if (!empty($errorMessage)) {
  121. 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>';
  122. }
  123. $form = new FormValidator('update_course', 'POST', '', '', 'style="margin: 0;"');
  124. // build the form
  125. $form->addElement('html', '<br>');
  126. $div_upload_limit = '&nbsp;&nbsp;'.get_lang('UploadMaxSize').' : '.ini_get('post_max_size');
  127. $renderer = $form->defaultRenderer();
  128. // set template for user_file element
  129. $user_file_template =
  130. <<<EOT
  131. <div class="row" style="margin-top:10px;width:100%">
  132. <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}{element}$div_upload_limit
  133. <!-- BEGIN error --><br /><span class="form_error">{error}</span><!-- END error -->
  134. </div>
  135. EOT;
  136. $renderer->setElementTemplate($user_file_template, 'user_file');
  137. // set template for other elements
  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}
  142. <!-- BEGIN error --><br /><span class="form_error">{error}</span><!-- END error -->
  143. </div>
  144. EOT;
  145. $renderer->setElementTemplate($user_file_template);
  146. $form->addElement('file', 'user_file', '<img src="../img/word_big.gif" align="absbottom" />');
  147. if (api_get_setting('search_enabled') == 'true') {
  148. $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument'));
  149. $form->addElement('html', '<br />');
  150. $form->addElement ('html', get_lang('SearchFeatureDocumentLanguage').': &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'. api_get_languages_combo());
  151. $form->addElement('html', '<div class="sub-form">');
  152. foreach ($specific_fields as $specific_field) {
  153. $form->addElement('text', $specific_field['code'], $specific_field['name'].' : ');
  154. }
  155. $form->addElement('html', '</div>');
  156. }
  157. /*
  158. * commented because SplitStepsPerChapter is not stable at all
  159. * $form -> addElement ('radio', 'split_steps',null, get_lang('SplitStepsPerPage'),'per_page');
  160. * $form -> addElement ('radio', 'split_steps',null, get_lang('SplitStepsPerChapter'),'per_chapter');
  161. */
  162. $form->addElement('hidden', 'split_steps', 'per_page');
  163. $form->addElement('submit', 'convert', get_lang('ConvertToLP'), 'class="convert_button"');
  164. $form->addElement('hidden', 'woogie', 'true');
  165. $form->add_real_progress_bar(md5(rand(0, 10000)), 'user_file', 1, true);
  166. $defaults = array('split_steps' => 'per_page', 'index_document' => 'checked="checked"');
  167. $form->setDefaults($defaults);
  168. // display the form
  169. $form->display();
  170. Display::display_footer();