function sanitizeForInsert($row, $meta) { global $adb; $associatedToUser = false; if (strtolower($meta->getEntityName()) == "emails") { if (isset($row['parent_id'])) { $components = vtws_getIdComponents($row['parent_id']); if ($components[0] == VtigerWebserviceObject::fromName($adb, 'Users')) { $associatedToUser = true; } } } $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 { $emailFields = $meta->getEmailFields(); $fieldId = getEmailFieldId($meta, $row['parent_id'], $emailFields); $row['parent_id'] = $row['parent_id'] . "@{$fieldId}|"; } } } if ($row["id"]) { unset($row["id"]); } if (isset($row[$meta->getObectIndexColumn()])) { unset($row[$meta->getObectIndexColumn()]); } return $row; }
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"; } if (isset($row['contact_id']) and strpos($row['contact_id'], ';') !== false) { $ctowsids = array(); $listofctos = explode(';', $row['contact_id']); foreach ($listofctos as $cto) { if (strpos($cto, 'x') !== false) { $ctowsid = vtws_getIdComponents($cto); $ctowsids[] = $ctowsid[1]; } else { $ctowsids[] = $cto; } } $row['contact_id'] = implode(';', $ctowsids); } } 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); return $row; }