webcam_clip.php 7.2 KB

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