forked from pellcorp/opendb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.php
146 lines (121 loc) · 4.7 KB
/
export.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
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
<?php
/*
OpenDb Media Collector Database
Copyright (C) 2001,2013 by Jason Pell
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
include_once("./lib/database.php");
include_once("./lib/logging.php");
include_once("./lib/status_type.php");
/*
* Fetch a complete list of item records, which have at least one
* item instance, for the specified owner_id.
*/
function fetch_export_item_rs($s_item_type, $owner_id, $restrict_status_type_r = NULL) {
$query = "SELECT DISTINCT i.id as item_id, i.title, i.s_item_type " . "FROM user u, item i, item_instance ii, s_status_type sst " . "WHERE u.user_id = ii.owner_id AND i.id = ii.item_id AND sst.s_status_type = ii.s_status_type ";
if (strlen ( $owner_id ) > 0)
$query .= "AND ii.owner_id = '$owner_id' ";
// can only export items for active users.
$query .= "AND u.active_ind = 'Y' ";
if (strlen ( $s_item_type ) > 0)
$query .= "AND i.s_item_type = '$s_item_type'";
if (is_not_empty_array ( $restrict_status_type_r )) {
$query .= 'AND sst.s_status_type IN(' . format_sql_in_clause ( $restrict_status_type_r ) . ')';
}
// Not the status_type restriction could override this, but thats fine leave it as is.
if (! is_user_granted_permission ( PERM_ITEM_ADMIN )) {
$query .= " AND ( sst.hidden_ind = 'N' OR ii.owner_id = '" . get_opendb_session_var ( 'user_id' ) . "') ";
}
$result = db_query ( $query );
if ($result && db_num_rows ( $result ) > 0)
return $result;
else
return FALSE;
}
/*
* Return a list of records owned by the specified $owner_id
* AND visible to the current user.
*/
function fetch_export_item_instance_rs($s_item_type, $owner_id) {
$query = "SELECT i.id as item_id, ii.instance_no, i.title, i.s_item_type, ii.owner_id, ii.borrow_duration, ii.s_status_type, ii.status_comment, UNIX_TIMESTAMP(ii.update_on) AS update_on " . "FROM user u, item i, item_instance ii, s_status_type sst " . "WHERE u.user_id = ii.owner_id AND i.id = ii.item_id AND sst.s_status_type = ii.s_status_type ";
if (strlen ( $s_item_type ) > 0)
$query .= "AND i.s_item_type = '$s_item_type'";
// can only export items for active users.
$query .= "AND u.active_ind = 'Y' ";
if (strlen ( $owner_id ) > 0)
$query .= " AND ii.owner_id = '$owner_id' ";
if (! is_user_granted_permission ( PERM_ITEM_ADMIN )) {
$query .= " AND ( sst.hidden_ind = 'N' OR ii.owner_id = '" . get_opendb_session_var ( 'user_id' ) . "') ";
}
$query .= "ORDER by i.id, ii.instance_no";
$result = db_query ( $query );
if ($result && db_num_rows ( $result ) > 0)
return $result;
else
return FALSE;
}
function is_export_plugin($plugin) {
if (strlen ( $plugin ) > 0 && file_exists ( './lib/export/' . $plugin . '.class.php' ))
return TRUE;
else
return FALSE;
}
/**
Generate a list of export plugins
Returns an array of the following format:
*/
function get_export_r() {
$handle = opendir ( './lib/export' );
while ( $file = readdir ( $handle ) ) {
// Ensure valid plugin name.
if (! preg_match ( "/^\./", $file ) && preg_match ( "/(.*).class.php$/", $file, $regs )) {
$export [] = $regs [1];
}
}
closedir ( $handle );
if (is_array ( $export ) && count ( $export ) > 0)
return $export;
else // empty array as last resort.
return array ();
}
function &get_export_plugin($pluginName) {
if (is_export_plugin ( $pluginName )) {
include_once("./lib/export/" . $pluginName . ".class.php");
$exportPlugin = new $pluginName ();
return $exportPlugin;
} else {
return NULL;
}
}
function get_export_plugin_list_r() {
$pluginList = NULL;
$export_type_r = get_export_r ();
if (is_array ( $export_type_r )) {
foreach ($export_type_r as $pluginRef) {
include_once("./lib/export/" . $pluginRef . ".class.php");
$exportPlugin = new $pluginRef ();
if ($exportPlugin !== NULL) {
if (strcasecmp ( $pluginRef, get_class ( $exportPlugin ) ) === 0) {
$pluginList [] = array (
'name' => $pluginRef,
'description' => $exportPlugin->get_display_name () );
} else {
opendb_logger ( OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, 'Export class is not valid', array (
$pluginRef ) );
}
}
}
}
return $pluginList;
}
?>