/**
 * Retrieve the html for a block of attributes.
 * @param array $attributes Array of attributes as returned from a call to data_entry_helper::getAttributes.
 * @param array $args Form argument array.
 * @param array $ctrlOptions Array of default options to apply to every attribute control.
 * @param array $outerFilter Name of the outer block to get controls for. Leave null for all outer blocks.
 * @param array $attrSpecificOptions Associative array of control names that have non-default options. Each entry
 * is keyed by the control name and has an array of the options and values to override.
 * @param array $idPrefix Optional prefix to give to IDs (e.g. for fieldsets) to allow you to ensure they remain unique.
 */
function get_attribute_html(&$attributes, $args, $ctrlOptions, $outerFilter = null, $attrSpecificOptions = null, $idPrefix = '', $helperClass = 'data_entry_helper')
{
    $lastOuterBlock = '';
    $lastInnerBlock = '';
    $r = '';
    foreach ($attributes as &$attribute) {
        if (in_array($attribute['id'], data_entry_helper::$handled_attributes)) {
            $attribute['handled'] = 1;
        }
        // Apply filter to only output 1 block at a time. Also hide controls that have already been handled.
        if (($outerFilter === null || strcasecmp($outerFilter, $attribute['outer_structure_block']) == 0) && !isset($attribute['handled'])) {
            if (empty($outerFilter) && $lastOuterBlock != $attribute['outer_structure_block']) {
                if (!empty($lastInnerBlock)) {
                    $r .= '</fieldset>';
                }
                if (!empty($lastOuterBlock)) {
                    $r .= '</fieldset>';
                }
                if (!empty($attribute['outer_structure_block'])) {
                    $r .= '<fieldset id="' . get_fieldset_id($attribute['outer_structure_block'], $idPrefix) . '"><legend>' . lang::get($attribute['outer_structure_block']) . '</legend>';
                }
                if (!empty($attribute['inner_structure_block'])) {
                    $r .= '<fieldset id="' . get_fieldset_id($attribute['outer_structure_block'], $attribute['inner_structure_block'], $idPrefix) . '"><legend>' . lang::get($attribute['inner_structure_block']) . '</legend>';
                }
            } elseif ($lastInnerBlock != $attribute['inner_structure_block']) {
                if (!empty($lastInnerBlock)) {
                    $r .= '</fieldset>';
                }
                if (!empty($attribute['inner_structure_block'])) {
                    $r .= '<fieldset id="' . get_fieldset_id($lastOuterBlock, $attribute['inner_structure_block'], $idPrefix) . '"><legend>' . lang::get($attribute['inner_structure_block']) . '</legend>';
                }
            }
            $lastInnerBlock = $attribute['inner_structure_block'];
            $lastOuterBlock = $attribute['outer_structure_block'];
            $options = $ctrlOptions + get_attr_validation($attribute, $args);
            // when getting the options, only use the first 2 parts of the fieldname as any further imply an existing record ID so would differ.
            $fieldNameParts = explode(':', $attribute['fieldname']);
            if (preg_match('/[a-z][a-z][a-z]Attr/', $fieldNameParts[count($fieldNameParts) - 2])) {
                $optionFieldName = $fieldNameParts[count($fieldNameParts) - 2] . ':' . $fieldNameParts[count($fieldNameParts) - 1];
            } elseif (preg_match('/[a-za-za-z]Attr/', $fieldNameParts[count($fieldNameParts) - 3])) {
                $optionFieldName = $fieldNameParts[count($fieldNameParts) - 3] . ':' . $fieldNameParts[count($fieldNameParts) - 2];
            } else {
                throw new exception('Option fieldname not found');
            }
            if (isset($attrSpecificOptions[$optionFieldName])) {
                $options = array_merge($options, $attrSpecificOptions[$optionFieldName]);
            }
            $r .= call_user_func($helperClass . '::outputAttribute', $attribute, $options);
            $attribute['handled'] = true;
        }
    }
    if (!empty($lastInnerBlock)) {
        $r .= '</fieldset>';
    }
    if (!empty($lastOuterBlock) && strcasecmp($outerFilter, $lastOuterBlock) !== 0) {
        $r .= '</fieldset>';
    }
    return $r;
}
Esempio n. 2
0
/**
 * List of methods that can be used for a prebuilt form control generation.
 * @package Client
 * @subpackage PrebuiltForms.
 * @param array $attributes
 * @param array $args
 * @param array $defAttrOptions
 * @param array $outerFilter
 * @param array $blockOptions Associative array of control names that have non-default options. Each entry
 * is keyed by the control name and has an array of the options and values to override.
 * @param array $idPrefix Optional prefix to give to IDs (e.g. for fieldsets) to allow you to ensure they remain unique.
 */
