}
}
# Checks whether the User is logged in and prevents further operations if he/she is not
include "function/modules/mod.login.php";
# Otherwise user-specific settings are loaded
include userdir . "/" . $_SESSION["user"] . "/settings.php";
# If User already has downloaded his/her PIM-Resources, they are stored in a file
# in the User-Dir referenced by the constant "restree"
if (file_exists(restree)) {
    include restree;
}
# This code-snippet offers the possibility to view the full tree of resources
# for development purposes
if ($_GET["print_restree"]) {
    die(str_replace("\n", "<br />", str_replace(" ", "&nbsp;", print_r($GLOBALS["restree"], true))));
}
# The called module should be given by POST or GET
# If no module is given, the standard module is taken (see config.php)
define("inc_main", RetrieveVar("module", "0110") != "" ? RetrieveVar("module", "0110") : defaultmodule);
# If this is an ajax-call just start the mainpage without embracing index.html
if (ajax) {
    $GLOBALS["stdOUT"] = "~mainpage~" . inc_main . "~/mainpage~";
} else {
    $GLOBALS["stdOUT"] = file_get_contents(designroot . "/display/index.html");
}
# Analyse Output for template-Commands
$GLOBALS["stdOUT"] = sourceAnalyze($GLOBALS["stdOUT"], true);
# Validate output (at least better than nothing)
$GLOBALS["stdOUT"] = validateText($GLOBALS["stdOUT"]);
# Flush the results
echo $GLOBALS["stdOUT"];
<?php

