Files
luos/workflow/engine/classes/class.pmFunctions.php

2870 lines
95 KiB
PHP
Raw Normal View History

2010-12-02 23:34:41 +00:00
<?php
/**
* class.pmFunctions.php
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2008 Colosa Inc.23
2010-12-02 23:34:41 +00:00
*
* 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
2012-10-09 12:56:31 -04:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2010-12-02 23:34:41 +00:00
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
2012-10-09 12:56:31 -04:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2010-12-02 23:34:41 +00:00
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*/
////////////////////////////////////////////////////
// PM Functions
//
// Copyright (C) 2007 COLOSA
//
// License: LGPL, see LICENSE
////////////////////////////////////////////////////
2012-10-09 12:56:31 -04:00
if (! class_exists( 'PMScript' )) {
G::LoadClass( 'pmScript' );
}
2010-12-02 23:34:41 +00:00
/**
* ProcessMaker has made a number of its PHP functions available be used in triggers and conditions.
* Most of these functions are wrappers for internal functions used in Gulliver, which is the development framework
* used by ProcessMaker.
* @class pmFunctions
2012-10-09 12:56:31 -04:00
*
2010-12-02 23:34:41 +00:00
* @name ProcessMaker Functions
* @icon /images/pm.gif
* @className class.pmFunctions.php
2010-12-02 23:34:41 +00:00
*/
/**
* @method
*
* Retrieves the current date formated in the format "yyyy-mm-dd", with leading zeros in the
2010-12-02 23:34:41 +00:00
* month and day if less than 10. This function is equivalent to PHP's date("Y-m-d").
*
* @name getCurrentDate
* @label Get Current Date
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#getCurrentDate.28.29
*
* @return date | $date | Current Date (Y-m-d) | It returns the current date as a string value.
*
*/
2012-10-09 12:56:31 -04:00
function getCurrentDate ()
{
2012-10-09 12:56:31 -04:00
return G::CurDate( 'Y-m-d' );
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns the current time in the format "hh:mm:ss" with leading zeros when the hours,
2010-12-02 23:34:41 +00:00
* minutes or seconds are less than 10.
*
* @name getCurrentTime
* @label Get Current Time
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#getCurrentTime.28.29
*
* @return time | $time | Current Time (H:i:s)| The function returns the current time as a string.
*
*/
2012-10-09 12:56:31 -04:00
function getCurrentTime ()
{
2012-10-09 12:56:31 -04:00
return G::CurDate( 'H:i:s' );
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Retrieves information about a user with a given ID.
2010-12-02 23:34:41 +00:00
*
* @name userInfo
* @label User Info
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#userInfo.28.29
*
* @param string(32) | $userUid | User ID | The user unique ID
* @return array | $info | User Info | An associative array with Information
2010-12-02 23:34:41 +00:00
*
*/
function userInfo($userUid)
{
return PMFInformationUser($userUid);
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a string converted into all UPPERCASE letters.
2010-12-02 23:34:41 +00:00
*
* @name upperCase
* @label Upper Case
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#upperCase.28.29
*
* @param string(32) | $sText | Text To Convert | A string to convert to UPPERCASE letters.
* @return string | $TextC | Text Converted | Returns a string with the text converted into upper case letters.
*
*/
2012-10-09 12:56:31 -04:00
function upperCase ($sText)
{
2012-10-09 12:56:31 -04:00
return G::toUpper( $sText );
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a string with all the letters converted into lower case letters.
2010-12-02 23:34:41 +00:00
*
* @name lowerCase
* @label Lower Case
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#lowerCase.28.29
*
* @param string(32) | $sText | Text To Convert | A string to convert to lower case letters.
* @return string | $TextC | Text Converted | Returns a string with the text converted into lower case letters.
*
*/
2012-10-09 12:56:31 -04:00
function lowerCase ($sText)
{
2012-10-09 12:56:31 -04:00
return G::toLower( $sText );
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Converts the first letter in each word into an uppercase letter.
2010-12-02 23:34:41 +00:00
* Subsequent letters in each word are changed into lowercase letters.
*
* @name capitalize
* @label Capitalize
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#capitalize.28.29
*
* @param string(32) | $sText | Text To Convert | The string to capitalize.
* @return string | $TextC | Text Converted | It returns the introduced text with the first letter capitalized in each word and the subsequent letters into lowercase letters
*
*/
2012-10-09 12:56:31 -04:00
function capitalize ($sText)
{
2012-10-09 12:56:31 -04:00
return G::capitalizeWords( $sText );
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a string formatted according to the given date format and given language
2010-12-02 23:34:41 +00:00
*
* @name formatDate
* @label Format Date
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#formatDate.28.29
*
* @param string(32) | $date | Date | The input date to be reformatted. The input date must be a string in the format 'yyyy-mm-dd'.
* @param string(32) | $format="" | format | The format of the date which will be returned. It can have the following definitions:
* @param string(32) | $lang="en"| Language | The language in which to reformat the date. It can be 'en' (English), 'es' (Spanish) or 'fa' (Persian).
* @return string | $formatDate | Date whit format | It returns the passed date according to the given date format.
*
*/
2012-10-09 12:56:31 -04:00
function formatDate ($date, $format = '', $lang = 'en')
{
2012-10-09 12:56:31 -04:00
if (! isset( $date ) or $date == '') {
throw new Exception( 'function:formatDate::Bad param' );
}
try {
2012-10-09 12:56:31 -04:00
return G::getformatedDate( $date, $format, $lang );
} catch (Exception $oException) {
throw $oException;
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a specified date written out in a given language, with full month names.
2010-12-02 23:34:41 +00:00
*
* @name literalDate
* @label Literal Date
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#literalDate.28.29
*
* @param string(32) | $date | date | The input date in standard format (yyyy-mm-dd) that is a string.
* @param string(32) | $lang="en" | Language | The language to display, which can be 'en' (English) or 'es' (Spanish). If not included, then it will be English by default.
* @return string | $literaDate | Literal date | It returns the literal date as a string value.
*
*/
2012-10-09 12:56:31 -04:00
function literalDate ($date, $lang = 'en')
{
2012-10-09 12:56:31 -04:00
if (! isset( $date ) or $date == '') {
throw new Exception( 'function:formatDate::Bad param' );
}
try {
switch ($lang) {
case 'en':
2012-10-09 12:56:31 -04:00
$ret = G::getformatedDate( $date, 'M d,yyyy', $lang );
break;
case 'es':
2012-10-09 12:56:31 -04:00
$ret = G::getformatedDate( $date, 'd de M de yyyy', $lang );
break;
}
return $ret;
} catch (Exception $oException) {
throw $oException;
2010-12-02 23:34:41 +00:00
}
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Executes a SQL statement in a database connection or in one of ProcessMaker's
2010-12-02 23:34:41 +00:00
* internal databases.
*
* @name executeQuery
* @label execute Query
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#executeQuery.28.29
*
* @param string(32) | $SqlStatement | Sql query | The SQL statement to be executed. Do NOT include the database name in the SQL statement.
* @param string(32) | $DBConnectionUID="workflow"| UID database | The UID of the database connection where the SQL statement will be executed.
* @return array or string | $Resultquery | Result | Result of the query | If executing a SELECT statement, it returns an array of associative arrays
*
*/
2012-10-09 12:56:31 -04:00
function executeQuery ($SqlStatement, $DBConnectionUID = 'workflow', $aParameter = array())
{
2012-10-09 12:56:31 -04:00
$con = Propel::getConnection( $DBConnectionUID );
$con->begin();
try {
2012-10-09 12:56:31 -04:00
$statement = trim( $SqlStatement );
$statement = str_replace( '(', '', $statement );
$result = false;
2012-10-09 12:56:31 -04:00
if (getEngineDataBaseName( $con ) != 'oracle') {
switch (true) {
case preg_match( "/^(SELECT|EXECUTE|EXEC|SHOW|DESCRIBE|EXPLAIN|BEGIN)\s/i", $statement ):
$rs = $con->executeQuery( $SqlStatement );
$con->commit();
2012-10-09 12:56:31 -04:00
$result = Array ();
$i = 1;
while ($rs->next()) {
2012-10-09 12:56:31 -04:00
$result[$i ++] = $rs->getRow();
}
break;
2012-10-09 12:56:31 -04:00
case preg_match( "/^INSERT\s/i", $statement ):
$rs = $con->executeUpdate( $SqlStatement );
$result = $con->getUpdateCount();
$con->commit();
//$result = $lastId->getId();
// $result = 1;
break;
2012-10-09 12:56:31 -04:00
case preg_match( "/^UPDATE\s/i", $statement ):
$rs = $con->executeUpdate( $SqlStatement );
$result = $con->getUpdateCount();
$con->commit();
break;
2012-10-09 12:56:31 -04:00
case preg_match( "/^DELETE\s/i", $statement ):
$rs = $con->executeUpdate( $SqlStatement );
$result = $con->getUpdateCount();
$con->commit();
break;
}
} else {
2012-10-09 12:56:31 -04:00
$result = executeQueryOci( $SqlStatement, $con, $aParameter );
}
2010-12-02 23:34:41 +00:00
return $result;
} catch (SQLException $sqle) {
$con->rollback();
throw $sqle;
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Sorts a grid according to a specified field in ascending or descending order.
2010-12-02 23:34:41 +00:00
*
* @name orderGrid
* @label order Grid
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#orderGrid.28.29
*
2012-10-09 12:56:31 -04:00
* @param array | $dataM | User ID | A grid, which is a numbered array containing associative arrays with field names and their values, it has to be set like this "@=".
2010-12-02 23:34:41 +00:00
* @param string(32) | $field | Name of field | The name of the field by which the grid will be sorted.
* @param string(32) | $ord = "ASC"| Optional parameter | Optional parameter. The order which can either be 'ASC' (ascending) or 'DESC' (descending). If not included, 'ASC' will be used by default.
* @return array | $dataM | Grid Sorted | Grid sorted
*
*/
2012-10-09 12:56:31 -04:00
function orderGrid ($dataM, $field, $ord = 'ASC')
{
2012-10-09 12:56:31 -04:00
if (! is_array( $dataM ) or ! isset( $field ) or $field == '') {
throw new Exception( 'function:orderGrid Error!, bad parameters found!' );
}
2012-10-09 12:56:31 -04:00
for ($i = 1; $i <= count( $dataM ) - 1; $i ++) {
for ($j = $i + 1; $j <= count( $dataM ); $j ++) {
if (strtoupper( $ord ) == 'ASC') {
if (strtolower( $dataM[$j][$field] ) < strtolower( $dataM[$i][$field] )) {
$swap = $dataM[$i];
$dataM[$i] = $dataM[$j];
$dataM[$j] = $swap;
}
} else {
if ($dataM[$j][$field] > $dataM[$i][$field]) {
2012-10-09 12:56:31 -04:00
$swap = $dataM[$i];
$dataM[$i] = $dataM[$j];
$dataM[$j] = $swap;
}
}
2010-12-02 23:34:41 +00:00
}
}
return $dataM;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Executes operations among the grid fields, such as addition, substraction, etc
2010-12-02 23:34:41 +00:00
*
* @name evaluateFunction
* @label evaluate Function
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#evaluateFunction.28.29
*
* @param array | $aGrid | Grid | The input grid.
* @param string(32) | $sExpresion | Expression for the operation | The input expression for the operation among grid fields. The expression must always be within double quotes, otherwise a fatal error will occur.
2010-12-02 23:34:41 +00:00
* @return array | $aGrid | Grid | Grid with executed operation
*
*/
2012-10-09 12:56:31 -04:00
function evaluateFunction ($aGrid, $sExpresion)
{
2012-10-09 12:56:31 -04:00
$sExpresion = str_replace( 'Array', '$this->aFields', $sExpresion );
$sExpresion .= ';';
2012-10-09 12:56:31 -04:00
G::LoadClass( 'pmScript' );
$pmScript = new PMScript();
2012-10-09 12:56:31 -04:00
$pmScript->setScript( $sExpresion );
2010-12-02 23:34:41 +00:00
2012-10-09 12:56:31 -04:00
for ($i = 1; $i <= count( $aGrid ); $i ++) {
$aFields = $aGrid[$i];
2010-12-02 23:34:41 +00:00
2012-10-09 12:56:31 -04:00
$pmScript->setFields( $aFields );
2010-12-02 23:34:41 +00:00
$pmScript->execute();
2010-12-02 23:34:41 +00:00
$aGrid[$i] = $pmScript->aFields;
}
return $aGrid;
2010-12-02 23:34:41 +00:00
}
/**
2012-10-09 12:56:31 -04:00
* Web Services Functions *
*/
/**
2010-12-02 23:34:41 +00:00
*
* @method
*
* Logs in a user to initiate a web services session in a ProcessMaker server.
2010-12-02 23:34:41 +00:00
*
* @name WSLogin
* @label WS Login
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSLogin.28.29
*
* @param string(32) | $user | Username of the user | The username of the user who will login to ProcessMaker. All subsequent actions will be limited to the permissions of that user.
* @param string(32) | $pass | Password encrypted | The user's password encrypted as an MD5 or SHA256 hash with '{hashType}:' prepended.
2010-12-02 23:34:41 +00:00
* @param string(32) | $endpoint="" | URI of the WSDL | The URI (address) of the WSDL definition of the ProcessMaker web services.
* @return string | $unique ID | Unique Id |The unique ID for the initiated session.
*
*/
2012-10-09 12:56:31 -04:00
function WSLogin ($user, $pass, $endpoint = "")
{
2012-10-09 12:56:31 -04:00
$client = WSOpen( true );
2012-10-09 12:56:31 -04:00
$params = array ("userid" => $user,"password" => $pass
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "login", array ($params
) );
if ($result->status_code == 0) {
if ($endpoint != "") {
2012-10-09 12:56:31 -04:00
if (isset( $_SESSION["WS_SESSION_ID"] )) {
$_SESSION["WS_END_POINT"] = $endpoint;
}
}
/*
if (isset($_SESSION["WS_SESSION_ID"]))
return $_SESSION["WS_SESSION_ID"] = $result->message;
else
return $result->message;
*/
$_SESSION["WS_SESSION_ID"] = $result->message;
return $result->message;
} else {
2012-10-09 12:56:31 -04:00
if (isset( $_SESSION["WS_SESSION_ID"] )) {
unset( $_SESSION["WS_SESSION_ID"] );
}
2012-10-09 12:56:31 -04:00
$wp = (trim( $pass ) != "") ? "YES" : "NO";
2012-10-09 12:56:31 -04:00
throw new Exception( "WSAccess denied! for user $user with password $wp" );
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Opens a connection for web services and returns a SOAP client object which is
2010-12-02 23:34:41 +00:00
* used by all subsequent other WS function calls
*
* @name WSOpen
* @label WS Open
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSOpen.28.29
*
* @param boolean | $force=false | Optional Parameter | Optional parameter. Set to true to force a new connection to be created even if a valid connection already exists.
* @return Object Client | $client | SoapClient object | A SoapClient object. If unable to establish a connection, returns NULL.
*
*/
2012-10-09 12:56:31 -04:00
function WSOpen ($force = false)
{
2012-10-09 12:56:31 -04:00
if (isset( $_SESSION["WS_SESSION_ID"] ) || $force) {
if (! isset( $_SESSION["WS_END_POINT"] )) {
$defaultEndpoint = "http://" . $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . "/sys" . SYS_SYS . "/en/classic/services/wsdl2";
}
2012-10-09 12:56:31 -04:00
$endpoint = isset( $_SESSION["WS_END_POINT"] ) ? $_SESSION["WS_END_POINT"] : $defaultEndpoint;
2012-10-09 12:56:31 -04:00
$client = new SoapClient( $endpoint );
return $client;
} else {
2012-10-09 12:56:31 -04:00
throw new Exception( "WS session is not open" );
2010-12-02 23:34:41 +00:00
}
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns all the tasks which has open delegations for the indicated case.
2010-12-02 23:34:41 +00:00
*
* @name WSTaskCase
* @label WS Task Case
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSTaskCase.28.29
*
* @param string(32) | $caseId | Case ID | The unique ID for the case. Case UIDs can be found with WSCaseList() and are stored in the field wf_<WORKSPACE>.APPLICATION.APP_UID.
* @return array | $rows | Array of tasks open | An array of tasks in the indicated case which have open delegations.
*
*/
2012-10-09 12:56:31 -04:00
function WSTaskCase ($caseId)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"caseId" => $caseId
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "taskCase", array ($params
) );
2012-10-09 12:56:31 -04:00
$rows = array ();
$i = 0;
2012-10-09 12:56:31 -04:00
if (isset( $result->taskCases )) {
//Processing when it is an array
2012-10-09 12:56:31 -04:00
if (is_array( $result->taskCases )) {
foreach ($result->taskCases as $key => $obj) {
2012-10-09 12:56:31 -04:00
$rows[$i] = array ("guid" => $obj->guid,"name" => $obj->name
);
$i = $i + 1;
}
} else {
//Processing when it is an object //1 row
2012-10-09 12:56:31 -04:00
if (is_object( $result->taskCases )) {
$rows[$i] = array ("guid" => $result->taskCases->guid,"name" => $result->taskCases->name
);
$i = $i + 1;
}
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a list of tasks in which the logged-in user can initiate cases or is
2010-12-02 23:34:41 +00:00
* assigned to these cases.
*
* @name WSTaskList
* @label WS Task List
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSTaskList.28.29
*
* @return array | $rows |List of tasks | This function returns a list of tasks
*
*/
2012-10-09 12:56:31 -04:00
function WSTaskList ()
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "TaskList", array ($params
) );
2012-10-09 12:56:31 -04:00
$rows = array ();
$i = 0;
2012-10-09 12:56:31 -04:00
if (isset( $result->tasks )) {
//Processing when it is an array
2012-10-09 12:56:31 -04:00
if (is_array( $result->tasks )) {
foreach ($result->tasks as $key => $obj) {
2012-10-09 12:56:31 -04:00
$rows[$i] = array ("guid" => $obj->guid,"name" => $obj->name
);
$i = $i + 1;
}
} else {
//Processing when it is an object //1 row
2012-10-09 12:56:31 -04:00
if (is_object( $result->tasks )) {
$rows[$i] = array ("guid" => $result->tasks->guid,"name" => $result->tasks->name
);
$i = $i + 1;
}
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a list of users whose status is "ACTIVE" in the current workspace.
2010-12-02 23:34:41 +00:00
*
* @name WSUserList
* @label WS User List
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSUserList.28.29
*
* @return array | $rows | List | List of Active users in the workspace
*
*/
2012-10-09 12:56:31 -04:00
function WSUserList ()
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "UserList", array ($params
) );
2012-10-09 12:56:31 -04:00
$rows = array ();
$i = 0;
2012-10-09 12:56:31 -04:00
if (isset( $result->users )) {
//Processing when it is an array
2012-10-09 12:56:31 -04:00
if (is_array( $result->users )) {
foreach ($result->users as $key => $obj) {
2012-10-09 12:56:31 -04:00
$rows[$i] = array ("guid" => $obj->guid,"name" => $obj->name
);
$i = $i + 1;
}
} else {
//Processing when it is an object //1 row
2012-10-09 12:56:31 -04:00
if (is_object( $result->users )) {
$rows[$i] = array ("guid" => $result->users->guid,"name" => $result->users->name
);
$i = $i + 1;
}
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a list of active groups in a workspace.
2010-12-02 23:34:41 +00:00
*
* @name WSGroupList
* @label WS Group List
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSGroupList.28.29
*
* @return array | $rows | List | List of active groups in the workspace
*
*/
2012-10-09 12:56:31 -04:00
function WSGroupList ()
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "GroupList", array ($params
) );
2012-10-09 12:56:31 -04:00
$rows = array ();
$i = 0;
2012-10-09 12:56:31 -04:00
if (isset( $result->groups )) {
//Processing when it is an array
2012-10-09 12:56:31 -04:00
if (is_array( $result->groups )) {
foreach ($result->groups as $key => $obj) {
2012-10-09 12:56:31 -04:00
$rows[$i] = array ("guid" => $obj->guid,"name" => $obj->name
);
$i = $i + 1;
}
} else {
//Processing when it is an object //1 row
2012-10-09 12:56:31 -04:00
if (is_object( $result->groups )) {
$rows[$i] = array ("guid" => $result->groups->guid,"name" => $result->groups->name
);
$i = $i + 1;
}
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
/**
*
* @method
*
* Returns a list of roles in the current workspace.
2010-12-02 23:34:41 +00:00
*
* @name WSRoleList
* @label WS Role List
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSRoleList.28.29
*
* @return array | $rows | List | List of roles in the workspace
*
*/
2012-10-09 12:56:31 -04:00
function WSRoleList ()
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "RoleList", array ($params
) );
2012-10-09 12:56:31 -04:00
$rows = array ();
$i = 0;
2012-10-09 12:56:31 -04:00
if (isset( $result->roles )) {
//Processing when it is an array
2012-10-09 12:56:31 -04:00
if (is_array( $result->roles )) {
foreach ($result->roles as $key => $obj) {
2012-10-09 12:56:31 -04:00
$rows[$i] = array ("guid" => $obj->guid,"name" => $obj->name
);
$i = $i + 1;
}
} else {
//Processing when it is an object //1 row
2012-10-09 12:56:31 -04:00
if (is_object( $result->roles )) {
$rows[$i] = array ("guid" => $result->roles->guid,"name" => $result->roles->name
);
$i = $i + 1;
}
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a list of the cases which the current logged-in user has privileges to
2010-12-02 23:34:41 +00:00
* open.
*
* @name WSCaseList
* @label WS Case List
2012-10-09 12:56:31 -04:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSCaseList.28.29
2010-12-02 23:34:41 +00:00
*
* @return array | $rows | List of the cases |It returns a list of cases
*
*/
2012-10-09 12:56:31 -04:00
function WSCaseList ()
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "CaseList", array ($params
) );
2012-10-09 12:56:31 -04:00
$rows = array ();
$i = 0;
2012-10-09 12:56:31 -04:00
if (isset( $result->cases )) {
//Processing when it is an array
2012-10-09 12:56:31 -04:00
if (is_array( $result->cases )) {
foreach ($result->cases as $key => $obj) {
2012-10-09 12:56:31 -04:00
$rows[$i] = array ("guid" => $obj->guid,"name" => $obj->name
);
$i = $i + 1;
}
} else {
//Processing when it is an object //1 row
2012-10-09 12:56:31 -04:00
if (is_object( $result->cases )) {
$rows[$i] = array ("guid" => $result->cases->guid,"name" => $result->cases->name
);
$i = $i + 1;
}
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a list of processes in the current workspace.
2010-12-02 23:34:41 +00:00
*
* @name WSProcessList
* @label WS Process List
2012-10-09 12:56:31 -04:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSProcessList.28.29
2010-12-02 23:34:41 +00:00
*
* @return array | $rows | List of processes | A list of processes
*
*/
2012-10-09 12:56:31 -04:00
function WSProcessList ()
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "ProcessList", array ($params
) );
2012-10-09 12:56:31 -04:00
$rows = array ();
$i = 0;
2012-10-09 12:56:31 -04:00
if (isset( $result->processes )) {
//Processing when it is an array
2012-10-09 12:56:31 -04:00
if (is_array( $result->processes )) {
foreach ($result->processes as $key => $obj) {
2012-10-09 12:56:31 -04:00
$rows[$i] = array ("guid" => $obj->guid,"name" => $obj->name
);
$i = $i + 1;
}
} else {
//Processing when it is an object //1 row
2012-10-09 12:56:31 -04:00
if (is_object( $result->processes )) {
$rows[$i] = array ("guid" => $result->processes->guid,"name" => $result->processes->name
);
$i = $i + 1;
}
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns Email configuration.
2010-12-02 23:34:41 +00:00
*
* @name getEmailConfiguration
* @label Get Email Configuration
2010-12-02 23:34:41 +00:00
*
* @return array | $aFields | Array |Get current email configuration
*
*/
//private function to get current email configuration
2012-10-09 12:56:31 -04:00
function getEmailConfiguration ()
{
2012-10-09 12:56:31 -04:00
G::loadClass( 'system' );
return System::getEmailConfiguration();
2010-12-02 23:34:41 +00:00
}
/**
*
* @method
*
* Sends an email using a template file.
2010-12-02 23:34:41 +00:00
*
* @name PMFSendMessage
* @label PMF Send Message
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFSendMessage.28.29
*
* @param string(32) | $caseId | UID for case | The UID (unique identification) for a case, which is a string of 32 hexadecimal characters to identify the case.
* @param string(32) | $sFrom | Email address | The email address of the person who sends out the email.
* @param string(100) | $sTo | Email receptor | The email address(es) to whom the email is sent. If multiple recipients, separate each email address with a comma.
* @param string(100) | $sCc = '' | Email address for copies | The email address(es) of people who will receive carbon copies of the email.
* @param string(100) | $sBcc = ''| Email address for copies hidden | The email address(es) of people who will receive blind carbon copies of the email.
* @param string(50) | $sSubject | Subject of the email | The subject (title) of the email.
* @param string(50) | $sTemplate | Name of the template | The name of the template file in plain text or HTML format which will produce the body of the email.
* @param array | $aFields = array() | An optional associative array | Optional parameter. An associative array where the keys are the variable names and the values are the variables' values.
* @param array | $aAttachment = array() | Attachment | An Optional arrray. An array of files (full paths) to be attached to the email.
* @param boolean | $showMessage = true | Show message | Optional parameter.
* @param int | $delIndex = 0 | Delegation index of the case | Optional parameter. The delegation index of the current task in the case.
* @param array | $config = array() | Alternative Email Settings | An optional array: An array of parameters to be used in the Email sent (MESS_ENGINE, MESS_SERVER, MESS_PORT, MESS_FROM_MAIL, MESS_RAUTH, MESS_ACCOUNT, MESS_PASSWORD, and SMTPSecure).
* @return int | | result | Result of sending email
2010-12-02 23:34:41 +00:00
*
*/
//@param array | $aFields=array() | An associative array optional | Optional parameter. An associative array where the keys are the variable name and the values are the variable's value.
function PMFSendMessage(
$caseId,
$sFrom,
$sTo,
$sCc,
$sBcc,
$sSubject,
$sTemplate,
$aFields = array(),
$aAttachment = array(),
$showMessage = true,
$delIndex = 0,
$config = array()
) {
ini_set ( "pcre.backtrack_limit", 1000000 );
ini_set ( 'memory_limit', '-1' );
@set_time_limit ( 100000 );
global $oPMScript;
2012-10-09 12:56:31 -04:00
if (isset( $oPMScript->aFields ) && is_array( $oPMScript->aFields )) {
if (is_array( $aFields )) {
$aFields = array_merge( $oPMScript->aFields, $aFields );
} else {
$aFields = $oPMScript->aFields;
}
}
G::LoadClass("wsBase");
2012-10-09 12:56:31 -04:00
$ws = new wsBase();
$result = $ws->sendMessage(
$caseId,
$sFrom,
$sTo,
$sCc,
$sBcc,
$sSubject,
$sTemplate,
$aFields,
$aAttachment,
$showMessage,
$delIndex,
$config
);
2012-10-09 12:56:31 -04:00
if ($result->status_code == 0) {
return 1;
} else {
error_log($result->message);
return 0;
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Sends two variables to the specified case.
2010-12-02 23:34:41 +00:00
* It will create new case variables if they don't already exist
*
* @name WSSendVariables
* @label WS Send Variables
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSSendVariables.28.29
*
* @param string(32) | $caseId | UID for case | The unique ID of the case which will receive the variables.
* @param string(32) | $name1 | Name of the first variable | The name of the first variable to be sent to the created case.
* @param string(32) | $value1 | Value of the first variable | The value of the first variable to be sent to the created case.
* @param string(32) | $name2 | Name of the second variable | The name of the second variable to be sent to the created case.
* @param string(32) | $value2 | Value of the second variable | The value of the second variable to be sent to the created case.
* @return array | $fields | WS Response Associative Array: | The function returns a WS Response associative array.
*
*/
2012-10-09 12:56:31 -04:00
function WSSendVariables ($caseId, $name1, $value1, $name2, $value2)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
$v1 = new stdClass();
$v1->name = $name1;
$v1->value = $value1;
$v2 = new stdClass();
$v2->name = $name2;
$v2->value = $value2;
2012-10-09 12:56:31 -04:00
$variables = array ($v1,$v2
);
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"caseId" => $caseId,"variables" => $variables
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "SendVariables", array ($params
) );
$fields["status_code"] = $result->status_code;
2012-10-09 12:56:31 -04:00
$fields["message"] = $result->message;
$fields["time_stamp"] = $result->timestamp;
return $fields;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Routes (derivates) a case, moving the case to the next task in the process
2010-12-02 23:34:41 +00:00
* according its routing rules.
*
* @name WSDerivateCase
* @label WS Derivate Case
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSDerivateCase.28.29
*
* @param string(32) | $CaseId | Case ID |The unique ID for a case, which can be found with WSCaseList() or by examining the field wf_<WORKSPACE>.APPLICATION.APP_UID.
* @param string(32) | $delIndex | Delegation index for the task | The delegation index for the task, which can be found by examining the field wf_<WORKSPACE>.APP_DELEGATION.DEL_INDEX.
* @return array | $fields | WS Response Associative Array | A WS Response associative array.
*
*/
2012-10-09 12:56:31 -04:00
function WSDerivateCase ($caseId, $delIndex)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"caseId" => $caseId,"delIndex" => $delIndex
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "DerivateCase", array ($params
) );
$fields["status_code"] = $result->status_code;
2012-10-09 12:56:31 -04:00
$fields["message"] = $result->message;
$fields["time_stamp"] = $result->timestamp;
return $fields;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Creates a case with any user with two initial case variables.
2010-12-02 23:34:41 +00:00
*
* @name WSNewCaseImpersonate
* @label WS New Case Impersonate
2012-10-09 12:56:31 -04:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSNewCaseImpersonate.28.29
2010-12-02 23:34:41 +00:00
*
* @param string(32) | $processId | Process ID | The unique ID for the process.
* @param string(32) | $userId | User ID | The unique ID for the user.
2012-10-09 12:56:31 -04:00
* @param string(32) | $name1 | Name of the first variable | The name of the first variable to be sent to the created case.
2010-12-02 23:34:41 +00:00
* @param string(32) | $value1 | Value of the first variable | The value of the first variable to be sent to the created case.
* @param string(32) | $name2 | Name of the second variable | The name of the second variable to be sent to the created case.
* @param string(32) | $value2 | Value of the second variable | The value of the second variable to be sent to the created case.
* @return array | $fields | WS Response Associative Array | A WS Response associative array.
*
*/
2012-10-09 12:56:31 -04:00
function WSNewCaseImpersonate ($processId, $userId, $name1, $value1, $name2, $value2)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
$v1 = new stdClass();
$v1->name = $name1;
$v1->value = $value1;
$v2 = new stdClass();
$v2->name = $name2;
$v2->value = $value2;
2012-10-09 12:56:31 -04:00
$variables = array ($v1,$v2
);
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"processId" => $processId,"userId" => $userId,"variables" => $variables
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "NewCaseImpersonate", array ($params
) );
$fields["status_code"] = $result->status_code;
2012-10-09 12:56:31 -04:00
$fields["message"] = $result->message;
$fields["time_stamp"] = $result->timestamp;
$fields["case_id"] = $result->caseId;
$fields["case_number"] = $result->caseNumber;
return $fields;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Creates a new case starting with a specified task and using two initial case
2010-12-02 23:34:41 +00:00
* variables.
*
* @name WSNewCase
* @label WS New Case
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSNewCase.28.29
*
* @param string(32) | $processId | Process ID | The unique ID for the process. To use the current process, use the system variable @@PROCESS.
* @param string(32) | $userId | User ID | The unique ID for the user. To use the currently logged-in user, use the system variable @@USER_LOGGED.
2012-10-09 12:56:31 -04:00
* @param string(32) | $name1 | Name of the first variable | The name of the first variable to be sent to the created case.
2010-12-02 23:34:41 +00:00
* @param string(32) | $value1 | Value of the first variable | The value of the first variable to be sent to the created case.
* @param string(32) | $name2 | Name of the second variable | The name of the second variable to be sent to the created case.
* @param string(32) | $value2 | Value of the second variable | The value of the second variable to be sent to the created case.
* @return array | $fields | WS array | A WS Response associative array.
*
*/
2012-10-09 12:56:31 -04:00
function WSNewCase ($processId, $taskId, $name1, $value1, $name2, $value2)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
$v1 = new stdClass();
$v1->name = $name1;
$v1->value = $value1;
$v2 = new stdClass();
$v2->name = $name2;
$v2->value = $value2;
2012-10-09 12:56:31 -04:00
$variables = array ($v1,$v2
);
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"processId" => $processId,"taskId" => $taskId,"variables" => $variables
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "NewCase", array ($params
) );
$fields["status_code"] = $result->status_code;
2012-10-09 12:56:31 -04:00
$fields["message"] = $result->message;
$fields["time_stamp"] = $result->timestamp;
$fields["case_id"] = $result->caseId;
$fields["case_number"] = $result->caseNumber;
return $fields;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Assigns a user to a group (as long as the logged in user has the PM_USERS
2010-12-02 23:34:41 +00:00
* permission in their role).
*
* @name WSAssignUserToGroup
* @label WS Assign User To Group
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSAssignUserToGroup.28.29
*
* @param string(32) | $userId | User ID | The unique ID for a user.
* @param string(32) | $groupId | Group ID | The unique ID for a group.
* @return array | $fields | WS array |A WS Response associative array.
*
*/
2012-10-09 12:56:31 -04:00
function WSAssignUserToGroup ($userId, $groupId)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"userId" => $userId,"groupId" => $groupId
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "AssignUserToGroup", array ($params
) );
$fields["status_code"] = $result->status_code;
2012-10-09 12:56:31 -04:00
$fields["message"] = $result->message;
$fields["time_stamp"] = $result->timestamp;
return $fields;
2010-12-02 23:34:41 +00:00
}
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Creates a new user in ProcessMaker.
2010-12-02 23:34:41 +00:00
*
* @name WSCreateUser
* @label WS Create User
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSCreateUser.28.29
*
* @param string(32) | $userId | User ID | The username of the new user, which can be up to 32 characters long.
* @param string(32) | $password | Password of the new user | El password of the new user, which can be up to 32 characters long.
* @param string(32) | $firstname | Firstname of the new user | The first name(s) of the new user, which can be up to 50 characters long.
* @param string(32) | $lastname | Lastname of the new user | The last name(s) of the new user, which can be up to 50 characters long.
* @param string(32) | $email | Email the new user | The e-mail of the new user, which can be up to 100 characters long.
* @param string(32) | $role | Rol of the new user | The role of the new user, such as "PROCESSMAKER_ADMIN" and "PROCESSMAKER_OPERATOR".
* @param string(32) | $dueDate=null | Expiration date | Optional parameter. The expiration date must be a string in the format "yyyy-mm-dd".
* @param string(32) | $status=null | Status of the new user | Optional parameter. The user's status, such as "ACTIVE", "INACTIVE" or "VACATION".
2010-12-02 23:34:41 +00:00
* @return array | $fields | WS array | A WS Response associative array.
*
*/
2012-10-09 12:56:31 -04:00
function WSCreateUser ($userId, $password, $firstname, $lastname, $email, $role, $dueDate = null, $status = null)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"userId" => $userId,"firstname" => $firstname,"lastname" => $lastname,"email" => $email,"role" => $role,"password" => $password,"dueDate" => $dueDate,"status" => $status
);
2013-03-20 10:58:19 -04:00
try {
$result = $client->__soapCall( "CreateUser", array ($params) );
} catch(Exception $oError) {
return $oError->getMessage();
}
$fields["status_code"] = $result->status_code;
2012-10-09 12:56:31 -04:00
$fields["message"] = $result->message;
$fields["time_stamp"] = $result->timestamp;
return $fields;
2010-12-02 23:34:41 +00:00
}
/**
*
* @method
*
* Update an user in ProcessMaker.
*
* @name WSUpdateUser
* @label WS Update User
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSUpdateUser.28.29
*
* @param string(32) | $userUid | User UID | The user UID.
* @param string(32) | $userName | User ID | The username for the user.
* @param string(32) | $firstName=null | Firstname of the user | Optional parameter. The first name of the user, which can be up to 50 characters long.
* @param string(32) | $lastName=null | Lastname of the user | Optional parameter. The last name of the user, which can be up to 50 characters long.
* @param string(32) | $email=null | Email the user | Optional parameter. The email of the user, which can be up to 100 characters long.
* @param string(32) | $dueDate=null | Expiration date | Optional parameter. The expiration date must be a string in the format "yyyy-mm-dd".
* @param string(32) | $status=null | Status of the user | Optional parameter. The user's status, such as "ACTIVE", "INACTIVE" or "VACATION".
* @param string(32) | $role=null | Rol of the user | The role of the user such as "PROCESSMAKER_ADMIN" or "PROCESSMAKER_OPERATOR".
* @param string(32) | $password=null | Password of the user | The password of the user, which can be up to 32 characters long.
* @return array | $fields | WS array | A WS Response associative array.
*
*/
2012-10-09 12:56:31 -04:00
function WSUpdateUser ($userUid, $userName, $firstName = null, $lastName = null, $email = null, $dueDate = null, $status = null, $role = null, $password = null)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"userUid" => $userUid,"userName" => $userName,"firstName" => $firstName,"lastName" => $lastName,"email" => $email,"dueDate" => $dueDate,"status" => $status,"role" => $role,"password" => $password
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "updateUser", array ($params
) );
$fields["status_code"] = $result->status_code;
2012-10-09 12:56:31 -04:00
$fields["message"] = $result->message;
$fields["time_stamp"] = $result->timestamp;
return $fields;
}
/**
*
* @method
*
* Retrieves information about a user with a given ID.
*
* @name WSInformationUser
* @label WS Information User
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSInformationUser.28.29
*
* @param string(32) | $userUid | User UID | The user UID.
* @return array | $response | WS array | A WS Response associative array.
*
*/
function WSInformationUser($userUid)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
$params = array(
"sessionId" => $sessionId,
"userUid" => $userUid
);
$result = $client->__soapCall("informationUser", array($params));
$response = array();
$response["status_code"] = $result->status_code;
$response["message"] = $result->message;
$response["time_stamp"] = $result->timestamp;
$response["info"] = (isset($result->info))? $result->info : null;
return $response;
}
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns the unique ID for the current active session.
2010-12-02 23:34:41 +00:00
*
* @name WSGetSession
* @label WS Get Session
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSGetSession.28.29
*
* @return string | $userId | Sesion ID | The unique ID for the current active session.
*
*/
2012-10-09 12:56:31 -04:00
function WSGetSession ()
{
2012-10-09 12:56:31 -04:00
if (isset( $_SESSION["WS_SESSION_ID"] )) {
return $_SESSION["WS_SESSION_ID"];
} else {
2012-10-09 12:56:31 -04:00
throw new Exception( "SW session is not open!" );
}
2010-12-02 23:34:41 +00:00
}
/**
*
* @method
*
* Delete a specified case.
*
* @name WSDeleteCase
* @label WS Delete Case
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSDeleteCase.28.29
*
* @param string(32) | $caseUid | ID of the case | The unique ID of the case.
* @return array | $response | WS array | A WS Response associative array.
*
*/
2012-10-09 12:56:31 -04:00
function WSDeleteCase ($caseUid)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"caseUid" => $caseUid
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "deleteCase", array ($params
) );
2012-10-09 12:56:31 -04:00
$response = array ();
$response["status_code"] = $result->status_code;
2012-10-09 12:56:31 -04:00
$response["message"] = $result->message;
$response["time_stamp"] = $result->timestamp;
return $response;
}
/**
*
* @method
*
* Cancel a specified case.
*
* @name WSCancelCase
* @label WS Cancel Case
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSCancelCase.28.29
*
* @param string(32) | $caseUid | ID of the case | The unique ID of the case.
* @param int | $delIndex | Delegation index of the case | The delegation index of the current task in the case.
* @param string(32) | $userUid | ID user | The unique ID of the user who will cancel the case.
* @return array | $response | WS array | A WS Response associative array.
*
*/
2012-10-09 12:56:31 -04:00
function WSCancelCase ($caseUid, $delIndex, $userUid)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"caseUid" => $caseUid,"delIndex" => $delIndex,"userUid" => $userUid
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "cancelCase", array ($params
) );
2012-10-09 12:56:31 -04:00
$response = array ();
$response["status_code"] = $result->status_code;
2012-10-09 12:56:31 -04:00
$response["message"] = $result->message;
$response["time_stamp"] = $result->timestamp;
return $response;
}
/**
*
* @method
*
* Pauses a specified case.
*
* @name WSPauseCase
* @label WS Pause Case
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSPauseCase.28.29
*
* @param string(32) | $caseUid | ID of the case | The unique ID of the case.
* @param int | $delIndex | Delegation index of the case | The delegation index of the current task in the case.
* @param string(32) | $userUid | ID user | The unique ID of the user who will pause the case.
* @param string(32) | $unpauseDate=null | Date | Optional parameter. The date in the format "yyyy-mm-dd" indicating when to unpause the case.
* @return array | $response | WS array | A WS Response associative array.
*
*/
2012-10-09 12:56:31 -04:00
function WSPauseCase ($caseUid, $delIndex, $userUid, $unpauseDate = null)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"caseUid" => $caseUid,"delIndex" => $delIndex,"userUid" => $userUid,"unpauseDate" => $unpauseDate
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "pauseCase", array ($params
) );
2012-10-09 12:56:31 -04:00
$response = array ();
$response["status_code"] = $result->status_code;
2012-10-09 12:56:31 -04:00
$response["message"] = $result->message;
$response["time_stamp"] = $result->timestamp;
return $response;
}
/**
*
* @method
*
* Unpause a specified case.
*
* @name WSUnpauseCase
* @label WS Unpause Case
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSUnpauseCase.28.29
*
* @param string(32) | $caseUid | ID of the case | The unique ID of the case.
* @param int | $delIndex | Delegation index of the case | The delegation index of the current task in the case.
* @param string(32) | $userUid | ID user | The unique ID of the user who will unpause the case.
* @return array | $response | WS array | A WS Response associative array.
*
*/
2012-10-09 12:56:31 -04:00
function WSUnpauseCase ($caseUid, $delIndex, $userUid)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
2012-10-09 12:56:31 -04:00
$params = array ("sessionId" => $sessionId,"caseUid" => $caseUid,"delIndex" => $delIndex,"userUid" => $userUid
);
2012-10-09 12:56:31 -04:00
$result = $client->__soapCall( "unpauseCase", array ($params
) );
2012-10-09 12:56:31 -04:00
$response = array ();
$response["status_code"] = $result->status_code;
2012-10-09 12:56:31 -04:00
$response["message"] = $result->message;
$response["time_stamp"] = $result->timestamp;
return $response;
}
/**
*
* @method
*
* Add case note.
*
* @name WSAddCaseNote
* @label WS Add case note
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#WSAddCaseNote.28.29
*
* @param string(32) | $caseUid | ID of the case | The unique ID of the case.
* @param string(32) | $processUid | ID of the process | The unique ID of the process.
* @param string(32) | $taskUid | ID of the task | The unique ID of the task.
* @param string(32) | $userUid | ID user | The unique ID of the user who will add note case.
* @param string | $note | Note of the case | Note of the case.
* @param int | $sendMail = 1 | Send mail | Optional parameter. If set to 1, will send an email to all participants in the case.
* @return array | $response | WS array | A WS Response associative array.
*
*/
function WSAddCaseNote($caseUid, $processUid, $taskUid, $userUid, $note, $sendMail = 1)
{
$client = WSOpen();
$sessionId = $_SESSION["WS_SESSION_ID"];
$params = array(
"sessionId" => $sessionId,
"caseUid" => $caseUid,
"processUid" => $processUid,
"taskUid" => $taskUid,
"userUid" => $userUid,
"note" => $note,
"sendMail" => $sendMail
);
$result = $client->__soapCall("addCaseNote", array($params));
$response = array();
$response["status_code"] = $result->status_code;
$response["message"] = $result->message;
$response["time_stamp"] = $result->timestamp;
return $response;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2010-12-02 23:34:41 +00:00
/**
2012-10-09 12:56:31 -04:00
* Local Services Functions *
*/
/**
2010-12-02 23:34:41 +00:00
*
* @method
*
* Returns all the tasks for the specified case which have open delegations.
2010-12-02 23:34:41 +00:00
*
* @name PMFTaskCase
* @label PMF Task Case
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFTaskCase.28.29
*
* @param string(32) | $caseId | Case ID | The unique ID for a case.
* @return array | $rows | List of tasks | A list of tasks
*
*/
2012-10-09 12:56:31 -04:00
function PMFTaskCase ($caseId) //its test was successfull
2010-12-02 23:34:41 +00:00
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
$result = $ws->taskCase( $caseId );
$rows = Array ();
$i = 1;
2012-10-09 12:56:31 -04:00
if (isset( $result )) {
foreach ($result as $item) {
2012-10-09 12:56:31 -04:00
$rows[$i ++] = $item;
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a list of tasks which the specified user has initiated.
2010-12-02 23:34:41 +00:00
*
* @name PMFTaskList
* @label PMF Task List
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFTaskList.28.29
*
* @param string(32) | $userid | User ID | The unique ID of a user.
* @return array | $rows | List of tasks | An array of tasks
*
*/
2012-10-09 12:56:31 -04:00
function PMFTaskList ($userId) //its test was successfull
2010-12-02 23:34:41 +00:00
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
$result = $ws->taskList( $userId );
$rows = Array ();
$i = 1;
2012-10-09 12:56:31 -04:00
if (isset( $result )) {
foreach ($result as $item) {
2012-10-09 12:56:31 -04:00
$rows[$i ++] = $item;
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a list of users whose status is set to "ACTIVE" for the current workspace.
2010-12-02 23:34:41 +00:00
*
* @name PMFUserList
* @label PMF User List
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFUserList.28.29
*
* @return array | $rows | List of users | An array of users
*
*/
2012-10-09 12:56:31 -04:00
function PMFUserList () //its test was successfull
2010-12-02 23:34:41 +00:00
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
$result = $ws->userList();
2012-10-09 12:56:31 -04:00
$rows = Array ();
$i = 1;
if (isset( $result )) {
foreach ($result as $item) {
2012-10-09 12:56:31 -04:00
$rows[$i ++] = $item;
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
/**
* @method
*
* Add a input document.
*
* @name PMFAddInputDocument
* @label PMF Add a input document
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFAddInputDocument.28.29
*
* @param string(32) | $inputDocumentUid | ID of the input document | The unique ID of the input document.
* @param string(32) | $appDocUid | ID of the application document | The unique ID of the application document; if action is set to null or empty (Add), then this parameter it set to null or empty.
* @param int | $docVersion | Document version | Document version.
* @param string | $appDocType = "INPUT" | Document type | Document type.
* @param string | $appDocComment | Document comment | Document comment.
* @param string | $inputDocumentAction | Action | Action, posible values: null or empty (Add), "R" (Replace), "NV" (New Version).
* @param string(32) | $caseUid | ID of the case | The unique ID of the case.
* @param int | $delIndex | Delegation index of the case | The delegation index of the current task in the case.
* @param string(32) | $taskUid | ID of the task | The unique ID of the task.
* @param string(32) | $userUid | ID user | The unique ID of the user who will add a input document.
* @param string | $option = "file" | Option | Option, value: "file".
* @param string | $file = "path_to_file/myfile.txt" | File, path to file | File, path to file.
* @return string | $appDocUid | ID of the application document | Returns ID if it has added the input document successfully; otherwise, returns null or empty if an error occurred.
*
*/
function PMFAddInputDocument(
$inputDocumentUid,
$appDocUid,
$docVersion,
$appDocType = "INPUT",
$appDocComment,
$inputDocumentAction,
$caseUid,
$delIndex,
$taskUid,
$userUid,
$option = "file",
$file = "path_to_file/myfile.txt"
) {
G::LoadClass("case");
$g = new G();
$g->sessionVarSave();
$_SESSION["APPLICATION"] = $caseUid;
$_SESSION["INDEX"] = $delIndex;
$_SESSION["TASK"] = $taskUid;
$_SESSION["USER_LOGGED"] = $userUid;
$case = new Cases();
$appDocUid = $case->addInputDocument(
$inputDocumentUid,
$appDocUid,
$docVersion,
$appDocType,
$appDocComment,
$inputDocumentAction,
$caseUid,
$delIndex,
$taskUid,
$userUid,
$option,
$file
);
$g->sessionVarRestore();
return $appDocUid;
}
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Generates an Output Document
2010-12-02 23:34:41 +00:00
*
* @name PMFGenerateOutputDocument
* @label PMF Generate Output Document
2010-12-02 23:34:41 +00:00
*
* @param string(32) | $outputID | Output ID | Output Document ID
* @return none | $none | None | None
*
*/
2012-10-09 12:56:31 -04:00
function PMFGenerateOutputDocument ($outputID, $sApplication = null, $index = null, $sUserLogged = null)
{
$g = new G();
$g->sessionVarSave();
if ($sApplication) {
$_SESSION["APPLICATION"] = $sApplication;
} else {
$sApplication = $_SESSION["APPLICATION"];
}
if ($index) {
$_SESSION["INDEX"] = $index;
} else {
$index = $_SESSION["INDEX"];
}
if ($sUserLogged) {
$_SESSION["USER_LOGGED"] = $sUserLogged;
} else {
$sUserLogged = $_SESSION["USER_LOGGED"];
}
2012-10-09 12:56:31 -04:00
G::LoadClass( 'case' );
$oCase = new Cases();
$oCase->thisIsTheCurrentUser( $sApplication, $index, $sUserLogged, '', 'casesListExtJs' );
//require_once 'classes/model/OutputDocument.php';
$oOutputDocument = new OutputDocument();
2012-10-09 12:56:31 -04:00
$aOD = $oOutputDocument->load( $outputID );
$Fields = $oCase->loadCase( $sApplication );
//The $_GET['UID'] variable is used when a process executes.
//$_GET['UID']=($aOD['OUT_DOC_VERSIONING'])?$_GET['UID']:$aOD['OUT_DOC_UID'];
//$sUID = ($aOD['OUT_DOC_VERSIONING'])?$_GET['UID']:$aOD['OUT_DOC_UID'];
2012-10-09 12:56:31 -04:00
$sFilename = preg_replace( '[^A-Za-z0-9_]', '_', G::replaceDataField( $aOD['OUT_DOC_FILENAME'], $Fields['APP_DATA'] ) );
require_once 'classes/model/AppFolder.php';
require_once 'classes/model/AppDocument.php';
//Get the Custom Folder ID (create if necessary)
2012-10-09 12:56:31 -04:00
$oFolder = new AppFolder();
//$aOD['OUT_DOC_DESTINATION_PATH'] = ($aOD['OUT_DOC_DESTINATION_PATH']=='')?PATH_DOCUMENT
// . $_SESSION['APPLICATION'] . PATH_SEP . 'outdocs'. PATH_SEP:$aOD['OUT_DOC_DESTINATION_PATH'];
2012-10-09 12:56:31 -04:00
$folderId = $oFolder->createFromPath( $aOD['OUT_DOC_DESTINATION_PATH'], $sApplication );
//Tags
2012-10-09 12:56:31 -04:00
$fileTags = $oFolder->parseTags( $aOD['OUT_DOC_TAGS'], $sApplication );
//Get last Document Version and apply versioning if is enabled
2012-10-09 12:56:31 -04:00
$oAppDocument = new AppDocument();
$lastDocVersion = $oAppDocument->getLastDocVersion( $outputID, $sApplication );
2012-10-09 12:56:31 -04:00
$oCriteria = new Criteria( 'workflow' );
$oCriteria->add( AppDocumentPeer::APP_UID, $sApplication );
//$oCriteria->add(AppDocumentPeer::DEL_INDEX, $index);
2012-10-09 12:56:31 -04:00
$oCriteria->add( AppDocumentPeer::DOC_UID, $outputID );
$oCriteria->add( AppDocumentPeer::DOC_VERSION, $lastDocVersion );
$oCriteria->add( AppDocumentPeer::APP_DOC_TYPE, 'OUTPUT' );
$oDataset = AppDocumentPeer::doSelectRS( $oCriteria );
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset->next();
2012-10-09 12:56:31 -04:00
if (($aOD['OUT_DOC_VERSIONING']) && ($lastDocVersion != 0)) {
//Create new Version of current output
2012-10-09 12:56:31 -04:00
$lastDocVersion ++;
if ($aRow = $oDataset->getRow()) {
2012-10-09 12:56:31 -04:00
$aFields = array ('APP_DOC_UID' => $aRow['APP_DOC_UID'],'APP_UID' => $sApplication,'DEL_INDEX' => $index,'DOC_UID' => $outputID,'DOC_VERSION' => $lastDocVersion + 1,'USR_UID' => $sUserLogged,'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags
);
$oAppDocument = new AppDocument();
2012-10-09 12:56:31 -04:00
$oAppDocument->create( $aFields );
$sDocUID = $aRow['APP_DOC_UID'];
}
} else {
////No versioning so Update a current Output or Create new if no exist
if ($aRow = $oDataset->getRow()) {
//Update
2012-10-09 12:56:31 -04:00
$aFields = array ('APP_DOC_UID' => $aRow['APP_DOC_UID'],'APP_UID' => $sApplication,'DEL_INDEX' => $index,'DOC_UID' => $outputID,'DOC_VERSION' => $lastDocVersion,'USR_UID' => $sUserLogged,'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags
);
$oAppDocument = new AppDocument();
2012-10-09 12:56:31 -04:00
$oAppDocument->update( $aFields );
$sDocUID = $aRow['APP_DOC_UID'];
} else {
//we are creating the appdocument row
//create
2012-10-09 12:56:31 -04:00
if ($lastDocVersion == 0) {
$lastDocVersion ++;
}
2012-10-09 12:56:31 -04:00
$aFields = array ('APP_UID' => $sApplication,'DEL_INDEX' => $index,'DOC_UID' => $outputID,'DOC_VERSION' => $lastDocVersion,'USR_UID' => $sUserLogged,'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags
);
$oAppDocument = new AppDocument();
2012-10-09 12:56:31 -04:00
$aFields['APP_DOC_UID'] = $sDocUID = $oAppDocument->create( $aFields );
}
}
2012-10-09 12:56:31 -04:00
$sFilename = $aFields['APP_DOC_UID'] . "_" . $lastDocVersion;
$pathOutput = PATH_DOCUMENT . G::getPathFromUID($sApplication) . PATH_SEP . 'outdocs' . PATH_SEP; //G::pr($sFilename);die;
2012-10-09 12:56:31 -04:00
G::mk_dir( $pathOutput );
2012-10-09 12:56:31 -04:00
$aProperties = array ();
2012-10-09 12:56:31 -04:00
if (! isset( $aOD['OUT_DOC_MEDIA'] )) {
$aOD['OUT_DOC_MEDIA'] = 'Letter';
}
2012-10-09 12:56:31 -04:00
if (! isset( $aOD['OUT_DOC_LEFT_MARGIN'] )) {
$aOD['OUT_DOC_LEFT_MARGIN'] = '15';
}
2012-10-09 12:56:31 -04:00
if (! isset( $aOD['OUT_DOC_RIGHT_MARGIN'] )) {
$aOD['OUT_DOC_RIGHT_MARGIN'] = '15';
}
2012-10-09 12:56:31 -04:00
if (! isset( $aOD['OUT_DOC_TOP_MARGIN'] )) {
$aOD['OUT_DOC_TOP_MARGIN'] = '15';
}
2012-10-09 12:56:31 -04:00
if (! isset( $aOD['OUT_DOC_BOTTOM_MARGIN'] )) {
$aOD['OUT_DOC_BOTTOM_MARGIN'] = '15';
}
$aProperties['media'] = $aOD['OUT_DOC_MEDIA'];
2012-10-09 12:56:31 -04:00
$aProperties['margins'] = array ('left' => $aOD['OUT_DOC_LEFT_MARGIN'],'right' => $aOD['OUT_DOC_RIGHT_MARGIN'],'top' => $aOD['OUT_DOC_TOP_MARGIN'],'bottom' => $aOD['OUT_DOC_BOTTOM_MARGIN']
);
if (isset($aOD['OUT_DOC_REPORT_GENERATOR'])) {
$aProperties['report_generator'] = $aOD['OUT_DOC_REPORT_GENERATOR'];
}
$oOutputDocument->generate( $outputID, $Fields['APP_DATA'], $pathOutput, $sFilename, $aOD['OUT_DOC_TEMPLATE'], (boolean) $aOD['OUT_DOC_LANDSCAPE'], $aOD['OUT_DOC_GENERATE'], $aProperties );
//Plugin Hook PM_UPLOAD_DOCUMENT for upload document
//G::LoadClass('plugin');
2012-10-09 12:56:31 -04:00
$oPluginRegistry = & PMPluginRegistry::getSingleton();
if ($oPluginRegistry->existsTrigger( PM_UPLOAD_DOCUMENT ) && class_exists( 'uploadDocumentData' )) {
$triggerDetail = $oPluginRegistry->getTriggerInfo( PM_UPLOAD_DOCUMENT );
$aFields['APP_DOC_PLUGIN'] = $triggerDetail->sNamespace;
$oAppDocument1 = new AppDocument();
2012-10-09 12:56:31 -04:00
$oAppDocument1->update( $aFields );
$sPathName = PATH_DOCUMENT . G::getPathFromUID($sApplication) . PATH_SEP;
2012-10-09 12:56:31 -04:00
$oData['APP_UID'] = $sApplication;
$oData['ATTACHMENT_FOLDER'] = true;
switch ($aOD['OUT_DOC_GENERATE']) {
case "BOTH":
2012-10-09 12:56:31 -04:00
$documentData = new uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.pdf', $sFilename . '.pdf', $sDocUID, $oAppDocument->getDocVersion() );
$documentData->sFileType = "PDF";
$documentData->bUseOutputFolder = true;
2012-10-09 12:56:31 -04:00
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
if ($uploadReturn) {
//Only delete if the file was saved correctly
2012-10-09 12:56:31 -04:00
unlink( $pathOutput . $sFilename . '.pdf' );
}
2012-10-09 12:56:31 -04:00
$documentData = new uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.doc', $sFilename . '.doc', $sDocUID, $oAppDocument->getDocVersion() );
$documentData->sFileType = "DOC";
$documentData->bUseOutputFolder = true;
2012-10-09 12:56:31 -04:00
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
if ($uploadReturn) {
//Only delete if the file was saved correctly
2012-10-09 12:56:31 -04:00
unlink( $pathOutput . $sFilename . '.doc' );
}
break;
case "PDF":
2012-10-09 12:56:31 -04:00
$documentData = new uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.pdf', $sFilename . '.pdf', $sDocUID, $oAppDocument->getDocVersion() );
$documentData->sFileType = "PDF";
$documentData->bUseOutputFolder = true;
2012-10-09 12:56:31 -04:00
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
if ($uploadReturn) {
//Only delete if the file was saved correctly
2012-10-09 12:56:31 -04:00
unlink( $pathOutput . $sFilename . '.pdf' );
}
break;
case "DOC":
2012-10-09 12:56:31 -04:00
$documentData = new uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.doc', $sFilename . '.doc', $sDocUID, $oAppDocument->getDocVersion() );
$documentData->sFileType = "DOC";
$documentData->bUseOutputFolder = true;
2012-10-09 12:56:31 -04:00
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
if ($uploadReturn) {
//Only delete if the file was saved correctly
2012-10-09 12:56:31 -04:00
unlink( $pathOutput . $sFilename . '.doc' );
}
break;
}
}
$g->sessionVarRestore();
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a list of groups from the current workspace
2010-12-02 23:34:41 +00:00
*
* @name PMFGroupList
* @label PMF Group List
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFGroupList.28.29
*
* @return array | $rows | List of groups | An array of groups
*
*/
2012-10-09 12:56:31 -04:00
function PMFGroupList () //its test was successfull
2010-12-02 23:34:41 +00:00
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
$result = $ws->groupList();
2012-10-09 12:56:31 -04:00
$rows = Array ();
$i = 1;
2012-10-09 12:56:31 -04:00
if (isset( $result )) {
foreach ($result as $item) {
2012-10-09 12:56:31 -04:00
$rows[$i ++] = $item;
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
/**
*
* @method
*
* Returns a list of roles whose status is "ACTIVE" for the current workspace.
2010-12-02 23:34:41 +00:00
*
* @name PMFRoleList
* @label PMF Role List
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFRoleList.28.29
*
* @return array | $rows | List of roles | This function returns an array of roles
*
*/
2012-10-09 12:56:31 -04:00
function PMFRoleList () //its test was successfull
2010-12-02 23:34:41 +00:00
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
$result = $ws->roleList();
2012-10-09 12:56:31 -04:00
$rows = Array ();
$i = 1;
2012-10-09 12:56:31 -04:00
if (isset( $result )) {
foreach ($result as $item) {
2012-10-09 12:56:31 -04:00
$rows[$i ++] = $item;
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
2012-10-09 12:56:31 -04:00
* @method Returns a list of the pending cases for a specified user
2010-12-02 23:34:41 +00:00
*
* returns a list of the pending cases for a specified user. Note that the specified user must be designated to work on the current task for these cases.
*
2010-12-02 23:34:41 +00:00
* @name PMFCaseList
* @label PMF Case List
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFCaseList.28.29
*
* @param string(32) | $userId | User ID | The unique ID of a user who is assigned to work on the cases.
* @return array | $rows | List of cases | A list of cases
*
*/
2012-10-09 12:56:31 -04:00
function PMFCaseList ($userId) //its test was successfull
2010-12-02 23:34:41 +00:00
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
$result = $ws->caseList( $userId );
$rows = Array ();
$i = 1;
2012-10-09 12:56:31 -04:00
if (isset( $result )) {
foreach ($result as $item) {
2012-10-09 12:56:31 -04:00
$rows[$i ++] = $item;
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns a list of processes for the current workspace
2010-12-02 23:34:41 +00:00
*
* @name PMFProcessList
* @label PMF Process List
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFProcessList.28.29
*
* @return array | $rows | Lis ot Processes | An array of tasks in the indicated case which have open delegations
*
*/
2012-10-09 12:56:31 -04:00
function PMFProcessList () //its test was successfull
2010-12-02 23:34:41 +00:00
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
$result = $ws->processList();
2012-10-09 12:56:31 -04:00
$rows = Array ();
$i = 1;
2012-10-09 12:56:31 -04:00
if (isset( $result )) {
foreach ($result as $item) {
2012-10-09 12:56:31 -04:00
$rows[$i ++] = $item;
}
2010-12-02 23:34:41 +00:00
}
return $rows;
2010-12-02 23:34:41 +00:00
}
/**
*
* @method
*
* Sends an array of case variables to a specified case.
2010-12-02 23:34:41 +00:00
*
* @name PMFSendVariables
* @label PMF Send Variables
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFSendVariables.28.29
*
* @param string(32) | $caseId | Case ID | The unique ID of the case to receive the variable.
* @param array | $variables | Array of variables | An associative array to hold the case variables to send to the case.
* @return int | $result | Result of send variables | Returns 1 if the variables were sent successfully to the case; otherwise, returns 0 if an error occurred.
*
*/
2012-10-09 12:56:31 -04:00
function PMFSendVariables ($caseId, $variables)
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
2012-10-09 12:56:31 -04:00
$result = $ws->sendVariables( $caseId, $variables );
if ($result->status_code == 0) {
if (isset($_SESSION['APPLICATION'])) {
if ($caseId == $_SESSION['APPLICATION']) {
global $oPMScript;
if (isset($oPMScript->aFields) && is_array($oPMScript->aFields)) {
if (is_array($variables)) {
$oPMScript->aFields = array_merge($oPMScript->aFields, $variables);
}
}
}
}
return 1;
} else {
return 0;
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Derivates (routes) a case to the next task in the process.
2010-12-02 23:34:41 +00:00
*
* @name PMFDerivateCase
* @label PMF Derivate Case
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFDerivateCase.28.29
*
* @param string(32) | $caseId | Case ID | The unique ID for the case to be derivated (routed)
2012-10-09 12:56:31 -04:00
* @param int | $delIndex | delegation index for the case | The delegation index for the case to derivated (routed).
2010-12-02 23:34:41 +00:00
* @param boolean | $bExecuteTriggersBeforeAssignment = false | Trigger | Optional parameter. If set to true, any triggers which are assigned to pending steps in the current task will be executed before the case is assigned to the next user.
* @param boolean | $sUserLogged = null | User ID | Optional parameter. The unique ID of the user who will route the case. This should be set to the user who is currently designated to work on the case. If omitted or set to NULL, then the currently logged-in user will route the case.
2010-12-02 23:34:41 +00:00
* @return int | $result | Result of Derivate case | Returns 1 if new case was derivated (routed) successfully; otherwise, returns 0 if an error occurred.
*
*/
2012-10-09 12:56:31 -04:00
function PMFDerivateCase ($caseId, $delIndex, $bExecuteTriggersBeforeAssignment = false, $sUserLogged = null)
{
2012-10-09 12:56:31 -04:00
if (! $sUserLogged) {
$sUserLogged = $_SESSION['USER_LOGGED'];
}
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
$result = $ws->derivateCase( $sUserLogged, $caseId, $delIndex, $bExecuteTriggersBeforeAssignment );
if (isset( $result->status_code )) {
return $result->status_code;
} else {
return 0;
}
if ($result->status_code == 0) {
return 1;
} else {
return 0;
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Creates a new case with a user who can impersonate a user with the proper
2010-12-02 23:34:41 +00:00
* privileges.
*
* @name PMFNewCaseImpersonate
* @label PMF New Case Impersonate
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFNewCaseImpersonate.28.29
*
* @param string(32) | $processId | Process ID | The unique ID of the process.
* @param string(32) | $userId | User ID | The unique ID of the user.
* @param array | $variables | Array of variables | An associative array of the variables which will be sent to the case.
* @param string(32) | $taskId | The unique ID of the task taha is in the starting group.
2010-12-02 23:34:41 +00:00
* @return int | $result | Result | Returns 1 if new case was created successfully; otherwise, returns 0 if an error occurred.
*
*/
function PMFNewCaseImpersonate ($processId, $userId, $variables, $taskId = '')
{
2012-10-09 12:56:31 -04:00
G::LoadClass( "wsBase" );
$ws = new wsBase();
$result = $ws->newCaseImpersonate( $processId, $userId, $variables, $taskId);
if ($result->status_code == 0) {
return $result->caseId;
} else {
return 0;
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Creates a new case starting with the specified task
2010-12-02 23:34:41 +00:00
*
* @name PMFNewCase
* @label PMF New Case
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFNewCase.28.29
*
* @param string(32) | $processId | Process ID | The unique ID of the process.
* @param string(32) | $userId | User ID | The unique ID of the user.
* @param string(32) | $taskId | Task ID | The unique ID of the task.
* @param array | $variables | Array of variables | An associative array of the variables which will be sent to the case.
* @return string | $idNewCase | Case ID | If an error occured, it returns the integer zero. Otherwise, it returns a string with the case UID of the new case.
*
*/
2012-10-09 12:56:31 -04:00
function PMFNewCase ($processId, $userId, $taskId, $variables)
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
2010-12-02 23:34:41 +00:00
2012-10-09 12:56:31 -04:00
$result = $ws->newCase( $processId, $userId, $taskId, $variables );
2010-12-02 23:34:41 +00:00
if ($result->status_code == 0) {
return $result->caseId;
} else {
return 0;
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Assigns a user to a group.
2010-12-02 23:34:41 +00:00
*
* Assigns a user to a group. Note that the logged-in user must have the PM_USERS permission in his/her role to be able to assign a user to a group.
*
2010-12-02 23:34:41 +00:00
* @name PMFAssignUserToGroup
* @label PMF Assign User To Group
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFNewCase.28.29
*
* @param string(32) | $userId | User ID | The unique ID of the user.
* @param string(32) | $groupId | Group ID | The unique ID of the group.
* @return int | $result | Result of the assignment | Returns 1 if the user was successfully assigned to the group; otherwise, returns 0.
*
*/
2012-10-09 12:56:31 -04:00
function PMFAssignUserToGroup ($userId, $groupId)
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
$result = $ws->assignUserToGroup( $userId, $groupId );
if ($result->status_code == 0) {
return 1;
} else {
return 0;
}
2010-12-02 23:34:41 +00:00
}
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Creates a new user with the given data.
2010-12-02 23:34:41 +00:00
*
* @name PMFCreateUser
* @label PMF Create User
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFCreateUser.28.29
*
* @param string(32) | $userId | User ID | The username for the new user.
* @param string(32) | $password | Password of the new user | The password of the new user, which can be up to 32 characters long.
2010-12-02 23:34:41 +00:00
* @param string(32) | $firstname | Firstname of the new user | The first name of the user, which can be up to 50 characters long.
* @param string(32) | $lastname | Lastname of the new user | The last name of the user, which can be up to 50 characters long.
* @param string(32) | $email | Email the new user | The email of the new user, which can be up to 100 characters long.
* @param string(32) | $role | Rol of the new user | The role of the new user such as "PROCESSMAKER_ADMIN" or "PROCESSMAKER_OPERATOR".
* @param string(32) | $dueDate=null | Expiration date | Optional parameter. The expiration date must be a string in the format "yyyy-mm-dd".
* @param string(32) | $status=null | Status of the new user | Optional parameter. The user's status, such as "ACTIVE", "INACTIVE" or "VACATION".
2010-12-02 23:34:41 +00:00
* @return int | $result | Result of the creation | Returns 1 if the new user was created successfully; otherwise, returns 0 if an error occurred.
*
*/
2012-10-09 12:56:31 -04:00
function PMFCreateUser ($userId, $password, $firstname, $lastname, $email, $role, $dueDate = null, $status = null)
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'wsBase' );
$ws = new wsBase();
2012-10-09 12:56:31 -04:00
$result = $ws->createUser( $userId, $firstname, $lastname, $email, $role, $password, $dueDate, $status );
if ($result->status_code == 0) {
return 1;
} else {
return 0;
}
2010-12-02 23:34:41 +00:00
}
/**
*
* @method
*
* Update a user with the given data.
*
* @name PMFUpdateUser
* @label PMF Update User
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFUpdateUser.28.29
*
* @param string(32) | $userUid | User UID | The user UID.
* @param string(32) | $userName | User ID | The username for the user.
* @param string(32) | $firstName=null | Firstname of the user | Optional parameter. The first name of the user, which can be up to 50 characters long.
* @param string(32) | $lastName=null | Lastname of the user | Optional parameter. The last name of the user, which can be up to 50 characters long.
* @param string(32) | $email=null | Email the user | Optional parameter. The email of the user, which can be up to 100 characters long.
* @param string(32) | $dueDate=null | Expiration date | Optional parameter. The expiration date must be a string in the format "yyyy-mm-dd".
* @param string(32) | $status=null | Status of the user | Optional parameter. The user's status, such as "ACTIVE", "INACTIVE" or "VACATION".
* @param string(32) | $role=null | Rol of the user | The role of the user such as "PROCESSMAKER_ADMIN" or "PROCESSMAKER_OPERATOR".
* @param string(32) | $password=null | Password of the user | The password of the user, which can be up to 32 characters long.
* @return int | $result | Result of the update | Returns 1 if the user is updated successfully; otherwise, returns 0 if an error occurred.
*
*/
2012-10-09 12:56:31 -04:00
function PMFUpdateUser ($userUid, $userName, $firstName = null, $lastName = null, $email = null, $dueDate = null, $status = null, $role = null, $password = null)
{
G::LoadClass( "wsBase" );
$ws = new wsBase();
2012-10-09 12:56:31 -04:00
$result = $ws->updateUser( $userUid, $userName, $firstName, $lastName, $email, $dueDate, $status, $role, $password );
if ($result->status_code == 0) {
return 1;
} else {
return 0;
}
}
/**
*
* @method
*
* Retrieves information about a user with a given ID.
*
* @name PMFInformationUser
* @label PMF Information User
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFInformationUser.28.29
*
* @param string(32) | $userUid | User UID | The user UID.
* @return array | $info | Information of user | An associative array with Information.
*
*/
function PMFInformationUser($userUid)
{
G::LoadClass("wsBase");
$ws = new wsBase();
$result = $ws->informationUser($userUid);
$info = array();
if ($result->status_code == 0 && isset($result->info)) {
$info = $result->info;
}
return $info;
}
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Creates a random string of letters and/or numbers of a specified length,which
2010-12-02 23:34:41 +00:00
* can be used as the PINs (public identification numbers) and codes for cases.
*
* @name generateCode
* @label generate Code
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#generateCode.28.29
*
* @param int | $iDigits = 4 | Number of characters | The number of characters to be generated.
* @param string(32) | $sType="NUMERIC" | Type of characters | The type of of characters to be generated
* @return string | $generateString | Generated string | The generated string of random characters.
*
*/
2012-10-09 12:56:31 -04:00
function generateCode ($iDigits = 4, $sType = 'NUMERIC')
{
2012-10-09 12:56:31 -04:00
return G::generateCode( $iDigits, $sType );
2010-12-02 23:34:41 +00:00
}
/**
*
* @method
*
* Sets the code and PIN for a case.
2010-12-02 23:34:41 +00:00
*
* @name setCaseTrackerCode
* @label set Case Tracker Code
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#setCaseTrackerCode.28.29
*
* @param string(32) | $sApplicationUID | Case ID | The unique ID for a case (which can be found with WSCaseList()
* @param string(32) | $sCode | New Code for case | The new code for a case, which will be stored in the field wf_<WORKSPACE>.APPLICATION.APP_CODE
* @param string(32) | $sPIN = "" | New Code PIN for case |The new code for a case.
* @return int | $result | Result | If successful, returns one, otherwise zero or error number.
2010-12-02 23:34:41 +00:00
*
*/
2012-10-09 12:56:31 -04:00
function setCaseTrackerCode ($sApplicationUID, $sCode, $sPIN = '')
{
if ($sCode != '' || $sPIN != '') {
2012-10-09 12:56:31 -04:00
G::LoadClass( 'case' );
$oCase = new Cases();
$aFields = $oCase->loadCase( $sApplicationUID );
$aFields['APP_PROC_CODE'] = $sCode;
if ($sPIN != '') {
$aFields['APP_DATA']['PIN'] = $sPIN;
2012-10-09 12:56:31 -04:00
$aFields['APP_PIN'] = md5( $sPIN );
}
2012-10-09 12:56:31 -04:00
$oCase->updateCase( $sApplicationUID, $aFields );
if (isset($_SESSION['APPLICATION'])) {
if ($sApplicationUID == $_SESSION['APPLICATION']) {
global $oPMScript;
if (isset($oPMScript->aFields) && is_array($oPMScript->aFields)) {
$oPMScript->aFields['PIN'] = $aFields['APP_DATA']['PIN'];
}
}
}
return 1;
} else {
return 0;
2010-12-02 23:34:41 +00:00
}
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Routes (derivates) a case and then displays the case list.
2010-12-02 23:34:41 +00:00
*
* @name jumping
* @label jumping
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#jumping.28.29
*
* @param string(32) | $caseId | Case ID | The unique ID for the case to be routed (derivated).
* @param int | $delIndex | delegation Index of case | The delegation index of the task to be routed (derivated). Counting starts from 1.
* @return none | $none | None | None
*
*/
function jumping ($caseId, $delIndex)
{
try {
2012-10-09 12:56:31 -04:00
$x = PMFDerivateCase( $caseId, $delIndex );
if ($x == 0) {
2012-10-09 12:56:31 -04:00
G::SendTemporalMessage( 'ID_NOT_DERIVATED', 'error', 'labels' );
}
} catch (Exception $oException) {
2012-10-09 12:56:31 -04:00
G::SendTemporalMessage( 'ID_NOT_DERIVATED', 'error', 'labels' );
}
G::header( 'Location: casesListExtJs' );
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Returns the label of a specified option from a dropdown box, listbox,
2010-12-02 23:34:41 +00:00
* checkgroup or radiogroup.
*
* @name PMFgetLabelOption
* @label PMF get Label Option
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFgetLabelOption.28.29
*
* @param string(32) | $PROCESS | Process ID | The unique ID of the process which contains the field.
* @param string(32) | $DYNAFORM_UID | Dynaform ID | The unique ID of the DynaForm where the field is located.
* @param string(32) | $FIELD_NAME | Fiel Name | The field name of the dropdown box, listbox, checkgroup or radiogroup from the specified DynaForm.
* @param string(32) | $FIELD_SELECTED_ID | ID selected | The value (i.e., ID) of the option from the fieldName.
* @return string | $label | Label of the specified option | A string holding the label of the specified option or NULL if the specified option does not exist.
*
*/
2012-10-09 12:56:31 -04:00
function PMFgetLabelOption ($PROCESS, $DYNAFORM_UID, $FIELD_NAME, $FIELD_SELECTED_ID)
{
2012-10-09 12:56:31 -04:00
$G_FORM = new Form( "{$PROCESS}/{$DYNAFORM_UID}", PATH_DYNAFORM, SYS_LANG, false );
if (isset( $G_FORM->fields[$FIELD_NAME]->option[$FIELD_SELECTED_ID] )) {
return $G_FORM->fields[$FIELD_NAME]->option[$FIELD_SELECTED_ID];
} else {
return null;
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
2010-12-02 23:34:41 +00:00
/**
*
* @method
*
* Redirects a case to any step in the current task. In order for the step to
2010-12-02 23:34:41 +00:00
* be executed, the specified step much exist and if it contains a condition,
* it must evaluate to true.
*
* @name PMFRedirectToStep
* @label PMF Redirect To Step
2010-12-02 23:34:41 +00:00
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFRedirectToStep.28.29
*
* @param string(32) | $sApplicationUID | Case ID | The unique ID for a case,
* @param int | $iDelegation | Delegation index | The delegation index of a case.
* @param string(32) | $sStepType | Type of Step | The type of step, which can be "DYNAFORM", "INPUT_DOCUMENT" or "OUTPUT_DOCUMENT".
* @param string(32) | $sStepUid | Step ID | The unique ID for the step.
* @return none | $none | None | None
*
*/
2012-10-09 12:56:31 -04:00
function PMFRedirectToStep ($sApplicationUID, $iDelegation, $sStepType, $sStepUid)
{
$g = new G();
$g->sessionVarSave();
$iDelegation = intval($iDelegation);
$_SESSION["APPLICATION"] = $sApplicationUID;
$_SESSION["INDEX"] = $iDelegation;
require_once 'classes/model/AppDelegation.php';
2012-10-09 12:56:31 -04:00
$oCriteria = new Criteria( 'workflow' );
$oCriteria->addSelectColumn( AppDelegationPeer::TAS_UID );
$oCriteria->add( AppDelegationPeer::APP_UID, $sApplicationUID );
$oCriteria->add( AppDelegationPeer::DEL_INDEX, $iDelegation );
$oDataset = AppDelegationPeer::doSelectRS( $oCriteria );
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset->next();
global $oPMScript;
$aRow = $oDataset->getRow();
if ($aRow) {
require_once 'classes/model/Step.php';
$oStep = new Step();
2012-10-09 12:56:31 -04:00
$oTheStep = $oStep->loadByType( $aRow['TAS_UID'], $sStepType, $sStepUid );
$bContinue = true;
2012-10-09 12:56:31 -04:00
G::LoadClass( 'case' );
$oCase = new Cases();
2012-10-09 12:56:31 -04:00
$aFields = $oCase->loadCase( $sApplicationUID );
if ($oTheStep->getStepCondition() != '') {
2012-10-09 12:56:31 -04:00
G::LoadClass( 'pmScript' );
$pmScript = new PMScript();
2012-10-09 12:56:31 -04:00
$pmScript->setFields( $aFields['APP_DATA'] );
$pmScript->setScript( $oTheStep->getStepCondition() );
$bContinue = $pmScript->evaluate();
}
if ($bContinue) {
switch ($oTheStep->getStepTypeObj()) {
case 'DYNAFORM':
$sAction = 'EDIT';
break;
case 'OUTPUT_DOCUMENT':
$sAction = 'GENERATE';
break;
case 'INPUT_DOCUMENT':
$sAction = 'ATTACH';
break;
case 'EXTERNAL':
$sAction = 'EDIT';
break;
case 'MESSAGE':
$sAction = '';
break;
}
// save data
2012-10-09 12:56:31 -04:00
if (! is_null( $oPMScript )) {
$aFields['APP_DATA'] = $oPMScript->aFields;
unset($aFields['APP_STATUS']);
unset($aFields['APP_PROC_STATUS']);
unset($aFields['APP_PROC_CODE']);
unset($aFields['APP_PIN']);
2012-10-09 12:56:31 -04:00
$oCase->updateCase( $sApplicationUID, $aFields );
}
$g->sessionVarRestore();
2012-10-09 12:56:31 -04:00
G::header( 'Location: ' . 'cases_Step?TYPE=' . $sStepType . '&UID=' . $sStepUid . '&POSITION=' . $oTheStep->getStepPosition() . '&ACTION=' . $sAction );
die();
}
2010-12-02 23:34:41 +00:00
}
$g->sessionVarRestore();
2010-12-02 23:34:41 +00:00
}
/**
*
* @method
*
* Returns a list of the next assigned users to a case.
2010-12-02 23:34:41 +00:00
*
* @name PMFGetNextAssignedUser
* @label PMFGet Next Assigned User
2010-12-02 23:34:41 +00:00
*
* @param string(32) | $application | Case ID | Id of the case
* @param string(32) | $task | Task ID | Id of the task
2010-12-02 23:34:41 +00:00
* @return array | $array | List of users | Return a list of users
*
*/
function PMFGetNextAssignedUser ($application, $task, $delIndex = null, $userUid = null)
{
2010-12-02 23:34:41 +00:00
require_once 'classes/model/AppDelegation.php';
require_once 'classes/model/Task.php';
require_once 'classes/model/TaskUser.php';
require_once 'classes/model/Users.php';
require_once 'classes/model/Groupwf.php';
require_once 'classes/model/GroupUser.php';
$oTask = new Task();
2012-10-09 12:56:31 -04:00
$TaskFields = $oTask->load( $task );
$typeTask = $TaskFields['TAS_ASSIGN_TYPE'];
$g = new G();
$g->sessionVarSave();
$_SESSION['INDEX'] = (!is_null($delIndex) ? $delIndex : (isset($_SESSION['INDEX']) ? $_SESSION['INDEX'] : null));
$_SESSION['USER_LOGGED'] = (!is_null($userUid) ? $userUid : (isset($_SESSION['USER_LOGGED']) ? $_SESSION['USER_LOGGED'] : null));
if ($typeTask == 'BALANCED' && !is_null($_SESSION['INDEX']) && !is_null($_SESSION['USER_LOGGED'])) {
2012-10-09 12:56:31 -04:00
G::LoadClass( 'derivation' );
$oDerivation = new Derivation();
2012-10-09 12:56:31 -04:00
$aDeriv = $oDerivation->prepareInformation( array ('USER_UID' => $_SESSION['USER_LOGGED'],'APP_UID' => $application,'DEL_INDEX' => $_SESSION['INDEX']
) );
foreach ($aDeriv as $derivation) {
2012-10-09 12:56:31 -04:00
$aUser = array ('USR_UID' => $derivation['NEXT_TASK']['USER_ASSIGNED']['USR_UID'],'USR_USERNAME' => $derivation['NEXT_TASK']['USER_ASSIGNED']['USR_USERNAME'],'USR_FIRSTNAME' => $derivation['NEXT_TASK']['USER_ASSIGNED']['USR_FIRSTNAME'],'USR_LASTNAME' => $derivation['NEXT_TASK']['USER_ASSIGNED']['USR_LASTNAME'],'USR_EMAIL' => $derivation['NEXT_TASK']['USER_ASSIGNED']['USR_EMAIL']
);
$aUsers[] = $aUser;
}
$g->sessionVarRestore();
2012-10-09 12:56:31 -04:00
if (count( $aUsers ) == 1) {
return $aUser;
} else {
return $aUsers;
}
} else {
$g->sessionVarRestore();
return false;
}
}
2010-12-02 23:34:41 +00:00
/**
* @method
*
* Returns a list or user.
*
* @name PMFGetUserEmailAddress
* @label PMF Get User Email Address
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFGetUserEmailAddress.28.29
*
* @param string(32) or Array | $id | Case ID | Id of the case.
* @param string(32) | $APP_UID = null | Application ID | Id of the Application.
* @param string(32) | $prefix = "usr" | prefix | Id of the task.
* @return array | $aRecipient | Array of the Recipient | Return an Array of the Recipient.
*
*/
2012-10-09 12:56:31 -04:00
function PMFGetUserEmailAddress ($id, $APP_UID = null, $prefix = 'usr')
{
2010-12-02 23:34:41 +00:00
require_once 'classes/model/UsersPeer.php';
require_once 'classes/model/AppDelegation.php';
2012-10-09 12:56:31 -04:00
G::LoadClass( 'case' );
2012-10-09 12:56:31 -04:00
if (is_string( $id ) && trim( $id ) == "") {
return false;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:56:31 -04:00
if (is_array( $id ) && count( $id ) == 0) {
return false;
2010-12-02 23:34:41 +00:00
}
//recipient to store the email addresses
2012-10-09 12:56:31 -04:00
$aRecipient = Array ();
$aItems = Array ();
/*
* First at all the $id user input can be by example erik@colosa.com
* 2.this $id param can be a array by example Array('000000000001','000000000002') in this case $prefix is necessary
* 3.this same param can be a array by example Array('usr|000000000001', 'usr|-1', 'grp|2245141479413131441')
*/
/*
* The second thing is that the return type will be configurated depend of the input type (using $retType)
*/
2012-10-09 12:56:31 -04:00
if (is_array( $id )) {
$aItems = $id;
$retType = 'array';
} else {
$retType = 'string';
2012-10-09 12:56:31 -04:00
if (strpos( $id, "," ) !== false) {
$aItems = explode( ',', $id );
2010-12-02 23:34:41 +00:00
} else {
2012-10-09 12:56:31 -04:00
array_push( $aItems, $id );
2010-12-02 23:34:41 +00:00
}
}
2010-12-02 23:34:41 +00:00
foreach ($aItems as $sItem) {
//cleaning for blank spaces into each array item
2012-10-09 12:56:31 -04:00
$sItem = trim( $sItem );
if (strpos( $sItem, "|" ) !== false) {
// explode the parameter because always will be compose with pipe separator to indicate
// the type (user or group) and the target mai
2012-10-09 12:56:31 -04:00
list ($sType, $sID) = explode( '|', $sItem );
$sType = trim( $sType );
$sID = trim( $sID );
} else {
$sType = $prefix;
$sID = $sItem;
}
2010-12-02 23:34:41 +00:00
switch ($sType) {
case 'ext':
2012-10-09 12:56:31 -04:00
if (G::emailAddress( $sID )) {
array_push( $aRecipient, $sID );
}
break;
case 'usr':
if ($sID == '-1') {
// -1: Curent user, load from user record
2012-10-09 12:56:31 -04:00
if (isset( $APP_UID )) {
$oAppDelegation = new AppDelegation();
$aAppDel = $oAppDelegation->getLastDeleration( $APP_UID );
if (isset( $aAppDel )) {
$oUserRow = UsersPeer::retrieveByPK( $aAppDel['USR_UID'] );
if (isset( $oUserRow )) {
$sID = $oUserRow->getUsrEmail();
} else {
2012-10-09 12:56:31 -04:00
throw new Exception( 'User with ID ' . $oAppDelegation->getUsrUid() . 'doesn\'t exist' );
}
2012-10-09 12:56:31 -04:00
if (G::emailAddress( $sID )) {
array_push( $aRecipient, $sID );
}
}
}
} else {
2012-10-09 12:56:31 -04:00
$oUserRow = UsersPeer::retrieveByPK( $sID );
if ($oUserRow != null) {
$sID = $oUserRow->getUsrEmail();
if (G::emailAddress( $sID )) {
array_push( $aRecipient, $sID );
}
}
}
break;
case 'grp':
2012-10-09 12:56:31 -04:00
G::LoadClass( 'groups' );
$oGroups = new Groups();
2012-10-09 12:56:31 -04:00
$oCriteria = $oGroups->getUsersGroupCriteria( $sID );
$oDataset = GroupwfPeer::doSelectRS( $oCriteria );
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
while ($oDataset->next()) {
$aGroup = $oDataset->getRow();
//to validate email address
2012-10-09 12:56:31 -04:00
if (G::emailAddress( $aGroup['USR_EMAIL'] )) {
array_push( $aRecipient, $aGroup['USR_EMAIL'] );
}
}
break;
case 'dyn':
$oCase = new Cases();
2012-10-09 12:56:31 -04:00
$aFields = $oCase->loadCase( $APP_UID );
$aFields['APP_DATA'] = array_merge( $aFields['APP_DATA'], G::getSystemConstants() );
//to validate email address
2012-10-09 12:56:31 -04:00
if (isset( $aFields['APP_DATA'][$sID] ) && G::emailAddress( $aFields['APP_DATA'][$sID] )) {
array_push( $aRecipient, $aFields['APP_DATA'][$sID] );
}
break;
2010-12-02 23:34:41 +00:00
}
}
switch ($retType) {
case 'array':
return $aRecipient;
break;
case 'string':
2012-10-09 12:56:31 -04:00
return implode( ',', $aRecipient );
break;
default:
return $aRecipient;
}
2010-12-02 23:34:41 +00:00
}
BUG 9043 Variable for Case Notes content needed SOLVED - Se crearon varias funciones para este caso. - La funcion getCaseNotes en la class.case.php con los parametros applicationID, type que es la forma que quiere que se devuelvan los datos, puede ser array, objetc, string por defecto esta en array, y userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios. - Se modifico la funcion getNotesList para poder traer las notas por un determinado usuario y por defecto recupera las notas de todos los usuarios. - en class.pmFunctions.php se creo la funcion PMFGetCaseNotes con los parametros applicationID, type que es la forma que quiere que se devuelvan los datos, puede ser array, objetc, string por defecto esta en array, y userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios. - En class.wsBase.php la funcion getCaseNotes con los parametros applicationID, userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios, esta funcion nos devuelve un array con los fieds en minuscula. - En soap2.php getCaseNotes donde se tienen los siguiente parametros: sessionId, se necesita iniciar una session para poder utilizarlo, applicationID, userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios. - Se adiciono la funcion para utilizarlo en SoapServer. - En wsResponse se creo un nuevo template para la respuesta del webservice wsGetCaseNotesResponse con los campos status_code, message, notes, timestamp. - En pmos2.wsdl se agregaron los datos necesarios para la salida correcta del webservice.
2012-05-02 09:56:30 -04:00
/**
* @method
*
* Get of the cases notes an application.
*
* @name PMFGetCaseNotes
* @label PMF Get of the cases notes an application
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFGetCaseNotes.28.29
*
* @param string(32) | $applicationID | Application ID | ID of the Application.
* @param string(32) | $type = "array" | type of the return value | type of the return value (array, object, string).
* @param string(32) | $userUid = "" | User ID | Id of the User.
* @return array, object or string | $response | Array of the response | Return an Array or Object or String.
*
*/
2012-10-09 12:56:31 -04:00
function PMFGetCaseNotes ($applicationID, $type = 'array', $userUid = '')
{
2012-10-09 12:56:31 -04:00
G::LoadClass( 'case' );
$response = Cases::getCaseNotes( $applicationID, $type, $userUid );
return $response;
BUG 9043 Variable for Case Notes content needed SOLVED - Se crearon varias funciones para este caso. - La funcion getCaseNotes en la class.case.php con los parametros applicationID, type que es la forma que quiere que se devuelvan los datos, puede ser array, objetc, string por defecto esta en array, y userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios. - Se modifico la funcion getNotesList para poder traer las notas por un determinado usuario y por defecto recupera las notas de todos los usuarios. - en class.pmFunctions.php se creo la funcion PMFGetCaseNotes con los parametros applicationID, type que es la forma que quiere que se devuelvan los datos, puede ser array, objetc, string por defecto esta en array, y userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios. - En class.wsBase.php la funcion getCaseNotes con los parametros applicationID, userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios, esta funcion nos devuelve un array con los fieds en minuscula. - En soap2.php getCaseNotes donde se tienen los siguiente parametros: sessionId, se necesita iniciar una session para poder utilizarlo, applicationID, userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios. - Se adiciono la funcion para utilizarlo en SoapServer. - En wsResponse se creo un nuevo template para la respuesta del webservice wsGetCaseNotesResponse con los campos status_code, message, notes, timestamp. - En pmos2.wsdl se agregaron los datos necesarios para la salida correcta del webservice.
2012-05-02 09:56:30 -04:00
}
/**
*
* @method
*
* Delete a specified case.
*
* @name PMFDeleteCase
* @label PMF Delete a specified case.
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFDeleteCase.28.29
*
* @param string(32) | $caseUid | ID of the case | The unique ID of the case.
* @return int | $result | Result of the elimination | Returns 1 if the case is delete successfully; otherwise, returns 0 if an error occurred.
*
*/
2012-10-09 12:56:31 -04:00
function PMFDeleteCase ($caseUid)
{
2012-10-09 12:56:31 -04:00
G::LoadClass( "wsBase" );
$ws = new wsBase();
2012-10-09 12:56:31 -04:00
$result = $ws->deleteCase( $caseUid );
if ($result->status_code == 0) {
return 1;
} else {
return 0;
}
}
/**
*
* @method
*
* Cancel a specified case.
*
* @name PMFCancelCase
* @label PMF Cancel a specified case.
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFCancelCase.28.29
*
* @param string(32) | $caseUid | ID of the case | The unique ID of the case.
* @param int | $delIndex | Delegation index of the case | The delegation index of the current task in the case.
* @param string(32) | $userUid | ID user | The unique ID of the user who will cancel the case.
* @return int | $result | Result of the cancelation | Returns 1 if the case is cancel successfully; otherwise, returns 0 if an error occurred.
*
*/
2012-10-09 12:56:31 -04:00
function PMFCancelCase ($caseUid, $delIndex, $userUid)
{
2012-10-09 12:56:31 -04:00
G::LoadClass( "wsBase" );
$ws = new wsBase();
2012-10-09 12:56:31 -04:00
$result = $ws->cancelCase( $caseUid, $delIndex, $userUid );
if ($result->status_code == 0) {
if (isset($_SESSION['APPLICATION']) && isset($_SESSION['INDEX'])) {
if ($_SESSION['APPLICATION'] == $caseUid && $_SESSION['INDEX'] == $delIndex) {
if (!defined('WEB_SERVICE_VERSION')) {
G::header('Location: ../cases/casesListExtJsRedirector');
die();
} else {
die(__('ID_PM_FUNCTION_CHANGE_CASE', SYS_LANG, array('PMFCancelCase', G::LoadTranslation('ID_CANCELLED'))));
}
}
}
return 1;
} else {
return 0;
}
}
/**
*
* @method
*
* Pauses a specified case.
*
* @name PMFPauseCase
* @label PMF Pauses a specified case.
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFPauseCase.28.29
*
* @param string(32) | $caseUid | ID of the case | The unique ID of the case.
* @param int | $delIndex | Delegation index of the case | The delegation index of the current task in the case.
* @param string(32) | $userUid | ID user | The unique ID of the user who will pause the case.
* @param string(32) | $unpauseDate=null | Date | Optional parameter. The date in the format "yyyy-mm-dd" indicating when to unpause the case.
* @return int | $result | Result of the pause | Returns 1 if the case is paused successfully; otherwise, returns 0 if an error occurred.
*
*/
2012-10-09 12:56:31 -04:00
function PMFPauseCase ($caseUid, $delIndex, $userUid, $unpauseDate = null)
{
G::LoadClass('wsBase');
$ws = new wsBase();
$result = $ws->pauseCase($caseUid, $delIndex, $userUid, $unpauseDate);
if ($result->status_code == 0) {
if (isset($_SESSION['APPLICATION']) && isset($_SESSION['INDEX'])) {
if ($_SESSION['APPLICATION'] == $caseUid && $_SESSION['INDEX'] == $delIndex) {
if (!defined('WEB_SERVICE_VERSION')) {
G::header('Location: ../cases/casesListExtJsRedirector');
die();
} else {
die(__('ID_PM_FUNCTION_CHANGE_CASE', SYS_LANG, array('PMFPauseCase', G::LoadTranslation('ID_PAUSED'))));
}
}
}
return 1;
} else {
return 0;
}
}
/**
*
* @method
*
* Unpause a specified case.
*
* @name PMFUnpauseCase
* @label PMF Unpause a specified case.
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFUnpauseCase.28.29
*
* @param string(32) | $caseUid | ID of the case | The unique ID of the case.
* @param int | $delIndex | Delegation index of the case | The delegation index of the current task in the case.
* @param string(32) | $userUid | ID user | The unique ID of the user who will unpause the case.
* @return int | $result | Result of the unpause | Returns 1 if the case is unpause successfully; otherwise, returns 0 if an error occurred.
*
*/
2012-10-09 12:56:31 -04:00
function PMFUnpauseCase ($caseUid, $delIndex, $userUid)
{
2012-10-09 12:56:31 -04:00
G::LoadClass( "wsBase" );
$ws = new wsBase();
2012-10-09 12:56:31 -04:00
$result = $ws->unpauseCase( $caseUid, $delIndex, $userUid );
if ($result->status_code == 0) {
return 1;
} else {
return 0;
}
}
/**
*
* @method
*
* Add case note.
*
* @name PMFAddCaseNote
* @label PMF Add case note
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFAddCaseNote.28.29
*
* @param string(32) | $caseUid | ID of the case | The unique ID of the case.
* @param string(32) | $processUid | ID of the process | The unique ID of the process.
* @param string(32) | $taskUid | ID of the task | The unique ID of the task.
* @param string(32) | $userUid | ID user | The unique ID of the user who will add note case.
* @param string | $note | Note of the case | Note of the case.
* @param int | $sendMail = 1 | Send mail | Optional parameter. If set to 1, will send an email to all participants in the case.
* @return int | $result | Result of the add case note | Returns 1 if the note has been added to the case.; otherwise, returns 0 if an error occurred.
*
*/
function PMFAddCaseNote($caseUid, $processUid, $taskUid, $userUid, $note, $sendMail = 1)
{
G::LoadClass("wsBase");
$ws = new wsBase();
$result = $ws->addCaseNote($caseUid, $processUid, $taskUid, $userUid, $note, $sendMail);
if ($result->status_code == 0) {
return 1;
} else {
return 0;
}
}
/**
*@method
*
* It adds an element to the asociative array of attached documents that will be sent by mail, if it exists a file with the same name, it wll return a generated name with an autoincrementable sequential number.
*
* @name PMFAddAttachmentToArray
* @label Add Element in Array
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#arrayDocumentAddElement.28.29
*
* @param array | $arrayData | Array that will contain new data | Array value comes where will contain the new data.
* @param string(32) | $index | Name of the index | New index name
* @param string(32) | $value | Index value | New value will contain the index
* @param string | $suffix = " Copy({i})" | Is suffix | A string that is concatenated to index different
* @return array | $arrayData | Array with new data | The array will contain the new data
*
*/
function PMFAddAttachmentToArray($arrayData, $index, $value, $suffix = " Copy({i})")
{
if (isset($suffix) && $suffix == "") {
$suffix = " Copy ({i})";
}
$newIndex = $index;
$count = 2;
$newIndexFormat = $index . $suffix;
if (preg_match("/^(.+)\.(.+)$/", $index, $arrayMatch)) {
$newIndexFormat = $arrayMatch[1] . $suffix . "." . $arrayMatch[2];
}
while (isset($arrayData[$newIndex])) {
$newIndex = str_replace("{i}", $count, $newIndexFormat);
$count = $count + 1;
}
$arrayData[$newIndex] = $value;
return $arrayData;
}
/**
*@method
*
* It delete the mask a field.
*
* @name PMFRemoveMask
* @label PMF Remove Mask
*
* @param string | $field | Value the field
* @param string | $separator | Separator of thousands (, or .)
* @param string | $currency | symbol of currency
* @return $field | value without mask
*
*/
function PMFRemoveMask ($field, $separator = '.', $currency = '')
{
$sep = array();
if ( trim($currency) != '') {
$sep[] = $currency;
}
$sep[] = ($separator == ',') ? '.' : ',';
$field = str_replace($sep, '', $field);
$field = trim(str_replace($separator, '.', $field));
return $field;
}