<?php

class Input{


    public static function exists($type='post')
    {
        switch($type)
        {
            case 'post':
                return (!empty($_POST)?true:false);
                break;

            case 'get':
                return (!empty($_GET)?true:false);
                break;

            default :
                return false;
                break;


        }


    }


    public static function getInput($name,$requestedArray=array())
    {
        if(isset($_POST[$name]))
        {
            return $_POST[$name];
        }
        else  if(isset($_GET[$name]))
        {
            return $_GET[$name];
        }
        else if(!empty($requestedArray))
        {
            return $requestedArray[$name];
        }

        else return '';

    }


    public static function getSelected($name,$requestedArray=array(),$values=array())
    {
        $r='';

        foreach ($values as $key=>$value)
        {
            $r.='<option ';
            $r.="value='{$key}'";

            if(isset($_POST[$name]) && $_POST[$name]==$key)
            {
                 $r.=" selected ";
            }
            
             else if(isset($_SESSION[$name]) && $_SESSION[$name]==$key && empty($requestedArray))
            {
                $r.=" selected ";
            }

            else if(!empty($requestedArray) && isset($requestedArray[$name]) && $requestedArray[$name]==$key )
            {
                $r.=" selected ";
            }
            
           



            $r.="> {$value} </option>";
        }

        return $r;

    }


    public static function getMultiSelected($name,$requestedArray=array(),$values=array())
    {
        $r='';

        foreach ($values as $key=>$value)
        {
            $r.='<option ';
            $r.="value='{$key}'";

            if(isset($_POST[$name]) && $_POST[$name]==$key)
            {
                $r.=" selected ";
            }


            else if(!empty($requestedArray) && in_array($key,$requestedArray) )
            {
                //echo "working";
                $r.=" selected ";
            }

            $r.="> {$value} </option>";
        }

        return $r;

    }


    public static function particularInputExists($type='post',$input=null)
    {

        switch($type)
        {
            case 'post':
                return (!empty($_POST[$input])?true:false);
                break;

            case 'get':
                return (!empty($_GET[$input])?true:false);
                break;

            default :
                return false;
                break;


        }


    }

}