Exemple #1
0
 static function sanitizeRetrieveEntityInfo($newRow, $meta)
 {
     $newRow = DataTransform::sanitizeDateFieldsForInsert($newRow, $meta);
     $newRow = DataTransform::sanitizeCurrencyFieldsForInsert($newRow, $meta);
     $newRow = DataTransform::sanitizeTextFieldsForInsert($newRow, $meta);
     return $newRow;
 }
Exemple #2
0
 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;
 }
Exemple #3
0
 public function save()
 {
     if ($this->_deleted == true) {
         return;
     }
     if ($this->_data == false) {
         return;
     }
     if ($this->_isDummy) {
         return;
     }
     if (empty($this->_id)) {
         ${"GLOBALS"}["udgdmdj"] = "result";
         ${"GLOBALS"}["bgfrqsi"] = "result";
         ${${"GLOBALS"}["bgfrqsi"]} = $this->createRecord();
         return ${${"GLOBALS"}["udgdmdj"]};
     }
     if ($this->_changed == false) {
         return;
     }
     global $default_charset;
     $wislscn = "_cache";
     $this->prepareTransfer();
     try {
         $mnjcnqlgng = "metaHandler";
         $elevuutnetl = "metaHandler";
         require_once "data/CRMEntity.php";
         ${$elevuutnetl} = self::getMetaHandler($this->getModuleName());
         $_REQUEST = $this->_data;
         ${${"GLOBALS"}["bnxctgz"]} = CRMEntity::getInstance($this->getModuleName());
         $vanizlvofalw = "focus";
         $focus->id = $this->_id;
         $focus->mode = "edit";
         ${"GLOBALS"}["ivcjrkopdtg"] = "moduleFields";
         $focus->retrieve_entity_info($this->_id, $this->getModuleName());
         $focus->clearSingletonSaveFields();
         $focus->column_fields = \DataTransform::sanitizeDateFieldsForInsert($focus->column_fields, ${${"GLOBALS"}["xjcvkdbwo"]});
         $nlkugopxcby = "value";
         $focus->column_fields = \DataTransform::sanitizeCurrencyFieldsForInsert($focus->column_fields, ${$mnjcnqlgng});
         ${${"GLOBALS"}["ivcjrkopdtg"]} = $metaHandler->getModuleFields();
         foreach ($focus->column_fields as ${${"GLOBALS"}["hjgwjtwk"]} => ${$nlkugopxcby}) {
             if ($this->_data[${${"GLOBALS"}["hjgwjtwk"]}] != ${${"GLOBALS"}["uphxwmiizl"]} && !in_array(${${"GLOBALS"}["hjgwjtwk"]}, array("record_id", "record_module"))) {
                 $dlmyihkhrx = "key";
                 ${"GLOBALS"}["qxesemuz"] = "newValue";
                 ${"GLOBALS"}["iaebjbr"] = "moduleFields";
                 $eklkegifwy = "fieldDataType";
                 $yuelkvntx = "fieldInstance";
                 ${"GLOBALS"}["qfydrxtn"] = "fieldDataType";
                 ${${"GLOBALS"}["qxesemuz"]} = $this->_data[${${"GLOBALS"}["hjgwjtwk"]}];
                 ${$yuelkvntx} = ${${"GLOBALS"}["iaebjbr"]}[${$dlmyihkhrx}];
                 if (empty(${${"GLOBALS"}["rrjhgcneilp"]})) {
                     throw new \Exception("Field " . ${${"GLOBALS"}["hjgwjtwk"]} . " not found in module " . $this->getModuleName() . ".");
                 }
                 ${$eklkegifwy} = $fieldInstance->getFieldDataType();
                 if ("reference" == ${${"GLOBALS"}["xoonpevch"]} || "owner" == ${${"GLOBALS"}["qfydrxtn"]}) {
                     ${"GLOBALS"}["smqnzlzkae"] = "key";
                     ${${"GLOBALS"}["rztsbw"]} = $this->getCrmId(${${"GLOBALS"}["rztsbw"]});
                     $lnakiyyxnloc = "newValue";
                     if ($focus->column_fields[${${"GLOBALS"}["smqnzlzkae"]}] == ${$lnakiyyxnloc}) {
                         continue;
                     }
                 }
                 $focus->column_fields[${${"GLOBALS"}["hjgwjtwk"]}] = ${${"GLOBALS"}["rztsbw"]};
             }
         }
         foreach ($focus->column_fields as ${${"GLOBALS"}["okvmusckd"]} => ${${"GLOBALS"}["naoyqsa"]}) {
             ${"GLOBALS"}["xkqgctp"] = "fieldValue";
             ${"GLOBALS"}["bxkclviriy"] = "default_charset";
             if (is_array(${${"GLOBALS"}["naoyqsa"]})) {
                 throw new \Exception("Wrong input VTEntity::" . __LINE__ . "=" . serialize(${${"GLOBALS"}["naoyqsa"]}));
             }
             $focus->column_fields[${${"GLOBALS"}["okvmusckd"]}] = html_entity_decode(${${"GLOBALS"}["xkqgctp"]}, ENT_QUOTES, ${${"GLOBALS"}["bxkclviriy"]});
         }
         ${$vanizlvofalw} = $this->modifyValuesBeforeSave(${${"GLOBALS"}["bnxctgz"]});
         $_REQUEST["file"] = "";
         $_REQUEST["ajxaction"] = "";
         ${${"GLOBALS"}["djwhrrnnsjk"]} = $_REQUEST["action"];
         $_REQUEST["action"] = "";
         $focus->isLineItemUpdate = false;
         $focus->save($this->getModuleName());
     } catch (\Exception $exp) {
         if ($exp->getCode() == "DATABASE_QUERY_ERROR") {
             $nhkvwsu = "handleResult";
             global $adb;
             ${$nhkvwsu} = $this->_handleDatabaseError($adb->database->_errorMsg);
             return;
         }
         if ($exp->getCode() == "MANDATORY_FIELDS_MISSING") {
             ${"GLOBALS"}["xkshfsxwf"] = "handleResult";
             ${"GLOBALS"}["gmokooantx"] = "handleResult";
             ${${"GLOBALS"}["gmokooantx"]} = $this->_handleMandatoryError(${${"GLOBALS"}["jvdhxqdu"]});
             if (${${"GLOBALS"}["xkshfsxwf"]} !== false) {
                 return;
             }
         }
         \Workflow2::error_handler($exp->getCode(), $exp->getMessage(), $exp->getFile(), $exp->getLine());
     }
     $this->afterTransfer();
     $this->_changed = false;
     $_FILES = ${${"GLOBALS"}["rednnyjghpl"]};
     unset(VTEntity::${$wislscn}[VTEntity::$_user->id][$this->_id]);
     if (!$this instanceof VTInventoryEntity) {
         $this->_data = false;
     }
 }
 public function save()
 {
     if ($this->_deleted == true) {
         return;
     }
     if ($this->_data == false) {
         return;
     }
     if ($this->_isDummy) {
         return;
     }
     if (empty($this->_id)) {
         $result = $this->createRecord();
         return $result;
     }
     if (VTEntity::$_user === false || VTEntity::$_user->is_admin != "on") {
         $useUser = Users::getActiveAdminUser();
     } else {
         $useUser = VTEntity::$_user;
     }
     $oldFiles = $_FILES;
     require_once "include/Webservices/Update.php";
     if ($this->_changed == false) {
         return;
     }
     // I must prevent $ajaxSave to come true in vtws_update. This will remove all date fields !
     unset($_FILES);
     #$oldA = $_REQUEST['file'];
     #$oldB = $_REQUEST['action'];
     #$_REQUEST['file'] = "VTEntitiy";
     #$_REQUEST['action'] = "WebServiceSave";
     global $current_user, $default_charset;
     $oldCurrentUser = $current_user;
     $current_user = $useUser;
     $this->prepareTransfer();
     try {
         require_once 'data/CRMEntity.php';
         $metaHandler = self::getMetaHandler($this->getModuleName());
         $focus = CRMEntity::getInstance($this->getModuleName());
         $focus->id = $this->_id;
         $focus->mode = 'edit';
         $focus->retrieve_entity_info($this->_id, $this->getModuleName());
         $focus->clearSingletonSaveFields();
         $focus->column_fields = \DataTransform::sanitizeDateFieldsForInsert($focus->column_fields, $metaHandler);
         $focus->column_fields = \DataTransform::sanitizeCurrencyFieldsForInsert($focus->column_fields, $metaHandler);
         $moduleFields = $metaHandler->getModuleFields();
         foreach ($focus->column_fields as $key => $value) {
             if ($this->_data[$key] != $value && !in_array($key, array('record_id', 'record_module'))) {
                 //var_dump($key, $this->_data[$key], $value);
                 $newValue = $this->_data[$key];
                 $fieldInstance = $moduleFields[$key];
                 if (empty($fieldInstance)) {
                     throw new \Exception('Field ' . $key . ' not found in module ' . $this->getModuleName() . '.');
                 }
                 $fieldDataType = $fieldInstance->getFieldDataType();
                 if ('reference' == $fieldDataType || 'owner' == $fieldDataType) {
                     $newValue = $this->getCrmId($newValue);
                     if ($focus->column_fields[$key] == $newValue) {
                         continue;
                     }
                 }
                 //var_dump('set');
                 $focus->column_fields[$key] = $newValue;
             }
         }
         foreach ($focus->column_fields as $fieldName => $fieldValue) {
             $focus->column_fields[$fieldName] = html_entity_decode($fieldValue, ENT_QUOTES, $default_charset);
         }
         $_REQUEST['file'] = '';
         $_REQUEST['ajxaction'] = '';
         // Added as Mass Edit triggers workflow and date and currency fields are set to user format
         // When saving the information in database saveentity API should convert to database format
         // and save it. But it converts in database format only if that date & currency fields are
         // changed(massedit) other wise they wont be converted thereby changing the values in user
         // format, CRMEntity.php line 474 has the login to check wheather to convert to database format
         $actionName = $_REQUEST['action'];
         $_REQUEST['action'] = '';
         // For workflows update field tasks is deleted all the lineitems.
         $focus->isLineItemUpdate = false;
         $focus->save($this->getModuleName());
         //// Reverting back the action name as there can be some dependencies on this.
         //$_REQUEST['action'] = $actionName;
         //$result = vtws_update($this->_data, $useUser);
         $current_user = $oldCurrentUser;
     } catch (Exception $exp) {
         $current_user = $oldCurrentUser;
         if ($exp->getCode() == "DATABASE_QUERY_ERROR") {
             global $adb;
             $handleResult = $this->_handleDatabaseError($adb->database->_errorMsg);
             return;
         }
         if ($exp->getCode() == "MANDATORY_FIELDS_MISSING") {
             $handleResult = $this->_handleMandatoryError($exp);
             if ($handleResult !== false) {
                 return;
             }
         }
         throw $exp;
     }
     $this->afterTransfer();
     $this->_changed = false;
     $_FILES = $oldFiles;
 }