Commit b2945c5a authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files
parents afa6f075 80ef47a8
......@@ -31,6 +31,7 @@ require('init.php');
$smarty = smarty();
$smarty->assign('page_content', get_site_page_content('about'));
$smarty->assign('site_menu', site_menu());
$smarty->display('sitepage.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 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');
?>
......@@ -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,8 @@ define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
$itemid = clean_requestdata('itemid', PARAM_INT, REQUEST_EITHER);
//$itemid = clean_requestdata('itemid', PARAM_INT, REQUEST_EITHER);
$itemid = param_variable('itemid');
$result = array();
try {
......
......@@ -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";
......@@ -37,10 +36,10 @@ $ijs .= "var adminfile = '" . get_string('adminfile') . "';\n";
$ijs .= <<< EOJS
// Request a list of menu items from the server
function getitems(menu) {
function getitems() {
logDebug(get_string('loadingmenuitems'));
processingStart();
var d = loadJSONDoc('getmenuitems.json.php',{'menu':menu});
var d = loadJSONDoc('getmenuitems.json.php',{'public':selectedmenu == 'public'});
d.addCallback(function(data) {
if (!data.error) {
logDebug(get_string('loadedmenuitems'));
......@@ -200,7 +199,7 @@ function delitem(itemid) {
d.addCallback(function(data) {
if (data.success) {
logDebug(get_string('menuitemdeleted'));
getitems(menu);
getitems();
}
else {
displayMessage(get_string('deletefailed'),'error');
......@@ -218,7 +217,7 @@ function saveitem(formid) {
'name':f.name.value,
'linkedto':f.linkedto.value,
'itemid':f.itemid.value,
'menu':menu};
'public':selectedmenu == 'public'};
var req = getXMLHttpRequest();
req.open('POST','updatemenu.json.php');
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
......@@ -237,7 +236,7 @@ function saveitem(formid) {
}
else {
displayMessage(data.message,errtype);
getitems(menu);
getitems();
processingStop();
}
});
......@@ -252,13 +251,29 @@ function getadminfiles() {
return null;
}
var menu = 'public';
addLoadEvent(function () {getitems(menu);});
function setmenu(menu) {
selectedmenu = menu;
var pub = get_string('loggedoutmenu');
var priv = get_string('loggedinmenu');
if (menu == 'public') {
priv = A({'href':'#'},priv);
priv.onclick = function (e) {stop(e); setmenu('private');};
}
else {
pub = A({'href':'#'},pub);
pub.onclick = function (e) {stop(e); setmenu('public');};
}
replaceChildNodes($('menuselect'), [pub, priv]);
getitems();
}
var selectedmenu = 'public';
addLoadEvent(function () {setmenu(selectedmenu);});
EOJS;
$style = '<style type="text/css">.invisible{display:none;} .menueditcell{width:200px;}</style>';
$strings = array('deletefailed','deletingmenuitem','menuitemdeleted','noadminfiles',
'edit','delete','update','cancel');
'edit','delete','update','cancel','add','loggedinmenu','loggedoutmenu');
$smarty = smarty(array(),array($style),$strings);
$smarty->assign('INLINEJAVASCRIPT',$ijs);
$smarty->display('admin/editmenu.tpl');
......
......@@ -64,7 +64,7 @@ $f = array(
'submit' => array(
'value' => get_string('savechanges'),
'type' => 'submit',
)
),
)
);
$form = form($f);
......
......@@ -28,8 +28,7 @@ define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
$menu = get_variable('menu');
$public = $menu == 'public' ? 1 : 0;
$public = (int) param_boolean('public');
$result = array();
......
......@@ -28,8 +28,6 @@ define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
error_log('updatemenu.json.php');
function send_fail_message() {
$result = array();
$result['error'] = 'local';
......@@ -38,13 +36,11 @@ function send_fail_message() {
exit;
}
$type = get_variable('type');
$name = get_variable('name');
$linkedto = get_variable('linkedto');
$itemid = get_variable('itemid');
$menu = get_variable('menu');
error_log('updatemenu.json.php '.$type .' '. $name .' '. $linkedto .' '. $itemid);
$type = param_alpha('type'); // external list or admin file
$name = param_variable('name');
$linkedto = param_variable('linkedto');
$itemid = param_variable('itemid');
$public = (int) param_boolean('public');
$data = new StdClass;
if ($type == 'adminfile') {
......@@ -58,12 +54,12 @@ else { // Bad menu item type
send_fail_message();
}
$data->title = $name;
$data->public = $menu == 'public' ? 1 : 0;
if ($itemid == 'new') {
$data->public = $public;
// set displayorder to be after all the existing menu items
try {
$displayorders = get_rows('site_menu', '', '', '', 'displayorder');
$displayorders = get_rows('site_menu', 'public', $data->public, '', 'displayorder');
$max = 0;
foreach ($displayorders as $r) {
$max = $r['displayorder'] >= $max ? $r['displayorder'] + 1 : $max;
......@@ -77,7 +73,6 @@ if ($itemid == 'new') {
}
else {
$data->id = $itemid;
log_debug($data);
try {
update_record('site_menu', $data, 'id');
}
......
......@@ -28,9 +28,65 @@ define('INTERNAL', 1);
define('PUBLIC', 1);
require('init.php');
require_once('form.php');
if ($SESSION->is_logged_in()) {
$name = display_name($USER);
$email = $USER->email;
}
else {
$name = '';
$email = '';
}
$contactform = form(array(
'name' => 'contactus',
'method' => 'post',
'action' => '',
'submit' => false,
'autofocus' => '', // only for testing for now
'elements' => array(
'name' => array(
'type' => 'text',
'title' => get_string('name'),
'value' => $name,
'rules' => array(
'required' => true
),
),
'email' => array(
'type' => 'text',
'title' => get_string('email'),
'value' => $email,
'rules' => array(
'required' => true
),
),
'subject' => array(
'type' => 'text',
'title' => get_string('subject'),
'value' => '',
),
'message' => array(
'type' => 'textarea',
'rows' => 10,
'cols' => 60,
'title' => get_string('message'),
'value' => '',
'rules' => array(
'required' => true
),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('submitcontactinformation')
),
)
));
$smarty = smarty();
$smarty->assign('page_content', get_site_page_content('contactus'));
$smarty->assign('page_content', $contactform);
$smarty->assign('site_menu', site_menu());
$smarty->display('sitepage.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);
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('./');
}