Subversion Repositories oidplus

Rev

Rev 147 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 147 Rev 150
Line 100... Line 100...
100
                $icon = file_exists(__DIR__.'/icon_big.png') ? 'plugins/objectTypes/'.basename(__DIR__).'/icon_big.png' : '';
100
                $icon = file_exists(__DIR__.'/icon_big.png') ? 'plugins/objectTypes/'.basename(__DIR__).'/icon_big.png' : '';
101
 
101
 
102
                if ($this->isRoot()) {
102
                if ($this->isRoot()) {
103
                        $title = OIDplusOid::objectTypeTitle();
103
                        $title = OIDplusOid::objectTypeTitle();
104
 
104
 
105
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = '".OIDplus::db()->real_escape_string(self::root())."'");
105
                        $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = ?", array(self::root()));
106
                        if (OIDplus::db()->num_rows($res) > 0) {
106
                        if (OIDplus::db()->num_rows($res) > 0) {
107
                                $content = 'Please select an OID in the tree view at the left to show its contents.';
107
                                $content = 'Please select an OID in the tree view at the left to show its contents.';
108
                        } else {
108
                        } else {
109
                                $content = 'Currently, no OID is registered in the system.';
109
                                $content = 'Currently, no OID is registered in the system.';
110
                        }
110
                        }
Line 183... Line 183...
183
                if (is_null($parent)) $parent = OIDplusOid::parse('oid:');
183
                if (is_null($parent)) $parent = OIDplusOid::parse('oid:');
184
 
184
 
185
                $part = $this->deltaDotNotation($parent);
185
                $part = $this->deltaDotNotation($parent);
186
 
186
 
187
                if (strpos($part, '.') === false) {
187
                if (strpos($part, '.') === false) {
188
                        $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = '".OIDplus::db()->real_escape_string("oid:".$this->oid)."' order by lfd");
188
                        $res2 = OIDplus::db()->query("select name from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = ? order by lfd", array("oid:".$this->oid));
189
                        while ($row2 = OIDplus::db()->fetch_array($res2)) {
189
                        while ($row2 = OIDplus::db()->fetch_array($res2)) {
190
                                $asn_ids[] = $row2['name'].'('.$part.')';
190
                                $asn_ids[] = $row2['name'].'('.$part.')';
191
                        }
191
                        }
192
                }
192
                }
193
 
193
 
Line 198... Line 198...
198
        public function getAsn1Notation($withAbbr=true) {
198
        public function getAsn1Notation($withAbbr=true) {
199
                $asn1_notation = '';
199
                $asn1_notation = '';
200
                $arcs = explode('.', $this->oid);
200
                $arcs = explode('.', $this->oid);
201
 
201
 
202
                foreach ($arcs as $arc) {
202
                foreach ($arcs as $arc) {
203
                        $res = OIDplus::db()->query("select name, standardized from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = '".OIDplus::db()->real_escape_string('oid:'.implode('.',$arcs))."' order by lfd");
203
                        $res = OIDplus::db()->query("select name, standardized from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = ? order by lfd", array('oid:'.implode('.',$arcs)));
204
 
204
 
205
                        $names = array();
205
                        $names = array();
206
                        while ($row = OIDplus::db()->fetch_array($res)) {
206
                        while ($row = OIDplus::db()->fetch_array($res)) {
207
                                $names[] = $row['name']."(".end($arcs).")";
207
                                $names[] = $row['name']."(".end($arcs).")";
208
                                if ($row['standardized']) {
208
                                if ($row['standardized']) {
Line 232... Line 232...
232
        public function getIriNotation($withAbbr=true) {
232
        public function getIriNotation($withAbbr=true) {
233
                $iri_notation = '';
233
                $iri_notation = '';
234
                $arcs = explode('.', $this->oid);
234
                $arcs = explode('.', $this->oid);
235
 
235
 
236
                foreach ($arcs as $arc) {
236
                foreach ($arcs as $arc) {
237
                        $res = OIDplus::db()->query("select name, longarc from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = '".OIDplus::db()->real_escape_string('oid:'.implode('.',$arcs))."' order by lfd");
237
                        $res = OIDplus::db()->query("select name, longarc from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = ? order by lfd", array('oid:'.implode('.',$arcs)));
238
 
238
 
239
                        $is_longarc = false;
239
                        $is_longarc = false;
240
                        $names = array();
240
                        $names = array();
241
                        while ($row = OIDplus::db()->fetch_array($res)) {
241
                        while ($row = OIDplus::db()->fetch_array($res)) {
242
                                $is_longarc = $row['longarc'];
242
                                $is_longarc = $row['longarc'];
Line 271... Line 271...
271
        public function getDotNotation() {
271
        public function getDotNotation() {
272
                return $this->oid;
272
                return $this->oid;
273
        }
273
        }
274
 
274
 
275
        public function isWellKnown() {
275
        public function isWellKnown() {
276
                $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = '".OIDplus::db()->real_escape_string("oid:".$this->oid)."' and well_known = 1");
276
                $res = OIDplus::db()->query("select oid from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = ? and well_known = 1", array("oid:".$this->oid));
277
                if (OIDplus::db()->num_rows($res) > 0) return true;
277
                if (OIDplus::db()->num_rows($res) > 0) return true;
278
 
278
 
279
                $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = '".OIDplus::db()->real_escape_string("oid:".$this->oid)."' and well_known = 1");
279
                $res = OIDplus::db()->query("select oid from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = ? and well_known = 1", array("oid:".$this->oid));
280
                if (OIDplus::db()->num_rows($res) > 0) return true;
280
                if (OIDplus::db()->num_rows($res) > 0) return true;
281
 
281
 
282
                return false;
282
                return false;
283
        }
283
        }
284
 
284
 
Line 293... Line 293...
293
 
293
 
294
                        // Validate identifier
294
                        // Validate identifier
295
                        if (!oid_id_is_valid($asn1)) throw new Exception("'$asn1' is not a valid ASN.1 identifier!");
295
                        if (!oid_id_is_valid($asn1)) throw new Exception("'$asn1' is not a valid ASN.1 identifier!");
296
 
296
 
297
                        // Check if the (real) parent has any conflict
297
                        // Check if the (real) parent has any conflict
298
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."asn1id where name = '".OIDplus::db()->real_escape_string($asn1)."'");
298
                        $res = OIDplus::db()->query("select oid from ".OIDPLUS_TABLENAME_PREFIX."asn1id where name = ?", array($asn1));
299
                        while ($row = OIDplus::db()->fetch_array($res)) {
299
                        while ($row = OIDplus::db()->fetch_array($res)) {
300
                                $check_oid = OIDplusOid::parse($row['oid'])->oid;
300
                                $check_oid = OIDplusOid::parse($row['oid'])->oid;
301
                                if ((oid_up($check_oid) === oid_up($this->oid)) && // same parent
301
                                if ((oid_up($check_oid) === oid_up($this->oid)) && // same parent
302
                                   ($check_oid !== $this->oid))                    // different OID
302
                                   ($check_oid !== $this->oid))                    // different OID
303
                                {
303
                                {
Line 306... Line 306...
306
                        }
306
                        }
307
                }
307
                }
308
 
308
 
309
                // Now do the real replacement
309
                // Now do the real replacement
310
                if (!$simulate) {
310
                if (!$simulate) {
311
                        OIDplus::db()->query("delete from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = '".OIDplus::db()->real_escape_string("oid:".$this->oid)."'");
311
                        OIDplus::db()->query("delete from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = ?", array("oid:".$this->oid));
312
                        foreach ($demandedASN1s as &$asn1) {
312
                        foreach ($demandedASN1s as &$asn1) {
313
                                if (!OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."asn1id (oid, name) values ('".OIDplus::db()->real_escape_string("oid:".$this->oid)."', '".OIDplus::db()->real_escape_string($asn1)."')")) {
313
                                if (!OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."asn1id (oid, name) values (?, ?)", array("oid:".$this->oid, $asn1))) {
314
                                        throw new Exception("Insertion of ASN.1 ID $asn1 to OID ".$this->oid." failed!");
314
                                        throw new Exception("Insertion of ASN.1 ID $asn1 to OID ".$this->oid." failed!");
315
                                }
315
                                }
316
                        }
316
                        }
317
                }
317
                }
318
        }
318
        }
Line 328... Line 328...
328
 
328
 
329
                        // Validate identifier
329
                        // Validate identifier
330
                        if (!iri_arc_valid($iri, false)) throw new Exception("'$iri' is not a valid IRI!");
330
                        if (!iri_arc_valid($iri, false)) throw new Exception("'$iri' is not a valid IRI!");
331
 
331
 
332
                        // Check if the (real) parent has any conflict
332
                        // Check if the (real) parent has any conflict
333
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."iri where name = '".OIDplus::db()->real_escape_string($iri)."'");
333
                        $res = OIDplus::db()->query("select oid from ".OIDPLUS_TABLENAME_PREFIX."iri where name = ?", array($iri));
334
                        while ($row = OIDplus::db()->fetch_array($res)) {
334
                        while ($row = OIDplus::db()->fetch_array($res)) {
335
                                $check_oid = OIDplusOid::parse($row['oid'])->oid;
335
                                $check_oid = OIDplusOid::parse($row['oid'])->oid;
336
                                if ((oid_up($check_oid) === oid_up($this->oid)) && // same parent
336
                                if ((oid_up($check_oid) === oid_up($this->oid)) && // same parent
337
                                   ($check_oid !== $this->oid))                    // different OID
337
                                   ($check_oid !== $this->oid))                    // different OID
338
                                {
338
                                {
Line 341... Line 341...
341
                        }
341
                        }
342
                }
342
                }
343
 
343
 
344
                // Now do the real replacement
344
                // Now do the real replacement
345
                if (!$simulate) {
345
                if (!$simulate) {
346
                        OIDplus::db()->query("delete from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = '".OIDplus::db()->real_escape_string("oid:".$this->oid)."'");
346
                        OIDplus::db()->query("delete from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = ?", array("oid:".$this->oid));
347
                        foreach ($demandedIris as &$iri) {
347
                        foreach ($demandedIris as &$iri) {
348
                                if (!OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."iri (oid, name) values ('".OIDplus::db()->real_escape_string("oid:".$this->oid)."', '".OIDplus::db()->real_escape_string($iri)."')")) {
348
                                if (!OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."iri (oid, name) values (?, ?)", array("oid:".$this->oid, $iri))) {
349
                                        throw new Exception("Insertion of IRI $iri to OID ".$this->oid." failed!");
349
                                        throw new Exception("Insertion of IRI $iri to OID ".$this->oid." failed!");
350
                                }
350
                                }
351
                        }
351
                        }
352
                }
352
                }
353
        }
353
        }