From c06a812ed65c8d9aea9701211fd9f91844eca247 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Fri, 5 Jul 2013 14:11:47 +0800 Subject: [PATCH 1/3] MDL-28466 Remove enrol_authorize - this code is dead It does not work and its not maintained. --- enrol/authorize/authorize.js | 5 - enrol/authorize/authorizenet.class.php | 433 ------------ enrol/authorize/const.php | 92 --- enrol/authorize/db/access.php | 83 --- enrol/authorize/db/install.xml | 51 -- enrol/authorize/db/messages.php | 29 - enrol/authorize/db/upgrade.php | 45 -- enrol/authorize/enrol_form.php | 358 ---------- enrol/authorize/import_form.php | 40 -- enrol/authorize/index.php | 78 --- enrol/authorize/lang/en/enrol_authorize.php | 271 -------- enrol/authorize/localfuncs.php | 314 --------- enrol/authorize/locallib.php | 728 -------------------- enrol/authorize/uploadcsv.php | 265 ------- enrol/authorize/version.php | 31 - 15 files changed, 2823 deletions(-) delete mode 100644 enrol/authorize/authorize.js delete mode 100644 enrol/authorize/authorizenet.class.php delete mode 100644 enrol/authorize/const.php delete mode 100644 enrol/authorize/db/access.php delete mode 100644 enrol/authorize/db/install.xml delete mode 100644 enrol/authorize/db/messages.php delete mode 100644 enrol/authorize/db/upgrade.php delete mode 100644 enrol/authorize/enrol_form.php delete mode 100644 enrol/authorize/import_form.php delete mode 100644 enrol/authorize/index.php delete mode 100644 enrol/authorize/lang/en/enrol_authorize.php delete mode 100644 enrol/authorize/localfuncs.php delete mode 100644 enrol/authorize/locallib.php delete mode 100644 enrol/authorize/uploadcsv.php delete mode 100644 enrol/authorize/version.php diff --git a/enrol/authorize/authorize.js b/enrol/authorize/authorize.js deleted file mode 100644 index fe8139ae37d..00000000000 --- a/enrol/authorize/authorize.js +++ /dev/null @@ -1,5 +0,0 @@ -function authorize_jump_to_mypayments(e, args) { - var locationtogo = M.cfg.wwwroot + '/enrol/authorize/index.php?status=' + args.status; - locationtogo += '&user=' + (this.checked ? args.userid : '0'); - top.location.href = locationtogo; -} diff --git a/enrol/authorize/authorizenet.class.php b/enrol/authorize/authorizenet.class.php deleted file mode 100644 index 299eda081d4..00000000000 --- a/enrol/authorize/authorizenet.class.php +++ /dev/null @@ -1,433 +0,0 @@ -. - -/** - * Authorize enrolment plugin. - * - * This plugin allows you to set up paid courses, using authorize.net. - * - * @package enrol_authorize - * @copyright 2010 Eugene Venter - * @author Eugene Venter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -if (!defined('MOODLE_INTERNAL')) { - die('Direct access to this script is forbidden.'); -} - -require_once($CFG->dirroot.'/enrol/authorize/const.php'); -require_once($CFG->dirroot.'/enrol/authorize/localfuncs.php'); - -class AuthorizeNet -{ - const AN_DELIM = '|'; - const AN_ENCAP = '"'; - - const AN_REASON_NOCCTYPE = 17; - const AN_REASON_NOCCTYPE2 = 28; - const AN_REASON_NOACH = 18; - const AN_REASON_ACHONLY = 56; - const AN_REASON_NOACHTYPE = 245; - const AN_REASON_NOACHTYPE2 = 246; - - /** - * Gets settlement time - * - * @param int $time Time processed, usually now. - * @return int Settlement time - */ - public static function getsettletime($time) - { - $mconfig = get_config('enrol_authorize'); - - $cutoff_hour = intval($mconfig->an_cutoff_min); - $cutoff_min = intval($mconfig->an_cutoff_hour); - $cutofftime = strtotime("{$cutoff_hour}:{$cutoff_min}", $time); - if ($cutofftime < $time) { - $cutofftime = strtotime("{$cutoff_hour}:{$cutoff_min}", $time + (24 * 3600)); - } - return $cutofftime; - } - - /** - * Is order settled? Status must be auth_captured or credited. - * - * @param object $order Order details - * @return bool true, if settled, false otherwise. - */ - public static function settled($order) - { - return ((AN_STATUS_AUTHCAPTURE == $order->status || AN_STATUS_CREDIT == $order->status) and ($order->settletime > 0) and ($order->settletime < time())); - } - - /** - * Is order expired? 'Authorized/Pending Capture' transactions are expired after 30 days. - * - * @param object &$order Order details. - * @return bool true, transaction is expired, false otherwise. - */ - public static function expired(&$order) - { - global $DB; - static $timediff30 = 0; - - if ($order->status == AN_STATUS_EXPIRE) { - return true; - } - elseif ($order->status != AN_STATUS_AUTH) { - return false; - } - - if (0 == $timediff30) { - $timediff30 = self::getsettletime(time()) - (30 * 24 * 3600); - } - - $expired = self::getsettletime($order->timecreated) < $timediff30; - if ($expired) - { - $order->status = AN_STATUS_EXPIRE; - $DB->update_record('enrol_authorize', $order); - } - return $expired; - } - - /** - * Performs an action on authorize.net and updates/inserts records. If record update fails, - * sends email to admin. - * - * @param object &$order Which transaction data will be sent. See enrol_authorize table. - * @param string &$message Information about error message. - * @param object &$extra Extra data that used for refunding and credit card information. - * @param int $action Which action will be performed. See AN_ACTION_* - * @param string $cctype Used internally to configure credit types automatically. - * @return int AN_APPROVED Transaction was successful, AN_RETURNZERO otherwise. Use $message for reason. - */ - public static function process(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $cctype=NULL) - { - global $CFG, $DB; - static $constpd = array(); - require_once($CFG->libdir.'/filelib.php'); - - $mconfig = get_config('enrol_authorize'); - - if (empty($constpd)) { - $mconfig = get_config('enrol_authorize'); - $constpd = array( - 'x_version' => '3.1', - 'x_delim_data' => 'True', - 'x_delim_char' => self::AN_DELIM, - 'x_encap_char' => self::AN_ENCAP, - 'x_relay_response' => 'FALSE', - 'x_login' => $mconfig->an_login - ); - - if (!empty($mconfig->an_tran_key)) { - $constpd['x_tran_key'] = $mconfig->an_tran_key; - } - else { - $constpd['x_password'] = $mconfig->an_password; - } - } - - if (empty($order) or empty($order->id)) { - $message = "Check order->id!"; - return AN_RETURNZERO; - } - - $method = $order->paymentmethod; - if (empty($method)) { - $method = AN_METHOD_CC; - } - elseif ($method != AN_METHOD_CC && $method != AN_METHOD_ECHECK) { - $message = "Invalid method: $method"; - return AN_RETURNZERO; - } - - $action = intval($action); - if ($method == AN_METHOD_ECHECK) { - if ($action != AN_ACTION_AUTH_CAPTURE && $action != AN_ACTION_CREDIT) { - $message = "Please perform AUTH_CAPTURE or CREDIT for echecks"; - return AN_RETURNZERO; - } - } - - $pd = $constpd; - $pd['x_method'] = $method; - $test = !empty($mconfig->an_test); - $pd['x_test_request'] = ($test ? 'TRUE' : 'FALSE'); - - switch ($action) { - case AN_ACTION_AUTH_ONLY: - case AN_ACTION_CAPTURE_ONLY: - case AN_ACTION_AUTH_CAPTURE: - { - if ($order->status != AN_STATUS_NONE) { - $message = "Order status must be AN_STATUS_NONE(0)!"; - return AN_RETURNZERO; - } - elseif (empty($extra)) { - $message = "Need extra fields!"; - return AN_RETURNZERO; - } - elseif (($action == AN_ACTION_CAPTURE_ONLY) and empty($extra->x_auth_code)) { - $message = "x_auth_code is required for capture only transactions!"; - return AN_RETURNZERO; - } - - $ext = (array)$extra; - $pd['x_type'] = (($action==AN_ACTION_AUTH_ONLY) - ? 'AUTH_ONLY' :( ($action==AN_ACTION_CAPTURE_ONLY) - ? 'CAPTURE_ONLY' : 'AUTH_CAPTURE')); - foreach($ext as $k => $v) { - $pd[$k] = $v; - } - } - break; - - case AN_ACTION_PRIOR_AUTH_CAPTURE: - { - if ($order->status != AN_STATUS_AUTH) { - $message = "Order status must be authorized!"; - return AN_RETURNZERO; - } - if (self::expired($order)) { - $message = "Transaction must be captured within 30 days. EXPIRED!"; - return AN_RETURNZERO; - } - $pd['x_type'] = 'PRIOR_AUTH_CAPTURE'; - $pd['x_trans_id'] = $order->transid; - } - break; - - case AN_ACTION_CREDIT: - { - if ($order->status != AN_STATUS_AUTHCAPTURE) { - $message = "Order status must be authorized/captured!"; - return AN_RETURNZERO; - } - if (!self::settled($order)) { - $message = "Order must be settled. Try VOID, check Cut-Off time if it fails!"; - return AN_RETURNZERO; - } - if (empty($extra->amount)) { - $message = "No valid amount!"; - return AN_RETURNZERO; - } - $timenowsettle = self::getsettletime(time()); - $timediff = $timenowsettle - (120 * 3600 * 24); - if ($order->settletime < $timediff) { - $message = "Order must be credited within 120 days!"; - return AN_RETURNZERO; - } - - $pd['x_type'] = 'CREDIT'; - $pd['x_trans_id'] = $order->transid; - $pd['x_currency_code'] = $order->currency; - $pd['x_invoice_num'] = $extra->orderid; - $pd['x_amount'] = $extra->amount; - if ($method == AN_METHOD_CC) { - $pd['x_card_num'] = sprintf("%04d", intval($order->refundinfo)); - } - elseif ($method == AN_METHOD_ECHECK && empty($order->refundinfo)) { - $message = "Business checkings can be refunded only."; - return AN_RETURNZERO; - } - } - break; - - case AN_ACTION_VOID: - { - if (self::expired($order) || self::settled($order)) { - $message = "The transaction cannot be voided due to the fact that it is expired or settled."; - return AN_RETURNZERO; - } - $pd['x_type'] = 'VOID'; - $pd['x_trans_id'] = $order->transid; - } - break; - - default: - { - $message = "Invalid action: $action"; - return AN_RETURNZERO; - } - } - - $headers = array('Connection' => 'close'); - if (! (empty($mconfig->an_referer) || $mconfig->an_referer == "http://")) { - $headers['Referer'] = $mconfig->an_referer; - } - - @ignore_user_abort(true); - if (intval(ini_get('max_execution_time')) > 0) { - @set_time_limit(300); - } - - $host = $test ? 'test.authorize.net' : 'secure.authorize.net'; - $data = download_file_content("https://$host:443/gateway/transact.dll", $headers, $pd, false, 300, 60, true); - if (!$data) { - $message = "No connection to https://$host:443"; - return AN_RETURNZERO; - } - $response = explode(self::AN_ENCAP.self::AN_DELIM.self::AN_ENCAP, $data); - if ($response === false) { - $message = "response error"; - return AN_RETURNZERO; - } - $rcount = count($response) - 1; - if ($response[0]{0} == self::AN_ENCAP) { - $response[0] = substr($response[0], 1); - } - if (substr($response[$rcount], -1) == self::AN_ENCAP) { - $response[$rcount] = substr($response[$rcount], 0, -1); - } - - $responsecode = intval($response[0]); - if ($responsecode == AN_APPROVED || $responsecode == AN_REVIEW) - { - $transid = floatval($response[6]); - if ($test || $transid == 0) { - return $responsecode; // don't update original transaction in test mode. - } - switch ($action) { - case AN_ACTION_AUTH_ONLY: - case AN_ACTION_CAPTURE_ONLY: - case AN_ACTION_AUTH_CAPTURE: - case AN_ACTION_PRIOR_AUTH_CAPTURE: - { - $order->transid = $transid; - - if ($method == AN_METHOD_CC) { - if ($action == AN_ACTION_AUTH_ONLY || $responsecode == AN_REVIEW) { - $order->status = AN_STATUS_AUTH; - } else { - $order->status = AN_STATUS_AUTHCAPTURE; - $order->settletime = self::getsettletime(time()); - } - } - elseif ($method == AN_METHOD_ECHECK) { - $order->status = AN_STATUS_UNDERREVIEW; - } - - $DB->update_record('enrol_authorize', $order); - } - break; - - case AN_ACTION_CREDIT: - { - // Credit generates new transaction id. - // So, $extra must be updated, not $order. - $extra->status = AN_STATUS_CREDIT; - $extra->transid = $transid; - $extra->settletime = self::getsettletime(time()); - $extra->id = $DB->insert_record('enrol_authorize_refunds', $extra); - } - break; - - case AN_ACTION_VOID: - { - $tableupdate = 'enrol_authorize'; - if ($order->status == AN_STATUS_CREDIT) { - $tableupdate = 'enrol_authorize_refunds'; - unset($order->paymentmethod); - } - $order->status = AN_STATUS_VOID; - $DB->update_record($tableupdate, $order); - } - break; - } - } - else - { - $reasonno = $response[2]; - $reasonstr = "reason" . $reasonno; - $message = get_string($reasonstr, "enrol_authorize"); - if ($message == '[[' . $reasonstr . ']]') { - $message = isset($response[3]) ? $response[3] : 'unknown error'; - } - if ($method == AN_METHOD_CC && !empty($mconfig->an_avs) && $response[5] != "P") { - $avs = "avs" . strtolower($response[5]); - $stravs = get_string($avs, "enrol_authorize"); - $message .= "
" . get_string("avsresult", "enrol_authorize", $stravs); - } - if (!$test) { // Autoconfigure :) - switch($reasonno) { - // Credit card type isn't accepted - case self::AN_REASON_NOCCTYPE: - case self::AN_REASON_NOCCTYPE2: - { - if (!empty($cctype)) { - $ccaccepts = get_list_of_creditcards(); - - unset($ccaccepts[$cctype]); - set_config("an_acceptcc_{$cctype}", 0, 'enrol_authorize'); - - foreach ($ccaccepts as $key=>$val) { - set_config("an_acceptcc_{$key}", 1, 'enrol_authorize'); - } - message_to_admin("$message ($cctype) This is new config(an_acceptccs):", $ccaccepts); - } - break; - } - // Echecks only - case self::AN_REASON_ACHONLY: - { - set_config("an_acceptmethod_".AN_METHOD_ECHECK, 1, 'enrol_authorize'); - message_to_admin("$message This is new config(an_acceptmethods):", array(AN_METHOD_ECHECK)); - break; - } - // Echecks aren't accepted - case self::AN_REASON_NOACH: - { - set_config("an_acceptmethod_".AN_METHOD_CC, 1, 'enrol_authorize'); - message_to_admin("$message This is new config(an_acceptmethods):", array(AN_METHOD_CC)); - break; - } - // This echeck type isn't accepted - case self::AN_REASON_NOACHTYPE: - case self::AN_REASON_NOACHTYPE2: - { - if (!empty($extra->x_echeck_type)) { - switch ($extra->x_echeck_type) { - // CCD=BUSINESSCHECKING - case 'CCD': - { - set_config('an_acceptecheck_CHECKING', 1, 'enrol_authorize'); - set_config('an_acceptecheck_SAVINGS', 1, 'enrol_authorize'); - message_to_admin("$message This is new config(an_acceptechecktypes):", array('CHECKING','SAVINGS')); - } - break; - // WEB=CHECKING or SAVINGS - case 'WEB': - { - set_config('an_acceptecheck_BUSINESSCHECKING', 1, 'enrol_authorize'); - message_to_admin("$message This is new config(an_acceptechecktypes):", array('BUSINESSCHECKING')); - } - break; - } - } - break; - } - } - } - } - return $responsecode; - } -} - - diff --git a/enrol/authorize/const.php b/enrol/authorize/const.php deleted file mode 100644 index 16030df37dd..00000000000 --- a/enrol/authorize/const.php +++ /dev/null @@ -1,92 +0,0 @@ -. - -/** - * Authorize.Net enrolment plugin capabilities. - * - * @package enrol_authorize - * @copyright 2006 Eugene Venter - * @author Eugene Venter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -$capabilities = array( - - 'enrol/authorize:config' => array( - 'captype' => 'write', - 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'manager' => CAP_ALLOW, - ) - ), - - 'enrol/authorize:manage' => array( - 'captype' => 'write', - 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'manager' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW, - ) - ), - - 'enrol/authorize:unenrol' => array( - 'captype' => 'write', - 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'manager' => CAP_ALLOW, - ) - ), - - 'enrol/authorize:unenrolself' => array( - 'captype' => 'write', - 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - ) - ), - - - 'enrol/authorize:managepayments' => array( - 'riskbitmask' => RISK_PERSONAL, - 'captype' => 'write', - 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array( - 'manager' => CAP_ALLOW - ) - ), - - 'enrol/authorize:uploadcsv' => array( - 'riskbitmask' => RISK_XSS, - 'captype' => 'write', - 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array( - 'manager' => CAP_ALLOW - ) - ) - -); - - diff --git a/enrol/authorize/db/install.xml b/enrol/authorize/db/install.xml deleted file mode 100644 index 39df20ae325..00000000000 --- a/enrol/authorize/db/install.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
-
-
\ No newline at end of file diff --git a/enrol/authorize/db/messages.php b/enrol/authorize/db/messages.php deleted file mode 100644 index 8d3df01ea28..00000000000 --- a/enrol/authorize/db/messages.php +++ /dev/null @@ -1,29 +0,0 @@ -. - -/** - * Defines message providers (types of message sent) for the PayPal enrolment plugin. - * - * @package enrol_authorize - * @copyright 2012 Andrew Davis - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -$messageproviders = array( - 'authorize_enrolment' => array(), -); diff --git a/enrol/authorize/db/upgrade.php b/enrol/authorize/db/upgrade.php deleted file mode 100644 index adbb27db4b2..00000000000 --- a/enrol/authorize/db/upgrade.php +++ /dev/null @@ -1,45 +0,0 @@ -. - -/** - * Authorize.Net enrolment plugin upgrades. - * - * @package enrol_authorize - * @copyright 2006 Eugene Venter - * @author Eugene Venter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -function xmldb_enrol_authorize_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - return true; -} diff --git a/enrol/authorize/enrol_form.php b/enrol/authorize/enrol_form.php deleted file mode 100644 index 49136dae50d..00000000000 --- a/enrol/authorize/enrol_form.php +++ /dev/null @@ -1,358 +0,0 @@ -. - -/** - * Authorize.Net enrol plugin implementation. - * - * @package enrol_authorize - * @copyright 2010 Eugene Venter - * @author Eugene Venter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir.'/formslib.php'); - -class enrol_authorize_form extends moodleform -{ - protected $instance; - - function definition() { - global $USER; - - $mform = $this->_form; - $this->instance = $this->_customdata; - $plugin = enrol_get_plugin('authorize'); - - $paymentmethodsenabled = get_list_of_payment_methods(); - $paymentmethod = optional_param('paymentmethod', $paymentmethodsenabled[0], PARAM_ALPHA); - if (!in_array($paymentmethod, $paymentmethodsenabled)) { - print_error('invalidpaymentmethod', '', '', $paymentmethod); - } - - $othermethodstr = $this->other_method_available($paymentmethod); - if ($othermethodstr) { - $mform->addElement('static', '', '
' . $othermethodstr . '
', ''); - } - - $mform->addElement('hidden', 'id'); - $mform->setType('id', PARAM_INT); - $mform->setDefault('id', $this->instance->courseid); - - $mform->addElement('hidden', 'instanceid'); - $mform->setType('instanceid', PARAM_INT); - $mform->setDefault('instanceid', $this->instance->id); - - $mform->addElement('hidden', 'paymentmethod', $paymentmethod); - $mform->setType('paymentmethod', PARAM_ALPHA); - - $firstlastnamestr = (AN_METHOD_CC == $paymentmethod) ? get_string('nameoncard', 'enrol_authorize') : get_string('echeckfirslasttname', 'enrol_authorize'); - $mform->addElement('text', 'firstname', get_string('firstnameoncard', 'enrol_authorize'), 'size="16"'); - $mform->addElement('text', 'lastname', get_string('lastnameoncard', 'enrol_authorize'), 'size="16"'); - $mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'client'); - $mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'client'); - $mform->setType('firstname', PARAM_ALPHANUM); - $mform->setType('lastname', PARAM_ALPHANUM); - $mform->setDefault('firstname', $USER->firstname); - $mform->setDefault('lastname', $USER->lastname); - - if (AN_METHOD_CC == $paymentmethod) - { - $mform->addElement('passwordunmask', 'cc', get_string('ccno', 'enrol_authorize'), 'size="20"'); - $mform->setType('cc', PARAM_ALPHANUM); - $mform->setDefault('cc', ''); - $mform->addRule('cc', get_string('missingcc', 'enrol_authorize'), 'required', null, 'client'); - $mform->addRule('cc', get_string('ccinvalid', 'enrol_authorize'), 'numeric', null, 'client'); - - $monthsmenu = array('' => get_string('choose')); - for ($i = 1; $i <= 12; $i++) { - $monthsmenu[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), "%B"); - } - $nowdate = getdate(); - $startyear = $nowdate["year"] - 1; - $endyear = $startyear + 20; - $yearsmenu = array('' => get_string('choose')); - for ($i = $startyear; $i < $endyear; $i++) { - $yearsmenu[$i] = $i; - } - $mform->addElement('select', 'ccexpiremm', get_string('expiremonth', 'enrol_authorize'), $monthsmenu); - $mform->addElement('select', 'ccexpireyyyy', get_string('expireyear', 'enrol_authorize'), $yearsmenu); - $mform->addRule('ccexpiremm', get_string('missingccexpiremonth', 'enrol_authorize'), 'required', null, 'client'); - $mform->addRule('ccexpireyyyy', get_string('missingccexpireyear', 'enrol_authorize'), 'required', null, 'client'); - $mform->setType('ccexpiremm', PARAM_INT); - $mform->setType('ccexpireyyyy', PARAM_INT); - $mform->setDefault('ccexpiremm', ''); - $mform->setDefault('ccexpireyyyy', ''); - - $creditcardsmenu = array('' => get_string('choose')) + get_list_of_creditcards(); - $mform->addElement('select', 'cctype', get_string('cctype', 'enrol_authorize'), $creditcardsmenu); - $mform->setType('cctype', PARAM_ALPHA); - $mform->addRule('cctype', get_string('missingcctype', 'enrol_authorize'), 'required', null, 'client'); - $mform->setDefault('cctype', ''); - - $mform->addElement('text', 'cvv', get_string('ccvv', 'enrol_authorize'), 'size="4"'); - $mform->setType('cvv', PARAM_ALPHANUM); - $mform->setDefault('cvv', ''); - $mform->addRule('cvv', get_string('missingcvv', 'enrol_authorize'), 'required', null, 'client'); - $mform->addRule('cvv', get_string('missingcvv', 'enrol_authorize'), 'numeric', null, 'client'); - - if ($plugin->get_config('an_authcode')) { - $ccauthgrp = array(); - $ccauthgrp[] = &$mform->createElement('checkbox', 'haveauth', null, get_string('haveauthcode', 'enrol_authorize')); - $ccauthgrp[] = &$mform->createElement('static', 'nextline', null, '
'); - $ccauthgrp[] = &$mform->createElement('text', 'ccauthcode', '', 'size="8"'); - $mform->addGroup($ccauthgrp, 'ccauthgrp', get_string('authcode', 'enrol_authorize'), ' ', false); - - $ccauthgrprules = array(); - $ccauthgrprules['ccauthcode'][] = array(get_string('missingccauthcode', 'enrol_authorize'), 'numeric', null, 'client'); - $mform->addGroupRule('ccauthgrp', $ccauthgrprules); - $mform->setDefault('haveauth', ''); - $mform->setDefault('ccauthcode', ''); - } - - if ($plugin->get_config('an_avs')) { - $mform->addElement('header', 'addressheader', '  ' . get_string('address'), ''); - - $mform->addElement('text', 'ccaddress', get_string('address'), 'size="30"'); - $mform->setType('ccaddress', PARAM_ALPHANUM); - $mform->setDefault('ccaddress', $USER->address); - $mform->addRule('ccaddress', get_string('missingaddress', 'enrol_authorize'), 'required', null, 'client'); - - $mform->addElement('text', 'cccity', get_string('cccity', 'enrol_authorize'), 'size="14"'); - $mform->addElement('text', 'ccstate', get_string('ccstate', 'enrol_authorize'), 'size="8"'); - $mform->addRule('cccity', get_string('missingcity'), 'required', null, 'client'); - $mform->setType('cccity', PARAM_ALPHANUM); - $mform->setType('ccstate', PARAM_ALPHANUM); - $mform->setDefault('cccity', $USER->city); - $mform->setDefault('ccstate', ''); - - $mform->addElement('select', 'cccountry', get_string('country'), get_string_manager()->get_list_of_countries()); - $mform->addRule('cccountry', get_string('missingcountry'), 'required', null, 'client'); - $mform->setType('cccountry', PARAM_ALPHA); - $mform->setDefault('cccountry', $USER->country); - } - else { - $mform->addElement('hidden', 'ccstate', ''); - $mform->setType('ccstate', PARAM_ALPHANUM); - $mform->addElement('hidden', 'ccaddress', $USER->address); - $mform->setType('ccaddress', PARAM_ALPHANUM); - $mform->addElement('hidden', 'cccity', $USER->city); - $mform->setType('cccity', PARAM_ALPHANUM); - $mform->addElement('hidden', 'cccountry', $USER->country); - $mform->setType('ccountry', PARAM_ALPHA); - $mform->setDefault('cccountry', $USER->country); - } - } elseif (AN_METHOD_ECHECK == $paymentmethod) { - $mform->addElement('text', 'abacode', get_string('echeckabacode', 'enrol_authorize'), 'size="9" maxlength="9"'); - $mform->setType('abacode', PARAM_ALPHANUM); - $mform->setDefault('abacode', ''); - $mform->addRule('abacode', get_string('missingaba', 'enrol_authorize'), 'required', null, 'client'); - $mform->addRule('abacode', get_string('missingaba', 'enrol_authorize'), 'numeric', null, 'client'); - - $mform->addElement('text', 'accnum', get_string('echeckaccnum', 'enrol_authorize'), 'size="20" maxlength="20"'); - $mform->setType('accnum', PARAM_ALPHANUM); - $mform->setDefault('accnum', ''); - $mform->addRule('accnum', get_string('invalidaccnum', 'enrol_authorize'), 'required', null, 'client'); - $mform->addRule('accnum', get_string('invalidaccnum', 'enrol_authorize'), 'numeric', null, 'client'); - - $acctypes = array(); - $acctypesenabled = get_list_of_bank_account_types(); - foreach ($acctypesenabled as $key) { - $acctypes[$key] = get_string("echeck".strtolower($key), "enrol_authorize"); - } - $acctypes = array('' => get_string('choose')) + $acctypes; - $mform->addElement('select', 'acctype', get_string('echeckacctype', 'enrol_authorize'), $acctypes); - $mform->setType('acctype', PARAM_ALPHA); - $mform->addRule('acctype', get_string('invalidacctype', 'enrol_authorize'), 'required', null, 'client'); - $mform->setDefault('acctype', ''); - - $mform->addElement('text', 'bankname', get_string('echeckbankname', 'enrol_authorize'), 'size="20" maxlength="50"'); - $mform->setType('bankname', PARAM_ALPHANUM); - $mform->setDefault('bankname', ''); - $mform->addRule('bankname', get_string('missingbankname', 'enrol_authorize'), 'required', null, 'client'); - } - - $mform->addElement('text', 'cczip', get_string('zipcode', 'enrol_authorize'), 'size="5"'); - $mform->setType('cczip', PARAM_ALPHANUM); - $mform->setDefault('cczip', ''); - $mform->addRule('cczip', get_string('missingzip', 'enrol_authorize'), 'required', null, 'client'); - - $this->add_action_buttons(false, get_string('sendpaymentbutton', 'enrol_authorize')); - } - - function validation($data, $files) { - $errors = parent::validation($data, $files); - $plugin = enrol_get_plugin('authorize'); - - if (AN_METHOD_CC == $data['paymentmethod']) - { - if (!in_array($data['cctype'], array_keys(get_list_of_creditcards()))) { - $errors['cctype'] = get_string('missingcctype', 'enrol_authorize'); - } - - $expdate = sprintf("%02d", intval($data['ccexpiremm'])) . $data['ccexpireyyyy']; - $validcc = $this->validate_cc($data['cc'], $data['cctype'], $expdate); - if (!$validcc) { - if ($validcc === 0) { - $errors['ccexpiremm'] = get_string('ccexpired', 'enrol_authorize'); - } - else { - $errors['cc'] = get_string('ccinvalid', 'enrol_authorize'); - } - } - - if ($plugin->get_config('an_authcode') && !empty($data['haveauth']) && empty($data['ccauthcode'])) { - $errors['ccauthgrp'] = get_string('missingccauthcode', 'enrol_authorize'); - } - } - elseif (AN_METHOD_ECHECK == $data['paymentmethod']) - { - if (!$this->validate_aba($data['abacode'])) { - $errors['abacode'] = get_string('invalidaba', 'enrol_authorize'); - } - - if (!in_array($data['acctype'], get_list_of_bank_account_types())) { - $errors['acctype'] = get_string('invalidacctype', 'enrol_authorize'); - } - } - - return $errors; - } - - private function other_method_available($currentmethod) - { - - if ($currentmethod == AN_METHOD_CC) { - $otheravailable = in_array(AN_METHOD_ECHECK, get_list_of_payment_methods()); - $url = 'index.php?id='.$this->instance->courseid.'&paymentmethod='.AN_METHOD_ECHECK; - $stringtofetch = 'usingecheckmethod'; - } else { - $otheravailable = in_array(AN_METHOD_CC, get_list_of_payment_methods()); - $url = 'index.php?id='.$this->instance->courseid.'&paymentmethod='.AN_METHOD_CC; - $stringtofetch = 'usingccmethod'; - } - if ($otheravailable) { - $a = new stdClass; - $a->url = $url; - return get_string($stringtofetch, "enrol_authorize", $a); - } - else { - return ''; - } - } - - private function validate_aba($aba) - { - if (preg_match("/^[0-9]{9}$/", $aba)) { - $n = 0; - for($i = 0; $i < 9; $i += 3) { - $n += (substr($aba, $i, 1) * 3) + (substr($aba, $i + 1, 1) * 7) + (substr($aba, $i + 2, 1)); - } - if ($n != 0 and $n % 10 == 0) { - return true; - } - } - return false; - } - - private function validate_cc($Num, $Name = "n/a", $Exp = "") - { - // Check the expiration date first - if (strlen($Exp)) - { - $Month = substr($Exp, 0, 2); - $Year = substr($Exp, -2); - $WorkDate = "$Month/01/$Year"; - $WorkDate = strtotime($WorkDate); - $LastDay = date("t", $WorkDate); - $Expires = strtotime("$Month/$LastDay/$Year 11:59:59"); - if ($Expires < time()) return 0; - } - - // Innocent until proven guilty - $GoodCard = true; - - // Get rid of any non-digits - $Num = preg_replace("/[^0-9]~/", "", $Num); - - // Perform card-specific checks, if applicable - switch ($Name) - { - case "mcd" : - $GoodCard = preg_match("/^5[1-5].{14}$/", $Num); - break; - - case "vis" : - $GoodCard = preg_match("/^4.{15}$|^4.{12}$/", $Num); - break; - - case "amx" : - $GoodCard = preg_match("/^3[47].{13}$/", $Num); - break; - - case "dsc" : - $GoodCard = preg_match("/^6011.{12}$/", $Num); - break; - - case "dnc" : - $GoodCard = preg_match("/^30[0-5].{11}$|^3[68].{12}$/", $Num); - break; - - case "jcb" : - $GoodCard = preg_match("/^3.{15}$|^2131|1800.{11}$/", $Num); - break; - - case "dlt" : - $GoodCard = preg_match("/^4.{15}$/", $Num); - break; - - case "swi" : - $GoodCard = preg_match("/^[456].{15}$|^[456].{17,18}$/", $Num); - break; - - case "enr" : - $GoodCard = preg_match("/^2014.{11}$|^2149.{11}$/", $Num); - break; - } - - // The Luhn formula works right to left, so reverse the number. - $Num = strrev($Num); - $Total = 0; - - for ($x=0; $x < strlen($Num); $x++) - { - $digit = substr($Num, $x, 1); - - // If it's an odd digit, double it - if ($x/2 != floor($x/2)) { - $digit *= 2; - - // If the result is two digits, add them - if (strlen($digit) == 2) - $digit = substr($digit, 0, 1) + substr($digit, 1, 1); - } - // Add the current digit, doubled and added if applicable, to the Total - $Total += $digit; - } - - // If it passed (or bypassed) the card-specific check and the Total is - // evenly divisible by 10, it's cool! - return ($GoodCard && $Total % 10 == 0); - } - -} - diff --git a/enrol/authorize/import_form.php b/enrol/authorize/import_form.php deleted file mode 100644 index 91484aa0e52..00000000000 --- a/enrol/authorize/import_form.php +++ /dev/null @@ -1,40 +0,0 @@ -. - -/** - * Adds new instance of enrol_authorize to specified course - * or edits current instance. - * - * @package enrol_authorize - * @copyright 2010 Eugene Venter - * @author Eugene Venter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -require_once($CFG->libdir.'/formslib.php'); - -class enrol_authorize_import_form extends moodleform { - - function definition() { - global $CFG; - $mform =& $this->_form; - - $mform->addElement('filepicker', 'csvfile', get_string('filetoimport', 'glossary')); - $submit_string = get_string('submit'); - $this->add_action_buttons(false, $submit_string); - } -} diff --git a/enrol/authorize/index.php b/enrol/authorize/index.php deleted file mode 100644 index f888a9e2483..00000000000 --- a/enrol/authorize/index.php +++ /dev/null @@ -1,78 +0,0 @@ -. - -/** - * Adds new instance of enrol_authorize to specified course - * or edits current instance. - * - * @package enrol_authorize - * @copyright 2010 Eugene Venter - * @author Eugene Venter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -/// Load libraries - require_once('../../config.php'); - require_once('const.php'); - require_once('locallib.php'); - require_once('localfuncs.php'); - require_once('authorizenet.class.php'); - -/// Parameters - $orderid = optional_param('order', 0, PARAM_INT); - $courseid = optional_param('course', SITEID, PARAM_INT); - $userid = optional_param('user', 0, PARAM_INT); - - $url = new moodle_url('/enrol/authorize/index.php'); - if ($orderid !== 0) { - $url->param('order', $orderid); - } - if ($courseid !== SITEID) { - $url->param('course', $courseid); - } - if ($userid !== 0) { - $url->param('user', $userid); - } - $PAGE->set_url($url); - -/// Get course - if (!($course = $DB->get_record('course', array('id'=>$courseid)))) { - print_error('invalidcourseid'); - } - -/// Only SITE users can access to this page - require_login(); // Don't use $courseid! User may want to see old orders. - if (isguestuser()) { - print_error('noguest'); - } - -/// Load strings. All strings should be defined here. locallib.php uses these strings. - $strs = get_strings(array('search','status','action','time','course','confirm','yes','no','cancel','all','none','error')); - $authstrs = get_strings(array('orderid','nameoncard','echeckfirslasttname','void','capture','refund','delete', - 'allpendingorders','authcaptured','authorizedpendingcapture','capturedpendingsettle','settled', - 'refunded','cancelled','expired','underreview','approvedreview','reviewfailed','tested','new', - 'paymentmethod','methodcc','methodecheck', 'paymentmanagement', 'orderdetails', 'cclastfour', 'isbusinesschecking','shopper', - 'transid','settlementdate','notsettled','amount','unenrolstudent'), 'enrol_authorize'); - -/// User wants to see all orders - if (empty($orderid)) { - authorize_print_orders($courseid, $userid); - } - else { - authorize_print_order($orderid); - } - diff --git a/enrol/authorize/lang/en/enrol_authorize.php b/enrol/authorize/lang/en/enrol_authorize.php deleted file mode 100644 index 5a67999ca5f..00000000000 --- a/enrol/authorize/lang/en/enrol_authorize.php +++ /dev/null @@ -1,271 +0,0 @@ -. - -/** - * Strings for component 'enrol_authorize', language 'en'. - * - * @package enrol_authorize - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -$string['authorize:config'] = 'Configure Authorize.Net enrol instances'; -$string['authorize:manage'] = 'Manage enrolled users'; -$string['authorize:unenrol'] = 'Unenrol users from course'; -$string['authorize:unenrolself'] = 'Unenrol self from the course'; -$string['authorize:managepayments'] = 'Manage payments'; -$string['authorize:uploadcsv'] = 'Upload CSV file'; -$string['adminacceptccs'] = 'Which credit card types will be accepted?'; -$string['adminaccepts'] = 'Select payment methods allowed and their types'; -$string['anauthcode'] = 'Obtain authcode'; -$string['anauthcodedesc'] = 'If a user\'s credit card cannot be captured on the internet directly, obtain authorization code over the phone from customer\'s bank.'; -$string['adminauthorizeccapture'] = 'Order review and scheduled-capture settings'; -$string['adminauthorizeemail'] = 'Email sending settings'; -$string['adminauthorizesettings'] = 'Authorize.Net merchant account settings'; -$string['adminauthorizewide'] = 'General settings'; -$string['anavs'] = 'Address Verification System'; -$string['anavsdesc'] = 'Check this if you have activated Address Verification System (AVS) in your Authorize.Net merchant account. This demands address fields like street, state, country and zip when user fills out payment form.'; -$string['adminconfighttps'] = 'Please ensure that you have "turned loginhttps ON" to use this plugin
in Admin >> Variables >> Security >> HTTP security.'; -$string['adminconfighttpsgo'] = 'Go to the secure page to configure this plugin.'; -$string['admincronsetup'] = 'The cron.php maintenance script has not been run for at least 24 hours.
Cron must be enabled if you want to use scheduled-capture feature.
Enable \'Authorize.Net plugin\' and setup cron properly; or uncheck an_review again.
If you disable scheduled-capture, transactions will be cancelled unless you review them within 30 days.
Check an_review and enter \'0\' to an_capture_day field
if you want to manually accept/deny payments within 30 days.'; -$string['anemailexpired'] = 'Expiry notification'; -$string['anemailexpireddesc'] = 'This is useful for \'manual-capture\'. Admins are notified the specified amount of days prior to pending orders expiring.'; -$string['adminemailexpiredsort'] = 'When the number of pending orders expiring are sent to the teachers via email, which one is important?'; -$string['adminemailexpiredsortcount'] = 'Order count'; -$string['adminemailexpiredsortsum'] = 'Total amount'; -$string['anemailexpiredteacher'] = 'Expiry notification - Teacher'; -$string['anemailexpiredteacherdesc'] = 'If you have enabled manual-capture (see above) and teachers can manage the payments, they may also notified about pending orders expiring. This will send an email to each course teachers about the count of the pending orders to expire.'; -$string['adminemailexpsetting'] = '(0=disable sending email, default=2, max=5)
(Manual capture settings for sending email: cron=enabled, an_review=checked, an_capture_day=0, an_emailexpired=1-5)'; -$string['adminhelpcapturetitle'] = 'Scheduled-capture day'; -$string['adminhelpreviewtitle'] = 'Order review'; -$string['adminneworder'] = 'Dear Admin, - - You have received a new pending order: - - Order ID: {$a->orderid} - Transaction ID: {$a->transid} - User: {$a->user} - Course: {$a->course} - Amount: {$a->amount} - - SCHEDULED-CAPTURE ENABLED?: {$a->acstatus} - - If the scheduled-capture is active, the credit card is to be captured on {$a->captureon} - and then the user is to be enrolled to course; otherwise it will be expired - on {$a->expireon} and cannot be captured after this day. - - You can also accept/deny the payment to enrol the student immediately following this link: - {$a->url}'; -$string['adminnewordersubject'] = '{$a->course}: New pending order: {$a->orderid}'; -$string['adminpendingorders'] = 'You have disabled scheduled-capture feature.
Total {$a->count} transactions with the status of \'Authorized/Pending capture\' are to be cancelled unless you check them.
To accept/deny payments, go to url}\'>Payment Management page.'; -$string['anreview'] = 'Review'; -$string['anreviewdesc'] = 'Review order before processing the credit card.'; -$string['adminteachermanagepay'] = 'Teachers can manage the payments of the course.'; -$string['allpendingorders'] = 'All pending orders'; -$string['amount'] = 'Amount'; -$string['anlogin'] = 'Authorize.Net: Login name'; -$string['anpassword'] = 'Authorize.Net: Password'; -$string['anreferer'] = 'Referer'; -$string['anrefererdesc'] = 'Define the URL referer if you have set up this in your Authorize.Net merchant account. This will send a line "Referer: URL" embedded in the web request.'; -$string['antestmode'] = 'Test mode'; -$string['antestmodedesc'] = 'Run transactions in test mode only (no money will be drawn)'; -$string['antrankey'] = 'Authorize.Net: Transaction key'; -$string['approvedreview'] = 'Approved review'; -$string['authcaptured'] = 'Authorized / Captured'; -$string['authcode'] = 'Authorization code'; -$string['authorizedpendingcapture'] = 'Authorized / Pending capture'; -$string['authorizeerror'] = 'Authorize.Net error: {$a}'; -$string['avsa'] = 'Address (street) matches, postal code does not'; -$string['avsb'] = 'Address information not provided'; -$string['avse'] = 'Address Verification System error'; -$string['avsg'] = 'Non-U.S. card issuing bank'; -$string['avsn'] = 'No match on address (street) nor postal code'; -$string['avsp'] = 'Address Verification System not applicable'; -$string['avsr'] = 'Retry - system unavailable or timed out'; -$string['avsresult'] = 'AVS result: {$a}'; -$string['avss'] = 'Service not supported by issuer'; -$string['avsu'] = 'Address information is unavailable'; -$string['avsw'] = '9 digit postal code matches, address (street) does not'; -$string['avsx'] = 'Address (street) and 9 digit postal code match'; -$string['avsy'] = 'Address (street) and 5 digit postal code match'; -$string['avsz'] = '5 digit postal code matches, address (street) does not'; -$string['canbecredit'] = 'Can be refunded to {$a->upto}'; -$string['cancelled'] = 'Cancelled'; -$string['capture'] = 'Capture'; -$string['capturedpendingsettle'] = 'Captured / Pending settlement'; -$string['capturedsettled'] = 'Captured / Settled'; -$string['captureyes'] = 'The credit card will be captured and the student will be enrolled to the course. Are you sure?'; -$string['ccexpire'] = 'Expiry date'; -$string['ccexpired'] = 'The credit card has expired'; -$string['ccinvalid'] = 'Invalid card number'; -$string['cclastfour'] = 'CC last four'; -$string['ccno'] = 'Credit card number'; -$string['cctype'] = 'Credit card type'; -$string['ccvv'] = 'Card verification'; -$string['ccvvhelp'] = 'Look at the back of card (last 3 digits)'; -$string['costdefaultdesc'] = 'In course settings, enter -1 to use this default cost to course cost field.'; -$string['cutofftime'] = 'Cut-off time'; -$string['cutofftimedesc'] = 'Transaction cut-off time. When the last transaction is picked up for settlement?'; -$string['dataentered'] = 'Data entered'; -$string['delete'] = 'Destroy'; -$string['description'] = 'The Authorize.Net module allows you to set up paid courses via payment providers. Two ways to set the course cost (1) a site-wide cost as a default for the whole site or (2) a course setting that you can set for each course individually. The course cost overrides the site cost.'; -$string['echeckabacode'] = 'Bank ABA number'; -$string['echeckaccnum'] = 'Bank account number'; -$string['echeckacctype'] = 'Bank account type'; -$string['echeckbankname'] = 'Bank name'; -$string['echeckbusinesschecking'] = 'Business checking'; -$string['echeckfirslasttname'] = 'Bank account owner'; -$string['echeckchecking'] = 'Checking'; -$string['echecksavings'] = 'Savings'; -$string['enrolname'] = 'Authorize.Net payment gateway'; -$string['expired'] = 'Expired'; -$string['haveauthcode'] = 'I have already an authorization code'; -$string['howmuch'] = 'How much?'; -$string['httpsrequired'] = 'We are sorry to inform you that your request cannot be processed now. This site\'s configuration couldn\'t be set up correctly.

Please don\'t enter your credit card number unless you see a yellow lock at the bottom of the browser. If the symbol appears, it means the page encrypts all data sent between client and server. So the information during the transaction between the two computers is protected, hence your credit card number cannot be captured over the internet.'; -$string['choosemethod'] = 'If you know the enrolment key of the cource, please enter it below;
Otherwise you need to pay for this course.'; -$string['chooseone'] = 'Fill one or both of the following two fields. The password isn\'t shown.'; -$string['invalidaba'] = 'Invalid ABA number'; -$string['invalidaccnum'] = 'Invalid account number'; -$string['invalidacctype'] = 'Invalid account type'; -$string['isbusinesschecking'] = 'Is business checking?'; -$string['logindesc'] = 'This option must be ON.

Please ensure that you have turned loginhttps ON in Admin >> Variables >> Security.

Turning this on will make Moodle use a secure https connection just for the login and payment pages.'; -$string['logininfo'] = 'When configuring your Authorize.Net account, the login name is required and you must enter either the transaction key or the password in the appropriate box. We recommend you enter the transaction key due to security precautions.'; -$string['messageprovider:authorize_enrolment'] = 'Authorize.Net enrolment messages'; -$string['methodcc'] = 'Credit card'; -$string['methodccdesc'] = 'Select credit card and accepted types below'; -$string['methodecheck'] = 'eCheck (ACH)'; -$string['methodecheckdesc'] = 'Select eCheck and accepted types below'; -$string['missingaba'] = 'Missing ABA number'; -$string['missingaddress'] = 'Missing address'; -$string['missingbankname'] = 'Missing bank name'; -$string['missingcc'] = 'Missing card number'; -$string['missingccauthcode'] = 'Missing authorization code'; -$string['missingccexpiremonth'] = 'Missing expiration month'; -$string['missingccexpireyear'] = 'Missing expiration year'; -$string['missingcctype'] = 'Missing card type'; -$string['missingcvv'] = 'Missing verification number'; -$string['missingzip'] = 'Missing postal code'; -$string['mypaymentsonly'] = 'Show my payments only'; -$string['nameoncard'] = 'Name on card'; -$string['new'] = 'New'; -$string['noreturns'] = 'No returns!'; -$string['notsettled'] = 'Not settled'; -$string['orderdetails'] = 'Order details'; -$string['orderid'] = 'OrderID'; -$string['paymentmanagement'] = 'Payment management'; -$string['paymentmethod'] = 'Payment method'; -$string['paymentpending'] = 'Your payment is pending for this course with this order number {$a->orderid}. See url}\'>Order Details.'; -$string['pendingecheckemail'] = 'Dear manager, - -There are {$a->count} pending echecks now and you have to upload a csv file to get the users enrolled. - -Click the link and read the help file on the page seen: -{$a->url}'; -$string['pendingechecksubject'] = '{$a->course}: Pending eChecks({$a->count})'; -$string['pendingordersemail'] = 'Dear admin, - -{$a->pending} transactions for course "{$a->course}" will expire unless you accept payment within {$a->days} days. - -This is a warning message, because you didn\'t enable scheduled-capture. -It means you have to accept or deny payments manually. - -To accept/deny pending payments go to: -{$a->url} - -To enable scheduled-capture, it means you will not receive any warning emails anymore, go to: - -{$a->enrolurl}'; -$string['pendingordersemailteacher'] = 'Dear teacher, - -{$a->pending} transactions costed {$a->currency} {$a->sumcost} for course "{$a->course}" -will expire unless you accept payment with in {$a->days} days. - -You have to accept or deny payments manually because of the admin hasn\'t enabled the scheduled-capture. - -{$a->url}'; -$string['pendingorderssubject'] = 'WARNING: {$a->course}, {$a->pending} order(s) will expire within {$a->days} day(s).'; -$string['pluginname'] = 'Authorize.Net'; -$string['reason11'] = 'A duplicate transaction has been submitted.'; -$string['reason13'] = 'The merchant Login ID is invalid or the account is inactive.'; -$string['reason16'] = 'The transaction was not found.'; -$string['reason17'] = 'The merchant does not accept this type of credit card.'; -$string['reason245'] = 'This eCheck type is not allowed when using the payment gateway hosted payment form.'; -$string['reason246'] = 'This eCheck type is not allowed.'; -$string['reason27'] = 'The transaction resulted in an AVS mismatch. The address provided does not match billing address of cardholder.'; -$string['reason28'] = 'The merchant does not accept this type of credit card.'; -$string['reason30'] = 'The configuration with the processor is invalid. Call merchant service provider.'; -$string['reason39'] = 'The supplied currency code is either invalid, not supported, not allowed for this merchant or doesn\'t have an exchange rate.'; -$string['reason43'] = 'The merchant was incorrectly set up at the processor. Call your merchant service provider.'; -$string['reason44'] = 'This transaction has been declined. Card code filter error!'; -$string['reason45'] = 'This transaction has been declined. Card code / AVS filter error!'; -$string['reason47'] = 'The amount requested for settlement may not be greater than the original amount authorized.'; -$string['reason5'] = 'A valid amount is required.'; -$string['reason50'] = 'This transaction is awaiting settlement and cannot be refunded.'; -$string['reason51'] = 'The sum of all credits against this transaction is greater than the original transaction amount.'; -$string['reason54'] = 'The referenced transaction does not meet the criteria for issuing a credit.'; -$string['reason55'] = 'The sum of credits against the referenced transaction would exceed the original debit amount.'; -$string['reason56'] = 'This merchant accepts eCheck (ACH) transactions only; no credit card transactions are accepted.'; -$string['refund'] = 'Refund'; -$string['refunded'] = 'Refunded'; -$string['returns'] = 'Returns'; -$string['ancaptureday'] = 'Capture day'; -$string['ancapturedaydesc'] = 'Capture the credit card automatically unless a teacher or administrator review the order within the specified days. CRON MUST BE ENABLED.
(0 days means it will disable scheduled-capture, also means teacher or admin review order manually. Transaction will be cancelled if you disable scheduled-capture or unless you review it within 30 days.)'; -$string['reviewfailed'] = 'Review failed'; -$string['reviewnotify'] = 'Your payment will be reviewed. Expect an email within a few days from your teacher.'; -$string['sendpaymentbutton'] = 'Send payment'; -$string['settled'] = 'Settled'; -$string['settlementdate'] = 'Settlement date'; -$string['shopper'] = 'Shopper'; -$string['subvoidyes'] = 'The transaction refunded ({$a->transid}) is going to be cancelled and this will cause crediting {$a->amount} to your account. Are you sure?'; -$string['tested'] = 'Tested'; -$string['testmode'] = '[TEST MODE]'; -$string['testwarning'] = 'Capturing/Voiding/Refunding seems working in test mode, but no record was updated or inserted in database.'; -$string['transid'] = 'TransactionID'; -$string['underreview'] = 'Under review'; -$string['unenrolstudent'] = 'Unenrol student?'; -$string['uploadcsv'] = 'Upload a CSV file'; -$string['usingccmethod'] = 'Enrol using Credit Card'; -$string['usingecheckmethod'] = 'Enrol using eCheck'; -$string['verifyaccount'] = 'Verify your Authorize.Net merchant account'; -$string['verifyaccountresult'] = 'Verification result: {$a}'; -$string['void'] = 'Void'; -$string['voidyes'] = 'The transaction will be cancelled. Are you sure?'; -$string['welcometocoursesemail'] = 'Dear {$a->name}, - -Thanks for your payments. You have enrolled these courses: - -{$a->courses} - -You may view your payment details or edit your profile: - {$a->paymenturl} - {$a->profileurl}'; -$string['youcantdo'] = 'You can\'t do this action: {$a->action}'; -$string['zipcode'] = 'Zip code'; -$string['cost'] = 'Cost'; -$string['currency'] = 'Currency'; -$string['enrolperiod'] = 'Enrolment duration'; -$string['enrolstartdate'] = 'Start date'; -$string['enrolenddate'] = 'End date'; -$string['enrolenddaterror'] = 'Enrolment end date cannot be earlier than start date'; -$string['status'] = 'Allow Autorize.Net enrolments'; -$string['nocost'] = 'There is no cost associated with enrolling in this course via Authorize.Net!'; -$string['firstnameoncard'] = 'Firstname on card'; -$string['lastnameoncard'] = 'Lastname on card'; -$string['expiremonth'] = 'Expiry month'; -$string['expireyear'] = 'Expiry year'; -$string['cccity'] = 'City'; -$string['ccstate'] = 'State'; -$string['unenrolselfconfirm'] = 'Do you really want to unenrol yourself from course "{$a}"?'; diff --git a/enrol/authorize/localfuncs.php b/enrol/authorize/localfuncs.php deleted file mode 100644 index 473af614962..00000000000 --- a/enrol/authorize/localfuncs.php +++ /dev/null @@ -1,314 +0,0 @@ -. - -/** - * Authorize enrolment plugin. - * - * This plugin allows you to set up paid courses, using authorize.net. - * - * @package enrol_authorize - * @copyright 2010 Eugene Venter - * @author Eugene Venter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -require_once($CFG->libdir.'/eventslib.php'); - -function get_course_cost($plugininstance) { - $defaultplugin = enrol_get_plugin('authorize'); - - $cost = (float)0; - $currency = (!empty($plugininstance->currency)) - ? $plugininstance->currency :( empty($defaultplugin->currency) - ? 'USD' : $defaultplugin->enrol_currency ); - - if (!empty($plugininstance->cost)) { - $cost = (float)(((float)$plugininstance->cost) < 0) ? $defaultplugin->cost : $plugininstance->cost; - } - - $cost = format_float($cost, 2); - $ret = array( - 'cost' => $cost, - 'currency' => $currency - ); - - return $ret; -} - -function zero_cost($plugininstance) { - $curcost = get_course_cost($plugininstance); - return (abs($curcost['cost']) < 0.01); -} - -function prevent_double_paid($plugininstance) { - global $CFG, $SESSION, $USER, $DB; - $plugin = enrol_get_plugin('authorize'); - - $sql = "SELECT id FROM {enrol_authorize} WHERE userid = ? AND courseid = ? AND instanceid = ?"; - $params = array($USER->id, $plugininstance->courseid, $plugininstance->id); - - if (!$plugin->get_config('an_test')) { // Real mode - $sql .= ' AND status IN(?,?,?)'; - $params[] = AN_STATUS_AUTH; - $params[] = AN_STATUS_UNDERREVIEW; - $params[] = AN_STATUS_APPROVEDREVIEW; - } - else { // Test mode - $sql .= ' AND status=?'; - $params[] = AN_STATUS_NONE; - } - - if (($recid = $DB->get_field_sql($sql, $params))) { - $a = new stdClass; - $a->orderid = $recid; - $a->url = "$CFG->wwwroot/enrol/authorize/index.php?order=$a->orderid"; - redirect($a->url, get_string("paymentpending", "enrol_authorize", $a), '10'); - return; - } - if (isset($SESSION->ccpaid)) { - unset($SESSION->ccpaid); - redirect($CFG->wwwroot . '/login/logout.php?sesskey='.sesskey()); - return; - } -} - -function get_list_of_creditcards($getall = false) { - $plugin = enrol_get_plugin('authorize'); - - $alltypes = array( - 'mcd' => 'Master Card', - 'vis' => 'Visa', - 'amx' => 'American Express', - 'dsc' => 'Discover', - 'dnc' => 'Diners Club', - 'jcb' => 'JCB', - 'swi' => 'Switch', - 'dlt' => 'Delta', - 'enr' => 'EnRoute' - ); - - if ($getall) { - return $alltypes; - } - - $ret = array(); - foreach ($alltypes as $code=>$name) { - if ($plugin->get_config("an_acceptcc_{$code}")) { - $ret[$code] = $name; - } - } - - return $ret; -} - -function get_list_of_payment_methods($getall = false) { - $plugin = enrol_get_plugin('authorize'); - $method_cc = $plugin->get_config('an_acceptmethod_cc'); - $method_echeck = $plugin->get_config('an_acceptmethod_echeck'); - - - if ($getall || (empty($method_cc) && empty($method_echeck))) { - return array(AN_METHOD_CC, AN_METHOD_ECHECK); - } else { - $methods = array(); - if ($method_cc) { - $methods[] = AN_METHOD_CC; - } - - if ($method_echeck) { - $methods[] = AN_METHOD_ECHECK; - } - - return $methods; - } -} - -function get_list_of_bank_account_types($getall = false) { - $plugin = enrol_get_plugin('authorize'); - $alltypes = array('CHECKING', 'BUSINESSCHECKING', 'SAVINGS'); - - if ($getall) { - return $alltypes; - } else { - $types = array(); - foreach ($alltypes as $type) { - if ($plugin->get_config("an_acceptecheck_{$type}")) { - $types[] = $type; - } - } - - return $types; - } -} - -function message_to_admin($subject, $data) { - global $SITE; - - $admin = get_admin(); - $data = (array)$data; - - $emailmessage = "$SITE->fullname: Transaction failed.\n\n$subject\n\n"; - $emailmessage .= print_r($data, true); - $eventdata = new stdClass(); - $eventdata->modulename = 'moodle'; - $eventdata->component = 'enrol_authorize'; - $eventdata->name = 'authorize_enrolment'; - $eventdata->userfrom = $admin; - $eventdata->userto = $admin; - $eventdata->subject = "$SITE->fullname: Authorize.net ERROR"; - $eventdata->fullmessage = $emailmessage; - $eventdata->fullmessageformat = FORMAT_PLAIN; - $eventdata->fullmessagehtml = ''; - $eventdata->smallmessage = ''; - message_send($eventdata); -} - -function send_welcome_messages($orderdata) { - global $CFG, $SITE, $DB; - - if (empty($orderdata)) { - return; - } - - if (is_numeric($orderdata)) { - $orderdata = array($orderdata); - } - - $sql = "SELECT e.id, e.courseid, e.userid, c.fullname - FROM {enrol_authorize} e - JOIN {course} c ON c.id = e.courseid - WHERE e.id IN(" . implode(',', $orderdata) . ") - ORDER BY e.userid"; - - $rs = $DB->get_recordset_sql($sql); - if (!$rs->valid()) { - $rs->close(); // Not going to iterate (but exit), close rs - return; - } - - if ($rs->valid() and $ei = current($rs)) - { - if (1 < count($orderdata)) { - $sender = get_admin(); - } - else { - $context = context_course::instance($ei->courseid); - $paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments', '', '', '0', '1'); - $sender = array_shift($paymentmanagers); - } - - do - { - $usercourses = array(); - $lastuserid = $ei->userid; - - while ($ei && $ei->userid == $lastuserid) { - $context = context_course::instance($ei->courseid); - $usercourses[] = format_string($ei->fullname, true, array('context' => $context)); - if (!$rs->valid()) { - break; - } - $rs->next(); - $ei = $rs->current(); - } - - if (($user = $DB->get_record('user', array('id'=>$lastuserid)))) { - $a = new stdClass; - $a->name = $user->firstname; - $a->courses = implode("\n", $usercourses); - $a->profileurl = "$CFG->wwwroot/user/view.php?id=$lastuserid"; - $a->paymenturl = "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid"; - $emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a); - $subject = get_string("enrolmentnew", 'enrol', format_string($SITE->shortname, true, array('context' => context_course::instance(SITEID)))); - - $eventdata = new stdClass(); - $eventdata->modulename = 'moodle'; - $eventdata->component = 'enrol_authorize'; - $eventdata->name = 'authorize_enrolment'; - $eventdata->userfrom = $sender; - $eventdata->userto = $user; - $eventdata->subject = $subject; - $eventdata->fullmessage = $emailmessage; - $eventdata->fullmessageformat = FORMAT_PLAIN; - $eventdata->fullmessagehtml = ''; - $eventdata->smallmessage = ''; - message_send($eventdata); - } - } - while ($ei); - - $rs->close(); // end of iteration, close rs - } -} - -function check_curl_available() { - return function_exists('curl_init') && - function_exists('stream_get_wrappers') && - in_array('https', stream_get_wrappers()); -} - -function authorize_verify_account() { - global $USER, $SITE; - $plugin = enrol_get_plugin('authorize'); - - require_once('authorizenet.class.php'); - - $original_antest = $plugin->get_config('an_test'); - $plugin->set_config('an_test', 1); // Test mode - $shortname = format_string($SITE->shortname, true, array('context' => context_course::instance(SITEID))); - - $order = new stdClass(); - $order->id = -1; - $order->paymentmethod = AN_METHOD_CC; - $order->refundinfo = '1111'; - $order->ccname = 'Test User'; - $order->courseid = $SITE->id; - $order->userid = $USER->id; - $order->status = AN_STATUS_NONE; - $order->settletime = 0; - $order->transid = 0; - $order->timecreated = time(); - $order->amount = '0.01'; - $order->currency = 'USD'; - - $extra = new stdClass(); - $extra->x_card_num = '4111111111111111'; - $extra->x_card_code = '123'; - $extra->x_exp_date = "12" . intval(date("Y")) + 5; - $extra->x_currency_code = $order->currency; - $extra->x_amount = $order->amount; - $extra->x_first_name = 'Test'; - $extra->x_last_name = 'User'; - $extra->x_country = $USER->country; - - $extra->x_invoice_num = $order->id; - $extra->x_description = $shortname . ' - Authorize.net Merchant Account Verification Test'; - - $ret = ''; - $message = ''; - if (AN_APPROVED == AuthorizeNet::process($order, $message, $extra, AN_ACTION_AUTH_CAPTURE)) { - $ret = get_string('verifyaccountresult', 'enrol_authorize', get_string('success')); - } - else { - $ret = get_string('verifyaccountresult', 'enrol_authorize', $message); - } - - $plugin->set_config('an_test', $original_antest); - - return $ret; -} - - diff --git a/enrol/authorize/locallib.php b/enrol/authorize/locallib.php deleted file mode 100644 index b44c727d2b3..00000000000 --- a/enrol/authorize/locallib.php +++ /dev/null @@ -1,728 +0,0 @@ -. - -/** - * Authorize enrolment plugin. - * - * This plugin allows you to set up paid courses, using authorize.net. - * - * @package enrol_authorize - * @copyright 2010 Eugene Venter - * @author Eugene Venter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -if (!defined('MOODLE_INTERNAL')) { - die('Direct access to this script is forbidden.'); -} - -define('ORDER_CAPTURE', 'capture'); -define('ORDER_DELETE', 'delete'); -define('ORDER_REFUND', 'refund'); -define('ORDER_VOID', 'void'); - -/** - * authorize_print_orders - * - */ -function authorize_print_orders($courseid, $userid) { - global $course; - global $CFG, $USER, $SITE, $DB, $OUTPUT, $PAGE; - global $strs, $authstrs; - - $plugin = enrol_get_plugin('authorize'); - - require_once($CFG->libdir.'/tablelib.php'); - - $perpage = optional_param('perpage', 10, PARAM_INT); - $showonlymy = optional_param('showonlymy', 0, PARAM_BOOL); - $searchquery = optional_param('searchquery', '0', PARAM_INT); - $searchtype = optional_param('searchtype', 'orderid', PARAM_ALPHA); - $status = optional_param('status', AN_STATUS_NONE, PARAM_INT); - - $coursecontext = context_course::instance($courseid); - - $searchmenu = array('orderid' => $authstrs->orderid, 'transid' => $authstrs->transid, 'cclastfour' => $authstrs->cclastfour); - $buttons = "
"; - $buttons .= html_writer::label(get_string('orderdetails', 'enrol_authorize'), 'menusearchtype', false, array('class' => 'accesshide')); - $buttons .= html_writer::select($searchmenu, 'searchtype', $searchtype, false); - $buttons .= html_writer::label(get_string('search'), 'searchquery', false, array('class' => 'accesshide')); - $buttons .= ""; - $buttons .= ""; - $buttons .= "
"; - - if (has_capability('enrol/authorize:uploadcsv', context_user::instance($USER->id))) { - $buttons .= "
"; - } - - $canmanagepayments = has_capability('enrol/authorize:managepayments', $coursecontext); - if ($showonlymy || !$canmanagepayments) { - $userid = $USER->id; - } - - $baseurl = $CFG->wwwroot.'/enrol/authorize/index.php?user='.$userid; - - $params = array('userid'=>$userid); - $sql = "SELECT c.id, c.fullname FROM {course} c JOIN {enrol_authorize} e ON c.id = e.courseid "; - $sql .= ($userid > 0) ? "WHERE (e.userid=:userid) " : ''; - $sql .= "ORDER BY c.sortorder, c.fullname"; - if (($popupcrs = $DB->get_records_sql_menu($sql, $params))) { - $popupcrs = array($SITE->id => $SITE->fullname) + $popupcrs; - } - $popupmenu = empty($popupcrs) ? '' : $OUTPUT->single_select(new moodle_url($baseurl.'&status='.$status), 'course', $popupcrs, $courseid, null, 'coursesmenu'); - $popupmenu .= '
'; - $statusmenu = array( - AN_STATUS_NONE => $strs->all, - AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW => $authstrs->allpendingorders, - AN_STATUS_AUTH => $authstrs->authorizedpendingcapture, - AN_STATUS_AUTHCAPTURE => $authstrs->authcaptured, - AN_STATUS_CREDIT => $authstrs->refunded, - AN_STATUS_VOID => $authstrs->cancelled, - AN_STATUS_EXPIRE => $authstrs->expired, - AN_STATUS_UNDERREVIEW => $authstrs->underreview, - AN_STATUS_APPROVEDREVIEW => $authstrs->approvedreview, - AN_STATUS_REVIEWFAILED => $authstrs->reviewfailed, - AN_STATUS_TEST => $authstrs->tested - ); - - $popupmenu .= $OUTPUT->single_select(new moodle_url($baseurl.'&course='.$courseid), 'status', $statusmenu, $status, null, 'statusmenu'); - if ($canmanagepayments) { - $popupmenu .= '
'; - $PAGE->requires->js('/enrol/authorize/authorize.js'); - $aid = $OUTPUT->add_action_handler(new component_action('click', 'authorize_jump_to_mypayments', array('userid' => $USER->id, 'status' => $status))); - $popupmenu .= html_writer::checkbox('enrol_authorize', 1, $userid == $USER->id, get_string('mypaymentsonly', 'enrol_authorize'), array('id'=>$aid)); - } - - if (SITEID != $courseid) { - $shortname = format_string($course->shortname, true, array('context' => $coursecontext)); - $PAGE->navbar->add($shortname, new moodle_url('/course/view.php', array('id'=>$course->id))); - } - $PAGE->navbar->add($authstrs->paymentmanagement, 'index.php'); - $PAGE->set_title("$course->shortname: $authstrs->paymentmanagement"); - $PAGE->set_heading($authstrs->paymentmanagement); - $PAGE->set_headingmenu($popupmenu); - $PAGE->set_button($buttons); - echo $OUTPUT->header(); - - $table = new flexible_table('enrol-authorize'); - $table->set_attribute('width', '100%'); - $table->set_attribute('cellspacing', '0'); - $table->set_attribute('cellpadding', '3'); - $table->set_attribute('id', 'orders'); - $table->set_attribute('class', 'generaltable generalbox'); - - if ($perpage > 100) { $perpage = 100; } - $perpagemenus = array(5 => 5, 10 => 10, 20 => 20, 50 => 50, 100 => 100); - $perpagemenu = $OUTPUT->single_select(new moodle_url($baseurl.'&status='.$status.'&course='.$courseid), 'perpage', $perpagemenus, $perpage, array(''=>'choosedots'), 'perpagemenu'); - $table->define_columns(array('id', 'userid', 'timecreated', 'status', 'action')); - $table->define_headers(array($authstrs->orderid, $authstrs->shopper, $strs->time, $strs->status, $perpagemenu)); - $table->define_baseurl($baseurl."&status=$status&course=$courseid&perpage=$perpage"); - - $table->no_sorting('action'); - $table->sortable(true, 'id', SORT_DESC); - $table->pageable(true); - $table->setup(); - - $select = "SELECT e.id, e.paymentmethod, e.refundinfo, e.transid, e.courseid, e.userid, e.status, e.ccname, e.timecreated, e.settletime "; - $from = "FROM {enrol_authorize} e "; - $where = "WHERE (1=1) "; - $params = array(); - - if (!empty($searchquery)) { - switch($searchtype) { - case 'orderid': - $where = "WHERE (e.id = :searchquery) "; - $params['searchquery'] = $searchquery; - break; - - case 'transid': - $where = "WHERE (e.transid = :searchquery) "; - $params['searchquery'] = $searchquery; - break; - - case 'cclastfour': - $searchquery = sprintf("%04d", $searchquery); - $where = "WHERE (e.refundinfo = :searchquery) AND (e.paymentmethod=:method) "; - $params['searchquery'] = $searchquery; - $params['method'] = AN_METHOD_CC; - break; - } - } - else { - switch ($status) - { - case AN_STATUS_NONE: - if (!$plugin->get_config('an_test')) { - $where .= "AND (e.status != :status) "; - $params['status'] = AN_STATUS_NONE; - } - break; - - case AN_STATUS_TEST: - $newordertime = time() - 120; // -2 minutes. Order may be still in process. - $where .= "AND (e.status = :status) AND (e.transid = '0') AND (e.timecreated < :newordertime) "; - $params['status'] = AN_STATUS_NONE; - $params['newordertime'] = $newordertime; - break; - - case AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW: - $where .= 'AND (e.status IN(:status1,:status2,:status3)) '; - $params['status1'] = AN_STATUS_AUTH; - $params['status2'] = AN_STATUS_UNDERREVIEW; - $params['status3'] = AN_STATUS_APPROVEDREVIEW; - break; - - case AN_STATUS_CREDIT: - $from .= "INNER JOIN {enrol_authorize_refunds} r ON e.id = r.orderid "; - $where .= "AND (e.status = :status) "; - $params['status'] = AN_STATUS_AUTHCAPTURE; - break; - - default: - $where .= "AND (e.status = :status) "; - $params['status'] = $status; - break; - } - - if (SITEID != $courseid) { - $where .= "AND (e.courseid = :courseid) "; - $params['courseid'] = $courseid; - } - } - - // This must be always LAST where!!! - if ($userid > 0) { - $where .= "AND (e.userid = :userid) "; - $params['userid'] = $userid; - } - - if (($sort = $table->get_sql_sort())) { - $sort = ' ORDER BY ' . $sort; - } - - $totalcount = $DB->count_records_sql('SELECT COUNT(*) ' . $from . $where, $params); - $table->initialbars($totalcount > $perpage); - $table->pagesize($perpage, $totalcount); - - if (($records = $DB->get_records_sql($select . $from . $where . $sort, $params, $table->get_page_start(), $table->get_page_size()))) { - foreach ($records as $record) { - $actionstatus = authorize_get_status_action($record); - $color = authorize_get_status_color($actionstatus->status); - $actions = ''; - - if (empty($actionstatus->actions)) { - $actions .= $strs->none; - } - else { - foreach ($actionstatus->actions as $val) { - $actions .= authorize_print_action_button($record->id, $val); - } - } - - $table->add_data(array( - "$record->id", - $record->ccname, - userdate($record->timecreated), - "" . $authstrs->{$actionstatus->status} . "", - $actions - )); - } - } - - $table->print_html(); - echo $OUTPUT->footer(); -} - -/** - * authorize_print_order - * - * @param object $order - */ -function authorize_print_order($orderid) -{ - global $CFG, $USER, $DB, $OUTPUT, $PAGE; - global $strs, $authstrs; - - $plugin = enrol_get_plugin('authorize'); - $an_test = $plugin->get_config('an_test'); - - $do = optional_param('do', '', PARAM_ALPHA); - $unenrol = optional_param('unenrol', 0, PARAM_BOOL); - $confirm = optional_param('confirm', 0, PARAM_BOOL); - - if (!$order = $DB->get_record('enrol_authorize', array('id'=>$orderid))) { - print_error('orderidnotfound', '', - "$CFG->wwwroot/enrol/authorize/index.php", $orderid); - } - - if (!$course = $DB->get_record('course', array('id'=>$order->courseid))) { - print_error('invalidcourseid', '', "$CFG->wwwroot/enrol/authorize/index.php"); - } - - if (!$user = $DB->get_record('user', array('id'=>$order->userid))) { - print_error('nousers', '', "$CFG->wwwroot/enrol/authorize/index.php"); - } - - $coursecontext = context_course::instance($course->id); - if ($USER->id != $order->userid) { // Current user viewing someone else's order - require_capability('enrol/authorize:managepayments', $coursecontext); - } - - $settled = AuthorizeNet::settled($order); - $statusandactions = authorize_get_status_action($order); - $color = authorize_get_status_color($statusandactions->status); - - $buttons = ''; - if (empty($do)) - { - if (empty($statusandactions->actions)) { - if ((AN_METHOD_ECHECK == $order->paymentmethod) && has_capability('enrol/authorize:uploadcsv', context_user::instance($USER->id))) { - $buttons .= "
"; - } - } - else { - foreach ($statusandactions->actions as $val) { - $buttons .= authorize_print_action_button($orderid, $val); - } - } - } - - if (SITEID != $course->id) { - $shortname = format_string($course->shortname, true, array('context' => $coursecontext)); - $PAGE->navbar->add($shortname, new moodle_url('/course/view.php', array('id'=>$course->id))); - } - $PAGE->navbar->add($authstrs->paymentmanagement, 'index.php?course='.$course->id); - $PAGE->navbar->add($authstrs->orderid . ': ' . $orderid, 'index.php'); - $PAGE->set_course($course); - $PAGE->set_title("$course->shortname: $authstrs->paymentmanagement"); - $PAGE->set_heading($authstrs->orderdetails); - $PAGE->set_cacheable(false); - $PAGE->set_button($buttons); - echo $OUTPUT->header(); - - $table = new html_table(); - $table->width = '100%'; - $table->size = array('30%', '70%'); - $table->align = array('right', 'left'); - - if (AN_METHOD_CC == $order->paymentmethod) { - $table->data[] = array("$authstrs->paymentmethod:", $authstrs->methodcc); - $table->data[] = array("$authstrs->nameoncard:", $order->ccname . ' ('.fullname($user).')'); - $table->data[] = array("$authstrs->cclastfour:", $order->refundinfo); - } - else { - $table->data[] = array("$authstrs->paymentmethod:", $authstrs->methodecheck); - $table->data[] = array("$authstrs->echeckfirslasttname:", $order->ccname . ' ('.fullname($user).')'); - $table->data[] = array("$authstrs->isbusinesschecking:", ($order->refundinfo == 1) ? $strs->yes : $strs->no); - } - - $table->data[] = array("$authstrs->amount:", "$order->currency $order->amount"); - $table->data[] = array("$authstrs->transid:", $order->transid); - $table->data[] = array("$strs->time:", userdate($order->timecreated)); - $table->data[] = array("$authstrs->settlementdate:", $settled ? userdate($order->settletime) : $authstrs->notsettled); - $table->data[] = array("$strs->status:", "" . $authstrs->{$statusandactions->status} . ""); - - if (ORDER_CAPTURE == $do && in_array(ORDER_CAPTURE, $statusandactions->actions)) { - if ($confirm && confirm_sesskey()) { - $message = ''; - $extra = NULL; - if (AN_APPROVED == AuthorizeNet::process($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) { - if (empty($an_test)) { - if (enrol_into_course($course, $user, 'authorize')) { - if ($plugin->get_config('enrol_mailstudents')) { - send_welcome_messages($orderid); - } - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); - } - else { - $shortname = format_string($course->shortname, true, array('context' => $coursecontext)); - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", "Error while trying to enrol ".fullname($user)." in '" . $shortname . "'", 20); - } - } - else { - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", get_string('testwarning', 'enrol_authorize'), 10); - } - } - else { - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", $message, 20); - } - } - $table->data[] = array("$strs->confirm:", get_string('captureyes', 'enrol_authorize') . '
' . - authorize_print_action_button($orderid, ORDER_CAPTURE, 0, true, false, $strs->no)); - echo html_writer::table($table); - } - elseif (ORDER_REFUND == $do && in_array(ORDER_REFUND, $statusandactions->actions)) { - $refunded = 0.0; - $sql = "SELECT SUM(amount) AS refunded - FROM {enrol_authorize_refunds} - WHERE (orderid = ?) - AND (status = ?)"; - - if (($refundval = $DB->get_field_sql($sql, array($orderid, AN_STATUS_CREDIT)))) { - $refunded = floatval($refundval); - } - $upto = round($order->amount - $refunded, 2); - if ($upto <= 0) { - print_error('refoundtoorigi', '', - "$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", $order->amount); - } - $amount = round(optional_param('amount', $upto, PARAM_RAW), 2); - if ($amount > $upto) { - print_error('refoundto', '', - "$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", $upto); - } - if ($confirm && confirm_sesskey()) { - $extra = new stdClass; - $extra->orderid = $orderid; - $extra->amount = $amount; - $message = ''; - $success = AuthorizeNet::process($order, $message, $extra, AN_ACTION_CREDIT); - if (AN_APPROVED == $success || AN_REVIEW == $success) { - if (empty($an_test)) { - if (empty($extra->id)) { - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", "insert record error", 20); - } - else { - if (!empty($unenrol)) { - $pinstance = $DB->get_record('enrol', array('id'=>$order->instanceid)); - $plugin->unenrol_user($pinstance, $order->userid); - //role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true); - } - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); - } - } - else { - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", get_string('testwarning', 'enrol_authorize'), 10); - } - } - else { - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", $message, 20); - } - } - $a = new stdClass; - $a->upto = $upto; - $inputattrs = array('id' => 'amount', 'type' => 'text', 'size' => '5', 'name' => 'amount', 'value' => $amount); - $extrahtml = html_writer::label(get_string('howmuch', 'enrol_authorize'), 'amount'). ' '. - html_writer::empty_tag('input', $inputattrs). ' '. - get_string('canbecredit', 'enrol_authorize', $a) . '
'; - $table->data[] = array("$strs->confirm:", - authorize_print_action_button($orderid, ORDER_REFUND, 0, true, $authstrs->unenrolstudent, $strs->no, $extrahtml)); - echo html_writer::table($table); - } - elseif (ORDER_DELETE == $do && in_array(ORDER_DELETE, $statusandactions->actions)) { - if ($confirm && confirm_sesskey()) { - if (!empty($unenrol)) { - $pinstance = $DB->get_record('enrol', array('id'=>$order->instanceid)); - $plugin->unenrol_user($pinstance, $order->userid); - //role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true); - } - $DB->delete_records('enrol_authorize', array('id'=>$orderid)); - redirect("$CFG->wwwroot/enrol/authorize/index.php"); - } - $table->data[] = array("$strs->confirm:", - authorize_print_action_button($orderid, ORDER_DELETE, 0, true, $authstrs->unenrolstudent,$strs->no)); - echo html_writer::table($table); - } - elseif (ORDER_VOID == $do) { // special case: cancel original or refunded transaction? - $suborderid = optional_param('suborder', 0, PARAM_INT); - if (empty($suborderid) && in_array(ORDER_VOID, $statusandactions->actions)) { // cancel original - if ($confirm && confirm_sesskey()) { - $extra = NULL; - $message = ''; - if (AN_APPROVED == AuthorizeNet::process($order, $message, $extra, AN_ACTION_VOID)) { - if (empty($an_test)) { - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); - } - else { - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", get_string('testwarning', 'enrol_authorize'), 10); - } - } - else { - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", $message, 20); - } - } - $table->data[] = array("$strs->confirm:", get_string('voidyes', 'enrol_authorize') . '
' . - authorize_print_action_button($orderid, ORDER_VOID, 0, true, false, $strs->no)); - echo html_writer::table($table); - } - elseif (!empty($suborderid)) { // cancel refunded - $sql = "SELECT r.*, e.courseid, e.paymentmethod - FROM {enrol_authorize_refunds} r - INNER JOIN {enrol_authorize} e - ON r.orderid = e.id - WHERE r.id = ? - AND r.orderid = ? - AND r.status = ?"; - - $suborder = $DB->get_record_sql($sql, array($suborderid, $orderid, AN_STATUS_CREDIT)); - if (!$suborder) { // not found - print_error('transactionvoid', '', "$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); - } - $refundedstatus = authorize_get_status_action($suborder); - unset($suborder->courseid); - if (in_array(ORDER_VOID, $refundedstatus->actions)) { - if ($confirm && confirm_sesskey()) { - $message = ''; - $extra = NULL; - if (AN_APPROVED == AuthorizeNet::process($suborder, $message, $extra, AN_ACTION_VOID)) { - if (empty($an_test)) { - if (!empty($unenrol)) { - $pinstance = $DB->get_record('enrol', array('id'=>$order->instanceid)); - $plugin->unenrol_user($pinstance, $order->userid); - //role_unassign_all(array('userid'=>$order->userid, 'contextid'=>$coursecontext->id, 'component'=>'enrol_authorize'), true, true); - } - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); - } - else { - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", get_string('testwarning', 'enrol_authorize'), 10); - } - } - else { - redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", $message, 20); - } - } - $a = new stdClass; - $a->transid = $suborder->transid; - $a->amount = $suborder->amount; - $table->data[] = array("$strs->confirm:", get_string('subvoidyes', 'enrol_authorize', $a) . '
' . - authorize_print_action_button($orderid, ORDER_VOID, $suborderid, true, $authstrs->unenrolstudent, $strs->no)); - echo html_writer::table($table); - } - } - } - else { - echo html_writer::table($table); - - if ($settled) { // show refunds. - $t2 = new html_table(); - $t2->size = array('45%', '15%', '20%', '10%', '10%'); - $t2->align = array('right', 'right', 'right', 'right', 'right'); - $t2->head = array($authstrs->settlementdate, $authstrs->transid, $strs->status, $strs->action, $authstrs->amount); - - $sql = "SELECT r.*, e.courseid, e.paymentmethod - FROM {enrol_authorize_refunds} r - INNER JOIN {enrol_authorize} e - ON r.orderid = e.id - WHERE r.orderid = ?"; - - if (($refunds = $DB->get_records_sql($sql, array($orderid)))) { - $sumrefund = floatval(0.0); - foreach ($refunds as $rf) { - $subactions = ''; - $substatus = authorize_get_status_action($rf); - if (empty($substatus->actions)) { - $subactions .= $strs->none; - } - else { - foreach ($substatus->actions as $vl) { - $subactions .= authorize_print_action_button($orderid, $vl, $rf->id); - } - } - $sign = ''; - $color = authorize_get_status_color($substatus->status); - if ($substatus->status == 'refunded' or $substatus->status == 'settled') { - $sign = '-'; - $sumrefund += floatval($rf->amount); - } - $t2->data[] = array( - userdate($rf->settletime), - $rf->transid, - "" .$authstrs->{$substatus->status} . "", - $subactions, - format_float($sign . $rf->amount, 2) - ); - } - $t2->data[] = array('','',get_string('total'),$order->currency,format_float('-'.$sumrefund, 2)); - } - else { - $t2->data[] = array('','',get_string('noreturns', 'enrol_authorize'),'',''); - } - echo "

" . get_string('returns', 'enrol_authorize') . "

\n"; - echo html_writer::table($t2); - } - } - - echo $OUTPUT->footer(); -} - -/** - * authorize_get_status_action - * - * @param object $order Order details. - * @return object - */ -function authorize_get_status_action($order) -{ - global $CFG; - static $newordertime = 0; - - if (0 == $newordertime) { - $newordertime = time() - 120; // -2 minutes. Order may be still in process. - } - - $ret = new stdClass(); - $ret->actions = array(); - - $canmanage = has_capability('enrol/authorize:managepayments', context_course::instance($order->courseid)); - - if (floatval($order->transid) == 0) { // test transaction or new order - if ($order->timecreated < $newordertime) { - if ($canmanage) { - $ret->actions = array(ORDER_DELETE); - } - $ret->status = 'tested'; - } - else { - $ret->status = 'new'; - } - return $ret; - } - - switch ($order->status) { - case AN_STATUS_AUTH: - if (AuthorizeNet::expired($order)) { - if ($canmanage) { - $ret->actions = array(ORDER_DELETE); - } - $ret->status = 'expired'; - } - else { - if ($canmanage) { - $ret->actions = array(ORDER_CAPTURE, ORDER_VOID); - } - $ret->status = 'authorizedpendingcapture'; - } - return $ret; - - case AN_STATUS_AUTHCAPTURE: - if (AuthorizeNet::settled($order)) { - if ($canmanage) { - if (($order->paymentmethod == AN_METHOD_CC) || ($order->paymentmethod == AN_METHOD_ECHECK && !empty($order->refundinfo))) { - $ret->actions = array(ORDER_REFUND); - } - } - $ret->status = 'settled'; - } - else { - if ($order->paymentmethod == AN_METHOD_CC && $canmanage) { - $ret->actions = array(ORDER_VOID); - } - $ret->status = 'capturedpendingsettle'; - } - return $ret; - - case AN_STATUS_CREDIT: - if (AuthorizeNet::settled($order)) { - $ret->status = 'settled'; - } - else { - if ($order->paymentmethod == AN_METHOD_CC && $canmanage) { - $ret->actions = array(ORDER_VOID); - } - $ret->status = 'refunded'; - } - return $ret; - - case AN_STATUS_VOID: - $ret->status = 'cancelled'; - return $ret; - - case AN_STATUS_EXPIRE: - if ($canmanage) { - $ret->actions = array(ORDER_DELETE); - } - $ret->status = 'expired'; - return $ret; - - case AN_STATUS_UNDERREVIEW: - $ret->status = 'underreview'; - return $ret; - - case AN_STATUS_APPROVEDREVIEW: - $ret->status = 'approvedreview'; - return $ret; - - case AN_STATUS_REVIEWFAILED: - if ($canmanage) { - $ret->actions = array(ORDER_DELETE); - } - $ret->status = 'reviewfailed'; - return $ret; - - default: - return $ret; - } -} - - -function authorize_get_status_color($status) -{ - $color = 'black'; - switch ($status) - { - case 'settled': - case 'capturedpendingsettle': - $color = '#339900'; // green - break; - - case 'underreview': - case 'approvedreview': - case 'authorizedpendingcapture': - $color = '#FF6600'; // orange - break; - - case 'new': - case 'tested': - $color = '#003366'; // blue - break; - - case 'expired': - case 'cancelled': - case 'refunded'; - case 'reviewfailed': - $color = '#FF0033'; // red - break; - } - return $color; -} - -function authorize_print_action_button($orderid, $do, $suborderid=0, $confirm=false, $unenrol=false, $nobutton=false, $extrahtml='') -{ - global $CFG, $OUTPUT; - global $authstrs; - - $ret = '
' . - '' . - '' . - ''; - if (!empty($suborderid)) { - $ret .= ''; - } - if (!empty($confirm)) { - $ret .= ''; - } - if (!empty($unenrol)) { - $ret .= html_writer::checkbox('unenrol', 1, false, $unenrol) . '
'; - } - $ret .= $extrahtml; - $ret .= '' . - '
'; - if (!empty($nobutton)) { - $ret .= '
'; - } - return $ret; -} - diff --git a/enrol/authorize/uploadcsv.php b/enrol/authorize/uploadcsv.php deleted file mode 100644 index 9c62501ef61..00000000000 --- a/enrol/authorize/uploadcsv.php +++ /dev/null @@ -1,265 +0,0 @@ -. - -/** - * Authorize.Net enrolment plugin - support for user self unenrolment. - * - * @package enrol_authorize - * @copyright 2010 Eugene Venter - * @author Eugene Venter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/// Load libraries -require_once('../../config.php'); -require_once($CFG->dirroot.'/enrol/authorize/const.php'); -require_once($CFG->dirroot.'/enrol/authorize/localfuncs.php'); -require_once($CFG->libdir.'/eventslib.php'); -require_once('import_form.php'); - -/// Require capabilities -require_login(); -require_capability('enrol/authorize:uploadcsv', context_system::instance()); - -/// Print header -$struploadcsv = get_string('uploadcsv', 'enrol_authorize'); -$managebutton = "
"; - -$form = new enrol_authorize_import_form(); - -$PAGE->set_url('/enrol/authorize/uploadcsv.php'); -$PAGE->navbar->add(get_string('paymentmanagement', 'enrol_authorize'), 'index.php'); -$PAGE->navbar->add($struploadcsv, 'uploadcsv.php'); -$PAGE->set_title($struploadcsv); -$PAGE->set_cacheable(false); -$PAGE->set_button($managebutton); -echo $OUTPUT->header(); -echo $OUTPUT->heading($struploadcsv); - -/// Handle CSV file -if (!$form->get_data()) { - $form->display(); -} else { - $filename = $CFG->tempdir . '/enrolauthorize/importedfile_'.time().'.csv'; - make_temp_directory('enrolauthorize'); - // Fix mac/dos newlines - $text = $form->get_file_content('csvfile'); - $text = preg_replace('!\r\n?!', "\n", $text); - $fp = fopen($filename, "w"); - fwrite($fp, $text); - fclose($fp); - authorize_process_csv($filename); -} - -/// Print footer -echo $OUTPUT->footer(); - -function authorize_process_csv($filename) { - global $CFG, $SITE, $DB; - - $plugin = enrol_get_plugin('authorize'); - - /// We need these fields - $myfields = array( - 'Transaction ID', // enrol_authorize.transid or enrol_authorize_refunds.transid; See: Reference Transaction ID - 'Transaction Status', // Under Review,Approved Review,Review Failed,Settled Successfully - 'Transaction Type', // Authorization w/ Auto Capture, Authorization Only, Capture Only, Credit, Void, Prior Authorization Capture - 'Settlement Amount', // - 'Settlement Currency', // - 'Settlement Date/Time', // - 'Authorization Amount', // - 'Authorization Currency', // - 'Submit Date/Time', // timecreated - 'Reference Transaction ID', // enrol_authorize.transid if Transaction Type = Credit - 'Total Amount', // enrol_authorize.cost - 'Currency', // enrol_authorize.currency - 'Invoice Number', // enrol_authorize.id: Don't trust this! Backup/Restore changes this - 'Customer ID' // enrol_authorize.userid - ); - - /// Open the file and get first line - $handle = fopen($filename, "r"); - if (!$handle) { - print_error('cannotopencsv'); - } - $firstline = fgetcsv($handle, 8192, ","); - $numfields = count($firstline); - if ($numfields != 49 && $numfields != 70) { - @fclose($handle); - print_error('csvinvalidcolsnum'); - } - - /// Re-sort fields - $csvfields = array(); - foreach ($myfields as $myfield) { - $csvindex = array_search($myfield, $firstline); - if ($csvindex === false) { - $csvfields = array(); - break; - } - $csvfields[$myfield] = $csvindex; - } - if (empty($csvfields)) { - @fclose($handle); - print_error('csvinvalidcols'); - } - - /// Read lines - $sendem = array(); - $ignoredlines = ''; - - $imported = 0; - $updated = 0; - $ignored = 0; - while (($data = fgetcsv($handle, 8192, ",")) !== FALSE) { - if (count($data) != $numfields) { - $ignored++; // ignore empty lines - continue; - } - - $transid = $data[$csvfields['Transaction ID']]; - $transtype = $data[$csvfields['Transaction Type']]; - $transstatus = $data[$csvfields['Transaction Status']]; - $reftransid = $data[$csvfields['Reference Transaction ID']]; - $settlementdate = strtotime($data[$csvfields['Settlement Date/Time']]); - - if ($transstatus == 'Approved Review' || $transstatus == 'Review Failed') { - if (($order = $DB->get_record('enrol_authorize', array('transid'=>$transid)))) { - $order->status = ($transstatus == 'Approved Review') ? AN_STATUS_APPROVEDREVIEW : AN_STATUS_REVIEWFAILED; - $DB->update_record('enrol_authorize', $order); - $updated++; // Updated order status - } - continue; - } - - if (!empty($reftransid) && is_numeric($reftransid) && 'Settled Successfully' == $transstatus && 'Credit' == $transtype) { - if (($order = $DB->get_record('enrol_authorize', array('transid'=>$reftransid)))) { - if (AN_METHOD_ECHECK == $order->paymentmethod) { - $refund = $DB->get_record('enrol_authorize_refunds', array('transid'=>$transid)); - if ($refund) { - $refund->status = AN_STATUS_CREDIT; - $refund->settletime = $settlementdate; - $DB->update_record('enrol_authorize_refunds', $refund); - $updated++; - } - else { - $ignored++; - $ignoredlines .= $reftransid . ": Not our business(Reference Transaction ID)\n"; - } - } - } - else { - $ignored++; - $ignoredlines .= $reftransid . ": Not our business(Transaction ID)\n"; - } - continue; - } - - if (! ($transstatus == 'Settled Successfully' && $transtype == 'Authorization w/ Auto Capture')) { - $ignored++; - $ignoredlines .= $transid . ": Not settled\n"; - continue; - } - - // TransactionId must match - $order = $DB->get_record('enrol_authorize', array('transid'=>$transid)); - if (!$order) { - $ignored++; - $ignoredlines .= $transid . ": Not our business\n"; - continue; - } - - // Authorized/Captured and Settled - $order->status = AN_STATUS_AUTHCAPTURE; - $order->settletime = $settlementdate; - $DB->update_record('enrol_authorize', $order); - $updated++; // Updated order status and settlement date - - if ($order->paymentmethod != AN_METHOD_ECHECK) { - $ignored++; - $ignoredlines .= $transid . ": The method must be echeck\n"; - continue; - } - - // Get course and context - $course = $DB->get_record('course', array('id'=>$order->courseid)); - if (!$course) { - $ignored++; - $ignoredlines .= $transid . ": Could not find this course: " . $order->courseid . "\n"; - continue; - } - $coursecontext = context_course::instance($course->id, IGNORE_MISSING); - if (!$coursecontext) { - $ignored++; - $ignoredlines .= $transid . ": Could not find course context: " . $order->courseid . "\n"; - continue; - } - - // Get user - $user = $DB->get_record('user', array('id'=>$order->userid)); - if (!$user) { - $ignored++; - $ignoredlines .= $transid . ": Could not find this user: " . $order->userid . "\n"; - continue; - } - - // If user wasn't enrolled, enrol now. Ignore otherwise. Because admin user might submit this file again. - if (($role = get_default_course_role($course))) { - if (! user_has_role_assignment($user->id, $role->id, $coursecontext->id)) { - $timestart = $timeend = 0; - if ($course->enrolperiod) { - $timestart = time(); - $timeend = $timestart + $course->enrolperiod; - } - // Enrol user - $pinstance = $DB->get_record('enrol', array('id'=>$order->instanceid)); - $plugin->enrol_user($pinstance, $user->id, $pinstance->roleid, $timestart, $timeend); - - $imported++; - if ($plugin->get_config('enrol_mailstudents')) { - $sendem[] = $order->id; - } - } - } - } - fclose($handle); - - /// Send email to admin - if (!empty($ignoredlines)) { - $admin = get_admin(); - - $eventdata = new stdClass(); - $eventdata->modulename = 'moodle'; - $eventdata->component = 'enrol_authorize'; - $eventdata->name = 'authorize_enrolment'; - $eventdata->userfrom = $admin; - $eventdata->userto = $admin; - $eventdata->subject = format_string($SITE->fullname, true, array('context' => context_course::instance(SITEID))).': Authorize.net CSV ERROR LOG'; - $eventdata->fullmessage = $ignoredlines; - $eventdata->fullmessageformat = FORMAT_PLAIN; - $eventdata->fullmessagehtml = ''; - $eventdata->smallmessage = ''; - message_send($eventdata); - } - - /// Send welcome messages to users - if (!empty($sendem)) { - send_welcome_messages($sendem); - } - - /// Show result - notice("Done...
Imported: $imported
Updated: $updated
Ignored: $ignored"); -} diff --git a/enrol/authorize/version.php b/enrol/authorize/version.php deleted file mode 100644 index 1a913835859..00000000000 --- a/enrol/authorize/version.php +++ /dev/null @@ -1,31 +0,0 @@ -. - -/** - * Authorize.Net enrolment plugin version specification. - * - * @package enrol_authorize - * @copyright 2010 Eugene Venter - * @author Eugene Venter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -$plugin->version = 2013050100; // The current plugin version (Date: YYYYMMDDXX) -$plugin->requires = 2013050100; // Requires this Moodle version -$plugin->component = 'enrol_authorize'; // Full name of the plugin (used for diagnostics) -$plugin->cron = 180; From 317638a3d69896f9128ebd0da1e59db9722b65dd Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Fri, 5 Jul 2013 15:21:43 +0800 Subject: [PATCH 2/3] MDL-28466 remove enrol_authorize from standard list of plugins --- lib/pluginlib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 1706683964b..b76cd313741 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -715,7 +715,7 @@ class plugin_manager { ), 'enrol' => array( - 'authorize', 'category', 'cohort', 'database', 'flatfile', + 'category', 'cohort', 'database', 'flatfile', 'guest', 'imsenterprise', 'ldap', 'manual', 'meta', 'mnet', 'paypal', 'self' ), From fdb0dfe7c07aa93403b4d14b92fae993e3a23284 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Mon, 15 Jul 2013 10:15:16 +0800 Subject: [PATCH 3/3] MDL-28466 pluginlib: Add enrol_authorize as standard deleted plugin This means we won't bother our users about it in the plugin list thanks Marina for picking it up! --- lib/pluginlib.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pluginlib.php b/lib/pluginlib.php index b76cd313741..fb6ff3b1601 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -636,6 +636,7 @@ class plugin_manager { // Moodle 2.3 supports upgrades from 2.2.x only. $plugins = array( 'qformat' => array('blackboard'), + 'enrol' => array('authorize'), ); if (!isset($plugins[$type])) {