mails.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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::getFirstStudentBoss($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'] : $admin['lastname'].', '.$admin['firstname']
  74. ;
  75. }
  76. unset($admin);
  77. // Set data
  78. $data['action'] = 'confirm';
  79. $data['student'] = $studentArray;
  80. $data['superior'] = $superiorArray;
  81. $data['admins'] = $adminsArray;
  82. $data['admin'] = current($adminsArray);
  83. $data['session'] = $sessionArray;
  84. $data['signature'] = api_get_setting('Institution');
  85. $data['admin_view_url'] = api_get_path(WEB_PLUGIN_PATH).
  86. 'advanced_subscription/src/admin_view.php?s='.$data['sessionId'];
  87. $data['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_BOSS_APPROVED;
  88. $data['student']['acceptUrl'] = $plugin->getQueueUrl($data);
  89. $data['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_BOSS_DISAPPROVED;
  90. $data['student']['rejectUrl'] = $plugin->getQueueUrl($data);
  91. $tpl = new Template($plugin->get_lang('plugin_title'));
  92. $tpl->assign('data', $data);
  93. $tplParams = array(
  94. 'user',
  95. 'student',
  96. 'students',
  97. 'superior',
  98. 'admins',
  99. 'admin',
  100. 'session',
  101. 'signature',
  102. 'admin_view_url',
  103. 'acceptUrl',
  104. 'rejectUrl'
  105. );
  106. foreach ($tplParams as $tplParam) {
  107. $tpl->assign($tplParam, $data[$tplParam]);
  108. }
  109. $dir = __DIR__.'/../views/';
  110. $files = scandir($dir);
  111. echo '<br>', '<pre>', print_r($files, 1), '</pre>';
  112. foreach ($files as $k =>&$file) {
  113. if (
  114. is_file($dir.$file) &&
  115. strpos($file, '.tpl') &&
  116. $file != 'admin_view.tpl'
  117. ) {
  118. echo '<pre>', $file, '</pre>';
  119. echo $tpl->fetch('/advanced_subscription/views/'.$file);
  120. } else {
  121. unset($files[$k]);
  122. }
  123. }
  124. echo '<br>', '<pre>', print_r($files, 1), '</pre>';