Browse Source

Revert "for revert"

This reverts commit 9c2fccea01.
develop_fields
Flottertotte 10 years ago
parent
commit
d137d8e346
  1. 2448
      class.phpmailer.php
  2. 784
      class.smtp.php
  3. 37
      enrol.php
  4. 17
      lang/en/enrol_apply.php
  5. 49
      lib.php
  6. 201
      locallib.php
  7. 2
      version.php

2448
class.phpmailer.php

File diff suppressed because it is too large

784
class.smtp.php

@ -1,784 +0,0 @@
<?php
/**
* *************************************************************************
* * Apply Enrol **
* *************************************************************************
* @copyright emeneo.com **
* @link emeneo.com **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************
*/
class SMTP {
/**
* SMTP server port
* @var int
*/
public $SMTP_PORT = 25;
/**
* SMTP reply line ending
* @var string
*/
public $CRLF = "\r\n";
/**
* Sets whether debugging is turned on
* @var bool
*/
public $do_debug; // the level of debug to perform
/**
* Sets VERP use on/off (default is off)
* @var bool
*/
public $do_verp = false;
/**
* Sets the SMTP PHPMailer Version number
* @var string
*/
public $Version = '5.2';
/////////////////////////////////////////////////
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
private $smtp_conn; // the socket to the server
private $error; // error if any on the last call
private $helo_rply; // the reply the server sent to us for HELO
/**
* Initialize the class so that the data is in a known state.
* @access public
* @return void
*/
public function __construct() {
$this->smtp_conn = 0;
$this->error = null;
$this->helo_rply = null;
$this->do_debug = 0;
}
/////////////////////////////////////////////////
// CONNECTION FUNCTIONS
/////////////////////////////////////////////////
/**
* Connect to the server specified on the port specified.
* If the port is not specified use the default SMTP_PORT.
* If tval is specified then a connection will try and be
* established with the server for that number of seconds.
* If tval is not specified the default is 30 seconds to
* try on the connection.
*
* SMTP CODE SUCCESS: 220
* SMTP CODE FAILURE: 421
* @access public
* @return bool
*/
public function Connect($host, $port = 0, $tval = 30) {
// set the error val to null so there is no confusion
$this->error = null;
// make sure we are __not__ connected
if($this->connected()) {
// already connected, generate error
$this->error = array("error" => "Already connected to a server");
return false;
}
if(empty($port)) {
$port = $this->SMTP_PORT;
}
// connect to the smtp server
$this->smtp_conn = @fsockopen($host, // the host of the server
$port, // the port to use
$errno, // error number if any
$errstr, // error message if any
$tval); // give up after ? secs
// verify we connected properly
if(empty($this->smtp_conn)) {
$this->error = array("error" => "Failed to connect to server",
"errno" => $errno,
"errstr" => $errstr);
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
}
return false;
}
// SMTP server can take longer to respond, give longer timeout for first read
// Windows does not have support for this timeout function
if(substr(PHP_OS, 0, 3) != "WIN")
socket_set_timeout($this->smtp_conn, $tval, 0);
// get any announcement
$announce = $this->get_lines();
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';
}
return true;
}
/**
* Initiate a TLS communication with the server.
*
* SMTP CODE 220 Ready to start TLS
* SMTP CODE 501 Syntax error (no parameters allowed)
* SMTP CODE 454 TLS not available due to temporary reason
* @access public
* @return bool success
*/
public function StartTLS() {
$this->error = null; # to avoid confusion
if(!$this->connected()) {
$this->error = array("error" => "Called StartTLS() without being connected");
return false;
}
fputs($this->smtp_conn,"STARTTLS" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 220) {
$this->error =
array("error" => "STARTTLS not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
// Begin encrypted connection
if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
return false;
}
return true;
}
/**
* Performs SMTP authentication. Must be run after running the
* Hello() method. Returns true if successfully authenticated.
* @access public
* @return bool
*/
public function Authenticate($username, $password) {
// Start authentication
fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($code != 334) {
$this->error =
array("error" => "AUTH not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
// Send encoded username
fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($code != 334) {
$this->error =
array("error" => "Username not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
// Send encoded password
fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($code != 235) {
$this->error =
array("error" => "Password not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* Returns true if connected to a server otherwise false
* @access public
* @return bool
*/
public function Connected() {
if(!empty($this->smtp_conn)) {
$sock_status = socket_get_status($this->smtp_conn);
if($sock_status["eof"]) {
// the socket is valid but we are not connected
if($this->do_debug >= 1) {
echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
}
$this->Close();
return false;
}
return true; // everything looks good
}
return false;
}
/**
* Closes the socket and cleans up the state of the class.
* It is not considered good to use this function without
* first trying to use QUIT.
* @access public
* @return void
*/
public function Close() {
$this->error = null; // so there is no confusion
$this->helo_rply = null;
if(!empty($this->smtp_conn)) {
// close the connection and cleanup
fclose($this->smtp_conn);
$this->smtp_conn = 0;
}
}
/////////////////////////////////////////////////
// SMTP COMMANDS
/////////////////////////////////////////////////
/**
* Issues a data command and sends the msg_data to the server
* finializing the mail transaction. $msg_data is the message
* that is to be send with the headers. Each header needs to be
* on a single line followed by a <CRLF> with the message headers
* and the message body being seperated by and additional <CRLF>.
*
* Implements rfc 821: DATA <CRLF>
*
* SMTP CODE INTERMEDIATE: 354
* [data]
* <CRLF>.<CRLF>
* SMTP CODE SUCCESS: 250
* SMTP CODE FAILURE: 552,554,451,452
* SMTP CODE FAILURE: 451,554
* SMTP CODE ERROR : 500,501,503,421
* @access public
* @return bool
*/
public function Data($msg_data) {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Data() without being connected");
return false;
}
fputs($this->smtp_conn,"DATA" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 354) {
$this->error =
array("error" => "DATA command not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
/* the server is ready to accept data!
* according to rfc 821 we should not send more than 1000
* including the CRLF
* characters on a single line so we will break the data up
* into lines by \r and/or \n then if needed we will break
* each of those into smaller lines to fit within the limit.
* in addition we will be looking for lines that start with
* a period '.' and append and additional period '.' to that
* line. NOTE: this does not count towards limit.
*/
// normalize the line breaks so we know the explode works
$msg_data = str_replace("\r\n","\n",$msg_data);
$msg_data = str_replace("\r","\n",$msg_data);
$lines = explode("\n",$msg_data);
/* we need to find a good way to determine is headers are
* in the msg_data or if it is a straight msg body
* currently I am assuming rfc 822 definitions of msg headers
* and if the first field of the first line (':' sperated)
* does not contain a space then it _should_ be a header
* and we can process all lines before a blank "" line as
* headers.
*/
$field = substr($lines[0],0,strpos($lines[0],":"));
$in_headers = false;
if(!empty($field) && !strstr($field," ")) {
$in_headers = true;
}
$max_line_length = 998; // used below; set here for ease in change
while(list(,$line) = @each($lines)) {
$lines_out = null;
if($line == "" && $in_headers) {
$in_headers = false;
}
// ok we need to break this line up into several smaller lines
while(strlen($line) > $max_line_length) {
$pos = strrpos(substr($line,0,$max_line_length)," ");
// Patch to fix DOS attack
if(!$pos) {
$pos = $max_line_length - 1;
$lines_out[] = substr($line,0,$pos);
$line = substr($line,$pos);
} else {
$lines_out[] = substr($line,0,$pos);
$line = substr($line,$pos + 1);
}
/* if processing headers add a LWSP-char to the front of new line
* rfc 822 on long msg headers
*/
if($in_headers) {
$line = "\t" . $line;
}
}
$lines_out[] = $line;
// send the lines to the server
while(list(,$line_out) = @each($lines_out)) {
if(strlen($line_out) > 0)
{
if(substr($line_out, 0, 1) == ".") {
$line_out = "." . $line_out;
}
}
fputs($this->smtp_conn,$line_out . $this->CRLF);
}
}
// message data has been sent
fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 250) {
$this->error =
array("error" => "DATA not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* Sends the HELO command to the smtp server.
* This makes sure that we and the server are in
* the same known state.
*
* Implements from rfc 821: HELO <SP> <domain> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE ERROR : 500, 501, 504, 421
* @access public
* @return bool
*/
public function Hello($host = '') {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Hello() without being connected");
return false;
}
// if hostname for HELO was not specified send default
if(empty($host)) {
// determine appropriate default to send to server
$host = "localhost";
}
// Send extended hello first (RFC 2821)
if(!$this->SendHello("EHLO", $host)) {
if(!$this->SendHello("HELO", $host)) {
return false;
}
}
return true;
}
/**
* Sends a HELO/EHLO command.
* @access private
* @return bool
*/
private function SendHello($hello, $host) {
fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';
}
if($code != 250) {
$this->error =
array("error" => $hello . " not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
$this->helo_rply = $rply;
return true;
}
/**
* Starts a mail transaction from the email address specified in
* $from. Returns true if successful or false otherwise. If True
* the mail transaction is started and then one or more Recipient
* commands may be called followed by a Data command.
*
* Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE SUCCESS: 552,451,452
* SMTP CODE SUCCESS: 500,501,421
* @access public
* @return bool
*/
public function Mail($from) {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Mail() without being connected");
return false;
}
$useVerp = ($this->do_verp ? "XVERP" : "");
fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 250) {
$this->error =
array("error" => "MAIL not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* Sends the quit command to the server and then closes the socket
* if there is no error or the $close_on_error argument is true.
*
* Implements from rfc 821: QUIT <CRLF>
*
* SMTP CODE SUCCESS: 221
* SMTP CODE ERROR : 500
* @access public
* @return bool
*/
public function Quit($close_on_error = true) {
$this->error = null; // so there is no confusion
if(!$this->connected()) {
$this->error = array(
"error" => "Called Quit() without being connected");
return false;
}
// send the quit command to the server
fputs($this->smtp_conn,"quit" . $this->CRLF);
// get any good-bye messages
$byemsg = $this->get_lines();
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
}
$rval = true;
$e = null;
$code = substr($byemsg,0,3);
if($code != 221) {
// use e as a tmp var cause Close will overwrite $this->error
$e = array("error" => "SMTP server rejected quit command",
"smtp_code" => $code,
"smtp_rply" => substr($byemsg,4));
$rval = false;
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
}
}
if(empty($e) || $close_on_error) {
$this->Close();
}
return $rval;
}
/**
* Sends the command RCPT to the SMTP server with the TO: argument of $to.
* Returns true if the recipient was accepted false if it was rejected.
*
* Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
*
* SMTP CODE SUCCESS: 250,251
* SMTP CODE FAILURE: 550,551,552,553,450,451,452
* SMTP CODE ERROR : 500,501,503,421
* @access public
* @return bool
*/
public function Recipient($to) {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Recipient() without being connected");
return false;
}
fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 250 && $code != 251) {
$this->error =
array("error" => "RCPT not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* Sends the RSET command to abort and transaction that is
* currently in progress. Returns true if successful false
* otherwise.
*
* Implements rfc 821: RSET <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE ERROR : 500,501,504,421
* @access public
* @return bool
*/
public function Reset() {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Reset() without being connected");
return false;
}
fputs($this->smtp_conn,"RSET" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 250) {
$this->error =
array("error" => "RSET failed",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* Starts a mail transaction from the email address specified in
* $from. Returns true if successful or false otherwise. If True
* the mail transaction is started and then one or more Recipient
* commands may be called followed by a Data command. This command
* will send the message to the users terminal if they are logged
* in and send them an email.
*
* Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE SUCCESS: 552,451,452
* SMTP CODE SUCCESS: 500,501,502,421
* @access public
* @return bool
*/
public function SendAndMail($from) {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called SendAndMail() without being connected");
return false;
}
fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 250) {
$this->error =
array("error" => "SAML not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* This is an optional command for SMTP that this class does not
* support. This method is here to make the RFC821 Definition
* complete for this class and __may__ be implimented in the future
*
* Implements from rfc 821: TURN <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE FAILURE: 502
* SMTP CODE ERROR : 500, 503
* @access public
* @return bool
*/
public function Turn() {
$this->error = array("error" => "This method, TURN, of the SMTP ".
"is not implemented");
if($this->do_debug >= 1) {
echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
}
return false;
}
/**
* Get the current error
* @access public
* @return array
*/
public function getError() {
return $this->error;
}
/////////////////////////////////////////////////
// INTERNAL FUNCTIONS
/////////////////////////////////////////////////
/**
* Read in as many lines as possible
* either before eof or socket timeout occurs on the operation.
* With SMTP we can tell if we have more lines to read if the
* 4th character is '-' symbol. If it is a space then we don't
* need to read anything else.
* @access private
* @return string
*/
private function get_lines() {
$data = "";
while($str = @fgets($this->smtp_conn,515)) {
if($this->do_debug >= 4) {
echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';
echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';
}
$data .= $str;
if($this->do_debug >= 4) {
echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';
}
// if 4th character is a space, we are done reading, break the loop
if(substr($str,3,1) == " ") { break; }
}
return $data;
}
}
?>

37
enrol.php

@ -1,37 +0,0 @@
<?php
/**
* *************************************************************************
* * Apply Enrol **
* *************************************************************************
* @copyright emeneo.com **
* @link emeneo.com **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************
*/
class enrolment_plugin_apply {
/**
* Prints out the configuration form for this plugin. All we need
* to provide is the form fields. The <form> tags and submit button will
* be provided for us by Moodle.
*
* @param object $formdata Equal to the global $CFG variable, or if
* process_config() returned false, the form contents
* @return void
*/
public function config_form( $formdata ){
return;
}
/**
* Process the data from the configuration form.
*
* @param object $formdata
* @return boolean True if configuration was successful, False if the user
* should be kicked back to config_form() again.
*/
public function process_config( $formdata ){
return true;
}
}
?>

17
lang/en/enrol_apply.php

@ -60,21 +60,4 @@ $string['city'] = 'City/town';
$string['country'] = 'Country';
$string['lang'] = 'Preferred language';
$string['description_editor'] = 'Description';
$string['firstnamephonetic'] = 'First name - phonetic';
$string['lastnamephonetic'] = 'Surname - phonetic';
$string['middlename'] = 'Middle name';
$string['alternatename'] = 'Alternate name';
$string['url'] = 'Web page';
$string['icq'] = 'ICQ number';
$string['skype'] = 'Skype ID';
$string['aim'] = 'AIM ID';
$string['yahoo'] = 'Yahoo ID';
$string['msn'] = 'MSN ID';
$string['idnumber'] = 'ID number';
$string['institution'] = 'Institution';
$string['department'] = 'Department';
$string['phone1'] = 'Phone';
$string['phone2'] = 'Mobile phone';
$string['address'] = 'Address';
?>

49
lib.php

@ -79,12 +79,8 @@ class enrol_apply_plugin extends enrol_plugin {
if ($instance->id == $instanceid) {
if ($data = $form->get_data()) {
$userInfo = $data;
$applydescription = $userInfo->applydescription;
unset($userInfo->applydescription);
$userInfo->id = $USER->id;
$res = $DB->update_record('user',$userInfo);
//echo "<pre>";print_r($userInfo);exit;
//var_dump($res);exit;
$enrol = enrol_get_plugin('self');
$timestart = time();
if ($instance->enrolperiod) {
@ -100,8 +96,8 @@ class enrol_apply_plugin extends enrol_plugin {
}
$this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend,1);
sendConfirmMailToTeachers($instance->courseid, $instance->id, $data, $applydescription);
sendConfirmMailToManagers($instance->courseid,$data, $applydescription);
sendConfirmMailToTeachers($instance->courseid, $instance->id, $data);
sendConfirmMailToManagers($instance->courseid,$data);
add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere!
redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid");
@ -272,7 +268,7 @@ function sendConfirmMail($info){
email_to_user($info, $contact, $apply_setting['confirmmailsubject']->value, html_to_text($body), $body);
}
function sendConfirmMailToTeachers($courseid,$instanceid,$info,$applydescription){
function sendConfirmMailToTeachers($courseid,$instanceid,$info){
global $DB;
global $CFG;
global $USER;
@ -287,7 +283,7 @@ function sendConfirmMailToTeachers($courseid,$instanceid,$info,$applydescription
$editTeacher = $DB->get_record('user',array('id'=>$teacher->userid));
$body = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>';
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$info->firstname.' '.$info->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$info->applydescription.'</p>';
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname', 'enrol_apply') .': '.$info->firstname.'</p>';
@ -298,23 +294,6 @@ function sendConfirmMailToTeachers($courseid,$instanceid,$info,$applydescription
$body .= '<p>'. get_string('lang', 'enrol_apply') .': '.$info->lang.'</p>';
$body .= '<p>'. get_string('description_editor', 'enrol_apply') .': '.$info->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic', 'enrol_apply') .': '.$info->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic', 'enrol_apply') .': '.$info->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename', 'enrol_apply') .': '.$info->middlename.'</p>';
$body .= '<p>'. get_string('alternatename', 'enrol_apply') .': '.$info->alternatename.'</p>';
$body .= '<p>'. get_string('url', 'enrol_apply') .': '.$info->url.'</p>';
$body .= '<p>'. get_string('icq', 'enrol_apply') .': '.$info->icq.'</p>';
$body .= '<p>'. get_string('skype', 'enrol_apply') .': '.$info->skype.'</p>';
$body .= '<p>'. get_string('aim', 'enrol_apply') .': '.$info->aim.'</p>';
$body .= '<p>'. get_string('yahoo', 'enrol_apply') .': '.$info->yahoo.'</p>';
$body .= '<p>'. get_string('msn', 'enrol_apply') .': '.$info->msn.'</p>';
$body .= '<p>'. get_string('idnumber', 'enrol_apply') .': '.$info->idnumber.'</p>';
$body .= '<p>'. get_string('institution', 'enrol_apply') .': '.$info->institution.'</p>';
$body .= '<p>'. get_string('department', 'enrol_apply') .': '.$info->department.'</p>';
$body .= '<p>'. get_string('phone1', 'enrol_apply') .': '.$info->phone1.'</p>';
$body .= '<p>'. get_string('phone2', 'enrol_apply') .': '.$info->phone2.'</p>';
$body .= '<p>'. get_string('address', 'enrol_apply') .': '.$info->address.'</p>';
$body .= '<p>'. html_writer::link(new moodle_url("/enrol/apply/apply.php", array('id'=>$courseid,'enrolid'=>$instanceid)), get_string('applymanage', 'enrol_apply')).'</p>';
$contact = core_user::get_support_user();
$info = $editTeacher;
@ -324,7 +303,7 @@ function sendConfirmMailToTeachers($courseid,$instanceid,$info,$applydescription
}
}
function sendConfirmMailToManagers($courseid,$info,$applydescription){
function sendConfirmMailToManagers($courseid,$info){
global $DB;
global $CFG;
global $USER;
@ -339,7 +318,7 @@ function sendConfirmMailToManagers($courseid,$info,$applydescription){
$userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid));
$body = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>';
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$info->firstname.' '.$info->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$info->applydescription.'</p>';
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname', 'enrol_apply') .': '.$info->firstname.'</p>';
$body .= '<p>'. get_string('lastname', 'enrol_apply') .': '.$info->lastname.'</p>';
@ -348,22 +327,6 @@ function sendConfirmMailToManagers($courseid,$info,$applydescription){
$body .= '<p>'. get_string('country', 'enrol_apply') .': '.$info->country.'</p>';
$body .= '<p>'. get_string('lang', 'enrol_apply') .': '.$info->lang.'</p>';
$body .= '<p>'. get_string('description_editor', 'enrol_apply') .': '.$info->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic', 'enrol_apply') .': '.$info->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic', 'enrol_apply') .': '.$info->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename', 'enrol_apply') .': '.$info->middlename.'</p>';
$body .= '<p>'. get_string('alternatename', 'enrol_apply') .': '.$info->alternatename.'</p>';
$body .= '<p>'. get_string('url', 'enrol_apply') .': '.$info->url.'</p>';
$body .= '<p>'. get_string('icq', 'enrol_apply') .': '.$info->icq.'</p>';
$body .= '<p>'. get_string('skype', 'enrol_apply') .': '.$info->skype.'</p>';
$body .= '<p>'. get_string('aim', 'enrol_apply') .': '.$info->aim.'</p>';
$body .= '<p>'. get_string('yahoo', 'enrol_apply') .': '.$info->yahoo.'</p>';
$body .= '<p>'. get_string('msn', 'enrol_apply') .': '.$info->msn.'</p>';
$body .= '<p>'. get_string('idnumber', 'enrol_apply') .': '.$info->idnumber.'</p>';
$body .= '<p>'. get_string('institution', 'enrol_apply') .': '.$info->institution.'</p>';
$body .= '<p>'. get_string('department', 'enrol_apply') .': '.$info->department.'</p>';
$body .= '<p>'. get_string('phone1', 'enrol_apply') .': '.$info->phone1.'</p>';
$body .= '<p>'. get_string('phone2', 'enrol_apply') .': '.$info->phone2.'</p>';
$body .= '<p>'. get_string('address', 'enrol_apply') .': '.$info->address.'</p>';
$body .= '<p>'. html_writer::link(new moodle_url('/enrol/apply/manage.php'), get_string('applymanage', 'enrol_apply')).'</p>';
$contact = core_user::get_support_user();
$info = $userWithManagerRole;

201
locallib.php

@ -37,7 +37,6 @@ class enrol_apply_enrol_form extends moodleform {
}
public function definition() {
global $DB;
$mform = $this->_form;
$instance = $this->_customdata;
$this->instance = $instance;
@ -67,93 +66,49 @@ class enrol_apply_enrol_form extends moodleform {
require_once($CFG->dirroot.'/user/profile/lib.php');
require_once($CFG->dirroot.'/user/lib.php');
$user = $DB->get_record('user',array('id'=>$USER->id));
$editoroptions = $filemanageroptions = null;
useredit_shared_definition($mform, $editoroptions, $filemanageroptions);
$user = $USER;
$personalcontext = context_user::instance($user->id);
//profile_load_data($user);
profile_definition($mform, $user->id);
$mform->addElement('header', 'selfheader', 'User profile');
//useredit_load_preferences($user, false);
$profile_default_values = $user;
if (is_object($profile_default_values)) {
$profile_default_values = (array)$profile_default_values;
}
$mform->setDefaults($profile_default_values);
$this->add_action_buttons(false, get_string('enrolme', 'enrol_self'));
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->setDefault('id', $instance->courseid);
$mform->addElement('hidden', 'instance');
$mform->setType('instance', PARAM_INT);
$mform->setDefault('instance', $instance->id);
}
public function validation($data, $files) {
global $DB, $CFG;
$errors = parent::validation($data, $files);
$instance = $this->instance;
if ($instance->password) {
if ($data['enrolpassword'] !== $instance->password) {
if ($instance->customint1) {
$groups = $DB->get_records('groups', array('courseid'=>$instance->courseid), 'id ASC', 'id, enrolmentkey');
$found = false;
foreach ($groups as $group) {
if (empty($group->enrolmentkey)) {
continue;
}
if ($group->enrolmentkey === $data['enrolpassword']) {
$found = true;
break;
}
$strrequired = get_string('required');
foreach (useredit_get_required_name_fields() as $fullname) {
$mform->addElement('text', $fullname, get_string($fullname), 'maxlength="100" size="30"');
$mform->addRule($fullname, $strrequired, 'required', null, 'client');
$mform->setType($fullname, PARAM_NOTAGS);
}
if (!$found) {
// we can not hint because there are probably multiple passwords
$errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
$enabledusernamefields = useredit_get_enabled_name_fields();
foreach ($enabledusernamefields as $addname) {
$mform->addElement('text', $addname, get_string($addname), 'maxlength="100" size="30"');
$mform->setType($addname, PARAM_NOTAGS);
}
//Do not show email field if change confirmation is pending
if (!empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) {
$notice = get_string('emailchangepending', 'auth', $user);
$notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id='.$user->id.'">'
. get_string('emailchangecancel', 'auth') . '</a>';
$mform->addElement('static', 'emailpending', get_string('email'), $notice);
} else {
$plugin = enrol_get_plugin('self');
if ($plugin->get_config('showhint')) {
$textlib = textlib_get_instance();
$hint = $textlib->substr($instance->password, 0, 1);
$errors['enrolpassword'] = get_string('passwordinvalidhint', 'enrol_self', $hint);
} else {
$errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
}
}
$mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
$mform->addRule('email', $strrequired, 'required', null, 'client');
$mform->setType('email', PARAM_EMAIL);
}
}
return $errors;
}
/**
* Adds user preferences elements to user edit form.
*
* @param stdClass $user
* @param moodleform $mform
* @param array|null $editoroptions
* @param array|null $filemanageroptions
*/
public function useredit_shared_definition_preferences($user, &$mform, $editoroptions = null, $filemanageroptions = null) {
global $CFG;
$choices = array();
$choices['0'] = get_string('emaildisplayno');
$choices['1'] = get_string('emaildisplayyes');
$choices['2'] = get_string('emaildisplaycourse');
$mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
//$mform->setDefault('maildisplay', $CFG->defaultpreference_maildisplay);
$mform->setDefault('maildisplay', 2);
$choices = array();
$choices['0'] = get_string('textformat');
$choices['1'] = get_string('htmlformat');
$mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
//$mform->setDefault('mailformat', $CFG->defaultpreference_mailformat);
$mform->setDefault('mailformat', 1);
if (!empty($CFG->allowusermailcharset)) {
$choices = array();
@ -172,21 +127,21 @@ public function useredit_shared_definition_preferences($user, &$mform, $editorop
$choices['1'] = get_string('emaildigestcomplete');
$choices['2'] = get_string('emaildigestsubjects');
$mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
//$mform->setDefault('maildigest', $CFG->defaultpreference_maildigest);
$mform->setDefault('maildigest', 0);
$mform->addHelpButton('maildigest', 'emaildigest');
$choices = array();
$choices['1'] = get_string('autosubscribeyes');
$choices['0'] = get_string('autosubscribeno');
$mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
//$mform->setDefault('autosubscribe', $CFG->defaultpreference_autosubscribe);
$mform->setDefault('autosubscribe', 1);
if (!empty($CFG->forum_trackreadposts)) {
$choices = array();
$choices['0'] = get_string('trackforumsno');
$choices['1'] = get_string('trackforumsyes');
$mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
//$mform->setDefault('trackforums', $CFG->defaultpreference_trackforums);
$mform->setDefault('trackforums', 0);
}
$editors = editors_get_enabled();
@ -208,8 +163,108 @@ public function useredit_shared_definition_preferences($user, &$mform, $editorop
$mform->setType('preference_htmleditor', PARAM_PLUGIN);
}
$mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
$mform->setType('city', PARAM_TEXT);
if (!empty($CFG->defaultcity)) {
$mform->setDefault('city', $CFG->defaultcity);
}
$choices = get_string_manager()->get_list_of_countries();
$choices= array(''=>get_string('selectacountry').'...') + $choices;
$mform->addElement('select', 'country', get_string('selectacountry'), $choices);
if (!empty($CFG->country)) {
$mform->setDefault('country', $CFG->country);
}
$choices = get_list_of_timezones();
$choices['99'] = get_string('serverlocaltime');
if ($CFG->forcetimezone != 99) {
$mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
} else {
$mform->addElement('select', 'timezone', get_string('timezone'), $choices);
$mform->setDefault('timezone', '99');
}
$mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
$mform->setDefault('lang', $CFG->lang);
// Multi-Calendar Support - see MDL-18375.
$calendartypes = \core_calendar\type_factory::get_list_of_calendar_types();
// We do not want to show this option unless there is more than one calendar type to display.
if (count($calendartypes) > 1) {
$mform->addElement('select', 'calendartype', get_string('preferredcalendar', 'calendar'), $calendartypes);
}
if (!empty($CFG->allowuserthemes)) {
$choices = array();
$choices[''] = get_string('default');
$themes = get_list_of_themes();
foreach ($themes as $key=>$theme) {
if (empty($theme->hidefromselector)) {
$choices[$key] = get_string('pluginname', 'theme_'.$theme->name);
}
}
$mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
}
$mform->addElement('editor', 'description_editor', get_string('userdescription'), null, null);
$mform->setType('description_editor', PARAM_CLEANHTML);
$profile_default_values = $user;
if (is_object($profile_default_values)) {
$profile_default_values = (array)$profile_default_values;
}
$mform->setDefaults($profile_default_values);
$this->add_action_buttons(false, get_string('enrolme', 'enrol_self'));
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->setDefault('id', $instance->courseid);
$mform->addElement('hidden', 'instance');
$mform->setType('instance', PARAM_INT);
$mform->setDefault('instance', $instance->id);
}
public function validation($data, $files) {
global $DB, $CFG;
$errors = parent::validation($data, $files);
$instance = $this->instance;
if ($instance->password) {
if ($data['enrolpassword'] !== $instance->password) {
if ($instance->customint1) {
$groups = $DB->get_records('groups', array('courseid'=>$instance->courseid), 'id ASC', 'id, enrolmentkey');
$found = false;
foreach ($groups as $group) {
if (empty($group->enrolmentkey)) {
continue;
}
if ($group->enrolmentkey === $data['enrolpassword']) {
$found = true;
break;
}
}
if (!$found) {
// we can not hint because there are probably multiple passwords
$errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
}
} else {
$plugin = enrol_get_plugin('self');
if ($plugin->get_config('showhint')) {
$textlib = textlib_get_instance();
$hint = $textlib->substr($instance->password, 0, 1);
$errors['enrolpassword'] = get_string('passwordinvalidhint', 'enrol_self', $hint);
} else {
$errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
}
}
}
}
return $errors;
}
}

2
version.php

@ -18,7 +18,7 @@
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2015032701;
$plugin->version = 2015012500;
$plugin->requires = 2011080100;
$plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Course Enrol Apply Plugin Version 1.3.1 (build 2014091000)';

Loading…
Cancel
Save