summaryrefslogtreecommitdiff
path: root/httemplate/elements/menu.html
blob: 1909d909d665b3376ff310f8b8637fd9d28fa7d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
<script type="text/javascript" src="<%$fsurl%>elements/cssexpr.js"></script>

% if ( $opt{'position'} eq 'top' ) {

  <script type="text/javascript" src="<%$fsurl%>elements/xmenu.top.js"></script>
  <link href="<%$fsurl%>elements/xmenu.top.css" type="text/css" rel="stylesheet">

% } else {  # elsif ( $opt{'position'} eq 'left' ) {

  <script type="text/javascript" src="<%$fsurl%>elements/xmenu.js"></script>
  <link href="<%$fsurl%>elements/xmenu.css" type="text/css" rel="stylesheet">

% }

% unless ( $opt{'nocss'} ) {
  <link href="<%$fsurl%>elements/freeside.css" type="text/css" rel="stylesheet">
% }
<link href="<%$fsurl%>elements/freeside-menu.css" type="text/css" rel="stylesheet">

<SCRIPT TYPE="text/javascript">

% my $fs_popup = include( '/elements/popup_link_onclick.html',
%                           'action'      => $fsurl.'docs/about.html',
%                           'label'       => 'Freeside',
%                           'style'       => 'color:#999999',
%                           'actionlabel' => 'About',
%                           'width'       => 300,
%                           'height'      => 360,
%                           'color'       => '#7e0079',
%                           'scrolling'   => 'no',
%                       );
% $fs_popup =~ s/return false;//;
  function about_freeside() {
    <% $fs_popup |n %>
  }

  webfxMenuImagePath      = "<%$fsurl%>images/";
  webfxMenuUseHover       = 1;
  webfxMenuShowTime       = 300;
  webfxMenuHideTime       = 500;

  var myBar = new WebFXMenuBar;

% foreach my $item ( keys %menu ) {
%
%     my( $url_or_submenu, $tooltip ) = @{ $menu{$item} };
%
%     if ( ref($url_or_submenu) ) {
%
%         #warn $item;
%
%         my( $subhtml, $submenuname ) = submenu($url_or_submenu, $item);

          <% $subhtml |n %>
          myBar.add(new WebFXMenuButton("<% $item %>", null, "<% $tooltip %>", <% $submenuname |n %> ));

%     } else { 
    
          myBar.add(new WebFXMenuButton("<% $item %>", "<% $url_or_submenu %>", "<% $tooltip %>" ));

%     }
%
% }

  myBar.show( null, 'vertical' );
  myBar.width = 154;

</SCRIPT>

<%init>
my( %opt ) = @_;
my $conf = new FS::Conf;
my $fsurl = $opt{'freeside_baseurl'};

my $curuser = $FS::CurrentUser::CurrentUser;

#XXX Active tickets not assigned to a customer

tie my %report_prospects, 'Tie::IxHash',
  'List prospects' => [ $fsurl. 'search/prospect_main.html', '' ],
  'Advanced prospect reports' => [ $fsurl. 'search/report_prospect_main.html', '' ],
;

tie my %report_customers_lists, 'Tie::IxHash',
  'by customer number' => [ $fsurl. 'search/cust_main.cgi?browse=custnum', '' ],
  'by last name' => [ $fsurl. 'search/cust_main.cgi?browse=last', '' ],
  'by company name' => [ $fsurl. 'search/cust_main.cgi?browse=company', '' ],
;
$report_customers_lists{'by active trouble tickets'} = [ $fsurl. 'search/cust_main.cgi?browse=tickets', '' ]
  if $conf->config('ticket_system');

tie my %report_customers_search, 'Tie::IxHash';
$report_customers_search{'by ordering employee'} = [ $fsurl. 'search/cust_main-otaker.cgi' ]
  if $curuser->access_right('Configuration');

tie my %report_customers, 'Tie::IxHash';
$report_customers{'List customers'} = [ \%report_customers_lists, 'List customers' ]
  if $curuser->access_right('List customers');
$report_customers{'Search customers'} = [ \%report_customers_search, 'Search customers' ]
  if keys %report_customers_search;
$report_customers{'Zip code distribution'}     = [ $fsurl. 'search/report_cust_main-zip.html', 'Zip codes by number of customers' ];
$report_customers{'Advanced customer reports'} = [ $fsurl. 'search/report_cust_main.html', 'by status, signup date, agent, etc.' ]
  if    $curuser->access_right('List customers')
     && $curuser->access_right('List packages');

