function addAttribute($attribute_type, $order_no, $value)
 {
     if (is_array($value)) {
         for ($i = 0; $i < count($value); $i++) {
             $this->addAttribute($attribute_type, $order_no, $value[$i]);
         }
     } else {
         $value = trim($value);
         if (strlen($value) > 0) {
             if (!is_array($this->_attribute_rs)) {
                 $this->_attribute_rs = array();
             }
             if (isset($this->_attribute_rs[$attribute_type])) {
                 if (!is_array($this->_attribute_rs[$attribute_type])) {
                     // do not add duplicates
                     if ($this->_attribute_rs[$attribute_type] != $value) {
                         $tmpvalue = $this->_attribute_rs[$attribute_type];
                         $this->_attribute_rs[$attribute_type] = array();
                         $this->_attribute_rs[$attribute_type][] = $tmpvalue;
                         // add new value to array
                         $this->_attribute_rs[$attribute_type][] = $value;
                     }
                 } else {
                     // do not add duplicates
                     if (array_search2($value, $this->_attribute_rs[$attribute_type]) === FALSE) {
                         $this->_attribute_rs[$attribute_type][] = $value;
                     }
                 }
             } else {
                 $this->_attribute_rs[$attribute_type] = $value;
             }
         }
     }
 }
示例#2
0
 function addItemAttribute($attribute, $value, $options = NULL, $keyname = NULL)
 {
     // where value is array, recursively call the addItemAttribute function,
     // so rest of function can assume string $value.
     if (is_array($value)) {
         foreach ($value as $key => $val) {
             $this->addItemAttribute($attribute, $val, $options, $key);
         }
     } else {
         // site plugins cannot normally pass any HTML entities or tags through.
         if ($options != HTML_CONTENT_IS_LEGAL) {
             $value = html_entity_decode(strip_tags($value), ENT_COMPAT, get_opendb_config_var('themes', 'charset') == 'utf-8' ? 'UTF-8' : 'ISO-8859-1');
             //thawn: fix utf-8 issues
         }
         // hack: remove hard spaces
         $replace = array(utf8_encode(chr(160)) => ' ');
         //thawn: fixes issue with 3param version of strtr() not being utf-8 compatible.
         $value = strtr($value, $replace);
         $value = trim($value);
         if (strlen($value) > 0) {
             if (!is_array($this->_item_data_r)) {
                 $this->_item_data_r = array();
             }
             if (isset($this->_item_data_r[$attribute])) {
                 if (!is_array($this->_item_data_r[$attribute])) {
                     // do not add duplicates
                     if ($this->_item_data_r[$attribute] != $value) {
                         $tmpvalue = $this->_item_data_r[$attribute];
                         $this->_item_data_r[$attribute] = array();
                         $this->_item_data_r[$attribute][] = $tmpvalue;
                         // add new value to array
                         if (is_numeric($keyname) || is_null($keyname)) {
                             $this->_item_data_r[$attribute][] = $value;
                         } else {
                             $this->_item_data_r[$attribute][$keyname] = $value;
                         }
                     }
                 } else {
                     // do not add duplicates
                     if (array_search2($value, $this->_item_data_r[$attribute]) === FALSE) {
                         if (is_numeric($keyname) || is_null($keyname)) {
                             $this->_item_data_r[$attribute][] = $value;
                         } else {
                             $this->_item_data_r[$attribute][$keyname] = $value;
                         }
                     }
                 }
             } else {
                 // otherwise single value only
                 if (is_numeric($keyname) || is_null($keyname)) {
                     $this->_item_data_r[$attribute] = $value;
                 } else {
                     $this->_item_data_r[$attribute] = array($keyname => $value);
                 }
             }
         }
         //if(strlen($value)>0)
     }
 }
