Add terms and conditions, script and ws - refs BT#9461#hook

1.10.x
Daniel Barreto 10 years ago
parent 1fb1fc43c0
commit 9a5c4afc9a
  1. 10
      plugin/advanced_subscription/ajax/advanced_subscription.ajax.php
  2. 2
      plugin/advanced_subscription/lang/english.php
  3. 2
      plugin/advanced_subscription/lang/spanish.php
  4. 52
      plugin/advanced_subscription/src/AdvancedSubscriptionPlugin.php
  5. 80
      plugin/advanced_subscription/src/HookAdvancedSubscription.php
  6. 72
      plugin/advanced_subscription/src/terms_and_conditions.php
  7. 27
      plugin/advanced_subscription/views/terms_and_conditions.tpl

@ -25,6 +25,8 @@ $data['newStatus'] = intval($_REQUEST['e']);
// $data['is_connected'] = isset($_REQUEST['is_connected']) ? boolval($_REQUEST['is_connected']) : false;
$data['is_connected'] = true;
$data['profile_completed'] = isset($_REQUEST['profile_completed']) ? floatval($_REQUEST['profile_completed']) : 0;
$data['accept_terms'] = isset($_REQUEST['accept_terms']) ? intval($_REQUEST['accept_terms']) : 0;
$data['courseId'] = isset($_REQUEST['c']) ? intval($_REQUEST['c']) : 0;
// Init result array
$result = array('error' => true, 'errorMessage' => get_lang('ThereWasAnError'));
// Check if data is valid or is for start subscription
@ -274,6 +276,14 @@ if ($verified) {
}
}
break;
case 'terms_response':
// Check if new status is set
if (isset($data['accept_terms']) && $data['accept_terms'] == 1) {
$legalPlugin = CourseLegalPlugin::create()->saveUserLegal($data['studentId'], $data['courseId'], $data['sessionId']);
} else {
$result['errorMessage'] = 'Need terms response params';
}
break;
default:
$result['errorMessage'] = 'This action does not exist!';
}

@ -135,3 +135,5 @@ $strings['MailContentReminderSuperiorSecond'] = 'We invite you to accept or reje
$strings['MailTitleReminderMaxSuperior'] = 'Reminder: Course inscription request for your collaborators';
$strings['MailContentReminderMaxSuperior'] = 'We remind you, we have received inscription requests below to course <strong>%s</strong> for your collaborators. This course is starting at <strong>%s</strong>. Course details: <strong>%s</strong>.';
$strings['MailContentReminderMaxSuperiorSecond'] = 'This course have limited vacancies and has received a high inscription request rate, So we recommend all areas to accept at most <strong>%s</strong> candidates. We invite you to accept or reject inscription request, clicking corresponding button for each collaborator.';
$strings['YouMustAcceptTermsAndConditions'] = 'To subscribe to course <strong>%s</strong>, you must accept this terms and conditions.';

@ -135,3 +135,5 @@ $strings['MailContentReminderSuperiorSecond'] = 'Le invitamos a aprobar o desapr
$strings['MailTitleReminderMaxSuperior'] = 'Recordatorio: Solicitud de consideración de curso para colaborador(es)';
$strings['MailContentReminderMaxSuperior'] = 'Le recordamos que hemos recibido las siguientes solicitudes de suscripción al curso <strong>%s</strong> de parte de sus colaboradores. El curso se iniciará el <strong>%s</strong>. Detalles del curso: <strong>%s</strong>.';
$strings['MailContentReminderMaxSuperiorSecond'] = 'Este curso tiene una cantidad de cupos limitados y ha recibido una alta tasa de solicitudes de inscripción, por lo que recomendamos que cada área apruebe un máximo de <strong>%s</strong> candidatos. Le invitamos a aprobar o desaprobar las suscripciones, dando clic en el botón correspondiente a continuación para cada colaborador.';
$strings['YouMustAcceptTermsAndConditions'] = 'Para inscribirse al curso <strong>%s</strong>, debe aceptar estos términos y condiciones.';

