Commit bd192910 authored by Penny Leach's avatar Penny Leach
Browse files

Merge commit 'origin/master' into mahoodle-phase2

Conflicts:

	htdocs/lib/db/upgrade.php
	htdocs/lib/version.php
parents 83962714 a16c31e1
......@@ -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->assign('createviewform', pieform(create_view_form(null, 'mahara')));
$smarty->display('view/index.tpl');
?>
......@@ -78,7 +78,17 @@ $elements['quota'] = array(
'defaultvalue' => get_config_plugin('artefact', 'file', 'defaultquota'),
);
$authinstances = auth_get_auth_instances();
if ($USER->get('admin')) {
$authinstances = auth_get_auth_instances();
} else {
$admininstitutions = $USER->get('admininstitutions');
$authinstances = auth_get_auth_instances_for_institutions($admininstitutions);
if (empty($authinstances)) {
$SESSION->add_info_msg(get_string('configureauthplugin', 'admin'));
redirect(get_config('wwwroot').'admin/users/institutions.php?i='.key($admininstitutions).'&amp;edit=1');
}
}
if (count($authinstances) > 1) {
$options = array();
......@@ -204,43 +214,19 @@ function adduser_submit(Pieform $form, $values) {
}
$authinstance = get_record('auth_instance', 'id', $values['authinstance']);
$institution = new Institution($authinstance->institution);
db_begin();
$id = insert_record('usr', $user, 'id', true);
$user->id = $id;
$user->id = create_user($user, array(), $authinstance->institution, $authinstance, $values['remoteusername']);
if (isset($user->admin) && $user->admin) {
activity_add_admin_defaults(array($user->id));
}
if ($institution->name != 'mahara') {
$institution->addUserAsMember($user);
if ($values['institutionadmin']) {
set_field('usr_institution', 'admin', 1, 'usr', $user->id);
}
}
if ($authinstance->authname != 'internal') {
if (isset($values['remoteusername']) && strlen($values['remoteusername']) > 0) {
$un = $values['remoteusername'];
}
else {
$un = $user->username;
}
insert_record('auth_remote_user', (object) array(
'authinstance' => $authinstance->id,
'remoteusername' => $un,
'localusr' => $user->id,
));
if ($values['institutionadmin']) {
set_field('usr_institution', 'admin', 1, 'usr', $user->id, 'institution', $authinstance->institution);
}
// Set profile fields
foreach (array('firstname', 'lastname', 'email') as $field) {
set_profile_field($id, $field, $user->{$field});
}
handle_event('createuser', $user);
db_commit();
try {
......@@ -253,7 +239,7 @@ function adduser_submit(Pieform $form, $values) {
$SESSION->add_error_msg(get_string('newuseremailnotsent', 'admin'));
}
redirect('/admin/users/edit.php?id='.$id);
redirect('/admin/users/edit.php?id='.$user->id);
}
$smarty = smarty();
......
......@@ -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');
......
......@@ -74,7 +74,7 @@ if ($USER->get('admin')) {
$admininstitutions = $USER->get('admininstitutions');
$authinstances = auth_get_auth_instances_for_institutions($admininstitutions);
if (empty($authinstances)) {
$SESSION->add_info_msg(get_string('uploadcsvconfigureauthplugin', 'admin'));
$SESSION->add_info_msg(get_string('configureauthplugin', 'admin'));
redirect(get_config('wwwroot').'admin/users/institutions.php?i='.key($admininstitutions).'&amp;edit=1');
}
}
......@@ -301,6 +301,7 @@ function uploadcsv_submit(Pieform $form, $values) {
log_info('Inserting users from the CSV file');
db_begin();
$authobj = get_record('auth_instance', 'id', $authinstance);
$addedusers = array();
foreach ($CSVDATA as $record) {
log_debug('adding user ' . $record[$formatkeylookup['username']]);
......@@ -319,29 +320,17 @@ function uploadcsv_submit(Pieform $form, $values) {
$user->preferredname = $record[$formatkeylookup['preferredname']];
}
$user->passwordchange = (int)$values['forcepasswordchange'];
$id = insert_record('usr', $user, 'id', true);
$user->id = $id;
if ($institution->name != 'mahara') {
$institution->addUserAsMember($user);
}
if (get_field('auth_instance', 'authname', 'id', $authinstance) != 'internal') {
// Assume the admin knows what they're doing when they choose the external auth instance.
delete_records('auth_remote_user', 'authinstance', $authinstance, 'remoteusername', $user->username);
insert_record('auth_remote_user', (object) array(
'authinstance' => $authinstance,
'remoteusername' => $user->username,
'localusr' => $id,
));
}
$profilefields = new StdClass;
foreach ($FORMAT as $field) {
if ($field == 'username' || $field == 'password') {
continue;
}
set_profile_field($id, $field, $record[$formatkeylookup[$field]]);
$profilefields->{$field} = $record[$formatkeylookup[$field]];
}
handle_event('createuser', $user);
$user->id = create_user($user, $profilefields, $institution, $authobj);
if ($values['emailusers']) {
$addedusers[] = $user;
}
......
......@@ -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;
}
......
......@@ -124,27 +124,9 @@ class PluginBlocktypeFiledownload extends PluginBlocktype {
/**
* Optional method. If specified, allows the blocktype class to munge the
* artefactchooser element data before it's templated
*
* Note: same as the 'image' blocktype's version of this
*/
public static function artefactchooser_get_element_data($artefact) {
$artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id));
if ($artefact->artefacttype == 'profileicon') {
$artefact->hovertitle = $artefact->note;
if ($artefact->title) {
$artefact->hovertitle .= ': ' . $artefact->title;
}
}
else {
$artefact->hovertitle = $artefact->title;
if ($artefact->description) {
$artefact->hovertitle .= ': ' . $artefact->description;
}
}
$artefact->title = str_shorten($artefact->title, 20);
$artefact->description = ($artefact->artefacttype == 'profileicon') ? $artefact->title : $artefact->description;
return $artefact;
return ArtefactTypeFileBase::artefactchooser_get_file_data(&$artefact);
}
}
......
......@@ -103,21 +103,15 @@ class PluginBlocktypeFolder extends PluginBlocktype {
/**
* Optional method. If specified, allows the blocktype class to munge the
* artefactchooser element data before it's templated
*
* Note: this method is the same as the one for the 'filedownload' blocktype
*/
public static function artefactchooser_get_element_data($artefact) {
global $USER;
// Grab data about all folders this user has, so we can make full paths to them
static $folderdata = null;
if ($folderdata === null) {
$folderdata = get_records_select_assoc('artefact', "artefacttype='folder' AND owner = ?", array($USER->get('id')), '', 'id, title, parent');
}
$folderdata = ArtefactTypeFileBase::artefactchooser_folder_data(&$artefact);
$artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id));
$artefact->hovertitle = $artefact->description;
$artefact->description = self::get_full_folder_path($artefact->id, $folderdata);
$path = $artefact->parent ? ArtefactTypeFileBase::get_full_path($artefact->parent, $folderdata->data) : '';
$artefact->description = str_shorten($folderdata->ownername . $path . $artefact->title, 30);
return $artefact;
}
......@@ -126,24 +120,6 @@ class PluginBlocktypeFolder extends PluginBlocktype {
return 'parent, title';
}
/**
* Works out a full path to a folder, given an ID. Implemented this way so
* only one query is made.
*/
private static function get_full_folder_path($id, $folderdata) {
$path = '';
foreach ($folderdata as $folder) {
if ($folder->id == $id) {
$path = $folder->title;
while ($folder->parent !== null) {
$folder = $folderdata[$folder->parent];
$path = $folder->title . '/' . $path;
}
}
}
return $path;
}
}
?>
......@@ -124,27 +124,9 @@ class PluginBlocktypeImage extends PluginBlocktype {
/**
* Optional method. If specified, allows the blocktype class to munge the
* artefactchooser element data before it's templated
*
* Note: this method is the same as the one for the 'filedownload' blocktype
*/
public static function artefactchooser_get_element_data($artefact) {
$artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id));
if ($artefact->artefacttype == 'profileicon') {
$artefact->hovertitle = $artefact->note;
if ($artefact->title) {
$artefact->hovertitle .= ': ' . $artefact->title;
}
}
else {
$artefact->hovertitle = $artefact->title;
if ($artefact->description) {
$artefact->hovertitle .= ': ' . $artefact->description;
}
}
$artefact->title = str_shorten($artefact->title, 20);
$artefact->description = ($artefact->artefacttype == 'profileicon') ? $artefact->title : $artefact->description;
return $artefact;
return ArtefactTypeFileBase::artefactchooser_get_file_data(&$artefact);
}
}
......
......@@ -25,7 +25,7 @@
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups');
define('MENUITEM', 'groups/files');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(get_config('libroot') . 'group.php');
......@@ -33,11 +33,10 @@ safe_require('artefact', 'file');
$javascript = ArtefactTypeFileBase::get_my_files_js(param_integer('folder', null));
$groupid = param_integer('group');
if (!$group = get_record('group', 'id', $groupid, 'deleted', 0)) {
throw new GroupNotFoundException("Couldn't find group with id $groupid");
}
if (!group_user_access($groupid)) {
define('GROUP', param_integer('group'));
$group = group_current_group();
if (!group_user_access($group->id)) {
throw new AccessDeniedException();
}
define('TITLE', $group->name . ' - ' . get_string('groupfiles', 'artefact.file'));
......@@ -45,28 +44,17 @@ define('TITLE', $group->name . ' - ' . get_string('groupfiles', 'artefact.file')
require_once(get_config('docroot') . 'interaction/lib.php');
$groupdata = json_encode($group);
$grouproles = json_encode(array_values(group_get_role_info($groupid)));
$grouproles = json_encode(array_values(group_get_role_info($group->id)));
$javascript .= <<<GROUPJS
var group = {$groupdata};
group.roles = {$grouproles};
browser.setgroup({$groupid});
uploader.setgroup({$groupid});
browser.setgroup({$group->id});
uploader.setgroup({$group->id});
GROUPJS;
$smarty = smarty(
array('tablerenderer', 'artefact/file/js/file.js'),
array(),
array(),
array(
'sideblocks' => array(
interaction_sideblock($groupid),