diff --git a/class/bericht.class.php b/class/bericht.class.php index 0147f60..da37c99 100644 --- a/class/bericht.class.php +++ b/class/bericht.class.php @@ -59,27 +59,41 @@ class Bericht extends CommonObject $this->ref = 'BR'.date('ymd-His', $this->datec); } - $sql = "INSERT INTO ".$this->db->prefix()."bericht (" - ."entity, ref, titel, element_type, fk_element, auftragsnummer, template_odt, page_format, page_orientation, is_template, template_label, version, fk_bericht_parent, status, fk_user_creat, datec, note" - .") VALUES (" - .((int) $this->entity)."," - ."'".$this->db->escape($this->ref)."'," - .($this->titel ? "'".$this->db->escape($this->titel)."'" : "NULL")."," - ."'".$this->db->escape($this->element_type)."'," - .((int) $this->fk_element)."," - .($this->auftragsnummer ? "'".$this->db->escape($this->auftragsnummer)."'" : "NULL")."," - .($this->template_odt ? "'".$this->db->escape($this->template_odt)."'" : "NULL")."," - ."'".$this->db->escape($this->page_format)."'," - ."'".$this->db->escape($this->page_orientation)."'," - .((int) ($this->is_template ? 1 : 0))."," - .($this->template_label ? "'".$this->db->escape($this->template_label)."'" : "NULL")."," - .((int) ($this->version ?: 1))."," - .($this->fk_bericht_parent ? (int) $this->fk_bericht_parent : "NULL")."," - .((int) $this->status)."," - .((int) $this->fk_user_creat)."," - ."'".$this->db->idate($this->datec)."'," - .($this->note ? "'".$this->db->escape($this->note)."'" : "NULL") - .")"; + // Prüfen welche optionalen Spalten existieren (Migrationen können unvollständig sein) + $cols = array( + 'entity' => (int) $this->entity, + 'ref' => "'".$this->db->escape($this->ref)."'", + 'titel' => ($this->titel ? "'".$this->db->escape($this->titel)."'" : "NULL"), + 'element_type' => "'".$this->db->escape($this->element_type)."'", + 'fk_element' => (int) $this->fk_element, + 'auftragsnummer' => ($this->auftragsnummer ? "'".$this->db->escape($this->auftragsnummer)."'" : "NULL"), + 'template_odt' => ($this->template_odt ? "'".$this->db->escape($this->template_odt)."'" : "NULL"), + 'status' => (int) $this->status, + 'fk_user_creat' => (int) $this->fk_user_creat, + 'datec' => "'".$this->db->idate($this->datec)."'", + 'note' => ($this->note ? "'".$this->db->escape($this->note)."'" : "NULL"), + ); + // Optionale Spalten — nur wenn in der DB vorhanden + $optional = array( + 'page_format' => "'".$this->db->escape($this->page_format)."'", + 'page_orientation' => "'".$this->db->escape($this->page_orientation)."'", + 'is_template' => (int) ($this->is_template ? 1 : 0), + 'template_label' => ($this->template_label ? "'".$this->db->escape($this->template_label)."'" : "NULL"), + 'version' => (int) ($this->version ?: 1), + 'fk_bericht_parent' => ($this->fk_bericht_parent ? (int) $this->fk_bericht_parent : "NULL"), + ); + $existing = array(); + $cres = $this->db->query("SHOW COLUMNS FROM ".$this->db->prefix()."bericht"); + if ($cres) { + while ($cr = $this->db->fetch_object($cres)) { + $existing[$cr->Field] = true; + } + } + foreach ($optional as $k => $v) { + if (isset($existing[$k])) $cols[$k] = $v; + } + + $sql = "INSERT INTO ".$this->db->prefix()."bericht (".implode(',', array_keys($cols)).") VALUES (".implode(',', array_values($cols)).")"; $this->db->begin(); $res = $this->db->query($sql);