//  WEBSITE.FGL, (c) 2008 by Steve Repetti, All Rights Reserved
//  CLASSES:  pageClass, GuestBook, gbData

LIBRARY \fgl\libs\system.flb

CLASS pageClass
  PUBLIC:
      local ver="1.0"

    METHOD navmenu( curmenu )
        local s, a, i, cnt
        
        a = {
            { "Designer", "designer.htm", "" },
            { "Developer", "developer.htm", "" },
            { "Author", "author.htm", "" },
            { "Advocate", "advocate.htm", "" },
            { "Speaker", "speaker.htm", "" },
            { "</td><td align=center nowrap width='100%'>", "", "" },
            { "Awards", "awards.htm", "" },
            { " <img src='images/new.png' border=0> In the news", "inthenews.htm", "" },
            { "</td><td align=right nowrap width='1%'>", "", "" },
            { "Blog", "http://webtechinsight.blogspot.com/", "_blank" },
            { "Contact", "contact.htm", "" },
            { "Home", "index.htm", "" }
        }

        curmenu = upper( curmenu )
        s = "<table border=0 class=txt width=100% cellspacing=0 cellpadding=0><tr><td nowrap width='1%'>"

        cnt = len( a )
        for ( i=1; i<=cnt; i++ )
            if ( left( a[i,1], 1 ) == "<" )
                s += a[i,1]
                continue
            end
            if ( curmenu == upper( a[i,1] ) )
                s += "<a href='" + a[i,2] + "'" + ( strempty( a[i,3] ) ? "" : " target=" +  a[i,3] ) + "><u>" + a[i,1] + "</u></a>"
            else
                s += "<a href='" + a[i,2] + "'" + ( strempty( a[i,3] ) ? "" : " target=" +  a[i,3] ) + ">" + a[i,1] + "</a>"
            end
            
            if ( ( i != cnt ) && ( left( a[i+1,1], 1 ) != "<" ) )
                s += " | "
            end
        end

        s += "</td></tr></table>"

        return( s )
    END

    METHOD metaData( desc="", keywords="" )
        local s
        
        if ( strempty( desc ) )
            desc = "Business website for Steve Repetti"
        end
        if ( strempty( keywords ) )
            keywords = "Steve Repetti,Steven Repetti,Zude,FGL,open5G,VirtualDESK,PerfectMenu,Angie & Steve,Angie and Steve,Data Portability,Open Source,OpenSocial,SocialMix,technologist"
        end
        
        s = "<meta name=\"author\" content=\"Steve Repetti/TextPad/FGL\">\r\n" +
            " <meta http-equiv='PICS-Label' content=\"(PICS-1.1 'http://www.weburbia.com/safe/ratings.htm' l r (s 0))\">\r\n" +
            " <meta name=\"keywords\" content=\"" + keywords + "\">\r\n" +
            " <meta name=\"description\" content=\"" + desc + "\">"
            
        return( s )
    END
  
    METHOD header( )
        local s = "<table border=0 cellspacing=0 cellpadding=0 class=txt width=100% height=100%><tr height=1%><td>" +
            "<table border=0 cellspacing=0 cellpadding=0 class=smtxt width=100% height=44 bgcolor='#A0A0A0'>" +
            "<tr><td colspan=2><img src='images/dot_black.gif' width=100% height=1></td></tr>" +
            "<tr><td nowrap>" +

            " &nbsp;<b>Visit me at:</b> &nbsp;" +
            " <a href='http://www.scrapplet.com/SteveRepetti' class=nav target=_blank>Scrapplet</a> | " +
            " <a href='http://www.linkedin.com/in/steverepetti' class=nav target=_blank>Linkedin</a> | " +
            " <a href='http://www.facebook.com/profile.php?id=556295938' class=nav target=_blank>Facebook</a> | " +
            " <a href='http://www.myspace.com/steverepetti' class=nav target=_blank>MySpace</a> | " +
            " <a href='http://twitter.com/SteveRepetti' class=nav target=_blank>Twitter</a> " +
            "</td><td nowrap align=right>" +

            " &nbsp;<b>Also visit:</b> &nbsp; " +
            " <a href='http://www.angieandsteve.com' class=nav target=_blank>Angie & Steve</a>" +
