|
|
@@ -146,7 +146,7 @@ class Route_UrlAction_BiAuditGenerate extends RouteBase {
|
|
|
<div class="form-group">
|
|
|
<div class="col-sm-12">
|
|
|
<div class="containter" style="text-align:center">
|
|
|
- <button type="submit" class="btn btn-primary" name="action" value="initialize">Generuj</button>
|
|
|
+ <button type="submit" class="btn btn-primary btn-sm" name="action" value="initialize">Generuj</button>
|
|
|
<a href="<?=$this->REFERER?>" class="btn btn-default">Anuluj</a>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -1103,20 +1103,66 @@ function validateCompany(source) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private function benford_getDetails($a = null, $b = null) {
|
|
|
+ try {
|
|
|
+ if (!($benford = V::get('benford', '', $_SESSION))) throw new Exception("Nieznany błąd wewnętrzny #1");
|
|
|
+ if (isset($benford[$this->SOURCE['TABLE']]['details'][$a][$b])) throw new Exception(@gzuncompress($benford[$this->SOURCE['TABLE']]['details'][$a][$b]));
|
|
|
+ if (!($benford = @unserialize(@gzuncompress($benford[$this->SOURCE['TABLE']]['data'])))) throw new Exception("Nieznany błąd wewnętrzny #2");
|
|
|
+ if (!isset($benford['conf']['groupField'])) throw new Exception("Nieznany błąd wewnętrzny #3");
|
|
|
+ if (!($groupField = $benford['conf']['groupField'])) throw new Exception("Nieznany błąd wewnętrzny #4");
|
|
|
+ if ($a === null) throw new Exception("Nieznany błąd wewnętrzny #5");
|
|
|
+ if ($b === null) {
|
|
|
+ if (!isset($benford['firstStep'][$a]['keys'])) throw new Exception("Nieznany błąd wewnętrzny #6");
|
|
|
+ $keys = $benford['firstStep'][$a]['keys'];
|
|
|
+ } else {
|
|
|
+ if (!isset($benford['secondStep'][$a][$b]['keys'])) throw new Exception("Nieznany błąd wewnętrzny #7");
|
|
|
+ $keys = $benford['secondStep'][$a][$b]['keys'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $tempTable = uniqid('_temp_benford_ids_');
|
|
|
+ DB::getPDO()->query("create temporary table `{$tempTable}` (`ID` int(11) NOT NULL, UNIQUE KEY `ID` (`ID`))");
|
|
|
+ foreach (array_chunk($keys, 100) as $ids) {
|
|
|
+ DB::getPDO()->query("insert into `{$tempTable}` values (" . implode('),(', $ids) . ")");
|
|
|
+ }
|
|
|
+ $query = "select `table`.`{$groupField}` as `field`, count(*) as `count` from `{$this->SOURCE['TABLE']}` `table` join `{$tempTable}` `temp` on `table`.`ID` = `temp`.`ID` where coalesce(`table`.`{$groupField}`,'') != '' group by `table`.`{$groupField}` having `count` > 1 order by `count` desc limit 10";
|
|
|
+ try {
|
|
|
+ $result = DB::getPDO()->fetchAll($query);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ throw new Exception("Nieznany błąd, prawdopodobnie błędna konfiguracja kolumny grupującej");
|
|
|
+ }
|
|
|
+ $showDetails = "<h4>Najczęściej występujące wartości kolumny {$groupField}</h4>";
|
|
|
+ if ($result) {
|
|
|
+ $showDetails .= "<table class=\"table table-bordered table-hover table-striped table-condensed\"><thead><tr style=\"font-weight:bold;\"><td>Wartość</td><td>Liczba wystąpień</td><td>Procent występowania</td></tr></thead><tbody>";
|
|
|
+ $showDetails .= implode('', array_map(function($v) use ($keys) {
|
|
|
+ return "<tr><td>{$v['field']}</td><td>{$v['count']}</td><td>" . number_format(round($v['count'] / count($keys) * 100, 3), 3, ',', '') . "</td></tr>";
|
|
|
+ }, $result));
|
|
|
+ $showDetails .= "</tbody></table>";
|
|
|
+ } else {
|
|
|
+ $showDetails .= "<h5>Żadna wartość nie występuje wiele razy</h5>";
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+ $showDetails = "<h4>{$e->getMessage()}</h4>";
|
|
|
+ }
|
|
|
+ $_SESSION['benford'][$this->SOURCE['TABLE']]['details'][$a][$b] = gzcompress($showDetails);
|
|
|
+ $showDetails .= '<button type="submit" class="btn btn-primary btn-sm" onClick="hideDetails()">Zamknij</button>';
|
|
|
+ return $showDetails;
|
|
|
+ }
|
|
|
+
|
|
|
private function benford_form($edit = false) {
|
|
|
- if (!($field = V::get('_benfordField', '', $_GET))) throw new Exception ("Błąd konfiguracji UrlAction - brak parametru _benfordField (DANE )");
|
|
|
+ if (!($valueField = V::get('_benfordValueField', '', $_GET))) throw new Exception ("Błąd konfiguracji UrlAction - brak parametru _benfordField (DANE )");
|
|
|
+ if (!($groupField = V::get('_benfordGroupField', '', $_GET))) throw new Exception("Brak konfiguracji kolumny grupującej");
|
|
|
if (!($namespace = V::get('_fromNamespace', '', $_GET))) throw new Exception("Błąd formularza");
|
|
|
|
|
|
Lib::loadClass('FeatureAttrSelected');
|
|
|
$count = FeatureAttrSelected::getTotalSelected($namespace);
|
|
|
$selectedTable = FeatureAttrSelected::getAttributeTableName($namespace, User::getID());
|
|
|
- $query = "select `t`.`ID`, `{$field}` from `{$this->SOURCE['TABLE']}` `t` join `{$selectedTable}` `s` on `t`.`ID` = `s`.`primaryKey` where `t`.`{$field}` != 0 order by `s`.`primaryKey`";
|
|
|
+ $query = "select `t`.`ID`, `{$valueField}` from `{$this->SOURCE['TABLE']}` `t` join `{$selectedTable}` `s` on `t`.`ID` = `s`.`primaryKey` where `t`.`{$valueField}` != 0 order by `s`.`primaryKey`";
|
|
|
$values = [];
|
|
|
try {
|
|
|
$result = DB::getPDO()->fetchAll($query);
|
|
|
- foreach ($result as $row) $values[$row['ID']] = $row[$field];
|
|
|
+ foreach ($result as $row) $values[$row['ID']] = $row[$valueField];
|
|
|
} catch (Exception $e) {
|
|
|
- echo $e->getMessage();
|
|
|
+ throw new Exception("Błąd zapytania SQL ({$e->getMessage()})");
|
|
|
}
|
|
|
if (!$values) throw new Exception("Nie wybrano żadnych obiektów lub wszystkie wybrane obiekty mają zerową wartość");
|
|
|
|
|
|
@@ -1124,6 +1170,12 @@ function validateCompany(source) {
|
|
|
try {
|
|
|
$benfordObj = new Benford($values);
|
|
|
$benford = $benfordObj->getAllResult();
|
|
|
+ $benford['conf'] = [
|
|
|
+ 'count' => count($values),
|
|
|
+ 'valueField' => $valueField,
|
|
|
+ 'groupField' => $groupField,
|
|
|
+ ];
|
|
|
+ $_SESSION['benford'][$this->SOURCE['TABLE']] = ['data' => gzcompress(serialize($benford))];
|
|
|
} catch (Exception $e) {
|
|
|
die($e->getMessage());
|
|
|
}
|
|
|
@@ -1136,7 +1188,7 @@ function validateCompany(source) {
|
|
|
</legend>
|
|
|
<div class="form-group">
|
|
|
<div class="col-sm-12">
|
|
|
- <h5>Analiza na podstawie kolumny <?=$field?>. Liczba znalezionych obiektów z niezerową wartością: <?=count($values)?> (wybrano obiektów: <?=$count?>)</h5>
|
|
|
+ <h5>Analiza na podstawie kolumny <?=$valueField?>. Liczba znalezionych obiektów z niezerową wartością: <?=count($values)?> (wybrano obiektów: <?=$count?>)</h5>
|
|
|
</div>
|
|
|
</div>
|
|
|
<?php if($edit):?>
|
|
|
@@ -1147,7 +1199,7 @@ function validateCompany(source) {
|
|
|
<table>
|
|
|
<tr>
|
|
|
<td>
|
|
|
- <select name="stage" class="form-control" onChange="toggleStage(this)">
|
|
|
+ <select name="step" class="form-control" onChange="toggleStep(this)">
|
|
|
<option value="first" selected>Pierwszy stopień analizy</option>
|
|
|
<option value="second">Drugi stopień analizy</option>
|
|
|
</select>
|
|
|
@@ -1163,9 +1215,9 @@ function validateCompany(source) {
|
|
|
</div>
|
|
|
</div>
|
|
|
<?php endif;?>
|
|
|
- <div class="form-group">
|
|
|
+ <div class="form-group" id="benford">
|
|
|
<div class="col-sm-offset-2 col-sm-8">
|
|
|
- <table class="table table-bordered table-hover table-striped table-condensed">
|
|
|
+ <table class="table table-bordered table-hover table-striped table-condensed" id="benford">
|
|
|
<thead style="text-align:center; font-weight:bold; background-color:lightgray">
|
|
|
<tr>
|
|
|
<td style="vertical-align:middle;" rowspan="2">Pierwsze cyfry</td>
|
|
|
@@ -1173,6 +1225,7 @@ function validateCompany(source) {
|
|
|
<td style="vertical-align:middle;" rowspan="2">Liczba wystąpień</td>
|
|
|
<td style="vertical-align:middle;" rowspan="2">Procent występowania</td>
|
|
|
<td colspan="3">Rozkład Benford'a</td>
|
|
|
+ <td style="vertical-align:middle;" rowspan="2">Szczegóły</td>
|
|
|
<?php if($edit):?>
|
|
|
<td style="vertical-align:middle;" rowspan="2">Załącz obiekty<br/>do raportu</td>
|
|
|
<?php endif;?>
|
|
|
@@ -1190,43 +1243,45 @@ function validateCompany(source) {
|
|
|
};
|
|
|
|
|
|
for ($ka = 1; $ka < 10; $ka++) {
|
|
|
- if (!isset($benford['firstStage'][$ka])) $benford['firstStage'][$ka] = ['count' => 0, 'value' => 0, 'correct' => true];
|
|
|
- $va = $benford['firstStage'][$ka];
|
|
|
+ if (!isset($benford['firstStep'][$ka])) $benford['firstStep'][$ka] = ['count' => 0, 'value' => 0, 'correct' => true];
|
|
|
+ $va = $benford['firstStep'][$ka];
|
|
|
$odchylenie = round(($va['value'] / Benford::benford($ka) - 1) * 100, 3);
|
|
|
if ($odchylenie > 0) $odchylenie = "+" . $number_format($odchylenie);
|
|
|
else $odchylenie = $number_format($odchylenie);
|
|
|
?>
|
|
|
- <tr style="text-align:center; font-weight:bold;" class="tr-stage1-<?=$va['correct'] ? 'green' : 'red" onClick="toggleSecondStage(' . $ka . ');'?>">
|
|
|
- <td style="text-align:left"><?=$ka?></td>
|
|
|
- <td>I</td>
|
|
|
- <td style="text-align:right"><?=$va['count']?></td>
|
|
|
- <td style="text-align:right"><?=$number_format(round($va['value'] * 100, 3))?></td>
|
|
|
- <td style="text-align:right"><?=$number_format(round(Benford::benford($ka) * 100, 3))?></td>
|
|
|
- <td style="text-align:right"><?=$odchylenie?></td>
|
|
|
- <td<?=$va['correct'] ? '' : ' name="firstStageDesc" data-ka="' . $ka . '"'?> nowrap><?=$va['correct'] ? 'Tak' : 'Nie (rozwiń)'?></td>
|
|
|
+ <tr style="text-align:center; font-weight:bold;<?=$va['correct'] ? '' : ' cursor:pointer;'?>"<?=$va['correct'] ? '' : ' onClick="toggleSecondStep(' . $ka . ');"'?>>
|
|
|
+ <td style="text-align:left" class="step1-<?=$va['correct'] ? 'green' : 'red'?>"><?=$ka?></td>
|
|
|
+ <td class="step1-<?=$va['correct'] ? 'green' : 'red'?>">I</td>
|
|
|
+ <td style="text-align:right" class="step1-<?=$va['correct'] ? 'green' : 'red'?>"><?=$va['count']?></td>
|
|
|
+ <td style="text-align:right" class="step1-<?=$va['correct'] ? 'green' : 'red'?>"><?=$number_format(round($va['value'] * 100, 3))?></td>
|
|
|
+ <td style="text-align:right" class="step1-<?=$va['correct'] ? 'green' : 'red'?>"><?=$number_format(round($va['norm'] * 100, 3))?></td>
|
|
|
+ <td style="text-align:right" class="step1-<?=$va['correct'] ? 'green' : 'red'?>"><?=$odchylenie?></td>
|
|
|
+ <td <?=$va['correct'] ? 'class="step1-green">Tak' : 'class="step1-red" name="firstStepDesc" data-ka="' . $ka . '" nowrap>Nie (rozwiń)'?></td>
|
|
|
+ <td<?=$va['correct'] ? '>' : ' onClick="showDetails(' . $ka . ', 0)"><span class="glyphicon glyphicon-search"></span>'?></td>
|
|
|
<?php if($edit):?>
|
|
|
- <td><input type="checkbox" <?=$va['correct'] ? 'disabled' : 'checked name="checkFirstStage[]" value="' . $ka . '" onClick="toggleSecondStage(' . $ka . '); toggleCheckFirst(this)"'?>></td>
|
|
|
+ <td<?=$va['correct'] ? '' : ' onClick="_click(\'checkFirstStep_' . $ka . '\')"'?>><input type="checkbox" <?=$va['correct'] ? 'disabled' : 'checked id="checkFirstStep_' . $ka . '" name="checkFirstStep[]" value="' . $ka . '" onClick="toggleCheckFirst(this)"'?>></td>
|
|
|
<?php endif;?>
|
|
|
</tr>
|
|
|
<?php
|
|
|
if (!$va['correct']) {
|
|
|
for ($kb = 0; $kb < 10; $kb++) {
|
|
|
- if (!isset($benford['secondStage'][$ka][$kb])) $benford['secondStage'][$ka][$kb] = ['count' => 0, 'value' => 0, 'correct' => true];
|
|
|
- $vb = $benford['secondStage'][$ka][$kb];
|
|
|
+ if (!isset($benford['secondStep'][$ka][$kb])) $benford['secondStep'][$ka][$kb] = ['count' => 0, 'value' => 0, 'correct' => true];
|
|
|
+ $vb = $benford['secondStep'][$ka][$kb];
|
|
|
$odchylenie = round(($vb['value'] / Benford::benford($ka * 10 + $kb) - 1) * 100, 3);
|
|
|
if ($odchylenie > 0) $odchylenie = "+" . $number_format($odchylenie);
|
|
|
else $odchylenie = $number_format($odchylenie);
|
|
|
?>
|
|
|
- <tr style="text-align:center;" class="tr-stage2-<?=$vb['correct'] ? 'green' : 'red'?>" name="secondStage" data-ka="<?=$ka?>" hidden>
|
|
|
- <td style="text-align:left"><?=$ka . $kb?></td>
|
|
|
- <td>II</td>
|
|
|
- <td style="text-align:right"><?=$vb['count']?></td>
|
|
|
- <td style="text-align:right"><?=$number_format(round($vb['value'] * 100, 3))?></td>
|
|
|
- <td style="text-align:right"><?=$number_format(round(Benford::benford($ka * 10 + $kb) * 100, 3))?></td>
|
|
|
- <td style="text-align:right"><?=$odchylenie?></td>
|
|
|
- <td><?=$vb['correct'] ? 'Tak' : 'Nie'?></td>
|
|
|
+ <tr style="text-align:center;" name="secondStep" data-ka="<?=$ka?>" hidden>
|
|
|
+ <td style="text-align:left" class="step2-<?=$vb['correct'] ? 'green' : 'red'?>"><?=$ka . $kb?></td>
|
|
|
+ <td class="step2-<?=$vb['correct'] ? 'green' : 'red'?>">II</td>
|
|
|
+ <td style="text-align:right" class="step2-<?=$vb['correct'] ? 'green' : 'red'?>"><?=$vb['count']?></td>
|
|
|
+ <td style="text-align:right" class="step2-<?=$vb['correct'] ? 'green' : 'red'?>"><?=$number_format(round($vb['value'] * 100, 3))?></td>
|
|
|
+ <td style="text-align:right" class="step2-<?=$vb['correct'] ? 'green' : 'red'?>"><?=$number_format(round($vb['norm'] * 100, 3))?></td>
|
|
|
+ <td style="text-align:right" class="step2-<?=$vb['correct'] ? 'green' : 'red'?>"><?=$odchylenie?></td>
|
|
|
+ <td class="step2-<?=$vb['correct'] ? 'green' : 'red'?>"><?=$vb['correct'] ? 'Tak' : 'Nie'?></td>
|
|
|
+ <td<?=$vb['correct'] ? '>' : ' style="cursor:pointer;" onClick="showDetails(' . "{$ka}, {$kb}" . ')"><span class="glyphicon glyphicon-search"></span>'?></td>
|
|
|
<?php if($edit):?>
|
|
|
- <td onClick=""><input type="checkbox"<?=$vb['correct'] ?: ' checked name="checkSecondStage[]" value="' . $ka . $kb . '" onClick="toggleCheckSecond(this)"'?> disabled></td>
|
|
|
+ <td<?=$vb['correct'] ? '' : ' style="cursor:pointer;" onClick="_click(\'checkSecondStep_' . $ka . $kb . '\')"'?>><input type="checkbox"<?=$vb['correct'] ?: ' checked id="checkSecondStep_' . $ka . $kb . '" name="checkSecondStep[]" value="' . $ka . $kb . '" onClick="toggleCheckSecond(this)"'?> disabled></td>
|
|
|
<?php endif;?>
|
|
|
</tr>
|
|
|
<?php
|
|
|
@@ -1240,19 +1295,48 @@ function validateCompany(source) {
|
|
|
</div>
|
|
|
</form>
|
|
|
</div>
|
|
|
+<div id="details" onClick="hideDetails();">
|
|
|
+ <div id="detailsMsg" onClick="event.stopPropagation();"></div>
|
|
|
+</div>
|
|
|
<style type="text/css">
|
|
|
<!--
|
|
|
-.tr-stage1-green,.tr-stage1-red {font-weight:bold;}
|
|
|
-.tr-stage1-green,.tr-stage2-green {color:#008800;}
|
|
|
-.tr-stage1-red,.tr-stage2-red {color:#ff0000;}
|
|
|
-body { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}
|
|
|
-::selection {background: transparent;}
|
|
|
+#benford .step1-green,#benford .step1-red {font-weight:bold;}
|
|
|
+#benford .step1-green,#benford .step2-green {color:#008800;}
|
|
|
+#benford .step1-red,#benford .step2-red {color:#ff0000;}
|
|
|
+#benford table { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}
|
|
|
+td {font-size: 12px;}
|
|
|
+#benford ::selection {background: transparent;}
|
|
|
+#details {display:none; position: fixed; left: 0; top: 0; width: 100%; height: 100%; text-align: center; z-index: 1000; background-color: rgba(0,0,0,0.5);}
|
|
|
+#details div {width: 500px; height: auto; margin: 100px auto; background: #fff; padding: 10px; text-align: center; overflow: hidden; border-radius: 5px; box-shadow: 0 0 7px 7px rgba(0,0,0,0.25);}
|
|
|
-->
|
|
|
</style>
|
|
|
<script language="JavaScript">
|
|
|
<!--
|
|
|
-function toggleSecondStage(ka) {
|
|
|
- var rows = document.getElementsByName('secondStage');
|
|
|
+function showDetails(ka, kb) {
|
|
|
+ event.stopPropagation();
|
|
|
+ document.getElementById('detailsMsg').innerHTML = "<h4>Proszę czekać...</h4>";
|
|
|
+ document.getElementById('details').style.display = 'block';
|
|
|
+ var post = "_noMenu=1&action=getDetails&_ka=" + ka;
|
|
|
+ if (kb) post += "&_kb=" + kb;
|
|
|
+ var xhttp = new XMLHttpRequest();
|
|
|
+ xhttp.open("POST", '', true);
|
|
|
+ xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
|
|
+ xhttp.onreadystatechange = function() {
|
|
|
+ if (this.readyState == 4 && this.status == 200) {
|
|
|
+ document.getElementById('detailsMsg').innerHTML = this.responseText;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ xhttp.send(post);
|
|
|
+}
|
|
|
+function hideDetails() {
|
|
|
+ document.getElementById('details').style.display = 'none';
|
|
|
+}
|
|
|
+function _click(id) {
|
|
|
+ event.stopPropagation();
|
|
|
+ document.getElementById(id).click();
|
|
|
+}
|
|
|
+function toggleSecondStep(ka) {
|
|
|
+ var rows = document.getElementsByName('secondStep');
|
|
|
var hidden = false;
|
|
|
for(var i = 0, n = rows.length; i < n; i++) {
|
|
|
if (rows[i].dataset.ka == ka) {
|
|
|
@@ -1260,21 +1344,21 @@ function toggleSecondStage(ka) {
|
|
|
hidden = rows[i].hidden;
|
|
|
}
|
|
|
}
|
|
|
- var descs = document.getElementsByName('firstStageDesc');
|
|
|
+ var descs = document.getElementsByName('firstStepDesc');
|
|
|
for(var i = 0, n = descs.length; i < n; i++) {
|
|
|
if (descs[i].dataset.ka == ka) {
|
|
|
descs[i].innerHTML = (hidden ? 'Nie (rozwiń)' : 'Nie (zwiń)');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-function toggleStage(option) {
|
|
|
+function toggleStep(option) {
|
|
|
if (option.value == 'first') first = true;
|
|
|
else if (option.value == 'second') first = false;
|
|
|
else {
|
|
|
alert('Wystąpił nieznany błąd formularza');
|
|
|
return;
|
|
|
}
|
|
|
- var checks = document.getElementsByName('checkSecondStage[]');
|
|
|
+ var checks = document.getElementsByName('checkSecondStep[]');
|
|
|
var all = [];
|
|
|
for(var i = 0, n = checks.length; i < n; i++) {
|
|
|
checks[i].disabled = first;
|
|
|
@@ -1282,7 +1366,7 @@ function toggleStage(option) {
|
|
|
if (all[ka] === 'undefined') all[ka] = checks[i].checked;
|
|
|
else if (checks[i].checked) all[ka] = true;
|
|
|
}
|
|
|
- var checks = document.getElementsByName('checkFirstStage[]');
|
|
|
+ var checks = document.getElementsByName('checkFirstStep[]');
|
|
|
for(var i = 0, n = checks.length; i < n; i++) {
|
|
|
checks[i].disabled = !(first);
|
|
|
if (checks[i].checked != all[checks[i].value]) {
|
|
|
@@ -1290,23 +1374,25 @@ function toggleStage(option) {
|
|
|
toggleCheckFirst(checks[i]);
|
|
|
}
|
|
|
}
|
|
|
- var descs = document.getElementsByName('firstStageDesc');
|
|
|
+ var descs = document.getElementsByName('firstStepDesc');
|
|
|
for(var i = 0, n = descs.length; i < n; i++) {
|
|
|
descs[i].innerHTML = (first ? 'Nie (rozwiń)' : 'Nie (zwiń)');
|
|
|
}
|
|
|
- var rows = document.getElementsByName('secondStage');
|
|
|
+ var rows = document.getElementsByName('secondStep');
|
|
|
for(var i = 0, n = rows.length; i < n; i++) {
|
|
|
rows[i].hidden = first;
|
|
|
}
|
|
|
}
|
|
|
function toggleCheckFirst(check) {
|
|
|
- var checks = document.getElementsByName('checkSecondStage[]');
|
|
|
+ event.stopPropagation();
|
|
|
+ var checks = document.getElementsByName('checkSecondStep[]');
|
|
|
for(var i = 0, n = checks.length; i < n; i++) {
|
|
|
if ((checks[i].value / 10 | 0) == check.value) checks[i].checked = check.checked;
|
|
|
}
|
|
|
}
|
|
|
function toggleCheckSecond(check) {
|
|
|
- var checks = document.getElementsByName('checkSecondStage[]');
|
|
|
+ event.stopPropagation();
|
|
|
+ var checks = document.getElementsByName('checkSecondStep[]');
|
|
|
var all = true;
|
|
|
var ka = check.value / 10 | 0;
|
|
|
for(var i = 0, n = checks.length; i < n; i++) {
|
|
|
@@ -1317,7 +1403,7 @@ function toggleCheckSecond(check) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- var checks = document.getElementsByName('checkFirstStage[]');
|
|
|
+ var checks = document.getElementsByName('checkFirstStep[]');
|
|
|
for(var i = 0, n = checks.length; i < n; i++) {
|
|
|
if (checks[i].value == ka) {
|
|
|
checks[i].checked = all;
|
|
|
@@ -1331,8 +1417,122 @@ function toggleCheckSecond(check) {
|
|
|
}
|
|
|
|
|
|
private function benford_generate() {
|
|
|
- SE_Layout::alert('warning', 'Not implemented yet');
|
|
|
+ $namespace = function($table, $field = null) {
|
|
|
+ if ($field === null) return "default_db__x3A__{$table}";
|
|
|
+ return "default_db__x3A__{$table}:{$field}";
|
|
|
+ };
|
|
|
+ $arrayWithNamespace = function($table, $array) use ($namespace) {
|
|
|
+ $keys = array_map(function($key) use ($table, $namespace) {
|
|
|
+ return $namespace($table, $key);
|
|
|
+ }, array_keys($array));
|
|
|
+ return array_combine($keys, $array);
|
|
|
+ };
|
|
|
+
|
|
|
+ $benfordId = null;
|
|
|
+ try {
|
|
|
+ $benford = @unserialize(@gzuncompress(V::get('benford', '', $_SESSION)[$this->SOURCE['TABLE']]['data']));
|
|
|
+ unset($_SESSION['benford'][$this->SOURCE['TABLE']]);
|
|
|
+ if (!$benford) {
|
|
|
+ $this->benford_form(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $mainTable = 'BI_audit_BENFORD';
|
|
|
+
|
|
|
+ if (!($refTable = BiAuditRefTables::getRefTable($mainTable, $this->SOURCE['TABLE'], false))) throw new Exception("Nie znaleziono relacji do obiektu \"{$this->SOURCE['TABLE']}\" w konfiguracji obiektu \"{$mainTable}\" - nie można wygenerować raportu.");
|
|
|
+
|
|
|
+ $sqlArr = [
|
|
|
+ 'step' => V::get('step', '', $_POST),
|
|
|
+ 'table' => $this->SOURCE['TABLE'],
|
|
|
+ 'valueField' => $benford['conf']['valueField'],
|
|
|
+ 'groupField' => $benford['conf']['groupField'],
|
|
|
+ 'count' => $benford['conf']['count'],
|
|
|
+ 'L_APPOITMENT_INFO' => V::get('L_APPOITMENT_INFO', '', $_POST),
|
|
|
+ 'A_RECORD_CREATE_AUTHOR' => User::getName(),
|
|
|
+ 'A_RECORD_CREATE_DATE' => date('Y-m-d-H:i'),
|
|
|
+ ];
|
|
|
+ if (!($benfordId = DB::getPDO()->insert($mainTable, $sqlArr))) throw new Exception("Nie wygenerowano raportu - Wystąpił nieznany błąd podczas zapisywania raportu do bazy");
|
|
|
+
|
|
|
+ $dir = self::getDirectory($mainTable, $benfordId);
|
|
|
+ if (!file_exists($dir)) mkdir($dir, 0770, true);
|
|
|
+ if (!is_dir($dir)) throw new Exception("Nie wygenerowano raportu - wystąpił błąd podczas tworzenia katalogu dla rekordu");
|
|
|
+
|
|
|
+ $root = 'RelatedFeatureRoot';
|
|
|
+ $array = [];
|
|
|
+ $array['@attributes'] = [
|
|
|
+ 'xmlns' => 'http://www.opengis.net/wfs',
|
|
|
+ 'xmlns:system_cache__dita' => 'http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/dita.xsd',
|
|
|
+ 'xmlns:p5' => 'https://biuro.biall-net.pl/wfs',
|
|
|
+ 'xmlns:'.$namespace($mainTable) => 'https://biuro.biall-net.pl/wfs',
|
|
|
+ 'xmlns:'.$namespace($this->SOURCE['TABLE']) => 'https://biuro.biall-net.pl/wfs'
|
|
|
+ ];
|
|
|
+ $array[$namespace($mainTable, $mainTable)] = array_merge(['@attributes' => ['fid' => "{$mainTable}.{$benfordId}", 'p5:primaryKey' => $benfordId]], $arrayWithNamespace($mainTable, array_merge(['ID' => $benfordId], $sqlArr)));
|
|
|
+ $checked = [
|
|
|
+ 'firstStep' => V::get('checkFirstStep', [], $_POST),
|
|
|
+ 'secondStep' => V::get('checkSecondStep', [], $_POST),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $firstStep = [];
|
|
|
+ for ($ka = 1; $ka <= 9; $ka++) {
|
|
|
+ if (!isset($benford['firstStep'][$ka])) $va = ['count' => 0, 'value' => 0, 'correct' => true];
|
|
|
+ else $va = $benford['firstStep'][$ka];
|
|
|
+ $_firstStep = [
|
|
|
+ '@attributes' => ['leadingNumber' => $ka],
|
|
|
+ 'count' => $va['count'],
|
|
|
+ 'value' => (double) round($va['value'], 5),
|
|
|
+ 'norm' => (double) round($va['norm'], 5),
|
|
|
+ 'deviation' => (double) round($va['value'] / $va['norm'] - 1, 5),
|
|
|
+ 'correct' => $va['correct'] ? 'true' : 'false',
|
|
|
+ ];
|
|
|
+ if ($array[$namespace($mainTable, $mainTable)][$namespace($mainTable, 'step')] == 'second' && (!$va['correct'])) {
|
|
|
+ $secondStep = [];
|
|
|
+ for ($kb = 0; $kb <= 9; $kb++) {
|
|
|
+ if (!isset($benford['secondStep'][$ka][$kb])) $vb = ['count' => 0, 'value' => 0, 'correct' => true];
|
|
|
+ else $vb = $benford['secondStep'][$ka][$kb];
|
|
|
+ $_secondStep = [
|
|
|
+ '@attributes' => ['leadingNumber' => $ka.$kb],
|
|
|
+ 'count' => $vb['count'],
|
|
|
+ 'value' => (double) round($vb['value'], 5),
|
|
|
+ 'norm' => (double) round($vb['norm'], 5),
|
|
|
+ 'deviation' => (double) round($vb['value'] / $vb['norm'] - 1, 5),
|
|
|
+ 'correct' => $vb['correct'] ? 'true' : 'false',
|
|
|
+ ];
|
|
|
+ if ((!$vb['correct']) && in_array($ka.$kb, $checked['secondStep'])) {
|
|
|
+ $objects = [];
|
|
|
+ foreach ($benford['secondStep'][$ka][$kb]['keys'] as $id) {
|
|
|
+ DB::getPDO()->insert($refTable, ['PRIMARY_KEY' => $benfordId, 'REMOTE_PRIMARY_KEY' => $id]);
|
|
|
+ $object = DB::getPDO()->fetchFirst("select * from `{$this->SOURCE['TABLE']}` where `ID` = " . DB::getPDO()->quote($id));
|
|
|
+ if (!$object) continue;
|
|
|
+ $objects[] = array_merge(['@attributes' => ['fid' => "{$this->SOURCE['TABLE']}.{$id}", 'p5:primaryKey' => $id]], $arrayWithNamespace($this->SOURCE['TABLE'], $object));
|
|
|
+ }
|
|
|
+ $_secondStep[$namespace($this->SOURCE['TABLE'], $this->SOURCE['TABLE'])][] = $objects;
|
|
|
+ }
|
|
|
+ $secondStep[] = $_secondStep;
|
|
|
+ }
|
|
|
+ $_firstStep['secondStep'] = $secondStep;
|
|
|
+ } elseif ((!$va['correct']) && in_array($ka, $checked['firstStep'])) {
|
|
|
+ $objects = [];
|
|
|
+ foreach ($benford['firstStep'][$ka]['keys'] as $id) {
|
|
|
+ DB::getPDO()->insert($refTable, ['PRIMARY_KEY' => $benfordId, 'REMOTE_PRIMARY_KEY' => $id]);
|
|
|
+ $object = DB::getPDO()->fetchFirst("select * from `{$this->SOURCE['TABLE']}` where `ID` = " . DB::getPDO()->quote($id));
|
|
|
+ if (!$object) continue;
|
|
|
+ $objects[] = array_merge(['@attributes' => ['fid' => "{$this->SOURCE['TABLE']}.{$id}", 'p5:primaryKey' => $id]], $arrayWithNamespace($this->SOURCE['TABLE'], $object));
|
|
|
+ }
|
|
|
+ $_firstStep[$namespace($this->SOURCE['TABLE'], $this->SOURCE['TABLE'])][] = $objects;
|
|
|
+ }
|
|
|
+ $firstStep[] = $_firstStep;
|
|
|
+ }
|
|
|
+ $array[$namespace($mainTable, $mainTable)]['firstStep'] = $firstStep;
|
|
|
+
|
|
|
+ $xml = V::arrayToXML($array, true, $root);
|
|
|
+ file_put_contents($dir . DIRECTORY_SEPARATOR . "{$mainTable}_{$benfordId}.xml", $xml);
|
|
|
+ DB::getPDO()->update($mainTable, 'ID', $benfordId, ['A_STATUS' => 'NORMAL', 'A_STATUS_INFO' => 'Poprawnie wygenerowano raport']);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ if ($benfordId) DB::getPDO()->update($mainTable, 'ID', $benfordId, ['A_STATUS' => 'DELETED', 'A_STATUS_INFO' => $e->getMessage()]);
|
|
|
+ SE_Layout::alert('danger', $e->getMessage());
|
|
|
+ }
|
|
|
?>
|
|
|
+<pre><?//=htmlspecialchars($xml)?></pre>
|
|
|
<br><br>
|
|
|
<div style="text-align:center">
|
|
|
<a href="<?=$this->REFERER?>" class="btn btn-default" style="width: 80px;">Powrót</a>
|
|
|
@@ -1347,6 +1547,11 @@ function toggleCheckSecond(check) {
|
|
|
case "generate":
|
|
|
$this->benford_generate();
|
|
|
break;
|
|
|
+ case "getDetails":
|
|
|
+ $ka = V::get('_ka', null, $_POST, 'int');
|
|
|
+ $kb = V::get('_kb', null, $_POST, 'int');
|
|
|
+ echo $this->benford_getDetails($ka, $kb);
|
|
|
+ break;
|
|
|
default:
|
|
|
$this->benford_form(true);
|
|
|
}
|
|
|
@@ -1356,8 +1561,11 @@ function toggleCheckSecond(check) {
|
|
|
}
|
|
|
|
|
|
public function defaultAction() {
|
|
|
- SE_Layout::gora();
|
|
|
- SE_Layout::menu();
|
|
|
+ $showMenu = !(V::get('_noMenu', false, $_POST));
|
|
|
+ if ($showMenu) {
|
|
|
+ SE_Layout::gora();
|
|
|
+ SE_Layout::menu();
|
|
|
+ }
|
|
|
if (isset($_SESSION['REFERER'])) {
|
|
|
$this->REFERER = $_SESSION['REFERER'];
|
|
|
unset($_SESSION['REFERER']);
|
|
|
@@ -1444,8 +1652,10 @@ function toggleCheckSecond(check) {
|
|
|
}
|
|
|
}
|
|
|
else SE_Layout::alert('danger', 'Błąd parametru #0');
|
|
|
- echo "<br/><br/>";
|
|
|
- SE_Layout::dol();
|
|
|
+ if ($showMenu) {
|
|
|
+ echo "<br/><br/>";
|
|
|
+ SE_Layout::dol();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private static function truncatePowiazaniaFromDB($ID) {
|
|
|
@@ -2846,8 +3056,22 @@ class BiAuditPowiazania {
|
|
|
private $results = [];
|
|
|
private $items_results = [];
|
|
|
private $relations = [];
|
|
|
- private $srcTables = ['BI_audit_ENERGA_PRACOWNICY']; //, ['BI_audit_POWIAZANIA_OD', 'BI_audit_POWIAZANIA_OBIEKTY']];
|
|
|
- private $destTables = ['BI_audit_ENERGA_RUM_KONTRAHENCI', 'BI_audit_KW_requested_person']; //, ['BI_audit_POWIAZANIA_DO', 'BI_audit_POWIAZANIA_OBIEKTY']];
|
|
|
+ private $srcTables = ['BI_audit_ENERGA_PRACOWNICY',
|
|
|
+ ['BI_audit_POWIAZANIA_OD', 'BI_audit_KRS'],
|
|
|
+ ['BI_audit_POWIAZANIA_OD', 'BI_audit_KRS_person'],
|
|
|
+ ['BI_audit_POWIAZANIA_OD', 'BI_audit_MSIG'],
|
|
|
+ ['BI_audit_POWIAZANIA_OD', 'BI_audit_MSIG_person'],
|
|
|
+ ['BI_audit_POWIAZANIA_OD', 'BI_audit_CEIDG'],
|
|
|
+ ['BI_audit_POWIAZANIA_OD', 'BI_audit_CEIDG_pelnomocnicy'],
|
|
|
+ ];
|
|
|
+ private $destTables = ['BI_audit_ENERGA_RUM_KONTRAHENCI', 'BI_audit_KW_requested_person',
|
|
|
+ ['BI_audit_POWIAZANIA_DO', 'BI_audit_KRS'],
|
|
|
+ ['BI_audit_POWIAZANIA_DO', 'BI_audit_KRS_person'],
|
|
|
+ ['BI_audit_POWIAZANIA_DO', 'BI_audit_MSIG'],
|
|
|
+ ['BI_audit_POWIAZANIA_DO', 'BI_audit_MSIG_person'],
|
|
|
+ ['BI_audit_POWIAZANIA_DO', 'BI_audit_CEIDG'],
|
|
|
+ ['BI_audit_POWIAZANIA_DO', 'BI_audit_CEIDG_pelnomocnicy'],
|
|
|
+ ];
|
|
|
private $step = 0;
|
|
|
private $tasksDirLocation;
|
|
|
private $progressFile;
|
|
|
@@ -2948,7 +3172,7 @@ class BiAuditPowiazania {
|
|
|
$resultDest = [];
|
|
|
foreach ($this->destTables as $destTable) {
|
|
|
if ($refTable = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', $destTable)) {
|
|
|
- $subQueries[] = "select `all`.`ID` from `BI_audit_ALL` `all` join `{$refTable}` `ref` on `all`.`REMOTE_TABLE` = '{$destTable}' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}'";
|
|
|
+ $subQueries[] = "select `all`.`ID`, `all`.`REMOTE_TABLE` from `BI_audit_ALL` `all` join `{$refTable}` `ref` on `all`.`REMOTE_TABLE` = '{$destTable}' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}'";
|
|
|
}
|
|
|
}
|
|
|
if ($subQueries) {
|
|
|
@@ -2961,7 +3185,7 @@ class BiAuditPowiazania {
|
|
|
$resultSrc = [];
|
|
|
foreach ($this->srcTables as $srcTable) {
|
|
|
if ($refTable = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', $srcTable)) {
|
|
|
- $subQueries[] = "select `all`.`ID` from `BI_audit_ALL` `all` join `{$refTable}` `ref` on `all`.`REMOTE_TABLE` = '{$srcTable}' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}'";
|
|
|
+ $subQueries[] = "select `all`.`ID`, `all`.`REMOTE_TABLE` from `BI_audit_ALL` `all` join `{$refTable}` `ref` on `all`.`REMOTE_TABLE` = '{$srcTable}' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}'";
|
|
|
}
|
|
|
}
|
|
|
if ($subQueries) {
|
|
|
@@ -2985,6 +3209,7 @@ class BiAuditPowiazania {
|
|
|
|
|
|
self::saveToLog("Rozpoczynam wyszukiwanie powiązań");
|
|
|
|
|
|
+ $externalTables = array_filter(array_merge($this->srcTables, $this->destTables), function($x) {if (!is_array($x)) return true;});
|
|
|
$this->count = count($result);
|
|
|
$this->progress['summary']['count'] = $this->count;
|
|
|
$this->origMaxDepth = $this->maxDepth;
|
|
|
@@ -3002,7 +3227,8 @@ class BiAuditPowiazania {
|
|
|
$this->maxDepth = $this->origMaxDepth;
|
|
|
self::saveToLog("Przywrócono oryginalną maksymalną głębokość przeszukiwania ({$this->origMaxDepth})");
|
|
|
}
|
|
|
- $this->findPowiazania($row['ID']);
|
|
|
+ $weight = in_array($row['REMOTE_TABLE'], $externalTables) ? 0 : 1;
|
|
|
+ $this->findPowiazania($row['ID'], $weight);
|
|
|
$this->saveProgress(['progress' => 1, 'message' => "Zakończono wyszukiwanie powiązań dla obiektu {$this->i}/{$this->count}"]);
|
|
|
$this->lastResults = count($this->results);
|
|
|
}
|
|
|
@@ -3057,7 +3283,7 @@ class BiAuditPowiazania {
|
|
|
return 10;
|
|
|
}
|
|
|
|
|
|
- public function findPowiazania($ID, $progress = 0, $steps = 1, $relation = "", $weight = 0) {
|
|
|
+ public function findPowiazania($ID, $weight = 0, $progress = 0, $steps = 1, $relation = "") {
|
|
|
$this->step++;
|
|
|
|
|
|
if ($this->maxDepth > $this->minDepth) {
|
|
|
@@ -3092,12 +3318,12 @@ class BiAuditPowiazania {
|
|
|
if (!$relation) $relation = 0;
|
|
|
|
|
|
if (in_array($ID, $this->endNodes)) {
|
|
|
- if (count($this->path) > $this->minDepth) $this->addResult($progress);
|
|
|
+ if (($weight) > $this->minDepth) $this->addResult($progress);
|
|
|
array_pop($this->path);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (count($this->path) > $this->maxDepth) {
|
|
|
+ if (($weight) > $this->maxDepth) {
|
|
|
if (!$this->onlyTargets) $this->addResult($progress);
|
|
|
array_pop($this->path);
|
|
|
return;
|
|
|
@@ -3116,7 +3342,7 @@ class BiAuditPowiazania {
|
|
|
$count = count($nodes);
|
|
|
$weight += self::weightCalc($count);
|
|
|
if ($weight <= $this->maxDepth) {
|
|
|
- foreach ($nodes as $i => $node) $this->findPowiazania($node['ID'], ($progress + ($i / ($count * $steps))), ($count * $steps), $node['RELATION_ID'], $weight);
|
|
|
+ foreach ($nodes as $i => $node) $this->findPowiazania($node['ID'], $weight, ($progress + ($i / ($count * $steps))), ($count * $steps), $node['RELATION_ID']);
|
|
|
}
|
|
|
|
|
|
array_pop($this->path);
|