+ # Find GPS traces with specified name/id.
+ # Returns array listing GPXs, each one comprising id, name and description.
+
+ def findgpx(searchterm, usertoken)
+ uid = getuserid(usertoken)
+ if !uid then return -1,"You must be logged in to search for GPX traces." end
+
+ gpxs = []
+ if searchterm.to_i>0 then
+ gpx = Trace.find(searchterm.to_i, :conditions => ["visible=? AND (public=? OR user_id=?)",true,true,uid] )
+ if gpx then
+ gpxs.push([gpx.id, gpx.name, gpx.description])
+ end
+ else
+ Trace.find(:all, :limit => 21, :conditions => ["visible=? AND (public=? OR user_id=?) AND MATCH(name) AGAINST (?)",true,true,uid,searchterm] ).each do |gpx|
+ gpxs.push([gpx.id, gpx.name, gpx.description])
+ end
+ end
+ gpxs
+ end
+