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 AllowItemsOnHoldCheckoutSCO
137 AllowNotForLoanOverride
138 AllowRenewalLimitOverride
142 AutoRemoveOverduesRestrictions
145 InProcessingToShelvingCart
148 ManInvInNoissuesCharge
152 RentalsInNoissuesCharge
155 TransfersMaxDaysWarning
156 UseBranchTransferLimits
158 UseTransportCostMatrix
161 FinesIncludeGracePeriod
163 RefundLostOnReturnControl
164 WhenLostChargeReplacementFee
166 AllowHoldDateInFuture
167 AllowHoldPolicyOverride
168 AllowHoldsOnDamagedItems
169 AllowHoldsOnPatronsPossessions
170 AutoResumeSuspendedHolds
171 canreservefromotherbranches
172 decreaseLoanHighHolds
173 DisplayMultiPlaceHold
174 emailLibrarianWhenHoldIsPlaced
175 ExpireReservesMaxPickUpDelay
176 OPACAllowHoldDateInFuture
177 OPACAllowUserToChooseBranch
178 ReservesControlBranch
182 TransferWhenCancelAllWaitingHolds
183 AllowAllMessageDeletion
184 AllowOfflineCirculation
186 CircAutoPrintQuickSlip
187 DisplayClearScreenButton
188 FilterBeforeOverdueReport
190 itemBarcodeFallbackSearch
191 itemBarcodeInputFilter
192 previousIssuesDefaultSortOrder
193 RecordLocalUseOnReturn
196 todaysIssuesDefaultSortOrder
197 UpdateTotalIssuesOnCirc
199 WaitingNotifyAtCheckin
200 AllowSelfCheckReturns
205 OPACAmazonCoverImages
210 IDreamBooksReadometer
213 LibraryThingForLibrariesEnabled
216 NovelistSelectEnabled
223 CalendarFirstDayOfWeek
237 HighlightOwnItemsOnOPAC
238 OpacAddMastheadLibraryPulldown
239 OPACDisplay856uAsImage
247 OpacShowFiltersPulldownMobile
248 OPACShowHoldQueueDetails
249 OpacShowLibrariesPulldownMobile
250 OpacShowRecentComments
251 OPACShowUnusedAuthorities
254 OPACURLOpenInNewWindow
266 OPACPopupAuthorsSearch
276 AllowPurchaseSuggestionBranchChoice
277 OpacAllowPublicListCreation
278 OpacAllowSharingPrivateLists
281 OPACViewOthersSuggestions
284 EnableOpacSearchHistory
288 PatronSelfRegistration
291 AutoEmailPrimaryAddress
293 BorrowerRenewalPeriodBase
296 EnhancedMessagingPreferences
297 ExtendedPatronAttributes
298 intranetreadinghistory
301 TalkingTechItivaPhoneNotification
303 IncludeSeeFromInSearches
309 TraceCompleteSubfields
310 TraceSubjectSubdivisions
316 OPACItemsResultsDisplay
318 IntranetNumbersPreferPhrase
319 OPACNumbersPreferPhrase
321 RenewSerialAddsSuggestion
322 RoutingListAddReserves
331 StaffDetailItemSelection
341 $report->{systempreferences
}{$_} = C4
::Context
->preference($_);
346 =head2 ReportToCommunity
350 Send to hea.koha-community.org database informations
354 sub ReportToCommunity
{
356 my $json = encode_json
($data);
358 my $url = "https://hea.koha-community.org/upload.pl";
359 my $ua = LWP
::UserAgent
->new;
362 'Content-type' => 'application/json;charset=utf-8',
365 my $content = decode_json
( $res->decoded_content );
366 if ( $content->{koha_id
} ) {
367 C4
::Context
->set_preference( 'UsageStatsID', $content->{koha_id
} );
369 if ( $content->{id
} ) {
370 C4
::Context
->set_preference( 'UsageStatsPublicID', $content->{id
} );
376 $data = _count($table);
378 Count the number of records in $table tables
385 my $dbh = C4
::Context
->dbh;
386 my $sth = $dbh->prepare("SELECT count(*) from $table");
388 return $sth->fetchrow_array;