Updating plugin see BT#7848

1.9.x
Julio Montoya 11 years ago
parent 1c31e2613e
commit 476bce53f2
  1. 52
      main/inc/lib/mail.lib.inc.php
  2. 83
      plugin/courselegal/CourseLegalPlugin.php
  3. 0
      plugin/courselegal/config.php
  4. 0
      plugin/courselegal/install.php
  5. 5
      plugin/courselegal/lang/english.php
  6. 12
      plugin/courselegal/start.php

@ -9,7 +9,6 @@
*/
require_once api_get_path(LIBRARY_PATH).'phpmailer/class.phpmailer.php';
// A regular expression for testing against valid email addresses.
// It should actually be revised for using the complete RFC3696 description:
// http://tools.ietf.org/html/rfc3696#section-3
@ -30,9 +29,9 @@ require_once api_get_path(LIBRARY_PATH).'phpmailer/class.phpmailer.php';
* @see class.phpmailer.php
* @deprecated use api_mail_html()
*/
function api_mail($recipient_name, $recipient_email, $subject, $message, $sender_name = '',
function api_mail($recipient_name, $recipient_email, $subject, $message, $sender_name = '',
$sender_email = '', $extra_headers = '', $additional_parameters = array()) {
api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name,
api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name,
$sender_email, $extra_headers, null, null, $additional_parameters);
}
@ -57,9 +56,18 @@ function api_mail($recipient_name, $recipient_email, $subject, $message, $sender
* @return returns true if mail was sent
* @see class.phpmailer.php
*/
function api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name = '', $sender_email = '',
$extra_headers = array(), $data_file = array(), $embedded_image = false, $additional_parameters = array())
{
function api_mail_html(
$recipient_name,
$recipient_email,
$subject,
$message,
$sender_name = '',
$sender_email = '',
$extra_headers = array(),
$data_file = array(),
$embedded_image = false,
$additional_parameters = array()
) {
global $platform_email;
$mail = new PHPMailer();
@ -73,6 +81,9 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s
$mail->SMTPAuth = 1;
$mail->Username = $platform_email['SMTP_USER'];
$mail->Password = $platform_email['SMTP_PASS'];
$mail->From = $platform_email['SMTP_FROM_EMAIL'];
$mail->Sender = $platform_email['SMTP_FROM_EMAIL'];
$mail->FromName = $platform_email['SMTP_FROM_NAME'];
}
$mail->Priority = 3; // 5 = low, 1 = high
@ -92,23 +103,21 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s
// $mail->AddAttachment($path);
// $mail->AddAttachment($path, $filename);
if ($sender_email != '') {
$mail->From = $sender_email;
$mail->Sender = $sender_email;
//$mail->ConfirmReadingTo = $sender_email; // Disposition-Notification
} else {
$mail->From = $platform_email['SMTP_FROM_EMAIL'];
$mail->Sender = $platform_email['SMTP_FROM_EMAIL'];
//$mail->ConfirmReadingTo = $platform_email['SMTP_FROM_EMAIL']; // Disposition-Notification
if (!$platform_email['SMTP_AUTH']) {
if ($sender_email != '') {
$mail->From = $sender_email;
$mail->Sender = $sender_email;
$mail->FromName = $sender_name;
//$mail->ConfirmReadingTo = $sender_email; // Disposition-Notification
} else {
$mail->From = api_get_setting('emailAdministrator');
$mail->Sender = api_get_setting('emailAdministrator');
$mail->FromName = api_get_setting('administratorName').' '.api_get_setting('administratorSurname');
//$noReply = api_get_setting('noreply_email_address');
}
}
if ($sender_name != '') {
$mail->FromName = $sender_name;
} else {
$mail->FromName = $platform_email['SMTP_FROM_NAME'];
}
$mail->Subject = $subject;
$mail->AltBody = strip_tags(str_replace('<br />',"\n", api_html_entity_decode($message)));
// Send embedded image.
@ -196,7 +205,6 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s
// WordWrap the html body (phpMailer only fixes AltBody) FS#2988
$mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap);
// Send the mail message.
if (!$mail->Send()) {
@ -209,7 +217,7 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s
$installedPluginsList = $plugin->getInstalledPluginListObject();
foreach ($installedPluginsList as $installedPlugin) {
if ($installedPlugin->isMailPlugin and array_key_exists("smsType", $additional_parameters)) {
$clockworksmsObject = new Clockworksms();
$clockworksmsObject = new Clockworksms();
$clockworksmsObject->send($additional_parameters);
}
}

@ -19,7 +19,7 @@ class CourseLegalPlugin extends Plugin
/**
* @return CourseLegalPlugin
*/
static function create()
public static function create()
{
static $result = null;
return $result ? $result : $result = new self();
@ -238,10 +238,11 @@ class CourseLegalPlugin extends Plugin
}
/**
* @param int $courseId
* @param int $sessionId
* @param int $courseId
* @param int $sessionId
* @param string $filePath
*/
public function warnUsersByEmail($courseId, $sessionId)
public function warnUsersByEmail($courseId, $sessionId, $filePath = null)
{
$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo['code'];
@ -257,11 +258,24 @@ class CourseLegalPlugin extends Plugin
$subject = $this->get_lang("AgreementUpdated");
$message = sprintf($this->get_lang("AgreementWasUpdatedClickHere"), $url);
$dataFile = array(
'path' => $filePath,
'filename' => basename($filePath),
);
if (!empty($students)) {
foreach ($students as $student) {
$userId = $student['user_id'];
MessageManager::send_message_simple($userId, $subject, $message);
$userInfo = api_get_user_info($student['user_id']);
api_mail_html(
$userInfo['complete_name'],
$userInfo['email'],
$subject,
$message,
null,
null,
null,
$dataFile
);
//MessageManager::send_message_simple($student['user_id'], $subject, $message);
}
}
}
@ -269,6 +283,7 @@ class CourseLegalPlugin extends Plugin
/**
* @param int $courseId
* @param int $sessionId
* @param string $order
* @return array
*/
public function getUserAgreementList($courseId, $sessionId, $order = null)
@ -311,7 +326,8 @@ class CourseLegalPlugin extends Plugin
/**
* @param array $values
* @param array $file $_FILES['uploaded_file']
* @param array $file $_FILES['uploaded_file']
* @param bool $deleteFile
*/
public function save($values, $file = array(), $deleteFile = false)
{
@ -325,12 +341,11 @@ class CourseLegalPlugin extends Plugin
'session_id' => $sessionId,
);
$legalData = $this->getData($courseId, $sessionId);
$course = api_get_course_info_by_id($courseId);
$conditions['content'] = $values['content'];
$course = api_get_course_info();
$legalData = $this->getData($courseId, $sessionId);
$coursePath = api_get_path(SYS_COURSE_PATH).$course['directory'].'/courselegal';
$uploadResult = $coursePath.'/'.$legalData['filename'];
if (!is_dir($coursePath)) {
mkdir($coursePath, api_get_permissions_for_new_directories());
@ -338,8 +353,8 @@ class CourseLegalPlugin extends Plugin
require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
$uploadOk = process_uploaded_file($file, false);
$fileName = null;
if ($uploadOk) {
$uploadResult = handle_uploaded_document(
$course,
@ -368,18 +383,26 @@ class CourseLegalPlugin extends Plugin
}
}
}
$conditions['content'] = $values['content'];
$conditions['filename'] = $fileName;
if (empty($legalData)) {
$id = Database::insert($table, $conditions);
} else {
$id = $legalData['id'];
$updateParams = array(
'content' => $values['content'],
);
if (!empty($fileName)) {
$updateParams['filename'] = $fileName;
}
Database::update(
$table,
array(
'content' => $values['content'],
'filename' => $fileName
),
$updateParams,
array('id = ? ' => $id)
);
}
@ -398,12 +421,32 @@ class CourseLegalPlugin extends Plugin
}
}
if (isset($values['remove_previous_agreements']) && !empty($values['remove_previous_agreements'])) {
if (isset($values['remove_previous_agreements']) &&
!empty($values['remove_previous_agreements'])
) {
$this->removePreviousAgreements($courseId, $sessionId);
}
if (isset($values['warn_users_by_email']) && !empty($values['warn_users_by_email'])) {
$this->warnUsersByEmail($courseId, $sessionId);
$warnUsers = isset($values['warn_users_by_email']) ? $values['warn_users_by_email'] : null;
switch ($warnUsers) {
case '1':
// Nothing
break;
case '2':
// Send mail
$this->warnUsersByEmail($courseId, $sessionId);
break;
case '3':
// Send mail + attachment if exists.
if (!empty($legalData['filename'])) {
$this->warnUsersByEmail(
$courseId,
$sessionId,
$uploadResult
);
}
break;
}
}

@ -13,6 +13,11 @@ $strings['YouNeedToConfirmYourAgreementCheckYourEmail'] = 'You need to confirm y
$strings['DeleteFile'] = 'Delete file';
$strings['RemoveAllUserAgreements'] = 'Remove all user agreements';
$strings['WarnAllUsersByEmail'] = 'Warn all users by email';
$strings['WarnAllUsersByEmailAndSendAttachment'] = 'Warn all users by email and send the attachment.';
$strings['ReSendMailAgreementLink'] = 'Re send mail agreement link';
$strings['SendOnlyWarning'] = 'Send only warning';
$strings['SendAgreementFile'] = 'Send warning and attach the agreement';
$strings['NoSendWarning'] = 'No send warning';

@ -1,6 +1,7 @@
<?php
/* For license terms, see /license.txt */
$language_file = array('document','gradebook');
$language_file = array('document', 'gradebook');
require_once dirname(__FILE__) . '/config.php';
@ -34,10 +35,13 @@ if (!empty($file)) {
$form->addElement('checkbox', 'delete_file', null, $legal->get_lang('DeleteFile'));
$form->addElement('checkbox', 'remove_previous_agreements', null, $legal->get_lang('RemoveAllUserAgreements'));
$form->addElement('checkbox', 'warn_users_by_email', null, $legal->get_lang('WarnAllUsersByEmail'));
$form->addElement('radio', 'warn_users_by_email', null, $legal->get_lang('NoSendWarning'), 1);
$form->addElement('radio', 'warn_users_by_email', $legal->get_lang('WarnAllUsersByEmail'), $legal->get_lang('SendOnlyWarning'), 2);
$form->addElement('radio', 'warn_users_by_email', null, $legal->get_lang('SendAgreementFile'), 3);
$form->addElement('button', 'submit', get_lang('Send'));
$form->setDefaults($legal->getData($courseId, $sessionId));
$defaults = $legal->getData($courseId, $sessionId);
$defaults['warn_users_by_email'] = 1;
$form->setDefaults($defaults);
if ($form->validate()) {
$values = $form->getSubmitValues();

Loading…
Cancel
Save