diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 80228628c61..ad36a6e5ee7 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -60,7 +60,10 @@ if ($action == 'add' && !empty($permissiontoadd)) if (!GETPOSTISSET($key)) continue; // The field was not submited to be edited } // Ignore special fields - if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; + if (in_array($key, array('rowid', 'entity', 'import_key'))) continue; + if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) { + if (!in_array(abs($val['visible']), array(1, 3))) continue; // Only 1 and 3 that are case to create + } // Set value to insert if (in_array($object->fields[$key]['type'], array('text', 'html'))) { @@ -141,7 +144,10 @@ if ($action == 'update' && !empty($permissiontoadd)) if (!GETPOSTISSET($key)) continue; // The field was not submited to be edited } // Ignore special fields - if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; + if (in_array($key, array('rowid', 'entity', 'import_key'))) continue; + if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) { + if (!in_array(abs($val['visible']), array(1, 3, 4))) continue; // Only 1 and 3 and 4 that are case to update + } // Set value to update if (preg_match('/^(text|html)/', $object->fields[$key]['type'])) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 18fe31aa4e2..1dd68accbc9 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7512,8 +7512,7 @@ abstract class CommonObject // Depending on field type ('datetime', ...) if ($this->isDate($info)) { - if (empty($this->{$field})) - { + if (empty($this->{$field})) { $queryarray[$field] = null; } else { $queryarray[$field] = $this->db->idate($this->{$field}); @@ -7928,6 +7927,7 @@ abstract class CommonObject unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. if (array_key_exists('ref', $fieldvalues)) $fieldvalues['ref'] = dol_string_nospecial($fieldvalues['ref']); // If field is a ref, we sanitize data + // Add quotes and escape on fields with type string $keys = array(); $values = array(); $tmp = array(); @@ -7938,7 +7938,7 @@ abstract class CommonObject $tmp[] = $k.'='.$this->quote($v, $this->fields[$k]); } - // Clean and check mandatory + // Clean and check mandatory fields foreach ($keys as $key) { if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = ''; // This is an implicit foreign key field