//            " <a href='http://www.zude.com/64908052004083023896' class=nav target=_blank>My Profile</a> | " +
//            " <a href='guestbook.htm' class=nav>Guestbook</a> " +
            " &nbsp; " +

            "</td></tr>" +
            "<tr><td colspan=2><img src='images/dot_black.gif' width=100% height=2></td></tr>" +
            "<tr height=20 bgcolor=white><td colspan=2>&nbsp;</td></tr>" +
            "</table>" +
            "</td></tr><tr><td align=center valign=top>";

        return( s )
    END
    
    METHOD contentTop( )
        local s = "<table border=0 cellspacing=0 cellpadding=0 class=txt width=780>" +
             "<tr height=100%>" +
            "<td>" +
            "<table border=0 cellspacing=0 cellpadding=25 class=txt width=780 height=100% style='border:solid 3px #000000;' bgcolor='#FFFFFF'><tr><td>";

        return( s )
    END

    METHOD contentBottom( )
        local s = "</td></tr></table>" +
              "</td>" +
              "<td><img src='images/shadow_right.gif' width=12 height=100%></td>" +
              "</tr>" +
              "<tr height=15>" +
              "<td><img src='images/shadow_bottom.gif' width=100% height=15></td>" +
              "<td><img src='images/shadow_bottom_right.gif' width=12 height=15></td>" +
              "</tr>" +
              "</table>";

        return( s )
    END

    METHOD copyright( )
        local s = "<br><font class=smtxt><font color='#a0a0a0'>&copy; 2008-2009 by Steve Repetti, All Rights Reserved</font></font><br><br>" +
            "</td></tr></table>";
        
        return( s )
    END

    METHOD source( )
        return( "" )
        //return( "<center>" + fglSourceLink( "smtxt" ) + "<br><br></center>" )
    END        

    
END
    

CLASS GuestBook
  PUBLIC:
      local aData
      const datafile = 'c:\sdweb\home\websites\steverepetti\gb.dat'
      const timezone = "ET"
      const maxlen = 1024

    METHOD get( )
        local data, e
        data = fileReadASCII( ::datafile )
        try
            unpack( data, self )
        catch( e )
            ::aData = {}
        end
        return( 1 )
    END

    METHOD set( )
        return( fileWriteASCII( ::datafile, pack( self ) ) )
    END

    METHOD add( from, msg )
        local date, index

        if ( len( msg ) > ::maxlen )
            msg = left( msg, ::maxlen )
        end

        ::get( )
        index = len( ::aData ) + 1
        date = date( "MMMM DD, YYYY" ) + " " + timetostr( time( ), 0 ) + "m " + ::timezone
        ::aData[index] = new( "gbData", date, from, msg )
        ::set( )

        return( index )
    END

    METHOD display( maxnum=50 )
        local s, cnt, i, max, obj, blog
        
        ::get( )

        cnt = len( ::aData )
        if ( ! cnt )
            return( "No guestbook entries." )
        end
        
        max = cnt - maxnum
        if ( max < 1 )
            max = 1
        end

        s = new( "ServerBuffer" )

        blog = new( "weblog" )
        s += blog.init( "#acd1fa" )
        
        for ( i=cnt; i>=max; i-- )
            obj = ::aData[i]
            s += blog.display( obj.date, obj.from, obj.msg )
        end
        
        return( s.value )
    END

END

CLASS gbData
  PUBLIC:
       local date, from, msg
       
       METHOD new( date="", from="", msg="" )
           ::date = date
           ::from = from
           ::msg = msg
           return( 1 )
       END
END