From 6e4f174e4433927ec47b65a27a1650fa4650af34 Mon Sep 17 00:00:00 2001 From: Daniel Barreto Date: Wed, 4 Feb 2015 17:26:51 -0500 Subject: [PATCH] Fix admin view approval and mails - refs BT#9092 --- .../advancedsubscription/ajax/advsub.ajax.php | 42 ++++++++- .../src/AdvancedSubscriptionPlugin.class.php | 86 +++++++++++-------- .../advancedsubscription/src/admin_view.php | 37 +++++++- .../advancedsubscription/views/admin_view.tpl | 4 +- 4 files changed, 127 insertions(+), 42 deletions(-) diff --git a/plugin/advancedsubscription/ajax/advsub.ajax.php b/plugin/advancedsubscription/ajax/advsub.ajax.php index c5ae106144..3ea2149e0b 100644 --- a/plugin/advancedsubscription/ajax/advsub.ajax.php +++ b/plugin/advancedsubscription/ajax/advsub.ajax.php @@ -22,6 +22,8 @@ if (isset($data) && is_array($data)) { $u = isset($data['u']) ? $data['u'] : null; // Session ID $s = isset($data['s']) ? $data['s'] : null; + // Adv sub action + $e = isset($data['e']) ? intval($data['e']) : null; // More data $params['is_connected'] = isset($data['is_connected']) ? $data['is_connected'] : false; $params['profile_completed'] = isset($data['profile_completed']) ? $data['profile_completed'] : 0; @@ -30,9 +32,11 @@ if (isset($data) && is_array($data)) { // Action code $a = isset($_REQUEST['a']) ? Security::remove_XSS($_REQUEST['a']) : null; // User ID - $u = isset($_REQUEST['u']) ? Security::remove_XSS($_REQUEST['u']) : null; + $u = isset($_REQUEST['u']) ? intval($_REQUEST['u']) : null; // Session ID - $s = isset($_REQUEST['s']) ? Security::remove_XSS($_REQUEST['s']) : null; + $s = isset($_REQUEST['s']) ? intval($_REQUEST['s']) : null; + // Adv sub action + $e = isset($_REQUEST['e']) ? intval($_REQUEST['e']) : null; // More data $params['is_connected'] = isset($_REQUEST['is_connected']) ? $_REQUEST['is_connected'] : false; $params['profile_completed'] = isset($_REQUEST['profile_completed']) ? $_REQUEST['profile_completed'] : 0; @@ -120,6 +124,40 @@ if (!empty($a) && !empty($u)) { $result['pass'] = false; } break; + case 'confirm': + if (isset($e)) { + $res = $plugin->updateQueueStatus($data, $e); + if (true || $res === true) { + $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(); + foreach ($adminsArray as &$admin) { + $admin['complete_name'] = $admin['lastname'] . ', ' . $admin['firstname']; + } + unset($admin); + $data['student'] = $studentArray; + $data['superior'] = $superiorArray; + $data['admins'] = $adminsArray; + $data['session'] = $sessionArray; + $data['signature'] = 'AQUI DEBE IR UNA FIRMA'; + $result['mailIds'] = $plugin->sendMail($data, $data['action']); + } else { + $result['errorMessage'] = 'User queue can not be updated'; + } + } + break; default: $result['errorMessage'] = 'Action do not exist!'; } diff --git a/plugin/advancedsubscription/src/AdvancedSubscriptionPlugin.class.php b/plugin/advancedsubscription/src/AdvancedSubscriptionPlugin.class.php index ee01b3d2da..b8556ae859 100644 --- a/plugin/advancedsubscription/src/AdvancedSubscriptionPlugin.class.php +++ b/plugin/advancedsubscription/src/AdvancedSubscriptionPlugin.class.php @@ -251,22 +251,19 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface /** * Send message for the student subscription approval to a specific session * @param int $studentId + * @param int $receiverId * @param string $subject * @param string $content * @param int $sessionId * @param bool $save * @return bool|int */ - public function sendMailMessage($studentId, $subject, $content, $sessionId, $save = false) + public function sendMailMessage($studentId, $receiverId, $subject, $content, $sessionId, $save = false) { - var_dump($studentId); - var_dump($subject); - var_dump($content); - var_dump($sessionId); global $_configuration; // @TODO: Add $_configuration['no_reply_user_id'] to configuration file $mailId = MessageManager::send_message( - $studentId, + $receiverId, $subject, $content, null, @@ -280,9 +277,8 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface if ($save && !empty($mailId)) { // Save as sent message - $mailId = $this->saveLastMessage($mailId, $studentId, $sessionId); + $this->saveLastMessage($mailId, $studentId, $sessionId); } - return $mailId; } @@ -328,19 +324,18 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface { if (isset($params['queue']['id'])) { $where = array( - 'id' => $params['queue']['id'], + 'id = ?' => $params['queue']['id'], ); - } elseif(isset($params['user']['id']) && isset($params['session']['id'])) { + } elseif(isset($params['u']) && isset($params['s'])) { $where = array( - 'user_id' => $params['user']['id'], - 'session_id' => $params['session']['id'], + 'user_id = ? AND session_id = ?' => array($params['u'], $params['s']), ); } if (isset($where)) { $res = (bool) Database::update( Database::get_main_table(TABLE_ADV_SUB_QUEUE), array( - 'unsigned' => $newStatus, + 'status' => $newStatus, ), $where ); @@ -361,111 +356,127 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface { $tpl = new Template($this->get_lang('plugin_title')); $tpl->assign('data', $data); - $tplParams = array('user', 'student', 'students','superior', 'admins', 'session', 'signature', '_p', ); + $tplParams = array('user', 'student', 'students', 'superior', 'admins', 'session', 'signature', 'admin_view_url'); foreach ($tplParams as $tplParam) { if (isset($data['superior'])) { $tpl->assign($tplParam, $data[$tplParam]); } } + $mailIds = array(); switch ($actionType) { case ADV_SUB_ACTION_STUDENT_REQUEST: // 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['session_id'] + $data['s'] ); // Mail to superior $mailIds[] = $this->sendMailMessage( + $data['u'], $data['superior']['user_id'], $this->get_lang('MailStudentRequest'), $tpl->fetch('/advancedsubscription/views/advsub_request_superior.tpl'), - $data['session_id'], + $data['s'], true ); break; case ADV_SUB_ACTION_SUPERIOR_APPROVE: // Mail to student $mailIds[] = $this->sendMailMessage( + $data['u'], $data['student']['user_id'], $this->get_lang('MailStudentRequest'), $tpl->fetch('/advancedsubscription/views/advsub_request_superior_approved.tpl'), - $data['session_id'] + $data['s'] ); // Mail to superior $mailIds[] = $this->sendMailMessage( + $data['u'], $data['superior']['user_id'], $this->get_lang('MailStudentRequest'), $tpl->fetch('/advancedsubscription/views/advsub_approve_confirmed.tpl'), - $data['session_id'] + $data['s'] ); // Mail to admin - $mailIds[] = $this->sendMailMessage( - $data['admin']['user_id'], - $this->get_lang('MailStudentRequest'), - $tpl->fetch('/advancedsubscription/views/advsub_request_approved_info_admin.tpl'), - $data['session_id'], - true - ); + 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; case ADV_SUB_ACTION_SUPERIOR_DISAPPROVE: // Mail to student $mailIds[] = $this->sendMailMessage( + $data['u'], $data['student']['user_id'], $this->get_lang('MailStudentRequest'), $tpl->fetch('/advancedsubscription/views/advsub_request_superior_disapproved.tpl'), - $data['session_id'], + $data['s'], true ); // Mail to superior $mailIds[] = $this->sendMailMessage( + $data['u'], $data['superior']['user_id'], $this->get_lang('MailStudentRequest'), $tpl->fetch('/advancedsubscription/views/advsub_disapprove_confirmed.tpl'), - $data['session_id'] + $data['s'] ); break; case ADV_SUB_ACTION_SUPERIOR_SELECT: // 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['session_id'] + $data['s'] ); // Mail to superior $mailIds[] = $this->sendMailMessage( + $data['u'], $data['superior']['user_id'], $this->get_lang('MailStudentRequest'), $tpl->fetch('/advancedsubscription/views/advsub_request_superior.tpl'), - $data['session_id'], + $data['s'], true ); break; case ADV_SUB_ACTION_ADMIN_APPROVE: // Mail to student $mailIds[] = $this->sendMailMessage( + $data['u'], $data['student']['user_id'], $this->get_lang('MailStudentRequest'), $tpl->fetch('/advancedsubscription/views/advsub_approval_admin_accepted_notice_student.tpl'), - $data['session_id'] + $data['s'] ); // Mail to superior $mailIds[] = $this->sendMailMessage( + $data['u'], $data['superior']['user_id'], $this->get_lang('MailStudentRequest'), $tpl->fetch('/advancedsubscription/views/advsub_approval_admin_accepted_notice_superior.tpl'), - $data['session_id'] + $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_approval_admin_accepted_notice_admin.tpl'), - $data['session_id'], + $data['s'], true ); } @@ -473,27 +484,30 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface case ADV_SUB_ACTION_ADMIN_DISAPPROVE: // Mail to student $mailIds[] = $this->sendMailMessage( + $data['u'], $data['student']['user_id'], $this->get_lang('MailStudentRequest'), $tpl->fetch('/advancedsubscription/views/advsub_approval_admin_rejected_notice_student.tpl'), - $data['session_id'], + $data['s'], true ); // Mail to superior $mailIds[] = $this->sendMailMessage( + $data['u'], $data['superior']['user_id'], $this->get_lang('MailStudentRequest'), $tpl->fetch('/advancedsubscription/views/advsub_approval_admin_rejected_notice_superior.tpl'), - $data['session_id'] + $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_approval_admin_rejected_notice_admin.tpl'), - $data['session_id'] + $data['s'] ); } break; @@ -780,7 +794,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface $userTable = Database::get_main_table(TABLE_MAIN_USER); $userJoinTable = $queueTable . ' q INNER JOIN ' . $userTable . ' u ON q.user_id = u.user_id'; $where = array('where' => array('session_id = ?' => $sessionId)); - $select = 'u.user_id, u.firstname, u.lastname, q.created_at, q.updated_at, q.status'; + $select = 'u.user_id, u.firstname, u.lastname, q.created_at, q.updated_at, q.status, q.id as queue_id'; $students = Database::select($select, $userJoinTable, $where); foreach ($students as &$student) { $status = intval($student['status']); diff --git a/plugin/advancedsubscription/src/admin_view.php b/plugin/advancedsubscription/src/admin_view.php index c339fc2702..5bd71a86d9 100644 --- a/plugin/advancedsubscription/src/admin_view.php +++ b/plugin/advancedsubscription/src/admin_view.php @@ -45,21 +45,54 @@ if (isset($data) && is_array($data)) { // Init template $tpl = new Template('TESTING'); +// Get all sessions +$sessionList = $plugin->listAllSessions(); if (!empty($s)) { // Get student list in queue $studentList = $plugin->listAllStudentsInQueueBySession($s); // Set selected to current session $sessionList[$s]['selected'] = 'selected="selected"'; + $studentList['session']['id'] = $s; // Assign variables + + // 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']; + $adminsArray = UserManager::get_all_administrators(); + + $data = array( + 'a' => 'confirm', + 's' => $s, + ); + + foreach ($studentList['students'] as &$student) { + $data['u'] = $student['user_id']; + $data['queue'] = array('id' => $student['queue_id']); + $data['e'] = ADV_SUB_QUEUE_STATUS_ADMIN_APPROVED; + $student['dataApprove'] = $plugin->encrypt($data); + $data['e'] = ADV_SUB_QUEUE_STATUS_ADMIN_DISAPPROVED; + $student['dataDisapprove'] = $plugin->encrypt($data); + } $tpl->assign('session', $studentList['session']); $tpl->assign('students', $studentList['students']); } -// Get all sessions -$sessionList = $plugin->listAllSessions(); // Assign variables $tpl->assign('sessionItems', $sessionList); +$tpl->assign('data', $data); +$tpl->assign('approveAdmin', ADV_SUB_QUEUE_STATUS_ADMIN_APPROVED); +$tpl->assign('disapproveAdmin', ADV_SUB_QUEUE_STATUS_ADMIN_DISAPPROVED); // Get rendered template $content = $tpl->fetch('/advancedsubscription/views/admin_view.tpl'); // Assign into content diff --git a/plugin/advancedsubscription/views/admin_view.tpl b/plugin/advancedsubscription/views/admin_view.tpl index ac145c1422..7e192a9788 100644 --- a/plugin/advancedsubscription/views/admin_view.tpl +++ b/plugin/advancedsubscription/views/admin_view.tpl @@ -43,10 +43,10 @@ {{ student.lastname }} {{ student.firstname }} {{ student.created_at }} {{ student.validation }} - Aceptar + Aceptar - Rechazar + Rechazar