Commit 88ee5414 authored by Dan Marsden's avatar Dan Marsden Committed by Richard Mansfield
Browse files

First version of Group categories patch


Signed-off-by: default avatarDan Marsden <dan@catalyst.net.nz>
parent 3dabe26c
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
json_headers();
$itemid = param_integer('itemid');
if (!delete_records('group_category','id', $itemid)) {
json_reply('local', get_string('deletefailed','admin'));
}
json_reply(false, get_string('groupcategorydeleted','admin'));
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$public = (int) param_boolean('public');
$result = array();
$groupcategories = get_records_array('group_category','','','displayorder');
$rows = array();
if ($groupcategories) {
foreach ($groupcategories as $i) {
$r = array();
$r['id'] = $i->id;
$r['name'] = $i->title;
$rows[] = $r;
}
}
$result['groupcategories'] = array_values($rows);
$result['error'] = false;
$result['message'] = false;
json_headers();
echo json_encode($result);
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite/groups');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'groups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('groups', 'admin'));
$strings = array('edit','delete','update','cancel','add','name','unknownerror');
$adminstrings = array('confirmdeletecategory', 'deletefailed');
foreach ($strings as $string) {
$getstring[$string] = json_encode(get_string($string));
}
foreach ($adminstrings as $string) {
$getstring[$string] = json_encode(get_string($string, 'admin'));
}
//set up initial pieform
$groupoptionform = array(
'name' => 'groupoptions',
'jsform' => true,
'renderer' => 'table',
'plugintype' => 'core',
'pluginname' => 'admin',
'jssuccesscallback' => 'checkReload',
'elements' => array(
'creategroups' => array(
'type' => 'select',
'title' => get_string('whocancreategroups', 'admin'),
'description' => get_string('whocancreategroupsdescription', 'admin'),
'defaultvalue' => get_config('creategroups'),
'options' => array(
'admins' => get_string('adminsonly', 'admin'),
'staff' => get_string('adminsandstaffonly', 'admin'),
'all' => get_string('Everyone', 'admin'),
),
),
'createpublicgroups' => array(
'type' => 'select',
'title' => get_string('whocancreatepublicgroups', 'admin'),
'description' => get_string('whocancreatepublicgroupsdescription', 'admin'),
'defaultvalue' => get_config('createpublicgroups'),
'options' => array(
'admins' => get_string('adminsonly', 'admin'),
'all' => get_string('Everyone', 'admin'),
),
'help' => true,
),
'allowgroupcategories' => array(
'type' => 'select',
'title' => get_string('allowgroupcategories', 'admin'),
'description' => get_string('allowgroupcategoriesdescription', 'admin'),
'defaultvalue' => get_config('allowgroupcategories'),
'options' => array(true => get_string('yes'), false => get_string('no')),
'help' => true,
),
)
);
$groupoptionform['elements']['submit'] = array(
'type' => 'submit',
'value' => get_string('updatesiteoptions', 'admin')
);
$groupoptionform = pieform($groupoptionform);
function groupoptions_fail(Pieform $form, $field) {
$form->reply(PIEFORM_ERR, array(
'message' => get_string('setsiteoptionsfailed', 'admin', get_string($field, 'admin')),
'goto' => '/admin/site/options.php',
));
}
function groupoptions_submit(Pieform $form, $values) {
$fields = array('creategroups', 'createpublicgroups', 'allowgroupcategories');
foreach ($fields as $field) {
if (!set_config($field, $values[$field])) {
siteoptions_fail($form, $field);
}
}
$message = get_string('groupoptionsset', 'group');
$form->reply(PIEFORM_OK, array('message' => $message, 'goto' => '/admin/site/groups.php'));
}
if (get_config('allowgroupcategories')) {
$thead = array(json_encode(get_string('name', 'admin')), '""');
$ijs = "var thead = TR(null,map(partial(TH,null),[" . implode($thead,",") . "]));\n";
$ijs .= <<< EOJS
// Request a list of menu items from the server
function getitems() {
sendjsonrequest('getgroupcategories.json.php', {}, 'GET',
function(data) { displaymenuitems(data.groupcategories); });
}
// Puts the list of menu items into the empty table.
function displaymenuitems(itemlist) {
var rows = map(formatrow,itemlist);
var form = FORM({'id':'form','method':'post','enctype':'multipart/form-data',
'encoding':'multipart/form-data'},
TABLE({'class':'nohead'},TBODY(null,[thead,rows,addform()])));
replaceChildNodes($('menuitemlist'),form);
}
// Creates one table row
function formatrow (item) {
// item has id, type, name, link, linkedto
var del = INPUT({'type':'button','class':'button','value':{$getstring['delete']}});
connect(del, 'onclick', function () { delitem(item.id); });
var edit = INPUT({'type':'button','class':'button','value':{$getstring['edit']}});
connect(edit, 'onclick', function () { edititem(item); });
var cells = map(
partial(TD,null),
[
item.name,
[del,edit,contextualHelpIcon(null, null, 'core', 'admin', null, 'adminmenuedit')]
]
);
return TR({'id':'menuitem_'+item.id},cells);
}
// Returns the form which adds a new menu item
function addform(type) {
var item = {'id':'new'};
return editform(item);
}
// Creates the contents of a menu item edit form
// This is formatted as a table within the form (which is within a row of the table).
function editform(item) {
// item has id, name
// Either a save, a cancel button, or both.
var savecancel = [];
var save = INPUT({'type':'button','class':'button'});
connect(save, 'onclick', function () { saveitem(item.id); });
var rowtype = 'add';
if (!item) {
// This is the 'add' form rather than the edit form
// Set defaults.
item = {'type':'externallist'};
}
if (!item.name) {
item.name = '';
// The save button says 'add', and there's no cancel button.
setNodeAttribute(save,'value',{$getstring['add']});
savecancel = [save];
}
else { // Editing an existing menu item.
// The save button says 'update' and there's a cancel button.
var rowtype = 'edit';
setNodeAttribute(save,'value',{$getstring['update']});
var cancel = INPUT({'type':'button','class':'button','value':{$getstring['cancel']}});
connect(cancel, 'onclick', closeopenedits);
savecancel = [save,cancel];
}
// A text field for the name
var name = INPUT({'type':'text','class':'text','id':'name'+item.id,'value':item.name});
var row = TR({'id':'row'+item.id, 'class':rowtype},
map(partial(TD,null),[name,savecancel]));
return row;
}
// Close all open edit forms
function closeopenedits() {
var rows = getElementsByTagAndClassName('tr',null,$('menuitemlist'));
for (var i=0; i<rows.length; i++) {
if (hasElementClass(rows[i],'edit')) {
removeElement(rows[i]);
}
else if (hasElementClass(rows[i],'invisible')) {
removeElementClass(rows[i],'invisible');
}
}
}
// Open a new edit form
function edititem(item) {
closeopenedits();
var menuitem = $('menuitem_'+item.id);
addElementClass(menuitem,'invisible');
var newrow = editform(item);
insertSiblingNodesBefore(menuitem, newrow);
}
// Receive standard json error message
// Request deletion of a menu item from the db
function delitem(itemid) {
if (confirm({$getstring['confirmdeletecategory']})) {
sendjsonrequest('deletegroupcategory.json.php',{'itemid':itemid}, 'POST', getitems);
}
}
// Send the menu item in the form to the database.
function saveitem(itemid) {
var f = $('form');
var name = $('name'+itemid).value;
if (name == '') {
displayMessage(get_string('namedfieldempty',{$getstring['name']}),'error');
return false;
}
var data = {'name':name,
'itemid':itemid,};
sendjsonrequest('updategroup.json.php', data, 'POST', getitems);
return false;
}
addLoadEvent(function () {
getitems();
});
EOJS;
}
$style = '<style type="text/css">.invisible{display:none;}</style>';
$smarty = smarty(array('groupoptions'), array($style));
$smarty->assign('PAGEHEADING', hsc(get_string('groups', 'admin')));
$smarty->assign('groupoptionform', $groupoptionform);
if (get_config('allowgroupcategories')) {
$smarty->assign('grouptitle', get_string('groupsdescription', 'admin'));
$smarty->assign('INLINEJAVASCRIPT', $ijs);
}
$smarty->display('admin/site/groups.tpl');
?>
\ No newline at end of file
......@@ -326,30 +326,6 @@ $siteoptionform = array(
'help' => true,
'disabled' => in_array('allowpublicprofiles', $OVERRIDDEN),
),
'creategroups' => array(
'type' => 'select',
'title' => get_string('whocancreategroups', 'admin'),
'description' => get_string('whocancreategroupsdescription', 'admin'),
'defaultvalue' => get_config('creategroups'),
'options' => array(
'admins' => get_string('adminsonly', 'admin'),
'staff' => get_string('adminsandstaffonly', 'admin'),
'all' => get_string('Everyone', 'admin'),
'disabled' => in_array('creategroups', $OVERRIDDEN),
),
),
'createpublicgroups' => array(
'type' => 'select',
'title' => get_string('whocancreatepublicgroups', 'admin'),
'description' => get_string('whocancreatepublicgroupsdescription', 'admin'),
'defaultvalue' => get_config('createpublicgroups'),
'options' => array(
'admins' => get_string('adminsonly', 'admin'),
'all' => get_string('Everyone', 'admin'),
),
'help' => true,
'disabled' => in_array('createpublicgroups', $OVERRIDDEN),
),
'showtagssideblock' => array(
'type' => 'checkbox',
'title' => get_string('showtagssideblock', 'admin'),
......@@ -410,7 +386,7 @@ function siteoptions_submit(Pieform $form, $values) {
$fields = array(
'sitename','lang','theme', 'pathtoclam',
'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
'allowpublicviews', 'allowpublicprofiles', 'creategroups', 'createpublicgroups', 'searchplugin',
'allowpublicviews', 'allowpublicprofiles', 'searchplugin',
'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend',
'showselfsearchsideblock', 'showtagssideblock',
'tagssideblockmaxtags', 'country', 'viewmicroheaders', 'userscanchooseviewthemes',
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
json_headers();
$name = param_variable('name');
$itemid = param_variable('itemid');
$data = new StdClass;
$data->title = $name;
if ($itemid == 'new') {
try {
$displayorders = get_records_array('group_category', '', '', '', 'displayorder');
$max = 0;
if ($displayorders) {
foreach ($displayorders as $r) {
$max = $r->displayorder >= $max ? $r->displayorder + 1 : $max;
}
}
$data->displayorder = $max;
insert_record('group_category', $data);
}
catch (Exception $e) {
json_reply('local',get_string('savefailed','admin'));
}
}
else {
$data->id = $itemid;
try {
update_record('group_category', $data, 'id');
}
catch (Exception $e) {
json_reply('local',get_string('savefailed','admin'));
}
}
json_reply(false,get_string('menuitemsaved','admin'));
?>
......@@ -35,32 +35,31 @@ define('TITLE', get_string('creategroup', 'group'));
if (!group_can_create_groups()) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$creategroup = pieform(array(
'name' => 'creategroup',
'method' => 'post',
'plugintype' => 'core',
'pluginname' => 'groups',
'elements' => array(
'name' => array(
$elements = array();
$elements['name'] = array(
'type' => 'text',
'title' => get_string('groupname', 'group'),
'rules' => array( 'required' => true, 'maxlength' => 128 ),
),
'description' => array(
'rules' => array( 'required' => true, 'maxlength' => 128 ));
$elements['description'] = array(
'type' => 'wysiwyg',
'title' => get_string('groupdescription', 'group'),
'rows' => 10,
'cols' => 55,
),
'grouptype' => array(
'cols' => 55);
$elements['grouptype'] = array(
'type' => 'select',
'title' => get_string('grouptype', 'group'),
'options' => group_get_grouptype_options(),
'defaultvalue' => 'standard.open',
'help' => true,
),
'public' => array(
'help' => true);
if (get_config('allowgroupcategories')) {
$elements['groupcategory'] = array(
'type' => 'select',
'title' => get_string('groupcategory', 'group'),
'options' => get_records_menu('group_category','','','displayorder', 'id,title'),
'defaultvalue' => '',
'help' => true);
}
$elements['public'] = array(
'type' => 'select',
'title' => get_string('publiclyviewablegroup', 'group'),
'description' => get_string('publiclyviewablegroupdescription', 'group'),
......@@ -68,9 +67,8 @@ $creategroup = pieform(array(
false => get_string('no')),
'defaultvalue' => 'no',
'help' => true,
'ignore' => !(get_config('createpublicgroups') == 'all' || get_config('createpublicgroups') == 'admins' && $USER->get('admin')),
),
'usersautoadded' => array(
'ignore' => !(get_config('createpublicgroups') == 'all' || get_config('createpublicgroups') == 'admins' && $USER->get('admin')));
$elements['usersautoadded'] = array(
'type' => 'select',
'title' => get_string('usersautoadded', 'group'),
'description' => get_string('usersautoaddeddescription', 'group'),
......@@ -78,13 +76,17 @@ $creategroup = pieform(array(
false => get_string('no')),
'defaultvalue' => 'no',
'help' => true,
'ignore' => !$USER->get('admin'),
),
'submit' => array(
'ignore' => !$USER->get('admin'));
$elements['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('savegroup', 'group'), get_string('cancel')),
),
),
'value' => array(get_string('savegroup', 'group'), get_string('cancel')));
$creategroup = pieform(array(
'name' => 'creategroup',
'method' => 'post',
'plugintype' => 'core',
'pluginname' => 'groups',
'elements' => $elements
));
$smarty = smarty();
......@@ -115,6 +117,7 @@ function creategroup_submit(Pieform $form, $values) {
'name' => $values['name'],
'description' => $values['description'],
'grouptype' => $grouptype,
'groupcategory' => intval($values['groupcategory']),
'jointype' => $jointype,
'public' => intval($values['public']),
'usersautoadded' => intval($values['usersautoadded']),
......
<
......@@ -35,7 +35,7 @@ define('TITLE', get_string('editgroup', 'group'));
$id = param_integer('id');
define('GROUP', $id);
$group_data = get_record_sql("SELECT g.id, g.name, g.description, g.grouptype, g.jointype, g.public, g.usersautoadded
$group_data = get_record_sql("SELECT g.id, g.name, g.description, g.grouptype, g.jointype, g.public, g.usersautoadded, g.groupcategory
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
WHERE g.id = ?
......@@ -45,34 +45,33 @@ if (!$group_data) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('/group/mygroups.php');
}
$editgroup = pieform(array(
'name' => 'editgroup',
'method' => 'post',
'plugintype' => 'core',
'pluginname' => 'groups',
'elements' => array(
'name' => array(
$elements = array();
$elements['name'] = array(
'type' => 'text',
'title' => get_string('groupname', 'group'),
'rules' => array( 'required' => true, 'maxlength' => 128 ),
'defaultvalue' => $group_data->name,
),
'description' => array(
'defaultvalue' => $group_data->name);
$elements['description'] = array(
'type' => 'wysiwyg',
'title' => get_string('groupdescription', 'group'),
'rows' => 10,
'cols' => 55,
'defaultvalue' => $group_data->description,
),
'grouptype' => array(
'defaultvalue' => $group_data->description);
$elements['grouptype'] = array(
'type' => 'select',
'title' => get_string('grouptype', 'group'),
'options' => group_get_grouptype_options($group_data->grouptype),
'defaultvalue' => $group_data->grouptype . '.' . $group_data->jointype,