terms_to_pdf.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. $data['action'] = 'confirm';
  12. $data['currentUserId'] = 1;
  13. $data['queueId'] = 0;
  14. $data['is_connected'] = true;
  15. $data['profile_completed'] = 90.0;
  16. $data['sessionId'] = intval($_REQUEST['s']);
  17. $data['studentUserId'] = intval($_REQUEST['u']);
  18. $data['student'] = api_get_user_info($data['studentUserId']);
  19. $data['session'] = api_get_session_info($data['sessionId']);
  20. if (!empty($data['sessionId']) && !empty($data['studentUserId'])) {
  21. $plugin = AdvancedSubscriptionPlugin::create();
  22. if (api_get_plugin_setting('courselegal', 'tool_enable')) {
  23. $courseLegal = CourseLegalPlugin::create();
  24. $courses = SessionManager::get_course_list_by_session_id($data['sessionId']);
  25. $course = current($courses);
  26. $data['courseId'] = $course['id'];
  27. $data['course'] = api_get_course_info_by_id($data['courseId']);
  28. $termsAndConditions = $courseLegal->getData($data['courseId'], $data['sessionId']);
  29. $termsAndConditions = $termsAndConditions['content'];
  30. $termsAndConditions = $plugin->renderTemplateString($termsAndConditions, $data);
  31. $tpl = new Template($plugin->get_lang('Terms'));
  32. $tpl->assign('session', $data['session']);
  33. $tpl->assign('student', $data['student']);
  34. $tpl->assign('sessionId', $data['sessionId']);
  35. $tpl->assign('termsContent', $termsAndConditions);
  36. $termsAndConditions = $tpl->fetch('/advanced_subscription/views/terms_and_conditions_to_pdf.tpl');
  37. $pdf = new PDF();
  38. $filename = 'terms'.sha1(rand(0, 99999));
  39. $pdf->content_to_pdf($termsAndConditions, null, $filename, null, 'F');
  40. $fileDir = api_get_path(WEB_ARCHIVE_PATH).$filename.'.pdf';
  41. echo '<pre>', print_r($fileDir, 1), '</pre>';
  42. }
  43. }