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 }
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); } } }
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 static function getInstance($workflowId) { $db = PearDatabase::getInstance(); $wm = new VTWorkflowManager($db); $wf = $wm->retrieve($workflowId); return self::getInstanceFromWorkflowObject($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 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"); }
$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)) { $previousConditionGroupId = 0;
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 }
function vtWorkflowSave($adb, $request) { $util = new VTWorkflowUtils(); $module = new VTWorkflowApplication("saveworkflow"); $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; } $description = from_html($request["description"]); $moduleName = vtlib_purify($request["module_name"]); $conditions = $request["conditions"]; $taskId = $request["task_id"]; $saveType = vtlib_purify($request["save_type"]); //OnDemand Specific Starts $schtypeid = $request["schtypeid"]; $schtime = $request["s_time"]; if (!preg_match('/^[0-2]\\d(:[0-5]\\d){1,2}$/', $schtime) or substr($schtime, 0, 2) > 23) { // invalid time format $schtime = '00:00'; } $schdayofmonth = $request["s_dayofmonth"]; $schdayofweek = $request["s_dayofweek"]; $schmonth = $request["s_month"]; //OnDemand Specific Ends $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); $wf->filtersavedinnew = 5; //OnDemand Specific Starts $wf->schtypeid = $schtypeid; $wf->schtime = $schtime; $wf->schdayofmonth = $schdayofmonth; $wf->schdayofweek = $schdayofweek; $wf->schmonth = $schmonth; //OnDemand Specific Ends $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->filtersavedinnew = 5; //OnDemand Specific Starts $wf->schtypeid = $schtypeid; $wf->schtime = $schtime; $wf->schdayofmonth = $schdayofmonth; $wf->schdayofweek = $schdayofweek; $wf->schmonth = $schmonth; //OnDemand Specific Ends $wm->save($wf); } else { throw new Exception(); } } if (isset(vtlib_purify($request["return_url"]))) { $returnUrl = vtlib_purify($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 }