Пример #1
0
 public function sql_delete($data = null)
 {
     unset($this->error);
     $this->error = array();
     if (count($this->_keys) === 0) {
         $this->unserializeKeys();
     }
     //TODO implement verification of child table before delete
     foreach ($data as $table => $field) {
         if (file_exists(TMP . "/database/" . $table . ".table.txt")) {
             if (!empty($field['id'])) {
                 if (static::HISTORY_ACTIVE) {
                     //traitement specifique
                     if (strstr($this->_table_to_history, $table)) {
                         $sql = "SELECT * FROM " . static::ESC . "" . $table . "" . static::ESC . " WHERE id ='" . $data[$table]['id'] . "'";
                         $res = $this->sql_query($sql);
                         if ($this->sql_num_rows($res) === 1) {
                             $before_update = $this->sql_to_array($res);
                         } else {
                             return false;
                         }
                         $param = \history::compare($before_update[0], array());
                         $id_table = $data[$table]['id'];
                         \history::insert($table, $id_table, $param, $this->_history_type, $this->_history_user, 'DELETE');
                         $this->_history_type = HISTORY_TYPE;
                         $this->_history_user = null;
                     }
                 }
                 $sql = "UPDATE " . $table . " SET id_history_etat = 3 WHERE id =" . $field['id'];
                 $this->sql_query($sql, $table, "UPDATE");
             }
         }
     }
 }