コード例 #1
0
 public function transformForImport($fieldData, $moduleMeta, $fillDefault = true, $mergeMode = false)
 {
     $moduleFields = $moduleMeta->getModuleFields();
     $defaultFieldValues = $this->getDefaultFieldValues($moduleMeta);
     foreach ($fieldData as $fieldName => $fieldValue) {
         $fieldInstance = $moduleFields[$fieldName];
         if (!is_object($fieldInstance)) {
             continue;
         }
         // specially for Inventory module import which has virtual item line fields
         if ($fieldInstance->getFieldDataType() == 'owner') {
             global $adb;
             if (strpos($fieldValue, '::::') > 0) {
                 $fieldValueDetails = explode('::::', $fieldValue);
             } else {
                 $fieldValueDetails = explode(':::', $fieldValue);
             }
             if (count($fieldValueDetails) == 2) {
                 $fieldValue = $fieldValueDetails[1];
             }
             if (count($fieldValueDetails) == 3) {
                 $user_qry = 'select vtiger_users.id from vtiger_users where ' . $fieldValueDetails[2] . ' = ?';
                 $res = $adb->pquery($user_qry, array($fieldValueDetails[1]));
                 $ownerId = 0;
                 if ($res and $adb->num_rows($res) > 0) {
                     $ownerId = $adb->query_result($res, 0, 'id');
                 }
             } else {
                 $ownerId = getUserId_Ol($fieldValue);
                 if (empty($ownerId)) {
                     $ownerId = getGrpId($fieldValue);
                 }
             }
             if (empty($ownerId) && isset($defaultFieldValues[$fieldName])) {
                 $ownerId = $defaultFieldValues[$fieldName];
             }
             if (empty($ownerId) || !Import_Utils::hasAssignPrivilege($moduleMeta->getEntityName(), $ownerId)) {
                 $ownerId = $this->user->id;
             }
             $fieldData[$fieldName] = $ownerId;
         } elseif ($fieldInstance->getFieldDataType() == 'reference') {
             $entityId = false;
             if (!empty($fieldValue)) {
                 if (strpos($fieldValue, '::::') > 0) {
                     $fieldValueDetails = explode('::::', $fieldValue);
                 } else {
                     $fieldValueDetails = explode(':::', $fieldValue);
                 }
                 if (count($fieldValueDetails) > 1) {
                     $referenceModuleName = trim($fieldValueDetails[0]);
                     $entityLabel = trim($fieldValueDetails[1]);
                     if (!empty($fieldValueDetails[2])) {
                         $entityId = getEntityId($referenceModuleName, $entityLabel, $fieldValueDetails[2]);
                     } else {
                         $entityId = getEntityId($referenceModuleName, $entityLabel);
                     }
                 } else {
                     $referencedModules = $fieldInstance->getReferenceList();
                     $entityLabel = $fieldValue;
                     foreach ($referencedModules as $referenceModule) {
                         $referenceModuleName = $referenceModule;
                         if ($referenceModule == 'Users') {
                             $referenceEntityId = getUserId_Ol($entityLabel);
                             if (empty($referenceEntityId) || !Import_Utils::hasAssignPrivilege($moduleMeta->getEntityName(), $referenceEntityId)) {
                                 $referenceEntityId = $this->user->id;
                             }
                         } else {
                             $referenceEntityId = getEntityId($referenceModule, $entityLabel);
                         }
                         if ($referenceEntityId != 0) {
                             $entityId = $referenceEntityId;
                             break;
                         }
                     }
                 }
                 if ((empty($entityId) || $entityId == 0) && (!empty($referenceModuleName) and !in_array($referenceModuleName, getInventoryModules()))) {
                     if (isPermitted($referenceModuleName, 'EditView') == 'yes') {
                         $wsEntityIdInfo = $this->createEntityRecord($referenceModuleName, $entityLabel);
                         $wsEntityId = $wsEntityIdInfo['id'];
                         $entityIdComponents = vtws_getIdComponents($wsEntityId);
                         $entityId = $entityIdComponents[1];
                     }
                 }
                 $fieldData[$fieldName] = $entityId;
             } else {
                 $referencedModules = $fieldInstance->getReferenceList();
                 if ($referencedModules[0] == 'Users') {
                     if (isset($defaultFieldValues[$fieldName])) {
                         $fieldData[$fieldName] = $defaultFieldValues[$fieldName];
                     }
                     if (empty($fieldData[$fieldName]) || !Import_Utils::hasAssignPrivilege($moduleMeta->getEntityName(), $fieldData[$fieldName])) {
                         $fieldData[$fieldName] = $this->user->id;
                     }
                 } else {
                     $fieldData[$fieldName] = '';
                 }
             }
         } elseif ($fieldInstance->getFieldDataType() == 'picklist') {
             global $default_charset;
             if (empty($fieldValue) && isset($defaultFieldValues[$fieldName])) {
                 $fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName];
             }
             $allPicklistDetails = $fieldInstance->getPicklistDetails();
             $allPicklistValues = array();
             foreach ($allPicklistDetails as $picklistDetails) {
                 $allPicklistValues[] = $picklistDetails['value'];
             }
             $encodePicklistValue = $fieldValue;
             if (!in_array($encodePicklistValue, $allPicklistValues)) {
                 $moduleObject = Vtiger_Module::getInstance($moduleMeta->getEntityName());
                 $fieldObject = Vtiger_Field::getInstance($fieldName, $moduleObject);
                 $fieldObject->setPicklistValues(array($fieldValue));
             }
         } else {
             if ($fieldInstance->getFieldDataType() == 'datetime' && !empty($fieldValue)) {
                 if ($fieldValue == null || $fieldValue == '0000-00-00 00:00:00') {
                     $fieldValue = '';
                 }
                 $valuesList = explode(' ', $fieldValue);
                 if (count($valuesList) == 1) {
                     $fieldValue = '';
                 }
                 $fieldValue = getValidDBInsertDateTimeValue($fieldValue);
                 if (preg_match("/^[0-9]{2,4}[-][0-1]{1,2}?[0-9]{1,2}[-][0-3]{1,2}?[0-9]{1,2} ([0-1][0-9]|[2][0-3])([:][0-5][0-9]){1,2}\$/", $fieldValue) == 0) {
                     $fieldValue = '';
                 }
                 $fieldData[$fieldName] = $fieldValue;
             }
             if ($fieldInstance->getFieldDataType() == 'date' && !empty($fieldValue)) {
                 if ($fieldValue == null || $fieldValue == '0000-00-00') {
                     $fieldValue = '';
                 }
                 $fieldValue = getValidDBInsertDateValue($fieldValue);
                 if (preg_match("/^[0-9]{2,4}[-][0-1]{1,2}?[0-9]{1,2}[-][0-3]{1,2}?[0-9]{1,2}\$/", $fieldValue) == 0) {
                     $fieldValue = '';
                 }
                 $fieldData[$fieldName] = $fieldValue;
             }
             if (empty($fieldValue) && isset($defaultFieldValues[$fieldName]) && !$mergeMode) {
                 $fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName];
             }
         }
     }
     if ($fillDefault) {
         foreach ($defaultFieldValues as $fieldName => $fieldValue) {
             if (!isset($fieldData[$fieldName])) {
                 $fieldData[$fieldName] = $defaultFieldValues[$fieldName];
             }
         }
     }
     if (!$mergeMode) {
         //Do not check mandatory fields on merge !
         foreach ($moduleFields as $fieldName => $fieldInstance) {
             if (empty($fieldData[$fieldName]) && $fieldInstance->isMandatory()) {
                 return null;
             }
         }
     }
     return DataTransform::sanitizeData($fieldData, $moduleMeta);
 }
