[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Vtiger/views/ -> Edit.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  
  11  Class Vtiger_Edit_View extends Vtiger_Index_View {
  12      protected $record = false;
  13  	function __construct() {
  14          parent::__construct();
  15      }
  16      
  17  	public function checkPermission(Vtiger_Request $request) {
  18          $moduleName = $request->getModule();
  19          $record = $request->get('record');
  20  
  21          $recordPermission = Users_Privileges_Model::isPermitted($moduleName, 'EditView', $record);
  22  
  23          if(!$recordPermission) {
  24              throw new AppException(vtranslate('LBL_PERMISSION_DENIED'));
  25          }
  26      }
  27  
  28  	public function process(Vtiger_Request $request) {
  29          $viewer = $this->getViewer ($request);
  30          $moduleName = $request->getModule();
  31          $record = $request->get('record');
  32          if(!empty($record) && $request->get('isDuplicate') == true) {
  33              $recordModel = $this->record?$this->record:Vtiger_Record_Model::getInstanceById($record, $moduleName);
  34              $viewer->assign('MODE', '');
  35  
  36              //While Duplicating record, If the related record is deleted then we are removing related record info in record model
  37              $mandatoryFieldModels = $recordModel->getModule()->getMandatoryFieldModels();
  38              foreach ($mandatoryFieldModels as $fieldModel) {
  39                  if ($fieldModel->isReferenceField()) {
  40                      $fieldName = $fieldModel->get('name');
  41                      if (Vtiger_Util_Helper::checkRecordExistance($recordModel->get($fieldName))) {
  42                          $recordModel->set($fieldName, '');
  43                      }
  44                  }
  45              }  
  46          }else if(!empty($record)) {
  47              $recordModel = $this->record?$this->record:Vtiger_Record_Model::getInstanceById($record, $moduleName);
  48              $viewer->assign('RECORD_ID', $record);
  49              $viewer->assign('MODE', 'edit');
  50          } else {
  51              $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
  52              $viewer->assign('MODE', '');
  53          }
  54          if(!$this->record){
  55              $this->record = $recordModel;
  56          }
  57          
  58          $moduleModel = $recordModel->getModule();
  59          $fieldList = $moduleModel->getFields();
  60          $requestFieldList = array_intersect_key($request->getAll(), $fieldList);
  61  
  62          foreach($requestFieldList as $fieldName=>$fieldValue){
  63              $fieldModel = $fieldList[$fieldName];
  64              $specialField = false;
  65              // We collate date and time part together in the EditView UI handling 
  66              // so a bit of special treatment is required if we come from QuickCreate 
  67              if ($moduleName == 'Calendar' && empty($record) && $fieldName == 'time_start' && !empty($fieldValue)) { 
  68                  $specialField = true; 
  69                  // Convert the incoming user-picked time to GMT time 
  70                  // which will get re-translated based on user-time zone on EditForm 
  71                  $fieldValue = DateTimeField::convertToDBTimeZone($fieldValue)->format("H:i"); 
  72                  
  73              }
  74              
  75              if ($moduleName == 'Calendar' && empty($record) && $fieldName == 'date_start' && !empty($fieldValue)) { 
  76                  $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($requestFieldList['time_start']);
  77                  $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($fieldValue." ".$startTime);
  78                  list($startDate, $startTime) = explode(' ', $startDateTime);
  79                  $fieldValue = Vtiger_Date_UIType::getDisplayDateValue($startDate);
  80              }
  81              if($fieldModel->isEditable() || $specialField) {
  82                  $recordModel->set($fieldName, $fieldModel->getDBInsertValue($fieldValue));
  83              }
  84          }
  85          $recordStructureInstance = Vtiger_RecordStructure_Model::getInstanceFromRecordModel($recordModel, Vtiger_RecordStructure_Model::RECORD_STRUCTURE_MODE_EDIT);
  86          $picklistDependencyDatasource = Vtiger_DependencyPicklist::getPicklistDependencyDatasource($moduleName);
  87  
  88          $viewer->assign('PICKIST_DEPENDENCY_DATASOURCE',Zend_Json::encode($picklistDependencyDatasource));
  89          $viewer->assign('RECORD_STRUCTURE_MODEL', $recordStructureInstance);
  90          $viewer->assign('RECORD_STRUCTURE', $recordStructureInstance->getStructure());
  91          $viewer->assign('MODULE', $moduleName);
  92          $viewer->assign('CURRENTDATE', date('Y-n-j'));
  93          $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel());
  94  
  95          $isRelationOperation = $request->get('relationOperation');
  96  
  97          //if it is relation edit
  98          $viewer->assign('IS_RELATION_OPERATION', $isRelationOperation);
  99          if($isRelationOperation) {
 100              $viewer->assign('SOURCE_MODULE', $request->get('sourceModule'));
 101              $viewer->assign('SOURCE_RECORD', $request->get('sourceRecord'));
 102          }
 103          
 104          $viewer->assign('MAX_UPLOAD_LIMIT_MB', Vtiger_Util_Helper::getMaxUploadSize());
 105          $viewer->assign('MAX_UPLOAD_LIMIT', vglobal('upload_maxsize'));
 106          $viewer->view('EditView.tpl', $moduleName);
 107      }
 108  }


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