forked from bitweaver/nlpg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
NlpgStreet.php
89 lines (80 loc) · 2.83 KB
/
NlpgStreet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
*----------------------------------------------------------------------
* nsg street record
*----------------------------------------------------------------------
* Copyright (c) 2007 bitweaver
*
* |
*----------------------------------------------------------------------
* Ported to bitweaver framework by Lester Caine 2006-12-29
* $Id$
*/
require_once(NLPG_PKG_PATH.'lib/phpcoord-2.3.php' );
class NlpgStreet extends BitBase {
var $mUsrn;
function NlpgStreet( $pUsrn ) {
BitBase::BitBase();
if( is_numeric( $pUsrn ) ) {
$this->mUsrn = $pUsrn;
}
}
function isValid() {
return( !empty( $this->mUsrn ) && is_numeric( $this->mUsrn ) );
}
function load() {
if( $this->isValid() ) {
$sql = "SELECT *
FROM `".BIT_DB_PREFIX."nlpg_street` s WHERE `usrn`=?";
if( $rs = $this->mDb->query( $sql, array( $this->mUsrn ) ) ) {
if( $this->mInfo = $rs->fields ) {
if( $this->mInfo['swa_org_ref_naming'] == 0 ) {
global $gBitSystem;
$gBitSystem->fatalError( tra( 'You do not have permission to access this USRN record' ), 'error.tpl', tra( 'Permission denied.' ) );
}
$os1 = new OSRef($this->mInfo['street_start_x'], $this->mInfo['street_start_y']);
$ll1 = $os1->toLatLng();
$this->mInfo['street_start_lat'] = $ll1->lat;
$this->mInfo['street_start_lng'] = $ll1->lng;
$os1->easting = $this->mInfo['street_end_x'];
$os1->northing = $this->mInfo['street_end_y'];
$ll1 = $os1->toLatLng();
$this->mInfo['street_end_lat'] = $ll1->lat;
$this->mInfo['street_end_lng'] = $ll1->lng;
$this->mInfo['display_usrn'] = $this->getUsrnEntryUrl( $this->mInfo['usrn'] );
$sql = "SELECT *
FROM `".BIT_DB_PREFIX."nlpg_street_xref` x WHERE `usrn`=?";
$result = $this->mDb->query( $sql, array( $this->mUsrn ) );
while( $res = $result->fetchRow() ) {
$this->mInfo['xref'][] = $res;
}
$sql = "SELECT *
FROM `".BIT_DB_PREFIX."nlpg_street_descriptor` s WHERE `usrn`=?";
$result = $this->mDb->query( $sql, array( $this->mUsrn ) );
while( $res = $result->fetchRow() ) {
$this->mInfo['descriptor'][$res['language']] = $res;
}
} else {
global $gBitSystem;
$gBitSystem->fatalError( tra( 'USRN does not exist' ), 'error.tpl', tra( 'Not found.' ) );
}
}
}
return( count( $this->mInfo ) );
}
/**
* Generates the URL to a usrn record reference
* @param usrn
* @return the link to display the page.
*/
function getUsrnEntryUrl( $usrn = NULL ) {
$ret = NULL;
if ( is_numeric( $usrn ) ) {
$ret = NLPG_PKG_URL."index.php?usrn=".$usrn;
} else {
$ret = NLPG_PKG_URL."index.php";
}
return $ret;
}
}
?>