Location: PHPKode > projects > GUP: GTP Usability Prototype > default.php
<?
/** 
 * Open Universiteit Nederland
 * File containing configuration parameters to be included
 * in all pages.
 * Last modified 17 January 2006
 */ 

////// ENV: //////////////////////////
// Turn debugging on or off. Set debugging to off(0) in a production system
define ("_DEBUGGING_",1); // debugging on(1)/off(0)

// server parameters
// The directory of the webserver in which you installed the GUP code
define ("_FILE_ROOT_",''); // include trailing slash
// The webroot of your webserver
define ("_WEB_ROOT_",''); // include trailing slash
// The path to the PHP binary
define ("_PHP_PROCESS_LOCATION_","");
// The hostname of your server, check your webserver settings
define ("_HOST_NAME_",'localhost'); // use localhost only for a testserver
// The path to the folder where people upload there files to be included in 
// a document set. This folder can be located on another server. Please make 
// sure that the webserver running GUP has read access to this folder.
define ("_UPLOAD_SOURCE_FOLDER_",'');

// version of GUP application
define ("_VERSION_",'June-29-2005');

////// LAYOUT: //////////////////////////
define ("_WINDOW_NEW_",0);
define ("_WINDOW_INHERIT_",1);
define ("_WINDOW_TOP_",2);

define ("_WINDOW_TYPE_NORMAL_",0);
define ("_WINDOW_TYPE_IFRAME_",1);

////// LOGGING: //////////////////////////
function log_action($message){
  
  $log_time = date("d-n-Y/H:i:s");
  $log_string = $log_time." - ".$_SERVER["REMOTE_ADDR"]." - ".$_SERVER["REQUEST_URI"]." - ".$message."\n";
 
  $log_file = fopen(_FILE_ROOT_."logs/action_log.txt","a");
  fwrite($log_file,$log_string);
  fclose($log_file);
}


// -1 notification (don't spam in error_log)
// 0 recoverable error write into errorlog and continue
// 1 fatal error write into errorlog and stop execution
function raise_error($message,$error_level){

  $err_time = date("d-n-Y/H:i:s");

  if (_DEBUGGING_ == 1){
    switch($error_level){
    case -1: 
    break;

    case 0:
    echo "<DIV style=\"z-order:100\"><P><B><FONT COLOR=\"#FFaaaa\">$err_time - Error (execution continues) : $message</FONT></B><P>";
    break;
    
    default:
    echo "<DIV style=\"z-order:100\"><P><B><FONT COLOR=\"#FF6666\">$err_time - Fatal error (execution stopped) : $message</FONT></B><P>";
    break;
    }
  }

  switch($error_level){
    case -1:
      echo "<P><B>Notice (Logged): ".$_SERVER["REMOTE_ADDR"]." ,$err_time: $message</B></P>";
      log_action("Errorhandler notice: $message");
    break;

    case 0:
    case 1:
    default:
      $err_fatal = ($error_level == 0)?"Proceeded":"---FATAL---";
      $error_file = fopen( _FILE_ROOT_ ."logs/error_log.txt","a");
      $error_string = $err_fatal."  ".$err_time."   ".$_SERVER["REQUEST_URI"]." ".$message."\n";
      fwrite($error_file,$error_string);
      fclose($error_file);
  }

  if ($error_level > 0){
    echo "<P><B> Unrecoverable error, cannot continue operations on this page. The error has been reported.";
  exit;
  }
}

////// FUNCTIONS: //////////////////////////
function getVar($name,$default,$maxlength=-1){
    if (isset($_GET[$name])){
        $value = htmlspecialchars($_GET[$name]);
    } elseif (isset($_POST[$name])){
        $value = htmlspecialchars($_POST[$name]);
    } else {
        return $default;
    }

    if ($maxlength!=-1){
        if (strlen($value) > $maxlength){
            return(substr($value,0,$maxlength));
        }
    }
    return $value;
}

