|
|
|
|
@ -322,6 +322,17 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$studentId = intval($studentId); |
|
|
|
|
$this->saveLastMessage($mailId, $studentId, $sessionId); |
|
|
|
|
} |
|
|
|
|
} elseif (!empty($mailId)) { |
|
|
|
|
// Update queue row, updated_at |
|
|
|
|
Database::update( |
|
|
|
|
Database::get_main_table(TABLE_ADVANCED_SUBSCRIPTION_QUEUE), |
|
|
|
|
array( |
|
|
|
|
'updated_at' => api_get_utc_datetime(), |
|
|
|
|
), |
|
|
|
|
array( |
|
|
|
|
'user_id = ? AND session_id = ?' => array($studentId, $sessionId) |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
return $mailId; |
|
|
|
|
} |
|
|
|
|
@ -431,7 +442,8 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$data['student']['user_id'], |
|
|
|
|
$this->get_lang('MailStudentRequest'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/student_notice_student.tpl'), |
|
|
|
|
$data['sessionId'] |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
// Mail to superior |
|
|
|
|
$mailIds[] = $this->sendMailMessage( |
|
|
|
|
@ -439,8 +451,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$data['superior']['user_id'], |
|
|
|
|
$this->get_lang('MailStudentRequest'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/student_notice_superior.tpl'), |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
$data['sessionId'] |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
|
case ADVANCED_SUBSCRIPTION_ACTION_SUPERIOR_APPROVE: |
|
|
|
|
@ -450,7 +461,8 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$data['student']['user_id'], |
|
|
|
|
$this->get_lang('MailBossAccept'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/superior_accepted_notice_student.tpl'), |
|
|
|
|
$data['sessionId'] |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
// Mail to superior |
|
|
|
|
$mailIds['render'] = $this->sendMailMessage( |
|
|
|
|
@ -468,8 +480,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$adminId, |
|
|
|
|
$this->get_lang('MailBossAccept'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/superior_accepted_notice_admin.tpl'), |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
$data['sessionId'] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
@ -499,7 +510,8 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$data['student']['user_id'], |
|
|
|
|
$this->get_lang('MailStudentRequestSelect'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/student_notice_student.tpl'), |
|
|
|
|
$data['sessionId'] |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
// Mail to superior |
|
|
|
|
$mailIds['render'] = $this->sendMailMessage( |
|
|
|
|
@ -507,8 +519,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$data['superior']['user_id'], |
|
|
|
|
$this->get_lang('MailStudentRequestSelect'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/student_notice_superior.tpl'), |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
$data['sessionId'] |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
|
case ADVANCED_SUBSCRIPTION_ACTION_ADMIN_APPROVE: |
|
|
|
|
@ -518,7 +529,8 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$data['student']['user_id'], |
|
|
|
|
$this->get_lang('MailAdminAccept'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/admin_accepted_notice_student.tpl'), |
|
|
|
|
$data['sessionId'] |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
// Mail to superior |
|
|
|
|
$mailIds[] = $this->sendMailMessage( |
|
|
|
|
@ -536,8 +548,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$adminId, |
|
|
|
|
$this->get_lang('MailAdminAccept'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/admin_accepted_notice_admin.tpl'), |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
$data['sessionId'] |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
|
case ADVANCED_SUBSCRIPTION_ACTION_ADMIN_DISAPPROVE: |
|
|
|
|
@ -576,7 +587,8 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$data['student']['user_id'], |
|
|
|
|
$this->get_lang('MailStudentRequestNoBoss'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/student_no_superior_notice_student.tpl'), |
|
|
|
|
$data['sessionId'] |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
// Mail to admin |
|
|
|
|
foreach ($data['admins'] as $adminId => $admin) { |
|
|
|
|
@ -586,8 +598,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$adminId, |
|
|
|
|
$this->get_lang('MailStudentRequestNoBoss'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/student_no_superior_notice_admin.tpl'), |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
$data['sessionId'] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
@ -607,8 +618,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$data['superior']['user_id'], |
|
|
|
|
$this->get_lang('MailRemindSuperior'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/reminder_notice_superior.tpl'), |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
$data['sessionId'] |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
|
case ADVANCED_SUBSCRIPTION_ACTION_REMINDER_SUPERIOR_MAX: |
|
|
|
|
@ -617,8 +627,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$data['superior']['user_id'], |
|
|
|
|
$this->get_lang('MailRemindSuperior'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/reminder_notice_superior_max.tpl'), |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
$data['sessionId'] |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
|
case ADVANCED_SUBSCRIPTION_ACTION_REMINDER_ADMIN: |
|
|
|
|
@ -630,8 +639,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$adminId, |
|
|
|
|
$this->get_lang('MailRemindAdmin'), |
|
|
|
|
$template->fetch('/advanced_subscription/views/reminder_notice_admin.tpl'), |
|
|
|
|
$data['sessionId'], |
|
|
|
|
true |
|
|
|
|
$data['sessionId'] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
@ -1045,7 +1053,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
* @param int $mode |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
public function getTermsUrl($params, $mode = 0) |
|
|
|
|
public function getTermsUrl($params, $mode = ADVANCED_SUBSCRIPTION_TERMS_MODE_POPUP) |
|
|
|
|
{ |
|
|
|
|
$url = api_get_path(WEB_PLUGIN_PATH) . 'advanced_subscription/src/terms_and_conditions.php?' . |
|
|
|
|
'a=' . Security::remove_XSS($params['action']) . '&' . |
|
|
|
|
@ -1059,32 +1067,52 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
'r=' . intval($mode) . '&' . |
|
|
|
|
'v=' . $this->generateHash($params); |
|
|
|
|
// Launch popup |
|
|
|
|
if ($mode == 0) { |
|
|
|
|
$url = 'javascript:void(window.open(\'' . $url .'\',\'Terms\', \'100\', \'100\' );)'; |
|
|
|
|
if ($mode == ADVANCED_SUBSCRIPTION_TERMS_MODE_POPUP) { |
|
|
|
|
$url = 'javascript:void(window.open(\'' . $url .'\',\'AdvancedSubscriptionTerms\', \'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700px,height=600px\', \'100\' ))'; |
|
|
|
|
} |
|
|
|
|
return $url; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the url to get subscription terms |
|
|
|
|
* Return the url to get mail rendered |
|
|
|
|
* @param array $params |
|
|
|
|
* @param int $acceptTerms |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
public function getTermsResponseUrl($params, $acceptTerms = 0) |
|
|
|
|
public function getRenderMailUrl($params) |
|
|
|
|
{ |
|
|
|
|
$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']) . '&' . |
|
|
|
|
$url = api_get_path(WEB_PLUGIN_PATH) . 'advanced_subscription/src/render_mail.php?' . |
|
|
|
|
'q=' . $params['queueId'] . '&' . |
|
|
|
|
'v=' . $this->generateHash($params); |
|
|
|
|
return $url; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the last message id from queue row |
|
|
|
|
* @param int $studentUserId |
|
|
|
|
* @param int $sessionId |
|
|
|
|
* @return int|bool |
|
|
|
|
*/ |
|
|
|
|
public function getLastMessageId($studentUserId, $sessionId) |
|
|
|
|
{ |
|
|
|
|
$studentUserId = intval($studentUserId); |
|
|
|
|
$sessionId = intval($sessionId); |
|
|
|
|
if (!empty($sessionId) && !empty($studentUserId)) { |
|
|
|
|
$row = Database::select( |
|
|
|
|
'last_message_id', |
|
|
|
|
Database::get_main_table(TABLE_ADVANCED_SUBSCRIPTION_QUEUE), |
|
|
|
|
array( |
|
|
|
|
'where' => array( |
|
|
|
|
'user_id = ? AND session_id = ?' => array($studentUserId, $sessionId), |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (count($row) > 0) { |
|
|
|
|
|
|
|
|
|
return $row[0]['last_message_id']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|