Commit 80ef47a8 authored by Penny Leach's avatar Penny Leach
Browse files

rough but working first cut of recent activity page

parent 17afed09
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
json_headers();
$markasread = param_integer('markasread', 0);
if ($markasread) {
db_begin();
try {
foreach ($_GET as $k => $v) {
if (preg_match('/^unread\-(\d+)$/',$k,$m)) {
set_field('notification_internal_activity', 'read', 1, 'id', $m[1]);
}
}
}
catch (Exception $e) {
db_rollback();
$data = array('error' => $e->getMessage);
echo json_encode($data);
}
db_commit();
$data = array('success' => 1);
echo json_encode($data);
exit;
}
// normal processing
$type = param_alpha('type', 'all');
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$userid = $SESSION->get('id');
if ($type == 'all') {
$count = count_records('notification_internal_activity', 'usr', $userid);
$records = get_rows('notification_internal_activity', 'usr', $userid,
'ctime DESC', '*', $offset, $limit);
} else {
$count = count_records_select('notification_internal_activity', 'usr = ? AND type = ?',
array($userid,$type));
$records = get_rows_select('notification_internal_activity', 'usr = ? AND type = ?',
array($userid, $type),
'ctime DESC', '*', $offset, $limit);
}
if (empty($records)) {
$records = array();
}
$data = array();
$star = theme_get_image_path('star.png');
$unread = get_string('unread', 'activity');
foreach ($records as $r) {
$r['date'] = format_date(strtotime($r['ctime']));
}
$activity = array(
'count' => $count,
'offset' => $offset,
'limit' => $limit,
'data' => $records,
'star' => $star,
'unread' => $unread,
);
echo json_encode($activity);
?>
......@@ -30,8 +30,92 @@ define('SUBMENUITEM', 'activity');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$smarty = smarty();
$types = get_records('activity_type', 'admin', 0);
$smarty->display('account/activity/index.tpl');
$readsavefail = get_string('failedtomarkasread', 'activity');
$readsave = get_string('markedasread', 'activity');
$javascript = <<<JAVASCRIPT
var activitylist = new TableRenderer(
'activitylist',
'index.json.php',
[
function(r) {
if (r.url) {
return TD(null,A({'href': r.url}, r.message));
}
return TD(null,r.message);
},
'ctime',
function (r, d) {
if (r.read == 0) {
return TD(null,IMG({'src' : d.star, 'alt' : d.unread}));
}
return TD(null);
},
function (r) {
if (r.read == 0) {
return TD(null, INPUT({'type' : 'checkbox', 'class' : 'tocheck', 'name' : 'unread-' + r.id}));
}
return TD(null);
}
]
);
activitylist.type = 'all';
activitylist.statevars.push('type');
activitylist.updateOnLoad();
function checkall(c) {
var e = getElementsByTagAndClassName(null,c);
if (e) {
for (cb in e) {
log(e[cb]);
e[cb].checked = 'checked';
}
}
return false;
}
function markread(form) {
var c = 'tocheck';
var e = getElementsByTagAndClassName(null,'tocheck',form);
var pd = {};
for (cb in e) {
if (e[cb].checked == true) {
pd[e[cb].name] = 1;
}
}
pd['markasread'] = 1;
var d = loadJSONDoc('index.json.php', pd);
d.addCallbacks(function (data) {
if (data.success) {
$('messagediv').innerHTML = '$readsave';
activitylist.doupdate();
}
if (data.error) {
$('messagediv').innerHTML = '$readsavefail(' + data.error + ')';
}
},
function () {
$('messagediv').innerHTML = '$readsavefail';
activitylist.doupdate();
}
)
}
JAVASCRIPT;
$smarty = smarty(array('tablerenderer'));
$smarty->assign('site_menu', site_menu());
$smarty->assign('selectall', 'checkall(\'tocheck\'); return false;');
$smarty->assign('markread', 'markread(this); return false;');
$smarty->assign('typechange', 'activitylist.doupdate({\'type\':this.options[this.selectedIndex].value});');
$smarty->assign('types', $types);
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('account/activity/index.tpl');
?>
......@@ -39,4 +39,17 @@ $string['typevirusrelease'] = 'Virus flag release';
$string['type'] = 'Activity type: ';
$string['attime'] = 'at';
$string['prefsdescr'] = 'For options other than Activity log, notifications will still go into the Activity log, but will be automatically marked as read';
$string['date'] = 'Date';
$string['read'] = 'Read';
$string['unread'] = 'Unread';
$string['markasread'] = 'Mark as read';
$string['selectall'] = 'Select all';
$string['alltypes'] = 'All types';
$string['markedasread'] = 'Marked your notifications as read';
$string['failedtomarkasread'] = 'Failed to mark your notifications as read';
?>
......@@ -172,4 +172,5 @@ $string['activity'] = 'Recent activity';
$string['emailname'] = 'Mahara System'; // robot!
$string['save'] = 'Save';
$string['update'] = 'Update';
?>
{include file="header.tpl"}
{include file="adminmenu.tpl"}
<h2>{str tag="account"}</h2>
<h2>{str tag="activity"}</h2>
<div class="content">
Content from database here
<form method="post">
{str section='activity' tag='type'}
<select name="type" onChange="{$typechange}">
<option value="all">{str section='activity' tag='alltypes'}</option>
{foreach from=$types item='type'}
{assign var="tag1" value=$type->name}
{assign var="tag" value=type$tag1}
<option value="{$type->name}">{str section='activity' tag=$tag}</option>
{/foreach}
</select>
</form>
<form method="post" onSubmit="{$markread}">
<table id="activitylist">
<thead>
<tr>
<th></th>
<th>{str section='activity' tag='date'}</th>
<th>{str section='activity' tag='read'}</th>
<th>{str section='activity' tag='markasread'} [<a href="" onClick="{$selectall}">{str section='activity' tag='selectall'}</a>]</th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td align="right" colspan="4"><div id="messagediv"></div></td>
<td align="right"><input type="submit" value="{str tag='update'}" /></td>
</tr>
</tfoot>
</table>
</form>
</div>
{include file="footer.tpl"}
......@@ -2,7 +2,7 @@
{include file="adminmenu.tpl"}
<h2>{str tag="account"}</h2>
<h2>{str tag="activityprefs"}</h2>
<div class="content">
{$prefsdescr}
......
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