Browse Source
This is the latest version of the plugin before we started to use github seriously. We are looking forward to the github open source development methoddevelop_fields
Flottertotte
11 years ago
commit
d7792a869e
23 changed files with 4930 additions and 0 deletions
@ -0,0 +1,22 @@ |
|||
# Auto detect text files and perform LF normalization |
|||
* text=auto |
|||
|
|||
# Custom for Visual Studio |
|||
*.cs diff=csharp |
|||
*.sln merge=union |
|||
*.csproj merge=union |
|||
*.vbproj merge=union |
|||
*.fsproj merge=union |
|||
*.dbproj merge=union |
|||
|
|||
# Standard to msysgit |
|||
*.doc diff=astextplain |
|||
*.DOC diff=astextplain |
|||
*.docx diff=astextplain |
|||
*.DOCX diff=astextplain |
|||
*.dot diff=astextplain |
|||
*.DOT diff=astextplain |
|||
*.pdf diff=astextplain |
|||
*.PDF diff=astextplain |
|||
*.rtf diff=astextplain |
|||
*.RTF diff=astextplain |
@ -0,0 +1,215 @@ |
|||
################# |
|||
## Eclipse |
|||
################# |
|||
|
|||
*.pydevproject |
|||
.project |
|||
.metadata |
|||
bin/ |
|||
tmp/ |
|||
*.tmp |
|||
*.bak |
|||
*.swp |
|||
*~.nib |
|||
local.properties |
|||
.classpath |
|||
.settings/ |
|||
.loadpath |
|||
|
|||
# External tool builders |
|||
.externalToolBuilders/ |
|||
|
|||
# Locally stored "Eclipse launch configurations" |
|||
*.launch |
|||
|
|||
# CDT-specific |
|||
.cproject |
|||
|
|||
# PDT-specific |
|||
.buildpath |
|||
|
|||
|
|||
################# |
|||
## Visual Studio |
|||
################# |
|||
|
|||
## Ignore Visual Studio temporary files, build results, and |
|||
## files generated by popular Visual Studio add-ons. |
|||
|
|||
# User-specific files |
|||
*.suo |
|||
*.user |
|||
*.sln.docstates |
|||
|
|||
# Build results |
|||
|
|||
[Dd]ebug/ |
|||
[Rr]elease/ |
|||
x64/ |
|||
build/ |
|||
[Bb]in/ |
|||
[Oo]bj/ |
|||
|
|||
# MSTest test Results |
|||
[Tt]est[Rr]esult*/ |
|||
[Bb]uild[Ll]og.* |
|||
|
|||
*_i.c |
|||
*_p.c |
|||
*.ilk |
|||
*.meta |
|||
*.obj |
|||
*.pch |
|||
*.pdb |
|||
*.pgc |
|||
*.pgd |
|||
*.rsp |
|||
*.sbr |
|||
*.tlb |
|||
*.tli |
|||
*.tlh |
|||
*.tmp |
|||
*.tmp_proj |
|||
*.log |
|||
*.vspscc |
|||
*.vssscc |
|||
.builds |
|||
*.pidb |
|||
*.log |
|||
*.scc |
|||
|
|||
# Visual C++ cache files |
|||
ipch/ |
|||
*.aps |
|||
*.ncb |
|||
*.opensdf |
|||
*.sdf |
|||
*.cachefile |
|||
|
|||
# Visual Studio profiler |
|||
*.psess |
|||
*.vsp |
|||
*.vspx |
|||
|
|||
# Guidance Automation Toolkit |
|||
*.gpState |
|||
|
|||
# ReSharper is a .NET coding add-in |
|||
_ReSharper*/ |
|||
*.[Rr]e[Ss]harper |
|||
|
|||
# TeamCity is a build add-in |
|||
_TeamCity* |
|||
|
|||
# DotCover is a Code Coverage Tool |
|||
*.dotCover |
|||
|
|||
# NCrunch |
|||
*.ncrunch* |
|||
.*crunch*.local.xml |
|||
|
|||
# Installshield output folder |
|||
[Ee]xpress/ |
|||
|
|||
# DocProject is a documentation generator add-in |
|||
DocProject/buildhelp/ |
|||
DocProject/Help/*.HxT |
|||
DocProject/Help/*.HxC |
|||
DocProject/Help/*.hhc |
|||
DocProject/Help/*.hhk |
|||
DocProject/Help/*.hhp |
|||
DocProject/Help/Html2 |
|||
DocProject/Help/html |
|||
|
|||
# Click-Once directory |
|||
publish/ |
|||
|
|||
# Publish Web Output |
|||
*.Publish.xml |
|||
*.pubxml |
|||
|
|||
# NuGet Packages Directory |
|||
## TODO: If you have NuGet Package Restore enabled, uncomment the next line |
|||
#packages/ |
|||
|
|||
# Windows Azure Build Output |
|||
csx |
|||
*.build.csdef |
|||
|
|||
# Windows Store app package directory |
|||
AppPackages/ |
|||
|
|||
# Others |
|||
sql/ |
|||
*.Cache |
|||
ClientBin/ |
|||
[Ss]tyle[Cc]op.* |
|||
~$* |
|||
*~ |
|||
*.dbmdl |
|||
*.[Pp]ublish.xml |
|||
*.pfx |
|||
*.publishsettings |
|||
|
|||
# RIA/Silverlight projects |
|||
Generated_Code/ |
|||
|
|||
# Backup & report files from converting an old project file to a newer |
|||
# Visual Studio version. Backup files are not needed, because we have git ;-) |
|||
_UpgradeReport_Files/ |
|||
Backup*/ |
|||
UpgradeLog*.XML |
|||
UpgradeLog*.htm |
|||
|
|||
# SQL Server files |
|||
App_Data/*.mdf |
|||
App_Data/*.ldf |
|||
|
|||
############# |
|||
## Windows detritus |
|||
############# |
|||
|
|||
# Windows image file caches |
|||
Thumbs.db |
|||
ehthumbs.db |
|||
|
|||
# Folder config file |
|||
Desktop.ini |
|||
|
|||
# Recycle Bin used on file shares |
|||
$RECYCLE.BIN/ |
|||
|
|||
# Mac crap |
|||
.DS_Store |
|||
|
|||
|
|||
############# |
|||
## Python |
|||
############# |
|||
|
|||
*.py[co] |
|||
|
|||
# Packages |
|||
*.egg |
|||
*.egg-info |
|||
dist/ |
|||
build/ |
|||
eggs/ |
|||
parts/ |
|||
var/ |
|||
sdist/ |
|||
develop-eggs/ |
|||
.installed.cfg |
|||
|
|||
# Installer logs |
|||
pip-log.txt |
|||
|
|||
# Unit test / coverage reports |
|||
.coverage |
|||
.tox |
|||
|
|||
#Translations |
|||
*.mo |
|||
|
|||
#Mr Developer |
|||
.mr.developer.cfg |
@ -0,0 +1,5 @@ |
|||
How to install: |
|||
|
|||
1. extract file and put the /apply folder into the folder /enrol |
|||
|
|||
2. go to admin --> notifications and install the plugin |
@ -0,0 +1,86 @@ |
|||
<?php |
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
require ('../../config.php'); |
|||
require_once($CFG->dirroot.'/enrol/renderer.php'); |
|||
require_once($CFG->dirroot.'/enrol/locallib.php'); |
|||
require_once($CFG->dirroot.'/lib/outputcomponents.php'); |
|||
require_once ('lib.php'); |
|||
|
|||
$site = get_site (); |
|||
$systemcontext = get_context_instance ( CONTEXT_SYSTEM ); |
|||
|
|||
$id = required_param ( 'id', PARAM_INT ); // course id |
|||
$course = $DB->get_record ( 'course', array ('id' => $id ), '*', MUST_EXIST ); |
|||
$context = get_context_instance ( CONTEXT_COURSE, $course->id, MUST_EXIST ); |
|||
|
|||
require_login ( $course ); |
|||
require_capability ( 'moodle/course:enrolreview', $context ); |
|||
|
|||
$PAGE->set_url ( '/enrol/apply.php', array ('id' => $course->id ) ); |
|||
//$PAGE->set_context($systemcontext); |
|||
$PAGE->set_pagelayout ( 'admin' ); |
|||
$PAGE->set_heading ( $course->fullname ); |
|||
|
|||
$PAGE->navbar->add ( get_string ( 'confirmusers', 'enrol_apply' ) ); |
|||
$PAGE->set_title ( "$site->shortname: " . get_string ( 'confirmusers', 'enrol_apply' ) ); |
|||
|
|||
if (isset ( $_POST ['enrolid'] )) { |
|||
if ($_POST ['enrolid']) { |
|||
if ($_POST ['type'] == 'confirm') { |
|||
confirmEnrolment ( $_POST ['enrolid'] ); |
|||
} elseif ($_POST ['type'] == 'cancel') { |
|||
cancelEnrolment ( $_POST ['enrolid'] ); |
|||
} |
|||
redirect ( "$CFG->wwwroot/enrol/apply/apply.php?id=" . $id . "&enrolid=" . $_GET ['enrolid'] ); |
|||
} |
|||
} |
|||
|
|||
$enrols = getAllEnrolment ($id); |
|||
|
|||
echo $OUTPUT->header (); |
|||
echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) ); |
|||
echo '<form id="frmenrol" method="post" action="apply.php?id=' . $id . '&enrolid=' . $_GET ['enrolid'] . '">'; |
|||
echo '<input type="hidden" id="type" name="type" value="confirm">'; |
|||
echo '<table class="generalbox editcourse boxaligncenter"><tr class="header">'; |
|||
echo '<th class="header" scope="col"> </th>'; |
|||
echo '<th class="header" scope="col">' . get_string ( 'coursename', 'enrol_apply' ) . '</th>'; |
|||
echo '<th class="header" scope="col"> </th>'; |
|||
echo '<th class="header" scope="col">' . get_string ( 'applyuser', 'enrol_apply' ) . '</th>'; |
|||
echo '<th class="header" scope="col">' . get_string ( 'applyusermail', 'enrol_apply' ) . '</th>'; |
|||
echo '<th class="header" scope="col">' . get_string ( 'applydate', 'enrol_apply' ) . '</th>'; |
|||
echo '</tr>'; |
|||
foreach ( $enrols as $enrol ) { |
|||
$picture = get_user_picture($enrol->userid); |
|||
echo '<tr><td><input type="checkbox" name="enrolid[]" value="' . $enrol->id . '"></td>'; |
|||
echo '<td>' . $enrol->course . '</td>'; |
|||
echo '<td>' . $OUTPUT->render($picture) . '</td>'; |
|||
echo '<td>'.$enrol->firstname . ' ' . $enrol->lastname.'</td>'; |
|||
echo '<td>' . $enrol->email . '</td>'; |
|||
echo '<td>' . date ( "Y-m-d", $enrol->timecreated ) . '</td></tr>'; |
|||
} |
|||
echo '</table>'; |
|||
echo '<p align="center"><input type="button" value="' . get_string ( 'btnconfirm', 'enrol_apply' ) . '" onclick="doSubmit(\'confrim\');"> <input type="button" value="' . get_string ( 'btncancel', 'enrol_apply' ) . '" onclick="doSubmit(\'cancel\');"></p>'; |
|||
echo '</form>'; |
|||
echo '<script>function doSubmit(type){if(type=="cancel"){document.getElementById("type").value=type;}document.getElementById("frmenrol").submit();}</script>'; |
|||
echo $OUTPUT->footer (); |
|||
|
|||
|
|||
function get_user_picture($userid){ |
|||
global $DB; |
|||
|
|||
$extrafields[] = 'lastaccess'; |
|||
$ufields = user_picture::fields('u', $extrafields); |
|||
$sql = "SELECT DISTINCT $ufields FROM {user} u where u.id=$userid"; |
|||
|
|||
$user = $DB->get_record_sql($sql); |
|||
return new user_picture($user); |
|||
} |
File diff suppressed because it is too large
@ -0,0 +1,784 @@ |
|||
<?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; |
|||
} |
|||
|
|||
} |
|||
|
|||
?> |
@ -0,0 +1,66 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
|
|||
/** |
|||
* Capabilities for apply enrolment plugin. |
|||
* |
|||
* @package enrol |
|||
* @subpackage apply |
|||
* @copyright 2010 Petr Skoda {@link http://skodak.org} |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$capabilities = array( |
|||
|
|||
'enrol/apply:config' => array( |
|||
|
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_COURSE, |
|||
'archetypes' => array( |
|||
'editingteacher' => CAP_ALLOW, |
|||
'manager' => CAP_ALLOW, |
|||
) |
|||
), |
|||
|
|||
'enrol/apply:manage' => array( |
|||
|
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_COURSE, |
|||
'archetypes' => array( |
|||
'editingteacher' => CAP_ALLOW, |
|||
'manager' => CAP_ALLOW, |
|||
) |
|||
), |
|||
|
|||
'enrol/apply:unenrolapply' => array( |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_COURSE, |
|||
'archetypes' => array( |
|||
'student' => CAP_ALLOW, |
|||
) |
|||
), |
|||
|
|||
'enrol/apply:unenrol' => array( |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_COURSE, |
|||
'archetypes' => array( |
|||
'editingteacher' => CAP_ALLOW, |
|||
'manager' => CAP_ALLOW, |
|||
) |
|||
), |
|||
|
|||
); |
|||
|
|||
|
@ -0,0 +1,41 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
|
|||
/** |
|||
* apply enrol plugin installation script |
|||
* |
|||
* @package enrol |
|||
* @subpackage apply |
|||
* @copyright 2010 Petr Skoda {@link http://skodak.org} |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
function xmldb_enrol_apply_install() { |
|||
global $CFG, $DB; |
|||
|
|||
// migrate welcome message |
|||
if (isset($CFG->sendcoursewelcomemessage)) { |
|||
set_config('sendcoursewelcomemessage', $CFG->sendcoursewelcomemessage, 'enrol_apply'); // new course default |
|||
$DB->set_field('enrol', 'customint4', $CFG->sendcoursewelcomemessage, array('enrol'=>'apply')); // each instance has different setting now |
|||
unset_config('sendcoursewelcomemessage'); |
|||
} |
|||
|
|||
// migrate long-time-no-see feature settings |
|||
if (isset($CFG->longtimenosee)) { |
|||
$nosee = $CFG->longtimenosee * 3600 * 24; |
|||
set_config('longtimenosee', $nosee, 'enrol_apply'); |
|||
$DB->set_field('enrol', 'customint2', $nosee, array('enrol'=>'apply')); |
|||
unset_config('longtimenosee'); |
|||
} |
|||
} |
@ -0,0 +1,85 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
require('../../config.php'); |
|||
require_once('edit_form.php'); |
|||
|
|||
$courseid = required_param('courseid', PARAM_INT); |
|||
$instanceid = optional_param('id', 0, PARAM_INT); // instanceid |
|||
|
|||
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); |
|||
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); |
|||
|
|||
require_login($course); |
|||
require_capability('enrol/self:config', $context); |
|||
|
|||
$PAGE->set_url('/enrol/apply/edit.php', array('courseid'=>$course->id, 'id'=>$instanceid)); |
|||
$PAGE->set_pagelayout('admin'); |
|||
|
|||
$return = new moodle_url('/enrol/instances.php', array('id'=>$course->id)); |
|||
if (!enrol_is_enabled('apply')) { |
|||
redirect($return); |
|||
} |
|||
|
|||
$plugin = enrol_get_plugin('apply'); |
|||
|
|||
if ($instanceid) { |
|||
$instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'apply', 'id'=>$instanceid), '*', MUST_EXIST); |
|||
} else { |
|||
require_capability('moodle/course:enrolconfig', $context); |
|||
// no instance yet, we have to add new instance |
|||
navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id))); |
|||
$instance = new stdClass(); |
|||
$instance->id = null; |
|||
$instance->courseid = $course->id; |
|||
} |
|||
|
|||
$mform = new enrol_self_edit_form(NULL, array($instance, $plugin, $context)); |
|||
|
|||
if ($mform->is_cancelled()) { |
|||
redirect($return); |
|||
|
|||
} else if ($data = $mform->get_data()) { |
|||
if ($instance->id) { |
|||
$instance->status = $data->status; |
|||
$instance->name = $data->name; |
|||
$instance->password = $data->password; |
|||
$instance->customint1 = $data->customint1; |
|||
$instance->customint2 = $data->customint2; |
|||
$instance->customint3 = $data->customint3; |
|||
$instance->customint4 = $data->customint4; |
|||
$instance->customtext1 = $data->customtext1; |
|||
$instance->roleid = $data->roleid; |
|||
$instance->enrolperiod = $data->enrolperiod; |
|||
$instance->enrolstartdate = $data->enrolstartdate; |
|||
$instance->enrolenddate = $data->enrolenddate; |
|||
$instance->timemodified = time(); |
|||
$DB->update_record('enrol', $instance); |
|||
|
|||
} else { |
|||
// $fields = array('status'=>$data->status, 'name'=>$data->name, 'password'=>$data->password, 'customint1'=>$data->customint1, 'customint2'=>$data->customint2, |
|||
// 'customint3'=>$data->customint3, 'customint4'=>$data->customint4, 'customtext1'=>$data->customtext1, |
|||
// 'roleid'=>$data->roleid, 'enrolperiod'=>$data->enrolperiod, 'enrolstartdate'=>$data->enrolstartdate, 'enrolenddate'=>$data->enrolenddate); |
|||
$fields = array('status'=>$data->status, 'name'=>$data->name, 'customtext1'=>$data->customtext1); |
|||
$plugin->add_instance($course, $fields); |
|||
} |
|||
|
|||
redirect($return); |
|||
} |
|||
|
|||
$PAGE->set_heading($course->fullname); |
|||
$PAGE->set_title(get_string('pluginname', 'enrol_apply')); |
|||
|
|||
echo $OUTPUT->header(); |
|||
echo $OUTPUT->heading(get_string('pluginname', 'enrol_apply')); |
|||
$mform->display(); |
|||
echo $OUTPUT->footer(); |
@ -0,0 +1,42 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once($CFG->libdir.'/formslib.php'); |
|||
|
|||
class enrol_self_edit_form extends moodleform { |
|||
|
|||
function definition() { |
|||
$mform = $this->_form; |
|||
|
|||
list($instance, $plugin, $context) = $this->_customdata; |
|||
|
|||
$mform->addElement('header', 'header', get_string('pluginname', 'enrol_apply')); |
|||
|
|||
$mform->addElement('text', 'name', get_string('custominstancename', 'enrol')); |
|||
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), |
|||
ENROL_INSTANCE_DISABLED => get_string('no')); |
|||
$mform->addElement('select', 'status', get_string('status', 'enrol_apply'), $options); |
|||
$mform->addElement('textarea', 'customtext1', get_string('editdescription', 'enrol_apply')); |
|||
|
|||
|
|||
$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); |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
<?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; |
|||
} |
|||
} |
|||
?> |
@ -0,0 +1,179 @@ |
|||
<?php |
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
|
|||
require('../../config.php'); |
|||
require_once($CFG->dirroot.'/enrol/apply/selectlib.php'); |
|||
|
|||
$enrolid = required_param('enrolid', PARAM_INT); |
|||
$roleid = optional_param('roleid', -1, PARAM_INT); |
|||
$extendperiod = optional_param('extendperiod', 0, PARAM_INT); |
|||
$extendbase = optional_param('extendbase', 3, PARAM_INT); |
|||
|
|||
$instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'apply'), '*', MUST_EXIST); |
|||
$course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); |
|||
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); |
|||
|
|||
require_login($course); |
|||
//require_capability('enrol/manual:enrol', $context); |
|||
//require_capability('enrol/manual:manage', $context); |
|||
//require_capability('enrol/manual:unenrol', $context); |
|||
|
|||
if ($roleid < 0) { |
|||
$roleid = $instance->roleid; |
|||
} |
|||
$roles = get_assignable_roles($context); |
|||
$roles = array('0'=>get_string('none')) + $roles; |
|||
|
|||
if (!isset($roles[$roleid])) { |
|||
// weird - security always first! |
|||
$roleid = 0; |
|||
} |
|||
|
|||
if (!$enrol_manual = enrol_get_plugin('apply')) { |
|||
throw new coding_exception('Can not instantiate enrol_manual'); |
|||
} |
|||
|
|||
$instancename = $enrol_manual->get_instance_name($instance); |
|||
|
|||
$PAGE->set_url('/enrol/apply/enroluser.php', array('enrolid'=>$instance->id)); |
|||
$PAGE->set_pagelayout('admin'); |
|||
$PAGE->set_title($enrol_manual->get_instance_name($instance)); |
|||
$PAGE->set_heading($course->fullname); |
|||
navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id'=>$course->id))); |
|||
|
|||
// Create the user selector objects. |
|||
$options = array('enrolid' => $enrolid); |
|||
|
|||
$potentialuserselector = new enrol_apply_potential_participant('addselect', $options); |
|||
$currentuserselector = new enrol_apply_current_participant('removeselect', $options); |
|||
|
|||
// Build the list of options for the enrolment period dropdown. |
|||
$unlimitedperiod = get_string('unlimited'); |
|||
$periodmenu = array(); |
|||
for ($i=1; $i<=365; $i++) { |
|||
$seconds = $i * 86400; |
|||
$periodmenu[$seconds] = get_string('numdays', '', $i); |
|||
} |
|||
// Work out the apropriate default setting. |
|||
if ($extendperiod) { |
|||
$defaultperiod = $extendperiod; |
|||
} else { |
|||
$defaultperiod = $instance->enrolperiod; |
|||
} |
|||
|
|||
// Build the list of options for the starting from dropdown. |
|||
$timeformat = get_string('strftimedatefullshort'); |
|||
$today = time(); |
|||
$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); |
|||
|
|||
// enrolment start |
|||
$basemenu = array(); |
|||
if ($course->startdate > 0) { |
|||
$basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $timeformat) . ')'; |
|||
} |
|||
$basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ; |
|||
|
|||
// process add and removes |
|||
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { |
|||
$userstoassign = $potentialuserselector->get_selected_users(); |
|||
if (!empty($userstoassign)) { |
|||
foreach($userstoassign as $adduser) { |
|||
switch($extendbase) { |
|||
case 2: |
|||
$timestart = $course->startdate; |
|||
break; |
|||
case 3: |
|||
default: |
|||
$timestart = $today; |
|||
break; |
|||
} |
|||
|
|||
if ($extendperiod <= 0) { |
|||
$timeend = 0; |
|||
} else { |
|||
$timeend = $timestart + $extendperiod; |
|||
} |
|||
//echo "<pre>";print_r($instance);exit(); |
|||
$enrol_manual->enrol_user($instance, $adduser->id, $roleid, $timestart, $timeend); |
|||
add_to_log($course->id, 'course', 'enrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere! |
|||
} |
|||
|
|||
$potentialuserselector->invalidate_selected_users(); |
|||
$currentuserselector->invalidate_selected_users(); |
|||
|
|||
//TODO: log |
|||
} |
|||
} |
|||
|
|||
// Process incoming role unassignments |
|||
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { |
|||
$userstounassign = $currentuserselector->get_selected_users(); |
|||
if (!empty($userstounassign)) { |
|||
foreach($userstounassign as $removeuser) { |
|||
$enrol_manual->unenrol_user($instance, $removeuser->id); |
|||
add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere! |
|||
} |
|||
|
|||
$potentialuserselector->invalidate_selected_users(); |
|||
$currentuserselector->invalidate_selected_users(); |
|||
|
|||
//TODO: log |
|||
} |
|||
} |
|||
|
|||
|
|||
echo $OUTPUT->header(); |
|||
echo $OUTPUT->heading($instancename); |
|||
|
|||
?> |
|||
<form id="assignform" method="post" action="<?php echo $PAGE->url ?>"><div> |
|||
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" /> |
|||
|
|||
<table summary="" class="roleassigntable generaltable generalbox boxaligncenter" cellspacing="0"> |
|||
<tr> |
|||
<td id="existingcell"> |
|||
<p><label for="removeselect"><?php print_string('enrolledusers', 'enrol'); ?></label></p> |
|||
<?php $currentuserselector->display() ?> |
|||
</td> |
|||
<td id="buttonscell"> |
|||
<div id="addcontrols"> |
|||
<input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().' '.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br /> |
|||
|
|||
<div class="enroloptions"> |
|||
|
|||
<p><label for="roleid"><?php print_string('assignrole', 'enrol_manual') ?></label><br /> |
|||
<?php echo html_writer::select($roles, 'roleid', $roleid, false); ?></p> |
|||
|
|||
<p><label for="extendperiod"><?php print_string('enrolperiod', 'enrol') ?></label><br /> |
|||
<?php echo html_writer::select($periodmenu, 'extendperiod', $defaultperiod, $unlimitedperiod); ?></p> |
|||
|
|||
<p><label for="extendbase"><?php print_string('startingfrom') ?></label><br /> |
|||
<?php echo html_writer::select($basemenu, 'extendbase', $extendbase, false); ?></p> |
|||
|
|||
</div> |
|||
</div> |
|||
|
|||
<div id="removecontrols"> |
|||
<input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').' '.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" /> |
|||
</div> |
|||
</td> |
|||
<td id="potentialcell"> |
|||
<p><label for="addselect"><?php print_string('enrolcandidates', 'enrol'); ?></label></p> |
|||
<?php $potentialuserselector->display() ?> |
|||
</td> |
|||
</tr> |
|||
</table> |
|||
</div></form> |
|||
<?php |
|||
|
|||
|
|||
echo $OUTPUT->footer(); |
@ -0,0 +1,39 @@ |
|||
<?php |
|||
|
|||
// The name of your plugin. Displayed on admin menus. |
|||
$string['enrolname'] = 'Bestätigung der Kurseinschreibung'; |
|||
$string['pluginname'] = 'Bestätigung der Kurseinschreibung'; |
|||
|
|||
$string['confirmmailsubject'] = 'Bestätigung des Mail-Betreffs'; |
|||
$string['confirmmailcontent'] = 'Bestätigung des Mail-Inhalts'; |
|||
$string['cancelmailsubject'] = 'Löschen des Mail-Betreffs'; |
|||
$string['cancelmailcontent'] = 'Löschen des Mail-Inhalts'; |
|||
$string['mailaddress'] = 'Mailadresse senden'; |
|||
$string['mailusername'] = 'Mailbenutzernamen senden'; |
|||
$string['mailpassword'] = 'Mailpasswort senden'; |
|||
$string['confirmmailcontent_desc'] = 'Bitte benutzen Sie die Spezialmarkierungen, um den gewünschten Mailinhalt zu ersetzen.<br>{Vorname}:Registrierungsname; {Inhalt}:Kursname'; |
|||
$string['cancelmailcontent_desc'] = 'Bitte benutzen Sie die Spezialmarkierungen, um den gewünschten Mailinhalt zu ersetzen.<br>{Vorname}:Registrierungsname; {Inhalt}:Kursname'; |
|||
|
|||
$string['confirmusers'] = 'Einschreibung bestätigen'; |
|||
|
|||
$string['coursename'] = 'Kurs'; |
|||
$string['applyuser'] = 'Voname / Nachname'; |
|||
$string['applyusermail'] = 'Email'; |
|||
$string['applydate'] = 'Einschreibungsdatum'; |
|||
$string['btnconfirm'] = 'Bestätigen'; |
|||
$string['btncancel'] = 'Abbruch'; |
|||
$string['enrolusers'] = 'Benutzer einschreiben'; |
|||
|
|||
$string['status'] = 'Bestätigung der Kurseinschreibung erlauben'; |
|||
$string['confirmenrol'] = 'Anwendung verwalten'; |
|||
|
|||
$string['apply:config'] = 'Einschreibungsbelegstellen anlegen'; |
|||
$string['apply:manage'] = 'Einschreibungsanfragen verwalten'; |
|||
$string['apply:unenrol'] = 'Benutzer aus dem Kurs entfernen'; |
|||
$string['apply:unenrolapply'] = 'Sich selbst aus dem Kurs entfernen'; |
|||
|
|||
// Description of your plugin. Shown on the plugin's configuration screen. |
|||
$string['description'] = ''; |
|||
$string['notification'] = '<b>Einschreibungsantrag wurde erfolgreich gesendet.</b>. <br/><br/>Sie werden via Mail informiert, sobald Ihre Einschreibung bestätigt wurde. Wenn Sie sich in andere Kurse einschreiben wollen, klicken Sie bitte den "Kurskatalog" im Hauptmenu an.'; |
|||
|
|||
?> |
@ -0,0 +1,53 @@ |
|||
<?php |
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
// The name of your plugin. Displayed on admin menus. |
|||
$string['enrolname'] = 'Course enrol confirmation'; |
|||
$string['pluginname'] = 'Course enrol confirmation'; |
|||
|
|||
$string['confirmmailsubject'] = 'Confirm mail subject'; |
|||
$string['confirmmailcontent'] = 'Confirm mail content'; |
|||
$string['cancelmailsubject'] = 'Cancel mail subject'; |
|||
$string['cancelmailcontent'] = 'Cancel mail sontent'; |
|||
$string['mailaddress'] = 'Send mail address'; |
|||
$string['mailusername'] = 'Send mail username'; |
|||
$string['mailpassword'] = 'Send mail password'; |
|||
$string['confirmmailcontent_desc'] = 'Please use special marks designated email content replaced.<br>{firstname}:Registration name; {content}:Course name'; |
|||
$string['cancelmailcontent_desc'] = 'Please use special marks designated email content replaced.<br>{firstname}:Registration name; {content}:Course name'; |
|||
|
|||
$string['confirmusers'] = 'Enrol Confirm'; |
|||
|
|||
$string['coursename'] = 'Course'; |
|||
$string['applyuser'] = 'First name / Surname'; |
|||
$string['applyusermail'] = 'Email'; |
|||
$string['applydate'] = 'Enrol date'; |
|||
$string['btnconfirm'] = 'Confirm'; |
|||
$string['btncancel'] = 'Cancel'; |
|||
$string['enrolusers'] = 'Enrol users'; |
|||
|
|||
$string['status'] = 'Allow Course enrol confirmation'; |
|||
$string['confirmenrol'] = 'Manage application'; |
|||
|
|||
$string['apply:config'] = 'Configure apply enrol instances'; |
|||
$string['apply:manage'] = 'Manage apply enrolment'; |
|||
$string['apply:unenrol'] = 'Cancel users from course'; |
|||
$string['apply:unenrolapply'] = 'Cancel self from the course'; |
|||
|
|||
// Description of your plugin. Shown on the plugin's configuration screen. |
|||
$string['description'] = ''; |
|||
$string['notification'] = '<b>Enrollment Application successfully sent</b>. <br/><br/>You will be informed by email as soon as your enrollment has been confirmed. If you want to enroll to other courses, please click "course catalogue" in the top menu.'; |
|||
|
|||
$string['sendmailtoteacher'] = 'Send email notification to teachers'; |
|||
$string['mailtoteacher_suject'] = 'New Enrollment request!'; |
|||
$string['setting_edit'] = 'Edit'; |
|||
$string['editdescription'] = 'Textarea description'; |
|||
$string['applymanage'] = 'Manage enrolment applications'; |
|||
?> |
@ -0,0 +1,48 @@ |
|||
<?php |
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
// The name of your plugin. Displayed on admin menus. |
|||
$string['enrolname'] = 'Matrículas solicitadas'; |
|||
$string['pluginname'] = 'Matrículas solicitadas'; |
|||
|
|||
$string['confirmmailsubject'] = 'Asunto del correo de confirmación'; |
|||
$string['confirmmailcontent'] = 'Contenido del correo de confirmación'; |
|||
$string['cancelmailsubject'] = 'Asunto del correo de cancelación'; |
|||
$string['cancelmailcontent'] = 'Contenido del correo de cancelación'; |
|||
$string['mailaddress'] = 'Send mail address'; // Those configuration parameters |
|||
$string['mailusername'] = 'Send mail username'; // are commented out in code |
|||
$string['mailpassword'] = 'Send mail password'; // Couldn't make an accurate translation without seen those in action |
|||
$string['confirmmailcontent_desc'] = 'Por favor, use marcas especiales que se substituirán en el contenido del correo.<br>{firstname}:Nombre registrado por el usuario; {content}:Nombre del curso'; |
|||
$string['cancelmailcontent_desc'] = 'Por favor, use marcas especiales que se substituirán en el contenido del correo.<br>{firstname}:Nombre registrado por el usuario; {content}:Nombre del curso'; |
|||
|
|||
$string['confirmusers'] = 'Confirmar matrículas'; |
|||
|
|||
$string['coursename'] = 'Curso'; |
|||
$string['applyuser'] = 'Nombre / Apellido'; |
|||
$string['applyusermail'] = 'Correo electrónico'; |
|||
$string['applydate'] = 'Fecha de solicitud'; // Enrol date -> Fecha de matriculación |
|||
$string['btnconfirm'] = 'Confirmar'; |
|||
$string['btncancel'] = 'Cancelar'; |
|||
$string['enrolusers'] = 'Matricular usuarios'; |
|||
|
|||
$string['status'] = 'Aceptar matriculación tras aprobación'; |
|||
$string['confirmenrol'] = 'Gestionar solicitudes'; |
|||
|
|||
$string['apply:config'] = 'Configurar instancias de matrículas solicitadas'; // Needs more insight |
|||
$string['apply:manage'] = 'Gestionar matrículas solicitadas'; // Needs more insight |
|||
$string['apply:unenrol'] = 'Cancelar usuarios del curso'; // Needs more insight |
|||
$string['apply:unenrolapply'] = 'Cancelarse a si mismo del curso'; // Needs more insight. Very ugly translation! |
|||
|
|||
// Description of your plugin. Shown on the plugin's configuration screen. |
|||
$string['description'] = ''; |
|||
$string['notification'] = '<b>Solicitud de matriculación enviada correctamente</b>. <br/><br/>Será notificado por correo electrónico en cuanto se confirme su matriculación.'; |
|||
|
|||
?> |
@ -0,0 +1,52 @@ |
|||
<?php |
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
// The name of your plugin. Displayed on admin menus. |
|||
$string['enrolname'] = 'Matrículas solicitadas'; |
|||
$string['pluginname'] = 'Matrículas solicitadas'; |
|||
|
|||
$string['confirmmailsubject'] = 'Assunto do e-mail de confirmação'; |
|||
$string['confirmmailcontent'] = 'Conteúdo do e-mail de confirmação'; |
|||
$string['cancelmailsubject'] = 'Assunto do e-mail de cancelamento'; |
|||
$string['cancelmailcontent'] = 'Conteúdo do e-mail de cancelamento'; |
|||
$string['mailaddress'] = 'Endereço do e-mail de envio'; // Those configuration parameters |
|||
$string['mailusername'] = 'Usuário do e-mail de envio'; // are commented out in code |
|||
$string['mailpassword'] = 'Senha do e-mail de envio'; // Couldn't make an accurate translation without seen those in action |
|||
$string['confirmmailcontent_desc'] = 'Por favor, use marcas especiais que substituirão o conteúdo do e-mail.<br>{firstname}:Nome registrado pelo usuário; {content}:Nome do curso'; |
|||
$string['cancelmailcontent_desc'] = 'Por favor, use marcas especiais que substituirão o conteúdo do e-mail.<br>{firstname}:Nome registrado pelo usuário {content}:Nome do curso'; |
|||
|
|||
$string['confirmusers'] = 'Confirmar matrículas'; |
|||
|
|||
$string['coursename'] = 'Curso'; |
|||
$string['applyuser'] = 'Nome / Sobrenome'; |
|||
$string['applyusermail'] = 'E-mail'; |
|||
$string['applydate'] = 'Data de solicitação'; // Enrol date -> Fecha de matriculación |
|||
$string['btnconfirm'] = 'Confirmar'; |
|||
$string['btncancel'] = 'Cancelar'; |
|||
$string['enrolusers'] = 'Matricular usuários'; |
|||
|
|||
$string['status'] = 'Aceitar matrícula após aprovação'; |
|||
$string['confirmenrol'] = 'Gerenciar solicitações'; |
|||
|
|||
$string['apply:config'] = 'Configurar instâncias de matrículas solicitadas'; // Needs more insight |
|||
$string['apply:manage'] = 'Gerenciar matrículas solicitadas'; // Needs more insight |
|||
$string['apply:unenrol'] = 'Cancelar usuários do curso'; // Needs more insight |
|||
$string['apply:unenrolapply'] = 'Cancelar minha matrícula do curso'; // Needs more insight. Very ugly translation! |
|||
|
|||
// Description of your plugin. Shown on the plugin's configuration screen. |
|||
$string['description'] = ''; |
|||
$string['notification'] = '<b>Solicitação de matrícula enviada com sucesso</b>. <br/><br/>Você será notificado por e-mail quando a sua matrícula for confirmada.'; |
|||
|
|||
$string['sendmailtoteacher'] = 'Enviar e-mail de notificação para professores'; |
|||
$string['mailtoteacher_suject'] = 'Nova solicitação de inscrição!'; |
|||
$string['setting_edit'] = 'Editar'; |
|||
$string['editdescription'] = 'Descrição'; |
|||
?> |
@ -0,0 +1,245 @@ |
|||
<?php |
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
class enrol_apply_plugin extends enrol_plugin { |
|||
|
|||
public function allow_unenrol(stdClass $instance) { |
|||
// users with unenrol cap may unenrol other users manually manually |
|||
return true; |
|||
} |
|||
|
|||
public function get_newinstance_link($courseid) { |
|||
$context = get_context_instance(CONTEXT_COURSE, $courseid, MUST_EXIST); |
|||
|
|||
if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/manual:config', $context)) { |
|||
return NULL; |
|||
} |
|||
// multiple instances supported - different roles with different password |
|||
return new moodle_url('/enrol/apply/edit.php', array('courseid'=>$courseid)); |
|||
} |
|||
|
|||
public function enrol_page_hook(stdClass $instance) { |
|||
global $CFG, $OUTPUT, $SESSION, $USER, $DB; |
|||
|
|||
if (isguestuser()) { |
|||
// can not enrol guest!! |
|||
return null; |
|||
} |
|||
if ($DB->record_exists('user_enrolments', array('userid'=>$USER->id, 'enrolid'=>$instance->id))) { |
|||
//TODO: maybe we should tell them they are already enrolled, but can not access the course |
|||
//return null; |
|||
return $OUTPUT->notification(get_string('notification', 'enrol_apply')); |
|||
} |
|||
|
|||
if ($instance->enrolstartdate != 0 and $instance->enrolstartdate > time()) { |
|||
//TODO: inform that we can not enrol yet |
|||
return null; |
|||
} |
|||
|
|||
if ($instance->enrolenddate != 0 and $instance->enrolenddate < time()) { |
|||
//TODO: inform that enrolment is not possible any more |
|||
return null; |
|||
} |
|||
|
|||
if ($instance->customint3 > 0) { |
|||
// max enrol limit specified |
|||
$count = $DB->count_records('user_enrolments', array('enrolid'=>$instance->id)); |
|||
if ($count >= $instance->customint3) { |
|||
// bad luck, no more self enrolments here |
|||
return $OUTPUT->notification(get_string('maxenrolledreached', 'enrol_self')); |
|||
} |
|||
} |
|||
|
|||
require_once("$CFG->dirroot/enrol/apply/locallib.php"); |
|||
|
|||
$form = new enrol_apply_enrol_form(NULL, $instance); |
|||
|
|||
$instanceid = optional_param('instance', 0, PARAM_INT); |
|||
if ($instance->id == $instanceid) { |
|||
if ($data = $form->get_data()) { |
|||
$enrol = enrol_get_plugin('self'); |
|||
$timestart = time(); |
|||
if ($instance->enrolperiod) { |
|||
$timeend = $timestart + $instance->enrolperiod; |
|||
} else { |
|||
$timeend = 0; |
|||
} |
|||
|
|||
$roleid = $instance->roleid; |
|||
if(!$roleid){ |
|||
$role = $DB->get_record_sql('select * from '.$CFG->prefix.'role where archetype="student" limit 1'); |
|||
$roleid = $role->id; |
|||
} |
|||
|
|||
$this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend,1); |
|||
sendConfirmMailToTeachers($instance->courseid,$data->applydescription); |
|||
|
|||
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"); |
|||
} |
|||
} |
|||
|
|||
ob_start(); |
|||
$form->display(); |
|||
$output = ob_get_clean(); |
|||
|
|||
return $OUTPUT->box($output); |
|||
|
|||
} |
|||
|
|||
public function get_action_icons(stdClass $instance) { |
|||
global $OUTPUT; |
|||
|
|||
if ($instance->enrol !== 'apply') { |
|||
throw new coding_exception('invalid enrol instance!'); |
|||
} |
|||
$context = get_context_instance(CONTEXT_COURSE, $instance->courseid); |
|||
|
|||
$icons = array(); |
|||
|
|||
if (has_capability("enrol/manual:manage", $context)) { |
|||
$editlink = new moodle_url("/enrol/apply/edit.php", array('courseid'=>$instance->courseid, 'id'=>$instance->id)); |
|||
$icons[] = $OUTPUT->action_icon($editlink, new pix_icon('i/edit', get_string('edit'), 'core', array('class'=>'icon'))); |
|||
} |
|||
|
|||
if (has_capability('enrol/manual:manage', $context)) { |
|||
$managelink = new moodle_url("/enrol/apply/apply.php", array('id'=>$_GET['id'],'enrolid'=>$instance->id)); |
|||
$icons[] = $OUTPUT->action_icon($managelink, new pix_icon('i/users', get_string('confirmenrol', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); |
|||
} |
|||
|
|||
if (has_capability("enrol/manual:manage", $context)) { |
|||
$managelink = new moodle_url("/enrol/apply/enroluser.php", array('enrolid'=>$instance->id)); |
|||
$icons[] = $OUTPUT->action_icon($managelink, new pix_icon('i/users', get_string('enrolusers', 'enrol_apply'), 'core', array('class'=>'iconsmall'))); |
|||
} |
|||
|
|||
return $icons; |
|||
} |
|||
|
|||
public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) { |
|||
$actions = array(); |
|||
$context = $manager->get_context(); |
|||
$instance = $ue->enrolmentinstance; |
|||
$params = $manager->get_moodlepage()->url->params(); |
|||
$params['ue'] = $ue->id; |
|||
if ($this->allow_unenrol($instance) && has_capability("enrol/apply:unenrol", $context)) { |
|||
$url = new moodle_url('/enrol/apply/unenroluser.php', $params); |
|||
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id)); |
|||
} |
|||
if ($this->allow_manage($instance) && has_capability("enrol/apply:manage", $context)) { |
|||
$url = new moodle_url('/enrol/apply/editenrolment.php', $params); |
|||
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id)); |
|||
} |
|||
return $actions; |
|||
} |
|||
} |
|||
|
|||
function getAllEnrolment($id = null){ |
|||
global $DB; |
|||
global $CFG; |
|||
if($id){ |
|||
$userenrolments = $DB->get_records_sql('select ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated from '.$CFG->prefix.'user_enrolments as ue left join '.$CFG->prefix.'user as u on ue.userid=u.id left join '.$CFG->prefix.'enrol as e on ue.enrolid=e.id left join '.$CFG->prefix.'course as c on e.courseid=c.id where ue.status=1 and e.courseid='.$id); |
|||
}else{ |
|||
$userenrolments = $DB->get_records_sql('select ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated from '.$CFG->prefix.'user_enrolments as ue left join '.$CFG->prefix.'user as u on ue.userid=u.id left join '.$CFG->prefix.'enrol as e on ue.enrolid=e.id left join '.$CFG->prefix.'course as c on e.courseid=c.id where ue.status=1'); |
|||
} |
|||
return $userenrolments; |
|||
} |
|||
|
|||
function confirmEnrolment($enrols){ |
|||
global $DB; |
|||
global $CFG; |
|||
foreach ($enrols as $enrol){ |
|||
@$enroluser->id = $enrol; |
|||
@$enroluser->status = 0; |
|||
|
|||
if($DB->update_record('user_enrolments',$enroluser)){ |
|||
$userenrolments = $DB->get_record_sql('select * from '.$CFG->prefix.'user_enrolments where id='.$enrol); |
|||
$role = $DB->get_record_sql('select * from '.$CFG->prefix.'role where archetype="student" limit 1'); |
|||
@$roleAssignments->userid = $userenrolments->userid; |
|||
@$roleAssignments->roleid = $role->id; |
|||
@$roleAssignments->contextid = 3; |
|||
@$roleAssignments->timemodified = time(); |
|||
@$roleAssignments->modifierid = 2; |
|||
$DB->insert_record('role_assignments',$roleAssignments); |
|||
$info = getRelatedInfo($enrol); |
|||
sendConfirmMail($info); |
|||
} |
|||
} |
|||
} |
|||
|
|||
function cancelEnrolment($enrols){ |
|||
global $DB; |
|||
foreach ($enrols as $enrol){ |
|||
$info = getRelatedInfo($enrol); |
|||
if($DB->delete_records('user_enrolments',array('id'=>$enrol))){ |
|||
sendCancelMail($info); |
|||
} |
|||
} |
|||
} |
|||
|
|||
function sendCancelMail($info){ |
|||
global $DB; |
|||
global $CFG; |
|||
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); |
|||
|
|||
$replace = array('firstname'=>$info->firstname,'content'=>$info->coursename); |
|||
$body = $apply_setting['cancelmailcontent']->value; |
|||
$body = updateMailContent($body,$replace); |
|||
$contact = get_admin(); |
|||
email_to_user($info, $contact, $apply_setting['cancelmailsubject']->value, '', $body); |
|||
} |
|||
|
|||
function sendConfirmMail($info){ |
|||
global $DB; |
|||
global $CFG; |
|||
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); |
|||
|
|||
$replace = array('firstname'=>$info->firstname,'content'=>$info->coursename); |
|||
$body = $apply_setting['confirmmailcontent']->value; |
|||
$body = updateMailContent($body,$replace); |
|||
$contact = get_admin(); |
|||
email_to_user($info, $contact, $apply_setting['confirmmailsubject']->value, '', $body); |
|||
} |
|||
|
|||
function sendConfirmMailToTeachers($courseid,$desc){ |
|||
global $DB; |
|||
global $CFG; |
|||
global $USER; |
|||
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); |
|||
|
|||
if($apply_setting['sendmailtoteacher']->value == 1){ |
|||
$course = $DB->get_record('course',array('id'=>$courseid)); |
|||
$context = get_context_instance(CONTEXT_COURSE, $courseid, MUST_EXIST); |
|||
$teacherType = $DB->get_record('role',array("shortname"=>"editingteacher")); |
|||
$teachers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$teacherType->id)); |
|||
foreach($teachers as $teacher){ |
|||
$editTeacher = $DB->get_record('user',array('id'=>$teacher->userid)); |
|||
$body = '<p>Course: '.$course->fullname.'</p><p>First name: '.$USER->firstname.'</p><p>Last name: '.$USER->lastname.'</p><p>Information: '.$desc.'</p>'; |
|||
$contact = get_admin(); |
|||
$info = $editTeacher; |
|||
$info->coursename = $course->fullname; |
|||
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), '', $body); |
|||
} |
|||
} |
|||
} |
|||
|
|||
function getRelatedInfo($enrolid){ |
|||
global $DB; |
|||
global $CFG; |
|||
return $DB->get_record_sql('select u.*,c.fullname as coursename from '.$CFG->prefix.'user_enrolments as ue left join '.$CFG->prefix.'user as u on ue.userid=u.id left join '.$CFG->prefix.'enrol as e on ue.enrolid=e.id left |
|||
join '.$CFG->prefix.'course as c on e.courseid=c.id where ue.id='.$enrolid); |
|||
} |
|||
|
|||
function updateMailContent($content,$replace){ |
|||
foreach ($replace as $key=>$val) { |
|||
$content = str_replace("{".$key."}",$val,$content); |
|||
} |
|||
return $content; |
|||
} |
@ -0,0 +1,108 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
/** |
|||
* Self enrol plugin implementation. |
|||
* |
|||
* @package enrol |
|||
* @subpackage self |
|||
* @copyright 2010 Petr Skoda {@link http://skodak.org} |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once("$CFG->libdir/formslib.php"); |
|||
|
|||
class enrol_apply_enrol_form extends moodleform { |
|||
protected $instance; |
|||
|
|||
/** |
|||
* Overriding this function to get unique form id for multiple self enrolments |
|||
* |
|||
* @return string form identifier |
|||
*/ |
|||
protected function get_form_identifier() { |
|||
$formid = $this->_customdata->id.'_'.get_class($this); |
|||
return $formid; |
|||
} |
|||
|
|||
public function definition() { |
|||
$mform = $this->_form; |
|||
$instance = $this->_customdata; |
|||
$this->instance = $instance; |
|||
$plugin = enrol_get_plugin('self'); |
|||
|
|||
if ($instance->password) { |
|||
$heading = $plugin->get_instance_name($instance); |
|||
$mform->addElement('header', 'selfheader', $heading); |
|||
//change the id of self enrolment key input as there can be multiple self enrolment methods |
|||
$mform->addElement('passwordunmask', 'enrolpassword', get_string('password', 'enrol_self'), |
|||
array('id' => $instance->id."_enrolpassword")); |
|||
} else { |
|||
// nothing? |
|||
} |
|||
|
|||
$mform->addElement('html', '<p>'.$instance->customtext1.'</p>'); |
|||
$mform->addElement('textarea', 'applydescription','','cols="80"'); |
|||
$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; |
|||
} |
|||
} |
@ -0,0 +1,62 @@ |
|||
<?php |
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
require ('../../config.php'); |
|||
require_once ('lib.php'); |
|||
require_login(); |
|||
require_capability('enrol/apply:manage', context_system::instance()); |
|||
|
|||
$site = get_site (); |
|||
$systemcontext = get_context_instance ( CONTEXT_SYSTEM ); |
|||
|
|||
$PAGE->set_url ( '/enrol/manage.php'); |
|||
$PAGE->set_context($systemcontext); |
|||
$PAGE->set_pagelayout ( 'admin' ); |
|||
//$PAGE->set_heading ( $course->fullname ); |
|||
|
|||
$PAGE->navbar->add ( get_string ( 'confirmusers', 'enrol_apply' ) ); |
|||
$PAGE->set_title ( "$site->shortname: " . get_string ( 'confirmusers', 'enrol_apply' ) ); |
|||
|
|||
if (isset ( $_POST ['enrolid'] )) { |
|||
if ($_POST ['enrolid']) { |
|||
if ($_POST ['type'] == 'confirm') { |
|||
confirmEnrolment ( $_POST ['enrolid'] ); |
|||
} elseif ($_POST ['type'] == 'cancel') { |
|||
cancelEnrolment ( $_POST ['enrolid'] ); |
|||
} |
|||
redirect ( "$CFG->wwwroot/enrol/apply/manage.php" ); |
|||
} |
|||
} |
|||
|
|||
$enrols = getAllEnrolment(); |
|||
echo $OUTPUT->header (); |
|||
echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) ); |
|||
echo '<form id="frmenrol" method="post" action="manage.php">'; |
|||
echo '<input type="hidden" id="type" name="type" value="confirm">'; |
|||
echo '<table class="generalbox editcourse boxaligncenter"><tr class="header">'; |
|||
echo '<th class="header" scope="col"> </th>'; |
|||
echo '<th class="header" scope="col">' . get_string ( 'coursename', 'enrol_apply' ) . '</th>'; |
|||
echo '<th class="header" scope="col">' . get_string ( 'applyuser', 'enrol_apply' ) . '</th>'; |
|||
echo '<th class="header" scope="col">' . get_string ( 'applyusermail', 'enrol_apply' ) . '</th>'; |
|||
echo '<th class="header" scope="col">' . get_string ( 'applydate', 'enrol_apply' ) . '</th>'; |
|||
echo '</tr>'; |
|||
foreach ( $enrols as $enrol ) { |
|||
echo '<tr><td><input type="checkbox" name="enrolid[]" value="' . $enrol->id . '"></td>'; |
|||
echo '<td>' . $enrol->course . '</td>'; |
|||
echo '<td>' . $enrol->firstname . ' ' . $enrol->lastname . '</td>'; |
|||
echo '<td>' . $enrol->email . '</td>'; |
|||
echo '<td>' . date ( "Y-m-d", $enrol->timecreated ) . '</td></tr>'; |
|||
} |
|||
echo '</table>'; |
|||
echo '<p align="center"><input type="button" value="' . get_string ( 'btnconfirm', 'enrol_apply' ) . '" onclick="doSubmit(\'confrim\');"> <input type="button" value="' . get_string ( 'btncancel', 'enrol_apply' ) . '" onclick="doSubmit(\'cancel\');"></p>'; |
|||
echo '</form>'; |
|||
echo '<script>function doSubmit(type){if(type=="cancel"){document.getElementById("type").value=type;}document.getElementById("frmenrol").submit();}</script>'; |
|||
echo $OUTPUT->footer (); |
@ -0,0 +1,155 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Auxiliary manual user enrolment lib, the main purpose is to lower memory requirements... |
|||
* |
|||
* @package enrol |
|||
* @subpackage manual |
|||
* @copyright 2010 Petr Skoda {@link http://skodak.org} |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once($CFG->dirroot . '/user/selector/lib.php'); |
|||
|
|||
/** |
|||
* Enrol candidates |
|||
*/ |
|||
class enrol_apply_potential_participant extends user_selector_base { |
|||
protected $enrolid; |
|||
|
|||
public function __construct($name, $options) { |
|||
$this->enrolid = $options['enrolid']; |
|||
parent::__construct($name, $options); |
|||
} |
|||
|
|||
/** |
|||
* Candidate users |
|||
* @param <type> $search |
|||
* @return array |
|||
*/ |
|||
public function find_users($search) { |
|||
global $DB; |
|||
//by default wherecondition retrieves all users except the deleted, not confirmed and guest |
|||
list($wherecondition, $params) = $this->search_sql($search, 'u'); |
|||
$params['enrolid'] = $this->enrolid; |
|||
|
|||
$fields = 'SELECT ' . $this->required_fields_sql('u'); |
|||
$countfields = 'SELECT COUNT(1)'; |
|||
|
|||
$sql = " FROM {user} u |
|||
WHERE $wherecondition |
|||
AND u.id NOT IN (SELECT ue.userid |
|||
FROM {user_enrolments} ue |
|||
JOIN {enrol} e ON (e.id = ue.enrolid AND e.id = :enrolid))"; |
|||
|
|||
$order = ' ORDER BY u.lastname ASC, u.firstname ASC'; |
|||
|
|||
if (!$this->is_validating()) { |
|||
$potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params); |
|||
if ($potentialmemberscount > 100) { |
|||
return $this->too_many_results($search, $potentialmemberscount); |
|||
} |
|||
} |
|||
|
|||
$availableusers = $DB->get_records_sql($fields . $sql . $order, $params); |
|||
|
|||
if (empty($availableusers)) { |
|||
return array(); |
|||
} |
|||
|
|||
|
|||
if ($search) { |
|||
$groupname = get_string('enrolcandidatesmatching', 'enrol', $search); |
|||
} else { |
|||
$groupname = get_string('enrolcandidates', 'enrol'); |
|||
} |
|||
|
|||
return array($groupname => $availableusers); |
|||
} |
|||
|
|||
protected function get_options() { |
|||
$options = parent::get_options(); |
|||
$options['enrolid'] = $this->enrolid; |
|||
$options['file'] = 'enrol/apply/selectlib.php'; |
|||
return $options; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Enroled users |
|||
*/ |
|||
class enrol_apply_current_participant extends user_selector_base { |
|||
protected $courseid; |
|||
protected $enrolid; |
|||
|
|||
public function __construct($name, $options) { |
|||
$this->enrolid = $options['enrolid']; |
|||
parent::__construct($name, $options); |
|||
} |
|||
|
|||
/** |
|||
* Candidate users |
|||
* @param <type> $search |
|||
* @return array |
|||
*/ |
|||
public function find_users($search) { |
|||
global $DB; |
|||
//by default wherecondition retrieves all users except the deleted, not confirmed and guest |
|||
list($wherecondition, $params) = $this->search_sql($search, 'u'); |
|||
$params['enrolid'] = $this->enrolid; |
|||
|
|||
$fields = 'SELECT ' . $this->required_fields_sql('u'); |
|||
$countfields = 'SELECT COUNT(1)'; |
|||
|
|||
$sql = " FROM {user} u |
|||
JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid) |
|||
WHERE $wherecondition"; |
|||
|
|||
$order = ' ORDER BY u.lastname ASC, u.firstname ASC'; |
|||
|
|||
if (!$this->is_validating()) { |
|||
$potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params); |
|||
if ($potentialmemberscount > 100) { |
|||
return $this->too_many_results($search, $potentialmemberscount); |
|||
} |
|||
} |
|||
|
|||
$availableusers = $DB->get_records_sql($fields . $sql . $order, $params); |
|||
|
|||
if (empty($availableusers)) { |
|||
return array(); |
|||
} |
|||
|
|||
|
|||
if ($search) { |
|||
$groupname = get_string('enrolledusersmatching', 'enrol', $search); |
|||
} else { |
|||
$groupname = get_string('enrolledusers', 'enrol'); |
|||
} |
|||
|
|||
return array($groupname => $availableusers); |
|||
} |
|||
|
|||
protected function get_options() { |
|||
$options = parent::get_options(); |
|||
$options['enrolid'] = $this->enrolid; |
|||
$options['file'] = 'enrol/apply/locallib.php'; |
|||
return $options; |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
<?php |
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
if ($ADMIN->fulltree) { |
|||
|
|||
//--- general settings ----------------------------------------------------------------------------------- |
|||
$settings->add(new admin_setting_heading('enrol_apply_enrolname','','')); |
|||
|
|||
$settings->add(new admin_setting_configtext('enrol_apply/confirmmailsubject','',get_string('confirmmailsubject', 'enrol_apply'),null,PARAM_TEXT,60)); |
|||
$settings->add(new admin_setting_heading('enrol_apply_settings', '', get_string('confirmmailcontent_desc', 'enrol_apply'))); |
|||
$settings->add(new admin_setting_confightmleditor('enrol_apply/confirmmailcontent', get_string('confirmmailcontent', 'enrol_apply'),'utf-8','')); |
|||
|
|||
$settings->add(new admin_setting_configtext('enrol_apply/cancelmailsubject','',get_string('cancelmailsubject', 'enrol_apply'),null,PARAM_TEXT,60)); |
|||
//$settings->add(new admin_setting_heading('enrol_apply_settings', '', get_string('cancelmailcontent_desc', 'enrol_apply'))); |
|||
$settings->add(new admin_setting_confightmleditor('enrol_apply/cancelmailcontent', get_string('cancelmailcontent', 'enrol_apply'),'utf-8','')); |
|||
|
|||
$settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtoteacher', |
|||
get_string('sendmailtoteacher', 'enrol_apply'), '', 0)); |
|||
|
|||
} |
|||
|
|||
if ($hassiteconfig) { // needs this condition or there is error on login page |
|||
$ADMIN->add('courses', new admin_externalpage('enrol_apply', |
|||
get_string('applymanage', 'enrol_apply'), |
|||
new moodle_url('/enrol/apply/manage.php'))); |
|||
} |
@ -0,0 +1,97 @@ |
|||
<?php |
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
/** |
|||
* Unenrol a user who was enrolled through a self enrolment. |
|||
* |
|||
* @package enrol |
|||
* @subpackage self |
|||
* @copyright 2011 Sam Hemelryk |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
require('../../config.php'); |
|||
require_once("$CFG->dirroot/enrol/locallib.php"); |
|||
require_once("$CFG->dirroot/enrol/renderer.php"); |
|||
|
|||
$ueid = required_param('ue', PARAM_INT); // user enrolment id |
|||
$filter = optional_param('ifilter', 0, PARAM_INT); |
|||
$confirm = optional_param('confirm', false, PARAM_BOOL); |
|||
|
|||
// Get the user enrolment object |
|||
$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST); |
|||
// Get the user for whom the enrolment is |
|||
$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST); |
|||
// Get the course the enrolment is to |
|||
list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); |
|||
$sql = "SELECT c.* $ctxsql |
|||
FROM {course} c |
|||
LEFT JOIN {enrol} e ON e.courseid = c.id |
|||
$ctxjoin |
|||
WHERE e.id = :enrolid"; |
|||
$params = array('enrolid' => $ue->enrolid); |
|||
$course = $DB->get_record_sql($sql, $params, MUST_EXIST); |
|||
context_instance_preload($course); |
|||
|
|||
|
|||
// Make sure it's not the front page |
|||
if ($course->id == SITEID) { |
|||
redirect(new moodle_url('/')); |
|||
} |
|||
|
|||
// Obviously |
|||
require_login($course); |
|||
// Make sure the user can unenrol self enrolled users. |
|||
require_capability("enrol/self:unenrol", get_context_instance(CONTEXT_COURSE, $course->id)); |
|||
|
|||
// Get the enrolment manager for this course |
|||
$manager = new course_enrolment_manager($PAGE, $course, $filter); |
|||
// Get an enrolment users table object. Doign this will automatically retrieve the the URL params |
|||
// relating to table the user was viewing before coming here, and allows us to return the user to the |
|||
// exact page of the users screen they can from. |
|||
$table = new course_enrolment_users_table($manager, $PAGE); |
|||
|
|||
// The URL of the enrolled users page for the course. |
|||
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id)); |
|||
// The URl to return the user too after this screen. |
|||
$returnurl = new moodle_url($usersurl, $manager->get_url_params()+$table->get_url_params()); |
|||
// The URL of this page |
|||
$url = new moodle_url('/enrol/apply/unenroluser.php', $returnurl->params()); |
|||
$url->param('ue', $ueid); |
|||
|
|||
$PAGE->set_url($url); |
|||
$PAGE->set_pagelayout('admin'); |
|||
navigation_node::override_active_url($usersurl); |
|||
|
|||
list($instance, $plugin) = $manager->get_user_enrolment_components($ue); |
|||
if (!$plugin->allow_unenrol($instance) || $instance->enrol != 'apply' || !($plugin instanceof enrol_apply_plugin)) { |
|||
print_error('erroreditenrolment', 'enrol'); |
|||
} |
|||
|
|||
// If the unenrolment has been confirmed and the sesskey is valid unenrol the user. |
|||
if ($confirm && confirm_sesskey() && $manager->unenrol_user($ue)) { |
|||
redirect($returnurl); |
|||
} |
|||
|
|||
$yesurl = new moodle_url($PAGE->url, array('confirm'=>1, 'sesskey'=>sesskey())); |
|||
$message = get_string('unenroluser', 'enrol_self', array('user' => fullname($user, true), 'course' => format_string($course->fullname))); |
|||
$fullname = fullname($user); |
|||
$title = get_string('unenrol', 'enrol_self'); |
|||
|
|||
$PAGE->set_title($title); |
|||
$PAGE->set_heading($title); |
|||
$PAGE->navbar->add($title); |
|||
$PAGE->navbar->add($fullname); |
|||
|
|||
echo $OUTPUT->header(); |
|||
echo $OUTPUT->heading($fullname); |
|||
echo $OUTPUT->confirm($message, $yesurl, $returnurl); |
|||
echo $OUTPUT->footer(); |
@ -0,0 +1,25 @@ |
|||
<?php |
|||
/** |
|||
* ************************************************************************* |
|||
* * Apply Enrol ** |
|||
* ************************************************************************* |
|||
* @copyright emeneo.com ** |
|||
* @link emeneo.com ** |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later ** |
|||
* ************************************************************************* |
|||
* ************************************************************************ |
|||
*/ |
|||
/** |
|||
* Short answer question type version information. |
|||
* |
|||
* @package enrol apply |
|||
* @copyright Emeneo {@link http://www.emeneo.com/} |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$plugin->version = 20131209; |
|||
$plugin->requires = 2011080100; |
|||
$plugin->maturity = MATURITY_STABLE; |
|||
$plugin->release = 'Course Enrol Apply Plugin Version 1.2.1(build 20131209)'; |
|||
$plugin->cron = 180; |
Loading…
Reference in new issue