102 lines
2.4 KiB
PHP
Executable File
102 lines
2.4 KiB
PHP
Executable File
<?
|
|
error_reporting(E_ALL);
|
|
$sql=mysql_connect("localhost","root","");
|
|
mysql_select_db("sugar45");
|
|
function create_guid()
|
|
{
|
|
$microTime = microtime();
|
|
list($a_dec, $a_sec) = explode(" ", $microTime);
|
|
|
|
$dec_hex = sprintf("%x", $a_dec* 1000000);
|
|
$sec_hex = sprintf("%x", $a_sec);
|
|
|
|
ensure_length($dec_hex, 5);
|
|
ensure_length($sec_hex, 6);
|
|
|
|
$guid = "";
|
|
$guid .= $dec_hex;
|
|
$guid .= create_guid_section(3);
|
|
$guid .= '-';
|
|
$guid .= create_guid_section(4);
|
|
$guid .= '-';
|
|
$guid .= create_guid_section(4);
|
|
$guid .= '-';
|
|
$guid .= create_guid_section(4);
|
|
$guid .= '-';
|
|
$guid .= $sec_hex;
|
|
$guid .= create_guid_section(6);
|
|
|
|
return $guid;
|
|
|
|
}
|
|
|
|
function create_guid_section($characters)
|
|
{
|
|
$return = "";
|
|
for($i=0; $i<$characters; $i++)
|
|
{
|
|
$return .= sprintf("%x", mt_rand(0,15));
|
|
}
|
|
return $return;
|
|
}
|
|
|
|
function ensure_length(&$string, $length)
|
|
{
|
|
$strlen = strlen($string);
|
|
if($strlen < $length)
|
|
{
|
|
$string = str_pad($string,$length,"0");
|
|
}
|
|
else if($strlen > $length)
|
|
{
|
|
$string = substr($string, 0, $length);
|
|
}
|
|
}
|
|
|
|
function build_tree($katalog,$id)
|
|
{
|
|
if($dir=opendir($katalog))
|
|
{
|
|
while($file=readdir($dir))
|
|
{
|
|
|
|
if($file!="." && $file!="..")
|
|
{
|
|
$name=explode(".",$file);
|
|
$no=$name[0];
|
|
$nn="";
|
|
for($i=1;$i<=count($name)-1;$i++)
|
|
{
|
|
if($i>1)$nn.=".";
|
|
$nn.=$name[$i];
|
|
}
|
|
$guid=create_guid();
|
|
print "id: ".$guid.", iddir: ".$id." = ";
|
|
$z="insert into ecmdocuments(id,date_entered,date_modified,assigned_user_id,modified_user_id,iddir,name,isdir,no,deleted) values('".$guid."','".date("Y-m-d H:m:s")."','".date("Y-m-d H:m:s")."',1,1,'".$id."','".$nn."','1','".$no."','0')";
|
|
if(is_dir($katalog."/".$file))
|
|
if(mysql_query($z))print "ok<br>";
|
|
else print "no<br>";
|
|
$katalogtemp=$katalog;
|
|
$katalog.="/".$file;
|
|
if(is_dir($katalog))build_tree($katalog,$guid);
|
|
$katalog=$katalogtemp;
|
|
}
|
|
}
|
|
closedir($dir);
|
|
}
|
|
}
|
|
function build_dirs_strukture($katalog,$id)
|
|
{
|
|
$z="select * from ecmdocuments where iddir='".$id."'";
|
|
$w=mysql_query($z);
|
|
while($r=mysql_fetch_array($w))
|
|
{
|
|
mkdir($katalog."/".$r['no'].".".$r['name'],7777);
|
|
build_dirs_strukture($katalog."/".$r['no'].".".$r['name'],$r['id']);
|
|
}
|
|
}
|
|
mysql_query("truncate table ecmdocuments");
|
|
if($_GET['mode']=="build_dirs")build_dirs_strukture("d:/users/sugar45/modules/EcmDocuments/root",0);
|
|
if($_GET['mode']=="build_data")build_tree("d:/users/sugar45/modules/EcmDocuments/root/",0);
|
|
mysql_close($sql);
|
|
?>
|