Commit 59b19bf4 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files
parents a433ede3 89ffd8ac
......@@ -29,9 +29,72 @@ define('MENUITEM', 'account');
define('SUBMENUITEM', 'activityprefs');
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('form.php');
$smarty = smarty();
$activitytypes = get_records('activity_type', 'admin', 0);
$notifications = plugins_installed('notification');
$elements = array();
foreach ($activitytypes as $type) {
$elements[$type->name] = array(
'value' => $type->name,
'type' => 'select',
'title' => get_string('type' . $type->name, 'activity'),
'options' => array(),
'rules' => array(
'required' => true
)
);
foreach ($notifications as $n) {
$elements[$type->name]['options'][$n->name] = get_string('name', 'notification.' . $n->name);
}
}
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('save'),
);
$prefsform = array(
'name' => 'activityprefs',
'method' => 'post',
'ajaxpost' => true,
'plugintype ' => 'core',
'pluginname' => 'account',
'elements' => $elements,
);
$smarty = smarty();
$smarty->assign('prefsdescr', get_string('prefsdescr', 'activity'));
$smarty->assign('form', form($prefsform));
$smarty->display('account/activity/preferences/index.tpl');
function activityprefs_submit($values) {
global $activitytypes, $SESSION;
$userid = $SESSION->get('id');
db_begin();
delete_records('usr_activity_preference', 'usr', $userid);
try {
foreach ($activitytypes as $type) {
$t = new StdClass;
$t->usr = $userid;
$t->type = $type->name;
$t->method = $values[$type->name];
insert_record('usr_activity_preference', $t);
}
}
catch (Exception $e) {
db_rollback();
throw $e;
// @todo actually return a json failure
}
db_commit();
}
?>
......@@ -29,7 +29,7 @@ define('MENUITEM', 'account');
define('SUBMENUITEM', 'accountprefs');
require(dirname(dirname(__FILE__)) . '/init.php');
require('form.php');
require_once('form.php');
// load up user preferences
$prefs = (object)($SESSION->get('accountprefs'));
......@@ -71,6 +71,7 @@ $prefsform = array(
'type' => 'radio',
'value' => $prefs->messages,
'title' => get_string('messagesdescr', 'account'),
'separator' => HTML_BR,
'options' => array(
'nobody' => get_string('messagesnobody', 'account'),
'friends' => get_string('messagesfriends', 'account'),
......@@ -93,8 +94,16 @@ $smarty->assign('form', form($prefsform));
$smarty->display('account/index.tpl');
function accountprefs_submit($values) {
// use this as looping through values is not safe.
$expectedprefs = expected_account_preferences();
try {
foreach (array_keys($expectedprefs) as $pref) {
set_account_preference($SESSION->get('id'), $pref, $expectedprefs[$pref]);
}
}
catch (Exception $e) {
}
}
......
......@@ -28,7 +28,6 @@ define('INTERNAL',1);
define('ADMIN', 1);
define('MENUITEM','menueditor');
require(dirname(dirname(__FILE__)).'/init.php');
//require_once('form.php');
$thead = array(get_string('type'),get_string('name'),get_string('linkedto'),'');
$ijs = "var thead = TR(null,map(partial(TH,null),['" . implode($thead,"','") . "']));\n";
......@@ -40,7 +39,7 @@ $ijs .= <<< EOJS
function getitems() {
logDebug(get_string('loadingmenuitems'));
processingStart();
var d = loadJSONDoc('getmenuitems.json.php',{'menu':selectedmenu});
var d = loadJSONDoc('getmenuitems.json.php',{'public':selectedmenu == 'public'});
d.addCallback(function(data) {
if (!data.error) {
logDebug(get_string('loadedmenuitems'));
......@@ -218,7 +217,7 @@ function saveitem(formid) {
'name':f.name.value,
'linkedto':f.linkedto.value,
'itemid':f.itemid.value,
'menu':selectedmenu};
'public':selectedmenu == 'public'};
var req = getXMLHttpRequest();
req.open('POST','updatemenu.json.php');
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
......
......@@ -28,8 +28,7 @@ define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
$menu = param_variable('menu');
$public = (int)($menu == 'public');
$public = (int) param_boolean('public');
$result = array();
......
......@@ -36,11 +36,11 @@ function send_fail_message() {
exit;
}
$type = param_variable('type'); // external list or admin file
$type = param_alpha('type'); // external list or admin file
$name = param_variable('name');
$linkedto = param_variable('linkedto');
$itemid = param_variable('itemid');
$menu = param_variable('menu');
$public = (int) param_boolean('public');
$data = new StdClass;
if ($type == 'adminfile') {
......@@ -56,7 +56,7 @@ else { // Bad menu item type
$data->title = $name;
if ($itemid == 'new') {
$data->public = (int) ($menu == 'public');
$data->public = $public;
// set displayorder to be after all the existing menu items
try {
$displayorders = get_rows('site_menu', 'public', $data->public, '', 'displayorder');
......
......@@ -38,4 +38,5 @@ $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';
?>
......@@ -603,6 +603,16 @@ function plugin_types() {
return $pluginstocheck;
}
/**
* This return returns the names of plugins installed
* for the given plugin type.
*
* @param string $plugintype type of plugin
*/
function plugins_installed($plugintype) {
return get_records($plugintype . '_installed');
}
/**
* Helper to call a static method when you do not know the name of the class
* you want to call the method on. PHP5 does not support $class::method().
......
......@@ -130,6 +130,27 @@ function set_activity_preference($userid, $activity, $method) {
}
}
/**
* gets an account preference for the user,
* or the default if not set for that user,
* as specified in {@link expected_account_preferences}
*
* @param int $userid id of user
* @param string $field preference to get
*/
function get_account_preference($userid, $field) {
if ($pref = record_exists('usr_account_preference', 'usr', $userid, 'field', $field)) {
return $pref->value;
}
$expected = expected_account_preferences();
return $expected[$field];
}
/**
* default account settings
*
* @returns array of fields => values
*/
function expected_account_preferences() {
return array('friendscontrol' => 'auth',
'wysiwyg' => 1,
......
......@@ -650,7 +650,7 @@ function param_integer_list($name) {
function param_boolean($name) {
$value = param_variable($name, false);
if (empty($value) || $value == 'off' || $value == 'no') {
if (empty($value) || $value == 'off' || $value == 'no' || $value == 'false') {
return false;
}
else {
......
......@@ -30,4 +30,6 @@ $string['emailsubject'] = 'Message from Mahara: %s';
$string['emailbodynoreply'] = "This is an auto generated notification from Mahara. Please do not reply to this message. Following is the content of your notification\n\n--------------------------------------------------\n\n";
$string['emailbody'] = "This is an auto generated notification from Mahara. Following is the content of your notification\n\n--------------------------------------------------\n\n";
$string['emailbodyending'] = 'To update your notification preferences, visit %s';
$string['name'] = 'Email';
?>
......@@ -30,4 +30,6 @@ $string['emailsubject'] = 'Message from Mahara: Daily digest';
$string['emailbodynoreply'] = "This is an auto generated notification from Mahara. Following is the daily digest of all your notifications\n\n--------------------------------------------------\n\n";
$string['emailbodyending'] = 'To update your notification preferences, visit %s';
$string['name'] = 'Email digest';
?>
<?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 notification-internal
* @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
*
*/
defined('INTERNAL') || die();
$string['name'] = 'Activity log';
?>
......@@ -31,5 +31,4 @@ abstract class PluginNotification extends Plugin {
public abstract static function notify_user($user, $data);
}
?>
......@@ -5,7 +5,8 @@
<h2>{str tag="account"}</h2>
<div class="content">
Content from database here
{$prefsdescr}
{$form}
</div>
{include file="footer.tpl"}
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