upload_word.php 7.8 KB

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