Skip to content

Commit 7ccae44

Browse files
committed
Change roster to use "with selected" dropdown; add unlock
1 parent d9a4190 commit 7ccae44

File tree

3 files changed

+63
-24
lines changed

3 files changed

+63
-24
lines changed

course/gradebook.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@
191191
require_once "lockstu.php";
192192
require_once "../footer.php";
193193
exit;
194-
}
194+
} elseif (isset($_POST['posted']) && $_POST['posted']=="Unlock") {
195+
$calledfrom='gb';
196+
require_once('lockstu.php');
197+
exit;
198+
}
195199
if (isset($_POST['posted']) && $_POST['posted']=='Print Report') {
196200
//based on a contribution by Cam Joyce
197201
require_once "gbtable2.php";
@@ -581,7 +585,9 @@ function showfb(id,type,uid) {
581585
echo ' <li><a href="#" onclick="postGBform(\'Make Exception\');return false;" title="',_("Make due date exceptions for selected students"),'">',_('Make Exception'), "</a></li>";
582586
echo ' <li><a href="#" onclick="postGBform(\'Print Report\');return false;" title="',_("Generate printable grade reports"),'">', _('Print Report'), "</a></li>";
583587
echo ' <li><a href="#" onclick="postGBform(\'Lock\');return false;" title="',_("Lock selected students out of the course"),'">', _('Lock'), "</a></li>";
588+
echo ' <li><a href="#" onclick="postGBform(\'Unlock\');return false;" title="',_("Un-Lock selected students from the course"),'">', _('Un-Lock'), "</a></li>";
584589
if (!isset($CFG['GEN']['noInstrUnenroll'])) {
590+
echo '<li role="separator" class="divider"></li>';
585591
echo ' <li><a href="#" onclick="postGBform(\'Unenroll\');return false;" title="',_("Unenroll the selected students"),'">', _('Unenroll'), "</a></li>";
586592
}
587593

course/listusers.php

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
$body = "You need to log in as a teacher to access this page";
5454
} else { // PERMISSIONS ARE OK, PROCEED WITH PROCESSING
5555

56-
if (isset($_POST['submit']) && $_POST['submit']=="Unenroll") {
56+
if (isset($_POST['posted']) && $_POST['posted']=="Unenroll") {
5757
$_GET['action'] = "unenroll";
5858
}
59-
if (isset($_POST['submit']) && $_POST['submit']=="Lock") {
59+
if (isset($_POST['posted']) && $_POST['posted']=="Lock") {
6060
$_GET['action'] = "lock";
6161
}
6262
if (isset($_POST['lockinstead'])) {
@@ -192,7 +192,7 @@
192192
exit;
193193
}
194194
}
195-
} elseif (isset($_POST['submit']) && $_POST['submit']=="Copy Emails") {
195+
} elseif (isset($_POST['posted']) && $_POST['posted']=="Copy Emails") {
196196
$curBreadcrumb .= " <a href=\"listusers.php?cid=$cid\">Roster</a> &gt; Copy Emails\n";
197197
$pagetitle = "Copy Student Emails";
198198
if (!empty($_POST['checked'])) {
@@ -382,11 +382,11 @@
382382

383383
}
384384

385-
} elseif ((isset($_POST['submit']) && ($_POST['submit']=="E-mail" || $_POST['submit']=="Message"))|| isset($_GET['masssend'])) {
385+
} elseif ((isset($_POST['posted']) && ($_POST['posted']=="E-mail" || $_POST['posted']=="Message"))|| isset($_GET['masssend'])) {
386386
$calledfrom='lu';
387387
$overwriteBody = 1;
388388
$fileToInclude = "masssend.php";
389-
} elseif ((isset($_POST['submit']) && $_POST['submit']=="Make Exception") || isset($_GET['massexception'])) {
389+
} elseif ((isset($_POST['posted']) && $_POST['posted']=="Make Exception") || isset($_GET['massexception'])) {
390390
$calledfrom='lu';
391391
$overwriteBody = 1;
392392
$fileToInclude = "massexception.php";
@@ -404,6 +404,10 @@
404404
$overwriteBody = 1;
405405
$fileToInclude = "lockstu.php";
406406

407+
} elseif (isset($_POST['posted']) && $_POST['posted']=="Unlock") {
408+
$calledfrom='lu';
409+
require_once('lockstu.php');
410+
exit;
407411
} elseif (isset($_POST['action']) && $_POST['action']=="lockone" && is_numeric($_POST['uid'])) {
408412
$now = time();
409413
$stm = $DBH->prepare("UPDATE imas_students SET locked=:locked WHERE courseid=:courseid AND userid=:userid");
@@ -534,6 +538,16 @@ function postRosterForm(uid,action) {
534538
.append($("<input>", {name:"uid", value:uid, type:"hidden"}))
535539
.appendTo("body").submit();
536540
}
541+
function postWithSelform(val) {
542+
$("#qform").append($("<input>", {name:"posted", value:val, type:"hidden"})).submit();
543+
}
544+
function copyemails() {
545+
var ids = [];
546+
$("#myTable input:checkbox:checked").each(function(i) {
547+
ids.push(this.value);
548+
});
549+
GB_show("Emails","viewemails.php?cid="+cid+"&ids="+ids.join("-"),500,500);
550+
}
537551
</script>';
538552

539553
require_once "../header.php";
@@ -617,7 +631,7 @@ function postRosterForm(uid,action) {
617631
<?php
618632
require_once "../includes/newusercommon.php";
619633
showNewUserValidation("pageform");
620-
} elseif (isset($_POST['submit']) && $_POST['submit']=="Copy Emails") {
634+
} elseif (isset($_POST['posted']) && $_POST['posted']=="Copy Emails") {
621635
if (empty($_POST['checked'])) {
622636
echo "No student selected. <a href=\"listusers.php?cid=$cid\">Try again</a>";
623637
} else {
@@ -767,24 +781,29 @@ function chgrmode() {
767781
echo '</p>';
768782
?>
769783
<form id="qform" method=post action="listusers.php?cid=<?php echo $cid ?>">
770-
<p>Check: <a href="#" onclick="return chkAllNone('qform','checked[]',true)">All</a> <a href="#" onclick="return chkAllNone('qform','checked[]',true,'locked')">Non-locked</a> <a href="#" onclick="return chkAllNone('qform','checked[]',false)">None</a>
771-
With Selected:
772-
<?php
773-
if (!isset($CFG['GEN']['noEmailButton'])) {
774-
echo '<input type=submit name=submit value="E-mail" title="Send e-mail to the selected students">';
775-
}
776-
?>
777-
<input type=submit name=submit value="Message" title="Send a message to the selected students">
778-
<input type=submit name=submit value="Lock" title="Lock selected students out of the course">
779-
<input type=submit name=submit value="Make Exception" title="Make due date exceptions for selected students">
780-
<input type=submit name=submit value="Copy Emails" title="Get copyable list of email addresses for selected students">
781-
<?php
782-
if (!isset($CFG['GEN']['noInstrUnenroll'])) {
783-
echo '<input type=submit name=submit value="Unenroll" title="Unenroll the selected students">';
784-
}
785-
?>
786-
</p>
784+
<?php
785+
echo _('Check:'), ' <a href="#" onclick="return chkAllNone(\'qform\',\'checked[]\',true)">', _('All'), '</a> <a href="#" onclick="return chkAllNone(\'qform\',\'checked[]\',true,\'locked\')">', _('Non-locked'), '</a> <a href="#" onclick="return chkAllNone(\'qform\',\'checked[]\',false)">', _('None'), '</a> ';
786+
echo '<span class="dropdown">';
787+
echo ' <a tabindex=0 class="dropdown-toggle arrow-down" id="dropdownMenuWithsel" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">';
788+
echo _('With Selected').'</a>';
789+
echo '<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuWithsel">';
790+
echo ' <li><a href="#" onclick="postWithSelform(\'Message\');return false;" title="',_("Send a message to the selected students"),'">', _('Message'), "</a></li>";
791+
if (!isset($CFG['GEN']['noEmailButton'])) {
792+
echo ' <li><a href="#" onclick="postWithSelform(\'E-mail\');return false;" title="',_("Send e-mail to the selected students"),'">', _('E-mail'), "</a></li>";
793+
}
794+
echo ' <li><a href="#" onclick="copyemails();return false;" title="',_("Copy e-mail addresses of the selected students"),'">', _('Copy E-mails'), "</a></li>";
795+
echo ' <li><a href="#" onclick="postWithSelform(\'Make Exception\');return false;" title="',_("Make due date exceptions for selected students"),'">',_('Make Exception'), "</a></li>";
796+
echo ' <li><a href="#" onclick="postWithSelform(\'Lock\');return false;" title="',_("Lock selected students out of the course"),'">', _('Lock'), "</a></li>";
797+
echo ' <li><a href="#" onclick="postWithSelform(\'Unlock\');return false;" title="',_("Un-Lock selected students from the course"),'">', _('Un-Lock'), "</a></li>";
798+
799+
if (!isset($CFG['GEN']['noInstrUnenroll'])) {
800+
echo '<li role="separator" class="divider"></li>';
801+
echo ' <li><a href="#" onclick="postWithSelform(\'Unenroll\');return false;" title="',_("Unenroll the selected students"),'">', _('Unenroll'), "</a></li>";
802+
}
787803

804+
echo '</ul></span>';
805+
?>
806+
788807
<table class=gb id=myTable>
789808
<caption class="sr-only">Roster</caption>
790809
<thead>

course/lockstu.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@
3434
$stm = $DBH->prepare("UPDATE imas_students SET locked=:locked WHERE courseid=:courseid AND userid IN ($locklist)");
3535
$stm->execute(array(':locked'=>$now, ':courseid'=>$cid));
3636

37+
if ($calledfrom=='lu') {
38+
header('Location: ' . $GLOBALS['basesiteurl'] . "/course/listusers.php?cid=$cid&r=" . Sanitize::randomQueryStringParam());
39+
exit;
40+
} else if ($calledfrom == 'gb') {
41+
header('Location: ' . $GLOBALS['basesiteurl'] . "/course/gradebook.php?cid=$cid&gbmode=" . Sanitize::encodeUrlParam($_GET['gbmode'] ?? '') . "&r=" . Sanitize::randomQueryStringParam());
42+
exit;
43+
}
44+
} else if (isset($_POST['posted']) && $_POST['posted']=="Unlock") { // handle unlock
45+
if (!empty($_POST['checked'])) {
46+
$uids = array_map('intval', $_POST['checked']);
47+
$ph = Sanitize::generateQueryPlaceholders($uids);
48+
$stm = $DBH->prepare("UPDATE imas_students SET locked=0 WHERE courseid=? AND userid IN ($ph)");
49+
$stm->execute([$cid, ...$uids]);
50+
}
3751
if ($calledfrom=='lu') {
3852
header('Location: ' . $GLOBALS['basesiteurl'] . "/course/listusers.php?cid=$cid&r=" . Sanitize::randomQueryStringParam());
3953
exit;

0 commit comments

Comments
 (0)