tie my %report_invoices_open, 'Tie::IxHash',
  'All open invoices' => [ $fsurl.'search/cust_bill.html?OPEN_date', 'All invoices with an unpaid balance' ],
  '15 day open invoices' => [ $fsurl.'search/cust_bill.html?OPEN15_date', 'Invoices 15 days or older with an unpaid balance' ],
  '30 day open invoices' => [ $fsurl.'search/cust_bill.html?OPEN30_date', 'Invoices 30 days or older with an unpaid balance' ],
  '60 day open invoices' => [ $fsurl.'search/cust_bill.html?OPEN60_date', 'Invoices 60 days or older with an unpaid balance' ],
  '90 day open invoices' => [ $fsurl.'search/cust_bill.html?OPEN90_date', 'Invoices 90 days or older with an unpaid balance' ],
  '120 day open invoices' => [ $fsurl.'search/cust_bill.html?OPEN120_date', 'Invoices 120 days or older with an unpaid balance' ],
;

tie my %report_invoices, 'Tie::IxHash',
  'Open invoices' => [ \%report_invoices_open, 'Open invoices' ],
  'All invoices'  => [ $fsurl. 'search/cust_bill.html?date', 'List all invoices' ],
  'Advanced invoice reports' => [ $fsurl.'search/report_cust_bill.html', 'by agent, date range, etc.' ],
;

tie my %report_discounts, 'Tie::IxHash',
  'Discount graph'  => [ $fsurl. 'graph/report_cust_bill_pkg_discount.html', 'Discount overview per month' ],
  'Discount detail' => [ $fsurl.'search/report_cust_bill_pkg_discount.html', 'Discount report (by employee and/or date range)' ],
  #awful name
  'Package discounts' => [ $fsurl.'search/report_cust_pkg_discount.html', 'Active/inactive discounts by package' ],
;

tie my %report_services, 'Tie::IxHash';
if ( $curuser->access_right('Configuration') ) {
  $report_services{'Service definitions'} =  [ $fsurl.'browse/part_svc.cgi?orderby=active', 'Service definitions by number of active packages' ];
  $report_services{'separator'} =  '';
}
foreach my $svcdb ( FS::part_svc->svc_tables() ) {

  my $name =        "FS::$svcdb"->table_info->{'name_plural'}
             || PL( "FS::$svcdb"->table_info->{'name'}        );
  my $lcname = lc($name);
  my $lcsname = lc("FS::$svcdb"->table_info->{'name'});
  my $longname = "FS::$svcdb"->table_info->{'longname_plural'} || $name;
  my $lclongname = lc($longname);
  my $sorts = "FS::$svcdb"->table_info->{'sorts'} || [ 'svcnum' ];
  $sorts = [ $sorts ] unless ref($sorts);
  my %svc_url = ( 'm'      => $m,
		  'action' => 'search',
		  'svcdb'  => $svcdb,
		);

  tie my %report_svc, 'Tie::IxHash';

  foreach my $sort ( @$sorts ) {

    my $field_info = FS::part_svc->svc_table_fields($svcdb)->{$sort};
    my $label = $field_info->{'label_sort'} || 'by '.$field_info->{'label'};

    my $title = "All $lcname";
    $title .= " $label"
      if scalar(@$sorts) > 1;

    $report_svc{$title} =
      [ svc_url( %svc_url, 'query' => "magic=all;sortby=$sort" ),
        '',
      ];
  }

  if ( $svcdb eq 'svc_acct' ) {

    $report_svc{"All $lcname never logged in"} = 
      [ svc_url( %svc_url, 'query' => "magic=nologin;sortby=svcnum" ),
        '',
      ];

  } elsif ( $svcdb eq 'svc_phone' ) {

    $report_svc{"${name}' total usage by time period"} = 
      [ $fsurl. 'search/report_svc_phone.html',
        'Total usage (minutes, and amount billed) for the specified time period, per phone number.',
      ];

  }

  if ( $curuser->access_right('View/link unlinked services') ) {
    $report_svc{"Unlinked $lcname"} = 
      [ svc_url( %svc_url, 'query' => "magic=unlinked;sortby=". $sorts->[0] ),
        "Pre-Freeside $lcname without a customer record",
      ];
  }

  if ( $svcdb eq 'svc_acct' || $svcdb eq 'svc_broadband' ) {
    $report_svc{"Advanced $lcsname reports"} = 
      [ $fsurl."search/report_$svcdb.html", '' ];
  }

  if ( $svcdb eq 'svc_phone' ) {
    $report_svc{"Avaialble phone numbers (DIDs)"} =
      [ $fsurl."search/phone_avail.html", '' ];
  }

  $report_services{$name} = [ \%report_svc, $longname ];

}

