webcam_clip.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file allows record wav files.
  5. *
  6. * @package chamilo.document
  7. *
  8. * @author Juan Carlos Raña Trabado herodoto@telefonica.net
  9. * @since 7/jun/2012
  10. * @Updated 04/09/2015 Upgrade to WebCamJS
  11. */
  12. require_once '../inc/global.inc.php';
  13. $_SESSION['whereami'] = 'document/webcamclip';
  14. $this_section = SECTION_COURSES;
  15. $nameTools = get_lang('WebCamClip');
  16. api_protect_course_script();
  17. api_block_anonymous_users();
  18. $document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id(), true);
  19. if (empty($document_data)) {
  20. if (api_is_in_group()) {
  21. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  22. $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
  23. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  24. }
  25. }
  26. $document_id = $document_data['id'];
  27. $dir = $document_data['path'];
  28. //make some vars
  29. $webcamdir=$dir;
  30. if($webcamdir=="/"){
  31. $webcamdir="";
  32. }
  33. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  34. // Please, do not modify this dirname formatting
  35. if (strstr($dir, '..')) {
  36. $dir = '/';
  37. }
  38. if ($dir[0] == '.') {
  39. $dir = substr($dir, 1);
  40. }
  41. if ($dir[0] != '/') {
  42. $dir = '/'.$dir;
  43. }
  44. if ($dir[strlen($dir) - 1] != '/') {
  45. $dir .= '/';
  46. }
  47. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  48. if (!is_dir($filepath)) {
  49. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  50. $dir = '/';
  51. }
  52. $groupId = api_get_group_id();
  53. if (!empty($groupId)) {
  54. $interbreadcrumb[] = array ("url" => "../group/group_space.php?".api_get_cidreq(), "name" => get_lang('GroupSpace'));
  55. $noPHP_SELF = true;
  56. $group = GroupManager :: get_group_properties($groupId);
  57. $path = explode('/', $dir);
  58. if ('/'.$path[1] != $group['directory']) {
  59. api_not_allowed(true);
  60. }
  61. }
  62. $interbreadcrumb[] = array ("url" => "./document.php?id=".$document_id."&".api_get_cidreq(), "name" => get_lang('Documents'));
  63. if (!$is_allowed_in_course) {
  64. api_not_allowed(true);
  65. }
  66. if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] ||
  67. DocumentManager::is_my_shared_folder(api_get_user_id(), Security::remove_XSS($dir),api_get_session_id()))) {
  68. api_not_allowed(true);
  69. }
  70. /* Header */
  71. Event::event_access_tool(TOOL_DOCUMENT);
  72. $display_dir = $dir;
  73. if (isset ($group)) {
  74. $display_dir = explode('/', $dir);
  75. unset ($display_dir[0]);
  76. unset ($display_dir[1]);
  77. $display_dir = implode('/', $display_dir);
  78. }
  79. // Interbreadcrumb for the current directory root path
  80. $counter = 0;
  81. if (isset($document_data['parents'])) {
  82. foreach($document_data['parents'] as $document_sub_data) {
  83. //fixing double group folder in breadcrumb
  84. if (api_get_group_id()) {
  85. if ($counter == 0) {
  86. $counter++;
  87. continue;
  88. }
  89. }
  90. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  91. $counter++;
  92. }
  93. }
  94. //make some vars
  95. $webcamuserid=api_get_user_id();
  96. Display :: display_header($nameTools, 'Doc');
  97. echo '<div class="actions">';
  98. echo '<a href="document.php?id='.$document_id.'">'.
  99. Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
  100. echo '</div>';
  101. ?>
  102. <div align="center">
  103. <h2><?php echo get_lang('TakeYourPhotos'); ?></h2>
  104. </div>
  105. <div align="center">
  106. <table><tr><td valign='top' align='center'>
  107. <h3 align='center'><?php echo get_lang('LocalInputImage'); ?></h3>
  108. <!-- Including New Lib WebCamJS upgrading from JPEGCam -->
  109. <script type="text/javascript" src="<?php echo api_get_path(WEB_PATH); ?>web/assets/webcamjs/webcam.js"></script>
  110. <!-- Adding a div container for the new live camera with some cool style options-->
  111. <div class="webcamclip_bg">
  112. <div id="chamilo-camera"></div>
  113. </div>
  114. <!-- Configure a few settings and attach the camera to the div container -->
  115. <script language="JavaScript">
  116. Webcam.set({
  117. width: 320,
  118. height: 240,
  119. image_format: 'jpeg',
  120. jpeg_quality: 90
  121. });
  122. Webcam.attach( '#chamilo-camera' );
  123. //This line Fix a minor bug that made a conflict with a videochat feature in another module file
  124. $('video').addClass('skip');
  125. </script>
  126. <!-- Using now Jquery to do the webcamJS Functions and handle the server response (see webcam_receiver.php now in webcamJS directory) -->
  127. <script language="JavaScript">
  128. $(document).ready(function() {
  129. $('#btnCapture').click(function() {
  130. Webcam.freeze();
  131. return false;
  132. });
  133. $('#btnClean').click(function() {
  134. Webcam.unfreeze();
  135. return false;
  136. });
  137. $('#btnSave').click(function() {
  138. snap();
  139. return false;
  140. });
  141. $('#btnAuto').click(function() {
  142. start_video();
  143. return false;
  144. });
  145. $('#btnStop').click(function() {
  146. stop_video();
  147. return false;
  148. });
  149. });
  150. function snap() {
  151. Webcam.snap( function(data_uri) {
  152. var clip_filename='video_clip.jpg';
  153. var url = 'webcam_receiver.php?webcamname='+escape(clip_filename)+'&webcamdir=<?php echo $webcamdir; ?>&webcamuserid=<?php echo $webcamuserid; ?>';
  154. Webcam.upload(data_uri, url, function(code, response){
  155. $('#upload_results').html(
  156. '<h3>'+response+'</h3>' +
  157. '<div>'+
  158. '<img src="' + data_uri + '" class="webcamclip_bg">' +
  159. '</div>'+
  160. '</div>'+
  161. '<p hidden="true">'+code+'</p>'
  162. );
  163. });
  164. });
  165. }
  166. </script>
  167. <script language=javascript>
  168. var interval=null;
  169. var timeout=null;
  170. var counter=0;
  171. var fps=1000;//one frame per second
  172. var maxclip=25;//maximum number of clips
  173. var maxtime=60000;//stop after one minute
  174. function stop_video() {
  175. interval=window.clearInterval(interval);
  176. return false;
  177. }
  178. function start_video() {
  179. interval=window.setInterval("clip_send_video()",fps);
  180. }
  181. function clip_send_video() {
  182. counter++;
  183. timeout=setTimeout('stop_video()',maxtime);
  184. if(maxclip>=counter){
  185. snap();// clip and upload
  186. }
  187. else {
  188. interval=window.clearInterval(interval);
  189. }
  190. }
  191. </script>
  192. </td><td width=50></td><td valign='top' align='center'>
  193. <div id="upload_results" style="background-color:#ffffff;"></div>
  194. </td></tr></table>
  195. <!-- Implementing Button html5 Tags instead Inputs and some cool bootstrap button styles -->
  196. <div>
  197. <br/>
  198. <form>
  199. <br/>
  200. <button id="btnCapture" class="btn btn-danger">
  201. <em class="fa fa-camera"></em>
  202. <?php echo get_lang('Snapshot'); ?>
  203. </button>
  204. <button id="btnClean" class="btn btn-success">
  205. <em class="fa fa-refresh"></em>
  206. <?php echo get_lang('Clean'); ?>
  207. </button>
  208. <button id="btnSave" class="btn btn-primary">
  209. <em class="fa fa-save"></em>
  210. <?php echo get_lang('Save'); ?>
  211. </button>
  212. &nbsp;&nbsp;||&nbsp;&nbsp;
  213. <button id="btnAuto" class="btn btn-default">
  214. <?php echo get_lang('Auto'); ?>
  215. </button>
  216. <button id="btnStop" class="btn btn-default">
  217. <?php echo get_lang('Stop'); ?>
  218. </button>
  219. <br/>
  220. </form>
  221. <br/>
  222. </div>
  223. </div>
  224. <?php
  225. Display :: display_footer();