Bug 22755: Import Koha::Script into patron_emailer cronjob
[koha.git] / Koha / Manual.pm
blob29028eff8b32f93cbb754c2729538a162fd62f58
1 package Koha::Manual;
3 use Modern::Perl;
5 use C4::Context;
7 sub _get_help_version {
8 my $help_version = C4::Context->preference("Version");
9 if ( $help_version =~ m|^(\d+)\.(\d{2}).*$| ) {
10 my $version = $1;
11 my $major = $2;
12 unless ( $major % 2 ) { $major-- };
13 $major = sprintf("%02d", $major);
14 $help_version = "$version.$major";
16 return $help_version;
19 sub _get_base_url {
20 my ( $preferred_language ) = @_;
22 my @available_languages = qw( en ar cs es fr it pt_BR tz zh_TW );
24 my ( $language ) = grep {
25 my $preferred_short = substr $preferred_language, 0, 2;
26 my $avail_short = substr $_, 0, 2;
27 $preferred_short eq $avail_short ? $_ : ()
28 } @available_languages;
30 my $KohaManualLanguage = $language || C4::Context->preference('KohaManualLanguage') || 'en';
31 my $KohaManualBaseURL = C4::Context->preference('KohaManualBaseURL') || 'https://koha-community.org/manual';
32 if ( $KohaManualBaseURL =~ m|^/| ) {
33 $KohaManualBaseURL = C4::Context->preference('staffClientBaseURL') . $KohaManualBaseURL;
35 return $KohaManualBaseURL . '/' . _get_help_version . '/' . $KohaManualLanguage . '/html'; # TODO html could be a KohaManualFormat with pdf, html, epub
38 our $mapping = {
39 'about' => '/plugins.html#about-koha',
40 'acqui/acqui-home' => '/acquisitions.html',
41 'acqui/addorderiso2709' => '/acquisitions.html#create-a-basket',
42 'acqui/basket' => '/acquisitions.html#create-a-basket',
43 'acqui/basketgroup' => '/acquisitions.html#create-a-basket-group',
44 'acqui/basketheader' => '/acquisitions.html#create-a-basket',
45 'acqui/booksellers' => '/acquisitions.html#acquisition-searches',
46 'acqui/edifactmsgs' => '/acquisitions.html#edifact-messages',
47 'acqui/histsearch' => '/acquisitions.html#acquisition-searches',
48 'acqui/invoice' => '/acquisitions.html#invoices',
49 'acqui/invoices' => '/acquisitions.html#invoices',
50 'acqui/lateorders' => '/acquisitions.html#claims-late-orders',
51 'acqui/neworderbiblio' => '/acquisitions.html#create-a-basket',
52 'acqui/neworderempty' => '/acquisitions.html#create-a-basket',
53 'acqui/newordersubscription' => '/acquisitions.html#create-a-basket',
54 'acqui/newordersuggestion' => '/acquisitions.html#create-a-basket',
55 'acqui/orderreceive' => '/acquisitions.html#receiving-orders',
56 'acqui/parcel' => '/acquisitions.html#receiving-orders',
57 'acqui/parcels' => '/acquisitions.html#receiving-orders',
58 'acqui/supplier' => '/acquisitions.html#vendors',
59 'acqui/uncertainprice' => '/acquisitions.html#create-a-basket',
60 'acqui/z3950_search' => '/acquisitions.html#create-a-basket',
61 'admin/admin-home' => '/administration.html',
62 'admin/aqbudgetperiods' => '/administration.html#budgets',
63 'admin/aqbudgets' => '/administration.html#funds',
64 'admin/aqcontract' => '/acquisitions.html#vendor-contracts',
65 'admin/aqplan' => '/administration.html#budget-planning',
66 'admin/auth_subfields_structure' => '/administration.html#authority-types',
67 'admin/auth_tag_structure' => '/administration.html#authority-types',
68 'admin/authorised_values' => '/administration.html#authorized-values',
69 'admin/authtypes' => '/administration.html#authority-types',
70 'admin/biblio_framework' => '/administration.html#marc-bibliographic-frameworks',
71 'admin/branch_transfer_limits' => '/administration.html#library-transfer-limits',
72 'admin/branches' => '/administration.html#libraries-&-groups',
73 'admin/categorie' => '/administration.html#patron-categories',
74 'admin/checkmarc' => '/administration.html#marc-bibliographic-framework-test',
75 'admin/cities' => '/administration.html#cities-and-towns',
76 'admin/classsources' => '/administration.html#classification-sources',
77 'admin/columns_settings' => '/administration.html#column-settings',
78 'admin/currency' => '/administration.html#currencies-and-exchange-rates',
79 'admin/didyoumean' => '/administration.html#did-you-mean?',
80 'admin/edi_accounts' => '/administration.html#edi-accounts',
81 'admin/edi_ean_accounts' => '/administration.html#library-eans',
82 'admin/fieldmapping' => '/administration.html#keywords-to-marc-mapping',
83 'admin/item_circulation_alerts' => '/administration.html#item-circulation-alerts',
84 'admin/items_search_fields' => '/administration.html#item-search-fields',
85 'admin/itemtypes' => '/administration.html#item-types',
86 'admin/koha2marclinks' => '/administration.html#koha-to-marc-mapping',
87 'admin/marc_subfields_structure' => '/administration.html#marc-bibliographic-frameworks',
88 'admin/marctagstructure' => '/administration.html#marc-bibliographic-frameworks',
89 'admin/matching-rules' => '/administration.html#record-matching-rules',
90 'admin/oai_set_mappings' => '/administration.html#oai-sets-configuration',
91 'admin/oai_sets' => '/administration.html#oai-sets-configuration',
92 'admin/patron-attr-types' => '/administration.html#patron-attribute-types',
93 'admin/preferences' => '/systempreferences.html',
94 'admin/smart-rules' => '/administration.html#circulation-and-fine-rules',
95 'admin/systempreferences' => '/systempreferences.html#local-use',
96 'admin/transport-cost-matrix' => '/administration.html#transport-cost-matrix',
97 'admin/z3950servers' => '/administration.html#z39.50/sru-servers',
98 'authorities/authorities-home' => '/cataloging.html#authorities',
99 'authorities/authorities' => '/cataloging.html#authorities',
100 'authorities/detail' => '/cataloging.html#authorities',
101 'authorities/merge' => '/cataloging.html#merging-authorities',
102 'catalogue/detail' => '/cataloging.html#bibliographic-records',
103 'catalogue/issuehistory' => '/cataloging.html#item-specific-circulation-history',
104 'catalogue/itemsearch' => '/searching.html#item-searching',
105 'catalogue/moredetail' => '/cataloging.html#item-records',
106 'catalogue/search-history' => '/plugins.html#search-history',
107 'catalogue/search' => '/searching.html',
108 'cataloguing/addbiblio' => '/cataloging.html#bibliographic-records',
109 'cataloguing/addbooks' => '/cataloging.html',
110 'cataloguing/additem' => '/cataloging.html#item-records',
111 'cataloguing/linkitem' => '/cataloging.html#adding-analytic-records',
112 'cataloguing/merge' => '/cataloging.html#merging-records',
113 'cataloguing/moveitem' => '/cataloging.html#moving-items',
114 'circ/article-requests' => '/circulation.html#article-requests',
115 'circ/branchoverdues' => '/circulation.html#overdues-with-fines',
116 'circ/branchtransfers' => '/circulation.html#transfers',
117 'circ/circulation-home' => '/circulation.html',
118 'circ/circulation' => '/circulation.html#check-out-(issuing)',
119 'circ/offline' => '/circulation.html#offline-circulation-in-koha',
120 'circ/on-site_checkouts' => '/circulation.html#pending-on-site-checkouts',
121 'circ/overdue' => '/circulation.html#overdues',
122 'circ/pendingreserves' => '/circulation.html#holds-to-pull',
123 'circ/renew' => '/circulation.html#renewing',
124 'circ/reserveratios' => '/circulation.html#hold-ratios',
125 'circ/returns' => '/circulation.html#check-in-returning',
126 'circ/selectbranchprinter' => '/circulation.html#set-library',
127 'circ/transferstoreceive' => '/circulation.html#transfers-to-receive',
128 'circ/view_holdsqueue' => '/circulation.html#holds-queue',
129 'circ/waitingreserves' => '/circulation.html#holds-awaiting-pickup',
130 'course_reserves/add_items' => '/course_reserves.html',
131 'course_reserves/course-details' => '/course_reserves.html',
132 'course_reserves/course-reserves' => '/course_reserves.html',
133 'course_reserves/course' => '/course_reserves.html#adding-courses',
134 'labels/label-edit-batch' => '/tools.html#batches',
135 'labels/label-edit-layout' => '/tools.html#layouts',
136 'labels/label-edit-profile' => '/tools.html#profiles',
137 'labels/label-edit-template' => '/tools.html#templates',
138 'labels/label-home' => '/tools.html#label-creator',
139 'labels/label-manage' => '/tools.html#layouts',
140 'labels/label-manage' => '/tools.html#templates',
141 'labels/label-manage' => '/tools.html#profiles',
142 'labels/label-manage' => '/tools.html#batches',
143 'labels/spinelabel-home' => '/tools.html#quick-spine-label-creator',
144 'mainpage' => '/',
145 'members/apikeys' => '/webservices.html#api-key-management-interface-for-patrons',
146 'members/boraccount' => '/patrons.html#fines',
147 'members/discharge' => '/patrons.html#patron-discharges',
148 'members/files' => '/patrons.html#files',
149 'members/mancredit' => '/patrons.html#creating-manual-credits',
150 'members/maninvoice' => '/patrons.html#creating-manual-invoices',
151 'members/member-flags' => '/patrons.html#patron-permissions',
152 'members/member-password' => '/patrons.html#editing-patrons',
153 'members/member' => '/patrons.html#patron-search',
154 'members/memberentry' => '/patrons.html#add-a-new-patron',
155 'members/members-home' => '/patrons.html',
156 'members/members-update' => '/patrons.html#managing-patron-self-edits',
157 'members/moremember' => '/patrons.html#patron-information',
158 'members/notices' => '/patrons.html#notices',
159 'members/pay' => '/patrons.html#pay/reverse-fines',
160 'members/paycollect' => '/patrons.html#pay/reverse-fines',
161 'members/purchase-suggestions' => '/patrons.html#purchase-suggestions',
162 'members/readingrec' => '/patrons.html#circulation-history',
163 'members/routing-lists' => '/patrons.html#routing-lists',
164 'members/statistics' => '/patrons.html#statistics',
165 'offline_circ/list' => '/circulation.html#offline-circulation-utilities',
166 'offline_circ/process_koc' => '/circulation.html#upload-offline-circ-file',
167 'patron_lists/lists' => '/tools.html#patron-lists',
168 'patroncards/edit-batch' => '/tools.html#batches',
169 'patroncards/edit-layout' => '/tools.html#layouts',
170 'patroncards/edit-profile' => '/tools.html#profiles',
171 'patroncards/edit-template' => '/tools.html#templates',
172 'patroncards/home' => '/tools.html#patron-card-creator',
173 'patroncards/image-manage' => '/tools.html#manage-images',
174 'patroncards/manage' => '/tools.html#patron-card-creator',
175 'plugins/plugins-home' => '/plugins.html',
176 'plugins/plugins-upload' => '/plugins.html',
177 'reports/acquisitions_stats' => '/reports.html#acquisitions-statistics',
178 'reports/bor_issues_top' => '/reports.html#patrons-with-the-most-checkouts',
179 'reports/borrowers_out' => '/reports.html#patrons-with-no-checkouts',
180 'reports/borrowers_stats' => '/reports.html#patron-statistics',
181 'reports/cat_issues_top' => '/reports.html#most-circulated-items',
182 'reports/catalogue_out' => '/reports.html#items-with-no-checkouts',
183 'reports/catalogue_stats' => '/reports.html#catalog-statistics',
184 'reports/dictionary' => '/reports.html#report-dictionary',
185 'reports/guided_reports' => '/reports.html#custom-reports',
186 'reports/issues_avg_stats' => '/reports.html#average-loan-time',
187 'reports/issues_stats' => '/reports.html#circulation-statistics',
188 'reports/itemslost' => '/reports.html#lost-items',
189 'reports/manager' => '/reports.html#catalog-by-item-type',
190 'reports/reports-home' => '/reports.html',
191 'reports/reserves_stats' => '/reports.html#holds-statistics',
192 'reports/serials_stats' => '/reports.html#serials-statistics',
193 'reserve/request' => '/circulation.html#holds',
194 'reviews/reviewswaiting' => '/tools.html#comments',
195 'rotating_collections/rotatingCollections' => '/tools.html#rotating-collections',
196 'serials/checkexpiration' => '/serials.html#check-serial-expiration',
197 'serials/claims' => '/serials.html#claim-late-serials',
198 'serials/routing' => '/serials.html#create-a-routing-list',
199 'serials/serials-collection' => '/serials.html',
200 'serials/serials-edit' => '/serials.html#receive-issues',
201 'serials/serials-home' => '/serials.html',
202 'serials/subscription-add' => '/serials.html#add-a-subscription',
203 'serials/subscription-detail' => '/serials.html',
204 'serials/subscription-frequencies' => '/serials.html#manage-serial-frequencies',
205 'serials/subscription-numberpatterns' => '/serials.html#manage-serial-numbering-patterns',
206 'suggestion/suggestion' => '/acquisitions.html#managing-suggestions',
207 'tags/list' => '/tools.html#tag-moderation',
208 'tags/review' => '/tools.html#tag-moderation',
209 'tools/batchMod' => '/tools.html#batch-item-deletion',
210 'tools/batch_delete_records' => '/tools.html#batch-record-deletion',
211 'tools/batch_record_modification' => '/tools.html#batch-record-modification',
212 'tools/cleanborrowers' => '/tools.html#patrons-anonymize-bulk-delete',
213 'tools/csv-profiles' => '/tools.html#csv-profiles',
214 'tools/export' => '/tools.html#export-bibliographic-records',
215 'tools/holidays' => '/tools.html#calendar',
216 'tools/import_borrowers' => '/tools.html#patron-import',
217 'tools/inventory' => '/tools.html#inventory-stocktaking',
218 'tools/koha-news' => '/tools.html#news',
219 'tools/letter' => '/tools.html#notices-slips',
220 'tools/manage-marc-import' => '/tools.html#staged-marc-record-management',
221 'tools/marc_modification_templates' => '/tools.html#marc-modification-templates',
222 'tools/modborrowers' => '/tools.html#batch-patron-modification',
223 'tools/overduerules' => '/tools.html#overdue-notice-status-triggers',
224 'tools/picture-upload' => '/tools.html#upload-patron-images',
225 'tools/quotes-upload' => '/tools.html#import-quotes',
226 'tools/quotes' => '/tools.html#quote-of-the-day-(qotd)-editor',
227 'tools/scheduler' => '/tools.html#task-scheduler',
228 'tools/stage-marc-import' => '/tools.html#stage-marc-records-for-import',
229 'tools/tools-home' => '/tools.html',
230 'tools/upload-cover-image' => '/tools.html#upload-local-cover-image',
231 'tools/viewlog' => '/tools.html#log-viewer',
232 'virtualshelves/shelves' => '/lists.html#lists',
235 sub get_url {
236 my ( $url, $preferred_language ) = @_;
237 my $file;
238 if ($url =~ /koha\/(.*)\.pl/) {
239 $file = $1;
240 } else {
241 $file = 'mainpage';
243 $file =~ s/[^a-zA-Z0-9_\-\/]*//g;
245 my $base_url = _get_base_url( $preferred_language );
246 return $base_url . ( exists $mapping->{$file} ? $mapping->{$file} : $mapping->{mainpage} );