<?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: form.php,v 1.9 2004/04/04 15:53:42 ordnas Exp $
@copyright Copyright © 2001-2004 ZZ/OSS GbR, http://www.zzoss.com
@license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
*/
// set parameters
define('ZI_LOCATION_CANCEL', 'cancel.php');
// redirect if we cancel
if(isset($_REQUEST['ZI_BUTTON_CANCEL']) || isset($_REQUEST['ZI_BUTTON_CANCEL_x'])){
if(!isset($_REQUEST['ZI_LOCATION_CANCEL'])){
$_REQUEST['ZI_LOCATION_CANCEL'] = $chdir.ZI_LOCATION_CANCEL;
}
header('Location: '.$_REQUEST['ZI_LOCATION_CANCEL']);
exit;
}
// redirect to previous page
if(isset($_REQUEST['ZI_BUTTON_BACK']) || isset($_REQUEST['ZI_BUTTON_BACK_x'])){
header('Location: '.$_REQUEST['ZI_LOCATION_BACK']);
exit;
}
// did we submit valid data?
if(
isset($_REQUEST['ZI_BUTTON_NEXT']) || isset($_REQUEST['ZI_BUTTON_NEXT_x']) ||
isset($_REQUEST['ZI_BUTTON_OK']) || isset($_REQUEST['ZI_BUTTON_OK_x'])){
//echo 'VALIDATE';
// iterate values
if(isset($_REQUEST['ZI_VALUES']) && isset($_REQUEST['ZI_VALIDATIONS']) && is_array($_REQUEST['ZI_VALIDATIONS']) && count($_REQUEST['ZI_VALIDATIONS'])){
$zi_errors = null;
foreach($_REQUEST['ZI_VALIDATIONS'] as $var_name => $validation_type){
// what should we check?
$switch = $validation_type;
switch($switch){
case 'not empty':
if(strlen($_REQUEST['ZI_VALUES'][$var_name]) < 1){
$zi_errors[$var_name] = 'must not be empty';
}
break;
case 'email':
if (!empty($_REQUEST['ZI_VALUES'][$var_name])){
if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+([a-z]{2,3}$)", trim($_REQUEST['ZI_VALUES'][$var_name]), $check)) {
$zi_errors[$var_name] = 'wrong email syntax';
}
} else {
$zi_errors[$var_name] = 'no email provided';
}
break;
}
}
}
// check for custom validation
if(function_exists('zi_validate')){
$custom_result = call_user_func('zi_validate');
if(is_array($custom_result) && count($custom_result)) {
if(!is_array($zi_errors)) {
$zi_errors = array();
}
$zi_errors = array_merge($zi_errors, $custom_result);
}
}
}
//print_r($_REQUEST);
if(
(
isset($_REQUEST['ZI_BUTTON_NEXT']) || isset($_REQUEST['ZI_BUTTON_NEXT_x']) ||
isset($_REQUEST['ZI_BUTTON_OK']) || isset($_REQUEST['ZI_BUTTON_OK_x'])
) &&
!isset($zi_errors)){
// process data
if(function_exists('zi_process')){
call_user_func('zi_process', array($_REQUEST));
}
// go on
if(isset($_REQUEST['ZI_LOCATION_NEXT']) && strlen($_REQUEST['ZI_LOCATION_NEXT'])){
$redirect = $_REQUEST['ZI_LOCATION_NEXT'];
header('Location: '.$redirect);
exit;
} elseif(isset($_REQUEST['ZI_LOCATION_OK']) && strlen($_REQUEST['ZI_LOCATION_OK'])) {
$redirect = $_REQUEST['ZI_LOCATION_OK'];
header('Location: '.$redirect);
exit;
}
}
// assign default values
if(!(isset($_REQUEST['ZI_BUTTON_NEXT']) || isset($_REQUEST['ZI_BUTTON_NEXT_x']))){
if(function_exists('zi_default') && ($def = call_user_func('zi_default'))){
$_REQUEST = $def;
}
}
// compose the query string
function zi_form_querystr()
{
$fields = array('id', 'distribution', 'application', 'package', 'mode', 'update_old', 'type', 'dev', 'profile', 'nav', 'widget_type');
$querystr = '';
foreach($fields as $field){
if(isset($_REQUEST[$field])){
$querystr .= $field.'='.rawurlencode($_REQUEST[$field]).'&';
}
}
return '?'.$querystr;
}
function zi_form_hidden_fields($fields)
{
if(is_array($fields) && count($fields)){
foreach($fields as $field){
if(isset($_REQUEST[$field])){
?>
<input type="hidden" name="<?php echo $field; ?>" value="<?php echo $_REQUEST[$field]; ?>">
<?php
}
}
}
}
?>