Add voice recorder button when sending a msg in the chamilo inbox

See BT#14453
pull/2573/head
Julio 8 years ago
parent 6eb782a7a6
commit 0a345a939a
  1. 1
      main/document/record_audio.php
  2. 116
      main/inc/ajax/record_audio_rtc.ajax.php
  3. 192
      main/inc/ajax/record_audio_wami.ajax.php
  4. 22
      main/inc/lib/api.lib.php
  5. 13
      main/inc/lib/javascript/record_audio/record_audio.js
  6. 72
      main/inc/lib/message.lib.php
  7. 76
      main/messages/new_message.php
  8. 24
      main/messages/record_audio.php
  9. 4
      main/messages/view_message.php
  10. 4
      main/template/default/document/record_audio.tpl
  11. 72
      main/template/default/message/record_audio.tpl

@ -153,6 +153,7 @@ $actions = Display::toolbarButton(
$template = new Template($nameTools); $template = new Template($nameTools);
$template->assign('directory', $wamidir); $template->assign('directory', $wamidir);
$template->assign('user_id', api_get_user_id()); $template->assign('user_id', api_get_user_id());
$template->assign('reload_page', 1);
$layout = $template->get_template('document/record_audio.tpl'); $layout = $template->get_template('document/record_audio.tpl');
$content = $template->fetch($layout); $content = $template->fetch($layout);

@ -6,12 +6,17 @@ use ChamiloSession as Session;
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
// Add security from Chamilo // Add security from Chamilo
api_protect_course_script();
api_block_anonymous_users(); api_block_anonymous_users();
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
/** @var string $tool document or exercise */ /** @var string $tool document or exercise */
$tool = isset($_REQUEST['tool']) ? $_REQUEST['tool'] : ''; $tool = isset($_REQUEST['tool']) ? $_REQUEST['tool'] : '';
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'document'; // can be document or message
if ($type == 'document') {
api_protect_course_script();
}
$userId = api_get_user_id(); $userId = api_get_user_id();
if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) { if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) {
@ -33,57 +38,64 @@ if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) {
} }
$file = isset($_FILES['audio_blob']) ? $_FILES['audio_blob'] : []; $file = isset($_FILES['audio_blob']) ? $_FILES['audio_blob'] : [];
$audioDir = Security::remove_XSS($_REQUEST['audio_dir']);
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
$saveDir = $dirBaseDocuments.$audioDir;
if (!is_dir($saveDir)) {
mkdir($saveDir, api_get_permissions_for_new_directories(), true);
}
$file['file'] = $file; $file['file'] = $file;
$audioDir = Security::remove_XSS($_REQUEST['audio_dir']);
$uploadedDocument = DocumentManager::upload_document( switch ($type) {
$file, case 'document':
$audioDir, $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
$file['name'], $saveDir = $dirBaseDocuments.$audioDir;
null, if (!is_dir($saveDir)) {
0, mkdir($saveDir, api_get_permissions_for_new_directories(), true);
'overwrite', }
false, $uploadedDocument = DocumentManager::upload_document(
in_array($tool, ['document', 'exercise']) $file,
); $audioDir,
$file['name'],
$error = empty($uploadedDocument) || !is_array($uploadedDocument); null,
0,
if (!$error) { 'overwrite',
$newDocId = $uploadedDocument['id']; false,
$courseId = $uploadedDocument['c_id']; in_array($tool, ['document', 'exercise'])
);
/** @var learnpath $lp */
$lp = Session::read('oLP'); $error = empty($uploadedDocument) || !is_array($uploadedDocument);
$lpItemId = isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id']) ? $_REQUEST['lp_item_id'] : null;
if (!empty($lp) && empty($lpItemId)) { if (!$error) {
$lp->set_modified_on(); $newDocId = $uploadedDocument['id'];
$courseId = $uploadedDocument['c_id'];
$lpItem = new learnpathItem($lpItemId);
$lpItem->add_audio_from_documents($newDocId); /** @var learnpath $lp */
} $lp = Session::read('oLP');
$lpItemId = isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id']) ? $_REQUEST['lp_item_id'] : null;
$data = DocumentManager::get_document_data_by_id($newDocId, $courseInfo['code']); if (!empty($lp) && empty($lpItemId)) {
$lp->set_modified_on();
if ($tool === 'exercise') {
header('Content-Type: application/json'); $lpItem = new learnpathItem($lpItemId);
echo json_encode([ $lpItem->add_audio_from_documents($newDocId);
'error' => $error, }
'message' => Display::getFlashToString(),
'fileUrl' => $data['document_url'], $data = DocumentManager::get_document_data_by_id($newDocId, $courseInfo['code']);
]);
if ($tool === 'exercise') {
Display::cleanFlashMessages(); header('Content-Type: application/json');
exit; echo json_encode([
} 'error' => $error,
'message' => Display::getFlashToString(),
echo $data['document_url']; 'fileUrl' => $data['document_url'],
]);
Display::cleanFlashMessages();
exit;
}
echo $data['document_url'];
}
break;
case 'message':
Session::write('current_audio_id', $file['name']);
api_upload_file('audio_message', $file, api_get_user_id());
break;
} }

