<commit_before><?php
/**
 * triggers_WizardSave.php
 *  
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2008 Colosa Inc.23
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd., 
 * Coral Gables, FL, 33134, USA, or email <EMAIL>.
 * 
 */

if (($RBAC_Response = $RBAC->userCanAccess ( "PM_FACTORY" )) != 1)
	return $RBAC_Response;
require_once ('classes/model/Triggers.php');
$oTrigger = new Triggers ( );

G::LoadClass('processMap');
$oProcessMap = new processMap(new DBConnection);

$aDataTriggers = $_POST;

$aInfoFunction = explode ( ",", $aDataTriggers ['ALLFUNCTION'] );

$sPMfunction = "
/***************************************************
 *                                                 
 * Generated by ProcessMaker Trigger Wizard
 * Library: " . $aDataTriggers ['LIBRARY_NAME'] . "
 * Method: " . $aDataTriggers ['PMFUNTION_LABEL'] . "
 * Date: " . date ( "Y-m-d H:i:s" ) . "
 * 
 * ProcessMaker " . date ( "Y" ) . "
 *
 ****************************************************/
 
";

$methodParamsFinal = array ();
//Generate params to send
foreach ( $aInfoFunction as $k => $v ) {
	if ($v != '') {
		
		$sOptionTrigger = trim ( str_replace ( "$", "", $v ) );
		if (strstr ( $sOptionTrigger, "=" )) {
			$aOptionParameters = explode ( "=", $sOptionTrigger );
			$sOptionTrigger = trim ( $aOptionParameters [0] );
		}
		if ($aDataTriggers [$sOptionTrigger] != '') {
			
			if ((strstr ( $aDataTriggers [$sOptionTrigger], "@@" ))) {
				$option = $aDataTriggers [$sOptionTrigger];
			} else {
				$option = "'" . $aDataTriggers [$sOptionTrigger] . "'";
			}
		} else {
			$option = "' '";
		}
		$methodParamsFinal [] = $option;
	
	}

}
$sPMfunction .= (isset ( $aDataTriggers ['TRI_ANSWER'] ) && $aDataTriggers ['TRI_ANSWER'] != '') ? $aDataTriggers ['TRI_ANSWER'] . " = " : "";
$sPMfunction .= $aDataTriggers ['PMFUNTION_NAME'] . " (" . implode ( ",", $methodParamsFinal ) . ");";

//Create Trigger
$aDataTriggers ['TRI_WEBBOT'] = $sPMfunction;
$aDataTriggersParams = array();
$aDataTriggersParams['hash'] = md5 ($sPMfunction);
$aDataTriggersParams['params'] = $aDataTriggers;

$aDataTriggers ['TRI_PARAM'] = serialize($aDataTriggersParams);
$oTrigger->create ( $aDataTriggers );<commit_msg>Fix on trigger geenration. No extra spaces<commit_after><?php
/**
 * triggers_WizardSave.php
 *  
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2008 Colosa Inc.23
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd., 
 * Coral Gables, FL, 33134, USA, or email <EMAIL>.
 * 
 */

if (($RBAC_Response = $RBAC->userCanAccess ( "PM_FACTORY" )) != 1)
	return $RBAC_Response;
require_once ('classes/model/Triggers.php');
$oTrigger = new Triggers ( );

G::LoadClass('processMap');
$oProcessMap = new processMap(new DBConnection);

$aDataTriggers = $_POST;

$aInfoFunction = explode ( ",", $aDataTriggers ['ALLFUNCTION'] );

$sPMfunction = "
/***************************************************
 *                                                 
 * Generated by ProcessMaker Trigger Wizard
 * Library: " . $aDataTriggers ['LIBRARY_NAME'] . "
 * Method: " . $aDataTriggers ['PMFUNTION_LABEL'] . "
 * Date: " . date ( "Y-m-d H:i:s" ) . "
 * 
 * ProcessMaker " . date ( "Y" ) . "
 *
 ****************************************************/
 
";

$methodParamsFinal = array ();
//Generate params to send
foreach ( $aInfoFunction as $k => $v ) {
	if ($v != '') {
		
		$sOptionTrigger = trim ( str_replace ( "$", "", $v ) );
		if (strstr ( $sOptionTrigger, "=" )) {
			$aOptionParameters = explode ( "=", $sOptionTrigger );
			$sOptionTrigger = trim ( $aOptionParameters [0] );
		}
		if ($aDataTriggers [$sOptionTrigger] != '') {
			
			if ((strstr ( $aDataTriggers [$sOptionTrigger], "@@" ))) {
				$option = trim($aDataTriggers [$sOptionTrigger]);
			} else {
				$option = "'" . trim($aDataTriggers [$sOptionTrigger]) . "'";
			}
		} else {
			$option = "''";
		}
		$methodParamsFinal [] = $option;
	
	}

}
G::pr($methodParamsFinal);die;
$sPMfunction .= (isset ( $aDataTriggers ['TRI_ANSWER'] ) && $aDataTriggers ['TRI_ANSWER'] != '') ? $aDataTriggers ['TRI_ANSWER'] . " = " : "";
$sPMfunction .= $aDataTriggers ['PMFUNTION_NAME'] . " (" . implode ( ",", $methodParamsFinal ) . ");";

//Create Trigger
$aDataTriggers ['TRI_WEBBOT'] = $sPMfunction;
$aDataTriggersParams = array();
$aDataTriggersParams['hash'] = md5 ($sPMfunction);
$aDataTriggersParams['params'] = $aDataTriggers;

$aDataTriggers ['TRI_PARAM'] = serialize($aDataTriggersParams);
$oTrigger->create ( $aDataTriggers );
{'fraction_non_alphanumeric': 0.18578489858530764, 'fraction_numerical': 0.007840463610022158, 'mean_word_length': 3.8336079077429983, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6957643', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1887, 'n_words': 505}