HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/keystud.komma-mediadesign.nl/wwwroot/kms/lib/form/form_block.class.php
<?php

/**
 * form_blocks.class.php
 * Created by Komma Mediadesign.
 * Author: mike
 * Date: 4/3/13
 */

class Form_Block
{
    /*
     * Info (for example name, width, extra classes
     */
    private $_data;

    /*
     * Blocks inside this block
     */
    private $_children;

    /*
     * Fields inside this block
     */
    private $_fields;


    /*
     * Construct
     */
    public function construct(){}

    /*
     * Add a child block to this block
     */
    public function addChild($string)
    {
        if( ! empty($string))
        {
        $this->_children[] = $string;
        }
    }

    /*
     * Add a child field to this block
     */
    public function addField($Field)
    {
        if( ! empty($Field))
        {
            $this->_fields[] = $Field;
        }
    }

    /*
     * Configure Block
     */
    public function setData($key,$value)
    {
        if( ! empty($key))
        {
            $this->_data[$key] = $value;
        }
    }

    /*
     * Return output block
     */
    public function display()
    {
        $output = '';
        $output .= '<div class="column';
            if(isset($this->_data['last'])) $output .= ' last';
            if(isset($this->_data['width']))
            {
                switch($this->_data['width'])
                {
                    case 2 : $output .= ' double';
                        break;
                    case 3 : $output .= ' triple';
                        break;
                    case 4 : $output .= ' quadruple';
                        break;
                }
            }
        $output .= '">';

        // check if this block has children blocks
        if( isset($this->_children) && is_array($this->_children))
        {
            foreach($this->_children as $child)
            {
                $output .= $child;
            }
        }


        // check if this block contains any fields
        if( isset($this->_fields) && is_array($this->_fields))
        {
            foreach ($this->_fields as $Field)
            {
                //  Get field data

                $data = $Field->get();

                if( ! empty($data['name']))
                {
                    $output .= '<div class="input_holder';

                    // Get errors
                    $errorKey = array($data['form_name'] . '_errors', $data['name']);
                    $error = '';
                    $error .= Session::get($errorKey);
                    if( ! empty($error))
                    {
                        $output .= ' input_error';
                        // clean up error
                        Session::destroy($errorKey);
                    }
                    $output .= '">';

                    // Label
                    $output .= '<label for="' . $data['id'] . '">' . $data['label'];
                    if(isset($data['validation'][1]))
                    {
                        if(is_object($data['validation'][1]))
                        {
                            $validation = $data['validation'][1]->getName();
                            if($validation == 'required') $output .= ' *';
                        };
                    }
                    $output .= '</label>';

                    // Get specified object
                    isset($data['object']) ? $object = $data['object'] : $object = 'Field_Type_Text_Field';
                    $file = DOCUMENT_ROOT . 'lib/form/types/' . $object . '.class.php';
                    if(is_file($file))
                    {
                        if( ! class_exists($object)) require $file;
                        $TypeObject = new $object($data['label']);
                        $TypeObject->set($data);
                        $output .= $TypeObject->createInput();
                    }
                    $output .= '</div>';
                }
            }
        }
        $output .= '</div>';
        if(isset($this->_data['clear'])) $output .= '<div class="clear"></div>';


        return $output;
    }
}