function get_attribute_html($attributes, $args, $defAttrOptions, $outerFilter = null, $blockOptions = null, $idPrefix = '')
{
    $lastOuterBlock = '';
    $lastInnerBlock = '';
    $r = '';
    foreach ($attributes as $attribute) {
        // Apply filter to only output 1 block at a time. Also hide controls that have already been handled.
        if (($outerFilter === null || strcasecmp($outerFilter, $attribute['outer_structure_block']) == 0) && !isset($attribute['handled'])) {
            if (empty($outerFilter) && $lastOuterBlock != $attribute['outer_structure_block']) {
                if (!empty($lastInnerBlock)) {
                    $r .= '</fieldset>';
                }
                if (!empty($lastOuterBlock)) {
                    $r .= '</fieldset>';
                }
                if (!empty($attribute['outer_structure_block'])) {
                    $r .= '<fieldset id="' . get_fieldset_id($attribute['outer_structure_block'], $idPrefix) . '"><legend>' . lang::get($attribute['outer_structure_block']) . '</legend>';
                }
                if (!empty($attribute['inner_structure_block'])) {
                    $r .= '<fieldset id="' . get_fieldset_id($attribute['outer_structure_block'], $attribute['inner_structure_block'], $idPrefix) . '"><legend>' . lang::get($attribute['inner_structure_block']) . '</legend>';
                }
            } elseif ($lastInnerBlock != $attribute['inner_structure_block']) {
                if (!empty($lastInnerBlock)) {
                    $r .= '</fieldset>';
                }
                if (!empty($attribute['inner_structure_block'])) {
                    $r .= '<fieldset id="' . get_fieldset_id($lastOuterBlock, $attribute['inner_structure_block'], $idPrefix) . '"><legend>' . lang::get($attribute['inner_structure_block']) . '</legend>';
                }
            }
            $lastInnerBlock = $attribute['inner_structure_block'];
            $lastOuterBlock = $attribute['outer_structure_block'];
            $options = $defAttrOptions + get_attr_validation($attribute, $args);
            if (isset($blockOptions[$attribute['fieldname']])) {
                $options = array_merge($options, $blockOptions[$attribute['fieldname']]);
            }
            $r .= data_entry_helper::outputAttribute($attribute, $options);
            $attribute['handled'] = true;
        }
    }
    if (!empty($lastInnerBlock)) {
        $r .= '</fieldset>';
    }
    if (!empty($lastOuterBlock) && strcasecmp($outerFilter, $lastOuterBlock) !== 0) {
        $r .= '</fieldset>';
    }
    return $r;
}
Esempio n. 3
0
function iform_mnhnl_locationattributes($auth, $args, $tabalias, $options)
{
    $creatorAttr = iform_mnhnl_getAttrID($auth, $args, 'location', 'Creator');
    if ($creatorAttr) {
        data_entry_helper::$javascript .= "\njQuery('[name=locAttr:" . $creatorAttr . "],[name^=locAttr:" . $creatorAttr . ":]').removeClass('wide').attr('readonly','readonly');";
    }
    $attrArgs = array('valuetable' => 'location_attribute_value', 'attrtable' => 'location_attribute', 'key' => 'location_id', 'fieldprefix' => 'locAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']);
    //    if($options['read_only']===true) $attrArgs['read_only']='read_only';
    $tabName = isset($options['tabNameFilter']) && isset($options['tabNameFilter']) != '' ? $options['tabNameFilter'] : '';
    if (array_key_exists('location:id', data_entry_helper::$entity_to_load) && data_entry_helper::$entity_to_load['location:id'] != "") {
        // if we have location Id to load, use it to get attribute values
        $attrArgs['id'] = data_entry_helper::$entity_to_load['location:id'];
    }
    $locationAttributes = data_entry_helper::getAttributes($attrArgs, false);
    $defAttrOptions = array_merge(array('extraParams' => array_merge($auth['read'], array('view' => 'detail')), 'language' => iform_lang_iso_639_2($args['language'])), $options);
    $r = '';
    foreach ($locationAttributes as $attribute) {
        if ($tabName == '' && $attribute['inner_structure_block'] != "Filter" || strcasecmp($tabName, $attribute['inner_structure_block']) == 0) {
            $opt = $defAttrOptions + get_attr_validation($attribute, $args);
            $r .= data_entry_helper::outputAttribute($attribute, $opt);
        }
    }
    return $r;
}
 private function get_sample_attribute_html($attributes, $args, $defAttrOptions, $outerBlockFilter, $innerBlockFilter, $useCaptions = false)
 {
     $r = '';
     if (!isset($attributes)) {
         return $r;
     }
     foreach ($attributes as $attribute) {
         // Apply filter to only output 1 block at a time.
         if (($innerBlockFilter === null || strcasecmp($innerBlockFilter, $attribute['inner_structure_block']) == 0) && ($outerBlockFilter === null || strcasecmp($outerBlockFilter, $attribute['outer_structure_block']) == 0)) {
             $options = $defAttrOptions + get_attr_validation($attribute, $args);
             if (!$useCaptions) {
                 unset($attribute['caption']);
             }
             $r .= '<td ' . (isset($defAttrOptions['cellClass']) ? 'class="' . $defAttrOptions['cellClass'] . '"' : '') . '>' . data_entry_helper::outputAttribute($attribute, $options) . '</td>';
         }
     }
     return $r;
 }
