-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPB.php
153 lines (141 loc) · 3.77 KB
/
PB.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* Progress bar for a lengthy PHP process
* http://spidgorny.blogspot.com/2012/02/progress-bar-for-lengthy-php-process.html
*/
class ProgressBar
{
var $percentDone = 0;
var $pbid;
var $pbarid;
var $tbarid;
var $textid;
var $decimals = 1;
function __construct($percentDone = 0)
{
$this->pbid = 'pb';
$this->pbarid = 'progress-bar';
$this->tbarid = 'transparent-bar';
$this->textid = 'pb_text';
$this->percentDone = $percentDone;
}
function render()
{
//print ($GLOBALS['CONTENT']);
//$GLOBALS['CONTENT'] = '';
print($this->getContent());
$this->flush();
//$this->setProgressBarProgress(0);
}
function getContent()
{
$this->percentDone = floatval($this->percentDone);
$percentDone = number_format($this->percentDone, $this->decimals, '.', '') . '%';
$content = '<div id="' . $this->pbid . '" class="pb_container">
<div id="' . $this->textid . '" class="' . $this->textid . '">' . $percentDone . '</div>
<div class="pb_bar">
<div id="' . $this->pbarid . '" class="pb_before"
style="width: ' . $percentDone . ';"></div>
<div id="' . $this->tbarid . '" class="pb_after"></div>
</div>
<br style="height: 1px; font-size: 1px;"/>
</div>
<style>
.pb_container {
position: relative;
}
.pb_bar {
width: 100%;
height: 1.3em;
border: 1px solid silver;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
-moz-border-radius-bottomleft: 5px;
-moz-border-radius-bottomright: 5px;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
}
.pb_before {
float: left;
height: 1.3em;
background-color: #43b6df;
-moz-border-radius-topleft: 5px;
-moz-border-radius-bottomleft: 5px;
-webkit-border-top-left-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
}
.pb_after {
float: left;
background-color: #FEFEFE;
-moz-border-radius-topright: 5px;
-moz-border-radius-bottomright: 5px;
-webkit-border-top-right-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
}
.pb_text {
padding-top: 0.1em;
position: absolute;
left: 48%;
}
</style>' . "\r\n";
return $content;
}
function setProgressBarProgress($percentDone, $text = '')
{
$this->percentDone = $percentDone;
$text = $text ? $text : number_format($this->percentDone, $this->decimals, '.', '') . '%';
print('
<script type="text/javascript">
if (document.getElementById("' . $this->pbarid . '")) {
document.getElementById("' . $this->pbarid . '").style.width = "' . $percentDone . '%";');
if ($percentDone == 100) {
print('document.getElementById("' . $this->pbid . '").style.display = "none";');
} else {
print('document.getElementById("' . $this->tbarid . '").style.width = "' . (100 - $percentDone) . '%";');
}
if ($text) {
print('document.getElementById("' . $this->textid . '").innerHTML = "' . htmlspecialchars($text) . '";');
}
print('}</script>' . "\n");
$this->flush();
}
function flush()
{
print str_pad('', intval(ini_get('output_buffering'))) . "\n";
//ob_end_flush();
flush();
}
function processaxml($file){
//fai la magia!
echo "<br><br><strong>sto dentro ".$file.'</strong><br>';
}
}
/*
$content = "";
echo 'Avvio Conversione…<br />';
$p = new ProgressBar();
echo '<div style="width: 300px;">';
$p->render();
echo '</div>';
$mimmo = glob('C:\xampp\htdocs\copernico\*.xml');
$f=0;
$i=0;
$size = 100;
$conta=100/count($mimmo);
foreach ($mimmo as $t) {
//}
if (count($mimmo)==1)
{
$i=100;
}
$p->processaxml($t);
echo basename($t).'<br>'.round($i,2).'%<br>';
$p->setProgressBarProgress($i * 100 / $size);
usleep(10000000 * 0.1);
$i=$i+$conta;
}
$p->setProgressBarProgress(100);
echo 'Terminato.<br />';
*/