webcam_clip.php 8.2 KB

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