RT#39638: VoIP Usage cost reporting [bug fixes/cleanup]
[freeside.git] / httemplate / elements / menu.html
1 <script type="text/javascript" src="<%$fsurl%>elements/cssexpr.js"></script>
2
3 % if ( $opt{'position'} eq 'top' ) {
4
5   <script type="text/javascript" src="<%$fsurl%>elements/xmenu.top.js"></script>
6   <link href="<%$fsurl%>elements/xmenu.top.css" type="text/css" rel="stylesheet">
7
8 % } else {  # elsif ( $opt{'position'} eq 'left' ) {
9
10   <script type="text/javascript" src="<%$fsurl%>elements/xmenu.js"></script>
11   <link href="<%$fsurl%>elements/xmenu.css" type="text/css" rel="stylesheet">
12
13 % }
14
15 % unless ( $opt{'nocss'} ) {
16   <link href="<%$fsurl%>elements/freeside.css" type="text/css" rel="stylesheet">
17   <link href="<%$fsurl%>elements/freeside-print.css" type="text/css" rel="stylesheet" media="print">
18 % }
19 <link href="<%$fsurl%>elements/freeside-menu.css" type="text/css" rel="stylesheet">
20
21 <SCRIPT TYPE="text/javascript">
22
23 % my $fs_popup = include( '/elements/popup_link_onclick.html',
24 %                           'action'      => $fsurl.'docs/about.html',
25 %                           'label'       => emt('Freeside'),
26 %                           'style'       => 'color:#999999',
27 %                           'actionlabel' => emt('About'),
28 %                           'width'       => 300,
29 %                           'height'      => 375,
30 %                           'color'       => '#7e0079',
31 %                           #'scrolling'   => 'no',
32 %                       );
33 % $fs_popup =~ s/return false;//;
34   function about_freeside() {
35     <% $fs_popup |n %>
36   }
37
38   webfxMenuImagePath      = "<%$fsurl%>images/";
39   webfxMenuUseHover       = 1;
40   webfxMenuShowTime       = 300;
41   webfxMenuHideTime       = 500;
42
43   var myBar = new WebFXMenuBar;
44
45 % if ( $mobile ) {
46 %   
47 %   my( $subhtml, $submenuname ) = submenu(\%menu, 'Freeside');
48     <% $subhtml |n %>
49     myBar.add(new WebFXMenuButton("Freeside", 
50                                   null,
51                                   null,
52                                   <% $submenuname |n %>));
53 % }
54 % else {
55 %   foreach my $item ( keys %menu ) {
56 %
57 %     my( $url_or_submenu, $tooltip ) = @{ $menu{$item} };
58 %
59 %     if ( ref($url_or_submenu) ) {
60 %
61 %         #warn $item;
62 %
63 %         my( $subhtml, $submenuname ) = submenu($url_or_submenu, $item);
64
65           <% $subhtml |n %>
66           myBar.add(new WebFXMenuButton(<% mt($item) |js_string %>, null, <% mt($tooltip) |js_string %>, <% $submenuname |n %> ));
67
68 %     } else { 
69     
70           myBar.add(new WebFXMenuButton(<% mt($item) |js_string %>, "<% $url_or_submenu %>", <% mt($tooltip) |js_string %> ));
71
72 %     }
73 %   } #foreach $item
74 % } #if $mobile
75
76   myBar.show( null, 'vertical' );
77   myBar.width = 154;
78
79 </SCRIPT>
80
81 <%init>
82 my( %opt ) = @_;
83 my $conf = new FS::Conf;
84 my $fsurl = $opt{'freeside_baseurl'};
85
86 my $mobile = $opt{'mobile'} || 0;
87
88 my $curuser = $FS::CurrentUser::CurrentUser;
89
90 #XXX Active tickets not assigned to a customer
91
92 tie my %report_prospects, 'Tie::IxHash';
93 if ( $curuser->access_right('List prospects') ) {
94   $report_prospects{'List prospects'} = [ $fsurl. 'search/prospect_main.html', '' ];
95   $report_prospects{'Advanced prospect reports'} = [ $fsurl. 'search/report_prospect_main.html', '' ];
96 }
97 $report_prospects{'separator'} = ''
98   if $curuser->access_right('List prospects')
99   && $curuser->access_right('List contacts');
100 $report_prospects{'Prospect contacts'} = [ $fsurl. 'search/report_contact.html?link=prospect_main', '' ]
101   if $curuser->access_right('List contacts');
102
103 tie my %report_quotations, 'Tie::IxHash',
104   'List quotations' => [ $fsurl. 'search/quotation.html', '' ],
105   'Advanced quotation reports' => [ $fsurl. 'search/report_quotation.html', '' ],
106 ;
107
108 tie my %report_customers_lists, 'Tie::IxHash',
109   'by customer number' => [ $fsurl. 'search/cust_main.cgi?browse=custnum', '' ],
110   'by last name' => [ $fsurl. 'search/cust_main.cgi?browse=last', '' ],
111   'by company name' => [ $fsurl. 'search/cust_main.cgi?browse=company', '' ],
112 ;
113 $report_customers_lists{'by active trouble tickets'} = [ $fsurl. 'search/cust_main.cgi?browse=tickets', '' ]
114   if $conf->config('ticket_system');
115 $report_customers_lists{'with USPS-unvalidated addresses'} = [ $fsurl. 'search/cust_main.cgi?browse=uspsunvalid', '' ]
116   if $conf->config('usps_webtools-userid') && $conf->config('usps_webtools-password');
117
118 tie my %report_customers, 'Tie::IxHash';
119 $report_customers{'List customers'} = [ \%report_customers_lists, 'List customers' ]
120   if $curuser->access_right('List all customers');
121 $report_customers{'Zip code distribution'}     = [ $fsurl. 'search/report_cust_main-zip.html', 'Zip codes by number of customers' ];
122 $report_customers{'Customer signup report'}    = [ $fsurl. 'graph/report_cust_signup.html',    'New customer signups by date' ];
123 $report_customers{'Customer churn report'} =  [ $fsurl.'graph/report_cust_churn.html', 'New customers, suspensions, and cancellations summary' ];
124 $report_customers{'Signup date report'}        = [ $fsurl. 'graph/report_signupdate.html',     'Signup date report (by date of signup)' ];
125 $report_customers{'Advanced customer reports'} = [ $fsurl. 'search/report_cust_main.html',     'by status, signup date, agent, etc.' ]
126   if $curuser->access_right('Advanced customer search');
127 if ( $curuser->access_right('List contacts') ) {
128   $report_customers{'separator'} = '';
129   $report_customers{'Customer contacts'} = [ $fsurl. 'search/report_contact.html?link=cust_main' ];
130   $report_customers{'Customer stored payment information'} = [ $fsurl. 'search/report_cust_payby.html' ];
131 }
132
133 tie my %report_invoices_open, 'Tie::IxHash',
134   'All open invoices' => [ $fsurl.'search/cust_bill.html?OPEN_date', 'All invoices with an unpaid balance' ],
135   '15 day open invoices' => [ $fsurl.'search/cust_bill.html?OPEN15_date', 'Invoices 15 days or older with an unpaid balance' ],
136   '30 day open invoices' => [ $fsurl.'search/cust_bill.html?OPEN30_date', 'Invoices 30 days or older with an unpaid balance' ],
137   '60 day open invoices' => [ $fsurl.'search/cust_bill.html?OPEN60_date', 'Invoices 60 days or older with an unpaid balance' ],
138   '90 day open invoices' => [ $fsurl.'search/cust_bill.html?OPEN90_date', 'Invoices 90 days or older with an unpaid balance' ],
139   '120 day open invoices' => [ $fsurl.'search/cust_bill.html?OPEN120_date', 'Invoices 120 days or older with an unpaid balance' ],
140 ;
141
142 tie my %report_invoices, 'Tie::IxHash',
143   'Open invoices' => [ \%report_invoices_open, 'Open invoices' ],
144   'All invoices'  => [ $fsurl. 'search/cust_bill.html?date', 'List all invoices' ],
145   'Advanced invoice reports' => [ $fsurl.'search/report_cust_bill.html', 'by agent, date range, etc.' ],
146   'separator'     => '',
147   'Line items'    => [ $fsurl. 'search/report_cust_bill_pkg.html', 'Individual line item detail' ],
148   'separator'     => '',
149   'Voided invoices' => [ $fsurl.'search/report_cust_bill_void.html', 'Search for voided invoices' ],
150
151 ;
152
153 tie my %report_discounts, 'Tie::IxHash',
154   'Discount graph'  => [ $fsurl. 'graph/report_cust_bill_pkg_discount.html', 'Discount overview per month' ],
155   'Discount detail' => [ $fsurl.'search/report_cust_bill_pkg_discount.html', 'Discount report (by employee and/or date range)' ],
156   #awful name
157   'Package discounts' => [ $fsurl.'search/report_cust_pkg_discount.html', 'Active/inactive discounts by package' ],
158 ;
159
160 tie my %report_services, 'Tie::IxHash';
161 if ( $curuser->access_right('Configuration') ) {
162   $report_services{'Service definitions'} =  [ $fsurl.'browse/part_svc.cgi?orderby=active', 'Service definitions by number of active packages' ];
163   $report_services{'separator'} =  '';
164 }
165
166 if ( $curuser->access_right('List services') ) {
167   $report_services{'Unprovisioned services'} =  [ $fsurl.'search/report_unprovisioned_services.html', 'Unprovisioned services' ];
168   $report_services{'separator2'} =  '';
169 }
170
171 foreach my $svcdb ( FS::part_svc->svc_tables() ) {
172
173   my $name =        "FS::$svcdb"->table_info->{'name_plural'}
174              || PL( "FS::$svcdb"->table_info->{'name'}        );
175   my $lcname =  "FS::$svcdb"->table_info->{'lcname_plural'} || lc($name);
176   my $lcsname = lc("FS::$svcdb"->table_info->{'name'});
177   my $longname = "FS::$svcdb"->table_info->{'longname_plural'} || $name;
178   my $lclongname = lc($longname);
179   my $sorts = "FS::$svcdb"->table_info->{'sorts'} || [ 'svcnum' ];
180   $sorts = [ $sorts ] unless ref($sorts);
181   my %svc_url = ( 'm'      => $m,
182                   'action' => 'search',
183                   'svcdb'  => $svcdb,
184                 );
185
186   tie my %report_svc, 'Tie::IxHash';
187
188   foreach my $sort ( @$sorts ) {
189
190     my $field_info = FS::part_svc->svc_table_fields($svcdb)->{$sort};
191     my $label = $field_info->{'label_sort'} || 'by '.$field_info->{'label'};
192
193     my $title = "All $lcname";
194     $title .= " $label"
195       if scalar(@$sorts) > 1;
196
197     $report_svc{$title} =
198       [ svc_url( %svc_url, 'query' => "magic=all;sortby=$sort" ),
199         '',
200       ];
201   }
202
203   if ( $svcdb eq 'svc_acct' ) {
204
205     $report_svc{"All $lcname never logged in"} = 
206       [ svc_url( %svc_url, 'query' => "magic=nologin;sortby=svcnum" ),
207         '',
208       ];
209
210   } elsif ( $svcdb eq 'svc_phone' ) {
211
212     $report_svc{"${name}' total usage by time period"} = 
213       [ $fsurl. 'search/report_svc_phone_usage.html',
214         'Total usage (minutes, and amount billed) for the specified time period, per phone number.',
215       ];
216     $report_svc{"${name} by state"} =
217       [ $fsurl. 'search/phone_state.html',
218         'Current or historical phone services broken down by state.',
219       ];
220
221   }
222
223   if ( $curuser->access_right('View/link unlinked services') ) {
224     $report_svc{"Unlinked $lcname"} = 
225       [ svc_url( %svc_url, 'query' => "magic=unlinked;sortby=". $sorts->[0] ),
226         "Pre-Freeside $lcname without a customer record",
227       ];
228   }
229
230   if ( $curuser->access_right("Services: $name: Advanced search")
231     && $svcdb =~ /^svc_(acct|broadband|hardware|phone|fiber)$/ ) {
232
233     $report_svc{"Advanced $lcsname reports"} = 
234       [ $fsurl."search/report_$svcdb.html", '' ]
235   }
236
237   if ( $svcdb eq 'svc_phone' ) {
238
239     $report_svc{"Phone number (DID) availability"} =
240       [ $fsurl."search/report_phone_avail.html", '' ];
241     $report_svc{"Inventory/Provisioning Status"} =
242       [ $fsurl."search/phone_inventory_provisioned.html", '' ];
243
244   } elsif ( $svcdb eq 'svc_dsl' ) {
245
246     $report_svc{'Qualifications'} = [ $fsurl. 'search/qual.cgi', #XXX qual.html
247                                       '',
248                                     ];
249
250   }
251
252   $report_services{$name} = [ \%report_svc, $longname ]
253     if $curuser->access_right("Services: $name");
254
255 }
256
257 tie my %report_packages, 'Tie::IxHash';
258 $report_packages{'Package definitions (by # active)'} =  [ $fsurl.'browse/part_pkg.cgi?active=1', 'Package definitions by number of active packages' ]
259   if    $curuser->access_right('Edit package definitions')
260      || $curuser->access_right('Edit global package definitions');
261 $report_packages{'Package costs'} = [ $fsurl.'graph/report_cust_pkg_cost.html', 'Package setup and recurring costs graph' ]
262   if $curuser->access_right('Financial reports');
263 $report_packages{'separator'} =  ''
264   if keys %report_packages;
265 if ( $curuser->access_right('Financial reports') ) {
266   $report_packages{'Package churn'} =  [ $fsurl.'graph/report_cust_pkg.html', 'Orders, suspensions and cancellations summary graph' ];
267   $report_packages{'separator2'} =  '';
268 }
269 $report_packages{'All customer packages'} =  [ $fsurl.'search/cust_pkg.cgi?pkgnum', 'List all customer packages', ];
270 $report_packages{'Package summary'} = [ $fsurl.'search/cust_pkg_summary.html', 'Show package sales summary', ]
271   if $curuser->access_right('Summarize packages');
272 $report_packages{'Suspended customer packages'} =  [ $fsurl.'search/cust_pkg.cgi?magic=suspended', 'List suspended packages' ];
273 $report_packages{'Suspension summary'} = [ $fsurl.'search/cust_pkg_susp.html', 'Show suspension activity', ]
274   if $curuser->access_right('Summarize packages');
275 $report_packages{'Customer packages with unconfigured services'} =  [ $fsurl.'search/cust_pkg.cgi?APKG_pkgnum', 'List packages which have provisionable services' ];
276 $report_packages{'FCC Form 477'} =  [ $fsurl.'search/report_477.html' ]
277   if $conf->exists('part_pkg-show_fcc_options');
278 $report_packages{'Advanced package reports'} =  [ $fsurl.'search/report_cust_pkg.html', 'by agent, date range, status, package definition' ];
279
280 tie my %report_inventory, 'Tie::IxHash',
281   'Inventory by agent' => [ $fsurl.'search/report_agent_inventory.html', '' ],
282   'Inventory activity' => [ $fsurl.'search/report_h_inventory_item.html', '' ],
283 ;
284
285 tie my %report_rating, 'Tie::IxHash';
286 $report_rating{'RADIUS sessions'} = [ $fsurl.'search/sqlradius.html', '' ]
287   if $curuser->access_right("Usage: RADIUS sessions");
288 $report_rating{'RADIUS data usage'} = [ $fsurl.'search/report_sqlradius_usage.html', '' ]
289   if $curuser->access_right("Usage: RADIUS sessions");
290 $report_rating{'Call Detail Records (CDRs)'} = [ $fsurl.'search/report_cdr.html', '' ]
291   if $curuser->access_right("Usage: Call Detail Records (CDRs)");
292 $report_rating{'Unrateable CDRs'} = [ $fsurl.'search/cdr.html?freesidestatus=failed;cdrbatchnum=_ALL_' ]
293   if $curuser->access_right("Usage: Unrateable CDRs");
294 $report_rating{'Customer CDRs Profit/Loss'} = [ $fsurl.'search/report_customer_cdr_profit.html', 'Profit/loss from customer CDRs' ]
295   if $curuser->access_right('Financial reports');
296 if ( $curuser->access_right("Usage: Time worked") ) {
297   $report_rating{'Time worked'} = [ $fsurl.'search/report_rt_transaction.html', '' ];
298   $report_rating{'Time worked summary per ticket'} = [ $fsurl.'search/report_rt_ticket.html', '' ];
299   $report_rating{'Time worked summary per customer'} = [ $fsurl.'search/report_rt_cust.html', '' ];
300 }
301
302 tie my %report_ticketing_statistics, 'Tie::IxHash',
303   'Tickets per day per Queue'         => [ $fsurl.'rt/RTx/Statistics/CallsQueueDay', 'View the number of tickets created, resolved or deleted in a specific Queue, over the requested period of days' ],
304   'Ticket status by Queue'            => [ $fsurl.'rt/RTx/Statistics/OpenStalled', 'View numbers of new, open and stalled tickets in a selected Queue' ],
305   'Tickets per day (multiple Queues)' => [ $fsurl.'rt/RTx/Statistics/CallsMultiQueue', 'View tickets created, resolved or deleted on in one or more Queues over a specified time period' ],
306   'Tickets per Day of Week'           => [ $fsurl.'rt/RTx/Statistics/DayOfWeek', 'View trends showing when tickets are created, resolved or deleted' ],
307   'Time to resolve'                   => [ $fsurl.'rt/RTx/Statistics/Resolution', 'View how long tickets take to be resolved by Queue' ],
308   'Time to resolve (scatter graph)'   => [ $fsurl.'rt/RTx/Statistics/TimeToResolve', 'View a detailed scatter graph of time to resolve tickets by Queue' ],
309 ;
310
311 tie my %report_ticketing, 'Tie::IxHash',
312 # fix TimeToResolve extension?  or redo in a more modern way?
313 #  'Resolved by owner'       => [ $fsurl.'rt/Tools/Reports/ResolvedByOwner.html', '' ],
314 #  'Resolved in date range'  => [ $fsurl.'rt/Tools/Reports/ResolvedByDates.html', '' ],
315 #  'Created in date range'   => [ $fsurl.'rt/Tools/Reports/CreatedByDates.html', '' ],
316 #  'separator'               => '',
317   'Statistics'              => [ \%report_ticketing_statistics, '' ],
318   'separator2'              => '',
319   'Advanced ticket reports' => [ $fsurl.'rt/Search/Build.html?NewQuery=1', 'List tickets by any criteria' ],
320 ;
321
322 tie my %report_bill_event, 'Tie::IxHash',
323   'All billing events' => [ $fsurl.'search/report_cust_event.html', 'All billing events for a date range' ],
324   'Billing event errors' => [ $fsurl.'search/report_cust_event.html?failed=1', 'Failed credit cards, processor or printer problems, etc.' ],
325 ;
326
327 tie my %report_payments, 'Tie::IxHash',
328   'Payments' => [ $fsurl.'search/report_cust_pay.html', 'Payment report (by type and/or date range)' ],
329   'Payment application detail' => [ $fsurl.'search/report_cust_bill_pay_pkg.html', 'Line item application detail' ],
330 ;
331 $report_payments{'Pending Payments'} = [ $fsurl.'search/cust_pay_pending.html?magic=_date;statusNOT=done', 'Pending real-time payments' ]
332   if $curuser->access_right('View customer pending payments');
333 $report_payments{'Unapplied Payments'} = [ $fsurl.'search/report_cust_pay.html?unapplied=1', 'Unapplied payment report (by type and/or date range)' ];
334 $report_payments{'Voided Payments'} = [ $fsurl.'search/report_cust_pay.html?void=1', 'Voided payment report (by type and/or date range)' ]
335   if $curuser->access_right('View customer pending payments');
336 $report_payments{'Payment Batches'} = [ $fsurl.'search/pay_batch.html', 'Payment batches (by status and/or date range)' ]
337   if $conf->exists('batch-enable') || $conf->config('batch-enable_payby');
338 $report_payments{'Unapplied Payment Aging'} = [ $fsurl.'search/report_unapplied_cust_pay.html', 'Unapplied payment aging report' ];
339 $report_payments{'Deleted Payments / Payment history table'} = [ $fsurl.'search/report_h_cust_pay.html', 'Deleted payments / payment history table' ]
340   if $conf->exists('payment-history-report');
341
342 tie my %report_credits, 'Tie::IxHash',
343   'Credit Report' => [ $fsurl.'search/report_cust_credit.html', 'Credit report (by employee and/or date range)' ],
344   'Credit package source detail' => [ $fsurl.'search/report_cust_credit_source_bill_pkg.html', 'Line-item detail for triggered package credits' ],
345   'Credit application detail' => [ $fsurl.'search/report_cust_credit_bill_pkg.html', 'Line item application detail' ],
346   'Unapplied Credits' => [ $fsurl.'search/report_cust_credit.html?unapplied=1', 'Unapplied credit report (by type and/or date range)' ],
347   'Voided Credits' => [ $fsurl.'search/report_cust_credit_void.html', 'Voided credit report (by employee and/or date range)' ],
348 ;
349
350 tie my %report_refunds, 'Tie::IxHash',
351   'Refund Report' => [ $fsurl.'search/report_cust_refund.html', 'Refund report (by type and/or date range)' ],
352   'Unapplied Refunds' => [ $fsurl.'search/report_cust_refund.html?unapplied=1', 'Unapplied refund report (by type and/or date range)' ],
353 ;
354
355 tie my %report_sales, 'Tie::IxHash',
356   'Sales, Credits and Receipts' => [ $fsurl.'graph/report_money_time.html', 'Sales, credits and receipts summary graph' ],
357   'Daily Sales, Credits and Receipts' => [ $fsurl.'graph/report_money_time_daily.html', 'Sales, credits and receipts (broken down by day) summary graph' ],
358   'Sales Report' => [ $fsurl.'graph/report_cust_bill_pkg.html', 'Sales report and graph (by agent, package class and/or date range)' ],
359   'Rated Call Sales Report' => [ $fsurl.'graph/report_cust_bill_pkg_detail.html', 'Sales report and graph (by agent, package class, usage class and/or date range)' ],
360   'Sales with Advertising Source' => [ $fsurl.'search/report_cust_bill_pkg_referral.html' ],
361 ;
362
363 tie my %report_commissions, 'Tie::IxHash',
364   'Agent' => [ $fsurl.'search/report_agent_commission.html' ],
365   'Agent per package' => [ $fsurl.'search/report_agent_commission_pkg.html' ],
366   'Sales Person' => [ $fsurl.'search/report_sales_commission.html' ],
367   'Sales Person per package' => [ $fsurl.'search/report_sales_commission_pkg.html' ],
368   'Employee' => [ $fsurl.'search/report_employee_commission.html', '' ]
369 ;
370
371 tie my %report_financial, 'Tie::IxHash';
372 if( $curuser->access_right('Financial reports') ) {
373
374   %report_financial = (
375     'Sales'       => [ \%report_sales, 'Sales reports', ],
376     'Commissions' => [ \%report_commissions, 'Commission reports', ],
377     'Credits'     => [ \%report_credits, 'Credit reports', ],
378     'Refunds'     => [ \%report_refunds, 'Refund reports', ],
379   );
380   $report_financial{'A/R Aging'} = [ $fsurl.'search/report_receivables.html', 'Accounts Receivable Aging report' ];
381   $report_financial{'Prepaid Income'} = [ $fsurl.'search/report_prepaid_income.html', 'Prepaid income (unearned revenue)  report' ];
382
383   my $taxproducts = $conf->config('tax_data_vendor');
384   $report_financial{'Tax Liability'. ($taxproducts ? ' (internal tax data)' : '')} = [ $fsurl.'search/report_tax.html', 'Tax liability report (internal tax data)' ];
385   $report_financial{'Tax Liability (vendor tax data)'} = [ $fsurl.'search/report_newtax.html', 'Tax liability report (vendor tax data)' ]
386     if $taxproducts;
387
388   $report_financial{'Monthly Sales and Taxes'} = [$fsurl.'search/tax_sales.html', 'Monthly sales and taxes report'];
389
390   # most sites don't need this but there isn't really a config to enable it
391   $report_financial{'E911 Fee Summary'} = [ $fsurl.'search/report_e911.html', 'E911 fee summary' ];
392
393   $report_financial{'Customer Accounting Summary'} = [ $fsurl.'search/report_customer_accounting_summary.html', 'Customer accounting summary report' ];
394
395 } elsif($curuser->access_right('Receivables report')) {
396
397   $report_financial{'A/R Aging'} = [ $fsurl.'search/report_receivables.html', 'Accounts Receivable Aging report' ];
398
399 } # else $report_financial contains nothing.
400
401 tie my %report_payable, 'Tie::IxHash',
402   'Payables summary' => [ $fsurl. 'search/report_vend_main.html', 'Payables summary by vendor' ],
403   'Payables detail' => [ $fsurl. 'search/report_vend_bill.html' ],
404 ;
405
406 tie my %report_logs, 'Tie::IxHash';
407 $report_logs{'Billing events'} =  [ \%report_bill_event, 'Billing events' ]
408   if $curuser->access_right('Billing event reports');
409 $report_logs{'Credit limit incidents'} = [ $fsurl.'search/report_cust_main_credit_limit.html', '' ]
410   if $curuser->access_right('List rating data');
411 $report_logs{'Employee activity'} = [ $fsurl.'search/report_employee_audit.html', '' ]
412   if $curuser->access_right('Employees: Audit Report');
413 $report_logs{'System log'} = [ $fsurl.'search/log.html', 'View system events and debugging information.' ],
414   if $curuser->access_right('View system logs')
415   || $curuser->access_right('Configuration');
416 $report_logs{'Outgoing messages'} = [ $fsurl.'search/cust_msg.html', 'View outgoing message log' ]
417   if $curuser->access_right('View email logs')
418   || $curuser->access_right('Configuration');
419
420 tie my %report_menu, 'Tie::IxHash';
421 $report_menu{'Prospects'}      = [ \%report_prospects, 'Prospect reports' ]
422   if $curuser->access_right('List prospects')
423   || $curuser->access_right('List contacts');
424 $report_menu{'Quotations'}     = [ \%report_quotations, 'Quotation reports' ]
425   if $curuser->access_right('List quotations');
426 $report_menu{'Customers'}      = [ \%report_customers, 'Customer reports'  ]
427   if $curuser->access_right('List customers')
428   || $curuser->access_right('List contacts');
429 $report_menu{'Invoices'}       =  [ \%report_invoices,  'Invoice reports'   ]
430   if $curuser->access_right('List invoices');
431 $report_menu{'Discounts'}      =  [ \%report_discounts, 'Discount reports'  ]
432   if $curuser->access_right('Financial reports');
433 $report_menu{'Payments'}       =  [ \%report_payments,  'Payment reports'   ]
434   if $curuser->access_right('Financial reports');
435 $report_menu{'Packages'}       =  [ \%report_packages,  'Package reports'   ]
436   if $curuser->access_right('List packages');
437 $report_menu{'Services'}       =  [ \%report_services,  'Services reports'  ]
438   if $curuser->access_right('List services');
439 $report_menu{'Inventory'}      =  [ \%report_inventory,  'Inventory reports'  ]
440   if $curuser->access_right('Configuration'); #XXX List inventory?
441 $report_menu{'Usage'}          =  [ \%report_rating,    'Usage reports'  ]
442   if $curuser->access_right('List rating data');
443 $report_menu{'Tickets'}        = [ \%report_ticketing, 'Ticket reports' ]
444   if $conf->config('ticket_system')
445   ;#&& FS::TicketSystem->access_right(\%session, 'Something');
446 $report_menu{'Financial (Receivables)'} = [ \%report_financial, 'Financial reports (Receivables)' ]
447   if $curuser->access_right('Financial reports') 
448   or $curuser->access_right('Receivables report');
449 $report_menu{'Financial (Payables)'} = [ \%report_payable, 'Financial reports (Payables)' ]
450   if $curuser->access_right('Financial reports');
451
452 $report_menu{'Logs'}           = [ \%report_logs, 'System and email logs' ]
453   if (keys %report_logs); # empty if the user has no rights to it
454 $report_menu{'SQL Query'}      = [ $fsurl.'search/report_sql.html', 'SQL Query']
455   if $curuser->access_right('Raw SQL');
456
457 tie my %tools_customers, 'Tie::IxHash', ();
458 $tools_customers{'Appointments'} = [ $fsurl.'rt/Search/Schedule.html?LengthMin=0', 'View appointment schedule' ]
459   if $curuser->access_right('View appointments');
460 $tools_customers{'Attachments'} = [ $fsurl.'browse/cust_attachment.html', 'View customer attachments' ]
461   if !$conf->config('disable_cust_attachment') and $curuser->access_right('View attachments') and $curuser->access_right('Browse attachments');
462 $tools_customers{'Customer email settings'} = [ $fsurl.'misc/manage_cust_email.html' ]
463   if $curuser->access_right('Edit customer');
464
465 tie my %tools_billing, 'Tie::IxHash', ();
466 $tools_billing{'Quick payment entry'} =  [ $fsurl.'misc/batch-cust_pay.html', 'Enter multiple payments in a batch' ]
467   if $curuser->access_right('Post payment batch');
468 $tools_billing{'Process payment batches'} = [ $fsurl.'search/pay_batch.cgi?magic=_date;open=1;intransit=1', 'Process credit card and electronic check batches' ]
469   if ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
470      && $curuser->access_right('Process batches');
471 $tools_billing{'Download invoice batches'} = [ $fsurl.'search/bill_batch.cgi' ]
472   if $curuser->access_right('Process invoice batches')
473   || $curuser->access_right('Process global invoice batches')
474   || $curuser->access_right('Configuration'); #XXX remove in 2.5
475   #now there's a standalone event#if $conf->exists('invoice_print_pdf');
476
477 tie my %tools_importing, 'Tie::IxHash',
478   'Customers'            => [ $fsurl.'misc/cust_main-import.cgi', '' ],
479   'Package definitions'  => [ $fsurl.'misc/part_pkg-import.html', '' ],
480   'Customer packages'    => [ $fsurl.'misc/cust_pkg-import.html', '' ],
481   'Customer comments'    => [ $fsurl.'misc/cust_main_note-import.html', '' ],
482   'One-time charges'     => [ $fsurl.'misc/cust_main-import_charges.cgi', '' ],
483   'Payments'             => [ $fsurl.'misc/cust_pay-import.cgi', '' ],
484   'Credits'              => [ $fsurl.'misc/cust_credit-import.html', '' ],
485   'Phone numbers (DIDs)' => [ $fsurl.'misc/phone_avail-import.html', '' ],
486   'Call Detail Records (CDRs)' => [ $fsurl.'misc/cdr-import.html', '' ],
487 ;
488 if ( $conf->config('tax_data_vendor') eq 'cch' ) {
489   if ( $conf->exists('taxdatadirectdownload') ) {
490       $tools_importing{'Tax rates from vendor site'} =
491       [ $fsurl.'misc/tax-fetch_and_import.cgi', '' ];
492   } else {
493     $tools_importing{'Tax rates from CSV files'} =
494       [ $fsurl.'misc/tax-import.cgi', '' ];
495   }
496 }
497
498 tie my %tools_misc, 'Tie::IxHash', ();
499 $tools_misc{'Bulk DID Orders'} =  [ $fsurl.'browse/did_order.html', 'View/manage bulk DID orders' ]
500   if $curuser->access_right('Import');
501 $tools_misc{'Business card scan'} = [ $fsurl.'edit/prospect_main-upload.html' ]
502   if $curuser->access_right('New prospect');
503 $tools_misc{'Time Queue'} =  [ $fsurl.'search/report_timeworked.html', 'View pending support time' ]
504   if $curuser->access_right('Time queue');
505
506 #tie my %tools_exporting, 'Tie::IxHash',
507 #  'Download database dump' => [ $fsurl. 'misc/dump.cgi', '' ],
508 #;
509
510 tie my %tools_ticketing_articles, 'Tie::IxHash',
511   'Overview' => [ $fsurl.'rt/Articles/index.html', '' ],
512   'Search'   => [ $fsurl.'rt/Articles/Article/Search.html', '' ],
513   'Topics'   => [ $fsurl.'rt/Articles/Topics.html', '' ],
514 ;
515
516 tie my %tools_ticketing, 'Tie::IxHash',
517   'Articles'     => [ \%tools_ticketing_articles, '' ],
518   'My Day'       => [ $fsurl.'rt/Tools/MyDay.html', '' ],
519   'My Reminders' => [ $fsurl.'rt/Tools/MyReminders.html', '' ],
520   'Offline'      => [ $fsurl.'rt/Tools/Offline.html', '' ],
521   'Approval'     => [ $fsurl.'rt/Approvals/', '' ],
522 ;
523 $tools_ticketing{'Cron Tool'} = [ $fsurl.'rt/Developer/CronTool/', '' ]
524   if $conf->exists('rt-crontool');
525
526 tie my %tools_system, 'Tie::IxHash', ();
527 $tools_system{'Status'} = [ $fsurl.'view/Status.html', 'System status' ]
528   if $curuser->access_right('Configuration'); # 'View system status');
529 $tools_system{'Job Queue'} =  [ $fsurl.'search/queue.html', 'View pending job queue' ]
530   if $curuser->access_right('Job queue');
531
532 tie my %tools_menu, 'Tie::IxHash', ();
533 $tools_menu{'Customers'} = [ \%tools_customers, 'Customer tools' ]
534   if keys %tools_customers;
535 $tools_menu{'Billing'} = [ \%tools_billing, 'Payment and invoice tools' ]
536   if keys %tools_billing;
537 $tools_menu{'Ticketing'} = [ \%tools_ticketing, 'Ticketing tools' ]
538   if $conf->config('ticket_system');
539 $tools_menu{'Miscellaneous'} = [ \%tools_misc, '' ]
540   if keys %tools_misc;
541 $tools_menu{'Importing'} =  [ \%tools_importing, 'Import tools' ]
542   if $curuser->access_right('Import');
543 #$tools_menu{'Exporting'} =  [ \%tools_exporting, 'Export tools' ]
544 #  if $curuser->access_right('Export');
545 $tools_menu{'System'} = [ \%tools_system, 'System tools' ]
546   if keys %tools_menu;
547
548 tie my %config_employees, 'Tie::IxHash',
549   'Employees' => [ $fsurl.'browse/access_user.html', 'Setup internal users' ],
550   'Employee groups' => [ $fsurl.'browse/access_group.html', 'Employee groups allow you to control access to the backend' ],
551   'Installer availability' => [ $fsurl.'browse/sched_item.html', 'Installer availability' ],
552 ;
553
554 tie my %config_dialup, 'Tie::IxHash',
555   'Access numbers' => [ $fsurl.'browse/svc_acct_pop.cgi', 'Points of Presence' ],
556 ;
557
558 tie my %config_broadband, 'Tie::IxHash',
559   'Towers'         => [ $fsurl.'browse/tower.html', 'Towers and sectors' ],
560   'Routers'        => [ $fsurl.'browse/router.cgi', 'Broadband access routers' ],
561   'Address blocks' => [ $fsurl.'browse/addr_block.cgi', 'Manage address blocks and block assignments to broadband routers' ],
562 ;
563 if ( $curuser->access_right('Broadband global configuration') ) {
564   $config_broadband{'Address ranges'} = 
565                       [ $fsurl.'browse/addr_range.html', 'Designate special address ranges' ];
566 }
567
568 tie my %config_phone, 'Tie::IxHash',
569   'View/Edit phone device types' => [ $fsurl.'browse/part_device.html', 'Phone device types' ],
570   'View/Edit bulk DID vendors' => [ $fsurl.'browse/did_vendor.html', 'Bulk DID vendors' ],
571   'View/Edit Carriers' => [ $fsurl.'browse/cdr_carrier.html', 'Carriers' ],
572 ;
573
574 tie my %config_radius, 'Tie::IxHash',
575   'RADIUS Groups' => [ $fsurl.'browse/radius_group.html', 'Manage RADIUS groups' ],
576   'RADIUS Clients' => [ $fsurl.'browse/nas.html', 'Manage RADIUS clients' ],
577 ;
578
579 tie my %config_cable, 'Tie::IxHash',
580   'Cable providers' => [ $fsurl.'browse/cable_provider.html', '' ],
581   'Cable modem models' => [ $fsurl.'browse/cable_model.html', '' ],
582 ;
583
584 tie my %config_alarm, 'Tie::IxHash',
585   'Alarm system vendors'   => [ $fsurl.'browse/alarm_system.html', '' ],
586   'Alarm system types'     => [ $fsurl.'browse/alarm_type.html', '' ],
587   'Alarm central stations' => [ $fsurl.'browse/alarm_station.html', '' ],
588 ;
589
590 tie my %config_conferencing, 'Tie::IxHash',
591   'Conferencing types' => [ $fsurl.'browse/conferencing_type.html', '' ],
592   'Quality levels'     => [ $fsurl.'browse/conferencing_quality.html', '' ],
593 ;
594
595 tie my %config_circuit, 'Tie::IxHash',
596   'Circuit types'     => [ $fsurl.'browse/circuit_type.html',         '' ],
597   'Circuit providers' => [ $fsurl.'browse/circuit_provider.html',     '' ],
598   'Termination types' => [ $fsurl.'browse/circuit_termination.html',  '' ],
599 ;
600
601 tie my %config_fiber, 'Tie::IxHash',
602   'OLTs' => [ $fsurl.'browse/fiber_olt.html', '' ],
603 ;
604
605 tie my %config_export_svc, 'Tie::IxHash', ();
606 if ( $curuser->access_right('Configuration') ) {
607   $config_export_svc{'Service definitions'} = [ $fsurl.'browse/part_svc.cgi', 'Services are items you offer to your customers' ];
608   $config_export_svc{'Service classes'} = [ $fsurl.'browse/part_svc_class.html', 'Services classes are user-defined, informational types for services' ];
609   $config_export_svc{'Service dependencies'} = [ $fsurl.'browse/part_svc_link.html', 'Services depencies define rules between service definitions' ];
610   $config_export_svc{'Provisioning exports'} = [ $fsurl.'browse/part_export.cgi', 'Provisioning services to external machines, databases and APIs' ];
611 }
612 $config_export_svc{'Dialup'}  = [ \%config_dialup, ''    ]
613   if $curuser->access_right('Dialup configuration');
614 $config_export_svc{'Wireless broadband'} = [ \%config_broadband, ''    ]
615   if $curuser->access_right('Broadband configuration');
616 $config_export_svc{'Phone'}  = [ \%config_phone, ''    ]
617   if $curuser->access_right('Configuration');
618 $config_export_svc{'RADIUS'} = [ \%config_radius, '' ]
619   if $curuser->access_right('Configuration');
620 $config_export_svc{'Cable'} = [ \%config_cable, '' ]
621   if $curuser->access_right('Configuration');
622 $config_export_svc{'Conferencing'} = [ \%config_conferencing, '' ]
623   if $curuser->access_right('Configuration');
624 $config_export_svc{'Alarm'} = [ \%config_alarm, '' ]
625   if $curuser->access_right(['Alarm configuration', 'Alarm global configuration']);
626 $config_export_svc{'Circuits'} = [ \%config_circuit, '' ]
627   if $curuser->access_right('Configuration');
628 $config_export_svc{'Fiber'} = [ \%config_fiber, '' ]
629   if $curuser->access_right('Configuration');
630 $config_export_svc{'Hardware types'} = [ $fsurl.'browse/hardware_class.html', 'Set up hardware type catalog' ]
631   if $curuser->access_right('Configuration');
632
633 tie my %config_pkg_reason, 'Tie::IxHash',
634   'Cancel reasons' => [ $fsurl.'browse/reason_type.html?class=C', 'Cancel reasons explain why a service was cancelled.' ],
635   'Suspend reasons' => [ $fsurl.'browse/reason_type.html?class=S', 'Suspend reasons explain why a service was suspended.' ],
636 ;
637
638 tie my %config_pkg, 'Tie::IxHash', ();
639 $config_pkg{'Package definitions'} = [ $fsurl.'browse/part_pkg.cgi', 'One or more services are grouped together into a package and given pricing information. Customers purchase packages, not services' ]
640   if    $curuser->access_right('Edit package definitions')
641      || $curuser->access_right('Edit global package definitions');
642 if ( $curuser->access_right('Configuration') ) {
643
644   #package grouping sub-menu?
645   $config_pkg{'Package classes'} =  [ $fsurl.'browse/pkg_class.html', 'Package classes define groups of packages, for taxation, ordering convenience and reporting.' ];
646   $config_pkg{'Package categories'} =  [ $fsurl.'browse/pkg_category.html', 'Package categories define groups of package classes, for invoice sections.' ];
647   $config_pkg{'Package report classes'} =  [ $fsurl.'browse/part_pkg_report_option.html', 'Package classes define optional groups of packages for reporting only.' ];
648   #eo package grouping sub-menu
649
650   if ( $curuser->access_right([ 'Edit fee definitions',
651                                 'Edit global fee definitions' ]) ) {
652     $config_pkg{'Fees'} = [ $fsurl.'browse/part_fee.html', '' ];
653   }
654   $config_pkg{'Discounts'} = [ $fsurl.'browse/discount.html', '' ];
655   $config_pkg{'Discount classes'} = [ $fsurl.'browse/discount_class.html', '' ];
656   $config_pkg{'Cancel/Suspend Reasons'} = [ \%config_pkg_reason, '' ];
657 }
658
659 tie my %config_cust, 'Tie::IxHash',
660   'Customer tags'       => [ $fsurl.'browse/part_tag.html', '' ],
661   'Customer classes'    =>  [ $fsurl.'browse/cust_class.html', 'Customer classes define groups of customers for reporting.' ],
662   'Customer categories' =>  [ $fsurl.'browse/cust_category.html', 'Customer categories define groups of customer classes.' ],
663   'separator'     => '', #its a separator!
664   'Contact types'    =>  [ $fsurl.'browse/contact_class.html', ''], #XXX useful description
665 ;
666   
667 $config_cust{'Note classes'} = [ $fsurl.'browse/cust_note_class.html', 'Note classes define groups of customer notes for reporting.' ]
668     if ($conf->exists('note-classes') && $conf->config('note-classes') > 0);
669
670 tie my %config_agent, 'Tie::IxHash',
671   'Agent types' => [ $fsurl.'browse/agent_type.cgi', 'Agent types define groups of package definitions that you can then assign to particular agents' ],
672   'Agents'      => [ $fsurl.'browse/agent.cgi', 'Agents are resellers of your service. Agents may be limited to a subset of your full offerings (via their type)' ],
673   'Agent payment gateways'         => [ $fsurl.'browse/payment_gateway.html', 'Credit card and electronic check processors for agent overrides' ];
674 ;
675
676 tie my %config_sales, 'Tie::IxHash',
677   'Sales People' => [ $fsurl.'browse/sales.html', 'Sales people bring in new business.' ],
678 ;
679
680 tie my %config_billing_rates, 'Tie::IxHash';
681 $config_billing_rates{'Rate plans'} = [ $fsurl.'browse/rate.cgi', 'Manage rate plans' ]
682   if $curuser->access_right('Edit CDR rates')
683   #|| $curuser->access_right('Edit global CDR rates')
684   || $curuser->access_right('Configuration');
685 if ( $curuser->access_right('Configuration') ) {
686   $config_billing_rates{'Regions and prefixes'} = [ $fsurl.'browse/rate_region.html', 'Manage regions and prefixes' ];
687   $config_billing_rates{'Usage classes'} = [ $fsurl.'browse/usage_class.html', 'Usage classes define groups of usage for taxation.' ];
688   $config_billing_rates{'Time periods'} = [ $fsurl.'browse/rate_time.html', 'Time periods define days and hours for rate plans' ];
689   $config_billing_rates{'Edit rates with Excel'} = [ $fsurl.'misc/rate_edit_excel.html', 'Download and edit rates with Excel, then upload changes.' ]; #"Edit with Excel" ?
690   $config_billing_rates{'separator'} = ''; #its a separator!
691   $config_billing_rates{'Tiering plans'} = [ $fsurl.'browse/rate_tier.html', 'Rating tiers' ];
692 }
693
694 tie my %config_billing, 'Tie::IxHash';
695 #  'Payment gateways'         => [ $fsurl.'browse/payment_gateway.html', 'Credit card and electronic check processors' ];
696 $config_billing{'Billing events'} = [ $fsurl.'browse/part_event.html', 'Billing actions for customers, invoices and packages' ]
697     if $curuser->access_right('Edit billing events')
698     || $curuser->access_right('Edit global billing events');
699 if ( $curuser->access_right('Configuration') ) {
700   $config_billing{'Invoice configurations'}      = [ $fsurl.'browse/invoice_conf.html', 'Adjust invoice settings for special-purpose notices' ];
701   $config_billing{'Invoice templates'}      = [ $fsurl.'browse/invoice_template.html', 'Edit templates for HTML, plaintext and typeset invoices' ];
702   $config_billing{'separator'} = ''; #its a separator!
703   $config_billing{'Prepaid cards'}          = [ $fsurl.'search/prepay_credit.html', 'View outstanding cards, generate new cards' ];
704 }
705 $config_billing{'Call rates and regions'} = [ \%config_billing_rates, 'Manage rate plans, regions and prefixes for VoIP and call billing' ]
706   if keys %config_billing_rates;
707 if ( $curuser->access_right('Configuration') ) {
708   $config_billing{'separator2'} = ''; #its a separator!
709
710   my $config_taxes_name = 'Locales and tax rates'.
711                           ( $conf->config('tax_data_vendor')
712                             ? ' (internal tax class system)'
713                             : ''
714                           );
715   $config_billing{$config_taxes_name}  = [ $fsurl.'browse/cust_main_county.cgi', 'Change tax rates, or break down a country into states, or a state into counties and assign different tax rates to each' ];
716   $config_billing{'Tax rates (vendor data tax products system)'}  = [ $fsurl.'browse/tax_rate.cgi', 'Edit tax rates for the vendor data tax products system' ]
717      if $conf->config('tax_data_vendor');
718   $config_billing{'Tax classes'} = [ $fsurl. 'browse/part_pkg_taxclass.html', 'Tax classes' ];
719
720   if ( $conf->config('currencies') ) {
721     $config_billing{'separator3'} = ''; #its a separator!
722     $config_billing{'Exchange rates'} = [ $fsurl.'edit/currency_exchange.html', 'Currency exchange rates' ];
723   }
724
725   $config_billing{'separator4'} = ''; #its a separator!
726   $config_billing{'Credit reasons'}  = [ $fsurl.'browse/reason_type.html?class=R', 'Credit reasons explain why a credit was issued.' ];
727   
728   $config_billing{'Refund reasons'}  = [ $fsurl.'browse/reason_type.html?class=F', 'Refund reasons explain why a refund was issued.' ];
729
730   $config_billing{'Invoice void reasons'}  = [ $fsurl.'browse/reason_type.html?class=I', 'Invoice void reasons explain why an invoice was voided.' ];
731   $config_billing{'Payment void reasons'}  = [ $fsurl.'browse/reason_type.html?class=P', 'Payment void reasons explain why a payment was voided.' ];
732   $config_billing{'Credit void reasons'}  = [ $fsurl.'browse/reason_type.html?class=X', 'Credit void reasons explain why a credit was voided.' ];
733 }
734
735 #XXX also to be unified
736 tie my %config_ticketing_groups, 'Tie::IxHash',
737   'Select' => [ $fsurl.'rt/Admin/Groups', '' ],
738   'Create' => [ $fsurl.'rt/Admin/Groups/Modify.html?Create=1', '' ],
739 ;
740
741 tie my %config_ticketing_queues, 'Tie::IxHash',
742   'Select' => [ $fsurl.'rt/Admin/Queues', '' ],
743   'Create' => [ $fsurl.'rt/Admin/Queues/Modify.html?Create=1', '' ],
744 ;
745
746 tie my %config_ticketing_customfields, 'Tie::IxHash',
747   'Select' => [ $fsurl.'rt/Admin/CustomFields', '' ],
748   'Create' => [ $fsurl.'rt/Admin/CustomFields/Modify.html?Create=1', '' ],
749 ;
750
751 tie my %config_ticketing_articles_classes, 'Tie::IxHash',
752   'Select' => [ $fsurl.'rt/Admin/Articles/Classes/', '' ],
753   'Create' => [ $fsurl.'rt/Admin/Articles/Classes/Modify.html?Create=1', '' ],
754 ;
755
756 tie my %config_ticketing_articles_customfields, 'Tie::IxHash',
757   'Select' => [ $fsurl.'rt/Admin/CustomFields/index.html?type=RT%3A%3AClass-RT%3A%3AArticle', '' ],
758   'Create' => [ $fsurl.'rt/Admin/CustomFields/Modify.html?Create=1&LookupType=RT%3A%3AClass-RT%3A%3AArticle', '' ],
759 ;
760
761 tie my %config_ticketing_articles, 'Tie::IxHash',
762   'Classes'       => [ \%config_ticketing_articles_classes, '' ],
763   'Custom Fields' => [ \%config_ticketing_articles_customfields, '' ],
764 ;
765
766 tie my %config_ticketing, 'Tie::IxHash',
767   'Ticketing Users'      => [ $fsurl.'rt/Admin/Users', 'Edit ticketing users' ], #XXX to be unified
768   'Ticketing Groups'     => [ \%config_ticketing_groups, 'View/Edit ticketing groups and group membership' ], #XXX to be unified
769   'Ticketing Queues'     => [ \%config_ticketing_queues, 'View/Edit ticketing queues and queue-specific properties' ], 
770   'Ticket Custom Fields' => [ \%config_ticketing_customfields, 'View/Edit ticketing custom fields' ], 
771   'Ticketing Global'     => [ $fsurl.'rt/Admin/Global', 'View/Edit ticketing configuration applicable to all queues' ], #XXX the individual items
772   'Ticketing Articles'   => [ \%config_ticketing_articles, '' ],
773   #"System Configuraiton"?  useless, just makes people report errors about missing Module::Versions::Report #'Ticketing Tools'     => [ $fsurl.'rt/Admin/Tools', '' ], 
774 ;
775
776 tie my %config_nms, 'Tie::IxHash',
777   'View/Edit virtual ports' => [ $fsurl.'browse/torrus_srvderive.html', '' ],
778 ;
779
780 tie my %config_misc, 'Tie::IxHash';
781 $config_misc{'Message templates'} = [ $fsurl.'browse/msg_template/email.html', 'Templates for customer notices' ]
782   if $curuser->access_right(['View templates', 'View global templates',
783                              'Edit templates', 'Edit global templates', ]);
784 $config_misc{'Advertising sources'} = [ $fsurl.'browse/part_referral.html', 'Where a customer heard about your service.' ]
785   if $curuser->access_right('Edit advertising sources')
786   || $curuser->access_right('Edit global advertising sources');
787 $config_misc{'Custom fields'} = [ $fsurl.'browse/part_virtual_field.html', 'Locally defined fields', ]
788   if $curuser->access_right('Edit custom fields');
789 $config_misc{'Translation strings'} = [ $fsurl.'browse/msgcat.html', 'Translations and other customizable labels for each locale' ]
790   if $curuser->access_right('Configuration');
791 $config_misc{'Inventory classes and inventory'} = [ $fsurl.'browse/inventory_class.html', 'Setup inventory classes and stock inventory' ]
792   if $curuser->access_right('Edit inventory')
793   || $curuser->access_right('Edit global inventory')
794   || $curuser->access_right('Configuration');
795
796 $config_misc{'Upload targets'} = [ $fsurl.'browse/upload_target.html', 'Billing and payment upload destinations' ]
797   if $curuser->access_right('Configuration');
798
799 $config_misc{'System log emails'} = [ $fsurl.'browse/log_email.html', 'Configure conditions for sending email when logging' ]
800   if $curuser->access_right('View system logs')
801   || $curuser->access_right('Configuration');
802
803 tie my %config_menu, 'Tie::IxHash';
804 if ( $curuser->access_right('Configuration' ) ) {
805   %config_menu = (
806     'Settings'      => [ $fsurl.'config/config-view.cgi', '' ],
807     'separator'     => '', #its a separator!
808     'Companies'     => [ \%config_agent, '' ],
809   );
810 }
811
812 $config_menu{'Sales People'}  = [ \%config_sales, '' ]
813   if $curuser->access_right('Edit sales people');
814
815 if ( $curuser->access_right('Configuration' ) ) {
816   $config_menu{'Employees'}  = [ \%config_employees, '' ];
817   $config_menu{'separator2'} = ''; #its a separator!
818   $config_menu{'Customers'}  = [ \%config_cust, '' ];
819     #or this? 'Customers and Contacts'
820 }
821
822 $config_menu{'Packages'} = [ \%config_pkg, '' ]
823   if    $curuser->access_right('Configuration' )
824      || $curuser->access_right('Edit package definitions')
825      || $curuser->access_right('Edit global package definitions');
826
827 if ( $curuser->access_right('Configuration') ) {
828   $config_menu{'Services'} = [ \%config_export_svc, '' ];
829   $config_menu{separator3} = '';
830 }
831
832 tie my %config_vendor, 'Tie::IxHash',
833   'Vendor classes' => [ $fsurl.'browse/vend_class.html', '' ],
834   'Vendors'        => [ $fsurl.'browse/vend_main.html', '' ],
835 ;
836
837 if ( $curuser->access_right('Configuration') ) {
838   $config_menu{'Vendors'} = [ \%config_vendor, '' ];
839   $config_menu{separator4} = '';
840 }
841
842 $config_menu{'Billing'} = [ \%config_billing, '' ]
843   if keys %config_billing;
844 $config_menu{'Ticketing'} = [ \%config_ticketing, '' ]
845   if $conf->config('ticket_system')
846   && FS::TicketSystem->access_right(\%session, 'ShowConfigTab');
847 $config_menu{'Network Monitoring'} = [ \%config_nms, '' ]
848   if $curuser->access_right('Configure network monitoring')
849   && $conf->config('network_monitoring_system') eq 'Torrus_Internal';
850
851 if ( $curuser->access_right([ 'Configuration',
852                               'View templates',
853                               'View global templates',
854                               'Edit templates',
855                               'Edit global templates',
856                            ])
857    ) {
858   $config_menu{separator9} = '' if keys %config_menu;
859   $config_menu{'Miscellaneous'} = [ \%config_misc, ''    ];
860 }
861
862
863 my $wiki = 'http://www.freeside.biz/mediawiki/index.php';
864 my $doc_link = $conf->config('support-key')
865                  ? "$wiki/Supported:Documentation"
866                  : $curuser->access_right('Configuration')
867                    ? "$wiki/Freeside:4:Documentation"
868                    : "$wiki/Freeside:2.1:Documentation:User"; #no page for other versions yet :/
869
870 eval "use RT;"
871   if $conf->config('ticket_system') eq 'RT_Internal';
872
873 tie my %help_menu, 'Tie::IxHash';
874 my $agentnum = $conf->config('brand-agent');
875 if ( $agentnum ) {
876   my $company_name = $conf->config('company_name', $agentnum);
877   $help_menu{"About $company_name"} = [ "javascript:about_freeside()", '' ];
878 } else {
879   $help_menu{'Billing documentation'} = [ $doc_link, 'Freeside documentation' ];
880   $help_menu{'Ticketing documentation'} = [ 'http://wiki.bestpractical.com/', 'Request Tracker Wiki' ]
881     if $conf->config('ticket_system') eq 'RT_Internal';
882   $help_menu{'Networking monitoring documentation'} = [ 'http://torrus.org/userguide.pod.html', 'Torrus User Guide' ]
883     if $conf->config('network_monitoring_system') eq 'Torrus_Internal';
884   $help_menu{'separator'} = '';
885   $help_menu{"About Freeside v$FS::VERSION"} = [ "javascript:about_freeside()", '' ];
886   $help_menu{"About RT v$RT::VERSION"} = [ 'http://www.bestpractical.com/rt', 'Request Tracker Homepage' ]
887     if $conf->config('ticket_system') eq 'RT_Internal';
888   $help_menu{"About Torrus v1.0.9"} = [ 'http://www.torrus.org/', 'Torrus Homepage' ] #XXX manual version
889     if $conf->config('network_monitoring_system') eq 'Torrus_Internal';
890 }
891
892
893 tie my %menu, 'Tie::IxHash';
894
895 if ( $conf->config('menu-prepend_links')) {
896   my @links = split(/\n/, $conf->config('menu-prepend_links'));
897   foreach my $link (@links) {
898     $link =~ /^\s*(\S+)\s+(.*?)(\s*\(([^\)]*)\))?$/ or next;
899     my($url, $label, $alt) = ($1, $2, $4);
900     $menu{$label} = [ $url, $alt ];
901   }
902 }
903
904 $menu{'Billing Main'} = [ $fsurl, 'Billing start page', ];
905
906 if ( $conf->config('ticket_system') ) {
907   $menu{'Ticketing Main'} =
908     [ 
909       ( $conf->config('ticket_system') eq 'RT_External'
910         ? FS::TicketSystem->baseurl()
911         : $fsurl.'rt/'
912       ),
913       'Ticketing start page',
914     ],
915 }
916
917 if ( $conf->config('network_monitoring_system') eq 'Torrus_Internal' &&
918   $curuser->access_right('Configure network monitoring') ) {
919   $menu{'Network Main'} =
920     [ $fsurl.'torrus/main', 'Network monitoring start page' ],
921 }
922
923 $menu{'New prospect'} = [ $fsurl.'edit/prospect_main.html', 'Add a new prospect' ]
924   if $curuser->access_right('New prospect');
925 $menu{'New customer'} = [ $fsurl.'edit/cust_main.cgi', 'Add a new customer' ]
926   if $curuser->access_right('New customer');
927 $menu{'Reports'} = [ \%report_menu, 'Lists, reporting and graphing' ]
928   if keys %report_menu;
929 $menu{'Tools'} = [ \%tools_menu, 'Tools' ]
930   if keys %tools_menu;
931 $menu{'Configuration'} = [ \%config_menu, 'Configuration and setup' ]
932   if $curuser->access_right([ 'Configuration',
933                               'Edit package definitions',
934                               'Edit global package definitions',
935                               'Edit billing events',
936                               'Edit global billing events',
937                               'Dialup configuration',
938                               'Wireless broadband configuration',
939                               'Phone configuration',
940                               'Alarm configuration',
941                               'Alarm global configuration',
942                               'Edit advertising sources',
943                               'Edit global advertising sources',
944                               'View templates',
945                               'View global templates',
946                               'Edit templates',
947                               'Edit global templates',
948                            ]);
949 $menu{'Help'} = [ \%help_menu, '' ];
950
951
952 use vars qw($gmenunum);
953 $gmenunum = 0;
954
955 sub submenu {
956   my($submenu, $title) = @_;
957   my $menunum = $gmenunum++;
958
959   #return two args: html, menuname
960
961   "var myMenu$menunum = new WebFXMenu;\n".
962   #"myMenu$menunum.useAutoPosition = true;\n".
963 #  "myMenu$menunum.emptyText = '$title';\n".
964   "myMenu$menunum.emptyText = '';\n".
965
966   (
967     join("\n", map {
968
969       if ( !ref( $submenu->{$_} ) ) {
970
971         "myMenu$menunum.add(new WebFXMenuSeparator());";
972
973       } else {
974
975         my($url_or_submenu, $tooltip ) = @{ $submenu->{$_} };
976         if ( ref($url_or_submenu) ) {
977
978           my($subhtml, $submenuname ) = submenu($url_or_submenu, $_); #mmm, recursion
979
980           "$subhtml\n".
981           "myMenu$menunum.add(new WebFXMenuItem(\"$_\", null, \"$tooltip\", $submenuname ));";
982
983         } else {
984
985           "myMenu$menunum.add(new WebFXMenuItem(\"$_\", \"$url_or_submenu\", \"$tooltip\" ));";
986
987         }
988
989       }
990
991     } keys %$submenu )
992   ). "\n".
993   "myMenu$menunum.width = 256;\n",
994
995   "myMenu$menunum";
996
997 }
998
999 </%init>
1000