3 # This file is part of Koha.
5 # Copyright 2014 BibLibre
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use POSIX qw(strftime);
25 use URI::Encode qw(uri_encode);
27 =head1 NAME C4::UsageStats
31 This package contains what is needed to report Koha statistics to hea
32 hea.koha-community.org is the server that centralize Koha setups informations
33 Koha libraries are encouraged to provide informations about their collections,
38 $needUpdateYN = C4::UsageStats::NeedUpdate;
40 Returns Y (1) if the last update is more than 1 month old
41 This way, even if the cronjob is run every minute, the webservice will be called
47 my $lastupdated = C4::Context->preference('UsageStatsLastUpdateTime') || 0;
48 my $now = strftime("%s", localtime);
50 # Need to launch cron.
51 return 1 if $now - $lastupdated >= 2592000;
53 # Data don't need to be updated
60 name => C4::Context->preference('UsageStatsLibraryName') || q||,
61 id => C4::Context->preference('UsageStatsID') || 0,
65 # Get database volumetry.
66 foreach (qw/biblio auth_header old_issues old_reserves borrowers aqorders subscription/) {
67 $report->{volumetry}{$_} = _count($_);
70 # Get systempreferences.
74 AcqWarnOnDuplicateInvoice
93 UseAuthoritiesForTracings
96 IntranetBiblioDefaultView
102 DefaultClassificationSource
103 EasyAnalyticalRecords
110 SpineLabelShowPrintOnBibDetails
111 BlockReturnOfWithdrawnItems
112 CalculateFinesOnReturn
113 AgeRestrictionOverride
116 AllowItemsOnHoldCheckout
117 AllowNotForLoanOverride
118 AllowRenewalLimitOverride
122 AutoRemoveOverduesRestrictions
125 HomeOrHoldingBranchReturn
126 InProcessingToShelvingCart
129 ManInvInNoissuesCharge
133 RentalsInNoissuesCharge
136 TransfersMaxDaysWarning
137 UseBranchTransferLimits
139 UseTransportCostMatrix
142 FinesIncludeGracePeriod
144 RefundLostItemFeeOnReturn
145 WhenLostChargeReplacementFee
147 AllowHoldDateInFuture
148 AllowHoldPolicyOverride
149 AllowHoldsOnDamagedItems
150 AllowHoldsOnPatronsPossessions
152 AutoResumeSuspendedHolds
153 canreservefromotherbranches
154 decreaseLoanHighHolds
155 DisplayMultiPlaceHold
156 emailLibrarianWhenHoldIsPlaced
157 ExpireReservesMaxPickUpDelay
158 OPACAllowHoldDateInFuture
159 OPACAllowUserToChooseBranch
160 ReservesControlBranch
164 TransferWhenCancelAllWaitingHolds
165 AllowAllMessageDeletion
166 AllowOfflineCirculation
168 CircAutoPrintQuickSlip
169 DisplayClearScreenButton
170 FilterBeforeOverdueReport
172 itemBarcodeFallbackSearch
173 itemBarcodeInputFilter
174 previousIssuesDefaultSortOrder
175 RecordLocalUseOnReturn
178 todaysIssuesDefaultSortOrder
179 UpdateTotalIssuesOnCirc
181 WaitingNotifyAtCheckin
182 AllowSelfCheckReturns
187 OPACAmazonCoverImages
192 IDreamBooksReadometer
195 LibraryThingForLibrariesEnabled
198 NovelistSelectEnabled
204 CalendarFirstDayOfWeek
214 AuthorisedValueImages
219 HighlightOwnItemsOnOPAC
220 OpacAddMastheadLibraryPulldown
221 OPACDisplay856uAsImage
229 OpacShowFiltersPulldownMobile
230 OPACShowHoldQueueDetails
231 OpacShowLibrariesPulldownMobile
232 OpacShowRecentComments
233 OPACShowUnusedAuthorities
236 OPACURLOpenInNewWindow
248 OPACPopupAuthorsSearch
258 AllowPurchaseSuggestionBranchChoice
259 OpacAllowPublicListCreation
260 OpacAllowSharingPrivateLists
264 OPACViewOthersSuggestions
268 EnableOpacSearchHistory
272 PatronSelfRegistration
276 AutoEmailPrimaryAddress
278 BorrowerRenewalPeriodBase
281 EnhancedMessagingPreferences
282 ExtendedPatronAttributes
283 intranetreadinghistory
286 TalkingTechItivaPhoneNotification
288 IncludeSeeFromInSearches
294 TraceCompleteSubfields
295 TraceSubjectSubdivisions
301 OPACItemsResultsDisplay
303 IntranetNumbersPreferPhrase
304 OPACNumbersPreferPhrase
306 RenewSerialAddsSuggestion
307 RoutingListAddReserves
312 StaffAuthorisedValueImages
317 StaffDetailItemSelection
327 $report->{systempreferences}{$_} = C4::Context->preference($_);
332 =head2 ReportToCommunity
336 Send to hea.koha-community.org database informations
340 sub ReportToCommunity {
342 my $json = uri_encode( to_json($data), 1 );
344 my $ua = LWP::UserAgent->new;
346 HTTP::Request->new( POST => "http://hea.koha-community.org/upload.pl" );
347 $req->content_type('application/x-www-form-urlencoded');
348 $req->content("data=$json");
349 my $res = $ua->request($req);
350 my $content = from_json( $res->decoded_content );
351 C4::Context->set_preference( 'UsageStatsID',
352 $content->{library}{library_id} );
357 $data = _count($table);
359 Count the number of records in $table tables
366 my $dbh = C4::Context->dbh;
367 my $sth = $dbh->prepare("SELECT count(*) from $table");
369 return $sth->fetchrow_array;