Location: PHPKode > projects > ZZ/OSS Installer > zic-1.1.0dev1/installer/lib/ZZOSS_Installer/Widget.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
    */
    
    /**
    @version $Id: Widget.php,v 1.8 2004/03/26 10:26:31 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_InstallerWidget
{

    var $errors;
    var $helpPath;
    
	function setErrors($errors)
	{
	  	$this->errors = $errors;
	}

	function setDefault($key, $val, $force = false)
	{
	  	if(!isset($_REQUEST['ZI_VALUES'][$key]) || $force){
		  	$_REQUEST['ZI_VALUES'][$key] = $val;
	  	}
	}


	function setHelpPath($path)
	{
	  	$this->helpPath = $path;
	}

	function add($widget, $label, $name = null, $options = array())
	{
	  	$this->label = $label;
		$this->name = $name;
		$this->options = $options;
		return $this->$widget();
	}

	function help($path, $title)
	{
	  	if($path != $this->helpPath){
		  	if(file_exists($path)){
			  	return '(<a href="'.$path.'" onclick="javascript:window.open(\''.$path.'\', \'Help\', \'width=200,height=200,resizable=1,status=0,scrollbars=1,toolbar=0,location=0,directories=0,menubar=0,dependent=1\');void(0);javascript:return(false);" target="_blank">?</a>)';
			} else {
			  	return '<b>Error: missing help file</b>';
			}
		} else {
		  	return '&nbsp;';
		}
	}

	function text()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><input type="text" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>" size="30">
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}
	
	function file()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><input type="file" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>" size="30">
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	function id()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><input type="text" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>" size="6" maxlength="10">
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	function path()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><input type="text" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>" size="40" maxlength="255"<?php
            if(isset($this->options['disabled']) && $this->options['disabled']){
                echo ' disabled';
            }
            ?>>
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	function email()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><input type="text" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>" size="30" maxlength="64">
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	function text_locked()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><input type="text" name="ZI_VALUES_TEMP[<?php echo $this->name; ?>]" value="<?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>" size="30" disabled read-only>
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>">
			</td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}
	
	function textNotChecked()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><input type="text" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>" size="30">
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<!--<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>">--></td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	function textarea()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><textarea name="ZI_VALUES[<?php echo $this->name; ?>]" rows="6" cols="60"><?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?></textarea>
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}


	function pwd()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><input type="password" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>" size="30">
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}


	function locked()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>
			<input type="hidden" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>">
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}


	function select()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  	echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><select name="ZI_VALUES[<?php echo $this->name; ?>]"><?php
			$options_split = preg_split('/,/',$this->options['list']);
			if(is_array($options_split) && count($options_split)){
				foreach($options_split as $option_split){
					$options_val = preg_split('/=>/', $option_split);
					$options[trim($options_val[1])] = trim($options_val[0]);
				}
			}
			if(is_array($options) && count($options)){
			  	foreach($options as $key => $val){
				  	?>
					<option value="<?php echo $val; ?>" <?php if(isset($_REQUEST['ZI_VALUES'][$this->name]) && $_REQUEST['ZI_VALUES'][$this->name] == $val) echo 'selected';?>><?php echo $key; ?>
					<?php
				}
			}
			?>
			</select>
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="	ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	function radiobutton()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
            
			?><input type="radio" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php echo $this->options['value']; ?>"<?php
            if(isset($_REQUEST['ZI_VALUES'][$this->name]) && $_REQUEST['ZI_VALUES'][$this->name] == $this->options['value']){
                echo ' checked';
            }?>>
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	function checkbox()
	{
        $checked = '';
        if(!isset($this->options['value'])){
            $this->options['value'] = 'on';
        }
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
            if(isset($_REQUEST['ZI_VALUES'][$this->name]) && $_REQUEST['ZI_VALUES'][$this->name] == $this->options['value']){
                $checked = ' checked';
            }
			?><input type="checkbox" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php echo $this->options['value']; ?>"<?php echo $checked; ?><?php
            if(isset($this->options['disabled']) && $this->options['disabled']){
                echo ' disabled';
            }
            ?>>
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	function dsn()
	{
	  	ob_start();
		/*
		if(strlen($_REQUEST['ZI_VALUES'][$name]) == 0){
			$_REQUEST['ZI_VALUES'][$name] = $_REQUEST['ZI_VALUES']['default_dsn'];
		}*/
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><input type="text" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php if(isset($_REQUEST['ZI_VALUES'][$this->name])) echo $_REQUEST['ZI_VALUES'][$this->name]; ?>" size="40" maxlength="255">
            <?php
            if(isset($this->options['append'])) echo $this->options['append'];
            if(isset($this->options['info'])){
                echo '<br/>';
                echo $this->options['info'];
            }
            ?>
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php echo $this->help('help/dsn.html', 'DSN'); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	function api()
	{
	  	ob_start();/*
		if(strlen($_REQUEST['ZI_VALUES'][$name]) == 0){
		  	$_REQUEST['ZI_VALUES'][$name] = $_REQUEST['ZI_VALUES']['default_api'];
		}*/
		?>
		<tr>
			<td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
			<td align="left" valign="top"><?php
			if(isset($this->errors[$this->name])){
			  	echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
			}
			?><select name="ZI_VALUES[<?php echo $this->name; ?>]">
			<option value=""></option>
			<option value="PHP::PEAR::DB" <?php if($_REQUEST['ZI_VALUES'][$this->name] == 'PHP::PEAR::DB') echo 'selected';?>>PHP::PEAR::DB
			<option value="PHP::PEAR::SOAP" <?php if($_REQUEST['ZI_VALUES'][$this->name] == 'PHP::PEAR::SOAP') echo 'selected';?>>PHP::PEAR::SOAP
			<option value="ZZOSS::Authorization::PHP::PEAR::DB" <?php if($_REQUEST['ZI_VALUES'][$this->name] == 'ZZOSS::Authorization::PHP::PEAR::DB') echo 'selected';?>>ZZOSS::Authorization::PHP::PEAR::DB
			<option value="ZZOSS::Repository::PHP::PEAR::DB" <?php if($_REQUEST['ZI_VALUES'][$this->name] == 'ZZOSS::Repository::PHP::PEAR::DB') echo 'selected';?>>ZZOSS::Repository::PHP::PEAR::DB
			<option value="ZZOSS::Repository::PHP::PEAR::OAI::Client" <?php if($_REQUEST['ZI_VALUES'][$this->name] == 'ZZOSS::Repository::PHP::PEAR::OAI::Client') echo 'selected';?>>ZZOSS::Repository::PHP::PEAR::OAI::Client
			<option value="ZZOSS::Repository::PHP::PEAR::OAI::Server" <?php if($_REQUEST['ZI_VALUES'][$this->name] == 'ZZOSS::Repository::PHP::PEAR::OAI::Server') echo 'selected';?>>ZZOSS::Repository::PHP::PEAR::OAI::Server
			<option value="ZZOSS::Repository::PHP::PEAR::SOAP" <?php if($_REQUEST['ZI_VALUES'][$this->name] == 'ZZOSS::Repository::PHP::PEAR::SOAP') echo 'selected';?>>ZZOSS::Repository::PHP::PEAR::SOAP
			</select>
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>"></td>
			<td align="left" valign="middle"><?php echo $this->help('help/api.html', 'API'); ?></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	function comment()
	{
	  	ob_start();
		?>
		<tr>
			<td align="left" valign="top" colspan="3"><p><?php echo $this->label; ?></p></td>
		</tr>
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}
    
    function hidden()
	{
	  	ob_start();
			if(isset($this->errors[$this->name])){
                ?>
                <tr>
                <td align="left" valign="top"><span class="label"><?php echo $this->label; ?></span></td>
                <td align="left" valign="top"><?php
                echo '<div class="warning-inline">'.$this->errors[$this->name].'</div>';
                ?>
                </td>
                <td align="left" valign="middle"><?php if(isset($this->options['help'])) echo $this->help($this->helpPath.$this->options['help'], $this->label); ?></td>
                </tr>
            <?php
			}
			?>
            <input type="hidden" name="ZI_VALUES[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['default'])) echo $this->options['default']; ?>">
			<input type="hidden" name="ZI_VALIDATIONS[<?php echo $this->name; ?>]" value="<?php if(isset($this->options['validation'])) echo $this->options['validation']; ?>">
		<?php
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}
}
Return current item: ZZ/OSS Installer