mails.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * A script to render all mails templates
  5. * @package chamilo.plugin.advanced_subscription
  6. */
  7. require_once __DIR__ . '/../config.php';
  8. // Protect test
  9. api_protect_admin_script();
  10. // exit;
  11. $plugin = AdvancedSubscriptionPlugin::create();
  12. // Get validation hash
  13. $hash = Security::remove_XSS($_REQUEST['v']);
  14. // Get data from request (GET or POST)
  15. $data['action'] = 'confirm';
  16. $data['currentUserId'] = 1;
  17. $data['queueId'] = 0;
  18. $data['is_connected'] = true;
  19. $data['profile_completed'] = 90.0;
  20. // Init result array
  21. $data['sessionId'] = 1;
  22. $data['studentUserId'] = 4;
  23. // Prepare data
  24. // Get session data
  25. // Assign variables
  26. $fieldsArray = array(
  27. 'description',
  28. 'target',
  29. 'mode',
  30. 'publication_end_date',
  31. 'recommended_number_of_participants',
  32. );
  33. $sessionArray = api_get_session_info($data['sessionId']);
  34. $extraSession = new ExtraFieldValue('session');
  35. $extraField = new ExtraField('session');
  36. // Get session fields
  37. $fieldList = $extraField->get_all(array(
  38. 'variable IN ( ?, ?, ?, ?, ?)' => $fieldsArray
  39. ));
  40. $fields = array();
  41. // Index session fields
  42. foreach ($fieldList as $field) {
  43. $fields[$field['id']] = $field['variable'];
  44. }
  45. $mergedArray = array_merge(array($data['sessionId']), array_keys($fields));
  46. $sessionFieldValueList = $extraSession->get_all(
  47. array('item_id = ? field_id IN ( ?, ?, ?, ?, ?, ?, ? )' => $mergedArray)
  48. );
  49. foreach ($sessionFieldValueList as $sessionFieldValue) {
  50. // Check if session field value is set in session field list
  51. if (isset($fields[$sessionFieldValue['field_id']])) {
  52. $var = $fields[$sessionFieldValue['field_id']];
  53. $val = $sessionFieldValue['value'];
  54. // Assign session field value to session
  55. $sessionArray[$var] = $val;
  56. }
  57. }
  58. // Get student data
  59. $studentArray = api_get_user_info($data['studentUserId']);
  60. $studentArray['picture'] = $studentArray['avatar'];
  61. // Get superior data if exist
  62. $superiorId = UserManager::getStudentBoss($data['studentUserId']);
  63. if (!empty($superiorId)) {
  64. $superiorArray = api_get_user_info($superiorId);
  65. } else {
  66. $superiorArray = api_get_user_info(3);
  67. }
  68. // Get admin data
  69. $adminsArray = UserManager::get_all_administrators();
  70. $isWesternNameOrder = api_is_western_name_order();
  71. foreach ($adminsArray as &$admin) {
  72. $admin['complete_name'] = $isWesternNameOrder ?
  73. $admin['firstname'] . ', ' . $admin['lastname'] :
  74. $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 = array(
  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>';