Commit 4ff97913 authored by Robert Lyon's avatar Robert Lyon

Bug 1781527: Removing paths to account/activity/index.php

And getting that file to redirect to correct place

behatnotneeded

Change-Id: Ifa6cebbcd6282b9eb3a39df90debc9ca9fdb9b71
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 92ffdc2d
<?php
/**
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$readone = param_integer('readone', 0);
$markasread = param_integer('markasread', 0);
$delete = param_integer('delete', 0);
if ($readone) {
set_field('notification_internal_activity', 'read', 1, 'id', $readone, 'usr', $USER->get('id'));
$unread = $USER->add_unread(-1);
$data = array(
'newunreadcount' => $unread
);
json_reply(false, array('data' => $data));
}
require_once(get_config('libroot') . 'activity.php');
$type = param_variable('type', 'all');
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$message = false;
if ($markasread) {
$ids = array();
foreach ($_GET as $k => $v) {
if (preg_match('/^unread\-(\d+)$/',$k,$m)) {
$ids[] = $m[1];
}
}
if ($ids) {
set_field_select(
'notification_internal_activity', 'read', 1,
'id IN (' . join(',', $ids) . ') AND usr = ?',
array($USER->get('id'))
);
$newunread = $USER->add_unread(-count($ids));
}
$message = get_string('markedasread', 'activity');
}
else if ($delete) {
$ids = array();
$deleteunread = 0; // Remember the number of unread messages being deleted
foreach ($_GET as $k => $v) {
if (preg_match('/^delete\-(\d+)$/',$k,$m)) {
$ids[] = $m[1];
if (param_exists('unread-' . $m[1])) {
$deleteunread++;
}
}
}
if ($ids) {
$strids = join(',', $ids);
$userid = $USER->get('id');
db_begin();
// Remove parent pointers to messages we're about to delete
// Use temp table in subselect for Mysql compat.
execute_sql("
UPDATE {notification_internal_activity}
SET parent = NULL
WHERE parent IN (
SELECT id
FROM (
SELECT id FROM {notification_internal_activity} WHERE id IN ($strids) AND usr = ?
) AS temp
)",
array($userid)
);
delete_records_select(
'notification_internal_activity',
"id IN ($strids) AND usr = ?",
array($userid)
);
if ($deleteunread) {
$newunread = $USER->add_unread(-$deleteunread);
}
db_commit();
}
$message = get_string('deletednotifications1', 'activity', count($ids));
}
$newhtml = activitylist_html($type, $limit, $offset);
if (isset($newunread)) {
$newhtml['newunreadcount'] = $newunread;
}
json_reply(false, (object) array('message' => $message, 'data' => $newhtml));
......@@ -16,142 +16,10 @@ define('SECTION_PLUGINNAME', 'account');
define('SECTION_PAGE', 'activity');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('inbox'));
// Make sure the unread message count is up to date whenever the
// user hits this page.
$USER->reload_background_fields();
$installedtypes = get_records_assoc(
'activity_type', '', '',
'plugintype,pluginname,name',
'name,admin,plugintype,pluginname'
);
$options = array(
'all' => get_string('alltypes', 'activity'),
);
foreach ($installedtypes as &$t) {
if (!$t->admin) {
$section = $t->pluginname ? "{$t->plugintype}.{$t->pluginname}" : 'activity';
$options[$t->name] = get_string('type' . $t->name, $section);
}
}
if ($USER->get('admin')) {
$options['adminmessages'] = get_string('typeadminmessages', 'activity');
}
$type = param_variable('type', 'all');
if ($type == '') {
$type = 'all';
}
if (!isset($options[$type])) {
// Comma-separated list; filter out anything that's not an installed type
$type = join(',', array_unique(array_filter(
explode(',', $type),
create_function('$a', 'global $installedtypes; return isset($installedtypes[$a]);')
)));
}
require_once('activity.php');
$activitylist = activitylist_html($type);
$strread = json_encode(get_string('read', 'activity'));
$javascript = <<<JAVASCRIPT
JAVASCRIPT;
$deleteall = pieform(array(
'name' => 'delete_all_notifications',
'method' => 'post',
'plugintype' => 'core',
'pluginname' => 'account',
'elements' => array(
'type' => array(
'type' => 'hidden',
'value' => $type,
),
'submit' => array(
'type' => 'submit',
'class' => 'btn-primary',
'value' => get_string('deleteallnotifications', 'activity'),
'confirm' => get_string('reallydeleteallnotifications', 'activity'),
),
),
));
function delete_all_notifications_submit() {
global $USER, $SESSION;
$userid = $USER->get('id');
$type = param_variable('type', 'all');
$typesql = '';
if ($type != 'all') {
// Treat as comma-separated list of activity type names
$types = explode(',', preg_replace('/[^a-z,]+/', '', $type));
if ($types) {
$typesql = ' at.name IN (' . join(',', array_map('db_quote', $types)) . ')';
if (in_array('adminmessages', $types)) {
$typesql = '(' . $typesql . ' OR at.admin = 1)';
}
$typesql = ' AND ' . $typesql;
}
}
$from = "
FROM {notification_internal_activity} a
JOIN {activity_type} at ON a.type = at.id
WHERE a.usr = ? $typesql";
$values = array($userid);
db_begin();
$count = 0;
$records = get_records_sql_array('SELECT a.id ' . $from, $values);
if ($records) {
$count = sizeof($records);
$ids = array();
foreach ($records as $row) {
$ids[] = $row->id;
}
// Remove parent pointers to messages we're about to delete
execute_sql('
UPDATE {notification_internal_activity}
SET parent = NULL
WHERE parent IN (
' . join(',', array_map('db_quote', $ids)) . '
)'
);
// delete
execute_sql('
DELETE FROM {notification_internal_activity}
WHERE id IN (
' . join(',', array_map('db_quote', $ids)) . '
)'
);
// The update_unread_delete db trigger on notification_internal_activity
// will update the unread column on the usr table.
}
db_commit();
$SESSION->add_ok_msg(get_string('deletednotifications1', 'activity', $count));
safe_require('module', 'multirecipientnotification');
if (PluginModuleMultirecipientnotification::is_active()) {
redirect(get_config('wwwroot') . 'module/multirecipientnotification/inbox.php?type='.$type);
}
else {
redirect(get_config('wwwroot') . 'account/activity/index.php?type='.$type);
}
safe_require('module', 'multirecipientnotification');
if (PluginModuleMultirecipientnotification::is_active()) {
redirect(get_config('wwwroot') . 'module/multirecipientnotification/inbox.php');
}
$smarty = smarty(array('paginator'));
$smarty->assign('options', $options);
$smarty->assign('type', $type);
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('deleteall', $deleteall);
$smarty->assign('activitylist', $activitylist);
$smarty->display('account/activity/index.tpl');
throw new ConfigSanityException(get_string('multirecipientnotificationnotenabled', 'error'));
......@@ -30,14 +30,8 @@ class PluginBlocktypeInbox extends MaharaCoreBlocktype {
}
public static function get_link(BlockInstance $instance) {
safe_require('module', 'multirecipientnotification');
if (PluginModuleMultirecipientnotification::is_active()) {
$data = get_config('wwwroot') . 'module/multirecipientnotification/inbox.php';
}
else {
$data = get_config('wwwroot') . 'account/activity/index.php';
}
return sanitize_url($data);
$data = get_config('wwwroot') . 'module/multirecipientnotification/inbox.php';
return $data;
}
public static function render_instance(BlockInstance $instance, $editing=false) {
......@@ -60,44 +54,10 @@ class PluginBlocktypeInbox extends MaharaCoreBlocktype {
$maxitems = isset($configdata['maxitems']) ? $configdata['maxitems'] : 5;
// check if multirecipientnotification plugin is active or if we proceed here
if (record_exists('module_installed', 'name', 'multirecipientnotification', 'active', '1') && safe_require_plugin('module', 'multirecipientnotification')) {
global $USER;
$userid = $USER->get('id');
$activitylist = activityblocklistin(join(',', $desiredtypes), $maxitems);
$records = $activitylist->records;
$showmore = ($activitylist->count > $maxitems);
// use a different template
$smartytemplate = 'blocktype:inbox:inboxmr.tpl';
}
else {
$records = array();
if ($desiredtypes) {
$sql = "
SELECT n.id, n.subject, n.message, n.url, n.urltext, n.read, t.name AS type
FROM {notification_internal_activity} n JOIN {activity_type} t ON n.type = t.id
WHERE n.usr = ?
AND t.name IN (" . join(',', array_map('db_quote', $desiredtypes)) . ")
ORDER BY n.ctime DESC
LIMIT ?;";
$records = get_records_sql_array($sql, array(
$USER->get('id'),
$maxitems + 1 // Hack to decide whether to show the More... link
));
}
// Hack to decide whether to show the More... link
if ($showmore = count($records) > $maxitems) {
unset($records[$maxitems]);
}
if ($records) {
foreach ($records as &$r) {
$r->message = format_notification_whitespace($r->message, $r->type);
}
}
$smartytemplate = 'blocktype:inbox:inbox.tpl';
}
safe_require_plugin('module', 'multirecipientnotification');
$activitylist = activityblocklistin(join(',', $desiredtypes), $maxitems);
$records = $activitylist->records;
$showmore = ($activitylist->count > $maxitems);
if ($records) {
require_once('activity.php');
......@@ -114,7 +74,7 @@ class PluginBlocktypeInbox extends MaharaCoreBlocktype {
$smarty->assign('blockid', 'blockinstance_' . $instance->get('id'));
$smarty->assign('items', $records);
return $smarty->fetch($smartytemplate);
return $smarty->fetch('blocktype:inbox:inboxmr.tpl');
}
public static function has_instance_config() {
......
......@@ -476,6 +476,13 @@ if (!defined('INSTALLER')) {
}
}
}
// Make sure that multirecipient notifications is installed and active
safe_require('module', 'multirecipientnotification');
if (!PluginModuleMultirecipientnotification::is_active()) {
throw new ConfigSanityException(get_string('multirecipientnotificationnotenabled',
'module.multirecipientnotification'));
}
}
if (get_config('disableexternalresources')) {
......
......@@ -1556,93 +1556,6 @@ function format_notification_whitespace($message, $type=null) {
return preg_replace('/(<br( ?\/)?>\s*){2,}/', $replace, $message);
}
/**
* Get one page of notifications and return html
*/
function activitylist_html($type='all', $limit=10, $offset=0) {
global $USER;
$userid = $USER->get('id');
$typesql = '';
if ($type != 'all') {
// Treat as comma-separated list of activity type names
$types = explode(',', preg_replace('/[^a-z,]+/', '', $type));
if ($types) {
$typesql = ' at.name IN (' . join(',', array_map('db_quote', $types)) . ')';
if (in_array('adminmessages', $types)) {
$typesql = '(' . $typesql . ' OR at.admin = 1)';
}
$typesql = ' AND ' . $typesql;
}
}
$from = "
FROM {notification_internal_activity} a
JOIN {activity_type} at ON a.type = at.id
WHERE a.usr = ? $typesql";
$values = array($userid);
$count = count_records_sql('SELECT COUNT(*)' . $from, $values);
safe_require('module', 'multirecipientnotification');
if (PluginModuleMultirecipientnotification::is_active()) {
$paginationurl = get_config('wwwroot') . 'module/multirecipientnotification/inbox.php?type=' . $type;
}
else {
$paginationurl = get_config('wwwroot') . 'account/activity/index.php?type=' . $type;
}
$pagination = build_pagination(array(
'id' => 'activitylist_pagination',
'url' => $paginationurl,
'jsonscript' => 'account/activity/index.json.php',
'datatable' => 'activitylist',
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
));
$result = array(
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'type' => $type,
'tablerows' => '',
'pagination' => $pagination['html'],
'pagination_js' => $pagination['javascript'],
);
if ($count < 1) {
return $result;
}
$records = get_records_sql_array('
SELECT
a.*, at.name AS type, at.plugintype, at.pluginname' . $from . '
ORDER BY a.ctime DESC',
$values,
$offset,
$limit
);
if ($records) {
foreach ($records as &$r) {
$r->date = format_date(strtotime($r->ctime), 'strfdaymonthyearshort');
$section = empty($r->plugintype) ? 'activity' : "{$r->plugintype}.{$r->pluginname}";
$r->strtype = get_string('type' . $r->type, $section);
$r->message = format_notification_whitespace($r->message);
}
}
$smarty = smarty_core();
$smarty->assign('data', $records);
$result['tablerows'] = $smarty->fetch('account/activity/activitylist.tpl');
return $result;
}
/**
* Get a table of elements that can be used to set notification settings for the specified user, or for the site defaults.
*
......
......@@ -3080,17 +3080,7 @@ function right_nav() {
'weight' => 10,
'iconclass' => 'cogs'
),
'inbox' => array(
'path' => 'inbox',
'url' => 'account/activity/index.php',
'title' => get_string('inbox'),
'alt' => get_string('inbox'),
'count' => $unread,
'countclass' => 'unreadmessagecount',
'linkid' => 'mail',
'weight' => 20,
'iconclass' => 'envelope'
),
'inbox' => array(), // overriden by module 'multirecipientnotification'
'settings/account' => array(
'path' => 'settings/account',
'url' => 'account/index.php',
......
......@@ -49,3 +49,5 @@ $string['clickformore'] = '(Press \'Enter\' to display more information)';
$string['labelsearch'] = 'Search';
$string['labelall'] = 'All';
$string['labelmessage'] = 'Message';
$string['multirecipientnotificationnotenabled'] = 'The module multirecipientnotifications needs to be installed and active. If you are upgrading Mahara from a version older than 16.10.0 please upgrade to this point first and make sure the module is installed and active by visiting "Administration menu" → "Extensions".';
{if !$items}
{str tag=nomessages section=blocktype.inbox}
{else}
<table id="inboxblock" class="fullwidth fixwidth table table-striped">
{foreach from=$items item=i}
<tr class="{cycle values='r0,r1'}">
<td class="icon-container">
{if $i->read}
<img src="{theme_url filename=cat('images/' $i->type '.png')}" alt="{$i->strtype}" />
{else}
<img src="{theme_url filename=cat('images/' $i->type '.png')}" class="unreadmessage" alt="{$i->strtype}" />
{/if}
</td>
<td>
{if $i->message}
<a href="{if $i->url}{$WWWROOT}{$i->url}{else}{$WWWROOT}account/activity/index.php{/if}" class="inbox-showmessage{if !$i->read} unread{/if}">
{if !$i->read}<span class="accessible-hidden sr-only">{str tag=unread section=activity}: </span>{/if}{$i->subject}
</a>
<div class="inbox-message hidden messagebody-{$i->type}" id="inbox-message-{$i->id}">{$i->message|safe}
{if $i->url}<br><a href="{$WWWROOT}{$i->url}">{if $i->urltext}{$i->urltext} &raquo;{else}{str tag="more..."}{/if}</a>{/if}
</div>
{elseif $i->url}
<a href="{$WWWROOT}{$i->url}">{$i->subject}</a>
{else}
{$i->subject}
{/if}
</td>
</tr>
{/foreach}
</table>
{if $morelink}
<div class="morelinkwrap"><a class="morelink" href="{$morelink}">{str tag=More section=blocktype.inbox} &raquo;</a></div>
<div class="cb"></div>
{/if}
<script type="application/javascript">
var blockid = '{$blockid}';
{literal}
jQuery(function() {
jQuery("#" + blockid + " a.inbox-showmessage").each(function() {
var el = jQuery(this);
el.on("click", function(e) {
e.preventDefault();
var message = jQuery(e.target).parent().find(".inbox-message");
message.toggleClass('hidden');
var unreadText = jQuery(e.target).find(".accessible-hidden");
if (unreadText.length) {
var tableinfo = message.attr('id').split('-');
var id = tableinfo.pop();
var table = tableinfo.pop();
var pd = {'readone':id, 'table':table};
sendjsonrequest(config.wwwroot + 'account/activity/index.json.php', pd, 'GET', function(data) {
unreadText.remove();
updateUnreadCount(data);
});
}
});
});
});
{/literal}
</script>
{/if}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment