/** * The progress bar's UI extended model class constructor * * @param string $file file name of model properties * @param string $type type of external ressource (phpArray, iniFile, XML ...) * * @since 1.0 * @access public * @throws HTML_PROGRESS_ERROR_INVALID_INPUT */ function HTML_Progress_Model($file, $type) { $this->_package = 'HTML_Progress_Model'; Error_Raise::initialize($this->_package, array('HTML_Progress', '_getErrorMessage')); if (!file_exists($file)) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error', array('var' => '$file', 'was' => $file, 'expected' => 'file exists', 'paramnum' => 1), PEAR_ERROR_TRIGGER); } $conf = new Config(); if (!$conf->isConfigTypeRegistered($type)) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error', array('var' => '$type', 'was' => $type, 'expected' => implode(" | ", array_keys($GLOBALS['CONFIG_TYPES'])), 'paramnum' => 2), PEAR_ERROR_TRIGGER); } $data = $conf->parseConfig($file, $type); $structure = $data->toArray(false); $this->_progress =& $structure['root']; if (is_array($this->_progress['cell']['font-family'])) { $this->_progress['cell']['font-family'] = implode(",", $this->_progress['cell']['font-family']); } if (is_array($this->_progress['string']['font-family'])) { $this->_progress['string']['font-family'] = implode(",", $this->_progress['string']['font-family']); } $this->_orientation = $this->_progress['orientation']['shape']; $this->_fillWay = $this->_progress['orientation']['fillway']; if (isset($this->_progress['script']['file'])) { $this->_script = $this->_progress['script']['file']; } else { $this->_script = null; } if (isset($this->_progress['cell']['count'])) { $this->_cellCount = $this->_progress['cell']['count']; } else { $this->_cellCount = 10; } $this->_updateProgressSize(); }
/** * Sets the progress bar's current value. * If the new value is different from previous value, all change listeners * are notified. * * @param integer $val progress bar's current value * * @return void * @since 1.0 * @access public * @throws HTML_PROGRESS_ERROR_INVALID_INPUT * @see getValue() */ function setValue($val) { if (!is_int($val)) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$val', 'was' => gettype($val), 'expected' => 'integer', 'paramnum' => 1), PEAR_ERROR_TRIGGER); } elseif ($val < $this->getMinimum()) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error', array('var' => '$val', 'was' => $val, 'expected' => 'greater than $min = ' . $this->getMinimum(), 'paramnum' => 1), PEAR_ERROR_TRIGGER); } elseif ($val > $this->getMaximum()) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error', array('var' => '$val', 'was' => $val, 'expected' => 'less than $max = ' . $this->getMaximum(), 'paramnum' => 1), PEAR_ERROR_TRIGGER); } $this->_value = $val; }
/** * Disables certain buttons for a page. * * Buttons [ = events] : back, next, cancel, reset, apply, help * * @param object $page Page where you want to activate buttons * @param array $events (optional) List of buttons * * @since 1.1 * @access public * @throws HTML_PROGRESS_ERROR_INVALID_INPUT * @see enableButton() */ function disableButton(&$page, $events = array()) { if (!is_a($page, 'HTML_QuickForm_Page')) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$page', 'was' => gettype($page), 'expected' => 'HTML_QuickForm_Page object', 'paramnum' => 1), PEAR_ERROR_TRIGGER); } elseif (!is_array($events)) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$events', 'was' => gettype($events), 'expected' => 'array', 'paramnum' => 2), PEAR_ERROR_TRIGGER); } static $all; if (!isset($all)) { $all = array('back', 'next', 'cancel', 'reset', 'apply', 'help'); } $buttons = count($events) == 0 ? $all : $events; foreach ($buttons as $event) { $group =& $page->getElement('buttons'); $elements =& $group->getElements(); foreach (array_keys($elements) as $key) { if ($group->getElementName($key) == $page->getButtonName($event)) { $elements[$key]->updateAttributes(array('disabled' => 'true')); } } } }
/** * Set the sleep delay in milisecond before each progress cells display. * * @param integer $delay Delay in milisecond. * * @return void * @since 1.1 * @access public * @throws HTML_PROGRESS_ERROR_INVALID_INPUT */ function setAnimSpeed($delay) { if (!is_int($delay)) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$delay', 'was' => gettype($delay), 'expected' => 'integer', 'paramnum' => 1), PEAR_ERROR_TRIGGER); } elseif ($delay < 0) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error', array('var' => '$delay', 'was' => $delay, 'expected' => 'greater than zero', 'paramnum' => 1), PEAR_ERROR_TRIGGER); } elseif ($delay > 1000) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error', array('var' => '$delay', 'was' => $delay, 'expected' => 'less or equal 1000', 'paramnum' => 1), PEAR_ERROR_TRIGGER); } $this->_anim_speed = $delay; }
/** * Set the external JavaScript code (file) to manage progress element. * * @param string $url URL to the linked Progress JavaScript * * @return void * @since 1.0 * @access public * @throws HTML_PROGRESS_ERROR_INVALID_INPUT * @see getScript() */ function setScript($url) { if (!is_null($url)) { if (!is_string($url)) { Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$url', 'was' => gettype($url), 'expected' => 'string', 'paramnum' => 1), PEAR_ERROR_TRIGGER); } elseif (!is_file($url) || $url == '.' || $url == '..') { Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error', array('var' => '$url', 'was' => $url . ' file does not exists', 'expected' => 'javascript file exists', 'paramnum' => 1), PEAR_ERROR_TRIGGER); } } /* - since version 0.5.0, - default javascript code comes from getScript() method - but may be overrided by external file. */ $this->_script = $url; }
/** * Uploads the files asynchronously, so the class can perform other operations * while files are being uploaded, such : * display a progress bar in indeterminate mode. * * @param string $dest Changes from current to the specified directory. * @param boolean $overwrite (optional) overwrite existing files. * * @return mixed a null array if all files transfered * @since 1.1 * @access public * @see FTP_Upload::setFiles() */ function moveTo($dest, $overwrite = false) { if (!is_string($dest)) { Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$dest', 'was' => gettype($dest), 'expected' => 'string', 'paramnum' => 1), PEAR_ERROR_TRIGGER); } elseif (!is_bool($overwrite)) { Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$overwrite', 'was' => gettype($overwrite), 'expected' => 'boolean', 'paramnum' => 2), PEAR_ERROR_TRIGGER); } $dir = parent::_changeDir($dest); if (PEAR::isError($dir)) { return $dir; } $remoteFiles = ftp_nlist($this->_conn, '.'); if ($remoteFiles === false) { return PEAR::raiseError('Couldn\'t read directory ' . $dest); } $nomove = array(); // files not transfered on remote host foreach ($this->_files as $file) { if (!$overwrite && in_array(basename($file), $remoteFiles)) { // file already exists, skip to next one continue; } // writes file caption $status = ob_get_clean(); $status = '<script type="text/javascript">self.setStatus(\''; $status .= sprintf($this->captionMask, basename($file)); $status .= '\'); </script>'; echo $status; ob_start(); $ret = ftp_nb_put($this->_conn, basename($file), $file, FTP_BINARY); while ($ret == FTP_MOREDATA) { $this->_progress->display(); // sleep a bit ... for ($i = 0; $i < $this->_progress->_anim_speed * 1000; $i++) { } if ($this->_progress->getPercentComplete() == 1) { $this->_progress->setValue(0); } else { $this->_progress->incValue(); } // upload Continue ... $ret = ftp_nb_continue($this->_conn); } if ($ret != FTP_FINISHED) { $nomove[] = $file; } } return $nomove; }
/** * Display a caption on action in progress. * * The idea of a simple utility function for replacing variables * with values in an message template, come from sprintfErrorMessage * function of Error_Raise package by Greg Beaver. * * This simple str_replace-based function can be used to have an * order-independent sprintf, so messages can be passed in * with different grammar ordering, or other possibilities without * changing the source code. * * Variables should simply be surrounded by % as in %varname% * * @param string $caption (optional) message template * @param array $args (optional) associative array of * template var -> message text * @since 1.1 * @access public */ function setCaption($caption = ' ', $args = array()) { if (!is_string($caption)) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$caption', 'was' => gettype($caption), 'expected' => 'string', 'paramnum' => 1), PEAR_ERROR_TRIGGER); } elseif (!is_array($args)) { return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception', array('var' => '$args', 'was' => gettype($args), 'expected' => 'array', 'paramnum' => 2), PEAR_ERROR_TRIGGER); } foreach ($args as $name => $value) { $caption = str_replace("%{$name}%", $value, $caption); } if (function_exists('ob_get_clean')) { $status = ob_get_clean(); // use for PHP 4.3+ } else { $status = ob_get_contents(); // use for PHP 4.2+ ob_end_clean(); } $status = '<script type="text/javascript">self.setStatus(\'' . $caption . '\'); </script>'; echo $status; ob_start(); }