通达OA触发器--压缩保存工作流中的表单文件和所有附件到服务器的指定目录(2013adv,2015,2016)

来源:互联网 发布:泰国有4g网络吗 编辑:程序博客网 时间:2024/05/16 07:01
<?//qq:1027167227include_once("inc/auth.inc.php");include_once("inc/utility_file.php");include_once("../../list/export_flow.php");include_once("inc/header.inc.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");$RUN_ID_STR="7857";//echo $RUN_ID_STR."<br>";//workflow/query/explot_zip.phpif($archive_data){$archive_time="_".$archive_data;$use_databases = "td_oa_archive.";}else{$archive_time =="";$use_databases = "";}$zip_name = sprintf(_($RUN_ID_STR."OA工作(%s).zip"), date("Y-m-d",time()));$zip_file = get_tmp_filename("workflow", $zip_name);$zip = new ZipArchive;$res = $zip->open($zip_file, ZipArchive::CREATE|ZIPARCHIVE::OVERWRITE);if($res !== TRUE){   Message(_("提示"),_("创建文件错误,代码:").$res);   exit;}if($RUN_ID_STR=="")   $RUN_ID_STR=0;elseif(substr($RUN_ID_STR,-1,1)==",")   $RUN_ID_STR=substr($RUN_ID_STR,0,-1);$tmp_file_array = array();$tmp_file_array[] = $zip_file;$query = "SELECT * from FLOW_RUN where RUN_ID IN ($RUN_ID_STR)";//echo $query."<br>";$cursor= exequery(TD::conn(),$query);while($ROW=mysql_fetch_array($cursor)){    $zipfiles="";    $role_str = "";    $RUN_ID = $run_id     = $ROW["RUN_ID"];    $flow_id    = $ROW["FLOW_ID"];    $run_name   = trim($ROW["RUN_NAME"]);        //判断查看权限    $role_str = run_role($run_id, 0, $archive_time);        //判断保密字段规则 0 - 无保密字段 1 - 根据步骤号获得保密字段 2 - 对所有步骤的保密字段都设定为保密字段    $flag_hidden_type = 1;    $table_flow_run_prcs = $use_databases."flow_run_prcs".$archive_time;        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))    {        //主办、经办、原始委托人可以查看其办理的最后一步流程步骤的所有字段        $query2 = "select prcs_id from ".$table_flow_run_prcs."                  where ID = (                  select MAX(ID) from ".$table_flow_run_prcs." where RUN_ID = '".$run_id."'                  AND (USER_ID = '".$_SESSION["LOGIN_USER_ID"]."'                  or FIND_IN_SET('".$_SESSION["LOGIN_USER_ID"]."',OTHER_USER))) ";        $cursor2 = exequery(TD::conn(), $query2);        if($row2 = mysql_fetch_array($cursor2))        {            $PRCS_ID = $row2['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($flag_hidden_type == 0)    {        $secret_fields = "";    }    else if($flag_hidden_type == 1)    {        //获得设计步骤号        $query3 = "select FLOW_PRCS from ".$table_flow_run_prcs." where RUN_ID = '".$run_id."' and PRCS_ID = '".$PRCS_ID."' limit 1";        $cursor3 = exequery(TD::conn(),$query3);        if($row3 = mysql_fetch_array($cursor3))        {            $FLOW_PRCS = $row3['FLOW_PRCS'];        }                //获得步骤保密字段        $table_flow_prcocess = $use_databases."flow_process".$archive_time;        $secret_fields = "";        $query3 = "select HIDDEN_ITEM from ".$table_flow_prcocess." where FLOW_ID = '".$flow_id."' and PRCS_ID = '".$FLOW_PRCS."' ";        $cursor3 = exequery(TD::conn(),$query3);        if($row3 = mysql_fetch_array($cursor3))        {            $secret_fields = $row3['HIDDEN_ITEM'];        }    }    else if($flag_hidden_type == 2)    {        //获得流程所有步骤的保密字段        $table_flow_prcocess = $use_databases."flow_process".$archive_time;        $secret_fields = "";        $query3 = "select HIDDEN_ITEM from ".$table_flow_prcocess." where FLOW_ID = '".$flow_id."' ";        $cursor3 = exequery(TD::conn(),$query3);        while($row3 = mysql_fetch_array($cursor3))        {            $secret_fields .= $row3['HIDDEN_ITEM'].",";        }                //去掉重复的        $secret_fields = td_trim($secret_fields);        $secret_fields = str_remove_dup($secret_fields);    }        $config = Array(        'FLOW_VIEW' => '12345',        'db' => $use_databases,        'archive_time' => $archive_time,        'secret_fields' => $secret_fields    );    $obj_export_zip = new TWorkExport($flow_id, $run_id, 0,0,0, $config);    $a_export = $obj_export_zip->export_all_run();//print_r($a_export);    $s_attachment_id = $a_export['attachment_id'];    $s_attachment_name = $a_export['attachment_name'];    $content_html = $a_export['content_html'];$query4="select data_2,data_2_key from flow_data_161 where run_id='$RUN_ID' limit 1";$cursor4=exequery(TD::conn(),$query4);while($row4=mysql_fetch_array($cursor4)){$data_2=str_replace("*",",",$row4["data_2"]);$data_2_key=$row4["data_2_key"];} $s_attachment_id.=$data_2_key;  $s_attachment_name.=$data_2;// echo $s_attachment_id."<br>";//echo $s_attachment_name."<br>";    //处理文件名称 /\*:?"<>|    $j = 0;    $char="/,\\,*,:,?,\",<,>,|";    while($j < strlen($run_name))    {        $str = substr($run_name, $j, 1);        if(find_id($char, $str))        {            $run_name = str_replace($str,"",$run_name);        }        $j++;    }        if(!$zip->addEmptyDir($run_name))    {        continue;    }        $zip->addFromString($run_name."/".$run_name.".html", $content_html);   // echo $s_attachment_id."<br>";    $a_attachment_id = explode(",",$s_attachment_id);    $a_attachment_name = explode(",",$s_attachment_name);        $feedbck_count_id = sizeof($a_attachment_id);    for($k=0; $k < $feedbck_count_id; $k++)    {        if($a_attachment_id[$k] == '')        {            continue;        }                $filename = attach_real_path($a_attachment_id[$k],$a_attachment_name[$k]);               if(!$filename)        {            continue;        }                $tmp_filename = get_tmp_filename("workflow_attach", basename($filename));                if(decrypt_attach($filename, $tmp_filename))        {            $filename = $tmp_filename;            $tmp_file_array[] = $tmp_filename;        }                $zip->addFile($filename, $run_name."/".$a_attachment_name[$k]);    }}//while$zip->close();ob_end_clean();/*Header("Cache-control: private");Header("Content-type: application/x-zip");header("Accept-Ranges: bytes");header("Accept-Length: ".sprintf("%u", filesize($zip_file)));header("Content-Disposition: attachment; ".get_attachment_filename($zip_name));*///readfile($zip_file);echo $zip_file."<br>";$PATH="E:/MYOA/attach/".$zip_name;  echo @copy($zip_file,$PATH)?'成功':'失败';//echo @rename($file1,$PATH)?'成功':'失败';//2677@1505_1668115426foreach ($tmp_file_array as $tmp_file){    @unlink($tmp_file);}?>

0 0