function getIntVar($name,$default,$rangeStart=-1,$rangeStop=-1){
    if (isset($_GET[$name])){
        $value = intval($_GET[$name]);
    } elseif (isset($_POST[$name])){
        $value = intval($_POST[$name]);
    } else {
        return $default;
    }

    if (!(($rangeStart==-1)&&($rangeStop==-1))){
        if ($value < $rangeStart){
            return $rangeStart;
        }
        if ($value > $rangeStop){
            return $rangeStop;
        }
    }
    return $value;
}

function getReqVar($name,&$error,&$errors,$errormessage,$minlength=-1,$maxlength=-1){
    if (isset($_GET[$name])){
        $value = htmlspecialchars($_GET[$name]);
    } elseif (isset($_POST[$name])){
        $value = htmlspecialchars($_POST[$name]);
    } else {
        $error = true;
        $errors .= $errormessage;
        return false;
    }

    if (!(($minlength==-1)&&($maxlength==-1))){
        if ((strlen($value) < $minlength)||(strlen($value) > $maxlength)){
            $error = true;
            $errors .= $errormessage;
            return false;
        }
    }
    return $value;
}

// Warning, This functions name is not correct. it also allows floating point numerics. (old name because of legacy reasons)
// checks if value is set, is numeric and in range, and returns that value, or false.
function getReqIntVar($name,&$error,&$errors,$errormessage,$rangeStart="no",$rangeStop="no"){
    if (isset($_GET[$name])){
        $value = htmlspecialchars($_GET[$name]);
    } elseif (isset($_POST[$name])){
        $value = htmlspecialchars($_POST[$name]);
    } else {
        $error = true;
        $errors .= $errormessage;
        return false;
    }

    if (!is_numeric($value)){
            $error = true;
            $errors .= $errormessage;
            return false;
    }

    if ($rangeStart !== "no"){
        if($value < $rangeStart){
            $error = true;
            $errors .= $errormessage."\n";
        }
    }

    if ($rangeStop !== "no"){
        if($value > $rangeStop){
            $error = true;
            $errors .= $errormessage."\n";
        }
    }
    if (!$error){
        return $value;
    } else {
        return false;
    }
}

function getCheckboxValue($name){
    $name = str_replace(" ","_",$name); // strange, but spaces within key names in html get converted to underscores.
    $name = str_replace(".","_",$name); // as well as points

    if(isset($_POST[$name]) && ($_POST[$name] == "on")){
        return true;
    }
    if(isset($_GET[$name]) && ($_GET[$name] == "on")){
        return true;
    }
    return false;

}

function formatError($errors){
    $errors = str_replace("\n","<BR>\n",$errors);
    return "<FONT class=\"code\" color=\"red\">$errors</FONT>\n";
        
}

// Function from php.net usercomments: (little adapted, (don't like to die)
function delDir($dirName) {
   if(empty($dirName)) {
       return true;
   }
   if(file_exists($dirName)) {
       $dir = dir($dirName);
       while($file = $dir->read()) {
           if($file != '.' && $file != '..') {
               if(is_dir($dirName.'/'.$file)) {
                   delDir($dirName.'/'.$file);
               } else {
                   if(!@unlink($dirName.'/'.$file)){
                     return false;   
                   }
               }
           }
       }
       $dir->close();
       if(!@rmdir($dirName)){
         return false;   
       }
   } else {
       return false;
   }
   return true;
} 

////// INCLUDES: //////////////////////////
include_once _FILE_ROOT_."tools/template_parser.php";
include_once _FILE_ROOT_."tools/database.php";
include_once _FILE_ROOT_."tools/layout_handler.php";
include_once _FILE_ROOT_."classes/TestSet.php";
include_once _FILE_ROOT_."classes/DocumentSpace.php";
include_once _FILE_ROOT_."classes/LSI.php";
include_once _FILE_ROOT_."classes/DocSet.php";
include_once _FILE_ROOT_."classes/DocCollection.php";
include_once _FILE_ROOT_."classes/Splitter.php";
include_once _FILE_ROOT_."classes/StopStem.php";
include_once _FILE_ROOT_."classes/GTP.php";
include_once _FILE_ROOT_."classes/Query.php";
include_once _FILE_ROOT_."classes/Input.php";
?>
Return current item: GUP: GTP Usability Prototype