tie my %report_packages, 'Tie::IxHash';
if (    $curuser->access_right('Edit package definitions')
     || $curuser->access_right('Edit global package definitions')
   )
{
  $report_packages{'Package definitions'} =  [ $fsurl.'browse/part_pkg.cgi?active=1', 'Package definitions by number of active packages' ];
  $report_packages{'separator'} =  '';
}
if ( $curuser->access_right('Financial reports') ) {
  $report_packages{'Package churn'} =  [ $fsurl.'graph/report_cust_pkg.html', 'Orders, suspensions and cancellations summary graph' ];
  $report_packages{'separator2'} =  '';
}
$report_packages{'All customer packages'} =  [ $fsurl.'search/cust_pkg.cgi?pkgnum', 'List all customer packages', ];
$report_packages{'Package summary'} = [ $fsurl.'search/cust_pkg_summary.html', 'Show package sales summary', ];
$report_packages{'Suspended customer packages'} =  [ $fsurl.'search/cust_pkg.cgi?magic=suspended', 'List suspended packages' ];
$report_packages{'Suspension summary'} = [ $fsurl.'search/cust_pkg_susp.html', 'Show suspension activity', ];
$report_packages{'Customer packages with unconfigured services'} =  [ $fsurl.'search/cust_pkg.cgi?APKG_pkgnum', 'List packages which have provisionable services' ];
$report_packages{'FCC Form 477 packages'} =  [ $fsurl.'search/report_477.html', 'Summarize packages by census tract for particular types' ]
  if $conf->exists('cust_main-require_censustract');
$report_packages{'Advanced package reports'} =  [ $fsurl.'search/report_cust_pkg.html', 'by agent, date range, status, package definition' ];

tie my %report_inventory, 'Tie::IxHash',
  'Inventory by agent' => [ $fsurl.'search/report_agent_inventory.html', '' ],
  'Inventory activity' => [ $fsurl.'search/report_h_inventory_item.html', '' ],
;

tie my %report_rating, 'Tie::IxHash',
  'RADIUS sessions' => [ $fsurl.'search/sqlradius.html', '' ],
  'Call Detail Records (CDRs)' => [ $fsurl.'search/report_cdr.html', '' ],
  'Time worked' => [ $fsurl.'search/report_rt_transaction.html', '' ],
;

tie my %report_ticketing_statistics, 'Tie::IxHash',
  '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' ],
  'Ticket status by Queue'            => [ $fsurl.'rt/RTx/Statistics/OpenStalled', 'View numbers of new, open and stalled tickets in a selected Queue' ],
  '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' ],
  'Tickets per Day of Week'           => [ $fsurl.'rt/RTx/Statistics/DayOfWeek', 'View trends showing when tickets are created, resolved or deleted' ],
  'Time to resolve'                   => [ $fsurl.'rt/RTx/Statistics/Resolution', 'View how long tickets take to be resolved by Queue' ],
  'Time to resolve (scatter graph)'   => [ $fsurl.'rt/RTx/Statistics/TimeToResolve', 'View a detailed scatter graph of time to resolve tickets by Queue' ],
;

tie my %report_ticketing, 'Tie::IxHash',
  'Resolved by owner'       => [ $fsurl.'rt/Tools/Reports/ResolvedByOwner.html', '' ],
  'Resolved in date range'  => [ $fsurl.'rt/Tools/Reports/ResolvedByDates.html', '' ],
  'Created in date range'   => [ $fsurl.'rt/Tools/Reports/CreatedByDates.html', '' ],
  'separator'               => '',
  'Statistics'              => [ \%report_ticketing_statistics, '' ],
  'separator2'              => '',
  'Advanced ticket reports' => [ $fsurl.'rt/Search/Build.html', 'List tickets by any criteria' ],
;

tie my %report_bill_event, 'Tie::IxHash',
  'All billing events' => [ $fsurl.'search/report_cust_event.html', 'All billing events for a date range' ],
  'Billing event errors' => [ $fsurl.'search/report_cust_event.html?failed=1', 'Failed credit cards, processor or printer problems, etc.' ],
#  'All invoice events' => [ $fsurl.'search/cust_bill_event.html', 'Reports on deprecated, old-style invoice events for a date range' ],
#  'Invoice event errors' => [ $fsurl.'search/cust_bill_event.html?failed=1', 'Reports on deprecated, old-style events for failed credit cards, processor or printer problems, etc.' ],
;

tie my %report_payments, 'Tie::IxHash',
    'Payments' => [ $fsurl.'search/report_cust_pay.html', 'Payment report (by type and/or date range)' ],
;
$report_payments{'Pending Payments'} = [ $fsurl.'search/cust_pay_pending.html?magic=_date;statusNOT=done', 'Pending real-time payments' ]
  if $curuser->access_right('View customer pending payments');
