upgrade
This commit is contained in:
134
plugin/advanced_subscription/test/mails.php
Normal file
134
plugin/advanced_subscription/test/mails.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* A script to render all mails templates.
|
||||
*
|
||||
* @package chamilo.plugin.advanced_subscription
|
||||
*/
|
||||
require_once __DIR__.'/../config.php';
|
||||
|
||||
// Protect test
|
||||
api_protect_admin_script();
|
||||
|
||||
// exit;
|
||||
$plugin = AdvancedSubscriptionPlugin::create();
|
||||
// Get validation hash
|
||||
$hash = Security::remove_XSS($_REQUEST['v']);
|
||||
// Get data from request (GET or POST)
|
||||
$data['action'] = 'confirm';
|
||||
$data['currentUserId'] = 1;
|
||||
$data['queueId'] = 0;
|
||||
$data['is_connected'] = true;
|
||||
$data['profile_completed'] = 90.0;
|
||||
// Init result array
|
||||
|
||||
$data['sessionId'] = 1;
|
||||
$data['studentUserId'] = 4;
|
||||
|
||||
// Prepare data
|
||||
// Get session data
|
||||
// Assign variables
|
||||
$fieldsArray = [
|
||||
'description',
|
||||
'target',
|
||||
'mode',
|
||||
'publication_end_date',
|
||||
'recommended_number_of_participants',
|
||||
];
|
||||
$sessionArray = api_get_session_info($data['sessionId']);
|
||||
$extraSession = new ExtraFieldValue('session');
|
||||
$extraField = new ExtraField('session');
|
||||
// Get session fields
|
||||
$fieldList = $extraField->get_all([
|
||||
'variable IN ( ?, ?, ?, ?, ?)' => $fieldsArray,
|
||||
]);
|
||||
$fields = [];
|
||||
// Index session fields
|
||||
foreach ($fieldList as $field) {
|
||||
$fields[$field['id']] = $field['variable'];
|
||||
}
|
||||
|
||||
$mergedArray = array_merge([$data['sessionId']], array_keys($fields));
|
||||
$sessionFieldValueList = $extraSession->get_all(
|
||||
['item_id = ? field_id IN ( ?, ?, ?, ?, ?, ?, ? )' => $mergedArray]
|
||||
);
|
||||
foreach ($sessionFieldValueList as $sessionFieldValue) {
|
||||
// Check if session field value is set in session field list
|
||||
if (isset($fields[$sessionFieldValue['field_id']])) {
|
||||
$var = $fields[$sessionFieldValue['field_id']];
|
||||
$val = $sessionFieldValue['value'];
|
||||
// Assign session field value to session
|
||||
$sessionArray[$var] = $val;
|
||||
}
|
||||
}
|
||||
// Get student data
|
||||
$studentArray = api_get_user_info($data['studentUserId']);
|
||||
$studentArray['picture'] = $studentArray['avatar'];
|
||||
|
||||
// Get superior data if exist
|
||||
$superiorId = UserManager::getFirstStudentBoss($data['studentUserId']);
|
||||
if (!empty($superiorId)) {
|
||||
$superiorArray = api_get_user_info($superiorId);
|
||||
} else {
|
||||
$superiorArray = api_get_user_info(3);
|
||||
}
|
||||
// Get admin data
|
||||
$adminsArray = UserManager::get_all_administrators();
|
||||
$isWesternNameOrder = api_is_western_name_order();
|
||||
foreach ($adminsArray as &$admin) {
|
||||
$admin['complete_name'] = $isWesternNameOrder ?
|
||||
$admin['firstname'].', '.$admin['lastname'] : $admin['lastname'].', '.$admin['firstname']
|
||||
;
|
||||
}
|
||||
unset($admin);
|
||||
// Set data
|
||||
$data['action'] = 'confirm';
|
||||
$data['student'] = $studentArray;
|
||||
$data['superior'] = $superiorArray;
|
||||
$data['admins'] = $adminsArray;
|
||||
$data['admin'] = current($adminsArray);
|
||||
$data['session'] = $sessionArray;
|
||||
$data['signature'] = api_get_setting('Institution');
|
||||
$data['admin_view_url'] = api_get_path(WEB_PLUGIN_PATH).
|
||||
'advanced_subscription/src/admin_view.php?s='.$data['sessionId'];
|
||||
$data['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_BOSS_APPROVED;
|
||||
$data['student']['acceptUrl'] = $plugin->getQueueUrl($data);
|
||||
$data['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_BOSS_DISAPPROVED;
|
||||
$data['student']['rejectUrl'] = $plugin->getQueueUrl($data);
|
||||
$tpl = new Template($plugin->get_lang('plugin_title'));
|
||||
$tpl->assign('data', $data);
|
||||
$tplParams = [
|
||||
'user',
|
||||
'student',
|
||||
'students',
|
||||
'superior',
|
||||
'admins',
|
||||
'admin',
|
||||
'session',
|
||||
'signature',
|
||||
'admin_view_url',
|
||||
'acceptUrl',
|
||||
'rejectUrl',
|
||||
];
|
||||
foreach ($tplParams as $tplParam) {
|
||||
$tpl->assign($tplParam, $data[$tplParam]);
|
||||
}
|
||||
|
||||
$dir = __DIR__.'/../views/';
|
||||
$files = scandir($dir);
|
||||
|
||||
echo '<br>', '<pre>', print_r($files, 1), '</pre>';
|
||||
|
||||
foreach ($files as $k => &$file) {
|
||||
if (
|
||||
is_file($dir.$file) &&
|
||||
strpos($file, '.tpl') &&
|
||||
$file != 'admin_view.tpl'
|
||||
) {
|
||||
echo '<pre>', $file, '</pre>';
|
||||
echo $tpl->fetch('/advanced_subscription/views/'.$file);
|
||||
} else {
|
||||
unset($files[$k]);
|
||||
}
|
||||
}
|
||||
echo '<br>', '<pre>', print_r($files, 1), '</pre>';
|
||||
47
plugin/advanced_subscription/test/terms_to_pdf.php
Normal file
47
plugin/advanced_subscription/test/terms_to_pdf.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* A script to render all mails templates.
|
||||
*
|
||||
* @package chamilo.plugin.advanced_subscription
|
||||
*/
|
||||
require_once __DIR__.'/../config.php';
|
||||
|
||||
// Protect test
|
||||
api_protect_admin_script();
|
||||
|
||||
$data['action'] = 'confirm';
|
||||
$data['currentUserId'] = 1;
|
||||
$data['queueId'] = 0;
|
||||
$data['is_connected'] = true;
|
||||
$data['profile_completed'] = 90.0;
|
||||
$data['sessionId'] = intval($_REQUEST['s']);
|
||||
$data['studentUserId'] = intval($_REQUEST['u']);
|
||||
$data['student'] = api_get_user_info($data['studentUserId']);
|
||||
$data['session'] = api_get_session_info($data['sessionId']);
|
||||
|
||||
if (!empty($data['sessionId']) && !empty($data['studentUserId'])) {
|
||||
$plugin = AdvancedSubscriptionPlugin::create();
|
||||
|
||||
if (api_get_plugin_setting('courselegal', 'tool_enable')) {
|
||||
$courseLegal = CourseLegalPlugin::create();
|
||||
$courses = SessionManager::get_course_list_by_session_id($data['sessionId']);
|
||||
$course = current($courses);
|
||||
$data['courseId'] = $course['id'];
|
||||
$data['course'] = api_get_course_info_by_id($data['courseId']);
|
||||
$termsAndConditions = $courseLegal->getData($data['courseId'], $data['sessionId']);
|
||||
$termsAndConditions = $termsAndConditions['content'];
|
||||
$termsAndConditions = $plugin->renderTemplateString($termsAndConditions, $data);
|
||||
$tpl = new Template($plugin->get_lang('Terms'));
|
||||
$tpl->assign('session', $data['session']);
|
||||
$tpl->assign('student', $data['student']);
|
||||
$tpl->assign('sessionId', $data['sessionId']);
|
||||
$tpl->assign('termsContent', $termsAndConditions);
|
||||
$termsAndConditions = $tpl->fetch('/advanced_subscription/views/terms_and_conditions_to_pdf.tpl');
|
||||
$pdf = new PDF();
|
||||
$filename = 'terms'.sha1(rand(0, 99999));
|
||||
$pdf->content_to_pdf($termsAndConditions, null, $filename, null, 'F');
|
||||
$fileDir = api_get_path(WEB_ARCHIVE_PATH).$filename.'.pdf';
|
||||
echo '<pre>', print_r($fileDir, 1), '</pre>';
|
||||
}
|
||||
}
|
||||
86
plugin/advanced_subscription/test/ws_session_user.php
Normal file
86
plugin/advanced_subscription/test/ws_session_user.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* A script to test session details by user web service.
|
||||
*
|
||||
* @package chamilo.plugin.advanced_subscription
|
||||
*/
|
||||
|
||||
/**
|
||||
* Init.
|
||||
*/
|
||||
require_once __DIR__.'/../config.php';
|
||||
// Protect test
|
||||
api_protect_admin_script();
|
||||
|
||||
// exit;
|
||||
|
||||
$plugin = AdvancedSubscriptionPlugin::create();
|
||||
$hookPlugin = HookAdvancedSubscription::create();
|
||||
// Get params from request (GET or POST)
|
||||
$params = [];
|
||||
// Init result array
|
||||
$params['user_id'] = intval($_REQUEST['u']);
|
||||
$params['user_field'] = 'drupal_user_id';
|
||||
$params['session_id'] = intval($_REQUEST['s']);
|
||||
$params['profile_completed'] = 100;
|
||||
$params['is_connected'] = true;
|
||||
|
||||
/**
|
||||
* Copied code from WSHelperVerifyKey function.
|
||||
*/
|
||||
/**
|
||||
* Start WSHelperVerifyKey.
|
||||
*/
|
||||
//error_log(print_r($params,1));
|
||||
$check_ip = false;
|
||||
$ip = trim($_SERVER['REMOTE_ADDR']);
|
||||
// if we are behind a reverse proxy, assume it will send the
|
||||
// HTTP_X_FORWARDED_FOR header and use this IP instead
|
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
list($ip1, $ip2) = split(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
$ip = trim($ip1);
|
||||
}
|
||||
// Check if a file that limits access from webservices exists and contains
|
||||
// the restraining check
|
||||
if (is_file(api_get_path(WEB_CODE_PATH).'webservices/webservice-auth-ip.conf.php')) {
|
||||
include api_get_path(WEB_CODE_PATH).'webservices/webservice-auth-ip.conf.php';
|
||||
if (!empty($ws_auth_ip)) {
|
||||
$check_ip = true;
|
||||
}
|
||||
}
|
||||
|
||||
global $_configuration;
|
||||
if ($check_ip) {
|
||||
$security_key = $_configuration['security_key'];
|
||||
} else {
|
||||
$security_key = $ip.$_configuration['security_key'];
|
||||
//error_log($secret_key.'-'.$security_key);
|
||||
}
|
||||
/**
|
||||
* End WSHelperVerifyKey.
|
||||
*/
|
||||
$params['secret_key'] = sha1($security_key);
|
||||
|
||||
// Registration soap wsdl
|
||||
$wsUrl = api_get_path(WEB_CODE_PATH).'webservices/registration.soap.php?wsdl';
|
||||
$options = [
|
||||
'location' => $wsUrl,
|
||||
'uri' => $wsUrl,
|
||||
];
|
||||
|
||||
/**
|
||||
* WS test.
|
||||
*/
|
||||
try {
|
||||
// Init soap client
|
||||
$client = new SoapClient(null, $options);
|
||||
// Soap call to WS
|
||||
$result = $client->__soapCall('HookAdvancedSubscription..WSSessionGetDetailsByUser', [$params]);
|
||||
if (is_object($result) && isset($result->action_url)) {
|
||||
echo '<br />';
|
||||
echo Display::url("message".$result->message, $result->action_url);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
Reference in New Issue
Block a user