processmaker如何将Process无须登录的Web Entry改为必须登录并与CAS集成做单点的Web App

废话少说,直接上干货

修改$pm/workflow/engine/methods/processes/processes_webEntryGenerate.php,原来是:

<?php
global $G_FORM;
$sPRO_UID = $oData->PRO_UID;
$sTASKS = $oData->TASKS;
$sDYNAFORM = $oData->DYNAFORM;
$sWE_TYPE = $oData->WE_TYPE;
$sWS_USER = $oData->WS_USER;
$sWS_PASS = $oData->WS_PASS;
$sWS_ROUNDROBIN = $oData->WS_ROUNDROBIN;
$sWE_USR = $oData->WE_USR;

$withWS = $sWE_TYPE == 'WS';

G::LoadClass("system");

try {
  $pathProcess = PATH_DATA_SITE . 'public' . PATH_SEP . $sPRO_UID . PATH_SEP;
  G::mk_dir ( $pathProcess, 0777 );
  
  $oTask = new Task ( );
  $TaskFields = $oTask->load ( $sTASKS );
  $WE_EVN_UID = $oTask->getStartingEvent($sTASKS);
  if ($TaskFields['TAS_ASSIGN_TYPE'] != 'BALANCED') {
    throw (new Exception ( "The task '" . $TaskFields['TAS_TITLE'] . "' doesn't have a valid assignment type. The task needs to have a 'Cyclical Assignment'." ));
  }
  
  G::LoadClass ( 'tasks' );
  $oTask = new Tasks ( );
  $user = $oTask->assignUsertoTask ( $sTASKS );
  
  if ($user == 0) {
    throw (new Exception ( "The task '" . $TaskFields['TAS_TITLE'] . "' doesn't have users." ));
  }
  
  if (G::is_https ())
    $http = 'https://';
  else
    $http = 'http://';
  
  $sContent = '';
  
  if ($withWS) {
    //creating sys.info;	
    $SITE_PUBLIC_PATH = '';
    if (file_exists ( $SITE_PUBLIC_PATH . '' )) {}
    
    //creating the first file
    require_once 'classes/model/Dynaform.php';
    $oDynaform = new Dynaform ( );
    $aDynaform = $oDynaform->load ( $sDYNAFORM );
    $dynTitle = str_replace ( ' ', '_', str_replace ( '/', '_', $aDynaform['DYN_TITLE'] ) );
    $sContent = "<?php\n";
    $sContent .= "global \$_DBArray;\n";
    $sContent .= "if (!isset(\$_DBArray)) {\n";
    $sContent .= "  \$_DBArray = array();\n";
    $sContent .= "}\n";
    $sContent .= "\$_SESSION['PROCESS'] = '" . $sPRO_UID . "';\n";
    $sContent .= "\$_SESSION['CURRENT_DYN_UID'] = '" . $sDYNAFORM . "';\n";
    $sContent .= "\$G_PUBLISH = new Publisher;\n";
    $sContent .= "\$G_PUBLISH->AddContent('dynaform', 'xmlform', '" . $sPRO_UID . '/' . $sDYNAFORM . "', '', array(), '" . $dynTitle . 'Post.php' . "');\n";
    $sContent .= "G::RenderPage('publish', 'blank');";
    file_put_contents ( $pathProcess . $dynTitle . '.php', $sContent );
    //creating the second file, the  post file who receive the post form.
    $pluginTpl = PATH_CORE . 'templates' . PATH_SEP . 'processes' . PATH_SEP . 'webentryPost.tpl';
    $template = new TemplatePower ( $pluginTpl );
    $template->prepare ();
    $template->assign ( 'wsdlUrl', $http . $_SERVER['HTTP_HOST'] . '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/services/wsdl2' );
    $template->assign ( 'wsUploadUrl', $http . $_SERVER['HTTP_HOST'] . '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/services/upload' );
    $template->assign ( 'processUid', $sPRO_UID );
    $template->assign ( 'dynaformUid', $sDYNAFORM );
    $template->assign ( 'taskUid', $sTASKS );
    $template->assign ( 'wsUser', $sWS_USER );
    $template->assign ( 'wsPass', 'md5:' . md5 ( $sWS_PASS ) );
    $template->assign ( 'wsRoundRobin', $sWS_ROUNDROBIN );
    
    if($sWE_USR == "2"){
      $template->assign ( 'USR_VAR', "\$cInfo = ws_getCaseInfo(\$caseId);\n\t  \$USR_UID = \$cInfo->currentUsers->userId;" );
    } else {
      $template->assign ( 'USR_VAR', '$USR_UID = -1;' );
    }
    
    
    $template->assign ( 'dynaform', $dynTitle );
    $template->assign ( 'timestamp', date ( 'l jS \of F Y h:i:s A' ) );
    $template->assign ( 'ws', SYS_SYS );
    $template->assign ( 'version', System::getVersion() );
    
    $fileName = $pathProcess . $dynTitle . 'Post.php';
    file_put_contents ( $fileName, $template->getOutputContent () );
    //creating the third file, only if this wsClient.php file doesn't exist.
    $fileName = $pathProcess . 'wsClient.php';
    $pluginTpl = PATH_CORE . 'test' . PATH_SEP . 'unit' . PATH_SEP . 'ws' . PATH_SEP . 'wsClient.php';
    
    if ( file_exists ($fileName) ) {
      if( filesize($fileName) != filesize($pluginTpl) ){
        @copy($fileName, $pathProcess . 'wsClient.php.bck');
        @unlink($fileName);
        
        $template = new TemplatePower ( $pluginTpl );
        $template->prepare ();
        file_put_contents ( $fileName, $template->getOutputContent () );
      }
    } else {
      $template = new TemplatePower ( $pluginTpl );
      $template->prepare ();
      file_put_contents ( $fileName, $template->getOutputContent () );
    }

    require_once 'classes/model/Event.php';
    $oEvent = new Event ( );
    $aDataEvent = array();

    $aDataEvent['EVN_UID']        = $WE_EVN_UID; //$oData->WE_EVN_UID;
    $aDataEvent['EVN_RELATED_TO'] = 'MULTIPLE';
    $aDataEvent['EVN_ACTION']     = $sDYNAFORM;
    $aDataEvent['EVN_CONDITIONS'] = $sWS_USER;
    $output = $oEvent->update($aDataEvent);
    //Show link
    $link = $http . $_SERVER['HTTP_HOST'] . '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/' . $sPRO_UID . '/' . $dynTitle . '.php';
    print $link;
    //print "\n<a href='$link' target='_new' > $link </a>";
  

  } else {
    $G_FORM = new Form ( $sPRO_UID . '/' . $sDYNAFORM, PATH_DYNAFORM, SYS_LANG, false );
    $G_FORM->action = $http . $_SERVER['HTTP_HOST'] . '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/services/cases_StartExternal.php';
    
    $scriptCode = '';
    $scriptCode = $G_FORM->render ( PATH_CORE . 'templates/' . 'xmlform' . '.html', $scriptCode );
    $scriptCode = str_replace ( '/controls/', $http . $_SERVER['HTTP_HOST'] . '/controls/', $scriptCode );
    $scriptCode = str_replace ( '/js/maborak/core/images/', $http . $_SERVER['HTTP_HOST'] . '/js/maborak/core/images/', $scriptCode );
    
    //render the template
    $pluginTpl = PATH_CORE . 'templates' . PATH_SEP . 'processes' . PATH_SEP . 'webentry.tpl';
    $template = new TemplatePower ( $pluginTpl );
    $template->prepare ();
    require_once 'classes/model/Step.php';
    $oStep = new Step();
    $sUidGrids = $oStep->lookingforUidGrids($sPRO_UID,$sDYNAFORM);


    $template->assign ( 'siteUrl', $http . $_SERVER['HTTP_HOST'] );
    $template->assign ( 'sysSys', SYS_SYS );
    $template->assign ( 'sysLang', SYS_LANG );
    $template->assign ( 'sysSkin', SYS_SKIN );
    $template->assign ( 'processUid', $sPRO_UID );
    $template->assign ( 'dynaformUid', $sDYNAFORM );
    $template->assign ( 'taskUid', $sTASKS );
    $template->assign ( 'dynFileName', $sPRO_UID . '/' . $sDYNAFORM );
    $template->assign ( 'formId', $G_FORM->id );
    $template->assign ( 'scriptCode', $scriptCode );
    
    if(sizeof($sUidGrids)>0){
      foreach($sUidGrids as $k => $v){
      	$template->newBlock( 'grid_uids' );
        $template->assign ( 'siteUrl', $http . $_SERVER['HTTP_HOST'] );
        $template->assign ( 'gridFileName', $sPRO_UID . '/' . $v );
      }
    }
    
    print_r ( '<textarea cols="70" rows="20">' . htmlentities ( str_replace ( '</body>', '</form></body>', str_replace ( '</form>', '', $template->getOutputContent () ) ) ) . '</textarea>' );
  }

} catch ( Exception $e ) {
  $G_PUBLISH = new Publisher ( );
  $aMessage['MESSAGE'] = $e->getMessage ();
  $G_PUBLISH->AddContent ( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
  G::RenderPage ( 'publish', 'raw' );
}

改为:
<?php
global $G_FORM;
$sPRO_UID = $oData->PRO_UID;
$sTASKS = $oData->TASKS;
$sDYNAFORM = $oData->DYNAFORM;
$sWE_TYPE = $oData->WE_TYPE;
$sWS_USER = $oData->WS_USER;
$sWS_PASS = $oData->WS_PASS;
$sWS_ROUNDROBIN = $oData->WS_ROUNDROBIN;
$sWE_USR = $oData->WE_USR;

$withWS = $sWE_TYPE == 'WS';

G::LoadClass("system");

try {
  $pathProcess = PATH_DATA_SITE . 'public' . PATH_SEP . $sPRO_UID . PATH_SEP;
  G::mk_dir ( $pathProcess, 0777 );
  
  $oTask = new Task ( );
  $TaskFields = $oTask->load ( $sTASKS );
  $WE_EVN_UID = $oTask->getStartingEvent($sTASKS);
  if ($TaskFields['TAS_ASSIGN_TYPE'] != 'BALANCED') {
    throw (new Exception ( "The task '" . $TaskFields['TAS_TITLE'] . "' doesn't have a valid assignment type. The task needs to have a 'Cyclical Assignment'." ));
  }
  
  G::LoadClass ( 'tasks' );
  $oTask = new Tasks ( );
  $user = $oTask->assignUsertoTask ( $sTASKS );
  
  if ($user == 0) {
    throw (new Exception ( "The task '" . $TaskFields['TAS_TITLE'] . "' doesn't have users." ));
  }
  
  if (G::is_https ())
    $http = 'https://';
  else
    $http = 'http://';
  
  $sContent = '';
  
  if ($withWS) {
    //creating sys.info;	
    $SITE_PUBLIC_PATH = '';
    if (file_exists ( $SITE_PUBLIC_PATH . '' )) {}
    
    //creating the first file
    require_once 'classes/model/Dynaform.php';
    $oDynaform = new Dynaform ( );
    $aDynaform = $oDynaform->load ( $sDYNAFORM );
    $dynTitle = str_replace ( ' ', '_', str_replace ( '/', '_', $aDynaform['DYN_TITLE'] ) );
    $sContent = "<?php\n";
    //
    $sContent .= "if ( ! isset( \$_SESSION['SSOUSER_NAME'] ) ) {\n";
    $sContent .= "  require_once (\"CAS-1.3.2/CAS.php\");\n";
    $sContent .= "  require_once (\"CAS-1.3.2/config.php\");\n";
    $sContent .= "  phpCAS::client(CAS_VERSION_2_0, CAS_SERVER_IP, 8443, 'cas', false);\n";
    $sContent .= "  phpCAS::setNoCasServerValidation();\n";
    $sContent .= "  phpCAS::forceAuthentication();\n";
    $sContent .= "  if ( phpCAS::isAuthenticated() == true )\n";
    $sContent .= "    \$casAuth = CASAuthIsTrue;\n";
    $sContent .= "  \$_SESSION['SSOUSER_NAME'] = phpCAS::getUser();\n";
    $sContent .= "  \$_SESSION['SSOUSER_PASS'] = \$casAuth;\n";
    $sContent .= "}\n\n";
    //
    $sContent .= "global \$_DBArray;\n";
    $sContent .= "if (!isset(\$_DBArray)) {\n";
    $sContent .= "  \$_DBArray = array();\n";
    $sContent .= "}\n";
    $sContent .= "\$_SESSION['PROCESS'] = '" . $sPRO_UID . "';\n";
    $sContent .= "\$_SESSION['CURRENT_DYN_UID'] = '" . $sDYNAFORM . "';\n";
    $sContent .= "\$G_PUBLISH = new Publisher;\n";
    $sContent .= "\$G_PUBLISH->AddContent('dynaform', 'xmlform', '" . $sPRO_UID . '/' . $sDYNAFORM . "', '', array(), '" . $dynTitle . 'Post.php' . "');\n";
    $sContent .= "G::RenderPage('publish', 'blank');";
    file_put_contents ( $pathProcess . $dynTitle . '.php', $sContent );
    //creating the second file, the  post file who receive the post form.
    $pluginTpl = PATH_CORE . 'templates' . PATH_SEP . 'processes' . PATH_SEP . 'webentryPost.tpl';
    $template = new TemplatePower ( $pluginTpl );
    $template->prepare ();
    $template->assign ( 'wsdlUrl', $http . $_SERVER['HTTP_HOST'] . '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/services/wsdl2' );
    $template->assign ( 'wsUploadUrl', $http . $_SERVER['HTTP_HOST'] . '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/services/upload' );
    $template->assign ( 'processUid', $sPRO_UID );
    $template->assign ( 'dynaformUid', $sDYNAFORM );
    $template->assign ( 'taskUid', $sTASKS );
    $template->assign ( 'wsUser', $sWS_USER );
    $template->assign ( 'wsPass', 'md5:' . md5 ( $sWS_PASS ) );
    $template->assign ( 'wsRoundRobin', $sWS_ROUNDROBIN );
    
    if($sWE_USR == "2"){
      $template->assign ( 'USR_VAR', "\$cInfo = ws_getCaseInfo(\$caseId);\n\t  \$USR_UID = \$cInfo->currentUsers->userId;" );
    } else {
      $template->assign ( 'USR_VAR', '$USR_UID = -1;' );
    }
    
    
    $template->assign ( 'dynaform', $dynTitle );
    $template->assign ( 'timestamp', date ( 'l jS \of F Y h:i:s A' ) );
    $template->assign ( 'ws', SYS_SYS );
    $template->assign ( 'version', System::getVersion() );
    
    $fileName = $pathProcess . $dynTitle . 'Post.php';
    file_put_contents ( $fileName, $template->getOutputContent () );
    //creating the third file, only if this wsClient.php file doesn't exist.
    $fileName = $pathProcess . 'wsClient.php';
    $pluginTpl = PATH_CORE . 'test' . PATH_SEP . 'unit' . PATH_SEP . 'ws' . PATH_SEP . 'wsClient.php';
    
    if ( file_exists ($fileName) ) {
      if( filesize($fileName) != filesize($pluginTpl) ){
        @copy($fileName, $pathProcess . 'wsClient.php.bck');
        @unlink($fileName);
        
        $template = new TemplatePower ( $pluginTpl );
        $template->prepare ();
        file_put_contents ( $fileName, $template->getOutputContent () );
      }
    } else {
      $template = new TemplatePower ( $pluginTpl );
      $template->prepare ();
      file_put_contents ( $fileName, $template->getOutputContent () );
    }

    require_once 'classes/model/Event.php';
    $oEvent = new Event ( );
    $aDataEvent = array();

    $aDataEvent['EVN_UID']        = $WE_EVN_UID; //$oData->WE_EVN_UID;
    $aDataEvent['EVN_RELATED_TO'] = 'MULTIPLE';
    $aDataEvent['EVN_ACTION']     = $sDYNAFORM;
    $aDataEvent['EVN_CONDITIONS'] = $sWS_USER;
    $output = $oEvent->update($aDataEvent);
    //Show link
    $link = $http . $_SERVER['HTTP_HOST'] . '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/' . $sPRO_UID . '/' . $dynTitle . '.php';
    print $link;
    //print "\n<a href='$link' target='_new' > $link </a>";
  

  } else {
    $G_FORM = new Form ( $sPRO_UID . '/' . $sDYNAFORM, PATH_DYNAFORM, SYS_LANG, false );
    $G_FORM->action = $http . $_SERVER['HTTP_HOST'] . '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/services/cases_StartExternal.php';
    
    $scriptCode = '';
    $scriptCode = $G_FORM->render ( PATH_CORE . 'templates/' . 'xmlform' . '.html', $scriptCode );
    $scriptCode = str_replace ( '/controls/', $http . $_SERVER['HTTP_HOST'] . '/controls/', $scriptCode );
    $scriptCode = str_replace ( '/js/maborak/core/images/', $http . $_SERVER['HTTP_HOST'] . '/js/maborak/core/images/', $scriptCode );
    
    //render the template
    $pluginTpl = PATH_CORE . 'templates' . PATH_SEP . 'processes' . PATH_SEP . 'webentry.tpl';
    $template = new TemplatePower ( $pluginTpl );
    $template->prepare ();
    require_once 'classes/model/Step.php';
    $oStep = new Step();
    $sUidGrids = $oStep->lookingforUidGrids($sPRO_UID,$sDYNAFORM);


    $template->assign ( 'siteUrl', $http . $_SERVER['HTTP_HOST'] );
    $template->assign ( 'sysSys', SYS_SYS );
    $template->assign ( 'sysLang', SYS_LANG );
    $template->assign ( 'sysSkin', SYS_SKIN );
    $template->assign ( 'processUid', $sPRO_UID );
    $template->assign ( 'dynaformUid', $sDYNAFORM );
    $template->assign ( 'taskUid', $sTASKS );
    $template->assign ( 'dynFileName', $sPRO_UID . '/' . $sDYNAFORM );
    $template->assign ( 'formId', $G_FORM->id );
    $template->assign ( 'scriptCode', $scriptCode );
    
    if(sizeof($sUidGrids)>0){
      foreach($sUidGrids as $k => $v){
      	$template->newBlock( 'grid_uids' );
        $template->assign ( 'siteUrl', $http . $_SERVER['HTTP_HOST'] );
        $template->assign ( 'gridFileName', $sPRO_UID . '/' . $v );
      }
    }
    
    print_r ( '<textarea cols="70" rows="20">' . htmlentities ( str_replace ( '</body>', '</form></body>', str_replace ( '</form>', '', $template->getOutputContent () ) ) ) . '</textarea>' );
  }

} catch ( Exception $e ) {
  $G_PUBLISH = new Publisher ( );
  $aMessage['MESSAGE'] = $e->getMessage ();
  $G_PUBLISH->AddContent ( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
  G::RenderPage ( 'publish', 'raw' );
}




注释之间的代码就是新加的,文件其他部分不用改。it's enough! 当然,要做到如此简单就实现,之前的准备工作(见processmaker在与cas做SSO集成时需要做的修改,)必须要做充分了!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值