Esempio n. 5
0
 private function bats_get_attribute_html($attributes, $args, $defAttrOptions, $blockFilter = null, $blockOptions = null)
 {
     $r = '';
     foreach ($attributes as $attribute) {
         // Apply filter to only output 1 block at a time. Also hide controls that have already been handled.
         if (($blockFilter === null || strcasecmp($blockFilter, $attribute['inner_structure_block']) == 0) && !isset($attribute['handled'])) {
             $options = $defAttrOptions + get_attr_validation($attribute, $args);
             if (isset($blockOptions[$attribute['fieldname']])) {
                 $options = array_merge($options, $blockOptions[$attribute['fieldname']]);
             }
             $r .= data_entry_helper::outputAttribute($attribute, $options);
             $attribute['handled'] = true;
         }
     }
     return $r;
 }
 protected static function get_control_sampleattributes($auth, $args, $tabAlias, $options)
 {
     $r = '';
     $tab = isset($options['tab']) ? $options['tab'] : null;
     $attrArgs = array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']);
     if (self::$loadedSampleId) {
         // if we have a single occurrence Id to load, use it to get attribute values
         $attrArgs['id'] = self::$loadedSampleId;
     }
     if (isset($args['sample_method_id']) && !empty($args['sample_method_id'])) {
         $attrArgs['sample_method_id'] = $args['sample_method_id'];
     }
     if (!empty($options['attributeIds'])) {
         $attrArgs['extraParams']['query'] = json_encode(array('in' => array('id' => $options['attributeIds'])));
     }
     $smpAttrs = data_entry_helper::getAttributes($attrArgs, false);
     $ctrlOptions = array('extraParams' => $auth['read']);
     $attrSpecificOptions = array();
     self::parseForAttrSpecificOptions($options, $ctrlOptions, $attrSpecificOptions);
     foreach ($attrSpecificOptions as $attr => $opts) {
         if (isset($attrSpecificOptions[$attr]['default'])) {
             $attrSpecificOptions[$attr]['default'] = apply_user_replacements($attrSpecificOptions[$attr]['default']);
         }
     }
     foreach ($smpAttrs as &$attribute) {
         if (in_array($attribute['id'], data_entry_helper::$handled_attributes)) {
             $attribute['handled'] = 1;
         }
         // Hide controls that have already been handled.
         if (($tab === null || strcasecmp($tab, $attribute['inner_structure_block']) == 0) && !isset($attribute['handled'])) {
             $options = $ctrlOptions + get_attr_validation($attribute, $args);
             // when getting the options, only use the first 2 parts of the fieldname as any further imply an existing record ID so would differ.
             $fieldNameParts = explode(':', $attribute['fieldname']);
             if (preg_match('/[a-z][a-z][a-z]Attr/', $fieldNameParts[count($fieldNameParts) - 2])) {
                 $optionFieldName = $fieldNameParts[count($fieldNameParts) - 2] . ':' . $fieldNameParts[count($fieldNameParts) - 1];
             } elseif (preg_match('/[a-za-za-z]Attr/', $fieldNameParts[count($fieldNameParts) - 3])) {
                 $optionFieldName = $fieldNameParts[count($fieldNameParts) - 3] . ':' . $fieldNameParts[count($fieldNameParts) - 2];
             } else {
                 throw new exception('Option fieldname not found');
             }
             $dummy = null;
             if (isset($attrSpecificOptions[$optionFieldName])) {
                 $options = array_merge($options, $attrSpecificOptions[$optionFieldName]);
             }
             $r .= data_entry_helper::outputAttribute($attribute, $options);
             $attribute['handled'] = true;
         }
     }
     return $r;
 }