$report_payments{'Voided Payments'} = [ $fsurl.'search/report_cust_pay.html?void=1', 'Voided payment report (by type and/or date range)' ]
  if $curuser->access_right('View customer pending payments');
$report_payments{'Unapplied Payments'} = [ $fsurl.'search/report_cust_pay.html?unapplied=1', 'Unapplied payment report (by type and/or date range)' ];
$report_payments{'Payment Batches'} = [ $fsurl.'search/pay_batch.html', 'Payment batches (by status and/or date range)' ]
  if $conf->exists('batch-enable') || $conf->config('batch-enable_payby');
$report_payments{'Unapplied Payment Aging'} = [ $fsurl.'search/report_unapplied_cust_pay.html', 'Unapplied payment aging report' ];

tie my %report_financial, 'Tie::IxHash';
if($curuser->access_right('Financial reports')) {

  %report_financial = (
    'Sales, Credits and Receipts' => [ $fsurl.'graph/report_money_time.html', 'Sales, credits and receipts summary graph' ],
    'Sales Report' => [ $fsurl.'graph/report_cust_bill_pkg.html', 'Sales report and graph (by agent, package class and/or date range)' ],
    '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)' ],
    'Employee Commission Report' => [ $fsurl.'search/report_employee_commission.html', '' ],
    'Credit Report' => [ $fsurl.'search/report_cust_credit.html', 'Credit report (by employee and/or date range)' ],
    'Unapplied Credits' => [ $fsurl.'search/report_cust_credit.html?unapplied=1', 'Unapplied credit report (by type and/or date range)' ],
    'Refund Report' => [ $fsurl.'search/report_cust_refund.html', 'Refund report (by type and/or date range)' ],
    'Unapplied Refunds' => [ $fsurl.'search/report_cust_refund.html?unapplied=1', 'Unapplied refund report (by type and/or date range)' ],
    'Package Costs Report' => [ $fsurl.'graph/report_cust_pkg_cost.html', 'Package setup and recurring costs graph' ],
  );
  $report_financial{'A/R Aging'} = [ $fsurl.'search/report_receivables.html', 'Accounts Receivable Aging report' ];
  $report_financial{'Prepaid Income'} = [ $fsurl.'search/report_prepaid_income.html', 'Prepaid income (unearned revenue)  report' ];
  $report_financial{'Sales Tax Liability'} = [ $fsurl.'search/report_tax.html', 'Sales tax liability report (internal taxclass system)' ];
  $report_financial{'Tax Liability'} = [ $fsurl.'search/report_newtax.html', 'Tax liability report (vendor data tax products system)' ]
    if $conf->exists('enable_taxproducts');

} elsif($curuser->access_right('Receivables report')) {

  $report_financial{'A/R Aging'} = [ $fsurl.'search/report_receivables.html', 'Accounts Receivable Aging report' ];

} # else $report_financial contains nothing.

tie my %report_menu, 'Tie::IxHash';
$report_menu{'Prospects'}   = [ \%report_prospects, 'Prospect reports' ]
  if $curuser->access_right('List prospects');
$report_menu{'Customers'}   = [ \%report_customers, 'Customer reports'  ]
  if $curuser->access_right('List customers');
$report_menu{'Invoices'}    =  [ \%report_invoices,  'Invoice reports'   ]
  if $curuser->access_right('List invoices');
$report_menu{'Discounts'}   =  [ \%report_discounts, 'Discount reports'  ]
  if $curuser->access_right('Financial reports');
$report_menu{'Payments'}    =  [ \%report_payments,  'Payment reports'   ]
  if $curuser->access_right('Financial reports');
$report_menu{'Packages'}    =  [ \%report_packages,  'Package reports'   ]
  if $curuser->access_right('List packages');
$report_menu{'Services'}    =  [ \%report_services,  'Services reports'  ]
  if $curuser->access_right('List services');
$report_menu{'Inventory'}    =  [ \%report_inventory,  'Inventory reports'  ]
  if $curuser->access_right('Configuration'); #XXX List inventory?
$report_menu{'Usage'} =  [ \%report_rating,    'Usage reports'  ]
  if $curuser->access_right('List rating data');
$report_menu{'Tickets'}   = [ \%report_ticketing, 'Ticket reports' ]
  if $conf->config('ticket_system')
  ;#&& FS::TicketSystem->access_right(\%session, 'Something');
$report_menu{'Billing events'} =  [ \%report_bill_event, 'Billing events' ]
  if $curuser->access_right('Billing event reports');
$report_menu{'Financial'}  = [ \%report_financial, 'Financial reports' ]
  if $curuser->access_right('Financial reports') 
  or $curuser->access_right('Receivables report');
