webcam_clip.php 7.3 KB

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