Browse Source

Feature #4596
upload wami audio record with a select name and avoid duplicates

Juan Carlos Raña 13 years ago
parent
commit
7c40f57c20
2 changed files with 36 additions and 24 deletions
  1. 19 20
      main/document/record_audio_wami.php
  2. 17 4
      main/inc/lib/wami-recorder/record_document.php

+ 19 - 20
main/document/record_audio_wami.php

@@ -77,22 +77,6 @@ if (!is_dir($filepath)) {
 	$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
 	$dir = '/';
 }
-//make some vars
-//$waminame="audiorecord.wav";
-$wamiuserid=api_get_user_id();
-$userinfo=Database::get_user_info_from_id($wamiuserid);
-$waminame = api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'.wav';
-$waminame = replace_dangerous_char($waminame, 'strict');
-
-
-$waminame_noex=basename($waminame, ".wav");
-$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
-$saveDir=$dirBaseDocuments.$wamidir;
-if (file_exists($saveDir.'/'.$waminame)){ 
-		$i = 1;		
-		while (file_exists($saveDir.'/'.$waminame_noex.'_'.$i.'.wav')) $i++;
-		$waminame = $waminame_noex . '_' . $i . '.wav';
-}
 
 //groups //TODO: clean
 if (isset ($_SESSION['_gid']) && $_SESSION['_gid'] != 0) {
@@ -145,6 +129,10 @@ if (isset($document_data['parents'])) {
     }
 }
 
+
+//make some vars
+$wamiuserid=api_get_user_id();
+
 Display :: display_header($nameTools, 'Doc');
 echo '<div class="actions">';
 		echo '<a href="document.php?id='.$document_id.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
@@ -161,7 +149,8 @@ echo '</div>';
 <!-- GUI code... take it or leave it -->
 <script type="text/javascript" src="<?php echo api_get_path(WEB_LIBRARY_PATH) ?>wami-recorder/gui.js"></script>
 
-<script>
+<script type="text/javascript">
+
 	function setupRecorder() {
 		Wami.setup({
 			id : "wami",
@@ -170,10 +159,14 @@ echo '</div>';
 	}
 
 	function setupGUI() {
+		var waminame = document.getElementById("audio_title").value+".wav";//adding name file and extension
+		document.getElementById('audio_title').style.display='none';
+		document.getElementById('audio_button').style.display='none';
+		
 		var gui = new Wami.GUI({
 			id : "wami",
-			recordUrl : "<?php echo api_get_path(WEB_LIBRARY_PATH) ?>wami-recorder/record_document.php?waminame=<?php echo $waminame; ?>&wamidir=<?php echo $wamidir; ?>&wamiuserid=<?php echo $wamiuserid; ?>",
-			playUrl : 	"<?php echo $wamiurlplay.$waminame; ?>",
+			recordUrl : "<?php echo api_get_path(WEB_LIBRARY_PATH) ?>wami-recorder/record_document.php?waminame="+waminame+"&wamidir=<?php echo $wamidir; ?>&wamiuserid=<?php echo $wamiuserid; ?>",
+			playUrl : 	"<?php echo $wamiurlplay; ?>"+waminame,
 			buttonUrl : "<?php echo api_get_path(WEB_LIBRARY_PATH) ?>wami-recorder/buttons.png",
 			swfUrl : 	"<?php echo api_get_path(WEB_LIBRARY_PATH) ?>wami-recorder/Wami.swf",
 		});
@@ -183,8 +176,15 @@ echo '</div>';
 
 </script>
 
+
 <div id="wami" style="margin-left: 460px; margin-top:50px;"></div>
 <div align="center" style="margin-top:200px;">
+
+<form name="form_wami_recorder">
+<input placeholder="<?php echo get_lang('Filename'); ?>" type="text" id="audio_title">
+<button class="upload" type="button" value="" onClick="setupRecorder()" id="audio_button" /><?php echo get_lang('Send'); ?></button>
+</form>
+
 <?php
 
 Display::display_normal_message(get_lang('VoiceRecord'), false);
@@ -192,7 +192,6 @@ Display::display_normal_message(get_lang('VoiceRecord'), false);
 ?>
 
 </div>
-<body onLoad="setupRecorder()">
 
 <?php
 

+ 17 - 4
main/inc/lib/wami-recorder/record_document.php

@@ -49,9 +49,22 @@ $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
 $saveDir=$dirBaseDocuments.$wamidir;
 $current_session_id = api_get_session_id();
 $groupId=$_SESSION['_gid'];
-$documentPath = $saveDir.'/'.$waminame;
-$title=str_replace('_',' ',$waminame);
-//$title=basename($waminame, ".wav");//save title whitout extension
+
+//avoid duplicates
+$waminame_to_save=$waminame;
+$title_to_save=str_replace('_',' ',$waminame);
+$waminame_noex=basename($waminame, ".wav");
+if (file_exists($saveDir.'/'.$waminame_noex.'.'.$ext)){ 
+		$i = 1;		
+		while (file_exists($saveDir.'/'.$waminame_noex.'_'.$i.'.'.$ext)) $i++;
+		$waminame_to_save = $waminame_noex . '_' . $i . '.'.$ext;
+		$title_to_save = $waminame_noex . '_' . $i . '.'.$ext;
+		$title_to_save = str_replace('_',' ',$title_to_save);
+}
+
+
+$documentPath = $saveDir.'/'.$waminame_to_save;
+
 
 //add to disk
 $fh = fopen($documentPath, 'w') or die("can't open file");
@@ -59,6 +72,6 @@ fwrite($fh, $content);
 fclose($fh);
 
 //add document to database
-	$doc_id = add_document($_course, $wamidir.'/'.$waminame, 'file', filesize($documentPath), $title);
+	$doc_id = add_document($_course, $wamidir.'/'.$waminame_to_save, 'file', filesize($documentPath), $title_to_save);
 	api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
 ?>