/**
 * 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 <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Settings
 *
 */
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);
                }
            } elseif ($part != '' && ($groupname == $part || $part == 'all')) {
                /**
                 * this part checks for the 'websrv_avail' entry in the settings-array
                 * if found, we check if the current webserver is in the array. If this
                 * is not the case, we change the setting type to "hidden", #502
                 */
                $do_show = true;
                if (isset($groupdetails['websrv_avail']) && is_array($groupdetails['websrv_avail'])) {
                    $websrv = Settings::Get('system.webserver');
                    if (!in_array($websrv, $groupdetails['websrv_avail'])) {
                        $do_show = false;
                    }
                }
                // visible = Settings::Get('phpfpm.enabled') for example would result in false if not enabled
                // and therefore not shown as intended. Only check if do_show is still true as it might
                // be false due to websrv_avail
                if (isset($groupdetails['visible']) && $do_show) {
                    $do_show = $groupdetails['visible'];
                }
                //if ($do_show) {
                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;
}
/**
 * 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 <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Settings
 *
 */
function buildFormEx($form, $part = '')
{
    global $settings;
    $fields = '';
    if (validateFormDefinition($form)) {
        foreach ($form['groups'] as $groupname => $groupdetails) {
            // show overview
            if ($part == '') {
                if (isset($groupdetails['title']) && $groupdetails['title'] != '') {
                    $fields .= getFormOverviewGroupOutput($groupname, $groupdetails);
                }
            } elseif ($part != '' && ($groupname == $part || $part == 'all')) {
                /**
                 * this part checks for the 'websrv_avail' entry in the settings-array
                 * if found, we check if the current webserver is in the array. If this
                 * is not the case, we change the setting type to "hidden", #502
                 */
                $do_show = true;
                if (isset($groupdetails['websrv_avail']) && is_array($groupdetails['websrv_avail'])) {
                    $websrv = $settings['system']['webserver'];
                    if (!in_array($websrv, $groupdetails['websrv_avail'])) {
                        $do_show = false;
                    }
                }
                if ($do_show) {
                    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;
}
Example #3
0
/**
 * This file is part of the Froxlor project.
 * Copyright (c) 2003-2009 the SysCP Team (see authors).
 * 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     Florian Lippert <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Functions
 *
 */
function buildForm($form)
{
    $fields = '';
    if (validateFormDefinition($form)) {
        foreach ($form['groups'] as $groupname => $groupdetails) {
            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;
}
Example #4
0
/**
 * This file is part of the SysCP project.
 * Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
 *
 * @copyright  (c) the authors
 * @author     Florian Lippert <*****@*****.**>
 * @license    GPLv2 http://files.syscp.org/misc/COPYING.txt
 *
 * @version    $Id$
 */
function processForm($form, $input, $url_params = array())
{
    if (validateFormDefinition($form)) {
        $submitted_fields = array();
        $changed_fields = array();
        $saved_fields = array();
        foreach ($form['groups'] as $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];
                }
            }
        }
        foreach ($form['groups'] as $groupname => $groupdetails) {
            if (validateFieldDefinition($groupdetails)) {
                // Validate fields
                foreach ($groupdetails['fields'] as $fieldname => $fielddetails) {
                    $newfieldvalue = getFormFieldData($fieldname, $fielddetails, $input);
                    if (isset($fielddetails['value']) && $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 (validateFieldDefinition($groupdetails)) {
                // Check fields for plausibility
                foreach ($groupdetails['fields'] as $fieldname => $fielddetails) {
                    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 (validateFieldDefinition($groupdetails)) {
                // Save fields
                foreach ($groupdetails['fields'] as $fieldname => $fielddetails) {
                    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);
    }
}