[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Settings/Workflows/actions/ -> Save.php (source)

   1  <?php
   2  /*+**********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.1
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   ************************************************************************************/
  10  
  11  class Settings_Workflows_Save_Action extends Settings_Vtiger_Basic_Action {
  12  
  13  	public function process(Vtiger_Request $request) {
  14          $recordId = $request->get('record');
  15          $summary = $request->get('summary');
  16          $moduleName = $request->get('module_name');
  17          $conditions = $request->get('conditions');
  18          $filterSavedInNew = $request->get('filtersavedinnew');
  19          $executionCondition = $request->get('execution_condition');
  20  
  21          if($recordId) {
  22              $workflowModel = Settings_Workflows_Record_Model::getInstance($recordId);
  23          } else {
  24              $workflowModel = Settings_Workflows_Record_Model::getCleanInstance($moduleName);
  25          }
  26  
  27          $response = new Vtiger_Response();
  28          $workflowModel->set('summary', $summary);
  29          $workflowModel->set('module_name', $moduleName);
  30          $workflowModel->set('conditions', $conditions);
  31          $workflowModel->set('execution_condition', $executionCondition);
  32          
  33          if($executionCondition == '6') {
  34              $schtime = $request->get("schtime");
  35              if(!preg_match('/^[0-2]\d(:[0-5]\d){1,2}$/', $schtime) or substr($schtime,0,2)>23) {  // invalid time format
  36                  $schtime='00:00';
  37              }
  38              $schtime .=':00';
  39  
  40              $workflowModel->set('schtime', $schtime);
  41  
  42              $workflowScheduleType = $request->get('schtypeid');
  43              $workflowModel->set('schtypeid', $workflowScheduleType);
  44  
  45              $dayOfMonth = null; $dayOfWeek = null; $month = null; $annualDates =null;
  46  
  47              if($workflowScheduleType == Workflow::$SCHEDULED_WEEKLY) {
  48                  $dayOfWeek = Zend_Json::encode($request->get('schdayofweek'));
  49              } else if($workflowScheduleType == Workflow::$SCHEDULED_MONTHLY_BY_DATE) {
  50                  $dayOfMonth = Zend_Json::encode($request->get('schdayofmonth'));
  51              } else if($workflowScheduleType == Workflow::$SCHEDULED_ON_SPECIFIC_DATE) {
  52                  $date = $request->get('schdate');
  53                  $dateDBFormat = DateTimeField::convertToDBFormat($date);
  54                  $nextTriggerTime = $dateDBFormat.' '.$schtime;
  55                  $currentTime = Vtiger_Util_Helper::getActiveAdminCurrentDateTime();
  56                  if($nextTriggerTime > $currentTime) {
  57                      $workflowModel->set('nexttrigger_time', $nextTriggerTime);
  58                  } else {
  59                      $workflowModel->set('nexttrigger_time', date('Y-m-d H:i:s', strtotime('+10 year')));
  60                  }
  61                  $annualDates = Zend_Json::encode(array($dateDBFormat));
  62              } else if($workflowScheduleType == Workflow::$SCHEDULED_ANNUALLY) {
  63                  $annualDates = Zend_Json::encode($request->get('schannualdates'));
  64              }
  65              $workflowModel->set('schdayofmonth', $dayOfMonth);
  66              $workflowModel->set('schdayofweek', $dayOfWeek);
  67              $workflowModel->set('schannualdates', $annualDates);
  68          }
  69          
  70          // Added to save the condition only when its changed from vtiger6
  71          if($filterSavedInNew == '6') {
  72              //Added to change advanced filter condition to workflow
  73              $workflowModel->transformAdvanceFilterToWorkFlowFilter();
  74          }
  75          $workflowModel->set('filtersavedinnew', $filterSavedInNew);
  76          $workflowModel->save();
  77  
  78          //Update only for scheduled workflows other than specific date
  79          if($workflowScheduleType != Workflow::$SCHEDULED_ON_SPECIFIC_DATE && $executionCondition == '6') {
  80              $workflowModel->updateNextTriggerTime();
  81          }
  82          
  83          $response->setResult(array('id' => $workflowModel->get('workflow_id')));
  84          $response->emit();
  85      }
  86          
  87          public function validateRequest(Vtiger_Request $request) { 
  88              $request->validateWriteAccess(); 
  89          }
  90  } 


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1