upload_word.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php // $Id$
  2. /**
  3. * Action controller for the upload process. The display scripts (web forms) redirect
  4. * the process here to do what needs to be done with each file.
  5. * @package dokeos.upload
  6. * @author Yannick Warnier <ywarnier@beeznest.org>
  7. */
  8. /**
  9. * First, initialise the script
  10. */
  11. // name of the language file which needs to be included
  12. // 'inc.php' is automatically appended to the file name
  13. $language_file[] = "document"; //the document file is loaded because most of the upload vocab relates to the document tool
  14. $language_file[] = "learnpath";
  15. $language_file[] = "scormdocument";
  16. // global settings initialisation
  17. // also provides access to main api (inc/lib/main_api.lib.php)
  18. include("../inc/global.inc.php");
  19. require_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  20. require_once(api_get_path(LIBRARY_PATH) . 'events.lib.inc.php');
  21. require_once(api_get_path(LIBRARY_PATH) . 'document.lib.php');
  22. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  23. $form_style= '
  24. <style>
  25. .row {
  26. width: 200px;
  27. }
  28. .convert_button{
  29. background: url("../img/scorm.gif") 0px 0px no-repeat;
  30. padding: 2px 0px 2px 22px;
  31. }
  32. #dynamic_div_container{float:left;margin-right:10px;}
  33. #dynamic_div_waiter_container{float:left;}
  34. </style>';
  35. $htmlHeadXtra[] = '<script language="javascript" src="../inc/lib/javascript/upload.js" type="text/javascript"></script>';
  36. $htmlHeadXtra[] = '<script type="text/javascript">
  37. var myUpload = new upload(0);
  38. </script>';
  39. $htmlHeadXtra[] = $form_style;
  40. if (api_get_setting('search_enabled')=='true')
  41. {
  42. $specific_fields = get_specific_field_list();
  43. }
  44. if(isset($_POST['convert'])){
  45. $cwdir = getcwd();
  46. if(isset($_FILES['user_file']))
  47. {
  48. $allowed_extensions = array('doc','docx','odt','txt','sxw','rtf');
  49. if(in_array(strtolower(pathinfo($_FILES['user_file']['name'],PATHINFO_EXTENSION)),$allowed_extensions))
  50. {
  51. require('../newscorm/lp_upload.php');
  52. if(isset($o_doc) && $first_item_id != 0){
  53. if (api_get_setting('search_enabled')=='true') {
  54. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  55. $specific_fields = get_specific_field_list();
  56. foreach ($specific_fields as $specific_field) {
  57. $values = explode(',', trim($_POST[$specific_field['code']]));
  58. if ( !empty($values) ) {
  59. foreach ($values as $value) {
  60. $value = trim($value);
  61. if ( !empty($value) ) {
  62. add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $o_doc->lp_id, $value);
  63. }
  64. }
  65. }
  66. }
  67. }
  68. header('Location: ../newscorm/lp_controller.php?'.api_get_cidreq().'&lp_id='.$o_doc->lp_id.'&action=view_item&id='.$first_item_id);
  69. }
  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. {
  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/woogie.gif"><br>
  94. <span style="color: #5577af; font-size: 16px; font-family: Arial; margin-left: 10px;"><?php echo get_lang("WelcomeWoogieSubtitle");?></span><br>
  95. <?php
  96. $message=get_lang("WelcomeWoogieConverter");
  97. echo '<br>';
  98. $s_style="border-width: 1px;
  99. border-style: solid;
  100. margin-left: 0;
  101. margin-top: 10px;
  102. margin-bottom: 0px;
  103. min-height: 30px;
  104. padding: 5px;
  105. position: relative;
  106. width: 500px;
  107. background-color: #E5EDF9;
  108. border-color: #4171B5;
  109. color: #000;";
  110. $s_style_error="border-width: 1px;
  111. border-style: solid;
  112. margin-left: 0;
  113. margin-top: 10px;
  114. margin-bottom: 10px;
  115. min-height: 30px;
  116. padding: 5px;
  117. position: relative;
  118. width: 500px;
  119. background-color: #FFD1D1;
  120. border-color: #FF0000;
  121. color: #000;";
  122. 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>';
  123. if(!empty($errorMessage)){
  124. 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>';
  125. }
  126. $form = new FormValidator('update_course', 'POST', '', '', 'style="margin: 0;"');
  127. // build the form
  128. $form -> addElement ('html','<br>');
  129. $div_upload_limit = '&nbsp;&nbsp;'.get_lang('UploadMaxSize').' : '.ini_get('post_max_size');
  130. $renderer = & $form->defaultRenderer();
  131. // set template for user_file element
  132. $user_file_template =
  133. <<<EOT
  134. <div class="row" style="margin-top:10px;width:100%">
  135. <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}{element}$div_upload_limit
  136. <!-- BEGIN error --><br /><span class="form_error">{error}</span><!-- END error -->
  137. </div>
  138. EOT;
  139. $renderer->setElementTemplate($user_file_template,'user_file');
  140. // set template for other elements
  141. $user_file_template =
  142. <<<EOT
  143. <div class="row" style="margin-top:10px;width:100%">
  144. <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}{element}
  145. <!-- BEGIN error --><br /><span class="form_error">{error}</span><!-- END error -->
  146. </div>
  147. EOT;
  148. $renderer->setElementTemplate($user_file_template);
  149. $form -> addElement ('file', 'user_file','<img src="../img/word_big.gif" align="absbottom" />');
  150. if (api_get_setting('search_enabled')=='true')
  151. {
  152. $form -> addElement ('checkbox', 'index_document','', get_lang('SearchFeatureDoIndexDocument'));
  153. $form -> addElement ('html','<br />');
  154. $form -> addElement ('html', get_lang('SearchFeatureDocumentLanguage').': &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'. api_get_languages_combo());
  155. $form -> addElement ('html','<div class="sub-form">');
  156. foreach ($specific_fields as $specific_field) {
  157. $form -> addElement ('text', $specific_field['code'], $specific_field['name'].' : ');
  158. }
  159. $form -> addElement ('html','</div>');
  160. }
  161. /*
  162. * commented because SplitStepsPerChapter is not stable at all
  163. * $form -> addElement ('radio', 'split_steps',null, get_lang('SplitStepsPerPage'),'per_page');
  164. * $form -> addElement ('radio', 'split_steps',null, get_lang('SplitStepsPerChapter'),'per_chapter');
  165. */
  166. $form -> addElement ('hidden', 'split_steps','per_page');
  167. $form -> addElement ('submit', 'convert', get_lang('ConvertToLP'), 'class="convert_button"');
  168. $form -> addElement ('hidden', 'woogie', 'true');
  169. $form -> add_real_progress_bar(md5(rand(0,10000)), 'user_file', 1, true);
  170. $defaults = array('split_steps'=>'per_page','index_document'=>'checked="checked"');
  171. $form -> setDefaults($defaults);
  172. // display the form
  173. $form -> display();
  174. /*
  175. ==============================================================================
  176. FOOTER
  177. ==============================================================================
  178. */
  179. Display::display_footer();
  180. ?>