[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
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 DataTransform{ 12 13 public static $recordString = "record_id"; 14 public static $recordModuleString = 'record_module'; 15 16 function sanitizeDataWithColumn($row,$meta){ 17 18 $newRow = array(); 19 if(isset($row['count(*)'])){ 20 return DataTransform::sanitizeDataWithCountColumn($row,$meta); 21 } 22 $fieldColumnMapping = $meta->getFieldColumnMapping(); 23 $columnFieldMapping = array_flip($fieldColumnMapping); 24 foreach($row as $col=>$val){ 25 if(array_key_exists($col,$columnFieldMapping)) 26 $newRow[$columnFieldMapping[$col]] = $val; 27 } 28 $newRow = DataTransform::sanitizeData($newRow,$meta,true); 29 return $newRow; 30 } 31 32 function sanitizeDataWithCountColumn($row,$meta){ 33 $newRow = array(); 34 foreach($row as $col=>$val){ 35 $newRow['count'] = $val; 36 } 37 return $newRow; 38 } 39 40 function filterAndSanitize($row,$meta){ 41 42 $row = DataTransform::filterAllColumns($row,$meta); 43 $row = DataTransform::sanitizeData($row,$meta); 44 return $row; 45 } 46 47 function sanitizeData($newRow,$meta,$t=null){ 48 49 $newRow = DataTransform::sanitizeReferences($newRow,$meta); 50 $newRow = DataTransform::sanitizeOwnerFields($newRow,$meta,$t); 51 $newRow = DataTransform::sanitizeFields($newRow,$meta); 52 return $newRow; 53 } 54 55 function sanitizeForInsert($row,$meta){ 56 global $adb; 57 $associatedToUser = false; 58 $parentTypeId = null; 59 if(strtolower($meta->getEntityName()) == "emails"){ 60 if(isset($row['parent_id'])){ 61 $components = vtws_getIdComponents($row['parent_id']); 62 $userObj = VtigerWebserviceObject::fromName($adb,'Users'); 63 $parentTypeId = $components[0]; 64 if($components[0] == $userObj->getEntityId()){ 65 $associatedToUser = true; 66 } 67 } 68 } 69 // added to handle the setting reminder time 70 if(strtolower($meta->getEntityName()) == "events"){ 71 if(isset($row['reminder_time'])&& $row['reminder_time']!= null && $row['reminder_time'] != 0){ 72 $_REQUEST['set_reminder'] = "Yes"; 73 $_REQUEST['mode'] = 'edit'; 74 75 $reminder = $row['reminder_time']; 76 $seconds = (int)$reminder%60; 77 $minutes = (int)($reminder/60)%60; 78 $hours = (int)($reminder/(60*60))%24; 79 $days = (int)($reminder/(60*60*24)); 80 81 //at vtiger there cant be 0 minutes reminder so we are setting to 1 82 if($minutes == 0){ 83 $minutes = 1; 84 } 85 86 $_REQUEST['remmin'] = $minutes; 87 $_REQUEST['remhrs'] = $hours; 88 $_REQUEST['remdays'] = $days; 89 } else { 90 $_REQUEST['set_reminder'] = "No"; 91 } 92 } elseif(strtolower($meta->getEntityName()) == "calendar") { 93 if(empty($row['sendnotification']) || strtolower($row['sendnotificaiton'])=='no' 94 || $row['sendnotificaiton'] == '0' || $row['sendnotificaiton'] == 'false' 95 || strtolower($row['sendnotificaiton']) == 'n') { 96 unset($row['sendnotification']); 97 } 98 } 99 $references = $meta->getReferenceFieldDetails(); 100 foreach($references as $field=>$typeList){ 101 if(strpos($row[$field],'x')!==false){ 102 $row[$field] = vtws_getIdComponents($row[$field]); 103 $row[$field] = $row[$field][1]; 104 } 105 } 106 $ownerFields = $meta->getOwnerFields(); 107 foreach($ownerFields as $index=>$field){ 108 if(isset($row[$field]) && $row[$field]!=null){ 109 $ownerDetails = vtws_getIdComponents($row[$field]); 110 $row[$field] = $ownerDetails[1]; 111 } 112 } 113 if(strtolower($meta->getEntityName()) == "emails"){ 114 if(isset($row['parent_id'])){ 115 if($associatedToUser === true){ 116 $_REQUEST['module'] = 'Emails'; 117 $row['parent_id'] = $row['parent_id']."@-1|"; 118 $_REQUEST['parent_id'] = $row['parent_id']; 119 }else{ 120 $referenceHandler = vtws_getModuleHandlerFromId($parentTypeId, 121 $meta->getUser()); 122 $referenceMeta = $referenceHandler->getMeta(); 123 $fieldId = getEmailFieldId($referenceMeta, $row['parent_id']); 124 $row['parent_id'] .= "@$fieldId|"; 125 } 126 } 127 } 128 if($row["id"]){ 129 unset($row["id"]); 130 } 131 if(isset($row[$meta->getObectIndexColumn()])){ 132 unset($row[$meta->getObectIndexColumn()]); 133 } 134 135 $row = DataTransform::sanitizeDateFieldsForInsert($row,$meta); 136 $row = DataTransform::sanitizeCurrencyFieldsForInsert($row,$meta); 137 138 return $row; 139 140 } 141 142 function filterAllColumns($row,$meta){ 143 144 $recordString = DataTransform::$recordString; 145 146 $allFields = $meta->getFieldColumnMapping(); 147 $newRow = array(); 148 foreach($allFields as $field=>$col){ 149 $newRow[$field] = $row[$field]; 150 } 151 if(isset($row[$recordString])){ 152 $newRow[$recordString] = $row[$recordString]; 153 } 154 return $newRow; 155 156 } 157 158 function sanitizeFields($row,$meta){ 159 $default_charset = VTWS_PreserveGlobal::getGlobal('default_charset'); 160 $recordString = DataTransform::$recordString; 161 162 $recordModuleString = DataTransform::$recordModuleString; 163 164 if(isset($row[$recordModuleString])){ 165 unset($row[$recordModuleString]); 166 } 167 168 if(isset($row['id'])){ 169 if(strpos($row['id'],'x')===false){ 170 $row['id'] = vtws_getId($meta->getEntityId(),$row['id']); 171 } 172 } 173 174 if(isset($row[$recordString])){ 175 $row['id'] = vtws_getId($meta->getEntityId(),$row[$recordString]); 176 unset($row[$recordString]); 177 } 178 179 if(!isset($row['id'])){ 180 if($row[$meta->getObectIndexColumn()] ){ 181 $row['id'] = vtws_getId($meta->getEntityId(),$row[$meta->getObectIndexColumn()]); 182 }else{ 183 //TODO Handle this. 184 //echo 'error id noy set' ; 185 } 186 }else if(isset($row[$meta->getObectIndexColumn()]) && strcmp($meta->getObectIndexColumn(),"id")!==0){ 187 unset($row[$meta->getObectIndexColumn()]); 188 } 189 190 foreach ($row as $field => $value) { 191 $row[$field] = html_entity_decode($value, ENT_QUOTES, $default_charset); 192 } 193 return $row; 194 } 195 196 function sanitizeReferences($row,$meta){ 197 global $adb,$log; 198 $references = $meta->getReferenceFieldDetails(); 199 foreach($references as $field=>$typeList){ 200 if(strtolower($meta->getEntityName()) == "emails"){ 201 if(isset($row['parent_id'])){ 202 list($row['parent_id'], $fieldId) = explode('@', $row['parent_id']); 203 } 204 } 205 if($row[$field]){ 206 $found = false; 207 foreach ($typeList as $entity) { 208 $webserviceObject = VtigerWebserviceObject::fromName($adb,$entity); 209 $handlerPath = $webserviceObject->getHandlerPath(); 210 $handlerClass = $webserviceObject->getHandlerClass(); 211 212 require_once $handlerPath; 213 214 $handler = new $handlerClass($webserviceObject,$meta->getUser(),$adb,$log); 215 $entityMeta = $handler->getMeta(); 216 if($entityMeta->exists($row[$field])){ 217 $row[$field] = vtws_getId($webserviceObject->getEntityId(),$row[$field]); 218 $found = true; 219 break; 220 } 221 } 222 if($found !== true){ 223 //This is needed as for query operation of the related record is deleted. 224 $row[$field] = null; 225 } 226 //0 is the default for most of the reference fields, so handle the case and return null instead as its the 227 //only valid value, which is not a reference Id. 228 }elseif(isset($row[$field]) && $row[$field]==0){ 229 $row[$field] = null; 230 } 231 } 232 return $row; 233 } 234 235 function sanitizeOwnerFields($row,$meta,$t=null){ 236 global $adb; 237 $ownerFields = $meta->getOwnerFields(); 238 foreach($ownerFields as $index=>$field){ 239 if(isset($row[$field]) && $row[$field]!=null){ 240 $ownerType = vtws_getOwnerType($row[$field]); 241 $webserviceObject = VtigerWebserviceObject::fromName($adb,$ownerType); 242 $row[$field] = vtws_getId($webserviceObject->getEntityId(),$row[$field]); 243 } 244 } 245 return $row; 246 } 247 248 function sanitizeDateFieldsForInsert($row,$meta){ 249 global $current_user; 250 $moduleFields = $meta->getModuleFields(); 251 foreach($moduleFields as $fieldName=>$fieldObj){ 252 if($fieldObj->getFieldDataType()=="date"){ 253 if(!empty($row[$fieldName])){ 254 $dateFieldObj = new DateTimeField($row[$fieldName]); 255 $row[$fieldName] = $dateFieldObj->getDisplayDate($current_user); 256 } 257 } 258 } 259 return $row; 260 } 261 262 function sanitizeCurrencyFieldsForInsert($row,$meta){ 263 global $current_user; 264 $moduleFields = $meta->getModuleFields(); 265 foreach($moduleFields as $fieldName=>$fieldObj){ 266 if($fieldObj->getFieldDataType()=="currency" && !empty($row[$fieldName])) { 267 if($fieldObj->getUIType() == '71') { 268 $row[$fieldName] = CurrencyField::convertToUserFormat($row[$fieldName],$current_user); 269 } else if($fieldObj->getUIType() == '72') { 270 $row[$fieldName] = CurrencyField::convertToUserFormat($row[$fieldName],$current_user,true); 271 } 272 } 273 } 274 return $row; 275 } 276 } 277 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |