upload_ppt.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
  4. /**
  5. * Action controller for the upload process. The display scripts (web forms) redirect
  6. * the process here to do what needs to be done with each file.
  7. *
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. */
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. if (isset($_POST['convert'])) {
  12. $cwdir = getcwd();
  13. if (isset($_FILES['user_file'])) {
  14. $allowed_extensions = ['odp', 'sxi', 'ppt', 'pps', 'sxd', 'pptx'];
  15. if (in_array(
  16. strtolower(pathinfo($_FILES['user_file']['name'], PATHINFO_EXTENSION)),
  17. $allowed_extensions
  18. )) {
  19. require_once api_get_path(SYS_CODE_PATH).'lp/lp_upload.php';
  20. if (isset($o_ppt) && $first_item_id != 0) {
  21. if (api_get_setting('search_enabled') == 'true') {
  22. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  23. $specific_fields = get_specific_field_list();
  24. foreach ($specific_fields as $specific_field) {
  25. $values = explode(',', trim($_POST[$specific_field['code']]));
  26. if (!empty($values)) {
  27. foreach ($values as $value) {
  28. $value = trim($value);
  29. if (!empty($value)) {
  30. add_specific_field_value(
  31. $specific_field['id'],
  32. api_get_course_id(),
  33. TOOL_LEARNPATH,
  34. $o_ppt->lp_id,
  35. $value
  36. );
  37. }
  38. }
  39. }
  40. }
  41. }
  42. header('Location: ../lp/lp_controller.php?'.api_get_cidreq().'&lp_id='.$o_ppt->lp_id.'&action=view_item&id='.$first_item_id);
  43. exit;
  44. } else {
  45. if (!empty($o_ppt->error)) {
  46. $errorMessage = $o_ppt->error;
  47. } else {
  48. $errorMessage = get_lang('The conversion failed for an unknown reason.<br />Please contact your administrator to get more information.');
  49. }
  50. }
  51. } else {
  52. $errorMessage = get_lang('Please upload presentations only. Filename extension should be .ppt or .odp');
  53. }
  54. }
  55. }
  56. Event::event_access_tool(TOOL_UPLOAD);
  57. // check access permissions (edit permission is needed to add a document or a LP)
  58. $is_allowed_to_edit = api_is_allowed_to_edit();
  59. if (!$is_allowed_to_edit) {
  60. api_not_allowed(true);
  61. }
  62. $interbreadcrumb[] = ["url" => "../lp/lp_controller.php?action=list", "name" => get_lang("Document")];
  63. $nameTools = get_lang("Chamilo RAPID : PowerPoint conversion");
  64. Display :: display_header($nameTools);
  65. $message = get_lang('Welcome to Chamilo RAPID<ul type="1"><li>Browse your hard disk to find any .ppt or .odp file<li>Upload it to Oogie. It will convert it into a SCORM course.<li>You will then be allowed to add audio comments on each slide and insert test and activities between slides.');
  66. if (!empty($errorMessage)) {
  67. echo Display::return_message($errorMessage, 'warning', false);
  68. }
  69. $div_upload_limit = get_lang('Upload max size').' : '.ini_get('post_max_size');
  70. $form = new FormValidator('upload_ppt', 'POST', '?'.api_get_cidreq(), '');
  71. $form->addElement('header', get_lang("A PowerPoint to SCORM Courses converter"));
  72. $form->addElement('html', Display::return_message($message, 'info', false));
  73. $form->addElement('file', 'user_file', [Display::return_icon('powerpoint_big.gif'), $div_upload_limit]);
  74. $form->addElement('checkbox', 'take_slide_name', '', get_lang('Use the slides names as course learning object names'));
  75. $options = ChamiloApi::getDocumentConversionSizes();
  76. $form->addElement('select', 'slide_size', get_lang('Size of the slides'), $options);
  77. if (api_get_setting('search_enabled') === 'true') {
  78. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  79. $specific_fields = get_specific_field_list();
  80. $form->addElement('checkbox', 'index_document', '', get_lang('Index document text?ument'));
  81. $form->addSelectLanguage('language', get_lang('SearchFeatureDocumentumentLanguage'));
  82. foreach ($specific_fields as $specific_field) {
  83. $form->addElement('text', $specific_field['code'], $specific_field['name'].' : ');
  84. }
  85. }
  86. $form->addButtonUpload(get_lang('Convert to course'), 'convert');
  87. $form->addElement('hidden', 'ppt2lp', 'true');
  88. $form->addProgress();
  89. $size = api_get_setting('service_ppt2lp', 'size');
  90. $defaults = [
  91. 'take_slide_name' => 'checked="checked"',
  92. 'index_document' => 'checked="checked"',
  93. 'slide_size' => $size,
  94. ];
  95. $form->setDefaults($defaults);
  96. $form->display();
  97. Display::display_footer();