@ -6,7 +6,6 @@ use ChamiloSession as Session;
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
// Add security from Chamilo // Add security from Chamilo
api_protect_course_script();
api_block_anonymous_users(); api_block_anonymous_users();
$_course = api_get_course_info(); $_course = api_get_course_info();
@ -28,6 +27,12 @@ if (empty($wamiuserid)) {
die(); die();
} }
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'document'; // can be document or message
if ($type === 'document') {
api_protect_course_script();
}
// Clean // Clean
$waminame = Security::remove_XSS($waminame); $waminame = Security::remove_XSS($waminame);
$waminame = Database::escape_string($waminame); $waminame = Database::escape_string($waminame);
@ -47,95 +52,106 @@ if ($ext != 'wav') {
die(); die();
} }
// Do not use here check Fileinfo method because return: text/plain switch ($type) {
case 'document':
// Do not use here check Fileinfo method because return: text/plain
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$saveDir = $dirBaseDocuments.$wamidir;
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; if (!is_dir($saveDir)) {
$saveDir = $dirBaseDocuments.$wamidir; DocumentManager::createDefaultAudioFolder($_course);
}
if (!is_dir($saveDir)) {
DocumentManager::createDefaultAudioFolder($_course);
}
//avoid duplicates // Avoid duplicates
$waminame_to_save = $waminame; $waminame_to_save = $waminame;
//$waminame_noex = basename($waminame, ".wav"); $documentPath = $saveDir.'/'.$waminame_to_save;
//if (file_exists($saveDir.'/'.$waminame_noex.'.'.$ext)) {
// $i = 1; // Add to disk
// while (file_exists($saveDir.'/'.$waminame_noex.'_'.$i.'.'.$ext)) { $fh = fopen($documentPath, 'w') or die("can't open file");
// $i++; fwrite($fh, $content);
// } fclose($fh);
// $waminame_to_save = $waminame_noex.'_'.$i.'.'.$ext;
//} $fileInfo = pathinfo($documentPath);
$courseInfo = api_get_course_info();
$documentPath = $saveDir.'/'.$waminame_to_save;
$file = [
// Add to disk 'file' => [
$fh = fopen($documentPath, 'w') or die("can't open file"); 'name' => $fileInfo['basename'],
fwrite($fh, $content); 'tmp_name' => $documentPath,
fclose($fh); 'size' => filesize($documentPath),
'type' => 'audio/wav',
$fileInfo = pathinfo($documentPath); 'from_file' => true,
$courseInfo = api_get_course_info(); ],
];
$file = [ $output = true;
'file' => [ ob_start();
'name' => $fileInfo['basename'],
'tmp_name' => $documentPath, // Strangely the file path changes with a double extension
'size' => filesize($documentPath), copy($documentPath, $documentPath.'.wav');
'type' => 'audio/wav',
'from_file' => true, $documentData = DocumentManager::upload_document(
], $file,
]; $wamidir,
$output = true; $fileInfo['basename'],
ob_start(); 'wav',
0,
// Strangely the file path changes with a double extension 'overwrite',
copy($documentPath, $documentPath.'.wav'); false,
$output
$documentData = DocumentManager::upload_document( );
$file, $contents = ob_get_contents();
$wamidir,
$fileInfo['basename'], if (!empty($documentData)) {
'wav', $newDocId = $documentData['id'];
0, $documentData['comment'] = 'mp3';
'overwrite', $newMp3DocumentId = DocumentManager::addAndConvertWavToMp3(
false, $documentData,
$output $courseInfo,
); api_get_session_id(),
$contents = ob_get_contents(); api_get_user_id(),
'overwrite',
if (!empty($documentData)) { true
$newDocId = $documentData['id']; );
$documentData['comment'] = 'mp3';
$newMp3DocumentId = DocumentManager::addAndConvertWavToMp3( if ($newMp3DocumentId) {
$documentData, $newDocId = $newMp3DocumentId;
$courseInfo, }
api_get_session_id(),
api_get_user_id(), if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) {
'overwrite', $lpItemId = $_REQUEST['lp_item_id'];
true /** @var learnpath $lp */
); $lp = Session::read('oLP');
if ($newMp3DocumentId) { if (!empty($lp)) {
$newDocId = $newMp3DocumentId; $lp->set_modified_on();
} $lpItem = new learnpathItem($lpItemId);
$lpItem->add_audio_from_documents($newDocId);
if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) { echo Display::return_message(get_lang('Updated'), 'info');
$lpItemId = $_REQUEST['lp_item_id']; }
/** @var learnpath $lp */ }
$lp = Session::read('oLP');
// Strangely the file path changes with a double extension
if (!empty($lp)) { // Remove file with one extension
$lp->set_modified_on(); unlink($documentPath);
$lpItem = new learnpathItem($lpItemId); } else {
$lpItem->add_audio_from_documents($newDocId); echo $contents;
echo Display::return_message(get_lang('Updated'), 'info');
} }
}
// Strangely the file path changes with a double extension break;
// Remove file with one extension case 'message':
unlink($documentPath); $tempFile = api_get_path(SYS_ARCHIVE_PATH).$waminame;
} else { file_put_contents($tempFile, $content);
echo $contents;
Session::write('current_audio_id', $waminame);
$file = [
'name' => basename($tempFile),
'tmp_name' => $tempFile,
'size' => filesize($tempFile),
'type' => 'audio/wav',
'move_file' => true,
];
api_upload_file('audio_message', $file, api_get_user_id());
break;
} }

