upload_word.php 7.2 KB

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