コード例 #1
0
 /**
  * Function adds default system workflows
  * @param <PearDatabase> $adb
  */
 static function populateDefaultWorkflows($adb)
 {
     vimport("~~modules/com_vtiger_workflow/include.inc");
     vimport("~~modules/com_vtiger_workflow/tasks/VTEntityMethodTask.inc");
     vimport("~~modules/com_vtiger_workflow/VTEntityMethodManager.inc");
     vimport("~~modules/com_vtiger_workflow/VTTaskManager.inc");
     // register the workflow tasks
     $taskTypes = array();
     $defaultModules = array('include' => array(), 'exclude' => array());
     $createToDoModules = array('include' => array("Leads", "Accounts", "Potentials", "Contacts", "HelpDesk", "Campaigns", "Quotes", "PurchaseOrder", "SalesOrder", "Invoice"), 'exclude' => array("Calendar", "FAQ", "Events"));
     $createEventModules = array('include' => array("Leads", "Accounts", "Potentials", "Contacts", "HelpDesk", "Campaigns"), 'exclude' => array("Calendar", "FAQ", "Events"));
     $taskTypes[] = array("name" => "VTEmailTask", "label" => "Send Mail", "classname" => "VTEmailTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTEmailTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTEmailTask.tpl", "modules" => $defaultModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTEntityMethodTask", "label" => "Invoke Custom Function", "classname" => "VTEntityMethodTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTEntityMethodTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTEntityMethodTask.tpl", "modules" => $defaultModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTCreateTodoTask", "label" => "Create Todo", "classname" => "VTCreateTodoTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTCreateTodoTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTCreateTodoTask.tpl", "modules" => $createToDoModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTCreateEventTask", "label" => "Create Event", "classname" => "VTCreateEventTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTCreateEventTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTCreateEventTask.tpl", "modules" => $createEventModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTUpdateFieldsTask", "label" => "Update Fields", "classname" => "VTUpdateFieldsTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTUpdateFieldsTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTUpdateFieldsTask.tpl", "modules" => $defaultModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTCreateEntityTask", "label" => "Create Entity", "classname" => "VTCreateEntityTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTCreateEntityTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTCreateEntityTask.tpl", "modules" => $defaultModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTSMSTask", "label" => "SMS Task", "classname" => "VTSMSTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTSMSTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTSMSTask.tpl", "modules" => $defaultModules, "sourcemodule" => 'SMSNotifier');
     foreach ($taskTypes as $taskType) {
         VTTaskType::registerTaskType($taskType);
     }
     // 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;
     $taskManager = new VTTaskManager($adb);
     $task = $taskManager->createTask('VTEntityMethodTask', $id1);
     $task->active = true;
     $task->summary = 'Email Customer Portal Login Details';
     $task->methodName = "SendPortalLoginDetails";
     $taskManager->saveTask($task);
     // 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);
     $tm = new VTTaskManager($adb);
     $task = $tm->createTask('VTEmailTask', $contactWorkFlow->id);
     $task->active = true;
     $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));
     // 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);
 }
