forked from ndlibersa/resources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.php
160 lines (143 loc) · 4.6 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/*
**************************************************************************************************************************
** CORAL Resources Module v. 1.2
**
** Copyright (c) 2010 University of Notre Dame
**
** This file is part of CORAL.
**
** CORAL 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 3 of the License, or (at your option) any later version.
**
** CORAL 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 CORAL. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************************************************************
*/
session_start();
include_once 'directory.php';
include_once 'util.php';
function escape_csv($value) {
// replace \n with \r\n
$value = preg_replace("/(?<!\r)\n/", "\r\n", $value);
// escape quotes
$value = str_replace('"', '""', $value);
return '"'.$value.'"';
}
function array_to_csv_row($array) {
$escaped_array = array_map("escape_csv", $array);
return implode(",",$escaped_array)."\r\n";
}
$queryDetails = Resource::getSearchDetails();
$whereAdd = $queryDetails["where"];
$searchDisplay = $queryDetails["display"];
$orderBy = $queryDetails["order"];
//get the results of the query into an array
$resourceObj = new Resource();
$resourceArray = array();
$resourceArray = $resourceObj->export($whereAdd, $orderBy);
$replace = array("/", "-");
$excelfile = "resources_export_" . str_replace( $replace, "_", format_date( date( 'Y-m-d' ) ) ).".csv";
header("Pragma: public");
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=\"" . $excelfile . "\"");
$columnHeaders = array(
"Record ID",
"Name",
"Type",
"Format",
"Date Created",
"User Created",
"Date Updated",
"User Updated",
"Status",
"ISSN/ISBN",
"Resource URL",
"Alt URL",
"Organizations",
"Aliases",
"Parent Record",
"Child Record",
"Acquisition Type",
"Cost",
"Order Number",
"System Number",
"Purchasing Sites",
"Sub Start",
"Current Sub End",
"Subscription Alert Enabled",
"License Names",
"License Status",
"Authorized Sites",
"Administering Sites",
"Authentication Type",
"Access Method",
"Storage Location",
"Simultaneous User Limit",
"Coverage",
"Username",
"Password",
"Cataloging Type",
"Cataloging Status",
"Catalog Record Set Identifier",
"Catalog Record Source URL",
"Catalog Records Available",
"Catalog Records Loaded",
"OCLC Holdings Updated"
);
echo array_to_csv_row(array("Resource Record Export " . format_date( date( 'Y-m-d' ))));
if (!$searchDisplay) {
$searchDisplay = array("All Resource Records");
}
echo array_to_csv_row(array(implode('; ', $searchDisplay)));
echo array_to_csv_row($columnHeaders);
foreach($resourceArray as $resource) {
$updateDateFormatted=normalize_date($resource['updateDate']);
$resourceValues = array(
$resource['resourceID'],
$resource['titleText'],
$resource['resourceType'],
$resource['resourceFormat'],
format_date($resource['createDate']),
$resource['createName'],
$updateDateFormatted,
$resource['updateName'],
$resource['status'],
$resource['isbnOrISSN'],
$resource['resourceURL'],
$resource['resourceAltURL'],
$resource['organizationNames'],
$resource['aliases'],
$resource['parentResources'],
$resource['childResources'],
$resource['acquisitionType'],
$resource['payments'],
$resource['orderNumber'],
$resource['systemNumber'],
$resource['purchasingSites'],
$resource['currentStartDate'],
$resource['currentEndDate'],
($resource['subscriptionAlertEnabledInd'] ? 'Y' : 'N'),
$resource['licenseNames'],
$resource['licenseStatuses'],
$resource['authorizedSites'],
$resource['administeringSites'],
$resource['authenticationType'],
$resource['accessMethod'],
$resource['storageLocation'],
$resource['userLimit'],
$resource['coverage'],
$resource['authenticationUserName'],
$resource['authenticationPassword'],
$resource['catalogingType'],
$resource['catalogingStatus'],
$resource['recordSetIdentifier'],
$resource['bibSourceURL'],
$resource['numberRecordsAvailable'],
$resource['numberRecordsLoaded'],
($resource['hasOclcHoldings'] ? 'Y' : 'N')
);
echo array_to_csv_row($resourceValues);
}
?>