Source of file stat5.php
Size: 4,415 Bytes - Last Modified: 2017-07-17T16:46:02+00:00
/home/travis/build/Limych/GeniBase/src/stat5.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 | <?php require_once ('gb-config.php'); // Load GeniBase require_once ('inc.php'); // Основной подключаемый файл-заплатка html_header('Статистика'); ?> <p> <a href="/">« Вернуться к поиску</a> </p> <h1>Общая статистика по базе данных</h1> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart"]}); </script> <?php show_records_stat(); dic_stat('Распределение по вероисповеданию', 'Вероисповедание', 'religion'); dic_stat('Распределение по семейному положению', 'Семейное положение', 'marital'); dic_stat('Распределение по событиям', 'События', 'reason'); ?> <table class="stat"> <caption>Распределение по воинским званиям</caption> <thead> <tr> <th>Воинское звание</th> <th>Записей</th> </tr> </thead> <tbody> <?php $even = 0; $result = gbdb()->get_column('SELECT rank, COUNT(*) FROM ?_persons GROUP BY rank ORDER BY rank', array(), TRUE); foreach ($result as $field => $cnt) { $even = 1 - $even; if (empty($field)) $field = '(не указано)'; print "<tr class='" . ($even ? 'even' : 'odd') . "'>\n\t<td>" . esc_html($field) . "</td>\n\t<td class='align-right'>" . format_num($cnt) . "</td>\n</tr>"; } ?> </tbody> </table> <table class="stat"> <caption>Распределение по регионам Российской Империи</caption> <thead> <tr> <th>Губерния, Уезд</th> <th>Записей</th> </tr> </thead> <tbody> <?php $even = 0; region_stat(); ?> </tbody> </table> <?php html_footer(); function region_stat($parent_id = 0, $level = 1) { global $even; $result = gbdb()->get_table('SELECT id, title, region_comment, region_cnt FROM ?_dic_regions' . ' WHERE parent_id = ?parent_id ORDER BY title', array( 'parent_id' => $parent_id )); foreach ($result as $row) { $even = 1 - $even; print "<tr class='" . ($even ? 'even' : 'odd') . "'>\n\t<td class='region level_$level id_" . $row['id'] . "'>" . esc_html($row['title']) . (empty($row['region_comment']) ? '' : ' <span class="comment">' . esc_html($row['region_comment']) . '</span>') . "</td>\n\t<td class='align-right'>" . format_num($row['region_cnt']) . "</td>\n"; region_stat($row['id'], $level + 1); } } function dic_stat($caption, $field_title, $field) { static $chart_num = 0; $chart_num ++; ?> <script type="text/javascript"> $(document).ready(function(){ var data = google.visualization.arrayToDataTable([ ['<?php print esc_js($field_title); ?>', 'Записей'], <?php $result = gbdb()->get_column('SELECT ?#field, ?#field_cnt FROM ?@table' . ' WHERE ?#field_cnt != 0 ORDER BY ?#field', array( '@table' => "dic_{$field}s", '#field' => $field, '#field_cnt' => "{$field}_cnt" ), TRUE); foreach ($result as $fld => $cnt) print "\t\t\t['" . esc_js($fld) . "', " . intval($cnt) . "],\n"; ?> ]); var options = { title: '<?php print esc_js($caption); ?>', vAxis: {minValue: 0, title: 'Потери'}, legend: {position: 'none'}, }; var chart = new google.visualization.PieChart(document.getElementById('chart_<?php print $chart_num; ?>')); chart.draw(data, options); } </script> <div id="chart_<?php print $chart_num; ?>" style="width: 100%; height: 300px"></div> <table class="stat"> <caption><?php print $caption; ?></caption> <thead> <tr> <th><?php print $field_title; ?></th> <th>Записей</th> </tr> </thead> <tbody> <?php $result = gbdb()->get_column('SELECT ?#field, ?#field_cnt FROM ?@table' . ' WHERE ?#field_cnt != 0 ORDER BY ?#field', array( '@table' => "dic_${field}s", '#field' => $field, '#field_cnt' => "{$field}_cnt" ), TRUE); $even = 0; foreach ($result as $field => $cnt) { $even = 1 - $even; print "<tr class='" . ($even ? 'even' : 'odd') . "'>\n\t<td>" . esc_html($field) . "</td>\n\t<td class='align-right'>" . format_num($cnt) . "</td>\n</tr>"; } ?> </tbody> </table> <?php } |