Bug 26172: Fix return value for ->register
[koha.git] / Koha / Manual.pm
blobe9551f1aa7942748d58719d80071e512df8fb0cf
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/categories' => '/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/item_circulation_alerts' => '/administration.html#item-circulation-alerts',
83 'admin/items_search_fields' => '/administration.html#item-search-fields',
84 'admin/itemtypes' => '/administration.html#item-types',
85 'admin/koha2marclinks' => '/administration.html#koha-to-marc-mapping',
86 'admin/marc_subfields_structure' => '/administration.html#marc-bibliographic-frameworks',
87 'admin/marctagstructure' => '/administration.html#marc-bibliographic-frameworks',
88 'admin/matching-rules' => '/administration.html#record-matching-rules',
89 'admin/oai_set_mappings' => '/administration.html#oai-sets-configuration',
90 'admin/oai_sets' => '/administration.html#oai-sets-configuration',
91 'admin/patron-attr-types' => '/administration.html#patron-attribute-types',
92 'admin/preferences' => '/systempreferences.html',
93 'admin/smart-rules' => '/administration.html#circulation-and-fine-rules',
94 'admin/sms_providers' => '/administration.html#sms-cellular-providers',
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/set-library' => '/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 'ill/ill-requests' => '/ILL_requests.html',
135 'labels/label-edit-batch' => '/tools.html#label-batches-label',
136 'labels/label-edit-layout' => '/tools.html#label-layouts-label',
137 'labels/label-edit-profile' => '/tools.html#label-profiles-label',
138 'labels/label-edit-range' => '/tools.html#label-creator-label', #FIXME Add when documented
139 'labels/label-edit-template' => '/tools.html#label-templates-label',
140 'labels/label-home' => '/tools.html#label-creator-label',
141 'labels/label-manage' => '/tools.html#label-creator-label',
142 'labels/spinelabel-home' => '/tools.html#quick-spine-label-creator',
143 'mainpage' => '/',
144 'members/apikeys' => '/webservices.html#api-key-management-interface-for-patrons',
145 'members/boraccount' => '/patrons.html#fines',
146 'members/discharge' => '/patrons.html#patron-discharges',
147 'members/files' => '/patrons.html#files',
148 'members/mancredit' => '/patrons.html#creating-manual-credits',
149 'members/maninvoice' => '/patrons.html#creating-manual-invoices',
150 'members/member-flags' => '/patrons.html#patron-permissions',
151 'members/member-password' => '/patrons.html#editing-patrons',
152 'members/member' => '/patrons.html#patron-search',
153 'members/memberentry' => '/patrons.html#add-a-new-patron',
154 'members/members-home' => '/patrons.html',
155 'members/members-update' => '/patrons.html#managing-patron-self-edits',
156 'members/moremember' => '/patrons.html#patron-information',
157 'members/notices' => '/patrons.html#notices',
158 'members/pay' => '/patrons.html#pay/reverse-fines',
159 'members/paycollect' => '/patrons.html#pay/reverse-fines',
160 'members/purchase-suggestions' => '/patrons.html#purchase-suggestions',
161 'members/readingrec' => '/patrons.html#circulation-history',
162 'members/routing-lists' => '/patrons.html#routing-lists',
163 'members/statistics' => '/patrons.html#statistics',
164 'offline_circ/list' => '/circulation.html#offline-circulation-utilities',
165 'offline_circ/process_koc' => '/circulation.html#upload-offline-circ-file',
166 'patron_lists/lists' => '/tools.html#patron-lists',
167 'patroncards/edit-batch' => '/tools.html#batches',
168 'patroncards/edit-layout' => '/tools.html#layouts',
169 'patroncards/edit-profile' => '/tools.html#profiles',
170 'patroncards/edit-template' => '/tools.html#templates',
171 'patroncards/home' => '/tools.html#patron-card-creator',
172 'patroncards/image-manage' => '/tools.html#manage-images',
173 'patroncards/manage' => '/tools.html#patron-card-creator',
174 'plugins/plugins-home' => '/plugins.html',
175 'plugins/plugins-upload' => '/plugins.html',
176 'reports/acquisitions_stats' => '/reports.html#acquisitions-statistics',
177 'reports/bor_issues_top' => '/reports.html#patrons-with-the-most-checkouts',
178 'reports/borrowers_out' => '/reports.html#patrons-with-no-checkouts',
179 'reports/borrowers_stats' => '/reports.html#patron-statistics',
180 'reports/cat_issues_top' => '/reports.html#most-circulated-items',
181 'reports/catalogue_out' => '/reports.html#items-with-no-checkouts',
182 'reports/catalogue_stats' => '/reports.html#catalog-statistics',
183 'reports/dictionary' => '/reports.html#report-dictionary',
184 'reports/guided_reports' => '/reports.html#custom-reports',
185 'reports/issues_avg_stats' => '/reports.html#average-loan-time',
186 'reports/issues_stats' => '/reports.html#circulation-statistics',
187 'reports/itemslost' => '/reports.html#lost-items',
188 'reports/manager' => '/reports.html#catalog-by-item-type',
189 'reports/reports-home' => '/reports.html',
190 'reports/reserves_stats' => '/reports.html#holds-statistics',
191 'reports/serials_stats' => '/reports.html#serials-statistics',
192 'reserve/request' => '/circulation.html#holds',
193 'reviews/reviewswaiting' => '/tools.html#comments',
194 'rotating_collections/rotatingCollections' => '/tools.html#rotating-collections',
195 'serials/checkexpiration' => '/serials.html#check-serial-expiration',
196 'serials/claims' => '/serials.html#claim-late-serials',
197 'serials/routing' => '/serials.html#create-a-routing-list',
198 'serials/serials-collection' => '/serials.html',
199 'serials/serials-edit' => '/serials.html#receive-issues',
200 'serials/serials-home' => '/serials.html',
201 'serials/subscription-add' => '/serials.html#add-a-subscription',
202 'serials/subscription-detail' => '/serials.html',
203 'serials/subscription-frequencies' => '/serials.html#manage-serial-frequencies',
204 'serials/subscription-numberpatterns' => '/serials.html#manage-serial-numbering-patterns',
205 'suggestion/suggestion' => '/acquisitions.html#managing-suggestions',
206 'tags/list' => '/tools.html#tag-moderation',
207 'tags/review' => '/tools.html#tag-moderation',
208 'tools/batchMod' => '/tools.html#batch-item-deletion',
209 'tools/batch_delete_records' => '/tools.html#batch-record-deletion',
210 'tools/batch_record_modification' => '/tools.html#batch-record-modification',
211 'tools/cleanborrowers' => '/tools.html#patrons-anonymize-bulk-delete',
212 'tools/csv-profiles' => '/tools.html#csv-profiles',
213 'tools/export' => '/tools.html#export-bibliographic-records',
214 'tools/holidays' => '/tools.html#calendar',
215 'tools/import_borrowers' => '/tools.html#patron-import',
216 'tools/inventory' => '/tools.html#inventory-stocktaking',
217 'tools/koha-news' => '/tools.html#news',
218 'tools/letter' => '/tools.html#notices-slips',
219 'tools/manage-marc-import' => '/tools.html#staged-marc-record-management',
220 'tools/marc_modification_templates' => '/tools.html#marc-modification-templates',
221 'tools/modborrowers' => '/tools.html#batch-patron-modification',
222 'tools/overduerules' => '/tools.html#overdue-notice-status-triggers',
223 'tools/picture-upload' => '/tools.html#upload-patron-images',
224 'tools/quotes-upload' => '/tools.html#import-quotes',
225 'tools/quotes' => '/tools.html#quote-of-the-day-(qotd)-editor',
226 'tools/scheduler' => '/tools.html#task-scheduler',
227 'tools/stage-marc-import' => '/tools.html#stage-marc-records-for-import',
228 'tools/tools-home' => '/tools.html',
229 'tools/upload-cover-image' => '/tools.html#upload-local-cover-image',
230 'tools/viewlog' => '/tools.html#log-viewer',
231 'virtualshelves/shelves' => '/lists.html#lists',
234 sub get_url {
235 my ( $url, $preferred_language ) = @_;
236 my $file;
237 if ($url =~ /koha\/(.*)\.pl/) {
238 $file = $1;
239 } else {
240 $file = 'mainpage';
242 $file =~ s/[^a-zA-Z0-9_\-\/]*//g;
244 my $base_url = _get_base_url( $preferred_language );
245 return $base_url . ( exists $mapping->{$file} ? $mapping->{$file} : $mapping->{mainpage} );