$report_menu{'SQL Query'}  = [ $fsurl.'search/report_sql.html', 'SQL Query' ]
  if $curuser->access_right('Raw SQL');

tie my %tools_importing, 'Tie::IxHash',
  'Customers' => [ $fsurl.'misc/cust_main-import.cgi', '' ],
  'Customer packages' => [ $fsurl.'misc/cust_pkg-import.html', '' ],
  'Customer comments from CSV file' => [ $fsurl.'misc/cust_main_note-import.html', '' ],
  'One-time charges from CSV file' => [ $fsurl.'misc/cust_main-import_charges.cgi', '' ],
  'Payments from CSV file' => [ $fsurl.'misc/cust_pay-import.cgi', '' ],
  'Phone numbers (DIDs)' => [ $fsurl.'misc/phone_avail-import.html', '' ],
  'Call Detail Records (CDRs)' => [ $fsurl.'misc/cdr-import.html', '' ],
#  'Import call rates and regions' => [ $fsurl.'misc/rate-import.html', '' ],
;
if ( $conf->exists('enable_taxproducts') ) {
  if ( $conf->exists('taxdatadirectdownload') ) {
      $tools_importing{'Tax rates from vendor site'} =
      [ $fsurl.'misc/tax-fetch_and_import.cgi', '' ];
  } else {
    $tools_importing{'Tax rates from CSV files'} =
      [ $fsurl.'misc/tax-import.cgi', '' ];
  }
}

tie my %tools_exporting, 'Tie::IxHash',
  'Download database dump' => [ $fsurl. 'misc/dump.cgi', '' ],
;

#    <!-- <BR>View active NAS ports: 
#      <A HREF="browse/nas.cgi">session server</A> -->
#      <!-- or <A HREF="browse/nas-sqlradius.cgi">RADIUS</A>
#    <BR> -->

tie my %tools_ticketing, 'Tie::IxHash',
  'Offline'      => [ $fsurl.'rt/Tools/Offline.html', '' ],
  'My Day'       => [ $fsurl.'rt/Tools/MyDay.html', '' ],
  'My Approvals' => [ $fsurl.'rt/Approvals/', '' ],
;
$tools_ticketing{'Cron Tool'} = [ $fsurl.'rt/Developer/CronTool/', '' ]
  if $conf->exists('rt-crontool');

tie my %tools_menu, 'Tie::IxHash', ();
$tools_menu{'Quick payment entry'} =  [ $fsurl.'misc/batch-cust_pay.html', 'Enter multiple payments in a batch' ]
  if $curuser->access_right('Post payment batch');
$tools_menu{'Process payment batches'} = [ $fsurl.'search/pay_batch.cgi?magic=_date;open=1;intransit=1', 'Process credit card and electronic check batches' ]
  if ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
     && $curuser->access_right('Process batches');
$tools_menu{'Process invoice batches'} = [ $fsurl.'search/bill_batch.cgi' ] 
  if $conf->exists('invoice_print_pdf');
$tools_menu{'Job Queue'} =  [ $fsurl.'search/queue.html', 'View pending job queue' ]
  if $curuser->access_right('Job queue');
$tools_menu{'Ticketing'} = [ \%tools_ticketing, 'Ticketing tools' ]
  if $conf->config('ticket_system');
$tools_menu{'Business card scan'} = [ $fsurl.'edit/prospect_main-upload.html' ]
  if $curuser->access_right('New prospect');
$tools_menu{'Time Queue'} =  [ $fsurl.'search/report_timeworked.html', 'View pending support time' ]
  if $curuser->access_right('Time queue');
$tools_menu{'Attachments'} = [ $fsurl.'browse/cust_attachment.html', 'View customer attachments' ]
  if !$conf->config('disable_cust_attachment') and $curuser->access_right('View attachments') and $curuser->access_right('Browse attachments');
$tools_menu{'Importing'} =  [ \%tools_importing, 'Import tools' ]
  if $curuser->access_right('Import');
$tools_menu{'Exporting'} =  [ \%tools_exporting, 'Export tools' ]
  if $curuser->access_right('Export');

tie my %config_employees, 'Tie::IxHash',
  'Employees' => [ $fsurl.'browse/access_user.html', 'Setup internal users' ],
  'Employee groups' => [ $fsurl.'browse/access_group.html', 'Employee groups allow you to control access to the backend' ],
;

tie my %config_export_svc, 'Tie::IxHash', ();
if ( $curuser->access_right('Configuration') ) {
  $config_export_svc{'Exports'} = [ $fsurl.'browse/part_export.cgi', 'Provisioning services to external machines, databases and APIs' ];
  $config_export_svc{'Service definitions'} = [ $fsurl.'browse/part_svc.cgi', 'Services are items you offer to your customers' ];
}