コード例 #2
0
ファイル: Data.php プロジェクト: cannking/vtigercrm-debug
 public function transformForImport($fieldData, $moduleMeta, $fillDefault = true, $checkMandatoryFieldValues = true)
 {
     $moduleFields = $moduleMeta->getModuleFields();
     $defaultFieldValues = $this->getDefaultFieldValues($moduleMeta);
     foreach ($fieldData as $fieldName => $fieldValue) {
         $fieldInstance = $moduleFields[$fieldName];
         if ($fieldInstance->getFieldDataType() == 'owner') {
             $ownerId = getUserId_Ol(trim($fieldValue));
             if (empty($ownerId)) {
                 $ownerId = getGrpId($fieldValue);
             }
             if (empty($ownerId) && isset($defaultFieldValues[$fieldName])) {
                 $ownerId = $defaultFieldValues[$fieldName];
             }
             if (empty($ownerId) || !Import_Utils_Helper::hasAssignPrivilege($moduleMeta->getEntityName(), $ownerId)) {
                 $ownerId = $this->user->id;
             }
             $fieldData[$fieldName] = $ownerId;
         } elseif ($fieldInstance->getFieldDataType() == 'multipicklist') {
             $trimmedValue = trim($fieldValue);
             if (!$trimmedValue && isset($defaultFieldValues[$fieldName])) {
                 $explodedValue = explode(',', $defaultFieldValues[$fieldName]);
             } else {
                 $explodedValue = explode(' |##| ', $trimmedValue);
             }
             foreach ($explodedValue as $key => $value) {
                 $explodedValue[$key] = trim($value);
             }
             $implodeValue = implode(' |##| ', $explodedValue);
             $fieldData[$fieldName] = $implodeValue;
         } elseif ($fieldInstance->getFieldDataType() == 'reference') {
             $entityId = false;
             if (!empty($fieldValue)) {
                 if (strpos($fieldValue, '::::') > 0) {
                     $fieldValueDetails = explode('::::', $fieldValue);
                 } else {
                     if (strpos($fieldValue, ':::') > 0) {
                         $fieldValueDetails = explode(':::', $fieldValue);
                     } else {
                         $fieldValueDetails = $fieldValue;
                     }
                 }
                 if (count($fieldValueDetails) > 1) {
                     $referenceModuleName = trim($fieldValueDetails[0]);
                     $entityLabel = trim($fieldValueDetails[1]);
                     $entityId = getEntityId($referenceModuleName, $entityLabel);
                 } else {
                     $referencedModules = $fieldInstance->getReferenceList();
                     $entityLabel = $fieldValue;
                     foreach ($referencedModules as $referenceModule) {
                         $referenceModuleName = $referenceModule;
                         if ($referenceModule == 'Users') {
                             $referenceEntityId = getUserId_Ol($entityLabel);
                             if (empty($referenceEntityId) || !Import_Utils_Helper::hasAssignPrivilege($moduleMeta->getEntityName(), $referenceEntityId)) {
                                 $referenceEntityId = $this->user->id;
                             }
                         } elseif ($referenceModule == 'Currency') {
                             $referenceEntityId = getCurrencyId($entityLabel);
                         } else {
                             $referenceEntityId = getEntityId($referenceModule, $entityLabel);
                         }
                         if ($referenceEntityId != 0) {
                             $entityId = $referenceEntityId;
                             break;
                         }
                     }
                 }
                 if ((empty($entityId) || $entityId == 0) && !empty($referenceModuleName)) {
                     if (isPermitted($referenceModuleName, 'EditView') == 'yes') {
                         try {
                             $wsEntityIdInfo = $this->createEntityRecord($referenceModuleName, $entityLabel);
                             $wsEntityId = $wsEntityIdInfo['id'];
                             $entityIdComponents = vtws_getIdComponents($wsEntityId);
                             $entityId = $entityIdComponents[1];
                         } catch (Exception $e) {
                             $entityId = false;
                         }
                     }
                 }
                 $fieldData[$fieldName] = $entityId;
             } else {
                 $referencedModules = $fieldInstance->getReferenceList();
                 if ($referencedModules[0] == 'Users') {
                     if (isset($defaultFieldValues[$fieldName])) {
                         $fieldData[$fieldName] = $defaultFieldValues[$fieldName];
                     }
                     if (empty($fieldData[$fieldName]) || !Import_Utils_Helper::hasAssignPrivilege($moduleMeta->getEntityName(), $fieldData[$fieldName])) {
                         $fieldData[$fieldName] = $this->user->id;
                     }
                 } else {
                     $fieldData[$fieldName] = '';
                 }
             }
         } elseif ($fieldInstance->getFieldDataType() == 'picklist') {
             $fieldValue = trim($fieldValue);
             global $default_charset;
             if (empty($fieldValue) && isset($defaultFieldValues[$fieldName])) {
                 $fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName];
             }
             $olderCacheEnable = Vtiger_Cache::$cacheEnable;
             Vtiger_Cache::$cacheEnable = false;
             if (!isset($this->allPicklistValues[$fieldName])) {
                 $this->allPicklistValues[$fieldName] = $fieldInstance->getPicklistDetails();
             }
             $allPicklistDetails = $this->allPicklistValues[$fieldName];
             $allPicklistValues = array();
             foreach ($allPicklistDetails as $picklistDetails) {
                 $allPicklistValues[] = $picklistDetails['value'];
             }
             $picklistValueInLowerCase = strtolower(htmlentities($fieldValue, ENT_QUOTES, $default_charset));
             $allPicklistValuesInLowerCase = array_map('strtolower', $allPicklistValues);
             $picklistDetails = array_combine($allPicklistValuesInLowerCase, $allPicklistValues);
             if (!in_array($picklistValueInLowerCase, $allPicklistValuesInLowerCase)) {
                 $moduleObject = Vtiger_Module::getInstance($moduleMeta->getEntityName());
                 $fieldObject = Vtiger_Field::getInstance($fieldName, $moduleObject);
                 $fieldObject->setPicklistValues(array($fieldValue));
                 unset($this->allPicklistValues[$fieldName]);
             } else {
                 $fieldData[$fieldName] = $picklistDetails[$picklistValueInLowerCase];
             }
             Vtiger_Cache::$cacheEnable = $olderCacheEnable;
         } else {
             if ($fieldInstance->getFieldDataType() == 'currency') {
                 // While exporting we are exporting as user format, we should import as db format while importing
                 $fieldData[$fieldName] = CurrencyField::convertToDBFormat($fieldValue, $current_user, false);
             } else {
                 if ($fieldInstance->getFieldDataType() == 'datetime' && !empty($fieldValue)) {
                     if ($fieldValue == null || $fieldValue == '0000-00-00 00:00:00') {
                         $fieldValue = '';
                     }
                     $valuesList = explode(' ', $fieldValue);
                     if (count($valuesList) == 1) {
                         $fieldValue = '';
                     }
                     $fieldValue = getValidDBInsertDateTimeValue($fieldValue);
                     if (preg_match("/^[0-9]{2,4}[-][0-1]{1,2}?[0-9]{1,2}[-][0-3]{1,2}?[0-9]{1,2} ([0-1][0-9]|[2][0-3])([:][0-5][0-9]){1,2}\$/", $fieldValue) == 0) {
                         $fieldValue = '';
                     }
                     $fieldData[$fieldName] = $fieldValue;
                 }
                 if ($fieldInstance->getFieldDataType() == 'date' && !empty($fieldValue)) {
                     if ($fieldValue == null || $fieldValue == '0000-00-00') {
                         $fieldValue = '';
                     }
                     $fieldValue = getValidDBInsertDateValue($fieldValue);
                     if (preg_match("/^[0-9]{2,4}[-][0-1]{1,2}?[0-9]{1,2}[-][0-3]{1,2}?[0-9]{1,2}\$/", $fieldValue) == 0) {
                         $fieldValue = '';
                     }
                     $fieldData[$fieldName] = $fieldValue;
                 }
                 if (empty($fieldValue) && isset($defaultFieldValues[$fieldName])) {
                     $fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName];
                 }
             }
         }
     }
     if ($fillDefault) {
         foreach ($defaultFieldValues as $fieldName => $fieldValue) {
             if (!isset($fieldData[$fieldName])) {
                 $fieldData[$fieldName] = $defaultFieldValues[$fieldName];
             }
         }
     }
     // We should sanitizeData before doing final mandatory check below.
     $fieldData = DataTransform::sanitizeData($fieldData, $moduleMeta);
     if ($fieldData != null && $checkMandatoryFieldValues) {
         foreach ($moduleFields as $fieldName => $fieldInstance) {
             if (empty($fieldData[$fieldName]) && $fieldInstance->isMandatory()) {
                 return null;
             }
         }
     }
     return $fieldData;
 }
