Beispiel #1
0
* @package     Heurist academic knowledge management system
* @subpackage  !!!subpackagename for file such as Administration, Search, Edit, Application, Library
*/
require_once dirname(__FILE__) . '/../../common/config/initialise.php';
require_once dirname(__FILE__) . '/../../common/connect/applyCredentials.php';
require_once dirname(__FILE__) . '/../../common/php/dbMySqlWrappers.php';
// Deals with all the database connections stuff
mysql_connection_overwrite(DATABASE);
if (!is_logged_in()) {
    header("Location: " . HEURIST_BASE_URL . "common/connect/login.php?db=" . HEURIST_DBNAME);
    return;
}
if (!is_admin()) {
    print "<html><head><link rel=stylesheet href='../../common/css/global.css'></head><body><div class=wrap>" . "<div id=errorMsg><span>You must be an adminstrator of the owner's group to unlock the database '" . HEURIST_DBNAME . "'</span>" . "<p><a href=" . HEURIST_BASE_URL . "common/connect/login.php?logout=1&amp;db=" . HEURIST_DBNAME . " target='_top'>Log out</a></p></div></div></body></html>";
    return;
}
mysql_query("delete from sysLocks where 1");
/*****DEBUG****/
//error_log("in unlock ".print_r(HEURIST_DBNAME,true));
if (!mysql_error()) {
    returnXMLSuccessMsgPage(" Successfully unlocked '" . HEURIST_DBNAME . "'");
}
returnXMLErrorMsgPage("The was a problem unlocking '" . HEURIST_DBNAME . "' error - " . mysql_error());
function returnXMLSuccessMsgPage($msg)
{
    die("<html><body><success>{$msg}</success></body></html>");
}
function returnXMLErrorMsgPage($msg)
{
    die("<?xml version='1.0' encoding='UTF-8'?>\n<error>{$msg}</error>");
}
// outName returns the hml direct.
//if no style given then try default, if default doesn't exist we our put raw xml
$style = @$_REQUEST['style'] ? $_REQUEST['style'] : 'default';
$outputFilename = @$_REQUEST['outputFilename'] ? "" . HEURIST_HTML_PUBPATH . $_REQUEST['outputFilename'] : (@$_REQUEST['recID'] ? "" . HEURIST_HTML_PUBPATH . $style . "-" . HEURIST_DBID . "-" . $recID . ".html" : null);
// outName returns the hml direct.
$pos = strpos(HEURIST_HTML_PUBPATH, HEURIST_DOCUMENT_ROOT);
if ($pos !== false || file_exists(HEURIST_DOCUMENT_ROOT . HEURIST_HTML_PUBPATH)) {
    $outputURI = 'http://' . HEURIST_SERVER_NAME . ($pos !== false ? substr(HEURIST_HTML_PUBPATH, $pos + strlen(HEURIST_DOCUMENT_ROOT)) : HEURIST_HTML_PUBPATH) . (@$_REQUEST['outputFilename'] ? $_REQUEST['outputFilename'] : (@$_REQUEST['recID'] ? $style . "-" . HEURIST_DBID . "-" . $_REQUEST['recID'] . ".html" : "unknown.html"));
}
if (!$inputFilename || !file_exists($inputFilename)) {
    returnXMLErrorMsgPage("unable to find input file '{$inputFilename}'");
}
//set the style filename and check that it exist
$styleFilename = $style ? "" . HEURIST_XSL_TEMPLATES_DIR . $style . ".xsl" : null;
if (!$styleFilename || !file_exists($styleFilename)) {
    returnXMLErrorMsgPage("unable to find style file '{$styleFilename}'");
}
loadRecordHTML($inputFilename, $styleFilename);
returnXMLSuccessMsgPage("Successfully wrote output file" . ($outputURI ? " <a href=\"{$outputURI}\" target=\"_blank\">{$outputURI}</a>" : "Unable to determine URI. Not in website path! {$outputFilename}"));
function loadRecordHTML($recHMLFilename, $styleFilename)
{
    global $recID, $outputFilename;
    $recHmlDoc = new DOMDocument();
    $recHmlDoc->load($recHMLFilename);
    $recHmlDoc->xinclude();
    if (!$styleFilename) {
        return $recHmlDoc->saveHTMLFile($outputFilename);
    }
    $xslDoc = DOMDocument::load($styleFilename);
    $xslProc = new XSLTProcessor();
    $xslProc->importStylesheet($xslDoc);
function saveTransformOutput($recHMLFilename, $styleFilename, $outputFilename = null)
{
    global $outputURI;
    $recHmlDoc = new DOMDocument();
    if (preg_match("/http/", $recHMLFilename)) {
        $suc = $recHmlDoc->loadXML(loadRemoteFile($recHMLFilename));
    } else {
        $suc = $recHmlDoc->load($recHMLFilename);
    }
    if (!$suc) {
        returnXMLErrorMsgPage("Unable to load file {$recHMLFilename}");
    }
    $recHmlDoc->xinclude();
    //todo write code here to squash xincludes down to some limit.
    if (!$styleFilename) {
        if (!$outputFilename) {
            returnXMLErrorMsgPage("No transform filename or outputFilename provided for {$recHMLFilename}");
        }
        if (is_logged_in()) {
            $cntByte = $recHmlDoc->saveHTMLFile($outputFilename);
        }
        if ($cntByte > 0) {
            returnXMLSuccessMsgPage("Successfully wrote {$cntByte} bytes of untransformed file {$recHMLFilename} to {$outputFilename}");
        } else {
            returnXMLErrorMsgPage("Unable to output untransformed file {$recHMLFilename} to {$outputFilename}");
        }
    } else {
        $xslDoc = new DOMDocument();
        if (preg_match("/http/", $styleFilename)) {
            $suc = $xslDoc->loadXML(loadRemoteFile($styleFilename));
        } else {
            $suc = $xslDoc->load($styleFilename);
        }
        if (!$suc) {
            returnXMLErrorMsgPage("Unable to load XSLT transform file {$styleFilename}");
        }
    }
    $xslProc = new XSLTProcessor();
    $xslProc->importStylesheet($xslDoc);
    // set up common parameters for stylesheets.
    $xslProc->setParameter('', 'hbaseURL', HEURIST_BASE_URL);
    $xslProc->setParameter('', 'dbName', HEURIST_DBNAME);
    $xslProc->setParameter('', 'dbID', HEURIST_DBID);
    $xslProc->setParameter('', 'transform', $styleFilename);
    $xslProc->setParameter('', 'standalone', '1');
    if ($outputFilename && is_logged_in()) {
        $cntByte = $xslProc->transformToURI($recHmlDoc, $outputFilename);
        if ($cntByte > 0) {
            returnXMLSuccessMsgPage("Successfully wrote {$cntByte} bytes of {$recHMLFilename} transformed by  {$styleFilename} to {$outputFilename}" . ($outputURI ? " <a href=\"{$outputURI}\" target=\"_blank\">{$outputURI}</a>" : "Unable to determine URI for {$outputFilename} because is does not match website path!"));
        } else {
            returnXMLErrorMsgPage("Unable to  transform and/or output file {$recHMLFilename} transformed by  {$styleFilename} to {$outputFilename}");
        }
    } else {
        $doc = $xslProc->transformToDoc($recHmlDoc);
        //		echo $xslProc->transformToXML($recHmlDoc);
        echo $doc->saveHTML();
    }
}
function saveRecordHML($filename)
{
    global $recID, $outFullName;
    $hml = loadRemoteURLContent($filename);
    if ($hml) {
        $xml = new DOMDocument();
        $xml->loadXML($hml);
        // convert to xml
        if (!$xml) {
            returnXMLErrorMsgPage("unable to generate valid hml for {$filename}");
        } else {
            if ($outFullName) {
                $text = $xml->saveXML();
                $ret = file_put_contents($outFullName, $text);
                if (!$ret) {
                    returnXMLErrorMsgPage("output of {$outFullName} failed to write");
                } else {
                    if ($ret < strlen($text)) {
                        returnXMLErrorMsgPage("output of {$outFullName} wrote {$ret} bytes of " . strlen($text));
                    } else {
                        // success output the contents of the saved file file
                        $text = file_get_contents($outFullName);
                    }
                }
                echo $text;
            } else {
                echo $xml->saveXML();
                //should never get here.
            }
        }
    }
}
}
mysql_connection_select(DATABASE);
// set parameter defaults
$recID = @$_REQUEST['recID'] ? $_REQUEST['recID'] : null;
$res = mysql_query("select * from Records where rec_ID = {$recID}");
if (!$recID || !mysql_num_rows($res)) {
    returnXMLErrorMsgPage(" Non-existent record ID ({$recID})");
}
$row = mysql_fetch_assoc($res);
$ACCESSABLE_OWNER_IDS = mysql__select_array('sysUsrGrpLinks left join sysUGrps grp on grp.ugr_ID=ugl_GroupID', 'ugl_GroupID', 'ugl_UserID=' . get_user_id() . ' and grp.ugr_Type != "user" order by ugl_GroupID');
array_push($ACCESSABLE_OWNER_IDS, get_user_id());
array_push($ACCESSABLE_OWNER_IDS, 0);
// 0 = belong to everyone
$rec_owner_id = mysql__select_array("Records", "rec_OwnerUGrpID", "rec_ID={$recID}");
if ($row['rec_NonOwnerVisibility'] == 'hidden' && (count($rec_owner_id) < 1 || !in_array($rec_owner_id[0], $ACCESSABLE_OWNER_IDS))) {
    returnXMLErrorMsgPage(" no access to record id {$recID} ");
}
$inputFilename = "" . HEURIST_HML_DIR . HEURIST_DBID . "-" . $recID . ".hml";
echo loadRecordHML($inputFilename);
function loadRecordHML($filename)
{
    global $recID;
    $dom = new DOMDocument();
    $dom->load($filename);
    $dom->xinclude();
    return $dom->saveXML();
}
function returnXMLErrorMsgPage($msg)
{
    die("<?xml version='1.0' encoding='UTF-8'?>\n<error>{$msg}</error>");
}