+
+ if @trace.save
+ saved_filename = "/home/osm/gpx/#{@trace.id}.gpx"
+ File.rename(filename, saved_filename)
+
+ logger.info("id is #{@trace.id}")
+ flash[:notice] = "Your GPX file has been uploaded and is awaiting insertion in to the database. This will usually happen within half an hour, and an email will be sent to you on completion."
+ redirect_to :action => 'mine'
+ else
+ # fixme throw an error here
+ redirect_to :action => 'mine'
+ flash[:notice] = "You haven't entered a tag or a description for yoru traces."
+ end
+ end
+
+ def data
+ trace = Trace.find(params[:id])
+ if trace.public? or (@user and @user == trace.user)
+ send_data(File.open("/home/osm/gpx/#{trace.id}.gpx",'r').read , :filename => "#{trace.id}.gpx", :type => 'text/plain', :disposition => 'inline')
+ end
+ end
+
+ def make_public
+ trace = Trace.find(params[:id])
+ if @user and trace.user == @user and !trace.public
+ trace.public = true
+ trace.save
+ flash[:notice] = 'Track made public'
+ redirect_to :controller => 'trace', :action => 'view', :id => params[:id]
+ end
+ end
+
+ def georss
+ traces = Trace.find(:all, :conditions => ['public = true'], :order => 'timestamp DESC', :limit => 20)
+
+ rss = OSM::GeoRSS.new
+
+ #def add(latitude=0, longitude=0, title_text='dummy title', url='http://www.example.com/', description_text='dummy description', timestamp=Time.now)
+ traces.each do |trace|
+ rss.add(trace.latitude, trace.longitude, trace.name, url_for({:controller => 'trace', :action => 'view', :id => trace.id, :display_name => trace.user.display_name}), "<img src='#{url_for({:controller => 'trace', :action => 'icon', :id => trace.id, :user_login => trace.user.display_name})}'> GPX file with #{trace.size} points from #{trace.user.display_name}", trace.timestamp)
+ end
+
+ response.headers["Content-Type"] = 'application/xml+rss'
+
+ render :text => rss.to_s
+ end
+
+ def picture
+ trace = Trace.find(params[:id])
+ send_data(trace.large_picture, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') if trace.public? or (@user and @user == trace.user)
+ end
+
+ def icon
+ trace = Trace.find(params[:id])
+ send_data(trace.icon_picture, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') if trace.public? or (@user and @user == trace.user)
+ end
+
+ def api_details
+ trace = Trace.find(params[:id])
+ doc = OSM::API.new.get_xml_doc
+ doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
+ render :text => doc.to_s
+ end
+
+ def api_data
+ render :action => 'data'
+ end
+
+ def api_create
+ #FIXME merge this code with create as they're pretty similar?
+
+ filename = "/tmp/#{rand}"
+ File.open(filename, "w") { |f| f.write(request.raw_post) }
+ params[:trace] = {}
+ params[:trace][:name] = params[:filename]
+ params[:trace][:tagstring] = params[:tags]
+ params[:trace][:description] = params[:description]
+ @trace = Trace.new(params[:trace])
+ @trace.inserted = false
+ @trace.user = @user
+ @trace.timestamp = Time.now
+