<?php
// dsurvey library specifying names of directories and files
$svydir='';
$rootdir=$_SERVER['DOCUMENT_ROOT'];
$dsvydir=$rootdir.'dSurvey/';
$wwwdir=$dsvydir;
$instruments_dir=$dsvydir.'instruments/';
$sessions_dir=$dsvydir.'sessions/';
$data_dir=$dsvydir.'data/';
$lookup_dir=$dsvydir.'pinfo/';
$pinfo_dir=$lookup_dir;
$debug=0;

$mysqlHdr='dSurvey_';

$aa=0;
if (array_key_exists('showDirs',$_GET)) {
   $aa=$_GET['showDirs'];
}

if ($aa == 1 ) {
print '<h1>Directories </h1>';
print '<ul>';
print "<li>Rootdir= $rootdir   ";
print "<li>dsvyDir= $dsvydir ";
print "<li>wwwDir= $wwwdir ";
print "<li>instruments_dir= $instruments_dir ";
print "<li>sessions_dir= $sessions_dir     ";
print "<li>data_dir= $data_dir ";
print "<li>lookup_dir= $lookup_dir ";
print "<li>pinfo_dir= $pinfo_dir ";
print '</ul> ';
}


//=========================
// check xml syntax of a string. Return 0 if no errors
// otherwise, returns an HTML message pointing out the errors

function checkSyntaxXML($xmlstr,$dafile) {

libxml_use_internal_errors(true);

$doc = simplexml_load_string($xmlstr);
//header('Content-Type: text/plain; charset=iso-8859-1');

if (!$doc) {
   $xml = explode("\n", $xmlstr);
   $errors = libxml_get_errors();
   $stuff=" <h3>Errors in XML file  $dafile </h3>  <ul> ";
    foreach ($errors as $error) {
        $stuff=$stuff . ' <li> ' .  display_xml_error($error, $xml);
    }
    libxml_clear_errors();
    return $stuff .  ' </ul>' ;
}
return 0 ;
}

function display_xml_error($error, $xml) {
    $return  = '<div style="white-space:pre;font-family:monospace;stybackground-color:#ababab">' .htmlentities($xml[$error->line - 1]) . '<br>' ;
    $return .= str_repeat('-', $error->column)  ;
    $return .= '</div> ';

    switch ($error->level) {
        case LIBXML_ERR_WARNING:
            $return .= "Warning $error->code: ";
            break;
         case LIBXML_ERR_ERROR:
            $return .= "Error $error->code: ";
            break;
        case LIBXML_ERR_FATAL:
            $return .= "Fatal Error $error->code: ";
            break;
    }

    $return .= trim($error->message) .
               "<br/>  Line:  $error->line   , Column: $error->column";

    if ($error->file) {
        $return .= "<br/>  File: $error->file";
    }

    return $return;
}



?>