Skip to content

Commit

Permalink
Announcements: Add conf setting disabled_announcement_attachment - re…
Browse files Browse the repository at this point in the history
…fs BT#16994

Disable fields to add an attachment when creating and announcement.
  • Loading branch information
AngelFQC committed Apr 7, 2020
1 parent fc3fd69 commit 504b2ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
32 changes: 19 additions & 13 deletions main/announcements/announcements.php
Expand Up @@ -89,6 +89,8 @@
];
Event::registerLog($logInfo);

$announcementAttachmentIsDisabled = api_get_configuration_value('disabled_announcement_attachment');

switch ($action) {
case 'move':
if (!$allowToEdit) {
Expand All @@ -112,7 +114,7 @@
}

$sql = "SELECT DISTINCT announcement.id, announcement.display_order
FROM $tbl_announcement announcement
FROM $tbl_announcement announcement
INNER JOIN $tbl_item_property itemproperty
ON (announcement.c_id = itemproperty.c_id)
WHERE
Expand Down Expand Up @@ -524,22 +526,22 @@
$form->addHtml("
<script>
$(function () {
$('#announcement_preview').on('click', function() {
$('#announcement_preview').on('click', function() {
var users = [];
$('#users_to option').each(function() {
users.push($(this).val());
users.push($(this).val());
});
var form = $('#announcement').serialize();
$.ajax({
type: 'POST',
dataType: 'json',
url: '".$ajaxUrl."',
data: {users : JSON.stringify(users), form: form},
data: {users : JSON.stringify(users), form: form},
beforeSend: function() {
$('#announcement_preview_result').html('<i class=\"fa fa-spinner\"></i>');
$('#send_button').hide();
},
},
success: function(result) {
var resultToString = '';
$.each(result, function(index, value) {
Expand All @@ -549,7 +551,7 @@
'".addslashes(get_lang('AnnouncementWillBeSentTo'))."<br/>' + resultToString
);
$('#announcement_preview_result').show();
$('#send_button').show();
$('#send_button').show();
}
});
});
Expand Down Expand Up @@ -600,8 +602,12 @@
false,
['ToolbarSet' => 'Announcements']
);
$form->addElement('file', 'user_upload', get_lang('AddAnAttachment'));
$form->addElement('textarea', 'file_comment', get_lang('FileComment'));

if (!$announcementAttachmentIsDisabled) {
$form->addElement('file', 'user_upload', get_lang('AddAnAttachment'));
$form->addElement('textarea', 'file_comment', get_lang('FileComment'));
}

$form->addHidden('sec_token', $token);

if (empty($sessionId)) {
Expand Down Expand Up @@ -645,8 +651,8 @@
if (isset($id) && $id) {
// there is an Id => the announcement already exists => update mode
if (Security::check_token('post')) {
$file_comment = $_POST['file_comment'];
$file = $_FILES['user_upload'];
$file_comment = $announcementAttachmentIsDisabled ? null : $_POST['file_comment'];
$file = $announcementAttachmentIsDisabled ? [] : $_FILES['user_upload'];

AnnouncementManager::edit_announcement(
$id,
Expand Down Expand Up @@ -688,8 +694,8 @@
} else {
// Insert mode
if (Security::check_token('post')) {
$file = $_FILES['user_upload'];
$file_comment = $data['file_comment'];
$file = $announcementAttachmentIsDisabled ? [] : $_FILES['user_upload'];
$file_comment = $announcementAttachmentIsDisabled ? null : $data['file_comment'];

if (empty($group_id)) {
$insert_id = AnnouncementManager::add_announcement(
Expand Down
3 changes: 3 additions & 0 deletions main/install/configuration.dist.php
Expand Up @@ -1447,6 +1447,9 @@
'fields' => ['mots_cles', 'duree_en_min', 'format'],
];*/

// Disable fields to add an attachment when creating and announcement.
//$_configuration['disabled_announcement_attachment'] = false;

This comment has been minimized.

Copy link
@ywarnier

ywarnier Apr 7, 2020

Member

Should be "disable", not "disabled", as per the other options in the same file that use "disable", not "disabled".

This comment has been minimized.

Copy link
@AngelFQC

AngelFQC Apr 7, 2020

Author Member

Changed a815898


// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email
Expand Down

0 comments on commit 504b2ec

Please sign in to comment.