Issues (2963)

includes/html/modal/new_bill.inc.php (1 issue)

1
<?php
2
/*
3
 * LibreNMS
4
 *
5
 * Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
6
 *
7
 * This program is free software: you can redistribute it and/or modify it
8
 * under the terms of the GNU General Public License as published by the
9
 * Free Software Foundation, either version 3 of the License, or (at your
10
 * option) any later version.  Please see LICENSE.txt at the top level of
11
 * the source code distribution for details.
12
 */
13
14
use LibreNMS\Config;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Config. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
16
if (Auth::user()->hasGlobalAdmin()) {
17
    require 'includes/html/javascript-interfacepicker.inc.php';
18
19
    $port_device_id = -1;
20
    if (is_numeric($vars['port'])) {
21
        $port = dbFetchRow('SELECT * FROM `ports` AS P, `devices` AS D WHERE `port_id` = ? AND D.device_id = P.device_id', [$vars['port']]);
22
        $bill_data['bill_name'] = $port['port_descr_descr'];
23
        $bill_data['bill_ref'] = $port['port_descr_circuit'];
24
        $bill_data['bill_notes'] = $port['port_descr_speed'];
25
        $port_device_id = $port['device_id'];
26
    } ?>
27
28
 <div class="modal fade bs-example-modal-sm" id="create-bill" tabindex="-1" role="dialog" aria-labelledby="Create" aria-hidden="true">
29
    <div class="modal-dialog">
30
      <div class="modal-content">
31
        <div class="modal-header">
32
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
33
          <h4 class="modal-title" id="Create">Add Traffic Bill</h4>
34
        </div>
35
        <div class="modal-body">
36
            <form method="post" role="form" action="bills/" class="form-horizontal alerts-form">
37
                <?php echo csrf_field() ?>
38
                <input type="hidden" name="addbill" value="yes" />
39
40
                <div class="form-group">
41
                    <label class="col-sm-4 control-label" for="device">Device</label>
42
                    <div class="col-sm-8">
43
                        <select class="form-control input-sm" id="device" name="device" onchange="getInterfaceList(this)"></select>
44
                        <script type="text/javascript">
45
                            init_select2('#device', 'device', {}, <?php echo "{id: $port_device_id, text: '" . format_hostname($device) . "'}"; ?>, '', {dropdownParent: $('#create-bill .modal-content')});
46
                        </script>
47
                    </div>
48
                </div>
49
                <div class="form-group">
50
                    <label class="col-sm-4 control-label" for="port_id">Port</label>
51
                    <div class="col-sm-8">
52
                        <select class="form-control input-sm" id="port_id" name="port_id">
53
                        <?php
54
                        if (is_array($port)) {
55
                            // Need to pre-populate port as we've got a port pre-selected
56
                            foreach (dbFetch('SELECT * FROM ports WHERE device_id = ?', [$port_device_id]) as $interface) {
57
                                $interface = cleanPort($interface);
58
                                $string = $interface['label'] . ' - ' . \LibreNMS\Util\Clean::html($interface['ifAlias'], []);
59
                                $selected = $interface['port_id'] === $port['port_id'] ? ' selected' : '';
60
                                echo "<option value='${interface['port_id']}' $selected>$string</option>\n";
61
                            }
62
                        } ?>
63
                        </select>
64
                    </div>
65
                </div>
66
67
    <?php
68
    if (Config::get('billing.95th_default_agg') == 1) {
69
        $bill_data['dir_95th'] = 'agg';
70
    } else {
71
        $bill_data['dir_95th'] = 'in';
72
    }
73
    $bill_data['bill_type'] = 'cdr';
74
    $quota = ['select_gb' => ' selected'];
75
    $cdr = ['select_mbps' => ' selected'];
76
    include 'includes/html/pages/bill/addoreditbill.inc.php'; ?>
77
                <div class="form-group">
78
                  <div class="col-sm-offset-4 col-sm-4">
79
                    <button type="submit" class="btn btn-primary"><i class="fa fa-check"></i> Add Bill</button>
80
                  </div>
81
                </div>
82
83
            </form>
84
        </div>
85
      </div>
86
    </div>
87
</div>
88
89
    <?php
90
}
91