Commit db640f93 authored by Donal McMullan's avatar Donal McMullan
Browse files
parents 9ac3b1e0 23a1b3d7
......@@ -34,26 +34,37 @@ define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'plugins');
require('upgrade.php');
// @TODO when artefact plugins get installed, move the not installed blocktypes
// that get installed into the list of installed blocktype plugins
$plugins = array();
$plugins['blocktype'] = array();
foreach (plugin_types() as $plugin) {
// this has to happen first because of broken artefact/blocktype ordering
$plugins[$plugin] = array();
$plugins[$plugin]['installed'] = array();
$plugins[$plugin]['notinstalled'] = array();
}
foreach (array_keys($plugins) as $plugin) {
if ($installed = get_records_array($plugin . '_installed')) {
foreach ($installed as $i) {
$plugins[$plugin]['installed'][$i->name] = array();
$key = $i->name;
if ($plugin == 'blocktype') {
$key = blocktype_single_to_namespaced($i->name, $i->artefactplugin);
}
$plugins[$plugin]['installed'][$key] = array();
if ($plugin == 'artefact') {
$plugins[$plugin]['installed'][$i->name]['types'] = array();
safe_require('artefact',$i->name);
$plugins[$plugin]['installed'][$key]['types'] = array();
safe_require('artefact', $key);
if ($types = call_static_method(generate_class_name('artefact', $i->name), 'get_artefact_types')) {
foreach ($types as $t) {
$classname = generate_artefact_class_name($t);
if ($collapseto = call_static_method($classname, 'collapse_config')) {
$plugins[$plugin]['installed'][$i->name]['types'][$collapseto] = true;
$plugins[$plugin]['installed'][$key]['types'][$collapseto] = true;
}
else {
$plugins[$plugin]['installed'][$i->name]['types'][$t] =
$plugins[$plugin]['installed'][$key]['types'][$t] =
call_static_method($classname, 'has_config');
}
}
......@@ -63,7 +74,7 @@ foreach (plugin_types() as $plugin) {
$classname = generate_class_name($plugin, $i->name);
safe_require($plugin, $i->name);
if (call_static_method($classname, 'has_config')) {
$plugins[$plugin]['installed'][$i->name]['config'] = true;
$plugins[$plugin]['installed'][$key]['config'] = true;
}
}
}
......@@ -71,6 +82,7 @@ foreach (plugin_types() as $plugin) {
$dirhandle = opendir(get_config('docroot') . $plugin);
while (false !== ($dir = readdir($dirhandle))) {
$installed = false; // reinitialise
if (strpos($dir, '.') === 0) {
continue;
}
......@@ -78,19 +90,51 @@ foreach (plugin_types() as $plugin) {
continue;
}
if (array_key_exists($dir, $plugins[$plugin]['installed'])) {
$installed = true;
}
// if we're already installed keep going
// if we're an artefact plugin, we have to check for blocktypes.
if ($plugin != 'artefact' && !empty($installed)) {
continue;
}
$plugins[$plugin]['notinstalled'][$dir] = array();
require_once('artefact.php');
$funname = $plugin . '_check_plugin_sanity';
if (function_exists($funname)) {
if (empty($installed)) {
$plugins[$plugin]['notinstalled'][$dir] = array();
try {
$funname($dir);
validate_plugin($plugin, $dir);
}
catch (InstallationException $e) {
$plugins[$plugin]['notinstalled'][$dir]['notinstallable'] = $e->GetMessage();
}
}
if ($plugin == 'artefact') { // go check it for blocks as well
$btlocation = get_config('docroot') . $plugin . '/' . $dir . '/blocktype';
if (!is_dir($btlocation)) {
continue;
}
$btdirhandle = opendir($btlocation);
while (false !== ($btdir = readdir($btdirhandle))) {
if (strpos($btdir, '.') === 0) {
continue;
}
if (!is_dir(get_config('docroot') . $plugin . '/' . $dir . '/blocktype/' . $btdir)) {
continue;
}
if (!array_key_exists($dir . '/' . $btdir, $plugins['blocktype']['installed'])) {
try {
if (!array_key_exists($dir, $plugins['artefact']['installed'])) {
throw new InstallationException(get_string('blocktypeprovidedbyartefactnotinstallable', 'error', $dir));
}
validate_plugin('blocktype', $dir . '/' . $btdir,
get_config('docroot') . 'artefact/' . $dir . '/blocktype/' . $btdir);
$plugins['blocktype']['notinstalled'][$dir . '/' . $btdir] = array();
}
catch (InstallationException $_e) {
$plugins['blocktype']['notinstalled'][$dir . '/' . $btdir]['notinstallable'] = $_e->getMessage();
}
}
}
}
}
}
......
<?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 Penny Leach <penny@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('ADMIN', 1);
define('MENUITEM', 'configextensions/templatesadmin');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('templatesadmin', 'admin'));
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'templates');
require_once(get_config('libroot') . 'template.php');
$installedtemplates = get_column('template', 'name');
$alltemplates = array();
$templates = get_dir_contents(get_config('dataroot') . 'templates/');
foreach ($templates as $dir) {
$alltemplates[$dir] = array();
}
$templates = get_dir_contents(get_config('libroot') . 'templates/');
foreach ($templates as $dir) {
if (!array_key_exists($dir,$templates)) {
$alltemplates[$dir] = array();
}
}
foreach (array_keys($alltemplates) as $t) {
try {
$alltemplates[$t]['template'] = template_parse($t);
}
catch (TemplateParserException $e) {
$alltemplates[$t]['error'] = $e->getMessage();
}
if (in_array($t, $installedtemplates)) {
$alltemplates[$t]['installed'] = true;
}
}
$loadingicon = theme_get_url('images/loading.gif');
$successicon = theme_get_url('images/success.gif');
$failureicon = theme_get_url('images/failure.gif');
$loadingstring = json_encode(get_string('upgradeloading', 'admin'));
$successstring = json_encode(get_string('upgradesuccess', 'admin'));
$failurestring = json_encode(get_string('upgradefailure', 'admin'));
$javascript = <<<JAVASCRIPT
function installtemplate(name) {
$(name + '.message').innerHTML = '<img src="{$loadingicon}" alt="' + {$loadingstring} + '" />';
sendjsonrequest('templateinstall.json.php', { 'name': name }, 'GET', function (data) {
if (!data.error) {
var message = {$successstring};
$(name + '.message').innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message;
// move the whole thing into the list of installed plugins
// new parent node
$(name + '.status').src = '$successicon';
}
else {
var message = '';
if (data.message) {
message = data.message;
}
else {
message = {$failurestring};
}
$(name + '.message').innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
}
},
function () {
message = {$failurestring};
$(name).innerHTML = message;
},
true);
}
JAVASCRIPT;
$smarty = smarty();
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('templates', $alltemplates);
$smarty->assign('installlink', 'installtemplate');
$smarty->display('admin/extensions/templates.tpl');
?>
......@@ -42,7 +42,7 @@ foreach ($sitepages as $page) {
}
asort($pageoptions);
$getstring = array('discardpageedits' => "'" . get_string('discardpageedits','admin') . "'");
$getstring = array('discardpageedits' => json_encode(get_string('discardpageedits','admin')));
$f = array(
'name' => 'editsitepage',
......
......@@ -32,9 +32,9 @@ define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require(get_config('libroot') . 'upgrade.php');
$install = param_boolean('install');
$name = param_variable('name');
$install = ($name == 'firstcoredata' || $name == 'lastcoredata');
if (!$install) {
$name = param_variable('name');
$upgrade = check_upgrades($name);
if (empty($upgrade->disablelogin)) {
......@@ -42,32 +42,23 @@ if (!$install) {
}
}
$data = array(
'key' => $name
);
if ($install) {
$message = '';
if (!get_config('installed')) {
try {
$exceptions = core_install_defaults();
$fun = 'core_install_' . $name . '_defaults';
$fun();
}
catch (SQLException $e) {
json_reply('local', $e->getMessage());
}
catch (TemplateParserException $e) {
$message = '<a href="' . get_config('wwwroot') .'admin/extensions/templates.php">'
. get_string('fixtemplatescontinue', 'admin') . '</a>';
}
if (is_array($exceptions) && count($exceptions) > 0) {
// these ones are non fatal...
$message = '<a href="' . get_config('wwwroot') .'admin/extensions/templates.php">'
. get_string('fixtemplatescontinue', 'admin') . '</a>';
json_reply('local', array('error' => true, 'key' => $name, 'errormessage' => $e->getMessage()));
}
}
json_reply(false, $message);
$data['coredata'] = true;
json_reply(false, $data);
}
$data = array(
'key' => $name
);
if (!empty($upgrade)) {
$data['newversion'] = $upgrade->torelease . ' (' . $upgrade->to . ')' ;
if ($name == 'core') {
......@@ -95,7 +86,7 @@ if (!empty($upgrade)) {
}
else {
json_reply(false, array('error' => false,
'message' => string('nothingtoupgrade','admin')));
'message' => get_string('nothingtoupgrade','admin')));
exit;
}
?>
......@@ -43,7 +43,6 @@ if (!$upgrades) {
die_info(get_string('noupgrades', 'admin'));
}
$js = 'var todo = ' . json_encode(array_keys($upgrades)) . ";\n";
$loadingicon = theme_get_url('images/loading.gif');
$successicon = theme_get_url('images/success.gif');
$failureicon = theme_get_url('images/failure.gif');
......@@ -57,53 +56,18 @@ $coresuccess = json_encode(get_string('coredatasuccess', 'admin'));
// Check if Mahara is being installed. An extra hook is required to insert core
// data if so.
if (!empty($upgrades['core']->install)) {
$upgrades['firstcoredata'] = true;
$upgrades['lastcoredata'] = true;
$smarty->assign('install', true);
$installjs =<<< EOJS
$('coredata').innerHTML = '<img src="{$loadingicon}" alt="' + {$loadingstring} + '" />';
sendjsonrequest(
'upgrade.json.php',
{ 'install' : 1 },
'GET',
function (data) {
if ( !data.error ) {
var message = {$coresuccess};
if (data.message) {
message += ' (' + data.message + ')';
}
$('coredata').innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message;
$('finished').style.visibility = 'visible';
}
else {
var message = '';
if (data.message) {
message = data.message;
}
else {
message = {$failurestring};
}
$('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
}
},
function () {
$('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + {$failurestring};
},
true); // quiet.
}
EOJS;
}
else {
$installjs = '';
}
$js .= <<< EOJS
$js = <<< EOJS
function processNext() {
var element = todo.shift();
if ( ! element ) {
// we're done
$installjs
return;
if (!element) {
$('finished').style.visibility = 'visible';
return; // done
}
$(element).innerHTML = '<img src="{$loadingicon}" alt="' + {$loadingstring} + '" />';
......@@ -111,14 +75,20 @@ $js .= <<< EOJS
sendjsonrequest('upgrade.json.php', { 'name': element }, 'GET', function (data) {
if ( !data.error ) {
var message;
if (data.install) {
message = {$installsuccessstring};
}
if (data.coredata) {
message = {$coresuccess};
}
else {
message = {$successstring};
if (data.install) {
message = {$installsuccessstring};
}
else {
message = {$successstring};
}
message += data.newversion;
}
message += data.newversion;
$(data.key).innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message;
processNext();
}
else {
var message = '';
......@@ -130,7 +100,6 @@ $js .= <<< EOJS
}
$(data.key).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
}
processNext();
},
function () {
$(element).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + {$failurestring};
......@@ -141,6 +110,8 @@ $js .= <<< EOJS
addLoadEvent( processNext );
EOJS;
uksort($upgrades, 'sort_upgrades');
$js .= "\n" . 'var todo = ' . json_encode(array_keys($upgrades)) . ";\n";
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign_by_ref('upgrades', $upgrades);
......@@ -149,4 +120,6 @@ if (isset($upgrades['core'])) {
}
$smarty->display('admin/upgrade.tpl');
?>
......@@ -49,6 +49,7 @@ if ($institution || $add) {
if ($delete) {
function delete_validate(Pieform $form, $values) {
if (get_field('usr', 'COUNT(*)', 'institution', $values['i'])) {
// TODO: exception is of the wrong type
throw new Exception('Attempt to delete an institution that has members');
}
}
......@@ -107,7 +108,7 @@ if ($institution || $add) {
$instancestring = implode(',',$instancearray);
$inuserecords = array();
$records = get_records_sql_assoc('select authinstance, count(id) from {usr} where authinstance in ('.$instancestring.') group by authinstance');
$records = get_records_sql_assoc('select authinstance, count(id) from {usr} where authinstance in ('.$instancestring.') group by authinstance', array());
foreach ($records as $record) {
$inuserecords[] = $record->authinstance;
}
......@@ -264,16 +265,19 @@ function institution_submit(Pieform $form, $values) {
$allinstances = array_merge($values['authplugin']['instancearray'], $values['authplugin']['deletearray']);
if (array_diff($allinstances, $instancearray)) {
// TODO wrong exception type
throw new Exception('Attempt to delete or update another institution\'s auth instance');
}
if (array_diff($instancearray, $allinstances)) {
// TODO wrong exception type
throw new Exception('One of your instances is unaccounted for in this transaction');
}
foreach($values['authplugin']['instancearray'] as $priority => $instanceid) {
if (in_array($instanceid, $values['authplugin']['deletearray'])) {
// Should never happen:
// TODO wrong exception type
throw new Exception('Attempt to update AND delete an auth instance');
}
$record = new StdClass;
......
......@@ -47,20 +47,22 @@ if ($action == 'suspend') {
if ($action == 'search') {
require('searchlib.php');
try {
$query = param_variable('query');
}
catch (ParameterException $e) {
json_reply('missingparameter','Missing parameter \'query\'');
}
$limit = param_integer('limit', 20);
$offset = param_integer('offset', 0);
$data = search_user($query, $limit, $offset);
$params = new StdClass;
$params->query = trim(param_variable('query', ''));
$params->institution = param_alpha('institution', null);
$params->f = param_alpha('f', null);
$params->l = param_alpha('l', null);
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
$sortby = param_alpha('sortby', 'firstname');
$sortdir = param_alpha('sortdir', 'asc');
json_headers();
$data['data'] = build_admin_user_search_results($params, $offset, $limit, $sortby, $sortdir);
$data['error'] = false;
$data['message'] = '';
$data['message'] = null;
echo json_encode($data);
exit;
}
......
......@@ -32,117 +32,25 @@ define('TITLE', get_string('usersearch', 'admin'));
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'usersearch');
require('searchlib.php');
$query = param_variable('query',null);
if (isset($query) && trim($query) == '') {
$query = null;
}
$wwwroot = get_config('wwwroot');
$str_profileimage = json_encode(get_string('profileimage'));
$str_institution = json_encode(get_string('institution'));
$str_suspenduser = json_encode(get_string('suspenduser', 'admin'));
$str_suspensionreason = json_encode(get_string('suspensionreason', 'admin'));
$str_errorwhilesuspending = json_encode(get_string('errorwhilesuspending', 'admin'));
$str_noresults = json_encode(get_string('noresultsfound'));
$str_cancel = json_encode(get_string('cancel'));
$str_sesskey = json_encode($USER->get('sesskey'));
$javascript = <<<EOF
var results = new TableRenderer(
'searchresults',
'search.json.php',
[
function(r) { return TD(null,IMG({'src': '{$wwwroot}thumb.php?type=profileicon&size=40x40&id=' + r.id, 'alt': {$str_profileimage}})); },
function(r) {
return TD({'style': 'vertical-align: top'},
A({'href': '{$wwwroot}user/view.php?id=' + r.id}, r.name),
BR(),
STRONG(null, {$str_institution} + ': '),
SPAN(null, r.institution)
);
},
function(r) {
return TD({'style': 'vertical-align: top'},
A({'href': '', 'onclick': 'suspendDisplay(this); return false;'}, $str_suspenduser),BR()
// A({'href': ''}, 'some other action'),BR()
);
}
]
$search = (object) array(
'query' => trim(param_variable('query', '')),
'institution' => param_alpha('institution', 'all'),
'f' => param_alpha('f', null), // first initial
'l' => param_alpha('l', null), // last initial
);
results.rowfunction = function(r) { var row = TR(); row.data = r; return row; };
results.statevars.push('query');
results.statevars.push('action');
results.statevars.push('sesskey');
results.action = 'search';
results.sesskey = {$str_sesskey};
results.emptycontent = {$str_noresults};
results.query = '';
results.updateOnLoad();
function doSearch() {
results.query = $('usersearch').value;
results.offset = 0;
results.doupdate();
}
addLoadEvent(function() {
$('usersearch').focus();
connect('usersearch', 'onkeypress', function (k) {
if (k.key().code == 13) {
doSearch();
}
});
});
function suspendDisplay(ref) {
ref = ref.parentNode.parentNode; // get the TR
var reason = INPUT({'type': 'text'});
var cancelButton = BUTTON({'type': 'button'}, {$str_cancel});
var saveButton = BUTTON({'type': 'button'}, {$str_suspenduser});
insertSiblingNodesAfter(ref, TR(null, TD({'colSpan': 3},
{$str_suspensionreason} + ': ',
reason,
cancelButton,
saveButton
)));
reason.focus();
connect(reason, 'onkeypress', function (k) {
if (k.key().code == 13) {
suspendSave(reason);
}
if (k.key().code == 27) {
suspendCancel(reason);
}
});
connect(cancelButton, 'onclick', partial(suspendCancel, reason));
connect(saveButton, 'onclick', partial(suspendSave, reason));
}
function suspendSave(reason) {
var susReason = reason.value;
var data = reason.parentNode.parentNode.previousSibling.data;
removeElement(reason.parentNode.parentNode);
sendjsonrequest('search.json.php', {'action': 'suspend', 'reason': susReason, 'id': data.id}, 'GET',
function(response) {
results.doupdate();
});
}
function suspendCancel(reason) {
removeElement(reason.parentNode.parentNode);
}
EOF;
$sortby = param_alpha('sortby', 'firstname');
$sortdir = param_alpha('sortdir', 'asc');