示例#3
0
 /**
  * A simple field mask parser, which only supports 'if' and 'switch' and config_var_key(...)
  * config_var_value(...)
  */
 function _expand_field_mask(&$values_rs, $mask, &$mask_element_rs, $config_var_rs = NULL)
 {
     // If no parsed mask elements, then return $mask.
     if (is_empty_array($mask_element_rs)) {
         // Only return mask if there is something to return.
         if (strlen($mask) > 0) {
             return $mask;
         } else {
             return NULL;
         }
     }
     for ($i = 0; $i < count($mask_element_rs); $i++) {
         // no array set, or simple attribute variable 's_attribute_type.option' not set.
         if (is_not_empty_array($mask_element_rs[$i]) && !isset($mask_element_rs[$i]['s_attribute_type']) && !isset($mask_element_rs[$i]['option'])) {
             // Replace the array index.
             switch ($mask_element_rs[$i]['type']) {
                 case 'ifdef':
                     // ifdef(s_attribute_type, "if_mask"[, "else_mask"])
                     if (isset($values_rs[$mask_element_rs[$i]['varname']])) {
                         $value = $this->_expand_field_mask($values_rs, $mask_element_rs[$i]['if_mask'], $mask_element_rs[$i]['if_mask_elements'], $config_var_rs);
                     } else {
                         if (strlen($mask_element_rs[$i]['else_mask']) > 0) {
                             $value = $this->_expand_field_mask($values_rs, $mask_element_rs[$i]['else_mask'], $mask_element_rs[$i]['else_mask_elements'], $config_var_rs);
                         } else {
                             $value = NULL;
                         }
                     }
                     break;
                 case 'if':
                     // if(varname[<|<=|>=|>|==|!=]value, "if_mask"[, "else_mask"])
                     $value = $values_rs[$mask_element_rs[$i]['varname']];
                     // The attribute is defined, so now lets do the comparison.
                     if (!empty($value)) {
                         if ($this->_test_if_condition($value, $mask_element_rs[$i]['op'], $mask_element_rs[$i]['value'])) {
                             $value = $this->_expand_field_mask($values_rs, $mask_element_rs[$i]['if_mask'], $mask_element_rs[$i]['if_mask_elements'], $config_var_rs);
                         } else {
                             if (strlen($mask_element_rs[$i]['else_mask']) > 0) {
                                 $value = $this->_expand_field_mask($values_rs, $mask_element_rs[$i]['else_mask'], $mask_element_rs[$i]['else_mask_elements'], $config_var_rs);
                             } else {
                                 $value = NULL;
                             }
                         }
                     } else {
                         $value = NULL;
                     }
                     break;
                 case 'switch':
                     $value = $values_rs[$mask_element_rs[$i]['varname']];
                     // The attribute is defined, so now lets do the comparison.
                     if (!empty($value)) {
                         if (is_not_empty_array($mask_element_rs[$i]['cases'])) {
                             for ($j = 0; $j < count($mask_element_rs[$i]['cases']); $j++) {
                                 // if a match.
                                 if (strcmp($value, $mask_element_rs[$i]['cases'][$j]['case']) === 0) {
                                     $value = $this->_expand_field_mask($values_rs, $mask_element_rs[$i]['cases'][$j]['result']['mask'], $mask_element_rs[$i]['cases'][$j]['result']['mask_elements'], $config_var_rs);
                                     break 2;
                                     // break out of switch
                                 }
                             }
                         }
                         if (is_not_empty_array($mask_element_rs[$i]['default_case'])) {
                             $value = $this->_expand_field_mask($values_rs, $mask_element_rs[$i]['default_case']['mask'], $mask_element_rs[$i]['cases']['default_case']['mask_elements'], $config_var_rs);
                         }
                     } else {
                         $value = NULL;
                     }
                     break;
                 case 'config_var_key':
                     // config_var_key(name, value)
                     if (is_not_empty_array($config_var_rs) && is_array($config_var_rs[$mask_element_rs[$i]['name']])) {
                         if (is_array($mask_element_rs[$i]['value'])) {
                             $srchValue = $this->_expand_field_mask($values_rs, $mask_element_rs[$i]['value']['mask'], $mask_element_rs[$i]['value']['elements'], $config_var_rs);
                         } else {
                             $srchValue = $mask_element_rs[$i]['value'];
                         }
                         $tmpValue = array_search2($srchValue, $config_var_rs[$mask_element_rs[$i]['name']]);
                         if ($tmpValue !== FALSE) {
                             $value = $tmpValue;
                         } else {
                             $value = '';
                         }
                     } else {
                         $value = '';
                     }
                     break;
                 case 'config_var_value':
                     // config_var_value(name, keyid)
                     if (is_not_empty_array($config_var_rs) && is_array($config_var_rs[$mask_element_rs[$i]['name']])) {
                         if (is_array($mask_element_rs[$i]['key'])) {
                             $srchKey = $this->_expand_field_mask($values_rs, $mask_element_rs[$i]['key']['mask'], $mask_element_rs[$i]['key']['elements'], $config_var_rs);
                         } else {
                             $srchKey = $mask_element_rs[$i]['key'];
                         }
                         if (isset($config_var_rs[$mask_element_rs[$i]['name']][$srchKey])) {
                             $value = $config_var_rs[$mask_element_rs[$i]['name']][$srchKey];
                         } else {
                             $value = '';
                         }
                     } else {
                         $value = '';
                     }
                     break;
                 default:
                     // No valid function specified, so set to empty.
                     $value = '';
             }
         } else {
             // in the case of this function, all {variables} are not actually s_attribute_type references, but
             // references to key's in the $values_rs array, thus we ignore the 'option' and assume 'value' in
             // every case.
             if (is_array($mask_element_rs[$i]) && isset($mask_element_rs[$i]['s_attribute_type']) && isset($mask_element_rs[$i]['option'])) {
                 $value = ifempty($values_rs[$mask_element_rs[$i]['s_attribute_type']], $values_rs[strtolower($mask_element_rs[$i]['s_attribute_type'])]);
             } else {
                 $value = $values_rs[$mask_element_rs[$i]];
             }
         }
         // Replace the array index.
         $mask = str_replace('{' . $i . '}', $value, $mask);
     }
     // Now return expanded subject.
     return $mask;
 }
