Commit d3adf10c authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Merge branch 'viewtemplate'

Conflicts:

	htdocs/view/columns.php
	htdocs/view/layout.php
parents eb0347b9 7f067328
......@@ -26,14 +26,14 @@
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite/adminfiles');
define('MENUITEM', 'configsite/sitefiles');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'adminfiles');
define('SECTION_PAGE', 'sitefiles');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
define('TITLE', get_string('adminfiles', 'admin'));
define('TITLE', get_string('sitefiles', 'admin'));
$copyright = get_field('site_content', 'content', 'name', 'uploadcopyright');
$wwwroot = get_config('wwwroot');
......@@ -52,7 +52,7 @@ $smarty = smarty(array('tablerenderer',
'artefact/file/js/file.js'));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('descriptionstrargs', array('<a href="' . get_config('wwwroot') . 'admin/site/menu.php">', '</a>'));
$smarty->assign('heading', get_string('adminfiles', 'admin'));
$smarty->assign('heading', get_string('sitefiles', 'admin'));
$smarty->display('admin/site/files.tpl');
?>
......@@ -50,7 +50,7 @@ if ($menuitems) {
$r['id'] = $i->id;
$r['name'] = $i->title;
if (empty($i->url) && !empty($i->file)) {
$r['type'] = 'adminfile';
$r['type'] = 'sitefile';
$r['linkedto'] = get_config('wwwroot') . 'artefact/file/download.php?file=' . $i->file;
$r['linktext'] = $i->filename;
$r['file'] = $i->file;
......
......@@ -36,8 +36,8 @@ define('TITLE', get_string('linksandresourcesmenu', 'admin'));
$strings = array('edit','delete','update','cancel','add','name','unknownerror');
$adminstrings = array('confirmdeletemenuitem', 'deletefailed','deletingmenuitem','savingmenuitem',
'noadminfiles','loggedinmenu','loggedoutmenu','linkedto','externallink','adminfile',
'loadingmenuitems','menuitemsloaded','failedloadingadminfiles',
'nositefiles','loggedinmenu','loggedoutmenu','linkedto','externallink','sitefile',
'loadingmenuitems','menuitemsloaded','failedloadingsitefiles',
'failedloadingmenuitems');
foreach ($strings as $string) {
$getstring[$string] = json_encode(get_string($string));
......@@ -49,7 +49,7 @@ foreach ($adminstrings as $string) {
$thead = array(json_encode(get_string('type', 'admin')), json_encode(get_string('name', 'admin')), json_encode(get_string('linkedto', 'admin')), '""');
$ijs = "var thead = TR(null,map(partial(TH,null),[" . implode($thead,",") . "]));\n";
$ijs .= "var externallink = " . json_encode(get_string('externallink', 'admin')) . ";\n";
$ijs .= "var adminfile = " . json_encode(get_string('adminfile','admin')) . ";\n";
$ijs .= "var sitefile = " . json_encode(get_string('sitefile','admin')) . ";\n";
$ijs .= <<< EOJS
// Request a list of menu items from the server
......@@ -115,7 +115,7 @@ function editform(item) {
// item has id, type, name, link, linkedto
// The form has two radio buttons to select the type, external link or admin file
var elink = INPUT({'type':'radio','class':'radio','name':'type'+item.id,'value':'externallink'});
var afile = INPUT({'type':'radio','class':'radio','name':'type'+item.id,'value':'adminfile'});
var afile = INPUT({'type':'radio','class':'radio','name':'type'+item.id,'value':'sitefile'});
// Either a save, a cancel button, or both.
var savecancel = [];
......@@ -135,7 +135,7 @@ function editform(item) {
item.linkedto = '';
item.name = '';
connect(elink, 'onclick', function () { changeaddform('externallink'); });
connect(afile, 'onclick', function () { changeaddform('adminfile'); });
connect(afile, 'onclick', function () { changeaddform('sitefile'); });
// The save button says 'add', and there's no cancel button.
setNodeAttribute(save,'value',{$getstring['add']});
savecancel = [save];
......@@ -148,16 +148,16 @@ function editform(item) {
connect(cancel, 'onclick', closeopenedits);
savecancel = [save,cancel];
connect(elink, 'onclick', function () { changeeditform(item,'externallink'); });
connect(afile, 'onclick', function () { changeeditform(item,'adminfile'); });
connect(afile, 'onclick', function () { changeeditform(item,'sitefile'); });
}
// A text field for the name
var name = INPUT({'type':'text','class':'text','id':'name'+item.id,'value':item.name});
if (item.type == 'adminfile') {
if (item.type == 'sitefile') {
if (adminfiles == null) {
// There are no admin files, we don't need the select or save button
linkedto = {$getstring['noadminfiles']};
linkedto = {$getstring['nositefiles']};
savecancel = [cancel];
}
else {
......@@ -180,7 +180,7 @@ function editform(item) {
setNodeAttribute(elink,'checked',true);
}
var radios = [DIV(null, LABEL(null,elink,{$getstring['externallink']}), contextualHelpIcon(null, null, 'core', 'admin', null, 'adminexternallink')),
DIV(null, LABEL(null,afile,{$getstring['adminfile']}), contextualHelpIcon(null, null, 'core', 'admin', null, 'adminadminfile'))];
DIV(null, LABEL(null,afile,{$getstring['sitefile']}), contextualHelpIcon(null, null, 'core', 'admin', null, 'adminsitefile'))];
var row = TR({'id':'row'+item.id, 'class':rowtype},
map(partial(TD,null),[radios,name,linkedto,savecancel]));
return row;
......@@ -242,7 +242,7 @@ function saveitem(itemid) {
return false;
}
var data = {'type':eval('f.type'+itemid+'[0].checked') ? 'externallink' : 'adminfile',
var data = {'type':eval('f.type'+itemid+'[0].checked') ? 'externallink' : 'sitefile',
'name':name,
'linkedto':linkedto,
'itemid':itemid,
......
......@@ -39,7 +39,7 @@ $itemid = param_variable('itemid');
$public = (int) param_boolean('public');
$data = new StdClass;
if ($type == 'adminfile') {
if ($type == 'sitefile') {
// Get file id.
$data->file = $linkedto;
}
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite/siteviews');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'siteviews');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(get_config('libroot') . 'view.php');
require_once('pieforms/pieform.php');
$limit = param_integer('limit', 5);
$offset = param_integer('offset', 0);
$title = get_string('siteviews', 'admin');
define('TITLE', $title);
$smarty = smarty();
$smarty->assign('heading', $title);
$data = View::get_myviews_data($limit, $offset, null, 'mahara');
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'view/?',
'count' => $data->count,
'limit' => $limit,
'offset' => $offset,
'resultcounttextsingular' => get_string('view', 'view'),
'resultcounttextplural' => get_string('views', 'view')
));
$smarty->assign('views', $data->data);
$smarty->assign('institution', 'mahara');
$smarty->assign('pagination', $pagination['html']);
$smarty->display('view/index.tpl');
?>
......@@ -32,12 +32,13 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('adminusers', 'admin'));
require_once('pieforms/pieform.php');
define('MENUITEM', 'manageinstitutions/institutionadmins');
$smarty = smarty();
require_once('institution.php');
$institution = add_institution_selector_to_page($smarty, param_alphanum('institution', false),
get_config('wwwroot') . 'admin/users/institutionadmins.php');
$s = institution_selector_for_page(param_alphanum('institution', false),
get_config('wwwroot') . 'admin/users/institutionadmins.php');
$institution = $s['institution'];
$smarty = smarty();
if ($institution === false) {
$smarty->display('admin/users/noinstitutions.tpl');
exit;
......@@ -100,6 +101,8 @@ function adminusers_submit(Pieform $form, $values) {
redirect('/admin/users/institutionadmins.php?institution=' . $inst);
}
$smarty->assign('institutionselector', $s['institutionselector']);
$smarty->assign('INLINEJAVASCRIPT', $s['institutionselectorjs']);
$smarty->assign('adminusersform', pieform($form));
$smarty->display('admin/users/institutionadmins.tpl');
......
......@@ -32,12 +32,13 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('staffusers', 'admin'));
require_once('pieforms/pieform.php');
define('MENUITEM', 'manageinstitutions/institutionstaff');
$smarty = smarty();
require_once('institution.php');
$institution = add_institution_selector_to_page($smarty, param_alphanum('institution', false),
get_config('wwwroot') . 'admin/users/institutionstaff.php');
$s = institution_selector_for_page(param_alphanum('institution', false),
get_config('wwwroot') . 'admin/users/institutionstaff.php');
$institution = $s['institution'];
$smarty = smarty();
if ($institution === false) {
$smarty->display('admin/users/noinstitutions.tpl');
exit;
......@@ -99,6 +100,8 @@ function staffusers_submit(Pieform $form, $values) {
redirect('/admin/users/institutionstaff.php?institution=' . $inst);
}
$smarty->assign('institutionselector', $s['institutionselector']);
$smarty->assign('INLINEJAVASCRIPT', $s['institutionselectorjs']);
$smarty->assign('staffusersform', pieform($form));
$smarty->display('admin/users/institutionstaff.tpl');
......
......@@ -131,6 +131,15 @@ class PluginBlocktypeBlog extends PluginBlocktype {
//public static function artefactchooser_get_sort_order() {
// return 'parent, ctime DESC';
//}
public static function copy_allowed($newowner=null) {
return false;
}
public static function copy_artefacts_allowed($newowner=null) {
return false;
}
}
?>
......@@ -129,6 +129,15 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
public static function artefactchooser_get_sort_order() {
return 'parent, ctime DESC';
}
public static function copy_allowed($newowner=null) {
return false;
}
public static function copy_artefacts_allowed($newowner=null) {
return false;
}
}
?>
......@@ -107,6 +107,15 @@ class PluginBlocktypeRecentposts extends PluginBlocktype {
public static function artefactchooser_get_sort_order() {
return 'title';
}
public static function copy_allowed($newowner=null) {
return false;
}
public static function copy_artefacts_allowed($newowner=null) {
return false;
}
}
?>
......@@ -666,17 +666,18 @@ class ArtefactTypeBlogPost extends ArtefactType {
}
public static function blogfiles_folder_id($create = true) {
global $USER;
$name = get_string('blogfilesdirname', 'artefact.blog');
$description = get_string('blogfilesdirdescription', 'artefact.blog');
safe_require('artefact', 'file');
return ArtefactTypeFolder::get_folder_id($name, $description, null, null, $create);
return ArtefactTypeFolder::get_folder_id($name, $description, null, $create, $USER->get('id'));
}
// Change the name & description of a user's blogfiles folder when the user changes language pref
public static function change_language($userid, $oldlang, $newlang) {
$oldname = get_string_from_language($oldlang, 'blogfilesdirname', 'artefact.blog');
safe_require('artefact', 'file');
$blogfiles = ArtefactTypeFolder::get_folder_by_name($oldname, null, $userid);
$blogfiles = ArtefactTypeFolder::get_folder_by_name($oldname, null, $userid, null, null);
if (empty($blogfiles)) {
return;
}
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 artefact-file
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'manageinstitutions/institutionfiles');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'institutionfiles');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
require_once('institution.php');
$institution = param_alphanum('institution', false);
define('TITLE', get_string('institutionfiles', 'admin'));
$s = institution_selector_for_page($institution,
get_config('wwwroot') . 'artefact/file/institutionfiles.php');
$institution = $s['institution'];
$smarty = smarty(array('tablerenderer', 'artefact/file/js/file.js'));
if ($institution === false) {
$smarty->display('admin/users/noinstitutions.tpl');
exit;
}
if (!$USER->can_edit_institution($institution)) {
throw new AccessDeniedException();
}
$javascript = ArtefactTypeFileBase::get_my_files_js(param_integer('folder', null));
$institutionstr = json_encode($institution);
$javascript .= <<<JS
browser.source += '?institution={$institution}';
browser.createfolderscript += '?institution={$institution}';
uploader.uploadscript += '?institution={$institution}';
JS;
$smarty->assign('institutionselector', $s['institutionselector']);
$smarty->assign('INLINEJAVASCRIPT', $s['institutionselectorjs'] . $javascript);
$smarty->assign('heading', TITLE);
$smarty->display('artefact:file:index.tpl');
?>
......@@ -28,7 +28,7 @@ defined('INTERNAL') || die();
$string['pluginname'] = 'Files';
$string['adminfilesloaded'] = 'Admin files loaded';
$string['sitefilesloaded'] = 'Site files loaded';
$string['bytes'] = 'bytes';
$string['changessaved'] = 'Changes saved';
$string['contents'] = 'Contents';
......
......@@ -395,25 +395,13 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
// either in adminfiles or with a specific owner.
public static function file_exists($title, $owner, $folder, $institution=null, $group=null) {
$filetypesql = "('" . join("','", PluginArtefactFile::get_artefact_types()) . "')";
$phvals = array($title);
if ($institution) {
$ownersql = 'a.institution = ? AND a.owner IS NULL';
$phvals[] = $institution;
}
else if ($group) {
$ownersql = 'a.group = ? AND a.owner IS NULL';
$phvals[] = $group;
}
else {
$ownersql = 'a.institution IS NULL AND a.owner = ?';
$phvals[] = $owner;
}
$ownersql = artefact_owner_sql($owner, $group, $institution);
return get_field_sql('SELECT a.id FROM {artefact} a
LEFT OUTER JOIN {artefact_file_files} f ON f.artefact = a.id
WHERE a.title = ?
AND ' . $ownersql . '
AND a.' . $ownersql . '
AND a.parent ' . (empty($folder) ? ' IS NULL' : ' = ' . $folder) . '
AND a.artefacttype IN ' . $filetypesql, $phvals);
AND a.artefacttype IN ' . $filetypesql, array($title));
}
......@@ -577,7 +565,7 @@ JAVASCRIPT;
return $javascript;
}
public static function count_user_files($owner=null, $institution=null, $group=null) {
public static function count_user_files($owner=null, $group=null, $institution=null) {
$filetypes = PluginArtefactFile::get_artefact_types();
foreach ($filetypes as $k => $v) {
if ($v == 'folder') {
......@@ -586,26 +574,10 @@ JAVASCRIPT;
}
$filetypesql = "('" . join("','", $filetypes) . "')";
$phvals = array();
if ($institution) {
$ownersql = 'institution = ? AND "group" IS NULL AND owner IS NULL';
$phvals[] = $institution;
}
else if ($group) {
$ownersql = '"group" = ? AND institution IS NULL AND owner IS NULL';
$phvals[] = $group;
}
else {
if (!$owner) {
global $USER;
$owner = $USER->get('id');
}
$ownersql = 'institution IS NULL AND "group" IS NULL AND owner = ?';
$phvals[] = $owner;
}
$ownersql = artefact_owner_sql($owner, $group, $institution);
return (object) array(
'files' => count_records_select('artefact', "artefacttype IN $filetypesql AND $ownersql", $phvals),
'folders' => count_records_select('artefact', "artefacttype = 'folder' AND $ownersql", $phvals)
'files' => count_records_select('artefact', "artefacttype IN $filetypesql AND $ownersql", array()),
'folders' => count_records_select('artefact', "artefacttype = 'folder' AND $ownersql", array())
);
}
......@@ -889,6 +861,25 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
public static function get_quota_usage($artefact) {
return get_field('artefact_file_files', 'size', 'artefact', $artefact);
}
public function copy_extra($new) {
$oldid = $this->get('id');
$dataroot = get_config('dataroot');
$oldfile = $dataroot . self::get_file_directory($oldid) . '/' . $oldid;
$newid = $new->get('id');
$newdir = $dataroot . self::get_file_directory($newid);
check_dir_exists($newdir);
if (!copy($oldfile, $newdir . '/' . $newid)) {
throw new SystemException('failed copying file artefact');
}
global $USER;
if ($new->get('owner') && $new->get('owner') == $USER->get('id')) {
$USER->quota_add($new->get('size'));
$USER->commit();
}
return;
}
}
class ArtefactTypeFolder extends ArtefactTypeFileBase {
......@@ -1004,33 +995,28 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase {
}
}
public static function get_folder_by_name($name, $parentfolderid=null, $userid=null) {
if (empty($userid)) {
global $USER;
$userid = $USER->id;
}
public static function get_folder_by_name($name, $parentfolderid=null, $userid=null, $groupid=null, $institution=null) {
$parentclause = $parentfolderid ? 'parent = ' . $parentfolderid : 'parent IS NULL';
$ownerclause = artefact_owner_sql($userid, $groupid, $institution);
return get_record_sql('SELECT * FROM {artefact}
WHERE title = ? AND ' . $parentclause . ' AND owner = ' . $userid . "
WHERE title = ? AND ' . $parentclause . ' AND ' . $ownerclause . "
AND artefacttype = 'folder'", array($name));
}
// Get the id of a folder, creating the folder if necessary
public static function get_folder_id($name, $description, $parentfolderid=null, $userid=null, $create=true) {
if (empty($userid)) {
global $USER;
$userid = $USER->id;
}
if (!$record = self::get_folder_by_name($name, $parentfolderid, $userid)) {
public static function get_folder_id($name, $description, $parentfolderid=null, $create=true, $userid=null, $groupid=null, $institution=null) {
if (!$record = self::get_folder_by_name($name, $parentfolderid, $userid, $groupid, $institution)) {
if (!$create) {
return false;
}
$data = new StdClass;
$data->title = $name;
$data->description = $description;
$data->owner = $userid;
$data->group = $groupid;
$data->institution = $institution;
$data->parent = $parentfolderid;
$f = new ArtefactTypeFolder(0, $data);
$f->set('owner', $userid);
$f->set('parent', $parentfolderid);
$f->commit();
return $f->get('id');
}
......
......@@ -5,6 +5,9 @@
{if $groupid}
<h2>{$heading}</h2>
{include file="group/tabstart.tpl" current="files"}
{elseif $institution}
<h2>{$heading}</h2>
{$institutionselector}
{/if}
{str tag='fileinstructions' section='artefact.file'}
<div id="myfiles">
......
......@@ -139,6 +139,15 @@ class PluginBlocktypeContactinfo extends PluginBlocktype {
public static function artefactchooser_get_sort_order() {
return '';
}
public static function copy_allowed($newowner=null) {
return $newowner['type'] == 'user';
}
public static function copy_artefacts_allowed($newowner=null) {
return false;
}
}
?>
......@@ -200,6 +200,15 @@ class PluginBlocktypeProfileinfo extends PluginBlocktype {
public static function artefactchooser_get_sort_order() {
return '';
}
public static function copy_allowed($newowner=null) {
return $newowner['type'] == 'user';
}
public static function copy_artefacts_allowed($newowner=null) {
return false;
}
}
?>
......@@ -147,7 +147,7 @@ abstract class ArtefactType {
if (in_array($field, array('atime', 'ctime', 'mtime'))) {
$value = strtotime($value);
}
if ($field == 'tags' && !is_array($field)) {
if ($field == 'tags' && !is_array($value)) {
$value = preg_split("/\s*,\s*/", trim($value));
}
$this->{$field} = $value;
......@@ -634,8 +634,58 @@ abstract class ArtefactType {
);
}
}
else {
$roles = group_get_role_info($this->get('group'));
foreach ($roles as $r) {
$this->rolepermissions->{$r->name} = (object) array('view' => true, 'edit' => true, 'republish' => true);
}
}
}
public function copy_data()