Commit a392b8b4 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files
parents 9dd5b985 976d0c6f
......@@ -28,12 +28,11 @@ define('INTERNAL', 1);
define('PUBLIC', 1);
require('init.php');
require_once('pieforms/pieform.php');
$smarty = smarty();
$smarty->assign('page_content', get_site_page_content('about'));
$smarty->assign('site_menu', site_menu());
$smarty->assign('searchform', pieform(searchform()));
$smarty->assign('searchform', searchform());
$smarty->display('sitepage.tpl');
?>
......@@ -39,15 +39,15 @@ if ($stopmonitoring) {
db_begin();
try {
foreach ($_GET as $k => $v) {
if (preg_match('/^stopview\-(\d+)$/',$k,$m)) {
if (preg_match('/^stopviews\-(\d+)$/',$k,$m)) {
delete_records('usr_watchlist_view', 'usr', $userid, 'view', $m[1]);
$count++;
}
else if (preg_match('/^stopartefact\-(\d+)$/',$k,$m)) {
else if (preg_match('/^stopartefacts\-(\d+)$/',$k,$m)) {
delete_records('usr_watchlist_artefact', 'usr', $userid, 'artefact', $m[1]);
$count++;
}
else if (preg_match('/^stopcommunity\-(\d+)$/',$k,$m)) {
else if (preg_match('/^stopcommunities\-(\d+)$/',$k,$m)) {
delete_records('usr_watchlist_community', 'usr', $userid, 'community', $m[1]);
$count++;
}
......@@ -74,6 +74,9 @@ $offset = param_integer('offset', 0);
$userid = $USER->get('id');
$prefix = get_config('dbprefix');
$count = 0;
$records = array();
if ($type == 'views') {
$count = count_records('usr_watchlist_view', 'usr', $userid);
$sql = 'SELECT v.*, v.title AS name
......@@ -81,11 +84,7 @@ if ($type == 'views') {
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id
WHERE w.usr = ?
ORDER BY v.mtime DESC';
if ($records = get_records_sql_array($sql, array($userid), $offset, $limit)) {
foreach ($records as &$r) {
// @todo session expandey stuff
}
}
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
}
else if ($type == 'communities') {
$count = count_records('usr_watchlist_community', 'usr', $userid);
......@@ -96,6 +95,15 @@ else if ($type == 'communities') {
ORDER BY c.mtime DESC';
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
}
else if ($type == 'artefacts') {
$count = count_records('usr_watchlist_artefact', 'usr', $userid);
$sql = 'SELECT a.* , a.title AS name
FROM ' . $prefix . 'artefact a
JOIN ' . $prefix . 'usr_watchlist_artefact w ON w.artefact = a.id
WHERE w.usr = ?
ORDER BY a.mtime DESC';
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
}
if (empty($records)) {
$records = array();
......@@ -107,10 +115,6 @@ $activity = array(
'limit' => $limit,
'data' => $records,
'type' => $type,
'minusicon' => theme_get_image_path('minus.png'),
'plusicon' => theme_get_image_path('plus.png'),
'minusalt' => get_string('collapse'),
'plusalt' => get_string('expand'),
);
echo json_encode($activity);
......
......@@ -30,8 +30,9 @@ define('SUBMENUITEM', 'watchlist');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$viewstring = get_string('viewsandartefacts', 'activity');
$viewstring = get_string('views', 'activity');
$communitystring = get_string('communities', 'activity');
$artefactstring = get_string('artefacts', 'activity');
$monitoredstring = get_string('monitored', 'activity');
$savefailed = get_string('stopmonitoringfailed', 'activity');
......@@ -39,44 +40,19 @@ $savesuccess = get_string('stopmonitoringsuccess', 'activity');
$getartefactsjson = get_config('wwwroot') . 'json/getartefacts.php';
$minusicon = theme_get_image_path('minus.png');
$plusicon = theme_get_image_path('plus.png');
$minusalt = get_string('collapse');
$plusalt = get_string('expand');
$javascript = <<<JAVASCRIPT
var watchlist = new TableRenderer(
'watchlist',
'index.json.php',
[
function(r, d) {
if (r.type == 'community') {
return TD(null, '');
}
if (r.expanded) {
return TD(null, A({'href': '', 'onclick': 'toggleExpand(' + r.id + ', \'view\'); return false;'},
IMG({'src' : '{$minusicon}', 'alt' : '{$minusalt}',
'border': 0, 'id' : 'viewicon-' + r.id})));
}
else {
return TD(null, A({'href': '', 'onclick': 'toggleExpand(' + r.id + ', \'view\'); return false;'},
IMG({'src' : '{$plusicon}', 'alt' : '{$plusalt}',
'border': 0, 'id' : 'viewicon-' + r.id})));
}
},
function(r) {
if (r.url) {
return TD(null,A({'href': r.url}, r.title));
return TD(null,A({'href': r.url}, r.name));
}
return TD(null,r.title);
return TD(null, r.name);
},
function (r) {
if (r.type == 'community') {
return TD(null, INPUT({'type' : 'checkbox', 'class': 'tocheck', 'name': 'stopcommunity-' + r.id}));
}
else {
return TD(null, INPUT({'type' : 'checkbox', 'class': 'tocheck', 'name': 'stopview-' + r.id}));
}
function (r, d) {
return TD(null, INPUT({'type' : 'checkbox', 'class': 'tocheck', 'name': 'stop' + d.type + '-' + r.id}));
}
]
);
......@@ -89,88 +65,10 @@ watchlist.updateOnLoad();
watchlist.rowfunction = function(r, n) { return TR({'id': r.id, 'class': 'view'}); }
function changeTitle(title) {
var titles = { 'views' : '{$viewstring}', 'communities' : '{$communitystring}' };
var titles = { 'views': '{$viewstring}', 'communities': '{$communitystring}', 'artefacts': '{$artefactstring}' };
$('typeheader').innerHTML = '{$monitoredstring} ' + titles[title];
}
function toggleExpand(id, type) {
if ($(type + 'icon-' + id).src == '{$minusicon}') {
$(type + 'icon-' + id).src = '{$plusicon}';
$(type + 'icon-' + id).alt = '{$plusalt}';
removeElement($(type + 'expanded' + id));
return;
}
$(type + 'icon-' + id).src = '{$minusicon}';
$(type + 'icon-' + id).alt = '{$minusalt}';
// the first thing to do is find out if we have children
var url = '{$getartefactsjson}';
var tablename = type + 'table' + id;
var newtable = TABLE({'id': tablename});
var newrow = TR({'class': type, 'id': type + 'expanded' + id}, TD(), TD({'colspan': 2}, newtable));
var tr = $(type + 'icon-' + id).parentNode.parentNode.parentNode;
insertSiblingNodesAfter(tr, newrow);
var newtablelist = new TableRenderer(
tablename,
url,
[
function(r, d) {
if (r.expanded) {
return TD(null, A({'href': '',
'onclick': 'toggleExpand(' + r.id + ', \'artefact\'); return false;'},
IMG({'src' : '{$minusicon}', 'alt' : '{$minusalt}',
'border': 0, 'id' : 'artefacticon-' + r.id})));
}
else {
return TD(null, A({'href': '',
'onclick': 'toggleExpand(' + r.id + ', \'artefact\'); return false;'},
IMG({'src' : '{$plusicon}', 'alt' : '{$plusalt}',
'border': 0, 'id' : 'artefacticon-' + r.id})));
}
},
function(r) {
if (r.url) {
return TD(null,A({'href': r.url}, r.title));
}
return TD(null,r.title);
},
function (r) {
return TD(null, INPUT({'type' : 'checkbox', 'class': 'tocheck', 'name': 'stopartefact-' + r.id}));
}
]
);
newtablelist.statevars.push('view');
if (type == 'artefact') {
newtablelist.statevars.push('artefact');
newtablelist.artefact = id;
newtablelist.view = findViewId(tr);
}
else {
newtablelist.view = id;
}
newtablelist.watchlist = 1;
newtablelist.statevars.push('watchlist');
newtablelist.rowfunction = function(r, n) { return TR({'id': r.id, 'class': 'artefact'}); }
newtablelist.paginate = false;
newtablelist.doupdate();
}
function findViewId(row) {
child = row;
while (typeof(child.parentNode) != 'undefined' && child.parentNode != null) {
parent = child.parentNode;
if (hasElementClass(parent, 'view')) {
if (parent.id.search(/viewexpanded(\d+)/) != -1) {
return parent.id.replace(/viewexpanded/,'');
}
}
child = parent;
}
}
function stopmonitoring(form) {
var c = 'tocheck';
var e = getElementsByTagAndClassName(null,'tocheck',form);
......@@ -206,12 +104,12 @@ function stopmonitoring(form) {
JAVASCRIPT;
$typechange = 'watchlist.doupdate({\'type\':this.options[this.selectedIndex].value}); changeTitle(this.options[this.selectedIndex].value);';
$typechange = 'watchlist.doupdate({\'type\':this.options[this.selectedIndex].value}); changeTitle(this.options[this.selectedIndex].value); $(\'messagediv\').innerHTML = \'\';';
$smarty = smarty(array('tablerenderer'));
$smarty->assign('site_menu', site_menu());
$smarty->assign('typechange', $typechange);
$smarty->assign('typestr', get_string('viewsandartefacts', 'activity'));
$smarty->assign('typestr', get_string('views', 'activity'));
$smarty->assign('selectall', 'toggleChecked(\'tocheck\'); return false;');
$smarty->assign('stopmonitoring', 'stopmonitoring(this); return false;');
$smarty->assign('INLINEJAVASCRIPT', $javascript);
......
......@@ -33,12 +33,58 @@ $smarty = smarty();
$institution = param_variable('i', '');
$add = param_boolean('add');
$edit = param_boolean('edit');
$delete = param_boolean('delete');
if ($institution || $add) {
if ($delete) {
function delete_validate(Pieform $form, $values) {
if (get_field('usr', 'COUNT(*)', 'institution', $values['i'])) {
throw new Exception('Attempt to delete an institution that has members');
}
}
function delete_cancel_submit() {
redirect(get_config('wwwroot') . 'admin/institutions.php');
}
function delete_submit($values) {
global $SESSION;
db_begin();
delete_records('institution_locked_profile_field', 'name', $values['i']);
delete_records('institution', 'name', $values['i']);
db_commit();
$SESSION->add_ok_msg(get_string('institutiondeletedsuccessfully', 'admin'));
redirect(get_config('wwwroot') . 'admin/institutions.php');
}
$form = array(
'name' => 'delete',
'elements' => array(
'i' => array(
'type' => 'hidden',
'value' => $institution
),
'delete' => array(
'type' => 'hidden',
'value' => 1
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no'))
)
)
);
$smarty->assign('delete_form', pieform($form));
$smarty->display('admin/institutions.tpl');
exit;
}
if (!$add) {
$data = get_record('institution', 'name', $institution);
$lockedprofilefields = (array)get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
$lockedprofilefields = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
}
else {
$data = new StdClass;
......@@ -52,76 +98,74 @@ if ($institution || $add) {
}
safe_require('artefact', 'internal');
$elements = array();
if ($add) {
$elements['name'] = array(
$elements = array(
'name' => array(
'type' => 'text',
'title' => get_string('institutionname'),
'title' => get_string('institutionname', 'admin'),
'rules' => array(
'required' => true,
'maxlength' => 255,
'regex' => '/^[a-z]+$/'
),
'ignore' => !$add
),
'add' => array(
'type' => 'hidden',
'value' => true,
'ignore' => !$add
),
'i' => array(
'type' => 'hidden',
'value' => $institution,
'ignore' => $add
),
'displayname' => array(
'type' => 'text',
'title' => get_string('institutiondisplayname', 'admin'),
'defaultvalue' => $data->displayname,
'rules' => array(
'required' => true,
'maxlength' => 255
)
);
$elements['add'] = array(
'type' => 'hidden',
'value' => true
);
}
else {
$elements['i'] = array(
'type' => 'hidden',
'value' => $institution
);
}
$elements['displayname'] = array(
'type' => 'text',
'title' => get_string('institutiondisplayname'),
'defaultvalue' => $data->displayname,
'rules' => array(
'required' => true,
'maxlength' => 255
),
'authplugin' => array(
'type' => 'select',
'title' => get_string('authplugin', 'admin'),
'options' => get_records_menu('auth_installed', '', '', 'name', 'name, name')
),
'registerallowed' => array(
'type' => 'checkbox',
'title' => get_string('registrationallowed', 'admin'),
'description' => get_string('registrationalloweddescription', 'admin'),
'checked' => $data->registerallowed
),
'defaultaccountlifetime' => array(
'type' => 'expiry',
'title' => get_string('defaultaccountlifetime', 'admin'),
'description' => get_string('defaultaccountlifetimedescription', 'admin'),
'defaultvalue' => $data->defaultaccountlifetime
),
'defaultaccountinactiveexpire' => array(
'type' => 'expiry',
'title' => get_string('defaultaccountinactiveexpire', 'admin'),
'description' => get_string('defaultaccountinactiveexpiredescription', 'admin'),
'defaultvalue' => $data->defaultaccountinactiveexpire
),
'defaultaccountinactivewarn' => array(
'type' => 'expiry',
'title' => get_string('defaultaccountinactivewarn', 'admin'),
'description' => get_string('defaultaccountinactivewarndescription', 'admin'),
'defaultvalue' => $data->defaultaccountinactivewarn
),
'lockedfields' => array(
'value' => '<tr><th colspan="2">Locked fields</th></tr>'
)
);
$elements['authplugin'] = array(
'type' => 'select',
'title' => get_string('authplugin'),
'options' => get_records_menu('auth_installed', '', '', 'name', 'name, name')
);
$elements['registerallowed'] = array(
'type' => 'checkbox',
'title' => get_string('registrationallowed'),
'description' => get_string('registrationalloweddescription'),
'checked' => $data->registerallowed
);
$elements['defaultaccountlifetime'] = array(
'type' => 'expiry',
'title' => get_string('defaultaccountlifetime'),
'description' => get_string('defaultaccountlifetimedescription'),
'defaultvalue' => $data->defaultaccountlifetime
);
$elements['defaultaccountinactiveexpire'] = array(
'type' => 'expiry',
'title' => get_string('defaultaccountinactiveexpire'),
'description' => get_string('defaultaccountinactiveexpiredescription'),
'defaultvalue' => $data->defaultaccountinactiveexpire
);
$elements['defaultaccountinactivewarn'] = array(
'type' => 'expiry',
'title' => get_string('defaultaccountinactivewarn'),
'description' => get_string('defaultaccountinactivewarndescription'),
'defaultvalue' => $data->defaultaccountinactivewarn
);
$elements['lockedfields'] = array(
'value' => '<tr><th colspan="2">Locked fields</th></tr>'
);
foreach (ArtefactTypeProfile::get_all_fields() as $field => $type) {
$elements[$field] = array(
'type' => 'checkbox',
'title' => get_string($field),
'title' => get_string($field, 'artefact.internal'),
'checked' => in_array($field, $lockedprofilefields)
);
}
......@@ -138,7 +182,7 @@ if ($institution || $add) {
}
else {
// Get a list of institutions
$institutions = get_records_sql_array('SELECT i.name, i.displayname, i.authplugin, i.registerallowed, COUNT(u.*)
$institutions = get_records_sql_array('SELECT i.name, i.displayname, i.authplugin, i.registerallowed, COUNT(u.*) AS hasmembers
FROM institution i
LEFT OUTER JOIN usr u ON (u.institution = i.name)
GROUP BY 1, 2, 3, 4
......@@ -185,7 +229,8 @@ function institution_submit($values) {
}
db_commit();
$SESSION->add_ok_msg(get_string('institutionupdatedsuccessfully'));
$message = ($add) ? 'institutionaddedsuccessfully' : 'institutionupdatedsuccessfully';
$SESSION->add_ok_msg(get_string($message, 'admin'));
redirect(get_config('wwwroot') . 'admin/institutions.php');
}
......
......@@ -62,6 +62,7 @@ $string['occupation'] = 'Occupation';
$string['industry'] = 'Industry';
// Field names for view user and search user display
$string['profile'] = 'Profile';
$string['name'] = 'Name';
$string['principalemailaddress'] = 'Principal email';
$string['emailaddress'] = 'Alternative email';
......
......@@ -255,23 +255,25 @@ class ArtefactTypeProfile extends ArtefactType {
'type' => 'html',
'value' => '&nbsp;',
);
$currentwidth = get_config_plugin('artefact', 'internal', 'profileiconwidth');
$form['elements']['profileiconwidth'] = array(
'type' => 'text',
'size' => 4,
'suffix' => get_string('widthshort'),
'title' => get_string('profileiconsize', 'artefact.internal'),
'defaultvalue' => get_config_plugin('artefact', 'internal', 'profileiconwidth'),
'defaultvalue' => ((!empty($currentwidth)) ? $currentwidth : 100),
'rules' => array(
'required' => true,
'integer' => true,
)
);
$currentheight = get_config_plugin('artefact', 'internal', 'profileiconheight');
$form['elements']['profileiconheight'] = array(
'type' => 'text',
'suffix' => get_string('heightshort'),
'size' => 4,
'title' => get_string('profileiconsize', 'artefact.internal'),
'defaultvalue' => get_config_plugin('artefact', 'internal', 'profileiconheight'),
'defaultvalue' => ((!empty($currentheight)) ? $currentheight : 100),
'rules' => array(
'required' => true,
'integer' => true,
......
......@@ -28,7 +28,7 @@ define('INTERNAL', 1);
define('PUBLIC', 1);
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('pieform.php');
require_once('pieforms/pieform.php');
safe_require('artefact', 'internal');
$email = param_variable('email');
......
......@@ -30,9 +30,9 @@ define('PUBLIC', 1);
require('init.php');
require_once('pieforms/pieform.php');
if ($SESSION->is_logged_in()) {
$name = display_name($USER);
$email = $USER->email;
if ($USER->is_logged_in()) {
$name = display_name($USER->get('id'));
$email = $USER->get('email');
}
else {
$name = '';
......@@ -118,7 +118,7 @@ function contactus_submit($values) {
$smarty = smarty();
$smarty->assign('page_content', $contactform);
$smarty->assign('site_menu', site_menu());
$smarty->assign('searchform', pieform(searchform()));
$smarty->assign('searchform', searchform());
$smarty->display('sitepage.tpl');
?>
......@@ -29,11 +29,11 @@ define('PUBLIC', 1);
define('MENUITEM', 'home');
require('init.php');
require_once('pieforms/pieform.php');
// Check for whether the user is logged in, before processing the page. After
// this, we can guarantee whether the user is logged in or not for this page.
if (!$USER->is_logged_in()) {
require_once('pieforms/pieform.php');
$institutions = get_records_menu('institution', '', '', 'name, displayname');
$loginform = get_login_form_js(pieform(array(
'name' => 'login',
......@@ -97,7 +97,7 @@ if (!$USER->is_logged_in()) {
$smarty->assign('login_form', $loginform);
}
else {
$smarty->assign('searchform', pieform(searchform()));
$smarty->assign('searchform', searchform());
}
$smarty->assign('page_content', get_site_page_content($pagename));
$smarty->assign('site_menu', site_menu());
......
......@@ -105,7 +105,7 @@ try {
else { // Use single connection
$dbconnected = $db->Connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
}
$db->SetFetchMode(ADODB_FETCH_ASSOC);
configure_dbconnection();
ensure_internal_plugins_exist();
......@@ -114,11 +114,10 @@ try {
}
catch (Exception $e) {
$errormessage = ob_get_contents();
if (!$errormessage) {
$errormessage = $e->getMessage();
}
ob_end_clean();
// @todo <nigel|penny>: At this point the raw error message can be munged from
// $errormessage, while the $e object holds some other information (like backtrace,
// which can be parsed with adodb_backtrace($e->gettrace());). At this point a
// nice message should be displayed explaining the problem etc. etc.
throw new Exception($errormessage);
}
try {
......
......@@ -53,6 +53,8 @@ $string['failedtomarkasread'] = 'Failed to mark your notifications as read';
$string['stopmonitoring'] = 'Stop monitoring';
$string['viewsandartefacts'] = 'Views and artefacts';
$string['views'] = 'Views';
$string['artefacts'] = 'Artefacts';
$string['communities'] = 'Communities';
$string['monitored'] = 'Monitored';
$string['stopmonitoring'] = 'Stop monitoring';
......
......@@ -26,13 +26,6 @@
defined('INTERNAL') || die();
$string['adminoptionsauthenticationtitle'] = 'AdminOptionsAuthentication';
$string['adminoptionsauthenticationdescription'] = '<p>List of installed authentication methods. Internal is used by default, if an
institution uses another authentication type then they will be listed beside it.</p>
<p>Did you want to <a href="institution.php">change the type of authentication for an institution</a>?</p>';
$string['authnoconfigurationoptions'] = 'No configuration options are available for this authentication type';
// Installer
$string['release'] = 'Release %s (%s)';
$string['component'] = 'Component or plugin';
......@@ -56,6 +49,7 @@ $string['siteoptions'] = 'Site options';
$string['institutions'] = 'Institutions';
$string['pageeditor'] = 'Site pages';
$string['menueditor'] = 'Site menu';
$string['adminplugins'] = 'Administer Plugins';
$string['files'] = 'Files';
$string['adminhome'] = 'Admin home';
......@@ -153,7 +147,23 @@ $string['adminnotifications'] = 'Admin Notifications';
// Suspended Users
$string['suspendedusers'] = 'Suspended Users';