/enrol/mpay/forms.php
PHP | 323 lines | 249 code | 52 blank | 22 comment | 18 complexity | 33ae274e9bd270476a6c078810713c82 MD5 | raw file
- <?php
-
- /**
- * @desc MoodlePayments - Pay for a course enrolment
- * @since 1.8
- * @version 1.3
- * @author Luuk Verhoeven [luuk@sebsoft.nl] / Sebastian Berm [sebastian@sebsoft.nl]
- * @package enrol/mpay
- * @copyright Sebsoft.nl
- */
- defined('MOODLE_INTERNAL') || die();
- require_once($CFG->libdir . '/formslib.php');
-
- //Settings for course enrolment
- class enrol_mpay_edit_form extends moodleform
- {
-
- function definition()
- {
- global $CFG;
- $mform = $this->_form;
-
- list($instance, $plugin, $context) = $this->_customdata;
-
- $mform->addElement('header', 'header', get_string('pluginname', 'enrol_mpay'));
-
- $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
- $mform->setType('name', PARAM_RAW_TRIMMED);
- $mform->setDefault('name',get_string('pluginname', 'enrol_mpay'));
-
- $mform->addElement('duration', 'enrolperiod', get_string('defaultperiod', 'enrol_manual'), array('optional' => true, 'defaultunit' => 86400));
- $mform->setType('duration',PARAM_RAW_TRIMMED);
- $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod'));
-
- if ($instance->id)
- {
- $roles = get_default_enrol_roles($context, $instance->roleid);
- }
- else
- {
- $roles = get_default_enrol_roles($context, $plugin->get_config('roleid'));
- }
- $mform->addElement('select', 'roleid', get_string('defaultrole', 'role'), $roles);
- $mform->setDefault('roleid', $plugin->get_config('roleid'));
- $mform->setType('roleid',PARAM_INT);
-
- /* CURRENCIE */
- $arrayCurrencies = get_string_manager()->get_list_of_currencies();
- $default = empty($CFG->enrol_mpay_currency) ? 'EUR' : $CFG->enrol_mpay_currency;
- $mform->addElement('hidden', 'currency', $default);
- $mform->setType('currency',PARAM_RAW_TRIMMED);
-
- $currency = $arrayCurrencies[$default];
- $mform->addElement('html', '<div class="fitem"><div class="fitemtitle"></div><div class="felement ftext">' . $currency . '</div></div>');
- /* AMOUT SETTINGS */
- $mform->addElement('text', 'cost', get_string('amount', 'enrol_mpay') . " ($default)");
- $default = empty($CFG->enrol_mpay_amount) ? 10.99 : $CFG->enrol_mpay_amount;
- $mform->setDefault('cost', $default);
- $mform->setType('cost', PARAM_FLOAT);
-
- $mform->addElement('hidden', 'id');
- $mform->setType('id',PARAM_INT);
- $mform->addElement('hidden', 'courseid');
- $mform->setType('courseid',PARAM_INT);
-
- $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
- $this->set_data($instance);
- }
- }
-
- //User pay values sending to pay.nl
- class payForm extends moodleform
- {
-
- function definition()
- {
- global $USER, $CFG, $PAGE, $DB, $SITE;
- //get amount
- $mform = & $this->_form;
- $id = $this->_customdata['id'];
- $COURSE = $this->_customdata['course'];
-
- $enrolSettings = Mpay::getEnrolSettings($COURSE->id);
- //var_dump($enrolSettings);
- if ((float) $enrolSettings->cost < 0)
- {
- $cost = (float) $CFG->mpay_enrol_amount;
- }
- else
- {
- $cost = (float) $enrolSettings->cost;
- }
- $mform->addElement('header', 'heading', get_string('pluginname', 'enrol_mpay'));
-
- // Calculate displaycost
- $lang = current_language();
- $displaycost = "";
-
- switch ($lang)
- {
- case 'en': $displaycost = number_format($cost, 2, '.', ',');
- break;
- case 'nl': $displaycost = number_format($cost, 2, ',', ' ');
- break;
- case 'be': $displaycost = number_format($cost, 2, ',', ' ');
- break;
- default : $displaycost = number_format($cost, 2, '.', ',');
- break;
- }
- //TODO this is a value thats not used
- $prencent = !empty($CFG->enrol_mpay_coupon_percent) ? $CFG->enrol_mpay_coupon_percent : '';
-
- $paymentValidationString = base64_encode(str_rot13($enrolSettings->password)) . "-" .
- base64_encode($COURSE->fullname) . "-" .
- base64_encode($cost) . "-" .
- base64_encode($prencent) . "-" .
- base64_encode(str_rot13($CFG->enrol_mpay_websitecode));
-
- $vs = $paymentValidationString . "-" . md5($paymentValidationString); // Payment validation
-
- $mform->addElement('hidden', 'id', $id);
- $mform->setType('id',PARAM_INT);
- $mform->addElement('hidden', 'cmd', "initpayment");
- $mform->setType('cmd',PARAM_ALPHAEXT);
- $mform->addElement('hidden', 'charset', "utf-8");
- $mform->setType('charset',PARAM_RAW_TRIMMED);
-
- $mform->addElement('hidden', 'websitecode', $CFG->enrol_mpay_websitecode);
- $mform->setType('websitecode',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'course_fullname', $COURSE->fullname);
- $mform->setType('course_fullname',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'course_shortname', $COURSE->shortname);
- $mform->setType('course_shortname',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'studentname', fullname($USER));
- $mform->setType('studentname',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'user_id', $USER->id);
- $mform->setType('user_id',PARAM_INT);
- $mform->addElement('hidden', 'course_id', $COURSE->id);
- $mform->setType('course_id',PARAM_INT);
- $mform->addElement('hidden', 'currency', $enrolSettings->currency);
- $mform->setType('currency',PARAM_RAW_TRIMMED);
-
- $mform->addElement('hidden', 'amount', $cost);
- $mform->setType('amount',PARAM_RAW_TRIMMED);
-
- $mform->addElement('hidden', 'return_notify', "$CFG->wwwroot/enrol/mpay/mpsup.php");
- $mform->setType('return_notify',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'return_url', "$CFG->wwwroot/enrol/mpay/return.php?id=$COURSE->id");
- $mform->setType('return_url',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'return_cancel', $CFG->wwwroot);
- $mform->setType('return_cancel',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'continuemessage', get_string('continuetocourse', 'enrol_mpay'));
- $mform->setType('continuemessage',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'first_name', $USER->firstname);
- $mform->setType('first_name',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'last_name', $USER->lastname);
- $mform->setType('last_name',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'address', $USER->address);
- $mform->setType('address',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'city', $USER->city);
- $mform->setType('city',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'email', $USER->email);
- $mform->setType('email',PARAM_EMAIL);
- $country = $USER->country;
- if (strlen($country) == 0)
- {
- $country = "NL";
- }
- $mform->addElement('hidden', 'country', $country);
- $mform->setType('country',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'studentidnumber', $USER->idnumber);
- $mform->setType('studentidnumber',PARAM_ALPHANUMEXT);
- $mform->addElement('hidden', 'clientversion', '2011081002');
- $mform->setType('clientversion',PARAM_INT);
- $mform->addElement('hidden', 'moodleversion', $CFG->release);
- $mform->setType('moodleversion',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'language', current_language());
- $mform->setType('language',PARAM_RAW_TRIMMED);
-
- $mform->addElement('hidden', 'site_fullname', $SITE->fullname);
- $mform->setType('site_fullname',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'site_shortname', $SITE->shortname);
- $mform->setType('site_shortname',PARAM_RAW_TRIMMED);
- $mform->addElement('hidden', 'vs', $vs, array('id' => 'vsString'));
- $mform->setType('vs',PARAM_RAW);
-
- if (isset($CFG->enrol_mpay_enable_couponcode) && $CFG->enrol_mpay_enable_couponcode == 1)
- {
- //global is active now check if there is a coupon code avialable
- $result = Mpay::getAvailableCoupon($COURSE->id); //Workarround popup not working if its in formtags
- if ($result)
- {
- $mform->addElement('hidden', 'couponcode', '', array('id' => 'couponK'));
- $mform->setType('couponcode',PARAM_RAW);
- Mpay::setPopup($COURSE->id);
- }
- }
- //check if sandbox is on
- if (isset($CFG->enrol_mpay_sandbox) && $CFG->enrol_mpay_sandbox == 1)
- {
- $mform->addElement('hidden', 'sandbox', 1);
- $mform->setType('sandbox',PARAM_INT);
- }
-
- $list = Mpay::getmPayPaymentMethodList();
-
- if (count($list) == 0)
- {
- # Just show the default method
- $record = $DB->get_record('enrol_mpay_methods', array('systemname' => $CFG->enrol_mpay_default_payment_methode));
- Mpay::show_payment_method($record, true, false, $extra, $realtext);
- }
- else
- {
- foreach ($list as $method)
- {
- Mpay::show_payment_method($method, false, true, $extra, $realtext);
- }
- }
- $currency = Currencies::getCurrency($enrolSettings->currency);
- if ($enrolSettings->currency == $currency)
- {
- //shit we dont find symbol
- $currency = '<small>' . $currency . '</small>';
- }
- //var_dump(get_course_cost($enrolSettings));
- $mform->addElement('html', '<div id="mpayfinder"></div><div><h4>' . get_string('price-to-pay', 'enrol_mpay') . '<font style="text-decoration:underline;"> ' . $currency . ' ' . $displaycost . '</font><span style="font-size:13px;color:red" rel="' . $cost . '" id="discount"></span></h4>
- <div>' . $extra . '</div><div id="paymentselect">' . $realtext . '</div>');
-
- $mform->addElement('html', Mpay::displayPopup());
- $mform->addElement('submit', 'mpay_submit', get_string('startpaymentbutton', 'enrol_mpay'));
- }
-
- }
-
- class couponedit_form extends moodleform
- {
-
- function definition()
- {
- $mform = & $this->_form;
-
- $mform->addElement('hidden', 'id');
-
- $courselist = get_courses();
- $courses = array();
- $courses['0'] = get_string('entiresite', 'enrol_mpay');
- foreach ($courselist as $course)
- {
- $courses[$course->id] = $course->fullname;
- }
- $mform->addElement('select', 'courseid', get_string('course'), $courses);
- $mform->addElement('hidden', 'nooutput', 1);
-
- $mform->addElement('text', 'code', get_string('couponcode', 'enrol_mpay'), 'maxlength="15" size="15"');
- $mform->addRule('code', get_string('couponcodemissing', 'enrol_mpay'), 'required', null, 'client');
- $mform->setType('code', PARAM_TEXT);
-
- $mform->addElement('date_selector', 'validfrom', get_string('validfromform', 'enrol_mpay'));
- $mform->addRule('validfrom', get_string('validfrommissing', 'enrol_mpay'), 'required', null, 'client');
-
- $mform->addElement('date_selector', 'validto', get_string('validtoform', 'enrol_mpay'));
- $mform->addRule('validto', get_string('validtomissing', 'enrol_mpay'), 'required', null, 'client');
-
-
- $mform->addElement('text', 'percentage', get_string('percentage', 'enrol_mpay'));
- $mform->addRule('percentage', get_string('percentagemissing', 'enrol_mpay'), 'required', null, 'client');
-
- // Calender
-
- $this->add_action_buttons();
- }
-
- function validation($data, $files)
- {
- $errors = parent::validation($data, $files);
-
- if ($data['validfrom'] > $data['validto'])
- {
- $errors['validfrom'] = get_string('validfromhigherthanvalidto', 'enrol_mpay');
- }
-
- return $errors;
- }
-
- }
-
- class vatedit_form extends moodleform
- {
-
- function definition()
- {
- $mform = & $this->_form;
-
- $mform->addElement('hidden', 'id');
- $mform->setType('id', PARAM_INT);
-
- $courselist = get_courses();
- $courses = array();
- $courses['0'] = get_string('entiresite', 'enrol_mpay');
-
- foreach ($courselist as $course)
- {
- $courses[$course->id] = $course->fullname;
- }
-
- $mform->addElement('select', 'course', get_string('course'), $courses);
- $mform->setType('course', PARAM_INT);
- $mform->addElement('hidden', 'nooutput', 1);
- $mform->setType('nooutput', PARAM_INT);
- $mform->addElement('text', 'percentage', get_string('percentage', 'enrol_mpay'));
- $mform->setType('percentage', PARAM_FLOAT);
- $mform->addRule('percentage', get_string('percentagemissing', 'enrol_mpay'), 'required', null, 'client');
-
- $this->add_action_buttons();
- }
-
- function validation($data, $files)
- {
- $errors = parent::validation($data, $files);
- return $errors;
- }
- }