1 package C4::UsageStats;
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);
34 This package contains what is needed to report Koha statistics to hea
35 hea.koha-community.org is the server that centralize Koha setups informations
36 Koha libraries are encouraged to provide informations about their collections,
41 $needUpdateYN = C4::UsageStats::NeedUpdate;
43 Returns Y (1) if the last update is more than 1 month old
44 This way, even if the cronjob is run every minute, the webservice will be called
50 my $lastupdated = C4::Context->preference('UsageStatsLastUpdateTime') || 0;
51 my $now = strftime( "%s", localtime );
53 # Need to launch cron.
54 return 1 if $now - $lastupdated >= 2592000;
56 # Data don't need to be updated
63 if( C4::Context->preference('UsageStatsLibrariesInfo') ) {
64 my $libraries = Koha::Libraries->search;
65 while ( my $library = $libraries->next ) {
66 push @libraries, { name => $library->branchname, url => $library->branchurl, country => $library->branchcountry, geolocation => $library->geolocation, };
71 koha_id => C4::Context->preference('UsageStatsID') || 0,
72 name => C4::Context->preference('UsageStatsLibraryName') || q||,
73 url => C4::Context->preference('UsageStatsLibraryUrl') || q||,
74 type => C4::Context->preference('UsageStatsLibraryType') || q||,
75 country => C4::Context->preference('UsageStatsCountry') || q||,
76 geolocation => C4::Context->preference('UsageStatsGeolocation') || q||,
78 libraries => \@libraries,
81 # Get database volumetry.
83 qw/biblio items auth_header old_issues old_reserves borrowers aqorders subscription/
86 $report->{volumetry}{$_} = _count($_);
89 # Get systempreferences.
93 AcqWarnOnDuplicateInvoice
109 AutoCreateAuthorities
110 BiblioAddsAuthorities
112 UseAuthoritiesForTracings
115 IntranetBiblioDefaultView
121 DefaultClassificationSource
122 EasyAnalyticalRecords
129 SpineLabelShowPrintOnBibDetails
130 BlockReturnOfWithdrawnItems
131 CalculateFinesOnReturn
132 AgeRestrictionOverride
135 AllowItemsOnHoldCheckout
136 AllowNotForLoanOverride
137 AllowRenewalLimitOverride
141 AutoRemoveOverduesRestrictions
144 InProcessingToShelvingCart
147 ManInvInNoissuesCharge
151 RentalsInNoissuesCharge
154 TransfersMaxDaysWarning
155 UseBranchTransferLimits
157 UseTransportCostMatrix
160 FinesIncludeGracePeriod
162 RefundLostItemFeeOnReturn
163 WhenLostChargeReplacementFee
165 AllowHoldDateInFuture
166 AllowHoldPolicyOverride
167 AllowHoldsOnDamagedItems
168 AllowHoldsOnPatronsPossessions
169 AutoResumeSuspendedHolds
170 canreservefromotherbranches
171 decreaseLoanHighHolds
172 DisplayMultiPlaceHold
173 emailLibrarianWhenHoldIsPlaced
174 ExpireReservesMaxPickUpDelay
175 OPACAllowHoldDateInFuture
176 OPACAllowUserToChooseBranch
177 ReservesControlBranch
181 TransferWhenCancelAllWaitingHolds
182 AllowAllMessageDeletion
183 AllowOfflineCirculation
185 CircAutoPrintQuickSlip
186 DisplayClearScreenButton
187 FilterBeforeOverdueReport
189 itemBarcodeFallbackSearch
190 itemBarcodeInputFilter
191 previousIssuesDefaultSortOrder
192 RecordLocalUseOnReturn
195 todaysIssuesDefaultSortOrder
196 UpdateTotalIssuesOnCirc
198 WaitingNotifyAtCheckin
199 AllowSelfCheckReturns
204 OPACAmazonCoverImages
209 IDreamBooksReadometer
212 LibraryThingForLibrariesEnabled
215 NovelistSelectEnabled
222 CalendarFirstDayOfWeek
236 HighlightOwnItemsOnOPAC
237 OpacAddMastheadLibraryPulldown
238 OPACDisplay856uAsImage
246 OpacShowFiltersPulldownMobile
247 OPACShowHoldQueueDetails
248 OpacShowLibrariesPulldownMobile
249 OpacShowRecentComments
250 OPACShowUnusedAuthorities
253 OPACURLOpenInNewWindow
265 OPACPopupAuthorsSearch
275 AllowPurchaseSuggestionBranchChoice
276 OpacAllowPublicListCreation
277 OpacAllowSharingPrivateLists
280 OPACViewOthersSuggestions
283 EnableOpacSearchHistory
287 PatronSelfRegistration
290 AutoEmailPrimaryAddress
292 BorrowerRenewalPeriodBase
295 EnhancedMessagingPreferences
296 ExtendedPatronAttributes
297 intranetreadinghistory
300 TalkingTechItivaPhoneNotification
302 IncludeSeeFromInSearches
308 TraceCompleteSubfields
309 TraceSubjectSubdivisions
315 OPACItemsResultsDisplay
317 IntranetNumbersPreferPhrase
318 OPACNumbersPreferPhrase
320 RenewSerialAddsSuggestion
321 RoutingListAddReserves
330 StaffDetailItemSelection
340 $report->{systempreferences}{$_} = C4::Context->preference($_);
345 =head2 ReportToCommunity
349 Send to hea.koha-community.org database informations
353 sub ReportToCommunity {
355 my $json = encode_json($data);
357 my $url = "https://hea.koha-community.org/upload.pl";
358 my $ua = LWP::UserAgent->new;
361 'Content-type' => 'application/json;charset=utf-8',
364 my $content = decode_json( $res->decoded_content );
365 if ( $content->{koha_id} ) {
366 C4::Context->set_preference( 'UsageStatsID', $content->{koha_id} );
368 if ( $content->{id} ) {
369 C4::Context->set_preference( 'UsageStatsPublicID', $content->{id} );
375 $data = _count($table);
377 Count the number of records in $table tables
384 my $dbh = C4::Context->dbh;
385 my $sth = $dbh->prepare("SELECT count(*) from $table");
387 return $sth->fetchrow_array;