REBOL [ Title: "Phone Log" Date: 2-Jul-2001 Version: 1.3.0 File: %phone-log.r Author: "Sean C. Johnson" Usage: { ^-This script is a cgi program. Place this script in the cgi-bin ^-directory of your webserver, change the path where the logs are saved, ^-call script from a browser (i.e. http://localhost/cgi-bin/phone-log.r). ^-Enjoy! } Purpose: {A cgi shared phone log in REBOL. Inspired by Andrew Grossman's guestbook. } History: { ^-1.3.0 Added debug func, revised logic to update log, more comments ^-1.1.0 Finally works with Xitami & Apache servers! } Email: sean@scj.net Category: [cgi markup web 3] Requires: %webpage.r ] ;--- Change the following path to be where you want to save the logs ;--- on your server. Remember it is relative to where the script is called! ;--- So, if your script is in Apache's cgi-bin this could be "%../htdocs/phone-logs/" save-log-path: %"../webpages/reb/phone-logs/" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;--- You should not need to change anything below ;--- unless you like messing things up to learn :) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;--- Setup some basic junk message-form: log-today: data: message: none how-to-use: [ print rejoin [system/script/header/title ": "] print system/script/header/purpose print system/script/header/usage print {This script quits in 15 seconds.} wait 15 quit ] if system/options/cgi/request-method = none [do how-to-use] do system/script/header/requires ;--- Crude cgi debug functions verbose: off ;--- turns on/off debug messages cgi-debug: func [/local m][ if not verbose [return ""] m: system/options/cgi/request-method either m = "POST" [ data: retrieve-user-data rejoin [m ":
" mold data] ][ rejoin [m ":
" system/options/cgi/query-string] ] ] ;--- Create phone log directories if they don't exist ;--- Logs are saved in dir "phone-logs", then by month (i.e. 3 means March), ;--- then by date (HTML). log-path: rejoin [save-log-path now/month "/"] log-today: to-file rejoin [log-path now/date ".html"] if not exists? to-file log-path [make-dir/deep to-file log-path] ;--- HTML form for new messages ;--- May want to customize some field options ;--- Changes to form method require changes elsewhere in this script! message-form: {
 
Urgent
Inbound Call     Outbound Call

View Old Phone Logs


} ;--- Print out the form first ;--- To understand the structure of this next statement see %webpage.r print [ content-type begin-body header 6 rejoin ["version: " system/script/header/version " (" read dns:// ")"] cgi-debug begin-center header 1 rejoin [system/script/header/title ": " now/date] message-form end-center ] ;--- Message formatting message: [{^/} either not error? try [data/urgent][if data/urgent = "1" [urgent-banner]][""] {} {} {
} {

} data/name {
} data/company {

} data/phone1_type {: } data/phone1{
} data/phone2_type {: } data/phone2 {
} data/for {

} data/message {

} now/date { | } now/time {
} either data/inout = "1" ["Inbound"]["Outbound"] {   Top of Page
} ;either not error? try [data/urgent][if data/urgent = "1" [urgent-banner]][""] {
} ] urgent-banner: {
URGENT     URGENT     URGENT     URGENT     URGENT
} ;--- Get form data and update log if new message is posted. ;--- When script is first called, method is "get"; therefore, ;--- we skip data retrieval and log update just showing log-today. if system/options/cgi/request-method = "POST"[ ;--- if cgi-debug is on it does the data retrieval, ;--- this keeps from getting empty string and error! :) if not verbose [data: retrieve-user-data] ;--- Set colors for distinction between inbound/outbound calls color: either data/inout = "1" ["#FFFFGG"]["#CCCCFF"] ;--- You can change these colors ;--- Write new message to log write/append log-today reform message ] ;--- Print updated phone log to client print [ either exists? log-today [read log-today] [{
The Phone Log is empty

}] end-body ]