Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

enrol/authorize: MDL-22777 deleting unused files (missed in previous …

…commit)
  • Loading branch information...
commit 0b66f4e46f0c867b17728f7f4df60e5914e5553e 1 parent 492a55e
Aaron Barnes srynot4sale authored

Showing 2 changed files with 0 additions and 1,148 deletions. Show diff stats Hide diff stats

  1. +0 243 enrol/authorize/config_form.php
  2. +0 905 enrol/authorize/enrol.php
243 enrol/authorize/config_form.php
... ... @@ -1,243 +0,0 @@
1   -<?php
2   -
3   -if (!defined('MOODLE_INTERNAL')) {
4   - die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
5   -}
6   -
7   -
8   -if (!isset($frm->enrol_cost)) $frm->enrol_cost = '5';
9   -if (!isset($frm->enrol_currency)) $frm->enrol_currency = 'USD';
10   -if (!isset($frm->enrol_mailstudents)) $frm->enrol_mailstudents = '';
11   -if (!isset($frm->enrol_mailteachers)) $frm->enrol_mailteachers = '';
12   -if (!isset($frm->enrol_mailadmins)) $frm->enrol_mailadmins = '';
13   -
14   -if (!isset($frm->an_login)) $frm->an_login = '';
15   -if (!isset($frm->an_tran_key)) $frm->an_tran_key = '';
16   -if (!isset($frm->an_password)) $frm->an_password = '';
17   -if (!isset($frm->delete_current)) $frm->delete_current = '';
18   -if (!isset($frm->an_referer)) $frm->an_referer = 'http://';
19   -if (!isset($frm->an_avs)) $frm->an_avs = '';
20   -if (!isset($frm->an_authcode)) $frm->an_authcode = '';
21   -if (!isset($frm->an_test)) $frm->an_test = '';
22   -if (!isset($frm->an_review)) $frm->an_review = '';
23   -if (!isset($frm->an_capture_day)) $frm->an_capture_day = '5';
24   -if (!isset($frm->an_emailexpired)) $frm->an_emailexpired = '2';
25   -if (!isset($frm->an_emailexpiredteacher)) $frm->an_emailexpiredteacher = '';
26   -if (!isset($frm->an_sorttype)) $frm->an_sorttype = 'ttl';
27   -
28   -if (isset($CFG->an_cutoff)) {
29   - $cutoff = intval($CFG->an_cutoff);
30   - $mins = $cutoff % 60; $hrs = ($cutoff - $mins) / 60;
31   - $frm->an_cutoff_hour = $hrs; $frm->an_cutoff_min = $mins;
32   -}
33   -if (!isset($frm->an_cutoff_hour)) {
34   - $timezone = round(get_user_timezone_offset(), 1);
35   - $frm->an_cutoff_hour = intval($timezone);
36   - $frm->an_cutoff_min = (intval(round($timezone)) != intval($timezone)) ? 35 : 5;
37   -}
38   -
39   -if (!isset($frm->acceptmethods)) {
40   - $frm->acceptmethods = get_list_of_payment_methods();
41   - $CFG->an_acceptmethods = implode(',', $frm->acceptmethods);
42   -}
43   -
44   -if (!isset($frm->acceptccs)) {
45   - $frm->acceptccs = array_keys(get_list_of_creditcards());
46   - $CFG->an_acceptccs = implode(',', $frm->acceptccs);
47   -}
48   -
49   -if (!isset($frm->acceptechecktypes)) {
50   - $frm->acceptechecktypes = get_list_of_bank_account_types();
51   - $CFG->an_acceptechecktypes = implode(',', $frm->acceptechecktypes);
52   -}
53   -
54   -?>
55   -
56   -<table cellspacing="0" cellpadding="5" border="0" class="boxaligncenter">
57   -
58   -<tr valign="top">
59   - <td colspan="2" align="right"><a href="../enrol/authorize/index.php"><?php print_string("paymentmanagement", "enrol_authorize") ?></a></td>
60   -</tr>
61   -
62   -<tr valign="top"><td colspan="2"><h4><?php print_string("adminauthorizewide", "enrol_authorize") ?></h4></td></tr>
63   -
64   -<tr valign="top">
65   - <td align="right">enrol_cost:</td>
66   - <td><input type="text" size="5" name="enrol_cost" value="<?php p($frm->enrol_cost) ?>" /><br />
67   - <?php print_string("costdefault") ?>. <?php print_string("costdefaultdesc", "enrol_authorize") ?></td>
68   -</tr>
69   -
70   -<tr valign="top">
71   - <td align="right">enrol_currency:</td>
72   - <td><?php
73   - echo html_writer::select(get_string_manager()->get_list_of_currencies(), "enrol_currency", $frm->enrol_currency, false);
74   - ?>
75   - <br />
76   - <?php print_string("currency") ?>
77   - </td>
78   -</tr>
79   -
80   -<tr valign="top"><td colspan="2"><h4><?php print_string("adminauthorizesettings", "enrol_authorize") ?></h4></td></tr>
81   -
82   -<tr valign="top">
83   - <td align="right">&nbsp;&nbsp;</td>
84   - <td><?php print_string("logininfo", "enrol_authorize") ?><br />
85   - <?php if (!optional_param('verifyaccount', 0, PARAM_INT) && isset($mconfig->an_login) && (isset($mconfig->an_tran_key) || isset($mconfig->an_password))) { ?>
86   - <br /><a href="enrol_config.php?enrol=authorize&amp;verifyaccount=1"><b><?php print_string("verifyaccount", "enrol_authorize") ?></b></a><br />
87   - <?php } ?></td>
88   -</tr>
89   -
90   -<tr valign="top">
91   - <td align="right">an_login:<br /><?php echo (isset($mconfig->an_login)) ? '<span style="color:green">'.get_string('dataentered', 'enrol_authorize').'</span>' : ''; ?></td>
92   - <td><?php print_string("anlogin", "enrol_authorize") ?><br /><input type="text" name="an_login" size="26" value="" /><sup>*</sup></td>
93   -</tr>
94   -
95   -<tr valign="top">
96   - <td align="right">an_tran_key:<br /><?php echo (isset($mconfig->an_tran_key)) ? '<span style="color:green">'.get_string('dataentered', 'enrol_authorize').'</span>' : ''; ?></td>
97   - <td><?php print_string("antrankey", "enrol_authorize") ?><br /><input type="text" name="an_tran_key" size="26" value="" /><sup>#1</sup></td>
98   -</tr>
99   -
100   -<tr valign="top">
101   - <td align="right">an_password:<br /><?php echo (isset($mconfig->an_password)) ? '<span style="color:green">'.get_string('dataentered', 'enrol_authorize').'</span>' : ''; ?></td>
102   - <td><?php print_string("anpassword", "enrol_authorize") ?><br /><input type="text" name="an_password" size="26" value="" /><sup>#2</sup></td>
103   -</tr>
104   -
105   -<tr valign="top">
106   - <td align="right">delete_current:</td>
107   - <td><?php echo html_writer::checkbox('delete_current', '1', !empty($frm->delete_current), get_string("deletecheck", "moodle", get_string('oldpassword')));?> <br />
108   - <hr /></td>
109   -</tr>
110   -
111   -<tr valign="top">
112   - <td align="right">an_referer:</td>
113   - <td><input type="text" name="an_referer" size="35" value="<?php p($frm->an_referer) ?>" /><br />
114   - <?php print_string("anreferer", "enrol_authorize") ?></td>
115   -</tr>
116   -
117   -<tr valign="top">
118   - <td align="right">an_cutoff:</td>
119   - <td><?php
120   - $curtime = make_timestamp(2000,1,1,$frm->an_cutoff_hour,$frm->an_cutoff_min);
121   - $hourselector = html_writer::select_time('hours', 'an_cutoff_hour', $curtime);
122   - $minselector = html_writer::select_time('minutes', 'an_cutoff_min', $curtime);
123   - echo $hourselector . $minselector;
124   - ?><br />
125   - <?php print_string("cutofftime", "enrol_authorize") ?></td>
126   -</tr>
127   -
128   -<tr valign="top">
129   - <td align="right">an_avs:</td>
130   - <td><?php echo html_writer::checkbox('an_avs', '1', !empty($frm->an_avs), get_string("adminavs", "enrol_authorize")); ?><br />
131   - </td>
132   -</tr>
133   -
134   -<tr valign="top">
135   - <td align="right">an_authcode:</td>
136   - <td><?php echo html_writer::checkbox('an_authcode', '1', !empty($frm->an_authcode), get_string("adminauthcode", "enrol_authorize")); ?>
137   - <?php echo $OUTPUT->old_help_icon('authorize/authcode', 'authcode', 'enrol'); ?><br />
138   - </td>
139   -</tr>
140   -
141   -<tr valign="top">
142   - <td align="right">an_test:</td>
143   - <td><?php echo html_writer::checkbox('an_test', '1', !empty($frm->an_test), get_string("antestmode", "enrol_authorize")); ?><br />
144   - </td>
145   -</tr>
146   -
147   -<tr valign="top">
148   - <td align="right">accepts:</td>
149   - <td><?php print_string("adminaccepts", "enrol_authorize") ?><br /><br /><?php
150   - $paymentmethodsenabled = get_list_of_payment_methods();
151   - $allpaymentmethods = get_list_of_payment_methods(true);
152   - foreach ($allpaymentmethods as $key) {
153   - if ($key == AN_METHOD_CC) {
154   - echo html_writer::checkbox('acceptmethods[]', AN_METHOD_CC, in_array(AN_METHOD_CC, $paymentmethodsenabled), get_string('method'.AN_METHOD_CC,'enrol_authorize'));
155   - echo("<ul>"); // blockquote breaks <span> and <br> tags
156   - $acceptedccs = array_keys(get_list_of_creditcards());
157   - $allccs = get_list_of_creditcards(true);
158   - foreach ($allccs as $key => $val) {
159   - echo "<li>";
160   - echo html_writer::checkbox('acceptccs[]', $key, in_array($key, $acceptedccs), $val);
161   - echo "</li>";
162   - }
163   - echo("</ul>");
164   - }
165   - elseif ($key == AN_METHOD_ECHECK) {
166   - echo html_writer::checkbox('acceptmethods[]', AN_METHOD_ECHECK, in_array(AN_METHOD_ECHECK, $paymentmethodsenabled), get_string('method'.AN_METHOD_ECHECK, 'enrol_authorize'));
167   - echo("<ul>"); // blockquote breaks <span> and <br> tags
168   - $echecktypesenabled = get_list_of_bank_account_types();
169   - $allechecktypes = get_list_of_bank_account_types(true);
170   - foreach ($allechecktypes as $key) {
171   - echo "<li>";
172   - echo html_writer::checkbox('acceptechecktypes[]', $key, in_array($key, $echecktypesenabled), get_string('echeck'.strtolower($key)));
173   - echo "</li>";
174   - }
175   - echo("</ul>");
176   - }
177   - }
178   - ?><br /></td>
179   -</tr>
180   -
181   -<tr valign="top"><td colspan="2"><h4><?php print_string("adminauthorizeccapture", "enrol_authorize") ?>
182   - <?php echo $OUTPUT->old_help_icon('authorize/orderreview', 'orderreview', 'enrol'); ?>
183   - </h4></td></tr>
184   -
185   -<tr valign="top">
186   - <td align="right">an_review:</td>
187   - <td><?php echo html_writer::checkbox('an_review', '1', !empty($frm->an_review), get_string("adminreview", "enrol_authorize")); ?>
188   - <?php echo $OUTPUT->old_help_icon('authorize/review', get_string('adminhelpreviewtitle', 'enrol_authorize'), 'enrol'); ?><br />
189   - </td>
190   -</tr>
191   -
192   -<tr valign="top">
193   - <td align="right">an_capture_day:</td>
194   - <td><input type="text" name="an_capture_day" size="2" maxlength="2" value="<?php p($frm->an_capture_day) ?>" />
195   - <?php echo $OUTPUT->old_help_icon('authorize/captureday', get_string('adminhelpcapturetitle', 'enrol_authorize'), 'enrol'); ?><br />
196   - <?php print_string("reviewday", "enrol_authorize", $frm->an_capture_day) ?></td>
197   -</tr>
198   -
199   -<tr valign="top"><td colspan="2"><h4><?php print_string("adminauthorizeemail", "enrol_authorize") ?></h4></td></tr>
200   -
201   -<tr valign="top">
202   - <td align="right">an_emailexpired:</td>
203   - <td><input type="text" name="an_emailexpired" size="1" maxlength="1" value="<?php p($frm->an_emailexpired) ?>" /><br />
204   - <?php print_string("adminemailexpired", "enrol_authorize", $frm->an_emailexpired) ?><br />
205   - <?php print_string("adminemailexpsetting", "enrol_authorize") ?></td>
206   -</tr>
207   -
208   -<tr valign="top">
209   - <td align="right">an_emailexpiredteacher:</td>
210   - <td><?php echo html_writer::checkbox('an_emailexpiredteacher', '1', !empty($frm->an_emailexpiredteacher), get_string("adminemailexpiredteacher", "enrol_authorize")); ?><br />
211   - </td>
212   -</tr>
213   -
214   -<tr valign="top">
215   - <td align="right">an_sorttype:</td>
216   - <td><?php
217   - $sorts = array('ttl' => get_string('adminemailexpiredsortsum', 'enrol_authorize'),
218   - 'cnt' => get_string('adminemailexpiredsortcount', 'enrol_authorize'));
219   - echo html_writer::select($sorts, "an_sorttype", $frm->an_sorttype, false);
220   - ?>
221   - <br />
222   - <?php print_string("adminemailexpiredsort", "enrol_authorize") ?></td>
223   -</tr>
224   -
225   -<tr valign="top">
226   - <td align="right">enrol_mailstudents:</td>
227   - <td><?php echo html_writer::checkbox('enrol_mailstudents', '1', !empty($frm->enrol_mailstudents), get_string("mailstudents")); ?><br />
228   - </td>
229   -</tr>
230   -
231   -<tr valign="top">
232   - <td align="right">enrol_mailteachers:</td>
233   - <td><?php echo html_writer::checkbox('enrol_mailteachers', '1', !empty($frm->enrol_mailteachers), get_string("mailteachers")); ?><br />
234   - </td>
235   -</tr>
236   -
237   -<tr valign="top">
238   - <td align="right">enrol_mailadmins:</td>
239   - <td><?php echo html_writer::checkbox('enrol_mailadmins', '1', !empty($frm->enrol_mailadmins), get_string("mailadmins")); ?><br />
240   - </td>
241   -</tr>
242   -
243   -</table>
905 enrol/authorize/enrol.php
... ... @@ -1,905 +0,0 @@
1   -<?php
2   -
3   -require_once($CFG->dirroot.'/enrol/authorize/const.php');
4   -require_once($CFG->dirroot.'/enrol/authorize/localfuncs.php');
5   -require_once($CFG->dirroot.'/enrol/authorize/authorizenet.class.php');
6   -require_once($CFG->libdir.'/eventslib.php');
7   -
8   -/**
9   - * Authorize.net Payment Gateway plugin
10   - */
11   -class enrolment_plugin_authorize
12   -{
13   -
14   - /**
15   - * Cron log.
16   - *
17   - * @var string
18   - * @access public
19   - */
20   - public $log;
21   -
22   -
23   - /**
24   - * Presents registration forms.
25   - *
26   - * @param object $course Course info
27   - * @access public
28   - */
29   - public function print_entry($course)
30   - {
31   - global $CFG, $USER, $OUTPUT, $PAGE, $form;
32   -
33   - $zerocost = zero_cost($course);
34   - if ($zerocost) {
35   - $manual = enrolment_factory::factory('manual');
36   - if (!empty($this->errormsg)) {
37   - $manual->errormsg = $this->errormsg;
38   - }
39   - $manual->print_entry($course);
40   - return;
41   - }
42   -
43   - prevent_double_paid($course);
44   - httpsrequired();
45   -
46   - if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 443) { // MDL-9836
47   - if (empty($CFG->loginhttps)) {
48   - print_error('httpsrequired', 'enrol_authorize');
49   - } else {
50   - $wwwsroot = str_replace('http:','https:', $CFG->wwwroot);
51   - redirect("$wwwsroot/enrol/index.php?id=$course->id");
52   - exit;
53   - }
54   - }
55   -
56   - $strcourses = get_string('courses');
57   - $strloginto = get_string('loginto', '', $course->shortname);
58   -
59   - $PAGE->navbar->add($strcourses, new moodle_url('/course/'));
60   - $PAGE->navbar->add($strloginto);
61   - $PAGE->set_title($strloginto);
62   - $PAGE->set_heading($course->fullname);
63   - echo $OUTPUT->header();
64   - print_course($course, '80%');
65   -
66   - if ($course->password) {
67   - echo $OUTPUT->heading(get_string('choosemethod', 'enrol_authorize'));
68   - }
69   -
70   - if (isguestuser()) { // only real guest user, not for users with guest role
71   - $curcost = get_course_cost($course);
72   - echo '<div class="mdl-align">';
73   - echo '<p>'.get_string('paymentrequired').'</p>';
74   - echo '<p><b>'.get_string('cost').": $curcost[currency] $curcost[cost]".'</b></p>';
75   - echo '<p><a href="'.$CFG->httpswwwroot.'/login/">'.get_string('loginsite').'</a></p>';
76   - echo '</div>';
77   - }
78   - else {
79   - require_once($CFG->dirroot.'/enrol/authorize/enrol_form.php');
80   - $frmenrol = new enrol_authorize_form('enrol.php', compact('course'));
81   - if ($frmenrol->get_data()) {
82   - $authorizeerror = '';
83   - switch ($form->paymentmethod) {
84   - case AN_METHOD_CC:
85   - $authorizeerror = $this->cc_submit($form, $course);
86   - break;
87   -
88   - case AN_METHOD_ECHECK:
89   - $authorizeerror = $this->echeck_submit($form, $course);
90   - break;
91   - }
92   - if (!empty($authorizeerror)) {
93   - print_error('authorizeerror', 'enrol_authorize', '', $authorizeerror);
94   - }
95   - }
96   -
97   - echo $OUTPUT->box_start();
98   - $frmenrol->display();
99   - echo $OUTPUT->box_end();
100   - }
101   -
102   - if ($course->password) {
103   - $password = '';
104   - include($CFG->dirroot.'/enrol/manual/enrol.html');
105   - }
106   -
107   - echo $OUTPUT->footer();
108   - }
109   -
110   -
111   - function print_enrolmentkeyfrom($course)
112   - {
113   - $manual = enrolment_factory::factory('manual');
114   - $manual->print_enrolmentkeyfrom($course);
115   - }
116   -
117   -
118   - /**
119   - * Validates registration forms and enrols student to course.
120   - *
121   - * @param object $form Form parameters
122   - * @param object $course Course info
123   - * @access public
124   - */
125   - public function check_entry($form, $course)
126   - {
127   - global $CFG;
128   -
129   - if (zero_cost($course) || (!empty($course->password) && !empty($form->enrol) && $form->enrol == 'manual')) {
130   - $manual = enrolment_factory::factory('manual');
131   - $manual->check_entry($form, $course);
132   - if (!empty($manual->errormsg)) {
133   - $this->errormsg = $manual->errormsg;
134   - }
135   - }
136   - }
137   -
138   -
139   -
140   - /**
141   - * The user submitted credit card form.
142   - *
143   - * @param object $form Form parameters
144   - * @param object $course Course info
145   - * @return string NULL if ok, error message otherwise.
146   - * @access private
147   - */
148   - private function cc_submit($form, $course)
149   - {
150   - global $CFG, $USER, $SESSION, $OUTPUT, $DB;
151   -
152   - prevent_double_paid($course);
153   -
154   - $useripno = getremoteaddr();
155   - $curcost = get_course_cost($course);
156   - $exp_date = sprintf("%02d", $form->ccexpiremm) . $form->ccexpireyyyy;
157   -
158   - // NEW CC ORDER
159   - $timenow = time();
160   - $order = new stdClass();
161   - $order->paymentmethod = AN_METHOD_CC;
162   - $order->refundinfo = substr($form->cc, -4);
163   - $order->ccname = $form->firstname . " " . $form->lastname;
164   - $order->courseid = $course->id;
165   - $order->userid = $USER->id;
166   - $order->status = AN_STATUS_NONE; // it will be changed...
167   - $order->settletime = 0; // cron changes this.
168   - $order->transid = 0; // Transaction Id
169   - $order->timecreated = $timenow;
170   - $order->amount = $curcost['cost'];
171   - $order->currency = $curcost['currency'];
172   - $order->id = $DB->insert_record("enrol_authorize", $order);
173   - if (!$order->id) {
174   - message_to_admin("Error while trying to insert new data", $order);
175   - return "Insert record error. Admin has been notified!";
176   - }
177   -
178   - $extra = new stdClass();
179   - $extra->x_card_num = $form->cc;
180   - $extra->x_card_code = $form->cvv;
181   - $extra->x_exp_date = $exp_date;
182   - $extra->x_currency_code = $curcost['currency'];
183   - $extra->x_amount = $curcost['cost'];
184   - $extra->x_first_name = $form->firstname;
185   - $extra->x_last_name = $form->lastname;
186   - $extra->x_country = $form->cccountry;
187   - $extra->x_address = $form->ccaddress;
188   - $extra->x_state = $form->ccstate;
189   - $extra->x_city = $form->cccity;
190   - $extra->x_zip = $form->cczip;
191   -
192   - $extra->x_invoice_num = $order->id;
193   - $extra->x_description = $course->shortname;
194   -
195   - $extra->x_cust_id = $USER->id;
196   - $extra->x_email = $USER->email;
197   - $extra->x_customer_ip = $useripno;
198   - $extra->x_email_customer = empty($CFG->enrol_mailstudents) ? 'FALSE' : 'TRUE';
199   - $extra->x_phone = '';
200   - $extra->x_fax = '';
201   -
202   - if (!empty($CFG->an_authcode) && !empty($form->ccauthcode)) {
203   - $action = AN_ACTION_CAPTURE_ONLY;
204   - $extra->x_auth_code = $form->ccauthcode;
205   - }
206   - elseif (!empty($CFG->an_review)) {
207   - $action = AN_ACTION_AUTH_ONLY;
208   - }
209   - else {
210   - $action = AN_ACTION_AUTH_CAPTURE;
211   - }
212   -
213   - $message = '';
214   - if (AN_APPROVED == AuthorizeNet::process($order, $message, $extra, $action, $form->cctype))
215   - {
216   - $SESSION->ccpaid = 1; // security check: don't duplicate payment
217   -
218   - switch ($action)
219   - {
220   - // review enabled (authorize but capture: draw money but wait for settlement during 30 days)
221   - // the first step is to inform payment managers and to redirect the user to main page.
222   - // the next step is to accept/deny payment (AN_ACTION_PRIOR_AUTH_CAPTURE/VOID) within 30 days (payment management or scheduled-capture CRON)
223   - // unless you accept payment or enable auto-capture cron, the transaction is expired after 30 days and the user cannot enrol to the course during 30 days.
224   - // see also: admin/cron.php, $this->cron(), $CFG->an_capture_day...
225   - case AN_ACTION_AUTH_ONLY:
226   - {
227   - $a = new stdClass;
228   - $a->url = "$CFG->wwwroot/enrol/authorize/index.php?order=$order->id";
229   - $a->orderid = $order->id;
230   - $a->transid = $order->transid;
231   - $a->amount = "$order->currency $order->amount";
232   - $a->expireon = userdate(AuthorizeNet::getsettletime($timenow + (30 * 3600 * 24)));
233   - $a->captureon = userdate(AuthorizeNet::getsettletime($timenow + (intval($CFG->an_capture_day) * 3600 * 24)));
234   - $a->course = $course->fullname;
235   - $a->user = fullname($USER);
236   - $a->acstatus = ($CFG->an_capture_day > 0) ? get_string('yes') : get_string('no');
237   - $emailmessage = get_string('adminneworder', 'enrol_authorize', $a);
238   - $a = new stdClass;
239   - $a->course = $course->shortname;
240   - $a->orderid = $order->id;
241   - $emailsubject = get_string('adminnewordersubject', 'enrol_authorize', $a);
242   - $context = get_context_instance(CONTEXT_COURSE, $course->id);
243   - if (($paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments'))) {
244   - foreach ($paymentmanagers as $paymentmanager) {
245   - $eventdata = new object();
246   - $eventdata->modulename = 'moodle';
247   - $eventdata->userfrom = $USER;
248   - $eventdata->userto = $paymentmanager;
249   - $eventdata->subject = $emailsubject;
250   - $eventdata->fullmessage = $emailmessage;
251   - $eventdata->fullmessageformat = FORMAT_PLAIN;
252   - $eventdata->fullmessagehtml = '';
253   - $eventdata->smallmessage = '';
254   - message_send($eventdata);
255   - }
256   - }
257   - redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '30');
258   - break;
259   - }
260   -
261   - case AN_ACTION_CAPTURE_ONLY: // auth code received via phone and the code accepted.
262   - case AN_ACTION_AUTH_CAPTURE: // real time transaction, authorize and capture.
263   - {
264   - // Credit card captured, ENROL student now...
265   - if (enrol_into_course($course, $USER, 'authorize'))
266   - {
267   - if (!empty($CFG->enrol_mailstudents)) {
268   - send_welcome_messages($order->id);
269   - }
270   - if (!empty($CFG->enrol_mailteachers)) {
271   - $context = get_context_instance(CONTEXT_COURSE, $course->id);
272   - $paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments', '', '', '0', '1');
273   - $paymentmanager = array_shift($paymentmanagers);
274   - $a = new stdClass;
275   - $a->course = "$course->fullname";
276   - $a->user = fullname($USER);
277   -
278   - $eventdata = new object();
279   - $eventdata->modulename = 'moodle';
280   - $eventdata->userfrom = $USER;
281   - $eventdata->userto = $paymentmanager;
282   - $eventdata->subject = get_string("enrolmentnew", '', format_string($course->shortname));
283   - $eventdata->fullmessage = get_string('enrolmentnewuser', '', $a);
284   - $eventdata->fullmessageformat = FORMAT_PLAIN;
285   - $eventdata->fullmessagehtml = '';
286   - $eventdata->smallmessage = '';
287   - message_send($eventdata);
288   - }
289   - if (!empty($CFG->enrol_mailadmins)) {
290   - $a = new stdClass;
291   - $a->course = "$course->fullname";
292   - $a->user = fullname($USER);
293   - $admins = get_admins();
294   - foreach ($admins as $admin) {
295   - $eventdata = new object();
296   - $eventdata->modulename = 'moodle';
297   - $eventdata->userfrom = $USER;
298   - $eventdata->userto = $admin;
299   - $eventdata->subject = get_string("enrolmentnew", '', format_string($course->shortname));
300   - $eventdata->fullmessage = get_string('enrolmentnewuser', '', $a);
301   - $eventdata->fullmessageformat = FORMAT_PLAIN;
302   - $eventdata->fullmessagehtml = '';
303   - $eventdata->smallmessage = '';
304   - message_send($eventdata);
305   - }
306   - }
307   - }
308   - else
309   - {
310   - message_to_admin("Error while trying to enrol " . fullname($USER) . " in '$course->fullname'", $order);
311   - }
312   -
313   - load_all_capabilities();
314   -
315   - echo $OUTPUT->box_start('generalbox notice');
316   - echo '<p>'. get_string('paymentthanks', 'moodle', $course->fullname) .'</p>';
317   - echo $OUTPUT->container_start('buttons');
318   - echo $OUTPUT->single_button(new moodle_url("$CFG->wwwroot/enrol/authorize/index.php", array('order'=>$order->id)), get_string('payments'));
319   - echo $OUTPUT->single_button(new moodle_url("$CFG->wwwroot/course/view.php", array('id'=>$course->id)), $course->fullname);
320   - echo $OUTPUT->container_end();
321   - echo $OUTPUT->box_end();
322   - echo $OUTPUT->footer();
323   - exit; // break;
324   - }
325   - }
326   - return NULL;
327   - }
328   - else
329   - {
330   - message_to_admin($message, $order);
331   - return $message;
332   - }
333   - }
334   -
335   -
336   - /**
337   - * The user submitted echeck form.
338   - *
339   - * @param object $form Form parameters
340   - * @param object $course Course info
341   - * @return string NULL if ok, error message otherwise.
342   - * @access private
343   - */
344   - private function echeck_submit($form, $course)
345   - {
346   - global $CFG, $USER, $SESSION, $DB;
347   -
348   - prevent_double_paid($course);
349   -
350   - $useripno = getremoteaddr();
351   - $curcost = get_course_cost($course);
352   - $isbusinesschecking = ($form->acctype == 'BUSINESSCHECKING');
353   -
354   - // NEW ECHECK ORDER
355   - $timenow = time();
356   - $order = new stdClass();
357   - $order->paymentmethod = AN_METHOD_ECHECK;
358   - $order->refundinfo = $isbusinesschecking ? 1 : 0;
359   - $order->ccname = $form->firstname . ' ' . $form->lastname;
360   - $order->courseid = $course->id;
361   - $order->userid = $USER->id;
362   - $order->status = AN_STATUS_NONE; // it will be changed...
363   - $order->settletime = 0; // cron changes this.
364   - $order->transid = 0; // Transaction Id
365   - $order->timecreated = $timenow;
366   - $order->amount = $curcost['cost'];
367   - $order->currency = $curcost['currency'];
368   - $order->id = $DB->insert_record("enrol_authorize", $order);
369   - if (!$order->id) {
370   - message_to_admin("Error while trying to insert new data", $order);
371   - return "Insert record error. Admin has been notified!";
372   - }
373   -
374   - $extra = new stdClass();
375   - $extra->x_bank_aba_code = $form->abacode;
376   - $extra->x_bank_acct_num = $form->accnum;
377   - $extra->x_bank_acct_type = $form->acctype;
378   - $extra->x_echeck_type = $isbusinesschecking ? 'CCD' : 'WEB';
379   - $extra->x_bank_name = $form->bankname;
380   - $extra->x_currency_code = $curcost['currency'];
381   - $extra->x_amount = $curcost['cost'];
382   - $extra->x_first_name = $form->firstname;
383   - $extra->x_last_name = $form->lastname;
384   - $extra->x_country = $USER->country;
385   - $extra->x_address = $USER->address;
386   - $extra->x_city = $USER->city;
387   - $extra->x_state = '';
388   - $extra->x_zip = '';
389   -
390   - $extra->x_invoice_num = $order->id;
391   - $extra->x_description = $course->shortname;
392   -
393   - $extra->x_cust_id = $USER->id;
394   - $extra->x_email = $USER->email;
395   - $extra->x_customer_ip = $useripno;
396   - $extra->x_email_customer = empty($CFG->enrol_mailstudents) ? 'FALSE' : 'TRUE';
397   - $extra->x_phone = '';
398   - $extra->x_fax = '';
399   -
400   - $message = '';
401   - if (AN_REVIEW == AuthorizeNet::process($order, $message, $extra, AN_ACTION_AUTH_CAPTURE)) {
402   - $SESSION->ccpaid = 1; // security check: don't duplicate payment
403   - redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '30');
404   - return NULL;
405   - }
406   - else {
407   - message_to_admin($message, $order);
408   - return $message;
409   - }
410   - }
411   -
412   -
413   - /**
414   - * Gets access icons.
415   - *
416   - * @param object $course
417   - * @return string
418   - * @access public
419   - */
420   - public function get_access_icons($course)
421   - {
422   - $manual = enrolment_factory::factory('manual');
423   - $str = $manual->get_access_icons($course);
424   - $curcost = get_course_cost($course);
425   -
426   - if (abs($curcost['cost']) > 0.00) {
427   - $strrequirespayment = get_string("requirespayment");
428   - $strcost = get_string("cost");
429   - $currency = $curcost['currency'];
430   -
431   - switch ($currency) {
432   - case 'USD': $currency = 'US$'; break;
433   - case 'CAD': $currency = 'C$'; break;
434   - case 'EUR': $currency = '&euro;'; break;
435   - case 'GBP': $currency = '&pound;'; break;
436   - case 'JPY': $currency = '&yen;'; break;
437   - }
438   -
439   - $str .= '<div class="cost" title="'.$strrequirespayment.'">'.$strcost.': ';
440   - $str .= $currency . ' ' . $curcost['cost'].'</div>';
441   - }
442   -
443   - return $str;
444   - }
445   -
446   -
447   - /**
448   - * Shows config form & errors
449   - *
450   - * @param object $frm
451   - * @access public
452   - */
453   - public function config_form($frm) {
454   - global $CFG, $DB, $OUTPUT;
455   - $mconfig = get_config('enrol/authorize');
456   -
457   - if (!check_curl_available()) {
458   - echo $OUTPUT->notification('PHP must be compiled with cURL+SSL support (--with-curl --with-openssl)');
459   - }
460   -
461   - if (empty($CFG->loginhttps) and substr($CFG->wwwroot, 0, 5) !== 'https') {
462   - $a = new stdClass;
463   - $a->url = "$CFG->wwwroot/$CFG->admin/settings.php?section=httpsecurity";
464   - echo $OUTPUT->notification(get_string('adminconfighttps', 'enrol_authorize', $a));
465   - return; // notice breaks the form and xhtml later
466   - }
467   - elseif (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 443) { // MDL-9836
468   - $wwwsroot = qualified_me();
469   - $wwwsroot = str_replace('http:', 'https:', $wwwsroot);
470   - $a = new stdClass;
471   - $a->url = $wwwsroot;
472   - echo $OUTPUT->notification(get_string('adminconfighttpsgo', 'enrol_authorize', $a));
473   - return; // notice breaks the form and xhtml later
474   - }
475   -
476   - if (optional_param('verifyaccount', 0, PARAM_INT)) {
477   - echo $OUTPUT->notification(authorize_verify_account());
478   - }
479   -
480   - if (!empty($frm->an_review)) {
481   - $captureday = intval($frm->an_capture_day);
482   - $emailexpired = intval($frm->an_emailexpired);
483   - if ($captureday > 0 || $emailexpired > 0) {
484   - $lastcron = $DB->get_field_sql('SELECT max(lastcron) FROM {modules}');
485   - if ((time() - intval($lastcron) > 3600 * 24)) {
486   - echo $OUTPUT->notification(get_string('admincronsetup', 'enrol_authorize'));
487   - }
488   - }
489   - }
490   -
491   - if (($count = $DB->count_records('enrol_authorize', array('status'=>AN_STATUS_AUTH)))) {
492   - $a = new stdClass;
493   - $a->count = $count;
494   - $a->url = $CFG->wwwroot."/enrol/authorize/index.php?status=".AN_STATUS_AUTH;
495   - echo $OUTPUT->notification(get_string('adminpendingorders', 'enrol_authorize', $a));
496   - }
497   -
498   - if (data_submitted()) {
499   - if (empty($mconfig->an_login)) {
500   - echo $OUTPUT->notification("an_login required");
501   - }
502   - if (empty($mconfig->an_tran_key) && empty($mconfig->an_password)) {
503   - echo $OUTPUT->notification("an_tran_key or an_password required");
504   - }
505   - }
506   -
507   - include($CFG->dirroot.'/enrol/authorize/config_form.php');
508   - }
509   -
510   -
511   - /**
512   - * process_config
513   - *
514   - * @param object $config
515   - * @return bool true if it will be saved.
516   - * @access public
517   - */
518   - public function process_config($config)
519   - {
520   - global $CFG, $DB;
521   - $mconfig = get_config('enrol/authorize');
522   -
523   - // site settings
524   - if (($cost = optional_param('enrol_cost', 5, PARAM_INT)) > 0) {
525   - set_config('enrol_cost', $cost);
526   - }
527   - set_config('enrol_currency', optional_param('enrol_currency', 'USD', PARAM_ALPHA));
528   - set_config('enrol_mailstudents', optional_param('enrol_mailstudents', 0, PARAM_BOOL));
529   - set_config('enrol_mailteachers', optional_param('enrol_mailteachers', 0, PARAM_BOOL));
530   - set_config('enrol_mailadmins', optional_param('enrol_mailadmins', 0, PARAM_BOOL));
531   -
532   - // optional authorize.net settings
533   - set_config('an_avs', optional_param('an_avs', 0, PARAM_BOOL));
534   - set_config('an_authcode', optional_param('an_authcode', 0, PARAM_BOOL));
535   - set_config('an_test', optional_param('an_test', 0, PARAM_BOOL));
536   - set_config('an_referer', optional_param('an_referer', 'http://', PARAM_URL));
537   -
538   - $acceptmethods = optional_param('acceptmethods', get_list_of_payment_methods(), PARAM_ALPHA);
539   - set_config('an_acceptmethods', implode(',', $acceptmethods));
540   - $acceptccs = optional_param('acceptccs', array_keys(get_list_of_creditcards()), PARAM_ALPHA);
541   - set_config('an_acceptccs', implode(',', $acceptccs));
542   - $acceptechecktypes = optional_param('acceptechecktypes', get_list_of_bank_account_types(), PARAM_ALPHA);
543   - set_config('an_acceptechecktypes', implode(',', $acceptechecktypes));
544   -
545   - $cutoff_hour = optional_param('an_cutoff_hour', 0, PARAM_INT);
546   - $cutoff_min = optional_param('an_cutoff_min', 5, PARAM_INT);
547   - set_config('an_cutoff', $cutoff_hour * 60 + $cutoff_min);
548   -
549   - // cron depencies
550   - $reviewval = optional_param('an_review', 0, PARAM_BOOL);
551   - $captureday = optional_param('an_capture_day', 5, PARAM_INT);
552   - $emailexpired = optional_param('an_emailexpired', 2, PARAM_INT);
553   - $emailexpiredteacher = optional_param('an_emailexpiredteacher', 0, PARAM_BOOL);
554   - $sorttype = optional_param('an_sorttype', 'ttl', PARAM_ALPHA);
555   -
556   - $captureday = ($captureday > 29) ? 29 : (($captureday < 0) ? 0 : $captureday);
557   - $emailexpired = ($emailexpired > 5) ? 5 : (($emailexpired < 0) ? 0 : $emailexpired);
558   -
559   - if (!empty($reviewval) && ($captureday > 0 || $emailexpired > 0)) {
560   - $lastcron = $DB->get_field_sql('SELECT max(lastcron) FROM {modules}');
561   - if (time() - intval($lastcron) > 3600 * 24) {
562   - return false;
563   - }
564   - }
565   -
566   - set_config('an_review', $reviewval);
567   - set_config('an_capture_day', $captureday);
568   - set_config('an_emailexpired', $emailexpired);
569   - set_config('an_emailexpiredteacher', $emailexpiredteacher);
570   - set_config('an_sorttype', $sorttype);
571   -
572   - // https and openssl library is required
573   - if ((substr($CFG->wwwroot, 0, 5) !== 'https' and empty($CFG->loginhttps)) or !check_curl_available()) {
574   - return false;
575   - }
576   -
577   - // REQUIRED fields;
578   - // an_login
579   - $loginval = optional_param('an_login', '', PARAM_RAW);
580   - if (empty($loginval) && empty($mconfig->an_login)) {
581   - return false;
582   - }
583   - $loginval = !empty($loginval) ? rc4encrypt($loginval) : strval($mconfig->an_login);
584   - set_config('an_login', $loginval, 'enrol/authorize');
585   -
586   - // an_tran_key, an_password
587   - $tranval = optional_param('an_tran_key', '', PARAM_RAW);
588   - $tranval = !empty($tranval) ? rc4encrypt($tranval) : (isset($mconfig->an_tran_key)?$mconfig->an_tran_key:'');
589   - $passwordval = optional_param('an_password', '', PARAM_RAW);
590   - $passwordval = !empty($passwordval) ? rc4encrypt($passwordval) :(isset($mconfig->an_password)?$mconfig->an_password:'');
591   - $deletecurrent = optional_param('delete_current', '0', PARAM_BOOL);
592   - if (!empty($deletecurrent) and !empty($tranval)) {
593   - unset_config('an_password', 'enrol/authorize');
594   - $passwordval = '';
595   - }
596   - elseif (!empty($passwordval)) {
597   - set_config('an_password', $passwordval, 'enrol/authorize');
598   - }
599   - if (empty($tranval) and empty($passwordval)) {
600   - return false;
601   - }
602   - if (!empty($tranval)) {
603   - set_config('an_tran_key', $tranval, 'enrol/authorize');
604   - }
605   -
606   - return true;
607   - }
608   -
609   - /**
610   - * This function is run by admin/cron.php every time if admin has enabled this plugin.
611   - *
612   - * Everyday at settlement time (default is 00:05), it cleans up some tables
613   - * and sends email to admin/teachers about pending orders expiring if manual-capture has enabled.
614   - *
615   - * If admin set up 'Order review' and 'Capture day', it captures credits cards and enrols students.
616   - *
617   - * @access public
618   - */
619   - public function cron()
620   - {
621   - global $CFG, $DB;
622   -
623   - $oneday = 86400;
624   - $timenow = time();
625   - $settlementtime = AuthorizeNet::getsettletime($timenow);
626   - $timediff30 = $settlementtime - (30 * $oneday);
627   - $mconfig = get_config('enrol/authorize');
628   -
629   - mtrace("Processing authorize cron...");
630   -
631   - if (intval($mconfig->an_dailysettlement) < $settlementtime) {
632   - set_config('an_dailysettlement', $settlementtime, 'enrol/authorize');
633   - mtrace(" Daily cron:");
634   - $this->cron_daily();
635   - mtrace(" Done");
636   - }
637   -
638   - mtrace(" Scheduled capture", ": ");
639   - if (empty($CFG->an_review) or (!empty($CFG->an_test)) or (intval($CFG->an_capture_day) < 1) or (!check_curl_available())) {
640   - mtrace("disabled");
641   - return; // order review disabled or test mode or manual capture or openssl wasn't loaded.
642   - }
643   -
644   - $timediffcnf = $settlementtime - (intval($CFG->an_capture_day) * $oneday);
645   - $select = "(status = ?) AND (timecreated < ?) AND (timecreated > ?)";
646   - $params = array(AN_STATUS_AUTH, $timediffcnf, $timediff30);
647   - if (!($ordercount = $DB->count_records_select('enrol_authorize', $select, $params))) {
648   - mtrace("no pending orders");
649   - return;
650   - }
651   -
652   - $eachconn = intval($mconfig->an_eachconnsecs);
653   - $eachconn = (($eachconn > 60) ? 60 : (($eachconn <= 0) ? 3 : $eachconn));
654   - if (($ordercount * $eachconn) + intval($mconfig->an_lastcron) > $timenow) {
655   - mtrace("blocked");
656   - return;
657   - }
658   - set_config('an_lastcron', $timenow, 'enrol/authorize');
659   -
660   - mtrace(" $ordercount orders are being processed now", ": ");
661   -
662   - $faults = '';
663   - $sendem = array();
664   - $elapsed = time();
665   - @set_time_limit(0);
666   - $this->log = "AUTHORIZE.NET AUTOCAPTURE CRON: " . userdate($timenow) . "\n";
667   -
668   - $lastcourseid = 0;
669   - $rs = $DB->get_recordset_select('enrol_authorize', $select, $params, 'courseid');
670   - foreach ( $rs as $order)
671   - {
672   - $message = '';
673   - $extra = NULL;
674   - if (AN_APPROVED == AuthorizeNet::process($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) {
675   - if ($lastcourseid != $order->courseid) {
676   - $lastcourseid = $order->courseid;
677   - $course = $DB->get_record('course', array('id'=>$lastcourseid));
678   - $role = get_default_course_role($course);
679   - $context = get_context_instance(CONTEXT_COURSE, $lastcourseid);
680   - }
681   - $timestart = $timeend = 0;
682   - if ($course->enrolperiod) {
683   - $timestart = $timenow;
684   - $timeend = $order->settletime + $course->enrolperiod;
685   - }
686   - $user = $DB->get_record('user', array('id'=>$order->userid));
687   - // TODO: do some real enrolment here
688   - if (role_assign($role->id, $user->id, $context->id, 'enrol_authorize')) {
689   - $this->log .= "User($user->id) has been enrolled to course($course->id).\n";
690   - if (!empty($CFG->enrol_mailstudents)) {
691   - $sendem[] = $order->id;
692   - }
693   - }
694   - else {
695   - $faults .= "Error while trying to enrol ".fullname($user)." in '$course->fullname' \n";
696   - foreach ($order as $okey => $ovalue) {
697   - $faults .= " $okey = $ovalue\n";
698   - }
699   - }
700   - }
701   - else {
702   - $this->log .= "Error, Order# $order->id: " . $message . "\n";
703   - }
704   - }
705   - $rs->close();
706   - mtrace("processed");
707   -
708   - $timenow = time();
709   - $elapsed = $timenow - $elapsed;
710   - $eachconn = ceil($elapsed / $ordercount);
711   - set_config('an_eachconnsecs', $eachconn, 'enrol/authorize');
712   -
713   - $this->log .= "AUTHORIZE.NET CRON FINISHED: " . userdate($timenow);
714   -
715   - $adminuser = get_admin();
716   - if (!empty($faults)) {
717   - $eventdata = new object();
718   - $eventdata->modulename = 'moodle';
719   - $eventdata->userfrom = $adminuser;
720   - $eventdata->userto = $adminuser;
721   - $eventdata->subject = "AUTHORIZE.NET CRON FAULTS";
722   - $eventdata->fullmessage = $faults;
723   - $eventdata->fullmessageformat = FORMAT_PLAIN;
724   - $eventdata->fullmessagehtml = '';
725   - $eventdata->smallmessage = '';
726   - message_send($eventdata);
727   - }
728   - if (!empty($CFG->enrol_mailadmins)) {
729   - $eventdata = new object();
730   - $eventdata->modulename = 'moodle';
731   - $eventdata->userfrom = $adminuser;
732   - $eventdata->userto = $adminuser;
733   - $eventdata->subject = "AUTHORIZE.NET CRON LOG";
734   - $eventdata->fullmessage = $this->log;
735   - $eventdata->fullmessageformat = FORMAT_PLAIN;
736   - $eventdata->fullmessagehtml = '';
737   - $eventdata->smallmessage = '';
738   - message_send($eventdata);
739   - }
740   -
741   - // Send emails to students about which courses have enrolled.
742   - if (!empty($sendem)) {
743   - mtrace(" sending welcome messages to students", ": ");
744   - send_welcome_messages($sendem);
745   - mtrace("sent");
746   - }
747   - }
748   -
749   - /**
750   - * Daily cron. It executes at settlement time (default is 00:05).
751   - *
752   - * @access private
753   - */
754   - private function cron_daily()
755   - {
756   - global $CFG, $SITE, $DB;
757   -
758   - $oneday = 86400;
759   - $timenow = time();
760   - $onepass = $timenow - $oneday;
761   - $settlementtime = AuthorizeNet::getsettletime($timenow);
762   - $timediff30 = $settlementtime - (30 * $oneday);
763   -
764   - $select = "(status=?) AND (timecreated<?)";
765   - $params = array(AN_STATUS_NONE, $timediff30);
766   - if ($DB->delete_records_select('enrol_authorize', $select, $params)) {
767   - mtrace(" orders no transaction made have deleted");
768   - }
769   -
770   - $select = "(status=?) AND (timecreated<?)";
771   - $params = array(AN_STATUS_EXPIRE, AN_STATUS_AUTH, $timediff30);
772   - if ($DB->execute("UPDATE {enrol_authorize} SET status=? WHERE $select", $params)) {
773   - mtrace(" pending orders to expire have updated");
774   - }
775   -
776   - $timediff60 = $settlementtime - (60 * $oneday);
777   - $select = "(status=?) AND (timecreated<?)";
778   - $params = array(AN_STATUS_EXPIRE, $timediff60);
779   - if ($DB->delete_records_select('enrol_authorize', $select, $params)) {
780   - mtrace(" orders expired older than 60 days have deleted");
781   - }
782   -
783   - $adminuser = get_admin();
784   - $select = "status IN(?,?) AND (timecreated<?) AND (timecreated>?)";
785   - $params = array(AN_STATUS_UNDERREVIEW, AN_STATUS_APPROVEDREVIEW, $onepass, $timediff60);
786   - if (($count = $DB->count_records_select('enrol_authorize', $select, $params)) &&
787   - ($csvusers = get_users_by_capability(get_context_instance(CONTEXT_SYSTEM), 'enrol/authorize:uploadcsv'))) {
788   - $a = new stdClass;
789   - $a->count = $count;
790   - $a->course = $SITE->shortname;
791   - $subject = get_string('pendingechecksubject', 'enrol_authorize', $a);
792   - $a = new stdClass;
793   - $a->count = $count;
794   - $a->url = $CFG->wwwroot.'/enrol/authorize/uploadcsv.php';
795   - $message = get_string('pendingecheckemail', 'enrol_authorize', $a);
796   - foreach($csvusers as $csvuser) {
797   - $eventdata = new object();
798   - $eventdata->modulename = 'moodle';
799   - $eventdata->userfrom = $adminuser;
800   - $eventdata->userto = $csvuser;
801   - $eventdata->subject = $subject;
802   - $eventdata->fullmessage = $message;
803   - $eventdata->fullmessageformat = FORMAT_PLAIN;
804   - $eventdata->fullmessagehtml = '';
805   - $eventdata->smallmessage = '';
806   - message_send($eventdata);
807   - }
808   - mtrace(" users who have 'enrol/authorize:uploadcsv' were mailed");
809   - }
810   -
811   - mtrace(" early pending order warning email for manual capture", ": ");
812   - if (empty($CFG->an_emailexpired)) {
813   - mtrace("not enabled");
814   - return;
815   - }
816   -
817   -
818   - $timediffem = $settlementtime - ((30 - intval($CFG->an_emailexpired)) * $oneday);
819   - $select = "(status=?) AND (timecreated<?) AND (timecreated>?)";
820   - $params = array(AN_STATUS_AUTH, $timediffem, $timediff30);
821   - $count = $DB->count_records_select('enrol_authorize', $select, $params);
822   - if (!$count) {
823   - mtrace("no orders prior to $CFG->an_emailexpired days");
824   - return;
825   - }
826   -
827   - mtrace("$count orders prior to $CFG->an_emailexpired days");
828   - $a = new stdClass;
829   - $a->pending = $count;
830   - $a->days = $CFG->an_emailexpired;
831   - $a->course = $SITE->shortname;
832   - $subject = get_string('pendingorderssubject', 'enrol_authorize', $a);
833   - $a = new stdClass;
834   - $a->pending = $count;
835   - $a->days = $CFG->an_emailexpired;
836   - $a->course = $SITE->fullname;
837   - $a->enrolurl = "$CFG->wwwroot/$CFG->admin/enrol_config.php?enrol=authorize";
838   - $a->url = $CFG->wwwroot.'/enrol/authorize/index.php?status='.AN_STATUS_AUTH;
839   - $message = get_string('pendingordersemail', 'enrol_authorize', $a);
840   -
841   - $eventdata = new object();
842   - $eventdata->modulename = 'moodle';
843   - $eventdata->userfrom = $adminuser;
844   - $eventdata->userto = $adminuser;
845   - $eventdata->subject = $subject;
846   - $eventdata->fullmessage = $message;
847   - $eventdata->fullmessageformat = FORMAT_PLAIN;
848   - $eventdata->fullmessagehtml = '';
849   - $eventdata->smallmessage = '';
850   - message_send($eventdata);
851   -
852   - // Email to payment managers
853   - if (empty($CFG->an_emailexpiredteacher)) {
854   - return; // email feature disabled for teachers.
855   - }
856   -
857   - $sorttype = empty($CFG->an_sorttype) ? 'ttl' : $CFG->an_sorttype;
858   - $sql = "SELECT e.courseid, e.currency, c.fullname, c.shortname,
859   - COUNT(e.courseid) AS cnt, SUM(e.amount) as ttl
860   - FROM {enrol_authorize} e
861   - INNER JOIN {course} c ON c.id = e.courseid
862   - WHERE (e.status = ?)
863   - AND (e.timecreated < ?)
864   - AND (e.timecreated > ?)
865   - GROUP BY e.courseid
866   - ORDER BY $sorttype DESC";
867   - $params = array(AN_STATUS_AUTH, $timediffem, $timediff30);
868   -
869   - $rs = $DB->get_recordset_sql($sql, $params);
870   - foreach ($rs as $courseinfo)
871   - {
872   - $lastcourse = $courseinfo->courseid;
873   - $context = get_context_instance(CONTEXT_COURSE, $lastcourse);
874   - if (($paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments'))) {
875   - $a = new stdClass;
876   - $a->course = $courseinfo->shortname;
877   - $a->pending = $courseinfo->cnt;
878   - $a->days = $CFG->an_emailexpired;
879   - $subject = get_string('pendingorderssubject', 'enrol_authorize', $a);
880   - $a = new stdClass;
881   - $a->course = $courseinfo->fullname;
882   - $a->pending = $courseinfo->cnt;
883   - $a->currency = $courseinfo->currency;
884   - $a->sumcost = $courseinfo->ttl;
885   - $a->days = $CFG->an_emailexpired;
886   - $a->url = $CFG->wwwroot.'/enrol/authorize/index.php?course='.$lastcourse.'&amp;status='.AN_STATUS_AUTH;
887   - $message = get_string('pendingordersemailteacher', 'enrol_authorize', $a);
888   - foreach ($paymentmanagers as $paymentmanager) {
889   - $eventdata = new object();
890   - $eventdata->modulename = 'moodle';
891   - $eventdata->userfrom = $adminuser;
892   - $eventdata->userto = $paymentmanager;
893   - $eventdata->subject = $subject;
894   - $eventdata->fullmessage = $message;
895   - $eventdata->fullmessageformat = FORMAT_PLAIN;
896   - $eventdata->fullmessagehtml = '';
897   - $eventdata->smallmessage = '';
898   - message_send($eventdata);
899   - }
900   - }
901   - }
902   - $rs->close();
903   - }
904   -}
905   -

0 comments on commit 0b66f4e

Please sign in to comment.
Something went wrong with that request. Please try again.