示例#4
0
function process_lookup_results($lookup_results, $value)
{
    if (is_array($value) && count($value) > 0) {
        $values_r = $value;
    } else {
        if (!is_array($value) && $value !== NULL) {
            // if a single string value, convert to single element array.
            $values_r[] = $value;
        } else {
            // is_empty_array!
            $values_r = NULL;
        }
    }
    $lookup_rs = fetch_results_array($lookup_results);
    $value_found = FALSE;
    while (list(, $lookup_r) = each($lookup_rs)) {
        if (is_array($values_r) && ($lookup_key = array_search2($lookup_r['value'], $values_r, TRUE)) !== FALSE) {
            $value_found = TRUE;
            break;
        }
    }
    $lookup_val_rs = array();
    reset($lookup_rs);
    while (list(, $lookup_r) = each($lookup_rs)) {
        if ($value_found) {
            $lookup_r['checked_ind'] = 'N';
        }
        if (is_array($values_r) && ($lookup_key = array_search2($lookup_r['value'], $values_r, TRUE)) !== FALSE) {
            $lookup_r['checked_ind'] = 'Y';
            // Remove the matched element
            array_splice($values_r, $lookup_key, 1);
        }
        $lookup_val_rs[] = $lookup_r;
    }
    if (is_array($values_r)) {
        // Add the value to the list of options and select it.
        reset($values_r);
        while (list(, $value) = each($values_r)) {
            if (strlen($value) > 0) {
                $lookup_val_rs[] = array(value => $value, checked_ind => 'Y');
            }
        }
    }
    return $lookup_val_rs;
}
示例#5
0
文件: utils.php 项目: horrabin/opendb
function validate_ind_column($column, $options_r = NULL)
{
    $column = strtoupper($column);
    if (is_array($options_r) && array_search2($column, $options_r) !== FALSE) {
        return $column;
    } else {
        if ($column == 'Y') {
            return 'Y';
        } else {
            return 'N';
        }
    }
}
示例#6
0
文件: index.php 项目: horrabin/opendb
                     }
                 } else {
                     if (!update_s_item_type_group($HTTP_VARS['s_item_type_group'][$i], $HTTP_VARS['description'][$i])) {
                         $errors[] = array('error' => 'Item Type Group not updated', 'detail' => db_error());
                     }
                 }
             }
         }
     }
     $HTTP_VARS['op'] = 'edit_item_type_groups';
 } else {
     if ($HTTP_VARS['op'] == 'update_item_type_group_rltshps') {
         $results = fetch_s_item_type_join_sitgr_rs($HTTP_VARS['s_item_type_group']);
         if ($results) {
             while ($item_type_r = db_fetch_assoc($results)) {
                 $key = array_search2($item_type_r['s_item_type'], $HTTP_VARS['s_item_type']);
                 if ($item_type_r['exists_ind'] == 'Y') {
                     if ($key === FALSE) {
                         // only if no longer checked, should we delete
                         if (!delete_s_item_type_group_rltshp($HTTP_VARS['s_item_type_group'], $item_type_r['s_item_type'])) {
                             $errors[] = array('error' => 'Item Type Group Relationship not deleted', 'detail' => db_error());
                         }
                     }
                 } else {
                     if ($key !== FALSE) {
                         if (!insert_s_item_type_group_rltshp($HTTP_VARS['s_item_type_group'], $HTTP_VARS['s_item_type'][$key])) {
                             $errors[] = array('error' => 'Item Type Group Relationship not inserted', 'detail' => db_error());
                         }
                     }
                 }
             }
示例#7
0
function get_item_display_field($item_r, $item_attribute_type_r, $value = NULL, $dowrap = TRUE, $prompt_mask = NULL)
{
    if ($item_attribute_type_r['display_type'] == 'hidden') {
        return '';
    } else {
        if ($item_attribute_type_r['display_type'] == 'fileviewer') {
            $format_mask = ifempty($item_attribute_type_r['display_type_arg1'], '%value%');
            $width = ifempty($item_attribute_type_r['display_type_arg2'], '400');
            $height = ifempty($item_attribute_type_r['display_type_arg3'], '300');
            $target = ifempty($item_attribute_type_r['display_type_arg4'], '_blank');
            if (is_array($value)) {
                $values = $value;
            } else {
                $values[] = $value;
            }
            if (count($values) > 0) {
                $display_value_r = array();
                while (list(, $value) = each($values)) {
                    $value = trim($value);
                    $value_format_mask = $format_mask;
                    if (strpos($value_format_mask, '%img%') !== FALSE) {
                        $file_type_r = fetch_file_type_r(fetch_file_type_for_extension(get_file_ext($value)));
                        if (strlen($file_type_r['image']) > 0 && ($image_src = theme_image_src($file_type_r['image'])) !== FALSE) {
                            $img = '<img src="' . $image_src . '" title="' . $value . '">';
                        } else {
                            $img = '';
                        }
                        $value_format_mask = str_replace('%img%', $img, $value_format_mask);
                    }
                    if (strpos($value_format_mask, '%value%') !== FALSE) {
                        $value_format_mask = str_replace('%value%', $value, $value_format_mask);
                    }
                    $file_r = file_cache_get_image_r($value, 'display');
                    $url = $file_r['fullsize']['url'];
                    $display_value_r[] = "<a href=\"" . $value . "\" onclick=\"fileviewer('{$url}' ,'" . ($width + 20) . "', '" . ($height + 25) . "', '" . $target . "'); return false;\" title=\"" . $item_attribute_type_r['prompt'] . "\" class=\"popuplink\">{$value_format_mask}</a>";
                }
                $field = format_multivalue_block($display_value_r, 'fileviewer');
                if ($dowrap) {
                    return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask);
                } else {
                    return $field;
                }
            } else {
                return '';
            }
        } else {
            if ($item_attribute_type_r['display_type'] == 'datetime') {
                if (is_array($value)) {
                    $values = $value;
                } else {
                    $values[] = $value;
                }
                if (count($values) > 0) {
                    $display_value_r = array();
                    while (list(, $value) = each($values)) {
                        $value = trim($value);
                        $timestamp = get_timestamp_for_datetime($value, 'YYYYMMDDHH24MISS');
                        if ($timestamp !== FALSE) {
                            if (strlen($item_attribute_type_r['display_type_arg1']) == 0) {
                                $item_attribute_type_r['display_type_arg1'] = 'DD/MM/YYYY';
                            }
                            $datetime = get_localised_timestamp($item_attribute_type_r['display_type_arg1'], $timestamp);
                            if ($datetime !== FALSE) {
                                $display_value_r[] = $datetime;
                            } else {
                                $display_value_r[] = $value;
                            }
                        } else {
                            $display_value_r[] = $value;
                        }
                    }
                    $field = format_multivalue_block($display_value_r, 'datetime');
                    if ($dowrap) {
                        return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask);
                    } else {
                        return $field;
                    }
                } else {
                    return '';
                }
            } else {
                if ($item_attribute_type_r['display_type'] == 'format_mins') {
                    if (is_array($value)) {
                        $values = $value;
                    } else {
                        $values[] = $value;
                    }
                    if (count($values) > 0) {
                        $display_value_r = array();
                        while (list(, $value) = each($values)) {
                            $value = trim($value);
                            if (is_numeric($value)) {
                                // Ensure we have a mask to work with.
                                $display_mask = $item_attribute_type_r['display_type_arg1'];
                                if (strlen($display_mask) == 0) {
                                    $display_mask = '%h %H %m %M';
                                }
                                $hrs = floor($value / 60);
                                // hours
                                $mins = $value % 60;
                                // minutes
                                // Process display_mask and remove any bits that are not needed because the hour/minute is zero.
                                if ($mins == 0 && $hrs > 0) {
                                    // only get rid of minutes if $hrs is a value.
                                    $index = strpos($display_mask, '%H');
                                    if ($index !== FALSE) {
                                        $display_mask = substr($display_mask, 0, $index + 2);
                                    } else {
                                        $index = strpos($display_mask, '%m');
                                        if ($index != FALSE) {
                                            $display_mask = substr($display_mask, 0, $index);
                                        }
                                        //include the %H
                                    }
                                } else {
                                    if ($hrs == 0) {
                                        $index = strpos($display_mask, '%m');
                                        if ($index != FALSE) {
                                            $display_mask = substr($display_mask, $index);
                                        }
                                        //include the %H
                                    }
                                }
                                // Unfortunately we need to do $mins>0 and $hrs>0 if's twice, because otherwise once we
                                // replace the %h and %H the test for $mins>0 would not be able to cut the display_mask,
                                // based on the %h/%H...
                                if ($hrs > 0) {
                                    // Now do all replacements.
                                    $display_mask = str_replace('%h', $hrs, $display_mask);
                                    if ($hrs != 1) {
                                        $display_mask = str_replace('%H', get_opendb_lang_var('hours'), $display_mask);
                                    } else {
                                        $display_mask = str_replace('%H', get_opendb_lang_var('hour'), $display_mask);
                                    }
                                }
                                if ($mins >= 0 || $hrs === 0 && $mins === 0) {
                                    // Now do minute replacements only.
                                    $display_mask = str_replace('%m', $mins, $display_mask);
                                    if ($mins != 1) {
                                        $display_mask = str_replace('%M', get_opendb_lang_var('minutes'), $display_mask);
                                    } else {
                                        $display_mask = str_replace('%M', get_opendb_lang_var('minute'), $display_mask);
                                    }
                                }
                                $display_value_r[] = $display_mask;
                            } else {
                                // what else can we do here?!
                                $display_value_r[] = $value;
                            }
                        }
                        $field = format_multivalue_block($display_value_r, 'format_mins');
                        if ($dowrap) {
                            return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask);
                        } else {
                            return $field;
                        }
                    } else {
                        return '';
                    }
                } else {
                    if ($item_attribute_type_r['display_type'] == 'star_rating') {
                        // arg[0] = rating range
                        if (is_array($value)) {
                            $values = $value;
                        } else {
                            $values[] = $value;
                        }
                        if (count($values) > 0) {
                            $display_value_r = array();
                            while (list(, $value) = each($values)) {
                                $value = trim($value);
                                // no point unless numeric
                                if (is_numeric($value)) {
                                    $total_count = $item_attribute_type_r['display_type_arg1'];
                                    if (is_numeric($total_count)) {
                                        $display_value = '';
                                        $j = $value;
                                        for ($i = 0; $i < $total_count; ++$i) {
                                            if ($j >= 0.75) {
                                                $display_value .= theme_image('rs.gif');
                                            } else {
                                                if ($j >= 0.25) {
                                                    $display_value .= theme_image('rgs.gif');
                                                } else {
                                                    $display_value .= theme_image('gs.gif');
                                                }
                                            }
                                            $j = $j - 1;
                                        }
                                        $ratingmask = $item_attribute_type_r['display_type_arg2'];
                                        if (strlen($ratingmask) > 0) {
                                            $ratingmask = str_replace('%value%', $value, $ratingmask);
                                            $ratingmask = str_replace('%maxrange%', $total_count, $ratingmask);
                                            $display_value = str_replace('%starrating%', $display_value, $ratingmask);
                                        }
                                        if ($item_attribute_type_r['listing_link_ind'] == 'Y') {
                                            $display_value = format_listing_link($value, $display_value, $item_attribute_type_r, NULL);
                                        }
                                    }
                                    $display_value_r[] = $display_value;
                                }
                            }
                            $field = format_multivalue_block($display_value_r, 'starrating');
                            if ($dowrap) {
                                return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask);
                            } else {
                                return $field;
                            }
                        } else {
                            return '';
                            // nothing to do!
                        }
                    } else {
                        if (!is_array($value) && $item_attribute_type_r['display_type'] == 'display' && ifempty($item_attribute_type_r['display_type_arg1'], '%value%') == '%value%') {
                            // Support newline formatting by default.
                            $value = nl2br(trim($value));
                            if ($item_attribute_type_r['listing_link_ind'] == 'Y') {
                                $field = format_listing_links($value, $item_attribute_type_r, 'exact');
                            } else {
                                $field = $value;
                            }
                            if ($dowrap) {
                                return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask);
                            } else {
                                return $field;
                            }
                        } else {
                            if ($item_attribute_type_r['display_type'] == 'list') {
                                //list(list_type [,delimiter])
                                if (is_array($value)) {
                                    $values = $value;
                                    $attr_match = 'exact';
                                } else {
                                    $value = trim($value);
                                    if (strlen($item_attribute_type_r['display_type_arg2']) == 0) {
                                        // Use newline!
                                        $values = explode_lines($value);
                                        $attr_match = 'partial';
                                    } else {
                                        $values = explode($item_attribute_type_r['display_type_arg2'], $value);
                                        if (strlen(trim($item_attribute_type_r['display_type_arg2'])) === 0) {
                                            $attr_match = 'word';
                                        } else {
                                            $attr_match = 'partial';
                                        }
                                    }
                                }
                                $field = format_list_from_array($values, $item_attribute_type_r, $item_attribute_type_r['listing_link_ind'] == 'Y' ? $attr_match : FALSE);
                                if ($dowrap) {
                                    return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask);
                                } else {
                                    return $field;
                                }
                            } else {
                                if ($item_attribute_type_r['display_type'] == 'category' || $item_attribute_type_r['display_type'] == 'display') {
                                    $field = '';
                                    if (is_array($value)) {
                                        $value_array = $value;
                                    } else {
                                        $value_array[] = $value;
                                    }
                                    $attribute_value_rs = array();
                                    if ($item_attribute_type_r['lookup_attribute_ind'] == 'Y') {
                                        $results = fetch_value_match_attribute_type_lookup_rs($item_attribute_type_r['s_attribute_type'], $value_array, get_lookup_order_by($item_attribute_type_r['display_type_arg1']), 'asc');
                                        if ($results) {
                                            while ($lookup_r = db_fetch_assoc($results)) {
                                                $lookup_key = array_search2($lookup_r['value'], $value_array, TRUE);
                                                if ($lookup_key !== FALSE) {
                                                    // Remove the matched element
                                                    array_splice($value_array, $lookup_key, 1);
                                                    $attribute_value_rs[] = array(value => $lookup_r['value'], display => $lookup_r['display'], img => $lookup_r['img']);
                                                }
                                            }
                                            db_free_result($results);
                                        }
                                    }
                                    // where extra items that do not have a matching lookup value.
                                    if (is_not_empty_array($value_array)) {
                                        reset($value_array);
                                        while (list(, $value) = each($value_array)) {
                                            if (strlen(trim($value)) > 0) {
                                                // In case there are extra spaces
                                                $attribute_value_rs[] = array(value => $value, display => $value);
                                            }
                                        }
                                    }
                                    if (is_not_empty_array($attribute_value_rs)) {
                                        $field = format_lookup_display_block($item_attribute_type_r, $attribute_value_rs);
                                        if (strlen($field) > 0) {
                                            if ($dowrap) {
                                                return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask);
                                            } else {
                                                return $field;
                                            }
                                        } else {
                                            return NULL;
                                        }
                                    }
                                } else {
                                    if ($item_attribute_type_r['display_type'] == 'review') {
                                        $total_count = fetch_attribute_type_cnt('S_RATING');
                                        if (is_numeric($total_count)) {
                                            $value = trim($value);
                                            if (!is_numeric($value)) {
                                                $value = 0;
                                            }
                                            $field = '';
                                            $j = $value;
                                            for ($i = 0; $i < $total_count; ++$i) {
                                                if ($j >= 0.75) {
                                                    $field .= theme_image('rs.gif');
                                                } else {
                                                    if ($j >= 0.25) {
                                                        $field .= theme_image('rgs.gif');
                                                    } else {
                                                        $field .= theme_image('gs.gif');
                                                    }
                                                }
                                                $j = $j - 1;
                                            }
                                            // If a mask is defined, format the display value.
                                            if (strlen($item_attribute_type_r['display_type_arg1']) > 0) {
                                                $lookup_r = fetch_attribute_type_lookup_r('S_RATING', $value);
                                                if (is_not_empty_array($lookup_r)) {
                                                    $field .= format_display_value($item_attribute_type_r['display_type_arg1'], $lookup_r['img'], $lookup_r['value'], $lookup_r['display']);
                                                }
                                            }
                                            return $field;
                                            // this is only used in a few places.
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //else -- no display type match.
    if ($dowrap) {
        return format_field($item_attribute_type_r['prompt'], nl2br($value), $prompt_mask);
    } else {
        return nl2br($value);
    }
}
示例#8
0
/**
 * Will test the old against the new value.
 * 
 * Assumes that filter_item_input_field(...) has already
 * been called for new_value.
 */
function is_value_refreshed($s_attribute_type, $new_value, $old_value)
{
    // Do the simplest check first!
    if (!is_array($old_value) && strlen($old_value) == 0 && !is_array($new_value) && strlen($new_value) > 0) {
        return TRUE;
    } else {
        // they should both be arrays at this point.
        if (is_multivalue_attribute_type($s_attribute_type)) {
            if (is_not_empty_array($old_value) && is_not_empty_array($new_value) && count($old_value) == count($new_value)) {
                for ($i = 0; $i < count($old_value); $i++) {
                    // case insensitive search
                    if (array_search2($old_value[$i], $new_value, TRUE) === FALSE) {
                        return TRUE;
                    }
                }
                //else
                return FALSE;
            } else {
                return TRUE;
            }
        } else {
            if (is_array($new_value)) {
                // multi-value option automatically means a refreshed field
                foreach ($new_value as $val) {
                    if (strcmp($val, $old_value) !== 0) {
                        return TRUE;
                    }
                }
                return FALSE;
            }
            if (strcmp($new_value, $old_value) !== 0) {
                return TRUE;
            } else {
                return FALSE;
            }
        }
    }
}