Commit 89ffd8ac authored by Penny Leach's avatar Penny Leach
Browse files
parents 47546777 ec519bf3
......@@ -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');
?>
......@@ -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');
......
......@@ -66,7 +66,7 @@ $f = array(
'submit' => array(
'value' => get_string('savechanges'),
'type' => 'submit',
)
),
)
);
......
......@@ -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;
......
......@@ -94,6 +94,7 @@ if (!$SESSION->is_logged_in()) {
$smarty->assign('login_form', $loginform);
}
$smarty->assign('page_content', get_site_page_content($pagename));
$smarty->assign('site_menu', site_menu());
$smarty->display('index.tpl');
?>
......@@ -53,7 +53,11 @@ function processingStop() {
// Autofocus the first element with a class of 'autofocus' on page load
addLoadEvent(function() {
getFirstElementByTagAndClassName(null, 'autofocus', document.body).focus();
var element = getFirstElementByTagAndClassName(null, 'autofocus', document.body)
if ( element && typeof(element.focus) == 'function' ) {
element.focus();
}
});
// @todo remove this when we migrate to mochikit 1.4
......
......@@ -910,7 +910,25 @@ function main_nav() {
return $menu;
}
/**
* Site-level sidebar menu (list of links)
* There is no admin files table yet so just get the urls.
* @return $menu a data structure containing the site menu
*/
function site_menu() {
//$wwwroot = get_config('wwwroot'); (int)
global $SESSION;
$menu = array();
if ($menuitems = @get_records('site_menu','public',(int) !$SESSION->is_logged_in(),'displayorder')) {
foreach ($menuitems as $i) {
if ($i->url) {
$menu[] = array('name' => $i->title,
'link' => $i->url);
}
}
}
return $menu;
}
/**
* Always use this function for all emails to users
*
......
......@@ -594,7 +594,7 @@ function param_alpha($name) {
$value = param_variable($name);
}
if (preg_match('/^[a-zA-Z]$/',$value)) {
if (preg_match('/^[a-zA-Z]+$/',$value)) {
return $value;
}
......@@ -647,7 +647,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 {
......
......@@ -31,6 +31,7 @@ require('init.php');
$smarty = smarty();
$smarty->assign('page_content', get_site_page_content('privacy'));
$smarty->assign('site_menu', site_menu());
$smarty->display('sitepage.tpl');
?>
......@@ -31,6 +31,7 @@ require('init.php');
$smarty = smarty();
$smarty->assign('page_content', get_site_page_content('termsandconditions'));
$smarty->assign('site_menu', site_menu());
$smarty->display('sitepage.tpl');
?>
......@@ -2,6 +2,8 @@
<p>Admin menu editor</p>
<div id="menuselect"></div>
<table id="menuitemlist" class="menueditor"><tbody><tr><td></td></tr></tbody></table>
{include file="footer.tpl"}
<div class="sidebar">
Admin Menu here
<ul id="sitemenu">
{foreach from=$site_menu item=item}
<li><a href="{$item.link|escape}">{$item.name}</a></li>
{/foreach}
</ul>
</div>
......@@ -2,16 +2,20 @@
use strict;
use warnings;
use Carp;
use FindBin;
use Data::Dumper;
use DBI;
use Data::RandomPerson;
use Data::Random::WordList;
use Getopt::Declare;
use Perl6::Slurp;
#use Smart::Comments;
my $args = Getopt::Declare->new(q(
[strict]
-t <type> Select type of data (currently only 'user') [required]
-t <type> Select type of data (user or group) [required]
-u <user> User to create data for (required for type 'group')
-c <configfile> What config.php to use (defaults to ../htdocs/config.php)
-n <count> How many to generate (default 1)
{ reject $count !~ /^\d+$/; }
......@@ -35,11 +39,11 @@ $config->{dbprefix} = '' unless defined $config->{dbprefix};
if ( $args->{-t} eq 'user' ) {
# get a list of existing usernames
my $existing_users = $dbh->selectall_hashref('SELECT ' . $config->{dbprefix} . 'username FROM usr', 'username');
my $existing_users = $dbh->selectall_hashref('SELECT id, username FROM ' . $config->{dbprefix} . 'usr', 'username');
$dbh->begin_work();
foreach ( 1 .. $args->{-n} ) {
foreach ( 1 .. $args->{-n} ) { ### [... ] (%)
my $userinfo = Data::RandomPerson->new()->create();
$userinfo->{username} = lc $userinfo->{firstname};
$userinfo->{email} = lc $userinfo->{firstname} . '.' . lc $userinfo->{lastname} . '@dollyfish.net.nz';
......@@ -67,6 +71,63 @@ if ( $args->{-t} eq 'user' ) {
$dbh->commit();
}
if ( $args->{-t} eq 'group' ) {
unless ( defined $args->{-u} ) {
croak 'Need to specify a user with -u';
}
my $existing_users = $dbh->selectall_hashref('SELECT id, username FROM ' . $config->{dbprefix} . 'usr', 'username');
unless ( exists $existing_users->{$args->{-u}} ) {
croak qq{User '$args->{-u}' doesn't exist\n};
}
my $user_id = $existing_users->{$args->{-u}}{id};
print qq{Adding groups for '$args->{-u}' ($user_id)\n};
my $wl = new Data::Random::WordList( wordlist => '/usr/share/dict/words' );
$dbh->begin_work();
foreach ( 1 .. $args->{-n} ) { ### [... ] (%)
my $groupname = join(' ', $wl->get_words(int(rand(5)) + 1));
my $groupdescription = join(' ', $wl->get_words(int(rand(50)) + 10));
if ( $args->{-p} or $args->{-v} ) {
print "Creating group '$groupname'\n";
print "INSERT INTO usr_group (name,owner,description,ctime,mtime) VALUES (?,?,?,?,?)\n";
my $members = {};
foreach (1..(int(rand(20)) + 5)) {
$members->{((keys %$existing_users)[int(rand(keys %$existing_users))])} = 1;
}
print "Members ... " . join(', ', keys %$members) . "\n";;
}
unless ( $args->{-p} ) {
$dbh->do(
'INSERT INTO usr_group (name,owner,description,ctime,mtime) VALUES (?,?,?,current_timestamp,current_timestamp)',
undef,
$groupname,
$user_id,
$groupdescription,
);
my $members = {};
foreach (1..(int(rand(20)) + 5)) {
$members->{$existing_users->{((keys %$existing_users)[int(rand(keys %$existing_users))])}{id}} = 1;
}
foreach my $id (keys %$members) {
$dbh->do(
q{INSERT INTO usr_group_member (grp,member,ctime) VALUES (currval('usr_group_id_seq'),?,current_timestamp)},
undef,
$id,
);
}
}
}
$dbh->commit();
}
sub read_config {
my ($file) = @_;
......
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