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
110 AutoCreateAuthorities
111 BiblioAddsAuthorities
114 UseAuthoritiesForTracings
117 IntranetBiblioDefaultView
123 DefaultClassificationSource
124 EasyAnalyticalRecords
131 SpineLabelShowPrintOnBibDetails
132 BlockReturnOfLostItems
133 BlockReturnOfWithdrawnItems
134 CalculateFinesOnReturn
135 AgeRestrictionOverride
138 AllowItemsOnHoldCheckoutSIP
139 AllowItemsOnHoldCheckoutSCO
140 AllowNotForLoanOverride
141 AllowRenewalLimitOverride
145 AutoRemoveOverduesRestrictions
150 ManInvInNoissuesCharge
154 RentalsInNoissuesCharge
156 TransfersMaxDaysWarning
157 UseBranchTransferLimits
159 UseTransportCostMatrix
162 FinesIncludeGracePeriod
164 RefundLostOnReturnControl
165 WhenLostChargeReplacementFee
167 AllowHoldDateInFuture
168 AllowHoldPolicyOverride
169 AllowHoldsOnDamagedItems
170 AllowHoldsOnPatronsPossessions
171 AutoResumeSuspendedHolds
172 canreservefromotherbranches
173 decreaseLoanHighHolds
174 DisplayMultiPlaceHold
175 emailLibrarianWhenHoldIsPlaced
176 ExpireReservesMaxPickUpDelay
177 OPACAllowHoldDateInFuture
178 OPACAllowUserToChooseBranch
179 ReservesControlBranch
183 TransferWhenCancelAllWaitingHolds
184 AllowAllMessageDeletion
185 AllowOfflineCirculation
187 CircAutoPrintQuickSlip
188 DisplayClearScreenButton
189 FilterBeforeOverdueReport
191 itemBarcodeFallbackSearch
192 itemBarcodeInputFilter
193 previousIssuesDefaultSortOrder
194 RecordLocalUseOnReturn
197 todaysIssuesDefaultSortOrder
198 UpdateTotalIssuesOnCirc
200 WaitingNotifyAtCheckin
201 AllowSelfCheckReturns
206 OPACAmazonCoverImages
211 LibraryThingForLibrariesEnabled
214 NovelistSelectEnabled
219 CalendarFirstDayOfWeek
233 HighlightOwnItemsOnOPAC
234 OpacAddMastheadLibraryPulldown
235 OPACDisplay856uAsImage
242 OpacShowFiltersPulldownMobile
243 OPACShowHoldQueueDetails
244 OpacShowRecentComments
245 OPACShowUnusedAuthorities
248 OPACURLOpenInNewWindow
260 OPACPopupAuthorsSearch
270 AllowPurchaseSuggestionBranchChoice
271 OpacAllowPublicListCreation
272 OpacAllowSharingPrivateLists
275 OPACViewOthersSuggestions
278 EnableOpacSearchHistory
282 PatronSelfRegistration
285 AutoEmailPrimaryAddress
287 BorrowerRenewalPeriodBase
289 EnhancedMessagingPreferences
290 ExtendedPatronAttributes
291 intranetreadinghistory
293 TalkingTechItivaPhoneNotification
295 IncludeSeeFromInSearches
301 TraceCompleteSubfields
302 TraceSubjectSubdivisions
307 OPACItemsResultsDisplay
309 IntranetNumbersPreferPhrase
310 OPACNumbersPreferPhrase
312 RenewSerialAddsSuggestion
313 RoutingListAddReserves
322 StaffDetailItemSelection
332 $report->{systempreferences
}{$_} = C4
::Context
->preference($_);
337 =head2 ReportToCommunity
341 Send to hea.koha-community.org database informations
345 sub ReportToCommunity
{
347 my $json = encode_json
($data);
349 my $url = "https://hea.koha-community.org/upload.pl";
350 my $ua = LWP
::UserAgent
->new;
353 'Content-type' => 'application/json;charset=utf-8',
356 my $content = decode_json
( $res->decoded_content );
357 if ( $content->{koha_id
} ) {
358 C4
::Context
->set_preference( 'UsageStatsID', $content->{koha_id
} );
360 if ( $content->{id
} ) {
361 C4
::Context
->set_preference( 'UsageStatsPublicID', $content->{id
} );
367 $data = _count($table);
369 Count the number of records in $table tables
376 my $dbh = C4
::Context
->dbh;
377 my $sth = $dbh->prepare("SELECT count(*) from $table");
379 return $sth->fetchrow_array;