lp_ajax_log.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  12. $use_anonymous = true;
  13. // Name of the language file that needs to be included.
  14. $language_file[] = 'learnpath';
  15. require_once 'back_compat.inc.php';
  16. /**
  17. * Write a log with the current message
  18. * @param string Message
  19. * @param int Debug level (if 0, do not log)
  20. */
  21. function lp_ajax_log($msg, $level) {
  22. $debug = 0;
  23. $return = '';
  24. if ($debug > 0) {error_log('In log('.$msg.')', 0); }
  25. if ($level == 0) {
  26. //error_log('Logging level too low, not writing files in '.__FILE__);
  27. return $return;
  28. }
  29. $msg = str_replace('<br />', "\r\n", $msg);
  30. $file = sys_get_temp_dir().DIRECTORY_SEPARATOR.session_id().'.'.date('Ymd').'-'.api_get_user_id().'.scorm.log';
  31. $fh = @fopen($file, 'a');
  32. @fwrite($fh,'['.date('Y-m-d H:m:s').'] '.$msg."\r\n");
  33. @fclose($fh);
  34. return $return;
  35. }
  36. echo lp_ajax_log($_POST['msg'], $_POST['debug']);