Commit 1121a614 authored by Richard Mansfield's avatar Richard Mansfield
Browse files
parents 2be7aea1 59b19bf4
......@@ -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) {
}
}
......
<?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 Martyn Smith <martyn@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);
define('MENUITEM', 'mycontacts');
define('SUBMENUITEM', 'mygroups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('form.php');
$creategroup = form(array(
'name' => 'creategroup',
'method' => 'post',
'elements' => array(
'name' => array(
'type' => 'text',
'title' => get_string('groupname'),
'rules' => array( 'required' => true ),
),
'description' => array(
'type' => 'wysiwyg',
'title' => get_string('groupdescription'),
'rows' => 10,
'cols' => 80,
),
'members' => array(
'type' => 'userlist',
'title' => get_string('groupmembers'),
'rules' => array( 'required' => true ),
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('creategroup'), get_string('cancel')),
),
),
));
function creategroup_validate(Form $form, $values) {
global $USER;
$gid = get_field('usr_group', 'id', 'owner', $USER->id, 'name', $values['name']);
if($gid) {
$form->set_error('name', get_string('groupalreadyexists'));
}
}
function creategroup_cancel_submit() {
redirect('./');
}
function creategroup_submit($values) {
global $USER;
global $SESSION;
db_begin();
$now = db_format_timestamp(time());
$gid = insert_record(
'usr_group',
(object) array(
'name' => $values['name'],
'owner' => $USER->id,
'description' => $values['description'],
'ctime' => $now,
'mtime' => $now,
),
'id',
true
);
foreach ($values['members'] as $member) {
insert_record(
'usr_group_member',
(object) array(
'grp' => $gid,
'member'=> $member,
'ctime' => $now,
)
);
}
$SESSION->add_ok_msg(get_string('groupcreated'));
db_commit();
redirect('./');
}
$smarty = smarty();
$smarty->assign('creategroup', $creategroup);
$smarty->display('contacts/groups/create.tpl');
?>
<?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 Martyn Smith <martyn@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();
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$dbprefix = get_config('dbprefix');
$count = get_field('usr_group', 'COUNT(*)', 'owner', $USER->id);
$data = get_rows_sql(
'SELECT g.id, g.name, COUNT(m.*) AS count FROM ' . $dbprefix . 'usr_group g INNER JOIN ' . $dbprefix . 'usr_group_member m ON m.grp=g.id WHERE g.owner=? GROUP BY 1, 2 ORDER BY g.name',
array($USER->id),
$offset,
$limit
);
if (!$data) {
$data = array();
}
print json_encode(array(
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'data' => $data,
));
......@@ -30,8 +30,28 @@ define('SUBMENUITEM', 'mygroups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$smarty = smarty();
$javascript = <<<JAVASCRIPT
var grouplist = new TableRenderer(
'grouplist',
'index.json.php',
[
'name',
'count',
function(r) { return TD(null,A({'href':'edit.php?id=' + r.id}, 'edit')); }
]
);
grouplist.offset = 0;
grouplist.limit = 10;
grouplist.type = 'testing';
grouplist.statevars.push('type');
grouplist.updateOnLoad();
JAVASCRIPT;
$smarty = smarty(array('tablerenderer'));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('contacts/groups/index.tpl');
?>
......@@ -4119,7 +4119,12 @@ k.string=String.fromCharCode(k.code);
if(this._event.keyCode&&typeof (this._event.charCode)=="undefined"){
k.code=this._event.keyCode;
k.string=String.fromCharCode(k.code);
} else if (this._event.keyCode &&
this._event.charCode == 0) {
k.code = this._event.keyCode;
k.string = String.fromCharCode(k.code);
}
}
return k;
}
......
function TableRenderer(target, source, columns, options) {
// to use on the callbacks
var self = this;
this.source = source;
this.columns = columns;
this.paginate = true;
this.statevars = ['offset','limit'];
addLoadEvent(function() {
self.table = target;
self.tbody = getFirstElementByTagAndClassName('tbody', null, self.table);
self.thead = getFirstElementByTagAndClassName('thead', null, self.table);
self.tfoot = getFirstElementByTagAndClassName('tfoot', null, self.table);
if (!self.thead) {
self.thead = THEAD();
appendChildNodes(self.table, self.thead);
}
if (!self.tfoot) {
self.tfoot = TFOOT();
appendChildNodes(self.table, self.tfoot);
}
if (self.paginate) {
forEach([self.thead,self.tfoot], function(ref) {
var nextPage = A({'href':''}, 'Next Page');
var prevPage = A({'href':''}, 'Prev Page');
connect(nextPage, 'onclick', function(e) { self.nextPage(); e.stop(); });
connect(prevPage, 'onclick', function(e) { self.prevPage(); e.stop(); });
var tr = TR(null, TD(null, prevPage, ' ', nextPage));
// replaceChildNodes(ref, tr, ref.childNodes);
appendChildNodes(ref, tr);
});
}
});
this.renderdata = function(data) {
replaceChildNodes(self.tbody);
forEach(data, function(row) {
var tr = TR();
if ( row._class ) { tr.className = row._class; }
if ( row._id ) { tr.id = row._id; }
forEach(self.columns, function (column) {
if ( typeof(column) == 'string' ) {
appendChildNodes(tr, TD(null,row[column]));
}
else if ( typeof(column) == 'function' ) {
appendChildNodes(tr, column(row));
}
else {
logError("Can't deal with column def of type: " + typeof(column));
}
});
appendChildNodes(self.tbody, tr);
});
}
this.doupdate = function(request_args) {
if (!request_args) {
request_args = {};
}
forEach(self.statevars, function(key) {
if (typeof(request_args[key]) == 'undefined') {
request_args[key] = self[key];
}
});
self.d = loadJSONDoc(self.source, request_args);
processingStart();
self.d.addCallbacks(
function (data) {
processingStop();
if ( data.error ) {
displayMessage(data.error);
return;
}
self.limit = data.limit;
self.offset = data.offset;
self.count = data.count;
self.renderdata(data.data);
},
function (error) {
processingStop();
displayMessage('Error loading data (not valid JSON)');
}
);
self.update = callLater(self.delay, partial(self.doupdate, {}));
};
this.prevPage = function() {
if ( self.offset > 0 ) {
if ( self.offset - self.limit < 0 ) {
self.doupdate({'offset': 0});
}
else {
self.doupdate({'offset': self.offset - self.limit});
}
}
else {
logDebug('Already on the first page (' + self.offset + ', ' + self.limit + ', ' + self.count + ')');
}
};
this.nextPage = function() {
if ( self.offset + self.limit < self.count ) {
self.doupdate({'offset': self.offset + self.limit});
}
else {
logDebug('Already on the last page (' + self.offset + ', ' + self.limit + ', ' + self.count + ')');
}
};
this.updateOnLoad = function() {
addLoadEvent(partial(self.doupdate, {}));
}
}
<?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 Martyn Smith <martyn@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(__FILE__)) . '/init.php');
require('searchlib.php');
json_headers();
safe_require('search', 'internal', 'lib.php', 'require_once');
try {
$query = param_variable('query');
}
catch (ParameterException $e) {
print json_encode(array(
'error' => 'missingparameter',
'message' => 'Missing parameter \'query\'',
));
exit;
}
$limit = param_integer('limit', 20);
$offset = param_integer('offset', 0);
$data = search_user($query, $limit, $offset);
foreach ($data['results'] as &$result) {
// @todo should call magical display user function
$result['name'] = $result['firstname'];
unset($result['email']);
unset($result['institution']);
unset($result['username']);
unset($result['firstname']);
unset($result['lastname']);
unset($result['prefname']);
}
print json_encode($data);
?>
......@@ -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';
?>
<?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 form-element
* @author Martyn Smith <martyn@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();
/**
* Provides a basic text field input.
*
* @todo this is just lies ...
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_userlist($element, Form $form) {
$smarty = smarty();
$smarty->left_delimiter = '{{';
$smarty->right_delimiter = '}}';
$value = $form->get_value($element);
if (is_array($value) && count($value)) {
$members = get_records_select('usr','id IN (' . join(',',$value) . ')', null, '', 'id,firstname,lastname,prefname');
foreach($members as &$member) {
// @todo should be using the pref/full name function here
$member = $member->firstname;
}
$smarty->assign('options',$members);
$smarty->assign('value', join(',',$form->get_value($element)));
}
else if (!is_array($value)) {
// @todo use the default
}
$smarty->assign('name', $element['name']);
return $smarty->fetch('form/userlist.tpl');
}
function form_get_value_userlist($element, Form $form) {
$name = $element['name'];
$global = ($form->get_method() == 'get') ? $_GET : $_POST;
if (isset($global[$name])) {
$value = $global[$name];