2006-08-30 10:29:10 +00:00
< ? php // $Id$
2005-05-13 09:05:39 +00:00
2006-06-01 07:47:22 +00:00
require_once ( $CFG -> dirroot . '/enrol/enrol.class.php' );
require_once ( $CFG -> dirroot . '/enrol/authorize/const.php' );
2006-09-02 11:49:02 +00:00
require_once ( $CFG -> dirroot . '/enrol/authorize/localfuncs.php' );
2008-03-03 16:04:32 +00:00
require_once ( $CFG -> dirroot . '/enrol/authorize/authorizenet.class.php' );
2008-07-24 08:38:03 +00:00
require_once ( $CFG -> libdir . '/eventslib.php' );
2005-05-13 09:05:39 +00:00
2005-12-09 12:00:28 +00:00
/**
2006-09-02 11:49:02 +00:00
* Authorize . net Payment Gateway plugin
2005-12-09 12:00:28 +00:00
*/
2006-03-13 16:47:44 +00:00
class enrolment_plugin_authorize
2005-12-09 12:00:28 +00:00
{
2005-11-21 07:33:04 +00:00
2005-12-14 15:47:37 +00:00
/**
* Cron log .
*
* @ var string
* @ access public
*/
2007-11-07 10:24:35 +00:00
public $log ;
2005-12-14 15:47:37 +00:00
2005-12-12 17:32:00 +00:00
2005-11-21 07:33:04 +00:00
/**
2006-10-16 09:39:08 +00:00
* Presents registration forms .
2005-11-21 07:33:04 +00:00
*
* @ param object $course Course info
2005-12-09 12:00:28 +00:00
* @ access public
2005-11-21 07:33:04 +00:00
*/
2007-11-07 10:24:35 +00:00
public function print_entry ( $course )
{
2005-11-21 07:33:04 +00:00
global $CFG , $USER , $form ;
2006-09-02 11:49:02 +00:00
$zerocost = zero_cost ( $course );
2006-06-29 19:07:28 +00:00
if ( $zerocost ) {
$manual = enrolment_factory :: factory ( 'manual' );
if ( ! empty ( $this -> errormsg )) {
$manual -> errormsg = $this -> errormsg ;
}
$manual -> print_entry ( $course );
return ;
}
2006-11-15 20:44:49 +00:00
prevent_double_paid ( $course );
2006-09-22 15:31:04 +00:00
httpsrequired ();
2007-06-15 17:40:58 +00:00
if ( isset ( $_SERVER [ 'SERVER_PORT' ]) && $_SERVER [ 'SERVER_PORT' ] != 443 ) { // MDL-9836
2005-11-21 07:33:04 +00:00
if ( empty ( $CFG -> loginhttps )) {
2008-04-04 02:54:20 +00:00
print_error ( 'httpsrequired' , 'enrol_authorize' );
2005-11-21 07:33:04 +00:00
} else {
2006-01-19 14:57:23 +00:00
$wwwsroot = str_replace ( 'http:' , 'https:' , $CFG -> wwwroot );
redirect ( " $wwwsroot /course/enrol.php?id= $course->id " );
2005-11-21 07:33:04 +00:00
exit ;
}
2005-08-03 10:11:16 +00:00
}
2005-07-13 20:26:16 +00:00
2006-01-19 14:57:23 +00:00
$strcourses = get_string ( 'courses' );
$strloginto = get_string ( 'loginto' , '' , $course -> shortname );
2005-07-13 20:26:16 +00:00
2007-08-17 19:09:11 +00:00
$navlinks = array ();
$navlinks [] = array ( 'name' => $strcourses , 'link' => " $CFG->wwwroot /course/ " , 'type' => 'misc' );
$navlinks [] = array ( 'name' => $strloginto , 'link' => null , 'type' => 'misc' );
$navigation = build_navigation ( $navlinks );
print_header ( $strloginto , $course -> fullname , $navigation );
2006-01-19 14:57:23 +00:00
print_course ( $course , '80%' );
2005-05-13 09:05:39 +00:00
2006-06-29 19:07:28 +00:00
if ( $course -> password ) {
2006-06-29 09:49:36 +00:00
print_heading ( get_string ( 'choosemethod' , 'enrol_authorize' ), 'center' );
2005-11-21 07:33:04 +00:00
}
2005-05-13 09:05:39 +00:00
2006-12-18 19:21:10 +00:00
if ( $USER -> username == 'guest' ) { // only real guest user, not for users with guest role
2006-09-02 11:49:02 +00:00
$curcost = get_course_cost ( $course );
2008-12-10 07:24:11 +00:00
echo '<div class="mdl-align">' ;
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
echo '<p>' . get_string ( 'paymentrequired' ) . '</p>' ;
2006-06-29 09:49:36 +00:00
echo '<p><b>' . get_string ( 'cost' ) . " : $curcost[currency] $curcost[cost] " . '</b></p>' ;
echo '<p><a href="' . $CFG -> httpswwwroot . '/login/">' . get_string ( 'loginsite' ) . '</a></p>' ;
echo '</div>' ;
2006-11-15 20:44:49 +00:00
}
else {
require_once ( $CFG -> dirroot . '/enrol/authorize/enrol_form.php' );
2007-02-05 13:51:27 +00:00
$frmenrol = new enrol_authorize_form ( 'enrol.php' , compact ( 'course' ));
2007-01-12 18:52:09 +00:00
if ( $frmenrol -> get_data ()) {
2006-11-17 08:49:08 +00:00
$authorizeerror = '' ;
2006-11-15 20:44:49 +00:00
switch ( $form -> paymentmethod ) {
case AN_METHOD_CC :
2006-11-17 08:49:08 +00:00
$authorizeerror = $this -> cc_submit ( $form , $course );
break ;
2006-11-15 20:44:49 +00:00
case AN_METHOD_ECHECK :
2006-11-17 08:49:08 +00:00
$authorizeerror = $this -> echeck_submit ( $form , $course );
break ;
2006-11-15 20:44:49 +00:00
}
2006-11-17 08:49:08 +00:00
if ( ! empty ( $authorizeerror )) {
2008-06-20 10:48:29 +00:00
print_error ( 'authorizeerror' , 'enrol_authorize' , '' , $authorizeerror );
2006-11-16 12:23:40 +00:00
}
2006-11-15 20:44:49 +00:00
}
2008-10-10 21:01:27 +00:00
print_box_start ();
2006-11-17 08:49:08 +00:00
$frmenrol -> display ();
2008-10-10 21:01:27 +00:00
print_box_end ();
2006-06-29 09:49:36 +00:00
}
if ( $course -> password ) {
$password = '' ;
include ( $CFG -> dirroot . '/enrol/manual/enrol.html' );
}
2005-11-21 07:33:04 +00:00
print_footer ();
2005-08-01 14:34:30 +00:00
}
2005-12-09 12:00:28 +00:00
2007-11-07 15:57:23 +00:00
function print_enrolmentkeyfrom ( $course )
{
$manual = enrolment_factory :: factory ( 'manual' );
$manual -> print_enrolmentkeyfrom ( $course );
}
2005-11-21 07:33:04 +00:00
/**
2006-10-16 09:39:08 +00:00
* Validates registration forms and enrols student to course .
2005-11-21 07:33:04 +00:00
*
* @ param object $form Form parameters
* @ param object $course Course info
2005-12-09 12:00:28 +00:00
* @ access public
2005-11-21 07:33:04 +00:00
*/
2007-11-07 10:24:35 +00:00
public function check_entry ( $form , $course )
2006-08-30 14:06:40 +00:00
{
global $CFG ;
2006-09-04 07:09:44 +00:00
if ( zero_cost ( $course ) || ( ! empty ( $course -> password ) && ! empty ( $form -> enrol ) && $form -> enrol == 'manual' )) {
2006-03-09 05:03:41 +00:00
$manual = enrolment_factory :: factory ( 'manual' );
$manual -> check_entry ( $form , $course );
2006-06-29 19:07:28 +00:00
if ( ! empty ( $manual -> errormsg )) {
2006-06-29 09:49:36 +00:00
$this -> errormsg = $manual -> errormsg ;
}
2006-08-30 14:06:40 +00:00
}
2005-05-16 22:22:31 +00:00
}
2005-05-26 13:22:01 +00:00
2006-09-02 15:05:10 +00:00
2006-11-15 20:44:49 +00:00
2005-11-21 07:33:04 +00:00
/**
2006-10-16 09:39:08 +00:00
* The user submitted credit card form .
2005-11-21 07:33:04 +00:00
*
* @ param object $form Form parameters
* @ param object $course Course info
2008-03-03 16:04:32 +00:00
* @ return string NULL if ok , error message otherwise .
2005-11-21 07:33:04 +00:00
* @ access private
*/
2007-11-07 10:24:35 +00:00
private function cc_submit ( $form , $course )
2005-12-09 12:00:28 +00:00
{
2008-06-05 14:06:39 +00:00
global $CFG , $USER , $SESSION , $DB ;
2005-12-12 17:32:00 +00:00
2006-09-02 11:49:02 +00:00
prevent_double_paid ( $course );
2005-12-12 17:32:00 +00:00
2006-01-27 13:34:42 +00:00
$useripno = getremoteaddr ();
2006-09-02 11:49:02 +00:00
$curcost = get_course_cost ( $course );
2006-01-27 13:34:42 +00:00
$exp_date = sprintf ( " %02d " , $form -> ccexpiremm ) . $form -> ccexpireyyyy ;
2005-12-12 17:32:00 +00:00
2006-08-31 18:24:37 +00:00
// NEW CC ORDER
2005-12-09 12:00:28 +00:00
$timenow = time ();
$order = new stdClass ();
2006-08-31 18:24:37 +00:00
$order -> paymentmethod = AN_METHOD_CC ;
2006-11-17 16:06:46 +00:00
$order -> refundinfo = substr ( $form -> cc , - 4 );
2006-11-15 20:44:49 +00:00
$order -> ccname = $form -> firstname . " " . $form -> lastname ;
2005-12-09 12:00:28 +00:00
$order -> courseid = $course -> id ;
$order -> userid = $USER -> id ;
$order -> status = AN_STATUS_NONE ; // it will be changed...
2005-12-22 15:24:05 +00:00
$order -> settletime = 0 ; // cron changes this.
2006-01-05 14:30:49 +00:00
$order -> transid = 0 ; // Transaction Id
2005-12-09 12:00:28 +00:00
$order -> timecreated = $timenow ;
2005-12-12 17:42:05 +00:00
$order -> amount = $curcost [ 'cost' ];
$order -> currency = $curcost [ 'currency' ];
2008-06-05 14:06:39 +00:00
$order -> id = $DB -> insert_record ( " enrol_authorize " , $order );
2005-12-09 12:00:28 +00:00
if ( ! $order -> id ) {
2008-07-24 08:38:03 +00:00
message_to_admin ( " Error while trying to insert new data " , $order );
2006-11-17 08:49:08 +00:00
return " Insert record error. Admin has been notified! " ;
2005-11-21 14:09:52 +00:00
}
2005-12-12 17:32:00 +00:00
2005-12-09 12:00:28 +00:00
$extra = new stdClass ();
$extra -> x_card_num = $form -> cc ;
$extra -> x_card_code = $form -> cvv ;
2006-01-05 16:28:34 +00:00
$extra -> x_exp_date = $exp_date ;
2005-12-09 12:00:28 +00:00
$extra -> x_currency_code = $curcost [ 'currency' ];
$extra -> x_amount = $curcost [ 'cost' ];
2006-11-15 20:44:49 +00:00
$extra -> x_first_name = $form -> firstname ;
$extra -> x_last_name = $form -> lastname ;
2006-01-27 09:16:01 +00:00
$extra -> x_country = $form -> cccountry ;
$extra -> x_address = $form -> ccaddress ;
$extra -> x_state = $form -> ccstate ;
$extra -> x_city = $form -> cccity ;
$extra -> x_zip = $form -> cczip ;
2005-12-09 12:00:28 +00:00
$extra -> x_invoice_num = $order -> id ;
$extra -> x_description = $course -> shortname ;
2006-01-27 09:16:01 +00:00
2006-01-19 14:57:23 +00:00
$extra -> x_cust_id = $USER -> id ;
$extra -> x_email = $USER -> email ;
2006-01-27 09:16:01 +00:00
$extra -> x_customer_ip = $useripno ;
2006-01-19 14:57:23 +00:00
$extra -> x_email_customer = empty ( $CFG -> enrol_mailstudents ) ? 'FALSE' : 'TRUE' ;
2006-01-27 09:16:01 +00:00
$extra -> x_phone = '' ;
$extra -> x_fax = '' ;
2005-12-12 17:32:00 +00:00
If an user's credit card cannot be captured on the internet directly, obtain authorization code over phone from customer's bank.
Some users may not wish to use their credit cards on the internet directly for security reasons.
In this case, you need to obtain an authorization code from user's bank.
Initially, ask for credit card information from the customer
like bank name, name on card, card number, expiry date and card validation code
by means of phone, face-to-face or a billing application.
Then, call the customer services of user's bank giving this information and demand an authorization code.
Finally, after obtaining it, login as user to get the user enrolled.
Alternatively, you can give it to the user saying enrol using this code.
2006-10-30 12:53:15 +00:00
if ( ! empty ( $CFG -> an_authcode ) && ! empty ( $form -> ccauthcode )) {
$action = AN_ACTION_CAPTURE_ONLY ;
$extra -> x_auth_code = $form -> ccauthcode ;
}
elseif ( ! empty ( $CFG -> an_review )) {
$action = AN_ACTION_AUTH_ONLY ;
}
2008-03-03 16:04:32 +00:00
else {
$action = AN_ACTION_AUTH_CAPTURE ;
}
If an user's credit card cannot be captured on the internet directly, obtain authorization code over phone from customer's bank.
Some users may not wish to use their credit cards on the internet directly for security reasons.
In this case, you need to obtain an authorization code from user's bank.
Initially, ask for credit card information from the customer
like bank name, name on card, card number, expiry date and card validation code
by means of phone, face-to-face or a billing application.
Then, call the customer services of user's bank giving this information and demand an authorization code.
Finally, after obtaining it, login as user to get the user enrolled.
Alternatively, you can give it to the user saying enrol using this code.
2006-10-30 12:53:15 +00:00
2005-12-22 15:24:05 +00:00
$message = '' ;
2008-03-03 16:04:32 +00:00
if ( AN_APPROVED == AuthorizeNet :: process ( $order , $message , $extra , $action , $form -> cctype ))
{
$SESSION -> ccpaid = 1 ; // security check: don't duplicate payment
switch ( $action )
{
// review enabled (authorize but capture: draw money but wait for settlement during 30 days)
// the first step is to inform payment managers and to redirect the user to main page.
// the next step is to accept/deny payment (AN_ACTION_PRIOR_AUTH_CAPTURE/VOID) within 30 days (payment management or scheduled-capture CRON)
// unless you accept payment or enable auto-capture cron, the transaction is expired after 30 days and the user cannot enrol to the course during 30 days.
// see also: admin/cron.php, $this->cron(), $CFG->an_capture_day...
case AN_ACTION_AUTH_ONLY :
2008-03-05 17:09:05 +00:00
{
$a = new stdClass ;
$a -> url = " $CFG->wwwroot /enrol/authorize/index.php?order= $order->id " ;
$a -> orderid = $order -> id ;
$a -> transid = $order -> transid ;
$a -> amount = " $order->currency $order->amount " ;
$a -> expireon = userdate ( AuthorizeNet :: getsettletime ( $timenow + ( 30 * 3600 * 24 )));
$a -> captureon = userdate ( AuthorizeNet :: getsettletime ( $timenow + ( intval ( $CFG -> an_capture_day ) * 3600 * 24 )));
$a -> course = $course -> fullname ;
$a -> user = fullname ( $USER );
$a -> acstatus = ( $CFG -> an_capture_day > 0 ) ? get_string ( 'yes' ) : get_string ( 'no' );
$emailmessage = get_string ( 'adminneworder' , 'enrol_authorize' , $a );
$a = new stdClass ;
$a -> course = $course -> shortname ;
$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' ))) {
foreach ( $paymentmanagers as $paymentmanager ) {
2008-07-24 08:38:03 +00:00
$eventdata = new object ();
$eventdata -> modulename = 'moodle' ;
$eventdata -> userfrom = $USER ;
$eventdata -> userto = $paymentmanager ;
$eventdata -> subject = $emailsubject ;
$eventdata -> fullmessage = $emailmessage ;
$eventdata -> fullmessageformat = FORMAT_PLAIN ;
$eventdata -> fullmessagehtml = '' ;
$eventdata -> smallmessage = '' ;
events_trigger ( 'message_send' , $eventdata );
2008-03-03 16:04:32 +00:00
}
}
2008-03-05 17:09:05 +00:00
redirect ( $CFG -> wwwroot , get_string ( " reviewnotify " , " enrol_authorize " ), '30' );
break ;
}
2005-12-12 17:32:00 +00:00
2008-03-03 16:04:32 +00:00
case AN_ACTION_CAPTURE_ONLY : // auth code received via phone and the code accepted.
case AN_ACTION_AUTH_CAPTURE : // real time transaction, authorize and capture.
{
// Credit card captured, ENROL student now...
if ( enrol_into_course ( $course , $USER , 'authorize' ))
{
if ( ! empty ( $CFG -> enrol_mailstudents )) {
send_welcome_messages ( $order -> id );
}
if ( ! empty ( $CFG -> enrol_mailteachers )) {
$context = get_context_instance ( CONTEXT_COURSE , $course -> id );
$paymentmanagers = get_users_by_capability ( $context , 'enrol/authorize:managepayments' , '' , '' , '0' , '1' );
$paymentmanager = array_shift ( $paymentmanagers );
$a = new stdClass ;
$a -> course = " $course->fullname " ;
$a -> user = fullname ( $USER );
2008-08-07 11:42:09 +00:00
2008-07-24 08:38:03 +00:00
$eventdata = new object ();
$eventdata -> modulename = 'moodle' ;
$eventdata -> userfrom = $USER ;
$eventdata -> userto = $paymentmanager ;
$eventdata -> subject = get_string ( " enrolmentnew " , '' , format_string ( $course -> shortname ));
$eventdata -> fullmessage = get_string ( 'enrolmentnewuser' , '' , $a );
$eventdata -> fullmessageformat = FORMAT_PLAIN ;
$eventdata -> fullmessagehtml = '' ;
$eventdata -> smallmessage = '' ;
events_trigger ( 'message_send' , $eventdata );
2008-03-03 16:04:32 +00:00
}
if ( ! empty ( $CFG -> enrol_mailadmins )) {
$a = new stdClass ;
$a -> course = " $course->fullname " ;
$a -> user = fullname ( $USER );
$admins = get_admins ();
foreach ( $admins as $admin ) {
2008-07-24 08:38:03 +00:00
$eventdata = new object ();
$eventdata -> modulename = 'moodle' ;
$eventdata -> userfrom = $USER ;
2008-08-07 11:42:09 +00:00
$eventdata -> userto = $admin ;
2008-07-24 08:38:03 +00:00
$eventdata -> subject = get_string ( " enrolmentnew " , '' , format_string ( $course -> shortname ));
$eventdata -> fullmessage = get_string ( 'enrolmentnewuser' , '' , $a );
$eventdata -> fullmessageformat = FORMAT_PLAIN ;
$eventdata -> fullmessagehtml = '' ;
$eventdata -> smallmessage = '' ;
events_trigger ( 'message_send' , $eventdata );
2008-03-03 16:04:32 +00:00
}
}
}
else
{
2008-07-24 08:38:03 +00:00
message_to_admin ( " Error while trying to enrol " . fullname ( $USER ) . " in ' $course->fullname ' " , $order );
2008-03-03 16:04:32 +00:00
}
2005-12-26 19:21:37 +00:00
2008-03-03 16:04:32 +00:00
load_all_capabilities ();
2008-10-10 21:01:27 +00:00
print_box_start ( 'generalbox' , 'notice' );
echo '<p>' . get_string ( 'paymentthanks' , 'moodle' , $course -> fullname ) . '</p>' ;
echo '<div class="buttons">' ;
print_single_button ( " $CFG->wwwroot /enrol/authorize/index.php " , array ( 'order' => $order -> id ), get_string ( 'payments' ));
print_single_button ( " $CFG->wwwroot /course/view.php " , array ( 'id' => $course -> id ), $course -> fullname );
echo '</div>' ;
print_box_end ();
print_footer ( $course );
exit ; // break;
2005-11-21 07:33:04 +00:00
}
}
2008-03-03 16:04:32 +00:00
return NULL ;
2005-12-22 15:24:05 +00:00
}
2008-03-03 16:04:32 +00:00
else
{
2008-07-24 08:38:03 +00:00
message_to_admin ( $message , $order );
2008-03-03 16:04:32 +00:00
return $message ;
2005-11-21 14:09:52 +00:00
}
2005-11-21 07:33:04 +00:00
}
2005-07-16 15:15:41 +00:00
2006-10-16 09:39:08 +00:00
/**
* The user submitted echeck form .
*
* @ param object $form Form parameters
* @ param object $course Course info
2008-03-03 16:04:32 +00:00
* @ return string NULL if ok , error message otherwise .
2006-10-16 09:39:08 +00:00
* @ access private
*/
2007-11-07 10:24:35 +00:00
private function echeck_submit ( $form , $course )
2006-08-30 14:06:40 +00:00
{
2008-06-05 14:06:39 +00:00
global $CFG , $USER , $SESSION , $DB ;
2006-08-30 14:06:40 +00:00
2006-09-02 11:49:02 +00:00
prevent_double_paid ( $course );
2006-08-30 18:59:53 +00:00
$useripno = getremoteaddr ();
2006-09-02 11:49:02 +00:00
$curcost = get_course_cost ( $course );
2006-11-17 08:21:11 +00:00
$isbusinesschecking = ( $form -> acctype == 'BUSINESSCHECKING' );
2006-08-30 18:59:53 +00:00
2006-08-31 18:24:37 +00:00
// NEW ECHECK ORDER
$timenow = time ();
$order = new stdClass ();
$order -> paymentmethod = AN_METHOD_ECHECK ;
2006-11-17 16:06:46 +00:00
$order -> refundinfo = $isbusinesschecking ? 1 : 0 ;
2006-08-31 18:24:37 +00:00
$order -> ccname = $form -> firstname . ' ' . $form -> lastname ;
$order -> courseid = $course -> id ;
$order -> userid = $USER -> id ;
$order -> status = AN_STATUS_NONE ; // it will be changed...
$order -> settletime = 0 ; // cron changes this.
$order -> transid = 0 ; // Transaction Id
$order -> timecreated = $timenow ;
$order -> amount = $curcost [ 'cost' ];
$order -> currency = $curcost [ 'currency' ];
2008-06-05 14:06:39 +00:00
$order -> id = $DB -> insert_record ( " enrol_authorize " , $order );
2006-08-31 18:24:37 +00:00
if ( ! $order -> id ) {
2008-07-24 08:38:03 +00:00
message_to_admin ( " Error while trying to insert new data " , $order );
2006-11-17 08:49:08 +00:00
return " Insert record error. Admin has been notified! " ;
2006-08-31 18:24:37 +00:00
}
2006-08-30 18:59:53 +00:00
2006-09-01 15:18:22 +00:00
$extra = new stdClass ();
$extra -> x_bank_aba_code = $form -> abacode ;
$extra -> x_bank_acct_num = $form -> accnum ;
$extra -> x_bank_acct_type = $form -> acctype ;
2006-11-17 08:21:11 +00:00
$extra -> x_echeck_type = $isbusinesschecking ? 'CCD' : 'WEB' ;
2006-09-01 15:18:22 +00:00
$extra -> x_bank_name = $form -> bankname ;
$extra -> x_currency_code = $curcost [ 'currency' ];
$extra -> x_amount = $curcost [ 'cost' ];
$extra -> x_first_name = $form -> firstname ;
$extra -> x_last_name = $form -> lastname ;
$extra -> x_country = $USER -> country ;
$extra -> x_address = $USER -> address ;
$extra -> x_city = $USER -> city ;
$extra -> x_state = '' ;
$extra -> x_zip = '' ;
$extra -> x_invoice_num = $order -> id ;
$extra -> x_description = $course -> shortname ;
$extra -> x_cust_id = $USER -> id ;
$extra -> x_email = $USER -> email ;
$extra -> x_customer_ip = $useripno ;
$extra -> x_email_customer = empty ( $CFG -> enrol_mailstudents ) ? 'FALSE' : 'TRUE' ;
$extra -> x_phone = '' ;
$extra -> x_fax = '' ;
2006-10-16 09:39:08 +00:00
$message = '' ;
2008-03-03 16:04:32 +00:00
if ( AN_REVIEW == AuthorizeNet :: process ( $order , $message , $extra , AN_ACTION_AUTH_CAPTURE )) {
$SESSION -> ccpaid = 1 ; // security check: don't duplicate payment
redirect ( $CFG -> wwwroot , get_string ( " reviewnotify " , " enrol_authorize " ), '30' );
return NULL ;
}
else {
2008-07-24 08:38:03 +00:00
message_to_admin ( $message , $order );
2006-11-17 08:49:08 +00:00
return $message ;
2006-09-01 15:18:22 +00:00
}
2006-08-30 14:06:40 +00:00
}
2005-05-16 22:22:31 +00:00
2005-11-21 07:33:04 +00:00
/**
* Gets access icons .
*
* @ param object $course
* @ return string
2005-12-09 12:00:28 +00:00
* @ access public
2005-11-21 07:33:04 +00:00
*/
2007-11-07 10:24:35 +00:00
public function get_access_icons ( $course )
{
2006-03-09 05:03:41 +00:00
$manual = enrolment_factory :: factory ( 'manual' );
$str = $manual -> get_access_icons ( $course );
2006-09-02 11:49:02 +00:00
$curcost = get_course_cost ( $course );
2005-11-21 07:33:04 +00:00
if ( abs ( $curcost [ 'cost' ]) > 0.00 ) {
$strrequirespayment = get_string ( " requirespayment " );
$strcost = get_string ( " cost " );
$currency = $curcost [ 'currency' ];
switch ( $currency ) {
case 'USD' : $currency = 'US$' ; break ;
case 'CAD' : $currency = 'C$' ; break ;
case 'EUR' : $currency = '€' ; break ;
case 'GBP' : $currency = '£' ; break ;
case 'JPY' : $currency = '¥' ; break ;
}
2005-08-01 14:34:30 +00:00
2005-11-21 07:33:04 +00:00
$str .= '<div class="cost" title="' . $strrequirespayment . '">' . $strcost . ': ' ;
$str .= $currency . ' ' . $curcost [ 'cost' ] . '</div>' ;
2005-08-01 14:34:30 +00:00
}
2005-05-16 22:22:31 +00:00
2005-11-21 07:33:04 +00:00
return $str ;
2005-05-16 22:22:31 +00:00
}
2005-08-01 14:34:30 +00:00
2005-12-12 17:32:00 +00:00
2005-11-21 07:33:04 +00:00
/**
* Shows config form & errors
*
* @ param object $frm
2005-12-09 12:00:28 +00:00
* @ access public
2005-11-21 07:33:04 +00:00
*/
2007-11-07 10:24:35 +00:00
public function config_form ( $frm )
2005-12-09 12:00:28 +00:00
{
2008-06-05 14:06:39 +00:00
global $CFG , $DB ;
2006-11-29 11:05:56 +00:00
$mconfig = get_config ( 'enrol/authorize' );
2005-11-21 07:33:04 +00:00
2008-02-05 17:05:29 +00:00
if ( ! check_curl_available ()) {
notify ( 'PHP must be compiled with cURL+SSL support (--with-curl --with-openssl)' );
2005-11-21 07:33:04 +00:00
}
2005-05-25 16:27:53 +00:00
2006-05-30 08:32:43 +00:00
if ( empty ( $CFG -> loginhttps ) and substr ( $CFG -> wwwroot , 0 , 5 ) !== 'https' ) {
2006-11-01 12:36:19 +00:00
$a = new stdClass ;
$a -> url = " $CFG->wwwroot / $CFG->admin /settings.php?section=httpsecurity " ;
2007-02-09 07:47:14 +00:00
notify ( get_string ( 'adminconfighttps' , 'enrol_authorize' , $a ));
return ; // notice breaks the form and xhtml later
2006-11-01 12:36:19 +00:00
}
2007-06-15 17:40:58 +00:00
elseif ( isset ( $_SERVER [ 'SERVER_PORT' ]) && $_SERVER [ 'SERVER_PORT' ] != 443 ) { // MDL-9836
2006-11-01 12:36:19 +00:00
$wwwsroot = qualified_me ();
$wwwsroot = str_replace ( 'http:' , 'https:' , $wwwsroot );
$a = new stdClass ;
$a -> url = $wwwsroot ;
2007-02-09 07:47:14 +00:00
notify ( get_string ( 'adminconfighttpsgo' , 'enrol_authorize' , $a ));
return ; // notice breaks the form and xhtml later
2006-01-03 10:23:28 +00:00
}
2006-01-19 14:57:23 +00:00
2008-01-18 10:43:21 +00:00
if ( optional_param ( 'verifyaccount' , 0 , PARAM_INT )) {
notify ( authorize_verify_account ());
2008-01-16 17:19:30 +00:00
}
2006-01-19 14:57:23 +00:00
if ( ! empty ( $frm -> an_review )) {
$captureday = intval ( $frm -> an_capture_day );
$emailexpired = intval ( $frm -> an_emailexpired );
if ( $captureday > 0 || $emailexpired > 0 ) {
2008-06-05 14:18:21 +00:00
$lastcron = $DB -> get_field_sql ( 'SELECT max(lastcron) FROM {modules}' );
2008-03-10 11:05:46 +00:00
if (( time () - intval ( $lastcron ) > 3600 * 24 )) {
2006-01-19 14:57:23 +00:00
notify ( get_string ( 'admincronsetup' , 'enrol_authorize' ));
}
2006-01-03 10:23:28 +00:00
}
}
2008-06-05 14:06:39 +00:00
if (( $count = $DB -> count_records ( 'enrol_authorize' , array ( 'status' => AN_STATUS_AUTH )))) {
2006-06-01 07:47:22 +00:00
$a = new stdClass ;
2006-01-19 14:57:23 +00:00
$a -> count = $count ;
$a -> url = $CFG -> wwwroot . " /enrol/authorize/index.php?status= " . AN_STATUS_AUTH ;
notify ( get_string ( 'adminpendingorders' , 'enrol_authorize' , $a ));
}
2005-11-21 07:33:04 +00:00
if ( data_submitted ()) {
2006-11-29 11:05:56 +00:00
if ( empty ( $mconfig -> an_login )) {
2005-11-21 07:33:04 +00:00
notify ( " an_login required " );
}
2006-11-29 11:05:56 +00:00
if ( empty ( $mconfig -> an_tran_key ) && empty ( $mconfig -> an_password )) {
2005-11-21 07:33:04 +00:00
notify ( " an_tran_key or an_password required " );
}
2005-07-13 20:26:16 +00:00
}
2005-05-16 22:22:31 +00:00
2006-11-15 07:39:04 +00:00
include ( $CFG -> dirroot . '/enrol/authorize/config_form.php' );
2005-05-25 16:27:53 +00:00
}
2005-08-03 10:11:16 +00:00
2005-12-12 17:32:00 +00:00
2005-11-21 07:33:04 +00:00
/**
* process_config
*
* @ param object $config
* @ return bool true if it will be saved .
2005-12-09 12:00:28 +00:00
* @ access public
2005-11-21 07:33:04 +00:00
*/
2007-11-07 10:24:35 +00:00
public function process_config ( $config )
2005-12-09 12:00:28 +00:00
{
2008-06-05 14:18:21 +00:00
global $CFG , $DB ;
2006-11-29 11:05:56 +00:00
$mconfig = get_config ( 'enrol/authorize' );
2005-12-12 17:32:00 +00:00
2006-02-01 13:30:45 +00:00
// site settings
2006-07-25 17:38:32 +00:00
if (( $cost = optional_param ( 'enrol_cost' , 5 , PARAM_INT )) > 0 ) {
set_config ( 'enrol_cost' , $cost );
}
2006-01-19 14:57:23 +00:00
set_config ( 'enrol_currency' , optional_param ( 'enrol_currency' , 'USD' , PARAM_ALPHA ));
2006-06-01 07:47:22 +00:00
set_config ( 'enrol_mailstudents' , optional_param ( 'enrol_mailstudents' , 0 , PARAM_BOOL ));
set_config ( 'enrol_mailteachers' , optional_param ( 'enrol_mailteachers' , 0 , PARAM_BOOL ));
set_config ( 'enrol_mailadmins' , optional_param ( 'enrol_mailadmins' , 0 , PARAM_BOOL ));
2006-05-05 18:16:45 +00:00
2006-02-01 13:30:45 +00:00
// optional authorize.net settings
2006-06-01 07:47:22 +00:00
set_config ( 'an_avs' , optional_param ( 'an_avs' , 0 , PARAM_BOOL ));
If an user's credit card cannot be captured on the internet directly, obtain authorization code over phone from customer's bank.
Some users may not wish to use their credit cards on the internet directly for security reasons.
In this case, you need to obtain an authorization code from user's bank.
Initially, ask for credit card information from the customer
like bank name, name on card, card number, expiry date and card validation code
by means of phone, face-to-face or a billing application.
Then, call the customer services of user's bank giving this information and demand an authorization code.
Finally, after obtaining it, login as user to get the user enrolled.
Alternatively, you can give it to the user saying enrol using this code.
2006-10-30 12:53:15 +00:00
set_config ( 'an_authcode' , optional_param ( 'an_authcode' , 0 , PARAM_BOOL ));
2006-06-01 07:47:22 +00:00
set_config ( 'an_test' , optional_param ( 'an_test' , 0 , PARAM_BOOL ));
2006-01-19 14:57:23 +00:00
set_config ( 'an_referer' , optional_param ( 'an_referer' , 'http://' , PARAM_URL ));
2006-02-01 13:03:13 +00:00
2006-09-02 11:49:02 +00:00
$acceptmethods = optional_param ( 'acceptmethods' , get_list_of_payment_methods (), PARAM_ALPHA );
2006-08-30 10:29:10 +00:00
set_config ( 'an_acceptmethods' , implode ( ',' , $acceptmethods ));
2006-09-02 11:49:02 +00:00
$acceptccs = optional_param ( 'acceptccs' , array_keys ( get_list_of_creditcards ()), PARAM_ALPHA );
2006-06-01 07:47:22 +00:00
set_config ( 'an_acceptccs' , implode ( ',' , $acceptccs ));
2006-09-04 12:09:30 +00:00
$acceptechecktypes = optional_param ( 'acceptechecktypes' , get_list_of_bank_account_types (), PARAM_ALPHA );
set_config ( 'an_acceptechecktypes' , implode ( ',' , $acceptechecktypes ));
2006-06-01 07:47:22 +00:00
2006-02-01 13:03:13 +00:00
$cutoff_hour = optional_param ( 'an_cutoff_hour' , 0 , PARAM_INT );
$cutoff_min = optional_param ( 'an_cutoff_min' , 5 , PARAM_INT );
set_config ( 'an_cutoff' , $cutoff_hour * 60 + $cutoff_min );
2006-01-19 14:57:23 +00:00
2006-02-01 13:30:45 +00:00
// cron depencies
2006-06-01 07:47:22 +00:00
$reviewval = optional_param ( 'an_review' , 0 , PARAM_BOOL );
2006-01-19 14:57:23 +00:00
$captureday = optional_param ( 'an_capture_day' , 5 , PARAM_INT );
$emailexpired = optional_param ( 'an_emailexpired' , 2 , PARAM_INT );
2006-06-14 11:53:50 +00:00
$emailexpiredteacher = optional_param ( 'an_emailexpiredteacher' , 0 , PARAM_BOOL );
2006-06-15 12:55:39 +00:00
$sorttype = optional_param ( 'an_sorttype' , 'ttl' , PARAM_ALPHA );
2006-01-19 14:57:23 +00:00
$captureday = ( $captureday > 29 ) ? 29 : (( $captureday < 0 ) ? 0 : $captureday );
$emailexpired = ( $emailexpired > 5 ) ? 5 : (( $emailexpired < 0 ) ? 0 : $emailexpired );
2006-09-02 11:49:02 +00:00
if ( ! empty ( $reviewval ) && ( $captureday > 0 || $emailexpired > 0 )) {
2008-06-05 14:18:21 +00:00
$lastcron = $DB -> get_field_sql ( 'SELECT max(lastcron) FROM {modules}' );
2008-03-10 11:05:46 +00:00
if ( time () - intval ( $lastcron ) > 3600 * 24 ) {
2006-09-02 11:49:02 +00:00
return false ;
}
2005-07-18 16:42:30 +00:00
}
2005-12-12 17:32:00 +00:00
2006-01-19 14:57:23 +00:00
set_config ( 'an_review' , $reviewval );
set_config ( 'an_capture_day' , $captureday );
set_config ( 'an_emailexpired' , $emailexpired );
2006-06-14 11:53:50 +00:00
set_config ( 'an_emailexpiredteacher' , $emailexpiredteacher );
2006-06-15 12:55:39 +00:00
set_config ( 'an_sorttype' , $sorttype );
2006-01-19 14:57:23 +00:00
2006-07-31 12:45:34 +00:00
// https and openssl library is required
2008-02-05 17:05:29 +00:00
if (( substr ( $CFG -> wwwroot , 0 , 5 ) !== 'https' and empty ( $CFG -> loginhttps )) or ! check_curl_available ()) {
2006-07-31 12:45:34 +00:00
return false ;
}
2006-11-29 11:05:56 +00:00
// REQUIRED fields;
// an_login
2006-01-19 14:57:23 +00:00
$loginval = optional_param ( 'an_login' , '' );
2006-11-29 11:05:56 +00:00
if ( empty ( $loginval ) && empty ( $mconfig -> an_login )) {
2006-08-30 14:16:45 +00:00
return false ;
2006-07-31 12:45:34 +00:00
}
2006-11-29 11:05:56 +00:00
$loginval = ! empty ( $loginval ) ? rc4encrypt ( $loginval ) : strval ( $mconfig -> an_login );
set_config ( 'an_login' , $loginval , 'enrol/authorize' );
2006-07-31 12:45:34 +00:00
2006-11-29 11:05:56 +00:00
// an_tran_key, an_password
2006-01-19 14:57:23 +00:00
$tranval = optional_param ( 'an_tran_key' , '' );
2006-11-29 11:05:56 +00:00
$tranval = ! empty ( $tranval ) ? rc4encrypt ( $tranval ) : ( isset ( $mconfig -> an_tran_key ) ? $mconfig -> an_tran_key : '' );
2006-01-19 14:57:23 +00:00
$passwordval = optional_param ( 'an_password' , '' );
2006-11-29 11:05:56 +00:00
$passwordval = ! empty ( $passwordval ) ? rc4encrypt ( $passwordval ) : ( isset ( $mconfig -> an_password ) ? $mconfig -> an_password : '' );
$deletecurrent = optional_param ( 'delete_current' , '0' , PARAM_BOOL );
if ( ! empty ( $deletecurrent ) and ! empty ( $tranval )) {
unset_config ( 'an_password' , 'enrol/authorize' );
$passwordval = '' ;
2006-07-31 12:45:34 +00:00
}
2006-11-29 11:05:56 +00:00
elseif ( ! empty ( $passwordval )) {
set_config ( 'an_password' , $passwordval , 'enrol/authorize' );
2006-07-31 12:45:34 +00:00
}
2006-11-29 11:05:56 +00:00
if ( empty ( $tranval ) and empty ( $passwordval )) {
2006-01-19 14:57:23 +00:00
return false ;
}
2006-11-29 11:05:56 +00:00
if ( ! empty ( $tranval )) {
set_config ( 'an_tran_key' , $tranval , 'enrol/authorize' );
}
2006-01-19 14:57:23 +00:00
2005-11-24 13:07:35 +00:00
return true ;
2005-05-25 16:27:53 +00:00
}
2005-05-13 09:05:39 +00:00
2005-12-09 12:00:28 +00:00
/**
2006-06-29 12:44:01 +00:00
* This function is run by admin / cron . php every time if admin has enabled this plugin .
*
* Everyday at settlement time ( default is 00 : 05 ), it cleans up some tables
* and sends email to admin / teachers about pending orders expiring if manual - capture has enabled .
*
* If admin set up 'Order review' and 'Capture day' , it captures credits cards and enrols students .
*
2005-12-09 12:00:28 +00:00
* @ access public
*/
2007-11-07 10:24:35 +00:00
public function cron ()
2005-12-09 12:00:28 +00:00
{
2008-06-05 14:06:39 +00:00
global $CFG , $DB ;
2005-12-09 12:00:28 +00:00
2006-01-19 14:57:23 +00:00
$oneday = 86400 ;
2005-11-21 14:09:52 +00:00
$timenow = time ();
2008-03-03 16:04:32 +00:00
$settlementtime = AuthorizeNet :: getsettletime ( $timenow );
2006-06-20 17:22:00 +00:00
$timediff30 = $settlementtime - ( 30 * $oneday );
2006-01-19 14:57:23 +00:00
$mconfig = get_config ( 'enrol/authorize' );
2005-12-26 19:21:37 +00:00
2006-07-06 13:41:55 +00:00
mtrace ( " Processing authorize cron... " );
2006-06-20 17:22:00 +00:00
if ( intval ( $mconfig -> an_dailysettlement ) < $settlementtime ) {
set_config ( 'an_dailysettlement' , $settlementtime , 'enrol/authorize' );
2008-02-05 17:05:29 +00:00
mtrace ( " Daily cron: " );
2006-07-06 12:01:24 +00:00
$this -> cron_daily ();
2008-02-05 17:05:29 +00:00
mtrace ( " Done " );
2006-01-19 14:57:23 +00:00
}
2008-02-05 17:05:29 +00:00
mtrace ( " Scheduled capture " , " : " );
if ( empty ( $CFG -> an_review ) or ( ! empty ( $CFG -> an_test )) or ( intval ( $CFG -> an_capture_day ) < 1 ) or ( ! check_curl_available ())) {
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
mtrace ( " disabled " );
2006-07-06 12:01:24 +00:00
return ; // order review disabled or test mode or manual capture or openssl wasn't loaded.
2005-12-09 12:00:28 +00:00
}
2005-08-24 14:59:42 +00:00
2006-06-20 17:22:00 +00:00
$timediffcnf = $settlementtime - ( intval ( $CFG -> an_capture_day ) * $oneday );
2008-06-05 14:06:39 +00:00
$select = " (status = ?) AND (timecreated < ?) AND (timecreated > ?) " ;
$params = array ( AN_STATUS_AUTH , $timediffcnf , $timediff30 );
if ( ! ( $ordercount = $DB -> count_records_select ( 'enrol_authorize' , $select , $params ))) {
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
mtrace ( " no pending orders " );
2005-12-26 19:21:37 +00:00
return ;
}
2006-01-19 14:57:23 +00:00
$eachconn = intval ( $mconfig -> an_eachconnsecs );
2008-03-05 17:09:05 +00:00
$eachconn = (( $eachconn > 60 ) ? 60 : (( $eachconn <= 0 ) ? 3 : $eachconn ));
2006-01-19 14:57:23 +00:00
if (( $ordercount * $eachconn ) + intval ( $mconfig -> an_lastcron ) > $timenow ) {
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
mtrace ( " blocked " );
2006-01-19 14:57:23 +00:00
return ;
2005-12-26 19:21:37 +00:00
}
2008-03-10 11:05:46 +00:00
set_config ( 'an_lastcron' , $timenow , 'enrol/authorize' );
2005-12-26 19:21:37 +00:00
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
mtrace ( " $ordercount orders are being processed now " , " : " );
2006-07-06 13:41:55 +00:00
2005-12-26 19:21:37 +00:00
$faults = '' ;
2006-01-02 09:45:07 +00:00
$sendem = array ();
2005-12-26 19:21:37 +00:00
$elapsed = time ();
@ set_time_limit ( 0 );
$this -> log = " AUTHORIZE.NET AUTOCAPTURE CRON: " . userdate ( $timenow ) . " \n " ;
2006-03-09 11:35:54 +00:00
2006-09-22 16:19:53 +00:00
$lastcourseid = 0 ;
2008-06-11 18:10:39 +00:00
$rs = $DB -> get_recordset_select ( 'enrol_authorize' , $select , $params , 'courseid' );
2008-06-05 14:06:39 +00:00
foreach ( $rs as $order )
2008-03-05 17:09:05 +00:00
{
2005-12-26 19:21:37 +00:00
$message = '' ;
$extra = NULL ;
2008-03-03 16:04:32 +00:00
if ( AN_APPROVED == AuthorizeNet :: process ( $order , $message , $extra , AN_ACTION_PRIOR_AUTH_CAPTURE )) {
2006-09-22 16:19:53 +00:00
if ( $lastcourseid != $order -> courseid ) {
$lastcourseid = $order -> courseid ;
2008-06-05 14:06:39 +00:00
$course = $DB -> get_record ( 'course' , array ( 'id' => $lastcourseid ));
2006-09-22 16:19:53 +00:00
$role = get_default_course_role ( $course );
$context = get_context_instance ( CONTEXT_COURSE , $lastcourseid );
}
2006-09-22 14:04:11 +00:00
$timestart = $timeend = 0 ;
if ( $course -> enrolperiod ) {
$timestart = $timenow ;
$timeend = $order -> settletime + $course -> enrolperiod ;
}
2008-06-05 14:06:39 +00:00
$user = $DB -> get_record ( 'user' , array ( 'id' => $order -> userid ));
2008-02-05 17:34:36 +00:00
if ( role_assign ( $role -> id , $user -> id , 0 , $context -> id , $timestart , $timeend , 0 , 'authorize' )) {
2006-09-22 14:04:11 +00:00
$this -> log .= " User( $user->id ) has been enrolled to course( $course->id ). \n " ;
2006-01-19 14:57:23 +00:00
if ( ! empty ( $CFG -> enrol_mailstudents )) {
$sendem [] = $order -> id ;
}
2005-12-26 19:21:37 +00:00
}
else {
2006-09-22 14:04:11 +00:00
$faults .= " Error while trying to enrol " . fullname ( $user ) . " in ' $course->fullname ' \n " ;
2005-12-26 19:21:37 +00:00
foreach ( $order as $okey => $ovalue ) {
$faults .= " $okey = $ovalue\n " ;
}
2005-12-09 12:00:28 +00:00
}
}
2006-01-19 14:57:23 +00:00
else {
2006-07-10 10:17:23 +00:00
$this -> log .= " Error, Order# $order->id : " . $message . " \n " ;
2005-12-09 12:00:28 +00:00
}
}
2008-06-05 14:06:39 +00:00
$rs -> close ();
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
mtrace ( " processed " );
2005-12-26 19:21:37 +00:00
$timenow = time ();
$elapsed = $timenow - $elapsed ;
2006-01-19 14:57:23 +00:00
$eachconn = ceil ( $elapsed / $ordercount );
set_config ( 'an_eachconnsecs' , $eachconn , 'enrol/authorize' );
2005-12-26 19:21:37 +00:00
$this -> log .= " AUTHORIZE.NET CRON FINISHED: " . userdate ( $timenow );
$adminuser = get_admin ();
if ( ! empty ( $faults )) {
2008-07-24 08:38:03 +00:00
$eventdata = new object ();
$eventdata -> modulename = 'moodle' ;
$eventdata -> userfrom = $adminuser ;
$eventdata -> userto = $adminuser ;
$eventdata -> subject = " AUTHORIZE.NET CRON FAULTS " ;
$eventdata -> fullmessage = $faults ;
$eventdata -> fullmessageformat = FORMAT_PLAIN ;
$eventdata -> fullmessagehtml = '' ;
$eventdata -> smallmessage = '' ;
events_trigger ( 'message_send' , $eventdata );
2005-12-26 19:21:37 +00:00
}
if ( ! empty ( $CFG -> enrol_mailadmins )) {
2008-07-24 08:38:03 +00:00
$eventdata = new object ();
$eventdata -> modulename = 'moodle' ;
$eventdata -> userfrom = $adminuser ;
$eventdata -> userto = $adminuser ;
$eventdata -> subject = " AUTHORIZE.NET CRON LOG " ;
$eventdata -> fullmessage = $this -> log ;
$eventdata -> fullmessageformat = FORMAT_PLAIN ;
$eventdata -> fullmessagehtml = '' ;
$eventdata -> smallmessage = '' ;
events_trigger ( 'message_send' , $eventdata );
2005-12-26 19:21:37 +00:00
}
2006-07-06 12:01:24 +00:00
// Send emails to students about which courses have enrolled.
2006-10-16 09:39:08 +00:00
if ( ! empty ( $sendem )) {
mtrace ( " sending welcome messages to students " , " : " );
send_welcome_messages ( $sendem );
mtrace ( " sent " );
2006-01-02 09:45:07 +00:00
}
2006-07-06 12:01:24 +00:00
}
/**
* Daily cron . It executes at settlement time ( default is 00 : 05 ) .
*
* @ access private
*/
2007-11-07 10:24:35 +00:00
private function cron_daily ()
2006-07-06 12:01:24 +00:00
{
2008-06-05 14:06:39 +00:00
global $CFG , $SITE , $DB ;
2006-07-06 12:01:24 +00:00
$oneday = 86400 ;
$timenow = time ();
2006-11-20 14:48:16 +00:00
$onepass = $timenow - $oneday ;
2008-03-03 16:04:32 +00:00
$settlementtime = AuthorizeNet :: getsettletime ( $timenow );
2006-07-06 12:01:24 +00:00
$timediff30 = $settlementtime - ( 30 * $oneday );
2008-06-05 14:06:39 +00:00
$select = " (status=?) AND (timecreated<?) " ;
$params = array ( AN_STATUS_NONE , $timediff30 );
if ( $DB -> delete_records_select ( 'enrol_authorize' , $select , $params )) {
2008-02-05 17:05:29 +00:00
mtrace ( " orders no transaction made have deleted " );
}
2006-07-06 12:01:24 +00:00
2008-06-05 14:06:39 +00:00
$select = " (status=?) AND (timecreated<?) " ;
$params = array ( AN_STATUS_EXPIRE , AN_STATUS_AUTH , $timediff30 );
2008-07-05 12:22:57 +00:00
if ( $DB -> execute ( " UPDATE { enrol_authorize} SET status=? WHERE $select " , $params )) {
2008-02-05 17:05:29 +00:00
mtrace ( " pending orders to expire have updated " );
}
2006-07-06 12:01:24 +00:00
$timediff60 = $settlementtime - ( 60 * $oneday );
2008-06-05 14:06:39 +00:00
$select = " (status=?) AND (timecreated<?) " ;
2008-06-11 17:27:58 +00:00
$params = array ( AN_STATUS_EXPIRE , $timediff60 );
2008-06-05 14:06:39 +00:00
if ( $DB -> delete_records_select ( 'enrol_authorize' , $select , $params )) {
2008-02-05 17:05:29 +00:00
mtrace ( " orders expired older than 60 days have deleted " );
}
2006-07-06 12:01:24 +00:00
2006-11-20 14:48:16 +00:00
$adminuser = get_admin ();
2008-06-05 14:06:39 +00:00
$select = " status IN(?,?) AND (timecreated<?) AND (timecreated>?) " ;
2008-06-11 17:27:58 +00:00
$params = array ( AN_STATUS_UNDERREVIEW , AN_STATUS_APPROVEDREVIEW , $onepass , $timediff60 );
2008-06-05 14:06:39 +00:00
if (( $count = $DB -> count_records_select ( 'enrol_authorize' , $select , $params )) &&
2008-02-05 17:05:29 +00:00
( $csvusers = get_users_by_capability ( get_context_instance ( CONTEXT_SYSTEM ), 'enrol/authorize:uploadcsv' ))) {
2006-11-20 14:48:16 +00:00
$a = new stdClass ;
$a -> count = $count ;
$a -> course = $SITE -> shortname ;
$subject = get_string ( 'pendingechecksubject' , 'enrol_authorize' , $a );
$a = new stdClass ;
$a -> count = $count ;
$a -> url = $CFG -> wwwroot . '/enrol/authorize/uploadcsv.php' ;
$message = get_string ( 'pendingecheckemail' , 'enrol_authorize' , $a );
2008-02-05 17:05:29 +00:00
foreach ( $csvusers as $csvuser ) {
2008-07-24 08:38:03 +00:00
$eventdata = new object ();
$eventdata -> modulename = 'moodle' ;
$eventdata -> userfrom = $adminuser ;
$eventdata -> userto = $csvuser ;
$eventdata -> subject = $subject ;
$eventdata -> fullmessage = $message ;
$eventdata -> fullmessageformat = FORMAT_PLAIN ;
$eventdata -> fullmessagehtml = '' ;
$eventdata -> smallmessage = '' ;
events_trigger ( 'message_send' , $eventdata );
2008-02-05 17:05:29 +00:00
}
mtrace ( " users who have 'enrol/authorize:uploadcsv' were mailed " );
2006-11-20 14:48:16 +00:00
}
2006-10-16 09:39:08 +00:00
2008-02-05 17:05:29 +00:00
mtrace ( " early pending order warning email for manual capture " , " : " );
2006-07-06 12:01:24 +00:00
if ( empty ( $CFG -> an_emailexpired )) {
2008-02-05 17:05:29 +00:00
mtrace ( " not enabled " );
return ;
2006-07-06 12:01:24 +00:00
}
2008-02-05 17:05:29 +00:00
2006-07-06 12:01:24 +00:00
$timediffem = $settlementtime - (( 30 - intval ( $CFG -> an_emailexpired )) * $oneday );
2008-06-05 14:06:39 +00:00
$select = " (status=?) AND (timecreated<?) AND (timecreated>?) " ;
$params = array ( AN_STATUS_AUTH , $timediffem , $timediff30 );
$count = $DB -> count_records_select ( 'enrol_authorize' , $select , $params );
2006-07-06 12:01:24 +00:00
if ( ! $count ) {
2008-02-05 17:05:29 +00:00
mtrace ( " no orders prior to $CFG->an_emailexpired days " );
2006-07-06 12:01:24 +00:00
return ;
}
2008-02-05 17:05:29 +00:00
mtrace ( " $count orders prior to $CFG->an_emailexpired days " );
2006-07-06 12:01:24 +00:00
$a = new stdClass ;
$a -> pending = $count ;
$a -> days = $CFG -> an_emailexpired ;
$a -> course = $SITE -> shortname ;
$subject = get_string ( 'pendingorderssubject' , 'enrol_authorize' , $a );
$a = new stdClass ;
$a -> pending = $count ;
$a -> days = $CFG -> an_emailexpired ;
$a -> course = $SITE -> fullname ;
2006-11-02 13:34:52 +00:00
$a -> enrolurl = " $CFG->wwwroot / $CFG->admin /enrol_config.php?enrol=authorize " ;
2006-07-06 12:01:24 +00:00
$a -> url = $CFG -> wwwroot . '/enrol/authorize/index.php?status=' . AN_STATUS_AUTH ;
$message = get_string ( 'pendingordersemail' , 'enrol_authorize' , $a );
2008-08-07 11:42:09 +00:00
2008-07-24 08:38:03 +00:00
$eventdata = new object ();
$eventdata -> modulename = 'moodle' ;
$eventdata -> userfrom = $adminuser ;
$eventdata -> userto = $adminuser ;
$eventdata -> subject = $subject ;
$eventdata -> fullmessage = $message ;
$eventdata -> fullmessageformat = FORMAT_PLAIN ;
$eventdata -> fullmessagehtml = '' ;
2008-08-07 11:42:09 +00:00
$eventdata -> smallmessage = '' ;
2008-07-24 08:38:03 +00:00
events_trigger ( 'message_send' , $eventdata );
2008-02-05 17:05:29 +00:00
// Email to payment managers
2006-08-14 15:06:11 +00:00
if ( empty ( $CFG -> an_emailexpiredteacher )) {
return ; // email feature disabled for teachers.
2006-07-06 12:01:24 +00:00
}
$sorttype = empty ( $CFG -> an_sorttype ) ? 'ttl' : $CFG -> an_sorttype ;
2006-10-16 09:39:08 +00:00
$sql = " SELECT e.courseid, e.currency, c.fullname, c.shortname,
COUNT ( e . courseid ) AS cnt , SUM ( e . amount ) as ttl
2008-06-05 14:06:39 +00:00
FROM { enrol_authorize } e
INNER JOIN { course } c ON c . id = e . courseid
WHERE ( e . status = ? )
AND ( e . timecreated < ? )
AND ( e . timecreated > ? )
2006-10-16 09:39:08 +00:00
GROUP BY e . courseid
ORDER BY $sorttype DESC " ;
2008-06-05 14:06:39 +00:00
$params = array ( AN_STATUS_AUTH , $timediffem , $timediff30 );
2006-07-06 12:01:24 +00:00
2008-06-05 14:06:39 +00:00
$rs = $DB -> get_recordset_sql ( $sql , $params );
foreach ( $rs as $courseinfo )
2008-03-05 17:09:05 +00:00
{
2006-07-06 12:01:24 +00:00
$lastcourse = $courseinfo -> courseid ;
2006-08-29 13:59:35 +00:00
$context = get_context_instance ( CONTEXT_COURSE , $lastcourse );
2008-02-05 17:05:29 +00:00
if (( $paymentmanagers = get_users_by_capability ( $context , 'enrol/authorize:managepayments' ))) {
2006-07-06 12:01:24 +00:00
$a = new stdClass ;
$a -> course = $courseinfo -> shortname ;
$a -> pending = $courseinfo -> cnt ;
$a -> days = $CFG -> an_emailexpired ;
$subject = get_string ( 'pendingorderssubject' , 'enrol_authorize' , $a );
$a = new stdClass ;
$a -> course = $courseinfo -> fullname ;
$a -> pending = $courseinfo -> cnt ;
$a -> currency = $courseinfo -> currency ;
$a -> sumcost = $courseinfo -> ttl ;
$a -> days = $CFG -> an_emailexpired ;
2006-08-29 13:59:35 +00:00
$a -> url = $CFG -> wwwroot . '/enrol/authorize/index.php?course=' . $lastcourse . '&status=' . AN_STATUS_AUTH ;
2006-07-06 12:01:24 +00:00
$message = get_string ( 'pendingordersemailteacher' , 'enrol_authorize' , $a );
2006-08-29 13:59:35 +00:00
foreach ( $paymentmanagers as $paymentmanager ) {
2008-07-24 08:38:03 +00:00
$eventdata = new object ();
$eventdata -> modulename = 'moodle' ;
$eventdata -> userfrom = $adminuser ;
$eventdata -> userto = $paymentmanager ;
$eventdata -> subject = $subject ;
$eventdata -> fullmessage = $message ;
$eventdata -> fullmessageformat = FORMAT_PLAIN ;
$eventdata -> fullmessagehtml = '' ;
2008-08-07 11:42:09 +00:00
$eventdata -> smallmessage = '' ;
2008-07-24 08:38:03 +00:00
events_trigger ( 'message_send' , $eventdata );
2006-07-06 12:01:24 +00:00
}
}
2006-01-02 09:45:07 +00:00
}
2008-06-05 14:06:39 +00:00
$rs -> close ();
2005-12-09 12:00:28 +00:00
}
}
?>