tie my %config_pkg_reason, 'Tie::IxHash',
  'Cancel reasons' => [ $fsurl.'browse/reason.html?class=C', 'Cancel reasons explain why a service was cancelled.' ],
  'Cancel reason types' => [ $fsurl.'browse/reason_type.html?class=C', 'Cancel reason types define groups of reasons.' ],
  'Suspend reasons' => [ $fsurl.'browse/reason.html?class=S', 'Suspend reasons explain why a service was suspended.' ],
  'Suspend reason types' => [ $fsurl.'browse/reason_type.html?class=S', 'Suspend reason types define groups of reasons.' ],
;

tie my %config_pkg, 'Tie::IxHash', ();
$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' ]
  if    $curuser->access_right('Edit package definitions')
     || $curuser->access_right('Edit global package definitions');
if ( $curuser->access_right('Configuration') ) {

  #package grouping sub-menu?
  $config_pkg{'Package classes'} =  [ $fsurl.'browse/pkg_class.html', 'Package classes define groups of packages, for taxation, ordering convenience and reporting.' ];
  $config_pkg{'Package categories'} =  [ $fsurl.'browse/pkg_category.html', 'Package categories define groups of package classes, for invoice sections.' ];
  $config_pkg{'Package report classes'} =  [ $fsurl.'browse/part_pkg_report_option.html', 'Package classes define optional groups of packages for reporting only.' ];
  #eo package grouping sub-menu

  $config_pkg{'Discounts'} = [ $fsurl.'browse/discount.html', '' ];
  $config_pkg{'Cancel/Suspend Reasons'} = [ \%config_pkg_reason, '' ];
}

tie my %config_cust, 'Tie::IxHash',
  'Customer classes'    =>  [ $fsurl.'browse/cust_class.html', 'Customer classes define groups of customers for reporting.' ],
  'Customer categories' =>  [ $fsurl.'browse/cust_category.html', 'Customer categories define groups of customer classes.' ],
;

tie my %config_agent, 'Tie::IxHash',
  'Agent types' => [ $fsurl.'browse/agent_type.cgi', 'Agent types define groups of package definitions that you can then assign to particular agents' ],
  '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)' ],
  'Agent payment gateways'         => [ $fsurl.'browse/payment_gateway.html', 'Credit card and electronic check processors for agent overrides' ];
;

tie my %config_billing_rates, 'Tie::IxHash',
  'Rate plans' => [ $fsurl.'browse/rate.cgi', 'Manage rate plans' ],
  'Regions and prefixes' => [ $fsurl.'browse/rate_region.html', 'Manage regions and prefixes' ],
  'Usage classes'  => [ $fsurl.'browse/usage_class.html', 'Usage classes define groups of usage for taxation.' ],
  'Time periods' => [ $fsurl.'browse/rate_time.html', 'Time periods define days and hours for rate plans' ],
  'Edit rates with Excel' => [ $fsurl.'misc/rate_edit_excel.html', 'Download and edit rates with Excel, then upload changes.' ], #"Edit with Excel" ?
;

tie my %config_billing, 'Tie::IxHash';
#  'Payment gateways'         => [ $fsurl.'browse/payment_gateway.html', 'Credit card and electronic check processors' ];
$config_billing{'Billing events'} = [ $fsurl.'browse/part_event.html', 'Billing actions for customers, invoices and packages' ]
    if $curuser->access_right('Edit billing events')
    || $curuser->access_right('Edit global billing events');
if ( $curuser->access_right('Configuration') ) {
  #$config_billing{'Invoice events'}         = [ $fsurl.'browse/part_bill_event.cgi', 'Deprecated, old-style actions for overdue invoices' ];
  $config_billing{'Invoice templates'}      = [ $fsurl.'browse/invoice_template.html', 'Edit templates for HTML, plaintext and typeset invoices' ];
  $config_billing{'Prepaid cards'}          = [ $fsurl.'search/prepay_credit.html', 'View outstanding cards, generate new cards' ];
  $config_billing{'Call rates and regions'} = [ \%config_billing_rates, 'Manage rate plans, regions and prefixes for VoIP and call billing' ];

  my $config_taxes_name = 'Locales and tax rates'.
                          ( $conf->exists('enable_taxproducts')
                            ? ' (internal tax class system)'
                            : ''
                          );
  $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' ];
  $config_billing{'Tax rates (vendor data tax products system)'}  = [ $fsurl.'browse/tax_rate.cgi', 'Edit tax rates for the vendor data tax products system' ]
     if $conf->exists('enable_taxproducts');
  $config_billing{'Tax classes'} = [ $fsurl. 'browse/part_pkg_taxclass.html', 'Tax classes' ];

  $config_billing{'Credit reasons'}  = [ $fsurl.'browse/reason.html?class=R', 'Credit reasons explain why a credit was issued.' ];
  $config_billing{'Credit reason types'}  = [ $fsurl.'browse/reason_type.html?class=R', 'Credit reason types define groups of reasons.' ];
}

