CBPVirtualDocument :: GetFieldInputValue: Bitrix method

      
<?php 
//  CBPVirtualDocument :: GetFieldInputValue()
//  /dist/bitrix/modules/bizproc/classes/general/virtualdocument.php:509

    
function GetFieldInputValue($documentType$arFieldType$arFieldName$arRequest, &$arErrors)
    {
        
$v substr($documentTypestrlen("type_"));
        if (
intval($v)."!" != $v."!")
            return 
null;
        
$iblockId intval($v);

        
$result = array();

        if (
$arFieldType["Type"] == "S:UserID")
        {
            
$value $arRequest[$arFieldName["Field"]];
            if (
strlen($value) > 0)
            {
                
$arErrorsTmp1 = array();
                
$result CBPHelper::UsersStringToArray($value, array("bizproc""CBPVirtualDocument"$documentType), $arErrorsTmp1);
                if (
count($arErrorsTmp1) > 0)
                {
                    foreach (
$arErrorsTmp1 as $e)
                        
$arErrors[] = $e;
                }
            }
        }
        elseif (
array_key_exists($arFieldName["Field"], $arRequest) || array_key_exists($arFieldName["Field"]."_text"$arRequest))
        {
            
$arValue = array();
            if (
array_key_exists($arFieldName["Field"], $arRequest))
            {
                
$arValue $arRequest[$arFieldName["Field"]];
                if (!
is_array($arValue) || is_array($arValue) && CBPHelper::IsAssociativeArray($arValue))
                    
$arValue = array($arValue);
            }
            if (
array_key_exists($arFieldName["Field"]."_text"$arRequest))
                
$arValue[] = $arRequest[$arFieldName["Field"]."_text"];

            foreach (
$arValue as $value)
            {
                if (
is_array($value)
                    || !
is_array($value) && !CBPActivity::isExpression($value))
                {
                    if (
$arFieldType["Type"] == "N")
                    {
                        if (
strlen($value) > 0)
                        {
                            
$value str_replace(" """str_replace(",""."$value));
                            if (
is_numeric($value))
                            {
                                
$value doubleval($value);
                            }
                            else
                            {
                                
$value null;
                                
$arErrors[] = array(
                                    
"code" => "ErrorValue",
                                    
"message" => GetMessage("BPCGWTL_INVALID1N"),
                                    
"parameter" => $arFieldName["Field"],
                                );
                            }
                        }
                        else
                        {
                            
$value null;
                        }
                    }
                    elseif (
$arFieldType["Type"] == "L")
                    {
                        if (!
is_array($arFieldType["Options"]) || count($arFieldType["Options"]) <= || strlen($value) <= 0)
                        {
                            
$value null;
                        }
                        else
                        {
                            
$ar array_values($arFieldType["Options"]);
                            if (
is_array($ar[0]))
                            {
                                
$b false;
                                foreach (
$ar as $a)
                                {
                                    if (
$a[0] == $value)
                                    {
                                        
$b true;
                                        break;
                                    }
                                }
                                if (!
$b)
                                {
                                    
$value null;
                                    
$arErrors[] = array(
                                        
"code" => "ErrorValue",
                                        
"message" => GetMessage("BPCGWTL_INVALID3N"),
                                        
"parameter" => $arFieldName["Field"],
                                    );
                                }
                            }
                            else
                            {
                                if (!
array_key_exists($value$arFieldType["Options"]))
                                {
                                    
$value null;
                                    
$arErrors[] = array(
                                        
"code" => "ErrorValue",
                                        
"message" => GetMessage("BPCGWTL_INVALID3N"),
                                        
"parameter" => $arFieldName["Field"],
                                    );
                                }
                            }
                        }
                    }
                    elseif (
$arFieldType["Type"] == "B")
                    {
                        if (
$value !== "Y" && $value !== "N")
                        {
                            if (
$value === true)
                            {
                                
$value "Y";
                            }
                            elseif (
$value === false)
                            {
                                
$value "N";
                            }
                            elseif (
strlen($value) > 0)
                            {
                                
$value strtolower($value);
                                if (
in_array($value, array("y""yes""true""1")))
                                {
                                    
$value "Y";
                                }
                                elseif (
in_array($value, array("n""no""false""0")))
                                {
                                    
$value "N";
                                }
                                else
                                {
                                    
$value null;
                                    
$arErrors[] = array(
                                        
"code" => "ErrorValue",
                                        
"message" => GetMessage("BPCGWTL_INVALID4N"),
                                        
"parameter" => $arFieldName["Field"],
                                    );
                                }
                            }
                            else
                            {
                                
$value null;
                            }
                        }
                    }
                    elseif (
$arFieldType["Type"] == "F")
                    {
                        if (
array_key_exists("name"$value) && strlen($value["name"]) > 0)
                        {
                            if (!
array_key_exists("MODULE_ID"$value))
                                
$value["MODULE_ID"] = "bizproc";

                            
$value CFile::SaveFile($value"bizproc_wf"true);
                            if (!
$value)
                            {
                                
$value null;
                                
$arErrors[] = array(
                                    
"code" => "ErrorValue",
                                    
"message" => GetMessage("BPCGWTL_INVALID9N"),
                                    
"parameter" => $arFieldName["Field"],
                                );
                            }
                        }
                        else
                        {
                            
$value null;
                        }
                    }
                    elseif (
strpos($arFieldType["Type"], ":") !== false)
                    {
                        
$arCustomType CIBlockProperty::GetUserType(substr($arFieldType["Type"], 2));
                        if (
array_key_exists("GetLength"$arCustomType))
                        {
                            if (
call_user_func_array(
                                
$arCustomType["GetLength"],
                                array(
                                    array(
"LINK_IBLOCK_ID" => $arFieldType["Options"]),
                                    array(
"VALUE" => $value)
                                )
                            ) <= 
0)
                            {
                                
$value null;
                            }
                        }
                        else
                        {
                            if (!
is_array($value) && (strlen($value) == 0) || is_array($value) && (count($value) == || count($value) == && isset($value["VALUE"]) && !is_array($value["VALUE"]) && strlen($value["VALUE"]) == 0))
                                
$value null;
                        }

                        if ((
$value !== null) && array_key_exists("CheckFields"$arCustomType))
                        {
                            
$arErrorsTmp1 call_user_func_array(
                                
$arCustomType["CheckFields"],
                                array(
                                    array(
"LINK_IBLOCK_ID" => $arFieldType["Options"]),
                                    array(
"VALUE" => $value)
                                )
                            );
                            if (
count($arErrorsTmp1) > 0)
                            {
                                
$value null;
                                foreach (
$arErrorsTmp1 as $e)
                                    
$arErrors[] = array(
                                        
"code" => "ErrorValue",
                                        
"message" => $e,
                                        
"parameter" => $arFieldName["Field"],
                                    );
                            }
                        }

                        if ((
$value !== null)
                            && (
$arFieldType["Type"] == "S:employee")
                            && 
COption::GetOptionString("bizproc""employee_compatible_mode""N") != "Y")
                        {
                            
$value "user_".$value;
                        }
                    }
                    else
                    {
                        if (!
is_array($value) && strlen($value) <= 0)
                            
$value null;
                    }
                }

                if (
$value !== null)
                    
$result[] = $value;
            }
        }

        if (!
$arFieldType["Multiple"])
        {
            if (
count($result) > 0)
                
$result $result[0];
            else
                
$result null;
        }

        return 
$result;
    }