// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or (at // your option) any later version. // // This program 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 // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // Topic: Description // // To use it, // create a subclass and define and optionally in its // constructor. Then, have your program instantiate your class and call // on it. // // TODO: // // Make use of . Right now, we're hard-coded in English. // // Requires: // // <$_REQUEST>, <$PHP_SELF> // // Group: Properties // Property: steps // // Array of methods to call in sequence. The first method name is // invoked at step 1, the second at step 2, etc. You may display any // form fields you wish at each step, but remember that the form block // itself is opened before your method gets called, and closed // afterwards. Multiple forms are not possible. // Property: titles // // Array of titles for each step. If defined, its contents is used to // display a title besides the "Step X of Y" heading. // Private Group: Private Methods // Private Method: Completed // // Display a progress bar. This is a span class 'wizard_progress' with // two spans containing vertical bars, inside. The first span is class // 'wizard_done', and the second is 'wizard_ahead'. After these two, // before closing the main span, a numeric percentage is also written. // It is up to your CSS to hide those bars for graphical browsers. // // Parameters: // $percent - Between 0 and 100 inclusively. (Optional. Default: 0) // $width - Width of the graphical portion, in vertical bars. (Optional. Default: 100) // function Completed($percent = 0, $width = 100) { $left = $width - ($done = floor($width * $percent / 100)); echo "". str_repeat('|',$done) ."". str_repeat('|',$left) ."$percent%"; } // Group: Methods // Constructor: Wizard // // In your own constructor, be sure to define the array, and // optionally the array. // function Wizard() { } // Method: Display // // Actually perform a step basd on <$_REQUEST> parameters. // function Display() { global $PHP_SELF, $_REQUEST; $current = 1; if (array_key_exists('wizard_current',$_REQUEST)) $current = $_REQUEST['wizard_current']; $total = count($this->steps); $this->can_prev = true; $this->can_next = true; if ($current >= $total) { echo "

Finished: {$this->titles[$total - 1]}

\n"; echo "

Completed: ". $this->Completed(100) ."

\n"; echo "
\n"; $calling = $this->steps[$total - 1]; if (method_exists($this, $calling)) $this->$calling(); $this->can_next = false; } else { echo "

Step $current of $total"; if (is_array($this->titles)) echo ': '. $this->titles[$current - 1]; echo "

\n"; echo "

Completed: ". $this->Completed(floor(($current - 1) * 100 / ($total - 1))) ."

\n"; echo "\n"; $calling = $this->steps[$current - 1]; if (method_exists($this, $calling)) $this->$calling(); }; if ($current <= 1) $this->can_prev = false; ?> can_prev) ? 'disabled="true"' : '')?> /> can_next) ? 'disabled="true"' : '')?>/>