Commit 3127523e authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge changes Ia63763f1,Ife693b3d

* changes:
  Bug 1797276: keyword 'groups' needs changed in sql queries
  Bug 1797276: escape admin reserved word in Mysql8
parents 26e19361 cd68ce01
......@@ -862,7 +862,7 @@ function siteoptions_submit(Pieform $form, $values) {
$fields = array_merge($fields, array('dropdownmenu'));
}
$count = 0;
$where_sql = " WHERE admin = 0 AND id != 0";
$where_sql = " WHERE \"admin\" = 0 AND id != 0";
// if default account lifetime expiry has no end date
if (empty($values['defaultaccountlifetime'])) {
if ($values['defaultaccountlifetimeupdate'] == 'all') {
......
......@@ -58,10 +58,10 @@ function adminusers_submit(Pieform $form, $values) {
db_begin();
execute_sql('UPDATE {usr}
SET admin = 0
WHERE admin = 1');
SET "admin" = 0
WHERE "admin" = 1');
execute_sql('UPDATE {usr}
SET admin = 1
SET "admin" = 1
WHERE id IN (' . join(',', array_map('intval', $values['users'])) . ')');
activity_add_admin_defaults($values['users']);
db_commit();
......
......@@ -307,8 +307,8 @@ function delete_validate(Pieform $form, $values) {
$form->set_error(null, get_string('unabletodeleteself1', 'admin'));
}
// Not allowed to remove all site admins
$siteadmins = count_records_sql("SELECT COUNT(admin) FROM {usr}
WHERE id NOT IN (" . join(',', array_map('db_quote', $users)) . ") AND admin = 1", array());
$siteadmins = count_records_sql("SELECT COUNT(\"admin\") FROM {usr}
WHERE id NOT IN (" . join(',', array_map('db_quote', $users)) . ") AND \"admin\" = 1", array());
if (!$siteadmins) {
$form->set_error(null, get_string('unabletodeletealladmins1', 'admin'));
}
......
......@@ -77,11 +77,11 @@ function adminusers_submit(Pieform $form, $values) {
db_begin();
execute_sql('UPDATE {usr_institution}
SET admin = 0
WHERE admin = 1 AND institution = ' . db_quote($inst));
SET "admin" = 0
WHERE "admin" = 1 AND institution = ' . db_quote($inst));
if ($values['users']) {
execute_sql('UPDATE {usr_institution}
SET admin = 1
SET "admin" = 1
WHERE usr IN (' . join(',', array_map('intval', $values['users'])) . ') AND institution = ' . db_quote($inst));
}
require_once('activity.php');
......
......@@ -446,7 +446,7 @@ function auth_setup () {
// out of the admin section
if (in_admin_section()) {
// Reload site admin/staff permissions
$realuser = get_record('usr', 'id', $USER->id, null, null, null, null, 'admin,staff');
$realuser = get_record('usr', 'id', $USER->id, null, null, null, null, '"admin",staff');
if (!$USER->get('admin') && $realuser->admin) {
// The user has been made into an admin
$USER->admin = 1;
......
......@@ -399,7 +399,7 @@ class PluginAuthSaml extends PluginAuth {
private static function create_certificates($numberofdays = 3650) {
global $CFG;
// Get the details of the first site admin and use it for setting up the certificate
$userid = get_record_sql('SELECT id FROM {usr} WHERE admin = 1 AND deleted = 0 ORDER BY id LIMIT 1', array());
$userid = get_record_sql('SELECT id FROM {usr} WHERE "admin" = 1 AND deleted = 0 ORDER BY id LIMIT 1', array());
$id = $userid->id;
$user = new User;
$user->find_by_id($id);
......
......@@ -85,18 +85,18 @@ function site_statistics($full=false) {
// Group graph
$smarty = smarty_core();
$smarty->assign('grouptypecounts', get_records_sql_array("
SELECT grouptype, COUNT(id) AS groups
SELECT grouptype, COUNT(id) AS groupcount
FROM {group}
WHERE deleted = 0
GROUP BY grouptype
ORDER BY groups DESC", array()
ORDER BY groupcount DESC", array()
));
$smarty->assign('jointypecounts', get_records_sql_array("
SELECT jointype, COUNT(id) AS groups
SELECT jointype, COUNT(id) AS groupcount
FROM {group}
WHERE deleted = 0
GROUP BY jointype
ORDER BY groups DESC", array()
ORDER BY groupcount DESC", array()
));
$smarty->assign('groupgraph', true);
$data['groupinfo'] = $smarty->fetch('admin/groupstatssummary.tpl');
......@@ -152,18 +152,18 @@ function site_statistics($full=false) {
$data['strmaxviews'] = get_string('statsnoviews', 'admin');
}
$maxgroups = get_records_sql_array("
SELECT u.id, u.firstname, u.lastname, u.preferredname, u.urlid, COUNT(m.group) AS groups
SELECT u.id, u.firstname, u.lastname, u.preferredname, u.urlid, COUNT(m.group) AS groupcount
FROM {usr} u JOIN {group_member} m ON u.id = m.member JOIN {group} g ON m.group = g.id
WHERE g.deleted = 0
GROUP BY u.id, u.firstname, u.lastname, u.preferredname, u.urlid
ORDER BY groups DESC
ORDER BY groupcount DESC
LIMIT 1", array());
$maxgroups = $maxgroups[0];
if ($maxgroups) {
$data['strmaxgroups'] = get_string(
'statsmaxgroups1',
'admin',
$maxgroups->groups,
$maxgroups->groupcount,
$data['groupmemberaverage'],
profile_url($maxgroups),
hsc(display_name($maxgroups, null, true))
......@@ -399,18 +399,18 @@ function institution_statistics($institution, $full=false) {
$data['strmaxviews'] = get_string('statsnoviews', 'admin');
}
$maxgroups = get_records_sql_array("
SELECT u.id, u.firstname, u.lastname, u.preferredname, u.urlid, COUNT(m.group) AS groups
SELECT u.id, u.firstname, u.lastname, u.preferredname, u.urlid, COUNT(m.group) AS groupcount
FROM {usr} u JOIN {group_member} m ON u.id = m.member JOIN {group} g ON m.group = g.id
WHERE g.deleted = 0 AND u.id IN (" . $data['memberssql'] . ")
GROUP BY u.id, u.firstname, u.lastname, u.preferredname, u.urlid
ORDER BY groups DESC
ORDER BY groupcount DESC
LIMIT 1", $data['memberssqlparams']);
$maxgroups = $maxgroups[0];
if ($maxgroups) {
$data['strmaxgroups'] = get_string(
'statsmaxgroups1',
'admin',
$maxgroups->groups,
$maxgroups->groupcount,
$data['groupmemberaverage'],
profile_url($maxgroups),
hsc(display_name($maxgroups, null, true))
......@@ -2372,11 +2372,11 @@ function group_stats_table($limit, $offset, $extra) {
function group_type_graph($type = false) {
$grouptypes = get_records_sql_array("
SELECT grouptype, jointype, COUNT(id) AS groups
SELECT grouptype, jointype, COUNT(id) AS groupcount
FROM {group}
WHERE deleted = 0
GROUP BY grouptype, jointype
ORDER BY groups DESC", array()
ORDER BY groupcount DESC", array()
);
if (count($grouptypes) > 1) {
......@@ -2384,7 +2384,7 @@ function group_type_graph($type = false) {
foreach ($grouptypes as &$t) {
$strtype = get_string('name', 'grouptype.' . $t->grouptype);
$strtype .= ' (' . get_string('membershiptype.abbrev.' . $t->jointype, 'group') . ')';
$dataarray[$strtype] = $t->groups;
$dataarray[$strtype] = $t->groupcount;
}
ksort($dataarray);
arsort($dataarray);
......
......@@ -42,7 +42,7 @@ $USER->reload_background_fields();
$installedtypes = get_records_assoc(
'activity_type', '', '',
'plugintype,pluginname,name',
'name,admin,plugintype,pluginname'
'name,"admin",plugintype,pluginname'
);
$options = array();
......
......@@ -31,7 +31,7 @@ $USER->reload_background_fields();
$installedtypes = get_records_assoc(
'activity_type', '', '',
'plugintype,pluginname,name',
'name,admin,plugintype,pluginname'
'name,"admin",plugintype,pluginname'
);
$options = array();
......
......@@ -5,7 +5,7 @@
<h4>{str tag=groupcountsbytype section=admin}</h4>
<ul class="list-group list-group-lite unstyled">
{foreach from=$grouptypecounts item=item}
<li class="list-group-item">{str tag=name section=grouptype.$item->grouptype}: {$item->groups}</li>
<li class="list-group-item">{str tag=name section=grouptype.$item->grouptype}: {$item->groupcount}</li>
{/foreach}
</ul>
</div>
......@@ -13,7 +13,7 @@
<h4>{str tag=groupcountsbyjointype section=admin}</h4>
<ul class="list-group list-group-lite unstyled">
{foreach from=$jointypecounts item=item}
<li class="list-group-item">{str tag=membershiptype.$item->jointype section=group}: {$item->groups}</li>
<li class="list-group-item">{str tag=membershiptype.$item->jointype section=group}: {$item->groupcount}</li>
{/foreach}
</ul>
</div>
......
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