<?php
/*********************/
/* */
/* Version : 5.1.0 */
/* Author : RM */
/* Comment : 071223 */
/* */
/*********************/
//联系人 qq:874689017
include_once( "inc/auth.inc.php" );
include_once( "inc/utility_all.php" );
include_once( "inc/utility_flow.php" );
include_once( "inc/utility_file.php" );
include_once( "inc/mobile_seal/seal_data.php" );
include_once( "../../prcs_role.php" );
include_once( "inc/workflow/inc/common.inc.php" );
include_once( "inc/workflow/inc/workflow.inc.php" );
include_once( "inc/workflow/tform/twork_export.class.php" );
include_once( "inc/workflow/inc/workpriv.inc.php" );
$HTML_PAGE_TITLE = _( "导出" );
include_once( "inc/header.inc.php" );
$archive_time = $_GET['archive_time'];
//HTML=1&RUN_ID=479&FLOW_ID=134&PRCS_ID=&FLOW_PRCS=&archive_time=&FLOW_VIEW=1234
//$RUN_ID=447;
//$FLOW_ID=132;
$FLOW_VIEW="12345";
if ( $archive_time != "" && $archive_time != "undefined" )
{
$use_databases = "td_oa_archive.";
}
else
{
$use_databases = "";
$archive_time = "";
}
$role_str = run_role( $RUN_ID, 0, $archive_time );
$PRIV_TYPE_STR = getflowprivofmanage( $FLOW_ID, $_SESSION['LOGIN_USER_ID'], $_SESSION['LOGIN_DEPT_ID'], $_SESSION['LOGIN_USER_PRIV'], $_SESSION['LOGIN_DEPT_ID_OTHER'], $_SESSION['LOGIN_USER_PRIV_OTHER'] );
setcookie( "FLOW_VIEW_COOKIE", $FLOW_VIEW, time( ) + 259200000 );
$flag_hidden_type = 1;
$table_flow_run_prcs = $use_databases."flow_run_prcs".$archive_time;
if ( $PRCS_ID == NULL || $PRCS_ID == "" )
{
if ( find_id( $role_str, 1 ) || find_id( $role_str, 3 ) || find_id( $role_str, 5 ) || find_id( $role_str, 9 ) || find_id( $role_str, 10 ) || find_id( $role_str, 11 ) )
{
$PRCS_ID = 0;
$flag_hidden_type = 0;
}
else if ( find_id( $role_str, 2 ) || find_id( $role_str, 4 ) || find_id( $role_str, 6 ) )
{
$query = "select prcs_id from ".$table_flow_run_prcs."\r\n where id = (\r\n select MAX(id) from ".$table_flow_run_prcs." where run_id = '".$RUN_ID."'\r\n AND (user_id = '".$_SESSION['LOGIN_USER_ID']."'\r\n or FIND_IN_SET('".$_SESSION['LOGIN_USER_ID']."',OTHER_USER))) ";
$cursor = exequery( TD::conn( ), $query );
if ( $row = mysql_fetch_array( $cursor ) )
{
$PRCS_ID = $row['prcs_id'];
}
$flag_hidden_type = 1;
}
else if ( find_id( $role_str, 8 ) || find_id( $role_str, 7 ) )
{
$PRCS_ID = 0;
$flag_hidden_type = 2;
}
}
if ( find_id( $role_str, 8 ) )
{
$query = "select 1 from APP_LOG where MODULE = '7' and OPP_ID = '".$RUN_ID."' and USER_ID = '".$_SESSION['LOGIN_USER_ID']."'";
$cursor = exequery( TD::conn( ), $query );
if ( !( $row = mysql_fetch_array( $cursor ) ) )
{
$CUR_TIME = date( "Y-m-d H:i:s", time( ) );
$query1 = "insert into APP_LOG(USER_ID,TIME,MODULE,OPP_ID,TYPE) values ('".$_SESSION['LOGIN_USER_ID'].( "','".$CUR_TIME."','7','{$RUN_ID}','1')" );
exequery( TD::conn( ), $query1 );
}
}
if ( $flag_hidden_type == 0 )
{
$secret_fields = "";
}
else if ( $flag_hidden_type == 1 )
{
$query = "select FLOW_PRCS from ".$table_flow_run_prcs." where RUN_ID = '".$RUN_ID."' and PRCS_ID = '".$PRCS_ID."' limit 1";
$cursor = exequery( TD::conn( ), $query );
if ( $row = mysql_fetch_array( $cursor ) )
{
$FLOW_PRCS = $row['FLOW_PRCS'];
}
$table_flow_prcocess = $use_databases."flow_process".$archive_time;
$secret_fields = "";
$query = "select HIDDEN_ITEM from ".$table_flow_prcocess." where FLOW_ID = '".$FLOW_ID."' and PRCS_ID = '".$FLOW_PRCS."' ";
$cursor = exequery( TD::conn( ), $query );
if ( $row = mysql_fetch_array( $cursor ) )
{
$secret_fields = $row['HIDDEN_ITEM'];
}
}
else if ( $flag_hidden_type == 2 )
{
$table_flow_prcocess = $use_databases."flow_process".$archive_time;
$secret_fields = "";
$query = "select HIDDEN_ITEM from ".$table_flow_prcocess." where FLOW_ID = '".$FLOW_ID."' ";
$cursor = exequery( TD::conn( ), $query );
while ( $row = mysql_fetch_array( $cursor ) )
{
$secret_fields .= $row['HIDDEN_ITEM'].",";
}
$secret_fields = td_trim( $secret_fields );
$secret_fields = str_remove_dup( $secret_fields );
}
$archive_time = $_GET['archive_time'];
if ( $archive_time != "" && $archive_time != "undefined" )
{
$use_databases = "td_oa_archive.";
}
else
{
$use_databases = "";
$archive_time = "";
}
$query = "select RUN_NAME from ".$use_databases."flow_run".$archive_time." where RUN_ID = '".$RUN_ID."' ";
$cursor = exequery( TD::conn( ), $query );
while ( $row = mysql_fetch_array( $cursor ) )
{
$RUN_NAME = $row['RUN_NAME'];
}
ob_start( );
echo "<script>\r\n\r\n//定义全局变量\r\nvar g_run_id = \"";
echo $RUN_ID;
echo "\"; //流水号\r\nvar g_flow_id = \"";
echo $FLOW_ID;
echo "\"; //流程ID\r\nvar g_prcs_id = \"";
echo $PRCS_ID;
echo "\"; //实际流程步骤序号\r\nvar g_form_view = 2; //打印表单\r\nvar doPrint = \"";
echo $doPrint;
echo "\";\r\nvar printView = \"";
echo $printView;
echo "\";\r\n</script>\r\n\r\n<body style=\"background:none;margin: 0;\" topmargin=\"5\">\r\n<div id='bodyScroll' >\r\n";
$query = "SELECT DEL_FLAG from ".$use_databases."FLOW_RUN".$archive_time.( " WHERE RUN_ID='".$RUN_ID."'" );
$cursor = exequery( TD::conn( ), $query );
if ( $ROW = mysql_fetch_array( $cursor ) )
{
$DEL_FLAG = $ROW['DEL_FLAG'];
}
if ( $DEL_FLAG == 1 )
{
message( "", _( "此流程已经被删除!" ) );
}
$config = array(
"db" => $use_databases,
"archive_time" => $archive_time,
"secret_fields" => $secret_fields,
"export_type" => "html"
);
$PRINT_FLAG = 1;
$HTML = 1;
$doc_content = "";
if ( strstr( $FLOW_VIEW, "1" ) )
{
echo "<style type=\"text/css\"> ".$CSS."</style>";
echo "<form name=\"form1\" method=\"post\" action=\"\">";
$obj_work_export = new TWorkExport( $FLOW_ID, $RUN_ID, $PRCS_ID, $FLOW_PRCS, $config );
echo $obj_work_export->get_form_html( );
echo "</form>";
$arr_files = $obj_work_export->get_form_files( );
$arr_files_count = count( $arr_files );
$arr_files_count /= 2;
$arr_files = array_slice( $arr_files, $arr_files_count );
}
if ( strstr( $FLOW_VIEW, "2" ) )
{
echo "<br>";
include_once( "../../list/public_attach.php" );
}
if ( strstr( $FLOW_VIEW, "3" ) )
{
echo "<br>";
include_once( "../../list/personal_sign.php" );
}
if ( strstr( $FLOW_VIEW, "4" ) )
{
echo "<br>";
include_once( "../../list/flow_view/view_list.php" );
}
if ( strstr( $FLOW_VIEW, "5" ) )
{
echo "<br>";
include_once( "../../list/flow_view/view_user.php" );
}
$doc_content = ob_get_contents( );
ob_end_clean( );
$RUN_NAME = str_replace( ":", "_", $RUN_NAME );
$RUN_NAME = str_replace( "\"", "", $RUN_NAME );
$RUN_NAME = str_replace( "<", "", $RUN_NAME );
$RUN_NAME = str_replace( ">", "", $RUN_NAME );
$RUN_NAME = str_replace( "|", "", $RUN_NAME );
$RUN_NAME = str_replace( "*", "", $RUN_NAME );
$RUN_NAME = str_replace( "?", "", $RUN_NAME );
$RUN_NAME = str_replace( "/", "", $RUN_NAME );
$RUN_NAME = str_replace( "\\", "", $RUN_NAME );
echo "<html><head>";
echo "<title>".$RUN_NAME."</title>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=".MYOA_CHARSET."\">";
echo "</head>";
echo $doc_content;
ob_end_clean();
/************************************************************************/
//创建目录
//$powneronfile="../../../../powneronfile";
$powneronfile="D:/MYOA/webroot/powneronfile";
if (!file_exists($powneronfile)){
mkdir($powneronfile); //如果没有的话创建webroot下的powneronfile
}
$mulu=$powneronfile."/".$RUN_ID.""; //powneronfile下按流水号创建文件夹
if (!file_exists($mulu)){
mkdir($mulu);
}
/************************************************************************/
$run_name = "";
$run_time = "";
$query = "SELECT * from flow_data_".$FLOW_ID." where run_id = '".$RUN_ID."' limit 1";
$cursor = exequery( TD::conn(), $query );
if( $ROW = mysql_fetch_array( $cursor ) )
{
$run_name = $ROW["run_name"];
$run_time = $ROW["begin_time"];
$begin_user = $ROW["begin_user"];
}
$query7="select BYNAME from user where USER_ID='$begin_user' limit 1";
$cursor7=exequery(TD::conn(),$query7);
while($row7=mysql_fetch_array($cursor7)){
$byname=$row7["BYNAME"];
}
//$folder_name="[".$RUN_ID."]".$RUN_NAME;
$folder_name=$RUN_ID."-".$RUN_NAME;
/******** 工作流表单中的附件*****************/
$query4="show COLUMNS from flow_data_".$FLOW_ID;
//echo $query4."<br>";
$cursor4=exequery(TD::conn(),$query4);
while($row4=mysql_fetch_array($cursor4)){
$ziduan=$row4["Field"];
//echo $ziduan."<br>";
$ziduan_arr=explode("_",$ziduan);
if($ziduan_arr[2]=="key"){
//echo $ziduan."<br>";
$wenjian_name=$ziduan_arr[0]."_".$ziduan_arr[1];
$wenjian_id=$ziduan_arr[0]."_".$ziduan_arr[1]."_".$ziduan_arr[2];
$query6="select ".$wenjian_id.",".$wenjian_name." from flow_data_".$FLOW_ID." where run_id='$RUN_ID'";
//echo $query6."<br>";
//将OA流程中表单中的附件获取出来,必须用数组拆分
$cursor6 = exequery( TD::conn(), $query6 );
while( $ROW6 = mysql_fetch_array( $cursor6 ) ){
$att_arr=explode(",",$ROW6[$wenjian_id]);
$att_name_arr=explode("*",$ROW6[$wenjian_name]);
for($i=0;$i<count($att_arr)-1;$i++){
$yuan_name1 = attach_real_path($att_arr[$i], $att_name_arr[$i], $MODULE = "" ); //每一个附件copy一次
$to_name1 = $mulu."/".$att_name_arr[$i]."";
//$yuan_name1 = attach_real_path("2682@1511_1589471134", "哈电国际--通达OA实施方案--通达OA孙忠海.docx", $MODULE = "" );
//$to_name1 = "../../../../powneronfile/".$RUN_ID."/哈电国际--通达OA实施方案--通达OA孙忠海.docx";
copy($yuan_name1,$to_name1); //每次只能是一个文件
$file_size=filesize($to_name1);
$file_name=$att_name_arr[$i];
$file_ext=substr(strrchr($file_name, '.'), 1);
$query5="INSERT INTO `powneronfile` (`flow_id`, `run_id`, `file_path`,`file_name`,`file_ext`,`file_size`,`create_user`, `t_flag`) VALUES ('$FLOW_ID', '$RUN_ID','".$RUN_ID."/".$att_name_arr[$i]."','$file_name','$file_ext','$file_size','$byname','0')";
exequery(TD::conn(),$query5);
}
} //end while
} // end if($ziduan_arr[2]=="key"){
}
/******** 工作流表单中的附件
//将工作流中的附件备份到其他目录下
$query1="select * from flow_data_".$FLOW_ID." where run_id='$RUN_ID'"; //将OA流程中表单中的附件获取出来,必须用数组拆分
$cursor1 = exequery( TD::conn(), $query1 );
while( $ROW1 = mysql_fetch_array( $cursor1 ) )
{ //echo $ROW1["data_22"]; echo "<br>";
//echo $ROW1["data_22_key"]; echo "<br>";
$att_arr=explode(",",$ROW1["data_22_key"]);
$att_name_arr=explode("*",$ROW1["data_22"]);
for($i=0;$i<count($att_arr)-1;$i++){
$yuan_name1 = attach_real_path($att_arr[$i], $att_name_arr[$i], $MODULE = "" ); //每一个附件copy一次
$to_name1 = "../../../../powneronfile/".$RUN_ID."/".$att_name_arr[$i]."";
//$yuan_name1 = attach_real_path("2682@1511_1589471134", "哈电国际--通达OA实施方案--通达OA孙忠海.docx", $MODULE = "" );
//$to_name1 = "../../../../powneronfile/".$RUN_ID."/哈电国际--通达OA实施方案--通达OA孙忠海.docx";
//echo $yuan_name1; echo "<br>";
//echo $to_name1; echo "<br>";
copy($yuan_name1,$to_name1); //每次只能是一个文件
}
}
****/
//查询公共附件
$query = "SELECT * from flow_run_attach where run_id = '".$RUN_ID."'";
$cursor = exequery( TD::conn(), $query );
while( $ROW = mysql_fetch_array( $cursor ) )
{
$yuan_name = attach_real_path($ROW["ATTACHMENT_ID"], $ROW["ATTACHMENT_NAME"], $MODULE = "" ); //flow_run_attach是单个附件存储的
$to_name = $mulu."/".$ROW["ATTACHMENT_NAME"]."";
copy($yuan_name,$to_name);
//插入到中间表
//$file_name=$ROW["ATTACHMENT_NAME"];
//$query2="INSERT INTO `hola_oa_file` (`flow_id`, `run_id`, `folder_name`,`file_path`,`file_name`, `t_flag`) VALUES ('$FLOW_ID', '$RUN_ID','$folder_name','".$RUN_ID."/".$ROW["ATTACHMENT_NAME"]."','$file_name','0')";
//插入到中间表
$file_name=$ROW["ATTACHMENT_NAME"];
$file_size=filesize($to_name);
$file_ext=substr(strrchr($file_name, '.'), 1);
$query2="INSERT INTO `powneronfile` (`flow_id`, `run_id`, `file_path`,`file_name`,`file_ext`,`file_size`,`create_user`, `t_flag`) VALUES ('$FLOW_ID', '$RUN_ID','".$RUN_ID."/".$ROW["ATTACHMENT_NAME"]."','$file_name','$file_ext','$file_size','$byname','0')";
exequery(TD::conn(),$query2);
}
//将工作流中的数据添加到数据表中
$biaodan=$RUN_ID."_".$RUN_NAME."[表单].html";
$path=$mulu."/".$biaodan;
wirtefile ($path,$doc_content);
//插入到中间表
//$query3="INSERT INTO `hola_oa_file` (`flow_id`, `run_id`, `folder_name`, `file_path`,`file_name`, `t_flag`) VALUES ('$FLOW_ID', '$RUN_ID','$folder_name', '".$RUN_ID."/".$biaodan."','$biaodan','0')";
$file_name=$biaodan;
$file_size=filesize($path);
$file_ext=substr(strrchr($file_name, '.'), 1);
$query3="INSERT INTO `powneronfile` (`flow_id`, `run_id`, `file_path`,`file_name`,`file_ext`,`file_size`,`create_user`, `t_flag`) VALUES ('$FLOW_ID', '$RUN_ID','".$RUN_ID."/".$biaodan."','$file_name','$file_ext','$file_size','$byname','0')";
exequery(TD::conn(),$query3);
function wirtefile ($fn,$data)
{
$fp=fopen($fn,"wb");
fwrite($fp,$data);
fclose($fp);
}
?>