Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
ethem committed Feb 5, 2008
1 parent a5137c5 commit e08dc18
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
8 changes: 8 additions & 0 deletions enrol/authorize/db/upgrade.php
Expand Up @@ -59,6 +59,14 @@ function xmldb_enrol_authorize_upgrade($oldversion=0) {
}
}

if ($result && $oldversion < 2008020500 && is_enabled_enrol('authorize')) {
require_once($CFG->dirroot.'/enrol/authorize/localfuncs.php');
if (!check_curl_available()) {
notify("You are using the authorize.net enrolment plugin for payment handling but cUrl is not available.
PHP must be compiled with cURL+SSL support (--with-curl --with-openssl)");
}
}

return $result;
}

Expand Down
59 changes: 32 additions & 27 deletions enrol/authorize/enrol.php
Expand Up @@ -245,7 +245,7 @@ private function cc_submit($form, $course)
$a->orderid = $order->id;
$emailsubject = get_string('adminnewordersubject', 'enrol_authorize', $a);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if ($paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments')) {
if (($paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments'))) {
foreach ($paymentmanagers as $paymentmanager) {
email_to_user($paymentmanager, $USER, $emailsubject, $emailmessage);
}
Expand Down Expand Up @@ -417,8 +417,8 @@ public function config_form($frm)
global $CFG;
$mconfig = get_config('enrol/authorize');

if (!check_openssl_loaded()) {
notify('PHP must be compiled with SSL support (--with-openssl)');
if (!check_curl_available()) {
notify('PHP must be compiled with cURL+SSL support (--with-curl --with-openssl)');
}

if (empty($CFG->loginhttps) and substr($CFG->wwwroot, 0, 5) !== 'https') {
Expand Down Expand Up @@ -450,7 +450,7 @@ public function config_form($frm)
}
}

if ($count = count_records('enrol_authorize', 'status', AN_STATUS_AUTH)) {
if (($count = count_records('enrol_authorize', 'status', AN_STATUS_AUTH))) {
$a = new stdClass;
$a->count = $count;
$a->url = $CFG->wwwroot."/enrol/authorize/index.php?status=".AN_STATUS_AUTH;
Expand Down Expand Up @@ -531,7 +531,7 @@ public function process_config($config)
set_config('an_sorttype', $sorttype);

// https and openssl library is required
if ((substr($CFG->wwwroot, 0, 5) !== 'https' and empty($CFG->loginhttps)) or !check_openssl_loaded()) {
if ((substr($CFG->wwwroot, 0, 5) !== 'https' and empty($CFG->loginhttps)) or !check_curl_available()) {
return false;
}

Expand Down Expand Up @@ -593,13 +593,13 @@ public function cron()

if (intval($mconfig->an_dailysettlement) < $settlementtime) {
set_config('an_dailysettlement', $settlementtime, 'enrol/authorize');
mtrace(" daily cron; some cleanups and sending email to admins the count of pending orders expiring", ": ");
mtrace(" Daily cron:");
$this->cron_daily();
mtrace("done");
mtrace(" Done");
}

mtrace(" scheduled capture", ": ");
if (empty($CFG->an_review) or (!empty($CFG->an_test)) or (intval($CFG->an_capture_day) < 1) or (!check_openssl_loaded())) {
mtrace(" Scheduled capture", ": ");
if (empty($CFG->an_review) or (!empty($CFG->an_test)) or (intval($CFG->an_capture_day) < 1) or (!check_curl_available())) {
mtrace("disabled");
return; // order review disabled or test mode or manual capture or openssl wasn't loaded.
}
Expand Down Expand Up @@ -710,26 +710,26 @@ private function cron_daily()
$settlementtime = authorize_getsettletime($timenow);
$timediff30 = $settlementtime - (30 * $oneday);

// Delete orders that no transaction was made.
$select = "(status='".AN_STATUS_NONE."') AND (timecreated<'$timediff30')";
delete_records_select('enrol_authorize', $select);
if (delete_records_select('enrol_authorize', $select)) {
mtrace(" orders no transaction made have deleted");
}

// Pending orders are expired with in 30 days.
$select = "(status='".AN_STATUS_AUTH."') AND (timecreated<'$timediff30')";
execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET status='".AN_STATUS_EXPIRE."' WHERE $select", false);
if (execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET status='".AN_STATUS_EXPIRE."' WHERE $select", false)) {
mtrace(" pending orders to expire have updated");
}

// Delete expired orders 60 days later.
$timediff60 = $settlementtime - (60 * $oneday);
$select = "(status='".AN_STATUS_EXPIRE."') AND (timecreated<'$timediff60')";
delete_records_select('enrol_authorize', $select);
if (delete_records_select('enrol_authorize', $select)) {
mtrace(" orders expired older than 60 days have deleted");
}

// XXX TODO SEND EMAIL to 'enrol/authorize:uploadcsv'
// get_users_by_capability() does not handling user level resolving
// After user resolving, get_admin() to get_users_by_capability()
$adminuser = get_admin();
$select = "status IN(".AN_STATUS_UNDERREVIEW.",".AN_STATUS_APPROVEDREVIEW.") AND (timecreated<'$onepass') AND (timecreated>'$timediff60')";
$count = count_records_select('enrol_authorize', $select);
if ($count) {
if (($count = count_records_select('enrol_authorize', $select)) &&
($csvusers = get_users_by_capability(get_context_instance(CONTEXT_SYSTEM), 'enrol/authorize:uploadcsv'))) {
$a = new stdClass;
$a->count = $count;
$a->course = $SITE->shortname;
Expand All @@ -738,23 +738,28 @@ private function cron_daily()
$a->count = $count;
$a->url = $CFG->wwwroot.'/enrol/authorize/uploadcsv.php';
$message = get_string('pendingecheckemail', 'enrol_authorize', $a);
@email_to_user($adminuser, $adminuser, $subject, $message);
foreach($csvusers as $csvuser) {
@email_to_user($csvuser, $adminuser, $subject, $message);
}
mtrace(" users who have 'enrol/authorize:uploadcsv' were mailed");
}

// Daily warning email for pending orders expiring.
mtrace(" early pending order warning email for manual capture", ": ");
if (empty($CFG->an_emailexpired)) {
return; // not enabled
mtrace("not enabled");
return;
}

// Pending orders count will be expired.

$timediffem = $settlementtime - ((30 - intval($CFG->an_emailexpired)) * $oneday);
$select = "(status='". AN_STATUS_AUTH ."') AND (timecreated<'$timediffem') AND (timecreated>'$timediff30')";
$count = count_records_select('enrol_authorize', $select);
if (!$count) {
mtrace("no orders prior to $CFG->an_emailexpired days");
return;
}

// Email to admin
mtrace("$count orders prior to $CFG->an_emailexpired days");
$a = new stdClass;
$a->pending = $count;
$a->days = $CFG->an_emailexpired;
Expand All @@ -769,7 +774,7 @@ private function cron_daily()
$message = get_string('pendingordersemail', 'enrol_authorize', $a);
email_to_user($adminuser, $adminuser, $subject, $message);

// Email to teachers
// Email to payment managers
if (empty($CFG->an_emailexpiredteacher)) {
return; // email feature disabled for teachers.
}
Expand All @@ -789,7 +794,7 @@ private function cron_daily()
foreach($courseinfos as $courseinfo) {
$lastcourse = $courseinfo->courseid;
$context = get_context_instance(CONTEXT_COURSE, $lastcourse);
if ($paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments')) {
if (($paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments'))) {
$a = new stdClass;
$a->course = $courseinfo->shortname;
$a->pending = $courseinfo->cnt;
Expand Down
6 changes: 4 additions & 2 deletions enrol/authorize/localfuncs.php
Expand Up @@ -168,9 +168,11 @@ function send_welcome_messages($orderdata)
}


function check_openssl_loaded()
function check_curl_available()
{
return extension_loaded('openssl');
return function_exists('curl_init') &&
function_exists('stream_get_wrappers') &&
in_array('https', stream_get_wrappers());
}


Expand Down
2 changes: 1 addition & 1 deletion enrol/authorize/version.php
@@ -1,6 +1,6 @@
<?php // $Id$

$plugin->version = 2006112901;
$plugin->version = 2008020500;
$plugin->requires = 2007101000;

?>

0 comments on commit e08dc18

Please sign in to comment.