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/SBogers18/decoockpit.nl/wwwroot/kms/lib/form/types/field_type_date.class.php
<?php
/**
 * form_type_date.class.php
 * Created by Komma Mediadesign.
 * Author: mike
 * Date: 4/3/13
 */

class Field_Type_Date extends Form_Field
{
    public function construct(){}

    public function createInput()
    {
        // Text area
        $output = '';
        $output .= '<input name="' . $this->_info['name'] . '" type="' . $this->_info['type'] . '" value="' . $this->_info['value'] . '" data-label="' . $this->_info['label'] . '"';
        if( ! empty($this->_info['id'])) $output .= ' id="' . $this->_info['id'] . '"';
        if(count($this->_info['classes']) > 0)
        {
            $output .= ' class="';
            foreach($this->_info['classes'] as $i => $class)
            {
                if($i != 0) $output .= ' ';
                $output .= $class;
            }
            $output .= '"';
        }
        $output .= ' />';
        return $output;
    }

    /*
     * Check if date really exists
     */
    public function validate($input)
    {
        //check if input is a valid date
        $temp = explode('-',$input);
        if(count($temp) >= 3)
        {
            $month = (int) $temp[0];
            $day = (int) $temp[1];
            $year = (int) $temp[2];

            if(checkdate($month,$day,$year))
            {
                return true;
            }
        }
        $this->_error = 'Please enter a valid date';
        return false;
    }

    /*
     * Converts '-' separated date to a timestamp
     */
    public function prepareToDb($input)
    {
        $temp = explode('-',$input);
        if(count($temp) >= 3)
        {
            $month = (int) $temp[0];
            $day = (int) $temp[1];
            $year = (int) $temp[2];

            $timestamp = mktime(12,0,0,$month,$day,$year);
            return $timestamp;
        }
        return $input;
    }

    /*
     * Converts timestamp to a '-' separated date
     */
    public function prepareFromDb($timestamp)
    {
        $date = date('m-d-Y',$timestamp);
        return $date;
    }

    /*
     * Return errors
     */
    public function getError()
    {
        return $this->_error;
    }
}