tie my %config_ticketing, 'Tie::IxHash',
  'Ticketing Users'      => [ $fsurl.'rt/Admin/Users', 'View/Edit ticketing users' ], #XXX to be unified
  'Ticketing Groups'     => [ $fsurl.'rt/Admin/Groups', 'View/Edit ticketing groups and group membership' ], #XXX to be unified
  'Ticketing Queues'     => [ $fsurl.'rt/Admin/Queues', 'View/Edit ticketing queues and queue-specific properties' ], 
  'Ticket Custom Fields' => [ $fsurl.'rt/Admin/CustomFields', 'View/Edit ticketing custom fields' ], 
  'Ticketing Global'     => [ $fsurl.'rt/Admin/Global', 'View/Edit ticketing configuration applicable to all queues' ], 
  #"System Configuraiton"?  useless, just makes people report errors about missing Module::Versions::Report #'Ticketing Tools'     => [ $fsurl.'rt/Admin/Tools', '' ], 
;

tie my %config_dialup, 'Tie::IxHash',
  'Access numbers' => [ $fsurl.'browse/svc_acct_pop.cgi', 'Points of Presence' ],
;

tie my %config_broadband, 'Tie::IxHash',
  'Routers'        => [ $fsurl.'browse/router.cgi', 'Broadband access routers' ],
  'Address blocks' => [ $fsurl.'browse/addr_block.cgi', 'Manage address blocks and block assignments to broadband routers' ],
;

tie my %config_phone, 'Tie::IxHash',
  'View/Edit phone device types' => [ $fsurl.'browse/part_device.html', 'Phone device types' ],
;

tie my %config_misc, 'Tie::IxHash';
$config_misc{'Message templates'} = [ $fsurl.'browse/msg_template.html', 'Templates for customer notices' ]
  if $curuser->access_right('Edit templates')
  || $curuser->access_right('Edit global templates')
  || $curuser->access_right('Configuration');
$config_misc{'Tags'} = [ $fsurl.'browse/part_tag.html', '' ]
  if $curuser->access_right('Configuration');
$config_misc{'Advertising sources'} = [ $fsurl.'browse/part_referral.html', 'Where a customer heard about your service.' ]
  if $curuser->access_right('Edit advertising sources')
  || $curuser->access_right('Edit global advertising sources');
if ( $curuser->access_right('Configuration') ) {
  $config_misc{'Virtual fields'} = [ $fsurl.'browse/part_virtual_field.cgi', 'Locally defined fields', ];
  $config_misc{'Error catalog'} = [ $fsurl.'browse/msgcat.cgi', 'Change error messages and other customizable labels' ];
}
$config_misc{'Inventory classes and inventory'} = [ $fsurl.'browse/inventory_class.html', 'Setup inventory classes and stock inventory' ]
  if $curuser->access_right('Edit inventory')
  || $curuser->access_right('Edit global inventory')
  || $curuser->access_right('Configuration');

tie my %config_menu, 'Tie::IxHash';
if ( $curuser->access_right('Configuration' ) ) {
  %config_menu = (
    'Settings'      => [ $fsurl.'config/config-view.cgi', '' ],
    'separator'     => '', #its a separator!
    'Employees'     => [ \%config_employees, '' ],
  );
}
$config_menu{'Provisioning and services'} = [ \%config_export_svc, '' ]
  if $curuser->access_right('Configuration' );
$config_menu{'Packages'} = [ \%config_pkg, '' ]
  if    $curuser->access_right('Configuration' )
     || $curuser->access_right('Edit package definitions')
     || $curuser->access_right('Edit global package definitions');
$config_menu{'Customers'} = [ \%config_cust, '' ]
  if $curuser->access_right('Configuration');
$config_menu{'Resellers'} = [ \%config_agent, '' ]
  if $curuser->access_right('Configuration');
$config_menu{'Billing'} = [ \%config_billing, '' ]
  if $curuser->access_right('Edit billing events')
  || $curuser->access_right('Edit global billing events');
$config_menu{'Ticketing'} = [ \%config_ticketing, '' ]
  if $conf->config('ticket_system')
  && FS::TicketSystem->access_right(\%session, 'ShowConfigTab');
