<?php

function getPathback()
{
  if ( $_SERVER['HTTPS'] ) {
    $retval = "https://";
  } else {
    $retval = "http://";
  }
  $retval = $retval . $_SERVER['SERVER_ADDR'];
  if ( $_SERVER['SERVER_PORT'] ) {
    $retval = $retval . ':' . $_SERVER['SERVER_PORT'];
  }
  $retval = $retval . $_SERVER['PHP_SELF'];
  return $retval;
}

$global_session = false;

function getSession( ) {
  global $global_session;
  $session = false;
  if ( $fp = fopen("session/last.session","r") ) {
    fscanf($fp,"%d", &$session);
    fclose($fp);
  }
  if ( ! $session || $session < 0 || $session > 9 ) {
    $session = 1;
  } else {
    $session = $session + 1;
  }
  if ( $fp = fopen("session/last.session", "w") ) {
    fwrite($fp,sprintf("%d\r\n", $session));
    fclose($fp);
  }
  $global_session = $session;
  return $session;
}

// Log to the Sakai log
function LG($stuff) {
  if ($fp = fopen("log.txt", 'a+')) {
    fwrite($fp, $stuff."\r\n");
    fflush($fp);
    fclose($fp);
  }
}

?>
