diff options
Diffstat (limited to 'frontends/php/include/items.inc.php')
| -rw-r--r-- | frontends/php/include/items.inc.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index 3eea2f4b..f44fa2cf 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -1111,4 +1111,72 @@ COpt::profiling_stop('prepare table'); } return $lastvalue; } + + /* + * Function: item_get_history + * + * Description: + * Get value from history + * + * Peremeters: + * itemid - item ID + * index - 0 - last value, 1 - prev value, 2 - prev prev, and so on + * if index=0, clock is used + * + * Author: + * Alexei Vladishev + * + * Comments: + * + */ + function item_get_history($db_item,$index = 1, $clock = 0) + { + $value = NULL; + + switch($db_item["value_type"]) + { + case ITEM_VALUE_TYPE_FLOAT: + $table = "history"; + break; + case ITEM_VALUE_TYPE_UINT64: + $table = "history_uint"; + break; + case ITEM_VALUE_TYPE_TEXT: + $table = "history_text"; + break; + case ITEM_VALUE_TYPE_STR: + $table = "history_str"; + break; + case ITEM_VALUE_TYPE_LOG: + default: + $table = "history_log"; + break; + } + if($index == 0) + { + $sql="select value from $table where itemid=".$db_item["itemid"]." and clock<=$clock order by clock desc"; + $result = DBselect($sql, 1); + $row = DBfetch(DBselect($sql, 1)); + if($row) + { + $value = $row["value"]; + } + } + else + { + $sql="select value from $table where itemid=".$db_item["itemid"]." order by clock desc"; + $result = DBselect($sql, $index); + $num=1; + while($row = DBfetch($result)) + { + if($num == $index) + { + $value = $row["value"]; + break; + } + $num++; + } + } + return $value; + } ?> |
