Updating lang vars, fixing user link see BT#7848

1.9.x
Julio Montoya 11 years ago
parent 7b8e69f76f
commit 00bcd18827
  1. 35
      main/course_info/legal.php
  2. 123
      plugin/courselegal/CourseLegalPlugin.php
  3. 14
      plugin/courselegal/lang/english.php
  4. 15
      plugin/courselegal/start.php
  5. 92
      plugin/courselegal/user_list.php

@ -25,22 +25,23 @@ $course_legal = $course_info['legal'];
$enabled = api_get_plugin_setting('courselegal', 'tool_enable');
$pluginExtra = null;
$pluginLegal = false;
if ($enabled == 'true') {
$pluginLegal = true;
require_once api_get_path(SYS_PLUGIN_PATH).'courselegal/config.php';
$plugin = CourseLegalPlugin::create();
$data = $plugin->getData($course_info['real_id'], $session_id);
if (!empty($data)) {
$course_legal = $data['content'];
}
$userData = $plugin->getUserAcceptedLegal(
$user_id,
$course_info['real_id'],
$session_id
);
if (!empty($data)) {
$course_legal = $data['content'];
}
if (isset($_GET['web_agreement_link'])) {
$plugin->saveUserMailLegal(
$_GET['web_agreement_link'],
@ -54,9 +55,15 @@ if ($enabled == 'true') {
// Build the form
$form = new FormValidator('legal', 'GET', api_get_self().'?course_code='.$course_code.'&session_id='.$session_id);
$pluginMessage = null;
if ($pluginLegal && isset($userData)) {
if ($userData['web_agreement'] == 1 && empty($userData['mail_agreement'])) {
$pluginMessage = Display::return_message(get_lang('YouNeedToConfirmYourAgreementCheckYourEmail'));
$hideForm = false;
if ($pluginLegal && isset($userData) && !empty($userData)) {
if ($userData['web_agreement'] == 1) {
if (empty($userData['mail_agreement'])) {
$pluginMessage = Display::return_message(
$plugin->get_lang('YouNeedToConfirmYourAgreementCheckYourEmail')
);
$hideForm = true;
}
}
}
$form->addElement('header', get_lang('CourseLegalAgreement'));
@ -71,6 +78,8 @@ $form->addElement('style_submit_button', null, get_lang('Accept'), 'class="save"
$variable = 'accept_legal_'.$user_id.'_'.$course_info['real_id'].'_'.$session_id;
$url = api_get_course_url($course_code, $session_id);
if ($form->validate()) {
$accept_legal = $form->exportValue('accept_legal');
@ -79,6 +88,11 @@ if ($form->validate()) {
if (api_check_user_access_to_legal($course_info['visibility'])) {
Session::write($variable, true);
}
if ($pluginLegal) {
header('Location:' .$url);
exit;
}
}
}
@ -87,8 +101,6 @@ if (api_check_user_access_to_legal($course_info['visibility']) && Session::read(
$user_pass_open_course = true;
}
$url = api_get_course_url($course_code, $session_id);
if (empty($session_id)) {
if (CourseManager::is_user_subscribed_in_course($user_id, $course_code) ||
api_check_user_access_to_legal($course_info['visibility'])
@ -106,7 +118,6 @@ if (empty($session_id)) {
api_not_allowed();
}
} else {
if (api_is_platform_admin()) {
header('Location: '.$url);
}
@ -127,5 +138,7 @@ if (empty($session_id)) {
Display :: display_header();
echo $pluginMessage;
$form->display();
if ($hideForm == false) {
$form->display();
}
Display :: display_footer();

@ -48,7 +48,7 @@ class CourseLegalPlugin extends Plugin
if (api_is_allowed_to_edit()) {
$url = api_get_path(WEB_PLUGIN_PATH).'courselegal/start.php?'.api_get_cidreq();
$link = Display::url(
get_lang('Legal'),
$this->get_lang('CourseLegal'),
$url,
array('class' => 'btn')
);
@ -108,12 +108,12 @@ class CourseLegalPlugin extends Plugin
}
/**
* @param int $userId
* @param int $courseCode
* @param int $sessionId
*
* @return bool
*/
* @param int $userId
* @param int $courseCode
* @param int $sessionId
*
* @return bool
*/
public function saveUserLegal($userId, $courseCode, $sessionId)
{
$courseInfo = api_get_course_info($courseCode);
@ -136,17 +136,80 @@ class CourseLegalPlugin extends Plugin
);
$id = Database::insert($table, $values);
$url = api_get_path(WEB_CODE_PATH).'course_info/legal.php?web_agreement_link='.$uniqueId.'&course_code='.Security::remove_XSS($courseCode).'&session_id='.$sessionId;
$courseUrl = Display::url($url, $url);
$subject = get_lang("MailAgreement");
$message = sprintf(get_lang("MailAgreementWasSentWithClickX"), $courseUrl);
MessageManager::send_message_simple($userId, $subject, $message);
$this->sendMailLink($uniqueId, $userId, $courseId, $sessionId);
}
return $id;
}
/**
* @param int $userId
* @param int $courseId
* @param int $sessionId
*/
public function updateMailAgreementLink($userId, $courseId, $sessionId)
{
$data = $this->getUserAcceptedLegal($userId, $courseId, $sessionId);
if (!empty($data)) {
$table = Database::get_main_table(
'session_rel_course_rel_user_legal'
);
$uniqueId = api_get_unique_id();
Database::update(
$table,
array('mail_agreement_link' => $uniqueId),
array('id = ? ' => array($data['id']))
);
$this->sendMailLink($uniqueId, $userId, $courseId, $sessionId);
}
}
/**
* @param int $userId
* @param int $courseId
* @param int $sessionId
*/
public function deleteUserAgreement($userId, $courseId, $sessionId)
{
$data = $this->getUserAcceptedLegal($userId, $courseId, $sessionId);
if (!empty($data)) {
$table = Database::get_main_table(
'session_rel_course_rel_user_legal'
);
Database::delete(
$table,
array('id = ? ' => array($data['id']))
);
}
}
/**
* @param string $uniqueId
* @param int $userId
* @param int $courseId
* @param int $sessionId
*/
public function sendMailLink($uniqueId, $userId, $courseId, $sessionId)
{
$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo['code'];
$url = api_get_path(WEB_CODE_PATH).'course_info/legal.php?web_agreement_link='.$uniqueId.'&course_code='.Security::remove_XSS($courseCode).'&session_id='.$sessionId;
$courseUrl = Display::url($url, $url);
$sessionInfo = api_get_session_info($sessionId);
$sesstionTitle = null;
if (!empty($sessionInfo)) {
$sesstionTitle = ' ('.$sessionInfo['name'].')';
}
$courseTitle = $courseInfo['title'].$sesstionTitle;
$subject = $this->get_lang("MailAgreement");
$message = sprintf($this->get_lang("MailAgreementWasSentWithClickX"), $courseTitle, $courseUrl);
MessageManager::send_message_simple($userId, $subject, $message);
}
/**
* @param string $link
* @param int $userId
@ -192,8 +255,8 @@ class CourseLegalPlugin extends Plugin
$url = api_get_course_url($courseCode, $sessionId);
$url = Display::url($url, $url);
$subject = get_lang("AgreementUpdated");
$message = sprintf(get_lang("AgreementWasUpdatedClickHere"), $url);
$subject = $this->get_lang("AgreementUpdated");
$message = sprintf($this->get_lang("AgreementWasUpdatedClickHere"), $url);
if (!empty($students)) {
foreach ($students as $student) {
@ -203,6 +266,35 @@ class CourseLegalPlugin extends Plugin
}
}
/**
* @param int $courseId
* @param int $sessionId
* @return array
*/
public function getUserAgreementList($courseId, $sessionId, $order = null)
{
$courseId = intval($courseId);
$sessionId = intval($sessionId);
$table = Database::get_main_table('session_rel_course_rel_user_legal');
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$sql = "SELECT *
FROM $table s INNER JOIN $userTable u
ON u.user_id = s.user_id
WHERE c_id = $courseId AND session_id = $sessionId ";
if (!empty($order)) {
$sql .= $order;
}
$result = Database::query($sql);
$data = array();
if (Database::num_rows($result) > 0 ) {
$data = Database::store_result($result, 'ASSOC');
}
return $data;
}
/**
* @param int $courseId
* @param int $sessionId
@ -318,6 +410,7 @@ class CourseLegalPlugin extends Plugin
/**
* @param int $courseId
* @param int $sessionId
*
* @return array|mixed
*/
public function getData($courseId, $sessionId)

@ -2,3 +2,17 @@
$strings['plugin_title'] = "Course agreements";
$strings['plugin_comment'] = "Course agreements";
$strings['CourseLegal'] = 'Course legal agreement';
$strings['WebAgreement'] = 'Web agreement';
$strings['MailAgreement'] = 'Mail agreement';
$strings['MailAgreementWasSentWithClickX'] = 'Click to the link below to agree with the terms and conditions of course %s: <br /> %s';
$strings['AgreementUpdated'] = 'Agreement Updated';
$strings['AgreementWasUpdatedClickHere'] = 'Agreement was updated click here %s';
$strings['YouNeedToConfirmYourAgreementCheckYourEmail'] = 'You need to confirm your agreement check your email.';
$strings['DeleteFile'] = 'Delete file';
$strings['RemoveAllUserAgreements'] = 'Remove all user agreements';
$strings['WarnAllUsersByEmail'] = 'Warn all users by email';
$strings['ReSendMailAgreementLink'] = 'Re send mail agreement link';

@ -21,7 +21,7 @@ $courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
$form = new FormValidator('plugin', 'post', $url );
$form->addElement('header', get_lang('CourseLegal'));
$form->addElement('header', $legal->get_lang('CourseLegal'));
$form->addElement('hidden', 'session_id', $sessionId);
$form->addElement('hidden', 'c_id', $courseId);
$form->addElement('textarea', 'content', get_lang('Text'));
@ -32,9 +32,9 @@ if (!empty($file)) {
$form->addElement('label', get_lang('File'), $file);
}
$form->addElement('checkbox', 'delete_file', null, get_lang('DeleteFile'));
$form->addElement('checkbox', 'remove_previous_agreements', null, get_lang('RemoveAllUserAgreements'));
$form->addElement('checkbox', 'warn_users_by_email', null, get_lang('WarnAllUsersByEmail'));
$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('button', 'submit', get_lang('Send'));
$form->setDefaults($legal->getData($courseId, $sessionId));
@ -47,5 +47,10 @@ if ($form->validate()) {
header('Location: '.$url);
exit;
}
Display::display_header(get_lang('CourseLegal'));
Display::display_header($legal->get_lang('CourseLegal'));
$url = api_get_path(WEB_PLUGIN_PATH).'courselegal/user_list.php?'.api_get_cidreq();
$link = Display::url(Display::return_icon('user.png', get_lang('UserList')), $url);
echo '<div class="actions">'.$link.'</div>';
$form->display();
Display::display_footer();

@ -0,0 +1,92 @@
<?php
/* For license terms, see /license.txt */
$language_file = array('document', 'gradebook');
require_once dirname(__FILE__) . '/config.php';
// Course legal
$enabled = api_get_plugin_setting('courselegal', 'tool_enable');
if ($enabled != 'true') {
api_not_allowed(true);
}
if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}
$legal = CourseLegalPlugin::create();
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
$url = api_get_self().'?'.api_get_cidreq();
$action = isset($_GET['action']) ? $_GET['action'] : null;
switch($action) {
case 'resend':
if (isset($_GET['user_id'])) {
$legal->updateMailAgreementLink($_GET['user_id'], $courseId, $sessionId);
header('Location: '.$url);
exit;
}
break;
case 'delete':
if (isset($_GET['user_id'])) {
$legal->deleteUserAgreement($_GET['user_id'], $courseId, $sessionId);
header('Location: '.$url);
exit;
}
break;
}
$order = " ORDER BY firstname, lastname";
$userList = $legal->getUserAgreementList($courseId, $sessionId, $order);
$table = new HTML_Table(array('class' => 'data_table'));
$table->setHeaderContents(0, 0, get_lang('User'));
$table->setHeaderContents(0, 1, $legal->get_lang('WebAgreement'));
$table->setHeaderContents(0, 2, $legal->get_lang('MailAgreement'));
$table->setHeaderContents(0, 3, $legal->get_lang('Actions'));
$row = 1;
$pluginPath = api_get_path(WEB_PLUGIN_PATH).'courselegal/';
if (!empty($userList)) {
foreach ($userList as $user) {
$userName = api_get_person_name($user['firstname'], $user['lastname']);
$webDate = !empty($user['web_agreement_date']) ? api_get_local_time($user['web_agreement_date']) : '-';
$mailDate = !empty($user['mail_agreement_date']) ? api_get_local_time($user['mail_agreement_date']) : '-';
$url = $pluginPath.'user_list.php?action=resend&user_id='.$user['user_id'].'&'.api_get_cidreq();
$link = Display::url(
Display::return_icon('inbox.png', $legal->get_lang('ReSendMailAgreementLink')),
$url
);
$deleteLink = Display::url(
Display::return_icon('delete.png', $legal->get_lang('Delete')),
$pluginPath.'user_list.php?action=delete&user_id='.$user['user_id'].'&'.api_get_cidreq()
);
$table->setCellContents($row, 0, $userName);
$table->setCellContents($row, 1, $webDate);
$table->setCellContents($row, 2, $mailDate);
$table->setCellContents($row, 3, $link.' '.$deleteLink);
$row++;
/*
'web_agreement' => string '1' (length=1)
'web_agreement_date' => string '2014-09-30 14:36:30' (length=19)
'mail_agreement' => string '1' (length=1)
'mail_agreement_date' => string '2014-09-30 14:43:16' (length=19)
'mail_agreement_link' => s*/
}
}
$url = $pluginPath.'start.php?'.api_get_cidreq();
$interbreadcrumb[] = array("url" => $url, "name" => $legal->get_lang('CourseLegal'));
Display::display_header($legal->get_lang('UserList'));
$table->display();
Display::display_footer();
Loading…
Cancel
Save