Exemple #1
0
function ProcessDtx($filename, $projectId)
{
    StartAccessToDB();
    $lines = file($filename);
    $msg = "processing " . $filename . "<br>";
    $unitname = basename($filename);
    // Delete the existing unit (if any)
    $msg .= "deleting previous values for {$unitname}, if any...<br>";
    $deleteResult = DeleteUnitAndItemsByUnitName($unitname);
    if ($deleteResult != "") {
        $msg .= "Error while removing previous values: " . $deleteResult;
    } else {
        $msg .= "Success<br>";
        $unitId = -1;
        $index = 0;
        while ($index < count($lines)) {
            $curline = rtrim($lines[$index]);
            if (HasPrefix($curline, '##Package:')) {
                $package = substr($curline, strpos($curline, ':') + 2);
                $msg .= "found package: {$package}<br>";
            }
            if (HasPrefix($curline, '##Status:')) {
                $status = substr($curline, strpos($curline, ':') + 2);
                $msg .= "found status: {$status}<br>";
            }
            if (HasPrefix($curline, '@@')) {
                $msg .= "found item: {$curline} - ";
                if ($unitId == -1) {
                    $msg .= "Adding unit <a href=\"unit.php?Name={$unitname}\">{$unitname}</a> - ";
                    $unitId = AddUnit($unitname, "", "", $package, $status, $projectId, GetLoggedUserId());
                    if (is_string($unitId)) {
                        $msg .= $unitId . "<br>";
                        $unitId = -1;
                    }
                }
                if ($unitId != -1) {
                    $msg .= ProcessItem($lines, $index, $unitId);
                }
            }
            $index++;
        }
    }
    // delete the file, we don't need it anymore
    unlink($filename);
    EndAccessToDB();
    return $msg;
}
Exemple #2
0
function GenerateTable($tableContent)
{
    // let's look for a line starting with at least 2 dashes, that will
    // be our "markup" line, indicating where are the columns
    $i = 0;
    while (!HasPrefix(ltrim($tableContent[$i]), "--") && $i < count($tableContent)) {
        $i++;
    }
    $indentLength = strlen($tableContent[$i]) - strlen(ltrim($tableContent[$i]));
    $markupLine = trim($tableContent[$i]);
    $tableContent[$i] = "";
    // so that it will not be displayed
    $pos = 0;
    $colValue = 0;
    while ($pos < strlen($markupLine) && !(($pos = strpos($markupLine, ' ', $pos + 1)) === false)) {
        // Add if the previous one is not a space already
        // Else, replace the existing value. We always add the indentation
        // length because the markup line has been trimmed
        $colValue = $pos + $indentLength + 1;
        if ($markupLine[$pos - 1] != ' ') {
            $columns[] = $colValue;
        } else {
            $columns[count($columns) - 1] = $colValue;
        }
    }
    $columns[] = -1;
    // $columns now contains as many colum indexes as there are columns to break
    // so we can now process the lines and create an in memory table, allowing
    // us to do unwraping inside cells
    $table = array();
    $rowIndex = 0;
    foreach ($tableContent as $row) {
        if (trim($row) != "") {
            $tableRow = array();
            $prevColumn = 0;
            $colIndex = 0;
            $tableColAdded = false;
            foreach ($columns as $column) {
                if ($column == -1) {
                    $cellContent = UnescapeHtmlMarkers(substr($row, $prevColumn));
                } else {
                    $cellContent = UnescapeHtmlMarkers(substr($row, $prevColumn, $column - $prevColumn));
                }
                if (trim($cellContent) != "") {
                    // if we have at least IndentationSpaces in front of the content, then
                    // we consider it is part of the cell just above and we add the content
                    // into that cell
                    if (HasPrefix($cellContent, str_repeat(" ", IndentationSpaces))) {
                        $table[$rowIndex - 1][$colIndex] .= $cellContent;
                    } else {
                        $tableRow[] = $cellContent;
                        $tableColAdded = true;
                    }
                }
                $prevColumn = $column;
                $colIndex++;
            }
            if ($tableColAdded) {
                $table[] = $tableRow;
                $rowIndex++;
            }
        }
    }
    // Now that the table is generated, we create a string representation for it
    $result = "<table>\n";
    $cellTag = "th";
    foreach ($table as $row) {
        $result .= "<tr>\n";
        foreach ($row as $cell) {
            if ($cell != "") {
                $result .= "<" . $cellTag . ">" . $cell . "</" . $cellTag . ">\n";
            } else {
                $result .= "<" . $cellTag . ">&nbsp;</" . $cellTag . ">\n";
            }
        }
        $result .= "</tr>\n";
        if ($cellTag == "th") {
            $cellTag = "td";
        }
    }
    $result .= "</table>\n";
    return $result;
}