Commit a433ede3 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Groups section

parent e49703b6
<?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');
?>
{include file="header.tpl"}
{include file="adminmenu.tpl"}
<div class="content">
<h2>{str tag="creategroup"}</h2>
{$creategroup}
</div>
{include file="footer.tpl"}
......@@ -7,8 +7,12 @@
<a href="create.php">{str tag="creategroup"}</a>
<table>
<table id="grouplist">
<thead>
<tr>
<th>{str tag="groupname"}</th>
<th>{str tag="membercount"}</th>
</tr>
</thead>
<tbody>
</tbody>
......
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