Issues (462)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/grid/ChargeGridView.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\grid;
12
13
use hipanel\grid\CurrencyColumn;
14
use hipanel\grid\MainColumn;
15
use hipanel\modules\client\grid\ClientColumn;
16
use hipanel\modules\finance\logic\bill\QuantityFormatterFactoryInterface;
17
use hipanel\modules\finance\models\Charge;
18
use hipanel\modules\finance\models\ChargeSearch;
19
use hipanel\modules\finance\widgets\BillType;
20
use hipanel\modules\finance\widgets\BillTypeFilter;
21
use hipanel\modules\finance\widgets\LinkToObjectResolver;
22
use hipanel\widgets\IconStateLabel;
23
use hiqdev\combo\StaticCombo;
24
use hiqdev\higrid\DataColumn;
25
use Yii;
26
use yii\helpers\Html;
27
28
/**
29
 * Class ChargeGridView.
30
 *
31
 * @author Dmytro Naumenko <[email protected]>
32
 */
33
class ChargeGridView extends \hipanel\grid\BoxedGridView
34
{
35
    /**
36
     * @var QuantityFormatterFactoryInterface
37
     */
38
    private $formatterFactory;
39
40
    /**
41
     * ChargeGridView constructor.
42
     *
43
     * @param QuantityFormatterFactoryInterface $formatterFactory
44
     * @param array $config
45
     */
46
    public function __construct(QuantityFormatterFactoryInterface $formatterFactory, array $config = [])
47
    {
48
        parent::__construct($config);
49
        $this->formatterFactory = $formatterFactory;
50
    }
51
52
    public function columns()
53
    {
54
        return array_merge(parent::columns(), [
55
            'label' => [
56
                'attribute' => 'label_ilike',
57
                'sortAttribute' => 'label_ilike',
58
                'label' => Yii::t('hipanel', 'Description'),
59
                'value' => function (Charge $model): string {
60
                    return $model->label ?? '';
61
                },
62
            ],
63
            'tariff' => [
64
                'attribute' => 'tariff_id',
65
                'label' => Yii::t('hipanel', 'Plan'),
66
                'filter' => false,
67
                'format' => 'html',
68
                'value' => function (Charge $model): string {
69
                    return $this->tariffLink($model);
70
                },
71
            ],
72
            'type_label' => [
73
                'label' => Yii::t('hipanel', 'Type'),
74
                'format' => 'raw',
75
                'value' => function (Charge $model) {
76
                    return BillType::widget([
77
                        'model' => $model,
78
                        'field' => 'ftype',
79
                        'labelField' => 'type_label',
80
                    ]);
81
                },
82
                'filterAttribute' => 'type',
83
                'filter' => function (DataColumn $column, ChargeSearch $filterModel): string {
84
                    return BillTypeFilter::widget([
85
                        'options' => ['class' => 'form-control text-right', 'style' => 'max-width: 12em'],
86
                        'attribute' => 'ftype',
87
                        'model' => $filterModel,
88
                    ]);
89
                },
90
            ],
91
            'sum' => [
92
                'class' => CurrencyColumn::class,
93
                'attribute' => 'sum',
94
                'sortAttribute' => 'sum',
95
                'colors' => ['danger' => 'warning'],
96
                'headerOptions' => ['class' => 'text-right'],
97
                'filter' => false,
98
                'contentOptions' => function ($model) {
99
                    return ['class' => 'text-right' . ($model->sum > 0 ? ' text-bold' : '')];
100
                },
101
            ],
102
            'name' => [
103
                'attribute' => 'name_ilike',
104
                'label' => Yii::t('hipanel', 'Object'),
105
                'format' => 'raw',
106
                'value' => function (Charge $model) {
107
                    $result = LinkToObjectResolver::widget([
108
                        'model' => $model,
109
                        'idAttribute' => 'object_id',
110
                        'typeAttribute' => 'class',
111
                        'labelAttribute' => 'name',
112
                    ]) . ($model->label ? " &ndash; $model->label" : '');
113
114
                    if ($model->commonObject->id !== null && $model->commonObject->id !== $model->latestCommonObject->id) {
115
                        $result .= ' ' . Html::tag(
116
                            'span',
117
                            Yii::t('hipanel:finance', 'Now it is in {objectLink}', [
118
                                'objectLink' => LinkToObjectResolver::widget([
119
                                    'model'          => $model->latestCommonObject,
120
                                    'idAttribute'    => 'id',
121
                                    'labelAttribute' => 'name',
122
                                    'typeAttribute'  => 'type',
123
                                ]),
124
                            ]),
125
                            ['class' => 'badge', 'style' => 'background-color: #f89406;']
126
                        );
127
                    }
128
129
                    return $result;
130
                },
131
            ],
132
            'quantity' => [
133
                'attribute' => 'quantity',
134
                'format' => 'raw',
135
                'filter' => false,
136
                'value' => function (Charge $model) {
137
                    return $this->renderQuantity($model);
138
                },
139
            ],
140
            'time' => [
141
                'format' => 'raw',
142
                'filter' => false,
143
                'contentOptions' => ['class' => 'text-nowrap'],
144
                'value' => function ($model) {
145
                    list($date, $time) = explode(' ', $model->time, 2);
146
147
                    return $model->isMonthly() && $time === '00:00:00'
148
                        ? Yii::$app->formatter->asDate($date, 'LLLL y')
149
                        : Yii::$app->formatter->asDateTime($model->time);
150
                },
151
            ],
152
            'is_payed' => [
153
                'attribute' => 'is_payed',
154
                'format' => 'raw',
155
                'enableSorting' => false,
156
                'filter' => $this->filterModel !== null
157
                    ? StaticCombo::widget([
158
                          'attribute' => 'is_payed',
159
                          'model' => $this->filterModel,
160
                          'data' => [
161
                              0 => Yii::t('hipanel:finance', 'Charge not paid'),
162
                              1 => Yii::t('hipanel:finance', 'Charge paid'),
163
                          ],
164
                          'hasId' => true,
165
                          'inputOptions' => ['id' => 'is_payed'],
166
                      ])
167
                    : false,
168
                'contentOptions' => ['class' => 'text-center'],
169
                'headerOptions' => ['class' => 'text-center'],
170
                'value' => static function (Charge $model) {
171
                    return IconStateLabel::widget([
172
                        'model' => $model,
173
                        'attribute' => 'is_payed',
174
                        'icons' => ['fa-check', 'fa-times'],
175
                        'colors' => ['#00a65a', '#dd4b39'],
176
                        'messages' => [
177
                            Yii::t('hipanel:finance', 'Charge paid'),
178
                            Yii::t('hipanel:finance', 'Charge not paid'),
179
                        ],
180
                    ]);
181
                }
182
            ]
183
        ]);
184
    }
185
186
    /**
187
     * @param Charge $model
188
     * @return string|null
189
     */
190
    public function tariffLink(Charge $model): ?string
191
    {
192
        $canSeeLink = Yii::$app->user->can('plan.create');
193
194
        return $canSeeLink ? Html::a($model->tariff, ['@plan/view', 'id' => $model->tariff_id]) : $model->tariff;
0 ignored issues
show
The property tariff_id does not seem to exist. Did you mean tariff?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
195
    }
196
197
    /**
198
     * @return string
199
     */
200
    private function renderQuantity(Charge $charge): string
201
    {
202
        $formatter = $this->formatterFactory->forCharge($charge);
203
204
        if ($formatter !== null) {
205
            return Html::tag('nobr', Html::tag('b', $formatter->format()));
206
        }
207
208
        return '';
209
    }
210
}
211