Subversion Repositories oidplus

Rev

Rev 755 | Rev 757 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
754 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
20
header('Content-Type:text/html; charset=UTF-8');
21
 
22
require_once __DIR__ . '/../../../../includes/oidplus.inc.php';
23
 
24
set_exception_handler(array('OIDplusGui', 'html_exception_handler'));
25
 
26
OIDplus::init(true);
27
 
756 daniel-mar 28
if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPageAdminNostalgia', false)) {
754 daniel-mar 29
        throw new OIDplusException(_L('This plugin was disabled by the system administrator!'));
30
}
31
 
756 daniel-mar 32
if (!OIDplus::authUtils()->isAdminLoggedIn()) {
33
        throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
34
}
35
 
755 daniel-mar 36
if (!class_exists('ZipArchive')) {
37
        throw new OIDplusException(_L('The PHP extension "ZipArchive" needs to be installed to create a ZIP archive with an included database. Otherwise, you can just download the plain program without data.'));
38
}
39
 
754 daniel-mar 40
$dos_ids = array();
41
$parent_oids = array();
42
$i = 0;
43
$dos_ids[''] = '00000000';
44
$parent_oids[''] = '';
45
 
46
$dos_ids[''] = str_pad($i++, 8, '0', STR_PAD_LEFT);
47
$res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id'));
48
while ($row = $res->fetch_object()) {
49
        $oid = substr($row->id, strlen('oid:'));
50
        $parent_oid = substr($row->parent, strlen('oid:'));
51
        $dos_ids[$oid] = str_pad($i++, 8, '0', STR_PAD_LEFT);
52
        if ($parent_oid == '') {
53
                $parent_oids[$oid] = '';
54
        } else {
55
                $parent_oids[$oid] = $parent_oid;
56
        }
57
}
58
 
59
$tmp_file = OIDplus::localpath().'userdata/dos_export.zip';
60
 
61
$zip = new ZipArchive();
62
if ($zip->open($tmp_file, ZipArchive::CREATE)!== true) {
63
        throw new OIDplusException("cannot open <$tmp_file>");
64
}
65
 
66
foreach ($dos_ids as $oid => $dos_id) {
67
        $cont = '';
68
 
69
        $cont .= "VERS2022\r\n";
70
 
71
        $cont .= "SELF$dos_id$oid\r\n";
72
 
73
        $parent_oid = $parent_oids[$oid];
74
        $parent_id = $dos_ids[$parent_oid];
75
        $cont .= "SUPR$parent_id$parent_oid\r\n";
76
 
77
        foreach ($parent_oids as $child_oid => $parent_oid) {
78
                if ($child_oid == '') continue;
79
                if ($parent_oid == $oid) {
80
                        $child_id = $dos_ids[$child_oid];
81
                        $cont .= "CHLD$child_id$child_oid\r\n";
82
                }
83
        }
84
 
85
        $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'");
86
        while ($row = $res->fetch_object()) {
87
                $asn1 = $row->name;
88
                $cont .= "ASN1$asn1\r\n";
89
        }
90
 
91
        $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'");
92
        while ($row = $res->fetch_object()) {
93
                $iri = $row->name;
94
                $cont .= "UNIL$iri\r\n";
95
        }
96
 
97
        if ($oid == '') {
98
                // TODO: Split in single parent OIDs
99
                $cont .= "DESCHere, you can find the root OIDs.\r\n";
100
        } else {
101
                $res = OIDplus::db()->query("select * from ###objects where id = 'oid:$oid';");
102
                $row = $res->fetch_object();
103
                $desc = trim(trim(strip_tags($row->description)));
104
                $desc = str_replace("\r", "", $desc);
105
                $desc = str_replace("\n", "  ", $desc);
106
                $desc_ary1 = explode("\r\n", wordwrap($desc, 80/*TREEVIEW_WIDTH*/, "\r\n", true));
107
                $desc_ary2 = explode("\r\n", wordwrap($row->title, 80/*TREEVIEW_WIDTH*/, "\r\n", true));
108
                if (implode('',$desc_ary1) == '') $desc_ary1 = array();
109
                if (implode('',$desc_ary2) == '') $desc_ary2 = array();
110
                $desc_ary = array_merge($desc_ary1, $desc_ary2);
111
                foreach ($desc_ary as $line_idx => $line) {
112
                        if ($line_idx >= 10/*DESCEDIT_LINES*/) break;
113
                        $cont .= "DESC$line\r\n";
114
                }
115
        }
116
 
117
        //echo "****$dos_id.OID\r\n";
118
        //echo "$cont\r\n";
119
 
120
        $zip->addFromString("$dos_id.OID", $cont);
121
}
122
 
123
$exe_url = 'https://github.com/danielmarschall/oidplus_dos/raw/master/OIDPLUS.EXE';
124
$exe = @file_get_contents($exe_url);
125
if ($exe == '') {
126
        throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url));
127
}
128
$zip->addFromString('OIDPLUS.EXE', $exe);
129
 
130
$zip->close();
131
 
132
if (!headers_sent()) {
133
        header('Content-Type: application/zip');
134
        header('Content-Disposition: attachment; filename=oidplus_dos.zip');
135
        readfile($tmp_file);
136
}
137
 
138
unlink($tmp_file);
139
 
140
OIDplus::invoke_shutdown();