更新到 5.2 正式版后第一次 SVN 提交。

[email protected]


git-svn-id: https://svn.code.sf.net/p/hawebs/svn@584 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
YuCheng Hu
2010-11-15 14:12:36 +00:00
parent 2026863cdd
commit a8833bacfd
59 changed files with 0 additions and 8358 deletions
@@ -1,126 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
class VTConditionalExpression{
public function __construct($expression){
$parser = new VTConditionalParser($expression);
$this->expTree = $parser->parse();
}
public function evaluate($data){
$this->env=$data;
return $this->evalGate($this->expTree);
}
private function evalGate($tree){
if(in_array($tree[0], array("and", "or"))){
switch($tree[0]){
case "and":
return $this->evalGate($tree[1]) and $this->evalGate($tree[2]);
case "or":
return $this->evalGate($tree[1]) or $this->evalGate($tree[2]);
}
}else{
return $this->evalCondition($tree);
}
}
private function evalCondition($tree){
switch($tree[0]){
case "=":
return (int)$this->getVal($tree[1]) == (int)$this->getVal($tree[2]);
}
}
private function getVal($node){
list($valueType, $value) = $node;
switch($valueType){
case "sym":
return $this->env[$value];
case "num":
return $value;
}
}
}
class VTParseFailed extends Exception { }
/**
* This is a simple parser for conditional expressions used to trigger workflow actions.
*
*/
class VTConditionalParser{
public function __construct($expr){
$this->tokens = $this->getTokens($expr);
$this->pos = 0;
}
private function getTokens($expression){
preg_match_all('/and|or|\\d+|=|\\w+|\\(|\\)/',$expression, $matches, PREG_SET_ORDER);
$tokens=array();
foreach($matches as $arr){
$tokenVal = $arr[0];
if(in_array($tokenVal, array("and", "or", "=", "(", ")"))){
$tokenType = "op";
}else if(is_numeric($tokenVal)){
$tokenType = "num";
}else{
$tokenType = "sym";
}
$tokens[]=array($tokenType, $tokenVal);
}
return $tokens;
}
public function parse(){
$op = array(
"and"=>array("op", "and"),
"or"=>array("op", "or"),
"="=>array("op", "="),
"("=>array("op", "("),
")"=>array("op", ")"));
if($this->peek()==$op['(']){
$this->nextToken();
$left = $this->parse();
if($this->nextToken()!= $op[')']){
throw new VTParseFailed();
}
}else{
$left = $this->cond();
}
if(sizeof($this->tokens)>$this->pos and in_array($this->peek(), array($op["and"], $op["or"]))){
$nt = $this->nextToken();
return array($nt[1], $left, $this->parse());
}else{
return $left;
}
}
private function cond(){
$left = $this->nextToken();
$operator = $this->nextToken();
$right = $this->nextToken();
return array($operator[1], $left, $right);
}
private function peek(){
return $this->tokens[$this->pos];
}
private function nextToken(){
$this->pos+=1;
return $this->tokens[$this->pos - 1];
}
}
?>
@@ -1,29 +0,0 @@
<?php
/*+*******************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*
*********************************************************************************/
require_once 'modules/com_vtiger_workflow/VTSimpleTemplate.inc';
/**
* Description of VTEmailRecipientsTemplate
*
* @author MAK
*/
class VTEmailRecipientsTemplate extends VTSimpleTemplate {
public function __construct($templateString) {
parent::__construct($templateString);
}
protected function useValue($data, $fieldname) {
return !empty($data[$fieldname]) && $data['emailoptout'] == 0;
}
}
?>
@@ -1,89 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
class VTWorkflowEntity{
function __construct($user, $id){
$this->moduleName = null;
$this->id = $id;
$this->user = $user;
$data = vtws_retrieve($id, $user);
foreach($data as $key => $value){
if(is_string($value)){
$data[$key] = html_entity_decode($value, ENT_QUOTES, 'utf-8');
}
}
$this->data = $data;
}
/**
* Get the data from the entity object as an array.
*
* @return An array representation of the module data.
*/
function getData(){
return $this->data;
}
/**
* Get the entity id.
*
* @return The entity id.
*/
function getId(){
return $this->data['id'];
}
/**
* Get the name of the module represented by the entity data object.
*
* @return The module name.
*/
function getModuleName(){
if($this->moduleName==null){
global $adb;
$wsId = $this->data['id'];
$parts = explode('x', $wsId);
$result = $adb->pquery('select name from vtiger_ws_entity where id=?',
array($parts[0]));
$rowData = $adb->raw_query_result_rowdata($result, 0);
$this->moduleName = $rowData['name'];
}
return $this->moduleName;
}
function get($fieldName){
return $this->data[$fieldName];
}
function set($fieldName, $value){
$this->data[$fieldName] = $value;
}
function save(){
vtws_update($this->data,$this->user);
}
}
class VTEntityCache{
function __construct($user){
$this->user = $user;
$this->cache = array();
}
function forId($id){
if($this->cache[$id]==null){
$data = new VTWorkflowEntity($this->user, $id);
$this->cache[$id] = $data;
}
return $this->cache[$id];
}
}
?>
@@ -1,62 +0,0 @@
<?php
/*+*******************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
******************************************************************************/
require_once("include/events/SqlResultIterator.inc");
class VTEntityMethodManager{
function __construct($adb){
$this->adb = $adb;
}
function addEntityMethod($moduleName, $methodName, $functionPath, $functionName){
$adb = $this->adb;
$id = $adb->getUniqueId("com_vtiger_workflowtasks_entitymethod");
$adb->pquery("insert into com_vtiger_workflowtasks_entitymethod (workflowtasks_entitymethod_id, module_name, function_path, function_name, method_name) values (?,?,?,?,?)", array($id, $moduleName, $functionPath, $functionName, $methodName));
}
function executeMethod($entityData, $methodName){
$adb = $this->adb;
$moduleName = $entityData->getModuleName();
$result = $adb->pquery("select function_path, function_name from com_vtiger_workflowtasks_entitymethod where module_name=? and method_name=?", array($moduleName, $methodName));
if($adb->num_rows($result)!=0){
$data = $adb->raw_query_result_rowdata($result, 0);
$functionPath = $data['function_path'];
$functionName = $data['function_name'];
require_once($functionPath);
$functionName($entityData);
}
}
function methodsForModule($moduleName){
$adb = $this->adb;
$result = $adb->pquery("select method_name from com_vtiger_workflowtasks_entitymethod where module_name=?", array($moduleName));
$it = new SqlResultIterator($adb, $result);
$methodNames = array();
foreach($it as $row){
$methodNames[] = $row->method_name;
}
return $methodNames;
}
/*
private function methodExists($object, $methodName){
$className = get_class($object);
$class = new ReflectionClass($className);
$methods = $class->getMethods();
foreach($methods as $method){
if($method->getName()==$methodName){
return true;
}
}
return false;
}*/
}
?>
@@ -1,127 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once('include/events/SqlResultIterator.inc');
require_once('VTWorkflowManager.inc');
require_once('VTTaskManager.inc');
require_once('VTTaskQueue.inc');
require_once('VTEntityCache.inc');
require_once 'include/Webservices/Utils.php';
require_once("modules/Users/Users.php");
require_once("include/Webservices/VtigerCRMObject.php");
require_once("include/Webservices/VtigerCRMObjectMeta.php");
require_once("include/Webservices/DataTransform.php");
require_once("include/Webservices/WebServiceError.php");
require_once 'include/utils/utils.php';
require_once 'include/Webservices/ModuleTypes.php';
require_once('include/Webservices/Retrieve.php');
require_once('include/Webservices/Update.php');
require_once 'include/Webservices/WebserviceField.php';
require_once 'include/Webservices/EntityMeta.php';
require_once 'include/Webservices/VtigerWebserviceObject.php';
require_once('VTWorkflowUtils.php');
/*
* VTEventHandler
*/
class VTWorkflowEventHandler extends VTEventHandler{
/**
* Push tasks to the task queue if the conditions are true
* @param $entityData A VTEntityData object representing the entity.
*/
function handleEvent($eventName, $entityData){
$util = new VTWorkflowUtils();
$user = $util->adminUser();
global $adb;
$isNew = $entityData->isNew();
$entityCache = new VTEntityCache($user);
$wsModuleName = $util->toWSModuleName($entityData);
$wsId = vtws_getWebserviceEntityId($wsModuleName,
$entityData->getId());
$entityData = $entityCache->forId($wsId);
$data = $entityData->getData();
$wfs = new VTWorkflowManager($adb);
$workflows = $wfs->getWorkflowsForModule($entityData->getModuleName());
$tm = new VTTaskManager($adb);
$taskQueue = new VTTaskQueue($adb);
foreach($workflows as $workflow){
switch($workflow->executionCondition){
case VTWorkflowManager::$ON_FIRST_SAVE:{
if($isNew){
$doEvaluate = true;
}else{
$doEvaluate = false;
}
break;
}
case VTWorkflowManager::$ONCE:{
$entity_id = vtws_getIdComponents($entityData->getId());
$entity_id = $entity_id[1];
$result = $adb->pquery("SELECT * FROM com_vtiger_workflow_activatedonce
WHERE entity_id=? and workflow_id=?", array($entity_id, $workflow->id));
//Changes
$result2=$adb->pquery("SELECT * FROM com_vtiger_workflowtasks
INNER JOIN com_vtiger_workflowtask_queue
ON com_vtiger_workflowtasks.task_id= com_vtiger_workflowtask_queue.task_id
WHERE workflow_id=? AND entity_id=?",
array($workflow->id,$entity_id));
if($adb->num_rows($result)===0 && $adb->num_rows($result2)===0){
$doEvaluate = true;
}else{
$doEvaluate = false;
}
break;
}
case VTWorkflowManager::$ON_EVERY_SAVE:{
$doEvaluate = true;
break;
}
case VTWorkflowManager::$ON_MODIFY:{
$doEvaluate = !($isNew);
break;
}
default:{
throw new Exception("Should never come here! Execution Condition:".$workflow->executionCondition);
}
}
if($doEvaluate && $workflow->evaluate($entityCache, $entityData->getId())){
if(VTWorkflowManager::$ONCE == $workflow->executionCondition) {
$entity_id = vtws_getIdComponents($entityData->getId());
$entity_id = $entity_id[1];
$adb->pquery("INSERT INTO com_vtiger_workflow_activatedonce (entity_id, workflow_id)
VALUES (?,?)", array($entity_id, $workflow->id));
}
$tasks = $tm->getTasksForWorkflow($workflow->id);
foreach($tasks as $task){
if($task->active) {
$trigger = $task->trigger;
if($trigger != null){
$delay = strtotime($data[$trigger['field']])+$trigger['days']*86400;
}else{
$delay = 0;
}
if($task->executeImmediately==true){
$task->doTask($entityData);
}else{
$taskQueue->queueTask($task->id,$entityData->getId(), $delay);
}
}
}
}
}
$util->revertUser();
}
}
?>
@@ -1,112 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once("include/Zend/Json.php");
class VTJsonCondition{
function __construct(){
}
function evaluate($condition, $entityCache, $id){
$expr = Zend_Json::decode($condition);
$result=TRUE;
$data = $entityCache->forId($id)->getData();
foreach($expr as $cond){
preg_match('/(\w+) : \((\w+)\) (\w+)/', $cond['fieldname'], $matches);
if(count($matches)==0){
$result = $this->checkCondition($data, $cond);
}else{
list($full, $referenceField, $referenceModule, $fieldname) = $matches;
$referenceFieldId = $data[$referenceField];
if($referenceFieldId != 0){
$entity = $entityCache->forId($data[$referenceField]);
if($entity->getModuleName()==$referenceModule){
$entityData = $entity->getData();
$cond['fieldname'] = $fieldname;
$result = $this->checkCondition($entityData, $cond);
}else{
$result = false;
}
}else{
return false;
}
}
if($result==false){
return false;
}
}
return true;
}
function startsWith($str, $subStr){
$sl = strlen($str);
$ssl = strlen($subStr);
if($sl>=$ssl){
return substr_compare($str,$subStr,0, $ssl)==0;
}else{
return FALSE;
}
}
function endsWith($str, $subStr){
$sl = strlen($str);
$ssl = strlen($subStr);
if($sl>=$ssl){
return substr_compare($str,$subStr,$sl-$ssl, $ssl)==0;
}else{
return FALSE;
}
}
function checkCondition($data, $cond){
$condition = $cond['operation'];
$fieldValue=$data[$cond['fieldname']];
$value = html_entity_decode($cond['value']);
switch($condition){
case "equal to":
return $fieldValue == $value;
case "less than":
return $fieldValue < $value;
case "greater than":
return $fieldValue > $value;
case "does not equal":
return $fieldValue != $value;
case "less than or equal to":
return $fieldValue <= $value;
case "greater than or equal to":
return $fieldValue >= $value;
case "is":
if(preg_match('/([^:]+):boolean$/', $value, $match)){
$value = $match[1];
if($value=='true'){
return $fieldValue==='on' || $fieldValue===1 || $fieldValue==='1';
}else{
return $fieldValue==='off' || $fieldValue===0 || $fieldValue==='0' || $fieldValue==='';
}
}else{
return $fieldValue == $value;
}
case "contains":
return strpos($fieldValue, $value) !== FALSE;
case "does not contain":
return strpos($fieldValue, $value) === FALSE;
case "starts with":
return $this->startsWith($fieldValue,$value);
case "ends with":
return $this->endsWith($fieldValue, $value);
case "matches":
return preg_match($value, $fieldValue);
default:
//Unexpected condition
throw new Exception("Found an unexpected condition: ".$condition);
}
}
}
?>
@@ -1,96 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
class VTSimpleTemplate{
function __construct($templateString){
$this->template = $templateString;
}
function render($entityCache, $entityId){
$this->cache = $entityCache;
$this->parent = $this->cache->forId($entityId);
return $this->parseTemplate();
}
private function matchHandler($match){
preg_match('/\((\w+) : \(([_\w]+)\) (\w+)\)/', $match[1], $matches);
if(count($matches)==0){
$fieldname = $match[1];
$data = $this->parent->getData();
if($this->useValue($data, $fieldname)){
$result = $data[$fieldname];
}else{
$result ='';
}
}else{
list($full, $referenceField, $referenceModule, $fieldname) = $matches;
if($referenceModule === '__VtigerMeta__'){
$result = $this->getMetaValue($fieldname);
}else{
$referenceId = $this->parent->get($referenceField);
if($referenceId==null){
$result="";
}else{
$entity = $this->cache->forId($referenceId);
if($referenceModule==="Users" && $entity->getModuleName()=="Groups"){
list($groupEntityId, $groupId) = vtws_getIdComponents($referenceId);
require_once('include/utils/GetGroupUsers.php');
$ggu = new GetGroupUsers();
$ggu->getAllUsersInGroup($groupId);
$users = $ggu->group_users;
$parts = Array();
foreach($users as $userId){
$refId = vtws_getWebserviceEntityId("Users", $userId);
$entity = $this->cache->forId($refId);
$data = $entity->getData();
if($this->useValue($data, $fieldname)){
$parts[] = $data[$fieldname];
}
}
$result = implode(",", $parts);
}if($entity->getModuleName()===$referenceModule){
$data = $entity->getData();
if($this->useValue($data, $fieldname)){
$result = $data[$fieldname];
}else{
$result = '';
}
}else{
$result = '';
}
}
}
}
if(!empty($result)){
$result .= ',';
}
return $result;
}
protected function useValue($data, $fieldname) {
return !empty($data[$fieldname]);
}
function parseTemplate(){
return preg_replace_callback('/\\$(\w+|\((\w+) : \(([_\w]+)\) (\w+)\))\s*,?/', array($this,"matchHandler"), $this->template);
}
function getMetaValue($fieldname){
switch($fieldname){
case 'date': return getNewDisplayDate();
case 'time': return date('h-i-s');
default: '';
}
}
}
?>
@@ -1,153 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
/**
* Functionality to save and retrieve Tasks from the database.
*/
class VTTaskManager{
function __construct($adb){
$this->adb = $adb;
}
/**
* Save the task into the database.
*
* When a new task is saved for the first time a field is added to it called
* id that stores the task id used in the database.
*
* @param $summary A summary of the task instance.
* @param $task The task instance to save.
* @return The id of the task
*/
public function saveTask($task){
$adb = $this->adb;
if(is_numeric($task->id)){//How do I check whether a member exists in php?
$taskId = $task->id;
$adb->pquery("update com_vtiger_workflowtasks set summary=?, task=? where task_id=?",
array($task->summary, serialize($task), $taskId));
return $taskId;
}else{
$taskId = $adb->getUniqueID("com_vtiger_workflowtasks");
$task->id = $taskId;
$adb->pquery("insert into com_vtiger_workflowtasks
(task_id, workflow_id, summary, task)
values (?, ?, ?, ?)",
array($taskId, $task->workflowId, $task->summary, serialize($task)));
return $taskId;
}
}
public function deleteTask($taskId){
$adb = $this->adb;
$adb->pquery("delete from com_vtiger_workflowtasks where task_id=?", array($taskId));
}
/**
* Create a new class instance
*/
public function createTask($taskType, $workflowId){
$taskClass = $taskType;
$this->requireTask($taskType);
$task = new $taskClass();
$task->workflowId=$workflowId;
$task->summary = "";
$task->active=true;
return $task;
}
/**
* Retrieve a task from the database
*
* @param $taskId The id of the task to retrieve.
* @return The retrieved task.
*/
public function retrieveTask($taskId){
$adb = $this->adb;
$result = $adb->pquery("select task from com_vtiger_workflowtasks where task_id=?", array($taskId));
$data = $adb->raw_query_result_rowdata($result, 0);
$task = $data["task"];
return $this->unserializeTask($task);
}
/**
*
*/
public function getTasksForWorkflow($workflowId){
$adb = $this->adb;
$result = $adb->pquery("select task from com_vtiger_workflowtasks
where workflow_id=?",
array($workflowId));
return $this->getTasksForResult($result);
}
/**
*
*/
public function unserializeTask($str){
$this->requireTask(self::taskName($str));
return unserialize($str);
}
/**
*
*/
function getTasks(){
$adb = $this->adb;
$result = $adb->query("select task from com_vtiger_workflowtasks");
return $this->getTasksForResult($result);
}
function getTaskTypes(){
$taskTypes = array("VTEmailTask", "VTEntityMethodTask", "VTCreateTodoTask","VTCreateEventTask");
// Make SMSTask available if module is active
// TODO Generic way of handling this could be helpful
if(getTabid('SMSNotifier') && vtlib_isModuleActive('SMSNotifier')) {
$taskTypes [] = 'VTSMSTask';
}
return $taskTypes;
}
private function getTasksForResult($result){
$adb = $this->adb;
$it = new SqlResultIterator($adb, $result);
$tasks = array();
foreach($it as $row){
$text = $row->task;
$this->requireTask(self::taskName($text));
$tasks[] = unserialize($text);
}
return $tasks;
}
private function taskName($serializedTask){
$matches = array();
preg_match ('/"([^"]+)"/', $serializedTask, $matches);
return $matches[1];
}
private function requireTask($taskType){
require_once("tasks/".$taskType.".inc");
}
}
abstract class VTTask{
public abstract function doTask($data);
public abstract function getFieldNames();
}
//require 'modules/Workflow/tasks/VTEmailTask.inc';
?>
@@ -1,65 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
/**
* Time based Queue of tasks ready for execution.
*
*/
class VTTaskQueue{
public function __construct($adb){
$this->adb = $adb;
}
/**
* Queue a task for execution.
*
* @param $taskId The id of the task to queue
* @param $entityId The id of the crm entity the task is assiciated with.
* @param $when The time after which the task should be executed. This is
* an optional value with a default value of 0.
*/
public function queueTask($taskId, $entityId, $when=0){
$adb = $this->adb;
$result = $adb->pquery("select * from com_vtiger_workflowtask_queue
where task_id=? and entity_id=?", array($taskId, $entityId));
if($adb->num_rows($result)==1){
return false;
}else{
$adb->pquery("insert into com_vtiger_workflowtask_queue (task_id, entity_id, do_after)
values (?,?,?)", array($taskId, $entityId, $when));
return true;
}
}
/**
* Get a list of taskId/entityId pairs ready for execution.
*
* The method fetches task id/entity id where the when timestamp
* is less than the current time when the method was called.
*
* @return A list of pairs of the form array(taskId, entityId)
*/
public function getReadyTasks(){
$adb = $this->adb;
$time = time();
$result = $adb->pquery("select task_id, entity_id from com_vtiger_workflowtask_queue where do_after<?", array($time));
$it = new SqlResultIterator($adb, $result);
$arr = array();
foreach($it as $row){
$arr[]=array($row->task_id, $row->entity_id);
}
$adb->pquery("delete from com_vtiger_workflowtask_queue where do_after<?", array($time));
return $arr;
}
}
?>
@@ -1,75 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
class VTWorkflowApplication{
function __construct($action){
global $_REQUEST;
$this->request;
$this->name = "com_vtiger_workflow";
$this->label = "Workflow";
$this->action = $action;
$this->returnUrl = $_SERVER["REQUEST_URI"];
}
function currentUrl(){
// $req = $this->request;
// $url = "index.php?module={$this->name}&action={$this->action}";
// if($this->action=='editworkflow'){
// if(isset($req['workflow_id'])){
// $url.="&workflow_id=".$req['workflow_id'];
// }
// }else if($this->action=='edittask'){
// if(isset($req['task_id'])){
// $url.="&task_id=".$req['task_id'];
// }
// }
return $_SERVER["REQUEST_URI"];
}
function returnUrl(){
return $this->returnUrl;
}
function listViewUrl(){
return "index.php?module={$this->name}&action=workflowlist";
}
function editWorkflowUrl($id=null){
if($id!=null){
$idPart="&workflow_id=$id";
}
return "index.php?module={$this->name}&action=editworkflow$idPart&return_url=".urlencode($this->returnUrl());
}
function deleteWorkflowUrl($id){
$idPart="&workflow_id=$id";
return "index.php?module={$this->name}&action=deleteworkflow$idPart&return_url=".urlencode($this->returnUrl());
}
function editTaskUrl($id=null){
if($id!=null){
$idPart="&task_id=$id";
}
return "index.php?module={$this->name}&action=edittask$idPart&return_url=".urlencode($this->returnUrl());
}
function deleteTaskUrl($id){
$idPart="&task_id=$id";
return "index.php?module={$this->name}&action=deletetask$idPart&return_url=".urlencode($this->returnUrl());
}
function setReturnUrl($returnUrl){
$this->returnUrl = $returnUrl;
}
function errorPageUrl($message){
return "index.php?module={$this->name}&action=errormessage&message=".urlencode($message);
}
}
?>
@@ -1,210 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once("VTJsonCondition.inc");
class VTWorkflowManager{
static $ON_FIRST_SAVE = 1;
static $ONCE = 2;
static $ON_EVERY_SAVE = 3;
static $ON_MODIFY = 4;
function __construct($adb){
$this->adb = $adb;
}
function save($workflow){
$adb=$this->adb;
if(isset($workflow->id)){
$wf=$workflow;
$adb->pquery("update com_vtiger_workflows set
module_name=?, summary=?, test=?, execution_condition=?
where workflow_id=?",
array($wf->moduleName, $wf->description, $wf->test, $wf->executionCondition, $wf->id));
}else{
$workflowId = $adb->getUniqueID("com_vtiger_workflows");
$workflow->id = $workflowId;
$wf=$workflow;
$adb->pquery("insert into com_vtiger_workflows
(workflow_id, module_name, summary, test, execution_condition)
values (?,?,?,?,?)",
array($workflowId, $wf->moduleName, $wf->description, $wf->test, $wf->executionCondition));
}
}
function getWorkflows(){
$adb=$this->adb;
$result=$adb->getColumnNames("com_vtiger_workflows");
if(in_array("defaultworkflow",$result)){
$result = $adb->query("select workflow_id, module_name, summary, test, execution_condition,defaultworkflow
from com_vtiger_workflows ");
}else{
$result = $adb->query("select workflow_id, module_name, summary, test, execution_condition
from com_vtiger_workflows");
}
return $this->getWorkflowsForResult($result);
}
function getWorkflowsForModule($moduleName){
$adb=$this->adb;
//my changes
$result=$adb->getColumnNames("com_vtiger_workflows");
if(in_array(defaultworkflow,$result)){
$result = $adb->pquery("select workflow_id, module_name, summary, test, execution_condition,defaultworkflow
from com_vtiger_workflows where module_name=?",array($moduleName));
}
else{
$result = $adb->pquery("select workflow_id, module_name, summary, test, execution_condition
from com_vtiger_workflows where module_name=?",array($moduleName));
}
return $this->getWorkflowsForResult($result);
}
private function getWorkflowsForResult($result){
$adb=$this->adb;
$it = new SqlResultIterator($adb, $result);
$workflows=array();
foreach($it as $row){
$workflow=new Workflow();
$workflow->id = $row->workflow_id;
$workflow->moduleName = $row->module_name;
$workflow->description = $row->summary;
$workflow->test = $row->test;
$workflow->executionCondition = $row->execution_condition;
if($row->defaultworkflow){
$workflow->defaultworkflow=$row->defaultworkflow;
}
$workflows[]=$workflow;
}
return $workflows;
}
/**
* Retrieve a workflow from the database
*
* Returns null if the workflow doesn't exist.
*
* @param The id of the workflow
* @return A workflow object.
*/
function retrieve($id){
$adb=$this->adb;
$workflow=new Workflow();
$result = $adb->pquery("select workflow_id, module_name, summary, test, execution_condition
from com_vtiger_workflows where workflow_id=?",
array($id));
if($adb->num_rows($result)){
$data = $adb->raw_query_result_rowdata($result, 0);
$workflow->id = $data["workflow_id"];
$workflow->moduleName = $data["module_name"];
$workflow->description = $data["summary"];
$workflow->test = $data["test"];
$workflow->executionCondition = $data['execution_condition'];
return $workflow;
}else{
return null;
}
}
function delete($id){
$adb=$this->adb;
$adb->pquery("delete from com_vtiger_workflowtasks where workflow_id=?", array($id));
$adb->pquery("delete from com_vtiger_workflows where workflow_id=?", array($id));
}
function newWorkflow($moduleName){
$workflow=new Workflow();
$workflow->moduleName = $moduleName;
$workflow->executionCondition = self::$ON_EVERY_SAVE;
return $workflow;
}
/**
* Export a workflow as a json encoded string
*
* @param $workflow The workflow instance to export.
*/
public function serializeWorkflow($workflow){
$exp = array();
$exp['moduleName'] = $workflow->moduleName;
$exp['description'] = $workflow->description;
$exp['test'] = $workflow->test;
$exp['executionCondition'] = $workflow->executionCondition;
$exp['tasks'] = array();
$tm = new VTTaskManager($this->adb);
$tasks = $tm->getTasksForWorkflow($workflow->id);
foreach($tasks as $task){
unset($task->id);
unset($task->workflowId);
$exp['tasks'][] = serialize($task);
}
return Zend_Json::encode($exp);
}
/**
* Import a json encoded string as a workflow object
*
* @return The Workflow instance representing the imported workflow.
*/
public function deserializeWorkflow($str){
$data = Zend_Json::decode($str);
$workflow = $this->newWorkflow($data['moduleName']);
$workflow->description = $data['description'];
$workflow->test = $data['test'];
$workflow->executionCondition = $data['executionCondition'];
$this->save($workflow);
$tm = new VTTaskManager($this->adb);
$tasks = $data['tasks'];
foreach($tasks as $taskStr){
$task = $tm->unserializeTask($taskStr);
$task->workflowId = $workflow->id;
$tm->saveTask($task);
}
return $workflow;
}
}
class Workflow{
function __construct(){
$this->conditionStrategy = new VTJsonCondition();
}
function evaluate($entityCache, $id){
if($this->test==""){
return true;
}else{
$cs = $this->conditionStrategy;
return $cs->evaluate($this->test,
$entityCache, $id);
}
}
function executionConditionAsLabel($label=null){
if($label==null){
$arr = array('ON_FIRST_SAVE', 'ONCE', 'ON_EVERY_SAVE','ON_MODIFY');
return $arr[$this->executionCondition-1];
}else{
$arr = array('ON_FIRST_SAVE'=>1, 'ONCE'=>2, 'ON_EVERY_SAVE'=>3, 'ON_MODIFY'=>4);
$this->executionCondition = $arr[$label];
}
}
}
?>
@@ -1,197 +0,0 @@
<?php
/*+********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
********************************************************************************/
class VTWorkflowTemplateManager{
public function __construct($adb){
$this->adb = $adb;
}
/**
* Create anew template instance from a workflow
*
* This template instance will not be saved. The save
* will have to be done explicitly.
*
* @param $title The title of the template
* @param $workflow A workflow instance.
*/
public function newTemplate($title, $workflow){
$adb = $this->adb;
$wms = new VTWorkflowManager($adb);
$str = $wms->serializeWorkflow($workflow);
$template = new VTWorkflowTemplate();
$template->title = $title;
$template->moduleName = $workflow->moduleName;
$template->template = $str;
return $template;
}
/**
* Retrieve a template given it's id
*
* @param $templateId The id of the template
* @return The template object
*/
public function retrieveTemplate($templateId){
$adb = $this->adb;
$result = $adb->pquery('select * from com_vtiger_workflowtemplates where template_id=?', array($templateId));
$it = new SqlResultIterator($adb, $result);
$data = $it->current();
$template = new VTWorkflowTemplate();
$template->id = $templateId;
$template->title = $data->title;
$template->moduleName = $data->module_name;
$template->template = $data->template;
return $template;
}
/**
* Create a workflow from a template
*
* The new workflow will also be added to the database.
*
* @param $template The template to use
* @return A workflow object.
*/
public function createWorkflow($template){
$adb = $this->adb;
$wfm = new VTWorkflowManager($adb);
return $wfm->deserializeWorkflow($template->template);
}
/**
* Get template objects for a particular module.
*
* @param $moduleName The name of the module
* @return An array containing template objects
*/
public function getTemplatesForModule($moduleName){
$adb = $this->adb;
$result = $adb->pquery("select * from com_vtiger_workflowtemplates where module_name=?", array($moduleName));
return $this->getTemplatesForResult($result);
}
/**
* Get all templates
*
* Get all the templates as an array
*
* @return An array containing template objects.
*/
public function getTemplates(){
$adb = $this->adb;
$result = $adb->query("select * from com_vtiger_workflowtemplates");
return $this->getTemplatesForResult($result);
}
/**
* Save a template
*
* If the object is a newly created template it
* will be added to the database and a field id containing
* the new id will be added to the object.
*
* @param $template The template object to save.
*/
public function saveTemplate($template){
$adb = $this->adb;
if(is_numeric($template->id)){//How do I check whether a member exists in php?
$templateId = $template->id;
$adb->pquery("update com_vtiger_workflowtemplates set title=?,"+
" module_name=?, template=? where template_id=?",
array($template->title, $template->moduleName,
$template->template, $templateId));
return $templateId;
}else{
$templateId = $adb->getUniqueID("com_vtiger_workflowtemplates");
$template->id = $templateId;
$adb->pquery("insert into com_vtiger_workflowtemplates
(template_id, title, module_name, template)
values (?, ?, ?, ?)",
array($templateId, $template->title,
$template->moduleName, $template->template));
return $templateId;
}
}
/**
* Delete a template
*
* $templateId The id of the template to delete.
*/
public function deleteTemplate($templateId){
$adb = $this->adb;
$adb->pquery('delete from com_vtiger_workflowtemplates where template_id=?',
array($templateId));
}
/**
* Dump all the templates in vtiger into a string
*
* This can be used for exporting templates from one
* machine to another
*
* @return The string dump of the templates.
*/
public function dumpAllTemplates(){
$adb = $this->adb;
$result = $adb->query("select * from com_vtiger_workflowtemplates");
$it = new SqlResultIterator($adb, $result);
$arr = array();
foreach($it as $row){
$el = array(
'moduleName'=>$row->module_name,
'title'=>$row->title,
'template'=>$row->template
);
$arr[] = $el;
}
return Zend_Json::encode($arr);
}
/**
* Load templates form a dumped string
*
* @param $str The string dump generated from dumpAllTemplates
*/
public function loadTemplates($str){
$arr = Zend_Json::decode($str);
foreach($arr as $el){
$template = new VTWorkflowTemplate();
$template->moduleName = $el['moduleName'];
$template->title = $el['title'];
$template->template = $el['template'];
$this->save($template);
$this->createWorkflow($template);
}
}
private function getTemplatesForResult($result){
$adb = $this->adb;
$it = new SqlResultIterator($adb, $result);
$templates = array();
foreach($it as $row){
$template = new VTWorkflowTemplate();
$template->id = $row->template_id;
$template->title = $row->title;
$tempalte->moduleName = $row->module_name;
$template->template = $row->template;
$templates[] = $template;
}
return $templates;
}
}
class VTWorkflowTemplate{
}
?>
@@ -1,132 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
//A collection of util functions for the workflow module
class VTWorkflowUtils{
function __construct(){
global $current_user;
$this->userStack = array();
}
/**
* Check whether the given identifier is valid.
*/
function validIdentifier($identifier){
if(is_string($identifier)){
return preg_match("/^[a-zA-Z][a-zA-Z_0-9]+$/", $identifier);
}else{
return false;
}
}
/**
* Push the admin user on to the user stack
* and make it the $current_user
*
*/
function adminUser(){
$user = new Users();
$user->retrieveCurrentUserInfoFromFile(1);
global $current_user;
array_push($this->userStack, $current_user);
$current_user = $user;
return $user;
}
/**
* Revert to the previous use on the user stack
*/
function revertUser(){
global $current_user;
if(count($this->userStack)!=0){
$current_user = array_pop($this->userStack);
}else{
$current_user = null;
}
return $current_user;
}
/**
* Get the current user
*/
function currentUser(){
return $current_user;
}
/**
* The the webservice entity type of an EntityData object
*/
function toWSModuleName($entityData){
$moduleName = $entityData->getModuleName();
if($moduleName == 'Activity'){
$arr = array('Task' => 'Calendar', 'Emails' => 'Emails');
$moduleName = $arr[getActivityType($entityData->getId())];
if($moduleName == null){
$moduleName = 'Events';
}
}
return $moduleName;
}
/**
* Insert redirection script
*/
function redirectTo($to, $message){
?>
<script type="text/javascript" charset="utf-8">
window.location="<?=$to?>";
</script>
<a href="<?=$to?>"><?=$message?></a>
<?php
}
/**
* Check if the current user is admin
*/
function checkAdminAccess(){
global $current_user;
return strtolower($current_user->is_admin)==='on';
}
/* function to check if the module has workflow
* @params :: $modulename - name of the module
*/
function checkModuleWorkflow($modulename){
global $adb;
$tabid = getTabid($modulename);
$modules_not_supported = array('Documents','Calendar','Emails','Faq','Events','PBXManager','Users');
$query = "SELECT name FROM vtiger_tab WHERE name not in (".generateQuestionMarks($modules_not_supported).") AND isentitytype=1 AND presence = 0 AND tabid = ?";
$result = $adb->pquery($query,array($modules_not_supported,$tabid));
$rows = $adb->num_rows($result);
if($rows > 0){
return true;
}else{
return false;
}
}
function vtGetModules($adb){
$modules_not_supported = array('Documents','Calendar','Emails','Faq','Events','PBXManager','Users');
$sql="select distinct vtiger_field.tabid, name
from vtiger_field
inner join vtiger_tab
on vtiger_field.tabid=vtiger_tab.tabid
where vtiger_tab.name not in(".generateQuestionMarks($modules_not_supported).") and vtiger_tab.isentitytype=1 and vtiger_tab.presence = 0 ";
$it = new SqlResultIterator($adb, $adb->pquery($sql,array($modules_not_supported)));
$modules = array();
foreach($it as $row){
$modules[] = $row->name;
}
return $modules;
}
}
?>
@@ -1,12 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once('include/Ajax/CommonAjax.php');
?>
@@ -1,45 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once("include/utils/CommonUtils.php");
require_once("include/events/SqlResultIterator.inc");
require_once("include/Zend/Json.php");
require_once("VTWorkflowApplication.inc");
require_once("VTTaskManager.inc");
require_once('VTWorkflowUtils.php');
function vtDeleteWorkflow($adb, $request){
$util = new VTWorkflowUtils();
$module = new VTWorkflowApplication("deltetask");
$mod = return_module_language($current_language, $module->name);
if(!$util->checkAdminAccess()){
$errorUrl = $module->errorPageUrl($mod['LBL_ERROR_NOT_ADMIN']);
$util->redirectTo($errorUrl, $mod['LBL_ERROR_NOT_ADMIN']);
return;
}
$wm = new VTTaskManager($adb);
$wm->deleteTask($request['task_id']);
if(isset($request["return_url"])){
$returnUrl=$request["return_url"];
}else{
$returnUrl=$module->editWorkflowUrl($wf->id);
}
?>
<script type="text/javascript" charset="utf-8">
window.location="<?=$returnUrl?>";
</script>
<a href="<?=$returnUrl?>">Return</a>
<?php
}
vtDeleteWorkflow($adb, $_REQUEST);
?>
@@ -1,44 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once("include/utils/CommonUtils.php");
require_once("include/events/SqlResultIterator.inc");
require_once("include/Zend/Json.php");
require_once("VTWorkflowApplication.inc");
require_once("VTWorkflowManager.inc");
require_once("VTWorkflowUtils.php");
function vtDeleteWorkflow($adb, $request){
$util = new VTWorkflowUtils();
$module = new VTWorkflowApplication("deleteworkflow");
$mod = return_module_language($current_language, $module->name);
if(!$util->checkAdminAccess()){
$errorUrl = $module->errorPageUrl($mod['LBL_ERROR_NOT_ADMIN']);
$util->redirectTo($errorUrl, $mod['LBL_ERROR_NOT_ADMIN']);
return;
}
$wm = new VTWorkflowManager($adb);
$wm->delete($request['workflow_id']);
if(isset($request["return_url"])){
$returnUrl=$request["return_url"];
}else{
$returnUrl=$module->listViewUrl($wf->id);
}
?>
<script type="text/javascript" charset="utf-8">
window.location="<?=$returnUrl?>";
</script>
<a href="<?=$returnUrl?>">Return</a>
<?php
}
vtDeleteWorkflow($adb, $_REQUEST);
?>
@@ -1,119 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once("Smarty_setup.php");
require_once("include/utils/CommonUtils.php");
require_once("include/events/SqlResultIterator.inc");
require_once("include/events/VTWSEntityType.inc");
require_once("VTWorkflowApplication.inc");
require_once("VTTaskManager.inc");
require_once("VTWorkflowManager.inc");
require_once("VTWorkflowUtils.php");
function vtTaskEdit($adb, $request, $current_language, $app_strings){
global $theme;
$util = new VTWorkflowUtils();
$image_path = "themes/$theme/images/";
$module = new VTWorkflowApplication('edittask');
$mod = return_module_language($current_language, $module->name);
if(!$util->checkAdminAccess()){
$errorUrl = $module->errorPageUrl($mod['LBL_ERROR_NOT_ADMIN']);
$util->redirectTo($errorUrl, $mod['LBL_ERROR_NOT_ADMIN']);
return;
}
$smarty = new vtigerCRM_Smarty();
$tm = new VTTaskManager($adb);
$smarty->assign('edit',isset($request["task_id"]));
if(isset($request["task_id"])){
$task = $tm->retrieveTask($request["task_id"]);
$workflowId=$task->workflowId;
}else{
$workflowId = $request["workflow_id"];
$taskClass = $request["task_type"];
$task = $tm->createTask($taskClass, $workflowId);
}
if($task==null){
$errorUrl = $module->errorPageUrl($mod['LBL_ERROR_NO_TASK']);
$util->redirectTo($errorUrl, $mod['LBL_ERROR_NO_TASK']);
return;
}
$wm = new VTWorkflowManager($adb);
$workflow = $wm->retrieve($workflowId);
if($workflow==null){
$errorUrl = $module->errorPageUrl($mod['LBL_ERROR_NO_WORKFLOW']);
$util->redirectTo($errorUrl, $mod['LBL_ERROR_NO_WORKFLOW']);
return;
}
$smarty->assign("workflow", $workflow);
$smarty->assign("returnUrl", $request["return_url"]);
$smarty->assign("task", $task);
$smarty->assign("taskType", $taskClass);
$smarty->assign("saveType", $request['save_type']);
$taskClass = get_class($task);
$smarty->assign("taskTemplate", "{$module->name}/taskforms/$taskClass.tpl");
$et = VTWSEntityType::usingGlobalCurrentUser($workflow->moduleName);
$smarty->assign("entityType", $et);
$smarty->assign('entityName', $workflow->moduleName);
$smarty->assign("fieldNames", $et->getFieldNames());
$dateFields = array();
$fieldTypes = $et->getFieldTypes();
$fieldLabels = $et->getFieldLabels();
foreach($fieldTypes as $name => $type){
if($type->type=='Date' || $type->type=='DateTime'){
$dateFields[$name] = $fieldLabels[$name];
}
}
$smarty->assign('dateFields', $dateFields);
if($task->trigger!=null){
$trigger = $task->trigger;
$days = $trigger['days'];
if ($days < 0){
$days*=-1;
$direction = 'before';
}else{
$direction = 'after';
}
$smarty->assign('trigger', array('days'=>$days, 'direction'=>$direction,
'field'=>$trigger['field']));
}
$curr_date="(general : (__VtigerMeta__) date)";
$curr_time='(general : (__VtigerMeta__) time)';
$smarty->assign("DATE",$curr_date);
$smarty->assign("TIME",$curr_time);
$smarty->assign("MOD", array_merge(
return_module_language($current_language,'Settings'),
return_module_language($current_language, 'Calendar'),
return_module_language($current_language, $module->name)));
$smarty->assign("APP", $app_strings);
$smarty->assign("dateFormat", parse_calendardate($app_strings['NTC_DATE_FORMAT']));
$smarty->assign("IMAGE_PATH",$image_path);
$smarty->assign("THEME", $theme);
$smarty->assign("MODULE_NAME", $module->label);
$smarty->assign("PAGE_NAME", $mod['LBL_EDIT_TASK']);
$smarty->assign("PAGE_TITLE", $mod['LBL_EDIT_TASK_TITLE']);
$smarty->assign("module", $module);
$smarty->display("{$module->name}/EditTask.tpl");
}
vtTaskEdit($adb, $_REQUEST, $current_language, $app_strings);
?>
@@ -1,87 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once("Smarty_setup.php");
require_once("include/utils/CommonUtils.php");
require_once("include/Zend/Json.php");
require_once("include/events/SqlResultIterator.inc");
require_once("include/events/VTWSEntityType.inc");
require_once("VTWorkflowManager.inc");
require_once("VTTaskManager.inc");
require_once("VTWorkflowApplication.inc");
require_once "VTWorkflowTemplateManager.inc";
require_once "VTWorkflowUtils.php";
function vtWorkflowEdit($adb, $request, $requestUrl, $current_language, $app_strings){
global $theme;
$util = new VTWorkflowUtils();
$image_path = "themes/$theme/images/";
$module = new VTWorkflowApplication("editworkflow");
$mod = return_module_language($current_language, $module->name);
if(!$util->checkAdminAccess()){
$errorUrl = $module->errorPageUrl($mod['LBL_ERROR_NOT_ADMIN']);
$util->redirectTo($errorUrl, $mod['LBL_ERROR_NOT_ADMIN']);
return;
}
$smarty = new vtigerCRM_Smarty();
if($request['source']=='from_template'){
$tm = new VTWorkflowTemplateManager($adb);
$template = $tm->retrieveTemplate($request['template_id']);
$workflow = $tm->createWorkflow($template);
}else{
$wfs = new VTWorkflowManager($adb);
if(isset($request["workflow_id"])){
$workflow = $wfs->retrieve($request["workflow_id"]);
}else{
$moduleName=$request["module_name"];
$workflow = $wfs->newWorkflow($moduleName);
}
}
if($workflow==null){
$errorUrl = $module->errorPageUrl($mod['LBL_ERROR_NO_WORKFLOW']);
$util->redirectTo($errorUrl, $mod['LBL_ERROR_NO_WORKFLOW']);
return;
}
$workflow->test = addslashes($workflow->test);
$tm = new VTTaskManager($adb);
$tasks = $tm->getTasksForWorkflow($workflow->id);
$smarty->assign("tasks", $tasks);
$smarty->assign("taskTypes", $tm->getTaskTypes());
$smarty->assign("newTaskReturnUrl", $requestUrl);
$smarty->assign("returnUrl", $request["return_url"]);
$smarty->assign("APP", $app_strings);
$smarty->assign("MOD", array_merge(
return_module_language($current_language,'Settings'),
return_module_language($current_language, $module->name)));
$smarty->assign("THEME", $theme);
$smarty->assign("IMAGE_PATH", $image_path);
$smarty->assign("MODULE_NAME", $module->label);
$smarty->assign("PAGE_NAME", $mod['LBL_EDIT_WORKFLOW']);
$smarty->assign("PAGE_TITLE", $mod['LBL_EDIT_WORKFLOW_TITLE']);
$smarty->assign("workflow", $workflow);
$smarty->assign("saveType", isset($workflow->id)?"edit":"new");
$smarty->assign("module", $module);
$smarty->display("{$module->name}/EditWorkflow.tpl");
}
vtWorkflowEdit($adb, $_REQUEST, $_SERVER["REQUEST_URI"], $current_language, $app_strings);
?>
@@ -1,21 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once("include/Zend/Json.php");
require_once('modules/com_vtiger_workflow/VTEntityMethodManager.inc');
function vtEntityMethodJson($adb, $request){
$moduleName = $request['module_name'];
$emm = new VTEntityMethodManager($adb);
$methodNames = $emm->methodsForModule($moduleName);
echo Zend_Json::encode($methodNames);
}
vtEntityMethodJson($adb, $_REQUEST);
?>
@@ -1,12 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
?>
<h1>Error</h1>
<?=htmlentities($_REQUEST['message'])?>
@@ -1,18 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
function displayErrorPage($request){
?>
<h1>Workflow engine error</h1>
<?="It appears that you have entered an invalid value."?>
<?php
}
displayErrorPage($_REQUEST);
?>
@@ -1,15 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once 'include/events/SqlResultIterator.inc';
require 'VTWorkflowManager.inc';
require 'VTTaskManager.inc';
require 'VTWorkflowTemplateManager.inc';
require 'VTTaskQueue.inc';
?>
@@ -1,18 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once 'include/Webservices/Utils.php';
require_once("modules/Users/Users.php");
require_once("include/Webservices/VtigerCRMObject.php");
require_once("include/Webservices/VtigerCRMObjectMeta.php");
require_once("include/Webservices/DataTransform.php");
require_once("include/Webservices/WebServiceError.php");
require_once 'include/utils/utils.php';
require_once 'include/Webservices/ModuleTypes.php';
?>
@@ -1,44 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
$mod_strings = array(
'VTEmailTask' => 'Send Email',
'VTEntityMethodTask' => 'Invoke Custom Function',
'VTCreateTodoTask' => 'Create Todo',
'VTCreateEventTask' => 'Create Event',
'VTSMSTask' => 'SMS Task',
'LBL_EDIT_TASK'=>'Edit Task',
'LBL_EDIT_TASK_TITLE'=>'Edit an existing task or create a new one',
'LBL_EDIT_WORKFLOW'=>'Edit Workflow',
'LBL_EDIT_WORKFLOW_TITLE'=>'Edit an existing workflow or create a one',
'LBL_FROM_TEMPLATE'=>'From Template',
'LBL_NEW_WORKFLOW'=>'New Workflow',
'LBL_NEW_TEMPLATE'=>'Save as Template',
'LBL_CREATE_WORKFLOW_FOR'=>'Create a workflow for',
'LBL_FOR_MODULE'=>'For Module',
'LBL_CHOOSE_A_TEMPLATE'=>'Choose a template',
'LBL_VALIDATION_MISSING_MANDATORY_FIELDS'=>'There are empty mandatory fields.',
'LBL_VALIDATION_INVALID_DATE_RANGE'=>'Start date/time is greater than the end date/time',
'LBL_ERROR_NO_WORKFLOW'=>'The workflow you requested does not exist',
'LBL_ERROR_NO_TASK'=>'The task you requested does not exist',
'LBL_ERROR_NOT_ADMIN'=>'You do not have access to this module as you are not an admin user',
'LBL_CREATE_WORKFLOW'=>'Create workflow',
'LBL_WORKFLOW_LIST'=>'Workflow List',
'LBL_AVAILABLE_WORKLIST_LIST'=>'Available Workflows',
'LBL_LOADING'=>'Loading...',
'LBL_VALIDATION_ERROR'=>'Validation Error',
'LBL_SELECT_OPTION_DOTDOTDOT'=>'Select Option...',
'LBL_WORKFLOW_NOTE_CRON_CONFIG'=>'NOTE: You should have Workflow cron script configured.',
'LBL_NO_TEMPLATES'=>'No Templates',
'LBL_SELECT'=>'Select',
'LBL_MESSAGE'=>'Message',
);
?>
@@ -1,55 +0,0 @@
<?php
/**
*Copyright(C)2006-2010 YUCHENG HU
*
*---------------------------------------------
*HAWEBSYSTEMS
*http://www.hawebs.net
*https://www.hawebs.org/forums/computer/
*
*CONTACT
*[email protected]/[email protected]
*
*---------------------------------------------
*[A]GNUGENERALPUBLICLICENSEGNU/LGPL
*[B]ApacheLicense,Version2.0
*
*---------------------------------------------
*NOTE
*1.所有的语言配置文件请采用UTF-8编码
*
*---------------------------------------------
*/
$mod_strings = array(
'VTEmailTask' => '发送邮件',
'VTEntityMethodTask' => '自定义函数',
'VTCreateTodoTask' => '创建待办事项',
'VTCreateEventTask' => '创建活动',
'LBL_EDIT_TASK'=>'编辑任务',
'LBL_EDIT_TASK_TITLE'=>'编辑现有的任务或者创建新任务',
'LBL_EDIT_WORKFLOW'=>'编辑工作流程',
'LBL_EDIT_WORKFLOW_TITLE'=>'编辑现有的工作流程或者创建新流程',
'LBL_FROM_TEMPLATE'=>'从模板',
'LBL_NEW_WORKFLOW'=>'新流程',
'LBL_NEW_TEMPLATE'=>'保存为模板',
'LBL_CREATE_WORKFLOW_FOR'=>'新的工作流程',
'LBL_FOR_MODULE'=>'的模块',
'LBL_FROM_TEMPLATE'=>'从模板',
'LBL_CHOOSE_A_TEMPLATE'=>'选择模板',
'LBL_VALIDATION_MISSING_MANDATORY_FIELDS'=>'有空必填。',
'LBL_VALIDATION_INVALID_DATE_RANGE'=>'开始的日期/时间大于结束日期/时间。',
'LBL_ERROR_NO_WORKFLOW'=>'你请求的工作流程不存在。 ',
'LBL_ERROR_NO_TASK'=>'你请求的任务不存在。',
'LBL_ERROR_NOT_ADMIN'=>'您没有访问此模块的权限。',
'LBL_CREATE_WORKFLOW'=>'创建工作流',
'LBL_WORKFLOW_LIST'=>'工作流列表',
'LBL_AVAILABLE_WORKLIST_LIST'=>'有效的工作流',
'LBL_LOADING'=>'下载...',
'LBL_VALIDATION_ERROR'=>'违例错误',
'LBL_SELECT_OPTION_DOTDOTDOT'=>'选择项...',
'LBL_WORKFLOW_NOTE_CRON_CONFIG'=>'注意:你必须配置工作流的核心脚本。',
'LBL_NO_TEMPLATES'=>'没有模板',
);
?>
@@ -1,26 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once('include/utils/utils.php');
require_once('include/Zend/Json.php');
require_once('include/events/include.inc');
require_once('modules/com_vtiger_workflow/include.inc');
/**
* This is a utility function to load a dumped templates files
* into vtiger
* @param $filename The name of the file to load.
*/
function loadTemplates($filename){
global $adb;
$str = file_get_contents('fetchtemplates.out');
$tm = new VTWorkflowTemplateManager($adb);
$tm->loadTemplates($str);
}
?>
@@ -1,19 +0,0 @@
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once "include/Zend/Json.php";
require_once("include/events/VTWSEntityType.inc");
function vtModuleTypeInfoJson($adb, $request){
$moduleName = $request['module_name'];
$et = VTWSEntityType::usingGlobalCurrentUser($moduleName);
echo Zend_Json::encode($et->getFieldLabels());
}
vtModuleTypeInfoJson($adb, $_REQUEST);
?>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 763 B

@@ -1,106 +0,0 @@
function VTCreateTodoTask($){
var map = fn.map;
var dict = fn.dict;
var filter = fn.filter;
var reduceR = fn.reduceR;
var parallelExecuter = fn.parallelExecuter;
var contains = fn.contains;
var concat = fn.concat;
function parse12HoursTime(timeStr){
var hours;
var match = timeStr.match(/(\d\d):(\d\d)(am|pm)/);
if(match[3]=='am'){
hours = parseInt(match[1], 10) % 12;
}else{
hours = parseInt(match[1], 10) % 12 + 12;
}
return hours*60+parseInt(match[2], 10);
}
function errorDialog(message){
alert(message);
}
function index(arr, field){
return dict(map(function(e){return [e[field], e];}, arr));
}
function handleError(fn){
return function(status, result){
if(status){
fn(result);
}else{
errorDialog('Failure:'+result);
}
};
}
function fillPicklist(picklistId, fieldInfo, defaultValue){
var values = fieldInfo['type']['picklistValues'];
var select = $('#'+picklistId);
$.each(values, function(i, v){
select.append('<option value="'+v['value']+'">'+v['label']+'</option>');
});
select.attr('value', defaultValue);
}
var validateDateRange = {
init: function(){
},
validator: function(){
var result;
var successResult = [true];
var failureResult = [false, 'invalid_date_range_message', []];
if(this.fieldValue('startDatefield') == this.fieldValue('endDatefield')){
var startTime = this.fieldValue('startTime');
var endTime = this.fieldValue('endTime');
var startDays = parseInt(this.fieldValue('startDays'), 10);
var endDays = parseInt(this.fieldValue('endDays'), 10);
var startDirection = this.fieldValue('startDirection')=="After"?1:-1;
var endDirection = this.fieldValue('endDirection')=="After"?1:-1;
var dd = endDays*endDirection - startDays*startDirection;
if(dd<0){
result = failureResult;
}else if(dd==0){
if(parse12HoursTime(startTime)>=parse12HoursTime(startTime)){
result = failureResult;
}else{
result = successResult;
}
}else{
result = successResult;
}
}else{
result = successResult;
}
return result;
}
};
var vtinst = new VtigerWebservices("webservice.php");
vtinst.extendSession(handleError(function(result){
$(document).ready(function(){
//Setup the validator
validator.addValidator('validateDateRange', validateDateRange);
validator.mandatoryFields.push('eventName');
vtinst.describeObject('Events', handleError(function(result){
var fields = result['fields'];
var fieldsMap = index(fields, 'name');
fillPicklist('event_status', fieldsMap['eventstatus'], eventStatus);
$('#event_status_busyicon').hide();
$('#event_status').show();
fillPicklist('event_type', fieldsMap['activitytype'], eventType);
$('#event_type_busyicon').hide();
$('#event_type').show();
}));
});
}));
}
VTCreateTodoTask(jQuery);
@@ -1,63 +0,0 @@
function VTCreateTodoTask($){
var map = fn.map;
var dict = fn.dict;
var filter = fn.filter;
var reduceR = fn.reduceR;
var parallelExecuter = fn.parallelExecuter;
var contains = fn.contains;
var concat = fn.concat;
function errorDialog(message){
alert(message);
}
function index(arr, field){
return dict(map(function(e){return [e[field], e];}, arr));
}
function handleError(fn){
return function(status, result){
if(status){
fn(result);
}else{
errorDialog('Failure:'+result);
}
}
}
var vtinst = new VtigerWebservices("webservice.php");
vtinst.extendSession(handleError(function(result){
$(document).ready(function(){
//Setup the validator
validator.mandatoryFields.push('todo');
vtinst.describeObject('Calendar', handleError(function(result){
var fields = result['fields'];
var fieldsMap = index(fields, 'name');
var eventStatusType = fieldsMap['taskstatus'];
var eventStatusValues = eventStatusType['type']['picklistValues'];
var taskPriorityType = fieldsMap['taskpriority'];
var taskPriorityValues = taskPriorityType['type']['picklistValues'];
var status = $('#task_status');
$.each(eventStatusValues, function(i, v){
status.append('<option value="'+v['value']+'">'+v['label']+'</option>');
});
status.attr('value', taskStatus);
$('#task_status_busyicon').hide();
$('#task_status').show();
var priority = $('#task_priority');
$.each(taskPriorityValues, function(i, v){
priority.append('<option value="'+v['value']+'">'+v['label']+'</option>');
});
priority.attr('value', taskPriority);
$('#task_priority_busyicon').hide();
$('#task_priority').show();
}));
});
}));
}
VTCreateTodoTask(jQuery);

Some files were not shown because too many files have changed in this diff Show More