webcam_clip.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. */
  11. require_once '../inc/global.inc.php';
  12. $_SESSION['whereami'] = 'document/webcamclip';
  13. $this_section = SECTION_COURSES;
  14. $nameTools = get_lang('WebCamClip');
  15. api_protect_course_script();
  16. api_block_anonymous_users();
  17. $document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id(), true);
  18. if (empty($document_data)) {
  19. if (api_is_in_group()) {
  20. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  21. $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
  22. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  23. }
  24. }
  25. $document_id = $document_data['id'];
  26. $dir = $document_data['path'];
  27. //make some vars
  28. $webcamdir=$dir;
  29. if($webcamdir=="/"){
  30. $webcamdir="";
  31. }
  32. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  33. // Please, do not modify this dirname formatting
  34. if (strstr($dir, '..')) {
  35. $dir = '/';
  36. }
  37. if ($dir[0] == '.') {
  38. $dir = substr($dir, 1);
  39. }
  40. if ($dir[0] != '/') {
  41. $dir = '/'.$dir;
  42. }
  43. if ($dir[strlen($dir) - 1] != '/') {
  44. $dir .= '/';
  45. }
  46. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  47. if (!is_dir($filepath)) {
  48. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  49. $dir = '/';
  50. }
  51. $groupId = api_get_group_id();
  52. if (!empty($groupId)) {
  53. $interbreadcrumb[] = array ("url" => "../group/group_space.php?".api_get_cidreq(), "name" => get_lang('GroupSpace'));
  54. $noPHP_SELF = true;
  55. $group = GroupManager :: get_group_properties($groupId);
  56. $path = explode('/', $dir);
  57. if ('/'.$path[1] != $group['directory']) {
  58. api_not_allowed(true);
  59. }
  60. }
  61. $interbreadcrumb[] = array ("url" => "./document.php?id=".$document_id."&".api_get_cidreq(), "name" => get_lang('Documents'));
  62. if (!$is_allowed_in_course) {
  63. api_not_allowed(true);
  64. }
  65. if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] ||
  66. DocumentManager::is_my_shared_folder(api_get_user_id(), Security::remove_XSS($dir),api_get_session_id()))) {
  67. api_not_allowed(true);
  68. }
  69. /* Header */
  70. Event::event_access_tool(TOOL_DOCUMENT);
  71. $display_dir = $dir;
  72. if (isset ($group)) {
  73. $display_dir = explode('/', $dir);
  74. unset ($display_dir[0]);
  75. unset ($display_dir[1]);
  76. $display_dir = implode('/', $display_dir);
  77. }
  78. // Interbreadcrumb for the current directory root path
  79. $counter = 0;
  80. if (isset($document_data['parents'])) {
  81. foreach($document_data['parents'] as $document_sub_data) {
  82. //fixing double group folder in breadcrumb
  83. if (api_get_group_id()) {
  84. if ($counter == 0) {
  85. $counter++;
  86. continue;
  87. }
  88. }
  89. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  90. $counter++;
  91. }
  92. }
  93. //make some vars
  94. $webcamuserid=api_get_user_id();
  95. Display :: display_header($nameTools, 'Doc');
  96. echo '<div class="actions">';
  97. echo '<a href="document.php?id='.$document_id.'">'.
  98. Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
  99. echo '</div>';
  100. ?>
  101. <div align="center">
  102. <h2><?php echo get_lang('TakeYourPhotos'); ?></h2>
  103. </div>
  104. <div align="center" style="padding-left:50px;">
  105. <table><tr><td valign=top>
  106. <h3><?php echo get_lang('LocalInputImage'); ?></h3>
  107. <!-- First, include the JPEGCam JavaScript Library -->
  108. <script type="text/javascript" src="<?php echo api_get_path(WEB_LIBRARY_PATH); ?>jpegcam/webcam.js"></script>
  109. <!-- Configure a few settings -->
  110. <script language="JavaScript">
  111. var clip_filename='video_clip.jpg';
  112. //var clip_filename='<?php //echo date('YmdHis') . '.jpg'; ?>';
  113. webcam.set_swf_url ( '<?php echo api_get_path(WEB_LIBRARY_PATH); ?>jpegcam//webcam.swf?blackboard.png' );
  114. webcam.set_shutter_sound( true,'<?php echo api_get_path(WEB_LIBRARY_PATH); ?>jpegcam/shutter.mp3' ); // true play shutter click sound
  115. webcam.set_quality( 90 ); // JPEG quality (1 - 100)
  116. webcam.set_api_url( '<?php echo api_get_path(WEB_LIBRARY_PATH); ?>jpegcam/webcam_receiver.php?webcamname='+escape(clip_filename)+'&webcamdir=<?php echo $webcamdir; ?>&webcamuserid=<?php echo $webcamuserid; ?>' );
  117. </script>
  118. <!-- Next, write the movie to the page at 320x240 -->
  119. <script language="JavaScript">
  120. document.write( webcam.get_html(320, 240) );
  121. </script>
  122. <!-- Some buttons for controlling things -->
  123. <br/>
  124. <form>
  125. <br/>
  126. <input type=button value="<?php echo get_lang('Snapshot'); ?>" onClick="webcam.freeze()">
  127. <input type=button value="<?php echo get_lang('Clean'); ?>" onClick="webcam.reset()">
  128. <input type=button value="<?php echo get_lang('Send'); ?>" onClick="do_upload()">
  129. &nbsp;&nbsp;||&nbsp;&nbsp;
  130. <input type=button value="<?php echo get_lang('Auto'); ?>" onClick="start_video();">
  131. <input type=button value="<?php echo get_lang('Stop'); ?>" onClick="stop_video()">
  132. <br/>
  133. <input type=button value="<?php echo get_lang('Configure'); ?>" onClick="webcam.configure()">
  134. </form>
  135. <!-- Code to handle the server response (see webcam_receiver.php) -->
  136. <script language="JavaScript">
  137. webcam.set_hook( 'onComplete', 'my_completion_handler' );
  138. function do_upload() {
  139. // upload to server
  140. if (this.loaded){
  141. document.getElementById('upload_results').innerHTML = '<h3><?php echo get_lang('Uploading'); ?></h3>';
  142. }
  143. webcam.upload();
  144. }
  145. function my_completion_handler(msg) {
  146. // extract URL out of PHP output
  147. if (msg.match(/(http\:\/\/\S+)/)) {
  148. var image_url = RegExp.$1;
  149. image_url=image_url.replace(/\\/g,'/').replace( /.*\//, '' );// extract basename
  150. image_url='<?php echo api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'.$dir;?>'+image_url+'<?php echo '?'.api_get_cidreq(); ?>';
  151. // show JPEG image in page
  152. document.getElementById('upload_results').innerHTML =
  153. '<div style="width: 320px;">' +
  154. '<h3><?php echo get_lang('ClipSent'); ?></h3>' +
  155. '<img src="' + image_url + '">' +
  156. '</div>';
  157. // reset camera for another shot
  158. webcam.reset();
  159. }
  160. else alert("PHP Error: " + msg);
  161. }
  162. </script>
  163. <script language=javascript>
  164. var internaval=null;
  165. var timeout=null;
  166. var counter=0;
  167. var fps=1000;//one frame per second
  168. var maxclip=25;//maximum number of clips
  169. var maxtime=60000;//stop after one minute
  170. function stop_video() {
  171. interval=window.clearInterval(interval);
  172. }
  173. function start_video() {
  174. webcam.set_stealth( true ); // do not freeze image upon capture
  175. interval=window.setInterval("clip_send_video()",fps);
  176. }
  177. function clip_send_video() {
  178. counter++
  179. timeout=setTimeout('stop_video()',maxtime);
  180. if(maxclip>=counter){
  181. webcam.snap();// clip and upload
  182. }
  183. else {
  184. interval=window.clearInterval(interval);
  185. }
  186. }
  187. </script>
  188. </td><td width=50>&nbsp;</td><td valign=top>
  189. <div id="upload_results" style="background-color:#ffffff;"></div>
  190. </td></tr></table>
  191. </div>
  192. <?php
  193. Display :: display_footer();