@ -25,6 +25,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
'min_profile_percentage' => 'text',
'check_induction' => 'boolean',
'secret_key' => 'text',
'terms_and_conditions' => 'wysiwyg'
);
parent::__construct('1.0', 'Imanol Losada, Daniel Barreto', $parameters);
@ -883,7 +884,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
'e=' . intval($params['newStatus']) . '&' .
'u=' . intval($params['studentUserId']) . '&' .
'q=' . intval($params['queueId']) . '&' .
'is_connected=' . true . '&' .
'is_connected=' . 1 . '&' .
'profile_completed=' . intval($params['profile_completed']) . '&' .
'v=' . $this->generateHash($params);
return $url;
@ -1037,4 +1038,53 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
{
return 'advanced_subscription';
}
/**
* Return the url to show subscription terms
* @param array $params
* @param int $mode
* @return string
*/
public function getTermsUrl($params, $mode = 0)
{
$url = api_get_path(WEB_PLUGIN_PATH) . 'advanced_subscription/src/terms_and_conditions.php?' .
'a=' . Security::remove_XSS($params['action']) . '&' .
's=' . intval($params['sessionId']) . '&' .
'current_user_id=' . intval($params['currentUserId']) . '&' .
'e=' . intval($params['newStatus']) . '&' .
'u=' . intval($params['studentUserId']) . '&' .
'q=' . intval($params['queueId']) . '&' .
'is_connected=' . 1 . '&' .
'profile_completed=' . intval($params['profile_completed']) . '&' .
'r=' . intval($mode) . '&' .
'v=' . $this->generateHash($params);
// Launch popup
if ($mode == 0) {
$url = 'javascript:void(window.open(\'' . $url .'\',\'Terms\', \'100\', \'100\' );)';
}
return $url;
}
/**
* Return the url to get subscription terms
* @param array $params
* @param int $acceptTerms
* @return string
*/
public function getTermsResponseUrl($params, $acceptTerms = 0)
{
$url = api_get_path(WEB_PLUGIN_PATH) . 'advanced_subscription/ajax/advanced_subscription.ajax.php?' .
'a=' . Security::remove_XSS($params['action']) . '&' .
's=' . intval($params['sessionId']) . '&' .
'current_user_id=' . 0 . '&' .
'e=' . 0 . '&' .
'u=' . intval($params['studentUserId']) . '&' .
'q=' . 0 . '&' .
'is_connected=' . 1 . '&' .
'profile_completed=' . intval($params['profile_completed']) . '&' .
'accept_terms=' . intval($acceptTerms) . '&' .
'c=' . intval($params['courseId']) . '&' .
'v=' . $this->generateHash($params);
return $url;
}
}

