Files
crm.e5.pl/modules/EcmDocuments/ecmhistory.php

83 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2024-04-27 09:23:34 +02:00
<?
function create_guid1()
{
$microTime = microtime();
list($a_dec, $a_sec) = explode(" ", $microTime);
$dec_hex = sprintf("%x", $a_dec* 1000000);
$sec_hex = sprintf("%x", $a_sec);
ensure_length1($dec_hex, 5);
ensure_length1($sec_hex, 6);
$guid = "";
$guid .= $dec_hex;
$guid .= create_guid_section1(3);
$guid .= '-';
$guid .= create_guid_section1(4);
$guid .= '-';
$guid .= create_guid_section1(4);
$guid .= '-';
$guid .= create_guid_section1(4);
$guid .= '-';
$guid .= $sec_hex;
$guid .= create_guid_section1(6);
return $guid;
}
function create_guid_section1($characters)
{
$return = "";
for($i=0; $i<$characters; $i++)
{
$return .= sprintf("%x", mt_rand(0,15));
}
return $return;
}
function ensure_length1(&$string, $length)
{
$strlen = strlen($string);
if($strlen < $length)
{
$string = str_pad($string,$length,"0");
}
else if($strlen > $length)
{
$string = substr($string, 0, $length);
}
}
function add_to_history($table,$id,$field,$value)
{
error_reporting(0);
$z="select id from ecmhistory where field_name='".$field."' and field_value='".$value."' and table_id='".$id."' and table_name='".$table."' order by date_modified desc limit 1";
$w=mysql_query($z);
$r=mysql_fetch_array($w);
$fn=$r['field_value'];
if($fn!=$field)
{
if($value)mysql_query("insert into ecmhistory(id,table_name,table_id,field_name,field_value,date_modified) values('".create_guid1()."','".$table."','".$id."','".$field."','".$value."','".date("Y-m-d H:i:s")."')");
}
}
function display_history($table,$id,$field)
{
$html="";
$z="select field_value,date_modified from ecmhistory where table_name='".$table."' and table_id='".$id."' and field_name='".$field."' order by date_modified asc";
$w=mysql_query($z);
while($r=mysql_fetch_array($w))
{
if($field=="assigned_user_id")
{
$rr=mysql_fetch_array(mysql_query("select user_name from users where id='".$r['field_value']."' and status='Active'"));
$f=$rr['user_name'];
}
else $f=$r['field_value'];
if($f)$html.="<div style='height:15px;'>".$r['date_modified']." - ".$f."<br></div>";
}
return $html;
}
?>