lp_ajax_log.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. /**
  20. * Write a log with the current message
  21. * @param string Message
  22. * @param int Debug level (if 0, do not log)
  23. */
  24. function lp_ajax_log($msg, $level) {
  25. $debug = 0;
  26. $return = '';
  27. if ($debug > 0) {error_log('In log('.$msg.')', 0); }
  28. if ($level == 0) {
  29. //error_log('Logging level too low, not writing files in '.__FILE__);
  30. return $return;
  31. }
  32. $msg = str_replace('<br />', "\r\n", $msg);
  33. $file = sys_get_temp_dir().DIRECTORY_SEPARATOR.session_id().'.'.date('Ymd').'-'.api_get_user_id().'.scorm.log';
  34. $fh = @fopen($file, 'a');
  35. @fwrite($fh,'['.date('Y-m-d H:m:s').'] '.$msg."\r\n");
  36. @fclose($fh);
  37. return $return;
  38. }
  39. echo lp_ajax_log($_POST['msg'], $_POST['debug']);