function vtSaveWorkflowTemplate($adb, $request)
{
    $util = new VTWorkflowUtils();
    $module = new VTWorkflowApplication("savetemplate");
    $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;
    }
    $title = vtlib_purifyForSql($request['title']);
    $workflowId = $request['workflow_id'];
    $wfs = new VTworkflowManager($adb);
    $workflow = $wfs->retrieve($workflowId);
    $tm = new VTWorkflowTemplateManager($adb);
    $tpl = $tm->newTemplate($title, $workflow);
    $tm->saveTemplate($tpl);
    $returnUrl = vtlib_purify($request['return_url']);
    ?>
		<script type="text/javascript" charset="utf-8">
			 window.location="<?php 
    echo $returnUrl;
    ?>
";
		</script>
		<a href="<?php 
    echo $returnUrl;
    ?>
">Return</a>
	<?php 
}
/**
 * This is a utility function to load a dumped templates files
 * into vtiger
 * @param $filename The name of the file to load.
 */
function loadTemplates($filename)
{
    global $adb;
    $str = file_get_contents('fetchtemplates.out');
    $tm = new VTWorkflowTemplateManager($adb);
    $tm->loadTemplates($str);
}
function vtTemplatesForModuleJson($adb, $request)
{
    $moduleName = $request['module_name'];
    $tm = new VTWorkflowTemplateManager($adb);
    $templates = $tm->getTemplatesForModule($moduleName);
    $arr = array();
    foreach ($templates as $template) {
        $arr[] = array("title" => $template->title, 'id' => $template->id);
    }
    echo Zend_Json::encode($arr);
}
Example #4
0
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");
}
Example #5
0
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");
}