Allow subscription from users without boss - refs BT#9092

1.10.x
Daniel Barreto 10 years ago
parent b0236fd202
commit a2ee3130fb
  1. 84
      plugin/advancedsubscription/ajax/advsub.ajax.php
  2. 1
      plugin/advancedsubscription/config.php
  3. 26
      plugin/advancedsubscription/src/AdvancedSubscriptionPlugin.class.php
  4. 11
      plugin/advancedsubscription/views/advsub_request_approved_info_admin.tpl

@ -63,35 +63,43 @@ if (!empty($a) && !empty($u)) {
break;
case 'subscribe': // Subscription
$bossId = UserManager::getStudentBoss($u);
if (true || !empty($bossId)) { // @TODO: If boss does not exist, then update queue status for admin aproval
$res = AdvancedSubscriptionPlugin::create()->startSubscription($u, $s, $params);
if ($res === true) {
// send mail to superior
$sessionArray = api_get_session_info($s);
$extraSession = new ExtraFieldValue('session');
$var = $extraSession->get_values_by_handler_and_field_variable($s, 'as_description');
$sessionArray['as_description'] = $var['field_valiue'];
$var = $extraSession->get_values_by_handler_and_field_variable($s, 'target');
$sessionArray['target'] = $var['field_valiue'];
$var = $extraSession->get_values_by_handler_and_field_variable($s, 'mode');
$sessionArray['mode'] = $var['field_valiue'];
$var = $extraSession->get_values_by_handler_and_field_variable($s, 'publication_end_date');
$sessionArray['publication_end_date'] = $var['field_value'];
$var = $extraSession->get_values_by_handler_and_field_variable($s, 'recommended_number_of_participants');
$sessionArray['recommended_number_of_participants'] = $var['field_valiue'];
$studentArray = api_get_user_info($u);
$superiorArray = api_get_user_info(UserManager::getStudentBoss($u));
$adminsArray = UserManager::get_all_administrators();
$data = array(
'student' => $studentArray,
'superior' => $superiorArray,
'admins' => $adminsArray,
'session' => $sessionArray,
'signature' => 'AQUI DEBE IR UNA FIRMA',
);
$res = AdvancedSubscriptionPlugin::create()->startSubscription($u, $s, $params);
if ($res === true) {
// send mail to superior
$sessionArray = api_get_session_info($s);
$extraSession = new ExtraFieldValue('session');
$var = $extraSession->get_values_by_handler_and_field_variable($s, 'as_description');
$sessionArray['as_description'] = $var['field_valiue'];
$var = $extraSession->get_values_by_handler_and_field_variable($s, 'target');
$sessionArray['target'] = $var['field_valiue'];
$var = $extraSession->get_values_by_handler_and_field_variable($s, 'mode');
$sessionArray['mode'] = $var['field_valiue'];
$var = $extraSession->get_values_by_handler_and_field_variable($s, 'publication_end_date');
$sessionArray['publication_end_date'] = $var['field_value'];
$var = $extraSession->get_values_by_handler_and_field_variable($s, 'recommended_number_of_participants');
$sessionArray['recommended_number_of_participants'] = $var['field_valiue'];
$studentArray = api_get_user_info($u);
$superiorId = UserManager::getStudentBoss($u);
if (!empty($superiorId)) {
$superiorArray = api_get_user_info($superiorId);
} else {
$superiorArray = null;
}
$adminsArray = UserManager::get_all_administrators();
$data = array(
'student' => $studentArray,
'superior' => $superiorArray,
'admins' => $adminsArray,
'session' => $sessionArray,
'signature' => 'AQUI DEBE IR UNA FIRMA',
);
if (empty($superiorId)) { // Does not have boss
$data['admin_view_url'] = api_get_path(WEB_PLUGIN_PATH) . 'advancedsubscription/src/admin_view.php?s=' . $s;
error_log($data['admin_view_url']);
$result['mails'] = $plugin->sendMail($data, ADV_SUB_ACTION_STUDENT_REQUEST_NO_BOSS);
} else {
$dataUrl = array(
'a' => 'confirm',
's' => $s,
@ -104,21 +112,17 @@ if (!empty($a) && !empty($u)) {
$dataUrl['e'] = ADV_SUB_QUEUE_STATUS_BOSS_DISAPPROVED;
$data['rejectUrl'] = api_get_path(WEB_PLUGIN_PATH) . 'advancedsubscription/ajax/advsub.ajax.php' .
'?data=' . $plugin->encrypt($dataUrl);
$result['mails'] = $plugin->sendMail($data, ADV_SUB_ACTION_STUDENT_REQUEST);
$result['error'] = false;
$result['errorMessage'] = 'No error';
$result['pass'] = true;
} else {
if (is_string($res)) {
$result['errorMessage'] = $res;
} else {
$result['errorMessage'] = 'User can not be subscribed';
}
$result['pass'] = false;
}
$result['error'] = false;
$result['errorMessage'] = 'No error';
$result['pass'] = true;
} else {
$result['errorMessage'] = 'User does not have Boss';
if (is_string($res)) {
$result['errorMessage'] = $res;
} else {
$result['errorMessage'] = 'User can not be subscribed';
}
$result['pass'] = false;
}
@ -141,7 +145,7 @@ if (!empty($a) && !empty($u)) {
case 'confirm':
if (isset($e)) {
$res = $plugin->updateQueueStatus($data, $e);
if (true || $res === true) {
if ($res === true) {
$sessionArray = api_get_session_info($s);
$extraSession = new ExtraFieldValue('session');
$var = $extraSession->get_values_by_handler_and_field_variable($s, 'as_description');

@ -14,6 +14,7 @@ define('ADV_SUB_ACTION_SUPERIOR_DISAPPROVE', 2);
define('ADV_SUB_ACTION_SUPERIOR_SELECT', 3);
define('ADV_SUB_ACTION_ADMIN_APPROVE', 4);
define('ADV_SUB_ACTION_ADMIN_DISAPPROVE', 5);
define('ADV_SUB_ACTION_STUDENT_REQUEST_NO_BOSS', 6);
define('ADV_SUB_QUEUE_STATUS_NO_QUEUE', -1);
define('ADV_SUB_QUEUE_STATUS_START', 0);

@ -369,9 +369,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
'rejectUrl'
);
foreach ($tplParams as $tplParam) {
if (isset($data['superior'])) {
$tpl->assign($tplParam, $data[$tplParam]);
}
$tpl->assign($tplParam, $data[$tplParam]);
}
$mailIds = array();
switch ($actionType) {
@ -522,6 +520,28 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
);
}
break;
case ADV_SUB_ACTION_STUDENT_REQUEST_NO_BOSS:
// Mail to student
$mailIds[] = $this->sendMailMessage(
$data['u'],
$data['student']['user_id'],
$this->get_lang('MailStudentRequest'),
$tpl->fetch('/advancedsubscription/views/advsub_request_received.tpl'),
$data['s']
);
// Mail to admin
foreach ($data['admins'] as $adminId => $admin) {
$tpl->assign('admin', $admin);
$mailIds[] = $this->sendMailMessage(
$data['u'],
$adminId,
$this->get_lang('MailStudentRequest'),
$tpl->fetch('/advancedsubscription/views/advsub_request_approved_info_admin.tpl'),
$data['s'],
true
);
}
break;
default:
break;
}

@ -60,7 +60,16 @@
<td height="356">&nbsp;</td>
<td valign="top"><p>Estimado:</p>
<h2>{{ admin.complete_name }}</h2>
<p>La inscripción del alumno <strong>{{ student.complete_name_with_username }}</strong> al curso <strong>{{ session.name }}</strong> ha sido aprobada por su superior. Puede gestionar las inscripciones al curso <a href="{{ admin_view_url }}"><strong>aquí</strong></a><strong></strong></p>
<p>La inscripción del alumno
<strong>{{ student.complete_name_with_username }}</strong>
al curso <strong>{{ session.name }}</strong>
ha sido aprobada por su superior.
Puede gestionar las inscripciones al curso
<a href="{{ admin_view_url }}">
<strong>aquí</strong>
</a>
<strong></strong>
</p>
<p>Gracias.</p>
<h3>{{ signature }}</h3></td>
<td>&nbsp;</td>

Loading…
Cancel
Save