@ -8979,8 +8979,8 @@ function api_upload_file($type, $file, $itemId, $cropParameters = '')
} }
$pathToSave = $path.$name; $pathToSave = $path.$name;
$result = moveUploadedFile($file, $pathToSave);
$result = move_uploaded_file($file['tmp_name'], $pathToSave);
if ($result) { if ($result) {
if (!empty($cropParameters)) { if (!empty($cropParameters)) {
$image = new Image($pathToSave); $image = new Image($pathToSave);
@ -9063,6 +9063,26 @@ function api_remove_uploaded_file($type, $file)
} }
} }
/**
* @param string $type
* @param int $itemId
* @param string $file
*
* @return bool
*/
function api_remove_uploaded_file_by_id($type, $itemId, $file)
{
$file = api_get_uploaded_file($type, $itemId, $file, false);
$typePath = api_get_path(SYS_UPLOAD_PATH).$type;
if (Security::check_abs_path($file, $typePath) && file_exists($file) && is_file($file)) {
unlink($file);
return true;
}
return false;
}
/** /**
* Converts string value to float value. * Converts string value to float value.
* *

@ -13,7 +13,7 @@ window.RecordAudio = (function () {
btnSave = rtcInfo.btnSaveId ? $(rtcInfo.btnSaveId) : null, btnSave = rtcInfo.btnSaveId ? $(rtcInfo.btnSaveId) : null,
tagAudio = $(rtcInfo.plyrPreviewId); tagAudio = $(rtcInfo.plyrPreviewId);
function saveAudio () { function saveAudio() {
var recordedBlob = recordRTC.getBlob(); var recordedBlob = recordRTC.getBlob();
if (!recordedBlob) { if (!recordedBlob) {
@ -28,7 +28,7 @@ window.RecordAudio = (function () {
formData.append('audio_dir', rtcInfo.directory); formData.append('audio_dir', rtcInfo.directory);
$.ajax({ $.ajax({
url: _p.web_ajax + 'record_audio_rtc.ajax.php?tool=' + (!!txtName.length ? 'document' : 'exercise'), url: _p.web_ajax + 'record_audio_rtc.ajax.php?type='+rtcInfo.type+'&tool=' + (!!txtName.length ? 'document' : 'exercise'),
data: formData, data: formData,
processData: false, processData: false,
contentType: false, contentType: false,
@ -44,8 +44,10 @@ window.RecordAudio = (function () {
} }
}).done(function (response) { }).done(function (response) {
if (!!txtName.length) { if (!!txtName.length) {
window.location.reload(); if (rtcInfo.reload_page == 1) {
return; window.location.reload();
return;
}
} }
$(response.message).insertAfter($(rtcInfo.blockId).find('.well')); $(response.message).insertAfter($(rtcInfo.blockId).find('.well'));
@ -194,7 +196,8 @@ window.RecordAudio = (function () {
recordUrl: _p.web_ajax + 'record_audio_wami.ajax.php?' + $.param({ recordUrl: _p.web_ajax + 'record_audio_wami.ajax.php?' + $.param({
waminame: fileName + '.wav', waminame: fileName + '.wav',
wamidir: wamiInfo.directory, wamidir: wamiInfo.directory,
wamiuserid: wamiInfo.userId wamiuserid: wamiInfo.userId,
type: wamiInfo.type
}), }),
buttonUrl: _p.web_lib + 'wami-recorder/buttons.png', buttonUrl: _p.web_lib + 'wami-recorder/buttons.png',
buttonNoUrl: _p.web_img + 'blank.gif' buttonNoUrl: _p.web_img + 'blank.gif'

@ -302,16 +302,17 @@ class MessageManager
* @param int $receiver_user_id * @param int $receiver_user_id
* @param string $subject * @param string $subject
* @param string $content * @param string $content
* @param array $attachments files array($_FILES) (optional) * @param array $attachments files array($_FILES) (optional)
* @param array $fileCommentList about attachment files (optional) * @param array $fileCommentList about attachment files (optional)
* @param int $group_id (optional) * @param int $group_id (optional)
* @param int $parent_id (optional) * @param int $parent_id (optional)
* @param int $editMessageId id for updating the message (optional) * @param int $editMessageId id for updating the message (optional)
* @param int $topic_id (optional) the default value is the current user_id * @param int $topic_id (optional) the default value is the current user_id
* @param int $sender_id * @param int $sender_id
* @param bool $directMessage * @param bool $directMessage
* @param int $forwardId * @param int $forwardId
* @param array $smsParameters * @param array $smsParameters
* @param bool $checkCurrentAudioId
* *
* @return bool * @return bool
*/ */
@ -328,7 +329,8 @@ class MessageManager
$sender_id = 0, $sender_id = 0,
$directMessage = false, $directMessage = false,
$forwardId = 0, $forwardId = 0,
$smsParameters = [] $smsParameters = [],
$checkCurrentAudioId = false
) { ) {
$table = Database::get_main_table(TABLE_MESSAGE); $table = Database::get_main_table(TABLE_MESSAGE);
$group_id = (int) $group_id; $group_id = (int) $group_id;
@ -372,6 +374,27 @@ class MessageManager
} }
} }
if ($checkCurrentAudioId) {
// Add the audio file as an attachment
$audioId = Session::read('current_audio_id');
if (!empty($audioId)) {
$file = api_get_uploaded_file('audio_message', api_get_user_id(), $audioId);
if (!empty($file)) {
$audioAttachment = [
'name' => basename($file),
'comment' => 'audio_message',
'size' => filesize($file),
'tmp_name' => $file,
'error' => 0,
'type' => DocumentManager::file_get_mime_type(basename($file)),
];
// create attachment from audio message
$attachmentList[] = $audioAttachment;
}
}
}
// Validating fields // Validating fields
if (empty($subject) && empty($group_id)) { if (empty($subject) && empty($group_id)) {
Display::addFlash( Display::addFlash(
@ -423,7 +446,7 @@ class MessageManager
// Forward also message attachments // Forward also message attachments
if (!empty($forwardId)) { if (!empty($forwardId)) {
$attachments = MessageManager::getAttachmentList($forwardId); $attachments = self::getAttachmentList($forwardId);
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
if (!empty($attachment['file_source'])) { if (!empty($attachment['file_source'])) {
$file = [ $file = [
@ -1211,14 +1234,14 @@ class MessageManager
public static function showMessageBox($messageId, $source = 'inbox') public static function showMessageBox($messageId, $source = 'inbox')
{ {
$table = Database::get_main_table(TABLE_MESSAGE); $table = Database::get_main_table(TABLE_MESSAGE);
$messageId = intval($messageId); $messageId = (int) $messageId;
if ($source == 'outbox') { if ($source == 'outbox') {
if (isset($messageId) && is_numeric($messageId)) { if (isset($messageId) && is_numeric($messageId)) {
$query = "SELECT * FROM $table $query = "SELECT * FROM $table
WHERE WHERE
user_sender_id = ".api_get_user_id()." AND user_sender_id = ".api_get_user_id()." AND
id = ".$messageId." AND id = $messageId AND
msg_status = ".MESSAGE_STATUS_OUTBOX; msg_status = ".MESSAGE_STATUS_OUTBOX;
$result = Database::query($query); $result = Database::query($query);
} }
@ -1890,16 +1913,23 @@ class MessageManager
// get file attachments by message id // get file attachments by message id
$list = []; $list = [];
if ($files) { if ($files) {
$attach_icon = Display::return_icon('attachment.gif', ''); $attachIcon = Display::return_icon('attachment.gif', '');
$archiveURL = api_get_path(WEB_CODE_PATH).'messages/download.php?type='.$type.'&file='; $archiveURL = api_get_path(WEB_CODE_PATH).'messages/download.php?type='.$type.'&file=';
foreach ($files as $row_file) { foreach ($files as $row_file) {
$archiveFile = $row_file['path']; $archiveFile = $row_file['path'];
$filename = $row_file['filename']; $filename = $row_file['filename'];
$filesize = format_file_size($row_file['size']); $size = format_file_size($row_file['size']);
$filecomment = Security::remove_XSS($row_file['comment']); $comment = Security::remove_XSS($row_file['comment']);
$filename = Security::remove_XSS($filename); $filename = Security::remove_XSS($filename);
$list[] = $attach_icon.'&nbsp;<a href="'.$archiveURL.$archiveFile.'">'.$filename.'</a> $link = Display::url($filename, $archiveURL.$archiveFile);
&nbsp;('.$filesize.')'.(!empty($filecomment) ? '&nbsp;-&nbsp;<i>'.$filecomment.'</i>' : ''); $comment = !empty($comment) ? '&nbsp;-&nbsp;<i>'.$comment.'</i>' : '';
$attachmentLine = $attachIcon.'&nbsp;'.$link.'&nbsp;('.$size.')'.$comment;
if ($row_file['comment'] == 'audio_message') {
$attachmentLine = '<audio src="'.$archiveURL.$archiveFile.'"/>';
}
$list[] = $attachmentLine;
} }
} }
@ -2522,4 +2552,16 @@ class MessageManager
return $row['count']; return $row['count'];
} }
/**
* Clean audio messages already added in the message tool
*/
public static function cleanAudioMessage()
{
$audioId = Session::read('current_audio_id');
if (!empty($audioId)) {
api_remove_uploaded_file_by_id('audio_message', api_get_user_id(), $audioId);
Session::erase('current_audio_id');
}
}
} }

@ -23,7 +23,6 @@ if (api_get_setting('allow_message_tool') !== 'true') {
} }
$allowSocial = api_get_setting('allow_social_tool') == 'true'; $allowSocial = api_get_setting('allow_social_tool') == 'true';
$nameTools = api_xml_http_response_encode(get_lang('Messages')); $nameTools = api_xml_http_response_encode(get_lang('Messages'));
$htmlHeadXtra[] = '<script> $htmlHeadXtra[] = '<script>
@ -52,24 +51,28 @@ function add_image_form() {
</script>'; </script>';
$nameTools = get_lang('ComposeMessage'); $nameTools = get_lang('ComposeMessage');
$tpl = new Template(get_lang('ComposeMessage'));
/** /**
* Shows the compose area + a list of users to select from. * Shows the compose area + a list of users to select from.
*/ */
function show_compose_to_any($user_id) function show_compose_to_any($tpl)
{ {
$default['user_list'] = 0; $default['user_list'] = 0;
$online_user_list = null; $html = manageForm($default, null, null, $tpl);
$html = manageForm($default, $online_user_list);
return $html; return $html;
} }
function show_compose_reply_to_message($message_id, $receiver_id) function show_compose_reply_to_message($message_id, $receiver_id, $tpl)
{ {
$table = Database::get_main_table(TABLE_MESSAGE); $table = Database::get_main_table(TABLE_MESSAGE);
$receiver_id = (int) $receiver_id;
$message_id = (int) $message_id;
$query = "SELECT user_sender_id $query = "SELECT user_sender_id
FROM $table FROM $table
WHERE user_receiver_id = ".intval($receiver_id)." AND id = ".intval($message_id); WHERE user_receiver_id = ".$receiver_id." AND id = ".$message_id;
$result = Database::query($query); $result = Database::query($query);
$row = Database::fetch_array($result, 'ASSOC'); $row = Database::fetch_array($result, 'ASSOC');
$userInfo = api_get_user_info($row['user_sender_id']); $userInfo = api_get_user_info($row['user_sender_id']);
@ -80,33 +83,34 @@ function show_compose_reply_to_message($message_id, $receiver_id)
} }
$default['users'] = [$row['user_sender_id']]; $default['users'] = [$row['user_sender_id']];
$html = manageForm($default, null, $userInfo['complete_name_with_username']); $html = manageForm($default, null, $userInfo['complete_name_with_username'], $tpl);
return $html; return $html;
} }
function show_compose_to_user($receiver_id) function show_compose_to_user($receiver_id, $tpl)
{ {
$userInfo = api_get_user_info($receiver_id); $userInfo = api_get_user_info($receiver_id);
$html = get_lang('To').':&nbsp;<strong>'.$userInfo['complete_name'].'</strong>'; $html = get_lang('To').':&nbsp;<strong>'.$userInfo['complete_name'].'</strong>';
$default['title'] = api_xml_http_response_encode(get_lang('EnterTitle')); $default['title'] = api_xml_http_response_encode(get_lang('EnterTitle'));
$default['users'] = [$receiver_id]; $default['users'] = [$receiver_id];
$html .= manageForm($default); $html .= manageForm($default, null, '', $tpl);
return $html; return $html;
} }
/** /**
* @param $default * @param $default
* @param null $select_from_user_list * @param null $select_from_user_list
* @param string $sent_to * @param string $sent_to
* @param Template $tpl
* *
* @return string * @return string
*/ */
function manageForm($default, $select_from_user_list = null, $sent_to = '') function manageForm($default, $select_from_user_list = null, $sent_to = '', $tpl = null)
{ {
$group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null; $group_id = isset($_REQUEST['group_id']) ? (int) $_REQUEST['group_id'] : null;
$message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null; $message_id = isset($_GET['message_id']) ? (int) $_GET['message_id'] : null;
$form = new FormValidator( $form = new FormValidator(
'compose_message', 'compose_message',
@ -115,6 +119,7 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
null, null,
['enctype' => 'multipart/form-data'] ['enctype' => 'multipart/form-data']
); );
if (empty($group_id)) { if (empty($group_id)) {
if (isset($select_from_user_list)) { if (isset($select_from_user_list)) {
$form->addText( $form->addText(
@ -170,8 +175,8 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
if (isset($_GET['re_id'])) { if (isset($_GET['re_id'])) {
$message_reply_info = MessageManager::get_message_by_id($_GET['re_id']); $message_reply_info = MessageManager::get_message_by_id($_GET['re_id']);
$default['title'] = get_lang('MailSubjectReplyShort')." ".$message_reply_info['title']; $default['title'] = get_lang('MailSubjectReplyShort').' '.$message_reply_info['title'];
$form->addHidden('re_id', intval($_GET['re_id'])); $form->addHidden('re_id', (int) $_GET['re_id']);
$form->addHidden('save_form', 'save_form'); $form->addHidden('save_form', 'save_form');
// Adding reply mail // Adding reply mail
@ -204,8 +209,7 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
} }
if (empty($group_id)) { if (empty($group_id)) {
$form->addElement( $form->addLabel(
'label',
'', '',
'<div id="file_uploads"><div id="filepath_1"> '<div id="file_uploads"><div id="filepath_1">
<div id="filepaths" class="form-horizontal"> <div id="filepaths" class="form-horizontal">
@ -221,13 +225,12 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
</div> </div>
</div> </div>
</div> </div>
</div> </div>'
'
); );
$form->addLabel( $form->addLabel(
'', '',
'<span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()">'. '<span id="link-more-attach"><a class="btn btn-default" href="javascript://" onclick="return add_image_form()">'.
get_lang('AddOneMoreFile').'</a></span>&nbsp;('. get_lang('AddOneMoreFile').'</a></span>&nbsp;('.
sprintf( sprintf(
get_lang('MaximunFileSizeX'), get_lang('MaximunFileSizeX'),
@ -236,6 +239,13 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
); );
} }
$form->addLabel(
'',
'<iframe
frameborder="0" height="200" width="100%" scrolling="no"
src="'.api_get_path(WEB_CODE_PATH).'messages/record_audio.php"></iframe>'
);
$form->addButtonSend(get_lang('SendMessage'), 'compose'); $form->addButtonSend(get_lang('SendMessage'), 'compose');
$form->setRequiredNote('<span class="form_required">*</span> <small>'.get_lang('ThisFieldIsRequired').'</small>'); $form->setRequiredNote('<span class="form_required">*</span> <small>'.get_lang('ThisFieldIsRequired').'</small>');
@ -262,7 +272,7 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
$forwardId = isset($_POST['forward_id']) ? $_POST['forward_id'] : false; $forwardId = isset($_POST['forward_id']) ? $_POST['forward_id'] : false;
if (is_array($user_list) && count($user_list) > 0) { if (is_array($user_list) && count($user_list) > 0) {
//all is well, send the message // All is well, send the message
foreach ($user_list as $userId) { foreach ($user_list as $userId) {
$res = MessageManager::send_message( $res = MessageManager::send_message(
$userId, $userId,
@ -276,7 +286,9 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
0, 0,
null, null,
false, false,
$forwardId $forwardId,
[],
true
); );
if ($res) { if ($res) {
@ -288,6 +300,7 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
)); ));
} }
} }
MessageManager::cleanAudioMessage();
} else { } else {
Display::addFlash(Display::return_message('ErrorSendingMessage', 'error')); Display::addFlash(Display::return_message('ErrorSendingMessage', 'error'));
} }
@ -369,12 +382,13 @@ if (!isset($_POST['compose'])) {
if (isset($_GET['re_id'])) { if (isset($_GET['re_id'])) {
$social_right_content .= show_compose_reply_to_message( $social_right_content .= show_compose_reply_to_message(
$_GET['re_id'], $_GET['re_id'],
api_get_user_id() api_get_user_id(),
$tpl
); );
} elseif (isset($_GET['send_to_user'])) { } elseif (isset($_GET['send_to_user'])) {
$social_right_content .= show_compose_to_user($_GET['send_to_user']); $social_right_content .= show_compose_to_user($_GET['send_to_user'], $tpl);
} else { } else {
$social_right_content .= show_compose_to_any(api_get_user_id()); $social_right_content .= show_compose_to_any($tpl);
} }
} else { } else {
$restrict = false; $restrict = false;
@ -391,19 +405,19 @@ if (!isset($_POST['compose'])) {
// comes from a reply button // comes from a reply button
if (isset($_GET['re_id']) || isset($_GET['forward_id'])) { if (isset($_GET['re_id']) || isset($_GET['forward_id'])) {
$social_right_content .= manageForm($default); $social_right_content .= manageForm($default, null, null, $tpl);
} else { } else {
// post // post
if ($restrict) { if ($restrict) {
if (!isset($_POST['group_id'])) { if (!isset($_POST['group_id'])) {
$default['users'] = isset($_POST['users']) ? $_POST['users'] : null; $default['users'] = isset($_POST['users']) ? $_POST['users'] : null;
} else { } else {
$default['group_id'] = $_POST['group_id']; $default['group_id'] = (int) $_POST['group_id'];
} }
if (isset($_POST['hidden_user'])) { if (isset($_POST['hidden_user'])) {
$default['users'] = [$_POST['hidden_user']]; $default['users'] = [$_POST['hidden_user']];
} }
$social_right_content .= manageForm($default); $social_right_content .= manageForm($default, null, null, $tpl);
} else { } else {
$social_right_content .= Display::return_message(get_lang('ErrorSendingMessage'), 'error'); $social_right_content .= Display::return_message(get_lang('ErrorSendingMessage'), 'error');
} }
@ -415,10 +429,10 @@ if ($allowSocial) {
$social_right_content .= '</div>'; $social_right_content .= '</div>';
} }
$tpl = new Template(get_lang('ComposeMessage'));
// Block Social Avatar // Block Social Avatar
SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'messages'); SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'messages');
MessageManager::cleanAudioMessage();
if ($allowSocial) { if ($allowSocial) {
$tpl->assign('social_menu_block', $social_menu_block); $tpl->assign('social_menu_block', $social_menu_block);
$tpl->assign('social_right_content', $social_right_content); $tpl->assign('social_right_content', $social_right_content);

@ -0,0 +1,24 @@
<?php
/* For licensing terms, see /license.txt */
require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users();
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'rtc/RecordRTC.js"></script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/recorder.js"></script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/gui.js"></script>';
$htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'swfobject/swfobject.js"></script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'swfobject/swfobject.js"></script>';
$htmlHeadXtra[] = api_get_js('record_audio/record_audio.js');
$tpl = new Template(get_lang('ComposeMessage'), false, false, false, true);
$record = $tpl->get_template('message/record_audio.tpl');
$tpl->assign('user_id', api_get_user_id());
$tpl->assign('audio_title', api_get_unique_id());
$tpl->assign('reload_page', 0);
$tpl->assign('content', $tpl->fetch($record));
$tpl->display_no_layout_template();
exit;

@ -12,8 +12,8 @@ if (api_get_setting('allow_message_tool') != 'true') {
api_not_allowed(true); api_not_allowed(true);
} }
$allowSocial = api_get_setting('allow_social_tool') == 'true'; $allowSocial = api_get_setting('allow_social_tool') === 'true';
$allowMessage = api_get_setting('allow_message_tool') == 'true'; $allowMessage = api_get_setting('allow_message_tool') === 'true';
if ($allowSocial) { if ($allowSocial) {
$this_section = SECTION_SOCIAL; $this_section = SECTION_SOCIAL;

@ -65,7 +65,9 @@
btnStopId: '#btn-stop-record', btnStopId: '#btn-stop-record',
btnSaveId: '#btn-save-record', btnSaveId: '#btn-save-record',
plyrPreviewId: '#record-preview', plyrPreviewId: '#record-preview',
directory: '{{ directory }}' directory: '{{ directory }}',
reload_page: 1,
type : 'document'
}, },
{ {
blockId: '#record-audio-wami', blockId: '#record-audio-wami',

@ -0,0 +1,72 @@
<div id="record-audio-recordrtc" class="row text-center">
<form>
<div class="row">
<div class="col-sm-4 col-sm-offset-4">
<div class="form-group">
<span class="fa fa-microphone fa-5x fa-fw" aria-hidden="true"></span>
<span class="sr-only">{{ 'RecordAudio'|get_lang }}</span>
</div>
<input type="hidden" name="audio_title" id="audio-title-rtc" value="{{ audio_title }}">
</div>
</div>
<div class="text-center">
<div class="form-group">
<button class="btn btn-default" type="button" id="btn-start-record">
<span class="fa fa-circle fa-fw" aria-hidden="true"></span> {{ 'StartRecordingAudio'|get_lang }}
</button>
<button class="btn btn-danger hidden" type="button" id="btn-stop-record" disabled>
<span class="fa fa-square fa-fw" aria-hidden="true"></span> {{ 'StopRecordingAudio'|get_lang }}
</button>
</div>
<div class="form-group">
<audio class="skip hidden center-block" controls id="record-preview"></audio>
</div>
</div>
</form>
</div>
<div class="row" id="record-audio-wami">
<div class="col-sm-3 col-sm-offset-3">
<br>
<form>
<div class="form-group">
<input type="hidden" name="audio_title" id="audio-title-wami" value="{{ audio_title }}">
</div>
<div class="form-group text-center">
<button class="btn btn-default" type="button" id="btn-activate-wami">
<span class="fa fa-check fa-fw" aria-hidden=""></span> {{ 'Activate'|get_lang }}
</button>
</div>
</form>
</div>
<div class="col-sm-3">
<div id="record-audio-wami-container" class="wami-container"></div>
</div>
</div>
<script>
$(document).on('ready', function () {
RecordAudio.init(
{
blockId: '#record-audio-recordrtc',
btnStartId: '#btn-start-record',
btnPauseId: '#btn-pause-record',
btnPlayId: '#btn-play-record',
btnStopId: '#btn-stop-record',
btnSaveId: '',
plyrPreviewId: '#record-preview',
directory: '{{ directory }}',
reload_page: '{{ reload_page }}',
type: 'message',
},
{
blockId: '#record-audio-wami',
containerId: 'record-audio-wami-container',
directory: '{{ directory }}',
userId: {{ user_id }},
type: 'message'
},
null
);
});
</script>
Loading…
Cancel
Save