$config_menu{'Dialup'}  = [ \%config_dialup, ''    ]
  if ( $curuser->access_right('Dialup configuration') );
$config_menu{'Broadband'} = [ \%config_broadband, ''    ]
  if ( $curuser->access_right('Broadband configuration') );
$config_menu{'Phone'}  = [ \%config_phone, ''    ]
  if ( $curuser->access_right('Configuration') );
$config_menu{'Miscellaneous'} = [ \%config_misc, ''    ]
  if $curuser->access_right('Configuration' )
  || $curuser->access_right('Edit advertising sources')
  || $curuser->access_right('Edit global advertising sources');


my $wiki = 'http://www.freeside.biz/mediawiki/index.php';
my $doc_link = $conf->config('support-key')
                 ? "$wiki/Supported:Documentation"
                 : $curuser->access_right('Configuration')
                   ? "$wiki/Freeside:2.1:Documentation"
                   : "$wiki/Freeside:2.1:Documentation:User";

eval "use RT;"
  if $conf->config('ticket_system') eq 'RT_Internal';

tie my %help_menu, 'Tie::IxHash', 'Billing documentation' => [ $doc_link, 'Freeside documentation' ];
$help_menu{'Ticketing documentation'} = [ 'http://wiki.bestpractical.com/', 'Request Tracker Wiki' ]
  if $conf->config('ticket_system') eq 'RT_Internal';
$help_menu{'separator'} = '';
$help_menu{"About Freeside v$FS::VERSION"} = [ "javascript:about_freeside()", '' ];
$help_menu{"About RT v$RT::VERSION"} = [ 'http://www.bestpractical.com/rt', 'Request Tracker Homepage' ]
  if $conf->config('ticket_system') eq 'RT_Internal';


tie my %menu, 'Tie::IxHash',
  'Billing Main'   => [ $fsurl, 'Billing start page', ],
;
if ( $conf->config('ticket_system') ) {
  $menu{'Ticketing Main'} =
    [ 
      ( $conf->config('ticket_system') eq 'RT_External'
        ? FS::TicketSystem->baseurl()
        : $fsurl.'rt/'
      ),
      'Ticketing start page',
    ],
}
$menu{'New prospect'} = [ $fsurl.'edit/prospect_main.html', 'Add a new prospect' ]
  if $curuser->access_right('New prospect');
$menu{'New customer'} = [ $fsurl.'edit/cust_main.cgi', 'Add a new customer' ]
  if $curuser->access_right('New customer');
$menu{'Reports'} = [ \%report_menu, 'Lists, reporting and graphing' ]
  if keys %report_menu;
$menu{'Tools'} = [ \%tools_menu, 'Tools' ]
  if keys %tools_menu;
$menu{'Configuration'} = [ \%config_menu, 'Configuraiton and setup' ]
  if $curuser->access_right('Configuration')
  || $curuser->access_right('Edit package definitions')
  || $curuser->access_right('Edit global package definitions')
  || $curuser->access_right('Edit billing events')
  || $curuser->access_right('Edit global billing events')
  || $curuser->access_right('Dialup configuration')
  || $curuser->access_right('Broadband configuration')
  || $curuser->access_right('Phone configuration')
  || $curuser->access_right('Edit advertising sources')
  || $curuser->access_right('Edit global advertising sources');
$menu{'Help'} = [ \%help_menu, '' ];


use vars qw($gmenunum);
$gmenunum = 0;

sub submenu {
  my($submenu, $title) = @_;
  my $menunum = $gmenunum++;

  #return two args: html, menuname

  "var myMenu$menunum = new WebFXMenu;\n".
  #"myMenu$menunum.useAutoPosition = true;\n".
#  "myMenu$menunum.emptyText = '$title';\n".
  "myMenu$menunum.emptyText = '';\n".

  (
    join("\n", map {

      if ( !ref( $submenu->{$_} ) ) {

        "myMenu$menunum.add(new WebFXMenuSeparator());";

      } else {

        my($url_or_submenu, $tooltip ) = @{ $submenu->{$_} };
        if ( ref($url_or_submenu) ) {

          my($subhtml, $submenuname ) = submenu($url_or_submenu, $_); #mmm, recursion

          "$subhtml\n".
          "myMenu$menunum.add(new WebFXMenuItem(\"$_\", null, \"$tooltip\", $submenuname ));";

        } else {

          "myMenu$menunum.add(new WebFXMenuItem(\"$_\", \"$url_or_submenu\", \"$tooltip\" ));";

        }

      }

    } keys %$submenu )
  ). "\n".
  "myMenu$menunum.width = 256;\n",

  "myMenu$menunum";

}

</%init>