]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/utils/progress_bar_utils.php
Release 6.5.0
[Github/sugarcrm.git] / include / utils / progress_bar_utils.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37
38
39 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
40
41 function progress_bar_flush()
42 {
43         if(ob_get_level()) {
44             @ob_flush();
45         } else {
46         @flush();
47         }
48 }
49
50 function display_flow_bar($name,$delay, $size=200)
51 {
52         $chunk = $size/5;
53         echo "<div id='{$name}_flow_bar'><table  class='list view' cellpading=0 cellspacing=0><tr><td id='{$name}_flow_bar0' width='{$chunk}px' bgcolor='#cccccc' align='center'>&nbsp;</td><td id='{$name}_flow_bar1' width='{$chunk}px' bgcolor='#ffffff' align='center'>&nbsp;</td><td id='{$name}_flow_bar2' width='{$chunk}px' bgcolor='#ffffff' align='center'>&nbsp;</td><td id='{$name}_flow_bar3' width='{$chunk}px' bgcolor='#ffffff' align='center'>&nbsp;</td><td id='{$name}_flow_bar4' width='{$chunk}px' bgcolor='#ffffff' align='center'>&nbsp;</td></tr></table></div><br>";
54
55         echo str_repeat(' ',256);
56
57         progress_bar_flush();
58         start_flow_bar($name, $delay);
59 }
60
61 function start_flow_bar($name, $delay)
62 {
63         $delay *= 1000;
64         $timer_id = $name . '_id';
65         echo "<script>
66                 function update_flow_bar(name, count){
67                         var last = (count - 1) % 5;
68                         var cur = count % 5;
69                         var next = cur + 1;
70                         eval(\"document.getElementById('\" + name+\"_flow_bar\" + last+\"').style.backgroundColor='#ffffff';\");
71                         eval(\"document.getElementById('\" + name+\"_flow_bar\" + cur+\"').style.backgroundColor='#cccccc';\");
72                         $timer_id = setTimeout(\"update_flow_bar('$name', \" + next + \")\", $delay);
73                 }
74                  var $timer_id = setTimeout(\"update_flow_bar('$name', 1)\", $delay);
75
76         </script>
77 ";
78         echo str_repeat(' ',256);
79
80         progress_bar_flush();
81 }
82
83 function destroy_flow_bar($name)
84 {
85         $timer_id = $name . '_id';
86         echo "<script>clearTimeout($timer_id);document.getElementById('{$name}_flow_bar').innerHTML = '';</script>";
87         echo str_repeat(' ',256);
88
89         progress_bar_flush();
90 }
91
92 function display_progress_bar($name,$current, $total)
93 {
94         $percent = $current/$total * 100;
95         $remain = 100 - $percent;
96         $status = floor($percent);
97         //scale to a larger size
98         $percent *= 2;
99         $remain *= 2;
100         if($remain == 0){
101                 $remain = 1;
102         }
103         if($percent == 0){
104                 $percent = 1;
105         }
106         echo "<div id='{$name}_progress_bar' style='width: 50%;'><table class='list view' cellpading=0 cellspacing=0><tr><td id='{$name}_complete_bar' width='{$percent}px' bgcolor='#cccccc' align='center'>$status% </td><td id='{$name}_remain_bar' width={$remain}px' bgcolor='#ffffff'>&nbsp;</td></tr></table></div><br>";
107         if($status == 0){
108                 echo "<script>document.getElementById('{$name}_complete_bar').style.backgroundColor='#ffffff';</script>";
109         }
110         echo str_repeat(' ',256);
111
112         progress_bar_flush();
113 }
114
115 function update_progress_bar($name,$current, $total)
116 {
117         $percent = $current/$total * 100;
118         $remain = 100 - $percent;
119         $status = floor($percent);
120         //scale to a larger size
121         $percent *= 2;
122         $remain *= 2;
123         if($remain == 0){
124                 $remain = 1;
125         }
126         if($status == 100){
127                 echo "<script>document.getElementById('{$name}_remain_bar').style.backgroundColor='#cccccc';</script>";
128         }
129         if($status == 0){
130                 echo "<script>document.getElementById('{$name}_remain_bar').style.backgroundColor='#ffffff';</script>";
131                 echo "<script>document.getElementById('{$name}_complete_bar').style.backgroundColor='#ffffff';</script>";
132         }
133         if($status > 0){
134                 echo "<script>document.getElementById('{$name}_complete_bar').style.backgroundColor='#cccccc';</script>";
135         }
136
137
138         if($percent == 0){
139                 $percent = 1;
140         }
141
142         echo "<script>
143                 document.getElementById('{$name}_complete_bar').width='{$percent}px';
144                 document.getElementById('{$name}_complete_bar').innerHTML = '$status%';
145                 document.getElementById('{$name}_remain_bar').width='{$remain}px';
146                 </script>";
147         progress_bar_flush();
148 }