コード例 #3
0
function isRecordExistInDB($fieldData, $moduleMeta, $user)
{
    $adb = PearDatabase::getInstance();
    $log = vglobal('log');
    $moduleFields = $moduleMeta->getModuleFields();
    $isRecordExist = false;
    if (array_key_exists('productid', $fieldData)) {
        $fieldName = 'productid';
        $fieldValue = $fieldData[$fieldName];
        $fieldInstance = $moduleFields[$fieldName];
        if ($fieldInstance->getFieldDataType() == 'reference') {
            $entityId = false;
            if (!empty($fieldValue)) {
                if (strpos($fieldValue, '::::') > 0) {
                    $fieldValueDetails = explode('::::', $fieldValue);
                } else {
                    if (strpos($fieldValue, ':::') > 0) {
                        $fieldValueDetails = explode(':::', $fieldValue);
                    } else {
                        $fieldValueDetails = $fieldValue;
                    }
                }
                if (count($fieldValueDetails) > 1) {
                    $referenceModuleName = trim($fieldValueDetails[0]);
                    $entityLabel = trim($fieldValueDetails[1]);
                    $entityId = getEntityId($referenceModuleName, $entityLabel);
                } else {
                    $referencedModules = $fieldInstance->getReferenceList();
                    $entityLabel = $fieldValue;
                    foreach ($referencedModules as $referenceModule) {
                        $referenceModuleName = $referenceModule;
                        $referenceEntityId = getEntityId($referenceModule, $entityLabel);
                        if ($referenceEntityId != 0) {
                            $entityId = $referenceEntityId;
                            break;
                        }
                    }
                }
                if (!empty($entityId) && $entityId != 0) {
                    $types = vtws_listtypes(null, $user);
                    $accessibleModules = $types['types'];
                    if (in_array($referenceModuleName, $accessibleModules)) {
                        $isRecordExist = true;
                    }
                }
            }
        }
    }
    return $isRecordExist;
}
コード例 #4
0
ファイル: InventoryUtils.php プロジェクト: jgjermeni/corebos
function createRecords($obj)
{
    global $adb, $VTIGER_BULK_SAVE_MODE;
    $moduleName = $obj->module;
    $moduleHandler = vtws_getModuleHandlerFromName($moduleName, $obj->user);
    $moduleMeta = $moduleHandler->getMeta();
    $moduleObjectId = $moduleMeta->getEntityId();
    $moduleFields = $moduleMeta->getModuleFields();
    include_once 'include/fields/InventoryLineField.php';
    $ilfields = new InventoryLineField();
    $moduleFields = array_merge($moduleFields, $ilfields->getInventoryLineFieldsByObject());
    $focus = CRMEntity::getInstance($moduleName);
    $wsrs = $adb->pquery('select id from vtiger_ws_entity where name=?', array('Products'));
    if ($wsrs and $adb->num_rows($wsrs) == 1) {
        $pdowsid = $adb->query_result($wsrs, 0, 0) . 'x';
    } else {
        $pdowsid = '0x';
    }
    $wsrs = $adb->pquery('select id from vtiger_ws_entity where name=?', array('Services'));
    if ($wsrs and $adb->num_rows($wsrs) == 1) {
        $srvwsid = $adb->query_result($wsrs, 0, 0) . 'x';
    } else {
        $srvwsid = '0x';
    }
    $wsrs = $adb->pquery('select id from vtiger_ws_entity where name=?', array('Users'));
    if ($wsrs and $adb->num_rows($wsrs) == 1) {
        $usrwsid = $adb->query_result($wsrs, 0, 0) . 'x';
    } else {
        $usrwsid = '0x';
    }
    $tableName = Import_Utils::getDbTableName($obj->user);
    $sql = 'SELECT * FROM ' . $tableName . ' WHERE status = ' . Import_Data_Controller::$IMPORT_RECORD_NONE . ' GROUP BY subject';
    if ($obj->batchImport) {
        $importBatchLimit = GlobalVariable::getVariable('Import_Batch_Limit', 100);
        $sql .= ' LIMIT ' . $importBatchLimit;
    }
    $result = $adb->query($sql);
    $numberOfRecords = $adb->num_rows($result);
    if ($numberOfRecords <= 0) {
        return;
    }
    $fieldMapping = $obj->fieldMapping;
    $fieldColumnMapping = $moduleMeta->getFieldColumnMapping();
    for ($i = 0; $i < $numberOfRecords; ++$i) {
        $row = $adb->raw_query_result_rowdata($result, $i);
        $rowId = $row['id'];
        $entityInfo = null;
        $fieldData = array();
        $lineItems = array();
        $subject = $row['subject'];
        $sql = 'SELECT * FROM ' . $tableName . ' WHERE status = ' . Import_Data_Controller::$IMPORT_RECORD_NONE . ' AND subject = "' . str_replace("\"", "\\\"", $subject) . '"';
        $subjectResult = $adb->query($sql);
        $count = $adb->num_rows($subjectResult);
        $subjectRowIDs = array();
        for ($j = 0; $j < $count; ++$j) {
            $subjectRow = $adb->raw_query_result_rowdata($subjectResult, $j);
            if ($subjectRow['productid'] == '' || $subjectRow['quantity'] == '' || $subjectRow['listprice'] == '') {
                continue;
            }
            array_push($subjectRowIDs, $subjectRow['id']);
            $lineItemData = array();
            $lineItemData['discount'] = 0;
            foreach ($fieldMapping as $fieldName => $index) {
                if ($moduleFields[$fieldName]->getTableName() == 'vtiger_inventoryproductrel') {
                    if ($fieldName == 'productid') {
                        $fieldValue = $subjectRow[$fieldName];
                        if (strpos($fieldValue, '::::') > 0) {
                            $fieldValueDetails = explode('::::', $fieldValue);
                        } else {
                            if (strpos($fieldValue, ':::') > 0) {
                                $fieldValueDetails = explode(':::', $fieldValue);
                            } else {
                                $fieldValueDetails = $fieldValue;
                            }
                        }
                        if (count($fieldValueDetails) > 1) {
                            $referenceModuleName = trim($fieldValueDetails[0]);
                            $entityLabel = trim($fieldValueDetails[1]);
                            $entityId = getEntityId($referenceModuleName, $entityLabel);
                        } else {
                            $referencedModules = array('Products', 'Services');
                            $entityLabel = $fieldValue;
                            foreach ($referencedModules as $referenceModule) {
                                $referenceModuleName = $referenceModule;
                                $referenceEntityId = getEntityId($referenceModule, $entityLabel);
                                if ($referenceEntityId != 0) {
                                    $entityId = $referenceEntityId;
                                    break;
                                }
                            }
                        }
                        if (empty($entityId) and in_array($referenceModuleName, array('Products', 'Services'))) {
                            $pdinfo = array();
                            if ($referenceModuleName == 'Services') {
                                $pdoinfo['servicename'] = $entityLabel;
                            } else {
                                $pdoinfo['productname'] = $entityLabel;
                            }
                            $pdoinfo['assigned_user_id'] = $usrwsid . $obj->user->id;
                            try {
                                $VTIGER_BULK_SAVE_MODE = false;
                                $psInfo = vtws_create($referenceModuleName, $pdoinfo, $obj->user);
                                $VTIGER_BULK_SAVE_MODE = true;
                                $entityId = $psInfo['id'];
                            } catch (Exception $e) {
                                continue 2;
                                // ignore this line
                            }
                        } else {
                            if ($referenceModuleName == 'Services') {
                                $entityId = $srvwsid . $entityId;
                            } else {
                                $entityId = $pdowsid . $entityId;
                            }
                        }
                        $lineItemData[$fieldName] = $entityId;
                    } else {
                        $lineItemData[$fieldName] = $subjectRow[$fieldName];
                        if ($fieldName == 'discount_amount' and $subjectRow[$fieldName] > 0) {
                            $lineItemData['discount'] = 1;
                            $lineItemData['discount_type'] = 'amount';
                        }
                        if ($fieldName == 'discount_percent' and $subjectRow[$fieldName] > 0) {
                            $lineItemData['discount'] = 1;
                            $lineItemData['discount_percentage'] = $subjectRow[$fieldName];
                            $lineItemData['discount_type'] = 'percentage';
                        }
                        if ($fieldName == 'quantity') {
                            $lineItemData['qty'] = $subjectRow[$fieldName];
                        }
                    }
                }
            }
            array_push($lineItems, $lineItemData);
        }
        foreach ($fieldMapping as $fieldName => $index) {
            $fieldData[$fieldName] = $row[strtolower($fieldName)];
            if ($fieldName == 'hdnTaxType') {
                $fieldData['taxtype'] = $row[strtolower($fieldName)];
            }
            if ($fieldName == 'txtAdjustment' and $fieldData[$fieldName] != 0) {
                $fieldData['adjustmentType'] = 'add';
                $fieldData['adjustment'] = $fieldData[$fieldName];
            }
        }
        if (!array_key_exists('assigned_user_id', $fieldData)) {
            $fieldData['assigned_user_id'] = $obj->user->id;
        }
        if (!empty($lineItems)) {
            if (method_exists($focus, 'importRecord')) {
                $entityInfo = $focus->importRecord($obj, $fieldData, $lineItems);
            }
        }
        if ($entityInfo == null) {
            $entityInfo = array('id' => null, 'status' => $obj->getImportRecordStatus('failed'));
        }
        foreach ($subjectRowIDs as $id) {
            $obj->importedRecordInfo[$id] = $entityInfo;
            $obj->updateImportStatus($id, $entityInfo);
        }
    }
    unset($result);
    return true;
}
コード例 #5
0
function get_where_clause($module, $column_fields)
{
    global $current_user, $dup_ow_count, $adb;
    $where_clause = "";
    $field_values_array = getFieldValues($module);
    $field_values = $field_values_array['fieldnames_list'];
    $tblname_field_arr = explode(",", $field_values);
    $uitype_arr = $field_values_array['fieldname_uitype'];
    $focus = CRMEntity::getInstance($module);
    foreach ($tblname_field_arr as $val) {
        list($tbl, $col, $fld) = explode(".", $val);
        $col_name = $tbl . "." . $col;
        $field_value = $column_fields[$fld];
        if ($fld == $focus->table_index && $column_fields[$focus->table_index] != '' && !is_integer($column_fields[$focus->table_index])) {
            $field_value = getEntityId($module, $column_fields[$focus->table_index]);
        }
        if (is_uitype($uitype_arr[$fld], '_users_list_') && $field_value == '') {
            $field_value = $current_user->id;
        }
        $where_clause .= " AND ifnull(" . $adb->sql_escape_string($col_name) . ",'') = ifnull('" . $adb->sql_escape_string($field_value) . "','') ";
    }
    return $where_clause;
}
コード例 #6
0
	public function transformForImport($fieldData, $moduleMeta, $fillDefault=true) {
		$moduleFields = $moduleMeta->getModuleFields();
		$defaultFieldValues = $this->getDefaultFieldValues($moduleMeta);
		foreach ($fieldData as $fieldName => $fieldValue) {
			$fieldInstance = $moduleFields[$fieldName];
			if ($fieldInstance->getFieldDataType() == 'owner') {
				$ownerId = getUserId_Ol($fieldValue);
				if (empty($ownerId)) {
					$ownerId = getGrpId($fieldValue);
				}
				if (empty($ownerId) && isset($defaultFieldValues[$fieldName])) {
					$ownerId = $defaultFieldValues[$fieldName];
				}
				if(empty($ownerId) ||
							!Import_Utils::hasAssignPrivilege($moduleMeta->getEntityName(), $ownerId)) {
					$ownerId = $this->user->id;
				}
				$fieldData[$fieldName] = $ownerId;

			} elseif ($fieldInstance->getFieldDataType() == 'reference') {
				$entityId = false;
				if (!empty($fieldValue)) {
					if(strpos($fieldValue, '::::') > 0) {
						$fieldValueDetails = explode('::::', $fieldValue);
					} else {
						$fieldValueDetails = explode(':::', $fieldValue);
					}
					if (count($fieldValueDetails) > 1) {
						$referenceModuleName = trim($fieldValueDetails[0]);
						$entityLabel = trim($fieldValueDetails[1]);
						$entityId = getEntityId($referenceModuleName, $entityLabel);
					} else {
						$referencedModules = $fieldInstance->getReferenceList();
						$entityLabel = $fieldValue;
						foreach ($referencedModules as $referenceModule) {
							$referenceModuleName = $referenceModule;
							if ($referenceModule == 'Users') {
								$referenceEntityId = getUserId_Ol($entityLabel);
								if(empty($referenceEntityId) ||
										!Import_Utils::hasAssignPrivilege($moduleMeta->getEntityName(), $referenceEntityId)) {
									$referenceEntityId = $this->user->id;
								}
							} else {
								$referenceEntityId = getEntityId($referenceModule, $entityLabel);
							}
							if ($referenceEntityId != 0) {
								$entityId = $referenceEntityId;
								break;
							}
						}
					}
					if ((empty($entityId) || $entityId == 0) && !empty($referenceModuleName)) {
						if(isPermitted($referenceModuleName, 'EditView') == 'yes') {
							$wsEntityIdInfo = $this->createEntityRecord($referenceModuleName, $entityLabel);
							$wsEntityId = $wsEntityIdInfo['id'];
							$entityIdComponents = vtws_getIdComponents($wsEntityId);
							$entityId = $entityIdComponents[1];
						}
					}
					$fieldData[$fieldName] = $entityId;
				} else {
					$referencedModules = $fieldInstance->getReferenceList();
					if ($referencedModules[0] == 'Users') {
						if(isset($defaultFieldValues[$fieldName])) {
							$fieldData[$fieldName] = $defaultFieldValues[$fieldName];
						}
						if(empty($fieldData[$fieldName]) ||
								!Import_Utils::hasAssignPrivilege($moduleMeta->getEntityName(), $fieldData[$fieldName])) {
							$fieldData[$fieldName] = $this->user->id;
						}
					} else {
						$fieldData[$fieldName] = '';
					}
				}

			} elseif ($fieldInstance->getFieldDataType() == 'picklist') {
				global $default_charset;
				if (empty($fieldValue) && isset($defaultFieldValues[$fieldName])) {
					$fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName];
				}
				$allPicklistDetails = $fieldInstance->getPicklistDetails();
				$allPicklistValues = array();
				foreach ($allPicklistDetails as $picklistDetails) {
					$allPicklistValues[] = $picklistDetails['value'];
				}
				$encodePicklistValue = htmlentities($fieldValue,ENT_QUOTES,$default_charset);
				if (!in_array($encodePicklistValue, $allPicklistValues)) {
					$moduleObject = Vtiger_Module::getInstance($moduleMeta->getEntityName());
					$fieldObject = Vtiger_Field::getInstance($fieldName, $moduleObject);
					$fieldObject->setPicklistValues(array($fieldValue));
				}
			} else {
				if ($fieldInstance->getFieldDataType() == 'datetime' && !empty($fieldValue)) {
					if($fieldValue == null || $fieldValue == '0000-00-00 00:00:00') {
						$fieldValue = '';
					}
					$valuesList = explode(' ', $fieldValue);
					if(count($valuesList) == 1) $fieldValue = '';
					$fieldValue = getValidDBInsertDateTimeValue($fieldValue);
					if (preg_match("/^[0-9]{2,4}[-][0-1]{1,2}?[0-9]{1,2}[-][0-3]{1,2}?[0-9]{1,2} ([0-1][0-9]|[2][0-3])([:][0-5][0-9]){1,2}$/",
							$fieldValue) == 0) {
						$fieldValue = '';
					}
					$fieldData[$fieldName] = $fieldValue;
				}
				if ($fieldInstance->getFieldDataType() == 'date' && !empty($fieldValue)) {
					if($fieldValue == null || $fieldValue == '0000-00-00') {
						$fieldValue = '';
					}
					$fieldValue = getValidDBInsertDateValue($fieldValue);
					if (preg_match("/^[0-9]{2,4}[-][0-1]{1,2}?[0-9]{1,2}[-][0-3]{1,2}?[0-9]{1,2}$/", $fieldValue) == 0) {
						$fieldValue = '';
					}
					$fieldData[$fieldName] = $fieldValue;
				}
				if (empty($fieldValue) && isset($defaultFieldValues[$fieldName])) {
					$fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName];
				}
			}
		}
		if($fillDefault) {
			foreach($defaultFieldValues as $fieldName => $fieldValue) {
				if (!isset($fieldData[$fieldName])) {
					$fieldData[$fieldName] = $defaultFieldValues[$fieldName];
				}
			}
		}

		foreach ($moduleFields as $fieldName => $fieldInstance) {
			if(empty($fieldData[$fieldName]) && $fieldInstance->isMandatory()) {
				return null;
			}
		}

		return DataTransform::sanitizeData($fieldData, $moduleMeta);
	}