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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
<?php
/**
* @version $Header$
* @package articles
*
* @copyright Copyright (c) 2004-2006, bitweaver.org
* All Rights Reserved. See below for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
*/
/**
* Required setup
*/
global $gBitSystem;
require_once( CONTACT_PKG_PATH.'ContactXrefType.php' );
/**
* @package contact
*/
class ContactXref extends BitBase {
var $mType;
var $mSource;
var $mXrefId;
var $mContentId;
var $mDate;
function ContactXref( $iXrefId = NULL ) {
$this->mXrefId = NULL;
$this->mSource = NULL;
BitBase::BitBase();
if( $iXrefId ) {
$this->load( $iXrefId );
}
// Date object to handle date and time display
$this->mDate = new BitDate();
$offset = $this->mDate->get_display_offset();
}
function isValid() {
return ($this->verifyId($this->mXrefId));
}
function load( $pXref_id = NULL ) {
if( @BitBase::verifyId( $pXref_id ) ) {
$sql = "SELECT x.*, CASE
WHEN x.`xorder` = 0 THEN s.`cross_ref_title`
ELSE s.`cross_ref_title` || '-' || x.`xorder` END
AS source_title, s.`source`, s.`xref_type`,
CASE WHEN x.`start_date` IS NULL THEN 'y' ELSE 'n' END AS `ignore_start_date`,
CASE WHEN x.`end_date` IS NULL THEN 'y' ELSE 'n' END AS `ignore_end_date`
FROM `".BIT_DB_PREFIX."contact_xref` x
JOIN `".BIT_DB_PREFIX."contact_xref_source` s ON s.`source` = x.`source`
WHERE x.`xref_id` = ?
ORDER BY x.`xorder`";
$result = $this->mDb->getRow( $sql, array( $pXref_id ) );
if( $result['content_id'] ) {
$this->mXrefId = $pXref_id;
$this->mContentId = $result['content_id'];
$this->mType = $result['xref_type'];
$this->mSource = $result['source'];
$this->mInfo['title'] = $result['source_title'];
unset($result['source_title']);
$this->mInfo['data'] = $result;
}
}
}
function verify( &$pParamHash ) {
// if ( $this->isValid() ) {
// Validate the (optional) xref_id parameter
if (@$this->verifyId($pParamHash['xref_id'])) {
$pParamHash['xref_id'] = (int)$pParamHash['xref_id'];
} else {
$pParamHash['xref_id'] = NULL;
}
if ( isset ( $pParamHash['fAddXref'] ) ) {
if ( isset( $pParamHash['Array_xref_type_list'] )) {
$pParamHash['xref_store']['source'] = $pParamHash['Array_xref_type_list']['Array.source'];
}
$pParamHash['xref_store']['content_id'] = $pParamHash['content_id'];
$sql = "SELECT x`.multi` FROM `".BIT_DB_PREFIX."contact_xref_source` x WHERE x.`source` = ?";
$pParamHash['xref_store']['xorder'] = $this->mDb->getOne( $sql, array( $pParamHash['xref_store']['source'] ) );
}
if ( isset ( $pParamHash['fStepXref'] ) ) {
$pParamHash['xref_store']['source'] = $this->mSource;
$pParamHash['xref_store']['xorder'] = $this->mInfo['data']['xorder'] + 1;
$pParamHash['xref_store']['content_id'] = $this->mContentId;
$pParamHash['start_date'] = $this->mDb->NOW();
$pParamHash['ignore_end_date'] = 'on';
$pParamHash['xref_store']['xkey'] = '';
$pParamHash['xref_store']['xkey_ext'] = '';
$pParamHash['xref_store']['data'] = '';
}
if ( isset( $pParamHash['xkey'] )) {
$pParamHash['xref_store']['xkey'] = $pParamHash['xkey'];
}
if ( isset( $pParamHash['xkey_ext'] )) {
$pParamHash['xref_store']['xkey_ext'] = $pParamHash['xkey_ext'];
}
if ( isset( $pParamHash['edit'] )) {
$pParamHash['xref_store']['data'] = $pParamHash['edit'];
}
$pParamHash['xref_store']['last_update_date'] = $this->mDb->NOW();
// If start and/or end dates are supplied these are updated as well
if( !empty( $pParamHash['start_Month'] ) ) {
$dateString = $this->mDate->gmmktime(
$pParamHash['start_Hour'],
$pParamHash['start_Minute'],
isset($pParamHash['start_Second']) ? $pParamHash['start_Second'] : 0,
$pParamHash['start_Month'],
$pParamHash['start_Day'],
$pParamHash['start_Year']
);
$timestamp = $this->mDate->getUTCFromDisplayDate( $dateString );
if( $timestamp !== -1 ) {
$pParamHash['start_date'] = $timestamp;
}
}
if( !empty( $pParamHash['start_date'] ) ) {
$pParamHash['xref_store']['start_date'] = $pParamHash['start_date'];
}
if( isset ($pParamHash['ignore_start_date']) && $pParamHash['ignore_start_date'] == 'on' ) {
$pParamHash['xref_store']['start_date'] = '';
}
if( !empty( $pParamHash['end_Month'] ) ) {
$dateString = $this->mDate->gmmktime(
$pParamHash['end_Hour'],
$pParamHash['end_Minute'],
isset($pParamHash['end_Second']) ? $pParamHash['end_Second'] : 0,
$pParamHash['end_Month'],
$pParamHash['end_Day'],
$pParamHash['end_Year']
);
$timestamp = $this->mDate->getUTCFromDisplayDate( $dateString );
if( $timestamp !== -1 ) {
$pParamHash['end_date'] = $timestamp;
}
}
if( !empty( $pParamHash['end_date'] ) ) {
$pParamHash['xref_store']['end_date'] = $pParamHash['end_date'];
}
if( isset ($pParamHash['ignore_end_date']) && $pParamHash['ignore_end_date'] == 'on' ) {
$pParamHash['xref_store']['end_date'] = '';
}
// }
return(count($this->mErrors) == 0);
}
function store( &$pParamHash = NULL ) {
if( $this->verify( $pParamHash ) ) {
$table = BIT_DB_PREFIX."contact_xref";
$this->mDb->StartTrans();
if( isset( $pParamHash['xref_id'] ) ) {
$result = $this->mDb->associateUpdate( $table, $pParamHash['xref_store'], array( "xref_id" => $pParamHash['xref_id'] ) );
} else {
$this->mXrefId = $pParamHash['ref_id'] = $pParamHash['xref_store']['xref_id'] = $this->mDb->GenID( 'contact_xref_seq' );
$result = $this->mDb->associateInsert( $table, $pParamHash['xref_store'] );
}
// load before completing transaction as firebird isolates results
$this->load( $this->mXrefId );
$this->mDb->CompleteTrans();
return true;
} else {
return false;
}
}
function stepXref( &$pParamHash = NULL ) {
if ( $pParamHash["expunge"] == 2 ) {
$pParamHash['end_date'] = $this->mDb->NOW();
$this->store( $pParamHash );
unset($pParamHash['xref_id']);
$pParamHash['fStepXref'] = 1;
} else if ( $pParamHash["expunge"] == 1 ) {
$pParamHash['end_date'] = $this->mDb->NOW();
} else {
$pParamHash['ignore_end_date'] = 'on';
}
$this->store( $pParamHash );
return true;
}
}
?>
|