Location: PHPKode > projects > ZZ/OSS Installer > zic-1.1.0dev1/installer/lib/ZZOSS_Html/Progress.php
<?php
    /*
    Copyright (C) 2001-2004 ZZOSS GbR, http://www.zzoss.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */

    require_once ('HTML/Progress.php');
    
/**
* Progress Bars
*
* @version $Id: Progress.php,v 1.1 2004/01/28 11:39:51 ordnas Exp $
* @copyright Copyright &copy; 2001-2004 ZZ/OSS GbR, http://www.zzoss.com
* @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
*/
class ZZOSS_HtmlProgress
{
    var $items = array();
    var $increment = 0;
    var $label = '';
    var $bar;
    var $msg_items = '';
    
    function prepareListHorizontal($items, $label = '')
    {
        if(!is_array($items) || !count($items)){
            return false;
        }
        $this->items = $items;
        $this->label = $label;
        $this->increment = (int) floor(100/count($this->items));
        
        $this->bar = new HTML_Progress();
        $this->bar->setIncrement($this->increment);
        $this->bar->setStringPainted(true);
        $this->bar->setString('');
    
        $ui =& $this->bar->getUI();
        $ui->setStringAttributes('valign="bottom" align="left"');
        ?>
        <script type="text/javascript">
        <!--
        <?php echo $this->bar->getScript(); ?>
        //-->
        </script>
        <?php
        echo $this->bar->toHtml();
    }
    
    function executeListHorizontal()
    {
        $val = $this->bar->getValue();
        $i = floor($val / $this->increment);
        if(strlen($this->msg_items)){
            $this->msg_items .= ' <b>ok</b><nobr><br/>';
        }
        if(isset($this->items[$i])){
            $this->msg_items .= '<nobr>'.$this->items[$i].' ...';
        }
        $msg = '<nobr>'.$this->label.' ('.$val.' %)</nobr>:<br/>'.$this->msg_items.'<nobr><br/>';
        $this->bar->setString($msg);
    
        $this->bar->display();
        if ($this->bar->getPercentComplete() == 1) {
            return false;
        }
        $this->bar->incValue();
        return true;
    }
    
    function _downloadCallback($msg, $params = null)
    {
        $val = $this->bar->getValue();
        $i = floor($val / $this->increment);
        
        $percentage = 0;
        if($val != 0){
            $percentage = $val + (100/count($this->items));
        }
        
        switch ($msg) {
            case 'start':
                if($params[1] != -1){
                    $bytes = number_format($params[1], 0, '', ',');
                } else {
                    $bytes = '???';
                }
                $this->msg_items .= "<nobr>".$this->items[$i]." (".$bytes." bytes) ...";
                break;
            case 'done':
                if(strlen($this->msg_items)){
                    $this->msg_items .= ' <b>ok</b><nobr><br/>';
                }
                
                if (!isset($this->items[$i+1])) {
                    $percentage = 100;
                    $this->bar->incValue();
                }
                $this->bar->incValue();
                break;
        }
        
        $msg = '<nobr>'.$this->label.' ('.$percentage.' %):</nobr><br/>'.$this->msg_items.'<nobr><br/>';
        $this->bar->setString($msg);
        $this->bar->display();
    }
}
?>
Return current item: ZZ/OSS Installer