@ -509,7 +509,7 @@ class HookAdvancedSubscription extends HookObserver implements
// Check conditions
if ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_NO_QUEUE) {
// No in Queue, require queue subscription url action
$data['action_url'] = self::$plugin->getQueueUrl($params);
$data['action_url'] = self::$plugin->getTermsUrl($params);
} elseif ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED) {
// send url action
$data['action_url'] = self::$plugin->getSessionUrl($sessionId);
@ -521,7 +521,7 @@ class HookAdvancedSubscription extends HookObserver implements
$data['action_url'] = self::$plugin->getSessionUrl($sessionId);
} elseif ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_NO_QUEUE) {
// in Queue or not, cannot be subscribed to session
$data['action_url'] = self::$plugin->getQueueUrl($params);
$data['action_url'] = self::$plugin->getTermsUrl($params);
} else {
// In queue, output status message, no more info.
}
@ -621,6 +621,82 @@ class HookAdvancedSubscription extends HookObserver implements
return $sessionList;
}
/**
* Get a list of sessions (id, coach_id, name, courses_num, users_num, classes_num,
* date_start, date_end, access_days_before_num, session_admin_id, visibility,
* session_category_id, promotion_id,
* validated_user_num, waiting_user_num,
* extra, course) the validated_usernum and waiting_user_num are
* used when have the plugin for advance incsription enables.
* The extra data (field_name, field_value)
* The course data (course_id, course_code, course_title,
* coach_username, coach_firstname, coach_lastname)
* @param array $params List of parameters (id, category_name, access_url_id, secret_key)
* @return array|soap_fault Sessions list (id=>[title=>'title',url='http://...',date_start=>'...',date_end=>''])
*/
public static function WSTermsAndConditions($params)
{
global $debug;
if ($debug) {
error_log('WSListSessionsDetailsByCategory');
error_log('Params ' . print_r($params, 1));
}
$secretKey = $params['secret_key'];
// Check if secret key is valid
if (!WSHelperVerifyKey($secretKey)) {
return return_error(WS_ERROR_SECRET_KEY);
}
// Get Data
$data = array();
$data['sessionId'] = $params['session_id'];
$data['studentUserId'] = $params['user_id'];
$data['profile_completed'] = $params['profile_completed'];
$legalEnabled = api_get_plugin_setting('courselegal', 'tool_enable');
$legalPlugin = CourseLegalPlugin::create();
if (
UserManager::is_user_id_valid($data['studentUserId']) &&
SessionManager::isValidId($data['sessionId'])
) {
$courses = SessionManager::get_course_list_by_session_id($data['sessionId']);
$course = current($courses);
$data['courseId'] = $course['id'];
$data['session'] = api_get_session_info($data['sessionId']);
$data['student'] = Usermanager::get_user_info_by_id($data['studentUserId']);
if ($legalEnabled) {
// Get Terms content
$termsContent = $legalPlugin->getData($data['courseId'], $data['sessionId']);
$termsContent = $termsContent['content'];
$termsFiles = $legalPlugin->getCurrentFile($data['courseId'], $data['sessionId']);
$twigString = new \Twig_Environment(new \Twig_Loader_String());
$termsContent = $twigString->render(
$termsContent,
array(
'session' => $data['session'],
'student' => $data['student'],
)
);
} else {
$termsContent = '';
$termsFiles = '';
}
// Set output data
$data['action'] = 'terms_response';
$data['terms_content'] = $termsContent;
$data['terms_files'] = $termsFiles;
$data['accept_terms_url'] = self::$plugin->getTermsResponseUrl($data, 1);
$data['reject_terms_url'] = self::$plugin->getTermsResponseUrl($data, 0);
$data['reject_message'] = self::$plugin->get_lang('YouMustAcceptTermsAndConditions');
} else {
$data = return_error(WS_ERROR_INVALID_INPUT);
}
return $data;
}
/**
* Return notification content when the hook has been triggered
* @param HookNotificationContentEventInterface $hook

@ -0,0 +1,72 @@
<?php
/* For license terms, see /license.txt */
/**
* Script to show sessions terms and conditions
* @package chamilo.plugin.advanced_subscription
*/
/**
* Init
*/
require_once __DIR__ . '/../config.php';
// start plugin
$plugin = AdvancedSubscriptionPlugin::create();
$courseLegal = CourseLegalPlugin::create();
// Session ID
$data['action'] = Security::remove_XSS($_REQUEST['a']);
$data['sessionId'] = isset($_REQUEST['s']) ? intval($_REQUEST['s']) : 0;
$data['currentUserId'] = isset($_REQUEST['current_user_id']) ? intval($_REQUEST['current_user_id']) : 0;
$data['studentUserId'] = isset($_REQUEST['u']) ? intval($_REQUEST['u']) : 0;
$data['queueId'] = isset($_REQUEST['q']) ? intval($_REQUEST['q']) : 0;
$data['newStatus'] = isset($_REQUEST['e']) ? intval($_REQUEST['e']) : 0;
$data['is_connected'] = true;
$data['profile_completed'] = isset($_REQUEST['profile_completed']) ? floatval($_REQUEST['profile_completed']) : 0;
$data['termsRejected'] = isset($_REQUEST['r']) ? intval($_REQUEST['r']) : 0;
// Init template
$tpl = new Template($plugin->get_lang('plugin_title'));
if (
!empty($data['sessionId']) &&
!empty($data['studentUserId']) &&
api_get_plugin_setting('courselegal', 'tool_enable')
) {
$courses = SessionManager::get_course_list_by_session_id($data['sessionId']);
$course = current($courses);
$data['courseId'] = $course['id'];
$termsAndConditions = $courseLegal->getData($data['courseId'], $data['sessionId']);
$termsAndConditions = $termsAndConditions['content'];
$termFiles = $courseLegal->getCurrentFile($data['courseId'], $data['sessionId']);
$data['session'] = api_get_session_info($data['sessionId']);
$data['student'] = Usermanager::get_user_info_by_id($data['studentUserId']);
$data['acceptTermsUrl'] = $plugin->getQueueUrl($data);
$data['rejectTermsUrl'] = $plugin->getTermsUrl($data, 1);
// Use Twig with String loader
$twigString = new \Twig_Environment(new \Twig_Loader_String());
$termsContent = $twigString->render(
$termsAndConditions,
array(
'session' => $data['session'],
'student' => $data['student'],
)
);
} else {
$termsContent = '';
$termFiles = '';
$data['acceptTermsUrl'] = '#';
$data['rejectTermsUrl'] = '#';
}
// Assign into content
$tpl->assign('termsRejected', $data['termsRejected']);
$tpl->assign('acceptTermsUrl', $data['acceptTermsUrl']);
$tpl->assign('rejectTermsUrl', $data['rejectTermsUrl']);
$tpl->assign('session', $data['session']);
$tpl->assign('student', $data['student']);
$tpl->assign('sessionId', $data['sessionId']);
$tpl->assign('termsContent', $termsContent);
$tpl->assign('termsFiles', $termFiles);
$content = $tpl->fetch('/advanced_subscription/views/terms_and_conditions.tpl');
$tpl->assign('content', $content);
// Display
$tpl->display_one_col_template();

@ -0,0 +1,27 @@
{% if termsRejected == 1 %}
<div class="error-message">
{{ "YouMustAcceptTermsAndConditions" | get_plugin_lang("AdvancedSubscriptionPlugin") | format(session.name) }}
</div>
{% endif %}
<div class="legal-terms">
{{ termsContent }}
</div>
<div>
{{ termsFiles }}
</div>
<div>
<a
class="btn btn-success btn-advanced-subscription btn-accept"
href="{{ acceptTermsUrl }}"
>
{{ "AcceptInfinitive" | get_plugin_lang("AdvancedSubscriptionPlugin") }}
</a>
<a
class="btn btn-danger btn-advanced-subscription btn-reject"
href="{{ rejectTermsUrl }}"
>
{{ "RejectInfinitive" | get_plugin_lang("AdvancedSubscriptionPlugin") }}
</a>
</div>
<link href="{{ _p.web_plugin }}advanced_subscription/views/css/style.css" rel="stylesheet" type="text/css">
Loading…
Cancel
Save