lp_ajax_log.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script contains the server part of the xajax interaction process. The client part is located
  5. * in lp_api.php or other api's.
  6. * This script, in particular, enables the process of SCORM messages logging.
  7. * It stores the SCORM interaction logs right into a temporary file on disk.
  8. * @package chamilo.learnpath
  9. * @author Yannick Warnier <ywarnier@beeznest.org>
  10. */
  11. /**
  12. * Code
  13. */
  14. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  15. $use_anonymous = true;
  16. // Name of the language file that needs to be included.
  17. $language_file[] = 'learnpath';
  18. //require_once '../inc/global.inc.php';
  19. $app['template.show_footer'] = false;
  20. $app['template.show_header'] = false;
  21. $app['default_layout'] = 'default/layout/blank.tpl';
  22. /**
  23. * Write a log with the current message
  24. * @param string Message
  25. * @param int Debug level (if 0, do not log)
  26. */
  27. function lp_ajax_log($msg, $level) {
  28. $debug = 0;
  29. $return = '';
  30. if ($debug > 0) {error_log('In log('.$msg.')', 0); }
  31. if ($level == 0) {
  32. //error_log('Logging level too low, not writing files in '.__FILE__);
  33. return $return;
  34. }
  35. $msg = str_replace('<br />', "\r\n", $msg);
  36. $file = sys_get_temp_dir().DIRECTORY_SEPARATOR.session_id().'.'.date('Ymd').'-'.api_get_user_id().'.scorm.log';
  37. $fh = @fopen($file, 'a');
  38. @fwrite($fh,'['.date('Y-m-d H:m:s').'] '.$msg."\r\n");
  39. @fclose($fh);
  40. return $return;
  41. }
  42. echo lp_ajax_log($_POST['msg'], $_POST['debug']);