Issues (132)

Security Analysis    not enabled

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

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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.

class/Mastop.php (6 issues)

1
<?php
2
3
namespace XoopsModules\Mastopgo2;
4
5
### =============================================================
6
### Mastop InfoDigital - Paixão por Internet
7
### =============================================================
8
### Classe MÃE
9
### =============================================================
10
### Developer: Fernando Santos (topet05), [email protected]
11
### Copyright: Mastop InfoDigital © 2003-2007
12
### -------------------------------------------------------------
13
### www.mastop.com.br
14
### =============================================================
15
###
16
### =============================================================
17
use Xmf\Request;
18
19
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
20
21
if (!class_exists('Mastop')) {
22
    /**
23
     * Class Mastop
24
     */
25
    class Mastop extends \XoopsObject
26
    {
27
        public $db;
28
        public $tabela;
29
        public $id;
30
        public $total    = 0;
31
        public $afetadas = 0;
32
33
        // construtor da classe
34
35
        /**
36
         * Mastop constructor.
37
         */
38
        public function __construct()
39
        {
40
            // Não usado diretamente
41
        }
42
43
        /**
44
         * @return bool|mixed
45
         */
46
        public function store()
47
        {
48
            if (!$this->cleanVars()) {
49
                return false;
50
            }
51
            $myts = \MyTextSanitizer::getInstance();
52
            foreach ($this->cleanVars as $k => $v) {
53
                $indices[] = $k;
54
                $valores[] = $v;
55
                //${$k} =$v;
56
            }
57
58
            if (null === $this->getVar($this->id) || 0 == $this->getVar($this->id)) {
59
                $sql = 'INSERT INTO ' . $this->tabela . ' ( ';
60
61
62
                if (0 == $valores[0]){
63
//                    $sql .= $indices[1];
64
                    for ($i = 1, $iMax = count($indices); $i < $iMax; ++$i) {
65
                            $sql .= $indices[$i];
66
                        if ($i != (count($indices) - 1)) {
67
                            $sql .= ',';
68
                        }
69
                    }
70
                } else {
71
                   $sql .= implode(', ', $indices);
72
                }
73
74
                $sql .= ') VALUES (';
75
76
                if (0 == $valores[0]){
77
                    for ($i = 1, $iMax = count($valores); $i < $iMax; ++$i) {
78
                        if (!is_int($valores[$i])) {
79
                            $sql .= $this->db->quoteString($valores[$i]);
80
                        } else {
81
                            $sql .= $valores[$i];
82
                        }
83
                        if ($i != (count($valores) - 1)) {
84
                            $sql .= ',';
85
                        }
86
                    }
87
                } else {
88
                    for ($i = 0, $iMax = count($valores); $i < $iMax; ++$i) {
89
                        if (!is_int($valores[$i])) {
90
                            $sql .= $this->db->quoteString($valores[$i]);
91
                        } else {
92
                            $sql .= $valores[$i];
93
                        }
94
                        if ($i != (count($valores) - 1)) {
95
                            $sql .= ',';
96
                        }
97
                    }
98
                }
99
100
101
                $sql .= ')';
102
            } else {
103
                $sql = 'UPDATE ' . $this->tabela . ' SET ';
104
                for ($i = 1, $iMax = count($valores); $i < $iMax; ++$i) {
105
                    $sql .= $indices[$i] . '=';
106
                    if (!is_int($valores[$i])) {
107
                        $sql .= $this->db->quoteString($valores[$i]);
108
                    } else {
109
                        $sql .= $valores[$i];
110
                    }
111
                    if ($i != (count($valores) - 1)) {
112
                        $sql .= ',';
113
                    }
114
                }
115
                $sql .= ' WHERE ' . $this->id . ' = ' . $this->getVar($this->id);
116
            }
117
            //echo $sql;
118
            $result         = $this->db->query($sql);
119
            $this->afetadas = $this->db->getAffectedRows();
120
            if (!$result) {
121
                $this->setErrors('Erro ao gravar dados na Base de Dados. <br>' . $this->db->error());
122
123
                return false;
124
            }
125
            if (null === $this->getVar($this->id) || 0 == $this->getVar($this->id)) {
126
                $this->setVar($this->id, $this->db->getInsertId());
127
128
                return $this->db->getInsertId();
129
            }
130
131
            return $this->getVar($this->id);
132
        }
133
134
        /**
135
         * @param      $campo
136
         * @param      $valor
137
         * @param null $criterio
138
         *
139
         * @return bool
140
         */
141
        public function atualizaTodos($campo, $valor, $criterio = null)
142
        {
143
            $set_clause = is_numeric($valor) ? $campo . ' = ' . $valor : $campo . ' = ' . $this->db->quoteString($valor);
144
            $sql        = 'UPDATE ' . $this->tabela . ' SET ' . $set_clause;
145
            if (isset($criterio) && $criterio instanceof \CriteriaElement) {
146
                $sql .= ' ' . $criterio->renderWhere();
147
            }
148
            if (!$result = $this->db->query($sql)) {
149
                return false;
150
            }
151
152
            return true;
153
        }
154
155
        /**
156
         * @return bool
157
         */
158
        public function delete()
159
        {
160
            $sql = sprintf('DELETE FROM `%s` WHERE ' . $this->id . ' = %u', $this->tabela, $this->getVar($this->id));
161
            if (!$this->db->query($sql)) {
162
                return false;
163
            }
164
            $this->afetadas = $this->db->getAffectedRows();
165
166
            return true;
167
        }
168
169
        /**
170
         * @param null $criterio
171
         *
172
         * @return bool
173
         */
174
        public function deletaTodos($criterio = null)
175
        {
176
            $sql = 'DELETE FROM ' . $this->tabela;
177
            if (isset($criterio) && $criterio instanceof \CriteriaElement) {
178
                $sql .= ' ' . $criterio->renderWhere();
179
            }
180
            if (!$result = $this->db->query($sql)) {
181
                return false;
182
            }
183
            $this->afetadas = $this->db->getAffectedRows();
184
185
            return true;
186
        }
187
188
        /**
189
         * @param $id
190
         *
191
         * @return bool
192
         */
193
        public function load($id)
194
        {
195
            $sql   = 'SELECT * FROM ' . $this->tabela . ' WHERE ' . $this->id . '=' . $id . ' LIMIT 1';
196
            $myrow = $this->db->fetchArray($this->db->query($sql));
197
            if ($myrow && is_array($myrow)) {
198
                $this->assignVars($myrow);
199
200
                return true;
201
            }
202
203
            return false;
204
        }
205
206
        /**
207
         * @param null $criterio
208
         * @param bool $objeto
209
         * @param null $join
210
         *
211
         * @return array|bool
212
         */
213
        public function pegaTudo($criterio = null, $objeto = true, $join = null)
214
        {
215
            $ret    = [];
216
            $limit  = $start = 0;
217
            $classe = get_class($this);
218
            if (!$objeto) {
219
                $sql = 'SELECT ' . $this->id . ' FROM ' . $this->tabela;
220
                if (isset($criterio) && $criterio instanceof \CriteriaElement) {
221
                    $sql .= ' ' . $criterio->renderWhere();
222
                    if ('' !== $criterio->getSort()) {
223
                        $sql .= ' ORDER BY ' . $criterio->getSort() . ' ' . $criterio->getOrder();
224
                    }
225
                    $limit = $criterio->getLimit();
226
                    $start = $criterio->getStart();
227
                }
228
                $result      = $this->db->query($sql, $limit, $start);
229
                $this->total = $this->db->getRowsNum($result);
230
                if ($this->total > 0) {
231
                    while (false !== ($myrow = $this->db->fetchArray($result))) {
232
                        $ret[] = $myrow[$this->id];
233
                    }
234
235
                    return $ret;
236
                }
237
238
                return false;
239
            }
240
            $sql = 'SELECT ' . $this->tabela . '.* FROM ' . $this->tabela . (!empty($join) ? ' ' . $join : '');
241
            if (isset($criterio) && $criterio instanceof \CriteriaElement) {
242
                $sql .= ' ' . $criterio->renderWhere();
243
                if ('' !== $criterio->getSort()) {
244
                    $sql .= ' ORDER BY ' . $criterio->getSort() . ' ' . $criterio->getOrder();
245
                }
246
                $limit = $criterio->getLimit();
247
                $start = $criterio->getStart();
248
            }
249
            $result      = $this->db->query($sql, $limit, $start);
250
            $this->total = $this->db->getRowsNum($result);
251
            if ($this->total > 0) {
252
                while (false !== ($myrow = $this->db->fetchArray($result))) {
253
                    $ret[] = new $classe($myrow);
254
                }
255
256
                return $ret;
257
            }
258
259
            return false;
260
        }
261
262
        /**
263
         * @param $url
264
         * @param $campos
265
         *
266
         * @return string
267
         */
268
        public function administracao($url, $campos)
269
        {
270
            $criterio = new \CriteriaCompo();
271
            if (!empty($campos['precrit']['campo']) && !empty($campos['precrit']['valor'])) {
272
                $precrit_hidden = '';
273
                $precrit_url    = '';
274
                foreach ($campos['precrit']['campo'] as $k => $v) {
275
                    $hiddens[$v] = $campos['precrit']['valor'][$k];
276
                    $criterio->add(new \Criteria($v, $campos['precrit']['valor'][$k], '=', $this->tabela));
277
                    $precrit_hidden .= "<input type='hidden' name='" . $v . "' value='" . $campos['precrit']['valor'][$k] . "'>";
278
                    $precrit_url    .= '&' . $v . '=' . $campos['precrit']['valor'][$k];
279
                }
280
            } else {
281
                $precrit_hidden = '';
282
                $precrit_url    = '';
283
            }
284
            if (!empty($campos['checks']) && Request::hasVar('group_action', 'POST') && is_array(Request::getArray('checks', '', 'POST'))
285
                && 'group_del_ok' === Request::getString('group_action', '', 'POST')) {
286
                $chks   = Request::getArray('checks', [], 'POST');
287
                $classe = get_class($this);
288
                foreach ($chks as $k => $v) {
289
                    $nova = new $classe($k);
290
                    if (!empty($campos['group_del_function']) && is_array($campos['group_del_function'])) {
291
                        foreach ($campos['group_del_function'] as $k => $v) {
292
                            $nova->$v();
293
                        }
294
                    }
295
                    $nova->delete();
296
                }
297
            }
298
            if (!empty($campos['checks']) && Request::hasVar('group_action', 'POST')
299
                && 'group_del' === Request::getString('group_action', '', 'POST')
300
                && is_array(Request::getArray('checks', '', 'POST'))) {
301
                $chks = Request::getArray('checks', [], 'POST');
302
                foreach ($chks as $k => $v) {
303
                    $hiddens['checks[' . $k . ']'] = 1;
304
                }
305
                $hiddens['op']           = $campos['op'];
306
                $hiddens['group_action'] = 'group_del_ok';
307
308
                return xoops_confirm($hiddens, $url, $campos['lang']['group_del_sure'], _SUBMIT) . '<br>';
309
            }
310
            $busca_url = '';
311
            if (Request::hasVar('busca', 'GET')) {
312
                foreach (Request::getArray('busca', [], 'GET') as $k => $v) {
313
                    if ('' !== $v && '-1' != $v && in_array($k, $campos['nome'])) {
314
                        if (is_numeric($v)) {
315
                            $criterio->add(new \Criteria($k, $v, '=', $this->tabela));
316
                        } elseif (is_array($v)) {
317
                            if (!empty($v['dday']) || !empty($v['dmonth']) || !empty($v['dyear']) || !empty($v['aday'])
318
                                || !empty($v['amonth'])
319
                                || !empty($v['ayear'])) {
320
                                $dday   = !empty($v['dday']) ? $v['dday'] : 1;
321
                                $dmonth = !empty($v['dmonth']) ? $v['dmonth'] : 1;
322
                                $dyear  = !empty($v['dyear']) ? $v['dyear'] : 1;
323
                                $aday   = !empty($v['aday']) ? $v['aday'] : 1;
324
                                $amonth = !empty($v['amonth']) ? $v['dmonth'] : 1;
325
                                $ayear  = !empty($v['ayear']) ? $v['ayear'] : date('Y');
326
                                $ddate  = mktime(0, 0, 0, $v['dmonth'], $v['dday'], $v['dyear']);
327
                                $adate  = mktime(0, 0, 0, $v['amonth'], $v['aday'], $v['ayear']);
328
                                $criterio->add(new \Criteria($k, $ddate, '>=', $this->tabela));
329
                                $criterio->add(new \Criteria($k, $adate, '<=', $this->tabela));
330
                            }
331
                        } else {
332
                            $criterio->add(new \Criteria($k, "%$v%", 'LIKE', $this->tabela));
333
                        }
334
                        $busca_url .= (!is_array($v)) ? '&busca[' . $k . ']=' . $v : '&busca['
335
                                                                                     . $k
336
                                                                                     . '][dday]='
337
                                                                                     . $v['dday']
338
                                                                                     . '&busca['
339
                                                                                     . $k
340
                                                                                     . '][dmonth]='
341
                                                                                     . $v['dmonth']
342
                                                                                     . '&busca['
343
                                                                                     . $k
344
                                                                                     . '][dyear]='
345
                                                                                     . $v['dyear']
346
                                                                                     . '&busca['
347
                                                                                     . $k
348
                                                                                     . '][aday]='
349
                                                                                     . $v['aday']
350
                                                                                     . '&busca['
351
                                                                                     . $k
352
                                                                                     . '][amonth]='
353
                                                                                     . $v['amonth']
354
                                                                                     . '&busca['
355
                                                                                     . $k
356
                                                                                     . '][ayear]='
357
                                                                                     . $v['ayear'];
358
                    }
359
                }
360
            }
361
            $limit = (Request::hasVar('limit', 'GET') && Request::getInt('limit', 0, 'GET') <= 100) ? Request::getInt('limit', 0, 'GET') : 15;
362
            $criterio->setLimit($limit);
363
            $start = Request::getInt('start', 0, 'GET');
364
            $criterio->setStart($start);
365
            $order = Request::getInt('order', 'DESC', 'GET');
366
            $criterio->setOrder($order);
367
            $sort = (Request::hasVar('sort', 'GET')
368
                     && in_array(Request::getString('sort', '', 'GET'), $campos['nome'])) ? $_GET['sort'] : (empty($campos['sort']) ? $campos['nome'][1] : $campos['sort']);
369
            $criterio->setSort($sort);
370
            $form        = !empty($campos['form']) ? 1 : 0;
371
            $checks      = !empty($campos['checks']) ? 1 : 0;
372
            $op          = !empty($campos['op']) ? $campos['op'] : '';
373
            $norder      = ('ASC' === $order) ? 'DESC' : 'ASC';
0 ignored issues
show
The condition 'ASC' === $order is always false.
Loading history...
374
            $colunas     = count($campos['rotulo']);
375
            $colunas     = !empty($campos['checks']) ? $colunas + 1 : $colunas;
376
            $colunas     = !empty($campos['botoes']) ? $colunas + 1 : $colunas;
377
            $url_colunas = $url . '?op=' . $op . '&limit=' . $limit . '&start=' . $start . $busca_url . $precrit_url;
378
            $url_full_pg = $url . '?op=' . $op . '&limit=' . $limit . '&sort=' . $sort . '&order=' . $order . $busca_url . $precrit_url;
379
            $contar      = $this->contar($criterio);
380
            $ret         = '<style type="text/css">
381
            .hd {background-color: #c2cdd6; padding: 5px; font-weight: bold;}
382
            tr.bx td {background-color: #DFDFDF; padding: 5px; font-weight: bold; color: #000000;}
383
            tr.hd td {background-image:url("../assets/images/bg.gif"); padding: 5px; font-weight: bold; border:1px solid #C0C0C0; color: #000000;}
384
            tr.hd td.hds {background-image:url("../assets/images/bgs.gif"); padding: 5px; font-weight: bolder; border:1px solid #C0C0C0; border-top: 1px solid #000000; color: #000000;}
385
            tr.hd td a{color: #1D5F9F;}
386
            .fundo1 {background-color: #DFDFDF; padding: 4px;}
387
            tr.fundo1 td {background-color: #DFDFDF; padding: 4px; border:1px solid #C0C0C0;}
388
            .fundo2 {background-color: #E0E8EF; padding: 4px;}
389
            tr.fundo2 td {background-color: #E0E8EF; padding: 4px; border:1px solid #C0C0C0;}
390
            .neutro {background-color: #FFFFFF; padding: 4px;}
391
            tr.neutro td {background-color: #FFFFFF; padding: 4px; border:1px solid #9FD4FF;}
392
            </style>
393
            <script language="javascript" type="text/javascript">
394
              function exibe_esconde(tipo) {
395
                var coisinha = document.getElementById(tipo);
396
                if (coisinha.style.display == "") {
397
                  coisinha.style.display = "none";
398
                } else {
399
                  coisinha.style.display = "";
400
                }
401
              }
402
403
              function esconde_menus() {
404
                var els = document.getElementsByTagName("TD");
405
                var elsLen = els.length;
406
                var pattern = new RegExp("(^|\\s)bg5(\\s|$)");
407
                for (i = 0, j = 0; i < elsLen; i++) {
408
                  if (pattern.test(els[i].className) && els[i].colSpan != 3 && els[i].colSpan != 4) {
409
                    if (els[i].style.display=="") {
410
                      els[i].style.display="none";
411
                    } else {
412
                      els[i].style.display="";
413
                    }
414
                  }
415
                }
416
              }
417
418
              function changecheck() {
419
                var f = document.getElementById("update_form");
420
                var inputs = document.getElementsByTagName("input");
421
                for (var t = 0;t < inputs.length;t++) {
422
                  if (inputs[t].type == "checkbox" && inputs[t].id != "checkAll") {
423
                    inputs[t].checked = !inputs[t].checked;
424
                    inputs[t].onclick();
425
                  }
426
                }
427
428
                return true;
429
              }' . ($checks ? '
430
431
              function verificaChecks() {
432
                var grp_sel = document.getElementById("group_action");
433
                if(grp_sel.options[grp_sel.selectedIndex].value == 0) return true;
434
                var inputs = document.getElementsByTagName("input");
435
                for (var t = 0;t < inputs.length;t++) {
436
                  if(inputs[t].type == "checkbox" && inputs[t].checked === true) return true;
437
                }
438
                alert("' . $campos['lang']['group_erro_sel'] . '");
439
440
                return false;
441
              }
442
443
              function marcaCheck(linha, ckbx, classe) {
444
                var tr = document.getElementById(linha);
445
                var valor = document.getElementById(ckbx).checked;
446
                //alert(tr.onmouseout);
447
                if (valor === true) {
448
                  tr.className = "neutro";
449
                  tr.onmouseout = function(){};
450
451
                  return true;
452
                } else {
453
                  tr.className = classe;
454
                  tr.onmouseout = function(){this.className=classe};
455
456
                  return true;
457
                }
458
              }
459
            </script>' : '</script>');
460
461
            $ret .= !empty($campos['noadminmenu']) ? '
462
              <script language="javascript" type="text/javascript">
463
                if (window.addEventListener) window.addEventListener("load", esconde_menus, false) else if (window.attachEvent) window.attachEvent("onload", esconde_menus)
464
              </script>' : '';
465
466
            global $pathIcon16;
467
468
            $ret .= '
469
<table width="100%" border="0" cellspacing="0" class="outer">
470
<tr><td style="padding:5px; font-size:16px; border: 1px solid #C0C0C0; border-bottom:0px;"><div style="font-size:12px; text-align:right; float:right;">' . (empty($campos['nofilters']) ? '<a href="javascript:void(0);"  onclick="exibe_esconde(\'busca\');">'
471
                                                                                                                                                                                          . $campos['lang']['filtros']
472
                                                                                                                                                                                          . '</a>'
473
                                                                                                                                                                                          //                                                     .' - <a href="javascript:void(0);"  onclick="esconde_menus();">'
474
                                                                                                                                                                                          //                                                     . $campos['lang']['showhidemenu']
475
                                                                                                                                                                                          //                                                     . '</a>'
476
                                                                                                                                                                                          . '' : '') . '</div><b>' . $campos['lang']['titulo'] . '</b></td></tr>
477
<tr><td class="outer" style="background-color: #F3F2F2;"><div style="text-align: center;">';
478
            $ret .= "<form action='"
479
                    . $url
480
                    . "' method='GET' name='form_npag'>"
481
                    . $precrit_hidden
482
                    . '<b>'
483
                    . $campos['lang']['exibir']
484
                    . "&nbsp;&nbsp;<input type='text' name='limit' value='"
485
                    . $limit
486
                    . "' size='4' maxlength='3' style='text-align:center'>&nbsp;&nbsp;"
487
                    . $campos['lang']['por_pagina']
488
                    . '</b>';
489
            if (Request::hasVar('busca', 'GET')) {
490
                foreach (Request::getArray('busca', [], 'GET') as $k => $v) {
491
                    if ('' !== $v && '-1' != $v && !is_array($v)) {
492
                        $ret .= "<input type='hidden' name='busca[" . $k . "]' value='" . $v . "'>";
493
                    } elseif (is_array($v)) {
494
                        $ret .= "<input type='hidden' name='busca[" . $k . "][dday]' value='" . $v['dday'] . "'>";
495
                        $ret .= "<input type='hidden' name='busca[" . $k . "][dmonth]' value='" . $v['dmonth'] . "'>";
496
                        $ret .= "<input type='hidden' name='busca[" . $k . "][dyear]' value='" . $v['dyear'] . "'>";
497
                        $ret .= "<input type='hidden' name='busca[" . $k . "][aday]' value='" . $v['aday'] . "'>";
498
                        $ret .= "<input type='hidden' name='busca[" . $k . "][amonth]' value='" . $v['amonth'] . "'>";
499
                        $ret .= "<input type='hidden' name='busca[" . $k . "][ayear]' value='" . $v['ayear'] . "'>";
500
                    }
501
                }
502
            }
503
            $ret .= "<input type='hidden' name='op' value='" . $op . "'><input type='hidden' name='sort' value='" . $sort . "'><input type='hidden' name='order' value='" . $order . "'>";
504
            $ret .= "&nbsp;&nbsp;&nbsp;<input type='image' src='../assets/images/envia.gif' style='border:0; background-color:transparent' align='absmiddle'></form>";
505
            $ret .= "<table width='100%' border='0' cellspacing='0'>";
506
            $ret .= "<tbody><tr><td colspan='" . $colunas . "' align='right'>" . sprintf($campos['lang']['exibindo'], $start + 1, ((($start + $limit) < $contar) ? $start + $limit : $contar), $contar) . '</td></tr></tbody>';
507
            $ret .= "<tbody><tr class='hd'>";
508
            $ret .= $checks ? "<td align='center'><input type='checkbox' name='checkAll' id='checkAll' onclick='changecheck();'></td>" : '';
509
            foreach ($campos['rotulo'] as $k => $v) {
510
                $ret .= "<td nowrap='nowrap' align='center' " . (($sort == $campos['nome'][$k]
511
                                                                  && empty($campos['nosort'][$k])) ? "class='hds'" : '') . '>' . (empty($campos['nosort'][$k]) ? "<A HREF='"
512
                                                                                                                                                                 . $url_colunas
513
                                                                                                                                                                 . '&sort='
514
                                                                                                                                                                 . $campos['nome'][$k]
515
                                                                                                                                                                 . '&order='
516
                                                                                                                                                                 . $norder
517
                                                                                                                                                                 . "'>"
518
                                                                                                                                                                 . $v
519
                                                                                                                                                                 . ' '
520
                                                                                                                                                                 . (($sort
521
                                                                                                                                                                     == $campos['nome'][$k]) ? '<img src='
522
                                                                                                                                                                                               . $pathIcon16
523
                                                                                                                                                                                               . '/'
524
                                                                                                                                                                                               . $order
525
                                                                                                                                                                                               . ".png align='absmiddle'>" : '')
526
                                                                                                                                                                 . '</a></td>' : $v . '</td>');
527
            }
528
            $ret .= !empty($campos['botoes']) ? "<td align='center'>" . $campos['lang']['acao'] . '</td>' : '';
529
            $ret .= '</tr></tbody>';
530
            if (empty($campos['nofilters'])) {
531
                $ret .= "<form action='" . $url . "' method='GET' name='form_busca'><tbody><tr id='busca' " . (Request::hasVar('busca', 'GET') ? '' : "style='display:none'") . " class='neutro'>";
532
                $ret .= $checks ? '<td>&nbsp;</td>' : '';
533
                foreach ($campos['rotulo'] as $k => $v) {
534
                    $ret .= "<td align='center' nowrap='nowrap'>";
535
                    switch ($campos['tipo'][$k]) {
536
                        case 'none':
537
                            break;
538
                        case 'date':
539
                            $ret .= "<input type='text' name='busca["
540
                                    . $campos['nome'][$k]
541
                                    . "][dday]' size='2' maxlength='2' value="
542
                                    . (Request::hasVar('busca', 'GET')[$campos['nome'][$k]]['dday'] ? Request::getArray('busca', [], 'GET')[$campos['nome'][$k]]['dday'] : '')
543
                                    . "> <input type='text' name='busca["
544
                                    . $campos['nome'][$k]
545
                                    . "][dmonth]' size='2' maxlength='2' value="
546
                                    . (Request::hasVar('busca', 'GET')[$campos['nome'][$k]]['dmonth'] ? Request::getArray('busca', [], 'GET')[$campos['nome'][$k]]['dmonth'] : '')
547
                                    . "> <input type='text' name='busca["
548
                                    . $campos['nome'][$k]
549
                                    . "][dyear]' size='2' maxlength='4' value="
550
                                    . (Request::hasVar('busca', 'GET')[$campos['nome'][$k]]['dyear'] ? Request::getArray('busca', [], 'GET')[$campos['nome'][$k]]['dyear'] : '')
551
                                    . '><br>';
552
                            $ret .= "<input type='text' name='busca["
553
                                    . $campos['nome'][$k]
554
                                    . "][aday]' size='2' maxlength='2' value="
555
                                    . (Request::hasVar('busca', 'GET')[$campos['nome'][$k]]['aday'] ? Request::getArray('busca', [], 'GET')[$campos['nome'][$k]]['aday'] : '')
556
                                    . "> <input type='text' name='busca["
557
                                    . $campos['nome'][$k]
558
                                    . "][amonth]' size='2' maxlength='2' value="
559
                                    . (Request::hasVar('busca', 'GET')[$campos['nome'][$k]]['amonth'] ? Request::getArray('busca', [], 'GET')[$campos['nome'][$k]]['amonth'] : '')
560
                                    . "> <input type='text' name='busca["
561
                                    . $campos['nome'][$k]
562
                                    . "][ayear]' size='2' maxlength='4' value="
563
                                    . (Request::hasVar('busca', 'GET')[$campos['nome'][$k]]['ayear'] ? Request::getArray('busca', [], 'GET')[$campos['nome'][$k]]['ayear'] : '')
564
                                    . '>';
565
                            break;
566
                        case 'select':
567
                            $ret .= "<select name='busca[" . $campos['nome'][$k] . "]'><option value='-1'>" . _SELECT . '</option>';
568
                            foreach ($campos['options'][$k] as $x => $y) {
569
                                $ret .= "<option value='" . $x . "'";
570
                                $ret .= (isset(Request::getArray('busca', [], 'GET') [$campos['nome'][$k]])
571
                                         && Request::getArray('busca', [], 'GET') [$campos['nome'][$k]] == $x) ? ' selected' : '';
572
                                $ret .= '>' . $y . '</option>';
573
                            }
574
                            $ret .= '</select>';
575
                            break;
576
                        case 'simnao':
577
                            $ret .= "<select name='busca[" . $campos['nome'][$k] . "]'><option value='-1'>" . _SELECT . '</option>';
578
                            $ret .= "<option value='1'";
579
                            $ret .= (isset(Request::getArray('busca', [], 'GET') [$campos['nome'][$k]])
580
                                     && 1 == Request::getArray('busca', [], 'GET') [$campos['nome'][$k]]) ? ' selected' : '';
581
                            $ret .= '>' . _YES . '</option>';
582
                            $ret .= "<option value='0'";
583
                            $ret .= (isset(Request::getArray('busca', [], 'GET') [$campos['nome'][$k]])
584
                                     && 0 == Request::getArray('busca', [], 'GET') [$campos['nome'][$k]]) ? ' selected' : '';
585
                            $ret .= '>' . _NO . '</option>';
586
                            $ret .= '</select>';
587
                            break;
588
                        case 'text':
589
                        default:
590
                            $ret .= "<input type='text' name='busca["
591
                                    . $campos['nome'][$k]
592
                                    . "]' value='"
593
                                    . (isset(Request::getArray('busca', [], 'GET') [$campos['nome'][$k]]) ? Request::getArray('busca', [], 'GET') [$campos['nome'][$k]] : '')
594
                                    . "' size='"
595
                                    . (isset($campos['tamanho'][$k]) ? $campos['tamanho'][$k] : 20)
596
                                    . "'>";
597
                    }
598
                    if (empty($campos['botoes']) && $k == count($campos['rotulo'])) {
599
                        $ret .= " <input type='image' src='../assets/images/envia.gif' style='border:0; background-color:transparent' align='absmiddle'>";
600
                    }
601
                    $ret .= '</td>';
602
                }
603
                $ret .= !empty($campos['botoes']) ? "<td align='center'><input type='image' src='../assets/images/envia.gif' style='border:0; background-color:transparent'></td>" : '';
604
                $ret .= '</tr></tbody>';
605
                $ret .= $precrit_hidden . "<input type='hidden' name='op' value='" . $op . "'><input type='hidden' name='sort' value='" . $sort . "'><input type='hidden' name='order' value='" . $order . "'><input type='hidden' name='limit' value='" . $limit . "'></form>";
606
            }
607
            $registros = empty($campos['join']) ? $this->pegaTudo($criterio) : $this->pegaTudo($criterio, true, $campos['join']);
608
            if (!$registros || 0 == count($registros)) {
609
                $ret .= "<tbody><tr><td colspan='" . $colunas . "'><h2>" . $campos['lang']['semresult'] . '</h2></td></tr></tbody>';
610
                $ret .= "<tbody><tr class='bx'><td colspan='" . $colunas . "' align='left'>" . $this->paginar($url_full_pg, $criterio, $precrit_url) . '</td></tr></tbody>';
611
            } else {
612
                $ret .= ($form || $checks) ? "<form action='" . $url . "' method='POST' name='update_form' id='update_form' " . ($checks ? "onsubmit='return verificaChecks()'" : '') . '>' : '';
613
                foreach ($registros as $reg) {
614
                    $eod = (!isset($eod) || 'fundo1' === $eod) ? 'fundo2' : 'fundo1';
615
                    $ret .= "<tbody><tr id='tr_reg_" . $reg->getVar($reg->id) . "' class='" . $eod . "' onmouseover='this.className=\"neutro\";' onmouseout='this.className=\"" . $eod . "\"'>";
616
                    $ret .= $checks ? "<td align='center'><input type='checkbox' name='checks["
617
                                      . $reg->getVar($reg->id)
618
                                      . "]' id='checks["
619
                                      . $reg->getVar($reg->id)
620
                                      . "]' value='1' onclick='marcaCheck(\"tr_reg_"
621
                                      . $reg->getVar($reg->id)
622
                                      . '", "checks['
623
                                      . $reg->getVar($reg->id)
624
                                      . ']", "'
625
                                      . $eod
626
                                      . "\");'></td>" : '';
627
                    foreach ($campos['rotulo'] as $l => $f) {
628
                        $ret .= '<td>';
629
                        switch ($campos['tipo'][$l]) {
630
                            case 'none':
631
                                $ret .= empty($campos['show'][$l]) ? $reg->getVar($campos['nome'][$l]) : eval('return ' . $campos['show'][$l] . ';');
0 ignored issues
show
The use of eval() is discouraged.
Loading history...
632
                                break;
633
                            case 'date':
634
                                $ret .= (!empty($campos['show'][$l]) ? eval('return ' . $campos['show'][$l] . ';') : ((0 != $reg->getVar($campos['nome'][$l])
0 ignored issues
show
The use of eval() is discouraged.
Loading history...
635
                                                                                                                       && '' !== $reg->getVar($campos['nome'][$l])) ? date(_SHORTDATESTRING, $reg->getVar($campos['nome'][$l])) : ''));
636
                                break;
637
                            case 'select':
638
                                if ($form && empty($campos['show'][$l])) {
639
                                    $ret .= "<select name='campos[" . $reg->getVar($reg->id) . '][' . $campos['nome'][$l] . "]'>";
640
                                    foreach ($campos['options'][$l] as $x => $y) {
641
                                        $ret .= "<option value='" . $x . "'";
642
                                        $ret .= ($reg->getVar($campos['nome'][$l]) == $x) ? ' selected' : '';
643
                                        $ret .= '>' . $y . '</option>';
644
                                    }
645
                                    $ret .= '</select>';
646
                                } elseif (!empty($campos['show'][$l])) {
647
                                    $ret .= eval('return ' . $campos['show'][$l] . ';');
0 ignored issues
show
The use of eval() is discouraged.
Loading history...
648
                                } else {
649
                                    $ret .= isset($campos['options'][$l][$reg->getVar($campos['nome'][$l])]) ? $campos['options'][$l][$reg->getVar($campos['nome'][$l])] : $reg->getVar($campos['nome'][$l]);
650
                                }
651
                                break;
652
                            case 'simnao':
653
                                if ($form && empty($campos['show'][$l])) {
654
                                    $ret .= "<select name='campos[" . $reg->getVar($reg->id) . '][' . $campos['nome'][$l] . "]'>";
655
                                    $ret .= "<option value='1'";
656
                                    $ret .= (1 == $reg->getVar($campos['nome'][$l])) ? ' selected' : '';
657
                                    $ret .= '>' . _YES . '</option>';
658
                                    $ret .= "<option value='0'";
659
                                    $ret .= (0 == $reg->getVar($campos['nome'][$l])) ? ' selected' : '';
660
                                    $ret .= '>' . _NO . '</option>';
661
                                    $ret .= '</select>';
662
                                } elseif (!empty($campos['show'][$l])) {
663
                                    $ret .= eval('return ' . $campos['show'][$l] . ';');
0 ignored issues
show
The use of eval() is discouraged.
Loading history...
664
                                } else {
665
                                    $ret .= (1 == $reg->getVar($campos['nome'][$l])) ? _YES : ((0 == $reg->getVar($campos['nome'][$l])) ? _NO : $reg->getVar($campos['nome'][$l]));
666
                                }
667
                                break;
668
                            case 'text':
669
                            default:
670
671
                                //                                                            $bong = $campos['nome'][$l];
672
                                //                                                            $bong2 = $reg->getVar($campos['nome'][$l]);
673
                                //                                                            echo $bong . '---- 1 <br><br>';
674
                                //                                                            echo $bong2 .'---- 2<br><br>';
675
                                //                                                            echo 'show: ' . $campos['show'][$l] . '---- 3<br><br><br>';
676
677
                                $ret .= ($form && empty($campos['show'][$l])) ? ("<input type='text' name='campos["
678
                                                                                 . $reg->getVar($reg->id)
679
                                                                                 . ']['
680
                                                                                 . $campos['nome'][$l]
681
                                                                                 . "]' value='"
682
                                                                                 . $reg->getVar($campos['nome'][$l])
683
                                                                                 . "' size='"
684
                                                                                 . (isset($campos['tamanho'][$l]) ? $campos['tamanho'][$l] : 20)
685
                                                                                 . "'>")
686
687
                                    : (!empty($campos['show'][$l]) ? eval('return ' . $campos['show'][$l] . ';') : $reg->getVar($campos['nome'][$l]));
0 ignored issues
show
The use of eval() is discouraged.
Loading history...
688
                        }
689
690
                        $ret .= '</td>';
691
                    }
692
                    //$ret.= "<td nowrap='nowrap'><a href='".$url."?op=".$op."_editar&".$reg->id."=".$reg->getVar($reg->id)."'><img src='../assets/images/editar.gif'></a> <a href='".$url."?op=".$op."_deletar&".$reg->id."=".$reg->getVar($reg->id)."'><img src='../assets/images/deletar.gif'></a> ".((!empty($campos['print'])) ? "<a href='".$url."?op=".$op."_imprime&".$reg->id."=".$reg->getVar($reg->id)."' target='_blank'><img src='../assets/images/imprime.gif'></a>" : '');
693
                    if (!empty($campos['botoes'])) {
694
                        $ret .= "<td nowrap='nowrap'>";
695
                        if (is_array($campos['botoes'])) {
696
                            foreach ($campos['botoes'] as $b) {
697
                                $ret .= "<a href='" . $b['link'] . '&' . $reg->id . '=' . $reg->getVar($reg->id) . "' title='" . $b['texto'] . "'><img src='" . $b['imagem'] . "' alt='" . $b['texto'] . "'></a> ";
698
                            }
699
                        }
700
                        $ret .= '</td>';
701
                    }
702
                    $ret .= '</tr></tbody>';
703
                }
704
                if ($form || $checks) {
705
                    $ret .= "<tbody><tr><td colspan='" . $colunas . "'>";
706
                    $ret .= $precrit_hidden . "<input type='hidden' name='sort' value='" . $sort . "'><input type='hidden' name='order' value='" . $order . "'><input type='hidden' name='limit' value='" . $limit . "'><input type='hidden' name='start' value='" . $start . "'>";
707
                    if (Request::hasVar('busca', 'GET')) {
708
                        foreach (Request::getArray('busca', [], 'GET') as $k => $v) {
709
                            if ('' !== $v && '-1' != $v && !is_array($v)) {
710
                                $ret .= "<input type='hidden' name='busca[" . $k . "]' value='" . $v . "'>";
711
                            } elseif (is_array($v)) {
712
                                $ret .= "<input type='hidden' name='busca[" . $k . "][dday]' value='" . $v['dday'] . "'>";
713
                                $ret .= "<input type='hidden' name='busca[" . $k . "][dmonth]' value='" . $v['dmonth'] . "'>";
714
                                $ret .= "<input type='hidden' name='busca[" . $k . "][dyear]' value='" . $v['dyear'] . "'>";
715
                                $ret .= "<input type='hidden' name='busca[" . $k . "][aday]' value='" . $v['aday'] . "'>";
716
                                $ret .= "<input type='hidden' name='busca[" . $k . "][amonth]' value='" . $v['amonth'] . "'>";
717
                                $ret .= "<input type='hidden' name='busca[" . $k . "][ayear]' value='" . $v['ayear'] . "'>";
718
                            }
719
                        }
720
                    }
721
                    $ret .= "<input type='hidden' name='op' value='" . $op . "'>&nbsp;<br>";
722
                    if ($checks) {
723
                        $ret .= $campos['lang']['group_action'] . " <select name='group_action' id='group_action'><option value='0'>" . _SELECT . '</option>';
724
                        $ret .= !empty($campos['group_del']) ? "<option value='group_del'>" . $campos['lang']['group_del'] . '</option>' : '';
725
                        if (!empty($campos['group_action'])) {
726
                            foreach ($campos['group_action'] as $grp) {
727
                                $ret .= "<option value='" . $grp['valor'] . "'>" . $grp['texto'] . '</option>';
728
                            }
729
                        }
730
                        $ret .= '</select> ';
731
                    }
732
                    $ret .= "<input type='submit' value='" . _SUBMIT . "'><br>&nbsp;</td></tr></tbody></form>";
733
                }
734
                $ret .= !empty($campos['soma']) ? "<tbody><tr class='bx'><td colspan='" . $colunas . "' align='right'>Total: R$ " . number_format($this->soma($criterio, $campos['soma']), 2, ',', '.') . '</td></tr></tbody>' : '';
735
                $ret .= "<tbody><tr class='bx'><td colspan='" . $colunas . "' align='left'>" . $this->paginar($url_full_pg, $criterio, $precrit_url) . '</td></tr></tbody>';
736
            }
737
            $ret .= '</table></div></td></tr></table><br>';
738
739
            return $ret;
740
        }
741
742
        /**
743
         * @param null $criterio
744
         *
745
         * @return int
746
         */
747
        public function contar($criterio = null)
748
        {
749
            $sql = 'SELECT COUNT(*) FROM ' . $this->tabela;
750
            if (isset($criterio) && $criterio instanceof \CriteriaElement) {
751
                $sql .= ' ' . $criterio->renderWhere();
752
            }
753
            $result = $this->db->query($sql);
754
            if (!$result) {
755
                return 0;
756
            }
757
            list($count) = $this->db->fetchRow($result);
758
759
            return $count;
760
        }
761
762
        /**
763
         * @param null $criterio
764
         * @param      $campo
765
         *
766
         * @return int
767
         */
768
        public function soma($criterio, $campo)
769
        {
770
            $sql = 'SELECT SUM(' . $campo . ') FROM ' . $this->tabela;
771
            if (isset($criterio) && $criterio instanceof \CriteriaElement) {
772
                $sql .= ' ' . $criterio->renderWhere();
773
            }
774
            $result = $this->db->query($sql);
775
            if (!$result) {
776
                return 0;
777
            }
778
            list($soma) = $this->db->fetchRow($result);
779
780
            return $soma;
781
        }
782
783
        // Retorna a paginação pronta
784
785
        /**
786
         * @param      $link
787
         * @param null $criterio
788
         * @param null $precrit_url
789
         *
790
         * @return string
791
         */
792
        public function paginar($link, $criterio = null, $precrit_url = null)
793
        {
794
            $ret   = '';
795
            $order = 'up';
796
            $sort  = $this->id;
797
            if (isset($criterio) && $criterio instanceof \CriteriaElement) {
798
                $limit = $criterio->getLimit();
799
                $start = $criterio->getStart();
800
                if ('' !== $criterio->getSort()) {
801
                    $order = $criterio->getOrder();
802
                    $sort  = $criterio->getSort();
803
                }
804
            } else {
805
                $limit = 15;
806
                $start = 0;
807
            }
808
            $todos = $this->contar($criterio);
809
            $total = (0 == $todos % $limit) ? ($todos / $limit) : (int)($todos / $limit) + 1;
810
            $pg    = $start ? (int)($start / $limit) + 1 : 1;
811
            $ret   .= Request::hasVar('busca', 'GET') ? "<input type=button value='"
812
                                                        . _ALL
813
                                                        . "' onclick=\"document.location= '"
814
                                                        . Request::getString('PHP_SELF', '', 'SERVER')
815
                                                        . '?limit='
816
                                                        . $limit
817
                                                        . '&order='
818
                                                        . $order
819
                                                        . '&sort='
820
                                                        . $sort
821
                                                        . '&op='
822
                                                        . $GLOBALS['op']
823
                                                        . $precrit_url
824
                                                        . "'\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" : '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
825
            for ($i = 1; $i <= $total; ++$i) {
826
                $start = $limit * ($i - 1);
827
                if ($i == $pg) {
828
                    $ret .= "<span style='font-weight: bold; color: #CF0000; font-size: 15px;'> $i </span>";
829
                } elseif (($pg - 10) > $i) {
830
                    if (!isset($pg1)) {
831
                        $ret .= ("<A HREF='" . $link . '&start=' . $start . "'>1</a>. . .");
832
                        $pg1 = true;
833
                    }
834
                    continue;
835
                } elseif ($i < ($pg + 10)) {
836
                    $ret .= (" <A HREF='" . $link . '&start=' . $start . "'>" . $i . '</a> ');
837
                } else {
838
                    $ret .= (". . . <A HREF='" . $link . '&start=' . ((0 == $todos % $limit) ? $todos - $limit : $todos - ($todos % $limit)) . "'>" . $total . '</a>');
839
                    break;
840
                }
841
                if ($i != $total) {
842
                    $ret .= '|';
843
                }
844
            }
845
846
            return $ret;
847
        }
848
    }
849
}
850