Commit 086acf17 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Browse & select from multiple files areas in html block config

parent 740f210d
......@@ -93,7 +93,7 @@ class PluginBlocktypeHtml extends PluginBlocktype {
'name' => 'filebrowser',
'type' => 'filebrowser',
'title' => get_string('file', 'artefact.file'),
'folder' => param_integer('folder', 0),
'folder' => (int) param_variable('folder', 0),
'highlight' => null,
'browse' => true,
'page' => View::make_base_url(),
......@@ -106,6 +106,7 @@ class PluginBlocktypeHtml extends PluginBlocktype {
'selectone' => true,
'alwaysopen' => true,
),
'tabs' => $instance->get_view()->ownership(),
'filters' => array(
'artefacttype' => array('file'),
'filetype' => self::get_allowed_mimetypes(),
......
......@@ -36,9 +36,26 @@ defined('INTERNAL') || die();
function pieform_element_filebrowser(Pieform $form, $element) {
global $USER, $_PIEFORM_FILEBROWSERS;
$smarty = smarty_core();
$group = $form->get_property('group');
$institution = $form->get_property('institution');
$userid = ($group || $institution) ? null : $USER->get('id');
if (!empty($element['tabs'])) {
$tabdata = pieform_element_filebrowser_configure_tabs($element['tabs']);
$smarty->assign('tabs', $tabdata);
if ($tabdata['owner'] == 'group') {
$group = $tabdata['ownerid'];
} else if ($tabdata['owner'] == 'institution') {
$institution = $tabdata['ownerid'];
} else if ($tabdata['owner'] == 'site') {
$institution = 'mahara';
}
}
if (empty($group)) {
$group = $form->get_property('group');
}
if (empty($institution)) {
$institution = $form->get_property('institution');
}
$userid = ($group || $institution) ? null : $USER->get('id');
if ($group) {
$smarty->assign('groupinfo', pieform_element_filebrowser_get_groupinfo($group));
......@@ -138,7 +155,7 @@ function pieform_element_filebrowser_get_path($folder) {
return $path;
}
function pieform_element_filebrowser_build_path($form, $element, $folder) {
function pieform_element_filebrowser_build_path($form, $element, $folder, $owner=null, $ownerid=null) {
if (!$form->submitted_by_js()) {
return;
}
......@@ -149,11 +166,13 @@ function pieform_element_filebrowser_build_path($form, $element, $folder) {
$smarty = smarty_core();
$smarty->assign('path', array_reverse($path));
$smarty->assign('owner', $owner);
$smarty->assign('ownerid', $ownerid);
$smarty->assign('querybase', $querybase);
return array('html' => $smarty->fetch('artefact:file:form/folderpath.tpl'), 'foldername' => $foldername);
}
function pieform_element_filebrowser_build_filelist($form, $element, $folder, $highlight=null) {
function pieform_element_filebrowser_build_filelist($form, $element, $folder, $highlight=null, $group=null, $institution=null) {
if (!$form->submitted_by_js()) {
// We're going to rebuild the page from scratch anyway.
return;
......@@ -161,8 +180,22 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h
global $USER;
$group = $form->get_property('group');
$institution = $form->get_property('institution');
$smarty = smarty_core();
if (is_null($group)) {
$group = $form->get_property('group');
}
else {
$smarty->assign('owner', 'group');
$smarty->assign('ownerid', $group);
}
if (is_null($institution)) {
$institution = $form->get_property('institution');
}
else {
$smarty->assign('owner', 'institution');
$smarty->assign('ownerid', $institution);
}
$userid = ($group || $institution) ? null : $USER->get('id');
$editable = (int) $element['config']['edit'];
$selectable = (int) $element['config']['select'];
......@@ -172,7 +205,6 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h
$filters = isset($element['filters']) ? $element['filters'] : null;
$filedata = ArtefactTypeFileBase::get_my_files_data($folder, $userid, $group, $institution, $filters);
$smarty = smarty_core();
$smarty->assign('edit', -1);
$smarty->assign('highlight', $highlight);
$smarty->assign('editable', $editable);
......@@ -187,6 +219,63 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h
);
}
function pieform_element_filebrowser_configure_tabs($viewowner) {
if ($viewowner['type'] == 'institution' && $viewowner['id'] == 'mahara') {
// No filebrowser tabs for site views
return null;
}
$tabs = array();
$subtabs = array();
$upload = null;
$selectedsubtab = null;
if ($viewowner['type'] == 'institution') {
$selectedtab = param_alpha('owner', 'institution');
$upload = $selectedtab == 'institution';
$tabs['institution'] = get_string('institutionfiles', 'admin');
}
else if ($viewowner['type'] == 'group') {
$selectedtab = param_alpha('owner', 'group');
$upload = $selectedtab == 'group';
$tabs['group'] = get_string('groupfiles', 'artefact.file');
}
else { // $viewowner['type'] == 'user'
global $USER;
$selectedtab = param_alpha('owner', 'user');
$upload = $selectedtab == 'user';
$tabs['user'] = get_string('myfiles', 'artefact.file');
if ($groups = $USER->get('grouproles')) {
$tabs['group'] = get_string('groupfiles', 'artefact.file');
require_once(get_config('libroot') . 'group.php');
$groups = group_get_user_groups($USER->get('id'));
if ($selectedtab == 'group') {
if (!$selectedsubtab = (int) param_variable('ownerid', 0)) {
$selectedsubtab = $groups[0]->id;
}
foreach ($groups as &$g) {
$subtabs[$g->id] = $g->name;
}
}
}
if ($institutions = $USER->get('institutions')) {
$tabs['institution'] = get_string('institutionfiles', 'admin');
$institutions = get_records_select_array('institution', 'name IN ('
. join(',', array_map('db_quote', array_keys($institutions))) . ')');
if ($selectedtab == 'institution') {
if (!$selectedsubtab = param_variable('ownerid', '')) {
$selectedsubtab = $institutions[0]->name;
}
$selectedsubtab = hsc($selectedsubtab);
foreach ($institutions as &$i) {
$subtabs[$i->name] = $i->displayname;
}
}
}
}
$tabs['site'] = get_string('sitefiles', 'admin');
return array('tabs' => $tabs, 'subtabs' => $subtabs, 'owner' => $selectedtab, 'ownerid' => $selectedsubtab, 'upload' => $upload);
}
function pieform_element_filebrowser_get_value(Pieform $form, $element) {
// Check if the user tried to make a change to the filebrowser element
......@@ -396,6 +485,15 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
return $result;
}
$changeowner = param_variable($prefix . '_changeowner', null);
if (!empty($changeowner)) {
// @TODO: drop non-admin users in public folder when they change to site owner.
$result = pieform_element_filebrowser_changeowner($form, $element, 0);
$result['browse'] = 1;
$result['folder'] = 0;
return $result;
}
$newfolder = param_variable($prefix . '_changefolder', null);
if (!is_null($newfolder) && is_numeric($newfolder)) {
$result = pieform_element_filebrowser_changefolder($form, $element, $newfolder);
......@@ -728,13 +826,62 @@ function pieform_element_filebrowser_move(Pieform $form, $element, $data) {
return array('error' => true, 'message' => get_string('movefailed', 'artefact.file'));
}
function pieform_element_filebrowser_changeowner(Pieform $form, $element, $folder) {
$newtabdata = pieform_element_filebrowser_configure_tabs($element['tabs']);
$smarty = smarty_core();
$smarty->assign('prefix', $form->get_name() . '_' . $element['name']);
$smarty->assign('querybase', $element['page'] . (strpos($element['page'], '?') === false ? '?' : '&'));
$smarty->assign('tabs', $newtabdata);
$newtabhtml = $smarty->fetch('artefact:file:form/ownertabs.tpl');
$newsubtabhtml = $smarty->fetch('artefact:file:form/ownersubtabs.tpl');
$group = null;
$institution = null;
if ($newtabdata['owner'] == 'site') {
$institution = 'mahara';
}
else if ($newtabdata['owner'] == 'institution') {
$institution = $newtabdata['ownerid'];
}
else if ($newtabdata['owner'] == 'group') {
$group = $newtabdata['ownerid'];
}
return array(
'error' => false,
'changedowner' => true,
'changedfolder' => true,
'tabupload' => $newtabdata['upload'],
'folder' => $folder,
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $group, $institution),
'newpath' => pieform_element_filebrowser_build_path($form, $element, $folder, $newtabdata['owner'], $newtabdata['ownerid']),
'newtabs' => $newtabhtml,
'newsubtabs' => $newsubtabhtml,
);
}
function pieform_element_filebrowser_changefolder(Pieform $form, $element, $folder) {
$owner = $ownerid = $group = $institution = null;
if (isset($element['tabs'])) {
if ($owner = param_variable('owner', null)) {
if ($ownerid = param_variable('ownerid', null)) {
if ($owner == 'group') {
$group = (int) $ownerid;
} else if ($owner == 'institution') {
$institution = $ownerid;
}
}
}
}
return array(
'error' => false,
'changedfolder' => true,
'folder' => $folder,
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder),
'newpath' => pieform_element_filebrowser_build_path($form, $element, $folder),
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $group, $institution),
'newpath' => pieform_element_filebrowser_build_path($form, $element, $folder, $owner, $ownerid),
);
}
......
......@@ -247,11 +247,34 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
});
forEach(getElementsByTagAndClassName('tr', 'folder', 'filelist'), self.make_row_droppable);
}
forEach(getElementsByTagAndClassName('a', 'changeowner', self.id + '_upload_browse'), function (elem) {
connect(elem, 'onclick', function (e) {
var href = getNodeAttribute(this, 'href');
var params = parseQueryString(href.substring(href.indexOf('?')+1));
$(self.id + '_changeowner').value = 1;
$(self.id + '_owner').value = params.owner;
if (params.ownerid) {
$(self.id + '_ownerid').value = params.ownerid;
}
else {
$(self.id + '_ownerid').value = '';
}
if (params.folder) {
$(self.id + '_changefolder').value = params.folder;
}
self.submitform();
$(self.id + '_changeowner').value = $(self.id + '_changefolder').value = '';
e.stop();
return false;
});
});
forEach(getElementsByTagAndClassName('a', 'changefolder', self.id + '_upload_browse'), function (elem) {
connect(elem, 'onclick', function (e) {
var href = getNodeAttribute(this, 'href');
var params = parseQueryString(href.substring(href.indexOf('?')+1));
$(self.id + '_changefolder').value = params.folder;
$(self.id + '_owner').value = params.owner ? params.owner : '';
$(self.id + '_ownerid').value = params.ownerid ? params.ownerid : '';
self.submitform();
$(self.id + '_changefolder').value = '';
e.stop();
......@@ -468,6 +491,15 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
$(self.id+'_folder').value = self.folderid = data.folder;
$(self.id+'_foldername').value = self.foldername = data.newpath.foldername;
$(self.id+'_foldernav').innerHTML = data.newpath.html;
if (data.changedowner && data.newtabs) {
$(self.id+'_ownertabs').innerHTML = data.newtabs;
$(self.id+'_ownersubtabs').innerHTML = data.newsubtabs;
if (data.tabupload) {
removeElementClass(self.id + '_upload_container', 'hidden');
} else {
addElementClass(self.id + '_upload_container', 'hidden');
}
}
}
else if (data.uploaded && self.config.select && data.highlight) {
// Newly uploaded files should be automatically selected
......
......@@ -22,7 +22,20 @@
<input type="submit" class="buttondk" name="{$prefix}_cancelbrowse" id="{$prefix}_close_upload_browse" value="{str tag=Close}" />
{/if}
<table class="fileupload">
{if $tabs}
<input type="hidden" name="owner" id="{$prefix}_owner" value="{$tabs.owner}" />
<input type="hidden" name="ownerid" id="{$prefix}_ownerid" value="{$tabs.ownerid}" />
<input type="hidden" name="{$prefix}_changeowner" id="{$prefix}_changeowner" value="" />
<div id="{$prefix}_ownertabs">
{include file="artefact:file:form/ownertabs.tpl" tabs=$tabs prefix=$prefix querybase=$querybase}
</div>
<div id="artefactchooser-body">
<div id="{$prefix}_ownersubtabs">
{if $tabs.subtabs}{include file="artefact:file:form/ownersubtabs.tpl" tabs=$tabs prefix=$prefix querybase=$querybase}{/if}
</div>
{/if}
<table id="{$prefix}_upload_container" class="fileupload{if $tabs && !$tabs.upload} hidden{/if}">
<tbody>
{if $config.upload}
<tr><td><input type="hidden" name="{$prefix}_uploadnumber" id="{$prefix}_uploadnumber" value="1" /></td></tr>
......@@ -75,11 +88,11 @@
{/if}
<div id="{$prefix}_foldernav" class="foldernav">
{include file="artefact:file:form/folderpath.tpl" path=$path querybase=$querybase}
{include file="artefact:file:form/folderpath.tpl" path=$path querybase=$querybase owner=$tabs.owner ownerid=$tabs.ownerid}
</div>
<div id="{$prefix}_filelist_container">
{include file="artefact:file:form/filelist.tpl" prefix=$prefix filelist=$filelist editable=$config.edit selectable=$config.select highlight=$highlight edit=$edit querybase=$querybase groupinfo=$groupinfo}
{include file="artefact:file:form/filelist.tpl" prefix=$prefix filelist=$filelist editable=$config.edit selectable=$config.select highlight=$highlight edit=$edit querybase=$querybase groupinfo=$groupinfo owner=$tabs.owner ownerid=$tabs.ownerid}
</div>
{* Edit form used when js is available *}
......@@ -91,4 +104,8 @@
</table>
{/if}
{if $tabs}
</div>
{/if}
</div>
\ No newline at end of file
......@@ -27,7 +27,7 @@
<td class="filename">
{assign var=displaytitle value=$file->title|str_shorten_text:34|escape}
{if $file->artefacttype == 'folder'}
<a href="{$querybase}folder={$file->id}" class="changefolder" title="{str tag=gotofolder section=artefact.file arg1=$displaytitle}">{$displaytitle}</a>
<a href="{$querybase}folder={$file->id}{if $owner}&owner={$owner}{if $ownerid}&ownerid={$ownerid}{/if}{/if}" class="changefolder" title="{str tag=gotofolder section=artefact.file arg1=$displaytitle}">{$displaytitle}</a>
{else}
<a href="{$WWWROOT}artefact/file/download.php?file={$file->id}" target="_blank" title="{str tag=downloadfile section=artefact.file arg1=$displaytitle}">{$displaytitle}</a>
{/if}
......
{foreach from=$path item=f name=path}
{if !$smarty.foreach.path.first}/ {/if}<a href="{$querybase}folder={$f->id}" class="changefolder">{$f->title|str_shorten_text:34|escape}</a>
{if !$smarty.foreach.path.first}/ {/if}<a href="{$querybase}folder={$f->id}{if $owner}&owner={$owner}{if $ownerid}&ownerid={$ownerid}{/if}{/if}" class="changefolder">{$f->title|str_shorten_text:34|escape}</a>
{/foreach}
{if $tabs.subtabs}
<ul class="artefactchooser-subtabs">
{foreach from=$tabs.subtabs item=displayname key=ownerid}
<li{if $tabs.ownerid == $ownerid} class="current"{/if}><a class="changeowner" href="{$querybase}owner={$tabs.owner}&ownerid={$ownerid}">{$displayname}</a></li>
{/foreach}
</ul>
{/if}
<ul class="artefactchooser-tabs files">
{foreach from=$tabs.tabs item=displayname key=name}
<li{if $tabs.owner == $name} class="current"{/if}><a class="changeowner" href="{$querybase}owner={$name}">{$displayname}</a></li>
{/foreach}
</ul>
......@@ -1111,4 +1111,22 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=
}
function group_get_user_groups($userid=null) {
if (is_null($userid)) {
global $USER;
$userid = $USER->get('id');
}
if ($groups = get_records_sql_array(
"SELECT g.id, g.name, gm.role
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
WHERE gm.member = ?
AND g.deleted = 0
ORDER BY gm.role = 'admin' DESC, gm.role, g.id", array($userid))) {
return $groups;
}
return array();
}
?>
......@@ -1950,13 +1950,7 @@ function profile_sideblock() {
$data['invitedgroupsmessage'] = $data['invitedgroups'] == 1 ? get_string('invitedgroup') : get_string('invitedgroups');
$data['pendingfriends'] = count_records('usr_friend_request', 'owner', $USER->get('id'));
$data['pendingfriendsmessage'] = $data['pendingfriends'] == 1 ? get_string('pendingfriend') : get_string('pendingfriends');
$data['groups'] = get_records_sql_array(
"SELECT g.id, g.name, gm.role
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
WHERE gm.member = ?
AND g.deleted = 0
ORDER BY gm.role = 'admin' DESC, gm.role, g.id", array($USER->get('id')));
$data['groups'] = group_get_user_groups($USER->get('id'));
$data['views'] = get_records_sql_array(
'SELECT v.id, v.title
FROM {view} v
......
......@@ -212,6 +212,9 @@ body:last-child:not(:root:root) .newblockhere {
}
/* styling the tabs for the artefact chooser */
ul.artefactchooser-tabs.files {
margin-top: 1em;
}
ul.artefactchooser-tabs {
padding: 0;
margin: 0;
......@@ -232,6 +235,24 @@ ul.artefactchooser-tabs li.current a {
background: #ddd;
color: #333;
}
ul.artefactchooser-subtabs {
margin: 2px;
padding: 0 0 .2em 0;
font-size: .9em;
list-style: none;
border-bottom: 1px solid #ddd;
}
ul.artefactchooser-subtabs li {
display: inline;
}
ul.artefactchooser-subtabs li a {
text-decoration: none;
padding: 2px;
}
ul.artefactchooser-subtabs li.current a {
color: #333;
font-weight: bold;
}
#artefactchooser-body {
border: 1px solid #ddd;
......
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