-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProgressBar.Class.php
82 lines (73 loc) · 2.86 KB
/
ProgressBar.Class.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
<?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 $indeterminate = true;
var $pbid;
var $pbarid;
var $tbarid;
var $textid;
var $decimals = 0;
function __construct($percentDone = 0) {
$this->pbid = 'pb';
$this->pbarid = 'progress-bar';
$this->tbarid = 'transparent-bar';
$this->textid = 'pb_text';
$this->percentDone = $percentDone;
$this->indeterminate = true;
}
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, '.', '') .'%';
return ' <div id="'.$this->pbid.'" class="pb_container">
<div id="'.$this->textid.'" class="'.$this->textid.'" style="display: none"></div>
<div class="pb_bar">
<div id="'.$this->pbarid.'" class="pb_indeterminate" style="width: 100%;"></div>
<div id="'.$this->tbarid.'"></div>
</div>
<br style="height: 1px; font-size: 1px;"/>
</div>';
}
function setProgressBarProgress($percentDone, $text = '') {
if ($this->indeterminate) {
print('<script>'."\n\r".' document.getElementById("'.$this->pbarid.'").setAttribute("class", "pb_before");'."\n\r".' document.getElementById("'.$this->textid.'").style.display = "inline";'."\n\r".'</script>'."\n\r");
$this->indeterminate = false;
}
$this->percentDone = $percentDone;
$text = $text ? $text : number_format($this->percentDone, $this->decimals, '.', '').'%';
print('<script>'."\n\r".'if (document.getElementById("'.$this->pbarid.'")) {
document.getElementById("'.$this->pbarid.'").style.width = "'.$percentDone.'%";'."\n\r");
if ($percentDone == 100) {
//print('document.getElementById("'.$this->pbid.'").style.display = "none";');
print(' document.getElementById("carregando").innerHTML = "Redirecionando…";
document.getElementById("'.$this->pbarid.'").setAttribute("class", "pb_indeterminate");
document.getElementById("'.$this->textid.'").style.display = "none";'."\r\n");
} else {
print(' document.getElementById("'.$this->tbarid.'").style.width = "'.(100-$percentDone).'%";'."\r\n");
}
if ($text) {
print(' document.getElementById("'.$this->textid.'").innerHTML = "'.htmlspecialchars($text).'";'."\r\n");
}
print('}'."\n\r".'</script>');
$this->flush();
}
function hide() {
print('<script>'."\n\r".'document.getElementById("'.$this->pbid.'").style.display = "none";'."\n\r".'document.getElementById("carregando").style.display = "none";'."\n\r".'document.title = "Erro";'."\n\r".'</script>'."\n\r");
$this->flush();
}
function flush() {
print str_pad('', intval(ini_get('output_buffering')))."\n\r";
//ob_end_flush();
flush();
}
}