コード例 #2
0
 /**
  * Function adds default system workflows
  * @param <PearDatabase> $adb
  */
 static function populateDefaultWorkflows($adb)
 {
     vimport("~~modules/com_vtiger_workflow/include.inc");
     vimport("~~modules/com_vtiger_workflow/tasks/VTEntityMethodTask.inc");
     vimport("~~modules/com_vtiger_workflow/VTEntityMethodManager.inc");
     vimport("~~modules/com_vtiger_workflow/VTTaskManager.inc");
     // register the workflow tasks
     $taskTypes = array();
     $defaultModules = array('include' => array(), 'exclude' => array());
     $createToDoModules = array('include' => array("Leads", "Accounts", "Potentials", "Contacts", "HelpDesk", "Campaigns", "Quotes", "PurchaseOrder", "SalesOrder", "Invoice"), 'exclude' => array("Calendar", "FAQ", "Events"));
     $createEventModules = array('include' => array("Leads", "Accounts", "Potentials", "Contacts", "HelpDesk", "Campaigns"), 'exclude' => array("Calendar", "FAQ", "Events"));
     $taskTypes[] = array("name" => "VTEmailTask", "label" => "Send Mail", "classname" => "VTEmailTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTEmailTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTEmailTask.tpl", "modules" => $defaultModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTEntityMethodTask", "label" => "Invoke Custom Function", "classname" => "VTEntityMethodTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTEntityMethodTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTEntityMethodTask.tpl", "modules" => $defaultModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTCreateTodoTask", "label" => "Create Todo", "classname" => "VTCreateTodoTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTCreateTodoTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTCreateTodoTask.tpl", "modules" => $createToDoModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTCreateEventTask", "label" => "Create Event", "classname" => "VTCreateEventTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTCreateEventTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTCreateEventTask.tpl", "modules" => $createEventModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTUpdateFieldsTask", "label" => "Update Fields", "classname" => "VTUpdateFieldsTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTUpdateFieldsTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTUpdateFieldsTask.tpl", "modules" => $defaultModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTCreateEntityTask", "label" => "Create Entity", "classname" => "VTCreateEntityTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTCreateEntityTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTCreateEntityTask.tpl", "modules" => $defaultModules, "sourcemodule" => '');
     $taskTypes[] = array("name" => "VTSMSTask", "label" => "SMS Task", "classname" => "VTSMSTask", "classpath" => "modules/com_vtiger_workflow/tasks/VTSMSTask.inc", "templatepath" => "com_vtiger_workflow/taskforms/VTSMSTask.tpl", "modules" => $defaultModules, "sourcemodule" => 'SMSNotifier');
     foreach ($taskTypes as $taskType) {
         VTTaskType::registerTaskType($taskType);
     }
     // 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"}]';
     // SalesPlatform.ru begin
     $accWorkFlow->description = "Отправить Email пользователю, если указано Уведомлять ответственного";
     //$accWorkFlow->description = "Send Email to user when Notifyowner is True";
     // SalesPlatform.ru end
     $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)";
     // SalesPlatform.ru begin
     $task->subject = "Уведомление о назначении Контрагента";
     $task->content = "В системе vtigerCRM Вам был назначен контрагент<br>Информация о контрагенте :<br><br>" . "Контрагент №:" . '<b>$account_no</b><br>' . "Контрагент:" . '<b>$accountname</b><br>' . "Рейтинг:" . '<b>$rating</b><br>' . "Отрасль:" . '<b>$industry</b><br>' . "Тип:" . '<b>$accounttype</b><br>' . "Описание:" . '<b>$description</b><br><br><br>' . "Спасибо,<br>Admin";
     $task->summary = "Создан Контрагент ";
     //$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 ";
     // SalesPlatform.ru end
     $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");
     // SalesPlatform.ru begin
     $conWorkFlow->summary = "Создан Контакт ";
     //$conWorkFlow->summary="A contact has been created ";
     // SalesPlatform.ru end
     $conWorkFlow->executionCondition = 2;
     $conWorkFlow->test = '[{"fieldname":"notify_owner","operation":"is","value":"true:boolean"}]';
     // SalesPlatform.ru begin
     $conWorkFlow->description = "Отправить Email пользователю, если указано Уведомлять ответственного";
     //$conWorkFlow->description = "Send Email to user when Notifyowner is True";
     // SalesPlatform.ru end
     $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)";
     // SalesPlatform.ru begin
     $task->subject = "Уведомление о назначении Контакта";
     $task->content = "В системе vtigerCRM Вам был назначен контакт<br>Информация о контакте :<br><br>" . "Контакт №:" . '<b>$contact_no</b><br>' . "Фамилия:" . '<b>$lastname</b><br>' . "Имя:" . '<b>$firstname</b><br>' . "Источник:" . '<b>$leadsource</b><br>' . "Отдел:" . '<b>$department</b><br>' . "Описание:" . '<b>$description</b><br><br><br>' . "Спасибо,<br>Admin";
     $task->summary = "Создан Контакт ";
     //$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 ";
     // SalesPlatform.ru end
     $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"}]';
     // SalesPlatform.ru begin
     $conpuWorkFlow->description = "Отправить Email пользователю, если контакт стал пользователем портала";
     //$conpuWorkFlow->description = "Send Email to user when Portal User is True";
     // SalesPlatform.ru end
     $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)";
     // SalesPlatform.ru begin
     $task->subject = "Уведомление о назначении Контакта";
     $task->content = "В системе vtigerCRM Вам был назначен контакт<br>Информация о контакте :<br><br>" . "Контакт №:" . '<b>$contact_no</b><br>' . "Фамилия:" . '<b>$lastname</b><br>' . "Имя:" . '<b>$firstname</b><br>' . "Источник:" . '<b>$leadsource</b><br>' . "Отдел:" . '<b>$department</b><br>' . "Описание:" . '<b>$description</b><br><br><br>' . "А также <b>детали логина на CustomerPortal</b> были отправлены " . "Email :-" . '$email<br>' . "<br>Спасибо,<br>Admin";
     $task->summary = "Создан Контакт ";
     //$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 ";
     // SalesPlatform.ru end
     $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");
     // SalesPlatform.ru begin
     $potentialWorkFlow->description = "Отправить Email пользователю при создании Сделки";
     //$potentialWorkFlow->description = "Send Email to users on Potential creation";
     // SalesPlatform.ru end
     $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)";
     // SalesPlatform.ru begin
     $task->subject = "Уведомление о назначении Сделки";
     $task->content = "В системе vtigerCRM Вам была назначена сделка<br>Информация о сделке :<br><br>" . "Сделка №:" . '<b>$potential_no</b><br>' . "Название Сделки:" . '<b>$potentialname</b><br>' . "Сумма (руб):" . '<b>$amount</b><br>' . "Ожидаемая Дата Закрытия:" . '<b>$closingdate</b><br>' . "Тип:" . '<b>$opportunity_type</b><br><br><br>' . "Описание:" . '$description<br>' . "<br>Спасибо,<br>Admin";
     $task->summary = "Создана сделка ";
     //$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 ";
     // SalesPlatform.ru end
     $tm->saveTask($task);
     $workflowManager = new VTWorkflowManager($adb);
     $taskManager = new VTTaskManager($adb);
     // Contact workflow on creation/modification
     $contactWorkFlow = $workflowManager->newWorkFlow("Contacts");
     $contactWorkFlow->test = '';
     //SalesPlatform.ru begin
     $contactWorkFlow->description = "Автоматические обработчики для создания и модификации контактов";
     //$contactWorkFlow->description = "Workflow for Contact Creation or Modification";
     //SalesPlatform.ru end
     $contactWorkFlow->executionCondition = VTWorkflowManager::$ON_EVERY_SAVE;
     $contactWorkFlow->defaultworkflow = 1;
     $workflowManager->save($contactWorkFlow);
     $task = $taskManager->createTask('VTEntityMethodTask', $contactWorkFlow->id);
     $task->active = true;
     //SalesPlatform.ru begin
     $task->summary = 'Сообщение с регистрационными данными клиентского портала';
     //$task->summary = 'Email Customer Portal Login Details';
     //SalesPlatform.ru end
     $task->methodName = "SendPortalLoginDetails";
     $taskManager->saveTask($task);
     $task->active = true;
     $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));
     // Trouble Tickets workflow on creation from Customer Portal
     $helpDeskWorkflow = $workflowManager->newWorkFlow("HelpDesk");
     $helpDeskWorkflow->test = '[{"fieldname":"from_portal","operation":"is","value":"true:boolean"}]';
     //SalesPlatform.ru begin
     $helpDeskWorkflow->description = "Автоматический обработчик для создаваемой заявки из портала";
     //$helpDeskWorkflow->description = "Workflow for Ticket Created from Portal";
     //SalesPlatform.ru end
     $helpDeskWorkflow->executionCondition = VTWorkflowManager::$ON_FIRST_SAVE;
     $helpDeskWorkflow->defaultworkflow = 1;
     $workflowManager->save($helpDeskWorkflow);
     $task = $taskManager->createTask('VTEntityMethodTask', $helpDeskWorkflow->id);
     $task->active = true;
     //SalesPlatform.ru begin
     $task->summary = 'Уведомляет ответственного за заявку и связанный контакт при создании заявки из портала';
     //$task->summary = 'Notify Record Owner and the Related Contact when Ticket is created from Portal';
     //SalesPlatform.ru end
     $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"}]';
     //SalesPlatform.ru begin
     $helpDeskWorkflow->description = "Автоматические обработчики для обновляемых заявок из портала";
     //$helpDeskWorkflow->description = "Workflow for Ticket Updated from Portal";
     //SalesPlatform.ru end
     $helpDeskWorkflow->executionCondition = VTWorkflowManager::$ON_MODIFY;
     $helpDeskWorkflow->defaultworkflow = 1;
     $workflowManager->save($helpDeskWorkflow);
     $task = $taskManager->createTask('VTEntityMethodTask', $helpDeskWorkflow->id);
     $task->active = true;
     //SalesPlatform.ru begin
     $task->summary = 'Уведомляет ответственного за заявку при добавлении комментариев к заявке через Клиентский портал';
     //$task->summary = 'Notify Record Owner when Comment is added to a Ticket from Customer Portal';
     //SalesPlatform.ru end
     $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"}]';
     //SalesPlatform.ru begin
     $helpDeskWorkflow->description = "Обработчик для изменяемых заявок, не из портала";
     //$helpDeskWorkflow->description = "Workflow for Ticket Change, not from the Portal";
     //SalesPlatform.ru end
     $helpDeskWorkflow->executionCondition = VTWorkflowManager::$ON_EVERY_SAVE;
     $helpDeskWorkflow->defaultworkflow = 1;
     $workflowManager->save($helpDeskWorkflow);
     $task = $taskManager->createTask('VTEntityMethodTask', $helpDeskWorkflow->id);
     $task->active = true;
     //SalesPlatform.ru begin
     $task->summary = 'Уведомляет ответственного за заявку, созданную не из портала, при ее изменении';
     //$task->summary = 'Notify Record Owner on Ticket Change, which is not done from Portal';
     //SalesPlatform.ru end
     $task->methodName = "NotifyOwnerOnTicketChange";
     $taskManager->saveTask($task);
     $task = $taskManager->createTask('VTEntityMethodTask', $helpDeskWorkflow->id);
     $task->active = true;
     //SalesPlatform.ru begin
     $task->summary = 'Уведомляет связанного клиента при изменении заявки, которая создана не из портала';
     //$task->summary = 'Notify Related Customer on Ticket Change, which is not done from Portal';
     //SalesPlatform.ru end
     $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"}]';
     //SalesPlatform.ru begin
     $eventsWorkflow->description = "Автоматические обработчики для событий при выбранной опции Отправить уведомление";
     //$eventsWorkflow->description = "Workflow for Events when Send Notification is True";
     //SalesPlatform.ru end
     $eventsWorkflow->executionCondition = VTWorkflowManager::$ON_EVERY_SAVE;
     $eventsWorkflow->defaultworkflow = 1;
     $workflowManager->save($eventsWorkflow);
     $task = $taskManager->createTask('VTEmailTask', $eventsWorkflow->id);
     $task->active = true;
     //SalesPlatform.ru begin
     $task->summary = 'Отправляет письмо с уведомлением приглашенным пользователям';
     //$task->summary = 'Send Notification Email to Record Owner';
     //SalesPlatform.ru end
     $task->recepient = "\$(assigned_user_id : (Users) email1)";
     //SalesPlatform.ru begin
     $task->subject = "Событие :  \$subject";
     $task->content = '$(assigned_user_id : (Users) first_name) $(assigned_user_id : (Users) last_name) ,<br/>' . '<b>Детали события:</b><br/>' . 'Название события       : $subject<br/>' . 'Дата и Время Начала    : $date_start  $time_start ( $(general : (__VtigerMeta__) dbtimezone) ) <br/>' . 'Дата и Время Окончания : $due_date  $time_end ( $(general : (__VtigerMeta__) dbtimezone) ) <br/>' . 'Статус                 : $eventstatus <br/>' . 'Приоритет              : $taskpriority <br/>' . 'Относится к            : $(parent_id : (Leads) lastname) $(parent_id : (Leads) firstname) $(parent_id : (Accounts) accountname) ' . '$(parent_id            : (Potentials) potentialname) $(parent_id : (HelpDesk) ticket_title) <br/>' . 'Контакты               : $(contact_id : (Contacts) lastname) $(contact_id : (Contacts) firstname) <br/>' . 'Место проведения       : $location <br/>' . 'Описание               : $description';
     //vtiger commented code
     /*
     		$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';
     */
     //SalesPlatform.ru end
     $taskManager->saveTask($task);
     // Calendar workflow when Send Notification is checked
     $calendarWorkflow = $workflowManager->newWorkFlow("Calendar");
     $calendarWorkflow->test = '[{"fieldname":"sendnotification","operation":"is","value":"true:boolean"}]';
     //SalesPlatform.ru begin
     $calendarWorkflow->description = "Автоматические обработчики для задач Календаря при выбранной опции Отправить уведомление";
     //$calendarWorkflow->description = "Workflow for Calendar Todos when Send Notification is True";
     //SalesPlatform.ru end
     $calendarWorkflow->executionCondition = VTWorkflowManager::$ON_EVERY_SAVE;
     $calendarWorkflow->defaultworkflow = 1;
     $workflowManager->save($calendarWorkflow);
     $task = $taskManager->createTask('VTEmailTask', $calendarWorkflow->id);
     $task->active = true;
     //SalesPlatform.ru begin
     $task->summary = 'Отправляет письмо с уведомлением ответственному за задачу';
     //$task->summary = 'Send Notification Email to Record Owner';
     //SalesPlatform.ru end
     $task->recepient = "\$(assigned_user_id : (Users) email1)";
     //SalesPlatform.ru begin
     $task->subject = "Задача :  \$subject";
     $task->content = '$(assigned_user_id : (Users) first_name) $(assigned_user_id : (Users) last_name) ,<br/>' . '<b>Детали задачи:</b><br/>' . 'Название задачи        : $subject<br/>' . 'Дата и Время Начала    : $date_start  $time_start ( $(general : (__VtigerMeta__) dbtimezone) ) <br/>' . 'Дата и Время Окончания : $due_date ( $(general : (__VtigerMeta__) dbtimezone) ) <br/>' . 'Статус                 : $taskstatus <br/>' . 'Приоритет              : $taskpriority <br/>' . 'Относится к            : $(parent_id : (Leads) lastname) $(parent_id : (Leads) firstname) $(parent_id : (Accounts) accountname) ' . '$(parent_id : (Potentials) potentialname) $(parent_id : (HelpDesk) ticket_title) <br/>' . 'Контакты               : $(contact_id : (Contacts) lastname) $(contact_id : (Contacts) firstname) <br/>' . 'Место проведения       : $location <br/>' . 'Описание               : $description';
     //vtiger commented code
     /*
     		$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';
     */
     //SalesPlatform.ru end
     $taskManager->saveTask($task);
 }