function SetPeriod($relation, $DateConcept, $srcAtom, $Period)
{
    emitLog("SetPeriod({$relation},{$DateConcept},{$srcAtom},{$Period})");
    // Insert the pair ($srcAtom,$srcAtom + $period) into $relation
    if (($dt1 = strtotime($srcAtom)) === false) {
        ExecEngineSHOUTS("SetPeriod: Illegal date {$dt1} specified in srcAtom (3rd arg): {$srcAtom}");
    }
    if (($dt3 = strtotime($srcAtom . $Period)) === false) {
        ExecEngineSHOUTS("SetPeriod: Illegal period {$dt3} specified as period (4th arg): {$Period}");
    }
    $tgtAtom = date('d-m-Y', $dt3);
    global $execEngineWhispers;
    // Defined in 'pluginsettings.php'
    $execEngineWhispers = false;
    // ExecEngineWhispers("SetPeriod: InsPair($relation,$DateConcept,$srcAtom,$DateConcept,$tgtAtom)");
    // Als '$tgtAtom' nog niet in de database bestaat als een instantie van $DateConcept, dan moet die nog wel worden toegevoegd:
    if (!isAtomInConcept($tgtAtom, $DateConcept)) {
        addAtomToConcept($tgtAtom, $DateConcept);
    }
    InsPair($relation, $DateConcept, $srcAtom, $DateConcept, $tgtAtom);
    return;
}
function initSession()
{
    // when using $_SESSION, we get a nonsense warning if not declared global, however here
    // we only do isset, so no need for global
    global $conceptTableInfo;
    session_start();
    // Start a new, or resume the existing, PHP session
    // only execute session code when concept SESSION is used by adl script
    if (isset($conceptTableInfo['SESSION'])) {
        // TODO: until error handling is improved, this hack tries a dummy query and returns silently if it fails.
        //       This way, errors during initSession do not prevent the reset-database link from being visible.
        DB_doquerErr("SELECT * FROM `__SessionTimeout__` WHERE false", $error);
        if ($error) {
            return;
        }
        // Remove expired Ampersand-sessions from __SessionTimeout__ and all concept tables and relations where it appears.
        $expirationLimit = time() - EXPIRATION_TIME;
        $expiredSessions = firstCol(DB_doquer("SELECT SESSION FROM `__SessionTimeout__` WHERE lastAccess < {$expirationLimit};"));
        foreach ($expiredSessions as $expiredSessionAtom) {
            deleteSession($expiredSessionAtom);
        }
        // If the PHP session has the Ampersand sessionAtom, retrieve it.
        // Note that it may still refer to an Ampersand session that has expired and therefore no longer exists in the Ampersand administration
        $sessionAtom = $_SESSION['sessionAtom'];
        // create a new session if $sessionAtom is not set (browser started a new session)
        // or $sessionAtom is not in SESSIONS (previous session expired)
        if (!isset($sessionAtom) || !isAtomInConcept($sessionAtom, 'SESSION')) {
            $sessionAtom = mkUniqueAtomByTime('SESSION');
            $_SESSION['sessionAtom'] = $sessionAtom;
            addAtomToConcept($sessionAtom, 'SESSION');
        }
        // echo "sessionAtom = [$sessionAtom]<br>";
        $timeInSeconds = time();
        DB_doquer("INSERT INTO `__SessionTimeout__` (`SESSION`,`lastAccess`) VALUES ('{$_SESSION['sessionAtom']}','{$timeInSeconds}')" . "ON DUPLICATE KEY UPDATE `lastAccess` = '{$timeInSeconds}'");
        //echo "SessionAtom is $sessionAtom access is $timeInSeconds";
    }
}
Exemplo n.º 3
0
     // This will be obsolete once these and other properties are in a separate div.
     echo "<div id=AmpersandRoot refresh={$autoRefreshInterval} timestamp=\"" . $timeStamp . "\">";
     echo "</div>";
     echo '<div id=SignalAndPhpLogs>';
     genSignalLogWindow($selectedRoleNr);
     echo '</div>';
     echo '<ul id="Maintenance">';
     echo '<li id="Reset"><a href="javascript:resetDatabase()"><span class=TextContent>Reset database</span></a></li>';
     echo '</ul>';
     echo '<h3 id="CreateHeader"><span class=TextContent>Create</span></h3>';
     genNewAtomLinks();
 } else {
     $interface = $_REQUEST['interface'];
     $atom = $_REQUEST['atom'];
     $concept = $allInterfaceObjects[$interface]['srcConcept'];
     $isNew = $concept != 'ONE' && !isAtomInConcept($atom, $concept);
     echo '<div id=AmpersandRoot interface=' . showHtmlAttrStr($interface) . ' atom=' . showHtmlAttrStr($atom) . ' concept=' . showHtmlAttrStr($allInterfaceObjects[$interface]['srcConcept']) . ' editing=' . ($isNew ? 'true' : 'false') . ' isNew=' . ($isNew ? 'true' : 'false') . " refresh={$autoRefreshInterval} dev=" . ($isDev ? 'true' : 'false') . ' role=' . showHtmlAttrStr(getRoleName($selectedRoleNr)) . ' timestamp="' . $timeStamp . '">';
     echo '<div class=LogWindow id=EditLog minimized=false><div class=MinMaxButton></div><div class=Title>Edit commands</div></div>';
     echo '<div class=LogWindow id=ErrorLog minimized=false><div class=MinMaxButton></div><div class=Title>Errors</div></div>';
     echo '<div id=SignalAndPhpLogs>';
     echo '<div class=LogWindow id=PhpLog minimized=false><div class=MinMaxButton></div><div class=Title>Php log </div></div>';
     genSignalLogWindow($selectedRoleNr);
     echo '</div>';
     if (!empty($allInterfaceObjects[$interface]['editableConcepts'])) {
         echo '<button class="Button EditButton" onclick="startEditing()">Edit</button>';
         echo '<button class="Button SaveButton" onclick="commitEditing()">Save</button>';
         echo '<button class="Button CancelButton" onclick="cancelEditing()">Cancel</button>';
     }
     // If the atom is not in the concept, this means that a new atom was be created (and $atom is a time-based unique name).
     // We cannot use a url-encoded command for Create new, since such a url causes problems in the browser history. (pressing back
     // could cause the creation of another atom) With the current method, going back or refreshing the url simply shows the new atom.
function NewStruct()
{
    // We start with parsing the first one or two arguments
    $ConceptC = func_get_arg(0);
    // Name of concept for which atom is to be created
    $AtomC = mkUniqueAtomByTime($ConceptC);
    // Default marker for atom-to-be-created.
    if (func_num_args() % 5 == 2) {
        $AtomC = func_get_arg(1);
        // If so, we'll be using this to create the new atom
    } elseif (func_num_args() % 5 != 1) {
        ExecEngineSHOUTS("NewStruct: Illegal number of arguments: " . func_num_args());
        die;
    }
    // Then, we create a new atom of type $ConceptC
    ExecEngineWhispers("Creating a structure based on an atom '{$AtomC}' for concept '{$ConceptC}'");
    addAtomToConcept($AtomC, $ConceptC);
    // insert new atom in database
    // Next, for every relation that follows in the argument list, we create a link
    for ($i = func_num_args() % 5; $i < func_num_args(); $i = $i + 5) {
        emitLog("i = {$i}");
        $relation = func_get_arg($i);
        $srcConcept = func_get_arg($i + 1);
        $srcAtom = func_get_arg($i + 2);
        $tgtConcept = func_get_arg($i + 3);
        $tgtAtom = func_get_arg($i + 4);
        // populate relation r1, first checking for allowed syntax:
        if (!($srcAtom === 'NULL' or $tgtAtom === 'NULL')) {
            ExecEngineSHOUTS("NewStruct: relation {$relation} requires that atom {$srcAtom} or {$tgtAtom} must be NULL");
            throw new Exception("Failure 1 in NewStruct in InsDelPairAtom.php");
        }
        if (!($srcConcept == $ConceptC or $tgtConcept == $ConceptC)) {
            ExecEngineSHOUTS("NewStruct: relation {$relation} requires that concept {$srcConcept} or {$tgtConcept} must be {$ConceptC}");
            throw new Exception("Failure 2 in NewStruct in InsDelPairAtom.php");
        }
        if ($srcConcept == $ConceptC) {
            if ($srcAtom === 'NULL') {
                $srcAtom = $AtomC;
            }
        }
        if ($tgtConcept == $ConceptC) {
            if ($tgtAtom === 'NULL') {
                $tgtAtom = $AtomC;
            }
        }
        /* Als '$tgtAtom' nog niet in de database bestaat als een instantie van $tgtConcept, dan moet die nog wel worden toegevoegd; dat gebeurt bijvoorbeeld als '$tgtAtom' ontstaat uit de volgende ADL tekst: 
        VIOLATION (TXT "{EX} NewStruct;Beslissing"
                       ,TXT ";op;Beslissing;NULL;Verzoek;", SRC I 
                   ...
                       ,TXT ";reden;Beslissing;NULL;Reden;'Voldoen aan artikel 2 lid 10 Wet aanpassing arbeidsduur'"
                   ...                                  -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deze tekst moet als een instantie van het concept 'Reden' worden toegevoegd (als-ie nog niet als een Reden bestaat).
                       )
        */
        if (!isAtomInConcept($tgtAtom, $tgtConcept)) {
            addAtomToConcept($tgtAtom, $tgtConcept);
        }
        // Any logging is done by InsPair:
        InsPair($relation, $srcConcept, $srcAtom, $tgtConcept, $tgtAtom);
    }
    ExecEngineWhispers("Completed structure creation.");
}