################################################
## Robert Schrenk, 2007, phPIMap              ##
## This code is distributed under the GNU/GPL ##
################################################
if (phPIMap != "ok") {
    die("Direct access to this location is not allowed");
}
if (RetrieveVar("calorientation", "0111")) {
    $_SESSION["calorientation"] = RetrieveVar("calorientation", "0111");
} elseif ($_SESSION["calorientation"] == "") {
    $_SESSION["calorientation"] = TimeStamp(0);
}
$time = TimeStamp2Time($_SESSION["calorientation"]);
$prevyear = date("YmdHis", mktime(0, 0, 0, date("m", $time), date("d", $time), date("Y", $time) - 1));
$prevmonth = date("YmdHis", mktime(0, 0, 0, date("m", $time) - 1, date("d", $time), date("Y", $time)));
$nextyear = date("YmdHis", mktime(0, 0, 0, date("m", $time), date("d", $time), date("Y", $time) + 1));
$nextmonth = date("YmdHis", mktime(0, 0, 0, date("m", $time) + 1, date("d", $time), date("Y", $time)));
$GLOBALS["calendar"]["month"] = date("m", $time);
$GLOBALS["calendar"]["start"] = date("YmdHis", mktime(0, 0, 0, date("m", $time), 1, date("Y", $time)));
$GLOBALS["calendar"]["end"] = date("YmdHis", mktime(23, 59, 59, date("m", $time), date("t", $time), date("Y", $time)));
verbose("Orientiert an Timestamp: " . $time . ", Monat ist " . $GLOBALS["calendar"]["month"]);
verbose("Monat geht von " . $GLOBALS["calendar"]["start"] . " bis " . $GLOBALS["calendar"]["end"]);
$selection = $GLOBALS["restree"]["calendar"];
$selection1 = filterResources($selection, "to", $GLOBALS["calendar"]["start"], ">=", null);
$selection1x = filterResources($selection1, "to", $GLOBALS["calendar"]["end"], "<=", null);
$selection2 = filterResources($selection, "from", $GLOBALS["calendar"]["end"], "<=", null);
$selection2x = filterResources($selection2, "from", $GLOBALS["calendar"]["start"], ">=", null);
$selection = mergeSelections($selection1x, $selection2x);
for ($i = 0; $i < count($selection); $i++) {
<?php

################################################
## Robert Schrenk, 2007, phPIMap              ##
## This code is distributed under the GNU/GPL ##
################################################
if (phPIMap != "ok") {
    die("Direct access to this location is not allowed");
}
if (RetrieveVar("calorientation", "0111")) {
    $_SESSION["calorientation"] = RetrieveVar("calorientation", "0111");
} elseif ($_SESSION["calorientation"] == "") {
    $_SESSION["calorientation"] = TimeStamp(0);
}
if (RetrieveVar("calrange", "0111")) {
    $_SESSION["calrange"] = RetrieveVar("calrange", "0111");
} elseif ($_SESSION["calrange"] == "") {
    $_SESSION["calrange"] = "week";
}
$time = TimeStamp2Time($_SESSION["calorientation"]);
switch ($_SESSION["calrange"]) {
    case "month":
        $GLOBALS["calendar"]["month"] = date("m", $time);
        $GLOBALS["calendar"]["start"] = date("YmdHis", mktime(0, 0, 0, date("m", $time), 1, date("Y", $time)));
        $GLOBALS["calendar"]["end"] = date("YmdHis", mktime(23, 59, 59, date("m", $time), date("t", $time), date("Y", $time)));
        verbose("Orientiert an Timestamp: " . $time . ", Monat ist " . $GLOBALS["calendar"]["month"]);
        verbose("Monat geht von " . $GLOBALS["calendar"]["start"] . " bis " . $GLOBALS["calendar"]["end"]);
        break;
    case "week":
        $GLOBALS["calendar"]["week"] = date("W", $time);
        $dayofweek = date("w", $time) - ($_SESSION["week_start_on_sunday"] ? 0 : 1);
<?php

################################################
## Robert Schrenk, 2007, phPIMap              ##
## This code is distributed under the GNU/GPL ##
################################################
if (phPIMap != "ok") {
    die("Direct access to this location is not allowed");
}
$id = RetrieveVar("id", "0111");
$item = $GLOBALS["restree"]["contact"][$id];
if ($id == "" or $item == "") {
    append("Sorry, a Contact with this ID does not exist!");
} else {
    $fields = $GLOBALS["fields"];
    $tpl = file_get_contents(designroot . "/display/item.contact.html");
    $tpl = replaceFields($tpl, "contact", $item);
    append($tpl);
}
unset($GLOBALS["restree"]);
$pimbox = "{" . imap_host . ":" . imap_port . "/imap}";
append("Opening PIMBox on " . $pimbox . "<br />");
$resources = $GLOBALS["resources"];
$types = $GLOBALS["types"];
for ($i = 0; $i < count($types); $i++) {
    for ($z = 0; $z < count($resources[$types[$i]]); $z++) {
        append("Opening SubBox '" . $pimbox . $resources[$types[$i]][$z] . "'");
        $box[$types[$i]][$z] = imap_open($pimbox . $resources[$types[$i]][$z], imap_user, imap_pw) or die("Could not open: " . $pimbox . $resources[$types[$i]][$z]);
        append("Opened PIMBox for '" . $types[$i] . "/#" . $z . " as '" . $pimbox . $resources[$types[$i]][$z] . "'<br />");
    }
}
for ($i = 0; $i < count($types); $i++) {
    $res = $types[$i];
    for ($z = 0; $z < count($resources[$res]); $z++) {
        $norefresh = RetrieveVar("norefresh", "1111");
        if (!$norefresh) {
            $pbox =& $box[$res][$z];
            $info = imap_check($pbox);
            $mailamount = $info->Nmsgs;
            $list = imap_fetch_overview($pbox, "1:" . $mailamount, 0);
            emptyMirrorDir(mirror . "/" . $resources[$res][$z]);
            createMirrorDir(mirror . "/" . $resources[$res][$z]);
            append("Preparing to read " . $mailamount . " Mails from PIMBox '" . $types[$i] . "/#" . $z . "'<br />");
            for ($y = 0; $y < $mailamount; $y++) {
                $subject = $list[$y]->subject;
                $mail = imap_body($pbox, $list[$y]->uid, FT_UID);
                $f = @fopen(mirror . "/" . $resources[$res][$z] . "/" . $subject, "w");
                @fputs($f, $mail);
                @fclose($f);
            }
function sourceAnalyze($SOLVED_TEXT, $globals)
{
    $State = "app";
    $i = 0;
    $SearchStrings[$i++] = "~designroot~";
    // 0
    $SearchStrings[$i++] = "~sessionid~";
    // 1
    $SearchStrings[$i++] = "~main~";
    // 2
    $SearchStrings[$i++] = "~application~";
    // 3
    $SearchStrings[$i++] = "~/application~";
    // 4
    $SearchStrings[$i++] = "~ignore~";
    // 5
    $SearchStrings[$i++] = "~/ignore~";
    // 6
    $SearchStrings[$i++] = "~mainpage~";
    // 7
    $SearchStrings[$i++] = "~/mainpage~";
    // 8
    $SearchStrings[$i++] = "~domain~";
    // 9
    $SearchStrings[$i++] = "~function~";
    // 10
    $SearchStrings[$i++] = "~/function~";
    // 11
    $itemamount = 1;
    while ($itemamount > 0) {
        $IndexPage = $SOLVED_TEXT;
        unset($AllPositions);
        $AllPositions[0] = 0;
        $i = 1;
        for ($z = 0; $z < count($SearchStrings); $z++) {
            $LastPos = 0;
            while (strpos($IndexPage, $SearchStrings[$z], $LastPos) != "") {
                $AllPositions[$i] = strpos($IndexPage, $SearchStrings[$z], $LastPos);
                $LastPos = $AllPositions[$i] + 1;
                $i++;
            }
        }
        $AllPositions[count($AllPositions)] = strlen($IndexPage);
        // Sortieralgorithmus der gespeicherten Positionen
        sort($AllPositions);
        unset($Log);
        $zPos = 0;
        $z = 0;
        $Weiter = true;
        while ($Weiter) {
            $Item = substr($IndexPage, $AllPositions[$zPos], $AllPositions[$zPos + 1] - $AllPositions[$zPos]);
            for ($x = 0; $x < count($SearchStrings); $x++) {
                $XFnd = false;
                if (strpos(" " . $Item, $SearchStrings[$x]) > 0) {
                    $Log[$z++] = $SearchStrings[$x];
                    $Log[$z++] = str_replace($SearchStrings[$x], "", $Item);
                    $XFnd = true;
                    break;
                }
            }
            if (!$XFnd) {
                $Log[$z++] = $Item;
            }
            $zPos++;
            if ($zPos > count($AllPositions)) {
                $Weiter = false;
            }
        }
        // Sichere derzeitige GLOBAL
        if (!$globals) {
            $SECURE_stdOUT = $GLOBALS["stdOUT"];
        }
        // Wenn keine Keywords mehr vorhanden Schleife abbrechen
        // Wenn Wert auf false BLEIBT wird die Schleife abgebrochen
        // Wird er auf TRUE gesetzt, geht die Schleife weiter.
        // Wegen den Keywords IGNORE wird die Variable SOURCE_ROUND direkt
        // in der Schleife auf TRUE gesetzt.
        $SOLVED_TEXT = "";
        $LogAnz = 0;
        $itemamount = 0;
        while ($LogAnz < count($Log)) {
            $GLOBALS["stdOUT"] = "";
            if (!in_array($Log[$LogAnz], $SearchStrings) or $Log[$LogAnz] == $SearchStrings[15]) {
                if ($Log[$LogAnz] != $SearchStrings[15]) {
                    $GLOBALS["stdOUT"] .= $Log[$LogAnz];
                    $GLOBALS["stdOUT"] = translateText($GLOBALS["stdOUT"]);
                    $GLOBALS["stdOUT"] = cloakURL($GLOBALS["stdOUT"]);
                    // Mailadressen nur deformieren, wenn stdOUT gewandelt wird. (In Mails ist die JavaScript-Funktion nicht vorhanden)
                    if ($globals) {
                        $GLOBALS["stdOUT"] = deformateMail($GLOBALS["stdOUT"]);
                    }
                } else {
                    while ($Log[$LogAnz] != $SearchStrings[16]) {
                        $GLOBALS["stdOUT"] .= $Log[$LogAnz];
                        $LogAnz++;
                    }
                    $GLOBALS["stdOUT"] .= $Log[$LogAnz];
                }
            } else {
                $itemamount++;
                switch ($Log[$LogAnz]) {
                    case $SearchStrings[0]:
                        // designroot
                        $GLOBALS["stdOUT"] .= designroot;
                        break;
                    case $SearchStrings[1]:
                        // sessionid
                        $GLOBALS["stdOUT"] .= session_id();
                        break;
                    case $SearchStrings[2]:
                        // mainmodule
                        $GLOBALS["stdOUT"] .= "~mainpage~" . inc_main . "~/mainpage~";
                        break;
                    case $SearchStrings[3]:
                        // application
                        $orig = $State;
                        $State = "app";
                        if (strpos($Log[$LogAnz + 1], "=") > 0) {
                            $url = explode("&", $Log[$LogAnz + 1]);
                            for ($i = 0; $i < count($url); $i++) {
                                $va = explode("=", $url[$i]);
                                $_ORIGS[$va[0]] = $_POST[$va[0]];
                                $_POST[$va[0]] = $va[1];
                                if ($va[0] == "State") {
                                    $State = $va[1];
                                }
                            }
                            $app = $_POST["module"];
                        } else {
                            $app = $Log[$LogAnz + 1];
                        }
                        if (!(include $GLOBALS["_MODULES"][$app][1])) {
                            $GLOBALS["stdOUT"] .= "Fehler bei Aufruf der Seite '" . $GLOBALS["_MODULES"][$app][0] . "'<br>";
                        }
                        $State = $orig;
                        if (strpos($Log[$LogAnz + 1], "=") > 0) {
                            for ($i = 0; $i < count($url); $i++) {
                                $va = explode("=", $url[$i]);
                                $_POST[$va[0]] = $_ORIGS[$va[0]];
                            }
                            unset($_ORIGS);
                        }
                        $LogAnz = $LogAnz + 2;
                        break;
                    case $SearchStrings[7]:
                        // mainpage
                        $orig = $GLOBALS["State"];
                        $State = "main";
                        if (strpos($Log[$LogAnz + 1], "=") > 0) {
                            $url = explode("&", $Log[$LogAnz + 1]);
                            for ($i = 0; $i < count($url); $i++) {
                                $va = explode("=", $url[$i]);
                                $_ORIGS[$va[0]] = $_POST[$va[0]];
                                $_POST[$va[0]] = $va[1];
                                if ($va[0] == "State") {
                                    $State = $va[1];
                                }
                                if ($va[0] == "module") {
                                    $app = $va[1];
                                }
                            }
                        } else {
                            $app = $Log[$LogAnz + 1];
                        }
                        if (!(include $GLOBALS["_MODULES"][$app][1])) {
                            $GLOBALS["stdOUT"] .= "Fehler bei Aufruf der Seite '" . $GLOBALS["_MODULES"][$app][0] . "'<br>";
                        }
                        $GLOBALS["_PAGEAPP"] = $app != "" ? $app : "Default Module";
                        $GLOBALS["State"] = $orig;
                        if (count($_ORIGS) > 0) {
                            for ($i = 0; $i < count($url); $i++) {
                                $va = explode("=", $url[$i]);
                                $_POST[$va[0]] = $_ORIGS[$va[0]];
                            }
                            unset($_ORIGS);
                        }
                        $LogAnz = $LogAnz + 1;
                        break;
                    case $SearchStrings[9]:
                        // domain
                        $GLOBALS["stdOUT"] .= domain;
                        break;
                    case $SearchStrings[10]:
                        // function
                        $command = $Log[$LogAnz + 1];
                        $command = explode("|", $command);
                        eval("\$sol = " . $command[0] . "(" . $command[1] . ");");
                        append($sol);
                        $LogAnz = $LogAnz + 1;
                        break;
                }
                // Hier können Operationen an stdOUT erfolgen. (ist in diesem Fall nur zustzliches Item)
                // Hier ist ignoring false
                $GLOBALS["stdOUT"] = translateText($GLOBALS["stdOUT"]);
                $GLOBALS["stdOUT"] = cloakURL($GLOBALS["stdOUT"]);
                // Mailadressen nur deformieren, wenn stdOUT gewandelt wird. (In Mails ist die JavaScript-Funktion nicht vorhanden)
                if ($globals) {
                    $GLOBALS["stdOUT"] = deformateMail($GLOBALS["stdOUT"]);
                }
            }
            $SOLVED_TEXT .= $GLOBALS["stdOUT"];
            $LogAnz++;
        }
        if (RetrieveVar("CASCADE", "0111")) {
            echo "#" . $GLOBALS["CASC_AMNT"]++ . ":<hr>\n\n" . $SOLVED_TEXT . "<br>Itemcount: " . $itemamount . "<br>\n\n<hr>\n\n";
        }
    }
    // Backsave GLOBAL
    if (!$globals) {
        $GLOBALS["stdOUT"] = $SECURE_stdOUT;
    }
    return $SOLVED_TEXT;
}