CBPHelper :: GetFieldInputControl: Bitrix method

      
<?php 
//  CBPHelper :: GetFieldInputControl()
//  /dist/bitrix/modules/bizproc/classes/general/helper.php:1212

    
public static function GetFieldInputControl($documentType$arFieldType$arFieldName$fieldValue$bAllowSelection false)
    {
        if (!
is_array($fieldValue) || is_array($fieldValue) && CBPHelper::IsAssociativeArray($fieldValue))
        {
            
$fieldValue = array($fieldValue);
        }

        
ob_start();

        if (
$arFieldType["Type"] == "select")
        {
            
$fieldValueTmp $fieldValue;
            
?>
            <select id="id_<?= $arFieldName["Field"?>" name="<?= $arFieldName["Field"].($arFieldType["Multiple"] ? "[]" ""?>"<?= ($arFieldType["Multiple"] ? ' size="5" multiple' ''?>>
                <?
                
if (!$arFieldType["Required"])
                    echo 
'<option value="">['.GetMessage("BPCGHLP_NOT_SET").']</option>';
                foreach (
$arFieldType["Options"] as $k => $v)
                {
                    
$ind array_search($k$fieldValueTmp);
                    echo 
'<option value="'.htmlspecialcharsbx($k).'"'.($ind !== false ' selected' '').'>'.htmlspecialcharsbx($v).'</option>';
                    if (
$ind !== false)
                        unset(
$fieldValueTmp[$ind]);
                }
                
?>
            </select>
            <?
            
if ($bAllowSelection)
            {
                
?>
                <br /><input type="text" id="id_<?= $arFieldName["Field"?>_text" name="<?= $arFieldName["Field"?>_text" value="<?
                
if (count($fieldValueTmp) > 0)
                {
                    
$a array_values($fieldValueTmp);
                    echo 
htmlspecialcharsbx($a[0]);
                }
                
?>"><?
                
echo CBPHelper::renderControlSelectorButton('id_'.$arFieldName["Field"].'_text''select');
            }
        }
        elseif (
$arFieldType["Type"] == "user")
        {
            
$fieldValue CBPHelper::UsersArrayToString($fieldValuenull$documentType);
            
?><input type="text" size="40" id="id_<?= $arFieldName["Field"?>" name="<?= $arFieldName["Field"?>" value="<?= htmlspecialcharsbx($fieldValue?>"><? echo CBPHelper::renderControlSelectorButton('id_'.$arFieldName["Field"], 'user');
        }
        else
        {
            if (!
array_key_exists("CBPVirtualDocumentCloneRowPrinted"$GLOBALS) && $arFieldType["Multiple"])
            {
                
$GLOBALS["CBPVirtualDocumentCloneRowPrinted"] = 1;
                
?>
                <script language="JavaScript">
                <!--
                function CBPVirtualDocumentCloneRow(tableID)
                {
                    var tbl = document.getElementById(tableID);
                    var cnt = tbl.rows.length;
                    var oRow = tbl.insertRow(cnt);
                    var oCell = oRow.insertCell(0);
                    var sHTML = tbl.rows[cnt - 1].cells[0].innerHTML;
                    var p = 0;
                    while (true)
                    {
                        var s = sHTML.indexOf('[n', p);
                        if (s < 0)
                            break;
                        var e = sHTML.indexOf(']', s);
                        if (e < 0)
                            break;
                        var n = parseInt(sHTML.substr(s + 2, e - s));
                        sHTML = sHTML.substr(0, s) + '[n' + (++n) + ']' + sHTML.substr(e + 1);
                        p = s + 1;
                    }
                    var p = 0;
                    while (true)
                    {
                        var s = sHTML.indexOf('__n', p);
                        if (s < 0)
                            break;
                        var e = sHTML.indexOf('_', s + 2);
                        if (e < 0)
                            break;
                        var n = parseInt(sHTML.substr(s + 3, e - s));
                        sHTML = sHTML.substr(0, s) + '__n' + (++n) + '_' + sHTML.substr(e + 1);
                        p = e + 1;
                    }
                    oCell.innerHTML = sHTML;
                    var patt = new RegExp('<' + 'script' + '>[^\000]*?<' + '\/' + 'script' + '>', 'ig');
                    var code = sHTML.match(patt);
                    if (code)
                    {
                        for (var i = 0; i < code.length; i++)
                        {
                            if (code[i] != '')
                            {
                                var s = code[i].substring(8, code[i].length - 9);
                                jsUtils.EvalGlobal(s);
                            }
                        }
                    }
                }
                //-->
                </script>
                <?
            
}

            if (
$arFieldType["Multiple"])
                echo 
'<table width="100%" border="0" cellpadding="2" cellspacing="2" id="CBPVirtualDocument_'.$arFieldName["Field"].'_Table">';

            if (
$bAllowSelection)
            {
                
$arFieldType["BaseType"] = "string";

                static 
$arDocumentTypes null;
                if (
is_null($arDocumentTypes))
                    
$arDocumentTypes self::GetDocumentFieldTypes($documentType);

                if (
array_key_exists($arFieldType["Type"], $arDocumentTypes))
                    
$arFieldType["BaseType"] = $arDocumentTypes[$arFieldType["Type"]]["BaseType"];
            }

            
$fieldValueTmp $fieldValue;

            
$ind = -1;
            foreach (
$fieldValue as $key => $value)
            {
                
$ind++;
                
$fieldNameId 'id_'.$arFieldName["Field"].'__n'.$ind.'_';
                
$fieldNameName $arFieldName["Field"].($arFieldType["Multiple"] ? "[n".$ind."]" "");

                if (
$arFieldType["Multiple"])
                    echo 
'<tr><td>';

                switch (
$arFieldType["Type"])
                {
                    case 
"int":
                    case 
"double":
                        unset(
$fieldValueTmp[$key]);
                        
?><input type="text" size="10" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>" value="<?= htmlspecialcharsbx($value?>"><?
                        
break;
                    case 
"file":
                        unset(
$fieldValueTmp[$key]);
                        
?><input type="file" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>"><?
                        
break;
                    case 
"bool":
                        if (
in_array($value, array("Y""N")))
                            unset(
$fieldValueTmp[$key]);
                        
?>
                        <select id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>">
                            <?
                            
if (!$arFieldType["Required"])
                                echo 
'<option value="">['.GetMessage("BPCGHLP_NOT_SET").']</option>';
                            
?>
                            <option value="Y"<?= (in_array("Y"$fieldValue) ? ' selected' ''?>><?= GetMessage("BPCGHLP_YES"?></option>
                            <option value="N"<?= (in_array("N"$fieldValue) ? ' selected' ''?>><?= GetMessage("BPCGHLP_NO"?></option>
                        </select>
                        <?
                        
break;
                    case 
"text":
                        unset(
$fieldValueTmp[$key]);
                        
?><textarea rows="5" cols="40" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>"><?= htmlspecialcharsbx($value?></textarea><?
                        
break;
                    case 
"date":
                    case 
"datetime":
                        
$v "";
                        if (!
CBPActivity::isExpression($value))
                        {
                            
$v $value;
                            unset(
$fieldValueTmp[$key]);
                        }
                        echo 
CAdminCalendar::CalendarDate($fieldNameName$v19, ($arFieldType["Type"] == "date"));
                        break;
                    default:
                        unset(
$fieldValueTmp[$key]);
                        
?><input type="text" size="40" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>" value="<?= htmlspecialcharsbx($value?>"><?
                
}

                if (
$bAllowSelection)
                {
                    if (!
in_array($arFieldType["Type"], array("file""bool""date""datetime")))
                    {
                        echo 
CBPHelper::renderControlSelectorButton($fieldNameId$arFieldType["BaseType"]);
                    }
                }

                if (
$arFieldType["Multiple"])
                    echo 
'</td></tr>';
            }

            if (
$arFieldType["Multiple"])
                echo 
"</table>";

            if (
$arFieldType["Multiple"])
                echo 
'<input type="button" value="'.GetMessage("BPCGHLP_ADD").'" onclick="CBPVirtualDocumentCloneRow(\'CBPVirtualDocument_'.$arFieldName["Field"].'_Table\')"/><br />';

            if (
$bAllowSelection)
            {
                if (
in_array($arFieldType["Type"], array("file""bool""date""datetime")))
                {
                    
?>
                    <input type="text" id="id_<?= $arFieldName["Field"?>_text" name="<?= $arFieldName["Field"?>_text" value="<?
                    
if (count($fieldValueTmp) > 0)
                    {
                        
$a array_values($fieldValueTmp);
                        echo 
htmlspecialcharsbx($a[0]);
                    }
                    
?>"><?
                    
echo CBPHelper::renderControlSelectorButton('id_'.$arFieldName["Field"].'_text'$arFieldType["BaseType"]);
                }
            }
        }

        
$s ob_get_contents();
        
ob_end_clean();

        return 
$s;
    }