[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Leads/views/ -> SaveConvertLead.php (source)

   1  <?php
   2  /*+***********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   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  vimport('~~/include/Webservices/ConvertLead.php');
  11  
  12  class Leads_SaveConvertLead_View extends Vtiger_View_Controller {
  13  
  14  	function checkPermission(Vtiger_Request $request) {
  15          $moduleName = $request->getModule();
  16          $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
  17  
  18          $currentUserPrivilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
  19          if(!$currentUserPrivilegesModel->hasModuleActionPermission($moduleModel->getId(), 'ConvertLead')) {
  20              throw new AppException(vtranslate('LBL_CONVERT_LEAD_PERMISSION_DENIED', $moduleName));
  21          }
  22      }
  23  
  24  	public function preProcess(Vtiger_Request $request) {
  25      }
  26  
  27  	public function process(Vtiger_Request $request) {
  28          $recordId = $request->get('record');
  29          $modules = $request->get('modules');
  30          $assignId = $request->get('assigned_user_id');
  31          $currentUser = Users_Record_Model::getCurrentUserModel();
  32  
  33          $entityValues = array();
  34  
  35          $entityValues['transferRelatedRecordsTo'] = $request->get('transferModule');
  36          $entityValues['assignedTo'] = vtws_getWebserviceEntityId(vtws_getOwnerType($assignId), $assignId);
  37          $entityValues['leadId'] =  vtws_getWebserviceEntityId($request->getModule(), $recordId);
  38  
  39          $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $request->getModule());
  40          $convertLeadFields = $recordModel->getConvertLeadFields();
  41  
  42          $availableModules = array('Accounts', 'Contacts', 'Potentials');
  43          foreach ($availableModules as $module) {
  44              if(vtlib_isModuleActive($module)&& in_array($module, $modules)) {
  45                  $entityValues['entities'][$module]['create'] = true;
  46                  $entityValues['entities'][$module]['name'] = $module;
  47  
  48                  foreach ($convertLeadFields[$module] as $fieldModel) {
  49                      $fieldName = $fieldModel->getName();
  50                      $fieldValue = $request->get($fieldName);
  51  
  52                      //Potential Amount Field value converting into DB format
  53                      if ($fieldModel->getFieldDataType() === 'currency') {
  54                          $fieldValue = Vtiger_Currency_UIType::convertToDBFormat($fieldValue);
  55                      } elseif ($fieldModel->getFieldDataType() === 'date') {
  56                          $fieldValue = DateTimeField::convertToDBFormat($fieldValue);
  57                      } elseif ($fieldModel->getFieldDataType() === 'reference' && $fieldValue) {
  58                          $ids = vtws_getIdComponents($fieldValue);
  59                          if (count($ids) === 1) {
  60                              $fieldValue = vtws_getWebserviceEntityId(getSalesEntityType($fieldValue), $fieldValue);
  61                          }
  62                      }
  63                      $entityValues['entities'][$module][$fieldName] = $fieldValue;
  64                  }
  65              }
  66          }
  67          try {
  68              $result = vtws_convertlead($entityValues, $currentUser);
  69          } catch(Exception $e) {
  70              $this->showError($request, $e);
  71              exit;
  72          }
  73  
  74          if(!empty($result['Accounts'])) {
  75              $accountIdComponents = vtws_getIdComponents($result['Accounts']);
  76              $accountId = $accountIdComponents[1];
  77          }
  78          if(!empty($result['Contacts'])) {
  79              $contactIdComponents = vtws_getIdComponents($result['Contacts']);
  80              $contactId = $contactIdComponents[1];
  81          }
  82  
  83          if(!empty($accountId)) {
  84              header("Location: index.php?view=Detail&module=Accounts&record=$accountId");
  85          } elseif (!empty($contactId)) {
  86              header("Location: index.php?view=Detail&module=Contacts&record=$contactId");
  87          } else {
  88              $this->showError($request);
  89              exit;
  90          }
  91      }
  92  
  93  	function showError($request, $exception=false) {
  94          $viewer = $this->getViewer($request);
  95          if($exception != false) {
  96              $viewer->assign('EXCEPTION', $exception->getMessage());
  97          }
  98  
  99          $moduleName = $request->getModule();
 100          $currentUser = Users_Record_Model::getCurrentUserModel();
 101  
 102          $viewer->assign('CURRENT_USER', $currentUser);
 103          $viewer->assign('MODULE', $moduleName);
 104          $viewer->view('ConvertLeadError.tpl', $moduleName);
 105      }
 106          
 107          public function validateRequest(Vtiger_Request $request) { 
 108              $request->validateWriteAccess(); 
 109          }
 110  }


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