# Copyright (C) 2004 Scott W. Dunlop <swdunlop at users.sourceforge.net>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
@export mt-save
@import auth-user
# Determine our request"s content, or scream at the client.
.content = req.getArg( "content" )
.if content is None: raise InvalidRequestError( request = req )
# Determine our request"s moment, or scream at the client.
.save_moment = req.getArg( "mt" )
.if save_moment is None: raise InvalidRequestError( request = req )
# Load the node, if it exists.
.key = req.getQuery()
.node = db.fetchNode( key )
.node_title = htmlquote( key )
.page_title = node_title
# A new node"s moment is 0.
.if node.getContent() is None:
    .node_moment = 0
.else:
    .node_moment = node.getModification() or node.getCreation()
# If the save moment is not the same as the node moment, then we are about to
# step on someone"s edit. Danger, danger Will Robinson!
@import html-head
@import node-cmds
@import content-head
.if node_moment > save_moment:
    <i>Error: The node has changed while you were editing.  Go back, copy your
    edit, then start a new edit and merge your changes with the node"s new
    contents.</i>
.else:
    .node.setContent( content, user )
    << node.getContentHtml() >>
@import content-tail
@import html-tail

