addLog($tour_id, $text); } public static function addRewrite($tour_id, $base_text, $appendix) { $log = new Tour_Log(); $log->addRewriteLog($tour_id, $base_text, $appendix); } protected function __construct($id=false) { parent::__construct('tour_log', $id); } protected function addLog($tour_id, $text) { return $this->db->insertInto($this->table, ['tour_id' => $tour_id, 'logdate' => 'now()', 'logtext' => $text]); } protected function addRewriteLog($tour_id, $base_text, $appendix) { $sql = sprintf("SELECT id FROM %s WHERE tour_id = %d AND sys_user_id = %d AND logtext LIKE %s AND sys_edit > (now() - INTERVAL '%d seconds')", $this->table, $tour_id, $_SESSION['userid'], $this->db->quote($base_text . '%'), $this->seconds); $id = $this->db->fetchValue($sql); if ($id) { return $this->db->update($this->table, ['logtext' => $base_text . $appendix], 'id='.$id); } else { return $this->db->insertInto($this->table, ['tour_id' => $tour_id, 'logdate' => 'now()', 'logtext' => $base_text . $appendix]); } } }