CBPVirtualDocument :: GetFieldInputControlOptions: Bitrix method

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

    
function GetFieldInputControlOptions($documentType, &$arFieldType$jsFunctionName, &$value)
    {
        
$result "";

        static 
$arDocumentFieldTypes = array();
        if (!
array_key_exists($documentType$arDocumentFieldTypes))
        {
            
$arDocumentFieldTypes[$documentType] = self::GetDocumentFieldTypes($documentType);
        }

        if (!
array_key_exists($arFieldType["Type"], $arDocumentFieldTypes[$documentType])
            || !
$arDocumentFieldTypes[$documentType][$arFieldType["Type"]]["Complex"])
        {
            return 
"";
        }

        if (
$arFieldType["Type"] == "E:EList")
        {
            if (
is_array($value))
            {
                
reset($value);
                
$valueTmp intval(current($value));
            }
            else
            {
                
$valueTmp intval($value);
            }

            
$iblockId 0;
            if (
$valueTmp 0)
            {
                
$dbResult CIBlockElement::GetList(array(), array("ID" => $valueTmp), falsefalse, array("ID""IBLOCK_ID"));
                if (
$arResult $dbResult->Fetch())
                    
$iblockId $arResult["IBLOCK_ID"];
            }
            if (
$iblockId <= && intval($arFieldType["Options"]) > 0)
                
$iblockId intval($arFieldType["Options"]);

            
$defaultIBlockId 0;

            
$result .= '<select onchange="'.htmlspecialcharsbx($jsFunctionName).'(this.options[this.selectedIndex].value)">';
            
$arIBlockType CIBlockParameters::GetIBlockTypes();
            foreach (
$arIBlockType as $iblockTypeId => $iblockTypeName)
            {
                
$result .= '<optgroup label="'.$iblockTypeName.'">';

                
$dbIBlock CIBlock::GetList(array("SORT" => "ASC"), array("TYPE" => $iblockTypeId"ACTIVE" => "Y"));
                while (
$arIBlock $dbIBlock->GetNext())
                {
                    
$result .= '<option value="'.$arIBlock["ID"].'"'.(($arIBlock["ID"] == $iblockId) ? " selected" "").'>'.$arIBlock["NAME"].'</option>';
                    if ((
$defaultIBlockId <= 0) || ($arIBlock["ID"] == $iblockId))
                        
$defaultIBlockId $arIBlock["ID"];
                }

                
$result .= '</optgroup>';
            }
            
$result .= '</select><!--__defaultOptionsValue:'.$defaultIBlockId.'--><!--__modifyOptionsPromt:'.GetMessage("IBD_DOCUMENT_MOPROMT").'-->';

            
$arFieldType["Options"] = $defaultIBlockId;
        }
        elseif (
$arFieldType["Type"] == "L")
        {
            
$valueTmp $arFieldType["Options"];
            if (!
is_array($valueTmp))
                
$valueTmp = array($valueTmp => $valueTmp);

            
$str '';
            foreach (
$valueTmp as $k => $v)
            {
                if (
is_array($v) && count($v) == 2)
                {
                    
$v1 array_values($v);
                    
$k $v1[0];
                    
$v $v1[1];
                }

                if (
$k != $v)
                    
$str .= '['.$k.']'.$v;
                else
                    
$str .= $v;

                
$str .= "\n";
            }
            
$result .= '<textarea id="WFSFormOptionsX" rows="5" cols="30">'.htmlspecialcharsbx($str).'</textarea><br />';
            
$result .= GetMessage("IBD_DOCUMENT_XFORMOPTIONS1").'<br />';
            
$result .= GetMessage("IBD_DOCUMENT_XFORMOPTIONS2").'<br />';
            
$result .= '<script type="text/javascript">
                function WFSFormOptionsXFunction()
                {
                    var result = {};
                    var i, id, val, str = document.getElementById("WFSFormOptionsX").value;

                    var arr = str.split(/[\r\n]+/);
                    var p, re = /\[([^\]]+)\].+/;
                    for (i in arr)
                    {
                        str = arr[i].replace(/^\s+|\s+$/g, \'\');
                        if (str.length > 0)
                        {
                            id = str.match(re);
                            if (id)
                            {
                                p = str.indexOf(\']\');
                                id = id[1];
                                val = str.substr(p + 1);
                            }
                            else
                            {
                                val = str;
                                id = val;
                            }
                            result[id] = val;
                        }
                    }

                    return result;
                }
                </script>'
;
            
$result .= '<input type="button" onclick="'.htmlspecialcharsbx($jsFunctionName).'(WFSFormOptionsXFunction())" value="'.GetMessage("IBD_DOCUMENT_XFORMOPTIONS3").'">';
        }

        return 
$result;
    }