- merged settings branch, fixes #134
This commit is contained in:
62
lib/functions/formfields/function.buildFormEx.php
Normal file
62
lib/functions/formfields/function.buildFormEx.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Settings
|
||||
* @version $Id $
|
||||
*/
|
||||
|
||||
function buildFormEx($form, $part = '')
|
||||
{
|
||||
$fields = '';
|
||||
|
||||
if(validateFormDefinition($form))
|
||||
{
|
||||
foreach($form['groups'] as $groupname => $groupdetails)
|
||||
{
|
||||
// show overview
|
||||
if($part == '')
|
||||
{
|
||||
if(isset($groupdetails['title']) && $groupdetails['title'] != '')
|
||||
{
|
||||
$fields .= getFormOverviewGroupOutput($groupname, $groupdetails);
|
||||
}
|
||||
}
|
||||
// only show one section
|
||||
elseif($part != '' && ($groupname == $part || $part == 'all'))
|
||||
{
|
||||
if(isset($groupdetails['title']) && $groupdetails['title'] != '')
|
||||
{
|
||||
$fields .= getFormGroupOutput($groupname, $groupdetails);
|
||||
}
|
||||
|
||||
if(validateFieldDefinition($groupdetails))
|
||||
{
|
||||
// Prefetch form fields
|
||||
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
|
||||
{
|
||||
$groupdetails['fields'][$fieldname] = array_merge_prefix($fielddetails, $fielddetails['type'], prefetchFormFieldData($fieldname, $fielddetails));
|
||||
$form['groups'][$groupname]['fields'][$fieldname] = $groupdetails['fields'][$fieldname];
|
||||
}
|
||||
|
||||
// Collect form field output
|
||||
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
|
||||
{
|
||||
$fields .= getFormFieldOutput($fieldname, $fielddetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
function getFormFieldData($fieldname, $fielddata, $input)
|
||||
function getFormFieldData($fieldname, $fielddata, &$input)
|
||||
{
|
||||
if(is_array($fielddata) && isset($fielddata['type']) && $fielddata['type'] != '' && function_exists('getFormFieldData' . ucfirst($fielddata['type'])))
|
||||
{
|
||||
|
||||
@@ -23,3 +23,54 @@ function getFormGroupOutput($groupname, $groupdetails)
|
||||
eval("\$group = \"" . getTemplate("settings/settings_group") . "\";");
|
||||
return $group;
|
||||
}
|
||||
|
||||
function getFormOverviewGroupOutput($groupname, $groupdetails)
|
||||
{
|
||||
global $lng, $settings, $filename, $s;
|
||||
|
||||
$group = '';
|
||||
$title = $groupdetails['title'];
|
||||
$part = $groupname;
|
||||
|
||||
$activated = true;
|
||||
$option = '';
|
||||
if(isset($groupdetails['fields']))
|
||||
{
|
||||
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
|
||||
{
|
||||
if(isset($fielddetails['overview_option'])
|
||||
&& $fielddetails['overview_option'] == true
|
||||
) {
|
||||
if($fielddetails['type'] != 'option'
|
||||
&& $fielddetails['type'] != 'bool')
|
||||
{
|
||||
standard_error('overviewsettingoptionisnotavalidfield');
|
||||
}
|
||||
|
||||
if($fielddetails['type'] == 'option')
|
||||
{
|
||||
$options_array = $fielddetails['option_options'];
|
||||
$options = '';
|
||||
foreach($options_array as $value => $vtitle)
|
||||
{
|
||||
$options .= makeoption($vtitle, $value, $settings[$fielddetails['settinggroup']][$fielddetails['varname']]);
|
||||
}
|
||||
$option.= $fielddetails['label'].': ';
|
||||
$option.= '<select class="dropdown_noborder" name="'.$fieldname.'">';
|
||||
$option.= $options;
|
||||
$option.= '</select>';
|
||||
$activated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$option.= $lng['admin']['activated'].': ';
|
||||
$option.= makeyesno($fieldname, '1', '0', $settings[$fielddetails['settinggroup']][$fielddetails['varname']]);
|
||||
$activated = (int)$settings[$fielddetails['settinggroup']][$fielddetails['varname']];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eval("\$group = \"" . getTemplate("settings/settings_overviewgroup") . "\";");
|
||||
return $group;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
function processForm($form, $input, $url_params = array())
|
||||
function processForm(&$form, &$input, $url_params = array())
|
||||
{
|
||||
if(validateFormDefinition($form))
|
||||
{
|
||||
@@ -45,7 +45,7 @@ function processForm($form, $input, $url_params = array())
|
||||
// Validate fields
|
||||
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
|
||||
{
|
||||
$newfieldvalue = getFormFieldData($fieldname, $fielddetails, &$input);
|
||||
$newfieldvalue = getFormFieldData($fieldname, $fielddetails, $input);
|
||||
|
||||
if($newfieldvalue != $fielddetails['value'])
|
||||
{
|
||||
@@ -143,3 +143,166 @@ function processForm($form, $input, $url_params = array())
|
||||
return saveForm($form, $saved_fields);
|
||||
}
|
||||
}
|
||||
|
||||
function processFormEx(&$form, &$input, $url_params = array(), $part, $settings_all, $settings_part, $only_enabledisable)
|
||||
{
|
||||
if(validateFormDefinition($form))
|
||||
{
|
||||
$submitted_fields = array();
|
||||
$changed_fields = array();
|
||||
$saved_fields = array();
|
||||
|
||||
foreach($form['groups'] as $groupname => $groupdetails)
|
||||
{
|
||||
if(($settings_part && $part == $groupname)
|
||||
|| $settings_all
|
||||
|| $only_enabledisable
|
||||
){
|
||||
if(validateFieldDefinition($groupdetails))
|
||||
{
|
||||
// Prefetch form fields
|
||||
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
|
||||
{
|
||||
if(!$only_enabledisable
|
||||
|| ($only_enabledisable && isset($fielddetails['overview_option']))
|
||||
) {
|
||||
$groupdetails['fields'][$fieldname] = array_merge_prefix($fielddetails, $fielddetails['type'], prefetchFormFieldData($fieldname, $fielddetails));
|
||||
$form['groups'][$groupname]['fields'][$fieldname] = $groupdetails['fields'][$fieldname];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($form['groups'] as $groupname => $groupdetails)
|
||||
{
|
||||
if(($settings_part && $part == $groupname)
|
||||
|| $settings_all
|
||||
|| $only_enabledisable
|
||||
){
|
||||
if(validateFieldDefinition($groupdetails))
|
||||
{
|
||||
// Validate fields
|
||||
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
|
||||
{
|
||||
if(!$only_enabledisable
|
||||
|| ($only_enabledisable && isset($fielddetails['overview_option']))
|
||||
) {
|
||||
$newfieldvalue = getFormFieldData($fieldname, $fielddetails, $input);
|
||||
|
||||
if($newfieldvalue != $fielddetails['value'])
|
||||
{
|
||||
if(($error = validateFormField($fieldname, $fielddetails, $newfieldvalue)) !== true)
|
||||
{
|
||||
standard_error($error, $fieldname);
|
||||
}
|
||||
else
|
||||
{
|
||||
$changed_fields[$fieldname] = $newfieldvalue;
|
||||
}
|
||||
}
|
||||
|
||||
$submitted_fields[$fieldname] = $newfieldvalue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($form['groups'] as $groupname => $groupdetails)
|
||||
{
|
||||
if(($settings_part && $part == $groupname)
|
||||
|| $settings_all
|
||||
|| $only_enabledisable
|
||||
){
|
||||
if(validateFieldDefinition($groupdetails))
|
||||
{
|
||||
// Check fields for plausibility
|
||||
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
|
||||
{
|
||||
if(!$only_enabledisable
|
||||
|| ($only_enabledisable && isset($fielddetails['overview_option']))
|
||||
) {
|
||||
if(($plausibility_check = checkPlausibilityFormField($fieldname, $fielddetails, $submitted_fields[$fieldname], $submitted_fields)) !== false)
|
||||
{
|
||||
if(is_array($plausibility_check) && isset($plausibility_check[0]))
|
||||
{
|
||||
if($plausibility_check[0] == FORMFIELDS_PLAUSIBILITY_CHECK_OK)
|
||||
{
|
||||
// Nothing to do here, everything's okay
|
||||
}
|
||||
elseif($plausibility_check[0] == FORMFIELDS_PLAUSIBILITY_CHECK_ERROR)
|
||||
{
|
||||
unset($plausibility_check[0]);
|
||||
$error = $plausibility_check[1];
|
||||
unset($plausibility_check[1]);
|
||||
$targetname = implode(' ', $plausibility_check);
|
||||
standard_error($error, $targetname);
|
||||
}
|
||||
elseif($plausibility_check[0] == FORMFIELDS_PLAUSIBILITY_CHECK_QUESTION)
|
||||
{
|
||||
unset($plausibility_check[0]);
|
||||
$question = $plausibility_check[1];
|
||||
unset($plausibility_check[1]);
|
||||
$targetname = implode(' ', $plausibility_check);
|
||||
if(!isset($input[$question]))
|
||||
{
|
||||
if(is_array($url_params) && isset($url_params['filename']))
|
||||
{
|
||||
$filename = $url_params['filename'];
|
||||
unset($url_params['filename']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$filename = '';
|
||||
}
|
||||
ask_yesno($question, $filename, array_merge($url_params, $submitted_fields, array($question => $question)), $targetname);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
standard_error('plausibilitychecknotunderstood');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($form['groups'] as $groupname => $groupdetails)
|
||||
{
|
||||
if(($settings_part && $part == $groupname)
|
||||
|| $settings_all
|
||||
|| $only_enabledisable
|
||||
){
|
||||
if(validateFieldDefinition($groupdetails))
|
||||
{
|
||||
// Save fields
|
||||
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
|
||||
{
|
||||
if(!$only_enabledisable
|
||||
|| ($only_enabledisable && isset($fielddetails['overview_option']))
|
||||
) {
|
||||
if(isset($changed_fields[$fieldname]))
|
||||
{
|
||||
if(($saved_field = saveFormField($fieldname, $fielddetails, manipulateFormFieldData($fieldname, $fielddetails, $changed_fields[$fieldname]))) !== false)
|
||||
{
|
||||
$saved_fields = array_merge($saved_fields, $saved_field);
|
||||
}
|
||||
else
|
||||
{
|
||||
standard_error('errorwhensaving', $fieldname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save form
|
||||
return saveForm($form, $saved_fields);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
function loadSettings($settings_data, $db)
|
||||
function loadSettings(&$settings_data, $db)
|
||||
{
|
||||
$settings = array();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user