Skip to content

Commit

Permalink
get_teacher() to get_users_by_capability(). Merged with HEAD.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethem committed Nov 3, 2006
1 parent 9abc42b commit 0b06840
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
14 changes: 8 additions & 6 deletions enrol/authorize/enrol.php
Expand Up @@ -205,7 +205,7 @@ function cc_submit($form, $course)
return; return;
} }


if ($an_review) { // review enabled, inform site payment managers and redirect the user who have paid to main page. if ($an_review) { // review enabled, inform payment managers and redirect the user who have paid to main page.
$a = new stdClass; $a = new stdClass;
$a->url = "$CFG->wwwroot/enrol/authorize/index.php?order=$order->id"; $a->url = "$CFG->wwwroot/enrol/authorize/index.php?order=$order->id";
$a->orderid = $order->id; $a->orderid = $order->id;
Expand Down Expand Up @@ -236,12 +236,14 @@ function cc_submit($form, $course)
if (!empty($CFG->enrol_mailstudents)) { if (!empty($CFG->enrol_mailstudents)) {
send_welcome_messages($order->id); send_welcome_messages($order->id);
} }
$teacher = get_teacher($course->id);
if (!empty($CFG->enrol_mailteachers)) { if (!empty($CFG->enrol_mailteachers)) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments', '', '', '0', '1');
$paymentmanager = array_shift($paymentmanagers);
$a = new stdClass; $a = new stdClass;
$a->course = "$course->fullname"; $a->course = "$course->fullname";
$a->user = fullname($USER); $a->user = fullname($USER);
email_to_user($teacher, email_to_user($paymentmanager,
$USER, $USER,
get_string("enrolmentnew", '', $course->shortname), get_string("enrolmentnew", '', $course->shortname),
get_string('enrolmentnewuser', '', $a)); get_string('enrolmentnewuser', '', $a));
Expand All @@ -259,16 +261,16 @@ function cc_submit($form, $course)
} }
} }
} else { } else {
email_to_admin("Error while trying to enrol " . email_to_admin("Error while trying to enrol " . fullname($USER) . " in '$course->fullname'", $order);
fullname($USER) . " in '$course->fullname'", $order);
} }


if ($SESSION->wantsurl) { if ($SESSION->wantsurl) {
$destination = $SESSION->wantsurl; unset($SESSION->wantsurl); $destination = $SESSION->wantsurl; unset($SESSION->wantsurl);
} else { } else {
$destination = "$CFG->wwwroot/course/view.php?id=$course->id"; $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
} }
redirect($destination); load_all_capabilities();
redirect($destination, get_string('paymentthanks', 'moodle', $course->fullname), 10);
} }




Expand Down
15 changes: 7 additions & 8 deletions enrol/authorize/localfuncs.php
Expand Up @@ -322,7 +322,7 @@ function send_welcome_messages($orderdata)
global $CFG, $SITE; global $CFG, $SITE;


if (empty($orderdata)) { if (empty($orderdata)) {
return; return;
} }


if (is_numeric($orderdata)) { if (is_numeric($orderdata)) {
Expand All @@ -336,12 +336,11 @@ function send_welcome_messages($orderdata)
ORDER BY e.userid"; ORDER BY e.userid";


$emailinfo = get_records_sql($select); $emailinfo = get_records_sql($select);
$emailcount = count($emailinfo); if (1 == count($emailinfo)) {
if ($emailcount == 1) {
$ei = reset($emailinfo); $ei = reset($emailinfo);
if (!$sender = get_teacher($ei->courseid)) { $context = get_context_instance(CONTEXT_COURSE, $ei->courseid);
$sender = get_admin(); $paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments', '', '', '0', '1');
} $sender = array_shift($paymentmanagers);
} }
else { else {
$sender = get_admin(); $sender = get_admin();
Expand All @@ -351,8 +350,8 @@ function send_welcome_messages($orderdata)
while ($ei !== false) { while ($ei !== false) {
$usercourses = array(); $usercourses = array();
$lastuserid = $ei->userid; $lastuserid = $ei->userid;
for ($current = $ei; $current !== false && $current->userid == $lastuserid; $current = next($emailinfo)) { for ($current = $ei; $current !== false && $current->userid == $lastuserid; $current = next($emailinfo)) {
$usercourses[] = $current->fullname; $usercourses[] = $current->fullname;
} }
$ei = $current; $ei = $current;
$a = new stdClass; $a = new stdClass;
Expand Down

0 comments on commit 0b06840

Please sign in to comment.