webcam_clip.php 7.9 KB

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