晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/akaindir/public_html/crm/include/Webservices/ |
Upload File : |
<?php
/*+***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*************************************************************************************/
class DataTransform{
public static $recordString = "record_id";
public static $recordModuleString = 'record_module';
public static $recordSource = 'WEBSERVICE';
function sanitizeDataWithColumn($row,$meta){
$newRow = array();
if(isset($row['count(*)'])){
return DataTransform::sanitizeDataWithCountColumn($row,$meta);
}
$fieldColumnMapping = $meta->getFieldColumnMapping();
$columnFieldMapping = array_flip($fieldColumnMapping);
foreach($row as $col=>$val){
if(array_key_exists($col,$columnFieldMapping))
$newRow[$columnFieldMapping[$col]] = $val;
}
$newRow = DataTransform::sanitizeData($newRow,$meta,true);
return $newRow;
}
function sanitizeDataWithCountColumn($row,$meta){
$newRow = array();
foreach($row as $col=>$val){
$newRow['count'] = $val;
}
return $newRow;
}
function filterAndSanitize($row,$meta){
$recordLabel = $row['label'];
$row = DataTransform::filterAllColumns($row,$meta);
$row = DataTransform::sanitizeData($row,$meta);
if(!empty($recordLabel)){
$row['label'] = $recordLabel;
}
return $row;
}
function sanitizeData($newRow,$meta,$t=null){
$newRow = DataTransform::sanitizeReferences($newRow,$meta);
$newRow = DataTransform::sanitizeOwnerFields($newRow,$meta,$t);
$newRow = DataTransform::sanitizeFields($newRow,$meta);
return $newRow;
}
function sanitizeForInsert($row,$meta){
global $adb;
$associatedToUser = false;
$parentTypeId = null;
if(strtolower($meta->getEntityName()) == "emails"){
if(isset($row['parent_id'])){
$components = vtws_getIdComponents($row['parent_id']);
$userObj = VtigerWebserviceObject::fromName($adb,'Users');
$parentTypeId = $components[0];
if($components[0] == $userObj->getEntityId()){
$associatedToUser = true;
}
}
}
// added to handle the setting reminder time
if(strtolower($meta->getEntityName()) == "events"){
if(isset($row['reminder_time'])&& $row['reminder_time']!= null && $row['reminder_time'] != 0){
$_REQUEST['set_reminder'] = "Yes";
$_REQUEST['mode'] = 'edit';
$reminder = $row['reminder_time'];
$seconds = (int)$reminder%60;
$minutes = (int)($reminder/60)%60;
$hours = (int)($reminder/(60*60))%24;
$days = (int)($reminder/(60*60*24));
//at vtiger there cant be 0 minutes reminder so we are setting to 1
if($minutes == 0){
$minutes = 1;
}
$_REQUEST['remmin'] = $minutes;
$_REQUEST['remhrs'] = $hours;
$_REQUEST['remdays'] = $days;
} else {
$_REQUEST['set_reminder'] = "No";
}
} elseif(strtolower($meta->getEntityName()) == "calendar") {
if(empty($row['sendnotification']) || strtolower($row['sendnotificaiton'])=='no'
|| $row['sendnotificaiton'] == '0' || $row['sendnotificaiton'] == 'false'
|| strtolower($row['sendnotificaiton']) == 'n') {
unset($row['sendnotification']);
}
}
$references = $meta->getReferenceFieldDetails();
foreach($references as $field=>$typeList){
if(strpos($row[$field],'x')!==false){
$row[$field] = vtws_getIdComponents($row[$field]);
$row[$field] = $row[$field][1];
}
}
$ownerFields = $meta->getOwnerFields();
foreach($ownerFields as $index=>$field){
if(isset($row[$field]) && $row[$field]!=null){
$ownerDetails = vtws_getIdComponents($row[$field]);
$row[$field] = $ownerDetails[1];
}
}
if(strtolower($meta->getEntityName()) == "emails"){
if(isset($row['parent_id'])){
if($associatedToUser === true){
$_REQUEST['module'] = 'Emails';
$row['parent_id'] = $row['parent_id']."@-1|";
$_REQUEST['parent_id'] = $row['parent_id'];
}else{
$referenceHandler = vtws_getModuleHandlerFromId($parentTypeId,
$meta->getUser());
$referenceMeta = $referenceHandler->getMeta();
$fieldId = getEmailFieldId($referenceMeta, $row['parent_id']);
$row['parent_id'] .= "@$fieldId|";
}
}
}
if($row["id"]){
unset($row["id"]);
}
if(isset($row[$meta->getObectIndexColumn()])){
unset($row[$meta->getObectIndexColumn()]);
}
$row = DataTransform::sanitizeDateFieldsForInsert($row,$meta);
$row = DataTransform::sanitizeCurrencyFieldsForInsert($row,$meta);
// New field added to store Source of Created Record
if (!isset($row['source'])) {
$row['source'] = self::$recordSource;
}
return $row;
}
function filterAllColumns($row,$meta){
$recordString = DataTransform::$recordString;
$allFields = $meta->getFieldColumnMapping();
$newRow = array();
foreach($allFields as $field=>$col){
$newRow[$field] = $row[$field];
}
if(isset($row[$recordString])){
$newRow[$recordString] = $row[$recordString];
}
return $newRow;
}
function sanitizeFields($row,$meta){
$default_charset = VTWS_PreserveGlobal::getGlobal('default_charset');
$recordString = DataTransform::$recordString;
$recordModuleString = DataTransform::$recordModuleString;
if(isset($row[$recordModuleString])){
unset($row[$recordModuleString]);
}
if(isset($row['id'])){
if(strpos($row['id'],'x')===false){
$row['id'] = vtws_getId($meta->getEntityId(),$row['id']);
}
}
if(isset($row[$recordString])){
$row['id'] = vtws_getId($meta->getEntityId(),$row[$recordString]);
unset($row[$recordString]);
}
if(!isset($row['id'])){
if($row[$meta->getObectIndexColumn()] ){
$row['id'] = vtws_getId($meta->getEntityId(),$row[$meta->getObectIndexColumn()]);
}else{
//TODO Handle this.
//echo 'error id noy set' ;
}
}else if(isset($row[$meta->getObectIndexColumn()]) && strcmp($meta->getObectIndexColumn(),"id")!==0){
unset($row[$meta->getObectIndexColumn()]);
}
foreach ($row as $field => $value) {
$row[$field] = html_entity_decode($value, ENT_QUOTES, $default_charset);
}
return $row;
}
function sanitizeReferences($row,$meta){
global $adb,$log;
$references = $meta->getReferenceFieldDetails();
foreach($references as $field=>$typeList){
if(strtolower($meta->getEntityName()) == "emails"){
if(isset($row['parent_id'])){
list($row['parent_id'], $fieldId) = explode('@', $row['parent_id']);
}
}
if($row[$field]){
$found = false;
foreach ($typeList as $entity) {
$webserviceObject = VtigerWebserviceObject::fromName($adb,$entity);
$handlerPath = $webserviceObject->getHandlerPath();
$handlerClass = $webserviceObject->getHandlerClass();
require_once $handlerPath;
$handler = new $handlerClass($webserviceObject,$meta->getUser(),$adb,$log);
$entityMeta = $handler->getMeta();
if($entityMeta->exists($row[$field])){
$row[$field] = vtws_getId($webserviceObject->getEntityId(),$row[$field]);
$found = true;
break;
}
}
if($found !== true){
//This is needed as for query operation of the related record is deleted.
$row[$field] = null;
}
//0 is the default for most of the reference fields, so handle the case and return null instead as its the
//only valid value, which is not a reference Id.
}elseif(isset($row[$field]) && $row[$field]==0){
$row[$field] = null;
}
}
return $row;
}
function sanitizeOwnerFields($row,$meta,$t=null){
global $adb;
$ownerFields = $meta->getOwnerFields();
foreach($ownerFields as $index=>$field){
if(isset($row[$field]) && $row[$field]!=null && $row[$field] != 0){
$ownerType = vtws_getOwnerType($row[$field]);
if ($ownerType) {
$webserviceObject = VtigerWebserviceObject::fromName($adb,$ownerType);
$row[$field] = vtws_getId($webserviceObject->getEntityId(),$row[$field]);
}
}
}
return $row;
}
function sanitizeDateFieldsForInsert($row,$meta){
global $current_user;
$moduleFields = $meta->getModuleFields();
foreach($moduleFields as $fieldName=>$fieldObj){
if($fieldObj->getFieldDataType()=="date"){
if(!empty($row[$fieldName])){
$dateFieldObj = new DateTimeField($row[$fieldName]);
$row[$fieldName] = $dateFieldObj->getDisplayDate($current_user);
}
}
}
return $row;
}
function sanitizeCurrencyFieldsForInsert($row,$meta){
global $current_user;
$moduleFields = $meta->getModuleFields();
foreach($moduleFields as $fieldName=>$fieldObj){
if (!empty($row[$fieldName])) {
if($fieldObj->getFieldDataType()=="currency") {
if($fieldObj->getUIType() == '71') {
$row[$fieldName."_raw"] = $row[$fieldName];
$row[$fieldName] = CurrencyField::convertToUserFormat($row[$fieldName],$current_user);
} else if($fieldObj->getUIType() == '72') {
$currencyConversionRate = $row['conversion_rate'];
if (!empty($currencyConversionRate)) {
$rawBaseCurrencyValue = CurrencyField::convertToDollar($row[$fieldName], $currencyConversionRate);
$row[$fieldName."_raw"] = $rawBaseCurrencyValue;
$row[$fieldName."_raw_converted"] = CurrencyField::convertToUserFormat($rawBaseCurrencyValue, $current_user);
}
$row[$fieldName] = CurrencyField::convertToUserFormat($row[$fieldName],$current_user,true);
}
} else if($fieldObj->getUIType() == 7 && in_array($fieldObj->getFieldType(), array('N', 'NN'))) {
$row[$fieldName] = CurrencyField::convertToUserFormat($row[$fieldName],$current_user,true);
} else if($fieldObj->getUIType() == 1 && in_array($fieldObj->getFieldType(), array('N', 'NN')) && in_array($fieldObj->getFieldName(), array('qty_per_unit', 'qtyinstock'))) {
$row[$fieldName] = CurrencyField::convertToUserFormat($row[$fieldName],$current_user,true);
}
}
}
return $row;
}
}
?>