-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcalendar.php
More file actions
272 lines (249 loc) · 10.5 KB
/
calendar.php
File metadata and controls
272 lines (249 loc) · 10.5 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
/*
**************************************************************************************************************************
** CORAL Licensing Module v. 1.0
**
** 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/>.
**
**************************************************************************************************************************
** This page was originally intended as a standalone add-on. After interest this was added to the Licensing module
** but it was not retrofitted to more tightly integrate into the Licensing module.
*/
include_once 'directory.php';
$pageTitle=_('Home');
include 'templates/header.php';
//used for creating a "sticky form" for back buttons
//except we don't want it to retain if they press the 'index' button
//check what referring script is
if (isset($_SESSION['ref_script']) && ($_SESSION['ref_script'] != "license.php")){
$reset='Y';
}else{
$reset='N';
}
$_SESSION['ref_script']=$currentPage;
//below includes search options in left pane only - the results are refreshed through ajax and placed in div searchResults
//print header
$pageTitle=_('Calendar');
$config = new Configuration;
$host = $config->database->host;
$username = $config->database->username;
$password = $config->database->password;
$license_databaseName = $config->database->name;
$resource_databaseName = $config->settings->resourcesDatabaseName;
$link = mysqli_connect($host, $username, $password) or die(_("Could not connect to host."));
mysqli_select_db($link, $license_databaseName) or die(_("Could not find License database."));
mysqli_select_db($link, $resource_databaseName) or die(_("Could not find Resource database."));
$display = array();
$calendarSettings = new CalendarSettings();
try{
$calendarSettingsArray = $calendarSettings->allAsArray();
}catch(Exception $e){
echo "<span style='color:red'>"._("There was an error with the CalendarSettings Table please verify the table has been created.")."</span>";
exit;
}
// Check for earlier version of Resource Module. With update of 1.3 the table definition changed.
$query = "Select subscriptionStartDate from `$resource_databaseName`.`Resource`";
$result = mysqli_query($link, $query);
if ($result) {
// Previous tabel definition before Resources version 1.3
$startDateName = "subscriptionStartDate";
$endDateName = "subscriptionEndDate";
} else {
$startDateName = "currentStartDate";
$endDateName = "currentEndDate";
}
foreach($calendarSettingsArray as $display) {
$config_error = TRUE;
if (strtolower($display['shortName']) == strtolower('Days After Subscription End')) {
if (strlen($display['value'])>0) {
$daybefore = $display['value'];
$config_error = FALSE;
}
} elseif (strtolower($display['shortName']) == strtolower('Days Before Subscription End')) {
if (strlen($display['value'])>0) {
$dayafter = $display['value'];
$config_error = FALSE;
}
} elseif (strtolower($display['shortName']) == strtolower('Resource Type(s)')) {
if (strlen($display['value'])>0) {
$resourceType = $display['value'];
$config_error = FALSE;
}
} elseif (strtolower($display['shortName']) == strtolower('Authorized Site(s)')) {
if (strlen($display['value'])>0) {
$authorizedSiteID = preg_split("/[\s,]+/", $display['value']);
$config_error = FALSE;
}
}
}
// Validate the config settings
if ($config_error) {
echo "<span style='color:red'>"._("There was an error with the CalendarSettings Configuration.")."</span>";
exit;
}
$query = "
SELECT DATE_FORMAT(`$resource_databaseName`.`Resource`.`$endDateName`, '%Y') AS `year`,
DATE_FORMAT(`$resource_databaseName`.`Resource`.`$endDateName`, '%M') AS `month`,
DATE_FORMAT(`$resource_databaseName`.`Resource`.`$endDateName`, '%y-%m-%d') AS `sortdate`,
DATE_FORMAT(`$resource_databaseName`.`Resource`.`$endDateName`, '%m/%d/%Y') AS `$endDateName`,
`$resource_databaseName`.`Resource`.`resourceID`, `$resource_databaseName`.`Resource`.`titleText`,
`$license_databaseName`.`License`.`shortName`,
`$license_databaseName`.`License`.`licenseID`, `$resource_databaseName`.`ResourceType`.`shortName` AS resourceTypeName, `$resource_databaseName`.`ResourceType`.`resourceTypeID`
FROM `$resource_databaseName`.`Resource`
LEFT JOIN `$resource_databaseName`.`ResourceLicenseLink` ON (`$resource_databaseName`.`Resource`.`resourceID` = `$resource_databaseName`.`ResourceLicenseLink`.`resourceID`)
LEFT JOIN `$license_databaseName`.`License` ON (`ResourceLicenseLink`.`licenseID` = `$license_databaseName`.`License`.`licenseID`)
INNER JOIN `$resource_databaseName`.`ResourceType` ON (`$resource_databaseName`.`Resource`.`resourceTypeID` = `$resource_databaseName`.`ResourceType`.`resourceTypeID`)
WHERE
`$resource_databaseName`.`Resource`.`archiveDate` IS NULL AND
`$resource_databaseName`.`Resource`.`$endDateName` IS NOT NULL AND
`$resource_databaseName`.`Resource`.`$endDateName` <> '00/00/0000' AND
`$resource_databaseName`.`Resource`.`$endDateName` BETWEEN (CURDATE() - INTERVAL " . $daybefore . " DAY) AND (CURDATE() + INTERVAL " . $dayafter . " DAY) ";
if ($resourceType) {
$query = $query . " AND `$resource_databaseName`.`Resource`.`resourceTypeID` IN ( ". $resourceType . " ) ";
}
$query = $query . "ORDER BY `sortdate`, `$resource_databaseName`.`Resource`.`titleText`";
$result = mysqli_query($link, $query) or die(_("Bad Query Failure"));
?>
<div style='text-align:left;'>
<table class="headerTable" style="background-image:url('images/header.gif');background-repeat:no-repeat;">
<tr style='vertical-align:top;'>
<td>
<b><?php echo _("Upcoming License Renewals");?></b>
</td>
</tr>
</table>
<div id="searchResults">
<table style="width: 100%;" class="dataTable">
<tbody>
<?php
$mYear = "";
$mMonth = "";
$month_html = "";
$year_html = "";
$displayYear = FALSE;
$displayMonth = FALSE;
$i = -1;
while ($row = mysqli_fetch_assoc($result)) {
$query2 = "SELECT
`$resource_databaseName`.`Resource`.`resourceID`,
`$resource_databaseName`.`AuthorizedSite`.`shortName`,
`$resource_databaseName`.`AuthorizedSite`.`authorizedSiteID`
FROM
`$resource_databaseName`.`Resource`
INNER JOIN `$resource_databaseName`.`ResourceAuthorizedSiteLink` ON (`$resource_databaseName`.`Resource`.`resourceID` = `$resource_databaseName`.`ResourceAuthorizedSiteLink`.`resourceID`)
INNER JOIN `$resource_databaseName`.`AuthorizedSite` ON (`$resource_databaseName`.`ResourceAuthorizedSiteLink`.`authorizedSiteID` = `$resource_databaseName`.`AuthorizedSite`.`authorizedSiteID`)
WHERE
`$resource_databaseName`.`Resource`.`resourceID` = " . $row["resourceID"] .
" order by `$resource_databaseName`.`AuthorizedSite`.`shortName`";
$result2 = mysqli_query($link, $query2) or die(_("Bad Query Failure"));
$i = $i + 1;
$html = "";
if ($mYear != $row["year"]) {
$mYear = $row["year"];
$year_html = "";
$year_html = $year_html . "<tr>";
$year_html = $year_html . "<th colspan='2'>
<table class='noBorderTable'>
<tbody>
<tr>
<td>" . $mYear . "</td>
</tr>
</tbody>
</table>
</th>";
$year_html = $year_html . "</tr>";
$displayYear = TRUE;
}
if ($mMonth != $row["month"]) {
$mMonth = $row["month"];
$month_html = "";
$month_html = $month_html . "<tr>";
$month_html = $month_html . "<th colspan='2'>
<table class='noBorderTable'>
<tbody>
<tr>
<td> " . $mMonth . "</td>
</tr>
</tbody>
</table>
</th>";
$month_html = $month_html . "</tr>";
$displayMonth = TRUE;
}
$html = $html . "<tr>";
if ($i % 2 == 0) {
$alt = "alt";
} else {
$alt = "";
}
$date1 = new DateTime(date("m/d/y"));
$date2 = new DateTime($row["currentEndDate"]);
$interval = $date1->diff($date2);
$num_days = ((($interval->y) * 365) + (($interval->m) * 30) + ($interval->d));
$html = $html . "<td colspan='2' class='$alt'>";
$html = $html . " <a href='../resources/resource.php?resourceID=" . $row["resourceID"] . "'><b>". $row["titleText"] . "</b></a>";
$html = $html . " [License: ";
if (is_null($row["licenseID"])) {
$html = $html . "<i>"._("No associated licenses available.")."</i>";
} else {
$html = $html . "<a href='license.php?licenseID=" . $row["licenseID"] . "'>". $row["shortName"] . "</a>";
}
$html = $html . " ] - " . $row["resourceTypeName"] . " ";
if ($interval->invert) {
$html = $html . "- <strong style='color:red'>"._("Expired ").$num_days._(" days ago")."</strong>";
} else {
$html = $html . _("- Expires in ");
if ($date1 > $date2) {
$html = $html . "<span style='color:red'>(" . $num_days . _(" days)")."</span>";
} else {
$html = $html . $num_days . _(" days ");
}
}
$k = 0;
$siteID = array();
while ($row2 = mysqli_fetch_assoc($result2)) {
if ($k == 0) {
$html = $html . "</td></tr>";
$html = $html . "<tr>
<td class='$alt'> </td>
<td class='$alt'>"._("Participants: ");
} else {
$html = $html . ", ";
}
$html = $html . $row2["shortName"];
array_push( $siteID, $row2["authorizedSiteID"] );
$k = $k + 1;
}
$arr3 = array_intersect($authorizedSiteID, $siteID);
$html = $html . "</td>";
$html = $html . "</tr>";
if (count($arr3) > 0) {
if ($displayYear) {
echo $year_html;
$displayYear = FALSE;
}
if ($displayMonth) {
echo $month_html;
$displayMonth = FALSE;
}
echo $html;
}
}
?>
</tbody>
</table>
</div>
</div>
<br />
<?php
//print footer
include 'templates/footer.php';
?>