Exemplo n.º 1
0
 echo "<table>";
 while ($item_attribute_type_r = db_fetch_assoc($results)) {
     if (has_role_permission($item_attribute_type_r['view_perm'])) {
         $display_type = trim($item_attribute_type_r['display_type']);
         if ($HTTP_VARS['mode'] == 'printable' && $item_attribute_type_r['printable_ind'] != 'Y' || strlen($display_type) == 0 && $item_attribute_type_r['input_type'] == 'hidden') {
             // We allow the get_display_field to handle hidden variable, in case at some stage
             // we might want to change the functionality of 'hidden' to something other than ignore.
             $display_type = 'hidden';
         }
         if ($item_attribute_type_r['s_field_type'] == 'ITEM_ID') {
             $value = $item_r['item_id'];
         } else {
             if ($item_attribute_type_r['s_field_type'] == 'UPDATE_ON') {
                 $value = $item_r['update_on'];
             } else {
                 if (is_multivalue_attribute_type($item_attribute_type_r['s_attribute_type'])) {
                     $value = fetch_attribute_val_r($item_r['item_id'], $item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']);
                 } else {
                     $value = fetch_attribute_val($item_r['item_id'], $item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']);
                 }
             }
         }
         if (is_not_empty_array($value) || !is_array($value) && strlen($value) > 0) {
             $item_attribute_type_r['display_type'] = $display_type;
             $item_attribute_type_r['compulsory_ind'] = 'N';
             $field = get_item_display_field($item_r, $item_attribute_type_r, $value, FALSE);
             if (strlen($field) > 0) {
                 echo format_item_data_field($item_attribute_type_r, $field, $prompt_mask, NULL);
                 // field mask
             }
         }
Exemplo n.º 2
0
function handle_item_attributes($op, $item_r, $HTTP_VARS, &$errors)
{
    // for these operations, no instance_no context is possible
    // item instance attributes will be handled in a separate call to this function, as a updateinstance op
    if ($op == 'insert' || $op == 'update') {
        $item_r['instance_no'] = NULL;
    }
    $attr_results = fetch_item_attribute_type_rs($item_r['s_item_type'], is_numeric($item_r['instance_no']) ? 'instance_attribute_ind' : 'item_attribute_ind', FALSE);
    if ($attr_results) {
        $attributes_updated = 0;
        while ($item_attribute_type_r = db_fetch_assoc($attr_results)) {
            // For all operations the {DURATION,TITLE,STATUSTYPE,STATUSCMNT,ITEM_ID} cannot be
            // updated because they exist at item/item_instance level.
            if ($item_attribute_type_r['s_field_type'] != 'DURATION' && $item_attribute_type_r['s_field_type'] != 'TITLE' && $item_attribute_type_r['s_field_type'] != 'STATUSTYPE' && $item_attribute_type_r['s_field_type'] != 'STATUSCMNT' && $item_attribute_type_r['s_field_type'] != 'ITEM_ID') {
                $fieldname = get_field_name($item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']);
                // save it in case we are in refresh mode.
                $orig_fieldname = $fieldname;
                if (!is_array($HTTP_VARS[$fieldname])) {
                    if (preg_match("/new([0-9]+)/", $HTTP_VARS[$fieldname], $matches) && isset($HTTP_VARS[$fieldname . '_' . $matches[0]])) {
                        $fieldname = $fieldname . '_' . $matches[0];
                    } else {
                        if ($HTTP_VARS[$fieldname] == 'old') {
                            // make sure this is a refresh value and not just a field with the value 'old'
                            if (isset($HTTP_VARS[$fieldname . '_new0'])) {
                                $fieldname = $fieldname . '_old';
                            }
                        }
                    }
                }
                if (is_multivalue_attribute_type($item_attribute_type_r['s_attribute_type'])) {
                    $value_r = NULL;
                    if (is_array($HTTP_VARS[$fieldname])) {
                        $value_r = $HTTP_VARS[$fieldname];
                    } else {
                        if (isset($HTTP_VARS[$fieldname])) {
                            $value_r[] = $HTTP_VARS[$fieldname];
                        }
                    }
                    if (is_item_attribute_set($item_r['item_id'], $item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'])) {
                        if (update_item_attributes($item_r['item_id'], $item_r['instance_no'], $item_r['s_item_type'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'], $value_r)) {
                            $attributes_updated++;
                        }
                    } else {
                        if (is_not_empty_array($value_r)) {
                            if (insert_item_attributes($item_r['item_id'], $item_r['instance_no'], $item_r['s_item_type'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'], $value_r)) {
                                $attributes_updated++;
                            }
                        }
                    }
                } else {
                    $file_r = NULL;
                    if (is_array($_FILES) && is_array($_FILES[$fieldname . '_upload']) && is_uploaded_file($_FILES[$fieldname . '_upload']['tmp_name'])) {
                        $value = basename($_FILES[$fieldname . '_upload']['name']);
                        $file_r = $_FILES[$fieldname . '_upload'];
                    } else {
                        // normal field
                        $value = $HTTP_VARS[$fieldname];
                    }
                    // If attribute value found - an existing attribute, so do an update.
                    if (is_item_attribute_set($item_r['item_id'], $item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'])) {
                        if (update_item_attributes($item_r['item_id'], $item_r['instance_no'], $item_r['s_item_type'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'], $value, $file_r)) {
                            $attributes_updated++;
                        }
                    } else {
                        if (strlen($value) > 0) {
                            if (insert_item_attributes($item_r['item_id'], $item_r['instance_no'], $item_r['s_item_type'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'], $value, $file_r)) {
                                $attributes_updated++;
                            }
                        }
                    }
                }
            }
        }
        //while
        db_free_result($attr_results);
        // Indicate how many attributes updated.
        return $attributes_updated;
    } else {
        return FALSE;
    }
}
Exemplo n.º 3
0
function get_edit_item_form($op, $item_r, $HTTP_VARS, &$upload_file_fields)
{
    // is at least one field a compulsory field?
    $compulsory_fields = FALSE;
    $upload_file_fields = FALSE;
    $results = fetch_item_attribute_type_rs($item_r['s_item_type'], 'not_instance_field_types');
    if ($results) {
        $formContents .= "\n<table>";
        while ($item_attribute_type_r = db_fetch_assoc($results)) {
            if ($item_attribute_type_r['s_field_type'] == 'ITEM_ID') {
                continue;
            }
            // need to provide a proper encoded form if upload encountered, assume upload where file attribute encountered
            if ($item_attribute_type_r['file_attribute_ind'] == 'Y') {
                $upload_file_fields = TRUE;
            }
            if ($op == 'refresh' || $op == 'edit' || $op == 'newinstance') {
                if (is_multivalue_attribute_type($item_attribute_type_r['s_attribute_type'])) {
                    $item_attribute_type_r['attribute_val'] = fetch_attribute_val_r($item_r['item_id'], $item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']);
                } else {
                    $item_attribute_type_r['attribute_val'] = fetch_attribute_val($item_r['item_id'], $item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']);
                }
            }
            if ($op == 'refresh') {
                $old_value = get_old_field_value($item_r, $item_attribute_type_r['s_field_type'], $item_attribute_type_r['attribute_val']);
                $new_value = get_field_value($op, $item_r, $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'], $item_attribute_type_r['s_field_type'], $item_attribute_type_r['attribute_val'], $HTTP_VARS);
                // this represents multiple selections for a single value, lookup / multi value attributes will
                // be dealt with together.
                if (is_not_empty_array($new_value) && !is_multivalue_attribute_type($item_attribute_type_r['s_attribute_type'])) {
                    foreach ($new_value as $key => $val) {
                        $new_value[$key] = filter_item_input_field($item_attribute_type_r, $val);
                    }
                } else {
                    $new_value = filter_item_input_field($item_attribute_type_r, $new_value);
                    // If no HTTP value, especially where FILE UPLOAD is being concerned, attempt to get from database again.
                    if (($op == 'edit' || $op == 'newinstance') && $new_value === NULL) {
                        $new_value = get_old_field_value($item_r, $item_attribute_type_r['s_field_type'], $item_attribute_type_r['attribute_val']);
                    }
                }
            } else {
                //if($op == 'refresh')
                $old_value = FALSE;
                $new_value = get_field_value($op, $item_r, $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'], $item_attribute_type_r['s_field_type'], $item_attribute_type_r['attribute_val'], $HTTP_VARS);
                if (is_not_empty_array($new_value) && !is_multivalue_attribute_type($item_attribute_type_r['s_attribute_type'])) {
                    foreach ($new_value as $key => $val) {
                        $new_value[$key] = filter_item_input_field($item_attribute_type_r, $val);
                    }
                } else {
                    $new_value = filter_item_input_field($item_attribute_type_r, $new_value);
                    // If no HTTP value, especially where FILE UPLOAD is being concerned, attempt to get from database again.
                    if (($op == 'edit' || $op == 'newinstance') && $new_value === NULL) {
                        $new_value = get_old_field_value($item_r, $item_attribute_type_r['s_field_type'], $item_attribute_type_r['attribute_val']);
                    }
                }
            }
            // Enforce compulsory indicator for TITLE.
            if ($item_attribute_type_r['s_field_type'] == 'TITLE') {
                $item_attribute_type_r['compulsory_ind'] = 'Y';
                $override_title_articles_r = get_opendb_config_var('item_input', 'title_articles');
                if (is_not_empty_array($override_title_articles_r)) {
                    if (is_not_empty_array($new_value)) {
                        foreach ($new_value as $key => $val) {
                            $new_value[$key] = trim(format_title_grammar_article($val, $override_title_articles_r));
                        }
                    } else {
                        $new_value = trim(format_title_grammar_article($new_value, $override_title_articles_r));
                    }
                }
            }
            $formContents .= get_item_form_row($op, $item_r, $item_attribute_type_r, $old_value, $new_value);
            if ($item_attribute_type_r['compulsory_ind'] == 'Y') {
                $compulsory_fields = TRUE;
            }
        }
        //while
        db_free_result($results);
        $formContents .= "\n</table>";
        $help_block_r = NULL;
        if ($op == 'refresh') {
            $help_block_r[] = array('img' => 'rs.gif', 'text' => get_opendb_lang_var('refreshed'));
        }
        $help_block_r[] = array('img' => 'compulsory.gif', 'text' => get_opendb_lang_var('compulsory_field'), id => 'compulsory');
        $formContents .= format_help_block($help_block_r);
        return $formContents;
    } else {
        return FALSE;
    }
}