コード例 #1
0
function instImportPages(&$session, $import_file, $import_replace)
{
    $message = null;
    if (!file_exists($import_file)) {
        $message = "Datei nicht gefunden: " . $import_file;
    } elseif (checkDB($session, $message) == DB_EXISTS) {
        $file = fopen($import_file, "r");
        $count_inserts = 0;
        $count_updates = 0;
        $count_lines = 0;
        while ($line = fgets($file)) {
            if (preg_match('/^#name=(\\S+)\\tlines=(\\d+)\\ttype=(\\w+)\\t/', $line, $param)) {
                $name = $param[1];
                $lines = $param[2];
                $type = $param[3];
                $session->trace(TC_Gui1, 'instImportPagesAnswer-2: ' . $line);
                if (($page = dbPageId($session, $name)) > 0) {
                    $count_updates++;
                    if ($import_replace) {
                        dbDeleteByClause($session, T_Text, 'page=' . $page);
                    }
                } else {
                    $page = dbInsert($session, T_Page, 'name,type', dbSqlString($session, $name) . ',' . dbSqlString($session, $type));
                    $count_inserts++;
                }
                $text = "";
                $session->trace(TC_Gui1, 'instImportPagesAnswer-3: ' . $lines);
                $count_lines += $lines;
                for ($ii = 0; $ii < $lines; $ii++) {
                    $text .= fgets($file);
                }
                if ($import_replace) {
                    $old_id = dbSingleValue($session, 'select max(id) from ' . dbTable($session, T_Text) . ' where page=' . (0 + $page));
                }
                $text_id = dbInsert($session, T_Text, 'page,type,text', $page . ',' . dbSqlString($session, $type) . ',' . dbSqlString($session, $text));
                if ($import_replace && $old_id > 0) {
                    dbUpdate($session, T_Text, $old_id, 'replacedby=' . $text_id);
                }
            }
        }
        fclose($file);
        $message = 'Datei ' . $import_file . ' wurde eingelesen. Neu: ' . (0 + $count_inserts) . ' Geändert: ' . (0 + $count_updates) . ' Zeilen: ' . (0 + $count_lines);
    }
    return $message;
}
コード例 #2
0
ファイル: admin.php プロジェクト: BackupTheBerlios/infobasar
function admImportPagesAnswer(&$session)
{
    admStandardHeader($session, 'SeitenimportAntwort');
    $session->trace(TC_Gui1, 'admImportPagesAnswer');
    $message = null;
    if (isset($_POST['import_upload'])) {
        $message = guiUploadFileAnswer($session, 'import_upload', '/import/');
    } elseif (($no = admPostContainsNumberedVar($session, 'import_import')) >= 0) {
        $file_name = $_POST['import_file' . (0 + $no)];
        if (!file_exists($file_name)) {
            $message = 'Datei nicht gefunden: ' . $file_name;
        } else {
            $file = fopen($file_name, "r");
            $count_inserts = 0;
            $count_updates = 0;
            $count_lines = 0;
            while ($line = fgets($file)) {
                if (preg_match('/^#name=(\\S+)\\tlines=(\\d+)\\ttype=(\\w+)\\t/', $line, $param)) {
                    $name = $param[1];
                    $lines = $param[2];
                    $type = $param[3];
                    $session->trace(TC_Gui1, 'admImportPagesAnswer-2: ' . $line);
                    if (($page = dbPageId($session, $name)) > 0) {
                        $count_updates++;
                        if (guiChecked($session, 'import_replace')) {
                            dbDeleteByClause($session, T_Text, 'page=' . $page);
                        }
                    } else {
                        $page = dbInsert($session, T_Page, 'name,type', dbSqlString($session, $name) . ',' . dbSqlString($session, $type));
                        $count_inserts++;
                    }
                    $text = "";
                    $session->trace(TC_Gui1, 'admImportPagesAnswer-3: ' . $lines);
                    $count_lines += $lines;
                    for ($ii = 0; $ii < $lines; $ii++) {
                        $text .= fgets($file);
                    }
                    if (guiChecked($session, 'import_replace')) {
                        $old_id = dbSingleValue($session, 'select max(id) from ' . dbTable($session, T_Text) . ' where page=' . (0 + $page));
                    }
                    $text_id = dbInsert($session, T_Text, 'page,type,text', $page . ',' . dbSqlString($session, $type) . ',' . dbSqlString($session, $text));
                    if (guiChecked($session, 'import_replace') && $old_id > 0) {
                        dbUpdate($session, T_Text, $old_id, 'replacedby=' . $text_id);
                    }
                }
            }
            fclose($file);
            $message = 'Datei ' . $file_name . ' wurde eingelesen. Neu: ' . (0 + $count_inserts) . ' Geändert: ' . (0 + $count_updates) . ' Zeilen: ' . (0 + $count_lines);
        }
    } else {
        $message = "unbekannte Antwort.";
    }
    admImportPages($session, $message);
}