mails.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * A script to render all mails templates.
  5. *
  6. * @package chamilo.plugin.advanced_subscription
  7. */
  8. require_once __DIR__.'/../config.php';
  9. // Protect test
  10. api_protect_admin_script();
  11. // exit;
  12. $plugin = AdvancedSubscriptionPlugin::create();
  13. // Get validation hash
  14. $hash = Security::remove_XSS($_REQUEST['v']);
  15. // Get data from request (GET or POST)
  16. $data['action'] = 'confirm';
  17. $data['currentUserId'] = 1;
  18. $data['queueId'] = 0;
  19. $data['is_connected'] = true;
  20. $data['profile_completed'] = 90.0;
  21. // Init result array
  22. $data['sessionId'] = 1;
  23. $data['studentUserId'] = 4;
  24. // Prepare data
  25. // Get session data
  26. // Assign variables
  27. $fieldsArray = [
  28. 'description',
  29. 'target',
  30. 'mode',
  31. 'publication_end_date',
  32. 'recommended_number_of_participants',
  33. ];
  34. $sessionArray = api_get_session_info($data['sessionId']);
  35. $extraSession = new ExtraFieldValue('session');
  36. $extraField = new ExtraField('session');
  37. // Get session fields
  38. $fieldList = $extraField->get_all([
  39. 'variable IN ( ?, ?, ?, ?, ?)' => $fieldsArray,
  40. ]);
  41. $fields = [];
  42. // Index session fields
  43. foreach ($fieldList as $field) {
  44. $fields[$field['id']] = $field['variable'];
  45. }
  46. $mergedArray = array_merge([$data['sessionId']], array_keys($fields));
  47. $sessionFieldValueList = $extraSession->get_all(
  48. ['item_id = ? field_id IN ( ?, ?, ?, ?, ?, ?, ? )' => $mergedArray]
  49. );
  50. foreach ($sessionFieldValueList as $sessionFieldValue) {
  51. // Check if session field value is set in session field list
  52. if (isset($fields[$sessionFieldValue['field_id']])) {
  53. $var = $fields[$sessionFieldValue['field_id']];
  54. $val = $sessionFieldValue['value'];
  55. // Assign session field value to session
  56. $sessionArray[$var] = $val;
  57. }
  58. }
  59. // Get student data
  60. $studentArray = api_get_user_info($data['studentUserId']);
  61. $studentArray['picture'] = $studentArray['avatar'];
  62. // Get superior data if exist
  63. $superiorId = UserManager::getFirstStudentBoss($data['studentUserId']);
  64. if (!empty($superiorId)) {
  65. $superiorArray = api_get_user_info($superiorId);
  66. } else {
  67. $superiorArray = api_get_user_info(3);
  68. }
  69. // Get admin data
  70. $adminsArray = UserManager::get_all_administrators();
  71. $isWesternNameOrder = api_is_western_name_order();
  72. foreach ($adminsArray as &$admin) {
  73. $admin['complete_name'] = $isWesternNameOrder ?
  74. $admin['firstname'].', '.$admin['lastname'] : $admin['lastname'].', '.$admin['firstname']
  75. ;
  76. }
  77. unset($admin);
  78. // Set data
  79. $data['action'] = 'confirm';
  80. $data['student'] = $studentArray;
  81. $data['superior'] = $superiorArray;
  82. $data['admins'] = $adminsArray;
  83. $data['admin'] = current($adminsArray);
  84. $data['session'] = $sessionArray;
  85. $data['signature'] = api_get_setting('Institution');
  86. $data['admin_view_url'] = api_get_path(WEB_PLUGIN_PATH).
  87. 'advanced_subscription/src/admin_view.php?s='.$data['sessionId'];
  88. $data['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_BOSS_APPROVED;
  89. $data['student']['acceptUrl'] = $plugin->getQueueUrl($data);
  90. $data['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_BOSS_DISAPPROVED;
  91. $data['student']['rejectUrl'] = $plugin->getQueueUrl($data);
  92. $tpl = new Template($plugin->get_lang('plugin_title'));
  93. $tpl->assign('data', $data);
  94. $tplParams = [
  95. 'user',
  96. 'student',
  97. 'students',
  98. 'superior',
  99. 'admins',
  100. 'admin',
  101. 'session',
  102. 'signature',
  103. 'admin_view_url',
  104. 'acceptUrl',
  105. 'rejectUrl',
  106. ];
  107. foreach ($tplParams as $tplParam) {
  108. $tpl->assign($tplParam, $data[$tplParam]);
  109. }
  110. $dir = __DIR__.'/../views/';
  111. $files = scandir($dir);
  112. echo '<br>', '<pre>', print_r($files, 1), '</pre>';
  113. foreach ($files as $k => &$file) {
  114. if (
  115. is_file($dir.$file) &&
  116. strpos($file, '.tpl') &&
  117. $file != 'admin_view.tpl'
  118. ) {
  119. echo '<pre>', $file, '</pre>';
  120. echo $tpl->fetch('/advanced_subscription/views/'.$file);
  121. } else {
  122. unset($files[$k]);
  123. }
  124. }
  125. echo '<br>', '<pre>', print_r($files, 1), '</pre>';