webcam_clip.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This file allows record wav files.
  6. *
  7. * @package chamilo.document
  8. *
  9. * @author Juan Carlos Raña Trabado herodoto@telefonica.net
  10. *
  11. * @since 7/jun/2012
  12. * @Updated 04/09/2015 Upgrade to WebCamJS
  13. */
  14. require_once __DIR__.'/../inc/global.inc.php';
  15. $_SESSION['whereami'] = 'document/webcamclip';
  16. $this_section = SECTION_COURSES;
  17. $nameTools = get_lang('Webcam Clip');
  18. $htmlHeadXtra[] = api_get_js_simple(api_get_path(WEB_PATH).'web/assets/webcamjs/webcam.js');
  19. $htmlHeadXtra[] = api_get_js('webcam_recorder.js');
  20. $groupRights = Session::read('group_member_with_upload_rights');
  21. api_protect_course_script();
  22. api_block_anonymous_users();
  23. $userId = api_get_user_id();
  24. $courseCode = api_get_course_id();
  25. $groupId = api_get_group_id();
  26. $sessionId = api_get_session_id();
  27. $documentData = DocumentManager::get_document_data_by_id($_GET['id'], $courseCode, true);
  28. if (empty($documentData)) {
  29. if (api_is_in_group()) {
  30. $groupProperties = GroupManager::get_group_properties($groupId);
  31. $documentId = DocumentManager::get_document_id(
  32. api_get_course_info(),
  33. $groupProperties['directory']
  34. );
  35. $documentData = DocumentManager::get_document_data_by_id($documentId, $courseCode);
  36. }
  37. }
  38. $documentId = $documentData['id'];
  39. $dir = $documentData['path'];
  40. //make some vars
  41. $webcamdir = $dir;
  42. if ($webcamdir == "/") {
  43. $webcamdir = '';
  44. }
  45. $isAllowedToEdit = api_is_allowed_to_edit(null, true);
  46. // Please, do not modify this dirname formatting
  47. if (strstr($dir, '..')) {
  48. $dir = '/';
  49. }
  50. if ($dir[0] == '.') {
  51. $dir = substr($dir, 1);
  52. }
  53. if ($dir[0] != '/') {
  54. $dir = '/'.$dir;
  55. }
  56. if ($dir[strlen($dir) - 1] != '/') {
  57. $dir .= '/';
  58. }
  59. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  60. if (!is_dir($filepath)) {
  61. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  62. $dir = '/';
  63. }
  64. if (!empty($groupId)) {
  65. $interbreadcrumb[] = [
  66. "url" => "../group/group_space.php?".api_get_cidreq(),
  67. "name" => get_lang('Group area'),
  68. ];
  69. $noPHP_SELF = true;
  70. $group = GroupManager::get_group_properties($groupId);
  71. $path = explode('/', $dir);
  72. if ('/'.$path[1] != $group['directory']) {
  73. api_not_allowed(true);
  74. }
  75. }
  76. $interbreadcrumb[] = [
  77. "url" => "./document.php?id=".$documentId."&".api_get_cidreq(),
  78. "name" => get_lang('Documents'),
  79. ];
  80. if (!api_is_allowed_in_course()) {
  81. api_not_allowed(true);
  82. }
  83. $isMySharedFolder = DocumentManager::is_my_shared_folder($userId, Security::remove_XSS($dir), $sessionId);
  84. if (!($isAllowedToEdit || $groupRights || $isMySharedFolder)) {
  85. api_not_allowed(true);
  86. }
  87. /* Header */
  88. Event::event_access_tool(TOOL_DOCUMENT);
  89. $displayDir = $dir;
  90. if (isset($group)) {
  91. $displayDir = explode('/', $dir);
  92. unset($displayDir[0]);
  93. unset($displayDir[1]);
  94. $displayDir = implode('/', $displayDir);
  95. }
  96. // Interbreadcrumb for the current directory root path
  97. $counter = 0;
  98. if (isset($documentData['parents'])) {
  99. foreach ($documentData['parents'] as $documentSubData) {
  100. //fixing double group folder in breadcrumb
  101. if ($groupId) {
  102. if ($counter == 0) {
  103. $counter++;
  104. continue;
  105. }
  106. }
  107. $interbreadcrumb[] = [
  108. 'url' => $documentSubData['document_url'],
  109. 'name' => $documentSubData['title'],
  110. ];
  111. $counter++;
  112. }
  113. }
  114. $actions = Display::toolbarAction(
  115. 'webcam_toolbar',
  116. [
  117. Display::url(
  118. Display::return_icon(
  119. 'back.png',
  120. get_lang('Back to').' '.get_lang('Documents overview'),
  121. [],
  122. ICON_SIZE_MEDIUM
  123. ),
  124. 'document.php?id='.$documentId.'&'.api_get_cidreq()
  125. ),
  126. ]
  127. );
  128. $template = new Template($nameTools);
  129. $template->assign('webcam_dir', $webcamdir);
  130. $template->assign('user_id', $userId);
  131. $template->assign('filename', 'video_clip.jpg');
  132. $layout = $template->get_template('document/webcam.tpl');
  133. $content = $template->fetch($layout);
  134. $template->assign('header', get_lang('Take your photos'));
  135. $template->assign('actions', $actions);
  136. $template->assign('content', $content);
  137. $template->display_one_col_template();