function vtDisplayWorkflowList($adb, $request, $requestUrl, $app_strings, $current_language) { global $theme; $image_path = "themes/{$theme}/images/"; $module = new VTWorkflowApplication("workflowlist"); $util = new VTWorkflowUtils(); $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(); $wfs = new VTWorkflowManager($adb); $smarty->assign("moduleNames", $util->vtGetModules($adb)); $smarty->assign("returnUrl", $requestUrl); $listModule = $request['list_module']; $smarty->assign("listModule", $listModule); if ($listModule == null || strtolower($listModule) == "all") { $smarty->assign("workflows", $wfs->getWorkflows()); } else { $smarty->assign("workflows", $wfs->getWorkflowsForModule($listModule)); } $smarty->assign("MOD", array_merge(return_module_language($current_language, 'Settings'), return_module_language($current_language, $module->name))); $smarty->assign("APP", $app_strings); $smarty->assign("THEME", $theme); $smarty->assign("IMAGE_PATH", $image_path); $smarty->assign("MODULE_NAME", $module->label); $smarty->assign("PAGE_NAME", $mod['LBL_WORKFLOW_LIST']); $smarty->assign("PAGE_TITLE", $mod['LBL_AVAILABLE_WORKLIST_LIST']); $smarty->assign("module", $module); $smarty->assign('MODULE', $module->name); $smarty->assign("CRON_TASK", Vtiger_Cron::getInstance('Workflow')); $smarty->display("{$module->name}/ListWorkflows.tpl"); }
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="<?php echo $returnUrl; ?> "; </script> <a href="<?php echo $returnUrl; ?> ">Return</a> <?php }
function process(Vtiger_Request $request) { $moduleName = $request->getModule(); $record = $request->get('record'); vimport('~~modules/com_vtiger_workflow/include.inc'); vimport('~~modules/com_vtiger_workflow/VTEntityCache.inc'); vimport('~~modules/com_vtiger_workflow/include.inc'); vimport('~~include/Webservices/Utils.php'); vimport('~~include/Webservices/Retrieve.php'); $adb = PearDatabase::getInstance(); $wfs = new VTWorkflowManager($adb); $workflows = $wfs->getWorkflowsForModule($moduleName, VTWorkflowManager::$TRIGGER); $currentUser = Users_Record_Model::getCurrentUserModel(); $wsId = vtws_getWebserviceEntityId($moduleName, $record); $entityCache = new VTEntityCache($currentUser); $entityData = $entityCache->forId($wsId); foreach ($workflows as $id => $workflow) { if (!$workflow->evaluate($entityCache, $entityData->getId())) { unset($workflows[$id]); } } $viewer = $this->getViewer($request); $viewer->assign('RECORD', $record); $viewer->assign('MODULE', $moduleName); $viewer->assign('WORKFLOWS', $workflows); $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel()); $viewer->view('WorkflowTrigger.tpl', $moduleName); }
public function step1(Vtiger_Request $request) { $currentUser = Users_Record_Model::getCurrentUserModel(); $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $qualifiedModuleName = $request->getModule(false); $recordId = $request->get('record'); if ($recordId) { $workflowModel = Settings_Workflows_Record_Model::getInstance($recordId); $viewer->assign('RECORDID', $recordId); $viewer->assign('MODULE_MODEL', $workflowModel->getModule()); $viewer->assign('MODE', 'edit'); } else { $workflowModel = Settings_Workflows_Record_Model::getCleanInstance($moduleName); $selectedModule = $request->get('source_module'); if (!empty($selectedModule)) { $viewer->assign('SELECTED_MODULE', $selectedModule); } } $db = PearDatabase::getInstance(); $workflowManager = new VTWorkflowManager($db); $viewer->assign('MAX_ALLOWED_SCHEDULED_WORKFLOWS', $workflowManager->getMaxAllowedScheduledWorkflows()); $viewer->assign('SCHEDULED_WORKFLOW_COUNT', $workflowManager->getScheduledWorkflowsCount()); $viewer->assign('WORKFLOW_MODEL', $workflowModel); $viewer->assign('ALL_MODULES', Settings_Workflows_Module_Model::getSupportedModules()); $viewer->assign('TRIGGER_TYPES', Settings_Workflows_Module_Model::getTriggerTypes()); $viewer->assign('MODULE', $moduleName); $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName); $viewer->assign('CURRENT_USER', $currentUser); $admin = Users::getActiveAdminUser(); $viewer->assign('ACTIVE_ADMIN', $admin); $viewer->view('Step1.tpl', $qualifiedModuleName); }
function handleEvent($eventName, $data) { if ($eventName == 'vtiger.entity.beforesave') { // Entity is about to be saved, take required action } if ($eventName == 'vtiger.entity.aftersave') { $db = PearDatabase::getInstance(); $relatedToId = $data->get('related_to'); if ($relatedToId) { $moduleName = getSalesEntityType($relatedToId); $focus = CRMEntity::getInstance($moduleName); $focus->retrieve_entity_info($relatedToId, $moduleName); $focus->id = $relatedToId; $fromPortal = $data->get('from_portal'); if ($fromPortal) { $focus->column_fields['from_portal'] = $fromPortal; } $entityData = VTEntityData::fromCRMEntity($focus); $wfs = new VTWorkflowManager($db); $relatedToEventHandler = new VTWorkflowEventHandler(); $relatedToEventHandler->workflows = $wfs->getWorkflowsForModuleSupportingComments($entityData->getModuleName()); $wsId = vtws_getWebserviceEntityId($entityData->getModuleName(), $entityData->getId()); $fromPortal = $entityData->get('from_portal'); $util = new VTWorkflowUtils(); $entityCache = new VTEntityCache($util->adminUser()); $entityCacheData = $entityCache->forId($wsId); $entityCacheData->set('from_portal', $fromPortal); $entityCache->cache[$wsId] = $entityCacheData; $relatedToEventHandler->handleEvent($eventName, $entityData, $entityCache); $util->revertUser(); } } }
/** * Function to get the detail view links (links and widgets) * @param <array> $linkParams - parameters which will be used to calicaulate the params * @return <array> - array of link models in the format as below * array('linktype'=>list of link models); */ public function getDetailViewLinks($linkParams) { $linkTypes = array('DETAILVIEWBASIC', 'DETAILVIEW'); $moduleModel = $this->getModule(); $recordModel = $this->getRecord(); $currentUserModel = Users_Record_Model::getCurrentUserModel(); $moduleName = $moduleModel->getName(); $recordId = $recordModel->getId(); $detailViewLinks = []; $adb = PearDatabase::getInstance(); vimport('~~modules/com_vtiger_workflow/include.inc'); vimport('~~modules/com_vtiger_workflow/VTEntityMethodManager.inc'); $wfs = new VTWorkflowManager($adb); $workflows = $wfs->getWorkflowsForModule($moduleName, VTWorkflowManager::$TRIGGER); if (Users_Privileges_Model::isPermitted($moduleName, 'WorkflowTrigger') && count($workflows) > 0) { $detailViewLinks[] = array('linktype' => 'DETAILVIEWBASIC', 'linklabel' => '', 'linkurl' => 'Vtiger_Detail_Js.showWorkflowTriggerView(this)', 'linkicon' => 'glyphicon glyphicon-plus-sign', 'linkhint' => 'BTN_WORKFLOW_TRIGGER'); } $lockEdit = Users_Privileges_Model::checkLockEdit($moduleName, $recordId); $currentUserPriviligesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel(); if (Users_Privileges_Model::isPermitted($moduleName, 'EditView', $recordId) && !$lockEdit) { $detailViewLinks[] = array('linktype' => 'DETAILVIEWBASIC', 'linklabel' => '', 'linkurl' => $recordModel->getEditViewUrl(), 'linkicon' => 'glyphicon glyphicon-pencil', 'linkclass' => 'btn', 'linkhint' => 'BTN_RECORD_EDIT'); } foreach ($detailViewLinks as $detailViewLink) { $linkModelList['DETAILVIEWBASIC'][] = Vtiger_Link_Model::getInstanceFromValues($detailViewLink); } $linkModelListDetails = Vtiger_Link_Model::getAllByType($moduleModel->getId(), $linkTypes, $linkParams); //Mark all detail view basic links as detail view links. //Since ui will be look ugly if you need many basic links $detailViewBasiclinks = $linkModelListDetails['DETAILVIEWBASIC']; unset($linkModelListDetails['DETAILVIEWBASIC']); if (Users_Privileges_Model::isPermitted($moduleName, 'Delete', $recordId) && $recordPermissionToEditView) { $deletelinkModel = array('linktype' => 'DETAILVIEW', 'linklabel' => sprintf("%s %s", getTranslatedString('LBL_DELETE', $moduleName), vtranslate('SINGLE_' . $moduleName, $moduleName)), 'linkurl' => 'javascript:Vtiger_Detail_Js.deleteRecord("' . $recordModel->getDeleteUrl() . '")', 'linkicon' => 'glyphicon glyphicon-trash', 'title' => vtranslate('LBL_DELETE_RECORD')); $linkModelList['DETAILVIEW'][] = Vtiger_Link_Model::getInstanceFromValues($deletelinkModel); } if (Users_Privileges_Model::isPermitted($moduleName, 'DuplicateRecord')) { $duplicateLinkModel = array('linktype' => 'DETAILVIEWBASIC', 'linklabel' => 'LBL_DUPLICATE', 'linkurl' => $recordModel->getDuplicateRecordUrl(), 'linkicon' => 'glyphicon glyphicon-retweet', 'title' => vtranslate('LBL_DUPLICATE_RECORD')); $linkModelList['DETAILVIEW'][] = Vtiger_Link_Model::getInstanceFromValues($duplicateLinkModel); } if (!empty($detailViewBasiclinks)) { foreach ($detailViewBasiclinks as $linkModel) { // Remove view history, needed in vtiger5 to see history but not in vtiger6 if ($linkModel->linklabel == 'View History') { continue; } $linkModelList['DETAILVIEW'][] = $linkModel; } } $relatedLinks = $this->getDetailViewRelatedLinks(); foreach ($relatedLinks as $relatedLinkEntry) { $relatedLink = Vtiger_Link_Model::getInstanceFromValues($relatedLinkEntry); $linkModelList[$relatedLink->getType()][] = $relatedLink; } if ($currentUserModel->isAdminUser()) { $settingsLinks = $moduleModel->getSettingLinks(); foreach ($settingsLinks as $settingsLink) { $linkModelList['DETAILVIEWSETTING'][] = Vtiger_Link_Model::getInstanceFromValues($settingsLink); } } return $linkModelList; }
function vtWorkflowSave($adb, $request) { $util = new VTWorkflowUtils(); $module = new VTWorkflowApplication("saveworkflow"); $mod = return_module_language($current_language, $module->name); $request = vtlib_purify($request); // this cleans all values of the array if (!$util->checkAdminAccess()) { $errorUrl = $module->errorPageUrl($mod['LBL_ERROR_NOT_ADMIN']); $util->redirectTo($errorUrl, $mod['LBL_ERROR_NOT_ADMIN']); return; } $description = from_html($request["description"]); $moduleName = $request["module_name"]; $conditions = $request["conditions"]; $taskId = $request["task_id"]; $saveType = $request["save_type"]; $executionCondition = $request['execution_condition']; $wm = new VTWorkflowManager($adb); if ($saveType == 'new') { $wf = $wm->newWorkflow($moduleName); $wf->description = $description; $wf->test = $conditions; $wf->taskId = $taskId; $wf->executionConditionAsLabel($executionCondition); $wm->save($wf); } else { if ($saveType == 'edit') { $wf = $wm->retrieve($request["workflow_id"]); $wf->description = $description; $wf->test = $conditions; $wf->taskId = $taskId; $wf->executionConditionAsLabel($executionCondition); $wm->save($wf); } else { throw new Exception(); } } if (isset($request["return_url"])) { $returnUrl = $request["return_url"]; } else { $returnUrl = $module->editWorkflowUrl($wf->id); } ?> <script type="text/javascript" charset="utf-8"> window.location="<?php echo $returnUrl; ?> "; </script> <a href="<?php echo $returnUrl; ?> ">Return</a> <?php }
public function queueScheduledWorkflowTasks() { global $default_timezone; $adb = $this->db; $vtWorflowManager = new VTWorkflowManager($adb); $taskQueue = new VTTaskQueue($adb); $entityCache = new VTEntityCache($this->user); // set the time zone to the admin's time zone, this is needed so that the scheduled workflow will be triggered // at admin's time zone rather than the systems time zone. This is specially needed for Hourly and Daily scheduled workflows $admin = Users::getActiveAdminUser(); $adminTimeZone = $admin->time_zone; @date_default_timezone_set($adminTimeZone); $currentTimestamp = date("Y-m-d H:i:s"); @date_default_timezone_set($default_timezone); $scheduledWorkflows = $vtWorflowManager->getScheduledWorkflows($currentTimestamp); $noOfScheduledWorkflows = count($scheduledWorkflows); foreach ($scheduledWorkflows as $workflow) { $tm = new VTTaskManager($adb); $tasks = $tm->getTasksForWorkflow($workflow->id); if ($tasks) { $records = $this->getEligibleWorkflowRecords($workflow); $noOfRecords = count($records); for ($j = 0; $j < $noOfRecords; ++$j) { $recordId = $records[$j]; // We need to pass proper module name to get the webservice if ($workflow->moduleName == 'Calendar') { $moduleName = vtws_getCalendarEntityType($recordId); } else { $moduleName = $workflow->moduleName; } $wsEntityId = vtws_getWebserviceEntityId($moduleName, $recordId); $entityData = $entityCache->forId($wsEntityId); $data = $entityData->getData(); 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) { if (empty($task->test) or $task->evaluate($entityCache, $entityData->getId())) { $task->doTask($entityData); } } else { $taskQueue->queueTask($task->id, $entityData->getId(), $delay); } } } } } $vtWorflowManager->updateNexTriggerTime($workflow); } $scheduledWorkflows = null; }
function applyChange() { global $adb; if ($this->hasError()) { $this->sendError(); } if ($this->isApplied()) { $this->sendMsg('Changeset ' . get_class($this) . ' already applied!'); } else { global $adb; $chktbl = $adb->query('select 1 from com_vtiger_workflow_tasktypes limit 1'); if ($chktbl) { $moduleInstance = Vtiger_Module::getInstance('Potentials'); $block = Vtiger_Block::getInstance('LBL_OPPORTUNITY_INFORMATION', $moduleInstance); $field = Vtiger_Field::getInstance('forecast_amount', $moduleInstance); if ($field) { $this->ExecuteQuery('update vtiger_field set presence=2 where fieldid=' . $field->id); } else { $forecast_field = new Vtiger_Field(); $forecast_field->name = 'forecast_amount'; $forecast_field->label = 'Forecast Amount'; $forecast_field->table = 'vtiger_potential'; $forecast_field->column = 'forecast_amount'; $forecast_field->columntype = 'decimal(25,4)'; $forecast_field->typeofdata = 'N~O'; $forecast_field->uitype = '71'; $forecast_field->masseditable = '0'; $block->addField($forecast_field); } $wfrs = $adb->query("SELECT workflow_id FROM com_vtiger_workflows WHERE summary='Calculate or Update forecast amount'"); if ($wfrs and $adb->num_rows($wfrs) == 1) { $this->sendMsg('Workfolw already exists!'); } else { $workflowManager = new VTWorkflowManager($adb); $taskManager = new VTTaskManager($adb); $potentailsWorkFlow = $workflowManager->newWorkFlow("Potentials"); $potentailsWorkFlow->test = ''; $potentailsWorkFlow->description = "Calculate or Update forecast amount"; $potentailsWorkFlow->executionCondition = VTWorkflowManager::$ON_EVERY_SAVE; $potentailsWorkFlow->defaultworkflow = 1; $workflowManager->save($potentailsWorkFlow); $task = $taskManager->createTask('VTUpdateFieldsTask', $potentailsWorkFlow->id); $task->active = true; $task->summary = 'update forecast amount'; $task->field_value_mapping = '[{"fieldname":"forecast_amount","valuetype":"expression","value":"amount * probability / 100"}]'; $taskManager->saveTask($task); } $this->sendMsg('Changeset ' . get_class($this) . ' applied!'); $this->markApplied(); } else { $this->sendMsgError('This changeset could not be applied because it depends on create_workflow_tasktype which probably has not been applied yet. Apply that changeset and try this one again.'); } } $this->finishExecution(); }
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); $taskTypes = $tm->getTaskTypes($workflow->moduleName); $smarty->assign("taskTypes", $taskTypes); $smarty->assign("newTaskReturnUrl", vtlib_purify($requestUrl)); $smarty->assign("returnUrl", vtlib_purify($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->assign("WORKFLOW_TRIGGER_TYPES_HELP_LINK", WORKFLOW_TRIGGER_TYPES); $smarty->display("{$module->name}/EditWorkflow.tpl"); }
public function execute($moduleName, $record, $ids) { vimport('~~modules/com_vtiger_workflow/VTEntityCache.inc'); vimport('~~modules/com_vtiger_workflow/include.inc'); vimport('~~include/Webservices/Utils.php'); vimport('~~include/Webservices/Retrieve.php'); $currentUser = Users_Record_Model::getCurrentUserModel(); $wsId = vtws_getWebserviceEntityId($moduleName, $record); $adb = PearDatabase::getInstance(); $wfs = new VTWorkflowManager($adb); $entityCache = new VTEntityCache($currentUser); $entityData = $entityCache->forId($wsId); foreach ($ids as $id) { $workflow = $wfs->retrieve($id); if ($workflow->evaluate($entityCache, $entityData->getId())) { $workflow->performTasks($entityData); } } }
public function queueScheduledWorkflowTasks() { global $default_timezone; $adb = $this->db; $vtWorflowManager = new VTWorkflowManager($adb); $entityCache = new VTEntityCache($this->user); // set the time zone to the admin's time zone, this is needed so that the scheduled workflow will be triggered // at admin's time zone rather than the systems time zone. This is specially needed for Hourly and Daily scheduled workflows $admin = Users::getActiveAdminUser(); $adminTimeZone = $admin->time_zone; @date_default_timezone_set($adminTimeZone); $currentTimestamp = date("Y-m-d H:i:s"); @date_default_timezone_set($default_timezone); $scheduledWorkflows = $vtWorflowManager->getScheduledWorkflows($currentTimestamp); $noOfScheduledWorkflows = count($scheduledWorkflows); for ($i = 0; $i < $noOfScheduledWorkflows; ++$i) { $workflow = $scheduledWorkflows[$i]; if ($workflow->active != 1) { continue; } $tm = new VTTaskManager($adb); $tasks = $tm->getTasksForWorkflow($workflow->id); if ($tasks) { $records = $this->getEligibleWorkflowRecords($workflow); $noOfRecords = count($records); for ($j = 0; $j < $noOfRecords; ++$j) { $recordId = $records[$j]; // We need to pass proper module name to get the webservice if ($workflow->moduleName == 'Calendar') { $moduleName = vtws_getCalendarEntityType($recordId); } else { $moduleName = $workflow->moduleName; } $wsEntityId = vtws_getWebserviceEntityId($moduleName, $recordId); $entityData = $entityCache->forId($wsEntityId); $tm->performTasks($entityData, false); } } $vtWorflowManager->updateNexTriggerTime($workflow); } $scheduledWorkflows = null; }
function applyChange() { if ($this->hasError()) { $this->sendError(); } if ($this->isApplied()) { $this->sendMsg('Changeset ' . get_class($this) . ' already applied!'); } else { global $adb; $emm = new VTEntityMethodManager($adb); // Adding EntityMethod for Updating Products data after updating PurchaseOrder $emm->addEntityMethod("PurchaseOrder", "UpdateInventory", "include/InventoryHandler.php", "handleInventoryProductRel"); // Creating Workflow for Updating Inventory Stock on PO $vtWorkFlow = new VTWorkflowManager($adb); $invWorkFlow = $vtWorkFlow->newWorkFlow("PurchaseOrder"); $invWorkFlow->test = '[{"fieldname":"subject","operation":"does not contain","value":"`!`"}]'; $invWorkFlow->description = "UpdateInventoryProducts On Every Save"; $invWorkFlow->defaultworkflow = 1; $vtWorkFlow->save($invWorkFlow); $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEntityMethodTask', $invWorkFlow->id); $task->active = true; $task->methodName = "UpdateInventory"; $task->summary = "Update product stock"; $tm->saveTask($task); // add Cancel status to Invoice and SO for stock control $moduleInstance = Vtiger_Module::getInstance('Invoice'); $field = Vtiger_Field::getInstance('invoicestatus', $moduleInstance); if ($field) { $field->setPicklistValues(array('Cancel')); } $this->sendMsg('Changeset ' . get_class($this) . ' applied! Add Workflow Custom Function complete!'); $this->markApplied(); } $this->finishExecution(); }
if (file_exists($unWanted[$i])) { unlink($unWanted[$i]); } } // Ticket #2629 global $adb; $query = 'SELECT tabid FROM vtiger_tab where name = ?'; $result = $adb->pquery($query, array('Accounts')); $tabId = $adb->query_result($result, 0, 'tabid'); Migration_Index_View::ExecuteQuery('UPDATE vtiger_relatedlists SET name=? WHERE tabid=? AND label=?', array('get_dependents_list', $tabId, 'Act')); Migration_Index_View::ExecuteQuery('UPDATE vtiger_relatedlists SET name=? WHERE tabid=? AND label=?', array('get_dependents_list', $tabId, 'Consignment')); // Begin Ticket #2601 Creating Workflow for Updating Inventory Stock for Invoice $checkQuery = "SELECT * FROM com_vtiger_workflows WHERE module_name = ? AND summary = ?"; $result = $adb->pquery($checkQuery, array('Invoice', 'UpdateInventoryProducts On Every Save')); if ($adb->num_rows($result) < 1) { $vtWorkFlow = new VTWorkflowManager($adb); $invWorkFlow = $vtWorkFlow->newWorkFlow("Invoice"); $invWorkFlow->test = '[{"fieldname":"subject","operation":"does not contain","value":"`!`"}]'; $invWorkFlow->description = "UpdateInventoryProducts On Every Save"; $invWorkFlow->defaultworkflow = 1; $vtWorkFlow->save($invWorkFlow); } // Begin Ticket #2668 $query = 'SELECT blockid FROM vtiger_settings_blocks WHERE label = ?'; $result = $adb->pquery($query, array('LBL_INTEGRATION')); $blockId = $adb->query_result($result, 0, 'blockid'); Migration_Index_View::ExecuteQuery('UPDATE vtiger_settings_field SET blockid = ? WHERE name = ? OR name = ?', array($blockId, 'LBL_CML_SETTINGS', 'LBL_SOCIALCONNECTOR_SETTINGS')); // Begin Ticket #2789 $query = 'SELECT tabid FROM vtiger_tab where name = ?'; $result = $adb->pquery($query, array('PBXManager')); $tabId = $adb->query_result($result, 0, 'tabid');
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"); }
public function addWorkflow() { global $log, $adb; $workflow = array(); $result = $adb->query("SELECT * FROM `com_vtiger_workflows` WHERE summary = 'Update Closed Time';"); if ($adb->num_rows($result) == 0) { $workflow[] = array(54, 'HelpDesk', 'Update Closed Time', '[{"fieldname":"ticketstatus","operation":"is","value":"Rejected","valuetype":"rawtext","joincondition":"or","groupjoin":null,"groupid":"1"},{"fieldname":"ticketstatus","operation":"is","value":"Closed","valuetype":"rawtext","joincondition":"","groupjoin":null,"groupid":"1"}]', 2, NULL, 'basic', 6, NULL, NULL, NULL, NULL, NULL, NULL); } $result = $adb->query("SELECT * FROM `com_vtiger_workflows` WHERE summary = 'Generate mail address book';"); if ($adb->num_rows($result) == 0) { $workflow[] = array(55, 'Contacts', 'Generate mail address book', '[]', 3, NULL, 'basic', 6, NULL, NULL, NULL, NULL, NULL, NULL); } $workflowTask = array(); $workflowTask[] = array(121, 54, 'Update Closed Time', 'O:18:"VTUpdateClosedTime":6:{s:18:"executeImmediately";b:1;s:10:"workflowId";s:2:"54";s:7:"summary";s:18:"Update Closed Time";s:6:"active";b:1;s:7:"trigger";N;s:2:"id";i:121;}'); $workflowTask[] = array(123, 55, 'Generate mail address book', 'O:17:"VTAddressBookTask":7:{s:18:"executeImmediately";b:0;s:10:"workflowId";s:2:"55";s:7:"summary";s:26:"Generate mail address book";s:6:"active";b:1;s:7:"trigger";N;s:4:"test";s:0:"";s:2:"id";i:123;}'); require_once 'modules/com_vtiger_workflow/include.inc'; require_once 'modules/com_vtiger_workflow/tasks/VTEntityMethodTask.inc'; require_once 'modules/com_vtiger_workflow/VTEntityMethodManager.inc'; $workflowManager = new VTWorkflowManager($adb); $taskManager = new VTTaskManager($adb); foreach ($workflow as $record) { $newWorkflow = $workflowManager->newWorkFlow($record[1]); $newWorkflow->description = $record[2]; $newWorkflow->test = $record[3]; $newWorkflow->executionCondition = $record[4]; $newWorkflow->defaultworkflow = $record[5]; $newWorkflow->type = $record[6]; $newWorkflow->filtersavedinnew = $record[7]; $workflowManager->save($newWorkflow); foreach ($workflowTask as $indexTask) { if ($indexTask[1] == $record[0]) { $task = $taskManager->unserializeTask($indexTask[3]); $task->id = ''; $task->workflowId = $newWorkflow->id; $taskManager->saveTask($task); } } } }
/** * Function to delete a given record model of the current module * @param Vtiger_Record_Model $recordModel */ public function deleteRecord($recordModel) { $moduleName = $this->get('name'); $focus = CRMEntity::getInstance($moduleName); $focus->trash($moduleName, $recordModel->getId()); if (method_exists($focus, 'transferRelatedRecords')) { if ($recordModel->get('transferRecordIDs')) { $focus->transferRelatedRecords($moduleName, $recordModel->get('transferRecordIDs'), $recordModel->getId()); } } vimport('~~modules/com_vtiger_workflow/include.inc'); vimport('~~modules/com_vtiger_workflow/VTEntityMethodManager.inc'); $wfs = new VTWorkflowManager(PearDatabase::getInstance()); $workflows = $wfs->getWorkflowsForModule($moduleName, VTWorkflowManager::$ON_DELETE); if (count($workflows)) { $wsId = vtws_getWebserviceEntityId($moduleName, $recordModel->getId()); $entityCache = new VTEntityCache(Users_Record_Model::getCurrentUserModel()); $entityData = $entityCache->forId($wsId); foreach ($workflows as $id => $workflow) { if ($workflow->evaluate($entityCache, $entityData->getId())) { $workflow->performTasks($entityData); } } } }
/** * Default (generic) function to handle the dependents list for the module. * NOTE: UI type '10' is used to stored the references to other modules for a given record. * These dependent records can be retrieved through this function. * For eg: A trouble ticket can be related to an Account or a Contact. * From a given Contact/Account if we need to fetch all such dependent trouble tickets, get_dependents_list function can be used. */ function get_dependents_list($id, $cur_tab_id, $rel_tab_id, $actions = false) { global $currentModule, $app_strings, $singlepane_view, $current_user, $adb; $parenttab = getParentTab(); $related_module = vtlib_getModuleNameById($rel_tab_id); $other = CRMEntity::getInstance($related_module); // Some standard module class doesn't have required variables // that are used in the query, they are defined in this generic API vtlib_setup_modulevars($currentModule, $this); vtlib_setup_modulevars($related_module, $other); $singular_modname = 'SINGLE_' . $related_module; $button = ''; // To make the edit or del link actions to return back to same view. if ($singlepane_view == 'true') { $returnset = "&return_module={$currentModule}&return_action=DetailView&return_id={$id}"; } else { $returnset = "&return_module={$currentModule}&return_action=CallRelatedList&return_id={$id}"; } $return_value = null; $dependentFieldSql = $this->db->pquery("SELECT tabid, tablename, fieldname, columnname FROM vtiger_field WHERE uitype='10' AND" . " fieldid IN (SELECT fieldid FROM vtiger_fieldmodulerel WHERE relmodule=? AND module=?)", array($currentModule, $related_module)); $numOfFields = $this->db->num_rows($dependentFieldSql); if ($numOfFields > 0) { $relconds = array(); while ($depflds = $this->db->fetch_array($dependentFieldSql)) { $dependentTable = $depflds['tablename']; if ($dependentTable != $other->table_name and !in_array($dependentTable, $other->related_tables)) { $relidx = isset($other->tab_name_index[$dependentTable]) ? $other->tab_name_index[$dependentTable] : $other->table_index; $other->related_tables[$dependentTable] = array($relidx, $other->table_name, $other->table_index); } $dependentColumn = $depflds['columnname']; $dependentField = $depflds['fieldname']; $relconds[] = "{$this->table_name}.{$this->table_index} = {$dependentTable}.{$dependentColumn}"; $button .= '<input type="hidden" name="' . $dependentColumn . '" id="' . $dependentColumn . '" value="' . $id . '">'; $button .= '<input type="hidden" name="' . $dependentColumn . '_type" id="' . $dependentColumn . '_type" value="' . $currentModule . '">'; } $relationconditions = '(' . implode(' or ', $relconds) . ')'; if ($actions) { if (is_string($actions)) { $actions = explode(',', strtoupper($actions)); } $wfs = ''; if (in_array('ADD', $actions) && isPermitted($related_module, 1, '') == 'yes' && getFieldVisibilityPermission($related_module, $current_user->id, $dependentField, 'readwrite') == '0') { $wfs = new VTWorkflowManager($adb); $racbr = $wfs->getRACRuleForRecord($currentModule, $id); if (!$racbr or $racbr->hasRelatedListPermissionTo('create', $related_module)) { $button .= "<input title='" . getTranslatedString('LBL_ADD_NEW') . " " . getTranslatedString($singular_modname, $related_module) . "' class='crmbutton small create'" . " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"{$related_module}\"' type='submit' name='button'" . " value='" . getTranslatedString('LBL_ADD_NEW') . " " . getTranslatedString($singular_modname, $related_module) . "'> "; } } } $query = "SELECT vtiger_crmentity.*, {$other->table_name}.*"; $userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); $query .= ", CASE WHEN (vtiger_users.user_name NOT LIKE '') THEN {$userNameSql} ELSE vtiger_groups.groupname END AS user_name"; $more_relation = ''; if (!empty($other->related_tables)) { foreach ($other->related_tables as $tname => $relmap) { $query .= ", {$tname}.*"; // Setup the default JOIN conditions if not specified if (empty($relmap[1])) { $relmap[1] = $other->table_name; } if (empty($relmap[2])) { $relmap[2] = $relmap[0]; } $more_relation .= " LEFT JOIN {$tname} ON {$tname}.{$relmap['0']} = {$relmap['1']}.{$relmap['2']}"; } } $query .= " FROM {$other->table_name}"; $query .= " INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = {$other->table_name}.{$other->table_index}"; $query .= $more_relation; $query .= " INNER JOIN {$this->table_name} ON {$relationconditions}"; $query .= " LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid"; $query .= " LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid"; $query .= " WHERE vtiger_crmentity.deleted = 0 AND {$this->table_name}.{$this->table_index} = {$id}"; $return_value = GetRelatedList($currentModule, $related_module, $other, $query, $button, $returnset); } if ($return_value == null) { $return_value = array(); } $return_value['CUSTOM_BUTTON'] = $button; return $return_value; }
public function updateNextTriggerTime() { $db = PearDatabase::getInstance(); $wm = new VTWorkflowManager($db); $wf = $this->getWorkflowObject(); $wm->updateNexTriggerTime($wf); }
function vtWorkflowEdit($adb, $request, $requestUrl, $current_language, $app_strings) { global $theme, $current_user; $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); } $smarty->assign('ScheduledWorkflowsCount', $wfs->getScheduledWorkflowsCount()); $smarty->assign('MaxAllowedScheduledWorkflows', $wfs->getMaxAllowedScheduledWorkflows()); $smarty->assign('schdtime_12h', date('h:ia', strtotime(substr($workflow->schtime, 0, strrpos($workflow->schtime, ':'))))); $schannualdates = json_decode($workflow->schannualdates); if (count($schannualdates) > 0) { $schannualdates = DateTimeField::convertToUserFormat($schannualdates[0]); } else { $schannualdates = ''; } $smarty->assign('schdate', $schannualdates); $smarty->assign('selected_days1_31', json_decode($workflow->schdayofmonth)); $smarty->assign('dayOfWeek', json_decode($workflow->schdayofweek)); } 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); $taskTypes = $tm->getTaskTypes($workflow->moduleName); $smarty->assign("taskTypes", $taskTypes); $smarty->assign("newTaskReturnUrl", vtlib_purify($requestUrl)); $dayrange = array(); for ($d = 1; $d <= 31; $d++) { $dayrange[$d] = $d; } $smarty->assign('days1_31', $dayrange); $smarty->assign('wfnexttrigger_time', DateTimeField::convertToUserFormat($workflow->nexttrigger_time)); $smarty->assign("dateFormat", parse_calendardate($current_user->date_format)); $smarty->assign("returnUrl", vtlib_purify($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->assign("WORKFLOW_TRIGGER_TYPES_HELP_LINK", WORKFLOW_TRIGGER_TYPES); $smarty->display("{$module->name}/EditWorkflow.tpl"); }
function populateDefaultWorkflows($adb) { require_once "modules/com_vtiger_workflow/include.inc"; require_once "modules/com_vtiger_workflow/tasks/VTEntityMethodTask.inc"; require_once "modules/com_vtiger_workflow/VTEntityMethodManager.inc"; //added column defaultworkflow //For default workflows it sets column defaultworkflow=true $column_name = "defaultworkflow"; $adb->pquery("alter table com_vtiger_workflows add column {$column_name} int(1)", array()); // Creating Workflow for Accounts when Notifyowner is true $vtaWorkFlow = new VTWorkflowManager($adb); $accWorkFlow = $vtaWorkFlow->newWorkFlow("Accounts"); $accWorkFlow->test = '[{"fieldname":"notify_owner","operation":"is","value":"true:boolean"}]'; $accWorkFlow->description = "Send Email to user when Notifyowner is True"; $accWorkFlow->executionCondition = 2; $vtaWorkFlow->save($accWorkFlow); $id1 = $accWorkFlow->id; $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEmailTask', $accWorkFlow->id); $task->active = true; $task->methodName = "NotifyOwner"; $task->recepient = "\$(assigned_user_id : (Users) email1)"; $task->subject = "Regarding Account Creation"; $task->content = "An Account has been assigned to you on vtigerCRM<br>Details of account are :<br><br>" . "AccountId:" . '<b>$account_no</b><br>' . "AccountName:" . '<b>$accountname</b><br>' . "Rating:" . '<b>$rating</b><br>' . "Industry:" . '<b>$industry</b><br>' . "AccountType:" . '<b>$accounttype</b><br>' . "Description:" . '<b>$description</b><br><br><br>' . "Thank You<br>Admin"; $task->summary = "An account has been created "; $tm->saveTask($task); $adb->pquery("update com_vtiger_workflows set defaultworkflow=? where workflow_id=?", array(1, $id1)); // Creating Workflow for Contacts when Notifyowner is true $vtcWorkFlow = new VTWorkflowManager($adb); $conWorkFlow = $vtcWorkFlow->newWorkFlow("Contacts"); $conWorkFlow->summary = "Test accounut"; $conWorkFlow->executionCondition = 2; $conWorkFlow->test = '[{"fieldname":"notify_owner","operation":"is","value":"true:boolean"}]'; $conWorkFlow->description = "Send Email to user when Notifyowner is True"; $vtcWorkFlow->save($conWorkFlow); $id1 = $conWorkFlow->id; $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEmailTask', $conWorkFlow->id); $task->active = true; $task->methodName = "NotifyOwner"; $task->recepient = "\$(assigned_user_id : (Users) email1)"; $task->subject = "Regarding Contact Creation"; $task->content = "An Contact has been assigned to you on vtigerCRM<br>Details of Contact are :<br><br>" . "Contact Id:" . '<b>$contact_no</b><br>' . "LastName:" . '<b>$lastname</b><br>' . "FirstName:" . '<b>$firstname</b><br>' . "Lead Source:" . '<b>$leadsource</b><br>' . "Department:" . '<b>$department</b><br>' . "Description:" . '<b>$description</b><br><br><br>' . "Thank You<br>Admin"; $task->summary = "An contact has been created "; $tm->saveTask($task); $adb->pquery("update com_vtiger_workflows set defaultworkflow=? where workflow_id=?", array(1, $id1)); // Creating Workflow for Contacts when PortalUser is true $vtcWorkFlow = new VTWorkflowManager($adb); $conpuWorkFlow = $vtcWorkFlow->newWorkFlow("Contacts"); $conpuWorkFlow->test = '[{"fieldname":"portal","operation":"is","value":"true:boolean"}]'; $conpuWorkFlow->description = "Send Email to user when Portal User is True"; $conpuWorkFlow->executionCondition = 2; $vtcWorkFlow->save($conpuWorkFlow); $id1 = $conpuWorkFlow->id; $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEmailTask', $conpuWorkFlow->id); $task->active = true; $task->methodName = "NotifyOwner"; $task->recepient = "\$(assigned_user_id : (Users) email1)"; $task->subject = "Regarding Contact Assignment"; $task->content = "An Contact has been assigned to you on vtigerCRM<br>Details of Contact are :<br><br>" . "Contact Id:" . '<b>$contact_no</b><br>' . "LastName:" . '<b>$lastname</b><br>' . "FirstName:" . '<b>$firstname</b><br>' . "Lead Source:" . '<b>$leadsource</b><br>' . "Department:" . '<b>$department</b><br>' . "Description:" . '<b>$description</b><br><br><br>' . "And <b>CustomerPortal Login Details</b> is sent to the " . "EmailID :-" . '$email<br>' . "<br>Thank You<br>Admin"; $task->summary = "An contact has been created "; $tm->saveTask($task); $adb->pquery("update com_vtiger_workflows set defaultworkflow=? where workflow_id=?", array(1, $id1)); // Creating Workflow for Potentials $vtcWorkFlow = new VTWorkflowManager($adb); $potentialWorkFlow = $vtcWorkFlow->newWorkFlow("Potentials"); $potentialWorkFlow->description = "Send Email to user on Potential creation"; $potentialWorkFlow->executionCondition = 1; $vtcWorkFlow->save($potentialWorkFlow); $id1 = $potentialWorkFlow->id; $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEmailTask', $potentialWorkFlow->id); $task->active = true; $task->recepient = "\$(assigned_user_id : (Users) email1)"; $task->subject = "Regarding Potential Assignment"; $task->content = "An Potential has been assigned to you on vtigerCRM<br>Details of Potential are :<br><br>" . "Potential No:" . '<b>$potential_no</b><br>' . "Potential Name:" . '<b>$potentialname</b><br>' . "Amount:" . '<b>$amount</b><br>' . "Expected Close Date:" . '<b>$closingdate</b><br>' . "Type:" . '<b>$opportunity_type</b><br><br><br>' . "Description :" . '$description<br>' . "<br>Thank You<br>Admin"; $task->summary = "An Potential has been created "; $tm->saveTask($task); $adb->pquery("update com_vtiger_workflows set defaultworkflow=? where workflow_id=?", array(1, $id1)); }
/** * Invoked when special actions are performed on the module. * @param String Module name * @param String Event Type (module.postinstall, module.disabled, module.enabled, module.preuninstall) */ function vtlib_handler($modulename, $event_type) { global $adb; require_once 'include/events/include.inc'; include_once 'vtlib/Vtiger/Module.php'; if ($event_type == 'module.postinstall') { // TODO Handle post installation actions $modAccounts = Vtiger_Module::getInstance('Accounts'); $modContacts = Vtiger_Module::getInstance('Contacts'); $modInvD = Vtiger_Module::getInstance('InventoryDetails'); $modIss = Vtiger_Module::getInstance('Issuecards'); if ($modAccounts) { $modAccounts->setRelatedList($modIss, 'Issuecards', array('ADD'), 'get_dependents_list'); } if ($modContacts) { $modContacts->setRelatedList($modIss, 'Issuecards', array('ADD'), 'get_dependents_list'); } if ($modInvD) { $field = Vtiger_Field::getInstance('related_to', $modInvD); $field->setRelatedModules(array('Issuecards')); $modIss->setRelatedList($modInvD, 'InventoryDetails', array(''), 'get_dependents_list'); } //Add Gendoc to Issuecards if (vtlib_isModuleActive("evvtgendoc")) { $modIss->addLink('LISTVIEWBASIC', 'Generate Document', "javascript:showgendoctemplates('\$MODULE\$');"); $modIss->addLink('DETAILVIEWWIDGET', 'Generate Document', "module=evvtgendoc&action=evvtgendocAjax&file=DetailViewWidget&formodule=\$MODULE\$&forrecord=\$RECORD\$", 'modules/evvtgendoc/evvtgendoc.gif'); } $emm = new VTEntityMethodManager($adb); // Adding EntityMethod for Updating Products data after updating PurchaseOrder $emm->addEntityMethod("Issuecards", "UpdateInventory", "include/InventoryHandler.php", "handleInventoryProductRel"); // Creating Workflow for Updating Inventory Stock on Issuecards $vtWorkFlow = new VTWorkflowManager($adb); $invWorkFlow = $vtWorkFlow->newWorkFlow("Issuecards"); $invWorkFlow->test = '[{"fieldname":"pslip_no","operation":"does not contain","value":"`!`"}]'; $invWorkFlow->description = "UpdateInventoryProducts On Every Save"; $invWorkFlow->defaultworkflow = 1; $vtWorkFlow->save($invWorkFlow); $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEntityMethodTask', $invWorkFlow->id); $task->active = true; $task->methodName = "UpdateInventory"; $task->summary = "Update product stock"; $tm->saveTask($task); $this->setModuleSeqNumber('configure', $modulename, 'pslip-', '0000001'); } else { if ($event_type == 'module.disabled') { // TODO Handle actions when this module is disabled. } else { if ($event_type == 'module.enabled') { // TODO Handle actions when this module is enabled. } else { if ($event_type == 'module.preuninstall') { // TODO Handle actions when this module is about to be deleted. } else { if ($event_type == 'module.preupdate') { // TODO Handle actions before this module is updated. } else { if ($event_type == 'module.postupdate') { // TODO Handle actions after this module is updated. $modInvD = Vtiger_Module::getInstance('InventoryDetails'); $modIss = Vtiger_Module::getInstance('Issuecards'); //Add subject field to can import and export $block = Vtiger_Block::getInstance('LBL_ISSUECARDS_INFO', $modIss); $field = Vtiger_Field::getInstance('subject', $modIss); if (!$field) { $field1 = new Vtiger_Field(); $field1->name = 'subject'; $field1->label = 'subject'; $field1->table = 'vtiger_issuecards'; $field1->column = 'subject'; $field1->columntype = 'VARCHAR(100)'; $field1->sequence = 3; $field1->uitype = 1; $field1->typeofdata = 'V~O'; $field1->displaytype = 1; $field1->presence = 0; $block->addField($field1); } if ($modInvD) { $field = Vtiger_Field::getInstance('related_to', $modInvD); $field->setRelatedModules(array('Issuecards')); $modIss->setRelatedList($modInvD, 'InventoryDetails', array(''), 'get_dependents_list'); } //Add Gendoc to Issuecards if (vtlib_isModuleActive("evvtgendoc")) { $modIss->addLink('LISTVIEWBASIC', 'Generate Document', "javascript:showgendoctemplates('\$MODULE\$');"); $modIss->addLink('DETAILVIEWWIDGET', 'Generate Document', "module=evvtgendoc&action=evvtgendocAjax&file=DetailViewWidget&formodule=\$MODULE\$&forrecord=\$RECORD\$", 'modules/evvtgendoc/evvtgendoc.gif'); } $emm = new VTEntityMethodManager($adb); // Adding EntityMethod for Updating Products data after updating Issuecards $emm->addEntityMethod("Issuecards", "UpdateInventory", "include/InventoryHandler.php", "handleInventoryProductRel"); // Creating Workflow for Updating Inventory Stock on Issuecards $vtWorkFlow = new VTWorkflowManager($adb); $invWorkFlow = $vtWorkFlow->newWorkFlow("Issuecards"); $invWorkFlow->test = '[{"fieldname":"pslip_no","operation":"does not contain","value":"`!`"}]'; $invWorkFlow->description = "UpdateInventoryProducts On Every Save"; $invWorkFlow->defaultworkflow = 1; $vtWorkFlow->save($invWorkFlow); $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEntityMethodTask', $invWorkFlow->id); $task->active = true; $task->methodName = "UpdateInventory"; $task->summary = "Update product stock"; $tm->saveTask($task); } } } } } } }
public static function checkLockEdit($moduleName, $record) { if (isset(self::$lockEditCache[$moduleName . $record])) { return self::$lockEditCache[$moduleName . $record]; } $return = false; if (empty($record)) { self::$lockEditCache[$moduleName . $record] = $return; return $return; } $currentUserModel = Users_Record_Model::getCurrentUserModel(); $currentUserId = $currentUserModel->getId(); vimport('~~modules/com_vtiger_workflow/include.inc'); vimport('~~modules/com_vtiger_workflow/VTEntityMethodManager.inc'); vimport('~~modules/com_vtiger_workflow/VTEntityCache.inc'); vimport('~~include/Webservices/Retrieve.php'); $wfs = new VTWorkflowManager(PearDatabase::getInstance()); $workflows = $wfs->getWorkflowsForModule($moduleName, VTWorkflowManager::$BLOCK_EDIT); if (count($workflows)) { $wsId = vtws_getWebserviceEntityId($moduleName, $record); $entityCache = new VTEntityCache($currentUserModel); $entityData = $entityCache->forId($wsId); foreach ($workflows as $id => $workflow) { if ($workflow->evaluate($entityCache, $entityData->getId())) { $return = true; } } } self::$lockEditCache[$moduleName . $record] = $return; return $return; }
private function addWorkflow($moduleName) { vimport('~~modules/com_vtiger_workflow/include.inc'); vimport('~~modules/com_vtiger_workflow/tasks/VTEntityMethodTask.inc'); vimport('~~modules/com_vtiger_workflow/VTEntityMethodManager.inc'); $db = PearDatabase::getInstance(); $functionName = 'UpdateBalance'; $emm = new VTEntityMethodManager($db); $emm->addEntityMethod($moduleName, $functionName, "modules/PaymentsIn/workflow/UpdateBalance.php", $functionName); $workflowManager = new VTWorkflowManager($db); $taskManager = new VTTaskManager($db); $newWorkflow = $workflowManager->newWorkFlow($moduleName); $newWorkflow->test = '[]'; $newWorkflow->defaultworkflow = 0; $newWorkflow->description = "{$moduleName} - UpdateBalance"; $newWorkflow->executionCondition = 3; $workflowManager->save($newWorkflow); $task = $taskManager->createTask('VTEntityMethodTask', $newWorkflow->id); $task->active = true; $task->summary = 'UpdateBalance'; $task->methodName = $functionName; $taskManager->saveTask($task); }
function vtWorkflowSave($adb, $request) { $util = new VTWorkflowUtils(); $module = new VTWorkflowApplication("saveworkflow"); $mod = return_module_language($current_language, $module->name); $request = vtlib_purify($request); // this cleans all values of the array if (!$util->checkAdminAccess()) { $errorUrl = $module->errorPageUrl($mod['LBL_ERROR_NOT_ADMIN']); $util->redirectTo($errorUrl, $mod['LBL_ERROR_NOT_ADMIN']); return; } $description = from_html($request["description"]); $moduleName = $request["module_name"]; $conditions = $request["conditions"]; $taskId = $request["task_id"]; $saveType = $request["save_type"]; $executionCondition = $request['execution_condition']; $schdayofweek = array(); if (isset($request['sun_flag']) && $_REQUEST['sun_flag'] != null) { $schdayofweek[] = 1; } if (isset($request['mon_flag']) && $_REQUEST['mon_flag'] != null) { $schdayofweek[] = 2; } if (isset($request['tue_flag']) && $_REQUEST['tue_flag'] != null) { $schdayofweek[] = 3; } if (isset($request['wed_flag']) && $_REQUEST['wed_flag'] != null) { $schdayofweek[] = 4; } if (isset($request['thu_flag']) && $_REQUEST['thu_flag'] != null) { $schdayofweek[] = 5; } if (isset($request['fri_flag']) && $_REQUEST['fri_flag'] != null) { $schdayofweek[] = 6; } if (isset($request['sat_flag']) && $_REQUEST['sat_flag'] != null) { $schdayofweek[] = 7; } // internally the code is prepared to launch the same workflow on many dates // but the interface only sends one in // TODO: change interface to send in many dates for annual scheduling $schannualdates = DateTimeField::convertToDBFormat($request['schdate']); $schannualdates = json_encode(array($schannualdates)); $schminuteinterval = $request['schminuteinterval']; $wm = new VTWorkflowManager($adb); if ($saveType == 'new') { $wf = $wm->newWorkflow($moduleName); $wf->description = $description; $wf->test = $conditions; $wf->taskId = $taskId; $wf->executionConditionAsLabel($executionCondition); $wf->schtypeid = $request['schtypeid']; $wf->schtime = VTCreateEventTask::conv12to24hour($request['schtime']); $wf->schdayofmonth = json_encode($request['schdayofmonth']); $wf->schdayofweek = json_encode($schdayofweek); $wf->schannualdates = $schannualdates; $wf->schminuteinterval = $schminuteinterval; $wm->save($wf); } else { if ($saveType == 'edit') { $wf = $wm->retrieve($request["workflow_id"]); $wf->description = $description; $wf->test = $conditions; $wf->taskId = $taskId; $wf->executionConditionAsLabel($executionCondition); $wf->schtypeid = $request['schtypeid']; $wf->schtime = VTCreateEventTask::conv12to24hour($request['schtime']); $wf->schdayofmonth = json_encode($request['schdayofmonth']); $wf->schdayofweek = json_encode($schdayofweek); $wf->schannualdates = $schannualdates; $wf->schminuteinterval = $schminuteinterval; $wm->save($wf); } else { throw new Exception(); } } if (isset($request["return_url"])) { $returnUrl = $request["return_url"]; } else { $returnUrl = $module->editWorkflowUrl($wf->id); } ?> <script type="text/javascript" charset="utf-8"> window.location="<?php echo $returnUrl; ?> "; </script> <a href="<?php echo $returnUrl; ?> ">Return</a> <?php }
/** Returns a list of the associated opportunities */ function get_opportunities($id, $cur_tab_id, $rel_tab_id, $actions = false) { global $log, $singlepane_view, $currentModule, $current_user, $adb; $log->debug("Entering get_opportunities(" . $id . ") method ..."); $this_module = $currentModule; $related_module = vtlib_getModuleNameById($rel_tab_id); require_once "modules/{$related_module}/{$related_module}.php"; $other = new $related_module(); vtlib_setup_modulevars($related_module, $other); $singular_modname = vtlib_toSingular($related_module); $parenttab = getParentTab(); if ($singlepane_view == 'true') { $returnset = '&return_module=' . $this_module . '&return_action=DetailView&return_id=' . $id; } else { $returnset = '&return_module=' . $this_module . '&return_action=CallRelatedList&return_id=' . $id; } $button = ''; if ($actions) { if (is_string($actions)) { $actions = explode(',', strtoupper($actions)); } if (in_array('SELECT', $actions) && isPermitted($related_module, 4, '') == 'yes') { $button .= "<input title='" . getTranslatedString('LBL_SELECT') . " " . getTranslatedString($related_module) . "' class='crmbutton small edit' type='button' onclick=\"return window.open('index.php?module={$related_module}&return_module={$currentModule}&action=Popup&popuptype=detailview&select=enable&form=EditView&form_submit=false&recordid={$id}&parenttab={$parenttab}','test','width=640,height=602,resizable=0,scrollbars=0');\" value='" . getTranslatedString('LBL_SELECT') . " " . getTranslatedString($related_module) . "'> "; } if (in_array('ADD', $actions) && isPermitted($related_module, 1, '') == 'yes') { $wfs = new VTWorkflowManager($adb); $racbr = $wfs->getRACRuleForRecord($currentModule, $id); if (!$racbr or $racbr->hasRelatedListPermissionTo('create', $related_module)) { $button .= "<input title='" . getTranslatedString('LBL_NEW') . " " . getTranslatedString($singular_modname) . "' class='crmbutton small create'" . " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"{$related_module}\";' type='submit' name='button'" . " value='" . getTranslatedString('LBL_ADD_NEW') . " " . getTranslatedString($singular_modname) . "'> "; } } } $userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); $query = 'select case when (vtiger_users.user_name not like "") then ' . $userNameSql . ' else vtiger_groups.groupname end as user_name, vtiger_contactdetails.accountid, vtiger_contactdetails.contactid , vtiger_potential.potentialid, vtiger_potential.potentialname, vtiger_potential.potentialtype, vtiger_potential.sales_stage, vtiger_potential.amount, vtiger_potential.closingdate, vtiger_potential.related_to, vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_account.accountname from vtiger_contactdetails left join vtiger_contpotentialrel on vtiger_contpotentialrel.contactid=vtiger_contactdetails.contactid left join vtiger_potential on (vtiger_potential.potentialid = vtiger_contpotentialrel.potentialid or vtiger_potential.related_to=vtiger_contactdetails.contactid) inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_potential.potentialid left join vtiger_account on vtiger_account.accountid=vtiger_contactdetails.accountid left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid where vtiger_contactdetails.contactid =' . $id . ' and (vtiger_contactdetails.accountid = vtiger_potential.related_to or vtiger_contactdetails.contactid=vtiger_potential.related_to) and vtiger_crmentity.deleted=0'; $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); if ($return_value == null) { $return_value = array(); } $return_value['CUSTOM_BUTTON'] = $button; $log->debug("Exiting get_opportunities method ..."); return $return_value; }
function populateDefaultWorkflows($adb) { require_once "modules/com_vtiger_workflow/include.inc"; require_once "modules/com_vtiger_workflow/tasks/VTEntityMethodTask.inc"; require_once "modules/com_vtiger_workflow/VTEntityMethodManager.inc"; // Creating Workflow for Updating Inventory Stock for Invoice $vtWorkFlow = new VTWorkflowManager($adb); $invWorkFlow = $vtWorkFlow->newWorkFlow("Invoice"); $invWorkFlow->test = '[{"fieldname":"subject","operation":"does not contain","value":"`!`"}]'; $invWorkFlow->description = "UpdateInventoryProducts On Every Save"; $invWorkFlow->defaultworkflow = 1; $vtWorkFlow->save($invWorkFlow); $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEntityMethodTask', $invWorkFlow->id); $task->active = true; $task->methodName = "UpdateInventory"; $tm->saveTask($task); // Creating Workflow for Accounts when Notifyowner is true $vtaWorkFlow = new VTWorkflowManager($adb); $accWorkFlow = $vtaWorkFlow->newWorkFlow("Accounts"); $accWorkFlow->test = '[{"fieldname":"notify_owner","operation":"is","value":"true:boolean"}]'; $accWorkFlow->description = "Send Email to user when Notifyowner is True"; $accWorkFlow->executionCondition = 2; $accWorkFlow->defaultworkflow = 1; $vtaWorkFlow->save($accWorkFlow); $id1 = $accWorkFlow->id; $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEmailTask', $accWorkFlow->id); $task->active = true; $task->methodName = "NotifyOwner"; $task->recepient = "\$(assigned_user_id : (Users) email1)"; $task->subject = "Regarding Account Creation"; $task->content = "An Account has been assigned to you on vtigerCRM<br>Details of account are :<br><br>" . "AccountId:" . '<b>$account_no</b><br>' . "AccountName:" . '<b>$accountname</b><br>' . "Rating:" . '<b>$rating</b><br>' . "Industry:" . '<b>$industry</b><br>' . "AccountType:" . '<b>$accounttype</b><br>' . "Description:" . '<b>$description</b><br><br><br>' . "Thank You<br>Admin"; $task->summary = "An account has been created "; $tm->saveTask($task); $adb->pquery("update com_vtiger_workflows set defaultworkflow=? where workflow_id=?", array(1, $id1)); // Creating Workflow for Contacts when Notifyowner is true $vtcWorkFlow = new VTWorkflowManager($adb); $conWorkFlow = $vtcWorkFlow->newWorkFlow("Contacts"); $conWorkFlow->summary = "A contact has been created "; $conWorkFlow->executionCondition = 2; $conWorkFlow->test = '[{"fieldname":"notify_owner","operation":"is","value":"true:boolean"}]'; $conWorkFlow->description = "Send Email to user when Notifyowner is True"; $conWorkFlow->defaultworkflow = 1; $vtcWorkFlow->save($conWorkFlow); $id1 = $conWorkFlow->id; $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEmailTask', $conWorkFlow->id); $task->active = true; $task->methodName = "NotifyOwner"; $task->recepient = "\$(assigned_user_id : (Users) email1)"; $task->subject = "Regarding Contact Creation"; $task->content = "An Contact has been assigned to you on vtigerCRM<br>Details of Contact are :<br><br>" . "Contact Id:" . '<b>$contact_no</b><br>' . "LastName:" . '<b>$lastname</b><br>' . "FirstName:" . '<b>$firstname</b><br>' . "Lead Source:" . '<b>$leadsource</b><br>' . "Department:" . '<b>$department</b><br>' . "Description:" . '<b>$description</b><br><br><br>' . "Thank You<br>Admin"; $task->summary = "An contact has been created "; $tm->saveTask($task); $adb->pquery("update com_vtiger_workflows set defaultworkflow=? where workflow_id=?", array(1, $id1)); // Creating Workflow for Contacts when PortalUser is true $vtcWorkFlow = new VTWorkflowManager($adb); $conpuWorkFlow = $vtcWorkFlow->newWorkFlow("Contacts"); $conpuWorkFlow->test = '[{"fieldname":"portal","operation":"is","value":"true:boolean"}]'; $conpuWorkFlow->description = "Send Email to user when Portal User is True"; $conpuWorkFlow->executionCondition = 2; $conpuWorkFlow->defaultworkflow = 1; $vtcWorkFlow->save($conpuWorkFlow); $id1 = $conpuWorkFlow->id; $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEmailTask', $conpuWorkFlow->id); $task->active = true; $task->methodName = "NotifyOwner"; $task->recepient = "\$(assigned_user_id : (Users) email1)"; $task->subject = "Regarding Contact Assignment"; $task->content = "An Contact has been assigned to you on vtigerCRM<br>Details of Contact are :<br><br>" . "Contact Id:" . '<b>$contact_no</b><br>' . "LastName:" . '<b>$lastname</b><br>' . "FirstName:" . '<b>$firstname</b><br>' . "Lead Source:" . '<b>$leadsource</b><br>' . "Department:" . '<b>$department</b><br>' . "Description:" . '<b>$description</b><br><br><br>' . "And <b>CustomerPortal Login Details</b> is sent to the " . "EmailID :-" . '$email<br>' . "<br>Thank You<br>Admin"; $task->summary = "An contact has been created "; $tm->saveTask($task); $adb->pquery("update com_vtiger_workflows set defaultworkflow=? where workflow_id=?", array(1, $id1)); // Creating Workflow for Potentials $vtcWorkFlow = new VTWorkflowManager($adb); $potentialWorkFlow = $vtcWorkFlow->newWorkFlow("Potentials"); $potentialWorkFlow->description = "Send Email to users on Potential creation"; $potentialWorkFlow->executionCondition = 1; $potentialWorkFlow->defaultworkflow = 1; $vtcWorkFlow->save($potentialWorkFlow); $id1 = $potentialWorkFlow->id; $tm = new VTTaskManager($adb); $task = $tm->createTask('VTEmailTask', $potentialWorkFlow->id); $task->active = true; $task->recepient = "\$(assigned_user_id : (Users) email1)"; $task->subject = "Regarding Potential Assignment"; $task->content = "An Potential has been assigned to you on vtigerCRM<br>Details of Potential are :<br><br>" . "Potential No:" . '<b>$potential_no</b><br>' . "Potential Name:" . '<b>$potentialname</b><br>' . "Amount:" . '<b>$amount</b><br>' . "Expected Close Date:" . '<b>$closingdate</b><br>' . "Type:" . '<b>$opportunity_type</b><br><br><br>' . "Description :" . '$description<br>' . "<br>Thank You<br>Admin"; $task->summary = "An Potential has been created "; $tm->saveTask($task); $workflowManager = new VTWorkflowManager($adb); $taskManager = new VTTaskManager($adb); // Contact workflow on creation/modification $contactWorkFlow = $workflowManager->newWorkFlow("Contacts"); $contactWorkFlow->test = ''; $contactWorkFlow->description = "Workflow for Contact Creation or Modification"; $contactWorkFlow->executionCondition = VTWorkflowManager::$ON_EVERY_SAVE; $contactWorkFlow->defaultworkflow = 1; $workflowManager->save($contactWorkFlow); $task = $taskManager->createTask('VTEntityMethodTask', $contactWorkFlow->id); $task->active = true; $task->summary = 'Email Customer Portal Login Details'; $task->methodName = "SendPortalLoginDetails"; $taskManager->saveTask($task); // Trouble Tickets workflow on creation from Customer Portal $helpDeskWorkflow = $workflowManager->newWorkFlow("HelpDesk"); $helpDeskWorkflow->test = '[{"fieldname":"from_portal","operation":"is","value":"true:boolean"}]'; $helpDeskWorkflow->description = "Workflow for Ticket Created from Portal"; $helpDeskWorkflow->executionCondition = VTWorkflowManager::$ON_FIRST_SAVE; $helpDeskWorkflow->defaultworkflow = 1; $workflowManager->save($helpDeskWorkflow); $task = $taskManager->createTask('VTEntityMethodTask', $helpDeskWorkflow->id); $task->active = true; $task->summary = 'Notify Record Owner and the Related Contact when Ticket is created from Portal'; $task->methodName = "NotifyOnPortalTicketCreation"; $taskManager->saveTask($task); // Trouble Tickets workflow on ticket update from Customer Portal $helpDeskWorkflow = $workflowManager->newWorkFlow("HelpDesk"); $helpDeskWorkflow->test = '[{"fieldname":"from_portal","operation":"is","value":"true:boolean"}]'; $helpDeskWorkflow->description = "Workflow for Ticket Updated from Portal"; $helpDeskWorkflow->executionCondition = VTWorkflowManager::$ON_MODIFY; $helpDeskWorkflow->defaultworkflow = 1; $workflowManager->save($helpDeskWorkflow); $task = $taskManager->createTask('VTEntityMethodTask', $helpDeskWorkflow->id); $task->active = true; $task->summary = 'Notify Record Owner when Comment is added to a Ticket from Customer Portal'; $task->methodName = "NotifyOnPortalTicketComment"; $taskManager->saveTask($task); // Trouble Tickets workflow on ticket change, which is not from Customer Portal - Both Record Owner and Related Customer $helpDeskWorkflow = $workflowManager->newWorkFlow("HelpDesk"); $helpDeskWorkflow->test = '[{"fieldname":"from_portal","operation":"is","value":"false:boolean"}]'; $helpDeskWorkflow->description = "Workflow for Ticket Change, not from the Portal"; $helpDeskWorkflow->executionCondition = VTWorkflowManager::$ON_EVERY_SAVE; $helpDeskWorkflow->defaultworkflow = 1; $workflowManager->save($helpDeskWorkflow); $task = $taskManager->createTask('VTEntityMethodTask', $helpDeskWorkflow->id); $task->active = true; $task->summary = 'Notify Record Owner on Ticket Change, which is not done from Portal'; $task->methodName = "NotifyOwnerOnTicketChange"; $taskManager->saveTask($task); $task = $taskManager->createTask('VTEntityMethodTask', $helpDeskWorkflow->id); $task->active = true; $task->summary = 'Notify Related Customer on Ticket Change, which is not done from Portal'; $task->methodName = "NotifyParentOnTicketChange"; $taskManager->saveTask($task); // Events workflow when Send Notification is checked $eventsWorkflow = $workflowManager->newWorkFlow("Events"); $eventsWorkflow->test = '[{"fieldname":"sendnotification","operation":"is","value":"true:boolean"}]'; $eventsWorkflow->description = "Workflow for Events when Send Notification is True"; $eventsWorkflow->executionCondition = VTWorkflowManager::$ON_EVERY_SAVE; $eventsWorkflow->defaultworkflow = 1; $workflowManager->save($eventsWorkflow); $task = $taskManager->createTask('VTEmailTask', $eventsWorkflow->id); $task->active = true; $task->summary = 'Send Notification Email to Record Owner'; $task->recepient = "\$(assigned_user_id : (Users) email1)"; $task->subject = "Event : \$subject"; $task->content = '$(assigned_user_id : (Users) first_name) $(assigned_user_id : (Users) last_name) ,<br/>' . '<b>Activity Notification Details:</b><br/>' . 'Subject : $subject<br/>' . 'Start date and time : $date_start $time_start ( $(general : (__VtigerMeta__) dbtimezone) ) <br/>' . 'End date and time : $due_date $time_end ( $(general : (__VtigerMeta__) dbtimezone) ) <br/>' . 'Status : $eventstatus <br/>' . 'Priority : $taskpriority <br/>' . 'Related To : $(parent_id : (Leads) lastname) $(parent_id : (Leads) firstname) $(parent_id : (Accounts) accountname) ' . '$(parent_id : (Potentials) potentialname) $(parent_id : (HelpDesk) ticket_title) <br/>' . 'Contacts List : $(contact_id : (Contacts) lastname) $(contact_id : (Contacts) firstname) <br/>' . 'Location : $location <br/>' . 'Description : $description'; $taskManager->saveTask($task); // Calendar workflow when Send Notification is checked $calendarWorkflow = $workflowManager->newWorkFlow("Calendar"); $calendarWorkflow->test = '[{"fieldname":"sendnotification","operation":"is","value":"true:boolean"}]'; $calendarWorkflow->description = "Workflow for Calendar Todos when Send Notification is True"; $calendarWorkflow->executionCondition = VTWorkflowManager::$ON_EVERY_SAVE; $calendarWorkflow->defaultworkflow = 1; $workflowManager->save($calendarWorkflow); $task = $taskManager->createTask('VTEmailTask', $calendarWorkflow->id); $task->active = true; $task->summary = 'Send Notification Email to Record Owner'; $task->recepient = "\$(assigned_user_id : (Users) email1)"; $task->subject = "Task : \$subject"; $task->content = '$(assigned_user_id : (Users) first_name) $(assigned_user_id : (Users) last_name) ,<br/>' . '<b>Task Notification Details:</b><br/>' . 'Subject : $subject<br/>' . 'Start date and time : $date_start $time_start ( $(general : (__VtigerMeta__) dbtimezone) ) <br/>' . 'End date and time : $due_date ( $(general : (__VtigerMeta__) dbtimezone) ) <br/>' . 'Status : $taskstatus <br/>' . 'Priority : $taskpriority <br/>' . 'Related To : $(parent_id : (Leads) lastname) $(parent_id : (Leads) firstname) $(parent_id : (Accounts) accountname) ' . '$(parent_id : (Potentials) potentialname) $(parent_id : (HelpDesk) ticket_title) <br/>' . 'Contacts List : $(contact_id : (Contacts) lastname) $(contact_id : (Contacts) firstname) <br/>' . 'Location : $location <br/>' . 'Description : $description'; $taskManager->saveTask($task); }
function vtTaskEdit($adb, $request, $current_language, $app_strings) { global $theme; $util = new VTWorkflowUtils(); $request = vtlib_purify($request); // this cleans all values of the array $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"]); $taskClass = get_class($task); $workflowId = $task->workflowId; } else { $workflowId = $request["workflow_id"]; $taskClass = vtlib_purifyForSql($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']); $taskTypeInstance = VTTaskType::getInstanceFromTaskType($taskClass); $taskTemplateClass = $tm->retrieveTemplatePath($module->name, $taskTypeInstance); $smarty->assign("taskTemplate", $taskTemplateClass); $et = VTWSEntityType::usingGlobalCurrentUser($workflow->moduleName); $smarty->assign("entityType", $et); $smarty->assign('entityName', $workflow->moduleName); $smarty->assign("fieldNames", $et->getFieldNames()); $repeat_date = $task->calendar_repeat_limit_date; if (!empty($repeat_date)) { $repeat_date = DateTimeField::convertToUserFormat($repeat_date); } $smarty->assign('REPEAT_DATE', $repeat_date); $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'])); } $metaVariables = $task->getMetaVariables(); $date = new DateTimeField(null); $time = substr($date->getDisplayTime(), 0, 5); $smarty->assign("META_VARIABLES", $metaVariables); $smarty->assign("SYSTEM_TIMEZONE", $db_timezone); $smarty->assign("USER_TIME", $task->formatTimeForTimePicker($time)); $smarty->assign("USER_DATE", $date->getDisplayDate()); $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']); $users = $group = array(); $users['user'] = get_user_array(); $users['group'] = get_group_array(); $smarty->assign('ASSIGNED_TO', $users); $smarty->assign("module", $module); $smarty->display("{$module->name}/EditTask.tpl"); }
/** * Invoked when special actions are performed on the module. * @param String Module name * @param String Event Type (module.postinstall, module.disabled, module.enabled, module.preuninstall) */ function vtlib_handler($modulename, $event_type) { if ($event_type == 'module.postinstall') { //Handle post installation actions require_once "modules/com_vtiger_workflow/include.inc"; require_once "modules/com_vtiger_workflow/tasks/VTEntityMethodTask.inc"; require_once "modules/com_vtiger_workflow/VTEntityMethodManager.inc"; global $adb; $mod = Vtiger_Module::getInstance('InventoryDetails'); $this->setModuleSeqNumber('configure', $modulename, '', '000000001'); $modAccounts = Vtiger_Module::getInstance('Accounts'); $modContacts = Vtiger_Module::getInstance('Contacts'); $modVnd = Vtiger_Module::getInstance('Vendors'); $modInvoice = Vtiger_Module::getInstance('Invoice'); $modSO = Vtiger_Module::getInstance('SalesOrder'); $modPO = Vtiger_Module::getInstance('PurchaseOrder'); $modQt = Vtiger_Module::getInstance('Quotes'); $modPrd = Vtiger_Module::getInstance('Products'); $modSrv = Vtiger_Module::getInstance('Services'); if ($modAccounts) { $modAccounts->setRelatedList($mod, 'InventoryDetails', array(''), 'get_dependents_list'); } if ($modContacts) { $modContacts->setRelatedList($mod, 'InventoryDetails', array(''), 'get_dependents_list'); } if ($modVnd) { $modVnd->setRelatedList($mod, 'InventoryDetails', array(''), 'get_dependents_list'); } if ($modInvoice) { $modInvoice->setRelatedList($mod, 'InventoryDetails', array(''), 'get_dependents_list'); } if ($modSO) { $modSO->setRelatedList($mod, 'InventoryDetails', array(''), 'get_dependents_list'); } if ($modPO) { $modPO->setRelatedList($mod, 'InventoryDetails', array(''), 'get_dependents_list'); } if ($modQt) { $modQt->setRelatedList($mod, 'InventoryDetails', array(''), 'get_dependents_list'); } if ($modPrd) { $modPrd->setRelatedList($mod, 'InventoryDetails', array(''), 'get_dependents_list'); } if ($modSrv) { $modSrv->setRelatedList($mod, 'InventoryDetails', array(''), 'get_dependents_list'); } $wfrs = $adb->query("SELECT workflow_id FROM com_vtiger_workflows WHERE summary='Line Completed'"); if ($wfrs and $adb->num_rows($wfrs) == 1) { echo 'Workfolw already exists!'; } else { $workflowManager = new VTWorkflowManager($adb); $taskManager = new VTTaskManager($adb); $InvDtWorkFlow = $workflowManager->newWorkFlow("InventoryDetails"); $InvDtWorkFlow->test = '[{"fieldname":"units_delivered_received","operation":"equal to","value":"quantity","valuetype":"fieldname","joincondition":"and","groupid":"0"}]'; $InvDtWorkFlow->description = "Line Completed"; $InvDtWorkFlow->executionCondition = VTWorkflowManager::$ON_EVERY_SAVE; $InvDtWorkFlow->defaultworkflow = 1; $workflowManager->save($InvDtWorkFlow); $task = $taskManager->createTask('VTUpdateFieldsTask', $InvDtWorkFlow->id); $task->active = true; $task->summary = 'Mark as Line Completed'; $task->field_value_mapping = '[{"fieldname":"line_completed","valuetype":"rawtext","value":"true:boolean"}]'; $taskManager->saveTask($task); } } else { if ($event_type == 'module.disabled') { // TODO Handle actions when this module is disabled. } else { if ($event_type == 'module.enabled') { // TODO Handle actions when this module is enabled. } else { if ($event_type == 'module.preuninstall') { // TODO Handle actions when this module is about to be deleted. } else { if ($event_type == 'module.preupdate') { // TODO Handle actions before this module is updated. } else { if ($event_type == 'module.postupdate') { // TODO Handle actions after this module is updated. } } } } } } }
$query = 'SELECT 1 FROM vtiger_currencies WHERE currency_name=?'; $result = $adb->pquery($query, array('Sudanese Pound')); if ($adb->num_rows($result) <= 0) { //Inserting Currency Sudanese Pound to vtiger_currencies Migration_Index_View::ExecuteQuery('INSERT INTO vtiger_currencies (currencyid,currency_name,currency_code,currency_symbol) VALUES (' . $adb->getUniqueID("vtiger_currencies") . ',"Sudanese Pound","SDG","£")', array()); Vtiger_Utils::AddColumn('vtiger_mailmanager_mailattachments', 'cid', 'VARCHAR(100)'); } //73 ends //74 starts //Start: Moving Entity methods of Tickets to Workflows $result = $adb->pquery('SELECT DISTINCT workflow_id FROM com_vtiger_workflowtasks WHERE workflow_id IN (SELECT workflow_id FROM com_vtiger_workflows WHERE module_name IN (?) AND defaultworkflow = ?) AND task LIKE ?', array($moduleName, 1, '%VTEntityMethodTask%')); $numOfRows = $adb->num_rows($result); for ($i = 0; $i < $numOfRows; $i++) { $wfs = new VTWorkflowManager($adb); $workflowModel = $wfs->retrieve($adb->query_result($result, $i, 'workflow_id')); $workflowModel->filtersavedinnew = 6; $tm = new VTTaskManager($adb); $tasks = $tm->getTasksForWorkflow($workflowModel->id); foreach ($tasks as $task) { $properties = get_object_vars($task); $emailTask = new VTEmailTask(); $emailTask->executeImmediately = 0; $emailTask->summary = $properties['summary']; $emailTask->active = $properties['active']; switch ($properties['methodName']) { case 'NotifyOnPortalTicketCreation': $conditions = Zend_Json::decode($workflowModel->test); $oldCondtions = array(); if (!empty($conditions)) {