1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 09:49:30 +02:00

Add set as read/unread and delete actions on private messages

This commit is contained in:
Afterster 2015-05-03 20:22:34 +02:00
parent 26b30a2817
commit db9cc4ed33
9 changed files with 94 additions and 12 deletions

View file

@ -124,6 +124,12 @@ class PrivateMsg extends database_object
return Dba::write($sql, array($read ? 1 : 0, $this->id));
}
public function delete()
{
$sql = "DELETE FROM `user_pvmsg` WHERE `id` = ?";
return Dba::write($sql, array($this->id));
}
public static function create(array $data)
{
$subject = trim(strip_tags($data['subject']));

View file

@ -104,7 +104,7 @@ $(function() {
},
error: function(jqXHR, status, errorThrown)
{
// Display error here?
alert(errorThrown);
}
});

View file

@ -45,6 +45,8 @@ switch ($action) {
require_once AmpConfig::get('prefix') . '/templates/show_add_pvmsg.inc.php';
break;
case 'add_message':
if (AmpConfig::get('demo_mode')) { break; }
// Remove unauthorized defined values from here
if (isset($_POST['from_user'])) {
unset($_POST['from_user']);
@ -65,14 +67,69 @@ switch ($action) {
show_confirmation($title, $body, AmpConfig::get('web_path') . '/browse.php?action=pvmsg');
}
break;
case 'set_is_read':
if (AmpConfig::get('demo_mode')) { break; }
$msgs = split(",", $_REQUEST['msgs']);
foreach ($msgs as $msg_id) {
$pvmsg = new PrivateMsg(intval($msg_id));
if ($pvmsg->id && $pvmsg->to_user === $GLOBALS['user']->id) {
$read = intval($_REQUEST['read']) !== 0;
$pvmsg->set_is_read($read);
} else {
debug_event('UI::access_denied', 'Unknown or unauthorized private message `' . $pvmsg->id . '`.', '3');
UI::access_denied();
exit();
}
}
show_confirmation(T_('Messages State Changed'), T_('Messages state have been changed.'), AmpConfig::get('web_path') . "/browse.php?action=pvmsg");
break;
case 'delete':
if (AmpConfig::get('demo_mode')) { break; }
$msgs = scrub_out($_REQUEST['msgs']);
show_confirmation(
T_('Message Deletion'),
T_('Are you sure you want to permanently delete the selected messages?'),
AmpConfig::get('web_path')."/pvmsg.php?action=confirm_delete&msgs=" . $msgs,
1,
'delete_message'
);
break;
case 'confirm_delete':
if (AmpConfig::get('demo_mode')) { break; }
$msgs = split(",", $_REQUEST['msgs']);
foreach ($msgs as $msg_id) {
$msg_id = intval($msg_id);
$pvmsg = new PrivateMsg($msg_id);
if ($pvmsg->id && $pvmsg->to_user === $GLOBALS['user']->id) {
$pvmsg->delete();
} else {
debug_event('UI::access_denied', 'Unknown or unauthorized private message #' . $msg_id . '.', '3');
UI::access_denied();
exit();
}
}
show_confirmation(T_('Messages Deletion'), T_('Messages have been deleted.'), AmpConfig::get('web_path') . "/browse.php?action=pvmsg");
break;
case 'show':
default:
$pvmsg = new PrivateMsg($_REQUEST['pvmsg_id']);
$pvmsg->format();
if (!$pvmsg->is_read) {
$pvmsg->set_is_read(true);
$msg_id = intval($_REQUEST['pvmsg_id']);
$pvmsg = new PrivateMsg($msg_id);
if ($pvmsg->id && $pvmsg->to_user === $GLOBALS['user']->id) {
$pvmsg->format();
if (!$pvmsg->is_read) {
$pvmsg->set_is_read(true);
}
require_once AmpConfig::get('prefix') . '/templates/show_pvmsg.inc.php';
} else {
debug_event('UI::access_denied', 'Unknown or unauthorized private message #' . $msg_id . '.', '3');
UI::access_denied();
exit();
}
require_once AmpConfig::get('prefix') . '/templates/show_pvmsg.inc.php';
break;
}

View file

@ -41,11 +41,11 @@ if (empty($logo_url)) {
<div class="container">
<a class="navbar-brand" href="#">
<img src="<?php echo $logo_url; ?>" title="Ampache" alt="Ampache">
<?php echo T_('site_title'); ?>
<?php echo AmpConfig::get('site_title'); ?>
</a>
</div>
</div>
<div class="container" role="main">
<div id="guts" class="container" role="main">
<div class="jumbotron">
<h1><?php echo T_('Access Denied'); ?></h1>
<p><?php echo T_('This event has been logged.'); ?></p>

View file

@ -21,6 +21,7 @@
*/
?>
<td class="cel_select"><input type="checkbox" name="pvmsg_select[]" value="<?php echo $libitem->id; ?>" title="<?php echo T_('Select'); ?>" /></td>
<td class="cel_subject"><?php echo $libitem->f_link; ?></td>
<td class="cel_from_user"><?php echo $libitem->f_from_user_link; ?></td>
<td class="cel_to_user"><?php echo $libitem->f_to_user_link; ?></td>
@ -29,4 +30,7 @@
<a id="<?php echo 'reply_pvmsg_'.$libitem->id ?>" href="<?php echo AmpConfig::get('web_path'); ?>/pvmsg.php?action=show_add_message&reply_to=<?php echo $libitem->id; ?>">
<?php echo UI::get_icon('mail', T_('Reply')); ?>
</a>
<a id="<?php echo 'delete_pvmsg_'.$libitem->id ?>" href="<?php echo AmpConfig::get('web_path'); ?>/pvmsg.php?action=delete&msgs=<?php echo $libitem->id; ?>">
<?php echo UI::get_icon('delete', T_('Delete')); ?>
</a>
</td>

View file

@ -22,15 +22,29 @@
$thcount = 5;
?>
<script language="javascript" type="text/javascript">
public function getSelectionArray()
{
var checked = []
$("input[name='pvmsg_select[]']:checked").each(function () {
checked.push(parseInt($(this).val()));
});
return checked.join(",");
}
</script>
<div id="information_actions">
<ul>
<li><?php echo UI::get_icon('mail', T_('Compose')); ?> <a href="<?php echo AmpConfig::get('web_path'); ?>/pvmsg.php?action=show_add_message"><?php echo T_('Compose a new message'); ?></a></li>
<li><a href="<?php echo AmpConfig::get('web_path'); ?>/pvmsg.php?action=show_add_message"><?php echo UI::get_icon('mail', T_('Compose')); ?> <?php echo T_('Compose a new message'); ?></a></li>
<li><a href="javascript:NavigateTo('<?php echo AmpConfig::get('web_path'); ?>/pvmsg.php?action=set_is_read&read=1&msgs=' + getSelectionArray());"><?php echo T_('Set as read'); ?></a></li>
<li><a href="javascript:NavigateTo('<?php echo AmpConfig::get('web_path'); ?>/pvmsg.php?action=set_is_read&read=0&msgs=' + getSelectionArray());"><?php echo T_('Set as unread'); ?></a></li>
<li><a href="javascript:NavigateTo('<?php echo AmpConfig::get('web_path'); ?>/pvmsg.php?action=delete&msgs=' + getSelectionArray());"><?php echo UI::get_icon('delete', T_('Delete')); ?> <?php echo T_('Delete'); ?></a></li>
</ul>
</div>
<?php if ($browse->get_show_header()) require AmpConfig::get('prefix') . '/templates/list_header.inc.php'; ?>
<table class="tabledata" cellpadding="0" cellspacing="0" data-objecttype="label">
<thead>
<tr class="th-top">
<th class="cel_select essential persist"></th>
<th class="cel_subject essential persist"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&type=pvmsg&sort=subject', T_('Subject'),'pvmsg_sort_subject'); ?></th>
<th class="cel_from_user essential"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&type=pvmsg&sort=from_user', T_('Sender'),'pvmsg_sort_from_user'); ?></th>
<th class="cel_to_user essential"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&type=pvmsg&sort=to_user', T_('Recipient'),'pvmsg_sort_to_user'); ?></th>
@ -57,6 +71,7 @@ $thcount = 5;
</tbody>
<tfoot>
<tr class="th-bottom">
<th class="cel_select essential persist"></th>
<th class="cel_subject essential persist"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&type=pvmsg&sort=subject', T_('Subject'),'pvmsg_sort_subject'); ?></th>
<th class="cel_from_user essential"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&type=pvmsg&sort=from_user', T_('Sender'),'pvmsg_sort_from_user'); ?></th>
<th class="cel_to_user essential"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&type=pvmsg&sort=to_user', T_('Recipient'),'pvmsg_sort_to_user'); ?></th>

View file

@ -56,7 +56,7 @@ $_SESSION['login'] = true;
?>
<br /><br />
<a href="<?php echo AmpConfig::get('web_path'); ?>/login.php"><?php echo T_('Return to Login Page'); ?></a>
<p><?php echo T_('site_title'); ?></p>
<p><?php echo AmpConfig::get('site_title'); ?></p>
</div>
</div>
<?php

View file

@ -58,7 +58,7 @@ $htmllang = str_replace("_","-",AmpConfig::get('lang'));
<!-- Propulsed by Ampache | ampache.org -->
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo AmpConfig::get('site_charset'); ?>" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><?php echo T_('site_title'); ?> - Update</title>
<title><?php echo AmpConfig::get('site_title'); ?> - Update</title>
<link href="modules/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="modules/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
<link rel="stylesheet" href="templates/install-doped.css" type="text/css" media="screen" />

View file

@ -22,7 +22,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>';
<friendlyName>Ampache</friendlyName>
<manufacturer>ampache.org</manufacturer>
<manufacturerURL>http://ampache.org</manufacturerURL>
<modelDescription><?php echo T_('site_title'); ?></modelDescription>
<modelDescription><?php echo AmpConfig::get('site_title'); ?></modelDescription>
<modelName>Ampache</modelName>
<modelNumber><?php echo AmpConfig::get('version'); ?></modelNumber>
<modelURL>http://ampache.org</modelURL>